-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtool_PM_BUTTON_FIXER.pygame
77 lines (65 loc) · 2.61 KB
/
tool_PM_BUTTON_FIXER.pygame
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import os
import sys
import pygame
scriptVersion = "1.1.1"
scriptName = "PM_BUTTON_FIXER"
pygame.init()
font = pygame.font.Font(None, 36)
message_font = pygame.font.Font(None, 36)
screen = pygame.display.set_mode((640, 480))
def show_message(message):
screen.fill((0, 0, 0))
text_surface = message_font.render(message, True, (255, 255, 255))
text_rect = text_surface.get_rect(center=(screen.get_width() // 2, screen.get_height() // 2))
screen.blit(text_surface, text_rect.topleft)
pygame.display.flip()
pygame.time.wait(2000)
def save_overlay():
show_message("Saving overlay...")
try:
result = os.system("sh /usr/bin/batocera-save-overlay")
if result == 0:
show_message("Overlay saved successfully!")
else:
show_message("Error: Overlay not saved!")
except Exception as e:
show_message(f"Error: {str(e)}")
def find_controller_file():
base_path = "/usr/lib"
python_versions = sorted([d for d in os.listdir(base_path) if d.startswith("python3.")], reverse=True)
for version in python_versions:
file_path = os.path.join(base_path, version, "site-packages/configgen/controller.py")
if os.path.exists(file_path):
return file_path
return None
def fix_buttons():
show_message("Checking...")
file_path = find_controller_file()
if not file_path:
show_message("Controller file not found! Exiting...")
pygame.quit()
exit()
old_code = """\"\"\"Default mapping of Batocera keys to SDL_GAMECONTROLLERCONFIG keys.\"\"\"\n_DEFAULT_SDL_MAPPING: Final = {\n 'b': 'a',\n 'a': 'b',\n 'x': 'y',\n 'y': 'x',"""
new_code = """\"\"\"Default mapping of Batocera keys to SDL_GAMECONTROLLERCONFIG keys.\"\"\"\n_DEFAULT_SDL_MAPPING: Final = {\n 'b': 'b',\n 'a': 'a',\n 'x': 'x',\n 'y': 'y',"""
try:
with open(file_path, "r") as file:
content = file.read()
if old_code in content:
show_message("Applying patch...")
updated_content = content.replace(old_code, new_code)
with open(file_path, "w") as file:
file.write(updated_content)
show_message("Patch applied successfully!")
save_overlay()
else:
show_message("Nothing to patch, Exiting...")
pygame.quit()
except Exception as e:
show_message(f"Error: {str(e)}")
pygame.quit()
def main():
fix_buttons()
pygame.quit()
if __name__ == "__main__":
show_message(f"Starting {scriptName} v{scriptVersion} by Ali BEYAZ...")
main()