using System;
using System.Collections;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Threading.Tasks;
using BasyFirstMod;
using BasyFirstMod.Patches;
using BepInEx;
using BepInEx.Logging;
using GamblersMod.Patches;
using GameNetcodeStuff;
using HarmonyLib;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.Networking;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("BasyFirstMod")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("BasyFirstMod")]
[assembly: AssemblyCopyright("Copyright © 2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("867e47e4-570f-443e-ace1-3ae15c3555b9")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace GamblersMod.Patches
{
public class GameNetworkManagerPatch
{
[HarmonyPatch(typeof(GameNetworkManager), "Start")]
[HarmonyPostfix]
public static void StartPatch(GameNetworkManager __instance)
{
BasyFirstPlugin.BasyLogger.LogInfo((object)"GameNetworkManagerPatch Start Start");
BasyFirstPlugin.BasyLogger.LogInfo((object)"GameNetworkManagerPatch Start End");
}
[HarmonyPostfix]
[HarmonyPatch(typeof(GameNetworkManager), "StartDisconnect")]
public static void StartDisconnectPatch()
{
}
}
}
namespace BasyFirstMod
{
[BepInPlugin("Basy.FirstMod", "Basy first mod", "1.0.0")]
public class BasyFirstPlugin : BaseUnityPlugin
{
private const string modGuid = "Basy.FirstMod";
private const string modName = "Basy first mod";
private readonly Harmony harmony = new Harmony("Basy.FirstMod");
private static BasyFirstPlugin Instance = new BasyFirstPlugin();
public static ManualLogSource BasyLogger;
public void Awake()
{
if ((Object)(object)Instance == (Object)null)
{
Instance = this;
BasyLogger = Logger.CreateLogSource("Basy.FirstMod");
BasySoundManager.Instance = new BasySoundManager();
}
BasyLogger.LogInfo((object)"BasyFirstPlugin Awake Start");
harmony.PatchAll(typeof(PlayerControllerBPatch));
harmony.PatchAll(typeof(StartOfRoundPatch));
harmony.PatchAll(typeof(RoundManagerPatch));
harmony.PatchAll(typeof(GameNetworkManagerPatch));
BasyLogger.LogInfo((object)"BasyFirstPlugin Awake End");
}
}
public class BasyFirstModNetworker : NetworkBehaviour
{
public static BasyFirstModNetworker Instance;
private void Awake()
{
BasyFirstPlugin.BasyLogger.LogInfo((object)"BasyFirstModNetworker Awake called");
}
private void Start()
{
BasyFirstPlugin.BasyLogger.LogInfo((object)"BasyFirstModNetworker Start called");
}
public void PlaySoundForPlayer(int playerId)
{
BasyFirstPlugin.BasyLogger.LogInfo((object)"BasyFirstModNetworker PlaySound Start");
if (((NetworkBehaviour)this).IsOwner)
{
BasyFirstPlugin.BasyLogger.LogInfo((object)"BasyFirstModNetworker PlaySound IsOwner true");
BasyFirstPlugin.BasyLogger.LogInfo((object)$"HasNetworkObject {((NetworkBehaviour)this).HasNetworkObject}");
BasyFirstPlugin.BasyLogger.LogInfo((object)$"NetworkObjectId {((NetworkBehaviour)this).NetworkObjectId}");
BasyFirstPlugin.BasyLogger.LogInfo((object)("name " + ((Object)this).name));
BasyFirstPlugin.BasyLogger.LogInfo((object)$"enabled {((Behaviour)this).enabled}");
BasyFirstPlugin.BasyLogger.LogInfo((object)$"gameObject {((Component)this).gameObject}");
BasyFirstPlugin.BasyLogger.LogInfo((object)$"IsLocalPlayer {((NetworkBehaviour)this).IsLocalPlayer}");
BasyFirstPlugin.BasyLogger.LogInfo((object)$"IsClient {((NetworkBehaviour)this).IsClient}");
BasyFirstPlugin.BasyLogger.LogInfo((object)$"IsHost {((NetworkBehaviour)this).IsHost}");
BasyFirstPlugin.BasyLogger.LogInfo((object)$"IsOwnedByServer {((NetworkBehaviour)this).IsOwnedByServer}");
Instance.PlaySoundForPlayerClient(playerId);
}
else
{
BasyFirstPlugin.BasyLogger.LogInfo((object)"BasyFirstModNetworker PlaySound IsOwner false");
Instance.PlaySoundForPlayerServer(playerId);
}
BasyFirstPlugin.BasyLogger.LogInfo((object)"BasyFirstModNetworker PlaySound end");
}
[ClientRpc]
public void PlaySoundForPlayerClient(int playerId)
{
BasySoundManager.Instance.PlaySound(playerId);
}
[ServerRpc(RequireOwnership = false)]
public void PlaySoundForPlayerServer(int playerId)
{
Instance.PlaySoundForPlayerClient(playerId);
}
}
public class BasySoundManager
{
public static BasySoundManager Instance;
public IEnumerator TestRoutine(int playerId)
{
yield return (object)new WaitForSeconds(0.1f);
}
public async void PlaySound(int playerId)
{
BasyFirstPlugin.BasyLogger.LogInfo((object)"BasySoundPlayer PlaySound Start");
PlayerControllerB player = StartOfRound.Instance.allPlayerScripts[playerId];
string path = Path.Combine(Directory.GetParent(Assembly.GetExecutingAssembly().Location).FullName, "Resources\\testSound2.wav");
BasyFirstPlugin.BasyLogger.LogInfo((object)("BasySoundPlayer Trying to load: " + path));
AudioClip clip = await LoadClip(path);
player.movementAudio.PlayOneShot(clip, 1f);
BasyFirstPlugin.BasyLogger.LogInfo((object)"BasySoundPlayer PlaySound End");
}
private async Task<AudioClip> LoadClip(string path)
{
AudioClip clip = null;
UnityWebRequest uwr = UnityWebRequestMultimedia.GetAudioClip(path, (AudioType)20);
try
{
uwr.SendWebRequest();
try
{
while (!uwr.isDone)
{
await Task.Delay(5);
}
if ((int)uwr.result == 2 || (int)uwr.result == 4 || (int)uwr.result == 3)
{
BasyFirstPlugin.BasyLogger.LogError((object)(uwr.error ?? ""));
}
else
{
clip = DownloadHandlerAudioClip.GetContent(uwr);
}
}
catch (Exception ex)
{
Exception err = ex;
BasyFirstPlugin.BasyLogger.LogError((object)(err.Message + ", " + err.StackTrace));
}
}
finally
{
((IDisposable)uwr)?.Dispose();
}
return clip;
}
}
internal class PlayerControllerBPatch
{
[HarmonyPatch(typeof(PlayerControllerB), "Update")]
[HarmonyPostfix]
public static void Update(PlayerControllerB __instance)
{
}
}
public class RoundManagerPatch
{
[HarmonyPatch(typeof(RoundManager), "SetExitIDs")]
[HarmonyPostfix]
public static void SetExitIDsPatch(ref RoundManager __instance, Vector3 mainEntrancePosition)
{
}
[HarmonyPatch(typeof(RoundManager), "Awake")]
[HarmonyPostfix]
public static void AwakePatch(RoundManager __instance)
{
BasyFirstPlugin.BasyLogger.LogInfo((object)"RoundManagerPatch AwakePatch Start");
BasyFirstModNetworker.Instance = ((Component)__instance).gameObject.AddComponent<BasyFirstModNetworker>();
BasyFirstPlugin.BasyLogger.LogInfo((object)("BasyFirstModNetworker.Instance is null: " + ((Object)(object)BasyFirstModNetworker.Instance == (Object)null)));
BasyFirstPlugin.BasyLogger.LogInfo((object)"RoundManagerPatch AwakePatch End");
}
}
}
namespace BasyFirstMod.Patches
{
public class StartOfRoundPatch
{
[HarmonyPatch(typeof(StartOfRound), "Start")]
[HarmonyPostfix]
public static void StartPatch(ref StartOfRound __instance)
{
BasyFirstPlugin.BasyLogger.LogInfo((object)"StartOfRoundPatch Start Start");
if (!((NetworkBehaviour)__instance).IsServer || (Object)(object)BasyFirstModNetworker.Instance == (Object)null)
{
}
BasyFirstPlugin.BasyLogger.LogInfo((object)"StartOfRoundPatch Start End");
}
[HarmonyPatch(typeof(StartOfRound), "Update")]
[HarmonyPostfix]
public static void UpdatePatch()
{
if (UnityInput.Current.GetKeyDown((KeyCode)112))
{
int num = (int)StartOfRound.Instance.localPlayerController.playerClientId;
BasyFirstPlugin.BasyLogger.LogInfo((object)"P PRESSED");
BasyFirstPlugin.BasyLogger.LogInfo((object)("By playerId: " + num));
PlayerControllerB[] allPlayerScripts = StartOfRound.Instance.allPlayerScripts;
foreach (PlayerControllerB val in allPlayerScripts)
{
int playerId = (int)val.playerClientId;
BasyFirstPlugin.BasyLogger.LogInfo((object)("Calling PlaySoundForPlayer for playerid: " + playerId));
BasyFirstModNetworker.Instance.PlaySoundForPlayer(playerId);
}
}
}
}
}