forked from vakdev/VakScript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
autoconfig.py
173 lines (148 loc) · 6.1 KB
/
autoconfig.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#ext
import os
import win32api
import fileinput
from psutil import process_iter
from json import dump
#own
from data import Data
settings_json = {
'Spaceglider': {
'orbwalk' : 'space',
'laneclear' : 'v',
'lasthit' : 'c',
'attack' : 'a',
'range' : 'o',
'kiting_mode' : 'Normal',
'orbwalk_prio' : 'Less Basic Attacks',
'lasthit_mode' : 'Manual',
'press_range': False,
'ppc' : False
},
'Drawings' : {
"show_position": True,
"show_focused": True,
"show_healths": True,
"show_gold": False,
"show_spells": True,
"show_player_range": True,
"show_enemy_range": True,
"show_turret_range": True,
"show_hits": True,
"screen_track": False
},
'AutoSmite' : {
'smite' : 'f',
'update' : 'q',
'randb' : False
}
}
DEFAULT_CHAMPION_ONLY = '[Button 3]'
DEFAULT_PLAYER_ATTACK = '[a]'
DEFAULT_WALK_CLICK = '[Button 2]'
DEFAULT_RANGE = '[o]'
DEFAULT_ORBWALK = '[space]'
DEFAULT_LANECLEAR = '[v]'
DEFAULT_LASTHIT = '[c]'
options = {
'EnableTargetedAttackMove':'1',
'TargetChampionsOnlyAsToggle':'0',
'evtChampionOnly':DEFAULT_CHAMPION_ONLY,
'evtPlayerAttackMoveClick':DEFAULT_PLAYER_ATTACK,
'evtPlayerMoveClick':DEFAULT_WALK_CLICK,
'evtShowCharacterMenu':DEFAULT_RANGE
}
class Autoconfig:
def __init__(self, settings_to_persist, persisted_settings):
self.settings_to_persist = settings_to_persist
self.persisted_settings = persisted_settings
@staticmethod
def clear_name(string):
return string.strip().removeprefix('"name": "').removesuffix('",')
@staticmethod
def clear_value(string):
return string.strip(" \n").removeprefix('"value": "').removesuffix('"')
def remove_duplications(self):
#Prevent key bugs.
current_values = self.get_persisted_settings()
duplications = dict()
with open(self.persisted_settings) as persisted_settings:
for index, line in enumerate(persisted_settings, 1):
line = Autoconfig.clear_value(line)
if not line.isdecimal() and '.' not in line:
for k, v in current_values.items():
if line == v and index != k:
duplications[index] = line
if (line.startswith(v) or line.endswith(v)) and index != k:
if not line.startswith(('[Alt]', '[Ctrl]')):
duplications[index] = line
if line == DEFAULT_LASTHIT:
duplications[index] = line
if line == DEFAULT_LANECLEAR:
duplications[index] = line
if line == DEFAULT_ORBWALK:
duplications[index] = line
for line in fileinput.input(self.persisted_settings, inplace=True):
current_index = fileinput.lineno()
for k, v in duplications.items():
if current_index == k:
line = line.replace(v, '[<Unbound>],[<Unbound>]')
print(line, end="")
def get_persisted_settings(self):
current_settings = dict()
is_value = False
value_pos = None
with open(self.persisted_settings, "r+") as persisted_settings:
for index, line in enumerate(persisted_settings, 1):
line_name = Autoconfig.clear_name(line)
if line_name in options.keys():
value_pos = index + 1
is_value = True
continue
if is_value:
current_settings[value_pos] = Autoconfig.clear_value(line)
is_value = False
return current_settings
def set_persisted_settings(self):
current_settings = self.get_persisted_settings()
for line in fileinput.input(self.persisted_settings, inplace=True):
current_index = fileinput.lineno()
for (value_pos, current_value), new_value in zip(current_settings.items(), options.values()):
if value_pos == current_index:
line = line.replace(current_value, new_value)
print(line, end="")
self.remove_duplications()
def toggle_settings_to_persist(self, statment):
for line in fileinput.input(self.settings_to_persist, inplace=True):
if statment:
line = line.replace("false", "true")
else:
line = line.replace("true", "false")
print(line, end="")
def set_json_settings(self):
with open(Data.settings_file_name, 'w') as json_file:
dump(settings_json, json_file, indent=4)
def set_config(self):
self.toggle_settings_to_persist(False)
self.set_persisted_settings()
self.toggle_settings_to_persist(True)
self.set_json_settings()
def start_autoconfig():
league_path = None
for process in process_iter(['name', 'cwd']):
if process.info['name'] == Data.client_name_executable:
os.system('taskkill -f -im "{}"'.format(Data.game_name_executable))
league_path = process.info['cwd']
if league_path is not None and os.path.isdir(league_path):
settings_to_persist = os.path.join(league_path, Data.settings_to_persist_path)
persisted_settings = os.path.join(league_path, Data.persisted_settings_path)
files_list = [settings_to_persist, persisted_settings]
for file in files_list:
try:
win32api.SetFileAttributes(file, 128)
except:
try:
os.chmod(file, 0o777)
except:
pass
Autoconfig(settings_to_persist, persisted_settings).set_config()