Skip to content

Commit

Permalink
Merge pull request #22 from n15421/main
Browse files Browse the repository at this point in the history
adapt: adapt LeviLamina 1.0.0-rc.3 and GMLIB-0.13.10
  • Loading branch information
zimuya4153 authored Jan 31, 2025
2 parents d9d246a + b718391 commit d41cc86
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 73 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
"name": "GMLIB"
}
]
}
}
4 changes: 2 additions & 2 deletions src/Command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ void RegisterCommand() {
auto& cmd = ll::command::CommandRegistrar::getInstance()
.getOrCreateCommand("freecamera", tr("freecamera.command.desc"), CommandPermissionLevel::Any);
ll::service::getCommandRegistry()->registerAlias("freecamera", "fc");
cmd.overload().execute<[&](CommandOrigin const& origin, CommandOutput& output) {
cmd.overload().execute([&](CommandOrigin const& origin, CommandOutput& output) {
auto entity = (GMLIB_Actor*)origin.getEntity();
if (entity && entity->isPlayer()) {
auto pl = (Player*)entity;
Expand All @@ -18,5 +18,5 @@ void RegisterCommand() {
}
}
return output.error(tr("freecamera.command.console"));
}>();
});
}
7 changes: 5 additions & 2 deletions src/Config.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#pragma once
#include <iostream>
#include <string>

namespace FreeCamera {

struct Config {
int version = 1;

std::string language = "zh_CN";
};

};
} // namespace FreeCamera
13 changes: 5 additions & 8 deletions src/Entry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@
#include "Global.h"
#include "Language.h"

ll::Logger logger(MOD_NAME);

namespace FreeCamera {

std::unique_ptr<Entry>& Entry::getInstance() {
static std::unique_ptr<Entry> instance;
Entry& Entry::getInstance() {
static Entry instance;
return instance;
}

Expand All @@ -21,8 +19,8 @@ bool Entry::load() {
mI18n->updateOrCreateLanguage("zh_CN", zh_CN);
mI18n->loadAllLanguages();
if (GMLIB::Version::getProtocolVersion() != TARGET_PROTOCOL) {
logger.error(tr("error.protocolMismatch.info"));
logger.error(
getSelf().getLogger().error(tr("error.protocolMismatch.info"));
getSelf().getLogger().error(
tr("error.protocolMismatch.version",
{std::to_string(TARGET_PROTOCOL), std::to_string(GMLIB::Version::getProtocolVersion())})
);
Expand Down Expand Up @@ -50,7 +48,6 @@ bool Entry::unload() {
mConfig.reset();
mI18n.reset();
FreeCamera::freecameraHook(false);
getInstance().reset();
return true;
}

Expand All @@ -63,5 +60,5 @@ GMLIB::Files::I18n::LangI18n& Entry::getI18n() { return mI18n.value(); }
LL_REGISTER_MOD(FreeCamera::Entry, FreeCamera::Entry::getInstance());

std::string tr(std::string const& key, std::vector<std::string> const& data) {
return FreeCamera::Entry::getInstance()->getI18n().get(key, data);
return FreeCamera::Entry::getInstance().getI18n().get(key, data);
}
4 changes: 2 additions & 2 deletions src/Entry.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ namespace FreeCamera {
class Entry {

public:
static std::unique_ptr<Entry>& getInstance();
static Entry& getInstance();

Entry(ll::mod::NativeMod& self) : mSelf(self) {}
Entry() : mSelf(*ll::mod::NativeMod::current()) {}

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

Expand Down
25 changes: 14 additions & 11 deletions src/FreeCamera.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#include "Global.h"
#include "mc/network/packet/UpdateAbilitiesPacket.h"
#include <mc/common/ActorUniqueID.h>
#include <mc/server/ServerPlayer.h>


std::unordered_set<uint64> FreeCamList;

Expand All @@ -9,10 +12,10 @@ void EnableFreeCameraPacket(Player* pl) { ((GMLIB_Player*)pl)->setClientGamemode

void SendFakePlayerPacket(Player* pl) {
// Client Player
auto pkt1 = AddPlayerPacket(*pl);
pkt1.mEntityId.id = pkt1.mEntityId.id + 114514;
auto randomUuid = mce::UUID::random();
pkt1.mUuid = randomUuid;
auto pkt1 = AddPlayerPacket(*pl);
pkt1.mEntityId->rawID = pkt1.mEntityId->rawID + 114514;
auto randomUuid = mce::UUID::random();
pkt1.mUuid = randomUuid;
pl->sendNetworkPacket(pkt1);
// Update Skin
auto skin = pl->getSkin();
Expand All @@ -28,8 +31,8 @@ void SendFakePlayerPacket(Player* pl) {

void DisableFreeCameraPacket(Player* pl) {
((GMLIB_Player*)pl)->setClientGamemode(pl->getPlayerGameType());
auto uniqueId = pl->getOrCreateUniqueID();
uniqueId.id = uniqueId.id + 114514;
auto uniqueId = pl->getOrCreateUniqueID();
uniqueId.rawID = uniqueId.rawID + 114514;
RemoveActorPacket(uniqueId).sendTo(*pl);
UpdateAbilitiesPacket(pl->getOrCreateUniqueID(), pl->getAbilities()).sendTo(*pl);
}
Expand Down Expand Up @@ -85,7 +88,7 @@ LL_TYPE_INSTANCE_HOOK(
ServerPlayerMoveHandleEvent,
ll::memory::HookPriority::Normal,
ServerNetworkHandler,
"?handle@ServerNetworkHandler@@UEAAXAEBVNetworkIdentifier@@AEBVPlayerAuthInputPacket@@@Z",
&ServerNetworkHandler::$handle,
void,
NetworkIdentifier const& id,
PlayerAuthInputPacket const& pkt
Expand All @@ -101,7 +104,7 @@ LL_TYPE_INSTANCE_HOOK(
PlayerGamemodeChangeEvent,
ll::memory::HookPriority::Normal,
Player,
"?setPlayerGameType@Player@@UEAAXW4GameType@@@Z",
&Player::$setPlayerGameType,
void,
::GameType gamemode
) {
Expand All @@ -115,7 +118,7 @@ LL_TYPE_INSTANCE_HOOK(
PlayerHurtEvent,
ll::memory::HookPriority::Normal,
Mob,
"?getDamageAfterResistanceEffect@Mob@@QEBAMAEBVActorDamageSource@@M@Z",
&Mob::getDamageAfterResistanceEffect,
float,
class ActorDamageSource const& a1,
float a2
Expand All @@ -134,7 +137,7 @@ LL_TYPE_INSTANCE_HOOK(
PlayerDieEvent,
ll::memory::HookPriority::Normal,
Player,
"?die@Player@@UEAAXAEBVActorDamageSource@@@Z",
&Player::$die,
void,
class ActorDamageSource const& a1
) {
Expand All @@ -148,7 +151,7 @@ LL_TYPE_INSTANCE_HOOK(
PlayerLeftEvent,
ll::memory::HookPriority::Normal,
ServerPlayer,
"?disconnect@ServerPlayer@@QEAAXXZ",
&ServerPlayer::disconnect,
void
) {
FreeCamList.erase(getNetworkIdentifier().mGuid.g);
Expand Down
5 changes: 2 additions & 3 deletions src/Global.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
#pragma once
#include <include_all.h>

#define MOD_NAME "FreeCamera"
#define TARGET_PROTOCOL 686
#define MOD_NAME "FreeCamera"
#define TARGET_PROTOCOL 766

extern ll::Logger logger;
extern std::unordered_set<uint64> FreeCamList;

extern void RegisterCommand();
Expand Down
2 changes: 1 addition & 1 deletion tooth.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
},
"asset_url": "https://github.com/GroupMountain/FreeCamera/releases/download/v0.13.2/FreeCamera-windows-x64.zip",
"dependencies": {
"github.com/GroupMountain/GMLIB": ">=0.13.8"
"github.com/GroupMountain/GMLIB": ">=0.13.10"
},
"files": {
"place": [
Expand Down
56 changes: 13 additions & 43 deletions xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,55 +3,20 @@ add_rules("mode.debug", "mode.release", "mode.releasedbg")
add_repositories("liteldev-repo https://github.com/LiteLDev/xmake-repo.git")
add_repositories("groupmountain-repo https://github.com/GroupMountain/xmake-repo.git")


if not has_config("vs_runtime") then
set_runtimes("MD")
end

-- Option 1: Use the latest version of LeviLamina released on GitHub.
add_requires("levilamina")
add_requires("gmlib 0.13.7")


-- Option 2: Use a specific version of LeviLamina released on GitHub.
-- add_requires("levilamina x.x.x")

-- Option 3: Use the latest commit of LeviLamina on GitHub.
-- -- Here, "develop" is the branch name. You can change it to any branch name you want.
-- add_requires("levilamina develop")
-- -- You can also use debug build of LeviLamina.
-- -- add_requires("levilamina develop", {debug = true})
-- package("levilamina")
-- add_urls("https://github.com/LiteLDev/LeviLamina.git")

-- add_deps("ctre 3.8.1")
-- add_deps("entt 3.12.2")
-- add_deps("fmt 10.1.1")
-- add_deps("gsl 4.0.0")
-- add_deps("leveldb 1.23")
-- add_deps("magic_enum 0.9.0")
-- add_deps("nlohmann_json 3.11.2")
-- add_deps("rapidjson 1.1.0")
-- add_deps("pcg_cpp 1.0.0")
-- add_deps("pfr 2.1.1")
-- add_deps("preloader 1.4.0")
-- add_deps("symbolprovider 1.1.0")

-- -- You may need to change this to the target BDS version of your choice.
-- add_deps("bdslibrary 1.20.50.03")

-- on_install(function (package)
-- import("package.tools.xmake").install(package)
-- end)
add_requires("levilamina 1.0.0")
add_requires("levibuildscript 0.3.0")
add_requires("gmlib 0.13.10")

target("FreeCamera") -- Change this to your mod name.
add_cxflags(
"/EHa",
"/utf-8"
)
add_defines(
"_HAS_CXX23=1" -- To enable C++23 features
)
add_files(
"src/**.cpp"
)
Expand All @@ -62,12 +27,17 @@ target("FreeCamera") -- Change this to your mod name.
"levilamina",
"gmlib"
)
add_shflags(
"/DELAYLOAD:bedrock_server.dll" -- Magic to import symbols from BDS
add_defines(
"NOMINMAX",
"UNICODE",
"_HAS_CXX17",
"_HAS_CXX20",
"_HAS_CXX23"
)
set_exceptions("none") -- To avoid conflicts with /EHa
add_rules("@levibuildscript/linkrule")
set_exceptions("none")
set_kind("shared")
set_languages("cxx23")
set_languages("cxx20")

after_build(function (target)
local mod_packer = import("scripts.after_build")
Expand All @@ -78,4 +48,4 @@ target("FreeCamera") -- Change this to your mod name.
}

mod_packer.pack_mod(target,mod_define)
end)
end)

0 comments on commit d41cc86

Please sign in to comment.