Eein / sea-of-stars-tas

Rust implementation of SoS-TAS
MIT License
1 stars 0 forks source link

Add Transport object for class/process/module/singleton #35

Closed Eein closed 1 month ago

Eein commented 1 month ago

the files can get messy, and we want to return these items to the functions, so the proposal is a transport struct for these unwrapped values For example:

impl MemoryManagerUpdate for TitleSequenceManagerData {
    fn update(
        &mut self,
        ctx: &StateContext,
        manager: &mut UnityMemoryManager,
    ) -> Result<(), Error> {
        if let Some(class) = manager.class {
            if let Some(process) = &ctx.process {
                if let Some(module) = &ctx.module {
                    if let Some(singleton) = manager.singleton {
                        self.update_current_screen_name(ctx, manager)?;
                        self.update_title_menu(ctx, manager)?;
                        self.update_pressed_start(ctx, manager)?;
                        self.update_load_save_done(ctx, manager)?;
                        self.update_relics(ctx, manager)?;
                        self.update_new_game_characters(ctx, manager)?;
                    }
                }
            }
        }
        Ok(())
    }
}

could be:

impl MemoryManagerUpdate for TitleSequenceManagerData {
    fn update(
        &mut self,
        ctx: &StateContext,
        manager: &mut UnityMemoryManager,
    ) -> Result<(), Error> {
        let context = MemoryContext::create(manager, &ctx)?;

        self.update_current_screen_name(context)?;
        self.update_title_menu(context)?;
        self.update_pressed_start(context)?;
        self.update_load_save_done(context)?;
        self.update_relics(context)?;
        self.update_new_game_characters(context)?;

        Ok(())
    }
}
struct MemoryContext {
    class: Class,
    process: Process,
    module: Module,
    singleton: Class
}
impl MemoryContext {
    fn create(manager, & ctx) {
        if let Some(class) = manager.class {
            if let Some(process) = &ctx.process {
                if let Some(module) = &ctx.module {
                    if let Some(singleton) = manager.singleton {
                        Self { class, process, module, singleton }
                    }
                }
            }
        }
    }
orkaboy commented 1 month ago

Maybe add something to impl MemoryContext so we can read from it directly instead of using its members.