diff --git a/CannedNet.Client/Patches/PhotonPatches.cs b/CannedNet.Client/Patches/PhotonPatches.cs index 78883a9..3123792 100644 --- a/CannedNet.Client/Patches/PhotonPatches.cs +++ b/CannedNet.Client/Patches/PhotonPatches.cs @@ -2,7 +2,9 @@ using System; using System.Reflection; using ExitGames.Client.Photon; using HarmonyLib; +using Photon.Pun; using Photon.Realtime; +using Photon.Voice.PUN; namespace CannedNet.Client.Patches; @@ -48,7 +50,7 @@ public class Photon_AppSettings_Patch if (type != null) break; } } - + return type?.GetMethod("FJOLIPKKIBE", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance); } @@ -60,14 +62,13 @@ public class Photon_AppSettings_Patch __result = new() { AppVersion = __result?.AppVersion, - AppIdRealtime = "", - AppIdVoice = "", - AppIdChat = "", - FixedRegion = "eu", + AppIdRealtime = Plugin.AppIdRT.Value, + AppIdVoice = Plugin.AppIdVoice.Value, + AppIdChat = Plugin.AppIdChat.Value, + FixedRegion = "us", UseNameServer = true, Protocol = ConnectionProtocol.Udp, - Server = Plugin.PhotonHostname.Value, - Port = Plugin.PhotonPort.Value == 0 ? 58913 : Plugin.PhotonPort.Value + Server = Plugin.PhotonHostname.Value }; } else diff --git a/CannedNet.Client/Patches/RecRoomGameRootPatch.cs b/CannedNet.Client/Patches/RecRoomGameRootPatch.cs new file mode 100644 index 0000000..357645f --- /dev/null +++ b/CannedNet.Client/Patches/RecRoomGameRootPatch.cs @@ -0,0 +1,17 @@ +using HarmonyLib; +using UnityEngine; + +namespace CannedNet.Client.Patches; + +[HarmonyPatch(typeof(RecRoomGameRoot))] +static class RecRoomGameRootPatch +{ + [HarmonyPatch(nameof(RecRoomGameRoot.Awake))] + static void Postfix() + { + if (GameObject.Find("CannedNetRoot")) return; + GameObject modRoot = new GameObject("CannedNetRoot"); + GameObject.DontDestroyOnLoad(modRoot); + modRoot.AddComponent(); + } +} \ No newline at end of file diff --git a/CannedNet.Client/PhotonVoiceAuth.cs b/CannedNet.Client/PhotonVoiceAuth.cs new file mode 100644 index 0000000..298dec2 --- /dev/null +++ b/CannedNet.Client/PhotonVoiceAuth.cs @@ -0,0 +1,39 @@ +using System; +using Photon.Pun; +using Photon.Voice.PUN; +using UnityEngine; + +namespace CannedNet.Client; + +public class PhotonVoiceAuth : MonoBehaviour +{ + public PhotonVoiceAuth(IntPtr handle) : base(handle) + { + } + + public bool authValuesSet = false; + + private void Update() + { + if (Plugin.EnableAdvancedSettings.Value) + { + var realtimeAuth = PhotonNetwork.AuthValues; + + if (realtimeAuth != null) + { + if (authValuesSet) + return; + + PhotonVoiceNetwork.Instance.Client.AuthValues = realtimeAuth; + authValuesSet = true; + } + else + { + if (!authValuesSet) + return; + + authValuesSet = false; + } + } + } +} \ No newline at end of file diff --git a/CannedNet.Client/Plugin.cs b/CannedNet.Client/Plugin.cs index 3becfdf..1bdc388 100644 --- a/CannedNet.Client/Plugin.cs +++ b/CannedNet.Client/Plugin.cs @@ -1,5 +1,8 @@ using System; using System.Collections; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; using System.Text.Json; using BepInEx; using BepInEx.Configuration; @@ -7,6 +10,8 @@ using BepInEx.Logging; using BepInEx.Unity.IL2CPP; using BepInEx.Unity.IL2CPP.Utils.Collections; using HarmonyLib; +using Il2CppInterop.Runtime.Injection; +using Photon.Voice.PUN; using UnityEngine; using UnityEngine.Events; using UnityEngine.SceneManagement; @@ -41,6 +46,20 @@ public class Plugin : BasePlugin Harmony.CreateAndPatchAll(typeof(Plugin).Assembly); + MethodInfo registerMethod = typeof(ClassInjector) + .GetMethods(BindingFlags.Public | BindingFlags.Static) + .FirstOrDefault(m => m.Name == "RegisterTypeInIl2Cpp" && m.IsGenericMethodDefinition); + + IEnumerable il2cppTypes = Assembly.GetExecutingAssembly().GetTypes() + .Where(t => t.IsClass && !t.IsAbstract && t.IsSubclassOf(typeof(MonoBehaviour))) + .Where(t => t.Namespace == "CannedNet.Client") + .Where(t => t.GetConstructor(new[] { typeof(IntPtr) }) != null); + + foreach (Type type in il2cppTypes) + { + registerMethod?.MakeGenericMethod(type).Invoke(null, null); + } + SceneManager.sceneLoaded += (Action)OnSceneLoaded; }