Home » Fable TLC » Development » Advanced Modding » BigTools
Re: .big Reading [message #66276 is a reply to message #66273] |
Wed, 04 April 2012 19:48 |
xenn
Messages: 17 Registered: February 2012 Location: Canada
|
|
|
|
Rather than Quote: | buffer += 2*4;
bnkAddr = *((long *) buffer);
buffer -= 2*4;
|
consider Quote: | bnkAddr = *((long *) buffer+2);
|
Saves you two steps. Should work the same.
"Bank Address" and "Number of Banks" read okay.
Bank ID doesn't read correctly.
The bank name seems to read okay though.
"Number of Bank Entries", "Index Start", "Index Size", and "Block Size" all seem to not read correctly.
Bank ID was a bit of a bitch to track down.
I don't know C, but I read somewhere that fscanf increments the file pointer as it reads characters, but that it can push the file pointer farther than the string length.
I don't know if that's true or accurate, but in case it is, this seems to be a safer (and working) implementation :
Quote: | /* BEGIN BANK INFO RETRIEVAL */
fseek(input, 4, SEEK_CUR);
fscanf(input, "%s", bankName[i]);
fseek(input,bnkAddr+5+strlen(bankName[i]),SEEK_SET);
|
The line added (in red) adds the length of the bank name (+1 to account for the null character and +4 to account for the "Number of Banks" dword) to the bank address, and sets the file pointer accordingly.
I hadn't been expecting it to, but fortunately that also seems to fix the next four readouts.
Only tested it with text.big and fonts.big, though.
I didn't look at anything from "NumberFileTypes" ("Number of File Types") onward, and stripped it out of the source for simplicity.
(To avoid crashing).
I'll keep changes I make to the source here : http://pastebin.com/raw.php?i=NNiYQ7HG
Combine the fseek fix with whatever you've got now, do some more of your own testing, and then let us know if you need some help.
It's unrelated, but one last thing that stood out was this :
Quote: | // Begin Reading File
char *buffer = (char *) malloc(5000);
|
The most memory I've seen your buffer use was something like 36 bytes.
It's probably convenient to choose some arbitrarily large memory amount, but just be careful not to get carried away ;)
It's not so important now, but if (when) you get to loading large chunks of the .BIG files at a time, being careful with your memory management can avoid crashes and hard-to-find bugs.
Good luck with the rest of your work !
|
|
|
Goto Forum:
Current Time: Sun Nov 24 02:58:48 PST 2024
Total time taken to generate the page: 0.17788 seconds
|