From 11bf45f50739afb923829b3cc32efb9c8c009613 Mon Sep 17 00:00:00 2001 From: Pixel Date: Sat, 17 Aug 2002 01:48:34 +0000 Subject: Working with Baltisot now.... --- Xenogears/Makefile | 13 ++++-- Xenogears/reinsert.cpp | 121 ++++++++++++++++++++----------------------------- 2 files changed, 58 insertions(+), 76 deletions(-) (limited to 'Xenogears') diff --git a/Xenogears/Makefile b/Xenogears/Makefile index 4fec754..50cc0f4 100755 --- a/Xenogears/Makefile +++ b/Xenogears/Makefile @@ -4,23 +4,26 @@ CPPFLAGS=-Wall -g -O3 -mcpu=i686 -pedantic -pedantic-errors -I../includes CXX=g++ CC=gcc +LIBS=-lz +LDFLAGS=${LIBS} + TARGET = reinsert main_dump Decrypt script-comp script-dec XenoCD1.sqr XenoCD2.sqr compil compil-2 all: ${TARGET} -main_dump: main_dump.o ../includes/cdutils.h ../includes/fileutils.h ../includes/generic.h ../includes/yazedc.h ../lib/lib.a ../generic/generic.a Makefile +main_dump: main_dump.o ../includes/cdutils.h ../includes/generic.h ../includes/yazedc.h ../lib/lib.a ../generic/generic.a Makefile ${CXX} ${LDFLAGS} main_dump.o ../lib/lib.a ../generic/generic.a -o main_dump -reinsert: reinsert.o ../includes/cdutils.h ../includes/fileutils.h ../includes/generic.h ../includes/yazedc.h ../lib/lib.a ../generic/generic.a Makefile +reinsert: reinsert.o ../includes/cdutils.h ../includes/generic.h ../includes/yazedc.h ../lib/lib.a ../generic/generic.a Makefile ${CXX} ${LDFLAGS} reinsert.o ../lib/lib.a ../generic/generic.a -o reinsert -Decrypt: Decrypt.o ../includes/fileutils.h ../includes/generic.h ../generic/generic.a Makefile +Decrypt: Decrypt.o ../includes/generic.h ../generic/generic.a Makefile ${CXX} ${LDFLAGS} Decrypt.o ../generic/generic.a -o Decrypt -script-comp: script-comp.o ../includes/fileutils.h ../includes/generic.h ../includes/lzss.h ../lib/lib.a ../generic/generic.a Makefile +script-comp: script-comp.o ../includes/generic.h ../includes/lzss.h ../lib/lib.a ../generic/generic.a Makefile ${CXX} ${LDFLAGS} script-comp.o ../lib/lib.a ../generic/generic.a -o script-comp -script-dec: script-dec.o ../includes/fileutils.h ../includes/generic.h ../includes/lzss.h ../lib/lib.a ../generic/generic.a Makefile +script-dec: script-dec.o ../includes/generic.h ../includes/lzss.h ../lib/lib.a ../generic/generic.a Makefile ${CXX} ${LDFLAGS} script-dec.o ../lib/lib.a ../generic/generic.a -o script-dec compil: compil.o diff --git a/Xenogears/reinsert.cpp b/Xenogears/reinsert.cpp index d6e0a4c..1227fcc 100644 --- a/Xenogears/reinsert.cpp +++ b/Xenogears/reinsert.cpp @@ -2,9 +2,10 @@ #include #include #include -#include "fileutils.h" #include "cdutils.h" #include "generic.h" +#include "Input.h" +#include "Output.h" unsigned int tourne = 0; @@ -18,38 +19,38 @@ struct t_index_tab { struct t_sequence { unsigned int n; unsigned int sum; - char *prefix; - char *name; + String prefix; + String name; int type; }; -char *title, *iso_filename, *prefix, *in_filename; +String title, iso_filename, prefix, in_filename; unsigned long iso_size; unsigned int nb_records, nb_seqs = 0; struct t_sequence sequences[1000]; int slus_index = -1, force = 0; -long check_iso(int f_iso); -void write_files(int f_iso_r, int f_iso_w, int f_in, int fileindex); -int process_def_file(int f_def); +long check_iso(Handle * f_iso); +void write_files(Handle * f_iso_r, Handle * f_iso_w, Handle * f_in, int fileindex); +int process_def_file(Handle * f_def); unsigned char user_data[2352]; void usage(char ** argv) { - fprintf(stderr, "Usage: %s [-f]\nSee readme.txt for details\n", + printm(M_BARE, "Usage: %s [-f]\nSee readme.txt for details\n", argv[0]); exit(-1); } int main(int argc, char **argv) { - int f_def, f_iso_r, f_iso_w, f_in; + Handle * f_def, * f_iso_r, * f_iso_w, * f_in; int fileindex; verbosity = 1; - fprintf(stderr, "Xenogears File Insertor by Nicolas \"Pixel\" Noble\n\n"); + printm(M_BARE, "Xenogears File Insertor by Nicolas \"Pixel\" Noble\n\n"); if ((argc != 5) && (argc != 6)) { usage(argv); @@ -65,13 +66,10 @@ int main(int argc, char **argv) printm(M_STATUS, "Processing file %s...\n", argv[1]); - if ((f_def = open(argv[1], O_RDONLY)) < 0) { - printm(M_ERROR, "Unable to open the definition file \"%s\"...\n", argv[1]); - exit(-1); - } + f_def = new Input(argv[1]); if (process_def_file(f_def)) { - close(f_def); + delete f_def; printm(M_ERROR, "Unable to process the definition file \"%s\"...\n", argv[1]); exit(-1); } @@ -79,74 +77,58 @@ int main(int argc, char **argv) iso_filename = argv[2]; printm(M_STATUS, "Begin processing iso file.\n"); - if ((f_iso_r = open(iso_filename, O_RDONLY)) < 0) { - printm(M_ERROR, "Unable to open the iso file \"%s\"...\n", iso_filename); - exit(-1); - } - - if ((f_iso_w = open(iso_filename, O_WRONLY)) < 0) { - printm(M_ERROR, "Unable to open the iso file \"%s\"...\n", iso_filename); - exit(-1); - } - - if (lseek(f_iso_w, 0, SEEK_SET)) { - printm(M_ERROR, "Can't rewind the file\n"); - exit(-1); - } + f_iso_r = new Input(iso_filename); + f_iso_w = new Output(iso_filename, 0, 0); + f_iso_w->seek(0, SEEK_SET); if (check_iso(f_iso_r)) { - printm(M_ERROR, "Invalid iso file for %s\n", title); + printm(M_ERROR, "Invalid iso file for " + title + "\n"); printm(M_ERROR, "===> Make sure you are using a Genuine iso file.\n"); exit(-1); } else { - printm(M_INFO, "Genuine %s iso detected.\n", title); + printm(M_INFO, "Genuine " + title + " iso detected.\n"); } fileindex = atoi(argv[3]); in_filename = argv[4]; - if ((f_in = open(in_filename, O_RDONLY)) < 0) { - printm(M_ERROR, "Unable to open the file \"%s\"...\n", in_filename); - exit(-1); - } + f_in = new Input(in_filename); printm(M_STATUS, "Entering files write sequence\n"); write_files(f_iso_r, f_iso_w, f_in, fileindex); - close(f_iso_r); - close(f_iso_w); + delete f_iso_r; + delete f_iso_w; exit(0); } /* * Ugly but working... for now */ -int process_def_file(int ff_def) +int process_def_file(Handle * f_def) { - char t[1024], *p; - FILE * f_def = fdopen(ff_def, "r"); unsigned int n, sum = 0; + String t; - if ((p = strchr(fgets(t, 1024, f_def), '\n')) == NULL) - return 1; - *p = 0; - printm(M_INFO, "Read title: %s\n", t); - title = strdup(t); + *f_def >> t; + printm(M_INFO, "Read title: " + t + "\n"); + title = t; - if (fscanf(f_def, "%lu\n", &iso_size) != 1) + *f_def >> t; + if (sscanf(t.to_charp(), "%lu\n", &iso_size) != 1) return 1; printm(M_INFO, "Read iso size: %lu bytes\n", iso_size); - if ((p = strchr(fgets(t, 1024, f_def), '\n')) == NULL) - return 1; - *p = 0; - printm(M_INFO, "Read global directory prefix: %s\n", t); - prefix = strdup(t); + *f_def >> t; + printm(M_INFO, "Read global directory prefix: " + t + "\n"); + prefix = t; - if (fscanf(f_def, "%u\n", &nb_records) != 1) + *f_def >> t; + if (sscanf(t.to_charp(), "%u\n", &nb_records) != 1) return 1; printm(M_INFO, "Read total of records: %u\n", nb_records); while (1) { - if (fscanf(f_def, "%u\n", &n) != 1) + *f_def >> t; + if (sscanf(t.to_charp(), "%u\n", &n) != 1) return 1; if (!n) { if (sum == nb_records) { @@ -160,29 +142,26 @@ int process_def_file(int ff_def) sum += n; sequences[nb_seqs].n = n; sequences[nb_seqs].sum = sum; - if ((p = strchr(fgets(t, 1024, f_def), '\n')) == NULL) - return 1; - *p = 0; - sequences[nb_seqs].prefix = strdup(t); - if (fscanf(f_def, "%u\n", &n) != 1) + *f_def >> t; + sequences[nb_seqs].prefix = t; + *f_def >> t; + if (sscanf(t.to_charp(), "%u\n", &n) != 1) return 1; sequences[nb_seqs].type = n; - if ((p = strchr(fgets(t, 1024, f_def), '\n')) == NULL) - return 1; - *p = 0; - sequences[nb_seqs].name = strdup(t); - printm(M_INFO, "Read definition of sequence %i:\n===> %5i (sum = %5i) chunks of %s (%s)\n", - nb_seqs, n, sum, t, sequences[nb_seqs].prefix); + *f_def >> t; + sequences[nb_seqs].name = t; + printm(M_INFO, "Read definition of sequence %i:\n===> %5i (sum = %5i) chunks of " + t + + " (" + sequences[nb_seqs].prefix + ")\n", nb_seqs, n, sum); nb_seqs++; } } -long check_iso(int f_iso) +long check_iso(Handle * f_iso) { unsigned long length; - length = filesize(f_iso); - printm(M_INFO, "Filesize of iso file %s is %ld bytes\n", iso_filename, length); + length = f_iso->GetSize(); + printm(M_INFO, "Filesize of iso file " + iso_filename + " is %ld bytes\n", length); if (length != iso_size) { return 1; } @@ -191,7 +170,7 @@ long check_iso(int f_iso) #define INDEXPOS 24 -void rewrite_fat(int f_iso_r, int f_iso_w, unsigned char * new_fat) { +void rewrite_fat(Handle * f_iso_r, Handle * f_iso_w, Byte * new_fat) { unsigned char old_fat[34816]; int i; @@ -215,7 +194,7 @@ void rewrite_fat(int f_iso_r, int f_iso_w, unsigned char * new_fat) { } } -void write_files(int f_iso_r, int f_iso_w, int f_in, int fileindex) +void write_files(Handle * f_iso_r, Handle * f_iso_w, Handle * f_in, int fileindex) { t_index_tab index_tab[10000]; unsigned char t[8]; @@ -258,7 +237,7 @@ void write_files(int f_iso_r, int f_iso_w, int f_in, int fileindex) if (sequences[seq].sum == i) seq++; index_tab[i].type = sequences[seq].type; - if (!strcmp(sequences[seq].prefix, "SLUS")) { + if (sequences[seq].prefix == "SLUS") { if (slus_index >= 0) { printm(M_ERROR, "Two SLUS files defined\n"); exit(-1); @@ -274,7 +253,7 @@ void write_files(int f_iso_r, int f_iso_w, int f_in, int fileindex) printm(M_INFO, "SLUS file found at sector %6i\n", slus_index); - new_file_size = filesize(f_in); + new_file_size = f_in->GetSize(); old_file_size = index_tab[fileindex].size; new_nb_sects = new_file_size / sec_sizes[index_tab[fileindex].type]; -- cgit v1.2.3