diff options
author | pixel <pixel> | 2003-09-05 23:50:16 +0000 |
---|---|---|
committer | pixel <pixel> | 2003-09-05 23:50:16 +0000 |
commit | 44adf768555ecd211f90cbf4d87b44ba42044d86 (patch) | |
tree | 662018d76d3f2f19ed58ea8e94c54445fc2a47e4 /PE/reinsert.cpp | |
parent | 7ff77f49e9577ff5b63d7f2e2ce7651257bf1d63 (diff) |
Continuing toying
Diffstat (limited to 'PE/reinsert.cpp')
-rw-r--r-- | PE/reinsert.cpp | 151 |
1 files changed, 151 insertions, 0 deletions
diff --git a/PE/reinsert.cpp b/PE/reinsert.cpp new file mode 100644 index 0000000..660e81e --- /dev/null +++ b/PE/reinsert.cpp @@ -0,0 +1,151 @@ +#include <Exceptions.h> +#include <Input.h> +#include <Output.h> +#include <Main.h> +#include "cdutils.h" + +#define index 0x838da + +#define offset 0x83b78 + +CODE_BEGINS +virtual int startup() throw (GeneralException) { + Handle * ir; + Handle * iw; + cdutils * cd; + + ir = new Input("PE1.bin"); + iw = new Output("PE1.bin", 0, 0); + cd = new cdutils(ir, iw); + + printm(M_INFO, "Patch du CD1\n"); + patch_img(cd); + + delete cd; + delete iw; + delete ir; + + ir = new Input("PE2.bin"); + iw = new Output("PE2.bin", 0, 0); + cd = new cdutils(ir, iw); + printm(M_INFO, "Patch du CD2\n"); + patch_img(cd); + + delete cd; + delete iw; + delete ir; + + return 0; +} + +int patch_img(cdutils * cd) { + struct cdutils::DirEntry d_slus, d_pe1; + unsigned char * slus; + int i, j, c, fontei; + String s; + int groupes[100][20]; + int counts[20]; + + verbosity = M_INFO; + + d_slus = cd->find_path("/SLUS_006.62;1"); + + if (!d_slus.Sector) + d_slus = cd->find_path("/SLUS_006.68;1"); + + d_pe1 = cd->find_path("/PE.IMG;1"); + + slus = (unsigned char *) malloc(d_slus.Size); + + cd->read_datas(slus, GUESS, d_slus.Sector, d_slus.Size); + + fontei = *((short *)(slus + index + 18)); + Handle * fonte = new Input("fonte.tim"); + printm(M_INFO, "Ecriture de la fonte...\n"); + cd->write_file(fonte, GUESS, fontei + d_pe1.Sector); + delete fonte; + + Handle * pslus = new Input("PE-SLUS00662-patched.exe"); + printm(M_INFO, "Ecriture du SLUS...\n"); + cd->write_file(pslus, GUESS, d_slus.Sector); + delete pslus; + + Handle * menu = new Input("69/0069.out"); + printm(M_INFO, "Ecriture du menu...\n"); + cd->write_file(menu, GUESS, d_pe1.Sector + 978); + delete menu; + + for (i = 1; i <= 20; i++) { + Input groupe(String().set("groupe-%02i.txt", i)); + c = 0; + while (1) { + groupe >> s; + if (!s.strlen()) + break; + groupes[c++][i] = s.to_int(); + } + counts[i] = c; + } + + for (i = 1; i <= 20; i++) { + Handle * f = new Input(String().set("scripts/c/%02i.out", i)); + unsigned char * script = (unsigned char *) malloc(f->GetSize()); + f->read(script, f->GetSize()); + printm(M_INFO, "Groupe %i...\n", i); + for (c = 0; c < counts[i]; c++) { + int sector, s1, s2, s3, r, size, size2, ptr, tptr, sig, jptr, sizes[2]; + r = groupes[c][i]; + unsigned char * room; + + sector = *((int *) (slus + offset + r * 8)); + s1 = *(slus + offset + r * 8 + 4); + s2 = *(slus + offset + r * 8 + 5) | ((*(slus + offset + r * 8 + 6) & 0x0f) << 8); + s3 = ((*(slus + offset + r * 8 + 6) & 0xf0) >> 4) | (*(slus + offset + r * 8 + 7) << 4); + + cd->read_datas((unsigned char *) sizes, GUESS, d_pe1.Sector + sector + s1 + s2, 8); + size = sizes[0]; + size2 = sizes[1]; + + room = (unsigned char *) malloc(size); + cd->read_datas(room, GUESS, d_pe1.Sector + sector + s1 + s2, size); + + ptr = size - 4; + while (1) { + tptr = *((int *) (room + ptr)); + if ((tptr >> 24) == 1) { + tptr &= 0xffffff; + sig = *((int *) (room + tptr)); + if ((sig & 0xffff) == 0xfe) { + break; + } + } + ptr -= 4; + } + + jptr = *((int *) (room + ptr - 8)); + + printm(M_INFO, " Room %i\n", r); + + if (size2 < (jptr + f->GetSize())) { + printm(M_ERROR, "size2 = %i, jptr = %i, f = %i, + = %i - script trop gros.\n", size2, jptr, f->GetSize(), jptr + f->GetSize()); + exit(-1); + } + + memcpy(room + jptr, script, f->GetSize()); + + *((int *) (room + ptr)) = jptr | 0x01000000; + + cd->write_datas(room, GUESS, d_pe1.Sector + sector + s1 + s2, size); + + free(room); + } + delete f; + free(script); + } + + free(slus); + + return 0; +} + +CODE_ENDS |