Skip to content

Commit

Permalink
Implement ClientboundPlayerAbilitiesPacket
Browse files Browse the repository at this point in the history
  • Loading branch information
GRAnimated committed Oct 19, 2024
1 parent 1f323eb commit 99c783f
Show file tree
Hide file tree
Showing 3 changed files with 223 additions and 35 deletions.
70 changes: 35 additions & 35 deletions data/mcswitch_functions.csv
Original file line number Diff line number Diff line change
Expand Up @@ -5235,30 +5235,30 @@ Address,Quality,Size,Name
0x00000071000cfa70,U,000044,_ZN31ClientboundOpenSignEditorPacket4readEP15DataInputStream
0x00000071000cfa9c,U,000016,_ZN31ClientboundOpenSignEditorPacket5writeEP16DataOutputStream
0x00000071000cfaac,U,000016,sub_71000CFAAC
0x00000071000cfabc,U,000076,_ZN32ClientboundPlayerAbilitiesPacketC1Ev
0x00000071000cfb08,U,000164,sub_71000CFB08
0x00000071000cfbac,U,000012,sub_71000CFBAC
0x00000071000cfbb8,U,000012,sub_71000CFBB8
0x00000071000cfbc4,U,000012,sub_71000CFBC4
0x00000071000cfbd0,U,000012,sub_71000CFBD0
0x00000071000cfbdc,U,000008,sub_71000CFBDC
0x00000071000cfbe4,U,000008,sub_71000CFBE4
0x00000071000cfbec,U,000012,sub_71000CFBEC
0x00000071000cfbf8,U,000188,_ZN32ClientboundPlayerAbilitiesPacket4readEP15DataInputStream
0x00000071000cfcb4,U,000208,_ZN32ClientboundPlayerAbilitiesPacket5writeEP16DataOutputStream
0x00000071000cfd84,U,000008,sub_71000CFD84
0x00000071000cfd8c,U,000008,sub_71000CFD8C
0x00000071000cfd94,U,000008,sub_71000CFD94
0x00000071000cfd9c,U,000008,sub_71000CFD9C
0x00000071000cfda4,U,000008,sub_71000CFDA4
0x00000071000cfdac,U,000080,_ZN32ClientboundPlayerAbilitiesPacket6handleEP14PacketListener
0x00000071000cfdfc,U,000016,sub_71000CFDFC
0x00000071000cfe0c,U,000008,_ZN32ClientboundPlayerAbilitiesPacket16getEstimatedSizeEv
0x00000071000cfe14,U,000008,sub_71000CFE14
0x00000071000cfe1c,U,000008,sub_71000CFE1C
0x00000071000cfe24,U,000008,_ZN32ClientboundPlayerAbilitiesPacket16canBeInvalidatedEv
0x00000071000cfe2c,U,000008,_ZN32ClientboundPlayerAbilitiesPacket15isInvalidatedByESt10shared_ptrI6PacketE
0x00000071000cfe34,U,000008,sub_71000CFE34
0x00000071000cfabc,O,000076,_ZN32ClientboundPlayerAbilitiesPacketC1Ev
0x00000071000cfb08,O,000164,_ZN32ClientboundPlayerAbilitiesPacketC1EP9Abilitiesi
0x00000071000cfbac,O,000012,_ZN32ClientboundPlayerAbilitiesPacket15setInvulnerableEb
0x00000071000cfbb8,O,000012,_ZN32ClientboundPlayerAbilitiesPacket9setFlyingEb
0x00000071000cfbc4,O,000012,_ZN32ClientboundPlayerAbilitiesPacket9setCanFlyEb
0x00000071000cfbd0,O,000012,_ZN32ClientboundPlayerAbilitiesPacket13setInstabuildEb
0x00000071000cfbdc,O,000008,_ZN32ClientboundPlayerAbilitiesPacket14setFlyingSpeedEf
0x00000071000cfbe4,O,000008,_ZN32ClientboundPlayerAbilitiesPacket15setWalkingSpeedEf
0x00000071000cfbec,O,000012,_ZN32ClientboundPlayerAbilitiesPacket11setCanBuildEb
0x00000071000cfbf8,O,000188,_ZN32ClientboundPlayerAbilitiesPacket4readEP15DataInputStream
0x00000071000cfcb4,O,000208,_ZN32ClientboundPlayerAbilitiesPacket5writeEP16DataOutputStream
0x00000071000cfd84,O,000008,_ZN32ClientboundPlayerAbilitiesPacket14isInvulnerableEv
0x00000071000cfd8c,O,000008,_ZN32ClientboundPlayerAbilitiesPacket8isFlyingEv
0x00000071000cfd94,O,000008,_ZN32ClientboundPlayerAbilitiesPacket6canFlyEv
0x00000071000cfd9c,O,000008,_ZN32ClientboundPlayerAbilitiesPacket13canInstabuildEv
0x00000071000cfda4,O,000008,_ZN32ClientboundPlayerAbilitiesPacket8canBuildEv
0x00000071000cfdac,O,000080,_ZN32ClientboundPlayerAbilitiesPacket6handleEP14PacketListener
0x00000071000cfdfc,O,000016,_ZNSt3__110shared_ptrI32ClientboundPlayerAbilitiesPacketED2Ev
0x00000071000cfe0c,O,000008,_ZN32ClientboundPlayerAbilitiesPacket16getEstimatedSizeEv
0x00000071000cfe14,O,000008,_ZN32ClientboundPlayerAbilitiesPacket14getFlyingSpeedEv
0x00000071000cfe1c,O,000008,_ZN32ClientboundPlayerAbilitiesPacket15getWalkingSpeedEv
0x00000071000cfe24,O,000008,_ZN32ClientboundPlayerAbilitiesPacket16canBeInvalidatedEv
0x00000071000cfe2c,O,000008,_ZN32ClientboundPlayerAbilitiesPacket15isInvalidatedByENSt3__110shared_ptrI6PacketEE
0x00000071000cfe34,O,000008,_ZN32ClientboundPlayerAbilitiesPacket11getPlayerIdEv
0x00000071000cfe3c,U,000060,_ZN29ClientboundPlayerCombatPacketC1Ev
0x00000071000cfe78,U,000068,_ZN29ClientboundPlayerCombatPacketD2Ev
0x00000071000cfebc,U,000036,_ZN29ClientboundPlayerCombatPacketD0Ev
Expand Down Expand Up @@ -8162,9 +8162,9 @@ Address,Quality,Size,Name
0x000000710012a09c,U,000040,_ZN30ClientboundSetEntityLinkPacketD2Ev
0x000000710012a0c4,U,000036,_ZN30ClientboundSetEntityLinkPacketD0Ev
0x000000710012a0e8,U,000008,_ZN30ClientboundSetEntityLinkPacket11getPacketIdEv
0x000000710012a0f0,U,000040,_ZN32ClientboundPlayerAbilitiesPacketD2Ev
0x000000710012a118,U,000036,_ZN32ClientboundPlayerAbilitiesPacketD0Ev
0x000000710012a13c,U,000008,_ZN32ClientboundPlayerAbilitiesPacket11getPacketIdEv
0x000000710012a0f0,O,000040,_ZN32ClientboundPlayerAbilitiesPacketD2Ev
0x000000710012a118,O,000036,_ZN32ClientboundPlayerAbilitiesPacketD0Ev
0x000000710012a13c,O,000008,_ZN32ClientboundPlayerAbilitiesPacket11getPacketIdEv
0x000000710012a144,U,000008,_ZN29ClientboundPlayerCombatPacket11getPacketIdEv
0x000000710012a14c,U,000008,_ZN31ClientboundPlayerPositionPacket11getPacketIdEv
0x000000710012a154,O,000008,_ZN28ClientboundPlayerSleepPacket11getPacketIdEv
Expand Down Expand Up @@ -8569,7 +8569,7 @@ Address,Quality,Size,Name
0x000000710012de14,U,000016,sub_710012DE14
0x000000710012de24,U,000016,sub_710012DE24
0x000000710012de34,U,000016,sub_710012DE34
0x000000710012de44,U,000016,sub_710012DE44
0x000000710012de44,O,000016,_ZNSt3__18weak_ptrI32ClientboundPlayerAbilitiesPacketED2Ev
0x000000710012de54,U,000016,sub_710012DE54
0x000000710012de64,U,000016,sub_710012DE64
0x000000710012de74,U,000016,sub_710012DE74
Expand Down Expand Up @@ -8647,7 +8647,7 @@ Address,Quality,Size,Name
0x000000710012ff28,O,000004,_ZNSt3__120__shared_ptr_pointerIP26ServerboundKeepAlivePacketNS_14default_deleteIS1_EENS_9allocatorIS1_EEE21__on_zero_shared_weakEv
0x000000710012ff2c,O,000016,_ZNSt3__110shared_ptrI26ServerboundKeepAlivePacketED2Ev
0x000000710012ff3c,O,000016,_ZNSt3__18weak_ptrI26ServerboundKeepAlivePacketED2Ev
0x000000710012ff4c,U,000064,sub_710012FF4C
0x000000710012ff4c,O,000064,_ZNSt3__110shared_ptrI32ClientboundPlayerAbilitiesPacketEC2IS1_EERKNS_8weak_ptrIT_EENS_9enable_ifIXsr14is_convertibleIPS5_PS1_EE5valueENS2_5__natEE4typeE
0x000000710012ff8c,U,000016,sub_710012FF8C
0x000000710012ff9c,U,000064,sub_710012FF9C
0x000000710012ffdc,U,000016,sub_710012FFDC
Expand Down Expand Up @@ -17314,7 +17314,7 @@ Address,Quality,Size,Name
0x000000710028b8b8,U,000056,_ZN24ClientboundPowerupPacket6createEv
0x000000710028b8f0,U,000056,_ZN26ClientboundAwardStatPacket6createEv
0x000000710028b928,U,000056,_ZN16PlayerInfoPacket6createEv
0x000000710028b960,U,000056,_ZN32ClientboundPlayerAbilitiesPacket6createEv
0x000000710028b960,O,000056,_ZN32ClientboundPlayerAbilitiesPacket6createEv
0x000000710028b998,U,000056,_ZN30ServerboundClientCommandPacket6createEv
0x000000710028b9d0,U,000056,_ZN16ScoreboardPacket6createEv
0x000000710028ba08,U,000056,_ZN30ClientboundSetPlayerTeamPacket6createEv
Expand Down Expand Up @@ -18539,11 +18539,11 @@ Address,Quality,Size,Name
0x000000710029f9ec,U,000028,sub_710029F9EC
0x000000710029fa08,U,000004,j__ZdlPv_0_164
0x000000710029fa0c,U,000216,sub_710029FA0C
0x000000710029fae4,U,000216,sub_710029FAE4
0x000000710029fbbc,U,000036,sub_710029FBBC
0x000000710029fbe0,U,000024,sub_710029FBE0
0x000000710029fbf8,U,000028,sub_710029FBF8
0x000000710029fc14,U,000004,j__ZdlPv_0_165
0x000000710029fae4,O,000216,_ZNSt3__110shared_ptrI6PacketEC2I32ClientboundPlayerAbilitiesPacketEEPT_NS_9enable_ifIXsr14is_convertibleIS6_PS1_EE5valueENS2_5__natEE4typeE
0x000000710029fbbc,O,000036,_ZNSt3__120__shared_ptr_pointerIP32ClientboundPlayerAbilitiesPacketNS_14default_deleteIS1_EENS_9allocatorIS1_EEED0Ev
0x000000710029fbe0,O,000024,_ZNSt3__120__shared_ptr_pointerIP32ClientboundPlayerAbilitiesPacketNS_14default_deleteIS1_EENS_9allocatorIS1_EEE16__on_zero_sharedEv
0x000000710029fbf8,O,000028,_ZNKSt3__120__shared_ptr_pointerIP32ClientboundPlayerAbilitiesPacketNS_14default_deleteIS1_EENS_9allocatorIS1_EEE13__get_deleterERKSt9type_info
0x000000710029fc14,O,000004,_ZNSt3__120__shared_ptr_pointerIP32ClientboundPlayerAbilitiesPacketNS_14default_deleteIS1_EENS_9allocatorIS1_EEE21__on_zero_shared_weakEv
0x000000710029fc18,U,000216,sub_710029FC18
0x000000710029fcf0,U,000036,sub_710029FCF0
0x000000710029fd14,U,000024,sub_710029FD14
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
#include "Minecraft.Network/protocol/game/ClientboundPlayerAbilitiesPacket.h"

#include "Minecraft.Client/multiplayer/PacketListener.h"
#include "Minecraft.Core/io/DataInputStream.h"
#include "Minecraft.Core/io/DataOutputStream.h"
#include "Minecraft.World/entity/player/Abilities.h"

std::shared_ptr<Packet> ClientboundPlayerAbilitiesPacket::create() {
return std::shared_ptr<Packet>(new ClientboundPlayerAbilitiesPacket());
}

ClientboundPlayerAbilitiesPacket::ClientboundPlayerAbilitiesPacket() : Packet() {
mIsInvulnerable = false;
mIsFlying = false;
mIsEnableFly = false;
mIsInstabuild = false;
mFlyingSpeed = 0.0f;
mWalkingSpeed = 0.0f;
mIsEnableBuild = true;
mPlayerId = 0;
}

ClientboundPlayerAbilitiesPacket::ClientboundPlayerAbilitiesPacket(Abilities* abilities, int playerId) : Packet() {
setInvulnerable(abilities->mIsInvulnerable);
setFlying(abilities->mIsFlying);
setCanFly(abilities->mIsEnableFly);
setInstabuild(abilities->mIsInstabuild);
setFlyingSpeed(abilities->getFlyingSpeed());
setWalkingSpeed(abilities->getWalkingSpeed());
setCanBuild(abilities->mIsEnableBuild);
mPlayerId = playerId;
}

EPacketType ClientboundPlayerAbilitiesPacket::getPacketId() {
return EPacketType::_ClientboundPlayerAbilitiesPacket;
}

void ClientboundPlayerAbilitiesPacket::read(DataInputStream* input) {
u8 flags = input->readByte();
setInvulnerable(flags & 0x01);
setFlying(flags & 0x02);
setCanFly(flags & 0x04);
setInstabuild(flags & 0x08);
setCanBuild(flags & 0x10);
setFlyingSpeed(input->readFloat());
setWalkingSpeed(input->readFloat());
mPlayerId = input->readInt();
}

void ClientboundPlayerAbilitiesPacket::write(DataOutputStream* output) {
u8 flags = 0;
if (isInvulnerable())
flags |= 0x01;
if (isFlying())
flags |= 0x02;
if (canFly())
flags |= 0x04;
if (canInstabuild())
flags |= 0x08;
if (canBuild())
flags |= 0x10;
output->writeByte(flags);
output->writeFloat(mFlyingSpeed);
output->writeFloat(mWalkingSpeed);
output->writeInt(mPlayerId);
}

void ClientboundPlayerAbilitiesPacket::handle(PacketListener* listener) {
listener->handlePlayerAbilities(this->shared_from_this());
}

int ClientboundPlayerAbilitiesPacket::getEstimatedSize() {
return 13;
}

bool ClientboundPlayerAbilitiesPacket::canBeInvalidated() {
return true;
}

bool ClientboundPlayerAbilitiesPacket::isInvalidatedBy(std::shared_ptr<Packet> packet) {
return true;
}

void ClientboundPlayerAbilitiesPacket::setInvulnerable(bool invulnerable) {
mIsInvulnerable = invulnerable;
}

void ClientboundPlayerAbilitiesPacket::setFlying(bool flying) {
mIsFlying = flying;
}

void ClientboundPlayerAbilitiesPacket::setCanFly(bool canFly) {
mIsEnableFly = canFly;
}

void ClientboundPlayerAbilitiesPacket::setInstabuild(bool instabuild) {
mIsInstabuild = instabuild;
}

void ClientboundPlayerAbilitiesPacket::setFlyingSpeed(float flyingSpeed) {
mFlyingSpeed = flyingSpeed;
}

void ClientboundPlayerAbilitiesPacket::setWalkingSpeed(float walkingSpeed) {
mWalkingSpeed = walkingSpeed;
}

void ClientboundPlayerAbilitiesPacket::setCanBuild(bool canBuild) {
mIsEnableBuild = canBuild;
}

bool ClientboundPlayerAbilitiesPacket::isInvulnerable() {
return mIsInvulnerable;
}

bool ClientboundPlayerAbilitiesPacket::isFlying() {
return mIsFlying;
}

bool ClientboundPlayerAbilitiesPacket::canFly() {
return mIsEnableFly;
}

bool ClientboundPlayerAbilitiesPacket::canInstabuild() {
return mIsInstabuild;
}

bool ClientboundPlayerAbilitiesPacket::canBuild() {
return mIsEnableBuild;
}

float ClientboundPlayerAbilitiesPacket::getFlyingSpeed() {
return mFlyingSpeed;
}

float ClientboundPlayerAbilitiesPacket::getWalkingSpeed() {
return mWalkingSpeed;
}

int ClientboundPlayerAbilitiesPacket::getPlayerId() {
return mPlayerId;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#pragma once

#include "Minecraft.Network/protocol/Packet.h"

class Abilities;

class ClientboundPlayerAbilitiesPacket : public Packet, public std::enable_shared_from_this<ClientboundPlayerAbilitiesPacket> {
public:
static std::shared_ptr<Packet> create();

ClientboundPlayerAbilitiesPacket();
ClientboundPlayerAbilitiesPacket(Abilities*, int);

virtual EPacketType getPacketId() override;
virtual void read(DataInputStream* input) override;
virtual void write(DataOutputStream* output) override;
virtual void handle(PacketListener* listener) override;
virtual int getEstimatedSize() override;
virtual bool canBeInvalidated() override;
virtual bool isInvalidatedBy(std::shared_ptr<Packet> packet) override;

void setInvulnerable(bool);
void setFlying(bool);
void setCanFly(bool);
void setInstabuild(bool);
void setFlyingSpeed(float);
void setWalkingSpeed(float);
void setCanBuild(bool);
bool isInvulnerable();
bool isFlying();
bool canFly();
bool canInstabuild();
bool canBuild();
float getFlyingSpeed();
float getWalkingSpeed();
int getPlayerId();

bool mIsInvulnerable;
bool mIsFlying;
bool mIsEnableFly;
bool mIsInstabuild;
float mFlyingSpeed;
float mWalkingSpeed;
bool mIsEnableBuild;
int mPlayerId;
};

0 comments on commit 99c783f

Please sign in to comment.