mirror of
https://github.com/tangerineturtle1/NX2navi.git
synced 2026-11-16 07:31:06 -04:00
Up to four players, each in their own game and save, meet in a room. Rooms are Steam lobbies and the games talk through Steam's networking, so nobody forwards a port and nobody runs a server. The game signs in to Steam as its test app (480), so Steam shows the player as playing Spacewar. Off by default; the menu has a Co-op tab with Create a room, Join a room by its ID, Invite a friend, the players, chat and Leave, in English, Russian, Brazilian Portuguese and Simplified Chinese. runtime/steam.c loads steam_api64.dll from beside the exe at run time and declares the C functions it calls itself; nothing of the Steamworks SDK is in the repository, and a player copies the file from a Steam game they have. runtime/coop.c is the room: the lobby's owner is the host, lets games of the same protocol and game build in and lists them, and every game takes positions, chat and progress only from the players on that list. runtime/coop_game.c reads Link from the Player actor and shares progress, items, songs and quest items through the game's own flag routines, each value only ever raised; small keys, rupees, ammunition and hearts stay each player's own, and the save is copied to coop-backup before anything of a room reaches it. The other players show as a name with a distance where their Link stands, projected with the upscaler's camera. One Steam account cannot be in a lobby twice, and this PC has not the memory for two games, so the room and the game side were run with one game and tests/coop_peer.py as the second player over runtime/coop_local.c, a stand-in for Steam on 127.0.0.1 that only the environment turns on: the peer was let in, saw the game's Link in Hyrule Field, chat went both ways, the save was copied, one flag the save lacked was set and a flag the game does not share was refused. On Steam itself one game signed in as app 480, made a room, showed its ID and the player's Steam name on the Co-op tab and left. Not run: two Steam accounts in one room, an invite, a join by room ID over Steam, a host that leaves, a removal, and the menu's text probe on this build. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
31 lines
1.5 KiB
C
31 lines
1.5 KiB
C
// What co-op (coop.c) needs from the network under it: Steam (steam.c), or the stand-in for tests of two games on one
|
|
// PC (coop_local.c), which one Steam account cannot do. The functions are steam.h's, with its events.
|
|
#pragma once
|
|
|
|
#include "steam.h"
|
|
|
|
typedef struct {
|
|
int (*start)(char *why, size_t cap, int *which);
|
|
void (*stop)(void);
|
|
uint64_t (*self)(void);
|
|
void (*name_of)(uint64_t id, char *out, size_t cap);
|
|
int (*room_create)(int max_players);
|
|
int (*room_join)(uint64_t room);
|
|
void (*room_leave)(void);
|
|
uint64_t (*room)(void);
|
|
uint64_t (*room_owner)(void);
|
|
int (*room_members)(uint64_t *out, int max);
|
|
int (*room_set)(const char *key, const char *value);
|
|
void (*room_get)(const char *key, char *out, size_t cap);
|
|
int (*send)(uint64_t to, const void *data, size_t n, int reliable);
|
|
void (*pump)(void (*on)(const SteamEvent *e, void *user), void *user);
|
|
} CoopNet;
|
|
|
|
// The stand-in: NX2NAVI_COOP_LOCAL=<port> in the environment (never from nx2navi.ini) makes this game the player
|
|
// whose id is that UDP port on 127.0.0.1; the room it makes has that number, and another game joins it with
|
|
// NX2NAVI_COOP_LOCAL_JOIN=<that port>. No Steam, no room ids, no invites.
|
|
extern const CoopNet coop_net_local;
|
|
int coop_local_wanted(void); // the variable is set
|
|
uint64_t coop_local_join(void); // the room NX2NAVI_COOP_LOCAL_JOIN names, 0 none
|
|
int coop_local_makes(void); // NX2NAVI_COOP_LOCAL_MAKE=1: this game makes its room at once
|