the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 216 lines 5.7 kB view raw
1#include "stdafx.h" 2#include "DLCManager.h" 3#include "DLCAudioFile.h" 4#if defined _XBOX || defined _WINDOWS64 5#include "..\..\Xbox\XML\ATGXmlParser.h" 6#include "..\..\Xbox\XML\xmlFilesCallback.h" 7#endif 8 9DLCAudioFile::DLCAudioFile(const wstring &path) : DLCFile(DLCManager::e_DLCType_Audio,path) 10{ 11 m_pbData = NULL; 12 m_dwBytes = 0; 13} 14 15void DLCAudioFile::addData(PBYTE pbData, DWORD dwBytes) 16{ 17 m_pbData = pbData; 18 m_dwBytes = dwBytes; 19 20 processDLCDataFile(pbData,dwBytes); 21} 22 23PBYTE DLCAudioFile::getData(DWORD &dwBytes) 24{ 25 dwBytes = m_dwBytes; 26 return m_pbData; 27} 28 29WCHAR *DLCAudioFile::wchTypeNamesA[]= 30{ 31 L"CUENAME", 32 L"CREDIT", 33}; 34 35DLCAudioFile::EAudioParameterType DLCAudioFile::getParameterType(const wstring &paramName) 36{ 37 EAudioParameterType type = e_AudioParamType_Invalid; 38 39 for(DWORD i = 0; i < e_AudioParamType_Max; ++i) 40 { 41 if(paramName.compare(wchTypeNamesA[i]) == 0) 42 { 43 type = (EAudioParameterType)i; 44 break; 45 } 46 } 47 48 return type; 49} 50 51void DLCAudioFile::addParameter(EAudioType type, EAudioParameterType ptype, const wstring &value) 52{ 53 switch(ptype) 54 { 55 56 case e_AudioParamType_Credit: // If this parameter exists, then mark this as free 57 //add it to the DLC credits list 58 59 // we'll need to justify this text since we don't have a lot of room for lines of credits 60 { 61 // don't look for duplicate in the music credits 62 63 //if(app.AlreadySeenCreditText(value)) break; 64 65 int maximumChars = 55; 66 67 bool bIsSDMode=!RenderManager.IsHiDef() && !RenderManager.IsWidescreen(); 68 69 if(bIsSDMode) 70 { 71 maximumChars = 45; 72 } 73 74 switch(XGetLanguage()) 75 { 76 case XC_LANGUAGE_JAPANESE: 77 case XC_LANGUAGE_TCHINESE: 78 case XC_LANGUAGE_KOREAN: 79 maximumChars = 35; 80 break; 81 } 82 wstring creditValue = value; 83 while (creditValue.length() > maximumChars) 84 { 85 unsigned int i = 1; 86 while (i < creditValue.length() && (i + 1) <= maximumChars) 87 { 88 i++; 89 } 90 int iLast=(int)creditValue.find_last_of(L" ",i); 91 switch(XGetLanguage()) 92 { 93 case XC_LANGUAGE_JAPANESE: 94 case XC_LANGUAGE_TCHINESE: 95 case XC_LANGUAGE_KOREAN: 96 iLast = maximumChars; 97 break; 98 default: 99 iLast=(int)creditValue.find_last_of(L" ",i); 100 break; 101 } 102 103 // if a space was found, include the space on this line 104 if(iLast!=i) 105 { 106 iLast++; 107 } 108 109 app.AddCreditText((creditValue.substr(0, iLast)).c_str()); 110 creditValue = creditValue.substr(iLast); 111 } 112 app.AddCreditText(creditValue.c_str()); 113 114 } 115 break; 116 case e_AudioParamType_Cuename: 117 m_parameters[type].push_back(value); 118 //m_parameters[(int)type] = value; 119 break; 120 } 121} 122 123bool DLCAudioFile::processDLCDataFile(PBYTE pbData, DWORD dwLength) 124{ 125 unordered_map<int, EAudioParameterType> parameterMapping; 126 unsigned int uiCurrentByte=0; 127 128 // File format defined in the AudioPacker 129 // File format: Version 1 130 131 unsigned int uiVersion=*(unsigned int *)pbData; 132 uiCurrentByte+=sizeof(int); 133 134 if(uiVersion < CURRENT_AUDIO_VERSION_NUM) 135 { 136 if(pbData!=NULL) delete [] pbData; 137 app.DebugPrintf("DLC version of %d is too old to be read\n", uiVersion); 138 return false; 139 } 140 141 unsigned int uiParameterTypeCount=*(unsigned int *)&pbData[uiCurrentByte]; 142 uiCurrentByte+=sizeof(int); 143 C4JStorage::DLC_FILE_PARAM *pParams = (C4JStorage::DLC_FILE_PARAM *)&pbData[uiCurrentByte]; 144 145 for(unsigned int i=0;i<uiParameterTypeCount;i++) 146 { 147 // Map DLC strings to application strings, then store the DLC index mapping to application index 148 wstring parameterName((WCHAR *)pParams->wchData); 149 EAudioParameterType type = getParameterType(parameterName); 150 if( type != e_AudioParamType_Invalid ) 151 { 152 parameterMapping[pParams->dwType] = type; 153 } 154 uiCurrentByte+= sizeof(C4JStorage::DLC_FILE_PARAM)+(pParams->dwWchCount*sizeof(WCHAR)); 155 pParams = (C4JStorage::DLC_FILE_PARAM *)&pbData[uiCurrentByte]; 156 } 157 unsigned int uiFileCount=*(unsigned int *)&pbData[uiCurrentByte]; 158 uiCurrentByte+=sizeof(int); 159 C4JStorage::DLC_FILE_DETAILS *pFile = (C4JStorage::DLC_FILE_DETAILS *)&pbData[uiCurrentByte]; 160 161 DWORD dwTemp=uiCurrentByte; 162 for(unsigned int i=0;i<uiFileCount;i++) 163 { 164 dwTemp+=sizeof(C4JStorage::DLC_FILE_DETAILS)+pFile->dwWchCount*sizeof(WCHAR); 165 pFile = (C4JStorage::DLC_FILE_DETAILS *)&pbData[dwTemp]; 166 } 167 PBYTE pbTemp=((PBYTE )pFile); 168 pFile = (C4JStorage::DLC_FILE_DETAILS *)&pbData[uiCurrentByte]; 169 170 for(unsigned int i=0;i<uiFileCount;i++) 171 { 172 EAudioType type = (EAudioType)pFile->dwType; 173 // Params 174 unsigned int uiParameterCount=*(unsigned int *)pbTemp; 175 pbTemp+=sizeof(int); 176 pParams = (C4JStorage::DLC_FILE_PARAM *)pbTemp; 177 for(unsigned int j=0;j<uiParameterCount;j++) 178 { 179 //EAudioParameterType paramType = e_AudioParamType_Invalid; 180 181 AUTO_VAR(it, parameterMapping.find( pParams->dwType )); 182 183 if(it != parameterMapping.end() ) 184 { 185 addParameter(type,(EAudioParameterType)pParams->dwType,(WCHAR *)pParams->wchData); 186 } 187 pbTemp+=sizeof(C4JStorage::DLC_FILE_PARAM)+(sizeof(WCHAR)*pParams->dwWchCount); 188 pParams = (C4JStorage::DLC_FILE_PARAM *)pbTemp; 189 } 190 // Move the pointer to the start of the next files data; 191 pbTemp+=pFile->uiFileSize; 192 uiCurrentByte+=sizeof(C4JStorage::DLC_FILE_DETAILS)+pFile->dwWchCount*sizeof(WCHAR); 193 194 pFile=(C4JStorage::DLC_FILE_DETAILS *)&pbData[uiCurrentByte]; 195 196 } 197 198 return true; 199} 200 201int DLCAudioFile::GetCountofType(DLCAudioFile::EAudioType eType) 202{ 203 return m_parameters[eType].size(); 204} 205 206 207wstring &DLCAudioFile::GetSoundName(int iIndex) 208{ 209 int iWorldType=e_AudioType_Overworld; 210 while(iIndex>=m_parameters[iWorldType].size()) 211 { 212 iIndex-=m_parameters[iWorldType].size(); 213 iWorldType++; 214 } 215 return m_parameters[iWorldType].at(iIndex); 216}