generated from LiteLDev/levilamina-mod-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
46 changed files
with
6,209 additions
and
194 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
#include "cfsp/CFSP.h" | ||
#include "cfsp/base/Mod.h" | ||
#include "cfsp/commands/Command.h" | ||
#include "cfsp/simplayer/CFSP.h" | ||
#include "cfsp/simplayer/Hooks.h" | ||
#include "ll/api/Config.h" | ||
#include "ll/api/i18n/I18n.h" | ||
#include "ll/api/mod/RegisterHelper.h" | ||
#include <memory> | ||
|
||
namespace coral_fans::cfsp { | ||
|
||
static std::unique_ptr<CFSP> instance; | ||
|
||
CFSP& CFSP::getInstance() { return *instance; } | ||
|
||
bool CFSP::load() { | ||
const auto& logger = getSelf().getLogger(); | ||
auto& mod = coral_fans::cfsp::mod(); | ||
|
||
// load config | ||
try { | ||
const auto& configFilePath = getSelf().getConfigDir() / "config.json"; | ||
if (!ll::config::loadConfig(mod.getConfig(), configFilePath)) { | ||
logger.warn("Cannot load configurations from {}", configFilePath); | ||
logger.info("Saving default configurations"); | ||
if (!ll::config::saveConfig(mod.getConfig(), configFilePath)) { | ||
logger.error("Cannot save default configurations to {}", configFilePath); | ||
return false; | ||
} | ||
} | ||
} catch (...) { | ||
logger.error("Failed to load config.json. Please check the file!"); | ||
return false; | ||
} | ||
|
||
// load i18n | ||
logger.debug("Loading I18n"); | ||
ll::i18n::load(getSelf().getLangDir()); | ||
ll::i18n::getInstance()->mDefaultLocaleName = mod.getConfig().locateName; | ||
return true; | ||
} | ||
|
||
bool CFSP::enable() { | ||
auto& mod = coral_fans::cfsp::mod(); | ||
|
||
hookSimPlayer(true); | ||
|
||
// get DefaultDataLoadHelper | ||
mod.getDefaultDataLoadHelper() = | ||
static_cast<DefaultDataLoadHelper*>(ll::memory::resolveSymbol("??_7DefaultDataLoadHelper@@6B@")); | ||
if (!mod.getDefaultDataLoadHelper()) { | ||
getSelf().getLogger().error("Cannot get DefaultDataLoadHelper from symbol."); | ||
return false; | ||
} | ||
|
||
if (mod.getConfig().command.sp.enabled) commands::registerSpCommand(mod.getConfig().command.sp.permission); | ||
|
||
// load simplayer data | ||
SimPlayerManager::getInstance().load(); | ||
|
||
return true; | ||
} | ||
|
||
bool CFSP::disable() { | ||
hookSimPlayer(false); | ||
return true; | ||
} | ||
|
||
} // namespace coral_fans::cfsp | ||
|
||
LL_REGISTER_MOD(coral_fans::cfsp::CFSP, coral_fans::cfsp::instance); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#pragma once | ||
|
||
#include "mc/server/commands/CommandPermissionLevel.h" | ||
#include <string> | ||
#include <unordered_set> | ||
|
||
namespace coral_fans::cfsp::config { | ||
|
||
struct CommandConfigStruct { | ||
bool enabled; | ||
CommandPermissionLevel permission; | ||
}; | ||
|
||
struct CommandStruct { | ||
CommandConfigStruct sp = {true, CommandPermissionLevel::Any}; | ||
}; | ||
|
||
enum class ListType : int { disabled, blacklist, whitelist }; | ||
|
||
struct SimPlayerStruct { | ||
std::string namePrefix = "SIM-"; | ||
std::string namePostfix = ""; | ||
unsigned long long maxOnline = 16; | ||
unsigned long long maxOwn = 4; | ||
unsigned long long maxGroup = 8; | ||
unsigned long long maxSpawnCount = 128; | ||
CommandPermissionLevel adminPermission = CommandPermissionLevel::GameDirectors; | ||
ListType listType = ListType::disabled; | ||
std::unordered_set<std::string> list; | ||
std::string luaPreload = ""; | ||
}; | ||
|
||
struct Config { | ||
int version = 1; | ||
std::string locateName = "zh_CN"; | ||
|
||
SimPlayerStruct simPlayer; | ||
|
||
CommandStruct command; | ||
}; | ||
|
||
} // namespace coral_fans::cfsp::config |
File renamed without changes.
Oops, something went wrong.