2026-03-01 12:16:08 +08:00
# include " stdafx.h "
# include "..\Common\Consoles_App.h"
# include "..\User.h"
# include "..\..\Minecraft.Client\Minecraft.h"
# include "..\..\Minecraft.Client\MinecraftServer.h"
# include "..\..\Minecraft.Client\PlayerList.h"
# include "..\..\Minecraft.Client\ServerPlayer.h"
# include "..\..\Minecraft.World\Level.h"
# include "..\..\Minecraft.World\LevelSettings.h"
# include "..\..\Minecraft.World\BiomeSource.h"
# include "..\..\Minecraft.World\LevelType.h"
2026-03-02 23:50:45 +00:00
wstring g_playerName ;
2026-03-01 12:16:08 +08:00
CConsoleMinecraftApp app ;
2026-03-02 23:50:45 +00:00
static void LoadPlayerName ( )
{
if ( ! g_playerName . empty ( ) ) return ;
g_playerName = L " Windows " ;
char exePath [ MAX_PATH ] = { } ;
GetModuleFileNameA ( NULL , exePath , MAX_PATH ) ;
char * lastSlash = strrchr ( exePath , ' \\ ' ) ;
if ( lastSlash ) * ( lastSlash + 1 ) = ' \0 ' ;
char filePath [ MAX_PATH ] = { } ;
_snprintf_s ( filePath , sizeof ( filePath ) , _TRUNCATE , " %susername.txt " , exePath ) ;
FILE * f = NULL ;
if ( fopen_s ( & f , filePath , " r " ) = = 0 & & f )
{
char buf [ 128 ] = { } ;
if ( fgets ( buf , sizeof ( buf ) , f ) )
{
int len = ( int ) strlen ( buf ) ;
while ( len > 0 & & ( buf [ len - 1 ] = = ' \n ' | | buf [ len - 1 ] = = ' \r ' | | buf [ len - 1 ] = = ' ' ) )
buf [ - - len ] = ' \0 ' ;
if ( len > 0 )
{
wchar_t wbuf [ 128 ] = { } ;
mbstowcs ( wbuf , buf , 127 ) ;
g_playerName = wbuf ;
}
}
fclose ( f ) ;
}
}
2026-03-01 12:16:08 +08:00
CConsoleMinecraftApp : : CConsoleMinecraftApp ( ) : CMinecraftApp ( )
{
2026-03-01 22:13:44 +04:00
m_bShutdown = false ;
2026-03-02 23:50:45 +00:00
LoadPlayerName ( ) ;
2026-03-01 12:16:08 +08:00
}
void CConsoleMinecraftApp : : SetRichPresenceContext ( int iPad , int contextId )
{
ProfileManager . SetRichPresenceContextValue ( iPad , CONTEXT_GAME_STATE , contextId ) ;
}
void CConsoleMinecraftApp : : StoreLaunchData ( )
{
}
void CConsoleMinecraftApp : : ExitGame ( )
{
2026-03-01 22:13:44 +04:00
m_bShutdown = true ;
2026-03-01 12:16:08 +08:00
}
void CConsoleMinecraftApp : : FatalLoadError ( )
{
}
void CConsoleMinecraftApp : : CaptureSaveThumbnail ( )
{
2026-03-02 23:50:45 +00:00
RenderManager . CaptureThumbnail ( & m_ThumbnailBuffer ) ;
2026-03-01 12:16:08 +08:00
}
void CConsoleMinecraftApp : : GetSaveThumbnail ( PBYTE * pbData , DWORD * pdwSize )
{
2026-03-02 23:50:45 +00:00
// On a save caused by a create world, the thumbnail capture won't have happened
if ( m_ThumbnailBuffer . Allocated ( ) )
{
if ( pbData )
{
* pbData = new BYTE [ m_ThumbnailBuffer . GetBufferSize ( ) ] ;
* pdwSize = m_ThumbnailBuffer . GetBufferSize ( ) ;
memcpy ( * pbData , m_ThumbnailBuffer . GetBufferPointer ( ) , * pdwSize ) ;
}
m_ThumbnailBuffer . Release ( ) ;
}
else
{
// No capture happened (e.g. first save on world creation) leave thumbnail as NULL
if ( pbData ) * pbData = NULL ;
if ( pdwSize ) * pdwSize = 0 ;
}
2026-03-01 12:16:08 +08:00
}
void CConsoleMinecraftApp : : ReleaseSaveThumbnail ( )
{
}
void CConsoleMinecraftApp : : GetScreenshot ( int iPad , PBYTE * pbData , DWORD * pdwSize )
{
}
void CConsoleMinecraftApp : : TemporaryCreateGameStart ( )
{
////////////////////////////////////////////////////////////////////////////////////////////// From CScene_Main::OnInit
app . setLevelGenerationOptions ( NULL ) ;
// From CScene_Main::RunPlayGame
Minecraft * pMinecraft = Minecraft : : GetInstance ( ) ;
app . ReleaseSaveThumbnail ( ) ;
ProfileManager . SetLockedProfile ( 0 ) ;
2026-03-02 23:50:45 +00:00
LoadPlayerName ( ) ;
pMinecraft - > user - > name = g_playerName ;
2026-03-01 12:16:08 +08:00
app . ApplyGameSettingsChanged ( 0 ) ;
////////////////////////////////////////////////////////////////////////////////////////////// From CScene_MultiGameJoinLoad::OnInit
MinecraftServer : : resetFlags ( ) ;
// From CScene_MultiGameJoinLoad::OnNotifyPressEx
app . SetTutorialMode ( false ) ;
app . SetCorruptSaveDeleted ( false ) ;
////////////////////////////////////////////////////////////////////////////////////////////// From CScene_MultiGameCreate::CreateGame
app . ClearTerrainFeaturePosition ( ) ;
wstring wWorldName = L " TestWorld " ;
StorageManager . ResetSaveData ( ) ;
StorageManager . SetSaveTitle ( wWorldName . c_str ( ) ) ;
bool isFlat = false ;
2026-03-02 17:39:35 +07:00
__int64 seedValue = 0 ; // BiomeSource::findSeed(isFlat?LevelType::lvl_flat:LevelType::lvl_normal); // 4J - was (new Random())->nextLong() - now trying to actually find a seed to suit our requirements
2026-03-01 12:16:08 +08:00
NetworkGameInitData * param = new NetworkGameInitData ( ) ;
param - > seed = seedValue ;
param - > saveData = NULL ;
app . SetGameHostOption ( eGameHostOption_Difficulty , 0 ) ;
app . SetGameHostOption ( eGameHostOption_FriendsOfFriends , 0 ) ;
app . SetGameHostOption ( eGameHostOption_Gamertags , 1 ) ;
app . SetGameHostOption ( eGameHostOption_BedrockFog , 1 ) ;
app . SetGameHostOption ( eGameHostOption_GameType , GameType : : CREATIVE - > getId ( ) ) ; // LevelSettings::GAMETYPE_SURVIVAL
app . SetGameHostOption ( eGameHostOption_LevelType , 0 ) ;
app . SetGameHostOption ( eGameHostOption_Structures , 1 ) ;
app . SetGameHostOption ( eGameHostOption_BonusChest , 0 ) ;
app . SetGameHostOption ( eGameHostOption_PvP , 1 ) ;
app . SetGameHostOption ( eGameHostOption_TrustPlayers , 1 ) ;
app . SetGameHostOption ( eGameHostOption_FireSpreads , 1 ) ;
app . SetGameHostOption ( eGameHostOption_TNT , 1 ) ;
app . SetGameHostOption ( eGameHostOption_HostCanFly , 1 ) ;
app . SetGameHostOption ( eGameHostOption_HostCanChangeHunger , 1 ) ;
app . SetGameHostOption ( eGameHostOption_HostCanBeInvisible , 1 ) ;
param - > settings = app . GetGameHostOption ( eGameHostOption_All ) ;
g_NetworkManager . FakeLocalPlayerJoined ( ) ;
LoadingInputParams * loadingParams = new LoadingInputParams ( ) ;
loadingParams - > func = & CGameNetworkManager : : RunNetworkGameThreadProc ;
loadingParams - > lpParam = ( LPVOID ) param ;
// Reset the autosave time
app . SetAutosaveTimerTime ( ) ;
C4JThread * thread = new C4JThread ( loadingParams - > func , loadingParams - > lpParam , " RunNetworkGame " ) ;
thread - > Run ( ) ;
}
int CConsoleMinecraftApp : : GetLocalTMSFileIndex ( WCHAR * wchTMSFile , bool bFilenameIncludesExtension , eFileExtensionType eEXT )
{
return - 1 ;
}
int CConsoleMinecraftApp : : LoadLocalTMSFile ( WCHAR * wchTMSFile )
{
return - 1 ;
}
int CConsoleMinecraftApp : : LoadLocalTMSFile ( WCHAR * wchTMSFile , eFileExtensionType eExt )
{
return - 1 ;
}
void CConsoleMinecraftApp : : FreeLocalTMSFiles ( eTMSFileType eType )
{
}