Decompiled source of Corruption v0.1.2

WwiseVolumeController.dll

Decompiled 4 months ago
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Text.Json;
using System.Text.Json.Serialization;
using BepInEx;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using GTFO.API.JSON;
using HarmonyLib;
using Il2CppInterop.Runtime.Injection;
using UnityEngine;
using WwiseVolumeController.Utils;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("WwiseVolumeController")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("WwiseVolumeController")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("96d71ef4-5db6-4030-ae67-5473cc8f899e")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.1", FrameworkDisplayName = ".NET Framework 4.7.1")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace WwiseVolumeController
{
	public class GameParameterConnectorConverter : JsonConverter<GameParameterConnector>
	{
		public override GameParameterConnector Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Invalid comparison between Unknown and I4
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Invalid comparison between Unknown and I4
			if ((int)((Utf8JsonReader)(ref reader)).TokenType == 7)
			{
				return new GameParameterConnector(((Utf8JsonReader)(ref reader)).GetString());
			}
			if ((int)((Utf8JsonReader)(ref reader)).TokenType == 8)
			{
				return new GameParameterConnector(((Utf8JsonReader)(ref reader)).GetUInt32());
			}
			return default(GameParameterConnector);
		}

		public override void Write(Utf8JsonWriter writer, GameParameterConnector value, JsonSerializerOptions options)
		{
			if (value.HasName)
			{
				writer.WriteStringValue(value.ValueString);
			}
			else
			{
				writer.WriteNumberValue(value.ValueInt);
			}
		}

		public override bool CanConvert(Type typeToConvert)
		{
			return typeToConvert == typeof(GameParameterConnector);
		}
	}
	[Serializable]
	public struct GameParameterConnector
	{
		public uint ValueInt;

		public string ValueString;

		public bool HasName => !string.IsNullOrEmpty(ValueString);

		public static implicit operator GameParameterConnector(uint id)
		{
			return new GameParameterConnector(id);
		}

		public static implicit operator GameParameterConnector(string id)
		{
			return new GameParameterConnector(id);
		}

		public GameParameterConnector(string valueString)
		{
			ValueString = valueString;
			ValueInt = 0u;
		}

		public GameParameterConnector(uint valueInt)
		{
			ValueInt = valueInt;
			ValueString = null;
		}

		public void SetParameter(float rtpcVal)
		{
			if (HasName)
			{
				AkSoundEnginePINVOKE.CSharp_SetRTPCValue__SWIG_9(ValueString, rtpcVal);
			}
			else if (ValueInt != 0)
			{
				AkSoundEnginePINVOKE.CSharp_SetRTPCValue__SWIG_4(ValueInt, rtpcVal);
			}
		}
	}
	[Serializable]
	public class GameParameterSettings
	{
		public GameParameterConnector Volume_Music { get; set; }

		public GameParameterConnector Volume_Master { get; set; }

		public GameParameterConnector Volume_SFX { get; set; }

		public GameParameterConnector Volume_PlayerDialog { get; set; }
	}
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("WIS", "east.wwise.com", "0.0.1")]
	public class WwiseVolumeControllerEntry : BasePlugin
	{
		private static bool m_inited;

		private static GameObject m_wwiseControllerGameObject;

		public const string GUID = "WIS";

		public const string Name = "east.wwise.com";

		public const string Version = "0.0.1";

		public override void Load()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			new Harmony("WIS").PatchAll();
			ClassInjector.RegisterTypeInIl2Cpp<WwiseVolumeSettingsController>();
		}

		public static void OnGameStarted()
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Expected O, but got Unknown
			if (!m_inited)
			{
				m_inited = true;
				m_wwiseControllerGameObject = new GameObject("WwiseController");
				m_wwiseControllerGameObject.AddComponent<WwiseVolumeSettingsController>();
				Object.DontDestroyOnLoad((Object)(object)m_wwiseControllerGameObject);
			}
		}
	}
	public class WwiseVolumeSettingsController : MonoBehaviour
	{
		private JsonSerializerOptions m_serializeOptions;

		public static bool IsGameFocused = true;

		private bool m_hasSettings;

		private GameParameterSettings m_settings;

		public WwiseVolumeSettingsController()
		{
		}

		public WwiseVolumeSettingsController(IntPtr pointer)
			: base(pointer)
		{
		}

		private void Start()
		{
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Expected O, but got Unknown
			DebugLogger.Message("WwiseVolumeSettingsController.Start");
			string text = Path.Combine(Paths.ConfigPath, "WwiseGameParameters");
			if (!Directory.Exists(text))
			{
				Directory.CreateDirectory(text);
			}
			text = Path.Combine(text, "WwiseGameParameters.json");
			m_serializeOptions = new JsonSerializerOptions((JsonSerializerDefaults)0);
			m_serializeOptions.WriteIndented = true;
			m_serializeOptions.Converters.Add((JsonConverter)(object)new GameParameterConnectorConverter());
			if (!File.Exists(text))
			{
				m_settings = new GameParameterSettings();
				m_settings.Volume_SFX = "sfx_volume";
				m_settings.Volume_Music = 633463456u;
				m_settings.Volume_Master = "master_volume";
				m_settings.Volume_PlayerDialog = 432642346u;
				string contents = JsonSerializer.Serialize((object)m_settings, m_serializeOptions);
				File.WriteAllText(text, contents);
				DebugLogger.Warn("WwiseGameParameters doesn't exist! Creating a sample one for you to edit :D -> " + text);
			}
			else
			{
				DebugLogger.Message("Loading Custom WwiseGameParameters from path -> " + text);
				m_settings = JsonSerializer.Deserialize<GameParameterSettings>(File.ReadAllText(text), m_serializeOptions);
				m_hasSettings = true;
			}
		}

		private void Update()
		{
			UpdateCustomVolumes();
		}

		private void UpdateCustomVolumes()
		{
			if (m_hasSettings)
			{
				if (!IsGameFocused && CellSettingsManager.SettingsData.Audio.MuteInBackground.Value)
				{
					m_settings.Volume_SFX.SetParameter(0f);
					m_settings.Volume_Music.SetParameter(0f);
					m_settings.Volume_Master.SetParameter(0f);
					m_settings.Volume_PlayerDialog.SetParameter(0f);
				}
				else
				{
					m_settings.Volume_SFX.SetParameter(CellSettingsManager.SettingsData.Audio.SFXVolume.Value * 100f);
					m_settings.Volume_Music.SetParameter(CellSettingsManager.SettingsData.Audio.MusicVolume.Value * 100f);
					m_settings.Volume_Master.SetParameter(CellSettingsManager.SettingsData.Audio.MasterVolume.Value * 100f);
					m_settings.Volume_PlayerDialog.SetParameter(CellSettingsManager.SettingsData.Audio.DialogVolume.Value * 100f);
				}
			}
		}
	}
}
namespace WwiseVolumeController.Patches
{
	[HarmonyPatch(typeof(CellSettingsManager))]
	internal class Patch_CellSettingsManager
	{
		[HarmonyPostfix]
		[HarmonyPatch("OnApplicationFocus")]
		private static void Post_OnApplicationFocus(bool focus)
		{
			WwiseVolumeSettingsController.IsGameFocused = focus;
		}
	}
	[HarmonyPatch(typeof(StartMainGame))]
	internal class Patch_StartMainGame
	{
		[HarmonyPostfix]
		[HarmonyPatch("Start")]
		private static void Post_StartGame()
		{
			WwiseVolumeControllerEntry.OnGameStarted();
		}
	}
}
namespace WwiseVolumeController.Utils
{
	public static class DebugLogger
	{
		private static readonly ManualLogSource logger;

		private static readonly bool LogEnabled;

		static DebugLogger()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Expected O, but got Unknown
			logger = new ManualLogSource("Wwise-Paramter-Controller");
			LogEnabled = true;
			Logger.Sources.Add((ILogSource)(object)logger);
		}

		public static void Verbose(object msg)
		{
			logger.LogInfo(msg);
		}

		public static void Debug(object msg)
		{
			if (LogEnabled)
			{
				logger.LogDebug(msg);
			}
		}

		public static void Message(object msg)
		{
			if (LogEnabled)
			{
				logger.LogMessage(msg);
			}
		}

		public static void Error(object msg)
		{
			if (LogEnabled)
			{
				logger.LogError(msg);
			}
		}

		public static void Warn(object msg)
		{
			if (LogEnabled)
			{
				logger.LogWarning(msg);
			}
		}
	}
}