Skip to content

Commit da0a383

Browse files
committed
refactor: rename plugin to mod
1 parent 2a7e2be commit da0a383

File tree

7 files changed

+31
-28
lines changed

7 files changed

+31
-28
lines changed

CHANGELOG.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## [1.8.0] - 2024-06-28
11+
12+
### Changed
13+
14+
- Rename plugin to mod.
15+
1016
## [1.7.0] - 2024-06-28
1117

1218
### Changed
@@ -62,7 +68,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6268
- Preload native plugins
6369
- Clean up code
6470

65-
[Unreleased]: https://github.com/LiteLDev/LeviLamina/compare/v1.7.0...HEAD
71+
[Unreleased]: https://github.com/LiteLDev/LeviLamina/compare/v1.8.0...HEAD
72+
[1.8.0]: https://github.com/LiteLDev/LeviLamina/compare/v1.7.0...v1.8.0
6673
[1.7.0]: https://github.com/LiteLDev/LeviLamina/compare/v1.6.3...v1.7.0
6774
[1.6.3]: https://github.com/LiteLDev/LeviLamina/compare/v1.6.2...v1.6.3
6875
[1.6.2]: https://github.com/LiteLDev/LeviLamina/compare/v1.6.1...v1.6.2

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
A library preloader for loading LeviLamina
44

5-
This is the library preloader for [LeviLamina](https://github.com/LiteLDev/LeviLamina). It loads LeviLamina before BDS starts and provides MCAPIs required by LeviLamina and various plugins. We uses windows delay load to expose and remap original bds symbol to our own symbol, and then we will provide them to plugins.
5+
This is the library preloader for [LeviLamina](https://github.com/LiteLDev/LeviLamina). It loads LeviLamina before game starts and provides MCAPIs required by LeviLamina and various mods. We uses windows delay load to expose and remap original symbol to our own symbol, and then we will provide them to mods.
66

77
## Install
88

src/pl/PreLoader.cpp

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,12 @@
2626
#include <winnls.h>
2727
#include <winnt.h>
2828

29-
namespace fs = std::filesystem;
30-
31-
std::set<std::string> preloadList;
32-
3329
namespace pl {
34-
35-
constexpr std::string_view NativePluginManagerName = "preload-native";
30+
namespace fs = std::filesystem;
3631

3732
bool loadLibrary(std::string const& libName, bool showFailInfo = true) {
3833
if (LoadLibraryW(pl::utils::str2wstr(libName).c_str())) {
39-
Info("{} Loaded.", pl::utils::u8str2str(std::filesystem::path(libName).filename().u8string()));
34+
Info("{} Loaded.", pl::utils::u8str2str(std::filesystem::path(libName).stem().u8string()));
4035
return true;
4136
}
4237
if (showFailInfo) {
@@ -64,11 +59,11 @@ bool loadLibrary(std::string const& libName, bool showFailInfo = true) {
6459
}
6560
return false;
6661
}
67-
void loadPreloadNativePlugins() {
68-
namespace fs = std::filesystem;
69-
fs::path pluginsDir = ".\\plugins";
62+
void loadPreloadNativeMods() {
63+
namespace fs = std::filesystem;
64+
fs::path modsDir = ".\\mods";
7065
try {
71-
for (const auto& entry : fs::directory_iterator(pluginsDir)) {
66+
for (const auto& entry : fs::directory_iterator(modsDir)) {
7267
if (!entry.is_directory()) { continue; }
7368
fs::path manifestPath = entry.path() / "manifest.json";
7469
if (!fs::exists(manifestPath)) { continue; }
@@ -78,17 +73,16 @@ void loadPreloadNativePlugins() {
7873
nlohmann::json manifestJson;
7974
manifestFile >> manifestJson;
8075
std::string type = manifestJson["type"];
81-
if (type == NativePluginManagerName) {
82-
std::string pluginName = manifestJson["name"];
83-
std::string pluginEntry = manifestJson["entry"];
84-
Info("Preloading: {} <{}>", pluginName, pluginEntry);
85-
pluginEntry = (entry.path() / pluginEntry).string();
86-
if (!fs::exists(pluginEntry)) {
87-
Error("Entry not exists: {}", pluginEntry);
76+
if (type == preloadModManagerName) {
77+
std::string modName = manifestJson["name"];
78+
std::string modEntry = manifestJson["entry"];
79+
Info("Preloading: {} <{}>", modName, modEntry);
80+
modEntry = (entry.path() / modEntry).string();
81+
if (!fs::exists(modEntry)) {
82+
Error("Entry not exists: {}", modEntry);
8883
continue;
8984
}
90-
loadLibrary(pluginEntry);
91-
preloadList.insert(pluginEntry);
85+
loadLibrary(modEntry);
9286
}
9387
} catch (const nlohmann::json::parse_error& e) { Error("Error parsing manifest file: {}", e.what()); }
9488
}
@@ -98,7 +92,7 @@ void loadPreloadNativePlugins() {
9892
void init() {
9993
loadLoggerConfig();
10094
pl::symbol_provider::init();
101-
loadPreloadNativePlugins();
95+
loadPreloadNativeMods();
10296
}
10397
} // namespace pl
10498

@@ -126,7 +120,7 @@ void openConsole() {
126120
GetConsoleMode(GetStdHandle(STD_OUTPUT_HANDLE), &mode);
127121
SetConsoleMode(GetStdHandle(STD_OUTPUT_HANDLE), mode | ENABLE_VIRTUAL_TERMINAL_PROCESSING);
128122

129-
// Change current working dir to current module path to make sure we can load plugins correctly
123+
// Change current working dir to current module path to make sure we can load mods correctly
130124
SetCurrentDirectoryW(mainExe.parent_path().c_str());
131125

132126
SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX | SEM_NOOPENFILEERRORBOX | SEM_NOALIGNMENTFAULTEXCEPT);

src/pl/PreLoader.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@
33
#include "pl/Hook.h" // IWYU pragma: export
44
#include "pl/SymbolProvider.h" // IWYU pragma: export
55
#include "pl/internal/Macro.h" // IWYU pragma: export
6+
7+
[[maybe_unused]] constexpr char const* preloadModManagerName = "preload-native";

src/pl/SymbolProvider.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ void* pl_resolve_symbol(const char* symbolName) {
204204
auto iter = funcMap->find(std::string_view(symbolName));
205205
if (iter == funcMap->end()) {
206206
Error("Could not find function in memory: {}", symbolName);
207-
Error("Plugin: {}", pl::utils::getCallerModuleFileName());
207+
Error("Module: {}", pl::utils::getCallerModuleFileName());
208208
return nullptr;
209209
}
210210
return (void*)(imageBaseAddr + iter->second);

src/pl/internal/Logger.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ inline bool shouldLogColor = true;
2323

2424
inline void loadLoggerConfig() {
2525
try {
26-
std::ifstream file(fs::path{u8"plugins/LeviLamina/config/config.json"});
26+
std::ifstream file(fs::path{u8"mods/LeviLamina/config/config.json"});
2727
nlohmann::json json;
2828
file >> json;
2929
file.close();

tooth.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
{
22
"format_version": 2,
33
"tooth": "github.com/LiteLDev/PreLoader",
4-
"version": "1.7.0",
4+
"version": "1.8.0",
55
"info": {
66
"name": "PreLoader",
77
"description": "A library preloader for loading LeviLamina",
88
"author": "LiteLDev",
99
"tags": []
1010
},
11-
"asset_url": "https://github.com/LiteLDev/PreLoader/releases/download/v1.7.0/preloader-windows-x64.zip",
11+
"asset_url": "https://github.com/LiteLDev/PreLoader/releases/download/v1.8.0/preloader-windows-x64.zip",
1212
"files": {
1313
"place": [
1414
{

0 commit comments

Comments
 (0)