This repository has been archived on 2026-05-30. You can view files and clone it, but cannot push or open issues or pull requests.
Files
undead-universal-patch-il2cpp/Core/Init.cs

148 lines
9.6 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Mapster;
using undead_universal_patch_il2cpp.Core.Config;
using undead_universal_patch_il2cpp.Core.Content.CustomRecNet.CustomEmotes;
using undead_universal_patch_il2cpp.Core.Content.CustomRecNet.CustomPhoton;
using undead_universal_patch_il2cpp.Core.Content.UndeadGameManager;
using undead_universal_patch_il2cpp.Patches.Video;
using UnityEngine;
namespace undead_universal_patch_il2cpp.Core;
public class Initialization
{
public static void Initialize()
{
AddMapsterGlobalTypeConfigs();
FetchConfigurations();
AttachGameObjects();
try
{
UniversalPatchPlugin.Instance.HarmonyInstance.PatchAll();
}
catch (Exception ex)
{
UniversalPatchPlugin.Log.LogError($"--------> PATCH ERROR! Please report this in the gitea repo!\n{ex}");
}
if (GenericConfig.PatchDebug.Value)
{
UniversalPatchPlugin.Log.LogInfo("PATCH LIST START =========================");
foreach (var method in UniversalPatchPlugin.Instance.HarmonyInstance.GetPatchedMethods())
UniversalPatchPlugin.Log.LogInfo($"- {method.ToString()}");
UniversalPatchPlugin.Log.LogInfo("PATCH LIST END =========================");
}
try
{
CacheChangePatchConfigs();
}
catch (Exception ex)
{
UniversalPatchPlugin.Log.LogError($"Could not load change patches: {ex}");
}
}
private static void CacheChangePatchConfigs()
{
if (GameManagerConfig.AnyGameFreeSpawn.Value) GameFreeSpawns.config.Get();
if (GameManagerConfig.StaticGameConfig.Value) GameConfigurator.config.Get();
VideoTamperPatch.config.Get();
}
private static void AttachGameObjects()
{
UniversalPatchPlugin.Log.LogInfo("Attaching game objects");
if (ServerPatchesConfig.CustomEmotes.Value) UniversalPatchPlugin.Instance.AddComponent<CustomEmotes>();
UniversalPatchPlugin.Instance.AddComponent<CustomPhoton>();
}
private static void FetchConfigurations()
{
GenericConfig.PatchDebug = UniversalPatchPlugin.Instance.Config.Bind("Generic", "PatchDebug", GenericConfigDefaults.PatchDebug,
"Enable logging messages sent by patches for debugging. Usually not needed. Enable when submitting issues or bug reports.");
GenericConfig.LogAllRequests = UniversalPatchPlugin.Instance.Config.Bind("Generic", "LogAllRequests", GenericConfigDefaults.LogAllRequests,
"Log all BestHTTP requests sent by the game.");
GenericConfig.VerboseRequestLogs = UniversalPatchPlugin.Instance.Config.Bind("Generic", "VerboseRequestLogs", GenericConfigDefaults.VerboseRequestLogs,
"Add additional request information to BestHTTPProxy logs. Requires LogAllRequest to be enabled.");
PatchConfig.CertificatePatch = UniversalPatchPlugin.Instance.Config.Bind("Generic", "CertificatePatch", PatchConfigDefaults.CertificatePatch,
"The game expects a certain certificate from rec.net when making HTTPS requests. Enable this to allow any valid certificate.");
PatchConfig.HilePatch = UniversalPatchPlugin.Instance.Config.Bind("Generic", "HilePatch", PatchConfigDefaults.HilePatch,
"The game will close after a short period of time if BepInEx is found. Enable to stop this from happening." +
"\nThis will also enable the AGRoomRuntimeConfig patch. See the README for more info.");
PatchConfig.SignalRHandshakeFix = UniversalPatchPlugin.Instance.Config.Bind("Generic", "SignalRHandshakeFix", PatchConfigDefaults.SignalRHandshakeFix,
"Replace apostrophes with quotes in the initial SignalR handshake.");
PatchConfig.ImageSignaturePatch = UniversalPatchPlugin.Instance.Config.Bind("Generic", "ImageSignaturePatch", PatchConfigDefaults.ImageSignaturePatch,
"When enabled, all image signatures will be valid." +
"\nWorks only if the server appends a properly formatted signature header (signature does not need to be valid)");
PatchConfig.RegistrationPatch = UniversalPatchPlugin.Instance.Config.Bind("Generic", "RegistrationPatch", PatchConfigDefaults.RegistrationPatch,
"Always disable the registration prompt.");
PatchConfig.AFKPatch = UniversalPatchPlugin.Instance.Config.Bind("Generic", "AFKPatch", PatchConfigDefaults.AFKPatch,
"Always present patch. Never get kicked to dorm for being AFK.");
ServerPatchesConfig.CustomEmotes = UniversalPatchPlugin.Instance.Config.Bind("ServerPatches", "CustomEmotes", ServerPatchesConfigDefaults.CustomEmotes,
"Modify the game's emote text with a configuration from the server.");
ServerPatchesConfig.CustomPhoton = UniversalPatchPlugin.Instance.Config.Bind("ServerPatches", "CustomPhoton", ServerPatchesConfigDefaults.CustomPhoton,
"Patch Photon ServerSettings values with a configuration from the server." +
"\nWhen the server fails to provide a valid configuration, values from the local config will be used." +
"\nPhoton.PatchPhotonIds must be enabled for this fallback to work.");
GameManagerConfig.AnyGameFreeSpawn = UniversalPatchPlugin.Instance.Config.Bind("GameManagerConfig", "AnyGameFreeSpawn", GameManagerConfigDefaults.AnyGameFreeSpawn,
$"Use patches from '{GameFreeSpawns.config.path}' to spawn in any valid player spawnpoint in specified games. See README.md");
GameManagerConfig.StaticGameConfig = UniversalPatchPlugin.Instance.Config.Bind("GameManagerConfig", "StaticGameConfig", GameManagerConfigDefaults.StaticGameConfig,
$"Use patches from '{GameConfigurator.config.path}' to set new configurations for built-in games. See README.md");
PhotonConfig.PatchPhotonIds = UniversalPatchPlugin.Instance.Config.Bind("Photon", "PatchPhotonIds", PhotonConfigDefaults.PatchPhotonIds,
"Patch Photon configuration.");
PhotonConfig.PunLogging = UniversalPatchPlugin.Instance.Config.Bind("Photon", "PunLogging", PhotonConfigDefaults.PunLogging,
"Enable all PUN/Voice logging (useful for server debugging)");
PhotonConfig.SelfHosted = UniversalPatchPlugin.Instance.Config.Bind("Photon", "IsSelfHosted", PhotonConfigDefaults.SelfHosted,
"When enabled, use a self-hosted ('OnPremises' or 'PhotonSocketServer') Photon server." +
"\nWhen disabled, AppID and VoiceAppID are sent to Photon Cloud and a cloud masterserver is used.");
PhotonConfig.AppID = UniversalPatchPlugin.Instance.Config.Bind("Photon", "AppID", PhotonConfigDefaults.AppID,
"The new target (PUN) App ID from the Photon dashboard." +
"\nWhen self-hosting, this should be the name of your Photon application (usually 'Master' without quotes)");
PhotonConfig.VoiceAppID = UniversalPatchPlugin.Instance.Config.Bind("Photon", "VoiceAppID", PhotonConfigDefaults.VoiceAppID,
"The new target Voice App ID from the Photon dashboard." +
"\nWhen self-hosting, this should be the same as AppID.");
PhotonConfig.ServerAddress = UniversalPatchPlugin.Instance.Config.Bind("Photon", "ServerAddress", PhotonConfigDefaults.ServerAddress,
"Address of the Photon Master server (ignored if using cloud)");
PhotonConfig.ServerPort = UniversalPatchPlugin.Instance.Config.Bind("Photon", "ServerPort", PhotonConfigDefaults.ServerPort,
"Photon Master server port (ignored if using cloud)." +
"\nYou can set this port to the matching protocol port from the server, e.g. 5055 for UDP, 9091 for WebSockets");
PhotonConfig.ConnectionProtocol = UniversalPatchPlugin.Instance.Config.Bind("Photon", "ConnectionProtocol", PhotonConfigDefaults.ConnectionProtocol,
"Connection protocol to use when connecting to the Photon servers (ignored if using cloud)." +
"\n0: UDP, 1: TCP;" +
"\nWebSockets are not supported by Photon in this build. TCP is experimental and may cause instability/crashes.");
NameserverConfig.Rewrite = UniversalPatchPlugin.Instance.Config.Bind("Nameserver", "Rewrite", NameserverConfigDefaults.Rewrite,
"Enable/disable rewriting the URL for nameserver requests.");
NameserverConfig.NewUrl = UniversalPatchPlugin.Instance.Config.Bind("Nameserver", "NewUrl", NameserverConfigDefaults.NewUrl,
"The new full URL to use when sending a nameserver request.");
}
private static void AddMapsterGlobalTypeConfigs()
{
TypeAdapterConfig.GlobalSettings
.ForType<List<TeamConfigurationDTO>, Il2CppStructArray<TeamConfiguration>>()
.MapWith(src => new Il2CppStructArray<TeamConfiguration>(src.Select(x => x.Adapt<TeamConfiguration>()).ToArray()));
TypeAdapterConfig.GlobalSettings
.ForType<List<StatConfigurationDTO>, Il2CppReferenceArray<StatConfiguration>>()
.MapWith(src => new Il2CppReferenceArray<StatConfiguration>(src.Select(x => x.Adapt<StatConfiguration>()).ToArray()));
TypeAdapterConfig.GlobalSettings
.ForType<EmoteConfigDTO, RecRoom.AGUI.Expresso.ContextualEmotesConfig.ExpressoEmote>()
.Map(dest => dest.emoteUniqueName, source => source.UniqueName)
.Map(dest => dest.emoteText, source => source.NewText)
.Map(dest => dest.emoteRoomChatText, source => source.RoomChatText)
.Map(dest => dest.facialExpression, source => source.FacialExpression)
.Map(dest => dest.forceEmoteBubble, source => source.ForceEmoteBubble)
.Map(dest => dest.onlyBroadcastToTeam, source => source.OnlyBroadcastToTeam);
}
}