Skip to content

Commit 7f67917

Browse files
Initial Commit
0 parents  commit 7f67917

File tree

10 files changed

+1060
-0
lines changed

10 files changed

+1060
-0
lines changed

.editorconfig

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# https://EditorConfig.org
2+
3+
root = true
4+
5+
[*]
6+
end_of_line = lf
7+
insert_final_newline = true
8+
9+
indent_style = space
10+
indent_size = 4
11+
12+
[Makefile]
13+
indent_style = tab

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
.vscode/
2+
.idea/
3+
/build
4+
*.elf
5+
*.wps
6+
certs/

Dockerfile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
FROM ghcr.io/wiiu-env/devkitppc:20230417
2+
3+
COPY --from=wiiuenv/libkernel:20220724 /artifacts $DEVKITPRO
4+
COPY --from=wiiuenv/libmocha:20220903 /artifacts $DEVKITPRO
5+
COPY --from=wiiuenv/wiiupluginsystem:20230126 /artifacts $DEVKITPRO
6+
7+
WORKDIR /app
8+
CMD make -f Makefile -j$(nproc)

LICENSE

Lines changed: 674 additions & 0 deletions
Large diffs are not rendered by default.

Makefile

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
#-------------------------------------------------------------------------------
2+
.SUFFIXES:
3+
#-------------------------------------------------------------------------------
4+
5+
ifeq ($(strip $(DEVKITPRO)),)
6+
$(error "Please set DEVKITPRO in your environment. export DEVKITPRO=<path to>/devkitpro")
7+
endif
8+
9+
TOPDIR ?= $(CURDIR)
10+
11+
include $(DEVKITPRO)/wups/share/wups_rules
12+
13+
WUT_ROOT := $(DEVKITPRO)/wut
14+
WUMS_ROOT := $(DEVKITPRO)/wums
15+
#-------------------------------------------------------------------------------
16+
# TARGET is the name of the output
17+
# BUILD is the directory where object files & intermediate files will be placed
18+
# SOURCES is a list of directories containing source code
19+
# DATA is a list of directories containing data files
20+
# INCLUDES is a list of directories containing header files
21+
#-------------------------------------------------------------------------------
22+
TARGET := HaltFix
23+
BUILD := build
24+
SOURCES := src src/utils
25+
DATA := data
26+
INCLUDES := src
27+
28+
#-------------------------------------------------------------------------------
29+
# options for code generation
30+
#-------------------------------------------------------------------------------
31+
CFLAGS := -g -Wall -O2 -ffunction-sections \
32+
$(MACHDEP)
33+
34+
CFLAGS += $(INCLUDE) -D__WIIU__ -D__WUT__ -D__WUPS__
35+
36+
CXXFLAGS := $(CFLAGS)
37+
38+
ASFLAGS := -g $(ARCH)
39+
LDFLAGS = -g $(ARCH) $(RPXSPECS) -Wl,-Map,$(notdir $*.map)
40+
41+
LDFLAGS += -T$(WUMS_ROOT)/share/libkernel.ld $(WUPSSPECS)
42+
43+
LIBS := -lwups -lmocha -lkernel -lwut
44+
45+
#-------------------------------------------------------------------------------
46+
# list of directories containing libraries, this must be the top level
47+
# containing include and lib
48+
#-------------------------------------------------------------------------------
49+
LIBDIRS := $(PORTLIBS) $(WUMS_ROOT) $(WUPS_ROOT) $(WUT_ROOT) $(WUT_ROOT)/usr
50+
51+
#-------------------------------------------------------------------------------
52+
# no real need to edit anything past this point unless you need to add additional
53+
# rules for different file extensions
54+
#-------------------------------------------------------------------------------
55+
ifneq ($(BUILD),$(notdir $(CURDIR)))
56+
#-------------------------------------------------------------------------------
57+
58+
export OUTPUT := $(CURDIR)/$(TARGET)
59+
export TOPDIR := $(CURDIR)
60+
61+
export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
62+
$(foreach dir,$(DATA),$(CURDIR)/$(dir))
63+
64+
export DEPSDIR := $(CURDIR)/$(BUILD)
65+
66+
CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
67+
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
68+
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
69+
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))
70+
71+
#-------------------------------------------------------------------------------
72+
# use CXX for linking C++ projects, CC for standard C
73+
#-------------------------------------------------------------------------------
74+
ifeq ($(strip $(CPPFILES)),)
75+
#-------------------------------------------------------------------------------
76+
export LD := $(CC)
77+
#-------------------------------------------------------------------------------
78+
else
79+
#-------------------------------------------------------------------------------
80+
export LD := $(CXX)
81+
#-------------------------------------------------------------------------------
82+
endif
83+
#-------------------------------------------------------------------------------
84+
85+
export OFILES_BIN := $(addsuffix .o,$(BINFILES))
86+
export OFILES_SRC := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
87+
export OFILES := $(OFILES_BIN) $(OFILES_SRC)
88+
export HFILES_BIN := $(addsuffix .h,$(subst .,_,$(BINFILES)))
89+
90+
export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
91+
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
92+
-I$(CURDIR)/$(BUILD)
93+
94+
export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)
95+
96+
.PHONY: $(BUILD) clean all
97+
98+
#-------------------------------------------------------------------------------
99+
all: $(BUILD)
100+
101+
$(BUILD):
102+
@$(shell [ ! -d $(BUILD) ] && mkdir -p $(BUILD))
103+
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile
104+
105+
#-------------------------------------------------------------------------------
106+
clean:
107+
@echo clean ...
108+
@rm -fr $(BUILD) $(TARGET).wps $(TARGET).elf
109+
110+
#-------------------------------------------------------------------------------
111+
else
112+
.PHONY: all
113+
114+
DEPENDS := $(OFILES:.o=.d)
115+
116+
#-------------------------------------------------------------------------------
117+
# main targets
118+
#-------------------------------------------------------------------------------
119+
all : $(OUTPUT).wps
120+
121+
$(OUTPUT).wps : $(OUTPUT).elf
122+
$(OUTPUT).elf : $(OFILES)
123+
124+
$(OFILES_SRC) : $(HFILES_BIN)
125+
126+
#-------------------------------------------------------------------------------
127+
# you need a rule like this for each extension you use as binary data
128+
#-------------------------------------------------------------------------------
129+
%.bin.o %_bin.h : %.bin
130+
#-------------------------------------------------------------------------------
131+
@echo $(notdir $<)
132+
@$(bin2o)
133+
134+
%.pem.o %_pem.h : %.pem
135+
#-------------------------------------------------------------------------------
136+
@echo $(notdir $<)
137+
@$(bin2o)
138+
139+
-include $(DEPENDS)
140+
141+
#-------------------------------------------------------------------------------
142+
endif
143+
#-------------------------------------------------------------------------------

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# HaltFix
2+
Reboots a Wii U automatically after a game crash (PPCHalt)

main.cpp

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/* Copyright 2022 Pretendo Network contributors <pretendo.network>
2+
Copyright 2022 Ash Logan <ash@heyquark.com>
3+
Copyright 2019 Maschell
4+
5+
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby
6+
granted, provided that the above copyright notice and this permission notice appear in all copies.
7+
8+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
9+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
10+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
11+
IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
12+
PERFORMANCE OF THIS SOFTWARE.
13+
*/
14+
15+
#include <wups.h>
16+
#include <utils/logger.h>
17+
#include <coreinit/screen.h>
18+
#include <mocha/mocha.h>
19+
20+
/**
21+
Mandatory plugin information.
22+
If not set correctly, the loader will refuse to use the plugin.
23+
**/
24+
WUPS_PLUGIN_NAME("HaltFix");
25+
WUPS_PLUGIN_DESCRIPTION("Reboots the Wii U upon a game crash");
26+
WUPS_PLUGIN_VERSION("v1.0");
27+
WUPS_PLUGIN_AUTHOR("shutterbug2000");
28+
WUPS_PLUGIN_LICENSE("GPL");
29+
30+
extern "C" {
31+
void OSSendAppSwitchRequest(uint32_t rampid, void* args, uint32_t argsSize);
32+
}
33+
34+
DECL_FUNCTION(void, PPCHalt) {
35+
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)
36+
OSScreenInit();
37+
OSScreenEnableEx(SCREEN_TV, 1);
38+
OSScreenEnableEx(SCREEN_DRC, 1);
39+
uint32_t tvSize = OSScreenGetBufferSizeEx(SCREEN_TV);
40+
OSScreenSetBufferEx(SCREEN_TV, (unsigned char*)0xf4000000);
41+
OSScreenSetBufferEx(SCREEN_DRC, (unsigned char*)0xf4000000+tvSize);
42+
OSScreenClearBufferEx(SCREEN_TV,0x0000ffff);
43+
OSScreenClearBufferEx(SCREEN_DRC,0x0000ffff);
44+
OSScreenPutFontEx(SCREEN_TV,0,0,"An error has occurred in the running game or application.\nYour Wii U console will now reboot.");
45+
OSScreenPutFontEx(SCREEN_DRC,0,0,"An error has occurred in the running game or application.\nYour Wii U console will now reboot.");
46+
OSScreenFlipBuffersEx(SCREEN_TV);
47+
OSScreenFlipBuffersEx(SCREEN_DRC);
48+
OSSleepTicks(OSMillisecondsToTicks(5000));
49+
Mocha_IOSUCallSVC(0x74, 0, 0, 0);
50+
return;
51+
}
52+
53+
INITIALIZE_PLUGIN() {
54+
WHBLogUdpInit();
55+
WHBLogCafeInit();
56+
DEBUG_FUNCTION_LINE("HaltFix loaded");
57+
58+
auto res = Mocha_InitLibrary();
59+
60+
if (res != MOCHA_RESULT_SUCCESS) {
61+
DEBUG_FUNCTION_LINE("Mocha init failed with code %d!", res);
62+
return;
63+
}
64+
}
65+
66+
DEINITIALIZE_PLUGIN() {
67+
WHBLogUdpDeinit();
68+
WHBLogCafeDeinit();
69+
Mocha_DeInitLibrary();
70+
}
71+
72+
ON_APPLICATION_START() {
73+
}
74+
75+
ON_APPLICATION_ENDS() {
76+
}
77+
78+
WUPS_MUST_REPLACE_FOR_PROCESS(PPCHalt, WUPS_LOADER_LIBRARY_COREINIT, PPCHalt, WUPS_FP_TARGET_PROCESS_GAME);

src/main.cpp

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/* Copyright 2022 Pretendo Network contributors <pretendo.network>
2+
Copyright 2022 Ash Logan <ash@heyquark.com>
3+
Copyright 2019 Maschell
4+
5+
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby
6+
granted, provided that the above copyright notice and this permission notice appear in all copies.
7+
8+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
9+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
10+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
11+
IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
12+
PERFORMANCE OF THIS SOFTWARE.
13+
*/
14+
15+
#include <wups.h>
16+
#include <utils/logger.h>
17+
#include <coreinit/screen.h>
18+
#include <mocha/mocha.h>
19+
20+
/**
21+
Mandatory plugin information.
22+
If not set correctly, the loader will refuse to use the plugin.
23+
**/
24+
WUPS_PLUGIN_NAME("HaltFix");
25+
WUPS_PLUGIN_DESCRIPTION("Reboots the Wii U upon a game crash");
26+
WUPS_PLUGIN_VERSION("v1.0");
27+
WUPS_PLUGIN_AUTHOR("shutterbug2000");
28+
WUPS_PLUGIN_LICENSE("ISC");
29+
30+
extern "C" {
31+
void OSSendAppSwitchRequest(uint32_t rampid, void* args, uint32_t argsSize);
32+
}
33+
34+
DECL_FUNCTION(void, PPCHalt) {
35+
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)
36+
OSScreenInit();
37+
OSScreenEnableEx(SCREEN_TV, 1);
38+
OSScreenEnableEx(SCREEN_DRC, 1);
39+
uint32_t tvSize = OSScreenGetBufferSizeEx(SCREEN_TV);
40+
OSScreenSetBufferEx(SCREEN_TV, (unsigned char*)0xf4000000);
41+
OSScreenSetBufferEx(SCREEN_DRC, (unsigned char*)0xf4000000+tvSize);
42+
OSScreenClearBufferEx(SCREEN_TV,0x0000ffff);
43+
OSScreenClearBufferEx(SCREEN_DRC,0x0000ffff);
44+
OSScreenPutFontEx(SCREEN_TV,0,0,"An error has occurred in the running game or application.\nYour Wii U console will now reboot.");
45+
OSScreenPutFontEx(SCREEN_DRC,0,0,"An error has occurred in the running game or application.\nYour Wii U console will now reboot.");
46+
OSScreenFlipBuffersEx(SCREEN_TV);
47+
OSScreenFlipBuffersEx(SCREEN_DRC);
48+
OSSleepTicks(OSMillisecondsToTicks(5000));
49+
Mocha_IOSUCallSVC(0x74, 0, 0, 0);
50+
return;
51+
}
52+
53+
INITIALIZE_PLUGIN() {
54+
WHBLogUdpInit();
55+
WHBLogCafeInit();
56+
DEBUG_FUNCTION_LINE("HaltFix loaded");
57+
58+
auto res = Mocha_InitLibrary();
59+
60+
if (res != MOCHA_RESULT_SUCCESS) {
61+
DEBUG_FUNCTION_LINE("Mocha init failed with code %d!", res);
62+
return;
63+
}
64+
}
65+
66+
DEINITIALIZE_PLUGIN() {
67+
WHBLogUdpDeinit();
68+
WHBLogCafeDeinit();
69+
Mocha_DeInitLibrary();
70+
}
71+
72+
ON_APPLICATION_START() {
73+
}
74+
75+
ON_APPLICATION_ENDS() {
76+
}
77+
78+
WUPS_MUST_REPLACE_FOR_PROCESS(PPCHalt, WUPS_LOADER_LIBRARY_COREINIT, PPCHalt, WUPS_FP_TARGET_PROCESS_GAME);

src/utils/logger.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#pragma once
2+
3+
#ifdef __cplusplus
4+
extern "C" {
5+
#endif
6+
7+
#include <string.h>
8+
#include <whb/log.h>
9+
#include <whb/log_udp.h>
10+
#include <whb/log_cafe.h>
11+
12+
#define __FILENAME_X__ (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__)
13+
#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILENAME_X__)
14+
15+
#define OSFATAL_FUNCTION_LINE(FMT, ARGS...)do { \
16+
OSFatal_printf("[%s]%s@L%04d: " FMT "",__FILENAME__,__FUNCTION__, __LINE__, ## ARGS); \
17+
} while (0)
18+
19+
#define DEBUG_FUNCTION_LINE(FMT, ARGS...)do { \
20+
WHBLogPrintf("[%23s]%30s@L%04d: " FMT "",__FILENAME__,__FUNCTION__, __LINE__, ## ARGS); \
21+
} while (0);
22+
23+
#define DEBUG_FUNCTION_LINE_WRITE(FMT, ARGS...)do { \
24+
WHBLogWritef("[%23s]%30s@L%04d: " FMT "",__FILENAME__,__FUNCTION__, __LINE__, ## ARGS); \
25+
} while (0);
26+
27+
#ifdef __cplusplus
28+
}
29+
#endif

utils/logger.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#pragma once
2+
3+
#ifdef __cplusplus
4+
extern "C" {
5+
#endif
6+
7+
#include <string.h>
8+
#include <whb/log.h>
9+
#include <whb/log_udp.h>
10+
#include <whb/log_cafe.h>
11+
12+
#define __FILENAME_X__ (strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__)
13+
#define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILENAME_X__)
14+
15+
#define OSFATAL_FUNCTION_LINE(FMT, ARGS...)do { \
16+
OSFatal_printf("[%s]%s@L%04d: " FMT "",__FILENAME__,__FUNCTION__, __LINE__, ## ARGS); \
17+
} while (0)
18+
19+
#define DEBUG_FUNCTION_LINE(FMT, ARGS...)do { \
20+
WHBLogPrintf("[%23s]%30s@L%04d: " FMT "",__FILENAME__,__FUNCTION__, __LINE__, ## ARGS); \
21+
} while (0);
22+
23+
#define DEBUG_FUNCTION_LINE_WRITE(FMT, ARGS...)do { \
24+
WHBLogWritef("[%23s]%30s@L%04d: " FMT "",__FILENAME__,__FUNCTION__, __LINE__, ## ARGS); \
25+
} while (0);
26+
27+
#ifdef __cplusplus
28+
}
29+
#endif

0 commit comments

Comments
 (0)