summaryrefslogtreecommitdiff
path: root/Xenogears
diff options
context:
space:
mode:
authorPixel <Pixel>2002-09-27 12:17:57 +0000
committerPixel <Pixel>2002-09-27 12:17:57 +0000
commitbfa5de7eccf4604ff8217f619e9685a09e80d545 (patch)
treea5be5de750ac611145f459a09bda902c3dbc1a70 /Xenogears
parent60c1003845035ad4cd0e9ea50862bad7626faf0e (diff)
The week-without-the-network changes
Diffstat (limited to 'Xenogears')
-rw-r--r--Xenogears/Decrypt.cpp7
-rwxr-xr-xXenogears/Makefile6
-rw-r--r--Xenogears/main_dump.cpp77
-rw-r--r--Xenogears/reinsert.cpp86
-rw-r--r--Xenogears/script-comp.cpp16
-rw-r--r--Xenogears/script-dec.cpp15
6 files changed, 128 insertions, 79 deletions
diff --git a/Xenogears/Decrypt.cpp b/Xenogears/Decrypt.cpp
index 76289e2..5f606a7 100644
--- a/Xenogears/Decrypt.cpp
+++ b/Xenogears/Decrypt.cpp
@@ -1,6 +1,8 @@
#include<stdio.h>
#include<string.h>
+#include "Main.h"
+CODE_BEGINS
void init_table(long table[5000])
{
long i;
@@ -467,7 +469,7 @@ int decrypt(FILE * f_source, FILE * f_cible, int room_number)
return (0);
}
-int main(void)
+int startup(void) throw (GeneralException)
{
int i;
char file_name[100];
@@ -501,4 +503,7 @@ int main(void)
fclose(f_cible);
}
}
+
+ return 0;
}
+CODE_ENDS
diff --git a/Xenogears/Makefile b/Xenogears/Makefile
index 0f4a0bc..61f4486 100755
--- a/Xenogears/Makefile
+++ b/Xenogears/Makefile
@@ -4,8 +4,10 @@ CPPFLAGS=-Wall -g -O3 -mcpu=i686 -pedantic -pedantic-errors -I../includes -DHAVE
CXX=g++
CC=gcc
-LIBS=-lz -lefence
-LDFLAGS=${LIBS} `pkg-config --libs glib-2.0`
+LIBS=-lz
+#-lefence
+LDFLAGS=${LIBS}
+#`pkg-config --libs glib-2.0`
TARGET = reinsert main_dump Decrypt script-comp script-dec XenoCD1.sqr XenoCD2.sqr compil compil-2
diff --git a/Xenogears/main_dump.cpp b/Xenogears/main_dump.cpp
index e380f7a..4a8cb2e 100644
--- a/Xenogears/main_dump.cpp
+++ b/Xenogears/main_dump.cpp
@@ -32,8 +32,21 @@
#include "generic.h"
#include "Input.h"
#include "Output.h"
+#include "Main.h"
+#include "cdabstract.h"
+
+CODE_BEGINS
+public:
+Appli() : tourne(0), nb_seqs(0), f_def(0), f_iso(0), cdutil(0) {}
+virtual ~Appli() {
+ delete cdutil;
+ delete f_def;
+ delete f_iso;
+ delete f_out;
+}
+private:
-unsigned int tourne = 0;
+unsigned int tourne;
struct t_index_tab {
unsigned long address;
@@ -52,19 +65,16 @@ struct t_sequence {
String title, iso_filename, prefix;
unsigned long iso_size;
-unsigned int nb_records, nb_seqs = 0;
+unsigned int nb_records, nb_seqs;
struct t_sequence sequences[100];
+Handle * f_def, * f_iso, * f_out;
-long check_iso(Handle * f_iso);
-void read_files(Handle * f_iso);
-void file_dump(Handle * f_iso, unsigned long debut, unsigned long taille, long num, int seq);
-int process_def_file(Handle * f_def);
+cdutils * cdutil;
Byte user_data[2352];
-int Main(int argc, char **argv)
+int startup()
{
- Handle * f_def, * f_iso;
verbosity = 3;
@@ -82,8 +92,7 @@ int Main(int argc, char **argv)
f_def = new Input(argv[1]);
- if (process_def_file(f_def)) {
- delete f_def;
+ if (process_def_file()) {
printm(M_ERROR, "Unable to process the definition file \"%s\"...\n", argv[1]);
exit(-1);
}
@@ -91,24 +100,26 @@ int Main(int argc, char **argv)
iso_filename = argv[2];
printm(M_STATUS, "Begin processing iso file.\n");
- f_iso = new Input(iso_filename);
+ f_iso = open_iso(iso_filename);
- if (check_iso(f_iso)) {
+ if (check_iso()) {
printm(M_ERROR, "Invalid iso file for " + title + "\n");
printm(M_ERROR, "===> Make sure you are using a Genuine iso file.\n");
} else {
printm(M_INFO, "Genuine " + title + " iso detected.\n");
}
+
+ cdutil = new cdutils(f_iso);
+
printm(M_STATUS, "Entering files read sequence\n");
- read_files(f_iso);
- delete f_iso;
+ read_files();
exit(0);
}
/*
* Ugly but working... for now
*/
-int process_def_file(Handle * f_def)
+int process_def_file()
{
String t;
unsigned int n, sum = 0;
@@ -157,19 +168,23 @@ int process_def_file(Handle * f_def)
}
}
-long check_iso(Handle * f_iso)
+long check_iso()
{
unsigned long 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;
+ if (length < 0) {
+ printm(M_INFO, "Can not get file size, assuming reading from CD.\n");
+ } else {
+ printm(M_INFO, "Filesize of iso file " + iso_filename + " is %ld bytes\n", length);
+ if (length != iso_size) {
+ return 1;
+ }
}
return 0;
}
-void read_files(Handle * f_iso)
+void read_files()
{
t_index_tab index_tab[10000];
unsigned char t[8];
@@ -183,10 +198,10 @@ void read_files(Handle * f_iso)
#define INDEXPOS 24
- sector_seek(f_iso, INDEXPOS);
+ cdutil->sector_seek(INDEXPOS);
for (i = INDEXPOS; i < (INDEXPOS + 16); i++) {
printm(M_INFO, "Reading fat sector %lu\n", i);
- read_sector(f_iso, &fat[2048 * (i - INDEXPOS)], MODE_2_FORM_1);
+ cdutil->read_sector(&fat[2048 * (i - INDEXPOS)], MODE_2_FORM_1);
}
indexer = 0;
@@ -217,7 +232,7 @@ void read_files(Handle * f_iso)
printm(M_INFO, "%6lu (%10lu): ignored\n", index_tab[i].address, index_tab[i].size);
} else {
printm(M_INFO, "%6lu (%10lu): ", index_tab[i].address, index_tab[i].size);
- file_dump(f_iso, index_tab[i].address, index_tab[i].size, i, seq);
+ file_dump(index_tab[i].address, index_tab[i].size, i, seq);
if (verbosity >= M_INFO) {
fprintf(stderr, "\n");
}
@@ -226,14 +241,13 @@ void read_files(Handle * f_iso)
fprintf(stderr, "\n");
}
-void file_dump(Handle * f_iso, unsigned long debut, unsigned long taille, long num, int seq)
+void file_dump(unsigned long debut, unsigned long taille, long num, int seq)
{
long i;
long nbsects;
String nom;
String extension = ".out";
String nom_t;
- Handle * f_out;
char type = sequences[seq].type;
char ptitbidule[] = "-\\|/";
@@ -252,11 +266,11 @@ void file_dump(Handle * f_iso, unsigned long debut, unsigned long taille, long n
nbsects = taille / sec_sizes[type];
if (taille % sec_sizes[type])
nbsects++;
- sector_seek(f_iso, debut);
+ cdutil->sector_seek(debut);
for (i = 0; i < nbsects; i++) {
if (verbosity < M_INFO)
fprintf(stderr, " (%c)\010\010\010\010\010", ptitbidule[((tourne++) >> 8) % 4]);
- read_sector(f_iso, user_data, type);
+ cdutil->read_sector(user_data, type);
if (i != (nbsects - 1)) {
f_out->write(user_data, sec_sizes[type]);
} else {
@@ -264,13 +278,8 @@ void file_dump(Handle * f_iso, unsigned long debut, unsigned long taille, long n
}
}
delete f_out;
+ f_out = 0;
printm(M_BARE, " (*) Dumped file number %4ld - type \"" + sequences[seq].name + "\" \r", num);
}
-int main(int argc, char ** argv) {
- try {
- Main(argc, argv);
- } catch (GeneralException e) {
- fprintf(stderr, "Main got an unexpected exception: %s\n", e.GetMsg());
- }
-}
+} * Application = new Appli();
diff --git a/Xenogears/reinsert.cpp b/Xenogears/reinsert.cpp
index 440e444..da23033 100644
--- a/Xenogears/reinsert.cpp
+++ b/Xenogears/reinsert.cpp
@@ -6,8 +6,21 @@
#include "generic.h"
#include "Input.h"
#include "Output.h"
+#include "Main.h"
+
+CODE_BEGINS
+public:
+Appli() : tourne(0), nb_seqs(0), f_def(0), f_iso_r(0), f_iso_w(0), f_in(0), cdutil(0), slus_index(-1), force(0) {}
+virtual ~Appli() {
+ delete cdutil;
+ delete f_def;
+ delete f_iso_r;
+ delete f_iso_w;
+ delete f_in;
+}
+private:
-unsigned int tourne = 0;
+unsigned int tourne;
struct t_index_tab {
unsigned long address;
@@ -26,26 +39,23 @@ struct t_sequence {
String title, iso_filename, prefix, in_filename;
unsigned long iso_size;
-unsigned int nb_records, nb_seqs = 0;
+unsigned int nb_records, nb_seqs;
struct t_sequence sequences[1000];
+Handle * f_def, * f_iso_r, * f_iso_w, * f_in;
+cdutils * cdutil;
-int slus_index = -1, force = 0;
-
-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);
+int slus_index, force;
unsigned char user_data[2352];
-void usage(char ** argv) {
+void usage() throw (GeneralException) {
printm(M_BARE, "Usage: %s <definition_file.sqr> <iso_file_name> <file_index> <filename> [-f]\nSee readme.txt for details\n",
argv[0]);
- exit(-1);
+ throw Exit(-1);
}
-int main(int argc, char **argv)
+virtual int startup() throw (GeneralException)
{
- Handle * f_def, * f_iso_r, * f_iso_w, * f_in;
int fileindex;
verbosity = 1;
@@ -53,12 +63,12 @@ int main(int argc, char **argv)
printm(M_BARE, "Xenogears File Insertor by Nicolas \"Pixel\" Noble\n\n");
if ((argc != 5) && (argc != 6)) {
- usage(argv);
+ usage();
}
if (argc == 6) {
if (strcmp(argv[5], "-f")) {
- usage(argv);
+ usage();
} else {
force = 1;
}
@@ -69,9 +79,8 @@ int main(int argc, char **argv)
f_def = new Input(argv[1]);
if (process_def_file(f_def)) {
- delete f_def;
printm(M_ERROR, "Unable to process the definition file \"%s\"...\n", argv[1]);
- exit(-1);
+ throw Exit(-1);
}
iso_filename = argv[2];
@@ -81,10 +90,12 @@ int main(int argc, char **argv)
f_iso_w = new Output(iso_filename, 0, 0);
f_iso_w->seek(0, SEEK_SET);
- if (check_iso(f_iso_r)) {
+ cdutil = new cdutils(f_iso_r, f_iso_w);
+
+ if (check_iso()) {
printm(M_ERROR, "Invalid iso file for " + title + "\n");
printm(M_ERROR, "===> Make sure you are using a Genuine iso file.\n");
- exit(-1);
+ throw Exit(-1);
} else {
printm(M_INFO, "Genuine " + title + " iso detected.\n");
}
@@ -94,10 +105,8 @@ int main(int argc, char **argv)
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);
- delete f_iso_r;
- delete f_iso_w;
- exit(0);
+ write_files(fileindex);
+ return 0;
}
/*
@@ -152,11 +161,11 @@ int process_def_file(Handle * f_def)
}
}
-long check_iso(Handle * f_iso)
+long check_iso()
{
unsigned long length;
- length = f_iso->GetSize();
+ length = f_iso_r->GetSize();
printm(M_INFO, "Filesize of iso file " + iso_filename + " is %ld bytes\n", length);
if (length != iso_size) {
return 1;
@@ -166,31 +175,31 @@ long check_iso(Handle * f_iso)
#define INDEXPOS 24
-void rewrite_fat(Handle * f_iso_r, Handle * f_iso_w, Byte * new_fat) {
+void rewrite_fat(Byte * new_fat) {
unsigned char old_fat[34816];
int i;
- sector_seek(f_iso_w, INDEXPOS);
+ cdutil->sector_seek(INDEXPOS);
for (i = INDEXPOS; i < (INDEXPOS + 16); i++) {
printm(M_INFO, "Writing fat sector %lu\n", i);
- write_sector(f_iso_r, f_iso_w, &new_fat[2048 * (i - INDEXPOS)], MODE_2_FORM_1);
+ cdutil->write_sector(&new_fat[2048 * (i - INDEXPOS)], MODE_2_FORM_1);
}
- sector_seek(f_iso_r, slus_index + 1);
+ cdutil->sector_seek(slus_index + 1);
for (i = slus_index + 1; i < (slus_index + 18); i++) {
printm(M_INFO, "Reading SLUS sector %lu\n", i);
- read_sector(f_iso_r, &old_fat[2048 * (i - slus_index - 1)], MODE_2_FORM_1);
+ cdutil->read_sector(&old_fat[2048 * (i - slus_index - 1)], MODE_2_FORM_1);
}
bcopy((char *) new_fat, (char *) old_fat + 4, 32768);
- sector_seek(f_iso_w, slus_index + 1);
+ cdutil->sector_seek(slus_index + 1);
for (i = slus_index + 1; i < (slus_index + 18); i++) {
printm(M_INFO, "Writing SLUS sector %lu\n", i);
- write_sector(f_iso_r, f_iso_w, &old_fat[2048 * (i - slus_index - 1)], MODE_2_FORM_1);
+ cdutil->write_sector(&old_fat[2048 * (i - slus_index - 1)], MODE_2_FORM_1);
}
}
-void write_files(Handle * f_iso_r, Handle * f_iso_w, Handle * f_in, int fileindex)
+void write_files(int fileindex) throw (GeneralException)
{
t_index_tab index_tab[10000];
unsigned char t[8];
@@ -203,10 +212,10 @@ void write_files(Handle * f_iso_r, Handle * f_iso_w, Handle * f_in, int fileinde
long old_file_size, new_file_size, old_nb_sects, new_nb_sects;
unsigned char fat[32768];
- sector_seek(f_iso_r, INDEXPOS);
+ cdutil->sector_seek(INDEXPOS);
for (i = INDEXPOS; i < (INDEXPOS + 16); i++) {
printm(M_INFO, "Reading fat sector %lu\n", i);
- read_sector(f_iso_r, &fat[2048 * (i - INDEXPOS)], MODE_2_FORM_1);
+ cdutil->read_sector(&fat[2048 * (i - INDEXPOS)], MODE_2_FORM_1);
}
indexer = 0;
@@ -236,7 +245,7 @@ void write_files(Handle * f_iso_r, Handle * f_iso_w, Handle * f_in, int fileinde
if (sequences[seq].prefix == "SLUS") {
if (slus_index >= 0) {
printm(M_ERROR, "Two SLUS files defined\n");
- exit(-1);
+ throw Exit(-1);
}
slus_index = index_tab[i].address;
}
@@ -244,7 +253,7 @@ void write_files(Handle * f_iso_r, Handle * f_iso_w, Handle * f_in, int fileinde
if (slus_index < 0) {
printm(M_ERROR, "No SLUS file defined\n");
- exit(-1);
+ throw Exit(-1);
}
printm(M_INFO, "SLUS file found at sector %6i\n", slus_index);
@@ -266,7 +275,7 @@ void write_files(Handle * f_iso_r, Handle * f_iso_w, Handle * f_in, int fileinde
if (new_nb_sects > old_nb_sects) {
printm(M_ERROR, "New file too big.\n");
if (!force) {
- exit(-1);
+ throw Exit(-1);
}
}
@@ -275,7 +284,8 @@ void write_files(Handle * f_iso_r, Handle * f_iso_w, Handle * f_in, int fileinde
printm(M_INFO, "File address: %6i\n", index_tab[fileindex].address);
- write_file(f_iso_r, f_iso_w, f_in, index_tab[fileindex].type, index_tab[fileindex].address);
+ cdutil->write_file(f_in, index_tab[fileindex].type, index_tab[fileindex].address);
*((long *)(&fat[index_tab[fileindex].index * 7 + 3])) = new_file_size;
- rewrite_fat(f_iso_r, f_iso_w, fat);
+ rewrite_fat(fat);
}
+CODE_ENDS
diff --git a/Xenogears/script-comp.cpp b/Xenogears/script-comp.cpp
index ee71d8f..76eab1d 100644
--- a/Xenogears/script-comp.cpp
+++ b/Xenogears/script-comp.cpp
@@ -2,6 +2,15 @@
#include "Input.h"
#include "Output.h"
#include "generic.h"
+#include "Main.h"
+
+CODE_BEGINS
+public:
+Appli() : lzss_o(new lzss()) {}
+virtual ~Appli() { delete lzss_o; }
+private:
+
+lzss * lzss_o;
void process_one_file(Handle * f, Handle * d, int n) {
String nom_du_fichier;
@@ -38,7 +47,7 @@ void process_one_file(Handle * f, Handle * d, int n) {
d->write(&true_length, 4);
d->seek(0, SEEK_END);
- lzss_comp(f_part, d, &delta);
+ lzss_o->lzss_comp(f_part, d, &delta);
delete f_part;
@@ -58,7 +67,7 @@ void process_one_file(Handle * f, Handle * d, int n) {
free(datas);
}
-int main(int argc, char ** argv)
+virtual int startup() throw (GeneralException)
{
Handle * f_script_comp, * f_new_script;
int i;
@@ -95,4 +104,7 @@ int main(int argc, char ** argv)
num++;
}
printm(M_BARE, "Done !\n");
+
+ return 0;
}
+CODE_ENDS
diff --git a/Xenogears/script-dec.cpp b/Xenogears/script-dec.cpp
index 81dfea3..84e55f0 100644
--- a/Xenogears/script-dec.cpp
+++ b/Xenogears/script-dec.cpp
@@ -5,6 +5,15 @@
#include "String.h"
#include "Input.h"
#include "Output.h"
+#include "Main.h"
+
+CODE_BEGINS
+public:
+Appli() : lzss_o(new lzss()) {}
+virtual ~Appli() { delete lzss_o; }
+private:
+
+lzss * lzss_o;
void process_one_file(Handle * f, int d, int n) {
String nom_du_fichier;
@@ -28,7 +37,7 @@ void process_one_file(Handle * f, int d, int n) {
f->seek(0x10c + i * 4);
f->read(&true_length, 4);
f->seek(script_position);
- lzss_decomp(f, f_out, true_length);
+ lzss_o->lzss_decomp(f, f_out, true_length);
// if (i == 7) {
// fseek(f_out, 0, SEEK_SET);
// fread(&true_length, 4, 1, f_out);
@@ -38,7 +47,7 @@ void process_one_file(Handle * f, int d, int n) {
// }
}
-int main(void)
+int startup()
{
Handle * f_script_comp;
int i;
@@ -69,4 +78,6 @@ int main(void)
num++;
}
printm(M_BARE, "Done !\n");
+ return 0;
}
+CODE_ENDS