This commit is contained in:
Michael Fabian Dirks
2016-03-11 14:13:25 +01:00
parent 2bf8361797
commit a52326d80a
60 changed files with 2776 additions and 1059 deletions
-195
View File
@@ -1,195 +0,0 @@
// BlitzSteam - Steam wrapper for Blitz
// Copyright (C) 2015 Xaymar (Michael Fabian Dirks)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "BlitzCallback.h"
std::map<uint32_t, size_t>* BlitzCallback_Sizes;
#define BlitzCallback_Sizes_Add(T) BlitzCallback_Sizes->emplace(T::k_iCallback, sizeof(T))
void BlitzCallback_Init() {
BlitzCallback_Sizes = new std::map<uint32_t, size_t>();
BlitzCallback_Sizes->emplace(0, sizeof(BlitzCallback));
// SteamAPI
// SteamAppList
BlitzCallback_Sizes_Add(SteamAppInstalled_t);
BlitzCallback_Sizes_Add(SteamAppUninstalled_t);
// SteamApps
BlitzCallback_Sizes_Add(DlcInstalled_t);
BlitzCallback_Sizes_Add(RegisterActivationCodeResponse_t);
BlitzCallback_Sizes_Add(AppProofOfPurchaseKeyResponse_t);
BlitzCallback_Sizes_Add(NewLaunchQueryParameters_t);
// SteamController
// SteamFriends
BlitzCallback_Sizes_Add(PersonaStateChange_t);
BlitzCallback_Sizes_Add(GameOverlayActivated_t);
BlitzCallback_Sizes_Add(GameServerChangeRequested_t);
BlitzCallback_Sizes_Add(GameLobbyJoinRequested_t);
BlitzCallback_Sizes_Add(AvatarImageLoaded_t);
BlitzCallback_Sizes_Add(ClanOfficerListResponse_t);
BlitzCallback_Sizes_Add(FriendRichPresenceUpdate_t);
BlitzCallback_Sizes_Add(GameRichPresenceJoinRequested_t);
BlitzCallback_Sizes_Add(GameConnectedClanChatMsg_t);
BlitzCallback_Sizes_Add(GameConnectedChatJoin_t);
BlitzCallback_Sizes_Add(GameConnectedChatLeave_t);
BlitzCallback_Sizes_Add(DownloadClanActivityCountsResult_t);
BlitzCallback_Sizes_Add(JoinClanChatRoomCompletionResult_t);
BlitzCallback_Sizes_Add(GameConnectedFriendChatMsg_t);
BlitzCallback_Sizes_Add(FriendsGetFollowerCount_t);
BlitzCallback_Sizes_Add(FriendsIsFollowing_t);
BlitzCallback_Sizes_Add(FriendsEnumerateFollowingList_t);
BlitzCallback_Sizes_Add(SetPersonaNameResponse_t);
// SteamGameServer
BlitzCallback_Sizes_Add(GSClientApprove_t);
BlitzCallback_Sizes_Add(GSClientDeny_t);
BlitzCallback_Sizes_Add(GSClientKick_t);
BlitzCallback_Sizes_Add(GSClientAchievementStatus_t);
BlitzCallback_Sizes_Add(GSPolicyResponse_t);
BlitzCallback_Sizes_Add(GSGameplayStats_t);
BlitzCallback_Sizes_Add(GSClientGroupStatus_t);
BlitzCallback_Sizes_Add(GSReputation_t);
BlitzCallback_Sizes_Add(AssociateWithClanResult_t);
BlitzCallback_Sizes_Add(ComputeNewPlayerCompatibilityResult_t);
// SteamGameServerStats
BlitzCallback_Sizes_Add(GSStatsReceived_t);
BlitzCallback_Sizes_Add(GSStatsStored_t);
BlitzCallback_Sizes_Add(GSStatsUnloaded_t);
// SteamHTMLSurface
BlitzCallback_Sizes_Add(HTML_BrowserReady_t);
}
BlitzCallback::BlitzCallback(BP_BlitzFunction3_t pFunctionPointer) {
this->m_pFunctionPointer = pFunctionPointer;
this->m_hSteamAPICall = 0;
this->m_iCallback = 0;
// Initialize BlitzCallback_Sizes
if (BlitzCallback_Sizes == 0)
BlitzCallback_Init();
}
BlitzCallback::~BlitzCallback() {
this->Unregister();
this->UnregisterResult();
}
int BlitzCallback::GetCallbackSizeBytes() {
return (BlitzCallback_Sizes->find(this->m_iCallback)->second);
}
void BlitzCallback::Run(void *pvParam) {
if (m_hSteamAPICall != 0)
m_hSteamAPICall = 0; // Caller unregisters for us.
BP_CallFunction3(m_pFunctionPointer, reinterpret_cast<int32_t>(pvParam), 0, 0);
}
void BlitzCallback::Run(void *pvParam, bool bIOFailure, SteamAPICall_t hSteamAPICall) {
if (m_hSteamAPICall != 0)
m_hSteamAPICall = 0; // Caller unregisters for us.
BP_CallFunction3(m_pFunctionPointer, reinterpret_cast<int32_t>(pvParam), (bIOFailure ? 0 : 1), reinterpret_cast<int32_t>(&hSteamAPICall));
}
bool BlitzCallback::IsRegistered() {
return (this->m_nCallbackFlags & this->k_ECallbackFlagsRegistered) != 0;
}
void BlitzCallback::Register(uint32_t iCallback) {
if (this->IsRegistered())
this->Unregister();
SteamAPI_RegisterCallback(this, iCallback);
}
void BlitzCallback::Unregister() {
if (this->IsRegistered())
SteamAPI_UnregisterCallback(this);
}
void BlitzCallback::RegisterResult(SteamAPICall_t hSteamAPICall, uint32_t iCallback) {
if (this->m_hSteamAPICall == 0)
this->UnregisterResult();
this->m_hSteamAPICall = hSteamAPICall;
this->m_iCallback = iCallback;
SteamAPI_RegisterCallResult(this, hSteamAPICall);
}
void BlitzCallback::UnregisterResult() {
if (this->m_hSteamAPICall != 0)
SteamAPI_UnregisterCallResult(this, this->m_hSteamAPICall);
this->m_hSteamAPICall = 0;
this->m_iCallback = 0;
}
bool BlitzCallback::IsGameServer() {
return (this->m_nCallbackFlags & this->k_ECallbackFlagsGameServer) != 0;
}
void BlitzCallback::SetGameServer(bool bIsGameServer) {
this->m_nCallbackFlags &= ~k_ECallbackFlagsGameServer;
if (bIsGameServer)
this->m_nCallbackFlags |= k_ECallbackFlagsGameServer;
}
// DLL-Callables
DLL_FUNCTION(BlitzCallback*) BS_Callback_Create(BP_BlitzFunction3_t pFunctionPointer) {
return new BlitzCallback(pFunctionPointer);
}
DLL_FUNCTION(void) BS_Callback_Destroy(BlitzCallback* pCallback) {
delete pCallback;
}
DLL_FUNCTION(int32_t) BS_Callback_IsRegistered(BlitzCallback* pCallback) {
return pCallback->IsRegistered();
}
DLL_FUNCTION(int32_t) BS_Callback_IsGameServer(BlitzCallback* pCallback) {
return pCallback->IsGameServer();
}
DLL_FUNCTION(int32_t) BS_Callback_SetGameServerFlag(BlitzCallback* pCallback, int32_t bIsGameServer) {
bool isGameServer = pCallback->IsGameServer();
pCallback->SetGameServer(!!bIsGameServer);
return isGameServer;
}
DLL_FUNCTION(void) BS_Callback_Register(BlitzCallback* pCallback, uint32_t iCallback) {
pCallback->Register(iCallback);
}
DLL_FUNCTION(void) BS_Callback_Unregister(BlitzCallback* pCallback) {
pCallback->Unregister();
}
DLL_FUNCTION(void) BS_Callback_RegisterResult(BlitzCallback* pCallback, SteamAPICall_t* pSteamAPICall, uint32_t iCallback) {
pCallback->RegisterResult(*pSteamAPICall, iCallback);
}
DLL_FUNCTION(void) BS_Callback_UnregisterResult(BlitzCallback* pCallback) {
pCallback->UnregisterResult();
}
-59
View File
@@ -1,59 +0,0 @@
// BlitzSteam - Steam wrapper for Blitz
// Copyright (C) 2015 Xaymar (Michael Fabian Dirks)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
BS_I#include "BlitzSteam.h"
#include "BlitzPointer.h"
#include <list>
#include <vector>
#include <map>
class BlitzCallback : public CCallbackBase {
public:
BlitzCallback(BP_BlitzFunction3_t pFunctionPointer);
~BlitzCallback();
virtual void Run(void *pvParam);
virtual void Run(void *pvParam, bool bIOFailure, SteamAPICall_t hSteamAPICall);
virtual int GetCallbackSizeBytes();
bool IsRegistered();
bool IsGameServer();
void SetGameServer(bool bIsGameServer);
void Register(uint32_t iCallback);
void Unregister();
void RegisterResult(SteamAPICall_t hSteamAPICall, uint32_t iCallback);
void UnregisterResult();
private:
BP_BlitzFunction3_t m_pFunctionPointer;
uint32_t m_iCallback;
SteamAPICall_t m_hSteamAPICall;
};
DLL_FUNCTION(BlitzCallback*) BS_Callback_Create(BP_BlitzFunction3_t pFunctionPointer);
DLL_FUNCTION(void) BS_Callback_Destroy(BlitzCallback* pCallback);
DLL_FUNCTION(int32_t) BS_Callback_IsRegistered(BlitzCallback* pCallback);
DLL_FUNCTION(int32_t) BS_Callback_IsGameServer(BlitzCallback* pCallback);
DLL_FUNCTION(int32_t) BS_Callback_SetGameServerFlag(BlitzCallback* pCallback, int32_t isGameServer);
DLL_FUNCTION(void) BS_Callback_Register(BlitzCallback* pCallback, uint32_t iCallback);
DLL_FUNCTION(void) BS_Callback_Unregister(BlitzCallback* pCallback);
DLL_FUNCTION(void) BS_Callback_RegisterResult(BlitzCallback* pCallback, SteamAPICall_t* pSteamAPICall, uint32_t iCallback);
DLL_FUNCTION(void) BS_Callback_UnregisterResult(BlitzCallback* pCallback);
+2 -1
View File
@@ -14,7 +14,8 @@
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
BS_I
#pragma once
// Types of Blitz Functions.
typedef int32_t(__stdcall *BP_BlitzFunction0_t)();
typedef int32_t(__stdcall *BP_BlitzFunction1_t)(int32_t);
+62 -5
View File
@@ -24,10 +24,67 @@ DLL_FUNCTION(const char*) BS_Helper_FormatUnixTime(uint32_t unTime, const char*
delete tm;
return output;
}
DLL_FUNCTION(double_t*) BS_Helper_CreateDouble(float_t value) {
return new double_t(value);
}
DLL_FUNCTION(void) BS_Helper_DeleteDouble(double_t* pDouble) {
delete pDouble;
DLL_FUNCTION(void) BS_Helper_CopyMemoryIntMangle(void* pSource, void* pDest, int32_t iMangling,
uint32_t iSourceW, uint32_t iSourceH, uint32_t iDestW, uint32_t iDestH,
uint32_t iAreaX, uint32_t iAreaY, uint32_t iAreaW, uint32_t iAreaH) {
int8_t iMangleByte0 = static_cast<int8_t>((iMangling & 0xFF));
int8_t iMangleByte1 = static_cast<int8_t>((iMangling & 0xFF00) >> 8);
int8_t iMangleByte2 = static_cast<int8_t>((iMangling & 0xFF0000) >> 16);
int8_t iMangleByte3 = static_cast<int8_t>((iMangling & 0xFF000000) >> 24);
if (pSource > pDest) {
// Start at beginning
for (uint32_t iY = iAreaY; iY < (iAreaY + iAreaH); iY++) {
// Only do this once per loop
for (uint32_t iX = iAreaX; iX < (iAreaX + iAreaW); iX++) {
// Could technically optimize the following into single instructions, but this is fast enough for now.
uint32_t* pSourceOff = reinterpret_cast<uint32_t*>(pSource) + ((iSourceW * iY) + iX);
uint32_t* pDestOff = reinterpret_cast<uint32_t*>(pDest) + ((iDestW * iY) + iX);
// Allow Mangling using just a single integer and checking on the fly if it's positive or negative to branch out to the correct shift.
*pDestOff =
(iMangleByte0 > 0 ?
(*pSourceOff & 0xFF) >> iMangleByte0 :
(*pSourceOff & 0xFF) << -iMangleByte0)
+ (iMangleByte1 > 0 ?
(*pSourceOff & 0xFF00) >> iMangleByte1 :
(*pSourceOff & 0xFF00) << -iMangleByte1)
+ (iMangleByte2 > 0 ?
(*pSourceOff & 0xFF0000) >> iMangleByte2 :
(*pSourceOff & 0xFF0000) << -iMangleByte2)
+ (iMangleByte3 > 0 ?
(*pSourceOff & 0xFF000000) >> iMangleByte3 :
(*pSourceOff & 0xFF000000) << -iMangleByte3);
}
}
} else {
//ToDo, mirror the above. Instead of adding we subtract.
//// Start at end
//for (uint32_t iY = y + h; iY >= y; iY--) {
// pSourceOff = reinterpret_cast<uint32_t*>(pSource) + ((tw * iY) + x);
// pDestOff = reinterpret_cast<uint32_t*>(pDest) + ((tw * iY) + x);
// for (uint32_t iX = x + w; iX >= x; iX--) {
// *pDestOff =
// (iMangleByte0 > 0 ?
// (*pSourceOff & 0xFF) >> iMangleByte0 :
// (*pSourceOff & 0xFF) << -iMangleByte0)
// + (iMangleByte1 > 0 ?
// (*pSourceOff & 0xFF00) >> iMangleByte1 :
// (*pSourceOff & 0xFF00) << -iMangleByte1)
// + (iMangleByte2 > 0 ?
// (*pSourceOff & 0xFF0000) >> iMangleByte2 :
// (*pSourceOff & 0xFF0000) << -iMangleByte2)
// + (iMangleByte3 > 0 ?
// (*pSourceOff & 0xFF000000) >> iMangleByte3 :
// (*pSourceOff & 0xFF000000) << -iMangleByte3);
// // Above is some mangling magic i learned in some source code. Allows you to define a byte bit shift using a single integer.
// pSourceOff -= 1;
// pDestOff -= 1;
// }
//}
}
}
+3 -1
View File
@@ -14,6 +14,8 @@
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
BS_I#include "BlitzSteam.h"
#pragma once
#include "BlitzSteam.h"
#include <time.h>
DLL_FUNCTION(const char*) BS_Helper_FormatUnixTime(uint32_t unTime, const char* pchFormat);
-61
View File
@@ -1,61 +0,0 @@
// BlitzSteam - Steam wrapper for Blitz
// Copyright (C) 2015 Xaymar (Michael Fabian Dirks)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "Memory.h"
DLL_FUNCTION(void*) BS_Memory_Alloc(uint32_t iSize) {
return malloc(iSize);
}
DLL_FUNCTION(void*) BS_Memory_ReAlloc(void* pMemory, uint32_t iNewSize) {
return realloc(pMemory, iNewSize);
}
DLL_FUNCTION(void) BS_Memory_Free(void* pMemory) {
free(pMemory);
}
DLL_FUNCTION(uint8_t) BS_Memory_PeekByte(void* pMemory, uint32_t offset) {
return *(reinterpret_cast<uint8_t*>(pMemory) + offset);
}
DLL_FUNCTION(uint16_t) BS_Memory_PeekShort(void* pMemory, uint32_t offset) {
return *(uint16_t*)(reinterpret_cast<uint8_t*>(pMemory) + offset);
}
DLL_FUNCTION(uint32_t) BS_Memory_PeekInt(void* pMemory, uint32_t offset) {
return *(uint32_t*)(reinterpret_cast<uint8_t*>(pMemory) + offset);
}
DLL_FUNCTION(float_t) BS_Memory_PeekFloat(void* pMemory, uint32_t offset) {
return *(float_t*)(reinterpret_cast<uint8_t*>(pMemory) + offset);
}
DLL_FUNCTION(void) BS_Memory_PokeByte(void* pMemory, uint32_t offset, uint8_t value) {
*((reinterpret_cast<uint8_t*>(pMemory) + offset)) = value;
}
DLL_FUNCTION(void) BS_Memory_PokeShort(void* pMemory, uint32_t offset, uint16_t value) {
*(reinterpret_cast<uint16_t*>(reinterpret_cast<uint8_t*>(pMemory) + offset)) = value;
}
DLL_FUNCTION(void) BS_Memory_PokeInt(void* pMemory, uint32_t offset, uint32_t value) {
*(reinterpret_cast<uint32_t*>(reinterpret_cast<uint8_t*>(pMemory) + offset)) = value;
}
DLL_FUNCTION(void) BS_Memory_PokeFloat(void* pMemory, uint32_t offset, float_t value) {
*(reinterpret_cast<float_t*>(reinterpret_cast<uint8_t*>(pMemory) + offset)) = value;
}
-29
View File
@@ -1,29 +0,0 @@
// BlitzSteam - Steam wrapper for Blitz
// Copyright (C) 2015 Xaymar (Michael Fabian Dirks)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
BS_I#include "BlitzSteam.h"
DLL_FUNCTION(void*) BS_Memory_Alloc(uint32_t iSize);
DLL_FUNCTION(void*) BS_Memory_ReAlloc(void* pMemory, uint32_t iNewSize);
DLL_FUNCTION(void) BS_Memory_Free(void* pMemory);
DLL_FUNCTION(uint8_t) BS_Memory_PeekByte(void* pMemory, uint32_t offset);
DLL_FUNCTION(uint16_t) BS_Memory_PeekShort(void* pMemory, uint32_t offset);
DLL_FUNCTION(uint32_t) BS_Memory_PeekInt(void* pMemory, uint32_t offset);
DLL_FUNCTION(float_t) BS_Memory_PeekFloat(void* pMemory, uint32_t offset);
DLL_FUNCTION(void) BS_Memory_PokeByte(void* pMemory, uint32_t offset, uint8_t value);
DLL_FUNCTION(void) BS_Memory_PokeShort(void* pMemory, uint32_t offset, uint16_t value);
DLL_FUNCTION(void) BS_Memory_PokeInt(void* pMemory, uint32_t offset, uint32_t value);
DLL_FUNCTION(void) BS_Memory_PokeFloat(void* pMemory, uint32_t offset, float_t value);