forked from zombieb/undead-universal-patch-il2cpp
fixes
This commit is contained in:
@@ -1,61 +0,0 @@
|
||||
using HarmonyLib;
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Reflection;
|
||||
|
||||
namespace undead_universal_patch_il2cpp.Patches
|
||||
{
|
||||
[HarmonyPatch]
|
||||
public class ConnectToRecNetPatchEvent
|
||||
{
|
||||
static readonly string TargetTypeName = "RecNet.Core";
|
||||
static readonly string TargetMethodName = "ConnectToRecNet";
|
||||
static readonly string Description = "Photon/Hile Patch event method"; // It's convenient. Could patch at a different time. But this part was easy.
|
||||
static readonly MethodInfo connectMethod = AccessTools.Method(AccessTools.TypeByName(TargetTypeName), TargetMethodName);
|
||||
|
||||
static bool Prepare()
|
||||
{
|
||||
if (connectMethod == null)
|
||||
{
|
||||
Plugin.Log.LogWarning($"'{Description}' disabled. The method for this patch was not found.");
|
||||
return false;
|
||||
}
|
||||
|
||||
Plugin.Log.LogInfo($"'{Description}' succeeded validation.");
|
||||
return true;
|
||||
}
|
||||
static MethodBase TargetMethod() => connectMethod;
|
||||
static void Prefix()
|
||||
{
|
||||
if (PhotonConfig.PatchPhotonIds.Value) PhotonPatch.Patch();
|
||||
if (GenericConfig.HilePatch.Value) HilePatch.Patch();
|
||||
}
|
||||
}
|
||||
|
||||
public class PhotonPatch
|
||||
{
|
||||
public static void Patch()
|
||||
{
|
||||
Type photonNetworkType = AccessTools.TypeByName("PhotonNetwork");
|
||||
Type serverSettingsType = AccessTools.TypeByName("ServerSettings");
|
||||
|
||||
if (photonNetworkType == null || serverSettingsType == null)
|
||||
{
|
||||
Plugin.Log.LogError("Cannot patch Photon: PhotonNetwork or ServerSettings types were not found. Is this build supported?");
|
||||
return;
|
||||
}
|
||||
|
||||
// The property PhotonServerSettings (which should be a field) didn't appear when I didn't specify `Runtime`. Not sure why. But this works.
|
||||
PropertyInfo photonServerSettingsProperty = photonNetworkType.GetRuntimeProperty("PhotonServerSettings");
|
||||
object serverSettings = photonServerSettingsProperty.GetValue(serverSettingsType);
|
||||
|
||||
PropertyInfo appIdField = serverSettingsType.GetRuntimeProperty("AppID");
|
||||
PropertyInfo voiceAppIdField = serverSettingsType.GetRuntimeProperty("VoiceAppID");
|
||||
|
||||
appIdField.SetValue(serverSettings, PhotonConfig.AppID.Value);
|
||||
voiceAppIdField.SetValue(serverSettings, PhotonConfig.VoiceAppID.Value);
|
||||
|
||||
Plugin.Log.LogInfo("Photon patch succeeded.");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user