Skip to content

Commit

Permalink
Various fixes and clean up, reload application via _SYSLaunchTitleWit…
Browse files Browse the repository at this point in the history
…hStdArgsInNoSplash when loading a plugin
  • Loading branch information
Maschell committed Jan 10, 2021
1 parent d350fa8 commit 6c1607b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 49 deletions.
23 changes: 6 additions & 17 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,23 @@ WUPS_PLUGIN_LICENSE("GPL");

WUPS_USE_WUT_CRT()

TcpReceiver *thread = NULL;
TcpReceiver *thread = nullptr;

/* Entry point */
ON_APPLICATION_START(args) {
WHBLogUdpInit();
DEBUG_FUNCTION_LINE("Started wiiload thread");
DEBUG_FUNCTION_LINE("Start wiiload thread");
thread = new TcpReceiver(4299);
}

void stopThread() {
if (thread != NULL) {
if (thread != nullptr) {
delete thread;
thread = NULL;
thread = nullptr;
}
}

ON_APPLICATION_END() {
DEBUG_FUNCTION_LINE("Kill thread");
DEBUG_FUNCTION_LINE("Kill wiiload thread");
stopThread();
}

bool gDoRelaunch __attribute__((section(".data"))) = 0;

ON_VYSNC() {
// On each frame check if we want to exit.
if(gDoRelaunch){
SYSRelaunchTitle(0, NULL);
gDoRelaunch = 0;
DCFlushRange(&gDoRelaunch, sizeof(gDoRelaunch));
}
}
}
19 changes: 1 addition & 18 deletions src/main.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#ifndef _MAIN_H_
#define _MAIN_H_
#pragma once

/* Main */
#ifdef __cplusplus
Expand All @@ -8,22 +7,6 @@ extern "C" {
#include <stdint.h>
#include <nsysnet/socket.h>

#define MAXPATHLEN 256

#define WIIU_EAGAIN EWOULDBLOCK
#define ENODATA 1
#define EISCONN 3
#define EWOULDBLOCK 6
#define EALREADY 10
#define EAGAIN EWOULDBLOCK
#define EINVAL 11
#define ENOMEM 18
#define EINPROGRESS 22

#define wiiu_geterrno() (socketlasterr())

//! C wrapper for our C++ functions
int Menu_Main(void);

#ifdef __cplusplus
}
Expand Down
23 changes: 9 additions & 14 deletions src/utils/TcpReceiver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <sysapp/launch.h>

#include <coreinit/dynload.h>
#include <coreinit/title.h>

#include <coreinit/messagequeue.h>
#include <coreinit/ios.h>
Expand Down Expand Up @@ -99,13 +100,6 @@ void TcpReceiver::executeThread() {
socketclose(serverSocket);
}

typedef struct __attribute((packed)) {
uint32_t command;
uint32_t target;
uint32_t filesize;
uint32_t fileoffset;
char path[256];
} LOAD_REQUEST;

extern bool gDoRelaunch;
int32_t TcpReceiver::loadToMemory(int32_t clientSocket, uint32_t ipAddress) {
Expand Down Expand Up @@ -251,8 +245,8 @@ int32_t TcpReceiver::loadToMemory(int32_t clientSocket, uint32_t ipAddress) {

finalList.push_back(newContainer.value());
for (auto &plugin : oldPlugins) {
if (plugin.metaInformation.getName().compare(newContainer->metaInformation.getName()) == 0 &&
plugin.metaInformation.getAuthor().compare(newContainer->metaInformation.getAuthor()) == 0
if (plugin.metaInformation.getName() == newContainer->metaInformation.getName() &&
plugin.metaInformation.getAuthor() == newContainer->metaInformation.getAuthor()
) {
DEBUG_FUNCTION_LINE("Skipping duplicate");
PluginUtils::destroyPluginContainer(plugin);
Expand All @@ -270,16 +264,17 @@ int32_t TcpReceiver::loadToMemory(int32_t clientSocket, uint32_t ipAddress) {
}

if (PluginUtils::LoadAndLinkOnRestart(finalList) != 0) {
DEBUG_FUNCTION_LINE("Failed to load& link");
PluginUtils::destroyPluginContainer(finalList);
DEBUG_FUNCTION_LINE("Failed to load & link");
} else {
PluginUtils::destroyPluginContainer(finalList);
gDoRelaunch = 1;
DCFlushRange(&gDoRelaunch, sizeof(gDoRelaunch));
//gDoRelaunch = true;
//DCFlushRange(&gDoRelaunch, sizeof(gDoRelaunch));
}
PluginUtils::destroyPluginContainer(finalList);

free(loadAddress);
free(inflatedData);

_SYSLaunchTitleWithStdArgsInNoSplash(OSGetTitleID(), 0);
return fileSize;
} else {
DEBUG_FUNCTION_LINE("Failed to parse plugin");
Expand Down

0 comments on commit 6c1607b

Please sign in to comment.