Decompiled source of TonightWeDine v1.0.1

TonightWeDine.dll

Decompiled 3 days ago
using System;
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 BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Unity.AI.Navigation;
using UnityEngine;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("TonightWeDine")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Changes the layout of Dine's exterior.")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: AssemblyInformationalVersion("1.0.1+00a6696c9997fc07f39d7f39a73192f6190cf61b")]
[assembly: AssemblyProduct("TonightWeDine")]
[assembly: AssemblyTitle("TonightWeDine")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.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 TonightWeDine
{
	internal class TonightWeDineConfig
	{
		internal enum DineLayoutEnum
		{
			V60 = -1,
			V50,
			Hybrid
		}

		internal static ConfigEntry<DineLayoutEnum> dineLayout;

		public static void Bind(ConfigFile config)
		{
			dineLayout = config.Bind<DineLayoutEnum>("7-Dine", "Layout", DineLayoutEnum.V50, "Dine's Exterior Layout\n\nV60 = V60's exterior\n\nV50 = V50's exterior\n\nHybird = V50's exterior with V49's entrances");
		}
	}
	[BepInPlugin("TonightWeDine", "TonightWeDine", "1.0.1")]
	public class Plugin : BaseUnityPlugin
	{
		private readonly Harmony harmony = new Harmony("TonightWeDine");

		public static Plugin Instance;

		private void Awake()
		{
			if (Instance == null)
			{
				Instance = this;
			}
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin TonightWeDine is loaded!");
			TonightWeDineConfig.Bind(((BaseUnityPlugin)this).Config);
			Assets.LoadAssets();
			harmony.PatchAll(typeof(DineOverridePatch));
			if (Chainloader.PluginInfos.ContainsKey("butterystancakes.lethalcompany.chameleon"))
			{
				harmony.PatchAll(typeof(ChameleonFancyDoorPatch));
			}
			SceneManager.sceneUnloaded += delegate
			{
				DineOverride.executed = false;
				DineOverride.fancyExecuted = false;
			};
		}

		public static void Log(string msg)
		{
			((BaseUnityPlugin)Instance).Logger.LogInfo((object)msg);
		}

		public static void LogError(string msg)
		{
			((BaseUnityPlugin)Instance).Logger.LogError((object)msg);
		}

		public static void LogDebug(string msg)
		{
			((BaseUnityPlugin)Instance).Logger.LogDebug((object)msg);
		}
	}
	internal class DineOverridePatch
	{
		[HarmonyPatch(typeof(RoundManager), "FinishGeneratingNewLevelClientRpc")]
		[HarmonyPriority(900)]
		[HarmonyPostfix]
		private static void FinishGeneratingNewLevel_DineOverridePatch()
		{
			if (((Object)StartOfRound.Instance.currentLevel).name == "DineLevel" && !DineOverride.executed)
			{
				DineOverride.executed = true;
				if (TonightWeDineConfig.dineLayout.Value >= TonightWeDineConfig.DineLayoutEnum.V50)
				{
					Plugin.LogDebug("Dine's layout is \"" + TonightWeDineConfig.dineLayout.Value.ToString() + "\"");
					DineOverride.DineSceneOverride((int)TonightWeDineConfig.dineLayout.Value);
				}
				Plugin.LogDebug("Fixing Dine's pits");
				DineOverride.DineFixes();
			}
		}
	}
	internal class ChameleonFancyDoorPatch
	{
		[HarmonyPatch(typeof(RoundManager), "FinishGeneratingNewLevelClientRpc")]
		[HarmonyPriority(300)]
		[HarmonyPostfix]
		private static void FancyDoorsPatch()
		{
			if (((Object)StartOfRound.Instance.currentLevel).name == "DineLevel" && TonightWeDineConfig.dineLayout.Value >= TonightWeDineConfig.DineLayoutEnum.V50 && !DineOverride.fancyExecuted)
			{
				DineOverride.fancyExecuted = true;
				DineOverride.FancyDoorOverride();
			}
		}
	}
	internal static class Assets
	{
		internal static AssetBundle assetBundle;

		internal static Mesh newSurfaceMesh;

		internal static Mesh metalWallMesh;

		internal static GameObject treeNearFire;

		internal static GameObject leavesNearFire;

		internal static void LoadAssets()
		{
			try
			{
				assetBundle = AssetBundle.LoadFromFile(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "tonightwedine"));
				newSurfaceMesh = assetBundle.LoadAsset<Mesh>("DineHybridTerrain");
				metalWallMesh = assetBundle.LoadAsset<Mesh>("Cube.001_0");
				treeNearFire = assetBundle.LoadAsset<GameObject>("NearFireTree");
				leavesNearFire = assetBundle.LoadAsset<GameObject>("NearFireLeaves");
				assetBundle.Unload(false);
			}
			catch
			{
				Plugin.LogError("Failed to load mod assets!");
			}
		}
	}
	internal static class DineOverride
	{
		internal static bool executed;

		internal static bool fancyExecuted;

		internal static void DineSceneOverride(int dineVersion)
		{
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_0409: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0223: Unknown result type (might be due to invalid IL or missing references)
			//IL_0241: Unknown result type (might be due to invalid IL or missing references)
			//IL_0446: Unknown result type (might be due to invalid IL or missing references)
			//IL_0461: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_0309: Unknown result type (might be due to invalid IL or missing references)
			//IL_032c: Unknown result type (might be due to invalid IL or missing references)
			//IL_034b: Unknown result type (might be due to invalid IL or missing references)
			//IL_049e: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_036e: Unknown result type (might be due to invalid IL or missing references)
			//IL_038d: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0516: Unknown result type (might be due to invalid IL or missing references)
			//IL_0553: Unknown result type (might be due to invalid IL or missing references)
			//IL_0573: Unknown result type (might be due to invalid IL or missing references)
			//IL_05b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_05d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_060d: Unknown result type (might be due to invalid IL or missing references)
			//IL_062d: Unknown result type (might be due to invalid IL or missing references)
			//IL_066a: Unknown result type (might be due to invalid IL or missing references)
			//IL_068a: Unknown result type (might be due to invalid IL or missing references)
			//IL_06c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_06e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0702: Unknown result type (might be due to invalid IL or missing references)
			if (dineVersion < 0)
			{
				return;
			}
			GameObject obj = GameObject.Find("/Environment/NeonLightsSingle");
			if (obj != null)
			{
				obj.SetActive(false);
			}
			GameObject obj2 = GameObject.Find("/Environment/Map/CementFacility1/Cube.002");
			Transform val = ((obj2 != null) ? obj2.transform : null);
			GameObject obj3 = GameObject.Find("/Environment/FireExitDoorContainer/FireExitDoor");
			Transform val2 = ((obj3 != null) ? obj3.transform : null);
			GameObject obj4 = GameObject.Find("/Environment/Teleports/EntranceTeleportB");
			Transform val3 = ((obj4 != null) ? obj4.transform : null);
			switch (dineVersion)
			{
			case 0:
				if ((Object)(object)val != (Object)null)
				{
					val.localPosition = new Vector3(21.48f, 1.69f, 54.77f);
					val.localRotation = new Quaternion(0.043608133f, -0.70601994f, -0.7056099f, -0.04182105f);
					val.localScale = new Vector3(0.6834142f, 0.8991681f, 0.6834142f);
				}
				if ((Object)(object)val2 != (Object)null)
				{
					val2.localPosition = new Vector3(-73.69555f, 9.62243f, 48.685997f);
					val2.localRotation = new Quaternion(0f, 0.85768974f, 0f, -0.51416767f);
				}
				if ((Object)(object)val3 != (Object)null)
				{
					val3.localPosition = new Vector3(137.39407f, -15.564064f, 46.236385f);
					val3.localRotation = new Quaternion(0f, 0.9981922f, 0f, 0.06010294f);
					val3.localScale = new Vector3(1.9334757f, 3.462273f, 0.5321793f);
				}
				break;
			case 1:
			{
				GameObject val4 = GameObject.Find("/Environment/NewDineTerrainCutdown");
				if ((Object)(object)val4 != (Object)null)
				{
					val4.GetComponent<MeshFilter>().mesh = Assets.newSurfaceMesh;
					val4.GetComponent<MeshCollider>().sharedMesh = Assets.newSurfaceMesh;
				}
				GameObject obj5 = GameObject.Find("/Environment/ReverbTriggers (1)/WindTriggers");
				Transform val5 = ((obj5 != null) ? obj5.transform : null);
				GameObject val6 = GameObject.Find("/Environment/ReverbTriggers (1)/WindTriggers/shipWindTrigger2");
				if ((Object)(object)val6 != (Object)null && (Object)(object)val5 != (Object)null)
				{
					GameObject obj6 = Object.Instantiate<GameObject>(val6, val5);
					obj6.transform.localPosition = new Vector3(-193.03427f, 7.074562f, -83.64745f);
					obj6.transform.localRotation = new Quaternion(0f, 0f, 0f, 1f);
					obj6.transform.localScale = new Vector3(12.9657545f, 6.9007154f, 11.519966f);
				}
				if ((Object)(object)RoundManager.Instance.mapPropsContainer == (Object)null)
				{
					RoundManager.Instance.mapPropsContainer = GameObject.FindGameObjectWithTag("MapPropsContainer");
				}
				if ((Object)(object)RoundManager.Instance.mapPropsContainer != (Object)null)
				{
					Object.Instantiate<GameObject>(Assets.treeNearFire, RoundManager.Instance.mapPropsContainer.transform);
					Object.Instantiate<GameObject>(Assets.leavesNearFire, RoundManager.Instance.mapPropsContainer.transform);
				}
				if ((Object)(object)val != (Object)null)
				{
					val.localPosition = new Vector3(-15.267663f, 5.13949f, 29.441992f);
					val.localRotation = new Quaternion(-0.2334155f, -0.66771203f, -0.66668123f, 0.23497672f);
					val.localScale = new Vector3(0.5241794f, 0.64612794f, 0.4780146f);
				}
				if ((Object)(object)val2 != (Object)null)
				{
					val2.localPosition = new Vector3(-218.79054f, 32.197186f, -177.6566f);
					val2.localRotation = new Quaternion(0f, 0.5992887f, 0f, -0.800533f);
				}
				if ((Object)(object)val3 != (Object)null)
				{
					val3.localPosition = new Vector3(-28.067f, 1.4099998f, -70.185f);
					val3.localRotation = new Quaternion(0f, 0.94372284f, 0f, -0.33073732f);
					val3.localScale = new Vector3(1.9334757f, 3.462273f, 0.5321793f);
				}
				break;
			}
			}
			GameObject val7 = GameObject.Find("/Environment/Map/Cube.001 (16)");
			if ((Object)(object)val7 != (Object)null)
			{
				val7.GetComponent<MeshFilter>().mesh = Assets.metalWallMesh;
				val7.transform.localPosition = new Vector3(179.3406f, -20.249994f, -22.0728f);
				val7.transform.localScale = new Vector3(1f, 1.4000261f, 1.1451999f);
			}
			GameObject obj7 = GameObject.Find("/Environment/Map/Cube.001 (8)");
			BoxCollider val8 = ((obj7 != null) ? obj7.GetComponent<BoxCollider>() : null);
			if ((Object)(object)val8 != (Object)null)
			{
				val8.center = new Vector3(-0.14010677f, -2.7291498f, -0.26022604f);
				val8.size = new Vector3(0.53314275f, 6.8050165f, 4.480085f);
			}
			GameObject obj8 = GameObject.Find("/Environment/Map/Cube.001 (4)");
			BoxCollider val9 = ((obj8 != null) ? obj8.GetComponent<BoxCollider>() : null);
			if ((Object)(object)val9 != (Object)null)
			{
				val9.center = new Vector3(-0.14010829f, -1.0517684f, -0.26022604f);
				val9.size = new Vector3(0.53314275f, 10.159763f, 4.480085f);
			}
			GameObject obj9 = GameObject.Find("/Environment/Plane");
			Transform val10 = ((obj9 != null) ? obj9.transform : null);
			if ((Object)(object)val10 != (Object)null)
			{
				val10.localPosition = new Vector3(178.84203f, -20.405f, -16.50813f);
				val10.localRotation = new Quaternion(0.5249201f, -0.4737709f, -0.4737702f, -0.52492076f);
			}
			GameObject obj10 = GameObject.Find("/Environment/SteelDoorFake");
			Transform val11 = ((obj10 != null) ? obj10.transform : null);
			if ((Object)(object)val11 != (Object)null)
			{
				val11.localPosition = new Vector3(178.729f, -20.34f, -15.17f);
				val11.localRotation = new Quaternion(0.038197827f, -0.7060744f, -0.70607436f, -0.03819688f);
			}
			GameObject obj11 = GameObject.Find("/Environment/SteelDoorFake (1)");
			Transform val12 = ((obj11 != null) ? obj11.transform : null);
			if ((Object)(object)val12 != (Object)null)
			{
				val12.localPosition = new Vector3(179.06046f, -20.340002f, -18.119337f);
				val12.localRotation = new Quaternion(0.03954247f, -0.7060007f, -0.706f, -0.039542507f);
			}
			GameObject obj12 = GameObject.Find("/Environment/DoorFrame (1)");
			Transform val13 = ((obj12 != null) ? obj12.transform : null);
			if ((Object)(object)val13 != (Object)null)
			{
				val13.localPosition = new Vector3(178.902f, -23.807f, -16.656f);
				val13.localRotation = new Quaternion(0.03933583f, -0.7060121f, -0.70601153f, -0.03933586f);
			}
			GameObject obj13 = GameObject.Find("/Environment/Teleports/EntranceTeleportA");
			Transform val14 = ((obj13 != null) ? obj13.transform : null);
			if ((Object)(object)val14 != (Object)null)
			{
				val14.localPosition = new Vector3(178.67831f, -21.2327f, -16.662853f);
				val14.localRotation = new Quaternion(0f, 0.99843365f, 0f, 0.055948973f);
			}
			GameObject obj14 = GameObject.Find("/Environment/ScanNodes/ScanNode");
			Transform val15 = ((obj14 != null) ? obj14.transform : null);
			if ((Object)(object)val15 != (Object)null)
			{
				val15.localPosition = new Vector3(175.7f, -24.01f, -19.5f);
				val15.localRotation = new Quaternion(0.7071068f, -0.7071068f, -2.43634E-06f, 2.43634E-06f);
				val15.localScale = new Vector3(9.139909f, 138.73448f, 4.0328393f);
			}
			GameObject val16 = GameObject.Find("/Environment");
			if ((Object)(object)val16 != (Object)null)
			{
				val16.GetComponent<NavMeshSurface>().RemoveData();
				val16.GetComponent<NavMeshSurface>().BuildNavMesh();
			}
		}

		internal static void FancyDoorOverride()
		{
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			GameObject obj = GameObject.Find("/Environment/MapPropsContainer/WideDoorFrame(Clone)");
			Transform val = ((obj != null) ? obj.transform : null);
			if ((Object)(object)val != (Object)null)
			{
				Plugin.LogDebug("Found Chameleon's fancy door, moving them");
				((Component)val).transform.position = new Vector3(-156.553f, -15.126f, 12.155f);
				((Component)val).transform.rotation = new Quaternion(-0.70618117f, -0.036169115f, -0.036169115f, 0.70618117f);
			}
		}

		internal static void DineFixes()
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			GameObject obj = GameObject.Find("/Environment/Map/KillTrigger (1)");
			Transform val = ((obj != null) ? obj.transform : null);
			if ((Object)(object)val != (Object)null)
			{
				val.localScale = new Vector3(349.60406f, 0.69064f, 181.3727f);
			}
			GameObject obj2 = GameObject.Find("/Environment/Map/KillTrigger (4)");
			Transform val2 = ((obj2 != null) ? obj2.transform : null);
			if ((Object)(object)val2 != (Object)null)
			{
				val2.localScale = new Vector3(42.223473f, 0.69064f, 81.23343f);
			}
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "TonightWeDine";

		public const string PLUGIN_NAME = "TonightWeDine";

		public const string PLUGIN_VERSION = "1.0.1";
	}
}