summaryrefslogtreecommitdiff
path: root/Xenogears/script-comp.cpp
blob: 76eab1d27e91799080e6569b5b30bf4ee9322634 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#include "lzss.h"
#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;
    char zeros[4] = {0, 0, 0, 0}, * datas;
    long script_position, true_length, delta, data_length;
    Handle * f_part;
    
    printm(M_BARE, "  Copying header\n");
    
    f->seek(0x14c);
    f->read(&script_position, 4);
    f->seek(0);
    copy(f, d, script_position);
    
    f->seek(0x150);
    f->read(&script_position, 4);
    f->seek(script_position);
    
    data_length = f->GetSize() - script_position;
    
    datas = (char *) malloc(data_length);
    f->read(datas, data_length);
    
    printm(M_BARE, "  Processing script\n");
    nom_du_fichier = String("xeno_d1/ROOMS/") + n + "/script.comp";

    f_part = new Input(nom_du_fichier);
    true_length = f_part->GetSize();

    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_o->lzss_comp(f_part, d, &delta);

    delete f_part;	
	
    script_position = d->tell();
    if ((true_length = (script_position & 3))) {
        d->write(zeros, 4 - true_length);
    }
    
    printm(M_BARE, "  Processing extra datas\n");
    script_position = d->tell();
    d->seek(0x150);
    d->write(&script_position, 4);
    d->seek(0);
    
    d->write(datas, data_length);
    
    free(datas);
}

virtual int startup() throw (GeneralException)
{
    Handle * f_script_comp, * f_new_script;
    int i;
    int num = 0;
    String nom_du_fichier;

    for (i = 384; i < 1844; i = i + 2) {
	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);

	delete f_script_comp;
	delete f_new_script;
	num++;
    }
    num = 0;
    

    for (i = 379; i < 1838; i = i + 2) {
	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);

	delete f_script_comp;
	delete f_new_script;
    	num++;
    }
    printm(M_BARE, "Done !\n");
    
    return 0;
}
CODE_ENDS