the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
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#include "ServiceConfig\Events-XBLA.8-149E11AEEvents.h"
13#include "..\..\Minecraft.World\DurangoStats.h"
14#include "..\..\Minecraft.Client\Durango\XML\xmlFilesCallback.h"
15
16CConsoleMinecraftApp app;
17
18CConsoleMinecraftApp::CConsoleMinecraftApp() : CMinecraftApp()
19{
20 memset(&m_ThumbnailBuffer,0,sizeof(ImageFileBuffer));
21 m_bShutdown=false;
22
23 m_bRead_TMS_DLCINFO_XML=false;
24 m_bTMSPP_GlobalFileListRead=false;
25 m_bTMSPP_UserFileListRead=false;
26
27 for (int i=0; i<MAX_LOCAL_PLAYERS; i++)
28 {
29 m_iLastPresenceContext[i] = -1;
30 m_xuidLastPresencePlayer[i] = INVALID_XUID;
31 }
32}
33
34
35void CConsoleMinecraftApp::HandleDLCLicenseChange()
36{
37 // run through the DLC packs and update if required
38 int iOfferC=app.GetDLCOffersCount();
39 for(int i = 0; i < iOfferC; i++)
40 {
41 MARKETPLACE_CONTENTOFFER_INFO xOffer = StorageManager.GetOffer(i);
42
43 XCONTENT_DATA *pContentData=StorageManager.GetInstalledDLC(xOffer.wszProductID);
44
45 if((pContentData!=NULL) &&(pContentData->bTrialLicense==false))
46 {
47 DLCPack *pack = app.m_dlcManager.getPackFromProductID(xOffer.wszProductID);
48 if(pack)
49 {
50 // Clear the DLC installed flag so the scenes will pick up the new dlc (could be a full pack install)
51 app.ClearDLCInstalled();
52 app.DebugPrintf(">>> HandleDLCLicenseChange - Updating license for DLC [%ls]\n",xOffer.wszOfferName);
53 pack->updateLicenseMask(1);
54 }
55 else
56 {
57 app.DebugPrintf(">>> HandleDLCLicenseChange - Couldn't find licensed DLC [%ls] in app.m_dlcManager\n",xOffer.wszOfferName);
58 }
59 }
60 }
61
62 ui.HandleDLCLicenseChange();
63}
64
65
66void CConsoleMinecraftApp::SetRichPresenceContext(int iPad, int contextId)
67{
68 if(iPad < XUSER_MAX_COUNT && Minecraft::GetInstance()->localplayers[iPad])
69 {
70 PlayerUID uid;
71 ProfileManager.GetXUID(iPad, &uid, true);
72
73 if (uid != INVALID_XUID)
74 {
75 // 4J-JEV: Player has changed, update cached player and ensure this next presence is sent.
76 if (uid != m_xuidLastPresencePlayer[iPad])
77 {
78 m_xuidLastPresencePlayer[iPad] = uid;
79 m_iLastPresenceContext[iPad] = -1;
80 }
81
82 if (m_iLastPresenceContext[iPad] != contextId)
83 {
84 app.DebugPrintf(">>> EventWriteRichPresenceState(%ls,_,%d)\n", uid.toString().c_str(), contextId);
85 EventWriteRichPresenceState(uid.toString().c_str(), DurangoStats::getPlayerSession(), contextId);
86
87 m_iLastPresenceContext[iPad] = contextId;
88 }
89 }
90 }
91}
92
93void CConsoleMinecraftApp::StoreLaunchData()
94{
95}
96void CConsoleMinecraftApp::ExitGame()
97{
98 //Windows::ApplicationModel::Core::CoreApplication::Exit();
99 m_bShutdown=true;
100}
101void CConsoleMinecraftApp::FatalLoadError()
102{
103 // 4J-PB -
104 //for(int i=0;i<10;i++)
105 {
106#ifndef _CONTENT_PACKAGE
107 OutputDebugStringA("FatalLoadError\n");
108#endif
109 //Sleep(5000);
110 }
111}
112
113void CConsoleMinecraftApp::CaptureSaveThumbnail()
114{
115 RenderManager.CaptureThumbnail(&m_ThumbnailBuffer);
116}
117void CConsoleMinecraftApp::GetSaveThumbnail(PBYTE *pbData,DWORD *pdwSize)
118{
119 // on a save caused by a create world, the thumbnail capture won't have happened
120 if(m_ThumbnailBuffer.Allocated())
121 {
122 if( pbData )
123 {
124 *pbData= new BYTE [m_ThumbnailBuffer.GetBufferSize()];
125 *pdwSize=m_ThumbnailBuffer.GetBufferSize();
126 memcpy(*pbData,m_ThumbnailBuffer.GetBufferPointer(),*pdwSize);
127 }
128 m_ThumbnailBuffer.Release();
129 }
130 else
131 {
132 if( pbData )
133 {
134 // use the default image
135 StorageManager.GetDefaultSaveThumbnail(pbData,pdwSize);
136 }
137 }
138}
139void CConsoleMinecraftApp::ReleaseSaveThumbnail()
140{
141
142}
143
144void CConsoleMinecraftApp::GetScreenshot(int iPad,PBYTE *pbData,DWORD *pdwSize)
145{
146
147}
148
149int CConsoleMinecraftApp::GetLocalTMSFileIndex(WCHAR *wchTMSFile,bool bFilenameIncludesExtension,eFileExtensionType eEXT)
150{
151 return -1;
152}
153
154
155int CConsoleMinecraftApp::LoadLocalTMSFile(WCHAR *wchTMSFile)
156{
157 return -1;
158}
159
160int CConsoleMinecraftApp::LoadLocalTMSFile(WCHAR *wchTMSFile, eFileExtensionType eExt)
161{
162 return -1;
163}
164
165void CConsoleMinecraftApp::FreeLocalTMSFiles(eTMSFileType eType)
166{
167
168}
169
170int CConsoleMinecraftApp::LoadLocalDLCImages()
171{
172 unordered_map<wstring,DLC_INFO * > *pDLCInfoA=app.GetDLCInfo();
173 // 4J-PB - Any local graphic files for the Minecraft Store?
174 for( AUTO_VAR(it, pDLCInfoA->begin()); it != pDLCInfoA->end(); it++ )
175 {
176 DLC_INFO * pDLCInfo=(*it).second;
177
178 LoadLocalDLCImage(pDLCInfo->wchBanner,&pDLCInfo->pbImageData,&pDLCInfo->dwImageBytes);
179 }
180 return 0;
181}
182
183void CConsoleMinecraftApp::FreeLocalDLCImages()
184{
185 // 4J-PB - Any local graphic files for the Minecraft Store?
186 unordered_map<wstring,DLC_INFO * > *pDLCInfoA=app.GetDLCInfo();
187
188 for( AUTO_VAR(it, pDLCInfoA->begin()); it != pDLCInfoA->end(); it++ )
189 {
190 DLC_INFO * pDLCInfo=(*it).second;
191
192 if(pDLCInfo->dwImageBytes!=0)
193 {
194 free(pDLCInfo->pbImageData);
195 pDLCInfo->dwImageBytes=0;
196 pDLCInfo->pbImageData=NULL;
197 }
198 }
199}
200
201
202int CConsoleMinecraftApp::LoadLocalDLCImage(WCHAR *wchName,PBYTE *ppbImageData,DWORD *pdwBytes)
203{
204 // load the local file
205 WCHAR wchFilename[64];
206
207
208 // 4J-PB - Read the file containing the product codes. This will be different for the SCEE/SCEA/SCEJ builds
209 swprintf(wchFilename,L"DLCImages/%s",wchName);
210 HANDLE hFile = CreateFile(wchFilename, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
211
212 if( hFile == INVALID_HANDLE_VALUE )
213 {
214 app.DebugPrintf("Failed to open %ls\n", wchFilename);
215 return FALSE;
216 }
217
218 DWORD dwHigh=0;
219 *pdwBytes = GetFileSize(hFile,&dwHigh);
220
221 if(*pdwBytes!=0)
222 {
223 DWORD dwBytesRead;
224 PBYTE pbImageData=(PBYTE)malloc(*pdwBytes);
225
226 if(ReadFile(hFile,pbImageData,*pdwBytes,&dwBytesRead,NULL)==FALSE)
227 {
228 // failed
229 free(pbImageData);
230 *pdwBytes=0;
231 }
232 else
233 {
234 *ppbImageData=pbImageData;
235 }
236 }
237
238 CloseHandle(hFile);
239
240 return 0;
241}
242
243void CConsoleMinecraftApp::TemporaryCreateGameStart()
244{
245 ////////////////////////////////////////////////////////////////////////////////////////////// From CScene_Main::OnInit
246
247 app.setLevelGenerationOptions(NULL);
248
249 // From CScene_Main::RunPlayGame
250 Minecraft *pMinecraft=Minecraft::GetInstance();
251 app.ReleaseSaveThumbnail();
252 ProfileManager.SetLockedProfile(0);
253 pMinecraft->user->name = L"Durango";
254 app.ApplyGameSettingsChanged(0);
255
256 ////////////////////////////////////////////////////////////////////////////////////////////// From CScene_MultiGameJoinLoad::OnInit
257 MinecraftServer::resetFlags();
258
259 // From CScene_MultiGameJoinLoad::OnNotifyPressEx
260 app.SetTutorialMode( false );
261 app.SetCorruptSaveDeleted(false);
262
263 ////////////////////////////////////////////////////////////////////////////////////////////// From CScene_MultiGameCreate::CreateGame
264
265 app.ClearTerrainFeaturePosition();
266 wstring wWorldName = L"TestWorld";
267
268 StorageManager.ResetSaveData();
269 StorageManager.SetSaveTitle(wWorldName.c_str());
270
271 bool isFlat = false;
272 __int64 seedValue = 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
273
274 NetworkGameInitData *param = new NetworkGameInitData();
275 param->seed = seedValue;
276 param->saveData = NULL;
277
278 app.SetGameHostOption(eGameHostOption_Difficulty,0);
279 app.SetGameHostOption(eGameHostOption_FriendsOfFriends,0);
280 app.SetGameHostOption(eGameHostOption_Gamertags,1);
281 app.SetGameHostOption(eGameHostOption_BedrockFog,1);
282
283 app.SetGameHostOption(eGameHostOption_GameType,GameType::SURVIVAL->getId() );
284 app.SetGameHostOption(eGameHostOption_LevelType, 0 );
285 app.SetGameHostOption(eGameHostOption_Structures, 1 );
286 app.SetGameHostOption(eGameHostOption_BonusChest, 0 );
287
288 app.SetGameHostOption(eGameHostOption_PvP, 1);
289 app.SetGameHostOption(eGameHostOption_TrustPlayers, 1 );
290 app.SetGameHostOption(eGameHostOption_FireSpreads, 1 );
291 app.SetGameHostOption(eGameHostOption_TNT, 1 );
292 app.SetGameHostOption(eGameHostOption_HostCanFly, 1);
293 app.SetGameHostOption(eGameHostOption_HostCanChangeHunger, 1);
294 app.SetGameHostOption(eGameHostOption_HostCanBeInvisible, 1 );
295
296 param->settings = app.GetGameHostOption( eGameHostOption_All );
297
298 g_NetworkManager.FakeLocalPlayerJoined();
299
300 LoadingInputParams *loadingParams = new LoadingInputParams();
301 loadingParams->func = &CGameNetworkManager::RunNetworkGameThreadProc;
302 loadingParams->lpParam = (LPVOID)param;
303
304 // Reset the autosave time
305 app.SetAutosaveTimerTime();
306
307 C4JThread* thread = new C4JThread(loadingParams->func, loadingParams->lpParam, "RunNetworkGame");
308 thread->Run();
309}
310
311typedef struct
312{
313 eDLCContentType e_DLC_Type;
314 //WCHAR *wchDisplayName;
315 WCHAR *wchProductId;
316 WCHAR *wchBannerName;
317 WCHAR *wchFirstSkin;
318 int iConfig;
319 unsigned int uiSortIndex;
320}
321DLC_DETAILS;
322
323#define MAX_DLC_DETAILS 18
324/*DLC_DETAILS DLCDetailsA[MAX_DLC_DETAILS] =
325{
326 // skin packs
327
328 // Skin Pack Festive
329 { e_DLC_SkinPack,L"Festive Skin Pack",L"6dffc4d6-a2d2-4c8c-9284-c607f77e431a",L"SPF.png",L"dlcskin00000600.png",0,1},
330 // Skin Pack 1
331 { e_DLC_SkinPack,L"Skin Pack 1",L"8ecf0f25-a119-4987-a32b-ee0a5925ad8d",L"SP1.png",L"dlcskin00000000.png",0,2},
332 // Skin Pack 2
333 { e_DLC_SkinPack,L"Skin Pack 2",L"cc59b688-7cfb-4fa0-a76e-84aa55b92cae",L"SP2.png",L"dlcskin00000900.png",0,3},
334 // Skin Pack 6
335 //{ e_DLC_SkinPack,L"0037a29f-876e-4709-8bb8-a388738e6f51","SP6.png","dlcskin00000900.png",0,3},
336 // Skin Pack Battle And Beasts
337 { e_DLC_SkinPack,L"Battle And Beasts",L"eeeb6489-02a3-4c6e-a8c9-2ace2aa1094d",L"SPC.png",L"dlcskin00000800.png",0,4},
338 // Skin Pack Battle And Beasts 2
339 { e_DLC_SkinPack,L"Battle And Beasts 2",L"b858200a-59a8-4e1f-a049-f3e73db2d786",L"SPZ.png",L"dlcskin00001000.png",0,5},
340 // Skin Pack Marvel Avengers
341 { e_DLC_SkinPack,L"Marvel Avengers",L"d59757dd-7757-4c5e-8499-dbe4743baa10",L"SPM.png",L"dlcskin00001700.png",0,6},
342 // Skin Pack Marvel Spider-Man
343 { e_DLC_SkinPack,L"Marvel Spider-Man",L"cdca1bff-13d1-435a-8aee-e7a35002473f",L"SPI.png",L"dlcskin00001800.png",0,7},
344 // Skin Pack Birthday 1
345 { e_DLC_SkinPack,L"Birthday Skin Pack",L"951e8062-3d4e-470c-8177-5eca91bc08b3",L"SPB.png",L"dlcskin00000700.png",0,8},
346 // Skin Pack Birthday 2
347 { e_DLC_SkinPack,L"2nd Birthday Skin Pack",L"c7157788-468d-4ca8-9ecf-5d77a09850fc",L"SPB2.png",L"dlcskin00002200.png",0,9},
348
349 // Texture Packs
350
351 // Plastic Texture Pack
352 { e_DLC_TexturePacks,L"Plastic Texture Pack",L"52ecdcf1-d362-47a1-973b-1eeca0db0ea8",L"TP01.png",L"",2049,1},
353 // Natural Texture Pack
354 { e_DLC_TexturePacks,L"Natural Texture Pack",L"1c56db0c-ff49-4bb1-b372-2122b0e813c1",L"TP02.png",L"",2053,2},
355 // Halloween Texture Pack
356 { e_DLC_TexturePacks,L"Halloween Texture Pack",L"8cb331d1-8fa1-4367-a41a-d4830a80ce67",L"TP03.png",L"",2052,3},
357 // Fantasy Texture Pack
358 { e_DLC_TexturePacks,L"Fantasy Texture Pack",L"375a1df4-5550-415b-b278-20f65b31a7a3",L"TP04.png",L"",2051,4},
359 // City Texture Pack
360 { e_DLC_TexturePacks,L"City Texture Pack",L"ea5c7b40-e04d-4469-9382-8806467ca2c4",L"TP05.png",L"",2054,5},
361 // Candy Texture Pack
362 { e_DLC_TexturePacks,L"Candy Texture Pack",L"94c75e45-0757-4886-916c-ab026ae27ca9",L"TP06.png",L"",2050,6},
363 // Comic Texture Pack
364 //{ e_DLC_TexturePacks,L"Comic Texture Pack",L"3e14cf0f-26eb-40df-897d-7af905456e58",L"TP07.png",L"",2055,7},
365
366 // Mash-up Packs
367
368 // Mass Effect
369 { e_DLC_MashupPacks,L"Mass Effect",L"ead4f3bb-b388-42da-8fa9-f1f91570b5c7",L"MPMA.png",L"dlcskin00001100.png",1024,1},
370 // Skyrim
371 { e_DLC_MashupPacks,L"Skyrim",L"81cc4261-7b63-4e48-af1c-60b9ae099644",L"MPSR.png",L"dlcskin00001400.png",1025,2},
372 // Halo
373 { e_DLC_MashupPacks,L"Halo",L"1e06dafc-ea27-475e-945c-fcee0c455f87",L"MPHA.png",L"dlcskin00001600.png",1026,3},
374};*/
375
376void CConsoleMinecraftApp::InitialiseDLCDetails()
377{
378 for(int i=0;i<18;i++)
379 {
380 //RegisterDLCData(DLCDetailsA[i].e_DLC_Type, DLCDetailsA[i].wchBannerName, DLCDetailsA[i].wchDisplayName, DLCDetailsA[i].wchProductId, DLCDetailsA[i].wchFirstSkin, DLCDetailsA[i].iConfig, DLCDetailsA[i].uiSortIndex);
381 }
382}
383
384bool CConsoleMinecraftApp::UpdateProductId(XCONTENT_DATA &Data)
385{
386 // Do we have a product id for this?
387 DLC_INFO *pDLCInfo=app.GetDLCInfoForProductName(Data.wszDisplayName);
388
389 if(pDLCInfo!=NULL)
390 {
391 app.DebugPrintf("Updating product id for %ls\n",Data.wszDisplayName);
392 swprintf_s(Data.wszProductID, 64,L"%ls",pDLCInfo->wsProductId.c_str());
393 return true;
394 }
395 else
396 {
397 app.DebugPrintf("Couldn't find %ls\n",Data.wszDisplayName);
398 }
399
400 return false;
401}
402
403void CConsoleMinecraftApp::Shutdown()
404{
405 m_bShutdown=true;
406}
407
408bool CConsoleMinecraftApp::getShutdownFlag()
409{
410 return m_bShutdown;
411}
412
413
414// TMS
415bool CConsoleMinecraftApp::TMSPP_ReadBannedList(int iPad,eTMSAction NextAction)
416{
417 app.DebugPrintf("CConsoleMinecraftApp::TMSPP_ReadBannedList\n");
418 eTitleStorageState eResult;
419 bool bSendBanFileRetrievedMsg=false;
420
421 if(GetBanListRead(iPad)==false)
422 {
423 // Attempt to read the ban list
424 // do we have one in our user filelist?
425 //if(StorageManager.TMSPP_InFileList(C4JStorage::eGlobalStorage_TitleUser,iPad,L"BannedList"))
426 {
427 SetBanListRead(iPad,true);
428 ClearBanList(iPad);
429
430 eResult=StorageManager.TMSPP_ReadFile(iPad,C4JStorage::eGlobalStorage_TitleUser,C4JStorage::TMS_FILETYPE_BINARY,L"BannedList",&CConsoleMinecraftApp::Callback_TMSPPReadBannedList,this,NextAction);
431 if(eResult!=eTitleStorage_pending)
432 {
433 // something went wrong
434 app.SetTMSAction(iPad,(eTMSAction)NextAction);
435 bSendBanFileRetrievedMsg=true;
436 }
437 }
438 }
439 else
440 {
441 bSendBanFileRetrievedMsg=true;
442 }
443
444 if(bSendBanFileRetrievedMsg)
445 {
446 ui.HandleTMSBanFileRetrieved(iPad);
447 }
448
449 app.SetTMSAction(iPad,(eTMSAction)NextAction);
450
451 return true;
452}
453
454int CConsoleMinecraftApp::Callback_TMSPPReadBannedList(void *pParam,int iPad, int iUserData, LPVOID lpvData,WCHAR *wchFilename)
455{
456 app.DebugPrintf("CConsoleMinecraftApp::Callback_TMSPPReadBannedList\n");
457 C4JStorage::PTMSPP_FILEDATA pFileData=(C4JStorage::PTMSPP_FILEDATA)lpvData;
458
459 CConsoleMinecraftApp* pClass = (CConsoleMinecraftApp*)pParam;
460
461 if(pFileData)
462 {
463 // put the entries into the vector
464 int iEntries=pFileData->dwSize/sizeof(BANNEDLISTDATA);
465 PBANNEDLISTDATA pData=(PBANNEDLISTDATA)pFileData->pbData;
466
467 for(int i=0;i<iEntries;i++)
468 {
469 pClass->AddLevelToBannedLevelList(iPad,&pData[i], false);
470 }
471 // mark the level as not checked against banned levels - it'll be checked once the level starts
472 app.SetBanListCheck(iPad,false);
473
474 // Xbox One will clear things within the DownloadBlob
475#ifndef _XBOX_ONE
476 delete [] pFileData->pbData;
477 delete [] pFileData;
478#endif
479
480 ui.HandleTMSBanFileRetrieved(iPad);
481 }
482 else
483 {
484 // read problem - set state to idel again
485 StorageManager.TMSPP_ClearTitleStorageState(iPad);
486 }
487
488 // change the state to the next action
489 pClass->SetTMSAction(iPad,(eTMSAction)iUserData);
490
491 return 0;
492}
493
494void CConsoleMinecraftApp::TMSPP_ReadDLCFile(int iPad,eTMSAction NextAction)
495{
496 app.DebugPrintf("CConsoleMinecraftApp::TMSPP_ReadDLCFile\n");
497 bool bRetrievedDLCFile=false;
498 // try reading the DLC.xml file (from TMS global) - only allowed to do this once an hour at the most, but we'll just read once each time the game launches
499 eTitleStorageState eResult;
500 if(m_bRead_TMS_DLCINFO_XML==false)
501 {
502// 4J-PB - we're reading this info from a local file now
503
504 eResult=StorageManager.TMSPP_ReadFile(iPad,C4JStorage::eGlobalStorage_Title,C4JStorage::TMS_FILETYPE_BINARY,L"DLCXbox1.cmp",&CConsoleMinecraftApp::Callback_TMSPPReadDLCFile,this,NextAction);
505 if(eResult!=eTitleStorage_pending)
506 {
507 // something went wrong
508 app.SetTMSAction(iPad,(eTMSAction)NextAction);
509 bRetrievedDLCFile=true;
510 m_bRead_TMS_DLCINFO_XML=true;
511 }
512 }
513 else
514 {
515 bRetrievedDLCFile=true;
516 }
517
518 if(bRetrievedDLCFile)
519 {
520 ui.HandleTMSDLCFileRetrieved(iPad);
521
522 app.SetTMSAction(iPad,(eTMSAction)NextAction);
523 }
524}
525
526void CConsoleMinecraftApp::TMSPP_RetrieveFileList(int iPad,C4JStorage::eGlobalStorage eStorageFacility,eTMSAction NextAction)
527{
528 app.DebugPrintf("CConsoleMinecraftApp::TMSPP_RetrieveFileList\n");
529
530 if(eStorageFacility==C4JStorage::eGlobalStorage_Title)
531 {
532 if(m_bTMSPP_GlobalFileListRead==false)
533 {
534 m_bTMSPP_GlobalFileListRead=true;
535 StorageManager.TMSPP_ReadFileList(iPad,eStorageFacility,&CConsoleMinecraftApp::Callback_TMSPPRetrieveFileList,this,NextAction);
536 }
537 else
538 {
539 SetTMSAction(iPad,NextAction);
540 }
541 }
542 else
543 {
544 if(m_bTMSPP_UserFileListRead==false)
545 {
546 m_bTMSPP_UserFileListRead=true;
547 StorageManager.TMSPP_ReadFileList(iPad,eStorageFacility,&CConsoleMinecraftApp::Callback_TMSPPRetrieveFileList,this,NextAction);
548 }
549 else
550 {
551 SetTMSAction(iPad,NextAction);
552 }
553 }
554}
555
556int CConsoleMinecraftApp::Callback_TMSPPRetrieveFileList(void *pParam,int iPad, int iUserData, LPVOID lpvData, WCHAR *wchFilename)
557{
558 CConsoleMinecraftApp* pClass = (CConsoleMinecraftApp*)pParam;
559 app.DebugPrintf("CConsoleMinecraftApp::Callback_TMSPPRetrieveFileList\n");
560 if(lpvData!=NULL)
561 {
562 vector<C4JStorage::PTMSPP_FILE_DETAILS> *pvTmsFileDetails=(vector<C4JStorage::PTMSPP_FILE_DETAILS> *)lpvData;
563
564 if(pvTmsFileDetails->size()>0)
565 {
566 #ifdef _DEBUG
567 // dump out the file list
568 app.DebugPrintf("TMSPP filecount - %d\nFiles - \n",pvTmsFileDetails->size());
569 int iCount=0;
570 AUTO_VAR(itEnd, pvTmsFileDetails->end());
571 for( AUTO_VAR(it, pvTmsFileDetails->begin()); it != itEnd; it++ )
572 {
573 C4JStorage::PTMSPP_FILE_DETAILS fd = *it;
574 app.DebugPrintf("%2d. %ls (size - %d)\n",iCount++,fd->wchFilename,fd->ulFileSize);
575 }
576
577 #endif
578 }
579 }
580 // change the state to the next action
581 pClass->SetTMSAction(iPad,(eTMSAction)iUserData);
582 return 0;
583}
584
585//#define WRITE_DLCINFO 1
586int CConsoleMinecraftApp::Callback_TMSPPReadDLCFile(void *pParam,int iPad, int iUserData, LPVOID lpvData ,WCHAR *pwchFilename)
587{
588 app.DebugPrintf("CConsoleMinecraftApp::Callback_TMSPPReadDLCFile\n");
589 C4JStorage::PTMSPP_FILEDATA pFileData= (C4JStorage::PTMSPP_FILEDATA)lpvData;
590 CConsoleMinecraftApp* pClass = (CConsoleMinecraftApp*)pParam;
591
592#ifdef WRITE_DLCINFO
593 if(0)
594#else
595 if(pFileData && pFileData->dwSize>0)
596#endif
597 {
598 // the DLC.xml file is now compressed
599
600 unsigned int uiDecompSize=*(unsigned int *)pFileData->pbData;
601 unsigned int uiCompSize=((unsigned int *)pFileData->pbData)[1];
602
603 BYTE *pDecompressedData = new BYTE [uiDecompSize];
604
605 Compression::ECompressionTypes eOriginalCompressionType=Compression::getCompression()->GetDecompressionType();
606 Compression::getCompression()->SetDecompressionType(Compression::eCompressionType_LZXRLE);
607 Compression::getCompression()->Decompress(pDecompressedData,&uiDecompSize,&((unsigned int *)pFileData->pbData)[2],uiCompSize);
608 Compression::getCompression()->SetDecompressionType(eOriginalCompressionType);
609
610 ATG::XMLParser xmlParser;
611 xmlDLCInfoCallback xmlCallback;
612
613 xmlParser.RegisterSAXCallbackInterface( &xmlCallback );
614 xmlParser.ParseXMLBuffer((CHAR *)pDecompressedData,uiDecompSize);
615
616 pClass->m_bRead_TMS_DLCINFO_XML=true;
617
618 delete pDecompressedData;
619
620 // apply the dlc info to the locally installed DLC
621 StorageManager.UpdateDLCProductIDs();
622
623 ui.HandleTMSDLCFileRetrieved(iPad);
624 }
625 else
626 {
627
628 // if there was a read error, reset to idle
629 StorageManager.TMSPP_ClearTitleStorageState(iPad);
630
631#ifdef WRITE_DLCINFO
632 HANDLE file;
633 DWORD dwHigh=0;
634 DWORD dwFileSize;
635
636 // hack for now to upload the file
637 // open the local file
638 file = CreateFile(L"DLCXbox1.cmp", GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
639 if( file == INVALID_HANDLE_VALUE )
640 {
641 DWORD error = GetLastError();
642 app.DebugPrintf("Failed to open DLCXbox1.cmp with error code %d (%x)\n", error, error);
643 __debugbreak();
644 return 0;
645 }
646
647 dwHigh=0;
648 dwFileSize = GetFileSize(file,&dwHigh);
649
650 if(dwFileSize!=0)
651 {
652 DWORD bytesRead;
653
654 PBYTE pbData= new BYTE [dwFileSize];
655
656 ReadFile(file,pbData,dwFileSize,&bytesRead,NULL);
657
658 if(bytesRead==dwFileSize)
659 {
660 //StorageManager.TMSPP_WriteFile(iPad,C4JStorage::eGlobalStorage_TitleUser,C4JStorage::TMS_FILETYPE_BINARY,L"DLCXbox1.cmp",(PBYTE) pbData, dwFileSize,NULL,NULL, 0);
661 StorageManager.TMSPP_WriteFile(iPad,C4JStorage::eGlobalStorage_TitleUser,C4JStorage::TMS_FILETYPE_BINARY,L"TP06.cmp",(PBYTE) pbData, dwFileSize,NULL,NULL, 0);
662 }
663 Sleep(5000);
664 }
665
666 CloseHandle(file);
667
668 /*
669 // now the icon
670 file = CreateFile(L"TP06.png", GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
671 if( file == INVALID_HANDLE_VALUE )
672 {
673 DWORD error = GetLastError();
674 app.DebugPrintf("Failed to open DLCXbox1.cmp with error code %d (%x)\n", error, error);
675 return 0;
676 }
677
678 dwHigh=0;
679 dwFileSize = GetFileSize(file,&dwHigh);
680
681 if(dwFileSize!=0)
682 {
683 DWORD bytesRead;
684
685 PBYTE pbData= new BYTE [dwFileSize];
686
687 ReadFile(file,pbData,dwFileSize,&bytesRead,NULL);
688
689 if(bytesRead==dwFileSize)
690 {
691 StorageManager.TMSPP_WriteFile(iPad,C4JStorage::eGlobalStorage_TitleUser,C4JStorage::TMS_FILETYPE_BINARY,L"TP06.png",(PBYTE) pbData, dwFileSize,NULL,NULL, 0);
692 }
693 Sleep(5000);
694 }
695
696 CloseHandle(file);*/
697#endif
698 }
699
700 // change the state to the next action
701 pClass->SetTMSAction(iPad,(eTMSAction)iUserData);
702
703 return 0;
704}
705
706void CConsoleMinecraftApp::Callback_SaveGameIncomplete(void *pParam, C4JStorage::ESaveIncompleteType saveIncompleteType)
707{
708 CConsoleMinecraftApp* pClass = (CConsoleMinecraftApp*)pParam;
709
710 if ( saveIncompleteType == C4JStorage::ESaveIncomplete_OutOfQuota
711 || saveIncompleteType == C4JStorage::ESaveIncomplete_OutOfLocalStorage )
712 {
713 StorageManager.SetSaveDisabled(true);
714 pClass->EnterSaveNotificationSection();
715
716 int message;
717 if (saveIncompleteType == C4JStorage::ESaveIncomplete_OutOfQuota) message = IDS_SAVE_INCOMPLETE_EXPLANATION_QUOTA;
718 else message = IDS_SAVE_INCOMPLETE_EXPLANATION_LOCAL_STORAGE;
719
720 UINT uiIDA[3] =
721 {
722 IDS_SAVE_INCOMPLETE_RETRY_SAVING,
723 IDS_SAVE_INCOMPLETE_DISABLE_SAVING,
724 IDS_SAVE_INCOMPLETE_DELETE_SAVES
725 };
726
727 if ( ui.RequestMessageBox( IDS_SAVE_INCOMPLETE_TITLE, message, uiIDA,3,0,Callback_SaveGameIncompleteMessageBoxReturned,pClass, app.GetStringTable()) == C4JStorage::EMessage_Busy)
728 {
729 // If this failed to display, continue as if we cancelled. This isn't ideal, but the user should already have had some system notification of being out of memory,
730 // and if we instantly retry then they may not be able to navigate whatever other error is blocking this from appearing
731 Callback_SaveGameIncompleteMessageBoxReturned(pParam, 0, C4JStorage::EMessage_Cancelled);
732 }
733 }
734 else
735 {
736 // 4J-JEV: Unknown error, just cancel the operation.
737 Callback_SaveGameIncompleteMessageBoxReturned(pParam, 0, C4JStorage::EMessage_Cancelled);
738 }
739}
740
741int CConsoleMinecraftApp::Callback_SaveGameIncompleteMessageBoxReturned(void *pParam,int iPad,C4JStorage::EMessageResult result)
742{
743 CConsoleMinecraftApp* pClass = (CConsoleMinecraftApp*)pParam;
744
745 switch(result)
746 {
747 case C4JStorage::EMessage_ResultAccept:
748 pClass->LeaveSaveNotificationSection();
749 StorageManager.SetSaveDisabled(false);
750 StorageManager.ContinueIncompleteOperation();
751 break;
752 case C4JStorage::EMessage_ResultDecline:
753 case C4JStorage::EMessage_Cancelled:
754 pClass->LeaveSaveNotificationSection();
755 // Set the global flag, so that we don't disable saving again once the message box is complete
756 app.SetGameHostOption(eGameHostOption_DisableSaving, 1);
757 StorageManager.CancelIncompleteOperation();
758 break;
759 case C4JStorage::EMessage_ResultThirdOption:
760 ui.NavigateToScene(iPad, eUIScene_InGameSaveManagementMenu, NULL, eUILayer_Error, eUIGroup_Fullscreen);
761 break;
762 }
763 return 0;
764}
765
766void CConsoleMinecraftApp::ReadLocalDLCList(void)
767{
768 char szFile[255];
769 DWORD dwLength;
770 // read the local dlc list
771 File fDLCList(L"CU/DLCXbox1.cmp") ;
772 if(fDLCList.exists())
773 {
774 dwLength = fDLCList.length();
775 byteArray data(dwLength);
776
777 FileInputStream fis(fDLCList);
778 fis.read(data,0,dwLength);
779 fis.close();
780
781 unsigned int uiDecompSize=*(unsigned int *)data.data;
782 unsigned int uiCompSize=((unsigned int *)data.data)[1];
783
784 BYTE *pDecompressedData = new BYTE [uiDecompSize];
785
786 Compression::ECompressionTypes eOriginalCompressionType=Compression::getCompression()->GetDecompressionType();
787 Compression::getCompression()->SetDecompressionType(Compression::eCompressionType_LZXRLE);
788 Compression::getCompression()->Decompress(pDecompressedData,&uiDecompSize,&((unsigned int *)data.data)[2],uiCompSize);
789 Compression::getCompression()->SetDecompressionType(eOriginalCompressionType);
790
791 ATG::XMLParser xmlParser;
792 xmlDLCInfoCallback xmlCallback;
793
794 xmlParser.RegisterSAXCallbackInterface( &xmlCallback );
795 xmlParser.ParseXMLBuffer((CHAR *)pDecompressedData,uiDecompSize);
796
797 delete pDecompressedData;
798 }
799}