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
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:
36
CringeLauncher/Patches/PbInstantiatePatch.cs
Normal file
36
CringeLauncher/Patches/PbInstantiatePatch.cs
Normal 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);
|
||||
}
|
Reference in New Issue
Block a user