Skip to content

Commit

Permalink
half of DWC matching (#326)
Browse files Browse the repository at this point in the history
* half of DWC matching

* works on my machine™
  • Loading branch information
ieee802dot11ac authored Aug 26, 2024
1 parent 3df24f2 commit f69a504
Show file tree
Hide file tree
Showing 16 changed files with 407 additions and 3 deletions.
8 changes: 8 additions & 0 deletions config/SZBE69_B8/flags.json
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,14 @@
"-O4,p"
]
},
"sdk/DWC": {
"base": "base",
"flags": [
"-func_align 4",
"-O4,p",
"-Isrc/sdk/DWC"
]
},
"sdk/ec": {
"base": "base",
"flags": [
Expand Down
8 changes: 7 additions & 1 deletion config/SZBE69_B8/objects.json
Original file line number Diff line number Diff line change
Expand Up @@ -846,6 +846,7 @@
"sdk/RVL_SDK/revolution/gx/GXTransform.c": "Matching",

"sdk/RVL_SDK/revolution/os/OSCrc.c": "NonMatching",
"sdk/RVL_SDK/revolution/os/OSReboot.c": "Matching",
"sdk/RVL_SDK/revolution/os/OSSemaphore.c": "Matching",

"sdk/RVL_SDK/revolution/sc/scsystem.c": "NonMatching",
Expand All @@ -871,9 +872,14 @@
},
"sdk/DWC": {
"mw_version": "Wii/1.3",
"cflags": "base",
"cflags": "sdk/DWC",
"objects": {
"sdk/DWC/dwc_common/dwc_error.c": "Matching",
"sdk/DWC/dwc_common/dwc_init.c": "Matching",
"sdk/DWC/dwc_common/dwc_memfunc.c": "Matching",
"sdk/DWC/dwc_common/dwc_report.c": "Matching",

"sdk/DWC/dwcsec_nas/dwc_naslogin.c": "Matching"
}
},
"sdk/ec": {
Expand Down
66 changes: 66 additions & 0 deletions src/sdk/DWC/dwc_common/dwc_error.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#include "dwc_error.h"
#include "dwc_common/dwc_report.h"

int stDwcLastError = 0;
u32 stDwcErrorCode = 0;

u32 DWC_GetLastErrorEx(int* errCode, int* r4) {
if (errCode != NULL) {
*errCode = stDwcErrorCode;
}
if (r4 != NULL) {
switch(stDwcLastError) {
case 2:
case 3:
case 4:
case 5:
case 8:
case 0xe:
case 0x10:
case 0x12:
case 0x15:
*r4 = 6; break;
case 6:
*r4 = 3; break;
case 7:
*r4 = 4; break;
case 0xd:
*r4 = 5; break;
case 0x16:
*r4 = 8; break;
case 10:
case 0xb:
case 0xc:
case 0x18:
*r4 = 1; break;
case 0xf:
case 0x11:
case 0x13:
case 0x14:
case 0x17:
case 0x19:
*r4 = 2; break;
case 1:
case 9:
*r4 = 7; break;
default:
*r4 = 0; break;
}
}
return stDwcLastError;
}

void DWC_ClearError(void) {
if (stDwcLastError == 9) return;
stDwcLastError = 0;
stDwcErrorCode = 0;
}

void DWCi_SetError(int lastErr, int errCode) {
if (stDwcLastError != 9) {
stDwcLastError = lastErr;
stDwcErrorCode = errCode;
}
if (lastErr != 9) return;
DWC_Printf(-1, "FATALERROR_SET\n");
}
14 changes: 14 additions & 0 deletions src/sdk/DWC/dwc_common/dwc_error.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#pragma once
#ifdef __cplusplus
extern "C" {
#endif

#include "types.h"

u32 DWC_GetLastErrorEx(int* r3, int* r4);
void DWC_ClearError(void);
void DWCi_SetError(int r3, int r4);

#ifdef __cplusplus
}
#endif
78 changes: 78 additions & 0 deletions src/sdk/DWC/dwc_common/dwc_init.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#include "dwc_init.h"
#include "revolution/os/OS.h"
#include "dwc_common/dwc_memfunc.h"
#include "dwc_common/dwc_report.h"
#include "dwc_nonport/dwc_nonport.h"
#include "dwcsec_auth/dwc_auth_interface.h"
#include "types.h"
#include <string.h>

static u32 dwci_gamecode = 0;
static BOOL s_initialized = FALSE;

BOOL DWC_Init(int id, const char* name, int gamecode, DWCAllocExFunc alloc, DWCFreeFunc free) {
OSRegisterVersion("<< RVL_SDK - DWCDL \trelease build: Apr 22 2010 18:57:59 (0x4302_162) >>");
DWCi_SetMemFunc(alloc, free);
DWC_SetReportLevel(-1);
DWC_Printf(8, "================================\n");
DWC_Printf(8, "- %s\n", "2_1_14");
DWC_Printf(8, "--------------------------------\n");

if (id != 1) {
DWC_Printf(8, "\n");
DWC_Printf(8, "********************************\n");
DWC_Printf(8, "*YOU ARE USING THE DEBUG SERVER*\n");
DWC_Printf(8, "********************************\n");
DWC_Printf(8, "*\n");
DWC_Printf(8, "* Please note that you need to\n");
DWC_Printf(8, "* switch it to the RELEASE\n");
DWC_Printf(8, "* server with your FINALROM!\n");
DWC_Printf(8, "*\n");
DWC_Printf(8, "*******************************\n");
DWC_Printf(8, "\n");
}

if (gamecode == 0x4E54524A) { // NTRJ
DWC_Printf(8, "\n");
DWC_Printf(8, "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n");
DWC_Printf(8, "x IS THIS DEMO? x\n");
DWC_Printf(8, "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n");
DWC_Printf(8, "x\n");
DWC_Printf(8, "x You are using the gameCode for\n");
DWC_Printf(8, "x demos. It is not allowed\n");
DWC_Printf(8, "x using this gameCode except\n");
DWC_Printf(8, "x in demos and testing.\n");
DWC_Printf(8, "x\n");
DWC_Printf(8, "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n");
DWC_Printf(8, "\n");
}

if (name != NULL && !strcmp(name, "dwctest")) {
DWC_Printf(8, "\n");
DWC_Printf(8, "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n");
DWC_Printf(8, "x IS THIS DEMO? x\n");
DWC_Printf(8, "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n");
DWC_Printf(8, "x\n");
DWC_Printf(8, "x You are using the gameName for\n");
DWC_Printf(8, "x demos. It is not allowed\n");
DWC_Printf(8, "x using this gameName except\n");
DWC_Printf(8, "x in demos and testing.\n");
DWC_Printf(8, "x\n");
DWC_Printf(8, "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n");
DWC_Printf(8, "\n");
}

if (!DWCi_Auth_InitInterface(id)) {
DWC_Printf(8, "Failed to initialize auth interface.\n");
return -1;
} else {
dwci_gamecode = gamecode;
s_initialized = TRUE;
DWCi_Np_GetConsoleId();
return FALSE;
}
}

void DWC_Shutdown(void) {
s_initialized = FALSE;
}
13 changes: 13 additions & 0 deletions src/sdk/DWC/dwc_common/dwc_init.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#pragma once
#ifdef __cplusplus
extern "C" {
#endif

#include "dwc_common/dwc_memfunc.h"

BOOL DWC_Init(int id, const char* name, int gamecode, DWCAllocExFunc alloc, DWCFreeFunc free);
void DWC_Shutdown(void);

#ifdef __cplusplus
}
#endif
56 changes: 56 additions & 0 deletions src/sdk/DWC/dwc_common/dwc_memfunc.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#include "dwc_memfunc.h"
#include "dwc_report.h"

static DWCFreeFunc s_free = NULL;
static DWCAllocExFunc s_alloc = NULL;

void DWCi_SetMemFunc(DWCAllocExFunc alloc, DWCFreeFunc free) {
s_alloc = alloc;
s_free = free;
}

void* DWC_Alloc(int id, size_t size) {
void* mem = (*s_alloc)(id, size + 0x20, 0x20);
void* mem2;
if (mem == NULL) {
DWC_Printf(
8,
"Failed to alloc memory. Original requested size: %d, Required size: %d, align: %d.\n",
size,
size + 0x20,
0x20
);
mem2 = NULL;
} else {
mem2 = (void*)((int)mem + 0x20);
*(u32*)mem = 0x4457434d;
((u32*)mem)[1] = size;
}
return mem2;
}

void* DWC_AllocEx(int id, size_t size, int alignment) {
void* mem = (*s_alloc)(id, size + 0x20, alignment);
void* mem2;
if (mem == NULL) {
DWC_Printf(
8,
"Failed to alloc memory. Original requested size: %d, Required size: %d, align: %d.\n",
size,
size + 0x20,
alignment
);
return NULL;
} else {
*(u32*)mem = 0x4457434d; // DWCM
((u32*)mem)[1] = size;
mem = (void*)((int)mem + 0x20);
}
return mem;
}

void DWC_Free(int id, void* mem, int alignment) {
if (mem != NULL) {
(*s_free)(id, (void*)((int)mem - 0x20), alignment);
}
}
11 changes: 11 additions & 0 deletions src/sdk/DWC/dwc_common/dwc_memfunc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once
#include <types.h>

typedef void *(*DWCAllocFunc)(int, size_t);
typedef void *(*DWCAllocExFunc)(int, size_t, int);
typedef void (*DWCFreeFunc)(int, void*, int);

void DWCi_SetMemFunc(DWCAllocExFunc alloc, DWCFreeFunc free);
void* DWC_Alloc(int, size_t);
void* DWC_AllocEx(int, size_t, int);
void DWC_Free(int, void*, int);
43 changes: 43 additions & 0 deletions src/sdk/DWC/dwc_common/dwc_report.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include "dwc_report.h"
#include "types.h"
#include <revolution/os/OSError.h>
#include <stdarg.h>

static u32 sReportLevel = 0;

void DWC_SetReportLevel(int level) {
sReportLevel = level;
}

void DWC_Printf(int id, const char* format, ...) {
va_list args;
if ((id & sReportLevel) == 0) return;
switch (id) {
case 0x1: OSReport("DWC_INFO :"); break;
case 0x2: OSReport("++DWC_ERROR :"); break;
case 0x4: OSReport("DWC_DEBUG :"); break;
case 0x8: OSReport("DWC_WARN :"); break;
case 0x10: OSReport("DWC_ACHECK :"); break;
case 0x20: OSReport("DWC_LOGIN :"); break;
case 0x40: OSReport("DWC_MATCH_NN :"); break;
case 0x80: OSReport("DWC_MATCH_GT2:"); break;
case 0x100: OSReport("DWC_TRANSPORT:"); break;
case 0x200: OSReport("DWC_QR2_REQ :"); break;
case 0x400: OSReport("DWC_SB_UPDATE:"); break;
case 0x8000:OSReport("DWC_SEND :"); break;
case 0x10000: OSReport("DWC_RECV :"); break;
case 0x20000: OSReport("DWC_UPDATE_SV:"); break;
case 0x40000: OSReport("DWC_CONNECTINET:"); break;
case 0x1000000: OSReport("DWC_AUTH :"); break;
case 0x2000000: OSReport("DWC_AC :"); break;
case 0x4000000: OSReport("DWC_BM :"); break;
case 0x8000000: OSReport("DWC_UTIL :"); break;
case 0x10000000:OSReport("DWC_OPTION_CF:"); break;
case 0x20000000:OSReport("DWC_OPTION_CONNTEST:"); break;
case 0x80000000:OSReport("DWC_GAMESPY :"); break;

default: OSReport("DWC_UNKNOWN :"); break;
}
va_start(args, format);
OSVReport(format, args);
}
11 changes: 11 additions & 0 deletions src/sdk/DWC/dwc_common/dwc_report.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once
#ifdef __cplusplus
extern "C" {
#endif

void DWC_SetReportLevel(int level);
void DWC_Printf(int id, const char* format, ...);

#ifdef __cplusplus
}
#endif
11 changes: 11 additions & 0 deletions src/sdk/DWC/dwc_nonport/dwc_nonport.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#include "types.h"

u64 DWCi_Np_GetConsoleId(void);

#ifdef __cplusplus
}
#endif
18 changes: 18 additions & 0 deletions src/sdk/DWC/dwcsec_auth/dwc_auth_interface.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#pragma once
#ifdef __cplusplus
extern "C" {
#endif

#include "dwc_common/dwc_memfunc.h"

int DWCi_Auth_InitInterface(int id);
int DWCi_Auth_StartAuthentication(const char*, const char*, u64, DWCAllocFunc, DWCFreeFunc);
void DWCi_Auth_AbortAuthentication(void);
void DWCi_Auth_ProcessAuthentication(void);
int DWCi_Auth_GetErrorCode(void);
int DWCi_Auth_IsFinished(void);
int DWCi_Auth_IsSucceeded(void);

#ifdef __cplusplus
}
#endif
Loading

0 comments on commit f69a504

Please sign in to comment.