* Fix BlitzSteam.h including uneccessary headers.

* Rename Callback class to BlitzCallback and add state-aware functionality (Register, RegisterResult, automatic unregistering).
* Add functionality to delete Long pointers.
* Add functionality to create and delete Doubles.
* Add memory management functionality.
* Reimplement SteamController Wrapper.
* Implement SteamHTMLSurface Wrapper.
* Fix up Declaration File and make it more descriptive.
* Add Blitz Examples and Project.
This commit is contained in:
Michael Dirks
2016-02-23 13:25:34 +01:00
parent 0ebbd7e9a0
commit 30beba2ada
27 changed files with 2190 additions and 699 deletions
+131
View File
@@ -0,0 +1,131 @@
// 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"
BlitzCallback::BlitzCallback(BP_Function3_t pFunctionPointer) {
this->m_pFunctionPointer = pFunctionPointer;
}
BlitzCallback::~BlitzCallback() {
this->Unregister();
this->UnregisterResult();
}
int BlitzCallback::GetCallbackSizeBytes() {
return sizeof(BlitzCallback);
}
void BlitzCallback::Run(void *pvParam) {
if (this->m_hSteamAPICall != 0)
this->m_hSteamAPICall = 0; // Caller unregisters for us.
BP_CallFunction3(m_pFunctionPointer, reinterpret_cast<uint32_t>(pvParam), 0, 0);
}
void BlitzCallback::Run(void *pvParam, bool bIOFailure, SteamAPICall_t hSteamAPICall) {
if (this->m_hSteamAPICall != 0)
this->m_hSteamAPICall = 0; // Caller unregisters for us.
BP_CallFunction3(m_pFunctionPointer, reinterpret_cast<uint32_t>(pvParam), (uint32_t)bIOFailure, (uint32_t)&hSteamAPICall);
}
bool BlitzCallback::IsRegistered() {
return (this->m_nCallbackFlags & this->k_ECallbackFlagsRegistered) != 0;
}
void BlitzCallback::Register(uint32_t iCallback) {
if (!this->IsRegistered())
SteamAPI_RegisterCallback(this, iCallback);
}
void BlitzCallback::Unregister() {
if (this->IsRegistered())
SteamAPI_UnregisterCallback(this);
}
void BlitzCallback::RegisterResult(SteamAPICall_t hSteamAPICall) {
if (this->m_hSteamAPICall == 0) {
SteamAPI_RegisterCallResult(this, hSteamAPICall);
this->m_hSteamAPICall = hSteamAPICall;
}
}
void BlitzCallback::UnregisterResult()
{
if (this->m_hSteamAPICall != 0) {
SteamAPI_UnregisterCallResult(this, this->m_hSteamAPICall);
this->m_hSteamAPICall = 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_Function3_t pFunctionPointer) {
#pragma comment(linker, "/EXPORT:BS_Callback_Create=_BS_Callback_Create@4")
return new BlitzCallback(pFunctionPointer);
}
DLL_FUNCTION(void) BS_Callback_Destroy(BlitzCallback* pCallback) {
#pragma comment(linker, "/EXPORT:BS_Callback_Destroy=_BS_Callback_Destroy@4")
delete pCallback;
}
DLL_FUNCTION(int32_t) BS_Callback_IsRegistered(BlitzCallback* pCallback) {
#pragma comment(linker, "/EXPORT:BS_Callback_IsRegistered=_BS_Callback_IsRegistered@4")
return pCallback->IsRegistered();
}
DLL_FUNCTION(int32_t) BS_Callback_IsGameServer(BlitzCallback* pCallback) {
#pragma comment(linker, "/EXPORT:BS_Callback_IsGameServer=_BS_Callback_IsGameServer@4")
return pCallback->IsGameServer();
}
DLL_FUNCTION(int32_t) BS_Callback_SetGameServerFlag(BlitzCallback* pCallback, int32_t bIsGameServer) {
#pragma comment(linker, "/EXPORT:BS_Callback_SetGameServerFlag=_BS_Callback_SetGameServerFlag@8")
bool isGameServer = pCallback->IsGameServer();
pCallback->SetGameServer(!!bIsGameServer);
return isGameServer;
}
DLL_FUNCTION(void) BS_Callback_Register(BlitzCallback* pCallback, uint32_t iCallback) {
#pragma comment(linker, "/EXPORT:BS_Callback_Register=_BS_Callback_Register@8")
pCallback->Register(iCallback);
}
DLL_FUNCTION(void) BS_Callback_Unregister(BlitzCallback* pCallback) {
#pragma comment(linker, "/EXPORT:BS_Callback_Unregister=_BS_Callback_Unregister@4")
pCallback->Unregister();
}
DLL_FUNCTION(void) BS_Callback_RegisterResult(BlitzCallback* pCallback, SteamAPICall_t* pSteamAPICall) {
#pragma comment(linker, "/EXPORT:BS_Callback_RegisterResult=_BS_Callback_RegisterResult@8")
pCallback->RegisterResult(*pSteamAPICall);
}
DLL_FUNCTION(void) BS_Callback_UnregisterResult(BlitzCallback* pCallback) {
#pragma comment(linker, "/EXPORT:BS_Callback_UnregisterResult=_BS_Callback_UnregisterResult@4")
pCallback->UnregisterResult();
}
+55
View File
@@ -0,0 +1,55 @@
// 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/>.
#pragma once
#include "BlitzSteam.h"
#include "BlitzPointer.h"
class BlitzCallback : public CCallbackBase {
public:
BlitzCallback(BP_Function3_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);
void UnregisterResult();
private:
BP_Function3_t m_pFunctionPointer;
SteamAPICall_t m_hSteamAPICall;
};
DLL_FUNCTION(BlitzCallback*) BS_Callback_Create(BP_Function3_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);
DLL_FUNCTION(void) BS_Callback_UnregisterResult(BlitzCallback* pCallback);
-45
View File
@@ -1,45 +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 "Callbacks.h"
// Callbacks
void BS_Callback::Run(void *pvParam) {
BP_CallFunction3(bbRunFunction, reinterpret_cast<uint32_t>(pvParam), 0, 0);
}
void BS_Callback::Run(void *pvParam, bool bIOFailure, SteamAPICall_t hSteamAPICall) {
BP_CallFunction3(bbRunFunction, reinterpret_cast<uint32_t>(pvParam), (uint32_t)bIOFailure, reinterpret_cast<uint32_t>(&hSteamAPICall));
}
int BS_Callback::GetCallbackSizeBytes() {
return sizeof(BS_Callback);
}
// DLL-Callables
DLL_FUNCTION(BS_Callback*) BS_Callback_Create(uint32_t fpFunctionPointer) {
BS_Callback* lpCallback = new BS_Callback();
lpCallback->bbRunFunction = (void*)fpFunctionPointer;
return lpCallback;
}
#pragma comment(linker, "/EXPORT:BS_Callback_Create=_BS_Callback_Create@4")
DLL_FUNCTION(void) BS_Callback_Destroy(BS_Callback* lpCallback) {
if (lpCallback != nullptr) {
delete lpCallback;
}
}
#pragma comment(linker, "/EXPORT:BS_Callback_Destroy=_BS_Callback_Destroy@4")
-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/>.
#pragma once
#include "BlitzSteam.h"
class BS_Callback : CCallbackBase {
public:
void* bbRunFunction;
virtual void Run(void *pvParam);
virtual void Run(void *pvParam, bool bIOFailure, SteamAPICall_t hSteamAPICall);
virtual int GetCallbackSizeBytes();
};
DLL_FUNCTION(BS_Callback*) BS_Callback_Create(uint32_t fpFunctionPointer);
DLL_FUNCTION(void) BS_Callback_Destroy(BS_Callback* lpCallback);
+16 -1
View File
@@ -17,6 +17,7 @@
#include "Helper.h"
DLL_FUNCTION(const char*) BS_Helper_FormatUnixTime(uint32_t unTime, const char* pchFormat) {
#pragma comment(linker, "/EXPORT:BS_Helper_FormatUnixTime=_BS_Helper_FormatUnixTime@8")
char* output = new char[strlen(pchFormat) * 4];
time_t t = unTime;
struct tm *tm = localtime(&t);
@@ -24,4 +25,18 @@ DLL_FUNCTION(const char*) BS_Helper_FormatUnixTime(uint32_t unTime, const char*
delete tm;
return output;
}
#pragma comment(linker, "/EXPORT:BS_Helper_FormatUnixTime=_BS_Helper_FormatUnixTime@8")
DLL_FUNCTION(void) BS_Helper_DeleteLong(uint64_t* pLong) {
#pragma comment(linker, "/EXPORT:BS_Helper_DeleteLong=_BS_Helper_DeleteLong@4")
delete pLong;
}
DLL_FUNCTION(double_t*) BS_Helper_CreateDouble(float_t value) {
#pragma comment(linker, "/EXPORT:BS_Helper_CreateDouble=_BS_Helper_CreateDouble@4")
return new double_t(value);
}
DLL_FUNCTION(void) BS_Helper_DeleteDouble(double_t* pDouble) {
#pragma comment(linker, "/EXPORT:BS_Helper_DeleteDouble=_BS_Helper_DeleteDouble@4")
delete pDouble;
}
+72
View File
@@ -0,0 +1,72 @@
// 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) {
#pragma comment(linker, "/EXPORT:BS_Memory_Alloc=_BS_Memory_Alloc@4")
return malloc(iSize);
}
DLL_FUNCTION(void*) BS_Memory_ReAlloc(void* pMemory, uint32_t iNewSize) {
#pragma comment(linker, "/EXPORT:BS_Memory_ReAlloc=_BS_Memory_ReAlloc@8")
return realloc(pMemory, iNewSize);
}
DLL_FUNCTION(void) BS_Memory_Free(void* pMemory) {
#pragma comment(linker, "/EXPORT:BS_Memory_Free=_BS_Memory_Free@4")
free(pMemory);
}
DLL_FUNCTION(uint8_t) BS_Memory_PeekByte(void* pMemory, uint32_t offset) {
#pragma comment(linker, "/EXPORT:BS_Memory_PeekByte=_BS_Memory_PeekByte@8")
return *(reinterpret_cast<uint8_t*>(pMemory) + offset);
}
DLL_FUNCTION(uint16_t) BS_Memory_PeekShort(void* pMemory, uint32_t offset) {
#pragma comment(linker, "/EXPORT:BS_Memory_PeekShort=_BS_Memory_PeekShort@8")
return *(uint16_t*)(reinterpret_cast<uint8_t*>(pMemory) + offset);
}
DLL_FUNCTION(uint32_t) BS_Memory_PeekInt(void* pMemory, uint32_t offset) {
#pragma comment(linker, "/EXPORT:BS_Memory_PeekInt=_BS_Memory_PeekInt@8")
return *(uint32_t*)(reinterpret_cast<uint8_t*>(pMemory) + offset);
}
DLL_FUNCTION(float_t) BS_Memory_PeekFloat(void* pMemory, uint32_t offset) {
#pragma comment(linker, "/EXPORT:BS_Memory_PeekFloat=_BS_Memory_PeekFloat@8")
return *(float_t*)(reinterpret_cast<uint8_t*>(pMemory) + offset);
}
DLL_FUNCTION(void) BS_Memory_PokeByte(void* pMemory, uint32_t offset, uint8_t value) {
#pragma comment(linker, "/EXPORT:BS_Memory_PokeByte=_BS_Memory_PokeByte@12")
*((reinterpret_cast<uint8_t*>(pMemory) + offset)) = value;
}
DLL_FUNCTION(void) BS_Memory_PokeShort(void* pMemory, uint32_t offset, uint16_t value) {
#pragma comment(linker, "/EXPORT:BS_Memory_PokeShort=_BS_Memory_PokeShort@12")
*(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) {
#pragma comment(linker, "/EXPORT:BS_Memory_PokeInt=_BS_Memory_PokeInt@12")
*(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) {
#pragma comment(linker, "/EXPORT:BS_Memory_PokeFloat=_BS_Memory_PokeFloat@12")
*(reinterpret_cast<float_t*>(reinterpret_cast<uint8_t*>(pMemory) + offset)) = value;
}
+30
View File
@@ -0,0 +1,30 @@
// 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/>.
#pragma once
#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);