wolfrpg_map_parser/command/set_variable_command/
db.rs

1use crate::byte_utils::{as_u16_le, as_u32_le};
2#[cfg(feature = "serde")]
3use serde::{Serialize, Deserialize};
4
5#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6#[derive(PartialEq, Clone)]
7#[allow(unused)]
8pub struct DB {
9    unknown1: u16,
10    db_type: u32,
11    db_data: u32,
12    db_field: u32,
13    unknown2: u16,
14}
15
16impl DB {
17    pub(crate) fn parse(bytes: &[u8]) -> (usize, Self) {
18        let mut offset = 0;
19
20        let unknown1: u16 = as_u16_le(&bytes[offset..offset + 2]);
21        offset += 2;
22
23        let db_type: u32 = as_u32_le(&bytes[offset..offset + 4]);
24        offset += 4;
25
26        let db_data: u32 = as_u32_le(&bytes[offset..offset + 4]);
27        offset += 4;
28
29        let db_field: u32 = as_u32_le(&bytes[offset..offset + 4]);
30        offset += 4;
31
32        let unknown2: u16 = as_u16_le(&bytes[offset..offset + 2]);
33        offset += 2;
34
35        offset += 1; // command end signature
36
37        (offset, Self {
38            unknown1,
39            db_type,
40            db_data,
41            db_field,
42            unknown2,
43        })
44    }
45
46    pub fn db_type(&self) -> u32 {
47        self.db_type
48    }
49
50    pub fn db_type_mut(&mut self) -> &mut u32 {
51        &mut self.db_type
52    }
53
54    pub fn db_data(&self) -> u32 {
55        self.db_data
56    }
57
58    pub fn db_data_mut(&mut self) -> &mut u32 {
59        &mut self.db_data
60    }
61
62    pub fn db_field(&self) -> u32 {
63        self.db_field
64    }
65
66    pub fn db_field_mut(&mut self) -> &mut u32 {
67        &mut self.db_field
68    }
69}