This commit is contained in:
Asuro
2025-02-07 00:32:38 +01:00
parent 445844bb6d
commit 3be734ae2f
16 changed files with 193 additions and 32 deletions

View File

@@ -1,11 +1,115 @@
#include <bx/bx.h>
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>
#undef min
#undef max
#include <cstdio>
#include <libloaderapi.h>
#include <bx/string.h>
//#define VISUAL_STUDIO
typedef void (*Startup)(void*);
typedef void (*Update)();
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
{
LRESULT Res = 0;
switch (message)
{
default:
{
Res = DefWindowProcW(hwnd, message, wparam, lparam);
break;
}
}
return Res;
}
HWND InitWindow()
{
uint32_t startWidth = 1920;
uint32_t startHeight = 1080;
HINSTANCE instance = (HINSTANCE)GetModuleHandle(NULL);
WNDCLASSEXW wnd;
bx::memSet(&wnd, 0, sizeof(wnd));
wnd.cbSize = sizeof(wnd);
wnd.style = CS_HREDRAW | CS_VREDRAW;
wnd.lpfnWndProc = WndProc;
wnd.hInstance = instance;
wnd.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wnd.hCursor = LoadCursor(NULL, IDC_ARROW);
wnd.lpszClassName = L"EngineWin";
wnd.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
RegisterClassExW(&wnd);
HWND window = CreateWindowExW(0, L"EngineWin", L"PuzGame", WS_OVERLAPPEDWINDOW | WS_VISIBLE, 0, 0, startWidth, startHeight, NULL, NULL, instance, 0);
if (window == NULL)
{
DWORD err = GetLastError();
printf("Failed to create window: %#x!\n", err);
}
return window;
}
int main()
{
while (true)
HWND window = InitWindow();
if (window == NULL) return 1;
char Buf[512];
GetCurrentDirectoryA(sizeof(Buf), Buf);
#ifdef VISUAL_STUDIO
const char* dllPath = "Debug/PuzGame.dll";
#else
const char* dllPath = "libPuzGame.dll";
#endif
HMODULE gameLibModule = LoadLibraryEx(dllPath, NULL, 0);
if (gameLibModule == NULL)
{
printf("a\n");
printf("Failed to load game DLL from %s!", dllPath);
return 1;
}
return 1;
#ifdef VISUAL_STUDIO
Startup StartFunc = (Startup)GetProcAddress(gameLibModule, "?Setup@Game@@YAXPEAX@Z");
#else
Startup StartFunc = (Startup)GetProcAddress(gameLibModule, "_ZN4Game5SetupEPv");
#endif
if (StartFunc == NULL)
{
printf("Failed to load startup function from game DLL!\n");
return 1;
}
#ifdef VISUAL_STUDIO
Update UpdateFunc = (Update)GetProcAddress(gameLibModule, "?Update@Game@@YAXXZ");
#else
Update UpdateFunc = (Update)GetProcAddress(gameLibModule, "_ZN4Game6UpdateEv");
#endif
if (UpdateFunc == NULL)
{
printf("Failed to load update function from game DLL!\n");
return 1;
}
printf("Loaded Game DLL successfully!\n");
StartFunc(window);
bool isRunning = true;
while (isRunning)
{
MSG Message;
BOOL MessageResult = GetMessage(&Message, 0, 0, 0);
if (MessageResult > 0)
{
TranslateMessage(&Message);
DispatchMessageW(&Message);
}
// UpdateFunc();
// Sleep(1000.0);
}
return 0;
}