summaryrefslogtreecommitdiff
path: root/VP
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 /VP
parent60c1003845035ad4cd0e9ea50862bad7626faf0e (diff)
The week-without-the-network changes
Diffstat (limited to 'VP')
-rwxr-xr-xVP/Makefile7
-rw-r--r--VP/decomp-slz.cpp52
-rw-r--r--VP/main_dump.cpp82
-rw-r--r--VP/unarc.cpp41
4 files changed, 104 insertions, 78 deletions
diff --git a/VP/Makefile b/VP/Makefile
index 27af592..815eb9d 100755
--- a/VP/Makefile
+++ b/VP/Makefile
@@ -1,9 +1,12 @@
#!/usr/bin/make -f
-CPPFLAGS=-Wall -g -O3 -mcpu=i686 -pedantic -pedantic-errors -Werror -I../includes
+CPPFLAGS=-Wall -g -O3 -mcpu=i686 -pedantic -pedantic-errors -Werror -I../includes -DHAVE_ZLIB
CXX=g++
-TARGET = main_dump VP-CD1.sqr decomp-slz unarc search-script
+LIBS=-lz
+LDFLAGS=${LIBS}
+
+TARGET = main_dump VP-CD1.sqr decomp-slz unarc
all: ${TARGET}
diff --git a/VP/decomp-slz.cpp b/VP/decomp-slz.cpp
index fa09411..076d3bd 100644
--- a/VP/decomp-slz.cpp
+++ b/VP/decomp-slz.cpp
@@ -2,56 +2,62 @@
#include <stdlib.h>
#include "lzss.h"
-#include "fileutils.h"
-#include "generic.h"
+#include "Input.h"
+#include "Output.h"
+#include "Main.h"
-int main(int argc, char ** argv) {
+CODE_BEGINS
+public:
+Appli() : lzss_o(new lzss) {}
+virtual ~Appli() {
+ delete lzss_o;
+}
+private:
+
+lzss * lzss_o;
+
+virtual int startup() throw (GeneralException) {
int sig, l, d, v;
- FILE * fin = stdin, * fout = stdout;
+ Handle * fin = &Stdin, * fout = &Stdout;
switch (argc) {
case 3:
- if (!(fout = fopen(argv[2], "w"))) {
- printm(M_ERROR, "Error opening file %s.\n", argv[3]);
- exit(-1);
- }
+ fout = new Output(argv[2]);
case 2:
- if (!(fin = fopen(argv[1], "r"))) {
- printm(M_ERROR, "Error opening file %s.\n", argv[2]);
- exit(-1);
- }
+ fin = new Input(argv[1]);
break;
case 1:
break;
default:
printm(M_BARE, "Usage: %s [filein] [fileout]\n", argv[0]);
- exit(-1);
+ return -1;
}
verbosity = M_STATUS;
- fread(&sig, 1, 4, fin);
- fread(&d, 1, 4, fin);
- fread(&l, 1, 4, fin);
+ fin->read(&sig, 4);
+ fin->read(&d, 4);
+ fin->read(&l, 4);
switch (sig) {
case 0x05a4c53:
printm(M_STATUS, "Detected a SLZ-type 0 file.\n");
- fread(&v, 1, 4, fin);
+ fin->read(&v, 4);
copy(fin, fout, d);
- exit(0);
+ return 0;
case 0x15a4c53:
- scheme = schemes[VP_1];
+ lzss_o->change_scheme(lzss_o->schemes[lzss_o->VP_1]);
printm(M_STATUS, "Detected a SLZ-type 1 file.\n");
break;
case 0x25a4c53:
- scheme = schemes[VP_2];
+ lzss_o->change_scheme(lzss_o->schemes[lzss_o->VP_2]);
printm(M_STATUS, "Detected a SLZ-type 2 file.\n");
break;
default:
printm(M_ERROR, "Not a SLZ file.\n");
- exit(-1);
+ return -1;
}
- lzss_decomp(fin, fout, l);
- exit(0);
+ lzss_o->lzss_decomp(fin, fout, l);
+ return 0;
}
+CODE_ENDS
diff --git a/VP/main_dump.cpp b/VP/main_dump.cpp
index 0845e1a..421db66 100644
--- a/VP/main_dump.cpp
+++ b/VP/main_dump.cpp
@@ -33,8 +33,21 @@
#include "Input.h"
#include "Output.h"
#include "String.h"
+#include "Main.h"
+#include "cdabstract.h"
+
+CODE_BEGINS
+public:
+Appli() : tourne(0), nb_seqs(0), f_def(0), f_iso(0), f_out(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;
@@ -53,20 +66,15 @@ 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[1000];
-
-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);
+Handle * f_def, * f_iso, * f_out;
+cdutils * cdutil;
unsigned char user_data[2352];
-int main(int argc, char **argv)
+virtual int startup() throw (GeneralException)
{
- Handle * f_def, * f_iso;
-
verbosity = M_STATUS;
fprintf(stderr,
@@ -76,40 +84,41 @@ int main(int argc, char **argv)
if (argc != 3) {
fprintf(stderr, "Usage: %s <definition_file.sqr> <iso_file_name>\nSee readme.txt for details\n",
argv[0]);
- exit(-1);
+ throw Exit(-1);
}
printm(M_STATUS, "Processing file %s...\n", argv[1]);
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);
+ throw Exit(-1);
}
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;
- exit(0);
+ read_files();
+ throw 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;
@@ -153,19 +162,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 long i;
@@ -178,10 +191,10 @@ void read_files(Handle * f_iso)
#define INDEXPOS 150
- sector_seek(f_iso, INDEXPOS);
+ cdutil->sector_seek(INDEXPOS);
for (i = INDEXPOS; i < (INDEXPOS + 10); 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);
}
memcpy(key, fat + 0x4f00, 256);
@@ -197,7 +210,7 @@ void read_files(Handle * f_iso)
m = fat[j];
s = fat[j + 1];
f = fat[j + 2];
- index_tab[indexer].address = from_MSF(m, s, f);
+ index_tab[indexer].address = cdutil->from_MSF(m, s, f);
if (m || s || f) {
index_tab[indexer].index = j / 4;
index_tab[indexer].flags = fat[j + 3];
@@ -224,7 +237,7 @@ void read_files(Handle * f_iso)
printm(M_INFO, "%6lu - %02x: ", index_tab[i].address, index_tab[i].flags);
size = index_tab[i + 1].address - index_tab[i].address;
size *= sec_sizes[index_tab[i].type];
- file_dump(f_iso, index_tab[i].address, size, i, seq);
+ file_dump(index_tab[i].address, size, i, seq);
if (verbosity >= M_INFO) {
fprintf(stderr, "\n");
}
@@ -233,12 +246,11 @@ 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;
- Handle * f_out;
char type = sequences[seq].type;
char ptitbidule[] = "-\\|/";
@@ -248,17 +260,17 @@ void file_dump(Handle * f_iso, unsigned long debut, unsigned long taille, long n
nom += sequences[seq].prefix + "/";
MKDIR(nom.to_charp());
- nom += String("%04ld.out", num);
+ nom += String().set("%04ld.out", num);
f_out = new Output(nom);
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 {
@@ -266,5 +278,7 @@ 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);
}
+CODE_ENDS
diff --git a/VP/unarc.cpp b/VP/unarc.cpp
index 5699260..7a22c48 100644
--- a/VP/unarc.cpp
+++ b/VP/unarc.cpp
@@ -2,14 +2,18 @@
#include <stdlib.h>
#include <unistd.h>
-#include "fileutils.h"
+#include "Input.h"
+#include "Output.h"
#include "generic.h"
+#include "Main.h"
#define THRESHOLD 2000
-int main(int argc, char ** argv) {
- int h, o, n, * index, * sizes, i, d;
- char temp[100];
+CODE_BEGINS
+int startup() {
+ int n, * index, * sizes, i, d;
+ String temp;
+ Handle * h, * o;
verbosity = M_INFO;
@@ -18,12 +22,9 @@ int main(int argc, char ** argv) {
exit(-1);
}
- if ((h = open(argv[1], O_RDONLY)) < 0) {
- printm(M_ERROR, "Unable to open archive file: %s\n", argv[1]);
- exit(-1);
- }
+ h = new Input(argv[1]);
- read(h, &n, 4);
+ h->read(&n, 4);
printm(M_STATUS, "Archive claims to have %i files, checking integrity.\n", n);
@@ -36,8 +37,8 @@ int main(int argc, char ** argv) {
sizes = (int *) malloc(n * sizeof(int));
for (i = 0; i < n; i++) {
- lseek(h, (i + 1) * 8 + 4, SEEK_SET);
- read(h, &(sizes[i]), 4);
+ h->seek((i + 1) * 8 + 4, SEEK_SET);
+ h->read(&(sizes[i]), 4);
printm(M_INFO, "File #%i size = %i = 0x%08x\n", i, sizes[i], sizes[i]);
}
@@ -50,9 +51,9 @@ int main(int argc, char ** argv) {
printm(M_INFO, "Index #%i = %i = 0x%08x\n", i, index[i], index[i]);
}
- d = filesize(h) - index[n - 1] - sizes[n - 1];
+ d = h->GetSize() - index[n - 1] - sizes[n - 1];
- printm(M_INFO, "Archive size: %i, last index: %i, last file size: %i, difference = %i\n", filesize(h), index[n - 1], sizes[n - 1], d);
+ printm(M_INFO, "Archive size: %i, last index: %i, last file size: %i, difference = %i\n", h->GetSize(), index[n - 1], sizes[n - 1], d);
if ((d < 0) || (d > 2048)) {
printm(M_ERROR, "Archive incoherent.\n");
@@ -62,15 +63,17 @@ int main(int argc, char ** argv) {
printm(M_STATUS, "Archive seems to be ok, extracting.\n");
for (i = 0; i < n; i++) {
- sprintf(temp, "%04i.out", i);
- o = open(temp, O_WRONLY | O_CREAT | O_TRUNC, 0666);
+ temp.set("%04i.out", i);
+ o = new Output(temp);
- printm(M_INFO, "Extracting %s\n", temp);
+ printm(M_INFO, "Extracting " + temp + "\n");
- lseek(h, index[i], SEEK_SET);
+ h->seek(index[i], SEEK_SET);
copy(h, o, sizes[i]);
- close(o);
+ delete o;
}
- exit(0);
+ delete h;
+ return 0;
}
+CODE_ENDS