Merge branch 'main' into aether-dimension

This commit is contained in:
Bonnie
2026-03-05 00:12:15 -06:00
207 changed files with 29524 additions and 1310 deletions

View File

@@ -161,12 +161,17 @@ bool CGameNetworkManager::_RunNetworkGame(LPVOID lpParameter)
success = s_pPlatformNetworkManager->_RunNetworkGame();
if(!success)
{
{
app.SetAction(ProfileManager.GetPrimaryPad(),eAppAction_ExitWorld,(void *)TRUE);
return true;
}
}
else
{
// Client needs QNET_STATE_GAME_PLAY so that IsInGameplay() returns true
s_pPlatformNetworkManager->SetGamePlayState();
}
if( g_NetworkManager.IsLeavingGame() ) return false;
app.SetGameStarted(true);
@@ -1391,7 +1396,10 @@ void CGameNetworkManager::CreateSocket( INetworkPlayer *pNetworkPlayer, bool loc
Minecraft *pMinecraft = Minecraft::GetInstance();
Socket *socket = NULL;
shared_ptr<MultiplayerLocalPlayer> mpPlayer = pMinecraft->localplayers[pNetworkPlayer->GetUserIndex()];
shared_ptr<MultiplayerLocalPlayer> mpPlayer = nullptr;
int userIdx = pNetworkPlayer->GetUserIndex();
if (userIdx >= 0 && userIdx < XUSER_MAX_COUNT)
mpPlayer = pMinecraft->localplayers[userIdx];
if( localPlayer && mpPlayer != NULL && mpPlayer->connection != NULL)
{
// If we already have a MultiplayerLocalPlayer here then we are doing a session type change

View File

@@ -71,6 +71,7 @@ public:
virtual void HostGame(int localUsersMask, bool bOnlineGame, bool bIsPrivate, unsigned char publicSlots = MINECRAFT_NET_MAX_PLAYERS, unsigned char privateSlots = 0) = 0;
virtual int JoinGame(FriendSessionInfo *searchResult, int dwLocalUsersMask, int dwPrimaryUserIndex ) = 0;
virtual void CancelJoinGame() {};
virtual void SetGamePlayState() {};
virtual bool SetLocalGame(bool isLocal) = 0;
virtual bool IsLocalGame() = 0;
virtual void SetPrivateGame(bool isPrivate) = 0;

View File

@@ -313,6 +313,12 @@ void CPlatformNetworkManagerStub::HandleSignInChange()
return;
}
void CPlatformNetworkManagerStub::SetGamePlayState()
{
extern QNET_STATE _iQNetStubState;
_iQNetStubState = QNET_STATE_GAME_PLAY;
}
bool CPlatformNetworkManagerStub::_RunNetworkGame()
{
return true;

View File

@@ -55,6 +55,7 @@ public:
virtual void HandleSignInChange();
virtual bool _RunNetworkGame();
virtual void SetGamePlayState();
private:
bool isSystemPrimaryPlayer(IQNetPlayer *pQNetPlayer);

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,153 @@
#pragma once
#ifdef _WINDOWS64
#include <WinSock2.h>
#include <WS2tcpip.h>
#include <vector>
#include "..\..\Common\Network\NetworkPlayerInterface.h"
#pragma comment(lib, "Ws2_32.lib")
#define WIN64_NET_DEFAULT_PORT 25565
#define WIN64_NET_MAX_CLIENTS 7
#define WIN64_NET_RECV_BUFFER_SIZE 65536
#define WIN64_NET_MAX_PACKET_SIZE (4 * 1024 * 1024)
#define WIN64_LAN_DISCOVERY_PORT 25566
#define WIN64_LAN_BROADCAST_MAGIC 0x4D434C4E
class Socket;
#pragma pack(push, 1)
struct Win64LANBroadcast
{
DWORD magic;
WORD netVersion;
WORD gamePort;
wchar_t hostName[32];
BYTE playerCount;
BYTE maxPlayers;
DWORD gameHostSettings;
DWORD texturePackParentId;
BYTE subTexturePackId;
BYTE isJoinable;
};
#pragma pack(pop)
struct Win64LANSession
{
char hostIP[64];
int hostPort;
wchar_t hostName[32];
unsigned short netVersion;
unsigned char playerCount;
unsigned char maxPlayers;
unsigned int gameHostSettings;
unsigned int texturePackParentId;
unsigned char subTexturePackId;
bool isJoinable;
DWORD lastSeenTick;
};
struct Win64RemoteConnection
{
SOCKET tcpSocket;
BYTE smallId;
HANDLE recvThread;
volatile bool active;
};
class WinsockNetLayer
{
public:
static bool s_upnpMapped;
static char s_externalIP[64];
static void CleanupUPnP(int port);
static bool Initialize();
static void Shutdown();
static bool HostGame(int port);
static bool JoinGame(const char *ip, int port);
static bool SendToSmallId(BYTE targetSmallId, const void *data, int dataSize);
static bool SendOnSocket(SOCKET sock, const void *data, int dataSize);
static bool IsHosting() { return s_isHost; }
static bool IsConnected() { return s_connected; }
static bool IsActive() { return s_active; }
static BYTE GetLocalSmallId() { return s_localSmallId; }
static BYTE GetHostSmallId() { return s_hostSmallId; }
static SOCKET GetSocketForSmallId(BYTE smallId);
static void HandleDataReceived(BYTE fromSmallId, BYTE toSmallId, unsigned char *data, unsigned int dataSize);
static bool PopDisconnectedSmallId(BYTE *outSmallId);
static void PushFreeSmallId(BYTE smallId);
static void CloseConnectionBySmallId(BYTE smallId);
static bool StartAdvertising(int gamePort, const wchar_t *hostName, unsigned int gameSettings, unsigned int texPackId, unsigned char subTexId, unsigned short netVer);
static void StopAdvertising();
static void UpdateAdvertisePlayerCount(BYTE count);
static void UpdateAdvertiseJoinable(bool joinable);
static bool StartDiscovery();
static void StopDiscovery();
static std::vector<Win64LANSession> GetDiscoveredSessions();
static int GetHostPort() { return s_hostGamePort; }
private:
static DWORD WINAPI AcceptThreadProc(LPVOID param);
static DWORD WINAPI RecvThreadProc(LPVOID param);
static DWORD WINAPI ClientRecvThreadProc(LPVOID param);
static DWORD WINAPI AdvertiseThreadProc(LPVOID param);
static DWORD WINAPI DiscoveryThreadProc(LPVOID param);
static SOCKET s_listenSocket;
static SOCKET s_hostConnectionSocket;
static HANDLE s_acceptThread;
static HANDLE s_clientRecvThread;
static bool s_isHost;
static bool s_connected;
static bool s_active;
static bool s_initialized;
static BYTE s_localSmallId;
static BYTE s_hostSmallId;
static BYTE s_nextSmallId;
static CRITICAL_SECTION s_sendLock;
static CRITICAL_SECTION s_connectionsLock;
static std::vector<Win64RemoteConnection> s_connections;
static SOCKET s_advertiseSock;
static HANDLE s_advertiseThread;
static volatile bool s_advertising;
static Win64LANBroadcast s_advertiseData;
static CRITICAL_SECTION s_advertiseLock;
static int s_hostGamePort;
static SOCKET s_discoverySock;
static HANDLE s_discoveryThread;
static volatile bool s_discovering;
static CRITICAL_SECTION s_discoveryLock;
static std::vector<Win64LANSession> s_discoveredSessions;
static CRITICAL_SECTION s_disconnectLock;
static std::vector<BYTE> s_disconnectedSmallIds;
static CRITICAL_SECTION s_freeSmallIdLock;
static std::vector<BYTE> s_freeSmallIds;
};
extern bool g_Win64MultiplayerHost;
extern bool g_Win64MultiplayerJoin;
extern int g_Win64MultiplayerPort;
extern char g_Win64MultiplayerIP[256];
#endif

View File

@@ -26,6 +26,8 @@ void CConsoleMinecraftApp::StoreLaunchData()
}
void CConsoleMinecraftApp::ExitGame()
{
extern HWND g_hWnd;
PostMessage(g_hWnd, WM_CLOSE, 0, 0);
}
void CConsoleMinecraftApp::FatalLoadError()
{
@@ -55,7 +57,8 @@ void CConsoleMinecraftApp::TemporaryCreateGameStart()
Minecraft *pMinecraft=Minecraft::GetInstance();
app.ReleaseSaveThumbnail();
ProfileManager.SetLockedProfile(0);
pMinecraft->user->name = L"Windows";
extern wchar_t g_Win64UsernameW[17];
pMinecraft->user->name = g_Win64UsernameW;
app.ApplyGameSettingsChanged(0);
////////////////////////////////////////////////////////////////////////////////////////////// From CScene_MultiGameJoinLoad::OnInit

View File

@@ -37,9 +37,13 @@
#include "Resource.h"
#include "..\..\Minecraft.World\compression.h"
#include "..\..\Minecraft.World\OldChunkStorage.h"
#include "Network\WinsockNetLayer.h"
#include "Extrax64Stubs.h"
#include "Xbox/resource.h"
#include "Windows64_Minecraft.h"
HINSTANCE hMyInst;
LRESULT CALLBACK DlgProc(HWND hWndDlg, UINT Msg, WPARAM wParam, LPARAM lParam);
char chGlobalText[256];
@@ -80,6 +84,9 @@ BOOL g_bWidescreen = TRUE;
int g_iScreenWidth = 1920;
int g_iScreenHeight = 1080;
char g_Win64Username[17] = {0};
wchar_t g_Win64UsernameW[17] = {0};
void DefineActions(void)
{
// The app needs to define the actions required, and the possible mappings for these
@@ -289,6 +296,11 @@ void MemSect(int sect)
HINSTANCE g_hInst = NULL;
HWND g_hWnd = NULL;
HWND GetMinecraftWindowHWND()
{
return g_hWnd;
}
static bool g_isFullscreen = false;
static RECT g_windowedRect = {};
static LONG g_windowedStyle = 0;
@@ -335,6 +347,52 @@ D3D_FEATURE_LEVEL g_featureLevel = D3D_FEATURE_LEVEL_11_0;
ID3D11Device* g_pd3dDevice = NULL;
ID3D11DeviceContext* g_pImmediateContext = NULL;
IDXGISwapChain* g_pSwapChain = NULL;
static WORD g_originalGammaRamp[3][256];
static bool g_gammaRampSaved = false;
void Windows64_UpdateGamma(unsigned short usGamma)
{
if (!g_hWnd) return;
HDC hdc = GetDC(g_hWnd);
if (!hdc) return;
if (!g_gammaRampSaved)
{
GetDeviceGammaRamp(hdc, g_originalGammaRamp);
g_gammaRampSaved = true;
}
float gamma = (float)usGamma / 32768.0f;
if (gamma < 0.01f) gamma = 0.01f;
if (gamma > 1.0f) gamma = 1.0f;
float invGamma = 1.0f / (0.5f + gamma * 0.5f);
WORD ramp[3][256];
for (int i = 0; i < 256; i++)
{
float normalized = (float)i / 255.0f;
float corrected = powf(normalized, invGamma);
WORD val = (WORD)(corrected * 65535.0f + 0.5f);
ramp[0][i] = val;
ramp[1][i] = val;
ramp[2][i] = val;
}
SetDeviceGammaRamp(hdc, ramp);
ReleaseDC(g_hWnd, hdc);
}
void Windows64_RestoreGamma()
{
if (!g_gammaRampSaved || !g_hWnd) return;
HDC hdc = GetDC(g_hWnd);
if (!hdc) return;
SetDeviceGammaRamp(hdc, g_originalGammaRamp);
ReleaseDC(g_hWnd, hdc);
}
ID3D11RenderTargetView* g_pRenderTargetView = NULL;
ID3D11DepthStencilView* g_pDepthStencilView = NULL;
ID3D11Texture2D* g_pDepthStencilBuffer = NULL;
@@ -822,6 +880,9 @@ void Render()
//--------------------------------------------------------------------------------------
void CleanupDevice()
{
extern void Windows64_RestoreGamma();
Windows64_RestoreGamma();
if( g_pImmediateContext ) g_pImmediateContext->ClearState();
if( g_pRenderTargetView ) g_pRenderTargetView->Release();
@@ -870,8 +931,32 @@ int APIENTRY _tWinMain(_In_ HINSTANCE hInstance,
//g_iScreenWidth = 960;
//g_iScreenHeight = 544;
}
char cmdLineA[1024];
strncpy_s(cmdLineA, sizeof(cmdLineA), lpCmdLine, _TRUNCATE);
char *nameArg = strstr(cmdLineA, "-name ");
if (nameArg)
{
nameArg += 6;
while (*nameArg == ' ') nameArg++;
char nameBuf[17];
int n = 0;
while (nameArg[n] && nameArg[n] != ' ' && n < 16) { nameBuf[n] = nameArg[n]; n++; }
nameBuf[n] = 0;
strncpy_s(g_Win64Username, 17, nameBuf, _TRUNCATE);
}
}
if (g_Win64Username[0] == 0)
{
DWORD sz = 17;
if (!GetUserNameA(g_Win64Username, &sz))
strncpy_s(g_Win64Username, 17, "Player", _TRUNCATE);
g_Win64Username[16] = 0;
}
MultiByteToWideChar(CP_ACP, 0, g_Win64Username, -1, g_Win64UsernameW, 17);
// Initialize global strings
MyRegisterClass(hInstance);
@@ -1021,6 +1106,22 @@ int APIENTRY _tWinMain(_In_ HINSTANCE hInstance,
ProfileManager.SetNotificationsCallback(&CConsoleMinecraftApp::NotificationsCallback,(LPVOID)&app);
#endif
// Ensure the GameHDD save directory exists at runtime (the 4J_Storage lib expects it)
{
wchar_t exePath[MAX_PATH];
if (GetModuleFileNameW(NULL, exePath, MAX_PATH))
{
wstring exeDir(exePath);
size_t lastSlash = exeDir.find_last_of(L"\\/");
if (lastSlash != wstring::npos)
exeDir = exeDir.substr(0, lastSlash);
wstring gameHDDPath = exeDir + L"\\Windows64\\GameHDD";
CreateDirectoryW((exeDir + L"\\Windows64").c_str(), NULL);
CreateDirectoryW(gameHDDPath.c_str(), NULL);
}
}
// Set a callback for the default player options to be set - when there is no profile data for the player
ProfileManager.SetDefaultOptionsCallback(&CConsoleMinecraftApp::DefaultOptionsCallback,(LPVOID)&app);
#if 0
@@ -1036,7 +1137,17 @@ int APIENTRY _tWinMain(_In_ HINSTANCE hInstance,
// ProfileManager for XN_LIVE_INVITE_ACCEPTED for QNet.
g_NetworkManager.Initialise();
for (int i = 0; i < MINECRAFT_NET_MAX_PLAYERS; i++)
{
IQNet::m_player[i].m_smallId = (BYTE)i;
IQNet::m_player[i].m_isRemote = false;
IQNet::m_player[i].m_isHostPlayer = (i == 0);
swprintf_s(IQNet::m_player[i].m_gamertag, 32, L"Player%d", i);
}
extern wchar_t g_Win64UsernameW[17];
wcscpy_s(IQNet::m_player[0].m_gamertag, 32, g_Win64UsernameW);
WinsockNetLayer::Initialize();
// 4J-PB moved further down
//app.InitGameSettings();
@@ -1135,6 +1246,7 @@ int APIENTRY _tWinMain(_In_ HINSTANCE hInstance,
// Intro loop ?
while(app.IntroRunning())
{
ProfileManager.Tick();
// Tick XUI
app.RunFrame();
@@ -1156,14 +1268,30 @@ int APIENTRY _tWinMain(_In_ HINSTANCE hInstance,
MSG msg = {0};
while( WM_QUIT != msg.message )
{
g_KBMInput.Tick();
if( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) )
while( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) )
{
if( msg.message == WM_QUIT ) break;
TranslateMessage( &msg );
DispatchMessage( &msg );
continue;
}
if( msg.message == WM_QUIT ) break;
g_KBMInput.Tick();
#ifdef _DEBUG
for( int vk = 0; vk < 256; vk++ )
{
if( g_KBMInput.IsKeyPressed(vk) )
{
char dbgBuf[64];
sprintf_s(dbgBuf, "INPUT: Key pressed vk=0x%02X\n", vk);
OutputDebugStringA(dbgBuf);
}
}
#endif
RenderManager.StartFrame();
#if 0
if(pMinecraft->soundEngine->isStreamingWavebankReady() &&
@@ -1186,6 +1314,26 @@ int APIENTRY _tWinMain(_In_ HINSTANCE hInstance,
PIXBeginNamedEvent(0,"Input manager tick");
InputManager.Tick();
PIXEndNamedEvent();
if (InputManager.IsPadConnected(0))
{
bool controllerActive = InputManager.ButtonPressed(0) ||
InputManager.GetJoypadStick_LX(0,false) != 0.0f || InputManager.GetJoypadStick_LY(0,false) != 0.0f ||
InputManager.GetJoypadStick_RX(0,false) != 0.0f || InputManager.GetJoypadStick_RY(0,false) != 0.0f ||
InputManager.GetJoypadLTrigger(0,false) != 0 || InputManager.GetJoypadRTrigger(0,false) != 0;
if (controllerActive && g_KBMInput.IsKBMActive())
{
g_KBMInput.SetKBMActive(false);
g_KBMInput.SetMouseGrabbed(false);
g_KBMInput.SetCursorHiddenForUI(true);
}
else if (!g_KBMInput.IsKBMActive() && g_KBMInput.HasAnyInput())
{
g_KBMInput.SetCursorHiddenForUI(false);
g_KBMInput.SetKBMActive(true);
}
}
PIXBeginNamedEvent(0,"Profile manager tick");
// ProfileManager.Tick();
PIXEndNamedEvent();
@@ -1209,9 +1357,11 @@ int APIENTRY _tWinMain(_In_ HINSTANCE hInstance,
PIXEndNamedEvent();
PIXBeginNamedEvent(0,"Network manager do work #1");
// g_NetworkManager.DoWork();
g_NetworkManager.DoWork();
PIXEndNamedEvent();
TickDiscord();
// LeaderboardManager::Instance()->Tick();
// Render game graphics.
if(app.GetGameStarted())