Skip to content
This repository has been archived by the owner on Oct 30, 2022. It is now read-only.

Commit

Permalink
Match LXL_Player, EntityTransformEvent, and ProjectileCreatedEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
Rjlintkh committed Feb 9, 2022
1 parent 46f7b96 commit 7015992
Show file tree
Hide file tree
Showing 7 changed files with 127 additions and 40 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bdsx/bdsx-lxl",
"version": "1.0.5",
"version": "1.1.0",
"description": "LiteXLoader ported into BDSX",
"main": "index.js",
"keywords": [],
Expand Down
80 changes: 54 additions & 26 deletions src/api/event.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Actor, ActorDamageCause, ActorDamageSource, ActorDefinitionIdentifier, ActorFlags } from "bdsx/bds/actor";
import { Actor, ActorDamageCause, ActorDamageSource, ActorDefinitionIdentifier, ActorFlags, ActorUniqueID } from "bdsx/bds/actor";
import { Block, BlockActor, BlockLegacy, BlockSource } from "bdsx/bds/block";
import { BlockPos, Vec3 } from "bdsx/bds/blockpos";
import { CommandOrigin } from "bdsx/bds/commandorigin";
Expand All @@ -13,6 +13,7 @@ import { RespawnPacket, TextPacket } from "bdsx/bds/packets";
import { Player, ServerPlayer } from "bdsx/bds/player";
import { Objective, Scoreboard, ScoreboardId } from "bdsx/bds/scoreboard";
import { serverInstance } from "bdsx/bds/server";
import { bin } from "bdsx/bin";
import { capi } from "bdsx/capi";
import { CANCEL } from "bdsx/common";
import { StaticPointer } from "bdsx/core";
Expand Down Expand Up @@ -67,10 +68,11 @@ export const LXL_Events = {
onChangeDim: new LXL_Event<(player: LXL_Player, dimid: number) => void>(),
/** Valid 03-02-2022 19:22:22 */
onJump: new LXL_Event<(player: LXL_Player) => void>(),
onEntityTransformation: new LXL_Event<(uniqueId: string, entity: LXL_Entity) => void>(),
onSneak: new LXL_Event<(player: LXL_Player, isSneaking: boolean) => void>(),
onAttackEntity: new LXL_Event<(player: LXL_Player, entity: LXL_Entity) => void | false>(),
onAttackBlock: new LXL_Event<(player: LXL_Player, block: LXL_Block, item: LXL_Item | null) => void | false>(),
onTakeItem: new LXL_Event<(player: LXL_Player, entity: LXL_Entity, item: LXL_Item) => void | false>(),
onTakeItem: new LXL_Event<(player: LXL_Player, entity: LXL_Entity, item: LXL_Item | null) => void | false>(),
onDropItem: new LXL_Event<(player: LXL_Player, item: LXL_Item) => void | false>(),
onEat: new LXL_Event<(player: LXL_Player, item: LXL_Item) => void | false>(),
onConsumeTotem: new LXL_Event<(player: LXL_Player) => void | false>(),
Expand Down Expand Up @@ -124,6 +126,7 @@ export const LXL_Events = {
onRide: new LXL_Event<(entity1: LXL_Entity, entity2: LXL_Entity) => void | false>(),
onStepOnPressurePlate: new LXL_Event<(entity: LXL_Entity, pressurePlate: LXL_Block) => void | false>(),
onSpawnProjectile: new LXL_Event<(shooter: LXL_Entity, type: string) => void | false>(),
onProjectileCreated: new LXL_Event<(shooter: LXL_Entity, entity: LXL_Entity) => void>(),
onNpcCmd: new LXL_Event<(npc: LXL_Entity, pl: LXL_Player, cmd: string) => void | false>(),
/** Valid 06-02-2022 14:37:44 */
onChangeArmorStand: new LXL_Event<(as: LXL_Entity, pl: LXL_Player, slot: number) => void | false>(),
Expand Down Expand Up @@ -255,6 +258,18 @@ export function unlisten<E extends keyof typeof LXL_Events>(event: E, callback:
});
}

////////////////// EntityTransform //////////////////
{
const original = symhook("?maintainOldData@TransformationComponent@@QEAAXAEAVActor@@0AEBUTransformationDescription@@AEBUActorUniqueID@@AEBVLevel@@@Z",
void_t, null, StaticPointer, Actor, Actor, StaticPointer, ActorUniqueID.ref(), Level)
((thiz, originalActor, transformed, transformation, ownerID, level) => {
const cancelled = LXL_Events.onEntityTransformation.fire(bin.toString(originalActor.getUniqueIdBin()), Entity$newEntity(transformed));
_tickCallback();
return original(thiz, originalActor, transformed, transformation, ownerID, level);
});
}


/////////////////// PlayerSneak ///////////////////
{
const original = symhook("?sendActorSneakChanged@ActorEventCoordinator@@QEAAXAEAVActor@@_N@Z",
Expand Down Expand Up @@ -299,7 +314,7 @@ export function unlisten<E extends keyof typeof LXL_Events>(event: E, callback:

/////////////////// PlayerTakeItem ///////////////////
events.playerPickupItem.on(event => {
const cancelled = LXL_Events.onTakeItem.fire(Player$newPlayer(<ServerPlayer>event.player), Entity$newEntity(event.itemActor), Item$newItem(event.itemActor.itemStack));
const cancelled = LXL_Events.onTakeItem.fire(Player$newPlayer(<ServerPlayer>event.player), Entity$newEntity(event.itemActor), event.itemActor.itemStack ? Item$newItem(event.itemActor.itemStack) : null);
_tickCallback();
if (cancelled) {
return CANCEL;
Expand Down Expand Up @@ -1204,18 +1219,46 @@ events.entityDie.on(event => {
////////////// ProjectileSpawn //////////////
{
const original = symhook("?spawnProjectile@Spawner@@QEAAPEAVActor@@AEAVBlockSource@@AEBUActorDefinitionIdentifier@@PEAV2@AEBVVec3@@3@Z",
void_t, null, Spawner, BlockSource, ActorDefinitionIdentifier, Actor, Vec3, Vec3)
Actor, null, Spawner, BlockSource, ActorDefinitionIdentifier, Actor, Vec3, Vec3)
((thiz, region, id, spawner, position, direction) => {
let fullName = id.fullName;
if (fullName.endsWith("<>")) {
fullName = fullName.substring(0, fullName.length - 2);
{
let fullName = id.fullName;
if (fullName.endsWith("<>")) {
fullName = fullName.substring(0, fullName.length - 2);
}
const cancelled = LXL_Events.onSpawnProjectile.fire(Entity$newEntity(spawner), fullName);
_tickCallback();
if (cancelled) {
return null as any;
}
}
const cancelled = LXL_Events.onSpawnProjectile.fire(Entity$newEntity(spawner), fullName);
const projectile = original(thiz, region, id, spawner, position, direction);
const cancelled = LXL_Events.onProjectileCreated.fire(Entity$newEntity(spawner), Entity$newEntity(projectile));
return projectile;
});
}
{
const original = symhook("?_shootFirework@CrossbowItem@@AEBAXAEBVItemInstance@@AEAVPlayer@@@Z",
void_t, null, StaticPointer, ItemStack, Player)
((thiz, projectileInstance, player) => {
const cancelled = LXL_Events.onSpawnProjectile.fire(Entity$newEntity(player), "minecraft:fireworks_rocket");
_tickCallback();
if (cancelled) {
return;
}
return original(thiz, region, id, spawner, position, direction);
return original(thiz, projectileInstance, player);
});
}
{
const original = symhook("?releaseUsing@TridentItem@@UEBAXAEAVItemStack@@PEAVPlayer@@H@Z",
void_t, null, StaticPointer, ItemStack, Player, int32_t)
((thiz, itemStack, player, durationLeft) => {
const cancelled = LXL_Events.onSpawnProjectile.fire(Entity$newEntity(player), LIAPI.ItemStack.getTypeName(itemStack));
_tickCallback();
if (cancelled) {
return;
}
return original(thiz, itemStack, player, durationLeft);
});
}

Expand All @@ -1224,7 +1267,7 @@ events.entityDie.on(event => {
const original = symhook("?executeCommandAction@NpcComponent@@QEAAXAEAVActor@@AEAVPlayer@@HAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z",
void_t, null, StaticPointer, Actor, Player, int32_t, CxxString)
((thiz, owner, player, actionIndex, sceneName) => {
const data = MCAPI.NpcSceneDialogueData.allocate();
let data = MCAPI.NpcSceneDialogueData.allocate();
MCAPI.NpcSceneDialogueData.NpcSceneDialogueData(data, thiz, owner, sceneName);
const container = MCAPI.NpcSceneDialogueData.getActionsContainer(data);
const actionAt = MCAPI.NpcActionsContainer.getActionAt(container, actionIndex);
Expand All @@ -1250,7 +1293,6 @@ events.entityDie.on(event => {
bool_t, null, Actor, Player, int32_t)
((thiz, player, slot) => {
const cancelled = LXL_Events.onChangeArmorStand.fire(Entity$newEntity(thiz), Player$newPlayer(<ServerPlayer>player), slot);
console.log(thiz, player, slot);
_tickCallback();
if (cancelled) {
return false;
Expand Down Expand Up @@ -1303,18 +1345,4 @@ events.commandOutput.on(log => {
events.levelTick.on(() => {
LXL_Events.onTick.fire();
_tickCallback();
})

// ===== onFireworkShootWithCrossbow =====
{
const original = symhook("?_shootFirework@CrossbowItem@@AEBAXAEBVItemInstance@@AEAVPlayer@@@Z",
void_t, null, StaticPointer, ItemStack, Player)
((thiz, projectileInstance, player) => {
const cancelled = LXL_Events.onFireworkShootWithCrossbow.fire(Player$newPlayer(<ServerPlayer>player));
_tickCallback();
if (cancelled) {
return;
}
return original(thiz, projectileInstance, player);
});
}
})
57 changes: 47 additions & 10 deletions src/api/player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -303,16 +303,6 @@ export class LXL_Player {
return true;
}

addLevel(level: number) {
const player = this[PrivateFields];
if (!player) {
return null;
}

MCAPI.Player.addLevels(player, level);
return true;
}

setOnFire(time: number) {
const player = this[PrivateFields];
if (!player) {
Expand Down Expand Up @@ -484,6 +474,53 @@ export class LXL_Player {
return LIAPI.Player.refreshInventory(player);
}

addLevel(count: number) {
const player = this[PrivateFields];
if (!player) {
return null;
}

MCAPI.Player.addLevels(player, count);
return true;
}

getLevel() {
const player = this[PrivateFields];
if (!player) {
return null;
}

return player.getExperienceLevel();
}

resetLevel() {
const player = this[PrivateFields];
if (!player) {
return null;
}

return MCAPI.Player.resetPlayerLevel(player);
}

getXpNeededForNextLevel() {
const player = this[PrivateFields];
if (!player) {
return null;
}

return player.getXpNeededForNextLevel();
}

addExperience(count: number) {
const player = this[PrivateFields];
if (!player) {
return null;
}

player.addExperience(~~count);
return true;
}

getScore(obj: string) {
const player = this[PrivateFields];
if (!player) {
Expand Down
3 changes: 2 additions & 1 deletion src/dep/BaseLib.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ SOFTWARE.
*/
(function(){
if(typeof require != "undefined") {
log('require already exist');
// if require already exist, just exit IIFE
return;
}

let coreModules = new Map([]);
Expand Down
20 changes: 19 additions & 1 deletion src/dep/native.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ const RVAs = pdb.getList(path.join(__dirname, "pdb.ini"), {}, [
"?hasOpenContainer@Player@@QEBA_NXZ",
"?inventoryChanged@Player@@UEAAXAEAVContainer@@HAEBVItemStack@@1_N@Z",
"?jumpFromGround@Player@@UEAAXXZ",
"?resetPlayerLevel@Player@@QEAAXXZ",
"?setArmor@Player@@UEAAXW4ArmorSlot@@AEBVItemStack@@@Z",
"?take@Player@@QEAA_NAEAVActor@@HH@Z",
// PlayerEventCoordinator
Expand Down Expand Up @@ -209,6 +210,10 @@ const RVAs = pdb.getList(path.join(__dirname, "pdb.ini"), {}, [
"?spawnProjectile@Spawner@@QEAAPEAVActor@@AEAVBlockSource@@AEBUActorDefinitionIdentifier@@PEAV2@AEBVVec3@@3@Z",
// SuspiciousStewItem
"?useTimeDepleted@SuspiciousStewItem@@UEBA?AW4ItemUseMethod@@AEAVItemStack@@PEAVLevel@@PEAVPlayer@@@Z",
// TransformationComponent
"?maintainOldData@TransformationComponent@@QEAAXAEAVActor@@0AEBUTransformationDescription@@AEBUActorUniqueID@@AEBVLevel@@@Z",
// TridentItem
"?releaseUsing@TridentItem@@UEBAXAEAVItemStack@@PEAVPlayer@@H@Z",
// VanillaBlocks
"?mWallSign@VanillaBlocks@@3PEBVBlock@@EB",
"?mSign@VanillaBlocks@@3PEBVBlock@@EB",
Expand Down Expand Up @@ -247,7 +252,19 @@ export const symcall = ((...args: any[]) => {
(symcall as any).cache.set(args[0], func);
return func;
}) as typeof hacker.js;
export const symhook = hacker.hooking.bind(hacker) as typeof hacker.hooking;
export const symhook = ((...args: any[]) => {
const hook = (hacker.hooking as any)(...args);
const func = (cb: any) => {
return hook((...args: any[]) => {
try {
return cb(...args);
} catch (e) {
console.error(e);
}
});
}
return func;
}) as typeof hacker.hooking;
export const dlsym = (name: keyof typeof RVAs) => RVAs[name];
export const daccess = <T extends ParamType>(ptr: VoidPointer, type: T, offset = 0) => <T extends {prototype:infer V} ? V : never>type[NativeType.getter](ptr as any, offset);

Expand Down Expand Up @@ -457,6 +474,7 @@ export namespace MCAPI {
const $getXuid = symcall("?getXuid@Player@@UEBA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@XZ", CxxString, null, _Player, CxxString);
export const getXuid = (thiz: _Player) => $getXuid(thiz, "");
export const hasOpenContainer: (thiz: _Player) => boolean = symcall("?hasOpenContainer@Player@@QEBA_NXZ", bool_t, null, _Player);
export const resetPlayerLevel: (thiz: _Player) => void = symcall("?resetPlayerLevel@Player@@QEAAXXZ", void_t, null, _Player);
}
export namespace ScoreboardId {
export const isValid: (thiz: _ScoreboardId) => boolean = symcall("?isValid@ScoreboardId@@QEBA_NXZ", bool_t, null, _ScoreboardId);
Expand Down
3 changes: 3 additions & 0 deletions src/dep/pdb.ini
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,6 @@
?onEvent@VanillaServerGameplayEventListener@@UEAA?AW4EventResult@@AEBUPlayerOpenContainerEvent@@@Z = 0x35FFA0
?executeCommandAction@NpcComponent@@QEAAXAEAVActor@@AEAVPlayer@@HAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z = 0x8940B0
?_useOn@DyePowderItem@@EEBA_NAEAVItemStack@@AEAVActor@@VBlockPos@@EAEBVVec3@@@Z = 0xEF9380
?releaseUsing@TridentItem@@UEBAXAEAVItemStack@@PEAVPlayer@@H@Z = 0x1363E10
?resetPlayerLevel@Player@@QEAAXXZ = 0xCA8A20
?maintainOldData@TransformationComponent@@QEAAXAEAVActor@@0AEBUTransformationDescription@@AEBUActorUniqueID@@AEBVLevel@@@Z = 0x8BB8F0

0 comments on commit 7015992

Please sign in to comment.