-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTestSystem.c
71 lines (54 loc) · 1.51 KB
/
TestSystem.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <stdbool.h>
#include <stdint.h>
#include <windows.h>
typedef struct ISystem ISystem;
typedef struct ISystem_VTable
{
void (*dtor)(ISystem* this);
bool (*Initialize)(ISystem* this);
void (*Shutdown)(ISystem* this);
const char* (*GetName)(ISystem* this);
uint32_t (*GetVersion)(ISystem* this);
} ISystem_VTable;
struct ISystem
{
ISystem_VTable* vfptr;
ISystem_VTable vtable;
};
void ISystem_dtor(struct ISystem* this)
{
}
bool ISystem_Initialize(struct ISystem* this)
{
return true;
}
void ISystem_Shutdown(struct ISystem* this)
{
}
const char* ISystem_GetName(struct ISystem* this)
{
return "Test";
}
uint32_t ISystem_GetVersion(struct ISystem* this)
{
return 69;
}
__declspec(dllexport) ISystem* CreateInterface(void)
{
HANDLE base = GetModuleHandle("Base.dll");
void* (*Base_Alloc)(intptr_t, intptr_t);
Base_Alloc = (void*(*)(intptr_t, intptr_t))GetProcAddress(base, "?Base_Alloc@@YAPEAX_J0@Z");
// must be allocated by Base_Alloc, or it'll crash the launcher after the app runs (which would probably be fine)
ISystem* system = Base_Alloc(sizeof(ISystem), 8);
system->vfptr = &system->vtable;
system->vfptr->dtor = ISystem_dtor;
system->vfptr->Initialize = ISystem_Initialize;
system->vfptr->Shutdown = ISystem_Shutdown;
system->vfptr->GetName = ISystem_GetName;
system->vfptr->GetVersion = ISystem_GetVersion;
return system;
}
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
return true;
}