-
Notifications
You must be signed in to change notification settings - Fork 3
/
extract_macros.py
executable file
·60 lines (52 loc) · 1.95 KB
/
extract_macros.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
#!/usr/bin/python
#FFXIV Macro Extractor
#Copyright Arthur Moore 2016
#BSD 3 Clause License
from __future__ import print_function
from FFXIV_settings_common import *
def read_macro(in_file):
macro={"data": []}
#There are exactly 18 sections per macro
macro["name"] = read_section(in_file,0x73)['data']
macro["icon"] = read_section(in_file,0x73)['data']
macro["key"] = read_section(in_file,0x73)['data']
#Every macro has 15 lines
for i in range(0,15):
macro["data"].append(read_section(in_file,0x73)['data'])
return macro
def write_macro(out_file,macro):
write_section(out_file,0x73,{'type':'T','data':macro["name"]})
write_section(out_file,0x73,{'type':'I','data':macro["icon"]})
write_section(out_file,0x73,{'type':'K','data':macro["key"]})
#Every macro has 15 lines
for i in range(0,15):
write_section(out_file,0x73,{'type':'L','data':macro["data"][i]})
def read_macro_file(in_file_name):
in_file = open(in_file_name, "rb")
header = read_header(in_file,0x11)
macros=[]
while in_file.tell() < header['data_size']:
macros.append(read_macro(in_file))
return (header,macros)
def write_macro_file(out_file_name,(header,macros)):
out_file = open(out_file_name, "wb")
write_header(out_file,header)
for i in macros:
write_macro(out_file,i)
write_padding(out_file,header)
def print_macro(in_macro):
print("Name: ",in_macro["name"])
print("Icon: ",in_macro["icon"])
print("Key: ",in_macro["key"])
print("Data (15 lines):")
for i in in_macro["data"]:
#Sanitize the line to ascii only characters to prevent print from choking (For python3)
#sanitized_line = i.encode('ascii','ignore').decode('ascii')
sanitized_line = i
print(" ",sanitized_line)
#Example usage
macro_file = read_macro_file("MACRO.DAT")
write_macro_file("MACRO_check.DAT",macro_file)
for i in macro_file[1]:
if(i["key"] != '000'):
print_macro(i)