diff options
author | Pixel <Pixel> | 2002-08-18 01:38:23 +0000 |
---|---|---|
committer | Pixel <Pixel> | 2002-08-18 01:38:23 +0000 |
commit | 396239cc78a75ba7be739788485319c92b07d827 (patch) | |
tree | cd3e9ef485c1026e40b909c1989ef662cde30f5f /Xenogears/script-comp.cpp | |
parent | 11bf45f50739afb923829b3cc32efb9c8c009613 (diff) |
Blehaurg
Diffstat (limited to 'Xenogears/script-comp.cpp')
-rw-r--r-- | Xenogears/script-comp.cpp | 105 |
1 files changed, 53 insertions, 52 deletions
diff --git a/Xenogears/script-comp.cpp b/Xenogears/script-comp.cpp index 41fb00b..ee71d8f 100644 --- a/Xenogears/script-comp.cpp +++ b/Xenogears/script-comp.cpp @@ -1,97 +1,98 @@ -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> #include "lzss.h" -#include "fileutils.h" +#include "Input.h" +#include "Output.h" +#include "generic.h" -void process_one_file(FILE * f, FILE * d, int n) { - char nom_du_fichier[100]; +void process_one_file(Handle * f, Handle * d, int n) { + String nom_du_fichier; char zeros[4] = {0, 0, 0, 0}, * datas; long script_position, true_length, delta, data_length; - FILE * f_part; + Handle * f_part; - fprintf(stderr, " Copying header\n"); + printm(M_BARE, " Copying header\n"); - fseek(f, 0x14c, SEEK_SET); - fread(&script_position, 1, 4, f); - fseek(f, 0, SEEK_SET); + f->seek(0x14c); + f->read(&script_position, 4); + f->seek(0); copy(f, d, script_position); - fseek(f, 0x150, SEEK_SET); - fread(&script_position, 1, 4, f); - fseek(f, script_position, SEEK_SET); + f->seek(0x150); + f->read(&script_position, 4); + f->seek(script_position); - data_length = filesize(f) - script_position; + data_length = f->GetSize() - script_position; datas = (char *) malloc(data_length); - fread(datas, 1, data_length, f); + f->read(datas, data_length); - fprintf(stderr, " Processing script\n"); - sprintf(nom_du_fichier, "xeno_d1/ROOMS/%04i/script.comp", n); + printm(M_BARE, " Processing script\n"); + nom_du_fichier = String("xeno_d1/ROOMS/") + n + "/script.comp"; - f_part = fopen(nom_du_fichier, "r"); - true_length = filesize(f_part); + f_part = new Input(nom_du_fichier); + true_length = f_part->GetSize(); - script_position = fseek(d, 0, SEEK_CUR); - fseek(d, 0x14c, SEEK_SET); - fwrite(&script_position, 1, 4, d); - fseek(d, 0x128, SEEK_SET); - fwrite(&true_length, 1, 4, d); - fseek(d, 0, SEEK_END); + script_position = d->seek(0); + d->seek(0x14c); + d->write(&script_position, 4); + d->seek(0x128); + d->write(&true_length, 4); + d->seek(0, SEEK_END); lzss_comp(f_part, d, &delta); + + delete f_part; - fclose(f_part); - - script_position = fseek(d, 0, SEEK_CUR); + script_position = d->tell(); if ((true_length = (script_position & 3))) { - fwrite(zeros, 1, 4 - true_length, d); + d->write(zeros, 4 - true_length); } - fprintf(stderr, " Processing extra datas\n"); - script_position = fseek(d, 0, SEEK_CUR); - fseek(d, 0x150, SEEK_SET); - fwrite(&script_position, 1, 4, d); - fseek(d, 0, SEEK_END); + printm(M_BARE, " Processing extra datas\n"); + script_position = d->tell(); + d->seek(0x150); + d->write(&script_position, 4); + d->seek(0); - fwrite(datas, 1, data_length, d); + d->write(datas, data_length); free(datas); } int main(int argc, char ** argv) { - FILE * f_script_comp, * f_new_script; + Handle * f_script_comp, * f_new_script; int i; int num = 0; - char nom_du_fichier[100]; + String nom_du_fichier; for (i = 384; i < 1844; i = i + 2) { - fprintf(stderr, "CD1 - File %d -> Script %d\n", i, num); - sprintf(nom_du_fichier, "xeno_d1/ROOMS/%04d.out", i); - f_script_comp = fopen(nom_du_fichier, "r"); - sprintf(nom_du_fichier, "xeno_d1/ROOMS/%04d.out-new", i); - f_new_script = fopen(nom_du_fichier, "w"); + printm(M_BARE, "CD1 - File %d -> Script %d\n", i, num); + nom_du_fichier.set("xeno_d1/ROOMS/%04d.out", i); + f_script_comp = new Input(nom_du_fichier); + nom_du_fichier.set("xeno_d1/ROOMS/%04d.out-new", i); + f_new_script = new Output(nom_du_fichier); process_one_file(f_script_comp, f_new_script, num); - fclose(f_script_comp); + delete f_script_comp; + delete f_new_script; num++; } num = 0; for (i = 379; i < 1838; i = i + 2) { - fprintf(stderr, "CD2 - File %d -> Script %d\n", i, num); - sprintf(nom_du_fichier, "xeno_d2/ROOMS/%04d.out", i); - f_script_comp = fopen(nom_du_fichier, "r"); - sprintf(nom_du_fichier, "xeno_d2/ROOMS/%04d.out-new", i); - f_new_script = fopen(nom_du_fichier, "w"); + printm(M_BARE, "CD2 - File %d -> Script %d\n", i, num); + nom_du_fichier.set("xeno_d2/ROOMS/%04d.out", i); + f_script_comp = new Input(nom_du_fichier); + nom_du_fichier.set("xeno_d2/ROOMS/%04d.out-new", i); + f_new_script = new Output(nom_du_fichier); process_one_file(f_script_comp, f_new_script, num); - fclose(f_script_comp); - num++; + delete f_script_comp; + delete f_new_script; + num++; } - fprintf(stderr, "Done !\n"); + printm(M_BARE, "Done !\n"); } |