using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("AbraxisAudio")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("AbraxisAudio")]
[assembly: AssemblyCopyright("Copyright © 2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("4fbc7476-f78b-4b10-924f-04f539f679d0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace CustomWwiseSoundbanks;
public static class CustomWwiseAPI
{
public static bool IsReady => CustomWwiseSoundbanksPlugin.IsReady;
public static bool IsBankLoaded(string bankName)
{
return CustomWwiseSoundbanksPlugin.IsBankLoaded(bankName);
}
public static uint PlayEvent(string eventName)
{
return PlayEvent(eventName, null);
}
public static uint PlayEvent(string eventName, GameObject gameObject)
{
if (string.IsNullOrEmpty(eventName))
{
ManualLogSource logger = CustomWwiseSoundbanksPlugin.Logger;
if (logger != null)
{
logger.LogWarning((object)"Cannot play event with null/empty name");
}
return 0u;
}
if ((Object)(object)gameObject == (Object)null && AudioBankManager.HasInstance)
{
gameObject = ((Component)AudioBankManager.Instance).gameObject;
}
if ((Object)(object)gameObject != (Object)null && (Object)(object)gameObject.GetComponent<AkGameObj>() == (Object)null)
{
ManualLogSource logger2 = CustomWwiseSoundbanksPlugin.Logger;
if (logger2 != null)
{
logger2.LogInfo((object)("Attempting to Post Event on object " + ((Object)gameObject).name + " (" + ((object)gameObject).GetType().Name + ") without AK Game Object. Adding One"));
}
gameObject.AddComponent<AkGameObj>();
}
uint num = AkSoundEngine.PostEvent(eventName, gameObject);
if (num == 0)
{
ManualLogSource logger3 = CustomWwiseSoundbanksPlugin.Logger;
if (logger3 != null)
{
logger3.LogWarning((object)("Failed to post event '" + eventName + "' - event may not exist in loaded banks"));
}
}
return num;
}
public static void StopEvent(uint playingId)
{
if (playingId != 0)
{
AkSoundEngine.StopPlayingID(playingId);
}
}
public static void StopEvent(string eventName)
{
if (!string.IsNullOrEmpty(eventName))
{
AkSoundEngine.StopAll();
}
}
public static void RegisterEventReplacement(string originalEventName, string customEventName)
{
CustomWwiseSoundbanksPlugin.RegisterEventReplacement(originalEventName, customEventName);
}
public static void RegisterEventReplacement(uint originalEventId, uint customEventId)
{
CustomWwiseSoundbanksPlugin.RegisterEventReplacement(originalEventId, customEventId);
}
public static void UnregisterEventReplacement(string originalEventName)
{
CustomWwiseSoundbanksPlugin.UnregisterEventReplacement(originalEventName);
}
public static void UnregisterEventReplacement(uint originalEventId)
{
CustomWwiseSoundbanksPlugin.UnregisterEventReplacement(originalEventId);
}
public static void ClearAllReplacements()
{
CustomWwiseSoundbanksPlugin.ClearAllReplacements();
}
public static void RegisterMusicConfig(string configId, string bankName, Dictionary<MusicState, string> musicStateEvents, string[] allowedEnvironments = null)
{
CustomWwiseMusicManager.RegisterMusicConfig(configId, bankName, musicStateEvents, allowedEnvironments);
}
public static void EnableMusicConfig(string configId)
{
CustomWwiseMusicManager.EnableMusicConfig(configId);
}
public static void DisableMusicConfig(string configId)
{
CustomWwiseMusicManager.DisableMusicConfig(configId);
}
public static void DisableAllMusicConfigs()
{
CustomWwiseMusicManager.DisableAllMusicConfigs();
}
public static void SetActiveMusicConfig(string configId)
{
CustomWwiseMusicManager.SetActiveMusicConfig(configId);
}
public static void UnregisterMusicConfig(string configId)
{
CustomWwiseMusicManager.UnregisterMusicConfig(configId);
}
public static string GetCurrentlyPlayingConfigId()
{
return CustomWwiseMusicManager.GetCurrentlyPlayingConfigId();
}
public static string[] GetActiveConfigIds()
{
return CustomWwiseMusicManager.GetActiveConfigIds();
}
public static bool IsConfigEnabled(string configId)
{
return CustomWwiseMusicManager.IsConfigEnabled(configId);
}
public static string GetActiveMusicConfigId()
{
return CustomWwiseMusicManager.GetCurrentlyPlayingConfigId();
}
public static float GetGameMusicVolume()
{
if (AudioBankManager.HasInstance)
{
try
{
Type type = typeof(AudioBankManager).Assembly.GetType("Settings");
if ((object)type != null)
{
FieldInfo field = type.GetField("MusicVolume", BindingFlags.Static | BindingFlags.Public);
if ((object)field != null)
{
object value = field.GetValue(null);
if (value != null)
{
PropertyInfo property = value.GetType().GetProperty("Value");
if ((object)property != null)
{
return (float)property.GetValue(value, null);
}
}
}
}
}
catch
{
}
}
return 1f;
}
public static float GetGameSFXVolume()
{
if (AudioBankManager.HasInstance)
{
try
{
Type type = typeof(AudioBankManager).Assembly.GetType("Settings");
if ((object)type != null)
{
FieldInfo field = type.GetField("SFXVolume", BindingFlags.Static | BindingFlags.Public);
if ((object)field != null)
{
object value = field.GetValue(null);
if (value != null)
{
PropertyInfo property = value.GetType().GetProperty("Value");
if ((object)property != null)
{
return (float)property.GetValue(value, null);
}
}
}
}
}
catch
{
}
}
return 1f;
}
public static void SetRTPCValue(string rtpcName, float value)
{
if (AudioBankManager.HasInstance)
{
AudioBankManager.Instance.SetRTPCValue(rtpcName, value);
}
}
public static void SetRTPCValue(string rtpcName, float value, GameObject gameObject)
{
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)gameObject != (Object)null)
{
AkSoundEngine.SetRTPCValue(rtpcName, value, gameObject);
}
}
public static void SetSwitch(string switchGroup, string switchState, GameObject gameObject)
{
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
if ((Object)(object)gameObject != (Object)null)
{
AkSoundEngine.SetSwitch(switchGroup, switchState, gameObject);
}
}
public static void SetState(string stateGroup, string stateValue)
{
if (AudioBankManager.HasInstance)
{
AudioBankManager.Instance.SetState(stateGroup, stateValue);
}
}
}
[BepInPlugin("cuttothechase.necropolis.abraxisaudio", "Abraxis Audio", "1.0.0")]
public class CustomWwiseSoundbanksPlugin : BaseUnityPlugin
{
[HarmonyPatch(typeof(AudioBankManager), "PostEvent", new Type[]
{
typeof(string),
typeof(GameObject)
})]
public class PostEventStringPatch
{
private static bool Prefix(ref string eventName, GameObject sourceObject)
{
if (Logger != null && (Object)(object)Instance != (Object)null && Instance._enableDebugLogging.Value)
{
Logger.LogInfo((object)("[PATCH] PostEvent called with: '" + eventName + "'"));
}
if (eventNameReplacements.TryGetValue(eventName, out var value))
{
Logger.LogInfo((object)("[REPLACE] Replacing event: '" + eventName + "' → '" + value + "'"));
eventName = value;
}
return true;
}
}
[HarmonyPatch(typeof(AudioBankManager), "PostEvent", new Type[]
{
typeof(uint),
typeof(GameObject)
})]
public class PostEventUintPatch
{
private static Dictionary<uint, uint> _computedIdReplacements = new Dictionary<uint, uint>();
private static bool Prefix(ref uint eventId, GameObject sourceObject)
{
if (_computedIdReplacements.TryGetValue(eventId, out var value))
{
Logger.LogInfo((object)$"[REPLACE] Replacing event ID: {eventId} → {value}");
eventId = value;
return true;
}
foreach (KeyValuePair<string, string> eventNameReplacement in eventNameReplacements)
{
uint num = ShortIDGenerator.Compute(eventNameReplacement.Key);
if (eventId == num)
{
uint num2 = ShortIDGenerator.Compute(eventNameReplacement.Value);
_computedIdReplacements[num] = num2;
Logger.LogInfo((object)$"[REPLACE] Replacing event: '{eventNameReplacement.Key}' (ID: {num}) → '{eventNameReplacement.Value}' (ID: {num2})");
eventId = num2;
return true;
}
}
if (eventIdReplacements.TryGetValue(eventId, out var value2))
{
Logger.LogInfo((object)$"[REPLACE] Replacing event ID: {eventId} → {value2}");
eventId = value2;
}
return true;
}
}
[HarmonyPatch(typeof(AudioBankManager), "SetMusicState")]
public class SetMusicStatePatch
{
private static bool Prefix(MusicState nextMusicState)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
return CustomWwiseMusicManager.HandleMusicStateChange(nextMusicState);
}
}
[HarmonyPatch(typeof(AudioBankManager), "SetEnvironmentState")]
public class SetEnvironmentStatePatch
{
private static void Postfix(AudioState_EnvironmentSet next)
{
//IL_0001: Unknown result type (might be due to invalid IL or missing references)
CustomWwiseMusicManager.HandleEnvironmentChange(next);
}
}
public const string PLUGIN_GUID = "cuttothechase.necropolis.abraxisaudio";
public const string PLUGIN_NAME = "Abraxis Audio";
public const string PLUGIN_VERSION = "1.0.0";
internal static ManualLogSource Logger;
internal static CustomWwiseSoundbanksPlugin Instance;
private static Dictionary<string, string> eventNameReplacements = new Dictionary<string, string>();
private static Dictionary<uint, uint> eventIdReplacements = new Dictionary<uint, uint>();
private static HashSet<string> loadedCustomBanks = new HashSet<string>();
private static bool isReady = false;
private static List<GCHandle> bankHandles = new List<GCHandle>();
private ConfigEntry<bool> _enableDebugLogging;
public static bool IsReady => isReady;
private void Awake()
{
//IL_0049: Unknown result type (might be due to invalid IL or missing references)
//IL_004f: Expected O, but got Unknown
Logger = ((BaseUnityPlugin)this).Logger;
Instance = this;
_enableDebugLogging = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "EnableDebugLogging", true, "Enable detailed logging for custom soundbanks");
CustomWwiseMusicManager.Initialize(Logger, _enableDebugLogging);
Harmony val = new Harmony("cuttothechase.necropolis.abraxisaudio");
val.PatchAll();
Logger.LogInfo((object)"Abraxis Audio v1.0.0 loaded!");
Logger.LogInfo((object)"Event replacement system enabled - modders can now register event replacements via CustomWwiseAPI");
Logger.LogInfo((object)"Music management system enabled - modders can configure environment-aware music via CustomWwiseAPI");
Logger.LogInfo((object)"Will scan all plugin directories for .bnk files");
((MonoBehaviour)this).StartCoroutine(InitializeWhenReady());
}
private IEnumerator InitializeWhenReady()
{
while (!AudioBankManager.HasInstance || !AkInitializer.HasInstance)
{
yield return (object)new WaitForSeconds(0.5f);
}
yield return (object)new WaitForSeconds(1f);
Logger.LogInfo((object)"AudioBankManager ready, scanning for custom soundbanks...");
ScanAndLoadCustomBanks();
isReady = true;
Logger.LogInfo((object)"Custom Wwise Soundbanks system ready!");
}
private void ScanAndLoadCustomBanks()
{
string pluginPath = Paths.PluginPath;
Logger.LogInfo((object)("Scanning for custom banks in all plugin directories under: " + pluginPath));
if (!Directory.Exists(pluginPath))
{
Logger.LogError((object)("Plugins directory doesn't exist: " + pluginPath));
return;
}
string[] directories = Directory.GetDirectories(pluginPath);
Logger.LogInfo((object)$"Found {directories.Length} plugin directory(ies) to scan");
string[] array = directories;
foreach (string text in array)
{
string fileName = Path.GetFileName(text);
Logger.LogInfo((object)("Scanning plugin directory: " + fileName));
ScanDirectoryForBanks(text);
}
Logger.LogInfo((object)("Scanning root plugins folder: " + pluginPath));
string[] files = Directory.GetFiles(pluginPath, "*.bnk");
Logger.LogInfo((object)$"Found {files.Length} .bnk file(s) in root plugins folder");
string[] array2 = files;
foreach (string text2 in array2)
{
string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(text2);
if (fileNameWithoutExtension.Equals("Init", StringComparison.OrdinalIgnoreCase))
{
Logger.LogInfo((object)"Skipping Init.bnk in root folder");
continue;
}
Logger.LogInfo((object)("Processing root bank file: " + text2));
LoadCustomBank(fileNameWithoutExtension, text2);
}
Logger.LogInfo((object)$"Scan complete! Loaded {loadedCustomBanks.Count} custom soundbank(s) total");
}
private void ScanDirectoryForBanks(string directory)
{
try
{
Logger.LogInfo((object)("Scanning directory: " + directory));
string[] files = Directory.GetFiles(directory, "*.bnk");
Logger.LogInfo((object)$"Found {files.Length} .bnk file(s) in {directory}");
string[] array = files;
foreach (string text in array)
{
string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(text);
Logger.LogInfo((object)("Processing bank file: " + text));
if (fileNameWithoutExtension.Equals("Init", StringComparison.OrdinalIgnoreCase))
{
Logger.LogInfo((object)"Skipping Init.bnk");
}
else
{
LoadCustomBank(fileNameWithoutExtension, text);
}
}
string[] directories = Directory.GetDirectories(directory);
Logger.LogInfo((object)$"Found {directories.Length} subdirectory(ies)");
string[] array2 = directories;
foreach (string directory2 in array2)
{
ScanDirectoryForBanks(directory2);
}
}
catch (Exception ex)
{
Logger.LogError((object)("Error scanning directory " + directory + ": " + ex.Message));
Logger.LogError((object)("Stack trace: " + ex.StackTrace));
}
}
private void LoadCustomBank(string bankName, string bankPath)
{
//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
//IL_00e5: Invalid comparison between Unknown and I4
//IL_0125: Unknown result type (might be due to invalid IL or missing references)
//IL_0129: Invalid comparison between Unknown and I4
//IL_0178: Unknown result type (might be due to invalid IL or missing references)
try
{
Logger.LogInfo((object)("Attempting to load bank: " + bankName + " from path: " + bankPath));
if (loadedCustomBanks.Contains(bankName))
{
Logger.LogWarning((object)("Bank '" + bankName + "' already loaded, skipping duplicate"));
return;
}
if (!File.Exists(bankPath))
{
Logger.LogError((object)("Bank file does not exist: " + bankPath));
return;
}
byte[] array = File.ReadAllBytes(bankPath);
Logger.LogInfo((object)$"Read {array.Length} bytes from bank file");
uint num = 0u;
GCHandle item = GCHandle.Alloc(array, GCHandleType.Pinned);
try
{
IntPtr intPtr = item.AddrOfPinnedObject();
AKRESULT val = AkSoundEngine.LoadBank(intPtr, (uint)array.Length, ref num);
Logger.LogInfo((object)$"LoadBank (from memory) result for '{bankName}': {val}, BankID: {num}");
if ((int)val == 1)
{
loadedCustomBanks.Add(bankName);
bankHandles.Add(item);
Logger.LogInfo((object)$"✓ Loaded custom soundbank: {bankName} (ID: {num})");
}
else if ((int)val == 69)
{
loadedCustomBanks.Add(bankName);
item.Free();
Logger.LogInfo((object)("Bank '" + bankName + "' was already loaded"));
}
else
{
item.Free();
Logger.LogError((object)$"✗ Failed to load bank '{bankName}': {val}");
}
}
finally
{
}
}
catch (Exception ex)
{
Logger.LogError((object)("Exception loading bank '" + bankName + "': " + ex.Message));
Logger.LogError((object)("Stack trace: " + ex.StackTrace));
}
}
public static void RegisterEventReplacement(string originalEventName, string customEventName)
{
if (string.IsNullOrEmpty(originalEventName) || string.IsNullOrEmpty(customEventName))
{
Logger.LogWarning((object)"Cannot register event replacement with null/empty names");
return;
}
if (eventNameReplacements.ContainsKey(originalEventName))
{
Logger.LogWarning((object)("Event replacement for '" + originalEventName + "' already exists, overwriting"));
eventNameReplacements[originalEventName] = customEventName;
}
else
{
eventNameReplacements.Add(originalEventName, customEventName);
}
Logger.LogInfo((object)("Registered event replacement: '" + originalEventName + "' → '" + customEventName + "'"));
}
public static void RegisterEventReplacement(uint originalEventId, uint customEventId)
{
if (eventIdReplacements.ContainsKey(originalEventId))
{
Logger.LogWarning((object)$"Event replacement for ID {originalEventId} already exists, overwriting");
eventIdReplacements[originalEventId] = customEventId;
}
else
{
eventIdReplacements.Add(originalEventId, customEventId);
}
Logger.LogInfo((object)$"Registered event replacement: {originalEventId} → {customEventId}");
}
public static void UnregisterEventReplacement(string originalEventName)
{
if (eventNameReplacements.Remove(originalEventName))
{
Logger.LogInfo((object)("Removed event replacement for '" + originalEventName + "'"));
}
}
public static void UnregisterEventReplacement(uint originalEventId)
{
if (eventIdReplacements.Remove(originalEventId))
{
Logger.LogInfo((object)$"Removed event replacement for ID {originalEventId}");
}
}
public static void ClearAllReplacements()
{
eventNameReplacements.Clear();
eventIdReplacements.Clear();
Logger.LogInfo((object)"Cleared all event replacements");
}
public static bool IsBankLoaded(string bankName)
{
return loadedCustomBanks.Contains(bankName);
}
public static IEnumerable<string> GetLoadedBanks()
{
return loadedCustomBanks.AsEnumerable();
}
}
internal static class CustomWwiseMusicManager
{
private class MusicConfig
{
public string BankName;
public Dictionary<MusicState, string> MusicStateEvents;
public HashSet<AudioState_EnvironmentSet> AllowedEnvironments;
public bool EnabledForAllEnvironments;
public MusicConfig()
{
MusicStateEvents = new Dictionary<MusicState, string>();
AllowedEnvironments = new HashSet<AudioState_EnvironmentSet>();
EnabledForAllEnvironments = false;
}
}
private static ManualLogSource Logger;
private static ConfigEntry<bool> _enableDebugLogging;
private static Dictionary<string, MusicConfig> musicConfigs = new Dictionary<string, MusicConfig>();
private static List<string> activeConfigIds = new List<string>();
private static uint currentMusicPlayingId = 0u;
private static string currentPlayingConfigId = null;
private static MusicState currentMusicState = (MusicState)4;
private static MusicState? pendingMusicStateForFirstActivation = null;
public static void Initialize(ManualLogSource logger, ConfigEntry<bool> enableDebugLogging)
{
Logger = logger;
_enableDebugLogging = enableDebugLogging;
}
public static void RegisterMusicConfig(string configId, string bankName, Dictionary<MusicState, string> musicStateEvents, string[] allowedEnvironments = null)
{
//IL_0097: Unknown result type (might be due to invalid IL or missing references)
//IL_009c: Unknown result type (might be due to invalid IL or missing references)
//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
if (string.IsNullOrEmpty(configId))
{
ManualLogSource logger = Logger;
if (logger != null)
{
logger.LogWarning((object)"Cannot register music config with null/empty ID");
}
return;
}
MusicConfig musicConfig = new MusicConfig
{
BankName = bankName,
MusicStateEvents = (musicStateEvents ?? new Dictionary<MusicState, string>())
};
if (allowedEnvironments == null || allowedEnvironments.Length == 0 || (allowedEnvironments.Length == 1 && allowedEnvironments[0].Equals("All", StringComparison.OrdinalIgnoreCase)))
{
musicConfig.EnabledForAllEnvironments = true;
}
else
{
foreach (string text in allowedEnvironments)
{
try
{
AudioState_EnvironmentSet item = (AudioState_EnvironmentSet)Enum.Parse(typeof(AudioState_EnvironmentSet), text, ignoreCase: true);
musicConfig.AllowedEnvironments.Add(item);
}
catch (ArgumentException)
{
ManualLogSource logger2 = Logger;
if (logger2 != null)
{
logger2.LogWarning((object)("Unknown environment name: " + text));
}
}
}
}
if (musicConfigs.ContainsKey(configId))
{
ManualLogSource logger3 = Logger;
if (logger3 != null)
{
logger3.LogWarning((object)("Music config '" + configId + "' already exists, overwriting"));
}
}
musicConfigs[configId] = musicConfig;
ManualLogSource logger4 = Logger;
if (logger4 != null)
{
logger4.LogInfo((object)("Registered music config '" + configId + "' for bank '" + bankName + "' (" + (musicConfig.EnabledForAllEnvironments ? "all environments" : $"{musicConfig.AllowedEnvironments.Count} specific environments") + ")"));
}
}
public static void EnableMusicConfig(string configId)
{
//IL_00da: Unknown result type (might be due to invalid IL or missing references)
//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
//IL_0138: Unknown result type (might be due to invalid IL or missing references)
if (string.IsNullOrEmpty(configId))
{
ManualLogSource logger = Logger;
if (logger != null)
{
logger.LogWarning((object)"Cannot enable music config with null/empty ID");
}
return;
}
if (!musicConfigs.ContainsKey(configId))
{
ManualLogSource logger2 = Logger;
if (logger2 != null)
{
logger2.LogWarning((object)("Music config '" + configId + "' not found"));
}
return;
}
activeConfigIds.Remove(configId);
activeConfigIds.Insert(0, configId);
ManualLogSource logger3 = Logger;
if (logger3 != null)
{
logger3.LogInfo((object)$"Enabled music config '{configId}' (now have {activeConfigIds.Count} active config(s))");
}
if (!pendingMusicStateForFirstActivation.HasValue || activeConfigIds.Count != 1)
{
return;
}
ManualLogSource logger4 = Logger;
if (logger4 != null)
{
logger4.LogInfo((object)$"[MUSIC] Processing music state from before activation: {pendingMusicStateForFirstActivation.Value}");
}
MusicState value = pendingMusicStateForFirstActivation.Value;
pendingMusicStateForFirstActivation = null;
if (AudioBankManager.HasInstance)
{
AkSoundEngine.StopAll(((Component)AudioBankManager.Instance).gameObject);
ManualLogSource logger5 = Logger;
if (logger5 != null)
{
logger5.LogInfo((object)"[MUSIC] Stopped any game music to prepare for custom music");
}
}
HandleMusicStateChange(value);
}
public static void DisableMusicConfig(string configId)
{
//IL_008e: 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)
if (string.IsNullOrEmpty(configId))
{
ManualLogSource logger = Logger;
if (logger != null)
{
logger.LogWarning((object)"Cannot disable music config with null/empty ID");
}
}
else
{
if (!activeConfigIds.Remove(configId))
{
return;
}
ManualLogSource logger2 = Logger;
if (logger2 != null)
{
logger2.LogInfo((object)$"Disabled music config '{configId}' (now have {activeConfigIds.Count} active config(s))");
}
if (currentPlayingConfigId == configId && currentMusicPlayingId != 0)
{
StopCurrentMusic();
currentPlayingConfigId = null;
currentMusicState = (MusicState)4;
if (activeConfigIds.Count > 0)
{
HandleMusicStateChange(currentMusicState);
}
}
}
}
public static void DisableAllMusicConfigs()
{
//IL_002b: Unknown result type (might be due to invalid IL or missing references)
if (activeConfigIds.Count > 0)
{
StopCurrentMusic();
activeConfigIds.Clear();
currentPlayingConfigId = null;
currentMusicState = (MusicState)4;
ManualLogSource logger = Logger;
if (logger != null)
{
logger.LogInfo((object)"Disabled all music configs");
}
}
}
public static void SetActiveMusicConfig(string configId)
{
if (string.IsNullOrEmpty(configId))
{
DisableAllMusicConfigs();
}
else
{
EnableMusicConfig(configId);
}
}
public static void UnregisterMusicConfig(string configId)
{
if (activeConfigIds.Contains(configId))
{
DisableMusicConfig(configId);
}
if (musicConfigs.Remove(configId))
{
ManualLogSource logger = Logger;
if (logger != null)
{
logger.LogInfo((object)("Unregistered music config '" + configId + "'"));
}
}
}
private static AudioState_EnvironmentSet GetCurrentEnvironment()
{
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
//IL_0045: Unknown result type (might be due to invalid IL or missing references)
//IL_003c: Unknown result type (might be due to invalid IL or missing references)
//IL_0041: Unknown result type (might be due to invalid IL or missing references)
//IL_0048: Unknown result type (might be due to invalid IL or missing references)
if (!AudioBankManager.HasInstance)
{
return (AudioState_EnvironmentSet)2;
}
FieldInfo field = typeof(AudioBankManager).GetField("currentEnvironmentSet", BindingFlags.Instance | BindingFlags.NonPublic);
if ((object)field != null)
{
return (AudioState_EnvironmentSet)field.GetValue(AudioBankManager.Instance);
}
return (AudioState_EnvironmentSet)2;
}
private static bool ShouldConfigPlayInCurrentEnvironment(MusicConfig config)
{
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
if (config.EnabledForAllEnvironments)
{
return true;
}
AudioState_EnvironmentSet currentEnvironment = GetCurrentEnvironment();
return config.AllowedEnvironments.Contains(currentEnvironment);
}
private static void StopCurrentMusic()
{
if (currentMusicPlayingId != 0)
{
AkSoundEngine.StopPlayingID(currentMusicPlayingId);
currentMusicPlayingId = 0u;
}
}
public static bool HandleMusicStateChange(MusicState nextMusicState)
{
//IL_011d: Unknown result type (might be due to invalid IL or missing references)
//IL_011e: Unknown result type (might be due to invalid IL or missing references)
//IL_0031: Unknown result type (might be due to invalid IL or missing references)
//IL_0079: Unknown result type (might be due to invalid IL or missing references)
//IL_0172: Unknown result type (might be due to invalid IL or missing references)
//IL_0177: Unknown result type (might be due to invalid IL or missing references)
//IL_0158: 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_00b6: Unknown result type (might be due to invalid IL or missing references)
//IL_0312: Unknown result type (might be due to invalid IL or missing references)
//IL_0313: Unknown result type (might be due to invalid IL or missing references)
//IL_02d9: Unknown result type (might be due to invalid IL or missing references)
//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
//IL_0202: Unknown result type (might be due to invalid IL or missing references)
//IL_0203: Unknown result type (might be due to invalid IL or missing references)
//IL_02ff: Unknown result type (might be due to invalid IL or missing references)
//IL_0269: Unknown result type (might be due to invalid IL or missing references)
//IL_0279: Unknown result type (might be due to invalid IL or missing references)
if (Logger != null && _enableDebugLogging != null && _enableDebugLogging.Value)
{
ManualLogSource logger = Logger;
if (logger != null)
{
logger.LogInfo((object)$"[MUSIC PATCH] SetMusicState called: {nextMusicState}, Active Configs: {activeConfigIds.Count}");
}
}
if (activeConfigIds.Count == 0)
{
if (!pendingMusicStateForFirstActivation.HasValue)
{
pendingMusicStateForFirstActivation = nextMusicState;
if (Logger != null && _enableDebugLogging != null && _enableDebugLogging.Value)
{
ManualLogSource logger2 = Logger;
if (logger2 != null)
{
logger2.LogInfo((object)$"[MUSIC PATCH] No active configs yet - queuing state '{nextMusicState}' and blocking game music");
}
}
return false;
}
if (Logger != null && _enableDebugLogging != null && _enableDebugLogging.Value)
{
ManualLogSource logger3 = Logger;
if (logger3 != null)
{
logger3.LogInfo((object)$"[MUSIC PATCH] Still no active configs - allowing game music for '{nextMusicState}'");
}
}
return true;
}
if (nextMusicState == currentMusicState && currentMusicPlayingId != 0)
{
if (_enableDebugLogging.Value)
{
ManualLogSource logger4 = Logger;
if (logger4 != null)
{
logger4.LogInfo((object)$"[MUSIC] Already playing music for state '{nextMusicState}' - ignoring duplicate call");
}
}
return false;
}
AudioState_EnvironmentSet currentEnvironment = GetCurrentEnvironment();
foreach (string activeConfigId in activeConfigIds)
{
if (!musicConfigs.TryGetValue(activeConfigId, out var value) || !CustomWwiseSoundbanksPlugin.IsBankLoaded(value.BankName) || !ShouldConfigPlayInCurrentEnvironment(value) || !value.MusicStateEvents.TryGetValue(nextMusicState, out var value2))
{
continue;
}
StopCurrentMusic();
currentMusicState = nextMusicState;
currentPlayingConfigId = activeConfigId;
if (!string.IsNullOrEmpty(value2))
{
GameObject val = (AudioBankManager.HasInstance ? ((Component)AudioBankManager.Instance).gameObject : null);
currentMusicPlayingId = AkSoundEngine.PostEvent(value2, val);
if (_enableDebugLogging.Value)
{
ManualLogSource logger5 = Logger;
if (logger5 != null)
{
logger5.LogInfo((object)($"[MUSIC] Playing '{value2}' from config '{activeConfigId}' for state '{nextMusicState}' " + $"(Environment: {currentEnvironment}, Playing ID: {currentMusicPlayingId})"));
}
}
}
return false;
}
if (currentMusicPlayingId != 0)
{
StopCurrentMusic();
currentPlayingConfigId = null;
currentMusicState = (MusicState)4;
if (_enableDebugLogging.Value)
{
ManualLogSource logger6 = Logger;
if (logger6 != null)
{
logger6.LogInfo((object)$"[MUSIC] No active config matches environment '{currentEnvironment}' - stopping custom music");
}
}
}
currentMusicState = nextMusicState;
return true;
}
public static void HandleEnvironmentChange(AudioState_EnvironmentSet newEnvironment)
{
//IL_0036: Unknown result type (might be due to invalid IL or missing references)
//IL_0115: Unknown result type (might be due to invalid IL or missing references)
//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
//IL_0100: Unknown result type (might be due to invalid IL or missing references)
//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
if (activeConfigIds.Count == 0)
{
return;
}
if (_enableDebugLogging.Value)
{
ManualLogSource logger = Logger;
if (logger != null)
{
logger.LogInfo((object)$"[MUSIC] Environment changed to '{newEnvironment}'");
}
}
if (currentMusicPlayingId != 0 && currentPlayingConfigId != null && musicConfigs.TryGetValue(currentPlayingConfigId, out var value))
{
if (!ShouldConfigPlayInCurrentEnvironment(value))
{
StopCurrentMusic();
currentPlayingConfigId = null;
if (_enableDebugLogging.Value)
{
ManualLogSource logger2 = Logger;
if (logger2 != null)
{
logger2.LogInfo((object)$"[MUSIC] Current config '{currentPlayingConfigId}' not valid in '{newEnvironment}' - checking other configs");
}
}
HandleMusicStateChange(currentMusicState);
}
else if (_enableDebugLogging.Value)
{
ManualLogSource logger3 = Logger;
if (logger3 != null)
{
logger3.LogInfo((object)$"[MUSIC] Current config still valid in '{newEnvironment}' - keeping music");
}
}
}
else
{
HandleMusicStateChange(currentMusicState);
}
}
public static string GetCurrentlyPlayingConfigId()
{
return currentPlayingConfigId;
}
public static string[] GetActiveConfigIds()
{
return activeConfigIds.ToArray();
}
public static bool IsConfigEnabled(string configId)
{
return activeConfigIds.Contains(configId);
}
}