the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 391 lines 14 kB view raw
1#include "stdafx.h" 2#include "..\..\Minecraft.h" 3#include "..\..\MultiplayerLocalPlayer.h" 4#include "..\..\MultiplayerLevel.h" 5#include "..\..\GameMode.h" 6#include "..\..\SurvivalMode.h" 7#include "..\..\CreativeMode.h" 8#include "ClientConnection.h" 9#include "MultiPlayerLocalPlayer.h" 10#include "..\..\..\Minecraft.World\ArrayWithLength.h" 11#include "..\..\..\Minecraft.World\com.mojang.nbt.h" 12#include "..\..\..\Minecraft.World\net.minecraft.world.entity.player.h" 13#include "..\..\..\Minecraft.World\net.minecraft.world.entity.animal.h" 14#include "..\..\..\Minecraft.World\net.minecraft.world.entity.monster.h" 15#include "..\..\..\Minecraft.World\net.minecraft.world.entity.boss.enderdragon.h" 16#include "..\..\..\Minecraft.World\net.minecraft.world.level.h" 17#include "..\..\..\Minecraft.World\net.minecraft.world.level.saveddata.h" 18#include "..\..\..\Minecraft.World\net.minecraft.world.level.chunk.storage.h" 19#include "..\..\..\Minecraft.World\net.minecraft.world.level.storage.h" 20#include "..\..\..\Minecraft.World\InputOutputStream.h" 21#include "..\..\..\Minecraft.World\ConsoleSaveFileIO.h" 22#include "..\..\..\Minecraft.World\net.minecraft.world.item.h" 23#include "..\..\..\Minecraft.World\net.minecraft.world.item.enchantment.h" 24#include "XUI_DebugOverlay.h" 25#include "..\..\..\Minecraft.Client\GameRenderer.h" 26#include "..\..\MinecraftServer.h" 27#include "..\..\Common\Tutorial\Tutorial.h" 28#include "..\..\..\Minecraft.World\net.minecraft.commands.common.h" 29#include "..\..\..\Minecraft.World\ConsoleSaveFileOriginal.h" 30 31#ifdef _DEBUG_MENUS_ENABLED 32HRESULT CScene_DebugOverlay::OnInit( XUIMessageInit *pInitData, BOOL &bHandled ) 33{ 34 MapChildControls(); 35 36 m_items.InsertItems( 0, 512 ); 37 38 for(unsigned int i = 0; i < Item::items.length; ++i) 39 { 40 if(Item::items[i] != NULL) 41 { 42 //m_items.InsertItems(m_items.GetItemCount(),1); 43 m_itemIds.push_back(i); 44 m_items.SetText( m_itemIds.size() - 1, app.GetString( Item::items[i]->getDescriptionId() ) ); 45 } 46 } 47 48 m_enchantments.InsertItems( 0, Enchantment::validEnchantments.size() ); 49 for(unsigned int i = 0; i < Enchantment::validEnchantments.size(); ++i ) 50 { 51 Enchantment *ench = Enchantment::validEnchantments.at(i); 52 53 m_enchantmentIds.push_back(ench->id); 54 m_enchantments.SetText( i, app.GetString( ench->getDescriptionId() ) ); 55 } 56 57 m_mobs.InsertItems( 0, 21 ); 58 59 m_mobs.SetText( m_mobFactories.size(), L"Chicken" ); 60 m_mobFactories.push_back(eTYPE_CHICKEN); 61 m_mobs.SetText( m_mobFactories.size(), L"Cow" ); 62 m_mobFactories.push_back(eTYPE_COW); 63 m_mobs.SetText( m_mobFactories.size(), L"Pig" ); 64 m_mobFactories.push_back(eTYPE_PIG); 65 m_mobs.SetText( m_mobFactories.size(), L"Sheep" ); 66 m_mobFactories.push_back(eTYPE_SHEEP); 67 m_mobs.SetText( m_mobFactories.size(), L"Squid" ); 68 m_mobFactories.push_back(eTYPE_SQUID); 69 m_mobs.SetText( m_mobFactories.size(), L"Wolf" ); 70 m_mobFactories.push_back(eTYPE_WOLF); 71 m_mobs.SetText( m_mobFactories.size(), L"Creeper" ); 72 m_mobFactories.push_back(eTYPE_CREEPER); 73 m_mobs.SetText( m_mobFactories.size(), L"Ghast" ); 74 m_mobFactories.push_back(eTYPE_GHAST); 75 m_mobs.SetText( m_mobFactories.size(), L"Pig Zombie" ); 76 m_mobFactories.push_back(eTYPE_PIGZOMBIE); 77 m_mobs.SetText( m_mobFactories.size(), L"Skeleton" ); 78 m_mobFactories.push_back(eTYPE_SKELETON); 79 m_mobs.SetText( m_mobFactories.size(), L"Slime" ); 80 m_mobFactories.push_back(eTYPE_SLIME); 81 m_mobs.SetText( m_mobFactories.size(), L"Spider" ); 82 m_mobFactories.push_back(eTYPE_SPIDER); 83 m_mobs.SetText( m_mobFactories.size(), L"Zombie" ); 84 m_mobFactories.push_back(eTYPE_ZOMBIE); 85 m_mobs.SetText( m_mobFactories.size(), L"Enderman" ); 86 m_mobFactories.push_back(eTYPE_ENDERMAN); 87 m_mobs.SetText( m_mobFactories.size(), L"Silverfish" ); 88 m_mobFactories.push_back(eTYPE_SILVERFISH); 89 m_mobs.SetText( m_mobFactories.size(), L"Cave Spider" ); 90 m_mobFactories.push_back(eTYPE_CAVESPIDER); 91 m_mobs.SetText( m_mobFactories.size(), L"Mooshroom" ); 92 m_mobFactories.push_back(eTYPE_MUSHROOMCOW); 93 m_mobs.SetText( m_mobFactories.size(), L"Snow Golem" ); 94 m_mobFactories.push_back(eTYPE_SNOWMAN); 95 m_mobs.SetText( m_mobFactories.size(), L"Ender Dragon" ); 96 m_mobFactories.push_back(eTYPE_ENDERDRAGON); 97 m_mobs.SetText( m_mobFactories.size(), L"Blaze" ); 98 m_mobFactories.push_back(eTYPE_BLAZE); 99 m_mobs.SetText( m_mobFactories.size(), L"Magma Cube" ); 100 m_mobFactories.push_back(eTYPE_LAVASLIME); 101 102 103 Minecraft *pMinecraft = Minecraft::GetInstance(); 104 m_setTime.SetValue( pMinecraft->level->getLevelData()->getTime() % 24000 ); 105 m_setFov.SetValue( (int)pMinecraft->gameRenderer->GetFovVal()); 106 107 XuiSetTimer(m_hObj,0,DEBUG_OVERLAY_UPDATE_TIME_PERIOD); 108 109 bHandled = TRUE; 110 return S_OK; 111} 112 113// Handler for the XM_NOTIFY message 114HRESULT CScene_DebugOverlay::OnNotifyPressEx(HXUIOBJ hObjPressed, XUINotifyPress* pNotifyPressData, BOOL& rfHandled) 115{ 116 // This assumes all buttons can only be pressed with the A button 117 ui.AnimateKeyPress(pNotifyPressData->UserIndex, VK_PAD_A); 118 119 unsigned int nIndex; 120 121 Minecraft *pMinecraft = Minecraft::GetInstance(); 122 123 if ( hObjPressed == m_items ) 124 { 125 nIndex = m_items.GetCurSel(); 126 if(nIndex<m_itemIds.size()) 127 { 128 int id = m_itemIds[nIndex]; 129 //app.SetXuiServerAction(pNotifyPressData->UserIndex, eXuiServerAction_DropItem, (void *)id); 130 ClientConnection *conn = Minecraft::GetInstance()->getConnection(ProfileManager.GetPrimaryPad()); 131 conn->send( GiveItemCommand::preparePacket(dynamic_pointer_cast<Player>(Minecraft::GetInstance()->localplayers[ProfileManager.GetPrimaryPad()]), id) ); 132 } 133 } 134 else if ( hObjPressed == m_mobs ) 135 { 136 nIndex = m_mobs.GetCurSel(); 137 if(nIndex<m_mobFactories.size()) 138 { 139 app.SetXuiServerAction(ProfileManager.GetPrimaryPad(),eXuiServerAction_SpawnMob,(void *)m_mobFactories[nIndex]); 140 } 141 } 142 else if ( hObjPressed == m_enchantments ) 143 { 144 nIndex = m_enchantments.GetCurSel(); 145 ClientConnection *conn = Minecraft::GetInstance()->getConnection(ProfileManager.GetPrimaryPad()); 146 conn->send( EnchantItemCommand::preparePacket(dynamic_pointer_cast<Player>(Minecraft::GetInstance()->localplayers[ProfileManager.GetPrimaryPad()]), m_enchantmentIds[nIndex]) ); 147 } 148 /*else if( hObjPressed == m_saveToDisc ) // 4J-JEV: Doesn't look like we use this debug option anymore. 149 { 150#ifndef _CONTENT_PACKAGE 151 pMinecraft->level->save(true, NULL); 152 153 int radius; 154 m_chunkRadius.GetValue(&radius); 155 if( radius > 0 ) 156 { 157 SaveLimitedFile(radius); 158 } 159 else 160 { 161 pMinecraft->level->getLevelStorage()->getSaveFile()->DebugFlushToFile(); 162 } 163#endif 164 }*/ 165 else if( hObjPressed == m_createSchematic ) 166 { 167#ifndef _CONTENT_PACKAGE 168 // load from the .xzp file 169 const ULONG_PTR c_ModuleHandle = (ULONG_PTR)GetModuleHandle(NULL); 170 171 HXUIOBJ hScene; 172 HRESULT hr; 173 //const WCHAR XZP_SEPARATOR = L'#'; 174 const DWORD LOCATOR_SIZE = 256; // Use this to allocate space to hold a ResourceLocator string 175 WCHAR szResourceLocator[ LOCATOR_SIZE ]; 176 177 swprintf(szResourceLocator, LOCATOR_SIZE, L"section://%X,%ls#%ls",c_ModuleHandle,L"media", L"media/"); 178 hr = XuiSceneCreate(szResourceLocator,app.GetSceneName(eUIScene_DebugCreateSchematic,false, false), NULL, &hScene); 179 this->NavigateForward(hScene); 180 //app.NavigateToScene(ProfileManager.GetPrimaryPad(),eUIScene_DebugCreateSchematic); 181#endif 182 } 183 else if ( hObjPressed == m_setCamera ) 184 { 185#ifndef _CONTENT_PACKAGE 186 // load from the .xzp file 187 const ULONG_PTR c_ModuleHandle = (ULONG_PTR)GetModuleHandle(NULL); 188 189 HXUIOBJ hScene; 190 HRESULT hr; 191 //const WCHAR XZP_SEPARATOR = L'#'; 192 const DWORD LOCATOR_SIZE = 256; // Use this to allocate space to hold a ResourceLocator string 193 WCHAR szResourceLocator[ LOCATOR_SIZE ]; 194 195 swprintf(szResourceLocator, LOCATOR_SIZE, L"section://%X,%ls#%ls",c_ModuleHandle,L"media", L"media/"); 196 hr = XuiSceneCreate(szResourceLocator,app.GetSceneName(eUIScene_DebugSetCamera, false, false), NULL, &hScene); 197 this->NavigateForward(hScene); 198 //app.NavigateToScene(ProfileManager.GetPrimaryPad(),eUIScene_DebugCreateSchematic); 199#endif 200 } 201 else if( hObjPressed == m_toggleRain ) 202 { 203 //app.SetXuiServerAction(ProfileManager.GetPrimaryPad(),eXuiServerAction_ToggleRain); 204 ClientConnection *conn = Minecraft::GetInstance()->getConnection(ProfileManager.GetPrimaryPad()); 205 conn->send( ToggleDownfallCommand::preparePacket() ); 206 } 207 else if( hObjPressed == m_toggleThunder ) 208 { 209 app.SetXuiServerAction(ProfileManager.GetPrimaryPad(),eXuiServerAction_ToggleThunder); 210 } 211 else if( hObjPressed == m_resetTutorial ) 212 { 213 Tutorial::debugResetPlayerSavedProgress( ProfileManager.GetPrimaryPad() ); 214 } 215 else if( hObjPressed == m_setDay ) 216 { 217 ClientConnection *conn = Minecraft::GetInstance()->getConnection(ProfileManager.GetPrimaryPad()); 218 conn->send( TimeCommand::preparePacket(false) ); 219 } 220 else if( hObjPressed == m_setNight ) 221 { 222 ClientConnection *conn = Minecraft::GetInstance()->getConnection(ProfileManager.GetPrimaryPad()); 223 conn->send( TimeCommand::preparePacket(true) ); 224 } 225 226 rfHandled = TRUE; 227 return S_OK; 228} 229 230HRESULT CScene_DebugOverlay::OnKeyDown(XUIMessageInput* pInputData, BOOL& rfHandled) 231{ 232 ui.AnimateKeyPress(pInputData->UserIndex, pInputData->dwKeyCode); 233 234 235 switch(pInputData->dwKeyCode) 236 { 237 238 case VK_PAD_B: 239 case VK_PAD_START: 240 case VK_PAD_BACK: 241 242 // kill the crafting xui 243 app.EnableDebugOverlay(false,pInputData->UserIndex); 244 245 rfHandled = TRUE; 246 247 break; 248 249 } 250 251 return S_OK; 252} 253 254HRESULT CScene_DebugOverlay::OnNotifyValueChanged( HXUIOBJ hObjSource, XUINotifyValueChanged *pNotifyValueChangedData, BOOL &bHandled) 255{ 256 if( hObjSource == m_setTime ) 257 { 258 Minecraft *pMinecraft = Minecraft::GetInstance(); 259 260 // Need to set the time on both levels to stop the flickering as the local level 261 // tries to predict the time 262 // Only works if we are on the host machine, but shouldn't break if not 263 MinecraftServer::SetTime(pNotifyValueChangedData->nValue); 264 pMinecraft->level->getLevelData()->setTime(pNotifyValueChangedData->nValue); 265 } 266 if( hObjSource == m_setFov ) 267 { 268 Minecraft *pMinecraft = Minecraft::GetInstance(); 269 pMinecraft->gameRenderer->SetFovVal((float)pNotifyValueChangedData->nValue); 270 } 271 return S_OK; 272} 273 274HRESULT CScene_DebugOverlay::OnTimer( XUIMessageTimer *pTimer, BOOL& bHandled ) 275{ 276 Minecraft *pMinecraft = Minecraft::GetInstance(); 277 if(pMinecraft->level != NULL) 278 { 279 m_setTime.SetValue( pMinecraft->level->getLevelData()->getTime() % 24000 ); 280 m_setFov.SetValue( (int)pMinecraft->gameRenderer->GetFovVal()); 281 } 282 return S_OK; 283} 284 285void CScene_DebugOverlay::SetSpawnToPlayerPos() 286{ 287 Minecraft *pMinecraft = Minecraft::GetInstance(); 288 289 pMinecraft->level->getLevelData()->setXSpawn((int)pMinecraft->player->x); 290 pMinecraft->level->getLevelData()->setYSpawn((int)pMinecraft->player->y); 291 pMinecraft->level->getLevelData()->setZSpawn((int)pMinecraft->player->z); 292} 293 294#ifndef _CONTENT_PACKAGE 295void CScene_DebugOverlay::SaveLimitedFile(int chunkRadius) 296{ 297 unordered_map<File, RegionFile *, FileKeyHash, FileKeyEq> newFileCache; 298 299 Minecraft *pMinecraft = Minecraft::GetInstance(); 300 301 ConsoleSaveFile *currentSave = pMinecraft->level->getLevelStorage()->getSaveFile(); 302 303 // With a size of 0 but a value in the data pointer we should create a new save 304 ConsoleSaveFileOriginal newSave( currentSave->getFilename(), NULL, 0, true ); 305 306 // TODO Make this only happen for the new save 307 //SetSpawnToPlayerPos(); 308 FileEntry *origFileEntry = currentSave->createFile( wstring( L"level.dat" ) ); 309 byteArray levelData( origFileEntry->getFileSize() ); 310 DWORD bytesRead; 311 currentSave->setFilePointer(origFileEntry,0,NULL,FILE_BEGIN); 312 currentSave->readFile( 313 origFileEntry, 314 levelData.data, // data buffer 315 origFileEntry->getFileSize(), // number of bytes to read 316 &bytesRead // number of bytes read 317 ); 318 319 FileEntry *newFileEntry = newSave.createFile( wstring( L"level.dat" ) ); 320 DWORD bytesWritten; 321 newSave.writeFile( newFileEntry, 322 levelData.data, // data buffer 323 origFileEntry->getFileSize(), // number of bytes to write 324 &bytesWritten // number of bytes written 325 ); 326 327 int playerChunkX = pMinecraft->player->xChunk; 328 int playerChunkZ = pMinecraft->player->zChunk; 329 330 for(int xPos = playerChunkX - chunkRadius; xPos < playerChunkX + chunkRadius; ++xPos) 331 { 332 for(int zPos = playerChunkZ - chunkRadius; zPos < playerChunkZ + chunkRadius; ++zPos) 333 { 334 CompoundTag *chunkData=NULL; 335 336 DataInputStream *is = RegionFileCache::getChunkDataInputStream(currentSave, L"", xPos, zPos); 337 if (is != NULL) 338 { 339 chunkData = NbtIo::read((DataInput *)is); 340 is->deleteChildStream(); 341 delete is; 342 } 343 app.DebugPrintf("Processing chunk (%d, %d)\n", xPos, zPos); 344 DataOutputStream *os = getChunkDataOutputStream(newFileCache, &newSave, L"", xPos, zPos); 345 if(os != NULL) 346 { 347 NbtIo::write(chunkData, os); 348 os->close(); 349 350 // 4J Stu - getChunkDataOutputStream makes a new DataOutputStream that points to a new ChunkBuffer( ByteArrayOutputStream ) 351 // We should clean these up when we are done 352 os->deleteChildStream(); 353 delete os; 354 } 355 if(chunkData != NULL) 356 { 357 delete chunkData; 358 } 359 } 360 } 361 362 newSave.DebugFlushToFile(); 363} 364#endif 365 366RegionFile *CScene_DebugOverlay::getRegionFile(unordered_map<File, RegionFile *, FileKeyHash, FileKeyEq> &newFileCache, ConsoleSaveFile *saveFile, const wstring &prefix, int chunkX, int chunkZ) // 4J - TODO was synchronized 367{ 368 File file( prefix + wstring(L"r.") + _toString(chunkX>>5) + L"." + _toString(chunkZ>>5) + L".mcr" ); 369 370 RegionFile *ref = NULL; 371 AUTO_VAR(it, newFileCache.find(file)); 372 if( it != newFileCache.end() ) 373 ref = it->second; 374 375 // 4J Jev, put back in. 376 if (ref != NULL) 377 { 378 return ref; 379 } 380 381 RegionFile *reg = new RegionFile(saveFile, &file); 382 newFileCache[file] = reg; // 4J - this was originally a softReferenc 383 return reg; 384} 385 386DataOutputStream *CScene_DebugOverlay::getChunkDataOutputStream(unordered_map<File, RegionFile *, FileKeyHash, FileKeyEq> &newFileCache, ConsoleSaveFile *saveFile, const wstring &prefix, int chunkX, int chunkZ) 387{ 388 RegionFile *r = getRegionFile(newFileCache, saveFile, prefix, chunkX, chunkZ); 389 return r->getChunkDataOutputStream(chunkX & 31, chunkZ & 31); 390} 391#endif