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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
|
// Autosplitter script for Lingo 2, by hatkirby.
//
// Massive thanks to the game developer, Brenton, for working with me to
// make this possible.
state("Lingo2") {}
startup
{
// Relative to Livesplit.exe
vars.logFilePath = Directory.GetCurrentDirectory() + "\\autosplitter_lingo2.log";
vars.log = (Action<string>)((string logLine) => {
print("[Lingo 2 ASL] " + logLine);
string time = System.DateTime.Now.ToString("dd/MM/yy hh:mm:ss.fff");
// AppendAllText will create the file if it doesn't exist.
System.IO.File.AppendAllText(vars.logFilePath, time + ": " + logLine + "\r\n");
});
settings.Add("panels", false, "Split on solving a panel");
settings.Add("panels_first", false, "Only split the first time each panel is solved", "panels");
settings.Add("maps", false, "Split on changing maps");
settings.Add("maps_first", false, "Only split the first time a map is entered", "maps");
settings.Add("ends", false, "Split on any ending");
settings.Add("keys", false, "Split on unlocking a key");
settings.Add("paintings", false, "Split on unlocking a gallery painting");
settings.Add("graves", false, "Split on completing a gravestone");
settings.Add("masteries", false, "Split on collecting a mastery");
vars.prevPanel = null;
vars.lastPanel = null;
vars.solvedPanels = new HashSet<string>();
vars.prevMap = "";
vars.visitedMaps = new HashSet<string>();
vars.collectedKeys = new HashSet<string>();
vars.latestKeyKey = null;
vars.log("Autosplitter loaded");
}
init
{
// magic byte array format:
// [0-7]: 9c 46 9f b0 4b 6a e0 8d (random bytes used for sigscanning)
// [8]: Loading flag
// [9]: First movement flag
// [10]: Latest unlocked key (0 if run just started)
// [11]: 1 or 2, indicating the level of the latest unlocked key
// [12-52]: Latest collectable unlocked (null terminated, truncated at 40 chars excluding null)
// [53-93]: Current map name (null terminated, truncated at 40 chars excluding null)
// [94-134]: Map name of latest solved panel (null terminated, truncated at 40 chars excluding null)
// [135-235]: Full nodepath of latest solved panel (null terminated, truncated at 100 chars excluding null)
IntPtr ptr = IntPtr.Zero;
foreach (var page in game.MemoryPages(true).Reverse())
{
var scanner = new SignatureScanner(game, page.BaseAddress, (int)page.RegionSize);
ptr = scanner.Scan(new SigScanTarget(0, "9c 46 9f b0 4b 6a e0 8d"));
if (ptr != IntPtr.Zero)
{
break;
}
}
if (ptr == IntPtr.Zero)
{
throw new Exception("Could not find magic autosplitter array!");
}
vars.loading = new MemoryWatcher<byte>(ptr + 8);
vars.firstInput = new MemoryWatcher<byte>(ptr + 9);
vars.latestKey = new MemoryWatcher<byte>(ptr + 10);
vars.latestKeyLevel = new MemoryWatcher<byte>(ptr + 11);
vars.latestCollectible = new StringWatcher(ptr + 12, 41);
vars.currentMap = new StringWatcher(ptr + 53, 41);
vars.lastPanelMap = new StringWatcher(ptr + 94, 41);
vars.lastPanelPath = new StringWatcher(ptr + 135, 101);
vars.log(String.Format("Magic autosplitter array: {0}", ptr.ToString("X")));
}
update
{
vars.loading.Update(game);
vars.firstInput.Update(game);
vars.latestKey.Update(game);
vars.latestKeyLevel.Update(game);
vars.latestCollectible.Update(game);
vars.currentMap.Update(game);
vars.lastPanelMap.Update(game);
vars.lastPanelPath.Update(game);
if (vars.lastPanelMap.Current != "")
{
vars.lastPanel = string.Format("{0}/{1}", vars.lastPanelMap.Current, vars.lastPanelPath.Current);
}
if (vars.latestKeyLevel.Current > 0)
{
vars.latestKeyKey = string.Format("{0}{1}", (char)vars.latestKey.Current, vars.latestKeyLevel.Current);
}
}
start
{
return vars.firstInput.Old == 0 && vars.firstInput.Current == 1;
}
onStart
{
vars.prevPanel = vars.lastPanel;
vars.prevMap = vars.currentMap.Current;
vars.lastPanel = null;
vars.solvedPanels.Clear();
vars.visitedMaps.Clear();
vars.visitedMaps.Add(vars.currentMap.Current);
vars.collectedKeys.Clear();
vars.latestKeyKey = null;
}
reset
{
return vars.firstInput.Old == 1 && vars.firstInput.Current == 0;
}
isLoading
{
return vars.loading.Current == 1;
}
split
{
bool should_split = false;
if (vars.lastPanel != vars.prevPanel)
{
if (settings["panels"])
{
should_split = true;
}
if (settings["panels_first"])
{
if (vars.solvedPanels.Contains(vars.lastPanel))
{
should_split = false;
vars.log("Already solved panel: " + vars.lastPanel);
}
else
{
vars.solvedPanels.Add(vars.lastPanel);
}
}
if (should_split)
{
vars.log("Split on panel: " + vars.lastPanel);
}
vars.prevPanel = vars.lastPanel;
}
else if (vars.currentMap.Current != vars.prevMap)
{
if (settings["maps"])
{
should_split = true;
}
if (settings["maps_first"])
{
if (vars.visitedMaps.Contains(vars.currentMap.Current))
{
should_split = false;
vars.log("Already visited map: " + vars.currentMap.Current);
}
else
{
vars.visitedMaps.Add(vars.currentMap.Current);
}
}
if (vars.currentMap.Current == "credits")
{
should_split = false;
}
if (should_split)
{
vars.log("Split on map change: " + vars.currentMap.Current);
}
vars.prevMap = vars.currentMap.Current;
}
else if (vars.latestKeyKey != null && !vars.collectedKeys.Contains(vars.latestKeyKey))
{
if (settings["keys"])
{
should_split = true;
vars.log("Split on collected key: " + vars.latestKeyKey);
}
vars.collectedKeys.Add(vars.latestKeyKey);
}
else if (vars.latestCollectible.Current != vars.latestCollectible.Old)
{
if (vars.latestCollectible.Current.EndsWith("Painting"))
{
if (settings["paintings"])
{
should_split = true;
vars.log("Split on unlocked painting: " + vars.latestCollectible.Current);
}
}
else if (vars.latestCollectible.Current.StartsWith("grave_"))
{
if (settings["graves"])
{
should_split = true;
vars.log("Split on completed gravestone: " + vars.latestCollectible.Current);
}
}
else if (vars.latestCollectible.Current.EndsWith("_mastery"))
{
if (settings["masteries"])
{
should_split = true;
vars.log("Split on collected mastery: " + vars.latestCollectible.Current);
}
}
else if (vars.latestCollectible.Current.EndsWith("_ending"))
{
if (settings["ends"])
{
should_split = true;
vars.log("Split on ending: " + vars.latestCollectible.Current);
}
}
}
return should_split;
}
|