Skip to content

Commit d62c08f

Browse files
committed
Add label splicer for ProcDesc
1 parent 6faa21c commit d62c08f

2 files changed

Lines changed: 28 additions & 1 deletion

File tree

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "engage-il2cpp"
3-
version = "0.1.0"
3+
version = "0.1.1"
44
edition = "2021"
55
description = "Auto-generated Fire Emblem Engage IL2CPP type bindings. To be used with unity-nx."
66
license = "MPL-2.0"

src/ext.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,12 @@ mod proc_desc_patch {
437437
use unity::Array;
438438

439439
use crate::app::procdesc::ProcDesc;
440+
#[cfg(all(feature = "app-proc", feature = "app-procdesclabel"))]
441+
use ::unity::Cast;
442+
#[cfg(all(feature = "app-proc", feature = "app-procdesclabel"))]
443+
use crate::app::proc::Proc;
444+
#[cfg(all(feature = "app-proc", feature = "app-procdesclabel"))]
445+
use crate::app::procdesclabel::{IProcDescLabel, ProcDescLabel};
440446

441447
pub struct ProcDescPatch {
442448
original: Vec<ProcDesc>,
@@ -464,6 +470,27 @@ mod proc_desc_patch {
464470
Array::<ProcDesc>::from_slice(&self.original).expect("ProcDescPatch::finish: ProcDesc array allocation failed")
465471
}
466472
}
473+
474+
#[cfg(all(feature = "app-proc", feature = "app-procdesclabel"))]
475+
impl ProcDescPatch {
476+
fn next_free_label(&self) -> i32 {
477+
self.original
478+
.iter()
479+
.filter_map(|desc| desc.try_cast::<ProcDescLabel>())
480+
.map(|label| label.m_label())
481+
.max()
482+
.map(|highest| highest + 1)
483+
.unwrap_or(31)
484+
}
485+
486+
pub fn append_labeled_block(self, body: impl IntoIterator<Item = ProcDesc>) -> (Self, i32) {
487+
let label = self.next_free_label();
488+
let end = self.original.len();
489+
let mut block = std::vec![Proc::label(label)];
490+
block.extend(body);
491+
(self.insert(end, block), label)
492+
}
493+
}
467494
}
468495
#[cfg(feature = "app-procdesc")]
469496
pub use proc_desc_patch::*;

0 commit comments

Comments
 (0)