From 83473b5e976c94eb1692e8d35d77b61cf57c97f9 Mon Sep 17 00:00:00 2001 From: pixel Date: Sun, 14 Dec 2003 21:14:07 +0000 Subject: Fixing things... --- FAQ-cd.txt | 194 ++++++++++++++++++------------------- Makefile | 5 +- PE/Makefile | 2 +- PE/extract-rooms.cpp | 6 +- PE/pe-hack.lua | 268 +++++++++++++++++++++++++++++++++++++++++++++++++++ lib/cdreader.cpp | 4 +- lib/luacd.cpp | 8 +- 7 files changed, 378 insertions(+), 109 deletions(-) create mode 100644 PE/pe-hack.lua diff --git a/FAQ-cd.txt b/FAQ-cd.txt index 1583b85..afd5fae 100644 --- a/FAQ-cd.txt +++ b/FAQ-cd.txt @@ -701,9 +701,9 @@ A: First of all, my LUA distribution is the 5.0, slightly modified. The basic This will copy the directory entry into the called DirTree, except the sector and size attributes. - :setbasicxa() + :setbasicsxa() - Will set the basic XA attribute. dir:setbasicxa() is equivalent to the + Will set the basic XA attribute. dir:setbasicsxa() is equivalent to the following piece of code: dir.have_xa = true @@ -849,13 +849,13 @@ A: First of all, my LUA distribution is the 5.0, slightly modified. The basic Okay, I presented everything. Now for a quick and simple example of use. This LUA script, when used with the cd-tool's luapatch command, will act exactly like the cd-tool's copy command: - - dir = cdutil:findpath "/" - rsize = dir.Size - - iso:foreword(cdutil) - pvd = createpvd(cdutil) - root = iso:setbasics(pvd, rsize / 2048) + + dir = cdutil:findpath "/" + rsize = dir.Size + + iso:foreword(cdutil) + pvd = createpvd(cdutil) + root = iso:setbasics(pvd, rsize / 2048) iso:copydir(root, cdutil, cdutil:findpath "/") buf = Buffer() @@ -869,91 +869,91 @@ A: First of all, my LUA distribution is the 5.0, slightly modified. The basic Q: What patch did you applied to the LUA compiler? A: Only one of my own, to add support for hex and octal numbers. Here it is: -diff -u -r1.1 llex.c ---- src/llex.c 6 Nov 2003 11:56:07 -0000 -+++ src/llex.c 19 Nov 2003 23:03:35 -0000 -@@ -172,15 +172,34 @@ - - /* LUA_NUMBER */ - static void read_numeral (LexState *LS, int comma, SemInfo *seminfo) { -+ int oct = 0, hex = 0; - size_t l = 0; - checkbuffer(LS, l); - if (comma) save(LS, '.', l); -- while (isdigit(LS->current)) { -+ else if (LS->current == '0') { -+ oct = 1; -+ checkbuffer(LS, 1); -+ save_and_next(LS, l); -+ if (LS->current == 'x') { -+ oct = 0; -+ hex = 1; -+ checkbuffer(LS, 1); -+ save_and_next(LS, l); -+ } -+ } -+ while (isdigit(LS->current) || (hex && isxdigit(LS->current))) { - checkbuffer(LS, l); - save_and_next(LS, l); - } -+ checkbuffer(LS, 1); - if (LS->current == '.') { - save_and_next(LS, l); -+ if (hex || oct) { -+ save(LS, '\0', l); -+ luaX_lexerror(LS, -+ "error in number, mixing decimal point with octal or hexadecimal", -+ TK_NUMBER); -+ } - if (LS->current == '.') { - save_and_next(LS, l); - save(LS, '\0', l); -@@ -195,6 +214,12 @@ - } - if (LS->current == 'e' || LS->current == 'E') { - save_and_next(LS, l); /* read `E' */ -+ if (hex || oct) { -+ save(LS, '\0', l); -+ luaX_lexerror(LS, -+ "error in number, mixing exponential with octal or hexadecimal", -+ TK_NUMBER); -+ } - if (LS->current == '+' || LS->current == '-') - save_and_next(LS, l); /* optional exponent sign */ - while (isdigit(LS->current)) { -diff -u -r1.1 lobject.c ---- src/lobject.c 6 Nov 2003 11:56:07 -0000 -+++ src/lobject.c 19 Nov 2003 23:03:35 -0000 -@@ -20,13 +20,6 @@ - #include "lstring.h" - #include "lvm.h" - -- --/* function to convert a string to a lua_Number */ --#ifndef lua_str2number --#define lua_str2number(s,p) strtod((s), (p)) --#endif -- -- - const TObject luaO_nilobject = {LUA_TNIL, {NULL}}; - - -@@ -91,7 +84,17 @@ - - int luaO_str2d (const char *s, lua_Number *result) { - char *endptr; -- lua_Number res = lua_str2number(s, &endptr); -+ size_t l = strlen(s); -+ lua_Number res; -+ if ((l > 0) && (s[0] == '0')) { -+ if ((l > 2) && (s[1] == 'x')) { -+ res = strtol(s + 2, &endptr, 16); -+ } else { -+ res = strtol(s + 1, &endptr, 8); -+ } -+ } else { -+ res = strtod(s, &endptr); -+ } - if (endptr == s) return 0; /* no conversion */ - while (isspace((unsigned char)(*endptr))) endptr++; - if (*endptr != '\0') return 0; /* invalid trailing characters? */ +diff -u -r1.1 llex.c +--- src/llex.c 6 Nov 2003 11:56:07 -0000 ++++ src/llex.c 19 Nov 2003 23:03:35 -0000 +@@ -172,15 +172,34 @@ + + /* LUA_NUMBER */ + static void read_numeral (LexState *LS, int comma, SemInfo *seminfo) { ++ int oct = 0, hex = 0; + size_t l = 0; + checkbuffer(LS, l); + if (comma) save(LS, '.', l); +- while (isdigit(LS->current)) { ++ else if (LS->current == '0') { ++ oct = 1; ++ checkbuffer(LS, 1); ++ save_and_next(LS, l); ++ if (LS->current == 'x') { ++ oct = 0; ++ hex = 1; ++ checkbuffer(LS, 1); ++ save_and_next(LS, l); ++ } ++ } ++ while (isdigit(LS->current) || (hex && isxdigit(LS->current))) { + checkbuffer(LS, l); + save_and_next(LS, l); + } ++ checkbuffer(LS, 1); + if (LS->current == '.') { + save_and_next(LS, l); ++ if (hex || oct) { ++ save(LS, '\0', l); ++ luaX_lexerror(LS, ++ "error in number, mixing decimal point with octal or hexadecimal", ++ TK_NUMBER); ++ } + if (LS->current == '.') { + save_and_next(LS, l); + save(LS, '\0', l); +@@ -195,6 +214,12 @@ + } + if (LS->current == 'e' || LS->current == 'E') { + save_and_next(LS, l); /* read `E' */ ++ if (hex || oct) { ++ save(LS, '\0', l); ++ luaX_lexerror(LS, ++ "error in number, mixing exponential with octal or hexadecimal", ++ TK_NUMBER); ++ } + if (LS->current == '+' || LS->current == '-') + save_and_next(LS, l); /* optional exponent sign */ + while (isdigit(LS->current)) { +diff -u -r1.1 lobject.c +--- src/lobject.c 6 Nov 2003 11:56:07 -0000 ++++ src/lobject.c 19 Nov 2003 23:03:35 -0000 +@@ -20,13 +20,6 @@ + #include "lstring.h" + #include "lvm.h" + +- +-/* function to convert a string to a lua_Number */ +-#ifndef lua_str2number +-#define lua_str2number(s,p) strtod((s), (p)) +-#endif +- +- + const TObject luaO_nilobject = {LUA_TNIL, {NULL}}; + + +@@ -91,7 +84,17 @@ + + int luaO_str2d (const char *s, lua_Number *result) { + char *endptr; +- lua_Number res = lua_str2number(s, &endptr); ++ size_t l = strlen(s); ++ lua_Number res; ++ if ((l > 0) && (s[0] == '0')) { ++ if ((l > 2) && (s[1] == 'x')) { ++ res = strtol(s + 2, &endptr, 16); ++ } else { ++ res = strtol(s + 1, &endptr, 8); ++ } ++ } else { ++ res = strtod(s, &endptr); ++ } + if (endptr == s) return 0; /* no conversion */ + while (isspace((unsigned char)(*endptr))) endptr++; + if (*endptr != '\0') return 0; /* invalid trailing characters? */ diff --git a/Makefile b/Makefile index a14beea..8e16c69 100755 --- a/Makefile +++ b/Makefile @@ -4,8 +4,9 @@ CPPFLAGS=-Wall -g -O3 -mcpu=i686 -Iincludes `sdl-config --cflags` -DHAVE_ZLIB `b LDFLAGS=-lz `sdl-config --libs` `baltisot-config --libs` CXX=g++ -SUBDIRS = psxdev lib Xenogears VP MegamanX5 -TARGET = lzss dlzss cd-tool str-player crypto-search bgrep tile-convert mipspoke +#SUBDIRS = psxdev lib Xenogears VP MegamanX5 +SUBDIRS = psxdev lib PE +TARGET = lzss dlzss cd-tool str-player crypto-search bgrep tile-convert all: subdirs ${TARGET} diff --git a/PE/Makefile b/PE/Makefile index 2d404ab..1444f44 100644 --- a/PE/Makefile +++ b/PE/Makefile @@ -9,7 +9,7 @@ LIBS=-lz -lefence LDFLAGS=${LIBS} `baltisot-config --libs` #`pkg-config --libs glib-2.0` -TARGET = reinsert compil extract extract-various extract-rooms +TARGET = compil extract extract-various extract-rooms all: ${TARGET} diff --git a/PE/extract-rooms.cpp b/PE/extract-rooms.cpp index 738411d..a23026f 100644 --- a/PE/extract-rooms.cpp +++ b/PE/extract-rooms.cpp @@ -15,7 +15,7 @@ struct entry { #define fullsize 206213120 #define offset 0x83b78 -#define N 437 +#define N 438 CODE_BEGINS struct entry tab[N]; @@ -43,8 +43,8 @@ virtual int startup() throw (GeneralException) { tab[i].sizes[0] = te.u[0]; tab[i].sizes[1] = te.u[1] | ((te.u[2] & 0xf) << 8); tab[i].sizes[2] = (te.u[2] >> 4) | (te.u[3] << 4); - printm(M_INFO, "entry %3i - offset: %9i, sizes = %4i %4i %4i\n", i, tab[i].sector * 2048, - tab[i].sizes[0], tab[i].sizes[1], tab[i].sizes[2]); + printm(M_INFO, "entry %3i - offset: %9i, sizes = %4i %4i %4i (%02x %02x %02x %02x)\n", i, tab[i].sector * 2048, + tab[i].sizes[0], tab[i].sizes[1], tab[i].sizes[2], te.u[0], te.u[1], te.u[2], te.u[3]); } delete f; diff --git a/PE/pe-hack.lua b/PE/pe-hack.lua new file mode 100644 index 0000000..97f1ec2 --- /dev/null +++ b/PE/pe-hack.lua @@ -0,0 +1,268 @@ +slus_hacks = { + +-- ASM Ptr hack + [0x1603c] = { 0xbc }, + +-- ASM Font hack + [0x284e4] = { 0x21 }, + [0x28540] = { 0x21, 0x18, 0x00, 0x00 }, + [0x28fb8] = { 0x21, 0x18, 0x00, 0x00 }, + [0x29074] = { 0x00, 0x00, 0x00 }, + + +-- Text "Susceptible to poison" + [0x81c96] = { 0x25, 0x34, 0x3d, 0x38, 0x3c, 0x34, 0x44, 0x47, + 0xff }, + +-- Text "Susceptible to acid" + [0x81cc0] = { 0x14, 0x3c, 0x3f, 0x3e, 0x38, 0x42, 0x3e, 0x3d, + 0x3d, 0x34, 0x0f, 0x3f, 0x30, 0x41, 0x0f, 0x30, + 0x32, 0x38, 0x33, 0x34, 0xff }, + +-- Text "Easily tranquilized" + [0x81ce8] = { 0x22, 0x34, 0x3d, 0x42, 0x38, 0x31, 0x3b, 0x34, + 0x0f, 0x30, 0x44, 0x47, 0x0f, 0x43, 0x41, 0x30, + 0x3d, 0x40, 0x44, 0x38, 0x3b, 0x38, 0x42, 0x30, + 0x3d, 0x43, 0x42, 0xff }, + +-- Text "Sensitive to heat" + [0x81d0e] = { 0x22, 0x34, 0x3d, 0x42, 0x38, 0x31, 0x3b, 0x34, + 0x0f, 0x51, 0x0f, 0x3b, 0x30, 0x0f, 0x32, 0x37, + 0x30, 0x3b, 0x34, 0x44, 0x41, 0xff }, + +-- Text "Sensitive to cold" + [0x81d32] = { 0x22, 0x34, 0x3d, 0x42, 0x38, 0x31, 0x3b, 0x34, + 0x0f, 0x30, 0x44, 0x0f, 0x35, 0x41, 0x3e, 0x38, + 0x33, 0xff }, + +-- Text "Objects easily stolen" + [0x81d5a] = { 0x1f, 0x3e, 0x42, 0x42, 0x4e, 0x33, 0x34, 0x0f, + 0x33, 0x34, 0x42, 0x0f, 0x3e, 0x31, 0x39, 0x34, + 0x43, 0x42, 0x0f, 0x51, 0x0f, 0x45, 0x3e, 0x3b, + 0x34, 0x41, 0xff }, + +-- Text "Gets confused easily" + [0x81d85] = { 0x12, 0x3e, 0x3d, 0x35, 0x44, 0x42, 0x38, 0x3e, + 0x3d, 0x0f, 0x3f, 0x3e, 0x42, 0x42, 0x38, 0x31, + 0x3b, 0x34, 0x0f, 0x34, 0x43, 0x0f, 0x34, 0x35, + 0x35, 0x38, 0x32, 0x30, 0x32, 0x34, 0xff }, + +-- Text "Failed to escape" + [0x81dad] = { 0x15, 0x44, 0x38, 0x43, 0x34, 0x0f, 0x4d, 0x32, + 0x37, 0x44, 0x4d, 0x34, 0xff }, + +-- Text "Can't escape!" + [0x81dca] = { 0x15, 0x44, 0x38, 0x43, 0x34, 0x0f, 0x38, 0x3c, + 0x3f, 0x3e, 0x42, 0x42, 0x38, 0x31, 0x3b, 0x34, + 0x2b, 0xff }, + + +-- Font width table + [0x81ea1] = { 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 6, 6, 8, 11, 14, + 9, 8, 7, 8, 7, 7, 8, 9, 6, 7, 9, 8, 11, 9, 7, 8, + 7, 9, 7, 7, 9, 9, 11, 7, 9, 7, 9, 4, 7, 6, 4, 4, + 8, 8, 7, 7, 7, 7, 8, 9, 5, 4, 8, 5, 11, 9, 7, 8, + 8, 7, 6, 5, 9, 9, 11, 7, 9, 6, 4, 4, 7, 7, 7, 7, + 7, 7, 7, 7, 5, 5, 7, 7, 9, 9, 9, 7, 11, 11, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, + +-- PE.BIN filename extension + [0x01b4c] = { 0x54, 0x49, 0x4d }, +} + +function apply_hacks(hacks, file) + local k, v, i, h + for k, v in pairs(slus_hacks) do + for i, h in ipairs(v) do + file[k + i - 1] = h + end + end +end + +function mainpatch() + local dirent, pvd, root, is_cd1, is_cd2, slusname, fmvdir, systemcnfstring, inslus, slus, peimg, pesect, tim, startsect, fmvdirtree + + dirent = cdutil:findpath "/SLUS_006.62;1" or cdutil:findpath "/SLUS_006.68;1" or error "Not a Parasite Eve CD" + + iso:foreword(cdutil) + pvd = createpvd(cdutil) + + print "Identifying CD..." + if (dirent.id == "SLUS_006.62;1") then + print "CD is Parasite Eve CD1" + pvd.volid = "PARASITE_EVE_FRANCAIS_CD1" + slusname = "PE-FR.CD1" + fmvdir = "FMV1" + is_cd1 = true + is_cd2 = false + else + print "CD is Parasite Eve CD2" + pvd.volid = "PARASITE_EVE_FRANCAIS_CD2" + slusname = "PE-FR.CD2" + fmvdir = "FMV2" + is_cd1 = false + is_cd2 = true + end + root = iso:setbasics(pvd) + + systemcnfstring = "BOOT=cdrom:\\" .. slusname .. [[;1 +TCB=4 +EVENT=16 +STACK=801fff00 +]] + + systemcnf = Buffer() + systemcnf:write(systemcnfstring) + iso:createfile(root, "SYSTEM.CNF", systemcnf, dirent) + + print "Reading CD's slus file" + inslus = cdfile(cdutil, dirent) + slus = Buffer(true) + slus:copyfrom(inslus) + apply_hacks(slus_hacks, slus) + + dirent = cdutil:findpath "/" + root:setbasicsxa() + root:fromdir(dirent) + + dirent = cdutil:findpath "/PE.IMG;1" + pesect = dirent.Sector + peimg = cdfile(cdutil, dirent) + tim = Buffer() + peimg:copyto(tim, 0x23800) + startsect = iso:createfile(root, "PE.TIM", tim, dirent).sector + print "Compiling IMG file" + do_img_file(slus, startsect, pesect) + + print "Writing final main file" + slus:seek(0) + iso:createfile(root, slusname, slus):setbasicsxa() + + print "Copying FMV directory" + dirent = cdutil:findpath("/" .. fmvdir) + fmvdirtree = iso:createdir(root, fmvdir, 1, dirent) +-- fmvdirtree.hardhide = true + iso:copydir(fmvdirtree, cdutil, dirent) + + print "Finalizing CD" + iso:createfile(root, "README.TXT", Input("readme.txt")):setbasicsxa() + + iso:close() +end + +function do_img_file(slus, startsect, pesect) + local i, j, sect1, tab1, sect2, tab2, sect3, tab3, sizes1, sizes2, sizes3, sect, file, file1, file2, file3, songsect, b1, b2, b3, b4, lastsect, s1, s2, s3 + + sect1 = {} + tab1 = {} + sect2 = {} + tab2 = {} + sect3 = {} + tab3 = {} + sizes1 = {} + sizes2 = {} + sizes3 = {} + + + print "Putting various files" + slus:seek(0x838da) + for i = 1, 80, 1 do + sect1[i] = slus:readU16() + pesect + end + for i = 1, 79, 1 do +-- print(i) + file = cdfile(cdutil, sect1[i], (sect1[i + 1] - sect1[i]) * 2048) + s1 = iso:putfile(file) + tab1[i] = s1 - startsect + print("Putting file " .. i .. " from sector " .. sect1[i] .. " to sector " .. s1) + end + tab1[80] = iso:getdispsect() - startsect + songsect = tab1[80] + + print "Putting musics" + slus:seek(0x83980) + for i = 1, 251, 1 do + sect2[i] = slus:readU16() + sect1[80] + end + for i = 1, 250, 1 do +-- print(i) + file = nil + if ((sect2[i + 1] - sect2[i]) ~= 0) then + file = cdfile(cdutil, sect2[i], (sect2[i + 1] - sect2[i]) * 2048) + end + if (file) then + s1 = iso:putfile(file) + end + tab2[i] = s1 - startsect - songsect + print("Putting music " .. i .. " from sector " .. sect2[i] .. " to sector " .. s1) + end + tab2[251] = iso:getdispsect() - startsect - songsect + + + print "Putting rooms" + slus:seek(0x83b78) + for i = 1, 438, 1 do + sect3[i] = slus:readU32() + pesect + b1 = slus:readU8() + b2 = slus:readU8() + b3 = slus:readU8() + b4 = slus:readU8() + sizes1[i] = b1 + sizes2[i] = orB(b2, (shl(andB(b3, 0x0f), 8))) + sizes3[i] = orB(shr(b3, 4), shl(b4, 4)) + end + for i = 1, 438, 1 do +-- print(i) + file1 = nil + file2 = nil + file3 = nil + if (sizes1[i] ~= 0) then + print("File " .. i .. " from sector " .. sect3[i]) + file1 = cdfile(cdutil, sect3[i], sizes1[i] * 2048) + end + if (sizes2[i] ~= 0) then + print("File " .. i .. " from sector " .. sect3[i] + sizes1[i]) + file2 = cdfile(cdutil, sect3[i] + sizes1[i], sizes2[i] * 2048) + end + if (sizes3[i] ~= 0) then + print("File " .. i .. " from sector " .. sect3[i] + sizes1[i] + sizes2[i]) + file3 = cdfile(cdutil, sect3[i] + sizes1[i] + sizes2[i], sizes3[i] * 2048) + end + + s1 = iso:getdispsect() - startsect + if (file1) then + print("Put file " .. i .. " at " .. s1) + iso:putfile(file1) + end + s2 = iso:getdispsect() - startsect + if (file2) then + iso:putfile(file2) + end + s3 = iso:getdispsect() - startsect + if (file3) then + iso:putfile(file3) + end + tab3[i] = s1 + sizes1[i] = s2 - s1 + sizes2[i] = s3 - s2 + sizes3[i] = iso:getdispsect() - s3 + end + + slus:wseek(0x838da) + for i = 1, 80, 1 do + slus:writeU16(tab1[i]) + end + slus:writeU16(0) + slus:writeU16(songsect) + slus:writeU16(0) + for i = 1, 251, 1 do + slus:writeU16(tab2[i]) + end + + slus:wseek(0x83b78) +end + +mainpatch() diff --git a/lib/cdreader.cpp b/lib/cdreader.cpp index 058dddc..3de92c0 100644 --- a/lib/cdreader.cpp +++ b/lib/cdreader.cpp @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* $Id: cdreader.cpp,v 1.17 2003-12-11 16:53:43 pixel Exp $ */ +/* $Id: cdreader.cpp,v 1.18 2003-12-14 21:14:08 pixel Exp $ */ #include #include @@ -194,7 +194,7 @@ cdreader::cdreader(const String & no) throw (GeneralException) : int i; #ifdef DEBUG - printm(M_ERROR, "Opening cdrom device " + no + "\n"); + printm(M_INFO, "Opening cdrom device " + no + "\n"); #endif if (GetHandle() < 0) { diff --git a/lib/luacd.cpp b/lib/luacd.cpp index 0e10af1..471c8a2 100644 --- a/lib/luacd.cpp +++ b/lib/luacd.cpp @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* $Id: luacd.cpp,v 1.6 2003-12-12 12:45:20 pixel Exp $ */ +/* $Id: luacd.cpp,v 1.7 2003-12-14 21:14:08 pixel Exp $ */ #include "luacd.h" @@ -860,7 +860,7 @@ void LuaPVD::pushstatics(Lua * L) throw (GeneralException) { } int sLua_PVD::PVD_proceed(Lua * L, int n, PVD * pvd, int caller) { - int r = 0, key_i, value_i; + int r = 0, key_i = 0, value_i; String key_s, value_s; cddate * value_date; bool invalid = false, keyisstring; @@ -870,9 +870,9 @@ int sLua_PVD::PVD_proceed(Lua * L, int n, PVD * pvd, int caller) { key_i = L->tonumber(2); } else { keyisstring = true; - key_s = L->tonumber(2); + key_s = L->tostring(2); } - + switch (caller) { case PVD_INDEX: r = 1; -- cgit v1.2.3