using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; 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 GameNetcodeStuff; using HarmonyLib; using Microsoft.CodeAnalysis; using QuotaDependentSpeed.Extensions; using TMPro; using Unity.Netcode; using UnityEngine; using UnityEngine.UI; [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: AssemblyCompany("Tomatobird.QuotaDependentSpeed")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyFileVersion("1.1.0.0")] [assembly: AssemblyInformationalVersion("1.1.0+f2e76d6b0d0a885c9a8dd9545bab2f13e7de4be2")] [assembly: AssemblyProduct("QuotaDependentSpeed")] [assembly: AssemblyTitle("Tomatobird.QuotaDependentSpeed")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.1.0.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 QuotaDependentSpeed { [BepInPlugin("Tomatobird.QuotaDependentSpeed", "QuotaDependentSpeed", "1.1.0")] public class QuotaDependentSpeed : BaseUnityPlugin { public static ConfigEntry quotaBaseValue; public static ConfigEntry quotaEffectScalar; public static ConfigEntry minSpeedMultiplier; public static ConfigEntry maxSpeedMultiplier; public static ConfigEntry inversed; public static ConfigEntry randomSpeed; public static ConfigEntry displayMultiplier; public static float currentRatio; public static QuotaDependentSpeed Instance { get; private set; } internal static ManualLogSource Logger { get; private set; } internal static Harmony? Harmony { get; set; } private void Awake() { Logger = ((BaseUnityPlugin)this).Logger; Instance = this; quotaBaseValue = ((BaseUnityPlugin)this).Config.Bind("General", "QuotaBaseValue", 1000, "The value of quota"); quotaEffectScalar = ((BaseUnityPlugin)this).Config.Bind("General", "QuotaEffectScalar", 0.5f, "How strongly the difference from QuotaBaseValue affects player speed."); minSpeedMultiplier = ((BaseUnityPlugin)this).Config.Bind("General", "MinSpeedMultiplier", 0.01f, "Minimum player speed multiplier."); maxSpeedMultiplier = ((BaseUnityPlugin)this).Config.Bind("General", "MaxSpeedMultiplier", 999f, "Maximum player speed multiplier."); inversed = ((BaseUnityPlugin)this).Config.Bind("General", "Decrease speed", false, "Decrease player speed as quota increases."); randomSpeed = ((BaseUnityPlugin)this).Config.Bind("General", "Random speed", false, "Choose a random speed instead of using the quota to calculate speed. Use min & max speed multipliers to set the limits. Random speed is independent from quota value. Scalar still affects the intensity."); displayMultiplier = ((BaseUnityPlugin)this).Config.Bind("General", "Display multiplier", true, "Should the multiplier be displayed in the HUD during gameplay?"); Patch(); Logger.LogInfo((object)"Tomatobird.QuotaDependentSpeed v1.1.0 has loaded!"); } internal static void Patch() { //IL_000d: Unknown result type (might be due to invalid IL or missing references) //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0018: Expected O, but got Unknown if (Harmony == null) { Harmony = new Harmony("Tomatobird.QuotaDependentSpeed"); } Logger.LogDebug((object)"Patching..."); Harmony.PatchAll(); Logger.LogDebug((object)"Finished patching!"); } internal static void Unpatch() { Logger.LogDebug((object)"Unpatching..."); Harmony? harmony = Harmony; if (harmony != null) { harmony.UnpatchSelf(); } Logger.LogDebug((object)"Finished unpatching!"); } } public static class MyPluginInfo { public const string PLUGIN_GUID = "Tomatobird.QuotaDependentSpeed"; public const string PLUGIN_NAME = "QuotaDependentSpeed"; public const string PLUGIN_VERSION = "1.1.0"; } } namespace QuotaDependentSpeed.Patches { [HarmonyPatch(typeof(NetworkManager))] internal class RegisterNetworkPrefabPatch { private static readonly string MOD_GUID = "Tomatobird.QuotaDependentSpeed"; [HarmonyPatch("SetSingleton")] [HarmonyPostfix] private static void RegisterPrefab() { //IL_0010: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Expected O, but got Unknown //IL_0018: Unknown result type (might be due to invalid IL or missing references) //IL_001f: Unknown result type (might be due to invalid IL or missing references) GameObject val = new GameObject(MOD_GUID + " Prefab"); ((Object)val).hideFlags = (HideFlags)(((Object)val).hideFlags | 0x3D); Object.DontDestroyOnLoad((Object)(object)val); NetworkObject obj = val.AddComponent(); FieldInfo field = typeof(NetworkObject).GetField("GlobalObjectIdHash", BindingFlags.Instance | BindingFlags.NonPublic); field.SetValue(obj, GetHash(MOD_GUID)); NetworkManager.Singleton.PrefabHandler.AddNetworkPrefab(val); static uint GetHash(string value) { return value?.Aggregate(17u, (uint current, char c) => (current * 31) ^ c) ?? 0; } } } [HarmonyPatch] internal class SprintSpeedPatch { private static float value = 1f; private static Dictionary previousPlayerMovementSpeeds = new Dictionary(); private static TextMeshProUGUI? speedDisplay; [HarmonyPatch(typeof(TimeOfDay), "UpdateProfitQuotaCurrentTime")] [HarmonyPostfix] private static void UpdateValue() { //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Expected O, but got Unknown //IL_00a5: 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_00ed: Unknown result type (might be due to invalid IL or missing references) //IL_00ff: Unknown result type (might be due to invalid IL or missing references) //IL_0163: Unknown result type (might be due to invalid IL or missing references) //IL_01b7: Unknown result type (might be due to invalid IL or missing references) //IL_01cb: Unknown result type (might be due to invalid IL or missing references) //IL_01e2: Unknown result type (might be due to invalid IL or missing references) //IL_01ef: Unknown result type (might be due to invalid IL or missing references) //IL_01fc: Unknown result type (might be due to invalid IL or missing references) value = CalculateSpeed(); if (!QuotaDependentSpeed.displayMultiplier.Value) { return; } if ((Object)(object)speedDisplay == (Object)null) { GameObject val = new GameObject("SpeedDisplay"); val.transform.parent = ((TMP_Text)HUDManager.Instance.weightCounter).transform.parent; TextMeshProUGUI weightCounter = HUDManager.Instance.weightCounter; speedDisplay = val.AddComponent(); ((TMP_Text)speedDisplay).textStyle = ((TMP_Text)weightCounter).textStyle; ((Component)speedDisplay).tag = ((Component)weightCounter).tag; ((TMP_Text)speedDisplay).alignment = ((TMP_Text)weightCounter).alignment; ((Graphic)speedDisplay).color = ((Graphic)weightCounter).color; ((TMP_Text)speedDisplay).font = ((TMP_Text)weightCounter).font; ((TMP_Text)speedDisplay).fontSize = ((TMP_Text)weightCounter).fontSize; ((TMP_Text)speedDisplay).fontStyle = ((TMP_Text)weightCounter).fontStyle; ((TMP_Text)speedDisplay).fontWeight = ((TMP_Text)weightCounter).fontWeight; ((TMP_Text)speedDisplay).enableAutoSizing = ((TMP_Text)weightCounter).enableAutoSizing; ((TMP_Text)speedDisplay).fontSizeMin = ((TMP_Text)weightCounter).fontSizeMin; ((TMP_Text)speedDisplay).fontSizeMax = ((TMP_Text)weightCounter).fontSizeMax; ((TMP_Text)speedDisplay).isOverlay = ((TMP_Text)weightCounter).isOverlay; ((TMP_Text)speedDisplay).transform.position = ((TMP_Text)weightCounter).transform.position; ((TMP_Text)speedDisplay).text = "text"; RectTransform component = ((Component)speedDisplay).GetComponent(); if ((Object)(object)component == (Object)null) { QuotaDependentSpeed.Logger.LogError((object)"Transform not found"); return; } component.offsetMin = ((Component)weightCounter).GetComponent().offsetMin; component.offsetMax = ((Component)weightCounter).GetComponent().offsetMax; component.anchoredPosition = new Vector2(67f, -32f); ((Transform)component).localScale = Vector3.one; ((Transform)component).localRotation = Quaternion.identity; } if (!((Object)(object)speedDisplay == (Object)null)) { float num = QuotaDependentSpeed.currentRatio * 100f; string text = ((num >= 1000f) ? num.ToString("F0") : num.ToString("F2")); ((TMP_Text)speedDisplay).text = text + "%"; } } [HarmonyPatch(typeof(PlayerControllerB), "Update")] [HarmonyPrefix] private static void UpdatePrefix(PlayerControllerB __instance, ref bool ___isPlayerControlled, ref float ___movementSpeed) { if (!StartOfRound.Instance.isChallengeFile) { previousPlayerMovementSpeeds[__instance] = ___movementSpeed; if (___isPlayerControlled) { ___movementSpeed *= value; } } } [HarmonyPatch(typeof(PlayerControllerB), "Update")] [HarmonyPostfix] private static void UpdatePostfix(PlayerControllerB __instance, ref bool ___isPlayerControlled, ref float ___movementSpeed) { if (!StartOfRound.Instance.isChallengeFile && previousPlayerMovementSpeeds.ContainsKey(__instance)) { ___movementSpeed = previousPlayerMovementSpeeds[__instance]; } } private static float CalculateSpeed() { float num = 0f; if (QuotaDependentSpeed.randomSpeed.Value) { Random random = new Random(StartOfRound.Instance.randomMapSeed + 1397); num = random.NextFloat(QuotaDependentSpeed.minSpeedMultiplier.Value, QuotaDependentSpeed.maxSpeedMultiplier.Value); return QuotaDependentSpeed.currentRatio = Mathf.Pow(num, QuotaDependentSpeed.quotaEffectScalar.Value); } num = ((!QuotaDependentSpeed.inversed.Value) ? ((float)TimeOfDay.Instance.profitQuota / (float)QuotaDependentSpeed.quotaBaseValue.Value) : ((float)QuotaDependentSpeed.quotaBaseValue.Value / (float)TimeOfDay.Instance.profitQuota)); return Mathf.Clamp(QuotaDependentSpeed.currentRatio = Mathf.Pow(num, QuotaDependentSpeed.quotaEffectScalar.Value), QuotaDependentSpeed.minSpeedMultiplier.Value, QuotaDependentSpeed.maxSpeedMultiplier.Value); } } } namespace QuotaDependentSpeed.Extensions { internal static class RandomExtensions { public static double NextDouble(this Random random, double min, double max) { return random.NextDouble() * (max - min) + min; } public static float NextFloat(this Random random, float min, float max) { return (float)random.NextDouble(min, max); } } }