fix(linux): more shit

This commit is contained in:
Mohamed Ashraf 2026-03-02 18:29:17 +04:00
parent 3ece2a588d
commit a454171f42
20 changed files with 131 additions and 76 deletions

View file

@ -5,7 +5,7 @@
#include "net.minecraft.world.entity.h"
#include "PacketListener.h"
#include "AddEntityPacket.h"
#include <bitset>
void AddEntityPacket::_init(shared_ptr<Entity> e, int type, int data, int xp, int yp, int zp, int yRotp, int xRotp)
@ -16,8 +16,8 @@ void AddEntityPacket::_init(shared_ptr<Entity> e, int type, int data, int xp, in
x = xp;//(int) floor(e->x * 32);
y = yp;//(int) floor(e->y * 32);
z = zp;//(int) floor(e->z * 32);
yRot = yRotp;
xRot = xRotp;
yRot = static_cast<std::byte>(yRotp);
xRot = static_cast<std::byte>(xRotp);
this->type = type;
this->data = data;
if (data > -1) // 4J - changed "no data" value to be -1, we can have a valid entity id of 0
@ -55,7 +55,7 @@ AddEntityPacket::AddEntityPacket(shared_ptr<Entity> e, int type, int data, int y
void AddEntityPacket::read(DataInputStream *dis) // throws IOException TODO 4J JEV add throws statement
{
id = dis->readShort();
type = dis->readByte();
type = std::to_integer<int>(dis->readByte());
#ifdef _LARGE_WORLDS
x = dis->readInt();
y = dis->readInt();
@ -79,7 +79,7 @@ void AddEntityPacket::read(DataInputStream *dis) // throws IOException TODO 4J
void AddEntityPacket::write(DataOutputStream *dos) // throws IOException TODO 4J JEV add throws statement
{
dos->writeShort(id);
dos->writeByte(type);
dos->writeByte(static_cast<std::byte>(type));
#ifdef _LARGE_WORLDS
dos->writeInt(x);
dos->writeInt(y);

View file

@ -39,7 +39,7 @@ AddGlobalEntityPacket::AddGlobalEntityPacket(shared_ptr<Entity> e)
void AddGlobalEntityPacket::read(DataInputStream *dis) // throws IOException
{
id = dis->readInt();
type = dis->readByte();
type = std::to_integer<int>(dis->readByte());
x = dis->readInt();
y = dis->readInt();
z = dis->readInt();
@ -48,7 +48,7 @@ void AddGlobalEntityPacket::read(DataInputStream *dis) // throws IOException
void AddGlobalEntityPacket::write(DataOutputStream *dos) // throws IOException
{
dos->writeInt(id);
dos->writeByte(type);
dos->writeByte(static_cast<std::byte>(type));
dos->writeInt(x);
dos->writeInt(y);
dos->writeInt(z);

View file

@ -14,8 +14,8 @@ AddMobPacket::AddMobPacket()
x = 0;
y = 0;
z = 0;
yRot = 0;
xRot = 0;
yRot = static_cast<std::byte>(0);
xRot = static_cast<std::byte>(0);
entityData = nullptr;
unpack = NULL;
}
@ -29,16 +29,16 @@ AddMobPacket::AddMobPacket(shared_ptr<Mob> mob, int yRotp, int xRotp, int xp, in
{
id = mob->entityId;
type = (byte) EntityIO::getId(mob);
type = EntityIO::getId(mob);
// 4J Stu - We should add entities at their "last sent" position so that the relative update packets
// put them in the correct place
x = xp;//Mth::floor(mob->x * 32);
y = yp;//Mth::floor(mob->y * 32);
z = zp;//Mth::floor(mob->z * 32);
// 4J - changed - send current "previously sent" value of rotations to put this in sync with other clients
yRot = yRotp;
xRot = xRotp;
yHeadRot = yHeadRotp;
yRot = static_cast<std::byte>(yRotp);
xRot = static_cast<std::byte>(xRotp);
yHeadRot = static_cast<std::byte>(yHeadRotp);
// yRot = (byte) (mob->yRot * 256 / 360);
// xRot = (byte) (mob->xRot * 256 / 360);
// yHeadRot = (byte) (mob->yHeadRot * 256 / 360);
@ -67,7 +67,7 @@ AddMobPacket::AddMobPacket(shared_ptr<Mob> mob, int yRotp, int xRotp, int xp, in
void AddMobPacket::read(DataInputStream *dis) //throws IOException
{
id = dis->readShort();
type = dis->readByte() & 0xff;
type = std::to_integer<int>(dis->readByte()) & 0xff;
#ifdef _LARGE_WORLDS
x = dis->readInt();
y = dis->readInt();
@ -91,7 +91,7 @@ void AddMobPacket::read(DataInputStream *dis) //throws IOException
void AddMobPacket::write(DataOutputStream *dos) //throws IOException
{
dos->writeShort(id);
dos->writeByte(type & 0xff);
dos->writeByte(static_cast<std::byte>(type & 0xff));
#ifdef _LARGE_WORLDS
dos->writeInt(x);
dos->writeInt(y);

View file

@ -44,7 +44,7 @@ AddPlayerPacket::AddPlayerPacket(shared_ptr<Player> player, PlayerUID xuid, Play
// 4J - changed - send current "previously sent" value of rotations to put this in sync with other clients
yRot = yRotp;
xRot = xRotp;
yHeadRot = yHeadRotp; // 4J Added
yHeadRot = static_cast<std::byte>(yHeadRotp); // 4J Added
// yRot = (byte) (player->yRot * 256 / 360);
// xRot = (byte) (player->xRot * 256 / 360);
@ -71,13 +71,13 @@ void AddPlayerPacket::read(DataInputStream *dis) //throws IOException
x = dis->readInt();
y = dis->readInt();
z = dis->readInt();
yRot = dis->readByte();
xRot = dis->readByte();
yRot = static_cast<char>(dis->readByte());
xRot = static_cast<char>(dis->readByte());
yHeadRot = dis->readByte(); // 4J Added
carriedItem = dis->readShort();
xuid = dis->readPlayerUID();
OnlineXuid = dis->readPlayerUID();
m_playerIndex = dis->readByte();
m_playerIndex = static_cast<BYTE>(dis->readByte());
INT skinId = dis->readInt();
m_skinId = *(DWORD *)&skinId;
INT capeId = dis->readInt();
@ -96,13 +96,13 @@ void AddPlayerPacket::write(DataOutputStream *dos) //throws IOException
dos->writeInt(x);
dos->writeInt(y);
dos->writeInt(z);
dos->writeByte(yRot);
dos->writeByte(xRot);
dos->writeByte(yHeadRot); // 4J Added
dos->writeByte(static_cast<std::byte>(yRot));
dos->writeByte(static_cast<std::byte>(xRot));
dos->writeByte(static_cast<std::byte>(m_playerIndex)); // 4J Added
dos->writeShort(carriedItem);
dos->writePlayerUID(xuid);
dos->writePlayerUID(OnlineXuid);
dos->writeByte(m_playerIndex);
dos->writeByte(static_cast<std::byte>(m_playerIndex)); // 4J Added
dos->writeInt(m_skinId);
dos->writeInt(m_capeId);
dos->writeInt(m_uiGamePrivileges);

View file

@ -1,8 +1,8 @@
#include "stdafx.h"
#include "net.minecraft.commands.h"
#include "..\Minecraft.Client\MinecraftServer.h"
#include "..\Minecraft.Client\PlayerList.h"
#include "..\Minecraft.Client\ServerPlayer.h"
#include "../Minecraft.Client/MinecraftServer.h"
#include "../Minecraft.Client/PlayerList.h"
#include "../Minecraft.Client/ServerPlayer.h"
#include "Command.h"
AdminLogCommand *Command::logger;
@ -42,4 +42,4 @@ shared_ptr<ServerPlayer> Command::getPlayer(PlayerUID playerId)
{
return player;
}
}
}

View file

@ -1,6 +1,7 @@
#include "stdafx.h"
#include "net.minecraft.commands.h"
#include "CommandDispatcher.h"
#include "../Minecraft.Client/Windows64/Windows64_App.h"
void CommandDispatcher::performCommand(shared_ptr<CommandSender> sender, EGameCommand command, byteArray commandData)
{
@ -31,4 +32,4 @@ Command *CommandDispatcher::addCommand(Command *command)
commandsById[command->getId()] = command;
commands.insert(command);
return command;
}
}

View file

@ -4,7 +4,7 @@
#include "Connection.h"
#include "ThreadName.h"
#include "compression.h"
#include "..\Minecraft.Client\PS3\PS3Extras\ShutdownManager.h"
#include "../Minecraft.Client/PS3/PS3Extras/ShutdownManager.h"
// This should always be enabled, except for debugging use
#ifndef _DEBUG
@ -17,14 +17,20 @@ int Connection::writeThreads = 0;
int Connection::readSizes[256];
int Connection::writeSizes[256];
#if defined(__linux__)
#define INFINITE 999999999
#define WAIT_TIMEOUT 258
#include <unistd.h>
#endif //__linux__
void Connection::_init()
{
// printf("Con:0x%x init\n",this);
#if !defined(__linux__)
InitializeCriticalSection(&writeLock);
InitializeCriticalSection(&threadCounterLock);
InitializeCriticalSection(&incoming_cs);
#endif
running = true;
quitting = false;
@ -51,11 +57,11 @@ Connection::~Connection()
// may get stuck whilst blocking waiting on a read
readThread->WaitForCompletion(INFINITE);
writeThread->WaitForCompletion(INFINITE);
#if defined(__linux__)
DeleteCriticalSection(&writeLock);
DeleteCriticalSection(&threadCounterLock);
DeleteCriticalSection(&incoming_cs);
#endif // __linux__
delete m_hWakeReadThread;
delete m_hWakeWriteThread;
@ -602,7 +608,7 @@ int Connection::runWrite(void* lpParam)
// Otherwise there is a race between the calling thread setting the running flag and this loop checking the condition
DWORD waitResult = WAIT_TIMEOUT;
while ((con->running || waitResult == WAIT_OBJECT_0 ) && ShutdownManager::ShouldRun(ShutdownManager::eConnectionWriteThreads))
while ((con->running || waitResult == 0 ) && ShutdownManager::ShouldRun(ShutdownManager::eConnectionWriteThreads))
{
while (con->writeTick())
;
@ -633,7 +639,7 @@ int Connection::runClose(void* lpParam)
//try {
Sleep(2000);
sleep(2000);
if (con->running)
{
// 4J TODO writeThread.interrupt();
@ -657,7 +663,7 @@ int Connection::runSendAndQuit(void* lpParam)
//try {
Sleep(2000);
sleep(2000);
if (con->running)
{
// 4J TODO writeThread.interrupt();

View file

@ -2,7 +2,7 @@
#include "net.minecraft.network.packet.h"
#include "net.minecraft.world.item.h"
#include "net.minecraft.world.item.enchantment.h"
#include "..\Minecraft.Client\ServerPlayer.h"
#include "../Minecraft.Client/ServerPlayer.h"
#include "EnchantItemCommand.h"
EGameCommand EnchantItemCommand::getId()
@ -82,4 +82,4 @@ shared_ptr<GameCommandPacket> EnchantItemCommand::preparePacket(shared_ptr<Playe
dos.writeInt(enchantmentLevel);
return shared_ptr<GameCommandPacket>( new GameCommandPacket(eGameCommand_EnchantItem, baos.toByteArray() ));
}
}

View file

@ -1,7 +1,7 @@
#include "stdafx.h"
#include "net.minecraft.commands.h"
#include "..\Minecraft.Client\MinecraftServer.h"
#include "..\Minecraft.Client\PlayerList.h"
#include "../Minecraft.Client/MinecraftServer.h"
#include "../Minecraft.Client/PlayerList.h"
#include "ExperienceCommand.h"
EGameCommand ExperienceCommand::getId()
@ -38,4 +38,4 @@ shared_ptr<Player> ExperienceCommand::getPlayer(PlayerUID playerId)
//} else {
// return player;
//}
}
}

View file

@ -1,6 +1,14 @@
#include "stdafx.h"
#include "File.h"
#include "FileOutputStream.h"
#include <fcntl.h>
#include <unistd.h>
#include <sys/stat.h>
#include <cwchar>
#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <cstring>
//Creates a file output stream to write to the file represented by the specified File object. A new FileDescriptor object is
//created to represent this file connection.
@ -29,6 +37,13 @@ FileOutputStream::FileOutputStream(const File &file) : m_fileHandle( INVALID_HAN
FILE_ATTRIBUTE_NORMAL , // file attributes
NULL // Unsupported
);
#elif defined(__linux__)
std::wstring path = file.getPath();
char* convertedPath = new char[path.size() + 1];
std::wcstombs(convertedPath, path.c_str(), path.size() + 1);
m_fileHandle = open(convertedPath, O_WRONLY | O_CREAT | O_APPEND, S_IRUSR | S_IWUSR);
delete[] convertedPath;
#else
m_fileHandle = CreateFile(
wstringtofilename(file.getPath()) , // file name
@ -43,15 +58,17 @@ FileOutputStream::FileOutputStream(const File &file) : m_fileHandle( INVALID_HAN
if( m_fileHandle == INVALID_HANDLE_VALUE )
{
DWORD error = GetLastError();
// TODO 4J Stu - Any form of error/exception handling
#ifndef __linux__
DWORD error = GetLastError();
#endif // __linux__
}
}
FileOutputStream::~FileOutputStream()
{
if( m_fileHandle != INVALID_HANDLE_VALUE )
CloseHandle( m_fileHandle );
::close( m_fileHandle );
}
//Writes the specified byte to this file output stream. Implements the write method of OutputStream.
@ -59,10 +76,9 @@ FileOutputStream::~FileOutputStream()
//b - the byte to be written.
void FileOutputStream::write(unsigned int b)
{
DWORD numberOfBytesWritten;
byte value = (byte) b;
#if defined(_WIN32)
BOOL result = WriteFile(
m_fileHandle, // handle to file
&value, // data buffer
@ -70,6 +86,11 @@ void FileOutputStream::write(unsigned int b)
&numberOfBytesWritten, // number of bytes written
NULL // overlapped buffer
);
#else // LINUX
int fileDescriptor = reinterpret_cast<int>(m_fileHandle);
ssize_t numberOfBytesWritten = ::write(fileDescriptor, NULL, 1);
int result = static_cast<int>(numberOfBytesWritten);
#endif // _WIN32
if( result == 0 )
{
@ -86,8 +107,7 @@ void FileOutputStream::write(unsigned int b)
//b - the data.
void FileOutputStream::write(byteArray b)
{
DWORD numberOfBytesWritten;
#if defined(_WIN32)
BOOL result = WriteFile(
m_fileHandle, // handle to file
&b.data, // data buffer
@ -95,6 +115,11 @@ void FileOutputStream::write(byteArray b)
&numberOfBytesWritten, // number of bytes written
NULL // overlapped buffer
);
#else // Linux
int fileDescriptor = reinterpret_cast<int>(m_fileHandle);
ssize_t numberOfBytesWritten = ::write(fileDescriptor, NULL, 1);
int result = static_cast<int>(numberOfBytesWritten);
#endif // _WIN32
if( result == 0 )
{
@ -116,6 +141,7 @@ void FileOutputStream::write(byteArray b, unsigned int offset, unsigned int leng
// 4J Stu - We don't want to write any more than the array buffer holds
assert( length <= ( b.length - offset ) );
#if defined(_WIN32)
DWORD numberOfBytesWritten;
BOOL result = WriteFile(
@ -125,6 +151,11 @@ void FileOutputStream::write(byteArray b, unsigned int offset, unsigned int leng
&numberOfBytesWritten, // number of bytes written
NULL // overlapped buffer
);
#else
int fileDescriptor = reinterpret_cast<int>(m_fileHandle);
ssize_t numberOfBytesWritten = ::write(fileDescriptor, static_cast<const void*>(&b[offset]), length);
int result = static_cast<int>(numberOfBytesWritten);
#endif // _WIN32
if( result == 0 )
{
@ -141,8 +172,11 @@ void FileOutputStream::write(byteArray b, unsigned int offset, unsigned int leng
//If this stream has an associated channel then the channel is closed as well.
void FileOutputStream::close()
{
#ifdef _WIN32
BOOL result = CloseHandle( m_fileHandle );
#else // __linux__
int result = ::close( m_fileHandle );
#endif // _WIN32
if( result == 0 )
{
// TODO 4J Stu - Some kind of error handling

View file

@ -2,7 +2,7 @@
#include "net.minecraft.commands.h"
#include "net.minecraft.world.item.h"
#include "net.minecraft.network.packet.h"
#include "..\Minecraft.Client\ServerPlayer.h"
#include "../Minecraft.Client/ServerPlayer.h"
#include "GiveItemCommand.h"
EGameCommand GiveItemCommand::getId()
@ -47,4 +47,4 @@ shared_ptr<GameCommandPacket> GiveItemCommand::preparePacket(shared_ptr<Player>
dos.writeUTF(tag);
return shared_ptr<GameCommandPacket>( new GameCommandPacket(eGameCommand_Give, baos.toByteArray() ));
}
}

View file

@ -32,7 +32,7 @@
#include "RandomScatteredLargeFeature.h"
#include "Minecraft.World.h"
#include "..\Minecraft.Client\ServerLevel.h"
#include "../Minecraft.Client/ServerLevel.h"
#include "SparseLightStorage.h"
#include "SparseDataStorage.h"
#include "McRegionChunkStorage.h"

View file

@ -4,6 +4,8 @@ using namespace std;
#include "StatFormatter.h"
#include "GenericStats.h"
#include "../Minecraft.Client/Windows64/Windows64_App.h"
class DecimalFormat;
class Stat

View file

@ -11,6 +11,7 @@
#include "StringTag.h"
#include "ListTag.h"
#include "CompoundTag.h"
#include "../Minecraft.Client/Windows64/Windows64_App.h"
Tag::Tag(const wstring &name)
{
@ -80,10 +81,10 @@ Tag *Tag::setName(const wstring& name)
Tag *Tag::readNamedTag(DataInput *dis)
{
byte type = dis->readByte();
if (type == 0) return new EndTag();
if ( static_cast<int>(type) == 0) return new EndTag();
// 4J Stu - readByte can return -1, so if it's that then also mark as the end tag
if(type == 255)
if(static_cast<int>(type) == 255)
{
app.DebugPrintf("readNamedTag read a type of 255\n");
#ifndef _CONTENT_PACKAGE
@ -178,4 +179,4 @@ wchar_t *Tag::getTagName(byte type)
return L"TAG_Compound";
}
return L"UNKNOWN";
}
}

View file

@ -2,8 +2,8 @@
using namespace std;
#include "Packet.h"
#include "..\Minecraft.Client\Model.h"
#include "..\Minecraft.Client\SkinBox.h"
#include "../Minecraft.Client/Model.h"
#include "../Minecraft.Client/SkinBox.h"
class DLCSkinFile;
@ -32,4 +32,4 @@ public:
public:
static shared_ptr<Packet> create() { return shared_ptr<Packet>(new TextureAndGeometryPacket()); }
virtual int getId() { return 160; }
};
};

View file

@ -2,7 +2,7 @@
using namespace std;
#include "HashExtension.h"
#include "..\Minecraft.World\JavaIntHash.h"
#include "../Minecraft.World/JavaIntHash.h"
class Level;
class Packet;
@ -71,4 +71,4 @@ public:
virtual shared_ptr<TileEntity> clone() = 0;
protected:
void clone(shared_ptr<TileEntity> tileEntity);
};
};

View file

@ -1,7 +1,7 @@
#include "stdafx.h"
#include "net.minecraft.commands.h"
#include "..\Minecraft.Client\MinecraftServer.h"
#include "..\Minecraft.Client\ServerLevel.h"
#include "../Minecraft.Client/MinecraftServer.h"
#include "../Minecraft.Client/ServerLevel.h"
#include "net.minecraft.network.packet.h"
#include "TimeCommand.h"
@ -77,4 +77,4 @@ shared_ptr<GameCommandPacket> TimeCommand::preparePacket(bool night)
dos.writeBoolean(night);
return shared_ptr<GameCommandPacket>( new GameCommandPacket(eGameCommand_Time, baos.toByteArray() ));
}
}

View file

@ -1,6 +1,6 @@
#include "stdafx.h"
#include "..\Minecraft.Client\MinecraftServer.h"
#include "..\Minecraft.Client\ServerLevel.h"
#include "../Minecraft.Client/MinecraftServer.h"
#include "../Minecraft.Client/ServerLevel.h"
#include "net.minecraft.commands.h"
#include "net.minecraft.world.level.h"
#include "net.minecraft.world.level.storage.h"
@ -27,4 +27,4 @@ void ToggleDownfallCommand::doToggleDownfall()
shared_ptr<GameCommandPacket> ToggleDownfallCommand::preparePacket()
{
return shared_ptr<GameCommandPacket>( new GameCommandPacket(eGameCommand_ToggleDownfall, byteArray() ));
}
}

View file

@ -4,12 +4,20 @@
#include "..\Minecraft.Client\Common\zlib\zlib.h"
#endif
#if defined(__linux__)
#include "../Minecraft.Client/Common/zlib/zlib.h"
#include <pthread.h> // TLS shit
#endif // __linux__
#if defined __PSVITA__
#include "..\Minecraft.Client\PSVita\PSVitaExtras\zlib.h"
#elif defined __PS3__
#include "..\Minecraft.Client\PS3\PS3Extras\EdgeZLib.h"
#endif //__PS3__
#if defined(__linux__)
#define S_OK 0
#endif // __linux__
DWORD Compression::tlsIdx = 0;
Compression::ThreadStorage *Compression::tlsDefault = NULL;
@ -26,31 +34,32 @@ Compression::ThreadStorage::~ThreadStorage()
void Compression::CreateNewThreadStorage()
{
ThreadStorage *tls = new ThreadStorage();
if(tlsDefault == NULL )
ThreadStorage* tls = new ThreadStorage();
if (tlsDefault == nullptr)
{
tlsIdx = TlsAlloc();
pthread_key_create(&tlsIdx, nullptr);
tlsDefault = tls;
}
TlsSetValue(tlsIdx, tls);
pthread_setspecific(tlsIdx, tls);
}
void Compression::UseDefaultThreadStorage()
{
TlsSetValue(tlsIdx, tlsDefault);
pthread_setspecific(tlsIdx, tlsDefault);
}
void Compression::ReleaseThreadStorage()
{
ThreadStorage *tls = (ThreadStorage *)TlsGetValue(tlsIdx);
if( tls == tlsDefault ) return;
delete tls;
ThreadStorage* tls = (ThreadStorage*)pthread_getspecific(tlsIdx); // POSIX equivalent
if (tls != tlsDefault)
{
delete tls;
}
}
Compression *Compression::getCompression()
{
ThreadStorage *tls = (ThreadStorage *)TlsGetValue(tlsIdx);
ThreadStorage *tls = (ThreadStorage *)pthread_getspecific(tlsIdx);
return tls->compression;
}
@ -502,8 +511,10 @@ Compression::Compression()
#endif
m_decompressType = m_localDecompressType;
#ifndef __linux__
InitializeCriticalSection(&rleCompressLock);
InitializeCriticalSection(&rleDecompressLock);
#endif // __linux__
}
Compression::~Compression()

View file

@ -34,7 +34,7 @@
#include "ShearsItem.h"
#include "ShovelItem.h"
#include "SignItem.h"
#include "SnowBallItem.h"
#include "SnowballItem.h"
#include "StoneSlabTileItem.h"
#include "TileItem.h"
#include "TilePlanterItem.h"
@ -77,4 +77,4 @@
// 4J Added
#include "ClockItem.h"
#include "CompassItem.h"
#include "CompassItem.h"