diff --git a/BlitzUtility.vcxproj b/BlitzUtility.vcxproj index 725ecda..5524bd7 100644 --- a/BlitzUtility.vcxproj +++ b/BlitzUtility.vcxproj @@ -158,16 +158,19 @@ - + + + + @@ -175,10 +178,12 @@ - + + + @@ -186,6 +191,7 @@ + diff --git a/BlitzUtility.vcxproj.filters b/BlitzUtility.vcxproj.filters index 6ff0a56..b3f7986 100644 --- a/BlitzUtility.vcxproj.filters +++ b/BlitzUtility.vcxproj.filters @@ -48,6 +48,12 @@ {13f1a82e-2123-4652-a573-2dd8235ae033} + + {5545a0db-1127-4588-8522-680ec51473e0} + + + {c14c025c-cae9-4d80-abe0-f04895a8f944} + @@ -95,9 +101,18 @@ Source Files\Type - + + Source Files\Utility + + + Source Files\System + + Source Files\Time + + Source Files\System + @@ -145,9 +160,18 @@ Header Files\Type - + + Header Files\Utility + + + Header Files\System + + Header Files\Time + + Header Files\System + diff --git a/Resources/BlitzUtility.bb b/Resources/BlitzUtility.bb index 3179630..c6f1544 100644 --- a/Resources/BlitzUtility.bb +++ b/Resources/BlitzUtility.bb @@ -86,7 +86,7 @@ End Type Function BU_Helper_Window_LockPointer(HWND% = 0) If HWND = 0 Then - BU_User32_ClipCursor(0) + BU_User32_ClipCursorEx(0) Else Local tRect.BU_Rectangle = New BU_Rectangle @@ -105,6 +105,8 @@ Function BU_Helper_Window_LockPointer(HWND% = 0) End Function Function BU_Helper_Window_LockPointerAuto(HWND=0) + If HWND = 0 Then HWND = SystemProperty("AppHwnd") + If BU_User32_GetActiveWindow() = HWND Then BU_Helper_Window_LockPointer(HWND) Else @@ -159,6 +161,8 @@ Function BU_Helper_Window_MakeBorderless(HWND=0) End Function Function BU_Helper_Window_Center(HWND=0, Monitor=0) + If HWND = 0 Then HWND = SystemProperty("AppHwnd") + Local displayEnumerator = BU_DisplayEnumerator_Create() Local displayAmount = BU_DisplayEnumerator_Enumerate(displayEnumerator) If Monitor >= displayAmount Then Monitor = displayAmount - 1 @@ -195,6 +199,8 @@ Function BU_Helper_Window_Center(HWND=0, Monitor=0) End Function Function BU_Helper_Window_Fill(HWND=0, Monitor=0) + If HWND = 0 Then HWND = SystemProperty("AppHwnd") + Local displayEnumerator = BU_DisplayEnumerator_Create() Local displayAmount = BU_DisplayEnumerator_Enumerate(displayEnumerator) If Monitor >= displayAmount Then Monitor = displayAmount - 1 diff --git a/Resources/BlitzUtility.decls b/Resources/BlitzUtility.decls index 4fe90cd..7f88509 100644 --- a/Resources/BlitzUtility.decls +++ b/Resources/BlitzUtility.decls @@ -15,8 +15,9 @@ ; along with this program. If not, see . .lib "BlitzUtility.dll" -; Container ------------------------------------------------------------------- -; -- List (Single Element) +;---------------------------------------------------------------- +;! Container - List (Element-wide) +;---------------------------------------------------------------- BU_List_Create%(element*) BU_List_Destroy%(list%) BU_List_First%(list%) @@ -28,12 +29,100 @@ BU_List_After%(list%, other*) BU_List_Insert(list%, element*) BU_List_InsertEx(list%, element*, other*) BU_List_Remove(list%, element*) -; -- TypeList (Single Type) + +;---------------------------------------------------------------- +;! Container - TypeList (Type-wide) +;---------------------------------------------------------------- BU_TypeList_Create%(obj*) BU_TypeList_Activate(list%) BU_TypeList_Deactivate(list%) BU_TypeList_Destroy(list%) +;---------------------------------------------------------------- +;! System - FileSystem +;---------------------------------------------------------------- +BU_FileSystem_WriteFile%(Path$) +;@desc: Opens or creates a file for writing only. Truncates existing content. +BU_FileSystem_OpenFile%(Path$) +;@desc: Opens an existing file for reading or writing. +BU_FileSystem_ReadFile%(Path$) +;@desc: Opens an existing file for reading only. +BU_FileSystem_CloseFile(File%) +;@desc: Closes an open file. +BU_FileSystem_FlushFile(File%) +;@desc: Flushes all buffers to disk for the file. +BU_FileSystem_EOF%(File%) +;@desc: Checks if the File handle is valid and not at the end of the file. +;@return: +; 0 = Good, Not End Of File +; 1 = End Of File +; -1 = Bad File Handle +; -2 = Failed to do internal action. +BU_FileSystem_SeekFile(File%, Pos%) +BU_FileSystem_SeekFileIn(File%, Pos%) +BU_FileSystem_SeekFileOut(File%, Pos%) +BU_FileSystem_FilePos%(File%) : "BU_FileSystem_FilePosIn" +BU_FileSystem_FilePosIn%(File%) +BU_FileSystem_FilePosOut%(File%) + +BU_FileSystem_WriteByte(File%, Value%) +BU_FileSystem_ReadByte%(File%) +BU_FileSystem_WriteShort(File%, Value%) +BU_FileSystem_ReadShort%(File%) +BU_FileSystem_WriteInt(File%, Value%) +BU_FileSystem_ReadInt%(File%) +BU_FileSystem_WriteFloat(File%, Value#) : "BU_FileSystem_WriteInt" +BU_FileSystem_ReadFloat#(File%) : "BU_FileSystem_ReadInt" + +;---------------------------------------------------------------- +;! System - Threading +;---------------------------------------------------------------- +BU_Thread_Create%(pFunction%, pData%, uiStackSize%, bIsSuspended%) +BU_Thread_Destroy(pThread%) +BU_Thread_Terminate(pThread%, iExitCode%) +BU_Thread_Suspend%(pThread%) +BU_Thread_Resume%(pThread%) +BU_Thread_Wait%(pThread%, iTimeout%) +BU_Thread_GetExitCode%(pThread%) +BU_Thread_Exit(iExitCode%) +BU_Mutex_Create%() +BU_Mutex_Destroy(pMutex%) +BU_Mutex_Lock%(pMutex%, iTimeout%) +BU_Mutex_Unlock%(pMutex%) + +;---------------------------------------------------------------- +;! Time - Time +;---------------------------------------------------------------- +BU_Time_Now%() +BU_Time_Create%(seconds%, minutes%, hours%, days%, months%, years%, isDST%) +BU_Time_Destroy(pTime%) +BU_Time_Format$(pTime%, formatString$) + +;---------------------------------------------------------------- +;! Time - Timer +;---------------------------------------------------------------- +BU_Timer_Create%(Interval%, hwnd%) : "_BU_Timer_Create@8" +BU_Timer_Destroy%(Timer%) : "_BU_Timer_Destroy@4" +BU_Timer_Wait%(Timer%) : "_BU_Timer_Wait@4" + +;---------------------------------------------------------------- +;! Time - SystemClock +;---------------------------------------------------------------- +BU_SystemClock_Now%() +BU_SystemClock_Destroy(pSystemClock%) +BU_SystemClock_FromTime%(pTime%) +BU_SystemClock_AsTime%(pSystemClock%) + +;---------------------------------------------------------------- +;! Time - HighResolutionClock +;---------------------------------------------------------------- +BU_HighResolutionClock_Now%() +BU_HighResolutionClock_Destroy(pHighResolutionClock%) +BU_HighResolutionClock_Duration%(pHighResolutionClock%, pOther%) +BU_HighResolutionClock_DurationLL%(pHighResolutionClock%, pOther%) +BU_HighResolutionClock_DurationF#(pHighResolutionClock%, pOther%) +BU_HighResolutionClock_DurationD%(pHighResolutionClock%, pOther%) + ; Database -------------------------------------------------------------------- ; -- SQLite3 ; Core @@ -144,29 +233,6 @@ BU_SQLite_Value_SubType%(pValue%) BU_SQLite_Value_Duplicate%(pValue%) BU_SQLite_Value_Free(pValue%) -; Time ------------------------------------------------------------------------ -; -- Time -BU_Time_Now%() -BU_Time_Create%(seconds%, minutes%, hours%, days%, months%, years%, isDST%) -BU_Time_Destroy(pTime%) -BU_Time_Format$(pTime%, formatString$) -; -- Timer -BU_Timer_Create%(Interval%, hwnd%) : "_BU_Timer_Create@8" -BU_Timer_Destroy%(Timer%) : "_BU_Timer_Destroy@4" -BU_Timer_Wait%(Timer%) : "_BU_Timer_Wait@4" -; -- SystemClock -BU_SystemClock_Now%() -BU_SystemClock_Destroy(pSystemClock%) -BU_SystemClock_FromTime%(pTime%) -BU_SystemClock_AsTime%(pSystemClock%) -; -- HighResolutionClock -BU_HighResolutionClock_Now%() -BU_HighResolutionClock_Destroy(pHighResolutionClock%) -BU_HighResolutionClock_Duration%(pHighResolutionClock%, pOther%) -BU_HighResolutionClock_DurationLL%(pHighResolutionClock%, pOther%) -BU_HighResolutionClock_DurationF#(pHighResolutionClock%, pOther%) -BU_HighResolutionClock_DurationD%(pHighResolutionClock%, pOther%) - ; Types - Long ---------------------------------------------------------------- BU_Long_New%() :"_BU_Long_New@0" BU_Long_Copy%(pThis%) :"_BU_Long_Copy@4" @@ -267,6 +333,9 @@ BU_MassOp_Create%(length%) BU_MassOp_Destroy(massop%) BU_MassOp_Instruction(massop%, index%, type%, code%, leftOperand%, rightOperand%, result%) BU_MassOp_Run(massop%) +; -- ThreadWrapper +BU_ThreadWrapper_Create%(pFunction%, pData%) +BU_ThreadWrapper_Destroy(pThreadWrapper%) ; -- Window Message Handler BU_WindowMessageHandler_Install(hwnd%) BU_WindowMessageHandler_Uninstall(hwnd%) @@ -274,6 +343,7 @@ BU_WindowMessageHandler_Message_Close%(hwnd%) BU_WindowMessageHandler_Message_Destroy%(hwnd%) BU_WindowMessageHandler_Message_Resize%(hwnd%, point*) + ; Helpers --------------------------------------------------------------------- .lib " " ; -- Blitz Functions @@ -282,6 +352,7 @@ BU_Helper_Window_LockPointerAuto(HWND%) BU_Helper_Window_MakeBorderless(HWND%) BU_Helper_Window_Center(HWND%, Monitor%) BU_Helper_Window_Fill(HWND%, Monitor%) + ; -- Windows API (User32) .lib "User32.dll" BU_User32_ClientToScreen%(hwnd%, point*) : "ClientToScreen" @@ -298,6 +369,7 @@ BU_User32_GetClientRect%(hwnd%, rect*) : "GetClientRect" BU_User32_GetClientRectEx%(hwnd%, rect%) : "GetClientRect" BU_User32_SetWindowPos%(hwnd%, hWndInsertAfter%, x%, y%, cx%, cy%, wFlags%) : "SetWindowPos" BU_User32_MessageBox%(hwnd%, lpText$, lpCaption$, uType%) : "MessageBoxA" + ; -- Windows API (Kernel32) .lib "Kernel32.dll" BU_Kernel32_FlushFileBuffers%(hFile%) : "FlushFileBuffers" diff --git a/System/FileSystem.cpp b/System/FileSystem.cpp new file mode 100644 index 0000000..ffc95f4 --- /dev/null +++ b/System/FileSystem.cpp @@ -0,0 +1,128 @@ +// BlitzUtility - Expanding the normal Blitz functionality. +// 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 . + +#include "FileSystem.h" + +using namespace std; + +DLL_FUNCTION(std::fstream*) BU_FileSystem_WriteFile(const char* path) { +#pragma comment(linker, "/EXPORT:BU_FileSystem_WriteFile=_BU_FileSystem_WriteFile@4") + std::fstream* file = new std::fstream(); + file->open(path, ios::in | ios::out || ios::trunc | ios::binary); + return file; +} + +DLL_FUNCTION(std::fstream*) BU_FileSystem_OpenFile(const char* path) { +#pragma comment(linker, "/EXPORT:BU_FileSystem_OpenFile=_BU_FileSystem_OpenFile@4") + std::fstream* file = new std::fstream(); + file->open(path, ios::in | ios::out | ios::binary); + return file; +} + +DLL_FUNCTION(std::fstream*) BU_FileSystem_ReadFile(const char* path) { +#pragma comment(linker, "/EXPORT:BU_FileSystem_ReadFile=_BU_FileSystem_ReadFile@4") + std::fstream* file = new std::fstream(); + file->open(path, ios::in | ios::binary); + return file; +} + +DLL_FUNCTION(void) BU_FileSystem_CloseFile(std::fstream* file) { +#pragma comment(linker, "/EXPORT:BU_FileSystem_CloseFile=_BU_FileSystem_CloseFile@4") + file->close(); + delete file; +} + +DLL_FUNCTION(void) BU_FileSystem_FlushFile(std::fstream* file) { +#pragma comment(linker, "/EXPORT:BU_FileSystem_FlushFile=_BU_FileSystem_FlushFile@4") + file->flush(); +} + +DLL_FUNCTION(int32_t) BU_FileSystem_EOF(std::fstream* file) { +#pragma comment(linker, "/EXPORT:BU_FileSystem_EOF=_BU_FileSystem_EOF@4") + if (file->eof()) + return 1; + if (file->bad()) + return -1; + if (file->fail()) + return -2; + + return 0; +} + +DLL_FUNCTION(void) BU_FileSystem_SeekFile(std::fstream* file, int32_t pos) { +#pragma comment(linker, "/EXPORT:BU_FileSystem_SeekFile=_BU_FileSystem_SeekFile@8") + file->seekg(pos); + file->seekp(pos); +} + +DLL_FUNCTION(void) BU_FileSystem_SeekFileIn(std::fstream* file, int32_t pos) { +#pragma comment(linker, "/EXPORT:BU_FileSystem_SeekFileIn=_BU_FileSystem_SeekFileIn@8") + file->seekg(pos); +} + +DLL_FUNCTION(void) BU_FileSystem_SeekFileOut(std::fstream* file, int32_t pos) { +#pragma comment(linker, "/EXPORT:BU_FileSystem_SeekFileOut=_BU_FileSystem_SeekFileOut@8") + file->seekp(pos); +} + +DLL_FUNCTION(int32_t) BU_FileSystem_FilePosIn(std::fstream* file) { +#pragma comment(linker, "/EXPORT:BU_FileSystem_FilePosIn=_BU_FileSystem_FilePosIn@4") + return (int32_t)file->tellg(); +} + +DLL_FUNCTION(int32_t) BU_FileSystem_FilePosOut(std::fstream* file) { +#pragma comment(linker, "/EXPORT:BU_FileSystem_FilePosOut=_BU_FileSystem_FilePosOut@4") + return (int32_t)file->tellp(); +} + +DLL_FUNCTION(void) BU_FileSystem_WriteByte(std::fstream* file, int32_t value) { +#pragma comment(linker, "/EXPORT:BU_FileSystem_WriteByte=_BU_FileSystem_WriteByte@8") + char myVal[1] = { value & 0xFF}; + file->write(myVal, 1); +} + +DLL_FUNCTION(int32_t) BU_FileSystem_ReadByte(std::fstream* file) { +#pragma comment(linker, "/EXPORT:BU_FileSystem_ReadByte=_BU_FileSystem_ReadByte@4") + char myVal[1] = { 0 }; + file->read(myVal, 1); + return myVal[0]; +} + +DLL_FUNCTION(void) BU_FileSystem_WriteShort(std::fstream* file, int32_t value) { +#pragma comment(linker, "/EXPORT:BU_FileSystem_WriteShort=_BU_FileSystem_WriteShort@8") + char myVal[2] = { value & 0xFF, (value >> 8) & 0xFF}; + file->write(myVal, 2); +} + +DLL_FUNCTION(int32_t) BU_FileSystem_ReadShort(std::fstream* file) { +#pragma comment(linker, "/EXPORT:BU_FileSystem_ReadShort=_BU_FileSystem_ReadShort@4") + char myVal[2] = { 0, 0 }; + file->read(myVal, 2); + return (myVal[1] << 8) + myVal[0]; +} + +DLL_FUNCTION(void) BU_FileSystem_WriteInt(std::fstream* file, int32_t value) { +#pragma comment(linker, "/EXPORT:BU_FileSystem_WriteInt=_BU_FileSystem_WriteInt@8") + char myVal[4] = { value & 0xFF, (value >> 8) & 0xFF, (value >> 16) & 0xFF , (value >> 24) & 0xFF }; + file->write(myVal, 4); +} + +DLL_FUNCTION(int32_t) BU_FileSystem_ReadInt(std::fstream* file) { +#pragma comment(linker, "/EXPORT:BU_FileSystem_ReadInt=_BU_FileSystem_ReadInt@4") + char myVal[4] = { 0, 0, 0, 0 }; + file->read(myVal, 4); + return (myVal[3] << 24) + (myVal[2] << 16) + (myVal[1] << 8) + myVal[0]; +} \ No newline at end of file diff --git a/System/FileSystem.h b/System/FileSystem.h new file mode 100644 index 0000000..f0e867f --- /dev/null +++ b/System/FileSystem.h @@ -0,0 +1,21 @@ +// Blitz - 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 . + +#pragma once +#include "BlitzUtility.h" +#include +#include +#include diff --git a/System/Threading.cpp b/System/Threading.cpp new file mode 100644 index 0000000..933dc97 --- /dev/null +++ b/System/Threading.cpp @@ -0,0 +1,143 @@ +// BlitzUtility - Expanding the normal Blitz functionality. +// 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 . + +#include "Threading.h" + +// Types of Blitz Functions. +typedef int32_t(__stdcall *BP_BlitzFunction1_t)(int32_t); +int32_t BP_CallFunction1(BP_BlitzFunction1_t lpFunctionPointer, int32_t p1) { + int32_t returnValue, StackPointer; + + __asm { // Store Stack Pointer + mov StackPointer, esp; + } + + returnValue = lpFunctionPointer(p1); + + __asm { // Restore Stack Pointer + mov esp, StackPointer; + } + + return returnValue; +} + +BlitzThread::BlitzThread(void* ptr, void* data, uint32_t uiStackSize, bool bIsSuspended) { + this->ptr = ptr; + this->data = data; + + this->thread = CreateThread(NULL, uiStackSize, &ThreadMain, this, (bIsSuspended ? CREATE_SUSPENDED : 0), NULL); +} + +BlitzThread::~BlitzThread() { + this->Terminate(-1); +} + +void BlitzThread::Terminate(int32_t exitCode) { + if (this->thread) { + TerminateThread(this->thread, -1); + this->thread = 0; + } +} + +int32_t BlitzThread::Suspend() { + return SuspendThread(this->thread); +} + +int32_t BlitzThread::Resume() { + return ResumeThread(this->thread); +} + +int32_t BlitzThread::Wait(int32_t timeout) { + return WaitForSingleObject(this->thread, timeout); +} + +int32_t BlitzThread::GetExitCode() { + DWORD pExitCode; + GetExitCodeThread(this->thread, &pExitCode); + return pExitCode; +} + +DWORD WINAPI BlitzThread::ThreadMain(LPVOID pData) { + BlitzThread* pThis = reinterpret_cast(pData); + + try { + return BP_CallFunction1((BP_BlitzFunction1_t)pThis->ptr, reinterpret_cast(pThis->data)); + } catch (std::exception e) { + return -2; + } catch (...) { + return -1; + } +} + +DLL_FUNCTION(BlitzThread*) BU_Thread_Create(void* pFunction, void* pData, uint32_t uiStackSize, uint32_t bIsSuspended) { +#pragma comment(linker, "/EXPORT:BU_Thread_Create=_BU_Thread_Create@16") + return new BlitzThread(pFunction, pData, uiStackSize, !!bIsSuspended); +} + +DLL_FUNCTION(void) BU_Thread_Destroy(BlitzThread* pThread) { +#pragma comment(linker, "/EXPORT:BU_Thread_Destroy=_BU_Thread_Destroy@4") + delete pThread; +} +DLL_FUNCTION(void) BU_Thread_Terminate(BlitzThread* pThread, int32_t exitCode) { +#pragma comment(linker, "/EXPORT:BU_Thread_Terminate=_BU_Thread_Terminate@8") + pThread->Terminate(exitCode); + delete pThread; +} + +DLL_FUNCTION(int32_t) BU_Thread_Suspend(BlitzThread* pThread) { +#pragma comment(linker, "/EXPORT:BU_Thread_Suspend=_BU_Thread_Suspend@4") + return pThread->Suspend(); +} + +DLL_FUNCTION(int32_t) BU_Thread_Resume(BlitzThread* pThread) { +#pragma comment(linker, "/EXPORT:BU_Thread_Resume=_BU_Thread_Resume@4") + return pThread->Resume(); +} + +DLL_FUNCTION(int32_t) BU_Thread_Wait(BlitzThread* pThread, int32_t timeout) { +#pragma comment(linker, "/EXPORT:BU_Thread_Wait=_BU_Thread_Wait@8") + return pThread->Wait(timeout); +} + +DLL_FUNCTION(int32_t) BU_Thread_GetExitCode(BlitzThread* pThread) { +#pragma comment(linker, "/EXPORT:BU_Thread_GetExitCode=_BU_Thread_GetExitCode@4") + return pThread->GetExitCode(); +} + +DLL_FUNCTION(void) BU_Thread_Exit(int32_t exitCode) { +#pragma comment(linker, "/EXPORT:BU_Thread_Exit=_BU_Thread_Exit@4") + ExitThread(exitCode); +} + +DLL_FUNCTION(HANDLE) BU_Mutex_Create(int32_t bInitialOwner) { +#pragma comment(linker, "/EXPORT:BU_Mutex_Create=_BU_Mutex_Create@4") + return CreateMutex(NULL, !!bInitialOwner, NULL); +} + +DLL_FUNCTION(void) BU_Mutex_Destroy(HANDLE mutex) { +#pragma comment(linker, "/EXPORT:BU_Mutex_Destroy=_BU_Mutex_Destroy@4") + CloseHandle(mutex); +} + +DLL_FUNCTION(int32_t) BU_Mutex_Lock(HANDLE mutex, int32_t timeout) { +#pragma comment(linker, "/EXPORT:BU_Mutex_Lock=_BU_Mutex_Lock@8") + return WaitForSingleObject(mutex, timeout); +} + +DLL_FUNCTION(int32_t) BU_Mutex_Unlock(HANDLE mutex) { +#pragma comment(linker, "/EXPORT:BU_Mutex_Unlock=_BU_Mutex_Unlock@4") + return ReleaseMutex(mutex); +} \ No newline at end of file diff --git a/System/Threading.h b/System/Threading.h new file mode 100644 index 0000000..e92517f --- /dev/null +++ b/System/Threading.h @@ -0,0 +1,44 @@ +// Blitz - 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 . + +#pragma once +#include "BlitzUtility.h" +#include +#include + +class BlitzThread { +public: + BlitzThread(void* ptr, void* data, uint32_t uiStackSize, bool bIsSuspended); + ~BlitzThread(); + + void Terminate(int32_t exitCode); + + int32_t Suspend(); + int32_t Resume(); + int32_t Wait(int32_t timeout); + int32_t GetExitCode(); + + static DWORD WINAPI ThreadMain(LPVOID pData); +private: + void *ptr, *data; + std::exception* ex; + + HANDLE thread; +}; + + + + diff --git a/Time/Time.cpp b/Time/Time.cpp index 4be8e50..f2beb7f 100644 --- a/Time/Time.cpp +++ b/Time/Time.cpp @@ -44,18 +44,14 @@ DLL_FUNCTION(void) BU_Time_Destroy(time_t* pTime) { delete pTime; } +char* BU_Time_Format_Buffer = new char[1024]; DLL_FUNCTION(const char*) BU_Time_Format(time_t* pTime, const char* pchFormatString) { #pragma comment(linker, "/EXPORT:BU_Time_Format=_BU_Time_Format@8") - std::string buffer; tm* pTM = new tm; localtime_s(pTM, pTime); - uint32_t length = strlen(pchFormatString); - buffer.resize(length); - while (strftime(&buffer[0], buffer.size(), pchFormatString, pTM) == 0) { - buffer.resize(buffer.size() * 2); - } - + strftime(BU_Time_Format_Buffer, 1024, pchFormatString, pTM); delete pTM; - return buffer.c_str(); + + return BU_Time_Format_Buffer; } \ No newline at end of file diff --git a/Timer.cpp b/Time/Timer.cpp similarity index 100% rename from Timer.cpp rename to Time/Timer.cpp diff --git a/Timer.h b/Time/Timer.h similarity index 100% rename from Timer.h rename to Time/Timer.h diff --git a/Utility/ThreadWrapper.cpp b/Utility/ThreadWrapper.cpp new file mode 100644 index 0000000..03f392d --- /dev/null +++ b/Utility/ThreadWrapper.cpp @@ -0,0 +1,53 @@ +// BlitzUtility - Expanding the normal Blitz functionality. +// 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 . + +#include "ThreadWrapper.h" + +class ThreadWrapper { +public: + ThreadWrapper(void* ptr, void* data) { + this->ptr = ptr; + this->data = data; + } + ~ThreadWrapper() { + + } + + static int Core(ThreadWrapper* data) { + try { + BP_CallFunction1((BP_BlitzFunction1_t)data->ptr, reinterpret_cast(data->data)); + } catch (const std::exception& e) { + std::stringstream ss; + ss << e.what(); + MessageBoxA(0, ss.str().c_str(), "ThreadWrapper", 0); + throw; + } + } + +private: + void *ptr, *data; + std::exception lastException; +}; + +DLL_FUNCTION(ThreadWrapper*) BU_ThreadWrapper_Create(void* ptr, void* data) { +#pragma comment(linker, "/EXPORT:BU_ThreadWrapper_Create=_BU_ThreadWrapper_Create@8") + return new ThreadWrapper(ptr, data); +} + +DLL_FUNCTION(void) BU_ThreadWrapper_Destroy(ThreadWrapper* pThreadWrapper) { +#pragma comment(linker, "/EXPORT:BU_ThreadWrapper_Destroy=_BU_ThreadWrapper_Destroy@4") + delete pThreadWrapper; +} \ No newline at end of file diff --git a/Utility/ThreadWrapper.h b/Utility/ThreadWrapper.h new file mode 100644 index 0000000..5b73424 --- /dev/null +++ b/Utility/ThreadWrapper.h @@ -0,0 +1,22 @@ +// Blitz - 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 . + +#pragma once +#include "BlitzUtility.h" + +// Types of Blitz Functions. +typedef int32_t(__stdcall *BP_BlitzFunction1_t)(int32_t); +int32_t BP_CallFunction1(BP_BlitzFunction1_t lpFunctionPointer, int32_t p1); \ No newline at end of file