Skip to content

RimWorld 1.7 runtime fixes - #1000

Open
romangr wants to merge 26 commits into
rwmt:devfrom
RimWorld-mods-patches:codex/rimworld-1.7-runtime-fixes
Open

romangr wants to merge 26 commits into
rwmt:devfrom
RimWorld-mods-patches:codex/rimworld-1.7-runtime-fixes

Conversation

@romangr

@romangr romangr commented Oct 28, 2026 •

Copy link
Copy Markdown

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

  • Remove Mono-specific profiler, native stack walking, and unsafe method-layout access.
  • Add selectable desync tracing: Fast records lightweight event context, Slow captures managed stacks, and None disables diagnostic history. RNG and simulation-state desync checks remain enabled in every mode.
  • Update reflection and generated synchronization IL for CoreCLR and Harmony 3.
  • Restore required game static defaults explicitly during reloads.

Deterministic simulation and state handling

  • Replace global System.HashCode.Combine patches with deterministic replacements at selected game call sites, preserving existing tuple and dictionary key behavior.
  • Preserve pawn-biography hashing under RimWorld 1.7's compatible string hashing.
  • Make shared-reference registration idempotent.
  • Preserve map and world viewer counts across save/reload, reset counts for newly hosted sessions, and suspend map-view reporting during loading and catch-up.
  • Track marked long-event freeze transitions at update boundaries.

Build and release setup

  • Centralize SDK selection in global.json and target the .NET 10 runtime.
  • Build the 1.7 assemblies into versioned mod folders and declare the Harmony 3 dependency.
  • Keep RimWorld 1.5 and 1.6 release builds separate from the 1.7 source; the workshop bundler includes the frozen legacy releases.

Validation

  • Debug and Release solution builds passed on .NET 10.
  • Release unit tests passed: 177 tests.
  • An isolated runtime probe exercised ritual patches against the 1.7 game assemblies; full multiplayer DLC ritual behavior still needs in-game verification.
  • Two clients connected through Steam and completed basic actions without observed desyncs.

@mibac138

Copy link
Copy Markdown
Member

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 workshop_bundler.sh for the mechanism

}

public int IncreasePlayerCount() => CurrentPlayerCount += 1;
public void ResetPlayerCount() => currentPlayerCount = 0;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes (re. currentPlayerCount) seem independent of the 1.7 upgrade?

@romangr romangr Oct 28, 2026 •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue was observed during the 1.7 testing

Two players both viewing map A:

  1. Its viewer count is 2.
  2. Multiplayer creates a join point by saving and reconstructing the game.
  3. Without serialization, the reconstructed map’s viewer count defaults to 0.
  4. 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.

@romangr

romangr commented Oct 28, 2026

Copy link
Copy Markdown
Author

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 workshop_bundler.sh for the mechanism

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;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@mibac138

Copy link
Copy Markdown
Member

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

Sure, right now for an old version to get a fix you'd need to send a PR for the relevant branch (like 1.5) instead of dev (which is not common), but it reduces the maintenance work required and simplifies the code, which is important as I (and I believe the rest of the team) don't have much time available and the mod is already intricate enough as it is. It also reduces the risk that a change that works fine on a new RW version causes issues for the old RW version one for whatever reason (as I doubt people would test their changes on both versions of the game)

@romangr

romangr commented Oct 28, 2026 •

Copy link
Copy Markdown
Author

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

Sure, right now for an old version to get a fix you'd need to send a PR for the relevant branch (like 1.5) instead of dev (which is not common), but it reduces the maintenance work required and simplifies the code, which is important as I (and I believe the rest of the team) don't have much time available and the mod is already intricate enough as it is. It also reduces the risk that a change that works fine on a new RW version causes issues for the old RW version one for whatever reason (as I doubt people would test their changes on both versions of the game)

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.

@mibac138

mibac138 commented Nov 4, 2026

Copy link
Copy Markdown
Member

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

Sure, right now for an old version to get a fix you'd need to send a PR for the relevant branch (like 1.5) instead of dev (which is not common), but it reduces the maintenance work required and simplifies the code, which is important as I (and I believe the rest of the team) don't have much time available and the mod is already intricate enough as it is. It also reduces the risk that a change that works fine on a new RW version causes issues for the old RW version one for whatever reason (as I doubt people would test their changes on both versions of the game)

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

Comment thread Source/Client/Desyncs/JittedMethods.cs Resolved
using System.Linq;
using System.Reflection;
using HarmonyLib;
using MethodInvoker = HarmonyLib.MethodInvoker;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the future, we could consider using System.Reflection.MethodInvoker instead. Not neccessary for this PR

Comment thread Source/Client/KeepDebugResolution.cs Resolved

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we require Harmony 3?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Comment thread Source/MultiplayerLoader/Prepatches.cs Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RimWorld 1.7.4995 rev309 has added "Experimental back-compat support for Prepatcher dependent mods". I'd rather try to use that instead

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm open to trying it but I don't have a DLC to test this change. So I'll defer this for now.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants