Decompiled source of ZortLib v1.0.0

plugins/ZortLib/ZortLib.dll

Decompiled 2 months ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
using Mirror;
using MonoMod.RuntimeDetour;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("ZortModBepInex")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ZortModBepInex")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("9df868d5-31a0-4d0d-8de2-7370fe2e4989")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace ZortLibrary;

[BepInPlugin("erne.zort.zortlib", "ZortLib", "1.0.0")]
public class ZortLib : BaseUnityPlugin
{
	public const string libGuid = "erne.zort.zortlib";

	public const string libName = "ZortLib";

	public const string libVersion = "1.0.0";

	public static float sceneDelay = 3f;

	public static byte scene;

	public static Action OnMenu;

	public static Action OnLobby;

	public static Action OnGame;

	public static Action OnceMenu;

	public static Action OnceLobby;

	public static Action OnceGame;

	public void Awake()
	{
		PatchUtils.RegisterCallback(typeof(MainMenuManager), "Awake", delegate
		{
			SetLine(0);
		});
		PatchUtils.RegisterCallback(typeof(NetworkManager), "StartHost", delegate
		{
			SetLine(1);
		});
		PatchUtils.RegisterCallback(typeof(NetworkManager), "StartClient", delegate
		{
			SetLine(1);
		});
		PatchUtils.RegisterCallback(typeof(ClueBoard), "StartMap", delegate
		{
			SetLine(2);
		});
	}

	public void Start()
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		Mono.Instance = new GameObject("Mono").AddComponent<Mono>();
		Object.DontDestroyOnLoad((Object)(object)Mono.Instance);
	}

	public void Update()
	{
		if (scene == 0)
		{
			OnMenu?.Invoke();
		}
		if (scene == 1)
		{
			OnLobby?.Invoke();
		}
		if (scene == 2)
		{
			OnGame?.Invoke();
		}
	}

	public void SetLine(byte newScene)
	{
		((MonoBehaviour)(object)this).InvokeIn(sceneDelay, delegate
		{
			scene = newScene;
			if (newScene == 0)
			{
				OnceMenu?.Invoke();
			}
			else if (newScene == 1)
			{
				OnceLobby?.Invoke();
			}
			else if (newScene == 2)
			{
				OnceGame?.Invoke();
			}
		});
	}
}
public static class ZortUtils
{
	public static void InvokeIn(this MonoBehaviour behaviour, float inSeconds, Action act)
	{
		if (inSeconds == 0f)
		{
			act();
		}
		else
		{
			behaviour.StartCoroutine(enumerator());
		}
		IEnumerator enumerator()
		{
			yield return (object)new WaitForSeconds(inSeconds);
			act();
		}
	}

	public static T GetPrivateVariable<T>(this object instance, string name)
	{
		Type type = instance.GetType();
		FieldInfo field = type.GetField(name, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
		object value = field.GetValue(instance);
		return (value is T) ? ((T)value) : default(T);
	}

	public static void SetPrivateVariable<T>(this object instance, string name, T value)
	{
		Type type = instance.GetType();
		FieldInfo field = type.GetField(name, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
		field.SetValue(instance, value);
	}

	public static void InvokePrivateVoid(this object instance, string methodName, params object[] parameters)
	{
		MethodInfo method = instance.GetType().GetMethod(methodName, BindingFlags.Instance | BindingFlags.NonPublic);
		if (instance == null || method == null)
		{
			Debug.LogWarning((object)("Instance : " + instance?.ToString() + " Method : " + method));
		}
		method.Invoke(instance, parameters);
	}

	public static void ReplaceMethod(Type class0, string method0, Type class1, string method1)
	{
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		new Hook((MethodBase)class0.GetMethod(method0, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic), class1.GetMethod(method1, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic));
	}
}
public static class PatchUtils
{
	private static Dictionary<string, Action> actions = new Dictionary<string, Action>();

	private static object callback;

	public static void RegisterCallback(Type classType, string callback, Action action, bool oneTime = false)
	{
		//IL_003a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0040: Expected O, but got Unknown
		//IL_006f: Unknown result type (might be due to invalid IL or missing references)
		//IL_007c: Expected O, but got Unknown
		PatchUtils.callback = callback;
		if (!actions.ContainsKey(callback))
		{
			actions.Add(callback, action);
		}
		else
		{
			actions[callback] = action;
		}
		Harmony val = new Harmony("com.example.patch");
		MethodInfo methodInfo = AccessTools.Method(classType, callback, (Type[])null, (Type[])null);
		MethodInfo methodInfo2 = AccessTools.Method(typeof(PatchUtils), oneTime ? "DynamicPostfixOnce" : "DynamicPostfix", (Type[])null, (Type[])null);
		val.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(methodInfo2), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
	}

	public static void UnRegisterCallback(Type classType, string callback)
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Expected O, but got Unknown
		Harmony val = new Harmony("com.example.patch");
		MethodInfo methodInfo = AccessTools.Method(classType, callback, (Type[])null, (Type[])null);
		val.Unpatch((MethodBase)methodInfo, (HarmonyPatchType)0, "com.example.patch");
		actions.Remove(callback);
	}

	public static void DynamicPostfix(MethodBase __originalMethod)
	{
		string name = __originalMethod.Name;
		actions[name]?.Invoke();
	}

	public static void DynamicPostfixOnce(MethodBase __originalMethod)
	{
		string name = __originalMethod.Name;
		actions[name]?.Invoke();
		UnRegisterCallback(__originalMethod.DeclaringType, name);
	}
}
public class Mono : MonoBehaviour
{
	public static Mono Instance;

	public void Awake()
	{
		Instance = this;
		Object.DontDestroyOnLoad((Object)(object)((Component)this).gameObject);
	}
}