Jump to content

staffroll.bin editor Python script not working

WhitetailAni

I'm getting closer to releasing Super Timmy Wii (my Mario Bros. Wii hack), and I wanted to edit the credits. For Super Mario Bros. Wii, the credits file is called staffroll.bin.

I found a Python script on github that converts staffroll.bin into a text file and back, so I copied staffroll.bin to the a folder with the script, used the script on staffroll.bin, and ended up with staffroll.bin.txt.

I edited staffroll.bin.txt to add my few changes, and attempted to use the script to remake staffroll.bin. However, it's not working.

I'm using the script via Windows' command line; here's what it reports:
image.png.e9034a1d9da0c8ff51363d1d402dfe2e.png

Here's the project on GitHub.

I've uninstalled and reinstalled Python, which did nothing. Does anyone have any other ideas?

elephants

Link to comment
Share on other sites

Link to post
Share on other sites

I only read the script briefly, but what seems to happen is that in line 156 "struct.pack()" is getting either to much or not enough arguments. Since it's called on a per line bases, as defined in "saveStaffrollBin" it's likely just a formatting mistake inside of the text file you edited (maybe indentation, maybe missed a colon?) You could just create an incremental counter inside the for loop on line 431 in staffroll_lib.py and print it out to see what line it worked on before it crashed. So we don't have to search the culprit manually. (the code could look sth. like this, changes in bold)

 

line_cnt = 0

for line in lines:

        line_cnt += 1

        print(line_cnt)
        if line is None:
            f.write(b'\xFF\xFF\xFF\xFF')
        else:
            line.saveToBinFile(f)

 

 

Or you can catch the exeption and ignore it (via try- except block). But this may lead to some lines missing, maybe the conversion won't even work.

 

Unfortunately I am really tired and will not be back until in like 15hrs. So I can't try to help in the mean time. 

   
Link to comment
Share on other sites

Link to post
Share on other sites

1 hour ago, Bladzy said:

I only read the script briefly, but what seems to happen is that in line 156 "struct.pack()" is getting either to much or not enough arguments. Since it's called on a per line bases, as defined in "saveStaffrollBin" it's likely just a formatting mistake inside of the text file you edited (maybe indentation, maybe missed a colon?) You could just create an incremental counter inside the for loop on line 431 in staffroll_lib.py and print it out to see what line it worked on before it crashed. So we don't have to search the culprit manually. (the code could look sth. like this, changes in bold)

 

line_cnt = 0

for line in lines:

        line_cnt += 1

        print(line_cnt)
        if line is None:
            f.write(b'\xFF\xFF\xFF\xFF')
        else:
            line.saveToBinFile(f)

 

 

Or you can catch the exeption and ignore it (via try- except block). But this may lead to some lines missing, maybe the conversion won't even work.

 

Unfortunately I am really tired and will not be back until in like 15hrs. So I can't try to help in the mean time. 

   

I left an Issue report on the GitHub page and here's what the author said:

Quote

Hm, it's probably calculating a negative amount of indentation required to center a very long line, and then failing to save it because it tries to save indentation as an unsigned value. It's definitely a bug, but thinking about exactly how to fix it raises a question... is it really supposed an unsigned value, or might the game actually read it as a signed one?

I'll do a bit of in-game testing and report back. Thanks for bringing this up!

As a workaround for now, you can either make sure that every line is at most 31 characters long, or force a specific non-negative indentation for long lines. The syntax for that is to put the indentation value at the start of the line, followed by a colon, e.g. 0:This Line Will Have Zero Indentation Even Though It's Very Long. But very long lines like that probably won't work well in-game anyway.

It seems that it's an issue with how I edited staffroll.bin and the script is confused as to what it's supposed to do. I'll try tomorrow - it's 10:46 PM right now.

elephants

Link to comment
Share on other sites

Link to post
Share on other sites

So it is indirectly editing related, yaaay (sry I am happy, but this is for real my first time reviewing other peeps code online, looking for errors and suggesting solutions).
 
A long line is producing negative indentation value because "auto_indent" uses this formular to calculate the indentation values  15 - self.num_chars // 2

And if the number of chars is >31 it gets negative, resulting in a negative value getting saved as unsigned int, which won't work. Your function gets the wrong amout of arguments and it crashes. The easiest way would be indeed what he described, and he's the author so he shall know best right.

Originally I wanted to suggest a fix to you, simply checking wether  the return value of auto_indent is >0 else returning 0, but while trying to recrate the error in the first place I realized that I coudn't do that. So I went after to check what happend in the meantime and I think the autor already fixed your issue. You just need to redownload the script. He simply changed auto_indent to this code:

 

return max(0, 15 - self.num_chars // 2)


This will pick 0 whenever the other value gets negative. Thats quite a clever fix, I would have likely just opted for an if, else statement. But thats not as clean as his solution. I'd still suggest keeping the ammount of chars lower. Having to much will certainly cut some of and make for weird looks.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×