Skip to content

Commit

Permalink
Lets not duplicate the link headers either
Browse files Browse the repository at this point in the history
  • Loading branch information
widberg committed Sep 26, 2023
1 parent d8ef812 commit b142a6c
Show file tree
Hide file tree
Showing 50 changed files with 286 additions and 1,520 deletions.
2 changes: 2 additions & 0 deletions bff-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ pub fn serialize_bits(_attr: TokenStream, input: TokenStream) -> TokenStream {
where
S: serde::Serializer,
{
use serde::ser::SerializeStruct;
use serde::Serialize;
let mut state = serializer.serialize_struct(#name_str, #field_count)?;
#(#serialize_fields)*
state.end()
Expand Down
11 changes: 3 additions & 8 deletions bff/src/class/animation/v1_381_67_09_pc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use serde::Serialize;

use crate::class::trivial_class::TrivialClass;
use crate::dynarray::DynArray;
use crate::name::Name;
use crate::link_header::ResourceObjectLinkHeader;
use crate::keyframer::{KeyframerFloatComp, KeyframerVec3fComp, KeyframerMessage, KeyframerRot, KeyframerBezierRot};

#[derive(BinRead, Debug, Serialize)]
Expand Down Expand Up @@ -64,12 +64,7 @@ struct Unknown14 {
}

#[derive(BinRead, Debug, Serialize)]
pub struct LinkHeader {
link_name: Name,
}

#[derive(BinRead, Debug, Serialize)]
#[br(import(_link_header: &LinkHeader))]
#[br(import(_link_header: &ResourceObjectLinkHeader))]
pub struct AnimationBodyV1_381_67_09PC {
duration: f32,
blending: f32,
Expand All @@ -85,4 +80,4 @@ pub struct AnimationBodyV1_381_67_09PC {
unknown15s: DynArray<Unknown14>,
}

pub type AnimationV1_381_67_09PC = TrivialClass<LinkHeader, AnimationBodyV1_381_67_09PC>;
pub type AnimationV1_381_67_09PC = TrivialClass<ResourceObjectLinkHeader, AnimationBodyV1_381_67_09PC>;
14 changes: 4 additions & 10 deletions bff/src/class/binary/v1_381_67_09_pc.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use bff_derive::serialize_bits;
use bilge::prelude::{bitsize, u12, u20, u4, Bitsized, DebugBits, Number};
use bilge::prelude::*;
use binrw::BinRead;
use serde::ser::SerializeStruct;
use serde::Serialize;

use crate::class::trivial_class::TrivialClass;
use crate::name::Name;
use crate::link_header::ResourceObjectLinkHeader;

#[serialize_bits]
#[bitsize(32)]
Expand Down Expand Up @@ -55,15 +54,10 @@ struct Internal {
}

#[derive(BinRead, Debug, Serialize)]
pub struct LinkHeader {
link_name: Name,
}

#[derive(BinRead, Debug, Serialize)]
#[br(import(_link_header: &LinkHeader))]
#[br(import(_link_header: &ResourceObjectLinkHeader))]
pub struct BinaryBodyV1_381_67_09PC {
data_size: u32,
data: Internal,
}

pub type BinaryV1_381_67_09PC = TrivialClass<LinkHeader, BinaryBodyV1_381_67_09PC>;
pub type BinaryV1_381_67_09PC = TrivialClass<ResourceObjectLinkHeader, BinaryBodyV1_381_67_09PC>;
75 changes: 3 additions & 72 deletions bff/src/class/camera/v1_381_67_09_pc.rs
Original file line number Diff line number Diff line change
@@ -1,85 +1,16 @@
use bff_derive::serialize_bits;
use bilge::prelude::{bitsize, u1, u15, Bitsized, DebugBits, Number};
use binrw::BinRead;
use serde::ser::SerializeStruct;
use serde::Serialize;

use crate::class::trivial_class::TrivialClass;
use crate::math::{Mat4f, Quat};
use crate::name::Name;

#[serialize_bits]
#[bitsize(32)]
#[derive(BinRead, DebugBits)]
struct ObjectFlags {
fl_object_init: u1,
fl_object_max_bsphere: u1,
fl_object_skinned: u1,
fl_object_morphed: u1,
fl_object_orientedbbox: u1,
fl_object_no_seaddisplay: u1,
fl_object_no_seadcollide: u1,
fl_object_no_display: u1,
fl_object_transparent: u1,
fl_object_optimized_vertex: u1,
fl_object_linear_mapping: u1,
fl_object_skinned_with_one_bone: u1,
fl_object_light_baked: u1,
fl_object_light_baked_with_material: u1,
fl_object_shadow_receiver: u1,
fl_object_no_tesselate: u1,
fl_object_last: u1,
padding: u15,
}

#[derive(BinRead, Debug, Serialize)]
#[br(repr = u16)]
enum ObjectType {
Points = 0,
Surface = 1,
Spline = 2,
Skin = 3,
RotShape = 4,
Lod = 5,
Mesh = 6,
Camera = 7,
SplineZone = 9,
Occluder = 10,
CameraZone = 11,
Light = 12,
HFog = 13,
CollisionVol = 14,
Emiter = 15,
Omni = 16,
Graph = 17,
Particles = 18,
Flare = 19,
HField = 20,
Tree = 21,
GenWorld = 22,
Road = 23,
GenWorldSurface = 24,
SplineGraph = 25,
WorldRef = 26,
}

#[derive(BinRead, Debug, Serialize)]
pub struct LinkHeader {
link_name: Name,
data_name: Name,
rot: Quat,
transform: Mat4f,
radius: f32,
flags: ObjectFlags,
r#type: ObjectType,
}
use crate::link_header::ObjectLinkHeaderV1_381_67_09PC;

#[derive(BinRead, Debug, Serialize)]
#[br(import(_link_header: &LinkHeader))]
#[br(import(_link_header: &ObjectLinkHeaderV1_381_67_09PC))]
pub struct CameraBodyV1_381_67_09PC {
angle_of_view: f32,
zero: f32,
node_name: Name,
}

pub type CameraV1_381_67_09PC = TrivialClass<LinkHeader, CameraBodyV1_381_67_09PC>;
pub type CameraV1_381_67_09PC = TrivialClass<ObjectLinkHeaderV1_381_67_09PC, CameraBodyV1_381_67_09PC>;
27 changes: 4 additions & 23 deletions bff/src/class/camera_zone/v1_06_63_02_pc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,8 @@ use serde::Serialize;

use crate::class::trivial_class::TrivialClass;
use crate::dynarray::DynArray;
use crate::math::{Mat, Sphere, Vec2f, Vec3f, Vec4f, RGBA};
use crate::name::Name;

#[derive(BinRead, Debug, Serialize)]
struct Box {
mat: Mat<3, 4>,
vec: Vec3f,
scale: f32,
}

#[derive(BinRead, Debug, Serialize)]
pub struct LinkInfo {
link_name: Name,
links: DynArray<u32>,
data_crc32: Name,
b_sphere_local: Sphere,
b_box: Box,
fade_out_distance: f32,
flags: u32,
r#type: u16,
}
use crate::link_header::ObjectLinkHeaderV1_06_63_02PC;
use crate::math::{Vec2f, Vec3f, Vec4f, RGBA};

#[derive(BinRead, Debug, Serialize)]
struct RangeSizeOffset {
Expand Down Expand Up @@ -94,12 +75,12 @@ struct ZoneTriggers {
}

#[derive(BinRead, Debug, Serialize)]
#[br(import(_link_header: &LinkInfo))]
#[br(import(_link_header: &ObjectLinkHeaderV1_06_63_02PC))]
pub struct CameraZoneBodyV1_06_63_02PC {
spline_zone: SplineZoneZ,
triggers: DynArray<Trigger>,
zone_triggers: DynArray<ZoneTriggers>,
trigger_ids: DynArray<u16>,
}

pub type CameraZoneV1_06_63_02PC = TrivialClass<LinkInfo, CameraZoneBodyV1_06_63_02PC>;
pub type CameraZoneV1_06_63_02PC = TrivialClass<ObjectLinkHeaderV1_06_63_02PC, CameraZoneBodyV1_06_63_02PC>;
19 changes: 4 additions & 15 deletions bff/src/class/collision_vol/v1_291_03_06_pc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,18 @@ use serde::Serialize;

use crate::class::trivial_class::TrivialClass;
use crate::dynarray::DynArray;
use crate::math::{Mat4f, Sphere};
use crate::link_header::ObjectLinkHeaderV1_06_63_02PC;
use crate::math::Mat4f;
use crate::name::Name;

#[derive(BinRead, Debug, Serialize)]
pub struct LinkInfo {
link_crc32: Name,
links: DynArray<Name>,
data_crc32: Name,
b_sphere_local: Sphere,
unknown_matrix: Mat4f,
fade_out_distance: f32,
flags: u32,
r#type: u16,
}

#[derive(BinRead, Debug, Serialize)]
struct CollisionVolInfo {
local_transform: Mat4f,
inv_local_transform: Mat4f,
}

#[derive(BinRead, Debug, Serialize)]
#[br(import(_link_header: &LinkInfo))]
#[br(import(_link_header: &ObjectLinkHeaderV1_06_63_02PC))]
pub struct CollisionVolBodyV1_291_03_06PC {
collision_vol_infos: DynArray<CollisionVolInfo>,
in_message_id: u32,
Expand All @@ -37,4 +26,4 @@ pub struct CollisionVolBodyV1_291_03_06PC {
anim_start_time: f32,
}

pub type CollisionVolV1_291_03_06PC = TrivialClass<LinkInfo, CollisionVolBodyV1_291_03_06PC>;
pub type CollisionVolV1_291_03_06PC = TrivialClass<ObjectLinkHeaderV1_06_63_02PC, CollisionVolBodyV1_291_03_06PC>;
76 changes: 4 additions & 72 deletions bff/src/class/collision_vol/v1_381_67_09_pc.rs
Original file line number Diff line number Diff line change
@@ -1,88 +1,20 @@
use bff_derive::serialize_bits;
use bilge::prelude::{bitsize, u1, u15, Bitsized, DebugBits, Number};
use binrw::BinRead;
use serde::ser::SerializeStruct;
use serde::Serialize;

use crate::class::trivial_class::TrivialClass;
use crate::dynarray::DynArray;
use crate::math::{Mat4f, Quat};
use crate::link_header::ObjectLinkHeaderV1_381_67_09PC;
use crate::math::Mat4f;
use crate::name::Name;

#[serialize_bits]
#[bitsize(32)]
#[derive(BinRead, DebugBits)]
struct ObjectFlags {
fl_object_init: u1,
fl_object_max_bsphere: u1,
fl_object_skinned: u1,
fl_object_morphed: u1,
fl_object_orientedbbox: u1,
fl_object_no_seaddisplay: u1,
fl_object_no_seadcollide: u1,
fl_object_no_display: u1,
fl_object_transparent: u1,
fl_object_optimized_vertex: u1,
fl_object_linear_mapping: u1,
fl_object_skinned_with_one_bone: u1,
fl_object_light_baked: u1,
fl_object_light_baked_with_material: u1,
fl_object_shadow_receiver: u1,
fl_object_no_tesselate: u1,
fl_object_last: u1,
padding: u15,
}

#[derive(BinRead, Debug, Serialize)]
#[br(repr = u16)]
enum ObjectType {
Points = 0,
Surface = 1,
Spline = 2,
Skin = 3,
RotShape = 4,
Lod = 5,
Mesh = 6,
Camera = 7,
SplineZone = 9,
Occluder = 10,
CameraZone = 11,
Light = 12,
HFog = 13,
CollisionVol = 14,
Emiter = 15,
Omni = 16,
Graph = 17,
Particles = 18,
Flare = 19,
HField = 20,
Tree = 21,
GenWorld = 22,
Road = 23,
GenWorldSurface = 24,
SplineGraph = 25,
WorldRef = 26,
}

#[derive(BinRead, Debug, Serialize)]
pub struct LinkHeader {
link_name: Name,
data_name: Name,
rot: Quat,
transform: Mat4f,
radius: f32,
flags: ObjectFlags,
r#type: ObjectType,
}

#[derive(BinRead, Debug, Serialize)]
struct CollisionVolInfo {
local_transform: Mat4f,
local_transform_inverse: Mat4f,
}

#[derive(BinRead, Debug, Serialize)]
#[br(import(_link_header: &LinkHeader))]
#[br(import(_link_header: &ObjectLinkHeaderV1_381_67_09PC))]
pub struct CollisionVolBodyV1_381_67_09PC {
collision_vol_info: DynArray<CollisionVolInfo>,
in_message_id: Name,
Expand All @@ -95,4 +27,4 @@ pub struct CollisionVolBodyV1_381_67_09PC {
delay: f32,
}

pub type CollisionVolV1_381_67_09PC = TrivialClass<LinkHeader, CollisionVolBodyV1_381_67_09PC>;
pub type CollisionVolV1_381_67_09PC = TrivialClass<ObjectLinkHeaderV1_381_67_09PC, CollisionVolBodyV1_381_67_09PC>;
10 changes: 3 additions & 7 deletions bff/src/class/fonts/v1_381_67_09_pc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use serde::Serialize;

use crate::class::trivial_class::TrivialClass;
use crate::dynarray::DynArray;
use crate::link_header::ResourceObjectLinkHeader;
use crate::map::BffMap;
use crate::math::Vec2f;
use crate::name::Name;
Expand All @@ -18,15 +19,10 @@ struct Character {
}

#[derive(BinRead, Debug, Serialize)]
pub struct LinkHeader {
link_name: Name,
}

#[derive(BinRead, Debug, Serialize)]
#[br(import(_link_header: &LinkHeader))]
#[br(import(_link_header: &ResourceObjectLinkHeader))]
pub struct FontsBodyV1_381_67_09PC {
characters: BffMap<CharacterID, Character>,
material_names: DynArray<Name>,
}

pub type FontsV1_381_67_09PC = TrivialClass<LinkHeader, FontsBodyV1_381_67_09PC>;
pub type FontsV1_381_67_09PC = TrivialClass<ResourceObjectLinkHeader, FontsBodyV1_381_67_09PC>;
10 changes: 3 additions & 7 deletions bff/src/class/game_obj/v1_381_67_09_pc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use serde::Serialize;

use crate::class::trivial_class::TrivialClass;
use crate::dynarray::DynArray;
use crate::link_header::ResourceObjectLinkHeader;
use crate::name::Name;
use crate::strings::PascalStringNull;

Expand All @@ -14,14 +15,9 @@ struct Prefab {
}

#[derive(BinRead, Debug, Serialize)]
pub struct LinkHeader {
link_name: Name,
}

#[derive(BinRead, Debug, Serialize)]
#[br(import(_link_header: &LinkHeader))]
#[br(import(_link_header: &ResourceObjectLinkHeader))]
pub struct GameObjBodyV1_381_67_09PC {
prefabs: DynArray<Prefab>,
}

pub type GameObjV1_381_67_09PC = TrivialClass<LinkHeader, GameObjBodyV1_381_67_09PC>;
pub type GameObjV1_381_67_09PC = TrivialClass<ResourceObjectLinkHeader, GameObjBodyV1_381_67_09PC>;
Loading

0 comments on commit b142a6c

Please sign in to comment.