diff --git a/Stub/DiabloUI/selconn.cpp b/Stub/DiabloUI/selconn.cpp index e0ebb03d5..b3d57356f 100644 --- a/Stub/DiabloUI/selconn.cpp +++ b/Stub/DiabloUI/selconn.cpp @@ -10,6 +10,8 @@ _SNETPLAYERDATA *selconn_UserInfo; _SNETUIDATA *selconn_UiInfo; _SNETVERSIONDATA *selconn_FileInfo; +DWORD provider; + UI_Item SELCONNECT_DIALOG[] = { { { 0, 0, 640, 480 }, UI_IMAGE, 0, 0, NULL, &ArtBackground }, { { 24, 161, 590, 35 }, UI_TEXT, UIS_CENTER | UIS_BIG, 0, "Multi Player Game" }, @@ -20,9 +22,9 @@ UI_Item SELCONNECT_DIALOG[] = { { { 35, 393, 205, 21 }, UI_TEXT, UIS_CENTER, 0, selconn_Gateway }, // Gateway { { 16, 427, 250, 35 }, UI_BUTTON, UIS_CENTER | UIS_VCENTER | UIS_BIG | UIS_GOLD | UIS_HIDDEN, 0, "Change Gateway" }, { { 300, 211, 295, 33 }, UI_TEXT, UIS_CENTER | UIS_BIG, 0, "Select Connection" }, - { { 305, 256, 285, 26 }, UI_LIST, UIS_CENTER | UIS_VCENTER | UIS_GOLD, 0, "Local Area Network (UDP)" }, - { { 305, 282, 285, 26 }, UI_LIST, UIS_CENTER | UIS_VCENTER | UIS_GOLD, 1, "Solo" }, - { { 305, 308, 285, 26 }, UI_LIST, UIS_CENTER | UIS_VCENTER | UIS_GOLD }, + { { 305, 256, 285, 26 }, UI_LIST, UIS_CENTER | UIS_VCENTER | UIS_GOLD, 0, "Client-Server (TCP)" }, + { { 305, 282, 285, 26 }, UI_LIST, UIS_CENTER | UIS_VCENTER | UIS_GOLD, 1, "Peer-to-Peer (UDP)" }, + { { 305, 308, 285, 26 }, UI_LIST, UIS_CENTER | UIS_VCENTER | UIS_GOLD, 2, "Loopback" }, { { 305, 334, 285, 26 }, UI_LIST, UIS_CENTER | UIS_VCENTER | UIS_GOLD }, { { 305, 360, 285, 26 }, UI_LIST, UIS_CENTER | UIS_VCENTER | UIS_GOLD }, { { 305, 386, 285, 26 }, UI_LIST, UIS_CENTER | UIS_VCENTER | UIS_GOLD }, @@ -33,7 +35,7 @@ UI_Item SELCONNECT_DIALOG[] = { void selconn_Load() { LoadBackgroundArt("ui_art\\selconn.pcx"); - UiInitList(0, 1, selconn_Focus, selconn_Select, selconn_Esc, SELCONNECT_DIALOG, size(SELCONNECT_DIALOG)); + UiInitList(0, 2, selconn_Focus, selconn_Select, selconn_Esc, SELCONNECT_DIALOG, size(SELCONNECT_DIALOG)); } void selconn_Free() @@ -53,11 +55,15 @@ void selconn_Focus(int value) int players = 4; switch (value) { case 0: - sprintf(selconn_Description, "All computers must be connected to an UDP-compatible network."); + sprintf(selconn_Description, "All computers must be connected to a TCP-compatible network."); players = 4; break; case 1: - sprintf(selconn_Description, "Play by your self with no network exposure."); + sprintf(selconn_Description, "All computers must be connected to a UDP-compatible network."); + players = 4; + break; + case 2: + sprintf(selconn_Description, "Play by yourself with no network exposure."); players = 1; break; } @@ -72,12 +78,14 @@ void selconn_Focus(int value) void selconn_Select(int value) { - DWORD provider; switch (value) { case 0: - provider = 'UDPN'; + provider = 'TCPN'; break; case 1: + provider = 'UDPN'; + break; + case 2: provider = 'SCBL'; break; } diff --git a/Stub/DiabloUI/selgame.cpp b/Stub/DiabloUI/selgame.cpp index 50b9699b0..27f599917 100644 --- a/Stub/DiabloUI/selgame.cpp +++ b/Stub/DiabloUI/selgame.cpp @@ -1,21 +1,24 @@ #include "selgame.h" char selgame_Lable[32]; -char selgame_Ip[129]; +char selgame_Ip[129] = "127.0.0.1"; // CONFIG char selgame_Description[256]; bool selgame_enteringGame; bool selgame_endMenu; int* gdwPlayerId; +static _SNETPROGRAMDATA* m_client_info; +extern DWORD provider; + UI_Item SELUDPGAME_DIALOG[] = { { { 0, 0, 640, 480 }, UI_IMAGE, 0, 0, NULL, &ArtBackground }, - { { 24, 161, 590, 35 }, UI_TEXT, UIS_CENTER | UIS_BIG, 0, "Join UDP Games" }, + { { 24, 161, 590, 35 }, UI_TEXT, UIS_CENTER | UIS_BIG, 0, "Join TCP/UDP Games" }, { { 35, 211, 205, 33 }, UI_TEXT, UIS_MED, 0, "Description:" }, { { 35, 256, 205, 192 }, UI_TEXT, 0, 0, selgame_Description }, // Description { { 300, 211, 295, 33 }, UI_TEXT, UIS_CENTER | UIS_BIG, 0, "Select Action" }, { { 305, 255, 285, 26 }, UI_LIST, UIS_CENTER | UIS_MED | UIS_GOLD, 0, "Create Game" }, { { 305, 281, 285, 26 }, UI_LIST, UIS_CENTER | UIS_MED | UIS_GOLD, 1, "Enter IP" }, - { { 305, 307, 285, 26 }, UI_LIST, UIS_CENTER | UIS_MED | UIS_GOLD, 2, "Localhost" }, + { { 305, 307, 285, 26 }, UI_LIST, UIS_CENTER | UIS_MED | UIS_GOLD }, { { 305, 333, 285, 26 }, UI_LIST, UIS_CENTER | UIS_MED | UIS_GOLD }, { { 305, 359, 285, 26 }, UI_LIST, UIS_CENTER | UIS_MED | UIS_GOLD }, { { 305, 385, 285, 26 }, UI_LIST, UIS_CENTER | UIS_MED | UIS_GOLD }, @@ -55,7 +58,11 @@ void selgame_Free() void selgame_GameSelection_Init() { - UiInitList(0, 2, selgame_GameSelection_Focus, selgame_GameSelection_Select, selgame_GameSelection_Esc, SELUDPGAME_DIALOG, size(SELUDPGAME_DIALOG)); + if(provider == 'SCBL') { + selgame_GameSelection_Select(0); + } else { + UiInitList(0, 1, selgame_GameSelection_Focus, selgame_GameSelection_Select, selgame_GameSelection_Esc, SELUDPGAME_DIALOG, size(SELUDPGAME_DIALOG)); + } } void selgame_GameSelection_Focus(int value) @@ -67,9 +74,6 @@ void selgame_GameSelection_Focus(int value) case 1: sprintf(selgame_Description, "Enter an IP and join a game already in progress at that address."); break; - default: - sprintf(selgame_Description, "%s.\nCreated by %s, a level %d %s.", "Normal Difficulty", "Localhost", 1, "Warrior"); - break; } for (auto &item : SELUDPGAME_DIALOG) { @@ -96,10 +100,6 @@ void selgame_GameSelection_Select(int value) case 1: UiInitList(0, 0, NULL, selgame_Ip_Select, selgame_GameSelection_Init, ENTERIP_DIALOG, size(ENTERIP_DIALOG)); break; - default: - sprintf(selgame_Ip, "127.0.0.1"); - selgame_Ip_Select(0); - break; } } @@ -135,8 +135,11 @@ void selgame_Diff_Select(int value) { selgame_endMenu = true; selgame_enteringGame = true; - gnDifficulty = value; - if (!SNetCreateGame(NULL, "mypass", NULL, 0, NULL, 0, MAX_PLRS, NULL, NULL, gdwPlayerId)) + + _gamedata* info = m_client_info->initdata; + info->bDiff = value; + + if (!SNetCreateGame(NULL, "mypass", NULL, 0, (char*)info, sizeof(_gamedata), MAX_PLRS, NULL, NULL, gdwPlayerId)) TermMsg("Unable to create game."); } @@ -144,6 +147,7 @@ int __stdcall UiSelectGame(int a1, _SNETPROGRAMDATA *client_info, _SNETPLAYERDAT _SNETVERSIONDATA *file_info, int *playerId) { gdwPlayerId = playerId; + m_client_info = client_info; LoadBackgroundArt("ui_art\\selgame.pcx"); selgame_GameSelection_Init(); selgame_enteringGame = false; diff --git a/Stub/dvlnet/base.cpp b/Stub/dvlnet/base.cpp index b8a2b137b..76acaf486 100644 --- a/Stub/dvlnet/base.cpp +++ b/Stub/dvlnet/base.cpp @@ -2,7 +2,7 @@ using namespace dvlnet; -base::base(buffer_t info) +void base::setup_gameinfo(buffer_t info) { game_init_info = std::move(info); } diff --git a/Stub/dvlnet/base.h b/Stub/dvlnet/base.h index 501a62bf4..8730bde87 100644 --- a/Stub/dvlnet/base.h +++ b/Stub/dvlnet/base.h @@ -10,8 +10,6 @@ namespace dvlnet { class base : public dvlnet { public: - base(buffer_t info); - virtual int create(std::string addrstr, std::string passwd) = 0; virtual int join(std::string addrstr, std::string passwd) = 0; @@ -30,6 +28,7 @@ namespace dvlnet { virtual void poll() = 0; virtual void send(packet& pkt) = 0; + void setup_gameinfo(buffer_t info); protected: std::map registered_handlers; buffer_t game_init_info; diff --git a/Stub/dvlnet/dvlnet.h b/Stub/dvlnet/dvlnet.h index 352049723..5edb89128 100644 --- a/Stub/dvlnet/dvlnet.h +++ b/Stub/dvlnet/dvlnet.h @@ -6,6 +6,7 @@ #include namespace dvlnet { + typedef std::vector buffer_t; typedef void(__stdcall *snet_event_func)(struct _SNETEVENT*); class dvlnet_exception : public std::exception {}; @@ -26,6 +27,7 @@ namespace dvlnet { virtual void* SNetUnregisterEventHandler(event_type evtype, snet_event_func func) = 0; virtual bool SNetLeaveGame(int type) = 0; + virtual void setup_gameinfo(buffer_t info) = 0; virtual ~dvlnet() {} }; } diff --git a/Stub/dvlnet/loopback.h b/Stub/dvlnet/loopback.h index 69b95aa5b..eef93ef7d 100644 --- a/Stub/dvlnet/loopback.h +++ b/Stub/dvlnet/loopback.h @@ -21,5 +21,6 @@ namespace dvlnet { virtual void *SNetUnregisterEventHandler(event_type evtype, snet_event_func func); virtual bool SNetLeaveGame(int type); + virtual void setup_gameinfo(buffer_t info) {} }; } diff --git a/Stub/dvlnet/packet.h b/Stub/dvlnet/packet.h index 2035c2a37..fe87811d1 100644 --- a/Stub/dvlnet/packet.h +++ b/Stub/dvlnet/packet.h @@ -14,7 +14,6 @@ namespace dvlnet { typedef uint32_t cookie_t; typedef int turn_t; // change int to something else in devilution code later typedef int leaveinfo_t; // also change later - typedef std::vector buffer_t; typedef std::array key_t; static constexpr plr_t PLR_MASTER = 0xFE; diff --git a/Stub/dvlnet/tcp_client.cpp b/Stub/dvlnet/tcp_client.cpp index e0728424e..6c6380c21 100644 --- a/Stub/dvlnet/tcp_client.cpp +++ b/Stub/dvlnet/tcp_client.cpp @@ -2,11 +2,6 @@ using namespace dvlnet; -tcp_client::tcp_client(buffer_t info) : - base(std::move(info)) -{ -} - int tcp_client::create(std::string addrstr, std::string passwd) { local_server = std::make_unique(ioc, addrstr, diff --git a/Stub/dvlnet/tcp_client.h b/Stub/dvlnet/tcp_client.h index 88e65cf0b..d0924b26a 100644 --- a/Stub/dvlnet/tcp_client.h +++ b/Stub/dvlnet/tcp_client.h @@ -3,7 +3,6 @@ namespace dvlnet { class tcp_client : public base { public: - tcp_client(buffer_t info); int create(std::string addrstr, std::string passwd); int join(std::string addrstr, std::string passwd); diff --git a/Stub/dvlnet/udp_p2p.cpp b/Stub/dvlnet/udp_p2p.cpp index fc66b9315..8580cca19 100644 --- a/Stub/dvlnet/udp_p2p.cpp +++ b/Stub/dvlnet/udp_p2p.cpp @@ -4,11 +4,6 @@ using namespace dvlnet; const udp_p2p::endpoint udp_p2p::none; -udp_p2p::udp_p2p(buffer_t info) : - base(info) -{ -} - int udp_p2p::create(std::string addrstr, std::string passwd) { sock = asio::ip::udp::socket(io_context);// to be removed later diff --git a/Stub/dvlnet/udp_p2p.h b/Stub/dvlnet/udp_p2p.h index c06c06219..abe8b8c96 100644 --- a/Stub/dvlnet/udp_p2p.h +++ b/Stub/dvlnet/udp_p2p.h @@ -1,7 +1,6 @@ namespace dvlnet { class udp_p2p : public base { public: - udp_p2p(buffer_t info); virtual int create(std::string addrstr, std::string passwd); virtual int join(std::string addrstr, std::string passwd); virtual void poll(); diff --git a/Stub/storm_net.cpp b/Stub/storm_net.cpp index eed502c3b..80ea4cde8 100644 --- a/Stub/storm_net.cpp +++ b/Stub/storm_net.cpp @@ -84,10 +84,10 @@ int __stdcall SNetInitializeProvider(unsigned long provider, struct _SNETPROGRAM struct _SNETPLAYERDATA *user_info, struct _SNETUIDATA *ui_info, struct _SNETVERSIONDATA *fileinfo) { - if (provider == 'UDPN') { - dvlnet::buffer_t game_init_info((char*)client_info->initdata, - (char*)client_info->initdata + client_info->initdatabytes); - dvlnet_inst = std::make_unique(std::move(game_init_info)); + if (provider == 'TCPN') { + dvlnet_inst = std::make_unique(); + } else if (provider == 'UDPN') { + dvlnet_inst = std::make_unique(); } else if (provider == 'SCBL' || provider == 0) { dvlnet_inst = std::make_unique(); } else { @@ -104,6 +104,10 @@ BOOL STORMAPI SNetCreateGame(const char *pszGameName, const char *pszGamePasswor DWORD dwGameType, char *GameTemplateData, int GameTemplateSize, int playerCount, char *creatorName, char *a11, int *playerID) { + if(GameTemplateSize != 8) + ABORT(); + dvlnet::buffer_t game_init_info(GameTemplateData, GameTemplateData + GameTemplateSize); + dvlnet_inst->setup_gameinfo(std::move(game_init_info)); *playerID = dvlnet_inst->create("0.0.0.0", pszGamePassword); return *playerID != -1;