Files
my-botty/tools/set_binds_from_params.py
alexpolo1 77b35df26b Two-layer keybind verification/setting driven by params.ini
Layer 1 (Controls page / .keyo): tools/set_controls_keyo.py parses the
character keyo (same binary format as utils/key_detector) and verifies every
skill hotkey in params.ini is bound to a skill slot; --fix writes missing keys
into free skill slots with a backup (D2R must be closed). Picks the configured
character file. Verified: fistman controls match params.

Layer 2 (skill assignment / picker): enabled the existing skill_hotkey_setter
machinery for the hammerdin build:
- skill_preflight: hammerdin build rules (blessed_hammer left/required,
  concentration right/required, redemption/vigor/conviction/holy_shield/
  teleport right/optional) + PALADIN_TEMPLATE_ALIASES, merged TEMPLATE_ALIASES.
- skill_hotkey_setter: paladin picker template aliases with slot-icon fallback.
- tools/set_binds_from_params.py: end-to-end runner - opens the in-game picker,
  binds each skill to its params hotkey, verifies via slot icon, reports
  match/mismatch per skill.
- tools/capture_skill_hotkeys.py now saves crops straight into
  assets/templates/ui/skills/ so captures immediately become live templates
  for both the preflight and the picker search.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-06-12 08:30:43 +02:00

58 lines
2.1 KiB
Python

"""
Make the in-game skill assignment match config/params.ini (layer 2 of hotkeys).
For each skill in the build rules (utils/skill_preflight.get_build_skill_checks)
this opens the in-game skill picker ('s'), finds the skill icon by template,
hovers it and presses the hotkey from params.ini - that assigns the bind on the
character (server-side for online chars; no file can be edited instead). Each
bind is then verified by pressing the hotkey and matching the slot icon.
Prerequisites:
1. Controls layer verified: python tools/set_controls_keyo.py
2. Skill icon templates exist: run tools/capture_skill_hotkeys.py once with
correct binds, OR they ship in assets/templates/ui/skills/. Without a
template for a skill, that skill is reported as 'template missing'.
3. D2R in a game (town), nothing else on screen.
Usage (from repo root): <botty-env-python> tools/set_binds_from_params.py
"""
import os
import sys
import time
import ctypes
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "src"))
ctypes.windll.user32.SetProcessDPIAware()
from config import Config
from screen import start_detecting_window, stop_detecting_window
from utils.skill_preflight import get_build_skill_checks
from utils.skill_hotkey_setter import bind_skill_hotkey
def main():
print("Focus the D2R window (in a game). Binding starts in 5s...")
time.sleep(5)
start_detecting_window()
try:
checks = get_build_skill_checks(Config())
if not checks:
raise SystemExit(f"no build rules for char type {Config().char.get('type')!r}")
results = [bind_skill_hotkey(c) for c in checks]
finally:
stop_detecting_window()
print("\nResults:")
ok = True
for r in results:
state = "OK" if (r.bound and r.verified) else ("BOUND, UNVERIFIED" if r.bound else "FAILED")
ok &= r.bound and r.verified
print(f" {r.skill:16s} -> {r.hotkey:>4s} {state} {r.reason}")
print("\nAll binds match params.ini." if ok else
"\nSome binds failed - fix in-game or capture missing templates "
"(tools/capture_skill_hotkeys.py), then re-run.")
if __name__ == "__main__":
main()