Repository navigation
Conversation
Use matching Harmony 3 and RimWorld 1.7 reference packages. Make shared-reference registration idempotent and track simulation freezes at long-event update boundaries. Explicitly rerun static initializers on CoreCLR so reloads restore debug defaults and resolver caches, preventing empty progress-bar effects from breaking jobs. Add regression coverage for repeated resets.
|
I haven't looked through your PR, but I just noticed that you mention preserving 1.6 compatibility. 1.6 compatibility is unlikely to be needed in the source code. For back-compat we just clone the previous branch (so 1.5 if 1.6 is the main version supported), compile it, and include in the mod release. See |
| } | ||
|
|
||
| public int IncreasePlayerCount() => CurrentPlayerCount += 1; | ||
| public void ResetPlayerCount() => currentPlayerCount = 0; |
There was a problem hiding this comment.
These changes (re. currentPlayerCount) seem independent of the 1.7 upgrade?
There was a problem hiding this comment.
The issue was observed during the 1.7 testing
Two players both viewing map A:
- Its viewer count is 2.
- Multiplayer creates a join point by saving and reconstructing the game.
- Without serialization, the reconstructed map’s viewer count defaults to 0.
- Both players remain on map A, so there is no actual view change to rebuild the count.
The map now has two real viewers but zero recorded viewers. VTR treats it as unviewed and selects the less frequent update rate.
I guess the previous versions don't get any fixes with this approach. With the approach from this PR, every version will get the fix if it is compatible |
| Multiplayer.game.sync.TryAddStackTraceForDesyncLogRaw(logItem, managedDepth, managedHash); | ||
| acc++; | ||
| return; | ||
| } |
There was a problem hiding this comment.
Have you performed any performance tests for this code? It's called frequently and while it could've been implemented this way even in 1.6, it was not fast enough and impacted the game performance.
There was a problem hiding this comment.
Good point. I measured the managed collector and decided to allow user to select a tracing mode in the settings view.
Fixed in cf163a2:
- Fast records lightweight event context without capturing or formatting managed stacks.
- Slow explicitly enables detailed managed stack capture.
- None disables diagnostic event history.
- The selection is now available in Release settings and persists between sessions.
- RNG-based desync detection remains enabled in every mode.
I tested the production collector on native ARM64 with RimWorld 1.7.4990. Five rotated comparisons restored the same one-map, three-colonist save, warmed 60 ticks, then measured 2,000 world-plus-map ticks:
| Mode | Median elapsed time | Median allocated memory |
|---|---|---|
| None | 117 ms | 4.65 MB |
| Fast | 118 ms | 5.17 MB |
| Slow | 223 ms | 202.74 MB |
Fast was comparable to None within the observed timing variability. Slow retains the expensive diagnostics intentionally.
Sure, right now for an old version to get a fix you'd need to send a PR for the relevant branch (like |
Ok, makes sense, but I'd still keep it in the CI. I think it makes testing easier for other people when they can go to PR and download a ZIP with mod that can be tested. |
Having a zip available for download would be nice, but it's not related to 1.7 compatibility and as such, please move those changes to a separate PR where I can review them |
| using System.Linq; | ||
| using System.Reflection; | ||
| using HarmonyLib; | ||
| using MethodInvoker = HarmonyLib.MethodInvoker; |
There was a problem hiding this comment.
In the future, we could consider using System.Reflection.MethodInvoker instead. Not neccessary for this PR
There was a problem hiding this comment.
The 1.7 implementation requires Harmony 3. An older Prepatcher left enabled can supply Harmony 2.4.x, so declaring the Harmony dependency alone doesn't guarantee that the required assembly is loaded.
This check validates the assembly actually loaded before Multiplayer initializes and gives the player a clear dependency error instead of failing later during patch installation.
There was a problem hiding this comment.
An older Prepatcher left enabled can supply Harmony 2.4.x, so declaring the Harmony dependency alone doesn't guarantee that the required assembly is loaded.
Prepatcher doesn't have 1.7 support, so if someone has it enabled, RimWorld will show a warning. Also, will 1.7 even start with Prepatcher enabled? To be clear, the warning is helpful, but I'm not sure if it will ever actually show (without the user ignoring a bunch of other warnings)
There was a problem hiding this comment.
RimWorld 1.7.4995 rev309 has added "Experimental back-compat support for Prepatcher dependent mods". I'd rather try to use that instead
There was a problem hiding this comment.
I'm open to trying it but I don't have a DLC to test this change. So I'll defer this for now.
There was a problem hiding this comment.
I'm open to trying it but I don't have a DLC to test this change.
That's fine, but does it mean that the patches in SyncRituals are also untested? If so, I think I'd rather have them removed from this PR and ship a bare-bones 1.7 version upon which later improvements can be made (such as re-adding DLC support).
There was a problem hiding this comment.
It is untested in a real game session but I did some checks offline using the actual WaylithCLR runtime in a small isolated executable, loading the real game DLLs, Harmony, and Multiplayer’s production patch code. It allocates real widget types without running their constructors and invoke their patched methods through reflection. A recording substitute for the sync handler captures the target and arguments and skips local execution.
So I can tell that the patches are applied correctly and the arguments are passed. Of course there can be issues in a real game but that's best effort of what I can do now.
Regarding the Prepatcher compatibility. The old code also needs changes for 1.7: it assumes Prepatcher restarts the game between patching and handler registration. The engine now runs both passes in one process, so placeholders survive and an early method lookup can remain cached as null.
There was a problem hiding this comment.
If it doesn't work we will get feedback anyway, but the Harmony implementation remains my preference for readability and maintenance as it doesn't require specific handling for the loading process of the mod.
Summary
Port Multiplayer to RimWorld 1.7's .NET 10/CoreCLR runtime. This branch targets RimWorld 1.7 and Harmony 3; older RimWorld releases remain separate frozen builds in the workshop bundle.
Thanks to @mkiplm-svg for the initial RimWorld 1.7 port, which provided the foundation for this work.
CoreCLR compatibility
Deterministic simulation and state handling
System.HashCode.Combinepatches with deterministic replacements at selected game call sites, preserving existing tuple and dictionary key behavior.Build and release setup
global.jsonand target the .NET 10 runtime.Validation