From 368f1080a7f0155e931fb37897ce98d267f6f2ed Mon Sep 17 00:00:00 2001 From: Wiz Date: Sun, 28 Apr 2024 02:55:21 +0100 Subject: [PATCH] Changed patch to be compatible with Passenger Jobs. --- CL.Game/LicenseManager.cs | 2 +- ...okletCreator_StaticRenderBookletPatches.cs | 54 ++++++------------- CL.Game/Patches/SaveGameManagerPatches.cs | 2 +- 3 files changed, 18 insertions(+), 40 deletions(-) diff --git a/CL.Game/LicenseManager.cs b/CL.Game/LicenseManager.cs index 83b7ef7..5cf3cb0 100644 --- a/CL.Game/LicenseManager.cs +++ b/CL.Game/LicenseManager.cs @@ -267,7 +267,7 @@ private static Sprite TryLoadIcon(string directory) tex.LoadImage(data); // Create a sprite that covers the whole texture. - return Sprite.Create(tex, new Rect(0.0f, 0.0f, tex.width, tex.height), new Vector2(0.5f, 0.5f), 100); + return Sprite.Create(tex, new Rect(0.0f, 0.0f, tex.width, tex.height), new Vector2(0.5f, 0.5f), 100, 1, SpriteMeshType.Tight); } return null!; diff --git a/CL.Game/Patches/BookletCreator_StaticRenderBookletPatches.cs b/CL.Game/Patches/BookletCreator_StaticRenderBookletPatches.cs index 295fce6..1ae8145 100644 --- a/CL.Game/Patches/BookletCreator_StaticRenderBookletPatches.cs +++ b/CL.Game/Patches/BookletCreator_StaticRenderBookletPatches.cs @@ -1,57 +1,35 @@ using DV.Booklets; using HarmonyLib; -using System.Collections.Generic; -using System.Reflection.Emit; -using System.Reflection; using UnityEngine; -using System; +using DV.Booklets.Rendered; +using DV.RenderTextureSystem.BookletRender; namespace CL.Game.Patches { - // Once again thanks to Passenger Jobs. [HarmonyPatch(typeof(BookletCreator_StaticRenderBooklet))] internal class BookletCreator_StaticRenderBookletPatches { - private static MethodInfo s_resourcesLoadMethod = AccessTools.Method( - typeof(Resources), nameof(Resources.Load), new[] { typeof(string), typeof(Type) }); - [HarmonyPatch(nameof(BookletCreator_StaticRenderBooklet.Render))] - [HarmonyTranspiler] - public static IEnumerable RenderTranspiler(IEnumerable instructions) + [HarmonyPrefix, HarmonyPatch(nameof(BookletCreator_StaticRenderBooklet.Render))] + public static bool RenderPrefix(GameObject existingBooklet, string renderPrefabName, ref RenderedTexturesBooklet __result) { - bool skipping = false; - - foreach (var instruction in instructions) + if (!LicenseManager.KeyToPrefab.TryGetValue(renderPrefabName, out var result)) { - if (skipping) - { - if (instruction.Calls(s_resourcesLoadMethod)) - { - skipping = false; - } - continue; - } + return true; + } - if (instruction.opcode == OpCodes.Ldtoken) - { - yield return CodeInstruction.Call((string s) => LoadRenderPrefab(s)); - skipping = true; - continue; - } + StaticTextureRenderBase component = Object.Instantiate(result, DV.RenderTextureSystem.RenderTextureSystem.Instance.transform.position, + Quaternion.identity).GetComponent(); - yield return instruction; - } - } + // Since this isn't a resource we have to reactive the object or it won't draw anything. + component.gameObject.SetActive(true); - private static UnityEngine.Object LoadRenderPrefab(string name) - { - if (!LicenseManager.KeyToPrefab.TryGetValue(name, out var result)) - { - result = Resources.Load(name); - } + RenderedTexturesBooklet component2 = existingBooklet.GetComponent(); + component2.RegisterTexturesGeneratedEvent(component); + component.GenerateStaticPagesTextures(); + __result = component2; - result!.SetActive(true); - return result; + return false; } } } diff --git a/CL.Game/Patches/SaveGameManagerPatches.cs b/CL.Game/Patches/SaveGameManagerPatches.cs index 11cea18..d689c61 100644 --- a/CL.Game/Patches/SaveGameManagerPatches.cs +++ b/CL.Game/Patches/SaveGameManagerPatches.cs @@ -5,7 +5,7 @@ namespace CL.Game.Patches [HarmonyPatch(typeof(SaveGameManager))] internal class SaveGameManagerPatches { - [HarmonyPrefix, HarmonyPatch("DoSaveIO")] + [HarmonyPrefix, HarmonyPatch(nameof(SaveGameManager.DoSaveIO))] public static void InjectSaveData(SaveGameData data) { SaveInjector.InjectDataIntoSaveGame(data);