Decompiled source of REPOGambling DirtyGames CompatibilityFix v1.0.1

BepInEx/patchers/REPOGamblingCompatibilityFix/REPOGamblingCompatibilityFix.dll

Decompiled 15 hours ago
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx.Logging;
using Mono.Cecil;
using Mono.Cecil.Cil;
using Mono.Collections.Generic;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: AssemblyVersion("0.1.0.0")]
namespace REPOGamblingCompatibilityFix;

public static class Patcher
{
	private static readonly ManualLogSource Log = Logger.CreateLogSource("REPOGamblingCompatibilityFix");

	public static IEnumerable<string> TargetDLLs
	{
		get
		{
			yield return "Assembly-CSharp.dll";
		}
	}

	public static void Patch(AssemblyDefinition assembly)
	{
		//IL_0080: Unknown result type (might be due to invalid IL or missing references)
		//IL_0085: Unknown result type (might be due to invalid IL or missing references)
		//IL_0220: Unknown result type (might be due to invalid IL or missing references)
		//IL_0227: Expected O, but got Unknown
		//IL_0258: Unknown result type (might be due to invalid IL or missing references)
		//IL_0262: Expected O, but got Unknown
		//IL_0284: Unknown result type (might be due to invalid IL or missing references)
		//IL_0297: Unknown result type (might be due to invalid IL or missing references)
		//IL_029c: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_0309: Unknown result type (might be due to invalid IL or missing references)
		//IL_02fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_031d: Unknown result type (might be due to invalid IL or missing references)
		//IL_032b: Unknown result type (might be due to invalid IL or missing references)
		TypeDefinition type = assembly.MainModule.GetType("ChatManager");
		if (type == null)
		{
			return;
		}
		string[] array = new string[8] { "ChatManager/PossessChatID", "System.String", "System.Single", "UnityEngine.Color", "System.Single", "System.Boolean", "System.Int32", "UnityEngine.Events.UnityEvent" };
		MethodDefinition val = null;
		Enumerator<MethodDefinition> enumerator = type.Methods.GetEnumerator();
		try
		{
			while (enumerator.MoveNext())
			{
				MethodDefinition current = enumerator.Current;
				if (((MemberReference)current).Name != "PossessChat" || current.IsStatic || ((MemberReference)((MethodReference)current).ReturnType).FullName != "System.Void" || (((MethodReference)current).Parameters.Count != 8 && ((MethodReference)current).Parameters.Count != 9))
				{
					continue;
				}
				bool flag = true;
				for (int i = 0; i < 8; i++)
				{
					if (((MemberReference)((ParameterReference)((MethodReference)current).Parameters[i]).ParameterType).FullName != array[i])
					{
						flag = false;
					}
				}
				if (flag)
				{
					if (((MethodReference)current).Parameters.Count == 8)
					{
						Log.LogInfo((object)"Legacy PossessChat already available; skipping.");
						return;
					}
					if (((MemberReference)((ParameterReference)((MethodReference)current).Parameters[8]).ParameterType).FullName == "System.String" && ((MethodReference)current).Parameters[8].HasConstant)
					{
						val = current;
					}
				}
			}
		}
		finally
		{
			((IDisposable)enumerator/*cast due to .constrained prefix*/).Dispose();
		}
		if (val == null)
		{
			Log.LogWarning((object)"Unknown PossessChat signature; skipping.");
			return;
		}
		MethodDefinition val2 = new MethodDefinition("PossessChat", (MethodAttributes)134, assembly.MainModule.TypeSystem.Void);
		for (int i = 0; i < 8; i++)
		{
			((MethodReference)val2).Parameters.Add(new ParameterDefinition(((ParameterReference)((MethodReference)val).Parameters[i]).Name, (ParameterAttributes)0, ((ParameterReference)((MethodReference)val).Parameters[i]).ParameterType));
		}
		ILProcessor iLProcessor = val2.Body.GetILProcessor();
		iLProcessor.Emit(OpCodes.Ldarg_0);
		Enumerator<ParameterDefinition> enumerator2 = ((MethodReference)val2).Parameters.GetEnumerator();
		try
		{
			while (enumerator2.MoveNext())
			{
				ParameterDefinition current2 = enumerator2.Current;
				iLProcessor.Emit(OpCodes.Ldarg, current2);
			}
		}
		finally
		{
			((IDisposable)enumerator2/*cast due to .constrained prefix*/).Dispose();
		}
		object constant = ((MethodReference)val).Parameters[8].Constant;
		if (constant == null)
		{
			iLProcessor.Emit(OpCodes.Ldnull);
		}
		else
		{
			iLProcessor.Emit(OpCodes.Ldstr, (string)constant);
		}
		iLProcessor.Emit(OpCodes.Call, (MethodReference)(object)val);
		iLProcessor.Emit(OpCodes.Ret);
		type.Methods.Add(val2);
		Log.LogInfo((object)"Restored legacy PossessChat overload, forwarding all arguments and the game's default locale. Memory only.");
	}
}

BepInEx/plugins/REPOGamblingCompatibilityFix/REPOGamblingTextFix.dll

Decompiled 15 hours ago
using System;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using HarmonyLib;
using TMPro;
using UnityEngine;

[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: CompilationRelaxations(8)]
[assembly: AssemblyVersion("1.0.1.0")]
namespace REPOGamblingCompatibilityFix;

[BepInPlugin("local.REPOGamblingCompatibilityFix.Text", "REPOGambling Text Compatibility Fix", "1.0.1")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class TextFix : BaseUnityPlugin
{
	private float nextCheck;

	private Harmony harmony;

	private static TextFix instance;

	private TMP_FontAsset stableFont;

	private void Awake()
	{
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: Expected O, but got Unknown
		//IL_0063: Unknown result type (might be due to invalid IL or missing references)
		//IL_0070: Expected O, but got Unknown
		instance = this;
		harmony = new Harmony("local.REPOGamblingCompatibilityFix.Text");
		Type type = AccessTools.TypeByName("REPOGambling.EnvironmentPlacementPatch");
		MethodInfo methodInfo = ((type == null) ? null : AccessTools.Method(type, "SetupSlotMachines", (Type[])null, (Type[])null));
		if (methodInfo != null)
		{
			harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(typeof(TextFix), "AfterSetup", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		}
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Language-independent Bet Text font repair ready.");
	}

	private static void AfterSetup()
	{
		if ((Object)(object)instance != (Object)null)
		{
			instance.Repair();
		}
	}

	private void Update()
	{
		if (!(Time.unscaledTime < nextCheck))
		{
			nextCheck = Time.unscaledTime + 2f;
			Repair();
		}
	}

	private bool InSlot(Transform t)
	{
		while ((Object)(object)t != (Object)null)
		{
			if (((Object)t).name.Contains("Slot Machine") || ((Object)t).name.Contains("Wheel Machine"))
			{
				return true;
			}
			t = t.parent;
		}
		return false;
	}

	private bool Valid(TMP_FontAsset font)
	{
		if ((Object)(object)font == (Object)null || (Object)(object)((TMP_Asset)font).material == (Object)null || (Object)(object)font.atlasTexture == (Object)null || (Object)(object)((TMP_Asset)font).material.shader == (Object)null || !((TMP_Asset)font).material.shader.isSupported)
		{
			return false;
		}
		if ((Object)(object)((TMP_Asset)font).material.mainTexture != (Object)(object)font.atlasTexture)
		{
			return false;
		}
		string text = "Bet: $0123456789K";
		foreach (char c in text)
		{
			if (c != ' ' && !font.HasCharacter(c, false, false))
			{
				return false;
			}
		}
		return true;
	}

	private TMP_FontAsset Font(TMP_Text[] texts)
	{
		if (Valid(stableFont))
		{
			return stableFont;
		}
		TMP_FontAsset[] array = Resources.FindObjectsOfTypeAll<TMP_FontAsset>();
		foreach (TMP_FontAsset val in array)
		{
			if (((Object)val).name == "LiberationSans SDF" && Valid(val))
			{
				stableFont = val;
				return val;
			}
		}
		foreach (TMP_Text val2 in texts)
		{
			if (((Component)val2).gameObject.activeInHierarchy && !InSlot(val2.transform) && Valid(val2.font))
			{
				return val2.font;
			}
		}
		return null;
	}

	private void Repair()
	{
		try
		{
			TMP_Text[] array = Object.FindObjectsOfType<TMP_Text>();
			TMP_FontAsset val = Font(array);
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			TMP_Text[] array2 = array;
			foreach (TMP_Text val2 in array2)
			{
				if (!(((Object)val2).name != "Bet Text") && InSlot(val2.transform) && (!((Object)(object)val2.font == (Object)(object)val) || !((Object)(object)val2.fontSharedMaterial == (Object)(object)((TMP_Asset)val).material)))
				{
					string text = (((Object)(object)val2.font == (Object)null) ? "null" : ((Object)val2.font).name);
					val2.font = val;
					val2.fontSharedMaterial = ((TMP_Asset)val).material;
					val2.ForceMeshUpdate(true, true);
					((BaseUnityPlugin)this).Logger.LogInfo((object)("Repaired Bet Text: " + text + " -> " + ((Object)val).name + "; value=" + val2.text + "; characters=" + val2.textInfo.characterCount));
				}
			}
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)("Bet Text repair deferred: " + ex.Message));
		}
	}

	private void OnDestroy()
	{
		if (harmony != null)
		{
			harmony.UnpatchSelf();
		}
		if ((Object)(object)instance == (Object)(object)this)
		{
			instance = null;
		}
	}
}