Skip to content

Commit 9a17bdb

Browse files
committed
Catch some edge cases
1 parent 2f3d768 commit 9a17bdb

File tree

3 files changed

+54
-29
lines changed

3 files changed

+54
-29
lines changed

Unreal/FileSystem/GameFileSystemSmite.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ void LoadSmiteManifest(const CGameFileInfo* info) {
2626
}
2727

2828

29-
FArchive* GetSmiteBlob(const char* name, int name_len, int level, const char* ext) {
29+
FMemReader* GetSmiteBlob(const char* name, int name_len, int level, const char* ext) {
3030
guard(GetSmiteBlob);
3131

3232
if(GSmiteManifest == nullptr) {
@@ -62,9 +62,9 @@ FArchive* GetSmiteBlob(const char* name, int name_len, int level, const char* ex
6262
byte *data = (byte*)appMalloc(entry->blob_size);
6363
Ar->Serialize(data, entry->blob_size);
6464
delete Ar;
65-
Ar = new FMemReader(data, entry->blob_size);
66-
Ar->Game = GAME_Smite;
67-
return Ar;
65+
FMemReader* MemAr = new FMemReader(data, entry->blob_size);
66+
MemAr->Game = GAME_Smite;
67+
return MemAr;
6868
}
6969
}
7070
unguard;

Unreal/FileSystem/GameFileSystemSmite.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@ struct FSmiteManifest
2929

3030
void LoadSmiteManifest(const CGameFileInfo* info);
3131

32-
FArchive* GetSmiteBlob(const char* name, int name_len, int level, const char* ext);
32+
FMemReader* GetSmiteBlob(const char* name, int name_len, int level, const char* ext);
3333

3434
#endif // SMITE

Unreal/UnrealMaterial/UnTexture3.cpp

Lines changed: 49 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -648,47 +648,72 @@ static int GetRealTextureOffset_MH(const UTexture2D *Obj, int MipIndex)
648648
#include "../UnrealPackage/UnPackageUE3Reader.h"
649649

650650
static bool LoadBulkTextureSMITE(const UTexture2D* texture, const TArray<FTexture2DMipMap> &MipsArray, int MipIndex, bool verbose) {
651+
FMemReader* MemAr = nullptr;
652+
const FTexture2DMipMap &Mip = MipsArray[MipIndex];
653+
654+
int i;
651655
static char buf[2048];
652-
texture->GetFullName(ARRAY_ARG(buf), true, true, true);
653-
char *s = buf;
654-
int len = 0;
655-
if(verbose) {
656-
appPrintf("Smite: Finding %s (Mip %d) in MergedFileIndexCache\n", buf, MipIndex);
657-
}
658-
while (*s) {
659-
*s = toupper((unsigned char) *s);
660-
len++;
661-
s++;
656+
for(i = 0; i < 4; ++i) {
657+
static char tmp[2048];
658+
texture->GetFullName(ARRAY_ARG(tmp), true, true, false);
659+
switch(i) {
660+
case 0:
661+
appSprintf(ARRAY_ARG(buf), "%s", tmp);
662+
break;
663+
case 1:
664+
if(texture->Package == nullptr) {
665+
continue;
666+
}
667+
appSprintf(ARRAY_ARG(buf), "%s.%s", texture->Package->Name, tmp);
668+
break;
669+
case 2:
670+
appSprintf(ARRAY_ARG(buf), "Textures.%s", tmp);
671+
break;
672+
case 3:
673+
if(texture->Package == nullptr) {
674+
continue;
675+
}
676+
appSprintf(ARRAY_ARG(buf), "%s.Textures.%s", texture->Package->Name, tmp);
677+
break;
678+
}
679+
char *s = buf;
680+
int len = 0;
681+
if(verbose) {
682+
appPrintf("Smite: Finding %s (Mip %d) in MergedFileIndexCache\n", buf, MipIndex);
683+
}
684+
while (*s) {
685+
*s = toupper((unsigned char) *s);
686+
len++;
687+
s++;
688+
}
689+
690+
MemAr = GetSmiteBlob(buf, len, MipIndex, "tfc");
691+
if(MemAr != NULL) {
692+
break;
693+
}
662694
}
663695

664-
const FTexture2DMipMap &Mip = MipsArray[MipIndex];
665-
FArchive* Ar = GetSmiteBlob(buf, len, MipIndex, "tfc");
666-
if(Ar == NULL) {
667-
appPrintf("Smite: unable to find %s (Mip %d) in MergedFileIndexCache\n", buf, MipIndex);
696+
if(MemAr == NULL) {
697+
appPrintf("Smite: unable to find %s (Mip %d) in MergedFileIndexCache\n", texture->Name, MipIndex);
668698
return false;
669699
}
670-
FArchive* free = Ar;
671700

672701
FCompressedChunkHeader H;
673-
*Ar << H;
702+
*MemAr << H;
674703
TArray<FCompressedChunk> Chunks;
675704
FCompressedChunk *Chunk = new (Chunks) FCompressedChunk;
676705
Chunk->UncompressedOffset = 0;
677706
Chunk->UncompressedSize = H.Sum.UncompressedSize;
678707
Chunk->CompressedOffset = 0;
679708
Chunk->CompressedSize = H.Sum.CompressedSize;
680709
FByteBulkData *Bulk = const_cast<FByteBulkData*>(&Mip.Data);
681-
int flags = 0;
710+
int flags = COMPRESS_LZO;
682711
if (Bulk->BulkDataFlags & BULKDATA_CompressedOodle_SMITE) flags = COMPRESS_OODLE;
683712
else if (Bulk->BulkDataFlags & BULKDATA_CompressedZlib) flags = COMPRESS_ZLIB;
684-
else if (Bulk->BulkDataFlags & BULKDATA_CompressedLzo) flags = COMPRESS_LZO;
685713
else if (Bulk->BulkDataFlags & BULKDATA_CompressedLzx) flags = COMPRESS_LZX;
686714

687-
if(flags > 0) {
688-
FUE3ArchiveReader* UE3Loader = new FUE3ArchiveReader(Ar, flags, Chunks);
689-
UE3Loader->IsFullyCompressed = true;
690-
Ar = UE3Loader;
691-
}
715+
FUE3ArchiveReader* Ar = new FUE3ArchiveReader(Ar, flags, Chunks);
716+
Ar->IsFullyCompressed = true;
692717

693718
if (verbose)
694719
{
@@ -703,7 +728,7 @@ static bool LoadBulkTextureSMITE(const UTexture2D* texture, const TArray<FTextur
703728
Bulk->SerializeData(*Ar);
704729
Bulk->BulkDataFlags = backup;
705730

706-
reinterpret_cast<FMemReader*>(free)->Free();
731+
MemAr->Free();
707732
delete Ar;
708733
return true;
709734
}

0 commit comments

Comments
 (0)