Decompiled source of XOTweaks MONO v1.0.0

XOTweaks.dll

Decompiled 2 months ago
using System;
using System.Collections;
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 Funly.SkyStudio;
using HarmonyLib;
using MelonLoader;
using MelonLoader.Utils;
using Newtonsoft.Json;
using ScheduleOne.DevUtilities;
using ScheduleOne.FX;
using ScheduleOne.GameTime;
using ScheduleOne.Map.Infrastructure;
using ScheduleOne.Persistence;
using ScheduleOne.PlayerScripts;
using ScheduleOne.Trash;
using StylizedWater2;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.SceneManagement;
using XOTweaks;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: MelonInfo(typeof(global::XOTweaks.XOTweaks), "XOTweaks", "1.0", "XOWithSauce", null)]
[assembly: MelonColor]
[assembly: MelonOptionalDependencies(new string[] { "FishNet.Runtime" })]
[assembly: MelonGame("TVGS", "Schedule I")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("XOTweaks")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("XOTweaks")]
[assembly: AssemblyTitle("XOTweaks")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace XOTweaks
{
	public static class BuildInfo
	{
		public const string Name = "XOTweaks";

		public const string Description = "Performance, Utility, Configuration";

		public const string Author = "XOWithSauce";

		public const string Company = null;

		public const string Version = "1.0";

		public const string DownloadLink = null;
	}
	[Serializable]
	public class ModConfig
	{
		public bool sunShadowDisabled = true;

		public float sunLightIntensityMult = 0.3f;

		public bool moonShadowDisabled = true;

		public float moonLightIntensityMult = 9.5f;

		public bool streetLightShadowDisabled = true;

		public bool optimizedLightApply = true;

		public float optimizedLightDistance = 50f;

		public float fogEndDistanceMult = 180f;

		public int trashClearThreshold = 300;

		public float timeProgressMult = 1f;

		public bool disableBushes = true;

		public bool disableSea = false;

		public float flashLightIntensity = 3.5f;

		public float flashLightRange = 30f;

		public float contrastMult = 2f;

		public bool hotReloadEnabled = true;

		public float camFarClipPlane = 230f;
	}
	public static class ConfigLoader
	{
		private static string path = Path.Combine(MelonEnvironment.ModsDirectory, "XOTweaks", "config.json");

		public static ModConfig Load()
		{
			ModConfig modConfig;
			if (File.Exists(path))
			{
				try
				{
					string text = File.ReadAllText(path);
					modConfig = JsonConvert.DeserializeObject<ModConfig>(text);
				}
				catch (Exception ex)
				{
					modConfig = new ModConfig();
					MelonLogger.Warning("Failed to read XOTweaks config: " + ex);
				}
			}
			else
			{
				modConfig = new ModConfig();
				Save(modConfig);
			}
			return modConfig;
		}

		public static void Save(ModConfig config)
		{
			try
			{
				string contents = JsonConvert.SerializeObject((object)config);
				Directory.CreateDirectory(Path.GetDirectoryName(path));
				File.WriteAllText(path, contents);
			}
			catch (Exception ex)
			{
				MelonLogger.Warning("Failed to save FeeningNPCs config: " + ex);
			}
		}
	}
	public class XOTweaks : MelonMod
	{
		[HarmonyPatch(typeof(TimeOfDayController), "UpdateSkyForCurrentTime")]
		public static class TimeOfDayControllerPatch
		{
			[HarmonyPostfix]
			public static void Postfix(TimeOfDayController __instance)
			{
				if ((Object)(object)__instance.sunOrbit != (Object)null && (Object)(object)__instance.sunOrbit.BodyLight != (Object)null)
				{
					Light bodyLight = __instance.sunOrbit.BodyLight;
					bodyLight.intensity *= currentConfig.sunLightIntensityMult;
				}
				if ((Object)(object)__instance.moonOrbit != (Object)null && (Object)(object)__instance.moonOrbit.BodyLight != (Object)null)
				{
					Light bodyLight2 = __instance.moonOrbit.BodyLight;
					bodyLight2.intensity *= currentConfig.moonLightIntensityMult;
				}
			}
		}

		[CompilerGenerated]
		private sealed class <SetupSettings>d__16 : IEnumerator<object>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private object <>2__current;

			private StreetLight[] <slights>5__1;

			private Transform <playerCam>5__2;

			private StreetLight[] <>s__3;

			private int <>s__4;

			private StreetLight <light>5__5;

			private StreetLight[] <>s__6;

			private int <>s__7;

			private StreetLight <light>5__8;

			private OptimizedLight[] <lights>5__9;

			private OptimizedLight[] <>s__10;

			private int <>s__11;

			private OptimizedLight <light>5__12;

			private GameObject <go>5__13;

			private GameObject <go>5__14;

			private Transform <flash>5__15;

			private Transform <spot>5__16;

			private Light <flashLight>5__17;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <SetupSettings>d__16(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<slights>5__1 = null;
				<playerCam>5__2 = null;
				<>s__3 = null;
				<light>5__5 = null;
				<>s__6 = null;
				<light>5__8 = null;
				<lights>5__9 = null;
				<>s__10 = null;
				<light>5__12 = null;
				<go>5__13 = null;
				<go>5__14 = null;
				<flash>5__15 = null;
				<spot>5__16 = null;
				<flashLight>5__17 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_0034: Unknown result type (might be due to invalid IL or missing references)
				//IL_003e: Expected O, but got Unknown
				//IL_005d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0063: Invalid comparison between Unknown and I4
				//IL_0087: Unknown result type (might be due to invalid IL or missing references)
				//IL_008d: Invalid comparison between Unknown and I4
				//IL_006e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0073: Unknown result type (might be due to invalid IL or missing references)
				//IL_0098: Unknown result type (might be due to invalid IL or missing references)
				//IL_009d: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>2__current = (object)new WaitForSeconds(5f);
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					sun = Singleton<EnvironmentFX>.Instance.SunLight;
					if ((int)sunShadowType == 0)
					{
						sunShadowType = sun.shadows;
					}
					moon = Singleton<EnvironmentFX>.Instance.MoonLight;
					if ((int)moonShadowType == 0)
					{
						moonShadowType = moon.shadows;
					}
					if (currentConfig.sunShadowDisabled)
					{
						sun.shadows = (LightShadows)0;
					}
					else
					{
						sun.shadows = sunShadowType;
					}
					if (currentConfig.moonShadowDisabled)
					{
						moon.shadows = (LightShadows)0;
					}
					else
					{
						moon.shadows = moonShadowType;
					}
					<slights>5__1 = Object.FindObjectsOfType<StreetLight>(true);
					if (currentConfig.streetLightShadowDisabled)
					{
						<>s__3 = <slights>5__1;
						for (<>s__4 = 0; <>s__4 < <>s__3.Length; <>s__4++)
						{
							<light>5__5 = <>s__3[<>s__4];
							<light>5__5.ShadowsEnabled = false;
							<light>5__5 = null;
						}
						<>s__3 = null;
					}
					else
					{
						<>s__6 = <slights>5__1;
						for (<>s__7 = 0; <>s__7 < <>s__6.Length; <>s__7++)
						{
							<light>5__8 = <>s__6[<>s__7];
							<light>5__8.ShadowsEnabled = true;
							<light>5__8 = null;
						}
						<>s__6 = null;
					}
					if (currentConfig.optimizedLightApply)
					{
						<lights>5__9 = Object.FindObjectsOfType<OptimizedLight>(true);
						<>s__10 = <lights>5__9;
						for (<>s__11 = 0; <>s__11 < <>s__10.Length; <>s__11++)
						{
							<light>5__12 = <>s__10[<>s__11];
							<light>5__12.MaxDistance = currentConfig.optimizedLightDistance;
							<light>5__12 = null;
						}
						<>s__10 = null;
						<lights>5__9 = null;
					}
					Singleton<EnvironmentFX>.Instance.fogEndDistanceMultiplier = currentConfig.fogEndDistanceMult;
					Singleton<EnvironmentFX>.Instance.contractMultiplier = currentConfig.contrastMult;
					NetworkSingleton<TimeManager>.Instance.TimeProgressionMultiplier = currentConfig.timeProgressMult;
					if (currentConfig.disableBushes)
					{
						<go>5__13 = GameObject.Find("Bushes");
						if ((Object)(object)<go>5__13 != (Object)null && ((Object)<go>5__13.transform.parent).name == "Container")
						{
							<go>5__13.SetActive(false);
							if ((Object)(object)bushesRef == (Object)null)
							{
								bushesRef = <go>5__13;
							}
						}
						<go>5__13 = null;
					}
					else
					{
						<go>5__14 = GameObject.Find("Bushes");
						if ((Object)(object)<go>5__14 != (Object)null && ((Object)<go>5__14.transform.parent).name == "Container")
						{
							<go>5__14.SetActive(true);
						}
						<go>5__14 = null;
					}
					if (currentConfig.disableSea)
					{
						((Component)Object.FindObjectOfType<WaterObject>(true)).gameObject.SetActive(false);
					}
					else
					{
						((Component)Object.FindObjectOfType<WaterObject>(true)).gameObject.SetActive(true);
					}
					<playerCam>5__2 = ((Component)PlayerSingleton<PlayerCamera>.Instance).transform.GetChild(0);
					if ((Object)(object)<playerCam>5__2 != (Object)null)
					{
						<flash>5__15 = <playerCam>5__2.Find("Flashlight");
						if ((Object)(object)<flash>5__15 != (Object)null)
						{
							<spot>5__16 = <flash>5__15.Find("Spot Light");
							if ((Object)(object)<spot>5__16 != (Object)null)
							{
								<flashLight>5__17 = ((Component)<spot>5__16).GetComponent<Light>();
								<flashLight>5__17.intensity = currentConfig.flashLightIntensity;
								<flashLight>5__17.range = currentConfig.flashLightRange;
								<flashLight>5__17 = null;
							}
							<spot>5__16 = null;
						}
						<flash>5__15 = null;
					}
					PlayerSingleton<PlayerCamera>.Instance.Camera.farClipPlane = currentConfig.camFarClipPlane;
					reloading = false;
					MelonLogger.Msg("Configuration applied");
					<>2__current = null;
					<>1__state = 2;
					return true;
				case 2:
					<>1__state = -1;
					return false;
				}
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		[CompilerGenerated]
		private sealed class <TrashRoutine>d__17 : IEnumerator<object>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private object <>2__current;

			public XOTweaks <>4__this;

			private TrashManager[] <>s__1;

			private int <>s__2;

			private TrashManager <mgr>5__3;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <TrashRoutine>d__17(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>s__1 = null;
				<mgr>5__3 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_0031: Unknown result type (might be due to invalid IL or missing references)
				//IL_003b: Expected O, but got Unknown
				//IL_00a2: 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_0088: Unknown result type (might be due to invalid IL or missing references)
				//IL_0092: Expected O, but got Unknown
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>2__current = (object)new WaitForSeconds(5f);
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					if (!<>4__this.registered)
					{
						return false;
					}
					if (currentConfig.trashClearThreshold > 9000)
					{
						return false;
					}
					break;
				case 2:
				{
					<>1__state = -1;
					Scene activeScene = SceneManager.GetActiveScene();
					if (((Scene)(ref activeScene)).buildIndex == 1)
					{
						mgrs = Object.FindObjectsOfType<TrashManager>(true);
						<>s__1 = mgrs;
						for (<>s__2 = 0; <>s__2 < <>s__1.Length; <>s__2++)
						{
							<mgr>5__3 = <>s__1[<>s__2];
							mgrs[0].DestroyAllTrash();
							<mgr>5__3 = null;
						}
						<>s__1 = null;
					}
					break;
				}
				}
				<>2__current = (object)new WaitForSeconds((float)currentConfig.trashClearThreshold);
				<>1__state = 2;
				return true;
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		private static ModConfig currentConfig;

		private bool registered = false;

		private bool firstTimeLoad = false;

		private static bool reloading;

		private static Light sun;

		private static LightShadows sunShadowType;

		private static Light moon;

		private static LightShadows moonShadowType;

		private static GameObject bushesRef;

		private static TrashManager[] mgrs;

		private static object trashCoro;

		public override void OnInitializeMelon()
		{
			((MelonBase)this).OnInitializeMelon();
			currentConfig = ConfigLoader.Load();
			MelonLogger.Msg("XOTweaks - by XOWithSauce | Performance, Utility, Configuration");
		}

		public override void OnSceneWasInitialized(int buildIndex, string sceneName)
		{
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Expected O, but got Unknown
			if (buildIndex == 1 && (Object)(object)Singleton<LoadManager>.Instance != (Object)null && !registered && !firstTimeLoad)
			{
				firstTimeLoad = true;
				Singleton<LoadManager>.Instance.onLoadComplete.AddListener(new UnityAction(OnLoadCompleteCb));
			}
			if (buildIndex != 1 && registered)
			{
				registered = false;
			}
		}

		private void OnLoadCompleteCb()
		{
			if (!registered)
			{
				currentConfig = ConfigLoader.Load();
				MelonCoroutines.Start(SetupSettings());
				trashCoro = MelonCoroutines.Start(TrashRoutine());
				registered = true;
			}
		}

		public override void OnUpdate()
		{
			if (registered && currentConfig != null && currentConfig.hotReloadEnabled && Input.GetKey((KeyCode)306) && Input.GetKey((KeyCode)114) && !reloading)
			{
				reloading = true;
				if (trashCoro != null)
				{
					MelonCoroutines.Stop(trashCoro);
				}
				MelonLogger.Msg("Hot Reload XOTweaks config");
				currentConfig = ConfigLoader.Load();
				trashCoro = MelonCoroutines.Start(TrashRoutine());
				MelonCoroutines.Start(SetupSettings());
			}
		}

		[IteratorStateMachine(typeof(<SetupSettings>d__16))]
		public static IEnumerator SetupSettings()
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <SetupSettings>d__16(0);
		}

		[IteratorStateMachine(typeof(<TrashRoutine>d__17))]
		private IEnumerator TrashRoutine()
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <TrashRoutine>d__17(0)
			{
				<>4__this = this
			};
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}