forked from zombieb/undead-universal-patch-il2cpp
INTERNAL REWRITE! server configs
This commit is contained in:
@@ -2,40 +2,27 @@
|
||||
using System.Reflection;
|
||||
using HarmonyLib;
|
||||
using undead_universal_patch_il2cpp.Core;
|
||||
using undead_universal_patch_il2cpp.Core.Config;
|
||||
|
||||
namespace undead_universal_patch_il2cpp.Patches
|
||||
{
|
||||
[HarmonyPatch]
|
||||
public class PhotonPatchEvent
|
||||
{
|
||||
static readonly string TargetTypeName = "PhotonNetwork";
|
||||
static readonly string TargetMethodName = "ConnectUsingSettings";
|
||||
static readonly string Description = "Photon ConnectUsingSettings patch event";
|
||||
static readonly Type targetType = AccessTools.TypeByName(TargetTypeName);
|
||||
static PatchTypesResult patchResult = Util.ConfigPreparePatchTypes(
|
||||
PhotonConfig.PatchPhotonIds,
|
||||
"Photon ConnectUsingSettings event path",
|
||||
"PhotonNetwork",
|
||||
"ConnectUsingSettings"
|
||||
);
|
||||
|
||||
static bool Prepare()
|
||||
{
|
||||
if (!PhotonConfig.PatchPhotonIds.Value) return false;
|
||||
if (targetType == null)
|
||||
{
|
||||
Plugin.Log.LogWarning($"'{Description}' disabled. The type for this patch was not found.");
|
||||
return false;
|
||||
}
|
||||
if (AccessTools.Method(targetType, TargetMethodName) == null)
|
||||
{
|
||||
Plugin.Log.LogWarning($"'{Description}' disabled. The method for this patch was not found.");
|
||||
return false;
|
||||
}
|
||||
static bool Prepare() => patchResult.Success;
|
||||
|
||||
Plugin.Log.LogInfo($"'{Description}' succeeded validation.");
|
||||
return true;
|
||||
}
|
||||
|
||||
static MethodInfo TargetMethod() => AccessTools.Method(targetType, TargetMethodName);
|
||||
static MethodInfo TargetMethod() => patchResult.Method;
|
||||
|
||||
static void Prefix()
|
||||
{
|
||||
if (GenericConfig.PatchDebug.Value) Plugin.Log.LogDebug("Attempting Photon patch");
|
||||
Util.ConditionalDebug("Attempting Photon patch");
|
||||
PhotonPatch.Patch();
|
||||
}
|
||||
}
|
||||
@@ -43,36 +30,24 @@ namespace undead_universal_patch_il2cpp.Patches
|
||||
[HarmonyPatch]
|
||||
public class ForceSelfHostedPhoton
|
||||
{
|
||||
class HarmonyState
|
||||
class HarmonyState
|
||||
{
|
||||
public object code;
|
||||
}
|
||||
|
||||
static readonly string TargetTypeName = "PUNNetworkManager";
|
||||
static readonly string TargetMethodName = "OnConnectedToMaster";
|
||||
static readonly string Description = "Force JoinOrCreateRoom when connected to master";
|
||||
static readonly Type targetType = AccessTools.TypeByName(TargetTypeName);
|
||||
static readonly MethodInfo targetMethod = AccessTools.Method(targetType, TargetMethodName);
|
||||
static PatchTypesResult patchResult = Util.ConfigsPreparePatchTypes(
|
||||
[
|
||||
PhotonConfig.PatchPhotonIds,
|
||||
PhotonConfig.SelfHosted
|
||||
],
|
||||
"Force JoinOrCreateRoom when connected to master",
|
||||
"PUNNetworkManager",
|
||||
"OnConnectedToMaster"
|
||||
);
|
||||
|
||||
static bool Prepare()
|
||||
{
|
||||
if (!(PhotonConfig.PatchPhotonIds.Value && PhotonConfig.SelfHosted.Value)) return false;
|
||||
if (targetType == null)
|
||||
{
|
||||
Plugin.Log.LogWarning($"'{Description}' disabled. The type for this patch was not found.");
|
||||
return false;
|
||||
}
|
||||
if (targetMethod == null)
|
||||
{
|
||||
Plugin.Log.LogWarning($"'{Description}' disabled. The method for this patch was not found.");
|
||||
return false;
|
||||
}
|
||||
static bool Prepare() => patchResult.Success;
|
||||
|
||||
Plugin.Log.LogInfo($"'{Description}' succeeded validation.");
|
||||
return true;
|
||||
}
|
||||
|
||||
static MethodBase TargetMethod() => targetMethod;
|
||||
static MethodBase TargetMethod() => patchResult.Method;
|
||||
|
||||
static void Prefix(ref PUNNetworkManager __instance, ref HarmonyState __state)
|
||||
{
|
||||
@@ -80,25 +55,25 @@ namespace undead_universal_patch_il2cpp.Patches
|
||||
PropertyInfo targetGameSessionProperty = __instance.GetType().GetRuntimeProperty("targetGameSession");
|
||||
if (targetGameSessionProperty == null)
|
||||
{
|
||||
Plugin.Log.LogFatal("Cannot force masterserver: targetGameSessionProperty was null.");
|
||||
UniversalPatchPlugin.Log.LogFatal("Cannot force masterserver: targetGameSessionProperty was null.");
|
||||
return;
|
||||
}
|
||||
var targetGameSession = targetGameSessionProperty.GetValue(__instance);
|
||||
if (targetGameSession == null)
|
||||
{
|
||||
Plugin.Log.LogFatal("Cannot force masterserver: targetGameSession was null.");
|
||||
UniversalPatchPlugin.Log.LogFatal("Cannot force masterserver: targetGameSession was null.");
|
||||
return;
|
||||
}
|
||||
PropertyInfo photonRegionIdProperty = targetGameSession.GetType().GetRuntimeProperty("PhotonRegionId");
|
||||
if (photonRegionIdProperty == null)
|
||||
{
|
||||
Plugin.Log.LogFatal("Cannot force masterserver: photonRegionIdProperty was null.");
|
||||
UniversalPatchPlugin.Log.LogFatal("Cannot force masterserver: photonRegionIdProperty was null.");
|
||||
return;
|
||||
}
|
||||
|
||||
__state.code = photonRegionIdProperty.GetValue(targetGameSession);
|
||||
photonRegionIdProperty.SetValue(targetGameSession, 4);
|
||||
if (GenericConfig.PatchDebug.Value) Plugin.Log.LogDebug("Forcing masterserver");
|
||||
Util.ConditionalDebug("Forcing masterserver");
|
||||
}
|
||||
|
||||
static void Postfix(ref PUNNetworkManager __instance, ref HarmonyState __state)
|
||||
@@ -106,24 +81,24 @@ namespace undead_universal_patch_il2cpp.Patches
|
||||
PropertyInfo targetGameSessionProperty = __instance.GetType().GetRuntimeProperty("targetGameSession");
|
||||
if (targetGameSessionProperty == null)
|
||||
{
|
||||
Plugin.Log.LogFatal("Cannot force masterserver postfix: targetGameSessionProperty was null.");
|
||||
UniversalPatchPlugin.Log.LogFatal("Cannot force masterserver postfix: targetGameSessionProperty was null.");
|
||||
return;
|
||||
}
|
||||
var targetGameSession = targetGameSessionProperty.GetValue(__instance);
|
||||
if (targetGameSession == null)
|
||||
{
|
||||
Plugin.Log.LogFatal("Cannot force masterserver postfix: targetGameSession was null.");
|
||||
UniversalPatchPlugin.Log.LogFatal("Cannot force masterserver postfix: targetGameSession was null.");
|
||||
return;
|
||||
}
|
||||
PropertyInfo photonRegionIdProperty = targetGameSession.GetType().GetRuntimeProperty("PhotonRegionId");
|
||||
if (photonRegionIdProperty == null)
|
||||
{
|
||||
Plugin.Log.LogFatal("Cannot force masterserver: photonRegionIdProperty was null.");
|
||||
UniversalPatchPlugin.Log.LogFatal("Cannot force masterserver: photonRegionIdProperty was null.");
|
||||
return;
|
||||
}
|
||||
|
||||
photonRegionIdProperty.SetValue(targetGameSession, __state.code);
|
||||
if (GenericConfig.PatchDebug.Value) Plugin.Log.LogDebug("Masterserver regionId roundtrip");
|
||||
Util.ConditionalDebug("Masterserver regionId roundtrip");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -139,7 +114,7 @@ namespace undead_universal_patch_il2cpp.Patches
|
||||
|
||||
if (photonNetworkType == null || serverSettingsType == null)
|
||||
{
|
||||
Plugin.Log.LogError("Cannot patch Photon: PhotonNetwork or ServerSettings types were not found. Is this build supported?");
|
||||
UniversalPatchPlugin.Log.LogError("Cannot patch Photon: PhotonNetwork or ServerSettings types were not found. Is this build supported?");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -157,8 +132,8 @@ namespace undead_universal_patch_il2cpp.Patches
|
||||
PropertyInfo appIdProperty = serverSettingsType.GetRuntimeProperty("AppID");
|
||||
PropertyInfo voiceAppIdProperty = serverSettingsType.GetRuntimeProperty("VoiceAppID");
|
||||
|
||||
if (GenericConfig.PatchDebug.Value) Plugin.Log.LogDebug($"New Photon AppID: '{PhotonConfig.AppID.Value}'");
|
||||
if (GenericConfig.PatchDebug.Value) Plugin.Log.LogDebug($"New Photon AppID: '{PhotonConfig.VoiceAppID.Value}'");
|
||||
Util.ConditionalDebug($"New Photon AppID: '{PhotonConfig.AppID.Value}'");
|
||||
Util.ConditionalDebug($"New Photon AppID: '{PhotonConfig.VoiceAppID.Value}'");
|
||||
appIdProperty.SetValue(serverSettings, PhotonConfig.AppID.Value);
|
||||
voiceAppIdProperty.SetValue(serverSettings, PhotonConfig.VoiceAppID.Value);
|
||||
|
||||
@@ -178,28 +153,28 @@ namespace undead_universal_patch_il2cpp.Patches
|
||||
PropertyInfo networkingPeerProperty = photonNetworkType.GetRuntimeProperty("networkingPeer");
|
||||
if (networkingPeerProperty == null)
|
||||
{
|
||||
Plugin.Log.LogError("Cannot patch Photon: networkingPeerProperty was null. Is this build supported?");
|
||||
UniversalPatchPlugin.Log.LogError("Cannot patch Photon: networkingPeerProperty was null. Is this build supported?");
|
||||
return;
|
||||
}
|
||||
|
||||
if (networkingPeerProperty.GetValue(null) == null)
|
||||
{
|
||||
Plugin.Log.LogError("Cannot patch Photon: networkingPeerInstance was null. Is this build supported?");
|
||||
UniversalPatchPlugin.Log.LogError("Cannot patch Photon: networkingPeerInstance was null. Is this build supported?");
|
||||
return;
|
||||
}
|
||||
|
||||
string id = Core.Util.LocalInstanceGuid;
|
||||
if (GenericConfig.PatchDebug.Value) Plugin.Log.LogDebug($"Instance GUID is {id}");
|
||||
Util.ConditionalDebug($"Instance GUID is {id}");
|
||||
|
||||
PhotonNetwork.AuthValues = new AuthenticationValues
|
||||
{
|
||||
UserId = id
|
||||
};
|
||||
|
||||
if (GenericConfig.PatchDebug.Value) Plugin.Log.LogDebug($"Set the authValues userId to {id}");
|
||||
Util.ConditionalDebug($"Set the authValues userId to {id}");
|
||||
}
|
||||
|
||||
Plugin.Log.LogInfo($"Photon patch ({(PhotonConfig.SelfHosted.Value ? "self-hosted" : "cloud")}) succeeded.");
|
||||
UniversalPatchPlugin.Log.LogInfo($"Photon patch ({(PhotonConfig.SelfHosted.Value ? "self-hosted" : "cloud")}) succeeded.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user