 |
Cheat Engine The Official Site of Cheat Engine
|
View previous topic :: View next topic |
Author |
Message |
daspamer Grandmaster Cheater Supreme
Reputation: 54
Joined: 13 Sep 2011 Posts: 1588
|
Posted: Thu Jul 25, 2013 5:18 pm Post subject: [C.E Extension] Cheat Engine Trainer > LUA Trainer. |
|
|
Hey guys,
Wrote this little easy script...
It's not full, but it will save you time of converting GUI locations, caption, visible,size and etc.
And even save you time, instead writing the GUI trainer.
Like if you have created a trainer using cheat engine Table > create form method and did not use lua commands.
This will help you convert it to lua.
of course you can edit it and add more stuff you wish...
This script basically, prints script for creating your GUI.
This was created because of request of Abhijeet1001
(thread: http://forum.cheatengine.org/viewtopic.php?t=566684)
Image preview:
URL: http://i39.tinypic.com/29j4v4.png
Credits:
Me obviously
Script:
Code: | function TranslateToFunction(Str, parent)
if (type(Str) ~= 'string') then error('Not valid type'); end;
local action = 'create' .. string.gsub(Str, 'TCE', '') -- Easy solution..
if ( Str == 'TTabSheet' and parent and object_getClassName(parent) == 'TCEPageControl') then
action = parent.getName() .. '.addTab()';
end
return action
end
function GenerateLuaScript(WantedForm)
Form = WantedForm
FormToLua = {}
FormToLua.MainForm = {}
CompCount = Form.getComponentCount()
FormToLua.MainForm.name = Form.getName()
FormToLua.MainForm.caption = Form.Caption
FormToLua.MainForm.left = Form.Left
FormToLua.MainForm.top = Form.Top
FormToLua.MainForm.width = Form.Width
FormToLua.MainForm.height = Form.Height
FormToLua.MainForm.align = Form.Align
FormToLua.MainForm.enabled = tostring(Form.Enabled)
FormToLua.MainForm.visible = control_getVisible(Form) and 'true' or 'false'
for i=1,CompCount do
i = i-1
FormToLua[i] = {}
Object = UDF1.getComponent(i)
FormToLua[i].Object_parent = Object.Parent.getName()
FormToLua[i].Object_type = TranslateToFunction(object_getClassName(Object), Object.Parent) or error("No object type???");
FormToLua[i].Object_name = Object.getName() or false
FormToLua[i].Object_caption = Object.caption or false
FormToLua[i].Object_left = Object.Left or false
FormToLua[i].Object_top = Object.Top or false
FormToLua[i].Object_width = Object.Width or false
FormToLua[i].Object_height = Object.Height or false
FormToLua[i].Object_align = Object.Align or false
FormToLua[i].Object_enabled = Object.Enabled and 'true' or false
FormToLua[i].Object_visible = control_getVisible(Object) and 'true' or false
FormToLua[i].IsTab = object_getClassName(Object) == 'TTabSheet';
-- FormToLua[i].Object_color = tostring(Object.Color) -- Not sure that you need this
-- FormToLua[i].Object_font = tostring(Object.Font) -- Or this..
end
GenerateScript = [[--Creates first the form
]] .. FormToLua.MainForm.name .. [[ = createForm(]] .. FormToLua.MainForm.visible .. [[)
]] .. FormToLua.MainForm.name .. [[.caption = ]] .. "[[" .. FormToLua.MainForm.caption .. "]]" .. [[
]] .. FormToLua.MainForm.name .. [[.left = ]] .. FormToLua.MainForm.left .. [[
]] .. FormToLua.MainForm.name .. [[.top = ]] .. FormToLua.MainForm.top .. [[
]] .. FormToLua.MainForm.name .. [[.width = ]] .. FormToLua.MainForm.width .. [[
]] .. FormToLua.MainForm.name .. [[.height = ]] .. FormToLua.MainForm.height .. [[
]] .. FormToLua.MainForm.name .. [[.align = ]] .. FormToLua.MainForm.align .. [[
]] .. FormToLua.MainForm.name .. [[.enabled = ]] .. FormToLua.MainForm.enabled .. [[
]] .. FormToLua.MainForm.name .. [[.visible = ]] .. FormToLua.MainForm.visible
for line in string.gfind (GenerateScript,"[^\n]+") do
print(line)
end
TempText = [[-- Creating the objects]]
for i = 1, CompCount do
i = i-1
TempText = TempText ..[[
]] .. (FormToLua[i].IsTab and FormToLua[i].Object_name .. [[ = ]] .. FormToLua[i].Object_type or FormToLua[i].Object_name .. [[ = ]] .. FormToLua[i].Object_type .. [[(]] .. FormToLua[i].Object_parent .. [[)]]) .. [[
]] .. ((FormToLua[i].Object_caption == false) and '' or FormToLua[i].Object_name .. [[.caption = ]] .. "[[" .. FormToLua[i].Object_caption .. "]]") .. [[
]] .. ((FormToLua[i].Object_left == false) and '' or FormToLua[i].Object_name .. [[.left = ]] .. "[[" .. FormToLua[i].Object_left .. "]]") .. [[
]] .. ((FormToLua[i].Object_top == false) and '' or FormToLua[i].Object_name .. [[.top = ]] .. "[[" .. FormToLua[i].Object_top .. "]]") .. [[
]] .. ((FormToLua[i].Object_width == false) and '' or FormToLua[i].Object_name .. [[.width = ]] .. "[[" .. FormToLua[i].Object_width .. "]]") .. [[
]] .. ((FormToLua[i].Object_height == false) and '' or FormToLua[i].Object_name .. [[.height = ]] .. "[[" .. FormToLua[i].Object_height .. "]]") .. [[
]] .. ((FormToLua[i].Object_align == false) and '' or FormToLua[i].Object_name .. [[.align = ]] .. "[[" .. FormToLua[i].Object_align .. "]]") .. [[
]] .. ((FormToLua[i].Object_enabled == false) and '' or FormToLua[i].Object_name .. [[.enabled = ]] .. "[[" .. FormToLua[i].Object_enabled .. "]]") .. [[
]] .. ((FormToLua[i].Object_visible == false) and '' or FormToLua[i].Object_name .. [[.visible = ]] .. "[[" .. FormToLua[i].Object_visible .. "]]")
end
for line in string.gfind (TempText,"[^\n]+") do
if (line~= '' and #line > 1) then
print(line);
end
end
end
function Start()
CEToLua = createForm(false)
CEToLua.height = 25
CEToLua.width = 240
CEToLua.caption = "Convert CE Trainers to LUA scripts"
CEToLuaButton = createButton(CEToLua)
CEToLuaButton.caption = "Generate"
CEToLuaButton.height = 20
CEToLuaButton.width = 60
CEToLuaButton.top = 2
CEToLuaButton.left = 178
CEToLuaEdit = createEdit(CEToLua)
CEToLuaEdit.width = 174
CEToLuaEdit.left = 2
CEToLuaEdit.top = 2
CEToLuaEdit.Caption = ""
CEToLuaButton.onClick = function ()
a = CEToLuaEdit.Text
loadstring([[test = (]] .. a .. [[ or nil) -- Defines test as a form]])()
a = nil
if (type(test)~="userdata") then
test = nil
CEToLuaEdit.Caption = ""
showMessage("Sorry but this is not a valid form!")
return
end
GenerateLuaScript(test)
test = nil
CEToLua.hide()
end
CEToLua.centerScreen()
end
Start()
function CETrainerToLua()
if CEToLua.getVisible() then
CEToLua.hide()
else
CEToLua.show()
end
end
CEMenu = menu_getItems(form_getMenu(getMainForm()))
CETrainerToLuaScript = createMenuItem(CEMenu)
menuItem_add(CEMenu, CETrainerToLuaScript)
menuItem_setCaption(CETrainerToLuaScript, "C.E Trainer to LUA")
menuItem_onClick(CETrainerToLuaScript, CETrainerToLua) |
Hope you'll love this and create something more advanced .
DaSpamer,
_________________
I'm rusty and getting older, help me re-learn lua.
Last edited by daspamer on Wed Jun 25, 2014 12:51 pm; edited 2 times in total |
|
Back to top |
|
 |
daspamer Grandmaster Cheater Supreme
Reputation: 54
Joined: 13 Sep 2011 Posts: 1588
|
Posted: Fri Jul 26, 2013 4:52 pm Post subject: |
|
|
After executing it,
It'll print the script so you can copy-paste it in C.E or new cheat engine window and execute.
_________________
I'm rusty and getting older, help me re-learn lua. |
|
Back to top |
|
 |
abhijeet1001 Advanced Cheater
Reputation: 0
Joined: 10 Apr 2013 Posts: 87
|
Posted: Sun Jul 28, 2013 11:36 am Post subject: |
|
|
hey daspammer after making a form i run ur script it make a new tab in my CE window CE trainer to Lua when i click on it a box appears with a generate button when i click on it it pops a error
Error:[string "function TranslateToFunction(Str)..."]:125: attempt to call a nil value
any idea why
|
|
Back to top |
|
 |
daspamer Grandmaster Cheater Supreme
Reputation: 54
Joined: 13 Sep 2011 Posts: 1588
|
Posted: Mon Jul 29, 2013 11:10 am Post subject: |
|
|
You need to enter your form name.. like UDF1 nothing more/else.
_________________
I'm rusty and getting older, help me re-learn lua. |
|
Back to top |
|
 |
abhijeet1001 Advanced Cheater
Reputation: 0
Joined: 10 Apr 2013 Posts: 87
|
Posted: Wed Jul 31, 2013 9:58 am Post subject: |
|
|
THNX MAN ITS AWESOME
|
|
Back to top |
|
 |
daspamer Grandmaster Cheater Supreme
Reputation: 54
Joined: 13 Sep 2011 Posts: 1588
|
Posted: Wed Jul 31, 2013 12:06 pm Post subject: |
|
|
No problem mate.
_________________
I'm rusty and getting older, help me re-learn lua. |
|
Back to top |
|
 |
abhijeet1001 Advanced Cheater
Reputation: 0
Joined: 10 Apr 2013 Posts: 87
|
Posted: Sat Aug 03, 2013 10:57 pm Post subject: |
|
|
hey mate just 1 problem i am facing now is how to define button functions ?
earlier i used to make trainers in trainer gene. then this was the command i used to use
Code: | function CEButton (sender)
end |
but that dont seem to work for this !! i get error after executing any help ?
Thanks
|
|
Back to top |
|
 |
daspamer Grandmaster Cheater Supreme
Reputation: 54
Joined: 13 Sep 2011 Posts: 1588
|
Posted: Sun Aug 04, 2013 6:47 am Post subject: |
|
|
Code: |
function BClicked(sender)
sender.Caption = string.char(math.random(65,90))..string.char(math.random(65,90))..string.char(math.random(65,90))..string.char(math.random(65,90))
end
f = createForm()
b = createButton(f)
b.onClick =BClicked --(Or control_onClick(b,BClicked ))
|
_________________
I'm rusty and getting older, help me re-learn lua. |
|
Back to top |
|
 |
sir-gunny Advanced Cheater
Reputation: 0
Joined: 15 Mar 2012 Posts: 81
|
Posted: Mon Jun 23, 2014 4:11 pm Post subject: |
|
|
Hi DaSpamer.
Can you update your script to CE6.4 please? I need PageControl and TabSheets...
Grrz, Gunny
|
|
Back to top |
|
 |
Redouane Master Cheater
Reputation: 3
Joined: 05 Sep 2013 Posts: 363 Location: Algeria
|
Posted: Mon Jun 23, 2014 5:38 pm Post subject: |
|
|
Hey DaSpammer,I really like your intentions to make CE helper extensions,but some parts of your script could be improved/made more beautiful:
This part:
Code: | function TranslateToFunction(Str)
if Str=="TCEButton" then return "createButton"
elseif Str=="TCELabel" then return "createLabel"
elseif Str=="TCEPanel" then return "createPanel"
elseif Str=="TCEImage" then return "createImage"
elseif Str=="TCEMemo" then return "createMemo"
elseif Str=="TCEEdit" then return "createEdit"
elseif Str=="TCEToggleBox" then return "createToggleBox"
elseif Str=="TCECheckBox" then return "createCheckBox"
elseif Str=="TCEGroupBox" then return "createGroupBox"
elseif Str=="TCERadioGroup" then return "createRadioGroup"
elseif Str=="TCEListBox" then return "createListBox"
elseif Str=="TCEComboBox" then return "createComboBox"
elseif Str=="TCEProgressBar" then return "createProgressBar"
elseif Str=="TCETrackBar" then return "createTrackBar"
elseif Str=="TCEListView" then return "createListView"
elseif Str=="TPaintBox" then return "createPaintBox"
elseif Str=="TCESplitter" then return "createSplitter"
elseif Str=="TCETimer" then return "createTimer"
elseif Str=="TCEOpenDialog" then return "createOpenDialog"
elseif Str=="TCESaveDialog" then return "createSaveDialog"
end
end |
I could make it this way:
It does the same job,without doing so many compares on each call
Code: | function TranslateToFunction(Str)
return string.format( 'create%s' , string.gsub( Str , '^TC?E?' , '' ) )
--[[You could make it even better using string.find and string.sub instead of gsub ]]--
end |
Or even this way:
Code: | local data = {
TCEButton = 'createButton' ,
TCELabel = 'createLabel' ,
TCEPanel = 'createPanel' ,
TCEImage = 'createImage' ,
TCEMemo = 'createMemo' ,
TCEEdit = 'createEdit' ,
TCEToggleBox = 'createToggleBox' ,
TCECheckBox = 'createCheckBox' ,
TCEGroupBox = 'createGroupBox' ,
TCERadioGroup = 'createRadioGroup' ,
TCEListBox = 'createListBox' ,
TCEComboBox = 'createComboBox' ,
TCEProgressBar = 'createProgressBar' ,
TCETrackBar = 'createTrackBar' ,
TCEListView = 'createListView' ,
TPaintBox = 'createPaintBox' ,
TCESplitter = 'createSplitter' ,
TCETimer = 'createTimer' ,
TCEOpenDialog = 'createOpenDialog' ,
TCESaveDialog = 'createSaveDialog'
}
function TranslateToFunction(Str)
return data[ Str ]
end |
You can read more here (Lua switch statement)
|
|
Back to top |
|
 |
daspamer Grandmaster Cheater Supreme
Reputation: 54
Joined: 13 Sep 2011 Posts: 1588
|
Posted: Mon Jun 23, 2014 8:16 pm Post subject: |
|
|
Redone wrote: | Hey DaSpammer,I really like your intentions to make CE helper extensions,but some parts of your script could be improved/made more beautiful:
This part:
Code: | function TranslateToFunction(Str)
if Str=="TCEButton" then return "createButton"
elseif Str=="TCELabel" then return "createLabel"
elseif Str=="TCEPanel" then return "createPanel"
elseif Str=="TCEImage" then return "createImage"
elseif Str=="TCEMemo" then return "createMemo"
elseif Str=="TCEEdit" then return "createEdit"
elseif Str=="TCEToggleBox" then return "createToggleBox"
elseif Str=="TCECheckBox" then return "createCheckBox"
elseif Str=="TCEGroupBox" then return "createGroupBox"
elseif Str=="TCERadioGroup" then return "createRadioGroup"
elseif Str=="TCEListBox" then return "createListBox"
elseif Str=="TCEComboBox" then return "createComboBox"
elseif Str=="TCEProgressBar" then return "createProgressBar"
elseif Str=="TCETrackBar" then return "createTrackBar"
elseif Str=="TCEListView" then return "createListView"
elseif Str=="TPaintBox" then return "createPaintBox"
elseif Str=="TCESplitter" then return "createSplitter"
elseif Str=="TCETimer" then return "createTimer"
elseif Str=="TCEOpenDialog" then return "createOpenDialog"
elseif Str=="TCESaveDialog" then return "createSaveDialog"
end
end |
I could make it this way:
It does the same job,without doing so many compares on each call
Code: | function TranslateToFunction(Str)
return string.format( 'create%s' , string.gsub( Str , '^TC?E?' , '' ) )
--[[You could make it even better using string.find and string.sub instead of gsub ]]--
end |
Or even this way:
Code: | local data = {
TCEButton = 'createButton' ,
TCELabel = 'createLabel' ,
TCEPanel = 'createPanel' ,
TCEImage = 'createImage' ,
TCEMemo = 'createMemo' ,
TCEEdit = 'createEdit' ,
TCEToggleBox = 'createToggleBox' ,
TCECheckBox = 'createCheckBox' ,
TCEGroupBox = 'createGroupBox' ,
TCERadioGroup = 'createRadioGroup' ,
TCEListBox = 'createListBox' ,
TCEComboBox = 'createComboBox' ,
TCEProgressBar = 'createProgressBar' ,
TCETrackBar = 'createTrackBar' ,
TCEListView = 'createListView' ,
TPaintBox = 'createPaintBox' ,
TCESplitter = 'createSplitter' ,
TCETimer = 'createTimer' ,
TCEOpenDialog = 'createOpenDialog' ,
TCESaveDialog = 'createSaveDialog'
}
function TranslateToFunction(Str)
return data[ Str ]
end |
You can read more here (Lua switch statement) |
Don't worry, I know it, wrote this script about a year ago.
_________________
I'm rusty and getting older, help me re-learn lua. |
|
Back to top |
|
 |
sir-gunny Advanced Cheater
Reputation: 0
Joined: 15 Mar 2012 Posts: 81
|
Posted: Wed Jun 25, 2014 5:54 am Post subject: |
|
|
sir-gunny wrote: | Hi DaSpamer.
Can you update your script to CE6.4 please? I need PageControl and TabSheets...
Grrz, Gunny |
Can you fix it please?
Greez, Gunny
|
|
Back to top |
|
 |
daspamer Grandmaster Cheater Supreme
Reputation: 54
Joined: 13 Sep 2011 Posts: 1588
|
Posted: Wed Jun 25, 2014 9:32 am Post subject: |
|
|
@sir-gunny, sorry didn't saw your post.
I've updated the script (Changed the Translate to function using string sub and find).
Page Control doesn't have some properties (align, caption and such).
So I went on easy route, checking if object has a specific property if not it sets false on the var, and adding the property if the var isn't false.
Pay attention, that there's no such function createPage, so if you have it, you'll need override it with specific function from main.lua ...
I'll update this in the future when I'll have more time.
_________________
I'm rusty and getting older, help me re-learn lua. |
|
Back to top |
|
 |
sir-gunny Advanced Cheater
Reputation: 0
Joined: 15 Mar 2012 Posts: 81
|
Posted: Wed Jun 25, 2014 11:54 am Post subject: |
|
|
Hi DaSpamer.
Thanks for update your script. The function PageControl is createPageControl() and createabSheet is addTab().
Quote: | Pagecontrol Class (WinControl->Control->Component->Object)
This is an object that can hold multiple pages
global functions
createPageControl(owner)
properties
ShowTabs: boolean - Shows the tabs
TabIndex: integer - Gets and sets the current tab
ActivePage: TabSheet - Returns the current tabsheet.
PageCount: integer - Gets the number of pages
Page[]: TabSheet - Get a specific page (TabSheet)
methods
addTab() : TabSheet - Creates a new TabSheet
TabSheet class (WinControl->Control->Component->Object)
Part of a page control. This object can contain other objects
properties
TabIndex: integer - the current index in the pagelist of the owning pagecontrol
methods |
Can you fix it again please? My lua is not good enough to fix it by myself
A small example:
Code: | test = (UDF1 or nil) -- Defines test as a form
--Creates first the form
UDF1 = createForm(nil)
UDF1.caption = [[UDF1]]
UDF1.left = 302
UDF1.top = 99
UDF1.width = 320
UDF1.height = 240
UDF1.align = alNone
UDF1.enabled = nil
UDF1.visible = nil
-- Creating the objects
CEPageControl1 = createPage(UDF1) -- Generate with C.E. Tarainer to Lua
--CEPageControl1 = createPageControl(UDF1)
CEPageControl1.left = [[66]]
CEPageControl1.top = [[31]]
CEPageControl1.width = [[192]]
CEPageControl1.height = [[164]]
CEPageControl1.align = [[alNone]]
CEPageControl1.enabled = [[true]]
CEPageControl1.visible = [[true]]
TabSheet1 = createabSheet(CEPageControl1) -- Generate with C.E. Tarainer to Lua
--TabSheet1 = CEPageControl1.addTab()
TabSheet1.caption = [[TabSheet1]]
TabSheet1.left = [[0]]
TabSheet1.top = [[0]]
TabSheet1.width = [[184]]
TabSheet1.height = [[136]]
TabSheet1.enabled = [[true]]
TabSheet1.visible = [[nil]]
TabSheet2 = createabSheet(CEPageControl1) -- Generate with C.E. Tarainer to Lua
--TabSheet2 = CEPageControl1.addTab()
TabSheet2.caption = [[TabSheet2]]
TabSheet2.left = [[0]]
TabSheet2.top = [[0]]
TabSheet2.width = [[184]]
TabSheet2.height = [[136]]
TabSheet2.enabled = [[true]]
TabSheet2.visible = [[nil]]
CEButton1 = createButton(TabSheet1)
CEButton1.caption = [[CEButton1]]
CEButton1.left = [[36]]
CEButton1.top = [[45]]
CEButton1.width = [[75]]
CEButton1.height = [[25]]
CEButton1.align = [[alNone]]
CEButton1.enabled = [[true]]
CEButton1.visible = [[true]]
CEButton2 = createButton(TabSheet2)
CEButton2.caption = [[CEButton2]]
CEButton2.left = [[86]]
CEButton2.top = [[79]]
CEButton2.width = [[75]]
CEButton2.height = [[25]]
CEButton2.align = [[alNone]]
CEButton2.enabled = [[true]]
CEButton2.visible = [[true]] |
Big THX and greez,
gunny
|
|
Back to top |
|
 |
daspamer Grandmaster Cheater Supreme
Reputation: 54
Joined: 13 Sep 2011 Posts: 1588
|
Posted: Wed Jun 25, 2014 12:51 pm Post subject: |
|
|
Try it again, added a quick fix.
_________________
I'm rusty and getting older, help me re-learn lua. |
|
Back to top |
|
 |
|
|
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
|
|