trainerbase 3.1.5__tar.gz → 3.3.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: trainerbase
3
- Version: 3.1.5
3
+ Version: 3.3.0
4
4
  Summary: Framework for creating game trainers/mods
5
5
  Home-page: https://gitlab.com/python-trainers/trainer-base
6
6
  License: MIT
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "trainerbase"
3
- version = "3.1.5"
3
+ version = "3.3.0"
4
4
  description = "Framework for creating game trainers/mods"
5
5
  authors = ["v01d <v01d@v01d.ru>", "doomayka <zd@doomayka.ru>"]
6
6
  license = "MIT"
@@ -28,10 +28,6 @@ from trainerbase.speedhack import SpeedHack
28
28
  from trainerbase.tts import say
29
29
 
30
30
 
31
- TAG_TELEPORT_LABELS = "__teleport_labels"
32
- TAG_SPEEDHACK_FACTOR_INPUT = "tag_speedhack_factor_input"
33
-
34
-
35
31
  class AbstractUIComponent(ABC):
36
32
  @abstractmethod
37
33
  def add_to_ui(self) -> None:
@@ -211,12 +207,14 @@ class GameObjectUI(AbstractUIComponent):
211
207
 
212
208
 
213
209
  class TeleportUI(AbstractUIComponent):
210
+ DPG_TAG_TELEPORT_LABELS = "__teleport_labels"
211
+
214
212
  def __init__(
215
213
  self,
216
214
  tp: Teleport,
217
- hotkey_save_position: str | None = None,
218
- hotkey_set_saved_position: str | None = None,
219
- hotkey_dash: str | None = None,
215
+ hotkey_save_position: str | None = "Insert",
216
+ hotkey_set_saved_position: str | None = "Home",
217
+ hotkey_dash: str | None = "End",
220
218
  tts_on_hotkey: bool = True,
221
219
  ):
222
220
  self.tp = tp
@@ -261,7 +259,7 @@ class TeleportUI(AbstractUIComponent):
261
259
  say("Dash!")
262
260
 
263
261
  def on_goto_label(self):
264
- self.tp.goto(dpg.get_value(TAG_TELEPORT_LABELS))
262
+ self.tp.goto(dpg.get_value(self.DPG_TAG_TELEPORT_LABELS))
265
263
 
266
264
  def _tp_add_save_set_position_hotkeys_if_needed(self):
267
265
  if self.hotkey_save_position is None or self.hotkey_set_saved_position is None:
@@ -289,14 +287,20 @@ class TeleportUI(AbstractUIComponent):
289
287
 
290
288
  with dpg.group(horizontal=True):
291
289
  dpg.add_button(label="Go To", callback=self.on_goto_label)
292
- dpg.add_combo(label="Labels", tag=TAG_TELEPORT_LABELS, items=labels, default_value=labels[0])
290
+ dpg.add_combo(label="Labels", tag=self.DPG_TAG_TELEPORT_LABELS, items=labels, default_value=labels[0])
293
291
 
294
292
 
295
293
  class SpeedHackUI(AbstractUIComponent):
296
- def __init__(self, speedhack: SpeedHack, key: str):
294
+ DPG_TAG_SPEEDHACK_FACTOR_INPUT = "tag_speedhack_factor_input"
295
+ DPG_TAG_SPEEDHACK_PRESET_INPUT = "tag_speedhack_preset_input"
296
+
297
+ PRESETS: tuple[float, ...] = (0.1, 0.2, 0.3, 0.5, 1.0, 2.0, 3.0, 5.0, 10.0, 20.0, 50.0)
298
+
299
+ def __init__(self, speedhack: SpeedHack, key: str = "Delete", default_factor_input_value: float = 3.0):
297
300
  self.speedhack = speedhack
298
301
  self.key = key
299
- self.switch = ShortLongPressSwitch(SpeedHackUISwitch(speedhack, TAG_SPEEDHACK_FACTOR_INPUT), key)
302
+ self.default_factor_input_value = default_factor_input_value
303
+ self.switch = ShortLongPressSwitch(SpeedHackUISwitch(speedhack, self.DPG_TAG_SPEEDHACK_FACTOR_INPUT), key)
300
304
 
301
305
  @override
302
306
  def add_to_ui(self) -> None:
@@ -304,17 +308,41 @@ class SpeedHackUI(AbstractUIComponent):
304
308
  dpg.add_text(f"Press [{self.key}] Toggle SpeedHack")
305
309
 
306
310
  dpg.add_input_double(
307
- tag=TAG_SPEEDHACK_FACTOR_INPUT,
311
+ tag=self.DPG_TAG_SPEEDHACK_FACTOR_INPUT,
308
312
  label="SpeedHack Factor",
309
313
  min_value=0.0,
310
314
  max_value=100.0,
311
- default_value=3.0,
315
+ default_value=self.default_factor_input_value,
312
316
  min_clamped=True,
313
317
  max_clamped=True,
318
+ callback=self.on_factor_change,
319
+ )
320
+
321
+ dpg.add_slider_int(
322
+ tag=self.DPG_TAG_SPEEDHACK_PRESET_INPUT,
323
+ label="Preset",
324
+ min_value=0,
325
+ max_value=len(self.PRESETS) - 1,
326
+ clamped=True,
327
+ default_value=self.get_closest_preset_index(self.default_factor_input_value),
328
+ callback=self.on_preset_change,
314
329
  )
315
330
 
316
331
  self.switch.handle()
317
332
 
333
+ def on_preset_change(self):
334
+ new_factor = self.PRESETS[dpg.get_value(self.DPG_TAG_SPEEDHACK_PRESET_INPUT)]
335
+ dpg.set_value(self.DPG_TAG_SPEEDHACK_FACTOR_INPUT, new_factor)
336
+
337
+ def on_factor_change(self):
338
+ new_factor = dpg.get_value(self.DPG_TAG_SPEEDHACK_FACTOR_INPUT)
339
+ closest_preset_index = self.get_closest_preset_index(new_factor)
340
+ dpg.set_value(self.DPG_TAG_SPEEDHACK_PRESET_INPUT, closest_preset_index)
341
+
342
+ def get_closest_preset_index(self, factor: float) -> int:
343
+ closest_preset = min(self.PRESETS, key=lambda preset: abs(preset - factor))
344
+ return self.PRESETS.index(closest_preset)
345
+
318
346
 
319
347
  class SpeedHackUISwitch(Switchable):
320
348
  def __init__(self, speedhack: SpeedHack, dpg_tag: str):
@@ -1,7 +1,7 @@
1
1
  from abc import ABC, abstractmethod
2
2
  from collections.abc import Callable
3
3
  from functools import partial
4
- from typing import Self, assert_never
4
+ from typing import Self, assert_never, override
5
5
 
6
6
  from pymem import Pymem
7
7
  from pymem.exception import ProcessNotFound
@@ -55,6 +55,11 @@ class AOBScan(AbstractAddress):
55
55
  self.module_name = module_name
56
56
  self.multiple_result_index = multiple_result_index
57
57
 
58
+ def __add__(self, extra_add: int) -> Self:
59
+ new_add = self.add + extra_add
60
+ return self.inherit(new_add=new_add)
61
+
62
+ @override
58
63
  def resolve(self) -> int:
59
64
  if self._saved_scan_result is not None:
60
65
  return self._saved_scan_result
@@ -88,6 +93,20 @@ class AOBScan(AbstractAddress):
88
93
 
89
94
  return result_address
90
95
 
96
+ def inherit(self, *, new_add: int | None = None) -> Self:
97
+ new_address = self.__class__(
98
+ self.aob,
99
+ add=self.add,
100
+ module_name=self.module_name,
101
+ multiple_result_index=self.multiple_result_index,
102
+ should_cache=self._should_cache,
103
+ )
104
+
105
+ if new_add is not None:
106
+ new_address.add = new_add
107
+
108
+ return new_address
109
+
91
110
 
92
111
  class Address(AbstractAddress):
93
112
  def __init__(self, base_address: int, offsets: list[int] | None = None, add: int = 0):
@@ -105,6 +124,14 @@ class Address(AbstractAddress):
105
124
  case _:
106
125
  assert_never(other)
107
126
 
127
+ @override
128
+ def resolve(self) -> int:
129
+ pointer = self.base_address
130
+ for offset in self.offsets:
131
+ pointer = read_pointer(pointer) + offset
132
+
133
+ return pointer + self.add
134
+
108
135
  def inherit(self, *, extra_offsets: list[int] | None = None, new_add: int | None = None) -> Self:
109
136
  new_address = self.__class__(self.base_address, self.offsets.copy(), self.add)
110
137
 
@@ -116,13 +143,6 @@ class Address(AbstractAddress):
116
143
 
117
144
  return new_address
118
145
 
119
- def resolve(self) -> int:
120
- pointer = self.base_address
121
- for offset in self.offsets:
122
- pointer = read_pointer(pointer) + offset
123
-
124
- return pointer + self.add
125
-
126
146
 
127
147
  def ensure_address(obj: ConvertibleToAddress) -> AbstractAddress:
128
148
  match obj:
File without changes
File without changes