the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 464 lines 12 kB view raw
1#include "stdafx.h" 2#include "TexturePackRepository.h" 3#include "DefaultTexturePack.h" 4#include "FileTexturePack.h" 5#include "FolderTexturePack.h" 6#include "DLCTexturePack.h" 7#include "Options.h" 8#include "..\Minecraft.World\File.h" 9#include "..\Minecraft.World\StringHelpers.h" 10#include "Minimap.h" 11 12TexturePack *TexturePackRepository::DEFAULT_TEXTURE_PACK = NULL; 13 14TexturePackRepository::TexturePackRepository(File workingDirectory, Minecraft *minecraft) 15{ 16 if(!DEFAULT_TEXTURE_PACK) DEFAULT_TEXTURE_PACK = new DefaultTexturePack(); 17 18 // 4J - added 19 usingWeb = false; 20 selected = NULL; 21 texturePacks = new vector<TexturePack *>; 22 23 this->minecraft = minecraft; 24 25 texturePacks->push_back(DEFAULT_TEXTURE_PACK); 26 cacheById[DEFAULT_TEXTURE_PACK->getId()] = DEFAULT_TEXTURE_PACK; 27 selected = DEFAULT_TEXTURE_PACK; 28 29 DEFAULT_TEXTURE_PACK->loadColourTable(); 30 31 m_dummyTexturePack = NULL; 32 m_dummyDLCTexturePack = NULL; 33 lastSelected = NULL; 34 35 updateList(); 36} 37 38void TexturePackRepository::addDebugPacks() 39{ 40#ifndef _CONTENT_PACKAGE 41 //File *file = new File(L"DummyTexturePack"); // Path to the test texture pack 42 //m_dummyTexturePack = new FolderTexturePack(FOLDER_TEST_TEXTURE_PACK_ID, L"FolderTestPack", file, DEFAULT_TEXTURE_PACK); 43 //texturePacks->push_back(m_dummyTexturePack); 44 //cacheById[m_dummyTexturePack->getId()] = m_dummyTexturePack; 45 46#ifdef _XBOX 47 File packedTestFile(L"GAME:\\DummyTexturePack\\TexturePack.pck"); 48 if(packedTestFile.exists()) 49 { 50 DLCPack *pack = app.m_dlcManager.getPack(L"DLCTestPack"); 51 52 if( pack != NULL && pack->IsCorrupt() ) 53 { 54 app.m_dlcManager.removePack(pack); 55 pack = NULL; 56 } 57 58 if(pack == NULL) 59 { 60 wprintf(L"Pack \"%ls\" is not installed, so adding it\n", L"DLCTestPack"); 61 pack = new DLCPack(L"DLCTestPack",0xffffffff); 62 DWORD dwFilesProcessed = 0; 63 if( app.m_dlcManager.readDLCDataFile(dwFilesProcessed, "GAME:\\DummyTexturePack\\TexturePack.pck",pack)) 64 { 65 // 4J Stu - Don't need to do this, as the readDLCDataFile now adds texture packs 66 //m_dummyDLCTexturePack = addTexturePackFromDLC(pack, DLC_TEST_TEXTURE_PACK_ID); //new DLCTexturePack(0xFFFFFFFE, L"DLCTestPack", pack, DEFAULT_TEXTURE_PACK); 67 app.m_dlcManager.addPack(pack); 68 } 69 else 70 { 71 delete pack; 72 } 73 } 74 } 75 76#endif // _XBOX 77#endif // _CONTENT_PACKAGE 78} 79 80void TexturePackRepository::createWorkingDirecoryUnlessExists() 81{ 82 // 4J Unused 83#if 0 84 if (!workDir.isDirectory()) { 85 workDir.delete(); 86 workDir.mkdirs(); 87 } 88 89 if (!multiplayerDir.isDirectory()) { 90 multiplayerDir.delete(); 91 multiplayerDir.mkdirs(); 92 } 93#endif 94} 95 96bool TexturePackRepository::selectSkin(TexturePack *skin) 97{ 98 if (skin==selected) return false; 99 100 lastSelected = selected; 101 usingWeb = false; 102 selected = skin; 103 //minecraft->options->skin = skin->getName(); 104 //minecraft->options->save(); 105 return true; 106} 107 108void TexturePackRepository::selectWebSkin(const wstring &url) 109{ 110 app.DebugPrintf("TexturePackRepository::selectWebSkin is not implemented\n"); 111#if 0 112 String filename = url.substring(url.lastIndexOf("/") + 1); 113 if (filename.contains("?")) filename = filename.substring(0, filename.indexOf("?")); 114 if (!filename.endsWith(".zip")) return; 115 File file = new File(multiplayerDir, filename); 116 downloadWebSkin(url, file); 117#endif 118} 119 120void TexturePackRepository::downloadWebSkin(const wstring &url, File file) 121{ 122 app.DebugPrintf("TexturePackRepository::selectWebSkin is not implemented\n"); 123#if 0 124 Map<String, String> headers = new HashMap<String, String>(); 125 final ProgressScreen listener = new ProgressScreen(); 126 headers.put("X-Minecraft-Username", minecraft.user.name); 127 headers.put("X-Minecraft-Version", SharedConstants.VERSION_STRING); 128 headers.put("X-Minecraft-Supported-Resolutions", "16"); 129 usingWeb = true; 130 131 minecraft.setScreen(listener); 132 133 HttpUtil.downloadTo(file, url, new HttpUtil.DownloadSuccessRunnable() { 134 public void onDownloadSuccess(File file) { 135 if (!usingWeb) return; 136 137 selected = new FileTexturePack(getIdOrNull(file), file, DEFAULT_TEXTURE_PACK); 138 minecraft.delayTextureReload(); 139 } 140 }, headers, MAX_WEB_FILESIZE, listener); 141#endif 142} 143 144bool TexturePackRepository::isUsingWebSkin() 145{ 146 return usingWeb; 147} 148 149void TexturePackRepository::resetWebSkin() 150{ 151 usingWeb = false; 152 updateList(); 153 minecraft->delayTextureReload(); 154} 155 156void TexturePackRepository::updateList() 157{ 158 // 4J Stu - We don't ever want to completely refresh the lists, we keep them up-to-date as we go 159#if 0 160 vector<TexturePack *> *currentPacks = new vector<TexturePack *>; 161 currentPacks->push_back(DEFAULT_TEXTURE_PACK); 162 cacheById[DEFAULT_TEXTURE_PACK->getId()] = DEFAULT_TEXTURE_PACK; 163#ifndef _CONTENT_PACKAGE 164 currentPacks->push_back(m_dummyTexturePack); 165 cacheById[m_dummyTexturePack->getId()] = m_dummyTexturePack; 166 167 if(m_dummyDLCTexturePack != NULL) 168 { 169 currentPacks->push_back(m_dummyDLCTexturePack); 170 cacheById[m_dummyDLCTexturePack->getId()] = m_dummyDLCTexturePack; 171 } 172 173 //selected = m_dummyTexturePack; 174#endif 175 selected = DEFAULT_TEXTURE_PACK; 176 177 178 // 4J Unused 179 for (File file : getWorkDirContents()) 180 { 181 final String id = getIdOrNull(file); 182 if (id == null) continue; 183 184 TexturePack pack = cacheById.get(id); 185 if (pack == null) { 186 pack = file.isDirectory() ? new FolderTexturePack(id, file, DEFAULT_TEXTURE_PACK) : new FileTexturePack(id, file, DEFAULT_TEXTURE_PACK); 187 cacheById.put(id, pack); 188 } 189 190 if (pack.getName().equals(minecraft.options.skin)) { 191 selected = pack; 192 } 193 currentPacks.add(pack); 194 } 195 196 // 4J - was texturePacks.removeAll(currentPacks); 197 AUTO_VAR(itEnd, currentPacks->end()); 198 for( vector<TexturePack *>::iterator it1 = currentPacks->begin(); it1 != itEnd; it1++ ) 199 { 200 for( vector<TexturePack *>::iterator it2 = texturePacks->begin(); it2 != texturePacks->end(); it2++ ) 201 { 202 if( *it1 == *it2 ) 203 { 204 it2 = texturePacks->erase(it2); 205 } 206 } 207 } 208 209 itEnd = texturePacks->end(); 210 for( vector<TexturePack *>::iterator it = texturePacks->begin(); it != itEnd; it++ ) 211 { 212 TexturePack *pack = *it; 213 pack->unload(minecraft->textures); 214 cacheById.erase(pack->getId()); 215 } 216 217 delete texturePacks; 218 texturePacks = currentPacks; 219#endif 220} 221 222wstring TexturePackRepository::getIdOrNull(File file) 223{ 224 app.DebugPrintf("TexturePackRepository::getIdOrNull is not implemented\n"); 225#if 0 226 if (file.isFile() && file.getName().toLowerCase().endsWith(".zip")) { 227 return file.getName() + ":" + file.length() + ":" + file.lastModified(); 228 } else if (file.isDirectory() && new File(file, "pack.txt").exists()) { 229 return file.getName() + ":folder:" + file.lastModified(); 230 } 231 232 return NULL; 233#endif 234 return L""; 235} 236 237vector<File> TexturePackRepository::getWorkDirContents() 238{ 239 app.DebugPrintf("TexturePackRepository::getWorkDirContents is not implemented\n"); 240#if 0 241 if (workDir.exists() && workDir.isDirectory()) { 242 return Arrays.asList(workDir.listFiles()); 243 } 244 245 return Collections.emptyList(); 246#endif 247 return vector<File>(); 248} 249 250vector<TexturePack *> *TexturePackRepository::getAll() 251{ 252 // 4J - note that original constucted a copy of texturePacks here 253 return texturePacks; 254} 255 256TexturePack *TexturePackRepository::getSelected() 257{ 258 if(selected->hasData()) return selected; 259 else return DEFAULT_TEXTURE_PACK; 260} 261 262bool TexturePackRepository::shouldPromptForWebSkin() 263{ 264 app.DebugPrintf("TexturePackRepository::shouldPromptForWebSkin is not implemented\n"); 265#if 0 266 if (!minecraft.options.serverTextures) return false; 267 ServerData data = minecraft.getCurrentServer(); 268 269 if (data == null) { 270 return true; 271 } else { 272 return data.promptOnTextures(); 273 } 274#endif 275 return false; 276} 277 278bool TexturePackRepository::canUseWebSkin() 279{ 280 app.DebugPrintf("TexturePackRepository::canUseWebSkin is not implemented\n"); 281#if 0 282 if (!minecraft.options.serverTextures) return false; 283 ServerData data = minecraft.getCurrentServer(); 284 285 if (data == null) { 286 return false; 287 } else { 288 return data.allowTextures(); 289 } 290#endif 291 return false; 292} 293 294vector< pair<DWORD,wstring> > *TexturePackRepository::getTexturePackIdNames() 295{ 296 vector< pair<DWORD,wstring> > *packList = new vector< pair<DWORD,wstring> >(); 297 298 for(AUTO_VAR(it,texturePacks->begin()); it != texturePacks->end(); ++it) 299 { 300 TexturePack *pack = *it; 301 packList->push_back( pair<DWORD,wstring>(pack->getId(),pack->getName()) ); 302 } 303 return packList; 304} 305 306bool TexturePackRepository::selectTexturePackById(DWORD id) 307{ 308 bool bDidSelect = false; 309 310 //4J-PB - add in a store of the texture pack required, so that join from invite games 311 // (where they don't have the texture pack) can check this when the texture pack is installed 312 app.SetRequiredTexturePackID(id); 313 314 AUTO_VAR(it, cacheById.find(id)); 315 if(it != cacheById.end()) 316 { 317 TexturePack *newPack = it->second; 318 if(newPack != selected) 319 { 320 selectSkin(newPack); 321 322 if(newPack->hasData()) 323 { 324 app.SetAction(ProfileManager.GetPrimaryPad(), eAppAction_ReloadTexturePack); 325 } 326 else 327 { 328 newPack->loadData(); 329 } 330 //Minecraft *pMinecraft = Minecraft::GetInstance(); 331 //pMinecraft->textures->reloadAll(); 332 } 333 else 334 { 335 app.DebugPrintf("TexturePack with id %d is already selected\n",id); 336 } 337 bDidSelect = true; 338 } 339 else 340 { 341 app.DebugPrintf("Failed to select texture pack %d as it is not in the list\n", id); 342#ifndef _CONTENT_PACKAGE 343 // TODO - 4J Stu: We should report this to the player in some way 344 //__debugbreak(); 345#endif 346 // Fail safely 347 if( selectSkin( DEFAULT_TEXTURE_PACK ) ) 348 { 349 app.SetAction(ProfileManager.GetPrimaryPad(), eAppAction_ReloadTexturePack); 350 } 351 } 352 return bDidSelect; 353} 354 355TexturePack *TexturePackRepository::getTexturePackById(DWORD id) 356{ 357 AUTO_VAR(it, cacheById.find(id)); 358 if(it != cacheById.end()) 359 { 360 return it->second; 361 } 362 363 return NULL; 364} 365 366TexturePack *TexturePackRepository::addTexturePackFromDLC(DLCPack *dlcPack, DWORD id) 367{ 368 TexturePack *newPack = NULL; 369 // 4J-PB - The City texture pack went out with a child id for the texture pack of 1 instead of zero 370 // we need to mask off the child id here to deal with this 371 DWORD dwParentID=id&0xFFFFFF; // child id is <<24 and Or'd with parent 372 373 if(dlcPack != NULL) 374 { 375 newPack = new DLCTexturePack(dwParentID, dlcPack, DEFAULT_TEXTURE_PACK); 376 texturePacks->push_back(newPack); 377 cacheById[dwParentID] = newPack; 378 379#ifndef _CONTENT_PACKAGE 380 if(dlcPack->hasPurchasedFile(DLCManager::e_DLCType_TexturePack,L"")) 381 { 382 wprintf(L"Added new FULL DLCTexturePack: %ls - id=%d\n", dlcPack->getName().c_str(),dwParentID ); 383 } 384 else 385 { 386 wprintf(L"Added new TRIAL DLCTexturePack: %ls - id=%d\n", dlcPack->getName().c_str(),dwParentID ); 387 } 388#endif 389 } 390 return newPack; 391} 392 393void TexturePackRepository::clearInvalidTexturePacks() 394{ 395 for(AUTO_VAR(it, m_texturePacksToDelete.begin()); it != m_texturePacksToDelete.end(); ++it) 396 { 397 delete *it; 398 } 399} 400 401void TexturePackRepository::removeTexturePackById(DWORD id) 402{ 403 AUTO_VAR(it, cacheById.find(id)); 404 if(it != cacheById.end()) 405 { 406 TexturePack *oldPack = it->second; 407 408 AUTO_VAR(it2, find(texturePacks->begin(), texturePacks->end(),oldPack) ); 409 if(it2 != texturePacks->end()) 410 { 411 texturePacks->erase(it2); 412 if(lastSelected == oldPack) 413 { 414 lastSelected = NULL; 415 } 416 } 417 m_texturePacksToDelete.push_back(oldPack); 418 } 419} 420 421void TexturePackRepository::updateUI() 422{ 423 if(lastSelected != NULL && lastSelected != selected) 424 { 425 lastSelected->unloadUI(); 426 selected->loadUI(); 427 Minimap::reloadColours(); 428 ui.StartReloadSkinThread(); 429 lastSelected = NULL; 430 } 431} 432 433bool TexturePackRepository::needsUIUpdate() 434{ 435 return lastSelected != NULL && lastSelected != selected; 436} 437 438unsigned int TexturePackRepository::getTexturePackCount() 439{ 440 return texturePacks->size(); 441} 442 443TexturePack *TexturePackRepository::getTexturePackByIndex(unsigned int index) 444{ 445 TexturePack *pack = NULL; 446 if(index < texturePacks->size()) 447 { 448 pack = texturePacks->at(index); 449 } 450 return pack; 451} 452 453unsigned int TexturePackRepository::getTexturePackIndex(unsigned int id) 454{ 455 int currentIndex = 0; 456 for(AUTO_VAR(it,texturePacks->begin()); it != texturePacks->end(); ++it) 457 { 458 TexturePack *pack = *it; 459 if(pack->getId() == id) break; 460 ++currentIndex; 461 } 462 if(currentIndex >= texturePacks->size()) currentIndex = 0; 463 return currentIndex; 464}