Decompiled source of AlecsCoolMod v1.0.3

BepInEx/plugins/AlecsCoolMod.dll

Decompiled a year ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using AlecsCoolMod.Patches;
using BepInEx;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using LCSoundTool;
using Microsoft.CodeAnalysis;
using Unity.Netcode;
using UnityEngine;

[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("AlecsCoolMod")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Just messing around with some stuff")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+80b399ee6c0f2bab346fba1216e5141e09bfdd98")]
[assembly: AssemblyProduct("AlecsCoolMod")]
[assembly: AssemblyTitle("AlecsCoolMod")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
internal class <Module>
{
	static <Module>()
	{
	}
}
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 AlecsCoolMod
{
	internal class NetworkHandler : NetworkBehaviour
	{
		public static NetworkHandler Instance { get; private set; }

		public static event Action SeedChanged;

		public override void OnNetworkSpawn()
		{
			NetworkHandler.SeedChanged = null;
			if (Object.op_Implicit((Object)(object)Instance) && (NetworkManager.Singleton.IsHost || NetworkManager.Singleton.IsServer))
			{
				((Component)Instance).gameObject.GetComponent<NetworkObject>().Despawn(true);
			}
			Instance = this;
		}

		[ClientRpc]
		public void ReceiveSeedClientRpc(int seed)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: 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)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				if ((int)base.__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
				{
					ClientRpcParams val = default(ClientRpcParams);
					FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(1053408422u, val, (RpcDelivery)0);
					BytePacker.WriteValueBitPacked(val2, seed);
					((NetworkBehaviour)this).__endSendClientRpc(ref val2, 1053408422u, val, (RpcDelivery)0);
				}
				if ((int)base.__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
				{
					Random.InitState(seed);
					NetworkHandler.SeedChanged?.Invoke();
				}
			}
		}

		[ServerRpc(RequireOwnership = false)]
		public void SendSeedServerRpc(int seed)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: 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)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost))
				{
					ServerRpcParams val = default(ServerRpcParams);
					FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendServerRpc(1278269377u, val, (RpcDelivery)0);
					BytePacker.WriteValueBitPacked(val2, seed);
					((NetworkBehaviour)this).__endSendServerRpc(ref val2, 1278269377u, val, (RpcDelivery)0);
				}
				if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost) && ((NetworkBehaviour)this).IsHost)
				{
					ReceiveSeedClientRpc(seed);
				}
			}
		}

		protected override void __initializeVariables()
		{
			((NetworkBehaviour)this).__initializeVariables();
		}

		[RuntimeInitializeOnLoadMethod]
		internal static void InitializeRPCS_NetworkHandler()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			NetworkManager.__rpc_func_table.Add(1053408422u, new RpcReceiveHandler(__rpc_handler_1053408422));
			NetworkManager.__rpc_func_table.Add(1278269377u, new RpcReceiveHandler(__rpc_handler_1278269377));
		}

		private static void __rpc_handler_1053408422(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				int seed = default(int);
				ByteUnpacker.ReadValueBitPacked(reader, ref seed);
				target.__rpc_exec_stage = (__RpcExecStage)2;
				((NetworkHandler)(object)target).ReceiveSeedClientRpc(seed);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_1278269377(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				int seed = default(int);
				ByteUnpacker.ReadValueBitPacked(reader, ref seed);
				target.__rpc_exec_stage = (__RpcExecStage)1;
				((NetworkHandler)(object)target).SendSeedServerRpc(seed);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		protected internal override string __getTypeName()
		{
			return "NetworkHandler";
		}
	}
	[BepInPlugin("AlecsCoolMod", "Alecs Cool Mod", "1.0.3")]
	public class TestModBase : BaseUnityPlugin
	{
		private const string modGUID = "AlecsCoolMod";

		private const string modName = "Alecs Cool Mod";

		private const string modVersion = "1.0.3";

		public static AssetBundle MainAssets;

		private static readonly Harmony harmony = new Harmony("AlecsCoolMod");

		public static TestModBase Instance;

		internal ManualLogSource logger;

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			logger = Logger.CreateLogSource("AlecsCoolMod");
			MainAssets = AssetBundle.LoadFromFile(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Assets/assetbundle"));
			NetcodePatcher();
			logger.LogInfo((object)"Alec's cool mod has awakened.");
		}

		private void Start()
		{
			harmony.PatchAll(typeof(NetworkManagerPatch));
			harmony.PatchAll(typeof(AudioPatch));
		}

		private static void NetcodePatcher()
		{
			Type[] types = Assembly.GetExecutingAssembly().GetTypes();
			Type[] array = types;
			foreach (Type type in array)
			{
				MethodInfo[] methods = type.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic);
				MethodInfo[] array2 = methods;
				foreach (MethodInfo methodInfo in array2)
				{
					object[] customAttributes = methodInfo.GetCustomAttributes(typeof(RuntimeInitializeOnLoadMethodAttribute), inherit: false);
					if (customAttributes.Length != 0)
					{
						methodInfo.Invoke(null, null);
					}
				}
			}
		}
	}
}
namespace AlecsCoolMod.Patches
{
	internal class AudioPatch
	{
		private static bool initialized;

		private static List<string> soundFiles;

		private static List<AudioClip> companySpeeches;

		public static AudioClip customFallSound;

		public static AudioClip customTurretSound;

		[HarmonyPrefix]
		[HarmonyPatch(typeof(StartOfRound), "Awake")]
		private static void LoadCustomAudio()
		{
			if (!initialized)
			{
				LoadCustomSpeech();
				LoadCustomSoundEffects();
				initialized = true;
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(StartOfRound), "PlayFirstDayShipAnimation")]
		private static void ResetSeedOnFirstDayAnimation()
		{
			if (Object.op_Implicit((Object)(object)NetworkHandler.Instance))
			{
				int seed = (int)DateTime.Now.Ticks;
				NetworkHandler.Instance.SendSeedServerRpc(seed);
			}
		}

		private static void LoadCustomSpeech()
		{
			soundFiles = new List<string> { "just_do_it.mp3", "boys_are_back.wav", "jg_wentworth.mp3", "great_asset.mp3", "little_einsteins.mp3" };
			companySpeeches = soundFiles.ConvertAll((string fileName) => SoundTool.GetAudioClip("Alec1017-AlecsCoolMod", fileName));
			foreach (AudioClip companySpeech in companySpeeches)
			{
				SoundTool.ReplaceAudioClip("IntroCompanySpeech", companySpeech, 1f / (float)companySpeeches.Count);
			}
		}

		private static void LoadCustomSoundEffects()
		{
			customFallSound = SoundTool.GetAudioClip("Alec1017-AlecsCoolMod", "wilhelm_scream.wav");
			customTurretSound = SoundTool.GetAudioClip("Alec1017-AlecsCoolMod", "surprise.mp3");
			SoundTool.ReplaceAudioClip("DieFromFallDamageSFX1", customFallSound);
			SoundTool.ReplaceAudioClip("TurretSeePlayer", customTurretSound);
		}
	}
	[HarmonyPatch]
	internal class NetworkManagerPatch
	{
		public static GameObject networkPrefab;

		[HarmonyPostfix]
		[HarmonyPatch(typeof(GameNetworkManager), "Start")]
		private static void LoadNetworkHandlerPrefab()
		{
			if (!((Object)(object)networkPrefab != (Object)null))
			{
				networkPrefab = TestModBase.MainAssets.LoadAsset<GameObject>("NetworkHandler.prefab");
				networkPrefab.AddComponent<NetworkHandler>();
				NetworkManager.Singleton.AddNetworkPrefab(networkPrefab);
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(StartOfRound), "Awake")]
		private static void SpawnNetworkHandler()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			if (NetworkManager.Singleton.IsHost || NetworkManager.Singleton.IsServer)
			{
				GameObject val = Object.Instantiate<GameObject>(networkPrefab, Vector3.zero, Quaternion.identity);
				val.GetComponent<NetworkObject>().Spawn(false);
			}
		}
	}
	internal class PlayerControllerBPatch
	{
		[HarmonyPostfix]
		[HarmonyPatch(typeof(PlayerControllerB), "Update")]
		private static void InfiniteSprintPatch(ref float ___sprintMeter)
		{
			___sprintMeter = 1f;
		}
	}
}