-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSpyroAHT_savedata.lua
More file actions
1690 lines (1412 loc) · 56.8 KB
/
Copy pathSpyroAHT_savedata.lua
File metadata and controls
1690 lines (1412 loc) · 56.8 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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
console.clear()
memory.usememorydomain("RAM")
--PACKAGES
package.loaded.geoHashes = nil
local geoHashes = require "SpyroAHT_geofile_hashes"
package.loaded.EXHashcodes = nil
local EXHashcodes = require "SpyroAHT_hashcodes"
package.loaded.ESHashcodes = nil
local ESHashcodes = require "SpyroAHT_soundhashes"
package.loaded.LocalHashes = nil
local LocalHashes = require "SpyroAHT_localhashes"
package.loaded.BH_MiniMapSizes = nil
local BH_MiniMapSizes = require "SpyroAHT_BH_MiniMapSizes"
package.loaded.SpyroPoint = nil
local SpyroPoint = require "SpyroPoint"
--package.loaded.triggerData = nil
--local triggerData = require "triggerData"
--TOGGLES
local doObjectives = true
local doTasks = true
local doMinimaps = true
local doTriggerstates = true
local doRenderPoints = true
--Table that holds save data
local gGameState = 0x463b38
local gGameState_PlayerState = gGameState + 0x2018 -- = 0x465B50
local gGameState_Objectives = gGameState + 0x2150 -- = 0x465C88
local gGameState_Tasks = gGameState + 0x2190 -- = 0x465CC8
local gGameState_Minimaps = gGameState + 0x21AC -- = 0x465CE4 (also base BitHeap address)
local gGameState_Triggerstates = gGameState + 0x27B7 -- = 0x4662EF
local gGameState_MapStates = gGameState + 0x6434 -- = 0x469F6C
local bitHeapSize = 0x4000 -- 0x465CE4 to 0x469F76
local bitHeapSize_Used = 0x10CC -- 0x465CE4 to 0x466DB0
local bitHeapSize_Minimaps = 0x60B -- 0x465CE4 to 0x4662EF
local bitHeapSize_Triggerstates = 0xAC1 -- 0x4662EF to 0x466DB0, BitHeap indexes start 12380
local currMinimapBlock = memory.read_bytes_as_array(gGameState_Minimaps, bitHeapSize_Minimaps)
local lastMinimapBlock = memory.read_bytes_as_array(gGameState_Minimaps, bitHeapSize_Minimaps)
local currTriggerStateBlock = memory.read_bytes_as_array(gGameState_Triggerstates, bitHeapSize_Triggerstates)
local lastTriggerStateBlock = memory.read_bytes_as_array(gGameState_Triggerstates, bitHeapSize_Triggerstates)
local playerState
local playerStateSize = 0x94
local currPlayerStateHash = memory.hash_region(gGameState_PlayerState, playerStateSize)
local lastPlayerStateHash = 0
local MinimapBitsTotal = 0
for k, v in ipairs(BH_MiniMapSizes) do
MinimapBitsTotal = MinimapBitsTotal + v.Size
end
local MinimapHeap = {}
local currMinimapHash = memory.hash_region(gGameState_Minimaps, bitHeapSize)
local lastMinimapHash = 0
local currTriggerStateHash = memory.hash_region(gGameState_Triggerstates, bitHeapSize_Triggerstates)
local currTriggerStateHash = 0
local gpCurrentMap = 0x4CB60C
local gNumMaps = 0x4cb608
local gMapList = 0x46EE54
local currentMap = bit.band(memory.read_u32_be(gpCurrentMap), 0xFFFFFF)
local numberOfMaps = memory.read_u32_be(gNumMaps)-1
local triggerList = 0x0
local lastTriggerList = 0x0
local triggerListSize = 0
local triggers = {}
local triggerRenderDist = 50
local showTriggerData = false
local currInput = {}
local lastInput = {}
local currMouseInput = {}
local lastMouseInput = {}
local objectives = {}
local numOfObjectives = 0x19B --Game allocates space for 0x200
local objectiveTableSize = math.floor(numOfObjectives/0x20)+1
local objectivesCleared = 0
local tasks = {}
local numOfTasks = 0x46 --Game allocates space for 0x50
local taskTableSize = math.floor(numOfTasks/0x10)+1
local tasksFound = 0
local tasksCleared = 0
local taskStates = {
[0] = " ", --Invisible, Not done
[1] = "[ ]", --Visible, Not done
[2] = "[?]", --Invisible, Done (impossible normally)
[3] = "[X]" --Visible, Done
}
local mapList = {}
local mapStates = {}
local mapStatesBlockSize = 0x64
local currObjectiveHash = 0
local lastObjectiveHash = 0
local currTaskHash = 0
local lastTaskHash = 0
local currMapStateHash = {}
local lastMapStateHash = {}
local eggNames = {
[1] = "Concept Art",
[2] = "Model Viewer",
[3] = "Ember",
[4] = "Flame",
[5] = "Sgt. Byrd",
[6] = "Spyro Turret",
[7] = "Sparx",
[8] = "Blink"
}
local textOffset = 0
local textAreaWidth = 350
local screenScale = 1
client.setwindowsize(1)
client.SetClientExtraPadding(textAreaWidth, 0, 0, 0)
gui.use_surface("client")
--TOGGLES WINDOW
forms.destroyall()
local togglesWindow = forms.newform(170, 250, "Toggles")
forms.setlocation(togglesWindow, client.xpos()+client.screenwidth(), client.ypos())
local labelUpdate = forms.label(togglesWindow, "Update:", 2, 5, 150, 14)
local checkObjectives = forms.checkbox(togglesWindow, "Objectives", 2, 25)
forms.setproperty(checkObjectives, "Checked", true)
local checkTasks = forms.checkbox(togglesWindow, "Tasks", 2, 45)
forms.setproperty(checkTasks, "Checked", true)
local checkMinimaps = forms.checkbox(togglesWindow, "Mini-Maps", 2, 65)
forms.setproperty(checkMinimaps, "Checked", true)
local checkTriggerstates = forms.checkbox(togglesWindow, "Trigger-States", 2, 85)
--forms.setproperty(checkTriggerstates, "Checked", true)
local labelShowMiniMap = forms.label(togglesWindow, "Display Minimap in Console:", 2, 110, 150, 14)
local checkShowMiniMap = forms.checkbox(togglesWindow, "Enable", 2, 125)
--forms.setproperty(checkShowMiniMap, "Checked", true)
local labelRenderPoints = forms.label(togglesWindow, "Render Trigger Positions:", 2, 150, 150, 14)
local checkRenderPoints = forms.checkbox(togglesWindow, "Enable", 2, 165)
--forms.setproperty(checkRenderPoints, "Checked", true)
local labelFilterTriggerTypes = forms.label(togglesWindow, "Filter Trigger Types:", 2, 195, 150, 14)
local textboxFilterTriggerTypes = forms.textbox(togglesWindow, nil, 160, 26, "STRING", 0, 215, true, true)
local function hex2float (c)
if c == 0 then return 0.0 end
local sign = bit.band(0x80000000, c) == 0x80000000
if sign then
sign = -1
else
sign = 1
end
local expo = bit.rshift(bit.band(0x7F800000, c), 23)
local mant = bit.band(0x7FFFFF, c)
local n
if mant == 0 and expo == 0 then
n = sign * 0.0
elseif expo == 0xFF then
if mant == 0 then
n = sign * math.huge
else
n = 0.0/0.0
end
else
n = sign * math.ldexp(1.0 + mant / 0x800000, expo - 0x7F)
end
return n
end
function table.shallow_copy(t)
local t2 = {}
for k,v in pairs(t) do
t2[k] = v
end
return t2
end
function string.insert(str1, str2, pos)
return str1:sub(1,pos)..str2..str1:sub(pos+1)
end
function setObjective(o)
local o_bit_index = bit.band(o, 0xFFFFFF)-1
if o_bit_index > 0x200 then
console.clear()
console.log("Invalid objective hash!")
return
end
local o_bit = bit.band(o_bit_index, 0x1f)
local o_index = bit.rshift(o_bit_index, 5)
local c = memory.read_u32_be(gGameState_Objectives + (o_index * 4))
memory.write_u32_be(gGameState_Objectives + (o_index * 4), bit.bor(c, bit.lshift(1, o_bit)))
return "Set objective 0x" .. bizstring.hex(o)
end
function resetObjective(o)
local o_bit_index = bit.band(o, 0xFFFFFF)-1
if o_bit_index > 0x200 then
console.clear()
console.log("Invalid objective hash!")
return
end
local o_bit = bit.band(o_bit_index, 0x1f)
local o_index = bit.rshift(o_bit_index, 5)
local c = memory.read_u32_be(gGameState_Objectives + (o_index * 4))
if not bit.check(c, o_bit) then
console.clear()
console.log("Objective already not set.")
return
end
memory.write_u32_be(gGameState_Objectives + (o_index * 4), bit.bxor(c, bit.lshift(1, o_bit)))
return "Reset objective 0x" .. bizstring.hex(o)
end
function getBitHeapBit(index)
local byteIndex = math.floor((index+1) / 8)
local bitPos = (index+1) % 8
local BH_Byte = memory.read_u8(gGameState_Minimaps + byteIndex)
return bit.band(bit.rshift(BH_Byte, bitPos), 1)
end
function setBitHeapBit(index, val, trIndex)
if trIndex then index=index+trIndex end
local byteIndex = math.floor((index+1) / 8)
local bitPos = (index+1) % 8
local BH_Byte = memory.read_u8(gGameState_Minimaps + byteIndex)
if val == 1 then
memory.write_u8(gGameState_Minimaps + byteIndex,
bit.bor(BH_Byte, bit.lshift(1, bitPos)))
elseif val == 0 then
memory.write_u8(gGameState_Minimaps + byteIndex,
bit.bxor(BH_Byte, bit.lshift(1, bitPos)))
else
return "Given value is not 0 or 1"
end
return "Set bit "..tostring(bitPos).." at index "..tostring(index).." to "..tostring(val)
end
function setStartPoint(hash)
local success = false
for i = 0, numberOfMaps do
if mapList[i].addr == currentMap then
memory.write_u32_be(gGameState_MapStates + (mapList[i].levelID * 0x64), hash)
success = true
end
end
if success then
return "Set startpoint to 0x"..bizstring.hex(hash)
else
return "Could not set start point!"
end
end
function tpToTrigger(i)
local trig = nil
for k, v in pairs(triggers) do
if v.Index == i then
trig = v
break
end
end
if trig then
memory.writefloat(bit.band(memory.read_u32_be(0x4CB360), 0xFFFFFF) + 0xD0, trig.Pos.X, true)
memory.writefloat(bit.band(memory.read_u32_be(0x4CB360), 0xFFFFFF) + 0xD4, trig.Pos.Y, true)
memory.writefloat(bit.band(memory.read_u32_be(0x4CB360), 0xFFFFFF) + 0xD8, trig.Pos.Z, true)
return "Teleported player to trigger "..tostring(i)
else
return "Trigger not found."
end
end
local function secToTimestamp(i)
local s = math.floor(i % 60)
local m = math.floor((i / 60) % 60)
local h = math.floor((i / 60) / 60)
local str = tostring(m)..":"..tostring(s)
if m < 10 then
str = string.insert(str, "0", 0)
end
if s < 10 then
str = string.insert(str, "0", 3)
end
return tostring(h)..":"..str
end
local function isBitSet(byteTable, index)
local byteIndex = math.floor(index / 8) + 1
local bitPos = index % 8
return bit.check(byteTable[byteIndex], bitPos)
end
local function stringPad(s, targetLen)
local sLen = string.len(s)
if sLen >= targetLen then return s end
return s .. string.rep(" ", targetLen - sLen)
end
local function convertByteArrayToIntArray(inputArray, arraySize)
local intArraySize = arraySize/4
local outputArray = {}
for i = 0, intArraySize-1 do
local index = i*4
outputArray[i+1] = inputArray[index+1]*0x1000000 + inputArray[index+2]*0x10000 + inputArray[index+3]*0x100 + inputArray[index+4]
end
return outputArray
end
local function color_RGBAtoARGB(input)
return bit.bor(bit.rshift(input, 8), bit.lshift(input, 24))
end
local function isInRange(Vect3a, Vect3b, range)
return math.sqrt( (Vect3a.X-Vect3b.X)^2 + (Vect3a.Y-Vect3b.Y)^2 + (Vect3a.Z-Vect3b.Z)^2 ) < range
end
local function getDistFromCam(vect3)
return math.sqrt( (vect3.X-SpyroPoint.camPos.X)^2 + (vect3.Y-SpyroPoint.camPos.Y)^2 + (vect3.Z-SpyroPoint.camPos.Z)^2 )
end
local function EXVectorFromBitfield(input, bitOffs)
local vect = {X = 0, Y = 0, Z = 0, W = 0}
local x = 0
local y = 0
local z = 0
local w = 0
if not bitOffs then bitOffs = 0 end
local bitTable
--Caller can either pass a table of bits directly, or an index into the BitHeap.
if type(input) == "number" then
--Treat input as BitHeap index and create table of bits from it
bitTable = {}
for i = 1, 128+bitOffs do
bitTable[i] = getBitHeapBit((input-1)+i)
end
elseif type(input) == "table" then
if table.getn(input) < 128+bitOffs then return end
bitTable = input
else return end
--Start reading floats
for i = bitOffs, bitOffs+32 do
x = bit.bor(bit.lshift(x, 1), bitTable[i])
end
vect.X = hex2float(x)
vect.Xh = x --Return raw hex value just for good measure
bitOffs=bitOffs+32
for i = bitOffs, bitOffs+32 do
y = bit.bor(bit.lshift(y, 1), bitTable[i])
end
vect.Y = hex2float(y)
vect.Yh = y
bitOffs=bitOffs+32
for i = bitOffs, bitOffs+32 do
z = bit.bor(bit.lshift(z, 1), bitTable[i])
end
vect.Z = hex2float(z)
vect.Zh = z
bitOffs=bitOffs+32
for i = bitOffs, bitOffs+32 do
w = bit.bor(bit.lshift(w, 1), bitTable[i])
end
vect.W = hex2float(w)
vect.Wh = w
return vect
end
--INIT
local function initPlayerState()
playerState = {
dateYear = memory.read_u16_be(gGameState_PlayerState),
dateMonth = memory.read_u8( gGameState_PlayerState + 0x2),
dateDay = memory.read_u8( gGameState_PlayerState + 0x3),
dateHour = memory.read_u8( gGameState_PlayerState + 0x4),
dateMinute = memory.read_u8( gGameState_PlayerState + 0x5),
dateSecond = memory.read_u8( gGameState_PlayerState + 0x6),
playTime = memory.readfloat( gGameState_PlayerState + 0x8, true),
breathSelected = memory.read_u32_be(gGameState_PlayerState + 0x10),
health = memory.read_u32_be(gGameState_PlayerState + 0x14),
gemCount = memory.read_u32_be(gGameState_PlayerState + 0x18),
lockPickCount = memory.read_u8( gGameState_PlayerState + 0x20),
lockPickLimit = memory.read_u8( gGameState_PlayerState + 0x21),
ammoFire = {
amount = memory.read_u8( gGameState_PlayerState + 0x24),
carryLimit = memory.read_u8( gGameState_PlayerState + 0x25),
magLimit = memory.read_u8( gGameState_PlayerState + 0x26),
magAmount = memory.read_u8( gGameState_PlayerState + 0x27)
},
ammoIce = {
amount = memory.read_u8( gGameState_PlayerState + 0x28),
carryLimit = memory.read_u8( gGameState_PlayerState + 0x29),
magLimit = memory.read_u8( gGameState_PlayerState + 0x2A),
magAmount = memory.read_u8( gGameState_PlayerState + 0x2B)
},
ammoWater = {
amount = memory.read_u8( gGameState_PlayerState + 0x2C),
carryLimit = memory.read_u8( gGameState_PlayerState + 0x2D),
magLimit = memory.read_u8( gGameState_PlayerState + 0x2E),
magAmount = memory.read_u8( gGameState_PlayerState + 0x2F)
},
ammoElectric = {
amount = memory.read_u8( gGameState_PlayerState + 0x30),
carryLimit = memory.read_u8( gGameState_PlayerState + 0x31),
magLimit = memory.read_u8( gGameState_PlayerState + 0x32),
magAmount = memory.read_u8( gGameState_PlayerState + 0x33)
},
fireArrows = memory.read_u16_be(gGameState_PlayerState + 0x34),
fireArrowsLimit = memory.read_u16_be(gGameState_PlayerState + 0x36),
playerFlags = memory.read_u32_be(gGameState_PlayerState + 0x38),
blinkCooldown = memory.readfloat( gGameState_PlayerState + 0x3C, true),
superchargeCooldown = memory.readfloat( gGameState_PlayerState + 0x40, true),
invincibilityCooldown = memory.readfloat( gGameState_PlayerState + 0x48, true),
cooldownLimit = memory.readfloat( gGameState_PlayerState + 0x4C, true),
sgtByrdBoost = memory.readfloat( gGameState_PlayerState + 0x58, true),
sgtByrdBombs = memory.read_u16_be(gGameState_PlayerState + 0x5C),
sgtByrdMissiles = memory.read_u16_be(gGameState_PlayerState + 0x5E),
lightGemAmount = memory.read_u8( gGameState_PlayerState + 0x66),
darkGemAmount = memory.read_u8( gGameState_PlayerState + 0x67),
dragonEggAmount = memory.read_u8( gGameState_PlayerState + 0x68),
playerSpawnX = memory.readfloat( gGameState_PlayerState + 0x70, true),
playerSpawnY = memory.readfloat( gGameState_PlayerState + 0x74, true),
playerSpawnZ = memory.readfloat( gGameState_PlayerState + 0x78, true),
playerSpawnPitch = memory.readfloat( gGameState_PlayerState + 0x80, true),
playerSpawnYaw = memory.readfloat( gGameState_PlayerState + 0x84, true),
playerSpawnRoll = memory.readfloat( gGameState_PlayerState + 0x88, true),
characterUI = memory.read_u32_be(gGameState_PlayerState + 0x90)
}
end
local function initMapGlobals()
for i = 0, numberOfMaps do
local cur = bit.band(memory.read_u32_be(gMapList + (i * 0x4)), 0xFFFFFF)
mapList[i] = {}
mapList[i].addr = cur
mapList[i].realm_nr = memory.read_u32_be(cur + 0x8C)
mapList[i].level_nr = memory.read_u32_be(cur + 0x90)
mapList[i].sbHash = ESHashcodes[memory.read_u32_be(cur + 0xB0)]
mapList[i].levelID = memory.read_u32_be(cur + 0xC8)
mapList[i].geoHash = memory.read_u32_be(cur + 0xDC)
mapList[i].triggerListSize = memory.read_u32_be(cur + 0x108)
mapList[i].triggerListPnt = memory.read_u32_be(cur + 0x10C)
mapList[i].filename = geoHashes[mapList[i].geoHash]
mapList[i].filehash = EXHashcodes[mapList[i].geoHash]
end
end
local function initMapStates()
for i = 0, 200 do
local cur = gGameState_MapStates + (i * mapStatesBlockSize)
local block = convertByteArrayToIntArray(memory.read_bytes_as_array(cur, mapStatesBlockSize), mapStatesBlockSize)
currMapStateHash[i] = memory.hash_region(cur, mapStatesBlockSize)
lastMapStateHash[i] = currMapStateHash[i]
mapStates[i] = {}
mapStates[i].startpoint = block[1]
if (block[3] ~= 0xFFFFFFFF) and (block[4] ~= 0xFFFFFFFF) and (block[5] ~= 0xFFFFFFFF) then
mapStates[i].totalDG = block[3]
mapStates[i].totalDE = block[4]
mapStates[i].totalLG = block[5]
else
mapStates[i].totalDG = 0
mapStates[i].totalDE = 0
mapStates[i].totalLG = 0
end
mapStates[i].tallyDG = block[13]
mapStates[i].tallyLG = block[14]
mapStates[i].tallyDE = {}
mapStates[i].tallyDE[1] = block[15]
mapStates[i].tallyDE[2] = block[16]
mapStates[i].tallyDE[3] = block[17]
mapStates[i].tallyDE[4] = block[18]
mapStates[i].tallyDE[5] = block[19]
mapStates[i].tallyDE[6] = block[20]
mapStates[i].tallyDE[7] = block[21]
mapStates[i].tallyDE[8] = block[22]
mapStates[i].tallyDE.all = 0
for j = 1, 8 do
mapStates[i].tallyDE.all = mapStates[i].tallyDE.all + mapStates[i].tallyDE[j]
end
end
end
local function initObjectives()
for i = 1, numOfObjectives do
objectives[i] = {}
objectives[i].Name = ""
objectives[i].State = false
objectives[i].Index = 0x0
objectives[i].Bit = 0
end
end
local function initTasks()
for i = 1, numOfTasks do
tasks[i] = {}
tasks[i].Name = ""
tasks[i].State = 0
tasks[i].Index = 0x0
tasks[i].Bit = 0
end
end
local function initMiniMaps()
local index = 0
for k, v in ipairs(BH_MiniMapSizes) do
MinimapHeap[k] = {}
for i = 0, v.Size do
local y = math.floor(i / v.X) + 1
if not MinimapHeap[k][y] then
MinimapHeap[k][y] = {}
end
local x = (i % v.X) + 1
if isBitSet(currMinimapBlock, i+index) then
MinimapHeap[k][y][x] = true
else
MinimapHeap[k][y][x] = false
end
end
index = index + v.Size
end
end
--PRINT
local function printTriggerBitHeapGaps()
local preservedTriggers = {}
for i, trig in pairs(triggers) do
if trig.BitHeapIndex then
table.insert(preservedTriggers, trig)
end
end
table.sort(preservedTriggers, function(a, b) return a.BitHeapIndex < b.BitHeapIndex end)
local str = ""
for i = 1, table.getn(preservedTriggers) do
if preservedTriggers[i+1] then
str=str.."["..tostring(preservedTriggers[i].Index).."] "
..stringPad("("..tostring(preservedTriggers[i].BitHeapIndex)..")", 8)
..preservedTriggers[i].Type.." - "
..tostring(preservedTriggers[i+1].BitHeapIndex-preservedTriggers[i].BitHeapIndex).." Bits\n"
else
str=str.."["..tostring(preservedTriggers[i].Index).."] "
..stringPad("("..tostring(preservedTriggers[i].BitHeapIndex)..")", 8)
..preservedTriggers[i].Type.." - Last"
break
end
end
console.clear()
console.log(str)
end
local function printPlayerStateToConsole()
local padLen = 24
local str = ""
str=str..stringPad("Date:", padLen)..tostring(playerState.dateDay)
.."/"..tostring(playerState.dateMonth)
.."/"..tostring(playerState.dateYear)
..", "..tostring(playerState.dateHour)
..":"..tostring(playerState.dateMinute)
..":"..tostring(playerState.dateSecond).."\n"
str=str..stringPad("Played:", padLen)
..secToTimestamp(playerState.playTime).."\n\n"
local breaths = {
[1] = "Fire",
[2] = "Water",
[4] = "Ice",
[8] = "Electricity"
}
if breaths[playerState.breathSelected] then
str=str..stringPad("Breath Selected:", padLen)..breaths[playerState.breathSelected].."\n"
else
str=str..stringPad("Breath Selected:", padLen).."None"
end
str=str..stringPad("Health:", padLen)..tostring(playerState.health).."\n"
str=str..stringPad("Gems:", padLen)..tostring(playerState.gemCount).."\n"
str=str..stringPad("Lockpicks:", padLen)..tostring(playerState.lockPickCount)
.."/"..tostring(playerState.lockPickLimit).."\n\n"
str=str.."Ammo:\n"
str=str..stringPad(" Fire:", padLen)
..stringPad("Amt: "..tostring(playerState.ammoFire.amount)
.."/" ..tostring(playerState.ammoFire.carryLimit), 10).." | "
.."Mag: " ..tostring(playerState.ammoFire.magAmount)
.."/" ..tostring(playerState.ammoFire.magLimit).."\n"
str=str..stringPad(" Ice:", padLen)
..stringPad("Amt: "..tostring(playerState.ammoIce.amount)
.."/" ..tostring(playerState.ammoIce.carryLimit), 10).." | "
.."Mag: " ..tostring(playerState.ammoIce.magAmount)
.."/" ..tostring(playerState.ammoIce.magLimit).."\n"
str=str..stringPad(" Water:", padLen)
..stringPad("Amt: "..tostring(playerState.ammoWater.amount)
.."/" ..tostring(playerState.ammoWater.carryLimit), 10).." | "
.."Mag: " ..tostring(playerState.ammoWater.magAmount)
.."/" ..tostring(playerState.ammoWater.magLimit).."\n"
str=str..stringPad(" Electric:", padLen)
..stringPad("Amt: "..tostring(playerState.ammoElectric.amount)
.."/" ..tostring(playerState.ammoElectric.carryLimit), 10).." | "
.."Mag: " ..tostring(playerState.ammoElectric.magAmount)
.."/" ..tostring(playerState.ammoElectric.magLimit).."\n\n"
str=str..stringPad("Fire Arrows:", padLen)
..tostring(playerState.fireArrows)
.."/"..tostring(playerState.fireArrowsLimit).."\n"
str=str..stringPad("Player Flags:", padLen)
..bizstring.binary(playerState.playerFlags).."\n"
str=str..stringPad("Blink Laser Cooldown:", padLen)
..tostring(playerState.blinkCooldown/60).." seconds\n"
str=str..stringPad("Supercharge Cooldown:", padLen)
..tostring(playerState.superchargeCooldown/60).." seconds\n"
str=str..stringPad("Invincibility Cooldown:", padLen)
..tostring(playerState.invincibilityCooldown/60).." seconds\n"
str=str..stringPad("Cooldown Limit:", padLen)
..tostring(playerState.cooldownLimit/60).." seconds\n\n"
str=str..stringPad("Sgt. Byrd Boost:", padLen)
..tostring(playerState.sgtByrdBoost).."\n"
str=str..stringPad("Sgt. Byrd Bombs:", padLen)
..tostring(playerState.sgtByrdBombs).."\n"
str=str..stringPad("Sgt. Byrd Missiles:", padLen)
..tostring(playerState.sgtByrdMissiles).."\n\n"
str=str..stringPad("Light Gems:", padLen)
..tostring(playerState.lightGemAmount).."\n"
str=str..stringPad("Dark Gems:", padLen)
..tostring(playerState.darkGemAmount).."\n"
str=str..stringPad("Dragon Eggs:", padLen)
..tostring(playerState.dragonEggAmount).."\n\n"
str=str.."Spawn Position:\n"
str=str..stringPad(" X:", padLen)..tostring(playerState.playerSpawnX).."\n"
str=str..stringPad(" Y:", padLen)..tostring(playerState.playerSpawnY).."\n"
str=str..stringPad(" Z:", padLen)..tostring(playerState.playerSpawnZ).."\n"
str=str..stringPad(" Pitch:", padLen)..tostring(playerState.playerSpawnPitch).."\n"
str=str..stringPad(" Yaw:", padLen)..tostring(playerState.playerSpawnYaw).."\n"
str=str..stringPad(" Roll:", padLen)..tostring(playerState.playerSpawnRoll).."\n\n"
local characters = {
[0] = "None",
[1] = "Spyro",
[2] = "Hunter",
[3] = "Sparx",
[4] = "Blink",
[5] = "Sgt. Byrd",
[6] = "Ball Gadget"
}
str=str..stringPad("Character UI:", padLen)..characters[playerState.characterUI]
console.clear()
console.log(str)
end
local function printMapsToConsole()
local str = ""
str = str .. string.format("Number of Maps: %d\n\n", numberOfMaps)
for i = 0, numberOfMaps do
str = str..string.format("Map ID %d:\n", mapList[i].levelID)
str = str..string.format(" Hash: 0x0%x (%s)\n", mapList[i].geoHash, mapList[i].filename)
if mapList[i].sbHash then
str = str.." SoundBank: " .. mapList[i].sbHash.."\n"
else
str = str.." SoundBank: None\n"
end
str = str..string.format(" Base Address: 0x%x\n", mapList[i].addr)
str = str..string.format(" Realm: %d\n", mapList[i].realm_nr)
str = str..string.format(" Level: %d\n", mapList[i].level_nr)
if mapStates[i].startpoint ~= 0xFFFFFFFF then
str = str..string.format(" Startpoint Hash: %x\n", mapStates[mapList[i].levelID].startpoint)
end
str = str..string.format(" Dark Gems : %d/%d\n", mapStates[mapList[i].levelID].tallyDG,mapStates[mapList[i].levelID].totalDG)
str = str..string.format(" Dragon Eggs: %d/%d\n", mapStates[mapList[i].levelID].tallyDE.all,mapStates[mapList[i].levelID].totalDE)
str = str..string.format(" Light Gems : %d/%d\n", mapStates[mapList[i].levelID].tallyLG,mapStates[mapList[i].levelID].totalLG)
end
console.clear()
console.log(str)
end
local function printObjectivesToConsole()
local divider = "------------------------------------------"
local str = "Hash | Index / Bit | State | Name\n" .. divider .. "\n"
local amount = 0
for h, o in ipairs(objectives) do
local sta = ""
if o.State then sta=sta.." X " else sta=sta.." " end
str = str ..
"0x"..bizstring.hex(bit.bor(h, 0x44000000)) ..
" | " ..
stringPad(string.format("i: 0x%x / b: %d", o.Index, o.Bit), 14) ..
" | " ..
sta ..
" | " ..
o.Name:gsub("HT_Objective_", "") ..
"\n"
if o.State then amount = amount + 1 end
end
str = str..divider.."\nObjectives Cleared: "..tostring(amount)
console.clear()
console.log(str)
end
local function printTasksToConsole()
local divider = "----------------------------------------------"
local str = "Hash | Index / Bit | State | Name\n" .. divider .. "\n"
local found = 0
local cleared = 0
for h, t in ipairs(tasks) do
str = str ..
string.format("0x%x", bit.bor(h, 0x45000000)) ..
" | " ..
stringPad(string.format("i: 0x%x / b: %d", t.Index, t.Bit), 14) ..
" | " ..
" "..taskStates[t.State].." " ..
" | " ..
t.Name:gsub("HT_Tasks_", "") ..
"\n"
if t.State == 1 or t.State == 3 then found=found+1 end
if t.State == 3 then cleared=cleared+1 end
end
str = str..divider.."\nTasks Cleared/Found: "..tostring(cleared).."/"..tostring(found)
console.clear()
console.log(str)
end
local function getPrintMiniMap(map)
local mapName = BH_MiniMapSizes[map].Name
local mapX = BH_MiniMapSizes[map].X
local mapY = BH_MiniMapSizes[map].Y
local str = " "..mapName..string.rep("-", mapX*2-string.len(mapName)).."\n"
for y = mapY, 1, -1 do
str=str.."|"
for x = 1, mapX do
if MinimapHeap[map][y][x] then
str=str.."XX"
else
str=str.." "
end
end
str=str.."|\n"
end
str=str.." "..string.rep("-", mapX*2).."\n"
return str
end
local function printAllMiniMapsToConsole()
str = ""
for k, v in ipairs(BH_MiniMapSizes) do
str=str..getPrintMiniMap(k)
end
console.clear()
console.log(str)
end
--UPDATE
local function getGameCompletion()
local defeatedMechaRed
if objectives[0x84].State then
defeatedMechaRed = 1
else
defeatedMechaRed = 0
end
local sum = playerState.lightGemAmount +
playerState.darkGemAmount +
playerState.dragonEggAmount +
defeatedMechaRed
return (sum / 221) * 100
end
local function updatePlayerState()
playerState.dateYear = memory.read_u16_be(gGameState_PlayerState)
playerState.dateMonth = memory.read_u8( gGameState_PlayerState + 0x2)
playerState.dateDay = memory.read_u8( gGameState_PlayerState + 0x3)
playerState.dateHour = memory.read_u8( gGameState_PlayerState + 0x4)
playerState.dateMinute = memory.read_u8( gGameState_PlayerState + 0x5)
playerState.dateSecond = memory.read_u8( gGameState_PlayerState + 0x6)
playerState.playTime = memory.readfloat( gGameState_PlayerState + 0x8, true)
playerState.breathSelected = memory.read_u32_be(gGameState_PlayerState + 0x10)
playerState.health = memory.read_u32_be(gGameState_PlayerState + 0x14)
playerState.gemCount = memory.read_u32_be(gGameState_PlayerState + 0x18)
playerState.lockPickCount = memory.read_u8( gGameState_PlayerState + 0x20)
playerState.lockPickLimit = memory.read_u8( gGameState_PlayerState + 0x21)
playerState.ammoFire.amount = memory.read_u8( gGameState_PlayerState + 0x24)
playerState.ammoFire.carryLimit = memory.read_u8( gGameState_PlayerState + 0x25)
playerState.ammoFire.magLimit = memory.read_u8( gGameState_PlayerState + 0x26)
playerState.ammoFire.magAmount = memory.read_u8( gGameState_PlayerState + 0x27)
playerState.ammoIce.amount = memory.read_u8( gGameState_PlayerState + 0x28)
playerState.ammoIce.carryLimit = memory.read_u8( gGameState_PlayerState + 0x29)
playerState.ammoIce.magLimit = memory.read_u8( gGameState_PlayerState + 0x2A)
playerState.ammoIce.magAmount = memory.read_u8( gGameState_PlayerState + 0x2B)
playerState.ammoWater.amount = memory.read_u8( gGameState_PlayerState + 0x2C)
playerState.ammoWater.carryLimit = memory.read_u8( gGameState_PlayerState + 0x2D)
playerState.ammoWater.magLimit = memory.read_u8( gGameState_PlayerState + 0x2E)
playerState.ammoWater.magAmount = memory.read_u8( gGameState_PlayerState + 0x2F)
playerState.ammoElectric.amount = memory.read_u8( gGameState_PlayerState + 0x30)
playerState.ammoElectric.carryLimit = memory.read_u8( gGameState_PlayerState + 0x31)
playerState.ammoElectric.magLimit = memory.read_u8( gGameState_PlayerState + 0x32)
playerState.ammoElectric.magAmount = memory.read_u8( gGameState_PlayerState + 0x33)
playerState.fireArrows = memory.read_u16_be(gGameState_PlayerState + 0x34)
playerState.fireArrowsLimit = memory.read_u16_be(gGameState_PlayerState + 0x36)
playerState.playerFlags = memory.read_u32_be(gGameState_PlayerState + 0x38)
playerState.blinkCooldown = memory.readfloat( gGameState_PlayerState + 0x3C, true)
playerState.superchargeCooldown = memory.readfloat( gGameState_PlayerState + 0x40, true)
playerState.invincibilityCooldown = memory.readfloat( gGameState_PlayerState + 0x48, true)
playerState.cooldownLimit = memory.readfloat( gGameState_PlayerState + 0x4C, true)
playerState.sgtByrdBoost = memory.readfloat( gGameState_PlayerState + 0x58, true)
playerState.sgtByrdBombs = memory.read_u16_be(gGameState_PlayerState + 0x5C)
playerState.sgtByrdMissiles = memory.read_u16_be(gGameState_PlayerState + 0x5E)
playerState.lightGemAmount = memory.read_u8( gGameState_PlayerState + 0x66)
playerState.darkGemAmount = memory.read_u8( gGameState_PlayerState + 0x67)
playerState.dragonEggAmount = memory.read_u8( gGameState_PlayerState + 0x68)
playerState.playerSpawnX = memory.readfloat( gGameState_PlayerState + 0x70, true)
playerState.playerSpawnY = memory.readfloat( gGameState_PlayerState + 0x74, true)
playerState.playerSpawnZ = memory.readfloat( gGameState_PlayerState + 0x78, true)
playerState.playerSpawnPitch = memory.readfloat( gGameState_PlayerState + 0x80, true)
playerState.playerSpawnYaw = memory.readfloat( gGameState_PlayerState + 0x84, true)
playerState.playerSpawnRoll = memory.readfloat( gGameState_PlayerState + 0x88, true)
playerState.characterUI = memory.read_u32_be(gGameState_PlayerState + 0x90)
end
local function updateObjectives()
local block = convertByteArrayToIntArray(memory.read_bytes_as_array(gGameState_Objectives, objectiveTableSize * 4), objectiveTableSize * 4)
local msgSent = 0
local maxMsg = 10
objectivesCleared = 0
for i = 1, numOfObjectives do
local o_bit_index = i-1 --Index starts at 0
local o_bit = bit.band(o_bit_index, 0x1f)
local o_index = bit.rshift(o_bit_index, 5)
local hash = bit.bor(0x44000000, i)
local hashStr = ""
if EXHashcodes[hash] then
hashStr = EXHashcodes[hash]
else
hashStr = "UNK_" .. tostring(i)
end
local objectiveState = bit.check(block[o_index+1], o_bit) --Outputs True if objective is set, False if not.
if msgSent < maxMsg then
if (objectives[i].State == false) and objectiveState then
local msg = string.format("OB| Objective cleared: %s (0x%x)", hashStr, hash)
gui.addmessage(msg)
console.log(msg)
msgSent = msgSent + 1
end
if msgSent == maxMsg then
msg = "OB| Message cap reached!"
gui.addmessage(msg)
console.log(msg)
end
end
objectives[i].Name = hashStr
objectives[i].State = objectiveState
objectives[i].Index = o_index
objectives[i].Bit = o_bit
if objectiveState then objectivesCleared = objectivesCleared + 1 end
end
end
local function updateTasks()
local block = convertByteArrayToIntArray(memory.read_bytes_as_array(gGameState_Tasks, taskTableSize * 4), taskTableSize * 4)
local msgSent = 0
local maxMsg = 10
tasksFound = 0
tasksCleared = 0
for i = 1, numOfTasks do
local t_bit_index = (i-1) * 2
local t_bit = bit.band(t_bit_index, 0x1f)
local t_index = bit.rshift(t_bit_index, 5)
local hash = bit.bor(0x45000000, i)
local hashStr = ""
if EXHashcodes[hash] ~= nil then
hashStr = EXHashcodes[hash]
else
hashStr = "UNK_" .. tostring(i)
end
local taskState = bit.rshift(bit.band(block[t_index+1], bit.lshift(3, t_bit)), t_bit)
if msgSent < maxMsg then
if (tasks[i].State == 0) and taskState == 1 then
local msg = string.format("TA| New task: %s (0x%x)", hashStr, hash)
gui.addmessage(msg)
console.log(msg)
msgSent = msgSent + 1
elseif (tasks[i].State == 1) and taskState == 3 then
local msg = string.format("TA| Task completed: %s (0x%x)", hashStr, hash)
gui.addmessage(msg)
console.log(msg)
msgSent = msgSent + 1
elseif (tasks[i].State == 0) and taskState == 3 then
local msg = string.format("TA| Task found+completed: %s (0x%x)", hashStr, hash)
gui.addmessage(msg)
console.log(msg)
msgSent = msgSent + 1
end
if msgSent == maxMsg then
local msg = "TA| Message cap reached!"
gui.addmessage(msg)
console.log(msg)