Added mouse position and designation coord, along with a 'trackpos' command for kittens plugin.

develop
Petr Mrázek 2011-09-26 03:39:27 +02:00
parent edc86ce36b
commit a83d9fa944
4 changed files with 84 additions and 4 deletions

@ -795,8 +795,9 @@
<Address name="window_x" description="X coordinate of the current view (DWORD)" />
<Address name="window_y" description="Y coordinate of the current view (DWORD)" />
<Address name="window_z" description="Z coordinate of the current view (DWORD)" />
<Address name="cursor_xyz" description="Coordinates of the cursor (3xDWORD)." />
<Address name="mouse_pos" description="Position of the mouse (3xDWORD?)" />
<Address name="designation_xyz" description="Coordinates of first point of designation (3x int32_t, -30000 = invalid)." />
<Address name="cursor_xyz" description="Coordinates of the cursor (3x int32_t, -30000 = invalid)." />
<Address name="mouse_xy" description="Position of the mouse (2x int32_t, -1 = invalid)" />
<Address name="window_dims" description="Size of the view in tiles (2xWORD)" />
<Address name="screen_tiles_pointer" description="Pointer to the screen tile array." />
</Group>
@ -2262,6 +2263,10 @@
<Address name="interface" value="0x14f6070" />
<Address name="current_menu_state" value="0x14f5fac" />
</Group>
<Group name="Position">
<Address name="designation_xyz" value="0xb347fc" />
<Address name="mouse_xy" value="0xb35084" />
</Group>
<Group name="Creatures">
<Address name="current_race" value="0x14F0C28" />
<Group name="creature">
@ -3103,6 +3108,8 @@
</Group>
<Group name="Position" valid="true">
<Address name="cursor_xyz" value="0x8c3de60"/>
<Address name="designation_xyz" value="0x8c3de70" />
<Address name="mouse_xy" value="0x8c3e370" />
</Group>
<Group name="World">
<Address name="control_mode" value="0x8c3de90" />

@ -158,6 +158,11 @@ namespace DFHack
bool getCursorCoords (int32_t &x, int32_t &y, int32_t &z);
bool setCursorCoords (const int32_t x, const int32_t y, const int32_t z);
bool getDesignationCoords (int32_t &x, int32_t &y, int32_t &z);
bool setDesignationCoords (const int32_t x, const int32_t y, const int32_t z);
bool getMousePos (int32_t & x, int32_t & y);
/*
* Gui screens
*/

@ -50,6 +50,8 @@ struct Gui::Private
{
Started = false;
StartedScreen = false;
mouse_xy_offset = 0;
designation_xyz_offset = 0;
}
bool Started;
@ -57,6 +59,8 @@ struct Gui::Private
uint32_t window_y_offset;
uint32_t window_z_offset;
uint32_t cursor_xyz_offset;
uint32_t designation_xyz_offset;
uint32_t mouse_xy_offset;
uint32_t window_dims_offset;
bool StartedScreen;
@ -125,6 +129,8 @@ Gui::Gui()
d->Started = true;
}
catch(Error::All &){};
OG_Position->getSafeAddress("mouse_xy", d->mouse_xy_offset);
OG_Position->getSafeAddress("designation_xyz", d->designation_xyz_offset);
try
{
d->screen_tiles_ptr_offset = OG_Position->getAddress ("screen_tiles_pointer");
@ -210,6 +216,37 @@ bool Gui::setCursorCoords (const int32_t x, const int32_t y, const int32_t z)
return true;
}
bool Gui::getDesignationCoords (int32_t &x, int32_t &y, int32_t &z)
{
if(!d->designation_xyz_offset) return false;
int32_t coords[3];
d->owner->read (d->designation_xyz_offset, 3*sizeof (int32_t), (uint8_t *) coords);
x = coords[0];
y = coords[1];
z = coords[2];
if (x == -30000) return false;
return true;
}
bool Gui::setDesignationCoords (const int32_t x, const int32_t y, const int32_t z)
{
if(!d->designation_xyz_offset) return false;
int32_t coords[3] = {x, y, z};
d->owner->write (d->designation_xyz_offset, 3*sizeof (int32_t), (uint8_t *) coords);
return true;
}
bool Gui::getMousePos (int32_t & x, int32_t & y)
{
if(!d->mouse_xy_offset) return false;
int32_t coords[2];
d->owner->read (d->mouse_xy_offset, 2*sizeof (int32_t), (uint8_t *) coords);
x = coords[0];
y = coords[1];
if(x == -1) return false;
return true;
}
bool Gui::getWindowSize (int32_t &width, int32_t &height)
{
if(!d->Started) return false;

@ -17,6 +17,9 @@ bool shutdown_flag = false;
bool final_flag = true;
bool timering = false;
bool trackmenu_flg = false;
bool trackpos_flg = false;
int32_t last_designation[3] = {-30000, -30000, -30000};
int32_t last_mouse[2] = {-1, -1};
uint32_t last_menu = 0;
uint64_t timeLast = 0;
@ -24,6 +27,7 @@ DFhackCExport command_result kittens (Core * c, vector <string> & parameters);
DFhackCExport command_result ktimer (Core * c, vector <string> & parameters);
DFhackCExport command_result bflags (Core * c, vector <string> & parameters);
DFhackCExport command_result trackmenu (Core * c, vector <string> & parameters);
DFhackCExport command_result trackpos (Core * c, vector <string> & parameters);
DFhackCExport command_result mapitems (Core * c, vector <string> & parameters);
DFhackCExport command_result test_creature_offsets (Core * c, vector <string> & parameters);
DFhackCExport command_result creat_job (Core * c, vector <string> & parameters);
@ -40,6 +44,7 @@ DFhackCExport command_result plugin_init ( Core * c, std::vector <PluginCommand>
commands.push_back(PluginCommand("ktimer","Measure time between game updates and console lag (toggle).",ktimer));
commands.push_back(PluginCommand("blockflags","Look up block flags",bflags));
commands.push_back(PluginCommand("trackmenu","Track menu ID changes (toggle).",trackmenu));
commands.push_back(PluginCommand("trackpos","Track mouse and designation coords (toggle).",trackpos));
commands.push_back(PluginCommand("mapitems","Check item ids under cursor against item ids in map block.",mapitems));
commands.push_back(PluginCommand("test_creature_offsets","Bleh.",test_creature_offsets));
commands.push_back(PluginCommand("creat_job","Bleh.",creat_job));
@ -76,6 +81,28 @@ DFhackCExport command_result plugin_onupdate ( Core * c )
c->con.print("Menu: %d\n",last_menu);
}
}
if(trackpos_flg)
{
DFHack::Gui * g =c->getGui();
g->Start();
int32_t desig_x, desig_y, desig_z;
g->getDesignationCoords(desig_x,desig_y,desig_z);
if(desig_x != last_designation[0] || desig_y != last_designation[1] || desig_z != last_designation[2])
{
last_designation[0] = desig_x;
last_designation[1] = desig_y;
last_designation[2] = desig_z;
c->con.print("Designation: %d %d %d\n",desig_x, desig_y, desig_z);
}
int mouse_x, mouse_y;
g->getMousePos(mouse_x,mouse_y);
if(mouse_x != last_mouse[0] || mouse_y != last_mouse[1])
{
last_mouse[0] = mouse_x;
last_mouse[1] = mouse_y;
c->con.print("Mouse: %d %d\n",mouse_x, mouse_y);
}
}
return CR_OK;
}
@ -151,7 +178,11 @@ DFhackCExport command_result trackmenu (Core * c, vector <string> & parameters)
}
}
}
DFhackCExport command_result trackpos (Core * c, vector <string> & parameters)
{
trackpos_flg = !trackpos_flg;
return CR_OK;
}
DFhackCExport command_result bflags (Core * c, vector <string> & parameters)
{
c->Suspend();