Skip to content

Commit

Permalink
feat: resolve #1519, add new thunks to link and get address
Browse files Browse the repository at this point in the history
  • Loading branch information
OEOTYAN committed Oct 15, 2024
1 parent ec74960 commit 7637dde
Show file tree
Hide file tree
Showing 32 changed files with 138 additions and 120 deletions.
6 changes: 3 additions & 3 deletions src-server/ll/api/Versions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ data::Version getGameVersion() {
auto info = Common::getBuildInfo();
auto v = data::Version{info.mBuildId};
v.preRelease = data::PreRelease{};
v.preRelease->values.emplace_back((uint16_t)SharedConstants::RevisionVersion);
v.preRelease->values.emplace_back((uint16_t)SharedConstants::NetworkProtocolVersion);
v.preRelease->values.emplace_back((uint16_t)SharedConstants::RevisionVersion());
v.preRelease->values.emplace_back((uint16_t)SharedConstants::NetworkProtocolVersion());
v.build = info.mCommitId.substr(0, std::min(info.mCommitId.size(), (size_t)7));
return v;
}();
return ver;
}

int getNetworkProtocolVersion() { return SharedConstants::NetworkProtocolVersion; }
int getNetworkProtocolVersion() { return SharedConstants::NetworkProtocolVersion(); }

} // namespace ll
2 changes: 1 addition & 1 deletion src-server/ll/api/event/player/PlayerChatEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ LL_TYPE_INSTANCE_HOOK(
PlayerSendMessageEventHook,
HookPriority::Normal,
ServerNetworkHandler,
&ServerNetworkHandler::handle,
&ServerNetworkHandler::handle$,
void,
NetworkIdentifier const& identifier,
TextPacket const& packet
Expand Down
2 changes: 1 addition & 1 deletion src-server/ll/api/event/player/PlayerJoinEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ LL_TYPE_INSTANCE_HOOK(
PlayerJoinEventHook,
HookPriority::Normal,
ServerNetworkHandler,
&ServerNetworkHandler::handle,
&ServerNetworkHandler::handle$,
void,
NetworkIdentifier const& identifier,
SetLocalPlayerAsInitializedPacket const& packet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ LL_TYPE_INSTANCE_HOOK(
PlayerActionEventHook,
HookPriority::Normal,
ServerNetworkHandler,
&ServerNetworkHandler::handle,
&ServerNetworkHandler::handle$,
void,
NetworkIdentifier const& id,
PlayerActionPacket const& packet
Expand Down
2 changes: 1 addition & 1 deletion src-server/ll/api/event/player/PlayerSwingEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ LL_TYPE_INSTANCE_HOOK(
PlayerSwingEventHook,
HookPriority::Normal,
ServerNetworkHandler,
&ServerNetworkHandler::handle,
&ServerNetworkHandler::handle$,
void,
NetworkIdentifier const& id,
AnimatePacket const& packet
Expand Down
72 changes: 51 additions & 21 deletions src-server/ll/api/service/TargetedBedrock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "ll/api/memory/Hook.h"

#include "mc/common/IMinecraftApp.h"
#include "mc/deps/ecs/systems/EntitySystemsCollection.h"
#include "mc/deps/raknet/RakPeer.h"
#include "mc/deps/raknet/RakPeerInterface.h"
Expand Down Expand Up @@ -52,7 +53,7 @@ LL_TYPE_INSTANCE_HOOK(MinecraftInit, HookPriority::High, Minecraft, &Minecraft::
minecraft = this;
origin();
}
LL_INSTANCE_HOOK(MinecraftDestructor, HookPriority::High, "??1Minecraft@@UEAA@XZ", void) {
LL_TYPE_INSTANCE_HOOK(MinecraftDestructor, HookPriority::High, Minecraft, &Minecraft::dtor$, void) {
minecraft = nullptr;
origin();
}
Expand All @@ -73,24 +74,33 @@ LL_TYPE_INSTANCE_HOOK(
unhook();
origin(a1, a2);
}
LL_INSTANCE_HOOK(ServerNetworkHandlerDestructor, HookPriority::High, "??1ServerNetworkHandler@@UEAA@XZ", void) {
LL_TYPE_INSTANCE_HOOK(
ServerNetworkHandlerDestructor,
HookPriority::High,
ServerNetworkHandler,
&ServerNetworkHandler::dtor$,
void
) {
serverNetworkHandler = nullptr;
origin();
}

// NetworkSystem
static std::atomic<NetworkSystem*> networkSystem;

LL_INSTANCE_HOOK(
LL_TYPE_INSTANCE_HOOK(
NetworkSystemConstructor,
HookPriority::High,
"??0NetworkSystem@@IEAA@$$QEAUDependencies@0@@Z",
NetworkSystem*,
NetworkSystem,
&NetworkSystem::ctor$,
void*,
struct NetworkSystem::Dependencies&& dependencies
) {
return networkSystem = origin(std::move(dependencies));
auto res = origin(std::move(dependencies));
networkSystem = this;
return res;
}
LL_INSTANCE_HOOK(NetworkSystemDestructor, HookPriority::High, "??1NetworkSystem@@MEAA@XZ", void) {
LL_TYPE_INSTANCE_HOOK(NetworkSystemDestructor, HookPriority::High, NetworkSystem, &NetworkSystem::dtor$, void) {
networkSystem = nullptr;
origin();
}
Expand All @@ -106,24 +116,26 @@ LL_TYPE_INSTANCE_HOOK(
void,
ServerInstance& ins
) {
level = ll::service::getMinecraft()->getLevel();
level = getMinecraft()->getLevel();
origin(ins);
}
LL_INSTANCE_HOOK(LevelDestructor, HookPriority::High, "??1Level@@UEAA@XZ", void) {
LL_TYPE_INSTANCE_HOOK(LevelDestructor, HookPriority::High, Level, &Level::dtor$, void) {
level = nullptr;
origin();
}

// RakNet::RakPeer
static std::atomic<RakNet::RakPeer*> rakPeer;

LL_INSTANCE_HOOK(RakNetRakPeerConstructor, HookPriority::High, "??0RakPeer@RakNet@@QEAA@XZ", RakNet::RakPeer*) {
LL_TYPE_INSTANCE_HOOK(RakNetRakPeerConstructor, HookPriority::High, RakNet::RakPeer, &RakNet::RakPeer::ctor$, void*) {
unhook();
return rakPeer = origin();
auto res = origin();
rakPeer = this;
return res;
}

LL_INSTANCE_HOOK(RakNetRakPeerDestructor, HookPriority::High, "??1RakPeer@RakNet@@UEAA@XZ", void) {
if ((void*)this == (void*)ll::service::getRakPeer()) rakPeer = nullptr;
LL_TYPE_INSTANCE_HOOK(RakNetRakPeerDestructor, HookPriority::High, RakNet::RakPeer, &RakNet::RakPeer::dtor$, void) {
if ((void*)this == (void*)getRakPeer()) rakPeer = nullptr;
origin();
}

Expand All @@ -140,7 +152,13 @@ LL_TYPE_INSTANCE_HOOK(
resourcePackRepository = this;
origin();
}
LL_INSTANCE_HOOK(ResourcePackRepositoryDestructor, HookPriority::High, "??1ResourcePackRepository@@QEAA@XZ", void) {
LL_TYPE_INSTANCE_HOOK(
ResourcePackRepositoryDestructor,
HookPriority::High,
ResourcePackRepository,
&ResourcePackRepository::dtor$,
void
) {
resourcePackRepository = nullptr;
origin();
}
Expand All @@ -152,24 +170,36 @@ LL_TYPE_INSTANCE_HOOK(
CommandRegistryConstructor,
HookPriority::High,
CommandRegistry,
"??0CommandRegistry@@QEAA@_N@Z",
CommandRegistry*,
&CommandRegistry::ctor$,
void*,
bool eduMode
) {
return commandRegistry = origin(eduMode);
auto res = origin(eduMode);
commandRegistry = this;
return res;
}
LL_INSTANCE_HOOK(CommandRegistryDestructor, HookPriority::High, "??1CommandRegistry@@QEAA@XZ", void) {
LL_TYPE_INSTANCE_HOOK(CommandRegistryDestructor, HookPriority::High, CommandRegistry, &CommandRegistry::dtor$, void) {
commandRegistry = nullptr;
origin();
}

// ServerInstance
static std::atomic<ServerInstance*> serverInstance;

LL_TYPE_INSTANCE_HOOK(ServerInstanceConstructor, HookPriority::High, ServerInstance, "??0ServerInstance@@QEAA@AEAVIMinecraftApp@@AEBV?$not_null@V?$NonOwnerPointer@VServerInstanceEventCoordinator@@@Bedrock@@@gsl@@@Z", ServerInstance*) {
return serverInstance = origin();
LL_TYPE_INSTANCE_HOOK(
ServerInstanceConstructor,
HookPriority::High,
ServerInstance,
&ServerInstance::ctor$,
void*,
IMinecraftApp& app,
Bedrock::NotNullNonOwnerPtr<ServerInstanceEventCoordinator> const& coordinator
) {
auto res = origin(app, coordinator);
serverInstance = this;
return res;
}
LL_INSTANCE_HOOK(ServerInstanceDestructor, HookPriority::High, "??1ServerInstance@@UEAA@XZ", void) {
LL_TYPE_INSTANCE_HOOK(ServerInstanceDestructor, HookPriority::High, ServerInstance, &ServerInstance::dtor$, void) {
serverInstance = nullptr;
origin();
}
Expand Down
8 changes: 4 additions & 4 deletions src-server/ll/core/main_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ BOOL WINAPI ConsoleExitHandler(DWORD CEvent) {
case CTRL_C_EVENT:
case CTRL_CLOSE_EVENT:
case CTRL_SHUTDOWN_EVENT: {
if (StopCommand::mServer) {
StopCommand::mServer->requestServerShutdown("");
if (StopCommand::mServer()) {
StopCommand::mServer()->requestServerShutdown("");
} else {
std::terminate();
}
Expand All @@ -144,7 +144,7 @@ void unixSignalHandler(int signum) {
switch (signum) {
case SIGINT:
case SIGTERM: {
if (StopCommand::mServer) StopCommand::mServer->requestServerShutdown("");
if (StopCommand::mServer()) StopCommand::mServer()->requestServerShutdown("");
else std::terminate();
break;
}
Expand Down Expand Up @@ -194,7 +194,7 @@ void leviLaminaMain() {
mod::ModRegistrar::getInstance().loadAllMods();
}

LL_AUTO_STATIC_HOOK(LeviLaminaMainHook, HookPriority::High, "main", int, int argc, char* argv[]) {
LL_AUTO_STATIC_HOOK(LeviLaminaMainHook, HookPriority::High, "main"_sym, int, int argc, char* argv[]) {

#if defined(LL_DEBUG)
static stacktrace_utils::SymbolLoader symbols{};
Expand Down
4 changes: 1 addition & 3 deletions src-test/client/jsonUITest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ LL_AUTO_TYPE_INSTANCE_HOOK(
TESTAAAA,
HookPriority::Normal,
Item,
"?appendFormattedHovertext@Item@@UEBAXAEBVItemStackBase@@AEAVLevel@@AEAV?$basic_string@DU?$char_traits@D@std@@"
"V?$"
"allocator@D@2@@std@@_N@Z",
&Item::appendFormattedHovertext$,
void,
class ItemStackBase const& stack,
Level& level,
Expand Down
4 changes: 3 additions & 1 deletion src-test/server/Packet_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

#include "magic_enum.hpp"

using namespace ll::literals;

template <>
struct magic_enum::customize::enum_range<MinecraftPacketIds> {
static constexpr int min = 0;
Expand Down Expand Up @@ -124,7 +126,7 @@ void autoGenerate() {
}
}

LL_AUTO_STATIC_HOOK(GeneratePacketHook, HookPriority::Normal, "main", int, int a, char* c) {
LL_AUTO_STATIC_HOOK(GeneratePacketHook, HookPriority::Normal, "main"_sym, int, int a, char* c) {
autoGenerate();
return origin(a, c);
}
Expand Down
4 changes: 2 additions & 2 deletions src-test/server/TestNbt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,6 @@ LL_AUTO_TYPE_INSTANCE_HOOK(NbtTest, HookPriority::Normal, ServerInstance, &Serve
->toSnbt(SnbtFormat::PrettyConsolePrint)
);

ll::getLogger().debug("signature {}", "48 8D 05 ? ? ? ? E8"_sigv.toString(false, false));
ll::getLogger().debug("resolve {}", "48 8D 05 ? ? ? ? E8"_sigv.resolve());
ll::getLogger().debug("signature {}", "48 8D 05 ? ? ? ? E8"_sig.toString(false, false));
ll::getLogger().debug("resolve {}", "48 8D 05 ? ? ? ? E8"_sig.resolve());
}
14 changes: 14 additions & 0 deletions src/ll/api/base/Alias.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#pragma once

namespace ll {
template <class T, size_t N>
struct CArray {
using type = T[N];
};
template <class T>
struct CArray<T, 0> {
using type = T[];
};
template <class T, size_t N = 0>
using CArrayT = typename CArray<T, N>::type;
} // namespace ll
2 changes: 1 addition & 1 deletion src/ll/api/event/command/ExecuteCommandEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ LL_TYPE_INSTANCE_HOOK(
auto event = ExecutingCommandEvent{*this, context, suppressOutput};
EventBus::getInstance().publish(event);
if (event.isCancelled()) {
return MCRESULT_CommandsDisabled;
return MCRESULT_CommandsDisabled();
}
return origin(context, suppressOutput);
}
Expand Down
9 changes: 1 addition & 8 deletions src/ll/api/event/entity/MobDieEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,7 @@ void MobDieEvent::serialize(CompoundTag& nbt) const {
ActorDamageSource const& MobDieEvent::source() const { return mSource; }


LL_TYPE_INSTANCE_HOOK(
MobDieEventHook,
HookPriority::Normal,
Mob,
"?die@Mob@@UEAAXAEBVActorDamageSource@@@Z",
void,
ActorDamageSource const& source
) {
LL_TYPE_INSTANCE_HOOK(MobDieEventHook, HookPriority::Normal, Mob, &Mob::die$, void, ActorDamageSource const& source) {
auto ev = MobDieEvent(*this, source);
EventBus::getInstance().publish(ev);
return origin(source);
Expand Down
2 changes: 1 addition & 1 deletion src/ll/api/event/player/PlayerAddExperienceEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ LL_TYPE_INSTANCE_HOOK(
PlayerAddExperienceEventHook,
HookPriority::Normal,
Player,
"?addExperience@Player@@UEAAXH@Z",
&Player::addExperience$,
void,
int exp
) {
Expand Down
2 changes: 1 addition & 1 deletion src/ll/api/event/player/PlayerAttackEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ LL_TYPE_INSTANCE_HOOK(
PlayerAttackEventHook,
HookPriority::Normal,
Player,
"?attack@Player@@UEAA_NAEAVActor@@AEBW4ActorDamageCause@@@Z",
&Player::attack$,
bool,
Actor& ac,
ActorDamageCause const& cause
Expand Down
2 changes: 1 addition & 1 deletion src/ll/api/event/player/PlayerDieEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ LL_TYPE_INSTANCE_HOOK(
PlayerDieEventHook,
HookPriority::Normal,
Player,
"?die@Player@@UEAAXAEBVActorDamageSource@@@Z",
&Player::die$,
void,
ActorDamageSource const& source
) {
Expand Down
2 changes: 1 addition & 1 deletion src/ll/api/event/player/PlayerInteractBlockEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ LL_TYPE_INSTANCE_HOOK(
PlayerInteractBlockEventHook,
HookPriority::Normal,
GameMode,
"?useItemOn@GameMode@@UEAA?AVInteractionResult@@AEAVItemStack@@AEBVBlockPos@@EAEBVVec3@@PEBVBlock@@@Z",
&GameMode::useItemOn$,
InteractionResult,
ItemStack& item,
BlockPos const& blockPos,
Expand Down
2 changes: 1 addition & 1 deletion src/ll/api/event/player/PlayerPlaceBlockEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ LL_TYPE_INSTANCE_HOOK(
PlayerPlacingBlockEventHook,
HookPriority::Normal,
BlockSource,
"?checkBlockPermissions@BlockSource@@UEAA_NAEAVActor@@AEBVBlockPos@@EAEBVItemStackBase@@_N@Z",
&BlockSource::checkBlockPermissions$,
bool,
Actor& actor,
BlockPos const& blockpos,
Expand Down
2 changes: 1 addition & 1 deletion src/ll/api/event/player/PlayerRespawnEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace ll::event::inline player {

LL_TYPE_INSTANCE_HOOK(PlayerRespawnEventHook, HookPriority::Normal, Player, "?respawn@Player@@UEAAXXZ", void) {
LL_TYPE_INSTANCE_HOOK(PlayerRespawnEventHook, HookPriority::Normal, Player, &Player::respawn$, void) {
// If the player returns from end or just joins server, his health will > 0
if (this->getHealth() <= 0) {
EventBus::getInstance().publish(PlayerRespawnEvent(*this));
Expand Down
4 changes: 2 additions & 2 deletions src/ll/api/event/world/FireSpreadEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ LL_TYPE_INSTANCE_HOOK(
FireSpreadEventHook1,
HookPriority::Normal,
FireBlock,
"?onPlace@FireBlock@@UEBAXAEAVBlockSource@@AEBVBlockPos@@@Z",
&FireBlock::onPlace$,
void,
BlockSource& blockSource,
BlockPos const& blockPos
Expand All @@ -34,7 +34,7 @@ LL_TYPE_INSTANCE_HOOK(
FireSpreadEventHook2,
HookPriority::Normal,
FireBlock,
"?mayPlace@FireBlock@@UEBA_NAEAVBlockSource@@AEBVBlockPos@@@Z",
&FireBlock::mayPlace$,
bool,
BlockSource& blockSource,
BlockPos const& blockPos
Expand Down
4 changes: 2 additions & 2 deletions src/ll/api/i18n/I18n.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ namespace ll::i18n::detail {
template <LL_I18N_STRING_LITERAL_TYPE str>
struct TrStrOut;
#ifndef LL_I18N_COLLECT_STRINGS_CUSTOM
template <LL_I18N_STRING_LITERAL_TYPE str>
struct TrStrOut {
template <LL_I18N_STRING_LITERAL_TYPE str>
struct TrStrOut {
static inline int _ = [] {
fmt::print("\"{0}\": \"{0}\", // at {1}\n", str.sv(), str.loc().toString());
return 0;
Expand Down
Loading

0 comments on commit 7637dde

Please sign in to comment.