using ActionGame; using BepInEx; using ChaCustom; using Common; using ExtensibleSaveFormat; using FreeH; using HarmonyLib; using Illusion.Game; using System; using System.Collections.Generic; using System.Linq; using UniRx; using UnityEngine.UI; namespace IllusionFixes { [BepInProcess(Constants.GameProcessName)] // Need a completely separate version for KK Party [BepInProcess(Constants.VRProcessName)] [BepInPlugin(GUID, PluginName, Constants.PluginsVersion)] public class CharacterListOptimizations : BaseUnityPlugin { public const string GUID = "KK_Fix_CharacterListOptimizations"; public const string PluginName = "Character List Optimizations"; internal void Awake() { var h = Harmony.CreateAndPatchAll(typeof(Hooks)); // The VR classes are only available in VR module so they can't be directly referenced var vrType = Type.GetType("VR.VRClassRoomCharaFile, Assembly-CSharp"); if (vrType != null) { h.Patch(vrType.GetMethod("InitializeList", AccessTools.all), prefix: new HarmonyMethod(typeof(Hooks), nameof(Hooks.ClassRoomCharaFileInitializeListPrefix)), postfix: new HarmonyMethod(typeof(Hooks), nameof(Hooks.ClassRoomCharaFileInitializeListPostfix))); h.Patch(vrType.GetMethod("Start", AccessTools.all), prefix: new HarmonyMethod(typeof(Hooks), nameof(Hooks.ClassRoomCharaFileStartPrefix)), postfix: new HarmonyMethod(typeof(Hooks), nameof(Hooks.ClassRoomCharaFileStartPostfix))); } } internal class Hooks { #region Free H List /// /// Turn off ExtensibleSaveFormat events /// [HarmonyPrefix, HarmonyPatch(typeof(FreeHClassRoomCharaFile), "Start")] internal static void FreeHClassRoomCharaFileStartPrefix() => ExtendedSave.LoadEventsEnabled = false; /// /// Turn back on ExtensibleSaveFormat events, load a copy of the character with extended data on this time, and use that instead. /// [HarmonyPostfix, HarmonyPatch(typeof(FreeHClassRoomCharaFile), "Start")] internal static void FreeHClassRoomCharaFileStartPostfix(FreeHClassRoomCharaFile __instance) { ExtendedSave.LoadEventsEnabled = true; ReactiveProperty info = Traverse.Create(__instance).Field("info").GetValue>(); ClassRoomFileListCtrl listCtrl = Traverse.Create(__instance).Field("listCtrl").GetValue(); List lstFileInfo = Traverse.Create(listCtrl).Field("lstFileInfo").GetValue>(); Button enterButton = Traverse.Create(__instance).Field("enterButton").GetValue