- Update Headers in files to match new owner.
- Update Example08.bb to be more detailed - Added function to grab Type pointers (would previously crash).
This commit is contained in:
+19
-3
@@ -1,5 +1,5 @@
|
|||||||
// BlitzPointer - Adding Pointers to Blitz.
|
// BlitzPointer - Adding Pointers to Blitz.
|
||||||
// Copyright (C) 2015 Project Kube (Michael Fabian Dirks)
|
// Copyright (C) 2015 Xaymar (Michael Fabian Dirks)
|
||||||
//
|
//
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// This program is free software: you can redistribute it and/or modify
|
||||||
// it under the terms of the GNU Lesser General Public License as
|
// it under the terms of the GNU Lesser General Public License as
|
||||||
@@ -15,7 +15,7 @@
|
|||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
// Idea take from Code by Noodoby<http://www.blitzforum.de/forum/viewtopic.php?t=31651>
|
// Idea take from Code by Noodoby<http://www.blitzforum.de/forum/viewtopic.php?t=31651>
|
||||||
// New Code by Xaymar<http://project-kube.de>
|
// New Code by Xaymar<http://xaymar.com>
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "BlitzPointer.h"
|
#include "BlitzPointer.h"
|
||||||
@@ -79,7 +79,23 @@ DLL_METHOD intptr_t DLL_CALL BP_GetVariablePointer(int32_t pVariable)
|
|||||||
// The Variable pointer that is used is at -9 bytes offset to the return address.
|
// The Variable pointer that is used is at -9 bytes offset to the return address.
|
||||||
return *reinterpret_cast<int32_t*>(ReturnAddress - 9);
|
return *reinterpret_cast<int32_t*>(ReturnAddress - 9);
|
||||||
}
|
}
|
||||||
#pragma comment(linker, "/EXPORT:BP_GetVariablePointer=_BP_GetVariablePointer@0")
|
#pragma comment(linker, "/EXPORT:BP_GetVariablePointer=_BP_GetVariablePointer@4")
|
||||||
|
|
||||||
|
DLL_METHOD intptr_t DLL_CALL BP_GetVariablePointerType( int32_t pVariable ) {
|
||||||
|
intptr_t StackPointer, ReturnAddress;
|
||||||
|
|
||||||
|
__asm { //ASM. Do touch if suicidal.
|
||||||
|
mov StackPointer, esp; // Store current Stack Pointer
|
||||||
|
mov esp, ebp; // On X86, EBP[0] is our own function and EBP[1] is the return address.
|
||||||
|
add esp, 4; // Which means that we can just take it from there into our own variable.
|
||||||
|
pop ReturnAddress; // Just like this.
|
||||||
|
mov esp, [StackPointer]; // And then reset the Stack Pointer.
|
||||||
|
}
|
||||||
|
|
||||||
|
// The Variable pointer that is used is at -9 bytes offset to the return address.
|
||||||
|
return *reinterpret_cast<int32_t*>(ReturnAddress - 11);
|
||||||
|
}
|
||||||
|
#pragma comment(linker, "/EXPORT:BP_GetVariablePointerType=_BP_GetVariablePointerType@4")
|
||||||
|
|
||||||
DLL_METHOD int32_t DLL_CALL BP_CallFunction0(BP_BlitzFunction0_t lpFunctionPointer) {
|
DLL_METHOD int32_t DLL_CALL BP_CallFunction0(BP_BlitzFunction0_t lpFunctionPointer) {
|
||||||
return lpFunctionPointer();
|
return lpFunctionPointer();
|
||||||
|
|||||||
+3
-3
@@ -1,5 +1,5 @@
|
|||||||
; BlitzPointer - Adding Pointers to Blitz.
|
; BlitzPointer - Adding Pointers to Blitz.
|
||||||
; Copyright (C) 2015 Project Kube (Michael Fabian Dirks)
|
; Copyright (C) 2015 Xaymar (Michael Fabian Dirks)
|
||||||
;
|
;
|
||||||
; This program is free software: you can redistribute it and/or modify
|
; This program is free software: you can redistribute it and/or modify
|
||||||
; it under the terms of the GNU Lesser General Public License as
|
; it under the terms of the GNU Lesser General Public License as
|
||||||
@@ -19,10 +19,10 @@
|
|||||||
; BlitzPointer
|
; BlitzPointer
|
||||||
BP_GetReturnAddress%()
|
BP_GetReturnAddress%()
|
||||||
BP_GetFunctionPointer%()
|
BP_GetFunctionPointer%()
|
||||||
;BP_GetVariablePointer%()
|
;BP_GetVariablePointer%(pVariable%)
|
||||||
BP_GetVariablePointerInt%(pVariable%) : "BP_GetVariablePointer"
|
BP_GetVariablePointerInt%(pVariable%) : "BP_GetVariablePointer"
|
||||||
BP_GetVariablePointerFloat%(pVariable#) : "BP_GetVariablePointer"
|
BP_GetVariablePointerFloat%(pVariable#) : "BP_GetVariablePointer"
|
||||||
BP_GetVariablePointerType%(pVariable*) : "BP_GetVariablePointer"
|
BP_GetVariablePointerType%(pVariable*) : "BP_GetVariablePointerType"
|
||||||
|
|
||||||
; Memory Modification
|
; Memory Modification
|
||||||
PeekMemoryByte%(lpMemoryPointer%)
|
PeekMemoryByte%(lpMemoryPointer%)
|
||||||
|
|||||||
+2
-1
@@ -1,5 +1,5 @@
|
|||||||
// BlitzPointer - Adding Pointers to Blitz.
|
// BlitzPointer - Adding Pointers to Blitz.
|
||||||
// Copyright (C) 2015 Project Kube (Michael Fabian Dirks)
|
// Copyright (C) 2015 Xaymar (Michael Fabian Dirks)
|
||||||
//
|
//
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// This program is free software: you can redistribute it and/or modify
|
||||||
// it under the terms of the GNU Lesser General Public License as
|
// it under the terms of the GNU Lesser General Public License as
|
||||||
@@ -30,6 +30,7 @@ typedef int32_t(__stdcall *BP_BlitzFunction5_t)(int32_t, int32_t, int32_t, int32
|
|||||||
DLL_METHOD intptr_t DLL_CALL BP_GetReturnAddress();
|
DLL_METHOD intptr_t DLL_CALL BP_GetReturnAddress();
|
||||||
DLL_METHOD intptr_t DLL_CALL BP_GetFunctionPointer();
|
DLL_METHOD intptr_t DLL_CALL BP_GetFunctionPointer();
|
||||||
DLL_METHOD intptr_t DLL_CALL BP_GetVariablePointer(int32_t pVariable);
|
DLL_METHOD intptr_t DLL_CALL BP_GetVariablePointer(int32_t pVariable);
|
||||||
|
DLL_METHOD intptr_t DLL_CALL BP_GetVariablePointerType(int32_t pVariable);
|
||||||
|
|
||||||
// Native Blitz Function Calls
|
// Native Blitz Function Calls
|
||||||
DLL_METHOD int32_t DLL_CALL BP_CallFunction0(BP_BlitzFunction0_t lpFunctionPointer);
|
DLL_METHOD int32_t DLL_CALL BP_CallFunction0(BP_BlitzFunction0_t lpFunctionPointer);
|
||||||
|
|||||||
@@ -61,7 +61,7 @@
|
|||||||
<BasicRuntimeChecks>Default</BasicRuntimeChecks>
|
<BasicRuntimeChecks>Default</BasicRuntimeChecks>
|
||||||
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
|
||||||
<BufferSecurityCheck>false</BufferSecurityCheck>
|
<BufferSecurityCheck>false</BufferSecurityCheck>
|
||||||
<FunctionLevelLinking>false</FunctionLevelLinking>
|
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||||
<CompileAsManaged>false</CompileAsManaged>
|
<CompileAsManaged>false</CompileAsManaged>
|
||||||
<CompileAsWinRT>false</CompileAsWinRT>
|
<CompileAsWinRT>false</CompileAsWinRT>
|
||||||
<StructMemberAlignment>4Bytes</StructMemberAlignment>
|
<StructMemberAlignment>4Bytes</StructMemberAlignment>
|
||||||
@@ -83,6 +83,7 @@
|
|||||||
<FloatingPointExceptions>false</FloatingPointExceptions>
|
<FloatingPointExceptions>false</FloatingPointExceptions>
|
||||||
<UseUnicodeForAssemblerListing>true</UseUnicodeForAssemblerListing>
|
<UseUnicodeForAssemblerListing>true</UseUnicodeForAssemblerListing>
|
||||||
<PreprocessorDefinitions>%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
<PreprocessorDefinitions>%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
|
<DebugInformationFormat>EditAndContinue</DebugInformationFormat>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
; BlitzPointer - Adding Pointers to Blitz.
|
; BlitzPointer - Adding Pointers to Blitz.
|
||||||
; Copyright (C) 2015 Project Kube (Michael Fabian Dirks)
|
; Copyright (C) 2015 Xaymar (Michael Fabian Dirks)
|
||||||
;
|
;
|
||||||
; This program is free software: you can redistribute it and/or modify
|
; This program is free software: you can redistribute it and/or modify
|
||||||
; it under the terms of the GNU Lesser General Public License as
|
; it under the terms of the GNU Lesser General Public License as
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
; BlitzPointer - Adding Pointers to Blitz.
|
; BlitzPointer - Adding Pointers to Blitz.
|
||||||
; Copyright (C) 2015 Project Kube (Michael Fabian Dirks)
|
; Copyright (C) 2015 Xaymar (Michael Fabian Dirks)
|
||||||
;
|
;
|
||||||
; This program is free software: you can redistribute it and/or modify
|
; This program is free software: you can redistribute it and/or modify
|
||||||
; it under the terms of the GNU Lesser General Public License as
|
; it under the terms of the GNU Lesser General Public License as
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
; BlitzPointer - Adding Pointers to Blitz.
|
; BlitzPointer - Adding Pointers to Blitz.
|
||||||
; Copyright (C) 2015 Project Kube (Michael Fabian Dirks)
|
; Copyright (C) 2015 Xaymar (Michael Fabian Dirks)
|
||||||
;
|
;
|
||||||
; This program is free software: you can redistribute it and/or modify
|
; This program is free software: you can redistribute it and/or modify
|
||||||
; it under the terms of the GNU Lesser General Public License as
|
; it under the terms of the GNU Lesser General Public License as
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
; BlitzPointer - Adding Pointers to Blitz.
|
; BlitzPointer - Adding Pointers to Blitz.
|
||||||
; Copyright (C) 2015 Project Kube (Michael Fabian Dirks)
|
; Copyright (C) 2015 Xaymar (Michael Fabian Dirks)
|
||||||
;
|
;
|
||||||
; This program is free software: you can redistribute it and/or modify
|
; This program is free software: you can redistribute it and/or modify
|
||||||
; it under the terms of the GNU Lesser General Public License as
|
; it under the terms of the GNU Lesser General Public License as
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
; BlitzPointer - Adding Pointers to Blitz.
|
; BlitzPointer - Adding Pointers to Blitz.
|
||||||
; Copyright (C) 2015 Project Kube (Michael Fabian Dirks)
|
; Copyright (C) 2015 Xaymar (Michael Fabian Dirks)
|
||||||
;
|
;
|
||||||
; This program is free software: you can redistribute it and/or modify
|
; This program is free software: you can redistribute it and/or modify
|
||||||
; it under the terms of the GNU Lesser General Public License as
|
; it under the terms of the GNU Lesser General Public License as
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
; BlitzPointer - Adding Pointers to Blitz.
|
; BlitzPointer - Adding Pointers to Blitz.
|
||||||
; Copyright (C) 2015 Project Kube (Michael Fabian Dirks)
|
; Copyright (C) 2015 Xaymar (Michael Fabian Dirks)
|
||||||
;
|
;
|
||||||
; This program is free software: you can redistribute it and/or modify
|
; This program is free software: you can redistribute it and/or modify
|
||||||
; it under the terms of the GNU Lesser General Public License as
|
; it under the terms of the GNU Lesser General Public License as
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
; BlitzPointer - Adding Pointers to Blitz.
|
; BlitzPointer - Adding Pointers to Blitz.
|
||||||
; Copyright (C) 2015 Project Kube (Michael Fabian Dirks)
|
; Copyright (C) 2015 Xaymar (Michael Fabian Dirks)
|
||||||
;
|
;
|
||||||
; This program is free software: you can redistribute it and/or modify
|
; This program is free software: you can redistribute it and/or modify
|
||||||
; it under the terms of the GNU Lesser General Public License as
|
; it under the terms of the GNU Lesser General Public License as
|
||||||
@@ -15,7 +15,7 @@
|
|||||||
; along with this program. If not, see <http:;www.gnu.org/licenses/>.
|
; along with this program. If not, see <http:;www.gnu.org/licenses/>.
|
||||||
|
|
||||||
; ---------------------------------------------------------------------------- ;
|
; ---------------------------------------------------------------------------- ;
|
||||||
; Example 6 - Callbacks
|
; Example 7 - Callbacks
|
||||||
; ---------------------------------------------------------------------------- ;
|
; ---------------------------------------------------------------------------- ;
|
||||||
; License: Creative Commons Attribution 2.0
|
; License: Creative Commons Attribution 2.0
|
||||||
; Author: Michael Fabian Dirks<michael.dirks@realitybends.de>
|
; Author: Michael Fabian Dirks<michael.dirks@realitybends.de>
|
||||||
|
|||||||
+62
-21
@@ -1,5 +1,5 @@
|
|||||||
; BlitzPointer - Adding Pointers to Blitz.
|
; BlitzPointer - Adding Pointers to Blitz.
|
||||||
; Copyright (C) 2015 Project Kube (Michael Fabian Dirks)
|
; Copyright (C) 2015 Xaymar (Michael Fabian Dirks)
|
||||||
;
|
;
|
||||||
; This program is free software: you can redistribute it and/or modify
|
; This program is free software: you can redistribute it and/or modify
|
||||||
; it under the terms of the GNU Lesser General Public License as
|
; it under the terms of the GNU Lesser General Public License as
|
||||||
@@ -15,29 +15,70 @@
|
|||||||
; along with this program. If not, see <http:;www.gnu.org/licenses/>.
|
; along with this program. If not, see <http:;www.gnu.org/licenses/>.
|
||||||
|
|
||||||
; ---------------------------------------------------------------------------- ;
|
; ---------------------------------------------------------------------------- ;
|
||||||
; Example 6 - Variable Pointers
|
; Example 8 - Variable-pointers
|
||||||
; ---------------------------------------------------------------------------- ;
|
; ---------------------------------------------------------------------------- ;
|
||||||
; Variable Pointers, the one thing we have all waited for in addition to every-
|
; Variable-pointers are really neat. Not only can you have a single variable for
|
||||||
; thing else. Now we can pass things by reference instead of copying to & from
|
; a lot of things in many locations (even across thread) but you can pass them
|
||||||
; a bank. Unfortunately it only works for Integers, Floats and Types.
|
; to DLLs too! This opens up Blitz to a whole new way of working with DLLs.
|
||||||
|
|
||||||
; For Integers, all you have to do is declare a variable and then call the func-
|
; Three functions were added for this, each for the respective type
|
||||||
; tion that retrieves the pointer:
|
; - BP_GetVariablePointerInt(Int%)
|
||||||
Global MyVariable% = 1
|
; - BP_GetVariablePointerFloat(Float#)
|
||||||
Global MyVariablePtr% = 0
|
; - BP_GetVariablePointerType(Type.)
|
||||||
MyVariablePtr = BP_GetVariablePointerInt(MyVariable)
|
; (Strings are not supported sorry.)
|
||||||
|
|
||||||
; Same for Floats, slightly different function though
|
; Integers and Floats are really simple, just declare them and grab the pointer.
|
||||||
Global MyVariable2# = 1.2
|
Global MyInteger% = 66
|
||||||
Global MyVariable2Ptr% = 0
|
Global MyFloat# = 66.6
|
||||||
MyVariable2Ptr = BP_GetVariablePointerFloat(MyVariable2)
|
Global Pointer% = 0
|
||||||
|
|
||||||
; Now we can directly modify them in memory, which means that we can modify them
|
; Grab the Integer Pointer and modify the value.
|
||||||
; from anywhere - inside and outside our program. What you do with this is up
|
Pointer = BP_GetVariablePointerInt(MyInteger)
|
||||||
; to your imagination, just don't fuck up. Computers don't like that.
|
Print "MyInteger: " + PeekMemoryInt(Pointer)
|
||||||
|
PokeMemoryInt(Pointer, 33)
|
||||||
|
Print "MyInteger: " + PeekMemoryInt(Pointer)
|
||||||
|
|
||||||
; Usage Example
|
; Grab the Float Pointer and modify the value.
|
||||||
Print MyVariable
|
Pointer = BP_GetVariablePointerFloat(MyFloat)
|
||||||
PokeMemoryInt(MyVariable, 283)
|
Print "MyFloat: " + PeekMemoryFloat(Pointer)
|
||||||
Print MyVariable
|
PokeMemoryFloat(Pointer, 33.3)
|
||||||
|
Print "MyFloat: " + PeekMemoryFloat(Pointer)
|
||||||
|
|
||||||
|
; Types are a tiny bit harder but open up so many possibilities once you get
|
||||||
|
; used to them. Start by defining a Type, we'll use a simple one for this.
|
||||||
|
Type MyType
|
||||||
|
Field Check%
|
||||||
|
End Type
|
||||||
|
|
||||||
|
; Now create some elements that we can use when modifying the pointer
|
||||||
|
Global MyElement.MyType = New MyType
|
||||||
|
Global MyElement1.MyType = New MyType
|
||||||
|
Global MyElement2.MyType = New MyType
|
||||||
|
Global MyElement3.MyType = New MyType
|
||||||
|
MyElement\Check = -1
|
||||||
|
MyElement1\Check = $F
|
||||||
|
MyElement2\Check = $FF
|
||||||
|
MyElement3\Check = $FFF
|
||||||
|
|
||||||
|
; Store the Pointer and original element.
|
||||||
|
Pointer = BP_GetVariablePointerType(MyElement)
|
||||||
|
Local TempPointer% = PeekMemoryInt(Pointer)
|
||||||
|
|
||||||
|
; Modifying is as simple as storing a new value to the address the pointer is
|
||||||
|
; pointing at. The Int() thing is explained in Example 5.
|
||||||
|
Print "MyElement\Check: " + MyElement\Check
|
||||||
|
PokeMemoryInt(Pointer, Int(MyElement1))
|
||||||
|
Print "MyElement\Check: " + MyElement\Check
|
||||||
|
PokeMemoryInt(Pointer, Int(MyElement2))
|
||||||
|
Print "MyElement\Check: " + MyElement\Check
|
||||||
|
PokeMemoryInt(Pointer, Int(MyElement3))
|
||||||
|
Print "MyElement\Check: " + MyElement\Check
|
||||||
|
|
||||||
|
; Always return things to their original condition. Just in case.
|
||||||
|
PokeMemoryInt(Pointer, TempPointer)
|
||||||
|
Print "MyElement\Check: " + MyElement\Check
|
||||||
|
|
||||||
|
WaitKey()
|
||||||
|
|
||||||
|
; You can do some magic with this, such as iterating through types yourself by
|
||||||
|
; changing the pointer to the next element or previous element. See Example 6.
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
; BlitzPointer - Adding Pointers to Blitz.
|
; BlitzPointer - Adding Pointers to Blitz.
|
||||||
; Copyright (C) 2015 Project Kube (Michael Fabian Dirks)
|
; Copyright (C) 2015 Xaymar (Michael Fabian Dirks)
|
||||||
;
|
;
|
||||||
; This program is free software: you can redistribute it and/or modify
|
; This program is free software: you can redistribute it and/or modify
|
||||||
; it under the terms of the GNU Lesser General Public License as
|
; it under the terms of the GNU Lesser General Public License as
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
// BlitzPointer - Adding Pointers to Blitz.
|
// BlitzPointer - Adding Pointers to Blitz.
|
||||||
// Copyright (C) 2015 Project Kube (Michael Fabian Dirks)
|
// Copyright (C) 2015 Xaymar (Michael Fabian Dirks)
|
||||||
//
|
//
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// This program is free software: you can redistribute it and/or modify
|
||||||
// it under the terms of the GNU Lesser General Public License as
|
// it under the terms of the GNU Lesser General Public License as
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
// BlitzPointer - Adding Pointers to Blitz.
|
// BlitzPointer - Adding Pointers to Blitz.
|
||||||
// Copyright (C) 2015 Project Kube (Michael Fabian Dirks)
|
// Copyright (C) 2015 Xaymar (Michael Fabian Dirks)
|
||||||
//
|
//
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// This program is free software: you can redistribute it and/or modify
|
||||||
// it under the terms of the GNU Lesser General Public License as
|
// it under the terms of the GNU Lesser General Public License as
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
// BlitzPointer - Adding Pointers to Blitz.
|
// BlitzPointer - Adding Pointers to Blitz.
|
||||||
// Copyright (C) 2015 Project Kube (Michael Fabian Dirks)
|
// Copyright (C) 2015 Xaymar (Michael Fabian Dirks)
|
||||||
//
|
//
|
||||||
// This program is free software: you can redistribute it and/or modify
|
// This program is free software: you can redistribute it and/or modify
|
||||||
// it under the terms of the GNU Lesser General Public License as
|
// it under the terms of the GNU Lesser General Public License as
|
||||||
|
|||||||
Reference in New Issue
Block a user