Skip to content

Commit

Permalink
"network_getlasterror()"
Browse files Browse the repository at this point in the history
  • Loading branch information
Naim2000 committed Aug 23, 2024
1 parent 31b18c2 commit ca773f5
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 27 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.vscode/
build
*.dol
*.elf
Expand Down
2 changes: 2 additions & 0 deletions source/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ static MainMenuItem items[] = {
.pause = true
},


{
.name = "Reload devices",
.action = ReloadDevices,
Expand All @@ -189,6 +190,7 @@ static MainMenuItem items[] = {
.action = options
},


{
.name = "Return to the Homebrew Channel",
.action = HBC
Expand Down
35 changes: 33 additions & 2 deletions source/network.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <string.h>
#include <errno.h>
#include <ogc/lwp_watchdog.h>
#include <ogc/ipc.h>
#include <wiisocket.h>
#include <curl/curl.h>

Expand All @@ -22,7 +23,7 @@ static size_t WriteToBlob(void* buffer, size_t size, size_t nmemb, void* userp)
// If ptr is NULL, then the call is equivalent to malloc(size), for all values of size.
unsigned char* _buffer = realloc(blob->ptr, blob->size + length);
if (!_buffer) {
printf("WriteToBlob: out of memory (%zu + %zu bytes)\n", blob->size, length);
printf("WriteToBlob: out of memory (%u + %u bytes)\n", blob->size, length);
free(blob->ptr);
blob->ptr = NULL;
blob->size = 0;
Expand Down Expand Up @@ -58,6 +59,36 @@ static int xferinfo_cb(void* userp, curl_off_t dltotal, curl_off_t dlnow, curl_o
return 0;
}

int network_getlasterror(void) {
int ret;

int fd = ret = IOS_Open("/dev/net/ncd/manage", IPC_OPEN_READ);
if (ret < 0) {
printf("IOS_Open failed (%i)\n", ret);
return ret;
}

int stbuf[8] __aligned(0x20) = {};
ioctlv vecs[1] __aligned(0x20) = {
{
.data = stbuf,
.len = sizeof(stbuf),
}
};

ret = IOS_Ioctlv(fd, 0x7, 0, 1, vecs);
if (ret < 0) {
printf("NCDGetLinkStatus returned %i\n", ret);
// return ret;
}
IOS_Close(fd);

puts("NCDGetLinkStatus:");
printf("%i:%i:%i:%i:%i:%i:%i:%i\n", stbuf[0], stbuf[1], stbuf[2], stbuf[3], stbuf[4], stbuf[5], stbuf[6], stbuf[7]);

return ret;
}

int network_init() {
if ((network_up = wiisocket_get_status()) > 0)
return 0;
Expand Down Expand Up @@ -103,7 +134,7 @@ int DownloadFile(char* url, blob* blob) {

if (res != CURLE_OK) {
if (!ebuffer[0])
sprintf(ebuffer, "%s", curl_easy_strerror(res));
strcpy(ebuffer, curl_easy_strerror(res));
}

return res;
Expand Down
27 changes: 2 additions & 25 deletions source/theme.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,23 +51,6 @@ static const char* getmainSelPath(char region) {
return "/FINAL/??\?/main.sel";
}


/*
// Todo: overhaul this function
SignatureLevel SignedTheme(const void* buffer, size_t length) {
sha1 hash = {};
mbedtls_sha1_ret(buffer, length, hash);
if (!memcmp(hash, sysmenu->archive.hash, sizeof(sha1)))
return default_theme;
else if (memmem(buffer, length, wiithemer_sig, strlen(wiithemer_sig)))
return wiithemer_signed;
else
return unknown;
}
*/

// This whole signature thing is kinda weird!!!
static ThemeSignature FindSignature(void* sel_header) {
if (!strcasecmp((const char*)sel_header + 0x100, "Wii_Themer"))
Expand Down Expand Up @@ -179,18 +162,12 @@ int InstallTheme(void* buffer, size_t size, int dbpatching) {
U8Context ctx = {};
int ret;

if (memcmp(buffer, "PK", 2) == 0) {
puts("\x1b[31;1mPlease do not rename .mym files.\x1b[39m\n"
"Follow https://wii.hacks.guide/themes to properly convert it."
);
return -EINVAL;
}
else if (U8Init(buffer, &ctx) != 0) {
if (U8Init(buffer, &ctx) != 0) {
puts("U8Init() failed, is this really a theme?");
return -EINVAL;
}

const char* const testPaths[] = { "/www.arc", "/font/font.ash", "/layout/common/health.ash", "/sound/IplSound.brsar", NULL };
static const char* const testPaths[] = { "/www.arc", "/layout/common/health.ash", "/sound/IplSound.brsar", NULL };

for (int i = 0; testPaths[i]; i++) {
ret = U8OpenFile(&ctx, testPaths[i], NULL);
Expand Down

0 comments on commit ca773f5

Please sign in to comment.