clang-format

This commit is contained in:
Maschell 2022-02-08 14:44:53 +01:00
parent 8e2a431827
commit 4993b321ce
26 changed files with 1824 additions and 1855 deletions

View File

@ -1,8 +1,8 @@
#include "cafe/coreinit.h"
#include "hbl.h"
#include <cstdint>
#include <cstddef>
#include <cstdint>
int (*OSDynLoad_Acquire)(const char *name, uint32_t *handle);
int (*OSDynLoad_FindExport)(uint32_t handle, bool isData, const char *name, void *ptr);
@ -117,132 +117,132 @@ uint32_t (*MEMGetAllocatableSizeForExpHeapEx)(void *handle, int alignment);
void *(**pMEMAllocFromDefaultHeap)(uint32_t size);
void *(**pMEMAllocFromDefaultHeapEx)(uint32_t size, int alignment);
void (**pMEMFreeToDefaultHeap)(void *ptr);
void (**pMEMFreeToDefaultHeap)(void *ptr);
OSDynLoad_RPLInfo **pMainRPL;
OSDynLoad_RPLInfo **pFirstRPL;
OSThread **pThreadList;
void coreinitInitialize() {
*(uint32_t *)&OSDynLoad_Acquire = OS_SPECIFICS->OSDynLoad_Acquire;
*(uint32_t *)&OSDynLoad_FindExport = OS_SPECIFICS->OSDynLoad_FindExport;
*(uint32_t *) &OSDynLoad_Acquire = OS_SPECIFICS->OSDynLoad_Acquire;
*(uint32_t *) &OSDynLoad_FindExport = OS_SPECIFICS->OSDynLoad_FindExport;
uint32_t handle;
OSDynLoad_Acquire("coreinit.rpl", &handle);
uint32_t handle;
OSDynLoad_Acquire("coreinit.rpl", &handle);
OSDynLoad_FindExport(handle, false, "OSDynLoad_GetModuleName", &OSDynLoad_GetModuleName);
OSDynLoad_FindExport(handle, true, "OSDynLoad_gLoaderLock", &OSDynLoad_gLoaderLock);
OSDynLoad_FindExport(handle, false, "OSDynLoad_GetModuleName", &OSDynLoad_GetModuleName);
OSDynLoad_FindExport(handle, true, "OSDynLoad_gLoaderLock", &OSDynLoad_gLoaderLock);
OSDynLoad_FindExport(handle, false, "OSIsDebuggerInitialized", &OSIsDebuggerInitialized);
OSDynLoad_FindExport(handle, false, "OSIsDebuggerInitialized", &OSIsDebuggerInitialized);
OSDynLoad_FindExport(handle, false, "exit", &exit);
OSDynLoad_FindExport(handle, false, "_Exit", &_Exit);
OSDynLoad_FindExport(handle, false, "exit", &exit);
OSDynLoad_FindExport(handle, false, "_Exit", &_Exit);
OSDynLoad_FindExport(handle, false, "OSFatal", &OSFatal);
OSDynLoad_FindExport(handle, false, "OSFatal", &OSFatal);
OSDynLoad_FindExport(handle, false, "OSGetSymbolName", &OSGetSymbolName);
OSDynLoad_FindExport(handle, false, "DisassemblePPCRange", &DisassemblePPCRange);
OSDynLoad_FindExport(handle, false, "DisassemblePPCOpcode", &DisassemblePPCOpcode);
OSDynLoad_FindExport(handle, false, "OSGetSymbolName", &OSGetSymbolName);
OSDynLoad_FindExport(handle, false, "DisassemblePPCRange", &DisassemblePPCRange);
OSDynLoad_FindExport(handle, false, "DisassemblePPCOpcode", &DisassemblePPCOpcode);
OSDynLoad_FindExport(handle, false, "OSSetExceptionCallback", &OSSetExceptionCallback);
OSDynLoad_FindExport(handle, false, "OSSetExceptionCallbackEx", &OSSetExceptionCallbackEx);
OSDynLoad_FindExport(handle, false, "OSLoadContext", &OSLoadContext);
OSDynLoad_FindExport(handle, false, "OSSetExceptionCallback", &OSSetExceptionCallback);
OSDynLoad_FindExport(handle, false, "OSSetExceptionCallbackEx", &OSSetExceptionCallbackEx);
OSDynLoad_FindExport(handle, false, "OSLoadContext", &OSLoadContext);
OSDynLoad_FindExport(handle, false, "OSDisableInterrupts", &OSDisableInterrupts);
OSDynLoad_FindExport(handle, false, "OSRestoreInterrupts", &OSRestoreInterrupts);
OSDynLoad_FindExport(handle, false, "OSDisableInterrupts", &OSDisableInterrupts);
OSDynLoad_FindExport(handle, false, "OSRestoreInterrupts", &OSRestoreInterrupts);
OSDynLoad_FindExport(handle, false, "__OSLockScheduler", &__OSLockScheduler);
OSDynLoad_FindExport(handle, false, "__OSUnlockScheduler", &__OSUnlockScheduler);
OSDynLoad_FindExport(handle, false, "__OSLockScheduler", &__OSLockScheduler);
OSDynLoad_FindExport(handle, false, "__OSUnlockScheduler", &__OSUnlockScheduler);
OSDynLoad_FindExport(handle, false, "OSInitMutex", &OSInitMutex);
OSDynLoad_FindExport(handle, false, "OSLockMutex", &OSLockMutex);
OSDynLoad_FindExport(handle, false, "OSUnlockMutex", &OSUnlockMutex);
OSDynLoad_FindExport(handle, false, "OSInitMutex", &OSInitMutex);
OSDynLoad_FindExport(handle, false, "OSLockMutex", &OSLockMutex);
OSDynLoad_FindExport(handle, false, "OSUnlockMutex", &OSUnlockMutex);
OSDynLoad_FindExport(handle, false, "OSInitMessageQueue", &OSInitMessageQueue);
OSDynLoad_FindExport(handle, false, "OSSendMessage", &OSSendMessage);
OSDynLoad_FindExport(handle, false, "OSReceiveMessage", &OSReceiveMessage);
OSDynLoad_FindExport(handle, false, "OSInitMessageQueue", &OSInitMessageQueue);
OSDynLoad_FindExport(handle, false, "OSSendMessage", &OSSendMessage);
OSDynLoad_FindExport(handle, false, "OSReceiveMessage", &OSReceiveMessage);
OSDynLoad_FindExport(handle, false, "OSCreateAlarm", &OSCreateAlarm);
OSDynLoad_FindExport(handle, false, "OSSetAlarm", &OSSetAlarm);
OSDynLoad_FindExport(handle, false, "OSCancelAlarm", &OSCancelAlarm);
OSDynLoad_FindExport(handle, false, "OSWaitAlarm", &OSWaitAlarm);
OSDynLoad_FindExport(handle, false, "OSCreateAlarm", &OSCreateAlarm);
OSDynLoad_FindExport(handle, false, "OSSetAlarm", &OSSetAlarm);
OSDynLoad_FindExport(handle, false, "OSCancelAlarm", &OSCancelAlarm);
OSDynLoad_FindExport(handle, false, "OSWaitAlarm", &OSWaitAlarm);
OSDynLoad_FindExport(handle, false, "OSGetCurrentThread", &OSGetCurrentThread);
OSDynLoad_FindExport(handle, false, "OSGetDefaultThread", &OSGetDefaultThread);
OSDynLoad_FindExport(handle, false, "OSCreateThread", &OSCreateThread);
OSDynLoad_FindExport(handle, false, "OSResumeThread", &OSResumeThread);
OSDynLoad_FindExport(handle, false, "OSJoinThread", &OSJoinThread);
OSDynLoad_FindExport(handle, false, "OSExitThread", &OSExitThread);
OSDynLoad_FindExport(handle, false, "OSGetThreadName", &OSGetThreadName);
OSDynLoad_FindExport(handle, false, "OSSetThreadName", &OSSetThreadName);
OSDynLoad_FindExport(handle, false, "OSGetThreadAffinity", &OSGetThreadAffinity);
OSDynLoad_FindExport(handle, false, "OSGetThreadPriority", &OSGetThreadPriority);
OSDynLoad_FindExport(handle, false, "OSGetCurrentThread", &OSGetCurrentThread);
OSDynLoad_FindExport(handle, false, "OSGetDefaultThread", &OSGetDefaultThread);
OSDynLoad_FindExport(handle, false, "OSCreateThread", &OSCreateThread);
OSDynLoad_FindExport(handle, false, "OSResumeThread", &OSResumeThread);
OSDynLoad_FindExport(handle, false, "OSJoinThread", &OSJoinThread);
OSDynLoad_FindExport(handle, false, "OSExitThread", &OSExitThread);
OSDynLoad_FindExport(handle, false, "OSGetThreadName", &OSGetThreadName);
OSDynLoad_FindExport(handle, false, "OSSetThreadName", &OSSetThreadName);
OSDynLoad_FindExport(handle, false, "OSGetThreadAffinity", &OSGetThreadAffinity);
OSDynLoad_FindExport(handle, false, "OSGetThreadPriority", &OSGetThreadPriority);
OSDynLoad_FindExport(handle, false, "OSGetSystemInfo", &OSGetSystemInfo);
OSDynLoad_FindExport(handle, false, "OSSleepTicks", &OSSleepTicks);
OSDynLoad_FindExport(handle, false, "OSGetSystemInfo", &OSGetSystemInfo);
OSDynLoad_FindExport(handle, false, "OSSleepTicks", &OSSleepTicks);
OSDynLoad_FindExport(handle, false, "OSGetTitleID", &OSGetTitleID);
OSDynLoad_FindExport(handle, false, "OSGetTitleID", &OSGetTitleID);
OSDynLoad_FindExport(handle, false, "OSGetMemBound", &OSGetMemBound);
OSDynLoad_FindExport(handle, false, "OSEffectiveToPhysical", &OSEffectiveToPhysical);
OSDynLoad_FindExport(handle, false, "OSGetMemBound", &OSGetMemBound);
OSDynLoad_FindExport(handle, false, "OSEffectiveToPhysical", &OSEffectiveToPhysical);
OSDynLoad_FindExport(handle, false, "OSScreenInit", &OSScreenInit);
OSDynLoad_FindExport(handle, false, "OSScreenGetBufferSizeEx", &OSScreenGetBufferSizeEx);
OSDynLoad_FindExport(handle, false, "OSScreenSetBufferEx", &OSScreenSetBufferEx);
OSDynLoad_FindExport(handle, false, "OSScreenEnableEx", &OSScreenEnableEx);
OSDynLoad_FindExport(handle, false, "OSScreenClearBufferEx", &OSScreenClearBufferEx);
OSDynLoad_FindExport(handle, false, "OSScreenFlipBuffersEx", &OSScreenFlipBuffersEx);
OSDynLoad_FindExport(handle, false, "OSScreenPutPixelEx", &OSScreenPutPixelEx);
OSDynLoad_FindExport(handle, false, "OSScreenPutFontEx", &OSScreenPutFontEx);
OSDynLoad_FindExport(handle, false, "OSScreenInit", &OSScreenInit);
OSDynLoad_FindExport(handle, false, "OSScreenGetBufferSizeEx", &OSScreenGetBufferSizeEx);
OSDynLoad_FindExport(handle, false, "OSScreenSetBufferEx", &OSScreenSetBufferEx);
OSDynLoad_FindExport(handle, false, "OSScreenEnableEx", &OSScreenEnableEx);
OSDynLoad_FindExport(handle, false, "OSScreenClearBufferEx", &OSScreenClearBufferEx);
OSDynLoad_FindExport(handle, false, "OSScreenFlipBuffersEx", &OSScreenFlipBuffersEx);
OSDynLoad_FindExport(handle, false, "OSScreenPutPixelEx", &OSScreenPutPixelEx);
OSDynLoad_FindExport(handle, false, "OSScreenPutFontEx", &OSScreenPutFontEx);
OSDynLoad_FindExport(handle, false, "DCFlushRange", &DCFlushRange);
OSDynLoad_FindExport(handle, false, "DCInvalidateRange", &DCInvalidateRange);
OSDynLoad_FindExport(handle, false, "ICInvalidateRange", &ICInvalidateRange);
OSDynLoad_FindExport(handle, false, "IOS_Open", &IOS_Open);
OSDynLoad_FindExport(handle, false, "IOS_Ioctl", &IOS_Ioctl);
OSDynLoad_FindExport(handle, false, "IOS_Close", &IOS_Close);
OSDynLoad_FindExport(handle, false, "DCFlushRange", &DCFlushRange);
OSDynLoad_FindExport(handle, false, "DCInvalidateRange", &DCInvalidateRange);
OSDynLoad_FindExport(handle, false, "ICInvalidateRange", &ICInvalidateRange);
OSDynLoad_FindExport(handle, false, "IOS_Open", &IOS_Open);
OSDynLoad_FindExport(handle, false, "IOS_Ioctl", &IOS_Ioctl);
OSDynLoad_FindExport(handle, false, "IOS_Close", &IOS_Close);
OSDynLoad_FindExport(handle, false, "FSInit", &FSInit);
OSDynLoad_FindExport(handle, false, "FSAddClient", &FSAddClient);
OSDynLoad_FindExport(handle, false, "FSInitCmdBlock", &FSInitCmdBlock);
OSDynLoad_FindExport(handle, false, "FSGetMountSource", &FSGetMountSource);
OSDynLoad_FindExport(handle, false, "FSMount", &FSMount);
OSDynLoad_FindExport(handle, false, "FSMakeDir", &FSMakeDir);
OSDynLoad_FindExport(handle, false, "FSChangeDir", &FSChangeDir);
OSDynLoad_FindExport(handle, false, "FSGetCwd", &FSGetCwd);
OSDynLoad_FindExport(handle, false, "FSOpenDir", &FSOpenDir);
OSDynLoad_FindExport(handle, false, "FSReadDir", &FSReadDir);
OSDynLoad_FindExport(handle, false, "FSCloseDir", &FSCloseDir);
OSDynLoad_FindExport(handle, false, "FSOpenFile", &FSOpenFile);
OSDynLoad_FindExport(handle, false, "FSGetStatFile", &FSGetStatFile);
OSDynLoad_FindExport(handle, false, "FSReadFile", &FSReadFile);
OSDynLoad_FindExport(handle, false, "FSWriteFile", &FSWriteFile);
OSDynLoad_FindExport(handle, false, "FSCloseFile", &FSCloseFile);
OSDynLoad_FindExport(handle, false, "FSGetStat", &FSGetStat);
OSDynLoad_FindExport(handle, false, "FSRename", &FSRename);
OSDynLoad_FindExport(handle, false, "FSRemove", &FSRemove);
OSDynLoad_FindExport(handle, false, "FSDelClient", &FSDelClient);
OSDynLoad_FindExport(handle, false, "FSShutdown", &FSShutdown);
OSDynLoad_FindExport(handle, false, "FSInit", &FSInit);
OSDynLoad_FindExport(handle, false, "FSAddClient", &FSAddClient);
OSDynLoad_FindExport(handle, false, "FSInitCmdBlock", &FSInitCmdBlock);
OSDynLoad_FindExport(handle, false, "FSGetMountSource", &FSGetMountSource);
OSDynLoad_FindExport(handle, false, "FSMount", &FSMount);
OSDynLoad_FindExport(handle, false, "FSMakeDir", &FSMakeDir);
OSDynLoad_FindExport(handle, false, "FSChangeDir", &FSChangeDir);
OSDynLoad_FindExport(handle, false, "FSGetCwd", &FSGetCwd);
OSDynLoad_FindExport(handle, false, "FSOpenDir", &FSOpenDir);
OSDynLoad_FindExport(handle, false, "FSReadDir", &FSReadDir);
OSDynLoad_FindExport(handle, false, "FSCloseDir", &FSCloseDir);
OSDynLoad_FindExport(handle, false, "FSOpenFile", &FSOpenFile);
OSDynLoad_FindExport(handle, false, "FSGetStatFile", &FSGetStatFile);
OSDynLoad_FindExport(handle, false, "FSReadFile", &FSReadFile);
OSDynLoad_FindExport(handle, false, "FSWriteFile", &FSWriteFile);
OSDynLoad_FindExport(handle, false, "FSCloseFile", &FSCloseFile);
OSDynLoad_FindExport(handle, false, "FSGetStat", &FSGetStat);
OSDynLoad_FindExport(handle, false, "FSRename", &FSRename);
OSDynLoad_FindExport(handle, false, "FSRemove", &FSRemove);
OSDynLoad_FindExport(handle, false, "FSDelClient", &FSDelClient);
OSDynLoad_FindExport(handle, false, "FSShutdown", &FSShutdown);
OSDynLoad_FindExport(handle, false, "MCP_Open", &MCP_Open);
OSDynLoad_FindExport(handle, false, "MCP_GetDeviceId", &MCP_GetDeviceId);
OSDynLoad_FindExport(handle, false, "MCP_TitleList", &MCP_TitleList);
OSDynLoad_FindExport(handle, false, "MCP_TitleListByAppType", &MCP_TitleListByAppType);
OSDynLoad_FindExport(handle, false, "MCP_TitleListByDevice", &MCP_TitleListByDevice);
OSDynLoad_FindExport(handle, false, "MCP_Close", &MCP_Close);
OSDynLoad_FindExport(handle, false, "MCP_Open", &MCP_Open);
OSDynLoad_FindExport(handle, false, "MCP_GetDeviceId", &MCP_GetDeviceId);
OSDynLoad_FindExport(handle, false, "MCP_TitleList", &MCP_TitleList);
OSDynLoad_FindExport(handle, false, "MCP_TitleListByAppType", &MCP_TitleListByAppType);
OSDynLoad_FindExport(handle, false, "MCP_TitleListByDevice", &MCP_TitleListByDevice);
OSDynLoad_FindExport(handle, false, "MCP_Close", &MCP_Close);
OSDynLoad_FindExport(handle, false, "__KernelGetInfo", &__KernelGetInfo);
OSDynLoad_FindExport(handle, false, "__KernelGetInfo", &__KernelGetInfo);
OSDynLoad_FindExport(handle, false, "__os_snprintf", &snprintf);
OSDynLoad_FindExport(handle, false, "__os_snprintf", &snprintf);
OSDynLoad_FindExport(handle, false, "MEMGetBaseHeapHandle", &MEMGetBaseHeapHandle);
OSDynLoad_FindExport(handle, false, "MEMGetAllocatableSizeForExpHeapEx", &MEMGetAllocatableSizeForExpHeapEx);
OSDynLoad_FindExport(handle, false, "MEMGetBaseHeapHandle", &MEMGetBaseHeapHandle);
OSDynLoad_FindExport(handle, false, "MEMGetAllocatableSizeForExpHeapEx", &MEMGetAllocatableSizeForExpHeapEx);
OSDynLoad_FindExport(handle, true, "MEMAllocFromDefaultHeap", &pMEMAllocFromDefaultHeap);
OSDynLoad_FindExport(handle, true, "MEMAllocFromDefaultHeapEx", &pMEMAllocFromDefaultHeapEx);
OSDynLoad_FindExport(handle, true, "MEMFreeToDefaultHeap", &pMEMFreeToDefaultHeap);
OSDynLoad_FindExport(handle, true, "MEMAllocFromDefaultHeap", &pMEMAllocFromDefaultHeap);
OSDynLoad_FindExport(handle, true, "MEMAllocFromDefaultHeapEx", &pMEMAllocFromDefaultHeapEx);
OSDynLoad_FindExport(handle, true, "MEMFreeToDefaultHeap", &pMEMFreeToDefaultHeap);
pMainRPL = (OSDynLoad_RPLInfo **)0x10081014;
pFirstRPL = (OSDynLoad_RPLInfo **)0x10081018;
pThreadList = (OSThread **)0x100567F8;
pMainRPL = (OSDynLoad_RPLInfo **) 0x10081014;
pFirstRPL = (OSDynLoad_RPLInfo **) 0x10081018;
pThreadList = (OSThread **) 0x100567F8;
}

View File

@ -1,101 +1,101 @@
#pragma once
#include <cstdint>
#include <cstddef>
#include <cstdint>
// Timers
#define OSTimerClockSpeed ((OSGetSystemInfo()->busClockSpeed) / 4)
#define OSTimerClockSpeed ((OSGetSystemInfo()->busClockSpeed) / 4)
#define OSSecondsToTicks(val) ((uint64_t)(val) * (uint64_t)OSTimerClockSpeed)
#define OSMillisecondsToTicks(val) (((uint64_t)(val) * (uint64_t)OSTimerClockSpeed) / 1000ull)
#define OSSecondsToTicks(val) ((uint64_t) (val) * (uint64_t) OSTimerClockSpeed)
#define OSMillisecondsToTicks(val) (((uint64_t) (val) * (uint64_t) OSTimerClockSpeed) / 1000ull)
#define OSTicksToSeconds(val) ((uint64_t)(val) / (uint64_t)OSTimerClockSpeed)
#define OSTicksToMilliseconds(val) (((uint64_t)(val) * 1000ull) / (uint64_t)OSTimerClockSpeed)
#define OSTicksToSeconds(val) ((uint64_t) (val) / (uint64_t) OSTimerClockSpeed)
#define OSTicksToMilliseconds(val) (((uint64_t) (val) *1000ull) / (uint64_t) OSTimerClockSpeed)
// Memory
enum OSMemoryType {
MEM1 = 1,
MEM2 = 2
MEM1 = 1,
MEM2 = 2
};
// System
enum KernelInfoType {
TITLE_INFO = 0,
SYSTEM_INFO = 1,
PLATFORM_INFO = 2,
TITLE_INFO = 0,
SYSTEM_INFO = 1,
PLATFORM_INFO = 2,
KERNEL_STATISTICS = 4,
PERFORMANCE_NUMBERS = 5,
KERNEL_STATISTICS = 4,
PERFORMANCE_NUMBERS = 5,
PROCESS_INFO = 8,
PROCESS_INFO = 8,
CRASH_INFO = 11,
APP_CRASH_CONTROL = 12,
COS_REPORT_MASKS = 13,
CRASH_RECOVERY = 14,
CRASH_DETAIL_LEVEL = 15,
CRASH_DUMP_TYPE = 16,
SHUTDOWN_REASON = 17,
WRITE_GATHER_REGS = 18,
PROC_DATA_BOUNDS = 19
CRASH_INFO = 11,
APP_CRASH_CONTROL = 12,
COS_REPORT_MASKS = 13,
CRASH_RECOVERY = 14,
CRASH_DETAIL_LEVEL = 15,
CRASH_DUMP_TYPE = 16,
SHUTDOWN_REASON = 17,
WRITE_GATHER_REGS = 18,
PROC_DATA_BOUNDS = 19
};
struct OSSystemInfo {
uint32_t busClockSpeed;
uint32_t coreClockSpeed;
int64_t baseTime;
char _10[0x10];
uint32_t busClockSpeed;
uint32_t coreClockSpeed;
int64_t baseTime;
char _10[0x10];
};
struct OSTitleInfo {
char _0[0xC];
uint32_t ramStart;
uint32_t ramEnd;
char _14[0x20];
uint32_t systemHeapSize;
char _38[0x40];
uint32_t textStart;
uint32_t _7C;
uint32_t textSize;
uint32_t dataStart;
uint32_t _88;
uint32_t dataSize;
uint32_t loadStart;
uint32_t _94;
uint32_t loadSize;
char _9C[0xC];
char _0[0xC];
uint32_t ramStart;
uint32_t ramEnd;
char _14[0x20];
uint32_t systemHeapSize;
char _38[0x40];
uint32_t textStart;
uint32_t _7C;
uint32_t textSize;
uint32_t dataStart;
uint32_t _88;
uint32_t dataSize;
uint32_t loadStart;
uint32_t _94;
uint32_t loadSize;
char _9C[0xC];
};
struct OSTitleInfoEx {
OSTitleInfo info;
uint64_t osVersionId;
OSTitleInfo info;
uint64_t osVersionId;
};
// OSDynLoad
struct OSDynLoad_NotifyData {
const char *path;
uint32_t textAddr;
uint32_t textOffset;
uint32_t textSize;
uint32_t dataAddr;
uint32_t dataOffset;
uint32_t dataSize;
uint32_t readAddr;
uint32_t readOffset;
uint32_t readSize;
const char *path;
uint32_t textAddr;
uint32_t textOffset;
uint32_t textSize;
uint32_t dataAddr;
uint32_t dataOffset;
uint32_t dataSize;
uint32_t readAddr;
uint32_t readOffset;
uint32_t readSize;
};
struct OSDynLoad_RPLInfo {
uint32_t handle;
uint32_t _4;
const char *name;
char _C[0x1C];
OSDynLoad_NotifyData *notifyData;
void *entryPoint;
char _30[0x24];
OSDynLoad_RPLInfo *next;
char _58[0x3C];
uint32_t handle;
uint32_t _4;
const char *name;
char _C[0x1C];
OSDynLoad_NotifyData *notifyData;
void *entryPoint;
char _30[0x24];
OSDynLoad_RPLInfo *next;
char _58[0x3C];
};
// Thread / mutex / context
@ -104,188 +104,187 @@ struct OSMutex;
struct OSAlarm;
struct OSContext {
uint64_t tag;
uint64_t tag;
uint32_t gpr[32];
uint32_t gpr[32];
uint32_t cr;
uint32_t lr;
uint32_t ctr;
uint32_t xer;
uint32_t cr;
uint32_t lr;
uint32_t ctr;
uint32_t xer;
uint32_t srr0;
uint32_t srr1;
uint32_t srr0;
uint32_t srr1;
uint32_t dsisr;
uint32_t dar;
uint32_t dsisr;
uint32_t dar;
char _A8[0xC];
char _A8[0xC];
uint32_t fpscr;
double fpr[32];
uint32_t fpscr;
double fpr[32];
uint16_t spinLockCount;
uint16_t state;
uint16_t spinLockCount;
uint16_t state;
uint32_t gqr[8];
uint32_t gqr[8];
uint32_t _1DC;
uint32_t _1DC;
double psf[32];
double psf[32];
uint64_t coretime[3];
uint64_t starttime;
uint64_t coretime[3];
uint64_t starttime;
uint32_t error;
uint32_t error;
uint32_t _304;
uint32_t _304;
uint32_t pmc1;
uint32_t pmc2;
uint32_t pmc3;
uint32_t pmc4;
uint32_t mmcr0;
uint32_t mmcr1;
uint32_t pmc1;
uint32_t pmc2;
uint32_t pmc3;
uint32_t pmc4;
uint32_t mmcr0;
uint32_t mmcr1;
};
struct OSThreadQueue {
OSThread *head;
OSThread *tail;
void *parent;
uint32_t _C;
OSThread *head;
OSThread *tail;
void *parent;
uint32_t _C;
};
struct OSThreadLink {
OSThread *next;
OSThread *prev;
OSThread *next;
OSThread *prev;
};
struct OSMutexLink {
OSMutex *next;
OSMutex *prev;
OSMutex *next;
OSMutex *prev;
};
struct OSMutexQueue {
OSMutex *head;
OSMutex *tail;
void *parent;
uint32_t _C;
OSMutex *head;
OSMutex *tail;
void *parent;
uint32_t _C;
};
struct OSMutex {
uint32_t tag;
const char *name;
uint32_t _8;
uint32_t tag;
const char *name;
uint32_t _8;
OSThreadQueue queue;
OSThread *thread;
int count;
OSMutexLink link;
OSThreadQueue queue;
OSThread *thread;
int count;
OSMutexLink link;
};
typedef int (*OSThreadFunc)(int argc, void *argv);
struct OSThread {
OSContext context;
OSContext context;
uint32_t tag;
uint32_t tag;
uint8_t state;
uint8_t attr;
uint16_t id;
uint32_t suspendCounter;
uint8_t state;
uint8_t attr;
uint16_t id;
uint32_t suspendCounter;
int priority;
int basePriority;
int priority;
int basePriority;
int exitValue;
int exitValue;
char _338[0x24];
char _338[0x24];
OSThreadQueue *queue;
OSThreadLink link;
OSThreadQueue *queue;
OSThreadLink link;
OSThreadQueue joinQueue;
OSThreadQueue joinQueue;
OSMutex *mutex;
OSMutexQueue mutexQueue;
OSMutex *mutex;
OSMutexQueue mutexQueue;
OSThreadLink activeLink;
OSThreadLink activeLink;
void *stackBase;
void *stackEnd;
void *stackBase;
void *stackEnd;
OSThreadFunc entryPoint;
OSThreadFunc entryPoint;
char _3A0[0x57C - 0x3A0];
char _3A0[0x57C - 0x3A0];
void *specific[0x10];
void *specific[0x10];
int type;
int type;
const char *name;
char _5C4[0x6A0 - 0x5C4];
const char *name;
char _5C4[0x6A0 - 0x5C4];
};
// Messages
enum OSMessageFlags {
OS_MESSAGE_FLAGS_NONE = 0,
OS_MESSAGE_FLAGS_BLOCKING = 1
OS_MESSAGE_FLAGS_NONE = 0,
OS_MESSAGE_FLAGS_BLOCKING = 1
};
struct OSMessage {
uint32_t message;
uint32_t args[3];
uint32_t message;
uint32_t args[3];
};
struct OSMessageQueue {
uint32_t tag;
const char *name;
uint32_t _8;
OSThreadQueue sendQueue;
OSThreadQueue recvQueue;
OSMessage *messages;
uint32_t size;
uint32_t first;
uint32_t used;
uint32_t tag;
const char *name;
uint32_t _8;
OSThreadQueue sendQueue;
OSThreadQueue recvQueue;
OSMessage *messages;
uint32_t size;
uint32_t first;
uint32_t used;
};
// Alarms
struct OSAlarmQueue {
uint32_t tag;
const char *name;
uint32_t _8;
uint32_t tag;
const char *name;
uint32_t _8;
OSThreadQueue threadQueue;
OSAlarm *head;
OSAlarm *tail;
OSThreadQueue threadQueue;
OSAlarm *head;
OSAlarm *tail;
};
struct OSAlarmLink {
OSAlarm *prev;
OSAlarm *next;
OSAlarm *prev;
OSAlarm *next;
};
typedef void (*OSAlarmCallback)(OSAlarm *alarm, OSContext *context);
struct OSAlarm {
uint32_t tag;
const char *name;
uint32_t _8;
OSAlarmCallback callback;
uint32_t group;
uint32_t _14;
uint64_t nextFire;
OSAlarmLink link;
uint64_t period;
uint64_t start;
void *userData;
uint32_t state;
OSThreadQueue threadQueue;
OSAlarmQueue *alarmQueue;
OSContext *context;
uint32_t tag;
const char *name;
uint32_t _8;
OSAlarmCallback callback;
uint32_t group;
uint32_t _14;
uint64_t nextFire;
OSAlarmLink link;
uint64_t period;
uint64_t start;
void *userData;
uint32_t state;
OSThreadQueue threadQueue;
OSAlarmQueue *alarmQueue;
OSContext *context;
};
// PPC disassembly
@ -293,94 +292,94 @@ typedef void (*DisassemblyPrintFn)(const char *fmt, ...);
typedef uint32_t (*DisassemblyFindSymbolFn)(uint32_t addr, char *buffer, size_t bufsize);
enum DisassemblyFlags {
DISASSEMBLY_FLAGS_NONE = 0,
DISASSEMBLY_FLAGS_SIMPLIFY = 1,
DISASSEMBLY_FLAGS_SPACE = 0x20,
DISASSEMBLY_FLAGS_PLAIN = 0x40,
DISASSEMBLY_FLAGS_NO_OPCODE = 0x80,
DISASSEMBLY_FLAGS_PRINT_SYMBOLS = 0x100
DISASSEMBLY_FLAGS_NONE = 0,
DISASSEMBLY_FLAGS_SIMPLIFY = 1,
DISASSEMBLY_FLAGS_SPACE = 0x20,
DISASSEMBLY_FLAGS_PLAIN = 0x40,
DISASSEMBLY_FLAGS_NO_OPCODE = 0x80,
DISASSEMBLY_FLAGS_PRINT_SYMBOLS = 0x100
};
// Exceptions
enum OSExceptionMode {
OS_EXCEPTION_MODE_THREAD = 1,
OS_EXCEPTION_MODE_GLOBAL = 2,
OS_EXCEPTION_MODE_THREAD_ALL_CORES = 3,
OS_EXCEPTION_MODE_GLOBAL_ALL_CORES = 4
OS_EXCEPTION_MODE_THREAD = 1,
OS_EXCEPTION_MODE_GLOBAL = 2,
OS_EXCEPTION_MODE_THREAD_ALL_CORES = 3,
OS_EXCEPTION_MODE_GLOBAL_ALL_CORES = 4
};
enum OSExceptionType {
OS_EXCEPTION_TYPE_DSI = 2,
OS_EXCEPTION_TYPE_ISI = 3,
OS_EXCEPTION_TYPE_PROGRAM = 6
OS_EXCEPTION_TYPE_DSI = 2,
OS_EXCEPTION_TYPE_ISI = 3,
OS_EXCEPTION_TYPE_PROGRAM = 6
};
typedef bool (*OSExceptionCallback)(OSContext *context);
// File system
enum FSMode {
FS_MODE_READ_OWNER = 0x400,
FS_MODE_WRITE_OWNER = 0x200,
FS_MODE_EXEC_OWNER = 0x100,
FS_MODE_READ_OWNER = 0x400,
FS_MODE_WRITE_OWNER = 0x200,
FS_MODE_EXEC_OWNER = 0x100,
FS_MODE_READ_GROUP = 0x040,
FS_MODE_WRITE_GROUP = 0x020,
FS_MODE_EXEC_GROUP = 0x010,
FS_MODE_READ_GROUP = 0x040,
FS_MODE_WRITE_GROUP = 0x020,
FS_MODE_EXEC_GROUP = 0x010,
FS_MODE_READ_OTHER = 0x004,
FS_MODE_WRITE_OTHER = 0x002,
FS_MODE_EXEC_OTHER = 0x001
FS_MODE_READ_OTHER = 0x004,
FS_MODE_WRITE_OTHER = 0x002,
FS_MODE_EXEC_OTHER = 0x001
};
enum FSStatFlags {
FS_STAT_DIRECTORY = 0x80000000
FS_STAT_DIRECTORY = 0x80000000
};
enum FSMountSourceType {
FS_MOUNT_SOURCE_SD = 0
FS_MOUNT_SOURCE_SD = 0
};
struct FSClient {
char data[0x1700];
char data[0x1700];
};
struct FSCmdBlock {
char data[0xA80];
char data[0xA80];
};
struct FSMountSource {
char data[0x300];
char data[0x300];
};
struct __attribute__((packed)) FSStat {
FSStatFlags flags;
FSMode mode;
uint32_t owner;
uint32_t group;
uint32_t size;
char _14[0xC];
uint32_t entryId;
int64_t created;
int64_t modified;
char _34[0x30];
FSStatFlags flags;
FSMode mode;
uint32_t owner;
uint32_t group;
uint32_t size;
char _14[0xC];
uint32_t entryId;
int64_t created;
int64_t modified;
char _34[0x30];
};
struct FSDirectoryEntry {
FSStat info;
char name[256];
FSStat info;
char name[256];
};
// MCP
struct MCPTitleListType {
uint64_t titleId;
uint32_t _4;
char path[56];
uint32_t appType;
char _48[0xC];
uint8_t device;
char _55;
char indexedDevice[10];
uint8_t _60;
uint64_t titleId;
uint32_t _4;
char path[56];
uint32_t appType;
char _48[0xC];
uint8_t device;
char _55;
char indexedDevice[10];
uint8_t _60;
};
// Function pointers
@ -497,17 +496,17 @@ extern uint32_t (*MEMGetAllocatableSizeForExpHeapEx)(void *handle, int alignment
extern void *(**pMEMAllocFromDefaultHeap)(uint32_t size);
extern void *(**pMEMAllocFromDefaultHeapEx)(uint32_t size, int alignment);
extern void (**pMEMFreeToDefaultHeap)(void *ptr);
#define MEMAllocFromDefaultHeap (*pMEMAllocFromDefaultHeap)
extern void (**pMEMFreeToDefaultHeap)(void *ptr);
#define MEMAllocFromDefaultHeap (*pMEMAllocFromDefaultHeap)
#define MEMAllocFromDefaultHeapEx (*pMEMAllocFromDefaultHeapEx)
#define MEMFreeToDefaultHeap (*pMEMFreeToDefaultHeap)
#define MEMFreeToDefaultHeap (*pMEMFreeToDefaultHeap)
// Internal
extern OSDynLoad_RPLInfo **pMainRPL;
extern OSDynLoad_RPLInfo **pFirstRPL;
extern OSThread **pThreadList;
#define MainRPL (*pMainRPL)
#define FirstRPL (*pFirstRPL)
#define MainRPL (*pMainRPL)
#define FirstRPL (*pFirstRPL)
#define ThreadList (*pThreadList)
void coreinitInitialize();

View File

@ -3,18 +3,18 @@
#include <cstdint>
namespace nn::act {
uint32_t (*Initialize)();
uint8_t (*GetSlotNo)();
uint32_t (*GetPersistentIdEx)(uint8_t slot);
uint32_t (*Finalize)();
}
uint32_t (*Initialize)();
uint8_t (*GetSlotNo)();
uint32_t (*GetPersistentIdEx)(uint8_t slot);
uint32_t (*Finalize)();
} // namespace nn::act
void nnactInitialize() {
uint32_t handle;
OSDynLoad_Acquire("nn_act.rpl", &handle);
uint32_t handle;
OSDynLoad_Acquire("nn_act.rpl", &handle);
OSDynLoad_FindExport(handle, false, "Initialize__Q2_2nn3actFv", &nn::act::Initialize);
OSDynLoad_FindExport(handle, false, "GetSlotNo__Q2_2nn3actFv", &nn::act::GetSlotNo);
OSDynLoad_FindExport(handle, false, "GetPersistentIdEx__Q2_2nn3actFUc", &nn::act::GetPersistentIdEx);
OSDynLoad_FindExport(handle, false, "Finalize__Q2_2nn3actFv", &nn::act::Finalize);
OSDynLoad_FindExport(handle, false, "Initialize__Q2_2nn3actFv", &nn::act::Initialize);
OSDynLoad_FindExport(handle, false, "GetSlotNo__Q2_2nn3actFv", &nn::act::GetSlotNo);
OSDynLoad_FindExport(handle, false, "GetPersistentIdEx__Q2_2nn3actFUc", &nn::act::GetPersistentIdEx);
OSDynLoad_FindExport(handle, false, "Finalize__Q2_2nn3actFv", &nn::act::Finalize);
}

View File

@ -2,10 +2,10 @@
#include <cstdint>
namespace nn::act {
extern uint32_t (*Initialize)();
extern uint8_t (*GetSlotNo)();
extern uint32_t (*GetPersistentIdEx)(uint8_t slot);
extern uint32_t (*Finalize)();
}
extern uint32_t (*Initialize)();
extern uint8_t (*GetSlotNo)();
extern uint32_t (*GetPersistentIdEx)(uint8_t slot);
extern uint32_t (*Finalize)();
} // namespace nn::act
void nnactInitialize();

View File

@ -8,11 +8,11 @@ int (*SAVEGetSharedDataTitlePath)(uint64_t titleId, const char *path, char *outp
void (*SAVEShutdown)();
void nnsaveInitialize() {
uint32_t handle;
OSDynLoad_Acquire("nn_save.rpl", &handle);
uint32_t handle;
OSDynLoad_Acquire("nn_save.rpl", &handle);
OSDynLoad_FindExport(handle, false, "SAVEInit", &SAVEInit);
OSDynLoad_FindExport(handle, false, "SAVEOpenFile", &SAVEOpenFile);
OSDynLoad_FindExport(handle, false, "SAVEGetSharedDataTitlePath", &SAVEGetSharedDataTitlePath);
OSDynLoad_FindExport(handle, false, "SAVEShutdown", &SAVEShutdown);
OSDynLoad_FindExport(handle, false, "SAVEInit", &SAVEInit);
OSDynLoad_FindExport(handle, false, "SAVEOpenFile", &SAVEOpenFile);
OSDynLoad_FindExport(handle, false, "SAVEGetSharedDataTitlePath", &SAVEGetSharedDataTitlePath);
OSDynLoad_FindExport(handle, false, "SAVEShutdown", &SAVEShutdown);
}

View File

@ -17,19 +17,19 @@ int (*socketclose)(int socket);
int (*socket_lib_finish)();
void nsysnetInitialize() {
uint32_t handle;
OSDynLoad_Acquire("nsysnet.rpl", &handle);
uint32_t handle;
OSDynLoad_Acquire("nsysnet.rpl", &handle);
OSDynLoad_FindExport(handle, false, "socket_lib_init", &socket_lib_init);
OSDynLoad_FindExport(handle, false, "inet_aton", &inet_aton);
OSDynLoad_FindExport(handle, false, "socket", &socket);
OSDynLoad_FindExport(handle, false, "setsockopt", &setsockopt);
OSDynLoad_FindExport(handle, false, "connect", &connect);
OSDynLoad_FindExport(handle, false, "bind", &bind);
OSDynLoad_FindExport(handle, false, "listen", &listen);
OSDynLoad_FindExport(handle, false, "accept", &accept);
OSDynLoad_FindExport(handle, false, "send", &send);
OSDynLoad_FindExport(handle, false, "recv", &recv);
OSDynLoad_FindExport(handle, false, "socketclose", &socketclose);
OSDynLoad_FindExport(handle, false, "socket_lib_finish", &socket_lib_finish);
OSDynLoad_FindExport(handle, false, "socket_lib_init", &socket_lib_init);
OSDynLoad_FindExport(handle, false, "inet_aton", &inet_aton);
OSDynLoad_FindExport(handle, false, "socket", &socket);
OSDynLoad_FindExport(handle, false, "setsockopt", &setsockopt);
OSDynLoad_FindExport(handle, false, "connect", &connect);
OSDynLoad_FindExport(handle, false, "bind", &bind);
OSDynLoad_FindExport(handle, false, "listen", &listen);
OSDynLoad_FindExport(handle, false, "accept", &accept);
OSDynLoad_FindExport(handle, false, "send", &send);
OSDynLoad_FindExport(handle, false, "recv", &recv);
OSDynLoad_FindExport(handle, false, "socketclose", &socketclose);
OSDynLoad_FindExport(handle, false, "socket_lib_finish", &socket_lib_finish);
}

View File

@ -3,22 +3,22 @@
#include <cstdint>
#define AF_INET 2
#define AF_INET 2
#define SOCK_STREAM 1
#define SOCK_DGRAM 2
#define SOCK_STREAM 1
#define SOCK_DGRAM 2
#define IPPROTO_TCP 6
#define IPPROTO_UDP 17
#define IPPROTO_TCP 6
#define IPPROTO_UDP 17
#define SOL_SOCKET -1
#define SOL_SOCKET -1
#define SO_REUSEADDR 4
struct sockaddr {
uint16_t family;
uint16_t port;
uint32_t addr;
char zero[8];
uint16_t family;
uint16_t port;
uint32_t addr;
char zero[8];
};
extern int (*socket_lib_init)();

View File

@ -9,12 +9,12 @@ void (*SYSLaunchMenu)();
void (*SYSLaunchTitleByPathFromLauncher)(const char *path, int len);
void sysappInitialize() {
uint32_t handle;
OSDynLoad_Acquire("sysapp.rpl", &handle);
uint32_t handle;
OSDynLoad_Acquire("sysapp.rpl", &handle);
OSDynLoad_FindExport(handle, false, "SYSCheckTitleExists", &SYSCheckTitleExists);
OSDynLoad_FindExport(handle, false, "SYSLaunchTitle", &SYSLaunchTitle);
OSDynLoad_FindExport(handle, false, "SYSLaunchMenu", &SYSLaunchMenu);
OSDynLoad_FindExport(handle, false, "SYSCheckTitleExists", &SYSCheckTitleExists);
OSDynLoad_FindExport(handle, false, "SYSLaunchTitle", &SYSLaunchTitle);
OSDynLoad_FindExport(handle, false, "SYSLaunchMenu", &SYSLaunchMenu);
OSDynLoad_FindExport(handle, false, "_SYSLaunchTitleByPathFromLauncher", &SYSLaunchTitleByPathFromLauncher);
OSDynLoad_FindExport(handle, false, "_SYSLaunchTitleByPathFromLauncher", &SYSLaunchTitleByPathFromLauncher);
}

View File

@ -5,8 +5,8 @@
void (*VPADRead)(int chan, VPADStatus *buffers, uint32_t count, int *error);
void vpadInitialize() {
uint32_t handle;
OSDynLoad_Acquire("vpad.rpl", &handle);
uint32_t handle;
OSDynLoad_Acquire("vpad.rpl", &handle);
OSDynLoad_FindExport(handle, false, "VPADRead", &VPADRead);
OSDynLoad_FindExport(handle, false, "VPADRead", &VPADRead);
}

View File

@ -4,84 +4,84 @@
#include <cstdint>
enum VPADButtons {
VPAD_BUTTON_A = 0x8000,
VPAD_BUTTON_B = 0x4000,
VPAD_BUTTON_X = 0x2000,
VPAD_BUTTON_Y = 0x1000,
VPAD_BUTTON_LEFT = 0x0800,
VPAD_BUTTON_RIGHT = 0x0400,
VPAD_BUTTON_UP = 0x0200,
VPAD_BUTTON_DOWN = 0x0100,
VPAD_BUTTON_ZL = 0x0080,
VPAD_BUTTON_ZR = 0x0040,
VPAD_BUTTON_L = 0x0020,
VPAD_BUTTON_R = 0x0010,
VPAD_BUTTON_PLUS = 0x0008,
VPAD_BUTTON_MINUS = 0x0004,
VPAD_BUTTON_HOME = 0x0002,
VPAD_BUTTON_SYNC = 0x0001,
VPAD_BUTTON_A = 0x8000,
VPAD_BUTTON_B = 0x4000,
VPAD_BUTTON_X = 0x2000,
VPAD_BUTTON_Y = 0x1000,
VPAD_BUTTON_LEFT = 0x0800,
VPAD_BUTTON_RIGHT = 0x0400,
VPAD_BUTTON_UP = 0x0200,
VPAD_BUTTON_DOWN = 0x0100,
VPAD_BUTTON_ZL = 0x0080,
VPAD_BUTTON_ZR = 0x0040,
VPAD_BUTTON_L = 0x0020,
VPAD_BUTTON_R = 0x0010,
VPAD_BUTTON_PLUS = 0x0008,
VPAD_BUTTON_MINUS = 0x0004,
VPAD_BUTTON_HOME = 0x0002,
VPAD_BUTTON_SYNC = 0x0001,
VPAD_BUTTON_STICK_R = 0x00020000,
VPAD_BUTTON_STICK_L = 0x00040000,
VPAD_BUTTON_TV = 0x00010000
VPAD_BUTTON_STICK_R = 0x00020000,
VPAD_BUTTON_STICK_L = 0x00040000,
VPAD_BUTTON_TV = 0x00010000
};
struct VPADVec2D {
float x;
float y;
float x;
float y;
};
struct VPADVec3D {
float x;
float y;
float z;
float x;
float y;
float z;
};
struct VPADDirection {
VPADVec3D x;
VPADVec3D y;
VPADVec3D z;
VPADVec3D x;
VPADVec3D y;
VPADVec3D z;
};
struct VPADTouchData {
uint16_t x;
uint16_t y;
uint16_t touched;
uint16_t validity;
uint16_t x;
uint16_t y;
uint16_t touched;
uint16_t validity;
};
struct VPADAccStatus {
VPADVec3D acc;
float magnitude;
float variation;
VPADVec2D vertical;
VPADVec3D acc;
float magnitude;
float variation;
VPADVec2D vertical;
};
struct VPADStatus {
uint32_t hold;
uint32_t pressed;
uint32_t released;
VPADVec2D leftStick;
VPADVec2D rightStick;
VPADAccStatus accelerometer;
VPADVec3D gyro;
VPADVec3D angle;
uint8_t error;
uint8_t _51;
uint32_t hold;
uint32_t pressed;
uint32_t released;
VPADVec2D leftStick;
VPADVec2D rightStick;
VPADAccStatus accelerometer;
VPADVec3D gyro;
VPADVec3D angle;
uint8_t error;
uint8_t _51;
VPADTouchData tpNormal;
VPADTouchData tpFiltered1;
VPADTouchData tpFiltered2;
uint16_t _6A;
VPADTouchData tpNormal;
VPADTouchData tpFiltered1;
VPADTouchData tpFiltered2;
uint16_t _6A;
VPADDirection direction;
bool headphones;
VPADVec3D mag;
uint8_t volume;
uint8_t battery;
uint8_t micStatus;
uint8_t volumeEx;
char _A4[8];
VPADDirection direction;
bool headphones;
VPADVec3D mag;
uint8_t volume;
uint8_t battery;
uint8_t micStatus;
uint8_t volumeEx;
char _A4[8];
};
extern void (*VPADRead)(int chan, VPADStatus *buffers, uint32_t count, int *error);

View File

@ -2,14 +2,14 @@
#pragma once
enum Colors {
COLOR_WHITE = 0xFFFFFFFF,
COLOR_BLACK = 0x000000FF,
COLOR_WHITE = 0xFFFFFFFF,
COLOR_BLACK = 0x000000FF,
COLOR_RED = 0xFF0000FF,
COLOR_GREEN = 0x00FF00FF,
COLOR_BLUE = 0x0000FFFF,
COLOR_RED = 0xFF0000FF,
COLOR_GREEN = 0x00FF00FF,
COLOR_BLUE = 0x0000FFFF,
COLOR_LIGHT_RED = 0xFF8080FF,
COLOR_LIGHT_GREEN = 0x80FF80FF,
COLOR_LIGHT_BLUE = 0x8080FFFF,
COLOR_LIGHT_RED = 0xFF8080FF,
COLOR_LIGHT_GREEN = 0x80FF80FF,
COLOR_LIGHT_BLUE = 0x8080FFFF,
};

File diff suppressed because it is too large Load Diff

View File

@ -9,256 +9,256 @@
#include <vector>
#define MESSAGE_COUNT 10
#define STACK_SIZE 0x8000
#define STACK_SIZE 0x8000
#define TRAP 0x7FE00008
#define TRAP 0x7FE00008
template <int N>
template<int N>
class Bits {
public:
Bits(uint32_t value) {
this->value = value;
}
Bits(uint32_t value) {
this->value = value;
}
bool operator [](int index) {
return (value >> (N - index - 1)) & 1;
}
bool operator[](int index) {
return (value >> (N - index - 1)) & 1;
}
private:
uint32_t value;
uint32_t value;
};
class ExceptionState {
public:
enum Type {
DSI,
ISI,
PROGRAM
};
enum Type {
DSI,
ISI,
PROGRAM
};
bool isBreakpoint();
void resume();
bool isBreakpoint();
void resume();
Type type;
OSContext context;
Type type;
OSContext context;
OSThread *thread;
OSThread *thread;
OSMessageQueue queue;
OSMessage message;
OSMessageQueue queue;
OSMessage message;
bool isPaused;
bool isPaused;
};
class ExceptionMgr {
public:
void init();
void lock();
void unlock();
void cleanup();
ExceptionState *find(OSThread *thread);
ExceptionState *findOrCreate(OSThread *thread);
void init();
void lock();
void unlock();
void cleanup();
ExceptionState *find(OSThread *thread);
ExceptionState *findOrCreate(OSThread *thread);
private:
OSMutex mutex;
std::vector<ExceptionState *> list;
OSMutex mutex;
std::vector<ExceptionState *> list;
};
class BreakPoint {
public:
bool isRange(uint32_t addr, uint32_t length);
bool isRange(uint32_t addr, uint32_t length);
uint32_t address;
uint32_t instruction;
bool isSpecial;
uint32_t address;
uint32_t instruction;
bool isSpecial;
};
class SpecialBreakPoint : public BreakPoint {
public:
OSThread *thread;
OSThread *thread;
};
template <class T>
template<class T>
class BreakPointList {
public:
size_t size() {
return list.size();
}
size_t size() {
return list.size();
}
T *alloc() {
for (int i = 0; i < size(); i++) {
if (list[i].address == 0) {
return &list[i];
}
}
T *alloc() {
for (int i = 0; i < size(); i++) {
if (list[i].address == 0) {
return &list[i];
}
}
T newBp;
newBp.address = 0;
newBp.instruction = 0;
list.push_back(newBp);
return &list.back();
}
T newBp;
newBp.address = 0;
newBp.instruction = 0;
list.push_back(newBp);
return &list.back();
}
T *find(uint32_t addr) {
for (int i = 0; i < size(); i++) {
if (list[i].address == addr) {
return &list[i];
}
}
return nullptr;
}
T *find(uint32_t addr) {
for (int i = 0; i < size(); i++) {
if (list[i].address == addr) {
return &list[i];
}
}
return nullptr;
}
T *findRange(uint32_t addr, uint32_t length, int *index) {
int i = *index;
while (i < size()) {
if (list[i].isRange(addr, length)) {
*index = i + 1;
return &list[i];
}
i++;
}
T *findRange(uint32_t addr, uint32_t length, int *index) {
int i = *index;
while (i < size()) {
if (list[i].isRange(addr, length)) {
*index = i + 1;
return &list[i];
}
i++;
}
if (i > *index) {
*index = i;
}
return nullptr;
}
if (i > *index) {
*index = i;
}
return nullptr;
}
T *operator [](int index) {
return &list[index];
}
T *operator[](int index) {
return &list[index];
}
void cleanup() {
for (int i = 0; i < size(); i++) {
if (list[i].address != 0) {
KernelWriteU32(list[i].address, list[i].instruction);
list[i].address = 0;
list[i].instruction = 0;
}
}
}
void cleanup() {
for (int i = 0; i < size(); i++) {
if (list[i].address != 0) {
KernelWriteU32(list[i].address, list[i].instruction);
list[i].address = 0;
list[i].instruction = 0;
}
}
}
private:
std::vector<T> list;
std::vector<T> list;
};
class BreakPointMgr {
public:
void init();
void lock();
void unlock();
void cleanup();
bool isCustom(uint32_t addr);
bool isSoftware(uint32_t addr);
bool isSpecial(uint32_t addr);
void read(void *buffer, uint32_t addr, uint32_t length);
void write(const void *buffer, uint32_t addr, uint32_t length);
void toggle(uint32_t addr);
uint32_t getInstr(uint32_t addr);
BreakPoint *find(uint32_t addr, bool includeSpecial);
BreakPoint *findRange(uint32_t addr, uint32_t length, int *index, bool includeSpecial);
SpecialBreakPoint *findSpecial(uint32_t addr, OSThread *thread);
void clearSpecial(OSThread *thread);
void predictStep(ExceptionState *state, bool stepOver);
void init();
void lock();
void unlock();
void cleanup();
bool isCustom(uint32_t addr);
bool isSoftware(uint32_t addr);
bool isSpecial(uint32_t addr);
void read(void *buffer, uint32_t addr, uint32_t length);
void write(const void *buffer, uint32_t addr, uint32_t length);
void toggle(uint32_t addr);
uint32_t getInstr(uint32_t addr);
BreakPoint *find(uint32_t addr, bool includeSpecial);
BreakPoint *findRange(uint32_t addr, uint32_t length, int *index, bool includeSpecial);
SpecialBreakPoint *findSpecial(uint32_t addr, OSThread *thread);
void clearSpecial(OSThread *thread);
void predictStep(ExceptionState *state, bool stepOver);
private:
BreakPoint *alloc();
SpecialBreakPoint *allocSpecial();
void disable(BreakPoint *bp);
void enable(BreakPoint *bp, uint32_t addr);
BreakPoint *alloc();
SpecialBreakPoint *allocSpecial();
void disable(BreakPoint *bp);
void enable(BreakPoint *bp, uint32_t addr);
BreakPointList<BreakPoint> breakpoints;
BreakPointList<SpecialBreakPoint> special;
BreakPointList<BreakPoint> breakpoints;
BreakPointList<SpecialBreakPoint> special;
OSMutex mutex;
OSMutex mutex;
};
class StepMgr {
public:
void init();
void lock();
void unlock();
void singleStep(ExceptionState *state, uint32_t instruction);
void handleBreakPoint(ExceptionState *state);
void adjustAddress(ExceptionState *state);
void init();
void lock();
void unlock();
void singleStep(ExceptionState *state, uint32_t instruction);
void handleBreakPoint(ExceptionState *state);
void adjustAddress(ExceptionState *state);
private:
static uint32_t buffer[96];
static uint32_t buffer[96];
uint32_t *alloc();
void free(int index);
void branchConditional(ExceptionState *state, uint32_t instruction, uint32_t target, bool checkCtr);
uint32_t *alloc();
void free(int index);
void branchConditional(ExceptionState *state, uint32_t instruction, uint32_t target, bool checkCtr);
OSMutex mutex;
OSMutex mutex;
uint32_t usedMask;
uint32_t usedMask;
};
class Debugger {
public:
enum StepCommand {
STEP_CONTINUE,
STEP_INTO,
STEP_OVER
};
enum StepCommand {
STEP_CONTINUE,
STEP_INTO,
STEP_OVER
};
void start();
void start();
private:
enum Command {
COMMAND_CLOSE,
COMMAND_READ,
COMMAND_WRITE,
COMMAND_WRITE_CODE,
COMMAND_GET_MODULE_NAME,
COMMAND_GET_MODULE_LIST,
COMMAND_GET_THREAD_LIST,
COMMAND_GET_STACK_TRACE,
COMMAND_TOGGLE_BREAKPOINT,
COMMAND_POKE_REGISTERS,
COMMAND_RECEIVE_MESSAGES,
COMMAND_SEND_MESSAGE
};
enum Command {
COMMAND_CLOSE,
COMMAND_READ,
COMMAND_WRITE,
COMMAND_WRITE_CODE,
COMMAND_GET_MODULE_NAME,
COMMAND_GET_MODULE_LIST,
COMMAND_GET_THREAD_LIST,
COMMAND_GET_STACK_TRACE,
COMMAND_TOGGLE_BREAKPOINT,
COMMAND_POKE_REGISTERS,
COMMAND_RECEIVE_MESSAGES,
COMMAND_SEND_MESSAGE
};
static int threadEntry(int argc, void *argv);
static bool dsiHandler(OSContext *context);
static bool isiHandler(OSContext *context);
static bool programHandler(OSContext *context);
static void exceptionHandler(OSContext *context, ExceptionState::Type type);
static int threadEntry(int argc, void *argv);
static bool dsiHandler(OSContext *context);
static bool isiHandler(OSContext *context);
static bool programHandler(OSContext *context);
static void exceptionHandler(OSContext *context, ExceptionState::Type type);
void threadFunc();
void mainLoop(Client *client);
void handleException(OSContext *context, ExceptionState::Type type);
void handleFatalCrash(OSContext *context, ExceptionState::Type type);
void handleCrash(ExceptionState *state);
void handleBreakPoint(ExceptionState *state);
void processBreakPoint(ExceptionState *state);
void resumeBreakPoint(ExceptionState *state);
StepCommand notifyBreak(ExceptionState *state);
void cleanup();
void threadFunc();
void mainLoop(Client *client);
void handleException(OSContext *context, ExceptionState::Type type);
void handleFatalCrash(OSContext *context, ExceptionState::Type type);
void handleCrash(ExceptionState *state);
void handleBreakPoint(ExceptionState *state);
void processBreakPoint(ExceptionState *state);
void resumeBreakPoint(ExceptionState *state);
StepCommand notifyBreak(ExceptionState *state);
void cleanup();
bool checkDataRead(uint32_t addr, uint32_t length);
bool checkDataRead(uint32_t addr, uint32_t length);
OSMessageQueue eventQueue;
OSMessage eventMessages[MESSAGE_COUNT];
OSMessageQueue eventQueue;
OSMessage eventMessages[MESSAGE_COUNT];
OSThread *serverThread;
OSThread *serverThread;
BreakPointMgr breakpoints;
ExceptionMgr exceptions;
StepMgr stepper;
BreakPointMgr breakpoints;
ExceptionMgr exceptions;
StepMgr stepper;
bool initialized;
bool connected;
bool firstTrap;
bool initialized;
bool connected;
bool firstTrap;
};
extern Debugger *debugger;

View File

@ -2,50 +2,49 @@
#include "cafe/coreinit.h"
void DumpContext(OSContext *context, const char *excType) {
char buffer[1000];
snprintf(buffer, 1000,
"%s exception occurred!\n"
"r0 :%08X r1 :%08X r2 :%08X r3 :%08X r4 :%08X\n"
"r5 :%08X r6 :%08X r7 :%08X r8 :%08X r9 :%08X\n"
"r10:%08X r11:%08X r12:%08X r13:%08X r14:%08X\n"
"r15:%08X r16:%08X r17:%08X r18:%08X r19:%08X\n"
"r20:%08X r21:%08X r22:%08X r23:%08X r24:%08X\n"
"r25:%08X r26:%08X r27:%08X r28:%08X r29:%08X\n"
"r30:%08X r31:%08X LR :%08X CTR:%08X XER:%08X\n"
"\n"
"SRR0:%08X SRR1:%08X DSISR:%08X DAR:%08X",
excType,
context->gpr[0], context->gpr[1], context->gpr[2], context->gpr[3],
context->gpr[4], context->gpr[5], context->gpr[6], context->gpr[7],
context->gpr[8], context->gpr[9], context->gpr[10], context->gpr[11],
context->gpr[12], context->gpr[13], context->gpr[14], context->gpr[15],
context->gpr[16], context->gpr[17], context->gpr[18], context->gpr[19],
context->gpr[20], context->gpr[21], context->gpr[22], context->gpr[23],
context->gpr[24], context->gpr[25], context->gpr[26], context->gpr[27],
context->gpr[28], context->gpr[29], context->gpr[30], context->gpr[31],
context->lr, context->ctr, context->xer, context->srr0, context->srr1,
context->dsisr, context->dar
);
OSFatal(buffer);
char buffer[1000];
snprintf(buffer, 1000,
"%s exception occurred!\n"
"r0 :%08X r1 :%08X r2 :%08X r3 :%08X r4 :%08X\n"
"r5 :%08X r6 :%08X r7 :%08X r8 :%08X r9 :%08X\n"
"r10:%08X r11:%08X r12:%08X r13:%08X r14:%08X\n"
"r15:%08X r16:%08X r17:%08X r18:%08X r19:%08X\n"
"r20:%08X r21:%08X r22:%08X r23:%08X r24:%08X\n"
"r25:%08X r26:%08X r27:%08X r28:%08X r29:%08X\n"
"r30:%08X r31:%08X LR :%08X CTR:%08X XER:%08X\n"
"\n"
"SRR0:%08X SRR1:%08X DSISR:%08X DAR:%08X",
excType,
context->gpr[0], context->gpr[1], context->gpr[2], context->gpr[3],
context->gpr[4], context->gpr[5], context->gpr[6], context->gpr[7],
context->gpr[8], context->gpr[9], context->gpr[10], context->gpr[11],
context->gpr[12], context->gpr[13], context->gpr[14], context->gpr[15],
context->gpr[16], context->gpr[17], context->gpr[18], context->gpr[19],
context->gpr[20], context->gpr[21], context->gpr[22], context->gpr[23],
context->gpr[24], context->gpr[25], context->gpr[26], context->gpr[27],
context->gpr[28], context->gpr[29], context->gpr[30], context->gpr[31],
context->lr, context->ctr, context->xer, context->srr0, context->srr1,
context->dsisr, context->dar);
OSFatal(buffer);
}
bool DSIHandler(OSContext *context) {
DumpContext(context, "A DSI");
return false;
DumpContext(context, "A DSI");
return false;
}
bool ISIHandler(OSContext *context) {
DumpContext(context, "An ISI");
return false;
DumpContext(context, "An ISI");
return false;
}
bool ProgramHandler(OSContext *context) {
DumpContext(context, "A program");
return false;
DumpContext(context, "A program");
return false;
}
void InstallExceptionHandlers() {
OSSetExceptionCallbackEx(OS_EXCEPTION_MODE_GLOBAL_ALL_CORES, OS_EXCEPTION_TYPE_DSI, DSIHandler);
OSSetExceptionCallbackEx(OS_EXCEPTION_MODE_GLOBAL_ALL_CORES, OS_EXCEPTION_TYPE_ISI, ISIHandler);
OSSetExceptionCallbackEx(OS_EXCEPTION_MODE_GLOBAL_ALL_CORES, OS_EXCEPTION_TYPE_PROGRAM, ProgramHandler);
OSSetExceptionCallbackEx(OS_EXCEPTION_MODE_GLOBAL_ALL_CORES, OS_EXCEPTION_TYPE_DSI, DSIHandler);
OSSetExceptionCallbackEx(OS_EXCEPTION_MODE_GLOBAL_ALL_CORES, OS_EXCEPTION_TYPE_ISI, ISIHandler);
OSSetExceptionCallbackEx(OS_EXCEPTION_MODE_GLOBAL_ALL_CORES, OS_EXCEPTION_TYPE_PROGRAM, ProgramHandler);
}

View File

@ -6,10 +6,10 @@
#define MEM_BASE 0x800000
struct OsSpecifics {
uint32_t OSDynLoad_Acquire;
uint32_t OSDynLoad_FindExport;
uint32_t OSDynLoad_Acquire;
uint32_t OSDynLoad_FindExport;
};
#define OS_SPECIFICS ((OsSpecifics *)(MEM_BASE + 0x1500))
#define OS_SPECIFICS ((OsSpecifics *) (MEM_BASE + 0x1500))
#define EXIT_SUCCESS 0
#define EXIT_SUCCESS 0
#define EXIT_RELAUNCH_ON_LOAD -3

View File

@ -3,19 +3,19 @@
#include <cstdint>
uint32_t GetInput(uint32_t mask) {
VPADStatus input;
int error;
VPADRead(0, &input, 1, &error);
return input.pressed & mask;
VPADStatus input;
int error;
VPADRead(0, &input, 1, &error);
return input.pressed & mask;
}
uint32_t WaitInput(uint32_t mask) {
VPADStatus input;
int error;
while (true) {
VPADRead(0, &input, 1, &error);
if (input.pressed & mask) {
return input.pressed & mask;
}
}
VPADStatus input;
int error;
while (true) {
VPADRead(0, &input, 1, &error);
if (input.pressed & mask) {
return input.pressed & mask;
}
}
}

View File

@ -13,52 +13,50 @@ extern "C" void SCKernelCopyData(uint32_t dst, uint32_t src, uint32_t len);
extern "C" void KernelCopyData(uint32_t dst, uint32_t src, uint32_t len);
void KernelWrite(uint32_t addr, const void *data, uint32_t length) {
uint32_t dst = OSEffectiveToPhysical(addr);
uint32_t src = OSEffectiveToPhysical((uint32_t)data);
KernelCopyData(dst, src, length);
DCFlushRange((void *)addr, length);
ICInvalidateRange((void *)addr, length);
uint32_t dst = OSEffectiveToPhysical(addr);
uint32_t src = OSEffectiveToPhysical((uint32_t) data);
KernelCopyData(dst, src, length);
DCFlushRange((void *) addr, length);
ICInvalidateRange((void *) addr, length);
}
void KernelWriteU32(uint32_t addr, uint32_t value) {
uint32_t dst = OSEffectiveToPhysical(addr);
uint32_t src = OSEffectiveToPhysical((uint32_t)&value);
KernelCopyData(dst, src, 4);
DCFlushRange((void *)addr, 4);
ICInvalidateRange((void *)addr, 4);
uint32_t dst = OSEffectiveToPhysical(addr);
uint32_t src = OSEffectiveToPhysical((uint32_t) &value);
KernelCopyData(dst, src, 4);
DCFlushRange((void *) addr, 4);
ICInvalidateRange((void *) addr, 4);
}
/* Write a 32-bit word with kernel permissions */
void __attribute__ ((noinline)) kern_write(uint32_t addr, uint32_t value)
{
asm volatile (
"li 3,1\n"
"li 4,0\n"
"mr 5,%1\n"
"li 6,0\n"
"li 7,0\n"
"lis 8,1\n"
"mr 9,%0\n"
"mr %1,1\n"
"li 0,0x3500\n"
"sc\n"
"nop\n"
"mr 1,%1\n"
:
: "r"(addr), "r"(value)
: "memory", "ctr", "lr", "0", "3", "4", "5", "6", "7", "8", "9", "10",
"11", "12"
);
void __attribute__((noinline)) kern_write(uint32_t addr, uint32_t value) {
asm volatile(
"li 3,1\n"
"li 4,0\n"
"mr 5,%1\n"
"li 6,0\n"
"li 7,0\n"
"lis 8,1\n"
"mr 9,%0\n"
"mr %1,1\n"
"li 0,0x3500\n"
"sc\n"
"nop\n"
"mr 1,%1\n"
:
: "r"(addr), "r"(value)
: "memory", "ctr", "lr", "0", "3", "4", "5", "6", "7", "8", "9", "10",
"11", "12");
}
void PatchSyscall(int index, uint32_t addr) {
kern_write(KERN_SYSCALL_TBL1 + index * 4, addr);
kern_write(KERN_SYSCALL_TBL2 + index * 4, addr);
kern_write(KERN_SYSCALL_TBL3 + index * 4, addr);
kern_write(KERN_SYSCALL_TBL4 + index * 4, addr);
kern_write(KERN_SYSCALL_TBL5 + index * 4, addr);
kern_write(KERN_SYSCALL_TBL1 + index * 4, addr);
kern_write(KERN_SYSCALL_TBL2 + index * 4, addr);
kern_write(KERN_SYSCALL_TBL3 + index * 4, addr);
kern_write(KERN_SYSCALL_TBL4 + index * 4, addr);
kern_write(KERN_SYSCALL_TBL5 + index * 4, addr);
}
void kernelInitialize() {
PatchSyscall(0x25, (uint32_t)SCKernelCopyData);
PatchSyscall(0x25, (uint32_t) SCKernelCopyData);
}

View File

@ -1,90 +1,87 @@
#include "cafe/coreinit.h"
#include "cafe/sysapp.h"
#include "cafe/nsysnet.h"
#include "cafe/vpad.h"
#include "cafe/nn_save.h"
#include "cafe/nn_act.h"
#include "kernel.h"
#include "cafe/nn_save.h"
#include "cafe/nsysnet.h"
#include "cafe/sysapp.h"
#include "cafe/vpad.h"
#include "hbl.h"
#include "kernel.h"
#include "patches.h"
#include "debugger.h"
#include "exceptions.h"
#include "screen.h"
#include "menu.h"
#include "patches.h"
#include "screen.h"
bool GetTitleIdOnDisk(uint64_t *titleId) {
MCPTitleListType title;
uint32_t count = 0;
MCPTitleListType title;
uint32_t count = 0;
int handle = MCP_Open();
MCP_TitleListByDevice(handle, "odd", &count, &title, sizeof(title));
MCP_Close(handle);
int handle = MCP_Open();
MCP_TitleListByDevice(handle, "odd", &count, &title, sizeof(title));
MCP_Close(handle);
if (count > 0) {
*titleId = title.titleId;
return true;
}
return false;
if (count > 0) {
*titleId = title.titleId;
return true;
}
return false;
}
int MenuMain() {
Screen screen;
screen.init();
Screen screen;
screen.init();
Menu menu(&screen);
Menu menu(&screen);
Menu::Option result = menu.show();
if (result == Menu::Exit) return EXIT_SUCCESS;
else if (result == Menu::LaunchDisk) {
uint64_t titleId;
if (GetTitleIdOnDisk(&titleId)) {
SYSLaunchTitle(titleId);
}
else {
menu.setMessage("Please insert a valid disk");
}
}
else if (result == Menu::ReturnToMenu) {
SYSLaunchMenu();
}
return EXIT_RELAUNCH_ON_LOAD;
Menu::Option result = menu.show();
if (result == Menu::Exit) return EXIT_SUCCESS;
else if (result == Menu::LaunchDisk) {
uint64_t titleId;
if (GetTitleIdOnDisk(&titleId)) {
SYSLaunchTitle(titleId);
} else {
menu.setMessage("Please insert a valid disk");
}
} else if (result == Menu::ReturnToMenu) {
SYSLaunchMenu();
}
return EXIT_RELAUNCH_ON_LOAD;
}
int DebuggerMain() {
ApplyPatches();
debugger = new Debugger();
debugger->start();
return EXIT_RELAUNCH_ON_LOAD;
ApplyPatches();
debugger = new Debugger();
debugger->start();
return EXIT_RELAUNCH_ON_LOAD;
}
bool firstRun = true;
int start() {
coreinitInitialize();
kernelInitialize();
vpadInitialize();
sysappInitialize();
nsysnetInitialize();
nnsaveInitialize();
nnactInitialize();
coreinitInitialize();
kernelInitialize();
vpadInitialize();
sysappInitialize();
nsysnetInitialize();
nnsaveInitialize();
nnactInitialize();
InstallExceptionHandlers();
InstallExceptionHandlers();
int result;
if (firstRun) {
result = MenuMain();
}
else {
result = DebuggerMain();
}
firstRun = false;
int result;
if (firstRun) {
result = MenuMain();
} else {
result = DebuggerMain();
}
firstRun = false;
return result;
return result;
}
extern "C" int entryPoint() {
return start();
return start();
}

View File

@ -3,26 +3,26 @@
#include <cstddef>
void * operator new(size_t size) {
return MEMAllocFromDefaultHeap(size);
void *operator new(size_t size) {
return MEMAllocFromDefaultHeap(size);
}
void * operator new[](size_t size) {
return MEMAllocFromDefaultHeap(size);
void *operator new[](size_t size) {
return MEMAllocFromDefaultHeap(size);
}
void * operator new(size_t size, int alignment) {
return MEMAllocFromDefaultHeapEx(size, alignment);
void *operator new(size_t size, int alignment) {
return MEMAllocFromDefaultHeapEx(size, alignment);
}
void * operator new[](size_t size, int alignment) {
return MEMAllocFromDefaultHeapEx(size, alignment);
void *operator new[](size_t size, int alignment) {
return MEMAllocFromDefaultHeapEx(size, alignment);
}
void operator delete(void *ptr) {
MEMFreeToDefaultHeap(ptr);
MEMFreeToDefaultHeap(ptr);
}
void operator delete(void *ptr, size_t size) {
MEMFreeToDefaultHeap(ptr);
MEMFreeToDefaultHeap(ptr);
}

View File

@ -1,44 +1,43 @@
#include "cafe/vpad.h"
#include "menu.h"
#include "screen.h"
#include "input.h"
#include "cafe/vpad.h"
#include "color.h"
#include "input.h"
#include "screen.h"
Menu::Menu(Screen *screen) : screen(screen) {
currentOption = LaunchDisk;
message = nullptr;
currentOption = LaunchDisk;
message = nullptr;
}
Menu::Option Menu::show() {
while (true) {
redraw();
uint32_t buttons = WaitInput(VPAD_BUTTON_A | VPAD_BUTTON_DOWN | VPAD_BUTTON_UP);
if (buttons & VPAD_BUTTON_A) return (Option)currentOption;
else if (buttons & VPAD_BUTTON_DOWN) {
if (currentOption < 2) currentOption++;
}
else if (buttons & VPAD_BUTTON_UP) {
if (currentOption > 0) currentOption--;
}
}
while (true) {
redraw();
uint32_t buttons = WaitInput(VPAD_BUTTON_A | VPAD_BUTTON_DOWN | VPAD_BUTTON_UP);
if (buttons & VPAD_BUTTON_A) return (Option) currentOption;
else if (buttons & VPAD_BUTTON_DOWN) {
if (currentOption < 2) currentOption++;
} else if (buttons & VPAD_BUTTON_UP) {
if (currentOption > 0) currentOption--;
}
}
}
void Menu::setMessage(const char *message) {
this->message = message;
redraw();
this->message = message;
redraw();
}
void Menu::redraw() {
screen->clear(COLOR_BLUE);
screen->drawText(5, 5, "Wii U Debugger");
screen->drawText(5, 7, "Choose an option:");
screen->drawText(8, 9, "Install and launch disc");
screen->drawText(8, 10, "Install and return to system menu");
screen->drawText(8, 11, "Exit without installing");
screen->drawText(5, 9 + currentOption, ">");
if (message) {
screen->drawText(5, 13, message);
}
screen->flip();
screen->clear(COLOR_BLUE);
screen->drawText(5, 5, "Wii U Debugger");
screen->drawText(5, 7, "Choose an option:");
screen->drawText(8, 9, "Install and launch disc");
screen->drawText(8, 10, "Install and return to system menu");
screen->drawText(8, 11, "Exit without installing");
screen->drawText(5, 9 + currentOption, ">");
if (message) {
screen->drawText(5, 13, message);
}
screen->flip();
}

View File

@ -4,21 +4,21 @@
#include "screen.h"
class Menu {
public:
enum Option {
LaunchDisk,
ReturnToMenu,
Exit
};
public:
enum Option {
LaunchDisk,
ReturnToMenu,
Exit
};
Menu(Screen *screen);
Option show();
void setMessage(const char *message);
void redraw();
Menu(Screen *screen);
Option show();
void setMessage(const char *message);
void redraw();
private:
Screen *screen;
int currentOption;
private:
Screen *screen;
int currentOption;
const char *message;
const char *message;
};

View File

@ -5,53 +5,52 @@
#include <cstdint>
int OSSetExceptionCallback_Patch() {
return 0;
return 0;
}
int OSSetExceptionCallbackEx_Patch() {
return 0;
return 0;
}
bool OSIsDebuggerInitialized_Patch() {
return true;
return true;
}
void Patch(void *funcPtr, void *patchPtr) {
OSDynLoad_NotifyData *sectionInfo = MainRPL->notifyData;
OSDynLoad_NotifyData *sectionInfo = MainRPL->notifyData;
uint32_t func = (uint32_t)funcPtr;
uint32_t patch = (uint32_t)patchPtr;
if (func < 0x01800000) { //OS function (with trampoline)
for (uint32_t addr = sectionInfo->textAddr; addr < 0x10000000; addr += 4) {
uint32_t *instrs = (uint32_t *)addr;
if (instrs[0] == (0x3D600000 | (func >> 16)) && //lis r11, func@h
instrs[1] == (0x616B0000 | (func & 0xFFFF)) && //ori r11, r11, func@l
instrs[2] == 0x7D6903A6 && //mtctr r11
instrs[3] == 0x4E800420) //bctr
{
KernelWriteU32(addr, 0x3D600000 | (patch >> 16)); //lis r11, patch@h
KernelWriteU32(addr + 4, 0x616B0000 | (patch & 0xFFFF)); //ori r11, r11, patch@l
}
}
}
else { //Dynamic function
for (uint32_t addr = sectionInfo->textAddr; addr < 0x10000000; addr += 4) {
uint32_t instr = *(uint32_t *)addr;
if ((instr & 0xFC000002) == 0x48000000) { //b or bl
if ((instr & 0x03FFFFFC) == func - addr) {
instr = instr & ~0x03FFFFFC;
instr |= patch;
instr |= 2; //Turn b/bl into ba/bla
KernelWriteU32(addr, instr);
}
}
}
}
uint32_t func = (uint32_t) funcPtr;
uint32_t patch = (uint32_t) patchPtr;
if (func < 0x01800000) { //OS function (with trampoline)
for (uint32_t addr = sectionInfo->textAddr; addr < 0x10000000; addr += 4) {
uint32_t *instrs = (uint32_t *) addr;
if (instrs[0] == (0x3D600000 | (func >> 16)) && //lis r11, func@h
instrs[1] == (0x616B0000 | (func & 0xFFFF)) && //ori r11, r11, func@l
instrs[2] == 0x7D6903A6 && //mtctr r11
instrs[3] == 0x4E800420) //bctr
{
KernelWriteU32(addr, 0x3D600000 | (patch >> 16)); //lis r11, patch@h
KernelWriteU32(addr + 4, 0x616B0000 | (patch & 0xFFFF)); //ori r11, r11, patch@l
}
}
} else { //Dynamic function
for (uint32_t addr = sectionInfo->textAddr; addr < 0x10000000; addr += 4) {
uint32_t instr = *(uint32_t *) addr;
if ((instr & 0xFC000002) == 0x48000000) { //b or bl
if ((instr & 0x03FFFFFC) == func - addr) {
instr = instr & ~0x03FFFFFC;
instr |= patch;
instr |= 2; //Turn b/bl into ba/bla
KernelWriteU32(addr, instr);
}
}
}
}
}
void ApplyPatches() {
Patch((void *)OSSetExceptionCallback, (void *)OSSetExceptionCallback_Patch);
Patch((void *)OSSetExceptionCallbackEx, (void *)OSSetExceptionCallbackEx_Patch);
Patch((void *) OSSetExceptionCallback, (void *) OSSetExceptionCallback_Patch);
Patch((void *) OSSetExceptionCallbackEx, (void *) OSSetExceptionCallbackEx_Patch);
Patch((void *)OSIsDebuggerInitialized, (void *)OSIsDebuggerInitialized_Patch);
Patch((void *) OSIsDebuggerInitialized, (void *) OSIsDebuggerInitialized_Patch);
}

View File

@ -1,87 +1,87 @@
#include "cafe/coreinit.h"
#include "screen.h"
#include "cafe/coreinit.h"
#include "memory.h"
Screen::Screen() : screenBuffer(0) {}
Screen::~Screen() {
if (screenBuffer) {
operator delete(screenBuffer);
}
if (screenBuffer) {
operator delete(screenBuffer);
}
}
void Screen::init() {
OSScreenInit();
OSScreenInit();
uint32_t bufferSize0 = OSScreenGetBufferSizeEx(0);
uint32_t bufferSize1 = OSScreenGetBufferSizeEx(1);
screenBuffer = operator new(bufferSize0 + bufferSize1, 0x40);
OSScreenSetBufferEx(0, screenBuffer);
OSScreenSetBufferEx(1, (char *)screenBuffer + bufferSize0);
uint32_t bufferSize0 = OSScreenGetBufferSizeEx(0);
uint32_t bufferSize1 = OSScreenGetBufferSizeEx(1);
screenBuffer = operator new(bufferSize0 + bufferSize1, 0x40);
OSScreenSetBufferEx(0, screenBuffer);
OSScreenSetBufferEx(1, (char *) screenBuffer + bufferSize0);
OSScreenEnableEx(0, 1);
OSScreenEnableEx(1, 1);
OSScreenClearBufferEx(0, 0);
OSScreenClearBufferEx(1, 0);
OSScreenFlipBuffersEx(0);
OSScreenFlipBuffersEx(1);
OSScreenEnableEx(0, 1);
OSScreenEnableEx(1, 1);
OSScreenClearBufferEx(0, 0);
OSScreenClearBufferEx(1, 0);
OSScreenFlipBuffersEx(0);
OSScreenFlipBuffersEx(1);
}
void Screen::clear(Display screen, uint32_t color) {
OSScreenClearBufferEx(screen, color);
OSScreenClearBufferEx(screen, color);
}
void Screen::drawRect(Display screen, int x1, int y1, int x2, int y2, uint32_t color) {
for (int x = x1; x < x2; x++) {
OSScreenPutPixelEx(screen, x, y1, color);
OSScreenPutPixelEx(screen, x, y2, color);
}
for (int y = y1; y < y2; y++) {
OSScreenPutPixelEx(screen, x1, y, color);
OSScreenPutPixelEx(screen, x2, y, color);
}
for (int x = x1; x < x2; x++) {
OSScreenPutPixelEx(screen, x, y1, color);
OSScreenPutPixelEx(screen, x, y2, color);
}
for (int y = y1; y < y2; y++) {
OSScreenPutPixelEx(screen, x1, y, color);
OSScreenPutPixelEx(screen, x2, y, color);
}
}
void Screen::fillRect(Display screen, int x1, int y1, int x2, int y2, uint32_t color) {
for (int x = x1; x < x2; x++) {
for (int y = y1; y < y2; y++) {
OSScreenPutPixelEx(screen, x, y, color);
}
}
for (int x = x1; x < x2; x++) {
for (int y = y1; y < y2; y++) {
OSScreenPutPixelEx(screen, x, y, color);
}
}
}
void Screen::drawText(Display screen, int x, int y, const char *text) {
OSScreenPutFontEx(screen, x, y, text);
OSScreenPutFontEx(screen, x, y, text);
}
void Screen::flip(Display screen) {
OSScreenFlipBuffersEx(screen);
OSScreenFlipBuffersEx(screen);
}
int Screen::convx(int x) { return x * 854 / 1280; }
int Screen::convy(int y) { return y * 480 / 720; }
void Screen::clear(uint32_t color) {
clear(TV, color);
clear(DRC, color);
clear(TV, color);
clear(DRC, color);
}
void Screen::drawRect(int x1, int y1, int x2, int y2, uint32_t color) {
drawRect(TV, x1, y1, x2, y2, color);
drawRect(DRC, convx(x1), convy(y1), convx(x2), convy(y2), color);
drawRect(TV, x1, y1, x2, y2, color);
drawRect(DRC, convx(x1), convy(y1), convx(x2), convy(y2), color);
}
void Screen::fillRect(int x1, int y1, int x2, int y2, uint32_t color) {
fillRect(TV, x1, y1, x2, y2, color);
fillRect(DRC, convx(x1), convy(y1), convx(x2), convy(y2), color);
fillRect(TV, x1, y1, x2, y2, color);
fillRect(DRC, convx(x1), convy(y1), convx(x2), convy(y2), color);
}
void Screen::drawText(int x, int y, const char *text) {
drawText(TV, x, y, text);
drawText(DRC, x, y, text);
drawText(TV, x, y, text);
drawText(DRC, x, y, text);
}
void Screen::flip() {
flip(TV);
flip(DRC);
flip(TV);
flip(DRC);
}

View File

@ -4,31 +4,31 @@
#include <cstdint>
class Screen {
public:
enum Display {
TV,
DRC
};
public:
enum Display {
TV,
DRC
};
Screen();
~Screen();
Screen();
~Screen();
void init();
void clear(uint32_t color);
void drawRect(int x1, int y1, int x2, int y2, uint32_t color);
void fillRect(int x1, int y1, int x2, int y2, uint32_t color);
void drawText(int x, int y, const char *text);
void flip();
void init();
void clear(uint32_t color);
void drawRect(int x1, int y1, int x2, int y2, uint32_t color);
void fillRect(int x1, int y1, int x2, int y2, uint32_t color);
void drawText(int x, int y, const char *text);
void flip();
void clear(Display screen, uint32_t color);
void drawRect(Display screen, int x1, int y1, int x2, int y2, uint32_t color);
void fillRect(Display screen, int x1, int y1, int x2, int y2, uint32_t color);
void drawText(Display screen, int x, int y, const char *text);
void flip(Display screen);
void clear(Display screen, uint32_t color);
void drawRect(Display screen, int x1, int y1, int x2, int y2, uint32_t color);
void fillRect(Display screen, int x1, int y1, int x2, int y2, uint32_t color);
void drawText(Display screen, int x, int y, const char *text);
void flip(Display screen);
private:
void *screenBuffer;
private:
void *screenBuffer;
int convx(int x);
int convy(int y);
int convx(int x);
int convy(int y);
};

View File

@ -6,96 +6,95 @@
Socket::Socket() : sock(-1) {}
Socket::~Socket() {
if (sock >= 0) {
socketclose(sock);
}
if (sock >= 0) {
socketclose(sock);
}
}
bool Socket::init(Type type) {
if (type == TCP) {
sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
}
else {
sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
}
return sock >= 0;
if (type == TCP) {
sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
} else {
sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
}
return sock >= 0;
}
bool Socket::close() {
if (sock >= 0) {
int result = socketclose(sock);
sock = -1;
return result == 0;
}
return true;
if (sock >= 0) {
int result = socketclose(sock);
sock = -1;
return result == 0;
}
return true;
}
bool Client::sendall(const void *data, size_t length) {
size_t sent = 0;
while (sent < length) {
int num = send(sock, data, length - sent, 0);
if (num < 0) {
close();
return false;
}
size_t sent = 0;
while (sent < length) {
int num = send(sock, data, length - sent, 0);
if (num < 0) {
close();
return false;
}
sent += num;
data = (const char *)data + num;
}
return true;
sent += num;
data = (const char *) data + num;
}
return true;
}
bool Client::recvall(void *data, size_t length) {
size_t received = 0;
while (received < length) {
int num = recv(sock, data, length - received, 0);
if (num <= 0) {
close();
return false;
}
size_t received = 0;
while (received < length) {
int num = recv(sock, data, length - received, 0);
if (num <= 0) {
close();
return false;
}
received += num;
data = (char *)data + num;
}
return true;
received += num;
data = (char *) data + num;
}
return true;
}
bool Server::bind(int port) {
uint32_t reuseaddr = 1;
int result = setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &reuseaddr, 4);
if (result < 0) {
close();
return false;
}
uint32_t reuseaddr = 1;
int result = setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &reuseaddr, 4);
if (result < 0) {
close();
return false;
}
sockaddr serverAddr = {0};
serverAddr.family = AF_INET;
serverAddr.port = port;
serverAddr.addr = 0;
sockaddr serverAddr = {0};
serverAddr.family = AF_INET;
serverAddr.port = port;
serverAddr.addr = 0;
result = ::bind(sock, &serverAddr, 16);
if (result < 0) {
close();
return false;
}
return true;
result = ::bind(sock, &serverAddr, 16);
if (result < 0) {
close();
return false;
}
return true;
}
bool Server::accept(Client *client) {
int result = listen(sock, 1);
if (result < 0) {
close();
return false;
}
int result = listen(sock, 1);
if (result < 0) {
close();
return false;
}
int fd = ::accept(sock, 0, 0);
if (fd < 0) {
close();
return false;
}
int fd = ::accept(sock, 0, 0);
if (fd < 0) {
close();
return false;
}
client->sock = fd;
return true;
client->sock = fd;
return true;
}

View File

@ -5,27 +5,27 @@
class Socket {
public:
enum Type {
TCP,
UDP
};
enum Type {
TCP,
UDP
};
Socket();
~Socket();
bool init(Type type);
bool close();
Socket();
~Socket();
bool init(Type type);
bool close();
int sock;
int sock;
};
class Client : public Socket {
public:
bool sendall(const void *data, size_t length);
bool recvall(void *data, size_t length);
bool sendall(const void *data, size_t length);
bool recvall(void *data, size_t length);
};
class Server : public Socket {
public:
bool bind(int port);
bool accept(Client *client);
bool bind(int port);
bool accept(Client *client);
};