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
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
|
#include "stdafx.h"
#include "TexturePackRepository.h"
#include "DefaultTexturePack.h"
#include "FileTexturePack.h"
#include "FolderTexturePack.h"
#include "DLCTexturePack.h"
#include "Options.h"
#include "..\Minecraft.World\File.h"
#include "..\Minecraft.World\StringHelpers.h"
#include "Minimap.h"
#include "Common/UI/UI.h"
TexturePack *TexturePackRepository::DEFAULT_TEXTURE_PACK = nullptr;
TexturePackRepository::TexturePackRepository(File workingDirectory, Minecraft *minecraft)
{
if(!DEFAULT_TEXTURE_PACK) DEFAULT_TEXTURE_PACK = new DefaultTexturePack();
// 4J - added
usingWeb = false;
selected = nullptr;
texturePacks = new vector<TexturePack *>;
this->minecraft = minecraft;
texturePacks->push_back(DEFAULT_TEXTURE_PACK);
cacheById[DEFAULT_TEXTURE_PACK->getId()] = DEFAULT_TEXTURE_PACK;
selected = DEFAULT_TEXTURE_PACK;
DEFAULT_TEXTURE_PACK->loadColourTable();
m_dummyTexturePack = nullptr;
m_dummyDLCTexturePack = nullptr;
lastSelected = nullptr;
updateList();
}
void TexturePackRepository::addDebugPacks()
{
#ifndef _CONTENT_PACKAGE
//File *file = new File(L"DummyTexturePack"); // Path to the test texture pack
//m_dummyTexturePack = new FolderTexturePack(FOLDER_TEST_TEXTURE_PACK_ID, L"FolderTestPack", file, DEFAULT_TEXTURE_PACK);
//texturePacks->push_back(m_dummyTexturePack);
//cacheById[m_dummyTexturePack->getId()] = m_dummyTexturePack;
#ifdef _XBOX
File packedTestFile(L"GAME:\\DummyTexturePack\\TexturePack.pck");
if(packedTestFile.exists())
{
DLCPack *pack = app.m_dlcManager.getPack(L"DLCTestPack");
if( pack != nullptr && pack->IsCorrupt() )
{
app.m_dlcManager.removePack(pack);
pack = nullptr;
}
if(pack == nullptr)
{
wprintf(L"Pack \"%ls\" is not installed, so adding it\n", L"DLCTestPack");
pack = new DLCPack(L"DLCTestPack",0xffffffff);
DWORD dwFilesProcessed = 0;
if( app.m_dlcManager.readDLCDataFile(dwFilesProcessed, "GAME:\\DummyTexturePack\\TexturePack.pck",pack))
{
// 4J Stu - Don't need to do this, as the readDLCDataFile now adds texture packs
//m_dummyDLCTexturePack = addTexturePackFromDLC(pack, DLC_TEST_TEXTURE_PACK_ID); //new DLCTexturePack(0xFFFFFFFE, L"DLCTestPack", pack, DEFAULT_TEXTURE_PACK);
app.m_dlcManager.addPack(pack);
}
else
{
delete pack;
}
}
}
#endif // _XBOX
#endif // _CONTENT_PACKAGE
}
void TexturePackRepository::createWorkingDirecoryUnlessExists()
{
// 4J Unused
#if 0
if (!workDir.isDirectory()) {
workDir.delete();
workDir.mkdirs();
}
if (!multiplayerDir.isDirectory()) {
multiplayerDir.delete();
multiplayerDir.mkdirs();
}
#endif
}
bool TexturePackRepository::selectSkin(TexturePack *skin)
{
if (skin==selected) return false;
lastSelected = selected;
usingWeb = false;
selected = skin;
//minecraft->options->skin = skin->getName();
//minecraft->options->save();
return true;
}
void TexturePackRepository::selectWebSkin(const wstring &url)
{
app.DebugPrintf("TexturePackRepository::selectWebSkin is not implemented\n");
#if 0
String filename = url.substring(url.lastIndexOf("/") + 1);
if (filename.contains("?")) filename = filename.substring(0, filename.indexOf("?"));
if (!filename.endsWith(".zip")) return;
File file = new File(multiplayerDir, filename);
downloadWebSkin(url, file);
#endif
}
void TexturePackRepository::downloadWebSkin(const wstring &url, File file)
{
app.DebugPrintf("TexturePackRepository::selectWebSkin is not implemented\n");
#if 0
Map<String, String> headers = new HashMap<String, String>();
final ProgressScreen listener = new ProgressScreen();
headers.put("X-Minecraft-Username", minecraft.user.name);
headers.put("X-Minecraft-Version", SharedConstants.VERSION_STRING);
headers.put("X-Minecraft-Supported-Resolutions", "16");
usingWeb = true;
minecraft.setScreen(listener);
HttpUtil.downloadTo(file, url, new HttpUtil.DownloadSuccessRunnable() {
public void onDownloadSuccess(File file) {
if (!usingWeb) return;
selected = new FileTexturePack(getIdOrNull(file), file, DEFAULT_TEXTURE_PACK);
minecraft.delayTextureReload();
}
}, headers, MAX_WEB_FILESIZE, listener);
#endif
}
bool TexturePackRepository::isUsingWebSkin()
{
return usingWeb;
}
void TexturePackRepository::resetWebSkin()
{
usingWeb = false;
updateList();
minecraft->delayTextureReload();
}
void TexturePackRepository::updateList()
{
// 4J Stu - We don't ever want to completely refresh the lists, we keep them up-to-date as we go
#if 0
vector<TexturePack *> *currentPacks = new vector<TexturePack *>;
currentPacks->push_back(DEFAULT_TEXTURE_PACK);
cacheById[DEFAULT_TEXTURE_PACK->getId()] = DEFAULT_TEXTURE_PACK;
#ifndef _CONTENT_PACKAGE
currentPacks->push_back(m_dummyTexturePack);
cacheById[m_dummyTexturePack->getId()] = m_dummyTexturePack;
if(m_dummyDLCTexturePack != nullptr)
{
currentPacks->push_back(m_dummyDLCTexturePack);
cacheById[m_dummyDLCTexturePack->getId()] = m_dummyDLCTexturePack;
}
//selected = m_dummyTexturePack;
#endif
selected = DEFAULT_TEXTURE_PACK;
// 4J Unused
for (File file : getWorkDirContents())
{
final String id = getIdOrNull(file);
if (id == null) continue;
TexturePack pack = cacheById.get(id);
if (pack == null) {
pack = file.isDirectory() ? new FolderTexturePack(id, file, DEFAULT_TEXTURE_PACK) : new FileTexturePack(id, file, DEFAULT_TEXTURE_PACK);
cacheById.put(id, pack);
}
if (pack.getName().equals(minecraft.options.skin)) {
selected = pack;
}
currentPacks.add(pack);
}
// 4J - was texturePacks.removeAll(currentPacks);
for( auto it1 = currentPacks->begin(); it1 != currentPacks->end(); it1++ )
{
for( auto it2 = texturePacks->begin(); it2 != texturePacks->end(); it2++ )
{
if( *it1 == *it2 )
{
it2 = texturePacks->erase(it2);
}
}
}
for( auto it = texturePacks->begin(); it != texturePacks->end(); it++ )
{
TexturePack *pack = *it;
pack->unload(minecraft->textures);
cacheById.erase(pack->getId());
}
delete texturePacks;
texturePacks = currentPacks;
#endif
}
wstring TexturePackRepository::getIdOrNull(File file)
{
app.DebugPrintf("TexturePackRepository::getIdOrNull is not implemented\n");
#if 0
if (file.isFile() && file.getName().toLowerCase().endsWith(".zip")) {
return file.getName() + ":" + file.length() + ":" + file.lastModified();
} else if (file.isDirectory() && new File(file, "pack.txt").exists()) {
return file.getName() + ":folder:" + file.lastModified();
}
return nullptr;
#endif
return L"";
}
vector<File> TexturePackRepository::getWorkDirContents()
{
app.DebugPrintf("TexturePackRepository::getWorkDirContents is not implemented\n");
#if 0
if (workDir.exists() && workDir.isDirectory()) {
return Arrays.asList(workDir.listFiles());
}
return Collections.emptyList();
#endif
return vector<File>();
}
vector<TexturePack *> *TexturePackRepository::getAll()
{
// 4J - note that original constucted a copy of texturePacks here
return texturePacks;
}
TexturePack *TexturePackRepository::getSelected()
{
if(selected->hasData()) return selected;
else return DEFAULT_TEXTURE_PACK;
}
bool TexturePackRepository::shouldPromptForWebSkin()
{
app.DebugPrintf("TexturePackRepository::shouldPromptForWebSkin is not implemented\n");
#if 0
if (!minecraft.options.serverTextures) return false;
ServerData data = minecraft.getCurrentServer();
if (data == null) {
return true;
} else {
return data.promptOnTextures();
}
#endif
return false;
}
bool TexturePackRepository::canUseWebSkin()
{
app.DebugPrintf("TexturePackRepository::canUseWebSkin is not implemented\n");
#if 0
if (!minecraft.options.serverTextures) return false;
ServerData data = minecraft.getCurrentServer();
if (data == null) {
return false;
} else {
return data.allowTextures();
}
#endif
return false;
}
vector< pair<DWORD,wstring> > *TexturePackRepository::getTexturePackIdNames()
{
vector< pair<DWORD,wstring> > *packList = new vector< pair<DWORD,wstring> >();
for(auto& pack : *texturePacks)
{
packList->emplace_back(pack->getId(), pack->getName());
}
return packList;
}
bool TexturePackRepository::selectTexturePackById(DWORD id)
{
bool bDidSelect = false;
//4J-PB - add in a store of the texture pack required, so that join from invite games
// (where they don't have the texture pack) can check this when the texture pack is installed
app.SetRequiredTexturePackID(id);
auto it = cacheById.find(id);
if(it != cacheById.end())
{
TexturePack *newPack = it->second;
if(newPack != selected)
{
selectSkin(newPack);
if(newPack->hasData())
{
app.SetAction(ProfileManager.GetPrimaryPad(), eAppAction_ReloadTexturePack);
}
else
{
newPack->loadData();
}
//Minecraft *pMinecraft = Minecraft::GetInstance();
//pMinecraft->textures->reloadAll();
}
else
{
app.DebugPrintf("TexturePack with id %d is already selected\n",id);
}
bDidSelect = true;
}
else
{
app.DebugPrintf("Failed to select texture pack %d as it is not in the list\n", id);
#ifndef _CONTENT_PACKAGE
// TODO - 4J Stu: We should report this to the player in some way
//__debugbreak();
#endif
// Fail safely
if( selectSkin( DEFAULT_TEXTURE_PACK ) )
{
app.SetAction(ProfileManager.GetPrimaryPad(), eAppAction_ReloadTexturePack);
}
}
return bDidSelect;
}
TexturePack *TexturePackRepository::getTexturePackById(DWORD id)
{
auto it = cacheById.find(id);
if(it != cacheById.end())
{
return it->second;
}
return nullptr;
}
TexturePack *TexturePackRepository::addTexturePackFromDLC(DLCPack *dlcPack, DWORD id)
{
TexturePack *newPack = nullptr;
// 4J-PB - The City texture pack went out with a child id for the texture pack of 1 instead of zero
// we need to mask off the child id here to deal with this
DWORD dwParentID=id&0xFFFFFF; // child id is <<24 and Or'd with parent
if(dlcPack != nullptr)
{
newPack = new DLCTexturePack(dwParentID, dlcPack, DEFAULT_TEXTURE_PACK);
texturePacks->push_back(newPack);
cacheById[dwParentID] = newPack;
#ifndef _CONTENT_PACKAGE
if(dlcPack->hasPurchasedFile(DLCManager::e_DLCType_TexturePack,L""))
{
wprintf(L"Added new FULL DLCTexturePack: %ls - id=%d\n", dlcPack->getName().c_str(),dwParentID );
}
else
{
wprintf(L"Added new TRIAL DLCTexturePack: %ls - id=%d\n", dlcPack->getName().c_str(),dwParentID );
}
#endif
}
return newPack;
}
void TexturePackRepository::clearInvalidTexturePacks()
{
for(auto& it : m_texturePacksToDelete)
{
delete it;
}
}
void TexturePackRepository::removeTexturePackById(DWORD id)
{
auto it = cacheById.find(id);
if(it != cacheById.end())
{
TexturePack *oldPack = it->second;
auto it2 = find(texturePacks->begin(), texturePacks->end(), oldPack);
if(it2 != texturePacks->end())
{
texturePacks->erase(it2);
if(lastSelected == oldPack)
{
lastSelected = nullptr;
}
}
m_texturePacksToDelete.push_back(oldPack);
}
}
void TexturePackRepository::updateUI()
{
if(lastSelected != nullptr && lastSelected != selected)
{
lastSelected->unloadUI();
selected->loadUI();
Minimap::reloadColours();
ui.StartReloadSkinThread();
lastSelected = nullptr;
}
}
bool TexturePackRepository::needsUIUpdate()
{
return lastSelected != nullptr && lastSelected != selected;
}
unsigned int TexturePackRepository::getTexturePackCount()
{
return texturePacks->size();
}
TexturePack *TexturePackRepository::getTexturePackByIndex(unsigned int index)
{
TexturePack *pack = nullptr;
if(index < texturePacks->size())
{
pack = texturePacks->at(index);
}
return pack;
}
unsigned int TexturePackRepository::getTexturePackIndex(unsigned int id)
{
int currentIndex = 0;
for(auto& pack : *texturePacks)
{
if(pack->getId() == id)
break;
++currentIndex;
}
if(currentIndex >= texturePacks->size()) currentIndex = 0;
return currentIndex;
}
|