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 


Simulating activation of registered code(How is Execute code

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
Aylin
Grandmaster Cheater
Reputation: 8

Joined: 16 Feb 2017
Posts: 557

PostPosted: Tue May 19, 2020 12:29 pm    Post subject: Simulating activation of registered code(How is Execute code Reply with quote

To get started, there is a representative code below.
I want to read and activate the code written in the memo box.
It should probably read and activate a timer.
How is this done?

Code:
UDF1.CETimer1.Enabled=false
UDF1.CETimer2.Enabled=false
UDF1.CETimer1.Interval=1
UDF1.CETimer2.Interval=1
local tIndex=0

function UDF1_CETimer1Timer(sender)
tIndex=tonumber(tIndex) + 1
end

function UDF1_CETimer2Timer(sender)
if UDF1.CEMemo1.Lines.Text=="" then
showMessage("Registered code not found!\nPlease save the code first.")
tIndex=tonumber(tIndex) + 1
-- Execute Code=UDF1.CEMemo1.Lines.Text?
end
-------------------------------------------------------

function UDF1_CEPanel2Click(sender)
UDF1.CEMemo1.Lines.Add("if tIndex=="..tIndex.." then")
UDF1.CEMemo1.Lines.Add("UDF1_CEPanel7Click() end")
end

function UDF1_CEPanel3Click(sender)
UDF1.CEMemo1.Lines.Add("if tIndex=="..tIndex.." then")
UDF1.CEMemo1.Lines.Add("UDF1_CEPanel8Click() end")
end

function UDF1_CEPanel4Click(sender)
UDF1.CEMemo1.Lines.Add("if tIndex=="..tIndex.." then")
UDF1.CEMemo1.Lines.Add("UDF1_CEPanel9Click() end")
end

function UDF1_CEPanel5Click(sender)
UDF1.CEMemo1.Lines.Add("if tIndex=="..tIndex.." then")
UDF1.CEMemo1.Lines.Add("UDF1_CEPanel10Click() end")
end

function UDF1_CEPanel6Click(sender)
UDF1.CEMemo1.Lines.Add("if tIndex=="..tIndex.." then")
UDF1.CEMemo1.Lines.Add("UDF1_CEPanel11Click() end")
end
-------------------------------------------------------
function UDF1_CEPanel7Click(sender)
UDF1.CEMemo2.Lines.Add(tIndex)
UDF1.CEMemo2.Lines.Add("CEPanel7Click")
end

function UDF1_CEPanel8Click(sender)
UDF1.CEMemo2.Lines.Add(tIndex)
UDF1.CEMemo2.Lines.Add("CEPanel8Click")
end

function UDF1_CEPanel9Click(sender)
UDF1.CEMemo2.Lines.Add(tIndex)
UDF1.CEMemo2.Lines.Add("CEPanel9Click")
end

function UDF1_CEPanel10Click(sender)
UDF1.CEMemo2.Lines.Add(tIndex)
UDF1.CEMemo2.Lines.Add("CEPanel10Click")
end

function UDF1_CEPanel11Click(sender)
UDF1.CEMemo2.Lines.Add(tIndex)
UDF1.CEMemo2.Lines.Add("CEPanel11Click")
end
-------------------------------------------------------

function UDF1_CECheckbox1Change(sender)
if UDF1.CECheckbox1.checked==true then
 tIndex=0
UDF1.CEMemo1.Lines.Text=""
UDF1.CEMemo1.Lines.Add("function Play1()")
UDF1.CETimer1.Enabled=true
else
UDF1.CETimer1.Enabled=false
UDF1.CEMemo1.Lines.Add("end")
end
end

function UDF1_CECheckbox2Change(sender)
if UDF1.CECheckbox2.checked==true then
 tIndex=0
UDF1.CEMemo2.Lines.Text=""
UDF1.CETimer2.Enabled=true
else
UDF1.CETimer2.Enabled=false
end
end

_________________
Hi Hitler Take control of your trainer
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 MSN Messenger
Corroder
Grandmaster Cheater Supreme
Reputation: 33

Joined: 10 Apr 2015
Posts: 1284

PostPosted: Tue May 19, 2020 3:23 pm    Post subject: Reply with quote

If I am not misunderstood, you ask about 'How to execute codes writing in a memo'. Use loadstring(code)(), while code is memo lines text.

Example:

Code:
script = [[
f = createForm()
b = createButton(f)
b.Caption = 'Click Me'

function bclick()
 print('Hello world')
end

b.OnClick = bclick
]]

UDF1.CEMemo1.Clear()

function runScriptFromMemoContents(code)
 UDF1.CEMemo1.Clear()
 UDF1.CEMemo1.Lines.Text = script
 code = UDF1.CEMemo1.Lines.Text
 if code == "" then showMessage('Nothing to execute') else
   loadstring(code)()
 end
end

UDF1.Show()
UDF1.CEButton1.OnClick = runScriptFromMemoContents

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

Joined: 16 Feb 2017
Posts: 557

PostPosted: Tue May 19, 2020 5:03 pm    Post subject: Reply with quote

In addition to the above code;


Code:
UDF1.CEMemo1.Lines.Text=([[
function play1()
if tIndex==110 then
UDF1_CEPanel7Click() end
if tIndex==153 then
UDF1_CEPanel8Click() end
if tIndex==207 then
UDF1_CEPanel9Click() end
if tIndex==255 then
UDF1_CEPanel10Click() end
if tIndex==308 then
UDF1_CEPanel11Click() end
if tIndex==394 then
UDF1_CEPanel11Click() end
if tIndex==445 then
UDF1_CEPanel10Click() end
end
]])

function UDF1_CETimer2Timer(sender)
if UDF1.CEMemo1.Lines.Text=="" then
showMessage("Registered code not found!\nPlease save the code first.")
else
tIndex=tonumber(tIndex) + 1
examp2 = UDF1.CEMemo1.Lines.Text
loadstring(examp2)()
play1()
end
end

local path = TrainerOrigin
print(path)
function CodeSave() --Memo1
local index = 1
if path then
local settingsFile = io.open(path.."Example.txt", "w")
    if (settingsFile ~= nil) then
      settingsFile:write(control_getCaption(UDF1.CEMemo1))
      settingsFile:close()
    end
  end
end

function CodeLoad() --Memo1
  if path then
    local settingsFile = io.open(path.."Example.txt", "r")
    if (settingsFile ~= nil) then
      UDF1.CEMemo1.Lines.Text = settingsFile:read("*a")
      settingsFile:close()

    end
  end
end

function UDF1_CECheckbox2Change(sender)
if sender.checked==true then
 tIndex=0
UDF1.CEMemo2.Lines.Text=""
UDF1.CETimer2.Enabled=true
else
UDF1.CETimer2.Enabled=false
end
end


How can I run "play1 ()" or "Memo1" commands.
I tried the method you gave me did not work.

_________________
Hi Hitler Take control of your trainer
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 MSN Messenger
Corroder
Grandmaster Cheater Supreme
Reputation: 33

Joined: 10 Apr 2015
Posts: 1284

PostPosted: Tue May 19, 2020 9:43 pm    Post subject: Reply with quote

Code:
function UDF1_CETimer2Timer(sender)
if UDF1.CEMemo1.Lines.Text=="" then
showMessage("Registered code not found!\nPlease save the code first.")
else
tIndex=tonumber(tIndex) + 1
examp2 = UDF1.CEMemo1.Lines.Text
loadstring(examp2) (play1)   --- looking here
play1()
end
end


Similar with this code:

Code:
UDF1.CEMemo1.Lines.Text=[[
function play1()
print('hello world')
end
]]


function test()
 local examp2 = UDF1.CEMemo1.Lines.Text
 loadstring(examp2) (play1)
 play1()
end

UDF1.Show()
UDF1.CEButton1.OnClick = test

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

Joined: 16 Feb 2017
Posts: 557

PostPosted: Wed May 20, 2020 9:08 am    Post subject: Reply with quote

Solved @Corroder.
Key point; Write the entire function into Load.

Example;

Code:
examp11=[[
local tIndex=0 --It doesn't work to promote it in lua. It is necessary to introduce it in Load.

function Play1()
print(tIndex)
if tIndex==tonumber(120) then
UDF1_CEPanel7Click() end
if tIndex==163 then
UDF1_CEPanel8Click() end
if tIndex==202 then
UDF1_CEPanel9Click() end
if tIndex==237 then
UDF1_CEPanel10Click() end
if tIndex==284 then
UDF1_CEPanel11Click() end
if tIndex==430 then
UDF1_CEPanel10Click() end
if tIndex==482 then
UDF1_CEPanel9Click() end
if tIndex==521 then
UDF1_CEPanel8Click() end
if tIndex==577 then
UDF1_CEPanel7Click() end
if tIndex==678 then
UDF1_CEPanel7Click() end
if tIndex==723 then
UDF1_CEPanel7Click() end
if tIndex==777 then
UDF1_CEPanel8Click() end
if tIndex==818 then
UDF1_CEPanel8Click() end
if tIndex==867 then
UDF1_CEPanel9Click() end
if tIndex==908 then
UDF1_CEPanel9Click() end
if tIndex==956 then
UDF1_CEPanel10Click() end
if tIndex==1001 then
UDF1_CEPanel10Click() end
if tIndex==1071 then
UDF1_CEPanel11Click() end
if tIndex==1113 then
UDF1_CEPanel11Click() end
if tIndex==1168 then
UDF1_CEPanel7Click() end
if tIndex==1288 then
UDF1.CETimer2.Enabled=false
end
end

UDF1.CETimer2.OnTimer=function()
tIndex=tonumber(tIndex) + 1
Play1()
end
]]


--Save
function UDF1_CECheckbox1Change(sender)
if UDF1.CECheckbox1.checked==true then
 tIndex=0
UDF1.CEMemo1.Lines.Text=""
UDF1.CEMemo1.Lines.Add("local tIndex=0")
UDF1.CEMemo1.Lines.Add("function Play1()")
UDF1.CETimer1.Enabled=true
else
UDF1.CEMemo1.Lines.Add("if tIndex=="..tIndex.." then")
UDF1.CEMemo1.Lines.Add("UDF1.CETimer2.Enabled=false")
UDF1.CEMemo1.Lines.Add("end")
UDF1.CEMemo1.Lines.Add("end")
UDF1.CEMemo1.Lines.Add("\nUDF1.CETimer2.OnTimer=function()")
UDF1.CEMemo1.Lines.Add("tIndex=tonumber(tIndex) + 1")
UDF1.CEMemo1.Lines.Add("Play1()")
UDF1.CEMemo1.Lines.Add("end")
CodeSave()
UDF1.CETimer1.Enabled=false
end
end

--Load and Play
function UDF1_CECheckbox2Change(sender)
UDF1.CEMemo2.Lines.Text=""
local examp2 = UDF1.CEMemo1.Lines.Text
if sender.checked==true then

examp12=([[]]..UDF1.CEMemo1.Lines.Text..[[]])
load(examp12)()
UDF1.CETimer2.Enabled=true
else
UDF1.CETimer2.Enabled=false
end
end


And Thanks Again.

( Imagine doing a Piano with CE Lua.
It should have 8 notes and 8 effects.
The above question is; It simulates recording music and automatic replay.
I think my project is complete. )

_________________
Hi Hitler Take control of your trainer
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 MSN Messenger
Aylin
Grandmaster Cheater
Reputation: 8

Joined: 16 Feb 2017
Posts: 557

PostPosted: Sat May 23, 2020 1:31 pm    Post subject: Reply with quote

What can be done with Cheat Engine?
Game hacking? Mp3 player? File manager?
Or a small piano? I made a piano. Smile
I'll share it soon. The fun should continue.

Note: @Corroder, When the project is completed, I will send you the .CT sample.



Ek-1.PNG
 Description:
 Filesize:  105.94 KB
 Viewed:  242 Time(s)

Ek-1.PNG



_________________
Hi Hitler Take control of your trainer
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 MSN Messenger
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