using System; using System.Diagnostics; using System.IO.MemoryMappedFiles; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using System.Text; using BepInEx; using BepInEx.Logging; using Microsoft.CodeAnalysis; using R2API.Utils; using RoR2; 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: AssemblyCompany("RoR2MumbleLink")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0+4758294539069c38548e1869e460d71b083607d3")] [assembly: AssemblyProduct("RoR2MumbleLink")] [assembly: AssemblyTitle("RoR2MumbleLink")] [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 RoR2MumbleLink { [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode, Pack = 4)] public struct LinkedMem { public uint uiVersion; public uint uiTick; [MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)] public float[] fAvatarPosition; [MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)] public float[] fAvatarFront; [MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)] public float[] fAvatarTop; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)] public string name; [MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)] public float[] fCameraPosition; [MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)] public float[] fCameraFront; [MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)] public float[] fCameraTop; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)] public string identity; public uint context_len; [MarshalAs(UnmanagedType.ByValArray, SizeConst = 256)] public byte[] context; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 2048)] public string description; } internal static class Log { private static ManualLogSource _logSource; internal static void Init(ManualLogSource logSource) { _logSource = logSource; } internal static void Debug(object data) { _logSource.LogDebug(data); } internal static void Error(object data) { _logSource.LogError(data); } internal static void Fatal(object data) { _logSource.LogFatal(data); } internal static void Info(object data) { _logSource.LogInfo(data); } internal static void Message(object data) { _logSource.LogMessage(data); } internal static void Warning(object data) { _logSource.LogWarning(data); } } [BepInPlugin("Zyrex.RoR2MumbleLink", "RoR2MumbleLink", "1.0.1")] [NetworkCompatibility(/*Could not decode attribute arguments.*/)] public class MumbleLink : BaseUnityPlugin { public const string PluginGUID = "Zyrex.RoR2MumbleLink"; public const string PluginAuthor = "Zyrex"; public const string PluginName = "RoR2MumbleLink"; public const string PluginVersion = "1.0.1"; private MumbleLinkFile _mumble; private PlayerTracker _playerTracker; public void Awake() { Log.Init(((BaseUnityPlugin)this).Logger); Log.Message("Loaded Mumble Link!"); _mumble = new MumbleLinkFile(); _playerTracker = new PlayerTracker(); } private void Update() { _playerTracker.Update(_mumble); } private void OnDestroy() { _mumble?.Dispose(); } } public sealed class MumbleLinkFile : IDisposable { private const string FILE_NAME = "MumbleLink"; private readonly MemoryMappedFile _file; private readonly MemoryMappedViewAccessor _accessor; private bool _disposed; public MumbleLinkFile() { _file = MemoryMappedFile.CreateOrOpen("MumbleLink", Marshal.SizeOf(), MemoryMappedFileAccess.ReadWrite); _accessor = _file.CreateViewAccessor(); } public void Write(LinkedMem lm) { if (_disposed) { throw new ObjectDisposedException(GetType().FullName); } int num = Marshal.SizeOf(); IntPtr intPtr = Marshal.AllocHGlobal(num); try { Marshal.StructureToPtr(lm, intPtr, fDeleteOld: false); byte[] array = new byte[num]; Marshal.Copy(intPtr, array, 0, num); _accessor.WriteArray(0L, array, 0, num); } finally { Marshal.FreeHGlobal(intPtr); } } public void Dispose() { if (!_disposed) { _disposed = true; _accessor.Dispose(); _file.Dispose(); } } } internal class PlayerTracker { private CharacterBody _localPlayerBody; private LinkedMem lm; private bool initialized = false; internal PlayerTracker() { CharacterBody.onBodyStartGlobal += OnBodyStart; CharacterBody.onBodyDestroyGlobal += OnBodyDestroy; lm.uiVersion = 2u; lm.name = "Risk of Rain 2"; lm.description = "RoR2 Mumble Link Positional Audio"; lm.context = new byte[256]; byte[] bytes = Encoding.ASCII.GetBytes("RoR2ServerContext"); Array.Copy(bytes, lm.context, bytes.Length); lm.context_len = (uint)bytes.Length; } private void OnBodyStart(CharacterBody body) { if (body.isPlayerControlled && body.hasEffectiveAuthority) { _localPlayerBody = body; } } private void OnBodyDestroy(CharacterBody body) { if ((Object)(object)body == (Object)(object)_localPlayerBody) { _localPlayerBody = null; } } public void Update(MumbleLinkFile file) { //IL_00cd: Unknown result type (might be due to invalid IL or missing references) //IL_00db: Unknown result type (might be due to invalid IL or missing references) //IL_00e9: Unknown result type (might be due to invalid IL or missing references) //IL_0108: Unknown result type (might be due to invalid IL or missing references) //IL_0116: Unknown result type (might be due to invalid IL or missing references) //IL_0124: Unknown result type (might be due to invalid IL or missing references) //IL_0143: Unknown result type (might be due to invalid IL or missing references) //IL_0151: Unknown result type (might be due to invalid IL or missing references) //IL_015f: Unknown result type (might be due to invalid IL or missing references) //IL_0185: Unknown result type (might be due to invalid IL or missing references) //IL_0193: Unknown result type (might be due to invalid IL or missing references) //IL_01a1: Unknown result type (might be due to invalid IL or missing references) //IL_01c0: Unknown result type (might be due to invalid IL or missing references) //IL_01ce: Unknown result type (might be due to invalid IL or missing references) //IL_01dc: Unknown result type (might be due to invalid IL or missing references) //IL_01fb: Unknown result type (might be due to invalid IL or missing references) //IL_0209: Unknown result type (might be due to invalid IL or missing references) //IL_0217: Unknown result type (might be due to invalid IL or missing references) Camera main = Camera.main; if (PlayerCharacterMasterController.instances.Count > 1 && !((Object)(object)_localPlayerBody == (Object)null) && file != null && !((Object)(object)main == (Object)null)) { if (!initialized) { lm.identity = ((Object)_localPlayerBody).name; initialized = true; } if (string.IsNullOrEmpty(lm.identity)) { lm.identity = ((Object)_localPlayerBody).name; } lm.uiTick++; Transform transform = _localPlayerBody.transform; lm.fAvatarPosition = new float[3] { transform.position.x, transform.position.y, transform.position.z }; lm.fAvatarFront = new float[3] { transform.forward.x, transform.forward.y, transform.forward.z }; lm.fAvatarTop = new float[3] { transform.up.x, transform.up.y, transform.up.z }; Transform transform2 = ((Component)main).transform; lm.fCameraPosition = new float[3] { transform2.position.x, transform2.position.y, transform2.position.z }; lm.fCameraFront = new float[3] { transform2.forward.x, transform2.forward.y, transform2.forward.z }; lm.fCameraTop = new float[3] { transform2.up.x, transform2.up.y, transform2.up.z }; file.Write(lm); } } } }