A lot of blah blah, scroll down for the matter i need help with...
I'm a moderator of a gaming forum and a big fan of bishoujo games. I sometimes do my own game releases/revamps, but what i've did till now didn't involve much "real" coding.
I want to make a game called Snow Drop compatible with XP and Vista. I've fixed the font animation bug already (just required a registry patch and a nice monospaced font) and remastered the music.
All worked fine on XP SP2 and Vista 32-bit, and replacing the ADPCM codec with an older version fixed voice on updated XP installs. But once i added another 2x 2GB RAM to my main computer, making for a total of 6GB, and installed Vista 64, i hit yet another voice issue.
The ADPCM codec in Vista 64 is screwed up badly, and no file changes would fix it, besides i also had to deal with permissions. So i tried using uncompressed PCM audio for voice, and it worked. The voice file will be 469MB instead of 160MB, but that's a different story, at least it works.
However, the work is far from over. Inside the voice datafile there are 1.564 different wave files. I found a Perl script to extract the WAVs from the main datafile and it worked, however i know exactly zero perl so i'm hoping i could do it in Python. I've written a little playlist converter app for Meizu players using Python a while ago, but i know this is going to be more complicated than copy/pasting a few lines of text.
Stuff of real interest starts here.
So, i have the WAVs extracted and converted. Now i need to get them back into the datafile. Keeping only the index of the voice datafile and using
copy /b "voice.arc" + "*.wav" "voice.arc"
did a nice job at merging the files, but i also have to make the game recognize the new file positions.
The structure of the datafile is as follows:
The header determins the file type. Then the file names are stored in alphabetical order (yes, it jumps from 0-2, 3-9, etc, no idea why, that's how they were made in the first place). After each file name there is a null character. The following 4 bytes represent the file size in hex, and the 4 bytes following them give that file's offset, in little endian. (It did take a while to figure this out...)
For the 23 music tracks i did all extraction, injection and correction of sizes/offsets by hand. But there's no way in hell i could do the same for the 1.5k+ voice files.
I also have the converted files separately, so i thought of doing this in Python the following way:
1. Give the program the initial offset in decimal (where the datafile's index ends)
2. Get size of every WAV file in the current folder, in alphabetical order, and dump the values into a temp file
3. Calculate the decimal offsets of the WAVs by adding up file sizes to the initial offset, dump those in a temp file as well (yeah i like temp files)
4. Convert sizes and offsets to hex, offsets will also have to be in little endian
5. Dump computed hex data into the index, at the right places.
Right now i'm stuck at step 2, and i only have a bit of crappy code. I think i know how to do steps 3 and 4, but right now i need to do 2.
import os filename = raw_input("filename plz: ") size = os.path.getsize(filename) filesize = str(size) output = open("sizes.txt", "w") output.write(filesize) output.write("\n")
This only gets the size of one file. I have no idea how to make it get the sizes of all files in current directory. I read i'll need to use os.listdir, however i have no idea how to use it for what i need to do.
Any help is welcome. :)