the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 431 lines 9.9 kB view raw
1#include "stdafx.h" 2#include "DLCPack.h" 3#include "DLCSkinFile.h" 4#include "DLCCapeFile.h" 5#include "DLCTextureFile.h" 6#include "DLCUIDataFile.h" 7#include "DLCLocalisationFile.h" 8#include "DLCGameRulesFile.h" 9#include "DLCGameRulesHeader.h" 10#include "DLCAudioFile.h" 11#include "DLCColourTableFile.h" 12#include "..\..\..\Minecraft.World\StringHelpers.h" 13 14DLCPack::DLCPack(const wstring &name,DWORD dwLicenseMask) 15{ 16 m_dataPath = L""; 17 m_packName = name; 18 m_dwLicenseMask=dwLicenseMask; 19#ifdef _XBOX_ONE 20 m_wsProductId = L""; 21#else 22 m_ullFullOfferId = 0LL; 23#endif 24 m_isCorrupt = false; 25 m_packId = 0; 26 m_packVersion = 0; 27 m_parentPack = NULL; 28 m_dlcMountIndex = -1; 29#ifdef _XBOX 30 m_dlcDeviceID = XCONTENTDEVICE_ANY; 31#endif 32 33 // This pointer is for all the data used for this pack, so deleting it invalidates ALL of it's children. 34 m_data = NULL; 35} 36 37#ifdef _XBOX_ONE 38DLCPack::DLCPack(const wstring &name,const wstring &productID,DWORD dwLicenseMask) 39{ 40 m_dataPath = L""; 41 m_packName = name; 42 m_dwLicenseMask=dwLicenseMask; 43 m_wsProductId = productID; 44 m_isCorrupt = false; 45 m_packId = 0; 46 m_packVersion = 0; 47 m_parentPack = NULL; 48 m_dlcMountIndex = -1; 49 50 // This pointer is for all the data used for this pack, so deleting it invalidates ALL of it's children. 51 m_data = NULL; 52} 53#endif 54 55DLCPack::~DLCPack() 56{ 57 for(AUTO_VAR(it, m_childPacks.begin()); it != m_childPacks.end(); ++it) 58 { 59 delete *it; 60 } 61 62 for(unsigned int i = 0; i < DLCManager::e_DLCType_Max; ++i) 63 { 64 for(AUTO_VAR(it,m_files[i].begin()); it != m_files[i].end(); ++it) 65 { 66 delete *it; 67 } 68 } 69 70 // This pointer is for all the data used for this pack, so deleting it invalidates ALL of it's children. 71 if(m_data) 72 { 73#ifndef _CONTENT_PACKAGE 74 wprintf(L"Deleting data for DLC pack %ls\n", m_packName.c_str()); 75#endif 76 // For the same reason, don't delete data pointer for any child pack as it just points to a region within the parent pack that has already been freed 77 if( m_parentPack == NULL ) 78 { 79 delete [] m_data; 80 } 81 } 82} 83 84DWORD DLCPack::GetDLCMountIndex() 85{ 86 if(m_parentPack != NULL) 87 { 88 return m_parentPack->GetDLCMountIndex(); 89 } 90 return m_dlcMountIndex; 91} 92 93XCONTENTDEVICEID DLCPack::GetDLCDeviceID() 94{ 95 if(m_parentPack != NULL ) 96 { 97 return m_parentPack->GetDLCDeviceID(); 98 } 99 return m_dlcDeviceID; 100} 101 102void DLCPack::addChildPack(DLCPack *childPack) 103{ 104 int packId = childPack->GetPackId(); 105#ifndef _CONTENT_PACKAGE 106 if(packId < 0 || packId > 15) 107 { 108 __debugbreak(); 109 } 110#endif 111 childPack->SetPackId( (packId<<24) | m_packId ); 112 m_childPacks.push_back(childPack); 113 childPack->setParentPack(this); 114 childPack->m_packName = m_packName + childPack->getName(); 115} 116 117void DLCPack::setParentPack(DLCPack *parentPack) 118{ 119 m_parentPack = parentPack; 120} 121 122void DLCPack::addParameter(DLCManager::EDLCParameterType type, const wstring &value) 123{ 124 switch(type) 125 { 126 case DLCManager::e_DLCParamType_PackId: 127 { 128 DWORD packId = 0; 129 130 std::wstringstream ss; 131 // 4J Stu - numbered using decimal to make it easier for artists/people to number manually 132 ss << std::dec << value.c_str(); 133 ss >> packId; 134 135 SetPackId(packId); 136 } 137 break; 138 case DLCManager::e_DLCParamType_PackVersion: 139 { 140 DWORD version = 0; 141 142 std::wstringstream ss; 143 // 4J Stu - numbered using decimal to make it easier for artists/people to number manually 144 ss << std::dec << value.c_str(); 145 ss >> version; 146 147 SetPackVersion(version); 148 } 149 break; 150 case DLCManager::e_DLCParamType_DisplayName: 151 m_packName = value; 152 break; 153 case DLCManager::e_DLCParamType_DataPath: 154 m_dataPath = value; 155 break; 156 default: 157 m_parameters[(int)type] = value; 158 break; 159 } 160} 161 162bool DLCPack::getParameterAsUInt(DLCManager::EDLCParameterType type, unsigned int &param) 163{ 164 AUTO_VAR(it,m_parameters.find((int)type)); 165 if(it != m_parameters.end()) 166 { 167 switch(type) 168 { 169 case DLCManager::e_DLCParamType_NetherParticleColour: 170 case DLCManager::e_DLCParamType_EnchantmentTextColour: 171 case DLCManager::e_DLCParamType_EnchantmentTextFocusColour: 172 { 173 std::wstringstream ss; 174 ss << std::hex << it->second.c_str(); 175 ss >> param; 176 } 177 break; 178 default: 179 param = _fromString<unsigned int>(it->second); 180 } 181 return true; 182 } 183 return false; 184} 185 186DLCFile *DLCPack::addFile(DLCManager::EDLCType type, const wstring &path) 187{ 188 DLCFile *newFile = NULL; 189 190 switch(type) 191 { 192 case DLCManager::e_DLCType_Skin: 193 { 194 wstring newPath = replaceAll(path, L"\\", L"/"); 195 std::vector<std::wstring> splitPath = stringSplit(newPath,L'/'); 196 wstring strippedPath = splitPath.back(); 197 198 newFile = new DLCSkinFile(strippedPath); 199 200 // check to see if we can get the full offer id using this skin name 201#ifdef _XBOX_ONE 202 app.GetDLCFullOfferIDForSkinID(strippedPath,m_wsProductId); 203#else 204 ULONGLONG ullVal=0LL; 205 206 if(app.GetDLCFullOfferIDForSkinID(strippedPath,&ullVal)) 207 { 208 m_ullFullOfferId=ullVal; 209 } 210#endif 211 } 212 break; 213 case DLCManager::e_DLCType_Cape: 214 { 215 wstring newPath = replaceAll(path, L"\\", L"/"); 216 std::vector<std::wstring> splitPath = stringSplit(newPath,L'/'); 217 wstring strippedPath = splitPath.back(); 218 newFile = new DLCCapeFile(strippedPath); 219 } 220 break; 221 case DLCManager::e_DLCType_Texture: 222 newFile = new DLCTextureFile(path); 223 break; 224 case DLCManager::e_DLCType_UIData: 225 newFile = new DLCUIDataFile(path); 226 break; 227 case DLCManager::e_DLCType_LocalisationData: 228 newFile = new DLCLocalisationFile(path); 229 break; 230 case DLCManager::e_DLCType_GameRules: 231 newFile = new DLCGameRulesFile(path); 232 break; 233 case DLCManager::e_DLCType_Audio: 234 newFile = new DLCAudioFile(path); 235 break; 236 case DLCManager::e_DLCType_ColourTable: 237 newFile = new DLCColourTableFile(path); 238 break; 239 case DLCManager::e_DLCType_GameRulesHeader: 240 newFile = new DLCGameRulesHeader(path); 241 break; 242 }; 243 244 if( newFile != NULL ) 245 { 246 m_files[newFile->getType()].push_back(newFile); 247 } 248 249 return newFile; 250} 251 252// MGH - added this comp func, as the embedded func in find_if was confusing the PS3 compiler 253static const wstring *g_pathCmpString = NULL; 254static bool pathCmp(DLCFile *val) 255{ 256 return (g_pathCmpString->compare(val->getPath()) == 0); 257} 258 259bool DLCPack::doesPackContainFile(DLCManager::EDLCType type, const wstring &path) 260{ 261 bool hasFile = false; 262 if(type == DLCManager::e_DLCType_All) 263 { 264 for(DLCManager::EDLCType currentType = (DLCManager::EDLCType)0; currentType < DLCManager::e_DLCType_Max; currentType = (DLCManager::EDLCType)(currentType + 1)) 265 { 266 hasFile = doesPackContainFile(currentType,path); 267 if(hasFile) break; 268 } 269 } 270 else 271 { 272 g_pathCmpString = &path; 273 AUTO_VAR(it, find_if( m_files[type].begin(), m_files[type].end(), pathCmp )); 274 hasFile = it != m_files[type].end(); 275 if(!hasFile && m_parentPack ) 276 { 277 hasFile = m_parentPack->doesPackContainFile(type,path); 278 } 279 } 280 return hasFile; 281} 282 283DLCFile *DLCPack::getFile(DLCManager::EDLCType type, DWORD index) 284{ 285 DLCFile *file = NULL; 286 if(type == DLCManager::e_DLCType_All) 287 { 288 for(DLCManager::EDLCType currentType = (DLCManager::EDLCType)0; currentType < DLCManager::e_DLCType_Max; currentType = (DLCManager::EDLCType)(currentType + 1)) 289 { 290 file = getFile(currentType,index); 291 if(file != NULL) break; 292 } 293 } 294 else 295 { 296 if(m_files[type].size() > index) file = m_files[type][index]; 297 if(!file && m_parentPack) 298 { 299 file = m_parentPack->getFile(type,index); 300 } 301 } 302 return file; 303} 304 305DLCFile *DLCPack::getFile(DLCManager::EDLCType type, const wstring &path) 306{ 307 DLCFile *file = NULL; 308 if(type == DLCManager::e_DLCType_All) 309 { 310 for(DLCManager::EDLCType currentType = (DLCManager::EDLCType)0; currentType < DLCManager::e_DLCType_Max; currentType = (DLCManager::EDLCType)(currentType + 1)) 311 { 312 file = getFile(currentType,path); 313 if(file != NULL) break; 314 } 315 } 316 else 317 { 318 g_pathCmpString = &path; 319 AUTO_VAR(it, find_if( m_files[type].begin(), m_files[type].end(), pathCmp )); 320 321 if(it == m_files[type].end()) 322 { 323 // Not found 324 file = NULL; 325 } 326 else 327 { 328 file = *it; 329 } 330 if(!file && m_parentPack) 331 { 332 file = m_parentPack->getFile(type,path); 333 } 334 } 335 return file; 336} 337 338DWORD DLCPack::getDLCItemsCount(DLCManager::EDLCType type /*= DLCManager::e_DLCType_All*/) 339{ 340 DWORD count = 0; 341 342 switch(type) 343 { 344 case DLCManager::e_DLCType_All: 345 for(int i = 0; i < DLCManager::e_DLCType_Max; ++i) 346 { 347 count += getDLCItemsCount((DLCManager::EDLCType)i); 348 } 349 break; 350 default: 351 count = (DWORD)m_files[(int)type].size(); 352 break; 353 }; 354 return count; 355}; 356 357DWORD DLCPack::getFileIndexAt(DLCManager::EDLCType type, const wstring &path, bool &found) 358{ 359 if(type == DLCManager::e_DLCType_All) 360 { 361 app.DebugPrintf("Unimplemented\n"); 362#ifndef __CONTENT_PACKAGE 363 __debugbreak(); 364#endif 365 return 0; 366 } 367 368 DWORD foundIndex = 0; 369 found = false; 370 DWORD index = 0; 371 for(AUTO_VAR(it, m_files[type].begin()); it != m_files[type].end(); ++it) 372 { 373 if(path.compare((*it)->getPath()) == 0) 374 { 375 foundIndex = index; 376 found = true; 377 break; 378 } 379 ++index; 380 } 381 382 return foundIndex; 383} 384 385bool DLCPack::hasPurchasedFile(DLCManager::EDLCType type, const wstring &path) 386{ 387 // Patch all DLC to be "purchased" 388 return true; 389 390 /*if(type == DLCManager::e_DLCType_All) 391 { 392 app.DebugPrintf("Unimplemented\n"); 393#ifndef _CONTENT_PACKAGE 394 __debugbreak(); 395#endif 396 return false; 397 } 398#ifndef _CONTENT_PACKAGE 399 if( app.GetGameSettingsDebugMask(ProfileManager.GetPrimaryPad())&(1L<<eDebugSetting_UnlockAllDLC) ) 400 { 401 return true; 402 } 403 else 404#endif 405 if ( m_dwLicenseMask == 0 ) 406 { 407 //not purchased. 408 return false; 409 } 410 else 411 { 412 //purchased 413 return true; 414 }*/ 415} 416 417void DLCPack::UpdateLanguage() 418{ 419 // find the language file 420 DLCManager::e_DLCType_LocalisationData; 421 DLCFile *file = NULL; 422 423 if(m_files[DLCManager::e_DLCType_LocalisationData].size() > 0) 424 { 425 file = m_files[DLCManager::e_DLCType_LocalisationData][0]; 426 DLCLocalisationFile *localisationFile = (DLCLocalisationFile *)getFile(DLCManager::e_DLCType_LocalisationData, L"languages.loc"); 427 StringTable *strTable = localisationFile->getStringTable(); 428 strTable->ReloadStringTable(); 429 } 430 431}