Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
InvoxiPlayGames committed Dec 10, 2020
0 parents commit 9187150
Show file tree
Hide file tree
Showing 7 changed files with 375 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.dol
*.elf
build
21 changes: 21 additions & 0 deletions LICENCE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 InvoxiPlayGames

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
138 changes: 138 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
#---------------------------------------------------------------------------------
# Clear the implicit built in rules
#---------------------------------------------------------------------------------
.SUFFIXES:
#---------------------------------------------------------------------------------
ifeq ($(strip $(DEVKITPPC)),)
$(error "Please set DEVKITPPC in your environment. export DEVKITPPC=<path to>devkitPPC")
endif

include $(DEVKITPPC)/wii_rules

#---------------------------------------------------------------------------------
# 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
# INCLUDES is a list of directories containing extra header files
#---------------------------------------------------------------------------------
TARGET := $(notdir $(CURDIR))
BUILD := build
SOURCES := source
DATA := data
INCLUDES :=

#---------------------------------------------------------------------------------
# options for code generation
#---------------------------------------------------------------------------------

CFLAGS = -g -O2 -Wall $(MACHDEP) $(INCLUDE)
CXXFLAGS = $(CFLAGS)

LDFLAGS = -g $(MACHDEP) -Wl,-Map,$(notdir $@).map

#---------------------------------------------------------------------------------
# any extra libraries we wish to link with the project
#---------------------------------------------------------------------------------
LIBS := -lwiiuse -lbte -logc -lm

#---------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level containing
# include and lib
#---------------------------------------------------------------------------------
LIBDIRS :=

#---------------------------------------------------------------------------------
# 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 VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
$(foreach dir,$(DATA),$(CURDIR)/$(dir))

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

#---------------------------------------------------------------------------------
# automatically build a list of object files for our project
#---------------------------------------------------------------------------------
CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
sFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
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_SOURCES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(sFILES:.s=.o) $(SFILES:.S=.o)
export OFILES := $(OFILES_BIN) $(OFILES_SOURCES)

export HFILES := $(addsuffix .h,$(subst .,_,$(BINFILES)))

#---------------------------------------------------------------------------------
# build a list of include paths
#---------------------------------------------------------------------------------
export INCLUDE := $(foreach dir,$(INCLUDES), -iquote $(CURDIR)/$(dir)) \
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
-I$(CURDIR)/$(BUILD) \
-I$(LIBOGC_INC)

#---------------------------------------------------------------------------------
# build a list of library paths
#---------------------------------------------------------------------------------
export LIBPATHS := -L$(LIBOGC_LIB) $(foreach dir,$(LIBDIRS),-L$(dir)/lib)

export OUTPUT := $(CURDIR)/$(TARGET)
.PHONY: $(BUILD) clean

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

#---------------------------------------------------------------------------------
clean:
@echo clean ...
@rm -fr $(BUILD) $(OUTPUT).elf $(OUTPUT).dol

#---------------------------------------------------------------------------------
run:
wiiload $(TARGET).dol


#---------------------------------------------------------------------------------
else

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

#---------------------------------------------------------------------------------
# main targets
#---------------------------------------------------------------------------------
$(OUTPUT).dol: $(OUTPUT).elf
$(OUTPUT).elf: $(OFILES)

$(OFILES_SOURCES) : $(HFILES)

#---------------------------------------------------------------------------------
# This rule links in binary data with the .jpg extension
#---------------------------------------------------------------------------------
%.jpg.o %_jpg.h : %.jpg
#---------------------------------------------------------------------------------
@echo $(notdir $<)
$(bin2o)

-include $(DEPENDS)

#---------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# GCPadder

GCPadder is a utility that allows you to send your GameCube controller's inputs to your computer from your modded Wii, either wirelessly or using a USB Gecko. _(Performance is best on a stable ethernet connection or a USB Gecko.)_

## [Download the Windows PC Client](https://github.com/InvoxiPlayGames/GCPadder/releases/latest) - requires [ViGEmBus](https://github.com/ViGEm/ViGEmBus/releases/latest).

## How to use:

- Please make sure you have the [ViGEmBus driver](https://github.com/ViGEm/ViGEmBus/releases/latest) installed.
- If you are using Windows 7, please make sure you have the [.NET Framework 4.5.2 Runtime](https://dotnet.microsoft.com/download/dotnet-framework/net452) installed.
- If you intend on using a USB Gecko, make sure you have [.NET Framework 4.0 Runtime](https://dotnet.microsoft.com/download/dotnet-framework/net40) installed as well as 4.5.2.
- Windows 8.1 and Windows 10 should come with these runtimes pre-installed, or should offer a download if they are not.

1. Download the latest version of the [Wii Homebrew application and Windows PC client](https://github.com/InvoxiPlayGames/GCPadder/releases/latest).
2. Launch the homebrew application and press the button corresponding with the connection method you want to use. Wait until it says 'Listening on...'.
3. In the PC client, type in the IP address you see on your Wii's screen. The IP may already be filled in for you. The port is filled in automatically, in most cases there is no reason to touch this.
- If using a USB Gecko, select the USB Gecko option in the PC client.
4. Click 'Connect' on the PC client, and if all goes well, an Xbox 360 Controller will appear to applications and games running on your PC with the inputs of your GameCube controller.

## For developers:

The "protocol" used is very simple, send 0x09AD09AD to the UDP server/USB Gecko from your application, and the Wii will start reporting inputs at ~200Hz. The controller input format is shown below as a C structure:
```c
struct NETPADData {
uint16_t buttons;
int8_t stickX;
int8_t stickY;
int8_t substickX;
int8_t substickY;
uint8_t triggerL;
uint8_t triggerR;
} paddata;
```
Binary file added hbc/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions hbc/meta.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<app version="1">
<name>GCPadder</name>
<coder>InvoxiPlayGames</coder>
<version>1.0</version>
<release_date>20201210000000</release_date>
<short_description>Use GameCube controllers on PC</short_description>
<long_description>GCPadder is a utility that allows you to send your GameCube controller's inputs to your computer, either wirelessly or using a USB Gecko. (Performance is best on a stable ethernet connection or a USB Gecko.)
Read more information and download the corresponding PC application from https://github.com/InvoxiPlayGames/GCPadder

THIS IS INCOMPATIBLE WITH WIIS WITHOUT GAMECUBE PORTS. (Obviously!)</long_description>
</app>
168 changes: 168 additions & 0 deletions source/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
#include <stdio.h>
#include <stdlib.h>
#include <gccore.h>
#include <network.h>
#include <wiiuse/wpad.h>
#include <string.h>

static void *xfb = NULL;
static GXRModeObj *rmode = NULL;

u32 storedmagic = 0x0;
s8 selectedoutput = -1;

u16 netport = 0x9AD;
s32 sock;
u32 size;
struct sockaddr_in connected;

char localip[16] = {0};
char gateway[16] = {0};
char netmask[16] = {0};
int recv_buffer(void *buffer, int size) {
if (selectedoutput == 2) {
size = sizeof(connected);
return net_recvfrom(sock, buffer, size, 0, (struct sockaddr *)&connected, (u32*)&size);
} else {
return usb_recvbuffer(selectedoutput, buffer, size);
}
}
int send_buffer(void *buffer, int size) {
if (selectedoutput == 2) {
return net_sendto(sock, buffer, size, 0, (struct sockaddr *)&connected, size);
} else {
return usb_sendbuffer(selectedoutput, buffer, size);
}
}

typedef struct NETPADData NETPADData;
struct NETPADData {
u16 buttons;
s8 stickX;
s8 stickY;
s8 substickX;
s8 substickY;
u8 triggerL;
u8 triggerR;
} paddata;

struct NETPADData old;

int main(int argc, char **argv) {
VIDEO_Init();
WPAD_Init();
PAD_Init();
rmode = VIDEO_GetPreferredMode(NULL);
xfb = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));
console_init(xfb,20,20,rmode->fbWidth,rmode->xfbHeight,rmode->fbWidth*VI_DISPLAY_PIX_SZ);
VIDEO_Configure(rmode);
VIDEO_SetNextFramebuffer(xfb);
VIDEO_SetBlack(FALSE);
VIDEO_Flush();
VIDEO_WaitVSync();
if(rmode->viTVMode&VI_NON_INTERLACE) VIDEO_WaitVSync();

bool geckoA;
bool geckoB;

printf("\x1b[2;0H");
printf("GCPadder v1.0\n");
printf("-------------\n\n");
printf("Press A on GameCube Pad 1 to use the network.\n");
if ((geckoB = usb_isgeckoalive(1))) printf("Press B on GameCube Pad 1 to use USB Gecko Slot B.\n");
if ((geckoA = usb_isgeckoalive(0))) printf("Press X on GameCube Pad 1 to use USB Gecko Slot A.\n");
printf("Press START, RESET or HOME to exit\n");

while(selectedoutput == -1) {
PAD_ScanPads();
WPAD_ScanPads();
u16 pressedGC = PAD_ButtonsDown(0);
if (pressedGC & PAD_BUTTON_A) selectedoutput = 2;
if (geckoB && pressedGC & PAD_BUTTON_B) selectedoutput = 1;
if (geckoA && pressedGC & PAD_BUTTON_X) selectedoutput = 0;
if (pressedGC & PAD_BUTTON_START) exit(0);
u32 pressedRVL = WPAD_ButtonsDown(0);
if (pressedRVL & WPAD_BUTTON_HOME) exit(0);
if (pressedRVL & WPAD_CLASSIC_BUTTON_HOME) exit(0);
if (SYS_ResetButtonDown()) exit(0);
}

if (selectedoutput == 2) {
printf("Connecting to the network...\n");
s32 ret;
char localip[16] = {0};
char gateway[16] = {0};
char netmask[16] = {0};
ret = if_config(localip, netmask, gateway, TRUE, 20);
if (ret < 0) {
printf("Failed to connect to the network. Press any button to exit.\n");
while (1) {
PAD_ScanPads();
if (PAD_ButtonsDown(0) > 0) exit(0);
}
}
printf("Initialising socket...\n");
sock = net_socket(AF_INET, SOCK_DGRAM, IPPROTO_IP);
if (sock == INVALID_SOCKET) {
printf("Failed to create a socket. Press any button to exit.\n");
while (1) {
PAD_ScanPads();
if (PAD_ButtonsDown(0) > 0) exit(0);
}
}
struct sockaddr_in bind;
memset(&bind, 0, sizeof(bind));
bind.sin_family = AF_INET;
bind.sin_port = htons(netport);
bind.sin_addr.s_addr = INADDR_ANY;
ret = net_bind(sock, (struct sockaddr *)&bind, sizeof(bind));
if (ret) {
printf("Failed to bind socket. Press any button to exit.\n");
while (1) {
PAD_ScanPads();
if (PAD_ButtonsDown(0) > 0) exit(0);
}
}
printf("Listening on %s:%i...\n", localip, netport);
} else {
printf("Listening on USB Gecko Slot %c...\n", 65 + selectedoutput);
}
printf("Use the GCPadder application on your PC to connect.");
while (storedmagic != 0x09ad09ad) {
recv_buffer(&storedmagic, 4);
}
if (selectedoutput == 2) {
uint32_t ip = connected.sin_addr.s_addr;
unsigned char bytes[4];
bytes[0] = ip & 0xFF;
bytes[1] = (ip >> 8) & 0xFF;
bytes[2] = (ip >> 16) & 0xFF;
bytes[3] = (ip >> 24) & 0xFF;
printf("\rConnected to %u.%u.%u.%u:%i! \n", bytes[3], bytes[2], bytes[1], bytes[0], connected.sin_port);
} else {
printf("\rConnected! \n");
}
printf("Press RESET or HOME to exit.\n");
uint8_t loopis = 0;
while(true) {
if (SYS_ResetButtonDown()) exit(0);
WPAD_ScanPads();
u32 pressedRVL = WPAD_ButtonsDown(0);
if (pressedRVL & WPAD_BUTTON_HOME) exit(0);
if (pressedRVL & WPAD_CLASSIC_BUTTON_HOME) exit(0);
PAD_ScanPads();
paddata.buttons = PAD_ButtonsHeld(0);
paddata.stickX = PAD_StickX(0);
paddata.stickY = PAD_StickY(0);
paddata.substickX = PAD_SubStickX(0);
paddata.substickY = PAD_SubStickY(0);
paddata.triggerL = PAD_TriggerL(0);
paddata.triggerR = PAD_TriggerR(0);
if (selectedoutput < 2 || loopis == 255 || memcmp(&paddata, &old, 8) != 0) send_buffer(&paddata, sizeof(paddata));
old = paddata;
loopis++;
usleep(5000);
};

return 0;
}

0 comments on commit 9187150

Please sign in to comment.