mirror of
https://github.com/modmii/YAWM-ModMii-Edition.git
synced 2025-02-05 00:06:26 +01:00
shared content & cIOS info functions go in title.c
This commit is contained in:
parent
3e8fb363e4
commit
32edea17fe
86
source/sys.c
86
source/sys.c
@ -163,6 +163,8 @@ void Sys_Shutdown(void)
|
||||
STM_SetLedMode is causing a crash, and I don't even like the concept of shutting down to WiiConnect24 standby anyways,
|
||||
so let's just remove this overall
|
||||
|
||||
Optimally we add a WII_Shutdown to wiilaunch.c in libogc to load system menu to shutdown. That would be cool.
|
||||
|
||||
- thepikachugamer
|
||||
*/
|
||||
if (CONF_GetShutdownMode() == CONF_SHUTDOWN_IDLE)
|
||||
@ -211,90 +213,6 @@ s32 Sys_GetCerts(signed_blob **certs, u32 *len)
|
||||
return ret;
|
||||
}
|
||||
|
||||
s32 Sys_GetSharedContents(SharedContent** out, u32* count)
|
||||
{
|
||||
if (!out || !count) return false;
|
||||
|
||||
u32 size;
|
||||
SharedContent* buf = (SharedContent*)NANDLoadFile("/shared1/content.map", &size);
|
||||
|
||||
if (!buf)
|
||||
return (s32)size;
|
||||
|
||||
else if (size % sizeof(SharedContent) != 0) {
|
||||
free(buf);
|
||||
return -996;
|
||||
}
|
||||
|
||||
*out = buf;
|
||||
*count = size / sizeof(SharedContent);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool Sys_SharedContentPresent(tmd_content* content, SharedContent shared[], u32 count)
|
||||
{
|
||||
if (!shared || !content || !count)
|
||||
return false;
|
||||
|
||||
if (!(content->type & 0x8000))
|
||||
return false;
|
||||
|
||||
for (SharedContent* s_content = shared; s_content < shared + count; s_content++)
|
||||
{
|
||||
if (memcmp(s_content->hash, content->hash, sizeof(sha1)) == 0)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Sys_GetcIOSInfo(int IOS, cIOSInfo* out)
|
||||
{
|
||||
u64 titleID = 0x0000000100000000ULL | IOS;
|
||||
ATTRIBUTE_ALIGN(0x20) char path[ISFS_MAXPATH];
|
||||
u32 size;
|
||||
cIOSInfo* buf = NULL;
|
||||
|
||||
u32 view_size = 0;
|
||||
if (ES_GetTMDViewSize(titleID, &view_size) < 0)
|
||||
return false;
|
||||
|
||||
tmd_view* view = memalign32(view_size);
|
||||
if (!view)
|
||||
return false;
|
||||
|
||||
if (ES_GetTMDView(titleID, (u8*)view, view_size) < 0)
|
||||
goto fail;
|
||||
|
||||
tmd_view_content* content0 = NULL;
|
||||
|
||||
for (tmd_view_content* con = view->contents; con < view->contents + view->num_contents; con++)
|
||||
{
|
||||
if (con->index == 0)
|
||||
content0 = con;
|
||||
}
|
||||
|
||||
if (!content0)
|
||||
goto fail;
|
||||
|
||||
sprintf(path, "/title/00000001/%08x/content/%08x.app", IOS, content0->cid);
|
||||
buf = (cIOSInfo*)NANDLoadFile(path, &size);
|
||||
|
||||
if (!buf || size != 0x40 || buf->hdr_magic != CIOS_INFO_MAGIC || buf->hdr_version != CIOS_INFO_VERSION)
|
||||
goto fail;
|
||||
|
||||
*out = *buf;
|
||||
free(view);
|
||||
free(buf);
|
||||
return true;
|
||||
|
||||
fail:
|
||||
free(view);
|
||||
free(buf);
|
||||
return false;
|
||||
}
|
||||
|
||||
void SetPRButtons(bool enabled)
|
||||
{
|
||||
gDisablePRButtons = !enabled;
|
||||
|
31
source/sys.h
31
source/sys.h
@ -1,34 +1,6 @@
|
||||
#ifndef _SYS_H_
|
||||
#define _SYS_H_
|
||||
|
||||
/* /shared1/content.map entry */
|
||||
typedef struct
|
||||
{
|
||||
char filename[8];
|
||||
sha1 hash;
|
||||
} ATTRIBUTE_PACKED SharedContent;
|
||||
|
||||
/* "cIOS build tag" */
|
||||
enum
|
||||
{
|
||||
CIOS_INFO_MAGIC = 0x1EE7C105,
|
||||
CIOS_INFO_VERSION = 1
|
||||
};
|
||||
|
||||
typedef struct
|
||||
{
|
||||
u32 hdr_magic; // 0x1EE7C105
|
||||
u32 hdr_version; // 1
|
||||
u32 cios_version; // Eg. 11
|
||||
u32 ios_base; // Eg. 60
|
||||
|
||||
char name[16];
|
||||
char cios_version_str[16];
|
||||
|
||||
char _padding[16];
|
||||
} cIOSInfo;
|
||||
// _Static_assert(sizeof(cIOSInfo) == 0x40, "Incorrect cIOSInfo struct size, do i really need to pack this..?");
|
||||
|
||||
#define IS_WIIU (*(vu16*)0xCD8005A0 == 0xCAFE)
|
||||
|
||||
extern u32 boot2version;
|
||||
@ -42,9 +14,6 @@ void Sys_Init(void);
|
||||
void Sys_Reboot(void);
|
||||
void Sys_Shutdown(void);
|
||||
s32 Sys_GetCerts(signed_blob **, u32 *);
|
||||
bool Sys_GetcIOSInfo(int IOS, cIOSInfo*);
|
||||
s32 Sys_GetSharedContents(SharedContent** out, u32* count);
|
||||
bool Sys_SharedContentPresent(tmd_content* content, SharedContent shared[], u32 count);
|
||||
void SetPRButtons(bool enabled);
|
||||
|
||||
#endif
|
||||
|
120
source/title.c
120
source/title.c
@ -5,6 +5,7 @@
|
||||
#include <ogcsys.h>
|
||||
#include <ogc/es.h>
|
||||
|
||||
#include "title.h"
|
||||
#include "sha1.h"
|
||||
#include "aes.h"
|
||||
#include "utils.h"
|
||||
@ -319,6 +320,125 @@ out:
|
||||
return ret;
|
||||
}
|
||||
|
||||
s32 Title_GetSharedContents(SharedContent** out, u32* count)
|
||||
{
|
||||
if (!out || !count) return false;
|
||||
|
||||
u32 size;
|
||||
SharedContent* buf = (SharedContent*)NANDLoadFile("/shared1/content.map", &size);
|
||||
|
||||
if (!buf)
|
||||
return (s32)size;
|
||||
|
||||
else if (size % sizeof(SharedContent) != 0) {
|
||||
free(buf);
|
||||
return -996;
|
||||
}
|
||||
|
||||
*out = buf;
|
||||
*count = size / sizeof(SharedContent);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool Title_SharedContentPresent(tmd_content* content, SharedContent shared[], u32 count)
|
||||
{
|
||||
if (!shared || !content || !count)
|
||||
return false;
|
||||
|
||||
if (!(content->type & 0x8000))
|
||||
return false;
|
||||
|
||||
for (SharedContent* s_content = shared; s_content < shared + count; s_content++)
|
||||
{
|
||||
if (memcmp(s_content->hash, content->hash, sizeof(sha1)) == 0)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Title_GetcIOSInfo(int IOS, cIOSInfo* out)
|
||||
{
|
||||
u64 titleID = 0x0000000100000000ULL | IOS;
|
||||
ATTRIBUTE_ALIGN(0x20) char path[ISFS_MAXPATH];
|
||||
u32 size;
|
||||
cIOSInfo* buf = NULL;
|
||||
|
||||
u32 view_size = 0;
|
||||
if (ES_GetTMDViewSize(titleID, &view_size) < 0)
|
||||
return false;
|
||||
|
||||
tmd_view* view = memalign32(view_size);
|
||||
if (!view)
|
||||
return false;
|
||||
|
||||
if (ES_GetTMDView(titleID, (u8*)view, view_size) < 0)
|
||||
goto fail;
|
||||
|
||||
tmd_view_content* content0 = NULL;
|
||||
|
||||
for (tmd_view_content* con = view->contents; con < view->contents + view->num_contents; con++)
|
||||
{
|
||||
if (con->index == 0)
|
||||
content0 = con;
|
||||
}
|
||||
|
||||
if (!content0)
|
||||
goto fail;
|
||||
|
||||
sprintf(path, "/title/00000001/%08x/content/%08x.app", IOS, content0->cid);
|
||||
buf = (cIOSInfo*)NANDLoadFile(path, &size);
|
||||
|
||||
if (!buf || size != 0x40 || buf->hdr_magic != CIOS_INFO_MAGIC || buf->hdr_version != CIOS_INFO_VERSION)
|
||||
goto fail;
|
||||
|
||||
*out = *buf;
|
||||
free(view);
|
||||
free(buf);
|
||||
return true;
|
||||
|
||||
fail:
|
||||
free(view);
|
||||
free(buf);
|
||||
return false;
|
||||
}
|
||||
|
||||
#if 0
|
||||
void Title_GetFreeSpace(u32* free, s32* user_free)
|
||||
{
|
||||
// Based off Dolphin Emulator's code. Cool stuff
|
||||
static const char* const userDirs[10] = {
|
||||
"/meta", "/ticket",
|
||||
"/title/00010000", "/title/00010001",
|
||||
"/title/00010003", "/title/00010004", "/title/00010005",
|
||||
"/title/00010006", "/title/00010007", "/shared2/title" /* Wtf */
|
||||
};
|
||||
|
||||
u32 stats[8];
|
||||
ISFS_GetStats(stats);
|
||||
u32 cluster_size = stats[0], // Can just hardcode 16384 here but eh
|
||||
free_clusters = stats[1],
|
||||
used_clusters = stats[2];
|
||||
|
||||
*free = free_clusters * cluster_size;
|
||||
|
||||
static const u32 user_blocks_max = 2176, // 1 block = 128KiB (131072 bytes)
|
||||
user_clusters_max = user_blocks_max * 8; // 1 cluster = 16KiB (16384)
|
||||
|
||||
u32 user_clusters_used = 0;
|
||||
for (int i = 0; i < 10; i++) {
|
||||
|
||||
// Clusters Inodes
|
||||
ret = ISFS_GetUsage(userDirs[i], &stats[0], &stats[1]);
|
||||
if (ret == 0)
|
||||
user_clusters_used += stats[0];
|
||||
}
|
||||
|
||||
s32 user_clusters_free = user_clusters_max - user_clusters_used;
|
||||
*user_free = user_clusters_free * cluster_size;
|
||||
}
|
||||
#endif
|
||||
__attribute__((aligned(0x10)))
|
||||
aeskey WiiCommonKey, vWiiCommonKey;
|
||||
|
||||
|
@ -6,6 +6,34 @@
|
||||
/* Constants */
|
||||
#define BLOCK_SIZE 0x4000
|
||||
|
||||
/* /shared1/content.map entry */
|
||||
typedef struct
|
||||
{
|
||||
char filename[8];
|
||||
sha1 hash;
|
||||
} ATTRIBUTE_PACKED SharedContent;
|
||||
|
||||
/* "cIOS build tag" */
|
||||
enum
|
||||
{
|
||||
CIOS_INFO_MAGIC = 0x1EE7C105,
|
||||
CIOS_INFO_VERSION = 1
|
||||
};
|
||||
|
||||
typedef struct
|
||||
{
|
||||
u32 hdr_magic; // 0x1EE7C105
|
||||
u32 hdr_version; // 1
|
||||
u32 cios_version; // Eg. 11
|
||||
u32 ios_base; // Eg. 60
|
||||
|
||||
char name[16];
|
||||
char cios_version_str[16];
|
||||
|
||||
char _padding[16];
|
||||
} cIOSInfo;
|
||||
_Static_assert(sizeof(cIOSInfo) == 0x40, "cIOSInfo struct size wrong");
|
||||
|
||||
/* Variables */
|
||||
extern aeskey WiiCommonKey, vWiiCommonKey;
|
||||
|
||||
@ -20,6 +48,9 @@ s32 Title_GetVersion(u64, u16 *);
|
||||
s32 Title_GetSysVersion(u64, u64 *);
|
||||
s32 Title_GetSize(u64, u32 *);
|
||||
s32 Title_GetIOSVersions(u8 **, u32 *);
|
||||
s32 Title_GetSharedContents(SharedContent** out, u32* count);
|
||||
bool Title_SharedContentPresent(tmd_content* content, SharedContent shared[], u32 count);
|
||||
bool Title_GetcIOSInfo(int IOS, cIOSInfo*);
|
||||
void Title_SetupCommonKeys(void);
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user