Please disclose if your mod was created primarily using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of BCMHQModule v1.3.1
Tomatobird.BCMHQModule.dll
Decompiled 2 weeks agousing System; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Reflection.Emit; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using BCMHQModule.Patches; using BepInEx; using BepInEx.Bootstrap; using BepInEx.Logging; using BrutalCompanyMinus; using BrutalCompanyMinus.Minus; using BrutalCompanyMinus.Minus.Events; using BrutalCompanyMinus.Minus.Handlers; using HQoL.Network; using HarmonyLib; using Microsoft.CodeAnalysis; using UnityEngine; using UnityEngine.AI; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: IgnoresAccessChecksTo("BrutalCompanyMinus")] [assembly: IgnoresAccessChecksTo("OreoM.HQoL.72")] [assembly: IgnoresAccessChecksTo("OreoM.HQoL.73")] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("Tomatobird.BCMHQModule")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyFileVersion("1.3.1.0")] [assembly: AssemblyInformationalVersion("1.3.1+bf68eafb4667b30060b7b204d5a2d7388d54a588")] [assembly: AssemblyProduct("BCMHQModule")] [assembly: AssemblyTitle("Tomatobird.BCMHQModule")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.3.1.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)] internal sealed class NullableAttribute : Attribute { public readonly byte[] NullableFlags; public NullableAttribute(byte P_0) { NullableFlags = new byte[1] { P_0 }; } public NullableAttribute(byte[] P_0) { NullableFlags = P_0; } } [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)] internal sealed class NullableContextAttribute : Attribute { public readonly byte Flag; public NullableContextAttribute(byte P_0) { Flag = P_0; } } [CompilerGenerated] [Microsoft.CodeAnalysis.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 BCMHQModule { [BepInPlugin("Tomatobird.BCMHQModule", "BCMHQModule", "1.3.1")] [BepInDependency("Drinkable.BrutalCompanyMinus", "0.10.12")] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] public class BCMHQModule : BaseUnityPlugin { internal enum Versions { v49, v50, v56, v72, v73 } internal static bool isHQoLLoaded; internal static Dictionary<Versions, string> VersionList = new Dictionary<Versions, string> { { Versions.v49, "0.10.12" }, { Versions.v50, "0.13.9" }, { Versions.v56, "0.13.10" }, { Versions.v72, "0.13.13" }, { Versions.v73, "0.13.14" } }; public static BCMHQModule Instance { get; private set; } = null; internal static ManualLogSource Logger { get; private set; } = null; internal static Harmony? Harmony { get; set; } private void Awake() { Logger = ((BaseUnityPlugin)this).Logger; if ((Object)(object)Instance == (Object)null) { Instance = this; } isHQoLLoaded = Chainloader.PluginInfos.ContainsKey("OreoM.HQoL.72") || Chainloader.PluginInfos.ContainsKey("OreoM.HQoL.73"); Patch(); Logger.LogInfo((object)"Tomatobird.BCMHQModule v1.3.1 has loaded!"); } internal static void Patch() { //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Expected O, but got Unknown if (Harmony == null) { Harmony = new Harmony("Tomatobird.BCMHQModule"); } foreach (PluginInfo value in Chainloader.PluginInfos.Values) { if (!(value.Metadata.GUID == "Drinkable.BrutalCompanyMinus")) { continue; } string text = value.Metadata.Version.ToString(); if (!VersionList.ContainsValue(text)) { Logger.LogWarning((object)("Version " + text + " of BCM loaded was NOT contained in the internal version list. Make sure you're using one of the versions listed below.")); foreach (KeyValuePair<Versions, string> version in VersionList) { Logger.LogWarning((object)(version.Value ?? "")); } Logger.LogWarning((object)"Applying v50+ patches anyway assuming this is a newer version. Things may break."); } if (text == VersionList[Versions.v49]) { Logger.LogDebug((object)("BCM Version " + VersionList[Versions.v49] + " is loaded")); PatchType(new Type[2] { typeof(NoMasksPatcher), typeof(GetSafePositionPatcher) }); break; } Logger.LogDebug((object)("BCM Version " + text + " is loaded")); if (isHQoLLoaded) { PatchType(new Type[1] { typeof(ValueSynchronizer) }); } else { Logger.LogWarning((object)"BCM 50+ loaded without HQoL. ValueSynchronizer won't be used."); } break; } PatchType(new Type[3] { typeof(ShipLeaveOnQuit), typeof(EndOfGamePatcher), typeof(QuotaRackupPatcher) }); Logger.LogDebug((object)"Finished patching!"); } internal static void PatchType(Type[] typeArray) { foreach (Type type in typeArray) { Logger.LogDebug((object)("Patching " + type.Name)); Harmony? harmony = Harmony; if (harmony != null) { harmony.PatchAll(type); } } } internal static void EndOfGameBackupPatch() { Logger.LogWarning((object)"Failed to patch EndOfGamePatcher! Patching EndOfGamePatcherBackup as backup!"); PatchType(new Type[1] { typeof(EndOfGamePatcherBackup) }); } internal static void Unpatch() { Logger.LogDebug((object)"Unpatching..."); Harmony? harmony = Harmony; if (harmony != null) { harmony.UnpatchSelf(); } Logger.LogDebug((object)"Finished unpatching!"); } } public static class MyPluginInfo { public const string PLUGIN_GUID = "Tomatobird.BCMHQModule"; public const string PLUGIN_NAME = "BCMHQModule"; public const string PLUGIN_VERSION = "1.3.1"; } } namespace BCMHQModule.Patches { [HarmonyPatch(typeof(StartOfRound))] public class EndOfGamePatcher { [HarmonyPatch(/*Could not decode attribute arguments.*/)] [HarmonyTranspiler] private static IEnumerable<CodeInstruction> EndOfGameTranspiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator) { //IL_018a: Unknown result type (might be due to invalid IL or missing references) //IL_01a4: Unknown result type (might be due to invalid IL or missing references) //IL_01aa: Expected O, but got Unknown //IL_01b8: Unknown result type (might be due to invalid IL or missing references) //IL_01be: Expected O, but got Unknown //IL_01cc: Unknown result type (might be due to invalid IL or missing references) //IL_01d2: Expected O, but got Unknown //IL_01e0: Unknown result type (might be due to invalid IL or missing references) //IL_01e6: Expected O, but got Unknown //IL_01f4: Unknown result type (might be due to invalid IL or missing references) //IL_01fa: Expected O, but got Unknown //IL_0208: Unknown result type (might be due to invalid IL or missing references) //IL_020e: Expected O, but got Unknown //IL_0244: Unknown result type (might be due to invalid IL or missing references) //IL_024a: Expected O, but got Unknown //IL_0258: Unknown result type (might be due to invalid IL or missing references) //IL_025e: Expected O, but got Unknown //IL_026c: Unknown result type (might be due to invalid IL or missing references) //IL_0272: Expected O, but got Unknown //IL_0280: Unknown result type (might be due to invalid IL or missing references) //IL_0286: Expected O, but got Unknown //IL_0294: Unknown result type (might be due to invalid IL or missing references) //IL_029a: Expected O, but got Unknown //IL_02a8: Unknown result type (might be due to invalid IL or missing references) //IL_02ae: Expected O, but got Unknown //IL_02dd: Unknown result type (might be due to invalid IL or missing references) //IL_02e3: Expected O, but got Unknown //IL_02f7: Unknown result type (might be due to invalid IL or missing references) //IL_02fd: Expected O, but got Unknown //IL_0311: Unknown result type (might be due to invalid IL or missing references) //IL_0317: Expected O, but got Unknown //IL_0330: Unknown result type (might be due to invalid IL or missing references) //IL_0336: Expected O, but got Unknown //IL_034a: Unknown result type (might be due to invalid IL or missing references) //IL_0350: Expected O, but got Unknown //IL_0364: Unknown result type (might be due to invalid IL or missing references) //IL_036a: Expected O, but got Unknown //IL_037d: Unknown result type (might be due to invalid IL or missing references) //IL_0383: Expected O, but got Unknown //IL_039c: Unknown result type (might be due to invalid IL or missing references) //IL_03a2: Expected O, but got Unknown FieldInfo fieldInfo = null; foreach (CodeInstruction instruction in instructions) { FieldInfo obj = instruction.operand as FieldInfo; if ((object)obj != null && (obj.Name?.Contains("<playersDead>")).GetValueOrDefault()) { FieldInfo obj2 = instruction.operand as FieldInfo; if ((object)obj2 != null && (obj2.ReflectedType?.Name.Contains("<EndOfGame>")).GetValueOrDefault()) { fieldInfo = instruction.operand as FieldInfo; break; } } } if (fieldInfo == null) { BCMHQModule.Logger.LogWarning((object)"Could not find playersDead in EndOfGame."); BCMHQModule.EndOfGameBackupPatch(); return instructions; } IEnumerable<CodeInstruction> result = instructions; FieldInfo fieldInfo2 = AccessTools.Field(typeof(StartOfRound), "gameStats"); FieldInfo fieldInfo3 = AccessTools.Field(typeof(EndOfGameStats), "daysSpent"); FieldInfo fieldInfo4 = AccessTools.Field(typeof(StartOfRound), "currentLevel"); FieldInfo fieldInfo5 = AccessTools.Field(typeof(SelectableLevel), "planetHasTime"); MethodInfo methodInfo = AccessTools.PropertyGetter(typeof(TimeOfDay), "Instance"); FieldInfo fieldInfo6 = AccessTools.Field(typeof(TimeOfDay), "daysUntilDeadline"); try { Label label = default(Label); Label label2 = default(Label); result = new CodeMatcher(instructions, generator).MatchForward(true, (CodeMatch[])(object)new CodeMatch[6] { new CodeMatch((OpCode?)OpCodes.Ldfld, (object)fieldInfo2, (string)null), new CodeMatch((OpCode?)OpCodes.Dup, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Ldfld, (object)fieldInfo3, (string)null), new CodeMatch((OpCode?)OpCodes.Ldc_I4_1, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Add, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Stfld, (object)fieldInfo3, (string)null) }).ThrowIfNotMatch("Couldnt match codes.", Array.Empty<CodeMatch>()).Advance(1) .CreateLabel(ref label) .MatchBack(false, (CodeMatch[])(object)new CodeMatch[6] { new CodeMatch((OpCode?)OpCodes.Ldfld, (object)fieldInfo2, (string)null), new CodeMatch((OpCode?)OpCodes.Dup, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Ldfld, (object)fieldInfo3, (string)null), new CodeMatch((OpCode?)OpCodes.Ldc_I4_1, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Add, (object)null, (string)null), new CodeMatch((OpCode?)OpCodes.Stfld, (object)fieldInfo3, (string)null) }) .ThrowIfNotMatch("Failed to MatchBack.", Array.Empty<CodeMatch>()) .Advance(-1) .CreateLabel(ref label2) .InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1] { new CodeInstruction(OpCodes.Ldloc_1, (object)null) }) .InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1] { new CodeInstruction(OpCodes.Ldfld, (object)fieldInfo4) }) .InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1] { new CodeInstruction(OpCodes.Ldfld, (object)fieldInfo5) }) .InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1] { new CodeInstruction(OpCodes.Brtrue_S, (object)label2) }) .InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1] { new CodeInstruction(OpCodes.Call, (object)methodInfo) }) .InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1] { new CodeInstruction(OpCodes.Ldfld, (object)fieldInfo6) }) .InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1] { new CodeInstruction(OpCodes.Ldc_I4_1, (object)null) }) .InsertAndAdvance((CodeInstruction[])(object)new CodeInstruction[1] { new CodeInstruction(OpCodes.Bge_S, (object)label) }) .InstructionEnumeration(); } catch (Exception arg) { BCMHQModule.Logger.LogWarning((object)$"Could not set new codeinstructions to EndOfGame. Exception {arg}"); BCMHQModule.EndOfGameBackupPatch(); } return result; } } [HarmonyPatch(typeof(StartOfRound))] public class EndOfGamePatcherBackup { [HarmonyPatch("EndOfGame")] [HarmonyPrefix] private static void EndOfGamePrefix(StartOfRound __instance) { if (!__instance.currentLevel.planetHasTime && TimeOfDay.Instance.daysUntilDeadline >= 1) { EndOfGameStats gameStats = __instance.gameStats; gameStats.daysSpent--; } } } [HarmonyPatch("BrutalCompanyMinus.Minus.Functions, BrutalCompanyMinus, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null", "GetSafePosition")] public class GetSafePositionPatcher { [HarmonyTranspiler] public static IEnumerable<CodeInstruction> GetSafePositionTranspiler(IEnumerable<CodeInstruction> instructions) { //IL_00f1: Unknown result type (might be due to invalid IL or missing references) //IL_00fb: Expected O, but got Unknown BCMHQModule.Logger.LogDebug((object)"Transpiler called for GetSafePosition"); List<CodeInstruction> list = new List<CodeInstruction>(instructions); MethodInfo methodInfo = AccessTools.Method(typeof(RoundManager), "GetRandomPositionInRadius", new Type[4] { typeof(Vector3), typeof(float), typeof(float), typeof(Random) }, (Type[])null); MethodInfo methodInfo2 = AccessTools.Method(typeof(GetSafePositionPatcher), "GetSafePosition_Replacement", (Type[])null, (Type[])null); if (methodInfo == null || methodInfo2 == null) { BCMHQModule.Logger.LogDebug((object)"OriginalMethod or ReplacementMethod were null."); return list; } for (int i = 0; i < list.Count; i++) { if (CodeInstructionExtensions.Calls(list[i], methodInfo)) { BCMHQModule.Logger.LogDebug((object)string.Format("Replacing call at index {0} with {1}.", i, "GetRandomNavMeshPositionInRadius")); list[i] = new CodeInstruction(OpCodes.Call, (object)methodInfo2); } } return list; } public static Vector3 GetSafePosition_Replacement(Vector3 vector, float minRadius, float radius, Random random) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Unknown result type (might be due to invalid IL or missing references) return RoundManager.Instance.GetRandomNavMeshPositionInRadius(vector, radius, default(NavMeshHit)); } } [HarmonyPatch] public class NoMasksPatcher { [HarmonyPatch("BrutalCompanyMinus.Minus.Events.NoMasks, BrutalCompanyMinus, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null", "Execute")] [HarmonyPrefix] public static void ExecutePatcher() { BCMHQModule.Logger.LogDebug((object)"Patching NoMasks event to keep a reference to the Comedy and Tragedy mask objects."); Type typeFromHandle = typeof(NoMasks); int num = RoundManager.Instance.currentLevel.spawnableScrap.FindIndex((SpawnableItemWithRarity s) => ((Object)s.spawnableItem).name == Assets.ItemNameList[(ItemName)35]); if (num != -1) { FieldInfo field = typeFromHandle.GetField("comedyReference"); field.SetValue(null, RoundManager.Instance.currentLevel.spawnableScrap[num]); } num = RoundManager.Instance.currentLevel.spawnableScrap.FindIndex((SpawnableItemWithRarity s) => ((Object)s.spawnableItem).name == Assets.ItemNameList[(ItemName)36]); if (num != -1) { FieldInfo field2 = typeFromHandle.GetField("tragedyRefernece"); field2.SetValue(null, RoundManager.Instance.currentLevel.spawnableScrap[num]); } } } [HarmonyPatch(typeof(HUDManager))] public class QuotaRackupPatcher { [HarmonyPatch(/*Could not decode attribute arguments.*/)] [HarmonyTranspiler] private static IEnumerable<CodeInstruction> rackUpNewQuotaTextMoveNext(IEnumerable<CodeInstruction> instructions) { //IL_00f9: Unknown result type (might be due to invalid IL or missing references) //IL_011c: Unknown result type (might be due to invalid IL or missing references) //IL_0122: Expected O, but got Unknown //IL_0130: Unknown result type (might be due to invalid IL or missing references) //IL_0136: Expected O, but got Unknown FieldInfo fieldInfo = null; foreach (CodeInstruction instruction in instructions) { FieldInfo obj = instruction.operand as FieldInfo; if ((object)obj != null && (obj.Name?.Contains("<quotaTextAmount>")).GetValueOrDefault()) { FieldInfo obj2 = instruction.operand as FieldInfo; if ((object)obj2 != null && (obj2.ReflectedType?.Name.Contains("<rackUpNewQuotaText>")).GetValueOrDefault()) { fieldInfo = instruction.operand as FieldInfo; break; } } } if (fieldInfo == null) { BCMHQModule.Logger.LogWarning((object)"Could not find quotaTextAmount in rackUpNewQuotaText enumerator. Quota rackup will not be sped up."); return instructions; } IEnumerable<CodeInstruction> result = instructions; try { result = new CodeMatcher(instructions, (ILGenerator)null).MatchForward(false, (CodeMatch[])(object)new CodeMatch[2] { new CodeMatch((OpCode?)OpCodes.Ldc_R4, (object)250f, (string)null), new CodeMatch((OpCode?)OpCodes.Mul, (object)null, (string)null) }).ThrowIfNotMatch("250f quota increment amount not found", Array.Empty<CodeMatch>()).SetOperandAndAdvance((object)1500f) .InstructionEnumeration(); } catch (Exception arg) { BCMHQModule.Logger.LogWarning((object)$"Could not set new codeinstructions to rackUpNewQuotaText. Exception: {arg}"); } return result; } } [HarmonyPatch] public class ShipLeaveOnQuit { [HarmonyPatch(typeof(QuickMenuManager), "LeaveGameConfirm")] [HarmonyPrefix] private static void ShipLeave(LevelModifications __instance) { if ((Object)(object)GameNetworkManager.Instance != (Object)null && !HUDManager.Instance.retrievingSteamLeaderboard && !StartOfRound.Instance.inShipPhase) { BCMHQModule.Logger.LogInfo((object)"ShipLeave called from LeaveGameConfirm to remove extra enemy spawn attributes."); LevelModifications.OnShipLeave(); } } } [HarmonyPatch] public class ValueSynchronizer { [HarmonyPatch(typeof(Manager), "GetScrapInShip")] [HarmonyPostfix] private static void AddStoredScrapValue(ref float __result) { HQoLNetwork instance = HQoLNetwork.Instance; if ((Object)(object)instance != (Object)null) { __result += HQoLNetwork.Instance.totalStorageValue.Value; } HQoLNetwork instance2 = HQoLNetwork.Instance; if ((Object)(object)instance2 != (Object)null) { __result += HQoLNetwork.Instance.totalStorageValue.Value; } } } [HarmonyPatch] public class PassTimeToNextDayPatcher { [HarmonyPatch(typeof(StartOfRound), "PassTimeToNextDay")] [HarmonyPrefix] public static void PassTimeToNextDayPatch() { if (TimeOfDay.Instance.currentLevel.planetHasTime || TimeOfDay.Instance.profitQuota - TimeOfDay.Instance.quotaFulfilled <= 0) { return; } if (TimeOfDay.Instance.daysUntilDeadline > 0) { if (TimeOfDay.Instance.daysUntilDeadline == 1) { TimeOfDay.Instance.globalTimeAtEndOfDay = 0f; } TimeOfDay instance = TimeOfDay.Instance; instance.timeUntilDeadline -= 1050f; TimeOfDay.Instance.OnDayChanged(); HUDManager.Instance.DisplayDaysLeft((int)Mathf.Floor(TimeOfDay.Instance.timeUntilDeadline / TimeOfDay.Instance.totalTime)); } else { TimeOfDay instance2 = TimeOfDay.Instance; instance2.timeUntilDeadline -= 1050f; } } } } namespace System.Runtime.CompilerServices { [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)] internal sealed class IgnoresAccessChecksToAttribute : Attribute { public IgnoresAccessChecksToAttribute(string assemblyName) { } } }