diff --git a/Minecraft.Client/Platform/Common/DLC/DLCAudioFile.cpp b/Minecraft.Client/Platform/Common/DLC/DLCAudioFile.cpp index 571b3a947..0c9e424a9 100644 --- a/Minecraft.Client/Platform/Common/DLC/DLCAudioFile.cpp +++ b/Minecraft.Client/Platform/Common/DLC/DLCAudioFile.cpp @@ -9,273 +9,252 @@ #include "../../Minecraft.Client/Platform/Xbox/XML/xmlFilesCallback.h" #endif -namespace -{ - constexpr std::size_t AUDIO_DLC_WCHAR_BIN_SIZE = 2; +namespace { +constexpr std::size_t AUDIO_DLC_WCHAR_BIN_SIZE = 2; #if WCHAR_MAX > 0xFFFF - static std::wstring ReadAudioDlcWString(const void *data) - { - const std::uint16_t *chars = static_cast(data); - const std::uint16_t *end = chars; - while(*end != 0) - { - ++end; - } +static std::wstring ReadAudioDlcWString(const void* data) { + const std::uint16_t* chars = static_cast(data); + const std::uint16_t* end = chars; + while (*end != 0) { + ++end; + } - std::wstring out(static_cast(end - chars), 0); - for(std::size_t i = 0; i < out.size(); ++i) - { - out[i] = static_cast(chars[i]); - } - return out; - } + std::wstring out(static_cast(end - chars), 0); + for (std::size_t i = 0; i < out.size(); ++i) { + out[i] = static_cast(chars[i]); + } + return out; +} #else - static std::wstring ReadAudioDlcWString(const void *data) - { - return std::wstring(static_cast(data)); - } +static std::wstring ReadAudioDlcWString(const void* data) { + return std::wstring(static_cast(data)); +} #endif - template - T ReadAudioDlcValue(const std::uint8_t *data, unsigned int offset = 0) - { - T value; - std::memcpy(&value, data + offset, sizeof(value)); - return value; - } - - template - void ReadAudioDlcStruct(T *out, const std::uint8_t *data, unsigned int offset = 0) - { - std::memcpy(out, data + offset, sizeof(*out)); - } - - inline unsigned int AudioParamAdvance(unsigned int wcharCount) - { - return static_cast(sizeof(C4JStorage::DLC_FILE_PARAM) + wcharCount * AUDIO_DLC_WCHAR_BIN_SIZE); - } - - inline unsigned int AudioDetailAdvance(unsigned int wcharCount) - { - return static_cast(sizeof(C4JStorage::DLC_FILE_DETAILS) + wcharCount * AUDIO_DLC_WCHAR_BIN_SIZE); - } - - inline std::wstring ReadAudioParamString(const std::uint8_t *data, unsigned int offset) - { - return ReadAudioDlcWString(data + offset + offsetof(C4JStorage::DLC_FILE_PARAM, wchData)); - } +template +T ReadAudioDlcValue(const std::uint8_t* data, unsigned int offset = 0) { + T value; + std::memcpy(&value, data + offset, sizeof(value)); + return value; } -DLCAudioFile::DLCAudioFile(const std::wstring &path) : DLCFile(DLCManager::e_DLCType_Audio,path) -{ - m_pbData = NULL; - m_dataBytes = 0; +template +void ReadAudioDlcStruct(T* out, const std::uint8_t* data, + unsigned int offset = 0) { + std::memcpy(out, data + offset, sizeof(*out)); } -void DLCAudioFile::addData(std::uint8_t *pbData, std::uint32_t dataBytes) -{ - m_pbData = pbData; - m_dataBytes = dataBytes; - - processDLCDataFile(pbData,dataBytes); +inline unsigned int AudioParamAdvance(unsigned int wcharCount) { + return static_cast(sizeof(C4JStorage::DLC_FILE_PARAM) + + wcharCount * AUDIO_DLC_WCHAR_BIN_SIZE); } -std::uint8_t *DLCAudioFile::getData(std::uint32_t &dataBytes) -{ - dataBytes = m_dataBytes; - return m_pbData; +inline unsigned int AudioDetailAdvance(unsigned int wcharCount) { + return static_cast(sizeof(C4JStorage::DLC_FILE_DETAILS) + + wcharCount * AUDIO_DLC_WCHAR_BIN_SIZE); } -const WCHAR *DLCAudioFile::wchTypeNamesA[]= -{ - L"CUENAME", - L"CREDIT", +inline std::wstring ReadAudioParamString(const std::uint8_t* data, + unsigned int offset) { + return ReadAudioDlcWString(data + offset + + offsetof(C4JStorage::DLC_FILE_PARAM, wchData)); +} +} // namespace + +DLCAudioFile::DLCAudioFile(const std::wstring& path) + : DLCFile(DLCManager::e_DLCType_Audio, path) { + m_pbData = NULL; + m_dataBytes = 0; +} + +void DLCAudioFile::addData(std::uint8_t* pbData, std::uint32_t dataBytes) { + m_pbData = pbData; + m_dataBytes = dataBytes; + + processDLCDataFile(pbData, dataBytes); +} + +std::uint8_t* DLCAudioFile::getData(std::uint32_t& dataBytes) { + dataBytes = m_dataBytes; + return m_pbData; +} + +const WCHAR* DLCAudioFile::wchTypeNamesA[] = { + L"CUENAME", + L"CREDIT", }; -DLCAudioFile::EAudioParameterType DLCAudioFile::getParameterType(const std::wstring ¶mName) -{ - EAudioParameterType type = e_AudioParamType_Invalid; +DLCAudioFile::EAudioParameterType DLCAudioFile::getParameterType( + const std::wstring& paramName) { + EAudioParameterType type = e_AudioParamType_Invalid; - for(int i = 0; i < e_AudioParamType_Max; ++i) - { - if(paramName.compare(wchTypeNamesA[i]) == 0) - { - type = (EAudioParameterType)i; - break; - } - } + for (int i = 0; i < e_AudioParamType_Max; ++i) { + if (paramName.compare(wchTypeNamesA[i]) == 0) { + type = (EAudioParameterType)i; + break; + } + } - return type; + return type; } -void DLCAudioFile::addParameter(EAudioType type, EAudioParameterType ptype, const std::wstring &value) -{ - switch(ptype) - { +void DLCAudioFile::addParameter(EAudioType type, EAudioParameterType ptype, + const std::wstring& value) { + switch (ptype) { + case e_AudioParamType_Credit: // If this parameter exists, then mark + // this as free + // add it to the DLC credits list - case e_AudioParamType_Credit: // If this parameter exists, then mark this as free - //add it to the DLC credits list + // we'll need to justify this text since we don't have a lot of room + // for lines of credits + { + // don't look for duplicate in the music credits - // we'll need to justify this text since we don't have a lot of room for lines of credits - { - // don't look for duplicate in the music credits + // if(app.AlreadySeenCreditText(value)) break; - //if(app.AlreadySeenCreditText(value)) break; + int maximumChars = 55; - int maximumChars = 55; + bool bIsSDMode = + !RenderManager.IsHiDef() && !RenderManager.IsWidescreen(); - bool bIsSDMode=!RenderManager.IsHiDef() && !RenderManager.IsWidescreen(); + if (bIsSDMode) { + maximumChars = 45; + } - if(bIsSDMode) - { - maximumChars = 45; - } + switch (XGetLanguage()) { + case XC_LANGUAGE_JAPANESE: + case XC_LANGUAGE_TCHINESE: + case XC_LANGUAGE_KOREAN: + maximumChars = 35; + break; + } + std::wstring creditValue = value; + while (creditValue.length() > maximumChars) { + unsigned int i = 1; + while (i < creditValue.length() && + (i + 1) <= maximumChars) { + i++; + } + int iLast = (int)creditValue.find_last_of(L" ", i); + switch (XGetLanguage()) { + case XC_LANGUAGE_JAPANESE: + case XC_LANGUAGE_TCHINESE: + case XC_LANGUAGE_KOREAN: + iLast = maximumChars; + break; + default: + iLast = (int)creditValue.find_last_of(L" ", i); + break; + } - switch(XGetLanguage()) - { - case XC_LANGUAGE_JAPANESE: - case XC_LANGUAGE_TCHINESE: - case XC_LANGUAGE_KOREAN: - maximumChars = 35; - break; - } - std::wstring creditValue = value; - while (creditValue.length() > maximumChars) - { - unsigned int i = 1; - while (i < creditValue.length() && (i + 1) <= maximumChars) - { - i++; - } - int iLast=(int)creditValue.find_last_of(L" ",i); - switch(XGetLanguage()) - { - case XC_LANGUAGE_JAPANESE: - case XC_LANGUAGE_TCHINESE: - case XC_LANGUAGE_KOREAN: - iLast = maximumChars; - break; - default: - iLast=(int)creditValue.find_last_of(L" ",i); - break; - } + // if a space was found, include the space on this line + if (iLast != i) { + iLast++; + } - // if a space was found, include the space on this line - if(iLast!=i) - { - iLast++; - } - - app.AddCreditText((creditValue.substr(0, iLast)).c_str()); - creditValue = creditValue.substr(iLast); - } - app.AddCreditText(creditValue.c_str()); - - } - break; - case e_AudioParamType_Cuename: - m_parameters[type].push_back(value); - //m_parameters[(int)type] = value; - break; - default: - break; - } + app.AddCreditText((creditValue.substr(0, iLast)).c_str()); + creditValue = creditValue.substr(iLast); + } + app.AddCreditText(creditValue.c_str()); + } + break; + case e_AudioParamType_Cuename: + m_parameters[type].push_back(value); + // m_parameters[(int)type] = value; + break; + default: + break; + } } -bool DLCAudioFile::processDLCDataFile(std::uint8_t *pbData, std::uint32_t dataLength) -{ - std::unordered_map parameterMapping; - unsigned int uiCurrentByte=0; +bool DLCAudioFile::processDLCDataFile(std::uint8_t* pbData, + std::uint32_t dataLength) { + std::unordered_map parameterMapping; + unsigned int uiCurrentByte = 0; - // File format defined in the AudioPacker - // File format: Version 1 + // File format defined in the AudioPacker + // File format: Version 1 - unsigned int uiVersion = ReadAudioDlcValue(pbData, uiCurrentByte); - uiCurrentByte+=sizeof(int); + unsigned int uiVersion = + ReadAudioDlcValue(pbData, uiCurrentByte); + uiCurrentByte += sizeof(int); - if(uiVersion < CURRENT_AUDIO_VERSION_NUM) - { - if(pbData!=NULL) delete [] pbData; - app.DebugPrintf("DLC version of %d is too old to be read\n", uiVersion); - return false; - } - - unsigned int uiParameterTypeCount = ReadAudioDlcValue(pbData, uiCurrentByte); - uiCurrentByte+=sizeof(int); - C4JStorage::DLC_FILE_PARAM paramBuf; - ReadAudioDlcStruct(¶mBuf, pbData, uiCurrentByte); - - for(unsigned int i=0;i(pbData, uiCurrentByte); - uiCurrentByte+=sizeof(int); - C4JStorage::DLC_FILE_DETAILS fileBuf; - ReadAudioDlcStruct(&fileBuf, pbData, uiCurrentByte); + if (uiVersion < CURRENT_AUDIO_VERSION_NUM) { + if (pbData != NULL) delete[] pbData; + app.DebugPrintf("DLC version of %d is too old to be read\n", uiVersion); + return false; + } - unsigned int tempByteOffset = uiCurrentByte; - for(unsigned int i=0;i(pbData, uiCurrentByte); + uiCurrentByte += sizeof(int); + C4JStorage::DLC_FILE_PARAM paramBuf; + ReadAudioDlcStruct(¶mBuf, pbData, uiCurrentByte); - for(unsigned int i=0;i(pbTemp); - pbTemp+=sizeof(int); - ReadAudioDlcStruct(¶mBuf, pbTemp); - for(unsigned int j=0;j(pbData, uiCurrentByte); + uiCurrentByte += sizeof(int); + C4JStorage::DLC_FILE_DETAILS fileBuf; + ReadAudioDlcStruct(&fileBuf, pbData, uiCurrentByte); - AUTO_VAR(it, parameterMapping.find(paramBuf.dwType)); + unsigned int tempByteOffset = uiCurrentByte; + for (unsigned int i = 0; i < uiFileCount; i++) { + tempByteOffset += AudioDetailAdvance(fileBuf.dwWchCount); + ReadAudioDlcStruct(&fileBuf, pbData, tempByteOffset); + } + std::uint8_t* pbTemp = &pbData[tempByteOffset]; + ReadAudioDlcStruct(&fileBuf, pbData, uiCurrentByte); - if(it != parameterMapping.end() ) - { - addParameter(type, (EAudioParameterType)paramBuf.dwType, ReadAudioParamString(pbTemp, 0)); - } - pbTemp += AudioParamAdvance(paramBuf.dwWchCount); - ReadAudioDlcStruct(¶mBuf, pbTemp); - } - // Move the pointer to the start of the next files data; - pbTemp += fileBuf.uiFileSize; - uiCurrentByte += AudioDetailAdvance(fileBuf.dwWchCount); + for (unsigned int i = 0; i < uiFileCount; i++) { + EAudioType type = (EAudioType)fileBuf.dwType; + // Params + unsigned int uiParameterCount = ReadAudioDlcValue(pbTemp); + pbTemp += sizeof(int); + ReadAudioDlcStruct(¶mBuf, pbTemp); + for (unsigned int j = 0; j < uiParameterCount; j++) { + // EAudioParameterType paramType = e_AudioParamType_Invalid; - ReadAudioDlcStruct(&fileBuf, pbData, uiCurrentByte); + AUTO_VAR(it, parameterMapping.find(paramBuf.dwType)); - } + if (it != parameterMapping.end()) { + addParameter(type, (EAudioParameterType)paramBuf.dwType, + ReadAudioParamString(pbTemp, 0)); + } + pbTemp += AudioParamAdvance(paramBuf.dwWchCount); + ReadAudioDlcStruct(¶mBuf, pbTemp); + } + // Move the pointer to the start of the next files data; + pbTemp += fileBuf.uiFileSize; + uiCurrentByte += AudioDetailAdvance(fileBuf.dwWchCount); - return true; + ReadAudioDlcStruct(&fileBuf, pbData, uiCurrentByte); + } + + return true; } -int DLCAudioFile::GetCountofType(DLCAudioFile::EAudioType eType) -{ - return m_parameters[eType].size(); +int DLCAudioFile::GetCountofType(DLCAudioFile::EAudioType eType) { + return m_parameters[eType].size(); } - -std::wstring &DLCAudioFile::GetSoundName(int iIndex) -{ - int iWorldType=e_AudioType_Overworld; - while(iIndex>=m_parameters[iWorldType].size()) - { - iIndex-=m_parameters[iWorldType].size(); - iWorldType++; - } - return m_parameters[iWorldType].at(iIndex); +std::wstring& DLCAudioFile::GetSoundName(int iIndex) { + int iWorldType = e_AudioType_Overworld; + while (iIndex >= m_parameters[iWorldType].size()) { + iIndex -= m_parameters[iWorldType].size(); + iWorldType++; + } + return m_parameters[iWorldType].at(iIndex); } diff --git a/Minecraft.Client/Platform/Common/DLC/DLCAudioFile.h b/Minecraft.Client/Platform/Common/DLC/DLCAudioFile.h index dc6804e30..6fdc8d591 100644 --- a/Minecraft.Client/Platform/Common/DLC/DLCAudioFile.h +++ b/Minecraft.Client/Platform/Common/DLC/DLCAudioFile.h @@ -1,54 +1,52 @@ #pragma once #include "DLCFile.h" -class DLCAudioFile : public DLCFile -{ - +class DLCAudioFile : public DLCFile { public: + // If you add to the Enum,then you need to add the array of type names + // These are the names used in the XML for the parameters + enum EAudioType { + e_AudioType_Invalid = -1, - // If you add to the Enum,then you need to add the array of type names - // These are the names used in the XML for the parameters - enum EAudioType - { - e_AudioType_Invalid = -1, + e_AudioType_Overworld = 0, + e_AudioType_Nether, + e_AudioType_End, - e_AudioType_Overworld = 0, - e_AudioType_Nether, - e_AudioType_End, + e_AudioType_Max, + }; + enum EAudioParameterType { + e_AudioParamType_Invalid = -1, - e_AudioType_Max, - }; - enum EAudioParameterType - { - e_AudioParamType_Invalid = -1, + e_AudioParamType_Cuename = 0, + e_AudioParamType_Credit, - e_AudioParamType_Cuename = 0, - e_AudioParamType_Credit, + e_AudioParamType_Max, - e_AudioParamType_Max, + }; + static const WCHAR* wchTypeNamesA[e_AudioParamType_Max]; - }; - static const WCHAR *wchTypeNamesA[e_AudioParamType_Max]; + DLCAudioFile(const std::wstring& path); - DLCAudioFile(const std::wstring &path); + virtual void addData(std::uint8_t* pbData, std::uint32_t dataBytes); + virtual std::uint8_t* getData(std::uint32_t& dataBytes); - virtual void addData(std::uint8_t *pbData, std::uint32_t dataBytes); - virtual std::uint8_t *getData(std::uint32_t &dataBytes); - - bool processDLCDataFile(std::uint8_t *pbData, std::uint32_t dataLength); - int GetCountofType(DLCAudioFile::EAudioType ptype); - std::wstring &GetSoundName(int iIndex); + bool processDLCDataFile(std::uint8_t* pbData, std::uint32_t dataLength); + int GetCountofType(DLCAudioFile::EAudioType ptype); + std::wstring& GetSoundName(int iIndex); private: - using DLCFile::addParameter; + using DLCFile::addParameter; - std::uint8_t *m_pbData; - std::uint32_t m_dataBytes; - static const int CURRENT_AUDIO_VERSION_NUM=1; - //std::unordered_map m_parameters; - std::vector m_parameters[e_AudioType_Max]; + std::uint8_t* m_pbData; + std::uint32_t m_dataBytes; + static const int CURRENT_AUDIO_VERSION_NUM = 1; + // std::unordered_map m_parameters; + std::vector m_parameters[e_AudioType_Max]; - // use the EAudioType to order these - void addParameter(DLCAudioFile::EAudioType type, DLCAudioFile::EAudioParameterType ptype, const std::wstring &value); - DLCAudioFile::EAudioParameterType getParameterType(const std::wstring ¶mName); + // use the EAudioType to order these + void addParameter(DLCAudioFile::EAudioType type, + DLCAudioFile::EAudioParameterType ptype, + const std::wstring& value); + DLCAudioFile::EAudioParameterType getParameterType( + const std::wstring& paramName); }; diff --git a/Minecraft.Client/Platform/Common/DLC/DLCCapeFile.cpp b/Minecraft.Client/Platform/Common/DLC/DLCCapeFile.cpp index a9edb92e8..151d1176b 100644 --- a/Minecraft.Client/Platform/Common/DLC/DLCCapeFile.cpp +++ b/Minecraft.Client/Platform/Common/DLC/DLCCapeFile.cpp @@ -2,11 +2,9 @@ #include "DLCManager.h" #include "DLCCapeFile.h" -DLCCapeFile::DLCCapeFile(const std::wstring &path) : DLCFile(DLCManager::e_DLCType_Cape,path) -{ -} +DLCCapeFile::DLCCapeFile(const std::wstring& path) + : DLCFile(DLCManager::e_DLCType_Cape, path) {} -void DLCCapeFile::addData(std::uint8_t *pbData, std::uint32_t dataBytes) -{ - app.AddMemoryTextureFile(m_path,pbData,dataBytes); +void DLCCapeFile::addData(std::uint8_t* pbData, std::uint32_t dataBytes) { + app.AddMemoryTextureFile(m_path, pbData, dataBytes); } diff --git a/Minecraft.Client/Platform/Common/DLC/DLCCapeFile.h b/Minecraft.Client/Platform/Common/DLC/DLCCapeFile.h index 406ac3dc4..5d72b8a61 100644 --- a/Minecraft.Client/Platform/Common/DLC/DLCCapeFile.h +++ b/Minecraft.Client/Platform/Common/DLC/DLCCapeFile.h @@ -1,10 +1,9 @@ #pragma once #include "DLCFile.h" -class DLCCapeFile : public DLCFile -{ +class DLCCapeFile : public DLCFile { public: - DLCCapeFile(const std::wstring &path); + DLCCapeFile(const std::wstring& path); - virtual void addData(std::uint8_t *pbData, std::uint32_t dataBytes); + virtual void addData(std::uint8_t* pbData, std::uint32_t dataBytes); }; diff --git a/Minecraft.Client/Platform/Common/DLC/DLCColourTableFile.cpp b/Minecraft.Client/Platform/Common/DLC/DLCColourTableFile.cpp index fed962a75..b315c25ff 100644 --- a/Minecraft.Client/Platform/Common/DLC/DLCColourTableFile.cpp +++ b/Minecraft.Client/Platform/Common/DLC/DLCColourTableFile.cpp @@ -5,22 +5,21 @@ #include "../../Minecraft.Client/Textures/Packs/TexturePackRepository.h" #include "../../Minecraft.Client/Textures/Packs/TexturePack.h" -DLCColourTableFile::DLCColourTableFile(const std::wstring &path) : DLCFile(DLCManager::e_DLCType_ColourTable,path) -{ - m_colourTable = NULL; +DLCColourTableFile::DLCColourTableFile(const std::wstring& path) + : DLCFile(DLCManager::e_DLCType_ColourTable, path) { + m_colourTable = NULL; } -DLCColourTableFile::~DLCColourTableFile() -{ - if(m_colourTable != NULL) - { - app.DebugPrintf("Deleting DLCColourTableFile data\n"); - delete m_colourTable; - } +DLCColourTableFile::~DLCColourTableFile() { + if (m_colourTable != NULL) { + app.DebugPrintf("Deleting DLCColourTableFile data\n"); + delete m_colourTable; + } } -void DLCColourTableFile::addData(std::uint8_t *pbData, std::uint32_t dataBytes) -{ - ColourTable *defaultColourTable = Minecraft::GetInstance()->skins->getDefault()->getColourTable(); - m_colourTable = new ColourTable(defaultColourTable, pbData, dataBytes); +void DLCColourTableFile::addData(std::uint8_t* pbData, + std::uint32_t dataBytes) { + ColourTable* defaultColourTable = + Minecraft::GetInstance()->skins->getDefault()->getColourTable(); + m_colourTable = new ColourTable(defaultColourTable, pbData, dataBytes); } diff --git a/Minecraft.Client/Platform/Common/DLC/DLCColourTableFile.h b/Minecraft.Client/Platform/Common/DLC/DLCColourTableFile.h index d75fec458..119ddf0e8 100644 --- a/Minecraft.Client/Platform/Common/DLC/DLCColourTableFile.h +++ b/Minecraft.Client/Platform/Common/DLC/DLCColourTableFile.h @@ -3,16 +3,15 @@ class ColourTable; -class DLCColourTableFile : public DLCFile -{ +class DLCColourTableFile : public DLCFile { private: - ColourTable *m_colourTable; + ColourTable* m_colourTable; public: - DLCColourTableFile(const std::wstring &path); - ~DLCColourTableFile(); + DLCColourTableFile(const std::wstring& path); + ~DLCColourTableFile(); - virtual void addData(std::uint8_t *pbData, std::uint32_t dataBytes); + virtual void addData(std::uint8_t* pbData, std::uint32_t dataBytes); - ColourTable *getColourTable() { return m_colourTable; } + ColourTable* getColourTable() { return m_colourTable; } }; diff --git a/Minecraft.Client/Platform/Common/DLC/DLCFile.cpp b/Minecraft.Client/Platform/Common/DLC/DLCFile.cpp index 5ae3551bc..0732416ad 100644 --- a/Minecraft.Client/Platform/Common/DLC/DLCFile.cpp +++ b/Minecraft.Client/Platform/Common/DLC/DLCFile.cpp @@ -1,26 +1,22 @@ #include "../../Minecraft.World/Platform/stdafx.h" #include "DLCFile.h" -DLCFile::DLCFile(DLCManager::EDLCType type, const std::wstring &path) -{ - m_type = type; - m_path = path; +DLCFile::DLCFile(DLCManager::EDLCType type, const std::wstring& path) { + m_type = type; + m_path = path; - // store the id - bool dlcSkin = path.substr(0,3).compare(L"dlc") == 0; + // store the id + bool dlcSkin = path.substr(0, 3).compare(L"dlc") == 0; - if(dlcSkin) - { - std::wstring skinValue = path.substr(7,path.size()); - skinValue = skinValue.substr(0,skinValue.find_first_of(L'.')); - std::wstringstream ss; - ss << std::dec << skinValue.c_str(); - ss >> m_dwSkinId; - m_dwSkinId = MAKE_SKIN_BITMASK(true, m_dwSkinId); + if (dlcSkin) { + std::wstring skinValue = path.substr(7, path.size()); + skinValue = skinValue.substr(0, skinValue.find_first_of(L'.')); + std::wstringstream ss; + ss << std::dec << skinValue.c_str(); + ss >> m_dwSkinId; + m_dwSkinId = MAKE_SKIN_BITMASK(true, m_dwSkinId); - } - else - { - m_dwSkinId=0; - } + } else { + m_dwSkinId = 0; + } } diff --git a/Minecraft.Client/Platform/Common/DLC/DLCFile.h b/Minecraft.Client/Platform/Common/DLC/DLCFile.h index cb472a77c..73466a5b1 100644 --- a/Minecraft.Client/Platform/Common/DLC/DLCFile.h +++ b/Minecraft.Client/Platform/Common/DLC/DLCFile.h @@ -2,25 +2,33 @@ #include #include "DLCManager.h" -class DLCFile -{ +class DLCFile { protected: - DLCManager::EDLCType m_type; - std::wstring m_path; - std::uint32_t m_dwSkinId; + DLCManager::EDLCType m_type; + std::wstring m_path; + std::uint32_t m_dwSkinId; public: - DLCFile(DLCManager::EDLCType type, const std::wstring &path); - virtual ~DLCFile() {} + DLCFile(DLCManager::EDLCType type, const std::wstring& path); + virtual ~DLCFile() {} - DLCManager::EDLCType getType() { return m_type; } - std::wstring getPath() { return m_path; } - std::uint32_t getSkinID() { return m_dwSkinId; } + DLCManager::EDLCType getType() { return m_type; } + std::wstring getPath() { return m_path; } + std::uint32_t getSkinID() { return m_dwSkinId; } - virtual void addData(std::uint8_t *pbData, std::uint32_t dataBytes) {} - virtual std::uint8_t *getData(std::uint32_t &dataBytes) { dataBytes = 0; return NULL; } - virtual void addParameter(DLCManager::EDLCParameterType type, const std::wstring &value) {} + virtual void addData(std::uint8_t* pbData, std::uint32_t dataBytes) {} + virtual std::uint8_t* getData(std::uint32_t& dataBytes) { + dataBytes = 0; + return NULL; + } + virtual void addParameter(DLCManager::EDLCParameterType type, + const std::wstring& value) {} - virtual std::wstring getParameterAsString(DLCManager::EDLCParameterType type) { return L""; } - virtual bool getParameterAsBool(DLCManager::EDLCParameterType type) { return false;} + virtual std::wstring getParameterAsString( + DLCManager::EDLCParameterType type) { + return L""; + } + virtual bool getParameterAsBool(DLCManager::EDLCParameterType type) { + return false; + } }; diff --git a/Minecraft.Client/Platform/Common/DLC/DLCGameRules.h b/Minecraft.Client/Platform/Common/DLC/DLCGameRules.h index 4b1fe01f8..05ad1d783 100644 --- a/Minecraft.Client/Platform/Common/DLC/DLCGameRules.h +++ b/Minecraft.Client/Platform/Common/DLC/DLCGameRules.h @@ -3,8 +3,8 @@ #include "DLCFile.h" #include "../GameRules/LevelGenerationOptions.h" -class DLCGameRules : public DLCFile -{ +class DLCGameRules : public DLCFile { public: - DLCGameRules(DLCManager::EDLCType type, const std::wstring &path) : DLCFile(type,path) {} + DLCGameRules(DLCManager::EDLCType type, const std::wstring& path) + : DLCFile(type, path) {} }; \ No newline at end of file diff --git a/Minecraft.Client/Platform/Common/DLC/DLCGameRulesFile.cpp b/Minecraft.Client/Platform/Common/DLC/DLCGameRulesFile.cpp index 1c91a39e3..9af3bee97 100644 --- a/Minecraft.Client/Platform/Common/DLC/DLCGameRulesFile.cpp +++ b/Minecraft.Client/Platform/Common/DLC/DLCGameRulesFile.cpp @@ -2,20 +2,18 @@ #include "DLCManager.h" #include "DLCGameRulesFile.h" -DLCGameRulesFile::DLCGameRulesFile(const std::wstring &path) : DLCGameRules(DLCManager::e_DLCType_GameRules,path) -{ - m_pbData = NULL; - m_dataBytes = 0; +DLCGameRulesFile::DLCGameRulesFile(const std::wstring& path) + : DLCGameRules(DLCManager::e_DLCType_GameRules, path) { + m_pbData = NULL; + m_dataBytes = 0; } -void DLCGameRulesFile::addData(std::uint8_t *pbData, std::uint32_t dataBytes) -{ - m_pbData = pbData; - m_dataBytes = dataBytes; +void DLCGameRulesFile::addData(std::uint8_t* pbData, std::uint32_t dataBytes) { + m_pbData = pbData; + m_dataBytes = dataBytes; } -std::uint8_t *DLCGameRulesFile::getData(std::uint32_t &dataBytes) -{ - dataBytes = m_dataBytes; - return m_pbData; +std::uint8_t* DLCGameRulesFile::getData(std::uint32_t& dataBytes) { + dataBytes = m_dataBytes; + return m_pbData; } diff --git a/Minecraft.Client/Platform/Common/DLC/DLCGameRulesFile.h b/Minecraft.Client/Platform/Common/DLC/DLCGameRulesFile.h index 56af6cd8c..2bcb24a65 100644 --- a/Minecraft.Client/Platform/Common/DLC/DLCGameRulesFile.h +++ b/Minecraft.Client/Platform/Common/DLC/DLCGameRulesFile.h @@ -1,15 +1,14 @@ #pragma once #include "DLCGameRules.h" -class DLCGameRulesFile : public DLCGameRules -{ +class DLCGameRulesFile : public DLCGameRules { private: - std::uint8_t *m_pbData; - std::uint32_t m_dataBytes; + std::uint8_t* m_pbData; + std::uint32_t m_dataBytes; public: - DLCGameRulesFile(const std::wstring &path); + DLCGameRulesFile(const std::wstring& path); - virtual void addData(std::uint8_t *pbData, std::uint32_t dataBytes); - virtual std::uint8_t *getData(std::uint32_t &dataBytes); + virtual void addData(std::uint8_t* pbData, std::uint32_t dataBytes); + virtual std::uint8_t* getData(std::uint32_t& dataBytes); }; diff --git a/Minecraft.Client/Platform/Common/DLC/DLCGameRulesHeader.cpp b/Minecraft.Client/Platform/Common/DLC/DLCGameRulesHeader.cpp index 09afd4783..e52b46368 100644 --- a/Minecraft.Client/Platform/Common/DLC/DLCGameRulesHeader.cpp +++ b/Minecraft.Client/Platform/Common/DLC/DLCGameRulesHeader.cpp @@ -9,23 +9,22 @@ #include "DLCManager.h" #include "DLCGameRulesHeader.h" -DLCGameRulesHeader::DLCGameRulesHeader(const std::wstring &path) : DLCGameRules(DLCManager::e_DLCType_GameRulesHeader,path) -{ - m_pbData = NULL; - m_dataBytes = 0; +DLCGameRulesHeader::DLCGameRulesHeader(const std::wstring& path) + : DLCGameRules(DLCManager::e_DLCType_GameRulesHeader, path) { + m_pbData = NULL; + m_dataBytes = 0; - m_hasData = false; + m_hasData = false; - m_grfPath = path.substr(0, path.length() - 4) + L".grf"; + m_grfPath = path.substr(0, path.length() - 4) + L".grf"; - lgo = NULL; + lgo = NULL; } -void DLCGameRulesHeader::addData(std::uint8_t *pbData, std::uint32_t dataBytes) -{ - m_pbData = pbData; - m_dataBytes = dataBytes; - +void DLCGameRulesHeader::addData(std::uint8_t* pbData, + std::uint32_t dataBytes) { + m_pbData = pbData; + m_dataBytes = dataBytes; #if 0 byteArray data(m_pbData, m_dataBytes); @@ -73,20 +72,18 @@ void DLCGameRulesHeader::addData(std::uint8_t *pbData, std::uint32_t dataBytes) #endif } -std::uint8_t *DLCGameRulesHeader::getData(std::uint32_t &dataBytes) -{ - dataBytes = m_dataBytes; - return m_pbData; +std::uint8_t* DLCGameRulesHeader::getData(std::uint32_t& dataBytes) { + dataBytes = m_dataBytes; + return m_pbData; } -void DLCGameRulesHeader::setGrfData(std::uint8_t *fData, std::uint32_t dataSize, StringTable *st) -{ - if (!m_hasData) - { - m_hasData = true; - - //app.m_gameRules.loadGameRules(lgo, fData, fSize); +void DLCGameRulesHeader::setGrfData(std::uint8_t* fData, std::uint32_t dataSize, + StringTable* st) { + if (!m_hasData) { + m_hasData = true; - app.m_gameRules.readRuleFile(lgo, fData, dataSize, st); - } + // app.m_gameRules.loadGameRules(lgo, fData, fSize); + + app.m_gameRules.readRuleFile(lgo, fData, dataSize, st); + } } diff --git a/Minecraft.Client/Platform/Common/DLC/DLCGameRulesHeader.h b/Minecraft.Client/Platform/Common/DLC/DLCGameRulesHeader.h index a947ece81..ddf766d00 100644 --- a/Minecraft.Client/Platform/Common/DLC/DLCGameRulesHeader.h +++ b/Minecraft.Client/Platform/Common/DLC/DLCGameRulesHeader.h @@ -3,40 +3,44 @@ #include "DLCGameRules.h" #include "../GameRules/LevelGenerationOptions.h" -class DLCGameRulesHeader : public DLCGameRules, public JustGrSource -{ +class DLCGameRulesHeader : public DLCGameRules, public JustGrSource { private: + // GR-Header + std::uint8_t* m_pbData; + std::uint32_t m_dataBytes; - // GR-Header - std::uint8_t *m_pbData; - std::uint32_t m_dataBytes; - - bool m_hasData; + bool m_hasData; public: - virtual bool requiresTexturePack() {return m_bRequiresTexturePack;} - virtual std::uint32_t getRequiredTexturePackId() {return m_requiredTexturePackId;} - virtual std::wstring getDefaultSaveName() {return m_defaultSaveName;} - virtual const wchar_t *getWorldName() {return m_worldName.c_str();} - virtual const wchar_t *getDisplayName() {return m_displayName.c_str();} - virtual std::wstring getGrfPath() {return L"GameRules.grf";} + virtual bool requiresTexturePack() { return m_bRequiresTexturePack; } + virtual std::uint32_t getRequiredTexturePackId() { + return m_requiredTexturePackId; + } + virtual std::wstring getDefaultSaveName() { return m_defaultSaveName; } + virtual const wchar_t* getWorldName() { return m_worldName.c_str(); } + virtual const wchar_t* getDisplayName() { return m_displayName.c_str(); } + virtual std::wstring getGrfPath() { return L"GameRules.grf"; } - virtual void setRequiresTexturePack(bool x) {m_bRequiresTexturePack = x;} - virtual void setRequiredTexturePackId(std::uint32_t x) {m_requiredTexturePackId = x;} - virtual void setDefaultSaveName(const std::wstring &x) {m_defaultSaveName = x;} - virtual void setWorldName(const std::wstring & x) {m_worldName = x;} - virtual void setDisplayName(const std::wstring & x) {m_displayName = x;} - virtual void setGrfPath(const std::wstring & x) {m_grfPath = x;} + virtual void setRequiresTexturePack(bool x) { m_bRequiresTexturePack = x; } + virtual void setRequiredTexturePackId(std::uint32_t x) { + m_requiredTexturePackId = x; + } + virtual void setDefaultSaveName(const std::wstring& x) { + m_defaultSaveName = x; + } + virtual void setWorldName(const std::wstring& x) { m_worldName = x; } + virtual void setDisplayName(const std::wstring& x) { m_displayName = x; } + virtual void setGrfPath(const std::wstring& x) { m_grfPath = x; } - LevelGenerationOptions *lgo; + LevelGenerationOptions* lgo; public: - DLCGameRulesHeader(const std::wstring &path); + DLCGameRulesHeader(const std::wstring& path); - virtual void addData(std::uint8_t *pbData, std::uint32_t dataBytes); - virtual std::uint8_t *getData(std::uint32_t &dataBytes); + virtual void addData(std::uint8_t* pbData, std::uint32_t dataBytes); + virtual std::uint8_t* getData(std::uint32_t& dataBytes); - void setGrfData(std::uint8_t *fData, std::uint32_t dataSize, StringTable *); + void setGrfData(std::uint8_t* fData, std::uint32_t dataSize, StringTable*); - virtual bool ready() { return m_hasData; } + virtual bool ready() { return m_hasData; } }; diff --git a/Minecraft.Client/Platform/Common/DLC/DLCLocalisationFile.cpp b/Minecraft.Client/Platform/Common/DLC/DLCLocalisationFile.cpp index c1f9c9e30..2c36c7455 100644 --- a/Minecraft.Client/Platform/Common/DLC/DLCLocalisationFile.cpp +++ b/Minecraft.Client/Platform/Common/DLC/DLCLocalisationFile.cpp @@ -3,12 +3,12 @@ #include "DLCLocalisationFile.h" #include "../../Minecraft.Client/Utils/StringTable.h" -DLCLocalisationFile::DLCLocalisationFile(const std::wstring &path) : DLCFile(DLCManager::e_DLCType_LocalisationData,path) -{ - m_strings = NULL; +DLCLocalisationFile::DLCLocalisationFile(const std::wstring& path) + : DLCFile(DLCManager::e_DLCType_LocalisationData, path) { + m_strings = NULL; } -void DLCLocalisationFile::addData(std::uint8_t *pbData, std::uint32_t dataBytes) -{ - m_strings = new StringTable(pbData, dataBytes); +void DLCLocalisationFile::addData(std::uint8_t* pbData, + std::uint32_t dataBytes) { + m_strings = new StringTable(pbData, dataBytes); } diff --git a/Minecraft.Client/Platform/Common/DLC/DLCLocalisationFile.h b/Minecraft.Client/Platform/Common/DLC/DLCLocalisationFile.h index 46f5782d4..7b8fca417 100644 --- a/Minecraft.Client/Platform/Common/DLC/DLCLocalisationFile.h +++ b/Minecraft.Client/Platform/Common/DLC/DLCLocalisationFile.h @@ -3,16 +3,18 @@ class StringTable; -class DLCLocalisationFile : public DLCFile -{ +class DLCLocalisationFile : public DLCFile { private: - StringTable *m_strings; + StringTable* m_strings; public: - DLCLocalisationFile(const std::wstring &path); - DLCLocalisationFile(std::uint8_t *pbData, std::uint32_t dataBytes); // when we load in a texture pack details file from TMS++ + DLCLocalisationFile(const std::wstring& path); + DLCLocalisationFile( + std::uint8_t* pbData, + std::uint32_t dataBytes); // when we load in a texture pack details + // file from TMS++ - virtual void addData(std::uint8_t *pbData, std::uint32_t dataBytes); + virtual void addData(std::uint8_t* pbData, std::uint32_t dataBytes); - StringTable *getStringTable() { return m_strings; } + StringTable* getStringTable() { return m_strings; } }; diff --git a/Minecraft.Client/Platform/Common/DLC/DLCManager.cpp b/Minecraft.Client/Platform/Common/DLC/DLCManager.cpp index d633e7223..c0021eec3 100644 --- a/Minecraft.Client/Platform/Common/DLC/DLCManager.cpp +++ b/Minecraft.Client/Platform/Common/DLC/DLCManager.cpp @@ -19,762 +19,709 @@ static const std::size_t DLC_WCHAR_BIN_SIZE = 2; #if WCHAR_MAX > 0xFFFF // than sizeof(WCHAR) != DLC_WCHAR_BIN_SIZE // e.g. Linux and all Posix/Unix systems with wchar_t beeing 4B/32bit -static_assert( sizeof(wchar_t) == 4, "wchar_t is not 4bytes but larger than 2bytes ???"); +static_assert(sizeof(wchar_t) == 4, + "wchar_t is not 4bytes but larger than 2bytes ???"); -static inline std::wstring dlc_read_wstring(const void *data) -{ - const std::uint16_t* p = static_cast(data); - // find the end (nullterminated) - const std::uint16_t* end = p; - while(*end) { - ++end; - } +static inline std::wstring dlc_read_wstring(const void* data) { + const std::uint16_t* p = static_cast(data); + // find the end (nullterminated) + const std::uint16_t* end = p; + while (*end) { + ++end; + } - std::size_t len = static_cast(end - p); + std::size_t len = static_cast(end - p); - // allocate wstring with length len - // it will be nullterminated internally, do not worry. - std::wstring out(len, 0); + // allocate wstring with length len + // it will be nullterminated internally, do not worry. + std::wstring out(len, 0); - // and copy them into thje string - for(std::size_t i = 0; i < len; ++i) { - out[i] = static_cast(p[i]); - } + // and copy them into thje string + for (std::size_t i = 0; i < len; ++i) { + out[i] = static_cast(p[i]); + } - return out; + return out; } #define DLC_WSTRING(ptr) dlc_read_wstring(ptr) #else // just in case. -static_assert( sizeof(wchar_t) == 2, "How did we get here? wide char smaller than 2 bytes"); +static_assert(sizeof(wchar_t) == 2, + "How did we get here? wide char smaller than 2 bytes"); // perfectly fine scince wchar_t will be 2 bytes (UCS-2/UTF-16) #define DLC_WSTRING(ptr) std::wstring((wchar_t*)(ptr)) #endif -#define DLC_PARAM_ADV(n) (sizeof(C4JStorage::DLC_FILE_PARAM) + (n) * DLC_WCHAR_BIN_SIZE) -#define DLC_DETAIL_ADV(n) (sizeof(C4JStorage::DLC_FILE_DETAILS) + (n) * DLC_WCHAR_BIN_SIZE) +#define DLC_PARAM_ADV(n) \ + (sizeof(C4JStorage::DLC_FILE_PARAM) + (n) * DLC_WCHAR_BIN_SIZE) +#define DLC_DETAIL_ADV(n) \ + (sizeof(C4JStorage::DLC_FILE_DETAILS) + (n) * DLC_WCHAR_BIN_SIZE) -namespace -{ - template - T ReadDlcValue(const std::uint8_t *data, unsigned int offset = 0) - { - T value; - std::memcpy(&value, data + offset, sizeof(value)); - return value; - } +namespace { +template +T ReadDlcValue(const std::uint8_t* data, unsigned int offset = 0) { + T value; + std::memcpy(&value, data + offset, sizeof(value)); + return value; +} - template - void ReadDlcStruct(T *out, const std::uint8_t *data, unsigned int offset = 0) - { - std::memcpy(out, data + offset, sizeof(*out)); - } +template +void ReadDlcStruct(T* out, const std::uint8_t* data, unsigned int offset = 0) { + std::memcpy(out, data + offset, sizeof(*out)); +} - std::wstring getMountedDlcReadPath(const std::string &path) - { - std::wstring readPath = convStringToWstring(path); +std::wstring getMountedDlcReadPath(const std::string& path) { + std::wstring readPath = convStringToWstring(path); #ifdef _WINDOWS64 - const std::string mountedPath = StorageManager.GetMountedPath(path.c_str()); - if(!mountedPath.empty()) - { - readPath = convStringToWstring(mountedPath); - } + const std::string mountedPath = StorageManager.GetMountedPath(path.c_str()); + if (!mountedPath.empty()) { + readPath = convStringToWstring(mountedPath); + } #elif defined(_DURANGO) - const std::wstring mountedPath = StorageManager.GetMountedPath(readPath.c_str()); - if(!mountedPath.empty()) - { - readPath = mountedPath; - } + const std::wstring mountedPath = + StorageManager.GetMountedPath(readPath.c_str()); + if (!mountedPath.empty()) { + readPath = mountedPath; + } #endif - return readPath; - } - - bool readOwnedDlcFile(const std::string &path, std::uint8_t **ppData, unsigned int *pBytesRead) - { - *ppData = NULL; - *pBytesRead = 0; - - const std::wstring readPath = getMountedDlcReadPath(path); - std::FILE *file = PortableFileIO::OpenBinaryFileForRead(readPath); - if(file == NULL) - { - return false; - } - - if(!PortableFileIO::Seek(file, 0, SEEK_END)) - { - std::fclose(file); - return false; - } - - const __int64 endPosition = PortableFileIO::Tell(file); - if(endPosition <= 0 || endPosition > std::numeric_limits::max()) - { - std::fclose(file); - return false; - } - - const unsigned int fileSize = static_cast(endPosition); - if(!PortableFileIO::Seek(file, 0, SEEK_SET)) - { - std::fclose(file); - return false; - } - - std::uint8_t *data = new std::uint8_t[fileSize]; - const std::size_t bytesRead = std::fread(data, 1, fileSize, file); - const bool failed = std::ferror(file) != 0 || bytesRead != fileSize; - std::fclose(file); - if(failed) - { - delete[] data; - return false; - } - - *ppData = data; - *pBytesRead = static_cast(bytesRead); - return true; - } + return readPath; } -const WCHAR *DLCManager::wchTypeNamesA[]= -{ - L"DISPLAYNAME", - L"THEMENAME", - L"FREE", - L"CREDIT", - L"CAPEPATH", - L"BOX", - L"ANIM", - L"PACKID", - L"NETHERPARTICLECOLOUR", - L"ENCHANTTEXTCOLOUR", - L"ENCHANTTEXTFOCUSCOLOUR", - L"DATAPATH", - L"PACKVERSION", +bool readOwnedDlcFile(const std::string& path, std::uint8_t** ppData, + unsigned int* pBytesRead) { + *ppData = NULL; + *pBytesRead = 0; + + const std::wstring readPath = getMountedDlcReadPath(path); + std::FILE* file = PortableFileIO::OpenBinaryFileForRead(readPath); + if (file == NULL) { + return false; + } + + if (!PortableFileIO::Seek(file, 0, SEEK_END)) { + std::fclose(file); + return false; + } + + const __int64 endPosition = PortableFileIO::Tell(file); + if (endPosition <= 0 || + endPosition > std::numeric_limits::max()) { + std::fclose(file); + return false; + } + + const unsigned int fileSize = static_cast(endPosition); + if (!PortableFileIO::Seek(file, 0, SEEK_SET)) { + std::fclose(file); + return false; + } + + std::uint8_t* data = new std::uint8_t[fileSize]; + const std::size_t bytesRead = std::fread(data, 1, fileSize, file); + const bool failed = std::ferror(file) != 0 || bytesRead != fileSize; + std::fclose(file); + if (failed) { + delete[] data; + return false; + } + + *ppData = data; + *pBytesRead = static_cast(bytesRead); + return true; +} +} // namespace + +const WCHAR* DLCManager::wchTypeNamesA[] = { + L"DISPLAYNAME", + L"THEMENAME", + L"FREE", + L"CREDIT", + L"CAPEPATH", + L"BOX", + L"ANIM", + L"PACKID", + L"NETHERPARTICLECOLOUR", + L"ENCHANTTEXTCOLOUR", + L"ENCHANTTEXTFOCUSCOLOUR", + L"DATAPATH", + L"PACKVERSION", }; -DLCManager::DLCManager() -{ - //m_bNeedsUpdated = true; - m_bNeedsCorruptCheck = true; +DLCManager::DLCManager() { + // m_bNeedsUpdated = true; + m_bNeedsCorruptCheck = true; } -DLCManager::~DLCManager() -{ - for(AUTO_VAR(it, m_packs.begin()); it != m_packs.end(); ++it) - { - DLCPack *pack = *it; - delete pack; - } +DLCManager::~DLCManager() { + for (AUTO_VAR(it, m_packs.begin()); it != m_packs.end(); ++it) { + DLCPack* pack = *it; + delete pack; + } } -DLCManager::EDLCParameterType DLCManager::getParameterType(const std::wstring ¶mName) -{ - EDLCParameterType type = e_DLCParamType_Invalid; +DLCManager::EDLCParameterType DLCManager::getParameterType( + const std::wstring& paramName) { + EDLCParameterType type = e_DLCParamType_Invalid; - for(unsigned int i = 0; i < e_DLCParamType_Max; ++i) - { - if(paramName.compare(wchTypeNamesA[i]) == 0) - { - type = (EDLCParameterType)i; - break; - } - } + for (unsigned int i = 0; i < e_DLCParamType_Max; ++i) { + if (paramName.compare(wchTypeNamesA[i]) == 0) { + type = (EDLCParameterType)i; + break; + } + } - return type; + return type; } -unsigned int DLCManager::getPackCount(EDLCType type /*= e_DLCType_All*/) -{ - unsigned int packCount = 0; - if( type != e_DLCType_All ) - { - for(AUTO_VAR(it, m_packs.begin()); it != m_packs.end(); ++it) - { - DLCPack *pack = *it; - if( pack->getDLCItemsCount(type) > 0 ) - { - ++packCount; - } - } - } - else - { - packCount = static_cast(m_packs.size()); - } - return packCount; +unsigned int DLCManager::getPackCount(EDLCType type /*= e_DLCType_All*/) { + unsigned int packCount = 0; + if (type != e_DLCType_All) { + for (AUTO_VAR(it, m_packs.begin()); it != m_packs.end(); ++it) { + DLCPack* pack = *it; + if (pack->getDLCItemsCount(type) > 0) { + ++packCount; + } + } + } else { + packCount = static_cast(m_packs.size()); + } + return packCount; } -void DLCManager::addPack(DLCPack *pack) -{ - m_packs.push_back(pack); +void DLCManager::addPack(DLCPack* pack) { m_packs.push_back(pack); } + +void DLCManager::removePack(DLCPack* pack) { + if (pack != NULL) { + AUTO_VAR(it, find(m_packs.begin(), m_packs.end(), pack)); + if (it != m_packs.end()) m_packs.erase(it); + delete pack; + } } -void DLCManager::removePack(DLCPack *pack) -{ - if(pack != NULL) - { - AUTO_VAR(it, find(m_packs.begin(),m_packs.end(),pack)); - if(it != m_packs.end() ) m_packs.erase(it); - delete pack; - } -} +DLCPack* DLCManager::getPack(const std::wstring& name) { + DLCPack* pack = NULL; + // DWORD currentIndex = 0; + DLCPack* currentPack = NULL; + for (AUTO_VAR(it, m_packs.begin()); it != m_packs.end(); ++it) { + currentPack = *it; + std::wstring wsName = currentPack->getName(); -DLCPack *DLCManager::getPack(const std::wstring &name) -{ - DLCPack *pack = NULL; - //DWORD currentIndex = 0; - DLCPack *currentPack = NULL; - for(AUTO_VAR(it, m_packs.begin()); it != m_packs.end(); ++it) - { - currentPack = *it; - std::wstring wsName=currentPack->getName(); - - if(wsName.compare(name) == 0) - { - pack = currentPack; - break; - } - } - return pack; + if (wsName.compare(name) == 0) { + pack = currentPack; + break; + } + } + return pack; } #ifdef _XBOX_ONE -DLCPack *DLCManager::getPackFromProductID(const std::wstring &productID) -{ - DLCPack *pack = NULL; - //DWORD currentIndex = 0; - DLCPack *currentPack = NULL; - for(AUTO_VAR(it, m_packs.begin()); it != m_packs.end(); ++it) - { - currentPack = *it; - std::wstring wsName=currentPack->getPurchaseOfferId(); +DLCPack* DLCManager::getPackFromProductID(const std::wstring& productID) { + DLCPack* pack = NULL; + // DWORD currentIndex = 0; + DLCPack* currentPack = NULL; + for (AUTO_VAR(it, m_packs.begin()); it != m_packs.end(); ++it) { + currentPack = *it; + std::wstring wsName = currentPack->getPurchaseOfferId(); - if(wsName.compare(productID) == 0) - { - pack = currentPack; - break; - } - } - return pack; + if (wsName.compare(productID) == 0) { + pack = currentPack; + break; + } + } + return pack; } #endif -DLCPack *DLCManager::getPack(unsigned int index, EDLCType type /*= e_DLCType_All*/) -{ - DLCPack *pack = NULL; - if( type != e_DLCType_All ) - { - unsigned int currentIndex = 0; - DLCPack *currentPack = NULL; - for(AUTO_VAR(it, m_packs.begin()); it != m_packs.end(); ++it) - { - currentPack = *it; - if(currentPack->getDLCItemsCount(type)>0) - { - if(currentIndex == index) - { - pack = currentPack; - break; - } - ++currentIndex; - } - } - } - else - { - if(index >= m_packs.size()) - { - app.DebugPrintf("DLCManager: Trying to access a DLC pack beyond the range of valid packs\n"); - __debugbreak(); - } - pack = m_packs[index]; - } +DLCPack* DLCManager::getPack(unsigned int index, + EDLCType type /*= e_DLCType_All*/) { + DLCPack* pack = NULL; + if (type != e_DLCType_All) { + unsigned int currentIndex = 0; + DLCPack* currentPack = NULL; + for (AUTO_VAR(it, m_packs.begin()); it != m_packs.end(); ++it) { + currentPack = *it; + if (currentPack->getDLCItemsCount(type) > 0) { + if (currentIndex == index) { + pack = currentPack; + break; + } + ++currentIndex; + } + } + } else { + if (index >= m_packs.size()) { + app.DebugPrintf( + "DLCManager: Trying to access a DLC pack beyond the range of " + "valid packs\n"); + __debugbreak(); + } + pack = m_packs[index]; + } - return pack; + return pack; } -unsigned int DLCManager::getPackIndex(DLCPack *pack, bool &found, EDLCType type /*= e_DLCType_All*/) -{ - unsigned int foundIndex = 0; - found = false; - if(pack == NULL) - { - app.DebugPrintf("DLCManager: Attempting to find the index for a NULL pack\n"); - //__debugbreak(); - return foundIndex; - } - if( type != e_DLCType_All ) - { - unsigned int index = 0; - for(AUTO_VAR(it, m_packs.begin()); it != m_packs.end(); ++it) - { - DLCPack *thisPack = *it; - if(thisPack->getDLCItemsCount(type)>0) - { - if(thisPack == pack) - { - found = true; - foundIndex = index; - break; - } - ++index; - } - } - } - else - { - unsigned int index = 0; - for(AUTO_VAR(it, m_packs.begin()); it != m_packs.end(); ++it) - { - DLCPack *thisPack = *it; - if(thisPack == pack) - { - found = true; - foundIndex = index; - break; - } - ++index; - } - } - return foundIndex; +unsigned int DLCManager::getPackIndex(DLCPack* pack, bool& found, + EDLCType type /*= e_DLCType_All*/) { + unsigned int foundIndex = 0; + found = false; + if (pack == NULL) { + app.DebugPrintf( + "DLCManager: Attempting to find the index for a NULL pack\n"); + //__debugbreak(); + return foundIndex; + } + if (type != e_DLCType_All) { + unsigned int index = 0; + for (AUTO_VAR(it, m_packs.begin()); it != m_packs.end(); ++it) { + DLCPack* thisPack = *it; + if (thisPack->getDLCItemsCount(type) > 0) { + if (thisPack == pack) { + found = true; + foundIndex = index; + break; + } + ++index; + } + } + } else { + unsigned int index = 0; + for (AUTO_VAR(it, m_packs.begin()); it != m_packs.end(); ++it) { + DLCPack* thisPack = *it; + if (thisPack == pack) { + found = true; + foundIndex = index; + break; + } + ++index; + } + } + return foundIndex; } -unsigned int DLCManager::getPackIndexContainingSkin(const std::wstring &path, bool &found) -{ - unsigned int foundIndex = 0; - found = false; - unsigned int index = 0; - for(AUTO_VAR(it, m_packs.begin()); it != m_packs.end(); ++it) - { - DLCPack *pack = *it; - if(pack->getDLCItemsCount(e_DLCType_Skin)>0) - { - if(pack->doesPackContainSkin(path)) - { - foundIndex = index; - found = true; - break; - } - ++index; - } - } - return foundIndex; +unsigned int DLCManager::getPackIndexContainingSkin(const std::wstring& path, + bool& found) { + unsigned int foundIndex = 0; + found = false; + unsigned int index = 0; + for (AUTO_VAR(it, m_packs.begin()); it != m_packs.end(); ++it) { + DLCPack* pack = *it; + if (pack->getDLCItemsCount(e_DLCType_Skin) > 0) { + if (pack->doesPackContainSkin(path)) { + foundIndex = index; + found = true; + break; + } + ++index; + } + } + return foundIndex; } -DLCPack *DLCManager::getPackContainingSkin(const std::wstring &path) -{ - DLCPack *foundPack = NULL; - for(AUTO_VAR(it, m_packs.begin()); it != m_packs.end(); ++it) - { - DLCPack *pack = *it; - if(pack->getDLCItemsCount(e_DLCType_Skin)>0) - { - if(pack->doesPackContainSkin(path)) - { - foundPack = pack; - break; - } - } - } - return foundPack; +DLCPack* DLCManager::getPackContainingSkin(const std::wstring& path) { + DLCPack* foundPack = NULL; + for (AUTO_VAR(it, m_packs.begin()); it != m_packs.end(); ++it) { + DLCPack* pack = *it; + if (pack->getDLCItemsCount(e_DLCType_Skin) > 0) { + if (pack->doesPackContainSkin(path)) { + foundPack = pack; + break; + } + } + } + return foundPack; } -DLCSkinFile *DLCManager::getSkinFile(const std::wstring &path) -{ - DLCSkinFile *foundSkinfile = NULL; - for(AUTO_VAR(it, m_packs.begin()); it != m_packs.end(); ++it) - { - DLCPack *pack = *it; - foundSkinfile=pack->getSkinFile(path); - if(foundSkinfile!=NULL) - { - break; - } - } - return foundSkinfile; +DLCSkinFile* DLCManager::getSkinFile(const std::wstring& path) { + DLCSkinFile* foundSkinfile = NULL; + for (AUTO_VAR(it, m_packs.begin()); it != m_packs.end(); ++it) { + DLCPack* pack = *it; + foundSkinfile = pack->getSkinFile(path); + if (foundSkinfile != NULL) { + break; + } + } + return foundSkinfile; } -unsigned int DLCManager::checkForCorruptDLCAndAlert(bool showMessage /*= true*/) -{ - unsigned int corruptDLCCount = m_dwUnnamedCorruptDLCCount; - DLCPack *pack = NULL; - DLCPack *firstCorruptPack = NULL; +unsigned int DLCManager::checkForCorruptDLCAndAlert( + bool showMessage /*= true*/) { + unsigned int corruptDLCCount = m_dwUnnamedCorruptDLCCount; + DLCPack* pack = NULL; + DLCPack* firstCorruptPack = NULL; - for(AUTO_VAR(it, m_packs.begin()); it != m_packs.end(); ++it) - { - pack = *it; - if( pack->IsCorrupt() ) - { - ++corruptDLCCount; - if(firstCorruptPack == NULL) firstCorruptPack = pack; - } - } + for (AUTO_VAR(it, m_packs.begin()); it != m_packs.end(); ++it) { + pack = *it; + if (pack->IsCorrupt()) { + ++corruptDLCCount; + if (firstCorruptPack == NULL) firstCorruptPack = pack; + } + } - // gotta fix this someday - if(corruptDLCCount > 0 && showMessage) - { - unsigned int uiIDA[1]; - uiIDA[0]=IDS_CONFIRM_OK; - if(corruptDLCCount == 1 && firstCorruptPack != NULL) - { - // pass in the pack format string - WCHAR wchFormat[132]; - swprintf(wchFormat, 132, L"%ls\n\n%%ls", firstCorruptPack->getName().c_str()); + // gotta fix this someday + if (corruptDLCCount > 0 && showMessage) { + unsigned int uiIDA[1]; + uiIDA[0] = IDS_CONFIRM_OK; + if (corruptDLCCount == 1 && firstCorruptPack != NULL) { + // pass in the pack format string + WCHAR wchFormat[132]; + swprintf(wchFormat, 132, L"%ls\n\n%%ls", + firstCorruptPack->getName().c_str()); - C4JStorage::EMessageResult result = ui.RequestMessageBox( IDS_CORRUPT_DLC_TITLE, IDS_CORRUPT_DLC, uiIDA,1,ProfileManager.GetPrimaryPad(),NULL,NULL, app.GetStringTable(),wchFormat); + C4JStorage::EMessageResult result = ui.RequestMessageBox( + IDS_CORRUPT_DLC_TITLE, IDS_CORRUPT_DLC, uiIDA, 1, + ProfileManager.GetPrimaryPad(), NULL, NULL, + app.GetStringTable(), wchFormat); - } - else - { - C4JStorage::EMessageResult result = ui.RequestMessageBox( IDS_CORRUPT_DLC_TITLE, IDS_CORRUPT_DLC_MULTIPLE, uiIDA,1,ProfileManager.GetPrimaryPad(),NULL,NULL, app.GetStringTable()); - } - } + } else { + C4JStorage::EMessageResult result = ui.RequestMessageBox( + IDS_CORRUPT_DLC_TITLE, IDS_CORRUPT_DLC_MULTIPLE, uiIDA, 1, + ProfileManager.GetPrimaryPad(), NULL, NULL, + app.GetStringTable()); + } + } - SetNeedsCorruptCheck(false); + SetNeedsCorruptCheck(false); - return corruptDLCCount; + return corruptDLCCount; } -bool DLCManager::readDLCDataFile(unsigned int &dwFilesProcessed, const std::wstring &path, DLCPack *pack, bool fromArchive) -{ - return readDLCDataFile( dwFilesProcessed, wstringtofilename(path), pack, fromArchive); +bool DLCManager::readDLCDataFile(unsigned int& dwFilesProcessed, + const std::wstring& path, DLCPack* pack, + bool fromArchive) { + return readDLCDataFile(dwFilesProcessed, wstringtofilename(path), pack, + fromArchive); } +bool DLCManager::readDLCDataFile(unsigned int& dwFilesProcessed, + const std::string& path, DLCPack* pack, + bool fromArchive) { + std::wstring wPath = convStringToWstring(path); + if (fromArchive && app.getArchiveFileSize(wPath) >= 0) { + byteArray bytes = app.getArchiveFile(wPath); + return processDLCDataFile(dwFilesProcessed, bytes.data, bytes.length, + pack); + } else if (fromArchive) + return false; -bool DLCManager::readDLCDataFile(unsigned int &dwFilesProcessed, const std::string &path, DLCPack *pack, bool fromArchive) -{ - std::wstring wPath = convStringToWstring(path); - if (fromArchive && app.getArchiveFileSize(wPath) >= 0) - { - byteArray bytes = app.getArchiveFile(wPath); - return processDLCDataFile(dwFilesProcessed, bytes.data, bytes.length, pack); - } - else if (fromArchive) return false; - - unsigned int bytesRead = 0; - std::uint8_t *pbData = NULL; - if(!readOwnedDlcFile(path, &pbData, &bytesRead)) - { - app.DebugPrintf("Failed to open DLC data file %s\n", path.c_str()); - pack->SetIsCorrupt(true); - SetNeedsCorruptCheck(true); - return false; - } - return processDLCDataFile(dwFilesProcessed, pbData, bytesRead, pack); + unsigned int bytesRead = 0; + std::uint8_t* pbData = NULL; + if (!readOwnedDlcFile(path, &pbData, &bytesRead)) { + app.DebugPrintf("Failed to open DLC data file %s\n", path.c_str()); + pack->SetIsCorrupt(true); + SetNeedsCorruptCheck(true); + return false; + } + return processDLCDataFile(dwFilesProcessed, pbData, bytesRead, pack); } -bool DLCManager::processDLCDataFile(unsigned int &dwFilesProcessed, std::uint8_t *pbData, unsigned int dwLength, DLCPack *pack) +bool DLCManager::processDLCDataFile(unsigned int& dwFilesProcessed, + std::uint8_t* pbData, unsigned int dwLength, + DLCPack* pack) // a bunch of makros to reduce memcpy and offset boilerplate -#define DLC_READ_UINT(out, buf, off) memcpy((out), (buf) + (off), sizeof(unsigned int)) +#define DLC_READ_UINT(out, buf, off) \ + memcpy((out), (buf) + (off), sizeof(unsigned int)) -#define DLC_READ_PARAM(out, buf, off) memcpy((out), (buf) + (off), sizeof(C4JStorage::DLC_FILE_PARAM)) +#define DLC_READ_PARAM(out, buf, off) \ + memcpy((out), (buf) + (off), sizeof(C4JStorage::DLC_FILE_PARAM)) -#define DLC_READ_DETAIL(out, buf, off) memcpy((out), (buf) + (off), sizeof(C4JStorage::DLC_FILE_DETAILS)) +#define DLC_READ_DETAIL(out, buf, off) \ + memcpy((out), (buf) + (off), sizeof(C4JStorage::DLC_FILE_DETAILS)) // for details, read in the function below -#define DLC_PARAM_WSTR(buf, off) DLC_WSTRING((buf) + (off) + offsetof(C4JStorage::DLC_FILE_PARAM, wchData)) +#define DLC_PARAM_WSTR(buf, off) \ + DLC_WSTRING((buf) + (off) + offsetof(C4JStorage::DLC_FILE_PARAM, wchData)) -#define DLC_DETAIL_WSTR(buf, off) DLC_WSTRING((buf) + (off) + offsetof(C4JStorage::DLC_FILE_DETAILS, wchFile)) +#define DLC_DETAIL_WSTR(buf, off) \ + DLC_WSTRING((buf) + (off) + offsetof(C4JStorage::DLC_FILE_DETAILS, wchFile)) { - std::unordered_map parameterMapping; - unsigned int uiCurrentByte=0; + std::unordered_map parameterMapping; + unsigned int uiCurrentByte = 0; - // File format defined in the DLC_Creator - // File format: Version 2 - // unsigned long, version number - // unsigned long, t = number of parameter types - // t * DLC_FILE_PARAM structs mapping strings to id's - // unsigned long, n = number of files - // n * DLC_FILE_DETAILS describing each file in the pack - // n * files of the form - // // unsigned long, p = number of parameters - // // p * DLC_FILE_PARAM describing each parameter for this file - // // ulFileSize bytes of data blob of the file added + // File format defined in the DLC_Creator + // File format: Version 2 + // unsigned long, version number + // unsigned long, t = number of parameter types + // t * DLC_FILE_PARAM structs mapping strings to id's + // unsigned long, n = number of files + // n * DLC_FILE_DETAILS describing each file in the pack + // n * files of the form + // // unsigned long, p = number of parameters + // // p * DLC_FILE_PARAM describing each parameter for this file + // // ulFileSize bytes of data blob of the file added - // 4jcraft, some parts of this code changed, specifically: - // instead of casting a goddamn raw byte pointer and dereferencing it - // use memcpy, and access WSTRING with propper offset - // (scince bufferoffset after advancing by variable string length is not - // guaranteed to be properly aligned, so casting to a scalar/struct is UB) + // 4jcraft, some parts of this code changed, specifically: + // instead of casting a goddamn raw byte pointer and dereferencing it + // use memcpy, and access WSTRING with propper offset + // (scince bufferoffset after advancing by variable string length is not + // guaranteed to be properly aligned, so casting to a scalar/struct is UB) - // those casts coult be dangerous on e.g. ARM, because it doesnt handle - // missaligned loads, like x86/x64, so it would crash + // those casts coult be dangerous on e.g. ARM, because it doesnt handle + // missaligned loads, like x86/x64, so it would crash - // WHO TF USES HUNGARIAN NOTATION + // WHO TF USES HUNGARIAN NOTATION - unsigned int uiVersion; - DLC_READ_UINT(&uiVersion, pbData, uiCurrentByte); - uiCurrentByte+=sizeof(int); + unsigned int uiVersion; + DLC_READ_UINT(&uiVersion, pbData, uiCurrentByte); + uiCurrentByte += sizeof(int); - if(uiVersion < CURRENT_DLC_VERSION_NUM) - { - if(pbData!=NULL) delete [] pbData; - app.DebugPrintf("DLC version of %d is too old to be read\n", uiVersion); - return false; - } - pack->SetDataPointer(pbData); - // safe, offset 4, aligned - unsigned int uiParameterCount; - DLC_READ_UINT(&uiParameterCount, pbData, uiCurrentByte); - uiCurrentByte+=sizeof(int); + if (uiVersion < CURRENT_DLC_VERSION_NUM) { + if (pbData != NULL) delete[] pbData; + app.DebugPrintf("DLC version of %d is too old to be read\n", uiVersion); + return false; + } + pack->SetDataPointer(pbData); + // safe, offset 4, aligned + unsigned int uiParameterCount; + DLC_READ_UINT(&uiParameterCount, pbData, uiCurrentByte); + uiCurrentByte += sizeof(int); - C4JStorage::DLC_FILE_PARAM parBuf; - DLC_READ_PARAM(&parBuf, pbData, uiCurrentByte); - //DWORD dwwchCount=0; - for(unsigned int i=0;igetName(), pack->getLicenseMask()); - } - else if(type != e_DLCType_PackConfig) - { - dlcFile = pack->addFile(type, DLC_DETAIL_WSTR(pbData, uiCurrentByte)); - } + if (type == e_DLCType_TexturePack) { + dlcTexturePack = + new DLCPack(pack->getName(), pack->getLicenseMask()); + } else if (type != e_DLCType_PackConfig) { + dlcFile = + pack->addFile(type, DLC_DETAIL_WSTR(pbData, uiCurrentByte)); + } - // Params - unsigned int uiParamCount; - DLC_READ_UINT(&uiParamCount, pbTemp, 0); - pbTemp+=sizeof(int); + // Params + unsigned int uiParamCount; + DLC_READ_UINT(&uiParamCount, pbTemp, 0); + pbTemp += sizeof(int); - DLC_READ_PARAM(&parBuf, pbTemp, 0); - for(unsigned int j=0;jaddParameter(it->second, DLC_PARAM_WSTR(pbTemp, 0)); - } - else - { - if(dlcFile != NULL) dlcFile->addParameter(it->second, DLC_PARAM_WSTR(pbTemp, 0)); - else if(dlcTexturePack != NULL) dlcTexturePack->addParameter(it->second, DLC_PARAM_WSTR(pbTemp, 0)); - } - } - pbTemp+=DLC_PARAM_ADV(parBuf.dwWchCount); - DLC_READ_PARAM(&parBuf, pbTemp, 0); - } - //pbTemp+=ulParameterCount * sizeof(C4JStorage::DLC_FILE_PARAM); + if (it != parameterMapping.end()) { + if (type == e_DLCType_PackConfig) { + pack->addParameter(it->second, DLC_PARAM_WSTR(pbTemp, 0)); + } else { + if (dlcFile != NULL) + dlcFile->addParameter(it->second, + DLC_PARAM_WSTR(pbTemp, 0)); + else if (dlcTexturePack != NULL) + dlcTexturePack->addParameter(it->second, + DLC_PARAM_WSTR(pbTemp, 0)); + } + } + pbTemp += DLC_PARAM_ADV(parBuf.dwWchCount); + DLC_READ_PARAM(&parBuf, pbTemp, 0); + } + // pbTemp+=ulParameterCount * sizeof(C4JStorage::DLC_FILE_PARAM); - if(dlcTexturePack != NULL) - { - unsigned int texturePackFilesProcessed = 0; - bool validPack = processDLCDataFile(texturePackFilesProcessed, pbTemp, fileBuf.uiFileSize, dlcTexturePack); - pack->SetDataPointer(NULL); // If it's a child pack, it doesn't own the data - if(!validPack || texturePackFilesProcessed == 0) - { - delete dlcTexturePack; - dlcTexturePack = NULL; - } - else - { - pack->addChildPack(dlcTexturePack); + if (dlcTexturePack != NULL) { + unsigned int texturePackFilesProcessed = 0; + bool validPack = + processDLCDataFile(texturePackFilesProcessed, pbTemp, + fileBuf.uiFileSize, dlcTexturePack); + pack->SetDataPointer( + NULL); // If it's a child pack, it doesn't own the data + if (!validPack || texturePackFilesProcessed == 0) { + delete dlcTexturePack; + dlcTexturePack = NULL; + } else { + pack->addChildPack(dlcTexturePack); - if(dlcTexturePack->getDLCItemsCount(DLCManager::e_DLCType_Texture) > 0) - { - Minecraft::GetInstance()->skins->addTexturePackFromDLC(dlcTexturePack, dlcTexturePack->GetPackId() ); - } - } - ++dwFilesProcessed; - } - else if(dlcFile != NULL) - { - // Data - dlcFile->addData(pbTemp,fileBuf.uiFileSize); + if (dlcTexturePack->getDLCItemsCount( + DLCManager::e_DLCType_Texture) > 0) { + Minecraft::GetInstance()->skins->addTexturePackFromDLC( + dlcTexturePack, dlcTexturePack->GetPackId()); + } + } + ++dwFilesProcessed; + } else if (dlcFile != NULL) { + // Data + dlcFile->addData(pbTemp, fileBuf.uiFileSize); - // TODO - 4J Stu Remove the need for this vSkinNames vector, or manage it differently - switch(fileBuf.dwType) - { - case DLCManager::e_DLCType_Skin: - app.vSkinNames.push_back(DLC_DETAIL_WSTR(pbData, uiCurrentByte)); - break; - } + // TODO - 4J Stu Remove the need for this vSkinNames vector, or + // manage it differently + switch (fileBuf.dwType) { + case DLCManager::e_DLCType_Skin: + app.vSkinNames.push_back( + DLC_DETAIL_WSTR(pbData, uiCurrentByte)); + break; + } - ++dwFilesProcessed; - } + ++dwFilesProcessed; + } - // Move the pointer to the start of the next files data; - pbTemp+=fileBuf.uiFileSize; - uiCurrentByte+=DLC_DETAIL_ADV(fileBuf.dwWchCount); + // Move the pointer to the start of the next files data; + pbTemp += fileBuf.uiFileSize; + uiCurrentByte += DLC_DETAIL_ADV(fileBuf.dwWchCount); - DLC_READ_DETAIL(&fileBuf, pbData, uiCurrentByte); - } + DLC_READ_DETAIL(&fileBuf, pbData, uiCurrentByte); + } - if( pack->getDLCItemsCount(DLCManager::e_DLCType_GameRules) > 0 - || pack->getDLCItemsCount(DLCManager::e_DLCType_GameRulesHeader) > 0) - { - app.m_gameRules.loadGameRules(pack); - } + if (pack->getDLCItemsCount(DLCManager::e_DLCType_GameRules) > 0 || + pack->getDLCItemsCount(DLCManager::e_DLCType_GameRulesHeader) > 0) { + app.m_gameRules.loadGameRules(pack); + } - if(pack->getDLCItemsCount(DLCManager::e_DLCType_Audio) > 0) - { - //app.m_Audio.loadAudioDetails(pack); - } - // TODO Should be able to delete this data, but we can't yet due to how it is added to the Memory textures (MEM_file) + if (pack->getDLCItemsCount(DLCManager::e_DLCType_Audio) > 0) { + // app.m_Audio.loadAudioDetails(pack); + } + // TODO Should be able to delete this data, but we can't yet due to how it + // is added to the Memory textures (MEM_file) - return true; + return true; } -std::uint32_t DLCManager::retrievePackIDFromDLCDataFile(const std::string &path, DLCPack *pack) -{ - std::uint32_t packId = 0; +std::uint32_t DLCManager::retrievePackIDFromDLCDataFile(const std::string& path, + DLCPack* pack) { + std::uint32_t packId = 0; - unsigned int bytesRead = 0; - std::uint8_t *pbData = NULL; - if(!readOwnedDlcFile(path, &pbData, &bytesRead)) - { - return 0; - } - packId=retrievePackID(pbData, bytesRead, pack); - delete [] pbData; + unsigned int bytesRead = 0; + std::uint8_t* pbData = NULL; + if (!readOwnedDlcFile(path, &pbData, &bytesRead)) { + return 0; + } + packId = retrievePackID(pbData, bytesRead, pack); + delete[] pbData; - return packId; + return packId; } -std::uint32_t DLCManager::retrievePackID(std::uint8_t *pbData, unsigned int dwLength, DLCPack *pack) -{ - std::uint32_t packId=0; - bool bPackIDSet=false; - std::unordered_map parameterMapping; - unsigned int uiCurrentByte=0; +std::uint32_t DLCManager::retrievePackID(std::uint8_t* pbData, + unsigned int dwLength, DLCPack* pack) { + std::uint32_t packId = 0; + bool bPackIDSet = false; + std::unordered_map parameterMapping; + unsigned int uiCurrentByte = 0; - // File format defined in the DLC_Creator - // File format: Version 2 - // unsigned long, version number - // unsigned long, t = number of parameter types - // t * DLC_FILE_PARAM structs mapping strings to id's - // unsigned long, n = number of files - // n * DLC_FILE_DETAILS describing each file in the pack - // n * files of the form - // // unsigned long, p = number of parameters - // // p * DLC_FILE_PARAM describing each parameter for this file - // // ulFileSize bytes of data blob of the file added - unsigned int uiVersion = ReadDlcValue(pbData, uiCurrentByte); - uiCurrentByte+=sizeof(int); + // File format defined in the DLC_Creator + // File format: Version 2 + // unsigned long, version number + // unsigned long, t = number of parameter types + // t * DLC_FILE_PARAM structs mapping strings to id's + // unsigned long, n = number of files + // n * DLC_FILE_DETAILS describing each file in the pack + // n * files of the form + // // unsigned long, p = number of parameters + // // p * DLC_FILE_PARAM describing each parameter for this file + // // ulFileSize bytes of data blob of the file added + unsigned int uiVersion = ReadDlcValue(pbData, uiCurrentByte); + uiCurrentByte += sizeof(int); - if(uiVersion < CURRENT_DLC_VERSION_NUM) - { - app.DebugPrintf("DLC version of %d is too old to be read\n", uiVersion); - return 0; - } - pack->SetDataPointer(pbData); - unsigned int uiParameterCount = ReadDlcValue(pbData, uiCurrentByte); - uiCurrentByte+=sizeof(int); - C4JStorage::DLC_FILE_PARAM paramBuf; - ReadDlcStruct(¶mBuf, pbData, uiCurrentByte); - for(unsigned int i=0;iSetDataPointer(pbData); + unsigned int uiParameterCount = + ReadDlcValue(pbData, uiCurrentByte); + uiCurrentByte += sizeof(int); + C4JStorage::DLC_FILE_PARAM paramBuf; + ReadDlcStruct(¶mBuf, pbData, uiCurrentByte); + for (unsigned int i = 0; i < uiParameterCount; i++) { + // Map DLC strings to application strings, then store the DLC index + // mapping to application index + std::wstring parameterName = DLC_PARAM_WSTR(pbData, uiCurrentByte); + DLCManager::EDLCParameterType type = + DLCManager::getParameterType(parameterName); + if (type != DLCManager::e_DLCParamType_Invalid) { + parameterMapping[paramBuf.dwType] = type; + } + uiCurrentByte += DLC_PARAM_ADV(paramBuf.dwWchCount); + ReadDlcStruct(¶mBuf, pbData, uiCurrentByte); + } - unsigned int uiFileCount = ReadDlcValue(pbData, uiCurrentByte); - uiCurrentByte+=sizeof(int); - C4JStorage::DLC_FILE_DETAILS fileBuf; - ReadDlcStruct(&fileBuf, pbData, uiCurrentByte); + unsigned int uiFileCount = + ReadDlcValue(pbData, uiCurrentByte); + uiCurrentByte += sizeof(int); + C4JStorage::DLC_FILE_DETAILS fileBuf; + ReadDlcStruct(&fileBuf, pbData, uiCurrentByte); - unsigned int dwTemp=uiCurrentByte; - for(unsigned int i=0;i(pbTemp); - pbTemp+=sizeof(int); - ReadDlcStruct(¶mBuf, pbTemp); - for(unsigned int j=0;j(pbTemp); + pbTemp += sizeof(int); + ReadDlcStruct(¶mBuf, pbTemp); + for (unsigned int j = 0; j < uiParameterCount; j++) { + AUTO_VAR(it, parameterMapping.find(paramBuf.dwType)); - if(it != parameterMapping.end() ) - { - if(type==e_DLCType_PackConfig) - { - if(it->second==e_DLCParamType_PackId) - { - std::wstring wsTemp = DLC_PARAM_WSTR(pbTemp, 0); - std::wstringstream ss; - // 4J Stu - numbered using decimal to make it easier for artists/people to number manually - ss << std::dec << wsTemp.c_str(); - ss >> packId; - bPackIDSet=true; - break; - } - } - } - pbTemp += DLC_PARAM_ADV(paramBuf.dwWchCount); - ReadDlcStruct(¶mBuf, pbTemp); - } + if (it != parameterMapping.end()) { + if (type == e_DLCType_PackConfig) { + if (it->second == e_DLCParamType_PackId) { + std::wstring wsTemp = DLC_PARAM_WSTR(pbTemp, 0); + std::wstringstream ss; + // 4J Stu - numbered using decimal to make it easier for + // artists/people to number manually + ss << std::dec << wsTemp.c_str(); + ss >> packId; + bPackIDSet = true; + break; + } + } + } + pbTemp += DLC_PARAM_ADV(paramBuf.dwWchCount); + ReadDlcStruct(¶mBuf, pbTemp); + } - if(bPackIDSet) break; - // Move the pointer to the start of the next files data; - pbTemp += fileBuf.uiFileSize; - uiCurrentByte += DLC_DETAIL_ADV(fileBuf.dwWchCount); + if (bPackIDSet) break; + // Move the pointer to the start of the next files data; + pbTemp += fileBuf.uiFileSize; + uiCurrentByte += DLC_DETAIL_ADV(fileBuf.dwWchCount); - ReadDlcStruct(&fileBuf, pbData, uiCurrentByte); - } + ReadDlcStruct(&fileBuf, pbData, uiCurrentByte); + } - parameterMapping.clear(); - return packId; + parameterMapping.clear(); + return packId; } diff --git a/Minecraft.Client/Platform/Common/DLC/DLCManager.h b/Minecraft.Client/Platform/Common/DLC/DLCManager.h index 8f4e46e39..368e61fa5 100644 --- a/Minecraft.Client/Platform/Common/DLC/DLCManager.h +++ b/Minecraft.Client/Platform/Common/DLC/DLCManager.h @@ -1,100 +1,110 @@ #pragma once -//using namespace std; +// using namespace std; #include #include class DLCPack; class DLCSkinFile; -class DLCManager -{ +class DLCManager { public: - enum EDLCType - { - e_DLCType_Skin = 0, - e_DLCType_Cape, - e_DLCType_Texture, - e_DLCType_UIData, - e_DLCType_PackConfig, - e_DLCType_TexturePack, - e_DLCType_LocalisationData, - e_DLCType_GameRules, - e_DLCType_Audio, - e_DLCType_ColourTable, - e_DLCType_GameRulesHeader, + enum EDLCType { + e_DLCType_Skin = 0, + e_DLCType_Cape, + e_DLCType_Texture, + e_DLCType_UIData, + e_DLCType_PackConfig, + e_DLCType_TexturePack, + e_DLCType_LocalisationData, + e_DLCType_GameRules, + e_DLCType_Audio, + e_DLCType_ColourTable, + e_DLCType_GameRulesHeader, - e_DLCType_Max, - e_DLCType_All, - }; + e_DLCType_Max, + e_DLCType_All, + }; - // If you add to the Enum,then you need to add the array of type names - // These are the names used in the XML for the parameters - enum EDLCParameterType - { - e_DLCParamType_Invalid = -1, + // If you add to the Enum,then you need to add the array of type names + // These are the names used in the XML for the parameters + enum EDLCParameterType { + e_DLCParamType_Invalid = -1, - e_DLCParamType_DisplayName = 0, - e_DLCParamType_ThemeName, - e_DLCParamType_Free, // identify free skins - e_DLCParamType_Credit, // legal credits for DLC - e_DLCParamType_Cape, - e_DLCParamType_Box, - e_DLCParamType_Anim, - e_DLCParamType_PackId, - e_DLCParamType_NetherParticleColour, - e_DLCParamType_EnchantmentTextColour, - e_DLCParamType_EnchantmentTextFocusColour, - e_DLCParamType_DataPath, - e_DLCParamType_PackVersion, + e_DLCParamType_DisplayName = 0, + e_DLCParamType_ThemeName, + e_DLCParamType_Free, // identify free skins + e_DLCParamType_Credit, // legal credits for DLC + e_DLCParamType_Cape, + e_DLCParamType_Box, + e_DLCParamType_Anim, + e_DLCParamType_PackId, + e_DLCParamType_NetherParticleColour, + e_DLCParamType_EnchantmentTextColour, + e_DLCParamType_EnchantmentTextFocusColour, + e_DLCParamType_DataPath, + e_DLCParamType_PackVersion, - e_DLCParamType_Max, + e_DLCParamType_Max, - }; - const static WCHAR *wchTypeNamesA[e_DLCParamType_Max]; + }; + const static WCHAR* wchTypeNamesA[e_DLCParamType_Max]; private: - std::vector m_packs; - //bool m_bNeedsUpdated; - bool m_bNeedsCorruptCheck; - unsigned int m_dwUnnamedCorruptDLCCount; + std::vector m_packs; + // bool m_bNeedsUpdated; + bool m_bNeedsCorruptCheck; + unsigned int m_dwUnnamedCorruptDLCCount; + public: - DLCManager(); - ~DLCManager(); + DLCManager(); + ~DLCManager(); - static EDLCParameterType getParameterType(const std::wstring ¶mName); + static EDLCParameterType getParameterType(const std::wstring& paramName); - unsigned int getPackCount(EDLCType type = e_DLCType_All); + unsigned int getPackCount(EDLCType type = e_DLCType_All); - //bool NeedsUpdated() { return m_bNeedsUpdated; } - //void SetNeedsUpdated(bool val) { m_bNeedsUpdated = val; } + // bool NeedsUpdated() { return m_bNeedsUpdated; } + // void SetNeedsUpdated(bool val) { m_bNeedsUpdated = val; } - bool NeedsCorruptCheck() { return m_bNeedsCorruptCheck; } - void SetNeedsCorruptCheck(bool val) { m_bNeedsCorruptCheck = val; } + bool NeedsCorruptCheck() { return m_bNeedsCorruptCheck; } + void SetNeedsCorruptCheck(bool val) { m_bNeedsCorruptCheck = val; } - void resetUnnamedCorruptCount() { m_dwUnnamedCorruptDLCCount = 0; } - void incrementUnnamedCorruptCount() { ++m_dwUnnamedCorruptDLCCount; } + void resetUnnamedCorruptCount() { m_dwUnnamedCorruptDLCCount = 0; } + void incrementUnnamedCorruptCount() { ++m_dwUnnamedCorruptDLCCount; } - void addPack(DLCPack *pack); - void removePack(DLCPack *pack); + void addPack(DLCPack* pack); + void removePack(DLCPack* pack); - DLCPack *getPack(const std::wstring &name); + DLCPack* getPack(const std::wstring& name); #ifdef _XBOX_ONE - DLCPack *DLCManager::getPackFromProductID(const std::wstring &productID); + DLCPack* DLCManager::getPackFromProductID(const std::wstring& productID); #endif - DLCPack *getPack(unsigned int index, EDLCType type = e_DLCType_All); - unsigned int getPackIndex(DLCPack *pack, bool &found, EDLCType type = e_DLCType_All); - DLCSkinFile *getSkinFile(const std::wstring &path); // Will hunt all packs of type skin to find the right skinfile + DLCPack* getPack(unsigned int index, EDLCType type = e_DLCType_All); + unsigned int getPackIndex(DLCPack* pack, bool& found, + EDLCType type = e_DLCType_All); + DLCSkinFile* getSkinFile( + const std::wstring& path); // Will hunt all packs of type skin to find + // the right skinfile - DLCPack *getPackContainingSkin(const std::wstring &path); - unsigned int getPackIndexContainingSkin(const std::wstring &path, bool &found); + DLCPack* getPackContainingSkin(const std::wstring& path); + unsigned int getPackIndexContainingSkin(const std::wstring& path, + bool& found); - unsigned int checkForCorruptDLCAndAlert(bool showMessage = true); + unsigned int checkForCorruptDLCAndAlert(bool showMessage = true); - bool readDLCDataFile(unsigned int &dwFilesProcessed, const std::wstring &path, DLCPack *pack, bool fromArchive = false); - bool readDLCDataFile(unsigned int &dwFilesProcessed, const std::string &path, DLCPack *pack, bool fromArchive = false); - std::uint32_t retrievePackIDFromDLCDataFile(const std::string &path, DLCPack *pack); + bool readDLCDataFile(unsigned int& dwFilesProcessed, + const std::wstring& path, DLCPack* pack, + bool fromArchive = false); + bool readDLCDataFile(unsigned int& dwFilesProcessed, + const std::string& path, DLCPack* pack, + bool fromArchive = false); + std::uint32_t retrievePackIDFromDLCDataFile(const std::string& path, + DLCPack* pack); private: - bool processDLCDataFile(unsigned int &dwFilesProcessed, std::uint8_t *pbData, unsigned int dwLength, DLCPack *pack); + bool processDLCDataFile(unsigned int& dwFilesProcessed, + std::uint8_t* pbData, unsigned int dwLength, + DLCPack* pack); - std::uint32_t retrievePackID(std::uint8_t *pbData, unsigned int dwLength, DLCPack *pack); + std::uint32_t retrievePackID(std::uint8_t* pbData, unsigned int dwLength, + DLCPack* pack); }; diff --git a/Minecraft.Client/Platform/Common/DLC/DLCPack.cpp b/Minecraft.Client/Platform/Common/DLC/DLCPack.cpp index ec3531c56..c51cb1987 100644 --- a/Minecraft.Client/Platform/Common/DLC/DLCPack.cpp +++ b/Minecraft.Client/Platform/Common/DLC/DLCPack.cpp @@ -11,402 +11,354 @@ #include "DLCColourTableFile.h" #include "../../Minecraft.World/Util/StringHelpers.h" -DLCPack::DLCPack(const std::wstring &name,std::uint32_t dwLicenseMask) -{ - m_dataPath = L""; - m_packName = name; - m_dwLicenseMask=dwLicenseMask; +DLCPack::DLCPack(const std::wstring& name, std::uint32_t dwLicenseMask) { + m_dataPath = L""; + m_packName = name; + m_dwLicenseMask = dwLicenseMask; #ifdef _XBOX_ONE - m_wsProductId = L""; + m_wsProductId = L""; #else - m_ullFullOfferId = 0LL; + m_ullFullOfferId = 0LL; #endif - m_isCorrupt = false; - m_packId = 0; - m_packVersion = 0; - m_parentPack = NULL; - m_dlcMountIndex = -1; + m_isCorrupt = false; + m_packId = 0; + m_packVersion = 0; + m_parentPack = NULL; + m_dlcMountIndex = -1; #ifdef _XBOX - m_dlcDeviceID = XCONTENTDEVICE_ANY; + m_dlcDeviceID = XCONTENTDEVICE_ANY; #endif - - // This pointer is for all the data used for this pack, so deleting it invalidates ALL of it's children. - m_data = NULL; + + // This pointer is for all the data used for this pack, so deleting it + // invalidates ALL of it's children. + m_data = NULL; } #ifdef _XBOX_ONE -DLCPack::DLCPack(const std::wstring &name,const std::wstring &productID,std::uint32_t dwLicenseMask) -{ - m_dataPath = L""; - m_packName = name; - m_dwLicenseMask=dwLicenseMask; - m_wsProductId = productID; - m_isCorrupt = false; - m_packId = 0; - m_packVersion = 0; - m_parentPack = NULL; - m_dlcMountIndex = -1; +DLCPack::DLCPack(const std::wstring& name, const std::wstring& productID, + std::uint32_t dwLicenseMask) { + m_dataPath = L""; + m_packName = name; + m_dwLicenseMask = dwLicenseMask; + m_wsProductId = productID; + m_isCorrupt = false; + m_packId = 0; + m_packVersion = 0; + m_parentPack = NULL; + m_dlcMountIndex = -1; - // This pointer is for all the data used for this pack, so deleting it invalidates ALL of it's children. - m_data = NULL; + // This pointer is for all the data used for this pack, so deleting it + // invalidates ALL of it's children. + m_data = NULL; } #endif -DLCPack::~DLCPack() -{ - for(AUTO_VAR(it, m_childPacks.begin()); it != m_childPacks.end(); ++it) - { - delete *it; - } +DLCPack::~DLCPack() { + for (AUTO_VAR(it, m_childPacks.begin()); it != m_childPacks.end(); ++it) { + delete *it; + } - for(unsigned int i = 0; i < DLCManager::e_DLCType_Max; ++i) - { - for(AUTO_VAR(it,m_files[i].begin()); it != m_files[i].end(); ++it) - { - delete *it; - } - } + for (unsigned int i = 0; i < DLCManager::e_DLCType_Max; ++i) { + for (AUTO_VAR(it, m_files[i].begin()); it != m_files[i].end(); ++it) { + delete *it; + } + } - // This pointer is for all the data used for this pack, so deleting it invalidates ALL of it's children. - if(m_data) - { + // This pointer is for all the data used for this pack, so deleting it + // invalidates ALL of it's children. + if (m_data) { #ifndef _CONTENT_PACKAGE - wprintf(L"Deleting data for DLC pack %ls\n", m_packName.c_str()); + wprintf(L"Deleting data for DLC pack %ls\n", m_packName.c_str()); #endif - // 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 - if( m_parentPack == NULL ) - { - delete [] m_data; - } - } + // 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 + if (m_parentPack == NULL) { + delete[] m_data; + } + } } -int DLCPack::GetDLCMountIndex() -{ - if(m_parentPack != NULL) - { - return m_parentPack->GetDLCMountIndex(); - } - return m_dlcMountIndex; +int DLCPack::GetDLCMountIndex() { + if (m_parentPack != NULL) { + return m_parentPack->GetDLCMountIndex(); + } + return m_dlcMountIndex; } -XCONTENTDEVICEID DLCPack::GetDLCDeviceID() -{ - if(m_parentPack != NULL ) - { - return m_parentPack->GetDLCDeviceID(); - } - return m_dlcDeviceID; +XCONTENTDEVICEID DLCPack::GetDLCDeviceID() { + if (m_parentPack != NULL) { + return m_parentPack->GetDLCDeviceID(); + } + return m_dlcDeviceID; } -void DLCPack::addChildPack(DLCPack *childPack) -{ - const std::uint32_t packId = childPack->GetPackId(); +void DLCPack::addChildPack(DLCPack* childPack) { + const std::uint32_t packId = childPack->GetPackId(); #ifndef _CONTENT_PACKAGE - if(packId > 15) - { - __debugbreak(); - } + if (packId > 15) { + __debugbreak(); + } #endif - childPack->SetPackId( (packId<<24) | m_packId ); - m_childPacks.push_back(childPack); - childPack->setParentPack(this); - childPack->m_packName = m_packName + childPack->getName(); + childPack->SetPackId((packId << 24) | m_packId); + m_childPacks.push_back(childPack); + childPack->setParentPack(this); + childPack->m_packName = m_packName + childPack->getName(); } -void DLCPack::setParentPack(DLCPack *parentPack) -{ - m_parentPack = parentPack; +void DLCPack::setParentPack(DLCPack* parentPack) { m_parentPack = parentPack; } + +void DLCPack::addParameter(DLCManager::EDLCParameterType type, + const std::wstring& value) { + switch (type) { + case DLCManager::e_DLCParamType_PackId: { + std::uint32_t packId = 0; + + std::wstringstream ss; + // 4J Stu - numbered using decimal to make it easier for + // artists/people to number manually + ss << std::dec << value.c_str(); + ss >> packId; + + SetPackId(packId); + } break; + case DLCManager::e_DLCParamType_PackVersion: { + std::uint32_t version = 0; + + std::wstringstream ss; + // 4J Stu - numbered using decimal to make it easier for + // artists/people to number manually + ss << std::dec << value.c_str(); + ss >> version; + + SetPackVersion(version); + } break; + case DLCManager::e_DLCParamType_DisplayName: + m_packName = value; + break; + case DLCManager::e_DLCParamType_DataPath: + m_dataPath = value; + break; + default: + m_parameters[(int)type] = value; + break; + } } -void DLCPack::addParameter(DLCManager::EDLCParameterType type, const std::wstring &value) -{ - switch(type) - { - case DLCManager::e_DLCParamType_PackId: - { - std::uint32_t packId = 0; - - std::wstringstream ss; - // 4J Stu - numbered using decimal to make it easier for artists/people to number manually - ss << std::dec << value.c_str(); - ss >> packId; - - SetPackId(packId); - } - break; - case DLCManager::e_DLCParamType_PackVersion: - { - std::uint32_t version = 0; - - std::wstringstream ss; - // 4J Stu - numbered using decimal to make it easier for artists/people to number manually - ss << std::dec << value.c_str(); - ss >> version; - - SetPackVersion(version); - } - break; - case DLCManager::e_DLCParamType_DisplayName: - m_packName = value; - break; - case DLCManager::e_DLCParamType_DataPath: - m_dataPath = value; - break; - default: - m_parameters[(int)type] = value; - break; - } +bool DLCPack::getParameterAsUInt(DLCManager::EDLCParameterType type, + unsigned int& param) { + AUTO_VAR(it, m_parameters.find((int)type)); + if (it != m_parameters.end()) { + switch (type) { + case DLCManager::e_DLCParamType_NetherParticleColour: + case DLCManager::e_DLCParamType_EnchantmentTextColour: + case DLCManager::e_DLCParamType_EnchantmentTextFocusColour: { + std::wstringstream ss; + ss << std::hex << it->second.c_str(); + ss >> param; + } break; + default: + param = _fromString(it->second); + } + return true; + } + return false; } -bool DLCPack::getParameterAsUInt(DLCManager::EDLCParameterType type, unsigned int ¶m) -{ - AUTO_VAR(it,m_parameters.find((int)type)); - if(it != m_parameters.end()) - { - switch(type) - { - case DLCManager::e_DLCParamType_NetherParticleColour: - case DLCManager::e_DLCParamType_EnchantmentTextColour: - case DLCManager::e_DLCParamType_EnchantmentTextFocusColour: - { - std::wstringstream ss; - ss << std::hex << it->second.c_str(); - ss >> param; - } - break; - default: - param = _fromString(it->second); - } - return true; - } - return false; -} +DLCFile* DLCPack::addFile(DLCManager::EDLCType type, const std::wstring& path) { + DLCFile* newFile = NULL; -DLCFile *DLCPack::addFile(DLCManager::EDLCType type, const std::wstring &path) -{ - DLCFile *newFile = NULL; + switch (type) { + case DLCManager::e_DLCType_Skin: { + std::vector splitPath = stringSplit(path, L'/'); + std::wstring strippedPath = splitPath.back(); - switch(type) - { - case DLCManager::e_DLCType_Skin: - { - std::vector splitPath = stringSplit(path,L'/'); - std::wstring strippedPath = splitPath.back(); + newFile = new DLCSkinFile(strippedPath); - newFile = new DLCSkinFile(strippedPath); - - // check to see if we can get the full offer id using this skin name + // check to see if we can get the full offer id using this skin name #ifdef _XBOX_ONE - app.GetDLCFullOfferIDForSkinID(strippedPath,m_wsProductId); + app.GetDLCFullOfferIDForSkinID(strippedPath, m_wsProductId); #else - ULONGLONG ullVal=0LL; + ULONGLONG ullVal = 0LL; - if(app.GetDLCFullOfferIDForSkinID(strippedPath,&ullVal)) - { - m_ullFullOfferId=ullVal; - } + if (app.GetDLCFullOfferIDForSkinID(strippedPath, &ullVal)) { + m_ullFullOfferId = ullVal; + } #endif - } - break; - case DLCManager::e_DLCType_Cape: - { - std::vector splitPath = stringSplit(path,L'/'); - std::wstring strippedPath = splitPath.back(); - newFile = new DLCCapeFile(strippedPath); - } - break; - case DLCManager::e_DLCType_Texture: - newFile = new DLCTextureFile(path); - break; - case DLCManager::e_DLCType_UIData: - newFile = new DLCUIDataFile(path); - break; - case DLCManager::e_DLCType_LocalisationData: - newFile = new DLCLocalisationFile(path); - break; - case DLCManager::e_DLCType_GameRules: - newFile = new DLCGameRulesFile(path); - break; - case DLCManager::e_DLCType_Audio: - newFile = new DLCAudioFile(path); - break; - case DLCManager::e_DLCType_ColourTable: - newFile = new DLCColourTableFile(path); - break; - case DLCManager::e_DLCType_GameRulesHeader: - newFile = new DLCGameRulesHeader(path); - break; - default: - break; - }; + } break; + case DLCManager::e_DLCType_Cape: { + std::vector splitPath = stringSplit(path, L'/'); + std::wstring strippedPath = splitPath.back(); + newFile = new DLCCapeFile(strippedPath); + } break; + case DLCManager::e_DLCType_Texture: + newFile = new DLCTextureFile(path); + break; + case DLCManager::e_DLCType_UIData: + newFile = new DLCUIDataFile(path); + break; + case DLCManager::e_DLCType_LocalisationData: + newFile = new DLCLocalisationFile(path); + break; + case DLCManager::e_DLCType_GameRules: + newFile = new DLCGameRulesFile(path); + break; + case DLCManager::e_DLCType_Audio: + newFile = new DLCAudioFile(path); + break; + case DLCManager::e_DLCType_ColourTable: + newFile = new DLCColourTableFile(path); + break; + case DLCManager::e_DLCType_GameRulesHeader: + newFile = new DLCGameRulesHeader(path); + break; + default: + break; + }; - if( newFile != NULL ) - { - m_files[newFile->getType()].push_back(newFile); - } + if (newFile != NULL) { + m_files[newFile->getType()].push_back(newFile); + } - return newFile; + return newFile; } -// MGH - added this comp func, as the embedded func in find_if was confusing the PS3 compiler -static const std::wstring *g_pathCmpString = NULL; -static bool pathCmp(DLCFile *val) -{ - return (g_pathCmpString->compare(val->getPath()) == 0); +// MGH - added this comp func, as the embedded func in find_if was confusing the +// PS3 compiler +static const std::wstring* g_pathCmpString = NULL; +static bool pathCmp(DLCFile* val) { + return (g_pathCmpString->compare(val->getPath()) == 0); } -bool DLCPack::doesPackContainFile(DLCManager::EDLCType type, const std::wstring &path) -{ - bool hasFile = false; - if(type == DLCManager::e_DLCType_All) - { - for(DLCManager::EDLCType currentType = (DLCManager::EDLCType)0; currentType < DLCManager::e_DLCType_Max; currentType = (DLCManager::EDLCType)(currentType + 1)) - { - hasFile = doesPackContainFile(currentType,path); - if(hasFile) break; - } - } - else - { - g_pathCmpString = &path; - AUTO_VAR(it, std::find_if( m_files[type].begin(), m_files[type].end(), pathCmp )); - hasFile = it != m_files[type].end(); - if(!hasFile && m_parentPack ) - { - hasFile = m_parentPack->doesPackContainFile(type,path); - } - } - return hasFile; +bool DLCPack::doesPackContainFile(DLCManager::EDLCType type, + const std::wstring& path) { + bool hasFile = false; + if (type == DLCManager::e_DLCType_All) { + for (DLCManager::EDLCType currentType = (DLCManager::EDLCType)0; + currentType < DLCManager::e_DLCType_Max; + currentType = (DLCManager::EDLCType)(currentType + 1)) { + hasFile = doesPackContainFile(currentType, path); + if (hasFile) break; + } + } else { + g_pathCmpString = &path; + AUTO_VAR(it, std::find_if(m_files[type].begin(), m_files[type].end(), + pathCmp)); + hasFile = it != m_files[type].end(); + if (!hasFile && m_parentPack) { + hasFile = m_parentPack->doesPackContainFile(type, path); + } + } + return hasFile; } -DLCFile *DLCPack::getFile(DLCManager::EDLCType type, unsigned int index) -{ - DLCFile *file = NULL; - if(type == DLCManager::e_DLCType_All) - { - for(DLCManager::EDLCType currentType = (DLCManager::EDLCType)0; currentType < DLCManager::e_DLCType_Max; currentType = (DLCManager::EDLCType)(currentType + 1)) - { - file = getFile(currentType,index); - if(file != NULL) break; - } - } - else - { - if(m_files[type].size() > index) file = m_files[type][index]; - if(!file && m_parentPack) - { - file = m_parentPack->getFile(type,index); - } - } - return file; +DLCFile* DLCPack::getFile(DLCManager::EDLCType type, unsigned int index) { + DLCFile* file = NULL; + if (type == DLCManager::e_DLCType_All) { + for (DLCManager::EDLCType currentType = (DLCManager::EDLCType)0; + currentType < DLCManager::e_DLCType_Max; + currentType = (DLCManager::EDLCType)(currentType + 1)) { + file = getFile(currentType, index); + if (file != NULL) break; + } + } else { + if (m_files[type].size() > index) file = m_files[type][index]; + if (!file && m_parentPack) { + file = m_parentPack->getFile(type, index); + } + } + return file; } -DLCFile *DLCPack::getFile(DLCManager::EDLCType type, const std::wstring &path) -{ - DLCFile *file = NULL; - if(type == DLCManager::e_DLCType_All) - { - for(DLCManager::EDLCType currentType = (DLCManager::EDLCType)0; currentType < DLCManager::e_DLCType_Max; currentType = (DLCManager::EDLCType)(currentType + 1)) - { - file = getFile(currentType,path); - if(file != NULL) break; - } - } - else - { - g_pathCmpString = &path; - AUTO_VAR(it, std::find_if( m_files[type].begin(), m_files[type].end(), pathCmp )); +DLCFile* DLCPack::getFile(DLCManager::EDLCType type, const std::wstring& path) { + DLCFile* file = NULL; + if (type == DLCManager::e_DLCType_All) { + for (DLCManager::EDLCType currentType = (DLCManager::EDLCType)0; + currentType < DLCManager::e_DLCType_Max; + currentType = (DLCManager::EDLCType)(currentType + 1)) { + file = getFile(currentType, path); + if (file != NULL) break; + } + } else { + g_pathCmpString = &path; + AUTO_VAR(it, std::find_if(m_files[type].begin(), m_files[type].end(), + pathCmp)); - if(it == m_files[type].end()) - { - // Not found - file = NULL; - } - else - { - file = *it; - } - if(!file && m_parentPack) - { - file = m_parentPack->getFile(type,path); - } - } - return file; + if (it == m_files[type].end()) { + // Not found + file = NULL; + } else { + file = *it; + } + if (!file && m_parentPack) { + file = m_parentPack->getFile(type, path); + } + } + return file; } -unsigned int DLCPack::getDLCItemsCount(DLCManager::EDLCType type /*= DLCManager::e_DLCType_All*/) -{ - unsigned int count = 0; +unsigned int DLCPack::getDLCItemsCount( + DLCManager::EDLCType type /*= DLCManager::e_DLCType_All*/) { + unsigned int count = 0; - switch(type) - { - case DLCManager::e_DLCType_All: - for(int i = 0; i < DLCManager::e_DLCType_Max; ++i) - { - count += getDLCItemsCount((DLCManager::EDLCType)i); - } - break; - default: - count = static_cast(m_files[(int)type].size()); - break; - }; - return count; + switch (type) { + case DLCManager::e_DLCType_All: + for (int i = 0; i < DLCManager::e_DLCType_Max; ++i) { + count += getDLCItemsCount((DLCManager::EDLCType)i); + } + break; + default: + count = static_cast(m_files[(int)type].size()); + break; + }; + return count; }; -unsigned int DLCPack::getFileIndexAt(DLCManager::EDLCType type, const std::wstring &path, bool &found) -{ - if(type == DLCManager::e_DLCType_All) - { - app.DebugPrintf("Unimplemented\n"); +unsigned int DLCPack::getFileIndexAt(DLCManager::EDLCType type, + const std::wstring& path, bool& found) { + if (type == DLCManager::e_DLCType_All) { + app.DebugPrintf("Unimplemented\n"); #ifndef __CONTENT_PACKAGE - __debugbreak(); + __debugbreak(); #endif - return 0; - } + return 0; + } - unsigned int foundIndex = 0; - found = false; - unsigned int index = 0; - for(AUTO_VAR(it, m_files[type].begin()); it != m_files[type].end(); ++it) - { - if(path.compare((*it)->getPath()) == 0) - { - foundIndex = index; - found = true; - break; - } - ++index; - } + unsigned int foundIndex = 0; + found = false; + unsigned int index = 0; + for (AUTO_VAR(it, m_files[type].begin()); it != m_files[type].end(); ++it) { + if (path.compare((*it)->getPath()) == 0) { + foundIndex = index; + found = true; + break; + } + ++index; + } - return foundIndex; + return foundIndex; } -bool DLCPack::hasPurchasedFile(DLCManager::EDLCType type, const std::wstring &path) -{ - if(type == DLCManager::e_DLCType_All) - { - app.DebugPrintf("Unimplemented\n"); +bool DLCPack::hasPurchasedFile(DLCManager::EDLCType type, + const std::wstring& path) { + if (type == DLCManager::e_DLCType_All) { + app.DebugPrintf("Unimplemented\n"); #ifndef _CONTENT_PACKAGE - __debugbreak(); + __debugbreak(); #endif - return false; - } + return false; + } #ifndef _CONTENT_PACKAGE - if( app.GetGameSettingsDebugMask(ProfileManager.GetPrimaryPad())&(1L< #include "DLCManager.h" class DLCFile; class DLCSkinFile; -class DLCPack -{ +class DLCPack { private: - std::vector m_files[DLCManager::e_DLCType_Max]; - std::vector m_childPacks; - DLCPack *m_parentPack; + std::vector m_files[DLCManager::e_DLCType_Max]; + std::vector m_childPacks; + DLCPack* m_parentPack; - std::unordered_map m_parameters; + std::unordered_map m_parameters; - std::wstring m_packName; - std::wstring m_dataPath; - std::uint32_t m_dwLicenseMask; - int m_dlcMountIndex; - XCONTENTDEVICEID m_dlcDeviceID; + std::wstring m_packName; + std::wstring m_dataPath; + std::uint32_t m_dwLicenseMask; + int m_dlcMountIndex; + XCONTENTDEVICEID m_dlcDeviceID; #ifdef _XBOX_ONE - std::wstring m_wsProductId; + std::wstring m_wsProductId; #else - ULONGLONG m_ullFullOfferId; + ULONGLONG m_ullFullOfferId; #endif - bool m_isCorrupt; - std::uint32_t m_packId; - std::uint32_t m_packVersion; + bool m_isCorrupt; + std::uint32_t m_packId; + std::uint32_t m_packVersion; - std::uint8_t *m_data; // This pointer is for all the data used for this pack, so deleting it invalidates ALL of it's children. + std::uint8_t* + m_data; // This pointer is for all the data used for this pack, so + // deleting it invalidates ALL of it's children. public: - - DLCPack(const std::wstring &name,std::uint32_t dwLicenseMask); + DLCPack(const std::wstring& name, std::uint32_t dwLicenseMask); #ifdef _XBOX_ONE - DLCPack(const std::wstring &name,const std::wstring &productID,std::uint32_t dwLicenseMask); + DLCPack(const std::wstring& name, const std::wstring& productID, + std::uint32_t dwLicenseMask); #endif - ~DLCPack(); + ~DLCPack(); - std::wstring getFullDataPath() { return m_dataPath; } + std::wstring getFullDataPath() { return m_dataPath; } - void SetDataPointer(std::uint8_t *pbData) { m_data = pbData; } + void SetDataPointer(std::uint8_t* pbData) { m_data = pbData; } - bool IsCorrupt() { return m_isCorrupt; } - void SetIsCorrupt(bool val) { m_isCorrupt = val; } + bool IsCorrupt() { return m_isCorrupt; } + void SetIsCorrupt(bool val) { m_isCorrupt = val; } - void SetPackId(std::uint32_t id) { m_packId = id; } - std::uint32_t GetPackId() { return m_packId; } + void SetPackId(std::uint32_t id) { m_packId = id; } + std::uint32_t GetPackId() { return m_packId; } - void SetPackVersion(std::uint32_t version) { m_packVersion = version; } - std::uint32_t GetPackVersion() { return m_packVersion; } + void SetPackVersion(std::uint32_t version) { m_packVersion = version; } + std::uint32_t GetPackVersion() { return m_packVersion; } - DLCPack * GetParentPack() { return m_parentPack; } - std::uint32_t GetParentPackId() { return m_parentPack->m_packId; } + DLCPack* GetParentPack() { return m_parentPack; } + std::uint32_t GetParentPackId() { return m_parentPack->m_packId; } - void SetDLCMountIndex(int id) { m_dlcMountIndex = id; } - int GetDLCMountIndex(); - void SetDLCDeviceID(XCONTENTDEVICEID deviceId) { m_dlcDeviceID = deviceId; } - XCONTENTDEVICEID GetDLCDeviceID(); + void SetDLCMountIndex(int id) { m_dlcMountIndex = id; } + int GetDLCMountIndex(); + void SetDLCDeviceID(XCONTENTDEVICEID deviceId) { m_dlcDeviceID = deviceId; } + XCONTENTDEVICEID GetDLCDeviceID(); - void addChildPack(DLCPack *childPack); - void setParentPack(DLCPack *parentPack); + void addChildPack(DLCPack* childPack); + void setParentPack(DLCPack* parentPack); - void addParameter(DLCManager::EDLCParameterType type, const std::wstring &value); - bool getParameterAsUInt(DLCManager::EDLCParameterType type, unsigned int ¶m); + void addParameter(DLCManager::EDLCParameterType type, + const std::wstring& value); + bool getParameterAsUInt(DLCManager::EDLCParameterType type, + unsigned int& param); - void updateLicenseMask(std::uint32_t dwLicenseMask) { m_dwLicenseMask = dwLicenseMask; } - std::uint32_t getLicenseMask() { return m_dwLicenseMask; } - - std::wstring getName() { return m_packName; } + void updateLicenseMask(std::uint32_t dwLicenseMask) { + m_dwLicenseMask = dwLicenseMask; + } + std::uint32_t getLicenseMask() { return m_dwLicenseMask; } + + std::wstring getName() { return m_packName; } #ifdef _XBOX_ONE - std::wstring getPurchaseOfferId() { return m_wsProductId; } + std::wstring getPurchaseOfferId() { return m_wsProductId; } #else - ULONGLONG getPurchaseOfferId() { return m_ullFullOfferId; } + ULONGLONG getPurchaseOfferId() { return m_ullFullOfferId; } #endif - DLCFile *addFile(DLCManager::EDLCType type, const std::wstring &path); - DLCFile *getFile(DLCManager::EDLCType type, unsigned int index); - DLCFile *getFile(DLCManager::EDLCType type, const std::wstring &path); + DLCFile* addFile(DLCManager::EDLCType type, const std::wstring& path); + DLCFile* getFile(DLCManager::EDLCType type, unsigned int index); + DLCFile* getFile(DLCManager::EDLCType type, const std::wstring& path); - unsigned int getDLCItemsCount(DLCManager::EDLCType type = DLCManager::e_DLCType_All); - unsigned int getFileIndexAt(DLCManager::EDLCType type, const std::wstring &path, bool &found); - bool doesPackContainFile(DLCManager::EDLCType type, const std::wstring &path); - std::uint32_t GetPackID() {return m_packId;} - - unsigned int getSkinCount() { return getDLCItemsCount(DLCManager::e_DLCType_Skin); } - unsigned int getSkinIndexAt(const std::wstring &path, bool &found) { return getFileIndexAt(DLCManager::e_DLCType_Skin, path, found); } - DLCSkinFile *getSkinFile(const std::wstring &path) { return (DLCSkinFile *)getFile(DLCManager::e_DLCType_Skin, path); } - DLCSkinFile *getSkinFile(unsigned int index) { return (DLCSkinFile *)getFile(DLCManager::e_DLCType_Skin, index); } - bool doesPackContainSkin(const std::wstring &path) { return doesPackContainFile(DLCManager::e_DLCType_Skin, path); } + unsigned int getDLCItemsCount( + DLCManager::EDLCType type = DLCManager::e_DLCType_All); + unsigned int getFileIndexAt(DLCManager::EDLCType type, + const std::wstring& path, bool& found); + bool doesPackContainFile(DLCManager::EDLCType type, + const std::wstring& path); + std::uint32_t GetPackID() { return m_packId; } - bool hasPurchasedFile(DLCManager::EDLCType type, const std::wstring &path); + unsigned int getSkinCount() { + return getDLCItemsCount(DLCManager::e_DLCType_Skin); + } + unsigned int getSkinIndexAt(const std::wstring& path, bool& found) { + return getFileIndexAt(DLCManager::e_DLCType_Skin, path, found); + } + DLCSkinFile* getSkinFile(const std::wstring& path) { + return (DLCSkinFile*)getFile(DLCManager::e_DLCType_Skin, path); + } + DLCSkinFile* getSkinFile(unsigned int index) { + return (DLCSkinFile*)getFile(DLCManager::e_DLCType_Skin, index); + } + bool doesPackContainSkin(const std::wstring& path) { + return doesPackContainFile(DLCManager::e_DLCType_Skin, path); + } + + bool hasPurchasedFile(DLCManager::EDLCType type, const std::wstring& path); }; diff --git a/Minecraft.Client/Platform/Common/DLC/DLCSkinFile.cpp b/Minecraft.Client/Platform/Common/DLC/DLCSkinFile.cpp index 6d82d0d57..54f000fff 100644 --- a/Minecraft.Client/Platform/Common/DLC/DLCSkinFile.cpp +++ b/Minecraft.Client/Platform/Common/DLC/DLCSkinFile.cpp @@ -7,166 +7,139 @@ #include "../../Minecraft.World/Player/Player.h" #include "../../Minecraft.World/Util/StringHelpers.h" -DLCSkinFile::DLCSkinFile(const std::wstring &path) : DLCFile(DLCManager::e_DLCType_Skin,path) -{ - m_displayName = L""; - m_themeName = L""; - m_cape = L""; - m_bIsFree = false; - m_uiAnimOverrideBitmask=0L; +DLCSkinFile::DLCSkinFile(const std::wstring& path) + : DLCFile(DLCManager::e_DLCType_Skin, path) { + m_displayName = L""; + m_themeName = L""; + m_cape = L""; + m_bIsFree = false; + m_uiAnimOverrideBitmask = 0L; } -void DLCSkinFile::addData(std::uint8_t *pbData, std::uint32_t dataBytes) -{ - app.AddMemoryTextureFile(m_path,pbData,dataBytes); +void DLCSkinFile::addData(std::uint8_t* pbData, std::uint32_t dataBytes) { + app.AddMemoryTextureFile(m_path, pbData, dataBytes); } -void DLCSkinFile::addParameter(DLCManager::EDLCParameterType type, const std::wstring &value) -{ - switch(type) - { - case DLCManager::e_DLCParamType_DisplayName: - { - // 4J Stu - In skin pack 2, the name for Zap is mis-spelt with two p's as Zapp - // dlcskin00000109.png - if( m_path.compare(L"dlcskin00000109.png") == 0) - { - m_displayName = L"Zap"; - } - else - { - m_displayName = value; - } - } - break; - case DLCManager::e_DLCParamType_ThemeName: - m_themeName = value; - break; - case DLCManager::e_DLCParamType_Free: // If this parameter exists, then mark this as free - m_bIsFree = true; - break; - case DLCManager::e_DLCParamType_Credit: // If this parameter exists, then mark this as free - //add it to the DLC credits list +void DLCSkinFile::addParameter(DLCManager::EDLCParameterType type, + const std::wstring& value) { + switch (type) { + case DLCManager::e_DLCParamType_DisplayName: { + // 4J Stu - In skin pack 2, the name for Zap is mis-spelt with two + // p's as Zapp dlcskin00000109.png + if (m_path.compare(L"dlcskin00000109.png") == 0) { + m_displayName = L"Zap"; + } else { + m_displayName = value; + } + } break; + case DLCManager::e_DLCParamType_ThemeName: + m_themeName = value; + break; + case DLCManager::e_DLCParamType_Free: // If this parameter exists, then + // mark this as free + m_bIsFree = true; + break; + case DLCManager::e_DLCParamType_Credit: // If this parameter exists, + // then mark this as free + // add it to the DLC credits + // list - // we'll need to justify this text since we don't have a lot of room for lines of credits - { - if(app.AlreadySeenCreditText(value)) break; - // first add a blank string for spacing - app.AddCreditText(L""); + // we'll need to justify this text since we don't have a lot of room + // for lines of credits + { + if (app.AlreadySeenCreditText(value)) break; + // first add a blank string for spacing + app.AddCreditText(L""); - int maximumChars = 55; + int maximumChars = 55; - bool bIsSDMode=!RenderManager.IsHiDef() && !RenderManager.IsWidescreen(); + bool bIsSDMode = + !RenderManager.IsHiDef() && !RenderManager.IsWidescreen(); - if(bIsSDMode) - { - maximumChars = 45; - } + if (bIsSDMode) { + maximumChars = 45; + } - switch(XGetLanguage()) - { - case XC_LANGUAGE_JAPANESE: - case XC_LANGUAGE_TCHINESE: - case XC_LANGUAGE_KOREAN: - maximumChars = 35; - break; - default: - break; - } - std::wstring creditValue = value; - while (creditValue.length() > maximumChars) - { - unsigned int i = 1; - while (i < creditValue.length() && (i + 1) <= maximumChars) - { - i++; - } - int iLast=(int)creditValue.find_last_of(L" ",i); - switch(XGetLanguage()) - { - case XC_LANGUAGE_JAPANESE: - case XC_LANGUAGE_TCHINESE: - case XC_LANGUAGE_KOREAN: - iLast = maximumChars; - break; - default: - iLast=(int)creditValue.find_last_of(L" ",i); - break; - } + switch (XGetLanguage()) { + case XC_LANGUAGE_JAPANESE: + case XC_LANGUAGE_TCHINESE: + case XC_LANGUAGE_KOREAN: + maximumChars = 35; + break; + default: + break; + } + std::wstring creditValue = value; + while (creditValue.length() > maximumChars) { + unsigned int i = 1; + while (i < creditValue.length() && + (i + 1) <= maximumChars) { + i++; + } + int iLast = (int)creditValue.find_last_of(L" ", i); + switch (XGetLanguage()) { + case XC_LANGUAGE_JAPANESE: + case XC_LANGUAGE_TCHINESE: + case XC_LANGUAGE_KOREAN: + iLast = maximumChars; + break; + default: + iLast = (int)creditValue.find_last_of(L" ", i); + break; + } - // if a space was found, include the space on this line - if(iLast!=i) - { - iLast++; - } - - app.AddCreditText((creditValue.substr(0, iLast)).c_str()); - creditValue = creditValue.substr(iLast); - } - app.AddCreditText(creditValue.c_str()); + // if a space was found, include the space on this line + if (iLast != i) { + iLast++; + } - } - break; - case DLCManager::e_DLCParamType_Cape: - m_cape = value; - break; - case DLCManager::e_DLCParamType_Box: - { - WCHAR wchBodyPart[10]; - SKIN_BOX *pSkinBox = new SKIN_BOX; - ZeroMemory(pSkinBox,sizeof(SKIN_BOX)); + app.AddCreditText((creditValue.substr(0, iLast)).c_str()); + creditValue = creditValue.substr(iLast); + } + app.AddCreditText(creditValue.c_str()); + } + break; + case DLCManager::e_DLCParamType_Cape: + m_cape = value; + break; + case DLCManager::e_DLCParamType_Box: { + WCHAR wchBodyPart[10]; + SKIN_BOX* pSkinBox = new SKIN_BOX; + ZeroMemory(pSkinBox, sizeof(SKIN_BOX)); - // 4J Stu - The Xbox version used swscanf_s which isn't available in GCC. - swscanf(value.c_str(), L"%10ls%f%f%f%f%f%f%f%f", wchBodyPart, - &pSkinBox->fX, - &pSkinBox->fY, - &pSkinBox->fZ, - &pSkinBox->fW, - &pSkinBox->fH, - &pSkinBox->fD, - &pSkinBox->fU, - &pSkinBox->fV); - - if(wcscmp(wchBodyPart,L"HEAD")==0) - { - pSkinBox->ePart=eBodyPart_Head; - } - else if(wcscmp(wchBodyPart,L"BODY")==0) - { - pSkinBox->ePart=eBodyPart_Body; - } - else if(wcscmp(wchBodyPart,L"ARM0")==0) - { - pSkinBox->ePart=eBodyPart_Arm0; - } - else if(wcscmp(wchBodyPart,L"ARM1")==0) - { - pSkinBox->ePart=eBodyPart_Arm1; - } - else if(wcscmp(wchBodyPart,L"LEG0")==0) - { - pSkinBox->ePart=eBodyPart_Leg0; - } - else if(wcscmp(wchBodyPart,L"LEG1")==0) - { - pSkinBox->ePart=eBodyPart_Leg1; - } + // 4J Stu - The Xbox version used swscanf_s which isn't available in + // GCC. + swscanf(value.c_str(), L"%10ls%f%f%f%f%f%f%f%f", wchBodyPart, + &pSkinBox->fX, &pSkinBox->fY, &pSkinBox->fZ, &pSkinBox->fW, + &pSkinBox->fH, &pSkinBox->fD, &pSkinBox->fU, &pSkinBox->fV); - // add this to the skin's vector of parts - m_AdditionalBoxes.push_back(pSkinBox); - } - break; - case DLCManager::e_DLCParamType_Anim: - { - // 4J Stu - The Xbox version used swscanf_s which isn't available in GCC. - swscanf(value.c_str(), L"%X", &m_uiAnimOverrideBitmask); - std::uint32_t skinId = app.getSkinIdFromPath(m_path); - app.SetAnimOverrideBitmask(skinId, m_uiAnimOverrideBitmask); - } - break; - default: - break; - } + if (wcscmp(wchBodyPart, L"HEAD") == 0) { + pSkinBox->ePart = eBodyPart_Head; + } else if (wcscmp(wchBodyPart, L"BODY") == 0) { + pSkinBox->ePart = eBodyPart_Body; + } else if (wcscmp(wchBodyPart, L"ARM0") == 0) { + pSkinBox->ePart = eBodyPart_Arm0; + } else if (wcscmp(wchBodyPart, L"ARM1") == 0) { + pSkinBox->ePart = eBodyPart_Arm1; + } else if (wcscmp(wchBodyPart, L"LEG0") == 0) { + pSkinBox->ePart = eBodyPart_Leg0; + } else if (wcscmp(wchBodyPart, L"LEG1") == 0) { + pSkinBox->ePart = eBodyPart_Leg1; + } + + // add this to the skin's vector of parts + m_AdditionalBoxes.push_back(pSkinBox); + } break; + case DLCManager::e_DLCParamType_Anim: { + // 4J Stu - The Xbox version used swscanf_s which isn't available in + // GCC. + swscanf(value.c_str(), L"%X", &m_uiAnimOverrideBitmask); + std::uint32_t skinId = app.getSkinIdFromPath(m_path); + app.SetAnimOverrideBitmask(skinId, m_uiAnimOverrideBitmask); + } break; + default: + break; + } } // std::vector *DLCSkinFile::getAdditionalModelParts() @@ -174,37 +147,32 @@ void DLCSkinFile::addParameter(DLCManager::EDLCParameterType type, const std::ws // return &m_AdditionalModelParts; // } -int DLCSkinFile::getAdditionalBoxesCount() -{ - return (int)m_AdditionalBoxes.size(); +int DLCSkinFile::getAdditionalBoxesCount() { + return (int)m_AdditionalBoxes.size(); } -std::vector *DLCSkinFile::getAdditionalBoxes() -{ - return &m_AdditionalBoxes; +std::vector* DLCSkinFile::getAdditionalBoxes() { + return &m_AdditionalBoxes; } -std::wstring DLCSkinFile::getParameterAsString(DLCManager::EDLCParameterType type) -{ - switch(type) - { - case DLCManager::e_DLCParamType_DisplayName: - return m_displayName; - case DLCManager::e_DLCParamType_ThemeName: - return m_themeName; - case DLCManager::e_DLCParamType_Cape: - return m_cape; - default: - return L""; - } +std::wstring DLCSkinFile::getParameterAsString( + DLCManager::EDLCParameterType type) { + switch (type) { + case DLCManager::e_DLCParamType_DisplayName: + return m_displayName; + case DLCManager::e_DLCParamType_ThemeName: + return m_themeName; + case DLCManager::e_DLCParamType_Cape: + return m_cape; + default: + return L""; + } } -bool DLCSkinFile::getParameterAsBool(DLCManager::EDLCParameterType type) -{ - switch(type) - { - case DLCManager::e_DLCParamType_Free: - return m_bIsFree; - default: - return false; - } +bool DLCSkinFile::getParameterAsBool(DLCManager::EDLCParameterType type) { + switch (type) { + case DLCManager::e_DLCParamType_Free: + return m_bIsFree; + default: + return false; + } } diff --git a/Minecraft.Client/Platform/Common/DLC/DLCSkinFile.h b/Minecraft.Client/Platform/Common/DLC/DLCSkinFile.h index 9a41b7d44..c0facea6c 100644 --- a/Minecraft.Client/Platform/Common/DLC/DLCSkinFile.h +++ b/Minecraft.Client/Platform/Common/DLC/DLCSkinFile.h @@ -2,28 +2,27 @@ #include "DLCFile.h" #include "../../Minecraft.Client/Rendering/Models/HumanoidModel.h" -class DLCSkinFile : public DLCFile -{ - +class DLCSkinFile : public DLCFile { private: - std::wstring m_displayName; - std::wstring m_themeName; - std::wstring m_cape; - unsigned int m_uiAnimOverrideBitmask; - bool m_bIsFree; - std::vector m_AdditionalBoxes; + std::wstring m_displayName; + std::wstring m_themeName; + std::wstring m_cape; + unsigned int m_uiAnimOverrideBitmask; + bool m_bIsFree; + std::vector m_AdditionalBoxes; public: + DLCSkinFile(const std::wstring& path); - DLCSkinFile(const std::wstring &path); + virtual void addData(std::uint8_t* pbData, std::uint32_t dataBytes); + virtual void addParameter(DLCManager::EDLCParameterType type, + const std::wstring& value); - virtual void addData(std::uint8_t *pbData, std::uint32_t dataBytes); - virtual void addParameter(DLCManager::EDLCParameterType type, const std::wstring &value); - - virtual std::wstring getParameterAsString(DLCManager::EDLCParameterType type); - virtual bool getParameterAsBool(DLCManager::EDLCParameterType type); - std::vector *getAdditionalBoxes(); - int getAdditionalBoxesCount(); - unsigned int getAnimOverrideBitmask() { return m_uiAnimOverrideBitmask;} - bool isFree() {return m_bIsFree;} + virtual std::wstring getParameterAsString( + DLCManager::EDLCParameterType type); + virtual bool getParameterAsBool(DLCManager::EDLCParameterType type); + std::vector* getAdditionalBoxes(); + int getAdditionalBoxesCount(); + unsigned int getAnimOverrideBitmask() { return m_uiAnimOverrideBitmask; } + bool isFree() { return m_bIsFree; } }; diff --git a/Minecraft.Client/Platform/Common/DLC/DLCTextureFile.cpp b/Minecraft.Client/Platform/Common/DLC/DLCTextureFile.cpp index 7f8a500fe..2b01d492d 100644 --- a/Minecraft.Client/Platform/Common/DLC/DLCTextureFile.cpp +++ b/Minecraft.Client/Platform/Common/DLC/DLCTextureFile.cpp @@ -2,60 +2,54 @@ #include "DLCManager.h" #include "DLCTextureFile.h" -DLCTextureFile::DLCTextureFile(const std::wstring &path) : DLCFile(DLCManager::e_DLCType_Texture,path) -{ - m_bIsAnim = false; - m_animString = L""; - - m_pbData = NULL; - m_dataBytes = 0; +DLCTextureFile::DLCTextureFile(const std::wstring& path) + : DLCFile(DLCManager::e_DLCType_Texture, path) { + m_bIsAnim = false; + m_animString = L""; + + m_pbData = NULL; + m_dataBytes = 0; } -void DLCTextureFile::addData(std::uint8_t *pbData, std::uint32_t dataBytes) -{ - //app.AddMemoryTextureFile(m_path,pbData,dwBytes); - m_pbData = pbData; - m_dataBytes = dataBytes; +void DLCTextureFile::addData(std::uint8_t* pbData, std::uint32_t dataBytes) { + // app.AddMemoryTextureFile(m_path,pbData,dwBytes); + m_pbData = pbData; + m_dataBytes = dataBytes; } -std::uint8_t *DLCTextureFile::getData(std::uint32_t &dataBytes) -{ - dataBytes = m_dataBytes; - return m_pbData; +std::uint8_t* DLCTextureFile::getData(std::uint32_t& dataBytes) { + dataBytes = m_dataBytes; + return m_pbData; } -void DLCTextureFile::addParameter(DLCManager::EDLCParameterType type, const std::wstring &value) -{ - switch(type) - { - case DLCManager::e_DLCParamType_Anim: - m_animString = value; - m_bIsAnim = true; +void DLCTextureFile::addParameter(DLCManager::EDLCParameterType type, + const std::wstring& value) { + switch (type) { + case DLCManager::e_DLCParamType_Anim: + m_animString = value; + m_bIsAnim = true; - break; - default: - break; - } + break; + default: + break; + } } -std::wstring DLCTextureFile::getParameterAsString(DLCManager::EDLCParameterType type) -{ - switch(type) - { - case DLCManager::e_DLCParamType_Anim: - return m_animString; - default: - return L""; - } +std::wstring DLCTextureFile::getParameterAsString( + DLCManager::EDLCParameterType type) { + switch (type) { + case DLCManager::e_DLCParamType_Anim: + return m_animString; + default: + return L""; + } } -bool DLCTextureFile::getParameterAsBool(DLCManager::EDLCParameterType type) -{ - switch(type) - { - case DLCManager::e_DLCParamType_Anim: - return m_bIsAnim; - default: - return false; - } +bool DLCTextureFile::getParameterAsBool(DLCManager::EDLCParameterType type) { + switch (type) { + case DLCManager::e_DLCParamType_Anim: + return m_bIsAnim; + default: + return false; + } } diff --git a/Minecraft.Client/Platform/Common/DLC/DLCTextureFile.h b/Minecraft.Client/Platform/Common/DLC/DLCTextureFile.h index baec5e951..bb25336ab 100644 --- a/Minecraft.Client/Platform/Common/DLC/DLCTextureFile.h +++ b/Minecraft.Client/Platform/Common/DLC/DLCTextureFile.h @@ -1,24 +1,24 @@ #pragma once #include "DLCFile.h" -class DLCTextureFile : public DLCFile -{ - +class DLCTextureFile : public DLCFile { private: - bool m_bIsAnim; - std::wstring m_animString; + bool m_bIsAnim; + std::wstring m_animString; - std::uint8_t *m_pbData; - std::uint32_t m_dataBytes; + std::uint8_t* m_pbData; + std::uint32_t m_dataBytes; public: - DLCTextureFile(const std::wstring &path); + DLCTextureFile(const std::wstring& path); - virtual void addData(std::uint8_t *pbData, std::uint32_t dataBytes); - virtual std::uint8_t *getData(std::uint32_t &dataBytes); + virtual void addData(std::uint8_t* pbData, std::uint32_t dataBytes); + virtual std::uint8_t* getData(std::uint32_t& dataBytes); - virtual void addParameter(DLCManager::EDLCParameterType type, const std::wstring &value); + virtual void addParameter(DLCManager::EDLCParameterType type, + const std::wstring& value); - virtual std::wstring getParameterAsString(DLCManager::EDLCParameterType type); - virtual bool getParameterAsBool(DLCManager::EDLCParameterType type); + virtual std::wstring getParameterAsString( + DLCManager::EDLCParameterType type); + virtual bool getParameterAsBool(DLCManager::EDLCParameterType type); }; diff --git a/Minecraft.Client/Platform/Common/DLC/DLCUIDataFile.cpp b/Minecraft.Client/Platform/Common/DLC/DLCUIDataFile.cpp index eb6d28220..4ea2138c0 100644 --- a/Minecraft.Client/Platform/Common/DLC/DLCUIDataFile.cpp +++ b/Minecraft.Client/Platform/Common/DLC/DLCUIDataFile.cpp @@ -2,31 +2,28 @@ #include "DLCManager.h" #include "DLCUIDataFile.h" -DLCUIDataFile::DLCUIDataFile(const std::wstring &path) : DLCFile(DLCManager::e_DLCType_UIData,path) -{ - m_pbData = NULL; - m_dataBytes = 0; - m_canDeleteData = false; +DLCUIDataFile::DLCUIDataFile(const std::wstring& path) + : DLCFile(DLCManager::e_DLCType_UIData, path) { + m_pbData = NULL; + m_dataBytes = 0; + m_canDeleteData = false; } -DLCUIDataFile::~DLCUIDataFile() -{ - if(m_canDeleteData && m_pbData != NULL) - { - app.DebugPrintf("Deleting DLCUIDataFile data\n"); - delete [] m_pbData; - } +DLCUIDataFile::~DLCUIDataFile() { + if (m_canDeleteData && m_pbData != NULL) { + app.DebugPrintf("Deleting DLCUIDataFile data\n"); + delete[] m_pbData; + } } -void DLCUIDataFile::addData(std::uint8_t *pbData, std::uint32_t dataBytes,bool canDeleteData) -{ - m_pbData = pbData; - m_dataBytes = dataBytes; - m_canDeleteData = canDeleteData; +void DLCUIDataFile::addData(std::uint8_t* pbData, std::uint32_t dataBytes, + bool canDeleteData) { + m_pbData = pbData; + m_dataBytes = dataBytes; + m_canDeleteData = canDeleteData; } -std::uint8_t *DLCUIDataFile::getData(std::uint32_t &dataBytes) -{ - dataBytes = m_dataBytes; - return m_pbData; +std::uint8_t* DLCUIDataFile::getData(std::uint32_t& dataBytes) { + dataBytes = m_dataBytes; + return m_pbData; } diff --git a/Minecraft.Client/Platform/Common/DLC/DLCUIDataFile.h b/Minecraft.Client/Platform/Common/DLC/DLCUIDataFile.h index a1ee86308..9676ac0dd 100644 --- a/Minecraft.Client/Platform/Common/DLC/DLCUIDataFile.h +++ b/Minecraft.Client/Platform/Common/DLC/DLCUIDataFile.h @@ -1,20 +1,20 @@ #pragma once #include "DLCFile.h" -class DLCUIDataFile : public DLCFile -{ +class DLCUIDataFile : public DLCFile { private: - std::uint8_t *m_pbData; - std::uint32_t m_dataBytes; - bool m_canDeleteData; + std::uint8_t* m_pbData; + std::uint32_t m_dataBytes; + bool m_canDeleteData; public: - DLCUIDataFile(const std::wstring &path); - ~DLCUIDataFile(); + DLCUIDataFile(const std::wstring& path); + ~DLCUIDataFile(); - using DLCFile::addData; - using DLCFile::addParameter; + using DLCFile::addData; + using DLCFile::addParameter; - virtual void addData(std::uint8_t *pbData, std::uint32_t dataBytes,bool canDeleteData = false); - virtual std::uint8_t *getData(std::uint32_t &dataBytes); + virtual void addData(std::uint8_t* pbData, std::uint32_t dataBytes, + bool canDeleteData = false); + virtual std::uint8_t* getData(std::uint32_t& dataBytes); }; diff --git a/Minecraft.Client/Platform/Common/Network/GameNetworkManager.cpp b/Minecraft.Client/Platform/Common/Network/GameNetworkManager.cpp index 6802521e8..625b526e7 100644 --- a/Minecraft.Client/Platform/Common/Network/GameNetworkManager.cpp +++ b/Minecraft.Client/Platform/Common/Network/GameNetworkManager.cpp @@ -6,6 +6,7 @@ #include "../../Minecraft.World/Util/ThreadName.h" #include "../../Minecraft.World/Entities/Entity.h" #include "../../Minecraft.World/Headers/net.minecraft.world.level.tile.h" +#include "../../Minecraft.World/Recipes/FireworksRecipe.h" #include "../../Minecraft.Client/Network/ClientConnection.h" #include "../../Minecraft.Client/Minecraft.h" #include "../../Minecraft.Client/Player/User.h" diff --git a/Minecraft.Client/Platform/Common/UI/IUIScene_CreativeMenu.cpp b/Minecraft.Client/Platform/Common/UI/IUIScene_CreativeMenu.cpp index 426d6deb1..28a3773b4 100644 --- a/Minecraft.Client/Platform/Common/UI/IUIScene_CreativeMenu.cpp +++ b/Minecraft.Client/Platform/Common/UI/IUIScene_CreativeMenu.cpp @@ -8,6 +8,9 @@ #include "../../Minecraft.World/Headers/net.minecraft.world.level.tile.entity.h" #include "../../Minecraft.World/Headers/net.minecraft.world.item.h" #include "../../Minecraft.World/Headers/net.minecraft.world.item.enchantment.h" +#include "../../Minecraft.World/Headers/net.minecraft.world.entity.h" +#include "../../Minecraft.World/Headers/net.minecraft.world.entity.animal.h" +#include "../../Minecraft.World/Util/JavaMath.h" // 4J JEV - Images for each tab. IUIScene_CreativeMenu::TabSpec** IUIScene_CreativeMenu::specs = NULL; diff --git a/Minecraft.Client/Platform/Common/UI/IUIScene_CreativeMenu.h b/Minecraft.Client/Platform/Common/UI/IUIScene_CreativeMenu.h index 4080cff2b..02967ac5a 100644 --- a/Minecraft.Client/Platform/Common/UI/IUIScene_CreativeMenu.h +++ b/Minecraft.Client/Platform/Common/UI/IUIScene_CreativeMenu.h @@ -63,6 +63,7 @@ public: unsigned int m_pages; unsigned int m_staticPerPage; unsigned int m_staticItems; + unsigned int m_debugItems; public: TabSpec(const wchar_t* icon, int descriptionId, int staticGroupsCount, @@ -96,13 +97,14 @@ public: virtual void loopClick(int slotIndex, int buttonNum, bool quickKeyHeld, std::shared_ptr player) {} // do nothing }* itemPickerMenu; - -protected: + + // 4jcraft: changed these two from public to protected for the java UI static std::vector > categoryGroups[eCreativeInventoryGroupsCount]; // 4J JEV - Tabs static TabSpec** specs; +public: bool m_bCarryingCreativeItem; int m_creativeSlotX, m_creativeSlotY, m_inventorySlotX, m_inventorySlotY; diff --git a/Minecraft.Client/Platform/Common/UI/UIComponent_Tooltips.cpp b/Minecraft.Client/Platform/Common/UI/UIComponent_Tooltips.cpp index d7e43362b..045f55afe 100644 --- a/Minecraft.Client/Platform/Common/UI/UIComponent_Tooltips.cpp +++ b/Minecraft.Client/Platform/Common/UI/UIComponent_Tooltips.cpp @@ -307,7 +307,7 @@ void UIComponent_Tooltips::_SetTooltip(unsigned int iToolTipId, UIString label, value[0].type = IGGY_DATATYPE_number; value[0].number = iToolTipId; - const std::u16string convLabel = convWstringToU16string(label); + const std::u16string convLabel = convWstringToU16string(label.getString()); value[1].type = IGGY_DATATYPE_string_UTF16; IggyStringUTF16 stringVal; diff --git a/Minecraft.Client/Platform/Common/UI/UIControl_Base.cpp b/Minecraft.Client/Platform/Common/UI/UIControl_Base.cpp index b35fae22c..4dd4fa4c8 100644 --- a/Minecraft.Client/Platform/Common/UI/UIControl_Base.cpp +++ b/Minecraft.Client/Platform/Common/UI/UIControl_Base.cpp @@ -29,7 +29,7 @@ void UIControl_Base::tick() { // app.DebugPrintf("Calling SetLabel - '%ls'\n", m_label.c_str()); m_bLabelChanged = false; - const std::u16string convLabel = convWstringToU16string(m_label); + const std::u16string convLabel = convWstringToU16string(m_label.getString()); IggyDataValue result; IggyDataValue value[1]; diff --git a/Minecraft.Client/Platform/Common/UI/UIControl_Button.cpp b/Minecraft.Client/Platform/Common/UI/UIControl_Button.cpp index 66e7857f5..be89d6012 100644 --- a/Minecraft.Client/Platform/Common/UI/UIControl_Button.cpp +++ b/Minecraft.Client/Platform/Common/UI/UIControl_Button.cpp @@ -19,7 +19,7 @@ void UIControl_Button::init(UIString label, int id) { m_label = label; m_id = id; - const std::u16string convLabel = convWstringToU16string(label); + const std::u16string convLabel = convWstringToU16string(label.getString()); IggyDataValue result; IggyDataValue value[2]; diff --git a/Minecraft.Client/Platform/Common/UI/UIControl_CheckBox.cpp b/Minecraft.Client/Platform/Common/UI/UIControl_CheckBox.cpp index 3abebc28c..ea1e771ef 100644 --- a/Minecraft.Client/Platform/Common/UI/UIControl_CheckBox.cpp +++ b/Minecraft.Client/Platform/Common/UI/UIControl_CheckBox.cpp @@ -19,12 +19,12 @@ bool UIControl_CheckBox::setupControl(UIScene* scene, IggyValuePath* parent, return success; } -void UIControl_CheckBox::init(const std::wstring& label, int id, bool checked) { +void UIControl_CheckBox::init(UIString label, int id, bool checked) { m_label = label; m_id = id; m_bChecked = checked; - const std::u16string convLabel = convWstringToU16string(label); + const std::u16string convLabel = convWstringToU16string(label.getString()); IggyDataValue result; IggyDataValue value[3]; diff --git a/Minecraft.Client/Platform/Common/UI/UIControl_Progress.cpp b/Minecraft.Client/Platform/Common/UI/UIControl_Progress.cpp index 0e44e7448..3f21a4ab8 100644 --- a/Minecraft.Client/Platform/Common/UI/UIControl_Progress.cpp +++ b/Minecraft.Client/Platform/Common/UI/UIControl_Progress.cpp @@ -30,7 +30,7 @@ void UIControl_Progress::init(UIString label, int id, int min, int max, m_max = max; m_current = current; - const std::u16string convLabel = convWstringToU16string(label); + const std::u16string convLabel = convWstringToU16string(label.getString()); IggyDataValue result; IggyDataValue value[1]; diff --git a/Minecraft.Client/Platform/Common/UI/UIControl_Slider.cpp b/Minecraft.Client/Platform/Common/UI/UIControl_Slider.cpp index 927ab921e..c72cba85e 100644 --- a/Minecraft.Client/Platform/Common/UI/UIControl_Slider.cpp +++ b/Minecraft.Client/Platform/Common/UI/UIControl_Slider.cpp @@ -29,7 +29,7 @@ void UIControl_Slider::init(UIString label, int id, int min, int max, m_max = max; m_current = current; - const std::u16string convLabel = convWstringToU16string(label); + const std::u16string convLabel = convWstringToU16string(label.getString()); IggyDataValue result; IggyDataValue value[5]; diff --git a/Minecraft.Client/Platform/Common/UI/UIControl_TextInput.cpp b/Minecraft.Client/Platform/Common/UI/UIControl_TextInput.cpp index 72c7e0f14..b2156bef5 100644 --- a/Minecraft.Client/Platform/Common/UI/UIControl_TextInput.cpp +++ b/Minecraft.Client/Platform/Common/UI/UIControl_TextInput.cpp @@ -1,6 +1,7 @@ #include "../../stdafx.h" #include "UI.h" #include "UIControl_TextInput.h" +#include "../../../Minecraft.World/Util/StringHelpers.h" UIControl_TextInput::UIControl_TextInput() { m_bHasFocus = false; } @@ -21,7 +22,7 @@ void UIControl_TextInput::init(UIString label, int id) { m_label = label; m_id = id; - const std::u16string convLabel = convWstringToU16string(label); + const std::u16string convLabel = convWstringToU16string(label.getString()); IggyDataValue result; IggyDataValue value[2]; diff --git a/Minecraft.Client/Platform/Common/UI/UIScene_AbstractContainerMenu.cpp b/Minecraft.Client/Platform/Common/UI/UIScene_AbstractContainerMenu.cpp index 92d146005..686ef0fb1 100644 --- a/Minecraft.Client/Platform/Common/UI/UIScene_AbstractContainerMenu.cpp +++ b/Minecraft.Client/Platform/Common/UI/UIScene_AbstractContainerMenu.cpp @@ -230,13 +230,13 @@ void UIScene_AbstractContainerMenu::customDraw( pMinecraft->localgameModes[m_iPad] == NULL) return; + int slotId = parseSlotId(region->name); std::shared_ptr item = nullptr; if (std::char_traits::compare(region->name, u"pointerIcon", 11) == 0) { m_cacheSlotRenders = false; item = pMinecraft->localplayers[m_iPad]->inventory->getCarried(); } else { - int slotId = parseSlotId(region->name); if (slotId == -1) { app.DebugPrintf("This is not the control we are looking for\n"); } else { diff --git a/Minecraft.Client/Platform/Common/UI/UIScene_BeaconMenu.cpp b/Minecraft.Client/Platform/Common/UI/UIScene_BeaconMenu.cpp index c1e1926a2..ba67a0a54 100644 --- a/Minecraft.Client/Platform/Common/UI/UIScene_BeaconMenu.cpp +++ b/Minecraft.Client/Platform/Common/UI/UIScene_BeaconMenu.cpp @@ -315,8 +315,7 @@ void UIScene_BeaconMenu::customDraw(IggyCustomDrawCallbackRegion* region) { return; std::shared_ptr item = nullptr; - int slotId = -1; - swscanf((wchar_t*)region->name, L"slot_%d", &slotId); + int slotId = parseSlotId(region->name); if (slotId >= 0 && slotId >= m_menu->getSize()) { int icon = slotId - m_menu->getSize(); diff --git a/Minecraft.Client/Platform/Common/UI/UIScene_CraftingMenu.cpp b/Minecraft.Client/Platform/Common/UI/UIScene_CraftingMenu.cpp index 3ad05f027..eeab7ea06 100644 --- a/Minecraft.Client/Platform/Common/UI/UIScene_CraftingMenu.cpp +++ b/Minecraft.Client/Platform/Common/UI/UIScene_CraftingMenu.cpp @@ -429,7 +429,8 @@ void UIScene_CraftingMenu::customDraw(IggyCustomDrawCallbackRegion* region) { float alpha = 1.0f; bool decorations = true; bool inventoryItem = false; - swscanf((wchar_t*)region->name, L"slot_%d", &slotId); + int slotId = parseSlotId(region->name); + if (slotId == -1) { app.DebugPrintf("This is not the control we are looking for\n"); } else if (slotId >= CRAFTING_INVENTORY_SLOT_START &&