I'm trying to homebrew a multiplayer roguelike game, and I want local ad-hoc multiplayer, but all the uds functions I'm calling (with the exception of those that return void, and udsInit()) are returning error (1, 1015), including udsCreateNetwork, udsSetApplicationData, and udsScanBeacons. I've searched online and asked chatGPT >10 times, and I haven't found any results.
C++:
enum class NetRole {
None,
Host,
Client
};
class NetworkManager {
private:
NetRole role;
int num_tries_before_host = 2;
int num_tries = 0;
Result ret=0;
u32 con_type=0;
u32 *tmpbuf;
size_t tmpbuf_size;
u8 data_channel = 1;
udsNetworkStruct networkstruct;
udsBindContext bindctx;
udsNetworkScanInfo *networks = NULL;
udsNetworkScanInfo *network = NULL;
size_t total_networks = 0;
u32 recv_buffer_size = UDS_DEFAULT_RECVBUFSIZE;
u32 wlancommID = 0x776969;
std::string passphrase = "n3tw0rk-p455c0d3";
const char* first = passphrase.c_str();
udsConnectionType conntype = UDSCONTYPE_Client;
size_t tempbuffer_size = 0x4000/sizeof(u32);
std::vector<u32> tempbuffer;
public:
std::string retToStr(Result ret) {
return std::to_string(R_MODULE(ret)) + ", " + std::to_string(R_DESCRIPTION(ret));
}
void initAsHost() {
role = NetRole::Host;
udsGenerateDefaultNetworkStruct(&networkstruct, wlancommID, 0, 8);
addDebugText("Created network struct with the following data:");
addDebugText(std::to_string(networkstruct.wlancommID));
addDebugText(std::to_string(networkstruct.id8));
addDebugText(std::to_string(networkstruct.max_nodes));
addDebugText("Creating network with the following data:");
addDebugText(passphrase);
addDebugText(std::to_string(data_channel) + " , " + std::to_string(recv_buffer_size));
ret = udsCreateNetwork(&networkstruct, first, strlen(first) + 1, &bindctx, data_channel, recv_buffer_size);
if(R_FAILED(ret)) {
addDebugText("Failed to create network: " + std::to_string((unsigned int)ret) + " (" + retToStr(ret) + ")");
} else {
addDebugText("Created network successfully!");
}
}
void initAsClient() {
role = NetRole::Client;
}
void Init() {
u32 wifiStatus = 0;
acInit(); // init config service
ACU_GetStatus(&wifiStatus);
acExit();
if (wifiStatus != 3) {
addDebugText("Wi-Fi is OFF");
} else {
addDebugText("Wi-Fi is ON");
}
Result res = udsInit(0x3000, NULL);
if (R_FAILED(res)) {
addDebugText("udsInit failed: " + retToStr(res));
} else {
addDebugText("udsInit successful");
}
//allocate for temp buffer
tempbuffer.resize(tempbuffer_size);
for(num_tries=0; num_tries < num_tries_before_host; num_tries++) {
total_networks = 0;
std::fill(tempbuffer.begin(), tempbuffer.end(), 0);
ret = udsScanBeacons(tempbuffer.data(), tempbuffer_size, &networks, &total_networks, wlancommID, 0, NULL, false);
addDebugText("udsScanBeacons returned " + std::to_string(total_networks));
if(total_networks)break;
}
if(total_networks) {
addDebugText("Found network! Connecting...");
initAsClient();
} else {
addDebugText("No networks found. Becoming host.");
initAsHost();
}
}
void Update();
};






