the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
1#include "stdafx.h"
2#include <algorithm>
3#include "DLCManager.h"
4#include "DLCPack.h"
5#include "DLCFile.h"
6#include "..\..\..\Minecraft.World\StringHelpers.h"
7#include "..\..\Minecraft.h"
8#include "..\..\TexturePackRepository.h"
9
10WCHAR *DLCManager::wchTypeNamesA[]=
11{
12 L"DISPLAYNAME",
13 L"THEMENAME",
14 L"FREE",
15 L"CREDIT",
16 L"CAPEPATH",
17 L"BOX",
18 L"ANIM",
19 L"PACKID",
20 L"NETHERPARTICLECOLOUR",
21 L"ENCHANTTEXTCOLOUR",
22 L"ENCHANTTEXTFOCUSCOLOUR",
23 L"DATAPATH",
24 L"PACKVERSION",
25};
26
27DLCManager::DLCManager()
28{
29 //m_bNeedsUpdated = true;
30 m_bNeedsCorruptCheck = true;
31}
32
33DLCManager::~DLCManager()
34{
35 for(AUTO_VAR(it, m_packs.begin()); it != m_packs.end(); ++it)
36 {
37 DLCPack *pack = *it;
38 delete pack;
39 }
40}
41
42DLCManager::EDLCParameterType DLCManager::getParameterType(const wstring ¶mName)
43{
44 EDLCParameterType type = e_DLCParamType_Invalid;
45
46 for(DWORD i = 0; i < e_DLCParamType_Max; ++i)
47 {
48 if(paramName.compare(wchTypeNamesA[i]) == 0)
49 {
50 type = (EDLCParameterType)i;
51 break;
52 }
53 }
54
55 return type;
56}
57
58DWORD DLCManager::getPackCount(EDLCType type /*= e_DLCType_All*/)
59{
60 DWORD packCount = 0;
61 if( type != e_DLCType_All )
62 {
63 for(AUTO_VAR(it, m_packs.begin()); it != m_packs.end(); ++it)
64 {
65 DLCPack *pack = *it;
66 if( pack->getDLCItemsCount(type) > 0 )
67 {
68 ++packCount;
69 }
70 }
71 }
72 else
73 {
74 packCount = (DWORD)m_packs.size();
75 }
76 return packCount;
77}
78
79void DLCManager::addPack(DLCPack *pack)
80{
81 m_packs.push_back(pack);
82}
83
84void DLCManager::removePack(DLCPack *pack)
85{
86 if(pack != NULL)
87 {
88 AUTO_VAR(it, find(m_packs.begin(),m_packs.end(),pack));
89 if(it != m_packs.end() ) m_packs.erase(it);
90 delete pack;
91 }
92}
93
94void DLCManager::removeAllPacks(void)
95{
96 for(AUTO_VAR(it, m_packs.begin()); it != m_packs.end(); ++it)
97 {
98 DLCPack *pack = (DLCPack *)*it;
99 delete pack;
100 }
101
102 m_packs.clear();
103}
104
105void DLCManager::LanguageChanged(void)
106{
107 for(AUTO_VAR(it, m_packs.begin()); it != m_packs.end(); ++it)
108 {
109 DLCPack *pack = (DLCPack *)*it;
110 // update the language
111 pack->UpdateLanguage();
112 }
113
114}
115
116DLCPack *DLCManager::getPack(const wstring &name)
117{
118 DLCPack *pack = NULL;
119 //DWORD currentIndex = 0;
120 DLCPack *currentPack = NULL;
121 for(AUTO_VAR(it, m_packs.begin()); it != m_packs.end(); ++it)
122 {
123 currentPack = *it;
124 wstring wsName=currentPack->getName();
125
126 if(wsName.compare(name) == 0)
127 {
128 pack = currentPack;
129 break;
130 }
131 }
132 return pack;
133}
134
135#ifdef _XBOX_ONE
136DLCPack *DLCManager::getPackFromProductID(const wstring &productID)
137{
138 DLCPack *pack = NULL;
139 //DWORD currentIndex = 0;
140 DLCPack *currentPack = NULL;
141 for(AUTO_VAR(it, m_packs.begin()); it != m_packs.end(); ++it)
142 {
143 currentPack = *it;
144 wstring wsName=currentPack->getPurchaseOfferId();
145
146 if(wsName.compare(productID) == 0)
147 {
148 pack = currentPack;
149 break;
150 }
151 }
152 return pack;
153}
154#endif
155
156DLCPack *DLCManager::getPack(DWORD index, EDLCType type /*= e_DLCType_All*/)
157{
158 DLCPack *pack = NULL;
159 if( type != e_DLCType_All )
160 {
161 DWORD currentIndex = 0;
162 DLCPack *currentPack = NULL;
163 for(AUTO_VAR(it, m_packs.begin()); it != m_packs.end(); ++it)
164 {
165 currentPack = *it;
166 if(currentPack->getDLCItemsCount(type)>0)
167 {
168 if(currentIndex == index)
169 {
170 pack = currentPack;
171 break;
172 }
173 ++currentIndex;
174 }
175 }
176 }
177 else
178 {
179 if(index >= m_packs.size())
180 {
181 app.DebugPrintf("DLCManager: Trying to access a DLC pack beyond the range of valid packs\n");
182 __debugbreak();
183 }
184 pack = m_packs[index];
185 }
186
187 return pack;
188}
189
190DWORD DLCManager::getPackIndex(DLCPack *pack, bool &found, EDLCType type /*= e_DLCType_All*/)
191{
192 DWORD foundIndex = 0;
193 found = false;
194 if(pack == NULL)
195 {
196 app.DebugPrintf("DLCManager: Attempting to find the index for a NULL pack\n");
197 //__debugbreak();
198 return foundIndex;
199 }
200 if( type != e_DLCType_All )
201 {
202 DWORD index = 0;
203 for(AUTO_VAR(it, m_packs.begin()); it != m_packs.end(); ++it)
204 {
205 DLCPack *thisPack = *it;
206 if(thisPack->getDLCItemsCount(type)>0)
207 {
208 if(thisPack == pack)
209 {
210 found = true;
211 foundIndex = index;
212 break;
213 }
214 ++index;
215 }
216 }
217 }
218 else
219 {
220 DWORD index = 0;
221 for(AUTO_VAR(it, m_packs.begin()); it != m_packs.end(); ++it)
222 {
223 DLCPack *thisPack = *it;
224 if(thisPack == pack)
225 {
226 found = true;
227 foundIndex = index;
228 break;
229 }
230 ++index;
231 }
232 }
233 return foundIndex;
234}
235
236DWORD DLCManager::getPackIndexContainingSkin(const wstring &path, bool &found)
237{
238 DWORD foundIndex = 0;
239 found = false;
240 DWORD index = 0;
241 for(AUTO_VAR(it, m_packs.begin()); it != m_packs.end(); ++it)
242 {
243 DLCPack *pack = *it;
244 if(pack->getDLCItemsCount(e_DLCType_Skin)>0)
245 {
246 if(pack->doesPackContainSkin(path))
247 {
248 foundIndex = index;
249 found = true;
250 break;
251 }
252 ++index;
253 }
254 }
255 return foundIndex;
256}
257
258DLCPack *DLCManager::getPackContainingSkin(const wstring &path)
259{
260 DLCPack *foundPack = NULL;
261 for(AUTO_VAR(it, m_packs.begin()); it != m_packs.end(); ++it)
262 {
263 DLCPack *pack = *it;
264 if(pack->getDLCItemsCount(e_DLCType_Skin)>0)
265 {
266 if(pack->doesPackContainSkin(path))
267 {
268 foundPack = pack;
269 break;
270 }
271 }
272 }
273 return foundPack;
274}
275
276DLCSkinFile *DLCManager::getSkinFile(const wstring &path)
277{
278 DLCSkinFile *foundSkinfile = NULL;
279 for(AUTO_VAR(it, m_packs.begin()); it != m_packs.end(); ++it)
280 {
281 DLCPack *pack = *it;
282 foundSkinfile=pack->getSkinFile(path);
283 if(foundSkinfile!=NULL)
284 {
285 break;
286 }
287 }
288 return foundSkinfile;
289}
290
291DWORD DLCManager::checkForCorruptDLCAndAlert(bool showMessage /*= true*/)
292{
293 DWORD corruptDLCCount = m_dwUnnamedCorruptDLCCount;
294 DLCPack *pack = NULL;
295 DLCPack *firstCorruptPack = NULL;
296
297 for(AUTO_VAR(it, m_packs.begin()); it != m_packs.end(); ++it)
298 {
299 pack = *it;
300 if( pack->IsCorrupt() )
301 {
302 ++corruptDLCCount;
303 if(firstCorruptPack == NULL) firstCorruptPack = pack;
304 }
305 }
306
307 if(corruptDLCCount > 0 && showMessage)
308 {
309 UINT uiIDA[1];
310 uiIDA[0]=IDS_CONFIRM_OK;
311 if(corruptDLCCount == 1 && firstCorruptPack != NULL)
312 {
313 // pass in the pack format string
314 WCHAR wchFormat[132];
315 swprintf(wchFormat, 132, L"%ls\n\n%%ls", firstCorruptPack->getName().c_str());
316
317 C4JStorage::EMessageResult result = ui.RequestErrorMessage( IDS_CORRUPT_DLC_TITLE, IDS_CORRUPT_DLC, uiIDA,1,ProfileManager.GetPrimaryPad(),NULL,NULL,wchFormat);
318
319 }
320 else
321 {
322 C4JStorage::EMessageResult result = ui.RequestErrorMessage( IDS_CORRUPT_DLC_TITLE, IDS_CORRUPT_DLC_MULTIPLE, uiIDA,1,ProfileManager.GetPrimaryPad());
323 }
324 }
325
326 SetNeedsCorruptCheck(false);
327
328 return corruptDLCCount;
329}
330
331bool DLCManager::readDLCDataFile(DWORD &dwFilesProcessed, const wstring &path, DLCPack *pack, bool fromArchive)
332{
333 return readDLCDataFile( dwFilesProcessed, wstringtofilename(path), pack, fromArchive);
334}
335
336
337bool DLCManager::readDLCDataFile(DWORD &dwFilesProcessed, const string &path, DLCPack *pack, bool fromArchive)
338{
339 wstring wPath = convStringToWstring(path);
340 if (fromArchive && app.getArchiveFileSize(wPath) >= 0)
341 {
342 byteArray bytes = app.getArchiveFile(wPath);
343 return processDLCDataFile(dwFilesProcessed, bytes.data, bytes.length, pack);
344 }
345 else if (fromArchive) return false;
346
347#ifdef _WINDOWS64
348 string finalPath = StorageManager.GetMountedPath(path.c_str());
349 if(finalPath.size() == 0) finalPath = path;
350 HANDLE file = CreateFile(finalPath.c_str(), GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
351#elif defined(_DURANGO)
352 wstring finalPath = StorageManager.GetMountedPath(wPath.c_str());
353 if(finalPath.size() == 0) finalPath = wPath;
354 HANDLE file = CreateFile(finalPath.c_str(), GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
355#else
356 HANDLE file = CreateFile(path.c_str(), GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
357#endif
358 if( file == INVALID_HANDLE_VALUE )
359 {
360 DWORD error = GetLastError();
361 app.DebugPrintf("Failed to open DLC data file with error code %d (%x)\n", error, error);
362 if( dwFilesProcessed == 0 ) removePack(pack);
363 assert(false);
364 return false;
365 }
366
367 DWORD bytesRead,dwFileSize = GetFileSize(file,NULL);
368 PBYTE pbData = (PBYTE) new BYTE[dwFileSize];
369 BOOL bSuccess = ReadFile(file,pbData,dwFileSize,&bytesRead,NULL);
370 if(bSuccess==FALSE)
371 {
372 // need to treat the file as corrupt, and flag it, so can't call fatal error
373 //app.FatalLoadError();
374 }
375 else
376 {
377 CloseHandle(file);
378 }
379 if(bSuccess==FALSE)
380 {
381 // Corrupt or some other error. In any case treat as corrupt
382 app.DebugPrintf("Failed to read %s from DLC content package\n", path.c_str());
383 pack->SetIsCorrupt( true );
384 SetNeedsCorruptCheck(true);
385 return false;
386 }
387 return processDLCDataFile(dwFilesProcessed, pbData, bytesRead, pack);
388}
389
390bool DLCManager::processDLCDataFile(DWORD &dwFilesProcessed, PBYTE pbData, DWORD dwLength, DLCPack *pack)
391{
392 unordered_map<int, DLCManager::EDLCParameterType> parameterMapping;
393 unsigned int uiCurrentByte=0;
394
395 // File format defined in the DLC_Creator
396 // File format: Version 2
397 // unsigned long, version number
398 // unsigned long, t = number of parameter types
399 // t * DLC_FILE_PARAM structs mapping strings to id's
400 // unsigned long, n = number of files
401 // n * DLC_FILE_DETAILS describing each file in the pack
402 // n * files of the form
403 // // unsigned long, p = number of parameters
404 // // p * DLC_FILE_PARAM describing each parameter for this file
405 // // ulFileSize bytes of data blob of the file added
406 unsigned int uiVersion=*(unsigned int *)pbData;
407 uiCurrentByte+=sizeof(int);
408
409 if(uiVersion < CURRENT_DLC_VERSION_NUM)
410 {
411 if(pbData!=NULL) delete [] pbData;
412 app.DebugPrintf("DLC version of %d is too old to be read\n", uiVersion);
413 return false;
414 }
415 pack->SetDataPointer(pbData);
416 unsigned int uiParameterCount=*(unsigned int *)&pbData[uiCurrentByte];
417 uiCurrentByte+=sizeof(int);
418 C4JStorage::DLC_FILE_PARAM *pParams = (C4JStorage::DLC_FILE_PARAM *)&pbData[uiCurrentByte];
419 //DWORD dwwchCount=0;
420 for(unsigned int i=0;i<uiParameterCount;i++)
421 {
422 // Map DLC strings to application strings, then store the DLC index mapping to application index
423 wstring parameterName((WCHAR *)pParams->wchData);
424 DLCManager::EDLCParameterType type = DLCManager::getParameterType(parameterName);
425 if( type != DLCManager::e_DLCParamType_Invalid )
426 {
427 parameterMapping[pParams->dwType] = type;
428 }
429 uiCurrentByte+= sizeof(C4JStorage::DLC_FILE_PARAM)+(pParams->dwWchCount*sizeof(WCHAR));
430 pParams = (C4JStorage::DLC_FILE_PARAM *)&pbData[uiCurrentByte];
431 }
432 //ulCurrentByte+=ulParameterCount * sizeof(C4JStorage::DLC_FILE_PARAM);
433
434 unsigned int uiFileCount=*(unsigned int *)&pbData[uiCurrentByte];
435 uiCurrentByte+=sizeof(int);
436 C4JStorage::DLC_FILE_DETAILS *pFile = (C4JStorage::DLC_FILE_DETAILS *)&pbData[uiCurrentByte];
437
438 DWORD dwTemp=uiCurrentByte;
439 for(unsigned int i=0;i<uiFileCount;i++)
440 {
441 dwTemp+=sizeof(C4JStorage::DLC_FILE_DETAILS)+pFile->dwWchCount*sizeof(WCHAR);
442 pFile = (C4JStorage::DLC_FILE_DETAILS *)&pbData[dwTemp];
443 }
444 PBYTE pbTemp=((PBYTE )pFile);//+ sizeof(C4JStorage::DLC_FILE_DETAILS)*ulFileCount;
445 pFile = (C4JStorage::DLC_FILE_DETAILS *)&pbData[uiCurrentByte];
446
447 for(unsigned int i=0;i<uiFileCount;i++)
448 {
449 DLCManager::EDLCType type = (DLCManager::EDLCType)pFile->dwType;
450
451 DLCFile *dlcFile = NULL;
452 DLCPack *dlcTexturePack = NULL;
453
454 if(type == e_DLCType_TexturePack)
455 {
456 dlcTexturePack = new DLCPack(pack->getName(), pack->getLicenseMask());
457 }
458 else if(type != e_DLCType_PackConfig)
459 {
460 dlcFile = pack->addFile(type,(WCHAR *)pFile->wchFile);
461 }
462
463 // Params
464 uiParameterCount=*(unsigned int *)pbTemp;
465 pbTemp+=sizeof(int);
466 pParams = (C4JStorage::DLC_FILE_PARAM *)pbTemp;
467 for(unsigned int j=0;j<uiParameterCount;j++)
468 {
469 //DLCManager::EDLCParameterType paramType = DLCManager::e_DLCParamType_Invalid;
470
471 AUTO_VAR(it, parameterMapping.find( pParams->dwType ));
472
473 if(it != parameterMapping.end() )
474 {
475 if(type == e_DLCType_PackConfig)
476 {
477 pack->addParameter(it->second,(WCHAR *)pParams->wchData);
478 }
479 else
480 {
481 if(dlcFile != NULL) dlcFile->addParameter(it->second,(WCHAR *)pParams->wchData);
482 else if(dlcTexturePack != NULL) dlcTexturePack->addParameter(it->second, (WCHAR *)pParams->wchData);
483 }
484 }
485 pbTemp+=sizeof(C4JStorage::DLC_FILE_PARAM)+(sizeof(WCHAR)*pParams->dwWchCount);
486 pParams = (C4JStorage::DLC_FILE_PARAM *)pbTemp;
487 }
488 //pbTemp+=ulParameterCount * sizeof(C4JStorage::DLC_FILE_PARAM);
489
490 if(dlcTexturePack != NULL)
491 {
492 DWORD texturePackFilesProcessed = 0;
493 bool validPack = processDLCDataFile(texturePackFilesProcessed,pbTemp,pFile->uiFileSize,dlcTexturePack);
494 pack->SetDataPointer(NULL); // If it's a child pack, it doesn't own the data
495 if(!validPack || texturePackFilesProcessed == 0)
496 {
497 delete dlcTexturePack;
498 dlcTexturePack = NULL;
499 }
500 else
501 {
502 pack->addChildPack(dlcTexturePack);
503
504 if(dlcTexturePack->getDLCItemsCount(DLCManager::e_DLCType_Texture) > 0)
505 {
506 Minecraft::GetInstance()->skins->addTexturePackFromDLC(dlcTexturePack, dlcTexturePack->GetPackId() );
507 }
508 }
509 ++dwFilesProcessed;
510 }
511 else if(dlcFile != NULL)
512 {
513 // Data
514 dlcFile->addData(pbTemp,pFile->uiFileSize);
515
516 // TODO - 4J Stu Remove the need for this vSkinNames vector, or manage it differently
517 switch(pFile->dwType)
518 {
519 case DLCManager::e_DLCType_Skin:
520 app.vSkinNames.push_back((WCHAR *)pFile->wchFile);
521 break;
522 }
523
524 ++dwFilesProcessed;
525 }
526
527 // Move the pointer to the start of the next files data;
528 pbTemp+=pFile->uiFileSize;
529 uiCurrentByte+=sizeof(C4JStorage::DLC_FILE_DETAILS)+pFile->dwWchCount*sizeof(WCHAR);
530
531 pFile=(C4JStorage::DLC_FILE_DETAILS *)&pbData[uiCurrentByte];
532 }
533
534 if( pack->getDLCItemsCount(DLCManager::e_DLCType_GameRules) > 0
535 || pack->getDLCItemsCount(DLCManager::e_DLCType_GameRulesHeader) > 0)
536 {
537 app.m_gameRules.loadGameRules(pack);
538 }
539
540 if(pack->getDLCItemsCount(DLCManager::e_DLCType_Audio) > 0)
541 {
542 //app.m_Audio.loadAudioDetails(pack);
543 }
544 // 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)
545
546 return true;
547}
548
549DWORD DLCManager::retrievePackIDFromDLCDataFile(const string &path, DLCPack *pack)
550{
551 DWORD packId = 0;
552 wstring wPath = convStringToWstring(path);
553
554#ifdef _WINDOWS64
555 string finalPath = StorageManager.GetMountedPath(path.c_str());
556 if(finalPath.size() == 0) finalPath = path;
557 HANDLE file = CreateFile(finalPath.c_str(), GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
558#elif defined(_DURANGO)
559 wstring finalPath = StorageManager.GetMountedPath(wPath.c_str());
560 if(finalPath.size() == 0) finalPath = wPath;
561 HANDLE file = CreateFile(finalPath.c_str(), GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
562#else
563 HANDLE file = CreateFile(path.c_str(), GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
564#endif
565 if( file == INVALID_HANDLE_VALUE )
566 {
567 return 0;
568 }
569
570 DWORD bytesRead,dwFileSize = GetFileSize(file,NULL);
571 PBYTE pbData = (PBYTE) new BYTE[dwFileSize];
572 BOOL bSuccess = ReadFile(file,pbData,dwFileSize,&bytesRead,NULL);
573 if(bSuccess==FALSE)
574 {
575 // need to treat the file as corrupt, and flag it, so can't call fatal error
576 //app.FatalLoadError();
577 }
578 else
579 {
580 CloseHandle(file);
581 }
582 if(bSuccess==FALSE)
583 {
584 // Corrupt or some other error. In any case treat as corrupt
585 app.DebugPrintf("Failed to read %s from DLC content package\n", path.c_str());
586 delete [] pbData;
587 return 0;
588 }
589 packId=retrievePackID(pbData, bytesRead, pack);
590 delete [] pbData;
591
592 return packId;
593}
594
595DWORD DLCManager::retrievePackID(PBYTE pbData, DWORD dwLength, DLCPack *pack)
596{
597 DWORD packId=0;
598 bool bPackIDSet=false;
599 unordered_map<int, DLCManager::EDLCParameterType> parameterMapping;
600 unsigned int uiCurrentByte=0;
601
602 // File format defined in the DLC_Creator
603 // File format: Version 2
604 // unsigned long, version number
605 // unsigned long, t = number of parameter types
606 // t * DLC_FILE_PARAM structs mapping strings to id's
607 // unsigned long, n = number of files
608 // n * DLC_FILE_DETAILS describing each file in the pack
609 // n * files of the form
610 // // unsigned long, p = number of parameters
611 // // p * DLC_FILE_PARAM describing each parameter for this file
612 // // ulFileSize bytes of data blob of the file added
613 unsigned int uiVersion=*(unsigned int *)pbData;
614 uiCurrentByte+=sizeof(int);
615
616 if(uiVersion < CURRENT_DLC_VERSION_NUM)
617 {
618 app.DebugPrintf("DLC version of %d is too old to be read\n", uiVersion);
619 return 0;
620 }
621 pack->SetDataPointer(pbData);
622 unsigned int uiParameterCount=*(unsigned int *)&pbData[uiCurrentByte];
623 uiCurrentByte+=sizeof(int);
624 C4JStorage::DLC_FILE_PARAM *pParams = (C4JStorage::DLC_FILE_PARAM *)&pbData[uiCurrentByte];
625 for(unsigned int i=0;i<uiParameterCount;i++)
626 {
627 // Map DLC strings to application strings, then store the DLC index mapping to application index
628 wstring parameterName((WCHAR *)pParams->wchData);
629 DLCManager::EDLCParameterType type = DLCManager::getParameterType(parameterName);
630 if( type != DLCManager::e_DLCParamType_Invalid )
631 {
632 parameterMapping[pParams->dwType] = type;
633 }
634 uiCurrentByte+= sizeof(C4JStorage::DLC_FILE_PARAM)+(pParams->dwWchCount*sizeof(WCHAR));
635 pParams = (C4JStorage::DLC_FILE_PARAM *)&pbData[uiCurrentByte];
636 }
637
638 unsigned int uiFileCount=*(unsigned int *)&pbData[uiCurrentByte];
639 uiCurrentByte+=sizeof(int);
640 C4JStorage::DLC_FILE_DETAILS *pFile = (C4JStorage::DLC_FILE_DETAILS *)&pbData[uiCurrentByte];
641
642 DWORD dwTemp=uiCurrentByte;
643 for(unsigned int i=0;i<uiFileCount;i++)
644 {
645 dwTemp+=sizeof(C4JStorage::DLC_FILE_DETAILS)+pFile->dwWchCount*sizeof(WCHAR);
646 pFile = (C4JStorage::DLC_FILE_DETAILS *)&pbData[dwTemp];
647 }
648 PBYTE pbTemp=((PBYTE )pFile);
649 pFile = (C4JStorage::DLC_FILE_DETAILS *)&pbData[uiCurrentByte];
650
651 for(unsigned int i=0;i<uiFileCount;i++)
652 {
653 DLCManager::EDLCType type = (DLCManager::EDLCType)pFile->dwType;
654
655 // Params
656 uiParameterCount=*(unsigned int *)pbTemp;
657 pbTemp+=sizeof(int);
658 pParams = (C4JStorage::DLC_FILE_PARAM *)pbTemp;
659 for(unsigned int j=0;j<uiParameterCount;j++)
660 {
661 AUTO_VAR(it, parameterMapping.find( pParams->dwType ));
662
663 if(it != parameterMapping.end() )
664 {
665 if(type==e_DLCType_PackConfig)
666 {
667 if(it->second==e_DLCParamType_PackId)
668 {
669 wstring wsTemp=(WCHAR *)pParams->wchData;
670 std::wstringstream ss;
671 // 4J Stu - numbered using decimal to make it easier for artists/people to number manually
672 ss << std::dec << wsTemp.c_str();
673 ss >> packId;
674 bPackIDSet=true;
675 break;
676 }
677 }
678 }
679 pbTemp+=sizeof(C4JStorage::DLC_FILE_PARAM)+(sizeof(WCHAR)*pParams->dwWchCount);
680 pParams = (C4JStorage::DLC_FILE_PARAM *)pbTemp;
681 }
682
683 if(bPackIDSet) break;
684 // Move the pointer to the start of the next files data;
685 pbTemp+=pFile->uiFileSize;
686 uiCurrentByte+=sizeof(C4JStorage::DLC_FILE_DETAILS)+pFile->dwWchCount*sizeof(WCHAR);
687
688 pFile=(C4JStorage::DLC_FILE_DETAILS *)&pbData[uiCurrentByte];
689 }
690
691 parameterMapping.clear();
692 return packId;
693}