summaryrefslogtreecommitdiff
path: root/MegamanX5/unarc.cpp
blob: ea5e498f99baf4d55a02cc7e636f862895bcd501 (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
#include <stdlib.h>
#include "generic.h"
#include "Input.h"
#include "Output.h"
#include "Main.h"

CODE_BEGINS
virtual int startup() throw (GeneralException) {
    Handle * f, * o;
    
    int i = 0;
    
    f = new Input(argv[1]);
    
    int offset = 0;
    while (1) {
	int sector, size;
	f->seek(offset, SEEK_SET);
	f->read(&sector, 4);
	f->read(&size, 4);
	offset += 8;
	
	if (!sector)
	    break;
	
	f->seek(sector <<= 9, SEEK_SET);
	
	String fname;
	fname.set("unarc-%03i.out", i);
	o = new Output(fname);
	copy(f, o, size);
	delete o;
	i++;
    }
    
    delete f;
    
    return -1;
}
CODE_ENDS