mirror of
https://github.com/d0k3/GodMode9.git
synced 2025-06-26 21:52:48 +00:00
Cleanup vgame.c / vgame.h
This commit is contained in:
parent
6bf88bbdfb
commit
ddd1dd070b
@ -4,21 +4,13 @@
|
|||||||
#include "aes.h"
|
#include "aes.h"
|
||||||
#include "ff.h"
|
#include "ff.h"
|
||||||
|
|
||||||
#define VFLAG_EXTHDR (1<<25)
|
#define VFLAG_EXTHDR (1<<26)
|
||||||
#define VFLAG_CIA (1<<26) // unused, see below
|
#define VFLAG_CIA (1<<27)
|
||||||
#define VFLAG_NCSD (1<<27) // unused, see below
|
#define VFLAG_NCSD (1<<28)
|
||||||
#define VFLAG_NCCH (1<<28)
|
#define VFLAG_NCCH (1<<29)
|
||||||
#define VFLAG_EXEFS (1<<29)
|
#define VFLAG_EXEFS (1<<30)
|
||||||
#define VFLAG_ROMFS (1<<30)
|
#define VFLAG_ROMFS (1<<31)
|
||||||
#define VFLAG_LV3 (1<<31)
|
#define VFLAG_GAMEDIR (VFLAG_CIA|VFLAG_NCSD|VFLAG_NCCH|VFLAG_EXEFS|VFLAG_ROMFS|VFLAG_LV3)
|
||||||
|
|
||||||
#define VDIR_CIA VFLAG_CIA
|
|
||||||
#define VDIR_NCSD VFLAG_NCSD
|
|
||||||
#define VDIR_NCCH VFLAG_NCCH
|
|
||||||
#define VDIR_EXEFS VFLAG_EXEFS
|
|
||||||
#define VDIR_ROMFS VFLAG_ROMFS
|
|
||||||
#define VDIR_LV3 VFLAG_LV3
|
|
||||||
#define VDIR_GAME (VDIR_CIA|VDIR_NCSD|VDIR_NCCH|VDIR_EXEFS|VDIR_ROMFS|VDIR_LV3)
|
|
||||||
|
|
||||||
#define MAX_N_TEMPLATES 2048 // this leaves us with enough room (128kB reserved)
|
#define MAX_N_TEMPLATES 2048 // this leaves us with enough room (128kB reserved)
|
||||||
|
|
||||||
@ -343,7 +335,7 @@ u32 InitVGameDrive(void) { // prerequisite: game file mounted as image
|
|||||||
offset_lv3 = (u64) -1;
|
offset_lv3 = (u64) -1;
|
||||||
offset_lv3fd = (u64) -1;
|
offset_lv3fd = (u64) -1;
|
||||||
|
|
||||||
base_vdir = (type == GAME_CIA) ? VDIR_CIA : (type == GAME_NCSD) ? VDIR_NCSD : (type == GAME_NCCH) ? VDIR_NCCH : 0;
|
base_vdir = (type == GAME_CIA) ? VFLAG_CIA : (type == GAME_NCSD) ? VFLAG_NCSD : (type == GAME_NCCH) ? VFLAG_NCCH : 0;
|
||||||
if (!base_vdir) return 0;
|
if (!base_vdir) return 0;
|
||||||
|
|
||||||
vgame_type = type;
|
vgame_type = type;
|
||||||
@ -364,7 +356,7 @@ bool OpenVGameDir(VirtualDir* vdir, VirtualFile* ventry) {
|
|||||||
vdir->size = GetMountSize();
|
vdir->size = GetMountSize();
|
||||||
vdir->flags = VFLAG_DIR|base_vdir;
|
vdir->flags = VFLAG_DIR|base_vdir;
|
||||||
} else { // non root dir
|
} else { // non root dir
|
||||||
if (!(ventry->flags & VFLAG_DIR) || !(ventry->flags & VDIR_GAME))
|
if (!(ventry->flags & VFLAG_DIR) || !(ventry->flags & VFLAG_GAMEDIR))
|
||||||
return false;
|
return false;
|
||||||
vdir->offset = ventry->offset;
|
vdir->offset = ventry->offset;
|
||||||
vdir->size = ventry->size;
|
vdir->size = ventry->size;
|
||||||
@ -372,7 +364,7 @@ bool OpenVGameDir(VirtualDir* vdir, VirtualFile* ventry) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// build directories where required
|
// build directories where required
|
||||||
if ((vdir->flags & VDIR_CIA) && (offset_cia != vdir->offset)) {
|
if ((vdir->flags & VFLAG_CIA) && (offset_cia != vdir->offset)) {
|
||||||
CiaInfo info;
|
CiaInfo info;
|
||||||
if ((ReadImageBytes((u8*) cia, 0, 0x20) != 0) ||
|
if ((ReadImageBytes((u8*) cia, 0, 0x20) != 0) ||
|
||||||
(ValidateCiaHeader(&(cia->header)) != 0) ||
|
(ValidateCiaHeader(&(cia->header)) != 0) ||
|
||||||
@ -381,25 +373,25 @@ bool OpenVGameDir(VirtualDir* vdir, VirtualFile* ventry) {
|
|||||||
return false;
|
return false;
|
||||||
offset_cia = vdir->offset; // always zero(!)
|
offset_cia = vdir->offset; // always zero(!)
|
||||||
if (!BuildVGameCiaDir()) return false;
|
if (!BuildVGameCiaDir()) return false;
|
||||||
} else if ((vdir->flags & VDIR_NCSD) && (offset_ncsd != vdir->offset)) {
|
} else if ((vdir->flags & VFLAG_NCSD) && (offset_ncsd != vdir->offset)) {
|
||||||
if ((ReadImageBytes((u8*) ncsd, 0, sizeof(NcsdHeader)) != 0) ||
|
if ((ReadImageBytes((u8*) ncsd, 0, sizeof(NcsdHeader)) != 0) ||
|
||||||
(ValidateNcsdHeader(ncsd) != 0))
|
(ValidateNcsdHeader(ncsd) != 0))
|
||||||
return 0;
|
return 0;
|
||||||
offset_ncsd = vdir->offset; // always zero(!)
|
offset_ncsd = vdir->offset; // always zero(!)
|
||||||
if (!BuildVGameNcsdDir()) return 0;
|
if (!BuildVGameNcsdDir()) return 0;
|
||||||
} else if ((vdir->flags & VDIR_NCCH) && (offset_ncch != vdir->offset)) {
|
} else if ((vdir->flags & VFLAG_NCCH) && (offset_ncch != vdir->offset)) {
|
||||||
if ((ReadImageBytes((u8*) ncch, vdir->offset, sizeof(NcchHeader)) != 0) ||
|
if ((ReadImageBytes((u8*) ncch, vdir->offset, sizeof(NcchHeader)) != 0) ||
|
||||||
(ValidateNcchHeader(ncch) != 0))
|
(ValidateNcchHeader(ncch) != 0))
|
||||||
return false;
|
return false;
|
||||||
offset_ncch = vdir->offset;
|
offset_ncch = vdir->offset;
|
||||||
if (!BuildVGameNcchDir()) return false;
|
if (!BuildVGameNcchDir()) return false;
|
||||||
} else if ((vdir->flags & VDIR_EXEFS) && (offset_exefs != vdir->offset)) {
|
} else if ((vdir->flags & VFLAG_EXEFS) && (offset_exefs != vdir->offset)) {
|
||||||
if ((ReadImageBytes((u8*) exefs, vdir->offset, sizeof(ExeFsHeader)) != 0) ||
|
if ((ReadImageBytes((u8*) exefs, vdir->offset, sizeof(ExeFsHeader)) != 0) ||
|
||||||
(ValidateExeFsHeader(exefs, ncch->size_exefs * NCCH_MEDIA_UNIT) != 0))
|
(ValidateExeFsHeader(exefs, ncch->size_exefs * NCCH_MEDIA_UNIT) != 0))
|
||||||
return false;
|
return false;
|
||||||
offset_exefs = vdir->offset;
|
offset_exefs = vdir->offset;
|
||||||
if (!BuildVGameExeFsDir()) return false;
|
if (!BuildVGameExeFsDir()) return false;
|
||||||
} else if ((vdir->flags & VDIR_ROMFS) && (offset_romfs != vdir->offset)) {
|
} else if ((vdir->flags & VFLAG_ROMFS) && (offset_romfs != vdir->offset)) {
|
||||||
// validate romFS magic
|
// validate romFS magic
|
||||||
u8 magic[] = { ROMFS_MAGIC };
|
u8 magic[] = { ROMFS_MAGIC };
|
||||||
u8 header[sizeof(magic)];
|
u8 header[sizeof(magic)];
|
||||||
@ -424,12 +416,12 @@ bool OpenVGameDir(VirtualDir* vdir, VirtualFile* ventry) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// for romfs dir: switch to lv3 dir object
|
// for romfs dir: switch to lv3 dir object
|
||||||
if (vdir->flags & VDIR_ROMFS) {
|
if (vdir->flags & VFLAG_ROMFS) {
|
||||||
vdir->index = -1;
|
vdir->index = -1;
|
||||||
vdir->offset = 0;
|
vdir->offset = 0;
|
||||||
vdir->size = 0;
|
vdir->size = 0;
|
||||||
vdir->flags &= ~VDIR_ROMFS;
|
vdir->flags &= ~VFLAG_ROMFS;
|
||||||
vdir->flags |= VDIR_LV3;
|
vdir->flags |= VFLAG_LV3;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true; // error (should not happen)
|
return true; // error (should not happen)
|
||||||
@ -509,19 +501,19 @@ bool ReadVGameDir(VirtualFile* vfile, VirtualDir* vdir) {
|
|||||||
VirtualFile* templates;
|
VirtualFile* templates;
|
||||||
int n = 0;
|
int n = 0;
|
||||||
|
|
||||||
if (vdir->flags & VDIR_CIA) {
|
if (vdir->flags & VFLAG_CIA) {
|
||||||
templates = templates_cia;
|
templates = templates_cia;
|
||||||
n = n_templates_cia;
|
n = n_templates_cia;
|
||||||
} else if (vdir->flags & VDIR_NCSD) {
|
} else if (vdir->flags & VFLAG_NCSD) {
|
||||||
templates = templates_ncsd;
|
templates = templates_ncsd;
|
||||||
n = n_templates_ncsd;
|
n = n_templates_ncsd;
|
||||||
} else if (vdir->flags & VDIR_NCCH) {
|
} else if (vdir->flags & VFLAG_NCCH) {
|
||||||
templates = templates_ncch;
|
templates = templates_ncch;
|
||||||
n = n_templates_ncch;
|
n = n_templates_ncch;
|
||||||
} else if (vdir->flags & VDIR_EXEFS) {
|
} else if (vdir->flags & VFLAG_EXEFS) {
|
||||||
templates = templates_exefs;
|
templates = templates_exefs;
|
||||||
n = n_templates_exefs;
|
n = n_templates_exefs;
|
||||||
} else if (vdir->flags & VDIR_LV3) {
|
} else if (vdir->flags & VFLAG_LV3) {
|
||||||
return ReadVGameDirLv3(vfile, vdir);
|
return ReadVGameDirLv3(vfile, vdir);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -558,11 +550,9 @@ int ReadVGameFile(const VirtualFile* vfile, u8* buffer, u32 offset, u32 count) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GetVGameFilename(char* name, const VirtualFile* vfile, u32 n_chars) {
|
bool GetVGameLv3Filename(char* name, const VirtualFile* vfile, u32 n_chars) {
|
||||||
if (!(vfile->flags & VFLAG_LV3)) {
|
if (!(vfile->flags & VFLAG_LV3))
|
||||||
snprintf(name, n_chars, "%s", vfile->name);
|
return false;
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
u16* wname = NULL;
|
u16* wname = NULL;
|
||||||
u32 name_len = 0;
|
u32 name_len = 0;
|
||||||
@ -585,8 +575,8 @@ bool GetVGameFilename(char* name, const VirtualFile* vfile, u32 n_chars) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MatchVGameFilename(const char* name, const VirtualFile* vfile, u32 n_chars) {
|
bool MatchVGameLv3Filename(const char* name, const VirtualFile* vfile, u32 n_chars) {
|
||||||
char vg_name[256];
|
char lv3_name[256];
|
||||||
if (!GetVGameFilename(vg_name, vfile, 256)) return false;
|
if (!GetVGameLv3Filename(lv3_name, vfile, 256)) return false;
|
||||||
return (strncasecmp(name, vg_name, n_chars) == 0);
|
return (strncasecmp(name, lv3_name, n_chars) == 0);
|
||||||
}
|
}
|
||||||
|
@ -12,5 +12,5 @@ bool ReadVGameDir(VirtualFile* vfile, VirtualDir* vdir);
|
|||||||
int ReadVGameFile(const VirtualFile* vfile, u8* buffer, u32 offset, u32 count);
|
int ReadVGameFile(const VirtualFile* vfile, u8* buffer, u32 offset, u32 count);
|
||||||
// int WriteVGameFile(const VirtualFile* vfile, const u8* buffer, u32 offset, u32 count); // writing is not enabled
|
// int WriteVGameFile(const VirtualFile* vfile, const u8* buffer, u32 offset, u32 count); // writing is not enabled
|
||||||
|
|
||||||
bool GetVGameFilename(char* name, const VirtualFile* vfile, u32 n_chars);
|
bool GetVGameLv3Filename(char* name, const VirtualFile* vfile, u32 n_chars);
|
||||||
bool MatchVGameFilename(const char* name, const VirtualFile* vfile, u32 n_chars);
|
bool MatchVGameLv3Filename(const char* name, const VirtualFile* vfile, u32 n_chars);
|
||||||
|
@ -90,9 +90,8 @@ bool GetVirtualFile(VirtualFile* vfile, const char* path) {
|
|||||||
for (name = strtok(lpath + 3, "/"); name && vdir.virtual_src; name = strtok(NULL, "/")) {
|
for (name = strtok(lpath + 3, "/"); name && vdir.virtual_src; name = strtok(NULL, "/")) {
|
||||||
while (true) {
|
while (true) {
|
||||||
if (!ReadVirtualDir(vfile, &vdir)) return false;
|
if (!ReadVirtualDir(vfile, &vdir)) return false;
|
||||||
if ((virtual_src != VRT_GAME) && (strncasecmp(name, vfile->name, 32) == 0))
|
if ((!(vfile->flags & VFLAG_LV3) && (strncasecmp(name, vfile->name, 32) == 0)) ||
|
||||||
break; // entry found
|
((vfile->flags & VFLAG_LV3) && MatchVGameLv3Filename(name, vfile, 256)))
|
||||||
if ((virtual_src == VRT_GAME) && MatchVGameFilename(name, vfile, 256))
|
|
||||||
break; // entry found
|
break; // entry found
|
||||||
}
|
}
|
||||||
if (!OpenVirtualDir(&vdir, vfile))
|
if (!OpenVirtualDir(&vdir, vfile))
|
||||||
@ -137,8 +136,8 @@ bool GetVirtualDirContents(DirStruct* contents, char* fpath, int fnsize, const c
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool GetVirtualFilename(char* name, const VirtualFile* vfile, u32 n_chars) {
|
bool GetVirtualFilename(char* name, const VirtualFile* vfile, u32 n_chars) {
|
||||||
if (!(vfile->flags & VRT_GAME)) strncpy(name, vfile->name, n_chars);
|
if (!(vfile->flags & VFLAG_LV3)) strncpy(name, vfile->name, n_chars);
|
||||||
else if (!GetVGameFilename(name, vfile, 256)) return false;
|
else if (!GetVGameLv3Filename(name, vfile, 256)) return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,15 +12,16 @@
|
|||||||
|
|
||||||
#define VRT_SOURCE (VRT_SYSNAND|VRT_EMUNAND|VRT_IMGNAND|VRT_MEMORY|VRT_GAME)
|
#define VRT_SOURCE (VRT_SYSNAND|VRT_EMUNAND|VRT_IMGNAND|VRT_MEMORY|VRT_GAME)
|
||||||
|
|
||||||
#define VFLAG_A9LH_AREA (1<<20)
|
#define VFLAG_DIR (1<<16)
|
||||||
#define VFLAG_DIR (1<<21)
|
#define VFLAG_ROOT (1<<17)
|
||||||
#define VFLAG_ROOT (1<<22)
|
#define VFLAG_A9LH_AREA (1<<18)
|
||||||
|
#define VFLAG_LV3 (1<<19)
|
||||||
|
|
||||||
// virtual file flag (subject to change):
|
// virtual file flag (subject to change):
|
||||||
// bits 0...9 : reserved for NAND virtual sources and info
|
// bits 0...9 : reserved for NAND virtual sources and info
|
||||||
// bits 10...15: reserved for other virtual sources
|
// bits 10...15: reserved for other virtual sources
|
||||||
// bits 16...19: reserved for external flags
|
// bits 16...23: reserved for external flags
|
||||||
// bits 20...31: reserved for internal flags (different per source)
|
// bits 24...31: reserved for internal flags (different per source)
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char name[32];
|
char name[32];
|
||||||
u64 offset; // must be a multiple of 0x200 (for NAND access)
|
u64 offset; // must be a multiple of 0x200 (for NAND access)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user