-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathmage_dat.ksy
778 lines (743 loc) · 18.2 KB
/
mage_dat.ksy
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
meta:
id: mage_dat
endian: le
seq:
- id: identifier
contents: MAGEGAME
- id: engine_version
type: u4
valid: 12
doc: If your engine versions mismatch with the ksy version, you are going to have a bad time. This validity check will stop parsing _really early_ if they do not match up.
- id: dat_file_content_crc32
type: u4
- id: dat_file_length
type: u4
- id: map_offsets
type: count_with_offsets
- id: tileset_offsets
type: count_with_offsets
- id: animation_offsets
type: count_with_offsets
- id: entity_type_offsets
type: count_with_offsets
- id: entity_offsets
type: count_with_offsets
- id: geometry_offsets
type: count_with_offsets
- id: script_offsets
type: count_with_offsets
- id: portrait_offsets
type: count_with_offsets
- id: dialog_offsets
type: count_with_offsets
- id: serial_dialog_offsets
type: count_with_offsets
- id: image_color_palette_offsets
type: count_with_offsets
- id: string_offsets
type: count_with_offsets
- id: save_flags_offsets
type: count_with_offsets
- id: variables_offsets
type: count_with_offsets
- id: image_offsets
type: count_with_offsets
- id: maps
type: map
repeat: expr
repeat-expr: map_offsets.count
- id: tilesets
type: tileset
repeat: expr
repeat-expr: tileset_offsets.count
- id: animations
type: animation
repeat: expr
repeat-expr: animation_offsets.count
- id: entity_types
type: entity_type
repeat: expr
repeat-expr: entity_type_offsets.count
- id: entites
type: entity
repeat: expr
repeat-expr: entity_offsets.count
- id: geometry
type: geometry
repeat: expr
repeat-expr: geometry_offsets.count
- id: scripts
type: script
repeat: expr
repeat-expr: script_offsets.count
- id: portraits
type: portrait
repeat: expr
repeat-expr: portrait_offsets.count
- id: dialogs
type: dialog
repeat: expr
repeat-expr: dialog_offsets.count
- id: serial_dialogs
type: serial_dialog
repeat: expr
repeat-expr: serial_dialog_offsets.count
- id: image_color_palettes
type: image_color_palette
repeat: expr
repeat-expr: image_color_palette_offsets.count
instances:
strings:
type: string(_index)
repeat: expr
repeat-expr: string_offsets.count
save_flags:
type: string(_index)
repeat: expr
repeat-expr: save_flags_offsets.count
variables:
type: string(_index)
repeat: expr
repeat-expr: variables_offsets.count
images:
type: image(_index)
repeat: expr
repeat-expr: image_offsets.count
types:
count_with_offsets:
seq:
- id: count
type: u4
doc: The number of items of type the file
- id: offsets
type: u4
repeat: expr
repeat-expr: count
doc: The offsets of items in bytes from the start of the file
- id: lengths
type: u4
repeat: expr
repeat-expr: count
doc: The lengths of items in bytes from the start of the offset
map:
seq:
- id: name
type: str
size: 16
encoding: ASCII
- id: tile_width
type: u2
doc: The width of the map tiles in pixels
- id: tile_height
type: u2
doc: The height of the map tiles in pixels
- id: cols
type: u2
doc: The width of the map, in tiles
- id: rows
type: u2
doc: The height of the map, in tiles
- id: on_load
type: u2
doc: local index to the map's script list
- id: on_tick
type: u2
doc: local index to the map's script list
- id: on_look
type: u2
doc: local index to the map's script list
- id: layer_count
type: u1
doc: The number of layers in this map's tile data
- id: player_entity_id
type: u1
doc: local index to the map's entity list
- id: entity_count
type: u2
doc: The number of entities placed on this map
- id: geometry_count
type: u2
doc: The number of geometry placed on this map
- id: script_count
type: u2
doc: The number of scripts used on this map
- id: go_direction_count
type: u1
doc: the number of items in the directions array
- id: count_padding
type: u1
doc: padding to get back to u2 alignment
- id: entity_global_ids
type: u2
repeat: expr
repeat-expr: entity_count
doc: The global IDs of the entities on this map
- id: geometry_global_ids
type: u2
repeat: expr
repeat-expr: geometry_count
doc: The global IDs of the geometry on this map
- id: script_global_ids
type: u2
repeat: expr
repeat-expr: script_count
doc: The global IDs of the scripts this map and its entities use
- id: go_directions
type: go_direction
repeat: expr
repeat-expr: go_direction_count
- id: map_header_padding
type: u2
repeat: expr
repeat-expr: (entity_count + geometry_count + script_count) % 2
doc: Padding to align things back to uint32_t
- id: layers
type: map_layer(cols, rows)
repeat: expr
repeat-expr: layer_count
instances:
tiles_per_layer:
value: 'cols * rows'
go_direction:
seq:
- id: name
type: str
size: 12
encoding: ASCII
- id: script_id
type: u2
- id: padding
type: u2
doc: to get us back into 16 alignment
map_layer:
params:
- id: width
type: u2
- id: height
type: u2
seq:
- id: tiles
type: map_tile
repeat: expr
repeat-expr: tiles_per_layer
instances:
tiles_per_layer:
value: 'width * height'
map_tile:
seq:
- id: tile_id
type: u2
- id: map_tileset_id
type: u1
- id: render_flags
type: render_flags
render_flags:
seq:
- id: flags
type: u1
instances:
is_glitched:
value: (flags & 0b10000000) != 0
is_debug:
value: (flags & 0b01000000) != 0
flip_x:
value: (flags & 0b00000100) != 0
flip_y:
value: (flags & 0b00000010) != 0
flip_diag:
value: (flags & 0b00000001) != 0
entity_render_flags:
seq:
- id: flags
type: u1
instances:
is_glitched:
value: (flags & 0b10000000) != 0
is_debug:
value: (flags & 0b01000000) != 0
relative_direction:
value: (flags & 0b00110000) >> 4
direction:
value: (flags & 0b00000011)
enum: direction_type
tileset:
seq:
- id: name
type: str
size: 16
encoding: ASCII
- id: image_id
type: u2
- id: image_width
type: u2
- id: image_height
type: u2
- id: tile_width
type: u2
- id: tile_height
type: u2
- id: cols
type: u2
- id: rows
type: u2
- id: padding
type: u2
- id: tile_global_geometry_ids
type: u2
repeat: expr
repeat-expr: tile_count
- id: tileset_footer_padding
type: u2
repeat: expr
repeat-expr: tile_count % 2
doc: Padding bytes to get things back to uint32_t alignment
instances:
tile_count:
value: cols * rows
animation:
seq:
- id: tileset_id
type: u2
- id: frame_count
type: u2
- id: animation_frames
type: animation_frame
repeat: expr
repeat-expr: frame_count
animation_frame:
seq:
- id: tile_id
type: u2
- id: duration
type: u2
entity_type:
seq:
- id: name
type: str
size: 32
encoding: ASCII
- id: padding_a
type: u1
- id: padding_b
type: u1
- id: portrait_index
type: u1
- id: animation_count
type: u1
- id: entity_type_animations
type: entity_type_animation
repeat: expr
repeat-expr: animation_count
entity_type_animation:
seq:
- id: north
type: entity_type_animation_direction
- id: east
type: entity_type_animation_direction
- id: south
type: entity_type_animation_direction
- id: west
type: entity_type_animation_direction
entity_type_animation_direction:
seq:
- id: type_id
type: u2
- id: type
type: u1
doc: if value is 0, type_id is the ID of an animation. If value is not 0, type is now a lookup on the tileset table, and type_id is the ID of the tile on that tileset
- id: render_flags
type: render_flags
entity:
seq:
- id: name
type: str
size: 12
encoding: ASCII
- id: x
type: u2
- id: y
type: u2
- id: on_interact_script_id
type: u2
doc: local index to the map's script list
- id: on_tick_script_id
type: u2
doc: local index to the map's script list
- id: primary_id
type: u2
doc: may be: entity_type_id, animation_id, tileset_id
- id: secondary_id
type: u2
doc: if primary_id_type is tileset_id, this is the tile_id, otherwise 0
- id: primary_id_type
type: u1
enum: entity_primary_id_type
- id: current_animation
type: u1
- id: current_frame
type: u1
- id: direction
type:
switch-on: primary_id_type
cases:
'entity_primary_id_type::tileset_id': render_flags
'entity_primary_id_type::animation_id': render_flags
'entity_primary_id_type::entity_type_id': entity_render_flags
- id: path_id
type: u2
doc: local index to the map's geometry list
- id: on_look_script_id
type: u2
doc: local index to the map's script list
geometry:
seq:
- id: name
type: str
size: 32
encoding: ASCII
- id: geometry_type
type: u1
enum: geometry_type
- id: point_count
type: u1
- id: segment_count
type: u1
- id: padding
type: u1
- id: path_length
type: f4
- id: points
type: point
repeat: expr
repeat-expr: point_count
- id: segment_lengths
type: f4
repeat: expr
repeat-expr: segment_count
point:
seq:
- id: x
type: u2
- id: y
type: u2
script:
seq:
- id: name
type: str
size: 32
encoding: ASCII
- id: action_count
type: u4
- id: actions
type: action
repeat: expr
repeat-expr: action_count
action:
seq:
- id: action_type
type: u1
enum: action_type
- id: padding_a
type: u1
- id: padding_b
type: u1
- id: padding_c
type: u1
- id: padding_d
type: u1
- id: padding_e
type: u1
- id: padding_f
type: u1
- id: padding_g
type: u1
portrait:
seq:
- id: name
type: str
size: 32
encoding: ASCII
- id: padding_a
type: u1
- id: padding_b
type: u1
- id: padding_c
type: u1
- id: emote_count
type: u1
- id: emotes
type: entity_type_animation_direction
repeat: expr
repeat-expr: emote_count
dialog:
seq:
- id: name
type: str
size: 32
encoding: ASCII
- id: screen_count
type: u4
- id: dialog_screens
type: dialog_screen
repeat: expr
repeat-expr: screen_count
dialog_screen:
seq:
- id: name_index
type: u2
- id: border_tileset_index
type: u2
- id: alignment
type: u1
enum: dialog_screen_alignment_type
- id: font_index
type: u1
- id: message_count
type: u1
- id: response_type
type: u1
enum: dialog_response_type
- id: response_count
type: u1
- id: entity_id
type: u1
- id: portrait_id
type: u1
- id: emote
type: u1
- id: messages
type: u2
repeat: expr
repeat-expr: message_count
- id: responses
type: dialog_response
repeat: expr
repeat-expr: response_count
- id: dialog_screen_padding
type: u2
repeat: expr
repeat-expr: (message_count) % 2
doc: Padding to align things back to uint32_t
dialog_response:
seq:
- id: string_id
type: u2
- id: map_local_script_id
type: u2
serial_dialog:
seq:
- id: name
type: str
size: 32
encoding: ASCII
- id: string_id
type: u2
- id: serial_response_type
type: u1
enum: serial_response_type
- id: response_count
type: u1
- id: responses
type: serial_dialog_response
repeat: expr
repeat-expr: response_count
serial_dialog_response:
seq:
- id: string_id
type: u2
- id: map_local_script_id
type: u2
string:
params:
- id: index
type: u4
instances:
offset:
value: '_parent.string_offsets.offsets[index]'
char_count:
value: '_parent.string_offsets.lengths[index]'
name:
type: strz
size: char_count
encoding: ASCII
image_color_palette:
seq:
- id: name
type: str
size: 32
encoding: ASCII
- id: color_count
type: u1
- id: padding
type: u1
doc: Padding to align things back to uint16_t
- id: colors
type: image_color
repeat: expr
repeat-expr: color_count
- id: colors_padding
type: u2
repeat: expr
repeat-expr: (color_count + 1) % 2
doc: Padding to align things back to uint32_t
image:
params:
- id: index
type: u4
instances:
offset:
value: '_parent.image_offsets.offsets[index]'
pixel_count:
value: '_parent.image_offsets.lengths[index] / 2'
colors:
pos: offset
type: u1
repeat: expr
repeat-expr: pixel_count
image_color:
seq:
- id: color_565
type: u2be
instances:
r:
value: '(color_565 & 0b1111100000000000) >> 11'
g:
value: '(color_565 & 0b0000011111000000) >> 6'
b:
value: '(color_565 & 0b0000000000011111)'
a:
value: '(color_565 & 0b0000000000100000 ^ 0b0000000000100000) >> 5'
enums:
entity_primary_id_type:
0: tileset_id
1: animation_id
2: entity_type_id
direction_type:
0: north
1: east
2: south
3: west
geometry_type:
0: point
1: polyline
2: polygon
action_type:
00: null_action
01: check_entity_name
02: check_entity_x
03: check_entity_y
04: check_entity_interact_script
05: check_entity_tick_script
06: check_entity_look_script
07: check_entity_type
08: check_entity_primary_id
09: check_entity_secondary_id
10: check_entity_primary_id_type
11: check_entity_current_animation
12: check_entity_current_frame
13: check_entity_direction
14: check_entity_glitched
15: check_entity_path
16: check_save_flag
17: check_if_entity_is_in_geometry
18: check_for_button_press
19: check_for_button_state
20: check_warp_state
21: run_script
22: blocking_delay
23: non_blocking_delay
24: set_entity_name
25: set_entity_x
26: set_entity_y
27: set_entity_interact_script
28: set_entity_tick_script
29: set_entity_type
30: set_entity_primary_id
31: set_entity_secondary_id
32: set_entity_primary_id_type
33: set_entity_current_animation
34: set_entity_current_frame
35: set_entity_direction
36: set_entity_direction_relative
37: set_entity_direction_target_entity
38: set_entity_direction_target_geometry
39: set_entity_glitched
40: set_entity_path
41: set_save_flag
42: set_player_control
43: set_map_tick_script
44: set_hex_cursor_location
45: set_warp_state
46: set_hex_editor_state
47: set_hex_editor_dialog_mode
48: set_hex_editor_control
49: set_hex_editor_control_clipboard
50: load_map
51: show_dialog
52: play_entity_animation
53: teleport_entity_to_geometry
54: walk_entity_to_geometry
55: walk_entity_along_geometry
56: loop_entity_along_geometry
57: set_camera_to_follow_entity
58: teleport_camera_to_geometry
59: pan_camera_to_entity
60: pan_camera_to_geometry
61: pan_camera_along_geometry
62: loop_camera_along_geometry
63: set_screen_shake
64: screen_fade_out
65: screen_fade_in
66: mutate_variable
67: mutate_variables
68: copy_variable
69: check_variable
70: check_variables
71: slot_save
72: slot_load
73: slot_erase
74: set_connect_serial_dialog
75: show_serial_dialog
76: set_map_look_script
77: set_entity_look_script
78: set_teleport_enabled
79: check_map
80: set_ble_flag
81: check_ble_flag
82: set_serial_dialog_control
83: register_serial_dialog_command
84: register_serial_dialog_command_argument
85: unregister_serial_dialog_command
86: unregister_serial_dialog_command_argument
87: set_entity_movement_relative
88: check_dialog_open
89: check_serial_dialog_open
90: check_debug_mode
91: close_dialog
92: close_serial_dialog
93: set_lights_control
94: set_lights_state
95: goto_action_index
96: set_script_pause
97: register_serial_dialog_command_alias
98: unregister_serial_dialog_command_alias
99: set_serial_dialog_command_visibility
dialog_screen_alignment_type:
0: bottom_left
1: bottom_right
2: top_left
3: top_right
4: bottom_left_with_name
5: bottom_right_with_name
6: top_left_with_name
7: top_right_with_name
dialog_response_type:
0: no_response
1: select_from_short_list
2: select_from_long_list
3: enter_number
4: enter_alphanumeric
serial_response_type:
0: response_none
1: response_enter_number
2: response_enter_string