1.5, added stuff, fixed stuff

- mod icon
- fixes for new vanilla clipping issues
- GenClosest optimization improving repairing, wardening, tending jobs
- caching for new ListerBuildings methods
- DynamicDrawManager single threading
- Type.GetFields caching
- StatParts analyzer category
- removed duplicate steam warning and optionally window
- added exception handling for debug menu, incidentworker, Graphic_Multi, InitializeComps, making all those now log what mod broke and not cause black screens or whatever
This commit is contained in:
bbradson
2024-04-27 22:31:07 +02:00
parent be3dae46bb
commit d34bc77869
76 changed files with 3061 additions and 1134 deletions
+38 -2
View File
@@ -48,7 +48,7 @@ public sealed class ThingPatches : ClassWithFishPrepatches
__instance.SetStuffDirect(GenStuff.DefaultStuffFor(def));
}
}
public sealed class SpawnedPatch : FishPrepatch
{
public override string? Description { get; }
@@ -60,7 +60,7 @@ public sealed class ThingPatches : ClassWithFishPrepatches
public override void Transpiler(ILProcessor ilProcessor, ModuleDefinition module)
=> ilProcessor.ReplaceBodyWith(MiscExtensions.IsSpawned);
}
public sealed class MapHeldPatch : FishPrepatch
{
public override string? Description { get; }
@@ -72,4 +72,40 @@ public sealed class ThingPatches : ClassWithFishPrepatches
public override void Transpiler(ILProcessor ilProcessor, ModuleDefinition module)
=> ilProcessor.ReplaceBodyWith(MiscExtensions.TryGetMapHeld);
}
public sealed class InitializeCompsFix : FishPrepatch
{
public override string? Description { get; }
= "Improves the error message in ThingWithComps.InitializeComps to include thing, props and mod";
public override MethodBase TargetMethodBase { get; }
= AccessTools.DeclaredMethod(typeof(ThingWithComps), nameof(ThingWithComps.InitializeComps));
public override void Transpiler(ILProcessor ilProcessor, ModuleDefinition module)
{
var codes = ilProcessor.instructions;
var errorMessageIndex = codes.FirstIndexOf(static code
=> code.Operand is "Could not instantiate or initialize a ThingComp: ");
codes[errorMessageIndex].OpCode = OpCodes.Ldarg_0;
codes[errorMessageIndex].Operand = null;
ilProcessor.InsertRange(errorMessageIndex + 1,
(OpCodes.Ldloca,
ilProcessor.Body.Variables.First(local => local.VariableType == module.TypeSystem.Int32)),
(OpCodes.Call, methodof(MakeErrorMessage)));
}
public static string MakeErrorMessage(ThingWithComps thing, ref int index)
{
var compProps = thing.def.comps;
if (compProps.TryGetItem(index, out var props))
compProps.RemoveAt(index--);
return $"Could not instantiate or initialize a ThingComp with props '{
(props != null! ? props.GetType().FullName : "null")}' on thing '{thing}' from mod '{
thing.def.modContentPack?.Name ?? "null"}': ";
}
}
}