Page 1 of 1

Cheat Engine 6.x Trainer Example

Posted: Fri Jan 09, 2015 10:09 am
by atom0s
  1. --[[
  2.  
  3.     Winmine.exe (Windows XP Minesweeper) Lua Trainer Example
  4.     by atom0s [Wiccaan]
  5.      
  6.     This is a demonstrational Lua script showing off
  7.     what Cheat Engine 6.0 can do with Lua.
  8.      
  9. ]]--
  10.  
  11. --
  12. -- DO NOT EDIT BELOW THIS LINE!!
  13. --
  14.  
  15. local Trainer_Example = { }
  16.  
  17. ----------------------------------------------------------------------------------
  18. -- func: InitButton( .. )
  19. -- desc: Wraps button creation and setup functions for smaller code.
  20. ----------------------------------------------------------------------------------
  21. function InitButton( form, caption, x, y, w, h, func )
  22.     local button = createButton( form );
  23.     if( button == nil ) then
  24.         return nil;
  25.     end
  26.  
  27.     control_setCaption( button, caption );
  28.     control_setPosition( button, x, y );
  29.     control_setSize( button, w, h );
  30.     control_onClick( button, func );
  31.     return button;
  32. end
  33.  
  34. ----------------------------------------------------------------------------------
  35. -- func: InitLabel( .. )
  36. -- desc: Wraps label creation and setup functions for smaller code.
  37. ----------------------------------------------------------------------------------
  38. function InitLabel( form, x, y, text )
  39.     local label = createLabel( form );
  40.     if( label == nil ) then
  41.         return nil;
  42.     end
  43.      
  44.     control_setCaption( label, text );
  45.     control_setPosition( label, x, y );
  46.     return label;
  47. end
  48.  
  49. ----------------------------------------------------------------------------------
  50. -- func: Trainer_Example.Main( .. )
  51. -- desc: Prepares script for overall actions.
  52. ----------------------------------------------------------------------------------
  53. function Trainer_Example.Main( )
  54.     -- Main trainer form pointer.
  55.     Trainer_Example.Form = createForm( true );
  56.  
  57.     -- Create buttons.
  58.     Trainer_Example.btnFlags = InitButton( Trainer_Example.Form, "Toggle  Inf. Flags", 1, 1, 150, 30, Trainer_Example.OnFlagsClicked );
  59.     Trainer_Example.btnTimer = InitButton( Trainer_Example.Form, "Toggle  Unlimited Time", 155, 1, 150, 30, Trainer_Example.OnTimeClicked );
  60.  
  61.     -- Create info label.
  62.     Trainer_Example.lblInfo = InitLabel( Trainer_Example.Form, 5, 175,  
  63.         "This is an example Lua trainer written using Cheat Engine 6.\n" ..
  64.         "Coded by: atom0s [Wiccaan]"
  65.         );
  66.      
  67.     -- Create option booleans.
  68.     Trainer_Example.bFlagsEnabled = false;
  69.     Trainer_Example.bTimerEnabled = false;
  70.      
  71.     -- Set form caption.
  72.     control_setCaption( Trainer_Example.Form, "Minesweeper Lua Trainer Example" );
  73.     return true;
  74. end
  75.  
  76. ----------------------------------------------------------------------------------
  77. -- func: Trainer_Example.OnFlagsClicked( .. )
  78. -- desc: Toggles infinite flags when flag button is clicked.
  79. ----------------------------------------------------------------------------------
  80. function Trainer_Example.OnFlagsClicked()
  81.     Trainer_Example.bFlagsEnabled = not Trainer_Example.bFlagsEnabled;
  82.      
  83.     if( Trainer_Example.bFlagsEnabled == true ) then
  84.         autoAssemble( "winmine.exe+346E:\n" ..  
  85.             "db 90 90 90 90 90 90"  
  86.             );
  87.     else
  88.         autoAssemble( "winmine.exe+346E:\n" ..
  89.             "db 01 05 94 51 00 01"  
  90.             );
  91.     end
  92. end
  93.  
  94. ----------------------------------------------------------------------------------
  95. -- func: Trainer_Example.OnTimeClicked( .. )
  96. -- desc: Toggles unlimited time when time button is clicked.
  97. ----------------------------------------------------------------------------------
  98. function Trainer_Example.OnTimeClicked()
  99.     Trainer_Example.bTimerEnabled = not Trainer_Example.bTimerEnabled;
  100.      
  101.     if( Trainer_Example.bTimerEnabled == true ) then
  102.         autoAssemble( "winmine.exe+2FF5:\n" ..  
  103.             "db 90 90 90 90 90 90"  
  104.             );
  105.     else
  106.         autoAssemble( "winmine.exe+2FF5:\n" ..
  107.             "db FF 05 9C 57 00 01"  
  108.             );
  109.     end
  110. end
  111.  
  112. -- Execute our script.
  113. Trainer_Example.Main();