Decompiled source of LCLocalFixes v0.0.1

LCLocalFixes.dll

Decompiled 8 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
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.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using ModelReplacement;
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: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: AssemblyCompany("LCLocalFixes")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("0.0.1.0")]
[assembly: AssemblyInformationalVersion("0.0.1")]
[assembly: AssemblyProduct("LCLocalFixes")]
[assembly: AssemblyTitle("LCLocalFixes")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.1.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 LCLocalFixes
{
	public class EditorTimeToggle
	{
		[HarmonyPatch(typeof(ShipBuildModeManager), "StoreObject_performed")]
		public class NewShipBuildModeManager
		{
			[HarmonyPostfix]
			public static void ToggleTimeMultiplier()
			{
				lastTimeStoreObject = Time.realtimeSinceStartup;
				if (!(Time.realtimeSinceStartup - lastTimeStoreObject < 1f))
				{
					return;
				}
				Logger.LogDebug((object)"StoreObject performed");
				if (!Application.isEditor)
				{
					Logger.LogDebug((object)"EditorTimeToggle.ToggleTime(): !isEditor");
					return;
				}
				TimeOfDay val = Object.FindAnyObjectByType<TimeOfDay>();
				if ((Object)(object)val == (Object)null)
				{
					Logger.LogDebug((object)"EditorTimeToggle.ToggleTime(): timeScript");
					return;
				}
				QuickMenuManager val2 = Object.FindAnyObjectByType<QuickMenuManager>();
				if ((Object)(object)val2 == (Object)null || val2.isMenuOpen)
				{
					if (val.globalTimeSpeedMultiplier != 0f)
					{
						lastSavedTimeMultiplier = val.globalTimeSpeedMultiplier;
						val.globalTimeSpeedMultiplier = 0f;
					}
					else
					{
						val.globalTimeSpeedMultiplier = lastSavedTimeMultiplier;
					}
					HUDManager.Instance.DisplayTip("TIME TOGGLE!!!", $"Set time to: {val.globalTimeSpeedMultiplier}", false, false, "LC_Tip1");
					Logger.LogDebug((object)$"Successfully finished EditorTimeToggle.ToggleTimeMultiplier with: {val.globalTimeSpeedMultiplier}");
				}
			}
		}

		private static ManualLogSource Logger = Plugin.Logger;

		private static float lastTimeStoreObject;

		private static float lastSavedTimeMultiplier;
	}
	public class HazardAudioLog
	{
		[HarmonyPatch(typeof(Landmine), "Start")]
		public class NewLandmine
		{
			[HarmonyPostfix]
			public static void StartPostfix(Landmine __instance)
			{
				PatchLandmine(__instance);
			}
		}

		private static ManualLogSource Logger = Plugin.Logger;

		private static void PatchLandmine(Landmine __instance)
		{
			if ((Object)(object)__instance == (Object)null || (Object)(object)Plugin.assetBundle == (Object)null)
			{
				Logger.LogWarning((object)"HazardAudioLog.PatchLandmine: null");
				return;
			}
			Logger.LogDebug((object)$"Patching Landmine #{((NetworkBehaviour)__instance).NetworkObjectId}");
			GameObject val = Plugin.assetBundle.LoadAsset<GameObject>("Assets/LandminePatch (audioSource).prefab");
			if ((Object)(object)val == (Object)null)
			{
				Logger.LogWarning((object)"HazardAudioLog.PatchLandmine: asset");
				return;
			}
			PlayAudioAnimationEvent component = ((Component)__instance).GetComponent<PlayAudioAnimationEvent>();
			if ((Object)(object)component == (Object)null)
			{
				Logger.LogWarning((object)"HazardAudioLog.PatchLandmine: playAudioAnimationEvent");
				return;
			}
			component.audioToPlay = (__instance.mineAudio = Object.Instantiate<GameObject>(val, ((Component)__instance).transform).GetComponent<AudioSource>());
			Logger.LogDebug((object)"Successfully patched this Landmine");
		}

		public static void StartSpikeTrapPatch(StartOfRound __instance)
		{
			Logger.LogDebug((object)"Starting HazardAudioLog.StartSpikeTrapPatch()");
			if ((Object)(object)__instance == (Object)null || (Object)(object)Plugin.assetBundle == (Object)null)
			{
				Logger.LogWarning((object)"HazardAudioLog.StartSpikeTrapPatch(): null");
				return;
			}
			SelectableLevel val = null;
			if (__instance.levels == null || __instance.levels.Length <= 1 || (Object)(object)__instance.levels[1] == (Object)null)
			{
				Logger.LogWarning((object)"HazardAudioLog.StartSpikeTrapPatch(): level");
				return;
			}
			val = __instance.levels[1];
			GameObject val2 = null;
			if (val.spawnableMapObjects == null || val.spawnableMapObjects.Length <= 2 || val.spawnableMapObjects[2] == null || (Object)(object)val.spawnableMapObjects[2].prefabToSpawn == (Object)null)
			{
				Logger.LogWarning((object)"HazardAudioLog.StartSpikeTrapPatch(): spawnableMapObject");
				return;
			}
			val2 = val.spawnableMapObjects[2].prefabToSpawn;
			PatchSpikeTrap(val2.GetComponentInChildren<SpikeRoofTrap>());
		}

		private static void PatchSpikeTrap(SpikeRoofTrap __instance)
		{
			if ((Object)(object)__instance == (Object)null)
			{
				Logger.LogWarning((object)"HazardAudioLog.PatchSpikeTrap(): null");
				return;
			}
			if ((Object)(object)((Component)__instance).transform.parent == (Object)null)
			{
				Logger.LogWarning((object)"HazardAudioLog.PatchSpikeTrap(): transform");
				return;
			}
			PlayAudioAnimationEvent component = ((Component)((Component)__instance).transform.parent).GetComponent<PlayAudioAnimationEvent>();
			if ((Object)(object)component == (Object)null)
			{
				Logger.LogWarning((object)"HazardAudioLog.PatchSpikeTrap(): playAudioAnimationEvent");
				return;
			}
			AudioClip val = Plugin.assetBundle.LoadAsset<AudioClip>("Assets/SpikeRoofTrapPatch (silence).ogg");
			if ((Object)(object)val == (Object)null)
			{
				Logger.LogWarning((object)"HazardAudioLog.PatchSpikeTrap(): asset");
				return;
			}
			component.audioClip2 = val;
			Logger.LogDebug((object)"Successfully patched SpikeRoofTrap");
		}
	}
	public class LevelBugs
	{
		[HarmonyPatch(typeof(AnimatedObjectTrigger), "PlayAudio")]
		public class NewAnimatedObjectTrigger
		{
			[HarmonyTranspiler]
			public static IEnumerable<CodeInstruction> PatchExperimentationParticles(IEnumerable<CodeInstruction> instructions)
			{
				Logger.LogDebug((object)"Starting LevelBugs.PatchExperimentationParticles()");
				CodeInstruction item = Transpilers.EmitDelegate<Action<ParticleSystem>>((Action<ParticleSystem>)delegate(ParticleSystem particles)
				{
					//IL_0024: Unknown result type (might be due to invalid IL or missing references)
					//IL_002f: Unknown result type (might be due to invalid IL or missing references)
					if ((Object)(object)particles != (Object)null)
					{
						particles.Play(true);
						if (Vector3.Distance(((Component)GameNetworkManager.Instance.localPlayerController).transform.position, ((Component)particles).transform.position) < 14f)
						{
							HUDManager.Instance.ShakeCamera((ScreenShakeType)2);
						}
					}
				});
				List<CodeInstruction> list = new List<CodeInstruction>(instructions);
				int num = -1;
				for (int i = 0; i < list.Count - 1; i++)
				{
					CodeInstruction val = list[i];
					if (val.opcode == OpCodes.Ldfld && ((FieldInfo)val.operand).Name == "playParticle")
					{
						num = i;
						break;
					}
				}
				if (num == -1)
				{
					Logger.LogWarning((object)"LevelBugs.PatchExperimentationParticles(): codeInstruction");
					return list;
				}
				list.RemoveRange(num + 1, 13);
				list.Insert(num + 1, item);
				Logger.LogDebug((object)"Reached end of LevelBugs.PatchExperimentationParticles()");
				return list;
			}
		}

		[HarmonyPatch(typeof(StartOfRound), "openingDoorsSequence")]
		public class NewStartOfRound
		{
			[HarmonyPostfix]
			public static void openingDoorsSequencePostfix(StartOfRound __instance)
			{
				if ((Object)(object)__instance == (Object)null || (Object)(object)__instance.currentLevel == (Object)null)
				{
					Logger.LogWarning((object)"LevelBugs: null");
				}
				else if (((Object)__instance.currentLevel).name == "ArtificeLevel")
				{
					PatchArtifice();
				}
			}
		}

		private static ManualLogSource Logger = Plugin.Logger;

		private static void PatchArtifice()
		{
			Logger.LogDebug((object)"Starting LevelBugs.PatchArtifice()");
			AudioReverbPresets val = Object.FindAnyObjectByType<AudioReverbPresets>();
			if ((Object)(object)val == (Object)null || val.audioPresets == null || val.audioPresets.Length <= 3 || (Object)(object)val.audioPresets[3] == (Object)null)
			{
				Logger.LogWarning((object)"LevelBugs.PatchArtifice(): presets");
				return;
			}
			AudioReverbTrigger val2 = val.audioPresets[3];
			if (val2.audioChanges == null || val2.audioChanges.Length <= 1 || val2.audioChanges[1] == null)
			{
				Logger.LogWarning((object)"LevelBugs.PatchArtifice(): trigger");
				return;
			}
			switchToAudio val3 = val2.audioChanges[1];
			if ((Object)(object)val3.audio == (Object)null || ((Object)val3.audio).name != "BlizzardAmbience")
			{
				Logger.LogWarning((object)"LevelBugs.PatchArtifice(): audio");
				return;
			}
			val3.changeAudioVolume = true;
			Logger.LogDebug((object)"Successfully reached end of LevelBugs.PatchArtifice()");
		}
	}
	public class Mythra : MonoBehaviour
	{
		[HarmonyPatch(typeof(BodyReplacementBase), "Awake")]
		public class NewBodyReplacementBase
		{
			[HarmonyPostfix]
			public static void AwakePostfix(BodyReplacementBase __instance)
			{
				if ((Object)(object)__instance == (Object)null)
				{
					Logger.LogWarning((object)"Mythra.AwakePostfix(): null");
				}
				else if ((Object)(object)GameNetworkManager.Instance == (Object)null || (Object)(object)GameNetworkManager.Instance.localPlayerController == (Object)null)
				{
					Logger.LogWarning((object)"Mythra.AwakePostfix(): GameNetworkManager");
				}
				else if ((Object)(object)__instance.controller == (Object)null || (Object)(object)__instance.replacementViewModel == (Object)null)
				{
					Logger.LogWarning((object)"Mythra.AwakePostfix(): __instance");
				}
				else if ((Object)(object)__instance.controller == (Object)(object)GameNetworkManager.Instance.localPlayerController)
				{
					localViewModel = __instance.replacementViewModel;
					timer = checkInterval;
					doUpdate = true;
				}
			}
		}

		private static ManualLogSource Logger = Plugin.Logger;

		private static GameObject localViewModel;

		private static bool doUpdate = false;

		private static float checkInterval = 0.5f;

		private static float timer;

		private void Update()
		{
			if (doUpdate)
			{
				if (timer >= checkInterval)
				{
					DoUpdateCheck();
					timer = 0f;
				}
				else
				{
					timer += Time.deltaTime;
				}
			}
		}

		private void DoUpdateCheck()
		{
			if ((Object)(object)localViewModel == (Object)null)
			{
				doUpdate = false;
				Logger.LogDebug((object)$"doUpdate: {doUpdate}");
				return;
			}
			PlayerControllerB localPlayerController = GameNetworkManager.Instance.localPlayerController;
			if ((Object)(object)localViewModel.transform.parent != (Object)(object)((Component)localPlayerController).transform.parent)
			{
				Logger.LogDebug((object)$"Caught discrepancy between {((Object)localViewModel).name} and {localPlayerController.playerUsername}. Reparenting to {((Component)localPlayerController).transform.parent}");
				localViewModel.transform.SetParent(((Component)localPlayerController).transform.parent, true);
			}
		}
	}
	[BepInPlugin("local.SimonTendo.LCLocalFixes", "LCLocalFixes", "0.0.1")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(StartOfRound), "Awake")]
		public class NewStartOfRound
		{
			[HarmonyPostfix]
			public static void StartPostfix(StartOfRound __instance)
			{
				//IL_0017: Unknown result type (might be due to invalid IL or missing references)
				//IL_0021: Expected O, but got Unknown
				HazardAudioLog.StartSpikeTrapPatch(__instance);
				if (foundModelReplacement)
				{
					managerObject = new GameObject("LCLocalFixes");
					managerObject.transform.SetParent(SearchForObject("SimonTendoManagers", ((Component)__instance).transform.parent).transform);
					managerObject.AddComponent<Mythra>();
				}
			}
		}

		internal static ManualLogSource Logger;

		public static Harmony harmony;

		public static AssetBundle assetBundle;

		public static GameObject managerObject;

		public static bool foundModelReplacement;

		private void Awake()
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Expected O, but got Unknown
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Expected O, but got Unknown
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Expected O, but got Unknown
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Expected O, but got Unknown
			//IL_016e: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Expected O, but got Unknown
			//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b6: Expected O, but got Unknown
			//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f2: Expected O, but got Unknown
			Logger = ((BaseUnityPlugin)this).Logger;
			Logger.LogInfo((object)"Plugin LCLocalFixes is loaded!");
			harmony = new Harmony("LCLocalFixes");
			assetBundle = AssetBundle.LoadFromFile(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "localfixesassetbundle"));
			if ((Object)(object)assetBundle == (Object)null)
			{
				Logger.LogError((object)"failed to load localfixesassetbundle");
				return;
			}
			Logger.LogInfo((object)"successfully loaded localfixesassetbundle");
			harmony.Patch((MethodBase)typeof(StartOfRound).GetMethod("Awake", BindingFlags.Instance | BindingFlags.NonPublic), (HarmonyMethod)null, new HarmonyMethod(typeof(NewStartOfRound).GetMethod("StartPostfix")), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			harmony.Patch((MethodBase)typeof(ShipBuildModeManager).GetMethod("StoreObject_performed", BindingFlags.Instance | BindingFlags.NonPublic), (HarmonyMethod)null, new HarmonyMethod(typeof(EditorTimeToggle.NewShipBuildModeManager).GetMethod("ToggleTimeMultiplier")), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			harmony.Patch((MethodBase)typeof(Landmine).GetMethod("Start", BindingFlags.Instance | BindingFlags.NonPublic), (HarmonyMethod)null, new HarmonyMethod(typeof(HazardAudioLog.NewLandmine).GetMethod("StartPostfix")), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			harmony.Patch((MethodBase)typeof(AnimatedObjectTrigger).GetMethod("PlayAudio", BindingFlags.Instance | BindingFlags.NonPublic), (HarmonyMethod)null, (HarmonyMethod)null, new HarmonyMethod(typeof(LevelBugs.NewAnimatedObjectTrigger).GetMethod("PatchExperimentationParticles")), (HarmonyMethod)null, (HarmonyMethod)null);
			harmony.Patch((MethodBase)typeof(StartOfRound).GetMethod("openingDoorsSequence"), (HarmonyMethod)null, new HarmonyMethod(typeof(LevelBugs.NewStartOfRound).GetMethod("openingDoorsSequencePostfix")), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			harmony.Patch((MethodBase)typeof(TimeOfDay).GetMethod("PlayTimeMusicDelayed"), new HarmonyMethod(typeof(TimeOfDayMusic.NewTimeOfDay).GetMethod("PlayTimeMusicDelayedPrefix")), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			foundModelReplacement = CheckForPlugin("ModelReplacementAPI");
			if (foundModelReplacement)
			{
				PatchBodyReplacement();
			}
		}

		private static void PatchBodyReplacement()
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Expected O, but got Unknown
			harmony.Patch((MethodBase)typeof(BodyReplacementBase).GetMethod("Awake", BindingFlags.Instance | BindingFlags.NonPublic), (HarmonyMethod)null, new HarmonyMethod(typeof(Mythra.NewBodyReplacementBase).GetMethod("AwakePostfix")), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		}

		private static bool CheckForPlugin(string pluginName, bool printDebug = true)
		{
			foreach (PluginInfo value in Chainloader.PluginInfos.Values)
			{
				if (value.Metadata.Name == pluginName)
				{
					if (printDebug)
					{
						Logger.LogDebug((object)("Successfully found " + pluginName));
					}
					return true;
				}
			}
			if (printDebug)
			{
				Logger.LogDebug((object)("Failed to find " + pluginName));
			}
			return false;
		}

		public static GameObject SearchForObject(string name, Transform parentTransform = null)
		{
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Expected O, but got Unknown
			Logger.LogDebug((object)("Starting search for " + name));
			GameObject[] array = Object.FindObjectsByType<GameObject>((FindObjectsSortMode)0);
			GameObject[] array2 = array;
			GameObject result;
			foreach (GameObject val in array2)
			{
				if (((Object)val).name == name)
				{
					result = val;
					Logger.LogDebug((object)("Found existing " + ((Object)val).name + ", using as parent."));
					return result;
				}
			}
			result = new GameObject(name);
			if ((Object)(object)parentTransform != (Object)null)
			{
				result.transform.SetParent(parentTransform, false);
			}
			Logger.LogDebug((object)("Did not find existing " + name + ", instantiating new " + ((Object)result).name));
			return result;
		}
	}
	public class TimeOfDayMusic
	{
		[HarmonyPatch(typeof(TimeOfDay), "PlayTimeMusicDelayed")]
		public class NewTimeOfDay
		{
			[HarmonyPrefix]
			public static void PlayTimeMusicDelayedPrefix()
			{
				if ((Object)(object)TimeOfDay.Instance == (Object)null || (Object)(object)StartOfRound.Instance == (Object)null)
				{
					Logger.LogWarning((object)"TimeOfDayMusic.PlayTimeMusicDelayedPrefix(): null");
					return;
				}
				float num = Mathf.Pow(0.75f, (float)StartOfRound.Instance.connectedPlayersAmount);
				float num2 = Random.Range(0f, 1f);
				Logger.LogDebug((object)$"Resetting TimeOfDay.Instance.playDelayedMusicCoroutine ({num2} < {num} = {num2 < num})");
				if (num2 <= num)
				{
					TimeOfDay.Instance.playDelayedMusicCoroutine = null;
				}
			}
		}

		private static ManualLogSource Logger = Plugin.Logger;
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "LCLocalFixes";

		public const string PLUGIN_NAME = "LCLocalFixes";

		public const string PLUGIN_VERSION = "0.0.1";
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}