The BepInEx console will not appear when launching like it does for other games on Thunderstore (you can turn it back on in your BepInEx.cfg file). If your PEAK crashes on startup, add -dx12 to your launch parameters.
Decompiled source of Dehydration v1.1.1
plugins/PeakThirst.dll
Decompiled a month agousing System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection; using System.Reflection.Emit; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using BepInEx; using HarmonyLib; using Microsoft.CodeAnalysis; using PEAKLib.Core; using PEAKLib.Stats; using PeakThirst; using UnityEngine; using UnityEngine.SceneManagement; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")] [assembly: AssemblyCompany("PeakThirst")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0")] [assembly: AssemblyProduct("PeakThirst")] [assembly: AssemblyTitle("PeakThirst")] [assembly: AssemblyVersion("1.0.0.0")] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Microsoft.CodeAnalysis.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; } } } [HarmonyPatch(typeof(Item), "Awake")] public static class Item_TargetMethod_Patch { private static void Postfix(Item __instance) { Debug.Log((object)((Object)((Component)__instance).gameObject).name); float restoration = ThirstRestorationCalculator.CalculateThirstRestoration(((Component)__instance).gameObject); if (restoration <= 0f) { return; } Item obj = __instance; obj.OnConsumed = (Action)Delegate.Combine(obj.OnConsumed, (Action)delegate { //IL_003a: Unknown result type (might be due to invalid IL or missing references) Character holderCharacter = __instance.holderCharacter; CharacterAfflictions val = (((Object)(object)holderCharacter != (Object)null) ? holderCharacter.refs : null)?.afflictions; if ((Object)(object)val != (Object)null) { val.SubtractStatus(ThirstAffliction.DehydrationType, restoration, false); } }); } } [HarmonyPatch(typeof(Action_RestoreHunger), "RunAction")] public static class Action_RestoreHunger_TargetMethod_Patch { private static readonly Func<ItemAction, Character> GetCharacter = AccessTools.MethodDelegate<Func<ItemAction, Character>>(AccessTools.PropertyGetter(typeof(ItemAction), "character"), (object)null, true); private static void Postfix(Action_RestoreHunger __instance) { //IL_0018: Unknown result type (might be due to invalid IL or missing references) Character val = GetCharacter((ItemAction)(object)__instance); val.refs.afflictions.SubtractStatus(ThirstAffliction.DehydrationType, __instance.restorationAmount / 4f, false); } } [HarmonyPatch(typeof(CharacterAfflictions), "UpdateNormalStatuses")] public static class CharacterAfflictions_TargetMethod_Patch { private static void Postfix(CharacterAfflictions __instance) { //IL_005b: Unknown result type (might be due to invalid IL or missing references) if (__instance.character.data.fullyConscious) { CharacterAfflictions afflictions = __instance.character.refs.afflictions; float num = 1f + afflictions.GetCurrentStatus((STATUSTYPE)8) * 20f; float num2 = Time.deltaTime * __instance.hungerPerSecond * Ascents.hungerRateMultiplier * 2f * num; afflictions.AddStatus(ThirstAffliction.DehydrationType, num2, false); } } } internal static class SpriteLoader { public static Sprite FromEmbedded(string resourceName, float pixelsPerUnit = 100f) { //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_004d: Expected O, but got Unknown //IL_00ad: Unknown result type (might be due to invalid IL or missing references) //IL_00bc: Unknown result type (might be due to invalid IL or missing references) Assembly executingAssembly = Assembly.GetExecutingAssembly(); using Stream stream = executingAssembly.GetManifestResourceStream(resourceName); if (stream == null) { Debug.LogError((object)("[PeakThirst] Embedded resource not found: " + resourceName)); return null; } using MemoryStream memoryStream = new MemoryStream(); stream.CopyTo(memoryStream); Texture2D val = new Texture2D(2, 2, (TextureFormat)5, false); if (!ImageConversion.LoadImage(val, memoryStream.ToArray())) { Debug.LogError((object)("[PeakThirst] Failed to load image data for: " + resourceName)); return null; } ((Object)val).name = Path.GetFileNameWithoutExtension(resourceName); ((Texture)val).filterMode = (FilterMode)1; return Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f), pixelsPerUnit); } } public static class ThirstAffliction { public const string StatusName = "Dehydration"; public static STATUSTYPE DehydrationType; public static void CreateThirstAffliction() { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_005d: Unknown result type (might be due to invalid IL or missing references) //IL_0069: Unknown result type (might be due to invalid IL or missing references) //IL_0072: Expected O, but got Unknown //IL_0073: Unknown result type (might be due to invalid IL or missing references) //IL_0084: Unknown result type (might be due to invalid IL or missing references) //IL_0089: Unknown result type (might be due to invalid IL or missing references) Sprite icon = SpriteLoader.FromEmbedded("PeakThirst.Sprites.Droplet.png"); Status val = new Status { Name = "Dehydration", Color = new Color(0.075f, 0.286f, 1f), MaxAmount = 2f, AllowClear = true, ReductionCooldown = 0f, ReductionPerSecond = 0f, Icon = icon }; new StatusContent(val).Register(Thirst.Definition); DehydrationType = val.Type; } } namespace System.Runtime.CompilerServices { [AttributeUsage(AttributeTargets.All, Inherited = false)] public sealed class NullableAttribute : Attribute { public NullableAttribute(byte b) { } public NullableAttribute(byte[] b) { } } [AttributeUsage(AttributeTargets.All, Inherited = false)] public sealed class NullableContextAttribute : Attribute { public NullableContextAttribute(byte b) { } } } namespace PeakThirst { public static class ThirstRestorationCalculator { public static float CalculateThirstRestoration(GameObject item) { string name = ((Object)item).name; Debug.Log((object)("Calculating thirst for " + name)); float num = 0f; if (name.Contains("Apple Berry")) { num += 0.1f; } if (name.Contains("Berrynana")) { num += 0.2f; } if (name.Contains("Bugfix")) { num += 0.15f; } if (name.Contains("Clusterberry")) { num += 0.35f; } if (name.Contains("Kingberry")) { num += 0.15f; } if (name.Contains("Marshmallow")) { num += 0.45f; } if (name.Contains("Mushroom")) { num += 0.075f; } if (name.Contains("Sports Drink")) { num += 1f; } if (name.Contains("Winterberry")) { num += 0.3f; } if (name.Contains("Honeycomb")) { num += 0.15f; } if (name.Contains("Coconut_half")) { num += 0.6f; } if (name.Contains("AloeVera")) { num += 1.5f; } if (name.Contains("Turkey")) { num += 0.7f; } if (name.Contains("Napberry")) { num += 1f; } if (name.Contains("Prickleberry")) { num += 0.5f; } if (name.Contains("Cure-All")) { num += 0.9f; } if (name.Contains("MedicinalRoot")) { num += 0.2f; } if (name.Contains("Energy Drink")) { num += 0.5f; } return num; } } public static class OnsenThirst { public static void AddThirstToOnsens(bool includeInactive = false) { //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Unknown result type (might be due to invalid IL or missing references) GameObject[] array = FindAllByName("heat zone", includeInactive); GameObject[] array2 = array; foreach (GameObject val in array2) { GameObject val2 = Object.Instantiate<GameObject>(val); val2.transform.SetParent(val.transform.parent, true); StatusEmitter val3 = val2.GetComponent<StatusEmitter>(); if ((Object)(object)val3 == (Object)null) { val3 = val2.AddComponent<StatusEmitter>(); } val3.statusType = ThirstAffliction.DehydrationType; } } public static GameObject[] FindAllByName(string targetName, bool includeInactive = false) { //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Unknown result type (might be due to invalid IL or missing references) if (string.IsNullOrEmpty(targetName)) { return Array.Empty<GameObject>(); } FindObjectsInactive val = (FindObjectsInactive)(includeInactive ? 1 : 0); Transform[] array = Object.FindObjectsByType<Transform>(val, (FindObjectsSortMode)0); List<GameObject> list = new List<GameObject>(array.Length); Transform[] array2 = array; foreach (Transform val2 in array2) { if ((Object)(object)val2 != (Object)null && ((Object)val2).name == targetName) { list.Add(((Component)val2).gameObject); } } return list.ToArray(); } } public class Action_MergerAction : ItemAction { public ItemAction action1; public ItemAction action2; public override void RunAction() { ((ItemActionBase)action1).RunAction(); ((ItemActionBase)action2).RunAction(); } } [BepInPlugin("com.khakixd.thirst", "Thirst", "0.1.0")] public class Thirst : BaseUnityPlugin { private Harmony _harmony; public static ModDefinition Definition { get; set; } private void Awake() { //IL_002e: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Expected O, but got Unknown Definition = ModDefinition.GetOrCreate(((BaseUnityPlugin)this).Info.Metadata); ((BaseUnityPlugin)this).Logger.LogInfo((object)"Thirst loaded!"); _harmony = new Harmony("com.khakixd.thirst"); ThirstAffliction.CreateThirstAffliction(); _harmony.PatchAll(Assembly.GetExecutingAssembly()); try { int num = Harmony.GetAllPatchedMethods().Count(); ((BaseUnityPlugin)this).Logger.LogInfo((object)$"Harmony: total patched methods in process = {num}"); } catch { } SceneManager.sceneLoaded += OnSceneLoaded; } private void OnDestroy() { try { Harmony harmony = _harmony; if (harmony != null) { harmony.UnpatchSelf(); } } catch { Debug.Log((object)"Cannot unpatch thirst!"); } } private void OnSceneLoaded(Scene scene, LoadSceneMode sceneMode) { OnsenThirst.AddThirstToOnsens(); } } } namespace PeakThirst.Patches { [HarmonyPatch] internal static class GetEatenHydrationPatch { [CompilerGenerated] private sealed class <TargetMethods>d__2 : IEnumerable<MethodBase>, IEnumerable, IEnumerator<MethodBase>, IDisposable, IEnumerator { private int <>1__state; private MethodBase <>2__current; private int <>l__initialThreadId; private IEnumerator<Type> <>s__1; private Type <t>5__2; private MethodInfo <m>5__3; MethodBase IEnumerator<MethodBase>.Current { [DebuggerHidden] get { return <>2__current; } } object IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public <TargetMethods>d__2(int <>1__state) { this.<>1__state = <>1__state; <>l__initialThreadId = Environment.CurrentManagedThreadId; } [DebuggerHidden] void IDisposable.Dispose() { int num = <>1__state; if (num == -3 || num == 1) { try { } finally { <>m__Finally1(); } } <>s__1 = null; <t>5__2 = null; <m>5__3 = null; <>1__state = -2; } private bool MoveNext() { try { int num = <>1__state; if (num != 0) { if (num != 1) { return false; } <>1__state = -3; goto IL_00ae; } <>1__state = -1; <>s__1 = AccessTools.AllTypes().GetEnumerator(); <>1__state = -3; goto IL_00bd; IL_00ae: <m>5__3 = null; <t>5__2 = null; goto IL_00bd; IL_00bd: if (<>s__1.MoveNext()) { <t>5__2 = <>s__1.Current; <m>5__3 = AccessTools.DeclaredMethod(<t>5__2, "GetEaten", new Type[1] { typeof(Character) }, (Type[])null); if (<m>5__3 != null) { <>2__current = <m>5__3; <>1__state = 1; return true; } goto IL_00ae; } <>m__Finally1(); <>s__1 = null; return false; } catch { //try-fault ((IDisposable)this).Dispose(); throw; } } bool IEnumerator.MoveNext() { //ILSpy generated this explicit interface implementation from .override directive in MoveNext return this.MoveNext(); } private void <>m__Finally1() { <>1__state = -1; if (<>s__1 != null) { <>s__1.Dispose(); } } [DebuggerHidden] void IEnumerator.Reset() { throw new NotSupportedException(); } [DebuggerHidden] IEnumerator<MethodBase> IEnumerable<MethodBase>.GetEnumerator() { if (<>1__state == -2 && <>l__initialThreadId == Environment.CurrentManagedThreadId) { <>1__state = 0; return this; } return new <TargetMethods>d__2(0); } [DebuggerHidden] IEnumerator IEnumerable.GetEnumerator() { return ((IEnumerable<MethodBase>)this).GetEnumerator(); } } private static MethodInfo Apply => AccessTools.Method(typeof(GetEatenHydrationPatch), "ApplyHydration", (Type[])null, (Type[])null); [IteratorStateMachine(typeof(<TargetMethods>d__2))] private static IEnumerable<MethodBase> TargetMethods() { //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new <TargetMethods>d__2(-2); } [HarmonyTranspiler] private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator il) { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_000f: 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 //IL_006e: Unknown result type (might be due to invalid IL or missing references) //IL_0074: Expected O, but got Unknown CodeMatcher codes = new CodeMatcher(instructions, il); if (!InsertedAt("ThrowAchievement") && !InsertedAt("AddStatus") && !InsertedAt("DieInstantly")) { codes.End().Insert((CodeInstruction[])(object)new CodeInstruction[2] { new CodeInstruction(OpCodes.Ldarg_1, (object)null), new CodeInstruction(OpCodes.Call, (object)Apply) }); } return codes.InstructionEnumeration(); bool InsertedAt(string methodName) { //IL_0036: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Expected O, but got Unknown //IL_007f: Unknown result type (might be due to invalid IL or missing references) //IL_0085: Expected O, but got Unknown //IL_0091: Unknown result type (might be due to invalid IL or missing references) //IL_0097: Expected O, but got Unknown int pos = codes.Pos; codes.MatchForward(false, (CodeMatch[])(object)new CodeMatch[1] { new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction i) => (i.opcode == OpCodes.Call || i.opcode == OpCodes.Callvirt) && i.operand is MethodInfo methodInfo && methodInfo.Name == methodName), (string)null) }); if (!codes.IsValid) { codes.Start().Advance(pos); return false; } codes.Insert((CodeInstruction[])(object)new CodeInstruction[2] { new CodeInstruction(OpCodes.Ldarg_1, (object)null), new CodeInstruction(OpCodes.Call, (object)Apply) }); return true; } } private static void ApplyHydration(Character eater) { //IL_0027: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)eater == (Object)null) && eater.IsLocal) { eater.refs.afflictions.SubtractStatus(ThirstAffliction.DehydrationType, 500f, false); } } } [HarmonyPatch(typeof(StormVisual))] internal static class StormVisualRainHydrationPatch { [HarmonyPatch("LateUpdate")] [HarmonyPostfix] private static void Postfix(StormVisual __instance) { //IL_0002: Unknown result type (might be due to invalid IL or missing references) //IL_0008: Invalid comparison between Unknown and I4 //IL_004b: Unknown result type (might be due to invalid IL or missing references) if ((int)__instance.stormType <= 0 && __instance.playerInWindZone) { Character observedCharacter = Character.observedCharacter; if (!((Object)(object)observedCharacter == (Object)null) && observedCharacter.IsLocal) { observedCharacter.refs.afflictions.SubtractStatus(ThirstAffliction.DehydrationType, 0.1f * Time.deltaTime, false); } } } } [HarmonyPatch(typeof(WaterfallPusher))] internal static class WaterfallPusher_OnTriggerEnter_Patch { [HarmonyPatch("OnTriggerEnter")] [HarmonyTranspiler] private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator il) { //IL_0069: Unknown result type (might be due to invalid IL or missing references) //IL_0084: Unknown result type (might be due to invalid IL or missing references) //IL_008a: Expected O, but got Unknown //IL_00be: Unknown result type (might be due to invalid IL or missing references) //IL_00c4: Expected O, but got Unknown //IL_00cc: Unknown result type (might be due to invalid IL or missing references) //IL_00d2: Expected O, but got Unknown //IL_00da: Unknown result type (might be due to invalid IL or missing references) //IL_00e0: Expected O, but got Unknown MethodInfo playCall = AccessTools.Method(typeof(SFX_PlayOneShot), "Play", (Type[])null, (Type[])null); MethodInfo methodInfo = AccessTools.Method(typeof(Component), "GetComponentInParent", Type.EmptyTypes, new Type[1] { typeof(Character) }); MethodInfo methodInfo2 = AccessTools.Method(typeof(WaterfallPusher_OnTriggerEnter_Patch), "ApplyHydration", (Type[])null, (Type[])null); CodeMatcher val = new CodeMatcher(instructions, il).MatchForward(false, (CodeMatch[])(object)new CodeMatch[1] { new CodeMatch((Func<CodeInstruction, bool>)((CodeInstruction ci) => CodeInstructionExtensions.Calls(ci, playCall)), (string)null) }); if (!val.IsValid) { return val.InstructionEnumeration(); } val.Advance(1).Insert((CodeInstruction[])(object)new CodeInstruction[3] { new CodeInstruction(OpCodes.Ldarg_1, (object)null), new CodeInstruction(OpCodes.Callvirt, (object)methodInfo), new CodeInstruction(OpCodes.Call, (object)methodInfo2) }); return val.InstructionEnumeration(); } private static void ApplyHydration(Character c) { //IL_0019: Unknown result type (might be due to invalid IL or missing references) if (!((Object)(object)c == (Object)null)) { c.refs.afflictions.SubtractStatus(ThirstAffliction.DehydrationType, 500f, false); } } } }