Skip to content

Use nameof instead of string method names in Harmony patches - #1013

Open
Sanjay-doppalapudi wants to merge 1 commit into
rwmt:devfrom
Sanjay-doppalapudi:issue-633-nameof-harmony-patches
Open

Sanjay-doppalapudi wants to merge 1 commit into
rwmt:devfrom
Sanjay-doppalapudi:issue-633-nameof-harmony-patches

Conversation

@Sanjay-doppalapudi

Copy link
Copy Markdown

Closes #633

I replaced string literals naming patched/looked-up methods with nameof(...) so patched methods are easier to find and renames in RimWorld updates surface as compile errors instead of runtime patch failures. Since the client assemblies are publicized, this also works for non-public members. nameof produces the same string, so there is no behaviour change.

Converted (31 literals):

  • [HarmonyPatch] attributes: PathFinder.ScheduleBatchedPathJobs, Alert_AbandonedBaby.AbandonedBabies, PatchClassProcessor.ProcessPatchJob
  • TargetMethod(s): PathGridDoorsBlockedJob.Execute/CanBlockEver, Widgets.Checkbox/CheckboxLabeled/TextFieldNumeric
  • Transpiler call matching: Dictionary<,>.TryGetValue, List<IntVec3>.Add
  • The manual patch lists in MultiplayerStatic.DoPatches (Thing, WorldObject, MainTabWindow_Inspect, InspectTabBase.FillTab), the example from the issue
  • SyncDelegate.Lambda registrations for GetOptionsFor, Plan.CheckContiguous, and the TestsOnMono Harmony test

Left as strings on purpose: compiler-generated names (<GetGizmos>b__1, <>c__DisplayClass...), local function names passed to LocalFunc, methods from other mods (ModManager, HugsLib), MultiplayerLoader (doesn't reference the client), and field names.

Tested: dotnet build Source/ -c Release builds with no errors, and dotnet test passes all 160 tests.

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.

1 participant