This project injects code into the original minesweeper in order to provide an API to interact with the game.
You can also change the smiley button to anything by adding 24x24 px *.png files to the same folder as the program named:
ButtonChecking.png
ButtonDown.png
ButtonIdle.png
ButtonLost.png
ButtonWon.png
Examples can be seen in the icons
folder.
Other than being an API to control the game from external tools, this also provides the quality of life feature of you being able to double click on a field and then it will clear all adjacent fields not being marked by af flag. If the number of flags is less than the number of adjacent bombs then nothing will happen.
First download winmine.exe
for Windows 2000/NT 4.0. It can be found on archive.org. Other version of winmine.exe
is not tested and is likely not to work since function call addresses possibly will be changed. For the install target of cmake to work move winmine.exe
to external/
in the repository.
To be able to build this, visual studio is needed as well as CMake. Other compilers than MSVC might work but is not tested.
To build it run from the repository root:
$ mkdir build
$ cd build
$ cmake ..
$ cmake --build .
Move external/winmine.exe
to the bin
folder or run the install target.
Please note that the install target is incomplete right now and does only install the winmine.exe file and no of the API and injection files.
For the API to be run, instead of running winmine.exe
, minesweeperRunetime.exe
should be run.
To check if the API is running you can press F10
to show the API terminal. F9
will hide it again.
To use the API all the functions needed is included in minesweeperAPIx64.dll
or minesweeperAPIx86.dll
dependent on the target architecture.
If run from a x64
architecture, the program must be started manually. The startMinesweeper()
function is only available to the x86
architecture for now.
To include the functions include the file minesweeperAPI/minesweeperAPI.hpp
. When building the *.dll
files library files should be created as well to link up against.
int connect();
Since the game is running in another process, it is necessary to connect to the game over RPC in order to interact with it. Therefore this command should be called when the game is running with the API loaded.
int disconnect();
When done using the API disconnect the RPC connection with this function.
int ResetField();
Resets the field to a new game with all tiles hidden.
void GetField(unsigned char* fieldBuffer);
Puts the field in it's current state into fieldBuffer
. fieldBuffer
must be at least 720 long.
To read the field is a bit complicated. Here is an example:
char fieldBuffer[720]; // Data array must be 720 long.
GetField(fieldBuffer)
auto height = GetFieldHeight();
auto width = GetFieldWidth();
for(char x = 0; x < width; ++x){
for(char y = 0; y < height; ++y){
auto tile = fieldBuffer[y * 30 + x]
// Do something with tile
}
}
Each tile in the field can have the ascii values "F
", "?
", "
", #
or a number between 1-8. Where "F
" means that there is a flag on the tile, "?
" means that there is a question mark on the tile. "
" means that the tile is unveiled but no bombs is around it. "#
" means that the tile is not yet unveiled. And a number means that the tile has a that number bombs adjacent to it.
Right now it is not possible to get the field where the bombs are shown.
unsigned char GetFieldHeight();
Returns the number of tiles there are vertically.
unsigned char GetFieldWidth();
Returns the number of tiles there are horizontally.
void ClickOnTile(unsigned char x, unsigned char y);
If the tile specified with the coordinate (x,y)
is within the board with and height then the tile will be reviled just like when clicking on it.
game_status_t GetGameStatus();
GetGameStatus()
returns a given value of the game_status_t
enum, shown bellow, dependent on what status the game is in.
typedef enum game_status {
GAME_RUNNING = 0,
GAME_WON = 1,
GAME_LOST = 2
} game_status_t;
void startMinesweeper();
Starts an instance of Minesweeper with the API injected.
bool isMinesweeperRunning();
Checks if Minesweeper is running with the API injected.
void dealocateMinesweeper();
Deallocates the Minesweeper process.