forked from Dorif/fragalyseqt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfillarray.py
99 lines (94 loc) · 4.35 KB
/
fillarray.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
# This file is part of FragalyseQt.
#
# FragalyseQt is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option)
# any later version.
#
# FragalyseQt is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License
# for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with FragalyseQt. If not, see <https://www.gnu.org/licenses/>.
from struct import unpack
def fill_num_array(FA_dict, FA_file, FA_str, namearray, hexarray, plen, fstr):
for item in namearray:
FA_dict[item] = ()
index = 0
while index < len(namearray):
FA_file.seek(FA_str.find(hexarray[index]) + 20, 0)
FA_file.seek(int.from_bytes(FA_file.read(4), 'big'), 0)
if fstr == '>H':
readnum = 2
elif fstr == '>I':
readnum = 4
elif fstr == '>d':
readnum = 8
iterator = 0
while iterator < plen:
FA_dict[namearray[index]] += unpack(fstr, FA_file.read(readnum))
iterator += 1
index += 1
def fill_char_array(FA_dict, FA_file, FA_str, namearray, dyestr, wavestr):
array = [b'\x44\x41\x54\x41\x00\x00\x00\x01',
b'\x44\x41\x54\x41\x00\x00\x00\x02',
b'\x44\x41\x54\x41\x00\x00\x00\x03',
b'\x44\x41\x54\x41\x00\x00\x00\x04',
b'\x44\x41\x54\x41\x00\x00\x00\x69',
b'\x44\x41\x54\x41\x00\x00\x00\x6a',
b'\x44\x41\x54\x41\x00\x00\x00\x6b',
b'\x44\x41\x54\x41\x00\x00\x00\x6c']
carray = [b'\x44\x79\x65\x57\x00\x00\x00\x01',
b'\x44\x79\x65\x57\x00\x00\x00\x02',
b'\x44\x79\x65\x57\x00\x00\x00\x03',
b'\x44\x79\x65\x57\x00\x00\x00\x04',
b'\x44\x79\x65\x57\x00\x00\x00\x05',
b'\x44\x79\x65\x57\x00\x00\x00\x06',
b'\x44\x79\x65\x57\x00\x00\x00\x07',
b'\x44\x79\x65\x57\x00\x00\x00\x08']
darray = [b'\x44\x79\x65\x4e\x00\x00\x00\x01',
b'\x44\x79\x65\x4e\x00\x00\x00\x02',
b'\x44\x79\x65\x4e\x00\x00\x00\x03',
b'\x44\x79\x65\x4e\x00\x00\x00\x04',
b'\x44\x79\x65\x4e\x00\x00\x00\x05',
b'\x44\x79\x65\x4e\x00\x00\x00\x06',
b'\x44\x79\x65\x4e\x00\x00\x00\x07',
b'\x44\x79\x65\x4e\x00\x00\x00\x08']
sarray = [b'\x44\x79\x65\x53\x00\x00\x00\x01',
b'\x44\x79\x65\x53\x00\x00\x00\x02',
b'\x44\x79\x65\x53\x00\x00\x00\x03',
b'\x44\x79\x65\x53\x00\x00\x00\x04',
b'\x44\x79\x65\x53\x00\x00\x00\x05',
b'\x44\x79\x65\x53\x00\x00\x00\x06',
b'\x44\x79\x65\x53\x00\x00\x00\x07',
b'\x44\x79\x65\x53\x00\x00\x00\x08']
FA_file.seek(FA_str.find(array[0]) + 12, 0)
datalength = int.from_bytes(FA_file.read(4), 'big')
FA_keys = FA_dict.keys()
for item in namearray:
if item in FA_keys:
FA_dict[item] = ()
index = 0
while index < FA_dict["Dye#1"]:
FA_file.seek(FA_str.find(array[index]) + 20, 0)
FA_file.seek(int.from_bytes(FA_file.read(4), 'big'), 0)
iterator = 0
while iterator < datalength:
FA_dict[namearray[index]] += unpack('>h', FA_file.read(2))
iterator += 1
if carray[index] in FA_keys:
FA_file.seek(FA_str.find(carray[index]) + 20, 0)
FA_dict[wavestr[index]] = int.from_bytes(FA_file.read(2), 'big')
FA_file.seek(FA_str.find(darray[index]) + 16, 0)
nlen = int.from_bytes(FA_file.read(4), 'big') - 1
FA_file.seek(int.from_bytes(FA_file.read(4), 'big') + 1, 0)
FA_dict[dyestr[index]] = FA_file.read(nlen)
if len(FA_dict[dyestr[index]]) == 0:
FA_file.seek(FA_str.find(sarray[index]) + 20, 0)
slen = int.from_bytes(FA_file.read(1), 'big')
FA_dict[dyestr[index]] = FA_file.read(slen)
if FA_dict[dyestr[index]] == b'':
FA_dict[dyestr[index]] = bytes(str(index+1), 'utf-8')
index += 1