Page 1 of 1
[Lua] Toggle an entry in a table
Posted: Mon Aug 02, 2021 4:03 pm
by LeFiXER
Code: Select all
function getMemRec(s)
local al = getAddressList()
local s = al.getMemoryRecordByDescription(tostring(s))
if s ~= nil then
return s
else
error(showMessage("Couldn't find the script :("))
end
end
function toggleScript(scr)
local x = getMemRec(scr)
if x ~= nil then
x.Active = not x.Active
if x.Active == true then
-- Set the enabled colour here, this is a medium-green
x.Color = 0x00AA00
else
-- Set the disabled colour here, this is a medium-red
x.Color = 0x0000AA
end
end
end
Usage:
in any other script
Code: Select all
[ENABLE]
...
{$LUA}
toggleScript('description of the script you wish to toggle here')
{$ASM}
[DISABLE]
...
{$LUA}
toggleScript('You get the idea')
This can be useful if you want to toggle another, or multiple scripts at the same time.
If this helps you in any way, please show your support by rating this post. Thanks
Re: [Lua] Toggle an entry in a table
Posted: Mon Aug 02, 2021 11:03 pm
by ShyTwig16
Not that there was anything wrong with the script, but with these changes you can use the description or ID. Plus I think it makes it a tiny bit more readable, and makes use of the "AddressList" variable CE makes available.
Code: Select all
function getMemRec(id)
local mr
if type(id) == 'string' then
mr = AddressList.getMemoryRecordByDescription(id)
else
mr = AddressList.getMemoryRecordByID(id)
end
if mr ~= nil then
return mr
else
error(showMessage("Couldn't find the script :("))
end
end
function toggleScript(id)
local mr = getMemRec(id)
if mr ~= nil then
mr.Active = not mr.Active
if mr.Active == true then
-- Set the enabled colour here, this is a medium-green
mr.Color = 0x00AA00
else
-- Set the disabled colour here, this is a medium-red
mr.Color = 0x0000AA
end
end
end
And this post/topic might be better suited in the tools section, or maybe the tutorials section; I think tools is more fitting though. It would help keep it from just getting buried here. Let me know if you would like it moved.
Re: [Lua] Toggle an entry in a table
Posted: Mon Aug 02, 2021 11:25 pm
by LeFiXER
I would not take offence to any improvement. I'm not a professional programmer by any means, I just like to share what I know and if anyone can improve that then I am all for it. I appreciate that you took the time to look at it and give excellent input/feedback.
If you feel that it would be more fitting in the tools section then by all means feel free to move it.
Thanks!
Re: [Lua] Toggle an entry in a table
Posted: Mon Aug 02, 2021 11:42 pm
by aSwedishMagyar
ShyTwig16 wrote: ↑Mon Aug 02, 2021 11:03 pm
Not that there was anything wrong with the script, but with these changes you can use the description or ID. Plus I think it makes it a tiny bit more readable, and makes use of the "AddressList" variable CE makes available.
And this post/topic might be better suited in the tools section, or maybe the tutorials section; I think tools is more fitting though. It would help keep it from just getting buried here. Let me know if you would like it moved.
I actually think it would be better to use the getAddressList() to preserve compatibility since I think AddressList is a feature that is only in v7.2+.
Also I like the idea of this going to tools so we can turn it into a repository of helper functions in lua.
Here are some of my contributions:
Simple function for disabling all your scripts at once.
Code: Select all
function disableScripts()
local addList = getAddressList()
for i = 0,addList.Count - 1 do
if addList[i].Type == vtAutoAssembler and addList[i].Description ~= 'Enable' then addList[i].Active = false end
end
end
Just returns the Base and Size of a module which you can use in search limits.
Code: Select all
function getModuleLimits(moduleName)
local modList = enumModules()
local moduleTemp = nil
local params = nil
for i = 1,#modList do
if moduleName == modList[i].Name then
moduleTemp = modList[i]
end
end
if moduleTemp then
params = {moduleTemp.Address,getModuleSize(moduleName)}
end
return params
end
Function for getting the address or parameter from an opcode. Useful for getting base addresses within a module or making sure your offsets are always correct when you have an AOB with wildcards.
Code: Select all
function getParamFromOpcode(opAddr)
local disassembler = createDisassembler()
disassembler.disassemble(opAddr)
local disTable = disassembler.getLastDisassembleData()
local modrm = disTable.modrmValue
local param = disTable.parameterValue
if modrm and modrm ~= 0 then return modrm
elseif param and param ~= 0 then return param end
return nil
end
Simple timer creation function to keep things organized:
Code: Select all
function createMyTimer(func,params,interval)
if func == nil then return nil end
local timer = createTimer()
timer.Interval = interval
timer.OnTimer = function() func(params) end
return timer
end
Functions for quickly adding/removing records or headers to your table:
Code: Select all
function createRecord(base,desc,vType,topRec)
local addList = getAddressList()
local newRec = addList.createMemoryRecord()
newRec.Address = base
newRec.Description = desc
newRec.Type = vType
if topRec then newRec.appendToEntry(topRec) end
end
For the headers keep in mind that the offset list must be in descending order (top to bottom).
Code: Select all
function createHeader(base,desc,offList,topRec)
local addList = getAddressList()
local header = addList.createMemoryRecord()
header.Address = base
header.OffsetCount = #offList
for i = 0,#offList - 1 do
header.Offset[i] = offList[i+1]
end
header.Description = desc
header.IsAddressGroupHeader = true
header.options = '[moHideChildren]'
if topRec then header.appendToEntry(topRec) end
return header
end
Code: Select all
function removeRecords(mainRec)
if mainRec ~= nil then
while mainRec.Count > 0 do
mainRec.Child[0]:Delete()
end
end
end
Re: [Lua] Toggle an entry in a table
Posted: Tue Aug 03, 2021 12:54 am
by ShyTwig16
aSwedishMagyar wrote: ↑Mon Aug 02, 2021 11:42 pm
...
I actually think it would be better to use the getAddressList() to preserve compatibility since I think AddressList is a feature that is only in v7.2+.
Also I like the idea of this going to tools so we can turn it into a repository of helper functions in lua.
...
I think "AddressList" and "MainForm" was added in 6.3 but not really sure, I know it's in 6.8.3 as I still have that one installed and just checked the celua file. But this is a good point, and I should have mentioned this. So thanks for pointing it out. I have seen plenty on people using older versions of CE, and if they're not using the new features no reason to force them to update for something so trivial. But I have a habit of adding a fix for that to my tables. Just something simple, if nil then set them, at the start of my lua code. But I guess it's a bit of, six in on hand and half a dozen in the other.
And I've been thinking a Lua extensions section would be a good idea, but with the tools section now I'm not really sure. But a Lua functions/extensions topic in tools might not be a bad idea, I don't know something to think about I guess.
Re: [Lua] Toggle an entry in a table
Posted: Sun May 14, 2023 4:48 pm
by sakuchi123
can you help me with this code
[ENABLE]
alloc(dmgMOD1,2048,"GRB.exe"+26130D1)
label(returnhere)
label(originalcode)
label(exit)
dmgMOD1:
mov [rax+08],(float)999
originalcode:
movss [rax+08],xmm6
exit:
jmp returnhere
"GRB.exe"+26130D1:
jmp dmgMOD1
returnhere:
alloc(dmgMOD2,2048,"GRB.exe"+261A590)
label(returnhere2)
label(originalcode2)
label(exit2)
dmgMOD2:
mov [rcx+08],(float)999
originalcode2:
movss xmm0,[rcx+08]
exit2:
jmp returnhere2
"GRB.exe"+261A590:
jmp dmgMOD2
returnhere2:
alloc(dmgMOD3,2048,"GRB.exe"+267B809)
label(returnhere3)
label(originalcode3)
label(exit3)
dmgMOD3:
mov [rcx+08],(float)999
originalcode3:
movss xmm0,[rcx+08]
exit3:
jmp returnhere3
"GRB.exe"+267B809:
jmp dmgMOD3
returnhere3:
[DISABLE]
dealloc(dmgMOD1)
"GRB.exe"+26130D1:
movss [rax+08],xmm6
dealloc(dmgMOD2)
"GRB.exe"+261A590:
movss xmm0,[rcx+08]
dealloc(dmgMOD3)
"GRB.exe"+267B809:
movss xmm0,[rcx+08]
i can'not execute it is show string bra bra
Re: [Lua] Toggle an entry in a table
Posted: Mon May 15, 2023 2:54 pm
by LeFiXER
sakuchi123 wrote: ↑Sun May 14, 2023 4:48 pm
can you help me with this code
[ENABLE]
alloc(dmgMOD1,2048,"GRB.exe"+26130D1)
label(returnhere)
label(originalcode)
label(exit)
dmgMOD1:
mov [rax+08],(float)999
originalcode:
movss [rax+08],xmm6
exit:
jmp returnhere
"GRB.exe"+26130D1:
jmp dmgMOD1
returnhere:
alloc(dmgMOD2,2048,"GRB.exe"+261A590)
label(returnhere2)
label(originalcode2)
label(exit2)
dmgMOD2:
mov [rcx+08],(float)999
originalcode2:
movss xmm0,[rcx+08]
exit2:
jmp returnhere2
"GRB.exe"+261A590:
jmp dmgMOD2
returnhere2:
alloc(dmgMOD3,2048,"GRB.exe"+267B809)
label(returnhere3)
label(originalcode3)
label(exit3)
dmgMOD3:
mov [rcx+08],(float)999
originalcode3:
movss xmm0,[rcx+08]
exit3:
jmp returnhere3
"GRB.exe"+267B809:
jmp dmgMOD3
returnhere3:
[DISABLE]
dealloc(dmgMOD1)
"GRB.exe"+26130D1:
movss [rax+08],xmm6
dealloc(dmgMOD2)
"GRB.exe"+261A590:
movss xmm0,[rcx+08]
dealloc(dmgMOD3)
"GRB.exe"+267B809:
movss xmm0,[rcx+08]
i can'not execute it is show string bra bra
Perhaps you should post your problem in the relevant section instead of posting in a thread that has nothing to do with what you want, or need.
Re: [Lua] Toggle an entry in a table
Posted: Mon May 15, 2023 5:28 pm
by sakuchi123
LeFiXER wrote: ↑Mon May 15, 2023 2:54 pm
sakuchi123 wrote: ↑Sun May 14, 2023 4:48 pm
can you help me with this code
[ENABLE]
alloc(dmgMOD1,2048,"GRB.exe"+26130D1)
label(returnhere)
label(originalcode)
label(exit)
dmgMOD1:
mov [rax+08],(float)999
originalcode:
movss [rax+08],xmm6
exit:
jmp returnhere
"GRB.exe"+26130D1:
jmp dmgMOD1
returnhere:
alloc(dmgMOD2,2048,"GRB.exe"+261A590)
label(returnhere2)
label(originalcode2)
label(exit2)
dmgMOD2:
mov [rcx+08],(float)999
originalcode2:
movss xmm0,[rcx+08]
exit2:
jmp returnhere2
"GRB.exe"+261A590:
jmp dmgMOD2
returnhere2:
alloc(dmgMOD3,2048,"GRB.exe"+267B809)
label(returnhere3)
label(originalcode3)
label(exit3)
dmgMOD3:
mov [rcx+08],(float)999
originalcode3:
movss xmm0,[rcx+08]
exit3:
jmp returnhere3
"GRB.exe"+267B809:
jmp dmgMOD3
returnhere3:
[DISABLE]
dealloc(dmgMOD1)
"GRB.exe"+26130D1:
movss [rax+08],xmm6
dealloc(dmgMOD2)
"GRB.exe"+261A590:
movss xmm0,[rcx+08]
dealloc(dmgMOD3)
"GRB.exe"+267B809:
movss xmm0,[rcx+08]
i can'not execute it is show string bra bra
Perhaps you should post your problem in the relevant section instead of posting in a thread that has nothing to do with what you want, or need.
sorry i just want someone that edit this script to make it work