Skip to content

Commit

Permalink
power beam WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
toasterparty committed Jan 20, 2024
1 parent 6f0a912 commit 9e0d903
Show file tree
Hide file tree
Showing 8 changed files with 255 additions and 47 deletions.
Binary file added extra_assets/power_beam.PART
Binary file not shown.
Binary file added extra_assets/power_beam_accent.TXTR
Binary file not shown.
Binary file added extra_assets/power_beam_capsule.TXTR
Binary file not shown.
Binary file added extra_assets/power_beam_part.TXTR
Binary file not shown.
46 changes: 45 additions & 1 deletion src/bin/resource_tracing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -899,6 +899,50 @@ fn create_flamethrower(pickup_table: &mut HashMap<PickupModel, PickupData>)
}).is_none());
}

fn create_power_beam(pickup_table: &mut HashMap<PickupModel, PickupData>)
{
let mut bytes = Vec::new();
{
let mut pickup = Reader::new(&pickup_table[&PickupModel::IceBeam].bytes)
.read::<Pickup>(()).clone();
pickup.name = Cow::Borrowed(CStr::from_bytes_with_nul(b"Power Beam\0").unwrap());
pickup.cmdl = custom_asset_ids::POWER_BEAM_PICKUP_CMDL;
pickup.ancs.file_id = custom_asset_ids::POWER_BEAM_PICKUP_ANCS;
pickup.write_to(&mut bytes).unwrap();
}

let mut deps: HashSet<_> = pickup_table[&PickupModel::IceBeam].deps.iter()
.filter(|i| ![
// b"SCAN".into(),
// b"STRG".into(),
// b"CMDL".into(),
// b"ANCS".into(),
// b"PART".into(),
// b"ANIM".into(),
// b"EVNT".into(),
// b"TXTR".into(),
].contains(&i.fourcc))
.cloned()
.collect();

deps.extend(&[
ResourceKey::from(custom_asset_ids::POWER_BEAM_PICKUP_CMDL),
ResourceKey::from(custom_asset_ids::POWER_BEAM_PICKUP_ANCS),
ResourceKey::from(custom_asset_ids::POWER_BEAM_PART),
ResourceKey::from(custom_asset_ids::POWER_BEAM_EVNT),
ResourceKey::from(custom_asset_ids::POWER_BEAM_ANIM),
ResourceKey::from(custom_asset_ids::POWER_BEAM_PICKUP_TXTR1),
ResourceKey::from(custom_asset_ids::POWER_BEAM_PICKUP_TXTR2),
ResourceKey::from(custom_asset_ids::POWER_BEAM_PART_TXTR),
]);

assert!(pickup_table.insert(PickupModel::PowerBeam, PickupData {
bytes,
deps,
attainment_audio_file_name: b"/audio/jin_itemattain.dsp\0".to_vec(),
}).is_none());
}

fn create_combat_visor(pickup_table: &mut HashMap<PickupModel, PickupData>)
{
let mut bytes = Vec::new();
Expand Down Expand Up @@ -1362,7 +1406,7 @@ fn main()
create_xray_visor(&mut pickup_table);
create_combat_visor(&mut pickup_table);
create_flamethrower(&mut pickup_table);
// create_power_beam(&mut pickup_table);
create_power_beam(&mut pickup_table);

println!("// This file is generated by bin/resource_tracing.rs");
println!("");
Expand Down
104 changes: 103 additions & 1 deletion src/custom_assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ pub mod custom_asset_ids {
def_asset_ids! {
// Item Assets
PHAZON_SUIT_TXTR1: TXTR = 0xDEAF0000,
POWER_BEAM_PART_TXTR: TXTR = 0xDEAF0001, // we cheat and hard-code this in a PART that is loaded as an external asset, do not change
PHAZON_SUIT_TXTR2: TXTR,
PHAZON_SUIT_CMDL: CMDL,
PHAZON_SUIT_ANCS: ANCS,
Expand Down Expand Up @@ -88,6 +89,13 @@ pub mod custom_asset_ids {
FLAMETHROWER_PICKUP_TXTR1: TXTR,
FLAMETHROWER_PICKUP_TXTR2: TXTR,
FLAMETHROWER_PICKUP_TXTR3: TXTR,
POWER_BEAM_PICKUP_CMDL: CMDL,
POWER_BEAM_PICKUP_ANCS: ANCS,
POWER_BEAM_PICKUP_TXTR1: TXTR,
POWER_BEAM_PICKUP_TXTR2: TXTR,
POWER_BEAM_PART: PART,
POWER_BEAM_ANIM: ANIM,
POWER_BEAM_EVNT: EVNT,

// Custom Scans
SHORELINES_POI_SCAN: SCAN,
Expand Down Expand Up @@ -336,7 +344,6 @@ pub mod custom_asset_ids {
pub fn custom_asset_filename(resource_info: structs::ResourceInfo) -> String
{
let base_name = match resource_info.file_id {
// id if custom_asset_ids::PHAZON_SUIT_TXTR1.to_u32() == id => "phazon_suit_txtr1".to_string() ,
_ => format!("{:X}", resource_info.file_id),
};

Expand Down Expand Up @@ -417,6 +424,9 @@ fn extern_assets_compile_time<'r>() -> Vec<Resource<'r>>
extern_asset!(FLAMETHROWER_PICKUP_TXTR1 , "flamethrower_vertice_color.TXTR" ),
extern_asset!(FLAMETHROWER_PICKUP_TXTR2 , "flamethrower_cap_glow.TXTR" ),
extern_asset!(FLAMETHROWER_PICKUP_TXTR3 , "flamethrower_color_body.TXTR" ),
extern_asset!(POWER_BEAM_PICKUP_TXTR1 , "power_beam_capsule.TXTR" ),
extern_asset!(POWER_BEAM_PICKUP_TXTR2 , "power_beam_accent.TXTR" ),
extern_asset!(POWER_BEAM_PART_TXTR , "power_beam_part.TXTR" ),
extern_asset!(RANDOVANIA_GAMECUBE0_TXTR , "randovania_gamecube.TXTR" ),
extern_asset!(RANDOVANIA_GAMECUBE1_TXTR , "randovania_gamecube_text.TXTR" ),

Expand Down Expand Up @@ -608,6 +618,7 @@ pub fn custom_assets<'r>(

assets.extend_from_slice(&create_shiny_missile_assets(resources));
assets.extend_from_slice(&create_flamethrower_assets(resources));
assets.extend_from_slice(&create_power_beam_assets(resources));

assets.extend_from_slice(&create_ice_trap_icon_ancs(
resources,
Expand Down Expand Up @@ -1699,6 +1710,97 @@ fn create_flamethrower_assets<'r>(
[cmdl, ancs]
}

fn create_power_beam_assets<'r>(
resources: &HashMap<(u32, FourCC), structs::Resource<'r>>,
) -> [structs::Resource<'r>; 5]
{
let cmdl = {
let cmdl = ResourceData::new(
&resources[&resource_info!("Node1_18.CMDL").into()]
);
let cmdl_bytes = cmdl.decompress().into_owned();
let mut cmdl = Reader::new(&cmdl_bytes[..]).read::<structs::Cmdl>(());

cmdl.material_sets.as_mut_vec()[0].texture_ids.as_mut_vec()[0] = custom_asset_ids::POWER_BEAM_PICKUP_TXTR1;
cmdl.material_sets.as_mut_vec()[0].texture_ids.as_mut_vec()[1] = custom_asset_ids::POWER_BEAM_PICKUP_TXTR2;

let mut new_cmdl_bytes = vec![];
cmdl.write_to(&mut new_cmdl_bytes).unwrap();

build_resource(
custom_asset_ids::POWER_BEAM_PICKUP_CMDL,
structs::ResourceKind::External(new_cmdl_bytes, b"CMDL".into())
)
};

let ancs = {
let ancs = ResourceData::new(
&resources[&resource_info!("Node1_18.ANCS").into()]
);
let ancs_bytes = ancs.decompress().into_owned();
let mut ancs = Reader::new(&ancs_bytes[..]).read::<structs::Ancs>(());

ancs.char_set.char_info.as_mut_vec()[0].cmdl = custom_asset_ids::POWER_BEAM_PICKUP_CMDL;
ancs.char_set.char_info.as_mut_vec()[0].particles.part_assets.as_mut_vec()[0] = custom_asset_ids::POWER_BEAM_PART.to_u32(); // 0x9884086

match &mut ancs.anim_set.animations.as_mut_vec()[0].meta {
structs::MetaAnimation::Play(play) => {
play.get_mut().anim = custom_asset_ids::POWER_BEAM_ANIM;
}
_ => {panic!("ANIM wasn't PLAY")}
}

ancs.anim_set.animation_resources.as_mut().unwrap().as_mut_vec()[0].anim = custom_asset_ids::POWER_BEAM_ANIM;
ancs.anim_set.animation_resources.as_mut().unwrap().as_mut_vec()[0].evnt = custom_asset_ids::POWER_BEAM_EVNT;

let mut new_ancs_bytes = vec![];
ancs.write_to(&mut new_ancs_bytes).unwrap();

build_resource(
custom_asset_ids::POWER_BEAM_PICKUP_ANCS,
structs::ResourceKind::External(new_ancs_bytes, b"ANCS".into())
)
};

let part = {
let bytes = include_bytes!("../extra_assets/power_beam.PART");
build_resource(
custom_asset_ids::POWER_BEAM_PART,
structs::ResourceKind::External(bytes.to_vec(), b"PART".into())
)
};

let evnt = {
let mut evnt = resources[&resource_info!("IceBeam_ready.EVNT").into()]
.kind.as_evnt()
.unwrap().into_owned();

evnt.effect_events.as_mut_vec()[0].effect_file_id = custom_asset_ids::POWER_BEAM_PART.to_u32();

build_resource(
custom_asset_ids::POWER_BEAM_EVNT,
structs::ResourceKind::Evnt(evnt)
)
};

let anim = {
let anim = ResourceData::new(
&resources[&resource_info!("IceBeam_ready.ANIM").into()]
);

let mut bytes = anim.decompress().into_owned();

custom_asset_ids::POWER_BEAM_EVNT.write_to(&mut std::io::Cursor::new(&mut bytes[8..])).unwrap();

build_resource(
custom_asset_ids::POWER_BEAM_ANIM,
structs::ResourceKind::External(bytes, b"ANIM".into())
)
};

[cmdl, ancs, part, evnt, anim]
}

fn create_ice_trap_icon_ancs<'r>(
resources: &HashMap<(u32, FourCC), structs::Resource<'r>>,
new_cmdl_id: ResId<res_id::CMDL>,
Expand Down
5 changes: 4 additions & 1 deletion src/pickup_meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ pub enum PickupModel
IceSpreader,
Flamethrower,
FlamethrowerNew,
PowerBeam,
WaveBeam,
IceBeam,
PlasmaBeam,
Expand Down Expand Up @@ -396,6 +397,7 @@ impl PickupModel
PickupModel::IceSpreader => "Ice Spreader",
PickupModel::Flamethrower => "FlamethrowerOld",
PickupModel::FlamethrowerNew => "Flamethrower",
PickupModel::PowerBeam => "Power Beam",
PickupModel::WaveBeam => "Wave Beam",
PickupModel::IceBeam => "Ice Beam",
PickupModel::PlasmaBeam => "Plasma Beam",
Expand Down Expand Up @@ -464,6 +466,7 @@ impl PickupModel
PickupModel::IceSpreader,
PickupModel::Flamethrower,
PickupModel::FlamethrowerNew,
PickupModel::PowerBeam,
PickupModel::WaveBeam,
PickupModel::IceBeam,
PickupModel::PlasmaBeam,
Expand Down Expand Up @@ -538,7 +541,7 @@ impl PickupModel
*/
pub fn from_type(pickup_type: PickupType) -> Self {
match pickup_type {
PickupType::PowerBeam => PickupModel::RandovaniaGamecube,
PickupType::PowerBeam => PickupModel::PowerBeam,
PickupType::IceBeam => PickupModel::IceBeam,
PickupType::WaveBeam => PickupModel::WaveBeam,
PickupType::PlasmaBeam => PickupModel::PlasmaBeam,
Expand Down
Loading

0 comments on commit 9e0d903

Please sign in to comment.