Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of SprintWeightConfig v0.0.2
SprintWeightConfig.dll
Decompiled 2 years agousing System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Reflection; using System.Reflection.Emit; 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 CSync.Extensions; using CSync.Lib; using GameNetcodeStuff; using HarmonyLib; using LethalConfig; using LethalConfig.ConfigItems; using Microsoft.CodeAnalysis; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: IgnoresAccessChecksTo("Assembly-CSharp")] [assembly: IgnoresAccessChecksTo("LethalConfig")] [assembly: IgnoresAccessChecksTo("Unity.Netcode.Runtime")] [assembly: AssemblyCompany("SprintWeightConfig")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyDescription("Allows the sprint speed and stamina regen weight modifiers to be configured. Never get extra tired carrying a V-Engine again!")] [assembly: AssemblyFileVersion("0.0.2.0")] [assembly: AssemblyInformationalVersion("0.0.2")] [assembly: AssemblyProduct("SprintWeightConfig")] [assembly: AssemblyTitle("SprintWeightConfig")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("0.0.2.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.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } namespace SprintWeightConfig { [BepInPlugin("DBJ.SprintWeightConfig", "SprintWeightConfig", "0.0.2")] [BepInDependency("com.sigurd.csync", "5.0.0")] [BepInDependency(/*Could not decode attribute arguments.*/)] public class SprintWeightConfigBase : BaseUnityPlugin { internal const string modGUID = "DBJ.SprintWeightConfig"; internal const string modName = "SprintWeightConfig"; internal const string modVersion = "0.0.2"; internal static ConfigFile configFile; internal static SyncedConfigValues configValues; internal readonly Harmony harmony = new Harmony("DBJ.SprintWeightConfig"); internal static ManualLogSource mls = Logger.CreateLogSource("DBJ.SprintWeightConfig"); private void Awake() { mls.LogInfo((object)"[Awake Log 1 / 3] Initializing SprintWeightConfig..."); configFile = ((BaseUnityPlugin)this).Config; configValues = new SyncedConfigValues(configFile); if (LethalConfigCompat.IsAvailable) { LethalConfigCompat.AddConfigItem(configValues.weightSpeedScalar.Entry); LethalConfigCompat.AddConfigItem(configValues.weightStaminaScalar.Entry); } mls.LogInfo((object)"[Awake Log 2 / 3] Config initialized..."); harmony.PatchAll(); mls.LogInfo((object)"[Awake Log 3 / 3] Patched PlayerControllerB methods!"); } internal static float GetSpeedScalar() { return configValues.weightSpeedScalar.Value; } internal static float GetStaminaScalar() { return configValues.weightStaminaScalar.Value; } } internal class SyncedConfigValues : SyncedConfig2<SyncedConfigValues> { [SyncedEntryField] internal SyncedEntry<float> weightSpeedScalar; [SyncedEntryField] internal SyncedEntry<float> weightStaminaScalar; internal SyncedConfigValues(ConfigFile configFile) : base("DBJ.SprintWeightConfig") { //IL_0032: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Expected O, but got Unknown //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Expected O, but got Unknown //IL_0070: Unknown result type (might be due to invalid IL or missing references) //IL_007f: Expected O, but got Unknown //IL_007a: Unknown result type (might be due to invalid IL or missing references) //IL_0084: Expected O, but got Unknown weightSpeedScalar = SyncedBindingExtensions.BindSyncedEntry<float>(configFile, "Sprinting Weight Scalars", "Sprinting Speed Weight Scalar", 1f, new ConfigDescription("Scales the impact your carry weight has on your sprinting speed. A lower number means your sprinting speed will be less slowed by carry weight; a higher number means it will be more slowed.", (AcceptableValueBase)new AcceptableValueRange<float>(0f, 5f), Array.Empty<object>())); weightStaminaScalar = SyncedBindingExtensions.BindSyncedEntry<float>(configFile, "Sprinting Weight Scalars", "Sprinting Stamina Weight Scalar", 1f, new ConfigDescription("Scales the impact your carry weight has on your stamina regen rate. A lower number means your stamina regen will be less slowed by carry weight; a higher number means it will be more slowed.", (AcceptableValueBase)new AcceptableValueRange<float>(0f, 5f), Array.Empty<object>())); ConfigManager.Register<SyncedConfigValues>((SyncedConfig2<SyncedConfigValues>)this); } } internal static class ILPatcher { internal static MethodInfo GetSpeedScalar; internal static MethodInfo GetStaminaScalar; static ILPatcher() { GetSpeedScalar = typeof(SprintWeightConfigBase).GetMethod("GetSpeedScalar", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy); GetStaminaScalar = typeof(SprintWeightConfigBase).GetMethod("GetStaminaScalar", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy); } public static bool IsLdfld(CodeInstruction instruction, string fieldName = null) { if (instruction.opcode == OpCodes.Ldfld) { if (fieldName != null && instruction.operand is FieldInfo fieldInfo) { string text = fieldInfo.DeclaringType.FullName + "." + fieldInfo.Name; return text == fieldName; } return true; } return false; } public static void AddSpeedScalarInstruction(List<CodeInstruction> instructions, int pos) { //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Expected O, but got Unknown //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Expected O, but got Unknown //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Expected O, but got Unknown //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Expected O, but got Unknown //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_0076: Expected O, but got Unknown //IL_007e: Unknown result type (might be due to invalid IL or missing references) //IL_0088: Expected O, but got Unknown List<CodeInstruction> list = new List<CodeInstruction>(); list.Add(new CodeInstruction(OpCodes.Ldc_R4, (object)1f)); list.Add(new CodeInstruction(OpCodes.Sub, (object)null)); list.Add(new CodeInstruction(OpCodes.Call, (object)GetSpeedScalar)); list.Add(new CodeInstruction(OpCodes.Mul, (object)null)); list.Add(new CodeInstruction(OpCodes.Ldc_R4, (object)1f)); list.Add(new CodeInstruction(OpCodes.Add, (object)null)); instructions.InsertRange(pos, list); } public static void AddStaminaScalarInstruction(List<CodeInstruction> instructions, int pos) { //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Expected O, but got Unknown //IL_0029: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Expected O, but got Unknown //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0049: Expected O, but got Unknown //IL_0051: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Expected O, but got Unknown //IL_006c: Unknown result type (might be due to invalid IL or missing references) //IL_0076: Expected O, but got Unknown //IL_007e: Unknown result type (might be due to invalid IL or missing references) //IL_0088: Expected O, but got Unknown List<CodeInstruction> list = new List<CodeInstruction>(); list.Add(new CodeInstruction(OpCodes.Ldc_R4, (object)1f)); list.Add(new CodeInstruction(OpCodes.Sub, (object)null)); list.Add(new CodeInstruction(OpCodes.Call, (object)GetStaminaScalar)); list.Add(new CodeInstruction(OpCodes.Mul, (object)null)); list.Add(new CodeInstruction(OpCodes.Ldc_R4, (object)1f)); list.Add(new CodeInstruction(OpCodes.Add, (object)null)); instructions.InsertRange(pos, list); } } [HarmonyPatch(typeof(PlayerControllerB))] internal class PlayerControllerBPatch { [HarmonyTranspiler] [HarmonyPatch(typeof(PlayerControllerB), "LateUpdate")] public static IEnumerable<CodeInstruction> PatchLateUpdate(IEnumerable<CodeInstruction> instructions) { SprintWeightConfigBase.mls.LogInfo((object)"Patching PlayerControllerB->LateUpdate..."); List<CodeInstruction> list = new List<CodeInstruction>(instructions); for (int i = 6; i < list.Count; i++) { if (list[i].opcode == OpCodes.Ldfld && list[i].operand.ToString() == "System.Single carryWeight") { ILPatcher.AddStaminaScalarInstruction(list, i + 1); SprintWeightConfigBase.mls.LogInfo((object)"Added Weight Stamina scalar."); break; } } SprintWeightConfigBase.mls.LogInfo((object)"Patched PlayerControllerB->LateUpdate..."); return list.AsEnumerable(); } [HarmonyTranspiler] [HarmonyPatch(typeof(PlayerControllerB), "Update")] public static IEnumerable<CodeInstruction> PatchUpdate(IEnumerable<CodeInstruction> instructions) { SprintWeightConfigBase.mls.LogInfo((object)"Patching PlayerControllerB->Update..."); List<CodeInstruction> list = new List<CodeInstruction>(instructions); for (int i = 0; i < list.Count; i++) { if (ILPatcher.IsLdfld(list[i], "GameNetcodeStuff.PlayerControllerB.carryWeight")) { ILPatcher.AddSpeedScalarInstruction(list, i + 1); SprintWeightConfigBase.mls.LogInfo((object)"Added Weight Speed scalar."); break; } } SprintWeightConfigBase.mls.LogInfo((object)"Patched PlayerControllerB->Update..."); return list.AsEnumerable(); } } internal static class LethalConfigCompat { private const string GUID = "ainavt.lc.lethalconfig"; internal static bool IsAvailable => Chainloader.PluginInfos.ContainsKey("ainavt.lc.lethalconfig"); [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)] internal static void AddConfigItem(ConfigEntry<int> entry, bool isSlider = true, bool restartRequired = false) { //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Expected O, but got Unknown //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Expected O, but got Unknown if (IsAvailable) { if (isSlider) { LethalConfigManager.AddConfigItem((BaseConfigItem)new IntSliderConfigItem(entry, restartRequired)); } else { LethalConfigManager.AddConfigItem((BaseConfigItem)new IntInputFieldConfigItem(entry, restartRequired)); } } } [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)] internal static void AddConfigItem(ConfigEntry<float> entry, bool isSlider = true, bool restartRequired = false) { //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Expected O, but got Unknown //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Expected O, but got Unknown if (IsAvailable) { if (isSlider) { LethalConfigManager.AddConfigItem((BaseConfigItem)new FloatSliderConfigItem(entry, restartRequired)); } else { LethalConfigManager.AddConfigItem((BaseConfigItem)new FloatInputFieldConfigItem(entry, restartRequired)); } } } [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)] internal static void AddConfigItem(ConfigEntry<bool> entry, bool restartRequired = false) { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_001b: Expected O, but got Unknown if (IsAvailable) { LethalConfigManager.AddConfigItem((BaseConfigItem)new BoolCheckBoxConfigItem(entry, restartRequired)); } } [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)] internal static void AddConfigItem(ConfigEntry<string> entry, bool isDropdown = false, bool restartRequired = false) { //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_0032: Expected O, but got Unknown //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Expected O, but got Unknown if (IsAvailable) { if (isDropdown) { LethalConfigManager.AddConfigItem((BaseConfigItem)new TextDropDownConfigItem(entry, restartRequired)); } else { LethalConfigManager.AddConfigItem((BaseConfigItem)new TextInputFieldConfigItem(entry, restartRequired)); } } } [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)] internal static void AddConfigItem(ConfigEntry<Enum> entry, bool restartRequired = false) { if (IsAvailable) { LethalConfigManager.AddConfigItem((BaseConfigItem)(object)new EnumDropDownConfigItem<Enum>(entry, restartRequired)); } } } public static class PluginInfo { public const string PLUGIN_GUID = "SprintWeightConfig"; public const string PLUGIN_NAME = "SprintWeightConfig"; public const string PLUGIN_VERSION = "0.0.2"; } } namespace System.Runtime.CompilerServices { [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)] internal sealed class IgnoresAccessChecksToAttribute : Attribute { public IgnoresAccessChecksToAttribute(string assemblyName) { } } }