-
Notifications
You must be signed in to change notification settings - Fork 5
/
offset.py
62 lines (51 loc) · 2.05 KB
/
offset.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import hashlib
from pathlib import Path
import random
from config import CONFIG
from util import try_input
def calculate_offset(profile_path: str | Path) -> int:
while True:
complete_prompt = "Press enter once you are done. "
sens_1 = random.randrange(10, 100, 5)
print(
f"\nPlease open your game, set your mouse sensitivity to {sens_1}, and exit to main menu."
)
input(complete_prompt)
with open(profile_path, "rb") as f:
profile_1 = bytearray(f.read()[20:])
indexes_1 = [i for i, val in enumerate(profile_1) if val == sens_1]
sens_2 = sens_1
while sens_2 == sens_1:
sens_2 = random.randrange(10, 100, 5)
print(
f"\nNow set your mouse sensitivity to {sens_2}, and exit to main menu again."
)
input(complete_prompt)
with open(profile_path, "rb") as f:
profile_2 = bytearray(f.read()[20:])
indexes_2 = [i for i, val in enumerate(profile_2) if val == sens_2]
intersection = set(indexes_1).intersection(indexes_2)
if len(intersection) == 1:
offset = intersection.pop()
CONFIG.set_data("offset", offset)
print("\nCalculated successfully!")
return offset
print("\nUnable to calculate offset! Restarting.")
def get_current_sens(profile_path: str | Path, offset: int) -> int:
with open(profile_path, "rb") as f:
profile = bytearray(f.read()[20:])
return profile[offset]
def rewrite_sens(profile_path: str | Path, offset) -> int:
sens = try_input(int, prompt="\nEnter your new desired sensitivity (1-255): ")
with open(profile_path, "rb") as f:
profile = bytearray(f.read()[20:])
profile[offset] = sens
hash = hashlib.sha1()
hash.update(profile)
profile[0:0] = bytearray(hash.digest())
with open(profile_path, "wb") as f:
f.write(profile)
print(
"\nDone! Restart the game, check the mouse settings, and enjoy your newly configured sensitivity."
)
return sens