Decompiled source of Darkness v0.1.2

Silksong.Darkness/Silksong.Darkness.dll

Decompiled 3 months ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using HarmonyLib;
using HutongGames.PlayMaker;
using HutongGames.PlayMaker.Actions;
using Microsoft.CodeAnalysis;
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("Silksong.Darkness")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("0.1.2.0")]
[assembly: AssemblyInformationalVersion("0.1.2+33fc3f8b1983789ea69a0dbefed50f11e0fb762c")]
[assembly: AssemblyProduct("Silksong.Darkness")]
[assembly: AssemblyTitle("Silksong.Darkness")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.2.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.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[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 BepInEx
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class BepInAutoPluginAttribute : Attribute
	{
		public BepInAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace BepInEx.Preloader.Core.Patching
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	internal sealed class PatcherAutoPluginAttribute : Attribute
	{
		public PatcherAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace Silksong.Darkness
{
	[BepInPlugin("io.github.silksong_darkness", "Silksong.Darkness", "0.1.2")]
	public class Silksong_DarknessPlugin : BaseUnityPlugin
	{
		public const string Id = "io.github.silksong_darkness";

		public static string Name => "Silksong.Darkness";

		public static string Version => "0.1.2";

		private void Awake()
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			((BaseUnityPlugin)this).Logger.LogInfo((object)("[Darkness] Plugin " + Name + " (io.github.silksong_darkness) has loaded!"));
			new Harmony("io.github.silksong_darkness").PatchAll();
		}
	}
	[HarmonyPatch(typeof(PlayMakerFSM), "Awake")]
	public static class VignetteFSM_AwakePatch
	{
		public static void Postfix(PlayMakerFSM __instance)
		{
			if (__instance.FsmName != "Darkness Control")
			{
				return;
			}
			FsmState val = null;
			FsmState val2 = null;
			FsmState[] fsmStates = __instance.FsmStates;
			foreach (FsmState val3 in fsmStates)
			{
				if (val3.Name == "Dark 2")
				{
					val = val3;
				}
				else if (val3.Name == "Dark 2 2")
				{
					val2 = val3;
				}
			}
			if (val == null || val2 == null)
			{
				Debug.LogError((object)"[Darkness] Could not find 'Dark 2' and 'Dark 2 2' states.");
				return;
			}
			changeDarkAction(val);
			changeDarkAction(val2);
			FsmState[] fsmStates2 = __instance.FsmStates;
			foreach (FsmState val4 in fsmStates2)
			{
				if (val4.Name == "Dark Lev Check")
				{
					FsmTransition[] transitions = val4.Transitions;
					foreach (FsmTransition val5 in transitions)
					{
						val5.ToState = "Dark 2";
						val5.ToFsmState = val;
					}
					Debug.Log((object)"[Darkness] Transition fixed and vignette forced Dark 2.");
				}
				else if (val4.Name == "Scene Reset")
				{
					FsmTransition[] transitions2 = val4.Transitions;
					foreach (FsmTransition val6 in transitions2)
					{
						val6.ToState = "Dark 2 2";
						val6.ToFsmState = val2;
					}
					Debug.Log((object)"[Darkness] Transition fixed and vignette forced Dark 2 2.");
				}
			}
		}

		private static void changeDarkAction(FsmState dark)
		{
			SetVector3XYZ action = dark.GetAction<SetVector3XYZ>(1);
			if (action == null)
			{
				Debug.LogError((object)"[Darkness] Could not find SetVector3XYZ action in Dark state.");
				return;
			}
			action.x = FsmFloat.op_Implicit(1.2f);
			action.y = FsmFloat.op_Implicit(1.6f);
			action.z = FsmFloat.op_Implicit(1.6f);
			SetVector3XYZ action2 = dark.GetAction<SetVector3XYZ>(2);
			if (action2 == null)
			{
				Debug.LogError((object)"[Darkness] Could not find SetVector3XYZ action in Dark state.");
				return;
			}
			action2.x = FsmFloat.op_Implicit(1.1f);
			action2.y = FsmFloat.op_Implicit(1.5f);
			action2.z = FsmFloat.op_Implicit(1.5f);
		}

		private static T? GetAction<T>(this FsmState state, int actionIndex) where T : FsmStateAction
		{
			if (actionIndex < 0 || actionIndex >= state.Actions.Length)
			{
				return default(T);
			}
			FsmStateAction obj = state.Actions[actionIndex];
			return (T)(object)((obj is T) ? obj : null);
		}
	}
	[HarmonyPatch(typeof(GameManager), "EnterHero")]
	public static class Darkness_EnterHeroPatch
	{
		public static void Postfix()
		{
			GameObject[] array = Object.FindObjectsByType<GameObject>((FindObjectsSortMode)0);
			GameObject[] array2 = array;
			foreach (GameObject val in array2)
			{
				if (((Object)val).name.Contains("Vignette Cutout"))
				{
					val.SetActive(false);
					Debug.Log((object)("[Darkness] Disabled Vignette Cutout object: " + ((Object)val).name));
				}
			}
		}
	}
	[HarmonyPatch(typeof(HeroController), "Update")]
	public static class Darkness_HeroUpdate
	{
		public static void Postfix()
		{
			if (Time.frameCount % 120 != 0)
			{
				return;
			}
			GameObject[] array = Object.FindObjectsByType<GameObject>((FindObjectsSortMode)0);
			GameObject[] array2 = array;
			foreach (GameObject val in array2)
			{
				if (((Object)val).name.Contains("Vignette Cutout") && val.activeSelf)
				{
					val.SetActive(false);
					Debug.Log((object)("[Darkness] Disabled Vignette Cutout object: " + ((Object)val).name));
				}
			}
		}
	}
}