fix crashes, temp disable reflection caching, possibly reduce optimization in some areas, likely break 1.5

This commit is contained in:
localavaster
2026-04-14 00:12:50 -06:00
parent 9821c68999
commit 35187cf2d2
20 changed files with 275 additions and 107 deletions
+8 -36
View File
@@ -19,45 +19,17 @@ public sealed class GenLocalDateCaching : ClassWithFishPatches
+ "optimization, but yields accurate results instead of a placeholder value to avoid issues";
public override Delegate TargetMethodGroup { get; } = (Func<Thing, int>)GenLocalDate.DayTick;
public override int TranspilerMethodPriority => Priority.First;
public override int PrefixMethodPriority => Priority.First;
public static CodeInstructions Transpiler(CodeInstructions codes, MethodBase method, ILGenerator generator)
//=> Reflection.GetCodeInstructions(Replacement);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool Prefix(Thing thing, ref int __result)
{
var labelToStartOfMethod = generator.DefineLabel();
codes.First().labels.Add(labelToStartOfMethod);
if (thing.TryGetMap() is not { } map)
return true;
yield return FishTranspiler.Argument(method, "thing");
yield return FishTranspiler.Field(typeof(Thing), nameof(Thing.mapIndexOrState));
yield return FishTranspiler.Constant(0);
yield return FishTranspiler.IfLessThan(labelToStartOfMethod);
yield return FishTranspiler.Field(typeof(Current), nameof(Current.gameInt));
yield return FishTranspiler.Field(typeof(Game), nameof(Game.maps));
yield return FishTranspiler.Argument(method, "thing");
yield return FishTranspiler.Field(typeof(Thing), nameof(Thing.mapIndexOrState));
yield return FishTranspiler.Call(typeof(List<Map>), "get_Item");
yield return FishTranspiler.Call<Func<Map, int>>(GenLocalDate.DayTick);
yield return FishTranspiler.Return;
foreach (var code in codes)
yield return code;
__result = GenLocalDate.DayTick(map);
return false;
}
//[MethodImpl(MethodImplOptions.AggressiveInlining)]
//public static int Replacement(Thing thing)
// => thing.mapIndexOrState < 0 ? GenDate.DayTick(GenTicks.TicksAbs, GenLocalDate.LongitudeForDate(thing))
// : GenLocalDate.DayTick(Current.gameInt.maps[thing.mapIndexOrState]);
//[MethodImpl(MethodImplOptions.AggressiveInlining)]
//public static bool Prefix(Thing thing, ref int __result)
//{
// if (thing.mapIndexOrState < 0)
// return true;
// __result = GenLocalDate.DayTick(Current.gameInt.maps[thing.mapIndexOrState]);
// return false;
//}
}
public sealed class DayTickByMap_Patch : FishPatch
@@ -100,4 +72,4 @@ public sealed class GenLocalDateCaching : ClassWithFishPatches
public static Map? SavedMap;
public static int SavedTick = -2;
public static int DayTick = -2;
}
}