fixor Platform.cpp

also remove debug shit that accidentally slipped in
This commit is contained in:
Arisotura 2019-03-04 22:24:28 +01:00
parent 0392f8736b
commit 720a5fbea5
3 changed files with 47 additions and 61 deletions

View File

@ -25,6 +25,26 @@
#include "LAN_Socket.h" #include "LAN_Socket.h"
#include "../Config.h" #include "../Config.h"
#ifdef __WIN32__
#include <winsock2.h>
#include <ws2tcpip.h>
#define socket_t SOCKET
#define sockaddr_t SOCKADDR
#else
#include <unistd.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <sys/select.h>
#include <sys/socket.h>
#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 namespace LAN_Socket
{ {

View File

@ -22,7 +22,8 @@
#include <SDL2/SDL.h> #include <SDL2/SDL.h>
#include "../Platform.h" #include "../Platform.h"
#include "../Config.h" #include "../Config.h"
#include "LAN.h" #include "LAN_Socket.h"
#include "LAN_PCap.h"
#ifdef __WIN32__ #ifdef __WIN32__
#include <winsock2.h> #include <winsock2.h>
@ -261,23 +262,43 @@ int MP_RecvPacket(u8* data, bool block)
bool LAN_Init() 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; return true;
} }
void LAN_DeInit() void LAN_DeInit()
{ {
LAN::DeInit(); // checkme. blarg
if (Config::DirectLAN)
LAN_PCap::DeInit();
else
LAN_Socket::DeInit();
} }
int LAN_SendPacket(u8* data, int len) 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) int LAN_RecvPacket(u8* data)
{ {
return LAN::RecvPacket(data); if (Config::DirectLAN)
return LAN_PCap::RecvPacket(data);
else
return LAN_Socket::RecvPacket(data);
} }

View File

@ -1683,7 +1683,7 @@ void ApplyNewSettings(int type)
EmuRunning = prevstatus; EmuRunning = prevstatus;
} }
u16 zogg(u16 val) { return (val>>8)|(val<<8);}
int main(int argc, char** argv) int main(int argc, char** argv)
{ {
srand(time(NULL)); srand(time(NULL));
@ -1691,61 +1691,6 @@ int main(int argc, char** argv)
printf("melonDS " MELONDS_VERSION "\n"); printf("melonDS " MELONDS_VERSION "\n");
printf(MELONDS_URL "\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) if (argc > 0 && strlen(argv[0]) > 0)
{ {
int len = strlen(argv[0]); int len = strlen(argv[0]);