add a bit more data to inventory struct, unwrap globals since they always exist

This commit is contained in:
bgkillas 2025-07-21 19:31:01 -04:00
parent 84ac39abf6
commit 0519d6ed64
3 changed files with 106 additions and 94 deletions

View file

@ -109,11 +109,7 @@ impl ExtState {
pub fn ephemerial(entity_id: isize) -> eyre::Result<()> { pub fn ephemerial(entity_id: isize) -> eyre::Result<()> {
ExtState::with_global(|state| { ExtState::with_global(|state| {
if let Some(entity) = state if let Some(entity) = state.globals.entity_manager_mut().get_entity_mut(entity_id) {
.globals
.entity_manager_mut()
.and_then(|em| em.get_entity_mut(entity_id))
{
entity.filename_index = 0; entity.filename_index = 0;
} }
}) })

View file

@ -84,109 +84,121 @@ pub struct Globals {
} }
#[allow(clippy::mut_from_ref)] #[allow(clippy::mut_from_ref)]
impl Globals { impl Globals {
pub fn world_seed(&self) -> Option<usize> { pub fn world_seed(&self) -> usize {
unsafe { self.world_seed.as_ref().copied() } unsafe { self.world_seed.as_ref().copied().unwrap() }
} }
pub fn new_game_count(&self) -> Option<usize> { pub fn new_game_count(&self) -> usize {
unsafe { self.new_game_count.as_ref().copied() } unsafe { self.new_game_count.as_ref().copied().unwrap() }
} }
pub fn game_global(&self) -> Option<&'static GameGlobal> { pub fn game_global(&self) -> &'static GameGlobal {
unsafe { self.game_global.as_ref()?.as_ref() } unsafe { self.game_global.as_ref().unwrap().as_ref().unwrap() }
} }
pub fn entity_manager(&self) -> Option<&'static EntityManager> { pub fn entity_manager(&self) -> &'static EntityManager {
unsafe { self.entity_manager.as_ref()?.as_ref() } unsafe { self.entity_manager.as_ref().unwrap().as_ref().unwrap() }
} }
pub fn entity_tag_manager(&self) -> Option<&'static TagManager<u16>> { pub fn entity_tag_manager(&self) -> &'static TagManager<u16> {
unsafe { self.entity_tag_manager.as_ref()?.as_ref() } unsafe { self.entity_tag_manager.as_ref().unwrap().as_ref().unwrap() }
} }
pub fn component_type_manager(&self) -> Option<&'static ComponentTypeManager> { pub fn component_type_manager(&self) -> &'static ComponentTypeManager {
unsafe { self.component_type_manager.as_ref() } unsafe { self.component_type_manager.as_ref().unwrap() }
} }
pub fn component_tag_manager(&self) -> Option<&'static TagManager<u8>> { pub fn component_tag_manager(&self) -> &'static TagManager<u8> {
unsafe { self.component_tag_manager.as_ref()?.as_ref() } unsafe {
self.component_tag_manager
.as_ref()
.unwrap()
.as_ref()
.unwrap()
}
} }
pub fn translation_manager(&self) -> Option<&'static TranslationManager> { pub fn translation_manager(&self) -> &'static TranslationManager {
unsafe { self.translation_manager.as_ref() } unsafe { self.translation_manager.as_ref().unwrap() }
} }
pub fn platform(&self) -> Option<&'static Platform> { pub fn platform(&self) -> &'static Platform {
unsafe { self.platform.as_ref() } unsafe { self.platform.as_ref().unwrap() }
} }
pub fn global_stats(&self) -> Option<&'static GlobalStats> { pub fn global_stats(&self) -> &'static GlobalStats {
unsafe { self.global_stats.as_ref() } unsafe { self.global_stats.as_ref().unwrap() }
} }
pub fn filenames(&self) -> Option<&'static StdVec<StdString>> { pub fn filenames(&self) -> &'static StdVec<StdString> {
unsafe { self.filenames.as_ref() } unsafe { self.filenames.as_ref().unwrap() }
} }
pub fn wand_pickup(&self) -> Option<&'static Inventory> { pub fn wand_pickup(&self) -> &'static Inventory {
unsafe { self.wand_pickup.as_ref() } unsafe { self.wand_pickup.as_ref().unwrap() }
} }
pub fn world_seed_mut(&self) -> Option<&'static mut usize> { pub fn world_seed_mut(&self) -> &'static mut usize {
unsafe { self.world_seed.as_mut() } unsafe { self.world_seed.as_mut().unwrap() }
} }
pub fn new_game_count_mut(&self) -> Option<&'static mut usize> { pub fn new_game_count_mut(&self) -> &'static mut usize {
unsafe { self.new_game_count.as_mut() } unsafe { self.new_game_count.as_mut().unwrap() }
} }
pub fn game_global_mut(&self) -> Option<&'static mut GameGlobal> { pub fn game_global_mut(&self) -> &'static mut GameGlobal {
unsafe { self.game_global.as_ref()?.as_mut() } unsafe { self.game_global.as_ref().unwrap().as_mut().unwrap() }
} }
pub fn entity_manager_mut(&self) -> Option<&'static mut EntityManager> { pub fn entity_manager_mut(&self) -> &'static mut EntityManager {
unsafe { self.entity_manager.as_ref()?.as_mut() } unsafe { self.entity_manager.as_ref().unwrap().as_mut().unwrap() }
} }
pub fn entity_tag_manager_mut(&self) -> Option<&'static mut TagManager<u16>> { pub fn entity_tag_manager_mut(&self) -> &'static mut TagManager<u16> {
unsafe { self.entity_tag_manager.as_ref()?.as_mut() } unsafe { self.entity_tag_manager.as_ref().unwrap().as_mut().unwrap() }
} }
pub fn component_type_manager_mut(&self) -> Option<&'static mut ComponentTypeManager> { pub fn component_type_manager_mut(&self) -> &'static mut ComponentTypeManager {
unsafe { self.component_type_manager.as_mut() } unsafe { self.component_type_manager.as_mut().unwrap() }
} }
pub fn component_tag_manager_mut(&self) -> Option<&'static mut TagManager<u8>> { pub fn component_tag_manager_mut(&self) -> &'static mut TagManager<u8> {
unsafe { self.component_tag_manager.as_ref()?.as_mut() } unsafe {
self.component_tag_manager
.as_ref()
.unwrap()
.as_mut()
.unwrap()
}
} }
pub fn translation_manager_mut(&self) -> Option<&'static mut TranslationManager> { pub fn translation_manager_mut(&self) -> &'static mut TranslationManager {
unsafe { self.translation_manager.as_mut() } unsafe { self.translation_manager.as_mut().unwrap() }
} }
pub fn platform_mut(&self) -> Option<&'static mut Platform> { pub fn platform_mut(&self) -> &'static mut Platform {
unsafe { self.platform.as_mut() } unsafe { self.platform.as_mut().unwrap() }
} }
pub fn global_stats_mut(&self) -> Option<&'static mut GlobalStats> { pub fn global_stats_mut(&self) -> &'static mut GlobalStats {
unsafe { self.global_stats.as_mut() } unsafe { self.global_stats.as_mut().unwrap() }
} }
pub fn filenames_mut(&self) -> Option<&'static mut StdVec<StdString>> { pub fn filenames_mut(&self) -> &'static mut StdVec<StdString> {
unsafe { self.filenames.as_mut() } unsafe { self.filenames.as_mut().unwrap() }
} }
pub fn wand_pickup_mut(&self) -> Option<&'static mut Inventory> { pub fn wand_pickup_mut(&self) -> &'static mut Inventory {
unsafe { self.wand_pickup.as_mut() } unsafe { self.wand_pickup.as_mut().unwrap() }
} }
pub fn as_ref(&self) -> Option<GlobalsRef> { pub fn as_ref(&self) -> GlobalsRef {
Some(GlobalsRef { GlobalsRef {
world_seed: self.world_seed()?, world_seed: self.world_seed(),
new_game_count: self.new_game_count()?, new_game_count: self.new_game_count(),
game_global: self.game_global()?, game_global: self.game_global(),
entity_manager: self.entity_manager()?, entity_manager: self.entity_manager(),
entity_tag_manager: self.entity_tag_manager()?, entity_tag_manager: self.entity_tag_manager(),
component_type_manager: self.component_type_manager()?, component_type_manager: self.component_type_manager(),
component_tag_manager: self.component_tag_manager()?, component_tag_manager: self.component_tag_manager(),
translation_manager: self.translation_manager()?, translation_manager: self.translation_manager(),
platform: self.platform()?, platform: self.platform(),
global_stats: self.global_stats()?, global_stats: self.global_stats(),
filenames: self.filenames()?, filenames: self.filenames(),
wand_pickup: self.wand_pickup()?, wand_pickup: self.wand_pickup(),
}) }
} }
pub fn as_mut(&self) -> Option<GlobalsMut> { pub fn as_mut(&self) -> GlobalsMut {
Some(GlobalsMut { GlobalsMut {
world_seed: self.world_seed_mut()?, world_seed: self.world_seed_mut(),
new_game_count: self.new_game_count_mut()?, new_game_count: self.new_game_count_mut(),
game_global: self.game_global_mut()?, game_global: self.game_global_mut(),
entity_manager: self.entity_manager_mut()?, entity_manager: self.entity_manager_mut(),
entity_tag_manager: self.entity_tag_manager_mut()?, entity_tag_manager: self.entity_tag_manager_mut(),
component_type_manager: self.component_type_manager_mut()?, component_type_manager: self.component_type_manager_mut(),
component_tag_manager: self.component_tag_manager_mut()?, component_tag_manager: self.component_tag_manager_mut(),
translation_manager: self.translation_manager_mut()?, translation_manager: self.translation_manager_mut(),
platform: self.platform_mut()?, platform: self.platform_mut(),
global_stats: self.global_stats_mut()?, global_stats: self.global_stats_mut(),
filenames: self.filenames_mut()?, filenames: self.filenames_mut(),
wand_pickup: self.wand_pickup_mut()?, wand_pickup: self.wand_pickup_mut(),
}) }
} }
pub fn new(lua: LuaState) -> Self { pub fn new(lua: LuaState) -> Self {
lua.get_global(c"EntityGetFilename"); lua.get_global(c"EntityGetFilename");

View file

@ -409,17 +409,21 @@ pub struct Inventory {
unk1: isize, unk1: isize,
unk2: isize, unk2: isize,
unk3: isize, unk3: isize,
held_item: isize, pub held_item_id: isize,
unk5: isize, unk5: isize,
unk6: isize, unk6: isize,
unk7: isize, unk7b1: bool,
item_near: isize, unk7b2: bool,
unk9: isize, unk7b3: bool,
unk10: isize, padding: u8,
unk11: isize, pub item_near: isize,
unk12: isize, unk9b1: bool,
unk13: isize, unk9b2: bool,
wand_pickup: *mut Entity, unk9b3: bool,
unk15: isize, padding2: u8,
unk16: isize, unk10: [*mut isize; 3],
pub pickup_state: isize,
pub wand_pickup: *mut Entity,
unk14: isize,
unk15: [*mut [isize; 18]; 3],
} }