Got at least one data fetching method working; turns out, we can't use a patched LogicStack to get the data
This commit is contained in:
69
Patches/Tick.cs
Normal file
69
Patches/Tick.cs
Normal file
@@ -0,0 +1,69 @@
|
||||
using System;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Assets.Scripts;
|
||||
using Assets.Scripts.Objects.Electrical;
|
||||
using HarmonyLib;
|
||||
using JetBrains.Annotations;
|
||||
|
||||
namespace RemoteControl.Patches
|
||||
{
|
||||
[HarmonyPatch(typeof(LogicStack), nameof(LogicStack.LogicStackTick))]
|
||||
[SuppressMessage("ReSharper", "InconsistentNaming")]
|
||||
// ReSharper disable once InconsistentNaming
|
||||
public class LogicStack_LogicStackTick
|
||||
{
|
||||
private struct State
|
||||
{
|
||||
internal object LockObj;
|
||||
internal bool Taken;
|
||||
}
|
||||
|
||||
[UsedImplicitly]
|
||||
private static void Prefix(out State __state)
|
||||
{
|
||||
__state = new State
|
||||
{
|
||||
LockObj = SubscriptionManager.Lock,
|
||||
Taken = false
|
||||
};
|
||||
if (!GameManager.RunSimulation) return;
|
||||
// System.Threading.Monitor.Enter(__state.LockObj, ref __state.Taken);
|
||||
try
|
||||
{
|
||||
RemoteControl.Log("logic stack tick: start prefix");
|
||||
SubscriptionManager.ApplyUpdates();
|
||||
RemoteControl.Log("logic stack tick: end prefix");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
RemoteControl.Log($"prefix: Exception {e}:\n {e.StackTrace}");
|
||||
}
|
||||
}
|
||||
|
||||
[UsedImplicitly]
|
||||
private static void Postfix(State __state)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!GameManager.RunSimulation) return;
|
||||
SubscriptionManager.RescanNetworks();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
RemoteControl.Log("logic stack tick: start postfix");
|
||||
RemoteControl.Log($"postfix: Exception {e}: \n{e.StackTrace}");
|
||||
RemoteControl.Log("logic stack tick: end postfix");
|
||||
}
|
||||
finally
|
||||
{
|
||||
// if (__state.Taken)
|
||||
// {
|
||||
// System.Threading.Monitor.Exit(__state.LockObj);
|
||||
// }
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user