Subversion Repositories Games.Carmageddon

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 pmbaty 1
#include "errors.h"
2
#include "cutscene.h"
3
#include "globvars.h"
4
#include "graphics.h"
5
#include "harness/config.h"
6
#include "harness/trace.h"
7
#include "network.h"
8
#include "pd/sys.h"
9
#include "utility.h"
10
 
11
#include <stdarg.h>
12
#include <stdio.h>
13
#include <stdlib.h>
14
#include <string.h>
15
 
16
char* gError_messages[126] = {
17
    "Unable to support this screen depth setting",
18
    "Couldn't allocate off-screen buffer",
19
    "Couldn't allocate Z-Buffer",
20
    "Couldn't allocate root actor",
21
    "Couldn't calculate the application's pathname",
22
    "Couldn't allocate camera",
23
    "Couldn't allocate self",
24
    "There was a problem with the Preferences file - try deleting it.",
25
    "Couldn't open General Settings file",
26
    "Couldn't open Key Map file",
27
    "Unable to find required palette",
28
    "Couldn't allocate and install standard lamp",
29
    "Couldn't allocate and install stupid test bastard",
30
    "Couldn't load FLIC file '%'",
31
    "Couldn't allocate memory to play FLIC file '%'",
32
    "The FLIC file '%' was not 8-bits deep",
33
    "Couldn't ascertain a frame-rate for FLIC file '%'",
34
    "A problem occurred whilst trying to free up some FLICs '%'",
35
    "Couldn't find a spare transient bitmap",
36
    "Save file was bigger than save structure",
37
    "Can't load font image '%'",
38
    "Can't load font width table '%'",
39
    "Can't load cursor image",
40
    "Can't load cursor giblet",
41
    "Screen width/height doesn't match graf data",
42
    "Can't load car resolution-independant file",
43
    "Can't load cockpit image",
44
    "Can't load damage image",
45
    "Can't open prat cam text file",
46
    "Premature flic specs end in prat cam text file",
47
    "Can't open prat cam flic file '%'",
48
    "Can't allocate memory for prat cam flic file",
49
    "Too many flic specs in prat cam text file",
50
    "Premature sequences end in prat cam text file",
51
    "Too many sequences in prat cam text file",
52
    "Can't load speedo image",
53
    "Can't load tacho image",
54
    "Pratcam sequence % has too many chunks",
55
    "Pratcam sequence % has too many alternatives",
56
    "Pratcam sequence % has too many sounds",
57
    "Can't load hands image",
58
    "Flying wombat alert: flic palette disposed before it's been allocated",
59
    "Can't load dials pix",
60
    "Trying to free a NULL pointer",
61
    "Trying to free an invalid pointer (%)",
62
    "Trying to free an already free block (%)",
63
    "Trying to lock an invalid pointer (%)",
64
    "Trying to unlock an invalid pointer (%)",
65
    "Out of memory (insufficient heap space)",
66
    "Out of memory (insufficient block slots)",
67
    "Can't open races file",
68
    "Can't load race scene image",
69
    "Can't load race map image",
70
    "Can't load race info image",
71
    "Can't open opponents file",
72
    "Opponents count mismatches actual number of opponents",
73
    "Can't load opponent mug-shot file",
74
    "Can't load grid image file",
75
    "Can't load part image file",
76
    "Can't load chrome font file",
77
    "Can't load funkotronic file",
78
    "Can't load groovadelic file",
79
    "Error within funkotronic file",
80
    "Error within groovidelic file",
81
    "Can't find main material '%' referenced in funkotronic file",
82
    "Can't find actor '%' referenced in groovidelic file",
83
    "Can't find animation frame pixelmap referenced in funkotronic file",
84
    "Insufficient pixelmap slots in storage area",
85
    "Insufficient shade table slots in storage area",
86
    "Insufficient material slots in storage area",
87
    "Insufficient model slots in storage area",
88
    "Can't load car actor",
89
    "Defined ref-num of controlled groovidelic/funkotronic is out of range",
90
    "Used ref-num of controlled groovidelic/funkotronic is out of range",
91
    "MAMS heap is corrupt",
92
    "Can't open pedestrian file",
93
    "Can't find pedestrian with ref num %",
94
    "Can't find pedestrian material '%'",
95
    "Can't find pedestrian pixelmap '%'",
96
    "Can't load pixelmap file '%' (or it's empty)",
97
    "Can't load shade table file '%' (or it's empty)",
98
    "Can't load material file '%' (or it's empty)",
99
    "Can't load model file '%' (or it's empty)",
100
    "Too many frames in pedestrian sequence",
101
    "Too many choices in pedestrian instructions",
102
    "Too many bearings in pedestrian sequences",
103
    "Pedestrian instruction marker not found",
104
    "Can't load depth-cue shade table",
105
    "Unrecognised opponent path type '%'",
106
    "Can't find sky material '%'",
107
    "Can't find sky pixelmap '%'",
108
    "Unknown damage type '%'",
109
    "Confused by format of conditional damage in car file",
110
    "Too many extra points for car index '%'",
111
    "Sorry, but Carmageddon has run out of memory (%)",
112
    "Piping buffer prematurely reached end",
113
    "Piping buffer prematurely reached beginning",
114
    "Piped pedestrian made no sense",
115
    "Something in the piping system went odd",
116
    "Can't open TEXT.TXT file",
117
    "Can't open DARE.TXT file",
118
    "Can't find the FLIC '%' referenced in the interface translation file",
119
    "Can't open headups file",
120
    "Can't open partshop file",
121
    "Can't open car resolution-dependant file",
122
    "Received new player list - and we're not in it!!!",
123
    "Can't open key names file",
124
    "Can't open '%'",
125
    "Too many planes in special volume (max is %)",
126
    "Can't load  a generated shade table",
127
    "Network code self-check failed",
128
    "Network message corrupted",
129
    "Memory has become corrupted",
130
    "Ran out of funk/groove slot bunches",
131
    "Net contents too big %",
132
    "File % is corrupted",
133
    "Random number out of range (%)",
134
};
135
int gError_code;
136
char* gPalette_copy__errors;    // suffix added to avoid duplicate symbol
137
int gPixel_buffer_size__errors; // suffix added to avoid duplicate symbol
138
int gMouse_was_started__errors; // suffix added to avoid duplicate symbol
139
char* gPixels_copy__errors;     // suffix added to avoid duplicate symbol
140
 
141
// IDA: void __cdecl FatalError(int pStr_index, ...)
142
void FatalError(int pStr_index, ...) {
143
    char the_str[1024];
144
    char* sub_str;
145
    char temp_str[1024];
146
    char* sub_pt;
147
    va_list ap;
148
    //int i; // Pierre-Marie Baty -- unused variable
149
    LOG_TRACE("(%d)", pStr_index);
150
 
151
    va_start(ap, pStr_index);
152
 
153
    gLast_demo_end_anim = 0x20000000 + PDGetTotalTime();
154
    strcpy(the_str, gError_messages[pStr_index]);
155
    sub_pt = temp_str;
156
 
157
    while (1) {
158
 
159
        sub_pt = strchr(the_str, '%');
160
        if (!sub_pt) {
161
            break;
162
        }
163
        sub_str = va_arg(ap, char*);
164
        StripCR(sub_str);
165
        strcpy(temp_str, sub_pt + 1);
166
        strcpy(sub_pt, sub_str);
167
        strcat(the_str, temp_str);
168
    }
169
    va_end(ap);
170
    dr_dprintf(the_str);
171
    FadePaletteUp();
172
    PDFatalError(the_str);
173
}
174
 
175
// IDA: void __cdecl NonFatalError(int pStr_index, ...)
176
void NonFatalError(int pStr_index, ...) {
177
    char the_str[256];
178
    char* sub_str;
179
    char temp_str[256];
180
    char* sub_pt;
181
    va_list ap;
182
    size_t i; // Pierre-Marie Baty -- fixed type
183
    LOG_TRACE("(%d)", pStr_index);
184
 
185
    va_start(ap, pStr_index);
186
 
187
    strcpy(the_str, gError_messages[pStr_index - 1]);
188
    sub_pt = temp_str;
189
 
190
    for (i = 0; i < strlen(the_str); i++) {
191
        if (the_str[i] == '%') {
192
            sub_str = va_arg(ap, char*);
193
            StripCR(sub_str);
194
            strcpy(sub_pt, sub_str);
195
            sub_pt += strlen(sub_str);
196
        } else {
197
            *sub_pt = the_str[i];
198
            sub_pt++;
199
        }
200
    }
201
    *sub_pt = 0;
202
    va_end(ap);
203
    PDNonFatalError(temp_str);
204
}
205
 
206
// IDA: void __cdecl CloseDiagnostics()
207
// This function is stripped from the retail binary, we've guessed at the implementation
208
void CloseDiagnostics(void) {
209
    LOG_TRACE("()");
210
 
211
    if (harness_game_config.enable_diagnostics == 0) {
212
        return;
213
    }
214
 
215
    fclose(gDiagnostic_file);
216
}
217
 
218
// IDA: void __cdecl OpenDiagnostics()
219
// This function is stripped from the retail binary, we've guessed at the implementation
220
void OpenDiagnostics(void) {
221
    LOG_TRACE("()");
222
 
223
    if (harness_game_config.enable_diagnostics == 0) {
224
        return;
225
    }
226
 
227
    gDiagnostic_file = fopen("DIAGNOST.TXT", "w");
228
 
229
    fputs("DIAGNOSTIC OUTPUT\n", gDiagnostic_file);
230
    // todo: generate a real date
231
    fprintf(gDiagnostic_file, "Date / time : %s\n\n\n", "Mon Mar 24 16 : 32 : 33 1997");
232
}
233
 
234
// Renamed from dprintf to avoid collisions to stdio
235
// This function is stripped from the retail binary, we've guessed at the implementation
236
void dr_dprintf(char* fmt_string, ...) {
237
    static tU32 first_time = 0;
238
    va_list args;
239
    tU32 the_time;
240
 
241
    if (harness_game_config.enable_diagnostics == 0) {
242
        return;
243
    }
244
 
245
    if (gDiagnostic_file == NULL) {
246
        return;
247
    }
248
 
249
    if (first_time == 0) {
250
        first_time = GetTotalTime();
251
    }
252
    the_time = GetTotalTime() - first_time;
253
 
254
    fprintf(gDiagnostic_file, "%7d.%02d: ", the_time / 1000, the_time % 100);
255
 
256
    va_start(args, fmt_string);
257
    vfprintf(gDiagnostic_file, fmt_string, args);
258
    va_end(args);
259
    fputs("\n", gDiagnostic_file);
260
    fflush(gDiagnostic_file);
261
 
262
    // Added by dethrace for debugging
263
    // va_start(args, fmt_string);
264
    // vprintf(fmt_string, args);
265
    // va_end(args);
266
    // printf("\n");
267
}
268
 
269
// IDA: int __usercall DoErrorInterface@<EAX>(int pMisc_text_index@<EAX>)
270
int DoErrorInterface(int pMisc_text_index) {
271
    LOG_TRACE("(%d)", pMisc_text_index);
272
 
273
    NetFullScreenMessage(pMisc_text_index, 0);
274
    return 0;
275
}