the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 410 lines 10 kB view raw
1#include "stdafx.h" 2#include "Textures.h" 3#include "AbstractTexturePack.h" 4#include "..\Minecraft.World\InputOutputStream.h" 5#include "..\Minecraft.World\StringHelpers.h" 6 7AbstractTexturePack::AbstractTexturePack(DWORD id, File *file, const wstring &name, TexturePack *fallback) : id(id), name(name) 8{ 9 // 4J init 10 textureId = -1; 11 m_colourTable = NULL; 12 13 14 this->file = file; 15 this->fallback = fallback; 16 17 m_iconData = NULL; 18 m_iconSize = 0; 19 20 m_comparisonData = NULL; 21 m_comparisonSize = 0; 22 23 // 4J Stu - These calls need to be in the most derived version of the class 24 //loadIcon(); 25 //loadDescription(); 26} 27 28wstring AbstractTexturePack::trim(wstring line) 29{ 30 if (!line.empty() && line.length() > 34) 31 { 32 line = line.substr(0, 34); 33 } 34 return line; 35} 36 37void AbstractTexturePack::loadIcon() 38{ 39#ifdef _XBOX 40 // 4J Stu - Temporary only 41 const DWORD LOCATOR_SIZE = 256; // Use this to allocate space to hold a ResourceLocator string 42 WCHAR szResourceLocator[ LOCATOR_SIZE ]; 43 44 const ULONG_PTR c_ModuleHandle = (ULONG_PTR)GetModuleHandle(NULL); 45 swprintf(szResourceLocator, LOCATOR_SIZE ,L"section://%X,%ls#%ls",c_ModuleHandle,L"media", L"media/Graphics/TexturePackIcon.png"); 46 47 UINT size = 0; 48 HRESULT hr = XuiResourceLoadAllNoLoc(szResourceLocator, &m_iconData, &size); 49 m_iconSize = size; 50#endif 51} 52 53void AbstractTexturePack::loadComparison() 54{ 55#ifdef _XBOX 56 // 4J Stu - Temporary only 57 const DWORD LOCATOR_SIZE = 256; // Use this to allocate space to hold a ResourceLocator string 58 WCHAR szResourceLocator[ LOCATOR_SIZE ]; 59 60 const ULONG_PTR c_ModuleHandle = (ULONG_PTR)GetModuleHandle(NULL); 61 swprintf(szResourceLocator, LOCATOR_SIZE ,L"section://%X,%ls#%ls",c_ModuleHandle,L"media", L"media/Graphics/DefaultPack_Comparison.png"); 62 63 UINT size = 0; 64 HRESULT hr = XuiResourceLoadAllNoLoc(szResourceLocator, &m_comparisonData, &size); 65 m_comparisonSize = size; 66#endif 67} 68 69void AbstractTexturePack::loadDescription() 70{ 71 // 4J Unused currently 72#if 0 73 InputStream *inputStream = NULL; 74 BufferedReader *br = NULL; 75 //try { 76 inputStream = getResourceImplementation(L"/pack.txt"); 77 br = new BufferedReader(new InputStreamReader(inputStream)); 78 desc1 = trim(br->readLine()); 79 desc2 = trim(br->readLine()); 80 //} catch (IOException ignored) { 81 //} finally { 82 // TODO [EB]: use IOUtils.closeSilently() 83 // try { 84 if (br != NULL) 85 { 86 br->close(); 87 delete br; 88 } 89 if (inputStream != NULL) 90 { 91 inputStream->close(); 92 delete inputStream; 93 } 94 // } catch (IOException ignored) { 95 // } 96 //} 97#endif 98} 99 100void AbstractTexturePack::loadName() 101{ 102} 103 104InputStream *AbstractTexturePack::getResource(const wstring &name, bool allowFallback) //throws IOException 105{ 106 app.DebugPrintf("texture - %ls\n",name.c_str()); 107 InputStream *is = getResourceImplementation(name); 108 if (is == NULL && fallback != NULL && allowFallback) 109 { 110 is = fallback->getResource(name, true); 111 } 112 113 return is; 114} 115 116// 4J Currently removed due to override in TexturePack class 117//InputStream *AbstractTexturePack::getResource(const wstring &name) //throws IOException 118//{ 119// return getResource(name, true); 120//} 121 122void AbstractTexturePack::unload(Textures *textures) 123{ 124 if (iconImage != NULL && textureId != -1) 125 { 126 textures->releaseTexture(textureId); 127 } 128} 129 130void AbstractTexturePack::load(Textures *textures) 131{ 132 if (iconImage != NULL) 133 { 134 if (textureId == -1) 135 { 136 textureId = textures->getTexture(iconImage); 137 } 138 glBindTexture(GL_TEXTURE_2D, textureId); 139 textures->clearLastBoundId(); 140 } 141 else 142 { 143 // 4J Stu - Don't do this 144 //textures->bindTexture(L"/gui/unknown_pack.png"); 145 } 146} 147 148bool AbstractTexturePack::hasFile(const wstring &name, bool allowFallback) 149{ 150 bool hasFile = this->hasFile(name); 151 152 return !hasFile && (allowFallback && fallback != NULL) ? fallback->hasFile(name, allowFallback) : hasFile; 153} 154 155DWORD AbstractTexturePack::getId() 156{ 157 return id; 158} 159 160wstring AbstractTexturePack::getName() 161{ 162 return texname; 163} 164 165wstring AbstractTexturePack::getWorldName() 166{ 167 return m_wsWorldName; 168} 169 170wstring AbstractTexturePack::getDesc1() 171{ 172 return desc1; 173} 174 175wstring AbstractTexturePack::getDesc2() 176{ 177 return desc2; 178} 179 180wstring AbstractTexturePack::getAnimationString(const wstring &textureName, const wstring &path, bool allowFallback) 181{ 182 return getAnimationString(textureName, path); 183} 184 185wstring AbstractTexturePack::getAnimationString(const wstring &textureName, const wstring &path) 186{ 187 wstring animationDefinitionFile = textureName + L".txt"; 188 189 bool requiresFallback = !hasFile(L"\\" + textureName + L".png", false); 190 191 wstring result = L""; 192 193 InputStream *fileStream = getResource(L"\\" + path + animationDefinitionFile, requiresFallback); 194 195 if(fileStream) 196 { 197 //Minecraft::getInstance()->getLogger().info("Found animation info for: " + animationDefinitionFile); 198#ifndef _CONTENT_PACKAGE 199 app.DebugPrintf("Found animation info for: %ls\n", animationDefinitionFile.c_str() ); 200#endif 201 InputStreamReader isr(fileStream); 202 BufferedReader br(&isr); 203 204 205 wstring line = br.readLine(); 206 while (!line.empty()) 207 { 208 line = trimString(line); 209 if (line.length() > 0) 210 { 211 result.append(L","); 212 result.append(line); 213 } 214 line = br.readLine(); 215 } 216 delete fileStream; 217 } 218 219 return result; 220} 221 222BufferedImage *AbstractTexturePack::getImageResource(const wstring& File, bool filenameHasExtension /*= false*/, bool bTitleUpdateTexture /*=false*/, const wstring &drive /*=L""*/) 223{ 224 const char *pchTexture=wstringtofilename(File); 225 app.DebugPrintf("AbstractTexturePack::getImageResource - %s, drive is %s\n",pchTexture, wstringtofilename(drive)); 226 227 return new BufferedImage(TexturePack::getResource(L"/" + File),filenameHasExtension,bTitleUpdateTexture,drive); 228} 229 230void AbstractTexturePack::loadDefaultUI() 231{ 232#ifdef _XBOX 233 // load from the .xzp file 234 const ULONG_PTR c_ModuleHandle = (ULONG_PTR)GetModuleHandle(NULL); 235 236 // Load new skin 237 const DWORD LOCATOR_SIZE = 256; // Use this to allocate space to hold a ResourceLocator string 238 WCHAR szResourceLocator[ LOCATOR_SIZE ]; 239 240 swprintf(szResourceLocator, LOCATOR_SIZE,L"section://%X,%ls#%ls",c_ModuleHandle,L"media", L"media/skin_Minecraft.xur"); 241 242 XuiFreeVisuals(L""); 243 app.LoadSkin(szResourceLocator,NULL);//L"TexturePack"); 244 //CXuiSceneBase::GetInstance()->SetVisualPrefix(L"TexturePack"); 245 CXuiSceneBase::GetInstance()->SkinChanged(CXuiSceneBase::GetInstance()->m_hObj); 246#else 247 ui.ReloadSkin(); 248#endif 249} 250 251void AbstractTexturePack::loadColourTable() 252{ 253 loadDefaultColourTable(); 254 loadDefaultHTMLColourTable(); 255} 256 257void AbstractTexturePack::loadDefaultColourTable() 258{ 259 // Load the file 260#ifdef __PS3__ 261 // need to check if it's a BD build, so pass in the name 262 File coloursFile(AbstractTexturePack::getPath(true,app.GetBootedFromDiscPatch()?"colours.col":NULL).append(L"res/colours.col")); 263 264#else 265 File coloursFile(AbstractTexturePack::getPath(true).append(L"res/colours.col")); 266#endif 267 268 269 if(coloursFile.exists()) 270 { 271 DWORD dwLength = coloursFile.length(); 272 byteArray data(dwLength); 273 274 FileInputStream fis(coloursFile); 275 fis.read(data,0,dwLength); 276 fis.close(); 277 if(m_colourTable != NULL) delete m_colourTable; 278 m_colourTable = new ColourTable(data.data, dwLength); 279 280 delete [] data.data; 281 } 282 else 283 { 284 app.DebugPrintf("Failed to load the default colours table\n"); 285 app.FatalLoadError(); 286 } 287} 288 289void AbstractTexturePack::loadDefaultHTMLColourTable() 290{ 291#ifdef _XBOX 292 // load from the .xzp file 293 const ULONG_PTR c_ModuleHandle = (ULONG_PTR)GetModuleHandle(NULL); 294 295 const DWORD LOCATOR_SIZE = 256; // Use this to allocate space to hold a ResourceLocator string 296 WCHAR szResourceLocator[ LOCATOR_SIZE ]; 297 298 // Try and load the HTMLColours.col based off the common XML first, before the deprecated xuiscene_colourtable 299 wsprintfW(szResourceLocator,L"section://%X,%s#%s",c_ModuleHandle,L"media", L"media/HTMLColours.col"); 300 BYTE *data; 301 UINT dataLength; 302 if(XuiResourceLoadAll(szResourceLocator, &data, &dataLength) == S_OK) 303 { 304 m_colourTable->loadColoursFromData(data,dataLength); 305 306 XuiFree(data); 307 } 308 else 309 { 310 wsprintfW(szResourceLocator,L"section://%X,%s#%s",c_ModuleHandle,L"media", L"media/"); 311 HXUIOBJ hScene; 312 HRESULT hr = XuiSceneCreate(szResourceLocator,L"xuiscene_colourtable.xur", NULL, &hScene); 313 314 if(HRESULT_SUCCEEDED(hr)) 315 { 316 loadHTMLColourTableFromXuiScene(hScene); 317 } 318 } 319#else 320 if(app.hasArchiveFile(L"HTMLColours.col")) 321 { 322 byteArray textColours = app.getArchiveFile(L"HTMLColours.col"); 323 m_colourTable->loadColoursFromData(textColours.data,textColours.length); 324 325 delete [] textColours.data; 326 } 327#endif 328} 329 330#ifdef _XBOX 331void AbstractTexturePack::loadHTMLColourTableFromXuiScene(HXUIOBJ hObj) 332{ 333 HXUIOBJ child; 334 HRESULT hr = XuiElementGetFirstChild(hObj, &child); 335 336 while(HRESULT_SUCCEEDED(hr) && child != NULL) 337 { 338 LPCWSTR childName; 339 XuiElementGetId(child,&childName); 340 m_colourTable->setColour(childName,XuiTextElementGetText(child)); 341 342 //eMinecraftTextColours colourIndex = eTextColor_NONE; 343 //for(int i = 0; i < (int)eTextColor_MAX; i++) 344 //{ 345 // if(wcscmp(HTMLColourTableElements[i],childName)==0) 346 // { 347 // colourIndex = (eMinecraftTextColours)i; 348 // break; 349 // } 350 //} 351 352 //LPCWSTR stringValue = XuiTextElementGetText(child); 353 354 //m_htmlColourTable[colourIndex] = XuiTextElementGetText(child); 355 356 hr = XuiElementGetNext(child, &child); 357 } 358} 359#endif 360 361void AbstractTexturePack::loadUI() 362{ 363 loadColourTable(); 364 365#ifdef _XBOX 366 CXuiSceneBase::GetInstance()->SkinChanged(CXuiSceneBase::GetInstance()->m_hObj); 367#endif 368} 369 370void AbstractTexturePack::unloadUI() 371{ 372 // Do nothing 373} 374 375wstring AbstractTexturePack::getXuiRootPath() 376{ 377 const ULONG_PTR c_ModuleHandle = (ULONG_PTR)GetModuleHandle(NULL); 378 379 // Load new skin 380 const DWORD LOCATOR_SIZE = 256; // Use this to allocate space to hold a ResourceLocator string 381 WCHAR szResourceLocator[ LOCATOR_SIZE ]; 382 383 swprintf(szResourceLocator, LOCATOR_SIZE,L"section://%X,%ls#%ls",c_ModuleHandle,L"media", L"media/"); 384 return szResourceLocator; 385} 386 387PBYTE AbstractTexturePack::getPackIcon(DWORD &dwImageBytes) 388{ 389 if(m_iconSize == 0 || m_iconData == NULL) loadIcon(); 390 dwImageBytes = m_iconSize; 391 return m_iconData; 392} 393 394PBYTE AbstractTexturePack::getPackComparison(DWORD &dwImageBytes) 395{ 396 if(m_comparisonSize == 0 || m_comparisonData == NULL) loadComparison(); 397 398 dwImageBytes = m_comparisonSize; 399 return m_comparisonData; 400} 401 402unsigned int AbstractTexturePack::getDLCParentPackId() 403{ 404 return 0; 405} 406 407unsigned char AbstractTexturePack::getDLCSubPackId() 408{ 409 return 0; 410}