Files
isaac-port/generated-src/kage_filesys_file_manager.cpp
T

265 lines
8.3 KiB
C++

#include "classes.h"
// 00a159d0
uint32_t KAGE_Filesys_FileManager::GetPrimaryFilePathHash(uint8_t *filePath)
{
uint32_t hash;
uint32_t normalizedCh;
uint8_t lowerCh;
uint8_t ch;
if (filePath == GHIDRA_CAST<uint8_t *>(0x0)) {
return 0;
}
hash = 0x1505;
ch = *filePath;
while (ch != 0) {
filePath = filePath + 1;
lowerCh = ch + 0x20;
if (0x19 < (uint8_t)(ch + 0xbf)) {
lowerCh = ch;
}
normalizedCh = GHIDRA_UINT(lowerCh);
if (lowerCh == 0x5c) {
normalizedCh = 0x2f;
}
hash = hash * 0x21 + normalizedCh;
ch = *filePath;
}
return hash;
}
// 00a15ab0
uint32_t KAGE_Filesys_FileManager::GetSecondaryFilePathHash()
{
uint8_t bVar1;
uint32_t uVar2;
uint8_t *in_ECX;
uint8_t bVar3;
uint32_t uVar4;
if (in_ECX == GHIDRA_CAST<uint8_t *>(0x0)) {
return 0;
}
uVar4 = 0x5bb2220e;
bVar1 = *in_ECX;
while (bVar1 != 0) {
in_ECX = in_ECX + 1;
bVar3 = bVar1 + 0x20;
if (0x19 < (uint8_t)(bVar1 + 0xbf)) {
bVar3 = bVar1;
}
uVar2 = GHIDRA_UINT(bVar3);
if (bVar3 == 0x5c) {
uVar2 = 0x2f;
}
uVar4 = (uVar2 ^ uVar4) * 0x1000193;
bVar1 = *in_ECX;
}
return uVar4;
}
// 00a179c0
void KAGE_Filesys_FileManager::LoadArchiveFile(uint8_t *param_1, uint32_t *param_2, uint16_t param_3)
{
uint8_t isExpectedChecksum;
uint32_t uVar1;
uint8_t *resolvedPath;
uint8_t *loadedPathChar;
uint32_t isExpectedChecksum;
uint32_t *fileEntry;
uint8_t *extraout_ECX;
uint8_t *resolvedPathChar;
int iVar3;
int *piVar4;
uint32_t uVar5;
int dwordCount;
bool isLess;
char *format;
uint32_t archiveIndex;
uint32_t fileCount;
uint8_t *archivePath;
int local_e58;
int *stream;
uint8_t archiveType;
uint32_t local_e4c;
int archivedFile [3];
int archivedFileRecord;
int chunkBuffer [128];
uint8_t headerMagic [7];
uint8_t local_15;
uint32_t local_14;
void *local_10;
uint8_t *puStack_c;
uint32_t local_8;
uint8_t ch;
local_8 = 0xffffffff;
puStack_c = &LAB_00b11020;
local_10 = ExceptionList;
uVar1 = __security_cookie ^ GHIDRA_UINT((headerMagic + 0x18));
ExceptionList = &local_10;
archivePath = param_1;
local_14 = uVar1;
resolvedPath = FileSystem::ResolvePath(param_1);
if (resolvedPath == GHIDRA_CAST<uint8_t *>(0x0)) {
KAGE_LogMessage(8,GHIDRA_CAST<uint8_t *>("Failed to open archive file \'%s\'\n"));
}
else {
uVar5 = 0;
archiveIndex = 0;
resolvedPathChar = extraout_ECX;
if (DAT_00c37b14 != 0) {
do {
loadedPathChar = GHIDRA_CAST<uint8_t *>((&DAT_00c37a14)[uVar5 * 2]);
resolvedPathChar = resolvedPath;
do {
ch = *loadedPathChar;
isLess = ch < *resolvedPathChar;
if (ch != *resolvedPathChar) {
LAB_00a17a60:
isExpectedChecksum = -GHIDRA_UINT(isLess) | 1;
goto LAB_00a17a65;
}
if (ch == 0) break;
ch = loadedPathChar[1];
isLess = ch < resolvedPathChar[1];
if (ch != resolvedPathChar[1]) goto LAB_00a17a60;
loadedPathChar = loadedPathChar + 2;
resolvedPathChar = resolvedPathChar + 2;
} while (ch != 0);
isExpectedChecksum = 0;
LAB_00a17a65:
} while ((isExpectedChecksum != 0) && (uVar5 = uVar5 + 1, uVar5 < DAT_00c37b14));
archiveIndex = uVar5;
if (0x1f < uVar5) {
KAGE_LogMessage(8,(uint8_t *)
"Cannot load archive file \'%s\', maximum number of archive files exceeded\n"
);
local_8 = 0;
tracked_alloc(1,resolvedPath,0);
ExceptionList = local_10;
return;
}
}
(&DAT_00c37a14)[archiveIndex * 2] = resolvedPath;
stream = GHIDRA_CAST<int *>(0x0);
(GHIDRA_CAST<FileSystem *>((resolvedPathChar)))->FileSystem::open_disk_file(resolvedPath,&stream);
if ((stream == GHIDRA_CAST<int *>(0x0)) &&
(FileSystem::open_archive_file
(&PTR_vftable_00c37a10,GHIDRA_CAST<uint8_t *>((&DAT_00c37a14)[archiveIndex * 2]),&stream),
stream == GHIDRA_CAST<int *>(0x0))) {
KAGE_LogMessage(8,GHIDRA_CAST<uint8_t *>("Failed to open archive file \'%s\'\n"));
if ((void *)(&DAT_00c37a14)[archiveIndex * 2] == (void *)0x0) {
ExceptionList = local_10;
return;
}
local_8 = 1;
tracked_alloc(1,(void *)(&DAT_00c37a14)[archiveIndex * 2],0);
(&DAT_00c37a14)[archiveIndex * 2] = 0;
ExceptionList = local_10;
return;
}
piVar4 = stream;
(**(code **)(*stream + 0x14))(headerMagic,1,7,uVar1);
local_15 = 0;
archiveType = 0;
(**(code **)(*piVar4 + 0x14))(&archiveType,1,1);
(&DAT_00c37a18)[archiveIndex * 8] = archiveType;
local_e58 = 0;
(**(code **)(*piVar4 + 0x14))(&local_e58,4,1);
fileCount = 0;
(**(code **)(*piVar4 + 0x14))(&fileCount,2,1);
(**(code **)(*piVar4 + 0xc))(local_e58,0);
local_e58 = 0;
if ((uint16_t)fileCount != 0) {
do {
fileEntry = operator_new(0x1c);
piVar4 = stream;
local_e4c = 0;
*fileEntry = archiveIndex;
(**(code **)(*stream + 0x14))(&local_e4c,4,1);
fileEntry[1] = local_e4c;
local_e4c = 0;
(**(code **)(*piVar4 + 0x14))(&local_e4c,4,1);
fileEntry[2] = local_e4c;
local_e4c = 0;
(**(code **)(*piVar4 + 0x14))(&local_e4c,4,1);
fileEntry[3] = local_e4c;
local_e4c = 0;
(**(code **)(*piVar4 + 0x14))(&local_e4c,4,1);
fileEntry[4] = local_e4c;
local_e4c = 0;
(**(code **)(*piVar4 + 0x14))(&local_e4c,4,1);
fileEntry[5] = local_e4c;
if (((uint16_t)local_e58 < param_3) && (*param_2 == local_e4c)) {
isExpectedChecksum = 1;
}
else {
isExpectedChecksum = 0;
}
*GHIDRA_CAST<uint8_t *>((fileEntry + 6)) = isExpectedChecksum;
FUN_00a68a50(fileEntry);
local_8 = 2;
uVar1 = 0xababeb98;
memset(chunkBuffer,0,0x200);
local_e4c = *GHIDRA_CAST<uint32_t *>((archivedFileRecord + 0x10));
do {
uVar5 = local_e4c;
if (0x200 < GHIDRA_INT(local_e4c)) {
uVar5 = 0x200;
}
isExpectedChecksum = (**(code **)(archivedFile[0] + 0x14))(chunkBuffer,1,uVar5);
iVar3 = 0;
dwordCount = GHIDRA_INT(((GHIDRA_INT((isExpectedChecksum + 3)) >> 0x1f & 3U) + isExpectedChecksum + 3)) >> 2;
if (0 < dwordCount) {
do {
piVar4 = chunkBuffer + iVar3;
iVar3 = iVar3 + 1;
uVar1 = uVar1 * -0x80000000 + *piVar4 + (uVar1 >> 1);
} while (iVar3 < dwordCount);
}
local_e4c = local_e4c - uVar5;
} while ((0 < GHIDRA_INT(local_e4c)) && (isExpectedChecksum == uVar5));
if (uVar1 == *GHIDRA_CAST<uint32_t *>((archivedFileRecord + 0x14))) {
uVar5 = fileEntry[1] & 0x7fff;
iVar3 = *GHIDRA_CAST<int *>((&DAT_00c37b18 + uVar5 * 4));
uVar1 = 0;
if (iVar3 != 0) {
do {
if (((*GHIDRA_CAST<uint32_t *>((iVar3 + 4)) == fileEntry[1]) &&
(isExpectedChecksum = uVar1, *GHIDRA_CAST<uint32_t *>((iVar3 + 8)) == fileEntry[2])) ||
(isExpectedChecksum = uVar1 + 1, 0x7fff < uVar1)) break;
uVar5 = uVar5 + 1 & 0x7fff;
iVar3 = *GHIDRA_CAST<int *>((&DAT_00c37b18 + uVar5 * 4));
uVar1 = isExpectedChecksum;
} while (iVar3 != 0);
if (0x7fff < isExpectedChecksum) {
format = "Failed to load file %x%x from \'%s\', hash table is full\n";
goto LAB_00a17dad;
}
}
*GHIDRA_CAST<uint32_t **>((&DAT_00c37b18 + uVar5 * 4)) = fileEntry;
}
else {
format = "Failed to load file %x%x from \'%s\', checksum is invalid\n";
LAB_00a17dad:
KAGE_LogMessage(8,GHIDRA_CAST<uint8_t *>(format));
operator_delete(fileEntry,0x1c);
}
local_8 = 0xffffffff;
(GHIDRA_CAST<KAGE::Filesys::ArchivedFile *>((archivedFile)))->KAGE::Filesys::ArchivedFile::~ArchivedFile();
param_2 = param_2 + 1;
local_e58 = local_e58 + 1;
} while ((uint16_t)local_e58 < (uint16_t)fileCount);
piVar4 = stream;
}
(**(code **)*piVar4)(1);
if (DAT_00c37b14 < archiveIndex + 1) {
DAT_00c37b14 = archiveIndex + 1;
}
}
ExceptionList = local_10;
return;
}