-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlacementBoardPatches.Relocation.cs
More file actions
92 lines (80 loc) · 2.99 KB
/
PlacementBoardPatches.Relocation.cs
File metadata and controls
92 lines (80 loc) · 2.99 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
using System.Collections.Generic;
using System.Reflection.Emit;
using Assets.Scripts;
using Assets.Scripts.Inventory;
using Assets.Scripts.Objects;
using HarmonyLib;
using LaunchPadBooster.Utils;
using UnityEngine;
namespace LibConstruct;
[HarmonyPatch(typeof(InventoryManager))]
static partial class InventoryManagerPatch
{
[HarmonyPatch("NormalMode"), HarmonyTranspiler]
static IEnumerable<CodeInstruction> NormalMode(IEnumerable<CodeInstruction> instructions)
{
var matcher = new CodeMatcher(instructions);
var match = new CodeMatch(CodeInstruction.Call(() => KeyManager.GetMouse(default)));
// go to second KeyManager.GetMouse call
matcher.MatchStartForward(match).Advance(1).MatchStartForward(match);
matcher.ThrowIfInvalid("could not find InventoryManager.NormalMode insertion point");
matcher.Advance(1);
matcher.Insert(CodeInstruction.Call(() => NormalModeRelocateCheck()));
return matcher.Instructions();
}
static void NormalModeRelocateCheck()
{
if (!PlacementBoard.IsRelocating)
return;
var action = PlacementBoard.RelocateAction();
var color = action.IsDisabled ? Color.red : Color.green;
InventoryManager.Instance.TooltipRef.HandleToolTipDisplay(new PassiveTooltip(action, string.Empty, PlacementBoard.RelocatingStructure.GetAsThing)
{
color = color,
});
color.a = InventoryManager.Instance.CursorAlphaInteractable;
CursorManager.SetSelection(action.Selection, color);
CursorManager.SetSelectionVisibility(InventoryManager.ShowUi && PlacementBoard.RelocatingCursor.GetAsThing.gameObject.activeInHierarchy);
}
[HarmonyPatch("NormalModeThing"), HarmonyPrefix]
static bool NormalModeThing(ref bool __result)
{
if (PlacementBoard.IsRelocating)
{
__result = true;
return false;
}
return true;
}
public static bool IsRelocateAttack = false;
[HarmonyPatch("HandlePrimaryUse"), HarmonyPrefix]
static bool HandlePrimaryUse()
{
if (!PlacementBoard.IsRelocating)
{
// reset flag so we're sure the next attack is a relocate start
IsRelocateAttack = false;
return true;
}
var action = PlacementBoard.RelocateAction();
// only relocate if we released the mouse since starting the relocate
if (!action.IsDisabled && PlacementBoard.RelocateMouseReleased)
PlacementBoard.FinishRelocate();
return false;
}
[HarmonyPatch("UseItemComplete"), HarmonyTranspiler]
static IEnumerable<CodeInstruction> UseItemComplete(IEnumerable<CodeInstruction> instructions)
{
var matcher = new CodeMatcher(instructions);
matcher.MatchStartForward(new CodeMatch(OpCodes.Ldfld, ReflectionUtils.Field(() => default(DynamicThing).AttackWithEvent)));
matcher.RemoveInstruction();
matcher.Insert(CodeInstruction.Call(() => GetAttackWithEvent(default)));
return matcher.Instructions();
}
static AttackWithEvent GetAttackWithEvent(DynamicThing thing)
{
if (IsRelocateAttack)
return AttackWithEvent.Local;
return thing.AttackWithEvent;
}
}