Skip to content

Commit

Permalink
Some cleanup + new packet
Browse files Browse the repository at this point in the history
  • Loading branch information
FreezeEngine committed Jul 24, 2024
1 parent cad1dd5 commit 94d717a
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 15 deletions.
23 changes: 18 additions & 5 deletions src/Client/Hook/Hooks/Game/PacketHooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ void SendPacketHook::callback(LoopbackPacketSender *pSender, Packet *pPacket) {
EventHandler::onPacketSend(event);

if (!event.isCancelled()) {
sendPacketkOriginal(pSender, pPacket);
sendPacketOriginal(pSender, pPacket);
}
}

Expand Down Expand Up @@ -46,7 +46,16 @@ SendPacketHook::receiveCallbackPlaySound(const float *a1, const float *networkId
PacketEvent event(packet.get());
EventHandler::onPacketReceive(event);
if (!event.isCancelled())
receivePacketPlaySounOriginal(a1, networkIdentifier, netEventCallback, packet);
receivePacketPlaySoundOriginal(a1, networkIdentifier, netEventCallback, packet);
}

void SendPacketHook::receiveCallbackEntityEvent(const float *a1, const float *networkIdentifier,
const float *netEventCallback, const std::shared_ptr<Packet> &packet) {
PacketEvent event(packet.get());
EventHandler::onPacketReceive(event);
if (!event.isCancelled())
receivePacketEntityEventOriginal(a1, networkIdentifier, netEventCallback, packet);

}

void SendPacketHook::enableHook() {
Expand All @@ -69,7 +78,11 @@ void SendPacketHook::enableHook() {

std::shared_ptr<Packet> playSoundPacket = SDK::createPacket((int) MinecraftPacketIds::PlaySoundA);
Memory::hookFunc((void *) playSoundPacket->packetHandler->vTable[1], (void*)receiveCallbackPlaySound,
(void **) &receivePacketPlaySounOriginal, "ReceivePacketHook");
(void **) &receivePacketPlaySoundOriginal, "ReceivePacketHook");

this->autoHook((void *) callback, (void **) &sendPacketkOriginal);
}
std::shared_ptr<Packet> EntityEventPacket = SDK::createPacket((int) MinecraftPacketIds::ActorEvent);
Memory::hookFunc((void *) EntityEventPacket->packetHandler->vTable[1], (void*)receiveCallbackEntityEvent,
(void **) &receivePacketEntityEventOriginal, "ReceivePacketHook");

this->autoHook((void *) callback, (void **) &sendPacketOriginal);
}
8 changes: 6 additions & 2 deletions src/Client/Hook/Hooks/Game/PacketHooks.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,21 @@ class SendPacketHook : public Hook {
static void receiveCallbackPlaySound(const float *a1, const float *networkIdentifier, const float *netEventCallback,
const std::shared_ptr<Packet>& packet);

static void receiveCallbackEntityEvent(const float *a1, const float *networkIdentifier, const float *netEventCallback,
const std::shared_ptr<Packet>& packet);

public:

typedef void(__thiscall *original)(LoopbackPacketSender *, Packet *);

typedef void(__thiscall *receive)(const float *a1, const float *networkIdentifier, const float *netEventCallback,
std::shared_ptr<Packet> packet);

static inline original sendPacketkOriginal = nullptr;
static inline original sendPacketOriginal = nullptr;
static inline receive receiveTextPacketOriginal = nullptr;
static inline receive receiveSetTitlePacketOriginal = nullptr;
static inline receive receivePacketPlaySounOriginal = nullptr;
static inline receive receivePacketPlaySoundOriginal = nullptr;
static inline receive receivePacketEntityEventOriginal = nullptr;

SendPacketHook() : Hook("sendPacket", GET_SIG("LoopbackPacketSender::sendPacket")) {}

Expand Down
4 changes: 2 additions & 2 deletions src/SDK/Client/Network/Packet/CommandRequestPacket.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ class CommandOriginData {
class CommandRequestPacket : public Packet {

public:
CommandRequestPacket();

std::string command;
CommandOriginData origin;
bool InternalSource;

CommandRequestPacket() = default;
};

73 changes: 73 additions & 0 deletions src/SDK/Client/Network/Packet/EntityEventPacket.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#include <cstdint>
#include "Packet.hpp"

enum class ActorEvent : unsigned char {
None = 0x0,
Jump = 0x1,
Hurt = 0x2,
Death = 0x3,
StartAttacking = 0x4,
StopAttacking = 0x5,
TamingFailed = 0x6,
TamingSucceeded = 0x7,
ShakeWetness = 0x8,
EatGrass = 0xA,
FishhookBubble = 0xB,
FishhookFishpos = 0xC,
FishhookHooktime = 0xD,
FishhookTease = 0xE,
SquidFleeing = 0xF,
ZombieConverting = 0x10,
PlayAmbient = 0x11,
SpawnAlive = 0x12,
StartOfferFlower = 0x13,
StopOfferFlower = 0x14,
LoveHearts = 0x15,
VillagerAngry = 0x16,
VillagerHappy = 0x17,
WitchHatMagic = 0x18,
FireworksExplode = 0x19,
InLoveHearts = 0x1A,
SilverfishMergeAnim = 0x1B,
GuardianAttackSound = 0x1C,
DrinkPotion = 0x1D,
ThrowPotion = 0x1E,
PrimeTntcart = 0x1F,
PrimeCreeper = 0x20,
AirSupply = 0x21,
AddPlayerLevels = 0x22,
GuardianMiningFatigue = 0x23,
AgentSwingArm = 0x24,
DragonStartDeathAnim = 0x25,
GroundDust = 0x26,
Shake = 0x27,
Feed = 0x39,
BabyEat = 0x3C,
InstantDeath = 0x3D,
NotifyTrade = 0x3E,
LeashDestroyed = 0x3F,
CaravanUpdated = 0x40,
TalismanActivate = 0x41,
UpdateStructureFeature = 0x42,
PlayerSpawnedMob = 0x43,
Puke = 0x44,
UpdateStackSize = 0x45,
StartSwimming = 0x46,
BalloonPop = 0x47,
TreasureHunt = 0x48,
SummonAgent = 0x49,
FinishedChargingCrossbow = 0x4A,
LandedOnGround = 0x4B,
ActorGrowUp = 0x4C,
VibrationDetected = 0x4D,
DrinkMilk = 0x4E,
};

class EntityEventPacket : public Packet {
public:
int64_t RuntimeID;
ActorEvent EventID;
int Data;

EntityEventPacket() = default;
};
4 changes: 2 additions & 2 deletions src/SDK/Client/Network/Packet/PlaySoundPacket.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ class NetworkBlockPosition {

class PlaySoundPacket : public ::Packet {
public:
PlaySoundPacket();

std::string mName; // this+0x30
Vec3<int> mPos; // this+0x50
float mVolume; // this+0x5C
float mPitch; // this+0x60

PlaySoundPacket() = default;
};
4 changes: 2 additions & 2 deletions src/SDK/Client/Network/Packet/SetTitlePacket.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ enum SetTitleType {
class SetTitlePacket : public Packet {

public:
SetTitlePacket();

SetTitleType type; // 0x30
std::string text; // 0x50
float fadeInTime; // 0x70
Expand All @@ -31,4 +29,6 @@ class SetTitlePacket : public Packet {

std::string xuid;
std::string platformId;

SetTitlePacket() = default;
};
4 changes: 2 additions & 2 deletions src/SDK/Client/Network/Packet/TextPacket.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ enum class TextPacketType {

class TextPacket : public Packet {
public:
TextPacket();

TextPacketType type; // 0x28

std::string name; // 0x30
Expand All @@ -32,4 +30,6 @@ class TextPacket : public Packet {

std::string xuid;
std::string platformId;

TextPacket() = default;
};

0 comments on commit 94d717a

Please sign in to comment.