forked from Extollite/BedrockX
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LightBase.cpp
84 lines (82 loc) · 2.2 KB
/
LightBase.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
// LightBase.cpp : 定义 DLL 的导出函数。
//
#include<lbpch.h>
#include<iostream>
#include <filesystem>
#include "framework.h"
#include<api/xuidreg/xuidreg.h>
#include<api/event/genericEvent.h>
#include<I18N.h>
Logger<stdio_commit> LOG(stdio_commit{ "[BDX] " });
static void PrintErrorMessage() {
DWORD errorMessageID = ::GetLastError();
if (errorMessageID == 0) {
std::wcerr << "wtf\n";
return;
}
std::cerr << errorMessageID << std::endl;
LPWSTR messageBuffer = nullptr;
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM , NULL, errorMessageID,
MAKELANGID(0x09, SUBLANG_DEFAULT), (LPWSTR)&messageBuffer, 0, NULL);
std::wcerr << messageBuffer << std::endl;
LocalFree(messageBuffer);
}
static void fixupLIBDIR() {
WCHAR* buffer=new WCHAR[8192];
auto sz = GetEnvironmentVariableW(TEXT("PATH"), buffer, 8192);
std::wstring PATH{ buffer, sz };
sz = GetCurrentDirectoryW(8192, buffer);
std::wstring CWD{ buffer, sz };
SetEnvironmentVariableW(TEXT("PATH"), (CWD + L"\\bdxmod;" + PATH).c_str());
delete[] buffer;
}
static void loadall() {
static std::vector<std::pair<std::wstring, HMODULE>> libs;
using namespace std::filesystem;
create_directory("bdxmod");
LOG("BedrockX Loaded! version 20200331_2");
fixupLIBDIR();
directory_iterator ent("bdxmod");
for (auto& i : ent) {
if (i.is_regular_file() && i.path().extension() == ".dll") {
auto lib = LoadLibrary(i.path().c_str());
if (lib) {
LOG("loaded", canonical(i.path()));
libs.push_back({ std::wstring{ i.path().c_str() }, lib });
}
else {
LOG.p<LOGLVL::Error>("Error when loading", i.path());
PrintErrorMessage();
}
}
}
for (auto& [name, h] : libs) {
auto FN = GetProcAddress(h, "onPostInit");
if (!FN) {
//std::wcerr << "Warning!!! mod" << name << " doesnt have a onPostInit\n";
}
else {
((void (*)()) FN)();
}
}
libs.clear();
}
namespace GUI {
void INIT();
};
void entry() {
XIDREG::initAll();
GUI::INIT();
WItem::determine_off();
I18N::InitAll();
loadall();
PostInitEvent::_call();
PostInitEvent::_removeall();
}
THook(int, "main", void* a, void* b) {
std::ios::sync_with_stdio(false);
system("chcp 65001");
entry();
return original(a, b);
}