-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
413 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
#include <stdio.h> | ||
#include <string.h> | ||
|
||
#include "FileSystem.hpp" | ||
#include "Pbg3Archive.hpp" | ||
#include "utils.hpp" | ||
|
||
u32 g_LastFileSize; | ||
|
||
u8 *OpenPath(char *filepath, int isExternalResource) | ||
{ | ||
// char *slashPos; | ||
u8 *buf; | ||
FILE *fileOb; | ||
size_t fsize; | ||
// this is pbg3Idx | ||
i32 pleaseGiveMeC; | ||
char *entryname; | ||
i32 i; | ||
|
||
pleaseGiveMeC = -1; | ||
if (isExternalResource == 0) | ||
{ | ||
entryname = strrchr(filepath, '¥¥'); | ||
if (entryname == (char *)0x0) | ||
{ | ||
entryname = filepath; | ||
} | ||
else | ||
{ | ||
entryname = entryname + 1; | ||
} | ||
entryname = strrchr(entryname, '/'); | ||
if (entryname == (char *)0x0) | ||
{ | ||
entryname = filepath; | ||
} | ||
else | ||
{ | ||
entryname = entryname + 1; | ||
} | ||
if (g_Pbg3Archives != NULL) | ||
{ | ||
for (i = 0; i < 0x10; i += 1) | ||
{ | ||
if (g_Pbg3Archives[i] != NULL) | ||
{ | ||
pleaseGiveMeC = g_Pbg3Archives[i]->FindEntry(entryname); | ||
if (pleaseGiveMeC >= 0) | ||
{ | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
if (pleaseGiveMeC < 0) | ||
{ | ||
return NULL; | ||
} | ||
} | ||
if (pleaseGiveMeC >= 0) | ||
{ | ||
DebugPrint2("%s Decode ... ¥n", entryname); | ||
buf = g_Pbg3Archives[i]->ReadEntry(pleaseGiveMeC, entryname); | ||
g_LastFileSize = g_Pbg3Archives[i]->GetEntrySize(pleaseGiveMeC); | ||
} | ||
else | ||
{ | ||
DebugPrint2("%s Load ... ¥n", filepath); | ||
fileOb = fopen(filepath, "rb"); | ||
if (fileOb == NULL) | ||
{ | ||
DebugPrint2("error : %s is not found.¥n", filepath); | ||
return NULL; | ||
} | ||
else | ||
{ | ||
fseek(fileOb, 0, SEEK_END); | ||
fsize = ftell(fileOb); | ||
g_LastFileSize = fsize; | ||
fseek(fileOb, 0, SEEK_SET); | ||
buf = (u8 *)malloc(fsize); | ||
fread(buf, 1, fsize, fileOb); | ||
fclose(fileOb); | ||
} | ||
} | ||
return buf; | ||
} | ||
|
||
int WriteDataToFile(char *path, void *data, size_t size) | ||
{ | ||
FILE *f; | ||
|
||
f = fopen(path, "wb"); | ||
if (f == (FILE *)0x0) | ||
{ | ||
return -1; | ||
} | ||
else | ||
{ | ||
if (fwrite(data, 1, size, f) != size) | ||
{ | ||
fclose(f); | ||
return -2; | ||
} | ||
else | ||
{ | ||
fclose(f); | ||
return 0; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#pragma once | ||
|
||
#include "inttypes.hpp" | ||
|
||
u8 *OpenPath(char *filepath, int isExternalResource); | ||
int WriteDataToFile(char *path, void *data, size_t size); | ||
|
||
extern u32 g_LastFileSize; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#include <stddef.h> | ||
|
||
#include "Pbg3Archive.hpp" | ||
|
||
Pbg3Archive **g_Pbg3Archives; | ||
|
||
u32 Pbg3Archive::FindEntry(char *path) | ||
{ | ||
return -1; | ||
} | ||
|
||
u8 *Pbg3Archive::ReadEntry(u32 entryIdx, char *filename) | ||
{ | ||
return NULL; | ||
} | ||
|
||
u32 Pbg3Archive::GetEntrySize(u32 entryIdx) | ||
{ | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#pragma once | ||
|
||
#include "inttypes.hpp" | ||
|
||
struct Pbg3Archive | ||
{ | ||
u32 FindEntry(char *path); | ||
u8 *ReadEntry(u32 entryIdx, char *filename); | ||
u32 GetEntrySize(u32 entryIdx); | ||
}; | ||
|
||
extern Pbg3Archive **g_Pbg3Archives; |
Oops, something went wrong.