isle-portable/ISLE/isle.cpp

284 lines
6.2 KiB
C++
Raw Normal View History

2023-04-27 22:19:39 -04:00
#include "isle.h"
// OFFSET: ISLE 0x401000
2023-04-27 22:19:39 -04:00
Isle::Isle()
{
m_hdPath = NULL;
m_cdPath = NULL;
m_deviceId = NULL;
m_savePath = NULL;
m_fullScreen = 1;
m_flipSurfaces = 0;
m_backBuffersInVram = 1;
m_using8bit = 0;
m_using16bit = 1;
m_unk24 = 0;
m_drawCursor = 0;
m_use3dSound = 1;
m_useMusic = 1;
m_useJoystick = 0;
m_joystickIndex = 0;
m_wideViewAngle = 1;
m_islandQuality = 1;
m_islandTexture = 1;
m_gameStarted = 0;
m_frameDelta = 10;
m_windowActive = 1;
m_videoParam = MxVideoParam(MxRect32(0, 0, 639, 479), NULL, 1, MxVideoParamFlags());
m_videoParam.flags().Set16Bit(MxDirectDraw::GetPrimaryBitDepth() == 16);
2023-04-27 22:19:39 -04:00
m_windowHandle = NULL;
2023-04-27 23:34:11 -04:00
m_cursorArrow = NULL;
m_cursorBusy = NULL;
m_cursorNo = NULL;
m_cursorCurrent = NULL;
2023-04-27 22:19:39 -04:00
LegoOmni::CreateInstance();
}
// OFFSET: ISLE 0x4011a0
2023-04-27 22:19:39 -04:00
Isle::~Isle()
{
if (LegoOmni::GetInstance()) {
Close();
2023-04-27 22:19:39 -04:00
MxOmni::DestroyInstance();
}
if (m_hdPath) {
delete [] m_hdPath;
}
if (m_cdPath) {
delete [] m_cdPath;
}
if (m_deviceId) {
delete [] m_deviceId;
}
if (m_savePath) {
delete [] m_savePath;
}
}
// OFFSET: ISLE 0x401260
void Isle::Close()
2023-04-27 22:19:39 -04:00
{
MxDSAction ds;
ds.SetUnknown24(-2);
2023-04-27 22:19:39 -04:00
if (Lego()) {
GameState()->Save(0);
if (InputManager()) {
InputManager()->QueueEvent(KEYDOWN, 0, 0, 0, 0x20);
}
VideoManager()->Get3DManager()->GetLego3DView()->GetViewManager()->RemoveAll(NULL);
2023-04-27 22:19:39 -04:00
Lego()->RemoveWorld(ds.GetAtomId(), ds.GetUnknown1c());
2023-04-27 22:19:39 -04:00
Lego()->vtable24(ds);
TransitionManager()->SetWaitIndicator(NULL);
Lego()->vtable3c();
long lVar8;
do {
lVar8 = Streamer()->Close(NULL);
} while (lVar8 == 0);
while (Lego()) {
if (Lego()->vtable28(ds) != MX_FALSE) {
2023-04-27 22:19:39 -04:00
break;
}
Timer()->GetRealTime();
2023-05-22 00:45:25 -04:00
TickleManager()->Tickle();
2023-04-27 22:19:39 -04:00
}
}
}
// OFFSET: ISLE 0x402740
BOOL Isle::ReadReg(LPCSTR name, LPSTR outValue, DWORD outSize)
2023-04-27 22:19:39 -04:00
{
HKEY hKey;
DWORD valueType;
2023-06-11 05:48:27 -04:00
BOOL out = FALSE;
unsigned long size = outSize;
2023-04-27 22:19:39 -04:00
if (RegOpenKeyExA(HKEY_LOCAL_MACHINE, "SOFTWARE\\Mindscape\\LEGO Island", 0, KEY_READ, &hKey) == ERROR_SUCCESS) {
2023-06-11 05:48:27 -04:00
if (RegQueryValueExA(hKey, name, NULL, &valueType, (LPBYTE) outValue, &size) == ERROR_SUCCESS) {
2023-04-27 22:19:39 -04:00
if (RegCloseKey(hKey) == ERROR_SUCCESS) {
2023-06-11 05:48:27 -04:00
out = TRUE;
2023-04-27 22:19:39 -04:00
}
}
}
2023-06-11 05:48:27 -04:00
return out;
2023-04-27 22:19:39 -04:00
}
// OFFSET: ISLE 0x4027b0
int Isle::ReadRegBool(LPCSTR name, BOOL *out)
2023-04-27 22:19:39 -04:00
{
char buffer[256];
BOOL read = ReadReg(name, buffer, sizeof(buffer));
2023-04-27 22:19:39 -04:00
if (read) {
if (strcmp("YES", buffer) == 0) {
*out = TRUE;
return read;
2023-04-27 22:19:39 -04:00
}
if (strcmp("NO", buffer) == 0) {
*out = FALSE;
return read;
2023-04-27 22:19:39 -04:00
}
read = FALSE;
2023-04-27 22:19:39 -04:00
}
return read;
2023-04-27 22:19:39 -04:00
}
// OFFSET: ISLE 0x402880
int Isle::ReadRegInt(LPCSTR name, int *out)
2023-04-27 22:19:39 -04:00
{
char buffer[256];
BOOL read = ReadReg(name, buffer, sizeof(buffer));
if (read) {
2023-04-27 22:19:39 -04:00
*out = atoi(buffer);
}
return read;
2023-04-27 22:19:39 -04:00
}
// OFFSET: ISLE 0x4028d0
void Isle::LoadConfig()
2023-04-27 22:19:39 -04:00
{
char buffer[1024];
2023-06-12 16:06:10 -04:00
if (!ReadReg("diskpath", buffer, sizeof(buffer))) {
2023-04-27 22:19:39 -04:00
strcpy(buffer, MxOmni::GetHD());
}
m_hdPath = new char[strlen(buffer) + 1];
strcpy(m_hdPath, buffer);
MxOmni::SetHD(m_hdPath);
if (!ReadReg("cdpath", buffer, sizeof(buffer))) {
2023-04-27 22:19:39 -04:00
strcpy(buffer, MxOmni::GetCD());
}
m_cdPath = new char[strlen(buffer) + 1];
strcpy(m_cdPath, buffer);
MxOmni::SetCD(m_cdPath);
ReadRegBool("Flip Surfaces", &m_flipSurfaces);
ReadRegBool("Full Screen", &m_fullScreen);
ReadRegBool("Wide View Angle", &m_wideViewAngle);
ReadRegBool("3DSound", &m_use3dSound);
ReadRegBool("Music", &m_useMusic);
ReadRegBool("UseJoystick", &m_useJoystick);
ReadRegInt("JoystickIndex", &m_joystickIndex);
ReadRegBool("Draw Cursor", &m_drawCursor);
2023-04-27 22:19:39 -04:00
int backBuffersInVRAM;
if (ReadRegBool("Back Buffers in Video RAM",&backBuffersInVRAM)) {
2023-04-27 22:19:39 -04:00
m_backBuffersInVram = !backBuffersInVRAM;
}
int bitDepth;
if (ReadRegInt("Display Bit Depth", &bitDepth)) {
2023-04-27 22:19:39 -04:00
if (bitDepth == 8) {
m_using8bit = TRUE;
} else if (bitDepth == 16) {
m_using16bit = TRUE;
}
}
if (!ReadReg("Island Quality", buffer, sizeof(buffer))) {
2023-04-27 22:19:39 -04:00
strcpy(buffer, "1");
}
m_islandQuality = atoi(buffer);
if (!ReadReg("Island Texture", buffer, sizeof(buffer))) {
2023-04-27 22:19:39 -04:00
strcpy(buffer, "1");
}
m_islandTexture = atoi(buffer);
if (ReadReg("3D Device ID", buffer, sizeof(buffer))) {
2023-04-27 22:19:39 -04:00
m_deviceId = new char[strlen(buffer) + 1];
strcpy(m_deviceId, buffer);
}
if (ReadReg("savepath", buffer, sizeof(buffer))) {
2023-04-27 22:19:39 -04:00
m_savePath = new char[strlen(buffer) + 1];
strcpy(m_savePath, buffer);
}
}
// OFFSET: ISLE 0x401560
void Isle::SetupVideoFlags(BOOL fullScreen, BOOL flipSurfaces, BOOL backBuffers,
BOOL using8bit, BOOL using16bit, BOOL param_6, BOOL param_7,
2023-04-27 22:19:39 -04:00
BOOL wideViewAngle, char *deviceId)
{
m_videoParam.flags().SetFullScreen(fullScreen);
m_videoParam.flags().SetFlipSurfaces(flipSurfaces);
m_videoParam.flags().SetBackBuffers(!backBuffers);
m_videoParam.flags().Set_f2bit0(!param_6);
m_videoParam.flags().Set_f1bit7(param_7);
m_videoParam.flags().SetWideViewAngle(wideViewAngle);
m_videoParam.flags().Set_f2bit1(1);
2023-04-27 22:19:39 -04:00
m_videoParam.SetDeviceName(deviceId);
if (using8bit) {
m_videoParam.flags().Set16Bit(0);
2023-04-27 22:19:39 -04:00
}
if (using16bit) {
m_videoParam.flags().Set16Bit(1);
2023-04-27 22:19:39 -04:00
}
}
// OFFSET: ISLE 0x4013b0
BOOL Isle::SetupLegoOmni()
2023-04-27 22:19:39 -04:00
{
BOOL result = FALSE;
2023-04-27 22:19:39 -04:00
char mediaPath[256];
GetProfileStringA("LEGO Island", "MediaPath", "", mediaPath, sizeof(mediaPath));
2023-04-27 22:19:39 -04:00
BOOL failure = Lego()->Create(MxOmniCreateParam(mediaPath, (struct HWND__ *) m_windowHandle, m_videoParam, MxOmniCreateFlags())) == FAILURE;
if (!failure) {
2023-04-27 22:19:39 -04:00
VariableTable()->SetVariable("ACTOR_01", "");
TickleManager()->vtable1c(VideoManager(), 10);
result = TRUE;
2023-04-27 22:19:39 -04:00
}
return result;
2023-04-27 22:19:39 -04:00
}
// OFFSET: ISLE 0x402e80
void Isle::SetupCursor(WPARAM wParam)
2023-04-27 23:34:11 -04:00
{
switch (wParam) {
case 0:
m_cursorCurrent = m_cursorArrow;
break;
case 1:
m_cursorCurrent = m_cursorBusy;
break;
case 2:
m_cursorCurrent = m_cursorNo;
break;
case 0xB:
m_cursorCurrent = NULL;
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
case 9:
case 0xA:
2023-04-27 23:34:11 -04:00
break;
}
SetCursor(m_cursorCurrent);
}