Skip to content

Commit 00ab66a

Browse files
committed
autowatch supports auroras hashed dash code trigger
1 parent 561c643 commit 00ab66a

File tree

4 files changed

+108
-1
lines changed

4 files changed

+108
-1
lines changed

Source/Gameplay/AutoWatchEntity/HelperClasses.cs

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
using Celeste.Mod.TASHelper.Utils;
22
using Microsoft.Xna.Framework;
33
using Monocle;
4+
using System.Security.Cryptography;
45
using System.Runtime.CompilerServices;
6+
using System.Text;
7+
using System.Diagnostics;
58

69
namespace Celeste.Mod.TASHelper.Gameplay.AutoWatchEntity;
710

@@ -210,6 +213,73 @@ public static string ToCode(int angle, int offset) {
210213
}
211214
return DashCodes[num];
212215
}
216+
217+
public static class AurorasHashedDashCode {
218+
219+
public static int AcceptableLengthUpperBound = 8;
220+
221+
private static readonly Dictionary<string, string> results = new Dictionary<string, string>();
222+
223+
private static readonly HashSet<string> failures = new HashSet<string>();
224+
225+
private static readonly string[] DashCodesWithoutBlank = ["L", "UL", "U", "UR", "R", "DR", "D", "DL"]; // we assume "" is not used
226+
private static byte[] AurorasGetHash(string inputString) {
227+
using HashAlgorithm hashAlgorithm = SHA256.Create();
228+
return hashAlgorithm.ComputeHash(Encoding.UTF8.GetBytes("AURORAWASHERE" + inputString));
229+
}
230+
231+
private static string AurorasGetHashString(string inputString) {
232+
StringBuilder stringBuilder = new StringBuilder();
233+
byte[] hash = AurorasGetHash(inputString);
234+
foreach (byte b in hash) {
235+
stringBuilder.Append(b.ToString("X2"));
236+
}
237+
return stringBuilder.ToString();
238+
}
239+
240+
public static bool TryGetInputs(string hash, int length, out string inputs) {
241+
if (results.TryGetValue(hash.ToLowerInvariant(), out string input)) {
242+
inputs = input;
243+
return true;
244+
}
245+
if (failures.Contains(hash.ToLowerInvariant())) {
246+
inputs = "";
247+
return false;
248+
}
249+
if (length > AcceptableLengthUpperBound) {
250+
inputs = "";
251+
return false;
252+
}
253+
Stopwatch stopwatch = Stopwatch.StartNew();
254+
Logger.Log(LogLevel.Warn, "TASHelper", "Trying to decrypt Auroras' DashcodeHashTrigger, please wait...");
255+
string lower = hash.ToLowerInvariant();
256+
uint upperBound = (uint)2 << (3 * length - 1);
257+
for (uint i = 0; i < upperBound; i++) {
258+
if (AurorasGetHashString(CastToDashCode(i, length)).ToLowerInvariant() == lower) {
259+
inputs = CastToDashCode(i, length);
260+
results.Add(lower, inputs);
261+
stopwatch.Stop();
262+
Logger.Log(LogLevel.Warn, "TASHelper", $"Found! {inputs} match, costs {stopwatch.ElapsedMilliseconds} ms.");
263+
return true;
264+
}
265+
}
266+
inputs = "";
267+
failures.Add(lower);
268+
stopwatch.Stop();
269+
Logger.Log(LogLevel.Warn, "TASHelper", $"Not Found! Costs {stopwatch.ElapsedMilliseconds} ms.");
270+
return false;
271+
}
272+
273+
private static string CastToDashCode(uint num, int length) {
274+
List<string> list = new();
275+
for (int loop = 0; loop < length; loop++) {
276+
list.Add(DashCodesWithoutBlank[num % 8]);
277+
num >>= 3;
278+
}
279+
return string.Join(",", list);
280+
}
281+
}
282+
213283
}
214284

215285
internal static class CoroutineFinder {

Source/Gameplay/AutoWatchEntity/Trigger/AbstractTriggerRenderer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ public override void DebugRenderImpl() {
209209
if (hitbox is not null) {
210210
Draw.Rect(hitbox.AbsoluteX, hitbox.AbsoluteY, hitbox.Width, hitbox.Height, innerRegion);
211211
}
212-
// Draw.HollowRect(nearPlayerDetector.AbsoluteX, nearPlayerDetector.AbsoluteY, nearPlayerDetector.Width, nearPlayerDetector.Height, Color.Pink);
212+
Draw.HollowRect(nearPlayerDetector.AbsoluteX, nearPlayerDetector.AbsoluteY, nearPlayerDetector.Width, nearPlayerDetector.Height, Color.Pink);
213213
}
214214

215215
public void SetVerticallyClampedCenter() {

Source/Gameplay/AutoWatchEntity/Trigger/TriggerDynamicInfoGetter.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ internal static class ModTriggerDynamicInfo {
5454
public static void AddToDictionary() {
5555
HandleMemorialHelper();
5656
HandleSardine7();
57+
HandleAurorasHelper();
5758
}
5859
public static void Add(Type type, TriggerDynamicPlayerlessHandler handler) {
5960
TriggerInfoHelper.DynamicInfoPlayerlessGetters.TryAdd(type, handler);
@@ -120,4 +121,24 @@ public static void HandleSardine7() {
120121
});
121122
}
122123
}
124+
125+
public static void HandleAurorasHelper() {
126+
if (ModUtils.GetType("AurorasHelper", "Celeste.Mod.AurorasHelper.DashcodeHashTrigger") is { } hashedDashCode) {
127+
Add(hashedDashCode, (trigger, level) => {
128+
string flag = trigger.GetFieldValue<string>("flag");
129+
bool flagState = trigger.GetFieldValue<bool>("flag_state");
130+
if (level.Session.GetFlag(flag) == flagState) {
131+
return $"{(flagState ? "Added: " : "Removed: ")}{flag}";
132+
}
133+
List<string> currentInputs = trigger.GetFieldValue<List<string>>("currentInputs");
134+
// techinically, your last dash need to be inside the trigger (so the trigger will be enabled)
135+
if (flagState) {
136+
return "Current: " + string.Join(",", currentInputs.Select(DashCode.ToCode)) + "\nAdd: " + flag;
137+
}
138+
else {
139+
return "Current: " + string.Join(",", currentInputs.Select(DashCode.ToCode)) + "\nRemove: " + flag;
140+
}
141+
});
142+
}
143+
}
123144
}

Source/Gameplay/AutoWatchEntity/Trigger/TriggerStaticInfoGetter.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ public static void AddToDictionary() {
9999
HandleMemorialHelper();
100100
HandleSardine7();
101101
HandleContortHelper();
102+
HandleAurorasHelper();
102103
}
103104

104105
public static void Add(Type type, TriggerStaticHandler handler) {
@@ -290,4 +291,19 @@ public static void HandleContortHelper() {
290291
});
291292
}
292293
}
294+
295+
public static void HandleAurorasHelper() {
296+
// not finished
297+
298+
if (ModUtils.GetType("AurorasHelper", "Celeste.Mod.AurorasHelper.DashcodeHashTrigger") is { } hashedDashCode) {
299+
Add(hashedDashCode, (trigger, _) => {
300+
string hashedCode = trigger.GetFieldValue<string>("hashedCode");
301+
int length = trigger.GetFieldValue<int>("codeLength");
302+
if (DashCode.AurorasHashedDashCode.TryGetInputs(hashedCode, length, out string inputs)) {
303+
return "DashCode: " + inputs;
304+
}
305+
return "";
306+
});
307+
}
308+
}
293309
}

0 commit comments

Comments
 (0)