diff --git a/Patches/Photon.cs b/Patches/Photon.cs index 82e7e55..860749d 100644 --- a/Patches/Photon.cs +++ b/Patches/Photon.cs @@ -8,7 +8,7 @@ { public class Photon { - public static void Patch() + public static object Patch() { Plugin.Log.LogInfo("Attempting Photon patch."); Type serverSettingsType = AccessTools.TypeByName("ServerSettings"); @@ -17,7 +17,7 @@ if (serverSettingsType == null) { Plugin.Log.LogFatal("Photon patch failed early, this Photon client is unsupported!"); - return; + return null; } string[] possibleNames = ["PHMMPAMMFLB", "PIHPJGJOPJA", "JDFMBDBEMCJ", "IECCGIPNGLF"]; @@ -31,7 +31,7 @@ if (hostingOptionType == null) { Plugin.Log.LogFatal("Photon patch failed early, this Photon client (HostingOption) is unsupported!"); - return; + return null; } ScriptableObject settingsInstance = ScriptableObject.CreateInstance(serverSettingsType); @@ -43,12 +43,12 @@ if (rpcListField == null) { Plugin.Log.LogFatal("Photon patch failed (serverSettingsType did not have an RpcList), this Photon client is unsupported!"); - return; + return null; } if (realPhotonServerSettings == null) { Plugin.Log.LogFatal("Photon patch failed (existing photon settings was null, is the patch event set to 'Awake'?), this Photon client is unsupported!"); - return; + return null; } var existingRpcList = (List)rpcListField.GetValue(realPhotonServerSettings); rpcListField.SetValue(settingsInstance, existingRpcList); @@ -57,7 +57,7 @@ { Plugin.Log.LogFatal("Photon patch failed (RpcList), this Photon client is unsupported!"); Plugin.Log.LogDebug(e); - return; + return null; } var appIdField = AccessTools.Field(serverSettingsType, "AppID"); @@ -76,7 +76,7 @@ catch (ArgumentException ex) { Plugin.Log.LogFatal($"Photon patch failed, cannot set HostingOption: {ex.Message}"); - return; + return null; } } @@ -94,7 +94,7 @@ if (photonNetworkType == null) { Plugin.Log.LogFatal("Photon patch will not work (class not found). Is this build supported?"); - return; + return null; } } FieldInfo photonServerSettingsField = photonNetworkType.GetField("PhotonServerSettings"); @@ -110,12 +110,13 @@ if (photonServerSettingsField == null) { Plugin.Log.LogFatal("Photon patch will not work (property not found). Is this build supported?"); - return; + return null; } } photonServerSettingsField.SetValue(serverSettingsType, settingsInstance); Plugin.Log.LogInfo("Photon patch was successful."); + return settingsInstance; } } } diff --git a/Patches/Resource.cs b/Patches/Resource.cs index ef430a0..3f29304 100644 --- a/Patches/Resource.cs +++ b/Patches/Resource.cs @@ -8,14 +8,14 @@ { static bool Ran = false; [HarmonyPostfix] - static void Postfix(ref string path) + static void Postfix(ref string path, ref object __result) { //Plugin.Log.LogInfo($"Resource loading '{path}'"); if (path.Contains("PhotonServerSettings") && PhotonConfig.PatchPhotonIds.Value && PhotonConfig.PatchEvent.Value == "Load") { if (Ran) return; // Photon.Patch calls Resources.Load, which may result in a loop if not handled properly Ran = true; - Photon.Patch(); + __result = Photon.Patch(); } } } diff --git a/Plugin.cs b/Plugin.cs index ea43ebc..df359aa 100644 --- a/Plugin.cs +++ b/Plugin.cs @@ -2,11 +2,10 @@ using BepInEx.Logging; using BepInEx.Unity.Mono; using HarmonyLib; -using undead_universal_patch.Patches; namespace undead_universal_patch; -[BepInPlugin("dev.proxnet.recroom.universalpatch.noneac.mono", "Undead Universal Patch", "1.0.0")] +[BepInPlugin("dev.proxnet.recroom.universalpatch.noneac.mono", "Undead Universal Patch", "1.0.1")] public class Plugin : BaseUnityPlugin { public static readonly ManualLogSource Log = BepInEx.Logging.Logger.CreateLogSource("UUPatch"); @@ -72,7 +71,8 @@ "\nor you get Photon patch errors, then change this to one of these values:" + "\n'Awake': When this plugin loads." + "\n'SocketConnect': When the WebSocket connects." + - "\n'Load': When PhotonNetwork loads PhotonServerSettings. (recommended)"); + "\n'Load': When PhotonNetwork loads PhotonServerSettings. (recommended, default)" + + "\n'Nameserver': When the game contacts the nameserver. (also recommended)"); NameserverConfig.UseNameserverHost = Config.Bind("Nameserver", "UseNameserverHost", NameserverConfigDefaults.UseNameserverHost, "Whether to rewrite outbound HTTP requests to 'ns.rec.net' to our host or not." + "\nYou must enable GenericConfig.IsNameserver as well."); @@ -96,6 +96,6 @@ Log.LogInfo("PATCH LIST END ==========="); //GenericUtils.PrintAllNamespaces(); - if (PhotonConfig.PatchEvent.Value == "Awake" && PhotonConfig.PatchPhotonIds.Value) Photon.Patch(); + if (PhotonConfig.PatchEvent.Value == "Awake" && PhotonConfig.PatchPhotonIds.Value) Patches.Photon.Patch(); } } diff --git a/Utils.cs b/Utils.cs index 88bbd72..8d89791 100644 --- a/Utils.cs +++ b/Utils.cs @@ -112,6 +112,7 @@ { if (targetUri.Host.Contains("ns.rec.net") && NameserverConfig.UseNameserverHost.Value) { + if (PhotonConfig.PatchEvent.Value == "Nameserver") Patches.Photon.Patch(); return GenericUtils.RewriteUri(targetUri, NameserverConfig.Host.Value, NameserverConfig.SecureProtocol.Value, NameserverConfig.Path.Value, ConfigUtils.GetNameserverProtocol()); diff --git a/undead-universal-patch-mono.csproj b/undead-universal-patch-mono.csproj index 16e250e..c8acab1 100644 --- a/undead-universal-patch-mono.csproj +++ b/undead-universal-patch-mono.csproj @@ -18,6 +18,7 @@ +