xoreos / xoreos-tools

Tools to help the development of xoreos
https://xoreos.org/
GNU General Public License v3.0
66 stars 28 forks source link

NCSDIS: NCS Decompiler #34

Closed Nostritius closed 5 years ago

Nostritius commented 5 years ago

For solving the problem with the first carth dialog in kotor I extended ncsdis with a decompiler which is able to translate ncs files back into a nss file the already analyzed information. This PR contains all my work on this matter. There are also multiple points which are still open like missing while loops. As i will most likely not work any further on this, i wan't to provide my work so someone might take this up.

DrMcCoy commented 5 years ago

Ooh, very nice :D

But I rather think that should be a new executable ("ncsdecomp"?) instead of added into ncsdis, and also a decompiler class "over"/"around" the disassembler class. There's potentially more analysis and transforms a decompiler needs to do.

For example, variable deduplication, which, I think, your code doesn't yet do?

Nostritius commented 5 years ago

Ok, but this almost likely means I have to do another PR. There is definitely more analysis necessary, for example i desperately need information about which variable is returned by a retn opcode or if a subroutine returns a value. Variable deduplication is also a problem, just a simple excerpt from a decompiled source code to depict the problem:

int local180 = GetLocalBoolean(local179, local178);
int local171 = local180;
int local181 = local171;
int local182 = 0;
int local183 = local182 > local181;

As i said this is mostly stuff i hacked together some months ago to solve the carth dialog problem.

DrMcCoy commented 5 years ago

I mean, you could just move things into a Decompiler class and ncsdecomp tool, and then force-push to your branch to update this PR. It's still the same thing, so I'd still count it, logically, as the same PR.

The further analysis and further work, yes, that's something for later PRs building upon your work here, sure. I didn't mean to imply that you have to do this either, since you said you'd likely not continue work on this. :)