Wing Commander
Reconstructed Win32 source (1996)
Loading...
Searching...
No Matches
wc1base.h
Go to the documentation of this file.
1/**
2 * @file
3 * @ingroup headers
4 * @brief Common types, macros and utility prototypes.
5 *
6 * wc1.h adds the data headers after these; the Win32 shell (winmain.c)
7 * includes them itself because it declares main.c's option flags with its
8 * own types.
9 */
10#ifndef WC1BASE_H
11#define WC1BASE_H
12
13#include <windows.h>
14#include <ddraw.h>
15#include <mmsystem.h>
16#include <conio.h>
17#include <direct.h>
18#include <io.h>
19#include <ctype.h>
20#include <errno.h>
21#include <fcntl.h>
22#include <math.h>
23#include <stdarg.h>
24#include <stdio.h>
25#include <stdlib.h>
26#include <string.h>
27#include <time.h>
28
29/* Degrees are the angular unit throughout the game core (the constant lives at
30 * DAT_004631b0 in the original); the trig shims convert on the way in. */
31#define DEGREES_TO_RADIANS 0.017453292519943295
32
33/* The DirectDraw back end uses this release-and-clear shape for its surfaces. */
34#define COM_RELEASE(surface) \
35 do { if ((surface) != 0) { IDirectDrawSurface_Release(surface); (surface) = 0; } } while (0)
36
37/* --------------------------------------------------------------------------
38 * Shared packet declarations and the retained DOS word spelling.
39 * -------------------------------------------------------------------------- */
40struct RLEShape;
41typedef unsigned short UINT16;
42/* Heterogeneous packet lists hold pointer slots, including unaligned slots
43 * in packed runtime records. Shapes are opaque to the C++ audio/console units. */
45;
46struct Shape;
47
48typedef struct IxSound IxSound;
49typedef struct IxSample IxSample;
50
51/* The game-side wave unit inspects the leading public fields and invokes the
52 * selected methods declared here. The IX implementation owns the complete
53 * C++ object layout. */
54struct IxSample {
55 unsigned int flags;
56#ifdef __cplusplus
57 int ix_sample_load_wav(void *data, int bytes);
58#endif
59};
60
61struct IxSound {
62 unsigned int flags;
64#ifdef __cplusplus
65 void ix_system_sound_set_volume(unsigned short volume);
66 void ix_system_sound_set_pan(unsigned short pan);
67 void ix_sound_set_delete_on_stop(int enabled);
68#endif
69};
70
71/* The DOS rasteriser passes this record to every drawing primitive. Its
72 * offsets are fixed by the accesses in the 0x00440C00-0x00441A8F block. */
73typedef struct Viewport {
74 unsigned char *pixels; /* +0x00 */
75 unsigned short *rowOffsets; /* +0x04 */
76 short left; /* +0x08 */
77 short top; /* +0x0A */
78 short right; /* +0x0C */
79 short bottom; /* +0x0E */
80 unsigned char *allocation; /* +0x10 */
82
83#define SPRITE_ROW_OFFSET(viewport, row) viewport->rowOffsets[row]
84
85/* Loaded shape packet: a leading dword followed by a variable-length offset
86 * table. Offsets are relative to the packet, and the low word of its first
87 * entry also marks the end of the table. The one-element tail is the
88 * variable-array spelling supported by VC++ 4.20. */
89#ifndef __cplusplus
90struct Shape {
91 unsigned int field_0; /* +0x00: not read by the shape helpers */
92 int frameOffsets[1]; /* +0x04 */
93};
94#endif
95
96/* The event manager snapshots these 28 bytes with seven MOVSD operations.
97 * The unaligned pointer fields and reserved spans are fixed by the original
98 * addresses at 0x0059AB10-0x0059AB2B. */
99#pragma pack(push, 1)
100typedef struct MouseCursorState {
101 short x; /* +0x00 */
102 short y; /* +0x02 */
103 unsigned char primaryButton; /* +0x04 */
104 unsigned char secondaryButton; /* +0x05 */
105 unsigned char reserved; /* +0x06 */
106 unsigned short flags; /* +0x07 */
107 struct Shape *shape; /* +0x09 */
108 unsigned short frame; /* +0x0D */
109 unsigned int reservedAfterFrame; /* +0x0F */
110 Viewport *viewport; /* +0x13 */
111 unsigned int reservedAfterViewport; /* +0x17 */
112 unsigned char shapeChanged; /* +0x1B */
114#pragma pack(pop)
115
117 sizeof(MouseCursorState) == 0x1c ? 1 : -1];
118
119/* The event manager keeps a fixed pool of doubly-linked input records. The
120 * 0x1C-byte stride is fixed by the allocator at 0x004356E0 and the link
121 * accesses at 0x00435790-0x004359BF. */
122typedef struct InputEvent {
123 short type; /* +0x00 */
124 short x; /* +0x02 */
125 short y; /* +0x04 */
126 short value; /* +0x06 */
127 unsigned int modifiers; /* +0x08 */
128 unsigned int timestamp; /* +0x0C */
129 short primaryButton; /* +0x10 */
130 short secondaryButton; /* +0x12 */
131 struct InputEvent *next; /* +0x14 */
132 struct InputEvent *previous; /* +0x18 */
134
135/* Public event records retain the packed layout of the 16-bit event-manager
136 * API. In particular, both 32-bit fields are intentionally unaligned. */
137#pragma pack(push, 1)
138typedef struct InputEventState {
139 short type; /* +0x00 */
140 unsigned int value; /* +0x02 */
141 unsigned int timestamp; /* +0x06 */
142 short modifiers; /* +0x0A */
143 short x; /* +0x0C */
144 short y; /* +0x0E */
146#pragma pack(pop)
147
148/* One sampled joystick position and its button mask. */
149typedef struct InputDeviceSample {
150 int x;
151 int y;
152 unsigned int buttons;
154
155/* Linear 8-bit raster target and its active clipping rectangle. */
156typedef struct RasterSurface {
157 unsigned char *pixels;
163
171
172/* The packet's frames start with four signed extents; their byte offsets
173 * need not be aligned. The encoded scanline stream follows these eight bytes. */
174#pragma pack(push, 1)
175#ifndef __cplusplus
177 short right; /* +0x00 */
178 short left; /* +0x02 */
179 short top; /* +0x04 */
180 short bottom; /* +0x06 */
181};
182#endif
183#pragma pack(pop)
184
185/* One transformed corner used by the hand-written RLE scan converter. The
186 * third word is deliberately unused; the retail workspace advances through
187 * these records with a 20-byte stride. */
195
196/* Prepared renderer cache, identified by the literal "1.00" at 0x00470D30.
197 * Each frame has an image offset followed by an optional palette offset.
198 * Both offsets are relative to the cache, not native pointers. */
199#ifndef __cplusplus
200struct RLEShape {
201 char version[4]; /* +0x00 */
202 int frameCount; /* +0x04 */
203 int frameOffsets[1][2]; /* +0x08: image, palette */
204};
205#endif
206
207/* Cached shape frames use the renderer's row-oriented RLE representation.
208 * The four signed bounds are relative to the shape origin; the byte stream
209 * for the first row begins immediately after this 24-byte header. */
210typedef struct RLEFrameHeader {
211 short height;
212 short width;
215 int left;
216 int top;
217 int right;
219}
221
222/* One scratch glyph bitmap used while drawing the packed game fonts. The
223 * renderer stores a pointer-to-pointer to this record in TextContext because
224 * the DOS implementation could move the backing allocation. */
225typedef struct FontWorkspace {
226 int width;
228 unsigned char *pixels;
230
231/* Packed text renderer state. The Win32 port retained the DOS byte layout:
232 * the draw colour is at +0x0C, the optional text pointer at +0x0E and the
233 * horizontal alignment byte at +0x16. */
234#pragma pack(push, 1)
235typedef struct TextContext {
236 Viewport *viewport; /* +0x00 */
237 short cursorX; /* +0x04 */
238 short cursorY; /* +0x06 */
239 unsigned char *font; /* +0x08 */
240 unsigned char colour; /* +0x0C */
241 unsigned char backgroundColour; /* +0x0D */
242 char *text; /* +0x0E */
243 char *textCursor; /* +0x12 */
244 unsigned char alignment; /* +0x16 */
247
248/* One of six numeric cockpit readouts. The packed ten-byte stride is used
249 * directly by the original renderer at 0x00413F70-0x0041409C. */
250typedef struct CockpitReadout {
251 TextContext *context; /* +0x00 */
252 short x; /* +0x04 */
253 short y; /* +0x06 */
254 short previousRight; /* +0x08 */
256
257/* Saved background and text state for the centred modal message panel. The
258 * unaligned Viewports are inherited from the packed DOS layout. */
259typedef struct ModalTextPanel {
260 TextContext context; /* +0x00 */
262 Viewport viewport; /* +0x2F */
264 short left; /* +0x47 */
265 short top; /* +0x49 */
266 short right; /* +0x4B */
267 short bottom; /* +0x4D */
269
270/* One flashing cockpit/VDU message. Two adjacent records begin at
271 * 0x005A7DD0; the unaligned text pointer at +0x0D is intentional. */
272typedef struct HudMessageSlot {
273 TextContext *context; /* +0x00 */
274 short x; /* +0x04 */
275 short y; /* +0x06 */
276 short colour; /* +0x08 */
277 short drawColour; /* +0x0A */
278 signed char flashCount; /* +0x0C */
279 const char *text; /* +0x0D */
281
282/* The killer-board room menu. Its pointers sit at 2 mod 4 in the original
283 * (0x00598AB2-0x00598ABA) and its text context at 0x00598ABE: LINK aligns
284 * every separate common of four or more bytes, so only one packed aggregate
285 * reproduces this layout. */
286typedef struct RoomMenu {
287 short cursorFrame; /* +0x00 */
288 const struct TitleMenuRegion *regions; /* +0x02 */
289 char **labels; /* +0x06 */
290 const char *currentLabel; /* +0x0A */
291 TextContext text; /* +0x0E */
293#pragma pack(pop)
294
295/* The record InitializeDIBScreenViewport fills at 0x005A66E0 and points
296 * 0x005A66EC at. The pointer's offset fixes the record at twelve bytes;
297 * nothing in the shipped executable reads its third word. */
298typedef struct ScreenAllocation {
299 int state; /* +0x00 */
300 Viewport *viewport; /* +0x04 */
301 int field_8; /* +0x08 */
303
305 sizeof(CockpitReadout) == 0x0a ? 1 : -1];
307 sizeof(RoomMenu) == 0x29 ? 1 : -1];
308
309/* Runtime wave-cache node. The name pointer and next link are established by
310 * the allocation/free paths at 0x0042B1F0 and 0x0042B300; the sample pointer
311 * at +0x08 is established by playWAVE. */
319
320/* One transient IX sound and its link in the game-side active-sound list. */
325
326/* Metadata preceding a tagged allocation, outside the on-disk packet.
327 * The SDL port stores its wider cache pointer before the legacy prefix. */
328#ifndef __cplusplus
330 unsigned int signature; /* packet - 8: 'jeff' */
331 struct RLEShape *preparedShape; /* packet - 4 */
332};
333#endif
334
335/* Metadata for allocations surrounded by the 0x400-byte 0xAB guard regions
336 * checked by ReportHeapGuardCorruption. */
338 void *block;
339 unsigned int size;
341};
342
343/* Win32 developer console. The constructor/destructor and member-call ABI in
344 * the shipped image identify this small utility as C++ even though the game
345 * itself remains C. The 0x400-byte formatting area fixes the complete 0x45C
346 * object layout used by the 0x0041C760 debug-overlay unit. */
347typedef struct DebugOverlayConsole {
348 int columns; /* +0x000 */
349 int rows; /* +0x004 */
350 int cursorColumn; /* +0x008 */
351 int cursorRow; /* +0x00C */
352 HWND window; /* +0x010 */
353 char formatBuffer[0x400]; /* +0x014 */
354 char *textBuffer; /* +0x414 */
355 unsigned char *dirtyLines; /* +0x418 */
356 int characterWidth; /* +0x41C */
357 int characterHeight; /* +0x420 */
358 int busyWait; /* +0x424 */
359 int reverseVideo; /* +0x428 */
360 COLORREF textColor; /* +0x42C */
361 COLORREF backgroundColor; /* +0x430 */
362 int backgroundMode; /* +0x434 */
363 int field_438; /* +0x438 */
364 int field_43c; /* +0x43C */
365 int field_440; /* +0x440 */
366 int field_444; /* +0x444 */
367 int field_448; /* +0x448 */
368 HANDLE mutex; /* +0x44C */
369 int animationState; /* +0x450 */
370 int spinnerIndex; /* +0x454 */
371 char *spinnerCharacters; /* +0x458 */
372#ifdef __cplusplus
373 DebugOverlayConsole(HINSTANCE module, HWND targetWindow,
374 int columnCount, int rowCount, int waitMode);
376 void Clear(void);
377 void Scroll(void);
378 void DrawPendingLines(void);
379 char WaitForKey(void);
380 void EnableReverseVideo(void);
381 void DisableReverseVideo(void);
382 void SetOverlayTextColor(int red, int green, int blue);
383 void SetOverlayBackgroundColor(int red, int green, int blue);
384 void SetTransparentBackground(void);
385 void SetOpaqueBackground(void);
386#endif
388
389/*
390 * The DOS source spelled `BOOLEAN window_colored = FALSE;`, but <windows.h>
391 * already provides BOOLEAN (as BYTE) and MSVC 4.2 rejects a redefinition with a
392 * different base type. The Win32 port therefore has to be using the windows.h
393 * one, so do not redeclare it here. TRUE/FALSE likewise come from windows.h.
394 */
395
396/* --------------------------------------------------------------------------
397 * Enumerations named by the leaked main-module source. The tag names and the
398 * first enumerator of each are original:
399 * GAME_MODE Game_Mode = Player;
400 * GAME_STATUS Game_Status = ALIVE;
401 * The remaining enumerators are NOT yet recovered -- do not invent values that
402 * the assembly has not confirmed.
403 * -------------------------------------------------------------------------- */
404typedef enum {
406 /* TODO: remaining GAME_MODE enumerators unknown */
407} GAME_MODE;
408
409typedef enum {
411 /* TODO: remaining GAME_STATUS enumerators unknown */
413
414/* --------------------------------------------------------------------------
415 * Shared utility layer. These were recovered by ranking the call graph by
416 * fan-in; the addresses are the originals.
417 * -------------------------------------------------------------------------- */
418#ifdef __cplusplus
419extern "C" {
420#endif
421
422/* Variadic printers cannot be generated mechanically, so they live here. */
423void ShowOnScreenMessage(int flags, short duration, const char *fmt, ...);
424void SoundDebugPrintf(const char *fmt, ...); /* 0x00403DB0 */
425void SystemDebugPrintf(const char *fmt, ...); /* 0x00425BB0 */
426
427#ifdef __cplusplus
428}
429#endif
430
431#endif /* WC1BASE_H */
struct ActiveSoundEntry * next
Definition wc1base.h:323
IxSound * sound
Definition wc1base.h:322
short previousRight
Definition wc1base.h:254
TextContext * context
Definition wc1base.h:251
COLORREF backgroundColor
Definition wc1base.h:361
char formatBuffer[0x400]
Definition wc1base.h:353
unsigned char * dirtyLines
Definition wc1base.h:355
char * spinnerCharacters
Definition wc1base.h:371
COLORREF textColor
Definition wc1base.h:360
unsigned char * pixels
Definition wc1base.h:228
struct GuardedAllocation * next
Definition wc1base.h:340
unsigned int size
Definition wc1base.h:339
TextContext * context
Definition wc1base.h:273
signed char flashCount
Definition wc1base.h:278
short drawColour
Definition wc1base.h:277
const char * text
Definition wc1base.h:279
unsigned int buttons
Definition wc1base.h:152
unsigned int value
Definition wc1base.h:140
short modifiers
Definition wc1base.h:142
unsigned int timestamp
Definition wc1base.h:141
unsigned int modifiers
Definition wc1base.h:127
short value
Definition wc1base.h:126
short x
Definition wc1base.h:124
struct InputEvent * next
Definition wc1base.h:131
struct InputEvent * previous
Definition wc1base.h:132
short secondaryButton
Definition wc1base.h:130
short type
Definition wc1base.h:123
unsigned int timestamp
Definition wc1base.h:128
short y
Definition wc1base.h:125
short primaryButton
Definition wc1base.h:129
unsigned int flags
Definition wc1base.h:55
int ix_sample_load_wav(void *data, int bytes)
Definition sample.cpp:199
unsigned short volume
Definition ix.h:158
void ix_system_sound_set_volume(unsigned short newVolume)
Definition sound.cpp:68
unsigned short pan
Definition ix.h:159
unsigned int flags
Definition wc1base.h:62
void ix_system_sound_set_pan(unsigned short newPan)
Definition sound.cpp:76
IxSample * sample
Definition wc1base.h:63
void ix_sound_set_delete_on_stop(int enabled)
Definition sound.cpp:346
TextContext context
Definition wc1base.h:260
TextContext * previousContext
Definition wc1base.h:263
Viewport viewport
Definition wc1base.h:262
Viewport savedBackground
Definition wc1base.h:261
unsigned char reserved
Definition wc1base.h:105
unsigned short flags
Definition wc1base.h:106
Viewport * viewport
Definition wc1base.h:110
unsigned char secondaryButton
Definition wc1base.h:104
unsigned int reservedAfterFrame
Definition wc1base.h:109
struct Shape * shape
Definition wc1base.h:107
unsigned char shapeChanged
Definition wc1base.h:112
unsigned char primaryButton
Definition wc1base.h:103
unsigned int reservedAfterViewport
Definition wc1base.h:111
unsigned short frame
Definition wc1base.h:108
short leftExtent
Definition wc1base.h:214
short topExtent
Definition wc1base.h:213
int frameCount
Definition wc1base.h:202
char version[4]
Definition wc1base.h:201
int frameOffsets[1][2]
Definition wc1base.h:203
int right
Definition wc1base.h:168
RasterSurface * surface
Definition wc1base.h:165
int bottom
Definition wc1base.h:169
unsigned char * pixels
Definition wc1base.h:157
const char * currentLabel
Definition wc1base.h:290
char ** labels
Definition wc1base.h:289
TextContext text
Definition wc1base.h:291
short cursorFrame
Definition wc1base.h:287
const struct TitleMenuRegion * regions
Definition wc1base.h:288
Viewport * viewport
Definition wc1base.h:300
short bottom
Definition wc1base.h:180
short top
Definition wc1base.h:179
short left
Definition wc1base.h:178
short right
Definition wc1base.h:177
unsigned int field_0
Definition wc1base.h:91
int frameOffsets[1]
Definition wc1base.h:92
struct RLEShape * preparedShape
Definition wc1base.h:331
unsigned int signature
Definition wc1base.h:330
unsigned char colour
Definition wc1base.h:240
short cursorY
Definition wc1base.h:238
unsigned char * font
Definition wc1base.h:239
char * text
Definition wc1base.h:242
FontWorkspace ** fontWorkspace
Definition wc1base.h:245
unsigned char backgroundColour
Definition wc1base.h:241
char * textCursor
Definition wc1base.h:243
short cursorX
Definition wc1base.h:237
Viewport * viewport
Definition wc1base.h:236
unsigned char alignment
Definition wc1base.h:244
unsigned char * pixels
Definition wc1base.h:74
short right
Definition wc1base.h:78
short bottom
Definition wc1base.h:79
unsigned char * allocation
Definition wc1base.h:80
unsigned short * rowOffsets
Definition wc1base.h:75
short left
Definition wc1base.h:76
short top
Definition wc1base.h:77
struct WaveTableEntry * next
Definition wc1base.h:317
IxSample * sample
Definition wc1base.h:315
char * name
Definition wc1base.h:313
unsigned short UINT16
Definition wc1base.h:41
struct IxSample IxSample
Definition wc1base.h:49
char MouseCursorState_size_must_be_0x1c[sizeof(MouseCursorState)==0x1c ? 1 :-1]
Definition wc1base.h:117
struct IxSound IxSound
Definition wc1base.h:48
GAME_STATUS
Definition wc1base.h:409
@ ALIVE
Definition wc1base.h:410
void * PackedResourcePointer
Definition wc1base.h:45
void SoundDebugPrintf(const char *fmt,...)
Definition mono.c:382
GAME_MODE
Definition wc1base.h:404
@ Player
Definition wc1base.h:405
char CockpitReadout_size_must_be_0x0a[sizeof(CockpitReadout)==0x0a ? 1 :-1]
Definition wc1base.h:305
void ShowOnScreenMessage(int flags, short duration, const char *fmt,...)
Definition main.c:1284
char RoomMenu_size_must_be_0x29[sizeof(RoomMenu)==0x29 ? 1 :-1]
Definition wc1base.h:307
void SystemDebugPrintf(const char *fmt,...)
Definition pilot.cpp:182