Skip to content

Commit

Permalink
refactor: rename plugin to mod
Browse files Browse the repository at this point in the history
  • Loading branch information
OEOTYAN committed Jun 28, 2024
1 parent 2a7e2be commit da0a383
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 28 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [1.8.0] - 2024-06-28

### Changed

- Rename plugin to mod.

## [1.7.0] - 2024-06-28

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

[Unreleased]: https://github.com/LiteLDev/LeviLamina/compare/v1.7.0...HEAD
[Unreleased]: https://github.com/LiteLDev/LeviLamina/compare/v1.8.0...HEAD
[1.8.0]: https://github.com/LiteLDev/LeviLamina/compare/v1.7.0...v1.8.0
[1.7.0]: https://github.com/LiteLDev/LeviLamina/compare/v1.6.3...v1.7.0
[1.6.3]: https://github.com/LiteLDev/LeviLamina/compare/v1.6.2...v1.6.3
[1.6.2]: https://github.com/LiteLDev/LeviLamina/compare/v1.6.1...v1.6.2
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

A library preloader for loading LeviLamina

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.
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.

## Install

Expand Down
38 changes: 16 additions & 22 deletions src/pl/PreLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,12 @@
#include <winnls.h>
#include <winnt.h>

namespace fs = std::filesystem;

std::set<std::string> preloadList;

namespace pl {

constexpr std::string_view NativePluginManagerName = "preload-native";
namespace fs = std::filesystem;

bool loadLibrary(std::string const& libName, bool showFailInfo = true) {
if (LoadLibraryW(pl::utils::str2wstr(libName).c_str())) {
Info("{} Loaded.", pl::utils::u8str2str(std::filesystem::path(libName).filename().u8string()));
Info("{} Loaded.", pl::utils::u8str2str(std::filesystem::path(libName).stem().u8string()));
return true;
}
if (showFailInfo) {
Expand Down Expand Up @@ -64,11 +59,11 @@ bool loadLibrary(std::string const& libName, bool showFailInfo = true) {
}
return false;
}
void loadPreloadNativePlugins() {
namespace fs = std::filesystem;
fs::path pluginsDir = ".\\plugins";
void loadPreloadNativeMods() {
namespace fs = std::filesystem;
fs::path modsDir = ".\\mods";
try {
for (const auto& entry : fs::directory_iterator(pluginsDir)) {
for (const auto& entry : fs::directory_iterator(modsDir)) {
if (!entry.is_directory()) { continue; }
fs::path manifestPath = entry.path() / "manifest.json";
if (!fs::exists(manifestPath)) { continue; }
Expand All @@ -78,17 +73,16 @@ void loadPreloadNativePlugins() {
nlohmann::json manifestJson;
manifestFile >> manifestJson;
std::string type = manifestJson["type"];
if (type == NativePluginManagerName) {
std::string pluginName = manifestJson["name"];
std::string pluginEntry = manifestJson["entry"];
Info("Preloading: {} <{}>", pluginName, pluginEntry);
pluginEntry = (entry.path() / pluginEntry).string();
if (!fs::exists(pluginEntry)) {
Error("Entry not exists: {}", pluginEntry);
if (type == preloadModManagerName) {
std::string modName = manifestJson["name"];
std::string modEntry = manifestJson["entry"];
Info("Preloading: {} <{}>", modName, modEntry);
modEntry = (entry.path() / modEntry).string();
if (!fs::exists(modEntry)) {
Error("Entry not exists: {}", modEntry);
continue;
}
loadLibrary(pluginEntry);
preloadList.insert(pluginEntry);
loadLibrary(modEntry);
}
} catch (const nlohmann::json::parse_error& e) { Error("Error parsing manifest file: {}", e.what()); }
}
Expand All @@ -98,7 +92,7 @@ void loadPreloadNativePlugins() {
void init() {
loadLoggerConfig();
pl::symbol_provider::init();
loadPreloadNativePlugins();
loadPreloadNativeMods();
}
} // namespace pl

Expand Down Expand Up @@ -126,7 +120,7 @@ void openConsole() {
GetConsoleMode(GetStdHandle(STD_OUTPUT_HANDLE), &mode);
SetConsoleMode(GetStdHandle(STD_OUTPUT_HANDLE), mode | ENABLE_VIRTUAL_TERMINAL_PROCESSING);

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

SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX | SEM_NOOPENFILEERRORBOX | SEM_NOALIGNMENTFAULTEXCEPT);
Expand Down
2 changes: 2 additions & 0 deletions src/pl/PreLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
#include "pl/Hook.h" // IWYU pragma: export
#include "pl/SymbolProvider.h" // IWYU pragma: export
#include "pl/internal/Macro.h" // IWYU pragma: export

[[maybe_unused]] constexpr char const* preloadModManagerName = "preload-native";
2 changes: 1 addition & 1 deletion src/pl/SymbolProvider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ void* pl_resolve_symbol(const char* symbolName) {
auto iter = funcMap->find(std::string_view(symbolName));
if (iter == funcMap->end()) {
Error("Could not find function in memory: {}", symbolName);
Error("Plugin: {}", pl::utils::getCallerModuleFileName());
Error("Module: {}", pl::utils::getCallerModuleFileName());
return nullptr;
}
return (void*)(imageBaseAddr + iter->second);
Expand Down
2 changes: 1 addition & 1 deletion src/pl/internal/Logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ inline bool shouldLogColor = true;

inline void loadLoggerConfig() {
try {
std::ifstream file(fs::path{u8"plugins/LeviLamina/config/config.json"});
std::ifstream file(fs::path{u8"mods/LeviLamina/config/config.json"});
nlohmann::json json;
file >> json;
file.close();
Expand Down
4 changes: 2 additions & 2 deletions tooth.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"format_version": 2,
"tooth": "github.com/LiteLDev/PreLoader",
"version": "1.7.0",
"version": "1.8.0",
"info": {
"name": "PreLoader",
"description": "A library preloader for loading LeviLamina",
"author": "LiteLDev",
"tags": []
},
"asset_url": "https://github.com/LiteLDev/PreLoader/releases/download/v1.7.0/preloader-windows-x64.zip",
"asset_url": "https://github.com/LiteLDev/PreLoader/releases/download/v1.8.0/preloader-windows-x64.zip",
"files": {
"place": [
{
Expand Down

0 comments on commit da0a383

Please sign in to comment.