Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
shutterbug2000 committed Aug 5, 2023
0 parents commit 7f67917
Show file tree
Hide file tree
Showing 10 changed files with 1,060 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# https://EditorConfig.org

root = true

[*]
end_of_line = lf
insert_final_newline = true

indent_style = space
indent_size = 4

[Makefile]
indent_style = tab
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.vscode/
.idea/
/build
*.elf
*.wps
certs/
8 changes: 8 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM ghcr.io/wiiu-env/devkitppc:20230417

COPY --from=wiiuenv/libkernel:20220724 /artifacts $DEVKITPRO
COPY --from=wiiuenv/libmocha:20220903 /artifacts $DEVKITPRO
COPY --from=wiiuenv/wiiupluginsystem:20230126 /artifacts $DEVKITPRO

WORKDIR /app
CMD make -f Makefile -j$(nproc)
674 changes: 674 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

143 changes: 143 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
#-------------------------------------------------------------------------------
.SUFFIXES:
#-------------------------------------------------------------------------------

ifeq ($(strip $(DEVKITPRO)),)
$(error "Please set DEVKITPRO in your environment. export DEVKITPRO=<path to>/devkitpro")
endif

TOPDIR ?= $(CURDIR)

include $(DEVKITPRO)/wups/share/wups_rules

WUT_ROOT := $(DEVKITPRO)/wut
WUMS_ROOT := $(DEVKITPRO)/wums
#-------------------------------------------------------------------------------
# TARGET is the name of the output
# BUILD is the directory where object files & intermediate files will be placed
# SOURCES is a list of directories containing source code
# DATA is a list of directories containing data files
# INCLUDES is a list of directories containing header files
#-------------------------------------------------------------------------------
TARGET := HaltFix
BUILD := build
SOURCES := src src/utils
DATA := data
INCLUDES := src

#-------------------------------------------------------------------------------
# options for code generation
#-------------------------------------------------------------------------------
CFLAGS := -g -Wall -O2 -ffunction-sections \
$(MACHDEP)

CFLAGS += $(INCLUDE) -D__WIIU__ -D__WUT__ -D__WUPS__

CXXFLAGS := $(CFLAGS)

ASFLAGS := -g $(ARCH)
LDFLAGS = -g $(ARCH) $(RPXSPECS) -Wl,-Map,$(notdir $*.map)

LDFLAGS += -T$(WUMS_ROOT)/share/libkernel.ld $(WUPSSPECS)

LIBS := -lwups -lmocha -lkernel -lwut

#-------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level
# containing include and lib
#-------------------------------------------------------------------------------
LIBDIRS := $(PORTLIBS) $(WUMS_ROOT) $(WUPS_ROOT) $(WUT_ROOT) $(WUT_ROOT)/usr

#-------------------------------------------------------------------------------
# no real need to edit anything past this point unless you need to add additional
# rules for different file extensions
#-------------------------------------------------------------------------------
ifneq ($(BUILD),$(notdir $(CURDIR)))
#-------------------------------------------------------------------------------

export OUTPUT := $(CURDIR)/$(TARGET)
export TOPDIR := $(CURDIR)

export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
$(foreach dir,$(DATA),$(CURDIR)/$(dir))

export DEPSDIR := $(CURDIR)/$(BUILD)

CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))

#-------------------------------------------------------------------------------
# use CXX for linking C++ projects, CC for standard C
#-------------------------------------------------------------------------------
ifeq ($(strip $(CPPFILES)),)
#-------------------------------------------------------------------------------
export LD := $(CC)
#-------------------------------------------------------------------------------
else
#-------------------------------------------------------------------------------
export LD := $(CXX)
#-------------------------------------------------------------------------------
endif
#-------------------------------------------------------------------------------

export OFILES_BIN := $(addsuffix .o,$(BINFILES))
export OFILES_SRC := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
export OFILES := $(OFILES_BIN) $(OFILES_SRC)
export HFILES_BIN := $(addsuffix .h,$(subst .,_,$(BINFILES)))

export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
-I$(CURDIR)/$(BUILD)

export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)

.PHONY: $(BUILD) clean all

#-------------------------------------------------------------------------------
all: $(BUILD)

$(BUILD):
@$(shell [ ! -d $(BUILD) ] && mkdir -p $(BUILD))
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile

#-------------------------------------------------------------------------------
clean:
@echo clean ...
@rm -fr $(BUILD) $(TARGET).wps $(TARGET).elf

#-------------------------------------------------------------------------------
else
.PHONY: all

DEPENDS := $(OFILES:.o=.d)

#-------------------------------------------------------------------------------
# main targets
#-------------------------------------------------------------------------------
all : $(OUTPUT).wps

$(OUTPUT).wps : $(OUTPUT).elf
$(OUTPUT).elf : $(OFILES)

$(OFILES_SRC) : $(HFILES_BIN)

#-------------------------------------------------------------------------------
# you need a rule like this for each extension you use as binary data
#-------------------------------------------------------------------------------
%.bin.o %_bin.h : %.bin
#-------------------------------------------------------------------------------
@echo $(notdir $<)
@$(bin2o)

%.pem.o %_pem.h : %.pem
#-------------------------------------------------------------------------------
@echo $(notdir $<)
@$(bin2o)

-include $(DEPENDS)

#-------------------------------------------------------------------------------
endif
#-------------------------------------------------------------------------------
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# HaltFix
Reboots a Wii U automatically after a game crash (PPCHalt)
78 changes: 78 additions & 0 deletions main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/* Copyright 2022 Pretendo Network contributors <pretendo.network>
Copyright 2022 Ash Logan <[email protected]>
Copyright 2019 Maschell
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby
granted, provided that the above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/

#include <wups.h>
#include <utils/logger.h>
#include <coreinit/screen.h>
#include <mocha/mocha.h>

/**
Mandatory plugin information.
If not set correctly, the loader will refuse to use the plugin.
**/
WUPS_PLUGIN_NAME("HaltFix");
WUPS_PLUGIN_DESCRIPTION("Reboots the Wii U upon a game crash");
WUPS_PLUGIN_VERSION("v1.0");
WUPS_PLUGIN_AUTHOR("shutterbug2000");
WUPS_PLUGIN_LICENSE("GPL");

extern "C" {
void OSSendAppSwitchRequest(uint32_t rampid, void* args, uint32_t argsSize);
}

DECL_FUNCTION(void, PPCHalt) {
OSSendAppSwitchRequest(5,0,0); //from what I can tell, staying in the crashed process causes the reboot to fail. So I switch to something else (HOME Menu overlay)
OSScreenInit();
OSScreenEnableEx(SCREEN_TV, 1);
OSScreenEnableEx(SCREEN_DRC, 1);
uint32_t tvSize = OSScreenGetBufferSizeEx(SCREEN_TV);
OSScreenSetBufferEx(SCREEN_TV, (unsigned char*)0xf4000000);
OSScreenSetBufferEx(SCREEN_DRC, (unsigned char*)0xf4000000+tvSize);
OSScreenClearBufferEx(SCREEN_TV,0x0000ffff);
OSScreenClearBufferEx(SCREEN_DRC,0x0000ffff);
OSScreenPutFontEx(SCREEN_TV,0,0,"An error has occurred in the running game or application.\nYour Wii U console will now reboot.");
OSScreenPutFontEx(SCREEN_DRC,0,0,"An error has occurred in the running game or application.\nYour Wii U console will now reboot.");
OSScreenFlipBuffersEx(SCREEN_TV);
OSScreenFlipBuffersEx(SCREEN_DRC);
OSSleepTicks(OSMillisecondsToTicks(5000));
Mocha_IOSUCallSVC(0x74, 0, 0, 0);
return;
}

INITIALIZE_PLUGIN() {
WHBLogUdpInit();
WHBLogCafeInit();
DEBUG_FUNCTION_LINE("HaltFix loaded");

auto res = Mocha_InitLibrary();

if (res != MOCHA_RESULT_SUCCESS) {
DEBUG_FUNCTION_LINE("Mocha init failed with code %d!", res);
return;
}
}

DEINITIALIZE_PLUGIN() {
WHBLogUdpDeinit();
WHBLogCafeDeinit();
Mocha_DeInitLibrary();
}

ON_APPLICATION_START() {
}

ON_APPLICATION_ENDS() {
}

WUPS_MUST_REPLACE_FOR_PROCESS(PPCHalt, WUPS_LOADER_LIBRARY_COREINIT, PPCHalt, WUPS_FP_TARGET_PROCESS_GAME);
78 changes: 78 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/* Copyright 2022 Pretendo Network contributors <pretendo.network>
Copyright 2022 Ash Logan <[email protected]>
Copyright 2019 Maschell
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby
granted, provided that the above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/

#include <wups.h>
#include <utils/logger.h>
#include <coreinit/screen.h>
#include <mocha/mocha.h>

/**
Mandatory plugin information.
If not set correctly, the loader will refuse to use the plugin.
**/
WUPS_PLUGIN_NAME("HaltFix");
WUPS_PLUGIN_DESCRIPTION("Reboots the Wii U upon a game crash");
WUPS_PLUGIN_VERSION("v1.0");
WUPS_PLUGIN_AUTHOR("shutterbug2000");
WUPS_PLUGIN_LICENSE("ISC");

extern "C" {
void OSSendAppSwitchRequest(uint32_t rampid, void* args, uint32_t argsSize);
}

DECL_FUNCTION(void, PPCHalt) {
OSSendAppSwitchRequest(5,0,0); //from what I can tell, staying in the crashed process causes the reboot to fail. So I switch to something else (HOME Menu overlay)
OSScreenInit();
OSScreenEnableEx(SCREEN_TV, 1);
OSScreenEnableEx(SCREEN_DRC, 1);
uint32_t tvSize = OSScreenGetBufferSizeEx(SCREEN_TV);
OSScreenSetBufferEx(SCREEN_TV, (unsigned char*)0xf4000000);
OSScreenSetBufferEx(SCREEN_DRC, (unsigned char*)0xf4000000+tvSize);
OSScreenClearBufferEx(SCREEN_TV,0x0000ffff);
OSScreenClearBufferEx(SCREEN_DRC,0x0000ffff);
OSScreenPutFontEx(SCREEN_TV,0,0,"An error has occurred in the running game or application.\nYour Wii U console will now reboot.");
OSScreenPutFontEx(SCREEN_DRC,0,0,"An error has occurred in the running game or application.\nYour Wii U console will now reboot.");
OSScreenFlipBuffersEx(SCREEN_TV);
OSScreenFlipBuffersEx(SCREEN_DRC);
OSSleepTicks(OSMillisecondsToTicks(5000));
Mocha_IOSUCallSVC(0x74, 0, 0, 0);
return;
}

INITIALIZE_PLUGIN() {
WHBLogUdpInit();
WHBLogCafeInit();
DEBUG_FUNCTION_LINE("HaltFix loaded");

auto res = Mocha_InitLibrary();

if (res != MOCHA_RESULT_SUCCESS) {
DEBUG_FUNCTION_LINE("Mocha init failed with code %d!", res);
return;
}
}

DEINITIALIZE_PLUGIN() {
WHBLogUdpDeinit();
WHBLogCafeDeinit();
Mocha_DeInitLibrary();
}

ON_APPLICATION_START() {
}

ON_APPLICATION_ENDS() {
}

WUPS_MUST_REPLACE_FOR_PROCESS(PPCHalt, WUPS_LOADER_LIBRARY_COREINIT, PPCHalt, WUPS_FP_TARGET_PROCESS_GAME);
29 changes: 29 additions & 0 deletions src/utils/logger.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#pragma once

#ifdef __cplusplus
extern "C" {
#endif

#include <string.h>
#include <whb/log.h>
#include <whb/log_udp.h>
#include <whb/log_cafe.h>

#define __FILENAME_X__ (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__)
#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILENAME_X__)

#define OSFATAL_FUNCTION_LINE(FMT, ARGS...)do { \
OSFatal_printf("[%s]%s@L%04d: " FMT "",__FILENAME__,__FUNCTION__, __LINE__, ## ARGS); \
} while (0)

#define DEBUG_FUNCTION_LINE(FMT, ARGS...)do { \
WHBLogPrintf("[%23s]%30s@L%04d: " FMT "",__FILENAME__,__FUNCTION__, __LINE__, ## ARGS); \
} while (0);

#define DEBUG_FUNCTION_LINE_WRITE(FMT, ARGS...)do { \
WHBLogWritef("[%23s]%30s@L%04d: " FMT "",__FILENAME__,__FUNCTION__, __LINE__, ## ARGS); \
} while (0);

#ifdef __cplusplus
}
#endif
29 changes: 29 additions & 0 deletions utils/logger.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#pragma once

#ifdef __cplusplus
extern "C" {
#endif

#include <string.h>
#include <whb/log.h>
#include <whb/log_udp.h>
#include <whb/log_cafe.h>

#define __FILENAME_X__ (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__)
#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILENAME_X__)

#define OSFATAL_FUNCTION_LINE(FMT, ARGS...)do { \
OSFatal_printf("[%s]%s@L%04d: " FMT "",__FILENAME__,__FUNCTION__, __LINE__, ## ARGS); \
} while (0)

#define DEBUG_FUNCTION_LINE(FMT, ARGS...)do { \
WHBLogPrintf("[%23s]%30s@L%04d: " FMT "",__FILENAME__,__FUNCTION__, __LINE__, ## ARGS); \
} while (0);

#define DEBUG_FUNCTION_LINE_WRITE(FMT, ARGS...)do { \
WHBLogWritef("[%23s]%30s@L%04d: " FMT "",__FILENAME__,__FUNCTION__, __LINE__, ## ARGS); \
} while (0);

#ifdef __cplusplus
}
#endif

0 comments on commit 7f67917

Please sign in to comment.