Skip to content

Commit fd1672b

Browse files
committed
fix: fix events except for inlined functions
1 parent dda5e5b commit fd1672b

File tree

5 files changed

+146
-132
lines changed

5 files changed

+146
-132
lines changed

src/lse/events/BlockEvents.cpp

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ LL_TYPE_INSTANCE_HOOK(
6565
return origin(slotNumber, oldItem, newItem);
6666

6767
Player& player = mUnk84d147.as<Player&>();
68-
if (player.hasOpenContainer()) {
68+
// Player::hasOpenContainer()
69+
if (player.mContainerManager) {
6970
if (!CallEvent(
7071
EVENT_TYPES::onContainerChange,
7172
PlayerClass::newPlayer(&player),
@@ -169,7 +170,7 @@ LL_TYPE_INSTANCE_HOOK(
169170
}
170171
if (!CallEvent(
171172
EVENT_TYPES::onPistonTryPush,
172-
IntPos::newPos(this->getPosition(), region.getDimensionId()),
173+
IntPos::newPos(this->mPosition, region.getDimensionId()),
173174
BlockClass::newBlock(curPos, region.getDimensionId())
174175
)) {
175176
return false;
@@ -181,7 +182,7 @@ LL_TYPE_INSTANCE_HOOK(
181182
if (shouldPush) {
182183
CallEvent( // Not cancellable
183184
EVENT_TYPES::onPistonPush,
184-
IntPos::newPos(this->getPosition(), region.getDimensionId()),
185+
IntPos::newPos(this->mPosition, region.getDimensionId()),
185186
BlockClass::newBlock(curPos, region.getDimensionId())
186187
);
187188
}
@@ -249,26 +250,26 @@ LL_TYPE_STATIC_HOOK(
249250
origin(player, pos, region, level);
250251
}
251252

252-
LL_TYPE_INSTANCE_HOOK(
253-
BlockExplodedHook,
254-
HookPriority::Normal,
255-
Block,
256-
&Block::onExploded,
257-
void,
258-
BlockSource& region,
259-
BlockPos const& pos,
260-
Actor* entitySource
261-
) {
262-
IF_LISTENED(EVENT_TYPES::onBlockExploded) {
263-
CallEvent(
264-
EVENT_TYPES::onBlockExploded,
265-
BlockClass::newBlock(pos, region.getDimensionId()),
266-
EntityClass::newEntity(entitySource)
267-
);
268-
}
269-
IF_LISTENED_END(EVENT_TYPES::onBlockExploded);
270-
origin(region, pos, entitySource);
271-
}
253+
// LL_TYPE_INSTANCE_HOOK(
254+
// BlockExplodedHook,
255+
// HookPriority::Normal,
256+
// Block,
257+
// &Block::onExploded,
258+
// void,
259+
// BlockSource& region,
260+
// BlockPos const& pos,
261+
// Actor* entitySource
262+
//) {
263+
// IF_LISTENED(EVENT_TYPES::onBlockExploded) {
264+
// CallEvent(
265+
// EVENT_TYPES::onBlockExploded,
266+
// BlockClass::newBlock(pos, region.getDimensionId()),
267+
// EntityClass::newEntity(entitySource)
268+
// );
269+
// }
270+
// IF_LISTENED_END(EVENT_TYPES::onBlockExploded);
271+
// origin(region, pos, entitySource);
272+
// }
272273

273274
namespace redstone {
274275
inline bool RedstoneUpdateEvent(BlockSource& region, BlockPos const& pos, int& strength, bool& isFirstTime) {
@@ -368,7 +369,7 @@ LL_TYPE_INSTANCE_HOOK(
368369
if (commandOrigin.getOriginType() == CommandOriginType::MinecartCommandBlock) {
369370
if (!CallEvent(
370371
EVENT_TYPES::onCmdBlockExecute,
371-
String::newString(this->getCommand()),
372+
String::newString(this->mCommand),
372373
FloatPos::newPos(commandOrigin.getEntity()->getPosition(), region.getDimensionId()),
373374
Boolean::newBoolean(true)
374375
)) {
@@ -377,7 +378,7 @@ LL_TYPE_INSTANCE_HOOK(
377378
} else {
378379
if (!CallEvent(
379380
EVENT_TYPES::onCmdBlockExecute,
380-
String::newString(this->getCommand()),
381+
String::newString(this->mCommand),
381382
FloatPos::newPos(commandOrigin.getBlockPosition(), region.getDimensionId()),
382383
Boolean::newBoolean(false)
383384
)) {
@@ -475,7 +476,9 @@ void FarmDecayEvent() { FarmDecayHook::hook(); }
475476
void PistonPushEvent() { PistonPushHook::hook(); }
476477
void ExplodeEvent() { ExplodeHook::hook(); }
477478
void RespawnAnchorExplodeEvent() { RespawnAnchorExplodeHook::hook(); }
478-
void BlockExplodedEvent() { BlockExplodedHook ::hook(); }
479+
void BlockExplodedEvent() {
480+
// BlockExplodedHook ::hook();
481+
}
479482
void RedstoneUpdateEvent() {
480483
redstone::RedstoneTorchBlockHook::hook();
481484
redstone::RedStoneWireBlockHook::hook();

src/lse/events/EntityEvents.cpp

Lines changed: 50 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "ll/api/memory/Memory.h"
88
#include "ll/api/service/Bedrock.h"
99
#include "ll/api/service/GamingStatus.h"
10+
#include "mc/common/Globals.h"
1011
#include "mc/deps/core/string/HashedString.h"
1112
#include "mc/deps/shared_types/legacy/actor/ActorDamageCause.h"
1213
#include "mc/entity/components_json_legacy/NpcComponent.h"
@@ -27,6 +28,8 @@
2728
#include "mc/world/actor/player/Player.h"
2829
#include "mc/world/effect/EffectDuration.h"
2930
#include "mc/world/effect/MobEffectInstance.h"
31+
#include "mc/world/events/ActorEventCoordinator.h"
32+
#include "mc/world/events/ProjectileHitEvent.h"
3033
#include "mc/world/item/CrossbowItem.h"
3134
#include "mc/world/item/ItemInstance.h"
3235
#include "mc/world/item/ItemStack.h"
@@ -51,11 +54,12 @@ LL_TYPE_INSTANCE_HOOK(
5154
Vec3 const& direction
5255
) {
5356
IF_LISTENED(EVENT_TYPES::onSpawnProjectile) {
54-
if (id._getLegacyActorType() != ActorType::Trident) {
57+
static auto& tridentName = EntityCanonicalName(ActorType::Trident);
58+
if (id.mCanonicalName.get() != tridentName) {
5559
if (!CallEvent(
5660
EVENT_TYPES::onSpawnProjectile,
5761
EntityClass::newEntity(spawner),
58-
String::newString(id.getCanonicalName())
62+
String::newString(id.mCanonicalName->getString())
5963
)) {
6064
return nullptr;
6165
}
@@ -179,30 +183,28 @@ LL_TYPE_INSTANCE_HOOK(
179183
origin(owner, res);
180184
}
181185

182-
LL_TYPE_INSTANCE_HOOK(
183-
ProjectileHitBlockHook,
184-
HookPriority::Normal,
185-
Block,
186-
&Block::onProjectileHit,
187-
void,
188-
BlockSource& region,
189-
BlockPos const& pos,
190-
Actor const& projectile
191-
) {
192-
IF_LISTENED(EVENT_TYPES::onProjectileHitBlock) {
193-
if (pos != BlockPos::ZERO() && !this->isAir()) {
194-
if (!CallEvent(
195-
EVENT_TYPES::onProjectileHitBlock,
196-
BlockClass::newBlock(*this, pos, region),
197-
EntityClass::newEntity(&const_cast<Actor&>(projectile))
198-
)) {
199-
return;
200-
}
201-
}
202-
}
203-
IF_LISTENED_END(EVENT_TYPES::onProjectileHitBlock);
204-
origin(region, pos, projectile);
205-
}
186+
// LL_TYPE_INSTANCE_HOOK(
187+
// ProjectileHitBlockHook,
188+
// HookPriority::Normal,
189+
// ActorEventCoordinator,
190+
// &ActorEventCoordinator::sendEvent,
191+
// CoordinatorResult,
192+
// EventRef<ActorGameplayEvent<CoordinatorResult>> const& event
193+
//) {
194+
// IF_LISTENED(EVENT_TYPES::onProjectileHitBlock) {
195+
// if (pos != BlockPos::ZERO() && !this->isAir()) {
196+
// if (!CallEvent(
197+
// EVENT_TYPES::onProjectileHitBlock,
198+
// BlockClass::newBlock(*this, pos, region),
199+
// EntityClass::newEntity(&const_cast<Actor&>(projectile))
200+
// )) {
201+
// return CoordinatorResult::Cancel;
202+
// }
203+
// }
204+
// }
205+
// IF_LISTENED_END(EVENT_TYPES::onProjectileHitBlock);
206+
// origin(event);
207+
// }
206208

207209
LL_TYPE_INSTANCE_HOOK(
208210
MobHurtHook,
@@ -231,7 +233,7 @@ LL_TYPE_INSTANCE_HOOK(
231233
EntityClass::newEntity(this),
232234
damageSource ? EntityClass::newEntity(damageSource) : Local<Value>(),
233235
Number::newNumber(damage < 0.0f ? -damage : damage),
234-
Number::newNumber((int)source.getCause())
236+
Number::newNumber((int)source.mCause)
235237
)) {
236238
return false;
237239
}
@@ -252,7 +254,8 @@ LL_TYPE_INSTANCE_HOOK(
252254
IF_LISTENED(EVENT_TYPES::onMobHurt) {
253255
// Mob is still hurt after hook Mob::$hurtEffects, and all hurt events are handled by this function, but we just
254256
// need magic damage.
255-
if (source.getCause() == ActorDamageCause::Magic || source.getCause() == ActorDamageCause::Wither) {
257+
if (source.mCause == SharedTypes::Legacy::ActorDamageCause::Magic
258+
|| source.mCause == SharedTypes::Legacy::ActorDamageCause::Wither) {
256259
Actor* damageSource = nullptr;
257260
if (source.isEntitySource()) {
258261
if (source.isChildEntitySource()) {
@@ -267,7 +270,7 @@ LL_TYPE_INSTANCE_HOOK(
267270
EntityClass::newEntity(this),
268271
damageSource ? EntityClass::newEntity(damageSource) : Local<Value>(),
269272
Number::newNumber(damage < 0.0f ? -damage : damage),
270-
Number::newNumber((int)source.getCause())
273+
Number::newNumber((int)source.mCause)
271274
)) {
272275
return 0.0f;
273276
}
@@ -289,9 +292,12 @@ LL_TYPE_INSTANCE_HOOK(
289292
::std::string const& sceneName
290293
) {
291294
IF_LISTENED(EVENT_TYPES::onNpcCmd) {
292-
auto action = this->getActionsContainer().at(actionIndex);
293-
if (std::holds_alternative<npc::CommandAction>(*action)) {
294-
auto& commands = std::get<npc::CommandAction>(*action).commands;
295+
auto& action =
296+
mActionsContainer->mUnke14f11.as<std::vector<std::variant<npc::CommandAction, npc::UrlAction>>>().at(
297+
actionIndex
298+
);
299+
if (std::holds_alternative<npc::CommandAction>(action)) {
300+
auto& commands = std::get<npc::CommandAction>(action).commands;
295301
std::string command;
296302
for (auto& cmd : commands.get()) {
297303
command += cmd.mUnk879303.as<std::string>() + ";";
@@ -316,26 +322,26 @@ LL_TYPE_INSTANCE_HOOK(
316322
LL_TYPE_INSTANCE_HOOK(
317323
EffectUpdateHook,
318324
HookPriority::Normal,
319-
MobEffectInstance,
320-
&MobEffectInstance::updateEffects,
325+
Actor,
326+
&Actor::onEffectUpdated,
321327
void,
322-
::Actor* mob
328+
MobEffectInstance& effect
323329
) {
324330
IF_LISTENED(EVENT_TYPES::onEffectUpdated) {
325-
if (mob->isPlayer()) {
331+
if (isPlayer()) {
326332
if (!CallEvent(
327333
EVENT_TYPES::onEffectUpdated,
328-
PlayerClass::newPlayer(static_cast<Player*>(mob)),
329-
String::newString(getComponentName().getString()),
330-
Number::newNumber(getAmplifier()),
331-
Number::newNumber(getDuration().getValueForSerialization())
334+
PlayerClass::newPlayer(reinterpret_cast<Player*>(this)),
335+
String::newString(MobEffect::mMobEffects()[effect.mId]->mComponentName->getString()),
336+
Number::newNumber(effect.mAmplifier),
337+
Number::newNumber(effect.mDuration->mValue)
332338
)) {
333339
return;
334340
}
335341
}
336342
}
337343
IF_LISTENED_END(EVENT_TYPES::onEffectUpdated);
338-
origin(mob);
344+
origin(effect);
339345
}
340346

341347
LL_TYPE_INSTANCE_HOOK(
@@ -371,7 +377,9 @@ void ProjectileCreatedEvent() { ProjectileSpawnHook1::hook(); };
371377
void ActorRideEvent() { ActorRideHook::hook(); }
372378
void WitherDestroyEvent() { WitherDestroyHook::hook(); }
373379
void ProjectileHitEntityEvent() { ProjectileHitEntityHook::hook(); }
374-
void ProjectileHitBlockEvent() { ProjectileHitBlockHook::hook(); }
380+
void ProjectileHitBlockEvent() {
381+
// ProjectileHitBlockHook::hook();
382+
}
375383
void MobHurtEvent() {
376384
MobHurtHook::hook();
377385
MobHurtEffectHook::hook();

src/lse/events/OtherEvents.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,16 @@ LL_TYPE_INSTANCE_HOOK(
2222
Objective const& obj
2323
) {
2424
IF_LISTENED(EVENT_TYPES::onScoreChanged) {
25-
if (id.getIdentityDef().isPlayerType()) {
25+
auto& idRef = id.mIdentityDef;
26+
if (idRef && idRef->mIdentityType == IdentityDefinition::Type::Player) {
2627
if (!CallEvent(
2728
EVENT_TYPES::onScoreChanged,
2829
PlayerClass::newPlayer(
29-
ll::service::getLevel()->getPlayer(
30-
ActorUniqueID(id.getIdentityDef().getPlayerId().mActorUniqueId)
31-
)
30+
ll::service::getLevel()->getPlayer(ActorUniqueID(idRef->mPlayerId->mActorUniqueId))
3231
),
3332
Number::newNumber(obj.getPlayerScore(id).mValue),
34-
String::newString(obj.getName()),
35-
String::newString(obj.getDisplayName())
33+
String::newString(obj.mName),
34+
String::newString(obj.mDisplayName)
3635
)) {
3736
return;
3837
}

0 commit comments

Comments
 (0)