Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
ASM = nasm
ASMFLAGS = -f win64
LINK = link
LINKFLAGS = /SUBSYSTEM:CONSOLE /ENTRY:main /LIBPATH:"C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.29.30133\lib\x64" msvcrt.lib kernel32.lib
SRC = src/main.asm
OBJ = src/main.obj
BIN = bin/mybot.exe

all: $(BIN)

$(BIN): $(OBJ) | bin
$(LINK) $(LINKFLAGS) /OUT:$@ $(OBJ)

src/main.obj: src/main.asm
$(ASM) $(ASMFLAGS) $< -o $@

bin:
mkdir -p bin

clean:
rm -rf bin/* src/*.obj

.PHONY: all clean
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
 ### What is it?
### What is it?
----------
- A Free Clash of Clans bot.
- A Free Clash of Clans bot rewritten in x86-64 Assembly for Windows.
- A bot is a general term in gaming that is used to refer to a character controlled by a computer.
- [MyBot.run](https://mybot.run)

#### Building the Assembly Version
----------
To build the assembly version:

1. Install NASM: `winget install nasm`
2. Install Microsoft Visual Studio for link.exe and libraries.
3. Run `make` in the project directory.

The assembly code is in `src/main.asm` and performs the same functionality as the C version.

#### The Latest Version
----------
- Details of the latest version can be found on the MyBot forum under [Official Releases](https://mybot.run/forums/index.php?/forum/4-official-releases/).
Expand Down
26 changes: 26 additions & 0 deletions README_C.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# MyBot C Scaffold

This folder contains a complete C rewrite of `MyBot`, a Clash of Clans automation bot originally written in AutoIt.

## Features
- Configuration loading from INI files
- Logging to file and console
- ADB integration for Android emulator control
- Placeholder image recognition (expand with OpenCV)
- Main automation loop with state detection and actions

## Build
```sh
make
```

## Run
```sh
./bin/mybot
```

## Notes
- This is a functional C port with core modules implemented.
- Image processing uses placeholders; integrate OpenCV for real recognition.
- Assumes ADB is installed and emulator is running.
- For full functionality, add OpenCV and expand logic for specific CoC mechanics.
Binary file added bin/mybot
Binary file not shown.
54 changes: 54 additions & 0 deletions src/adb.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#include "adb.h"
#include "logging.h"
#include <stdio.h>
#include <stdlib.h>

bool adb_init(void) {
log_message(LOG_LEVEL_INFO, "Initializing ADB connection...");
int result = system("adb devices > nul 2>&1");
if (result != 0) {
log_message(LOG_LEVEL_ERROR, "ADB not found or emulator not connected");
return false;
}
log_message(LOG_LEVEL_INFO, "ADB initialized successfully");
return true;
}

bool adb_tap(int x, int y) {
char command[256];
sprintf(command, "adb shell input tap %d %d", x, y);
int result = system(command);
if (result == 0) {
log_message(LOG_LEVEL_INFO, "Tapped at (%d, %d)", x, y);
return true;
} else {
log_message(LOG_LEVEL_ERROR, "Failed to tap at (%d, %d)", x, y);
return false;
}
}

bool adb_swipe(int x1, int y1, int x2, int y2) {
char command[256];
sprintf(command, "adb shell input swipe %d %d %d %d", x1, y1, x2, y2);
int result = system(command);
if (result == 0) {
log_message(LOG_LEVEL_INFO, "Swiped from (%d,%d) to (%d,%d)", x1, y1, x2, y2);
return true;
} else {
log_message(LOG_LEVEL_ERROR, "Failed to swipe");
return false;
}
}

bool adb_screenshot(const char *filename) {
char command[256];
sprintf(command, "adb exec-out screencap -p > %s", filename);
int result = system(command);
if (result == 0) {
log_message(LOG_LEVEL_INFO, "Screenshot saved to %s", filename);
return true;
} else {
log_message(LOG_LEVEL_ERROR, "Failed to capture screenshot");
return false;
}
}
11 changes: 11 additions & 0 deletions src/adb.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#ifndef ADB_H
#define ADB_H

#include <stdbool.h>

bool adb_init(void);
bool adb_tap(int x, int y);
bool adb_swipe(int x1, int y1, int x2, int y2);
bool adb_screenshot(const char *filename);

#endif // ADB_H
68 changes: 68 additions & 0 deletions src/bot.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#include "bot.h"
#include "config.h"
#include <stdio.h>
#include <unistd.h>
#include <time.h>

Config bot_config;

bool bot_init(void) {
log_message(LOG_LEVEL_INFO, "Initializing bot...");
if (!load_config("LastVersion.txt", &bot_config)) {
log_message(LOG_LEVEL_ERROR, "Failed to load config");
return false;
}
log_message(LOG_LEVEL_INFO, "Loaded version: %s", bot_config.version);
if (!adb_init()) {
return false;
}
if (!image_init()) {
return false;
}
log_message(LOG_LEVEL_INFO, "Bot initialized successfully");
return true;
}

void bot_run(void) {
log_message(LOG_LEVEL_INFO, "Starting bot run loop...");
printf("Message: %s\n", bot_config.messagenew);
time_t start_time = time(NULL);
int attacks_done = 0;
while (1) {
GameState state = detect_game_state();
switch (state) {
case GAME_STATE_HOME:
log_message(LOG_LEVEL_INFO, "On home screen, collecting resources");
if (find_and_tap_button("collect")) {
sleep(bot_config.collect_delay);
}
if (bot_config.enable_attacks && attacks_done < bot_config.max_attacks_per_hour) {
if (find_and_tap_button("attack")) {
attacks_done++;
sleep(10); // Simulate battle
}
}
break;
case GAME_STATE_BATTLE:
log_message(LOG_LEVEL_INFO, "In battle, deploying troops");
// Simulate actions
adb_tap(600, 800); // Deploy troop
sleep(5);
break;
default:
log_message(LOG_LEVEL_INFO, "Unknown state, waiting");
sleep(5);
break;
}
sleep(1); // Loop delay
// Check for shutdown condition, e.g., time limit
if (time(NULL) - start_time > 60) { // Run for 1 minute
break;
}
}
log_message(LOG_LEVEL_INFO, "Bot run loop ended");
}

void bot_shutdown(void) {
log_message(LOG_LEVEL_INFO, "Shutting down bot...");
}
16 changes: 16 additions & 0 deletions src/bot.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#ifndef BOT_H
#define BOT_H

#include <stdbool.h>
#include "config.h"
#include "logging.h"
#include "adb.h"
#include "image.h"

extern Config bot_config;

bool bot_init(void);
void bot_run(void);
void bot_shutdown(void);

#endif // BOT_H
Binary file added src/bot.o
Binary file not shown.
61 changes: 61 additions & 0 deletions src/config.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#include "config.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

bool load_config(const char *filename, Config *config) {
FILE *file = fopen(filename, "r");
if (!file) {
return false;
}

// Default values
config->enable_attacks = true;
config->max_attacks_per_hour = 10;
config->collect_delay = 300;

char line[512];
while (fgets(line, sizeof(line), file)) {
// Remove newline
line[strcspn(line, "\n")] = 0;

if (line[0] == '[') continue; // Skip sections

char *key = strtok(line, "=");
char *value = strtok(NULL, "=");
if (!key || !value) continue;

// Trim spaces
while (*key == ' ') key++;
char *end = key + strlen(key) - 1;
while (end > key && *end == ' ') *end-- = 0;

while (*value == ' ') value++;
end = value + strlen(value) - 1;
while (end > value && *end == ' ') *end-- = 0;

// Remove quotes if present
if (*value == '"') {
value++;
end = value + strlen(value) - 1;
if (*end == '"') *end = 0;
}

if (strcmp(key, "version") == 0) {
strncpy(config->version, value, sizeof(config->version) - 1);
} else if (strcmp(key, "messagenew") == 0) {
strncpy(config->messagenew, value, sizeof(config->messagenew) - 1);
} else if (strcmp(key, "messageold") == 0) {
strncpy(config->messageold, value, sizeof(config->messageold) - 1);
} else if (strcmp(key, "enable_attacks") == 0) {
config->enable_attacks = strcmp(value, "true") == 0;
} else if (strcmp(key, "max_attacks_per_hour") == 0) {
config->max_attacks_per_hour = atoi(value);
} else if (strcmp(key, "collect_delay") == 0) {
config->collect_delay = atoi(value);
}
}

fclose(file);
return true;
}
17 changes: 17 additions & 0 deletions src/config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#ifndef CONFIG_H
#define CONFIG_H

#include <stdbool.h>

typedef struct {
char version[32];
char messagenew[256];
char messageold[256];
bool enable_attacks;
int max_attacks_per_hour;
int collect_delay; // seconds
} Config;

bool load_config(const char *filename, Config *config);

#endif // CONFIG_H
36 changes: 36 additions & 0 deletions src/image.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include "image.h"
#include "adb.h"
#include "logging.h"
#include <stdlib.h>
#include <time.h>

bool image_init(void) {
log_message(LOG_LEVEL_INFO, "Initializing image processing...");
// Placeholder: In full implementation, load OpenCV and templates
srand(time(NULL));
log_message(LOG_LEVEL_INFO, "Image processing initialized");
return true;
}

GameState detect_game_state(void) {
// Placeholder: Capture screenshot and analyze
// For now, simulate random state
int r = rand() % 3;
GameState state = (GameState)r;
log_message(LOG_LEVEL_INFO, "Detected game state: %d", state);
return state;
}

bool find_and_tap_button(const char *button_name) {
// Placeholder: Use OpenCV to find button, then tap
// Simulate finding and tapping
if (rand() % 2 == 0) {
log_message(LOG_LEVEL_INFO, "Found and tapped button: %s", button_name);
// Simulate tap at random position
adb_tap(500 + rand() % 200, 500 + rand() % 200);
return true;
} else {
log_message(LOG_LEVEL_INFO, "Button %s not found", button_name);
return false;
}
}
16 changes: 16 additions & 0 deletions src/image.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#ifndef IMAGE_H
#define IMAGE_H

#include <stdbool.h>

typedef enum {
GAME_STATE_HOME,
GAME_STATE_BATTLE,
GAME_STATE_UNKNOWN
} GameState;

bool image_init(void);
GameState detect_game_state(void);
bool find_and_tap_button(const char *button_name);

#endif // IMAGE_H
Loading