Decompiled source of SugarCoat v1.0.0

Mods/SugarCoat.dll

Decompiled 2 months ago
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BoneLib;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSLZ.Marrow;
using Il2CppSLZ.Marrow.PuppetMasta;
using Il2CppSystem;
using ImNotGonnaSugarCoatIt;
using Jevil;
using Jevil.PostProcessing;
using Jevil.Prefs;
using Jevil.Tweening;
using MelonLoader;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("ImNotGonnaSugarCoatIt")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany(null)]
[assembly: AssemblyProduct("ImNotGonnaSugarCoatIt")]
[assembly: AssemblyCopyright("Created by extraes")]
[assembly: AssemblyTrademark(null)]
[assembly: ComVisible(false)]
[assembly: AssemblyFileVersion("1.0.0")]
[assembly: NeutralResourcesLanguage("en")]
[assembly: MelonInfo(typeof(global::ImNotGonnaSugarCoatIt.ImNotGonnaSugarCoatIt), "ImNotGonnaSugarCoatIt", "1.0.0", "extraes", null)]
[assembly: MelonGame("Stress Level Zero", "BONELAB")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyVersion("1.0.0.0")]
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;
		}
	}
}
namespace ImNotGonnaSugarCoatIt
{
	public static class BuildInfo
	{
		public const string Name = "ImNotGonnaSugarCoatIt";

		public const string Author = "extraes";

		public const string Company = null;

		public const string Version = "1.0.0";

		public const string DownloadLink = null;
	}
	[Preferences("SugarCoat", false)]
	public class ImNotGonnaSugarCoatIt : MelonMod
	{
		internal static ImNotGonnaSugarCoatIt instance;

		private const string BUILT_IN_IMAGE = "Built-in";

		[RangePref(0f, 1f, 0.1f)]
		private static float fadeDuration = 0.5f;

		[RangePref(0f, 1f, 0.1f)]
		private static float vineBoomVol = 0.6f;

		[RangePref(0f, 1f, 0.1f)]
		private static float damnVol = 0.6f;

		[Pref]
		private static string imagePath = "Built-in";

		private static AudioSource audioSrcBoom;

		private static AudioSource audioSrcDamn;

		private static AudioClip vineBoom;

		private static AudioClip damn;

		private static Texture2D texture;

		private static Material postProcessMat;

		private static GlobalTextureDescriptor textureDescriptor;

		private static ShaderProperty<float> blendFactor = ShaderProperty<float>.op_Implicit("_BlendFactor");

		public ImNotGonnaSugarCoatIt()
		{
			instance = this;
		}

		public override void OnInitializeMelon()
		{
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Expected O, but got Unknown
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Expected O, but got Unknown
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			Preferences.Register<ImNotGonnaSugarCoatIt>();
			AssetBundle bundle = null;
			Extensions.UseEmbeddedResource(((MelonBase)this).MelonAssembly.Assembly, "SugarCoat.assets.bundle", (Action<byte[]>)delegate(byte[] b)
			{
				bundle = AssetBundle.LoadFromMemory(Il2CppStructArray<byte>.op_Implicit(b));
			});
			vineBoom = ((Il2CppObjectBase)bundle.LoadAsset("VineBoom")).Cast<AudioClip>();
			damn = ((Il2CppObjectBase)bundle.LoadAsset("Dayum")).Cast<AudioClip>();
			postProcessMat = new Material(((Il2CppObjectBase)bundle.LoadAsset("ScreenBlendSugarcoat")).Cast<Shader>());
			bool flag = imagePath == "Built-in";
			if (!flag && !File.Exists(imagePath))
			{
				Warn("Image not found at given path '" + imagePath + "' falling back to built-in image!");
				flag = true;
			}
			if (flag)
			{
				texture = ((Il2CppObjectBase)bundle.LoadAsset("ImNotGonnaSugarCoatIt")).Cast<Texture2D>();
			}
			else
			{
				texture = new Texture2D(2, 2);
				ImageConversion.LoadImage(texture, Il2CppStructArray<byte>.op_Implicit(File.ReadAllBytes(imagePath)));
			}
			Extensions.Persist((Object)(object)vineBoom, true);
			Extensions.Persist((Object)(object)damn, true);
			Extensions.Persist((Object)(object)texture, true);
			Extensions.Persist((Object)(object)postProcessMat, true);
			textureDescriptor = new GlobalTextureDescriptor("_OverlayTexSugarcoat", (Texture)(object)texture);
			PostProcessingManager.SetGlobalTexture(textureDescriptor);
			PuppetMaster.OnDeathStatsEvent += Action<PuppetMaster>.op_Implicit((Action<PuppetMaster>)PuppetMasterKilled);
			Hooking.OnLevelLoaded += SetupAudioSources;
		}

		private void PuppetMasterKilled(PuppetMaster pm)
		{
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Expected O, but got Unknown
			if (!(((Health)Instances.Player_Health).curr_Health < 0.75f * ((Health)Instances.Player_Health).max_Health))
			{
				blendFactor.SetOn(postProcessMat, 1f);
				GenericFloatTween val = new GenericFloatTween((Func<float>)(() => blendFactor.GetFrom(postProcessMat)), (Action<float>)delegate(float f)
				{
					blendFactor.SetOn(postProcessMat, f);
				}, 0f, fadeDuration, (Object)(object)postProcessMat);
				audioSrcBoom.volume = vineBoomVol;
				audioSrcBoom.Play();
				audioSrcDamn.volume = damnVol;
				audioSrcDamn.Play();
				TweenTweenExtensions.Unique<GenericFloatTween>(TweenTweenExtensions.UseCustomInterpolator<GenericFloatTween>(TweenTweenExtensions.RunOnFinish<GenericFloatTween>(val, (Action)delegate
				{
					PostProcessingManager.RemoveFromStack(postProcessMat);
				}), (Func<float, float>)((float t) => t * t))).Play();
				PostProcessingManager.AddToStack(postProcessMat);
			}
		}

		private void SetupAudioSources(LevelInfo li)
		{
			GameObject gameObject = ((Component)Player.Head).gameObject;
			audioSrcBoom = gameObject.AddComponent<AudioSource>();
			audioSrcDamn = gameObject.AddComponent<AudioSource>();
			audioSrcBoom.outputAudioMixerGroup = Instances.SFXMixer;
			audioSrcDamn.outputAudioMixerGroup = Instances.SFXMixer;
			audioSrcBoom.clip = vineBoom;
			audioSrcDamn.clip = damn;
		}

		internal static void Log(string str)
		{
			((MelonBase)instance).LoggerInstance.Msg(str);
		}

		internal static void Log(object obj)
		{
			((MelonBase)instance).LoggerInstance.Msg(obj?.ToString() ?? "null");
		}

		internal static void Warn(string str)
		{
			((MelonBase)instance).LoggerInstance.Warning(str);
		}

		internal static void Warn(object obj)
		{
			((MelonBase)instance).LoggerInstance.Warning(obj?.ToString() ?? "null");
		}

		internal static void Error(string str)
		{
			((MelonBase)instance).LoggerInstance.Error(str);
		}

		internal static void Error(object obj)
		{
			((MelonBase)instance).LoggerInstance.Error(obj?.ToString() ?? "null");
		}
	}
}