diff --git a/source/banner/BannerTools.h b/source/banner/BannerTools.h index 8721d1c4..40c92609 100644 --- a/source/banner/BannerTools.h +++ b/source/banner/BannerTools.h @@ -25,7 +25,7 @@ distribution. #define BANNER_TOOLS_H_ #include -#include "gecko/gecko.h" +#include "gecko/gecko.hpp" #define MAKE_FOURCC(a, b, c, d) ((a) * (1 << 24) + (b) * (1 << 16) + (c) * (1 << 8) + (d) * (1 << 0)) diff --git a/source/banner/BannerWindow.cpp b/source/banner/BannerWindow.cpp index 6e247364..990597cb 100644 --- a/source/banner/BannerWindow.cpp +++ b/source/banner/BannerWindow.cpp @@ -17,7 +17,7 @@ #include #include "BannerWindow.hpp" #include "gx_addons.h" -#include "gecko/gecko.h" +#include "gecko/gecko.hpp" #include "loader/utils.h" #include "menu/menu.hpp" diff --git a/source/channel/banner.cpp b/source/channel/banner.cpp index 265919c6..9ebaacde 100644 --- a/source/channel/banner.cpp +++ b/source/channel/banner.cpp @@ -34,7 +34,7 @@ #include #include "banner.h" #include "MD5.h" -#include "gecko/gecko.h" +#include "gecko/gecko.hpp" #include "loader/fs.h" #include "unzip/U8Archive.h" diff --git a/source/channel/channel_launcher.cpp b/source/channel/channel_launcher.cpp index 85df3abc..f1c123ba 100644 --- a/source/channel/channel_launcher.cpp +++ b/source/channel/channel_launcher.cpp @@ -6,7 +6,7 @@ #include "channel_launcher.h" #include "booter/external_booter.hpp" -#include "gecko/gecko.h" +#include "gecko/gecko.hpp" #include "loader/disc.h" #include "loader/fs.h" #include "loader/fst.h" diff --git a/source/channel/channels.cpp b/source/channel/channels.cpp index 352c3e1a..8e0312ff 100644 --- a/source/channel/channels.cpp +++ b/source/channel/channels.cpp @@ -33,7 +33,7 @@ #include "channels.h" #include "banner.h" #include "config/config.hpp" -#include "gecko/gecko.h" +#include "gecko/gecko.hpp" #include "gui/text.hpp" #include "loader/fs.h" #include "memory/mem2.hpp" diff --git a/source/channel/nand.cpp b/source/channel/nand.cpp index 41bcf2d3..dac259c9 100644 --- a/source/channel/nand.cpp +++ b/source/channel/nand.cpp @@ -38,7 +38,7 @@ #include "nand.hpp" #include "identify.h" #include "fileOps/fileOps.h" -#include "gecko/gecko.h" +#include "gecko/gecko.hpp" #include "loader/alt_ios.h" #include "loader/cios.h" #include "loader/fs.h" diff --git a/source/config/config.cpp b/source/config/config.cpp index 2fff3af5..1591a1db 100644 --- a/source/config/config.cpp +++ b/source/config/config.cpp @@ -2,7 +2,7 @@ #include #include "config.hpp" -#include "gecko/gecko.h" +#include "gecko/gecko.hpp" #include "gui/text.hpp" static const char *g_whitespaces = " \f\n\r\t\v"; diff --git a/source/devicemounter/usbstorage.c b/source/devicemounter/usbstorage.c index f96337c2..f96fd77c 100644 --- a/source/devicemounter/usbstorage.c +++ b/source/devicemounter/usbstorage.c @@ -35,7 +35,7 @@ #include "usbstorage.h" #include "usbstorage_libogc.h" #include "usbthread.h" -#include "gecko/gecko.h" +#include "gecko/gecko.hpp" /* IOCTL commands */ #define UMS_BASE (('U'<<24)|('M'<<16)|('S'<<8)) diff --git a/source/devicemounter/usbthread.c b/source/devicemounter/usbthread.c index 079fe627..df819ded 100644 --- a/source/devicemounter/usbthread.c +++ b/source/devicemounter/usbthread.c @@ -22,7 +22,7 @@ #include "usbthread.h" #include "usbstorage.h" -#include "gecko/gecko.h" +#include "gecko/gecko.hpp" lwp_t USB_Thread = LWP_THREAD_NULL; volatile bool CheckUSB = false; diff --git a/source/fileOps/fileOps.c b/source/fileOps/fileOps.c index 5ecd9450..9f0d6625 100644 --- a/source/fileOps/fileOps.c +++ b/source/fileOps/fileOps.c @@ -18,7 +18,7 @@ en exposed s_fsop fsop structure can be used by callback to update operation sta #include #include "fileOps/fileOps.h" -#include "gecko/gecko.h" +#include "gecko/gecko.hpp" #include "loader/utils.h" #define SET(a, b) a = b; DCFlushRange(&a, sizeof(a)); diff --git a/source/gc/gc.cpp b/source/gc/gc.cpp index c240e1b1..0b6193b7 100644 --- a/source/gc/gc.cpp +++ b/source/gc/gc.cpp @@ -29,7 +29,7 @@ #include "gc/gc.hpp" #include "gui/text.hpp" #include "devicemounter/DeviceHandler.hpp" -#include "gecko/gecko.h" +#include "gecko/gecko.hpp" #include "fileOps/fileOps.h" #include "loader/utils.h" #include "loader/disc.h" diff --git a/source/gc/gcdisc.cpp b/source/gc/gcdisc.cpp index 7e2d95e3..9072666c 100644 --- a/source/gc/gcdisc.cpp +++ b/source/gc/gcdisc.cpp @@ -22,7 +22,7 @@ #include "gc.hpp" #include "gcdisc.hpp" #include "loader/gc_disc_dump.hpp" -#include "gecko/gecko.h" +#include "gecko/gecko.hpp" #include "memory/mem2.hpp" using namespace std; diff --git a/source/gecko/gecko.c b/source/gecko/gecko.cpp similarity index 79% rename from source/gecko/gecko.c rename to source/gecko/gecko.cpp index b07195b5..de313727 100644 --- a/source/gecko/gecko.c +++ b/source/gecko/gecko.cpp @@ -1,5 +1,3 @@ -//Enable the line below to always write SD log -//#define sd_write_log #include #include @@ -8,16 +6,18 @@ #include #include -#include "gecko.h" -#include "wifi_gecko.h" +#include "gecko.hpp" #include "memory/mem2.hpp" +#include "wifi_gecko.hpp" -/* init-globals */ -bool geckoinit = false; -bool textVideoInit = false; -bool bufferMessages = true; -bool WriteToSD = false; +#define GPRINTF_SIZE 256 #define SDWRITE_SIZE 1024 + +bool geckoinit = false; +bool sd_inited = false; +bool bufferMessages = true; + +char gprintfBuffer[GPRINTF_SIZE]; char sdwritebuffer[SDWRITE_SIZE]; static ssize_t __out_write(struct _reent *r __attribute__((unused)), int fd __attribute__((unused)), const char *ptr, size_t len) @@ -66,42 +66,7 @@ static void USBGeckoOutput() devoptab_list[STD_ERR] = &gecko_out; } -static void WriteToFile(const char* tmp, size_t len) -{ - if(!bufferMessages) - return; - - if((strlen(sdwritebuffer) + len) < SDWRITE_SIZE) - strcat(sdwritebuffer, tmp); - - if(WriteToSD) - { - FILE *outfile = fopen("sd:/wiiflow.log", "a"); - if(outfile) - { - fwrite(sdwritebuffer, 1, strlen(sdwritebuffer), outfile); - memset(sdwritebuffer, 0, SDWRITE_SIZE); - fclose(outfile); - } - } -} - -#define GPRINTF_SIZE 256 -static char gprintfBuffer[GPRINTF_SIZE]; -void gprintf(const char *format, ...) -{ - va_list va; - va_start(va, format); - size_t len = vsnprintf(gprintfBuffer, GPRINTF_SIZE - 1, format, va); - gprintfBuffer[GPRINTF_SIZE - 1] = '\0'; - va_end(va); - - __out_write(NULL, 0, gprintfBuffer, len); - WifiGecko_Send(gprintfBuffer, len); - WriteToFile(gprintfBuffer, len); -} - -char ascii(char s) +static char ascii(char s) { if(s < 0x20) return '.'; @@ -110,6 +75,65 @@ char ascii(char s) return s; } +static void WriteToFile(const char* tmp, size_t len) +{ + if(bufferMessages == false) + return; + + if((strlen(sdwritebuffer) + len) < SDWRITE_SIZE) + strcat(sdwritebuffer, tmp); + + if(sd_inited == false) + return; + + FILE *outfile = fopen("sd:/wiiflow.log", "a"); + if(outfile) + { + fwrite(sdwritebuffer, 1, strlen(sdwritebuffer), outfile); + memset(sdwritebuffer, 0, SDWRITE_SIZE); + fclose(outfile); + } +} + +void Gecko_Init(void) +{ + USBGeckoOutput(); + memset(sdwritebuffer, 0, SDWRITE_SIZE); + memset(gprintfBuffer, 0, GPRINTF_SIZE); + + u32 geckoattached = usb_isgeckoalive(EXI_CHANNEL_1); + if(geckoattached) + { + geckoinit = true; + usb_flush(EXI_CHANNEL_1); + const char *initstr = "USB Gecko inited.\n"; + __out_write(NULL, 0, initstr, strlen(initstr)); + } +} + +void LogToSD_SetBuffer(bool buf) +{ + bufferMessages = buf; + sd_inited = true; +} + +#ifdef __cplusplus +extern "C" +{ +#endif + +void gprintf(const char *format, ...) +{ + va_list va; + va_start(va, format); + size_t len = vsnprintf(gprintfBuffer, GPRINTF_SIZE - 1, format, va); + va_end(va); + + __out_write(NULL, 0, gprintfBuffer, len); + WiFiDebugger.Send(gprintfBuffer, len); + WriteToFile(gprintfBuffer, len); +} + void ghexdump(void *d, int len) { u8 *data; @@ -141,26 +165,6 @@ void ghexdump(void *d, int len) } } -static const char *initstr = "USB Gecko inited.\n"; -bool InitGecko() -{ - if(geckoinit) - return geckoinit; - - USBGeckoOutput(); - memset(sdwritebuffer, 0, SDWRITE_SIZE); - memset(gprintfBuffer, 0, GPRINTF_SIZE); - -#ifdef sd_write_log - WriteToSD = true; -#endif - - u32 geckoattached = usb_isgeckoalive(EXI_CHANNEL_1); - if(geckoattached) - { - geckoinit = true; - usb_flush(EXI_CHANNEL_1); - __out_write(NULL, 0, initstr, strlen(initstr)); - } - return geckoinit; +#ifdef __cplusplus } +#endif diff --git a/source/gecko/gecko.h b/source/gecko/gecko.hpp similarity index 55% rename from source/gecko/gecko.h rename to source/gecko/gecko.hpp index d42b973f..10198372 100644 --- a/source/gecko/gecko.h +++ b/source/gecko/gecko.hpp @@ -1,20 +1,18 @@ -#ifndef _GECKO_H_ -#define _GECKO_H_ +#ifndef _GECKO_HPP_ +#define _GECKO_HPP_ + +#include + +void Gecko_Init(void); +void LogToSD_SetBuffer(bool buf); #ifdef __cplusplus extern "C" { #endif -#include - -extern bool bufferMessages; -extern bool WriteToSD; - -//use this just like printf(); void gprintf(const char *format, ...); void ghexdump(void *d, int len); -bool InitGecko(); #ifdef __cplusplus } diff --git a/source/gecko/wifi_gecko.c b/source/gecko/wifi_gecko.c deleted file mode 100644 index 8b547668..00000000 --- a/source/gecko/wifi_gecko.c +++ /dev/null @@ -1,134 +0,0 @@ -/**************************************************************************** - * Copyright (C) 2010 - * by Dimok - * - * This software is provided 'as-is', without any express or implied - * warranty. In no event will the authors be held liable for any - * damages arising from the use of this software. - * - * Permission is granted to anyone to use this software for any - * purpose, including commercial applications, and to alter it and - * redistribute it freely, subject to the following restrictions: - * - * 1. The origin of this software must not be misrepresented; you - * must not claim that you wrote the original software. If you use - * this software in a product, an acknowledgment in the product - * documentation would be appreciated but is not required. - * - * 2. Altered source versions must be plainly marked as such, and - * must not be misrepresented as being the original software. - * - * 3. This notice may not be removed or altered from any source - * distribution. - * - * for WiiXplorer 2010 - ***************************************************************************/ -#include -#include -#include -#include -#include -#include -#include -#include "wifi_gecko.h" -#include "loader/utils.h" - -// set to use TCP socket instead of UDP -#define WIFI_GECKO_USE_TCP (0) - -static int connection = -1; -static int init = 0; - -const char *dest_ip = NULL; -u16 dest_port = 0; - -void WifiGecko_Init(const char *ip, const u16 port) -{ - dest_ip = ip; - dest_port = port; - init = 1; -} - -void WifiGecko_Close() -{ - if (!init) return; - - if(connection >= 0) - net_close(connection); - - connection = -1; -} - -int WifiGecko_Connect() -{ - if (!init) return -2; - - if(connection >= 0) - return connection; - - if (dest_ip == NULL || dest_port == 0) return connection; - -#if WIFI_GECKO_USE_TCP - connection = net_socket(PF_INET, SOCK_STREAM, 0); -#else - connection = net_socket(AF_INET, SOCK_DGRAM, IPPROTO_IP); -#endif - if (connection < 0) - return connection; - - struct sockaddr_in connect_addr; - memset(&connect_addr, 0, sizeof(connect_addr)); -#if WIFI_GECKO_USE_TCP - connect_addr.sin_family = PF_INET; -#else - connect_addr.sin_family = AF_INET; -#endif - connect_addr.sin_port = htons(dest_port); - inet_aton(dest_ip, &connect_addr.sin_addr); - - if(net_connect(connection, (struct sockaddr*)&connect_addr, sizeof(connect_addr)) < 0) - { - WifiGecko_Close(); - return -1; - } - - // First time connect, send hello message - char *msg = "Wiiflow WiFi Gecko output console connected\n"; - net_send(connection, msg, strlen(msg), 0); - - return connection; -} - -int WifiGecko_Send(const char * data, int datasize) -{ - if (!init) return -2; - - if(WifiGecko_Connect() < 0) - return connection; - - int ret = 0, done = 0, blocksize = 1024; - - while (done < datasize) - { - while(net_get_status() == -EBUSY); - - if(blocksize > datasize-done) - blocksize = datasize-done; - - ret = net_send(connection, data + done, blocksize, 0); - if (ret < 0) - { - WifiGecko_Close(); - return ret; - } - else if(ret == 0) - { - break; - } - - done += ret; - usleep (1000); - } - - return ret; -} diff --git a/source/gecko/wifi_gecko.cpp b/source/gecko/wifi_gecko.cpp new file mode 100644 index 00000000..62e6c685 --- /dev/null +++ b/source/gecko/wifi_gecko.cpp @@ -0,0 +1,124 @@ +/**************************************************************************** + * Copyright (C) 2010 by Dimok + * (C) 2012 by FIX94 + * + * This software is provided 'as-is', without any express or implied + * warranty. In no event will the authors be held liable for any + * damages arising from the use of this software. + * + * Permission is granted to anyone to use this software for any + * purpose, including commercial applications, and to alter it and + * redistribute it freely, subject to the following restrictions: + * + * 1. The origin of this software must not be misrepresented; you + * must not claim that you wrote the original software. If you use + * this software in a product, an acknowledgment in the product + * documentation would be appreciated but is not required. + * + * 2. Altered source versions must be plainly marked as such, and + * must not be misrepresented as being the original software. + * + * 3. This notice may not be removed or altered from any source + * distribution. + ***************************************************************************/ +#include +#include +#include +#include +#include +#include +#include "wifi_gecko.hpp" +#include "loader/utils.h" + +/* set to use TCP socket instead of UDP */ +//#define WIFI_GECKO_USE_TCP 1 + +WifiGecko WiFiDebugger; + +WifiGecko::WifiGecko() +{ + connection = -1; + inited = false; + buffer = true; + dest_ip = NULL; + dest_port = 0; + memset(wifigeckobuffer, 0, WIFIGECKO_SIZE); +} + +void WifiGecko::SetBuffer(bool buf) +{ + buffer = buf; +} + +void WifiGecko::Init(const char *ip, const u16 port) +{ + dest_ip = ip; + dest_port = port; + inited = true; +} + +void WifiGecko::Close() +{ + if(connection >= 0) + net_close(connection); + + connection = -1; + inited = false; + dest_ip = NULL; + dest_port = 0; +} + +int WifiGecko::Connect() +{ + if(inited == false) + return -2; + + if(connection != -1 || dest_ip == NULL || dest_port == 0) + return connection; + + int tmp_con = -1; + memset(&connect_addr, 0, sizeof(connect_addr)); +#ifdef WIFI_GECKO_USE_TCP + connect_addr.sin_family = PF_INET; + tmp_con = net_socket(connect_addr.sin_family, SOCK_STREAM, 0); +#else + connect_addr.sin_family = AF_INET; + tmp_con = net_socket(connect_addr.sin_family, SOCK_DGRAM, IPPROTO_IP); +#endif + if(tmp_con < 0) + return -3; + + connect_addr.sin_port = htons(dest_port); + inet_aton(dest_ip, &connect_addr.sin_addr); + + if(net_connect(tmp_con, (sockaddr*)&connect_addr, sizeof(connect_addr)) < 0) + { + Close(); + return -4; + } + connection = tmp_con; + return connection; +} + +int WifiGecko::Send(const char *data, int datasize) +{ + if(buffer == false) + return -1; + + if((strlen(wifigeckobuffer) + datasize) < WIFIGECKO_SIZE) + strcat(wifigeckobuffer, data); + + if(Connect() < 0) + return connection; + + u32 sendsize = strlen(wifigeckobuffer); + + while(net_get_status() == -EBUSY) + usleep(100); + int ret = net_send(connection, wifigeckobuffer, sendsize, 0); + if(ret < 0) + Close(); + + memset(wifigeckobuffer, 0, WIFIGECKO_SIZE); + return ret; +} diff --git a/source/gecko/wifi_gecko.h b/source/gecko/wifi_gecko.hpp similarity index 63% rename from source/gecko/wifi_gecko.h rename to source/gecko/wifi_gecko.hpp index 970d6e23..163330e3 100644 --- a/source/gecko/wifi_gecko.h +++ b/source/gecko/wifi_gecko.hpp @@ -1,6 +1,6 @@ /**************************************************************************** - * Copyright (C) 2010 - * by Dimok + * Copyright (C) 2010 by Dimok + * (C) 2012 by FIX94 * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any @@ -20,23 +20,33 @@ * * 3. This notice may not be removed or altered from any source * distribution. - * - * for WiiXplorer 2010 ***************************************************************************/ -#ifndef WIFI_GECKO_H_ -#define WIFI_GECKO_H_ +#ifndef WIFI_GECKO_HPP_ +#define WIFI_GECKO_HPP_ -#ifdef __cplusplus -extern "C" { -#endif +#include -void WifiGecko_Init(const char *ip, u16 port); -int WifiGecko_Connect(); -void WifiGecko_Close(); -int WifiGecko_Send(const char * data, int datasize); +#define WIFIGECKO_SIZE 1024 -#ifdef __cplusplus -} -#endif +class WifiGecko +{ +public: + WifiGecko(); + void Init(const char *ip, u16 port); + int Send(const char *data, int datasize); + void SetBuffer(bool buf); +private: + int Connect(); + void Close(); + + bool inited; + bool buffer; + const char *dest_ip; + u16 dest_port; + volatile int connection; + sockaddr_in connect_addr; + char wifigeckobuffer[WIFIGECKO_SIZE]; +}; +extern WifiGecko WiFiDebugger; #endif diff --git a/source/gui/GameTDB.cpp b/source/gui/GameTDB.cpp index e738caf8..ba9ca5a7 100644 --- a/source/gui/GameTDB.cpp +++ b/source/gui/GameTDB.cpp @@ -30,7 +30,7 @@ #include "defines.h" #include "text.hpp" #include "config/config.hpp" -#include "gecko/gecko.h" +#include "gecko/gecko.hpp" #include "memory/mem2.hpp" #define NAME_OFFSET_DB "gametdb_offsets.bin" #define MAXREADSIZE 1024*1024 //Cache size only for parsing the offsets: 1MB diff --git a/source/gui/WiiMovie.cpp b/source/gui/WiiMovie.cpp index 5f850a58..1526aed3 100644 --- a/source/gui/WiiMovie.cpp +++ b/source/gui/WiiMovie.cpp @@ -29,7 +29,7 @@ #include #include #include "WiiMovie.hpp" -#include "gecko/gecko.h" +#include "gecko/gecko.hpp" #define SND_BUFFERS 8 #define FRAME_BUFFERS 8 diff --git a/source/gui/coverflow.cpp b/source/gui/coverflow.cpp index 23779269..bee49e95 100644 --- a/source/gui/coverflow.cpp +++ b/source/gui/coverflow.cpp @@ -14,7 +14,7 @@ #include "lockMutex.hpp" #include "fonts.h" #include "types.h" -#include "gecko/gecko.h" +#include "gecko/gecko.hpp" #include "memory/mem2.hpp" #include "wstringEx/wstringEx.hpp" diff --git a/source/gui/fanart.cpp b/source/gui/fanart.cpp index b6208fa8..a966053b 100644 --- a/source/gui/fanart.cpp +++ b/source/gui/fanart.cpp @@ -2,7 +2,7 @@ #include "pngu.h" #include "boxmesh.hpp" #include "text.hpp" -#include "gecko/gecko.h" +#include "gecko/gecko.hpp" using namespace std; diff --git a/source/gui/pngu.c b/source/gui/pngu.c index 0ff20638..7e661db5 100644 --- a/source/gui/pngu.c +++ b/source/gui/pngu.c @@ -13,7 +13,7 @@ More info : http://frontier-dev.net #include "pngu.h" #include "png.h" -#include "gecko/gecko.h" +#include "gecko/gecko.hpp" #include "loader/utils.h" #include "memory/mem2.hpp" diff --git a/source/gui/video.cpp b/source/gui/video.cpp index 8ea2cb22..4b2d065f 100644 --- a/source/gui/video.cpp +++ b/source/gui/video.cpp @@ -6,7 +6,7 @@ #include "video.hpp" #include "pngu.h" #include "Gekko.h" -#include "gecko/gecko.h" +#include "gecko/gecko.hpp" #include "loader/utils.h" #define DEFAULT_FIFO_SIZE (256 * 1024) diff --git a/source/homebrew/homebrew.cpp b/source/homebrew/homebrew.cpp index 7d146b00..3afb2b83 100644 --- a/source/homebrew/homebrew.cpp +++ b/source/homebrew/homebrew.cpp @@ -5,7 +5,7 @@ #include #include #include -#include "gecko/gecko.h" +#include "gecko/gecko.hpp" #define EXECUTE_ADDR ((u8 *)0x92000000) #define BOOTER_ADDR ((u8 *)0x93000000) diff --git a/source/libwbfs/libwbfs_os.h b/source/libwbfs/libwbfs_os.h index f16bc562..75e55bb5 100644 --- a/source/libwbfs/libwbfs_os.h +++ b/source/libwbfs/libwbfs_os.h @@ -9,7 +9,7 @@ #include #include -#include "gecko/gecko.h" +#include "gecko/gecko.hpp" #include "loader/disc.h" #include "loader/utils.h" #include "memory/mem2.hpp" diff --git a/source/list/cache.hpp b/source/list/cache.hpp index a4860b33..07b58d15 100644 --- a/source/list/cache.hpp +++ b/source/list/cache.hpp @@ -7,7 +7,7 @@ #include #include "loader/disc.h" -//#include "gecko.h" +//#include "gecko.hpp" using namespace std; const char io[4][5] = { diff --git a/source/loader/alt_ios.cpp b/source/loader/alt_ios.cpp index e751a969..df469435 100644 --- a/source/loader/alt_ios.cpp +++ b/source/loader/alt_ios.cpp @@ -13,7 +13,7 @@ #include "devicemounter/DeviceHandler.hpp" #include "devicemounter/sdhc.h" #include "devicemounter/usbstorage.h" -#include "gecko/gecko.h" +#include "gecko/gecko.hpp" #include "memory/mem2.hpp" #include "memory/memory.h" #include "types.h" diff --git a/source/loader/cios.c b/source/loader/cios.c index 8e641203..2405080b 100644 --- a/source/loader/cios.c +++ b/source/loader/cios.c @@ -35,7 +35,7 @@ #include "nk.h" #include "fs.h" #include "mload.h" -#include "gecko/gecko.h" +#include "gecko/gecko.hpp" #include "memory/mem2.hpp" int mainIOS = 0; diff --git a/source/loader/disc.c b/source/loader/disc.c index 74a9bbce..701bae64 100644 --- a/source/loader/disc.c +++ b/source/loader/disc.c @@ -20,7 +20,7 @@ #include "cios.h" #include "devicemounter/usbstorage.h" -#include "gecko/gecko.h" +#include "gecko/gecko.hpp" #include "memory/memory.h" struct discHdr wii_hdr ATTRIBUTE_ALIGN(32); diff --git a/source/loader/frag.c b/source/loader/frag.c index 9e456738..8079c54b 100644 --- a/source/loader/frag.c +++ b/source/loader/frag.c @@ -16,7 +16,7 @@ #include "ext2_frag.h" #include "fatfile_frag.h" #include "devicemounter/usbstorage.h" -#include "gecko/gecko.h" +#include "gecko/gecko.hpp" #include "libwbfs/libwbfs.h" FragList *frag_list = NULL; diff --git a/source/loader/fs.c b/source/loader/fs.c index 75137c1b..751515f7 100644 --- a/source/loader/fs.c +++ b/source/loader/fs.c @@ -6,7 +6,7 @@ #include "fs.h" #include "utils.h" -#include "gecko/gecko.h" +#include "gecko/gecko.hpp" #include "memory/mem2.hpp" static fstats stats ATTRIBUTE_ALIGN(32); diff --git a/source/loader/fst.c b/source/loader/fst.c index eceeb90b..802d3a9b 100644 --- a/source/loader/fst.c +++ b/source/loader/fst.c @@ -28,7 +28,7 @@ #include "fst.h" #include "sys.h" -#include "gecko/gecko.h" +#include "gecko/gecko.hpp" #include "memory/mem2.hpp" #define FSTDIRTYPE 1 diff --git a/source/loader/gc_disc_dump.cpp b/source/loader/gc_disc_dump.cpp index 2cc2741b..65edaf25 100644 --- a/source/loader/gc_disc_dump.cpp +++ b/source/loader/gc_disc_dump.cpp @@ -35,7 +35,7 @@ #include "wdvd.h" #include "devicemounter/DeviceHandler.hpp" #include "fileOps/fileOps.h" -#include "gecko/gecko.h" +#include "gecko/gecko.hpp" #include "gui/Gekko.h" #include "gui/text.hpp" #include "memory/mem2.hpp" diff --git a/source/loader/mload.c b/source/loader/mload.c index 0e5e0d79..84caa7b9 100644 --- a/source/loader/mload.c +++ b/source/loader/mload.c @@ -16,7 +16,7 @@ */ #include "mload.h" -#include "gecko/gecko.h" +#include "gecko/gecko.hpp" static const char mload_fs[] ATTRIBUTE_ALIGN(32) = "/dev/mload"; diff --git a/source/loader/nk.c b/source/loader/nk.c index 2b6a2ec7..fcaca94d 100644 --- a/source/loader/nk.c +++ b/source/loader/nk.c @@ -31,7 +31,7 @@ #include "nk.h" #include "armboot.h" #include "memory/mem2.hpp" -#include "gecko/gecko.h" +#include "gecko/gecko.hpp" bool checked = false; bool neek = false; diff --git a/source/loader/playlog.c b/source/loader/playlog.c index 26714fc7..bf3b8861 100644 --- a/source/loader/playlog.c +++ b/source/loader/playlog.c @@ -12,7 +12,7 @@ #include #include #include -#include "gecko/gecko.h" +#include "gecko/gecko.hpp" #define PLAYRECPATH "/title/00000001/00000002/data/play_rec.dat" #define SECONDS_TO_2000 946684800LL diff --git a/source/loader/splits.c b/source/loader/splits.c index e93ff8fd..910e4176 100644 --- a/source/loader/splits.c +++ b/source/loader/splits.c @@ -12,7 +12,7 @@ #include #include "splits.h" -#include "gecko/gecko.h" +#include "gecko/gecko.hpp" #define off64_t off_t #define FMT_llu "%llu" diff --git a/source/loader/sys.c b/source/loader/sys.c index b7eee29a..1d89b5c2 100644 --- a/source/loader/sys.c +++ b/source/loader/sys.c @@ -13,7 +13,7 @@ #include "sys.h" #include "channel/channel_launcher.h" #include "loader/nk.h" -#include "gecko/gecko.h" +#include "gecko/gecko.hpp" #include "memory/mem2.hpp" #include "memory/memory.h" #include "wiiuse/wpad.h" diff --git a/source/loader/wbfs.c b/source/loader/wbfs.c index 533fba68..b2d5c2c5 100644 --- a/source/loader/wbfs.c +++ b/source/loader/wbfs.c @@ -21,7 +21,7 @@ #include "devicemounter/sdhc.h" #include "devicemounter/usbstorage.h" #include "libwbfs/libwbfs.h" -#include "gecko/gecko.h" +#include "gecko/gecko.hpp" #include "memory/mem2.hpp" /* Constants */ diff --git a/source/loader/wbfs_ext.c b/source/loader/wbfs_ext.c index 7ab286ff..e16911cd 100644 --- a/source/loader/wbfs_ext.c +++ b/source/loader/wbfs_ext.c @@ -21,7 +21,7 @@ #include "devicemounter/sdhc.h" #include "devicemounter/usbstorage.h" #include "fileOps/fileOps.h" -#include "gecko/gecko.h" +#include "gecko/gecko.hpp" #include "libwbfs/libwbfs.h" #define MAX_FAT_PATH 1024 diff --git a/source/loader/wdvd.c b/source/loader/wdvd.c index 4ad82931..2914cd4f 100644 --- a/source/loader/wdvd.c +++ b/source/loader/wdvd.c @@ -2,7 +2,7 @@ #include #include #include -#include "gecko/gecko.h" +#include "gecko/gecko.hpp" /* Constants */ #define IOCTL_DI_READID 0x70 diff --git a/source/loader/wip.c b/source/loader/wip.c index a7afb687..9cd3a158 100644 --- a/source/loader/wip.c +++ b/source/loader/wip.c @@ -5,7 +5,7 @@ #include #include "wip.h" -#include "gecko/gecko.h" +#include "gecko/gecko.hpp" #include "memory/mem2.hpp" static WIP_Code *CodeList = NULL; diff --git a/source/main.cpp b/source/main.cpp index 53a5abbe..6402e65b 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -6,7 +6,7 @@ #include "booter/external_booter.hpp" #include "channel/nand.hpp" #include "devicemounter/DeviceHandler.hpp" -#include "gecko/gecko.h" +#include "gecko/gecko.hpp" #include "gui/video.hpp" #include "gui/text.hpp" #include "homebrew/homebrew.h" @@ -27,7 +27,7 @@ int main(int argc, char **argv) { mainIOS = DOL_MAIN_IOS; __exception_setreload(5); - InitGecko(); //USB Gecko and SD buffer + Gecko_Init(); //USB Gecko and SD/WiFi buffer gprintf(" \nWelcome to %s!\nThis is the debug output.\n", VERSION_STRING.c_str()); m_vid.init(); // Init video diff --git a/source/memory/mem2.cpp b/source/memory/mem2.cpp index 6052ce49..a76fb0fe 100644 --- a/source/memory/mem2.cpp +++ b/source/memory/mem2.cpp @@ -5,7 +5,7 @@ #include "mem2.hpp" #include "mem2alloc.hpp" -#include "gecko/gecko.h" +#include "gecko/gecko.hpp" #include "loader/utils.h" #define MEM2_PRIORITY_SIZE 0x1000 diff --git a/source/menu/menu.cpp b/source/menu/menu.cpp index 37e5d9ef..3599b1c3 100644 --- a/source/menu/menu.cpp +++ b/source/menu/menu.cpp @@ -146,6 +146,9 @@ CMenu::CMenu() m_prevBg = NULL; m_nextBg = NULL; m_lqBg = NULL; + m_use_sd_logging = false; + m_use_wifi_gecko = false; + init_network = false; } void CMenu::init() @@ -204,15 +207,16 @@ void CMenu::init() fsop_MakeFolder(m_appDir.c_str()); /* Load/Create our wiiflow.ini */ m_cfg.load(fmt("%s/" CFG_FILENAME, m_appDir.c_str())); - /* Check if we want WiFi/SD Gecko */ - m_use_wifi_gecko = m_cfg.getBool("DEBUG", "wifi_gecko"); - if (m_cfg.getBool("GENERAL", "async_network") || has_enabled_providers() || m_use_wifi_gecko) - _reload_wifi_gecko(); - if(!WriteToSD) - { - WriteToSD = m_cfg.getBool("DEBUG", "sd_write_log", false); - bufferMessages = WriteToSD; - } + /* Check if we want WiFi Gecko */ + m_use_wifi_gecko = m_cfg.getBool("DEBUG", "wifi_gecko", false); + WiFiDebugger.SetBuffer(m_use_wifi_gecko); + /* Check if we want SD Gecko */ + m_use_sd_logging = m_cfg.getBool("DEBUG", "sd_write_log", false); + LogToSD_SetBuffer(m_use_sd_logging); + /* Init Network if wanted */ + init_network = (m_cfg.getBool("GENERAL", "async_network") || has_enabled_providers() || m_use_wifi_gecko); + if(init_network) + _netInit(); /* Check if we want a cIOS loaded */ int ForceIOS = min(m_cfg.getInt("GENERAL", "force_cios_rev", 0), 254); if(ForceIOS > 0) @@ -525,7 +529,6 @@ void CMenu::cleanup() CoverFlow.shutdown(); wiiLightOff(); - _deinitNetwork(); Close_Inputs(); LWP_MutexDestroy(m_mutex); @@ -534,6 +537,8 @@ void CMenu::cleanup() cleaned_up = true; //gprintf(" \nMemory cleaned up\n"); gprintf("MEM1_freesize(): %i\nMEM2_freesize(): %i\n", MEM1_freesize(), MEM2_freesize()); + /* Lets deinit our possible wifi gecko here */ + _deinitNetwork(); } void CMenu::_Theme_Cleanup(void) @@ -637,14 +642,13 @@ void CMenu::_Theme_Cleanup(void) theme.soundSet.clear(); } -void CMenu::_reload_wifi_gecko(void) +void CMenu::_netInit(void) { - if(m_use_wifi_gecko) - { - _initAsyncNetwork(); - while(net_get_status() == -EBUSY) - usleep(100); - } + if(!init_network) + return; + _initAsyncNetwork(); + while(net_get_status() == -EBUSY) + usleep(100); } void CMenu::_setAA(int aa) diff --git a/source/menu/menu.hpp b/source/menu/menu.hpp index 3fe153d8..8eeb9bae 100644 --- a/source/menu/menu.hpp +++ b/source/menu/menu.hpp @@ -12,7 +12,8 @@ #include "channel/channels.h" #include "cheats/gct.h" #include "devicemounter/DeviceHandler.hpp" -#include "gecko/gecko.h" +#include "gecko/gecko.hpp" +#include "gecko/wifi_gecko.hpp" #include "gui/coverflow.hpp" #include "gui/cursor.hpp" #include "gui/fanart.hpp" @@ -969,7 +970,9 @@ public: void directlaunch(const char *GameID); private: bool m_use_wifi_gecko; - void _reload_wifi_gecko(); + bool m_use_sd_logging; + bool init_network; + void _netInit(); bool _loadFile(u8 * &buffer, u32 &size, const char *path, const char *file); int _loadIOS(u8 ios, int userIOS, string id); void _launch(dir_discHdr *hdr); diff --git a/source/menu/menu_config4.cpp b/source/menu/menu_config4.cpp index e467aaa3..39aafb49 100644 --- a/source/menu/menu_config4.cpp +++ b/source/menu/menu_config4.cpp @@ -3,7 +3,6 @@ #include "defines.h" #include "channel/channels.h" #include "channel/nand.hpp" -#include "gecko/gecko.h" #include "loader/cios.h" #include "loader/nk.h" diff --git a/source/menu/menu_config_game.cpp b/source/menu/menu_config_game.cpp index 7009fc45..95d76cc2 100644 --- a/source/menu/menu_config_game.cpp +++ b/source/menu/menu_config_game.cpp @@ -1,7 +1,6 @@ #include "menu.hpp" #include "types.h" -#include "gecko/gecko.h" #include "loader/wbfs.h" #include "libwbfs/wiidisc.h" diff --git a/source/menu/menu_download.cpp b/source/menu/menu_download.cpp index 2a60bdcd..4297ecac 100644 --- a/source/menu/menu_download.cpp +++ b/source/menu/menu_download.cpp @@ -9,8 +9,6 @@ #include "lockMutex.hpp" #include "channel/nand.hpp" #include "devicemounter/usbstorage.h" -#include "gecko/gecko.h" -#include "gecko/wifi_gecko.h" #include "gui/GameTDB.hpp" #include "gui/pngu.h" #include "loader/fs.h" @@ -411,19 +409,13 @@ s32 CMenu::_networkComplete(s32 ok, void *usrData) bool wifigecko = m->m_cfg.getBool("DEBUG", "wifi_gecko", false); gprintf("NET: Network init complete, enabled wifi_gecko: %s\n", wifigecko ? "yes" : "no"); - if (wifigecko) + if(wifigecko) { - // Get ip - std::string ip = m->m_cfg.getString("DEBUG", "wifi_gecko_ip"); + const string &ip = m->m_cfg.getString("DEBUG", "wifi_gecko_ip"); u16 port = m->m_cfg.getInt("DEBUG", "wifi_gecko_port", 4405); - - if (ip.size() > 0 && port != 0) - { - gprintf("NET: WIFI Gecko to %s:%d\n", ip.c_str(), port); - WifiGecko_Init(ip.c_str(), port); - } + if(ip.size() > 0 && port != 0) + WiFiDebugger.Init(ip.c_str(), port); } - return 0; } diff --git a/source/menu/menu_error.cpp b/source/menu/menu_error.cpp index caacc737..c3c77274 100644 --- a/source/menu/menu_error.cpp +++ b/source/menu/menu_error.cpp @@ -1,6 +1,5 @@ #include "menu.hpp" -#include "gecko/gecko.h" extern const u8 error_png[]; s16 m_errorLblMessage; diff --git a/source/menu/menu_game.cpp b/source/menu/menu_game.cpp index 746f2b35..58b92252 100644 --- a/source/menu/menu_game.cpp +++ b/source/menu/menu_game.cpp @@ -19,7 +19,6 @@ #include "fileOps/fileOps.h" #include "gc/gc.hpp" #include "gc/gcdisc.hpp" -#include "gecko/gecko.h" #include "gui/WiiMovie.hpp" #include "gui/GameTDB.hpp" #include "gui/Gekko.h" @@ -951,7 +950,7 @@ int CMenu::_loadIOS(u8 gameIOS, int userIOS, string id) { if(!loadIOS(gameIOS, false)) { - _reload_wifi_gecko(); + _netInit(); error(sfmt("errgame4", L"Couldn't load IOS %i", gameIOS)); return LOAD_IOS_FAILED; } @@ -1011,7 +1010,7 @@ int CMenu::_loadIOS(u8 gameIOS, int userIOS, string id) gprintf("Reloading IOS into %d\n", gameIOS); if(!loadIOS(gameIOS, true)) { - _reload_wifi_gecko(); + _netInit(); error(sfmt("errgame4", L"Couldn't load IOS %i", gameIOS)); return LOAD_IOS_FAILED; } diff --git a/source/music/MusicPlayer.cpp b/source/music/MusicPlayer.cpp index b6eec5d7..40ccb3d7 100644 --- a/source/music/MusicPlayer.cpp +++ b/source/music/MusicPlayer.cpp @@ -20,7 +20,7 @@ #include "SoundHandler.hpp" #include "list/ListGenerator.hpp" #include "gui/text.hpp" -#include "gecko/gecko.h" +#include "gecko/gecko.hpp" #define MUSIC_DEPTH 10 Musicplayer MusicPlayer; diff --git a/source/music/SoundHandler.cpp b/source/music/SoundHandler.cpp index f8d9c82d..91f923aa 100644 --- a/source/music/SoundHandler.cpp +++ b/source/music/SoundHandler.cpp @@ -31,7 +31,7 @@ #include "WavDecoder.hpp" #include "AifDecoder.hpp" #include "BNSDecoder.hpp" -#include "gecko/gecko.h" +#include "gecko/gecko.hpp" #include "memory/mem2.hpp" SoundHandler SoundHandle; diff --git a/source/network/gcard.c b/source/network/gcard.c index f228e29c..87b1bf5c 100644 --- a/source/network/gcard.c +++ b/source/network/gcard.c @@ -4,7 +4,7 @@ #include "gcard.h" #include "http.h" #include "loader/utils.h" -#include "gecko/gecko.h" +#include "gecko/gecko.hpp" #define MAX_URL_SIZE 178 // 128 + 48 + 6 diff --git a/source/network/http.c b/source/network/http.c index 78139b98..1ba8a039 100644 --- a/source/network/http.c +++ b/source/network/http.c @@ -5,7 +5,7 @@ #include #include "http.h" -#include "gecko/gecko.h" +#include "gecko/gecko.hpp" /** * Emptyblock is a statically defined variable for functions to return if they are unable diff --git a/source/plugin/plugin.cpp b/source/plugin/plugin.cpp index 6fc12000..f2d4e60f 100644 --- a/source/plugin/plugin.cpp +++ b/source/plugin/plugin.cpp @@ -22,7 +22,7 @@ #include "plugin.hpp" #include "gui/text.hpp" -#include "gecko/gecko.h" +#include "gecko/gecko.hpp" #include "devicemounter/PartitionHandle.h" #include "devicemounter/DeviceHandler.hpp" #include "types.h" diff --git a/source/unzip/ash.cpp b/source/unzip/ash.cpp index bb74a60b..8dffd336 100644 --- a/source/unzip/ash.cpp +++ b/source/unzip/ash.cpp @@ -21,7 +21,7 @@ #include #include "ash.h" -#include "gecko/gecko.h" +#include "gecko/gecko.hpp" bool IsAshCompressed( const u8 *stuff, u32 len ) {