Sora no Kiseki The 3rd Script

The Legend of Heroes series is a long running game series created Falcom. Probably one of the best RPG series created with it mix of story telling and adventure.
Post Reply
flamethrower
Programmer
Posts: 790
Joined: Mon Mar 09, 2015 3:03 pm

Sora no Kiseki The 3rd Script

Post by flamethrower » Mon Aug 10, 2015 12:22 pm

Check this topic: http://www.romhacking.net/forum/index.p ... 666.0.html
I was able to solve his problem, he wanted a decompression program.

I don't own this game, so I'm not able to investigate the script. However, I think it's a very difficult format. You'd need to know about how to use regular x86 debuggers and my skill with those is lacking.

With LoH series, it's the "rooms" design. Anything that could happen in that room is put in one file. The file is divided into separate "functions." And there's also setup information - because different NPCs could be there or not depending on the situation. Within each function, it's just a list of instructions. With Nayuta, they made the instructions very obvious. But in LoH, it's not obvious which of the bytes are instructions and which are instruction operands. Like for example, "fade to white in 6 seconds" - 6 seconds would be an operand for the "fade to white" opcode. It should be easy to recognize which opcodes have to do with displayed text. But it's not possible to change the length until all opcodes are understood. Many opcodes are variable length which makes figuring it out more difficult.

User avatar
zeromonkey
Hacker, script editor and control freak
Posts: 486
Joined: Thu Mar 05, 2015 3:10 pm
Location: Tennessee

Re: Sora no Kiseki The 3rd Script

Post by zeromonkey » Mon Aug 10, 2015 6:59 pm

The script is stored in those nice little files we blanked out for the Falcom trick. I haven't located the uncompressed versions yet. I will check both the PC and PSP version to see if there is any differences in files.

User avatar
zeromonkey
Hacker, script editor and control freak
Posts: 486
Joined: Thu Mar 05, 2015 3:10 pm
Location: Tennessee

Re: Sora no Kiseki The 3rd Script

Post by zeromonkey » Tue Aug 11, 2015 12:13 am

This is for the PC version
After extracting archives (dat/dir) for 3rd. I located what I believe to be the uncompressed script files in ED6_DT21 archive. It's actually pretty cool. The header is labeled with what I am guessing is what the file relates to. Some of them are labeled "event" "zeiss" and "gaiden3". Lots of cool images in the game and you can extract a lot of maps. They are ._sn files.

Still no luck on the PSP version.

User avatar
Gu4n
Posts: 125
Joined: Wed Jul 08, 2015 5:25 am

Re: Sora no Kiseki The 3rd Script

Post by Gu4n » Tue Aug 11, 2015 5:52 am

The PSP version is compressed in a way unlike any other Falcom game as far as I know.

The reason I'm looking into this is because there's content within these files that didn't end up in the final game. To be more specific, in the game you can access various side stories (gaiden) through the means of Doors. Each door is part of a celestial body, i.e. Moon (long gaiden), Star (shorter gaiden) and Sun (mini-games). There are 5, 15 and 5 of each, respectively. However, there are a large sum of C_VISxxx.itp files in the /visuals/ folder that did not end up in the game, leading to the believe that there were originally 20 Star Doors. Chinese hackers have been able to re-construct the sixteenth door, which can be seen in this video (spoilers, of course). The Chinese hackers also managed to provide a transcript of Star Door 19, which consists of two visuals (C_VIS312.itp and C_VIS313.itp) and

[major spoilers for SC/3rd]
Spoiler: show
the confrontation between Weissman and Rufina after he got excommunicated from the Septian Church.
As you can see in the /visual/ folder of The 3rd PC, those visual files are present alongside a bunch of others, completing the number range. What struck me as odd, however, is that of all these files associated with the hidden Star Doors (C_VIS302-327), only the two I highlighted above remain of that range of visuals. Since the Chinese hackers managed to provide a transcript of the dialogue hidden under my spoiler and I have searched the entire script for The 3rd PC without luck, I'm positive there must be something within the PSP version. It's just, as you can see, oddly compressed. Also, in the /text/t_title._dt file, it lists all the chapter and door titles but there happen to be five blanked out, fuelling my suspicions that something must remains within the script files.

Considering the contents of that door, it's like a Holy Grail quest for Kiseki.

User avatar
zeromonkey
Hacker, script editor and control freak
Posts: 486
Joined: Thu Mar 05, 2015 3:10 pm
Location: Tennessee

Re: Sora no Kiseki The 3rd Script

Post by zeromonkey » Tue Aug 11, 2015 6:40 pm

There is 425 script files that are uncompressed in the Japanese PC version. Do you want to have a look through those?

User avatar
Gu4n
Posts: 125
Joined: Wed Jul 08, 2015 5:25 am

Re: Sora no Kiseki The 3rd Script

Post by Gu4n » Tue Aug 11, 2015 9:17 pm

zeromonkey wrote:There is 425 script files that are uncompressed in the Japanese PC version. Do you want to have a look through those?
I've gone through them numerous times, but alas, no luck.

User avatar
zeromonkey
Hacker, script editor and control freak
Posts: 486
Joined: Thu Mar 05, 2015 3:10 pm
Location: Tennessee

Re: Sora no Kiseki The 3rd Script

Post by zeromonkey » Tue Aug 11, 2015 10:02 pm

Do you have a link to the hackers site? So far I am coming up with nothing and potentially grabbing at straws.

User avatar
neoxephon
Posts: 10
Joined: Mon Aug 10, 2015 11:27 pm
Location: USA
Contact:

Re: Sora no Kiseki The 3rd Script

Post by neoxephon » Fri Aug 14, 2015 6:05 pm

I've actually been working on reverse engineering the PSP version for the last half week. I'm currently in the process of copying over the decompression routine for the script to a C# program.

I'm making good progress on it, it's just taking me awhile because it spans an entire function (that is long) plus portions of other functions. And it is a huge mess of if conditions and while loops all nestled together, so it can get confusing after awhile. I'm doing all of this because I'm interested in eventually starting up a translation project for the game. This is actually the first I've mentioned about any of this, I don't plan on announcing anything elsewhere until I've gone through all of the files and made certain that a project is possible with my current knowledge.

The main reason I'm saying anything here is because I heard mention elsewhere of a fake compression (I highly doubt that I'll be able to make a compression program, decompression is causing me enough trouble). I'm hoping that if I manage to get the files decompressed, I'll be able to keep them that way (with the obvious downside of increasing the size of the ISO, but that's a small price to pay).

Also, I'm currently at a bit of a roadblock with the decompression routine. Specifically, it does a lwl/lwr and then swl/swr to load and then store two words that are misaligned. I frankly have no idea how to replicate that in my C# program. Any ideas? Those 4 instructions are a vital part of how the game decompresses the script files.

I also have interest in doing the PC version alongside the PSP version. I just started looking at the PC version today.

flamethrower
Programmer
Posts: 790
Joined: Mon Mar 09, 2015 3:03 pm

Re: Sora no Kiseki The 3rd Script

Post by flamethrower » Fri Aug 14, 2015 7:06 pm

I am not a C programmer.
But for C code, there is this thing called file streams. I know this from some work on Excel VBA [Visual Basic for Applications] code, which is a bit like Visual Basic, and it's able to use the file stream objects just like you do in Visual Basic. It has a file that's opened for reading or writing and a pointer. The pointer specifies the place where the file will be read or written to next.
x86 computers don't care about data alignment (I don't think). So all you have to do is write or read the data normally.

Let me see if I can explain it to you:

You have an 8-space memory that looks like:
12345678

You want to load the data 4567, which is misaligned, as a word in register R1.
LWL 0x7 R1 R1 = 7650
LWR 0x4 R1 R1 = 7654

LWL: The address of the most significant byte is specified as the target. All of the bytes of the word that are in the aligned word that contains the target address are loaded. In this case 567 was in the aligned byte containing the address 0x7, and since it's LWL, these bytes get loaded into the most significant part of the target register. I hope that makes sense.

The net effect is to load an unaligned value.

I don't know the standard way of writing data in C#. You basically need to, for each word:
1) Change a number into a list of bytes
2) Reverse the order
3) Write the bytes

There is a library struct in Python that is part of the standard library. There must be an equivalent in C# but I don't know what it is.

Code: Select all

import struct

n = 1
with open('testfile.test','wb') as f:
    f.write(struct.pack('<I',n))
If you decide to try this, the indent is important and doesn't copy correctly from this forum (but does appear correct).

In the above example, '<I' is the format string for the pack. I means unsigned integer, which is 4 bytes long. < means little-endian. So this will convert the number 1 into a series of bytes: 01 00 00 00. It also converts numbers into strings because the write method in the Python standard library wants to consume strings rather than other data types.

User avatar
neoxephon
Posts: 10
Joined: Mon Aug 10, 2015 11:27 pm
Location: USA
Contact:

Re: Sora no Kiseki The 3rd Script

Post by neoxephon » Sun Aug 16, 2015 3:46 am

Thanks for the explanation. I thought it was going to be a little more difficult based on the little information I could find on the instruction. I think I have that part setup now.

I did run into another rare instruction that I haven't had to work with before. It's SEB (sign-extend byte). Specifically, this is the instruction I am working with:

Code: Select all

seb	t0,a1
It's supposed to take the least significant byte from a1, sign-extend it and store the result into t0.

If a1 = 0x000000FF, t0 gets 0xFFFFFFFF
If a1 = 0x00000040, t0 gets 0x00000040

I played a little bit with it in PPSSPP and it seems like if a1 >= 0x80 then t0 gets the 0xFF's instead of the 0x00's. But I'm not sure if that is always the case. I've honestly never had to sign-extend anything and doing a search didn't yield any worthwhile results.

Thanks for the help. I'll keep at it and see if I can figure out how to replicate the results from SEB.

User avatar
M_bot
Programmer
Posts: 98
Joined: Sun Apr 05, 2015 7:18 am
Location: Texas

Re: Sora no Kiseki The 3rd Script

Post by M_bot » Mon Aug 17, 2015 3:54 am

I'll be hijacking your thread monetarily to say that we would love to have you introduce yourself at some point. I'm M_bot, staff programmer here and I program C# and Java. And as you were able to see Flame is also a staff programmer here.

I'm not sure how much of help this will but I've explained what sign extension is below.

Sign extension is the process of increasing the number of bits allocated for a value while preserving both the value and the sign. This is based on the two's complement representation of positive/negative numbers. For example:

Code: Select all

Original Value    Sign Extended to 16 bits
0010 1010         0000 0000 0010 1010
1110 1110         1111 1111 1110 1110
0000 0001         0000 0000 0000 0001
1000 0000         1111 1111 1000 0000
The most significant digit is the sign bit which is copied over into the newly allocated bits.

Not sure if that assembly instruction is doing the same thing though. Based on the name (sign-extend byte) I would say its taking a single byte and sign extending it to the max number of bytes per value. In essence I would say that instruction is doing nothing value wise but rather converting the value to fit the allocated memory size. And I apologize in advance if my explanation is a little too technical, EE/CS major here.

User avatar
Gu4n
Posts: 125
Joined: Wed Jul 08, 2015 5:25 am

Re: Sora no Kiseki The 3rd Script

Post by Gu4n » Thu Dec 17, 2015 10:30 pm

I'm still look into this, but I've hardly made any progress.

I did find a video of a video that made the debug mode accessible in the game.

Read DxD
Posts: 1
Joined: Thu Apr 16, 2015 1:14 pm

Re: Sora no Kiseki The 3rd Script

Post by Read DxD » Fri Sep 16, 2016 3:50 am

Any chance of hacking the 3rd's translation into a PSP Iso? As much as I love this series, If I'm forced to play it on PC, I just dont think I'm gonna do it, its not worth the shoulder surgery it'd cause.

User avatar
Gu4n
Posts: 125
Joined: Wed Jul 08, 2015 5:25 am

Re: Sora no Kiseki The 3rd Script

Post by Gu4n » Mon Sep 19, 2016 9:02 am

Read DxD wrote:Any chance of hacking the 3rd's translation into a PSP Iso? As much as I love this series, If I'm forced to play it on PC, I just dont think I'm gonna do it, its not worth the shoulder surgery it'd cause.
It's easier to connect a controller to your PC.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest