using System; 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.Configuration; using BepInEx.Logging; using HarmonyLib; using Microsoft.CodeAnalysis; using Photon.Pun; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("0.0.0.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 ShopDifficulty { [HarmonyPatch(typeof(EnemyDirector))] internal static class EnemyCountPatch { [HarmonyPostfix] [HarmonyPatch("AmountSetup")] private static void AfterAmountSetup(EnemyDirector __instance) { if (Plugin.Enabled.Value && SemiFunc.IsMasterClientOrSingleplayer()) { float value = Plugin.EnemyCountMultiplier.Value; if (!Mathf.Approximately(value, 1f)) { int totalAmount = __instance.totalAmount; __instance.totalAmount = Scale(__instance.totalAmount, value); __instance.amountCurve1Value = Scale(__instance.amountCurve1Value, value); __instance.amountCurve2Value = Scale(__instance.amountCurve2Value, value); __instance.amountCurve3Value = Scale(__instance.amountCurve3Value, value); Plugin.Trace($"[ShopDifficulty] Enemy count {totalAmount} -> {__instance.totalAmount} " + $"(x{value:F2}); tiers {__instance.amountCurve1Value}/" + $"{__instance.amountCurve2Value}/{__instance.amountCurve3Value}"); } } } private static int Scale(int value, float mult) { if (value <= 0) { return value; } return Mathf.Max(1, Mathf.CeilToInt((float)value * mult)); } } [HarmonyPatch(typeof(RoundDirector))] internal static class HaulGoalPatch { private static bool _rebroadcasting; [HarmonyPostfix] [HarmonyPatch("StartRoundLogic")] private static void AfterStartRoundLogic(RoundDirector __instance, int value) { if (!Plugin.Enabled.Value || !Plugin.AllowHaulGoalChanges.Value || _rebroadcasting || !SemiFunc.IsMasterClientOrSingleplayer()) { return; } float value2 = Plugin.HaulGoalMultiplier.Value; if (Mathf.Approximately(value2, 1f)) { return; } int num = Mathf.Max(1, Mathf.CeilToInt((float)value * value2)); if (num == value) { return; } __instance.haulGoal = num; if (SemiFunc.IsMultiplayer() && (Object)(object)__instance.photonView != (Object)null) { _rebroadcasting = true; try { __instance.photonView.RPC("StartRoundRPC", (RpcTarget)1, new object[1] { num }); } finally { _rebroadcasting = false; } } Plugin.Trace($"[ShopDifficulty] Haul goal {value} -> {num} (x{value2:F2})"); } } [BepInPlugin("benjamin.shopdifficulty", "ShopDifficulty", "1.0.0")] [BepInProcess("REPO.exe")] public class Plugin : BaseUnityPlugin { public const string Guid = "benjamin.shopdifficulty"; public const string Name = "ShopDifficulty"; public const string Version = "1.0.0"; internal static ManualLogSource Log; private Harmony _harmony; internal static ConfigEntry Enabled; internal static ConfigEntry ToggleKey; internal static ConfigEntry EnemyCountMultiplier; internal static ConfigEntry HaulGoalMultiplier; internal static ConfigEntry AllowHaulGoalChanges; internal static ConfigEntry Verbose; private void Awake() { //IL_007d: Unknown result type (might be due to invalid IL or missing references) //IL_0087: Expected O, but got Unknown //IL_00ba: Unknown result type (might be due to invalid IL or missing references) //IL_00c4: Expected O, but got Unknown //IL_010f: Unknown result type (might be due to invalid IL or missing references) //IL_0119: Expected O, but got Unknown //IL_0168: Unknown result type (might be due to invalid IL or missing references) Log = ((BaseUnityPlugin)this).Logger; Enabled = ((BaseUnityPlugin)this).Config.Bind("General", "Enabled", true, "Master switch. Turn off to leave difficulty untouched without uninstalling."); ToggleKey = ((BaseUnityPlugin)this).Config.Bind("General", "ToggleKey", (KeyCode)288, "Opens and closes the difficulty panel. Only works while you're in the shop."); EnemyCountMultiplier = ((BaseUnityPlugin)this).Config.Bind("Difficulty", "EnemyCountMultiplier", 1f, new ConfigDescription("Scales how many enemies the next level spawns. 1.0 is vanilla. Adjustable in-game from the shop; this is just where the value persists.", (AcceptableValueBase)(object)new AcceptableValueRange(0.1f, 4f), Array.Empty())); HaulGoalMultiplier = ((BaseUnityPlugin)this).Config.Bind("Difficulty", "HaulGoalMultiplier", 1f, new ConfigDescription("Scales the extraction target for the next level. 1.0 is vanilla.", (AcceptableValueBase)(object)new AcceptableValueRange(0.25f, 3f), Array.Empty())); AllowHaulGoalChanges = ((BaseUnityPlugin)this).Config.Bind("Difficulty", "AllowHaulGoalChanges", true, "Allow the haul goal to be adjusted. The new goal is re-broadcast to clients so they see the same number without needing the mod. Turn off if you only want to change enemy counts."); Verbose = ((BaseUnityPlugin)this).Config.Bind("Debug", "Verbose", false, "Log every difficulty adjustment with the before and after values."); _harmony = new Harmony("benjamin.shopdifficulty"); _harmony.PatchAll(typeof(EnemyCountPatch)); _harmony.PatchAll(typeof(HaulGoalPatch)); ((Component)this).gameObject.AddComponent(); Log.LogInfo((object)string.Format("{0} v{1} loaded. Press {2} in the shop.", "ShopDifficulty", "1.0.0", ToggleKey.Value)); } private void OnDestroy() { Harmony harmony = _harmony; if (harmony != null) { harmony.UnpatchSelf(); } } internal static void Trace(string msg) { if (Verbose != null && Verbose.Value) { Log.LogInfo((object)msg); } } } internal class ShopPanel : MonoBehaviour { private bool _open; private int _row; private static readonly string[] RowNames = new string[2] { "Enemy count", "Haul goal" }; private void Update() { //IL_0029: Unknown result type (might be due to invalid IL or missing references) if (!Plugin.Enabled.Value) { return; } if (!SemiFunc.RunIsShop()) { _open = false; } else { if (!SemiFunc.IsMasterClientOrSingleplayer()) { return; } if (Input.GetKeyDown(Plugin.ToggleKey.Value)) { _open = !_open; } if (_open) { int num = ((!Plugin.AllowHaulGoalChanges.Value) ? 1 : 2); if (Input.GetKeyDown((KeyCode)274)) { _row = (_row + 1) % num; } if (Input.GetKeyDown((KeyCode)273)) { _row = (_row - 1 + num) % num; } float num2 = (Input.GetKey((KeyCode)304) ? 0.05f : 0.25f); if (Input.GetKeyDown((KeyCode)275)) { Adjust(_row, num2); } if (Input.GetKeyDown((KeyCode)276)) { Adjust(_row, 0f - num2); } if (Input.GetKeyDown((KeyCode)8)) { Reset(_row); } } } } private void Adjust(int row, float delta) { if (row == 0) { Plugin.EnemyCountMultiplier.Value = Clamp(Plugin.EnemyCountMultiplier.Value + delta, 0.1f, 4f); } else { Plugin.HaulGoalMultiplier.Value = Clamp(Plugin.HaulGoalMultiplier.Value + delta, 0.25f, 3f); } } private void Reset(int row) { if (row == 0) { Plugin.EnemyCountMultiplier.Value = 1f; } else { Plugin.HaulGoalMultiplier.Value = 1f; } } private static float Clamp(float v, float min, float max) { v = Mathf.Round(v * 100f) / 100f; return Mathf.Clamp(v, min, max); } private void OnGUI() { //IL_0038: Unknown result type (might be due to invalid IL or missing references) //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_007b: Unknown result type (might be due to invalid IL or missing references) //IL_00f3: Unknown result type (might be due to invalid IL or missing references) //IL_00f8: Unknown result type (might be due to invalid IL or missing references) if (_open) { Rect val = default(Rect); ((Rect)(ref val))..ctor(24f, 24f, 340f, 172f); GUI.color = new Color(0f, 0f, 0f, 0.82f); GUI.Box(val, GUIContent.none); GUI.color = Color.white; GUILayout.BeginArea(new Rect(((Rect)(ref val)).x + 14f, ((Rect)(ref val)).y + 12f, 312f, 148f)); GUILayout.Label("Difficulty — applies to the next level", RichLabel(), Array.Empty()); GUILayout.Space(6f); DrawRow(0, RowNames[0], Plugin.EnemyCountMultiplier.Value); if (Plugin.AllowHaulGoalChanges.Value) { DrawRow(1, RowNames[1], Plugin.HaulGoalMultiplier.Value); } GUILayout.Space(8f); GUILayout.Label("Up/Down select · Left/Right adjust · Shift for fine\nBackspace resets · " + ((object)Plugin.ToggleKey.Value/*cast due to .constrained prefix*/).ToString() + " closes", RichLabel(), Array.Empty()); GUILayout.EndArea(); } } private void DrawRow(int index, string label, float value) { string text = ((_row == index) ? "> " : " "); string text2 = (Mathf.Approximately(value, 1f) ? "#cccccc" : ((value > 1f) ? "#ff8a5c" : "#7fd4a0")); GUILayout.Label($"{text}{label} {value:0.00}x", RichLabel(), Array.Empty()); } private static GUIStyle RichLabel() { //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_000f: 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_001e: Expected O, but got Unknown return new GUIStyle(GUI.skin.label) { richText = true, wordWrap = true }; } } public static class MyPluginInfo { public const string PLUGIN_GUID = "ShopDifficulty"; public const string PLUGIN_NAME = "ShopDifficulty"; public const string PLUGIN_VERSION = "1.0.0"; } }