Skip to content

Commit

Permalink
Towards an opaque name type
Browse files Browse the repository at this point in the history
Add a Names struct for reading and writing name files. Add a simple driver
command for this struct for testing. Use signed integers for name types to match
the name file format.
  • Loading branch information
widberg committed Oct 1, 2023
1 parent 2b7a1b3 commit d33da9d
Show file tree
Hide file tree
Showing 62 changed files with 165 additions and 72 deletions.
8 changes: 4 additions & 4 deletions bff-cli/src/crc32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ pub enum Crc32Format {
Hexadecimal,
}

fn format_hash(hash: u32, format: &Crc32Format) -> String {
fn format_hash(hash: i32, format: &Crc32Format) -> String {
match format {
Crc32Format::Signed => {
format!("{}", hash as i32)
format!("{}", hash)
}
Crc32Format::Unsigned => {
format!("{}", hash)
format!("{}", hash as u32)
}
Crc32Format::Hexadecimal => {
format!("{:#08x}", hash)
Expand All @@ -40,7 +40,7 @@ fn format_hash(hash: u32, format: &Crc32Format) -> String {

pub fn crc32(
string: &Option<String>,
starting: &u32,
starting: &i32,
algorithm: &Crc32Algorithm,
mode: &Crc32Mode,
format: &Crc32Format,
Expand Down
2 changes: 1 addition & 1 deletion bff-cli/src/crc64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ fn format_hash(hash: u64, format: &Crc64Format) -> String {

pub fn crc64(
string: &Option<String>,
starting: &u64,
starting: &i64,
algorithm: &Crc64Algorithm,
mode: &Crc64Mode,
format: &Crc64Format,
Expand Down
16 changes: 11 additions & 5 deletions bff-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ mod info;
mod lz;
mod unlz;

mod names;

#[derive(Subcommand)]
enum Commands {
#[clap(alias = "x")]
Expand All @@ -19,7 +21,9 @@ enum Commands {
directory: PathBuf,
},
#[clap(alias = "t")]
Info { bigfile: PathBuf },
Info {
bigfile: PathBuf,
},
Crc32 {
string: Option<String>,
#[arg(
Expand All @@ -28,15 +32,15 @@ enum Commands {
default_value_t = 0,
help = "Starting value for the CRC-32 calculation"
)]
starting: u32,
starting: i32,
#[clap(value_enum)]
#[arg(short, long, default_value_t = Crc32Algorithm::Asobo)]
algorithm: Crc32Algorithm,
#[clap(value_enum)]
#[arg(short, long, default_value_t = Crc32Mode::Lines)]
mode: Crc32Mode,
#[clap(value_enum)]
#[arg(short, long, default_value_t = Crc32Format::Unsigned)]
#[arg(short, long, default_value_t = Crc32Format::Signed)]
format: Crc32Format,
},
Crc64 {
Expand All @@ -47,15 +51,15 @@ enum Commands {
default_value_t = 0,
help = "Starting value for the CRC-32 calculation"
)]
starting: u64,
starting: i64,
#[clap(value_enum)]
#[arg(short, long, default_value_t = Crc64Algorithm::Asobo)]
algorithm: Crc64Algorithm,
#[clap(value_enum)]
#[arg(short, long, default_value_t = Crc64Mode::Lines)]
mode: Crc64Mode,
#[clap(value_enum)]
#[arg(short, long, default_value_t = Crc64Format::Unsigned)]
#[arg(short, long, default_value_t = Crc64Format::Signed)]
format: Crc64Format,
},
Unlz {
Expand All @@ -68,6 +72,7 @@ enum Commands {
#[arg(short, long, default_value_t = lz::LzEndian::Little)]
endian: lz::LzEndian,
},
Names {},
}

#[derive(Parser)]
Expand Down Expand Up @@ -99,5 +104,6 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
} => crc64::crc64(string, starting, algorithm, mode, format),
Commands::Unlz { endian } => unlz::unlz(endian),
Commands::Lz { endian } => lz::lz(endian),
Commands::Names {} => names::names(),
}
}
14 changes: 14 additions & 0 deletions bff-cli/src/names.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use std::io;

use bff::names::Names;

pub fn names() -> Result<(), Box<dyn std::error::Error>> {
let mut names = Names::default();
names.read(io::stdin().lock())?;

println!("{:#?}", names);

names.write(&mut io::stdout().lock())?;

Ok(())
}
2 changes: 1 addition & 1 deletion bff-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub fn bff_named_class(input: TokenStream) -> TokenStream {

quote! {
impl crate::traits::NamedClass for #name {
const NAME: crate::name::Name = crate::crc32::asobo(#class_name.as_bytes());
const NAME: crate::names::Name = crate::crc32::asobo(#class_name.as_bytes());
}
}
.into()
Expand Down
2 changes: 1 addition & 1 deletion bff/src/bigfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use serde::Serialize;
use crate::block::Block;
use crate::header::*;
use crate::manifest::*;
use crate::name::Name;
use crate::names::Name;
use crate::object::Object;
use crate::platforms::Platform;
use crate::pool::Pool;
Expand Down
2 changes: 1 addition & 1 deletion bff/src/class/animation/v1_291_03_06_pc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::keyframer::{
KeyframerRot,
KeyframerVec3fComp,
};
use crate::name::Name;
use crate::names::Name;

#[derive(BinRead, Debug, Serialize, BinWrite, Deserialize)]
struct AnimationNode {
Expand Down
2 changes: 1 addition & 1 deletion bff/src/class/bitmap/v1_381_67_09_pc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use binrw::{BinRead, BinWrite};
use serde::{Deserialize, Serialize};

use crate::class::trivial_class::TrivialClass;
use crate::name::Name;
use crate::names::Name;

#[derive(BinRead, Debug, Serialize, BinWrite, Deserialize)]
#[brw(repr = u16)]
Expand Down
2 changes: 1 addition & 1 deletion bff/src/class/camera/v1_381_67_09_pc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use serde::{Deserialize, Serialize};

use crate::class::trivial_class::TrivialClass;
use crate::link_header::ObjectLinkHeaderV1_381_67_09PC;
use crate::name::Name;
use crate::names::Name;

#[derive(BinRead, Debug, Serialize, BinWrite, Deserialize)]
#[br(import(_link_header: &ObjectLinkHeaderV1_381_67_09PC))]
Expand Down
2 changes: 1 addition & 1 deletion bff/src/class/collision_vol/v1_291_03_06_pc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::class::trivial_class::TrivialClass;
use crate::dynarray::DynArray;
use crate::link_header::ObjectLinkHeaderV1_06_63_02PC;
use crate::math::Mat4f;
use crate::name::Name;
use crate::names::Name;

#[derive(BinRead, Debug, Serialize, BinWrite, Deserialize)]
struct CollisionVolInfo {
Expand Down
2 changes: 1 addition & 1 deletion bff/src/class/collision_vol/v1_381_67_09_pc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::class::trivial_class::TrivialClass;
use crate::dynarray::DynArray;
use crate::link_header::ObjectLinkHeaderV1_381_67_09PC;
use crate::math::Mat4f;
use crate::name::Name;
use crate::names::Name;

#[derive(BinRead, Debug, Serialize, BinWrite, Deserialize)]
struct CollisionVolInfo {
Expand Down
2 changes: 1 addition & 1 deletion bff/src/class/fonts/v1_381_67_09_pc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::dynarray::DynArray;
use crate::link_header::ResourceObjectLinkHeader;
use crate::map::BffMap;
use crate::math::Vec2f;
use crate::name::Name;
use crate::names::Name;

type CharacterID = u32;

Expand Down
2 changes: 1 addition & 1 deletion bff/src/class/game_obj/v1_291_03_06_pc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use serde::{Deserialize, Serialize};

use crate::class::trivial_class::TrivialClass;
use crate::dynarray::DynArray;
use crate::name::Name;
use crate::names::Name;

#[derive(Debug, BinRead, Serialize, BinWrite, Deserialize)]
#[br(import(_link_header: &()))]
Expand Down
2 changes: 1 addition & 1 deletion bff/src/class/game_obj/v1_381_67_09_pc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use serde::{Deserialize, Serialize};
use crate::class::trivial_class::TrivialClass;
use crate::dynarray::DynArray;
use crate::link_header::ResourceObjectLinkHeader;
use crate::name::Name;
use crate::names::Name;
use crate::strings::PascalStringNull;

#[derive(BinRead, Debug, Serialize, BinWrite, Deserialize)]
Expand Down
2 changes: 1 addition & 1 deletion bff/src/class/gen_world/v1_381_67_09_pc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::dynarray::DynArray;
use crate::link_header::ObjectLinkHeaderV1_381_67_09PC;
use crate::map::BffMap;
use crate::math::{Mat4f, Vec2f, Vec3f};
use crate::name::Name;
use crate::names::Name;
use crate::strings::{FixedStringNull, PascalStringNull};

#[derive(BinRead, Debug, Serialize, BinWrite, Deserialize)]
Expand Down
2 changes: 1 addition & 1 deletion bff/src/class/gw_road/v1_381_67_09_pc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::class::trivial_class::TrivialClass;
use crate::dynarray::DynArray;
use crate::link_header::ResourceObjectLinkHeader;
use crate::math::Vec2f;
use crate::name::Name;
use crate::names::Name;

#[bitsize(7)]
#[derive(TryFromBits, Debug, Serialize, Deserialize)]
Expand Down
2 changes: 1 addition & 1 deletion bff/src/class/lod/v1_06_63_02_pc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::class::trivial_class::TrivialClass;
use crate::dynarray::DynArray;
use crate::link_header::ObjectLinkHeaderV1_06_63_02PC;
use crate::math::{DynBox, DynSphere, Vec3f};
use crate::name::Name;
use crate::names::Name;

#[derive(BinRead, Debug, Serialize, BinWrite, Deserialize)]
struct ClassRes {
Expand Down
2 changes: 1 addition & 1 deletion bff/src/class/lod/v1_291_03_06_pc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::class::trivial_class::TrivialClass;
use crate::dynarray::DynArray;
use crate::link_header::ObjectLinkHeaderV1_06_63_02PC;
use crate::math::{DynBox, DynSphere, Vec3f};
use crate::name::Name;
use crate::names::Name;
use crate::option::BffOption;

#[derive(BinRead, Debug, Serialize, BinWrite, Deserialize)]
Expand Down
2 changes: 1 addition & 1 deletion bff/src/class/lod/v1_381_67_09_pc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::dynarray::DynArray;
use crate::link_header::ObjectLinkHeaderV1_381_67_09PC;
use crate::map::BffMap;
use crate::math::{DynBox, DynSphere};
use crate::name::Name;
use crate::names::Name;
use crate::option::BffOption;

#[derive(BinRead, Debug, Serialize, BinWrite, Deserialize)]
Expand Down
2 changes: 1 addition & 1 deletion bff/src/class/lod_data/v1_06_63_02_pc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use serde::{Deserialize, Serialize};
use crate::class::trivial_class::TrivialClass;
use crate::dynarray::DynArray;
use crate::math::RGBA;
use crate::name::Name;
use crate::names::Name;
use crate::option::BffOption;

#[derive(BinRead, Debug, Serialize, BinWrite, Deserialize)]
Expand Down
2 changes: 1 addition & 1 deletion bff/src/class/lod_data/v1_291_03_06_pc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use serde::{Deserialize, Serialize};
use crate::class::trivial_class::TrivialClass;
use crate::dynarray::DynArray;
use crate::math::Vec3f;
use crate::name::Name;
use crate::names::Name;
use crate::option::BffOption;

#[derive(BinRead, Debug, Serialize, BinWrite, Deserialize)]
Expand Down
2 changes: 1 addition & 1 deletion bff/src/class/lod_data/v1_381_67_09_pc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::class::trivial_class::TrivialClass;
use crate::dynarray::DynArray;
use crate::link_header::{ObjectDatasFlagsV1_381_67_09PC, ResourceObjectLinkHeader};
use crate::math::Vec3f;
use crate::name::Name;
use crate::names::Name;
use crate::option::BffOption;

#[derive(BinRead, Debug, Serialize, BinWrite, Deserialize)]
Expand Down
2 changes: 1 addition & 1 deletion bff/src/class/material/v1_381_67_09_pc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use serde::{Deserialize, Serialize};
use crate::class::trivial_class::TrivialClass;
use crate::link_header::ResourceObjectLinkHeader;
use crate::math::{Vec2f, RGB};
use crate::name::Name;
use crate::names::Name;

#[bitsize(32)]
#[derive(BinRead, DebugBits, SerializeBits, BinWrite, DeserializeBits)]
Expand Down
2 changes: 1 addition & 1 deletion bff/src/class/material_anim/v1_381_67_09_pc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::keyframer::{
KeyframerVec4fLinear,
};
use crate::link_header::ResourceObjectLinkHeader;
use crate::name::Name;
use crate::names::Name;

#[bitsize(8)]
#[derive(BinRead, DebugBits, SerializeBits, BinWrite, DeserializeBits)]
Expand Down
2 changes: 1 addition & 1 deletion bff/src/class/material_obj/v1_381_67_09_pc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::class::trivial_class::TrivialClass;
use crate::dynarray::DynArray;
use crate::link_header::ResourceObjectLinkHeader;
use crate::map::BffMap;
use crate::name::Name;
use crate::names::Name;

#[derive(BinRead, Debug, Serialize, BinWrite, Deserialize)]
#[br(import(_link_header: &ResourceObjectLinkHeader))]
Expand Down
2 changes: 1 addition & 1 deletion bff/src/class/mesh/v1_06_63_02_pc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use serde_big_array::BigArray;
use crate::class::trivial_class::TrivialClass;
use crate::dynarray::DynArray;
use crate::math::{DynBox, DynSphere, Mat, Sphere, Vec2f, Vec3, Vec3f};
use crate::name::Name;
use crate::names::Name;

#[derive(BinRead, Debug, Serialize, BinWrite, Deserialize)]
struct Box {
Expand Down
2 changes: 1 addition & 1 deletion bff/src/class/mesh/v1_291_03_06_pc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use serde_big_array::BigArray;
use crate::class::trivial_class::TrivialClass;
use crate::dynarray::DynArray;
use crate::math::{DynBox, DynSphere, Mat4f, Quat, Vec2, Vec2f, Vec3, Vec3f};
use crate::name::Name;
use crate::names::Name;

#[derive(BinRead, Debug, Serialize, BinWrite, Deserialize)]
struct PointsRelated0 {
Expand Down
2 changes: 1 addition & 1 deletion bff/src/class/mesh/v1_381_67_09_pc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::math::{
Vec2f,
Vec3f,
};
use crate::name::Name;
use crate::names::Name;
use crate::strings::PascalString;

type VertexVectorComponent = u8;
Expand Down
2 changes: 1 addition & 1 deletion bff/src/class/node/v1_291_03_06_pc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use serde::{Deserialize, Serialize};

use crate::class::trivial_class::TrivialClass;
use crate::math::{Mat4f, Quat, Rect, Sphere, Vec3f, RGBA};
use crate::name::Name;
use crate::names::Name;

#[derive(BinRead, Debug, Serialize, BinWrite, Deserialize)]
#[br(import(_link_header: &()))]
Expand Down
2 changes: 1 addition & 1 deletion bff/src/class/node/v1_381_67_09_pc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use serde::{Deserialize, Serialize};
use crate::class::trivial_class::TrivialClass;
use crate::link_header::ResourceObjectLinkHeader;
use crate::math::{Mat4f, Quat, Rect, Sphere, Vec3f, RGBA};
use crate::name::Name;
use crate::names::Name;

#[derive(BinRead, Debug, Serialize, BinWrite, Deserialize)]
#[br(import(_link_header: &ResourceObjectLinkHeader))]
Expand Down
2 changes: 1 addition & 1 deletion bff/src/class/omni/v1_381_67_09_pc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use serde::{Deserialize, Serialize};
use crate::class::trivial_class::TrivialClass;
use crate::link_header::ObjectLinkHeaderV1_381_67_09PC;
use crate::math::Mat4f;
use crate::name::Name;
use crate::names::Name;

#[derive(BinRead, Debug, Serialize, BinWrite, Deserialize)]
#[br(import(_link_header: &ObjectLinkHeaderV1_381_67_09PC))]
Expand Down
2 changes: 1 addition & 1 deletion bff/src/class/particles/v1_381_67_09_pc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::keyframer::{
};
use crate::link_header::ObjectLinkHeaderV1_381_67_09PC;
use crate::math::{Mat4f, Vec3f};
use crate::name::Name;
use crate::names::Name;

#[bitsize(32)]
#[derive(BinRead, DebugBits, SerializeBits, BinWrite, DeserializeBits)]
Expand Down
2 changes: 1 addition & 1 deletion bff/src/class/rot_shape/v1_291_03_06_pc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::class::trivial_class::TrivialClass;
use crate::dynarray::DynArray;
use crate::link_header::ObjectLinkHeaderV1_06_63_02PC;
use crate::math::{Vec2f, Vec3f};
use crate::name::Name;
use crate::names::Name;

#[derive(BinRead, Debug, Serialize, BinWrite, Deserialize)]
struct PointsRelated0 {
Expand Down
2 changes: 1 addition & 1 deletion bff/src/class/rot_shape/v1_381_67_09_pc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::class::trivial_class::TrivialClass;
use crate::dynarray::DynArray;
use crate::link_header::ObjectLinkHeaderV1_381_67_09PC;
use crate::math::{Vec2f, Vec3f};
use crate::name::Name;
use crate::names::Name;

#[derive(BinRead, Debug, Serialize, BinWrite, Deserialize)]
#[brw(repr = u16)]
Expand Down
2 changes: 1 addition & 1 deletion bff/src/class/rtc/v1_381_67_09_pc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::keyframer::{
KeyframerVec3fComp,
};
use crate::link_header::ResourceObjectLinkHeader;
use crate::name::Name;
use crate::names::Name;

#[derive(BinRead, Debug, Serialize, BinWrite, Deserialize)]
struct RtcAnimationNode {
Expand Down
Loading

0 comments on commit d33da9d

Please sign in to comment.