mirror of
https://github.com/krystalgamer/spidey-decomp.git
synced 2024-11-23 21:39:48 +00:00
dirAddToPkr
This commit is contained in:
parent
d9a2f35ee7
commit
4d13951a9f
1
main.cpp
1
main.cpp
@ -410,6 +410,7 @@ i32 validate(void)
|
||||
validate_PKR_FOOTER();
|
||||
validate_PKR_DIRINFO();
|
||||
validate_LIBPKR_HANDLE();
|
||||
validate_NODE_DIRINFO();
|
||||
|
||||
puts("[*] Validation done!");
|
||||
|
||||
|
59
pkr.cpp
59
pkr.cpp
@ -2,6 +2,8 @@
|
||||
#include "zlib.h"
|
||||
|
||||
#include "validate.h"
|
||||
#include <cstring>
|
||||
#include <cstdlib>
|
||||
|
||||
#define PKRFILE_UNCOMPRESSED -2
|
||||
#define PKRFILE_COMPRESSED_ZLIB 2
|
||||
@ -11,6 +13,54 @@ LIBPKR_HANDLE* gGlobalPkr;
|
||||
// @NB: the original was built as library and built in debug mode, I won't do the same
|
||||
// too much hassle for little gain
|
||||
|
||||
// @Ok
|
||||
u8 dirAddToPkr(LIBPKR_HANDLE* pHandle, PKR_DIRINFO dirInfo)
|
||||
{
|
||||
NODE_DIRINFO* newNode = new NODE_DIRINFO;
|
||||
if (!newNode)
|
||||
{
|
||||
PKR_ReportError("dirAddToPKR: Cannot allocate new dir node.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
memset(newNode, 0, sizeof(NODE_DIRINFO));
|
||||
memcpy(newNode, &dirInfo, sizeof(PKR_DIRINFO));
|
||||
|
||||
if (!pHandle->pDirInfo)
|
||||
{
|
||||
pHandle->pDirInfo = newNode;
|
||||
}
|
||||
else
|
||||
{
|
||||
NODE_DIRINFO* pNode;
|
||||
for (pNode = pHandle->pDirInfo;
|
||||
pNode->mNext;
|
||||
pNode = pNode->mNext)
|
||||
{
|
||||
if (!strcmp(pNode->dirInfo.name, newNode->dirInfo.name))
|
||||
{
|
||||
PKR_ReportError("dirAddToPKR: Dir already added.");
|
||||
delete newNode;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (!strcmp(pNode->dirInfo.name, newNode->dirInfo.name))
|
||||
{
|
||||
PKR_ReportError("dirAddToPKR: Dir already added.");
|
||||
delete newNode;
|
||||
return 0;
|
||||
}
|
||||
|
||||
pNode->mNext = newNode;
|
||||
newNode->mPrev = pNode;
|
||||
newNode->mNext = 0;
|
||||
}
|
||||
|
||||
pHandle->footer.numDirs++;
|
||||
return 1;
|
||||
}
|
||||
|
||||
// @BIGTODO
|
||||
u8 PKR_GetLastError(char*)
|
||||
{
|
||||
@ -154,3 +204,12 @@ void validate_LIBPKR_HANDLE(void)
|
||||
VALIDATE(LIBPKR_HANDLE, footer, 0x114);
|
||||
VALIDATE(LIBPKR_HANDLE, pDirInfo, 0x120);
|
||||
}
|
||||
|
||||
void validate_NODE_DIRINFO(void)
|
||||
{
|
||||
VALIDATE_SIZE(NODE_DIRINFO, 0x30);
|
||||
|
||||
VALIDATE(NODE_DIRINFO, dirInfo, 0x0);
|
||||
VALIDATE(NODE_DIRINFO, mNext, 0x28);
|
||||
VALIDATE(NODE_DIRINFO, mPrev, 0x2C);
|
||||
}
|
||||
|
12
pkr.h
12
pkr.h
@ -30,6 +30,13 @@ struct PKR_DIRINFO
|
||||
i32 numFiles;
|
||||
};
|
||||
|
||||
struct NODE_DIRINFO
|
||||
{
|
||||
PKR_DIRINFO dirInfo;
|
||||
struct NODE_DIRINFO* mNext;
|
||||
struct NODE_DIRINFO* mPrev;
|
||||
};
|
||||
|
||||
struct LIBPKR_HANDLE
|
||||
{
|
||||
FILE* fp;
|
||||
@ -42,7 +49,7 @@ struct LIBPKR_HANDLE
|
||||
i32 dirOffset;
|
||||
PKR_FOOTER footer;
|
||||
|
||||
PKR_DIRINFO* pDirInfo;
|
||||
NODE_DIRINFO* pDirInfo;
|
||||
|
||||
u8 padBottom[0x12C-0x120-4];
|
||||
};
|
||||
@ -56,11 +63,14 @@ EXPORT u8 PKR_UnlockFile(FILE** fp);
|
||||
EXPORT u8 PKR_Open(LIBPKR_HANDLE**, const char*, i32);
|
||||
EXPORT u8 PKR_GetLastError(char*);
|
||||
|
||||
EXPORT u8 dirAddToPkr(LIBPKR_HANDLE*, PKR_DIRINFO);
|
||||
|
||||
EXPORT extern LIBPKR_HANDLE* gGlobalPkr;
|
||||
|
||||
void validate_PKR_FILEINFO(void);
|
||||
void validate_PKR_FOOTER(void);
|
||||
void validate_PKR_DIRINFO(void);
|
||||
void validate_LIBPKR_HANDLE(void);
|
||||
void validate_NODE_DIRINFO(void);
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user