Fix init when pasting in a programmable block
All checks were successful
Build / Compute Version (push) Successful in 6s
Build / Build Nuget package (CringeBootstrap.Abstractions) (push) Successful in 1m30s
Build / Build Nuget package (SharedCringe) (push) Successful in 1m45s
Build / Build Nuget package (NuGet) (push) Successful in 1m47s
Build / Build Nuget package (CringePlugins) (push) Successful in 1m58s
Build / Build Launcher (push) Successful in 2m24s

Improvements for imgui input handling
This commit is contained in:
2025-05-16 22:52:15 -04:00
parent a87161f2f5
commit bd626f7a2b
4 changed files with 76 additions and 16 deletions

View File

@@ -0,0 +1,36 @@
using HarmonyLib;
using Sandbox.Game.Entities.Blocks;
using System.Reflection.Emit;
namespace CringeLauncher.Patches;
[HarmonyPatch(typeof(MyProgrammableBlock), "UpdateBeforeSimulation")]
internal static class PbInstantiatePatch
{
[HarmonyTranspiler]
public static List<CodeInstruction> UpdateBeforeSimulationTranspiler(IEnumerable<CodeInstruction> instructions)
{
var list = instructions.ToList();
var index = list.FindIndex(b => b.opcode == OpCodes.Brfalse);
//get second brfase
index = list.FindIndex(index, b => b.opcode == OpCodes.Brfalse);
var jump = new CodeInstruction(list[index])
{
opcode = OpCodes.Brtrue
};
index++;
list.Insert(index++, new CodeInstruction(OpCodes.Ldarg_0));
list.Insert(index++, CodeInstruction.CallClosure(PveMethod));
list.Insert(index, jump);
return list;
}
//IMPORTANT: if you reference CompilingPbs in the transpiler, ModScriptCompilerPatch will cause static init of MyScriptWhitelist, crashing the game
private static bool PveMethod(MyProgrammableBlock block) => ModScriptCompilerPatch.CompilingPbs.Contains(block);
}