using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security.Cryptography;
using AK.Wwise;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using NineSolsAPI.Utils;
using RCGFSM.Audios;
using RCGFSM.GameObjects;
using TPoVMod.Soundwork;
using TPoVMod.System;
using UnityEngine;
using UnityEngine.SceneManagement;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("TPoVMod")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("TPoV Mod")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+eb243b8e011f1e942ff8f9a12e02f57045c5f2ef")]
[assembly: AssemblyProduct("TPoVMod")]
[assembly: AssemblyTitle("TPoVMod")]
[assembly: AssemblyVersion("1.0.0.0")]
[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 TPoVMod
{
internal static class Log
{
private static ManualLogSource? logSource;
internal static void Init(ManualLogSource logSource)
{
Log.logSource = logSource;
}
internal static void Debug(object data)
{
ManualLogSource? obj = logSource;
if (obj != null)
{
obj.LogDebug(data);
}
}
internal static void Error(object data)
{
ManualLogSource? obj = logSource;
if (obj != null)
{
obj.LogError(data);
}
}
internal static void Fatal(object data)
{
ManualLogSource? obj = logSource;
if (obj != null)
{
obj.LogFatal(data);
}
}
internal static void Info(object data)
{
ManualLogSource? obj = logSource;
if (obj != null)
{
obj.LogInfo(data);
}
}
internal static void Message(object data)
{
ManualLogSource? obj = logSource;
if (obj != null)
{
obj.LogMessage(data);
}
}
internal static void Warning(object data)
{
ManualLogSource? obj = logSource;
if (obj != null)
{
obj.LogWarning(data);
}
}
}
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInPlugin("TPoVMod", "TPoVMod", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
private Harmony harmony;
internal static Action<Scene, LoadSceneMode>? OnSceneLoaded;
private void Awake()
{
Log.Init(((BaseUnityPlugin)this).Logger);
RCGLifeCycle.DontDestroyForever(((Component)this).gameObject);
GameObject[] array = SoundsLoader.LoadSounds();
for (int i = 0; i < array.Length; i++)
{
Object.DontDestroyOnLoad((Object)(object)array[i]);
}
SceneManager.sceneLoaded += OnSceneChanged;
SoundsPatcher.Subscribe();
harmony = Harmony.CreateAndPatchAll(typeof(Plugin).Assembly, (string)null);
((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin TPoVMod is loaded!");
}
private void OnSceneChanged(Scene scene, LoadSceneMode mode)
{
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
//IL_000b: Unknown result type (might be due to invalid IL or missing references)
OnSceneLoaded?.Invoke(scene, mode);
}
private void OnDestroy()
{
harmony.UnpatchSelf();
}
}
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "TPoVMod";
public const string PLUGIN_NAME = "TPoVMod";
public const string PLUGIN_VERSION = "1.0.0";
}
}
namespace TPoVMod.System
{
internal static class SoundsPatcher
{
private static SoundPlayer? _menuPausePlayer;
private static SoundPlayer? _menuResumePlayer;
private static bool _hasReplacedUIEvents;
public static void Subscribe()
{
Plugin.OnSceneLoaded = (Action<Scene, LoadSceneMode>)Delegate.Combine(Plugin.OnSceneLoaded, new Action<Scene, LoadSceneMode>(HandleSceneChange));
}
private static void HandleSceneChange(Scene scene, LoadSceneMode mode)
{
if (!string.IsNullOrEmpty(((Scene)(ref scene)).name))
{
if (((Scene)(ref scene)).name.Contains("YiGung"))
{
HandleUIEventsReplacement();
HandleBGMEventsReplacement();
}
else
{
HandleUIEventsReset();
}
}
}
private static void HandleUIEventsReplacement()
{
try
{
GetUISoundPlayers();
_menuPausePlayer.soundName = "TPoV_MenuPause";
_menuResumePlayer.soundName = "TPoV_MenuResume";
_hasReplacedUIEvents = true;
}
catch (Exception ex)
{
Log.Error(ex.Message + ", " + ex.StackTrace);
}
}
private static void HandleUIEventsReset()
{
if (!_hasReplacedUIEvents)
{
return;
}
try
{
GetUISoundPlayers();
_menuPausePlayer.soundName = "MenuPauseSFX";
_menuResumePlayer.soundName = "MenuResumeSFX";
_hasReplacedUIEvents = false;
}
catch (Exception ex)
{
Log.Error(ex.Message + ", " + ex.StackTrace);
}
}
private static void GetUISoundPlayers()
{
try
{
if ((Object)(object)_menuPausePlayer == (Object)null)
{
_menuPausePlayer = ObjectUtils.LookupPath("GameCore(Clone)/RCG LifeCycle/UIManager/GameplayUICamera/UI-Canvas/[Tab] MenuTab/MenuPauseSFX").GetComponent<SoundPlayer>();
}
if ((Object)(object)_menuResumePlayer == (Object)null)
{
_menuResumePlayer = ObjectUtils.LookupPath("GameCore(Clone)/RCG LifeCycle/UIManager/GameplayUICamera/UI-Canvas/[Tab] MenuTab/MenuResumeSFX").GetComponent<SoundPlayer>();
}
}
catch (Exception ex)
{
Log.Error(ex.Message + ", " + ex.StackTrace);
}
}
private static void HandleBGMEventsReplacement()
{
//IL_0069: Unknown result type (might be due to invalid IL or missing references)
//IL_007e: Unknown result type (might be due to invalid IL or missing references)
//IL_0083: Unknown result type (might be due to invalid IL or missing references)
//IL_0085: Unknown result type (might be due to invalid IL or missing references)
try
{
GameObject obj = ObjectUtils.LookupPath("GameLevel/Room/Prefab/EventBinder/General Boss Fight FSM Object Variant/--[States]/FSM/[State] BossFighting_Phase1/[Action] BGM->BattleBGM");
GameObject val = ObjectUtils.LookupPath("GameLevel/Room/Prefab/EventBinder/General Boss Fight FSM Object Variant/FSM Animator/LogicRoot/Boss三階BGM/BGM_Boss_A11_P3");
GameObject val2 = ObjectUtils.LookupPath("GameLevel/Room/Prefab/EventBinder/General Boss Fight FSM Object Variant/--[States]/FSM/[State] BossAngryToPhase3/[Action] 三階BGM");
ChangeBGMAction component = obj.GetComponent<ChangeBGMAction>();
AmbienceSource component2 = val.GetComponent<AmbienceSource>();
if (component.dataList.Count > 0)
{
ChangeBGMData obj2 = component.dataList[0];
obj2.ambienceTask.ambience = "TPoV_Replacement1";
obj2.bgmEntry._bgmName = "TPoV_Replacement1";
}
component2.ambPair = new AmbPair
{
sound = "TPoV_Replacement1",
type = (AmbienceType)1
};
val2.GetComponent<GameObjectActivateAction>().enableObj.Clear();
}
catch (Exception ex)
{
Log.Error(ex.Message + ", " + ex.StackTrace);
}
}
}
}
namespace TPoVMod.Soundwork
{
internal static class SoundsLoader
{
internal static FieldInfo wwiseBankIdField = AccessTools.Field(typeof(WwiseObjectReference), "id");
internal static FieldInfo wwiseBankObjectNameField = AccessTools.Field(typeof(WwiseObjectReference), "objectName");
internal static GameObject[] LoadSounds()
{
CreateBankFile();
return CreateBankObj();
}
private static GameObject[] CreateBankObj()
{
//IL_0005: Unknown result type (might be due to invalid IL or missing references)
//IL_000b: Expected O, but got Unknown
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
//IL_0019: Expected O, but got Unknown
//IL_001e: Expected O, but got Unknown
//IL_001f: Unknown result type (might be due to invalid IL or missing references)
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_0026: Expected O, but got Unknown
//IL_002b: Expected O, but got Unknown
GameObject val = new GameObject("TPoV_Bank");
AkBank obj = val.AddComponent<AkBank>();
Bank val2 = new Bank();
Bank val3 = val2;
obj.data = val2;
WwiseBankReference val4 = new WwiseBankReference();
WwiseBankReference val5 = val4;
val3.WwiseObjectReference = val4;
WwiseBankReference obj2 = val5;
wwiseBankIdField.SetValue(obj2, 2903215819u);
wwiseBankObjectNameField.SetValue(obj2, "TPoV_Bank");
((AkTriggerHandler)obj).HandleEvent((GameObject)null);
return (GameObject[])(object)new GameObject[1] { val };
}
private static void CreateBankFile()
{
string dataPath = Application.dataPath;
string path = string.Empty;
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
path = "Windows";
}
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
path = "Mac";
}
string path2 = Path.Combine(dataPath, "StreamingAssets\\Audio\\GeneratedSoundBanks", path);
byte[] embeddedResource = AssemblyUtils.GetEmbeddedResource("TPoVMod.Resources.TPoV_Bank.bnk");
string path3 = Path.Combine(path2, "TPoV_Bank.bnk");
if (!File.Exists(path3))
{
File.WriteAllBytes(path3, embeddedResource);
return;
}
byte[] array = File.ReadAllBytes(path3);
if (embeddedResource != null && array.Length != embeddedResource.Length && !ComputeHash(embeddedResource).SequenceEqual(ComputeHash(array)))
{
File.WriteAllBytes(path3, embeddedResource);
}
}
private static byte[] ComputeHash(byte[] data)
{
using SHA256 sHA = SHA256.Create();
return sHA.ComputeHash(data);
}
}
}
namespace TPoVMod.Config
{
internal static class ModConfig
{
internal const string BANKS_LOCATION = "StreamingAssets\\Audio\\GeneratedSoundBanks";
internal const string MOD_BANK_RESOURCES_LOCATION = "TPoVMod.Resources";
internal const string MOD_BANK_NAME = "TPoV_Bank";
internal const uint MOD_BANK_ID = 2903215819u;
internal const string TARGET_SCEN_NAME_PART = "YiGung";
internal const string MENU_RESUME_SOUND_PLAYER_PATH = "GameCore(Clone)/RCG LifeCycle/UIManager/GameplayUICamera/UI-Canvas/[Tab] MenuTab/MenuResumeSFX";
internal const string MENU_RESUME_SOUND_PLAYER_ORIGINAL_EVENT = "MenuResumeSFX";
internal const string MENU_RESUME_SOUND_PLAYER_REPLACEMENT_EVENT = "TPoV_MenuResume";
internal const string MENU_PAUSE_SOUND_PLAYER_PATH = "GameCore(Clone)/RCG LifeCycle/UIManager/GameplayUICamera/UI-Canvas/[Tab] MenuTab/MenuPauseSFX";
internal const string MENU_PAUSE_SOUND_PLAYER_ORIGINAL_EVENT = "MenuPauseSFX";
internal const string MENU_PAUSE_SOUND_PLAYER_REPLACEMENT_EVENT = "TPoV_MenuPause";
internal const string STATE_BGM_ACTIVATOR_PATH = "GameLevel/Room/Prefab/EventBinder/General Boss Fight FSM Object Variant/--[States]/FSM/[State] BossAngryToPhase3/[Action] 三階BGM";
internal const string REPLACEMENT_EVENT = "TPoV_Replacement1";
internal const string MY_WILL_SOUND_SOURCE_PATH = "GameLevel/Room/Prefab/EventBinder/General Boss Fight FSM Object Variant/--[States]/FSM/[State] BossFighting_Phase1/[Action] BGM->BattleBGM";
internal const string THE_PATH_SOUND_SOURCE_PATH = "GameLevel/Room/Prefab/EventBinder/General Boss Fight FSM Object Variant/FSM Animator/LogicRoot/Boss三階BGM/BGM_Boss_A11_P3";
}
}