22#pragma function(strcmp)
38 ctrlFile = _open(
"ctrl.del", O_BINARY);
44 config = fopen(
"WC2.CFG",
"rt");
46 scanned = fscanf(config,
"%s", option);
51 if (strcmp(
"[[log]]", option) == 0)
85#pragma intrinsic(strcmp)
87#pragma function(memset)
89int WINAPI
WinMain(HINSTANCE instance, HINSTANCE previous,
90 LPSTR commandLine,
int showCommand)
92 MEMORYSTATUS memoryStatus;
96 if (commandLine != 0 && strchr(commandLine,
's') != 0)
99 CreateSemaphoreA(0, 0, 1,
"Wing Commander 2");
100 if (GetLastError() == ERROR_ALREADY_EXISTS) {
102 "Only one instance of Wing Commander 2 for Windows95 may be running at a time",
103 "ATTENTION", MB_ICONERROR);
107 memset(&memoryStatus, 0,
sizeof(memoryStatus));
108 memoryStatus.dwLength =
sizeof(memoryStatus);
109 GlobalMemoryStatus(&memoryStatus);
110 if (memoryStatus.dwTotalPhys < 0x800000) {
112 "You must have at leat 8 megs of memory available to play Wing Commander 2 for Windows95",
113 "ATTENTION", MB_ICONERROR);
116 if (memoryStatus.dwTotalPageFile < 0x800000) {
118 "You must have at leat 8 megs of virtual memory available to play Wing Commander 2 for Window95",
119 "ATTENTION", MB_ICONERROR);
123 if (waveOutGetNumDevs() < 1)
134 processHandle = GetCurrentProcess();
136 SetPriorityClass(processHandle, HIGH_PRIORITY_CLASS);
139 srand((
unsigned int)time(0));
186 process = GetCurrentProcess();
187 SetPriorityClass(process, IDLE_PRIORITY_CLASS);
197 MessageBoxA(0, text,
"NOTICE", 0x10);
202#pragma function(strcpy)
209 va_start(arguments, format);
211 vsprintf(buffer, format, arguments);
213 strcpy(buffer, va_arg(arguments,
const char *));
215 OutputDebugStringA(buffer);
227 process = GetCurrentProcess();
228 SetPriorityClass(process, IDLE_PRIORITY_CLASS);
230 "Current: %i\nMax : %i\nTotal : %i\n",
234 OutputDebugStringA(
"Memory Info:\n");
244 WNDCLASSA windowClass;
254 windowClass.hCursor = 0;
255 windowClass.hIcon = LoadIconA(0, IDI_APPLICATION);
257 windowClass.hbrBackground = GetStockObject(BLACK_BRUSH);
258 windowClass.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
259 windowClass.cbClsExtra = 0;
260 windowClass.cbWndExtra = 0;
261 if (RegisterClassA(&windowClass) == 0)
268 error = GetLastError();
277 "You must be running with 256, or more, colors to play Wing Commander",
278 "NOTICE", MB_ICONEXCLAMATION);
306 if (skipMessages == 0) {
316 if (GetMessageA(&message, 0, 0, 0) != 0) {
317 TranslateMessage(&message);
318 DispatchMessageA(&message);
325 if (PeekMessageA(&message, 0, 0, 0,
327 if (GetMessageA(&message, 0, 0, 0) != 0) {
328 TranslateMessage(&message);
329 DispatchMessageA(&message);
351 WPARAM wParam, LPARAM lParam)
356 unsigned int primaryButtonDown;
357 unsigned int secondaryDown;
358 unsigned int pointerPositionX;
359 unsigned int cursorY;
360 unsigned int scanValue;
362 unsigned int character;
363 HANDLE processHandle;
366 menuId = (
unsigned int)wParam & 0xffff;
368 primaryButtonDown = ((
unsigned int)wParam & 1) != 0;
369 secondaryDown = ((
unsigned int)wParam & 2) != 0;
370 if (message == WM_MOUSEMOVE || message == WM_RBUTTONUP ||
371 message == WM_LBUTTONUP || message == WM_LBUTTONDOWN ||
372 message == WM_RBUTTONDOWN) {
392 processHandle = GetCurrentProcess();
393 SetPriorityClass(processHandle, HIGH_PRIORITY_CLASS);
409 processHandle = GetCurrentProcess();
410 SetPriorityClass(processHandle, IDLE_PRIORITY_CLASS);
419 if (((
unsigned int)wParam & 0xffff) != 0) {
420 if (HIWORD(wParam) != 0) {
430 processHandle = GetCurrentProcess();
431 SetPriorityClass(processHandle, HIGH_PRIORITY_CLASS);
447 processHandle = GetCurrentProcess();
448 SetPriorityClass(processHandle, IDLE_PRIORITY_CLASS);
475 primaryButtonDown, secondaryDown, 0, 0, 0);
481 cursorY, 0, 0, 1, 0, 0, 0);
487 cursorY, 0, 1, 0, 0, 0, 0);
494 primaryButtonDown, secondaryDown, 0, 0, 0);
501 if (PeekMessageA(&textEvent, window, WM_CHAR, WM_CHAR,
503 character = (
unsigned int)textEvent.wParam;
507 if (wParam == VK_F1) {
508 if (((
unsigned long)lParam & 0x40000000) == 0)
513 scanValue = ((
unsigned long)lParam & 0xff0000) >> 16;
516 if (((
unsigned long)lParam & 0x40000000) == 0 &&
527 if (PeekMessageA(&textEvent, window, WM_CHAR, WM_CHAR,
529 character = (
unsigned int)textEvent.wParam;
535 scanValue = ((
unsigned long)lParam & 0xff0000) >> 16;
536 if (scanValue != 0x81) {
565 if (((
unsigned long)lParam & 0x20000000) != 0)
575 if (((
unsigned long)lParam & 0x20000000) != 0)
579 if (((
unsigned long)lParam & 0x20000000) != 0)
583 if (((
unsigned long)lParam & 0x20000000) != 0)
587 if (((
unsigned long)lParam & 0x20000000) != 0)
591 if (((
unsigned long)lParam & 0x20000000) != 0)
595 if (((
unsigned long)lParam & 0x20000000) != 0)
599 if (((
unsigned long)lParam & 0x20000000) != 0)
603 if (((
unsigned long)lParam & 0x20000000) != 0)
607 if (((
unsigned long)lParam & 0x20000000) != 0)
611 if (((
unsigned long)lParam & 0x20000000) != 0 &&
629 processHandle = GetCurrentProcess();
630 SetPriorityClass(processHandle, IDLE_PRIORITY_CLASS);
637 processHandle = GetCurrentProcess();
638 SetPriorityClass(processHandle, IDLE_PRIORITY_CLASS);
642 if ((wParam & 0xfff0) == SC_SCREENSAVE ||
643 (wParam & 0xfff0) == SC_MONITORPOWER)
647 if (mouseInput != 0) {
653 return DefWindowProcA(window, message, wParam, lParam);
658 int *buttons,
unsigned short joystick,
659 unsigned int fallback)
662 unsigned int deviceId;
679 if ((joyInfo.wButtons & 1) != 0) {
686 if ((joyInfo.wButtons & 2) != 0) {
717 short *yMin,
short *yMax)
720 unsigned int deviceId = joystick != 0;
722 *xMin = *xMax = *yMin = *yMax = 0;
723 if (joyGetDevCapsA(deviceId, &devCaps,
sizeof(devCaps)) != JOYERR_NOERROR) {
727 *xMin = (short)devCaps.wXmin;
728 *xMax = (short)devCaps.wXmax;
729 *yMin = (short)devCaps.wYmin;
730 *yMax = (short)devCaps.wYmax;
755#pragma function(memset)
786#pragma intrinsic(memset)
792 sprintf(text,
"Memory at %p %swritten. Corruption : (%i/%i) %s",
793 memory, overrun ?
"over" :
"under", count, 0x100,
795 ? (count > 0xc0 ?
"EXTREME" :
"SEVERE")
796 : (count > 0x40 ?
"BAD" :
"NAUGHTY"));
797 MessageBoxA(0, text,
"NOTICE", 0x10);
812 if (block->
block == memory)
814 if (block->
block == (
unsigned char *)memory - 8)
828 if (block->
block == memory) {
829 OutputDebugStringA(
"DoubleFree Detected\n");
832 if (block->
block == (
unsigned char *)memory - 8) {
833 OutputDebugStringA(
"DoubleFree (pushed) Detected\n");
866 while (current != 0) {
867 if (current->
block == memory) {
870 if (current->
next == 0)
874 if (current->
next == 0)
881 current = current->
next;
918 fence = (
unsigned int *)((
unsigned char *)memory - 0x400);
922 if (entry->
block == fence) {
924 for (i = 0; i < 0x100; i++) {
925 if (*fence != 0xabababab)
933 (
unsigned int *)((
unsigned char *)memory + entry->
size);
935 for (i = 0; i < 0x100; i++) {
936 if (*fence != 0xabababab)
943 fence = (
unsigned int *)((
unsigned char *)memory - 0x400);
968 "MEM: Unknown memory lost (%p)\n", fence);
985 if (GetAsyncKeyState(VK_ESCAPE) != 0)
1048 return GetAsyncKeyState(VK_HOME);
1054 return GetAsyncKeyState(VK_UP);
1060 return GetAsyncKeyState(VK_PRIOR);
1066 return GetAsyncKeyState(VK_LEFT);
1072 return GetAsyncKeyState(VK_RIGHT);
1078 return GetAsyncKeyState(VK_END);
1084 return GetAsyncKeyState(VK_DOWN);
1090 return GetAsyncKeyState(VK_NEXT);
1096 return GetAsyncKeyState(VK_NUMLOCK);
1102 return GetAsyncKeyState(VK_ADD);
1108 return GetAsyncKeyState(VK_SUBTRACT);
1114 return GetAsyncKeyState(VK_RETURN);
1120 return GetAsyncKeyState(VK_SPACE);
1126 return GetAsyncKeyState(VK_SHIFT);
1138 return GetAsyncKeyState(VK_CONTROL);
1144 return GetAsyncKeyState(0x4a);
1165 OutputDebugString(s);
1183#pragma function(memset)
1196 for (slot = 0; slot < 1; slot++) {
1197 workspace[0][slot].
width = 5;
1198 workspace[0][slot].
height = 5;
1199 workspace[0][slot].
pixels = (
unsigned char *)malloc(
1200 (*workspace)->height * (*workspace)->width);
1201 memset(workspace[0][slot].pixels, 5,
1202 (*workspace)->
height * (*workspace)->width);
1214 for (slot = 0; slot < 1; slot++)
1215 free(workspace[0][slot].pixels);
1228 GetCurrentDirectoryA(0xff, current);
1233 "\\wc2\\streams\\");
1235 if (strstr(current,
"gamedat") != 0)
1241 GetCurrentDirectoryA(0xff, current);
1244 SetCurrentDirectoryA(current);
1249#pragma function(strcmp)
1252 const char *directory)
1254 char volumeName[256];
1256 char systemName[64];
1258 DWORD maximumComponentLength;
1266 for (device =
'a'; device <=
'z'; device++) {
1267 sprintf(rootPath,
"%c:\\", (
char)device);
1268 if (GetDriveTypeA(rootPath) == DRIVE_CDROM) {
1269 drives[count] = (char)device;
1275 for (device = 0; device < count; device++) {
1276 sprintf(drivePath,
"%c:\\", drives[device]);
1277 GetVolumeInformationA(drivePath, volumeName, 0xff, 0,
1278 &maximumComponentLength, &volumeFlags,
1279 systemName,
sizeof(systemName));
1280 if (strcmp(label,
"<anydisc>") == 0) {
1282 answer = drives[device];
1285 }
else if (strcmp(volumeName, label) == 0) {
1287 answer = drives[device];
1295#pragma intrinsic(strcmp)
1304 GetCurrentDirectoryA(0xff, previous);
1305 sprintf(path,
"%c:%s", drive, directory);
1306 if (SetCurrentDirectoryA(path) != 0)
1308 SetCurrentDirectoryA(previous);
1322#pragma intrinsic(strcpy)
1331 strcpy(title,
"Insert Correct CD");
1333 "Please place The Kilrathi Saga disc %d into your CD-ROM drive and click OK\n"
1334 "or click cancel to quit",
1337 if (MessageBoxA(0, message, title,
1338 MB_OKCANCEL | MB_ICONEXCLAMATION) == IDCANCEL)
1363 "Wing Commander II: Vengeance of the Kilrathi";
1365 "Wing Commander II: Vengeance of the Kilrathi";
WINUSERAPI HDC WINAPI GetDC(HWND window)
WINGDIAPI COLORREF WINAPI SetTextColor(HDC deviceContext, COLORREF colour)
WINGDIAPI COLORREF WINAPI SetBkColor(HDC deviceContext, COLORREF colour)
int GetDownArrowKeyState(void)
int GetSpaceKeyState(void)
void AllocateApplicationScratchBuffer(void)
void SetMousePosition(int x, int y)
void GetJoystickPosition(unsigned int *x, unsigned int *y, int *buttons, unsigned short joystick, unsigned int fallback)
void DestroyGlobalDebugOverlayConsole(void)
short LogMemoryUsage(void)
int GetReturnKeyState(void)
void ServiceAudioStream(void)
void ReleaseApplicationScratchBuffer(void)
void ShutdownGameWindow(void)
unsigned int AbortToDesktop(void)
int GetPageUpKeyState(void)
void InitializeAudioStreamer(HWND window)
unsigned int PollKeyboardState(void)
void * AllocateGuardedMemory(unsigned int size)
void ReportSpaceFlightMaxFps(float adjustment)
int ReadCheaterFlagFromRegistry(void)
int GetPageDownKeyState(void)
void CheckLauncherAndConfig(void)
HWND GetMainWindowHandle(void)
void SetInputKeyState(int scanCode, unsigned char pressed)
int IsFreedHeapBlockTracked(void *memory)
void DIBinstall(HWND window)
void FreeGuardedAllocation(void *memory)
int GetNumLockKeyState(void)
int GetRightArrowKeyState(void)
void DIBpositionWindow(void)
void QueueInputEvent(int type, int x, int y, int value, int primaryButton, int secondaryButton, unsigned int ignored, unsigned int field14, unsigned int field18)
LRESULT CALLBACK MainWindowProc(HWND window, UINT message, WPARAM wParam, LPARAM lParam)
unsigned int PumpWindowMessages(int skipMessages)
void KeyboardMousePump(void)
int GetNumpadPlusKeyState(void)
void CheckAllGuardedAllocations(void)
void MonoDebug_install(void)
int GetHomeKeyState(void)
void InitializeAudioSystem(HWND window)
HINSTANCE GetApplicationInstance(void)
char * LocateStreamsDirOnDisc(void)
int GetNumpadMinusKeyState(void)
int TakeInputPressCount(void)
unsigned int GetF1KeyLatch(void)
HDC GetMainWindowDeviceContext(void)
short GetJoystickButtons(void)
int DetectDoubleFree(void *memory)
int GetControlKeyState(void)
void InitGameClockRandomEpoch(void)
void UntrackFreedHeapBlock(void *memory)
void GetJoystickDevCaps(short joystick, short *xMin, short *xMax, short *yMin, short *yMax)
void ReportHeapGuardCorruption(void *memory, int count, int overrun)
char FindCdRomDriveByVolumeLabel(const char *label, const char *directory)
void SignalAudioMixerWakeEvent(void)
unsigned int GetGameClockTicks(void)
void RunGameApplication(short argc, char **argv)
int PromptInsertCorrectCd(void)
void SetInputCursorHostPosition(int x, int y)
void ShowNoticeMessageBox(const char *text)
int SetCurrentDirOnDrive(char drive, const char *directory)
int GetShiftKeyState(void)
int GetUpArrowKeyState(void)
int GetLeftArrowKeyState(void)
int WINAPI WinMain(HINSTANCE instance, HINSTANCE previous, LPSTR commandLine, int showCommand)
void WriteDebugString(const char *s)
unsigned int GetKeyboardModifiers(void)
void TrackFreedHeapBlock(void *memory)
void OutputDebugPrintf(const char *format,...)
void CreateDebugOverlayConsole(HINSTANCE module, HWND window, short columns, short rows)
int CreateMainWindow(HINSTANCE instance, HINSTANCE previous, int showCommand)
Shared Win32 declarations, types and library interfaces.
FreedHeapBlock * g_pFreedHeapBlockTail
HostMouseMessage g_6_stHostMouseTextBlock
WINMAIN_STATIC int g_13_nUpDirKeyState
unsigned long g_128_dwGameClockBase
int g_27_nLastAltCommandScanNumberWord
int g_bInputEventQueueEnabled
WINMAIN_STATIC int g_15_nDownArrowKeyState
int g_3_nSavedOwnerCursorX
int g_bApplicationControllerActive
WINMAIN_STATIC int g_nPgUpwardKeyMode
long g_13_lGameClockStartData
int g_16_bMainWindowRunning
HANDLE g_19_hOneProcessLock
int g_bJoystickCalibrationHotkey
signed char g_bSceneEscapeRequested
WINMAIN_STATIC int g_nOemCommaKeyState
unsigned int g_48_dwGameExitClockValue
WINMAIN_STATIC int g_nDeleteKeyState
WINMAIN_STATIC int g_nClearKeyMode
WINMAIN_STATIC int g_nRightDirKeyboardState
WINMAIN_STATIC char g_9_szStreamsPath[0x100]
int g_bUseHardwarePalette
FreedHeapBlock * g_pFreedHeapBlockHead
int g_nDebugFileLoggingEnabled
int g_2_bIgnoreNextCursorMoveFlag
int g_bJoystickPrimaryButtonLatched
char g_29_abMemoryLoadNotice[0x80]
unsigned int g_dwGuardedAllocationTotalBytes
char g_szGuardedHeapDiagnosticMessage[0x80]
unsigned int g_dwGuardedAllocationPeakBytes
WINMAIN_STATIC int g_3_nBeginKeyboardState
short g_bPlayerCollisionEnabled
WINMAIN_STATIC int g_1_nPageDownKeyboardMode
GuardedAllocation * g_9_pGuardedAllocationLastRef
int g_bAltNumpadSubtractShortcut
WINMAIN_STATIC int g_3_nOemPeriodKeyState
unsigned int g_dwGuardedAllocationBytes
int g_bConfigMemoryOption
JOYINFO g_1_aJoystickInfoArray[2]
unsigned int g_11_dwGameZeroTime
int g_6_bMenuTHotkeySwitch
WINMAIN_STATIC int g_102_nLeftDirKeyboardState
volatile int g_196_nInputTimerTicks
int g_39_bAltNumpadAddHotkeySwitch
int g_bConfigQuickModeEnabled
int g_102_nStoredWindowCursorYWord
short g_bPlayerDamageEnabled
void(*) g_176_pfnCurrentInputPump(void)
WINMAIN_STATIC int g_18_nEndKeyState
WINMAIN_STATIC int g_2_nClearedKeyboardState
HCURSOR g_1_hMainWndCursor
int g_bApplicationShutdownStarted
int g_bJoystickSecondaryButtonLatched
WINMAIN_STATIC int g_nInsertKeyStatus
int g_bWindowMessagePumpActive
GuardedAllocation * g_pGuardedAllocationHead
HDC g_18_hMainWindowContext
unsigned int g_69_dwSysKeyValue
struct FreedHeapBlock * next
struct GuardedAllocation * next
int g_nUnusedWinMainWord1
static char g_szWindowClassName[45]
void FreeFontWorkspace(FontWorkspace **workspace)
int g_nUnusedWinMainWord2
int g_5_nIdleWinmainWord[32]
FontWorkspace ** AllocateFontWorkspace(short fontIndex)
void FreeTrackedHeapBlocks(void)
static char g_szWindowTitle[45]