1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
|
#include "stdafx.h"
#include "DLCPack.h"
#include "DLCSkinFile.h"
#include "DLCCapeFile.h"
#include "DLCTextureFile.h"
#include "DLCUIDataFile.h"
#include "DLCLocalisationFile.h"
#include "DLCGameRulesFile.h"
#include "DLCGameRulesHeader.h"
#include "DLCAudioFile.h"
#include "DLCColourTableFile.h"
#include "..\..\..\Minecraft.World\StringHelpers.h"
DLCPack::DLCPack(const wstring &name,DWORD dwLicenseMask)
{
m_dataPath = L"";
m_packName = name;
m_dwLicenseMask=dwLicenseMask;
#ifdef _XBOX_ONE
m_wsProductId = L"";
#else
m_ullFullOfferId = 0LL;
#endif
m_isCorrupt = false;
m_packId = 0;
m_packVersion = 0;
m_parentPack = NULL;
m_dlcMountIndex = -1;
#ifdef _XBOX
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;
}
#ifdef _XBOX_ONE
DLCPack::DLCPack(const wstring &name,const wstring &productID,DWORD 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;
}
#endif
DLCPack::~DLCPack()
{
for( auto& it : m_childPacks )
{
if ( it )
delete it;
}
for(unsigned int i = 0; i < DLCManager::e_DLCType_Max; ++i)
{
for (auto& it : m_files[i] )
{
if ( 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)
{
#ifndef _CONTENT_PACKAGE
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;
}
}
}
DWORD 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;
}
void DLCPack::addChildPack(DLCPack *childPack)
{
int packId = childPack->GetPackId();
#ifndef _CONTENT_PACKAGE
if(packId < 0 || 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();
}
void DLCPack::setParentPack(DLCPack *parentPack)
{
m_parentPack = parentPack;
}
void DLCPack::addParameter(DLCManager::EDLCParameterType type, const wstring &value)
{
switch(type)
{
case DLCManager::e_DLCParamType_PackId:
{
DWORD 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:
{
DWORD 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 ¶m)
{
auto 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<unsigned int>(it->second);
}
return true;
}
return false;
}
DLCFile *DLCPack::addFile(DLCManager::EDLCType type, const wstring &path)
{
DLCFile *newFile = NULL;
switch(type)
{
case DLCManager::e_DLCType_Skin:
{
wstring newPath = replaceAll(path, L"\\", L"/");
std::vector<std::wstring> splitPath = stringSplit(newPath,L'/');
wstring strippedPath = splitPath.back();
newFile = new DLCSkinFile(strippedPath);
// check to see if we can get the full offer id using this skin name
#ifdef _XBOX_ONE
app.GetDLCFullOfferIDForSkinID(strippedPath,m_wsProductId);
#else
ULONGLONG ullVal=0LL;
if(app.GetDLCFullOfferIDForSkinID(strippedPath,&ullVal))
{
m_ullFullOfferId=ullVal;
}
#endif
}
break;
case DLCManager::e_DLCType_Cape:
{
wstring newPath = replaceAll(path, L"\\", L"/");
std::vector<std::wstring> splitPath = stringSplit(newPath,L'/');
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;
};
if( newFile != NULL )
{
m_files[newFile->getType()].push_back(newFile);
}
return newFile;
}
// MGH - added this comp func, as the embedded func in find_if was confusing the PS3 compiler
static const wstring *g_pathCmpString = NULL;
static bool pathCmp(DLCFile *val)
{
return (g_pathCmpString->compare(val->getPath()) == 0);
}
bool DLCPack::doesPackContainFile(DLCManager::EDLCType type, const 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 it = 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, DWORD 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 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 it = 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;
}
DWORD DLCPack::getDLCItemsCount(DLCManager::EDLCType type /*= DLCManager::e_DLCType_All*/)
{
DWORD 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 = (DWORD)m_files[(int)type].size();
break;
};
return count;
};
DWORD DLCPack::getFileIndexAt(DLCManager::EDLCType type, const wstring &path, bool &found)
{
if(type == DLCManager::e_DLCType_All)
{
app.DebugPrintf("Unimplemented\n");
#ifndef __CONTENT_PACKAGE
__debugbreak();
#endif
return 0;
}
DWORD foundIndex = 0;
found = false;
DWORD index = 0;
for( auto& it : m_files[type] )
{
if(path.compare(it->getPath()) == 0)
{
foundIndex = index;
found = true;
break;
}
++index;
}
return foundIndex;
}
bool DLCPack::hasPurchasedFile(DLCManager::EDLCType type, const wstring &path)
{
// Patch all DLC to be "purchased"
return true;
/*if(type == DLCManager::e_DLCType_All)
{
app.DebugPrintf("Unimplemented\n");
#ifndef _CONTENT_PACKAGE
__debugbreak();
#endif
return false;
}
#ifndef _CONTENT_PACKAGE
if( app.GetGameSettingsDebugMask(ProfileManager.GetPrimaryPad())&(1L<<eDebugSetting_UnlockAllDLC) )
{
return true;
}
else
#endif
if ( m_dwLicenseMask == 0 )
{
//not purchased.
return false;
}
else
{
//purchased
return true;
}*/
}
void DLCPack::UpdateLanguage()
{
// find the language file
DLCManager::e_DLCType_LocalisationData;
DLCFile *file = NULL;
if(m_files[DLCManager::e_DLCType_LocalisationData].size() > 0)
{
file = m_files[DLCManager::e_DLCType_LocalisationData][0];
DLCLocalisationFile *localisationFile = (DLCLocalisationFile *)getFile(DLCManager::e_DLCType_LocalisationData, L"languages.loc");
StringTable *strTable = localisationFile->getStringTable();
strTable->ReloadStringTable();
}
}
|