Subversion Repositories Games.Descent

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 pmbaty 1
/*
2
 * This file is part of the DXX-Rebirth project <https://www.dxx-rebirth.com/>.
3
 * It is copyright by its individual contributors, as recorded in the
4
 * project's Git history.  See COPYING.txt at the top level for license
5
 * terms and a link to the Git history.
6
 */
7
/*
8
 *  extractD1Data.cpp
9
 *  
10
 *
11
 *  Created by Peter "halprin" Kendall on 8/26/09.
12
 *  Copyright 2009 @PAK Software. All rights reserved.
13
 *
14
 */
15
 
16
#define DEFAULT_INSTALL_LOCATION "/Volumes/Descent/Install Descent"
17
#define CHAOS_HOG_SIZE 0x2AA9F
18
#define CHAOS_HOG_OFFSET 0xAF310
19
#define CHAOS_MSN_REZ_SIZE 0x14C
20
#define CHAOS_MSN_REZ_OFFSET 0xD9E1F
21
#define CHAOS_MSN_SIZE 0x12B
22
#define CHAOS_MSN_OFFSET 0xD9F6B
23
#define DESCENT_HOG_SIZE 0x71C5B3
24
#define DESCENT_HOG_OFFSET 0xDA106
25
#define DESCENT_PIG_SIZE 0x3CA96D
26
#define DESCENT_PIG_OFFSET 0x7F6729
27
 
28
#include <iostream>
29
#include <fstream>
30
#include <string>
31
using namespace std;
32
 
33
void printUsage();
34
 
35
int main(int argc, char **argv)
36
{
37
        string install_location=DEFAULT_INSTALL_LOCATION;
38
 
39
        if(argc>2 || (argc==2 && strcmp(argv[1], "-help")==0))
40
        {
41
                printUsage();
42
                return -1;
43
        }
44
        else if(argc==2)
45
        {
46
                //use a custom location for the installer
47
                install_location=argv[1];
48
        }
49
 
50
        //report what we are doing
51
        cout << endl;
52
        cout << "DETAILS" << endl;
53
        cout << "Installer:  " << install_location << endl;
54
 
55
        ifstream installer(install_location.c_str());
56
        if(!installer)
57
        {
58
                cout << "Error:  Cannot open the installer file." << endl;
59
                cout << "Does it exist at the location specified?"  << endl << endl;
60
                printUsage();
61
                return -2;
62
        }
63
 
64
        //report more on what we are doing
65
        cout << "CHAOS.HOG:" << endl;
66
        cout << "   starts 0x" << hex << uppercase << CHAOS_HOG_OFFSET << endl;
67
        cout << "   size 0x" << hex << uppercase << CHAOS_HOG_SIZE << endl;
68
        cout << "CHAOS.MSN:" << endl;
69
        cout << "   starts 0x" << hex << uppercase << CHAOS_MSN_OFFSET << endl;
70
        cout << "   size 0x" << hex << uppercase << CHAOS_MSN_SIZE << endl;
71
        cout << "CHAOS.MSN resource fork:" << endl;
72
        cout << "   starts 0x" << hex << uppercase << CHAOS_MSN_REZ_OFFSET << endl;
73
        cout << "   size 0x" << hex << uppercase << CHAOS_MSN_REZ_SIZE << endl;
74
        cout << "descent.hog:" << endl;
75
        cout << "   starts 0x" << hex << uppercase << DESCENT_HOG_OFFSET << endl;
76
        cout << "   size 0x" << hex << uppercase << DESCENT_HOG_SIZE << endl;
77
        cout << "descent.pig:" << endl;
78
        cout << "   starts 0x" << hex << uppercase << DESCENT_PIG_OFFSET << endl;
79
        cout << "   size 0x" << hex << uppercase << DESCENT_PIG_SIZE << endl;
80
        cout << endl;
81
 
82
        char* chaos_hog_buffer=(char*)malloc(CHAOS_HOG_SIZE);
83
        char* chaos_msn_rez_buffer=(char*)malloc(CHAOS_MSN_REZ_SIZE);
84
        char* chaos_msn_buffer=(char*)malloc(CHAOS_MSN_SIZE);
85
        char* descent_hog_buffer=(char*)malloc(DESCENT_HOG_SIZE);
86
        char* descent_pig_buffer=(char*)malloc(DESCENT_PIG_SIZE);
87
 
88
        ofstream chaos_hog_file("CHAOS.HOG");
89
        if(!chaos_hog_file)
90
        {
91
                cout << "Error:  Unable to create new CHAOS.HOG file.  Skipping!" << endl;
92
        }
93
        ofstream chaos_msn_file("CHAOS.MSN");
94
        if(!chaos_msn_file)
95
        {
96
                cout << "Error:  Unable to create new CHAOS.MSN file.  Skipping!" << endl;
97
        }
98
        ofstream chaos_msn_rez_file("CHAOS.MSN/..namedfork/rsrc");
99
        if(!chaos_msn_rez_file)
100
        {
101
                cout << "Error:  Unable to create the resource fork of the CHAOS.MSN file.  Skipping!" << endl;
102
        }
103
        ofstream descent_hog_file("descent.hog");
104
        if(!descent_hog_file)
105
        {
106
                cout << "Error:  Unable to create new descent.hog file.  Skipping!" << endl;
107
        }
108
        ofstream descent_pig_file("descent.pig");
109
        if(!descent_pig_file)
110
        {
111
                cout << "Error:  Unable to create new descent.pig file.  Skipping!" << endl;
112
        }
113
 
114
        //read the CHAOS.HOG file
115
        installer.ignore(CHAOS_HOG_OFFSET);
116
        installer.read(chaos_hog_buffer, CHAOS_HOG_SIZE);
117
        //write the CHAOS.HOG file
118
        chaos_hog_file.write(chaos_hog_buffer, CHAOS_HOG_SIZE);
119
 
120
        //read the CHAOS.MSN file's resource fork
121
        installer.ignore(CHAOS_MSN_REZ_OFFSET-(CHAOS_HOG_OFFSET+CHAOS_HOG_SIZE));
122
        installer.read(chaos_msn_rez_buffer, CHAOS_MSN_REZ_SIZE);
123
        //write the CHAOS.MSN file's resource fork
124
        chaos_msn_rez_file.write(chaos_msn_rez_buffer, CHAOS_MSN_REZ_SIZE);
125
 
126
        //read the CHAOS.MSN file
127
        installer.ignore(CHAOS_MSN_OFFSET-(CHAOS_MSN_REZ_OFFSET+CHAOS_MSN_REZ_SIZE));
128
        installer.read(chaos_msn_buffer, CHAOS_MSN_SIZE);
129
        //write the CHAOS.MSN file
130
        chaos_msn_file.write(chaos_msn_buffer, CHAOS_MSN_SIZE);
131
 
132
        //read the descent.hog file
133
        installer.ignore(DESCENT_HOG_OFFSET-(CHAOS_MSN_OFFSET+CHAOS_MSN_SIZE));
134
        installer.read(descent_hog_buffer, DESCENT_HOG_SIZE);
135
        //write the descent.hog file
136
        descent_hog_file.write(descent_hog_buffer, DESCENT_HOG_SIZE);
137
 
138
        //read the descent.pig file
139
        installer.ignore(DESCENT_PIG_OFFSET-(DESCENT_HOG_OFFSET+DESCENT_HOG_SIZE));
140
        installer.read(descent_pig_buffer, DESCENT_PIG_SIZE);
141
        //write the descent.pig file
142
        descent_pig_file.write(descent_pig_buffer, DESCENT_PIG_SIZE);
143
 
144
 
145
        //Done!
146
        cout << "Extraction complete!" << endl << endl;
147
 
148
        free(chaos_hog_buffer);
149
        free(chaos_msn_rez_buffer);
150
        free(chaos_msn_buffer);
151
        free(descent_hog_buffer);
152
        free(descent_pig_buffer);
153
 
154
        chaos_hog_file.close();
155
        chaos_msn_file.close();
156
        chaos_msn_rez_file.close();
157
        descent_hog_file.close();
158
        descent_pig_file.close();
159
 
160
        return 0;
161
}
162
 
163
void printUsage()
164
{
165
        cout << "Usage:  ./d1Extract <Path to Descent installer>" << endl;
166
        cout << "If <Path to Descent installer> is not specified, the default \"" << DEFAULT_INSTALL_LOCATION << "\" will be used." << endl << endl;
167
}