using 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.1.0.0")]
[assembly: AssemblyInformationalVersion("1.1.0+07df4298a7f70ed2f8af2e85b45f85440a588791")]
[assembly: AssemblyProduct("BCMHQModule")]
[assembly: AssemblyTitle("Tomatobird.BCMHQModule")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.0.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.1.0")]
[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.1.0 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)("Brutal Company Minus v" + 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"));
Logger.LogDebug((object)"Patching NoMasksPatcher");
Harmony.PatchAll(typeof(NoMasksPatcher));
Logger.LogDebug((object)"Patching GetSafePositionPatcher");
Harmony.PatchAll(typeof(GetSafePositionPatcher));
}
else
{
Logger.LogDebug((object)("BCM Version " + text + " is loaded"));
if (isHQoLLoaded)
{
Logger.LogDebug((object)"Patching ValueSynchronizer");
Harmony.PatchAll(typeof(ValueSynchronizer));
}
else
{
Logger.LogWarning((object)"BCM 50+ loaded without HQoL. ValueSynchronizer won't be used.");
}
}
break;
}
Logger.LogDebug((object)"Patching ShipLeaveOnQuit");
Harmony.PatchAll(typeof(ShipLeaveOnQuit));
Logger.LogDebug((object)"Patching PassTimeToNextDayPatcher");
Harmony.PatchAll(typeof(PassTimeToNextDayPatcher));
Logger.LogDebug((object)"Finished patching!");
}
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.1.0";
}
}
namespace BCMHQModule.Patches
{
[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]
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;
}
}
}
[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)
{
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;
}
}
}
}
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
internal sealed class IgnoresAccessChecksToAttribute : Attribute
{
public IgnoresAccessChecksToAttribute(string assemblyName)
{
}
}
}