Skip to content

Commit

Permalink
Refactored script
Browse files Browse the repository at this point in the history
- Fetch game offsets from an online repository
- Search for the cs2.exe process and client.dll module
- Use pymem for process and memory manipulation
- Add error handling for process and memory access issues
  • Loading branch information
Jesewe authored Jun 1, 2024
1 parent e9bce83 commit 5057f21
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 49 deletions.
73 changes: 56 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,34 +1,73 @@
# CS2 Bunny Hop Script
# CS2 Bhop Script

This Python script is designed to enable bunny hopping in the game CS2 by continuously jumping while the spacebar key is held down.
This is a Bunny Hop (Bhop) script for Counter-Strike 2 (CS2) that automates jumping while holding the space bar, providing a smoother and more consistent bunny hopping experience.

## Features

- Automatically jumps when the space bar is held down
- Simple and lightweight script
- Real-time process and memory manipulation using the `pymem` library
- Fetches the latest game offsets from an online repository

## Requirements

- Python 3.x
- `pymem` library
- `colorama` library
- `requests` library

## Installation
1. Install Python 3.x from the official website.
2. Install the required libraries using pip:
```bash
pip install pymem colorama
```

1. **Clone the repository:**

```bash
git clone https://github.com/Jesewe/cs2-bhop.git
cd cs2-bhop
```

2. **Install the required Python libraries:**

```bash
pip install pymem requests
```

## Usage
1. Run the script in a Python environment.
2. The script will search for the `cs2.exe` process and the `client.dll` module.
3. If the process and module are found, the script will continuously write to the memory to enable jumping.
4. Press the spacebar key to activate the bunny hop feature.
5. Press Enter to exit the script.

## Contributing
1. **Ensure that Counter-Strike 2 (cs2.exe) is running.**

2. **Run the script:**

```bash
python main.py
```

3. **Hold down the space bar to activate the bunny hop.**

## Script Explanation

The script works by:
- Searching for the `cs2.exe` process.
- Fetching the memory offsets required for jumping from an online repository.
- Writing to the memory address responsible for the jump action when the space bar is pressed.

### Code Overview

- `fetch_offsets()`: Fetches the latest game offsets from an online repository.
- `get_cs2_process()`: Retrieves the `cs2.exe` process.
- `get_client_module(pm)`: Gets the `client.dll` module from the process.
- `bhop()`: Main function that handles the bunny hopping logic.
### Error Handling
The script includes error handling for various exceptions, including process not found, module not found, memory read/write errors, and more.
## Logging
We welcome contributions from the community!
The script uses the `logging` module to log important information and errors, making it easier to debug and monitor the script's execution.
## License
CS2 Bhop Script is released under the [MIT License](LICENSE).
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
## Disclaimer
The CS2 Bhop script script is provided for educational and informational purposes only. The author do not endorse or promote cheating in any form, and this script should not be used to gain an unfair advantage in CS2 or any other game. The usage of this script may violate the terms of service of CS2, leading to penalties or a ban. Use it responsibly and at your own risk.
This script is for educational purposes only. Use it at your own risk. The author is not responsible for any consequences resulting from the use of this script, including but not limited to game bans or other punitive actions by game administrators.
92 changes: 60 additions & 32 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,44 +1,72 @@
import pymem, pymem.process, time, ctypes
from colorama import Fore, init
import pymem, pymem.process
import time
import ctypes
import logging
from requests import get

init(autoreset=True)
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
logger = logging.getLogger(__name__)

ctypes.windll.kernel32.SetConsoleTitleW("CS2 Bhop Script | ItsJesewe")

def bhop():
SPACE_KEY = 0x20
FORCE_JUMP_ON = 65537
FORCE_JUMP_OFF = 256
SLEEP_INTERVAL = 0.01

def fetch_offsets():
try:
buttons = get("https://raw.githubusercontent.com/a2x/cs2-dumper/main/output/buttons.json").json()
return buttons
except Exception as e:
logger.error(f"Failed to fetch offsets: {e}")
return None

def get_cs2_process():
try:
print(Fore.YELLOW + "[*] Searching for cs2.exe process...\n")
pm = pymem.Pymem("cs2.exe")
client_module = pymem.process.module_from_name(pm.process_handle, "client.dll").lpBaseOfDll
dwForceJump = 0x1730530 # Offset are being updated: https://github.com/a2x/cs2-dumper/blob/main/generated/offsets.py
force_jump_address = client_module + dwForceJump
jump = False
return pymem.Pymem("cs2.exe")
except pymem.exception.ProcessNotFound:
print(Fore.RED + '[*] cs2.exe process is not running!')
logger.error('cs2.exe process is not running!')
except pymem.exception.ProcessError:
print(Fore.RED + '[*] Error accessing process cs2.exe')
logger.error('Error accessing process cs2.exe')
return None

def get_client_module(pm):
try:
return pymem.process.module_from_name(pm.process_handle, "client.dll").lpBaseOfDll
except pymem.exception.ModuleNotFound:
print(Fore.RED + '[*] module not found')
except pymem.exception.MemoryReadError:
print(Fore.RED + '[*] Error reading memory')
except pymem.exception.MemoryWriteError:
print(Fore.RED + '[*] Error writing memory')
except AttributeError:
print(Fore.RED + '[*] Byte pattern not found')
else:
print(Fore.GREEN + "[*] cs2.exe is running.\n\n[*] Client loaded...")
logger.error('client.dll module not found')
return None

def bhop():
logger.info("Searching for cs2.exe process...")
pm = get_cs2_process()
if not pm:
return

client_module = get_client_module(pm)
if not client_module:
return

buttons = fetch_offsets()
if not buttons:
return

global ForceJump
ForceJump = buttons["client.dll"]["jump"]
force_jump_address = client_module + ForceJump

jump = False
try:
while True:
if ctypes.windll.user32.GetAsyncKeyState(0x20):
if not jump:
time.sleep(0.01)
pm.write_int(force_jump_address, 65537)
jump = True
elif jump:
time.sleep(0.01)
pm.write_int(force_jump_address, 256)
jump = False
finally:
input('\n[*] Press Enter to exit...')
if ctypes.windll.user32.GetAsyncKeyState(SPACE_KEY):
time.sleep(SLEEP_INTERVAL)
pm.write_int(force_jump_address, FORCE_JUMP_ON if not jump else FORCE_JUMP_OFF)
jump = not jump
except pymem.exception.MemoryWriteError:
logger.error('Error writing memory')
except KeyboardInterrupt:
logger.warning('Script interrupted by user')

if __name__ == "__main__":
bhop()

0 comments on commit 5057f21

Please sign in to comment.