using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Reflection; using System.Reflection.Emit; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using AnarchyBox; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: AssemblyCompany("AnarchyBox")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyFileVersion("2.5.0.0")] [assembly: AssemblyInformationalVersion("2.5.0")] [assembly: AssemblyProduct("AnarchyBox")] [assembly: AssemblyTitle("AnarchyBox")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("2.5.0.0")] [module: UnverifiableCode] [HarmonyPatch(typeof(ValuableDirector), "SetupHost")] public class ResetPatch { private static void Prefix() { Plugin.ResetRoll(); } } namespace AnarchyBox { [BepInPlugin("anarchy.box", "AnarchyBox", "2.5.0")] public class Plugin : BaseUnityPlugin { internal static ManualLogSource Log; private static int forcedCount; private Harmony harmony; public static ConfigEntry maxAttemptsConfig; public static ConfigEntry forcedSuccessConfig; public static ConfigEntry commonWeightConfig; public static ConfigEntry uncommonWeightConfig; public static ConfigEntry rareWeightConfig; public static ConfigEntry ultraRareWeightConfig; public static ConfigEntry preventStackingConfig; private void Awake() { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Expected O, but got Unknown //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Expected O, but got Unknown //IL_0072: Unknown result type (might be due to invalid IL or missing references) //IL_007c: Expected O, but got Unknown //IL_009d: Unknown result type (might be due to invalid IL or missing references) //IL_00a7: Expected O, but got Unknown //IL_00d0: Unknown result type (might be due to invalid IL or missing references) //IL_00da: Expected O, but got Unknown //IL_0103: Unknown result type (might be due to invalid IL or missing references) //IL_010d: Expected O, but got Unknown //IL_0136: Unknown result type (might be due to invalid IL or missing references) //IL_0140: Expected O, but got Unknown //IL_0168: Unknown result type (might be due to invalid IL or missing references) //IL_0172: Expected O, but got Unknown //IL_01fd: Unknown result type (might be due to invalid IL or missing references) //IL_020b: Expected O, but got Unknown //IL_0231: Unknown result type (might be due to invalid IL or missing references) //IL_023d: Expected O, but got Unknown //IL_0271: Unknown result type (might be due to invalid IL or missing references) //IL_027e: Expected O, but got Unknown //IL_02b1: Unknown result type (might be due to invalid IL or missing references) //IL_02bf: Expected O, but got Unknown Log = ((BaseUnityPlugin)this).Logger; harmony = new Harmony("anarchy.box"); maxAttemptsConfig = ((BaseUnityPlugin)this).Config.Bind("General", "Max Attempts", 25, new ConfigDescription("The maximum attempts for cosmetic loops", (AcceptableValueBase)(object)new AcceptableValueRange(1, 100), Array.Empty())); forcedSuccessConfig = ((BaseUnityPlugin)this).Config.Bind("General", "Forced Successes", 15, new ConfigDescription("How many box successes to force", (AcceptableValueBase)(object)new AcceptableValueRange(0, 100), Array.Empty())); preventStackingConfig = ((BaseUnityPlugin)this).Config.Bind("General", "Prevent Stacking", true, new ConfigDescription("If enabled, boxes will not spawn on occupied points if all unique locations are taken. Highly recommended for multiplayer to avoid crashes!", (AcceptableValueBase)null, Array.Empty())); commonWeightConfig = ((BaseUnityPlugin)this).Config.Bind("Rarity Weights", "Common Weight", 60, new ConfigDescription("Weight of Common boxes.", (AcceptableValueBase)(object)new AcceptableValueRange(0, 100), Array.Empty())); uncommonWeightConfig = ((BaseUnityPlugin)this).Config.Bind("Rarity Weights", "Uncommon Weight", 25, new ConfigDescription("Weight of Uncommon boxes.", (AcceptableValueBase)(object)new AcceptableValueRange(0, 100), Array.Empty())); rareWeightConfig = ((BaseUnityPlugin)this).Config.Bind("Rarity Weights", "Epic Weight", 12, new ConfigDescription("Weight of Rare boxes.", (AcceptableValueBase)(object)new AcceptableValueRange(0, 100), Array.Empty())); ultraRareWeightConfig = ((BaseUnityPlugin)this).Config.Bind("Rarity Weights", "Legendary Weight", 3, new ConfigDescription("Weight of Ultra Rare boxes.", (AcceptableValueBase)(object)new AcceptableValueRange(0, 100), Array.Empty())); ((BaseUnityPlugin)this).Config.Save(); Type type = typeof(ValuableDirector).GetNestedTypes(BindingFlags.NonPublic).FirstOrDefault((Type t) => t.Name.Contains("SetupHost")); if (type == null) { Log.LogError((object)"Could not find the compiler-generated enumerator type for SetupHost. Transpiler patch aborted!"); return; } harmony.Patch((MethodBase)AccessTools.Method(typeof(ValuableDirector), "SetupHost", (Type[])null, (Type[])null), new HarmonyMethod(typeof(Plugin), "ResetRoll", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); harmony.Patch((MethodBase)AccessTools.Method(type, "MoveNext", (Type[])null, (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, new HarmonyMethod(typeof(Plugin), "SetupHostTranspiler", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null); harmony.Patch((MethodBase)AccessTools.Method(typeof(ValuableDirector), "CosmeticWorldObjectLevelLoopsClampedGet", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(AccessTools.Method(typeof(Plugin), "MaxAttemptsPostfix", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); harmony.Patch((MethodBase)AccessTools.Method(typeof(ValuableDirector), "SpawnCosmeticWorldObject", (Type[])null, (Type[])null), new HarmonyMethod(AccessTools.Method(typeof(Plugin), "SpawnResetPrefix", (Type[])null, (Type[])null)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); Log.LogInfo((object)"ANARCHYBOX LOADED!"); } public static int GuaranteedRoll(int min, int max) { if (forcedCount < forcedSuccessConfig.Value) { forcedCount++; Log.LogInfo((object)$"Forcing box success #{forcedCount}"); return 0; } return Random.Range(min, max); } private static IEnumerable SetupHostTranspiler(IEnumerable instructions) { List list = new List(instructions); MethodInfo methodInfo = AccessTools.Method(typeof(Random), "Range", new Type[2] { typeof(int), typeof(int) }, (Type[])null); MethodInfo operand = AccessTools.Method(typeof(Plugin), "GuaranteedRoll", (Type[])null, (Type[])null); bool flag = false; for (int i = 0; i < list.Count - 2; i++) { if (list[i].opcode == OpCodes.Ldc_I4_0 && (list[i + 1].opcode == OpCodes.Ldc_I4_S || list[i + 1].opcode == OpCodes.Ldc_I4) && Convert.ToInt32(list[i + 1].operand) == 100 && CodeInstructionExtensions.Calls(list[i + 2], methodInfo)) { list[i + 2].operand = operand; flag = true; break; } } if (flag) { Log.LogInfo((object)"SetupHostTranspiler: Patched Random.Range"); } return list; } public static void ResetRoll() { if (SemiFunc.IsMasterClientOrSingleplayer()) { forcedCount = 0; Log.LogInfo((object)"Reset anarchy counter on Host"); } } public static void MaxAttemptsPostfix(ref int __result) { __result = maxAttemptsConfig.Value; } public static Rarity PickRarity() { int num = commonWeightConfig.Value + uncommonWeightConfig.Value + rareWeightConfig.Value + ultraRareWeightConfig.Value; if (num > 0) { int num2 = Random.Range(0, num); if (num2 >= commonWeightConfig.Value) { num2 -= commonWeightConfig.Value; if (num2 >= uncommonWeightConfig.Value) { num2 -= uncommonWeightConfig.Value; if (num2 >= rareWeightConfig.Value) { return (Rarity)3; } return (Rarity)2; } return (Rarity)1; } return (Rarity)0; } return (Rarity)0; } public static bool SpawnResetPrefix(int[] _volumeIndex, List[] _volumes, ref Rarity _cosmeticRarity, ValuableDirector __instance) { //IL_000b: 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) //IL_0013: Expected I4, but got Unknown //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Expected I4, but got Unknown //IL_00ba: Unknown result type (might be due to invalid IL or missing references) if (!SemiFunc.IsMasterClientOrSingleplayer()) { return true; } Rarity val = _cosmeticRarity; _cosmeticRarity = (Rarity)(int)PickRarity(); int num = (int)__instance.cosmeticWorldObjectSetups[(int)_cosmeticRarity].volume; if (_volumes == null || num >= _volumes.Length || _volumes[num] == null || _volumes[num].Count == 0) { Log.LogWarning((object)$"Skipped spawning box of rarity {_cosmeticRarity} (No spawn volumes found)"); return false; } if (_volumeIndex[num] >= _volumes[num].Count) { if (preventStackingConfig.Value) { Log.LogInfo((object)$"Prevented stacking: all {_volumes[num].Count} spawn points of volume {num} are occupied. Skipping spawn"); return false; } _volumeIndex[num] = 0; Log.LogWarning((object)"Stacking box on old points!"); } Log.LogInfo((object)$"Box spawn approved on Host: {val} -> {_cosmeticRarity} at volume index {_volumeIndex[num]}"); return true; } } public enum SpawnMode { Volume_Offline, All_Offline, AutoLevel_Online } } public enum SpawnMode { Volume_Offline, All_Offline, AutoLevel_Online } namespace AnarchyBox { public enum SpawnMode__0 { Volume_Offline, All_Offline, AutoLevel_Online } }