the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at master 189 lines 5.7 kB view raw
1#include "stdafx.h" 2#include "..\Common\Consoles_App.h" 3#include "..\User.h" 4#include "..\..\Minecraft.Client\Minecraft.h" 5#include "..\..\Minecraft.Client\MinecraftServer.h" 6#include "..\..\Minecraft.Client\PlayerList.h" 7#include "..\..\Minecraft.Client\ServerPlayer.h" 8#include "..\..\Minecraft.World\Level.h" 9#include "..\..\Minecraft.World\LevelSettings.h" 10#include "..\..\Minecraft.World\BiomeSource.h" 11#include "..\..\Minecraft.World\LevelType.h" 12 13wstring g_playerName; 14 15CConsoleMinecraftApp app; 16 17static void LoadPlayerName() 18{ 19 if (!g_playerName.empty()) return; 20 g_playerName = L"Windows"; 21 22 char exePath[MAX_PATH] = {}; 23 GetModuleFileNameA(NULL, exePath, MAX_PATH); 24 char *lastSlash = strrchr(exePath, '\\'); 25 if (lastSlash) *(lastSlash + 1) = '\0'; 26 char filePath[MAX_PATH] = {}; 27 _snprintf_s(filePath, sizeof(filePath), _TRUNCATE, "%susername.txt", exePath); 28 29 FILE *f = NULL; 30 if (fopen_s(&f, filePath, "r") == 0 && f) 31 { 32 char buf[128] = {}; 33 if (fgets(buf, sizeof(buf), f)) 34 { 35 int len = (int)strlen(buf); 36 while (len > 0 && (buf[len-1] == '\n' || buf[len-1] == '\r' || buf[len-1] == ' ')) 37 buf[--len] = '\0'; 38 if (len > 0) 39 { 40 wchar_t wbuf[128] = {}; 41 mbstowcs(wbuf, buf, 127); 42 g_playerName = wbuf; 43 } 44 } 45 fclose(f); 46 } 47} 48 49CConsoleMinecraftApp::CConsoleMinecraftApp() : CMinecraftApp() 50{ 51 m_bShutdown = false; 52 LoadPlayerName(); 53} 54 55void CConsoleMinecraftApp::SetRichPresenceContext(int iPad, int contextId) 56{ 57 ProfileManager.SetRichPresenceContextValue(iPad,CONTEXT_GAME_STATE,contextId); 58} 59 60void CConsoleMinecraftApp::StoreLaunchData() 61{ 62} 63void CConsoleMinecraftApp::ExitGame() 64{ 65 m_bShutdown = true; 66} 67void CConsoleMinecraftApp::FatalLoadError() 68{ 69} 70 71void CConsoleMinecraftApp::CaptureSaveThumbnail() 72{ 73 RenderManager.CaptureThumbnail(&m_ThumbnailBuffer); 74} 75void CConsoleMinecraftApp::GetSaveThumbnail(PBYTE *pbData,DWORD *pdwSize) 76{ 77 // On a save caused by a create world, the thumbnail capture won't have happened 78 if (m_ThumbnailBuffer.Allocated()) 79 { 80 if (pbData) 81 { 82 *pbData = new BYTE[m_ThumbnailBuffer.GetBufferSize()]; 83 *pdwSize = m_ThumbnailBuffer.GetBufferSize(); 84 memcpy(*pbData, m_ThumbnailBuffer.GetBufferPointer(), *pdwSize); 85 } 86 m_ThumbnailBuffer.Release(); 87 } 88 else 89 { 90 // No capture happened (e.g. first save on world creation) leave thumbnail as NULL 91 if (pbData) *pbData = NULL; 92 if (pdwSize) *pdwSize = 0; 93 } 94} 95void CConsoleMinecraftApp::ReleaseSaveThumbnail() 96{ 97} 98 99void CConsoleMinecraftApp::GetScreenshot(int iPad,PBYTE *pbData,DWORD *pdwSize) 100{ 101} 102 103void CConsoleMinecraftApp::TemporaryCreateGameStart() 104{ 105 ////////////////////////////////////////////////////////////////////////////////////////////// From CScene_Main::OnInit 106 107 app.setLevelGenerationOptions(NULL); 108 109 // From CScene_Main::RunPlayGame 110 Minecraft *pMinecraft=Minecraft::GetInstance(); 111 app.ReleaseSaveThumbnail(); 112 ProfileManager.SetLockedProfile(0); 113 LoadPlayerName(); 114 pMinecraft->user->name = g_playerName; 115 app.ApplyGameSettingsChanged(0); 116 117 ////////////////////////////////////////////////////////////////////////////////////////////// From CScene_MultiGameJoinLoad::OnInit 118 MinecraftServer::resetFlags(); 119 120 // From CScene_MultiGameJoinLoad::OnNotifyPressEx 121 app.SetTutorialMode( false ); 122 app.SetCorruptSaveDeleted(false); 123 124 ////////////////////////////////////////////////////////////////////////////////////////////// From CScene_MultiGameCreate::CreateGame 125 126 app.ClearTerrainFeaturePosition(); 127 wstring wWorldName = L"TestWorld"; 128 129 StorageManager.ResetSaveData(); 130 StorageManager.SetSaveTitle(wWorldName.c_str()); 131 132 bool isFlat = false; 133 __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 134 135 NetworkGameInitData *param = new NetworkGameInitData(); 136 param->seed = seedValue; 137 param->saveData = NULL; 138 139 app.SetGameHostOption(eGameHostOption_Difficulty,0); 140 app.SetGameHostOption(eGameHostOption_FriendsOfFriends,0); 141 app.SetGameHostOption(eGameHostOption_Gamertags,1); 142 app.SetGameHostOption(eGameHostOption_BedrockFog,1); 143 144 app.SetGameHostOption(eGameHostOption_GameType,GameType::CREATIVE->getId() ); // LevelSettings::GAMETYPE_SURVIVAL 145 app.SetGameHostOption(eGameHostOption_LevelType, 0 ); 146 app.SetGameHostOption(eGameHostOption_Structures, 1 ); 147 app.SetGameHostOption(eGameHostOption_BonusChest, 0 ); 148 149 app.SetGameHostOption(eGameHostOption_PvP, 1); 150 app.SetGameHostOption(eGameHostOption_TrustPlayers, 1 ); 151 app.SetGameHostOption(eGameHostOption_FireSpreads, 1 ); 152 app.SetGameHostOption(eGameHostOption_TNT, 1 ); 153 app.SetGameHostOption(eGameHostOption_HostCanFly, 1); 154 app.SetGameHostOption(eGameHostOption_HostCanChangeHunger, 1); 155 app.SetGameHostOption(eGameHostOption_HostCanBeInvisible, 1 ); 156 157 param->settings = app.GetGameHostOption( eGameHostOption_All ); 158 159 g_NetworkManager.FakeLocalPlayerJoined(); 160 161 LoadingInputParams *loadingParams = new LoadingInputParams(); 162 loadingParams->func = &CGameNetworkManager::RunNetworkGameThreadProc; 163 loadingParams->lpParam = (LPVOID)param; 164 165 // Reset the autosave time 166 app.SetAutosaveTimerTime(); 167 168 C4JThread* thread = new C4JThread(loadingParams->func, loadingParams->lpParam, "RunNetworkGame"); 169 thread->Run(); 170} 171 172int CConsoleMinecraftApp::GetLocalTMSFileIndex(WCHAR *wchTMSFile,bool bFilenameIncludesExtension,eFileExtensionType eEXT) 173{ 174 return -1; 175} 176 177int CConsoleMinecraftApp::LoadLocalTMSFile(WCHAR *wchTMSFile) 178{ 179 return -1; 180} 181 182int CConsoleMinecraftApp::LoadLocalTMSFile(WCHAR *wchTMSFile, eFileExtensionType eExt) 183{ 184 return -1; 185} 186 187void CConsoleMinecraftApp::FreeLocalTMSFiles(eTMSFileType eType) 188{ 189}