Skip to content

Commit

Permalink
Changed patch to be compatible with Passenger Jobs.
Browse files Browse the repository at this point in the history
  • Loading branch information
WhistleWiz committed Apr 28, 2024
1 parent 0af3623 commit 368f108
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 40 deletions.
2 changes: 1 addition & 1 deletion CL.Game/LicenseManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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!;
Expand Down
54 changes: 16 additions & 38 deletions CL.Game/Patches/BookletCreator_StaticRenderBookletPatches.cs
Original file line number Diff line number Diff line change
@@ -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<CodeInstruction> RenderTranspiler(IEnumerable<CodeInstruction> 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<StaticTextureRenderBase>();

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<GameObject>(name);
}
RenderedTexturesBooklet component2 = existingBooklet.GetComponent<RenderedTexturesBooklet>();
component2.RegisterTexturesGeneratedEvent(component);
component.GenerateStaticPagesTextures();
__result = component2;

result!.SetActive(true);
return result;
return false;
}
}
}
2 changes: 1 addition & 1 deletion CL.Game/Patches/SaveGameManagerPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 368f108

Please sign in to comment.