Decompiled source of ModDownloadFix v1.0.1

BepInEx/plugins/ModDownloadFix/ModDownloadFix.dll

Decompiled 2 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using HoldfastGame;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: AssemblyVersion("1.0.1.0")]
[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 ModDownloadFix
{
	[BepInPlugin("com.ryannlt.moddownloadfix", "ModDownloadFix", "1.0.1")]
	public class ModDownloadFixMod : BaseUnityPlugin
	{
		public const string Guid = "com.ryannlt.moddownloadfix";

		internal static ManualLogSource Log;

		private void Awake()
		{
			Log = ((BaseUnityPlugin)this).Logger;
			Harmony.CreateAndPatchAll(typeof(ModDownloadFixMod).Assembly, "com.ryannlt.moddownloadfix");
			Log.LogInfo((object)"Ready.");
		}
	}
	internal static class Handshake
	{
		internal static bool Running;

		internal static bool Deferred;

		internal static bool Withheld;

		internal static bool PendingRelease;
	}
	[HarmonyPatch(typeof(ClientGameManager), "WelcomeToTheServer")]
	internal static class WelcomeToTheServerPatch
	{
		private static void Prefix()
		{
			Handshake.Running = true;
			Handshake.Deferred = false;
			Handshake.Withheld = false;
			Handshake.PendingRelease = false;
		}

		private static void Postfix()
		{
			Handshake.Running = false;
			Handshake.PendingRelease = Handshake.Withheld;
		}
	}
	[HarmonyPatch(typeof(ClientErrorManager), "SetDisconnectPanelInformation", new Type[]
	{
		typeof(IList<ModDisconnectReason>),
		typeof(string),
		typeof(Action),
		typeof(Action)
	})]
	internal static class DisconnectPanelPatch
	{
		private static void Prefix()
		{
			if (Handshake.Running)
			{
				Handshake.Deferred = true;
			}
		}
	}
	[HarmonyPatch(typeof(GameServerInitialDetails), "ReleaseFields")]
	internal static class ReleaseFieldsPatch
	{
		private static bool Prefix()
		{
			if (!Handshake.Running || !Handshake.Deferred)
			{
				return true;
			}
			Handshake.Withheld = true;
			ModDownloadFixMod.Log.LogInfo((object)"Kept the handshake packet for the Workshop auto-join.");
			return false;
		}
	}
	[HarmonyPatch(typeof(ClientGameManager), "HandleMapLoading")]
	internal static class HandleMapLoadingPatch
	{
		private static void Postfix(GameServerInitialDetailsData gameServerInitialDetails)
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			if (!Handshake.Running && Handshake.PendingRelease)
			{
				Handshake.PendingRelease = false;
				GameServerInitialDetails.ReleaseFields(gameServerInitialDetails);
				ModDownloadFixMod.Log.LogInfo((object)"Released the handshake packet after loading.");
			}
		}
	}
	[HarmonyPatch(typeof(UIAdminMapRotationsPanel), "ResolveMapRotationDetails")]
	internal static class ResolveMapRotationDetailsPatch
	{
		private static bool Prefix(int mapRotationIndex, List<UIAdminMapRotationsPanelRow> ___activeRows, ref MapRotationDetails __result)
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Expected O, but got Unknown
			int num = ___activeRows?.Count ?? 0;
			if (mapRotationIndex >= 0 && mapRotationIndex < num)
			{
				return true;
			}
			__result = new MapRotationDetails
			{
				MapNameOverride = CustomMapName()
			};
			ModDownloadFixMod.Log.LogWarning((object)("Rotation " + mapRotationIndex + " was looked up with " + num + " rows loaded. Used a stand-in so the round could start."));
			return false;
		}

		private static string CustomMapName()
		{
			ClientComponentReferenceManager clientInstance = ClientComponentReferenceManager.ClientInstance;
			if ((Object)(object)clientInstance == (Object)null || (Object)(object)clientInstance.clientModLoaderManager == (Object)null)
			{
				return null;
			}
			CustomMapDefinition lastLoadedCustomMapDefinition = ((BaseModLoaderManager)clientInstance.clientModLoaderManager).lastLoadedCustomMapDefinition;
			return ((Object)(object)lastLoadedCustomMapDefinition != (Object)null) ? lastLoadedCustomMapDefinition.mapName : null;
		}
	}
	[HarmonyPatch(typeof(UIAdminMapRotationsPanel), "_InitializeOnMap")]
	internal static class RotationsTabInitializePatch
	{
		private static bool Prefix(RoundGameDetails roundGameDetails, List<UIAdminMapRotationsPanelRow> ___activeRows, ref int ___currentRotationIndex)
		{
			int num = ((roundGameDetails == null) ? (-1) : roundGameDetails.RotationIndex);
			int num2 = ___activeRows?.Count ?? 0;
			if (num >= 0 && num < num2)
			{
				return true;
			}
			___currentRotationIndex = -1;
			ModDownloadFixMod.Log.LogWarning((object)("Rotations tab asked to highlight row " + num + " of " + num2 + ". Skipped the highlight so the round could start."));
			return false;
		}
	}
	[HarmonyPatch(typeof(UIScoreboardPanel), "InitializeOnMap", new Type[] { typeof(RoundGameDetails) })]
	internal static class ScoreboardInitializePatch
	{
		private static Exception Finalizer(Exception __exception)
		{
			if (!(__exception is ArgumentOutOfRangeException))
			{
				return __exception;
			}
			ModDownloadFixMod.Log.LogWarning((object)("Scoreboard setup threw \"" + __exception.Message + "\". Carried on so the round could start."));
			return null;
		}
	}
}