Stuff?
This commit is contained in:
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
#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];
|
||||
}
|
||||
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
#pragma once
|
||||
#include "BlitzUtility.h"
|
||||
#include <mutex>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
#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<BlitzThread*>(pData);
|
||||
|
||||
try {
|
||||
return BP_CallFunction1((BP_BlitzFunction1_t)pThis->ptr, reinterpret_cast<int32_t>(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);
|
||||
}
|
||||
@@ -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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
#pragma once
|
||||
#include "BlitzUtility.h"
|
||||
#include <mutex>
|
||||
#include <chrono>
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user