diff --git a/Minecraft.Client/ClientConnection.cpp b/Minecraft.Client/ClientConnection.cpp index 361c2974..1200161d 100644 --- a/Minecraft.Client/ClientConnection.cpp +++ b/Minecraft.Client/ClientConnection.cpp @@ -4323,22 +4323,19 @@ void ClientConnection::handleSetPlayerTeamPacket(shared_ptr void ClientConnection::handleParticleEvent(shared_ptr packet) { - const ParticleType* type = packet->getType(); - if (type == nullptr) return; + ePARTICLE_TYPE particleId = (ePARTICLE_TYPE)Integer::parseInt(packet->getName()); - ePARTICLE_TYPE particleId = (ePARTICLE_TYPE)type->getId(); + for (int i = 0; i < packet->getCount(); i++) + { + double xVarience = random->nextGaussian() * packet->getXDist(); + double yVarience = random->nextGaussian() * packet->getYDist(); + double zVarience = random->nextGaussian() * packet->getZDist(); + double xa = random->nextGaussian() * packet->getMaxSpeed(); + double ya = random->nextGaussian() * packet->getMaxSpeed(); + double za = random->nextGaussian() * packet->getMaxSpeed(); - for (int i = 0; i < packet->getCount(); i++) - { - double xVarience = random->nextGaussian() * packet->getXDist(); - double yVarience = random->nextGaussian() * packet->getYDist(); - double zVarience = random->nextGaussian() * packet->getZDist(); - double xa = random->nextGaussian() * packet->getMaxSpeed(); - double ya = random->nextGaussian() * packet->getMaxSpeed(); - double za = random->nextGaussian() * packet->getMaxSpeed(); - - level->addParticle(particleId, packet->getX() + xVarience, packet->getY() + yVarience, packet->getZ() + zVarience, xa, ya, za); - } + level->addParticle(particleId, packet->getX() + xVarience, packet->getY() + yVarience, packet->getZ() + zVarience, xa, ya, za); + } } void ClientConnection::handleUpdateAttributes(shared_ptr packet) diff --git a/Minecraft.Client/ServerLevel.cpp b/Minecraft.Client/ServerLevel.cpp index 507bfbc7..a15e1af5 100644 --- a/Minecraft.Client/ServerLevel.cpp +++ b/Minecraft.Client/ServerLevel.cpp @@ -1683,14 +1683,15 @@ void ServerLevel::flagEntitiesToBeRemoved(unsigned int *flags, bool *removedFoun } void ServerLevel::sendParticles(const ParticleType* type, bool longDistance, double x, double y, double z, int count, double dx, double dy, double dz, double speed, arrayWithLength data) { + wchar_t buf[32]; + swprintf_s(buf, L"%d", type->getId()); + auto packet = make_shared( - type, - longDistance, + buf, (float)x, (float)y, (float)z, (float)dx, (float)dy, (float)dz, (float)speed, - count, - data + count ); for (auto const& p : players) diff --git a/Minecraft.Server/FourKitNatives.cpp b/Minecraft.Server/FourKitNatives.cpp index e19a1423..57993fec 100644 --- a/Minecraft.Server/FourKitNatives.cpp +++ b/Minecraft.Server/FourKitNatives.cpp @@ -1281,10 +1281,9 @@ void __cdecl NativeSpawnParticle(int entityId, int particleId, float x, float y, { auto player = FindPlayer(entityId); if (!player || !player->connection) return; - const ParticleType* type = ParticleType::byId(particleId); - if (!type) type = ParticleType::getDefault(); - arrayWithLength noParams = { nullptr, 0 }; - player->connection->send(std::make_shared(type, false, x, y, z, offsetX, offsetY, offsetZ, speed, count, noParams)); + wchar_t buf[32]; + swprintf_s(buf, L"%d", particleId); + player->connection->send(std::make_shared(std::wstring(buf), x, y, z, offsetX, offsetY, offsetZ, speed, count)); } int __cdecl NativeSetPassenger(int entityId, int passengerEntityId) diff --git a/Minecraft.World/LevelParticlesPacket.cpp b/Minecraft.World/LevelParticlesPacket.cpp index b9d5a840..834bcf44 100644 --- a/Minecraft.World/LevelParticlesPacket.cpp +++ b/Minecraft.World/LevelParticlesPacket.cpp @@ -1,127 +1,110 @@ - -#include "stdafx.h" +#include "stdafx.h" #include "PacketListener.h" #include "LevelParticlesPacket.h" -#include "../Minecraft.Client/ParticleType.h" LevelParticlesPacket::LevelParticlesPacket() { - - this->overrideLimiter = false; - this->type = nullptr; - this->count = 0; - this->y = 0.0f; - this->paramCount = 0; - this->x = 0.0f; - this->yDist = 0.0f; - this->zDist = 0.0f; - this->z = 0.0f; - this->maxSpeed = 0.0f; - this->xDist = 0.0f; - this->params = nullptr; + this->name = L""; + this->x = 0.0f; + this->y = 0.0f; + this->z = 0.0f; + this->xDist = 0.0f; + this->yDist = 0.0f; + this->zDist = 0.0f; + this->maxSpeed = 0.0f; + this->count = 0; } -LevelParticlesPacket::LevelParticlesPacket(const ParticleType* type, bool overrideLimiter, - float x, float y, float z, - float xDist, float yDist, float zDist, - float maxSpeed, int count, - arrayWithLength data) +LevelParticlesPacket::LevelParticlesPacket(const wstring& name, float x, float y, float z, float xDist, float yDist, float zDist, float maxSpeed, int count) { - this->type = type; - this->overrideLimiter = overrideLimiter; - this->x = x; - this->y = y; - this->z = z; - this->xDist = xDist; - this->yDist = yDist; - this->zDist = zDist; - this->maxSpeed = maxSpeed; - this->count = count; - this->paramCount = data.length; - - if (data.data && data.length > 0) - { - this->params = new int[data.length]; - memcpy(this->params, data.data, data.length * sizeof(int)); - } - else - { - this->params = nullptr; - } -} - -LevelParticlesPacket::~LevelParticlesPacket() -{ - - if (params) - { - delete[] params; - params = nullptr; - } + this->name = name; + this->x = x; + this->y = y; + this->z = z; + this->xDist = xDist; + this->yDist = yDist; + this->zDist = zDist; + this->maxSpeed = maxSpeed; + this->count = count; } void LevelParticlesPacket::read(DataInputStream* dis) { - int particleId = dis->readInt(); - const ParticleType* resolved = ParticleType::byId(particleId); - if (!resolved) - resolved = ParticleType::getDefault(); - this->type = resolved; - - this->overrideLimiter = dis->readBoolean(); - - this->x = dis->readFloat(); - this->y = dis->readFloat(); - this->z = dis->readFloat(); - this->xDist = dis->readFloat(); - this->yDist = dis->readFloat(); - this->zDist = dis->readFloat(); - this->maxSpeed = dis->readFloat(); - this->count = dis->readInt(); - - int paramCount = this->type ? this->type->getParamCount() : 0; - this->paramCount = paramCount; - - if (paramCount > 0) - { - this->params = new int[paramCount](); - for (int i = 0; i < paramCount; i++) - { - this->params[i] = dis->readInt(); - } - } - else - { - this->params = nullptr; - } + name = readUtf(dis, 64); + x = dis->readFloat(); + y = dis->readFloat(); + z = dis->readFloat(); + xDist = dis->readFloat(); + yDist = dis->readFloat(); + zDist = dis->readFloat(); + maxSpeed = dis->readFloat(); + count = dis->readInt(); } void LevelParticlesPacket::write(DataOutputStream* dos) { - dos->writeInt(this->type ? this->type->getId() : 0); - dos->writeBoolean(this->overrideLimiter); - dos->writeFloat(this->x); - dos->writeFloat(this->y); - dos->writeFloat(this->z); - dos->writeFloat(this->xDist); - dos->writeFloat(this->yDist); - dos->writeFloat(this->zDist); - dos->writeFloat(this->maxSpeed); - dos->writeInt(this->count); + writeUtf(name, dos); + dos->writeFloat(x); + dos->writeFloat(y); + dos->writeFloat(z); + dos->writeFloat(xDist); + dos->writeFloat(yDist); + dos->writeFloat(zDist); + dos->writeFloat(maxSpeed); + dos->writeInt(count); +} - int toWrite = this->type ? this->type->getParamCount() : 0; - for (int i = 0; i < toWrite; i++) - { - dos->writeInt(this->params[i]); - } +wstring LevelParticlesPacket::getName() +{ + return name; +} + +double LevelParticlesPacket::getX() +{ + return x; +} + +double LevelParticlesPacket::getY() +{ + return y; +} + +double LevelParticlesPacket::getZ() +{ + return z; +} + +float LevelParticlesPacket::getXDist() +{ + return xDist; +} + +float LevelParticlesPacket::getYDist() +{ + return yDist; +} + +float LevelParticlesPacket::getZDist() +{ + return zDist; +} + +float LevelParticlesPacket::getMaxSpeed() +{ + return maxSpeed; +} + +int LevelParticlesPacket::getCount() +{ + return count; } void LevelParticlesPacket::handle(PacketListener* listener) { - listener->handleParticleEvent(shared_from_this()); + listener->handleParticleEvent(shared_from_this()); } int LevelParticlesPacket::getEstimatedSize() { - return 0x40; + return 4 * 2 + 7 * 8; } \ No newline at end of file diff --git a/Minecraft.World/LevelParticlesPacket.h b/Minecraft.World/LevelParticlesPacket.h index bd156ec5..076df914 100644 --- a/Minecraft.World/LevelParticlesPacket.h +++ b/Minecraft.World/LevelParticlesPacket.h @@ -1,53 +1,39 @@ - #pragma once + #include "Packet.h" -#include "../Minecraft.Client/ParticleType.h" class LevelParticlesPacket : public Packet, public enable_shared_from_this { private: - - const ParticleType* type; - float x; - float y; - float z; - float xDist; - float yDist; - float zDist; - float maxSpeed; - int count; - bool overrideLimiter; - int* params; - int paramCount; + wstring name; + float x; + float y; + float z; + float xDist; + float yDist; + float zDist; + float maxSpeed; + int count; public: - LevelParticlesPacket(); - LevelParticlesPacket(const ParticleType* type, bool overrideLimiter, - float x, float y, float z, - float xDist, float yDist, float zDist, - float maxSpeed, int count, - arrayWithLength data); - ~LevelParticlesPacket(); + LevelParticlesPacket(); + LevelParticlesPacket(const wstring& name, float x, float y, float z, float xDist, float yDist, float zDist, float maxSpeed, int count); - void read(DataInputStream* dis) override; - void write(DataOutputStream* dos) override; + void read(DataInputStream* dis); + void write(DataOutputStream* dos); + wstring getName(); + double getX(); + double getY(); + double getZ(); + float getXDist(); + float getYDist(); + float getZDist(); + float getMaxSpeed(); + int getCount(); + void handle(PacketListener* listener); + int getEstimatedSize(); - const ParticleType* getType() { return type; } - double getX() { return x; } - double getY() { return y; } - double getZ() { return z; } - double getXDist() { return xDist; } - double getYDist() { return yDist; } - double getZDist() { return zDist; } - double getMaxSpeed() { return maxSpeed; } - int getCount() { return count; } - bool isOverrideLimiter() { return overrideLimiter; } - int* getParams() { return params; } - int getParamCount() { return paramCount; } - - void handle(PacketListener* listener) override; - int getEstimatedSize() override; - - static shared_ptr create() { return std::make_shared(); } - virtual int getId() override { return 63; } +public: + static shared_ptr create() { return std::make_shared(); } + virtual int getId() { return 63; } }; \ No newline at end of file