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 


Limitations on using the hack
Goto page 1, 2  Next
 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
mark_dellas
How do I cheat?
Reputation: 0

Joined: 28 May 2021
Posts: 9

PostPosted: Fri May 28, 2021 6:58 pm    Post subject: Limitations on using the hack Reply with quote

Hello guys I'm having a hard time and I would like a help.
I'm creating a trainer and I'm not sure how to do the following steps:
- The trainer can be used N times
- The trainer will be able to be used for M seconds
(N x M)
After these conditionals, the memory values ​​would return to the original. The identification part of the values ​​in the memory and the address I already managed to do.

Ex:
Basically, when pressing a button (key) during in the game, the memory value would go from 1 to 5. This value would stay at 5, for approximately five seconds. Then it would return to the initial value (1).
This process could be repeated 3 times.

Anyone who can help me, thank you.
Back to top
View user's profile Send private message
ByTransient
Expert Cheater
Reputation: 5

Joined: 05 Sep 2020
Posts: 240

PostPosted: Fri May 28, 2021 8:38 pm    Post subject: Reply with quote

Code:
local tic=0
local ticIndex=0
UDF1.CETrackBar1.Position=0
UDF1.CETimer1.Interval=1000
UDF1.CETimer1.Enabled=false

function UDF1_CETimer1Timer(sender)
if ticIndex==1 then
tic=tonumber(tic) + 1
if tic==10 then
ticIndex=2
tic=5
end
else
tic=tonumber(tic) - 1
if tic==0 then
UDF1.CETimer1.Enabled=false
end
end
UDF1.CETrackBar1.Position=tonumber(tic)
UDF1.CELabel1.caption=tonumber(tic)
end

function UDF1_CEButton1Click(sender)
ticIndex=1
UDF1.CETimer1.Enabled=true
end


or

Code:
local tic=0
local ticIndex=0
UDF1.CETrackBar1.Max=5
UDF1.CETrackBar1.Position=0
UDF1.CETimer1.Interval=1000
UDF1.CETimer1.Enabled=false

function UDF1_CETimer1Timer(sender)
if ticIndex==1 then
tic=tonumber(tic) + 1
if tic==6 then
ticIndex=2
tic=0
end
else
if tic==0 then
UDF1.CEButton1.Enabled=true
UDF1.CETimer1.Enabled=false
end
end
UDF1.CETrackBar1.Position=tonumber(tic)
UDF1.CELabel1.caption=tonumber(tic)
end

function UDF1_CEButton1Click(sender)
UDF1.CEButton1.Enabled=false
ticIndex=1
UDF1.CETimer1.Enabled=true
end
Back to top
View user's profile Send private message
mark_dellas
How do I cheat?
Reputation: 0

Joined: 28 May 2021
Posts: 9

PostPosted: Fri May 28, 2021 8:52 pm    Post subject: Reply with quote

Just to put this command in the form, can I already make this limitation?
I already have the positions in the memory that will be changed.

I apologize for not having much knowledge. I know only change the value directly in the memory and create a trainer out of it yet. Sad
Back to top
View user's profile Send private message
ByTransient
Expert Cheater
Reputation: 5

Joined: 05 Sep 2020
Posts: 240

PostPosted: Sat May 29, 2021 7:41 am    Post subject: Re: Limitations on using the hack Reply with quote

mark_dellas wrote:

This process could be repeated 3 times.


Code:
if trcTim then trcTim.Destroy() trcTim=nil end
trcTim=createTimer() trcTim.Interval=1000 trcTim.Enabled=false

local tic=0 --second
local ticIndex=0 --seconds back and forth index.
local actvBtn --button name
local maxClk=0 --timer button max click
local maxClick1=0 --button1 click
--local maxClick2=0 --button2 click

trcTim.OnTimer=function()
if ticIndex==1 then
actvBtn.Enabled=false
tic=tonumber(tic) + 1
if tic==6 then
ticIndex=2
tic=0
end
else
if maxClk==3 then
actvBtn.Enabled=false
trcTim.Enabled=false
else
actvBtn.Enabled=true
trcTim.Enabled=false
end
end
--UDF1.CELabel1.caption=tic
end


Put the above code at the top of the script (Lua Script).
It is set for a single button.
It records every click of the button and after the third click the button closes. (actvBtn.Enabled=false)
Below is an example of using the code with a button.
use:
Code:
function UDF1_CEButton1Click(sender)
actvBtn=sender
maxClick1=tonumber(maxClick1) + 1
maxClk=maxClick1
ticIndex=1
trcTim.Enabled=true
--your hack code
--sample
print(actvBtn.name.." Click= "..maxClk)
end


For more max 3 click buttons;
You should create a different "maxClick" control for each button.
Here is the usage example for the second button.

Code:
function UDF1_CEButton2Click(sender)
actvBtn=sender
maxClick2=tonumber(maxClick2) + 1
maxClk=maxClick2
ticIndex=1
trcTim.Enabled=true
--your hack code
--sample
print(actvBtn.name.." Click= "..maxClk)
end


Of course you should give this control at the top of the script.
Code:
local maxClick2=0 --button2 click
Back to top
View user's profile Send private message
mark_dellas
How do I cheat?
Reputation: 0

Joined: 28 May 2021
Posts: 9

PostPosted: Sat May 29, 2021 3:27 pm    Post subject: Reply with quote

The part the lua programation its work now , thanks.

My difficulty now is to make it really work within the game.
The memory position to be changed is as follows:

"GameName.exe +3C897C"
007C897C

I don't know how and where to insert this


And I am trying to do it in a way, that it is not necessary to press a button, because the game does not work in window mode.

So when pressing the "K" key, the trainer has to go into action
Back to top
View user's profile Send private message
ByTransient
Expert Cheater
Reputation: 5

Joined: 05 Sep 2020
Posts: 240

PostPosted: Sat May 29, 2021 6:22 pm    Post subject: Reply with quote

Wrap your current code in an asm and drop it in the address list.
I can't help with this as I don't use asm.
Below is a refactored activation and test code.
*When the key is pressed, the hack will be active, it will stay on for 5 seconds and the hack will be closed. (I'm assuming the hack code is in the address list.)
*The same action will take place with a hotkey. (Default K)
*When the hack is run 3 times, the button will turn itself off and the hotkey will die.

Code:
if trcTim then trcTim.Destroy() trcTim=nil end
trcTim=createTimer() trcTim.Interval=1000 trcTim.Enabled=false

local tic=0 --second
local ticIndex=0 --seconds back and forth index.
local actvBtn="" --button name
local maxClk=0 --timer button max click
local maxClick1=0 --button1 click

local addressList = getAddressList()

trcTim.OnTimer=function()
if ticIndex==1 then
actvBtn.Enabled=false
tic=tonumber(tic) + 1
addressList.getMemoryRecordByDescription("YourHackDescription").Active = true
if tic==6 then
ticIndex=2
tic=0
addressList.getMemoryRecordByDescription("YourHackDescription").Active = false
end
else
if maxClk==3 then
if hackKey1 then hackKey1.Destroy() hackKey1=nil end
actvBtn.Enabled=false
trcTim.Enabled=false
else
actvBtn.Enabled=true
trcTim.Enabled=false
end
end
--UDF1.CELabel1.caption=tic
end

function UDF1_CEButton1Click(sender)
actvBtn=UDF1.CEButton1
maxClick1=tonumber(maxClick1) + 1
maxClk=maxClick1
ticIndex=1
trcTim.Enabled=true
--print(actvBtn.name.." Click= "..maxClk)
end

function keyHack()
sleep(200)
UDF1_CEButton1Click()
end

if hackKey1 then hackKey1.Destroy() hackKey1=nil end
hackKey1=createHotkey(keyHack, VK_K)
Back to top
View user's profile Send private message
DaSpamer
Grandmaster Cheater Supreme
Reputation: 52

Joined: 13 Sep 2011
Posts: 1578

PostPosted: Sun May 30, 2021 9:05 pm    Post subject: Reply with quote

Try this if it, at the top there is some variables that you could customize to decide the duration, the amount of repetition, address and what key press to check.

Added a small GUI example
Code:
-- your N x M limits..
local duration    = 5;
local nTimes    = 3;
-- your address and what value you want to write, and what key to check
local address       = getAddress("GameName.exe+3C897C");
local targetValue    = 5;
local hotkey       = VK_Q;

-- past this point you could customize if you want to ..
--temp variables..
local conditionalTimestamp = 0;
local conditionalCounter = 0;
local previousValue

-- small GUI (assuming it is a trainer?)
local myForm = createForm();
myForm.setSize(250,50);
myForm.OnClose = function(sender) sender.destroy(); end;

local myLabel = createLabel(myForm);
myLabel.setPosition(5,10);
myLabel.Caption = "Idle";
myLabel.Font.Color = 0xAA00;

local myResetButton = createButton(myForm);
myResetButton.Caption = "Reset";
myResetButton.setPosition(myForm.Width - myResetButton.Width - 5,10);
myResetButton.OnClick = function(sender)
   conditionalTimestamp = 0;
   conditionalCounter = 0;
   myLabel.Caption = "Idle";
   myLabel.Font.Color = 0xAA00;
end


-- hotkey & main activation logic
local conditionalTimer = createTimer(myForm);
conditionalTimer.Interval = 16; -- 60 times a second

conditionalTimer.OnTimer = function(sender)
   if (conditionalCounter >= nTimes) then -- reached the max num of repetition so halt
      myLabel.Caption = "Reached limit";
      myLabel.Font.Color = 0xFF;
      return
   end

   local currentTS = os.clock();
   if (conditionalTimestamp+duration > currentTS) then
      writeInteger(address,targetValue); -- write value to address ..
      myLabel.Caption = ("Active - %.2f"):format(conditionalTimestamp+duration-currentTS);
   elseif(previousValue) then -- single time update after
      writeInteger(address,previousValue)
      previousValue = nil;
      conditionalCounter = conditionalCounter + 1;
      myLabel.Caption = "Idle";
   end

   if (isKeyPressed(hotkey)) then
      if (conditionalTimestamp+duration < currentTS) then
         previousValue = readInteger(address); -- backup value to restore later
         conditionalTimestamp = currentTS;
      end
   end
end

_________________
HEY Hitler
Do you get lazy when making trainers?
Well no more!
My CETrainer will generate it for you in seconds, so you won't get lazy! Very Happy

http://forum.cheatengine.org/viewtopic.php?t=564919
Back to top
View user's profile Send private message
mark_dellas
How do I cheat?
Reputation: 0

Joined: 28 May 2021
Posts: 9

PostPosted: Mon May 31, 2021 9:04 pm    Post subject: Reply with quote

DaSpamer wrote:
Try this if it, at the top there is some variables that you could customize to decide the duration, the amount of repetition, address and what key press to check.

Added a small GUI example
Code:
-- your N x M limits..
local duration    = 5;
local nTimes    = 3;
-- your address and what value you want to write, and what key to check
local address       = getAddress("GameName.exe+3C897C");
local targetValue    = 5;
local hotkey       = VK_Q;

-- past this point you could customize if you want to ..
--temp variables..
local conditionalTimestamp = 0;
local conditionalCounter = 0;
local previousValue

-- small GUI (assuming it is a trainer?)
local myForm = createForm();
myForm.setSize(250,50);
myForm.OnClose = function(sender) sender.destroy(); end;

local myLabel = createLabel(myForm);
myLabel.setPosition(5,10);
myLabel.Caption = "Idle";
myLabel.Font.Color = 0xAA00;

local myResetButton = createButton(myForm);
myResetButton.Caption = "Reset";
myResetButton.setPosition(myForm.Width - myResetButton.Width - 5,10);
myResetButton.OnClick = function(sender)
   conditionalTimestamp = 0;
   conditionalCounter = 0;
   myLabel.Caption = "Idle";
   myLabel.Font.Color = 0xAA00;
end


-- hotkey & main activation logic
local conditionalTimer = createTimer(myForm);
conditionalTimer.Interval = 16; -- 60 times a second

conditionalTimer.OnTimer = function(sender)
   if (conditionalCounter >= nTimes) then -- reached the max num of repetition so halt
      myLabel.Caption = "Reached limit";
      myLabel.Font.Color = 0xFF;
      return
   end

   local currentTS = os.clock();
   if (conditionalTimestamp+duration > currentTS) then
      writeInteger(address,targetValue); -- write value to address ..
      myLabel.Caption = ("Active - %.2f"):format(conditionalTimestamp+duration-currentTS);
   elseif(previousValue) then -- single time update after
      writeInteger(address,previousValue)
      previousValue = nil;
      conditionalCounter = conditionalCounter + 1;
      myLabel.Caption = "Idle";
   end

   if (isKeyPressed(hotkey)) then
      if (conditionalTimestamp+duration < currentTS) then
         previousValue = readInteger(address); -- backup value to restore later
         conditionalTimestamp = currentTS;
      end
   end
end



Works great. But the target value in the game (and cheat engine test) is resulting in the following data:
2.47032822920623E-323

In the table, the target value is a Double
Back to top
View user's profile Send private message
DaSpamer
Grandmaster Cheater Supreme
Reputation: 52

Joined: 13 Sep 2011
Posts: 1578

PostPosted: Tue Jun 01, 2021 11:43 am    Post subject: Reply with quote

Change in line 49 writeInteger to writeDouble
_________________
HEY Hitler
Do you get lazy when making trainers?
Well no more!
My CETrainer will generate it for you in seconds, so you won't get lazy! Very Happy

http://forum.cheatengine.org/viewtopic.php?t=564919
Back to top
View user's profile Send private message
mark_dellas
How do I cheat?
Reputation: 0

Joined: 28 May 2021
Posts: 9

PostPosted: Tue Jun 01, 2021 2:05 pm    Post subject: Reply with quote

DaSpamer wrote:
Change in line 49 writeInteger to writeDouble


I change the line 52 too.

Now the script is working perfectly Very Happy Very Happy

But one last question. When will I finally save the project as "Cheat Engine Trainer Standalone .EXE"

And when running it later, the following error message appears :


Did I do something wrong?



cheatengineerror.png
 Description:
 Filesize:  9.17 KB
 Viewed:  3890 Time(s)

cheatengineerror.png


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

Joined: 13 Sep 2011
Posts: 1578

PostPosted: Tue Jun 01, 2021 5:14 pm    Post subject: Reply with quote

You removed the quotes from the getAddress call, causing Lua to attempt to perform arithmetic on a non existent variable.

Or you did not modify it to your game name thus breaking the script.

_________________
HEY Hitler
Do you get lazy when making trainers?
Well no more!
My CETrainer will generate it for you in seconds, so you won't get lazy! Very Happy

http://forum.cheatengine.org/viewtopic.php?t=564919
Back to top
View user's profile Send private message
mark_dellas
How do I cheat?
Reputation: 0

Joined: 28 May 2021
Posts: 9

PostPosted: Tue Jun 01, 2021 5:51 pm    Post subject: Reply with quote

DaSpamer wrote:
You removed the quotes from the getAddress call, causing Lua to attempt to perform arithmetic on a non existent variable.

Or you did not modify it to your game name thus breaking the script.


I didn't remove the quotes, I kept the same in the script, I just updated it to the name of the game.

When I run the script, it works normally. The error appeared when I generated the EXE only
Back to top
View user's profile Send private message
DaSpamer
Grandmaster Cheater Supreme
Reputation: 52

Joined: 13 Sep 2011
Posts: 1578

PostPosted: Tue Jun 01, 2021 11:20 pm    Post subject: Reply with quote

I see, you did not include anywhere in the script
openProcess("gameprocess.exe")

Add it to the top of your script, alternatively you could use the Trainer Generator to generate a quick trainer.

_________________
HEY Hitler
Do you get lazy when making trainers?
Well no more!
My CETrainer will generate it for you in seconds, so you won't get lazy! Very Happy

http://forum.cheatengine.org/viewtopic.php?t=564919
Back to top
View user's profile Send private message
mark_dellas
How do I cheat?
Reputation: 0

Joined: 28 May 2021
Posts: 9

PostPosted: Wed Jun 02, 2021 7:06 am    Post subject: Reply with quote

DaSpamer wrote:
I see, you did not include anywhere in the script
openProcess("gameprocess.exe")

Add it to the top of your script, alternatively you could use the Trainer Generator to generate a quick trainer.


Now is works Very Happy

But something strange is happening.
When I open the executable, the script automatically starts running, without any commands or keystrokes.

I recorded it to better show what's happening

Code:
https://youtu.be/Sk2vr5gI_M0
Back to top
View user's profile Send private message
mark_dellas
How do I cheat?
Reputation: 0

Joined: 28 May 2021
Posts: 9

PostPosted: Thu Jun 03, 2021 7:48 pm    Post subject: Reply with quote

mark_dellas wrote:
DaSpamer wrote:
I see, you did not include anywhere in the script
openProcess("gameprocess.exe")

Add it to the top of your script, alternatively you could use the Trainer Generator to generate a quick trainer.


Now is works Very Happy

But something strange is happening.
When I open the executable, the script automatically starts running, without any commands or keystrokes.

I recorded it to better show what's happening

Code:
https://youtu.be/Sk2vr5gI_M0


Somebody?
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
Goto page 1, 2  Next
Page 1 of 2

 
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