Skip to content
This repository has been archived by the owner on Nov 1, 2024. It is now read-only.

Commit

Permalink
Release 2.13.0 (LiteLDev#1266)
Browse files Browse the repository at this point in the history
  • Loading branch information
ShrBox authored May 6, 2023
2 parents d610ac6 + 7f8b1be commit d797509
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 138 deletions.
33 changes: 0 additions & 33 deletions LiteLoader/include/llapi/EventAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ class BlockLegacy;
class ArmorStand;
class Objective;
struct ScoreboardId;
class Village;

/**
* @brief The event system.
Expand Down Expand Up @@ -714,38 +713,6 @@ class MobSpawnedEvent : public EventTemplate<MobSpawnedEvent> {
Vec3 mPos;
int mDimensionId = -1;
};
/**
* @brief An event that Raid mob spawn.
*
* @note This event cannot be suppressed.
*/
class RaidMobSpawnEvent : public EventTemplate<RaidMobSpawnEvent> {
public:

/**
* @brief Village Center generated by which village raid
*
*/
Vec3 mVillageCenter;

/**
* @brief Spawn Pos;
*
*/
Vec3 mPos;

/**
* @brief Raid spawn wave number
*
*/
int mWaveNum;

/**
* @brief Spawn Entity IDs;
*
*/
int mActorNum;
};

/* endregion */

Expand Down
52 changes: 16 additions & 36 deletions LiteLoader/include/llapi/mc/Bedrock.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class Value;
class CommandIntegerRange;
struct ActorDefinitionIdentifier;
class CommandItem;
class CommandBlockName;

#undef BEFORE_EXTRA

Expand Down Expand Up @@ -161,7 +162,8 @@ template <>
MCAPI typeid_t<CommandRegistry> type_id<CommandRegistry, ActorDamageCause>();
template <>
MCAPI typeid_t<CommandRegistry> type_id<CommandRegistry, AutomaticID<class Dimension, int>>();
// template MCAPI typeid_t<CommandRegistry> type_id<CommandRegistry, class Block const*>();
template<>
MCAPI typeid_t<CommandRegistry> type_id<CommandRegistry, CommandBlockName>();
template<>
MCAPI typeid_t<CommandRegistry> type_id<CommandRegistry, bool>();
template <>
Expand All @@ -172,8 +174,6 @@ template <>
MCAPI typeid_t<CommandRegistry> type_id<CommandRegistry, class CommandPosition>();
template <>
MCAPI typeid_t<CommandRegistry> type_id<CommandRegistry, class CommandPositionFloat>();
template <>
MCAPI typeid_t<CommandRegistry> type_id<CommandRegistry, class CommandPositionFloat>();
//template <>
//MCAPI typeid_t<CommandRegistry> type_id<CommandRegistry, class CommandSelector<class Actor>>();
template <>
Expand All @@ -198,46 +198,26 @@ template <>
MCAPI typeid_t<CommandRegistry> type_id<CommandRegistry, std::unique_ptr<class Command>>();
template <>
MCAPI typeid_t<CommandRegistry> type_id<CommandRegistry, class WildcardCommandSelector<class Actor>>();
// template MCAPI typeid_t<CommandRegistry> type_id<CommandRegistry, CommandItem>();
template<>
MCAPI typeid_t<CommandRegistry> type_id<CommandRegistry, CommandItem>();
template <>
MCAPI typeid_t<CommandRegistry> type_id<CommandRegistry, CommandIntegerRange>();

// template MCAPI typeid_t<CommandRegistry> type_id<CommandRegistry, ActorDefinitionIdentifier const*>();

template <>
inline typeid_t<CommandRegistry> type_id<CommandRegistry, ActorDefinitionIdentifier const*>() {
static typeid_t<CommandRegistry> id =
*(typeid_t<CommandRegistry>*)dlsym_real("??$type_id@VCommandRegistry@@PEBUActorDefinitionIdentifier@@@Bedrock@@YA?AV?$typeid_t@VCommandRegistry@@@0@XZ");
// static typeid_t<CommandRegistry> id = ([]() -> typeid_t<CommandRegistry> {
// CommandParameterData data =
// SymCall("??$mandatory@VRideCommand@@PEBUActorDefinitionIdentifier@@@commands@@YA?AVCommandParameterData@@PEQRideCommand@@PEBUActorDefinitionIdentifier@@PEBDPEQ2@_N@Z",
// CommandParameterData, void*, char const*, uintptr_t)(nullptr, "entityType", 0);
// return data.tid;
// })();
return id;
};

template <>
inline typeid_t<CommandRegistry> type_id<CommandRegistry, CommandItem>() {
static typeid_t<CommandRegistry> id = *(typeid_t<CommandRegistry>*)dlsym_real(
"??$type_id@VCommandRegistry@@VCommandItem@@@Bedrock@@YA?AV?$typeid_t@VCommandRegistry@@@0@XZ");
return id;
};
template<>
MCAPI typeid_t<CommandRegistry> type_id<CommandRegistry, ActorDefinitionIdentifier const*>();

//template <>
//inline typeid_t<CommandRegistry> type_id<CommandRegistry, bool>() {
// static typeid_t<CommandRegistry> id = *(typeid_t<CommandRegistry>*)dlsym_real(
// "??$type_id@VCommandRegistry@@H@Bedrock@@YA?AV?$typeid_t@VCommandRegistry@@@0@XZ");
//inline typeid_t<CommandRegistry> type_id<CommandRegistry, ActorDefinitionIdentifier const*>() {
// static typeid_t<CommandRegistry> id =
// *(typeid_t<CommandRegistry>*)dlsym_real("??$type_id@VCommandRegistry@@PEBUActorDefinitionIdentifier@@@Bedrock@@YA?AV?$typeid_t@VCommandRegistry@@@0@XZ");
//// static typeid_t<CommandRegistry> id = ([]() -> typeid_t<CommandRegistry> {
//// CommandParameterData data =
//// SymCall("??$mandatory@VRideCommand@@PEBUActorDefinitionIdentifier@@@commands@@YA?AVCommandParameterData@@PEQRideCommand@@PEBUActorDefinitionIdentifier@@PEBDPEQ2@_N@Z",
//// CommandParameterData, void*, char const*, uintptr_t)(nullptr, "entityType", 0);
//// return data.tid;
//// })();
// return id;
//};

template <>
inline typeid_t<CommandRegistry> type_id<CommandRegistry, class CommandBlockName>() {
static typeid_t<CommandRegistry> id = *(typeid_t<CommandRegistry>*)dlsym_real(
"??$type_id@VCommandRegistry@@VCommandBlockName@@@Bedrock@@YA?AV?$typeid_t@VCommandRegistry@@@0@XZ");
return id;
};


#undef AFTER_EXTRA
/**
Expand Down
65 changes: 18 additions & 47 deletions LiteLoader/src/llapi/EventAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,6 @@ DECLARE_EVENT_DATA(PlayerBedEnterEvent);
DECLARE_EVENT_DATA(ScriptPluginManagerEvent);
DECLARE_EVENT_DATA(MobTrySpawnEvent);
DECLARE_EVENT_DATA(MobSpawnedEvent);
DECLARE_EVENT_DATA(RaidMobSpawnEvent);
DECLARE_EVENT_DATA(FormResponsePacketEvent);
DECLARE_EVENT_DATA(ResourcePackInitEvent);
DECLARE_EVENT_DATA(PlayerOpenInventoryEvent);
Expand Down Expand Up @@ -354,15 +353,27 @@ TInstanceHook(bool, "?setLocalPlayerAsInitialized@ServerPlayer@@QEAAXXZ", Server
}

/////////////////// PlayerLeft ///////////////////
THook(void, "?disconnect@ServerPlayer@@QEAAXXZ", ServerPlayer* player) {
TInstanceHook(void, "?disconnect@ServerPlayer@@QEAAXXZ", ServerPlayer) {
IF_LISTENED(PlayerLeftEvent) {
PlayerLeftEvent ev{};
ev.mPlayer = player;
ev.mXUID = player->getXuid();
ev.mPlayer = (Player*)this;
ev.mXUID = this->getXuid();
ev.call();
}
IF_LISTENED_END(PlayerLeftEvent)
return original(this);
}

#include "llapi/mc/SimulatedPlayer.hpp"
TInstanceHook(void, "?simulateDisconnect@SimulatedPlayer@@QEAAXXZ", SimulatedPlayer) {
IF_LISTENED(PlayerLeftEvent) {
PlayerLeftEvent ev{};
ev.mPlayer = (Player*)this;
ev.mXUID = this->getXuid();
ev.call();
}
IF_LISTENED_END(PlayerLeftEvent)
return original(player);
return original(this);
}

/////////////////// PlayerRespawn ///////////////////
Expand Down Expand Up @@ -1324,30 +1335,9 @@ TInstanceHook(void*, "?die@ServerPlayer@@UEAAXAEBVActorDamageSource@@@Z", Server

/////////////////// PlayerDestroy ///////////////////

// TInstanceHook(bool, "?destroyBlock@SurvivalMode@@UEAA_NAEBVBlockPos@@E@Z",
// SurvivalMode, BlockPos a3, unsigned __int8 a4)
//{
// IF_LISTENED(PlayerDestroyBlockEvent)
// {
// if (getPlayer()->isPlayer())
// {
// PlayerDestroyBlockEvent ev{};
// ev.mPlayer = getPlayer();
// auto bl = Level::getBlockInstance(a3, getPlayer()->getDimensionId());
// ev.mBlockInstance = bl;
// if (!ev.call())
// {
// return false;
// }
// }
// }
// IF_LISTENED_END(PlayerDestroyBlockEvent)
// return original(this, a3, a4);
// }

TInstanceHook(bool, "?destroyBlock@GameMode@@UEAA_NAEBVBlockPos@@E@Z", GameMode, BlockPos a3, unsigned __int8 a4) {
TInstanceHook(bool, "?destroyBlock@SurvivalMode@@UEAA_NAEBVBlockPos@@E@Z", GameMode, BlockPos a3, unsigned __int8 a4) {
auto player = getPlayer();
if (player != nullptr && player->isPlayer()) {
if (player && player->isPlayer()) {
IF_LISTENED(PlayerDestroyBlockEvent) {
PlayerDestroyBlockEvent ev{};
ev.mPlayer = player;
Expand Down Expand Up @@ -2134,25 +2124,6 @@ TClasslessInstanceHook(void, "?_setRespawnStage@EndDragonFight@@AEAAXW4RespawnAn
}
}

#include "llapi/mc/Village.hpp"

TInstanceHook(void,
"?_spawnRaidGroup@Village@@AEBA_NVVec3@@EAEAV?$unordered_set@UActorUniqueID@@U?$hash@UActorUniqueID@@@"
"std@@U?$equal_to@UActorUniqueID@@@3@V?$allocator@UActorUniqueID@@@3@@std@@@Z",
Village, Vec3 pos, unsigned char num, std::unordered_set<long long>& actorIDs) {
// actorIDs其实是std::unordered_set<ActorUniqueID>,懒得写hash函数
original(this, pos, num, actorIDs);
IF_LISTENED(RaidMobSpawnEvent) {
RaidMobSpawnEvent ev{};
ev.mVillageCenter = this->getCenter();
ev.mPos = pos;
ev.mWaveNum = num;
ev.mActorNum = actorIDs.size();
ev.call();
}
IF_LISTENED_END(RaidMobSpawnEvent)
}

#include "llapi/impl/FormPacketHelper.h"
#include "llapi/mc/Json.hpp"

Expand Down
5 changes: 2 additions & 3 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# Release 2.13.0-beta.1
# Release 2.13.0

![BDS 1.19.81.01](https://img.shields.io/badge/BDS-1.19.81.01-blue?style=for-the-badge) ![Protocol 582](https://img.shields.io/badge/Protocol-582-orange?style=for-the-badge)

## Added

feat: add 'RaidMobSpawnEvent' event (#1229) (by @Qiuzhizhe)
feat(llse): effect method of Entity(#1225) (#1236) (by @harryxi)
feat: adapt to 1.19.81 (#1237) (by @ShrBox @dreamguxiang @OEOTYAN @quizhizhe)
feat: adapt to 1.19.81 (#1237) (by @ShrBox @dreamguxiang @OEOTYAN @quizhizhe @Tsubasa6848)

## Changed

Expand Down
10 changes: 6 additions & 4 deletions ScriptEngine/src/api/EntityAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1513,13 +1513,15 @@ Local<Value> EntityClass::getAllEffects() {
if (!actor) {
return Local<Value>();
}
auto effects = actor->getAllEffects();
if (effects.size() == 0) {
if (!actor->getActiveEffectCount()) {
return Local<Value>();
}
Local<Array> effectList = Array::newArray();
for (auto effect : effects)
effectList.add(Number::newNumber((int)effect.getId()));
for (unsigned int i = 0; i <= 30; i++) {
if (actor->getEffect(i)) {
effectList.add(Number::newNumber((int)i));
}
}
return effectList;
}
CATCH("Fail in getAllEffects!")
Expand Down
11 changes: 0 additions & 11 deletions ScriptEngine/src/api/EventAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ enum class EVENT_TYPES : int {
/* Entity Events */
onMobDie,
onMobHurt,
onRaidMobSpawn,
onEntityExplode,
onProjectileHitEntity,
onWitherBossDestroy,
Expand Down Expand Up @@ -840,16 +839,6 @@ void EnableEventListener(int eventId) {
});
break;

case EVENT_TYPES::onRaidMobSpawn:
Event::RaidMobSpawnEvent::subscribe([](const RaidMobSpawnEvent& ev) {
IF_LISTENED(EVENT_TYPES::onRaidMobSpawn) {
CallEvent(EVENT_TYPES::onRaidMobSpawn, IntPos::newPos(ev.mVillageCenter), IntPos::newPos(ev.mPos),
Number::newNumber(ev.mWaveNum), Number::newNumber(ev.mActorNum));
}
IF_LISTENED_END(EVENT_TYPES::onRaidMobSpawn)
});
break;

case EVENT_TYPES::onStepOnPressurePlate:
Event::EntityStepOnPressurePlateEvent::subscribe([](const EntityStepOnPressurePlateEvent& ev) {
IF_LISTENED(EVENT_TYPES::onStepOnPressurePlate) {
Expand Down
10 changes: 6 additions & 4 deletions ScriptEngine/src/api/PlayerAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3159,13 +3159,15 @@ Local<Value> PlayerClass::getAllEffects() {
if (!player) {
return Local<Value>();
}
auto effects = player->getAllEffects();
if (effects.size() == 0) {
if (!player->getActiveEffectCount()) {
return Local<Value>();
}
Local<Array> effectList = Array::newArray();
for (auto effect : effects)
effectList.add(Number::newNumber((int)effect.getId()));
for (unsigned int i = 0; i <= 30; i++) {
if (player->getEffect(i)) {
effectList.add(Number::newNumber((int)i));
}
}
return effectList;
}
CATCH("Fail in getAllEffects!")
Expand Down

0 comments on commit d797509

Please sign in to comment.