Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


How does Lua declare C++ pointers and data structures

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
.lua
Expert Cheater
Reputation: 1

Joined: 13 Sep 2018
Posts: 189

PostPosted: Mon Jan 09, 2023 10:45 am    Post subject: How does Lua declare C++ pointers and data structures Reply with quote

POINT point; point.x = 100; point.y = 100;
As a parameter of c++, it should be:&point

Is the following declaration of lua correct
Code:
--Example 1
point={}
point.x=100
point.y=100

--Example 2
point=createMemoryStream()
point.writeDword(100)
point.writeDword(100)
Back to top
View user's profile Send private message
AylinCE
Grandmaster Cheater Supreme
Reputation: 31

Joined: 16 Feb 2017
Posts: 1234

PostPosted: Mon Jan 09, 2023 11:18 am    Post subject: Reply with quote

I didn't quite understand what you wanted to do.
Sounds like you want to allocate memory for reading.

Here is a different (Similar) idea;

Code:
point=createMemoryStream() --{}
point.x=0x00000064
point.y=0x00000096
point.z=0x000000C8

print(point.z) --> 200
print(point.y) --> 150
print(point.x) --> 100

_________________
Hi Hitler Different Trainer forms for you!
https://forum.cheatengine.org/viewtopic.php?t=619279
Enthusiastic people: Always one step ahead
Do not underestimate me Master: You were a beginner in the past
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
.lua
Expert Cheater
Reputation: 1

Joined: 13 Sep 2018
Posts: 189

PostPosted: Mon Jan 09, 2023 11:34 am    Post subject: Reply with quote

AylinCE wrote:
Sounds like you want to allocate memory for reading.
This is an API function, where the parameters include pointer type and data structure

POINT point; point.x = 0; point.y = 0
SIZE size; size.cx = 500; size.cy = 500;
BLENDFUNCTION blend;
blend.BlendOp = AC_SRC_OVER;
blend.BlendFlags = 0;
blend.AlphaFormat = AC_SRC_ALPHA;
blend.SourceConstantAlpha = 255;
UpdateLayeredWindow(hwnd1, NULL, NULL, &size, mdc, &point, 0, &blend, ULW_ALPHA)

Refer to what the gods wrote,BLENDFUNCTION :(&blend)
Code:
function BLENDFUNCTION(alpha) 
  return byteTableToDword({0,0,alpha,0}) 
end


The remaining parameters are pointer types(&size、&point), which I have a headache
Back to top
View user's profile Send private message
AylinCE
Grandmaster Cheater Supreme
Reputation: 31

Joined: 16 Feb 2017
Posts: 1234

PostPosted: Mon Jan 09, 2023 11:56 am    Post subject: Reply with quote

https://github.com/luapower/winapi/blob/master/winapi/window.lua#L550
_________________
Hi Hitler Different Trainer forms for you!
https://forum.cheatengine.org/viewtopic.php?t=619279
Enthusiastic people: Always one step ahead
Do not underestimate me Master: You were a beginner in the past
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
ParkourPenguin
I post too much
Reputation: 138

Joined: 06 Jul 2014
Posts: 4275

PostPosted: Mon Jan 09, 2023 12:56 pm    Post subject: Reply with quote

Lua is a scripting language. It's not meant to be used as a low-level systems programming language.

You might be better off programming what you want in C using {$ccode} (autoAssemble w/ targetself = true)
https://forum.cheatengine.org/viewtopic.php?t=618134

Or write it in any language capable of building a dll and make a dll plugin.

_________________
I don't know where I'm going, but I'll figure it out when I get there.
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 457

Joined: 09 May 2003
Posts: 25262
Location: The netherlands

PostPosted: Mon Jan 09, 2023 5:05 pm    Post subject: Re: How does Lua declare C++ pointers and data structures Reply with quote

.lua wrote:
POINT point; point.x = 100; point.y = 100;
As a parameter of c++, it should be:&point

Is the following declaration of lua correct
Code:
--Example 1
point={}
point.x=100
point.y=100

--Example 2
point=createMemoryStream()
point.writeDword(100)
point.writeDword(100)


yes, that is correct. Point.Memory then contains the address of the point object

_________________
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
View user's profile Send private message MSN Messenger
.lua
Expert Cheater
Reputation: 1

Joined: 13 Sep 2018
Posts: 189

PostPosted: Wed Jan 11, 2023 2:46 am    Post subject: Re: How does Lua declare C++ pointers and data structures Reply with quote

Dark Byte wrote:
yes, that is correct. Point.Memory then contains the address of the point object
I have written the parameters as required

The API function UpdateLayeredWindow still doesn't work

You can download the CT file and remove the suffix (.lua)



Test.jpg
 Description:
 Filesize:  60.04 KB
 Viewed:  2521 Time(s)

Test.jpg



Test.CT.lua
 Description:

Download
 Filename:  Test.CT.lua
 Filesize:  275.27 KB
 Downloaded:  76 Time(s)

Back to top
View user's profile Send private message
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1667

PostPosted: Thu Jan 12, 2023 10:33 pm    Post subject: Reply with quote

Basic from your lua file attached. try this :

first, set this line "active'.
Code:
SetLayeredWindowAttributes(hWnd, 0xfffffff, 200, 1)

execute the script, close your form and set this line to "non active"
Code:
---SetLayeredWindowAttributes(hWnd, 0xfffffff, 200, 1)

execute again the script.

script:

Code:
UDF1.FormStyle='fsSystemStayOnTop'
UDF1.Color = 0xfffffff
UDF1.OnMouseDown=function()
  UDF1.DragNow()
end

function SetWindowLong(hWnd, nIndex, dwNewLong)
 return executeCodeLocalEx("user32.SetWindowLongPtrA", hWnd, nIndex, dwNewLong)
end

function GetWindowLong(hWnd, GWL)
 return executeCodeLocalEx("user32.GetWindowLongPtrA", hWnd, GWL)
end

function UpdateLayeredWindow(hwnd, hdcDst, pptDst, psize, hdcSrc, pptSrc, crKey, pblend, dwFlags)
 return executeCodeLocalEx("user32.UpdateLayeredWindow", hwnd, hdcDst, pptDst, psize, hdcSrc, pptSrc, crKey, pblend, dwFlags)
end

function SetLayeredWindowAttributes(hwnd, crKey, bAlpha, dwFlags)
 return executeCodeLocalEx("user32.SetLayeredWindowAttributes", hwnd, crKey, bAlpha, dwFlags)
end
---------------------------------------------------------------------------------
GWL_EXSTYLE = -20
GWL_STYLE = -16
WS_EX_LAYERED = 524288
ULW_COLORKEY = 1
ULW_ALPHA = 2
LWA_COLORKEY = 1
LWA_ALPHA = 2
LWA_BOTH = 3

hWnd=UDF1.Handle
HDC1=UDF1.Canvas.Handle
HDC2=UDF1.CEImage1.Canvas.Handle
function setBlend(alpha)  return  byteTableToDword({0,0,alpha,0})  end

pptDst = createMemoryStream()
pptDst.writeDword(UDF1.Left)
pptDst.writeDword(UDF1.Top)

psize = createMemoryStream()
psize.writeDword(200)
psize.writeDword(200)

pptSrc = createMemoryStream()
pptSrc.writeDword(0)
pptSrc.writeDword(0)

Attrib = GetWindowLong(UDF1.handle, GWL_EXSTYLE)
SetWindowLong(UDF1.handle, GWL_EXSTYLE, attrib or WS_EX_LAYERED)
--SetLayeredWindowAttributes(hWnd, 0xfffffff, 200, 1)
UpdateLayeredWindow(hWnd, HDC1, pptDst.Memory, psize.Memory, HDC2, pptSrc.Memory, 0, setBlend(200), ULW_ALPHA)
UDF1.Show()


So, according to MS, UpdateLayeredWindow only work to a form which the LAYERED has been SET.



Capture.png
 Description:
Your Form
 Filesize:  59.51 KB
 Viewed:  2399 Time(s)

Capture.png



_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL
Back to top
View user's profile Send private message
.lua
Expert Cheater
Reputation: 1

Joined: 13 Sep 2018
Posts: 189

PostPosted: Fri Jan 13, 2023 9:13 pm    Post subject: Reply with quote

Corroder wrote:
Basic from your lua file attached. try this :

first, set this line "active'.
Code:
SetLayeredWindowAttributes(hWnd, 0xfffffff, 200, 1)


So, according to MS, UpdateLayeredWindow only work to a form which the LAYERED has been SET.
Once SetLayeredWindowAttributes is used, the UpdateLayeredWindow function cannot be used.

So before calling the function, I added the form style code.
Look at the picture:

But it only has transparency, not heteromorphic forms, and no shadow rendering((There seems to be something missing))



test01.png
 Description:
 Filesize:  98.44 KB
 Viewed:  2303 Time(s)

test01.png


Back to top
View user's profile Send private message
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1667

PostPosted: Sat Jan 14, 2023 6:40 am    Post subject: Reply with quote

this line :

Code:

function GetWindowLong(hWnd, nIndex)
 return executeCodeLocalEx("user32.GetWindowLongA", hWnd, X)
end

--- change nIndex to something...X, Blabla or what ever

-- and then
HDC2=UDF1.CEImage1.Canvas.Handle

--- should be --> HDC2=UDF1.CEImage1.Picture.Bitmap.Canvas.Handle

--- and then

psize = createMemoryStream()
psize.writeDword(300)
psize.writeDword(300)

--- should be
psize = createMemoryStream()
psize.writeDword(UDF1.CEImage1.Picture.Bitmap.Width)
psize.writeDword(UDF1.CEImage1.Picture.Bitmap.Height)

-- also try
UpdateLayeredWindow(hWnd, HDC1, pptDst.Memory, psize.Memory, HDC2, pptSrc.Memory, 0, setBlend(225), 2)

-- change that default ULW_ALPHA = 2, to 1 or 3, to see the effect


_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL
Back to top
View user's profile Send private message
.lua
Expert Cheater
Reputation: 1

Joined: 13 Sep 2018
Posts: 189

PostPosted: Sat Jan 14, 2023 10:16 am    Post subject: Reply with quote

Corroder wrote:
this line :
God, I have succeeded. Thank you so much
1, 3 and 4 in the figure have been corrected successfully after being reminded by you.
Why can't the position of 2 in the figure be 0.

Since it is successful, it is naturally used as a background form, so how to move two forms at the same time



OK.jpg
 Description:
 Filesize:  101.12 KB
 Viewed:  2238 Time(s)

OK.jpg


Back to top
View user's profile Send private message
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1667

PostPosted: Sat Jan 14, 2023 7:41 pm    Post subject: Reply with quote

Quote:
Why can't the position of 2 in the figure be 0.


According to MS ;

Code:
BOOL UpdateLayeredWindow(
  [in]           HWND          hWnd,
  [in, optional] HDC           hdcDst,
  [in, optional] POINT         *pptDst,
  [in, optional] SIZE          *psize,
  [in, optional] HDC           hdcSrc,
  [in, optional] POINT         *pptSrc,
  [in]           COLORREF      crKey,
  [in, optional] BLENDFUNCTION *pblend,
  [in]           DWORD         dwFlags
);


Code:
[in, optional] pptSrc

Type: POINT*

A pointer to a structure that [b]specifies the location of the layer[/b] in the device context. If hdcSrc is NULL, pptSrc should be NULL.


And this one is OPTIONAL

Quote:
so how to move two forms at the same time


Try this :

Code:
if f1 or f2 then f1.Destroy() f2.Destroy() end
f1 = createForm()
f1.Caption = "Form1"
f2 = createForm()
f2.Caption = "Form2"
f2.Left = f1.Left + f1.Width + 5

function MoveTwoForms(Frm1, Frm2)
 if (Frm1 == nil) or (Frm2 == nil) then return nil end
    f2.Left = f1.Left + f1.Width + 5
    f2.Top = f1.Top
end

function mv()
 MoveTwoForms(f1, f2)
end

if t then t.destroy() end
t = createTimer()
t.Interval = 10
t.Enabled = false
t.OnTimer = mv

f1.OnMouseDown = function()
 t.Enabled = true
 f1.dragNow()
end

f1.OnMouseUp = function()
 t.Enabled = false
end


Try to modify the code. Add a sequence if the forms lost focus then set timer enabled to false to avoid error.

_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL
Back to top
View user's profile Send private message
.lua
Expert Cheater
Reputation: 1

Joined: 13 Sep 2018
Posts: 189

PostPosted: Sat Jan 14, 2023 11:11 pm    Post subject: Reply with quote

Corroder wrote:
Try to modify the code. Add a sequence if the forms lost focus then set timer enabled to false to avoid error.
I think this method is ideal (there is no trace when dragging at least two forms)


MoveTwoForm.gif
 Description:
 Filesize:  794.75 KB
 Viewed:  2160 Time(s)

MoveTwoForm.gif


Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites