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 


Cheat Engine Forum Index
PostGo back to topic
daspamer
Grandmaster Cheater Supreme
Reputation: 54
Joined: 13 Sep 2011
Posts: 1588

PostPosted: 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 Very Happy

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 Wink.
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
View user's profile Send private message Visit poster's website
Post reviews:   Approve 1
Author Review
Gi@nnis
Review: Approve
Post reference:
ReviewPosted: Fri Aug 22, 2014 4:01 pm

Greate job!Smile
Back to top
View user's profile Send private message
Display:  
Cheat Engine Forum Index


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites