using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using EntityStates;
using EntityStates.Croco;
using EntityStates.FalseSon;
using EntityStates.Railgunner.Scope;
using EntityStates.Toolbot;
using EntityStates.VoidSurvivor.Weapon;
using HarmonyLib;
using IL.RoR2.UI;
using Microsoft.CodeAnalysis;
using Mono.Cecil.Cil;
using MonoMod.Cil;
using MonoMod.RuntimeDetour;
using On.RoR2;
using On.RoR2.Skills;
using Rewired;
using RiskOfOptions;
using RiskOfOptions.OptionConfigs;
using RiskOfOptions.Options;
using RoR2;
using RoR2.Skills;
using RoR2BepInExPack.VanillaFixes;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("AutoSprint")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+0768e0c1ca794b373cb95bcaa4304b10ab1a52c9")]
[assembly: AssemblyProduct("AutoSprint")]
[assembly: AssemblyTitle("AutoSprint")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
[module: UnverifiableCode]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace AutoSprint
{
public class AutoSprintManager
{
[CompilerGenerated]
private static class <>O
{
public static Manipulator <0>__CrosshairManager_UpdateCrosshair;
}
internal readonly HashSet<string> stateSprintDisableList = new HashSet<string>();
internal readonly Dictionary<string, FieldInfo> stateAnimationDelayList = new Dictionary<string, FieldInfo>();
public float RT_timer;
public float RT_animationCancelDelay = 0.15f;
public bool RT_animationCancel;
public bool RT_walkToggle;
public static AutoSprintManager Instance { get; private set; }
public static void Init()
{
if (Instance == null)
{
Instance = new AutoSprintManager();
}
}
private AutoSprintManager()
{
//IL_002e: Unknown result type (might be due to invalid IL or missing references)
//IL_0038: Expected O, but got Unknown
//IL_0079: Unknown result type (might be due to invalid IL or missing references)
//IL_0083: Expected O, but got Unknown
//IL_006a: Unknown result type (might be due to invalid IL or missing references)
//IL_0093: Unknown result type (might be due to invalid IL or missing references)
//IL_0098: Unknown result type (might be due to invalid IL or missing references)
//IL_009e: Expected O, but got Unknown
SkillCatalog.Init += new hook_Init(SkillCatalog_Init);
if (FixFrameRateDependantLogic.IsFixedEnabled)
{
new Hook((MethodBase)typeof(PlayerCharacterMasterController).GetMethod("FixedUpdate", (BindingFlags)(-1)), typeof(AutoSprintManager).GetMethod("PlayerCharacterMasterController_FixedUpdate", (BindingFlags)(-1)), (object)this);
}
else
{
PlayerCharacterMasterController.Update += new hook_Update(PlayerCharacterMasterController_Update);
}
object obj = <>O.<0>__CrosshairManager_UpdateCrosshair;
if (obj == null)
{
Manipulator val = CrosshairManager_UpdateCrosshair;
<>O.<0>__CrosshairManager_UpdateCrosshair = val;
obj = (object)val;
}
CrosshairManager.UpdateCrosshair += (Manipulator)obj;
}
private static void CrosshairManager_UpdateCrosshair(ILContext il)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
//IL_0007: Expected O, but got Unknown
ILCursor val2 = new ILCursor(il);
if (val2.TryGotoNext((MoveType)2, new Func<Instruction, bool>[1]
{
(Instruction x) => ILPatternMatchingExt.MatchCallvirt<CharacterBody>(x, "get_isSprinting")
}))
{
val2.EmitDelegate<Func<bool, bool>>((Func<bool, bool>)((bool val) => val && !PluginConfig.DisableSprintingCrosshair.Value));
}
}
private void SkillCatalog_Init(orig_Init orig)
{
orig.Invoke();
foreach (SkillDef allSkillDef in SkillCatalog.allSkillDefs)
{
if (!Object.op_Implicit((Object)(object)allSkillDef) || allSkillDef.forceSprintDuringState || (object)((SerializableEntityStateType)(ref allSkillDef.activationState)).stateType == null)
{
continue;
}
Type stateType = ((SerializableEntityStateType)(ref allSkillDef.activationState)).stateType;
if (allSkillDef.canceledFromSprinting)
{
stateSprintDisableList.Add(stateType.FullName);
}
else if (allSkillDef.cancelSprintingOnActivation && !stateAnimationDelayList.ContainsKey(stateType.FullName))
{
FieldInfo fieldInfo = AccessTools.FindIncludingBaseTypes<FieldInfo>(stateType, (Func<Type, FieldInfo>)((Type t) => t.GetField("duration", AccessTools.all)));
if (fieldInfo != null)
{
stateAnimationDelayList.Add(stateType.FullName, fieldInfo);
}
}
}
stateSprintDisableList.Add(typeof(ToolbotDualWield).FullName);
stateSprintDisableList.Add(typeof(ToolbotDualWieldStart).FullName);
stateSprintDisableList.Add(typeof(ToolbotDualWieldEnd).FullName);
stateAnimationDelayList.Remove(typeof(ToolbotDualWield).FullName);
stateAnimationDelayList.Remove(typeof(ToolbotDualWieldStart).FullName);
stateAnimationDelayList.Remove(typeof(ToolbotDualWieldEnd).FullName);
stateSprintDisableList.Add(typeof(FireNailgun).FullName);
stateAnimationDelayList.Remove(typeof(FireNailgun).FullName);
stateSprintDisableList.Add(typeof(FireCorruptHandBeam).FullName);
stateAnimationDelayList.Remove(typeof(FireCorruptHandBeam).FullName);
stateSprintDisableList.Add(typeof(ActiveScopeHeavy).FullName);
stateSprintDisableList.Add(typeof(ActiveScopeLight).FullName);
stateAnimationDelayList.Remove(typeof(ActiveScopeHeavy).FullName);
stateAnimationDelayList.Remove(typeof(ActiveScopeLight).FullName);
stateAnimationDelayList.Remove(typeof(LaserFather).FullName);
stateSprintDisableList.Remove(typeof(Slash).FullName);
stateSprintDisableList.Remove(typeof(Bite).FullName);
stateAnimationDelayList[typeof(Slash).FullName] = AccessTools.DeclaredField(typeof(Slash), "durationBeforeInterruptable");
stateAnimationDelayList[typeof(Bite).FullName] = AccessTools.DeclaredField(typeof(Bite), "durationBeforeInterruptable");
string value = PluginConfig.DisableSprintingCustomList.Value;
if (!string.IsNullOrEmpty(value))
{
string[] array = value.Replace(" ", string.Empty).Split(',');
foreach (string text in array)
{
stateSprintDisableList.Add(text);
stateAnimationDelayList.Remove(text);
}
}
}
private void PlayerCharacterMasterController_FixedUpdate(Action<PlayerCharacterMasterController> orig, PlayerCharacterMasterController self)
{
orig(self);
LocalUser val = default(LocalUser);
Player inputPlayer = default(Player);
CameraRigController val2 = default(CameraRigController);
bool flag = default(bool);
if (Object.op_Implicit((Object)(object)self.bodyInputs) && Object.op_Implicit((Object)(object)self.body) && PlayerCharacterMasterController.CanSendBodyInput(self.networkUser, ref val, ref inputPlayer, ref val2, ref flag) && !flag)
{
HandleSprint(self.body, inputPlayer, self.bodyInputs);
}
}
private void PlayerCharacterMasterController_Update(orig_Update orig, PlayerCharacterMasterController self)
{
orig.Invoke(self);
LocalUser val = default(LocalUser);
Player inputPlayer = default(Player);
CameraRigController val2 = default(CameraRigController);
bool flag = default(bool);
if (Object.op_Implicit((Object)(object)self.bodyInputs) && Object.op_Implicit((Object)(object)self.body) && PlayerCharacterMasterController.CanSendBodyInput(self.networkUser, ref val, ref inputPlayer, ref val2, ref flag) && !flag)
{
HandleSprint(self.body, inputPlayer, self.bodyInputs);
}
}
private float SprintDelayTime(CharacterBody targetBody)
{
float num = 0f;
EntityStateMachine[] components = ((Component)targetBody).GetComponents<EntityStateMachine>();
for (int i = 0; i < components.Length; i++)
{
EntityState state = components[i].state;
if (state != null && stateAnimationDelayList.TryGetValue(((object)state).ToString(), out var value) && (object)value != null && value.GetValue(state) is float num2)
{
num = Mathf.Max(num, num2);
}
}
return num;
}
private bool ShouldSprintBeDisabledOnThisBody(CharacterBody targetBody)
{
EntityStateMachine[] components = ((Component)targetBody).GetComponents<EntityStateMachine>();
for (int i = 0; i < components.Length; i++)
{
EntityState state = components[i].state;
if (state != null && stateSprintDisableList.Contains(((object)state).ToString()))
{
return true;
}
}
return false;
}
public void HandleSprint(CharacterBody body, Player inputPlayer, InputBankTest bodyInputs)
{
//IL_0145: 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_015f: Unknown result type (might be due to invalid IL or missing references)
//IL_0164: Unknown result type (might be due to invalid IL or missing references)
//IL_0185: Unknown result type (might be due to invalid IL or missing references)
//IL_018c: Unknown result type (might be due to invalid IL or missing references)
//IL_018f: 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)
bool flag = body.isSprinting;
bool flag2 = ShouldSprintBeDisabledOnThisBody(body);
if (!flag)
{
RT_timer += Time.deltaTime;
if ((double)RT_timer >= 0.05)
{
if (!RT_animationCancel)
{
RT_timer = 0f - SprintDelayTime(body);
}
if (RT_timer >= 0f)
{
flag = !flag2;
RT_animationCancel = false;
RT_timer = 0f;
}
}
}
else
{
RT_timer = 0f;
}
if (!PluginConfig.HoldSprintToWalk.Value && inputPlayer.GetButtonDown("Sprint") && !flag2)
{
RT_walkToggle = !RT_walkToggle;
}
else if (inputPlayer.GetButton("Sprint"))
{
if (flag && PluginConfig.HoldSprintToWalk.Value)
{
flag = false;
}
if (!flag && flag2)
{
flag = true;
}
RT_timer = 0f;
}
if (!RT_animationCancel && RT_timer < 0f - RT_animationCancelDelay && !inputPlayer.GetButton("PrimarySkill") && !inputPlayer.GetButton("SecondarySkill") && !inputPlayer.GetButton("SpecialSkill") && !inputPlayer.GetButton("UtilitySkill"))
{
RT_timer = 0f - RT_animationCancelDelay;
RT_animationCancel = true;
}
if (flag)
{
Vector3 aimDirection = bodyInputs.aimDirection;
aimDirection.y = 0f;
((Vector3)(ref aimDirection)).Normalize();
Vector3 moveVector = bodyInputs.moveVector;
moveVector.y = 0f;
((Vector3)(ref moveVector)).Normalize();
if (!PluginConfig.EnableOmniSprint.Value && (body.bodyFlags & 0x20) == 0 && Vector3.Dot(aimDirection, moveVector) < PlayerCharacterMasterController.sprintMinAimMoveDot)
{
flag = false;
}
}
if (PluginConfig.HoldSprintToWalk.Value && RT_walkToggle)
{
RT_walkToggle = false;
}
if (!RT_walkToggle)
{
((ButtonState)(ref bodyInputs.sprint)).PushState(flag);
}
}
}
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInPlugin("com.score.AutoSprint", "AutoSprint", "1.1.1")]
public class AutoSprintPlugin : BaseUnityPlugin
{
public const string PluginGUID = "com.score.AutoSprint";
public const string PluginAuthor = "score";
public const string PluginName = "AutoSprint";
public const string PluginVersion = "1.1.1";
public static bool rooInstalled => Chainloader.PluginInfos.ContainsKey("com.rune580.riskofoptions");
public static AutoSprintPlugin Instance { get; private set; }
public void Awake()
{
Instance = this;
Log.Init(((BaseUnityPlugin)this).Logger);
PluginConfig.Init(((BaseUnityPlugin)this).Config);
AutoSprintManager.Init();
}
}
internal static class Log
{
private static ManualLogSource _logSource;
internal static void Init(ManualLogSource logSource)
{
_logSource = logSource;
}
internal static void Debug(string data)
{
_logSource.LogDebug((object)data);
}
internal static void Error(string data)
{
_logSource.LogError((object)data);
}
internal static void Fatal(string data)
{
_logSource.LogFatal((object)data);
}
internal static void Info(string data)
{
_logSource.LogInfo((object)data);
}
internal static void Message(string data)
{
_logSource.LogMessage((object)data);
}
internal static void Warning(string data)
{
_logSource.LogWarning((object)data);
}
}
internal static class PluginConfig
{
public static ConfigFile myConfig;
public static ConfigEntry<bool> HoldSprintToWalk { get; set; }
public static ConfigEntry<bool> DisableSprintingCrosshair { get; set; }
public static ConfigEntry<string> DisableSprintingCustomList { get; set; }
public static ConfigEntry<bool> EnableOmniSprint { get; set; }
public static void Init(ConfigFile cfg)
{
myConfig = cfg;
HoldSprintToWalk = BindOption("General", "Hold Sprint To Walk", defaultValue: true, "Walk by holding down the sprint key. If disabled, makes the Sprint key toggle AutoSprinting functionality on and off.");
DisableSprintingCrosshair = BindOption("General", "Disable Sprinting Crosshair", defaultValue: true, "Disables the special sprinting chevron crosshair.");
DisableSprintingCustomList = BindOption("General", "Disable Sprint Custom List", "", "Custom EntityState list for when broken things break, separated by commas.\r\nManual Entry -> EntityStates.Character.ExampleState\r\nFrom Code -> typeof(EntityStates.Character.ExampleState).FullName");
EnableOmniSprint = BindOption("General", "Enable OmniSprint", defaultValue: false, "Allows sprinting in all directions. This is generally considered cheating, use with discretion.");
}
[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
public static ConfigEntry<T> BindOption<T>(string section, string name, T defaultValue, string description = "", bool restartRequired = false)
{
if (string.IsNullOrEmpty(description))
{
description = name;
}
if (restartRequired)
{
description += " (restart required)";
}
ConfigEntry<T> val = myConfig.Bind<T>(section, name, defaultValue, description);
if (AutoSprintPlugin.rooInstalled)
{
TryRegisterOption<T>(val, restartRequired);
}
return val;
}
[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
public static ConfigEntry<T> BindOptionSlider<T>(string section, string name, T defaultValue, string description = "", float min = 0f, float max = 20f, bool restartRequired = false)
{
if (string.IsNullOrEmpty(description))
{
description = name;
}
string text = description;
T val = defaultValue;
description = text + " (Default: " + val?.ToString() + ")";
if (restartRequired)
{
description += " (restart required)";
}
ConfigEntry<T> val2 = myConfig.Bind<T>(section, name, defaultValue, description);
if (AutoSprintPlugin.rooInstalled)
{
TryRegisterOptionSlider<T>(val2, min, max, restartRequired);
}
return val2;
}
[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
public static void InitRoO()
{
ModSettingsManager.SetModDescription("Devotion Artifact but better.");
}
[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
public static void TryRegisterOption<T>(ConfigEntry<T> entry, bool restartRequired)
{
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
//IL_0016: Expected O, but got Unknown
//IL_0022: 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_0032: Unknown result type (might be due to invalid IL or missing references)
//IL_003d: Unknown result type (might be due to invalid IL or missing references)
//IL_0048: Unknown result type (might be due to invalid IL or missing references)
//IL_0054: Expected O, but got Unknown
//IL_004f: Unknown result type (might be due to invalid IL or missing references)
//IL_0059: Expected O, but got Unknown
//IL_0066: Unknown result type (might be due to invalid IL or missing references)
//IL_0070: Expected O, but got Unknown
//IL_007d: Unknown result type (might be due to invalid IL or missing references)
//IL_0087: Expected O, but got Unknown
//IL_0097: Unknown result type (might be due to invalid IL or missing references)
//IL_00a1: Expected O, but got Unknown
//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
//IL_00bf: Expected O, but got Unknown
if (entry is ConfigEntry<string> val)
{
ModSettingsManager.AddOption((BaseOption)new StringInputFieldOption(val, restartRequired));
}
else if (entry is ConfigEntry<float> val2)
{
ModSettingsManager.AddOption((BaseOption)new SliderOption(val2, new SliderConfig
{
min = 0f,
max = 20f,
formatString = "{0:0.00}",
restartRequired = restartRequired
}));
}
else if (entry is ConfigEntry<int> val3)
{
ModSettingsManager.AddOption((BaseOption)new IntSliderOption(val3, restartRequired));
}
else if (entry is ConfigEntry<bool> val4)
{
ModSettingsManager.AddOption((BaseOption)new CheckBoxOption(val4, restartRequired));
}
else if (entry is ConfigEntry<KeyboardShortcut> val5)
{
ModSettingsManager.AddOption((BaseOption)new KeyBindOption(val5, restartRequired));
}
else if (typeof(T).IsEnum)
{
ModSettingsManager.AddOption((BaseOption)new ChoiceOption((ConfigEntryBase)(object)entry, restartRequired));
}
}
[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
public static void TryRegisterOptionSlider<T>(ConfigEntry<T> entry, float min, float max, bool restartRequired)
{
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
//IL_0018: Unknown result type (might be due to invalid IL or missing references)
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
//IL_002b: Unknown result type (might be due to invalid IL or missing references)
//IL_0037: Expected O, but got Unknown
//IL_0032: Unknown result type (might be due to invalid IL or missing references)
//IL_003c: Expected O, but got Unknown
//IL_0048: Unknown result type (might be due to invalid IL or missing references)
//IL_004d: 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_005b: Unknown result type (might be due to invalid IL or missing references)
//IL_0066: Unknown result type (might be due to invalid IL or missing references)
//IL_0072: Expected O, but got Unknown
//IL_006d: Unknown result type (might be due to invalid IL or missing references)
//IL_0077: Expected O, but got Unknown
if (entry is ConfigEntry<int> val)
{
ModSettingsManager.AddOption((BaseOption)new IntSliderOption(val, new IntSliderConfig
{
min = (int)min,
max = (int)max,
formatString = "{0:0.00}",
restartRequired = restartRequired
}));
}
else if (entry is ConfigEntry<float> val2)
{
ModSettingsManager.AddOption((BaseOption)new SliderOption(val2, new SliderConfig
{
min = min,
max = max,
formatString = "{0:0.00}",
restartRequired = restartRequired
}));
}
}
}
}