mirror of
https://github.com/N64Recomp/N64ModernRuntime.git
synced 2025-10-30 08:02:29 +00:00
osPfsAllocateFile_recomp: add check for max files
This commit is contained in:
parent
1834cef9c9
commit
381e0704b9
1 changed files with 162 additions and 101 deletions
|
|
@ -10,7 +10,8 @@
|
||||||
#define ARRAY_COUNT(arr) (s32)(sizeof(arr) / sizeof(arr[0]))
|
#define ARRAY_COUNT(arr) (s32)(sizeof(arr) / sizeof(arr[0]))
|
||||||
#define MAX_FILES 16
|
#define MAX_FILES 16
|
||||||
|
|
||||||
typedef struct ControllerPak {
|
typedef struct ControllerPak
|
||||||
|
{
|
||||||
std::fstream header;
|
std::fstream header;
|
||||||
std::fstream file;
|
std::fstream file;
|
||||||
} ControllerPak;
|
} ControllerPak;
|
||||||
|
|
@ -19,15 +20,18 @@ typedef struct ControllerPak {
|
||||||
// const std::u8string save_folder = u8"saves";
|
// const std::u8string save_folder = u8"saves";
|
||||||
// std::filesystem::path save_folder_path = config_path / save_folder;
|
// std::filesystem::path save_folder_path = config_path / save_folder;
|
||||||
|
|
||||||
void Pfs_PakHeader_Write(u32* file_size, u32* game_code, u16* company_code, u8* ext_name, u8* game_name, u8 fileIndex) {
|
void Pfs_PakHeader_Write(u32 *file_size, u32 *game_code, u16 *company_code, u8 *ext_name, u8 *game_name, u8 fileIndex)
|
||||||
|
{
|
||||||
ControllerPak pak;
|
ControllerPak pak;
|
||||||
|
|
||||||
pak.header.open("controllerPak_header.sav", std::ios::binary | std::ios::in | std::ios::out);
|
pak.header.open("controllerPak_header.sav", std::ios::binary | std::ios::in | std::ios::out);
|
||||||
|
|
||||||
if (!pak.header.good()) {
|
if (!pak.header.good())
|
||||||
|
{
|
||||||
assert(false);
|
assert(false);
|
||||||
}
|
}
|
||||||
if (!pak.header.is_open()) {
|
if (!pak.header.is_open())
|
||||||
|
{
|
||||||
assert(false);
|
assert(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -54,15 +58,18 @@ void Pfs_PakHeader_Write(u32* file_size, u32* game_code, u16* company_code, u8*
|
||||||
}
|
}
|
||||||
|
|
||||||
void Pfs_PakHeader_Read(u32 *file_size, u32 *game_code, u16 *company_code, char *ext_name, char *game_name,
|
void Pfs_PakHeader_Read(u32 *file_size, u32 *game_code, u16 *company_code, char *ext_name, char *game_name,
|
||||||
u8 fileIndex) {
|
u8 fileIndex)
|
||||||
|
{
|
||||||
ControllerPak pak;
|
ControllerPak pak;
|
||||||
|
|
||||||
pak.header.open("controllerPak_header.sav", std::ios::binary | std::ios::in | std::ios::out);
|
pak.header.open("controllerPak_header.sav", std::ios::binary | std::ios::in | std::ios::out);
|
||||||
|
|
||||||
if (!pak.header.good()) {
|
if (!pak.header.good())
|
||||||
|
{
|
||||||
assert(false);
|
assert(false);
|
||||||
}
|
}
|
||||||
if (!pak.header.is_open()) {
|
if (!pak.header.is_open())
|
||||||
|
{
|
||||||
assert(false);
|
assert(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -88,10 +95,12 @@ void Pfs_PakHeader_Read(u32* file_size, u32* game_code, u16* company_code, char*
|
||||||
pak.header.close();
|
pak.header.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Pfs_ByteSwapFile(u8* buffer, size_t size) {
|
void Pfs_ByteSwapFile(u8 *buffer, size_t size)
|
||||||
|
{
|
||||||
uint8_t c0, c1, c2, c3;
|
uint8_t c0, c1, c2, c3;
|
||||||
|
|
||||||
for (size_t i = 0; i < size; i += 4) {
|
for (size_t i = 0; i < size; i += 4)
|
||||||
|
{
|
||||||
c0 = buffer[i + 0];
|
c0 = buffer[i + 0];
|
||||||
c1 = buffer[i + 1];
|
c1 = buffer[i + 1];
|
||||||
c2 = buffer[i + 2];
|
c2 = buffer[i + 2];
|
||||||
|
|
@ -104,18 +113,22 @@ void Pfs_ByteSwapFile(u8* buffer, size_t size) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ByteSwapCopy(uint8_t* dst, uint8_t* src, size_t size_bytes) {
|
void ByteSwapCopy(uint8_t *dst, uint8_t *src, size_t size_bytes)
|
||||||
for (size_t i = 0; i < size_bytes; i++) {
|
{
|
||||||
|
for (size_t i = 0; i < size_bytes; i++)
|
||||||
|
{
|
||||||
dst[i] = src[i ^ 3];
|
dst[i] = src[i ^ 3];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" void osPfsIsPlug_recomp(uint8_t* rdram, recomp_context* ctx) {
|
extern "C" void osPfsIsPlug_recomp(uint8_t *rdram, recomp_context *ctx)
|
||||||
|
{
|
||||||
MEM_B(0, ctx->r5) = 0b0001; // *pattern = 1;
|
MEM_B(0, ctx->r5) = 0b0001; // *pattern = 1;
|
||||||
ctx->r2 = 0; // PFS_NO_ERROR
|
ctx->r2 = 0; // PFS_NO_ERROR
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" void osPfsInit_recomp(uint8_t* rdram, recomp_context* ctx) {
|
extern "C" void osPfsInit_recomp(uint8_t *rdram, recomp_context *ctx)
|
||||||
|
{
|
||||||
int32_t queue = _arg<0, int32_t>(rdram, ctx);
|
int32_t queue = _arg<0, int32_t>(rdram, ctx);
|
||||||
OSPfs *pfs = _arg<1, OSPfs *>(rdram, ctx);
|
OSPfs *pfs = _arg<1, OSPfs *>(rdram, ctx);
|
||||||
s32 channel = _arg<2, s32>(rdram, ctx);
|
s32 channel = _arg<2, s32>(rdram, ctx);
|
||||||
|
|
@ -127,7 +140,8 @@ extern "C" void osPfsInit_recomp(uint8_t* rdram, recomp_context* ctx) {
|
||||||
ControllerPak pak;
|
ControllerPak pak;
|
||||||
|
|
||||||
// If a header file doesn't exist, create it.
|
// If a header file doesn't exist, create it.
|
||||||
if (!std::filesystem::exists("controllerPak_header.sav")) {
|
if (!std::filesystem::exists("controllerPak_header.sav"))
|
||||||
|
{
|
||||||
pak.header.open("controllerPak_header.sav", std::ios::binary | std::ios::in | std::ios::out | std::ios::trunc);
|
pak.header.open("controllerPak_header.sav", std::ios::binary | std::ios::in | std::ios::out | std::ios::trunc);
|
||||||
pak.header.close();
|
pak.header.close();
|
||||||
}
|
}
|
||||||
|
|
@ -135,7 +149,8 @@ extern "C" void osPfsInit_recomp(uint8_t* rdram, recomp_context* ctx) {
|
||||||
ctx->r2 = 0; // PFS_NO_ERROR
|
ctx->r2 = 0; // PFS_NO_ERROR
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" void osPfsInitPak_recomp(uint8_t* rdram, recomp_context* ctx) {
|
extern "C" void osPfsInitPak_recomp(uint8_t *rdram, recomp_context *ctx)
|
||||||
|
{
|
||||||
int32_t queue = _arg<0, int32_t>(rdram, ctx);
|
int32_t queue = _arg<0, int32_t>(rdram, ctx);
|
||||||
OSPfs *pfs = _arg<1, OSPfs *>(rdram, ctx);
|
OSPfs *pfs = _arg<1, OSPfs *>(rdram, ctx);
|
||||||
s32 channel = _arg<2, s32>(rdram, ctx);
|
s32 channel = _arg<2, s32>(rdram, ctx);
|
||||||
|
|
@ -147,7 +162,8 @@ extern "C" void osPfsInitPak_recomp(uint8_t* rdram, recomp_context* ctx) {
|
||||||
ControllerPak pak;
|
ControllerPak pak;
|
||||||
|
|
||||||
// If a header file doesn't exist, create it.
|
// If a header file doesn't exist, create it.
|
||||||
if (!std::filesystem::exists("controllerPak_header.sav")) {
|
if (!std::filesystem::exists("controllerPak_header.sav"))
|
||||||
|
{
|
||||||
pak.header.open("controllerPak_header.sav", std::ios::binary | std::ios::in | std::ios::out | std::ios::trunc);
|
pak.header.open("controllerPak_header.sav", std::ios::binary | std::ios::in | std::ios::out | std::ios::trunc);
|
||||||
pak.header.close();
|
pak.header.close();
|
||||||
}
|
}
|
||||||
|
|
@ -155,11 +171,13 @@ extern "C" void osPfsInitPak_recomp(uint8_t* rdram, recomp_context* ctx) {
|
||||||
ctx->r2 = 0; // PFS_NO_ERROR
|
ctx->r2 = 0; // PFS_NO_ERROR
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" void osPfsFreeBlocks_recomp(uint8_t* rdram, recomp_context* ctx) {
|
extern "C" void osPfsFreeBlocks_recomp(uint8_t *rdram, recomp_context *ctx)
|
||||||
|
{
|
||||||
s32 *bytes_not_used = _arg<1, s32 *>(rdram, ctx);
|
s32 *bytes_not_used = _arg<1, s32 *>(rdram, ctx);
|
||||||
|
|
||||||
s32 usedSpace = 0;
|
s32 usedSpace = 0;
|
||||||
for (size_t i = 0; i < MAX_FILES; i++) {
|
for (size_t i = 0; i < MAX_FILES; i++)
|
||||||
|
{
|
||||||
u32 file_size = 0;
|
u32 file_size = 0;
|
||||||
u32 game_code = 0;
|
u32 game_code = 0;
|
||||||
u16 company_code = 0;
|
u16 company_code = 0;
|
||||||
|
|
@ -168,9 +186,12 @@ extern "C" void osPfsFreeBlocks_recomp(uint8_t* rdram, recomp_context* ctx) {
|
||||||
|
|
||||||
Pfs_PakHeader_Read(&file_size, &game_code, &company_code, ext_name, game_name, i);
|
Pfs_PakHeader_Read(&file_size, &game_code, &company_code, ext_name, game_name, i);
|
||||||
|
|
||||||
if ((company_code == 0) || (game_code == 0)) {
|
if ((company_code == 0) || (game_code == 0))
|
||||||
|
{
|
||||||
continue;
|
continue;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
usedSpace += file_size >> 8;
|
usedSpace += file_size >> 8;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -180,7 +201,8 @@ extern "C" void osPfsFreeBlocks_recomp(uint8_t* rdram, recomp_context* ctx) {
|
||||||
ctx->r2 = 0; // PFS_NO_ERROR
|
ctx->r2 = 0; // PFS_NO_ERROR
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" void osPfsAllocateFile_recomp(uint8_t* rdram, recomp_context* ctx) {
|
extern "C" void osPfsAllocateFile_recomp(uint8_t *rdram, recomp_context *ctx)
|
||||||
|
{
|
||||||
u16 company_code = _arg<1, u16>(rdram, ctx);
|
u16 company_code = _arg<1, u16>(rdram, ctx);
|
||||||
u32 game_code = _arg<2, u32>(rdram, ctx);
|
u32 game_code = _arg<2, u32>(rdram, ctx);
|
||||||
u8 *game_name = _arg<3, u8 *>(rdram, ctx);
|
u8 *game_name = _arg<3, u8 *>(rdram, ctx);
|
||||||
|
|
@ -188,14 +210,16 @@ extern "C" void osPfsAllocateFile_recomp(uint8_t* rdram, recomp_context* ctx) {
|
||||||
u32 file_size = (s32)MEM_W(0x14, ctx->r29);
|
u32 file_size = (s32)MEM_W(0x14, ctx->r29);
|
||||||
s32 *file_no = TO_PTR(s32, MEM_W(0x18, ctx->r29));
|
s32 *file_no = TO_PTR(s32, MEM_W(0x18, ctx->r29));
|
||||||
|
|
||||||
if ((company_code == 0) || (game_code == 0)) {
|
if ((company_code == 0) || (game_code == 0))
|
||||||
|
{
|
||||||
ctx->r2 = 5; // PFS_ERR_INVALID
|
ctx->r2 = 5; // PFS_ERR_INVALID
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Search for a free slot */
|
/* Search for a free slot */
|
||||||
u8 freeFileIndex = 0;
|
u8 freeFileIndex = 0;
|
||||||
for (size_t i = 0; i < MAX_FILES; i++) {
|
for (size_t i = 0; i < MAX_FILES; i++)
|
||||||
|
{
|
||||||
u32 file_size_ = 0;
|
u32 file_size_ = 0;
|
||||||
u32 game_code_ = 0;
|
u32 game_code_ = 0;
|
||||||
u16 company_code_ = 0;
|
u16 company_code_ = 0;
|
||||||
|
|
@ -204,12 +228,18 @@ extern "C" void osPfsAllocateFile_recomp(uint8_t* rdram, recomp_context* ctx) {
|
||||||
|
|
||||||
Pfs_PakHeader_Read(&file_size_, &game_code_, &company_code_, ext_name_, game_name_, i);
|
Pfs_PakHeader_Read(&file_size_, &game_code_, &company_code_, ext_name_, game_name_, i);
|
||||||
|
|
||||||
if ((company_code_ == 0) || (game_code_ == 0)) {
|
if ((company_code_ == 0) || (game_code_ == 0))
|
||||||
|
{
|
||||||
freeFileIndex = i;
|
freeFileIndex = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (freeFileIndex == MAX_FILES) {
|
||||||
|
ctx->r2 = 8; // PFS_DIR_FULL
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Pfs_PakHeader_Write(&file_size, &game_code, &company_code, ext_name, game_name, freeFileIndex);
|
Pfs_PakHeader_Write(&file_size, &game_code, &company_code, ext_name, game_name, freeFileIndex);
|
||||||
|
|
||||||
/* Create empty file */
|
/* Create empty file */
|
||||||
|
|
@ -237,7 +267,8 @@ extern "C" void osPfsAllocateFile_recomp(uint8_t* rdram, recomp_context* ctx) {
|
||||||
ctx->r2 = 0; // PFS_NO_ERROR
|
ctx->r2 = 0; // PFS_NO_ERROR
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" void osPfsFileState_recomp(uint8_t* rdram, recomp_context* ctx) {
|
extern "C" void osPfsFileState_recomp(uint8_t *rdram, recomp_context *ctx)
|
||||||
|
{
|
||||||
s32 file_no = _arg<1, s32>(rdram, ctx);
|
s32 file_no = _arg<1, s32>(rdram, ctx);
|
||||||
OSPfsState *state = _arg<2, OSPfsState *>(rdram, ctx);
|
OSPfsState *state = _arg<2, OSPfsState *>(rdram, ctx);
|
||||||
|
|
||||||
|
|
@ -253,7 +284,8 @@ extern "C" void osPfsFileState_recomp(uint8_t* rdram, recomp_context* ctx) {
|
||||||
|
|
||||||
char filename[100];
|
char filename[100];
|
||||||
sprintf(filename, "controllerPak_file_%d.sav", file_no);
|
sprintf(filename, "controllerPak_file_%d.sav", file_no);
|
||||||
if (!std::filesystem::exists(filename)) {
|
if (!std::filesystem::exists(filename))
|
||||||
|
{
|
||||||
ctx->r2 = 5;
|
ctx->r2 = 5;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -265,24 +297,28 @@ extern "C" void osPfsFileState_recomp(uint8_t* rdram, recomp_context* ctx) {
|
||||||
state->company_code = game_code;
|
state->company_code = game_code;
|
||||||
state->game_code = game_code;
|
state->game_code = game_code;
|
||||||
|
|
||||||
for (size_t j = 0; j < ARRAY_COUNT(game_name); j++) {
|
for (size_t j = 0; j < ARRAY_COUNT(game_name); j++)
|
||||||
|
{
|
||||||
state->game_name[j] = game_name[j];
|
state->game_name[j] = game_name[j];
|
||||||
}
|
}
|
||||||
for (size_t j = 0; j < ARRAY_COUNT(ext_name); j++) {
|
for (size_t j = 0; j < ARRAY_COUNT(ext_name); j++)
|
||||||
|
{
|
||||||
state->ext_name[j] = ext_name[j];
|
state->ext_name[j] = ext_name[j];
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx->r2 = 0; // PFS_NO_ERROR
|
ctx->r2 = 0; // PFS_NO_ERROR
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" void osPfsFindFile_recomp(uint8_t* rdram, recomp_context* ctx) {
|
extern "C" void osPfsFindFile_recomp(uint8_t *rdram, recomp_context *ctx)
|
||||||
|
{
|
||||||
u16 company_code = _arg<1, u16>(rdram, ctx);
|
u16 company_code = _arg<1, u16>(rdram, ctx);
|
||||||
u32 game_code = _arg<2, u32>(rdram, ctx);
|
u32 game_code = _arg<2, u32>(rdram, ctx);
|
||||||
u8 *game_name = _arg<3, u8 *>(rdram, ctx);
|
u8 *game_name = _arg<3, u8 *>(rdram, ctx);
|
||||||
u8 *ext_name = TO_PTR(u8, MEM_W(0x10, ctx->r29));
|
u8 *ext_name = TO_PTR(u8, MEM_W(0x10, ctx->r29));
|
||||||
s32 *file_no = TO_PTR(s32, MEM_W(0x14, ctx->r29));
|
s32 *file_no = TO_PTR(s32, MEM_W(0x14, ctx->r29));
|
||||||
|
|
||||||
for (size_t i = 0; i < MAX_FILES; i++) {
|
for (size_t i = 0; i < MAX_FILES; i++)
|
||||||
|
{
|
||||||
u32 file_size_ = 0;
|
u32 file_size_ = 0;
|
||||||
u32 game_code_ = 0;
|
u32 game_code_ = 0;
|
||||||
u16 company_code_ = 0;
|
u16 company_code_ = 0;
|
||||||
|
|
@ -291,12 +327,16 @@ extern "C" void osPfsFindFile_recomp(uint8_t* rdram, recomp_context* ctx) {
|
||||||
|
|
||||||
Pfs_PakHeader_Read(&file_size_, &game_code_, &company_code_, ext_name_, game_name_, i);
|
Pfs_PakHeader_Read(&file_size_, &game_code_, &company_code_, ext_name_, game_name_, i);
|
||||||
|
|
||||||
if ((company_code_ == 0) || (game_code_ == 0)) {
|
if ((company_code_ == 0) || (game_code_ == 0))
|
||||||
|
{
|
||||||
continue;
|
continue;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
if ((game_code == game_code_) && (company_code == company_code_) &&
|
if ((game_code == game_code_) && (company_code == company_code_) &&
|
||||||
(strcmp((const char *)game_name, (const char *)game_name_) == 0) &&
|
(strcmp((const char *)game_name, (const char *)game_name_) == 0) &&
|
||||||
strcmp((const char*) ext_name, (const char*) ext_name_) == 0) {
|
strcmp((const char *)ext_name, (const char *)ext_name_) == 0)
|
||||||
|
{
|
||||||
// File found
|
// File found
|
||||||
*file_no = i;
|
*file_no = i;
|
||||||
ctx->r2 = 0; // PFS_NO_ERROR
|
ctx->r2 = 0; // PFS_NO_ERROR
|
||||||
|
|
@ -309,7 +349,8 @@ extern "C" void osPfsFindFile_recomp(uint8_t* rdram, recomp_context* ctx) {
|
||||||
ctx->r2 = 5; // PFS_ERR_INVALID
|
ctx->r2 = 5; // PFS_ERR_INVALID
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" void osPfsReadWriteFile_recomp(uint8_t* rdram, recomp_context* ctx) {
|
extern "C" void osPfsReadWriteFile_recomp(uint8_t *rdram, recomp_context *ctx)
|
||||||
|
{
|
||||||
s32 file_no = _arg<1, s32>(rdram, ctx);
|
s32 file_no = _arg<1, s32>(rdram, ctx);
|
||||||
u8 flag = _arg<2, u8>(rdram, ctx);
|
u8 flag = _arg<2, u8>(rdram, ctx);
|
||||||
s32 offset = _arg<3, s32>(rdram, ctx);
|
s32 offset = _arg<3, s32>(rdram, ctx);
|
||||||
|
|
@ -322,25 +363,31 @@ extern "C" void osPfsReadWriteFile_recomp(uint8_t* rdram, recomp_context* ctx) {
|
||||||
sprintf(filename, "controllerPak_file_%d.sav", file_no);
|
sprintf(filename, "controllerPak_file_%d.sav", file_no);
|
||||||
pak.file.open(filename, std::ios::binary | std::ios::in | std::ios::out);
|
pak.file.open(filename, std::ios::binary | std::ios::in | std::ios::out);
|
||||||
|
|
||||||
if (!std::filesystem::exists(filename)) {
|
if (!std::filesystem::exists(filename))
|
||||||
|
{
|
||||||
ctx->r2 = 5; // PFS_ERR_INVALID
|
ctx->r2 = 5; // PFS_ERR_INVALID
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!pak.file.good()) {
|
if (!pak.file.good())
|
||||||
|
{
|
||||||
ctx->r2 = 5; // PFS_ERR_INVALID
|
ctx->r2 = 5; // PFS_ERR_INVALID
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!pak.file.is_open()) {
|
if (!pak.file.is_open())
|
||||||
|
{
|
||||||
ctx->r2 = 5; // PFS_ERR_INVALID
|
ctx->r2 = 5; // PFS_ERR_INVALID
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
u8 *swapBuffer = (u8 *)malloc(size_in_bytes);
|
u8 *swapBuffer = (u8 *)malloc(size_in_bytes);
|
||||||
if (flag == 0) {
|
if (flag == 0)
|
||||||
|
{
|
||||||
pak.file.seekg(offset, std::ios::beg);
|
pak.file.seekg(offset, std::ios::beg);
|
||||||
pak.file.read((char *)swapBuffer, size_in_bytes);
|
pak.file.read((char *)swapBuffer, size_in_bytes);
|
||||||
ByteSwapCopy(data_buffer, swapBuffer, size_in_bytes);
|
ByteSwapCopy(data_buffer, swapBuffer, size_in_bytes);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
ByteSwapCopy(swapBuffer, data_buffer, size_in_bytes);
|
ByteSwapCopy(swapBuffer, data_buffer, size_in_bytes);
|
||||||
pak.file.seekp(offset, std::ios::beg);
|
pak.file.seekp(offset, std::ios::beg);
|
||||||
pak.file.write((char *)swapBuffer, size_in_bytes);
|
pak.file.write((char *)swapBuffer, size_in_bytes);
|
||||||
|
|
@ -352,16 +399,19 @@ extern "C" void osPfsReadWriteFile_recomp(uint8_t* rdram, recomp_context* ctx) {
|
||||||
ctx->r2 = 0; // PFS_NO_ERROR
|
ctx->r2 = 0; // PFS_NO_ERROR
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" void osPfsChecker_recomp(uint8_t* rdram, recomp_context* ctx) {
|
extern "C" void osPfsChecker_recomp(uint8_t *rdram, recomp_context *ctx)
|
||||||
|
{
|
||||||
ctx->r2 = 0; // PFS_NO_ERROR
|
ctx->r2 = 0; // PFS_NO_ERROR
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" void osPfsNumFiles_recomp(uint8_t* rdram, recomp_context* ctx) {
|
extern "C" void osPfsNumFiles_recomp(uint8_t *rdram, recomp_context *ctx)
|
||||||
|
{
|
||||||
s32 *max_files = _arg<1, s32 *>(rdram, ctx);
|
s32 *max_files = _arg<1, s32 *>(rdram, ctx);
|
||||||
s32 *files_used = _arg<2, s32 *>(rdram, ctx);
|
s32 *files_used = _arg<2, s32 *>(rdram, ctx);
|
||||||
|
|
||||||
u8 files = 0;
|
u8 files = 0;
|
||||||
for (size_t i = 0; i < MAX_FILES; i++) {
|
for (size_t i = 0; i < MAX_FILES; i++)
|
||||||
|
{
|
||||||
u32 file_size = 0;
|
u32 file_size = 0;
|
||||||
u32 game_code = 0;
|
u32 game_code = 0;
|
||||||
u16 company_code = 0;
|
u16 company_code = 0;
|
||||||
|
|
@ -370,7 +420,8 @@ extern "C" void osPfsNumFiles_recomp(uint8_t* rdram, recomp_context* ctx) {
|
||||||
|
|
||||||
Pfs_PakHeader_Read(&file_size, &game_code, &company_code, ext_name, game_name, i);
|
Pfs_PakHeader_Read(&file_size, &game_code, &company_code, ext_name, game_name, i);
|
||||||
|
|
||||||
if ((company_code != 0) || (game_code != 0)) {
|
if ((company_code != 0) || (game_code != 0))
|
||||||
|
{
|
||||||
files++;
|
files++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -381,20 +432,23 @@ extern "C" void osPfsNumFiles_recomp(uint8_t* rdram, recomp_context* ctx) {
|
||||||
ctx->r2 = 0; // PFS_NO_ERROR
|
ctx->r2 = 0; // PFS_NO_ERROR
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" void osPfsDeleteFile_recomp(uint8_t* rdram, recomp_context* ctx) {
|
extern "C" void osPfsDeleteFile_recomp(uint8_t *rdram, recomp_context *ctx)
|
||||||
|
{
|
||||||
u16 company_code = _arg<1, u16>(rdram, ctx);
|
u16 company_code = _arg<1, u16>(rdram, ctx);
|
||||||
u32 game_code = _arg<2, u32>(rdram, ctx);
|
u32 game_code = _arg<2, u32>(rdram, ctx);
|
||||||
u8 *game_name = _arg<3, u8 *>(rdram, ctx);
|
u8 *game_name = _arg<3, u8 *>(rdram, ctx);
|
||||||
u8 *ext_name = TO_PTR(u8, MEM_W(0x10, ctx->r29));
|
u8 *ext_name = TO_PTR(u8, MEM_W(0x10, ctx->r29));
|
||||||
|
|
||||||
if (company_code == 0 || game_code == 0) {
|
if (company_code == 0 || game_code == 0)
|
||||||
|
{
|
||||||
ctx->r2 = 5; // PFS_ERR_INVALID
|
ctx->r2 = 5; // PFS_ERR_INVALID
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ControllerPak pak;
|
ControllerPak pak;
|
||||||
|
|
||||||
for (int i = 0; i < MAX_FILES; i++) {
|
for (int i = 0; i < MAX_FILES; i++)
|
||||||
|
{
|
||||||
u32 file_size_ = 0;
|
u32 file_size_ = 0;
|
||||||
u32 game_code_ = 0;
|
u32 game_code_ = 0;
|
||||||
u16 company_code_ = 0;
|
u16 company_code_ = 0;
|
||||||
|
|
@ -403,20 +457,26 @@ extern "C" void osPfsDeleteFile_recomp(uint8_t* rdram, recomp_context* ctx) {
|
||||||
|
|
||||||
Pfs_PakHeader_Read(&file_size_, &game_code_, &company_code_, ext_name_, game_name_, i);
|
Pfs_PakHeader_Read(&file_size_, &game_code_, &company_code_, ext_name_, game_name_, i);
|
||||||
|
|
||||||
if ((company_code_ == 0) || (game_code_ == 0)) {
|
if ((company_code_ == 0) || (game_code_ == 0))
|
||||||
|
{
|
||||||
continue;
|
continue;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
if ((game_code == game_code_) && (company_code == company_code_) &&
|
if ((game_code == game_code_) && (company_code == company_code_) &&
|
||||||
(strcmp((const char *)game_name, (const char *)game_name_) == 0) &&
|
(strcmp((const char *)game_name, (const char *)game_name_) == 0) &&
|
||||||
strcmp((const char*) ext_name, (const char*) ext_name_) == 0) {
|
strcmp((const char *)ext_name, (const char *)ext_name_) == 0)
|
||||||
|
{
|
||||||
// File found
|
// File found
|
||||||
|
|
||||||
pak.header.open("controllerPak_header.sav", std::ios::binary | std::ios::in | std::ios::out);
|
pak.header.open("controllerPak_header.sav", std::ios::binary | std::ios::in | std::ios::out);
|
||||||
|
|
||||||
if (!pak.header.good()) {
|
if (!pak.header.good())
|
||||||
|
{
|
||||||
assert(false);
|
assert(false);
|
||||||
}
|
}
|
||||||
if (!pak.header.is_open()) {
|
if (!pak.header.is_open())
|
||||||
|
{
|
||||||
assert(false);
|
assert(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -446,6 +506,7 @@ extern "C" void osPfsDeleteFile_recomp(uint8_t* rdram, recomp_context* ctx) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" void osPfsRepairId_recomp(uint8_t* rdram, recomp_context* ctx) {
|
extern "C" void osPfsRepairId_recomp(uint8_t *rdram, recomp_context *ctx)
|
||||||
|
{
|
||||||
_return<s32>(ctx, 0); // PFS_NO_ERROR
|
_return<s32>(ctx, 0); // PFS_NO_ERROR
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue