2020-05-27 09:21:20 +02:00
|
|
|
#include "framework.h"
|
2018-08-19 09:46:58 +02:00
|
|
|
#include "winmain.h"
|
2020-05-30 15:55:23 +02:00
|
|
|
#include "init.h"
|
2020-05-27 09:21:20 +02:00
|
|
|
#include "resource.h"
|
|
|
|
#include "draw.h"
|
|
|
|
#include "sound.h"
|
|
|
|
#include "inventory.h"
|
|
|
|
#include "control.h"
|
|
|
|
#include "gameflow.h"
|
|
|
|
#include "savegame.h"
|
|
|
|
#include "level.h"
|
2019-05-08 21:11:18 +02:00
|
|
|
#include "configuration.h"
|
2020-05-30 15:55:23 +02:00
|
|
|
#include "Renderer11.h"
|
2020-09-29 21:40:02 +02:00
|
|
|
#include <CommCtrl.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <process.h>
|
|
|
|
#include <corecrt_io.h>
|
2020-06-21 14:27:12 +02:00
|
|
|
using namespace T5M::Renderer;
|
2020-06-20 23:39:08 +02:00
|
|
|
using std::exception;
|
|
|
|
using std::string;
|
|
|
|
using std::cout;
|
|
|
|
using std::endl;
|
2020-05-27 09:21:20 +02:00
|
|
|
WINAPP App;
|
|
|
|
unsigned int ThreadID;
|
|
|
|
uintptr_t ThreadHandle;
|
2018-08-19 09:46:58 +02:00
|
|
|
HACCEL hAccTable;
|
2018-12-28 12:12:58 +01:00
|
|
|
byte receivedWmClose = false;
|
2019-01-06 12:27:56 +01:00
|
|
|
bool Debug = false;
|
2020-04-23 19:22:01 +02:00
|
|
|
HWND WindowsHandle;
|
2020-04-24 19:15:05 +02:00
|
|
|
int App_Unk00D9ABFD;
|
2019-12-02 09:11:21 +01:00
|
|
|
extern int IsLevelLoading;
|
2018-09-22 23:54:36 +02:00
|
|
|
extern GameFlow* g_GameFlow;
|
|
|
|
extern GameScript* g_GameScript;
|
2018-12-29 11:44:44 +01:00
|
|
|
extern GameConfiguration g_Configuration;
|
2020-05-01 20:42:17 +02:00
|
|
|
DWORD DebugConsoleThreadID;
|
|
|
|
DWORD MainThreadID;
|
2020-06-09 04:16:51 -03:00
|
|
|
bool BlockAllInput = true;
|
2020-06-11 16:25:19 -03:00
|
|
|
int skipLoop = -1;
|
|
|
|
int skipFrames = 2;
|
2020-06-11 23:03:05 -03:00
|
|
|
int lockInput = 0;
|
|
|
|
int newSkipLoop = -1;
|
|
|
|
int newSkipFrames = 2;
|
|
|
|
int newLockInput = 0;
|
|
|
|
bool newSkipFramesValue = false;
|
|
|
|
bool newSkipLoopValue = false;
|
|
|
|
bool newLockInputValue = false;
|
|
|
|
|
2020-08-18 20:26:24 +02:00
|
|
|
#if _DEBUG
|
|
|
|
string commit;
|
|
|
|
#endif
|
2020-08-25 19:25:28 -03:00
|
|
|
|
2020-06-09 04:16:51 -03:00
|
|
|
int lua_exception_handler(lua_State* L, sol::optional<const exception&> maybe_exception, sol::string_view description)
|
2020-04-28 12:24:10 -03:00
|
|
|
{
|
|
|
|
return luaL_error(L, description.data());
|
|
|
|
}
|
|
|
|
|
2020-05-27 09:21:20 +02:00
|
|
|
void WinProcMsg()
|
2018-08-19 09:46:58 +02:00
|
|
|
{
|
2020-05-27 09:21:20 +02:00
|
|
|
MSG Msg;
|
2018-08-19 09:46:58 +02:00
|
|
|
|
|
|
|
do
|
|
|
|
{
|
2020-05-27 09:21:20 +02:00
|
|
|
GetMessage(&Msg, 0, 0, 0);
|
|
|
|
if (!TranslateAccelerator(WindowsHandle, hAccTable, &Msg))
|
2018-08-19 09:46:58 +02:00
|
|
|
{
|
|
|
|
TranslateMessage(&Msg);
|
2020-05-27 09:21:20 +02:00
|
|
|
DispatchMessage(&Msg);
|
2018-08-19 09:46:58 +02:00
|
|
|
}
|
2020-05-27 09:21:20 +02:00
|
|
|
}
|
|
|
|
while (!ThreadEnded && Msg.message != WM_QUIT);
|
2018-08-19 09:46:58 +02:00
|
|
|
}
|
|
|
|
|
2020-05-27 09:21:20 +02:00
|
|
|
void CALLBACK HandleWmCommand(unsigned short wParam)
|
2018-12-28 12:12:58 +01:00
|
|
|
{
|
|
|
|
if (wParam == 8)
|
|
|
|
{
|
|
|
|
if (!IsLevelLoading)
|
|
|
|
{
|
2020-05-27 09:21:20 +02:00
|
|
|
SuspendThread((HANDLE)ThreadHandle);
|
2020-08-09 15:25:56 +02:00
|
|
|
g_Renderer.toggleFullScreen();
|
2020-05-27 09:21:20 +02:00
|
|
|
ResumeThread((HANDLE)ThreadHandle);
|
2018-12-28 12:12:58 +01:00
|
|
|
|
2020-08-09 15:25:56 +02:00
|
|
|
if (g_Renderer.isFullsScreen())
|
2018-12-28 12:12:58 +01:00
|
|
|
{
|
|
|
|
SetCursor(0);
|
|
|
|
ShowCursor(false);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SetCursor(LoadCursorA(App.hInstance, (LPCSTR)0x68));
|
|
|
|
ShowCursor(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-18 20:26:24 +02:00
|
|
|
void getCurrentCommit() {
|
|
|
|
LPSTR cmdLine = {TEXT("git.exe log -1 --oneline")};
|
|
|
|
|
|
|
|
SECURITY_ATTRIBUTES sa = {0};
|
|
|
|
sa.nLength = sizeof(sa);
|
|
|
|
sa.lpSecurityDescriptor = NULL;
|
|
|
|
sa.bInheritHandle = TRUE;
|
|
|
|
|
|
|
|
HANDLE hStdOutRd, hStdOutWr;
|
|
|
|
HANDLE hStdErrRd, hStdErrWr;
|
|
|
|
|
|
|
|
if(!CreatePipe(&hStdOutRd, &hStdOutWr, &sa, 0)){
|
|
|
|
// error handling...
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!CreatePipe(&hStdErrRd, &hStdErrWr, &sa, 0)){
|
|
|
|
// error handling...
|
|
|
|
}
|
|
|
|
|
|
|
|
SetHandleInformation(hStdOutRd, HANDLE_FLAG_INHERIT, 0);
|
|
|
|
SetHandleInformation(hStdErrRd, HANDLE_FLAG_INHERIT, 0);
|
|
|
|
|
|
|
|
STARTUPINFO si = {};
|
|
|
|
si.cb = sizeof(si);
|
|
|
|
si.dwFlags = STARTF_USESTDHANDLES;
|
|
|
|
si.hStdInput = GetStdHandle(STD_INPUT_HANDLE);
|
|
|
|
si.hStdOutput = hStdOutWr;
|
|
|
|
si.hStdError = hStdErrWr;
|
|
|
|
|
|
|
|
PROCESS_INFORMATION pi = {};
|
|
|
|
|
|
|
|
if(!CreateProcess(NULL, cmdLine, NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi)){
|
|
|
|
// error handling...
|
|
|
|
} else{
|
|
|
|
CHAR buf[256];
|
|
|
|
DWORD n;
|
|
|
|
BOOL success = ReadFile(hStdOutRd, buf, 256, &n, NULL);
|
|
|
|
if(!success || n == 0){
|
|
|
|
std::cout << "Failed to call ReadFile" << std::endl;
|
|
|
|
}
|
|
|
|
commit = std::string(buf, buf + n);
|
|
|
|
// read from hStdOutRd and hStdErrRd as needed until the process is terminated...
|
|
|
|
|
|
|
|
CloseHandle(pi.hThread);
|
|
|
|
CloseHandle(pi.hProcess);
|
|
|
|
}
|
|
|
|
|
|
|
|
CloseHandle(hStdOutRd);
|
|
|
|
CloseHandle(hStdOutWr);
|
|
|
|
CloseHandle(hStdErrRd);
|
|
|
|
CloseHandle(hStdErrWr);
|
|
|
|
}
|
|
|
|
|
2020-05-01 20:42:17 +02:00
|
|
|
void HandleScriptMessage(WPARAM wParam)
|
|
|
|
{
|
2020-06-09 04:16:51 -03:00
|
|
|
string ErrorMessage;
|
2020-05-01 20:42:17 +02:00
|
|
|
string message = *(string*)(wParam);
|
2020-06-11 16:25:19 -03:00
|
|
|
bool status = false;
|
2020-06-09 04:16:51 -03:00
|
|
|
|
2020-05-01 20:42:17 +02:00
|
|
|
//check whether line starts with "lua "
|
2020-06-09 04:16:51 -03:00
|
|
|
if (message.find("lua ") == 0) {
|
2020-05-01 20:42:17 +02:00
|
|
|
string scriptSubstring = message.substr(4);
|
2020-06-09 04:16:51 -03:00
|
|
|
status = g_GameScript->ExecuteScript(scriptSubstring, ErrorMessage);
|
|
|
|
}
|
|
|
|
else {
|
2020-06-11 23:03:05 -03:00
|
|
|
if (message.find("SL=") == 0)
|
|
|
|
{
|
|
|
|
string scriptSubstring = message.substr(3);
|
|
|
|
newSkipLoop = stoi(scriptSubstring);
|
|
|
|
newSkipLoopValue = true;
|
|
|
|
}
|
|
|
|
else if (message.find("SF=") == 0)
|
2020-06-11 16:25:19 -03:00
|
|
|
{
|
2020-06-11 23:03:05 -03:00
|
|
|
string scriptSubstring = message.substr(3);
|
|
|
|
newSkipFrames = stoi(scriptSubstring);
|
|
|
|
newSkipFramesValue = true;
|
2020-06-11 16:25:19 -03:00
|
|
|
}
|
2020-06-11 23:03:05 -03:00
|
|
|
else if (message.find("LI=") == 0)
|
2020-06-11 16:25:19 -03:00
|
|
|
{
|
2020-06-11 23:03:05 -03:00
|
|
|
string scriptSubstring = message.substr(3);
|
|
|
|
newLockInput = stoi(scriptSubstring);
|
|
|
|
newLockInputValue = true;
|
2020-06-11 16:25:19 -03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
status = g_GameScript->ExecuteString(message, ErrorMessage);
|
|
|
|
}
|
2020-05-01 20:42:17 +02:00
|
|
|
}
|
2020-06-09 04:16:51 -03:00
|
|
|
if (!status)
|
|
|
|
cout << ErrorMessage << endl;
|
2020-05-01 20:42:17 +02:00
|
|
|
}
|
|
|
|
|
2018-12-28 12:12:58 +01:00
|
|
|
LRESULT CALLBACK WinAppProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
|
|
|
{
|
2020-05-27 09:21:20 +02:00
|
|
|
if (msg == WM_USER + 0)
|
|
|
|
{
|
2020-05-01 20:42:17 +02:00
|
|
|
HandleScriptMessage(wParam);
|
|
|
|
return 0;
|
|
|
|
}
|
2020-05-27 09:21:20 +02:00
|
|
|
|
2019-03-17 11:05:07 +01:00
|
|
|
// Disables ALT + SPACE
|
2020-05-27 09:21:20 +02:00
|
|
|
if (msg == WM_SYSCOMMAND && wParam == SC_KEYMENU)
|
2019-03-17 11:05:07 +01:00
|
|
|
return 0;
|
|
|
|
|
2018-12-28 12:12:58 +01:00
|
|
|
if (msg > 0x10)
|
|
|
|
{
|
|
|
|
if (msg == WM_COMMAND)
|
2019-12-02 09:11:21 +01:00
|
|
|
HandleWmCommand((unsigned short)wParam);
|
2018-12-28 12:12:58 +01:00
|
|
|
|
|
|
|
return DefWindowProcA(hWnd, msg, wParam, (LPARAM)lParam);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (msg == WM_CLOSE)
|
|
|
|
{
|
|
|
|
receivedWmClose = true;
|
|
|
|
PostQuitMessage(0);
|
2020-04-27 06:38:50 +02:00
|
|
|
DoTheGame = false;
|
2018-12-28 12:12:58 +01:00
|
|
|
|
2018-12-29 14:27:39 +01:00
|
|
|
return DefWindowProcA(hWnd, 0x10u, wParam, (LPARAM)lParam);
|
2018-12-28 12:12:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (msg != WM_ACTIVATE)
|
|
|
|
return DefWindowProcA(hWnd, msg, wParam, (LPARAM)lParam);
|
|
|
|
|
|
|
|
if (receivedWmClose)
|
|
|
|
{
|
|
|
|
return DefWindowProcA(hWnd, msg, wParam, (LPARAM)lParam);
|
|
|
|
}
|
|
|
|
|
2019-12-02 09:11:21 +01:00
|
|
|
if ((short)wParam)
|
2018-12-28 12:12:58 +01:00
|
|
|
{
|
2019-12-02 09:11:21 +01:00
|
|
|
if ((signed int)(unsigned short)wParam > 0 && (signed int)(unsigned short)wParam <= 2)
|
2018-12-28 12:12:58 +01:00
|
|
|
{
|
2020-06-09 04:16:51 -03:00
|
|
|
//DB_Log(6, "WM_ACTIVE");
|
|
|
|
BlockAllInput = false;
|
2019-01-06 12:27:56 +01:00
|
|
|
if (!Debug)
|
2020-05-27 09:21:20 +02:00
|
|
|
ResumeThread((HANDLE)ThreadHandle);
|
2019-01-06 12:27:56 +01:00
|
|
|
|
2018-12-31 17:13:20 +01:00
|
|
|
App_Unk00D9ABFD = 0;
|
|
|
|
return 0;
|
2018-12-28 12:12:58 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-06-09 04:16:51 -03:00
|
|
|
//DB_Log(6, "WM_INACTIVE");
|
|
|
|
//DB_Log(5, "HangGameThread");
|
|
|
|
BlockAllInput = true;
|
2018-12-31 17:13:20 +01:00
|
|
|
App_Unk00D9ABFD = 1;
|
2019-01-06 12:27:56 +01:00
|
|
|
|
|
|
|
if (!Debug)
|
2020-05-27 09:21:20 +02:00
|
|
|
SuspendThread((HANDLE)ThreadHandle);
|
2018-12-28 12:12:58 +01:00
|
|
|
}
|
2018-12-31 17:13:20 +01:00
|
|
|
|
2018-12-28 12:12:58 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-05-27 09:21:20 +02:00
|
|
|
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
|
2018-08-19 09:46:58 +02:00
|
|
|
{
|
2020-08-18 20:26:24 +02:00
|
|
|
if constexpr (DebugBuild)
|
|
|
|
getCurrentCommit();
|
2018-08-19 09:46:58 +02:00
|
|
|
int RetVal;
|
|
|
|
int n;
|
|
|
|
|
2018-12-29 13:19:18 +01:00
|
|
|
// Process the command line
|
|
|
|
bool setup = false;
|
2020-05-23 19:59:58 +02:00
|
|
|
|
2020-05-24 08:31:36 +02:00
|
|
|
//TrLevel* level = new TrLevel(string("Data\\andrea1.t5m"));
|
|
|
|
//level->Load();
|
2019-01-06 12:27:56 +01:00
|
|
|
|
2018-12-29 13:19:18 +01:00
|
|
|
LPWSTR* argv;
|
2019-12-02 09:11:21 +01:00
|
|
|
int argc;
|
2018-12-29 13:19:18 +01:00
|
|
|
argv = CommandLineToArgvW(GetCommandLineW(), &argc);
|
|
|
|
|
2019-12-02 09:11:21 +01:00
|
|
|
for (int i = 1; i < argc; i++)
|
2018-12-29 13:19:18 +01:00
|
|
|
{
|
|
|
|
if (wcscmp(argv[i], L"/setup") == 0)
|
|
|
|
setup = true;
|
|
|
|
if (wcscmp(argv[i], L"/debug") == 0)
|
2019-01-06 12:27:56 +01:00
|
|
|
Debug = true;
|
2018-12-29 13:19:18 +01:00
|
|
|
}
|
|
|
|
LocalFree(argv);
|
|
|
|
|
2018-08-19 09:46:58 +02:00
|
|
|
// Clear Application Structure
|
|
|
|
memset(&App, 0, sizeof(WINAPP));
|
2019-05-08 21:11:18 +02:00
|
|
|
|
2018-09-02 09:29:36 +02:00
|
|
|
// Initialise the new scripting system
|
2018-09-22 23:54:36 +02:00
|
|
|
sol::state luaState;
|
|
|
|
luaState.open_libraries(sol::lib::base);
|
2020-04-28 12:24:10 -03:00
|
|
|
luaState.set_exception_handler(lua_exception_handler);
|
2018-09-22 23:54:36 +02:00
|
|
|
|
|
|
|
g_GameFlow = new GameFlow(&luaState);
|
2019-03-15 23:03:54 +01:00
|
|
|
LoadScript();
|
|
|
|
|
2018-09-22 23:54:36 +02:00
|
|
|
g_GameScript = new GameScript(&luaState);
|
2018-09-02 09:29:36 +02:00
|
|
|
|
2020-09-28 10:02:24 -03:00
|
|
|
luaState.set_function("GetItemByID", &GameScript::GetItemById, g_GameScript);
|
|
|
|
luaState.set_function("GetItemByName", &GameScript::GetItemByName, g_GameScript);
|
|
|
|
luaState.set_function("CreatePosition", &GameScript::CreatePosition, g_GameScript);
|
|
|
|
luaState.set_function("CreateRotation", &GameScript::CreateRotation, g_GameScript);
|
|
|
|
luaState.set_function("CalculateDistance", &GameScript::CalculateDistance, g_GameScript);
|
|
|
|
luaState.set_function("CalculateHorizontalDistance", &GameScript::CalculateHorizontalDistance, g_GameScript);
|
|
|
|
|
2018-10-09 00:02:14 +02:00
|
|
|
// Initialise chunks for savegames
|
|
|
|
SaveGame::Start();
|
|
|
|
|
2019-05-09 13:50:55 +02:00
|
|
|
INITCOMMONCONTROLSEX commCtrlInit;
|
|
|
|
commCtrlInit.dwSize = sizeof(INITCOMMONCONTROLSEX);
|
|
|
|
commCtrlInit.dwICC = ICC_USEREX_CLASSES | ICC_STANDARD_CLASSES;
|
|
|
|
InitCommonControlsEx(&commCtrlInit);
|
|
|
|
|
2019-05-03 20:58:36 +02:00
|
|
|
// Initialise main window
|
2018-08-19 09:46:58 +02:00
|
|
|
App.hInstance = hInstance;
|
|
|
|
App.WindowClass.hIcon = NULL;
|
|
|
|
App.WindowClass.lpszMenuName = NULL;
|
|
|
|
App.WindowClass.lpszClassName = "TR5Main";
|
2020-05-30 15:55:23 +02:00
|
|
|
App.WindowClass.hbrBackground = reinterpret_cast<HBRUSH>(GetStockObject(BLACK_BRUSH));
|
2018-08-19 09:46:58 +02:00
|
|
|
App.WindowClass.hInstance = hInstance;
|
|
|
|
App.WindowClass.style = CS_VREDRAW | CS_HREDRAW;
|
2020-05-30 15:55:23 +02:00
|
|
|
App.WindowClass.lpfnWndProc = WinAppProc;
|
2018-08-19 09:46:58 +02:00
|
|
|
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");
|
2019-11-21 07:43:34 +01:00
|
|
|
return false;
|
2018-08-19 09:46:58 +02:00
|
|
|
}
|
|
|
|
|
2018-12-29 11:44:44 +01:00
|
|
|
// Create the renderer and enumerate adapters and video modes
|
2020-06-21 14:27:12 +02:00
|
|
|
g_Renderer.Create();
|
|
|
|
g_Renderer.EnumerateVideoModes();
|
2018-12-29 11:44:44 +01:00
|
|
|
|
|
|
|
// Load configuration and optionally show the setup dialog
|
2019-05-09 08:06:30 +02:00
|
|
|
InitDefaultConfiguration();
|
2018-12-29 13:19:18 +01:00
|
|
|
if (setup || !LoadConfiguration())
|
2018-12-29 11:44:44 +01:00
|
|
|
{
|
|
|
|
if (!SetupDialog())
|
|
|
|
{
|
|
|
|
WinClose();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
LoadConfiguration();
|
|
|
|
}
|
|
|
|
|
2020-05-27 09:21:20 +02:00
|
|
|
RECT Rect;
|
2018-08-19 09:46:58 +02:00
|
|
|
Rect.left = 0;
|
|
|
|
Rect.top = 0;
|
2018-12-29 11:44:44 +01:00
|
|
|
Rect.right = g_Configuration.Width;
|
|
|
|
Rect.bottom = g_Configuration.Height;
|
2018-08-19 09:46:58 +02:00
|
|
|
AdjustWindowRect(&Rect, WS_CAPTION, false);
|
|
|
|
|
|
|
|
App.WindowHandle = CreateWindowEx(
|
2019-03-17 11:05:07 +01:00
|
|
|
0,
|
2018-08-19 09:46:58 +02:00
|
|
|
"TR5Main",
|
2018-09-22 23:54:36 +02:00
|
|
|
g_GameFlow->GetSettings()->WindowTitle.c_str(),
|
2019-03-17 11:05:07 +01:00
|
|
|
WS_POPUP,
|
2020-05-27 19:07:34 +02:00
|
|
|
CW_USEDEFAULT, // TODO: change this to center of screen !!!
|
2020-05-27 09:21:20 +02:00
|
|
|
CW_USEDEFAULT,
|
2018-08-19 09:46:58 +02:00
|
|
|
Rect.right - Rect.left,
|
|
|
|
Rect.bottom - Rect.top,
|
2019-03-17 11:05:07 +01:00
|
|
|
NULL,
|
|
|
|
NULL,
|
2018-08-19 09:46:58 +02:00
|
|
|
App.hInstance,
|
2019-03-17 11:05:07 +01:00
|
|
|
NULL
|
2018-08-19 09:46:58 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
if (!App.WindowHandle)
|
|
|
|
{
|
2018-12-28 12:12:58 +01:00
|
|
|
printf("Unable To Create Window: %d\n", GetLastError());
|
2019-11-21 07:43:34 +01:00
|
|
|
return false;
|
2018-08-19 09:46:58 +02:00
|
|
|
}
|
|
|
|
|
2019-05-03 20:58:36 +02:00
|
|
|
WindowsHandle = App.WindowHandle;
|
2018-12-28 17:19:54 +01:00
|
|
|
// Initialise the renderer
|
2020-06-21 14:27:12 +02:00
|
|
|
g_Renderer.Initialise(g_Configuration.Width, g_Configuration.Height, g_Configuration.RefreshRate, g_Configuration.Windowed, App.WindowHandle);
|
2018-08-19 09:46:58 +02:00
|
|
|
|
|
|
|
// Initialize audio
|
2018-12-31 10:38:34 +01:00
|
|
|
if (g_Configuration.EnableSound)
|
2018-12-29 11:44:44 +01:00
|
|
|
Sound_Init();
|
2018-08-19 09:46:58 +02:00
|
|
|
|
|
|
|
// Initialise the new inventory
|
2020-06-16 19:45:06 +02:00
|
|
|
//g_Inventory = Inventory();
|
2019-05-03 20:58:36 +02:00
|
|
|
|
2018-08-19 09:46:58 +02:00
|
|
|
App.bNoFocus = false;
|
|
|
|
App.isInScene = false;
|
|
|
|
|
|
|
|
UpdateWindow(WindowsHandle);
|
|
|
|
ShowWindow(WindowsHandle, nShowCmd);
|
2020-05-27 09:21:20 +02:00
|
|
|
|
2020-05-01 20:42:17 +02:00
|
|
|
//Create debug script terminal
|
2020-05-27 09:21:20 +02:00
|
|
|
if (Debug)
|
|
|
|
{
|
2020-05-01 20:42:17 +02:00
|
|
|
MainThreadID = GetWindowThreadProcessId(WindowsHandle, NULL);
|
|
|
|
AllocConsole();
|
|
|
|
HANDLE handle_in = GetStdHandle(STD_INPUT_HANDLE);
|
|
|
|
DWORD consoleModeIn;
|
|
|
|
int hCrt = _open_osfhandle((long)handle_in, _O_BINARY);
|
|
|
|
FILE* hf_in = _fdopen(hCrt, "r");
|
|
|
|
setvbuf(hf_in, NULL, _IONBF, 512);
|
|
|
|
GetConsoleMode(handle_in, &consoleModeIn);
|
|
|
|
consoleModeIn = consoleModeIn | ENABLE_LINE_INPUT;
|
|
|
|
SetConsoleMode(handle_in, consoleModeIn);
|
2020-05-04 22:10:01 +02:00
|
|
|
freopen_s(&hf_in, "CONIN$", "r", stdin);
|
|
|
|
|
|
|
|
HANDLE ConsoleOutput = GetStdHandle(STD_OUTPUT_HANDLE);
|
|
|
|
int SystemOutput = _open_osfhandle(intptr_t(ConsoleOutput), _O_TEXT);
|
|
|
|
FILE* COutputHandle = _fdopen(SystemOutput, "w");
|
|
|
|
freopen_s(&COutputHandle, "CONOUT$", "w", stdout);
|
|
|
|
|
2020-05-01 20:42:17 +02:00
|
|
|
LPTHREAD_START_ROUTINE readConsoleLoop = [](LPVOID params) -> DWORD {
|
|
|
|
DWORD read;
|
|
|
|
CHAR buffer[4096];
|
2020-05-27 09:21:20 +02:00
|
|
|
while (true)
|
|
|
|
{
|
2020-05-01 20:42:17 +02:00
|
|
|
BOOL success = ReadFile(params, &buffer, 4096, &read, NULL);
|
2020-06-09 04:16:51 -03:00
|
|
|
if (success && read > 2)
|
2020-05-27 09:21:20 +02:00
|
|
|
{
|
2020-05-01 20:42:17 +02:00
|
|
|
//Only send the actual written message minus \r\n
|
|
|
|
string msg(buffer, read-2);
|
2020-05-27 19:07:34 +02:00
|
|
|
SendMessage(WindowsHandle, WM_USER, (WPARAM)&msg, NULL);
|
2020-05-01 20:42:17 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
return 0;
|
|
|
|
};
|
|
|
|
CreateThread(NULL, 0, readConsoleLoop, handle_in, 0, &DebugConsoleThreadID);
|
|
|
|
}
|
2020-05-27 09:21:20 +02:00
|
|
|
|
|
|
|
SetCursor(NULL);
|
|
|
|
ShowCursor(FALSE);
|
2020-05-27 19:07:34 +02:00
|
|
|
hAccTable = LoadAccelerators(hInstance, (LPCSTR)0x65);
|
2018-08-19 09:46:58 +02:00
|
|
|
|
2019-01-13 21:57:16 +01:00
|
|
|
//g_Renderer->Test();
|
|
|
|
|
2018-08-19 09:46:58 +02:00
|
|
|
SoundActive = false;
|
|
|
|
DoTheGame = true;
|
|
|
|
|
2020-05-27 09:21:20 +02:00
|
|
|
ThreadEnded = false;
|
2020-05-27 19:07:34 +02:00
|
|
|
ThreadHandle = BeginThread(GameMain, ThreadID);
|
2018-08-19 09:46:58 +02:00
|
|
|
WinProcMsg();
|
2020-05-27 09:21:20 +02:00
|
|
|
ThreadEnded = true;
|
2018-08-19 09:46:58 +02:00
|
|
|
|
|
|
|
while (DoTheGame);
|
|
|
|
|
|
|
|
WinClose();
|
2020-05-27 09:21:20 +02:00
|
|
|
exit(EXIT_SUCCESS);
|
2018-08-19 09:46:58 +02:00
|
|
|
}
|
|
|
|
|
2020-05-27 09:21:20 +02:00
|
|
|
void WinClose()
|
2018-08-19 09:46:58 +02:00
|
|
|
{
|
|
|
|
DestroyAcceleratorTable(hAccTable);
|
2018-12-29 11:44:44 +01:00
|
|
|
|
2018-12-31 10:38:34 +01:00
|
|
|
if (g_Configuration.EnableSound)
|
2018-12-29 11:44:44 +01:00
|
|
|
Sound_DeInit();
|
2018-08-19 09:46:58 +02:00
|
|
|
|
2020-04-28 12:24:10 -03:00
|
|
|
delete g_GameScript;
|
2018-09-22 23:54:36 +02:00
|
|
|
delete g_GameFlow;
|
2018-08-19 09:46:58 +02:00
|
|
|
|
2018-10-09 00:02:14 +02:00
|
|
|
SaveGame::End();
|
2020-05-01 20:42:17 +02:00
|
|
|
}
|