summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xMakefile2
-rwxr-xr-xVP/Makefile5
-rw-r--r--VP/search-script.cpp73
-rw-r--r--Xenogears/Decrypt.cpp11
4 files changed, 82 insertions, 9 deletions
diff --git a/Makefile b/Makefile
index 95a09bf..c330d89 100755
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,6 @@
#!/usr/bin/make -f
-CPPFLAGS=-Wall -g -O3 -mcpu=i686 -pedantic -pedantic-errors -Werror -I.
+CPPFLAGS=-Wall -g -O3 -mcpu=i686 -pedantic -pedantic-errors -Werror
CXX=g++
SUBDIRS = psxdev Xenogears VP MegamanX5
diff --git a/VP/Makefile b/VP/Makefile
index 9e723d3..13a540e 100755
--- a/VP/Makefile
+++ b/VP/Makefile
@@ -3,7 +3,7 @@
CPPFLAGS=-Wall -g -O3 -mcpu=i686 -pedantic -pedantic-errors -Werror -I..
CXX=g++
-TARGET = main_dump VP-CD1.sqr decomp-slz unarc
+TARGET = main_dump VP-CD1.sqr decomp-slz unarc search-script
all: ${TARGET}
@@ -16,6 +16,9 @@ decomp-slz: decomp-slz.o ../fileutils.o ../fileutils.h ../generic.o ../generic.h
unarc: unarc.o ../fileutils.o ../fileutils.h ../generic.o ../generic.h Makefile
${CXX} ${LDFLAGS} unarc.o ../fileutils.o ../generic.o -o unarc
+search-script: search-script.o ../fileutils.o ../fileutils.h ../generic.o ../generic.h Makefile
+ ${CXX} ${LDFLAGS} search-script.o ../fileutils.o ../generic.o -o search-script
+
clean:
rm -f *.o ${TARGET}
diff --git a/VP/search-script.cpp b/VP/search-script.cpp
new file mode 100644
index 0000000..263bc49
--- /dev/null
+++ b/VP/search-script.cpp
@@ -0,0 +1,73 @@
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include "fileutils.h"
+#include "generic.h"
+
+#define THRESHOLD 2000
+
+int main(int argc, char ** argv) {
+ int h, n, o, i, p, c, pp, b;
+
+ verbosity = M_INFO;
+
+ if (argc != 2) {
+ printm(M_BARE, "Usage: search-script <file>\n");
+ exit(-1);
+ }
+
+ if ((h = open(argv[1], O_RDONLY)) < 0) {
+ printm(M_ERROR, "Error opening file %s\n", argv[1]);
+ exit(-1);
+ }
+
+ printm(M_STATUS, "Reading informations...\n");
+
+ read(h, &n, 4);
+
+ o = n;
+
+ n -= 4;
+ n /= 8;
+
+ printm(M_INFO, "Script claims to have %i texts.\n", n);
+
+ if (n > THRESHOLD) {
+ printm(M_ERROR, "Too much texts to make sense.\n");
+ exit(-1);
+ }
+
+ printm(M_STATUS, "Reading index.\n");
+
+ pp = -1;
+ for (i = 0; i < n; i++) {
+ lseek(h, i * 8 + 4, SEEK_SET);
+ read(h, &c, 4);
+ read(h, &p, 4);
+ printm(M_INFO, "Index #%i has pointer %i and counter %i\n", i, p, c);
+ if (pp > p) {
+ printm(M_ERROR, "Script's text overlapping.\n");
+ exit(-1);
+ }
+
+ if (((unsigned int)(p + o)) > filesize(h)) {
+ printm(M_ERROR, "Text bigger than script.\n");
+ exit(-1);
+ }
+
+ lseek(h, p + o - 1, SEEK_SET);
+ b = 0;
+ read(h, &b, 1);
+
+ if (b) {
+ printm(M_ERROR, "Byte before the pointer is not 0 (%i = 0x%02x)\n", b, b);
+ exit(-1);
+ }
+
+ pp = p;
+ }
+
+ printm(M_STATUS, "Script seems ok to me.\n");
+
+ exit(0);
+}
diff --git a/Xenogears/Decrypt.cpp b/Xenogears/Decrypt.cpp
index 2f4d99f..76289e2 100644
--- a/Xenogears/Decrypt.cpp
+++ b/Xenogears/Decrypt.cpp
@@ -52,14 +52,11 @@ void dump_text(FILE * f_source, FILE * f_cible, long table[5000], long script_nu
{
long next;
unsigned char val;
- char temp_string[2];
+ char temp_string[2] = {0, 0};
long position;
unsigned char temp1 = 0;
unsigned char temp2 = 0;
- long temp;
-
- temp_string[1] = NULL;
-
+
next = found_next(table, script_number, max_script);
fseek(f_source, table[script_number], SEEK_SET);
@@ -86,7 +83,7 @@ void dump_text(FILE * f_source, FILE * f_cible, long table[5000], long script_nu
} else if (val == 0x03) // "<Wait>"
{
fprintf(f_cible, "<Wait>");
- } else if (val == 0x0F) // "<Delay X>
+ } else if (val == 0x0F) // Extended opcode. Reads two more bytes.
{
fread((unsigned char *) &temp1, 1, 1, f_source);
fread((unsigned char *) &temp2, 1, 1, f_source);
@@ -435,7 +432,7 @@ int decrypt(FILE * f_source, FILE * f_cible, int room_number)
script_number = (script_number++);
- fprintf(f_cible, "<Blocks:%i>\n", script_number);
+ fprintf(f_cible, "<Blocks:%li>\n", script_number);
init_table(table);
i = j = 0;