using System; using System.Collections.Generic; using System.Reflection; using HarmonyLib; using Mapster; using RecRoom.Core.GameManagement; using RecRoom.Protobuf; using undead_universal_patch_il2cpp.Core; using undead_universal_patch_il2cpp.Core.UndeadGameManager; namespace undead_universal_patch_il2cpp.Patches.UndeadGameManager; [HarmonyPatch] public class GameConfiguratorPatch { static Dictionary gameConfig = GameConfigurator.config.Get(); static string TargetTypeName = "GameConfigurationTool"; static string TargetMethodName = "SetGameConfiguration"; static string Description = "GameConfigurator event patch"; static Type targetType = AccessTools.TypeByName(TargetTypeName); static MethodInfo targetMethod = AccessTools.Method(targetType, TargetMethodName); public static bool Prepare() { if (!GameManagerConfig.StaticGameConfig.Value) return false; if (targetMethod == null) { Plugin.Log.LogWarning($"'{Description}' disabled. The method for this patch was not found."); return false; } Plugin.Log.LogInfo($"'{Description}' succeeded validation."); return true; } public static MethodBase TargetMethod() => targetMethod; public static GameConfigurationData res; public static void Prefix(ref GameConfigurationAsset config, ref bool showNotification) { var conf = config; showNotification = GenericConfig.PatchDebug.Value; var gameConf = gameConfig.GetValueOrDefault(conf.Name, null); if (gameConf == null) { if (GenericConfig.PatchDebug.Value) Plugin.Log.LogDebug($"Game '{conf.Name}' does not have external configuration"); return; } gameConf.Adapt(conf); config = conf; if (GenericConfig.PatchDebug.Value) Plugin.Log.LogDebug($"Applied external game configuration for '{config.Name}'"); } }