Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Source/Client/Debug/DebugPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ static void Postfix(FloatMenuOption __instance, Rect rect)
}

[EarlyPatch]
[HarmonyPatch(typeof(PatchClassProcessor), "ProcessPatchJob")]
[HarmonyPatch(typeof(PatchClassProcessor), nameof(PatchClassProcessor.ProcessPatchJob))]
static class HarmonyMeasurePatchTime
{
static void Prefix(ref double __state)
Expand Down
24 changes: 12 additions & 12 deletions Source/Client/MultiplayerStatic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -365,18 +365,18 @@ void TryPatch(MethodBase original, HarmonyMethod prefix = null, HarmonyMethod po

var thingMethods = new[]
{
("Tick", Type.EmptyTypes),
("TickRare", Type.EmptyTypes),
("TickLong", Type.EmptyTypes),
("TickInterval", [typeof(int)]),
("TakeDamage", [typeof(DamageInfo)]),
("Kill", [typeof(DamageInfo?), typeof(Hediff)])
(nameof(Thing.Tick), Type.EmptyTypes),
(nameof(Thing.TickRare), Type.EmptyTypes),
(nameof(Thing.TickLong), Type.EmptyTypes),
(nameof(Thing.TickInterval), [typeof(int)]),
(nameof(Thing.TakeDamage), [typeof(DamageInfo)]),
(nameof(Thing.Kill), [typeof(DamageInfo?), typeof(Hediff)])
};

foreach (Type t in typeof(Thing).AllSubtypesAndSelf())
{
// SpawnSetup is patched separately because it sets the map
var spawnSetupMethod = t.GetMethod("SpawnSetup", BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly, null, new[] { typeof(Map), typeof(bool) }, null);
var spawnSetupMethod = t.GetMethod(nameof(Thing.SpawnSetup), BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly, null, new[] { typeof(Map), typeof(bool) }, null);
if (spawnSetupMethod != null)
TryPatch(spawnSetupMethod, thingMethodPrefixSpawnSetup, finalizer: thingMethodFinalizer);

Expand All @@ -396,9 +396,9 @@ void TryPatch(MethodBase original, HarmonyMethod prefix = null, HarmonyMethod po

var thingMethods = new[]
{
("SpawnSetup", Type.EmptyTypes),
("Tick", Type.EmptyTypes),
("TickInterval", [typeof(int)]),
(nameof(WorldObject.SpawnSetup), Type.EmptyTypes),
(nameof(WorldObject.Tick), Type.EmptyTypes),
(nameof(WorldObject.TickInterval), [typeof(int)]),
};

foreach (Type t in typeof(WorldObject).AllSubtypesAndSelf())
Expand Down Expand Up @@ -429,13 +429,13 @@ void TryPatch(MethodBase original, HarmonyMethod prefix = null, HarmonyMethod po
var setMapTimePrefix = new HarmonyMethod(AccessTools.Method(typeof(SetMapTimeForUI), nameof(SetMapTimeForUI.Prefix)));
var setMapTimeFinalizer = new HarmonyMethod(AccessTools.Method(typeof(SetMapTimeForUI), nameof(SetMapTimeForUI.Finalizer)));

var windowMethods = new[] { "DoWindowContents", "WindowUpdate" };
var windowMethods = new[] { nameof(MainTabWindow_Inspect.DoWindowContents), nameof(MainTabWindow_Inspect.WindowUpdate) };
foreach (string m in windowMethods)
TryPatch(typeof(MainTabWindow_Inspect).GetMethod(m), setMapTimePrefix, finalizer: setMapTimeFinalizer);

foreach (var t in typeof(InspectTabBase).AllSubtypesAndSelf())
{
var method = t.GetMethod("FillTab", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.DeclaredOnly, null, Type.EmptyTypes, null);
var method = t.GetMethod(nameof(InspectTabBase.FillTab), BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.DeclaredOnly, null, Type.EmptyTypes, null);
if (method != null && !method.IsAbstract)
TryPatch(method, setMapTimePrefix, finalizer: setMapTimeFinalizer);
}
Expand Down
2 changes: 1 addition & 1 deletion Source/Client/Patches/Alerts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static void Postfix(ref List<Pawn> __result)
// You will not get abandoned warning: (baby from other faction without the same faction adult)
// for (other) player owned babies at all, unless it's happened directly on YOUR base.
// Example: someone catapulted their baby on your map. Your own babies get a different set of warning, which works fine.
[HarmonyPatch(typeof(Alert_AbandonedBaby), "AbandonedBabies")]
[HarmonyPatch(typeof(Alert_AbandonedBaby), nameof(Alert_AbandonedBaby.AbandonedBabies))]
public static class Patch_Alert_AbandonedBaby_MultifactionWarning
{
public static void Postfix(ref List<Pawn> __result)
Expand Down
2 changes: 1 addition & 1 deletion Source/Client/Patches/Determinism.cs
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> inst

// Modify cache update checking
matcher.MatchEndForward(
new CodeMatch(OpCodes.Callvirt, typeof(Dictionary<Thing, StatCacheEntry>).GetMethod("TryGetValue"))
new CodeMatch(OpCodes.Callvirt, typeof(Dictionary<Thing, StatCacheEntry>).GetMethod(nameof(Dictionary<Thing, StatCacheEntry>.TryGetValue)))
).Advance(1).Insert(
new CodeInstruction(OpCodes.Ldarg_0),
new CodeInstruction(OpCodes.Ldarg_1),
Expand Down
8 changes: 4 additions & 4 deletions Source/Client/Patches/PathFinderPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public static bool TryGet(Pawn pawn, out PawnSnapShot snapshot) =>
snapshotDict.TryGetValue(pawn, out snapshot);
}

[HarmonyPatch(typeof(PathFinder), "ScheduleBatchedPathJobs")]
[HarmonyPatch(typeof(PathFinder), nameof(PathFinder.ScheduleBatchedPathJobs))]
static class ScheduleBatchedPathJobsSnapshotPositions
{
static readonly FieldInfo CachedPawns =
Expand All @@ -82,8 +82,8 @@ static class PathGridDoorsBlockedJobPositionPatch

static IEnumerable<MethodBase> TargetMethods()
{
yield return AccessTools.Method(typeof(PathGridDoorsBlockedJob), "Execute");
yield return AccessTools.Method(typeof(PathGridDoorsBlockedJob), "CanBlockEver");
yield return AccessTools.Method(typeof(PathGridDoorsBlockedJob), nameof(PathGridDoorsBlockedJob.Execute));
yield return AccessTools.Method(typeof(PathGridDoorsBlockedJob), nameof(PathGridDoorsBlockedJob.CanBlockEver));
}

static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> insts)
Expand Down Expand Up @@ -120,7 +120,7 @@ static class PathGridDoorsBlockedJobCollideWithNonHostilePatch
AccessTools.Method(typeof(PathGridDoorsBlockedJobCollideWithNonHostilePatch), nameof(GetCollideWithNonHostile));
static IEnumerable<MethodBase> TargetMethods()
{
yield return AccessTools.Method(typeof(PathGridDoorsBlockedJob), "Execute");
yield return AccessTools.Method(typeof(PathGridDoorsBlockedJob), nameof(PathGridDoorsBlockedJob.Execute));
}
// start
// calls to ShouldCollideWithPawns, replace with cached one
Expand Down
2 changes: 1 addition & 1 deletion Source/Client/Patches/Plans.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ static bool Prefix(object __instance)
public static void SyncSetPlanColor(Plan plan, ColorDef color)
{
plan.Color = color;
AccessTools.Method(typeof(Plan), "CheckContiguous").Invoke(plan, null);
AccessTools.Method(typeof(Plan), nameof(Plan.CheckContiguous)).Invoke(plan, null);
}
}
}
6 changes: 3 additions & 3 deletions Source/Client/Persistent/CaravanFormingPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ static bool Prefix(TimedForcedExit __instance)
static class DisableCaravanFormCheckboxForOtherFactions
{
static MethodInfo TargetMethod() {
return typeof(Widgets).GetMethod("Checkbox", [
return typeof(Widgets).GetMethod(nameof(Widgets.Checkbox), [
typeof(Vector2), typeof(bool).MakeByRefType(), typeof(float), typeof(bool), typeof(bool), typeof(Texture2D), typeof(Texture2D)
]);
}
Expand All @@ -270,7 +270,7 @@ static bool Prefix(Vector2 topLeft, bool checkOn, bool disabled)
static class DisableCaravanFormSuppliesCheckboxForOtherFactions
{
static MethodInfo TargetMethod() {
return typeof(Widgets).GetMethod("CheckboxLabeled", [
return typeof(Widgets).GetMethod(nameof(Widgets.CheckboxLabeled), [
typeof(Rect), typeof(string), typeof(bool).MakeByRefType(), typeof(bool), typeof(Texture2D), typeof(Texture2D), typeof(bool), typeof(bool)
]);
}
Expand Down Expand Up @@ -328,7 +328,7 @@ static bool Prefix(Rect rect, string label, ref bool __result)
static class DisableCaravanFormCountTextBoxForOtherFactions
{
static MethodInfo TargetMethod() {
return typeof(Widgets).GetMethod("TextFieldNumeric", BindingFlags.Public | BindingFlags.Static).MakeGenericMethod(typeof(int));
return typeof(Widgets).GetMethod(nameof(Widgets.TextFieldNumeric), BindingFlags.Public | BindingFlags.Static).MakeGenericMethod(typeof(int));
}
static bool Prefix(Rect rect, int val)
{
Expand Down
2 changes: 1 addition & 1 deletion Source/Client/Persistent/TradingUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ static bool Prefix(Rect rect, string label, ref bool __result)
static class DisableTradeCountTextBoxForOtherFactions
{
static MethodInfo TargetMethod() {
return typeof(Widgets).GetMethod("TextFieldNumeric", BindingFlags.Public | BindingFlags.Static).MakeGenericMethod(typeof(int));
return typeof(Widgets).GetMethod(nameof(Widgets.TextFieldNumeric), BindingFlags.Public | BindingFlags.Static).MakeGenericMethod(typeof(int));
}
static bool Prefix(Rect rect, int val)
{
Expand Down
4 changes: 2 additions & 2 deletions Source/Client/Persistent/TransporterLoadingPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ static void Prefix(Dialog_LoadTransporters __instance, Map map, List<CompTranspo
static class DisableTransferCheckboxForOtherFactions
{
static MethodInfo TargetMethod() {
return typeof(Widgets).GetMethod("Checkbox", [
return typeof(Widgets).GetMethod(nameof(Widgets.Checkbox), [
typeof(Vector2), typeof(bool).MakeByRefType(), typeof(float), typeof(bool), typeof(bool), typeof(Texture2D), typeof(Texture2D)
]);
}
Expand Down Expand Up @@ -202,7 +202,7 @@ static bool Prefix(Rect rect, string label, ref bool __result)
static class DisableTransferCountTextBoxForOtherFactions
{
static MethodInfo TargetMethod() {
return typeof(Widgets).GetMethod("TextFieldNumeric", BindingFlags.Public | BindingFlags.Static).MakeGenericMethod(typeof(int));
return typeof(Widgets).GetMethod(nameof(Widgets.TextFieldNumeric), BindingFlags.Public | BindingFlags.Static).MakeGenericMethod(typeof(int));
}
static bool Prefix(Rect rect, int val)
{
Expand Down
4 changes: 2 additions & 2 deletions Source/Client/Syncing/Game/SyncDelegates.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ public static void Init()
{
const SyncContext mouseKeyContext = SyncContext.QueueOrder_Down | SyncContext.MapMouseCell;
// TODO probably not needed, perhaps just sync PrepareCycleJob as it contains SetQueuedInformation after TryTakeOrderedJob
SyncDelegate.Lambda(typeof(FloatMenuOptionProvider_CarryToBiosculpterPod), "GetOptionsFor", 0).CancelIfAnyFieldNull().SetContext(mouseKeyContext); // Carry to biosculpter pod
SyncDelegate.Lambda(typeof(FloatMenuOptionProvider_CaptureEntity), "GetOptionsFor", 2).CancelIfAnyFieldNull().SetContext(mouseKeyContext); // Capture entity
SyncDelegate.Lambda(typeof(FloatMenuOptionProvider_CarryToBiosculpterPod), nameof(FloatMenuOptionProvider_CarryToBiosculpterPod.GetOptionsFor), 0).CancelIfAnyFieldNull().SetContext(mouseKeyContext); // Carry to biosculpter pod
SyncDelegate.Lambda(typeof(FloatMenuOptionProvider_CaptureEntity), nameof(FloatMenuOptionProvider_CaptureEntity.GetOptionsFor), 2).CancelIfAnyFieldNull().SetContext(mouseKeyContext); // Capture entity

// Other possible float menu options that could be added later:
// TODO maybe? TransporterUtility.InitiateLoading is not synced, not sure if significant
Expand Down
2 changes: 1 addition & 1 deletion Source/Client/Syncing/Game/SyncMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ static IEnumerable<CodeInstruction> CompPlantableTranspiler(IEnumerable<CodeInst
foreach (var inst in insts)
{
// this.plantCells.Add(t.Cell) => CompPlantable_AddCell(t.Cell, this)
if (inst.operand as MethodInfo == typeof(List<IntVec3>).GetMethod("Add"))
if (inst.operand as MethodInfo == typeof(List<IntVec3>).GetMethod(nameof(List<IntVec3>.Add)))
{
// Load this
yield return new CodeInstruction(OpCodes.Ldarg_0);
Expand Down
4 changes: 2 additions & 2 deletions Source/TestsOnMono/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ public static void Main3(string[] args)
Console.WriteLine(test.GetField().b);

new Harmony("test").Patch(
typeof(TestClassForPatches<SomeClass>).GetMethod("GetField"),
postfix: new HarmonyMethod(typeof(Program).GetMethod("GenericPostfix"))
typeof(TestClassForPatches<SomeClass>).GetMethod(nameof(TestClassForPatches<SomeClass>.GetField)),
postfix: new HarmonyMethod(typeof(Program).GetMethod(nameof(GenericPostfix)))
);

Console.WriteLine(test.GetField().b);
Expand Down