Merge branch 'master' into pr/43

This commit is contained in:
itsmattkc 2023-06-27 18:31:09 -07:00
commit 2a5e6490dc
22 changed files with 1010 additions and 582 deletions

View File

@ -29,7 +29,7 @@ jobs:
if: steps.cache-dx5.outputs.cache-hit != 'true'
run: |
cd dx5sdk
C:\msys64\usr\bin\wget.exe https://archive.org/download/idx5sdk/idx5sdk.exe
curl -fLOSs https://archive.org/download/idx5sdk/idx5sdk.exe
7z x .\idx5sdk.exe
7z x .\DX5SDK.EXE
@ -57,12 +57,12 @@ jobs:
- name: Summarize Accuracy
shell: cmd
run: |
C:\msys64\usr\bin\wget.exe https://legoisland.org/download/ISLE.EXE
C:\msys64\usr\bin\wget.exe https://legoisland.org/download/LEGO1.DLL
curl -fLOSs https://legoisland.org/download/ISLE.EXE
curl -fLOSs https://legoisland.org/download/LEGO1.DLL
pip install capstone
pip install colorama
python3 tools/reccmp/reccmp.py -H ISLEPROGRESS.HTML ISLE.EXE Release/ISLE.EXE Release/ISLE.PDB .
python3 tools/reccmp/reccmp.py -H LEGO1PROGRESS.HTML LEGO1.DLL Release/LEGO1.DLL Release/LEGO1.PDB .
python3 tools/reccmp/reccmp.py -S ISLEPROGRESS.SVG --svg-icon tools/reccmp/isle.png -H ISLEPROGRESS.HTML ISLE.EXE Release/ISLE.EXE Release/ISLE.PDB .
python3 tools/reccmp/reccmp.py -S LEGO1PROGRESS.SVG -T 1929 --svg-icon tools/reccmp/lego1.png -H LEGO1PROGRESS.HTML LEGO1.DLL Release/LEGO1.DLL Release/LEGO1.PDB .
- name: Upload Artifact
uses: actions/upload-artifact@master
@ -72,3 +72,28 @@ jobs:
Release
ISLEPROGRESS.HTML
LEGO1PROGRESS.HTML
ISLEPROGRESS.SVG
LEGO1PROGRESS.SVG
- name: Upload Continuous Release
shell: bash
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Convert SVGs to PNG
INKSCAPE_DIR=inkscape-1.2.2_2022-12-09_732a01da63-x64
curl -fLOSs https://inkscape.org/gallery/item/37364/$INKSCAPE_DIR.7z
7z x $INKSCAPE_DIR.7z
$INKSCAPE_DIR/bin/inkscape -w 1024 ISLEPROGRESS.SVG -o ISLEPROGRESS.PNG
$INKSCAPE_DIR/bin/inkscape -w 1024 LEGO1PROGRESS.SVG -o LEGO1PROGRESS.PNG
curl -fLOSs https://raw.githubusercontent.com/probonopd/uploadtool/master/upload.sh
./upload.sh \
Release/ISLE.EXE \
Release/LEGO1.DLL \
ISLEPROGRESS.HTML \
ISLEPROGRESS.SVG \
ISLEPROGRESS.PNG \
LEGO1PROGRESS.HTML \
LEGO1PROGRESS.PNG \
LEGO1PROGRESS.SVG

View File

@ -6,7 +6,7 @@ Generally, decompilation is a fairly advanced skill. If you aren't already famil
## Ghidra Server
For documenting the original binaries and generating pseudocode that we decompile with, we primarily use [Ghidra](https://ghidra-sre.org/) (it's free and open source). To help with collaboration, we have a shared Ghidra repository with all of our current work. It is available to the public but read-only; to contribute to it yourself, you'll need approval from a current maintainer.
For documenting the original binaries and generating pseudocode that we decompile with, we primarily use [Ghidra](https://ghidra-sre.org/) (it's free and open source). To help with collaboration, we have a shared Ghidra repository with all of our current work. You are free to check it out and mess around with it locally, however to prevent sabotage, you will need to request permission before you can push back to the server (ask in the Matrix room).
To access the Ghidra repository, use the following details:
@ -21,6 +21,7 @@ In general, we're not exhaustively strict about coding style, but there are some
- `PascalCase` for classes and function names.
- `m_camelCase` for member variables.
- `g_camelCase` for global variables.
- `p_camelCase` for function parameters.
## Kinds of Contributions

View File

@ -1,7 +1,7 @@
#include "define.h"
// 0x410030
Isle *g_isle = 0;
IsleApp *g_isle = 0;
// 0x410034
unsigned char g_mousedown = 0;
@ -28,7 +28,7 @@ int g_targetWidth = 640;
int g_targetHeight = 480;
// 0x410060
unsigned int g_targetDepth = 16;
int g_targetDepth = 16;
// 0x410064
int g_reqEnableRMDevice = 0;

View File

@ -3,9 +3,9 @@
#include "legoinc.h"
class Isle;
class IsleApp;
extern Isle *g_isle;
extern IsleApp *g_isle;
extern int g_closed;
// 0x4101c4
#define WNDCLASS_NAME "Lego Island MainNoM App"
@ -18,7 +18,7 @@ extern int g_rmDisabled;
extern int g_waitingForTargetDepth;
extern int g_targetWidth;
extern int g_targetHeight;
extern unsigned int g_targetDepth;
extern int g_targetDepth;
extern int g_reqEnableRMDevice;
extern int g_startupDelay;
extern long g_lastFrameTime;

View File

@ -1,7 +1,21 @@
#include "isle.h"
#include "define.h"
#include <dsound.h>
#include "legoomni.h"
#include "legoanimationmanager.h"
#include "legobuildingmanager.h"
#include "legomodelpresenter.h"
#include "legopartpresenter.h"
#include "legoworldpresenter.h"
#include "mxdirectdraw.h"
#include "mxdsaction.h"
#include "res/resource.h"
// OFFSET: ISLE 0x401000
Isle::Isle()
IsleApp::IsleApp()
{
m_hdPath = NULL;
m_cdPath = NULL;
@ -38,7 +52,7 @@ Isle::Isle()
}
// OFFSET: ISLE 0x4011a0
Isle::~Isle()
IsleApp::~IsleApp()
{
if (LegoOmni::GetInstance()) {
Close();
@ -63,7 +77,7 @@ Isle::~Isle()
}
// OFFSET: ISLE 0x401260
void Isle::Close()
void IsleApp::Close()
{
MxDSAction ds;
ds.SetUnknown24(-2);
@ -97,8 +111,461 @@ void Isle::Close()
}
}
// OFFSET: ISLE 0x4013b0
BOOL IsleApp::SetupLegoOmni()
{
BOOL result = FALSE;
char mediaPath[256];
GetProfileStringA("LEGO Island", "MediaPath", "", mediaPath, sizeof(mediaPath));
BOOL failure = Lego()->Create(MxOmniCreateParam(mediaPath, (struct HWND__ *) m_windowHandle, m_videoParam, MxOmniCreateFlags())) == FAILURE;
if (!failure) {
VariableTable()->SetVariable("ACTOR_01", "");
TickleManager()->vtable1c(VideoManager(), 10);
result = TRUE;
}
return result;
}
// OFFSET: ISLE 0x401560
void IsleApp::SetupVideoFlags(BOOL fullScreen, BOOL flipSurfaces, BOOL backBuffers,
BOOL using8bit, BOOL using16bit, BOOL param_6, BOOL param_7,
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);
m_videoParam.SetDeviceName(deviceId);
if (using8bit) {
m_videoParam.flags().Set16Bit(0);
}
if (using16bit) {
m_videoParam.flags().Set16Bit(1);
}
}
BOOL FindExistingInstance(void);
BOOL StartDirectSound(void);
// OFFSET: ISLE 0x401610
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) {
MessageBoxA(NULL, "\"LEGO\xAE Island\" is not detecting a DirectSound compatible sound card. Please quit all other applications and try again.",
"Lego Island Error", MB_OK);
return 0;
}
// Create global app instance
g_isle = new IsleApp();
// Create window
if (g_isle->SetupWindow(hInstance, lpCmdLine) != SUCCESS) {
MessageBoxA(NULL, "\"LEGO\xAE Island\" failed to start. Please quit all other applications and try again.", "LEGO\xAE Island Error", MB_OK);
return 0;
}
// Get reference to window
HWND window;
if (g_isle->m_windowHandle) {
window = g_isle->m_windowHandle;
}
// Load accelerators (this call actually achieves nothing - there is no "AppAccel" resource in the original - but we'll keep this for authenticity)
// This line may actually be here because it's in DFVIEW, an example project that ships with
// MSVC420, and was such a clean example of a Win32 app, that it was later adapted
// into an "ExeSkeleton" sample for MSVC600. It's quite possible Mindscape derived
// this app from that example since they no longer had the luxury of the
// MFC AppWizard which we know they used for the frontend used during development (ISLEMFC.EXE, MAIN.EXE, et al.)
LoadAcceleratorsA(hInstance, "AppAccel");
MSG msg;
while (!g_closed) {
while (!PeekMessageA(&msg, NULL, 0, 0, PM_NOREMOVE)) {
if (g_isle) {
g_isle->Tick(1);
}
}
if (g_isle) {
g_isle->Tick(0);
}
while (!g_closed) {
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);
}
if (g_reqEnableRMDevice) {
g_reqEnableRMDevice = 0;
VideoManager()->EnableRMDevice();
g_rmDisabled = 0;
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) {
g_isle->Tick(0);
}
goto LAB_00401bc7;
}
}
}
DestroyWindow(window);
return msg.wParam;
}
// OFFSET: ISLE 0x401ca0
BOOL FindExistingInstance(void)
{
HWND hWnd = FindWindowA(WNDCLASS_NAME, WINDOW_TITLE);
if (hWnd) {
if (SetForegroundWindow(hWnd)) {
ShowWindow(hWnd, SW_RESTORE);
}
return 0;
}
return 1;
}
// OFFSET: ISLE 0x401ce0
BOOL StartDirectSound(void)
{
LPDIRECTSOUND lpDS = NULL;
HRESULT ret = DirectSoundCreate(NULL, &lpDS, NULL);
if (ret == DS_OK && lpDS != NULL) {
lpDS->Release();
return TRUE;
}
return FALSE;
}
// OFFSET: ISLE 0x401d20
LRESULT WINAPI WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
NotificationId type;
unsigned char keyCode = 0;
if (!g_isle) {
return DefWindowProcA(hWnd, uMsg, wParam, lParam);
}
switch (uMsg) {
case WM_PAINT:
return DefWindowProcA(hWnd, uMsg, wParam, lParam);
case WM_ACTIVATE:
return DefWindowProcA(hWnd, uMsg, wParam, lParam);
case WM_ACTIVATEAPP:
if (g_isle) {
if ((wParam != 0) && (g_isle->m_fullScreen)) {
MoveWindow(hWnd, g_windowRect.left, g_windowRect.top,
(g_windowRect.right - g_windowRect.left) + 1,
(g_windowRect.bottom - g_windowRect.top) + 1, TRUE);
}
g_isle->m_windowActive = wParam;
}
return DefWindowProcA(hWnd,uMsg,wParam,lParam);
case WM_CLOSE:
if (!g_closed && g_isle) {
if (g_isle) {
delete g_isle;
}
g_isle = NULL;
g_closed = TRUE;
return 0;
}
return DefWindowProcA(hWnd,uMsg,wParam,lParam);
case WM_GETMINMAXINFO:
((MINMAXINFO*) lParam)->ptMaxTrackSize.x = (g_windowRect.right - g_windowRect.left) + 1;
((MINMAXINFO*) lParam)->ptMaxTrackSize.y = (g_windowRect.bottom - g_windowRect.top) + 1;
((MINMAXINFO*) lParam)->ptMinTrackSize.x = (g_windowRect.right - g_windowRect.left) + 1;
((MINMAXINFO*) lParam)->ptMinTrackSize.y = (g_windowRect.bottom - g_windowRect.top) + 1;
return 0;
case WM_ENTERMENULOOP:
return DefWindowProcA(hWnd,uMsg,wParam,lParam);
case WM_SYSCOMMAND:
if (wParam == SC_SCREENSAVE) {
return 0;
}
if (wParam == SC_CLOSE && g_closed == 0) {
if (g_isle) {
if (g_rmDisabled) {
ShowWindow(g_isle->m_windowHandle, SW_RESTORE);
}
PostMessageA(g_isle->m_windowHandle, WM_CLOSE, 0, 0);
return 0;
}
} else if (g_isle && g_isle->m_fullScreen && (wParam == SC_MOVE || wParam == SC_KEYMENU)) {
return 0;
}
return DefWindowProcA(hWnd,uMsg,wParam,lParam);
case WM_EXITMENULOOP:
return DefWindowProcA(hWnd, uMsg, wParam, lParam);
case WM_MOVING:
if (g_isle && g_isle->m_fullScreen) {
GetWindowRect(hWnd, (LPRECT) lParam);
return 0;
}
return DefWindowProcA(hWnd, uMsg, wParam, lParam);
case WM_NCPAINT:
if (g_isle && g_isle->m_fullScreen) {
return 0;
}
return DefWindowProcA(hWnd, uMsg, wParam, lParam);
case WM_DISPLAYCHANGE:
if (g_isle && VideoManager() && g_isle->m_fullScreen && VideoManager()->m_unk74 && VideoManager()->m_unk74[0x220]) {
int targetWidth = LOWORD(lParam);
int targetHeight = HIWORD(lParam);
int targetDepth = wParam;
if (g_waitingForTargetDepth) {
g_waitingForTargetDepth = 0;
g_targetDepth = targetDepth;
}
else {
BOOL valid = FALSE;
if (targetWidth == g_targetWidth && targetHeight == g_targetHeight && g_targetDepth == targetDepth) {
valid = TRUE;
}
if (g_rmDisabled) {
if (valid) {
g_reqEnableRMDevice = 1;
}
}
else if (!valid) {
g_rmDisabled = 1;
Lego()->vtable38();
VideoManager()->DisableRMDevice();
}
}
}
return DefWindowProcA(hWnd, uMsg, wParam, lParam);
case WM_SETCURSOR:
if (g_isle) {
HCURSOR hCursor = g_isle->m_cursorCurrent;
if (hCursor == g_isle->m_cursorBusy || hCursor == g_isle->m_cursorNo || !hCursor) {
SetCursor(hCursor);
return 0;
}
}
break;
case WM_KEYDOWN:
// While this probably should be (HIWORD(lParam) & KF_REPEAT), this seems
// to be what the assembly is actually doing
if (lParam & (KF_REPEAT << 16)) {
return DefWindowProcA(hWnd, uMsg, wParam, lParam);
}
keyCode = wParam;
type = KEYDOWN;
break;
case WM_MOUSEMOVE:
g_mousemoved = 1;
type = MOUSEMOVE;
break;
case WM_TIMER:
type = TIMER;
break;
case WM_LBUTTONDOWN:
g_mousedown = 1;
type = MOUSEDOWN;
break;
case WM_LBUTTONUP:
g_mousedown = 0;
type = MOUSEUP;
break;
case 0x5400:
if (g_isle) {
g_isle->SetupCursor(wParam);
return 0;
}
break;
default:
return DefWindowProcA(hWnd,uMsg,wParam,lParam);
}
if (g_isle) {
if (InputManager()) {
InputManager()->QueueEvent(type, wParam, LOWORD(lParam), HIWORD(lParam), keyCode);
}
if (g_isle && g_isle->m_drawCursor && type == MOUSEMOVE) {
int x = LOWORD(lParam);
int y = HIWORD(lParam);
if (x >= 640) {
x = 639;
}
if (y >= 480) {
y = 479;
}
VideoManager()->MoveCursor(x,y);
}
}
return 0;
}
// OFFSET: ISLE 0x4023e0
MxResult IsleApp::SetupWindow(HINSTANCE hInstance, LPSTR lpCmdLine)
{
WNDCLASSA wndclass;
ZeroMemory(&wndclass, sizeof(WNDCLASSA));
LoadConfig();
SetupVideoFlags(m_fullScreen, m_flipSurfaces, m_backBuffersInVram, m_using8bit,
m_using16bit, m_unk24, FALSE, m_wideViewAngle, m_deviceId);
MxOmni::SetSound3D(m_use3dSound);
srand(timeGetTime() / 1000);
SystemParametersInfoA(SPI_SETMOUSETRAILS, 0, NULL, 0);
ZeroMemory(&wndclass, sizeof(WNDCLASSA));
wndclass.cbClsExtra = 0;
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = WndProc;
wndclass.cbWndExtra = 0;
wndclass.hIcon = LoadIconA(hInstance, MAKEINTRESOURCEA(APP_ICON));
wndclass.hCursor = m_cursorArrow = m_cursorCurrent = LoadCursorA(hInstance, MAKEINTRESOURCEA(ISLE_ARROW));
m_cursorBusy = LoadCursorA(hInstance, MAKEINTRESOURCEA(ISLE_BUSY));
m_cursorNo = LoadCursorA(hInstance, MAKEINTRESOURCEA(ISLE_NO));
wndclass.hInstance = hInstance;
wndclass.hbrBackground = (HBRUSH) GetStockObject(BLACK_BRUSH);
wndclass.lpszClassName = WNDCLASS_NAME;
if (!RegisterClassA(&wndclass)) {
return FAILURE;
}
if (m_fullScreen) {
AdjustWindowRectEx(&g_windowRect, WS_CAPTION | WS_SYSMENU, 0, WS_EX_APPWINDOW);
m_windowHandle = CreateWindowExA(
WS_EX_APPWINDOW,
WNDCLASS_NAME,
WINDOW_TITLE,
WS_CAPTION | WS_SYSMENU,
g_windowRect.left,
g_windowRect.top,
g_windowRect.right - g_windowRect.left + 1,
g_windowRect.bottom - g_windowRect.top + 1,
NULL, NULL, hInstance, NULL
);
} else {
AdjustWindowRectEx(&g_windowRect, WS_CAPTION | WS_SYSMENU, 0, WS_EX_APPWINDOW);
m_windowHandle = CreateWindowExA(
WS_EX_APPWINDOW,
WNDCLASS_NAME,
WINDOW_TITLE,
WS_CAPTION | WS_SYSMENU | WS_MAXIMIZEBOX | WS_MINIMIZEBOX,
CW_USEDEFAULT,
CW_USEDEFAULT,
g_windowRect.right - g_windowRect.left + 1,
g_windowRect.bottom - g_windowRect.top + 1,
NULL, NULL, hInstance, NULL
);
}
if (!m_windowHandle) {
return FAILURE;
}
if (m_fullScreen) {
MoveWindow(m_windowHandle, g_windowRect.left, g_windowRect.top, (g_windowRect.right - g_windowRect.left) + 1, (g_windowRect.bottom - g_windowRect.top) + 1, TRUE);
}
ShowWindow(m_windowHandle, SW_SHOWNORMAL);
UpdateWindow(m_windowHandle);
if (!SetupLegoOmni()) {
return FAILURE;
}
GameState()->SetSavePath(m_savePath);
GameState()->SerializePlayersInfo(1);
GameState()->SerializeScoreHistory(1);
int iVar10;
switch (m_islandQuality) {
case 0:
iVar10 = 1;
break;
case 1:
iVar10 = 2;
break;
default:
iVar10 = 100;
}
int uVar1 = (m_islandTexture == 0);
LegoModelPresenter::configureLegoModelPresenter(uVar1);
LegoPartPresenter::configureLegoPartPresenter(uVar1,iVar10);
LegoWorldPresenter::configureLegoWorldPresenter(m_islandQuality);
LegoBuildingManager::configureLegoBuildingManager(m_islandQuality);
LegoROI::configureLegoROI(iVar10);
LegoAnimationManager::configureLegoAnimationManager(m_islandQuality);
if (LegoOmni::GetInstance()) {
if (LegoOmni::GetInstance()->GetInputManager()) {
LegoOmni::GetInstance()->GetInputManager()->m_useJoystick = m_useJoystick;
LegoOmni::GetInstance()->GetInputManager()->m_joystickIndex = m_joystickIndex;
}
}
if (m_fullScreen) {
MoveWindow(m_windowHandle, g_windowRect.left, g_windowRect.top, (g_windowRect.right - g_windowRect.left) + 1, (g_windowRect.bottom - g_windowRect.top) + 1, TRUE);
}
ShowWindow(m_windowHandle, SW_SHOWNORMAL);
UpdateWindow(m_windowHandle);
return SUCCESS;
}
// OFFSET: ISLE 0x402740
BOOL Isle::ReadReg(LPCSTR name, LPSTR outValue, DWORD outSize)
BOOL IsleApp::ReadReg(LPCSTR name, LPSTR outValue, DWORD outSize)
{
HKEY hKey;
DWORD valueType;
@ -117,7 +584,7 @@ BOOL Isle::ReadReg(LPCSTR name, LPSTR outValue, DWORD outSize)
}
// OFFSET: ISLE 0x4027b0
int Isle::ReadRegBool(LPCSTR name, BOOL *out)
int IsleApp::ReadRegBool(LPCSTR name, BOOL *out)
{
char buffer[256];
@ -139,7 +606,7 @@ int Isle::ReadRegBool(LPCSTR name, BOOL *out)
}
// OFFSET: ISLE 0x402880
int Isle::ReadRegInt(LPCSTR name, int *out)
int IsleApp::ReadRegInt(LPCSTR name, int *out)
{
char buffer[256];
@ -152,7 +619,7 @@ int Isle::ReadRegInt(LPCSTR name, int *out)
}
// OFFSET: ISLE 0x4028d0
void Isle::LoadConfig()
void IsleApp::LoadConfig()
{
char buffer[1024];
@ -216,46 +683,76 @@ void Isle::LoadConfig()
}
}
// OFFSET: ISLE 0x401560
void Isle::SetupVideoFlags(BOOL fullScreen, BOOL flipSurfaces, BOOL backBuffers,
BOOL using8bit, BOOL using16bit, BOOL param_6, BOOL param_7,
BOOL wideViewAngle, char *deviceId)
// OFFSET: ISLE 0x402c20
inline void IsleApp::Tick(BOOL sleepIfNotNextFrame)
{
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);
m_videoParam.SetDeviceName(deviceId);
if (using8bit) {
m_videoParam.flags().Set16Bit(0);
}
if (using16bit) {
m_videoParam.flags().Set16Bit(1);
}
}
// OFFSET: ISLE 0x4013b0
BOOL Isle::SetupLegoOmni()
{
BOOL result = FALSE;
char mediaPath[256];
GetProfileStringA("LEGO Island", "MediaPath", "", mediaPath, sizeof(mediaPath));
BOOL failure = Lego()->Create(MxOmniCreateParam(mediaPath, (struct HWND__ *) m_windowHandle, m_videoParam, MxOmniCreateFlags())) == FAILURE;
if (!failure) {
VariableTable()->SetVariable("ACTOR_01", "");
TickleManager()->vtable1c(VideoManager(), 10);
result = TRUE;
if (!this->m_windowActive) {
Sleep(0);
return;
}
return result;
if (!Lego()) return;
if (!TickleManager()) return;
if (!Timer()) return;
long currentTime = Timer()->GetRealTime();
if (currentTime < g_lastFrameTime) {
g_lastFrameTime = -this->m_frameDelta;
}
if (this->m_frameDelta + g_lastFrameTime < currentTime) {
if (!Lego()->vtable40()) {
TickleManager()->Tickle();
}
g_lastFrameTime = currentTime;
if (g_startupDelay == 0) {
return;
}
g_startupDelay--;
if (g_startupDelay != 0) {
return;
}
LegoOmni::GetInstance()->CreateBackgroundAudio();
BackgroundAudioManager()->Enable(this->m_useMusic);
MxStreamController *stream = Streamer()->Open("\\lego\\scripts\\isle\\isle", 0);
MxDSAction ds;
if (!stream) {
stream = Streamer()->Open("\\lego\\scripts\\nocd", 0);
if (!stream) {
return;
}
ds.SetAtomId(stream->atom);
ds.SetUnknown24(-1);
ds.SetUnknown1c(0);
VideoManager()->EnableFullScreenMovie(TRUE, TRUE);
if (Start(&ds) != SUCCESS) {
return;
}
} else {
ds.SetAtomId(stream->atom);
ds.SetUnknown24(-1);
ds.SetUnknown1c(0);
if (Start(&ds) != SUCCESS) {
return;
}
this->m_gameStarted = 1;
}
return;
}
if (sleepIfNotNextFrame != 0)
Sleep(0);
}
// OFFSET: ISLE 0x402e80
void Isle::SetupCursor(WPARAM wParam)
void IsleApp::SetupCursor(WPARAM wParam)
{
switch (wParam) {
case 0:
@ -281,4 +778,4 @@ void Isle::SetupCursor(WPARAM wParam)
}
SetCursor(m_cursorCurrent);
}
}

View File

@ -2,47 +2,33 @@
#define ISLE_H
#include "legoinc.h"
#include "define.h"
#include "legoomni.h"
#include "legoanimationmanager.h"
#include "legobuildingmanager.h"
#include "legomodelpresenter.h"
#include "legopartpresenter.h"
#include "legoworldpresenter.h"
#include "mxresult.h"
#include "mxvideoparam.h"
#include "mxdirectdraw.h"
#include "mxdsaction.h"
#include "mxomni.h"
#include "res/resource.h"
class Isle
class IsleApp
{
public:
Isle();
~Isle();
IsleApp();
~IsleApp();
void Close();
BOOL SetupLegoOmni();
void SetupVideoFlags(BOOL fullScreen, BOOL flipSurfaces, BOOL backBuffers,
BOOL using8bit, BOOL using16bit, BOOL param_6, BOOL param_7,
BOOL wideViewAngle, char *deviceId);
MxResult SetupWindow(HINSTANCE hInstance, LPSTR lpCmdLine);
BOOL ReadReg(LPCSTR name, LPSTR outValue, DWORD outSize);
int ReadRegBool(LPCSTR name, BOOL *out);
int ReadRegInt(LPCSTR name, int *out);
MxResult SetupWindow(HINSTANCE hInstance, LPSTR lpCmdLine);
void Tick(BOOL sleepIfNotNextFrame);
BOOL SetupLegoOmni();
void LoadConfig();
void SetupVideoFlags(BOOL fullScreen, BOOL flipSurfaces, BOOL backBuffers,
BOOL using8bit, BOOL using16bit, BOOL param_6, BOOL param_7,
BOOL wideViewAngle, char *deviceId);
void Tick(BOOL sleepIfNotNextFrame);
void SetupCursor(WPARAM wParam);
// private:
// private:
// 0
LPSTR m_hdPath;
LPSTR m_cdPath;
@ -85,193 +71,6 @@ class Isle
HCURSOR m_cursorBusy;
HCURSOR m_cursorNo;
HCURSOR m_cursorCurrent;
};
extern LRESULT WINAPI WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
// OFFSET: ISLE 0x4023e0
inline MxResult Isle::SetupWindow(HINSTANCE hInstance, LPSTR lpCmdLine)
{
WNDCLASSA wndclass;
ZeroMemory(&wndclass, sizeof(WNDCLASSA));
LoadConfig();
SetupVideoFlags(m_fullScreen, m_flipSurfaces, m_backBuffersInVram, m_using8bit,
m_using16bit, m_unk24, FALSE, m_wideViewAngle, m_deviceId);
MxOmni::SetSound3D(m_use3dSound);
srand(timeGetTime() / 1000);
SystemParametersInfoA(SPI_SETMOUSETRAILS, 0, NULL, 0);
ZeroMemory(&wndclass, sizeof(WNDCLASSA));
wndclass.cbClsExtra = 0;
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = WndProc;
wndclass.cbWndExtra = 0;
wndclass.hIcon = LoadIconA(hInstance, MAKEINTRESOURCEA(APP_ICON));
wndclass.hCursor = m_cursorArrow = m_cursorCurrent = LoadCursorA(hInstance, MAKEINTRESOURCEA(ISLE_ARROW));
m_cursorBusy = LoadCursorA(hInstance, MAKEINTRESOURCEA(ISLE_BUSY));
m_cursorNo = LoadCursorA(hInstance, MAKEINTRESOURCEA(ISLE_NO));
wndclass.hInstance = hInstance;
wndclass.hbrBackground = (HBRUSH) GetStockObject(BLACK_BRUSH);
wndclass.lpszClassName = WNDCLASS_NAME;
if (!RegisterClassA(&wndclass)) {
return FAILURE;
}
if (m_fullScreen) {
AdjustWindowRectEx(&g_windowRect, WS_CAPTION | WS_SYSMENU, 0, WS_EX_APPWINDOW);
m_windowHandle = CreateWindowExA(
WS_EX_APPWINDOW,
WNDCLASS_NAME,
WINDOW_TITLE,
WS_CAPTION | WS_SYSMENU,
g_windowRect.left,
g_windowRect.top,
g_windowRect.right - g_windowRect.left + 1,
g_windowRect.bottom - g_windowRect.top + 1,
NULL, NULL, hInstance, NULL
);
} else {
AdjustWindowRectEx(&g_windowRect, WS_CAPTION | WS_SYSMENU, 0, WS_EX_APPWINDOW);
m_windowHandle = CreateWindowExA(
WS_EX_APPWINDOW,
WNDCLASS_NAME,
WINDOW_TITLE,
WS_CAPTION | WS_SYSMENU | WS_MAXIMIZEBOX | WS_MINIMIZEBOX,
CW_USEDEFAULT,
CW_USEDEFAULT,
g_windowRect.right - g_windowRect.left + 1,
g_windowRect.bottom - g_windowRect.top + 1,
NULL, NULL, hInstance, NULL
);
}
if (!m_windowHandle) {
return FAILURE;
}
if (m_fullScreen) {
MoveWindow(m_windowHandle, g_windowRect.left, g_windowRect.top, (g_windowRect.right - g_windowRect.left) + 1, (g_windowRect.bottom - g_windowRect.top) + 1, TRUE);
}
ShowWindow(m_windowHandle, SW_SHOWNORMAL);
UpdateWindow(m_windowHandle);
if (!SetupLegoOmni()) {
return FAILURE;
}
GameState()->SetSavePath(m_savePath);
GameState()->SerializePlayersInfo(1);
GameState()->SerializeScoreHistory(1);
int iVar10;
switch (m_islandQuality) {
case 0:
iVar10 = 1;
break;
case 1:
iVar10 = 2;
break;
default:
iVar10 = 100;
}
int uVar1 = (m_islandTexture == 0);
LegoModelPresenter::configureLegoModelPresenter(uVar1);
LegoPartPresenter::configureLegoPartPresenter(uVar1,iVar10);
LegoWorldPresenter::configureLegoWorldPresenter(m_islandQuality);
LegoBuildingManager::configureLegoBuildingManager(m_islandQuality);
LegoROI::configureLegoROI(iVar10);
LegoAnimationManager::configureLegoAnimationManager(m_islandQuality);
if (LegoOmni::GetInstance()) {
if (LegoOmni::GetInstance()->GetInputManager()) {
LegoOmni::GetInstance()->GetInputManager()->m_useJoystick = m_useJoystick;
LegoOmni::GetInstance()->GetInputManager()->m_joystickIndex = m_joystickIndex;
}
}
if (m_fullScreen) {
MoveWindow(m_windowHandle, g_windowRect.left, g_windowRect.top, (g_windowRect.right - g_windowRect.left) + 1, (g_windowRect.bottom - g_windowRect.top) + 1, TRUE);
}
ShowWindow(m_windowHandle, SW_SHOWNORMAL);
UpdateWindow(m_windowHandle);
return SUCCESS;
}
// OFFSET: ISLE 0x402c20
inline void Isle::Tick(BOOL sleepIfNotNextFrame)
{
if (!this->m_windowActive) {
Sleep(0);
return;
}
if (!Lego()) return;
if (!TickleManager()) return;
if (!Timer()) return;
long currentTime = Timer()->GetRealTime();
if (currentTime < g_lastFrameTime) {
g_lastFrameTime = -this->m_frameDelta;
}
if (this->m_frameDelta + g_lastFrameTime < currentTime) {
if (!Lego()->vtable40()) {
TickleManager()->Tickle();
}
g_lastFrameTime = currentTime;
if (g_startupDelay == 0) {
return;
}
g_startupDelay--;
if (g_startupDelay != 0) {
return;
}
LegoOmni::GetInstance()->CreateBackgroundAudio();
BackgroundAudioManager()->Enable(this->m_useMusic);
MxStreamController *stream = Streamer()->Open("\\lego\\scripts\\isle\\isle", 0);
MxDSAction ds;
if (!stream) {
stream = Streamer()->Open("\\lego\\scripts\\nocd", 0);
if (!stream) {
return;
}
ds.SetAtomId(stream->atom);
ds.SetUnknown24(-1);
ds.SetUnknown1c(0);
VideoManager()->EnableFullScreenMovie(TRUE, TRUE);
if (Start(&ds) != SUCCESS) {
return;
}
} else {
ds.SetAtomId(stream->atom);
ds.SetUnknown24(-1);
ds.SetUnknown1c(0);
if (Start(&ds) != SUCCESS) {
return;
}
this->m_gameStarted = 1;
}
return;
}
if (sleepIfNotNextFrame != 0)
Sleep(0);
}
#endif // ISLE_H

View File

@ -1,311 +0,0 @@
#include <dsound.h>
#include "legoinc.h"
#include "define.h"
#include "isle.h"
#include "legoomni.h"
// OFFSET: ISLE 0x401ca0
BOOL FindExistingInstance(void)
{
HWND hWnd = FindWindowA(WNDCLASS_NAME, WINDOW_TITLE);
if (hWnd) {
if (SetForegroundWindow(hWnd)) {
ShowWindow(hWnd, SW_RESTORE);
}
return 0;
}
return 1;
}
// OFFSET: ISLE 0x401ce0
BOOL StartDirectSound(void)
{
LPDIRECTSOUND lpDS = NULL;
HRESULT ret = DirectSoundCreate(NULL, &lpDS, NULL);
if (ret == DS_OK && lpDS != NULL) {
lpDS->Release();
return TRUE;
}
return FALSE;
}
// OFFSET: ISLE 0x401610
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) {
MessageBoxA(NULL, "\"LEGO\xAE Island\" is not detecting a DirectSound compatible sound card. Please quit all other applications and try again.",
"Lego Island Error", MB_OK);
return 0;
}
// Create global app instance
g_isle = new Isle();
// Create window
if (g_isle->SetupWindow(hInstance, lpCmdLine) != SUCCESS) {
MessageBoxA(NULL, "\"LEGO\xAE Island\" failed to start. Please quit all other applications and try again.", "LEGO\xAE Island Error", MB_OK);
return 0;
}
// Get reference to window
HWND window;
if (g_isle->m_windowHandle) {
window = g_isle->m_windowHandle;
}
// Load accelerators (this call actually achieves nothing - there is no "AppAccel" resource in the original - but we'll keep this for authenticity)
// This line may actually be here because it's in DFVIEW, an example project that ships with
// MSVC420, and was such a clean example of a Win32 app, that it was later adapted
// into an "ExeSkeleton" sample for MSVC600. It's quite possible Mindscape derived
// this app from that example since they no longer had the luxury of the
// MFC AppWizard which we know they used for the frontend used during development (ISLEMFC.EXE, MAIN.EXE, et al.)
LoadAcceleratorsA(hInstance, "AppAccel");
MSG msg;
while (!g_closed) {
while (!PeekMessageA(&msg, NULL, 0, 0, PM_NOREMOVE)) {
if (g_isle) {
g_isle->Tick(1);
}
}
if (g_isle) {
g_isle->Tick(0);
}
while (!g_closed) {
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);
}
if (g_reqEnableRMDevice) {
g_reqEnableRMDevice = 0;
VideoManager()->EnableRMDevice();
g_rmDisabled = 0;
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) {
g_isle->Tick(0);
}
goto LAB_00401bc7;
}
}
}
DestroyWindow(window);
return msg.wParam;
}
// OFFSET: ISLE 0x401d20
LRESULT WINAPI WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
if (!g_isle) {
return DefWindowProcA(hWnd, uMsg, wParam, lParam);
}
switch (uMsg) {
case WM_PAINT:
return DefWindowProcA(hWnd, WM_PAINT, wParam, lParam);
case WM_ACTIVATE:
return DefWindowProcA(hWnd, WM_ACTIVATE, wParam, lParam);
case WM_ACTIVATEAPP:
if (g_isle) {
if ((wParam != 0) && (g_isle->m_fullScreen)) {
MoveWindow(hWnd, g_windowRect.left, g_windowRect.top,
(g_windowRect.right - g_windowRect.left) + 1,
(g_windowRect.bottom - g_windowRect.top) + 1, TRUE);
}
g_isle->m_windowActive = wParam;
}
return DefWindowProcA(hWnd,WM_ACTIVATEAPP,wParam,lParam);
case WM_CLOSE:
if (!g_closed && g_isle) {
if (g_isle) {
delete g_isle;
}
g_isle = NULL;
g_closed = TRUE;
return 0;
}
return DefWindowProcA(hWnd,WM_CLOSE,wParam,lParam);
case WM_GETMINMAXINFO:
{
MINMAXINFO *mmi = (MINMAXINFO *) lParam;
mmi->ptMaxTrackSize.x = (g_windowRect.right - g_windowRect.left) + 1;
mmi->ptMaxTrackSize.y = (g_windowRect.bottom - g_windowRect.top) + 1;
mmi->ptMinTrackSize.x = (g_windowRect.right - g_windowRect.left) + 1;
mmi->ptMinTrackSize.y = (g_windowRect.bottom - g_windowRect.top) + 1;
return 0;
}
case WM_ENTERMENULOOP:
return DefWindowProcA(hWnd,WM_ENTERMENULOOP,wParam,lParam);
case WM_SYSCOMMAND:
if (wParam == SC_SCREENSAVE) {
return 0;
}
if (wParam == SC_CLOSE && g_closed == 0) {
if (g_isle) {
if (g_rmDisabled) {
ShowWindow(g_isle->m_windowHandle, SW_RESTORE);
}
PostMessageA(g_isle->m_windowHandle, WM_CLOSE, 0, 0);
return 0;
}
} else if (g_isle && g_isle->m_fullScreen && (wParam == SC_MOVE || wParam == SC_KEYMENU)) {
return 0;
}
return DefWindowProcA(hWnd,WM_SYSCOMMAND,wParam,lParam);
case WM_EXITMENULOOP:
return DefWindowProcA(hWnd, WM_EXITMENULOOP, wParam, lParam);
case WM_MOVING:
if (g_isle && g_isle->m_fullScreen) {
GetWindowRect(hWnd, (LPRECT) lParam);
return 0;
}
return DefWindowProcA(hWnd, WM_MOVING, wParam, lParam);
case WM_NCPAINT:
if (g_isle && g_isle->m_fullScreen) {
return 0;
}
return DefWindowProcA(hWnd, WM_NCPAINT, wParam, lParam);
case WM_DISPLAYCHANGE:
if (g_isle && VideoManager() && g_isle->m_fullScreen && VideoManager()->m_unk74 && VideoManager()->m_unk74[0x220]) {
if (!g_waitingForTargetDepth) {
unsigned char valid = FALSE;
if (LOWORD(lParam) == g_targetWidth && HIWORD(lParam) == g_targetHeight && g_targetDepth == wParam) {
valid = TRUE;
}
if (!g_rmDisabled) {
if (!valid) {
g_rmDisabled = 1;
Lego()->vtable38();
VideoManager()->DisableRMDevice();
}
} else if (valid) {
g_reqEnableRMDevice = 1;
}
} else {
g_waitingForTargetDepth = 0;
g_targetDepth = wParam;
}
}
return DefWindowProcA(hWnd, WM_DISPLAYCHANGE, wParam, lParam);
case WM_SETCURSOR:
case WM_KEYDOWN:
case WM_MOUSEMOVE:
case WM_TIMER:
case WM_LBUTTONDOWN:
case WM_LBUTTONUP:
case 0x5400:
{
NotificationId type = NONE;
unsigned char keyCode = 0;
switch (uMsg) {
case WM_KEYDOWN:
// While this probably should be (HIWORD(lParam) & KF_REPEAT), this seems
// to be what the assembly is actually doing
if (lParam & (KF_REPEAT << 16)) {
return DefWindowProcA(hWnd, WM_KEYDOWN, wParam, lParam);
}
keyCode = wParam;
type = KEYDOWN;
break;
case WM_MOUSEMOVE:
g_mousemoved = 1;
type = MOUSEMOVE;
break;
case WM_TIMER:
type = TIMER;
break;
case WM_SETCURSOR:
if (g_isle) {
HCURSOR hCursor = g_isle->m_cursorCurrent;
if (hCursor == g_isle->m_cursorBusy || hCursor == g_isle->m_cursorNo || !hCursor) {
SetCursor(hCursor);
return 0;
}
}
break;
case WM_LBUTTONDOWN:
g_mousedown = 1;
type = MOUSEDOWN;
break;
case WM_LBUTTONUP:
g_mousedown = 0;
type = MOUSEUP;
break;
case 0x5400:
if (g_isle) {
g_isle->SetupCursor(wParam);
return 0;
}
}
if (g_isle) {
if (InputManager()) {
InputManager()->QueueEvent(type, wParam, LOWORD(lParam), HIWORD(lParam), keyCode);
}
if (g_isle && g_isle->m_drawCursor && type == MOUSEMOVE) {
unsigned short x = LOWORD(lParam);
unsigned short y = HIWORD(lParam);
if (639 < x) {
x = 639;
}
if (479 < y) {
y = 479;
}
VideoManager()->MoveCursor(x,y);
}
}
return 0;
}
}
return DefWindowProcA(hWnd,uMsg,wParam,lParam);
}

View File

@ -1,6 +1,130 @@
#include "mxdsfile.h"
#include <stdio.h>
#define SI_MAJOR_VERSION 2
#define SI_MINOR_VERSION 2
#define FOURCC(a, b, c, d) (((a) << 0) | ((b) << 8) | ((c) << 16) | ((d) << 24))
// OFFSET: LEGO1 0x100cc4b0
MxDSFile::MxDSFile(const char *filename, unsigned long skipReadingChunks)
{
m_filename = filename;
m_skipReadingChunks = skipReadingChunks;
}
// OFFSET: LEGO1 0x100bfed0
MxDSFile::~MxDSFile()
{
Close();
}
// OFFSET: LEGO1 0x100cc590
long MxDSFile::Open(unsigned long uStyle)
{
// No idea what's stopping this one matching, but I'm pretty
// confident it has the correct behavior.
long longResult = 1;
memset(&m_io, 0, sizeof(MXIOINFO));
if (m_io.Open(m_filename.GetData(), uStyle) != 0) {
return -1;
}
m_io.SetBuffer(NULL, 0, 0);
m_position = 0;
if (m_skipReadingChunks == 0) {
longResult = ReadChunks();
}
if (longResult != 0) {
Close(); // vtable + 0x18
}
else {
Seek(0, 0); // vtable + 0x24
}
return longResult;
}
// OFFSET: LEGO1 0x100cc780
long MxDSFile::Read(unsigned char *pch, unsigned long cch)
{
if (m_io.Read((char*)pch, cch) != cch)
return -1;
m_position += cch;
return 0;
}
// OFFSET: LEGO1 0x100cc620
long MxDSFile::ReadChunks()
{
_MMCKINFO topChunk;
_MMCKINFO childChunk;
char tempBuffer[80];
topChunk.fccType = FOURCC('O', 'M', 'N', 'I');
if (m_io.Descend(&topChunk, NULL, MMIO_FINDRIFF) != 0) {
return -1;
}
childChunk.ckid = FOURCC('M', 'x', 'H', 'd');
if (m_io.Descend(&childChunk, &topChunk, 0) != 0) {
return -1;
}
m_io.Read((char*)&m_header, 0xc);
if ((m_header.majorVersion == SI_MAJOR_VERSION) && (m_header.minorVersion == SI_MINOR_VERSION))
{
childChunk.ckid = FOURCC('M', 'x', 'O', 'f');
if (m_io.Descend(&childChunk, &topChunk, 0) != 0) {
return -1;
}
unsigned long* pLengthInDWords = &m_lengthInDWords;
m_io.Read((char *)pLengthInDWords, 4);
m_pBuffer = malloc(*pLengthInDWords * 4);
m_io.Read((char*)m_pBuffer, *pLengthInDWords * 4);
return 0;
}
else
{
sprintf(tempBuffer, "Wrong SI file version. %d.%d expected.", SI_MAJOR_VERSION, SI_MINOR_VERSION);
MessageBoxA(NULL, tempBuffer, NULL, MB_ICONERROR);
return -1;
}
}
// OFFSET: LEGO1 0x100cc7b0
long MxDSFile::Seek(long lOffset, int iOrigin)
{
return (m_position = m_io.Seek(lOffset, iOrigin)) == -1 ? -1 : 0;
}
// OFFSET: LEGO1 0x100cc7e0
unsigned long MxDSFile::GetBufferSize()
{
return this->m_buffersize;
return m_header.bufferSize;
}
// OFFSET: LEGO1 0x100cc7f0
unsigned long MxDSFile::GetStreamBuffersNum()
{
return m_header.streamBuffersNum;
}
// OFFSET: LEGO1 0x100cc740
long MxDSFile::Close()
{
m_io.Close(0);
m_position = -1;
memset(&m_header, 0, sizeof(m_header));
if (m_lengthInDWords != 0)
{
m_lengthInDWords = 0;
free(m_pBuffer);
m_pBuffer = NULL;
}
return 0;
}

View File

@ -6,7 +6,7 @@
class MxDSFile : public MxDSSource
{
public:
__declspec(dllexport) MxDSFile(const char *,unsigned long);
__declspec(dllexport) MxDSFile(const char *filename, unsigned long skipReadingChunks);
__declspec(dllexport) virtual ~MxDSFile(); // vtable+0x0
__declspec(dllexport) virtual long Open(unsigned long); // vtable+0x14
__declspec(dllexport) virtual long Close(); // vtable+0x18
@ -15,8 +15,29 @@ class MxDSFile : public MxDSSource
__declspec(dllexport) virtual unsigned long GetBufferSize(); // vtable+0x28
__declspec(dllexport) virtual unsigned long GetStreamBuffersNum(); // vtable+0x2c
private:
char m_unknown[0x70];
unsigned long m_buffersize;
long ReadChunks();
struct ChunkHeader {
ChunkHeader()
: majorVersion(0)
, minorVersion(0)
, bufferSize(0)
, streamBuffersNum(0)
{}
unsigned short majorVersion;
unsigned short minorVersion;
unsigned long bufferSize;
short streamBuffersNum;
short reserved;
};
MxString m_filename;
MXIOINFO m_io;
ChunkHeader m_header;
// If false, read chunks immediately on open, otherwise
// skip reading chunks until ReadChunks is explicitly called.
unsigned long m_skipReadingChunks;
};
#endif // MXDSFILE_H

14
LEGO1/mxdssource.cpp Normal file
View File

@ -0,0 +1,14 @@
#include "mxdssource.h"
// OFFSET: LEGO1 0x100bffd0
void MxDSSource::SomethingWhichCallsRead(void* pUnknownObject)
{
// TODO: Calls read, reading into a buffer somewhere in pUnknownObject.
Read(NULL, 0);
}
// OFFSET: LEGO1 0x100bfff0
long MxDSSource::GetLengthInDWords()
{
return m_lengthInDWords;
}

View File

@ -5,7 +5,26 @@
class MxDSSource : public MxCore
{
public:
MxDSSource()
: m_lengthInDWords(0)
, m_pBuffer(0)
, m_position(-1)
{}
virtual long Open(unsigned long) = 0;
virtual long Close() = 0;
virtual void SomethingWhichCallsRead(void* pUnknownObject);
virtual long Read(unsigned char *, unsigned long) = 0;
virtual long Seek(long, int) = 0;
virtual unsigned long GetBufferSize() = 0;
virtual unsigned long GetStreamBuffersNum() = 0;
virtual long GetLengthInDWords();
protected:
unsigned long m_lengthInDWords;
void* m_pBuffer;
long m_position;
};
#endif // MXDSSOURCE_H

49
LEGO1/mxioinfo.cpp Normal file
View File

@ -0,0 +1,49 @@
#include "mxioinfo.h"
// OFFSET: LEGO1 0x100cc800
MXIOINFO::MXIOINFO()
{
memset(&m_info, 0, sizeof(MMIOINFO));
}
// OFFSET: LEGO1 0x100cc820
MXIOINFO::~MXIOINFO()
{
Close(0);
}
// OFFSET: LEGO1 0x100cc830
unsigned short MXIOINFO::Open(const char *filename, DWORD fdwOpen)
{
return 0;
}
// OFFSET: LEGO1 0x100cc8e0
void MXIOINFO::Close(long arg)
{
}
// OFFSET: LEGO1 0x100cc930
unsigned long MXIOINFO::Read(HPSTR pch, LONG cch)
{
return 0;
}
// OFFSET: LEGO1 0x100cca00
LONG MXIOINFO::Seek(LONG lOffset, int iOrigin)
{
return 0;
}
// OFFSET: LEGO1 0x100ccbc0
void MXIOINFO::SetBuffer(LPSTR pchBuffer, LONG cchBuffer, LONG unk)
{
}
// OFFSET: LEGO1 0x100cce60
unsigned short MXIOINFO::Descend(LPMMCKINFO pmmcki, const MMCKINFO *pmmckiParent, UINT fuDescend)
{
return 0;
}

View File

@ -1,10 +1,22 @@
#ifndef MXIOINFO_H
#define MXIOINFO_H
#include "legoinc.h"
#include "mmsystem.h"
class MXIOINFO
{
public:
MXIOINFO();
__declspec(dllexport) ~MXIOINFO();
unsigned short Open(const char *filename, DWORD fdwOpen);
void Close(long arg);
LONG Seek(LONG lOffset, int iOrigin);
unsigned long Read(HPSTR pch, LONG cch);
void SetBuffer(LPSTR pchBuffer, LONG cchBuffer, LONG unk);
unsigned short Descend(LPMMCKINFO pmmcki, const MMCKINFO *pmmckiParent, UINT fuDescend);
MMIOINFO m_info;
};
#endif // MXIOINFO_H

0
LEGO1/mxpalette.cpp Executable file → Normal file
View File

View File

@ -16,6 +16,8 @@ class MxString : public MxCore
void ToLowerCase();
const MxString &operator=(MxString *);
inline const char *GetData() const { return m_data; }
private:
char *m_data;
unsigned short m_length;

0
LEGO1/mxunknown100dc6b0.cpp Executable file → Normal file
View File

0
LEGO1/mxunknown100dc6b0.h Executable file → Normal file
View File

View File

@ -6,7 +6,7 @@ This is a **work-in-progress** decompilation of LEGO Island version 1.1. It aims
## Status
*TODO: A progress bar showing the percentage progress of this decompilation.*
<img src="https://github.com/isledecomp/isle/releases/download/continuous/ISLEPROGRESS.PNG" width="50%"><img src="https://github.com/isledecomp/isle/releases/download/continuous/LEGO1PROGRESS.PNG" width="50%">
Currently `ISLE.EXE` is completely decompiled, however there are some known inaccuracies. It should work if you pair it with the original game's `LEGO1.DLL` (and other files), however small things may not work correctly yet. Work on decompiling `LEGO1.DLL` has only just started and currently it is too incomplete to be usable.

BIN
tools/reccmp/isle.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

BIN
tools/reccmp/lego1.png Executable file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.5 KiB

View File

@ -1,6 +1,7 @@
#!/usr/bin/env python3
import argparse
import base64
from capstone import *
import difflib
import struct
@ -15,9 +16,12 @@
parser.add_argument('recompiled', metavar='recompiled-binary', help='The recompiled binary')
parser.add_argument('pdb', metavar='recompiled-pdb', help='The PDB of the recompiled binary')
parser.add_argument('decomp_dir', metavar='decomp-dir', help='The decompiled source tree')
parser.add_argument('--total', '-T', metavar='total-func-count', help='Total number of expected functions (improves total accuracy statistic)')
parser.add_argument('--verbose', '-v', metavar='offset', help='Print assembly diff for specific function (original file\'s offset)')
parser.add_argument('--html', '-H', metavar='output-file', help='Generate searchable HTML summary of status and diffs')
parser.add_argument('--no-color', '-n', action='store_true', help='Do not color the output')
parser.add_argument('--svg', '-S', metavar='output-svg', help='Generate SVG graphic of progress')
parser.add_argument('--svg-icon', metavar='svg-icon', help='Icon to use in SVG (PNG)')
args = parser.parse_args()
@ -50,6 +54,8 @@
if not os.path.isdir(source):
parser.error('Source directory does not exist')
svg = args.svg
# Declare a class that can automatically convert virtual executable addresses
# to file addresses
class Bin:
@ -365,7 +371,8 @@ def parse_asm(file, addr, size):
# If html, record the diffs to an HTML file
if html:
htmlinsert.append('{address: "%s", name: "%s", matching: %s, diff: "%s"}' % (hex(addr), recinfo.name, str(ratio), '\\n'.join(udiff).replace('"', '\\"').replace('\n', '\\n')))
escaped = '\\n'.join(udiff).replace('"', '\\"').replace('\n', '\\n').replace('<', '&lt;').replace('>', '&gt;')
htmlinsert.append('{address: "%s", name: "%s", matching: %s, diff: "%s"}' % (hex(addr), recinfo.name, str(ratio), escaped))
except UnicodeDecodeError:
break
@ -389,6 +396,49 @@ def gen_html(html, data):
htmlfile.write(templatedata)
htmlfile.close()
def gen_svg(svg, name, icon, implemented_funcs, total_funcs, raw_accuracy):
templatefile = open(get_file_in_script_dir('template.svg'), 'r')
if not templatefile:
print('Failed to find SVG template file, can\'t generate SVG summary')
return
templatedata = templatefile.read()
templatefile.close()
# Replace icon
if args.svg_icon:
iconfile = open(args.svg_icon, 'rb')
templatedata = templatedata.replace('{icon}', base64.b64encode(iconfile.read()).decode('utf-8'), 1)
iconfile.close()
# Replace name
templatedata = templatedata.replace('{name}', name, 1)
# Replace implemented statistic
templatedata = templatedata.replace('{implemented}', '%.2f%% (%i/%i)' % (implemented_funcs / total_funcs * 100, implemented_funcs, total_funcs), 1)
# Replace accuracy statistic
templatedata = templatedata.replace('{accuracy}', '%.2f%%' % (raw_accuracy / implemented_funcs * 100), 1)
# Generate progress bar width
total_statistic = raw_accuracy / total_funcs
percenttemplate = '{progbar'
percentstart = templatedata.index(percenttemplate)
percentend = templatedata.index('}', percentstart)
progwidth = float(templatedata[percentstart + len(percenttemplate) + 1:percentend]) * total_statistic
templatedata = templatedata[0:percentstart] + str(progwidth) + templatedata[percentend + 1:]
# Replace percentage statistic
templatedata = templatedata.replace('{percent}', '%.2f%%' % (total_statistic * 100), 2)
svgfile = open(svg, 'w')
if not svgfile:
print('Failed to write to SVG file %s' % svg)
return
svgfile.write(templatedata)
svgfile.close()
if html:
gen_html(html, htmlinsert)
@ -396,5 +446,13 @@ def gen_html(html, data):
if not found_verbose_target:
print('Failed to find the function with address %s' % hex(verbose))
else:
implemented_funcs = function_count
if args.total:
function_count = int(args.total)
if function_count > 0:
print('\nTotal accuracy %.2f%% across %i functions' % (total_accuracy / function_count * 100, function_count))
if svg:
gen_svg(svg, os.path.basename(original), args.svg_icon, implemented_funcs, function_count, total_accuracy)

118
tools/reccmp/template.svg Normal file
View File

@ -0,0 +1,118 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
width="640"
height="480"
viewBox="0 0 169.33333 127"
version="1.1"
id="svg5"
xml:space="preserve"
sodipodi:docname="template.svg"
inkscape:version="1.2.2 (b0a8486541, 2022-12-01)"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns="http://www.w3.org/2000/svg"
xmlns:svg="http://www.w3.org/2000/svg"><sodipodi:namedview
id="namedview26"
pagecolor="#505050"
bordercolor="#eeeeee"
borderopacity="1"
inkscape:showpageshadow="0"
inkscape:pageopacity="0"
inkscape:pagecheckerboard="0"
inkscape:deskcolor="#505050"
showgrid="false"
inkscape:zoom="1.6046875"
inkscape:cx="239.29893"
inkscape:cy="219.98053"
inkscape:window-width="2560"
inkscape:window-height="1379"
inkscape:window-x="0"
inkscape:window-y="0"
inkscape:window-maximized="1"
inkscape:current-layer="svg5" /><defs
id="defs5">
<clipPath
id="progBarCutoff">
<rect
width="{progbar:127.18422}"
height="8.6508904"
x="21.074554"
y="134.86963"
id="rect2" />
</clipPath>
</defs><rect
x="0"
y="0"
width="100%"
height="100%"
fill="#0d1117"
id="rect7" /><g
id="g1273"
transform="matrix(1.2683581,0,0,1.2683581,-22.720969,-65.913871)"><image
width="53.066437"
height="53.066437"
preserveAspectRatio="none"
style="image-rendering:optimizeSpeed"
xlink:href="data:image/png;base64,{icon}"
id="image1060"
x="58.13345"
y="51.967873" /><text
xml:space="preserve"
style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:12.7px;font-family:mono;-inkscape-font-specification:mono;text-align:center;text-anchor:middle;fill:#ffffff;stroke:#ffffff;stroke-width:2.64583"
x="84.666656"
y="118.35877"
id="text740"><tspan
id="tspan738"
style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-family:mono;-inkscape-font-specification:mono;text-align:center;text-anchor:middle;stroke:none;stroke-width:2.64583"
x="84.666656"
y="118.35877">{name}</tspan></text><g
id="g1250"
transform="translate(-1.3006529e-5,8.5767994)"><rect
style="fill:none;stroke:#ffffff;stroke-width:0.87411;stroke-dasharray:none;stroke-opacity:1"
id="rect1167"
width="127.18422"
height="8.6508904"
x="21.074554"
y="134.86963" /><text
xml:space="preserve"
style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:4.23333px;font-family:mono;-inkscape-font-specification:mono;text-align:start;text-anchor:start;fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:1.05833;stroke-dasharray:none;stroke-opacity:1"
x="76.841347"
y="140.70638"
id="text2152"><tspan
style="font-size:4.23333px;fill:#ffffff;fill-opacity:1;stroke-width:1.05833"
x="76.841347"
y="140.70638"
id="tspan2150">{percent}</tspan></text><rect
style="display:inline;fill:#ffffff;stroke:none;stroke-width:2.6764"
id="rect1169"
width="127.18422"
height="8.6508904"
x="21.074554"
y="134.86963"
clip-path="url(#progBarCutoff)" /><text
xml:space="preserve"
style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:4.23333px;font-family:mono;-inkscape-font-specification:mono;text-align:start;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1.05833;stroke-dasharray:none;stroke-opacity:1"
x="76.841347"
y="140.70638"
id="text18"
clip-path="url(#progBarCutoff)"><tspan
style="font-size:4.23333px;fill:#000000;fill-opacity:1;stroke-width:1.05833"
x="76.841347"
y="140.70638"
id="tspan16">{percent}</tspan></text></g><text
xml:space="preserve"
style="font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:4.23333px;font-family:mono;-inkscape-font-specification:mono;text-align:start;text-anchor:start;fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:1.05833;stroke-dasharray:none;stroke-opacity:1"
x="46.947659"
y="129.67447"
id="text1260"><tspan
id="tspan1258"
style="font-size:4.23333px;stroke-width:1.05833"
x="46.947659"
y="129.67447">Implemented: {implemented}</tspan><tspan
style="font-size:4.23333px;stroke-width:1.05833"
x="46.947659"
y="134.96613"
id="tspan1262">Accuracy: {accuracy}</tspan></text></g></svg>

After

Width:  |  Height:  |  Size: 4.9 KiB