mirror of
https://github.com/CannedNet/CannedNet.Client.git
synced 2026-10-25 15:09:24 -07:00
fix voice connecting for localhosted photon servers
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<PhotonVoiceAuth>();
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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<Type> 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<Scene, LoadSceneMode>)OnSceneLoaded;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user