Skip to content

Instantly share code, notes, and snippets.

@hapo31
Created May 6, 2019 14:32
Show Gist options
  • Save hapo31/464b1acc863598117f0c1c7de20ac49c to your computer and use it in GitHub Desktop.
Save hapo31/464b1acc863598117f0c1c7de20ac49c to your computer and use it in GitHub Desktop.
def split_list(l, n):
for idx in range(0, len(l), n):
yield l[idx:idx + n]
def extract_wav_size(byte):
dest = []
chunk = []
title_flag = False
for x in byte:
if x == 0x74: # 't'
title_flag = True
if len(chunk) > 0:
dest.append(list(split_list(chunk[5:21], 4)))
chunk = []
if x == 0x76: # 'v
title_flag = False
continue
if not title_flag:
chunk.append(x)
return dest
def format(number):
return "{:010X}".format(number)
def calc_bgm_size(chunks):
results = []
for i, chunk in enumerate(chunks):
start_pos = chunk[0]
intro_len = chunk[2]
if i + 1 < len(chunks):
bgm_len = chunks[i + 1][0] - start_pos
loop_len = bgm_len - intro_len
results.append([start_pos, intro_len, loop_len])
return results
if __name__ == "__main__":
with open("thbgm_tr.fmt", "rb") as src:
byte = src.read()
dest = extract_wav_size(byte)
chunks = []
for x in dest:
chunk = []
i = 0
print(x)
for i in x:
result = 0
result |= (i[0])
result |= (i[1] << 8)
result |= (i[2] << 16)
result |= (i[3] << 24)
chunk.append(result)
chunks.append(chunk)
results = calc_bgm_size(chunks)
for x in results:
print(",".join([format(c) for c in x]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment