|
Cheat Engine The Official Site of Cheat Engine
|
View previous topic :: View next topic |
Author |
Message |
Bennnie Newbie cheater Reputation: 0
Joined: 29 Aug 2012 Posts: 11
|
Posted: Mon Jun 10, 2019 5:17 am Post subject: Extending Lua |
|
|
Hi,
I almost never have to post a problem because my problem has been solved somewhere, but this is one of the rare times i'm not able to solve my problem. I have no experience in delphi, so the fix might be easy.
I am extenting the source of Cheat Engine with tag 6.8.3 to be able to rotate Bitmap/TImage or TPaintbox(whatever I manage to get working). I added the following code to CheatEngine source with lazarus 1.6.4 to file LuaHandler:
Code: |
CONST
MaxPixelCount = 32768;
TYPE
TRGBTripleArray = ARRAY[0..MaxPixelCount-1] OF TRGBTriple;
pRGBTripleArray = ^TRGBTripleArray;
function lua_rotateBitmap(L: Plua_State): integer; cdecl;
VAR
BitmapOriginal: graphics.TBitmap;
RESULT2: graphics.TBitmap;
iRotationAxis, jRotationAxis: INTEGER;
AngleOfRotation: DOUBLE {radians};
cosTheta : EXTENDED;
i : INTEGER;
iOriginal : INTEGER;
iPrime : INTEGER;
j : INTEGER;
jOriginal : INTEGER;
jPrime : INTEGER;
RowOriginal: pRGBTripleArray;
RowRotated : pRGBTRipleArray;
sinTheta : EXTENDED;
BEGIN
BitmapOriginal := lua_toceuserdata(L, 1);
RESULT2 := lua_toceuserdata(L, 2);
iRotationAxis := Lua_Tointeger(L, 3);
jRotationAxis := Lua_Tointeger(L, 4);
AngleOfRotation := 70;
// The size of BitmapRotated is the same as BitmapOriginal. PixelFormat
// must also match since 24-bit GBR triplets are assumed in ScanLine.
RESULT2 := graphics.TBitmap.Create;
RESULT2.Width := BitmapOriginal.Width;
RESULT2.Height := BitmapOriginal.Height;
RESULT2.PixelFormat := pf24bit; // Force this
// Get SIN and COS in single call from math library
sincos(AngleOfRotation, sinTheta, cosTheta);
// If no math library, then use this:
// sinTheta := SIN(AngleOfRotation);
// cosTheta := COS(AngleOfRotation);
// Step through each row of rotated image.
FOR j := RESULT2.Height-1 DOWNTO 0 DO
BEGIN
RowRotated := RESULT2.Scanline[j];
jPrime := j - jRotationAxis;
FOR i := RESULT2.Width-1 DOWNTO 0 DO
BEGIN
iPrime := i - iRotationAxis;
iOriginal := iRotationAxis + ROUND(iPrime * CosTheta - jPrime * sinTheta);
jOriginal := jRotationAxis + ROUND(iPrime * sinTheta + jPrime * cosTheta);
// Make sure (iOriginal, jOriginal) is in BitmapOriginal. If not,
// assign blue color to corner points.
IF (iOriginal >= 0) AND (iOriginal <= BitmapOriginal.Width-1) AND
(jOriginal >= 0) AND (jOriginal <= BitmapOriginal.Height-1)
THEN BEGIN
// Assign pixel from rotated space to current pixel in BitmapRotated
RowOriginal := BitmapOriginal.Scanline[jOriginal];
RowRotated[i] := RowOriginal[iOriginal]
END
ELSE BEGIN
RowRotated[i].rgbtBlue := 255; // assign "corner" color
RowRotated[i].rgbtGreen := 0;
RowRotated[i].rgbtRed := 0
END
END
END
END {RotateBitmapMethod1};
|
Source: from a site that I am not allowed to link. I adjusted it to make it work in CE
And:
Code: |
lua_register(L, 'RotateBitmap', lua_rotateBitmap);
|
So after compiling the code I run the following Lua in Cheat Engine to test the code:
Code: |
function attachBackground(wc,tblFile)
local p = createPicture()
p.loadFromStream(findTableFile(tblFile).Stream)
wc.OnPaint = function(sender)
local c = sender.getCanvas()
local bitmap = p.getBitmap()
local bitmap2 = p.getBitmap()
RotateBitmap(bitmap,bitmap2, 20, 20)
c.draw(0,0,bitmap2)
end
end
t0 = createForm()
control_setSize(t0, 300, 200)
x,y = control_getSize(t0)
attachBackground(t0,[[image.png]])
t0.show()
|
So I expect to put in a bitmap as the first parameter, and get a rotated bitmap of 70 degrees(will be parameterized later, but i couldnt find any lua_ToDouble(L, 5); function) from the second parameter but the image is always empty, but i expect a rotated bitmap.
I am unable to run the CE in Lazarus(with administrator rights) in debug mode. I receive will receive the error Code: | Project Cheat Engine 6.8.3 raised exception class 'External: SIGILL' .in file 'dbk32\vmxfunction.pas' at line 747 |
So my question is, is there any way to debug the program to print the actual content of the bitmap (in bytes) or does someone know an other way to fix this?
|
|
Back to top |
|
|
atom0s Moderator Reputation: 199
Joined: 25 Jan 2006 Posts: 8518 Location: 127.0.0.1
|
|
Back to top |
|
|
Dark Byte Site Admin Reputation: 458
Joined: 09 May 2003 Posts: 25296 Location: The netherlands
|
Posted: Mon Jun 10, 2019 11:26 pm Post subject: |
|
|
build in debug-novmx mode
or just continue after that error (it will appear a few more times)
_________________
Do not ask me about online cheats. I don't know any and wont help finding them.
Like my help? Join me on Patreon so i can keep helping |
|
Back to top |
|
|
Bennnie Newbie cheater Reputation: 0
Joined: 29 Aug 2012 Posts: 11
|
Posted: Tue Jun 11, 2019 1:17 pm Post subject: |
|
|
Thanks for the answers! I got i working now, thanks to being able to debug the program. My code had a few problems.
For anyone having the Code: | Project Cheat Engine 6.8.3 raised exception class 'External: SIGILL' .in file 'dbk32\vmxfunction.pas' at line 747
| error: run lazarus in administrator mode, go to project -> project options -> compiler command -> set build mode to debug
|
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
|
|