Skip to content

Commit

Permalink
Catch some edge cases
Browse files Browse the repository at this point in the history
  • Loading branch information
yretenai committed Jun 10, 2022
1 parent 2f3d768 commit 9a17bdb
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 29 deletions.
8 changes: 4 additions & 4 deletions Unreal/FileSystem/GameFileSystemSmite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ void LoadSmiteManifest(const CGameFileInfo* info) {
}


FArchive* GetSmiteBlob(const char* name, int name_len, int level, const char* ext) {
FMemReader* GetSmiteBlob(const char* name, int name_len, int level, const char* ext) {
guard(GetSmiteBlob);

if(GSmiteManifest == nullptr) {
Expand Down Expand Up @@ -62,9 +62,9 @@ FArchive* GetSmiteBlob(const char* name, int name_len, int level, const char* ex
byte *data = (byte*)appMalloc(entry->blob_size);
Ar->Serialize(data, entry->blob_size);
delete Ar;
Ar = new FMemReader(data, entry->blob_size);
Ar->Game = GAME_Smite;
return Ar;
FMemReader* MemAr = new FMemReader(data, entry->blob_size);
MemAr->Game = GAME_Smite;
return MemAr;
}
}
unguard;
Expand Down
2 changes: 1 addition & 1 deletion Unreal/FileSystem/GameFileSystemSmite.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ struct FSmiteManifest

void LoadSmiteManifest(const CGameFileInfo* info);

FArchive* GetSmiteBlob(const char* name, int name_len, int level, const char* ext);
FMemReader* GetSmiteBlob(const char* name, int name_len, int level, const char* ext);

#endif // SMITE
73 changes: 49 additions & 24 deletions Unreal/UnrealMaterial/UnTexture3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -648,47 +648,72 @@ static int GetRealTextureOffset_MH(const UTexture2D *Obj, int MipIndex)
#include "../UnrealPackage/UnPackageUE3Reader.h"

static bool LoadBulkTextureSMITE(const UTexture2D* texture, const TArray<FTexture2DMipMap> &MipsArray, int MipIndex, bool verbose) {
FMemReader* MemAr = nullptr;
const FTexture2DMipMap &Mip = MipsArray[MipIndex];

int i;
static char buf[2048];
texture->GetFullName(ARRAY_ARG(buf), true, true, true);
char *s = buf;
int len = 0;
if(verbose) {
appPrintf("Smite: Finding %s (Mip %d) in MergedFileIndexCache\n", buf, MipIndex);
}
while (*s) {
*s = toupper((unsigned char) *s);
len++;
s++;
for(i = 0; i < 4; ++i) {
static char tmp[2048];
texture->GetFullName(ARRAY_ARG(tmp), true, true, false);
switch(i) {
case 0:
appSprintf(ARRAY_ARG(buf), "%s", tmp);
break;
case 1:
if(texture->Package == nullptr) {
continue;
}
appSprintf(ARRAY_ARG(buf), "%s.%s", texture->Package->Name, tmp);
break;
case 2:
appSprintf(ARRAY_ARG(buf), "Textures.%s", tmp);
break;
case 3:
if(texture->Package == nullptr) {
continue;
}
appSprintf(ARRAY_ARG(buf), "%s.Textures.%s", texture->Package->Name, tmp);
break;
}
char *s = buf;
int len = 0;
if(verbose) {
appPrintf("Smite: Finding %s (Mip %d) in MergedFileIndexCache\n", buf, MipIndex);
}
while (*s) {
*s = toupper((unsigned char) *s);
len++;
s++;
}

MemAr = GetSmiteBlob(buf, len, MipIndex, "tfc");
if(MemAr != NULL) {
break;
}
}

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

FCompressedChunkHeader H;
*Ar << H;
*MemAr << H;
TArray<FCompressedChunk> Chunks;
FCompressedChunk *Chunk = new (Chunks) FCompressedChunk;
Chunk->UncompressedOffset = 0;
Chunk->UncompressedSize = H.Sum.UncompressedSize;
Chunk->CompressedOffset = 0;
Chunk->CompressedSize = H.Sum.CompressedSize;
FByteBulkData *Bulk = const_cast<FByteBulkData*>(&Mip.Data);
int flags = 0;
int flags = COMPRESS_LZO;
if (Bulk->BulkDataFlags & BULKDATA_CompressedOodle_SMITE) flags = COMPRESS_OODLE;
else if (Bulk->BulkDataFlags & BULKDATA_CompressedZlib) flags = COMPRESS_ZLIB;
else if (Bulk->BulkDataFlags & BULKDATA_CompressedLzo) flags = COMPRESS_LZO;
else if (Bulk->BulkDataFlags & BULKDATA_CompressedLzx) flags = COMPRESS_LZX;

if(flags > 0) {
FUE3ArchiveReader* UE3Loader = new FUE3ArchiveReader(Ar, flags, Chunks);
UE3Loader->IsFullyCompressed = true;
Ar = UE3Loader;
}
FUE3ArchiveReader* Ar = new FUE3ArchiveReader(Ar, flags, Chunks);
Ar->IsFullyCompressed = true;

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

reinterpret_cast<FMemReader*>(free)->Free();
MemAr->Free();
delete Ar;
return true;
}
Expand Down

0 comments on commit 9a17bdb

Please sign in to comment.