diff --git a/src/libui_sdl/LAN_Socket.cpp b/src/libui_sdl/LAN_Socket.cpp index 45c5c5b7..fdb74215 100644 --- a/src/libui_sdl/LAN_Socket.cpp +++ b/src/libui_sdl/LAN_Socket.cpp @@ -25,6 +25,26 @@ #include "LAN_Socket.h" #include "../Config.h" +#ifdef __WIN32__ + #include + #include + #define socket_t SOCKET + #define sockaddr_t SOCKADDR +#else + #include + #include + #include + #include + #include + #define socket_t int + #define sockaddr_t struct sockaddr + #define closesocket close +#endif + +#ifndef INVALID_SOCKET +#define INVALID_SOCKET (socket_t)-1 +#endif + namespace LAN_Socket { diff --git a/src/libui_sdl/Platform.cpp b/src/libui_sdl/Platform.cpp index 5cbb1425..2c467ac8 100644 --- a/src/libui_sdl/Platform.cpp +++ b/src/libui_sdl/Platform.cpp @@ -22,7 +22,8 @@ #include #include "../Platform.h" #include "../Config.h" -#include "LAN.h" +#include "LAN_Socket.h" +#include "LAN_PCap.h" #ifdef __WIN32__ #include @@ -261,23 +262,43 @@ int MP_RecvPacket(u8* data, bool block) bool LAN_Init() { - if (!LAN::Init()) return false; + if (Config::DirectLAN) + { + if (!LAN_PCap::Init()) + return false; + } + else + { + if (!LAN_Socket::Init()) + return false; + } + return true; } void LAN_DeInit() { - LAN::DeInit(); + // checkme. blarg + if (Config::DirectLAN) + LAN_PCap::DeInit(); + else + LAN_Socket::DeInit(); } int LAN_SendPacket(u8* data, int len) { - return LAN::SendPacket(data, len); + if (Config::DirectLAN) + return LAN_PCap::SendPacket(data, len); + else + return LAN_Socket::SendPacket(data, len); } int LAN_RecvPacket(u8* data) { - return LAN::RecvPacket(data); + if (Config::DirectLAN) + return LAN_PCap::RecvPacket(data); + else + return LAN_Socket::RecvPacket(data); } diff --git a/src/libui_sdl/main.cpp b/src/libui_sdl/main.cpp index f65b9d19..fcc0dd3d 100644 --- a/src/libui_sdl/main.cpp +++ b/src/libui_sdl/main.cpp @@ -1683,7 +1683,7 @@ void ApplyNewSettings(int type) EmuRunning = prevstatus; } -u16 zogg(u16 val) { return (val>>8)|(val<<8);} + int main(int argc, char** argv) { srand(time(NULL)); @@ -1691,61 +1691,6 @@ int main(int argc, char** argv) printf("melonDS " MELONDS_VERSION "\n"); printf(MELONDS_URL "\n"); - { - /*u8 shit[] = - { - 0x84, 0x7A, 0x88, 0x1E, 0x8D, 0x1E, 0x34, 0x02, 0x86, 0xC5, 0x45, 0x2C, 0x08, 0x00, 0x45, 0x00, - 0x00, 0x28, 0x12, 0x00, 0x00, 0x00, 0x80, 0x06, 0x37, 0x8D, 0xC0, 0xA8, 0x06, 0x5E, 0xA3, 0xAC, - 0x86, 0x90, 0x9D, 0xC5, 0x14, 0x46, 0xF9, 0xE0, 0x5B, 0x65, 0x00, 0x00, 0x00, 0x00, 0x50, 0x02, - 0x05, 0x78, 0x00, 0x00, 0x00, 0x00, 0x03, 0x69, 0x72, 0x63, 0x07, 0x67, 0x62, 0x61, 0x74, 0x65, - 0x6D, 0x70, 0x03, 0x6E - };*/ - u8 shit[] = - { - 0x00, 0xAB, 0x33, 0x28, 0x99, 0x44, 0x00, 0x09, 0xBF, 0x53, 0xC4, 0x49, 0x08, 0x00, 0x45, 0x00, - 0x00, 0x28, 0x7E, 0x00, 0x00, 0x00, 0x80, 0x06, 0x48, 0x43, 0x0A, 0x40, 0x40, 0x10, 0xA3, 0xAC, - 0x86, 0x90, 0x9C, 0x99, 0x14, 0x46, 0x31, 0x2F, 0x08, 0x59, 0x00, 0x00, 0x00, 0x00, 0x50, 0x02, - 0x05, 0x78, 0x00, 0x00, 0x00, 0x00, 0x03, 0x69, 0x72, 0x63, 0x07, 0x67, 0x62, 0x61, 0x74, 0x65, - 0x6D, 0x70, 0x03, 0x6E - }; - // 4B76 (B489) - u32 len=0x44; - u8* ipheader = &shit[0xE]; - u8* protoheader = &shit[0x22]; - u32 tcplen = 0x14;//len-0x22; - - // TCP checksum - u32 tmp = 0; - *(u16*)&protoheader[16] = 0; - tmp += zogg(*(u16*)&ipheader[12]); - printf("%04X %04X\n", zogg(*(u16*)&ipheader[12]), tmp); - tmp += zogg(*(u16*)&ipheader[14]); - printf("%04X %04X\n", zogg(*(u16*)&ipheader[14]), tmp); - tmp += zogg(*(u16*)&ipheader[16]); - printf("%04X %04X\n", zogg(*(u16*)&ipheader[16]), tmp); - tmp += zogg(*(u16*)&ipheader[18]); - printf("%04X %04X\n", zogg(*(u16*)&ipheader[18]), tmp); - tmp += zogg(0x0600); - printf("%04X %04X\n", zogg(0x600), tmp); - tmp += tcplen; - printf("%04X %04X\n", tcplen, tmp); - for (u8* i = protoheader; i < &protoheader[tcplen-1]; i += 2) - { - tmp += zogg(*(u16*)i); - printf("plarff: %d (%d) -> %04X %04X\n", - (u32)(i-protoheader), (u32)(i-&shit[0]), - zogg(*(u16*)i), tmp); - } - if (tcplen & 1) tmp += (protoheader[tcplen-1] << 8); - printf("tmp1=%04X\n", tmp); - while (tmp >> 16) - tmp = (tmp & 0xFFFF) + (tmp >> 16); - printf("tmp2=%04X\n", tmp); - tmp ^= 0xFFFF; - printf("chk = %04X\n", (tmp)); - printf("expected = B1D5, bad = 2E8C\n"); - } - if (argc > 0 && strlen(argv[0]) > 0) { int len = strlen(argv[0]);