hex_patch/app/plugins/ui_location/
ui_location_info.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
use mlua::IntoLua;

#[derive(Debug, Clone, PartialEq, Eq)]
pub enum UiLocationInfo {
    AddressView {
        file_address: Option<u64>,
    },
    HexView {
        file_address: Option<u64>,
        high: Option<bool>,
        virtual_address: Option<u64>,
        byte: Option<u8>,
    },
    TextView {
        file_address: Option<u64>,
        virtual_address: Option<u64>,
        byte: Option<u8>,
        character: Option<char>,
    },
    AssemblyView {
        section: Option<String>,
        file_address: Option<u64>,
        virtual_address: Option<u64>,
        instruction: Option<String>,
    },
    StatusBar,
    ScrollBar,
    Popup {
        name: String,
    },
}

impl IntoLua for UiLocationInfo {
    fn into_lua(self, lua: &mlua::Lua) -> mlua::Result<mlua::Value> {
        let ret = lua.create_table()?;
        match self {
            UiLocationInfo::AddressView { file_address } => {
                ret.set("type", "AddressView")?;
                ret.set("file_address", file_address)?;
            }
            UiLocationInfo::HexView {
                file_address,
                high,
                virtual_address,
                byte,
            } => {
                ret.set("type", "HexView")?;
                ret.set("file_address", file_address)?;
                ret.set("high", high)?;
                ret.set("virtual_address", virtual_address)?;
                ret.set("byte", byte)?;
            }
            UiLocationInfo::TextView {
                file_address,
                virtual_address,
                byte,
                character,
            } => {
                ret.set("type", "TextView")?;
                ret.set("file_address", file_address)?;
                ret.set("virtual_address", virtual_address)?;
                ret.set("byte", byte)?;
                ret.set("character", character.map(|c| c.to_string()))?;
            }
            UiLocationInfo::AssemblyView {
                section,
                file_address,
                virtual_address,
                instruction,
            } => {
                ret.set("type", "AssemblyView")?;
                ret.set("section", section)?;
                ret.set("file_address", file_address)?;
                ret.set("virtual_address", virtual_address)?;
                ret.set("instruction", instruction)?;
            }
            UiLocationInfo::StatusBar => {
                ret.set("type", "StatusBar")?;
            }
            UiLocationInfo::ScrollBar => {
                ret.set("type", "ScrollBar")?;
            }
            UiLocationInfo::Popup { name } => {
                ret.set("type", "Popup")?;
                ret.set("name", name)?;
            }
        }
        Ok(mlua::Value::Table(ret))
    }
}