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 CompatShield v1.4.54
patchers/CompatShield.dll
Decompiled 2 weeks ago
The result has been truncated due to the large size, download it to view full contents!
using System; using System.Collections; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Diagnostics; using System.Globalization; using System.IO; using System.Linq; using System.Linq.Expressions; using System.Reflection; using System.Reflection.Emit; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using System.Text; using System.Text.RegularExpressions; using System.Threading; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using Mono.Cecil; using Mono.Cecil.Cil; using Mono.Collections.Generic; using MonoMod.Cil; using MonoMod.RuntimeDetour; using MonoMod.RuntimeDetour.HookGen; using MonoMod.Utils; using UnityEngine; using UnityEngine.AddressableAssets; using UnityEngine.AddressableAssets.ResourceLocators; using UnityEngine.ResourceManagement.AsyncOperations; using UnityEngine.SceneManagement; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = "")] [assembly: AssemblyCompany("CompatShield")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("CompatShield")] [assembly: AssemblyTitle("CompatShield")] [assembly: AssemblyVersion("1.0.0.0")] namespace CompatShield; public static class CompatShieldPatcher { private static string preloadNote; internal static ManualLogSource Log; private static Harmony harmony; private static readonly HashSet<string> appliedFixes = new HashSet<string>(); private static bool paladinFixEnabled; private static bool tinkersIsolationEnabled; internal static bool TinkersLanguageFixEnabled; private static int monsterLimit; private static float spawnCredits; private static float printerWeight; private static float scrapperWeight; private static float combinerWeight; private static float droneSpawnWeight; private static float droneHealth; private static bool droneNoMinStage; private static bool interactableTweakApplied; private static bool spawnTweakApplied; private static bool assetRedirect; private static bool assetRedirectApplied; private static bool stopSoundFix; private static bool zetDropFix; private static bool gasolineFix; private static bool gasolineApplied; private static bool handlerGuard; private static bool printToInventoryFix; private static bool infernoMithrixFix; private static bool infernoBoostFix; private static bool infernoCooldownFix; private static bool infernoHookChurnFix; private static bool respawnHookChurnFix; private static bool lunarPoolLoopStopFix; private static bool shamanModelFix; private static bool soundTracer; private static bool soundTracerApplied; private static bool orphanLoopGuard; private static bool lagTracer; private static bool lagTracerApplied; private static bool physicsPileupTracer; private static bool physicsPileupApplied; private static bool bigHitTracer; private static bool bigHitApplied; private static bool hookTimer; private static bool hookTimerApplied; private static string lockedItems; private static bool lockedItemsApplied; private static float physicsCatchUpCap; private static float statUpdateInterval; private static int hardEnemyCap; private static float damageChainDrainMs; private static int damageChainQueueLimit; private static bool physicsCapApplied; private static bool statLimitApplied; private static bool hardCapApplied; private static bool damageChainGuard; private static bool damageChainGuardApplied; private static bool hypercritNullFix; private static int blastChainMaxDepth; private static float blastChainBudgetMs; private static bool blastChainCap; private static bool blastChainCapApplied; private static bool blastTargetGuard; private static bool blastTargetGuardApplied; private static bool statsRetryGuard; private static bool statsRetryGuardApplied; private static bool overlapHitGuard; private static bool overlapHitGuardApplied; private static bool dotTickGuard; private static bool dotTickGuardApplied; private static bool bulletHitGuard; private static bool bulletHitGuardApplied; private static bool totemTetherGuard; private static bool totemTetherGuardApplied; private static bool rouletteSpinCost; private static bool rouletteSpinCostApplied; private static bool bubbetsFix; private static bool linearDamageFix; private static bool skillSlotsHudFix; private static bool daggerOfFrenzyGuard; private static bool thetaShieldLoopFix; private static bool hallowedIchorTimerFix; private static bool paladinShockwaveFix; private static bool fireTrailFix; private static bool sharpAnchorFix; private static float acolyteAttackSpeed; private static bool acolyteTweakApplied; private static bool nullDccsPoolEntryFix; private static bool nullDccsPoolEntryFixApplied; private static bool disableGenetics; private static bool disableGeneticsApplied; private static bool swiftImpactFix; private static bool shareSuiteSacrificeFix; private static bool flowerRootFix; private static bool flowerRootApplied; private static bool scepterFlowerFix; private static bool stunDurationFix; private static bool stunDurationApplied; private static float sacrificeDropMult; private static bool sacrificeApplied; private static string sacrificeKeepList; private static float sacrificeKeptWeight; private static bool sacrificeKeepApplied; public static IEnumerable<string> TargetDLLs { get; } = new string[1] { "RoR2.dll" }; private static bool InteractableTweakWanted { get { if ((!(printerWeight >= 0f) || !(Math.Abs(printerWeight - 1f) > 0.001f)) && (!(scrapperWeight >= 0f) || !(Math.Abs(scrapperWeight - 1f) > 0.001f)) && (!(combinerWeight >= 0f) || !(Math.Abs(combinerWeight - 1f) > 0.001f)) && !droneNoMinStage && (!(droneSpawnWeight >= 0f) || !(Math.Abs(droneSpawnWeight - 1f) > 0.001f))) { if (droneHealth > 0f) { return Math.Abs(droneHealth - 1f) > 0.001f; } return false; } return true; } } private static bool SpawnTweakWanted { get { if (spawnCredits > 0f) { return Math.Abs(spawnCredits - 1f) > 0.001f; } return false; } } private static bool SacrificeTweakWanted { get { if (sacrificeDropMult >= 0f) { return Math.Abs(sacrificeDropMult - 1f) > 0.001f; } return false; } } private static bool SacrificeKeepWanted => !string.IsNullOrWhiteSpace(sacrificeKeepList); public static void Patch(AssemblyDefinition assembly) { //IL_00a9: Unknown result type (might be due to invalid IL or missing references) //IL_00af: Expected O, but got Unknown //IL_00cc: Unknown result type (might be due to invalid IL or missing references) //IL_00d6: Expected O, but got Unknown //IL_00f3: Unknown result type (might be due to invalid IL or missing references) //IL_00fd: Expected O, but got Unknown //IL_0109: Unknown result type (might be due to invalid IL or missing references) //IL_0114: Unknown result type (might be due to invalid IL or missing references) //IL_011f: Unknown result type (might be due to invalid IL or missing references) //IL_012a: Unknown result type (might be due to invalid IL or missing references) //IL_0135: Unknown result type (might be due to invalid IL or missing references) if (((AssemblyNameReference)assembly.Name).Name != "RoR2") { return; } try { TypeDefinition type = assembly.MainModule.GetType("RoR2.Inventory"); MethodDefinition val = ((type != null) ? ((IEnumerable<MethodDefinition>)type.Methods).FirstOrDefault((Func<MethodDefinition, bool>)((MethodDefinition m) => Takes(m, "RemoveItem2"))) : null); if (val != null && !((IEnumerable<MethodDefinition>)type.Methods).Any((MethodDefinition m) => Takes(m, "RemoveItem"))) { MethodDefinition val2 = new MethodDefinition("RemoveItem", (MethodAttributes)134, assembly.MainModule.TypeSystem.Void); ((MethodReference)val2).Parameters.Add(new ParameterDefinition("itemDef", (ParameterAttributes)0, ((ParameterReference)((MethodReference)val).Parameters[0]).ParameterType)); ((MethodReference)val2).Parameters.Add(new ParameterDefinition("count", (ParameterAttributes)0, ((ParameterReference)((MethodReference)val).Parameters[1]).ParameterType)); ILProcessor iLProcessor = val2.Body.GetILProcessor(); iLProcessor.Emit(OpCodes.Ldarg_0); iLProcessor.Emit(OpCodes.Ldarg_1); iLProcessor.Emit(OpCodes.Ldarg_2); iLProcessor.Emit(OpCodes.Call, (MethodReference)(object)val); iLProcessor.Emit(OpCodes.Ret); type.Methods.Add(val2); preloadNote = "Game: Inventory.RemoveItem(ItemDef, int) added back in memory for mods built before 1.5.0"; } } catch (Exception ex) { preloadNote = "Couldn't add Inventory.RemoveItem(ItemDef, int): " + ex.Message; } static bool Takes(MethodDefinition m, string name) { if (((MemberReference)m).Name == name && !m.IsStatic && ((MethodReference)m).Parameters.Count == 2 && ((MemberReference)((ParameterReference)((MethodReference)m).Parameters[0]).ParameterType).FullName == "RoR2.ItemDef") { return ((MemberReference)((ParameterReference)((MethodReference)m).Parameters[1]).ParameterType).FullName == "System.Int32"; } return false; } } public static void Finish() { //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Expected O, but got Unknown //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Unknown result type (might be due to invalid IL or missing references) //IL_0093: Unknown result type (might be due to invalid IL or missing references) //IL_00b4: Unknown result type (might be due to invalid IL or missing references) //IL_00d8: Unknown result type (might be due to invalid IL or missing references) //IL_00fc: Unknown result type (might be due to invalid IL or missing references) //IL_0120: Unknown result type (might be due to invalid IL or missing references) //IL_0144: Unknown result type (might be due to invalid IL or missing references) //IL_0164: Unknown result type (might be due to invalid IL or missing references) //IL_0188: Unknown result type (might be due to invalid IL or missing references) //IL_01ac: Unknown result type (might be due to invalid IL or missing references) //IL_01d0: Unknown result type (might be due to invalid IL or missing references) //IL_01f4: Unknown result type (might be due to invalid IL or missing references) //IL_0214: Unknown result type (might be due to invalid IL or missing references) //IL_0238: Unknown result type (might be due to invalid IL or missing references) //IL_025c: Unknown result type (might be due to invalid IL or missing references) //IL_027c: Unknown result type (might be due to invalid IL or missing references) //IL_029c: Unknown result type (might be due to invalid IL or missing references) //IL_02c0: Unknown result type (might be due to invalid IL or missing references) //IL_02e4: Unknown result type (might be due to invalid IL or missing references) //IL_030a: Unknown result type (might be due to invalid IL or missing references) //IL_032e: Unknown result type (might be due to invalid IL or missing references) //IL_0352: Unknown result type (might be due to invalid IL or missing references) //IL_0372: Unknown result type (might be due to invalid IL or missing references) //IL_0392: Unknown result type (might be due to invalid IL or missing references) //IL_03b6: Unknown result type (might be due to invalid IL or missing references) //IL_03f4: Unknown result type (might be due to invalid IL or missing references) //IL_0410: Unknown result type (might be due to invalid IL or missing references) //IL_0430: Unknown result type (might be due to invalid IL or missing references) //IL_0450: Unknown result type (might be due to invalid IL or missing references) //IL_0470: Unknown result type (might be due to invalid IL or missing references) //IL_0490: Unknown result type (might be due to invalid IL or missing references) //IL_04b6: Unknown result type (might be due to invalid IL or missing references) //IL_04e2: Unknown result type (might be due to invalid IL or missing references) //IL_0502: Unknown result type (might be due to invalid IL or missing references) //IL_0522: Unknown result type (might be due to invalid IL or missing references) //IL_0548: Unknown result type (might be due to invalid IL or missing references) //IL_0568: Unknown result type (might be due to invalid IL or missing references) //IL_0588: Unknown result type (might be due to invalid IL or missing references) //IL_05a8: Unknown result type (might be due to invalid IL or missing references) //IL_05c8: Unknown result type (might be due to invalid IL or missing references) //IL_05e8: Unknown result type (might be due to invalid IL or missing references) //IL_0608: Unknown result type (might be due to invalid IL or missing references) //IL_0628: Unknown result type (might be due to invalid IL or missing references) //IL_0648: Unknown result type (might be due to invalid IL or missing references) //IL_0668: Unknown result type (might be due to invalid IL or missing references) //IL_0688: Unknown result type (might be due to invalid IL or missing references) //IL_06ae: Unknown result type (might be due to invalid IL or missing references) //IL_06ce: Unknown result type (might be due to invalid IL or missing references) //IL_06ee: Unknown result type (might be due to invalid IL or missing references) //IL_070e: Unknown result type (might be due to invalid IL or missing references) //IL_072e: Unknown result type (might be due to invalid IL or missing references) //IL_074e: Unknown result type (might be due to invalid IL or missing references) //IL_076e: Unknown result type (might be due to invalid IL or missing references) //IL_078e: Unknown result type (might be due to invalid IL or missing references) //IL_07ae: Unknown result type (might be due to invalid IL or missing references) //IL_07ce: Unknown result type (might be due to invalid IL or missing references) //IL_07ee: Unknown result type (might be due to invalid IL or missing references) //IL_0813: Expected O, but got Unknown Log = Logger.CreateLogSource("CompatShield"); if (preloadNote != null) { Log.LogInfo((object)preloadNote); } harmony = new Harmony("local.compatshield"); string text = Path.Combine(Paths.ConfigPath, "local.compatshield.cfg"); ConfigMigration.Run(text); ConfigFile val = new ConfigFile(text, true); spawnCredits = val.Bind<float>("1. Spawns and Enemies", "SpawnCreditMultiplier", 1f, "How fast the stage's regular enemy spawners earn credits, so waves come sooner. 1 = game default, 1.5 = about a third sooner. Teleporter, shrine and special-mode spawners are left alone. Host only.").Value; monsterLimit = val.Bind<int>("1. Spawns and Enemies", "MonsterLimit", 0, "Most enemies alive at once while Multitudes No Price Scale is installed. The game's own limit is 40; 0 leaves the game and Multitudes alone. Multitudes' copies stop at this number, and normal spawns do too when Multitudes' Lift Monster Limit is false. Boss parts and scripted encounters still spawn. Host only.").Value; hardEnemyCap = val.Bind<int>("1. Spawns and Enemies", "HardEnemyCap", 80, "The most enemies alive at once, counting every enemy team. Unlike MonsterLimit this also stops summons that ignore the game's team limit, such as death effects, clones and mods' minions, which can otherwise multiply until the game hangs. Boss characters and scripted boss parts still spawn. It only stops new spawns; nothing already alive is removed. 0 = off. Host only.").Value; printerWeight = val.Bind<float>("1. Spawns and Enemies", "PrinterSpawnMultiplier", 1f, "How likely each stage spawn pick is a 3D printer (white, green, red, overgrown). 1 = game default, 4 = four times as likely. Host only.").Value; scrapperWeight = val.Bind<float>("1. Spawns and Enemies", "ScrapperSpawnMultiplier", 1f, "How likely each stage spawn pick is a scrapper. 1 = game default, 2 = twice as likely. Host only.").Value; droneSpawnWeight = val.Bind<float>("1. Spawns and Enemies", "DroneSpawnMultiplier", 1f, "How likely each stage spawn pick is a broken drone or turret. 1 = game default, 5 = five times as likely. Host only.").Value; combinerWeight = val.Bind<float>("1. Spawns and Enemies", "DroneCombinerSpawnMultiplier", 1f, "How likely each stage spawn pick is a Drone Combiner, compared to the unmodded game. This is the total: it already allows for DroneSpawnMultiplier. 1 = game default, 5 = five times as likely. Host only.").Value; droneNoMinStage = val.Bind<bool>("1. Spawns and Enemies", "DroneNoMinimumStage", false, "Lets every broken drone and turret spawn from stage 1, instead of waiting for the stage count the game sets on some of them. Host only.").Value; droneHealth = val.Bind<float>("1. Spawns and Enemies", "DroneHealthMultiplier", 1f, "Max health of allied drones and gunner turrets, including drones from items. Enemy drones are left alone. 1 = game default, 10 = ten times the health. Host only.").Value; sacrificeDropMult = val.Bind<float>("2. Artifact of Sacrifice", "DropChanceMultiplier", 1f, "Multiplies each kill's item drop chance under Artifact of Sacrifice. 1 = game or mod default, 0.7 = 30% fewer drops, 0 = none; below 0 is ignored. Works with RiskyMod's flat chance and ShareSuite's SacrificeFix on or off. Host only.").Value; sacrificeKeepList = val.Bind<string>("2. Artifact of Sacrifice", "KeepInteractables", "", "Interactables that still spawn under Artifact of Sacrifice, as a comma-separated list of spawn card names. A name also covers longer ones starting with it, so iscShrineChance covers the Sandy and Snowy versions. Empty = the game's normal rules. iscShrineChance = Shrine of Chance, iscCasinoChest = Adaptive Chest, iscEquipmentBarrel = Equipment Barrel, iscLunarChest = Lunar Pod. With at least one name set, the log lists every card Sacrifice blocks, so the other names are there to copy. Host only.").Value; sacrificeKeptWeight = val.Bind<float>("2. Artifact of Sacrifice", "KeptInteractableWeight", 1f, "How much of a spawn category's share goes to the cards kept by KeepInteractables when Sacrifice removes the rest of that category. 1 = the game's own math, 0.5 = half that, 0 = none; below 0 is ignored. Host only.").Value; shareSuiteSacrificeFix = val.Bind<bool>("2. Artifact of Sacrifice", "ShareSuiteSacrificeCreditFix", true, "ShareSuite and the game both halve a Sacrifice stage's interactable credits, so the stage spends a quarter. On = only the game halves them, which gives twice the interactables, drones included. Off = both halve. Host only.").Value; acolyteAttackSpeed = val.Bind<float>("3. Balance", "AcolyteAttackSpeedMultiplier", 1.5f, "Acolyte's attack speed, in both the normal and the transformed form. 1 = game default, 1.5 = 50% faster; 0 or below is ignored. Each player's own Acolyte uses the value on that player's PC.").Value; lockedItems = val.Bind<string>("3. Balance", "LockedItems", "", "Items and equipment locked off in every lobby, as a comma-separated list of internal names (the names in Def.StartBonusMod.cfg, for example ChainLightning). Each one shows [CONFIG DISABLED] in the lobby's item list and its lock can't be clicked off, the way an item disabled in TinkersSatchel's config behaves. The list goes by name, so adding or removing mods can't move the locks to other items. Empty = nothing locked. The log lists what was locked and any name it could not find. The host decides; the red title shows on each PC that has the same list.").Value; rouletteSpinCost = val.Bind<bool>("3. Balance", "RouletteSpinCost", true, "Takes a paid ItemRoulette spin out of ShareSuite's shared gold pool too. Without this, ShareSuite refunds every spin on the next frame, so spins are free in multiplayer. Does nothing with shared money off or in single player. Host only.").Value; disableGenetics = val.Bind<bool>("3. Balance", "DisableGenetics", true, "Keeps the Artifact of Genetics (GeneticArtifact mod) off: a vote for it is ignored and it is hidden from the lobby, while the mod stays installed. Set false to get it back. The host decides.").Value; statUpdateInterval = val.Bind<float>("4. Lag and Hang Protection", "StatUpdateInterval", 0.1f, "Shortest time between one character's automatic stat updates, in seconds. Items and auras that flip a shield or refresh a buff every physics tick made the game redo a character's full stat calculation up to 60 times a second, which drained the frame rate with few enemies around. 0.1 = at most 10 a second per character. A single change still applies at once; only rapid repeats wait, for at most this long. 0 = off. Each PC for itself.").Value; physicsCatchUpCap = val.Bind<float>("4. Lag and Hang Protection", "PhysicsCatchUpCap", 0.1f, "Limits how much physics Unity runs to catch up after a slow frame, in seconds. 0.1 = at most 6 steps per frame, 0.05 = at most 3, so under heavy load game time slows a little instead of the frame rate collapsing. 0 = off (game default 0.333). Set at each run start. Each PC for itself.").Value; gasolineFix = (damageChainGuard = val.Bind<bool>("4. Lag and Hang Protection", "DamageChainGuard", true, "Stops kill chains overflowing the stack and crashing the game. Hits nested more than 3 deep, and Gasoline blasts set off inside another Gasoline blast, wait in line and run after the outer hit. A huge chain is spread over later physics ticks instead of freezing the game. Host only.").Value); damageChainQueueLimit = val.Bind<int>("4. Lag and Hang Protection", "DamageChainQueueLimit", 256, "Goes with DamageChainGuard. How many hits from a chain may wait in line at once. Past this, hits nested more than 3 deep are dropped; direct hits and the first 3 links always land. Host only.").Value; damageChainDrainMs = val.Bind<float>("4. Lag and Hang Protection", "DamageChainDrainMs", 4f, "Goes with DamageChainGuard. Milliseconds of waiting hits that may run per physics tick, so a huge chain lands over a few seconds instead of freezing the game. 0 = no limit, the whole line runs in one frame. Host only.").Value; blastChainCap = val.Bind<bool>("4. Lag and Hang Protection", "BlastChainCap", true, "Stops item combos with exploding on-hit effects (such as Marwan's Ash and Fire Shield) from hanging the game. A blast set off inside other blasts stops firing at BlastChainMaxDepth or when BlastChainBudgetMs runs out. A blast that isn't inside another one always fires. Host only.").Value; blastChainMaxDepth = val.Bind<int>("4. Lag and Hang Protection", "BlastChainMaxDepth", 4, "Goes with BlastChainCap. How many blasts may run inside each other at once. A deeper one deals no damage and sets off nothing. Minimum 1. Host only.").Value; blastChainBudgetMs = val.Bind<float>("4. Lag and Hang Protection", "BlastChainBudgetMs", 100f, "Goes with BlastChainCap. Time allowance in milliseconds for blasts inside blasts, shared by every chain and refilled between chains. A big one-level explosion is not cut. 0 = no time limit. Host only.").Value; blastTargetGuard = (statsRetryGuard = (overlapHitGuard = (dotTickGuard = (bulletHitGuard = (totemTetherGuard = val.Bind<bool>("5. Error and Crash Protection", "ErrorLoopGuards", true, "Stops one error repeating every physics tick. Without these, an error inside a blast, melee hit or damage zone, damage-over-time tick, bullet, stat update or sacrifice totem's tether makes the game run that code again and again. Each new kind of failure logs one line naming what broke. Host for hits; each PC for its own stat updates and totem tethers.").Value))))); bool value = val.Bind<bool>("5. Error and Crash Protection", "OutdatedHookGuard", true, "Skips hooks a game update broke so the mod keeps loading, and ignores removing a hook that was never added. Every PC.").Value; assetRedirect = val.Bind<bool>("5. Error and Crash Protection", "MovedAssetRedirect", true, "When a mod asks for a game asset by a path the October 2026 update moved, loads it from its new path. Every PC.").Value; handlerGuard = val.Bind<bool>("5. Error and Crash Protection", "BrokenHandlerGuard", true, "Catches known, harmless crashes in Starstorm 2 (Strange Can, Relic of Force), DamageLog and Artifact of Genetics, so they stop breaking kills and damage. Host only.").Value; stunDurationFix = val.Bind<bool>("5. Error and Crash Protection", "StunDurationFix", true, "Game bug: a freeze, stun or shock on an enemy that is still spawning crashes and drops the rest of the hit, including the gold and XP on a kill. Host only.").Value; nullDccsPoolEntryFix = val.Bind<bool>("5. Error and Crash Protection", "NullDccsPoolEntryFix", true, "Removes empty entries from a stage's interactable pool, so Chen's drones, Tinker's Satchel and QoLChests can add their chests and drones. Logs one line per pool it cleans. Host only.").Value; infernoHookChurnFix = (respawnHookChurnFix = val.Bind<bool>("5. Error and Crash Protection", "HookChurnFixes", true, "Stops Inferno and PlayerRespawnSystem removing and re-adding all their hooks at every run, the kind of work that crashed the game when Start was pressed. They keep their hooks between runs instead, and runs play the same. Every PC.").Value); stopSoundFix = (orphanLoopGuard = (lunarPoolLoopStopFix = val.Bind<bool>("5. Error and Crash Protection", "StuckSoundFixes", true, "Stops looping sounds that would otherwise play until the game restarts: Stop events AudioOverlapFix would drop, loops left behind when their object is destroyed, and WolfoFixes' cauldron hum. One-shot sounds are left alone. Every PC.").Value)); bubbetsFix = val.Bind<bool>("6. Item Mod Fixes", "BubbetsItemsFix", true, "Lets Bubbets Items 1.8.20 run on game 1.5.0, and repairs Jellied Soles, Repulsion Plate Mk2, Void Scrap, Broken Clock, Wildlife Camera and the Slug health bar. Every PC.").Value; hallowedIchorTimerFix = val.Bind<bool>("6. Item Mod Fixes", "HallowedIchorTimerFix", true, "Sandswept: stops Hallowed Ichor throwing an error every frame and freezing the run timer once anyone picks it up, on a HUD without its text effect. Every PC.").Value; tinkersIsolationEnabled = (TinkersLanguageFixEnabled = val.Bind<bool>("6. Item Mod Fixes", "TinkersSatchelFixes", true, "Sets up each TinkersSatchel item on its own, so one broken item doesn't stop the rest, and shows its item names and descriptions as text instead of TINKERSSATCHEL_..._RENDERED. Every PC.").Value); linearDamageFix = val.Bind<bool>("6. Item Mod Fixes", "LinearDamageFocusCrystalFix", true, "Stops Focus Crystal counting twice when Bubbets Items and LinearDamage are both installed. Host only.").Value; daggerOfFrenzyGuard = val.Bind<bool>("6. Item Mod Fixes", "DaggerOfFrenzyGuard", true, "Stops Smite Items' Dagger of Frenzy breaking skills on bodies with no skill locator or primary skill. Every PC.").Value; zetDropFix = val.Bind<bool>("6. Item Mod Fixes", "ZetAspectsDropFix", true, "Stops ZetAspects' kill hook crashing on an elite's equipment slot, which skips that kill's item procs and drops.").Value; hypercritNullFix = val.Bind<bool>("6. Item Mod Fixes", "HypercritNullFix", true, "When Hypercrit2's crit roll throws an error, counts it as no crit so the hit still lands. Host only.").Value; printToInventoryFix = val.Bind<bool>("6. Item Mod Fixes", "PrintToInventoryScrappers", true, "Lets PrintToInventory load alongside ShareSuite and keeps only its scrapper part: scrap goes straight into the scrapping player's inventory. Printers, cauldrons, cleansing pools and the Wandering Chef stay as they are.").Value; infernoMithrixFix = val.Bind<bool>("7. Enemy and Survivor Mod Fixes", "InfernoMithrixFix", true, "Inferno 1.7.8: makes Mithrix's hammer slam work again, and stops his dash shards multiplying each run. Every PC.").Value; infernoBoostFix = val.Bind<bool>("7. Enemy and Survivor Mod Fixes", "InfernoLevelBoostFix", true, "Inferno: makes its Level and Difficulty Boost reach monsters when RiskyTweaks raises the level cap. Raises difficulty; the amount is Inferno's own setting. Every PC.").Value; infernoCooldownFix = val.Bind<bool>("7. Enemy and Survivor Mod Fixes", "InfernoCooldownScalingFix", true, "Inferno: makes Enemy Cooldown Reduction Scaling shorten enemy cooldowns, as its description says, instead of lengthening them. Host only.").Value; thetaShieldLoopFix = val.Bind<bool>("7. Enemy and Survivor Mod Fixes", "ThetaShieldLoopFix", true, "Sandswept: stops Theta Constructs repeating a failed shield cast every tick, which drops the frame rate and loops a sound. Host only in effect.").Value; swiftImpactFix = val.Bind<bool>("7. Enemy and Survivor Mod Fixes", "SwiftImpactFix", true, "EnemiesReturns: stops Swift breaking the game's Beetle Guard impact effect, which causes errors every tick and a run-end crash. Every PC.").Value; flowerRootFix = (scepterFlowerFix = val.Bind<bool>("7. Enemy and Survivor Mod Fixes", "RexFlowerFixes", true, "REX's Tangling Growth flower: unroots every enemy when one was already gone, and keeps working when REX died or left the stage with Ancient Scepter installed. Host only.").Value); shamanModelFix = val.Bind<bool>("7. Enemy and Survivor Mod Fixes", "ShamanModelFix", true, "Rebuilds the one method that stops the deprecated Shaman mod loading on game 1.5.0, and fixes the name clash that stalled loading at 99%. Every PC, and every player needs the Shaman mod.").Value; skillSlotsHudFix = val.Bind<bool>("7. Enemy and Survivor Mod Fixes", "ExtraSkillSlotsHudFix", true, "Builds ExtraSkillSlots' four extra icons to fit a replacement HUD such as RiskUI, so the slots can be seen. Each player, for their own screen.").Value; paladinFixEnabled = val.Bind<bool>("7. Enemy and Survivor Mod Fixes", "PaladinMaterialsFix", false, "Crash-proofs PaladinMod 2.1.0's material setup. Off by default: PaladinMod 2.2.0 fixed this itself. Every PC.").Value; paladinShockwaveFix = val.Bind<bool>("7. Enemy and Survivor Mod Fixes", "PaladinShockwaveFix", true, "PaladinMod: stops a shockwave throwing an error every tick, about 50 a second, once its dust effect is gone. Every PC.").Value; fireTrailFix = val.Bind<bool>("7. Enemy and Survivor Mod Fixes", "SandsweptFireTrailFix", true, "Sandswept: stops the Delta Construct's fire trail throwing an error when its last flame burns out, which skipped other trails' damage that tick. Every PC.").Value; sharpAnchorFix = val.Bind<bool>("6. Item Mod Fixes", "SharpAnchorZoneFix", true, "StormyItems: stops a Sharp Anchor zone that has lost track of its holder throwing an error every tick, up to 100 a second. Host only.").Value; lagTracer = val.Bind<bool>("8. Diagnostics", "LagTracer", true, "Finds where lag comes from: during a run, logs fps, the worst frame, counts of monsters and projectiles, and what each hot code path cost, every 10 s. About 6 log lines a minute. Set false to silence it.").Value; soundTracer = val.Bind<bool>("8. Diagnostics", "SoundTracer", true, "Names an audio loop that follows you into the lobby: at each run end, logs loop-type sounds started on objects that no longer exist. A few log lines per run end. Set false once the loop is found.").Value; bigHitTracer = val.Bind<bool>("8. Diagnostics", "BigHitTracer", true, "Names what dealt a huge hit to a player. During a run it logs the victim, the attacker, the object that carried the damage, the damage type, the proc chain and the code path for any hit that takes 25% or more of a player's full health or the last of it, and for every player death. At most 5 lines per source and 60 per run, plus a summary at run end. Log only: it changes nothing in the game. Only the host needs it.").Value; physicsPileupTracer = val.Bind<bool>("8. Diagnostics", "PhysicsPileupTracer", true, "Names a physics pile-up: after a frame over 0.5 s during a run, logs which moving objects hold the most colliders and how many share one spot, at most every 10 s. Silent while the game runs smoothly. Only the host needs it.").Value; hookTimer = val.Bind<bool>("8. Diagnostics", "HookTimer", false, "Lag hunting: names the mods whose code costs the most. From the first run start it times each mod's hooks, Harmony patches and event handlers on about 40 busy game methods (stats, damage, buffs, inventory, per-frame updates) and logs the slowest mods and single hooks every 5 minutes, at each stage change and at run end. Log only, but it wraps a few hundred mod methods in a timer: expect a pause of about 10 seconds at the first run start, a shorter one at the next stage and slightly lower speed, so leave it false unless you are measuring. Each PC measures itself.").Value; ConfigMigration.EnsureSaved(val); Log.LogInfo((object)($"Enabled fixes: ErrorLoopGuards={blastTargetGuard}, StuckSoundFixes={orphanLoopGuard}, HookChurnFixes={respawnHookChurnFix}, TinkersSatchelFixes={tinkersIsolationEnabled}, RexFlowerFixes={flowerRootFix}, " + $"ThetaShieldLoopFix={thetaShieldLoopFix}, HallowedIchorTimerFix={hallowedIchorTimerFix}, SandsweptFireTrailFix={fireTrailFix}, SharpAnchorZoneFix={sharpAnchorFix}, DaggerOfFrenzyGuard={daggerOfFrenzyGuard}, ExtraSkillSlotsHudFix={skillSlotsHudFix}, LinearDamageFocusCrystalFix={linearDamageFix}, BubbetsItemsFix={bubbetsFix}, OutdatedHookGuard={value}, PaladinMaterialsFix={paladinFixEnabled}, PaladinShockwaveFix={paladinShockwaveFix}, " + $"MovedAssetRedirect={assetRedirect}, ZetAspectsDropFix={zetDropFix}, BrokenHandlerGuard={handlerGuard}, StunDurationFix={stunDurationFix}, " + $"PrintToInventoryScrappers={printToInventoryFix}, InfernoMithrixFix={infernoMithrixFix}, InfernoLevelBoostFix={infernoBoostFix}, " + $"InfernoCooldownScalingFix={infernoCooldownFix}, ShamanModelFix={shamanModelFix}, SwiftImpactFix={swiftImpactFix}, ShareSuiteSacrificeCreditFix={shareSuiteSacrificeFix}, MonsterLimit={monsterLimit}, HardEnemyCap={hardEnemyCap}, " + $"SpawnCreditMultiplier={spawnCredits}, PrinterSpawnMultiplier={printerWeight}, ScrapperSpawnMultiplier={scrapperWeight}, DroneCombinerSpawnMultiplier={combinerWeight}, DroneNoMinimumStage={droneNoMinStage}, DroneSpawnMultiplier={droneSpawnWeight}, DroneHealthMultiplier={droneHealth}, AcolyteAttackSpeedMultiplier={acolyteAttackSpeed}, SacrificeDropChanceMultiplier={sacrificeDropMult}, DropChanceMultiplier={sacrificeDropMult}, KeepInteractables=[{sacrificeKeepList}], KeptInteractableWeight={sacrificeKeptWeight}, DamageChainGuard={damageChainGuard}, BlastChainCap={blastChainCap}, RouletteSpinCost={rouletteSpinCost}, NullDccsPoolEntryFix={nullDccsPoolEntryFix}, HypercritNullFix={hypercritNullFix}, DisableGenetics={disableGenetics}, LockedItems=[{lockedItems}], SoundTracer={soundTracer}, LagTracer={lagTracer}, BigHitTracer={bigHitTracer}, PhysicsPileupTracer={physicsPileupTracer}, HookTimer={hookTimer}, PhysicsCatchUpCap={physicsCatchUpCap}, StatUpdateInterval={statUpdateInterval}, DamageChainQueueLimit={damageChainQueueLimit}, DamageChainDrainMs={damageChainDrainMs}, BlastChainMaxDepth={blastChainMaxDepth}, BlastChainBudgetMs={blastChainBudgetMs}")); if (value) { try { HookShield.Apply(harmony); Log.LogInfo((object)"Outdated-hook guard installed"); } catch (Exception ex) { Log.LogError((object)("Outdated-hook guard failed to install: " + ex)); } } if (hookTimer) { HookTimerCapture.Install(); } if (paladinFixEnabled || tinkersIsolationEnabled || monsterLimit > 0 || SpawnTweakWanted || InteractableTweakWanted || assetRedirect || stopSoundFix || zetDropFix || gasolineFix || handlerGuard || printToInventoryFix || flowerRootFix || scepterFlowerFix || stunDurationFix || SacrificeTweakWanted || SacrificeKeepWanted || infernoMithrixFix || infernoBoostFix || infernoCooldownFix || infernoHookChurnFix || respawnHookChurnFix || lunarPoolLoopStopFix || shamanModelFix || bubbetsFix || linearDamageFix || skillSlotsHudFix || daggerOfFrenzyGuard || thetaShieldLoopFix || hallowedIchorTimerFix || paladinShockwaveFix || fireTrailFix || sharpAnchorFix || swiftImpactFix || shareSuiteSacrificeFix || soundTracer || orphanLoopGuard || lagTracer || physicsPileupTracer || bigHitTracer || hookTimer || damageChainGuard || blastChainCap || blastTargetGuard || statsRetryGuard || overlapHitGuard || dotTickGuard || bulletHitGuard || totemTetherGuard || rouletteSpinCost || acolyteAttackSpeed != 1f || nullDccsPoolEntryFix || hypercritNullFix || disableGenetics || !string.IsNullOrWhiteSpace(lockedItems) || physicsCatchUpCap > 0f || statUpdateInterval > 0f || hardEnemyCap > 0) { AppDomain.CurrentDomain.AssemblyLoad += delegate(object _, AssemblyLoadEventArgs e) { ApplyModFixes(e.LoadedAssembly); }; Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies(); for (int num = 0; num < assemblies.Length; num++) { ApplyModFixes(assemblies[num]); } } } private static bool IsPlugin(Assembly asm) { try { return asm.Location.StartsWith(Paths.PluginPath, StringComparison.OrdinalIgnoreCase); } catch { return false; } } private static void ApplyModFixes(Assembly asm) { string name; try { name = asm.GetName().Name; } catch { return; } if ((paladinFixEnabled || paladinShockwaveFix) && name == "PaladinMod" && appliedFixes.Add(name)) { if (paladinFixEnabled) { PaladinFix.Apply(harmony, asm); } if (paladinShockwaveFix) { Assembly assembly = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault((Assembly a) => a.GetName().Name == "RoR2"); if (assembly != null) { PaladinShockwaveFix.Apply(harmony, asm, assembly); } else { Log.LogWarning((object)"Paladin shockwave fix: RoR2 isn't loaded yet, not applied"); } } } if (tinkersIsolationEnabled && name == "TinkersSatchel" && appliedFixes.Add(name)) { Type type = asm.GetType("ThinkInvisible.TinkersSatchel.Module"); ModuleIsolation.Apply(harmony, "TinkersSatchel", type, type?.GetMethod("SetupAll_PluginAwake", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic), "SetupConfig", "SetupAttributes", "SetupBehavior"); ModuleIsolation.Apply(harmony, "TinkersSatchel", type, type?.GetMethod("SetupAll_PluginStart", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic), "SetupLate", "Install"); TinkersAutoConfigFix.Apply(harmony, asm); } if (monsterLimit > 0 && name == "MultitudesNoPriceScale" && appliedFixes.Add(name)) { MonsterLimitTweak.Apply(harmony, AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault((Assembly a) => a.GetName().Name == "RoR2"), asm, monsterLimit); } if (handlerGuard && name == "Starstorm2" && appliedFixes.Add(name)) { HandlerGuard.Apply(harmony, asm, "SS2.Items.StrangeCan", "OnCharacterDeathGlobal", typeof(KeyNotFoundException), "Strange Can skipped a kill whose Intoxicated attacker is gone"); HandlerGuard.Apply(harmony, asm, "SS2.Items.RelicOfForce+Behavior", "OnDamageDealtServer", typeof(NullReferenceException), "Relic of Force skipped a hit whose attacker's inventory is gone"); } if (handlerGuard && name == "DamageLog" && appliedFixes.Add(name)) { HandlerGuard.Apply(harmony, asm, "DamageLog.DamageLog", "Record", typeof(NullReferenceException), "DamageLog skipped a hit it couldn't find an attacker portrait for"); } if (handlerGuard && name == "GeneticsArtifact" && appliedFixes.Add(name)) { AfterOrigGuard.Apply(harmony, asm, "GeneticsArtifact.GeneEngineDriver", "HealthComponent_TakeDamage", typeof(NullReferenceException), "Artifact of Genetics skipped tracking a hit it crashed on (the damage itself already landed)"); } if (zetDropFix && name == "ZetAspects" && appliedFixes.Add(name)) { ZetAspectsDropFix.Apply(harmony, ZetAspectsDropFix.FindHook(asm)); } if (printToInventoryFix && name == "PrintToInventory" && appliedFixes.Add(name)) { PrintToInventoryScrapperFix.Apply(harmony, asm); } if (scepterFlowerFix && name == "AncientScepter" && appliedFixes.Add(name)) { ScepterFlowerFix.Apply(harmony, asm); } if ((infernoMithrixFix || infernoBoostFix || infernoCooldownFix || infernoHookChurnFix) && name == "Inferno" && appliedFixes.Add(name)) { if (infernoMithrixFix) { InfernoMithrixFix.Apply(harmony, asm); } if (infernoBoostFix || infernoCooldownFix) { InfernoScalingFix.Apply(harmony, asm, infernoBoostFix, infernoCooldownFix); } if (infernoHookChurnFix) { InfernoHookChurnFix.Apply(harmony, asm); } } if (respawnHookChurnFix && name == "PlayerRespawnSystem" && appliedFixes.Add(name)) { RespawnHookChurnFix.Apply(harmony, asm); } if (lunarPoolLoopStopFix && name == "WolfoFixes" && appliedFixes.Add(name)) { LunarPoolLoopStopFix.Apply(harmony); } if (skillSlotsHudFix && name == "ExtraSkillSlots" && appliedFixes.Add(name)) { SkillSlotsHudFix.Apply(harmony, asm); } if (daggerOfFrenzyGuard && name == "Smite Items" && appliedFixes.Add(name)) { Assembly assembly2 = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault((Assembly a) => a.GetName().Name == "RoR2"); if (assembly2 != null) { DaggerOfFrenzyFix.Apply(harmony, asm, assembly2); } else { Log.LogWarning((object)"Dagger of Frenzy guard: RoR2 isn't loaded yet, not applied"); } } if ((thetaShieldLoopFix || hallowedIchorTimerFix || fireTrailFix) && name == "Sandswept" && appliedFixes.Add(name)) { Assembly assembly3 = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault((Assembly a) => a.GetName().Name == "RoR2"); if (assembly3 == null) { Log.LogWarning((object)"Sandswept fixes: RoR2 isn't loaded yet, not applied"); } else { if (thetaShieldLoopFix) { ThetaShieldLoopFix.Apply(harmony, asm, assembly3); } if (hallowedIchorTimerFix) { HallowedIchorTimerFix.Apply(harmony, asm, assembly3); } if (fireTrailFix) { SandsweptFireTrailFix.Apply(harmony, asm, assembly3); } } } if (sharpAnchorFix && name == "StormyItems" && appliedFixes.Add(name)) { Assembly assembly4 = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault((Assembly a) => a.GetName().Name == "RoR2"); if (assembly4 != null) { SharpAnchorZoneFix.Apply(harmony, asm, assembly4); } else { Log.LogWarning((object)"Sharp Anchor fix: RoR2 isn't loaded yet, not applied"); } } if (linearDamageFix && name == "LinearDamage" && appliedFixes.Add(name)) { LinearDamageFix.Apply(harmony, asm); } if (bubbetsFix && name == "BubbetsItems" && appliedFixes.Add(name)) { Assembly assembly5 = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault((Assembly a) => a.GetName().Name == "RoR2"); if (assembly5 != null) { BubbetsFix.Apply(harmony, asm, assembly5); } else { Log.LogWarning((object)"Bubbets fix: RoR2 isn't loaded yet, not applied"); } } if (shamanModelFix && name == "ShamanMod" && appliedFixes.Add(name)) { ShamanModelFix.Apply(harmony, asm); } if (swiftImpactFix && name == "EnemiesReturns" && appliedFixes.Add(name)) { SwiftImpactFix.Apply(harmony, asm); } if (shareSuiteSacrificeFix && name == "ShareSuite" && appliedFixes.Add(name)) { ShareSuiteSacrificeCreditFix.Apply(harmony, asm); } if (stopSoundFix && name == "AudioOverlapFix" && appliedFixes.Add(name)) { StopSoundFix.Apply(harmony, asm, Type.GetType("AkSoundEngine, AK.Wwise.Unity.API")?.Assembly); } if ((soundTracer || orphanLoopGuard) && !soundTracerApplied && IsPlugin(asm)) { soundTracerApplied = true; SoundTracer.Apply(harmony, soundTracer, orphanLoopGuard); } if (lagTracer && !lagTracerApplied && IsPlugin(asm)) { lagTracerApplied = true; LagTracer.Apply(harmony); } if (!string.IsNullOrWhiteSpace(lockedItems) && !lockedItemsApplied && IsPlugin(asm)) { lockedItemsApplied = true; LockedItems.Apply(AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault((Assembly a) => a.GetName().Name == "RoR2"), lockedItems); } if (bigHitTracer && !bigHitApplied && IsPlugin(asm)) { bigHitApplied = true; BigHitTracer.Apply(); } if (hookTimer && !hookTimerApplied && IsPlugin(asm)) { hookTimerApplied = true; HookTimer.Apply(); } if (physicsPileupTracer && !physicsPileupApplied && IsPlugin(asm)) { physicsPileupApplied = true; PhysicsPileupTracer.Apply(); } if (physicsCatchUpCap > 0f && !physicsCapApplied && IsPlugin(asm)) { physicsCapApplied = true; PhysicsCatchUpCap.Apply(physicsCatchUpCap); } if (assetRedirect && !assetRedirectApplied && IsPlugin(asm)) { assetRedirectApplied = true; AssetRedirect.Apply(harmony, AssetRedirect.FindEvaluateKey()); } if (damageChainGuard && !damageChainGuardApplied && IsPlugin(asm)) { Assembly assembly6 = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault((Assembly a) => a.GetName().Name == "RoR2"); if (assembly6 != null) { damageChainGuardApplied = true; DamageChainGuard.Configure(damageChainQueueLimit, damageChainDrainMs); DamageChainGuard.Apply(harmony, assembly6); } } if (blastChainCap && !blastChainCapApplied && IsPlugin(asm)) { Assembly assembly7 = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault((Assembly a) => a.GetName().Name == "RoR2"); if (assembly7 != null) { blastChainCapApplied = true; BlastChainCap.Configure(blastChainMaxDepth, blastChainBudgetMs); BlastChainCap.Apply(harmony, assembly7); } } if (blastTargetGuard && !blastTargetGuardApplied && IsPlugin(asm)) { Assembly assembly8 = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault((Assembly a) => a.GetName().Name == "RoR2"); if (assembly8 != null) { blastTargetGuardApplied = true; BlastTargetGuard.Apply(harmony, assembly8); } } if (statUpdateInterval > 0f && !statLimitApplied && IsPlugin(asm)) { Assembly assembly9 = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault((Assembly a) => a.GetName().Name == "RoR2"); if (assembly9 != null) { statLimitApplied = true; StatUpdateLimit.Apply(harmony, assembly9, statUpdateInterval); } } if (hardEnemyCap > 0 && !hardCapApplied && IsPlugin(asm)) { Assembly assembly10 = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault((Assembly a) => a.GetName().Name == "RoR2"); if (assembly10 != null) { hardCapApplied = true; HardEnemyCap.Apply(harmony, assembly10, hardEnemyCap); } } if (statsRetryGuard && !statsRetryGuardApplied && IsPlugin(asm)) { Assembly assembly11 = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault((Assembly a) => a.GetName().Name == "RoR2"); if (assembly11 != null) { statsRetryGuardApplied = true; StatsRetryGuard.Apply(harmony, assembly11); } } if (overlapHitGuard && !overlapHitGuardApplied && IsPlugin(asm)) { Assembly assembly12 = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault((Assembly a) => a.GetName().Name == "RoR2"); if (assembly12 != null) { overlapHitGuardApplied = true; OverlapHitGuard.Apply(harmony, assembly12); } } if (dotTickGuard && !dotTickGuardApplied && IsPlugin(asm)) { Assembly assembly13 = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault((Assembly a) => a.GetName().Name == "RoR2"); if (assembly13 != null) { dotTickGuardApplied = true; DotTickGuard.Apply(harmony, assembly13); } } if (bulletHitGuard && !bulletHitGuardApplied && IsPlugin(asm)) { Assembly assembly14 = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault((Assembly a) => a.GetName().Name == "RoR2"); if (assembly14 != null) { bulletHitGuardApplied = true; BulletHitGuard.Apply(harmony, assembly14); } } if (totemTetherGuard && !totemTetherGuardApplied && IsPlugin(asm)) { Assembly assembly15 = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault((Assembly a) => a.GetName().Name == "RoR2"); if (assembly15 != null) { totemTetherGuardApplied = true; TotemTetherGuard.Apply(harmony, assembly15); } } if (rouletteSpinCost && !rouletteSpinCostApplied && IsPlugin(asm)) { Assembly assembly16 = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault((Assembly a) => a.GetName().Name == "RoR2"); if (assembly16 != null) { rouletteSpinCostApplied = true; RouletteSpinCost.Apply(harmony, assembly16); } } if (acolyteAttackSpeed != 1f && !acolyteTweakApplied && IsPlugin(asm)) { Assembly assembly17 = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault((Assembly a) => a.GetName().Name == "RoR2"); if (assembly17 != null) { acolyteTweakApplied = true; AcolyteTweak.Apply(assembly17, acolyteAttackSpeed); } } if (nullDccsPoolEntryFix && !nullDccsPoolEntryFixApplied && IsPlugin(asm)) { Assembly assembly18 = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault((Assembly a) => a.GetName().Name == "RoR2"); if (assembly18 != null) { nullDccsPoolEntryFixApplied = true; NullDccsPoolEntryFix.Apply(harmony, assembly18); } } if (disableGenetics && !disableGeneticsApplied && IsPlugin(asm)) { Assembly assembly19 = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault((Assembly a) => a.GetName().Name == "RoR2"); if (assembly19 != null) { disableGeneticsApplied = true; ArtifactDisabler.Apply(harmony, assembly19); } } if (hypercritNullFix && name == "NotHypercrit" && appliedFixes.Add(name)) { HypercritNullFix.Apply(harmony, asm); } if (gasolineFix && !gasolineApplied && IsPlugin(asm)) { Assembly assembly20 = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault((Assembly a) => a.GetName().Name == "RoR2"); if (assembly20 != null) { gasolineApplied = true; GasolineChainFix.Apply(harmony, assembly20); } } if (flowerRootFix && !flowerRootApplied && IsPlugin(asm)) { Assembly assembly21 = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault((Assembly a) => a.GetName().Name == "RoR2"); if (assembly21 != null) { flowerRootApplied = true; FlowerRootFix.Apply(harmony, assembly21); } } if (stunDurationFix && !stunDurationApplied && IsPlugin(asm)) { Assembly assembly22 = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault((Assembly a) => a.GetName().Name == "RoR2"); if (assembly22 != null) { stunDurationApplied = true; StunDurationFix.Apply(harmony, assembly22); } } if (SpawnTweakWanted && !spawnTweakApplied && IsPlugin(asm)) { Assembly assembly23 = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault((Assembly a) => a.GetName().Name == "RoR2"); if (assembly23 != null) { spawnTweakApplied = true; SpawnCreditTweak.Apply(harmony, assembly23, spawnCredits); } } if (InteractableTweakWanted && !interactableTweakApplied && IsPlugin(asm)) { Assembly assembly24 = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault((Assembly a) => a.GetName().Name == "RoR2"); if (assembly24 != null) { interactableTweakApplied = true; InteractableWeightTweak.Apply(assembly24, printerWeight, scrapperWeight, combinerWeight); DroneTweak.Apply(assembly24, droneNoMinStage, droneSpawnWeight, droneHealth); } } if (SacrificeTweakWanted && !sacrificeApplied && IsPlugin(asm)) { Assembly assembly25 = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault((Assembly a) => a.GetName().Name == "RoR2"); if (assembly25 != null) { sacrificeApplied = true; SacrificeDropTweak.Apply(harmony, assembly25, sacrificeDropMult); } } if (SacrificeKeepWanted && !sacrificeKeepApplied && IsPlugin(asm)) { Assembly assembly26 = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault((Assembly a) => a.GetName().Name == "RoR2"); if (assembly26 != null) { sacrificeKeepApplied = true; SacrificeKeepTweak.Apply(harmony, assembly26, sacrificeKeepList, sacrificeKeptWeight); } } } } internal static class HookShield { private static readonly HashSet<string> reported = new HashSet<string>(); internal static Harmony harmonyRef; public static void Apply(Harmony h) { harmonyRef = h; Patch(h, "Add", "AddFinalizer"); Patch(h, "Modify", "AddFinalizer"); Patch(h, "Remove", "RemoveFinalizer"); Patch(h, "Unmodify", "RemoveFinalizer"); } private static void Patch(Harmony h, string name, string finalizer) { //IL_0049: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Expected O, but got Unknown MethodInfo methodInfo = typeof(HookEndpointManager).GetMethods(BindingFlags.Static | BindingFlags.Public).First((MethodInfo m) => m.Name == name && !m.IsGenericMethodDefinition && m.GetParameters().Length == 2); MethodInfo method = typeof(HookShield).GetMethod(finalizer, BindingFlags.Static | BindingFlags.NonPublic); h.Patch((MethodBase)methodInfo, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, new HarmonyMethod(method), (HarmonyMethod)null); } private static Exception AddFinalizer(Exception __exception, object[] __args) { if (__exception is InvalidOperationException && __exception.Message.Contains("of hook for") && __exception.Message.Contains("doesn't match")) { Report("Skipped an outdated hook so the mod can keep loading", __args, __exception.Message); MethodBase methodBase = ((__args.Length != 0) ? (__args[0] as MethodBase) : null); if (CompatShieldPatcher.TinkersLanguageFixEnabled && OwnerOf(__args) == "TinkersSatchel" && methodBase?.Name == "SetCurrentLanguage" && methodBase.DeclaringType?.FullName == "RoR2.Language") { TinkersLanguageFix.OnTinkersLanguageHookSkipped(harmonyRef); } return null; } Exception ex = Innermost(__exception); if (ex is TypeLoadException && (ex.Message.Contains("expected class 'orig_") || ex.Message.Contains("expected class 'hook_"))) { Report("Skipped a hook whose hook type no longer exists after the game update", __args, ex.Message); return null; } return __exception; } private static Exception RemoveFinalizer(Exception __exception, object[] __args) { if (__exception is InvalidOperationException && __exception.Message.StartsWith("Stack empty")) { Report("Ignored removing a hook that was never added", __args, null); return null; } return __exception; } private static Exception Innermost(Exception e) { while (e is TargetInvocationException { InnerException: not null } ex) { e = ex.InnerException; } return e; } private static string OwnerOf(object[] args) { Delegate obj = ((args.Length > 1) ? (args[1] as Delegate) : null); try { return obj?.Method?.DeclaringType?.Assembly.GetName().Name ?? "?"; } catch { return "?"; } } private static void Report(string what, object[] args, string detail) { MethodBase methodBase = ((args.Length != 0) ? (args[0] as MethodBase) : null); string text = OwnerOf(args); string text2 = ((methodBase == null) ? "?" : (methodBase.DeclaringType?.FullName + "." + methodBase.Name)); if (reported.Add(what + "|" + text + "|" + text2)) { CompatShieldPatcher.Log.LogWarning((object)(what + ": " + text + " -> " + text2 + ((detail != null) ? (" (" + detail + ")") : ""))); } } } internal static class PaladinFix { private static Type asset; public static void Apply(Harmony h, Assembly asm) { //IL_005a: Unknown result type (might be due to invalid IL or missing references) //IL_0060: Expected O, but got Unknown //IL_0076: Unknown result type (might be due to invalid IL or missing references) //IL_0083: Expected O, but got Unknown try { asset = asm.GetType("PaladinMod.Modules.Asset"); MethodInfo methodInfo = asset?.GetMethod("GatherMaterials", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); if (methodInfo == null) { CompatShieldPatcher.Log.LogWarning((object)"PaladinMod: GatherMaterials not found (mod updated?), fix not applied"); return; } HarmonyMethod val = new HarmonyMethod(typeof(SafeStatements).GetMethod("Transpiler")); h.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(typeof(PaladinFix).GetMethod("Postfix", BindingFlags.Static | BindingFlags.NonPublic)), val, (HarmonyMethod)null, (HarmonyMethod)null); CompatShieldPatcher.Log.LogInfo((object)"PaladinMod: material setup made crash-proof"); } catch (Exception ex) { CompatShieldPatcher.Log.LogError((object)("PaladinMod fix failed to apply: " + ex)); } } private static void Postfix() { FieldInfo fieldInfo = AccessTools.Field(asset, "matMercSwipe"); if (!(fieldInfo == null) && !Object.op_Implicit((Object)/*isinst with value type is only supported in some contexts*/)) { Material val = MercSwipeFromGhost(); fieldInfo.SetValue(null, val); CompatShieldPatcher.Log.LogInfo((object)(Object.op_Implicit((Object)(object)val) ? "PaladinMod: matMercSwipe taken from the Eviscerate ghost prefab instead" : "PaladinMod: matMercSwipe unavailable; that sword effect may look plain")); } } private static Material MercSwipeFromGhost() { //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Unknown result type (might be due to invalid IL or missing references) string[] array = new string[2] { "RoR2/Base/Merc/EvisProjectileGhost.prefab", "RoR2/Base/Merc/EvisOverlapProjectileGhost.prefab" }; foreach (string text in array) { try { GameObject val = Addressables.LoadAssetAsync<GameObject>((object)text).WaitForCompletion(); if (Object.op_Implicit((Object)(object)val)) { Transform val2 = val.transform.Find("Base"); ParticleSystemRenderer val3 = (Object.op_Implicit((Object)(object)val2) ? ((Component)val2).GetComponent<ParticleSystemRenderer>() : null); if (Object.op_Implicit((Object)(object)val3) && Object.op_Implicit((Object)(object)((Renderer)val3).sharedMaterial)) { return Object.Instantiate<Material>(((Renderer)val3).sharedMaterial); } } } catch (Exception ex) { CompatShieldPatcher.Log.LogDebug((object)("PaladinMod: " + text + " not usable: " + ex.Message)); } } return null; } } public static class ModuleIsolation { private static readonly Dictionary<MethodInfo, string> steps = new Dictionary<MethodInfo, string>(); private static readonly Dictionary<string, MethodInfo> byName = new Dictionary<string, MethodInfo>(); private static string modName = "?"; private static int replaced; public static void Apply(Harmony h, string mod, Type moduleType, MethodInfo loop, params string[] stepNames) { //IL_0094: Unknown result type (might be due to invalid IL or missing references) //IL_00a0: Expected O, but got Unknown try { if (moduleType == null || loop == null) { CompatShieldPatcher.Log.LogWarning((object)(mod + ": setup loop not found (mod updated?), item isolation not applied")); return; } modName = mod; foreach (string text in stepNames) { MethodInfo method = moduleType.GetMethod(text, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); if (!(method == null)) { steps[method] = text; byName[text] = method; } } int num = replaced; h.Patch((MethodBase)loop, (HarmonyMethod)null, (HarmonyMethod)null, new HarmonyMethod(typeof(ModuleIsolation).GetMethod("Transpiler")), (HarmonyMethod)null, (HarmonyMethod)null); CompatShieldPatcher.Log.LogInfo((object)$"{mod}: each item now runs {loop.Name} on its own ({replaced - num} calls guarded)"); } catch (Exception ex) { CompatShieldPatcher.Log.LogError((object)(mod + " item isolation failed to apply: " + ex)); } } public static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions) { MethodInfo safe = typeof(ModuleIsolation).GetMethod("SafeCall"); foreach (CodeInstruction instruction in instructions) { if ((instruction.opcode == OpCodes.Callvirt || instruction.opcode == OpCodes.Call) && instruction.operand is MethodInfo key && steps.TryGetValue(key, out var value)) { instruction.opcode = OpCodes.Ldstr; instruction.operand = value; yield return instruction; yield return new CodeInstruction(OpCodes.Call, (object)safe); replaced++; } else { yield return instruction; } } } public static void SafeCall(object module, string step) { try { byName[step].Invoke(module, null); } catch (Exception ex) { Exception ex2 = ((ex is TargetInvocationException { InnerException: not null } ex3) ? ex3.InnerException : ex); CompatShieldPatcher.Log.LogWarning((object)(modName + ": " + module?.GetType().Name + "." + step + " failed and was skipped (" + ex2.GetType().Name + ": " + ex2.Message + ")")); } } } internal static class TinkersAutoConfigFix { private const BindingFlags Any = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic; private static FieldInfo statsDirty; private static FieldInfo dropsDirty; private static FieldInfo langDirty; private static Type appType; private static Type runType; private static Type masterType; private static Type languageType; private static bool reported; public static void Apply(Harmony h, Assembly asm) { //IL_00cd: Unknown result type (might be due to invalid IL or missing references) //IL_00db: Expected O, but got Unknown try { MethodInfo methodInfo = asm.GetType("ThinkInvisible.TinkersSatchel.TinkersSatchelPlugin")?.GetMethod("Update", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); Type? type = asm.GetType("ThinkInvisible.TinkersSatchel.AutoConfigModule"); statsDirty = type?.GetField("globalStatsDirty", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); dropsDirty = type?.GetField("globalDropsDirty", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); langDirty = type?.GetField("globalLanguageDirty", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); if (methodInfo == null || statsDirty == null || dropsDirty == null || langDirty == null) { CompatShieldPatcher.Log.LogWarning((object)"TinkersSatchel: auto-config members not found (mod updated?), fix not applied"); return; } h.Patch((MethodBase)methodInfo, new HarmonyMethod(typeof(TinkersAutoConfigFix).GetMethod("Prefix", BindingFlags.Static | BindingFlags.NonPublic)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); CompatShieldPatcher.Log.LogInfo((object)"TinkersSatchel: auto-config update now uses the new language API"); } catch (Exception ex) { CompatShieldPatcher.Log.LogError((object)("TinkersSatchel auto-config fix failed to apply: " + ex)); } } private static bool Prefix() { try { Tick(); } catch (Exception ex) { if (!reported) { reported = true; CompatShieldPatcher.Log.LogError((object)("TinkersSatchel auto-config replacement failed (logged once): " + ex)); } } return false; } private static void Tick() { //IL_0089: Unknown result type (might be due to invalid IL or missing references) bool flag = (bool)statsDirty.GetValue(null); bool flag2 = (bool)dropsDirty.GetValue(null); bool flag3 = (bool)langDirty.GetValue(null); if (!flag && !flag2 && !flag3) { return; } ResolveGameTypes(); if (!(bool)appType.GetProperty("loadFinished", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic).GetValue(null, null)) { return; } object? value = runType.GetProperty("instance", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic).GetValue(null, null); Object val = (Object)((value is Object) ? value : null); if (!Object.op_Implicit(val) || !((Behaviour)val).isActiveAndEnabled) { statsDirty.SetValue(null, false); dropsDirty.SetValue(null, false); } else { if (flag) { statsDirty.SetValue(null, false); foreach (object item in ((IEnumerable)masterType.GetProperty("readOnlyInstancesList", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic).GetValue(null, null)).Cast<object>().ToList()) { if ((bool)masterType.GetProperty("hasBody", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic).GetValue(item, null)) { object obj = masterType.GetMethod("GetBody", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic, null, Type.EmptyTypes, null).Invoke(item, null); object value2 = obj.GetType().GetProperty("healthComponent", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic).GetValue(obj, null); if (value2 != null && (bool)value2.GetType().GetProperty("alive", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic).GetValue(value2, null)) { obj.GetType().GetMethod("RecalculateStats", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic, null, Type.EmptyTypes, null).Invoke(obj, null); } } } } if (flag2) { dropsDirty.SetValue(null, false); object value3 = runType.GetField("networkRuleBookComponent", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic).GetValue(val); runType.GetMethod("OnRuleBookUpdated", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic).Invoke(val, new object[1] { value3 }); runType.GetMethod("BuildDropTable", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic, null, Type.EmptyTypes, null).Invoke(val, null); } } if (flag3) { langDirty.SetValue(null, false); string text = (string)languageType.GetProperty("currentLanguageName", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic).GetValue(null, null); languageType.GetMethod("SetCurrentLanguage", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[2] { typeof(string), typeof(bool) }, null).Invoke(null, new object[2] { text, true }); } } private static void ResolveGameTypes() { if (!(appType != null)) { Assembly assembly = AppDomain.CurrentDomain.GetAssemblies().First((Assembly a) => a.GetName().Name == "RoR2"); appType = assembly.GetType("RoR2.RoR2Application", throwOnError: true); runType = assembly.GetType("RoR2.Run", throwOnError: true); masterType = assembly.GetType("RoR2.CharacterMaster", throwOnError: true); languageType = assembly.GetType("RoR2.Language", throwOnError: true); } } } public static class TinkersLanguageFix { private const BindingFlags Any = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic; private static bool applied; private static FieldInfo allModules; private static FieldInfo langDirty; private static MethodInfo refreshPermanent; private static MethodInfo getEnabled; private static MethodInfo getLanguageInstalled; private static MethodInfo uninstallLanguage; private static MethodInfo installLanguage; private static readonly HashSet<string> failedModules = new HashSet<string>(); private static bool running; public static void OnTinkersLanguageHookSkipped(Harmony h) { if (applied || h == null) { return; } applied = true; try { Assembly assembly = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault((Assembly a) => a.GetName().Name == "TinkersSatchel"); MethodInfo methodInfo = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault((Assembly a) => a.GetName().Name == "RoR2")?.GetType("RoR2.Language")?.GetMethod("SetCurrentLanguage", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[2] { typeof(string), typeof(bool) }, null); if (assembly == null || methodInfo == null || !Init(assembly)) { CompatShieldPatcher.Log.LogWarning((object)"TinkersSatchel language fix: expected members not found, not applied"); return; } PatchTarget(h, methodInfo); CompatShieldPatcher.Log.LogInfo((object)"TinkersSatchel: item names/descriptions now refresh on the game's new language API"); } catch (Exception ex) { CompatShieldPatcher.Log.LogError((object)("TinkersSatchel language fix failed to apply: " + ex)); } } public static bool Init(Assembly tinkers) { Type type = tinkers.GetType("ThinkInvisible.TinkersSatchel.Module"); Type type2 = tinkers.GetType("ThinkInvisible.TinkersSatchel.AutoConfigModule"); if (type == null || type2 == null) { return false; } allModules = type.GetField("allModules", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); langDirty = type2.GetField("globalLanguageDirty", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); refreshPermanent = type.GetMethod("RefreshPermanentLanguage", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic, null, Type.EmptyTypes, null); getEnabled = type.GetProperty("enabled", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)?.GetGetMethod(nonPublic: true); getLanguageInstalled = type.GetProperty("languageInstalled", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)?.GetGetMethod(nonPublic: true); uninstallLanguage = type.GetMethod("UninstallLanguage", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic, null, Type.EmptyTypes, null); installLanguage = type.GetMethod("InstallLanguage", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic, null, Type.EmptyTypes, null); if (allModules != null && langDirty != null && refreshPermanent != null && getEnabled != null && getLanguageInstalled != null && uninstallLanguage != null) { return installLanguage != null; } return false; } public static void PatchTarget(Harmony h, MethodBase target) { //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Expected O, but got Unknown h.Patch(target, (HarmonyMethod)null, new HarmonyMethod(typeof(TinkersLanguageFix).GetMethod("Postfix", BindingFlags.Static | BindingFlags.NonPublic)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); } private static List<object> Modules() { return ((IEnumerable)allModules.GetValue(null))?.Cast<object>().ToList() ?? new List<object>(); } private static void Postfix() { if (running) { return; } running = true; try { foreach (object item in Modules()) { try { refreshPermanent.Invoke(item, null); if ((bool)getEnabled.Invoke(item, null)) { if ((bool)getLanguageInstalled.Invoke(item, null)) { uninstallLanguage.Invoke(item, null); } installLanguage.Invoke(item, null); } } catch (Exception ex) { string name = item.GetType().Name; if (failedModules.Add(name)) { Exception ex2 = ((ex is TargetInvocationException { InnerException: not null } ex3) ? ex3.InnerException : ex); CompatShieldPatcher.Log.LogWarning((object)("TinkersSatchel: " + name + " text refresh failed (" + ex2.GetType().Name + ": " + ex2.Message + ")")); } } } langDirty.SetValue(null, false); } catch (Exception ex4) { if (failedModules.Add("<all>")) { CompatShieldPatcher.Log.LogError((object)("TinkersSatchel language refresh failed: " + ex4)); } } finally { running = false; } } } public static class MonsterLimitTweak { private const BindingFlags Any = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic; private static int limit; private static object monsterTeam; private static object monsterDef; private static MethodInfo getTeamDef; private static MethodInfo getTeamMembers; private static MethodInfo getLiftSetting; private static FieldInfo softLimit; private static FieldInfo teamOverride; private static bool liftChecked; private static int skippedCopies; private static readonly HashSet<string> errors = new HashSet<string>(); private static bool limitChangeLogged; public static void Apply(Harmony h, Assembly ror2, Assembly multitudes, int max) { //IL_01d0: Unknown result type (might be due to invalid IL or missing references) //IL_01de: Expected O, but got Unknown //IL_01f7: Unknown result type (might be due to invalid IL or missing references) //IL_0205: Expected O, but got Unknown try { Type type = ror2?.GetType("RoR2.TeamIndex"); getTeamDef = ror2?.GetType("RoR2.TeamCatalog")?.GetMethod("GetTeamDef", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[1] { type }, null); softLimit = ror2?.GetType("RoR2.TeamDef")?.GetField("softCharacterLimit", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); getTeamMembers = ror2?.GetType("RoR2.TeamComponent")?.GetMethod("GetTeamMembers", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[1] { type }, null); teamOverride = ror2?.GetType("RoR2.DirectorSpawnRequest")?.GetField("teamIndexOverride", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); MethodInfo methodInfo = ror2?.GetType("RoR2.MasterSummon")?.GetMethod("Perform", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic, null, Type.EmptyTypes, null); Type? type2 = multitudes.GetType("SnoresvilleMultitudes.MultitudesNoPriceScale"); MethodInfo methodInfo2 = type2?.GetMethod("SpawnDuplicate", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); getLiftSetting = type2?.GetProperty("ConfigLiftMonsterLimit", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)?.GetGetMethod(nonPublic: true); if (type == null || getTeamDef == null || softLimit == null || getTeamMembers == null || teamOverride == null || methodInfo == null || methodInfo2 == null) { CompatShieldPatcher.Log.LogWarning((object)"Monster limit: expected game/Multitudes members not found, not applied"); return; } limit = max; monsterTeam = Enum.Parse(type, "Monster"); h.Patch((MethodBase)methodInfo, new HarmonyMethod(typeof(MonsterLimitTweak).GetMethod("PerformPrefix", BindingFlags.Static | BindingFlags.NonPublic)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); h.Patch((MethodBase)methodInfo2, new HarmonyMethod(typeof(MonsterLimitTweak).GetMethod("DuplicatePrefix", BindingFlags.Static | BindingFlags.NonPublic)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); CompatShieldPatcher.Log.LogInfo((object)$"Multitudes: enemies capped at {max} alive at once (its copies included)"); } catch (Exception ex) { CompatShieldPatcher.Log.LogError((object)("Monster limit failed to apply: " + ex)); } } private static void PerformPrefix() { try { monsterDef = monsterDef ?? getTeamDef.Invoke(null, new object[1] { monsterTeam }); if (monsterDef == null) { return; } int num = (int)softLimit.GetValue(monsterDef); if (num != limit) { softLimit.SetValue(monsterDef, limit); if (!limitChangeLogged) { limitChangeLogged = true; CompatShieldPatcher.Log.LogInfo((object)$"Game's enemy limit set to {limit} (it was {num})"); } } } catch (Exception ex) { Once("perform", "Monster limit: couldn't set the game's limit: " + ex); } } private static bool DuplicatePrefix(object request, ref GameObject __result) { try { CheckLiftOnce(); object obj = teamOverride.GetValue(request) ?? monsterTeam; if (((ICollection)getTeamMembers.Invoke(null, new object[1] { obj })).Count < limit) { return true; } __result = null; if (skippedCopies++ == 0) { CompatShieldPatcher.Log.LogInfo((object)$"Multitudes: copies paused at {limit} enemies (shown once)"); } return false; } catch (Exception ex) { Once("duplicate", "Monster limit: couldn't check a Multitudes copy, letting it spawn: " + ex); return true; } } private static void CheckLiftOnce() { if (!liftChecked) { liftChecked = true; object obj = getLiftSetting?.Invoke(null, null); object obj2 = obj?.GetType().GetProperty("Value")?.GetValue(obj); bool flag = default(bool); int num; if (obj2 is bool) { flag = (bool)obj2; num = 1; } else { num = 0; } if (((uint)num & (flag ? 1u : 0u)) != 0) { CompatShieldPatcher.Log.LogWarning((object)("Multitudes' Lift Monster Limit is on, so normal spawns ignore the limit " + $"and only its copies stop at {limit}. Set Lift Monster Limit = false for the full cap.")); } } } private static void Once(string key, string message) { if (errors.Add(key)) { CompatShieldPatcher.Log.LogError((object)(message + " (logged once)")); } } } public static class SpawnCreditTweak { private const BindingFlags Any = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic; private static float multiplier; private static FieldInfo creditMultiplier; private static Type sceneDirector; private static Type directorCore; private static int logged; private static readonly HashSet<string> errors = new HashSet<string>(); internal static Func<object, bool> IsStageSpawner = OnDirectorObject; public static void Apply(Harmony h, Assembly ror2, float mult) { //IL_00d0: Unknown result type (might be due to invalid IL or missing references) //IL_00de: Expected O, but got Unknown try { Type? obj = ror2?.GetType("RoR2.CombatDirector"); creditMultiplier = obj?.GetField("creditMultiplier", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); sceneDirector = ror2?.GetType("RoR2.SceneDirector"); directorCore = ror2?.GetType("RoR2.DirectorCore"); MethodInfo methodInfo = obj?.GetMethod("Awake", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic, null, Type.EmptyTypes, null); if (creditMultiplier == null || methodInfo == null || (sceneDirector == null && directorCore == null)) { CompatShieldPatcher.Log.LogWarning((object)"Spawn credits: expected game members not found, not applied"); return; } multiplier = mult; h.Patch((MethodBase)methodInfo, new HarmonyMethod(typeof(SpawnCreditTweak).GetMethod("AwakePrefix", BindingFlags.Static | BindingFlags.NonPublic)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); CompatShieldPatcher.Log.LogInfo((object)$"Spawns: the stage's regular spawners earn {mult}x credits"); } catch (Exception ex) { CompatShieldPatcher.Log.LogError((object)("Spawn credit tweak failed to apply: " + ex)); } } private static bool OnDirectorObject(object director) { Component val = (Component)((director is Component) ? director : null); if ((Object)(object)val != (Object)null) { if (!(sceneDirector != null) || !((Object)(object)val.GetComponent(sceneDirector) != (Object)null)) { if (directorCore != null) { return (Object)(object)val.GetComponent(directorCore) != (Object)null; } return false; } return true; } return false; } private static void AwakePrefix(object __instance) { try { if (IsStageSpawner(__instance)) { float num = (float)creditMultiplier.GetValue(__instance); creditMultiplier.SetValue(__instance, num * multiplier); if (logged++ < 2) { CompatShieldPatcher.Log.LogInfo((object)$"Spawns: {Describe(__instance)} credits {num:0.##}x -> {num * multiplier:0.##}x"); } } } catch (Exception ex) { if (errors.Add("awake")) { CompatShieldPatcher.Log.LogError((object)("Spawn credits: couldn't scale a spawner (logged once): " + ex)); } } } private static string Describe(object director) { Component val = (Component)((director is Component) ? director : null); if (val == null) { return director.GetType().Name; } return GameObjectName(val); } [MethodImpl(MethodImplOptions.NoInlining)] private static string GameObjectName(Component c) { return ((Object)c.gameObject).name; } } public static class InteractableWeightTweak { private const BindingFlags Any = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic; private static float printer = 1f; private static float scrapper = 1f; private static float combiner = 1f; internal static float combinerCategoryFactor = 1f; private static MethodInfo getSpawnCard; private static readonly Dictionary<object, float> factor = new Dictionary<object, float>(); private static readonly HashSet<string> seen = new HashSet<string>(); private static bool errorLogged; public static void Apply(Assembly ror2, float printerMult, float scrapperMult, float combinerMult) { try { EventInfo eventInfo = (ror2?.GetType("RoR2.DirectorCardCategorySelection"))?.GetEvent("calcCardWeight", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); getSpawnCard = ror2?.GetType("RoR2.DirectorCard")?.GetMethod("GetSpawnCard", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic, null, Type.EmptyTypes, null); if (eventInfo == null || getSpawnCard == null) { CompatShieldPatcher.Log.LogWarning((object)"Printer/scrapper spawns: expected game members not found, not applied"); return; } printer = ((printerMult >= 0f) ? printerMult : 1f); scrapper = ((scrapperMult >= 0f) ? scrapperMult : 1f); combiner = ((combinerMult >= 0f) ? combinerMult : 1f); Delegate handler = Delegate.CreateDelegate(eventInfo.EventHandlerType, typeof(InteractableWeightTweak).GetMethod("OnCalc", BindingFlags.Static | BindingFlags.NonPublic)); eventInfo.AddEventHandler(null, handler); CompatShieldPatcher.Log.LogInfo((object)$"Spawns: printers {printer}x, scrappers {scrapper}x, Drone Combiners {combiner}x as likely per stage pick"); } catch (Exception ex) { CompatShieldPatcher.Log.LogError((object)("Printer/scrapper spawn tweak failed to apply: " + ex)); } } internal static float FactorFor(string cardName) { if (string.IsNullOrEmpty(cardName)) { return 1f; } if (DroneTweak.IsCombiner(cardName)) { if (!(combinerCategoryFactor > 0f)) { return combiner; } return combiner / combinerCategoryFactor; } if (cardName.IndexOf("Duplicator", StringComparison.OrdinalIgnoreCase) >= 0) { return printer; } if (cardName.IndexOf("Scrapper", StringComparison.OrdinalIgnoreCase) >= 0) { return scrapper; } return 1f; } private static void OnCalc(object card, ref float weight) { try { object obj = getSpawnCard.Invoke(card, null); if (obj == null) { return; } if (!factor.TryGetValue(obj, out var value)) { string text = CardName(obj); value = FactorFor(text); factor[obj] = value; if (value != 1f && seen.Add(text)) { CompatShieldPatcher.Log.LogInfo((object)$"Spawns: {text} weight x{value}"); } } weight *= value; } catch (Exception ex) { if (!errorLogged) { errorLogged = true; CompatShieldPatcher.Log.LogError((object)("Printer/scrapper spawns: couldn't scale a card (logged once): " + ex)); } } } [MethodImpl(MethodImplOptions.NoInlining)] private static string CardName(object sc) { object obj = ((sc is Object) ? sc : null); if (obj == null) { return null; } return ((Object)obj).name; } } public static class DroneTweak { private const BindingFlags Any = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic; private static readonly string[] ItemDroneBodies = new string[2] { "BackupDroneBody", "DroneCommanderBody" }; private static bool noMinStage; private static float spawn = 1f; private static float health = 1f; private static FieldInfo categories; private static FieldInfo catName; private static FieldInfo catWeight; private static FieldInfo catCards; private static FieldInfo cardMinStage; private static FieldInfo spawnPrefab; private static FieldInfo droneBody; private static FieldInfo droneRemote; private static FieldInfo baseHealth; private static FieldInfo levelHealth; private static FieldInfo summonMaster; private static FieldInfo masterBody; private static MethodInfo getSpawnCard; private static MethodInfo findBody; private static PropertyInfo allDrones; private static Type bodyType; private static Type summonType; private static Type masterType; private static bool catalogDone; private static bool errorLogged; private static readonly HashSet<GameObject> scaled = new HashSet<GameObject>(); private static readonly HashSet<string> unlockedLogged = new HashSet<string>(); internal static bool IsCombiner(string cardName) { if (cardName != null) { return cardName.IndexOf("DroneCombiner", StringComparison.OrdinalIgnoreCase) >= 0; } return false; } internal static bool IsDroneCategory(string name) { if (name != null) { return name.IndexOf("Drone", StringComparison.OrdinalIgnoreCase) >= 0; } return false; } public static void Apply(Assembly ror2, bool noMinimumStage, float spawnMult, float healthMult) { try { noMinStage = noMinimumStage; spawn = ((spawnMult >= 0f) ? spawnMult : 1f); health = ((healthMult > 0f) ? healthMult : 1f); if (noMinStage || !(Math.Abs(spawn - 1f) < 0.001f) || !(Math.Abs(health - 1f) < 0.001f)) { Type? obj = ror2?.GetType("RoR2.DirectorCardCategorySelection"); Type type = ror2?.GetType("RoR2.DirectorCardCategorySelection+Category"); Type type2 = ror2?.GetType("RoR2.DirectorCard"); Type type3 = ror2?.GetType("RoR2.DroneDef"); bodyType = ror2?.GetType("RoR2.CharacterBody"); summonType = ror2?.GetType("RoR2.SummonMasterBehavior"); masterType = ror2?.GetType("RoR2.CharacterMaster"); categories = obj?.GetField("categories", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); catName = type?.GetField("name", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); catWeight = type?.GetField("selectionWeight", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); catCards = type?.GetField("cards", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); cardMinStage = type2?.GetField("minimumStageCompletions", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); getSpawnCard = type2?.GetMethod("GetSpawnCard", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic, null, Type.EmptyTypes, null); spawnPrefab = ror2?.GetType("RoR2.SpawnCard")?.GetField("prefab", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); droneBody = type3?.GetField("bodyPrefab", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); droneRemote = type3?.GetField("remoteOpBody", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); baseHealth = bodyType?.GetField("baseMaxHealth", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); levelHealth = bodyType?.GetField("levelMaxHealth", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); summonMaster = summonType?.GetField("masterPrefab", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); masterBody = masterType?.GetField("bodyPrefab", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); allDrones = ror2?.GetType("RoR2.DroneCatalog")?.GetProperty("allDroneDefs", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); findBody = ror2?.GetType("RoR2.BodyCatalog")?.GetMethod("FindBodyPrefab", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[1] { typeof(string) }, null); EventInfo eventInfo = ror2?.GetType("RoR2.SceneDirector")?.GetEvent("onGenerateInteractableCardSelection", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); if (eventInfo == null || categories == null || catName == null || catWeight == null || catCards == null || cardMinStage == null || getSpawnCard == null || spawnPrefab == null || droneBody == null || droneRemote == null || baseHealth == null || levelHealth == null || summonMaster == null || masterBody == null || allDrones == null || findBody == null) { CompatShieldPatcher.Log.LogWarning((object)"Drones: expected game members not found, not applied"); return; } eventInfo.AddEventHandler(null, Delegate.CreateDelegate(eventInfo.EventHandlerType, typeof(DroneTweak).GetMethod("OnGenerate", BindingFlags.Static | BindingFlags.NonPublic))); CompatShieldPatcher.Log.LogInfo((object)$"Drones: no minimum stage={noMinStage}, {spawn}x as likely per stage pick, {health}x health"); } } catch (Exception ex) { CompatShieldPatcher.Log.LogError((object)("Drone tweak failed to apply: " + ex)); } } private static void OnGenerate(object director, object selection) { try { if (!catalogDone) { catalogDone = true; ScaleCatalog(); } if (!(categories.GetValue(selection) is Array array)) { return; } for (int i = 0; i < array.Length; i++) { object value = array.GetValue(i); string text = catName.GetValue(value) as string; bool flag = IsDroneCategory(text); if (flag) { catWeight.SetValue(value, (float)catWeight.GetValue(value) * spawn); array.SetValue(value, i); } if (!(catCards.GetValue(value) is Array array2)) { continue; } foreach (object item in array2) { if (item != null) { NoteCombiner(item, text, flag); if (flag) { HandleCard(item); } } } } } catch (Exception ex) { if (!errorLogged) { errorLogged = true; CompatShieldPatcher.Log.LogError((object)("Drones: couldn't adjust a stage's drones (logged once): " + ex)); } } } private static void NoteCombiner(object card, string category, bool inDroneCategory) { object? obj = getSpawnCard.Invoke(card, null); object? obj2 = ((obj is Object) ? obj : null); string text = ((obj2 != null) ? ((Object)obj2).name : null); if (IsCombiner(text)) { if (inDroneCategory) { InteractableWeightTweak.combinerCategoryFactor = spawn; } if (unlockedLogged.Add("combiner:" + category)) { CompatShieldPatcher.Log.LogInfo((object)$"Drones: {text} is in category '{category}', needs {cardMinStage.GetValue(card)} stages cleared"); } } } private static void HandleCard(object card) { object obj = getSpawnCard.Invoke(card, null); if (noMinStage && (int)cardMinStage.GetValue(card) > 0) { object obj2 = ((obj is Object) ? obj : null); string text = ((obj2 != null) ? ((Object)obj2).name : null) ?? "a drone card"; if (unlockedLogged.Add(text)) { CompatShieldPatcher.Log.LogInfo((object)$"Drones: {text} can now spawn from stage 1 (needed {cardMinStage.GetValue(card)} stages cleared)"); } cardMinStage.SetValue(card, 0); } if (!(Math.Abs(health - 1f) < 0.001f) && obj != null) { object? value = spawnPrefab.GetValue(obj); GameObject val = (GameObject)((value is GameObject) ? value : null); Component val2 = (((Object)(object)val != (Object)null) ? val.GetComponent(summonType) : null); GameObject val3 = (GameObject)(((Object)(object)val2 != (Object)null) ? /*isinst with value type is only supported in some contexts*/: null); Component val4 = (((Object)(object)val3 != (Object)null) ? val3.GetComponent(masterType) : null); if ((Object)(object)val4 != (Object)null) { object? value2 = masterBody.GetValue(val4); ScaleBody((GameObject)((value2 is GameObject) ? value2 : null)); } } } private static void ScaleCatalog() { if (Math.Abs(health - 1f) < 0.001f) { return; } if (allDrones.GetValue(null, null) is IEnumerable enumerable) { foreach (object item in enumerable) { if (item != null) { object? value = droneBody.GetValue(item); ScaleBody((GameObject)((value is GameObject) ? value : null)); object? value2 = droneRemote.GetValue(item); ScaleBody((GameObject)((value2 is GameObject) ? value2 : null)); } } } string[] itemDroneBodies = ItemDroneBodies; foreach (string text in itemDroneBodies) { object? obj = findBody.Invoke(null, new object[1] { text }); ScaleBody((GameObject)((obj is GameObject) ? obj : null)); } } private static void ScaleBody(GameObject prefab) { if (!((Object)(object)prefab == (Object)null) && scaled.Add(prefab)) { Component component = prefab.GetComponent(bodyType); if (!((Object)(object)component == (Object)null)) { float num = (float)baseHealth.GetValue(component); baseHealth.SetValue(component, num * health); levelHealth.SetValue(component, (float)levelHealth.GetValue(component) * health); CompatShieldPatcher.Log.LogInfo((object)$"Drones: {((Object)prefab).name} health {num:0.#} -> {num * health:0.#}"); } } } } public static class AssetRedirect { private static HashSet<string> known; private static Dictionary<string, string> byFile; private static readonly Dictionary<string, string> decided = new Dictionary<string, string>(); private static readonly object gate = new object(); private static int logged; private static bool failed; public static void Apply(Harmony h, MethodInfo evaluateKey) { //IL_0033: Unknown result type (might be due to invalid IL or missing references) //IL_0040: Expected O, but got Unknown try { if (evaluateKey == null) { CompatShieldPatcher.Log.LogWarning((object)"Asset redirect: AddressablesImpl.EvaluateKey not found, not applied"); return; } h.Patch((MethodBase)evaluateKey, (HarmonyMethod)null, new HarmonyMethod(typeof(AssetRedirect).GetMethod("Postfix", BindingFlags.Static | BindingFlags.NonPublic)), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); CompatShieldPatcher.Log.LogInfo((object)"Assets: moved game asset paths now load from their new location"); } catch (Exception ex) { CompatShieldPatcher.Log.LogError((object)("Asset redirect failed to apply: " + ex)); } } public static MethodInfo FindEvaluateKey() { return typeof(Addressables).Assembly.GetType("UnityEngine.AddressableAssets.AddressablesImpl")?.GetMethod("EvaluateKey", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[1] { typeof(object) }, null); } public static void BuildIndex(IEnumerable<object> keys) { HashSet<string> hashSet = new HashSet<string>(); Dictionary<string, string> dictionary = new Dictionary<string, string>(); foreach (object key2 in keys) { if (key2 is string text) { hashSet.Add(text); if (text.StartsWith("RoR2/", StringComparison.Ordinal)) { string key = text.Substring(text.LastIndexOf('/') + 1).ToLowerInvariant(); dictionary[key] = (dictionary.ContainsKey(key) ? null : text); } } } byFile = dictionary; known = hashSet; decided.Clear(); } public static string Redirect(string key) { if (!key.StartsWith("RoR2/", StringComparison.Ordinal) || known.Contains(key)) { return null; } if (decided.TryGetValue(key, out var value)) { return value; } byFile.TryGetValue(key.Substring(key.LastIndexOf('/') + 1).ToLowerInvariant(), out var value2); decided[key] = value2; if (value2 != null && logged++ < 25) { CompatShieldPatcher.Log.LogInfo((object)("Assets: '" + key + "' moved to '" + value2 + "'" + ((logged == 25) ? " (further moves not logged)" : ""))); } return value2; } private static void Postfix(ref object __result) { if (failed || !(__result is string text) || !text.StartsWith("RoR2/", StringComparison.Ordinal)) { return; } try { lock (gate) { if (known == null) { List<object> list = CatalogKeys(); if (list.Count == 0) { return; } BuildIndex(list); CompatShieldPatcher.Log.LogInfo((object)$"Assets: indexed {known.Count} catalog keys for the moved-asset redirect"); } string text2 = Redirect(text); if (text2 != null) { __result = text2; } } } catch (Exception ex) { failed = true; CompatShieldPatcher.Log.LogError((object)("Asset redirect stopped after an error: " + ex)); } } [MethodImpl(MethodImplOptions.NoInlining)] private static List<object> CatalogKeys() { List<object> list = new List<object>(); foreach (IResourceLocator resourceLocator in Addressables.ResourceLocators) { list.AddRange(resourceLocator.Keys); } return list; } } public static class StopSoundFix { private const BindingFlags Any = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic; private static readonly HashSet<uint> stopIds = new HashSet<uint>(); private static int passed; public static void Apply(Harmony h, Assembly audioOverlapFix, Assembly wwise) { try { MethodInfo methodInfo = audioOverlapFix.GetType("AudioOverlapFix.SoundEnginePatcher")?.GetMethod("shouldPostEvent", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[1] { typeof(string) }, null); MethodInfo methodInfo2 = audioOverlapFix.GetType("AudioOverlapFix.Main")?.GetMethod("tryPlaySound", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[1] { typeof(uint) }, null); MethodInfo methodInfo3 = wwise?.GetType("AkSoundEngine")?.GetMethod("GetIDFromString", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[1] { typeof(string) }, null); if (methodInfo == null || methodInfo2 == null || methodInfo3 == null) { CompatShieldPatcher.Log.LogWarning((object)"AudioOverlapFix stop fix: expected members not found, not applied"); return; } h.Patch((MethodBase)methodInfo3, (HarmonyMethod)null, Method("RecordStopId"), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); h.Patch((MethodBase)methodInfo, Method("ByNamePrefix"), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); h.Patch((MethodBase)methodInfo2, Method("ByIdPrefix"), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null); CompatShieldPatcher.Log.LogInfo((object)"AudioOverlapFix: stop events always go through now, so looping sounds can end"); } catch (Exception ex) { CompatShieldPatcher.Log.LogError((object)("AudioOverlapFix stop fix failed to apply: " + ex)); } } private static HarmonyMethod Method(string name) { //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Expected O, but got Unknown return new HarmonyMethod(typeof(StopSoundFix).GetMethod(name, BindingFlags.Static | BindingFlags.NonPublic)); } private static bool IsStop(string eventName) { return eventName?.StartsWith("Stop_", StringComparison.OrdinalIgnoreCase) ?? false; } private static void RecordStopId(string in_pszString, uint __result) { if (IsStop(in_pszString)) { lock (stopIds) { stopIds.Add(__result); } } } private static bool ByNamePrefix(string eventName, ref bool __result) { if (!IsStop(eventName)) { return true; } __result = true; Noted(); return false; } private static bool ByIdPrefix(uint eventID, ref bool __result) { bool flag; lock (stopIds) { flag = stopIds.Contains(eventID); } if (!flag) { return true; } __result = true; Noted(); return false; } private static void Noted() { if (passed++ == 0) { CompatShieldPatcher.Log.LogInfo((object)"AudioOverlapFix: first stop event let through (shown once)"); } } } public static class ZetAspectsDropFix { private static bool matched; private static bool alreadyFixed; public static MethodInfo FindHook(Assembly zetAspects) { try { return zetAspects.GetType("TPDespair.ZetAspects.DropHooks+<>c")?.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).FirstOrDefault((MethodInfo m) => m.Name.StartsWith("<EarlyDropChanceHook>") && m.GetParameters().Length == 3); } catch (Exception ex) { CompatShieldPatcher.Log.LogError((object)("ZetAspects drop fix: couldn't look up the hook: " + ex)); return null; } } public static void Apply(Harmony h, MethodInfo hook) { //IL_0040: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Expected O, but got Unknown if (hook == null) { CompatShieldPatcher.Log.LogWarning((object)"ZetAspects drop fix: EarlyDropChanceHook not found, not applied"); return; } try { matched = (alreadyFixed = false); h.Patch((MethodBase)hook, (HarmonyMethod)null, (HarmonyMethod)null, new HarmonyMethod(typeof(Ze