forked from DFHack/dfhack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGui.cpp
More file actions
125 lines (107 loc) · 3.07 KB
/
Copy pathGui.cpp
File metadata and controls
125 lines (107 loc) · 3.07 KB
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/*
www.sourceforge.net/projects/dfhack
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any
damages arising from the use of this software.
Permission is granted to anyone to use this software for any
purpose, including commercial applications, and to alter it and
redistribute it freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must
not claim that you wrote the original software. If you use this
software in a product, an acknowledgment in the product documentation
would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and
must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*/
#include "Internal.h"
#include "ContextShared.h"
#include "dfhack/modules/Gui.h"
#include "dfhack/DFProcess.h"
#include "dfhack/VersionInfo.h"
#include "dfhack/DFTypes.h"
using namespace DFHack;
struct Gui::Private
{
Private()
{
Started = PauseInited = ViewScreeInited = MenuStateInited = false;
}
bool Started;
uint32_t pause_state_offset;
bool PauseInited;
uint32_t view_screen_offset;
bool ViewScreeInited;
uint32_t current_menu_state_offset;
bool MenuStateInited;
DFContextShared *d;
Process * owner;
};
Gui::Gui(DFContextShared * _d)
{
d = new Private;
d->d = _d;
d->owner = _d->p;
OffsetGroup * OG_Gui = d->d->offset_descriptor->getGroup("GUI");
try
{
d->current_menu_state_offset = OG_Gui->getAddress("current_menu_state");
d->MenuStateInited = true;
}
catch(exception &){};
try
{
d->pause_state_offset = OG_Gui->getAddress ("pause_state");
d->PauseInited = true;
}
catch(exception &){};
try
{
d->view_screen_offset = OG_Gui->getAddress ("view_screen");
d->ViewScreeInited = true;
}
catch(exception &){};
d->Started = true;
}
Gui::~Gui()
{
delete d;
}
bool Gui::Start()
{
return true;
}
bool Gui::Finish()
{
return true;
}
bool Gui::ReadPauseState()
{
// replace with an exception
if(!d->PauseInited) return false;
uint32_t pauseState = d->owner->readDWord (d->pause_state_offset);
return pauseState & 1;
}
uint32_t Gui::ReadMenuState()
{
if(d->MenuStateInited)
return(d->owner->readDWord(d->current_menu_state_offset));
return false;
}
bool Gui::ReadViewScreen (t_viewscreen &screen)
{
if (!d->ViewScreeInited) return false;
Process * p = d->owner;
uint32_t last = p->readDWord (d->view_screen_offset);
uint32_t screenAddr = p->readDWord (last);
uint32_t nextScreenPtr = p->readDWord (last + 4);
while (nextScreenPtr != 0)
{
last = nextScreenPtr;
screenAddr = p->readDWord (nextScreenPtr);
nextScreenPtr = p->readDWord (nextScreenPtr + 4);
}
return d->d->offset_descriptor->resolveObjectToClassID (last, screen.type);
}