INTERNAL REWRITE! server configs

This commit is contained in:
2025-08-12 03:10:25 -04:00
parent 1c51b37a7c
commit 7fc0d6c5b0
23 changed files with 645 additions and 564 deletions

View File

@@ -1,19 +0,0 @@
using System.Collections.Generic;
using System.Text.Json.Serialization;
namespace undead_universal_patch_il2cpp.Core.AssetChanges;
public class RecChange
{
[JsonPropertyName("Key")]
public string RecKey { get; set; }
[JsonPropertyName("Value")]
public dynamic RecValue { get; set; }
}
public static class AGRoomChanges
{
public static string name = "AGRoomObjectChanges";
public static DediConfig<Dictionary<string, List<RecChange>>> config = new(name, "[]", null);
}

View File

@@ -1,11 +1,21 @@
using BepInEx.Configuration;
namespace undead_universal_patch_il2cpp.Core
namespace undead_universal_patch_il2cpp.Core.Config
{
public static class GenericConfig
{
public static ConfigEntry<bool> PatchDebug;
public static ConfigEntry<bool> LogAllRequests;
public static ConfigEntry<bool> VerboseRequestLogs;
}
public static class GenericConfigDefaults
{
public static bool PatchDebug = false;
public static bool LogAllRequests = false;
public static bool VerboseRequestLogs = false;
}
public static class PatchConfig
{
public static ConfigEntry<bool> CertificatePatch;
public static ConfigEntry<bool> HilePatch;
public static ConfigEntry<bool> SignalRHandshakeFix;
@@ -13,10 +23,8 @@ namespace undead_universal_patch_il2cpp.Core
public static ConfigEntry<bool> RegistrationPatch;
public static ConfigEntry<bool> AFKPatch;
}
public static class GenericConfigDefaults
public static class PatchConfigDefaults
{
public static bool PatchDebug = false;
public static bool LogAllRequests = false;
public static bool CertificatePatch = false;
public static bool HilePatch = false;
public static bool SignalRHandshakeFix = false;
@@ -24,13 +32,13 @@ namespace undead_universal_patch_il2cpp.Core
public static bool RegistrationPatch = false;
public static bool AFKPatch = false;
}
public static class AssetChangesConfig
public static class ServerPatchesConfig
{
public static ConfigEntry<bool> AGRoomChanges;
public static ConfigEntry<bool> CustomEmotes;
}
public static class AssetChangesConfigDefaults
public static class ServerPatchesConfigDefaults
{
public static bool AGRoomChanges = false;
public static bool CustomEmotes = false;
}
public static class GameManagerConfig
{
@@ -56,9 +64,9 @@ namespace undead_universal_patch_il2cpp.Core
{
public static ConfigEntry<bool> PatchPhotonIds;
public static ConfigEntry<bool> PunLogging;
public static ConfigEntry<bool> SelfHosted;
public static ConfigEntry<string> AppID;
public static ConfigEntry<string> VoiceAppID;
public static ConfigEntry<bool> SelfHosted;
public static ConfigEntry<string> ServerAddress;
public static ConfigEntry<int> ServerPort;
}
@@ -66,9 +74,9 @@ namespace undead_universal_patch_il2cpp.Core
{
public static bool PatchPhotonIds = false;
public static bool PunLogging = false;
public static bool SelfHosted = false;
public static string AppID = "replace-me-please";
public static string VoiceAppID = "replace-me-please";
public static bool SelfHosted = false;
public static string ServerAddress = "127.0.0.1";
public static int ServerPort = 5055;
}

View File

@@ -0,0 +1,64 @@
using UnityEngine;
using System.Collections.Generic;
using System.Collections.Concurrent;
using Mapster;
using System;
using System.Linq;
using undead_universal_patch_il2cpp.Core.Config;
namespace undead_universal_patch_il2cpp.Core.CustomRecNet.CustomEmotes;
public class EmoteConfigDTO
{
public string UniqueName { get; set; }
public string NewText { get; set; }
public string RoomChatText { get; set; }
public string FacialExpression { get; set; }
public bool ForceEmoteBubble { get; set; }
public bool OnlyBroadcastToTeam { get; set; }
}
public class EmoteConfig
{
public static void Patch(List<EmoteConfigDTO> emotes)
{
UniversalPatchPlugin.Log.LogInfo("Setting new emotes");
var internalEmotes = RecRoom.AGUI.Expresso.ContextualEmotesSettings.ConfigAsset.Emotes.ToList();
foreach (var emote in emotes)
{
var internalEmote = internalEmotes.Find(match => match.emoteUniqueName == emote.UniqueName);
if (internalEmote != null)
{
emote.Adapt(internalEmote);
}
}
Util.ConditionalDebug($"{emotes.Count} new emote configurations");
}
}
public class CustomEmotes : MonoBehaviour
{
private static readonly ConcurrentQueue<Action> mainThreadQueue = new ConcurrentQueue<Action>();
public void Start()
{
if (ServerPatchesConfig.CustomEmotes.Value)
RecNetInteractions.postAuthenticationActions.Add(DownloadCustomEmotes);
}
void Update()
{
while (mainThreadQueue.TryDequeue(out var action))
{
try { action(); }
catch (Exception ex) { UniversalPatchPlugin.Log.LogError(ex); }
}
}
void DownloadCustomEmotes()
{
RecNetInteractions.SendRequest<List<EmoteConfigDTO>>(BestHTTP.HTTPMethods.Get, RecNet.Service.API, "/api/undead/v1/emotes", EmoteConfig.Patch);
}
}

View File

@@ -0,0 +1,48 @@
using System;
using System.Collections.Generic;
using System.Text.Json;
using BestHTTP;
using Il2CppInterop.Runtime;
using RecNet;
using RecRoom.Async;
namespace undead_universal_patch_il2cpp.Core.CustomRecNet;
public class RecNetInteractions
{
public static string AccessToken { get; set; }
public static List<Action> postNameServerActions = [];
public static List<Action> postAuthenticationActions = [];
public static Il2CppSystem.Uri CreateServiceUri(Service service, string pathAndQuery)
{
Il2CppSystem.Uri uri = RecNet.Core.GetServiceUri(service) ?? throw new Exception("Service is not available");
var newUri = new Il2CppSystem.Uri(uri, pathAndQuery);
return newUri;
}
public static bool HasNameserverConnected()
{
return RecNet.Core.ServiceUris.Count > 1;
}
public static void SendRequest<T>(HTTPMethods method, Service service, string requestUri, Action<T> reqFinished)
{
var res = RecNet.Core.SendRequest(method, service, requestUri);
res.Then(DelegateSupport.ConvertDelegate<Il2CppSystem.Action<HTTPResponse>>((HTTPResponse res) =>
{
try
{
var data = JsonSerializer.Deserialize<T>(res.DataAsText);
reqFinished(data);
}
catch (Exception ex)
{
UniversalPatchPlugin.Log.LogError($"'{requestUri}' failed\n{ex}");
}
}));
}
}

133
Core/Init.cs Normal file
View File

@@ -0,0 +1,133 @@
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.CustomRecNet.CustomEmotes;
using undead_universal_patch_il2cpp.Core.UndeadGameManager;
namespace undead_universal_patch_il2cpp.Core;
public class Initialization
{
public static void Initialize()
{
Util.LocalInstanceGuid = Guid.NewGuid().ToString();
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();
}
private static void AttachGameObjects()
{
UniversalPatchPlugin.Log.LogInfo("Attaching game objects");
UniversalPatchPlugin.Instance.AddComponent<CustomEmotes>();
}
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." +
"This 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.");
ServerPatchesConfig.CustomEmotes = UniversalPatchPlugin.Instance.Config.Bind("ServerPatches", "CustomEmotes", ServerPatchesConfigDefaults.CustomEmotes,
"Modify the game's emote text with a configuration from the server. Requires a custom server.");
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 logging sent by Photon/PUN/Voice (useful for server debugging)");
PhotonConfig.SelfHosted = UniversalPatchPlugin.Instance.Config.Bind("Photon", "IsSelfHosted", PhotonConfigDefaults.SelfHosted,
"When enabled, use a self-hosted 'OnPremises' PhotonSocketServer. (EXPERIMENTAL)" +
"\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 application (either 'Master' or 'Game')");
PhotonConfig.VoiceAppID = UniversalPatchPlugin.Instance.Config.Bind("Photon", "VoiceAppID", PhotonConfigDefaults.VoiceAppID,
"The new target Voice App ID from the Photon dashboard." +
"\nWhen self-hosting, this value is ignored, since Photon voice in Rec Room is based on PUN.");
PhotonConfig.ServerAddress = UniversalPatchPlugin.Instance.Config.Bind("Photon", "ServerAddress", PhotonConfigDefaults.ServerAddress,
"Address of the Photon master server (ignored if not using self-hosted)");
PhotonConfig.ServerPort = UniversalPatchPlugin.Instance.Config.Bind("Photon", "ServerPort", PhotonConfigDefaults.ServerPort,
"Photon master server UDP port (ignored if not using self-hosted)");
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);
}
}

View File

@@ -1,7 +1,123 @@
namespace undead_universal_patch_il2cpp.Core
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Security.Cryptography;
using System.Text;
using BepInEx.Configuration;
using HarmonyLib;
using undead_universal_patch_il2cpp.Core.Config;
namespace undead_universal_patch_il2cpp.Core
{
public class PatchTypesResult
{
public string Description;
public Type Type;
public MethodInfo Method;
public bool Success;
}
public class Util
{
private static readonly PatchTypesResult UnsuccessfulPatchResult = new()
{
Type = null,
Method = null,
Success = false
};
public static string LocalInstanceGuid { set; get; }
public static void ConditionalDebug(string msg)
{
if (GenericConfig.PatchDebug.Value) UniversalPatchPlugin.Log.LogDebug(msg);
}
public static PatchTypesResult ConfigsPreparePatchTypes(ConfigEntry<bool>[] config, string description, string targetTypeName, string methodName)
{
if (config.All(conf => conf.Value)) return VerifyPatchTypes(description, targetTypeName, methodName);
else return UnsuccessfulPatchResult;
}
public static PatchTypesResult ConfigPreparePatchTypes(ConfigEntry<bool> config, string description, string targetTypeName, string methodName)
{
if (config.Value) return VerifyPatchTypes(description, targetTypeName, methodName);
else return UnsuccessfulPatchResult;
}
public static PatchTypesResult PreparePatchTypes(string description, string targetTypeName, string methodName)
{
return VerifyPatchTypes(description, targetTypeName, methodName);
}
public static PatchTypesResult PreparePatchSpecificTypes(string description, string targetTypeName, string methodName, string[] generics)
{
return VerifyPatchTypes(description, targetTypeName, methodName, [.. generics]);
}
private static PatchTypesResult VerifyPatchTypes(string description, string targetTypeName, string methodName, List<string> generics = null)
{
ConditionalDebug($"Loading patch '{description}'");
Type targetType = AccessTools.TypeByName(targetTypeName);
if (targetType == null)
{
UniversalPatchPlugin.Log.LogWarning($"Patch '{description}' disabled. The type for this patch was not found.");
return UnsuccessfulPatchResult;
}
List<Type> types = null;
if (generics != null)
{
types = generics.Select(AccessTools.TypeByName).ToList();
if (!types.All(type => type != null))
{
UniversalPatchPlugin.Log.LogWarning($"Patch '{description}' disabled. One or more generics for this patch were not found.");
return UnsuccessfulPatchResult;
}
}
MethodInfo method;
if (generics != null && types != null)
{
ConditionalDebug($"Fetching method type: Type '{targetType.Name}', Method '{methodName}', Generics: {types.Count}");
method = AccessTools.Method(targetType, methodName, [.. types]);
}
else
{
ConditionalDebug($"Fetching method type: Type '{targetType.Name}', Method '{methodName}'");
method = AccessTools.Method(targetType, methodName);
}
if (method == null)
{
UniversalPatchPlugin.Log.LogWarning($"Patch '{description}' disabled. The method for this patch was not found.");
return UnsuccessfulPatchResult;
}
UniversalPatchPlugin.Log.LogInfo($"Patch '{description}' succeeded validation.");
return new PatchTypesResult
{
Description = description,
Type = targetType,
Method = method,
Success = true
};
}
public static PatchTypesResult PostRequireTypes(PatchTypesResult result, object[] objects)
{
if (result.Success)
{
if (!objects.All(obj => obj != null))
{
UniversalPatchPlugin.Log.LogError($"'{result.Description}' failed: A postrequire type was not found.");
return UnsuccessfulPatchResult;
}
else return result;
}
else return UnsuccessfulPatchResult;
}
}
}