-
Notifications
You must be signed in to change notification settings - Fork 0
/
PuzzleskipPatcher.cs
51 lines (47 loc) · 1.52 KB
/
PuzzleskipPatcher.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
using FFG.MoM;
using HarmonyLib;
namespace Puzzleskip
{
[HarmonyPatch(typeof(PuzzleViewBase))]
internal class PuzzleskipPatcher
{
[HarmonyPrefix]
[HarmonyPatch("PuzzleClosedEvent")]
static bool PrePuzzleClosedEvent(PuzzleViewBase __instance, ref bool completed)
{
SkipPuzzleButton skipPuzzleButton = __instance.gameObject.GetComponentInChildren<SkipPuzzleButton>();
if (skipPuzzleButton.SkipEnabled)
{
completed = true;
}
return true;
}
[HarmonyPrefix]
[HarmonyPatch("Show")]
static void PreShow(PuzzleViewBase __instance)
{
UIButton button = FindCloseButton(__instance);
if (button != null)
{
if (button.gameObject.GetComponent<SkipPuzzleButton>() == null)
{
button.gameObject.AddComponent<SkipPuzzleButton>();
}
SkipPuzzleButton skipButton = button.gameObject.GetComponent<SkipPuzzleButton>();
skipButton.SkipEnabled = false;
}
}
private static UIButton FindCloseButton(PuzzleViewBase puzzleViewBase)
{
var buttons = puzzleViewBase.GetComponentsInChildren<UIButton>();
foreach (var button in buttons)
{
if (button.name.Contains("Close"))
{
return button;
}
}
return null;
}
}
}