Ok so I think I'm ready to give this out, hopefully it won't just break. This is mainly for StorMyu and Sporky I suppose, but I'm gonna put it here for anyone interested: http://pastebin.com/sSzzMP6P - For python 2.7, usage is "script.py <filename> -e" to decompile, and "script.py <filename> -i" to recompile.
This is a script that decompiles and recompiles (although not perfectly) the game's script files. I've put a loooad of comments all throughout it to try and explain, hopefully make it clearer to make your own tools based off it. Be aware though, removing code does not work, so don't remove lines from the decompiled script, because I couldn't get removing to work properly. You can add and edit as much as you want though. It has automatic new-lining and splitting of strings. As strings are limited to basically 80 characters, although it's sort of like 78, the code will automatically split your strings. Keep single strings to one line. The automatic newlining (and lack of manual splitting) and splitting of strings will probably fuck you over in terms of actually making the text presentable, so I don't really advise this to be used for actually translating the game in its current state. If you wanted to do that though, you can just disable all the newlining and etc pretty easily, and then just newline/make new strings yourself. You'd just need to always be aware of line lengths and the string size limits though.
Ok so for actual editing, editing strings or any variables is straight forward, just change them. Strings need to be inside " " (and only one set).
To add code, add your lines so that the curly brace { starts the line, take the line number out of it, otherwise things will break. Added lines need to start with that {. Here's an example:
So you can see there, on the left is the original code that I modified manually. You see I added 3 jumps after the play-voice line, and also needed to add that "name goes here" line because it's required by the msgbox-name function. I change that line from msgbox to msgbox-name, so I had to set the name there as well. I also set the line after the name to be 3e6 instead of 1, because again, that's what's used for the msgbox-name function for the character name.
On the right you see the compiled, and then decompiled again script. You see all the strings split as they needed to, to stay within the string size limits, and you see that it added all the required parameters as well.
Most importantly though (for an adding point of view anyway, which is pretty much required with these tight string sizes), look at the jumps. Check the blocks I had them jumping to in the original script. They jumped to block 41e (the { get-string "40_0100_001_0" } line), block 420 the call-voice line, and 422 the バカッバカッバカッ line. Compare that with the script on the right, and note how they still match up, even after adding all those lines. That's important. StorMyu and anyone else who's going to play with these files or make tools, you really have to make sure you fix those jumps, otherwise you'll end up with the game jumping to the wrong place in the script. Could be an invalid location and just crash the game, or even more subtle in maybe you end up skipping over some code that sets a game flag, and then the game becomes impossible to finish or something. So, just make sure those are fixed.
And so back in game, we get the expected output, as the script on the right indicates. I had to take those jumps out of course, otherwise we'd just jump straight over our edited lines:
And etc etc.
I haven't checked all the opcodes, so I can't be 100% sure they're right. The trend I saw from all the ones I was able to actually hit in the game, had 1 dword variable if below 0x22, and just the opcode if 0x22 or above. But I didn't actually specifically check all the ones I have listed.
I'm unsure on the jumps as well, I have 0x1a - 0x1e as jumps, ruled 0x1f out, and I don't think I hit 0x1b in the game. So check those if possible Stormyu. As well as most of all the others. Pretty confident that 1a is a jmp, and 1b - 1e are conditional jumps, but I don't know the conditions.
So yeah, that's about it. \o/
EDIT: Added a couple more opcodes, all scripts in the script folder now decompile (apart from _def). You can decompile a whole folder using "script.py <foldername> -dumpall" and recompile a whole folder with "script.py <foldername> -compall"
This is a script that decompiles and recompiles (although not perfectly) the game's script files. I've put a loooad of comments all throughout it to try and explain, hopefully make it clearer to make your own tools based off it. Be aware though, removing code does not work, so don't remove lines from the decompiled script, because I couldn't get removing to work properly. You can add and edit as much as you want though. It has automatic new-lining and splitting of strings. As strings are limited to basically 80 characters, although it's sort of like 78, the code will automatically split your strings. Keep single strings to one line. The automatic newlining (and lack of manual splitting) and splitting of strings will probably fuck you over in terms of actually making the text presentable, so I don't really advise this to be used for actually translating the game in its current state. If you wanted to do that though, you can just disable all the newlining and etc pretty easily, and then just newline/make new strings yourself. You'd just need to always be aware of line lengths and the string size limits though.
Ok so for actual editing, editing strings or any variables is straight forward, just change them. Strings need to be inside " " (and only one set).
To add code, add your lines so that the curly brace { starts the line, take the line number out of it, otherwise things will break. Added lines need to start with that {. Here's an example:
So you can see there, on the left is the original code that I modified manually. You see I added 3 jumps after the play-voice line, and also needed to add that "name goes here" line because it's required by the msgbox-name function. I change that line from msgbox to msgbox-name, so I had to set the name there as well. I also set the line after the name to be 3e6 instead of 1, because again, that's what's used for the msgbox-name function for the character name.
On the right you see the compiled, and then decompiled again script. You see all the strings split as they needed to, to stay within the string size limits, and you see that it added all the required parameters as well.
Most importantly though (for an adding point of view anyway, which is pretty much required with these tight string sizes), look at the jumps. Check the blocks I had them jumping to in the original script. They jumped to block 41e (the { get-string "40_0100_001_0" } line), block 420 the call-voice line, and 422 the バカッバカッバカッ line. Compare that with the script on the right, and note how they still match up, even after adding all those lines. That's important. StorMyu and anyone else who's going to play with these files or make tools, you really have to make sure you fix those jumps, otherwise you'll end up with the game jumping to the wrong place in the script. Could be an invalid location and just crash the game, or even more subtle in maybe you end up skipping over some code that sets a game flag, and then the game becomes impossible to finish or something. So, just make sure those are fixed.
And so back in game, we get the expected output, as the script on the right indicates. I had to take those jumps out of course, otherwise we'd just jump straight over our edited lines:
And etc etc.
I haven't checked all the opcodes, so I can't be 100% sure they're right. The trend I saw from all the ones I was able to actually hit in the game, had 1 dword variable if below 0x22, and just the opcode if 0x22 or above. But I didn't actually specifically check all the ones I have listed.
I'm unsure on the jumps as well, I have 0x1a - 0x1e as jumps, ruled 0x1f out, and I don't think I hit 0x1b in the game. So check those if possible Stormyu. As well as most of all the others. Pretty confident that 1a is a jmp, and 1b - 1e are conditional jumps, but I don't know the conditions.
So yeah, that's about it. \o/
EDIT: Added a couple more opcodes, all scripts in the script folder now decompile (apart from _def). You can decompile a whole folder using "script.py <foldername> -dumpall" and recompile a whole folder with "script.py <foldername> -compall"