-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
838 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[submodule "3rdparty/OSW"] | ||
path = 3rdparty/OSW | ||
url = git@github.com:m4dEngi/open-steamworks.git | ||
branch = master | ||
[submodule "3rdparty/scrypt-jane"] | ||
path = 3rdparty/scrypt-jane | ||
url = git@github.com:floodyberry/scrypt-jane.git | ||
branch = master |
Submodule scrypt-jane
added at
0ab612
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
#ifndef CSTEAMAPI_H | ||
#define CSTEAMAPI_H | ||
|
||
#pragma once | ||
|
||
#include "./3rdparty/OSW/OpenSteamworks/Steamworks.h" | ||
#include "./3rdparty/OSW/OpenSteamAPI/src/Interface_OSW.h" | ||
|
||
class CSteamAPI | ||
{ | ||
public: | ||
CSteamAPI() | ||
: hPipe(0), hUser(0), m_pClientEngine(nullptr), m_pSteamClient(nullptr), | ||
Friends(nullptr), User(nullptr), UnifiedMessages(nullptr), ParentalSettings(nullptr) | ||
{ | ||
loader = new CSteamAPILoader(); | ||
} | ||
|
||
~CSteamAPI() | ||
{ | ||
if (hPipe && hUser) | ||
{ | ||
m_pSteamClient->ReleaseUser(hPipe, hUser); | ||
m_pSteamClient->BReleaseSteamPipe(hPipe); | ||
m_pSteamClient->BShutdownIfAllPipesClosed(); | ||
} | ||
delete loader; | ||
} | ||
|
||
bool Load() | ||
{ | ||
if (!loader->Load()) | ||
return false; | ||
|
||
DynamicLibrary m_pTier0("tier0_s"); // x64 ??? | ||
Tier0_Log = (decltype(Tier0_Log)) m_pTier0.GetSymbol("Log"); | ||
Tier0_Msg = (decltype(Tier0_Msg)) m_pTier0.GetSymbol("Msg"); | ||
Tier0_Warning = (decltype(Tier0_Warning)) m_pTier0.GetSymbol("Warning"); | ||
Tier0_Plat_RelativeTicks = (decltype(Tier0_Plat_RelativeTicks)) m_pTier0.GetSymbol("Plat_RelativeTicks"); | ||
Tier0_Plat_TickDiffMilliSec = (decltype(Tier0_Plat_TickDiffMilliSec)) m_pTier0.GetSymbol("Plat_TickDiffMilliSec"); | ||
|
||
return Tier0_Log && Tier0_Msg; | ||
} | ||
|
||
bool Connect() | ||
{ | ||
CreateInterfaceFn factory = loader->GetSteam3Factory(); | ||
if (!factory) | ||
return false; | ||
|
||
m_pClientEngine = (IClientEngine *)factory(CLIENTENGINE_INTERFACE_VERSION, NULL); | ||
m_pSteamClient = (ISteamClient017 *)factory(STEAMCLIENT_INTERFACE_VERSION_017, NULL); | ||
if (!m_pSteamClient) | ||
return false; | ||
|
||
hPipe = m_pSteamClient->CreateSteamPipe(); | ||
hUser = m_pSteamClient->ConnectToGlobalUser(hPipe); | ||
if (!hPipe || !hUser) | ||
return false; | ||
|
||
Friends = (ISteamFriends015 *)m_pSteamClient->GetISteamFriends(hUser, hPipe, STEAMFRIENDS_INTERFACE_VERSION_015); | ||
User = (ISteamUser019 *)m_pSteamClient->GetISteamUser(hUser, hPipe, STEAMUSER_INTERFACE_VERSION_019); | ||
UnifiedMessages = (ISteamUnifiedMessages001 *)m_pSteamClient->GetISteamUnifiedMessages(hUser, hPipe, STEAMUNIFIEDMESSAGES_INTERFACE_VERSION_001); | ||
|
||
if (m_pClientEngine) | ||
{ | ||
// ugly hack, but I am too lazy to fix it in the original repository | ||
ParentalSettings = (m_pClientEngine->*(IClientParentalSettings *(IClientEngine::*)(HSteamPipe, const char *))&m_pClientEngine->GetIClientParentalSettings)(hPipe, NULL); | ||
if (!ParentalSettings) // this mean vtable is changed (very old or very new steam client) | ||
{ | ||
// fix the stack pointer | ||
#if defined(_MSC_VER) | ||
__asm {subl $4,%esp} | ||
#elif defined(__GNUC__) | ||
asm ("subl $4,%esp"); | ||
#else | ||
// ..or not. not my problem. | ||
#endif | ||
} | ||
} | ||
|
||
return Friends && User && UnifiedMessages; | ||
} | ||
|
||
private: | ||
CSteamAPILoader *loader; | ||
HSteamPipe hPipe; | ||
HSteamUser hUser; | ||
IClientEngine *m_pClientEngine; | ||
ISteamClient017 *m_pSteamClient; | ||
|
||
public: | ||
ISteamFriends015 *Friends; | ||
ISteamUser019 *User; | ||
ISteamUnifiedMessages001 *UnifiedMessages; | ||
IClientParentalSettings *ParentalSettings; | ||
|
||
void (STEAM_CALL *Tier0_Log)(const char *szFormat, ...); | ||
void (STEAM_CALL *Tier0_Msg)(const char *szFormat, ...); | ||
void (STEAM_CALL *Tier0_Warning)(const char *szFormat, ...); | ||
uint64 (STEAM_CALL *Tier0_Plat_RelativeTicks)(); | ||
int32 (STEAM_CALL *Tier0_Plat_TickDiffMilliSec)(uint64 tickStart, uint64 tickEnd); | ||
}; | ||
|
||
#endif // CSTEAMAPI_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
//========================== Open Steamworks ================================ | ||
// | ||
// This file is part of the Open Steamworks project. All individuals associated | ||
// with this project do not claim ownership of the contents | ||
// | ||
// The code, comments, and all related files, projects, resources, | ||
// redistributables included with this project are Copyright Valve Corporation. | ||
// Additionally, Valve, the Valve logo, Half-Life, the Half-Life logo, the | ||
// Lambda logo, Steam, the Steam logo, Team Fortress, the Team Fortress logo, | ||
// Opposing Force, Day of Defeat, the Day of Defeat logo, Counter-Strike, the | ||
// Counter-Strike logo, Source, the Source logo, and Counter-Strike Condition | ||
// Zero are trademarks and or registered trademarks of Valve Corporation. | ||
// All other trademarks are property of their respective owners. | ||
// | ||
//============================================================================= | ||
|
||
#ifndef ICLIENTPARENTALSETTINGS_H | ||
#define ICLIENTPARENTALSETTINGS_H | ||
#ifdef _WIN32 | ||
#pragma once | ||
#endif | ||
|
||
#include "SteamTypes.h" | ||
|
||
abstract_class UNSAFE_INTERFACE IClientParentalSettings | ||
{ | ||
public: | ||
virtual bool BIsParentalLockEnabled() = 0; | ||
virtual bool BIsParentalLockLocked() = 0; | ||
virtual bool BIsAppBlocked( AppId_t unAppID ) = 0; | ||
virtual bool BIsAppInBlockList( AppId_t unAppID ) = 0; | ||
virtual bool BIsFeatureBlocked( EParentalFeature eParentalFeature ) = 0; | ||
virtual bool BIsFeatureInBlockList( EParentalFeature eParentalFeature ) = 0; | ||
virtual bool BGetSerializedParentalSettings( CUtlBuffer * pBuffer ) = 0; | ||
virtual bool BGetRecoveryEmail(char*, int) = 0; | ||
}; | ||
|
||
#endif // ICLIENTPARENTALSETTINGS_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
GCC = gcc | ||
GXX = g++ | ||
INCLUDE_PATH = "./3rdparty/OSW/OpenSteamworks" | ||
|
||
CFLAGS = -Wall -Wextra -Wshadow -m32 -O2 -pipe -fno-ident -fno-exceptions -I$(INCLUDE_PATH) | ||
CFLAGS += -DSTEAMWORKS_CLIENT_INTERFACES -DNO_CSTEAMID_STL -DSCRYPT_SALSA -DSCRYPT_SHA256 -DSCRYPT_TEST | ||
CFLAGS += -Wformat-security -Wno-unused-function -Wno-unused-variable -Wno-unused-but-set-variable -Wunreachable-code | ||
CPPFLAGS = $(CFLAGS) -nostdinc++ -std=c++11 | ||
LDFLAGS = -s -static | ||
|
||
SOURCES_SPPRT = spprt.cpp \ | ||
protoreader.cpp \ | ||
3rdparty\OSW\OpenSteamAPI\src\Interface_OSW.cpp | ||
|
||
SOURCES_SCRYPT = 3rdparty\scrypt-jane\scrypt-jane.c | ||
|
||
OBJECTS_SPPRT = $(SOURCES_SPPRT:.cpp=.o) | ||
#OBJECTS_SCRYPT = $(SOURCES_SCRYPT:.c=.o) | ||
TARGET_SPPRT = spprt.exe | ||
|
||
.PHONY: all clean | ||
|
||
.SUFFIXES: .cpp .c .o | ||
|
||
all: $(TARGET_SPPRT) | ||
|
||
$(TARGET_SPPRT): $(OBJECTS_SPPRT) $(OBJECTS_SCRYPT) | ||
$(GXX) $(OBJECTS_SPPRT) $(OBJECTS_SCRYPT) $(CPPFLAGS) $(LDFLAGS) -o $@ | ||
|
||
.cpp.o: | ||
$(GXX) $(CPPFLAGS) -c $< -o $@ | ||
|
||
.c.o: | ||
$(GCC) $(CFLAGS) -c $< -o $@ | ||
|
||
clean: | ||
del $(TARGET_SPPRT) $(OBJECTS_SPPRT) $(OBJECTS_SCRYPT) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,202 @@ | ||
/** | ||
* MIT License | ||
* | ||
* Copyright (c) 2017 Nephrite | ||
*/ | ||
|
||
#include <string.h> // memmove | ||
|
||
unsigned int ReadProtoNumber(const unsigned char *pubInput, unsigned int cubAvail, void *pubDest, unsigned int cubSize, bool bFixed = false) | ||
{ | ||
if (bFixed) | ||
{ | ||
switch (cubSize) | ||
{ | ||
case 1: | ||
*(unsigned char *)pubDest = *pubInput; | ||
break; | ||
case 2: | ||
*(unsigned short *)pubDest = *(unsigned short *)pubInput; | ||
break; | ||
case 4: | ||
*(unsigned int *)pubDest = *(unsigned int *)pubInput; | ||
break; | ||
case 8: | ||
*(unsigned long long *)pubDest = *(unsigned long long *)pubInput; | ||
break; | ||
default: | ||
return 0; | ||
} | ||
|
||
return cubSize; | ||
} | ||
|
||
union | ||
{ | ||
char result8; | ||
short result16; | ||
int result32; | ||
long long result64 = 0; | ||
}; | ||
|
||
unsigned int bytes_read = 0; | ||
|
||
while (bytes_read < cubAvail) | ||
{ | ||
switch (cubSize) | ||
{ | ||
case 1: | ||
case 2: | ||
case 3: | ||
case 4: | ||
result32 |= (pubInput[bytes_read] & 0x7F) << (bytes_read * 7); | ||
break; | ||
case 5: | ||
case 6: | ||
case 7: | ||
case 8: | ||
case 9: | ||
case 10: | ||
result64 |= (long long)(pubInput[bytes_read] & 0x7F) << (bytes_read * 7); | ||
break; | ||
default: | ||
break; | ||
} | ||
if ((pubInput[bytes_read++] & 0x80) == 0) { | ||
break; | ||
} | ||
} | ||
|
||
if (pubDest) | ||
{ | ||
switch (cubSize) | ||
{ | ||
case 1: | ||
*(char *)pubDest = result8; | ||
break; | ||
case 2: | ||
*(short *)pubDest = result16; | ||
break; | ||
case 4: | ||
*(int *)pubDest = result32; | ||
break; | ||
case 8: | ||
*(long long *)pubDest = result64; | ||
break; | ||
default: | ||
if (result64 >> 32) | ||
*(long long *)pubDest = result64; | ||
else | ||
*(int *)pubDest = result32; | ||
} | ||
} | ||
|
||
return bytes_read; | ||
} | ||
|
||
unsigned int ReadProtoLengthDelimited(const unsigned char *pubInput, unsigned int cubAvail, void *pubDest = NULL, unsigned int *cubSize = NULL) | ||
{ | ||
unsigned int bytes_read = 0; | ||
unsigned int length = 0; | ||
|
||
bytes_read = ReadProtoNumber(pubInput, cubAvail, &length, 4); | ||
cubAvail -= bytes_read; | ||
|
||
unsigned int max_size_to_read = (length <= cubAvail) ? length : cubAvail; | ||
unsigned int size_to_copy = max_size_to_read; | ||
|
||
if (cubSize) | ||
{ | ||
size_to_copy = (*cubSize == 0 || max_size_to_read <= *cubSize) ? max_size_to_read : *cubSize; | ||
*cubSize = length; | ||
} | ||
if (pubDest && size_to_copy) | ||
{ | ||
memmove(pubDest, pubInput + bytes_read, size_to_copy); | ||
} | ||
|
||
return bytes_read + max_size_to_read; | ||
} | ||
|
||
unsigned int ReadProtoField(const unsigned char *pubInput, unsigned int cubAvail, unsigned int *punTag, unsigned int *punWireType, void *pubDest = NULL, unsigned int *cubSize = NULL) | ||
{ | ||
unsigned int bytes_read = 0; | ||
unsigned int data_size = 0; | ||
unsigned int tag = 0; | ||
unsigned int wire_type = 0; | ||
|
||
bytes_read = ReadProtoNumber(pubInput, cubAvail, &tag, 4); | ||
cubAvail -= bytes_read; | ||
wire_type = tag & 0x07; | ||
tag = tag >> 3; | ||
|
||
switch (wire_type) | ||
{ | ||
case 0: // Varint - int32, int64, uint32, uint64, sint32, sint64, bool, enum | ||
data_size = ReadProtoNumber(pubInput + bytes_read, cubAvail, pubDest, cubSize ? *cubSize : 0, false); | ||
bytes_read += data_size; | ||
break; | ||
case 1: // 64-bit - fixed64, sfixed64, double | ||
if (pubDest) | ||
ReadProtoNumber(pubInput + bytes_read, cubAvail, pubDest, 8, true); | ||
data_size = 8; | ||
bytes_read += 8; | ||
break; | ||
case 5: // 32-bit - fixed32, sfixed32, float | ||
if (pubDest) | ||
ReadProtoNumber(pubInput + bytes_read, cubAvail, pubDest, 4, true); | ||
data_size = 4; | ||
bytes_read += 4; | ||
break; | ||
case 2: // Length-delimited - string, bytes, embedded messages, packed repeated fields | ||
if (cubSize) | ||
data_size = *cubSize; | ||
bytes_read += ReadProtoLengthDelimited(pubInput + bytes_read, cubAvail, pubDest, &data_size); | ||
break; | ||
default: | ||
break; | ||
} | ||
|
||
if (punTag) | ||
*punTag = tag; | ||
if (punWireType) | ||
*punWireType = wire_type; | ||
if (cubSize) | ||
*cubSize = data_size; | ||
|
||
return bytes_read; | ||
} | ||
|
||
bool GetFieldDataByTag(unsigned int nTag, const unsigned char *pubInput, unsigned int cubAvail, void *pubDest, unsigned int *cubSize, unsigned int *cubTotalRead = NULL) | ||
{ | ||
unsigned int bytes_read = 0; | ||
unsigned int bytes_read_field = 0; | ||
unsigned int data_size; | ||
unsigned int tag = 0; | ||
unsigned int wire_type = 0; | ||
bool result = false; | ||
|
||
while (cubAvail > 0) | ||
{ | ||
data_size = *cubSize; | ||
bytes_read_field = ReadProtoField(pubInput + bytes_read, cubAvail, &tag, &wire_type, NULL, &data_size); | ||
|
||
if ((wire_type != 0 && wire_type != 1 && wire_type != 2 && wire_type != 5) || (data_size > cubAvail)) | ||
{ | ||
break; | ||
} | ||
|
||
if (tag == nTag) | ||
{ | ||
bytes_read += ReadProtoField(pubInput + bytes_read, cubAvail, NULL, NULL, pubDest, cubSize); | ||
if (cubTotalRead) | ||
*cubTotalRead = bytes_read; | ||
result = true; | ||
break; | ||
} | ||
bytes_read += bytes_read_field; | ||
cubAvail -= bytes_read_field; | ||
} | ||
|
||
return result; | ||
} |
Oops, something went wrong.