forked from zombieb/undead-universal-patch-il2cpp
51 lines
1.8 KiB
C#
51 lines
1.8 KiB
C#
using HarmonyLib;
|
|
using Il2CppInterop.Runtime;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Reflection;
|
|
using UnityEngine;
|
|
|
|
namespace undead_universal_patch_il2cpp.Patches
|
|
{
|
|
[HarmonyPatch]
|
|
public class PhotonPatchEvent
|
|
{
|
|
static readonly string TargetTypeName = "RecNet.Core";
|
|
static readonly string TargetMethodName = "ConnectToRecNet";
|
|
static readonly string Description = "Photon Patch event method";
|
|
static readonly MethodInfo connectMethod = AccessTools.Method(AccessTools.TypeByName(TargetTypeName), TargetMethodName);
|
|
|
|
static bool Prepare()
|
|
{
|
|
if (connectMethod == null)
|
|
{
|
|
Plugin.Log.LogWarning($"'{Description}' disabled. The type 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) Photon.Patch();
|
|
}
|
|
}
|
|
|
|
public class Photon
|
|
{
|
|
public static void Patch()
|
|
{
|
|
/*
|
|
Normally, I would be using reflection and AccessTools to create a new instance of ServerSettings and set the value of PhotonNetwork.PhotonServerSettings,
|
|
but since it was difficult and confusing with IL2CPP, I ended up just using explicit references.. every targeted game build *should* have these types anyway.
|
|
Now I'm wondering if the patch runs faster when using explicit references rather than reflection
|
|
*/
|
|
|
|
PhotonNetwork.PhotonServerSettings.AppID = PhotonConfig.AppID.Value;
|
|
PhotonNetwork.PhotonServerSettings.VoiceAppID = PhotonConfig.VoiceAppID.Value;
|
|
}
|
|
}
|
|
}
|