-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy patharika_ps2_cd.bms
230 lines (225 loc) · 6.23 KB
/
arika_ps2_cd.bms
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
# Arika - ARIKA.DAT/INFO.DAT
# ---
# Street Fighter EX3 (PS2)
# Technictix (PS2)
# Technic Beat (PS2)
# Forever Blue (Wii)
# Forever Blue: Umi no Yubigoe (Wii)
math dat1 = 1
math dat2 = 2
math ver = 1
math is_elf = 1
get elf_name filename
if elf_name == "SLPM_601.05" # Street Fighter EX3 - Trial Version (PlayStation Festival 2000)
xmath files "0x1a00 / 0x20"
callfunction handle_arika_dat 1
goto 0x3fff40
callfunction txth_handling_for_sfex3 1
elif elf_name == "SLPS_200.03" # Street Fighter EX3 - Final Product (Japan)
xmath files "0x48c0 / 0x20"
callfunction handle_arika_dat 1
goto 0x433790
callfunction txth_handling_for_sfex3 1
elif elf_name == "SLPM_601.34" # Technictix - Trial Version (Japan)
xmath files "0xda0 / 0x20"
callfunction handle_arika_dat 1
elif elf_name == "SLPS_200.55" # Technictix - Final Product (Japan)
xmath files "0x2fc0 / 0x20"
callfunction handle_arika_dat 1
endif
startfunction handle_arika_dat
if is_elf = 0
if dat_name == "ARIKA.DAT"
open FDSE "ARIKA.DAT" dat1
open FDSE "PS2.DAT" dat2
elif dat_name == "INFO.DAT"
open FDSE "INFO.DAT" dat1
open FDSE "GAME.DAT" dat2
endif
else
# i don't know!
open FDSE "ARIKA.DAT" dat1
open FDSE "PS2.DAT" dat2
endif
get arika_dat_size asize dat1
goto 0 dat1
if ver = 2
get is_encrypted byte dat1
goto 0 dat1
endif
if is_encrypted == 0
# (todo)
else
for i = 0 < 0x10
get k1 byte dat1
xmath k2 "(k1 ^ 0xff) & 0xff"
putarray 0 i k2
next i
if is_elf = 0
math pos_02 = 0x20
goto pos_02 dat1
math files = 0
if ver = 1
xmath bytes_to_process "(arika_dat_size - pos_02) / 0x20"
for i2 = 0 < bytes_to_process
get tb01 long dat1
get tb02 long dat1
get tb03 long dat1
get tb04 long dat1
get tb05 long dat1
get tb06 long dat1
get tb07 long dat1
get tb08 long dat1
if tb01 != 0x40404040
if tb05 != 0x40404040
math files + 1
endif
endif
next i2
endif
endif
math pos_01 = 0x10
xmath bytes_to_process "(arika_dat_size - pos_01) / 0x10"
log MEMORY_FILE 0 0
goto 0 MEMORY_FILE
for i2 = 0 < bytes_to_process
for j1 = 0 < 0x10
goto pos_01 dat1
get target byte dat1
xmath d1 "(target & 0xf) << 4 | (target >> 4) & 0x0f"
getarray key 0 j1
xmath d2 "(key - d1) & 0xff"
put d2 byte MEMORY_FILE
math pos_01 + 1
next j1
next i2
putarray 0 "" ""
goto 0 dat1
getdstring arika_title 0x10 dat1
if ver = 1
goto 0 MEMORY_FILE
goto 4 MEMORY_FILE
get base_sector_for_ps2_dat long MEMORY_FILE
goto 0x10 MEMORY_FILE
elif ver = 2
goto 0x1c MEMORY_FILE
get files long MEMORY_FILE
goto 0x20 MEMORY_FILE
endif
for i = 0 < files
math do_not_extract = 0
if ver = 1
getdstring file_name 0x14 MEMORY_FILE
get file_offset long MEMORY_FILE
math file_offset - base_sector_for_ps2_dat
math file_offset << 11
get file_size_in_sectors long MEMORY_FILE
get file_size long MEMORY_FILE
elif ver = 2
getdstring file_name 0x20 MEMORY_FILE
get file_size_01 long MEMORY_FILE
get file_offset long MEMORY_FILE
math file_offset << 11
get file_size_in_sectors long MEMORY_FILE
get file_size_02 long MEMORY_FILE
endif
string final_name p "%s\%s" arika_title file_name
if ver = 2
if file_size_01 != file_size_02
print " compressed file %final_name% with unknown compression algorithm. "
math do_not_extract = 1
else
math file_size == file_size_02
endif
endif
if do_not_extract = 0
log final_name file_offset file_size dat2
endif
next i
endif
endfunction
# the executable part is just for handling .mus files as used by the game.
startfunction txth_handling_for_sfex3
xmath mus_entries "0xa8 / 0xc"
for i = 0 < mus_entries
get mus_name_offset long
math mus_name_offset - 0xfff00
putarray 0 i mus_name_offset
get num_songs short
putarray 1 i num_songs
get mus_size short
putarray 2 i mus_size
get mus_04 long
putarray 3 i mus_04
next i
math sample_rate = 0xac44
math interleave = 0x8000
math channels = 2
xmath chunk_size "interleave * channels"
for i = 0 < mus_entries
log MEMORY_FILE 0 0
getarray mus_name_offset 0 i
goto mus_name_offset
get mus_name string
getarray num_songs 1 i
getarray mus_size 2 i
getarray mus_04 3 i
putct "codec = PSX" string -1 MEMORY_FILE
string txth_l2 p "sample_rate = %d" sample_rate
put 0x0d byte MEMORY_FILE
put 0x0a byte MEMORY_FILE
putct txth_l2 string -1 MEMORY_FILE
string txth_l3 p "channels = %d" channels
put 0x0d byte MEMORY_FILE
put 0x0a byte MEMORY_FILE
putct txth_l3 string -1 MEMORY_FILE
string txth_l4 p "interleave = %d" interleave
put 0x0d byte MEMORY_FILE
put 0x0a byte MEMORY_FILE
putct txth_l4 string -1 MEMORY_FILE
string txth_l5 p "subsong_count = %d" num_songs
put 0x0d byte MEMORY_FILE
put 0x0a byte MEMORY_FILE
putct txth_l5 string -1 MEMORY_FILE
string txth_l6 p "chunk_start = 0"
put 0x0d byte MEMORY_FILE
put 0x0a byte MEMORY_FILE
putct txth_l6 string -1 MEMORY_FILE
string txth_l7 p "chunk_size = %d" chunk_size
put 0x0d byte MEMORY_FILE
put 0x0a byte MEMORY_FILE
putct txth_l7 string -1 MEMORY_FILE
string txth_l8 p "chunk_count = %d" num_songs
put 0x0d byte MEMORY_FILE
put 0x0a byte MEMORY_FILE
putct txth_l8 string -1 MEMORY_FILE
string txth_l9 p "start_offset = 0"
put 0x0d byte MEMORY_FILE
put 0x0a byte MEMORY_FILE
putct txth_l9 string -1 MEMORY_FILE
xmath num_samples "mus_size * chunk_size"
math num_samples / 2
math num_samples / 16
math num_samples * 28
string txth_l10 p "num_samples = %d" num_samples
put 0x0d byte MEMORY_FILE
put 0x0a byte MEMORY_FILE
putct txth_l10 string -1 MEMORY_FILE
string txth_name p "txth\%s.txth" mus_name
get txth_size asize MEMORY_FILE
log txth_name 0 txth_size MEMORY_FILE
next i
endfunction
math dat1 = 0
math dat2 = 1
math is_elf = 0
get dat_name filename
if dat_name == "ARIKA.DAT"
open FDSE "PS2.DAT" 1
math ver = 1
callfunction handle_arika_dat 1
elif dat_name == "INFO.DAT"
open FDSE "GAME.DAT" 1
math ver = 2
callfunction handle_arika_dat 1
endif