Registration Code (Part 1): w%kQ6
Registration Code (Part 2): b<#$1[*(cw~
In order to register on this forum, you must use the codes above. Combine them into one code (copy paste).

Cheat Engine 6.x Minesweeper Auto-Solver

Programming topics that relate to the Lua scripting language.
Post Reply
User avatar
atom0s
Site Admin
Posts: 401
Joined: Sun Jan 04, 2015 11:23 pm
Location: 127.0.0.1
Contact:

Cheat Engine 6.x Minesweeper Auto-Solver

Post by atom0s » Fri Jan 09, 2015 10:09 am

  1. --[[
  2.  
  3.     Minesweeper Solver via Lua Example
  4.     by atom0s
  5.  
  6. ]]--
  7.  
  8. -- ## DO NOT EDIT BELOW THIS LINE!! ##
  9.  
  10. local Minesweeper_Example = { }
  11.  
  12. ----------------------------------------------------------------------------------
  13. -- func: Minesweeper_Example.CallStepSquare( .. )
  14. -- desc: Calls our StepSquare cave to internally call left-click function.
  15. ----------------------------------------------------------------------------------
  16. function Minesweeper_Example.CallStepSquare( x, y )
  17.     -- Write current X and Y to memory.
  18.     autoAssemble(
  19.         "alloc(tempFunc, 1024)\n" ..
  20.         "CreateThread(tempFunc)\n" ..
  21.         "tempFunc:\n" ..
  22.         "mov [currXPos], " .. tostring( x ) .. "\n" ..
  23.         "mov [currYPos], " .. tostring( y ) .. "\n" ..
  24.         "ret\n"
  25.         );
  26.        
  27.     -- Create thread calling our StepSquare function.
  28.     autoAssemble( "CreateThread(StepSquareCave)\n" );
  29.  
  30.     -- Cleanup temp function.
  31.     autoAssemble( "dealloc(tempFunc)\n" );
  32. end
  33.  
  34. ----------------------------------------------------------------------------------
  35. -- func: Minesweeper_Example.CallMakeGuess( .. )
  36. -- desc: Calls our MakeGuess cave to internally call right-click function.
  37. ----------------------------------------------------------------------------------
  38. function Minesweeper_Example.CallMakeGuess( x, y )
  39.     -- Write current X and Y to memory.
  40.     autoAssemble(
  41.         "alloc(tempFunc, 1024)\n" ..
  42.         "CreateThread(tempFunc)\n" ..
  43.         "tempFunc:\n" ..
  44.         "mov [currXPos], " .. tostring( x ) .. "\n" ..
  45.         "mov [currYPos], " .. tostring( y ) .. "\n" ..
  46.         "ret\n"
  47.         );
  48.    
  49.     -- Create thread calling our MakeGuess function.
  50.     autoAssemble( "CreateThread(MakeGuessCave)\n" );
  51.  
  52.     -- Cleanup temp function.
  53.     autoAssemble( "dealloc(tempFunc)\n" );
  54. end
  55.  
  56. ----------------------------------------------------------------------------------
  57. -- func: Minesweeper_Example.Main( .. )
  58. -- desc: Main script function that handles everything of the script.
  59. ----------------------------------------------------------------------------------
  60. function Minesweeper_Example.Main ( )
  61.  
  62.     -- Obtain current board sizes.
  63.     Minesweeper_Example.BoardWidth  = readInteger( "10056AC" );
  64.     Minesweeper_Example.BoardHeight = readInteger( "10056A8" );
  65.  
  66.     -- Board layout starting position.
  67.     Minesweeper_Example.BoardStart = 16798528;
  68.    
  69.     -- Allocate memory locations for x and y positions.
  70.     autoAssemble(
  71.         "globalalloc(currXPos, 4)\n" ..
  72.         "globalalloc(currYPos, 4)\n"
  73.         );
  74.    
  75.     -- Allocate cave for StepSquare function.
  76.     autoAssemble(
  77.         "globalalloc(StepSquareCave, 1024)\n" ..
  78.         "StepSquareCave:\n" ..
  79.         "push [currYPos]\n" ..
  80.         "push [currXPos]\n" ..
  81.         "mov eax, 01003512\n" ..
  82.         "call eax\n" ..
  83.         "ret\n"
  84.         );
  85.        
  86.     -- Allocate cave for MakeGuess function.
  87.     autoAssemble(
  88.         "globalalloc(MakeGuessCave, 1024)\n" ..
  89.         "MakeGuessCave:\n" ..
  90.         "push [currYPos]\n" ..
  91.         "push [currXPos]\n" ..
  92.         "mov eax, 0100374F\n" ..
  93.         "call eax\n" ..
  94.         "ret\n"
  95.         );
  96.    
  97.     -- Attempt to solve the board.
  98.     local boardX = 1;
  99.     local boardY = 1;
  100.    
  101.     for boardX = 1, Minesweeper_Example.BoardWidth do
  102.         for boardY = 1, Minesweeper_Example.BoardHeight do
  103.             local bCurrentPos = Minesweeper_Example.BoardStart + ( boardX + ( boardY * 32 ) );
  104.             local bValue = readBytes( bCurrentPos, 1 );
  105.             if( bValue ~= 0x8F ) and ( bValue == 0x0F ) then
  106.                 Minesweeper_Example.CallStepSquare( boardX, boardY );
  107.             else
  108.                 Minesweeper_Example.CallMakeGuess( boardX, boardY );
  109.             end
  110.         end
  111.     end
  112.    
  113.     -- Cleanup allocations.
  114.     autoAssemble(
  115.         "dealloc(currXPos)\n" ..
  116.         "dealloc(currYPos)\n" ..
  117.         "dealloc(MakeGuessCave)\n" ..
  118.         "dealloc(StepSquareCave)\n"
  119.         );
  120.    
  121.     return true;
  122. end
  123.  
  124. -- Execute our script.
  125. Minesweeper_Example.Main();
Derp~
Need a great web host? Check out: AnHonestHost.com


Donations can be made via Paypal:
https://www.paypal.me/atom0s
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest