using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Unity.Netcode;
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: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: AssemblyCompany("LTOWSliderMinigameMusicMod")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("LTOWSliderMinigameMusicMod")]
[assembly: AssemblyTitle("LTOWSliderMinigameMusicMod")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.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.Module, AllowMultiple = false, Inherited = false)]
internal sealed class RefSafetyRulesAttribute : Attribute
{
public readonly int Version;
public RefSafetyRulesAttribute(int P_0)
{
Version = P_0;
}
}
}
namespace LTOWSliderMinigameMusicMod
{
public class Configs
{
private static ManualLogSource Logger;
public static ConfigEntry<int> musicVolume;
public static ConfigEntry<bool> pauseMusic;
public Configs(ConfigFile cfg)
{
//IL_0027: Unknown result type (might be due to invalid IL or missing references)
//IL_0031: Expected O, but got Unknown
musicVolume = cfg.Bind<int>("Customization", "Song Volume", 66, new ConfigDescription("Set the volume of the Slider music.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), Array.Empty<object>()));
pauseMusic = cfg.Bind<bool>("Customization", "Pause Song", true, "If true, the song will pause and resume from the same point the next time a worm grabs a pardner. If false, the song will always start from the beginning.");
}
public static void GetLogger(ManualLogSource PluginLogger)
{
Logger = PluginLogger;
}
public static void DisplayConfigs()
{
Logger.LogInfo((object)$"Config [Song Volume] is set to a value of {musicVolume.Value}");
if (pauseMusic.Value)
{
Logger.LogInfo((object)"Config [Pause Song] is set to TRUE. The Slider music will pause when a worm loses hold of a pardner, and resume from the same point the next time that worm grabs a pardner.");
}
else
{
Logger.LogInfo((object)"Config [Pause Song] is set to FALSE. The Slider music will always start from the beginning of the song.");
}
}
}
internal class HarmonyPatches
{
[HarmonyPatch(typeof(Player), "OnNetworkSpawn")]
public class NewPlayerOnNetworkSpawn
{
[HarmonyPostfix]
public static void Postfix(Player __instance)
{
if ((Object)(object)__instance == (Object)null)
{
Logger.LogError((object)"somehow spawned on null player");
return;
}
Logger.LogDebug((object)$"Start() Postfix on #{((NetworkBehaviour)__instance).NetworkObjectId}");
Plugin.InstantiateAudioPrefab(((Component)__instance).gameObject);
}
}
[HarmonyPatch(typeof(WormMouth), "SnapJawsOnPlayer_ClientRPC")]
public class StartMusic
{
[HarmonyPostfix]
public static void Postfix(ulong _playerObjectID, ulong _wormPlayerID)
{
Logger.LogDebug((object)"SnapJawsOnPlayer_ClientRPC");
StartMusicGeneral(_playerObjectID, _wormPlayerID);
}
}
[HarmonyPatch(typeof(WormMouth))]
public class StopMusic
{
[HarmonyPrefix]
[HarmonyPatch("DestroyFoodDummy_Client")]
public static void DestroyFoodDummy_ClientPrefix(WormMouth __instance)
{
Logger.LogDebug((object)"DestroyFoodDummy_Client()");
StopMusicGeneral(__instance);
}
[HarmonyPrefix]
[HarmonyPatch("ClearMouth_Server")]
public static void ClearMouth_ServerPrefix(WormMouth __instance)
{
Logger.LogDebug((object)"ClearMouth_Server()");
StopMusicGeneral(__instance);
}
[HarmonyPostfix]
[HarmonyPatch("GetNutrientsFromPlayerGrabbedTimes")]
public static void Test_DestroyFoodDummy(WormMouth __instance)
{
Logger.LogDebug((object)$"Test - lastPardnerGrabbed_Ulong: set to {__instance.lastPardnerGrabbed_Ulong}");
}
}
[HarmonyPatch(typeof(TimeOfDayManager))]
public class ClientRPCParamTest
{
[HarmonyPostfix]
[HarmonyPatch("SyncTimeOfDayForLateJoiner_ServerRPC")]
public static void Server()
{
Logger.LogDebug((object)"Test - RpcParams: ServerRPC");
}
[HarmonyPostfix]
[HarmonyPatch("SyncTimeOfDayForLateJoiner_ClientRPC")]
public static void Client(ref ClientRpcParams _clientRpcParams)
{
Logger.LogDebug((object)"Test - RpcParams: ClientRPC");
}
}
private static ManualLogSource Logger;
public static void GetLogger(ManualLogSource PluginLogger)
{
Logger = PluginLogger;
}
private static void StartMusicGeneral(ulong _playerObjectID, ulong _wormPlayerID)
{
Logger.LogDebug((object)$"_playerObjectID {_playerObjectID} | _wormPlayerID {_wormPlayerID}");
NetworkObject val = null;
Player val2 = null;
try
{
val = NetworkManager.Singleton.SpawnManager.SpawnedObjects[_playerObjectID];
}
catch
{
Logger.LogWarning((object)$"StartMusic failed to find anything for _playerObjectID {_playerObjectID}");
}
if ((Object)(object)val != (Object)null)
{
val2 = ((Component)val).GetComponent<Player>();
}
if ((Object)(object)val2 == (Object)null)
{
Logger.LogError((object)"error: could not retrieve player from StartMusic, returning");
return;
}
Logger.LogDebug((object)$"pardner: {val2}");
NetworkObject val3 = null;
WormPlayer val4 = null;
try
{
val3 = NetworkManager.Singleton.SpawnManager.SpawnedObjects[Plugin.GetPlayersNetworkObjectId(_wormPlayerID)];
}
catch
{
Logger.LogWarning((object)$"StartMusic failed to find anything for _wormPlayerID {_wormPlayerID}");
}
if ((Object)(object)val3 != (Object)null)
{
val4 = ((Component)val3).GetComponent<WormPlayer>();
}
if ((Object)(object)val4 != (Object)null)
{
Logger.LogDebug((object)("worm: " + ((Object)val4).name));
}
bool flag = false;
if ((Object)(object)GameManager.Singleton != (Object)null && (Object)(object)GameManager.Singleton.localPlayerObject != (Object)null)
{
GameObject localPlayerObject = GameManager.Singleton.localPlayerObject;
if ((Object)(object)localPlayerObject == (Object)(object)((Component)val2).gameObject || ((Object)(object)val4 != (Object)null && (Object)(object)localPlayerObject == (Object)(object)((Component)val4).gameObject))
{
Logger.LogDebug((object)"found local player involved in newly started chase");
flag = true;
}
}
Plugin.HandleSong(((Component)val2).gameObject, playOrPause: true, !flag);
}
private static void StopMusicGeneral(WormMouth __instance)
{
if ((Object)(object)__instance == (Object)null)
{
Logger.LogWarning((object)"got StopMusic for no worm");
return;
}
Logger.LogDebug((object)$"__instance {__instance} | playerIDInMouth {__instance.playerIDInMouth}");
NetworkObject val = null;
Player val2 = null;
try
{
if (__instance.playerIDInMouth != 1000000)
{
val = NetworkManager.Singleton.SpawnManager.SpawnedObjects[Plugin.GetPlayersNetworkObjectId(__instance.playerIDInMouth)];
}
}
catch
{
Logger.LogWarning((object)$"StopMusic failed to find anything for __instance.playerIDInMouth {__instance.playerIDInMouth}");
}
if ((Object)(object)val != (Object)null)
{
val2 = ((Component)val).GetComponent<Player>();
}
if ((Object)(object)val2 != (Object)null)
{
Plugin.HandleSong(((Component)val2).gameObject, playOrPause: false);
}
}
}
[BepInPlugin("local.SimonTendo.LTOWSliderMinigameMusicMod", "LTOWSliderMinigameMusicMod", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
internal static ManualLogSource Logger;
public static GameObject audioPrefab;
public static Configs MyConfig { get; internal set; }
private void Awake()
{
//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
Logger = ((BaseUnityPlugin)this).Logger;
Logger.LogInfo((object)"Plugin LTOWSliderMinigameMusicMod is loaded!");
AssetBundle val = AssetBundle.LoadFromFile(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "firstwormtownbundle"));
if ((Object)(object)val == (Object)null)
{
Logger.LogError((object)"Failed to load AssetBundle");
return;
}
audioPrefab = val.LoadAsset<GameObject>("Assets/SliderAudioObject.prefab");
if ((Object)(object)audioPrefab == (Object)null)
{
Logger.LogError((object)"Failed to load GameObject");
return;
}
Logger.LogDebug((object)"Successfully loaded AssetBundle and GameObject");
new Harmony("LTOWSliderMinigameMusicMod").PatchAll();
MyConfig = new Configs(((BaseUnityPlugin)this).Config);
SendLoggers();
Configs.DisplayConfigs();
}
private static void SendLoggers()
{
HarmonyPatches.GetLogger(Logger);
Configs.GetLogger(Logger);
}
public static void InstantiateAudioPrefab(GameObject gObject)
{
if ((Object)(object)gObject == (Object)null)
{
Logger.LogWarning((object)"null GameObject given to InstantiateAudioPrefab");
return;
}
GameObject val = Object.Instantiate<GameObject>(audioPrefab, gObject.transform);
AudioSource val2 = null;
if ((Object)(object)val != (Object)null)
{
val2 = val.GetComponent<AudioSource>();
}
if ((Object)(object)val2 != (Object)null)
{
val2.volume = (float)Configs.musicVolume.Value / 100f;
}
Logger.LogDebug((object)$"instantiated audio with volume {val2.volume}");
}
public static AudioSource GetInstantiatedAudio(GameObject fromObj)
{
AudioSource result = null;
Transform val = fromObj.transform.Find("SliderAudioObject(Clone)");
if ((Object)(object)val != (Object)null)
{
result = ((Component)val).GetComponent<AudioSource>();
}
return result;
}
public static void HandleSong(GameObject fromObj, bool playOrPause, bool audio3D = true)
{
AudioSource instantiatedAudio = GetInstantiatedAudio(fromObj);
if ((Object)(object)instantiatedAudio == (Object)null)
{
Logger.LogWarning((object)$"no instantiatedAudio found on {fromObj}!");
return;
}
Logger.LogDebug((object)$"HandleSong(): instantiatedAudio on {((Component)instantiatedAudio).transform.parent} | playOrPause {playOrPause} | audio3D {audio3D}");
if (playOrPause)
{
if (!instantiatedAudio.isPlaying)
{
instantiatedAudio.spatialBlend = (audio3D ? 1 : 0);
instantiatedAudio.Play();
}
}
else if (instantiatedAudio.isPlaying)
{
if (Configs.pauseMusic.Value)
{
instantiatedAudio.Pause();
}
else
{
instantiatedAudio.Stop();
}
}
}
public static ulong GetPlayersNetworkObjectId(ulong ownerClientID)
{
ulong num = 1000000uL;
bool flag = false;
if ((Object)(object)GameManager.Singleton != (Object)null)
{
if (!flag && GameManager.Singleton.humanPlayerScripts != null)
{
foreach (Player humanPlayerScript in GameManager.Singleton.humanPlayerScripts)
{
if (((NetworkBehaviour)humanPlayerScript).OwnerClientId == ownerClientID)
{
num = ((NetworkBehaviour)humanPlayerScript).NetworkObjectId;
flag = true;
break;
}
}
}
if (!flag && GameManager.Singleton.wormPlayerScripts != null)
{
foreach (WormPlayer wormPlayerScript in GameManager.Singleton.wormPlayerScripts)
{
if (((NetworkBehaviour)wormPlayerScript).OwnerClientId == ownerClientID)
{
num = ((NetworkBehaviour)wormPlayerScript).NetworkObjectId;
flag = true;
break;
}
}
}
}
Logger.LogDebug((object)$"GetNetworkObjectId successful? {flag} | toReturn {num}");
return num;
}
}
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "LTOWSliderMinigameMusicMod";
public const string PLUGIN_NAME = "LTOWSliderMinigameMusicMod";
public const string PLUGIN_VERSION = "1.0.0";
}
}
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
internal sealed class IgnoresAccessChecksToAttribute : Attribute
{
public IgnoresAccessChecksToAttribute(string assemblyName)
{
}
}
}