Files
2077-gps-mod/tools/write_momentum_weights.py
T
2026-06-27 04:16:59 -05:00

63 lines
1.8 KiB
Python
Executable File

#!/usr/bin/env python3
"""Write EdgeWeightGPS momentum penalty presets as one raw float32 value."""
from __future__ import annotations
import argparse
import struct
from pathlib import Path
DEFAULT_INSTALL_PATH = Path(
"/var/home/salt/.var/app/com.valvesoftware.Steam/.local/share/Steam/steamapps/common/"
"Cyberpunk 2077/red4ext/plugins/EdgeWeightGPS/momentum_weights.bin"
)
PRESETS: dict[str, float] = {
"vanilla": 0.0,
"legacy-default": 8.0,
"mild": 4.0,
"strong": 16.0,
"default": 80.0,
"silly": 80.0,
"overstrong": 160.0,
"pathological": 250.0,
}
def parse_penalty(text: str) -> float:
value = float(text)
if not 0.0 <= value <= 1000.0:
raise argparse.ArgumentTypeError("penalty must be between 0 and 1000")
return value
def write_weight(path: Path, value: float) -> None:
path.parent.mkdir(parents=True, exist_ok=True)
path.write_bytes(struct.pack("<f", value))
def main() -> int:
parser = argparse.ArgumentParser()
parser.add_argument("preset", nargs="?", choices=sorted(PRESETS), default="default")
parser.add_argument("--value", type=parse_penalty, help="explicit fixed edge penalty")
parser.add_argument("--output", type=Path, default=DEFAULT_INSTALL_PATH)
parser.add_argument("--preset-dir", type=Path, help="write every named preset into this directory")
args = parser.parse_args()
if args.preset_dir:
for name, value in PRESETS.items():
path = args.preset_dir / f"{name}.bin"
write_weight(path, value)
print(f"{path}: {value}")
return 0
value = args.value if args.value is not None else PRESETS[args.preset]
write_weight(args.output, value)
print(f"{args.output}: {value}")
return 0
if __name__ == "__main__":
raise SystemExit(main())