Decompiled source of SpeedoMode v2.0.0

SpeedoMode.dll

Decompiled 2 weeks ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using Unity.Collections;
using Unity.Netcode;
using UnityEngine.InputSystem;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("SpeedoMode")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("SpeedoMode")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("94de0c68-ad49-4163-a0ed-9065a488868a")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: UnverifiableCode]
namespace SpeedoMode;

[BepInPlugin("ShadowAPI.SpeedoMode", "SpeedoMode", "2.0.0")]
public class ModBase : BaseUnityPlugin
{
	public const string pluginGuid = "ShadowAPI.SpeedoMode";

	public const string pluginName = "SpeedoMode";

	public const string pluginVersion = "2.0.0";

	private static ManualLogSource _logger;

	private static Harmony _harmonyInstance;

	private static BaseUnityPlugin _pluginInstance;

	internal static ManualLogSource logger => _logger;

	internal static Harmony harmonyInstance => _harmonyInstance;

	internal static BaseUnityPlugin pluginInstance => _pluginInstance;

	private void Awake()
	{
		//IL_0025: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Expected O, but got Unknown
		_logger = ((BaseUnityPlugin)this).Logger;
		_logger.LogInfo((object)"SikoMode");
		_pluginInstance = (BaseUnityPlugin)(object)this;
		_harmonyInstance = new Harmony("ShadowAPI.SpeedoMode");
		_harmonyInstance.PatchAll();
	}
}
[HarmonyPatch]
internal class PlayerControllerBPatch
{
	private static InputAction action;

	private static bool sprintToggled;

	[HarmonyPatch(typeof(PlayerControllerB), "Update")]
	[HarmonyPostfix]
	public static void UpdateFunc(ref float ___sprintMultiplier, ref bool ___isSprinting, ref bool ___isFallingFromJump)
	{
		if ((ModConfiguration.Sync.instance.isHostEnabled & ___isSprinting) && sprintToggled)
		{
			float num = Math.Max(ModConfiguration.runningSpeed.Value, ___sprintMultiplier);
			___sprintMultiplier = ((NetworkManager.Singleton.IsClient && ModConfiguration.Sync.instance.speedLimit > ___sprintMultiplier) ? Math.Min(ModConfiguration.Sync.instance.speedLimit, num) : num);
		}
	}

	[HarmonyPatch(typeof(PlayerControllerB), "Awake")]
	[HarmonyPostfix]
	public static void AwakeFunc(PlayerControllerB __instance)
	{
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Expected O, but got Unknown
		if (action == null)
		{
			ModBase.logger.LogInfo((object)ModConfiguration.keyBinding.Value);
			action = new InputAction("Toggle", (InputActionType)0, ModConfiguration.keyBinding.Value, (string)null, (string)null, (string)null);
			action.performed += delegate
			{
				sprintToggled = !sprintToggled;
			};
			action.Enable();
			ModBase.harmonyInstance.Unpatch((MethodBase)typeof(PlayerControllerB).GetMethod("Awake", BindingFlags.Instance | BindingFlags.NonPublic), typeof(PlayerControllerBPatch).GetMethod("AwakeFunc"));
			ModBase.logger.LogInfo((object)"PlayerControllerB.AwakeFunc Unpatched");
		}
	}
}
[HarmonyPatch]
internal static class ModConfiguration
{
	[HarmonyPatch]
	public class Sync
	{
		public struct SyncData
		{
			public bool isHostEnabled;

			public float speedLimit;
		}

		public static SyncData instance;

		public static bool isSynced;

		private const string serverHandlerName = "SpeedoMode-OnTxConfigSync";

		private const string clientHandlerName = "SpeedoMode-OnRxConfigSync";

		private static int retries;

		[HarmonyPatch(typeof(NetworkManager), "Initialize")]
		[HarmonyPostfix]
		public static void OnInitialize(bool server)
		{
			NetworkManager.Singleton.OnClientConnectedCallback += delegate
			{
				SetSyncMode(server);
			};
		}

		private static void SetSyncMode(bool server)
		{
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Expected O, but got Unknown
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Expected O, but got Unknown
			if (server)
			{
				ModBase.logger.LogInfo((object)"Set as Server");
				NetworkManager.Singleton.CustomMessagingManager.RegisterNamedMessageHandler("SpeedoMode-OnTxConfigSync", new HandleNamedMessageDelegate(OnServerConfigSync));
				instance.isHostEnabled = true;
				instance.speedLimit = runningSpeed.Value;
				isSynced = true;
			}
			else
			{
				ModBase.logger.LogInfo((object)"Set as Client");
				NetworkManager.Singleton.CustomMessagingManager.RegisterNamedMessageHandler("SpeedoMode-OnRxConfigSync", new HandleNamedMessageDelegate(OnClientConfigSync));
				RequestConfigSync();
			}
		}

		private unsafe static void OnServerConfigSync(ulong clientID, FastBufferReader readBuffer)
		{
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			ModBase.logger.LogInfo((object)("Config request received from client: " + clientID));
			FastBufferWriter val = default(FastBufferWriter);
			fixed (SyncData* ptr = &instance)
			{
				byte* ptr2 = (byte*)ptr;
				int num = sizeof(SyncData);
				ModBase.logger.LogInfo((object)("Payload size: " + num + " bytes"));
				((FastBufferWriter)(ref val))..ctor(num, (Allocator)2, -1);
				((FastBufferWriter)(ref val)).WriteBytes(ptr2, num, 0);
			}
			NetworkManager.Singleton.CustomMessagingManager.SendNamedMessage("SpeedoMode-OnRxConfigSync", clientID, val, (NetworkDelivery)3);
			ModBase.logger.LogInfo((object)"Config payload sent");
		}

		private unsafe static void OnClientConfigSync(ulong clientID, FastBufferReader readBuffer)
		{
			int num = ((FastBufferReader)(ref readBuffer)).Length - ((FastBufferReader)(ref readBuffer)).Position;
			if (retries == 3)
			{
				ModBase.logger.LogError((object)"Failed to sync data, I adviced to check over your mods. Which one? idk bro can't tell.");
			}
			else if (num != sizeof(SyncData))
			{
				ModBase.logger.LogError((object)("Anomaly Detected: Payload size is " + num + " bytes, it should be " + sizeof(SyncData) + " bytes"));
				ModBase.logger.LogWarning((object)$"Discarding Data. Retry {retries} of 3");
				retries++;
				RequestConfigSync();
			}
			else
			{
				ModBase.logger.LogInfo((object)("Received host config. Payload size: " + num));
				fixed (SyncData* ptr = &instance)
				{
					byte* ptr2 = (byte*)ptr;
					((FastBufferReader)(ref readBuffer)).ReadBytes(ptr2, sizeof(SyncData), 0);
				}
				isSynced = true;
				ModBase.logger.LogInfo((object)"Config synced");
				ModBase.logger.LogInfo((object)("Server Speed Limit: " + instance.speedLimit));
			}
		}

		private static void RequestConfigSync()
		{
			//IL_0016: 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_0033: Unknown result type (might be due to invalid IL or missing references)
			FastBufferWriter val = default(FastBufferWriter);
			((FastBufferWriter)(ref val))..ctor(4, (Allocator)2, -1);
			int num = 219540062;
			((FastBufferWriter)(ref val)).WriteValue<int>(ref num, default(ForPrimitives));
			NetworkManager.Singleton.CustomMessagingManager.SendNamedMessage("SpeedoMode-OnTxConfigSync", 0uL, val, (NetworkDelivery)3);
			ModBase.logger.LogInfo((object)("Config request sent to server. Payload size: " + ((FastBufferWriter)(ref val)).Length));
		}
	}

	public static ConfigEntry<float> runningSpeed = ModBase.pluginInstance.Config.Bind<float>("Settings", "RunningSpeed", 100f, "Well its up to you how fast you want to move. Though, the host needs the mod installed and enabled (This is enforced by the Thunderstore ;(, my bad holmes)");

	public static ConfigEntry<string> keyBinding = ModBase.pluginInstance.Config.Bind<string>("Settings", "Keybind", "<Keyboard>/r", "Which key to use as the toggle. Default (R)");
}