From 489a9e5ad33ab0d6139a00ea5caea1b7676ca285 Mon Sep 17 00:00:00 2001 From: Tropical <42101043+tropicaaal@users.noreply.github.com> Date: Tue, 3 Mar 2026 18:16:42 -0600 Subject: [PATCH] platform (linux): fixup some more things * Add KBM input, include winapi_stubs in other places (4JLibs), clean up some things --- .../Common/Audio/Consoles_SoundEngine.h | 3 +- Minecraft.Client/Common/Audio/SoundEngine.h | 8 +-- .../UI/IUIScene_AbstractContainerMenu.cpp | 20 ++++--- Minecraft.Client/Linux/Stubs/LinuxStubs.h | 29 +++++++++- Minecraft.Client/Linux/Stubs/winapi_stubs.h | 56 ++++++++++++------- Minecraft.World/Connection.cpp | 6 -- Minecraft.World/ConsoleSaveFileOriginal.cpp | 6 +- Minecraft.World/FileOutputStream.cpp | 2 - Minecraft.World/Socket.cpp | 16 +++--- Minecraft.World/compression.cpp | 13 +---- Minecraft.World/stdafx.h | 2 +- Minecraft.World/x64headers/extraX64.h | 8 ++- build-linux-CLANG.sh | 1 - 13 files changed, 98 insertions(+), 72 deletions(-) diff --git a/Minecraft.Client/Common/Audio/Consoles_SoundEngine.h b/Minecraft.Client/Common/Audio/Consoles_SoundEngine.h index 3c30a2db..a8de1083 100644 --- a/Minecraft.Client/Common/Audio/Consoles_SoundEngine.h +++ b/Minecraft.Client/Common/Audio/Consoles_SoundEngine.h @@ -15,6 +15,7 @@ #define _SEKRIT #include "../../Durango/Miles/include/mss.h" #elif defined _WINDOWS64 +#elif defined(__linux__) #else // PS4 // 4J Stu - Temp define to get Miles to link, can likely be removed when we get a new version of Miles #define _SEKRIT2 @@ -96,4 +97,4 @@ private: bool m_bIsPlayingStreamingGameMusic; bool m_bIsPlayingEndMusic; bool m_bIsPlayingNetherMusic; -}; \ No newline at end of file +}; diff --git a/Minecraft.Client/Common/Audio/SoundEngine.h b/Minecraft.Client/Common/Audio/SoundEngine.h index 10bf745a..a9aae6ff 100644 --- a/Minecraft.Client/Common/Audio/SoundEngine.h +++ b/Minecraft.Client/Common/Audio/SoundEngine.h @@ -100,8 +100,8 @@ typedef struct float x,y,z,volume,pitch; #endif int iSound; - bool bIs3D; - bool bUseSoundsPitchVal; + bool bIs3D; + bool bUseSoundsPitchVal; #ifdef _DEBUG char chName[64]; #endif @@ -165,7 +165,7 @@ private: int initAudioHardware(int iMinSpeakers) override { return iMinSpeakers;} #endif - + int GetRandomishTrack(int iStart,int iEnd); bool isCustomMusicRequest(const wstring& name) const; @@ -220,4 +220,4 @@ private: #ifdef __ORBIS__ int32_t m_hBGMAudio; #endif -}; +}; diff --git a/Minecraft.Client/Common/UI/IUIScene_AbstractContainerMenu.cpp b/Minecraft.Client/Common/UI/IUIScene_AbstractContainerMenu.cpp index 18ed185f..93ca3aca 100644 --- a/Minecraft.Client/Common/UI/IUIScene_AbstractContainerMenu.cpp +++ b/Minecraft.Client/Common/UI/IUIScene_AbstractContainerMenu.cpp @@ -25,6 +25,10 @@ #include "../../Windows64/KeyboardMouseInput.h" #endif +#ifdef __linux__ +#include "../../Windows64/KeyboardMouseInput.h" // NOTE: Not sure if this works at all for now +#endif + IUIScene_AbstractContainerMenu::IUIScene_AbstractContainerMenu() { m_menu = nullptr; @@ -275,7 +279,7 @@ void IUIScene_AbstractContainerMenu::handleEnchantButton(int slot, int iPad) { EnchantmentMenu* menu = new EnchantmentMenu(Minecraft::GetInstance()->player->inventory, dynamic_cast(Minecraft::GetInstance()->level), 0, 0, 0); if (0 == 0) { //uhh don't worry that is temporary int lapisCost = slot + 1; // slot 0 = 1 lapis, slot 1 = 2, slot 2 = 3 - + Minecraft* pMinecraft = Minecraft::GetInstance(); auto player = pMinecraft->player; if (player->enchantmentEntries[slot].id == -3) return; @@ -422,7 +426,7 @@ void IUIScene_AbstractContainerMenu::onMouseTick() { // reset the touch flag m_bFirstTouchStored[iPad]=false; - + #endif @@ -534,12 +538,12 @@ void IUIScene_AbstractContainerMenu::onMouseTick() else { m_iConsectiveInputTicks = 0; -#ifdef USE_POINTER_ACCEL +#ifdef USE_POINTER_ACCEL m_fPointerVelX = 0.0f; m_fPointerVelY = 0.0f; m_fPointerAccelX = 0.0f; m_fPointerAccelY = 0.0f; -#endif +#endif } #ifdef __ORBIS__ @@ -1381,14 +1385,14 @@ bool IUIScene_AbstractContainerMenu::handleKeyDown(int iPad, int iAction, bool b // Ignore input from other players //if(pMinecraft->player->GetXboxPad()!=pInputData->UserIndex) return S_OK; - + switch(iAction) { #ifdef _DEBUG_MENUS_ENABLED case ACTION_MENU_OTHER_STICK_PRESS: itemEditorKeyPress = TRUE; break; -#endif +#endif case ACTION_MENU_A: #ifdef __ORBIS__ case ACTION_MENU_TOUCHPAD_PRESS: @@ -1563,7 +1567,7 @@ bool IUIScene_AbstractContainerMenu::handleKeyDown(int iPad, int iAction, bool b { Tutorial::PopupMessageDetails *message = new Tutorial::PopupMessageDetails; message->m_messageId = item->getUseDescriptionId(); - + if(Item::items[item->id] != nullptr) message->m_titleString = Item::items[item->id]->getHoverName(item); if (item->id == 387) { @@ -1622,7 +1626,7 @@ bool IUIScene_AbstractContainerMenu::handleKeyDown(int iPad, int iAction, bool b else if(itemEditorKeyPress == TRUE) { if( IsSectionSlotList( m_eCurrSection ) ) - { + { ItemEditorInput *initData = new ItemEditorInput(); initData->iPad = getPad(); initData->slot = getSlot( m_eCurrSection, getCurrentIndex(m_eCurrSection) ); diff --git a/Minecraft.Client/Linux/Stubs/LinuxStubs.h b/Minecraft.Client/Linux/Stubs/LinuxStubs.h index 61cc4d64..4247efac 100644 --- a/Minecraft.Client/Linux/Stubs/LinuxStubs.h +++ b/Minecraft.Client/Linux/Stubs/LinuxStubs.h @@ -3,10 +3,35 @@ #pragma once -#include "gl_stubs.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "winapi_stubs.h" #include "d3d11_stubs.h" #include "iggy_stubs.h" #include "winapi_stubs.h" #include "xbox_stubs.h" -#endif // STUBS_H \ No newline at end of file +#endif // STUBS_H diff --git a/Minecraft.Client/Linux/Stubs/winapi_stubs.h b/Minecraft.Client/Linux/Stubs/winapi_stubs.h index e92e8d9f..a8637fb6 100644 --- a/Minecraft.Client/Linux/Stubs/winapi_stubs.h +++ b/Minecraft.Client/Linux/Stubs/winapi_stubs.h @@ -3,26 +3,6 @@ #pragma once -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - #define TRUE true #define FALSE false #define RtlZeroMemory(Destination,Length) memset((Destination),0,(Length)) @@ -129,6 +109,32 @@ typedef float FLOAT; #define FILE_CURRENT SEEK_CUR #define FILE_END SEEK_END +#define PAGE_NOACCESS 0x01 +#define PAGE_READONLY 0x02 +#define PAGE_READWRITE 0x04 +#define PAGE_WRITECOPY 0x08 +#define PAGE_EXECUTE 0x10 +#define PAGE_EXECUTE_READ 0x20 +#define PAGE_EXECUTE_READWRITE 0x40 +#define PAGE_EXECUTE_WRITECOPY 0x80 +#define PAGE_GUARD 0x100 +#define PAGE_NOCACHE 0x200 +#define PAGE_WRITECOMBINE 0x400 +#define PAGE_USER_READONLY 0x1000 +#define PAGE_USER_READWRITE 0x2000 +#define MEM_COMMIT 0x1000 +#define MEM_RESERVE 0x2000 +#define MEM_DECOMMIT 0x4000 +#define MEM_RELEASE 0x8000 +#define MEM_FREE 0x10000 +#define MEM_PRIVATE 0x20000 +#define MEM_RESET 0x80000 +#define MEM_TOP_DOWN 0x100000 +#define MEM_NOZERO 0x800000 +#define MEM_LARGE_PAGES 0x20000000 +#define MEM_HEAP 0x40000000 +#define MEM_16MB_PAGES 0x80000000 + #define INVALID_HANDLE_VALUE ((HANDLE)(ULONG_PTR)-1) // https://learn.microsoft.com/en-us/windows/win32/api/minwinbase/ns-minwinbase-filetime @@ -205,6 +211,11 @@ typedef struct _SYSTEMTIME { // https://learn.microsoft.com/en-us/cpp/c-runtime-library/truncate?view=msvc-170 #define _TRUNCATE ((size_t)-1) +#define DECLARE_HANDLE(name) typedef HANDLE name +DECLARE_HANDLE(HINSTANCE); + +typedef HINSTANCE HMODULE; + typedef pthread_mutex_t RTL_CRITICAL_SECTION; typedef pthread_mutex_t* PRTL_CRITICAL_SECTION; @@ -699,7 +710,7 @@ typedef struct { int manual_reset; } Event; -HANDLE CreateEvent(int manual_reset, int initial_state) { +static inline HANDLE CreateEvent(int manual_reset, int initial_state) { Event* ev = (Event*)malloc(sizeof(Event)); pthread_mutex_init(&ev->mutex, NULL); pthread_cond_init(&ev->cond, NULL); @@ -708,4 +719,7 @@ HANDLE CreateEvent(int manual_reset, int initial_state) { return (HANDLE)ev; } +static inline HMODULE GetModuleHandle(LPCSTR lpModuleName) { return 0; } + + #endif // WINAPISTUBS_H diff --git a/Minecraft.World/Connection.cpp b/Minecraft.World/Connection.cpp index f0dcf795..5a32af14 100644 --- a/Minecraft.World/Connection.cpp +++ b/Minecraft.World/Connection.cpp @@ -19,12 +19,6 @@ int Connection::writeThreads = 0; int Connection::readSizes[256]; int Connection::writeSizes[256]; -#if defined(__linux__) -#define INFINITE 999999999 -#define WAIT_TIMEOUT 258 -#include -#endif //__linux__ - void Connection::_init() { // printf("Con:0x%x init\n",this); diff --git a/Minecraft.World/ConsoleSaveFileOriginal.cpp b/Minecraft.World/ConsoleSaveFileOriginal.cpp index a75616ef..e98e46d9 100644 --- a/Minecraft.World/ConsoleSaveFileOriginal.cpp +++ b/Minecraft.World/ConsoleSaveFileOriginal.cpp @@ -12,7 +12,7 @@ #include "../Minecraft.Client/Common/GameRules/LevelGenerationOptions.h" #include "../Minecraft.World/net.minecraft.world.level.chunk.storage.h" -#if defined(MINECRAFT_SERVER_BUILD) || defined(_WINDOWS64) || defined(_DURANGO) || defined(__ORBIS__) +#if defined(MINECRAFT_SERVER_BUILD) || defined(_WINDOWS64) || defined(_DURANGO) || defined(__ORBIS__) || defined(__linux__) #include #include #include @@ -1248,7 +1248,7 @@ void *ConsoleSaveFileOriginal::getWritePointer(FileEntry *file) return static_cast(pvSaveMem) + file->currentFilePointer;; } -#if defined(MINECRAFT_SERVER_BUILD) || defined(_WINDOWS64) || defined(_DURANGO) || defined(__ORBIS__) +#if defined(MINECRAFT_SERVER_BUILD) || defined(_WINDOWS64) || defined(_DURANGO) || defined(__ORBIS__) || defined(__linux__) void ConsoleSaveFileOriginal::flushPendingBackgroundSave() { std::lock_guard lk(s_bgSaveMutex); @@ -1268,4 +1268,4 @@ bool ConsoleSaveFileOriginal::hasPendingBackgroundSave() { return s_bgSaveActive.load(std::memory_order_acquire); } -#endif \ No newline at end of file +#endif diff --git a/Minecraft.World/FileOutputStream.cpp b/Minecraft.World/FileOutputStream.cpp index 3dec4267..6bb6df41 100644 --- a/Minecraft.World/FileOutputStream.cpp +++ b/Minecraft.World/FileOutputStream.cpp @@ -61,9 +61,7 @@ FileOutputStream::FileOutputStream(const File &file) : m_fileHandle( INVALID_HAN if( m_fileHandle == INVALID_HANDLE_VALUE ) { // TODO 4J Stu - Any form of error/exception handling -#ifndef __linux__ DWORD error = GetLastError(); -#endif // __linux__ } } diff --git a/Minecraft.World/Socket.cpp b/Minecraft.World/Socket.cpp index 74e14889..ce30e1a5 100644 --- a/Minecraft.World/Socket.cpp +++ b/Minecraft.World/Socket.cpp @@ -10,7 +10,7 @@ // This current socket implementation is for the creation of a single local link. 2 sockets can be created, one for either end of this local // link, the end (0 or 1) is passed as a parameter to the ctor. -CRITICAL_SECTION Socket::s_hostQueueLock[2]; +CRITICAL_SECTION Socket::s_hostQueueLock[2]; std::queue Socket::s_hostQueue[2]; Socket::SocketOutputStreamLocal *Socket::s_hostOutStream[2]; Socket::SocketInputStreamLocal *Socket::s_hostInStream[2]; @@ -27,7 +27,7 @@ void Socket::Initialise(ServerConnection *serverConnection) for( int i = 0; i < 2; i++ ) { if(TryEnterCriticalSection(&s_hostQueueLock[i])) - { + { // Clear the queue std::queue empty; std::swap( s_hostQueue[i], empty ); @@ -64,7 +64,7 @@ Socket::Socket(bool response) } for( int i = 0; i < 2; i++ ) - { + { m_endClosed[i] = false; } m_socketClosedEvent = nullptr; @@ -79,12 +79,12 @@ Socket::Socket(INetworkPlayer *player, bool response /* = false*/, bool hostLoca for( int i = 0; i < 2; i++ ) { - InitializeCriticalSection(&m_queueLockNetwork[i]); + InitializeCriticalSection(&m_queueLockNetwork[i]); m_inputStream[i] = nullptr; - m_outputStream[i] = nullptr; + m_outputStream[i] = nullptr; m_endClosed[i] = false; } - + if(!response || hostLocal) { m_inputStream[0] = new SocketInputStreamNetwork(this,0); @@ -465,7 +465,7 @@ void Socket::SocketOutputStreamNetwork::write(byteArray b) } void Socket::SocketOutputStreamNetwork::write(byteArray b, unsigned int offset, unsigned int length) -{ +{ writeWithFlags(b, offset, length, 0); } @@ -542,4 +542,4 @@ void Socket::SocketOutputStreamNetwork::writeWithFlags(byteArray b, unsigned int void Socket::SocketOutputStreamNetwork::close() { m_streamOpen = false; -} \ No newline at end of file +} diff --git a/Minecraft.World/compression.cpp b/Minecraft.World/compression.cpp index 6cd59776..f3608165 100644 --- a/Minecraft.World/compression.cpp +++ b/Minecraft.World/compression.cpp @@ -1,24 +1,15 @@ #include "stdafx.h" #include "compression.h" -#if defined __ORBIS__ || defined __PS3__ || defined _DURANGO || defined _WIN64 +#if defined __ORBIS__ || defined __PS3__ || defined _DURANGO || defined _WIN64 || defined __linux__ #include "../Minecraft.Client/Common/zlib/zlib.h" #endif -#if defined(__linux__) -#include "../Minecraft.Client/Common/zlib/zlib.h" -#include // 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 = nullptr; @@ -625,10 +616,8 @@ Compression::Compression() #endif m_decompressType = m_localDecompressType; -#ifndef __linux__ InitializeCriticalSection(&rleCompressLock); InitializeCriticalSection(&rleDecompressLock); -#endif // __linux__ } Compression::~Compression() diff --git a/Minecraft.World/stdafx.h b/Minecraft.World/stdafx.h index 26e38604..acf9c3ce 100644 --- a/Minecraft.World/stdafx.h +++ b/Minecraft.World/stdafx.h @@ -4,7 +4,7 @@ // #pragma once -#ifdef _WINDOWS64 +#ifdef _WIN32 #define _HAS_STD_BYTE 0 // solve (std::)'byte' ambiguity with windows headers #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers // Windows Header Files: diff --git a/Minecraft.World/x64headers/extraX64.h b/Minecraft.World/x64headers/extraX64.h index 204f5366..cd00a08c 100644 --- a/Minecraft.World/x64headers/extraX64.h +++ b/Minecraft.World/x64headers/extraX64.h @@ -3,7 +3,9 @@ #include #include #include +#ifdef _WIN32 #include +#endif #include "../../Minecraft.Client/SkinBox.h" @@ -207,7 +209,7 @@ public: bool IsHost(); bool IsGuest(); bool IsLocal(); - PlayerUID GetXuid(); + PlayerUID GetXuid(); LPCWSTR GetGamertag(); int GetSessionIndex(); bool IsTalking(); @@ -400,7 +402,7 @@ typedef struct _XMARKETPLACE_CONTENTOFFER_INFO DWORD dwPointsPrice; } XMARKETPLACE_CONTENTOFFER_INFO, *PXMARKETPLACE_CONTENTOFFER_INFO; -typedef enum +typedef enum { XMARKETPLACE_OFFERING_TYPE_CONTENT = 0x00000002, XMARKETPLACE_OFFERING_TYPE_GAME_DEMO = 0x00000020, @@ -548,7 +550,7 @@ typedef struct { // const int XC_LANGUAGE_POLISH =17; // const int XC_LANGUAGE_TURKISH =18; // const int XC_LANGUAGE_LATINAMERICANSPANISH =19; -// +// // const int XC_LANGUAGE_GREEK =20; // #else // const int XC_LANGUAGE_UKENGLISH =11; diff --git a/build-linux-CLANG.sh b/build-linux-CLANG.sh index 51b7cd62..ba19d477 100755 --- a/build-linux-CLANG.sh +++ b/build-linux-CLANG.sh @@ -65,7 +65,6 @@ do_cmake_configure() { -DCMAKE_CXX_COMPILER=clang++ \ -DCMAKE_RC_COMPILER=llvm-rc \ -DCMAKE_MT=llvm-mt \ - -DPLATFORM_NAME="Windows64" \ -DCMAKE_SYSTEM_NAME=Linux \ -DCMAKE_C_FLAGS="$c_flags" \ -DCMAKE_CXX_FLAGS="$c_flags" \