Repository navigation
Expand file tree
/
Copy pathKillerFrequencyAccessMod.WalkContainers.cs
More file actions
218 lines (191 loc) · 8.69 KB
/
Copy pathKillerFrequencyAccessMod.WalkContainers.cs
File metadata and controls
218 lines (191 loc) · 8.69 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
using System;
using System.Collections.Generic;
using UnityEngine;
using GameInteractableBase = Il2Cpp.InteractableBase;
namespace Killer_Frequency_Access;
/// <summary>
/// Objects that cannot be seen from anywhere because something encloses or holds them. When the
/// standing-spot search finds no spot, the colliders its sight lines hit instead say why, one rule for
/// every case:
/// - most hits on a closed container (Il2Cpp.Openable above the hit collider that is not IsFullyOpen:
/// DrawerOpenable, DoorOpenable on cabinets): walk to the container, open it (hinged doors pushed on their
/// hinge as in WalkDoors, drawers with Openable.Open(); the
/// user agreed 2026-11-23), wait until it is open, then walk to the object. Locked: say so.
/// DrawerOpenable overrides Open(); DoorOpenable does not, so whether the base Open() moves a cabinet
/// door is unverified and every open is checked with HowOpen(), as for room doors.
/// - most hits on an interactable that holds the object (the object is below it in the hierarchy, as a
/// tape in a cassette player slot, where the game reported the slot observed in the 2026-11-19 run):
/// walk to the holder instead; its own actions (take out) reach the object.
/// </summary>
public sealed partial class KillerFrequencyAccessMod
{
private const float ContainerOpenWaitSeconds = 3f;
private readonly Dictionary<int, (Collider Collider, int Hits)> _sightBlockers = new();
private Il2Cpp.Openable? _containerToOpen;
private Transform? _containerFinalTarget;
private bool _containerOpening;
private float _containerOpenStartTime;
private float _containerOpenStartAmount;
private void NoteSightBlocker(Collider collider)
{
var id = collider.GetInstanceID();
_sightBlockers[id] = _sightBlockers.TryGetValue(id, out var known) ? (collider, known.Hits + 1) : (collider, 1);
}
private void ClearContainerPlan()
{
_containerToOpen = null;
_containerFinalTarget = null;
_containerOpening = false;
}
/// <summary>
/// Called when a walk found no standing spot. True when the walk was redirected (to a container to
/// open, or to the holder of the target) or stopped with an explanation.
/// </summary>
private bool TryRedirectHiddenTarget(Transform target)
{
if (_sightBlockers.Count == 0)
{
return false;
}
// The collider hit most often from the candidate eyes.
Collider? blocker = null;
var most = 0;
foreach (var (collider, hits) in _sightBlockers.Values)
{
if (collider != null && hits > most)
{
blocker = collider;
most = hits;
}
}
if (blocker == null)
{
return false;
}
var name = GetSpokenName(target);
var openable = blocker.GetComponentInParent<Il2Cpp.Openable>();
if (openable != null && !openable.IsFullyOpen())
{
var containerName = GetSpokenName(openable.transform);
if (openable.IsLocked())
{
MelonLoader.MelonLogger.Msg($"[walk] {name} is behind {BuildHierarchyPath(openable.transform)}, which is locked");
StopAutoWalk("container locked");
SpeakWalk($"{name} is in {containerName}, which is locked");
return true;
}
var containerTarget = ContainerInteractable(openable);
MelonLoader.MelonLogger.Msg($"[walk] {name} is hidden by closed {BuildHierarchyPath(openable.transform)} ({most} sight lines); walking to {(containerTarget != null ? BuildHierarchyPath(containerTarget) : "its position")} to open it");
_containerToOpen = openable;
_containerFinalTarget = target;
SpeakWalk($"{name} is in {containerName}. Opening it first");
StartAutoWalkTo(containerTarget ?? openable.transform, keepContainerPlan: true);
return true;
}
if (TryGetGameInteractable(blocker.transform, out var holder) && target.IsChildOf(holder.transform) && holder.transform != target)
{
MelonLoader.MelonLogger.Msg($"[walk] {name} is held by {BuildHierarchyPath(holder.transform)} ({most} sight lines); walking to it");
SpeakWalk($"{name} is in {GetSpokenName(holder.transform)}. Walking there");
StartAutoWalkTo(holder.transform);
return true;
}
MelonLoader.MelonLogger.Msg($"[walk] no spot for {name}; sight lines mostly hit {BuildHierarchyPath(blocker.transform)} ({most})");
return false;
}
/// <summary>The container's flat-screen interactable (on it or below it, not a VR-only handle), to walk to.</summary>
private static Transform? ContainerInteractable(Il2Cpp.Openable openable)
{
Transform? fallback = null;
foreach (var candidate in openable.GetComponentsInChildren<GameInteractableBase>())
{
if (candidate == null || !candidate.isActiveAndEnabled)
{
continue;
}
if (!candidate.OculusOnly)
{
return candidate.transform;
}
fallback ??= candidate.transform;
}
var above = openable.GetComponentInParent<GameInteractableBase>();
return above != null && !above.OculusOnly ? above.transform : fallback;
}
/// <summary>
/// Arrived at a container to open: opens it, waits, then walks on to the object inside. True while
/// this owns the walk (the caller must not finish the walk as arrived).
/// </summary>
private bool UpdateContainerOpening(float now)
{
if (_containerToOpen == null)
{
return false;
}
var container = _containerToOpen;
var name = GetSpokenName(container.transform);
var hinged = container.TryCast<Il2Cpp.DoorOpenable>();
if (!_containerOpening)
{
_containerOpening = true;
_containerOpenStartTime = now;
_containerOpenStartAmount = container.HowOpen();
if (hinged != null && TryGetNavigationOrigin(out var origin) && TryBeginDoorPush(hinged, origin.position, now, out var started))
{
// Cabinet doors are DoorOpenables: Open() does not move them (2026-11-23 run), so they are
// pushed on their hinge like room doors.
MelonLoader.MelonLogger.Msg($"[walk] opening {BuildHierarchyPath(container.transform)} on its hinge ({started})");
return true;
}
MelonLoader.MelonLogger.Msg($"[walk] opening {BuildHierarchyPath(container.transform)} (open {_containerOpenStartAmount:0.00})");
container.Open();
return true;
}
var target = _containerFinalTarget;
float amount;
if (hinged != null && _walkOpeningDoor != null)
{
var state = StepDoorPush(now, out var report);
if (state == DoorPushState.Pushing)
{
return true;
}
_walkOpeningDoor = null;
ClearContainerPlan();
if (state == DoorPushState.Failed)
{
MelonLoader.MelonLogger.Msg($"[walk] {name} did not open: {report}");
StopAutoWalk("container did not open");
SpeakWalk($"{name} did not open. Open it, then walk again");
return true;
}
MelonLoader.MelonLogger.Msg($"[walk] {name} {report}; walking on to {(target != null ? GetSpokenName(target) : "the object")}");
StopAutoWalk("container opened");
if (target != null)
{
StartAutoWalkTo(target);
}
return true;
}
amount = container.HowOpen();
var opened = container.IsFullyOpen();
if (!opened && now - _containerOpenStartTime < ContainerOpenWaitSeconds)
{
return true;
}
ClearContainerPlan();
if (!opened && amount <= _containerOpenStartAmount + 0.2f)
{
MelonLoader.MelonLogger.Msg($"[walk] {name} did not open: Open() left HowOpen at {amount:0.00} (was {_containerOpenStartAmount:0.00})");
StopAutoWalk("container did not open");
SpeakWalk($"{name} did not open. Open it, then walk again");
return true;
}
MelonLoader.MelonLogger.Msg($"[walk] {name} open ({amount:0.00}) after {now - _containerOpenStartTime:0.0} s; walking on to {(target != null ? GetSpokenName(target) : "the object")}");
StopAutoWalk("container opened");
if (target != null)
{
StartAutoWalkTo(target);
}
return true;
}
}