Skip to content

Commit 7c1d5ed

Browse files
Update CreateSteamPipe to return the first free number as pipe handle
1 parent 8a7ef8b commit 7c1d5ed

3 files changed

Lines changed: 16 additions & 19 deletions

File tree

dll/dll/steam_client.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,8 @@ public ISteamClient
187187
int steamclient_version{};
188188
bool using_old_callbacks{};
189189

190-
unsigned steam_pipe_counter = 1;
190+
uint32 steam_pipe_counter = 1;
191+
std::priority_queue<uint32, std::vector<uint32>, std::greater<>> freed_steam_pipes{};
191192
std::map<HSteamPipe, enum Steam_Pipe> steam_pipes{};
192193

193194

dll/steam_client.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -311,18 +311,24 @@ void Steam_Client::setAppID(uint32 appid)
311311

312312
}
313313

314-
// Creates a communication pipe to the Steam client.
314+
// Creates a communication pipe to the Steam client.
315315
// NOT THREADSAFE - ensure that no other threads are accessing Steamworks API when calling
316316
HSteamPipe Steam_Client::CreateSteamPipe()
317317
{
318318
PRINT_DEBUG_ENTRY();
319-
if (!steam_pipe_counter) ++steam_pipe_counter;
320-
HSteamPipe pipe = steam_pipe_counter;
321-
++steam_pipe_counter;
322-
PRINT_DEBUG(" returned pipe handle %i", pipe);
323319

320+
HSteamPipe pipe{};
321+
if (!freed_steam_pipes.empty()) {
322+
pipe = freed_steam_pipes.top();
323+
freed_steam_pipes.pop();
324+
} else {
325+
if (!steam_pipe_counter) ++steam_pipe_counter;
326+
pipe = steam_pipe_counter;
327+
++steam_pipe_counter;
328+
}
329+
330+
PRINT_DEBUG(" returned pipe handle %i", pipe);
324331
steam_pipes[pipe] = Steam_Pipe::NO_USER;
325-
326332
return pipe;
327333
}
328334

@@ -334,6 +340,7 @@ bool Steam_Client::BReleaseSteamPipe( HSteamPipe hSteamPipe )
334340
{
335341
PRINT_DEBUG("%i", hSteamPipe);
336342
if (steam_pipes.count(hSteamPipe)) {
343+
freed_steam_pipes.push(hSteamPipe);
337344
return steam_pipes.erase(hSteamPipe) > 0;
338345
}
339346

dll/steam_client_interface_getter.cpp

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -96,18 +96,7 @@ ISteamGameStats *Steam_Client::GetISteamGameStats( HSteamUser hSteamUser, HSteam
9696
ISteamUser *Steam_Client::GetISteamUser( HSteamUser hSteamUser, HSteamPipe hSteamPipe, const char *pchVersion )
9797
{
9898
PRINT_DEBUG("%s", pchVersion);
99-
100-
if (!hSteamUser) {
101-
return NULL;
102-
}
103-
if (!steam_pipes.count(hSteamPipe)) {
104-
// Fallback for steamclient_experimental build: if pipe 1 is requested but not found,
105-
// and we have other valid pipes, continue execution instead of returning NULL
106-
if (hSteamPipe !=1 || steam_pipes.empty()) {
107-
return NULL;
108-
}
109-
}
110-
99+
if (!steam_pipes.count(hSteamPipe) || !hSteamUser) return nullptr;
111100

112101
Steam_User *steam_user_tmp{};
113102

0 commit comments

Comments
 (0)