Skip to content

Commit

Permalink
use name map
Browse files Browse the repository at this point in the history
  • Loading branch information
bananaturtlesandwich committed Jul 31, 2023
1 parent 1fe3385 commit 9885463
Show file tree
Hide file tree
Showing 5 changed files with 131 additions and 67 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "blue-fire-rando"
description = "a gamemode for blue fire which shuffles pickups"
repository = "https://github.com/bananaturtlesandwich/blue-fire-rando"
version = "1.1.2"
version = "1.1.3"
authors = ["spuds"]
edition = "2021"

Expand Down
41 changes: 22 additions & 19 deletions src/map/transform.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use unreal_asset::{
exports::ExportNormalTrait,
// exports::*,
properties::{struct_property::StructProperty, vector_property::VectorProperty, *},
types::{fname::FName, vector::Vector},
types::vector::Vector,
*,
};

Expand Down Expand Up @@ -46,6 +45,7 @@ pub fn set_location<C: std::io::Read + std::io::Seek>(
new: Vector<f64>,
offset: (f64, f64, f64),
) {
let mut name_map = asset.get_name_map();
let (x, y, z) = offset;
let Some(transform) = get_transform_index(index, asset) else {
return
Expand All @@ -67,28 +67,31 @@ pub fn set_location<C: std::io::Read + std::io::Seek>(
}
}
}
None => norm
.properties
.push(Property::StructProperty(StructProperty {
name: FName::from_slice("RelativeLocation"),
ancestry: unversioned::ancestry::Ancestry {
ancestry: Vec::new(),
},
struct_type: Some(FName::from_slice("Vector")),
struct_guid: None,
property_guid: None,
duplication_index: 0,
serialize_none: true,
value: vec![Property::VectorProperty(VectorProperty {
name: FName::from_slice("RelativeLocation"),
None => {
let name = name_map.get_mut().add_fname("RelativeLocation");
let struct_type = Some(name_map.clone_resource().get_mut().add_fname("Vector"));
norm.properties
.push(Property::StructProperty(StructProperty {
name,
ancestry: unversioned::ancestry::Ancestry {
ancestry: Vec::new(),
},
struct_type,
struct_guid: None,
property_guid: None,
duplication_index: 0,
value: Vector::new(new.x.into(), new.y.into(), new.z.into()),
})],
})),
serialize_none: true,
value: vec![Property::VectorProperty(VectorProperty {
name: name_map.get_mut().add_fname("RelativeLocation"),
ancestry: unversioned::ancestry::Ancestry {
ancestry: Vec::new(),
},
property_guid: None,
duplication_index: 0,
value: Vector::new(new.x.into(), new.y.into(), new.z.into()),
})],
}));
}
}
}

Expand Down
66 changes: 50 additions & 16 deletions src/writing.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::logic::*;
use crate::{io::*, map::*};
use unreal_asset::{exports::*, properties::*, types::fname::FName, *};
use unreal_asset::{exports::*, properties::*, *};

mod cutscenes;
mod overworld;
Expand Down Expand Up @@ -45,19 +45,27 @@ fn extract(
Ok((open(&loc)?, loc))
}

fn byte_property(name: &str, enum_type: &str, val: &str) -> Property {
fn byte_property(
name: &str,
enum_ty: &str,
val: &str,
name_map: &mut containers::shared_resource::SharedResource<asset::name_map::NameMap>,
) -> Property {
let name = name_map.get_mut().add_fname(name);
let enum_type = Some(name_map.get_mut().add_fname(enum_ty));
Property::ByteProperty(int_property::ByteProperty {
name: FName::from_slice(name),
name,
ancestry: unversioned::ancestry::Ancestry {
ancestry: Vec::new(),
},
property_guid: None,
duplication_index: 0,
enum_type: Some(FName::from_slice(enum_type)),
value: int_property::BytePropertyValue::FName(FName::new_dummy(
format!("{}::NewEnumerator{}", enum_type, val),
0,
)),
enum_type,
value: int_property::BytePropertyValue::FName(
name_map
.get_mut()
.add_fname(&format!("{}::NewEnumerator{}", enum_ty, val)),
),
})
}

Expand All @@ -66,6 +74,7 @@ fn set_byte(
enum_type: &str,
val: &str,
export: &mut normal_export::NormalExport,
name_map: &mut containers::shared_resource::SharedResource<asset::name_map::NameMap>,
) -> Result<(), Error> {
match export
.properties
Expand All @@ -74,10 +83,13 @@ fn set_byte(
{
Some(byte) => {
use int_property::BytePropertyValue;
*cast!(BytePropertyValue, FName, &mut byte.value).ok_or(Error::Assumption)? =
FName::new_dummy(format!("{}::NewEnumerator{}", enum_type, val), 0)
*cast!(BytePropertyValue, FName, &mut byte.value).ok_or(Error::Assumption)? = name_map
.get_mut()
.add_fname(&format!("{}::NewEnumerator{}", enum_type, val))
}
None => export.properties.push(byte_property(name, enum_type, val)),
None => export
.properties
.push(byte_property(name, enum_type, val, name_map)),
}
Ok(())
}
Expand Down Expand Up @@ -233,7 +245,23 @@ fn create_hook<C: std::io::Read + std::io::Seek>(
}

impl Drop {
pub fn as_shop_entry(&self, price: i32) -> Vec<unreal_asset::properties::Property> {
pub fn as_shop_entry(
&self,
price: i32,
name_map: &mut containers::shared_resource::SharedResource<asset::name_map::NameMap>,
) -> Vec<unreal_asset::properties::Property> {
let amount_name = name_map
.get_mut()
.add_fname("Amount_6_185C591747EF40A592FB63886FDB4281");
let resets_name = name_map
.get_mut()
.add_fname("Resets_8_E303F5DF4270CCEE83F05F974F3661C9");
let original_amounts_name = name_map
.get_mut()
.add_fname("OriginalAmount_11_58C3C17D426D49A439C0EE85D7E9B6EC");
let price_name = name_map
.get_mut()
.add_fname("Price_26_80A37F3645AE8292A9F311B86094C095");
use int_property::*;
[
byte_property(
Expand All @@ -245,9 +273,10 @@ impl Drop {
Drop::Duck => Items::Duck.as_ref(),
_ => "25",
},
name_map,
),
Property::IntProperty(IntProperty {
name: FName::from_slice("Amount_6_185C591747EF40A592FB63886FDB4281"),
name: amount_name,
ancestry: unversioned::ancestry::Ancestry {
ancestry: Vec::new(),
},
Expand All @@ -260,7 +289,7 @@ impl Drop {
},
}),
Property::BoolProperty(BoolProperty {
name: FName::from_slice("Resets_8_E303F5DF4270CCEE83F05F974F3661C9"),
name: resets_name,
ancestry: unversioned::ancestry::Ancestry {
ancestry: Vec::new(),
},
Expand All @@ -269,7 +298,7 @@ impl Drop {
value: false,
}),
Property::IntProperty(IntProperty {
name: FName::from_slice("OriginalAmount_11_58C3C17D426D49A439C0EE85D7E9B6EC"),
name: original_amounts_name,
ancestry: unversioned::ancestry::Ancestry {
ancestry: Vec::new(),
},
Expand All @@ -284,6 +313,7 @@ impl Drop {
"Type_17_9B84CFD04716464F71190CB4CECE0F49",
"InventoryItemType",
self.as_ref(),
name_map,
),
byte_property(
"Tunic_23_B7D465CA4DCF57F409450789A6DB8590",
Expand All @@ -293,6 +323,7 @@ impl Drop {
} else {
"0"
},
name_map,
),
byte_property(
"Weapon_22_F3B61F384438EE8A8193F385AE45F88A",
Expand All @@ -302,6 +333,7 @@ impl Drop {
} else {
"0"
},
name_map,
),
byte_property(
"Spirit_21_55691F2E4B399DB3F381209D33BBE30B",
Expand All @@ -311,9 +343,10 @@ impl Drop {
} else {
"0"
},
name_map,
),
Property::IntProperty(IntProperty {
name: FName::from_slice("Price_26_80A37F3645AE8292A9F311B86094C095"),
name: price_name,
ancestry: unversioned::ancestry::Ancestry {
ancestry: Vec::new(),
},
Expand All @@ -333,6 +366,7 @@ impl Drop {
} else {
"0"
},
name_map,
),
]
.to_vec()
Expand Down
38 changes: 22 additions & 16 deletions src/writing/overworld.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub fn write(
|(location, checks)| -> Result<std::thread::ScopedJoinHandle<Result<(), Error>>, Error> {
Ok(thread.spawn(move || {
let (mut map, loc) = extract(app, pak, &format!("{PREFIX}{location}.umap"))?;
let mut name_map = map.get_name_map();
for Check { context, drop, .. } in checks {
match context {
Context::Shop(shop, index, ..) => {
Expand Down Expand Up @@ -50,11 +51,11 @@ pub fn write(
.value
)
.ok_or(Error::Assumption)?
= FName::new_dummy(format!("E_Emotes::NewEnumerator{}", emote.as_ref()), 0);
= name_map.get_mut().add_fname(&format!("E_Emotes::NewEnumerator{}", emote.as_ref()));
}
if let Drop::Ability(ability) = drop {
set_byte("Ability", "Abilities", ability.as_ref(), norm)?;
set_byte("Type", "InventoryItemType", drop.as_ref(), norm)?;
set_byte("Ability", "Abilities", ability.as_ref(), norm, &mut name_map)?;
set_byte("Type", "InventoryItemType", drop.as_ref(), norm, &mut name_map)?;
}
cast!(
Property,
Expand Down Expand Up @@ -146,7 +147,7 @@ pub fn write(
Some(id) => id.value = Some(format!("{name}{counter}")),
None => norm.properties.push(Property::StrProperty(
str_property::StrProperty {
name: FName::from_slice("ID"),
name: name_map.get_mut().add_fname("ID"),
ancestry: unversioned::ancestry::Ancestry { ancestry: Vec::new() },
property_guid: None,
duplication_index: 0,
Expand All @@ -170,8 +171,9 @@ pub fn write(
"InventoryItemType",
drop.as_ref(),
chest,
&mut name_map
)?;
set_byte("Item", "Items", item.as_ref(), chest)?;
set_byte("Item", "Items", item.as_ref(), chest, &mut name_map)?;
match chest.properties.iter_mut().find_map(|prop| {
cast!(Property, BoolProperty, prop)
.filter(|bool| bool.name == "KeyItem")
Expand All @@ -180,7 +182,7 @@ pub fn write(
None if item.key_item() => {
chest.properties.push(Property::BoolProperty(
int_property::BoolProperty {
name: FName::from_slice("KeyItem"),
name: name_map.get_mut().add_fname("KeyItem"),
ancestry: unversioned::ancestry::Ancestry { ancestry: Vec::new() },
property_guid: None,
duplication_index: 0,
Expand All @@ -197,7 +199,7 @@ pub fn write(
Some(num) => num.value = *amount,
None => chest.properties.push(Property::IntProperty(
int_property::IntProperty {
name: FName::from_slice("Amount"),
name: name_map.get_mut().add_fname("Amount"),
ancestry: unversioned::ancestry::Ancestry { ancestry: Vec::new() },
property_guid: None,
duplication_index: 0,
Expand All @@ -218,8 +220,9 @@ pub fn write(
"InventoryItemType",
drop.as_ref(),
chest,
&mut name_map
)?;
set_byte("Weapon", "Weapons", weapon.as_ref(), chest)?;
set_byte("Weapon", "Weapons", weapon.as_ref(), chest, &mut name_map)?;
}
Drop::Tunic(tunic) => {
if !is_chest() {
Expand All @@ -233,8 +236,9 @@ pub fn write(
"InventoryItemType",
drop.as_ref(),
chest,
&mut name_map
)?;
set_byte("Tunic", "Tunics", tunic.as_ref(), chest)?;
set_byte("Tunic", "Tunics", tunic.as_ref(), chest, &mut name_map)?;
}
Drop::Spirit(spirit) if is_chest() => {
let chest = map.asset_data.exports[i]
Expand All @@ -245,8 +249,9 @@ pub fn write(
"InventoryItemType",
drop.as_ref(),
chest,
&mut name_map
)?;
set_byte("Amulet", "Spirits", spirit.as_ref(), chest)?;
set_byte("Amulet", "Spirits", spirit.as_ref(), chest, &mut name_map)?;
}
Drop::Spirit(spirit) => {
if class != "Spirit_C" {
Expand All @@ -255,7 +260,7 @@ pub fn write(
let spirit_bp = map.asset_data.exports[i]
.get_normal_export_mut()
.ok_or(Error::Assumption)?;
set_byte("Amulet", "Spirits", spirit.as_ref(), spirit_bp)?;
set_byte("Amulet", "Spirits", spirit.as_ref(), spirit_bp, &mut name_map)?;
}
Drop::Ability(ability) => {
if !is_chest() {
Expand All @@ -269,8 +274,9 @@ pub fn write(
"InventoryItemType",
drop.as_ref(),
chest,
&mut name_map
)?;
set_byte("Ability", "Abilities", ability.as_ref(), chest)?;
set_byte("Ability", "Abilities", ability.as_ref(), chest, &mut name_map)?;
}
Drop::Emote(emote) => {
if class != "EmoteStatue_BP_C" {
Expand All @@ -279,7 +285,7 @@ pub fn write(
let statue = map.asset_data.exports[i]
.get_normal_export_mut()
.ok_or(Error::Assumption)?;
set_byte("Emote", "E_Emotes", emote.as_ref(), statue)?;
set_byte("Emote", "E_Emotes", emote.as_ref(), statue, &mut name_map)?;
}
Drop::Ore(amount) => {
if class != "Pickup_C" {
Expand All @@ -288,7 +294,7 @@ pub fn write(
let pickup = map.asset_data.exports[i]
.get_normal_export_mut()
.ok_or(Error::Assumption)?;
set_byte("Type", "PickUpList", "5", pickup)?;
set_byte("Type", "PickUpList", "5", pickup, &mut name_map)?;
match pickup.properties.iter_mut().find_map(|prop| {
cast!(Property, IntProperty, prop).filter(|amount| {
amount.name == "Souls/LifeAmount"
Expand All @@ -297,8 +303,8 @@ pub fn write(
Some(num) => num.value = *amount,
None => pickup.properties.push(Property::IntProperty(
int_property::IntProperty {
name: FName::from_slice("Souls/LifeAmount"),
ancestry: unversioned::ancestry::Ancestry { ancestry: Vec::new() },
name: name_map.get_mut().add_fname("Souls/LifeAmount"),
ancestry: unversioned::ancestry::Ancestry { ancestry: Vec::new() },
property_guid: None,
duplication_index: 0,
value: *amount,
Expand Down
Loading

0 comments on commit 9885463

Please sign in to comment.