Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
8f563e0379 | |||
f8263c7ba8 |
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -111,7 +111,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "strafesnet_snf"
|
name = "strafesnet_snf"
|
||||||
version = "0.1.2"
|
version = "0.1.3-bot"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"binrw",
|
"binrw",
|
||||||
"id",
|
"id",
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "strafesnet_snf"
|
name = "strafesnet_snf"
|
||||||
version = "0.1.2"
|
version = "0.1.3-bot"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
37
src/bot.rs
37
src/bot.rs
@ -1,4 +1,7 @@
|
|||||||
use binrw::{BinReaderExt, binrw};
|
use std::io::Seek;
|
||||||
|
|
||||||
|
use binrw::{binrw,BinReaderExt,BinWriterExt};
|
||||||
|
use crate::newtypes::instruction::TimedPhysicsInstruction;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum Error{
|
pub enum Error{
|
||||||
@ -8,6 +11,38 @@ pub enum Error{
|
|||||||
File(crate::file::Error),
|
File(crate::file::Error),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct BotDebug{
|
||||||
|
file:std::fs::File,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl BotDebug{
|
||||||
|
pub fn new(name:impl AsRef<std::path::Path>)->std::io::Result<Self>{
|
||||||
|
Ok(Self{
|
||||||
|
file:std::fs::File::create(name)?,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
pub fn push(&mut self,ins:strafesnet_common::instruction::TimedInstruction<strafesnet_common::physics::Instruction>)->Result<(),binrw::Error>{
|
||||||
|
let ret=match TryInto::<TimedPhysicsInstruction>::try_into(ins){
|
||||||
|
Ok(ins)=>self.file.write_le(&ins),
|
||||||
|
Err(crate::newtypes::physics::PhysicsInputInstructionError::DropInstruction)=>Ok(()),
|
||||||
|
};
|
||||||
|
//check if too much data has written to be reasonable
|
||||||
|
//avoid filling my hard drive on an infinite loop basically
|
||||||
|
if self.file.stream_position().is_ok_and(|pos|50*1024*1024<pos){
|
||||||
|
panic!();
|
||||||
|
}
|
||||||
|
ret
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn read_bot_debug(mut reader:impl BinReaderExt)->Result<Vec<strafesnet_common::instruction::TimedInstruction<strafesnet_common::physics::Instruction>>,binrw::Error>{
|
||||||
|
let mut instructions=Vec::new();
|
||||||
|
while let Ok(ins)=reader.read_le::<TimedPhysicsInstruction>(){
|
||||||
|
instructions.push(ins.try_into().unwrap());
|
||||||
|
}
|
||||||
|
Ok(instructions)
|
||||||
|
}
|
||||||
|
|
||||||
/* block types
|
/* block types
|
||||||
|
|
||||||
BLOCK_BOT_HEADER:
|
BLOCK_BOT_HEADER:
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
mod common;
|
mod common;
|
||||||
pub mod aabb;
|
pub mod aabb;
|
||||||
pub mod model;
|
pub mod model;
|
||||||
|
pub mod mouse;
|
||||||
pub mod integer;
|
pub mod integer;
|
||||||
|
pub mod physics;
|
||||||
|
pub mod instruction;
|
||||||
pub mod gameplay_modes;
|
pub mod gameplay_modes;
|
||||||
pub mod gameplay_style;
|
pub mod gameplay_style;
|
||||||
pub mod gameplay_attributes;
|
pub mod gameplay_attributes;
|
||||||
|
27
src/newtypes/instruction.rs
Normal file
27
src/newtypes/instruction.rs
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
use super::integer::Time;
|
||||||
|
|
||||||
|
#[binrw::binrw]
|
||||||
|
#[brw(little)]
|
||||||
|
pub struct TimedPhysicsInstruction{
|
||||||
|
pub time:Time,
|
||||||
|
pub instruction:super::physics::PhysicsInputInstruction,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl TryInto<strafesnet_common::instruction::TimedInstruction<strafesnet_common::physics::Instruction>> for TimedPhysicsInstruction{
|
||||||
|
type Error=super::integer::RatioError;
|
||||||
|
fn try_into(self)->Result<strafesnet_common::instruction::TimedInstruction<strafesnet_common::physics::Instruction>,Self::Error>{
|
||||||
|
Ok(strafesnet_common::instruction::TimedInstruction{
|
||||||
|
time:strafesnet_common::integer::Time::raw(self.time),
|
||||||
|
instruction:self.instruction.try_into()?,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl TryFrom<strafesnet_common::instruction::TimedInstruction<strafesnet_common::physics::Instruction>> for TimedPhysicsInstruction{
|
||||||
|
type Error=super::physics::PhysicsInputInstructionError;
|
||||||
|
fn try_from(value:strafesnet_common::instruction::TimedInstruction<strafesnet_common::physics::Instruction>)->Result<Self,Self::Error>{
|
||||||
|
Ok(Self{
|
||||||
|
time:value.time.get(),
|
||||||
|
instruction:value.instruction.try_into()?,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
@ -38,6 +38,23 @@ pub struct Ratio64Vec2{
|
|||||||
pub x:Ratio64,
|
pub x:Ratio64,
|
||||||
pub y:Ratio64,
|
pub y:Ratio64,
|
||||||
}
|
}
|
||||||
|
impl TryInto<strafesnet_common::integer::Ratio64Vec2> for Ratio64Vec2{
|
||||||
|
type Error=RatioError;
|
||||||
|
fn try_into(self)->Result<strafesnet_common::integer::Ratio64Vec2,Self::Error>{
|
||||||
|
Ok(strafesnet_common::integer::Ratio64Vec2{
|
||||||
|
x:self.x.try_into()?,
|
||||||
|
y:self.y.try_into()?,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl From<strafesnet_common::integer::Ratio64Vec2> for Ratio64Vec2{
|
||||||
|
fn from(value:strafesnet_common::integer::Ratio64Vec2)->Self{
|
||||||
|
Self{
|
||||||
|
x:value.x.into(),
|
||||||
|
y:value.y.into(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub type Angle32=i32;
|
pub type Angle32=i32;
|
||||||
pub type Planar64=i64;
|
pub type Planar64=i64;
|
||||||
|
37
src/newtypes/mouse.rs
Normal file
37
src/newtypes/mouse.rs
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
use super::integer::Time;
|
||||||
|
|
||||||
|
#[binrw::binrw]
|
||||||
|
#[brw(little)]
|
||||||
|
pub enum EncodedMouseDelta{
|
||||||
|
//X did not move Y has 1 byte, time has 2 bytes
|
||||||
|
X0Y1T2{
|
||||||
|
y:i8,
|
||||||
|
t:u16,
|
||||||
|
},
|
||||||
|
X1Y1T2
|
||||||
|
}
|
||||||
|
///TODO: delta delta encoding lol
|
||||||
|
|
||||||
|
#[binrw::binrw]
|
||||||
|
#[brw(little)]
|
||||||
|
pub struct MouseState{
|
||||||
|
pub pos:[i32;2],
|
||||||
|
pub time:Time,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Into<strafesnet_common::mouse::MouseState> for MouseState{
|
||||||
|
fn into(self)->strafesnet_common::mouse::MouseState{
|
||||||
|
strafesnet_common::mouse::MouseState{
|
||||||
|
pos:self.pos.into(),
|
||||||
|
time:strafesnet_common::integer::Time::raw(self.time),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl From<strafesnet_common::mouse::MouseState> for MouseState{
|
||||||
|
fn from(value:strafesnet_common::mouse::MouseState)->Self{
|
||||||
|
Self{
|
||||||
|
pos:value.pos.to_array(),
|
||||||
|
time:value.time.get(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
98
src/newtypes/physics.rs
Normal file
98
src/newtypes/physics.rs
Normal file
@ -0,0 +1,98 @@
|
|||||||
|
use super::common::Boolio;
|
||||||
|
|
||||||
|
#[binrw::binrw]
|
||||||
|
#[brw(little)]
|
||||||
|
pub enum PhysicsInputInstruction{
|
||||||
|
#[brw(magic=0u8)]
|
||||||
|
ReplaceMouse(super::mouse::MouseState,super::mouse::MouseState),
|
||||||
|
#[brw(magic=1u8)]
|
||||||
|
SetNextMouse(super::mouse::MouseState),
|
||||||
|
#[brw(magic=2u8)]
|
||||||
|
SetMoveRight(Boolio),
|
||||||
|
#[brw(magic=3u8)]
|
||||||
|
SetMoveUp(Boolio),
|
||||||
|
#[brw(magic=4u8)]
|
||||||
|
SetMoveBack(Boolio),
|
||||||
|
#[brw(magic=5u8)]
|
||||||
|
SetMoveLeft(Boolio),
|
||||||
|
#[brw(magic=6u8)]
|
||||||
|
SetMoveDown(Boolio),
|
||||||
|
#[brw(magic=7u8)]
|
||||||
|
SetMoveForward(Boolio),
|
||||||
|
#[brw(magic=8u8)]
|
||||||
|
SetJump(Boolio),
|
||||||
|
#[brw(magic=9u8)]
|
||||||
|
SetZoom(Boolio),
|
||||||
|
#[brw(magic=10u8)]
|
||||||
|
Reset,
|
||||||
|
#[brw(magic=11u8)]
|
||||||
|
Restart,
|
||||||
|
#[brw(magic=12u8)]
|
||||||
|
Spawn(super::gameplay_modes::ModeId,super::gameplay_modes::StageId),
|
||||||
|
#[brw(magic=13u8)]
|
||||||
|
PracticeFly,
|
||||||
|
#[brw(magic=14u8)]
|
||||||
|
SetSensitivity(super::integer::Ratio64Vec2),
|
||||||
|
}
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub enum PhysicsInputInstructionError{
|
||||||
|
/// This is an instruction that can be dropped when serializing
|
||||||
|
DropInstruction,
|
||||||
|
}
|
||||||
|
impl std::fmt::Display for PhysicsInputInstructionError{
|
||||||
|
fn fmt(&self,f:&mut std::fmt::Formatter<'_>)->std::fmt::Result{
|
||||||
|
write!(f,"{self:?}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl std::error::Error for PhysicsInputInstructionError{}
|
||||||
|
impl TryInto<strafesnet_common::physics::Instruction> for PhysicsInputInstruction{
|
||||||
|
type Error=super::integer::RatioError;
|
||||||
|
fn try_into(self)->Result<strafesnet_common::physics::Instruction,Self::Error>{
|
||||||
|
Ok(match self{
|
||||||
|
PhysicsInputInstruction::ReplaceMouse(m0,m1)=>strafesnet_common::physics::Instruction::ReplaceMouse(m0.into(),m1.into()),
|
||||||
|
PhysicsInputInstruction::SetNextMouse(m)=>strafesnet_common::physics::Instruction::SetNextMouse(m.into()),
|
||||||
|
PhysicsInputInstruction::SetMoveRight(state)=>strafesnet_common::physics::Instruction::SetMoveRight(state.into()),
|
||||||
|
PhysicsInputInstruction::SetMoveUp(state)=>strafesnet_common::physics::Instruction::SetMoveUp(state.into()),
|
||||||
|
PhysicsInputInstruction::SetMoveBack(state)=>strafesnet_common::physics::Instruction::SetMoveBack(state.into()),
|
||||||
|
PhysicsInputInstruction::SetMoveLeft(state)=>strafesnet_common::physics::Instruction::SetMoveLeft(state.into()),
|
||||||
|
PhysicsInputInstruction::SetMoveDown(state)=>strafesnet_common::physics::Instruction::SetMoveDown(state.into()),
|
||||||
|
PhysicsInputInstruction::SetMoveForward(state)=>strafesnet_common::physics::Instruction::SetMoveForward(state.into()),
|
||||||
|
PhysicsInputInstruction::SetJump(state)=>strafesnet_common::physics::Instruction::SetJump(state.into()),
|
||||||
|
PhysicsInputInstruction::SetZoom(state)=>strafesnet_common::physics::Instruction::SetZoom(state.into()),
|
||||||
|
PhysicsInputInstruction::Reset=>strafesnet_common::physics::Instruction::Reset,
|
||||||
|
PhysicsInputInstruction::Restart=>strafesnet_common::physics::Instruction::Restart,
|
||||||
|
PhysicsInputInstruction::Spawn(mode_id,stage_id)=>strafesnet_common::physics::Instruction::Spawn(
|
||||||
|
strafesnet_common::gameplay_modes::ModeId::new(mode_id),
|
||||||
|
strafesnet_common::gameplay_modes::StageId::new(stage_id),
|
||||||
|
),
|
||||||
|
PhysicsInputInstruction::PracticeFly=>strafesnet_common::physics::Instruction::PracticeFly,
|
||||||
|
PhysicsInputInstruction::SetSensitivity(sensitivity)=>strafesnet_common::physics::Instruction::SetSensitivity(sensitivity.try_into()?),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl TryFrom<strafesnet_common::physics::Instruction> for PhysicsInputInstruction{
|
||||||
|
type Error=PhysicsInputInstructionError;
|
||||||
|
fn try_from(value:strafesnet_common::physics::Instruction)->Result<Self,Self::Error>{
|
||||||
|
match value{
|
||||||
|
strafesnet_common::physics::Instruction::ReplaceMouse(m0,m1)=>Ok(PhysicsInputInstruction::ReplaceMouse(m0.into(),m1.into())),
|
||||||
|
strafesnet_common::physics::Instruction::SetNextMouse(m)=>Ok(PhysicsInputInstruction::SetNextMouse(m.into())),
|
||||||
|
strafesnet_common::physics::Instruction::SetMoveRight(state)=>Ok(PhysicsInputInstruction::SetMoveRight(state.into())),
|
||||||
|
strafesnet_common::physics::Instruction::SetMoveUp(state)=>Ok(PhysicsInputInstruction::SetMoveUp(state.into())),
|
||||||
|
strafesnet_common::physics::Instruction::SetMoveBack(state)=>Ok(PhysicsInputInstruction::SetMoveBack(state.into())),
|
||||||
|
strafesnet_common::physics::Instruction::SetMoveLeft(state)=>Ok(PhysicsInputInstruction::SetMoveLeft(state.into())),
|
||||||
|
strafesnet_common::physics::Instruction::SetMoveDown(state)=>Ok(PhysicsInputInstruction::SetMoveDown(state.into())),
|
||||||
|
strafesnet_common::physics::Instruction::SetMoveForward(state)=>Ok(PhysicsInputInstruction::SetMoveForward(state.into())),
|
||||||
|
strafesnet_common::physics::Instruction::SetJump(state)=>Ok(PhysicsInputInstruction::SetJump(state.into())),
|
||||||
|
strafesnet_common::physics::Instruction::SetZoom(state)=>Ok(PhysicsInputInstruction::SetZoom(state.into())),
|
||||||
|
strafesnet_common::physics::Instruction::Reset=>Ok(PhysicsInputInstruction::Reset),
|
||||||
|
strafesnet_common::physics::Instruction::Restart=>Ok(PhysicsInputInstruction::Restart),
|
||||||
|
strafesnet_common::physics::Instruction::Spawn(mode_id,stage_id)=>Ok(PhysicsInputInstruction::Spawn(
|
||||||
|
mode_id.get(),
|
||||||
|
stage_id.get(),
|
||||||
|
)),
|
||||||
|
strafesnet_common::physics::Instruction::PracticeFly=>Ok(PhysicsInputInstruction::PracticeFly),
|
||||||
|
strafesnet_common::physics::Instruction::SetSensitivity(sensitivity)=>Ok(PhysicsInputInstruction::SetSensitivity(sensitivity.into())),
|
||||||
|
strafesnet_common::physics::Instruction::Idle=>Err(PhysicsInputInstructionError::DropInstruction),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user