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 


[Solved]Lua script to change debugger when starting CE

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

Joined: 01 Oct 2010
Posts: 28

PostPosted: Thu May 23, 2024 11:08 am    Post subject: [Solved]Lua script to change debugger when starting CE Reply with quote

Hi, Lua novice here.

I can see from the celua.txt that I can manipulate CE's settings directly using a Lua script in the autorun folder, I just don't know how to implement what I see.

celua.txt wrote:
Settings class
This class can be used to read out and set settings of cheat engine and of plugins, and store your own data

global functions
reloadSettingsFromRegistry(): This will cause cheat engine to reload the settings from the registry and apply them

getSettings(path Optional): Settings - Returns a settings object. If path is nil it will point to the Cheat Engine main settings (Registry) . If name is provided the settings currently accessed will be the one at the subkey provided
Note: Keep in mind that it returns a new object each call, even if he same name is used multiple times

etc ... etc ...


Pseudocode for what I'd like to do.

Code:

if registry value for VEH debugger = 1
    set value to 0
if registry value for windows debugger = 1
    set value to 0
if registry value for Kernel debugger = 1
    set value to 0
if registry value for DBVM debugger = 1
    set value to 0

(i.e. have no debugger set as default at CE startup)


Thanks for any help.

_________________
I am, and always will be, a CE novice.


Last edited by fade2gray on Mon May 27, 2024 11:28 am; edited 1 time in total
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 143

Joined: 06 Jul 2014
Posts: 4381

PostPosted: Thu May 23, 2024 12:06 pm    Post subject: Reply with quote

Code:
local f = getSettingsForm()

print('Windows:',tostring(f.cbUseWindowsDebugger.checked))
print('VEH:    ',tostring(f.cbUseVEHDebugger.checked))
print('Kernel: ',tostring(f.cbKDebug.checked))
print('DBVM:   ',tostring(f.cbUseDBVMDebugger.checked))


local function to_bool(bytetable)
  return byteTableToDword(assert(bytetable), false) ~= 0
end
local reg = getSettings()
print('Windows:',tostring(to_bool(reg.getBinaryValue'Use Windows Debugger')))
print('VEH:    ',tostring(to_bool(reg.getBinaryValue'Use VEH Debugger')))
print('Kernel: ',tostring(to_bool(reg.getBinaryValue'Use Kernel Debugger')))
print('DBVM:   ',tostring(to_bool(reg.getBinaryValue'Use DBVM Debugger')))

_________________
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
fade2gray
Cheater
Reputation: 0

Joined: 01 Oct 2010
Posts: 28

PostPosted: Fri May 24, 2024 6:22 am    Post subject: Reply with quote

Thanks for the code, but it doesn't do quite what I was hoping for.

The code only displays ...

a) The default debugger settings used when the debugger options are opened for the first time, and ...

b) The settings as they are seen in the debugger options, if they have been subsequently changed.

Thanks for any further advice.

PS: Maybe I need to somehow implement the method, 'setBinaryValue(name, stream, size OPTIONAL)'



CE_debugger_1.png
 Description:
 Filesize:  15.65 KB
 Viewed:  864 Time(s)

CE_debugger_1.png



CE_debugger_2.png
 Description:
 Filesize:  16.04 KB
 Viewed:  864 Time(s)

CE_debugger_2.png



_________________
I am, and always will be, a CE novice.
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 143

Joined: 06 Jul 2014
Posts: 4381

PostPosted: Fri May 24, 2024 11:41 am    Post subject: Reply with quote

You could set the `checked` property to false, but why would you want to do that? Other than forbidding the user from debugging the process, I don't see how that would do anything.

There are debugging functions available you might not know about:
Quote:
debugProcess(interface OPT): starts the debugger for the currently opened process (won't ask the user) Optional interface: 0=default, 1=windows debug, 2=VEHDebug, 3=Kerneldebug

debug_isDebugging(): Returns true if the debugger has been started
debug_getCurrentDebuggerInterface() : Returns the current debuggerinterface used (1=windows, 2=VEH 3=Kernel, nil=no debugging active)
...
from celua.txt
_________________
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
fade2gray
Cheater
Reputation: 0

Joined: 01 Oct 2010
Posts: 28

PostPosted: Sat May 25, 2024 8:47 am    Post subject: Reply with quote

Situation:
I may have previously booted using a DBVM bootloader, start CE and enabled DBVM, performed a scan and then use 'What accesses this address' with the DBVM debugger selected in Settings/Options.

The next time I boot up, I might do so without using the bootloader. If I then try doing 'What accesses this address', forgetting that the DBVM debugger is selected, I end up with a bunch of error messages.

I just thought it may be a simple solution to use Lua to automatically toggle from DBVM/Kernel debugger to the Windows/VEH debugger to avoid that situation.

Otherwise, I'll just use the following script to remind myself.

Code:
local function to_bool(bytetable)
    return byteTableToDword(assert(bytetable), false) ~= 0
end
local reg = getSettings()
local dbgrDBVM = tostring(to_bool(reg.getBinaryValue'Use DBVM Debugger'))
local dbgrKernel = tostring(to_bool(reg.getBinaryValue'Use Kernel Debugger'))

if dbgrDBVM == "true" or dbgrKernel == "true" then
    print("Warning: The DBVM or Kernel debugger is selected in Options.\n\nDon't forget to select the Windows or VEH debugger before using \'What writes to/accesses this address\' if DBVM isn't running.")
end


Quote:
You could set the `checked` property to false ...

I would try, but I can't figure how to do that.

_________________
I am, and always will be, a CE novice.
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 143

Joined: 06 Jul 2014
Posts: 4381

PostPosted: Sat May 25, 2024 11:37 am    Post subject: Reply with quote

fade2gray wrote:
I just thought it may be a simple solution to use Lua to automatically toggle from DBVM/Kernel debugger to the Windows/VEH debugger to avoid that situation.
Code:
local f = getSettingsForm()

if f.cbUseDBVMDebugger.checked or f.cbKDebug.checked then
  -- radio control: all others are automatically set to false
  f.cbUseWindowsDebugger.checked = true
end

Note that this won't modify the settings in the registry. The next time you start CE, the DBVM debugger could still be checked by default.
Code:
local f = getSettingsForm()

if f.cbUseDBVMDebugger.checked or f.cbKDebug.checked then
  f.cbUseWindowsDebugger.checked = true

  local reg = getSettings()
  reg["Use Windows Debugger"] = true
  reg["Use Kernel Debugger"] = false
  reg["Use DBVM Debugger"] = false
end
PS: I noticed setting the "Value" property of the TLuaSettings class correctly interprets boolean values; no need to access raw byte tables. Reading any setting just returns a string, and bools in the registry are usually just integers:
Code:
print(tostring(getSettings()["Use Windows Debugger"] ~= '0'))

_________________
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
fade2gray
Cheater
Reputation: 0

Joined: 01 Oct 2010
Posts: 28

PostPosted: Mon May 27, 2024 5:58 am    Post subject: Reply with quote

Thanks for trying, but I can't get any of the above to work as I'd like.

Is it not possible to use 'setBinaryValue(name, bytetable)'?

_________________
I am, and always will be, a CE novice.
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 460

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

PostPosted: Mon May 27, 2024 10:37 am    Post subject: Reply with quote

try '1'
_________________
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
fade2gray
Cheater
Reputation: 0

Joined: 01 Oct 2010
Posts: 28

PostPosted: Mon May 27, 2024 11:24 am    Post subject: Reply with quote

Thank you DB.
Code:

local function to_bool(bytetable)
    return byteTableToDword(assert(bytetable), false) ~= 0
end

local reg = getSettings()
local dbgrDBVM = tostring(to_bool(reg.getBinaryValue'Use DBVM Debugger'))
local dbgrKernel = tostring(to_bool(reg.getBinaryValue'Use Kernel Debugger'))

if dbgrDBVM == "true" or dbgrKernel == "true" then
    reg["Use VEH Debugger"] = '1'
    reg["Use Windows Debugger"] = '0'
    reg["Use Kernel Debugger"] = '0'
    reg["Use DBVM Debugger"] = '0'
end

_________________
I am, and always will be, a CE novice.
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