forked from Roman971/OoT-Randomizer
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Models.py
1370 lines (1290 loc) · 62.2 KB
/
Models.py
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
from __future__ import annotations
import os
import random
from enum import IntEnum
from typing import TYPE_CHECKING
from Utils import data_path
if TYPE_CHECKING:
from Cosmetics import CosmeticsLog
from Rom import Rom
from Settings import Settings
def get_model_choices(age: int) -> list[str]:
names = ["Default"]
path = data_path("Models/Adult")
if age == 1:
path = data_path("Models/Child")
if os.path.exists(path):
for file in os.listdir(path):
if file.endswith(".zobj"):
names.append(file[:-5])
if len(names) > 2:
# If more than 2 non-default model choices, add random option
names.insert(1, "Random")
return names
class ModelError(RuntimeError):
pass
class ModelDefinitionError(ModelError):
pass
# Used for writer model pointers to the rom in place of the vanilla pointers
class ModelPointerWriter:
def __init__(self, rom: Rom) -> None:
self.rom: Rom = rom
self.offset: int = 0
self.advance: int = 4
self.base: int = CODE_START
def SetBase(self, base: str) -> None:
if base == 'Code':
self.base = CODE_START
elif base == 'Player':
self.base = PLAYER_START
elif base == 'Hook':
self.base = HOOK_START
elif base == 'Shield':
self.base = SHIELD_START
elif base == 'Stick':
self.base = STICK_START
elif base == 'GraveyardKid':
self.base = GRAVEYARD_KID_START
elif base == 'Guard':
self.base = GUARD_START
elif base == 'RunningMan':
self.base = RUNNING_MAN_START
def GoTo(self, dest: int) -> None:
self.offset = dest
def SetAdvance(self, adv: int) -> None:
self.advance = adv
def GetAddress(self) -> int:
return self.base + self.offset
def WriteModelData(self, data: int) -> None:
self.rom.write_bytes(self.GetAddress(), data.to_bytes(4, 'big'))
self.offset += self.advance
def WriteModelData16(self, data: int) -> None:
self.rom.write_bytes(self.GetAddress(), data.to_bytes(2, 'big'))
self.offset += 2
def WriteModelDataHi(self, data: int) -> None:
bytes = data.to_bytes(4, 'big')
for i in range(2):
self.rom.write_byte(self.GetAddress(), bytes[i])
self.offset += 1
def WriteModelDataLo(self, data: int) -> None:
bytes = data.to_bytes(4, 'big')
for i in range(2, 4):
self.rom.write_byte(self.GetAddress(), bytes[i])
self.offset += 1
# Either return the starting index of the requested data (when start == 0)
# or the offset of the element in the footer, if it exists (start > 0)
def scan(bytes: bytearray, data: bytearray | str, start: int = 0) -> int:
databytes = data
# If a string was passed, encode string as bytes
if isinstance(data, str):
databytes = data.encode()
dataindex = 0
for i in range(start, len(bytes)):
# Byte matches next byte in string
if bytes[i] == databytes[dataindex]:
dataindex += 1
# Special case: Bottle, Bow, Slingshot, Fist.L, and Fist.R are subsets of
# Bottle.Hand.L, Bow.String, Slingshot.String, Gauntlet.Fist.L, and Gauntlet.Fist.R respectively
# And Hookshot which is a subset of Hookshot.Spike, Hookshot.Chain, Hookshot.Aiming.Reticule
# This leads to false positives. So if the next byte is . (0x2E) then reset the count.
if isinstance(data, str) and data in ["Bottle", "Bow", "Slingshot", "Hookshot", "Fist.L", "Fist.R", "Blade.3"] and i < len(bytes) - 1 and bytes[i+1] == 0x2E:
# Blade.3 is even wackier, as it is a subset of Blade.3.Break,
# and also a forward subset of Broken.Blade.3, and has a period in it
if data == "Blade.3":
resetCount = False
# If current byte is the "e" in "Blade.3", the period detected is the expected one- Carry on
# If it isn't, then reset the count
if bytes[i] != 0x65:
resetCount = True
# Make sure i is large enough, "Broken.Blad" is 11 chars (remember we're currently at the e)
if not resetCount and i > 10:
# Check if "Broken." immediately preceeds this string
preceedingBytes = bytes[i-11:i-4]
if preceedingBytes == bytearray(b'Broken.'):
resetCount = True
if resetCount:
dataindex = 0
# Fist.L and Fist.R are forward subsets of Gauntlet.Fist.x, check for "Gauntlet."
# "Gauntlet.Fis" is 12 chars (we are currently at the t)
elif data in ["Fist.L", "Fist.R"] and i > 11:
# Check if "Gauntlet." immediately preceeds this string
preceedingBytes = bytes[i-12:i-3]
if preceedingBytes == bytearray(b'Gauntlet.'):
dataindex = 0
# Default case for Bottle, Bow, Slingshot, Hookshot, reset count
else:
dataindex = 0
# Special case for Hookshot: Forward subset of FPS.Hookshot, "FPS." is 4 chars
# (Blade.3 and fists can check in the previous stanza since a . will be encountered at some point)
if isinstance(data, str) and data == "Hookshot" and dataindex == 1 and i > 3:
# Check if "FPS." immediately preceeds this string
preceedingBytes = bytes[i-4:i]
if preceedingBytes == bytearray(b'FPS.'):
dataindex = 0
# More special cases added by the new pipeline...
# Hand.L and Hand.R are forward subsets of Gauntlet.Hand.X, FPS.Hand.X
# And Hand.L specifically is a forward subset of Bottle.Hand.L
if isinstance(data, str) and data in ["Hand.L", "Hand.R"] and dataindex == 1:
if i > 8:
preceedingBytes = bytes[i-9:i]
if preceedingBytes == bytearray(b'Gauntlet.'):
dataindex = 0
if dataindex == 1 and i > 3:
preceedingBytes = bytes[i-4:i]
if preceedingBytes == bytearray(b'FPS.'):
dataindex = 0
if data == "Hand.L" and dataindex == 1 and i > 6:
preceedingBytes = bytes[i-7:i]
if preceedingBytes == bytearray(b'Bottle.'):
dataindex = 0
# Forearm.L and Forearm.R are forward subsets of FPS.Forearm.X
if isinstance(data, str) and data in ["Forearm.L", "Forearm.R"] and dataindex == 1 and i > 3:
preceedingBytes = bytes[i-4:i]
if preceedingBytes == bytearray(b'FPS.'):
dataindex = 0
# All bytes have been found, so a match
if dataindex == len(databytes):
# If start is 0 then looking for the footer, return the index
if start == 0:
return i + 1
# Else, we want to know the offset, which will be after the footer and 1 padding byte
else:
i += 2
offsetbytes = []
for j in range(4):
offsetbytes.append(bytes[i + j])
return int.from_bytes(offsetbytes, 'big')
# Match has been broken, reset to start of string
else:
dataindex = 0
return -1
# Follows pointers from the LUT until finding the actual DList, and returns the offset of the DList
def unwrap(zobj: bytearray, address: int) -> int:
# An entry in the LUT will look something like 0xDE 01 0000 06014050
# Only the last 3 bytes should be necessary.
data = int.from_bytes(zobj[address+5:address+8], 'big')
# If the data here points to another entry in the LUT, keep searching until
# an address outside the table is found.
while LUT_START <= data <= LUT_END:
address = data
data = int.from_bytes(zobj[address+5:address+8], 'big')
return address
# Used to overwrite pointers in the displaylist with new ones
def WriteDLPointer(dl: list[int], index: int, data: int) -> None:
bytes = data.to_bytes(4, 'big')
for i in range(4):
dl[index + i] = bytes[i]
# An extensive function which loads pieces from the vanilla Link model to add to the user-provided zobj
# Based on https://github.com/hylian-modding/ML64-Z64Lib/blob/master/cores/Z64Lib/API/zzoptimize.ts function optimize()
def LoadVanilla(rom: Rom, missing: list[str], rebase: int, linkstart: int, linksize: int,
pieces: dict[str, tuple[Offsets, int]], skips: dict[str, list[tuple[int, int]]]) -> tuple[list[int], dict[str, int]]:
# Get vanilla "zobj" of Link's model
vanillaData = []
for i in range(linksize):
vanillaData.append(rom.buffer[linkstart + i])
segment = 0x06
vertices = {}
matrices = {}
textures = {}
displayLists = {}
# For each missing piece, grab data from its vanilla display list
for item in missing:
offset = pieces[item][1]
i = offset
displayList = []
# Crawl displaylist bytecode and handle each command
while i < len(vanillaData):
# Check if these bytes need to be skipped
if item in skips.keys():
skip = False
for skippedRanges in skips[item]:
itemIndex = i - offset
# Byte is in a range that must be skipped
if skippedRanges[0] <= itemIndex and itemIndex < skippedRanges[1]:
skip = True
if skip:
i += 8
continue
op = vanillaData[i]
seg = vanillaData[i+4]
lo = int.from_bytes(vanillaData[i+4:i+8], 'big')
# Source for displaylist bytecode: https://hack64.net/wiki/doku.php?id=f3dex2
if op == 0xDF: # End of list
# DF: G_ENDDL
# Terminates the current displaylist
# DF 00 00 00 00 00 00 00
displayList.extend(vanillaData[i:i+8]) # Make sure to write the DF
break
# Shouldn't have to deal with DE (branch to new display list)
elif op == 0x01 and seg == segment: # Vertex data
# 01: G_VTX
# Fills the vertex buffer with vertex information
# 01 0[N N]0 [II] [SS SS SS SS]
# N: Number of vertices
# I: Where to start writing vertices inside the vertex buffer (start = II - N*2)
# S: Segmented address to load vertices from
# Grab the address from the low byte without teh base offset
vtxStart = lo & 0x00FFFFFF
# Grab the length of vertices from the instruction
# (Number of vertices will be from the 4th and 5th nibble as shown above, but each length 16)
vtxLen = int.from_bytes(vanillaData[i+1:i+3], 'big')
if vtxStart not in vertices or len(vertices[vtxStart]) < vtxLen:
vertices[vtxStart] = vanillaData[vtxStart:vtxStart+vtxLen]
elif op == 0xDA and seg == segment: # Push matrix
# DA: G_MTX
# Apply transformation matrix
# DA 38 00 [PP] [AA AA AA AA]
# P: Parameters for matrix
# A: Segmented address of vectors of matrix
# Grab the address from the low byte without the base offset
mtxStart = lo & 0x00FFFFFF
if mtxStart not in matrices:
matrices[mtxStart] = vanillaData[mtxStart:mtxStart+0x40] # Matrices always 0x40 long
elif op == 0xFD and seg == segment: # Texture
# G_SETTIMG
# Sets the texture image offset
# FD [fi] 00 00 [bb bb bb bb]
# [fi] -> fffi i000
# f: Texture format
# i: Texture bitsize
# b: Segmented address of texture
# Use 3rd nibble to get the texture type
textureType = (vanillaData[i+1] >> 3) & 0x1F
# Find the number of texel bits from the type
numTexelBits = 4 * (2 ** (textureType & 0x3))
# Get how many bytes there are per texel
bytesPerTexel = int(numTexelBits / 8)
# Grab the address from the low byte without the base offset
texOffset = lo & 0x00FFFFFF
numTexels = -1
returnStack = []
j = i+8
# The point of this loop is just to find the number of texels
# so that it may be multiplied by the bytesPerTexel so we know
# the length of the texture.
while j < len(vanillaData) and numTexels == -1:
opJ = vanillaData[j]
segJ = vanillaData[j+4]
loJ = int.from_bytes(vanillaData[j+4:j+8], 'big')
if opJ == 0xDF:
# End of branched texture, or something wrong
if len(returnStack) == 0:
numTexels = 0
break
else:
j = returnStack.pop()
elif opJ == 0xFD:
# Another texture command encountered, something wrong
numTexels = 0
break
elif opJ == 0xDE:
# Branch to another texture
if segJ == segment:
if vanillaData[j+1] == 0x0:
returnStack.append(j)
j = loJ & 0x00FFFFFF
elif opJ == 0xF0:
# F0: G_LOADTLUT
# Loads a number of colors for a pallette
# F0 00 00 00 0[t] [cc c]0 00
# t: Tile descriptor to load from
# c: ((colour count-1) & 0x3FF) << 2
# Just grab c from the instruction above
# Shift right 12 to get past the first 3 0s, then
# 2 more since c is shifted left twice, then add 1
# to get the color count of this pallette.
numTexels = ((loJ & 0x00FFF000) >> 14) + 1
break
# Also error if numTexels > 256
elif opJ == 0xF3:
# F3: G_LOADBLOCK
# Determines how much data to load after SETTIMG
# F3 [SS S][T TT] 0[I] [XX X][D DD]
# S: Upper left corner of texture's S-axis
# T: Upper left corner of texture's T-axis
# I: Tile descriptor
# X: Number of texels to load, minus one
# D: dxt (?)
# Just grab X from the instruction, shift
# right 12 times to get past 0s
numTexels = ((loJ & 0x00FFF000) >> 12) + 1
break
j += 8
dataLen = bytesPerTexel * numTexels
if texOffset not in textures or len(textures[texOffset]) < dataLen:
textures[texOffset] = vanillaData[texOffset:texOffset+dataLen]
displayList.extend(vanillaData[i:i+8])
i += 8
displayLists[item] = (displayList, offset)
# Create vanilla zobj of the pieces from data collected during crawl
vanillaZobj = []
# Add textures, vertices, and matrices to the beginning of the zobj
# Textures
oldTex2New = {}
for (offset, texture) in textures.items():
newOffset = len(vanillaZobj)
oldTex2New[offset] = newOffset
vanillaZobj.extend(texture)
# Vertices
oldVer2New = {}
for (offset, vertex) in vertices.items():
newOffset = len(vanillaZobj)
oldVer2New[offset] = newOffset
vanillaZobj.extend(vertex)
# Matrices
oldMtx2New = {}
for (offset, matrix) in matrices.items():
newOffset = len(vanillaZobj)
oldMtx2New[offset] = newOffset
vanillaZobj.extend(matrix)
# Now add display lists which will reference the data from the beginning of the zobj
# Display lists
oldDL2New = {}
for data in displayLists.values():
dl = data[0]
offset = data[1]
oldDL2New[offset] = len(vanillaZobj)
for i in range (0, len(dl), 8):
op = dl[i]
seg = dl[i+4]
lo = int.from_bytes(dl[i+4:i+8], 'big')
if seg == segment:
# If this instruction points to some data, it must be repointed
if op == 0x01:
vertEntry = oldVer2New[lo & 0x00FFFFFF]
WriteDLPointer(dl, i + 4, BASE_OFFSET + vertEntry + rebase)
elif op == 0xDA:
mtxEntry = oldMtx2New[lo & 0x00FFFFFF]
WriteDLPointer(dl, i + 4, BASE_OFFSET + mtxEntry + rebase)
elif op == 0xFD:
texEntry = oldTex2New[lo & 0x00FFFFFF]
WriteDLPointer(dl, i + 4, BASE_OFFSET + texEntry + rebase)
elif op == 0xDE:
dlEntry = oldDL2New[lo & 0x00FFFFFF]
WriteDLPointer(dl, i + 4, BASE_OFFSET + dlEntry + rebase)
vanillaZobj.extend(dl)
# Pad to the nearest multiple of 16
while len(vanillaZobj) % 0x10 != 0:
vanillaZobj.append(0x00)
# Now find the relation of items to new offsets
DLOffsets = {}
for item in missing:
DLOffsets[item] = oldDL2New[pieces[item][1]]
return vanillaZobj, DLOffsets
# Finds the address of the model's hierarchy so we can write the hierarchy pointer
# Based on https://github.com/hylian-modding/Z64Online/blob/master/src/Z64Online/common/cosmetics/UniversalAliasTable.ts function findHierarchy()
def FindHierarchy(zobj: bytearray, agestr: str) -> int:
# Scan until we find a segmented pointer which is 0x0C or 0x10 more than
# the preceeding data and loop until something that's not a segmented pointer is found
# then return the position of the last segemented pointer.
for i in range(0, len(zobj), 4):
if zobj[i] == 0x06:
possible = int.from_bytes(zobj[i+1:i+4], 'big')
if possible < len(zobj):
possible2 = int.from_bytes(zobj[i-3:i], 'big')
diff = possible - possible2
if diff == 0x0C or diff == 0x10:
pos = i + 4
count = 1
while zobj[pos] == 0x06:
pos += 4
count += 1
a = zobj[pos]
if a != count:
continue
return pos - 4
raise ModelDefinitionError("No hierarchy found in " + agestr + " model- Did you check \"Link hierarchy format\" in zzconvert?")
TOLERANCE: int = 0x100
def CheckDiff(limb: int, skeleton: int) -> bool:
# The normal difference
normalDiff = abs(limb - skeleton)
# Underflow/overflow diff
# For example, if limb is 0xFFFF and skeleton is 0x0001, then they are technically only 2 apart
# So subtract 0xFFFF from the absolute value of the difference to get the true difference in this case
# Necessary since values are signed, but not represented as signed here
flowDiff = abs(normalDiff - 0xFFFF)
# Take the minimum of the two differences
diff = min(normalDiff, flowDiff)
# Return true if diff is too big
return diff > TOLERANCE
def CorrectSkeleton(zobj: bytearray, skeleton: list[list[int]], agestr: str) -> bool:
# Get the hierarchy pointer
hierarchy = FindHierarchy(zobj, agestr)
# Get what the hierarchy pointer points to (pointer to limb 0)
limbPointer = int.from_bytes(zobj[hierarchy+1:hierarchy+4], 'big')
# Get the limb this points to
limb = int.from_bytes(zobj[limbPointer+1:limbPointer+4], 'big')
# Go through each limb in the table
hasVanillaSkeleton = True
withinTolerance = True
for i in range(1, 21):
offset = limb + i * 0x10
# X, Y, Z components are 2 bytes each
limbX = int.from_bytes(zobj[offset:offset+2], 'big')
limbY = int.from_bytes(zobj[offset+2:offset+4], 'big')
limbZ = int.from_bytes(zobj[offset+4:offset+6], 'big')
skeletonX = skeleton[i][0]
skeletonY = skeleton[i][1]
skeletonZ = skeleton[i][2]
# Check if the X, Y, and Z components all match
if limbX != skeletonX or limbY != skeletonY or limbZ != skeletonZ:
hasVanillaSkeleton = False
# Now check if the components are within a tolerance
# Exclude limb 0 since that one is always zeroed out on models for some reason
if CheckDiff(limbX, skeletonX) or CheckDiff(limbY, skeletonY) or CheckDiff(limbZ, skeletonZ):
withinTolerance = False
break
# If the skeleton is not vanilla but all components are within the tolerance, then force to vanilla
if not hasVanillaSkeleton and withinTolerance:
hasVanillaSkeleton = True
for i in range(21):
offset = limb + i * 0x10
bytes = []
bytes.extend(int.to_bytes(skeleton[i][0], 2, 'big'))
bytes.extend(int.to_bytes(skeleton[i][1], 2, 'big'))
bytes.extend(int.to_bytes(skeleton[i][2], 2, 'big'))
# Overwrite the X, Y, Z bytes with their vanilla values
for j in range(6):
zobj[offset+j] = bytes[j]
return hasVanillaSkeleton
# Loads model from file and processes it by adding vanilla pieces and setting up the LUT if necessary.
def LoadModel(rom: Rom, model: str, age: int) -> int:
# age 0 = adult, 1 = child
linkstart = ADULT_START
linksize = ADULT_SIZE
hierarchy = ADULT_HIERARCHY
postconstantstart = ADULT_POST_START
pieces = AdultPieces
path = data_path('Models/Adult')
skips = adultSkips
skeleton = adultSkeleton
agestr = "adult" # Just used for error messages
if age == 1:
linkstart = CHILD_START
linksize = CHILD_SIZE
hierarchy = CHILD_HIERARCHY
postconstantstart = CHILD_POST_START
pieces = ChildPieces
path = data_path('Models/Child')
skips = childSkips
skeleton = childSkeleton
agestr = "child"
# Read model data from file
file = open(model, "rb")
zobj = file.read()
file.close()
zobj = bytearray(zobj)
if len(zobj) > linksize:
raise ModelDefinitionError("Model for " + agestr + " too large- It is " + str(len(zobj)) + " bytes, but must be at most " + str(linksize) + " bytes.")
# See if the string MODLOADER64 appears before the LUT- if so this is a PlayAs model and needs no further processing
if scan(zobj, "MODLOADER64") == -1:
# First, make sure all important bytes are zeroed out
for i in range(LUT_START, LUT_END):
zobj[i] = 0x00
# Locate the manifest
footerstart = scan(zobj, "!PlayAsManifest0")
if footerstart == -1:
raise ModelDefinitionError("No manifest found in " + agestr + " model- Did you check \"Embed play-as data\" in zzconvert?")
startaddr = footerstart - len("!PlayAsManifest0")
# Check if this is a new pipeline model
if scan(zobj, "riggedmesh", startaddr) != -1:
# Replace Limb x names with the new pipeline names
for oldName, newName in oldToNewPipeline.items():
pieces[newName] = pieces.pop(oldName)
# Find which pieces, if any, are missing from this model
missing = []
present = {}
DLOffsets = {}
for piece in pieces:
offset = scan(zobj, piece, footerstart)
if offset == -1:
missing.append(piece)
else:
present[piece] = offset
if len(missing) > 0:
# Load vanilla model data for missing pieces
(vanillaZobj, DLOffsets) = LoadVanilla(rom, missing, startaddr, linkstart, linksize, pieces, skips)
# Write vanilla zobj data to end of model zobj
i = 0
for byte in vanillaZobj:
zobj.insert(startaddr + i, byte)
i += 1
if len(zobj) > linksize:
raise ModelDefinitionError("After processing, model for " + agestr + " too large- It is "
+ str(len(zobj)) + " bytes, but must be at most " + str(linksize) + " bytes.")
# Now we have to set the lookup table for each item
for (piece, offset) in DLOffsets.items():
# Add the starting address to each offset so they're accurate to the updated zobj
DLOffsets[piece] = offset + startaddr
DLOffsets.update(present)
for item in pieces:
lut = pieces[item][0] - BASE_OFFSET
entry = unwrap(zobj, lut)
zobj[entry] = 0xDE
zobj[entry+1] = 0x01
entry += 4
dladdress = DLOffsets[item] + BASE_OFFSET
dladdressbytes = dladdress.to_bytes(4, 'big')
for byte in dladdressbytes:
zobj[entry] = byte
entry += 1
# Put prefix for easily finding LUT in RAM
i = 0
for byte in "HEYLOOKHERE".encode():
zobj[LUT_START+i] = byte
i += 1
# Set constants in the LUT
file = open(os.path.join(path, 'Constants/preconstants.zobj'), "rb")
constants = file.read()
file.close()
i = 0
for byte in constants:
zobj[PRE_CONSTANT_START + i] = byte
i += 1
file = open(os.path.join(path, 'Constants/postconstants.zobj'), "rb")
constants = file.read()
file.close()
i = 0
for byte in constants:
zobj[postconstantstart + i] = byte
i += 1
# Set up hierarchy pointer
hierarchyOffset = FindHierarchy(zobj, agestr)
hierarchyBytes = zobj[hierarchyOffset:hierarchyOffset+4] # Get the data the offset points to
for i in range(4):
zobj[hierarchy - BASE_OFFSET + i] = hierarchyBytes[i]
zobj[hierarchy - BASE_OFFSET + 4] = 0x15 # Number of limbs
zobj[hierarchy - BASE_OFFSET + 8] = 0x12 # Number of limbs to draw
# Save zobj for testing
#with open(path + "/Test_Processed.zobj", "wb") as f:
# f.write(zobj)
# Correct skeleton if it should be corrected
CorrectSkeleton(zobj, skeleton, agestr)
# Write zobj to vanilla object (object_link_boy or object_link_child)
rom.write_bytes(linkstart, zobj)
# Finally, want to return an address with a DF instruction for use when writing the model data
dfBytes = bytearray(b'\xDF\x00\x00\x00\x00\x00\x00\x00')
return scan(zobj, dfBytes) - 8
# Write in the adult model and repoint references to it
def patch_model_adult(rom: Rom, settings: Settings, log: CosmeticsLog) -> None:
# Get model filepath
model = settings.model_adult_filepicker
# Default to filepicker if non-empty
if len(model) == 0:
model = settings.model_adult
if settings.model_adult == "Random":
choices = get_model_choices(0)
choices.remove("Default")
choices.remove("Random")
model = random.choice(choices)
model = data_path(f'Models/Adult/{model}.zobj')
pathsplit = os.path.basename(model)
log.settings.model_adult = pathsplit.split('.')[0]
# Load and process model
dfAddress = LoadModel(rom, model, 0)
dfAddress = dfAddress | 0x06000000 # Add segment to DF address
# Write adult Link pointer data
writer = ModelPointerWriter(rom)
writer.GoTo(0xE6718)
writer.SetAdvance(8)
writer.WriteModelData(Offsets.ADULT_LINK_LUT_DL_RFIST)
writer.WriteModelData(Offsets.ADULT_LINK_LUT_DL_RFIST)
writer.WriteModelData(dfAddress)
writer.WriteModelData(dfAddress)
writer.WriteModelData(Offsets.ADULT_LINK_LUT_DL_RFIST_SHIELD_HYLIAN)
writer.WriteModelData(Offsets.ADULT_LINK_LUT_DL_RFIST_SHIELD_HYLIAN)
writer.WriteModelData(Offsets.ADULT_LINK_LUT_DL_RFIST_SHIELD_MIRROR)
writer.WriteModelData(Offsets.ADULT_LINK_LUT_DL_RFIST_SHIELD_MIRROR)
writer.WriteModelData(Offsets.ADULT_LINK_LUT_DL_SWORD_SHEATHED)
writer.WriteModelData(Offsets.ADULT_LINK_LUT_DL_SWORD_SHEATHED)
writer.WriteModelData(dfAddress)
writer.WriteModelData(dfAddress)
writer.WriteModelData(Offsets.ADULT_LINK_LUT_DL_SWORD_SHIELD_HYLIAN)
writer.WriteModelData(Offsets.ADULT_LINK_LUT_DL_SWORD_SHIELD_HYLIAN)
writer.WriteModelData(Offsets.ADULT_LINK_LUT_DL_SWORD_SHIELD_MIRROR)
writer.WriteModelData(Offsets.ADULT_LINK_LUT_DL_SWORD_SHIELD_MIRROR)
writer.WriteModelData(0x00000000)
writer.WriteModelData(0x00000000)
writer.WriteModelData(0x00000000)
writer.WriteModelData(0x00000000)
writer.WriteModelData(Offsets.ADULT_LINK_LUT_DL_SWORD_SHEATH)
writer.WriteModelData(Offsets.ADULT_LINK_LUT_DL_SWORD_SHEATH)
writer.WriteModelData(dfAddress)
writer.WriteModelData(dfAddress)
writer.WriteModelData(Offsets.ADULT_LINK_LUT_DL_SHEATH0_HYLIAN)
writer.WriteModelData(Offsets.ADULT_LINK_LUT_DL_SHEATH0_HYLIAN)
writer.WriteModelData(Offsets.ADULT_LINK_LUT_DL_SHEATH0_MIRROR)
writer.WriteModelData(Offsets.ADULT_LINK_LUT_DL_SHEATH0_MIRROR)
writer.WriteModelData(0x00000000)
writer.WriteModelData(0x00000000)
writer.WriteModelData(0x00000000)
writer.WriteModelData(0x00000000)
writer.WriteModelData(Offsets.ADULT_LINK_LUT_DL_LFIST_LONGSWORD)
writer.WriteModelData(Offsets.ADULT_LINK_LUT_DL_LFIST_LONGSWORD)
writer.WriteModelData(Offsets.ADULT_LINK_LUT_DL_LFIST_LONGSWORD_BROKEN)
writer.WriteModelData(Offsets.ADULT_LINK_LUT_DL_LFIST_LONGSWORD_BROKEN)
writer.WriteModelData(Offsets.ADULT_LINK_LUT_DL_LHAND)
writer.WriteModelData(Offsets.ADULT_LINK_LUT_DL_LHAND)
writer.WriteModelData(Offsets.ADULT_LINK_LUT_DL_LFIST)
writer.WriteModelData(Offsets.ADULT_LINK_LUT_DL_LFIST)
writer.WriteModelData(dfAddress)
writer.WriteModelData(dfAddress)
writer.WriteModelData(Offsets.ADULT_LINK_LUT_DL_LFIST_SWORD)
writer.WriteModelData(Offsets.ADULT_LINK_LUT_DL_LFIST_SWORD)
writer.WriteModelData(Offsets.ADULT_LINK_LUT_DL_RHAND)
writer.WriteModelData(Offsets.ADULT_LINK_LUT_DL_RHAND)
writer.WriteModelData(Offsets.ADULT_LINK_LUT_DL_RFIST)
writer.WriteModelData(Offsets.ADULT_LINK_LUT_DL_RFIST)
writer.WriteModelData(Offsets.ADULT_LINK_LUT_DL_RFIST_BOW)
writer.WriteModelData(Offsets.ADULT_LINK_LUT_DL_RFIST_BOW)
writer.WriteModelData(Offsets.ADULT_LINK_LUT_DL_SWORD_SHEATHED)
writer.WriteModelData(Offsets.ADULT_LINK_LUT_DL_SWORD_SHEATHED)
writer.WriteModelData(Offsets.ADULT_LINK_LUT_DL_SWORD_SHEATH)
writer.WriteModelData(Offsets.ADULT_LINK_LUT_DL_SWORD_SHEATH)
writer.WriteModelData(Offsets.ADULT_LINK_LUT_DL_WAIST)
writer.WriteModelData(Offsets.ADULT_LINK_LUT_DL_WAIST)
writer.WriteModelData(Offsets.ADULT_LINK_LUT_DL_RFIST_BOW)
writer.WriteModelData(Offsets.ADULT_LINK_LUT_DL_RFIST_BOW)
writer.WriteModelData(Offsets.ADULT_LINK_LUT_DL_RHAND_OCARINA_TIME)
writer.WriteModelData(Offsets.ADULT_LINK_LUT_DL_RHAND_OCARINA_TIME)
writer.WriteModelData(Offsets.ADULT_LINK_LUT_DL_RHAND_OCARINA_TIME)
writer.WriteModelData(Offsets.ADULT_LINK_LUT_DL_RHAND_OCARINA_TIME)
writer.WriteModelData(Offsets.ADULT_LINK_LUT_DL_RFIST_HOOKSHOT)
writer.WriteModelData(Offsets.ADULT_LINK_LUT_DL_RFIST_HOOKSHOT)
writer.WriteModelData(Offsets.ADULT_LINK_LUT_DL_LFIST_HAMMER)
writer.WriteModelData(Offsets.ADULT_LINK_LUT_DL_LFIST_HAMMER)
writer.WriteModelData(dfAddress)
writer.WriteModelData(dfAddress)
writer.WriteModelData(Offsets.ADULT_LINK_LUT_DL_LHAND_BOTTLE)
writer.WriteModelData(Offsets.ADULT_LINK_LUT_DL_LHAND_BOTTLE)
writer.WriteModelData(Offsets.ADULT_LINK_LUT_DL_FPS_LFOREARM)
writer.WriteModelData(Offsets.ADULT_LINK_LUT_DL_FPS_LHAND)
writer.WriteModelData(Offsets.ADULT_LINK_LUT_DL_RSHOULDER)
writer.WriteModelData(Offsets.ADULT_LINK_LUT_DL_FPS_RFOREARM)
writer.WriteModelData(Offsets.ADULT_LINK_LUT_DL_FPS_RHAND_BOW)
writer.GoTo(0xE6A4C)
writer.SetAdvance(4)
writer.WriteModelData(Offsets.ADULT_LINK_LUT_DL_BOOT_LIRON)
writer.WriteModelData(Offsets.ADULT_LINK_LUT_DL_BOOT_RIRON)
writer.WriteModelData(Offsets.ADULT_LINK_LUT_DL_BOOT_LHOVER)
writer.WriteModelData(Offsets.ADULT_LINK_LUT_DL_BOOT_RHOVER)
writer.GoTo(0xE6B28)
writer.WriteModelData(Offsets.ADULT_LINK_LUT_DL_BOTTLE)
writer.GoTo(0xE6B64)
writer.SetAdvance(4)
writer.WriteModelData(Offsets.ADULT_LINK_LUT_DL_BOW_STRING)
writer.WriteModelData(0x00000000) # string anchor x: 0.0
writer.WriteModelData(0xC3B43333) # string anchor y: -360.4
writer.GoTo(0x69112)
writer.WriteModelDataHi(Offsets.ADULT_LINK_LUT_DL_UPGRADE_LFOREARM)
writer.GoTo(0x69116)
writer.WriteModelDataLo(Offsets.ADULT_LINK_LUT_DL_UPGRADE_LFOREARM)
writer.GoTo(0x6912E)
writer.WriteModelDataHi(Offsets.ADULT_LINK_LUT_DL_UPGRADE_RFOREARM)
writer.GoTo(0x69132)
writer.WriteModelDataLo(Offsets.ADULT_LINK_LUT_DL_UPGRADE_RFOREARM)
writer.GoTo(0x6914E)
writer.WriteModelDataHi(Offsets.ADULT_LINK_LUT_DL_UPGRADE_LFIST)
writer.GoTo(0x69162)
writer.WriteModelDataLo(Offsets.ADULT_LINK_LUT_DL_UPGRADE_LFIST)
writer.GoTo(0x69166)
writer.WriteModelDataHi(Offsets.ADULT_LINK_LUT_DL_UPGRADE_LHAND)
writer.GoTo(0x69172)
writer.WriteModelDataLo(Offsets.ADULT_LINK_LUT_DL_UPGRADE_LHAND)
writer.GoTo(0x6919E)
writer.WriteModelDataHi(Offsets.ADULT_LINK_LUT_DL_UPGRADE_RFIST)
writer.GoTo(0x691A2)
writer.WriteModelDataLo(Offsets.ADULT_LINK_LUT_DL_UPGRADE_RFIST)
writer.GoTo(0x691AE)
writer.WriteModelDataHi(Offsets.ADULT_LINK_LUT_DL_UPGRADE_RHAND)
writer.GoTo(0x691B2)
writer.WriteModelDataLo(Offsets.ADULT_LINK_LUT_DL_UPGRADE_RHAND)
writer.GoTo(0x69DEA)
writer.WriteModelDataHi(Offsets.ADULT_LINK_LUT_DL_FPS_LHAND_HOOKSHOT)
writer.GoTo(0x69DEE)
writer.WriteModelDataLo(Offsets.ADULT_LINK_LUT_DL_FPS_LHAND_HOOKSHOT)
writer.GoTo(0x6A666)
writer.WriteModelDataHi(Offsets.ADULT_LINK_LUT_DL_HOOKSHOT_AIM)
writer.GoTo(0x6A66A)
writer.WriteModelDataLo(Offsets.ADULT_LINK_LUT_DL_HOOKSHOT_AIM)
writer.SetBase('Hook')
writer.GoTo(0xA72)
writer.WriteModelDataHi(Offsets.ADULT_LINK_LUT_DL_HOOKSHOT_HOOK)
writer.GoTo(0xA76)
writer.WriteModelDataLo(Offsets.ADULT_LINK_LUT_DL_HOOKSHOT_HOOK)
writer.GoTo(0xB66)
writer.WriteModelDataHi(Offsets.ADULT_LINK_LUT_DL_HOOKSHOT_CHAIN)
writer.GoTo(0xB6A)
writer.WriteModelDataLo(Offsets.ADULT_LINK_LUT_DL_HOOKSHOT_CHAIN)
writer.GoTo(0xBA8)
writer.WriteModelData16(0x0014)
writer.SetBase('Stick')
writer.GoTo(0x32C)
writer.WriteModelData(Offsets.ADULT_LINK_LUT_DL_BLADEBREAK)
writer.GoTo(0x328)
writer.WriteModelData16(0x0014)
writer.SetBase('Code')
writer.GoTo(0xE65A0)
writer.WriteModelData(ADULT_HIERARCHY) # Hierarchy pointer
# Write in the child model and repoint references to it
def patch_model_child(rom: Rom, settings: Settings, log: CosmeticsLog) -> None:
# Get model filepath
model = settings.model_child_filepicker
# Default to filepicker if non-empty
if len(model) == 0:
model = settings.model_child
if settings.model_child == "Random":
choices = get_model_choices(1)
choices.remove("Default")
choices.remove("Random")
model = random.choice(choices)
model = data_path(f'Models/Child/{model}.zobj')
pathsplit = os.path.basename(model)
log.settings.model_child = pathsplit.split('.')[0]
# Load and process model
dfAddress = LoadModel(rom, model, 1)
dfAddress = dfAddress | 0x06000000 # Add segment to DF address
# Write child Link pointer data
writer = ModelPointerWriter(rom)
writer.GoTo(0xE671C)
writer.SetAdvance(8)
writer.WriteModelData(Offsets.CHILD_LINK_LUT_DL_RFIST)
writer.WriteModelData(Offsets.CHILD_LINK_LUT_DL_RFIST)
writer.WriteModelData(Offsets.CHILD_LINK_LUT_DL_RFIST_SHIELD_DEKU)
writer.WriteModelData(Offsets.CHILD_LINK_LUT_DL_RFIST_SHIELD_DEKU)
writer.WriteModelData(Offsets.CHILD_LINK_LUT_DL_RFIST)
writer.WriteModelData(Offsets.CHILD_LINK_LUT_DL_RFIST)
writer.WriteModelData(dfAddress)
writer.WriteModelData(dfAddress)
writer.WriteModelData(Offsets.CHILD_LINK_LUT_DL_SWORD_SHEATHED)
writer.WriteModelData(Offsets.CHILD_LINK_LUT_DL_SWORD_SHEATHED)
writer.WriteModelData(Offsets.CHILD_LINK_LUT_DL_SWORD_SHIELD_DEKU)
writer.WriteModelData(Offsets.CHILD_LINK_LUT_DL_SWORD_SHIELD_DEKU)
writer.WriteModelData(Offsets.CHILD_LINK_LUT_DL_SWORD_SHIELD_HYLIAN)
writer.WriteModelData(Offsets.CHILD_LINK_LUT_DL_SWORD_SHIELD_HYLIAN)
writer.WriteModelData(dfAddress)
writer.WriteModelData(dfAddress)
writer.WriteModelData(0x00000000)
writer.WriteModelData(0x00000000)
writer.WriteModelData(Offsets.CHILD_LINK_LUT_DL_SHIELD_DEKU_BACK)
writer.WriteModelData(Offsets.CHILD_LINK_LUT_DL_SHIELD_DEKU_BACK)
writer.WriteModelData(Offsets.CHILD_LINK_LUT_DL_SWORD_SHEATH)
writer.WriteModelData(Offsets.CHILD_LINK_LUT_DL_SWORD_SHEATH)
writer.WriteModelData(Offsets.CHILD_LINK_LUT_DL_SHEATH0_DEKU)
writer.WriteModelData(Offsets.CHILD_LINK_LUT_DL_SHEATH0_DEKU)
writer.WriteModelData(Offsets.CHILD_LINK_LUT_DL_SHEATH0_HYLIAN)
writer.WriteModelData(Offsets.CHILD_LINK_LUT_DL_SHEATH0_HYLIAN)
writer.WriteModelData(dfAddress)
writer.WriteModelData(dfAddress)
writer.WriteModelData(0x00000000)
writer.WriteModelData(0x00000000)
writer.WriteModelData(Offsets.CHILD_LINK_LUT_DL_SHIELD_DEKU_BACK)
writer.WriteModelData(Offsets.CHILD_LINK_LUT_DL_SHIELD_DEKU_BACK)
writer.WriteModelData(Offsets.CHILD_LINK_LUT_DL_LHAND_PEDESTALSWORD)
writer.WriteModelData(Offsets.CHILD_LINK_LUT_DL_LHAND_PEDESTALSWORD)
writer.WriteModelData(Offsets.CHILD_LINK_LUT_DL_LHAND_PEDESTALSWORD)
writer.WriteModelData(Offsets.CHILD_LINK_LUT_DL_LHAND_PEDESTALSWORD)
writer.WriteModelData(Offsets.CHILD_LINK_LUT_DL_LHAND)
writer.WriteModelData(Offsets.CHILD_LINK_LUT_DL_LHAND)
writer.WriteModelData(Offsets.CHILD_LINK_LUT_DL_LFIST)
writer.WriteModelData(Offsets.CHILD_LINK_LUT_DL_LFIST)
writer.WriteModelData(Offsets.CHILD_LINK_LUT_DL_LFIST_SWORD)
writer.WriteModelData(Offsets.CHILD_LINK_LUT_DL_LFIST_SWORD)
writer.WriteModelData(Offsets.CHILD_LINK_LUT_DL_LFIST_SWORD)
writer.WriteModelData(Offsets.CHILD_LINK_LUT_DL_LFIST_SWORD)
writer.WriteModelData(Offsets.CHILD_LINK_LUT_DL_RHAND)
writer.WriteModelData(Offsets.CHILD_LINK_LUT_DL_RHAND)
writer.WriteModelData(Offsets.CHILD_LINK_LUT_DL_RFIST)
writer.WriteModelData(Offsets.CHILD_LINK_LUT_DL_RFIST)
writer.WriteModelData(Offsets.CHILD_LINK_LUT_DL_RFIST_SLINGSHOT)
writer.WriteModelData(Offsets.CHILD_LINK_LUT_DL_RFIST_SLINGSHOT)
writer.WriteModelData(Offsets.CHILD_LINK_LUT_DL_SWORD_SHEATHED)
writer.WriteModelData(Offsets.CHILD_LINK_LUT_DL_SWORD_SHEATHED)
writer.WriteModelData(Offsets.CHILD_LINK_LUT_DL_SWORD_SHEATH)
writer.WriteModelData(Offsets.CHILD_LINK_LUT_DL_SWORD_SHEATH)
writer.WriteModelData(Offsets.CHILD_LINK_LUT_DL_WAIST)
writer.WriteModelData(Offsets.CHILD_LINK_LUT_DL_WAIST)
writer.WriteModelData(Offsets.CHILD_LINK_LUT_DL_RFIST_SLINGSHOT)
writer.WriteModelData(Offsets.CHILD_LINK_LUT_DL_RFIST_SLINGSHOT)
writer.WriteModelData(Offsets.CHILD_LINK_LUT_DL_RHAND_OCARINA_FAIRY)
writer.WriteModelData(Offsets.CHILD_LINK_LUT_DL_RHAND_OCARINA_FAIRY)
writer.WriteModelData(Offsets.CHILD_LINK_LUT_DL_RHAND_OCARINA_TIME)
writer.WriteModelData(Offsets.CHILD_LINK_LUT_DL_RHAND_OCARINA_TIME)
writer.WriteModelData(Offsets.CHILD_LINK_LUT_DL_RFIST)
writer.WriteModelData(Offsets.CHILD_LINK_LUT_DL_RFIST)
writer.WriteModelData(Offsets.CHILD_LINK_LUT_DL_LFIST)
writer.WriteModelData(Offsets.CHILD_LINK_LUT_DL_LFIST)
writer.WriteModelData(Offsets.CHILD_LINK_LUT_DL_LFIST_BOOMERANG)
writer.WriteModelData(Offsets.CHILD_LINK_LUT_DL_LFIST_BOOMERANG)
writer.WriteModelData(Offsets.CHILD_LINK_LUT_DL_LHAND_BOTTLE)
writer.WriteModelData(Offsets.CHILD_LINK_LUT_DL_LHAND_BOTTLE)
writer.WriteModelData(0x00000000)
writer.WriteModelData(0x00000000)
writer.WriteModelData(Offsets.CHILD_LINK_LUT_DL_RSHOULDER)
writer.WriteModelData(0x00000000)
writer.WriteModelData(Offsets.CHILD_LINK_LUT_DL_FPS_RARM_SLINGSHOT)
writer.GoTo(0xE6B2C)
writer.WriteModelData(Offsets.CHILD_LINK_LUT_DL_BOTTLE)
writer.GoTo(0xE6B74)
writer.SetAdvance(4)
writer.WriteModelData(Offsets.CHILD_LINK_LUT_DL_SLINGSHOT_STRING)
writer.WriteModelData(0x44178000) # string anchor x: 606.0
writer.WriteModelData(0x436C0000) # string anchor y: 236.0
writer.GoTo(0x6922E)
writer.WriteModelDataHi(Offsets.CHILD_LINK_LUT_DL_GORON_BRACELET)
writer.GoTo(0x69232)
writer.WriteModelDataLo(Offsets.CHILD_LINK_LUT_DL_GORON_BRACELET)
writer.GoTo(0x6A80E)
writer.WriteModelDataHi(Offsets.CHILD_LINK_LUT_DL_DEKU_STICK)
writer.GoTo(0x6A812)
writer.WriteModelDataLo(Offsets.CHILD_LINK_LUT_DL_DEKU_STICK)
writer.SetBase('Stick')
writer.GoTo(0x334)
writer.WriteModelData(Offsets.CHILD_LINK_LUT_DL_DEKU_STICK)
writer.GoTo(0x330)
writer.WriteModelData16(0x0015)
writer.SetBase('Shield')
writer.GoTo(0x7EE)
writer.WriteModelDataHi(Offsets.CHILD_LINK_LUT_DL_SHIELD_DEKU_ODD)
writer.GoTo(0x7F2)
writer.WriteModelDataLo(Offsets.CHILD_LINK_LUT_DL_SHIELD_DEKU_ODD)
writer.SetBase('Player')
writer.GoTo(0x2253C)
writer.SetAdvance(4)
writer.WriteModelData(Offsets.CHILD_LINK_LUT_DL_MASK_KEATON)
writer.WriteModelData(Offsets.CHILD_LINK_LUT_DL_MASK_SKULL)
writer.WriteModelData(Offsets.CHILD_LINK_LUT_DL_MASK_SPOOKY)
writer.WriteModelData(Offsets.CHILD_LINK_LUT_DL_MASK_BUNNY)
writer.WriteModelData(Offsets.CHILD_LINK_LUT_DL_MASK_GORON)
writer.WriteModelData(Offsets.CHILD_LINK_LUT_DL_MASK_ZORA)
writer.WriteModelData(Offsets.CHILD_LINK_LUT_DL_MASK_GERUDO)
writer.WriteModelData(Offsets.CHILD_LINK_LUT_DL_MASK_TRUTH)
writer.SetBase('GraveyardKid')
writer.GoTo(0xE62)
writer.WriteModelDataHi(Offsets.CHILD_LINK_LUT_DL_MASK_SPOOKY)
writer.GoTo(0xE66)
writer.WriteModelDataLo(Offsets.CHILD_LINK_LUT_DL_MASK_SPOOKY)
writer.SetBase('Guard')
writer.GoTo(0x1EA2)
writer.WriteModelDataHi(Offsets.CHILD_LINK_LUT_DL_MASK_KEATON)
writer.GoTo(0x1EA6)
writer.WriteModelDataLo(Offsets.CHILD_LINK_LUT_DL_MASK_KEATON)
writer.SetBase('RunningMan')
writer.GoTo(0x1142)
writer.WriteModelDataHi(Offsets.CHILD_LINK_LUT_DL_MASK_BUNNY)
writer.GoTo(0x1146)
writer.WriteModelDataLo(Offsets.CHILD_LINK_LUT_DL_MASK_BUNNY)
writer.SetBase('Code')
writer.GoTo(0xE65A4)
writer.WriteModelData(CHILD_HIERARCHY) # Hierarchy pointer
# LUT offsets for adult and child
class Offsets(IntEnum):
ADULT_LINK_LUT_DL_WAIST = 0x06005090
ADULT_LINK_LUT_DL_RTHIGH = 0x06005098
ADULT_LINK_LUT_DL_RSHIN = 0x060050A0
ADULT_LINK_LUT_DL_RFOOT = 0x060050A8
ADULT_LINK_LUT_DL_LTHIGH = 0x060050B0
ADULT_LINK_LUT_DL_LSHIN = 0x060050B8
ADULT_LINK_LUT_DL_LFOOT = 0x060050C0
ADULT_LINK_LUT_DL_HEAD = 0x060050C8
ADULT_LINK_LUT_DL_HAT = 0x060050D0
ADULT_LINK_LUT_DL_COLLAR = 0x060050D8
ADULT_LINK_LUT_DL_LSHOULDER = 0x060050E0
ADULT_LINK_LUT_DL_LFOREARM = 0x060050E8
ADULT_LINK_LUT_DL_RSHOULDER = 0x060050F0
ADULT_LINK_LUT_DL_RFOREARM = 0x060050F8
ADULT_LINK_LUT_DL_TORSO = 0x06005100
ADULT_LINK_LUT_DL_LHAND = 0x06005108
ADULT_LINK_LUT_DL_LFIST = 0x06005110
ADULT_LINK_LUT_DL_LHAND_BOTTLE = 0x06005118
ADULT_LINK_LUT_DL_RHAND = 0x06005120
ADULT_LINK_LUT_DL_RFIST = 0x06005128
ADULT_LINK_LUT_DL_SWORD_SHEATH = 0x06005130
ADULT_LINK_LUT_DL_SWORD_HILT = 0x06005138
ADULT_LINK_LUT_DL_SWORD_BLADE = 0x06005140
ADULT_LINK_LUT_DL_LONGSWORD_HILT = 0x06005148
ADULT_LINK_LUT_DL_LONGSWORD_BLADE = 0x06005150
ADULT_LINK_LUT_DL_LONGSWORD_BROKEN = 0x06005158
ADULT_LINK_LUT_DL_SHIELD_HYLIAN = 0x06005160
ADULT_LINK_LUT_DL_SHIELD_MIRROR = 0x06005168
ADULT_LINK_LUT_DL_HAMMER = 0x06005170
ADULT_LINK_LUT_DL_BOTTLE = 0x06005178
ADULT_LINK_LUT_DL_BOW = 0x06005180
ADULT_LINK_LUT_DL_OCARINA_TIME = 0x06005188
ADULT_LINK_LUT_DL_HOOKSHOT = 0x06005190
ADULT_LINK_LUT_DL_UPGRADE_LFOREARM = 0x06005198
ADULT_LINK_LUT_DL_UPGRADE_LHAND = 0x060051A0
ADULT_LINK_LUT_DL_UPGRADE_LFIST = 0x060051A8
ADULT_LINK_LUT_DL_UPGRADE_RFOREARM = 0x060051B0
ADULT_LINK_LUT_DL_UPGRADE_RHAND = 0x060051B8
ADULT_LINK_LUT_DL_UPGRADE_RFIST = 0x060051C0
ADULT_LINK_LUT_DL_BOOT_LIRON = 0x060051C8
ADULT_LINK_LUT_DL_BOOT_RIRON = 0x060051D0
ADULT_LINK_LUT_DL_BOOT_LHOVER = 0x060051D8
ADULT_LINK_LUT_DL_BOOT_RHOVER = 0x060051E0
ADULT_LINK_LUT_DL_FPS_LFOREARM = 0x060051E8
ADULT_LINK_LUT_DL_FPS_LHAND = 0x060051F0
ADULT_LINK_LUT_DL_FPS_RFOREARM = 0x060051F8
ADULT_LINK_LUT_DL_FPS_RHAND = 0x06005200
ADULT_LINK_LUT_DL_FPS_HOOKSHOT = 0x06005208
ADULT_LINK_LUT_DL_HOOKSHOT_CHAIN = 0x06005210
ADULT_LINK_LUT_DL_HOOKSHOT_HOOK = 0x06005218
ADULT_LINK_LUT_DL_HOOKSHOT_AIM = 0x06005220
ADULT_LINK_LUT_DL_BOW_STRING = 0x06005228
ADULT_LINK_LUT_DL_BLADEBREAK = 0x06005230
ADULT_LINK_LUT_DL_SWORD_SHEATHED = 0x06005238
ADULT_LINK_LUT_DL_SHIELD_HYLIAN_BACK = 0x06005258
ADULT_LINK_LUT_DL_SHIELD_MIRROR_BACK = 0x06005268