mirror of
https://gitlab.com/Mr_Goldberg/goldberg_emulator.git
synced 2024-11-23 20:38:07 +01:00
Very basic steam game coordinator emulation.
This commit is contained in:
parent
08a96883e7
commit
e3ddc8d89f
2 changed files with 50 additions and 4 deletions
|
@ -47,6 +47,7 @@ EXTERN_C IMAGE_DOS_HEADER __ImageBase;
|
||||||
#define PRINT_DEBUG(a, ...) do {FILE *t = fopen("STEAM_LOG.txt", "a"); fprintf(t, "%u " a, GetCurrentThreadId(), __VA_ARGS__); fclose(t); WSASetLastError(0);} while (0)
|
#define PRINT_DEBUG(a, ...) do {FILE *t = fopen("STEAM_LOG.txt", "a"); fprintf(t, "%u " a, GetCurrentThreadId(), __VA_ARGS__); fclose(t); WSASetLastError(0);} while (0)
|
||||||
#endif
|
#endif
|
||||||
#else
|
#else
|
||||||
|
#include <arpa/inet.h>
|
||||||
#define PATH_SEPARATOR "/"
|
#define PATH_SEPARATOR "/"
|
||||||
#ifndef EMU_RELEASE_BUILD
|
#ifndef EMU_RELEASE_BUILD
|
||||||
#define PRINT_DEBUG(...) {FILE *t = fopen("STEAM_LOG.txt", "a"); fprintf(t, __VA_ARGS__); fclose(t);}
|
#define PRINT_DEBUG(...) {FILE *t = fopen("STEAM_LOG.txt", "a"); fprintf(t, __VA_ARGS__); fclose(t);}
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
<http://www.gnu.org/licenses/>. */
|
<http://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
#include "base.h"
|
#include "base.h"
|
||||||
|
#include <queue>
|
||||||
|
|
||||||
class Steam_Game_Coordinator :
|
class Steam_Game_Coordinator :
|
||||||
public ISteamGameCoordinator
|
public ISteamGameCoordinator
|
||||||
|
@ -27,6 +27,18 @@ public ISteamGameCoordinator
|
||||||
class SteamCallBacks *callbacks;
|
class SteamCallBacks *callbacks;
|
||||||
class RunEveryRunCB *run_every_runcb;
|
class RunEveryRunCB *run_every_runcb;
|
||||||
|
|
||||||
|
static const uint32 protobuf_mask = 0x80000000;
|
||||||
|
std::queue<std::string> outgoing_messages;
|
||||||
|
|
||||||
|
void push_incoming(std::string message)
|
||||||
|
{
|
||||||
|
outgoing_messages.push(message);
|
||||||
|
|
||||||
|
struct GCMessageAvailable_t data;
|
||||||
|
data.m_nMessageSize = message.size();
|
||||||
|
callbacks->addCBResult(data.k_iCallback, &data, sizeof(data));
|
||||||
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static void steam_callback(void *object, Common_Message *msg)
|
static void steam_callback(void *object, Common_Message *msg)
|
||||||
{
|
{
|
||||||
|
@ -65,7 +77,19 @@ Steam_Game_Coordinator(class Settings *settings, class Networking *network, clas
|
||||||
// sends a message to the Game Coordinator
|
// sends a message to the Game Coordinator
|
||||||
EGCResults SendMessage_( uint32 unMsgType, const void *pubData, uint32 cubData )
|
EGCResults SendMessage_( uint32 unMsgType, const void *pubData, uint32 cubData )
|
||||||
{
|
{
|
||||||
PRINT_DEBUG("Steam_Game_Coordinator::SendMessage %u\n", unMsgType);
|
PRINT_DEBUG("Steam_Game_Coordinator::SendMessage %X %u len %u\n", unMsgType, (~protobuf_mask) & unMsgType, cubData);
|
||||||
|
if (protobuf_mask & unMsgType) {
|
||||||
|
uint32 message_type = (~protobuf_mask) & unMsgType;
|
||||||
|
if (message_type == 4006) { //client hello
|
||||||
|
std::string message("\xA4\x0F\x00\x80\x00\x00\x00\x00\x08\x00", 10);
|
||||||
|
push_incoming(message);
|
||||||
|
} else
|
||||||
|
if (message_type == 4007) { //server hello
|
||||||
|
std::string message("\xA5\x0F\x00\x80\x00\x00\x00\x00\x08\x00", 10);
|
||||||
|
push_incoming(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return k_EGCResultOK;
|
return k_EGCResultOK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,7 +97,12 @@ EGCResults SendMessage_( uint32 unMsgType, const void *pubData, uint32 cubData )
|
||||||
bool IsMessageAvailable( uint32 *pcubMsgSize )
|
bool IsMessageAvailable( uint32 *pcubMsgSize )
|
||||||
{
|
{
|
||||||
PRINT_DEBUG("Steam_Game_Coordinator::IsMessageAvailable\n");
|
PRINT_DEBUG("Steam_Game_Coordinator::IsMessageAvailable\n");
|
||||||
return false;
|
if (outgoing_messages.size()) {
|
||||||
|
if (pcubMsgSize) *pcubMsgSize = outgoing_messages.front().size();
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// fills the provided buffer with the first message in the queue and returns k_EGCResultOK or
|
// fills the provided buffer with the first message in the queue and returns k_EGCResultOK or
|
||||||
|
@ -83,7 +112,23 @@ bool IsMessageAvailable( uint32 *pcubMsgSize )
|
||||||
EGCResults RetrieveMessage( uint32 *punMsgType, void *pubDest, uint32 cubDest, uint32 *pcubMsgSize )
|
EGCResults RetrieveMessage( uint32 *punMsgType, void *pubDest, uint32 cubDest, uint32 *pcubMsgSize )
|
||||||
{
|
{
|
||||||
PRINT_DEBUG("Steam_Game_Coordinator::RetrieveMessage\n");
|
PRINT_DEBUG("Steam_Game_Coordinator::RetrieveMessage\n");
|
||||||
return k_EGCResultNoMessage;
|
if (outgoing_messages.size()) {
|
||||||
|
if (outgoing_messages.front().size() > cubDest) {
|
||||||
|
return k_EGCResultBufferTooSmall;
|
||||||
|
}
|
||||||
|
|
||||||
|
outgoing_messages.front().copy((char *)pubDest, cubDest);
|
||||||
|
if (pcubMsgSize) *pcubMsgSize = outgoing_messages.front().size();
|
||||||
|
if (punMsgType && outgoing_messages.front().size() >= sizeof(uint32)) {
|
||||||
|
outgoing_messages.front().copy((char *)punMsgType, sizeof(uint32));
|
||||||
|
*punMsgType = ntohl(*punMsgType);
|
||||||
|
}
|
||||||
|
|
||||||
|
outgoing_messages.pop();
|
||||||
|
return k_EGCResultOK;
|
||||||
|
} else {
|
||||||
|
return k_EGCResultNoMessage;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void RunCallbacks()
|
void RunCallbacks()
|
||||||
|
|
Loading…
Reference in a new issue