-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdllmain.cpp
109 lines (97 loc) · 2.26 KB
/
dllmain.cpp
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#ifdef _WIN32
#pragma comment( lib, "ws2_32" )
#include <WinSock2.h>
#endif
#include <fstream>
#include <queue>
#include <functional>
#include <random>
#include <iostream>
#include <cmath>
#include <windows.h>
#include "MinHook.h"
#include "json/json.hpp"
#include "loader.h"
#include "ghidra_export.h"
#include "util.h"
#include <thread>
#include "Base.h"
#include "Component.h"
#include "LuaData.h"
#include "ControlProgram.h"
#include "LuaScript.h"
using namespace loader;
void Lua_System()
{
while (true)
{
if (Base::ModConfig::GameDataInit) {
for (string file_name : Base::LuaHandle::LuaFiles) {
if (Base::LuaHandle::LuaCode[file_name].start) {
Lua_Main(file_name);
}
}
}
}
}
__declspec(dllexport) extern bool Load()
{
//游戏版本检查
if (std::string(GameVersion) != Base::ModConfig::Version) {
LOG(WARN) << Base::ModConfig::ModName << " : Wrong version";
return false;
}
Component::getFiles("nativePC\\LuaScript\\", Base::LuaHandle::LuaFiles);
LOG(INFO) << "Lua file load:";
for (string file_name : Base::LuaHandle::LuaFiles) {
LOG(INFO) << file_name;
}
//初始化WebSocket
#ifdef _WIN32
INT rc;
WSADATA wsaData;
rc = WSAStartup(MAKEWORD(2, 2), &wsaData);
if (rc) {
printf("WSAStartup Failed.\n");
return 1;
}
#endif
//初始化steamid
HMODULE module = ::GetModuleHandle("steam_api64.dll");
if (module != nullptr) {
MODULEINFO moduleInfo;
if (GetModuleInformation(GetCurrentProcess(), module, &moduleInfo, sizeof(moduleInfo))) {
void* startAddr = (void*)module;
Base::World::SteamId = *offsetPtr<int>(startAddr, 0x3A118);
}
}
//获取程序列表
Base::World::ProcessList = Component::GetProcessList();
//初始化钩子
MH_Initialize();
HookLambda(MH::World::MapClockLocal,
[](auto clock, auto clock2) {
auto ret = original(clock, clock2);
ControlProgram::InitConsole();
if (Base::Init()) {
Base::RealTimeUpdate();
}
return ret;
});
//应用钩子
MH_ApplyQueued();
return true;
}
BOOL APIENTRY DllMain(HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
if (ul_reason_for_call == DLL_PROCESS_ATTACH) {
DisableThreadLibraryCalls(hModule);
ControlProgram::hMod = hModule;
CreateThread(0, 0, (LPTHREAD_START_ROUTINE)Lua_System, 0, 0, 0);
return Load();
}
return TRUE;
}