Decompiled source of LobbyGlitchFix v1.0.2

GKFRLobbyGlitchFix.dll

Decompiled a month ago
using System;
using System.Collections;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.6", FrameworkDisplayName = ".NET Framework 4.6")]
[assembly: AssemblyCompany("GKFRLobbyGlitchFix")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.2.0")]
[assembly: AssemblyInformationalVersion("1.0.2+2f79f4c4f2c988faeceb2349289119fa63d206fe")]
[assembly: AssemblyProduct("GKFRLobbyGlitchFix")]
[assembly: AssemblyTitle("GKFRLobbyGlitchFix")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.2.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace GKFRLobbyGlitchFix
{
	[BepInPlugin("GKFRLobbyGlitchFix", "GKFRLobbyGlitchFix", "1.0.2")]
	public class Plugin : BaseUnityPlugin
	{
		private class FixPatch
		{
			private static bool raceEnding;

			[HarmonyPatch(typeof(InGameGameMode), "Start")]
			[HarmonyPrefix]
			private static void InGameGameMode_Start()
			{
				raceEnding = false;
			}

			[HarmonyPatch(typeof(GkNetMgr), "StartTimer")]
			[HarmonyPrefix]
			private static bool GkNetMgr_StartTimer(GkNetMgr __instance, TimerState state)
			{
				//IL_0008: Unknown result type (might be due to invalid IL or missing references)
				//IL_000a: Invalid comparison between Unknown and I4
				if (__instance.IsMasterClient && (int)state == 2)
				{
					bool result = !raceEnding;
					raceEnding = true;
					return result;
				}
				return true;
			}

			[HarmonyPatch(typeof(MenuHDMultiplayerMain), "Enter")]
			[HarmonyPostfix]
			private static void MenuHDMultiplayerMain_Enter(TMP_Text ___m_titleLabel)
			{
				___m_titleLabel.text += " (lobby glitch fix 1.0.2)";
			}
		}

		private class ReproPatch
		{
			private static bool delaySynchro = true;

			[HarmonyPatch(typeof(RcRace), "GetRaceNbLap")]
			[HarmonyPrefix]
			private static bool RcRace_GetRaceNbLap(ref int __result)
			{
				__result = 0;
				return false;
			}

			[HarmonyPatch(typeof(GkNetMgr), "OnEndSynchronization")]
			[HarmonyPrefix]
			private static bool GkNetMgr_OnEndSynchronization(GkNetMgr __instance, SynchroPoint ___m_currentSynchroPoint)
			{
				//IL_000a: Unknown result type (might be due to invalid IL or missing references)
				//IL_001a: Unknown result type (might be due to invalid IL or missing references)
				//IL_001c: Invalid comparison between Unknown and I4
				Logger.LogInfo((object)$"OnEndSynchronization({___m_currentSynchroPoint})");
				if ((int)___m_currentSynchroPoint == 5 && delaySynchro)
				{
					((MonoBehaviour)instance).StartCoroutine(DelayResultsSynchro(__instance));
					return false;
				}
				return true;
			}

			private static IEnumerator DelayResultsSynchro(GkNetMgr __instance)
			{
				yield return (object)new WaitForSeconds(2f);
				delaySynchro = false;
				__instance.OnEndSynchronization();
				delaySynchro = true;
			}

			[HarmonyPatch(typeof(TimerDisplay), "UpdateCustomTimer")]
			[HarmonyPrefix]
			private static bool TimerDisplay_UpdateCustomTimer(float seconds, InfoBox ___m_infoBox)
			{
				string text = seconds.ToString("0.000");
				if (text != "0.000")
				{
					___m_infoBox.SetMonospaceText(text, 0.55f);
				}
				else
				{
					___m_infoBox.SetText("");
				}
				return false;
			}

			[HarmonyPatch(typeof(GkNetMgr), "StartTimer")]
			[HarmonyPrefix]
			private static void GkNetMgr_StartTimer(TimerState state, TimerState ___m_eventTimerState, float ___m_eventTimer)
			{
				//IL_0000: Unknown result type (might be due to invalid IL or missing references)
				//IL_0025: Unknown result type (might be due to invalid IL or missing references)
				//IL_002b: Unknown result type (might be due to invalid IL or missing references)
				string arg = (((int)___m_eventTimerState == 0) ? "" : $", time left: {___m_eventTimer}s");
				Logger.LogInfo((object)$"StartTimer({state}) - active timer: {___m_eventTimerState}{arg}");
			}

			[HarmonyPatch(typeof(GkNetMgr), "StartTimer")]
			[HarmonyPostfix]
			private static void GkNetMgr_StartTimer_Postfix(TimerState ___m_eventTimerState)
			{
				//IL_000a: Unknown result type (might be due to invalid IL or missing references)
				Logger.LogInfo((object)$"Active timer now: {___m_eventTimerState}");
			}

			[HarmonyPatch(typeof(GkNetMgr), "StopTimer")]
			[HarmonyPrefix]
			private static void GkNetMgr_StopTimer(TimerState ___m_eventTimerState)
			{
				//IL_0000: Unknown result type (might be due to invalid IL or missing references)
				//IL_000d: Unknown result type (might be due to invalid IL or missing references)
				if ((int)___m_eventTimerState != 0)
				{
					Logger.LogInfo((object)$"Timer {___m_eventTimerState} done.");
				}
			}

			[HarmonyPatch(typeof(InGameGameMode), "Start")]
			[HarmonyPatch(typeof(InGameGameMode), "OnIaNetDriverRaceEnded")]
			[HarmonyPatch(typeof(InGameGameMode), "OnLocalHumanDriverRaceEnded")]
			[HarmonyPatch(typeof(GkNetMgr), "OnGoToResults")]
			[HarmonyPatch(typeof(MenuHDResultsLeaderboard), "Enter")]
			[HarmonyPatch(typeof(ResultGameState), "Enter")]
			[HarmonyPatch(typeof(ResultGameState), "OnNetworkSynchro")]
			[HarmonyPatch(typeof(ResultGameState), "ShowResults")]
			[HarmonyPrefix]
			private static void LogMethodCall(MethodBase __originalMethod)
			{
				Logger.LogInfo((object)(__originalMethod.DeclaringType.Name + "." + __originalMethod.Name));
			}
		}

		internal static ManualLogSource Logger;

		private Harmony harmony;

		private static Plugin instance;

		private void Awake()
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Expected O, but got Unknown
			instance = this;
			Logger = ((BaseUnityPlugin)this).Logger;
			Logger.LogInfo((object)"Plugin GKFRLobbyGlitchFix is loaded!");
			harmony = new Harmony("GKFRLobbyGlitchFix");
			harmony.PatchAll(typeof(FixPatch));
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "GKFRLobbyGlitchFix";

		public const string PLUGIN_NAME = "GKFRLobbyGlitchFix";

		public const string PLUGIN_VERSION = "1.0.2";
	}
}