Upgrade folder structure

This commit is contained in:
2024-09-24 19:45:20 +08:00
parent cdd0edd312
commit ee08c57515
64 changed files with 459 additions and 529 deletions

4
game_re/r3/README.md Normal file
View File

@@ -0,0 +1,4 @@
# r3 folder
Custom sources for the game

101
game_re/r3/binders/auto.h Normal file
View File

@@ -0,0 +1,101 @@
// This is included by any decompiled source file
#ifndef B8D59B54_1674_4C0F_AA2C_611385FF5D03
#define B8D59B54_1674_4C0F_AA2C_611385FF5D03
#include "static_mem.h"
#include "base.h"
#include <gh_types.h>
#include <gh_global.h>
#ifdef _WIN32
#include <direct.h>
#include <process.h>
#else
#include <unistd.h>
#endif
template <size_t Offset, size_t Size> struct Field {};
template <size_t Size> struct _FieldBinderSizeTraits {
using type = undefined;
};
template <> struct _FieldBinderSizeTraits<4> {
using type = undefined4;
};
template <> struct _FieldBinderSizeTraits<2> {
using type = undefined2;
};
template <> struct _FieldBinderSizeTraits<3> {
using type = undefined3;
};
template <size_t Size> struct FieldBinder {
void *dst;
using ExpectedType = typename _FieldBinderSizeTraits<Size>::type;
operator ExpectedType &() const {
return *reinterpret_cast<ExpectedType *>(dst);
}
template <typename T> T *operator=(T *src) {
union V {
T *a;
void* b;
};
V* trick = reinterpret_cast<V*>(this);
return trick->a = src;
}
ExpectedType& operator=(ExpectedType src) {
return *reinterpret_cast<ExpectedType *>(dst) = src;
}
};
template <size_t Offset, size_t Size>
inline FieldBinder<Size> operator+(const void *str,
Field<Offset, Size> offset) {
return FieldBinder<Size>{.dst = (uint8_t *)str + Offset};
}
typedef uint32_t cc_type_t;
template <typename T0, typename T1>
inline constexpr undefined3 CONCAT12(T0 a, T1 b) {
return undefined3(cc_type_t(a) << 16 | cc_type_t(b));
}
template <typename T0, typename T1>
inline constexpr cc_type_t CONCAT11(T0 a, T1 b) {
return cc_type_t(a) << 8 | cc_type_t(b);
}
template <typename T0, typename T1>
inline constexpr cc_type_t CONCAT21(T0 a, T1 b) {
return cc_type_t(a) << 8 | cc_type_t(b);
}
template <typename T0, typename T1>
inline constexpr cc_type_t CONCAT22(T0 a, T1 b) {
return cc_type_t(a) << 16 | cc_type_t(b);
}
template <typename T0, typename T1>
inline constexpr cc_type_t CONCAT23(T0 a, T1 b) {
return cc_type_t(a) << 24 | cc_type_t(b);
}
template <typename T0>
inline constexpr char SUB21(T0 a, size_t b) {
return cc_type_t(a) >> (b * 8);
}
template <typename T0>
inline constexpr char SUB41(T0 a, size_t b) {
return cc_type_t(a) >> (b * 8);
}
template <typename T0>
inline constexpr uint16_t SUB42(T0 a, size_t b) {
return cc_type_t(a) >> (b * 8);
}
#endif /* B8D59B54_1674_4C0F_AA2C_611385FF5D03 */

47
game_re/r3/binders/base.h Normal file
View File

@@ -0,0 +1,47 @@
// Common definition required for all generated files
#ifndef A523F6DB_0645_4DEB_8AEB_3792CB732B49
#define A523F6DB_0645_4DEB_8AEB_3792CB732B49
#if _WIN32
#include <Windows.h>
#else
#include "win32_shim.h"
#endif
#include <stdint.h>
#include <stdio.h>
#include <string.h>
typedef uint8_t undefined;
typedef uint32_t undefined4;
typedef uint16_t undefined2;
typedef uint16_t word;
typedef uint32_t dword;
struct undefined3 {
uint8_t _0;
uint8_t _1;
uint8_t _2;
undefined3& operator=(const uint32_t& other) {
_0 = other & 0xff;
_1 = (other >> 8) & 0xff;
_2 = (other >> 16) & 0xff;
return *this;
}
};
typedef unsigned char byte;
typedef byte undefined1;
// typedef uint64_t uint;
typedef void *pointer;
typedef char *TerminatedCString;
typedef char *string;
// Can not export enums for some reason
enum R3ModuleId : uint8_t {
R3ModId_unk = 0x00,
R3ModId_not_initialized = 0xff,
};
#endif /* A523F6DB_0645_4DEB_8AEB_3792CB732B49 */

View File

@@ -0,0 +1,10 @@
// This is included by gh_global.h
#ifndef EDBE48FC_B879_4985_9274_B7ACF24AD024
#define EDBE48FC_B879_4985_9274_B7ACF24AD024
#include "base.h"
#include "static_mem.h"
#include <gh_types.h>
#endif /* EDBE48FC_B879_4985_9274_B7ACF24AD024 */

View File

@@ -0,0 +1,11 @@
#ifndef DF40ED2B_5659_43AA_8A22_499A89C4BD62
#define DF40ED2B_5659_43AA_8A22_499A89C4BD62
// Header file that is automatically included in all generated code
#include "static_mem.h"
#include <gh_types.h>
#include <gh_global.h>
#endif /* DF40ED2B_5659_43AA_8A22_499A89C4BD62 */

View File

@@ -0,0 +1,16 @@
#include "static_mem.h"
#include <spdlog/spdlog.h>
unsigned char gh_static_mem[GH_DATA_SIZE];
void gh_init_data_segment() {
SPDLOG_INFO("Initializing data segment");
FILE *f = fopen(R3_DATA_SEGMENT_FILE, "rb");
if (!f) {
throw std::runtime_error("Failed to open gh_datasegment.bin");
}
size_t actual = fread(gh_static_mem, 1, gh_data_size, f);
if (actual != gh_data_size) {
throw std::runtime_error("Failed to read gh_datasegment.bin");
}
fclose(f);
}

View File

@@ -0,0 +1,22 @@
#ifndef A18E3E17_2A80_4DBD_96CD_1CE0120A164E
#define A18E3E17_2A80_4DBD_96CD_1CE0120A164E
#include <gh_datasegment.h>
#include <stdexcept>
extern unsigned char gh_static_mem[GH_DATA_SIZE];
template <size_t addr> inline constexpr void checkMappedMemory() {
static_assert(addr >= GH_DATA_START, "Address outside lower bound");
static_assert(addr < GH_DATA_END, "Address outside upper bound");
}
inline uint8_t *memoryMapSafe(size_t addr) {
if (addr < GH_DATA_START || addr > GH_DATA_END) {
throw std::runtime_error("Address out of bounds");
}
return (uint8_t *)(gh_static_mem + (addr - GH_DATA_START));
}
#define GH_MEM(addr) (checkMappedMemory<addr>(), *memoryMapSafe(addr))
#endif /* A18E3E17_2A80_4DBD_96CD_1CE0120A164E */

View File

@@ -0,0 +1,8 @@
// This is included by gh_types.h
#ifndef F3E71404_380C_4417_8642_0AA89E12BE28
#define F3E71404_380C_4417_8642_0AA89E12BE28
#include "base.h"
#endif /* F3E71404_380C_4417_8642_0AA89E12BE28 */

View File

@@ -0,0 +1,89 @@
#ifndef F69A0336_B517_4804_B49B_F4FBE6691DDB
#define F69A0336_B517_4804_B49B_F4FBE6691DDB
#include <stdint.h>
typedef const char* LPCSTR;
typedef const wchar_t* LPCWSTR;
typedef char* LPSTR;
typedef wchar_t* LPWSTR;
typedef void* LPVOID;
typedef const void* LPCVOID;
typedef unsigned long DWORD;
typedef unsigned short WORD;
typedef unsigned char BYTE;
typedef int32_t LONG;
typedef uint32_t ULONG;
typedef int32_t BOOL;
typedef uint32_t UINT;
typedef char CHAR;
typedef void* HANDLE;
typedef void* HMODULE;
typedef void* HINSTANCE;
typedef void* HWND;
typedef void* HDC;
typedef void* HGLRC;
typedef void* HMENU;
typedef void* HBITMAP;
typedef void* HBRUSH;
typedef void* HFONT;
typedef void* HPEN;
typedef void* HRGN;
typedef void* HICON;
typedef void* HCURSOR;
typedef void* HACCEL;
typedef void* HRSRC;
typedef void* HGLOBAL;
typedef void* HLOCAL;
typedef void* HKEY;
typedef void* PHKEY;
typedef DWORD* LPDWORD;
typedef BYTE* LPBYTE;
typedef int32_t LSTATUS;
typedef struct tagRECT {
LONG left;
LONG top;
LONG right;
LONG bottom;
} RECT;
inline void GetWindowsDirectoryA(char* lpBuffer, DWORD nSize) {
// TODO
}
inline LPSTR GetCommandLineA() {
// TODO
return const_cast<char*>("");
}
inline void GetPrivateProfileStringA(LPCSTR lpAppName, LPCSTR lpKeyName, LPCSTR lpDefault, LPSTR lpBuffer, DWORD nSize, LPCSTR lpFileName) {
// TODO
}
inline void MessageBoxA(HWND hWnd, LPCSTR lpText, LPCSTR lpCaption, UINT uType) {
// TODO
}
inline LSTATUS RegOpenKeyExA(HKEY hKey, LPCSTR lpSubKey, DWORD ulOptions, DWORD samDesired, PHKEY phkResult) {
// TODO
return -1;
}
inline LSTATUS RegQueryValueExA(HKEY hKey, LPCSTR lpValueName, LPDWORD lpReserved, LPDWORD lpType, LPBYTE lpData, LPDWORD lpcbData) {
// TODO
return -1;
}
inline LSTATUS RegCloseKey(HKEY hKey) {
// TODO
return -1;
}
inline DWORD GetCurrentThreadId() {
// TODO
return 0;
}
#endif /* F69A0336_B517_4804_B49B_F4FBE6691DDB */

View File

@@ -0,0 +1,34 @@
#ifndef D9171C14_8ED0_407B_A289_4C75D30D9DCC
#define D9171C14_8ED0_407B_A289_4C75D30D9DCC
#include <string>
#include <gh_global.h>
struct R3Config {
std::string gameDataDir;
std::string gfxAdapter;
std::string gfxIdentifier;
std::string gfxGliMode;
std::string language;
};
inline R3Config createDefaultConfig() {
R3Config config{};
#ifdef R3_GAME_DATA_DIR
config.gameDataDir = R3_GAME_DATA_DIR;
#endif
// Windowed 720p
config.gfxGliMode = "0 - 1200 x 720 - 16";
config.gfxAdapter = "D3D";
config.gfxIdentifier = "00000000-0000-0000-0000-000000000000";
config.language = s_English_005b684c;
return config;
}
inline R3Config &getDefaultConfig() {
static R3Config config = createDefaultConfig();
return config;
}
#endif /* D9171C14_8ED0_407B_A289_4C75D30D9DCC */

18
game_re/r3/main.cpp Normal file
View File

@@ -0,0 +1,18 @@
#include <windows.h>
#include <spdlog/spdlog.h>
#include <stdexcept>
#include <stdio.h>
extern "C" int r3_main(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR *cmdline, int showCmd);
extern void gh_init_data_segment();
int main() {
try {
gh_init_data_segment();
r3_main(GetModuleHandle(NULL), NULL, NULL, SW_SHOW);
} catch (const std::exception &e) {
SPDLOG_ERROR("Unhandled exception: {}", e.what());
}
return 0;
}