Please disclose if any significant portion of your mod was created 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 BrackenRandomizer v2.0.0
BepInEx/plugins/BrackenRandomizer.dll
Decompiled 2 years agousing System; using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using System.Threading.Tasks; using BepInEx; using BepInEx.Configuration; using BrackenRandomizer; using BrackenRandomizerRewrite.Audio; using BrackenRandomizerRewrite.Managers; using BrackenRandomizerRewrite.Patches; using BrackenRandomizerRewrite.Values; using HarmonyLib; using LethalNetworkAPI; using Steamworks.Data; using Unity.Netcode; using UnityEngine; using UnityEngine.Networking; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("BrackenRandomizer")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyDescription("My first plugin")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("BrackenRandomizer")] [assembly: AssemblyTitle("BrackenRandomizer")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.0.0")] [module: UnverifiableCode] namespace CustomBoomboxTracks.Utilities { public class SharedCoroutineStarter : MonoBehaviour { private static SharedCoroutineStarter _instance; public static Coroutine StartCoroutine(IEnumerator routine) { //IL_0016: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)_instance == (Object)null) { _instance = new GameObject("Shared Coroutine Starter").AddComponent<SharedCoroutineStarter>(); Object.DontDestroyOnLoad((Object)(object)_instance); } return ((MonoBehaviour)_instance).StartCoroutine(routine); } } } namespace BrackenRandomizer { [BepInPlugin("BrackenRandomizer", "BrackenRandomizer", "2.0.0")] public class Plugin : BaseUnityPlugin { public Harmony harmonymain; public static AssetBundle LoadedBundle; public static Plugin instance; private void Awake() { //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Expected O, but got Unknown instance = this; harmonymain = new Harmony("BrackenRandomizer"); harmonymain.PatchAll(); ConfigValues.InitializeConfig(); BundleLoader.LoadBundle(); NetworkManager.Start(); DirectoryManager.CreateFolders(); ((BaseUnityPlugin)this).Logger.LogInfo((object)"BrackenRandomizer loaded."); if (!ConfigValues.customVariationsfromLocalFiles.Value) { ((BaseUnityPlugin)this).Logger.LogInfo((object)$"CONFIG INFO : Default Bracken : {ConfigValues.shouldDefaultBrackenSpawn.Value}, Josh Hutcherson: {ConfigValues.shouldJoshHutchersonSpawn.Value}, Deku: {ConfigValues.shouldDekuSpawn.Value}, Goku: {ConfigValues.shouldGokuSpawn.Value}, Monday: {ConfigValues.shouldMondaySpawn.Value}, Bad to the Bone: {ConfigValues.shouldBadToTheBoneSpawn.Value}, Metal Pipe: {ConfigValues.shouldMetalPipeSpawn.Value}"); } else { ((BaseUnityPlugin)this).Logger.LogInfo((object)$"CONFIG INFO : Default Bracken : {ConfigValues.shouldDefaultBrackenSpawnCustomToggles.Value}, Variation1: {ConfigValues.shouldVariation1Spawn.Value}, Variation2: {ConfigValues.shouldVariation2Spawn.Value}, Variation3: {ConfigValues.shouldVariation3Spawn.Value}, Variation4: {ConfigValues.shouldVariation4Spawn.Value}, Variation5: {ConfigValues.shouldVariation5Spawn.Value}, Variation6: {ConfigValues.shouldVariation6Spawn.Value}"); } ((BaseUnityPlugin)this).Logger.LogInfo((object)$"CONFIG VALUES : {StoredValues.value0}, {StoredValues.value1}, {StoredValues.value2}, {StoredValues.value3}, {StoredValues.value4}, {StoredValues.value5}, {StoredValues.value6}"); } public void Log(object message) { ((BaseUnityPlugin)this).Logger.LogInfo(message); } public void LogError(object message) { ((BaseUnityPlugin)this).Logger.LogError(message); } public void LogWarning(object message) { ((BaseUnityPlugin)this).Logger.LogWarning(message); } public void LogDebug(object message) { ((BaseUnityPlugin)this).Logger.LogDebug(message); } } } namespace BrackenRandomizer.Patches { [HarmonyPatch] internal class BrackenPatch : MonoBehaviour { [HarmonyPatch(typeof(FlowermanAI), "Start")] [HarmonyPostfix] public static void SummonRBracken(FlowermanAI __instance) { //IL_04ec: Unknown result type (might be due to invalid IL or missing references) //IL_04f6: Expected O, but got Unknown //IL_0534: Unknown result type (might be due to invalid IL or missing references) AudioClip val = null; AudioClip val2 = null; AudioClip val3 = null; AudioClip val4 = null; Texture val5 = null; string text = null; string arg = null; int num = -1; PlayAudioAnimationEvent component = ((Component)((Component)__instance).gameObject.transform.Find("FlowermanModel").Find("AnimContainer")).GetComponent<PlayAudioAnimationEvent>(); switch (NetworkManager.currentBrackenRolled.Value) { case 1: if (StartofRoundPatch.isHost) { Plugin.instance.LogDebug("Starting roll as Host"); BrackenManager.roll(); } else if (!StoredValues.doNetworking) { Plugin.instance.LogDebug("Starting roll as Client w/ networking off"); BrackenManager.roll(); } if (!ConfigValues.customVariationsfromLocalFiles.Value) { Plugin.instance.Log($"Summoned Normal Bracken at {StoredValues.defaultRarity} chance"); } else { Plugin.instance.Log($"Summoned Normal Bracken at {StoredValues.customDefaultRarity} chance"); } return; case 2: if (!ConfigValues.customVariationsfromLocalFiles.Value) { val = Plugin.LoadedBundle.LoadAsset<AudioClip>("assets/hutcherson/whistlefull.mp3"); val2 = Plugin.LoadedBundle.LoadAsset<AudioClip>("assets/hutcherson/whistle.mp3"); val3 = Plugin.LoadedBundle.LoadAsset<AudioClip>("assets/hutcherson/placeholder"); val4 = Plugin.LoadedBundle.LoadAsset<AudioClip>("assets/hutcherson/placeholder"); text = "assets/hutcherson/JoshHutcherson.prefab"; arg = "Josh Hutcherson"; num = StoredValues.hutchersonRarity; } else { val = StoredValues.var1creatureAngerVoice; val2 = StoredValues.var1crackNeckAudio; val3 = StoredValues.var1found1; val4 = StoredValues.var1dieSFX; val5 = StoredValues.var1image; text = "assets/DefaultPrefab.prefab"; arg = "Variation1"; num = StoredValues.var1Rarity; } break; case 3: if (!ConfigValues.customVariationsfromLocalFiles.Value) { val = Plugin.LoadedBundle.LoadAsset<AudioClip>("assets/deku/deku_chase_alt.mp3"); val2 = Plugin.LoadedBundle.LoadAsset<AudioClip>("assets/deku/deku_necksnap.mp3"); val3 = Plugin.LoadedBundle.LoadAsset<AudioClip>("assets/deku/deku_growl.mp3"); val4 = Plugin.LoadedBundle.LoadAsset<AudioClip>("assets/deku/deku_growl2.mp3"); text = "assets/deku/Deku.prefab"; arg = "Deku"; num = StoredValues.dekuRarity; } else { val = StoredValues.var2creatureAngerVoice; val2 = StoredValues.var2crackNeckAudio; val3 = StoredValues.var2found1; val4 = StoredValues.var2dieSFX; val5 = StoredValues.var2image; text = "assets/DefaultPrefab.prefab"; arg = "Variation2"; num = StoredValues.var2Rarity; } break; case 4: if (!ConfigValues.customVariationsfromLocalFiles.Value) { val = Plugin.LoadedBundle.LoadAsset<AudioClip>("assets/goku/ultra.mp3"); val2 = Plugin.LoadedBundle.LoadAsset<AudioClip>("assets/goku/mods.mp3"); val4 = Plugin.LoadedBundle.LoadAsset<AudioClip>("assets/goku/mods.mp3"); text = "assets/goku/Gok.prefab"; arg = "Goku"; num = StoredValues.gokuRarity; } else { val = StoredValues.var3creatureAngerVoice; val2 = StoredValues.var3crackNeckAudio; val3 = StoredValues.var3found1; val4 = StoredValues.var3dieSFX; val5 = StoredValues.var3image; text = "assets/DefaultPrefab.prefab"; arg = "Variation3"; num = StoredValues.var3Rarity; } break; case 5: if (!ConfigValues.customVariationsfromLocalFiles.Value) { val = Plugin.LoadedBundle.LoadAsset<AudioClip>("assets/mond/monday.mp3"); val2 = Plugin.LoadedBundle.LoadAsset<AudioClip>("assets/mond/monday.mp3"); val3 = Plugin.LoadedBundle.LoadAsset<AudioClip>("assets/mond/monday.mp3"); text = "assets/mond/Monday.prefab"; arg = "Monday left me Broken"; num = StoredValues.mondayRarity; } else { val = StoredValues.var4creatureAngerVoice; val2 = StoredValues.var4crackNeckAudio; val3 = StoredValues.var4found1; val4 = StoredValues.var4dieSFX; val5 = StoredValues.var4image; text = "assets/DefaultPrefab.prefab"; arg = "Variation4"; num = StoredValues.var4Rarity; } break; case 6: if (!ConfigValues.customVariationsfromLocalFiles.Value) { val = Plugin.LoadedBundle.LoadAsset<AudioClip>("assets/bttb/bttb_full.mp3"); val2 = Plugin.LoadedBundle.LoadAsset<AudioClip>("assets/bttb/bttb.mp3"); val3 = Plugin.LoadedBundle.LoadAsset<AudioClip>("assets/bttb/bttb.mp3"); text = "assets/bttb/BadToTheBone.prefab"; arg = "Bad to the Bone"; num = StoredValues.bttbRarity; } else { val = StoredValues.var5creatureAngerVoice; val2 = StoredValues.var5crackNeckAudio; val3 = StoredValues.var5found1; val4 = StoredValues.var5dieSFX; val5 = StoredValues.var5image; text = "assets/DefaultPrefab.prefab"; arg = "Variation5"; num = StoredValues.var5Rarity; } break; case 7: if (!ConfigValues.customVariationsfromLocalFiles.Value) { val = Plugin.LoadedBundle.LoadAsset<AudioClip>("assets/pipe/bttb_full.mp3"); val2 = Plugin.LoadedBundle.LoadAsset<AudioClip>("assets/bttb/bttb.mp3"); val3 = Plugin.LoadedBundle.LoadAsset<AudioClip>("assets/bttb/bttb.mp3"); text = "assets/bttb/BadToTheBone.prefab"; arg = "Bad to the Bone"; num = StoredValues.bttbRarity; } else { val = StoredValues.var6creatureAngerVoice; val2 = StoredValues.var6crackNeckAudio; val3 = StoredValues.var6found1; val4 = StoredValues.var6dieSFX; val5 = StoredValues.var6image; text = "assets/DefaultPrefab.prefab"; arg = "Variation6"; num = StoredValues.var6Rarity; } break; } Object.Destroy((Object)((Component)((Component)__instance).gameObject.transform.Find("FlowermanModel").Find("LOD1")).gameObject.GetComponent<SkinnedMeshRenderer>()); GameObject val6 = Object.Instantiate<GameObject>(Plugin.LoadedBundle.LoadAsset<GameObject>(text ?? ""), ((Component)__instance).gameObject.transform); val6.transform.localPosition = new Vector3(0f, 2f, 0f); if ((Object)(object)val != (Object)null) { __instance.creatureAngerVoice.clip = val; } if ((Object)(object)val2 != (Object)null) { __instance.crackNeckAudio.clip = val2; __instance.crackNeckSFX = val2; } if ((Object)(object)val4 != (Object)null) { ((EnemyAI)__instance).dieSFX = val4; } if ((Object)(object)val3 != (Object)null) { component.audioClip = val3; } if ((Object)(object)val5 != (Object)null) { Renderer component2 = val6.GetComponent<Renderer>(); component2.material.mainTexture = val5; } if (StartofRoundPatch.isHost) { Plugin.instance.LogDebug("Starting roll as Host"); BrackenManager.roll(); } else if (!StoredValues.doNetworking) { Plugin.instance.LogDebug("Starting roll as Client w/ networking off"); BrackenManager.roll(); } Plugin.instance.Log($"Summoned {arg} at {num} chance"); StoredValues.currentBracken = -1; } } } namespace BrackenRandomizerRewrite { public static class MyPluginInfo { public const string PLUGIN_GUID = "BrackenRandomizer"; public const string PLUGIN_NAME = "BrackenRandomizer"; public const string PLUGIN_VERSION = "1.0.0"; } } namespace BrackenRandomizerRewrite.Values { public class ConfigValues { public static ConfigEntry<bool> doNetworking; public static ConfigEntry<int> defaultBrackenRarity; public static ConfigEntry<int> joshHutchersonRarity; public static ConfigEntry<int> dekuRarity; public static ConfigEntry<int> gokuRarity; public static ConfigEntry<int> mondayRarity; public static ConfigEntry<int> badToTheBoneRarity; public static ConfigEntry<int> metalPipeRarity; public static ConfigEntry<int> defaultBrackenCustomRarity; public static ConfigEntry<List<int>> variationsRarity; public static ConfigEntry<int> variation1Rarity; public static ConfigEntry<int> variation2Rarity; public static ConfigEntry<int> variation3Rarity; public static ConfigEntry<int> variation4Rarity; public static ConfigEntry<int> variation5Rarity; public static ConfigEntry<int> variation6Rarity; public static ConfigEntry<bool> shouldDefaultBrackenSpawn; public static ConfigEntry<bool> shouldDefaultBrackenSpawnCustomToggles; public static ConfigEntry<bool> shouldJoshHutchersonSpawn; public static ConfigEntry<bool> shouldDekuSpawn; public static ConfigEntry<bool> shouldGokuSpawn; public static ConfigEntry<bool> shouldMondaySpawn; public static ConfigEntry<bool> shouldBadToTheBoneSpawn; public static ConfigEntry<bool> shouldMetalPipeSpawn; public static ConfigEntry<bool> shouldVariation1Spawn; public static ConfigEntry<bool> shouldVariation2Spawn; public static ConfigEntry<bool> shouldVariation3Spawn; public static ConfigEntry<bool> shouldVariation4Spawn; public static ConfigEntry<bool> shouldVariation5Spawn; public static ConfigEntry<bool> shouldVariation6Spawn; public static ConfigEntry<bool> customVariationsfromLocalFiles; public static void InitializeConfig() { defaultBrackenRarity = ((BaseUnityPlugin)Plugin.instance).Config.Bind<int>("Variations", "NormalBrackenRarity", 25, "Standard Bracken Spawnrate"); joshHutchersonRarity = ((BaseUnityPlugin)Plugin.instance).Config.Bind<int>("Variations", "JoshHutchersonRarity", 20, "Josh Hutcherson Variation Spawnrate"); dekuRarity = ((BaseUnityPlugin)Plugin.instance).Config.Bind<int>("Variations", "DekuRarity", 15, "Deku Variation Spawnrate"); gokuRarity = ((BaseUnityPlugin)Plugin.instance).Config.Bind<int>("Variations", "GokuRarity", 15, "Goku Variation Spawnrate"); mondayRarity = ((BaseUnityPlugin)Plugin.instance).Config.Bind<int>("Variations", "MondayLeftMeBrokenRarity", 10, "Monday left me Broken Variation Spawnrate"); badToTheBoneRarity = ((BaseUnityPlugin)Plugin.instance).Config.Bind<int>("Variations", "BadToTheBoneRarity", 10, "Bad to the Bone Variation Spawnrate"); metalPipeRarity = ((BaseUnityPlugin)Plugin.instance).Config.Bind<int>("Variations", "MetalPipeRarity", 5, "Metal Pipe Variation Spawnrate"); shouldDefaultBrackenSpawn = ((BaseUnityPlugin)Plugin.instance).Config.Bind<bool>("Variations.Toggles", "shouldDefaultBrackenSpawn?", true, (ConfigDescription)null); shouldJoshHutchersonSpawn = ((BaseUnityPlugin)Plugin.instance).Config.Bind<bool>("Variations.Toggles", "shouldJoshHutchersonSpawn?", true, (ConfigDescription)null); shouldDekuSpawn = ((BaseUnityPlugin)Plugin.instance).Config.Bind<bool>("Variations.Toggles", "shouldDekuSpawn?", true, (ConfigDescription)null); shouldGokuSpawn = ((BaseUnityPlugin)Plugin.instance).Config.Bind<bool>("Variations.Toggles", "shouldGokuSpawn?", true, (ConfigDescription)null); shouldMondaySpawn = ((BaseUnityPlugin)Plugin.instance).Config.Bind<bool>("Variations.Toggles", "shouldMondayLeftMeBrokenSpawn?", true, (ConfigDescription)null); shouldBadToTheBoneSpawn = ((BaseUnityPlugin)Plugin.instance).Config.Bind<bool>("Variations.Toggles", "shouldBadToTheBoneSpawn?", true, (ConfigDescription)null); shouldMetalPipeSpawn = ((BaseUnityPlugin)Plugin.instance).Config.Bind<bool>("Variations.Toggles", "shouldMetalPipeSpawn?", true, (ConfigDescription)null); customVariationsfromLocalFiles = ((BaseUnityPlugin)Plugin.instance).Config.Bind<bool>("Custom.Variation.Toggle", "customVariationsfromFiles", false, "allows Custom Brackens to be created from local files (DISABLES INCLUDED BRACKENS)"); defaultBrackenCustomRarity = ((BaseUnityPlugin)Plugin.instance).Config.Bind<int>("Custom.Variations", "DefaultBrackenRarity", 0, "Default Bracken Spawnrate (Only applies if customVariationsfromLocalFiles is true!)"); variation1Rarity = ((BaseUnityPlugin)Plugin.instance).Config.Bind<int>("Custom.Variations", "Variation1Rarity", 20, "Spawnchance for which Variation1 will spawn at. Will only apply if customVariationsfromLocalFiles is true"); variation2Rarity = ((BaseUnityPlugin)Plugin.instance).Config.Bind<int>("Custom.Variations", "Variation2Rarity", 20, "Spawnchance for which Variation2 will spawn at. Will only apply if customVariationsfromLocalFiles is true"); variation3Rarity = ((BaseUnityPlugin)Plugin.instance).Config.Bind<int>("Custom.Variations", "Variation3Rarity", 20, "Spawnchance for which Variation3 will spawn at. Will only apply if customVariationsfromLocalFiles is true"); variation4Rarity = ((BaseUnityPlugin)Plugin.instance).Config.Bind<int>("Custom.Variations", "Variation4Rarity", 20, "Spawnchance for which Variation4 will spawn at. Will only apply if customVariationsfromLocalFiles is true"); variation5Rarity = ((BaseUnityPlugin)Plugin.instance).Config.Bind<int>("Custom.Variations", "Variation5Rarity", 20, "Spawnchance for which Variation5 will spawn at. Will only apply if customVariationsfromLocalFiles is true"); variation6Rarity = ((BaseUnityPlugin)Plugin.instance).Config.Bind<int>("Custom.Variations", "Variation6Rarity", 20, "Spawnchance for which Variation6 will spawn at. Will only apply if customVariationsfromLocalFiles is true"); shouldDefaultBrackenSpawnCustomToggles = ((BaseUnityPlugin)Plugin.instance).Config.Bind<bool>("Custom.Variations.Toggles", "shouldDefaultBrackenSpawn?", true, "Only applies if customVariationsfromLocalFiles is true!"); shouldVariation1Spawn = ((BaseUnityPlugin)Plugin.instance).Config.Bind<bool>("Custom.Variations.Toggles", "shouldVariation1Spawn?", true, "Only applies if customVariationsfromLocalFiles is true!"); shouldVariation2Spawn = ((BaseUnityPlugin)Plugin.instance).Config.Bind<bool>("Custom.Variations.Toggles", "shouldVariation2Spawn?", true, "Only applies if customVariationsfromLocalFiles is true!"); shouldVariation3Spawn = ((BaseUnityPlugin)Plugin.instance).Config.Bind<bool>("Custom.Variations.Toggles", "shouldVariation3Spawn?", true, "Only applies if customVariationsfromLocalFiles is true!"); shouldVariation4Spawn = ((BaseUnityPlugin)Plugin.instance).Config.Bind<bool>("Custom.Variations.Toggles", "shouldVariation4Spawn?", true, "Only applies if customVariationsfromLocalFiles is true!"); shouldVariation5Spawn = ((BaseUnityPlugin)Plugin.instance).Config.Bind<bool>("Custom.Variations.Toggles", "shouldVariation5Spawn?", true, "Only applies if customVariationsfromLocalFiles is true!"); shouldVariation6Spawn = ((BaseUnityPlugin)Plugin.instance).Config.Bind<bool>("Custom.Variations.Toggles", "shouldVariation6Spawn?", true, "Only applies if customVariationsfromLocalFiles is true!"); doNetworking = ((BaseUnityPlugin)Plugin.instance).Config.Bind<bool>("Networking", "doNetworking?", true, "If host has mod, will sync variations between players. Disabling will make mod completely client sided."); DoConfigMath(); } public static void DoConfigMath() { if (!customVariationsfromLocalFiles.Value) { StoredValues.defaultRarity = (StoredValues.hutchersonRarity = (StoredValues.dekuRarity = (StoredValues.gokuRarity = (StoredValues.mondayRarity = (StoredValues.bttbRarity = (StoredValues.pipeRarity = 0)))))); if (shouldDefaultBrackenSpawn.Value) { StoredValues.defaultRarity = defaultBrackenRarity.Value; } if (shouldJoshHutchersonSpawn.Value) { StoredValues.hutchersonRarity = joshHutchersonRarity.Value; } if (shouldDekuSpawn.Value) { StoredValues.dekuRarity = dekuRarity.Value; } if (shouldGokuSpawn.Value) { StoredValues.gokuRarity = gokuRarity.Value; } if (shouldMondaySpawn.Value) { StoredValues.mondayRarity = mondayRarity.Value; } if (shouldBadToTheBoneSpawn.Value) { StoredValues.bttbRarity = badToTheBoneRarity.Value; } if (shouldMetalPipeSpawn.Value) { StoredValues.pipeRarity = metalPipeRarity.Value; } StoredValues.value0 = StoredValues.defaultRarity; StoredValues.value1 = StoredValues.value0 + StoredValues.hutchersonRarity; StoredValues.value2 = StoredValues.value1 + StoredValues.dekuRarity; StoredValues.value3 = StoredValues.value2 + StoredValues.gokuRarity; StoredValues.value4 = StoredValues.value3 + StoredValues.mondayRarity; StoredValues.value5 = StoredValues.value4 + StoredValues.bttbRarity; StoredValues.value6 = StoredValues.value5 + StoredValues.pipeRarity; return; } StoredValues.customDefaultRarity = (StoredValues.var1Rarity = (StoredValues.var2Rarity = (StoredValues.var3Rarity = (StoredValues.var4Rarity = (StoredValues.var5Rarity = (StoredValues.var6Rarity = 0)))))); if (shouldDefaultBrackenSpawnCustomToggles.Value) { StoredValues.customDefaultRarity = defaultBrackenCustomRarity.Value; } if (shouldVariation1Spawn.Value) { StoredValues.var1Rarity = variation1Rarity.Value; } if (shouldVariation2Spawn.Value) { StoredValues.var2Rarity = variation2Rarity.Value; } if (shouldVariation3Spawn.Value) { StoredValues.var3Rarity = variation3Rarity.Value; } if (shouldVariation4Spawn.Value) { StoredValues.var4Rarity = variation4Rarity.Value; } if (shouldVariation5Spawn.Value) { StoredValues.var5Rarity = variation5Rarity.Value; } if (shouldVariation6Spawn.Value) { StoredValues.var6Rarity = variation6Rarity.Value; } StoredValues.value0 = StoredValues.customDefaultRarity; StoredValues.value1 = StoredValues.value0 + StoredValues.var1Rarity; StoredValues.value2 = StoredValues.value1 + StoredValues.var2Rarity; StoredValues.value3 = StoredValues.value2 + StoredValues.var3Rarity; StoredValues.value4 = StoredValues.value3 + StoredValues.var4Rarity; StoredValues.value5 = StoredValues.value4 + StoredValues.var5Rarity; StoredValues.value6 = StoredValues.value5 + StoredValues.var6Rarity; if (!doNetworking.Value) { StoredValues.clientSide = true; } } } public class StoredValues { public static AudioClip var1crackNeckAudio = null; public static AudioClip var1creatureAngerVoice = null; public static AudioClip var1found1 = null; public static AudioClip var1dieSFX = null; public static Texture var1image = null; public static AudioClip var2crackNeckAudio = null; public static AudioClip var2creatureAngerVoice = null; public static AudioClip var2found1 = null; public static AudioClip var2dieSFX = null; public static Texture var2image = null; public static AudioClip var3crackNeckAudio = null; public static AudioClip var3creatureAngerVoice = null; public static AudioClip var3found1 = null; public static AudioClip var3dieSFX = null; public static Texture var3image = null; public static AudioClip var4crackNeckAudio = null; public static AudioClip var4creatureAngerVoice = null; public static AudioClip var4found1 = null; public static AudioClip var4dieSFX = null; public static Texture var4image = null; public static AudioClip var5crackNeckAudio = null; public static AudioClip var5creatureAngerVoice = null; public static AudioClip var5found1 = null; public static AudioClip var5dieSFX = null; public static Texture var5image = null; public static AudioClip var6crackNeckAudio = null; public static AudioClip var6creatureAngerVoice = null; public static AudioClip var6found1 = null; public static AudioClip var6dieSFX = null; public static Texture var6image = null; public static bool clientSide; public static bool doNetworking; public static int currentBracken = -1; public static int caseSwitch = -1; public static int value0; public static int value1; public static int value2; public static int value3; public static int value4; public static int value5; public static int value6; public static int defaultRarity; public static int hutchersonRarity; public static int dekuRarity; public static int gokuRarity; public static int mondayRarity; public static int bttbRarity; public static int pipeRarity = 0; public static int customDefaultRarity; public static int var1Rarity; public static int var2Rarity; public static int var3Rarity; public static int var4Rarity; public static int var5Rarity; public static int var6Rarity = 0; } } namespace BrackenRandomizerRewrite.Patches { [HarmonyPatch] internal class StartofRoundPatch { public static bool isHost = ((NetworkBehaviour)RoundManager.Instance).IsHost; public static bool isInLobby = GameNetworkManager.Instance.currentLobby.HasValue; public static int caseSwitch = -1; public static bool firstinit = true; [HarmonyPatch(typeof(RoundManager), "Start")] [HarmonyPostfix] private static async void Postfix() { StoredValues.doNetworking = false; if (!StoredValues.clientSide) { Lobby valueOrDefault; if (isHost) { if (isInLobby) { Lobby? currentLobby = GameNetworkManager.Instance.currentLobby; if (currentLobby.HasValue) { valueOrDefault = currentLobby.GetValueOrDefault(); ((Lobby)(ref valueOrDefault)).SetData("hasBrackenRandomizer", "true"); } } } else if (isInLobby) { Lobby? currentLobby = GameNetworkManager.Instance.currentLobby; object obj; if (!currentLobby.HasValue) { obj = null; } else { valueOrDefault = currentLobby.GetValueOrDefault(); obj = ((Lobby)(ref valueOrDefault)).GetData("hasBrackenRandomizer"); } if (obj != null) { Plugin.instance.Log("Mod detected on host, setting networking to true."); StoredValues.doNetworking = true; } } } Plugin.instance.LogDebug($"doNetworking = {StoredValues.doNetworking}, clientSide = {StoredValues.clientSide}"); if (!firstinit) { return; } if (!ConfigValues.customVariationsfromLocalFiles.Value) { firstinit = false; Plugin.instance.LogDebug("Custom Variations are Disabled"); return; } if (ConfigValues.shouldVariation1Spawn.Value) { StoredValues.var1crackNeckAudio = await AudioManager.LoadAudioClip("Variant1", "crackNeckAudio"); StoredValues.var1creatureAngerVoice = await AudioManager.LoadAudioClip("Variant1", "creatureAngerVoice"); StoredValues.var1found1 = await AudioManager.LoadAudioClip("Variant1", "spotted"); StoredValues.var1dieSFX = await AudioManager.LoadAudioClip("Variant1", "dieSFX"); StoredValues.var1image = await TextureManager.LoadTexture("Variant1", "BrackenImage"); } if (ConfigValues.shouldVariation2Spawn.Value) { StoredValues.var2crackNeckAudio = await AudioManager.LoadAudioClip("Variant2", "crackNeckAudio"); StoredValues.var2creatureAngerVoice = await AudioManager.LoadAudioClip("Variant2", "creatureAngerVoice"); StoredValues.var2found1 = await AudioManager.LoadAudioClip("Variant2", "spotted"); StoredValues.var2dieSFX = await AudioManager.LoadAudioClip("Variant2", "dieSFX"); StoredValues.var2image = await TextureManager.LoadTexture("Variant2", "BrackenImage"); } if (ConfigValues.shouldVariation3Spawn.Value) { StoredValues.var3crackNeckAudio = await AudioManager.LoadAudioClip("Variant3", "crackNeckAudio"); StoredValues.var3creatureAngerVoice = await AudioManager.LoadAudioClip("Variant3", "creatureAngerVoice"); StoredValues.var3found1 = await AudioManager.LoadAudioClip("Variant3", "spotted"); StoredValues.var3dieSFX = await AudioManager.LoadAudioClip("Variant3", "dieSFX"); StoredValues.var3image = await TextureManager.LoadTexture("Variant3", "BrackenImage"); } if (ConfigValues.shouldVariation4Spawn.Value) { StoredValues.var4crackNeckAudio = await AudioManager.LoadAudioClip("Variant4", "crackNeckAudio"); StoredValues.var4creatureAngerVoice = await AudioManager.LoadAudioClip("Variant4", "creatureAngerVoice"); StoredValues.var4found1 = await AudioManager.LoadAudioClip("Variant4", "spotted"); StoredValues.var4dieSFX = await AudioManager.LoadAudioClip("Variant4", "dieSFX"); StoredValues.var4image = await TextureManager.LoadTexture("Variant4", "BrackenImage"); } if (ConfigValues.shouldVariation5Spawn.Value) { StoredValues.var5crackNeckAudio = await AudioManager.LoadAudioClip("Variant5", "crackNeckAudio"); StoredValues.var5creatureAngerVoice = await AudioManager.LoadAudioClip("Variant5", "creatureAngerVoice"); StoredValues.var5found1 = await AudioManager.LoadAudioClip("Variant5", "spotted"); StoredValues.var5dieSFX = await AudioManager.LoadAudioClip("Variant5", "dieSFX"); StoredValues.var5image = await TextureManager.LoadTexture("Variant5", "BrackenImage"); } if (ConfigValues.shouldVariation6Spawn.Value) { StoredValues.var6crackNeckAudio = await AudioManager.LoadAudioClip("Variant6", "crackNeckAudio"); StoredValues.var6creatureAngerVoice = await AudioManager.LoadAudioClip("Variant6", "creatureAngerVoice"); StoredValues.var6found1 = await AudioManager.LoadAudioClip("Variant6", "spotted"); StoredValues.var6dieSFX = await AudioManager.LoadAudioClip("Variant6", "dieSFX"); StoredValues.var6image = await TextureManager.LoadTexture("Variant6", "BrackenImage"); } firstinit = false; } [HarmonyPatch(typeof(RoundManager), "LoadNewLevel")] [HarmonyPrefix] private static void StartOfRoundPatch() { if (isHost) { Plugin.instance.LogDebug("Starting roll as Host"); BrackenManager.roll(); } else if (!StoredValues.doNetworking) { Plugin.instance.LogDebug("Starting roll as Client w/ networking off"); BrackenManager.roll(); } } } } namespace BrackenRandomizerRewrite.Managers { internal class BrackenManager { public static void roll() { Plugin.instance.LogDebug("Rolling..."); StoredValues.caseSwitch = new Random().Next(1, StoredValues.value6); brackenParse(StoredValues.caseSwitch); Plugin.instance.Log($"Rolled {StoredValues.caseSwitch}!"); } public static void brackenParse(int rollValue) { if (rollValue < StoredValues.value0 && rollValue >= 0) { NetworkManager.setBrackenData(1); return; } int num = rollValue; if (num < StoredValues.value1 && num >= StoredValues.value0) { NetworkManager.setBrackenData(2); return; } int num2 = rollValue; if (num2 < StoredValues.value2 && num2 >= StoredValues.value1) { NetworkManager.setBrackenData(3); return; } int num3 = rollValue; if (num3 < StoredValues.value3 && num3 >= StoredValues.value2) { NetworkManager.setBrackenData(4); return; } int num4 = rollValue; if (num4 < StoredValues.value4 && num4 >= StoredValues.value3) { NetworkManager.setBrackenData(5); return; } int num5 = rollValue; if (num5 < StoredValues.value5 && num5 >= StoredValues.value4) { NetworkManager.setBrackenData(6); return; } int num6 = rollValue; if (num6 < StoredValues.value6 && num6 >= StoredValues.value5) { NetworkManager.setBrackenData(7); } } } internal class BundleLoader { public static void LoadBundle() { string text = Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)Plugin.instance).Info.Location), "brackenrandomizer"); AssetBundle val = AssetBundle.LoadFromFile(text); if ((Object)(object)val == (Object)null) { Plugin.instance.LogError("Failed to load BrackenRandomizer AssetBundle! (Bundle should be located in the same folder as mod!)"); return; } Plugin.instance.Log("Successfully loaded BrackenRandomizer AssetBundle!"); Plugin.LoadedBundle = val; } } internal class DirectoryManager { public static readonly string directory = Path.Combine(Paths.PluginPath, "Woona-BrackenRandomizer", "CustomVariantsFolder"); public static readonly string modDirectory = Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)Plugin.instance).Info.Location)); public static void CreateFolders() { if (!ConfigValues.customVariationsfromLocalFiles.Value) { return; } if (Directory.Exists(directory)) { for (int i = 1; i < 7; i++) { CreateSubfolders($"Variant{i}"); } return; } Directory.CreateDirectory(directory); Plugin.instance.Log("Created directory at " + directory); Plugin.instance.Log("Creating subdirectories..."); for (int j = 1; j < 7; j++) { CreateSubfolders($"Variant{j}"); } } public static void CreateSubfolders(string Subfolder) { string path = Path.Combine(directory, Subfolder, "Audio"); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); Plugin.instance.Log("Created Subfolder " + Subfolder); } } } internal class NetworkManager { public static LethalNetworkVariable<int> currentBrackenRolled = new LethalNetworkVariable<int>("currentBrackenRolled") { Value = -1 }; public static void Start() { currentBrackenRolled.OnValueChanged += BrackenDataRecieved; } public static void BrackenDataRecieved(int brackenData) { StoredValues.currentBracken = brackenData; if (!StoredValues.clientSide && StoredValues.doNetworking && !StartofRoundPatch.isHost) { Plugin.instance.Log($"Recieved data ({StoredValues.currentBracken}) from Server!"); } } public static void setBrackenData(int brackenData) { currentBrackenRolled.Value = brackenData; Plugin.instance.LogDebug("Data set on Server."); } } internal class TextureManager { public static readonly string directory = Path.Combine(Paths.PluginPath, "Woona-BrackenRandomizer", "CustomVariantsFolder"); public static async Task<Texture> LoadTexture(string currentDir, string currentFile) { string[] fileList = Directory.GetFiles(Path.Combine(directory, currentDir), currentFile + ".png").Union(Directory.GetFiles(Path.Combine(directory, currentDir), currentFile + ".jpg").Union(Directory.GetFiles(Path.Combine(directory, currentDir), currentFile + ".jpeg"))).ToArray(); StringCollection fileCheck = new StringCollection(); fileCheck.AddRange(fileList); if (fileCheck.Count == 0) { Plugin.instance.LogWarning("No file matching " + currentFile + " in " + currentDir); return null; } Plugin.instance.Log("Preparing to load " + currentFile + " from " + currentDir + "..."); string filePath = fileList[0]; Plugin.instance.Log("Loading " + filePath + "!"); UnityWebRequest webreq = UnityWebRequestTexture.GetTexture(filePath); UnityWebRequestAsyncOperation webreqasync = webreq.SendWebRequest(); while (!((AsyncOperation)webreqasync).isDone) { await Task.Yield(); } if (webreq.error != null) { Plugin.instance.LogError("Webrequest error loading " + currentFile + " in " + currentDir + "\n" + filePath); Plugin.instance.LogError(webreq.error); return null; } Texture2D texture = DownloadHandlerTexture.GetContent(webreq); Plugin.instance.Log("Loaded " + filePath); return (Texture)(object)texture; } } } namespace BrackenRandomizerRewrite.Audio { internal class AudioManager { public static readonly string directory = Path.Combine(Paths.PluginPath, "Woona-BrackenRandomizer", "CustomVariantsFolder"); public static async Task<AudioClip> LoadAudioClip(string currentDir, string currentFile) { string[] fileList = Directory.GetFiles(Path.Combine(directory, currentDir, "Audio"), currentFile + ".*"); StringCollection fileCheck = new StringCollection(); fileCheck.AddRange(fileList); if (fileCheck.Count == 0) { Plugin.instance.LogWarning("No file matching " + currentFile + " in " + currentDir + "."); return null; } Plugin.instance.Log("Preparing to load " + currentFile + " from " + currentDir + "..."); string filePath = fileList[0]; Plugin.instance.Log("Loading " + filePath + "!"); AudioType audioType = GetAudioType(filePath); if ((int)audioType == 0) { Plugin.instance.LogError("Failed to load " + currentFile + " from " + currentDir + "\n" + filePath); return null; } UnityWebRequest webreq = UnityWebRequestMultimedia.GetAudioClip(filePath, GetAudioType(filePath)); webreq.SendWebRequest(); while (!webreq.isDone) { await Task.Yield(); } if (webreq.error != null) { Plugin.instance.LogError("Webrequest error loading " + currentFile + " in " + currentDir + "\n" + filePath + "\n" + webreq.error); return null; } AudioClip clip = DownloadHandlerAudioClip.GetContent(webreq); while ((int)clip.loadState != 2) { await Task.Yield(); } Plugin.instance.Log("Loaded " + filePath); return clip; } private static AudioType GetAudioType(string filePath) { //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_006b: Unknown result type (might be due to invalid IL or missing references) //IL_0068: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Unknown result type (might be due to invalid IL or missing references) string text = Path.GetExtension(filePath).ToLower(); switch (text) { case ".mp3": return (AudioType)13; case ".wav": return (AudioType)20; case ".ogg": return (AudioType)14; default: Plugin.instance.LogError(filePath + " contains an unsupported file extension (" + text + ")! Supported file extensions are WAV, MP3, & OGG."); return (AudioType)0; } } } }