using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using EmoteLaugh.Core;
using EmoteLaugh.NetcodePatcher;
using EmoteLaugh.Network;
using EmoteLaugh.Patches;
using GameNetcodeStuff;
using HarmonyLib;
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: AssemblyTitle("EmoteLaugh")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("EmoteLaugh")]
[assembly: AssemblyCopyright("Copyright © 2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("4bcabc86-bb82-403d-9f57-26cf2d20c2bf")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: NetcodePatchedAssembly]
internal class <Module>
{
static <Module>()
{
}
}
namespace EmoteLaugh.Network
{
public class NetworkHandler : NetworkBehaviour
{
public static NetworkHandler instance;
private void Awake()
{
instance = this;
}
private EmoteController GetEmoteController(ulong playerID)
{
NetworkObject networkObject = ((NetworkBehaviour)this).GetNetworkObject(playerID);
if ((Object)(object)networkObject == (Object)null)
{
ModBase.logger.LogError((object)("Could not find network object for this player ID " + playerID));
return null;
}
GameObject gameObject = ((Component)networkObject).gameObject;
if ((Object)(object)gameObject == (Object)null)
{
ModBase.logger.LogError((object)("Could not get game object for this player ID " + playerID));
return null;
}
EmoteController componentInChildren = gameObject.GetComponentInChildren<EmoteController>();
if ((Object)(object)componentInChildren == (Object)null)
{
ModBase.logger.LogError((object)("Could not find emote controller for this player ID " + playerID));
}
return componentInChildren;
}
[ServerRpc(RequireOwnership = false)]
public void PlayEmoteSoundServerRpc(ulong playerID, bool playLongAudio, int emoteID)
{
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_002e: Invalid comparison between Unknown and I4
//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
//IL_00cb: Invalid comparison between Unknown and I4
//IL_005f: Unknown result type (might be due to invalid IL or missing references)
//IL_0068: Unknown result type (might be due to invalid IL or missing references)
//IL_006d: Unknown result type (might be due to invalid IL or missing references)
//IL_0071: Unknown result type (might be due to invalid IL or missing references)
//IL_008a: Unknown result type (might be due to invalid IL or missing references)
//IL_0090: Unknown result type (might be due to invalid IL or missing references)
//IL_0099: Unknown result type (might be due to invalid IL or missing references)
//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
if (networkManager != null && networkManager.IsListening)
{
if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost))
{
ServerRpcParams val = default(ServerRpcParams);
FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendServerRpc(367101012u, val, (RpcDelivery)0);
BytePacker.WriteValueBitPacked(val2, playerID);
((FastBufferWriter)(ref val2)).WriteValueSafe<bool>(ref playLongAudio, default(ForPrimitives));
BytePacker.WriteValueBitPacked(val2, emoteID);
((NetworkBehaviour)this).__endSendServerRpc(ref val2, 367101012u, val, (RpcDelivery)0);
}
if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost))
{
PlayEmoteSoundClientRpc(playerID, playLongAudio, emoteID);
}
}
}
[ClientRpc]
public void PlayEmoteSoundClientRpc(ulong playerID, bool playLongAudio, int emoteID)
{
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_002e: Invalid comparison between Unknown and I4
//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
//IL_00cb: Invalid comparison between Unknown and I4
//IL_005f: Unknown result type (might be due to invalid IL or missing references)
//IL_0068: Unknown result type (might be due to invalid IL or missing references)
//IL_006d: Unknown result type (might be due to invalid IL or missing references)
//IL_0071: Unknown result type (might be due to invalid IL or missing references)
//IL_008a: Unknown result type (might be due to invalid IL or missing references)
//IL_0090: Unknown result type (might be due to invalid IL or missing references)
//IL_0099: Unknown result type (might be due to invalid IL or missing references)
//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
if (networkManager == null || !networkManager.IsListening)
{
return;
}
if ((int)base.__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
{
ClientRpcParams val = default(ClientRpcParams);
FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(2525985575u, val, (RpcDelivery)0);
BytePacker.WriteValueBitPacked(val2, playerID);
((FastBufferWriter)(ref val2)).WriteValueSafe<bool>(ref playLongAudio, default(ForPrimitives));
BytePacker.WriteValueBitPacked(val2, emoteID);
((NetworkBehaviour)this).__endSendClientRpc(ref val2, 2525985575u, val, (RpcDelivery)0);
}
if ((int)base.__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
{
EmoteController emoteController = GetEmoteController(playerID);
if ((Object)(object)emoteController != (Object)null)
{
emoteController.PlaySound(playLongAudio, emoteID, calledFromRpc: true);
}
}
}
[ServerRpc(RequireOwnership = false)]
public void StopEmoteSoundServerRpc(ulong playerID)
{
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_002e: Invalid comparison between Unknown and I4
//IL_0099: Unknown result type (might be due to invalid IL or missing references)
//IL_00a3: Invalid comparison between Unknown and I4
//IL_005f: Unknown result type (might be due to invalid IL or missing references)
//IL_0068: Unknown result type (might be due to invalid IL or missing references)
//IL_006d: Unknown result type (might be due to invalid IL or missing references)
//IL_0071: Unknown result type (might be due to invalid IL or missing references)
//IL_0089: Unknown result type (might be due to invalid IL or missing references)
NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
if (networkManager != null && networkManager.IsListening)
{
if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost))
{
ServerRpcParams val = default(ServerRpcParams);
FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendServerRpc(1902031379u, val, (RpcDelivery)0);
BytePacker.WriteValueBitPacked(val2, playerID);
((NetworkBehaviour)this).__endSendServerRpc(ref val2, 1902031379u, val, (RpcDelivery)0);
}
if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost))
{
StopEmoteSoundClientRpc(playerID);
}
}
}
[ClientRpc]
public void StopEmoteSoundClientRpc(ulong playerID)
{
//IL_0024: Unknown result type (might be due to invalid IL or missing references)
//IL_002e: Invalid comparison between Unknown and I4
//IL_0099: Unknown result type (might be due to invalid IL or missing references)
//IL_00a3: Invalid comparison between Unknown and I4
//IL_005f: Unknown result type (might be due to invalid IL or missing references)
//IL_0068: Unknown result type (might be due to invalid IL or missing references)
//IL_006d: Unknown result type (might be due to invalid IL or missing references)
//IL_0071: Unknown result type (might be due to invalid IL or missing references)
//IL_0089: Unknown result type (might be due to invalid IL or missing references)
NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
if (networkManager == null || !networkManager.IsListening)
{
return;
}
if ((int)base.__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
{
ClientRpcParams val = default(ClientRpcParams);
FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(1081301299u, val, (RpcDelivery)0);
BytePacker.WriteValueBitPacked(val2, playerID);
((NetworkBehaviour)this).__endSendClientRpc(ref val2, 1081301299u, val, (RpcDelivery)0);
}
if ((int)base.__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
{
EmoteController emoteController = GetEmoteController(playerID);
if ((Object)(object)emoteController != (Object)null)
{
emoteController.StopSound(calledFromRpc: true);
}
}
}
protected override void __initializeVariables()
{
((NetworkBehaviour)this).__initializeVariables();
}
[RuntimeInitializeOnLoadMethod]
internal static void InitializeRPCS_NetworkHandler()
{
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_001b: Expected O, but got Unknown
//IL_002c: Unknown result type (might be due to invalid IL or missing references)
//IL_0036: Expected O, but got Unknown
//IL_0047: Unknown result type (might be due to invalid IL or missing references)
//IL_0051: Expected O, but got Unknown
//IL_0062: Unknown result type (might be due to invalid IL or missing references)
//IL_006c: Expected O, but got Unknown
NetworkManager.__rpc_func_table.Add(367101012u, new RpcReceiveHandler(__rpc_handler_367101012));
NetworkManager.__rpc_func_table.Add(2525985575u, new RpcReceiveHandler(__rpc_handler_2525985575));
NetworkManager.__rpc_func_table.Add(1902031379u, new RpcReceiveHandler(__rpc_handler_1902031379));
NetworkManager.__rpc_func_table.Add(1081301299u, new RpcReceiveHandler(__rpc_handler_1081301299));
}
private static void __rpc_handler_367101012(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
{
//IL_0023: 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_0042: Unknown result type (might be due to invalid IL or missing references)
//IL_004b: Unknown result type (might be due to invalid IL or missing references)
//IL_005e: Unknown result type (might be due to invalid IL or missing references)
//IL_0080: Unknown result type (might be due to invalid IL or missing references)
NetworkManager networkManager = target.NetworkManager;
if (networkManager != null && networkManager.IsListening)
{
ulong playerID = default(ulong);
ByteUnpacker.ReadValueBitPacked(reader, ref playerID);
bool playLongAudio = default(bool);
((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref playLongAudio, default(ForPrimitives));
int emoteID = default(int);
ByteUnpacker.ReadValueBitPacked(reader, ref emoteID);
target.__rpc_exec_stage = (__RpcExecStage)1;
((NetworkHandler)(object)target).PlayEmoteSoundServerRpc(playerID, playLongAudio, emoteID);
target.__rpc_exec_stage = (__RpcExecStage)0;
}
}
private static void __rpc_handler_2525985575(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
{
//IL_0023: 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_0042: Unknown result type (might be due to invalid IL or missing references)
//IL_004b: Unknown result type (might be due to invalid IL or missing references)
//IL_005e: Unknown result type (might be due to invalid IL or missing references)
//IL_0080: Unknown result type (might be due to invalid IL or missing references)
NetworkManager networkManager = target.NetworkManager;
if (networkManager != null && networkManager.IsListening)
{
ulong playerID = default(ulong);
ByteUnpacker.ReadValueBitPacked(reader, ref playerID);
bool playLongAudio = default(bool);
((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref playLongAudio, default(ForPrimitives));
int emoteID = default(int);
ByteUnpacker.ReadValueBitPacked(reader, ref emoteID);
target.__rpc_exec_stage = (__RpcExecStage)2;
((NetworkHandler)(object)target).PlayEmoteSoundClientRpc(playerID, playLongAudio, emoteID);
target.__rpc_exec_stage = (__RpcExecStage)0;
}
}
private static void __rpc_handler_1902031379(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
{
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
//IL_0036: Unknown result type (might be due to invalid IL or missing references)
//IL_0050: Unknown result type (might be due to invalid IL or missing references)
NetworkManager networkManager = target.NetworkManager;
if (networkManager != null && networkManager.IsListening)
{
ulong playerID = default(ulong);
ByteUnpacker.ReadValueBitPacked(reader, ref playerID);
target.__rpc_exec_stage = (__RpcExecStage)1;
((NetworkHandler)(object)target).StopEmoteSoundServerRpc(playerID);
target.__rpc_exec_stage = (__RpcExecStage)0;
}
}
private static void __rpc_handler_1081301299(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
{
//IL_0023: Unknown result type (might be due to invalid IL or missing references)
//IL_0036: Unknown result type (might be due to invalid IL or missing references)
//IL_0050: Unknown result type (might be due to invalid IL or missing references)
NetworkManager networkManager = target.NetworkManager;
if (networkManager != null && networkManager.IsListening)
{
ulong playerID = default(ulong);
ByteUnpacker.ReadValueBitPacked(reader, ref playerID);
target.__rpc_exec_stage = (__RpcExecStage)2;
((NetworkHandler)(object)target).StopEmoteSoundClientRpc(playerID);
target.__rpc_exec_stage = (__RpcExecStage)0;
}
}
protected internal override string __getTypeName()
{
return "NetworkHandler";
}
}
}
namespace EmoteLaugh.Patches
{
internal class EmoteController : MonoBehaviour
{
private PlayerControllerB __player = null;
private AudioSource __playerAudio = null;
private float oldAudioSourceVolume = 0f;
private AudioClip oldAudioClip = null;
private const string emoteParamInAnimator = "emoteNumber";
private int previousEmoteID = 0;
private bool playingInterruptableAudio = false;
private bool playingSound = false;
private ulong GetPlayerID()
{
return ((Component)StartOfRound.Instance.localPlayerController).GetComponent<NetworkObject>().NetworkObjectId;
}
private void Start()
{
__player = ((Component)this).GetComponent<PlayerControllerB>();
__playerAudio = __player.movementAudio;
}
private void LateUpdate()
{
if (!((NetworkBehaviour)__player).IsOwner || !__player.isPlayerControlled)
{
return;
}
if (__player.performingEmote)
{
int integer = __player.playerBodyAnimator.GetInteger("emoteNumber");
if (integer != previousEmoteID)
{
if (playingSound)
{
playingSound = false;
AboutToStopSound();
}
if (ModBase.EmoteSounds.ContainsKey(integer))
{
playingSound = true;
bool playLongAudio = ModBase.InterruptableAudio.Contains(integer);
PlaySound(playLongAudio, integer, calledFromRpc: false);
NetworkHandler.instance.PlayEmoteSoundServerRpc(GetPlayerID(), playLongAudio, integer);
}
}
previousEmoteID = integer;
}
if (!__player.performingEmote && playingSound)
{
playingSound = false;
previousEmoteID = 0;
AboutToStopSound();
}
}
private void AboutToStopSound()
{
StopSound(calledFromRpc: false);
NetworkHandler.instance.StopEmoteSoundServerRpc(GetPlayerID());
}
public void PlaySound(bool playLongAudio, int emoteID, bool calledFromRpc)
{
//IL_004f: Unknown result type (might be due to invalid IL or missing references)
if (calledFromRpc && ((NetworkBehaviour)__player).IsOwner)
{
return;
}
bool flag = __player.isInHangarShipRoom && __player.playersManager.hangarDoorsClosed;
RoundManager.Instance.PlayAudibleNoise(((Component)__player).transform.position, 30f, 1f, 0, flag, 0);
if (!ModBase.EmoteSounds.TryGetValue(emoteID, out var value))
{
ModBase.logger.LogInfo((object)"Could not get audio clip");
return;
}
float num = (float)((double)ModBase.GlobalAudioVolume.Value * 0.01);
float num2 = num;
if (((NetworkBehaviour)__player).IsOwner)
{
num2 = (float)((double)ModBase.LocalAudioVolume.Value * 0.01);
}
if (playLongAudio)
{
oldAudioSourceVolume = __playerAudio.volume;
oldAudioClip = __playerAudio.clip;
__playerAudio.volume = num2;
__playerAudio.clip = value;
__playerAudio.pitch = 1f;
__playerAudio.Play();
playingInterruptableAudio = true;
}
else
{
__playerAudio.PlayOneShot(value, num2);
}
WalkieTalkie.TransmitOneShotAudio(__playerAudio, value, num);
}
public void StopSound(bool calledFromRpc)
{
if ((!calledFromRpc || !((NetworkBehaviour)__player).IsOwner) && playingInterruptableAudio)
{
__playerAudio.Stop();
__playerAudio.volume = oldAudioSourceVolume;
__playerAudio.clip = oldAudioClip;
playingInterruptableAudio = false;
}
}
}
[HarmonyPatch(typeof(GameNetworkManager))]
internal class GameNetworkManagerPatch
{
[HarmonyPostfix]
[HarmonyPatch("Start")]
private static void AddToPrefabs(ref GameNetworkManager __instance)
{
((Component)__instance).GetComponent<NetworkManager>().AddNetworkPrefab(ModBase.Instance.networkManagerPrefab);
}
}
[HarmonyPatch(typeof(PlayerControllerB))]
internal class PlayerControllerBPatch
{
[HarmonyPatch("Awake")]
[HarmonyPostfix]
private static void InjectController(PlayerControllerB __instance)
{
((Component)__instance).gameObject.AddComponent<EmoteController>();
}
}
[HarmonyPatch(typeof(StartOfRound))]
internal class StartOfRoundPatch
{
[HarmonyPostfix]
[HarmonyPatch("Start")]
private static void spawnNetManager(StartOfRound __instance)
{
if (((NetworkBehaviour)__instance).IsHost)
{
GameObject val = Object.Instantiate<GameObject>(ModBase.Instance.networkManagerPrefab);
val.GetComponent<NetworkObject>().Spawn(false);
}
}
}
}
namespace EmoteLaugh.Core
{
[BepInPlugin("thekagamiest.EmployeeLaughingAtYou", "EmployeeLaughingAtYou", "1.1.0")]
public class ModBase : BaseUnityPlugin
{
private const string modGUID = "thekagamiest.EmployeeLaughingAtYou";
private const string modName = "EmployeeLaughingAtYou";
private const string modVersion = "1.1.0";
private const string assetName = "stupidsounds.bundle";
public GameObject networkManagerPrefab;
public static ModBase Instance;
private readonly Harmony harmony = new Harmony("thekagamiest.EmployeeLaughingAtYou");
public static ManualLogSource logger;
public static ConfigEntry<int> LocalAudioVolume { get; private set; }
public static ConfigEntry<int> GlobalAudioVolume { get; private set; }
public static Dictionary<int, AudioClip> EmoteSounds { get; private set; }
public static List<int> InterruptableAudio { get; private set; }
private void Awake()
{
//IL_0166: Unknown result type (might be due to invalid IL or missing references)
//IL_0170: Expected O, but got Unknown
//IL_019a: Unknown result type (might be due to invalid IL or missing references)
//IL_01a4: Expected O, but got Unknown
if ((Object)(object)Instance == (Object)null)
{
Instance = this;
}
logger = Logger.CreateLogSource("thekagamiest.EmployeeLaughingAtYou");
logger.LogInfo((object)"Plugin initialized");
string text = Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "stupidsounds.bundle");
AssetBundle val = AssetBundle.LoadFromFile(text);
networkManagerPrefab = val.LoadAsset<GameObject>("NetworkManagerEmoteSounds");
networkManagerPrefab.AddComponent<NetworkHandler>();
AudioClip val2 = val.LoadAsset<AudioClip>("laugh");
AudioClip val3 = val.LoadAsset<AudioClip>("vine boom");
AudioClip val4 = val.LoadAsset<AudioClip>("rizz");
if ((Object)(object)val2 == (Object)null)
{
logger.LogWarning((object)"Could not load laugh sound");
}
if ((Object)(object)val3 == (Object)null)
{
logger.LogWarning((object)"Could not load vine boom sound");
}
if ((Object)(object)val4 == (Object)null)
{
logger.LogWarning((object)"Could not load rizz sound");
}
EmoteSounds = new Dictionary<int, AudioClip>
{
{ 2, val2 },
{ 3, val3 },
{ 1003, val3 },
{ 7, val4 }
};
InterruptableAudio = new List<int> { 2 };
LocalAudioVolume = ((BaseUnityPlugin)this).Config.Bind<int>("General", "Local audio volume", 50, new ConfigDescription("How loud you want own sounds to be for yourself?", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), Array.Empty<object>()));
GlobalAudioVolume = ((BaseUnityPlugin)this).Config.Bind<int>("General", "Global audio volume", 100, new ConfigDescription("How loud you want the sounds made by other players to be? This is independent of local volume.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), Array.Empty<object>()));
try
{
Type[] types = Assembly.GetExecutingAssembly().GetTypes();
Type[] array = types;
foreach (Type type in array)
{
MethodInfo[] methods = type.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic);
MethodInfo[] array2 = methods;
foreach (MethodInfo methodInfo in array2)
{
object[] customAttributes = methodInfo.GetCustomAttributes(typeof(RuntimeInitializeOnLoadMethodAttribute), inherit: false);
if (customAttributes.Length != 0)
{
methodInfo.Invoke(null, null);
}
}
}
}
catch (Exception ex)
{
logger.LogError((object)("Unity Netcode Patcher error\n" + ex.Message));
}
harmony.PatchAll();
logger.LogInfo((object)"Done patching");
}
}
}
namespace EmoteLaugh.NetcodePatcher
{
[AttributeUsage(AttributeTargets.Module)]
internal class NetcodePatchedAssemblyAttribute : Attribute
{
}
}