2018-08-19 09:46:58 +02:00
|
|
|
#include "game.h"
|
2018-08-30 10:32:32 +03:00
|
|
|
#include "init.h"
|
2018-08-19 09:46:58 +02:00
|
|
|
#include "winmain.h"
|
|
|
|
#include <process.h>
|
|
|
|
#include <crtdbg.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include "..\Game\draw.h"
|
|
|
|
#include "..\Game\sound.h"
|
|
|
|
#include "..\Game\inventory.h"
|
|
|
|
#include "..\Game\control.h"
|
|
|
|
#include "..\Game\gameflow.h"
|
|
|
|
|
|
|
|
WINAPP App;
|
|
|
|
unsigned int threadId;
|
|
|
|
uintptr_t hThread;
|
|
|
|
HACCEL hAccTable;
|
|
|
|
|
2018-09-02 21:13:34 +02:00
|
|
|
extern GameScript* g_Script;
|
2018-09-09 21:58:38 +02:00
|
|
|
|
2018-08-19 09:46:58 +02:00
|
|
|
__int32 __cdecl WinProcMsg()
|
|
|
|
{
|
|
|
|
int result;
|
|
|
|
struct tagMSG Msg;
|
|
|
|
|
|
|
|
DB_Log(2, "WinProcMsg");
|
|
|
|
do
|
|
|
|
{
|
|
|
|
GetMessageA(&Msg, 0, 0, 0);
|
|
|
|
if (!TranslateAcceleratorA(WindowsHandle, hAccTable, &Msg))
|
|
|
|
{
|
|
|
|
TranslateMessage(&Msg);
|
|
|
|
DispatchMessageA(&Msg);
|
|
|
|
}
|
|
|
|
result = Unk_876C48;
|
|
|
|
} while (!Unk_876C48 && Msg.message != WM_QUIT);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
__int32 __stdcall WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, __int32 nShowCmd)
|
|
|
|
{
|
|
|
|
int RetVal;
|
|
|
|
int n;
|
|
|
|
|
|
|
|
// Clear Application Structure
|
|
|
|
memset(&App, 0, sizeof(WINAPP));
|
|
|
|
|
|
|
|
_CrtSetReportMode(0, 2);
|
|
|
|
_CrtSetDbgFlag(-1);
|
2018-09-04 13:24:50 +02:00
|
|
|
|
|
|
|
// TODO: deprecated
|
2018-08-19 09:46:58 +02:00
|
|
|
LoadGameflow();
|
2018-08-30 10:32:32 +03:00
|
|
|
LoadSettings();
|
2018-08-19 09:46:58 +02:00
|
|
|
|
2018-09-02 09:29:36 +02:00
|
|
|
// Initialise the new scripting system
|
|
|
|
g_Script = new GameScript();
|
|
|
|
g_Script->ExecuteScript("Scripts\\English.lua");
|
|
|
|
g_Script->ExecuteScript("Scripts\\Settings.lua");
|
2018-09-02 21:13:34 +02:00
|
|
|
g_Script->ExecuteScript("Scripts\\Gameflow.lua");
|
2018-09-02 09:29:36 +02:00
|
|
|
|
2018-08-19 09:46:58 +02:00
|
|
|
App.hInstance = hInstance;
|
|
|
|
App.WindowClass.hIcon = NULL;
|
|
|
|
App.WindowClass.lpszMenuName = NULL;
|
|
|
|
App.WindowClass.lpszClassName = "TR5Main";
|
|
|
|
App.WindowClass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
|
|
|
|
App.WindowClass.hInstance = hInstance;
|
|
|
|
App.WindowClass.style = CS_VREDRAW | CS_HREDRAW;
|
|
|
|
App.WindowClass.lpfnWndProc = (WNDPROC)WinAppProc;
|
|
|
|
App.WindowClass.cbClsExtra = 0;
|
|
|
|
App.WindowClass.cbWndExtra = 0;
|
|
|
|
App.WindowClass.hCursor = LoadCursor(App.hInstance, IDC_ARROW);
|
|
|
|
|
|
|
|
if (!RegisterClass(&App.WindowClass))
|
|
|
|
{
|
|
|
|
printf("Unable To Register Window Class\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
tagRECT Rect;
|
|
|
|
|
|
|
|
Rect.left = 0;
|
|
|
|
Rect.top = 0;
|
2018-09-02 09:29:36 +02:00
|
|
|
Rect.right = g_Script->GetSettings()->ScreenWidth;
|
|
|
|
Rect.bottom = g_Script->GetSettings()->ScreenHeight;
|
2018-08-19 09:46:58 +02:00
|
|
|
|
|
|
|
AdjustWindowRect(&Rect, WS_CAPTION, false);
|
|
|
|
|
|
|
|
App.WindowHandle = CreateWindowEx(
|
|
|
|
WS_THICKFRAME,
|
|
|
|
"TR5Main",
|
2018-09-02 09:29:36 +02:00
|
|
|
g_Script->GetSettings()->WindowTitle.c_str(),
|
2018-08-19 09:46:58 +02:00
|
|
|
WS_BORDER,
|
|
|
|
CW_USEDEFAULT,
|
|
|
|
CW_USEDEFAULT,
|
|
|
|
Rect.right - Rect.left,
|
|
|
|
Rect.bottom - Rect.top,
|
|
|
|
nullptr,
|
|
|
|
nullptr,
|
|
|
|
App.hInstance,
|
|
|
|
nullptr
|
|
|
|
);
|
|
|
|
|
|
|
|
if (!App.WindowHandle)
|
|
|
|
{
|
|
|
|
printf("Unable To Create Window");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: load settings from Windows registry
|
|
|
|
OptionAutoTarget = 1;
|
|
|
|
|
|
|
|
//DXInitialise(App.WindowHandle);
|
|
|
|
g_Renderer = new Renderer();
|
2018-09-02 09:29:36 +02:00
|
|
|
g_Renderer->Initialise(g_Script->GetSettings()->ScreenWidth, g_Script->GetSettings()->ScreenHeight, true, App.WindowHandle);
|
2018-08-19 09:46:58 +02:00
|
|
|
|
|
|
|
// Initialize audio
|
|
|
|
Sound_Init();
|
|
|
|
|
|
|
|
// Initialise the new inventory
|
|
|
|
g_Inventory = new Inventory();
|
|
|
|
|
|
|
|
SetWindowPos(App.WindowHandle, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
|
|
|
|
|
2018-09-04 13:24:50 +02:00
|
|
|
WindowsHandle = App.WindowHandle;
|
2018-08-19 09:46:58 +02:00
|
|
|
|
|
|
|
App.bNoFocus = false;
|
|
|
|
App.isInScene = false;
|
|
|
|
|
|
|
|
UpdateWindow(WindowsHandle);
|
|
|
|
ShowWindow(WindowsHandle, nShowCmd);
|
|
|
|
|
|
|
|
SetCursor(0);
|
|
|
|
ShowCursor(0);
|
|
|
|
hAccTable = LoadAcceleratorsA(hInstance, (LPCSTR)0x65);
|
|
|
|
|
|
|
|
SoundActive = false;
|
|
|
|
DoTheGame = true;
|
|
|
|
|
|
|
|
Unk_876C48 = false;
|
|
|
|
hThread = _beginthreadex(0, 0, &GameMain, 0, 0, &threadId);
|
|
|
|
WinProcMsg();
|
|
|
|
Unk_876C48 = true;
|
|
|
|
|
|
|
|
while (DoTheGame);
|
|
|
|
|
|
|
|
WinClose();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
__int32 __cdecl WinClose()
|
|
|
|
{
|
|
|
|
DB_Log(2, "WinClose - DLL");
|
2018-09-04 13:24:50 +02:00
|
|
|
|
2018-08-19 09:46:58 +02:00
|
|
|
DestroyAcceleratorTable(hAccTable);
|
|
|
|
|
2018-09-04 13:24:50 +02:00
|
|
|
//Sound_DeInit();
|
2018-08-19 09:46:58 +02:00
|
|
|
|
|
|
|
delete g_Renderer;
|
|
|
|
delete g_Inventory;
|
2018-09-04 13:24:50 +02:00
|
|
|
delete g_Script;
|
2018-08-19 09:46:58 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Inject_WinMain()
|
|
|
|
{
|
|
|
|
INJECT(0x004D23E0, WinClose);
|
|
|
|
INJECT(0x004D24C0, WinProcMsg);
|
|
|
|
INJECT(0x004D1C00, WinMain);
|
|
|
|
}
|