generated from derail-valley-modding/template-umm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changed patch to be compatible with Passenger Jobs.
- Loading branch information
1 parent
0af3623
commit 368f108
Showing
3 changed files
with
18 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 16 additions & 38 deletions
54
CL.Game/Patches/BookletCreator_StaticRenderBookletPatches.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters