Skip to content

Commit

Permalink
Add new structs
Browse files Browse the repository at this point in the history
  • Loading branch information
Raytwo committed Apr 3, 2024
1 parent 5e2f0da commit 6f113e5
Show file tree
Hide file tree
Showing 7 changed files with 153 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/gamedata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use std::ops::Deref;
use unity::{prelude::*, system::ListFields};

pub mod accessory;
pub mod person;
pub mod skill;
pub mod job;
Expand Down
34 changes: 34 additions & 0 deletions src/gamedata/accessory.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
use unity::prelude::*;

use super::{Gamedata, StructBaseFields};

#[unity::class("App", "AccessoryData")]
pub struct AccessoryData {
pub parent: StructBaseFields,
pub aid: &'static Il2CppString,
pub name: &'static Il2CppString,
pub help: &'static Il2CppString,
pub name_m: &'static Il2CppString,
pub help_m: &'static Il2CppString,
pub name_f: &'static Il2CppString,
pub help_f: &'static Il2CppString,
pub first: bool,
pub amiibo: bool,
pub condition_cid: &'static Il2CppString,
pub condition_gender: i32,
pub condition_skills: &'static [Il2CppString; 0],
pub gid: &'static Il2CppString,
pub asset: &'static Il2CppString,
pub price: i32,
pub iron: i32,
pub steel: i32,
pub silver: i32,
pub mask: i32,
pub kind: i32,
pub god_data: u64,
pub flag_name: &'static Il2CppString,

// ...
}

impl Gamedata for AccessoryData { }
28 changes: 27 additions & 1 deletion src/gamedata/unit.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use unity::prelude::*;
use unity::il2cpp::object::*;
use crate::force::Force;
use crate::{force::Force, stream::Stream};
use crate::random::*;
use super::{JobData, WeaponMask, PersonData,
item::{UnitItemList, ItemData},
Expand Down Expand Up @@ -38,6 +38,32 @@ pub struct UnitBaseCapability {
pub capability: &'static mut Array<i8>,
}

#[unity::class("App", "UnitAccessory")]
pub struct UnitAccessory {
pub index: i32,
}

#[unity::from_offset("App", "UnitAccessory", "Serialize")]
extern "C" fn unitaccessory_serialize(this: &UnitAccessory, stream: &mut Stream, method_info: OptionalMethod);

#[unity::from_offset("App", "UnitAccessory", "Deserialize")]
extern "C" fn unitaccessory_deserialize(this: &mut UnitAccessory, stream: &Stream, method_info: OptionalMethod);

impl UnitAccessory {
pub fn serialize(&self, stream: &mut Stream) {
unsafe { unitaccessory_serialize(self, stream, None) };
}

pub fn deserialize(&mut self, stream: &Stream) {
unsafe { unitaccessory_deserialize(self, stream, None) }
}
}

#[unity::class("App", "UnitAccessoryList")]
pub struct UnitAccessoryList {
pub unit_accessory_array: &'static mut Il2CppArray<&'static mut UnitAccessory>
}

#[unity::class("App", "Unit")]
pub struct Unit {
pub status: &'static UnitStatus,
Expand Down
31 changes: 31 additions & 0 deletions src/gameicon.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
use unity::prelude::*;
use unity::engine::Sprite;

use crate::spriteatlasmanager::SpriteAtlasManager;

#[unity::class("App", "GameIcon")]
#[static_fields(GameIconStaticFields)]
pub struct GameIcon { }

impl GameIcon {
pub fn try_get_system<'a>(icon_name: impl Into<&'a Il2CppString>) -> Option<&'static mut Sprite> {
unsafe { gameicon_trygetsystem(icon_name.into(), None) }
}
}

pub struct GameIconStaticFields {
skill: SpriteAtlasManager,
item: SpriteAtlasManager,
efficacy: SpriteAtlasManager,
efficacy_outline: SpriteAtlasManager,
item_kinds: SpriteAtlasManager,
item_outline_kinds: SpriteAtlasManager,
god_symbol: SpriteAtlasManager,
god_ring: SpriteAtlasManager,
system: SpriteAtlasManager,
unit_icon_index: SpriteAtlasManager,
unit_icon_pallete: SpriteAtlasManager,
}

#[unity::from_offset("App", "GameIcon", "TryGetSystem")]
extern "C" fn gameicon_trygetsystem(icon_name: &Il2CppString, method_info: OptionalMethod) -> Option<&'static mut Sprite>;
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ pub mod eventsequence;
pub mod fade;
pub mod force;
pub mod gamedata;
pub mod gameicon;
pub mod gamemessage;
pub mod gametime;
pub mod gameuserdata;
Expand All @@ -26,6 +27,8 @@ pub mod resourcemanager;
pub mod script;
pub mod sequence;
pub mod singleton;
pub mod spriteatlasmanager;
pub mod stream;
pub mod titlebar;
pub mod tmpro;
pub mod uniticon;
Expand Down
6 changes: 6 additions & 0 deletions src/spriteatlasmanager.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#[unity::class("App", "SpriteAtlasManager")]
pub struct SpriteAtlasManager {
handle: i32,
spriteatlas: i32,
cachetable: i32,
}
51 changes: 51 additions & 0 deletions src/stream.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
use std::io;

use unity::prelude::*;

#[unity::class("App", "Stream")]
pub struct Stream {
buffer: &'static mut Il2CppArray<u8>,
position: i32,
stack: *const u8 ,
}

#[unity::from_offset("App", "Stream", "WriteInt")]
extern "C" fn stream_write_int(this: &mut Stream, data: i32, method_info: OptionalMethod);

#[unity::from_offset("App", "Stream", "ReadInt")]
extern "C" fn stream_read_int(this: &mut Stream, method_info: OptionalMethod) -> i32;

impl Stream {
pub fn get_position(&self) -> usize {
self.position as _
}

/// /!\ To be deprecated in favor of a std::io::Write implementation in due time.
///
/// Write a i32 into the stream and returns how many bytes were written.
/// An error of type WriteZero is returned if the buffer was too small to write the value.
///
/// While useless at the moment, this result type was chosen to facilitate migrating to proper Rust utilities later.
pub fn write_int(&mut self, data: i32) -> io::Result<usize> {
if self.buffer.len() >= self.get_position() + 4 {
unsafe { stream_write_int(self, data, None) }
Ok(4)
} else {
Err(io::Error::from(io::ErrorKind::WriteZero))
}
}

/// /!\ To be deprecated in favor of a std::io::Read implementation in due time.
///
/// Read a i32 from the stream and returns the value.
/// An error of type UnexpectedEof is returned if the buffer did not have enough bytes left to read the value.
///
/// While useless at the moment, this result type was chosen to facilitate migrating to proper Rust utilities later.
pub fn read_int(&mut self) -> io::Result<i32> {
if self.buffer.len() >= self.get_position() + 4 {
Ok(unsafe { stream_read_int(self, None) })
} else {
Err(io::Error::from(io::ErrorKind::UnexpectedEof))
}
}
}

0 comments on commit 6f113e5

Please sign in to comment.