Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
odorajbotoj committed Oct 12, 2024
2 parents 5b3d073 + c1d9367 commit 4b421b8
Show file tree
Hide file tree
Showing 46 changed files with 6,209 additions and 194 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,12 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.0.0] - 2024-10-11

### Added

+ Move CoralFans SimulatedPlayer System from [CoralFans](https://github.com/CoralFans-Dev/CoralFans) to here
+ Added Script Arg

[1.0.0]: https://github.com/CoralFans-Dev/CFSP/releases/tag/v1.0.0
782 changes: 661 additions & 121 deletions LICENSE

Large diffs are not rendered by default.

28 changes: 9 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,18 @@
# LeviLamina Mod Template
# CFSP

A LeviLamina mod template

This mod is a template for developing LeviLamina mods.
CoralFans SimulatedPlayer

## Install

Generate a new repository from this template.

## Usage

Before using this mod template, make sure that you have installed XMake and a Minecraft Bedrock Server with LeviLamina.
+ Use lip

1. Clone the new repository into a local folder.
```bash
lip install github.com/CoralFans-Dev/CFSP
```

1. Change the mod name and the expected LeviLamina version in `xmake.lua`.

1. Add your code.

1. Run `xmake repo -u` in the root of the repository.

1. Run `xmake` to build the mod.
## Usage

Now the build is complete at `bin/`.
+ See [doc-page](https://coralfans-dev.github.io/CoralFans-doc/) for more info.

## Contributing

Expand All @@ -32,4 +22,4 @@ PRs accepted.

## License

CC0-1.0 © LiteLDev
AGPL v3 License
5 changes: 3 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"name": "${modName}",
"entry": "${modFile}",
"version": "${modVersion}",
"type": "native"
}
"type": "native",
"author": "CoralFans-Dev"
}
4 changes: 4 additions & 0 deletions scripts/after_build.lua
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ function pack_mod(target,mod_define)
os.cp(oripdbfile, pdbfile)
end

-- Copy i18n files.
local langfile = path.join(os.projectdir(), "src", "lang")
os.cp(langfile, path.join(outputdir, "lang"))

formattedmanifest = string_formatter(manifest, mod_define)
io.writefile(manifestfile,formattedmanifest)
cprint("${bright green}[mod Packer]: ${reset}mod already generated to " .. outputdir)
Expand Down
72 changes: 72 additions & 0 deletions src/cfsp/CFSP.cpp
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);
10 changes: 5 additions & 5 deletions src/mod/MyMod.h → src/cfsp/CFSP.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

#include "ll/api/mod/NativeMod.h"

namespace my_mod {
namespace coral_fans::cfsp {

class MyMod {
class CFSP {

public:
static MyMod& getInstance();
static CFSP& getInstance();

MyMod(ll::mod::NativeMod& self) : mSelf(self) {}
CFSP(ll::mod::NativeMod& self) : mSelf(self) {}

[[nodiscard]] ll::mod::NativeMod& getSelf() const { return mSelf; }

Expand All @@ -30,4 +30,4 @@ class MyMod {
ll::mod::NativeMod& mSelf;
};

} // namespace my_mod
} // namespace coral_fans::cfsp
42 changes: 42 additions & 0 deletions src/cfsp/Config.h
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.
Loading

0 comments on commit 4b421b8

Please sign in to comment.