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 


Debugging Lua script [CE modification, autorun]

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
mgr.inz.Player
I post too much
Reputation: 218

Joined: 07 Nov 2008
Posts: 4438
Location: W kraju nad Wisla. UTC+01:00

PostPosted: Wed Jul 31, 2013 8:02 pm    Post subject: Debugging Lua script [CE modification, autorun] Reply with quote

For those who are debugging/testing trainers (trainer saved as CT file).


Try to execute this example script:
Code:
RequiredCEVersion=6.3
if (getCEVersion==nil) or (getCEVersion()<RequiredCEVersion) then
  messageDialog('Please install Cheat Engine '..RequiredCEVersion, mtError, mbOK)
  closeCE()
end
addresslist=getAddressList()


variable1 = 32423
variable2 = 32423

form_show(notExist)  -- Obvious, not like form_show(ShowCheatIist)

function AboutClick()
  showMessage(gAboutText)
end
gAboutText=[[This trainer was made by Cheat Engine
www.cheatengine.org]]



You will get "undefined lua error" message window and "Error:Invalid class object" string inside log output of "Lua Engine" window. Obviously, it is notExist variable's fault. But, if you have "wall of text", it is hard to catch typos like like this: you typed in form_show(ShowCheatIist) instead of form_show(ShowCheatlist).




My script (move it to autorun):
Code:
function trace(event, line)
  local s = debug.getinfo(2).short_src
  if not s:match('%[string') then return end
  DebugLabel.Caption = "last line executed: "..line
end

frmLuaTableScript = getMainForm().frmAutoInject
frmLuaTableScriptPanel1OnResizeOLD = frmLuaTableScript.Panel1.OnResize

frmLuaTableScript.Panel1.OnResize = function (sender)
  frmLuaTableScriptPanel1OnResizeOLD(sender)

  DebugButton.Top  = Button.Top  - 8
  DebugButton.Left = Button.Left + 50

  DebugLabel.Top   = Button.Top  + 18
  DebugLabel.Left  = Button.Left + 55

  Button.Left = Button.Left - 80
end

debugOnOffFlag = false

Button = frmLuaTableScript.Button1
Button.AutoSize = true

DebugLabel = createLabel(frmLuaTableScript.Panel1)
DebugLabel.AutoSize = true
DebugLabel.Caption = "debug disabled"

DebugButton = createButton(frmLuaTableScript.Panel1)
DebugButton.AutoSize = true
DebugButton.Caption = "Find faulty line"
DebugButton.Height = Button.Height

DebugButton.OnClick = function ()
  debugOnOffFlag = not debugOnOffFlag
    if debugOnOffFlag then debug.sethook(trace, "l")
                           DebugButton.Font.Style = '[fsBold]'
                           DebugLabel.Caption = "last line executed:"
                      else debug.sethook()
                           DebugButton.Font.Style = '[]'
                           DebugLabel.Caption = "debug disabled"
                      end
end




Now, you will have additional Button, called "Find faulty line". Click it, it gets bold and label shows "last line executed". Click "Execute script". You will get the same error messages and message window. But, this time you will get "last line executed" info.

In this case: "last line executed: 12"


Edit1:
added comments.

EDIT2:
newest version of this script here LINK



LuaDebug_FindFaultyLine.lua
 Description:
Feel free to modify it

Download
 Filename:  LuaDebug_FindFaultyLine.lua
 Filesize:  1.85 KB
 Downloaded:  1150 Time(s)


_________________


Last edited by mgr.inz.Player on Sun Aug 11, 2013 12:02 pm; edited 3 times in total
Back to top
View user's profile Send private message MSN Messenger
DaSpamer
Grandmaster Cheater Supreme
Reputation: 52

Joined: 13 Sep 2011
Posts: 1578

PostPosted: Thu Aug 01, 2013 9:46 am    Post subject: Reply with quote

thanks if i could rep u again i would but need to find some else before i can rep u again
_________________
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
mgr.inz.Player
I post too much
Reputation: 218

Joined: 07 Nov 2008
Posts: 4438
Location: W kraju nad Wisla. UTC+01:00

PostPosted: Thu Aug 01, 2013 10:07 am    Post subject: Reply with quote

Thanks Razz
_________________
Back to top
View user's profile Send private message MSN Messenger
DaSpamer
Grandmaster Cheater Supreme
Reputation: 52

Joined: 13 Sep 2011
Posts: 1578

PostPosted: Thu Aug 01, 2013 10:09 am    Post subject: Reply with quote

lets hope this will be in the next ce version or build.
_________________
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
mgr.inz.Player
I post too much
Reputation: 218

Joined: 07 Nov 2008
Posts: 4438
Location: W kraju nad Wisla. UTC+01:00

PostPosted: Thu Aug 01, 2013 10:13 am    Post subject: Reply with quote

From other thread:
Dark Byte wrote:
I once looked into it but it resulted in a even worse bug, but i'll see (perhaps the debug.hook function might be useful here to see the last called function)

Maybe now he can overcome this problem.

_________________
Back to top
View user's profile Send private message MSN Messenger
mgr.inz.Player
I post too much
Reputation: 218

Joined: 07 Nov 2008
Posts: 4438
Location: W kraju nad Wisla. UTC+01:00

PostPosted: Sun Aug 11, 2013 10:24 am    Post subject: This post has 3 review(s) Reply with quote

Small update:
- different button positions...
- extra info about function name


Code:
function trace(event, line)
  local s = debug.getinfo(2).short_src
  local name = debug.getinfo(2).name
  name = name and ' ( func '..name..' )' or ''
 
  if not s:match('%[string') then return end
  DebugLabel.Caption = "last line executed: "..line..name
end

frmLuaTableScript = getMainForm().frmAutoInject
frmLuaTableScriptPanel1OnResizeOLD = frmLuaTableScript.Panel1.OnResize

frmLuaTableScript.Panel1.OnResize = function (sender)
  frmLuaTableScriptPanel1OnResizeOLD(sender)

  Button.Left = Button.Left - 110

  DebugButton.Top  = Button.Top
  DebugButton.Left = Button.Left + 120

  DebugLabel.Top   = Button.Top  + 4
  DebugLabel.Left  = Button.Left + 250

end

debugOnOffFlag = false

Button = frmLuaTableScript.Button1
Button.AutoSize = true

DebugLabel = createLabel(frmLuaTableScript.Panel1)
DebugLabel.AutoSize = true
DebugLabel.Caption = "debug disabled"

DebugButton = createButton(frmLuaTableScript.Panel1)
DebugButton.AutoSize = true
DebugButton.Caption = "Find faulty line"
DebugButton.Height = Button.Height

DebugButton.OnClick = function ()
  debugOnOffFlag = not debugOnOffFlag
    if debugOnOffFlag then debug.sethook(trace, "l")
                           DebugLabel.Caption = "last line executed:"
                      else debug.sethook()
                           DebugLabel.Caption = "debug disabled"
                      end
end

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

Joined: 13 Sep 2011
Posts: 1578

PostPosted: Sun Aug 11, 2013 10:33 am    Post subject: Reply with quote

mgr.inz.Player wrote:
Small update:
- different button positions...
- extra info about function name


Code:
function trace(event, line)
  local s = debug.getinfo(2).short_src
  local name = debug.getinfo(2).name
  name = name and ' ( func '..name..' )' or ''
 
  if not s:match('%[string') then return end
  DebugLabel.Caption = "last line executed: "..line..name
end

frmLuaTableScript = getMainForm().frmAutoInject
frmLuaTableScriptPanel1OnResizeOLD = frmLuaTableScript.Panel1.OnResize

frmLuaTableScript.Panel1.OnResize = function (sender)
  frmLuaTableScriptPanel1OnResizeOLD(sender)

  Button.Left = Button.Left - 110

  DebugButton.Top  = Button.Top
  DebugButton.Left = Button.Left + 120

  DebugLabel.Top   = Button.Top  + 4
  DebugLabel.Left  = Button.Left + 250

end

debugOnOffFlag = false

Button = frmLuaTableScript.Button1
Button.AutoSize = true

DebugLabel = createLabel(frmLuaTableScript.Panel1)
DebugLabel.AutoSize = true
DebugLabel.Caption = "debug disabled"

DebugButton = createButton(frmLuaTableScript.Panel1)
DebugButton.AutoSize = true
DebugButton.Caption = "Find faulty line"
DebugButton.Height = Button.Height

DebugButton.OnClick = function ()
  debugOnOffFlag = not debugOnOffFlag
    if debugOnOffFlag then debug.sethook(trace, "l")
                           DebugLabel.Caption = "last line executed:"
                      else debug.sethook()
                           DebugLabel.Caption = "debug disabled"
                      end
end

It seems to not display the name var.
Only line, is it suppose to be that?
Also this line is required to executed, if you do not resize the Lua script window.

frmLuaTableScript.Panel1.OnResize()

+Rep, helps alot, thanks.

_________________
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
mgr.inz.Player
I post too much
Reputation: 218

Joined: 07 Nov 2008
Posts: 4438
Location: W kraju nad Wisla. UTC+01:00

PostPosted: Sun Aug 11, 2013 10:47 am    Post subject: Reply with quote

We don't have to call OnResize, this event occurs just after opening LuaTableScript window ("Lua Script: Cheat Table").



Quote:
It seems to not display the name var.

It is function name for most of the time. And maybe something else...

Try this code:
Code:


function testIt()
  form_show(nihilNovi)
end


testIt()

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

Joined: 13 Sep 2011
Posts: 1578

PostPosted: Sun Aug 11, 2013 10:54 am    Post subject: Reply with quote

mgr.inz.Player wrote:
We don't have to call OnResize, this event occurs just after opening LuaTableScript window ("Lua Script: Cheat Table").



Quote:
It seems to not display the name var.

It is function name for most of the time. And maybe something else...

Try this code:
Code:


function testIt()
  form_show(nihilNovi)
end


testIt()

I execute it via the lua script window, so no wonder why it didn't change it's position Smile.

Quote:

function testIt()
form_show(nihilNovi)
end

Seem to work (returns the full line).
Thanks Smile.

_________________
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
mgr.inz.Player
I post too much
Reputation: 218

Joined: 07 Nov 2008
Posts: 4438
Location: W kraju nad Wisla. UTC+01:00

PostPosted: Sun Aug 11, 2013 11:26 am    Post subject: Reply with quote

DaSpamer wrote:
I execute it via the lua script window, so no wonder why it didn't change it's position Smile

Oh, in that case you need this at the end:
Code:
frmLuaTableScript.Panel1.OnResize()





EDIT:
Another revision, shouldn't interfere with other Lua scripts:


Code:
SimpleLuaDebugger = {}

function SimpleLuaDebugger.Trace(event, line)
  local s = debug.getinfo(2).short_src
  local name = debug.getinfo(2).name
  name = name and ' ( function '..name..' )' or ''

  if not s:match('%[string') then return end
  SimpleLuaDebugger.DebugLabel.Caption = "Last line executed: "..line..name
end

function SimpleLuaDebugger:Init()
  self.frmLuaTableScript = getMainForm().frmAutoInject
  self.frmLuaTableScriptPanel1OnResizeOLD = self.frmLuaTableScript.Panel1.OnResize

  self.debugOnOffFlag = false

  self.Button = self.frmLuaTableScript.Button1
  self.Button.AutoSize = true

  self.DebugLabel = createLabel(self.frmLuaTableScript.Panel1)
  self.DebugLabel.AutoSize = true
  self.DebugLabel.Caption = "Lua debug: disabled"

  self.DebugButton = createButton(self.frmLuaTableScript.Panel1)
  self.DebugButton.AutoSize = true
  self.DebugButton.Caption = "Find faulty line"
  self.DebugButton.Height = self.Button.Height



  self.frmLuaTableScript.Panel1.OnResize = function (sender)
      self.frmLuaTableScriptPanel1OnResizeOLD(sender)

      self.Button.Left = self.Button.Left - 140

      self.DebugButton.Top  = self.Button.Top
      self.DebugButton.Left = self.Button.Left + 120

      self.DebugLabel.Top   = self.Button.Top  + 4
      self.DebugLabel.Left  = self.Button.Left + 250
    end

  self.DebugButton.OnClick = function ()
      self.debugOnOffFlag = not self.debugOnOffFlag
        if self.debugOnOffFlag then debug.sethook(SimpleLuaDebugger.Trace, "l")
                                    self.DebugLabel.Caption = "Lua debug: enabled"
                               else debug.sethook()
                                    self.DebugLabel.Caption = "Lua debug: disabled"
                               end
    end
   
  self.frmLuaTableScript.Panel1.OnResize()
end

SimpleLuaDebugger:Init()



LuaDebug_FindFaultyLine.lua
 Description:

Download
 Filename:  LuaDebug_FindFaultyLine.lua
 Filesize:  2.3 KB
 Downloaded:  1203 Time(s)


_________________
Back to top
View user's profile Send private message MSN Messenger
bknight2602
Grandmaster Cheater
Reputation: 0

Joined: 08 Oct 2012
Posts: 577

PostPosted: Sun Feb 27, 2022 6:54 am    Post subject: Reply with quote

So, copy this into what I call the debug window and execute? In other words NOT into the main script started by ctrl+alt+L.

ETA: Ok, there is a button created on the debug window. Pushed that button and the code seems to be in a loop printing out nothing of befit to me.
Back to top
View user's profile Send private message Yahoo 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