I'll post all my python questions (there will be many, many more in the future) in this thread.
I have a table.
FB 2C D2 93 40 00 00 00 00 00 00 00 EA C8 61 00
F9 AA F0 D7 C0 00 00 00 00 00 00 00 FD 28 CA 00
E2 49 B4 8B 50 00 00 00 00 00 00 00 F2 4B CE 00
E8 99 A4 4B B0 00 00 00 00 00 00 00 E1 37 D7 00
82 0E 00 C3 40 00 00 00 00 00 00 00 DE 89 19 00
F5 F1 FB 1F F0 00 00 00 00 00 00 00 E3 FE E6 00
FA E7 D2 DF D0 00 00 00 00 00 00 00 F5 EC F5 00
FF F9 FF 1F F0 00 00 00 00 00 00 00 F4 BD 79 00
FB C6 92 D3 20 00 00 00 00 00 00 00 FF FA FE 00
FB C9 54 03 D0 00 00 00 00 00 00 00 FF 13 0A 00
C9 96 92 CB B0 00 00 00 00 00 00 00 C5 1E BD 00
FB EE D2 C3 77 00 00 00 00 00 07 FC EA E9 F9 00
FD F9 FD 57 E0 00 00 00 00 00 00 00 F7 7D 7D 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
It's located at 0xE3FC in SCUS_942.30 (Saga Frontier). It's 256 bytes long, 16x16. It represents the Spark Talents lists in Saga Frontier, which are a list of bit flags which determine whether it's hard or not to spark specific skills. Each bit represents a single skill. The big gap in the middle are all the skills that can't be sparked by anyone. Each row is a list, which are assigned to human and half-human characters.
I first want to switch the columns and rows of the table, which I think is called transposing a matrix in Python. Can't force users to install some esoteric math module and I am not willing to spend a month figuring out licensing BS.
Language is Python 3.
How do I:
1. Read this into a list of lists?
2. Transpose it?
Regarding #1, search engines just return reads from text files which are totally useless.
I wrote code whose output must be seen to be believed.
Code 1:
import io,sys
with open(sys.argv[1], 'rb') as scus:
baseAddr =58364
scus.seek(baseAddr)
with open("sparks.txt", 'w') as writer:
tblList1 = []
cntr = 0
while cntr < 16:
tblList1.append(scus.read(16))
#tblList1.insert(cntr, scus.read(16))
cntr += 1
for i in tblList1:
for j in i:
print(hex(j)[2:].zfill(2) + "-", end='')
print()
Output 1:
https://pastebin.com/9rr4XDsDCode 2:
import io,sys
with open(sys.argv[1], 'rb') as scus:
baseAddr =58364
scus.seek(baseAddr)
with open("sparks.txt", 'w') as writer:
tblList1 = []
cntr = 0
while cntr < 16:
#tblList1.append(scus.read(16))
tblList1.insert(cntr, scus.read(16))
cntr += 1
for i in tblList1:
for j in i:
print(hex(j)[2:].zfill(2) + "-", end='')
print()
Output 2:
https://pastebin.com/e6Aq26KBI don't know if it's a "feature" of lists in Python, or something to do with the read() method used in binary mode, but it's apparently adding redundant lines over and over again. What should be a 16x16 list becomes a 138x16 list.
Assuming I ever get the code above to work, I then need to switch the rows and columns (aka transpose the matrix).
Once that's done, I need to move from printing 16 bytes per column to 256 ones (1) or zeroes (0) to represent talent or no-talent for each skill. I also need to add a space between each digit per row so it can safely be pasted into a spreadsheet.
edit
LOL my dumb *** missed the indentation = bracket, code fixed.
Disregard I am stoopidt!
import io,sys
with open(sys.argv[1], 'rb') as scus:
baseAddr =58364
scus.seek(baseAddr)
with open("sparks.txt", 'w') as writer:
tblList1 = []
cntr = 0
while cntr < 16:
#tblList1.append(scus.read(16))
tblList1.insert(cntr, scus.read(16))
cntr += 1
for i in tblList1:
for j in i:
print(hex(j)[2:].zfill(2) + "-", end='')
print()
Output:
$ python extractSparkTalents.py SCUS_942.30
fb-2c-d2-93-40-00-00-00-00-00-00-00-ea-c8-61-00-
f9-aa-f0-d7-c0-00-00-00-00-00-00-00-fd-28-ca-00-
e2-49-b4-8b-50-00-00-00-00-00-00-00-f2-4b-ce-00-
e8-99-a4-4b-b0-00-00-00-00-00-00-00-e1-37-d7-00-
82-0e-00-c3-40-00-00-00-00-00-00-00-de-89-19-00-
f5-f1-fb-1f-f0-00-00-00-00-00-00-00-e3-fe-e6-00-
fa-e7-d2-df-d0-00-00-00-00-00-00-00-f5-ec-f5-00-
ff-f9-ff-1f-f0-00-00-00-00-00-00-00-f4-bd-79-00-
fb-c6-92-d3-20-00-00-00-00-00-00-00-ff-fa-fe-00-
fb-c9-54-03-d0-00-00-00-00-00-00-00-ff-13-0a-00-
c9-96-92-cb-b0-00-00-00-00-00-00-00-c5-1e-bd-00-
fb-ee-d2-c3-77-00-00-00-00-00-07-fc-ea-e9-f9-00-
fd-f9-fd-57-e0-00-00-00-00-00-00-00-f7-7d-7d-00-
00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-
00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-
00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-
I'll transpose it tomorrow, time for a break.