using System; using System.Collections.Generic; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using Microsoft.CodeAnalysis; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("ScoutGemPetrifyConfig")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyDescription("Configurable scout gem petrify penalties for PEAK")] [assembly: AssemblyFileVersion("1.1.0.0")] [assembly: AssemblyInformationalVersion("1.1.0")] [assembly: AssemblyProduct("ScoutGemPetrifyConfig")] [assembly: AssemblyTitle("ScoutGemPetrifyConfig")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.1.0.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace PeakNoPetrifyMod { [BepInPlugin("com.modder.peak.scoutgempetrifyconfig", "ScoutGemPetrifyConfig", "1.1.0")] [BepInProcess("PEAK.exe")] public class NoPetrifyGemsPlugin : BaseUnityPlugin { public const string PLUGIN_GUID = "com.modder.peak.scoutgempetrifyconfig"; public const string PLUGIN_NAME = "ScoutGemPetrifyConfig"; public const string PLUGIN_VERSION = "1.1.0"; internal static ManualLogSource LogSource; private Harmony _harmony; public static ConfigEntry ModEnabled; public static ConfigEntry UseCustomFlatValues; public static ConfigEntry GlobalPetrifyMultiplier; public static ConfigEntry AmbitionPetrifyCost; public static ConfigEntry GenerosityPetrifyCost; public static ConfigEntry TenacityPetrifyCost; public static ConfigEntry InitiativePetrifyCost; public static ConfigEntry StrangeGemPetrifyCost; public static ConfigEntry GenericGemPetrifyCost; private void Awake() { //IL_0079: Unknown result type (might be due to invalid IL or missing references) //IL_0083: Expected O, but got Unknown //IL_00b6: Unknown result type (might be due to invalid IL or missing references) //IL_00c0: 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_0130: Unknown result type (might be due to invalid IL or missing references) //IL_013a: Expected O, but got Unknown //IL_016d: Unknown result type (might be due to invalid IL or missing references) //IL_0177: Expected O, but got Unknown //IL_01aa: Unknown result type (might be due to invalid IL or missing references) //IL_01b4: Expected O, but got Unknown //IL_01e7: Unknown result type (might be due to invalid IL or missing references) //IL_01f1: Expected O, but got Unknown //IL_020b: Unknown result type (might be due to invalid IL or missing references) //IL_0215: Expected O, but got Unknown LogSource = ((BaseUnityPlugin)this).Logger; ModEnabled = ((BaseUnityPlugin)this).Config.Bind("1. General", "ModEnabled", true, "Enable or disable custom Scout Gem petrify configuration."); UseCustomFlatValues = ((BaseUnityPlugin)this).Config.Bind("1. General", "UseCustomFlatValues", true, "If true, uses the exact flat petrify values configured below. If false, applies the Global Multiplier to default values."); GlobalPetrifyMultiplier = ((BaseUnityPlugin)this).Config.Bind("1. General", "GlobalPetrifyMultiplier", 0f, new ConfigDescription("Global multiplier applied to gem petrify penalty when 'UseCustomFlatValues' is false (0.0 = 0% penalty, 1.0 = 100% normal penalty).", (AcceptableValueBase)(object)new AcceptableValueRange(0f, 2f), Array.Empty())); AmbitionPetrifyCost = ((BaseUnityPlugin)this).Config.Bind("2. Gem Petrify Values", "ScoutsAmbitionPetrify", 0f, new ConfigDescription("Petrify penalty inflicted when using Scout's Ambition.", (AcceptableValueBase)(object)new AcceptableValueRange(0f, 100f), Array.Empty())); GenerosityPetrifyCost = ((BaseUnityPlugin)this).Config.Bind("2. Gem Petrify Values", "ScoutsGenerosityPetrify", 0f, new ConfigDescription("Petrify penalty inflicted when using Scout's Generosity.", (AcceptableValueBase)(object)new AcceptableValueRange(0f, 100f), Array.Empty())); TenacityPetrifyCost = ((BaseUnityPlugin)this).Config.Bind("2. Gem Petrify Values", "ScoutsTenacityPetrify", 0f, new ConfigDescription("Petrify penalty inflicted when using Scout's Tenacity.", (AcceptableValueBase)(object)new AcceptableValueRange(0f, 100f), Array.Empty())); InitiativePetrifyCost = ((BaseUnityPlugin)this).Config.Bind("2. Gem Petrify Values", "ScoutsInitiativePetrify", 0f, new ConfigDescription("Petrify penalty inflicted when using Scout's Initiative.", (AcceptableValueBase)(object)new AcceptableValueRange(0f, 100f), Array.Empty())); StrangeGemPetrifyCost = ((BaseUnityPlugin)this).Config.Bind("2. Gem Petrify Values", "StrangeGemPetrify", 0f, new ConfigDescription("Petrify penalty inflicted when activating Strange Gem / Relics.", (AcceptableValueBase)(object)new AcceptableValueRange(0f, 100f), Array.Empty())); GenericGemPetrifyCost = ((BaseUnityPlugin)this).Config.Bind("2. Gem Petrify Values", "OtherGemsPetrify", 0f, new ConfigDescription("Fallback petrify penalty for any other unidentified Scout Gems/Amulets.", (AcceptableValueBase)(object)new AcceptableValueRange(0f, 100f), Array.Empty())); LogSource.LogInfo((object)"ScoutGemPetrifyConfig v1.1.0 initialized."); try { _harmony = new Harmony("com.modder.peak.scoutgempetrifyconfig"); _harmony.PatchAll(Assembly.GetExecutingAssembly()); LogSource.LogInfo((object)"ScoutGemPetrifyConfig successfully patched Scout Gem petrify mechanics!"); } catch (Exception arg) { LogSource.LogError((object)string.Format("Failed to patch methods in {0}: {1}", "ScoutGemPetrifyConfig", arg)); } } public static float GetConfiguredPetrifyCost(string itemName, float originalCost) { if (!ModEnabled.Value) { return originalCost; } if (!UseCustomFlatValues.Value) { return Mathf.Max(0f, originalCost * GlobalPetrifyMultiplier.Value); } string text = itemName.ToLowerInvariant(); if (text.Contains("ambition")) { return AmbitionPetrifyCost.Value; } if (text.Contains("generosity")) { return GenerosityPetrifyCost.Value; } if (text.Contains("tenacity")) { return TenacityPetrifyCost.Value; } if (text.Contains("initiative")) { return InitiativePetrifyCost.Value; } if (text.Contains("strange")) { return StrangeGemPetrifyCost.Value; } return GenericGemPetrifyCost.Value; } private void OnDestroy() { Harmony harmony = _harmony; if (harmony != null) { harmony.UnpatchSelf(); } } } [HarmonyPatch] public static class ScoutGemUsagePatches { [HarmonyTargetMethods] public static IEnumerable TargetItemMethods() { string[] array = new string[10] { "AmuletItem", "ScoutGemItem", "MysticalItem", "ScoutAmbition", "ScoutGenerosity", "ScoutTenacity", "ScoutInitiative", "StrangeGemItem", "ItemUsageHandler", "ScoutItem" }; string[] array2 = array; foreach (string text in array2) { Type type = AccessTools.TypeByName(text) ?? AccessTools.TypeByName("PEAK." + text) ?? AccessTools.TypeByName("PEAK.Items." + text); if (!(type == null)) { MethodInfo methodInfo = AccessTools.Method(type, "Use", (Type[])null, (Type[])null) ?? AccessTools.Method(type, "OnUse", (Type[])null, (Type[])null) ?? AccessTools.Method(type, "Activate", (Type[])null, (Type[])null) ?? AccessTools.Method(type, "TriggerAbility", (Type[])null, (Type[])null) ?? AccessTools.Method(type, "ConsumeItem", (Type[])null, (Type[])null); if (methodInfo != null) { yield return methodInfo; } } } } [HarmonyPrefix] public static void PrefixItemUse(object __instance) { if (NoPetrifyGemsPlugin.ModEnabled.Value && __instance != null) { string name = __instance.GetType().Name; FieldInfo fieldInfo = AccessTools.Field(__instance.GetType(), "petrifyCost") ?? AccessTools.Field(__instance.GetType(), "petrifyAmount") ?? AccessTools.Field(__instance.GetType(), "petrifyPenalty") ?? AccessTools.Field(__instance.GetType(), "stoneCost"); if (fieldInfo != null) { float num = Convert.ToSingle(fieldInfo.GetValue(__instance)); float configuredPetrifyCost = NoPetrifyGemsPlugin.GetConfiguredPetrifyCost(name, num); fieldInfo.SetValue(__instance, configuredPetrifyCost); NoPetrifyGemsPlugin.LogSource.LogDebug((object)$"[ScoutGemConfig] Adjusted {name} petrify cost from {num} to {configuredPetrifyCost}."); } } } } [HarmonyPatch] public static class PetrifyStatusPatches { [HarmonyTargetMethods] public static IEnumerable TargetMethods() { string[] array = new string[5] { "PlayerStatus", "CharacterStats", "ScoutStatus", "StatusEffectManager", "PlayerController" }; string[] targetMethodNames = new string[5] { "AddPetrify", "ApplyPetrify", "AddStatusEffect", "IncreasePetrify", "ModifyPetrify" }; string[] array2 = array; foreach (string text in array2) { Type type = AccessTools.TypeByName(text) ?? AccessTools.TypeByName("PEAK." + text); if (type == null) { continue; } string[] array3 = targetMethodNames; foreach (string text2 in array3) { MethodInfo methodInfo = AccessTools.Method(type, text2, new Type[1] { typeof(float) }, (Type[])null) ?? AccessTools.Method(type, text2, (Type[])null, (Type[])null); if (methodInfo != null) { yield return methodInfo; } } } } [HarmonyPrefix] public static bool InterceptPetrify(ref float amount) { if (!NoPetrifyGemsPlugin.ModEnabled.Value) { return true; } if (!NoPetrifyGemsPlugin.UseCustomFlatValues.Value) { amount *= Mathf.Clamp01(NoPetrifyGemsPlugin.GlobalPetrifyMultiplier.Value); if (amount <= 0.001f) { amount = 0f; return false; } } return true; } } }