2023-06-19 00:45:25 -04:00
|
|
|
#include <dsound.h>
|
|
|
|
#include <windows.h>
|
2023-04-27 22:19:39 -04:00
|
|
|
|
|
|
|
#include "define.h"
|
|
|
|
#include "isle.h"
|
2023-05-05 05:54:17 -04:00
|
|
|
#include "legoomni.h"
|
2023-04-27 22:19:39 -04:00
|
|
|
|
2023-06-18 23:28:18 -04:00
|
|
|
// OFFSET: ISLE 0x401ca0
|
2023-06-19 02:22:32 -04:00
|
|
|
BOOL FindExistingInstance(void)
|
2023-04-27 22:19:39 -04:00
|
|
|
{
|
|
|
|
HWND hWnd = FindWindowA(WNDCLASS_NAME, WINDOW_TITLE);
|
|
|
|
if (hWnd) {
|
|
|
|
if (SetForegroundWindow(hWnd)) {
|
|
|
|
ShowWindow(hWnd, SW_RESTORE);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2023-06-18 23:28:18 -04:00
|
|
|
// OFFSET: ISLE 0x401ce0
|
2023-06-19 02:22:32 -04:00
|
|
|
BOOL StartDirectSound(void)
|
2023-04-27 22:19:39 -04:00
|
|
|
{
|
2023-06-19 00:45:25 -04:00
|
|
|
LPDIRECTSOUND lpDS = NULL;
|
2023-04-27 22:19:39 -04:00
|
|
|
HRESULT ret = DirectSoundCreate(NULL, &lpDS, NULL);
|
|
|
|
if (ret == DS_OK && lpDS != NULL) {
|
|
|
|
lpDS->Release();
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2023-06-18 23:28:18 -04:00
|
|
|
// OFFSET: ISLE 0x401610
|
2023-04-27 22:19:39 -04:00
|
|
|
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
|
|
|
|
{
|
|
|
|
// Look for another instance, if we find one, bring it to the foreground instead
|
|
|
|
if (!findExistingInstance()) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Attempt to create DirectSound instance
|
|
|
|
BOOL soundReady = FALSE;
|
|
|
|
for (int i = 0; i < 20; i++) {
|
|
|
|
if (startDirectSound()) {
|
|
|
|
soundReady = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
Sleep(500);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Throw error if sound unavailable
|
|
|
|
if (!soundReady) {
|
2023-06-13 11:59:03 -04:00
|
|
|
MessageBoxA(NULL, "\"LEGO\xAE Island\" is not detecting a DirectSound compatible sound card. Please quit all other applications and try again.",
|
2023-06-19 00:45:25 -04:00
|
|
|
"Lego Island Error", MB_OK);
|
2023-04-27 22:19:39 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create global app instance
|
|
|
|
g_isle = new Isle();
|
|
|
|
|
|
|
|
// Create window
|
2023-06-19 00:51:06 -04:00
|
|
|
if (g_isle->SetupWindow(hInstance) != SUCCESS) {
|
2023-06-19 00:45:25 -04:00
|
|
|
MessageBoxA(NULL, "\"LEGO\xAE Island\" failed to start. Please quit all other applications and try again.", "LEGO\xAE Island Error", MB_OK);
|
2023-04-27 22:19:39 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get reference to window
|
|
|
|
HWND window;
|
|
|
|
if (g_isle->m_windowHandle) {
|
|
|
|
window = g_isle->m_windowHandle;
|
|
|
|
}
|
|
|
|
|
2023-06-11 04:46:30 -04:00
|
|
|
// Load accelerator (this call actually achieves nothing - there is no "AppAccel" resource in the original - but we'll keep this for authenticity)
|
2023-04-27 22:19:39 -04:00
|
|
|
LoadAcceleratorsA(hInstance, "AppAccel");
|
|
|
|
|
|
|
|
MSG msg;
|
|
|
|
|
|
|
|
while (!g_closed) {
|
|
|
|
while (!PeekMessageA(&msg, NULL, 0, 0, PM_NOREMOVE)) {
|
|
|
|
if (g_isle) {
|
2023-06-19 00:51:06 -04:00
|
|
|
g_isle->Tick(1);
|
2023-04-27 22:19:39 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (g_isle) {
|
2023-06-19 00:51:06 -04:00
|
|
|
g_isle->Tick(1);
|
2023-04-27 22:19:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (g_closed) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
do {
|
|
|
|
if (!PeekMessageA(&msg, NULL, 0, 0, PM_REMOVE)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
MSG nextMsg;
|
|
|
|
if (!g_isle
|
|
|
|
|| !g_isle->m_windowHandle
|
|
|
|
|| msg.message != WM_MOUSEMOVE
|
|
|
|
|| !PeekMessageA(&nextMsg, NULL, 0, 0, PM_NOREMOVE)
|
|
|
|
|| nextMsg.message != WM_MOUSEMOVE) {
|
|
|
|
TranslateMessage(&msg);
|
|
|
|
DispatchMessageA(&msg);
|
|
|
|
}
|
|
|
|
|
2023-06-11 01:11:05 -04:00
|
|
|
if (g_reqEnableRMDevice) {
|
|
|
|
g_reqEnableRMDevice = 0;
|
2023-04-27 22:19:39 -04:00
|
|
|
VideoManager()->EnableRMDevice();
|
2023-06-11 01:11:05 -04:00
|
|
|
g_rmDisabled = 0;
|
2023-04-27 22:19:39 -04:00
|
|
|
Lego()->vtable3c();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (g_closed) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (g_mousedown == 0) {
|
|
|
|
LAB_00401bc7:
|
|
|
|
if (g_mousemoved) {
|
|
|
|
g_mousemoved = FALSE;
|
|
|
|
}
|
|
|
|
} else if (g_mousemoved) {
|
|
|
|
if (g_isle) {
|
2023-06-19 00:51:06 -04:00
|
|
|
g_isle->Tick(0);
|
2023-04-27 22:19:39 -04:00
|
|
|
}
|
|
|
|
goto LAB_00401bc7;
|
|
|
|
}
|
|
|
|
} while (!g_closed);
|
|
|
|
}
|
|
|
|
|
|
|
|
DestroyWindow(window);
|
|
|
|
|
|
|
|
return msg.wParam;
|
|
|
|
}
|