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 ForgeOfPotentialRedux v1.4.4
ForgeOfPotentialRedux.dll
Decompiled a week agousing System; using System.Collections.Generic; using System.Diagnostics; using System.Globalization; using System.Reflection; using System.Reflection.Emit; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Bootstrap; using BepInEx.Configuration; using BepInEx.Logging; using ConditionalConfigSync; using HarmonyLib; using Microsoft.CodeAnalysis; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: AssemblyCompany("ForgeOfPotentialRedux")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.4.4.0")] [assembly: AssemblyInformationalVersion("1.4.4")] [assembly: AssemblyProduct("ForgeOfPotentialRedux")] [assembly: AssemblyTitle("ForgeOfPotentialRedux")] [assembly: AssemblyVersion("1.4.4.0")] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace ForgeOfPotentialRedux { [BepInPlugin("com.dreich.fopredux", "Forge of Potential Redux", "1.4.4")] [BepInDependency(/*Could not decode attribute arguments.*/)] public class Plugin : BaseUnityPlugin { private const int DefaultLevelsLostOnFail = 1; private const int MinLevelsLostOnFail = 0; private const int MaxLevelsLostOnFail = 20; private const int DefaultEnemyCount = 1; private const int MinEnemyCount = 1; private const int MaxEnemyCount = 10; private const int DefaultEnemyStars = 1; private const int MinEnemyStars = 0; private const int MaxEnemyStars = 5; private const float DefaultSpawnDistance = 10f; private const float MinSpawnDistance = 2f; private const float MaxSpawnDistance = 20f; private const int DefaultBaseLevelCap = 3; private const int MinBaseLevelCap = 0; private const int MaxBaseLevelCap = 100; private const int DefaultLevelsPerBoss = 2; private const int MinLevelsPerBoss = 0; private const int MaxLevelsPerBoss = 50; private const float DefaultPenaltyPerSuccess = 5f; private const float MinPenaltyPerSuccess = 0f; private const float MaxPenaltyPerSuccess = 50f; private const float DefaultMaximumPenalty = 50f; private const float MinMaximumPenalty = 0f; private const float MaxMaximumPenalty = 100f; public const string PluginGuid = "com.dreich.fopredux"; public const string PluginName = "Forge of Potential Redux"; public const string PluginVersion = "1.4.4"; internal const string ConfigSyncGuid = "_shudnal.ConditionalConfigSync"; internal static ManualLogSource Log; internal static bool ConfigSyncAvailable; internal static ConfigEntry<bool> ResetToLevelOne; internal static ConfigEntry<int> LevelsLostOnFail; internal static ConfigEntry<bool> SpawnEnemyOnFail; internal static ConfigEntry<string> EnemyPrefabNames; internal static ConfigEntry<int> EnemyCount; internal static ConfigEntry<int> EnemyStars; internal static ConfigEntry<float> SpawnDistance; internal static ConfigEntry<bool> UseLastBossBiome; internal static ConfigEntry<string> ExcludedCreatures; internal static ConfigEntry<bool> TrophyBoostEnabled; internal static ConfigEntry<string> TrophyBonuses; internal static ConfigEntry<bool> TrophyConsumed; internal static ConfigEntry<string> BossTrophyTiers; internal static ConfigEntry<string> TierMaterials; internal static ConfigEntry<bool> LevelCapEnabled; internal static ConfigEntry<bool> LogForgeScan; internal static ConfigEntry<bool> GearOnly; internal static ConfigEntry<int> LevelCapBase; internal static ConfigEntry<int> LevelCapPerBoss; internal static ConfigEntry<bool> PenaltyEnabled; internal static ConfigEntry<float> PenaltyPerSuccess; internal static ConfigEntry<float> PenaltyMax; internal const string DefaultTrophyBonuses = "TrophyDeer=0.5,TrophyBoar=1,TrophyNeck=1,TrophyGreydwarf=1.5,TrophySkeleton=2,TrophyGreydwarfShaman=2.5,TrophyGhost=3,TrophyGreydwarfBrute=3.5,TrophySkeletonPoison=4.5,TrophyBjorn=5,TrophyForestTroll=6,TrophySkeletonHildir=7,TrophySurtling=2.5,TrophyLeech=3,TrophyBlob=3,TrophyDraugr=3.5,TrophyDraugrFem=3.5,TrophyDraugrElite=5,TrophyWraith=6,TrophyKvastur=6.5,TrophyWrithan=7,TrophyAbomination=8,TrophyWolf=4.5,TrophyHatchling=5,TrophyBlob_Frost=5.5,TrophyUlv=6.5,TrophyFenring=6.5,TrophyCultist=8,TrophySGolem=9,TrophyCultist_Hildir=10,TrophySerpent=9,TrophyDeathsquito=6.5,TrophyGoblin=7,TrophyGoblinShaman=7.5,TrophyGrowth=8,TrophyLox=9,TrophyBjornUndead=9.5,TrophyGoblinBrute=11,TrophyGoblinBruteBrosShaman=12,TrophyGoblinBruteBrosBrute=12,TrophyHare=7,TrophyTick=8,TrophySeeker=10,TrophyDvergr=11,TrophySeekerBrute=14,TrophyGjall=15,TrophyVolture=12,TrophyAsksvin=13,TrophyBlob_Lava=13,TrophyCharredMelee=14,TrophyCharredArcher=14,TrophyCharredMage=15,TrophyBonemawSerpent=17,TrophyFallenValkyrie=18,TrophyMorgen=20,TrophySeal=15,TrophyDeerWhite=15,TrophyMoose=16,TrophyFrostTroll=17,TrophyBlob_Morkhalla=18,TrophyBarka=19,TrophyMole=20,TrophyElaking=21,TrophyJotunWitch=22,TrophyJotunWarrior=24"; private const string PreviousDefaultTrophyBonuses = "TrophyDeer=0.5,TrophyBoar=1,TrophyNeck=1,TrophyGreydwarf=1.5,TrophySkeleton=2,TrophyGreydwarfShaman=2.5,TrophyGhost=3,TrophyGreydwarfBrute=3.5,TrophySkeletonPoison=4.5,TrophyBjorn=5,TrophyFrostTroll=6,TrophySkeletonHildir=7,TrophySurtling=2.5,TrophyLeech=3,TrophyBlob=3,TrophyDraugr=3.5,TrophyDraugrFem=3.5,TrophyDraugrElite=5,TrophyWraith=6,TrophyKvastur=6.5,TrophyWrithan=7,TrophyAbomination=8,TrophyWolf=4.5,TrophyHatchling=5,TrophyBlob_Frost=5.5,TrophyUlv=6.5,TrophyFenring=6.5,TrophyCultist=8,TrophySGolem=9,TrophyCultist_Hildir=10,TrophySerpent=9,TrophyDeathsquito=6.5,TrophyGoblin=7,TrophyGoblinShaman=7.5,TrophyGrowth=8,TrophyLox=9,TrophyBjornUndead=9.5,TrophyGoblinBrute=11,TrophyGoblinBruteBrosShaman=12,TrophyGoblinBruteBrosBrute=12,TrophyHare=7,TrophyTick=8,TrophySeeker=10,TrophyDvergr=11,TrophySeekerBrute=14,TrophyGjall=15,TrophyVolture=12,TrophyAsksvin=13,TrophyBlob_Lava=13,TrophyCharredMelee=14,TrophyCharredArcher=14,TrophyCharredMage=15,TrophyBonemawSerpent=17,TrophyFallenValkyrie=18,TrophyMorgen=20,TrophySeal=15,TrophyDeerWhite=15,TrophyMoose=16,TrophyBlob_Morkhalla=18,TrophyBarka=19,TrophyMole=20,TrophyElaking=21,TrophyJotunWitch=22,TrophyJotunWarrior=24"; internal static readonly Dictionary<Biome, ConfigEntry<string>> BiomeCreatures = new Dictionary<Biome, ConfigEntry<string>>(); private void Awake() { //IL_00a7: Unknown result type (might be due to invalid IL or missing references) //IL_00b1: Expected O, but got Unknown //IL_012c: Unknown result type (might be due to invalid IL or missing references) //IL_0136: Expected O, but got Unknown //IL_0162: Unknown result type (might be due to invalid IL or missing references) //IL_016c: Expected O, but got Unknown //IL_01a4: Unknown result type (might be due to invalid IL or missing references) //IL_01ae: Expected O, but got Unknown //IL_03ef: Unknown result type (might be due to invalid IL or missing references) //IL_03f9: Expected O, but got Unknown //IL_0426: Unknown result type (might be due to invalid IL or missing references) //IL_0430: Expected O, but got Unknown //IL_048d: Unknown result type (might be due to invalid IL or missing references) //IL_0497: Expected O, but got Unknown //IL_04cf: Unknown result type (might be due to invalid IL or missing references) //IL_04d9: Expected O, but got Unknown //IL_0508: Unknown result type (might be due to invalid IL or missing references) Log = ((BaseUnityPlugin)this).Logger; ConfigSyncAvailable = Chainloader.PluginInfos.ContainsKey("_shudnal.ConditionalConfigSync"); if (ConfigSyncAvailable) { ConfigSyncCompat.Initialize("com.dreich.fopredux", "Forge of Potential Redux", "1.4.4"); } ResetToLevelOne = Synced<bool>(((BaseUnityPlugin)this).Config.Bind<bool>("Forge of Potential", "Reset to level 1 on failure", true, "If true, a failed upgrade always sets the item back to level 1 and 'Levels lost on fail' is ignored.")); GearOnly = Synced<bool>(((BaseUnityPlugin)this).Config.Bind<bool>("Forge of Potential", "Only weapons, armor and tools", true, "If true, the Forge of Potential only upgrades weapons, shields, armor, capes and tools. Other items such as belts, trinkets and ammo are hidden from its list and cannot be upgraded there.")); LevelsLostOnFail = Synced<int>(((BaseUnityPlugin)this).Config.Bind<int>("Forge of Potential", "Levels lost on fail", 1, new ConfigDescription("How many levels an item loses when an upgrade fails (only used when 'Reset to level 1' is false). 0 = no levels lost. The item never drops below level 1.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 20), Array.Empty<object>()))); SpawnEnemyOnFail = Synced<bool>(((BaseUnityPlugin)this).Config.Bind<bool>("Enemy Spawn", "Spawn enemy on fail", true, "If true, a failed upgrade spawns enemies next to the player.")); EnemyPrefabNames = Synced<string>(((BaseUnityPlugin)this).Config.Bind<string>("Enemy Spawn", "Enemy prefabs", "Greydwarf", "Comma-separated internal prefab names, e.g. 'Greydwarf,Skeleton,Draugr'. Each spawned enemy picks one at random from the enemies to spawn. Names are case-sensitive. Used when 'Use last boss biome' is off, when no boss has been defeated yet, or when the boss biome list is empty.")); EnemyCount = Synced<int>(((BaseUnityPlugin)this).Config.Bind<int>("Enemy Spawn", "Enemy count", 1, new ConfigDescription("How many enemies spawn on a failed upgrade.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 10), Array.Empty<object>()))); EnemyStars = Synced<int>(((BaseUnityPlugin)this).Config.Bind<int>("Enemy Spawn", "Enemy stars", 1, new ConfigDescription("Star level of the spawned enemies. 0 = normal, 1 = one star, 2 = two stars (the vanilla maximum). Values above 2 are stronger than anything the game normally spawns.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 5), Array.Empty<object>()))); SpawnDistance = Synced<float>(((BaseUnityPlugin)this).Config.Bind<float>("Enemy Spawn", "Spawn distance", 10f, new ConfigDescription("How far from the player the enemy appears, in meters.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(2f, 20f), Array.Empty<object>()))); UseLastBossBiome = Synced<bool>(((BaseUnityPlugin)this).Config.Bind<bool>("Boss Biome Spawn", "Use last boss biome", true, "If true, failed upgrades spawn a random creature from the biome of the last boss you helped kill (using the per-biome lists below). If you have not killed a boss on this character, the highest boss defeated on the world is used; if none have been defeated, the regular 'Enemy prefabs' list is used.")); ExcludedCreatures = Synced<string>(((BaseUnityPlugin)this).Config.Bind<string>("Boss Biome Spawn", "Excluded creatures", "Gjall,SeekerBrute,Troll,GoblinBrute", "Comma-separated prefab names that never spawn from a failed upgrade, even if they appear in one of the lists. Defaults exclude Gjall, Seeker Soldier (SeekerBrute), Troll and Fuling Berserker (GoblinBrute). Not case-sensitive.")); BindBiome((Biome)1, "Meadows (Eikthyr)", "Boar,Neck,Greyling"); BindBiome((Biome)8, "Black Forest (The Elder)", "Greydwarf,Greydwarf_Elite,Greydwarf_Shaman,Skeleton"); BindBiome((Biome)2, "Swamp (Bonemass)", "Draugr,Draugr_Elite,Blob,Leech,Wraith"); BindBiome((Biome)4, "Mountain (Moder)", "Wolf,Fenring,Hatchling,StoneGolem,Ulv"); BindBiome((Biome)16, "Plains (Yagluth)", "Goblin,GoblinArcher,GoblinShaman,Deathsquito,Lox"); BindBiome((Biome)512, "Mistlands (The Queen)", "Seeker,Tick"); BindBiome((Biome)32, "Ashlands (Fader)", "Charred_Melee,Charred_Archer,Charred_Mage,Asksvin,Volture,Morgen"); BindBiome((Biome)64, "Deep North (Kall Fimbulbringer)", "JotunWarrior,JotunWarriorDualWield,JotunWitch,Barka,Elaking,ElakingMole,BlobMork,Skeleton_DeepNorth"); TrophyBoostEnabled = Synced<bool>(((BaseUnityPlugin)this).Config.Bind<bool>("Trophy Boost", "Enabled", true, "If true, carrying a creatures trophy adds to the success chance of Forge of Potential upgrades.")); TrophyBonuses = Synced<string>(((BaseUnityPlugin)this).Config.Bind<string>("Trophy Boost", "Trophy bonuses", "TrophyDeer=0.5,TrophyBoar=1,TrophyNeck=1,TrophyGreydwarf=1.5,TrophySkeleton=2,TrophyGreydwarfShaman=2.5,TrophyGhost=3,TrophyGreydwarfBrute=3.5,TrophySkeletonPoison=4.5,TrophyBjorn=5,TrophyForestTroll=6,TrophySkeletonHildir=7,TrophySurtling=2.5,TrophyLeech=3,TrophyBlob=3,TrophyDraugr=3.5,TrophyDraugrFem=3.5,TrophyDraugrElite=5,TrophyWraith=6,TrophyKvastur=6.5,TrophyWrithan=7,TrophyAbomination=8,TrophyWolf=4.5,TrophyHatchling=5,TrophyBlob_Frost=5.5,TrophyUlv=6.5,TrophyFenring=6.5,TrophyCultist=8,TrophySGolem=9,TrophyCultist_Hildir=10,TrophySerpent=9,TrophyDeathsquito=6.5,TrophyGoblin=7,TrophyGoblinShaman=7.5,TrophyGrowth=8,TrophyLox=9,TrophyBjornUndead=9.5,TrophyGoblinBrute=11,TrophyGoblinBruteBrosShaman=12,TrophyGoblinBruteBrosBrute=12,TrophyHare=7,TrophyTick=8,TrophySeeker=10,TrophyDvergr=11,TrophySeekerBrute=14,TrophyGjall=15,TrophyVolture=12,TrophyAsksvin=13,TrophyBlob_Lava=13,TrophyCharredMelee=14,TrophyCharredArcher=14,TrophyCharredMage=15,TrophyBonemawSerpent=17,TrophyFallenValkyrie=18,TrophyMorgen=20,TrophySeal=15,TrophyDeerWhite=15,TrophyMoose=16,TrophyFrostTroll=17,TrophyBlob_Morkhalla=18,TrophyBarka=19,TrophyMole=20,TrophyElaking=21,TrophyJotunWitch=22,TrophyJotunWarrior=24", "Comma-separated 'TrophyPrefab=percent' pairs. The percent is added to the upgrade's success chance (capped at 100%). If several listed trophies are carried, only the best one applies and is used up. Trophies listed under 'Boss trophy tiers' are ignored here. Names are case-sensitive; unknown names are skipped with a warning.")); if (TrophyBonuses.Value == "TrophyDeer=0.5,TrophyBoar=1,TrophyNeck=1,TrophyGreydwarf=1.5,TrophySkeleton=2,TrophyGreydwarfShaman=2.5,TrophyGhost=3,TrophyGreydwarfBrute=3.5,TrophySkeletonPoison=4.5,TrophyBjorn=5,TrophyFrostTroll=6,TrophySkeletonHildir=7,TrophySurtling=2.5,TrophyLeech=3,TrophyBlob=3,TrophyDraugr=3.5,TrophyDraugrFem=3.5,TrophyDraugrElite=5,TrophyWraith=6,TrophyKvastur=6.5,TrophyWrithan=7,TrophyAbomination=8,TrophyWolf=4.5,TrophyHatchling=5,TrophyBlob_Frost=5.5,TrophyUlv=6.5,TrophyFenring=6.5,TrophyCultist=8,TrophySGolem=9,TrophyCultist_Hildir=10,TrophySerpent=9,TrophyDeathsquito=6.5,TrophyGoblin=7,TrophyGoblinShaman=7.5,TrophyGrowth=8,TrophyLox=9,TrophyBjornUndead=9.5,TrophyGoblinBrute=11,TrophyGoblinBruteBrosShaman=12,TrophyGoblinBruteBrosBrute=12,TrophyHare=7,TrophyTick=8,TrophySeeker=10,TrophyDvergr=11,TrophySeekerBrute=14,TrophyGjall=15,TrophyVolture=12,TrophyAsksvin=13,TrophyBlob_Lava=13,TrophyCharredMelee=14,TrophyCharredArcher=14,TrophyCharredMage=15,TrophyBonemawSerpent=17,TrophyFallenValkyrie=18,TrophyMorgen=20,TrophySeal=15,TrophyDeerWhite=15,TrophyMoose=16,TrophyBlob_Morkhalla=18,TrophyBarka=19,TrophyMole=20,TrophyElaking=21,TrophyJotunWitch=22,TrophyJotunWarrior=24") { TrophyBonuses.Value = "TrophyDeer=0.5,TrophyBoar=1,TrophyNeck=1,TrophyGreydwarf=1.5,TrophySkeleton=2,TrophyGreydwarfShaman=2.5,TrophyGhost=3,TrophyGreydwarfBrute=3.5,TrophySkeletonPoison=4.5,TrophyBjorn=5,TrophyForestTroll=6,TrophySkeletonHildir=7,TrophySurtling=2.5,TrophyLeech=3,TrophyBlob=3,TrophyDraugr=3.5,TrophyDraugrFem=3.5,TrophyDraugrElite=5,TrophyWraith=6,TrophyKvastur=6.5,TrophyWrithan=7,TrophyAbomination=8,TrophyWolf=4.5,TrophyHatchling=5,TrophyBlob_Frost=5.5,TrophyUlv=6.5,TrophyFenring=6.5,TrophyCultist=8,TrophySGolem=9,TrophyCultist_Hildir=10,TrophySerpent=9,TrophyDeathsquito=6.5,TrophyGoblin=7,TrophyGoblinShaman=7.5,TrophyGrowth=8,TrophyLox=9,TrophyBjornUndead=9.5,TrophyGoblinBrute=11,TrophyGoblinBruteBrosShaman=12,TrophyGoblinBruteBrosBrute=12,TrophyHare=7,TrophyTick=8,TrophySeeker=10,TrophyDvergr=11,TrophySeekerBrute=14,TrophyGjall=15,TrophyVolture=12,TrophyAsksvin=13,TrophyBlob_Lava=13,TrophyCharredMelee=14,TrophyCharredArcher=14,TrophyCharredMage=15,TrophyBonemawSerpent=17,TrophyFallenValkyrie=18,TrophyMorgen=20,TrophySeal=15,TrophyDeerWhite=15,TrophyMoose=16,TrophyFrostTroll=17,TrophyBlob_Morkhalla=18,TrophyBarka=19,TrophyMole=20,TrophyElaking=21,TrophyJotunWitch=22,TrophyJotunWarrior=24"; } TrophyConsumed = Synced<bool>(((BaseUnityPlugin)this).Config.Bind<bool>("Trophy Boost", "Consumed on use", true, "If true, one trophy is used up per upgrade attempt. If false, carrying it boosts every attempt.")); BossTrophyTiers = Synced<string>(((BaseUnityPlugin)this).Config.Bind<string>("Trophy Boost", "Boss trophy tiers", "TrophyEikthyr=Meadows,TrophyTheElder=BlackForest,TrophyBonemass=Swamp,TrophyDragonQueen=Mountain,TrophyGoblinKing=Plains,TrophySeekerQueen=Mistlands,TrophyFader=AshLands", "Comma-separated 'TrophyPrefab=Biome' pairs. Carrying a boss trophy makes the upgrade 100% successful, but only on weapons and armor from that boss's biome (see 'Tier materials'). Boss trophies give no bonus on gear from other biomes and are not used up there. Biomes: Meadows, BlackForest, Swamp, Mountain, Plains, Mistlands, AshLands, DeepNorth.")); TierMaterials = Synced<string>(((BaseUnityPlugin)this).Config.Bind<string>("Trophy Boost", "Tier materials", "Bronze=BlackForest,Copper=BlackForest,Tin=BlackForest,TrollHide=BlackForest,BjornHide=BlackForest,BjornPaw=BlackForest,TrophyBjorn=BlackForest,TrophySkeleton=BlackForest,Voidplasm=BlackForest,GreydwarfEye=BlackForest,SurtlingCore=BlackForest,RoundLog=BlackForest,FineWood=BlackForest,Iron=Swamp,Ectoplasm=Swamp,Guck=Swamp,Chain=Swamp,ElderBark=Swamp,Root=Swamp,TrophyDraugrElite=Swamp,Chitin=Swamp,SerpentScale=Swamp,Bloodbag=Swamp,GiantBloodSack=Swamp,WrithanRoots=Swamp,Silver=Mountain,Crystal=Mountain,WolfHairBundle=Mountain,WolfPelt=Mountain,WolfFang=Mountain,WolfClaw=Mountain,Obsidian=Mountain,FreezeGland=Mountain,JuteRed=Mountain,TrophyWolf=Mountain,TrophyHatchling=Mountain,TrophyCultist=Mountain,YmirRemains=Mountain,ScytheHandle=Mountain,BlackMetal=Plains,LinenThread=Plains,LoxPelt=Plains,Needle=Plains,TrophyBjornUndead=Plains,UndeadBjornRibcage=Plains,Carapace=Mistlands,Eitr=Mistlands,ScaleHide=Mistlands,Mandible=Mistlands,BlackCore=Mistlands,YggdrasilWood=Mistlands,JuteBlue=Mistlands,Bilebag=Mistlands,Wisp=Mistlands,Flametal=AshLands,FlametalNew=AshLands,AskHide=AshLands,AskBladder=AshLands,CharredBone=AshLands,CelestialFeather=AshLands,MoltenCore=AshLands,MorgenHeart=AshLands,FaderEmber=AshLands,GemstoneRed=AshLands,GemstoneGreen=AshLands,GemstoneBlue=AshLands,MorgenSinew=AshLands,BonemawSerpentTooth=AshLands,SulfurStone=AshLands,Fiddleheadfern=AshLands,DyrnwynBladeFragment=AshLands,DyrnwynHiltFragment=AshLands,DyrnwynTipFragment=AshLands,AxeBerzerkr=AshLands,BowAshlands=AshLands,CrossbowRipper=AshLands,MaceEldner=AshLands,SpearSplitner=AshLands,SwordNiedhogg=AshLands,THSwordSlayer=AshLands,BarkaBranch=DeepNorth,Blackwood=DeepNorth,Frostwood=DeepNorth,MooseHide=DeepNorth,MooseSinew=DeepNorth,NornThread=DeepNorth,SealHide=DeepNorth,ElakingHairBundle=DeepNorth,ProustitePowder=DeepNorth,OrbFrostFire=DeepNorth,TrophyJotunWitch=DeepNorth,TrophyMoose=DeepNorth,TrophyFrostTroll=DeepNorth,Ice=DeepNorth,OrbThunderBlood=DeepNorth,Gold=DeepNorth,Leatherstraps=DeepNorth,AtgeirGold=DeepNorth,AxeGold=DeepNorth,BattleaxeGold=DeepNorth,BowGold=DeepNorth,CrossbowGold=DeepNorth,FistGold=DeepNorth,KnifeGold=DeepNorth,MaceGold=DeepNorth,SledgeGold=DeepNorth,SpearGold=DeepNorth,SwordGold=DeepNorth,THSwordGold=DeepNorth,MoldArmorGoldChest=DeepNorth,MoldArmorGoldLegs=DeepNorth,MoldArmorMageChest=DeepNorth,MoldArmorMageHelmet=DeepNorth,MoldArmorMageLegs=DeepNorth,MoldArmormediumChest=DeepNorth,MoldArmorMediumHelmet=DeepNorth,MoldArmorMediumLegs=DeepNorth,MoldAtgeir=DeepNorth,MoldAxe=DeepNorth,MoldAxe2H=DeepNorth,MoldBow=DeepNorth,MoldCrossbow=DeepNorth,MoldFistweapon=DeepNorth,MoldKnife=DeepNorth,MoldMace=DeepNorth,MoldMace2H=DeepNorth,MoldShieldBuckler=DeepNorth,MoldShieldRound=DeepNorth,MoldShieldTower=DeepNorth,MoldSpear=DeepNorth,MoldSword=DeepNorth,MoldSword2H=DeepNorth", "Comma-separated 'MaterialPrefab=Biome' pairs, only used for gear whose Forge of Potential recipe has no idol to tell its biome (normally every item's biome comes from the idol its forge upgrade needs). For that gear, its biome is the latest biome among the materials in its crafting recipe; gear with none of these materials counts as Meadows. Materials that no forge-upgradable item is made from are ignored. Turn on 'Log forge scan' under Debug to list which entries are used and which are ignored.")); LevelCapEnabled = Synced<bool>(((BaseUnityPlugin)this).Config.Bind<bool>("Level Cap", "Enabled", true, "If true, the Forge of Potential can't upgrade an item past the level cap. The cap is the item's normal max level plus 'Base level cap', and rises by 'Levels per boss' for every boss defeated on the world.")); LevelCapBase = Synced<int>(((BaseUnityPlugin)this).Config.Bind<int>("Level Cap", "Base level cap", 3, new ConfigDescription("How many levels past the item's normal max level the forge can reach before any boss is defeated. Example: a sword that normally maxes at level 4 can reach level 7 with the default of 3.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), Array.Empty<object>()))); LevelCapPerBoss = Synced<int>(((BaseUnityPlugin)this).Config.Bind<int>("Level Cap", "Levels per boss", 2, new ConfigDescription("How much the level cap rises for each boss defeated on the world.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 50), Array.Empty<object>()))); PenaltyEnabled = Synced<bool>(((BaseUnityPlugin)this).Config.Bind<bool>("Success Penalty", "Enabled", false, "If true, every successful upgrade lowers the success chance of that item's next upgrade, stacking with each success in a row. A failed upgrade resets it. Tracked per item.")); PenaltyPerSuccess = Synced<float>(((BaseUnityPlugin)this).Config.Bind<float>("Success Penalty", "Penalty per success (%)", 5f, new ConfigDescription("Percentage points removed from the success chance for each successful upgrade in a row.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 50f), Array.Empty<object>()))); PenaltyMax = Synced<float>(((BaseUnityPlugin)this).Config.Bind<float>("Success Penalty", "Maximum penalty (%)", 50f, new ConfigDescription("The most percentage points the penalty can remove, no matter how long the streak. Trophy bonuses are applied on top of the penalty.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 100f), Array.Empty<object>()))); LogForgeScan = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug", "Log forge scan", false, "If true, each time you enter a world the log lists the items the Forge of Potential can upgrade and which tier materials they use."); new Harmony("com.dreich.fopredux").PatchAll(); object? obj = AccessTools.Field(typeof(Localization), "m_instance")?.GetValue(null); LocalizationTweaks.Apply((Localization)((obj is Localization) ? obj : null)); } private static ConfigEntry<T> Synced<T>(ConfigEntry<T> entry) { if (ConfigSyncAvailable) { ConfigSyncCompat.AddServerControlled<T>(entry); } return entry; } private void BindBiome(Biome biome, string label, string defaultPrefabs, string description = "Comma-separated prefab names that can spawn when this was the last boss you helped kill. Names are case-sensitive.") { //IL_001f: Unknown result type (might be due to invalid IL or missing references) ConfigEntry<string> value = Synced<string>(((BaseUnityPlugin)this).Config.Bind<string>("Boss Biome Spawn", label, defaultPrefabs, description)); BiomeCreatures[biome] = value; } } internal static class ConfigSyncCompat { private static object configSync; [MethodImpl(MethodImplOptions.NoInlining)] internal static void Initialize(string guid, string name, string version) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Expected O, but got Unknown configSync = (object)new ConfigSync(guid) { DisplayName = name, CurrentVersion = version, MinimumRequiredVersion = version, ModRequired = true }; } [MethodImpl(MethodImplOptions.NoInlining)] internal static void AddServerControlled<T>(ConfigEntry<T> entry) { //IL_0005: Unknown result type (might be due to invalid IL or missing references) ((ConditionalConfigSync)(ConfigSync)configSync).AddConfigEntry<T>(entry, (ConfigSyncMode)0); } } internal static class IlHelpers { public static int LocalIndex(this CodeInstruction instruction) { OpCode opcode = instruction.opcode; if (opcode == OpCodes.Ldloc_0 || opcode == OpCodes.Stloc_0) { return 0; } if (opcode == OpCodes.Ldloc_1 || opcode == OpCodes.Stloc_1) { return 1; } if (opcode == OpCodes.Ldloc_2 || opcode == OpCodes.Stloc_2) { return 2; } if (opcode == OpCodes.Ldloc_3 || opcode == OpCodes.Stloc_3) { return 3; } object operand = instruction.operand; if (!(operand is LocalBuilder localBuilder)) { if (operand is byte) { return (byte)operand; } if (operand is sbyte) { return (sbyte)operand; } if (operand is short) { return (short)operand; } if (operand is ushort) { return (ushort)operand; } if (operand is int) { return (int)operand; } throw new ArgumentException("Instruction does not reference a local variable: " + (object)instruction); } return localBuilder.LocalIndex; } public static CodeInstruction LoadLocal(int index) { //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Expected O, but got Unknown //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Expected O, but got Unknown //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Expected O, but got Unknown //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Expected O, but got Unknown //IL_006e: Unknown result type (might be due to invalid IL or missing references) //IL_0074: Expected O, but got Unknown //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_0062: Expected O, but got Unknown switch (index) { case 0: return new CodeInstruction(OpCodes.Ldloc_0, (object)null); case 1: return new CodeInstruction(OpCodes.Ldloc_1, (object)null); case 2: return new CodeInstruction(OpCodes.Ldloc_2, (object)null); case 3: return new CodeInstruction(OpCodes.Ldloc_3, (object)null); default: if (index <= 255) { return new CodeInstruction(OpCodes.Ldloc_S, (object)(byte)index); } return new CodeInstruction(OpCodes.Ldloc, (object)(short)index); } } public static CodeInstruction StoreLocal(int index) { //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0024: Expected O, but got Unknown //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Expected O, but got Unknown //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Expected O, but got Unknown //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Expected O, but got Unknown //IL_006e: Unknown result type (might be due to invalid IL or missing references) //IL_0074: Expected O, but got Unknown //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_0062: Expected O, but got Unknown switch (index) { case 0: return new CodeInstruction(OpCodes.Stloc_0, (object)null); case 1: return new CodeInstruction(OpCodes.Stloc_1, (object)null); case 2: return new CodeInstruction(OpCodes.Stloc_2, (object)null); case 3: return new CodeInstruction(OpCodes.Stloc_3, (object)null); default: if (index <= 255) { return new CodeInstruction(OpCodes.Stloc_S, (object)(byte)index); } return new CodeInstruction(OpCodes.Stloc, (object)(short)index); } } } public static class BossTracker { internal const string CustomDataKey = "FoP_LastBossBiome"; private const string BossKilledRpc = "FoP_BossKilled"; private const float RecordRange = 100f; private static readonly (string globalKey, Biome biome)[] Bosses = new(string, Biome)[8] { ("defeated_eikthyr", (Biome)1), ("defeated_gdking", (Biome)8), ("defeated_bonemass", (Biome)2), ("defeated_dragon", (Biome)4), ("defeated_goblinking", (Biome)16), ("defeated_queen", (Biome)512), ("defeated_fader", (Biome)32), ("defeated_frozenking", (Biome)64) }; public static void DetectDeepNorthBossKey(IEnumerable<GameObject> prefabs) { if (prefabs == null) { return; } HashSet<string> hashSet = new HashSet<string>(); foreach (GameObject prefab in prefabs) { Character val = (((Object)(object)prefab != (Object)null) ? prefab.GetComponent<Character>() : null); if ((Object)(object)val == (Object)null || !val.m_boss || string.IsNullOrEmpty(val.m_defeatSetGlobalKey)) { continue; } string text = val.m_defeatSetGlobalKey.ToLowerInvariant(); bool flag = false; for (int i = 0; i < Bosses.Length - 1; i++) { if (Bosses[i].globalKey == text) { flag = true; } } if (!flag) { hashSet.Add(text); } } int num = Bosses.Length - 1; if (hashSet.Count != 1) { return; } foreach (string item in hashSet) { Bosses[num].globalKey = item; } } public static void RegisterRpc() { if (ZRoutedRpc.instance != null) { ZRoutedRpc.instance.Register<string, Vector3>("FoP_BossKilled", (Action<long, string, Vector3>)OnBossKilled); } } public static void BroadcastBossKill(Character boss) { //IL_0035: Unknown result type (might be due to invalid IL or missing references) string defeatSetGlobalKey = boss.m_defeatSetGlobalKey; if (!string.IsNullOrEmpty(defeatSetGlobalKey) && ZRoutedRpc.instance != null) { ZRoutedRpc.instance.InvokeRoutedRPC(0L, "FoP_BossKilled", new object[2] { defeatSetGlobalKey, ((Component)boss).transform.position }); } } private static void OnBossKilled(long sender, string globalKey, Vector3 position) { //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Unknown result type (might be due to invalid IL or missing references) try { Player localPlayer = Player.m_localPlayer; if ((Object)(object)localPlayer == (Object)null || Vector3.Distance(((Component)localPlayer).transform.position, position) > 100f) { return; } (string, Biome)[] bosses = Bosses; for (int i = 0; i < bosses.Length; i++) { (string, Biome) tuple = bosses[i]; if (string.Equals(tuple.Item1, globalKey, StringComparison.OrdinalIgnoreCase)) { RecordBossKill(localPlayer, tuple.Item2); break; } } } catch (Exception ex) { Plugin.Log.LogWarning((object)("Failed to record boss kill: " + ex.Message)); } } public static Biome? GetLastDefeatedBiome() { //IL_004a: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)ZoneSystem.instance == (Object)null) { return null; } for (int num = Bosses.Length - 1; num >= 0; num--) { if (ZoneSystem.instance.GetGlobalKey(Bosses[num].globalKey)) { return Bosses[num].biome; } } return null; } public static int CountDefeatedBosses() { if ((Object)(object)ZoneSystem.instance == (Object)null) { return 0; } int num = 0; (string, Biome)[] bosses = Bosses; for (int i = 0; i < bosses.Length; i++) { (string, Biome) tuple = bosses[i]; if (ZoneSystem.instance.GetGlobalKey(tuple.Item1)) { num++; } } return num; } private static string CurrentWorldName() { if (!((Object)(object)ZNet.instance != (Object)null)) { return ""; } return ZNet.instance.GetWorldName() ?? ""; } public unsafe static void RecordBossKill(Player player, Biome biome) { player.m_customData["FoP_LastBossBiome"] = ((object)(*(Biome*)(&biome))/*cast due to .constrained prefix*/).ToString() + "|" + CurrentWorldName(); } public static Biome? GetLastBossBiome() { //IL_005a: Unknown result type (might be due to invalid IL or missing references) Player localPlayer = Player.m_localPlayer; if ((Object)(object)localPlayer != (Object)null && localPlayer.m_customData.TryGetValue("FoP_LastBossBiome", out var value)) { string[] array = value.Split(new char[1] { '|' }, 2); if ((array.Length < 2 || array[1] == CurrentWorldName()) && Enum.TryParse<Biome>(array[0], out Biome result)) { return result; } } return GetLastDefeatedBiome(); } public static string GetBossBiomePrefabList() { //IL_0024: Unknown result type (might be due to invalid IL or missing references) if (!Plugin.UseLastBossBiome.Value) { return null; } Biome? lastBossBiome = GetLastBossBiome(); if (lastBossBiome.HasValue && Plugin.BiomeCreatures.TryGetValue(lastBossBiome.Value, out var value) && !string.IsNullOrEmpty(value.Value?.Trim())) { return value.Value; } return null; } } [HarmonyPatch(typeof(Game), "Start")] internal static class BossRpcRegisterPatch { private static void Postfix() { try { BossTracker.RegisterRpc(); } catch (Exception ex) { Plugin.Log.LogWarning((object)("Failed to register boss kill RPC: " + ex.Message)); } } } [HarmonyPatch(typeof(ZNetScene), "Awake")] internal static class BossKeyDetectPatch { private static void Postfix(ZNetScene __instance) { try { BossTracker.DetectDeepNorthBossKey(__instance.m_prefabs); } catch (Exception ex) { Plugin.Log.LogWarning((object)("Could not detect the Deep North boss: " + ex.Message)); } try { ForgeDiscovery.DetectUpgraderStations(__instance.m_prefabs); } catch (Exception ex2) { Plugin.Log.LogWarning((object)("Could not detect the Forge of Potential station: " + ex2.Message)); } } } [HarmonyPatch(typeof(Player), "OnSpawned")] internal static class ForgeScanReportPatch { private static void Postfix(Player __instance) { try { if ((Object)(object)__instance == (Object)(object)Player.m_localPlayer && Plugin.LogForgeScan.Value) { BossTrophy.ReportForgeScan(); } } catch (Exception ex) { Plugin.Log.LogWarning((object)("Could not scan Forge of Potential recipes: " + ex.Message)); } } } [HarmonyPatch(typeof(Character), "OnDeath")] internal static class BossDeathPatch { private static void Postfix(Character __instance) { try { if ((Object)(object)__instance != (Object)null && __instance.IsBoss()) { BossTracker.BroadcastBossKill(__instance); } } catch (Exception ex) { Plugin.Log.LogWarning((object)("Failed to announce boss kill: " + ex.Message)); } } } public static class BossTrophy { private const string IdolPrefix = "Upgrader"; private const int NoIdolTier = -1; private static readonly Biome[] Progression; private static readonly HashSet<ItemType> GearTypes; private static readonly HashSet<string> warned; private static string trophiesParsedFrom; private static Dictionary<string, Biome> trophyTable; private static string materialsParsedFrom; private static Dictionary<string, Biome> materialTable; private static readonly Dictionary<string, Biome?> tierCache; private static readonly HashSet<string> forgeItems; private static readonly HashSet<string> forgeMaterials; private static readonly Dictionary<string, int> forgeIdolTiers; private static int scannedRecipeCount; private static int reportedRecipeCount; public static bool IsGear(ItemData item) { //IL_0019: Unknown result type (might be due to invalid IL or missing references) if (item?.m_shared != null) { return GearTypes.Contains(item.m_shared.m_itemType); } return false; } private static Dictionary<string, Biome> ParseBiomeMap(string raw, string settingName) { //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_00d2: Unknown result type (might be due to invalid IL or missing references) Dictionary<string, Biome> dictionary = new Dictionary<string, Biome>(); if (string.IsNullOrEmpty(raw)) { return dictionary; } string[] array = raw.Split(new char[1] { ',' }); for (int i = 0; i < array.Length; i++) { string text = array[i].Trim(); if (text.Length == 0) { continue; } string[] array2 = text.Split(new char[1] { '=' }); if (array2.Length != 2 || !Enum.TryParse<Biome>(array2[1].Trim(), ignoreCase: true, out Biome result) || Array.IndexOf(Progression, result) < 0) { if (warned.Add(settingName + ":" + text)) { Plugin.Log.LogWarning((object)("Ignoring invalid '" + settingName + "' entry '" + text + "'; expected 'Prefab=Biome'.")); } } else { dictionary[array2[0].Trim()] = result; } } return dictionary; } private static Dictionary<string, Biome> GetTrophyTable() { string value = Plugin.BossTrophyTiers.Value; if (value != trophiesParsedFrom) { trophyTable = ParseBiomeMap(value, "Boss trophy tiers"); trophiesParsedFrom = value; } return trophyTable; } private static bool IsForgeRecipe(Recipe recipe) { if ((Object)(object)recipe == (Object)null || recipe.m_resources == null) { return false; } if ((Object)(object)recipe.m_craftingStation != (Object)null && recipe.m_craftingStation.m_upgrader) { return true; } Requirement[] resources = recipe.m_resources; foreach (Requirement val in resources) { if (val != null && val.m_upgraderResource) { return true; } } return false; } private static bool EnsureForgeScan() { List<Recipe> list = (((Object)(object)ObjectDB.instance != (Object)null) ? ObjectDB.instance.m_recipes : null); if (list == null || list.Count == 0) { return false; } if (list.Count == scannedRecipeCount) { return forgeItems.Count > 0; } scannedRecipeCount = list.Count; forgeItems.Clear(); forgeMaterials.Clear(); forgeIdolTiers.Clear(); tierCache.Clear(); materialsParsedFrom = null; foreach (Recipe item in list) { ItemData val = item?.m_item?.m_itemData; if (val?.m_shared == null || !IsForgeRecipe(item)) { continue; } RecordIdolTier(val.m_shared.m_name, item); if (!forgeItems.Add(val.m_shared.m_name)) { continue; } Recipe val2 = FindCraftRecipe(val); if ((Object)(object)val2 == (Object)null) { continue; } Requirement[] resources = val2.m_resources; foreach (Requirement val3 in resources) { if ((Object)(object)val3?.m_resItem != (Object)null && !val3.m_upgraderResource) { forgeMaterials.Add(Utils.GetPrefabName(((Component)val3.m_resItem).gameObject)); } } } return forgeItems.Count > 0; } private static void RecordIdolTier(string sharedName, Recipe forgeRecipe) { Requirement[] resources = forgeRecipe.m_resources; foreach (Requirement val in resources) { if (!((Object)(object)val?.m_resItem == (Object)null) && val.m_upgraderResource) { int num = IdolTier(Utils.GetPrefabName(((Component)val.m_resItem).gameObject)); if (num != -1 && (!forgeIdolTiers.TryGetValue(sharedName, out var value) || num > value)) { forgeIdolTiers[sharedName] = num; } } } } private static Dictionary<string, Biome> GetMaterialTable() { //IL_0066: Unknown result type (might be due to invalid IL or missing references) bool flag = EnsureForgeScan(); string value = Plugin.TierMaterials.Value; if (value != materialsParsedFrom) { Dictionary<string, Biome> dictionary = ParseBiomeMap(value, "Tier materials"); if (flag) { Dictionary<string, Biome> dictionary2 = new Dictionary<string, Biome>(); foreach (KeyValuePair<string, Biome> item in dictionary) { if (forgeMaterials.Contains(item.Key)) { dictionary2[item.Key] = item.Value; } } dictionary = dictionary2; } materialTable = dictionary; materialsParsedFrom = value; tierCache.Clear(); } return materialTable; } public unsafe static void ReportForgeScan() { if (!EnsureForgeScan()) { if ((Object)(object)ObjectDB.instance != (Object)null && ObjectDB.instance.m_recipes != null && ObjectDB.instance.m_recipes.Count > 0 && reportedRecipeCount != ObjectDB.instance.m_recipes.Count) { reportedRecipeCount = ObjectDB.instance.m_recipes.Count; Plugin.Log.LogWarning((object)"No Forge of Potential recipes found; 'Tier materials' is used unfiltered."); } } else { if (reportedRecipeCount == scannedRecipeCount) { return; } reportedRecipeCount = scannedRecipeCount; Dictionary<string, Biome> dictionary = ParseBiomeMap(Plugin.TierMaterials.Value, "Tier materials"); List<string> list = new List<string>(); foreach (string forgeItem in forgeItems) { list.Add((Localization.instance != null) ? Localization.instance.Localize(forgeItem) : forgeItem); } list.Sort(); List<string> list2 = new List<string>(); List<string> list3 = new List<string>(); foreach (string forgeMaterial in forgeMaterials) { if (dictionary.TryGetValue(forgeMaterial, out var value)) { list2.Add(forgeMaterial + "=" + ((object)(*(Biome*)(&value))/*cast due to .constrained prefix*/).ToString()); } else { list3.Add(forgeMaterial); } } list2.Sort(); list3.Sort(); List<string> list4 = new List<string>(); foreach (string key in dictionary.Keys) { if (!forgeMaterials.Contains(key)) { list4.Add(key); } } list4.Sort(); Plugin.Log.LogInfo((object)($"Forge of Potential can upgrade {list.Count} items: " + string.Join(", ", list.ToArray()))); Plugin.Log.LogInfo((object)("Tier materials used by forge items: " + string.Join(",", list2.ToArray()))); if (list4.Count > 0) { Plugin.Log.LogInfo((object)("Tier materials ignored (no forge item uses them): " + string.Join(", ", list4.ToArray()))); } if (list3.Count > 0) { Plugin.Log.LogInfo((object)("Forge item materials with no tier (count as Meadows): " + string.Join(", ", list3.ToArray()))); } } } public static bool IsBossTrophy(string prefabName) { if (prefabName != null) { return GetTrophyTable().ContainsKey(prefabName); } return false; } public static bool TryGetTrophyBiome(string prefabName, out Biome biome) { biome = (Biome)0; if (prefabName != null) { return GetTrophyTable().TryGetValue(prefabName, out biome); } return false; } public unsafe static string BiomeDisplayName(Biome biome) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0002: Invalid comparison between Unknown and I4 //IL_0004: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Invalid comparison between Unknown and I4 //IL_0009: Unknown result type (might be due to invalid IL or missing references) //IL_000c: Invalid comparison between Unknown and I4 if ((int)biome != 8) { if ((int)biome != 32) { if ((int)biome == 64) { return "Deep North"; } return ((object)(*(Biome*)(&biome))/*cast due to .constrained prefix*/).ToString(); } return "Ashlands"; } return "Black Forest"; } private static Recipe FindCraftRecipe(ItemData item) { if ((Object)(object)ObjectDB.instance == (Object)null || ObjectDB.instance.m_recipes == null) { return null; } string name = item.m_shared.m_name; Recipe val = null; foreach (Recipe recipe in ObjectDB.instance.m_recipes) { if ((Object)(object)recipe == (Object)null || (Object)(object)recipe.m_item == (Object)null || recipe.m_resources == null || recipe.m_item.m_itemData?.m_shared?.m_name != name || ((Object)(object)recipe.m_craftingStation != (Object)null && recipe.m_craftingStation.m_upgrader)) { continue; } bool flag = false; bool flag2 = false; Requirement[] resources = recipe.m_resources; foreach (Requirement val2 in resources) { if (val2 != null && !((Object)(object)val2.m_resItem == (Object)null)) { if (val2.m_upgraderResource) { flag = true; } else { flag2 = true; } } } if (!flag) { return recipe; } if (flag2 && (Object)(object)val == (Object)null) { val = recipe; } } return val; } public static Biome? GetItemTier(ItemData item) { //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_0088: Unknown result type (might be due to invalid IL or missing references) //IL_0090: Unknown result type (might be due to invalid IL or missing references) //IL_009c: Unknown result type (might be due to invalid IL or missing references) //IL_012e: Unknown result type (might be due to invalid IL or missing references) if (item?.m_shared == null || !GearTypes.Contains(item.m_shared.m_itemType)) { return null; } Dictionary<string, Biome> dictionary = GetMaterialTable(); string name = item.m_shared.m_name; if (EnsureForgeScan() && !forgeItems.Contains(name)) { return null; } if (tierCache.TryGetValue(name, out var value)) { return value; } if (forgeIdolTiers.TryGetValue(name, out var value2)) { Biome value3 = Progression[value2]; tierCache[name] = value3; return value3; } Recipe val = FindCraftRecipe(item); Biome? val2 = null; if ((Object)(object)val != (Object)null) { int num = 0; Requirement[] resources = val.m_resources; foreach (Requirement val3 in resources) { if (!((Object)(object)val3?.m_resItem == (Object)null)) { string prefabName = Utils.GetPrefabName(((Component)val3.m_resItem).gameObject); num = Math.Max(num, IdolTier(prefabName)); if (!val3.m_upgraderResource && dictionary.TryGetValue(prefabName, out var value4)) { num = Math.Max(num, Array.IndexOf(Progression, value4)); } } } val2 = Progression[num]; } if ((Object)(object)ObjectDB.instance != (Object)null && ObjectDB.instance.m_recipes != null && ObjectDB.instance.m_recipes.Count > 0) { tierCache[name] = val2; } return val2; } private static int IdolTier(string prefabName) { if (prefabName == null || !prefabName.StartsWith("Upgrader", StringComparison.Ordinal)) { return -1; } int length = "Upgrader".Length; int i; for (i = length; i < prefabName.Length && char.IsDigit(prefabName[i]); i++) { } if (i == length || !int.TryParse(prefabName.Substring(length, i - length), out var result)) { return -1; } if (result >= Progression.Length) { return -1; } return result; } public static ItemData FindMatchingTrophy(Inventory inventory, ItemData item) { //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0042: Unknown result type (might be due to invalid IL or missing references) if (inventory == null || item == null) { return null; } Biome? itemTier = GetItemTier(item); if (!itemTier.HasValue) { return null; } foreach (ItemData allItem in inventory.GetAllItems()) { if (TryGetTrophyBiome(TrophyBoost.GetPrefabName(allItem), out var biome) && biome == itemTier.Value) { return allItem; } } return null; } static BossTrophy() { Biome[] array = new Biome[8]; RuntimeHelpers.InitializeArray(array, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/); Progression = (Biome[])(object)array; GearTypes = new HashSet<ItemType> { (ItemType)3, (ItemType)14, (ItemType)22, (ItemType)4, (ItemType)5, (ItemType)6, (ItemType)7, (ItemType)11, (ItemType)17, (ItemType)19, (ItemType)15 }; warned = new HashSet<string>(); trophyTable = new Dictionary<string, Biome>(); materialTable = new Dictionary<string, Biome>(); tierCache = new Dictionary<string, Biome?>(); forgeItems = new HashSet<string>(); forgeMaterials = new HashSet<string>(); forgeIdolTiers = new Dictionary<string, int>(); scannedRecipeCount = -1; reportedRecipeCount = -1; } } public static class TrophyBoost { private static string parsedFrom; private static Dictionary<string, float> bonusTable = new Dictionary<string, float>(); private static readonly HashSet<string> warned = new HashSet<string>(); public static Dictionary<string, float> GetBonusTable() { string value = Plugin.TrophyBonuses.Value; if (value == parsedFrom) { return bonusTable; } Dictionary<string, float> dictionary = new Dictionary<string, float>(); string[] array = value.Split(new char[1] { ',' }); for (int i = 0; i < array.Length; i++) { string text = array[i].Trim(); if (text.Length == 0) { continue; } string[] array2 = text.Split(new char[1] { '=' }); if (array2.Length != 2 || !float.TryParse(array2[1].Trim(), NumberStyles.Float, CultureInfo.InvariantCulture, out var result) || result <= 0f) { if (warned.Add("bad:" + text)) { Plugin.Log.LogWarning((object)("Ignoring invalid trophy bonus entry '" + text + "'; expected 'TrophyPrefab=percent'.")); } } else { dictionary[array2[0].Trim()] = result; } } if ((Object)(object)ObjectDB.instance != (Object)null) { foreach (string key in dictionary.Keys) { if ((Object)(object)ObjectDB.instance.GetItemPrefab(key) == (Object)null && warned.Add("missing:" + key)) { Plugin.Log.LogWarning((object)("Trophy prefab '" + key + "' not found; it will have no effect.")); } } } bonusTable = dictionary; parsedFrom = value; return dictionary; } internal static string GetPrefabName(ItemData item) { if (item == null) { return null; } GameObject val = item.m_dropPrefab; if ((Object)(object)val == (Object)null && (Object)(object)ObjectDB.instance != (Object)null) { val = ObjectDB.instance.GetItemPrefab(item.m_shared); } if (!((Object)(object)val != (Object)null)) { return null; } return Utils.GetPrefabName(val); } public static float GetBestTrophy(Inventory inventory, out ItemData bestItem) { bestItem = null; float num = 0f; Dictionary<string, float> dictionary = GetBonusTable(); foreach (ItemData allItem in inventory.GetAllItems()) { string prefabName = GetPrefabName(allItem); if (prefabName != null && !BossTrophy.IsBossTrophy(prefabName) && dictionary.TryGetValue(prefabName, out var value) && value > num) { bestItem = allItem; num = value; } } return num; } public static float ApplyBoost(float roll) { try { if (!Plugin.TrophyBoostEnabled.Value) { return roll; } Player localPlayer = Player.m_localPlayer; Inventory val = ((localPlayer != null) ? ((Humanoid)localPlayer).GetInventory() : null); if (val == null) { return roll; } ItemData bestItem; float bestTrophy = GetBestTrophy(val, out bestItem); if (bestItem == null) { return roll; } string arg = Localization.instance.Localize(bestItem.m_shared.m_name); if (Plugin.TrophyConsumed.Value) { val.RemoveItem(bestItem, 1); } UpgradeOdds.QueueNotice($"{arg}: +{bestTrophy:0.#}% upgrade chance"); return Math.Max(0f, roll - bestTrophy / 100f); } catch (Exception ex) { Plugin.Log.LogWarning((object)("Trophy boost check failed: " + ex.Message)); return roll; } } } public static class ForgeDiscovery { private static readonly List<string> UpgraderStationNames = new List<string>(); private static bool warnedNoStation; private static bool warnedNoMethod; private static readonly MethodInfo KnowStationLevelMethod = AccessTools.Method(typeof(Player), "KnowStationLevel", new Type[2] { typeof(string), typeof(int) }, (Type[])null); public static void DetectUpgraderStations(IEnumerable<GameObject> prefabs) { if (prefabs == null) { return; } UpgraderStationNames.Clear(); foreach (GameObject prefab in prefabs) { CraftingStation val = (((Object)(object)prefab != (Object)null) ? prefab.GetComponent<CraftingStation>() : null); if ((Object)(object)val != (Object)null && val.m_upgrader && !string.IsNullOrEmpty(val.m_name) && !UpgraderStationNames.Contains(val.m_name)) { UpgraderStationNames.Add(val.m_name); } } } public static bool HasFoundForge() { Player localPlayer = Player.m_localPlayer; if ((Object)(object)localPlayer == (Object)null) { return false; } if (UpgraderStationNames.Count == 0) { if (!warnedNoStation) { warnedNoStation = true; Plugin.Log.LogWarning((object)"No Forge of Potential station found; trophy bonuses will always show in tooltips."); } return true; } if (KnowStationLevelMethod == null) { if (!warnedNoMethod) { warnedNoMethod = true; Plugin.Log.LogWarning((object)"Player.KnowStationLevel not found; trophy bonuses will always show in tooltips."); } return true; } bool flag = default(bool); foreach (string upgraderStationName in UpgraderStationNames) { object obj = KnowStationLevelMethod.Invoke(localPlayer, new object[2] { upgraderStationName, 1 }); int num; if (obj is bool) { flag = (bool)obj; num = 1; } else { num = 0; } if (((uint)num & (flag ? 1u : 0u)) != 0) { return true; } } return false; } } [HarmonyPatch] internal static class TrophyTooltipPatch { private static int appendingIndex = -1; private static MethodBase TargetMethod() { foreach (MethodInfo declaredMethod in AccessTools.GetDeclaredMethods(typeof(ItemData))) { if (!(declaredMethod.Name != "GetTooltip") && declaredMethod.IsStatic && !(declaredMethod.ReturnType != typeof(string))) { ParameterInfo[] parameters = declaredMethod.GetParameters(); if (parameters.Length != 0 && parameters[0].ParameterType == typeof(ItemData)) { return declaredMethod; } } } return null; } private static bool Prepare() { MethodBase methodBase = TargetMethod(); if (methodBase == null) { Plugin.Log.LogWarning((object)"ItemData.GetTooltip not found; trophy tooltips will not show their upgrade bonus."); return false; } ParameterInfo[] parameters = methodBase.GetParameters(); foreach (ParameterInfo parameterInfo in parameters) { if (parameterInfo.Name == "appending" && parameterInfo.ParameterType == typeof(bool)) { appendingIndex = parameterInfo.Position; } } return true; } private static void Postfix(object[] __args, ref string __result) { //IL_0079: Unknown result type (might be due to invalid IL or missing references) try { if (!Plugin.TrophyBoostEnabled.Value || __args == null || __args.Length == 0) { return; } bool flag = default(bool); int num; if (appendingIndex >= 0 && appendingIndex < __args.Length) { object obj = __args[appendingIndex]; if (obj is bool) { flag = (bool)obj; num = 1; } else { num = 0; } } else { num = 0; } if (((uint)num & (flag ? 1u : 0u)) != 0) { return; } object obj2 = __args[0]; string prefabName = TrophyBoost.GetPrefabName((ItemData)((obj2 is ItemData) ? obj2 : null)); if (prefabName == null) { return; } string text; if (BossTrophy.TryGetTrophyBiome(prefabName, out var biome)) { text = "Forge Success: 100% on " + BossTrophy.BiomeDisplayName(biome) + " gear"; } else { if (!TrophyBoost.GetBonusTable().TryGetValue(prefabName, out var value)) { return; } text = $"Forge Success added: {value:0.#}%"; } if (ForgeDiscovery.HasFoundForge()) { string text2 = (Plugin.TrophyConsumed.Value ? " <size=80%>(used up per attempt)</size>" : ""); __result = __result + "\n\n<color=yellow>" + text + "</color>" + text2; } } catch (Exception ex) { Plugin.Log.LogWarning((object)("Could not add trophy bonus to tooltip: " + ex.Message)); } } } public static class UpgradeOdds { private const float Percent = 100f; private const float RateTextRefreshSeconds = 0.25f; private const float GuaranteedRoll = -0.5f; private const float HighestRoll = 1.5f; private const int TrophiesUsedPerUpgrade = 1; private const string StreakKey = "FoP_UpgradeStreak"; private static readonly FieldInfo UpgradeItemField = AccessTools.Field(typeof(InventoryGui), "m_craftUpgradeItem"); private static readonly FieldInfo SelectedRecipeField = AccessTools.Field(typeof(InventoryGui), "m_selectedRecipe"); private static bool warnedNoRecipe; private static string cachedRateText = ""; private static ItemData cachedItem; private static Recipe cachedRecipe; private static float cachedAt = -1f; private static readonly List<string> PendingNotices = new List<string>(); private static int GetStreak(ItemData item) { if (item?.m_customData != null && item.m_customData.TryGetValue("FoP_UpgradeStreak", out var value) && int.TryParse(value, out var result)) { return Math.Max(0, result); } return 0; } private static float GetPenaltyPercent(ItemData item, out int streak) { streak = 0; if (!Plugin.PenaltyEnabled.Value) { return 0f; } streak = GetStreak(item); return Math.Min((float)streak * Plugin.PenaltyPerSuccess.Value, Plugin.PenaltyMax.Value); } private static bool TryGetBaseChance(Recipe recipe, out float chance) { chance = 0f; if (recipe?.m_resources == null) { return false; } Requirement[] resources = recipe.m_resources; foreach (Requirement val in resources) { if (val != null && val.m_upgraderResource) { SharedData val2 = val.m_resItem?.m_itemData?.m_shared; if (val2 == null) { return false; } chance = val2.m_upgradeChance; return true; } } return false; } private static object GetSelectedMember(InventoryGui gui, string memberName) { object obj = SelectedRecipeField?.GetValue(gui); if (obj == null) { return null; } Type type = obj.GetType(); object obj2 = AccessTools.Property(type, memberName)?.GetValue(obj, null); if (obj2 == null) { FieldInfo fieldInfo = AccessTools.Field(type, memberName); if ((object)fieldInfo == null) { return null; } obj2 = fieldInfo.GetValue(obj); } return obj2; } internal static Recipe GetSelectedRecipe(InventoryGui gui) { object selectedMember = GetSelectedMember(gui, "Recipe"); return (Recipe)((selectedMember is Recipe) ? selectedMember : null); } internal static ItemData GetSelectedItem(InventoryGui gui) { object selectedMember = GetSelectedMember(gui, "ItemData"); return (ItemData)((selectedMember is ItemData) ? selectedMember : null); } internal static bool IsForgeRecipe(Recipe recipe) { float chance; return TryGetBaseChance(recipe, out chance); } private static float ComputeRate(Recipe recipe, ItemData item, out float basePercent, out float penalty, out int streak, out float trophy, out string bossTrophyName) { basePercent = 0f; penalty = 0f; streak = 0; trophy = 0f; bossTrophyName = null; if (!TryGetBaseChance(recipe, out var chance)) { return -1f; } basePercent = chance * 100f; if (Plugin.TrophyBoostEnabled.Value) { Player localPlayer = Player.m_localPlayer; ItemData val = BossTrophy.FindMatchingTrophy((localPlayer != null) ? ((Humanoid)localPlayer).GetInventory() : null, item); if (val != null) { bossTrophyName = Localization.instance.Localize(val.m_shared.m_name); return 100f; } } penalty = GetPenaltyPercent(item, out streak); if (Plugin.TrophyBoostEnabled.Value) { Player localPlayer2 = Player.m_localPlayer; Inventory val2 = ((localPlayer2 != null) ? ((Humanoid)localPlayer2).GetInventory() : null); if (val2 != null) { trophy = TrophyBoost.GetBestTrophy(val2, out var _); } } return Math.Max(0f, Math.Min(100f, basePercent - penalty + trophy)); } private static string BuildRateText(InventoryGui gui, ItemData item) { Recipe selectedRecipe = GetSelectedRecipe(gui); if (item == cachedItem && (Object)(object)selectedRecipe == (Object)(object)cachedRecipe && Time.unscaledTime - cachedAt < 0.25f) { return cachedRateText; } cachedItem = item; cachedRecipe = selectedRecipe; cachedAt = Time.unscaledTime; cachedRateText = ""; if ((Object)(object)selectedRecipe == (Object)null && !warnedNoRecipe) { warnedNoRecipe = true; Plugin.Log.LogWarning((object)"Could not read the selected recipe; the success rate will not be shown."); } float basePercent; float penalty; int streak; float trophy; string bossTrophyName; float num = ComputeRate(selectedRecipe, item, out basePercent, out penalty, out streak, out trophy, out bossTrophyName); if (num < 0f) { return cachedRateText; } if (Plugin.LevelCapEnabled.Value && item != null) { int cap = LevelCap.GetCap(item); if (item.m_quality >= cap) { cachedRateText = "\n<size=100%><color=red>" + LevelCap.BlockedMessage(cap) + "</color></size>"; return cachedRateText; } } string text = string.Format("\n<size={0}><color=yellow>Success rate: {1:0.#}%</color></size>", "100%", num); if (bossTrophyName != null) { text = text + " <size=80%>(" + bossTrophyName + ")</size>"; } else if (penalty > 0f || trophy > 0f) { string text2 = $"base {basePercent:0.#}%"; if (penalty > 0f) { text2 += $", {streak} in a row -{penalty:0.#}%"; } if (trophy > 0f) { text2 += $", trophy +{trophy:0.#}%"; } text = text + " <size=80%>(" + text2 + ")</size>"; } if (Plugin.LevelCapEnabled.Value && item != null) { text += $"\n<size=80%>Level cap: {LevelCap.GetCap(item)}</size>"; } cachedRateText = text; return cachedRateText; } public static string AppendRate(string warningText, InventoryGui gui, ItemData item) { try { return warningText + BuildRateText(gui, item); } catch (Exception ex) { Plugin.Log.LogWarning((object)("Could not build the success rate text: " + ex.Message)); return warningText; } } public static void QueueNotice(string notice) { PendingNotices.Add(notice); } public static string AppendNotices(string message) { try { if (PendingNotices.Count == 0) { return message; } string result = message + "\n" + string.Join("\n", PendingNotices.ToArray()); PendingNotices.Clear(); return result; } catch (Exception ex) { Plugin.Log.LogWarning((object)("Could not append upgrade notices: " + ex.Message)); PendingNotices.Clear(); return message; } } public static float AdjustRoll(InventoryGui gui, float roll) { try { float num = roll; PendingNotices.Clear(); object? obj = UpgradeItemField?.GetValue(gui); ItemData item = (ItemData)((obj is ItemData) ? obj : null); if (Plugin.TrophyBoostEnabled.Value) { Player localPlayer = Player.m_localPlayer; Inventory val = ((localPlayer != null) ? ((Humanoid)localPlayer).GetInventory() : null); ItemData val2 = BossTrophy.FindMatchingTrophy(val, item); if (val2 != null) { string text = Localization.instance.Localize(val2.m_shared.m_name); if (Plugin.TrophyConsumed.Value) { val.RemoveItem(val2, 1); } QueueNotice(text + ": guaranteed upgrade"); return -0.5f; } } if (Plugin.PenaltyEnabled.Value) { int streak; float penaltyPercent = GetPenaltyPercent(item, out streak); if (penaltyPercent > 0f) { num += penaltyPercent / 100f; QueueNotice($"{streak} successful upgrades in a row: -{penaltyPercent:0.#}% success chance"); } } num = TrophyBoost.ApplyBoost(num); return Math.Min(num, 1.5f); } catch (Exception ex) { Plugin.Log.LogWarning((object)("Upgrade odds adjustment failed: " + ex.Message)); return roll; } } public static void OnUpgradeSucceeded(InventoryGui gui, ItemData newItem) { try { if (Plugin.PenaltyEnabled.Value && newItem != null && newItem.m_customData != null) { object? obj = UpgradeItemField?.GetValue(gui); ItemData item = (ItemData)((obj is ItemData) ? obj : null); newItem.m_customData["FoP_UpgradeStreak"] = (GetStreak(item) + 1).ToString(); } } catch (Exception ex) { Plugin.Log.LogWarning((object)("Could not record upgrade streak: " + ex.Message)); } } public static void OnUpgradeFailed(InventoryGui gui) { try { object? obj = UpgradeItemField?.GetValue(gui); ItemData val = (ItemData)((obj is ItemData) ? obj : null); if (val?.m_customData != null && val.m_customData.Remove("FoP_UpgradeStreak")) { cachedAt = -1f; } } catch (Exception ex) { Plugin.Log.LogWarning((object)("Could not reset upgrade streak: " + ex.Message)); } } } public static class LevelCap { public static int GetExtraLevels() { return Plugin.LevelCapBase.Value + Plugin.LevelCapPerBoss.Value * BossTracker.CountDefeatedBosses(); } public static int GetCap(ItemData item) { return ((item?.m_shared == null) ? 1 : Math.Max(1, item.m_shared.m_maxQuality)) + GetExtraLevels(); } public static bool IsBlocked(Recipe recipe, ItemData item, out int cap) { cap = 0; if (!Plugin.LevelCapEnabled.Value || item == null || !UpgradeOdds.IsForgeRecipe(recipe)) { return false; } cap = GetCap(item); return item.m_quality >= cap; } public static string BlockedMessage(int cap) { string arg = ((Plugin.LevelCapPerBoss.Value > 0) ? $" Defeat a boss to raise it by {Plugin.LevelCapPerBoss.Value}." : ""); return $"Level cap reached ({cap}).{arg}"; } public static void Notify(int cap) { Player localPlayer = Player.m_localPlayer; if (localPlayer != null) { ((Character)localPlayer).Message((MessageType)2, BlockedMessage(cap), 0, (Sprite)null, false); } } } public static class GearFilter { public const string BlockedMessage = "The Forge of Potential only upgrades weapons, armor and tools."; public static bool AtForge() { CraftingStation val = (((Object)(object)Player.m_localPlayer != (Object)null) ? Player.m_localPlayer.GetCurrentCraftingStation() : null); if ((Object)(object)val != (Object)null) { return val.m_upgrader; } return false; } public static bool IsBlocked(Recipe recipe, ItemData item) { if (!Plugin.GearOnly.Value || (Object)(object)recipe == (Object)null || !UpgradeOdds.IsForgeRecipe(recipe) || !AtForge()) { return false; } return !BossTrophy.IsGear(item ?? recipe.m_item?.m_itemData); } } [HarmonyPatch(typeof(InventoryGui), "UpdateRecipeList")] internal static class ForgeGearListPatch { private static void Prefix(List<Recipe> recipes) { try { if (Plugin.GearOnly.Value && recipes != null && GearFilter.AtForge()) { recipes.RemoveAll((Recipe recipe) => (Object)(object)recipe != (Object)null && !BossTrophy.IsGear(recipe.m_item?.m_itemData)); } } catch (Exception ex) { Plugin.Log.LogWarning((object)("Could not filter the Forge of Potential list: " + ex.Message)); } } } [HarmonyPatch(typeof(InventoryGui), "OnCraftPressed")] internal static class CraftPressedCapPatch { private static bool Prefix(InventoryGui __instance) { try { Recipe selectedRecipe = UpgradeOdds.GetSelectedRecipe(__instance); ItemData selectedItem = UpgradeOdds.GetSelectedItem(__instance); if (LevelCap.IsBlocked(selectedRecipe, selectedItem, out var cap)) { LevelCap.Notify(cap); return false; } } catch (Exception ex) { Plugin.Log.LogWarning((object)("Level cap check failed: " + ex.Message)); } return true; } } [HarmonyPatch(typeof(InventoryGui), "UpdateRecipe")] internal static class UpdateRecipePatch { private static readonly MethodInfo AppendRateMethod = AccessTools.Method(typeof(UpgradeOdds), "AppendRate", (Type[])null, (Type[])null); private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> originalInstructions) { //IL_012b: Unknown result type (might be due to invalid IL or missing references) //IL_0131: Expected O, but got Unknown //IL_0146: Unknown result type (might be due to invalid IL or missing references) //IL_014c: Expected O, but got Unknown List<CodeInstruction> list = new List<CodeInstruction>(originalInstructions); int num = list.FindIndex((CodeInstruction instruction) => instruction.opcode == OpCodes.Ldstr && instruction.operand is string text && text == "$inventory_upgraderwarning"); int num2 = -1; for (int num3 = 0; num3 < list.Count - 1; num3++) { if ((list[num3].operand is MethodBase { Name: "get_ItemData" } || list[num3].operand is FieldInfo { Name: "ItemData" }) && CodeInstructionExtensions.IsStloc(list[num3 + 1], (LocalBuilder)null)) { num2 = list[num3 + 1].LocalIndex(); break; } } if (num < 0 || num + 1 >= list.Count || !(list[num + 1].operand is MethodBase methodBase2) || methodBase2.Name != "Localize" || num2 < 0) { Plugin.Log.LogWarning((object)"Could not find the upgrader warning in UpdateRecipe; the success rate will not be shown."); return list; } list.InsertRange(num + 2, (IEnumerable<CodeInstruction>)(object)new CodeInstruction[3] { new CodeInstruction(OpCodes.Ldarg_0, (object)null), IlHelpers.LoadLocal(num2), new CodeInstruction(OpCodes.Call, (object)AppendRateMethod) }); return list; } } public static class FailSpawner { private const int GroundHeightMargin = 3; private const float LowestGroundBelowPlayer = 3f; private const float HighestGroundAbovePlayer = 1.5f; private const float SpawnLift = 0.5f; private static readonly Random random = new Random(); private static readonly HashSet<string> warnedPrefabs = new HashSet<string>(); private static void WarnOnce(string key, string message) { if (warnedPrefabs.Add(key)) { Plugin.Log.LogWarning((object)message); } } private static HashSet<string> GetExcludedNames() { HashSet<string> hashSet = new HashSet<string>(StringComparer.OrdinalIgnoreCase); string text = Plugin.ExcludedCreatures?.Value; if (string.IsNullOrEmpty(text)) { return hashSet; } string[] array = text.Split(new char[1] { ',' }); for (int i = 0; i < array.Length; i++) { string text2 = array[i].Trim(); if (text2.Length > 0) { hashSet.Add(text2); } } return hashSet; } private static List<GameObject> ResolvePrefabs(string nameList, HashSet<string> excluded) { List<GameObject> list = new List<GameObject>(); if (string.IsNullOrEmpty(nameList)) { return list; } string[] array = nameList.Split(new char[1] { ',' }); for (int i = 0; i < array.Length; i++) { string text = array[i].Trim(); if (text.Length != 0 && !excluded.Contains(text)) { GameObject prefab = ZNetScene.instance.GetPrefab(text); if ((Object)(object)prefab == (Object)null) { WarnOnce("missing:" + text, "Creature '" + text + "' not found; skipping it."); } else if ((Object)(object)prefab.GetComponent<Character>() == (Object)null) { WarnOnce("notcreature:" + text, "'" + text + "' is not a creature; skipping it."); } else { list.Add(prefab); } } } return list; } public static void SpawnPunishmentEnemies() { //IL_00f1: Unknown result type (might be due to invalid IL or missing references) //IL_010f: 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_0119: Unknown result type (might be due to invalid IL or missing references) //IL_0121: Unknown result type (might be due to invalid IL or missing references) //IL_013f: Unknown result type (might be due to invalid IL or missing references) //IL_0183: Unknown result type (might be due to invalid IL or missing references) //IL_0185: Unknown result type (might be due to invalid IL or missing references) try { if (!Plugin.SpawnEnemyOnFail.Value) { return; } Player localPlayer = Player.m_localPlayer; if ((Object)(object)localPlayer == (Object)null || (Object)(object)ZNetScene.instance == (Object)null) { return; } HashSet<string> excludedNames = GetExcludedNames(); List<GameObject> list = null; string bossBiomePrefabList = BossTracker.GetBossBiomePrefabList(); if (bossBiomePrefabList != null) { list = ResolvePrefabs(bossBiomePrefabList, excludedNames); if (list.Count == 0) { WarnOnce("emptybiome:" + bossBiomePrefabList, "No spawnable creatures left in the last boss biome list after exclusions; using 'Enemy prefabs' instead."); } } if (list == null || list.Count == 0) { list = ResolvePrefabs(Plugin.EnemyPrefabNames.Value, excludedNames); } if (list.Count == 0) { Plugin.Log.LogWarning((object)"No valid enemy prefabs configured; nothing spawned."); return; } float num2 = default(float); for (int i = 0; i < Plugin.EnemyCount.Value; i++) { GameObject obj = list[random.Next(list.Count)]; float num = (float)(random.NextDouble() * Math.PI * 2.0); float value = Plugin.SpawnDistance.Value; Vector3 val = ((Component)localPlayer).transform.position + new Vector3(Mathf.Cos(num) * value, 0f, Mathf.Sin(num) * value); float y = ((Component)localPlayer).transform.position.y; if ((Object)(object)ZoneSystem.instance != (Object)null && ZoneSystem.instance.GetSolidHeight(val, ref num2, 3) && num2 >= y - 3f && num2 <= y + 1.5f) { val.y = num2 + 0.5f; } else { val.y = y + 0.5f; } Character component = Object.Instantiate<GameObject>(obj, val, Quaternion.identity).GetComponent<Character>(); if ((Object)(object)component != (Object)null) { component.SetLevel(Plugin.EnemyStars.Value + 1); } } } catch (Exception ex) { Plugin.Log.LogWarning((object)("Failed to spawn punishment enemy: " + ex.Message)); } } } public static class LocalizationTweaks { internal const string TextSize = "100%"; private static readonly Dictionary<string, string> Translations = new Dictionary<string, string> { { "inventory_upgraderwarning", "<size=100%>Warning - Item could lose upgrades.</size>" }, { "msg_upgrader_failed", "<size=100%>$1 level was reduced!</size>" } }; private static readonly MethodInfo AddWordMethod = AccessTools.Method(typeof(Localization), "AddWord", new Type[2] { typeof(string), typeof(string) }, (Type[])null); private static readonly FieldInfo CacheField = AccessTools.Field(typeof(Localization), "m_cache"); private static bool hasWarnedAboutMissingMethod; public static void Apply(Localization localization) { if (localization == null) { return; } if (AddWordMethod == null) { if (!hasWarnedAboutMissingMethod) { hasWarnedAboutMissingMethod = true; Plugin.Log.LogWarning((object)"Localization.AddWord(string, string) not found; the crafting panel text was not changed."); } return; } try { foreach (KeyValuePair<string, string> translation in Translations) { AddWordMethod.Invoke(localization, new object[2] { translation.Key, translation.Value }); } object obj = CacheField?.GetValue(localization); if (obj != null) { AccessTools.Method(obj.GetType(), "EvictAll", (Type[])null, (Type[])null)?.Invoke(obj, null); } } catch (Exception ex) { Plugin.Log.LogWarning((object)("Could not add custom translations: " + ex.Message)); } } } [HarmonyPatch] internal static class SetupLanguagePatch { private static MethodBase TargetMethod() { return AccessTools.Method(typeof(Localization), "SetupLanguage", (Type[])null, (Type[])null); } private static bool Prepare() { return TargetMethod() != null; } private static void Postfix(Localization __instance) { LocalizationTweaks.Apply(__instance); } } [HarmonyPatch(typeof(InventoryGui), "DoCrafting")] internal static class DoCraftingPatch { private static readonly FieldInfo CraftRecipeField = AccessTools.Field(typeof(InventoryGui), "m_craftRecipe"); private static readonly MethodInfo LevelAfterFailureMethod = AccessTools.Method(typeof(DoCraftingPatch), "GetLevelAfterFailure", (Type[])null, (Type[])null); private static readonly MethodInfo SpawnEnemiesMethod = AccessTools.Method(typeof(FailSpawner), "SpawnPunishmentEnemies", (Type[])null, (Type[])null); private static readonly FieldInfo CraftUpgradeItemField = AccessTools.Field(typeof(InventoryGui), "m_craftUpgradeItem"); private static readonly MethodInfo BoostMethod = AccessTools.Method(typeof(UpgradeOdds), "AdjustRoll", (Type[])null, (Type[])null); private static readonly MethodInfo SuccessMethod = AccessTools.Method(typeof(UpgradeOdds), "OnUpgradeSucceeded", (Type[])null, (Type[])null); private static readonly MethodInfo FailureMethod = AccessTools.Method(typeof(UpgradeOdds), "OnUpgradeFailed", (Type[])null, (Type[])null); private static readonly MethodInfo AppendNoticesMethod = AccessTools.Method(typeof(UpgradeOdds), "AppendNotices", (Type[])null, (Type[])null); public static int GetLevelAfterFailure(int attemptedLevel) { if (Plugin.ResetToLevelOne.Value) { return 1; } int num = attemptedLevel - 1; return Math.Max(1, num - Plugin.LevelsLostOnFail.Value); } private static bool Prefix(InventoryGui __instance) { object? obj = CraftRecipeField?.GetValue(__instance); Recipe val = (Recipe)((obj is Recipe) ? obj : null); if ((Object)(object)val == (Object)null || val.m_resources == null) { return true; } try { object? obj2 = CraftUpgradeItemField?.GetValue(__instance); ItemData item = (ItemData)((obj2 is ItemData) ? obj2 : null); if (GearFilter.IsBlocked(val, item)) { Player localPlayer = Player.m_localPlayer; if (localPlayer != null) { ((Character)localPlayer).Message((MessageType)2, "The Forge of Potential only upgrades weapons, armor and tools.", 0, (Sprite)null, false); } return false; } if (LevelCap.IsBlocked(val, item, out var cap)) { LevelCap.Notify(cap); return false; } } catch (Exception ex) { Plugin.Log.LogWarning((object)("Level cap check failed: " + ex.Message)); } ApplyNoBreak(val); return true; } private static void ApplyNoBreak(Recipe recipe) { Requirement[] resources = recipe.m_resources; foreach (Requirement val in resources) { if (val != null && val.m_upgraderResource) { ItemDrop resItem = val.m_resItem; if (!((Object)(object)resItem == (Object)null) && resItem.m_itemData != null && resItem.m_itemData.m_shared != null) { resItem.m_itemData.m_shared.m_breakChance = -1f; } } } } private static bool IsUpgradeRoll(MethodBase method) { if (method == null) { return false; } if (method.Name == "GetItemUpgradeChance" && method.DeclaringType == typeof(Player)) { return true; } if (method.Name != "Range" || method.DeclaringType != typeof(Random)) { return false; } ParameterInfo[] parameters = method.GetParameters(); if (parameters.Length == 2) { return parameters[0].ParameterType == typeof(float); } return false; } private static bool InsertBoostHook(List<CodeInstruction> instructions) { //IL_0053: Unknown result type (might be due to invalid IL or missing references) //IL_0059: Expected O, but got Unknown //IL_00a8: Unknown result type (might be due to invalid IL or missing references) //IL_00ae: Expected O, but got Unknown for (int i = 0; i < instructions.Count - 2; i++) { if (instructions[i].operand is MethodBase method && IsUpgradeRoll(method) && CodeInstructionExtensions.IsStloc(instructions[i + 1], (LocalBuilder)null)) { int index = instructions[i + 1].LocalIndex(); CodeInstruction val = new CodeInstruction(OpCodes.Ldarg_0, (object)null); val.labels.AddRange(instructions[i + 2].labels); instructions[i + 2].labels.Clear(); instructions.InsertRange(i + 2, (IEnumerable<CodeInstruction>)(object)new CodeInstruction[4] { val, IlHelpers.LoadLocal(index), new CodeInstruction(OpCodes.Call, (object)BoostMethod), IlHelpers.StoreLocal(index) }); return true; } } return false; } private static bool InsertSuccessHook(List<CodeInstruction> instructions) { //IL_008c: Unknown result type (might be due to invalid IL or missing references) //IL_0092: Expected O, but got Unknown //IL_00a7: Unknown result type (might be due to invalid IL or missing references) //IL_00ad: Expected O, but got Unknown int num = instructions.FindIndex((CodeInstruction instruction) => instruction.opcode == OpCodes.Ldstr && instruction.operand is string text && text.Contains("succeeded")); if (num < 0) { return false; } for (int num2 = num; num2 < instructions.Count - 1; num2++) { if (instructions[num2].operand is MethodBase { Name: "AddItem" } && CodeInstructionExtensions.IsStloc(instructions[num2 + 1], (LocalBuilder)null)) { int index = instructions[num2 + 1].LocalIndex(); instructions.InsertRange(num2 + 2, (IEnumerable<CodeInstruction>)(object)new CodeInstruction[3] { new CodeInstruction(OpCodes.Ldarg_0, (object)null), IlHelpers.LoadLocal(index), new CodeInstruction(OpCodes.Call, (object)SuccessMethod) }); return true; } } return false; } private static int InsertNoticeHooks(List<CodeInstruction> instructions) { //IL_0091: Unknown result type (might be due to invalid IL or missing references) //IL_009b: Expected O, but got Unknown int num = 0; for (int i = 0; i < instructions.Count; i++) { if (instructions[i].opcode != OpCodes.Ldstr || !(instructions[i].operand is string text) || (text != "$msg_upgrader_success" && text != "$msg_upgrader_failed")) { continue; } for (int j = i + 1; j < instructions.Count; j++) { if (instructions[j].operand is MethodBase { Name: "Localize" }) { instructions.Insert(j + 1, new CodeInstruction(OpCodes.Call, (object)AppendNoticesMethod)); num++; i = j + 1; break; } } } return num; } private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> originalInstructions) { //IL_0123: Unknown result type (might be due to invalid IL or missing references) //IL_0129: Expected O, but got Unknown //IL_0169: Unknown result type (might be due to invalid IL or missing references) //IL_016f: Expected O, but got Unknown //IL_017b: Unknown result type (might be due to invalid IL or missing references) //IL_0181: Expected O, but got Unknown List<CodeInstruction> list = new List<CodeInstruction>(originalInstructions); int num = list.FindIndex((CodeInstruction instruction) => instruction.opcode == OpCodes.Ldstr && instruction.operand is string text && text.Contains("FAILED")); if (num < 0) { Plugin.Log.LogError((object)"Game build differs from the one the mod was written for; transpiler skipped."); return list; } int num2 = 0; for (int num3 = num; num3 < list.Count - 2 && !(list[num3].operand is MethodBase { Name: "AddItem" }); num3++) { if (CodeInstructionExtensions.IsLdloc(list[num3], (LocalBuilder)null) && list[num3 + 1].opcode == OpCodes.Ldc_I4_2 && list[num3 + 2].opcode == OpCodes.Sub) { list[num3 + 1].opcode = OpCodes.Call; list[num3 + 1].operand = LevelAfterFailureMethod; list.RemoveAt(num3 + 2); num2++; } } if (num2 == 0) { Plugin.Log.LogWarning((object)"Could not find the level loss in DoCrafting; failed upgrades will use the vanilla level loss."); } CodeInstruction val = new CodeInstruction(OpCodes.Ldarg_0, (object)null); val.labels.AddRange(list[num].labels); list[num].labels.Clear(); list.InsertRange(num, (IEnumerable<CodeInstruction>)(object)new CodeInstruction[3] { val, new CodeInstruction(OpCodes.Call, (object)FailureMethod), new CodeInstruction(OpCodes.Call, (object)SpawnEnemiesMethod) }); if (!InsertBoostHook(list)) { Plugin.Log.LogWarning((object)"Could not find the upgrade roll in DoCrafting; trophy boosts and the success penalty will not apply."); } if (!InsertSuccessHook(list)) { Plugin.Log.LogWarning((object)"Could not find the upgrade success in DoCrafting; success streaks will not be recorded."); } if (InsertNoticeHooks(list) == 0) { Plugin.Log.LogWarning((object)"Could not find the upgrade messages in DoCrafting; trophy and streak notices will not be shown."); } return list; } } }