using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using Assets.Scripts.Menu.Shop;
using Assets.Scripts.Utility;
using BepInEx;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using HarmonyLib;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSystem.Collections.Generic;
using MelonLoader;
using Rewired;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("SprintKey")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("SprintKey")]
[assembly: AssemblyCopyright("Copyright © 2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("a052f8b9-b678-40b0-a576-d1c5418579fb")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace SprintKey
{
[BepInPlugin("mike9k1.megabonk.sprintkey", "Simple Sprint Key", "0.0.6")]
public class SprintKey : MelonMod
{
public new const string PLUGIN_GUID = "mike9k1.megabonk.sprintkey";
public new const string PLUGIN_NAME = "Simple Sprint Key";
public new const string PLUGIN_VERSION = "0.0.6";
private string TimerTypeName = "Assets.Scripts.Utility.MyTime";
private string TimerMethodName = "stageTimer";
private string LevelTypeName = "LevelupScreen";
private string LevelMethodName = "Banish";
private string SkipMethodName = "Skip";
private string RefreshTypeName = "PlayerInventory";
private string RefreshMethodName = "Update";
private string ExpTypeName = "Inventory__Items__Pickups.Xp_and_Levels.PlayerXp";
private string ExpMethodName = "AddXp";
private static int newRefreshCount = 2;
private static int xpToRefund = 0;
private static int initialRefreshValue = -1;
private static int lastPlayerLevel = 0;
private static int newPlayerLevel = 0;
private static float sprintStartTime = 0f;
private static float sprintEndTime = 0f;
private static float playerDurationStat = 1f;
private static bool sprintEnabled = false;
private static bool sprintApplied = false;
private static bool banishUsed = false;
private static bool skipUsed = false;
private static bool ps4Controller = false;
private static bool xboxController = false;
private static bool controllerDetected = false;
private static float moveSpeed;
private static float fullSprintDuration;
private static float partialSprintDuration;
private static float modifiedMovementSpeed;
private static float originalMovementSpeed;
private static Dictionary<EStat, float> statDictionary;
private static KeyCode l3Button = (KeyCode)340;
private static KeyCode yButton = (KeyCode)330;
private static LevelupScreen lvlScreen;
private float lastTime;
private static void SprintPostfix(PlayerInventory __instance)
{
if (sprintEnabled && !sprintApplied)
{
statDictionary = __instance.playerStats.stats;
moveSpeed = statDictionary[(EStat)25];
originalMovementSpeed = moveSpeed;
playerDurationStat = statDictionary[(EStat)10];
playerDurationStat = (float)Math.Pow(playerDurationStat, 3.0);
moveSpeed *= 2.25f;
modifiedMovementSpeed = moveSpeed;
statDictionary[(EStat)25] = moveSpeed;
sprintApplied = true;
}
else if (!sprintEnabled && sprintApplied)
{
statDictionary = __instance.playerStats.stats;
moveSpeed = statDictionary[(EStat)25];
playerDurationStat = statDictionary[(EStat)10];
playerDurationStat = (float)Math.Pow(playerDurationStat, 3.0);
if (moveSpeed >= modifiedMovementSpeed)
{
moveSpeed /= 2.25f;
}
else if (!(moveSpeed > originalMovementSpeed))
{
moveSpeed = originalMovementSpeed;
}
statDictionary[(EStat)25] = moveSpeed;
sprintApplied = false;
}
}
private static Type FindType(string fullName)
{
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
foreach (Assembly assembly in assemblies)
{
try
{
Type type = assembly.GetType(fullName, throwOnError: false);
if (type != null)
{
return type;
}
}
catch
{
}
}
return null;
}
private void UpdateRefreshes()
{
Type type = FindType(TimerTypeName);
if (type == null)
{
MelonLogger.Error("Type not found: " + TimerTypeName);
return;
}
PropertyInfo property = type.GetProperty(TimerMethodName);
if (property == null)
{
MelonLogger.Error("Property not found: " + type.FullName + "." + TimerMethodName + "()");
return;
}
float num = (float)property.GetValue(property);
if (num - lastTime >= 60f)
{
newRefreshCount++;
lastTime = num;
}
else if (num < lastTime)
{
lastTime = num;
newRefreshCount = 2;
}
Type type2 = FindType(LevelTypeName);
if (type2 == null)
{
MelonLogger.Error("Type not found: " + LevelTypeName);
return;
}
lvlScreen = Object.FindFirstObjectByType<LevelupScreen>();
if (!((Object)(object)lvlScreen == (Object)null))
{
type2.GetProperty("hasRefreshes").SetValue(lvlScreen, true);
}
}
private void TryPatch()
{
//IL_0094: Unknown result type (might be due to invalid IL or missing references)
//IL_009a: Expected O, but got Unknown
Type type = FindType(RefreshTypeName);
if (type == null)
{
MelonLogger.Error("Type not found: " + RefreshTypeName);
return;
}
MethodInfo method = type.GetMethod(RefreshMethodName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
if (method == null)
{
MelonLogger.Error("Method not found: " + type.FullName + "." + RefreshMethodName + "()");
}
else
{
HarmonyMethod val = new HarmonyMethod(typeof(SprintKey).GetMethod("SprintPostfix", BindingFlags.Static | BindingFlags.NonPublic));
HarmonyInstance.Patch((MethodBase)method, (HarmonyMethod)null, val, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
MelonLogger.Msg("Patched " + type.FullName + "." + RefreshMethodName + "()");
}
}
public override void OnInitializeMelon()
{
TryPatch();
}
public override void OnFixedUpdate()
{
//IL_00ef: 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_007f: 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)
//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
if (!controllerDetected)
{
if (!ReInput.initialized)
{
return;
}
if (((Il2CppArrayBase<string>)(object)Input.GetJoystickNames()).Length == 0)
{
MelonLogger.Msg("No controller detected. Sprint bound to Left Shift on keyboard");
controllerDetected = true;
return;
}
string name = ((Controller)ReInput.players.GetPlayer(0).controllers.Joysticks[0]).name;
if (name.ToLower().Contains("dualshock") || name.ToLower().Contains("dualsense"))
{
ps4Controller = true;
l3Button = (KeyCode)340;
yButton = (KeyCode)330;
MelonLogger.Msg("Playstation controller detected. Sprint bound to L3 and Square");
}
else if (name.ToLower().Contains("xbox"))
{
xboxController = true;
l3Button = (KeyCode)338;
yButton = (KeyCode)332;
MelonLogger.Msg("Xbox controller detected. Sprint bound to LStick and X");
}
else
{
MelonLogger.Msg("Unknown controller detected. Sprint bound to default (Joystick Button #10 & #0)");
}
controllerDetected = true;
return;
}
if (Input.GetKey((KeyCode)304) || Input.GetKey(l3Button) || Input.GetKey(yButton))
{
if (sprintStartTime == 0f && !sprintEnabled)
{
sprintEnabled = true;
sprintStartTime = Time.time;
return;
}
if (Time.time < sprintStartTime + 6f * playerDurationStat)
{
return;
}
if (sprintEnabled)
{
sprintEnabled = false;
sprintEndTime = Time.time;
}
}
else if (sprintEnabled)
{
sprintEnabled = false;
fullSprintDuration = 6f * playerDurationStat;
partialSprintDuration = Time.time - sprintStartTime;
sprintEndTime = Time.time - (fullSprintDuration + 1f) / (partialSprintDuration + 1f);
}
if (Time.time > sprintEndTime + 5f && sprintStartTime != 0f)
{
sprintStartTime = 0f;
}
}
}
}
namespace MelonLoader
{
public class MelonMod : BasePlugin
{
public Harmony HarmonyInstance;
public static MelonMod melonModRef;
public virtual string PLUGIN_GUID => "author.game.modname";
public virtual string PLUGIN_NAME => "Mod Name Here";
public virtual string PLUGIN_VERSION => "0.0.1";
public MelonMod()
{
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_0017: Expected O, but got Unknown
HarmonyInstance = new Harmony(PLUGIN_GUID);
melonModRef = this;
}
public virtual void OnInitializeMelon()
{
}
public virtual void OnLateInitializeMelon()
{
}
public virtual void OnFixedUpdate()
{
}
public virtual void OnUpdate()
{
}
public override void Load()
{
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
//IL_0020: Expected O, but got Unknown
//IL_0059: Unknown result type (might be due to invalid IL or missing references)
//IL_005f: Expected O, but got Unknown
OnInitializeMelon();
HarmonyMethod val = new HarmonyMethod(typeof(MelonMod).GetMethod("FixedUpdate"));
HarmonyInstance.Patch((MethodBase)typeof(MyTime).GetMethod("FixedUpdate"), (HarmonyMethod)null, val, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
HarmonyMethod val2 = new HarmonyMethod(typeof(MelonMod).GetMethod("Update"));
HarmonyInstance.Patch((MethodBase)typeof(MyTime).GetMethod("Update"), (HarmonyMethod)null, val2, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
}
public void Awake()
{
OnLateInitializeMelon();
}
public static void FixedUpdate()
{
melonModRef.OnFixedUpdate();
}
public static void Update()
{
melonModRef.OnUpdate();
}
}
public class MelonLogger
{
private static ManualLogSource log;
private static bool logAdded;
public static void Msg(string message)
{
//IL_0028: Unknown result type (might be due to invalid IL or missing references)
//IL_0032: Expected O, but got Unknown
if (!logAdded)
{
log = new ManualLogSource(((AssemblyTitleAttribute)Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyTitleAttribute), inherit: false)[0]).Title);
Logger.Sources.Add((ILogSource)(object)log);
logAdded = true;
}
log.LogInfo((object)message);
}
public static void Error(string message)
{
//IL_0028: Unknown result type (might be due to invalid IL or missing references)
//IL_0032: Expected O, but got Unknown
if (!logAdded)
{
log = new ManualLogSource(((AssemblyTitleAttribute)Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyTitleAttribute), inherit: false)[0]).Title);
Logger.Sources.Add((ILogSource)(object)log);
logAdded = true;
}
log.LogError((object)message);
}
}
}