wiinetsock stuff (haven't been able to test) (#41)

This commit is contained in:
First Last
2023-12-14 13:09:47 -08:00
committed by GitHub
parent 11b7f4d59d
commit a0d44ef94a
8 changed files with 607 additions and 159 deletions
+4
View File
@@ -252,6 +252,10 @@ rb3/unk_802FB548.cpp:
rb3/joypad.cpp:
.text start:0x802FF088 end:0x80303E24
rb3/wiinetworksocket.cpp:
.text start:0x80308CC0 end:0x80308DB4
.data start:0x80853C30 end:0x80853D10
rb3/unk_8030F4F0.cpp:
.text start:0x8030F4F0 end:0x80311394
+155 -155
View File
File diff suppressed because it is too large Load Diff
+3 -2
View File
@@ -267,7 +267,7 @@ config.libs = [
Object(NonMatching, "rb3/arkfile.cpp"),
Object(NonMatching, "rb3/asyncfile.cpp"),
Object(NonMatching, "rb3/asyncfilecnt.cpp"),
Object(Matching, "rb3/netstream.cpp"),
Object(NonMatching, "rb3/netstream.cpp"),
Object(Matching, "rb3/textstream.cpp"),
Object(Matching, "rb3/rand2.cpp"),
Object(NonMatching, "rb3/notetube.cpp"),
@@ -276,7 +276,8 @@ config.libs = [
Object(NonMatching, "rb3/unk_80697FC8.cpp"),
Object(NonMatching, "rb3/ogg_mem.cpp"),
Object(NonMatching, "rb3/unk_8067F5A0.cpp"),
Object(NonMatching, "rb3/hmx/object.cpp")
Object(NonMatching, "rb3/hmx/object.cpp"),
Object(NonMatching, "rb3/wiinetworksocket.cpp")
],
},
{
+355
View File
@@ -0,0 +1,355 @@
/* so.h
* by Alex Chadwick
*
* Copyright (C) 2014, Alex Chadwick
*
* 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.
*/
/* definitions of symbols inferred to exist in the so.h header file for which
* the brainslug symbol information is available. */
#ifndef _RVL_SO_H_
#define _RVL_SO_H_
#include "types.h"
typedef int so_fd_t;
typedef void *(*so_alloc_fn_t)(int category, size_t size);
typedef void (*so_free_fn_t)(int category, void *memory, size_t size);
struct so_alloc_t {
so_alloc_fn_t alloc;
so_free_fn_t free;
};
enum so_ret_t {
SO_OK = 0,
SO_EAFNOSUPPORT = -5,
SO_EAGAIN = -6,
SO_EALREADY = -7,
SO_EBUSY = -10,
SO_EINPROGRESS = -26,
SO_EINVAL = -28,
SO_EIO = -29,
SO_ENETRESET = -39,
SO_ENOENT = -45,
SO_ENOLINK = -48,
SO_ENOMEM = -49,
SO_ETIMEDOUT = -76,
SO_E112 = -112,
SO_E121 = -121,
};
enum so_af_t {
AF_INET = 2, /* internet */
};
enum so_pf_t {
PF_INET = 2, /* internet */
};
enum so_type_t {
SOCK_STREAM = 1, /* tcp */
SOCK_DGRAM = 2, /* udp */
};
/* unlike what you may have been led to believe, this parameter is ALWAYS 0. */
enum so_prot_t {
PROTO_STREAM_UDP = 0,
PROTO_DGRAM_TCP = 0,
};
struct so_addr_t {
u8 sa_len; /* total length */
u8 sa_family; /* address family */
u16 sa_port; /* port number */
u32 sa_addr; /* ip address */
};
enum so_shut_t {
SHUT_RD = 1,
SHUT_WR = 2,
SHUT_RDWR = SHUT_RD | SHUT_WR,
};
enum so_event_t {
POLLIN = 0x1, /* data available */
POLLOUT = 0x8, /* can send */
POLLERR = 0x20, /* error occurred */
POLLHUP = 0x40, /* connection closed */
POLLNVAL = 0x80, /* invalid request */
};
struct so_poll_t {
so_fd_t socket;
so_event_t mask;
so_event_t result;
};
struct so_host_t {
char *h_name; /* official name of host */
char **h_aliases; /* alias list */
u16 h_addrtype; /* host address type */
u16 h_length; /* length of address */
char **h_addr_list; /* list of addresses from name server */
};
struct so_ainfo_t {
int ai_flags;
int ai_family;
int ai_socktype;
int ai_protocol;
size_t ai_addrlen;
struct so_addr_t *ai_addr;
char *ai_canonname;
struct so_ainfo_t *ai_next;
};
enum so_lvl_t {
SOL_INTERFACE = 0xfffe,
SOL_SOCKET = 0xffff,
};
enum so_opt_t {
SO_REUSEADDR = 0x0004,
SO_SNDBUF = 0x1001,
SO_RCVBUF = 0x1002,
SO_IERROR = 0x1003,
SO_MAC = 0x1004,
SO_LINK = 0x1005,
SO_ERROR = 0x1009,
SO_IP_NUM = 0x4002,
SO_IP_TBL = 0x4003,
SO_DNS_TBL = 0xB003,
};
typedef enum so_ret_t so_ret_t;
typedef struct so_alloc_t so_alloc_t;
typedef enum so_af_t so_af_t;
typedef enum so_pf_t so_pf_t;
typedef enum so_type_t so_type_t;
typedef enum so_prot_t so_prot_t;
typedef struct so_addr_t so_addr_t;
typedef enum so_shut_t so_shut_t;
typedef enum so_event_t so_event_t;
typedef struct so_poll_t so_poll_t;
typedef struct so_host_t so_host_t;
typedef struct so_ainfo_t so_ainfo_t;
typedef enum so_lvl_t so_lvl_t;
typedef enum so_opt_t so_opt_t;
so_ret_t SOInit(so_alloc_t *alloc);
so_ret_t SOFinish(void);
static inline so_ret_t SOStartup(void);
so_ret_t SOStartupEx(int timeout);
so_ret_t SOCleanup(void);
/* These methods set errno! Our constants are wrong though, use the so_ret_t
* SO_E* ones (they're negative!) */
/* returns an so_ret_t error value (negative) on error. */
so_fd_t SOSocket(so_pf_t protocol_family, so_type_t type, so_prot_t protocol);
/* this version is used by other libraries as it suppresses logging. */
so_fd_t __SOSocket(so_pf_t protocol_family, so_type_t type, so_prot_t protocol);
so_ret_t SOClose(so_fd_t socket);
so_ret_t SOBind(so_fd_t socket, so_addr_t *addr);
so_ret_t SOConnect(so_fd_t socket, so_addr_t *addr);
static inline so_ret_t SORecvFrom(
so_fd_t socket, void *buffer, size_t buffer_size, int flags,
so_addr_t *addr);
static inline so_ret_t SORecv(
so_fd_t socket, void *buffer, size_t buffer_size, int flags);
/* this is not intended to be called directly (feel free to replace) */
so_ret_t SOiRecvFrom(
int r3, so_fd_t socket, void *buffer, size_t buffer_size, int flags,
so_addr_t *addr);
static inline so_ret_t SOSendTo(
so_fd_t socket, const void *buffer, size_t buffer_size, int flags,
const so_addr_t *addr);
static inline so_ret_t SOSend(
so_fd_t socket, const void *buffer, size_t buffer_size, int flags);
/* this is not intended to be called directly (feel free to replace) */
so_ret_t SOiSendTo(
int r3, so_fd_t socket, const void *buffer, size_t buffer_size, int flags,
const so_addr_t *addr);
/* command is either F_GETFL or F_SETFL from <fcntl.h>. */
/* realistically, there is only ever one vararg; an int but this is what the
* method does. Commonly used to set and clear O_NONBLOCK flag. */
so_ret_t SOFcntl(so_fd_t socket, int command, ...);
so_ret_t SOShutdown(so_fd_t socket, so_shut_t how);
so_ret_t SOPoll(so_poll_t *polls, int poll_count, long long timeout);
so_ret_t SOInetAtoN(const char *str, u32 *addr);
/* not reentrant or thread safe! */
const char *SOInetNtoA(const u32 *addr);
/* host IP or 0 on error. */
u32 SOGetHostID(void);
so_ret_t SOGetHostByName(const char *addr);
/* not reentrant or thread safe! */
so_ret_t SOGetAddrInfo(
const char *node, const char *service,
const so_ainfo_t *hints, so_addr_t **res);
void SOFreeAddrInfo(so_addr_t *res);
so_ret_t SOSetSockOpt(
so_fd_t socket, so_lvl_t level, so_opt_t name,
const void *data, size_t size);
so_ret_t SOGetInterfaceOpt(
so_fd_t socket, so_lvl_t level, so_opt_t name,
void *buffer, size_t buffer_size);
so_ret_t SOListen(so_fd_t socket, s32 backlog);
/*
typedef void *(*so_alloc_fn_t)(int category, size_t size);
typedef void (*so_free_fn_t)(int category, void *memory, size_t size);
struct so_alloc_t {
so_alloc_fn_t alloc;
so_free_fn_t free;
};
enum so_ret_t {
SO_OK = 0,
SO_EAFNOSUPPORT = -5,
SO_EAGAIN = -6,
SO_EALREADY = -7,
SO_EBUSY = -10,
SO_EINPROGRESS = -26,
SO_EINVAL = -28,
SO_EIO = -29,
SO_ENETRESET = -39,
SO_ENOENT = -45,
SO_ENOLINK = -48,
SO_ENOMEM = -49,
SO_ETIMEDOUT = -76,
SO_E112 = -112,
SO_E121 = -121,
};
enum so_af_t {
AF_INET = 2, // internet
};
enum so_pf_t {
PF_INET = 2, // internet
};
enum so_type_t {
SOCK_STREAM = 1, // tcp
SOCK_DGRAM = 2, // udp
};
// unlike what you may have been led to believe, this parameter is ALWAYS 0.
enum so_prot_t {
PROTO_STREAM_UDP = 0,
PROTO_DGRAM_TCP = 0,
};
struct so_addr_t {
u8 sa_len; // total length
u8 sa_family; // address family
u16 sa_port; // port number
u32 sa_addr; // ip address
};
enum so_shut_t {
SHUT_RD = 1,
SHUT_WR = 2,
SHUT_RDWR = SHUT_RD | SHUT_WR,
};
enum so_event_t {
POLLIN = 0x1, // data available
POLLOUT = 0x8, // can send
POLLERR = 0x20, // error occurred
POLLHUP = 0x40, // connection closed
POLLNVAL = 0x80, // invalid request
};
struct so_poll_t {
so_fd_t socket;
so_event_t mask;
so_event_t result;
};
struct so_host_t {
char *h_name; // official name of host
char **h_aliases; // alias list
u16 h_addrtype; // host address type
u16 h_length; // length of address
char **h_addr_list; // list of addresses from name server
};
struct so_ainfo_t {
int ai_flags;
int ai_family;
int ai_socktype;
int ai_protocol;
size_t ai_addrlen;
struct so_addr_t *ai_addr;
char *ai_canonname;
struct so_ainfo_t *ai_next;
};
enum so_lvl_t {
SOL_INTERFACE = 0xfffe,
SOL_SOCKET = 0xffff,
};
enum so_opt_t {
SO_REUSEADDR = 0x0004,
SO_SNDBUF = 0x1001,
SO_RCVBUF = 0x1002,
SO_IERROR = 0x1003,
SO_MAC = 0x1004,
SO_LINK = 0x1005,
SO_ERROR = 0x1009,
SO_IP_NUM = 0x4002,
SO_IP_TBL = 0x4003,
SO_DNS_TBL = 0xB003,
};
*/
static inline so_ret_t SOStartup(void) {
return SOStartupEx(60000);
}
static inline so_ret_t SORecvFrom(
so_fd_t socket, void *buffer, size_t buffer_size, int flags,
so_addr_t *addr) {
return SOiRecvFrom(0, socket, buffer, buffer_size, flags, addr);
}
static inline so_ret_t SORecv(
so_fd_t socket, void *buffer, size_t buffer_size, int flags) {
return SOiRecvFrom(0, socket, buffer, buffer_size, flags, NULL);
}
static inline so_ret_t SOSendTo(
so_fd_t socket, const void *buffer, size_t buffer_size, int flags,
const so_addr_t *addr) {
return SOiSendTo(0, socket, buffer, buffer_size, flags, addr);
}
static inline so_ret_t SOSend(
so_fd_t socket, const void *buffer, size_t buffer_size, int flags) {
return SOiSendTo(0, socket, buffer, buffer_size, flags, NULL);
}
#endif /* _RVL_SO_H_ */
+3 -2
View File
@@ -6,6 +6,7 @@
#include "textstream.hpp"
#include "hmx/object.hpp"
namespace Hmx {class Object;}
class DataArray; // forward declaration
class DataNode; // also a forward declaration
class DataArrayPtr; // yet another forward declaration
@@ -29,7 +30,7 @@ enum DataType { /* differs from serialized, for... some reason; i trusted ghidra
kDataVariable = 2,
kDataFunc = 3,
kDataObject = 4,
kDataSymbol = 5,
kDataSymbol = 5,
kDataInt = 6,
kDataIfdef = 7,
kDataElse = 8,
@@ -147,7 +148,7 @@ public:
DataArray* FindArray(Symbol, Symbol) const; // fn_803162BC
DataArray* FindArray(Symbol, Symbol, Symbol) const; // fn_80316300
DataArray* FindArray(Symbol, const char*) const; // fn_80316358
bool FindData(Symbol, const char*&, bool) const; // fn_803163B8
bool FindData(Symbol, Symbol&, bool) const; // fn_80316414
bool FindData(Symbol, String&, bool) const; // fn_8031647C
+27
View File
@@ -0,0 +1,27 @@
#ifndef RB3_NETWORKSOCKET_HPP
#define RB3_NETWORKSOCKET_HPP
#include "types.h"
#include "revolution/rvl/so.h"
class NetworkSocket {
public:
NetworkSocket();
virtual ~NetworkSocket();
virtual bool Connect() = 0;
virtual bool Fail() = 0;
virtual bool Disconnect() = 0;
virtual bool InqBoundPort() = 0;
virtual void Listen() = 0;
virtual NetworkSocket* Accept() = 0;
virtual bool GetRemoteIP() = 0;
virtual int CanSend() = 0;
virtual int BytesAvailable() = 0;
virtual void* Send(int, uint) = 0;
virtual void* Recv(int, int) = 0;
virtual bool SendTo() = 0;
virtual bool BroadcastTo() = 0;
virtual bool RecvFrom() = 0;
virtual bool SetNoDelay() = 0;
virtual int V_Unk19();
};
#endif
+26
View File
@@ -0,0 +1,26 @@
#include "wiinetworksocket.hpp"
#include "revolution/rvl/so.h"
extern int fn_80308acc(const char*);
WiiNetworkSocket::~WiiNetworkSocket() { // 80308cc0
Disconnect();
}
bool WiiNetworkSocket::Connect(u32 a, u16 b) {
so_addr_t address;
address.sa_len = 8;
address.sa_family = 2;
address.sa_port = b;
address.sa_addr = a;
s32 ret = SOConnect(native_sock, &address);
if (ret < 0) {
if (ret == -0x1a) return true;
Failed = true;
}
return !ret;
}
void WiiNetworkSocket::Listen() {
SOListen(native_sock, 5);
}
+34
View File
@@ -0,0 +1,34 @@
#ifndef RB3_WIINETWORKSOCKET_HPP
#define RB3_WIINETWORKSOCKET_HPP
#include "types.h"
#include "networksocket.hpp"
class WiiNetworkSocket : public NetworkSocket {
public:
so_fd_t native_sock;
bool unk1;
bool Failed;
bool unk2;
bool unk3;
WiiNetworkSocket(bool);
virtual ~WiiNetworkSocket(); // 0x80308cc0
bool Connect(u32, u16); // 0x80308d34
bool Fail(); // 0x80308e84
bool Disconnect(); // 0x80308e34
bool Bind(u16); // 0x80308e8c
bool InqBoundPort(); // 0x80308f10, weird func, calls a stub with the name then returns 0
void Listen(); // 0x80308da8
WiiNetworkSocket* Accept(); // 0x80308db4
bool GetRemoteIP(); // 0x80308e28, see inqboundport
int CanSend(); // 0x80309210
int BytesAvailable(); // 0x80309080
void* Send(int, uint); // 0x80308f40
void* Recv(void*, size_t); // 0x80309110
bool SendTo(); // 0x80309020
bool BroadcastTo(); // 0x80309050
bool RecvFrom(); // 0x803091e0
bool SetNoDelay(int); // 0x80309280
int V_Unk19(); // links to fn_8077BAA0, which returns 0
};
#endif