using System;
using System.Collections;
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 PEAKLib.UI;
using PEAKLib.UI.Elements;
using PeakTuner.Cheats;
using PeakTuner.UI;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("PeakTuner")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.1.4")]
[assembly: AssemblyInformationalVersion("0.1.4+1d0026f04eff4ecc5c049d6d43d34d10a9e93bd7")]
[assembly: AssemblyProduct("PeakTuner")]
[assembly: AssemblyTitle("PeakTuner")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.4.0")]
[module: UnverifiableCode]
[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.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
internal sealed class NullableAttribute : Attribute
{
public readonly byte[] NullableFlags;
public NullableAttribute(byte P_0)
{
NullableFlags = new byte[1] { P_0 };
}
public NullableAttribute(byte[] P_0)
{
NullableFlags = P_0;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
internal sealed class NullableContextAttribute : Attribute
{
public readonly byte Flag;
public NullableContextAttribute(byte P_0)
{
Flag = P_0;
}
}
[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;
}
}
}
namespace BepInEx
{
[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
[Conditional("CodeGeneration")]
internal sealed class BepInAutoPluginAttribute : Attribute
{
public BepInAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
{
}
}
}
namespace BepInEx.Preloader.Core.Patching
{
[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
[Conditional("CodeGeneration")]
internal sealed class PatcherAutoPluginAttribute : Attribute
{
public PatcherAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
{
}
}
}
namespace PeakTuner
{
public sealed class ModConfig
{
public ConfigEntry<bool> InfiniteStamina { get; }
public ConfigEntry<bool> NoFallDamage { get; }
public ConfigEntry<bool> DisableCold { get; }
public ConfigEntry<bool> DisablePoison { get; }
public ConfigEntry<bool> DisableHot { get; }
public ConfigEntry<bool> DisableHunger { get; }
public ConfigEntry<bool> GodMode { get; }
public ConfigEntry<float> SpeedMultiplier { get; }
public ModConfig(ConfigFile cfg)
{
//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
//IL_0105: Expected O, but got Unknown
InfiniteStamina = cfg.Bind<bool>("Cheats", "InfiniteStamina", false, "Prevents stamina from decreasing.");
NoFallDamage = cfg.Bind<bool>("Cheats", "NoFallDamage", false, "Disables fall damage.");
DisableCold = cfg.Bind<bool>("Cheats", "DisableCold", false, "Continuously clears Cold if present.");
DisablePoison = cfg.Bind<bool>("Cheats", "DisablePoison", false, "Continuously clears Poison if present.");
DisableHot = cfg.Bind<bool>("Cheats", "DisableHot", false, "Continuously clears Hot if present.");
DisableHunger = cfg.Bind<bool>("Cheats", "DisableHunger", false, "Continuously clears Hunger if present.");
GodMode = cfg.Bind<bool>("Cheats", "GodMode", false, "Invincible while enabled.");
SpeedMultiplier = cfg.Bind<float>("Cheats", "SpeedMultiplier", 1f, new ConfigDescription("Movement speed multiplier (1, 2, or 4).", (AcceptableValueBase)(object)new AcceptableValueList<float>(new float[6] { 1f, 2f, 4f, 8f, 16f, 32f }), Array.Empty<object>()));
}
}
[BepInPlugin("com.cbein.peaktuner", "PeakTuner", "0.1.4")]
public class Plugin : BaseUnityPlugin
{
private ModConfig _cfg;
private CheatsService _cheats;
private float _nextApplyTime;
private DebugOverlay? _overlay;
internal static ManualLogSource Log { get; private set; }
private void Awake()
{
Log = ((BaseUnityPlugin)this).Logger;
_cfg = new ModConfig(((BaseUnityPlugin)this).Config);
ResetCheatsToDefaults();
ReflectionCache r = new ReflectionCache(Log);
StatusApi status = new StatusApi(Log, r);
_cheats = new CheatsService(Log, r, status, _cfg);
_overlay = new DebugOverlay("PeakTuner", "0.1.4");
SpeedController.Install(Log, _cfg);
PauseMenuCheatsUi.Install(Log, _cfg, _cheats);
Log.LogInfo((object)"[PeakTuner] Loaded v0.1.4 (pause menu integration).");
}
private void Update()
{
if (Input.GetKeyDown((KeyCode)289))
{
_overlay?.Toggle();
Log.LogInfo((object)"[PeakTuner] Debug overlay toggled (F8).");
}
_overlay?.Update();
if (IsGameplayReady() && Time.time >= _nextApplyTime)
{
_nextApplyTime = Time.time + 0.1f;
_cheats.ApplyCheats();
}
}
private void OnGUI()
{
_overlay?.OnGUI();
}
private static bool IsGameplayReady()
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0012: Expected O, but got Unknown
Character localCharacter = Character.localCharacter;
return (Object)localCharacter != (Object)null;
}
private void ResetCheatsToDefaults()
{
_cfg.InfiniteStamina.Value = false;
_cfg.NoFallDamage.Value = false;
_cfg.DisableCold.Value = false;
_cfg.DisablePoison.Value = false;
_cfg.DisableHot.Value = false;
_cfg.DisableHunger.Value = false;
_cfg.GodMode.Value = false;
_cfg.SpeedMultiplier.Value = 1f;
}
}
internal static class VersionInfo
{
public const string Guid = "com.cbein.peaktuner";
public const string Name = "PeakTuner";
public const string Version = "0.1.4";
}
}
namespace PeakTuner.UI
{
public sealed class CursorController
{
private bool _prevVisible;
private CursorLockMode _prevLock;
public bool IsCaptured { get; private set; }
public void Capture()
{
//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)
if (!IsCaptured)
{
_prevVisible = Cursor.visible;
_prevLock = Cursor.lockState;
ForceUnlockedCursor();
IsCaptured = true;
}
}
public void CaptureFrame()
{
if (!IsCaptured)
{
Capture();
}
else
{
ForceUnlockedCursor();
}
}
public void Release()
{
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
if (IsCaptured)
{
Cursor.visible = _prevVisible;
Cursor.lockState = _prevLock;
IsCaptured = false;
}
}
private static void ForceUnlockedCursor()
{
Cursor.visible = true;
Cursor.lockState = (CursorLockMode)0;
}
}
public sealed class DebugOverlay
{
private readonly string _modName;
private readonly string _version;
private bool _visible = true;
private readonly float _startTime;
private float _fps;
private float _fpsAccum;
private int _fpsFrames;
private float _fpsNextTime;
private GUIStyle? _style;
public DebugOverlay(string modName, string version)
{
_modName = modName;
_version = version;
_startTime = Time.unscaledTime;
_fpsNextTime = Time.unscaledTime + 0.5f;
}
public void Toggle()
{
_visible = !_visible;
}
public void Update()
{
float unscaledTime = Time.unscaledTime;
_fpsAccum += Time.unscaledDeltaTime;
_fpsFrames++;
if (unscaledTime >= _fpsNextTime)
{
float num = ((_fpsFrames > 0) ? (_fpsAccum / (float)_fpsFrames) : 0f);
_fps = ((num > 1E-06f) ? (1f / num) : 0f);
_fpsAccum = 0f;
_fpsFrames = 0;
_fpsNextTime = unscaledTime + 0.5f;
}
}
public void OnGUI()
{
//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
if (_visible)
{
EnsureStyle();
float num = Mathf.Max(0f, Time.unscaledTime - _startTime);
TimeSpan timeSpan = TimeSpan.FromSeconds(num);
string text = ((timeSpan.TotalHours >= 1.0) ? $"{(int)timeSpan.TotalHours:00}:{timeSpan.Minutes:00}:{timeSpan.Seconds:00}" : $"{timeSpan.Minutes:00}:{timeSpan.Seconds:00}");
string text2 = $"{_modName} v{_version} | FPS: {_fps:0} | Up: {text}";
float num2 = 520f;
float num3 = 22f;
Rect val = default(Rect);
((Rect)(ref val))..ctor((float)Screen.width - num2 - 10f, 10f, num2, num3);
GUI.Label(val, text2, _style);
}
}
private void EnsureStyle()
{
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
//IL_0019: Unknown result type (might be due to invalid IL or missing references)
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
//IL_0028: Unknown result type (might be due to invalid IL or missing references)
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
//IL_003b: Expected O, but got Unknown
//IL_0046: Unknown result type (might be due to invalid IL or missing references)
if (_style == null)
{
_style = new GUIStyle(GUI.skin.label)
{
fontSize = 13,
alignment = (TextAnchor)2,
richText = false,
wordWrap = false
};
_style.normal.textColor = Color.white;
}
}
}
public static class PauseMenuCheatsUi
{
private sealed class UiHost : MonoBehaviour
{
}
private sealed class ToggleRow
{
public string Label { get; }
public ConfigEntry<bool> Entry { get; }
public PeakMenuButton Button { get; }
public ToggleRow(string label, ConfigEntry<bool> entry, PeakMenuButton button)
{
Label = label;
Entry = entry;
Button = button;
}
}
private static class CheatColor
{
public static readonly Color StaminaGreen = new Color(0.2f, 0.7f, 0.2f, 1f);
public static readonly Color FallPink = new Color(0.9f, 0.35f, 0.7f, 1f);
public static readonly Color ColdBlue = new Color(0.2f, 0.55f, 0.95f, 1f);
public static readonly Color PoisonPurple = new Color(0.6f, 0.3f, 0.85f, 1f);
public static readonly Color HotRed = new Color(0.9f, 0.25f, 0.25f, 1f);
public static readonly Color HungerYellow = new Color(0.95f, 0.8f, 0.2f, 1f);
public static readonly Color GodOrange = new Color(0.95f, 0.55f, 0.15f, 1f);
public static readonly Color NeutralClose = new Color(0.55f, 0.55f, 0.55f, 1f);
public static readonly Color SpeedSelected = new Color(0.2f, 0.85f, 0.55f, 1f);
public static readonly Color SpeedUnselected = new Color(0.35f, 0.35f, 0.4f, 1f);
}
[CompilerGenerated]
private static class <>O
{
public static BuilderDelegate <0>__BuildIntoPauseMenu;
}
[CompilerGenerated]
private sealed class <RunUiActionNextFrame>d__11 : IEnumerator<object>, IEnumerator, IDisposable
{
private int <>1__state;
private object <>2__current;
public Action action;
public string name;
object IEnumerator<object>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <RunUiActionNextFrame>d__11(int <>1__state)
{
this.<>1__state = <>1__state;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
<>1__state = -2;
}
private bool MoveNext()
{
switch (<>1__state)
{
default:
return false;
case 0:
<>1__state = -1;
<>2__current = null;
<>1__state = 1;
return true;
case 1:
<>1__state = -1;
try
{
action();
}
catch (Exception arg)
{
_log.LogError((object)$"[PeakTuner] UI action '{name}' crashed: {arg}");
}
finally
{
_uiBusy = false;
}
return false;
}
}
bool IEnumerator.MoveNext()
{
//ILSpy generated this explicit interface implementation from .override directive in MoveNext
return this.MoveNext();
}
[DebuggerHidden]
void IEnumerator.Reset()
{
throw new NotSupportedException();
}
}
private static ManualLogSource _log = null;
private static ModConfig _cfg = null;
private static CheatsService _cheats = null;
private static bool _registered;
private static Sprite? _solidSprite;
private static UiHost? _uiHost;
private static bool _uiBusy;
private static float _nextAllowedClickTime;
private const float PanelWidth = 720f;
private const float PanelHeight = 840f;
private const float PanelSpacing = 6f;
private const float RowHeight = 44f;
private const float HeaderFontSize = 30f;
private const float SectionFontSize = 22f;
private const float CloseBarHeight = 52f;
private const float CloseBarTopGap = 10f;
private const float CloseTextFontSize = 28f;
private static readonly Color CloseBarNormal = new Color(0.09f, 0.09f, 0.11f, 0.96f);
private static readonly Color CloseBarHover = new Color(0.12f, 0.12f, 0.15f, 0.96f);
private static readonly Color CloseBarPress = new Color(0.07f, 0.07f, 0.09f, 0.96f);
private static readonly Color CloseBarText = Color.white;
private static readonly Color PanelBgColor = new Color(0.08f, 0.08f, 0.1f, 0.96f);
private static UiHost EnsureUiHost()
{
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
//IL_001e: Expected O, but got Unknown
if ((Object)(object)_uiHost != (Object)null)
{
return _uiHost;
}
GameObject val = new GameObject("PeakTuner_UiHost");
Object.DontDestroyOnLoad((Object)(object)val);
_uiHost = val.AddComponent<UiHost>();
return _uiHost;
}
private static void RunUiActionThrottled(string name, Action action, float cooldownSeconds = 0.2f)
{
if (!_uiBusy && !(Time.unscaledTime < _nextAllowedClickTime))
{
_uiBusy = true;
_nextAllowedClickTime = Time.unscaledTime + cooldownSeconds;
((MonoBehaviour)EnsureUiHost()).StartCoroutine(RunUiActionNextFrame(name, action));
}
}
[IteratorStateMachine(typeof(<RunUiActionNextFrame>d__11))]
private static IEnumerator RunUiActionNextFrame(string name, Action action)
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <RunUiActionNextFrame>d__11(0)
{
name = name,
action = action
};
}
public static void Install(ManualLogSource log, ModConfig cfg, CheatsService cheats)
{
//IL_0030: Unknown result type (might be due to invalid IL or missing references)
//IL_0035: Unknown result type (might be due to invalid IL or missing references)
//IL_003b: Expected O, but got Unknown
_log = log;
_cfg = cfg;
_cheats = cheats;
if (!_registered)
{
_registered = true;
object obj = <>O.<0>__BuildIntoPauseMenu;
if (obj == null)
{
BuilderDelegate val = BuildIntoPauseMenu;
<>O.<0>__BuildIntoPauseMenu = val;
obj = (object)val;
}
MenuAPI.AddToPauseMenu((BuilderDelegate)obj);
_log.LogInfo((object)"[PeakTuner] Registered pause-menu UI builder.");
}
}
private static void BuildIntoPauseMenu(Transform pauseMenuMainPageTransform)
{
//IL_005e: Unknown result type (might be due to invalid IL or missing references)
//IL_0068: Expected O, but got Unknown
//IL_0091: Unknown result type (might be due to invalid IL or missing references)
//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
//IL_00db: Unknown result type (might be due to invalid IL or missing references)
//IL_0124: Unknown result type (might be due to invalid IL or missing references)
//IL_012e: Expected O, but got Unknown
//IL_0198: Unknown result type (might be due to invalid IL or missing references)
//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
//IL_01da: Unknown result type (might be due to invalid IL or missing references)
//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
//IL_021c: Unknown result type (might be due to invalid IL or missing references)
//IL_023d: Unknown result type (might be due to invalid IL or missing references)
//IL_025e: Unknown result type (might be due to invalid IL or missing references)
//IL_0288: Unknown result type (might be due to invalid IL or missing references)
//IL_028f: Expected O, but got Unknown
//IL_02fa: Unknown result type (might be due to invalid IL or missing references)
//IL_0304: Expected O, but got Unknown
//IL_04cd: Unknown result type (might be due to invalid IL or missing references)
//IL_04d7: Expected O, but got Unknown
//IL_04ee: Unknown result type (might be due to invalid IL or missing references)
//IL_04f8: Expected O, but got Unknown
//IL_050f: Unknown result type (might be due to invalid IL or missing references)
//IL_0519: Expected O, but got Unknown
//IL_0530: Unknown result type (might be due to invalid IL or missing references)
//IL_053a: Expected O, but got Unknown
//IL_0551: Unknown result type (might be due to invalid IL or missing references)
//IL_055b: Expected O, but got Unknown
//IL_0572: Unknown result type (might be due to invalid IL or missing references)
//IL_057c: Expected O, but got Unknown
//IL_05bd: Unknown result type (might be due to invalid IL or missing references)
//IL_05ed: Unknown result type (might be due to invalid IL or missing references)
//IL_061d: Unknown result type (might be due to invalid IL or missing references)
//IL_064d: Unknown result type (might be due to invalid IL or missing references)
//IL_0696: Unknown result type (might be due to invalid IL or missing references)
//IL_06a0: Expected O, but got Unknown
if (!IsGameplayReady() || (Object)(object)pauseMenuMainPageTransform.Find("PeakTuner_CheatsPanel") != (Object)null)
{
return;
}
Transform val = FindPauseMenuButtonListParent(pauseMenuMainPageTransform);
PeakMenuButton val2 = MenuAPI.CreatePauseMenuButton("Cheats");
ElementExtensions.ParentTo<PeakMenuButton>(val2, val);
SetButtonText(val2, "Cheats");
((Component)val2.Button).transform.SetSiblingIndex(0);
GameObject panelGo = new GameObject("PeakTuner_CheatsPanel");
panelGo.transform.SetParent(pauseMenuMainPageTransform, false);
RectTransform val3 = panelGo.AddComponent<RectTransform>();
val3.anchorMin = new Vector2(0.5f, 0.5f);
val3.anchorMax = new Vector2(0.5f, 0.5f);
val3.pivot = new Vector2(0.5f, 0.5f);
val3.sizeDelta = new Vector2(720f, 840f);
val3.anchoredPosition = Vector2.zero;
Image bg = panelGo.AddComponent<Image>();
ApplySolidPanelBackground(bg);
VerticalLayoutGroup val4 = panelGo.AddComponent<VerticalLayoutGroup>();
((LayoutGroup)val4).childAlignment = (TextAnchor)1;
((HorizontalOrVerticalLayoutGroup)val4).spacing = 6f;
((LayoutGroup)val4).padding = new RectOffset(18, 18, 18, 18);
((HorizontalOrVerticalLayoutGroup)val4).childControlWidth = true;
((HorizontalOrVerticalLayoutGroup)val4).childControlHeight = true;
((HorizontalOrVerticalLayoutGroup)val4).childForceExpandWidth = true;
((HorizontalOrVerticalLayoutGroup)val4).childForceExpandHeight = false;
AddPlainHeaderText("CHEATS", panelGo.transform, 30f);
Transform transform = panelGo.transform;
List<ToggleRow> toggles = new List<ToggleRow>();
AddCheatToggleButton("Infinite Stamina", _cfg.InfiniteStamina, transform, toggles, CheatColor.StaminaGreen);
AddCheatToggleButton("No Fall Damage", _cfg.NoFallDamage, transform, toggles, CheatColor.FallPink);
AddCheatToggleButton("Disable Cold", _cfg.DisableCold, transform, toggles, CheatColor.ColdBlue);
AddCheatToggleButton("Disable Poison", _cfg.DisablePoison, transform, toggles, CheatColor.PoisonPurple);
AddCheatToggleButton("Disable Hot", _cfg.DisableHot, transform, toggles, CheatColor.HotRed);
AddCheatToggleButton("Disable Hunger", _cfg.DisableHunger, transform, toggles, CheatColor.HungerYellow);
AddCheatToggleButton("God Mode", _cfg.GodMode, transform, toggles, CheatColor.GodOrange);
AddPlainHeaderText("SPEED", panelGo.transform, 22f);
GameObject val5 = new GameObject("PeakTuner_SpeedRow");
val5.transform.SetParent(transform, false);
LayoutElement val6 = val5.AddComponent<LayoutElement>();
val6.flexibleWidth = 1f;
val6.minHeight = 44f;
val6.preferredHeight = 44f;
val6.flexibleHeight = 0f;
HorizontalLayoutGroup val7 = val5.AddComponent<HorizontalLayoutGroup>();
((LayoutGroup)val7).childAlignment = (TextAnchor)4;
((HorizontalOrVerticalLayoutGroup)val7).spacing = 6f;
((LayoutGroup)val7).padding = new RectOffset(0, 0, 0, 0);
((HorizontalOrVerticalLayoutGroup)val7).childControlWidth = true;
((HorizontalOrVerticalLayoutGroup)val7).childControlHeight = true;
((HorizontalOrVerticalLayoutGroup)val7).childForceExpandWidth = true;
((HorizontalOrVerticalLayoutGroup)val7).childForceExpandHeight = false;
PeakMenuButton b1 = MenuAPI.CreatePauseMenuButton("1x");
ElementExtensions.ParentTo<PeakMenuButton>(b1, val5.transform);
SetButtonText(b1, "1x");
MakePanelRow(b1, 44f);
PeakMenuButton b3 = MenuAPI.CreatePauseMenuButton("2x");
ElementExtensions.ParentTo<PeakMenuButton>(b3, val5.transform);
SetButtonText(b3, "2x");
MakePanelRow(b3, 44f);
PeakMenuButton b5 = MenuAPI.CreatePauseMenuButton("4x");
ElementExtensions.ParentTo<PeakMenuButton>(b5, val5.transform);
SetButtonText(b5, "4x");
MakePanelRow(b5, 44f);
PeakMenuButton b6 = MenuAPI.CreatePauseMenuButton("8x");
ElementExtensions.ParentTo<PeakMenuButton>(b6, val5.transform);
SetButtonText(b6, "8x");
MakePanelRow(b6, 44f);
PeakMenuButton b2 = MenuAPI.CreatePauseMenuButton("16x");
ElementExtensions.ParentTo<PeakMenuButton>(b2, val5.transform);
SetButtonText(b2, "16x");
MakePanelRow(b2, 44f);
PeakMenuButton b4 = MenuAPI.CreatePauseMenuButton("32x");
ElementExtensions.ParentTo<PeakMenuButton>(b4, val5.transform);
SetButtonText(b4, "32x");
MakePanelRow(b4, 44f);
((UnityEvent)b1.Button.onClick).AddListener((UnityAction)delegate
{
RunUiActionThrottled("Speed 1x", delegate
{
_cfg.SpeedMultiplier.Value = 1f;
RefreshSpeedButtonTints();
});
});
((UnityEvent)b3.Button.onClick).AddListener((UnityAction)delegate
{
RunUiActionThrottled("Speed 2x", delegate
{
_cfg.SpeedMultiplier.Value = 2f;
RefreshSpeedButtonTints();
});
});
((UnityEvent)b5.Button.onClick).AddListener((UnityAction)delegate
{
RunUiActionThrottled("Speed 4x", delegate
{
_cfg.SpeedMultiplier.Value = 4f;
RefreshSpeedButtonTints();
});
});
((UnityEvent)b6.Button.onClick).AddListener((UnityAction)delegate
{
RunUiActionThrottled("Speed 8x", delegate
{
_cfg.SpeedMultiplier.Value = 8f;
RefreshSpeedButtonTints();
});
});
((UnityEvent)b2.Button.onClick).AddListener((UnityAction)delegate
{
RunUiActionThrottled("Speed 16x", delegate
{
_cfg.SpeedMultiplier.Value = 16f;
RefreshSpeedButtonTints();
});
});
((UnityEvent)b4.Button.onClick).AddListener((UnityAction)delegate
{
RunUiActionThrottled("Speed 32x", delegate
{
_cfg.SpeedMultiplier.Value = 32f;
RefreshSpeedButtonTints();
});
});
AddPlainHeaderText("STATUS EFFECTS (APPLY NOW)", panelGo.transform, 22f);
AddActionButton("Apply Poison", transform, delegate
{
_cheats.ApplyStatus(PeakStatus.Poison, 1f);
}, CheatColor.PoisonPurple);
AddActionButton("Apply Cold", transform, delegate
{
_cheats.ApplyStatus(PeakStatus.Cold, 1f);
}, CheatColor.ColdBlue);
AddActionButton("Apply Hot", transform, delegate
{
_cheats.ApplyStatus(PeakStatus.Hot, 1f);
}, CheatColor.HotRed);
AddActionButton("Apply Hunger", transform, delegate
{
_cheats.ApplyStatus(PeakStatus.Hunger, 1f);
}, CheatColor.HungerYellow);
AddHeaderStyleCloseBar("CLOSE", panelGo.transform, delegate
{
panelGo.SetActive(false);
});
panelGo.SetActive(false);
((UnityEvent)val2.Button.onClick).AddListener((UnityAction)delegate
{
if (IsGameplayReady())
{
RefreshToggleLabels(toggles);
RefreshSpeedButtonTints();
panelGo.SetActive(true);
panelGo.transform.SetAsLastSibling();
}
});
void RefreshSpeedButtonTints()
{
//IL_0030: Unknown result type (might be due to invalid IL or missing references)
//IL_0029: Unknown result type (might be due to invalid IL or missing references)
//IL_005a: Unknown result type (might be due to invalid IL or missing references)
//IL_0053: 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_007d: Unknown result type (might be due to invalid IL or missing references)
//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
//IL_0102: Unknown result type (might be due to invalid IL or missing references)
//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
float value = _cfg.SpeedMultiplier.Value;
ApplyButtonTint(b1, (Mathf.Abs(value - 1f) < 0.001f) ? CheatColor.SpeedSelected : CheatColor.SpeedUnselected);
ApplyButtonTint(b3, (Mathf.Abs(value - 2f) < 0.001f) ? CheatColor.SpeedSelected : CheatColor.SpeedUnselected);
ApplyButtonTint(b5, (Mathf.Abs(value - 4f) < 0.001f) ? CheatColor.SpeedSelected : CheatColor.SpeedUnselected);
ApplyButtonTint(b6, (Mathf.Abs(value - 8f) < 0.001f) ? CheatColor.SpeedSelected : CheatColor.SpeedUnselected);
ApplyButtonTint(b2, (Mathf.Abs(value - 16f) < 0.001f) ? CheatColor.SpeedSelected : CheatColor.SpeedUnselected);
ApplyButtonTint(b4, (Mathf.Abs(value - 32f) < 0.001f) ? CheatColor.SpeedSelected : CheatColor.SpeedUnselected);
}
}
private static void AddCheatToggleButton(string label, ConfigEntry<bool> entry, Transform parent, List<ToggleRow> stash, Color tint)
{
//IL_0079: Unknown result type (might be due to invalid IL or missing references)
//IL_0097: Unknown result type (might be due to invalid IL or missing references)
//IL_00a1: Expected O, but got Unknown
string label2 = label;
ConfigEntry<bool> entry2 = entry;
PeakMenuButton btn = MenuAPI.CreatePauseMenuButton(BuildToggleLabel(label2, entry2.Value));
ElementExtensions.ParentTo<PeakMenuButton>(btn, parent);
SetButtonText(btn, BuildToggleLabel(label2, entry2.Value));
MakePanelRow(btn, 44f);
ApplyButtonTint(btn, tint);
((UnityEvent)btn.Button.onClick).AddListener((UnityAction)delegate
{
RunUiActionThrottled(label2, delegate
{
entry2.Value = !entry2.Value;
((PeakLocalizableElement)btn).Text.text = BuildToggleLabel(label2, entry2.Value);
});
});
stash.Add(new ToggleRow(label2, entry2, btn));
}
private static void AddActionButton(string text, Transform parent, Action action, Color tint)
{
//IL_0040: Unknown result type (might be due to invalid IL or missing references)
//IL_0058: Unknown result type (might be due to invalid IL or missing references)
//IL_0062: Expected O, but got Unknown
string text2 = text;
Action action2 = action;
PeakMenuButton val = MenuAPI.CreatePauseMenuButton(text2);
ElementExtensions.ParentTo<PeakMenuButton>(val, parent);
SetButtonText(val, text2);
MakePanelRow(val, 44f);
ApplyButtonTint(val, tint);
((UnityEvent)val.Button.onClick).AddListener((UnityAction)delegate
{
RunUiActionThrottled(text2, delegate
{
action2();
});
});
}
private static TMP_Text AddPlainHeaderText(string text, Transform parent, float fontSize)
{
//IL_0099: Unknown result type (might be due to invalid IL or missing references)
PeakText val = MenuAPI.CreateText(text, "PeakTuner_hdr_" + Guid.NewGuid().ToString("N"));
ElementExtensions.ParentTo<PeakText>(val, parent);
TMP_Text text2 = ((PeakLocalizableElement)val).Text;
text2.text = text;
text2.fontSize = fontSize;
text2.alignment = (TextAlignmentOptions)514;
text2.textWrappingMode = (TextWrappingModes)0;
LayoutElement val2 = ((Component)text2).gameObject.GetComponent<LayoutElement>();
if ((Object)(object)val2 == (Object)null)
{
val2 = ((Component)text2).gameObject.AddComponent<LayoutElement>();
}
val2.flexibleWidth = 1f;
val2.minHeight = fontSize + 10f;
val2.preferredHeight = fontSize + 10f;
((Graphic)text2).color = Color.white;
return text2;
}
private static void MakePanelRow(PeakMenuButton btn, float height)
{
try
{
GameObject gameObject = ((Component)btn.Button).gameObject;
LayoutElement val = gameObject.GetComponent<LayoutElement>();
if ((Object)(object)val == (Object)null)
{
val = gameObject.AddComponent<LayoutElement>();
}
val.flexibleWidth = 1f;
val.minHeight = height;
val.preferredHeight = height;
val.flexibleHeight = 0f;
}
catch
{
}
}
private static void ApplyButtonTint(PeakMenuButton btn, Color tint)
{
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
//IL_007c: Unknown result type (might be due to invalid IL or missing references)
//IL_0033: Unknown result type (might be due to invalid IL or missing references)
//IL_0040: Unknown result type (might be due to invalid IL or missing references)
//IL_0046: 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)
//IL_0054: Unknown result type (might be due to invalid IL or missing references)
try
{
Image[] componentsInChildren = ((Component)btn.Button).GetComponentsInChildren<Image>(true);
Image[] array = componentsInChildren;
foreach (Image val in array)
{
if (!((Object)(object)val == (Object)null) && !(((Graphic)val).color.a <= 0.01f))
{
float a = ((Graphic)val).color.a;
((Graphic)val).color = new Color(tint.r, tint.g, tint.b, a);
}
}
if ((Object)(object)((PeakLocalizableElement)btn).Text != (Object)null)
{
((Graphic)((PeakLocalizableElement)btn).Text).color = Color.white;
}
}
catch
{
}
}
private static void RefreshToggleLabels(List<ToggleRow> rows)
{
foreach (ToggleRow row in rows)
{
((PeakLocalizableElement)row.Button).Text.text = BuildToggleLabel(row.Label, row.Entry.Value);
}
}
private static string BuildToggleLabel(string label, bool enabled)
{
if (!enabled)
{
return label + ": OFF";
}
return label + ": ON";
}
private static bool IsGameplayReady()
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0012: Expected O, but got Unknown
Character localCharacter = Character.localCharacter;
return (Object)localCharacter != (Object)null;
}
private static Transform FindPauseMenuButtonListParent(Transform root)
{
Transform val = FindButtonParentByText(root, "BACK");
if ((Object)(object)val != (Object)null)
{
return val;
}
string[] array = new string[6] { "Resume", "Continue", "Options", "Settings", "Quit", "Exit" };
for (int i = 0; i < array.Length; i++)
{
Transform val2 = FindButtonParentByText(root, array[i]);
if ((Object)(object)val2 != (Object)null)
{
return val2;
}
}
return root;
}
private static Transform? FindButtonParentByText(Transform root, string needle)
{
Button[] componentsInChildren = ((Component)root).GetComponentsInChildren<Button>(true);
Button[] array = componentsInChildren;
foreach (Button val in array)
{
if ((Object)(object)val == (Object)null)
{
continue;
}
TMP_Text componentInChildren = ((Component)val).GetComponentInChildren<TMP_Text>(true);
if (!((Object)(object)componentInChildren == (Object)null))
{
string a = (componentInChildren.text ?? "").Trim();
if (string.Equals(a, needle, StringComparison.OrdinalIgnoreCase))
{
return ((Component)val).transform.parent;
}
}
}
return null;
}
private static void ApplySolidPanelBackground(Image bg)
{
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
bg.sprite = GetSolidSprite();
bg.type = (Type)1;
((Graphic)bg).material = null;
((Graphic)bg).raycastTarget = true;
((Graphic)bg).color = PanelBgColor;
}
private static Sprite GetSolidSprite()
{
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
//IL_001d: Expected O, but got Unknown
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
//IL_0047: Unknown result type (might be due to invalid IL or missing references)
//IL_0056: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)_solidSprite != (Object)null)
{
return _solidSprite;
}
Texture2D val = new Texture2D(1, 1, (TextureFormat)4, false);
val.SetPixel(0, 0, Color.white);
val.Apply(false, true);
_solidSprite = Sprite.Create(val, new Rect(0f, 0f, 1f, 1f), new Vector2(0.5f, 0.5f), 100f);
return _solidSprite;
}
private static void SetButtonText(PeakMenuButton btn, string text)
{
try
{
if ((Object)(object)((PeakLocalizableElement)btn).Text != (Object)null)
{
((PeakLocalizableElement)btn).Text.text = text;
}
}
catch
{
}
}
private static void AddHeaderStyleCloseBar(string text, Transform parent, Action onClick)
{
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
//IL_0018: Expected O, but got Unknown
//IL_005b: Unknown result type (might be due to invalid IL or missing references)
//IL_0062: Expected O, but got Unknown
//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
//IL_0107: Unknown result type (might be due to invalid IL or missing references)
//IL_0113: Unknown result type (might be due to invalid IL or missing references)
//IL_011f: Unknown result type (might be due to invalid IL or missing references)
//IL_014e: Unknown result type (might be due to invalid IL or missing references)
//IL_0172: Unknown result type (might be due to invalid IL or missing references)
//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
//IL_01ff: Unknown result type (might be due to invalid IL or missing references)
//IL_020b: Unknown result type (might be due to invalid IL or missing references)
//IL_0217: Unknown result type (might be due to invalid IL or missing references)
//IL_0274: Unknown result type (might be due to invalid IL or missing references)
//IL_0280: Unknown result type (might be due to invalid IL or missing references)
//IL_029f: Unknown result type (might be due to invalid IL or missing references)
//IL_02b5: Unknown result type (might be due to invalid IL or missing references)
//IL_02cb: Unknown result type (might be due to invalid IL or missing references)
//IL_02d7: Unknown result type (might be due to invalid IL or missing references)
//IL_02e3: Unknown result type (might be due to invalid IL or missing references)
//IL_02ef: Unknown result type (might be due to invalid IL or missing references)
//IL_0327: Unknown result type (might be due to invalid IL or missing references)
//IL_0331: Expected O, but got Unknown
Action onClick2 = onClick;
GameObject val = new GameObject("PeakTuner_CloseSpacer");
val.transform.SetParent(parent, false);
LayoutElement val2 = val.AddComponent<LayoutElement>();
val2.flexibleWidth = 1f;
float preferredHeight = (val2.minHeight = 18f);
val2.preferredHeight = preferredHeight;
val2.flexibleHeight = 0f;
GameObject val3 = new GameObject("PeakTuner_CloseBar");
val3.transform.SetParent(parent, false);
LayoutElement val4 = val3.AddComponent<LayoutElement>();
val4.flexibleWidth = 1f;
val4.minHeight = 52f;
val4.preferredHeight = 52f;
val4.flexibleHeight = 0f;
Image val5 = val3.AddComponent<Image>();
val5.sprite = GetSolidSprite();
val5.type = (Type)1;
((Graphic)val5).material = null;
((Graphic)val5).raycastTarget = true;
Button val6 = val3.AddComponent<Button>();
((Selectable)val6).targetGraphic = (Graphic)(object)val5;
((Selectable)val6).transition = (Transition)1;
ColorBlock colors = ((Selectable)val6).colors;
((ColorBlock)(ref colors)).normalColor = CloseBarNormal;
((ColorBlock)(ref colors)).highlightedColor = CloseBarHover;
((ColorBlock)(ref colors)).pressedColor = CloseBarPress;
((ColorBlock)(ref colors)).selectedColor = CloseBarHover;
((ColorBlock)(ref colors)).disabledColor = new Color(CloseBarNormal.r, CloseBarNormal.g, CloseBarNormal.b, 0.35f);
((ColorBlock)(ref colors)).colorMultiplier = 1f;
((ColorBlock)(ref colors)).fadeDuration = 0.08f;
((Selectable)val6).colors = colors;
PeakText val7 = MenuAPI.CreateText(text, "PeakTuner_close_txt_" + Guid.NewGuid().ToString("N"));
ElementExtensions.ParentTo<PeakText>(val7, val3.transform);
RectTransform component = ((Component)val7).gameObject.GetComponent<RectTransform>();
component.anchorMin = new Vector2(0f, 0f);
component.anchorMax = new Vector2(1f, 1f);
component.pivot = new Vector2(0.5f, 0.5f);
component.offsetMin = Vector2.zero;
component.offsetMax = Vector2.zero;
component.anchoredPosition = Vector2.zero;
ContentSizeFitter component2 = ((Component)val7).gameObject.GetComponent<ContentSizeFitter>();
if ((Object)(object)component2 != (Object)null)
{
((Behaviour)component2).enabled = false;
}
TMP_Text text2 = ((PeakLocalizableElement)val7).Text;
text2.text = text;
text2.fontSize = 28f;
text2.alignment = (TextAlignmentOptions)514;
text2.textWrappingMode = (TextWrappingModes)0;
((Graphic)text2).color = CloseBarText;
text2.margin = Vector4.zero;
RectTransform component3 = ((Component)text2).GetComponent<RectTransform>();
component3.anchorMin = new Vector2(0f, 0f);
component3.anchorMax = new Vector2(1f, 1f);
component3.pivot = new Vector2(0.5f, 0.5f);
component3.offsetMin = Vector2.zero;
component3.offsetMax = Vector2.zero;
component3.anchoredPosition = Vector2.zero;
ContentSizeFitter component4 = ((Component)text2).gameObject.GetComponent<ContentSizeFitter>();
if ((Object)(object)component4 != (Object)null)
{
((Behaviour)component4).enabled = false;
}
((UnityEvent)val6.onClick).AddListener((UnityAction)delegate
{
RunUiActionThrottled("Close", delegate
{
onClick2();
});
});
}
}
public sealed class PeakMenuSkin
{
private readonly ManualLogSource _log;
public Rect MenuRect = new Rect(24f, 80f, 520f, 520f);
public string WindowTitle = "";
private static readonly Color32 CWindow = new Color32((byte)22, (byte)22, (byte)26, byte.MaxValue);
private static readonly Color32 CPanel = new Color32((byte)30, (byte)30, (byte)36, byte.MaxValue);
private static readonly Color32 CBorder = new Color32((byte)70, (byte)70, (byte)84, byte.MaxValue);
private static readonly Color32 CText = new Color32((byte)235, (byte)235, (byte)240, byte.MaxValue);
private static readonly Color32 CTextDim = new Color32((byte)190, (byte)190, (byte)200, byte.MaxValue);
private static readonly Color32 CBtn = new Color32((byte)48, (byte)48, (byte)58, byte.MaxValue);
private static readonly Color32 CBtnHover = new Color32((byte)62, (byte)62, (byte)76, byte.MaxValue);
private static readonly Color32 CBtnActive = new Color32((byte)80, (byte)80, (byte)98, byte.MaxValue);
private bool _ready;
private Font? _uiFont;
private Texture2D? _texWindow;
private Texture2D? _texPanel;
private Texture2D? _texBtn;
private Texture2D? _texBtnHover;
private Texture2D? _texBtnActive;
private GUIStyle? _windowStyle;
private GUIStyle? _panelStyle;
private GUIStyle? _labelStyle;
private GUIStyle? _labelDimStyle;
private GUIStyle? _toggleStyle;
private GUIStyle? _buttonStyle;
private GUIStyle? _smallButtonStyle;
private GUIStyle? _sectionHeaderStyle;
public GUIStyle WindowStyle => _windowStyle;
public GUIStyle PanelStyle => _panelStyle;
public GUIStyle LabelStyle => _labelStyle;
public GUIStyle LabelDimStyle => _labelDimStyle;
public GUIStyle ToggleStyle => _toggleStyle;
public GUIStyle ButtonStyle => _buttonStyle;
public GUIStyle SmallButtonStyle => _smallButtonStyle;
public GUIStyle SectionHeaderStyle => _sectionHeaderStyle;
public PeakMenuSkin(ManualLogSource log)
{
//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)
_log = log;
}
public void EnsureStyles()
{
//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_002a: Unknown result type (might be due to invalid IL or missing references)
//IL_002f: Unknown result type (might be due to invalid IL or missing references)
//IL_003f: Unknown result type (might be due to invalid IL or missing references)
//IL_0044: Unknown result type (might be due to invalid IL or missing references)
//IL_0054: Unknown result type (might be due to invalid IL or missing references)
//IL_0059: 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_006e: 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_008d: Unknown result type (might be due to invalid IL or missing references)
//IL_0099: Unknown result type (might be due to invalid IL or missing references)
//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
//IL_00f6: Expected O, but got Unknown
//IL_00fb: Expected O, but got Unknown
//IL_0105: Unknown result type (might be due to invalid IL or missing references)
//IL_010f: Expected O, but got Unknown
//IL_011a: Unknown result type (might be due to invalid IL or missing references)
//IL_011f: Unknown result type (might be due to invalid IL or missing references)
//IL_012b: Unknown result type (might be due to invalid IL or missing references)
//IL_0133: Unknown result type (might be due to invalid IL or missing references)
//IL_0144: Unknown result type (might be due to invalid IL or missing references)
//IL_014a: Unknown result type (might be due to invalid IL or missing references)
//IL_014f: Unknown result type (might be due to invalid IL or missing references)
//IL_0159: Unknown result type (might be due to invalid IL or missing references)
//IL_0162: Unknown result type (might be due to invalid IL or missing references)
//IL_016c: Expected O, but got Unknown
//IL_016c: Unknown result type (might be due to invalid IL or missing references)
//IL_0171: Unknown result type (might be due to invalid IL or missing references)
//IL_017b: Expected O, but got Unknown
//IL_0180: Expected O, but got Unknown
//IL_018b: Unknown result type (might be due to invalid IL or missing references)
//IL_0190: Unknown result type (might be due to invalid IL or missing references)
//IL_019c: Unknown result type (might be due to invalid IL or missing references)
//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
//IL_01af: Unknown result type (might be due to invalid IL or missing references)
//IL_01be: Expected O, but got Unknown
//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
//IL_01e4: Expected O, but got Unknown
//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
//IL_01ff: Unknown result type (might be due to invalid IL or missing references)
//IL_0205: Unknown result type (might be due to invalid IL or missing references)
//IL_020a: Unknown result type (might be due to invalid IL or missing references)
//IL_0214: Unknown result type (might be due to invalid IL or missing references)
//IL_0219: Unknown result type (might be due to invalid IL or missing references)
//IL_0223: Expected O, but got Unknown
//IL_0228: Expected O, but got Unknown
//IL_0233: Unknown result type (might be due to invalid IL or missing references)
//IL_0238: Unknown result type (might be due to invalid IL or missing references)
//IL_0244: Unknown result type (might be due to invalid IL or missing references)
//IL_024c: Unknown result type (might be due to invalid IL or missing references)
//IL_025d: Unknown result type (might be due to invalid IL or missing references)
//IL_0263: Unknown result type (might be due to invalid IL or missing references)
//IL_026d: Unknown result type (might be due to invalid IL or missing references)
//IL_027e: Unknown result type (might be due to invalid IL or missing references)
//IL_0284: Unknown result type (might be due to invalid IL or missing references)
//IL_028e: Unknown result type (might be due to invalid IL or missing references)
//IL_029f: Unknown result type (might be due to invalid IL or missing references)
//IL_02a5: Unknown result type (might be due to invalid IL or missing references)
//IL_02af: Unknown result type (might be due to invalid IL or missing references)
//IL_02b8: Unknown result type (might be due to invalid IL or missing references)
//IL_02c2: Expected O, but got Unknown
//IL_02c7: Expected O, but got Unknown
//IL_02ce: Unknown result type (might be due to invalid IL or missing references)
//IL_02d3: Unknown result type (might be due to invalid IL or missing references)
//IL_02db: Unknown result type (might be due to invalid IL or missing references)
//IL_02e2: Unknown result type (might be due to invalid IL or missing references)
//IL_02ec: Expected O, but got Unknown
//IL_02f1: Expected O, but got Unknown
//IL_02fc: Unknown result type (might be due to invalid IL or missing references)
//IL_0301: Unknown result type (might be due to invalid IL or missing references)
//IL_030d: Unknown result type (might be due to invalid IL or missing references)
//IL_0315: Unknown result type (might be due to invalid IL or missing references)
//IL_031b: Unknown result type (might be due to invalid IL or missing references)
//IL_0320: Unknown result type (might be due to invalid IL or missing references)
//IL_032a: Unknown result type (might be due to invalid IL or missing references)
//IL_0330: Unknown result type (might be due to invalid IL or missing references)
//IL_0335: Unknown result type (might be due to invalid IL or missing references)
//IL_033f: Unknown result type (might be due to invalid IL or missing references)
//IL_0345: Unknown result type (might be due to invalid IL or missing references)
//IL_034f: Expected O, but got Unknown
//IL_0354: Expected O, but got Unknown
if (!_ready)
{
_uiFont = TryFindNiceFont();
_texWindow = MakeSolid(Color32.op_Implicit(CWindow));
_texPanel = MakeSolid(Color32.op_Implicit(CPanel));
_texBtn = MakeSolid(Color32.op_Implicit(CBtn));
_texBtnHover = MakeSolid(Color32.op_Implicit(CBtnHover));
_texBtnActive = MakeSolid(Color32.op_Implicit(CBtnActive));
GUIStyle val = new GUIStyle(GUI.skin.window)
{
font = _uiFont,
fontSize = 16
};
val.normal.background = _texWindow;
val.normal.textColor = Color.white;
val.onNormal.background = _texWindow;
val.onNormal.textColor = Color.white;
val.padding = new RectOffset(14, 14, 12, 12);
_windowStyle = val;
_windowStyle.border = new RectOffset(6, 6, 6, 6);
GUIStyle val2 = new GUIStyle(GUI.skin.box)
{
font = _uiFont,
fontSize = 14
};
val2.normal.background = _texPanel;
val2.normal.textColor = ToColor(CText);
val2.padding = new RectOffset(14, 14, 12, 12);
val2.margin = new RectOffset(0, 0, 0, 0);
_panelStyle = val2;
GUIStyle val3 = new GUIStyle(GUI.skin.label)
{
font = _uiFont,
fontSize = 14
};
val3.normal.textColor = ToColor(CText);
_labelStyle = val3;
GUIStyle val4 = new GUIStyle(_labelStyle);
val4.normal.textColor = ToColor(CTextDim);
_labelDimStyle = val4;
GUIStyle val5 = new GUIStyle(_labelStyle)
{
fontSize = 12,
fontStyle = (FontStyle)1
};
val5.normal.textColor = ToColor(CTextDim);
val5.margin = new RectOffset(0, 0, 8, 2);
_sectionHeaderStyle = val5;
GUIStyle val6 = new GUIStyle(GUI.skin.button)
{
font = _uiFont,
fontSize = 14
};
val6.normal.background = _texBtn;
val6.normal.textColor = Color.white;
val6.hover.background = _texBtnHover;
val6.hover.textColor = Color.white;
val6.active.background = _texBtnActive;
val6.active.textColor = Color.white;
val6.padding = new RectOffset(12, 12, 9, 9);
_buttonStyle = val6;
_smallButtonStyle = new GUIStyle(_buttonStyle)
{
fontSize = 13,
padding = new RectOffset(10, 10, 7, 7)
};
GUIStyle val7 = new GUIStyle(GUI.skin.toggle)
{
font = _uiFont,
fontSize = 14
};
val7.normal.textColor = ToColor(CText);
val7.onNormal.textColor = ToColor(CText);
val7.padding = new RectOffset(20, 0, 0, 0);
_toggleStyle = val7;
_ready = true;
_log.LogInfo((object)$"[PeakMenuSkin] IMGUI styles ready. Using customFont={(Object)(object)_uiFont != (Object)null}");
}
}
public void DrawBorderedBox(Rect r)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
//IL_003c: Unknown result type (might be due to invalid IL or missing references)
//IL_0075: Unknown result type (might be due to invalid IL or missing references)
//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
Texture2D val = MakeSolid(Color32.op_Implicit(CBorder));
GUI.DrawTexture(new Rect(((Rect)(ref r)).x - 1f, ((Rect)(ref r)).y - 1f, ((Rect)(ref r)).width + 2f, 1f), (Texture)(object)val);
GUI.DrawTexture(new Rect(((Rect)(ref r)).x - 1f, ((Rect)(ref r)).y + ((Rect)(ref r)).height, ((Rect)(ref r)).width + 2f, 1f), (Texture)(object)val);
GUI.DrawTexture(new Rect(((Rect)(ref r)).x - 1f, ((Rect)(ref r)).y, 1f, ((Rect)(ref r)).height), (Texture)(object)val);
GUI.DrawTexture(new Rect(((Rect)(ref r)).x + ((Rect)(ref r)).width, ((Rect)(ref r)).y, 1f, ((Rect)(ref r)).height), (Texture)(object)val);
}
private static Texture2D MakeSolid(Color c)
{
//IL_0004: Unknown result type (might be due to invalid IL or missing references)
//IL_000a: Expected O, but got Unknown
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
Texture2D val = new Texture2D(1, 1, (TextureFormat)4, false);
val.SetPixel(0, 0, c);
val.Apply(false, true);
return val;
}
private static Color ToColor(Color32 c)
{
//IL_0000: 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_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_0027: Unknown result type (might be due to invalid IL or missing references)
//IL_0034: Unknown result type (might be due to invalid IL or missing references)
return new Color((float)(int)c.r / 255f, (float)(int)c.g / 255f, (float)(int)c.b / 255f, (float)(int)c.a / 255f);
}
private static Font? TryFindNiceFont()
{
try
{
Font[] array = Resources.FindObjectsOfTypeAll<Font>();
if (array == null || array.Length == 0)
{
return null;
}
Font result = null;
int num = int.MinValue;
Font[] array2 = array;
foreach (Font val in array2)
{
if (!((Object)(object)val == (Object)null))
{
string text = ((Object)val).name ?? "";
int num2 = 0;
if (text.IndexOf("Arial", StringComparison.OrdinalIgnoreCase) >= 0)
{
num2 -= 50;
}
if (text.IndexOf("UI", StringComparison.OrdinalIgnoreCase) >= 0)
{
num2 += 30;
}
if (text.IndexOf("Menu", StringComparison.OrdinalIgnoreCase) >= 0)
{
num2 += 15;
}
if (text.IndexOf("Bold", StringComparison.OrdinalIgnoreCase) >= 0)
{
num2 += 5;
}
if (!val.dynamic)
{
num2 += 5;
}
if (num2 > num)
{
num = num2;
result = val;
}
}
}
return result;
}
catch
{
return null;
}
}
}
public sealed class PeakMenuView
{
public readonly struct Actions
{
public readonly Action onClose;
public readonly Action onApplyPoison;
public readonly Action onApplyCold;
public readonly Action onApplyHot;
public readonly Action onApplyHunger;
public Actions(Action onClose, Action onApplyPoison, Action onApplyCold, Action onApplyHot, Action onApplyHunger)
{
this.onClose = onClose;
this.onApplyPoison = onApplyPoison;
this.onApplyCold = onApplyCold;
this.onApplyHot = onApplyHot;
this.onApplyHunger = onApplyHunger;
}
}
private readonly PeakMenuSkin _skin;
private readonly ModConfig _cfg;
private readonly Actions _a;
private Vector2 _scroll;
private readonly int _windowId;
public PeakMenuView(PeakMenuSkin skin, ModConfig cfg, Actions actions)
{
//IL_002c: Unknown result type (might be due to invalid IL or missing references)
//IL_0031: Unknown result type (might be due to invalid IL or missing references)
_skin = skin;
_cfg = cfg;
_a = actions;
_windowId = "PeakTuner.Window".GetHashCode();
_scroll = Vector2.zero;
}
public void Draw()
{
//IL_0017: 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)
//IL_0021: 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_003e: Unknown result type (might be due to invalid IL or missing references)
//IL_005e: Expected O, but got Unknown
//IL_0059: Unknown result type (might be due to invalid IL or missing references)
_skin.EnsureStyles();
_skin.MenuRect = ClampToScreen(_skin.MenuRect);
GUI.Window(_windowId, _skin.MenuRect, new WindowFunction(DrawWindowContents), _skin.WindowTitle, _skin.WindowStyle);
}
private void DrawWindowContents(int id)
{
//IL_0043: 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_0062: Unknown result type (might be due to invalid IL or missing references)
//IL_020d: Unknown result type (might be due to invalid IL or missing references)
Rect val = default(Rect);
((Rect)(ref val))..ctor(10f, 28f, ((Rect)(ref _skin.MenuRect)).width - 20f, ((Rect)(ref _skin.MenuRect)).height - 38f);
_skin.DrawBorderedBox(val);
GUILayout.BeginArea(val);
_scroll = GUILayout.BeginScrollView(_scroll, false, true, Array.Empty<GUILayoutOption>());
GUILayout.BeginVertical(_skin.PanelStyle, Array.Empty<GUILayoutOption>());
ToggleEntry(_cfg.InfiniteStamina, "Infinite Stamina");
ToggleEntry(_cfg.NoFallDamage, "No Fall Damage");
ToggleEntry(_cfg.DisableCold, "Disable Cold");
ToggleEntry(_cfg.DisablePoison, "Disable Poison");
ToggleEntry(_cfg.DisableHot, "Disable Hot");
ToggleEntry(_cfg.DisableHunger, "Disable Hunger");
ToggleEntry(_cfg.GodMode, "God Mode");
GUILayout.Space(12f);
GUILayout.Label("Status effects", _skin.SectionHeaderStyle, Array.Empty<GUILayoutOption>());
if (GUILayout.Button("Apply Poison", _skin.ButtonStyle, Array.Empty<GUILayoutOption>()))
{
_a.onApplyPoison();
}
if (GUILayout.Button("Apply Cold", _skin.ButtonStyle, Array.Empty<GUILayoutOption>()))
{
_a.onApplyCold();
}
if (GUILayout.Button("Apply Hot", _skin.ButtonStyle, Array.Empty<GUILayoutOption>()))
{
_a.onApplyHot();
}
if (GUILayout.Button("Apply Hunger", _skin.ButtonStyle, Array.Empty<GUILayoutOption>()))
{
_a.onApplyHunger();
}
GUILayout.EndVertical();
GUILayout.EndScrollView();
GUILayout.EndArea();
GUI.DragWindow(new Rect(0f, 0f, 10000f, 24f));
}
private void ToggleEntry(ConfigEntry<bool> entry, string label)
{
bool value = entry.Value;
bool flag = GUILayout.Toggle(value, label, _skin.ToggleStyle, Array.Empty<GUILayoutOption>());
if (flag != value)
{
entry.Value = flag;
}
}
private static Rect ClampToScreen(Rect r)
{
//IL_0064: Unknown result type (might be due to invalid IL or missing references)
float num = Mathf.Clamp(((Rect)(ref r)).x, 0f, Mathf.Max(0f, (float)Screen.width - ((Rect)(ref r)).width));
float num2 = Mathf.Clamp(((Rect)(ref r)).y, 0f, Mathf.Max(0f, (float)Screen.height - ((Rect)(ref r)).height));
return new Rect(num, num2, ((Rect)(ref r)).width, ((Rect)(ref r)).height);
}
}
}
namespace PeakTuner.Cheats
{
public sealed class CheatsService
{
private sealed class SpeedTargets
{
private readonly struct Candidate
{
public readonly Component Component;
public readonly MemberInfo Member;
public readonly int Score;
public readonly bool IsMultiplier;
public readonly bool IsClimb;
public readonly float BaseValue;
public static Candidate None => new Candidate(null, null, int.MinValue, isMultiplier: false, isClimb: false, 1f);
public Candidate(Component component, MemberInfo member, int score, bool isMultiplier, bool isClimb, float baseValue)
{
Component = component;
Member = member;
Score = score;
IsMultiplier = isMultiplier;
IsClimb = isClimb;
BaseValue = baseValue;
}
public CachedTarget ToCachedTarget()
{
if (Member == null)
{
return default(CachedTarget);
}
string text = (((Object)(object)Component != (Object)null) ? (((object)Component).GetType().Name ?? "<?>") : "<?>");
string text2 = ((Member != null) ? (Member.Name ?? "<?>") : "<?>");
CachedTarget result = default(CachedTarget);
result.Component = Component;
result.Member = Member;
result.IsMultiplier = IsMultiplier;
result.BaseValue = (IsMultiplier ? 1f : BaseValue);
result.LastSetValue = float.NaN;
result.DebugLabel = text + "." + text2;
return result;
}
}
private struct CachedTarget
{
public Component? Component;
public MemberInfo? Member;
public bool IsMultiplier;
public float BaseValue;
public float LastSetValue;
public string DebugLabel;
}
public float NextProbeTime;
private CachedTarget _move;
private CachedTarget _climb;
private bool _loggedNotFound;
public bool Ready
{
get
{
if (!(_move.Member != null))
{
return _climb.Member != null;
}
return true;
}
}
public void TryCache(ManualLogSource log, Character c)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: Expected O, but got Unknown
//IL_0059: Unknown result type (might be due to invalid IL or missing references)
//IL_0064: Expected O, but got Unknown
try
{
if ((Object)c == (Object)null)
{
_move = default(CachedTarget);
_climb = default(CachedTarget);
return;
}
Component[] componentsInChildren = ((Component)c).GetComponentsInChildren<Component>(true);
if (componentsInChildren == null || componentsInChildren.Length == 0)
{
return;
}
Candidate bestMove = Candidate.None;
Candidate bestClimb = Candidate.None;
foreach (Component val in componentsInChildren)
{
if ((Object)val == (Object)null)
{
continue;
}
Type type = ((object)val).GetType();
string text = (type.Name ?? "").ToLowerInvariant();
if (type == typeof(Transform) || type == typeof(RectTransform))
{
continue;
}
int num = 0;
if (text.Contains("speed"))
{
num += 25;
}
if (text.Contains("movement"))
{
num += 18;
}
if (text.Contains("motor"))
{
num += 18;
}
if (text.Contains("controller"))
{
num += 10;
}
if (text.Contains("camera") || text.Contains("look") || text.Contains("aim"))
{
num -= 60;
}
FieldInfo[] fields = type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
foreach (FieldInfo fieldInfo in fields)
{
if (!(fieldInfo.FieldType != typeof(float)))
{
float? num2 = TryReadFloat(fieldInfo, val);
if (num2.HasValue)
{
ScoreAndMaybeTake(val, fieldInfo, fieldInfo.Name, num2.Value, num, ref bestMove, ref bestClimb);
}
}
}
PropertyInfo[] properties = type.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
foreach (PropertyInfo propertyInfo in properties)
{
if (!(propertyInfo.PropertyType != typeof(float)) && propertyInfo.CanWrite && (propertyInfo.GetIndexParameters() == null || propertyInfo.GetIndexParameters().Length == 0))
{
float? num3 = TryReadFloat(propertyInfo, val);
if (num3.HasValue)
{
ScoreAndMaybeTake(val, propertyInfo, propertyInfo.Name, num3.Value, num, ref bestMove, ref bestClimb);
}
}
}
}
_move = bestMove.ToCachedTarget();
_climb = bestClimb.ToCachedTarget();
if (!Ready)
{
if (!_loggedNotFound)
{
_loggedNotFound = true;
log.LogInfo((object)"[PeakTuner] Speed: could not locate any plausible speed member on the player (will keep retrying).");
}
}
else
{
log.LogInfo((object)("[PeakTuner] Speed: cached move=" + _move.DebugLabel + " climb=" + _climb.DebugLabel));
}
}
catch (Exception ex)
{
log.LogError((object)("[PeakTuner] Speed: cache scan failed: " + ex.GetType().Name));
}
}
public void Apply(ManualLogSource log, Character c, float multiplier)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: Expected O, but got Unknown
try
{
if (!((Object)c == (Object)null))
{
if (_move.Member != null)
{
ApplyOne(log, c, ref _move, multiplier);
}
if (_climb.Member != null)
{
ApplyOne(log, c, ref _climb, multiplier);
}
}
}
catch
{
}
}
private static void ApplyOne(ManualLogSource log, Character c, ref CachedTarget tgt, float m)
{
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_0025: Expected O, but got Unknown
if ((Object)(object)tgt.Component == (Object)null)
{
return;
}
Object component = (Object)(object)tgt.Component;
if (component != null && component == (Object)null)
{
return;
}
float num = (tgt.IsMultiplier ? m : (tgt.BaseValue * m));
if (Mathf.Abs(num - tgt.LastSetValue) < 0.0001f)
{
return;
}
try
{
if (tgt.Member is FieldInfo fieldInfo)
{
fieldInfo.SetValue(tgt.Component, num);
tgt.LastSetValue = num;
}
else if (tgt.Member is PropertyInfo propertyInfo)
{
propertyInfo.SetValue(tgt.Component, num, null);
tgt.LastSetValue = num;
}
}
catch (Exception ex)
{
log.LogInfo((object)("[PeakTuner] Speed: apply failed on " + tgt.DebugLabel + ": " + ex.GetType().Name));
}
}
private static void ScoreAndMaybeTake(Component comp, MemberInfo mi, string memberName, float cur, int typeScoreBias, ref Candidate bestMove, ref Candidate bestClimb)
{
string text = (memberName ?? "").ToLowerInvariant();
if (!float.IsNaN(cur) && !float.IsInfinity(cur) && !(cur < -0.001f) && !(cur > 5000f))
{
int num = typeScoreBias;
bool flag = text.Contains("mult") || text.Contains("multiplier") || text.Contains("scale");
if (text.Contains("speed"))
{
num += 35;
}
if (text.Contains("move"))
{
num += 18;
}
if (text.Contains("walk"))
{
num += 12;
}
if (text.Contains("run"))
{
num += 12;
}
if (text.Contains("sprint"))
{
num += 10;
}
if (text.Contains("velocity"))
{
num += 8;
}
if (flag)
{
num += 60;
}
if (text.Contains("look") || text.Contains("camera") || text.Contains("mouse") || text.Contains("turn") || text.Contains("rotate"))
{
num -= 80;
}
int num2 = num;
int num3 = num;
if (text.Contains("climb"))
{
num3 += 35;
}
if (text.Contains("ladder"))
{
num3 += 18;
}
if (text.Contains("hang"))
{
num3 += 10;
}
if (text.Contains("grip"))
{
num3 += 10;
}
if (!flag && cur >= 0.25f && cur <= 50f)
{
num2 += 5;
}
if (num2 > bestMove.Score && num2 >= 45)
{
bestMove = new Candidate(comp, mi, num2, flag, isClimb: false, cur);
}
if (num3 > bestClimb.Score && num3 >= 55)
{
bestClimb = new Candidate(comp, mi, num3, flag, isClimb: true, cur);
}
}
}
private static float? TryReadFloat(FieldInfo fi, Component comp)
{
try
{
object value = fi.GetValue(comp);
if (value is float)
{
return (float)value;
}
}
catch
{
}
return null;
}
private static float? TryReadFloat(PropertyInfo pi, Component comp)
{
try
{
if (!pi.CanRead)
{
return null;
}
object value = pi.GetValue(comp, null);
if (value is float)
{
return (float)value;
}
}
catch
{
}
return null;
}
}
private readonly ManualLogSource _log;
private readonly ReflectionCache _r;
private readonly StatusApi _status;
private readonly ModConfig _cfg;
private readonly SpeedTargets _speed = new SpeedTargets();
public CheatsService(ManualLogSource log, ReflectionCache r, StatusApi status, ModConfig cfg)
{
_log = log;
_r = r;
_status = status;
_cfg = cfg;
}
public void ApplyCheats()
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0012: Expected O, but got Unknown
//IL_008b: Unknown result type (might be due to invalid IL or missing references)
//IL_0096: Expected O, but got Unknown
Character localCharacter = Character.localCharacter;
if ((Object)localCharacter == (Object)null)
{
return;
}
_r.PiInfiniteStam?.SetValue(localCharacter, _cfg.InfiniteStamina.Value);
_r.PiStatusesLocked?.SetValue(localCharacter, false);
if (_cfg.NoFallDamage.Value && _r.FiFallDamageTime != null)
{
CharacterMovement component = ((Component)localCharacter).GetComponent<CharacterMovement>();
if ((Object)component != (Object)null)
{
_r.FiFallDamageTime.SetValue(component, 999f);
}
}
if (_cfg.DisablePoison.Value)
{
_status.Clear(localCharacter, PeakStatus.Poison);
}
if (_cfg.DisableCold.Value)
{
_status.Clear(localCharacter, PeakStatus.Cold);
}
if (_cfg.DisableHot.Value)
{
_status.Clear(localCharacter, PeakStatus.Hot);
}
if (_cfg.DisableHunger.Value)
{
_status.Clear(localCharacter, PeakStatus.Hunger);
}
ApplyInvincible(localCharacter, _cfg.GodMode.Value);
}
public void ApplyStatus(PeakStatus status, float value)
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0012: Expected O, but got Unknown
Character localCharacter = Character.localCharacter;
if (!((Object)localCharacter == (Object)null) && !_status.Apply(localCharacter, status, value))
{
_log.LogInfo((object)$"[PeakTuner] Apply {status}: failed (enum/method not resolved?)");
}
}
public void DumpAllStatusNames()
{
_status.DumpAllNames();
}
public void DumpCharacterDataMembers()
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0012: Expected O, but got Unknown
Character localCharacter = Character.localCharacter;
if ((Object)localCharacter == (Object)null)
{
_log.LogInfo((object)"[PeakTuner] Dump: local Character is null.");
return;
}
object obj;
try
{
if (_r.FiCharData == null)
{
_r.CacheInvincible();
}
obj = _r.FiCharData?.GetValue(localCharacter);
}
catch (Exception ex)
{
_log.LogInfo((object)("[PeakTuner] Dump: reading Character.data failed: " + ex.GetType().Name));
return;
}
if (obj == null)
{
_log.LogInfo((object)"[PeakTuner] Dump: Character.data is null (or inaccessible).");
return;
}
Type type = obj.GetType();
_log.LogInfo((object)("[PeakTuner] Dump: Character.data type = " + type.FullName));
try
{
FieldInfo[] fields = type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
_log.LogInfo((object)$"[PeakTuner] Dump: data fields ({fields.Length}):");
FieldInfo[] array = fields;
foreach (FieldInfo fieldInfo in array)
{
Type fieldType = fieldInfo.FieldType;
if (fieldType == typeof(int) || fieldType == typeof(float) || fieldType == typeof(bool))
{
object arg = null;
try
{
arg = fieldInfo.GetValue(obj);
}
catch
{
}
_log.LogInfo((object)$"[PeakTuner] FIELD {fieldType.Name} {fieldInfo.Name} = {arg}");
}
else
{
_log.LogInfo((object)("[PeakTuner] FIELD " + fieldType.Name + " " + fieldInfo.Name));
}
}
}
catch (Exception ex2)
{
_log.LogInfo((object)("[PeakTuner] Dump: field enumeration failed: " + ex2.GetType().Name));
}
}
private void ApplyInvincible(Character c, bool enabled)
{
if (!_r.InvincibleReady && Time.time >= _r.NextInvincibleProbeTime)
{
_r.NextInvincibleProbeTime = Time.time + 2f;
_r.CacheInvincible();
}
if (!_r.InvincibleReady || _r.FiCharData == null)
{
return;
}
try
{
object value = _r.FiCharData.GetValue(c);
if (value != null)
{
_r.FiDataIsInvincible?.SetValue(value, enabled);
_r.FiDataIsInvincibleMilk?.SetValue(value, enabled);
_r.FiCharData.SetValue(c, value);
}
}
catch
{
}
}
private void ApplySpeedMultiplier(Character c)
{
float num = _cfg.SpeedMultiplier.Value;
if (num != 1f && num != 2f && num != 4f)
{
num = 1f;
}
if (_speed.Ready || !(Time.time < _speed.NextProbeTime))
{
if (!_speed.Ready)
{
_speed.NextProbeTime = Time.time + 2f;
_speed.TryCache(_log, c);
}
if (_speed.Ready)
{
_speed.Apply(_log, c, num);
}
}
}
}
public enum PeakStatus
{
Injury,
Hunger,
Cold,
Poison,
Crab,
Curse,
Drowsy,
Weight,
Hot,
Thorns,
Spores,
Web
}
public sealed class ReflectionCache
{
private readonly struct Candidate
{
public readonly string Name;
public readonly int Score;
public readonly bool IsMultiplier;
public readonly bool IsClimb;
public readonly FieldInfo? Field;
public readonly PropertyInfo? Property;
public static Candidate None => new Candidate("", 0, isMultiplier: false, isClimb: false, null, null);
public Candidate(string name, int score, bool isMultiplier, bool isClimb)
: this(name, score, isMultiplier, isClimb, null, null)
{
}
private Candidate(string name, int score, bool isMultiplier, bool isClimb, FieldInfo? fi, PropertyInfo? pi)
{
Name = name;
Score = score;
IsMultiplier = isMultiplier;
IsClimb = isClimb;
Field = fi;
Property = pi;
}
public Candidate WithField(FieldInfo fi)
{
return new Candidate(Name, Score, IsMultiplier, IsClimb, fi, null);
}
public Candidate WithProperty(PropertyInfo pi)
{
return new Candidate(Name, Score, IsMultiplier, IsClimb, null, pi);
}
}
private readonly ManualLogSource _log;
private string? _lastSpeedSig;
public PropertyInfo? PiInfiniteStam { get; private set; }
public PropertyInfo? PiStatusesLocked { get; private set; }
public FieldInfo? FiFallDamageTime { get; private set; }
public MethodInfo? MiSetStatus { get; private set; }
public FieldInfo? FiCharData { get; private set; }
public FieldInfo? FiDataIsInvincible { get; private set; }
public FieldInfo? FiDataIsInvincibleMilk { get; private set; }
public bool InvincibleReady { get; private set; }
public Type? StatusEnumType { get; private set; }
public Array? StatusEnumValues { get; private set; }
public float NextInvincibleProbeTime { get; set; }
public FieldInfo? FiMoveSpeed { get; private set; }
public PropertyInfo? PiMoveSpeed { get; private set; }
public bool MoveIsMultiplier { get; private set; }
public FieldInfo? FiClimbSpeed { get; private set; }
public PropertyInfo? PiClimbSpeed { get; private set; }
public bool ClimbIsMultiplier { get; private set; }
public FieldInfo? FiDataMoveSpeed { get; private set; }
public PropertyInfo? PiDataMoveSpeed { get; private set; }
public bool DataMoveIsMultiplier { get; private set; }
public bool SpeedReady { get; private set; }
public float NextSpeedProbeTime { get; set; }
public ReflectionCache(ManualLogSource log)
{
_log = log;
Cache();
}
public void Cache()
{
try
{
PiInfiniteStam = typeof(Character).GetProperty("infiniteStam", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
PiStatusesLocked = typeof(Character).GetProperty("statusesLocked", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
FiFallDamageTime = typeof(CharacterMovement).GetField("fallDamageTime", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
MiSetStatus = typeof(CharacterAfflictions).GetMethod("SetStatus", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
StatusEnumType = null;
StatusEnumValues = null;
if (MiSetStatus != null)
{
ParameterInfo[] parameters = MiSetStatus.GetParameters();
if (parameters.Length >= 1 && parameters[0].ParameterType.IsEnum)
{
StatusEnumType = parameters[0].ParameterType;
StatusEnumValues = Enum.GetValues(StatusEnumType);
}
}
_log.LogInfo((object)("[PeakTuner] Reflection cached: " + $"infiniteStam={PiInfiniteStam != null}, " + $"statusesLocked={PiStatusesLocked != null}, " + $"fallDamageTime={FiFallDamageTime != null}, " + $"SetStatus={MiSetStatus != null}, " + $"statusEnumFound={StatusEnumType != null}"));
}
catch (Exception arg)
{
_log.LogWarning((object)$"[PeakTuner] Reflection cache failed: {arg}");
}
CacheInvincible();
CacheMovementSpeed();
}
public void CacheInvincible()
{
InvincibleReady = false;
try
{
FiCharData = typeof(Character).GetField("data", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
if (FiCharData == null)
{
_log.LogInfo((object)"[PeakTuner] GodMode reflection: Character.data not found.");
return;
}
Type fieldType = FiCharData.FieldType;
FiDataIsInvincible = fieldType.GetField("isInvincible", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
FiDataIsInvincibleMilk = fieldType.GetField("isInvincibleMilk", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
InvincibleReady = FiDataIsInvincible != null || FiDataIsInvincibleMilk != null;
_log.LogInfo((object)($"[PeakTuner] GodMode reflection: dataField={FiCharData != null}, " + $"isInvincible={FiDataIsInvincible != null}, isInvincibleMilk={FiDataIsInvincibleMilk != null}, " + $"ready={InvincibleReady}"));
}
catch (Exception arg)
{
_log.LogWarning((object)$"[PeakTuner] CacheInvincibleAccessors failed: {arg}");
InvincibleReady = false;
}
}
public void CacheMovementSpeed()
{
SpeedReady = false;
FiMoveSpeed = null;
PiMoveSpeed = null;
MoveIsMultiplier = false;
FiClimbSpeed = null;
PiClimbSpeed = null;
ClimbIsMultiplier = false;
FiDataMoveSpeed = null;
PiDataMoveSpeed = null;
DataMoveIsMultiplier = false;
try
{
Candidate candidate = Candidate.None;
Candidate candidate2 = Candidate.None;
PropertyInfo[] properties = typeof(CharacterMovement).GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
foreach (PropertyInfo propertyInfo in properties)
{
if (propertyInfo == null || !propertyInfo.CanWrite)
{
continue;
}
Type propertyType = propertyInfo.PropertyType;
if (propertyType != typeof(float) && propertyType != typeof(int))
{
continue;
}
Candidate candidate3 = ScoreCandidate(propertyInfo.Name, isProperty: true, propertyType);
if (candidate3.Score <= 0)
{
continue;
}
if (candidate3.IsClimb)
{
if (candidate3.Score > candidate2.Score)
{
candidate2 = candidate3.WithProperty(propertyInfo);
}
}
else if (candidate3.Score > candidate.Score)
{
candidate = candidate3.WithProperty(propertyInfo);
}
}
FieldInfo[] fields = typeof(CharacterMovement).GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
foreach (FieldInfo fieldInfo in fields)
{
if (fieldInfo == null)
{
continue;
}
Type fieldType = fieldInfo.FieldType;
if (fieldType != typeof(float) && fieldType != typeof(int))
{
continue;
}
Candidate candidate4 = ScoreCandidate(fieldInfo.Name, isProperty: false, fieldType);
if (candidate4.Score <= 0)
{
continue;
}
if (candidate4.IsClimb)
{
if (candidate4.Score > candidate2.Score)
{
candidate2 = candidate4.WithField(fieldInfo);
}
}
else if (candidate4.Score > candidate.Score)
{
candidate = candidate4.WithField(fieldInfo);
}
}
if (candidate.Score > 0)
{
FiMoveSpeed = candidate.Field;
PiMoveSpeed = candidate.Property;
MoveIsMultiplier = candidate.IsMultiplier;
}
if (candidate2.Score > 0)
{
FiClimbSpeed = candidate2.Field;
PiClimbSpeed = candidate2.Property;
ClimbIsMultiplier = candidate2.IsMultiplier;
}
try
{
if (FiCharData == null)
{
FiCharData = typeof(Character).GetField("data", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
}
if (FiCharData != null)
{
Type fieldType2 = FiCharData.FieldType;
Candidate candidate5 = Candidate.None;
PropertyInfo[] properties2 = fieldType2.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
foreach (PropertyInfo propertyInfo2 in properties2)
{
if (propertyInfo2 == null || !propertyInfo2.CanWrite)
{
continue;
}
Type propertyType2 = propertyInfo2.PropertyType;
if (!(propertyType2 != typeof(float)) || !(propertyType2 != typeof(int)))
{
Candidate candidate6 = ScoreCandidate(propertyInfo2.Name, isProperty: true, propertyType2, forData: true);
if (candidate6.Score > candidate5.Score)
{
candidate5 = candidate6.WithProperty(propertyInfo2);
}
}
}
FieldInfo[] fields2 = fieldType2.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
foreach (FieldInfo fieldInfo2 in fields2)
{
if (fieldInfo2 == null)
{
continue;
}
Type fieldType3 = fieldInfo2.FieldType;
if (!(fieldType3 != typeof(float)) || !(fieldType3 != typeof(int)))
{
Candidate candidate7 = ScoreCandidate(fieldInfo2.Name, isProperty: false, fieldType3, forData: true);
if (candidate7.Score > candidate5.Score)
{
candidate5 = candidate7.WithField(fieldInfo2);
}
}
}
if (candidate5.Score > 0)
{
FiDataMoveSpeed = candidate5.Field;
PiDataMoveSpeed = candidate5.Property;
DataMoveIsMultiplier = candidate5.IsMultiplier;
}
}
}
catch
{
}
SpeedReady = PiMoveSpeed != null || FiMoveSpeed != null || PiClimbSpeed != null || FiClimbSpeed != null || PiDataMoveSpeed != null || FiDataMoveSpeed != null;
string text = ((PiMoveSpeed != null) ? PiMoveSpeed.Name : ((FiMoveSpeed != null) ? FiMoveSpeed.Name : "null"));
string text2 = ((PiClimbSpeed != null) ? PiClimbSpeed.Name : ((FiClimbSpeed != null) ? FiClimbSpeed.Name : "null"));
string text3 = ((PiDataMoveSpeed != null) ? PiDataMoveSpeed.Name : ((FiDataMoveSpeed != null) ? FiDataMoveSpeed.Name : "null"));
string text4 = "move=" + text + "(" + (MoveIsMultiplier ? "mult" : "abs") + "),climb=" + text2 + "(" + (ClimbIsMultiplier ? "mult" : "abs") + "),data=" + text3 + "(" + (DataMoveIsMultiplier ? "mult" : "abs") + ")," + $"ready={SpeedReady}";
if (_lastSpeedSig != text4)
{
_lastSpeedSig = text4;
_log.LogInfo((object)("[PeakTuner] Speed reflection: " + text4));
}
}
catch (Exception ex)
{
SpeedReady = false;
string text5 = "exception:" + ex.GetType().Name;
if (_lastSpeedSig != text5)
{
_lastSpeedSig = text5;
_log.LogWarning((object)("[PeakTuner] CacheMovementSpeed failed: " + ex.GetType().Name));
}
}
}
private static Candidate ScoreCandidate(string? name, bool isProperty, Type memberType, bool forData = false)
{
string text = name ?? "";
string text2 = text.ToLowerInvariant();
bool flag = text2.IndexOf("speed", StringComparison.Ordinal) >= 0 || text2.EndsWith("spd", StringComparison.Ordinal);
bool flag2 = text2.IndexOf("move", StringComparison.Ordinal) >= 0 || text2.IndexOf("walk", StringComparison.Ordinal) >= 0 || text2.IndexOf("run", StringComparison.Ordinal) >= 0 || text2.IndexOf("sprint", StringComparison.Ordinal) >= 0;
bool flag3 = text2.IndexOf("climb", StringComparison.Ordinal) >= 0 || text2.IndexOf("climbing", StringComparison.Ordinal) >= 0;
bool flag4 = text2.IndexOf("mult", StringComparison.Ordinal) >= 0 || text2.IndexOf("multiplier", StringComparison.Ordinal) >= 0 || text2.IndexOf("factor", StringComparison.Ordinal) >= 0 || text2.IndexOf("scale", StringComparison.Ordinal) >= 0;
if (!flag && !flag4)
{
return Candidate.None;
}
int num = 0;
if (text2.IndexOf("lerp", StringComparison.Ordinal) >= 0)
{
num += 10;
}
if (text2.IndexOf("smooth", StringComparison.Ordinal) >= 0)
{
num += 10;
}
if (text2.IndexOf("accel", StringComparison.Ordinal) >= 0)
{
num += 10;
}
if (text2.IndexOf("damp", StringComparison.Ordinal) >= 0)
{
num += 10;
}
if (text2.IndexOf("drag", StringComparison.Ordinal) >= 0)
{
num += 10;
}
if (text2.IndexOf("friction", StringComparison.Ordinal) >= 0)
{
num += 10;
}
if (text2.IndexOf("curve", StringComparison.Ordinal) >= 0)
{
num += 10;
}
if (text2.IndexOf("time", StringComparison.Ordinal) >= 0)
{
num += 6;
}
int num2 = 0;
if (flag)
{
num2 += 20;
}
if (flag2)
{
num2 += 10;
}
if (flag3)
{
num2 += 15;
}
if (text2.IndexOf("max", StringComparison.Ordinal) >= 0)
{
num2 += 5;
}
if (flag4)
{
num2 += 18;
}
if (forData && !flag4)
{
return Candidate.None;
}
if (memberType == typeof(float))
{
num2 += 2;
}
num2 -= num;
if (num2 < 1)
{
return Candidate.None;
}
return new Candidate(text, num2, flag4, flag3);
}
}
internal static class SpeedController
{
private static ManualLogSource? _log;
private static Harmony? _harmony;
private static ConfigEntry<float>? _speedMultEntry;
private static float _cachedMultiplier = 1f;
private static bool _installed;
private static bool _loggedApplied;
public static void Install(ManualLogSource log, ModConfig cfg)
{
//IL_0061: Unknown result type (might be due to invalid IL or missing references)
//IL_006b: Expected O, but got Unknown
if (_installed)
{
return;
}
_installed = true;
_log = log;
_speedMultEntry = cfg.SpeedMultiplier;
_cachedMultiplier = SanitizeMultiplier(_speedMultEntry.Value);
_speedMultEntry.SettingChanged += delegate
{
try
{
_cachedMultiplier = SanitizeMultiplier(_speedMultEntry.Value);
_loggedApplied = false;
ManualLogSource? log2 = _log;
if (log2 != null)
{
log2.LogInfo((object)$"[PeakTuner] Speed multiplier set to {_cachedMultiplier:0.##}x");
}
}
catch (Exception arg)
{
ManualLogSource? log3 = _log;
if (log3 != null)
{
log3.LogError((object)$"[PeakTuner] Speed config change handler failed: {arg}");
}
}
};
_harmony = new Harmony("com.cbein.peaktuner.speed");
_harmony.PatchAll(typeof(SpeedController));
_log.LogInfo((object)"[PeakTuner] SpeedController installed (CharacterMovement.GetMovementForce patch).");
}
private static float SanitizeMultiplier(float v)
{
if (Mathf.Abs(v - 2f) < 0.01f)
{
return 2f;
}
if (Mathf.Abs(v - 4f) < 0.01f)
{
return 4f;
}
if (Mathf.Abs(v - 8f) < 0.01f)
{
return 8f;
}
if (Mathf.Abs(v - 16f) < 0.01f)
{
return 16f;
}
if (Mathf.Abs(v - 32f) < 0.01f)
{
return 32f;
}
return 1f;
}
private static bool IsGameplayReady()
{
return (Object)(object)Character.localCharacter != (Object)null;
}
[HarmonyPatch(typeof(CharacterMovement), "GetMovementForce")]
[HarmonyPostfix]
private static void CharacterMovement_GetMovementForce_Postfix(ref float ___movementModifier)
{
if (!IsGameplayReady())
{
_loggedApplied = false;
return;
}
float num = (___movementModifier = _cachedMultiplier);
if (!_loggedApplied)
{
_loggedApplied = true;
ManualLogSource? log = _log;
if (log != null)
{
log.LogInfo((object)$"[PeakTuner] Applied movementModifier = {num:0.##}x");
}
}
}
}
public sealed class StatusApi
{
private readonly ManualLogSource _log;
private readonly ReflectionCache _r;
public StatusApi(ManualLogSource log, ReflectionCache r)
{
_log = log;
_r = r;
}
public bool Clear(Character c, PeakStatus status)
{
return Set(c, status, 0f, clear: true);
}
public bool Apply(Character c, PeakStatus status, float value)
{
return Set(c, status, value, clear: false);
}
public void DumpAllNames()
{
if (_r.StatusEnumValues == null)
{
_log.LogInfo((object)"[PeakTuner] Status dump: enum not resolved.");
return;
}
_log.LogInfo((object)$"[PeakTuner] Status dump: ALL status enum names ({_r.StatusEnumValues.Length}):");
foreach (object statusEnumValue in _r.StatusEnumValues)
{
_log.LogInfo((object)$"[PeakTuner] {statusEnumValue}");
}
}
private bool Set(Character c, PeakStatus status, float value, bool clear)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: Expected O, but got Unknown
//IL_003a: Unknown result type (might be due to invalid IL or missing references)
//IL_0045: Expected O, but got Unknown
if ((Object)c == (Object)null)
{
return false;
}
if (_r.MiSetStatus == null || _r.StatusEnumValues == null)
{
return false;
}
CharacterAfflictions component = ((Component)c).GetComponent<CharacterAfflictions>();
if ((Object)component == (Object)null)
{
return false;
}
string b = status.ToString();
object obj = null;
foreach (object statusEnumValue in _r.StatusEnumValues)
{
if (string.Equals(statusEnumValue.ToString(), b, StringComparison.OrdinalIgnoreCase))
{
obj = statusEnumValue;
break;
}
}
if (obj == null)
{
return false;
}
ParameterInfo[] parameters = _r.MiSetStatus.GetParameters();
try
{
if (parameters.Length == 2)
{
object obj2 = ((parameters[1].ParameterType == typeof(float)) ? ((object)(clear ? 0f : value)) : ((parameters[1].ParameterType == typeof(int)) ? ((object)((!clear) ? ((int)Mathf.Round(value)) : 0)) : Activator.CreateInstance(parameters[1].ParameterType)));
_r.MiSetStatus.Invoke(component, new object[2] { obj, obj2 });
return true;
}
if (parameters.Length == 3)
{
object obj3 = ((parameters[1].ParameterType == typeof(float)) ? ((object)(clear ? 0f : value)) : ((parameters[1].ParameterType == typeof(int)) ? ((object)((!clear) ? ((int)Mathf.Round(value)) : 0)) : Activator.CreateInstance(parameters[1].ParameterType)));
object obj4 = ((parameters[2].ParameterType == typeof(bool)) ? ((object)clear) : Activator.CreateInstance(parameters[2].ParameterType));
_r.MiSetStatus.Invoke(component, new object[3] { obj, obj3, obj4 });
return true;
}
}
catch
{
}
return false;
}
}
}
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
internal sealed class IgnoresAccessChecksToAttribute : Attribute
{
public IgnoresAccessChecksToAttribute(string assemblyName)
{
}
}
}