Files
horizon-airdef/crates/horizon-client/examples/probe/input_probe.rs
T
Ludovic Marie 858f701ee8 Run the horizon-client parity probes from one binary
81 client examples that harnesses run become modules of examples/probe:
harnesses run `probe <name> ...` (or `cargo run --example probe -- <name>`),
and the shared helpers (audio_common, hud_fixture, chat_screen_fixture)
move with them. The benchmarks and manual tools stay standalone examples.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-23 16:30:38 +02:00

44 lines
1.4 KiB
Rust

#![forbid(unsafe_code)]
use horizon_client::{Result, input};
use serde_json::Value;
use std::{
fs::File,
io::{BufRead, BufReader, BufWriter, Write},
};
fn number(v: &Value) -> f32 {
f32::from_bits(u32::from_str_radix(v.as_str().unwrap(), 16).unwrap())
}
fn bits(v: f32) -> u32 {
if v.is_nan() { 0x7fc00000 } else { v.to_bits() }
}
pub fn main() -> Result<()> {
let args: Vec<_> = crate::args().skip(1).collect();
let mut out = BufWriter::new(File::create(&args[1])?);
for line in BufReader::new(File::open(&args[0])?).lines() {
let f: Value = serde_json::from_str(&line?)?;
let keys = f["keys"].as_u64().unwrap();
let direction =
input::keyboard_direction(keys & 1 != 0, keys & 2 != 0, keys & 4 != 0, keys & 8 != 0);
let vector = if f["vector"].is_null() {
direction
} else {
[number(&f["vector"][0]), number(&f["vector"][1])]
};
let result = input::modify_input(
vector,
(f["using"].as_bool().unwrap() && !f["riding"].as_bool().unwrap())
.then(|| number(&f["item"])),
f["slow"].as_bool().unwrap().then(|| number(&f["sneak"])),
);
writeln!(
out,
"{:08x} {:08x} {:08x} {:08x}",
bits(direction[0]),
bits(direction[1]),
bits(result[0]),
bits(result[1])
)?;
}
Ok(())
}