more cleanup

develop
Petr Mrázek 2009-12-13 00:47:58 +00:00
parent 58986ef838
commit 069597f10c
12 changed files with 60 additions and 289 deletions

@ -62,11 +62,6 @@ using namespace std;
#include <sys/stat.h> #include <sys/stat.h>
#include <fcntl.h> #include <fcntl.h>
#include <sys/wait.h> #include <sys/wait.h>
#include <X11/Xlib.h> //need for X11 functions
#include <X11/extensions/XTest.h> //need for Xtest
#include <X11/Xatom.h> //for the atom stuff
#define XK_MISCELLANY
#include <X11/keysymdef.h>
#else #else
#define _WIN32_WINNT 0x0500 // needed for INPUT struct #define _WIN32_WINNT 0x0500 // needed for INPUT struct
#define WINVER 0x0500 // OpenThread(), PSAPI, Toolhelp32 #define WINVER 0x0500 // OpenThread(), PSAPI, Toolhelp32

@ -21,8 +21,14 @@ must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source 3. This notice may not be removed or altered from any source
distribution. distribution.
*/ */
#define LINUX_BUILD
#include "DFCommonInternal.h" #include "DFCommonInternal.h"
#include <X11/Xlib.h> //need for X11 functions
#include <X11/extensions/XTest.h> //need for Xtest
#include <X11/Xatom.h> //for the atom stuff
#define XK_MISCELLANY
#include <X11/keysymdef.h>
using namespace DFHack; using namespace DFHack;
// ENUMARATE THROUGH WINDOWS AND DISPLAY THEIR TITLES // ENUMARATE THROUGH WINDOWS AND DISPLAY THEIR TITLES
@ -232,389 +238,154 @@ void API::TypeSpecial (t_special command, int count, int delay)
{ {
case ENTER: case ENTER:
mykeysym = XStringToKeysym ("Return"); mykeysym = XStringToKeysym ("Return");
xkeycode = XKeysymToKeycode (dpy, mykeysym);
XTestFakeKeyEvent (dpy, xkeycode, true, CurrentTime);
XSync (dpy, true);
XTestFakeKeyEvent (dpy, xkeycode, false, CurrentTime);
XSync (dpy, true);
break; break;
case SPACE: case SPACE:
mykeysym = XStringToKeysym ("space"); mykeysym = XStringToKeysym ("space");
xkeycode = XKeysymToKeycode (dpy, mykeysym);
XTestFakeKeyEvent (dpy, xkeycode, true, CurrentTime);
XSync (dpy, true);
XTestFakeKeyEvent (dpy, xkeycode, false, CurrentTime);
XSync (dpy, true);
break; break;
case BACK_SPACE: case BACK_SPACE:
mykeysym = XStringToKeysym ("BackSpace"); mykeysym = XStringToKeysym ("BackSpace");
xkeycode = XK_BackSpace;
xkeycode = XKeysymToKeycode (dpy, XK_BackSpace);
XTestFakeKeyEvent (dpy, xkeycode, true, CurrentTime);
XSync (dpy, true);
XTestFakeKeyEvent (dpy, xkeycode, false, CurrentTime);
XSync (dpy, true);
break; break;
case TAB: case TAB:
mykeysym = XStringToKeysym ("Tab"); mykeysym = XStringToKeysym ("Tab");
xkeycode = XKeysymToKeycode (dpy, mykeysym);
XTestFakeKeyEvent (dpy, xkeycode, true, CurrentTime);
XSync (dpy, true);
XTestFakeKeyEvent (dpy, xkeycode, false, CurrentTime);
XSync (dpy, true);
break; break;
case CAPS_LOCK: case CAPS_LOCK:
mykeysym = XStringToKeysym ("Caps_Lock"); mykeysym = XStringToKeysym ("Caps_Lock");
xkeycode = XKeysymToKeycode (dpy, mykeysym);
XTestFakeKeyEvent (dpy, xkeycode, true, CurrentTime);
XSync (dpy, true);
XTestFakeKeyEvent (dpy, xkeycode, false, CurrentTime);
XSync (dpy, true);
break; break;
case LEFT_SHIFT: // I am not positive that this will work to distinguish the left and right.. case LEFT_SHIFT:
mykeysym = XStringToKeysym ("Shift_L"); mykeysym = XStringToKeysym ("Shift_L");
xkeycode = XKeysymToKeycode (dpy, mykeysym);
XTestFakeKeyEvent (dpy, xkeycode, true, CurrentTime);
XSync (dpy, true);
XTestFakeKeyEvent (dpy, xkeycode, false, CurrentTime);
XSync (dpy, true);
break; break;
case RIGHT_SHIFT: case RIGHT_SHIFT:
mykeysym = XStringToKeysym ("Shift_R"); mykeysym = XStringToKeysym ("Shift_R");
xkeycode = XKeysymToKeycode (dpy, mykeysym);
XTestFakeKeyEvent (dpy, xkeycode, true, CurrentTime);
XSync (dpy, true);
XTestFakeKeyEvent (dpy, xkeycode, false, CurrentTime);
XSync (dpy, true);
break; break;
case LEFT_CONTROL: case LEFT_CONTROL:
mykeysym = XStringToKeysym ("Control_L"); mykeysym = XStringToKeysym ("Control_L");
xkeycode = XKeysymToKeycode (dpy, mykeysym); break;
XTestFakeKeyEvent (dpy, xkeycode, true, CurrentTime);
XSync (dpy, true);
XTestFakeKeyEvent (dpy, xkeycode, false, CurrentTime);
XSync (dpy, true);
case RIGHT_CONTROL: case RIGHT_CONTROL:
mykeysym = XStringToKeysym ("Control_R"); mykeysym = XStringToKeysym ("Control_R");
xkeycode = XKeysymToKeycode (dpy, mykeysym);
XTestFakeKeyEvent (dpy, xkeycode, true, CurrentTime);
XSync (dpy, true);
XTestFakeKeyEvent (dpy, xkeycode, false, CurrentTime);
XSync (dpy, true);
break; break;
case ALT: case ALT:
mykeysym = XStringToKeysym ("Alt_L"); mykeysym = XStringToKeysym ("Alt_L");
xkeycode = XKeysymToKeycode (dpy, mykeysym);
XTestFakeKeyEvent (dpy, xkeycode, true, CurrentTime);
XSync (dpy, true);
XTestFakeKeyEvent (dpy, xkeycode, false, CurrentTime);
XSync (dpy, true);
break; break;
case ESCAPE: case ESCAPE:
mykeysym = XStringToKeysym ("Escape"); mykeysym = XStringToKeysym ("Escape");
xkeycode = XKeysymToKeycode (dpy, mykeysym);
XTestFakeKeyEvent (dpy, xkeycode, true, CurrentTime);
XSync (dpy, true);
XTestFakeKeyEvent (dpy, xkeycode, false, CurrentTime);
XSync (dpy, true);
break; break;
case UP: case UP:
mykeysym = XStringToKeysym ("Up"); mykeysym = XStringToKeysym ("Up");
xkeycode = XKeysymToKeycode (dpy, mykeysym);
XTestFakeKeyEvent (dpy, xkeycode, true, CurrentTime);
XSync (dpy, true);
XTestFakeKeyEvent (dpy, xkeycode, false, CurrentTime);
XSync (dpy, true);
break; break;
case DOWN: case DOWN:
mykeysym = XStringToKeysym ("Down"); mykeysym = XStringToKeysym ("Down");
xkeycode = XKeysymToKeycode (dpy, mykeysym);
XTestFakeKeyEvent (dpy, xkeycode, true, CurrentTime);
XSync (dpy, true);
XTestFakeKeyEvent (dpy, xkeycode, false, CurrentTime);
XSync (dpy, true);
break; break;
case LEFT: case LEFT:
mykeysym = XStringToKeysym ("Left"); mykeysym = XStringToKeysym ("Left");
xkeycode = XKeysymToKeycode (dpy, mykeysym);
XTestFakeKeyEvent (dpy, xkeycode, true, CurrentTime);
XSync (dpy, true);
XTestFakeKeyEvent (dpy, xkeycode, false, CurrentTime);
XSync (dpy, true);
break; break;
case RIGHT: case RIGHT:
mykeysym = XStringToKeysym ("Right"); mykeysym = XStringToKeysym ("Right");
xkeycode = XKeysymToKeycode (dpy, mykeysym);
XTestFakeKeyEvent (dpy, xkeycode, true, CurrentTime);
XSync (dpy, true);
XTestFakeKeyEvent (dpy, xkeycode, false, CurrentTime);
XSync (dpy, true);
break; break;
case F1: case F1:
mykeysym = XStringToKeysym ("F1"); mykeysym = XStringToKeysym ("F1");
xkeycode = XKeysymToKeycode (dpy, mykeysym);
XTestFakeKeyEvent (dpy, xkeycode, true, CurrentTime);
XSync (dpy, true);
XTestFakeKeyEvent (dpy, xkeycode, false, CurrentTime);
XSync (dpy, true);
break; break;
case F2: case F2:
mykeysym = XStringToKeysym ("F2"); mykeysym = XStringToKeysym ("F2");
xkeycode = XKeysymToKeycode (dpy, mykeysym);
XTestFakeKeyEvent (dpy, xkeycode, true, CurrentTime);
XSync (dpy, true);
XTestFakeKeyEvent (dpy, xkeycode, false, CurrentTime);
XSync (dpy, true);
break; break;
case F3: case F3:
mykeysym = XStringToKeysym ("F3"); mykeysym = XStringToKeysym ("F3");
xkeycode = XKeysymToKeycode (dpy, mykeysym);
XTestFakeKeyEvent (dpy, xkeycode, true, CurrentTime);
XSync (dpy, true);
XTestFakeKeyEvent (dpy, xkeycode, false, CurrentTime);
XSync (dpy, true);
break; break;
case F4: case F4:
mykeysym = XStringToKeysym ("F4"); mykeysym = XStringToKeysym ("F4");
xkeycode = XKeysymToKeycode (dpy, mykeysym);
XTestFakeKeyEvent (dpy, xkeycode, true, CurrentTime);
XSync (dpy, true);
XTestFakeKeyEvent (dpy, xkeycode, false, CurrentTime);
XSync (dpy, true);
break; break;
case F5: case F5:
mykeysym = XStringToKeysym ("F5"); mykeysym = XStringToKeysym ("F5");
xkeycode = XKeysymToKeycode (dpy, mykeysym);
XTestFakeKeyEvent (dpy, xkeycode, true, CurrentTime);
XSync (dpy, true);
XTestFakeKeyEvent (dpy, xkeycode, false, CurrentTime);
XSync (dpy, true);
break; break;
case F6: case F6:
mykeysym = XStringToKeysym ("F6"); mykeysym = XStringToKeysym ("F6");
xkeycode = XKeysymToKeycode (dpy, mykeysym);
XTestFakeKeyEvent (dpy, xkeycode, true, CurrentTime);
XSync (dpy, true);
XTestFakeKeyEvent (dpy, xkeycode, false, CurrentTime);
XSync (dpy, true);
break; break;
case F7: case F7:
mykeysym = XStringToKeysym ("F7"); mykeysym = XStringToKeysym ("F7");
xkeycode = XKeysymToKeycode (dpy, mykeysym);
XTestFakeKeyEvent (dpy, xkeycode, true, CurrentTime);
XSync (dpy, true);
XTestFakeKeyEvent (dpy, xkeycode, false, CurrentTime);
XSync (dpy, true);
break; break;
case F8: case F8:
mykeysym = XStringToKeysym ("F8"); mykeysym = XStringToKeysym ("F8");
xkeycode = XKeysymToKeycode (dpy, mykeysym);
XTestFakeKeyEvent (dpy, xkeycode, true, CurrentTime);
XSync (dpy, true);
XTestFakeKeyEvent (dpy, xkeycode, false, CurrentTime);
XSync (dpy, true);
break; break;
case F9: case F9:
mykeysym = XStringToKeysym ("F9"); mykeysym = XStringToKeysym ("F9");
xkeycode = XKeysymToKeycode (dpy, mykeysym);
XTestFakeKeyEvent (dpy, xkeycode, true, CurrentTime);
XSync (dpy, true);
XTestFakeKeyEvent (dpy, xkeycode, false, CurrentTime);
XSync (dpy, true);
break; break;
case F11: case F11:
mykeysym = XStringToKeysym ("F11"); mykeysym = XStringToKeysym ("F11");
xkeycode = XKeysymToKeycode (dpy, mykeysym);
XTestFakeKeyEvent (dpy, xkeycode, true, CurrentTime);
XSync (dpy, true);
XTestFakeKeyEvent (dpy, xkeycode, false, CurrentTime);
XSync (dpy, true);
break; break;
case F12: case F12:
mykeysym = XStringToKeysym ("F12"); mykeysym = XStringToKeysym ("F12");
xkeycode = XKeysymToKeycode (dpy, mykeysym);
XTestFakeKeyEvent (dpy, xkeycode, true, CurrentTime);
XSync (dpy, true);
XTestFakeKeyEvent (dpy, xkeycode, false, CurrentTime);
XSync (dpy, true);
break; break;
case PAGE_UP: case PAGE_UP:
mykeysym = XStringToKeysym ("Page_Up"); mykeysym = XStringToKeysym ("Page_Up");
xkeycode = XKeysymToKeycode (dpy, mykeysym);
XTestFakeKeyEvent (dpy, xkeycode, true, CurrentTime);
XSync (dpy, true);
XTestFakeKeyEvent (dpy, xkeycode, false, CurrentTime);
XSync (dpy, true);
break; break;
case PAGE_DOWN: case PAGE_DOWN:
mykeysym = XStringToKeysym ("Page_Down"); mykeysym = XStringToKeysym ("Page_Down");
xkeycode = XKeysymToKeycode (dpy, mykeysym);
XTestFakeKeyEvent (dpy, xkeycode, true, CurrentTime);
XSync (dpy, true);
XTestFakeKeyEvent (dpy, xkeycode, false, CurrentTime);
XSync (dpy, true);
break; break;
case INSERT: case INSERT:
mykeysym = XStringToKeysym ("Insert"); mykeysym = XStringToKeysym ("Insert");
xkeycode = XKeysymToKeycode (dpy, mykeysym);
XTestFakeKeyEvent (dpy, xkeycode, true, CurrentTime);
XSync (dpy, true);
XTestFakeKeyEvent (dpy, xkeycode, false, CurrentTime);
XSync (dpy, true);
break; break;
case KEY_DELETE: case DFHack::DELETE: // collides with some windows stuff otherwise?
mykeysym = XStringToKeysym ("Delete"); mykeysym = XStringToKeysym ("Delete");
xkeycode = XKeysymToKeycode (dpy, mykeysym);
XTestFakeKeyEvent (dpy, xkeycode, true, CurrentTime);
XSync (dpy, true);
XTestFakeKeyEvent (dpy, xkeycode, false, CurrentTime);
XSync (dpy, true);
break; break;
case HOME: case HOME:
mykeysym = XStringToKeysym ("Home"); mykeysym = XStringToKeysym ("Home");
xkeycode = XKeysymToKeycode (dpy, mykeysym);
XTestFakeKeyEvent (dpy, xkeycode, true, CurrentTime);
XSync (dpy, true);
XTestFakeKeyEvent (dpy, xkeycode, false, CurrentTime);
XSync (dpy, true);
break; break;
case END: case END:
mykeysym = XStringToKeysym ("End"); mykeysym = XStringToKeysym ("End");
xkeycode = XKeysymToKeycode (dpy, mykeysym);
XTestFakeKeyEvent (dpy, xkeycode, true, CurrentTime);
XSync (dpy, true);
XTestFakeKeyEvent (dpy, xkeycode, false, CurrentTime);
XSync (dpy, true);
break; break;
case KEYPAD_DIVIDE: case KEYPAD_DIVIDE:
mykeysym = XStringToKeysym ("KP_Divide"); mykeysym = XStringToKeysym ("KP_Divide");
xkeycode = XKeysymToKeycode (dpy, mykeysym);
XTestFakeKeyEvent (dpy, xkeycode, true, CurrentTime);
XSync (dpy, true);
XTestFakeKeyEvent (dpy, xkeycode, false, CurrentTime);
XSync (dpy, true);
break; break;
case KEYPAD_MULTIPLY: case KEYPAD_MULTIPLY:
mykeysym = XStringToKeysym ("KP_Multiply"); mykeysym = XStringToKeysym ("KP_Multiply");
xkeycode = XKeysymToKeycode (dpy, mykeysym);
XTestFakeKeyEvent (dpy, xkeycode, true, CurrentTime);
XSync (dpy, true);
XTestFakeKeyEvent (dpy, xkeycode, false, CurrentTime);
XSync (dpy, true);
break; break;
case KEYPAD_SUBTRACT: case KEYPAD_SUBTRACT:
mykeysym = XStringToKeysym ("KP_Subtract"); mykeysym = XStringToKeysym ("KP_Subtract");
xkeycode = XKeysymToKeycode (dpy, mykeysym);
XTestFakeKeyEvent (dpy, xkeycode, true, CurrentTime);
XSync (dpy, true);
XTestFakeKeyEvent (dpy, xkeycode, false, CurrentTime);
XSync (dpy, true);
break; break;
case KEYPAD_ADD: case KEYPAD_ADD:
mykeysym = XStringToKeysym ("KP_Add"); mykeysym = XStringToKeysym ("KP_Add");
xkeycode = XKeysymToKeycode (dpy, mykeysym);
XTestFakeKeyEvent (dpy, xkeycode, true, CurrentTime);
XSync (dpy, true);
XTestFakeKeyEvent (dpy, xkeycode, false, CurrentTime);
XSync (dpy, true);
break; break;
case KEYPAD_ENTER: case KEYPAD_ENTER:
mykeysym = XStringToKeysym ("KP_Enter"); mykeysym = XStringToKeysym ("KP_Enter");
xkeycode = XKeysymToKeycode (dpy, mykeysym);
XTestFakeKeyEvent (dpy, xkeycode, true, CurrentTime);
XSync (dpy, true);
XTestFakeKeyEvent (dpy, xkeycode, false, CurrentTime);
XSync (dpy, true);
break; break;
case KEYPAD_0: case KEYPAD_0:
mykeysym = XStringToKeysym ("KP_0"); mykeysym = XStringToKeysym ("KP_0");
xkeycode = XKeysymToKeycode (dpy, mykeysym);
XTestFakeKeyEvent (dpy, xkeycode, true, CurrentTime);
XSync (dpy, true);
XTestFakeKeyEvent (dpy, xkeycode, false, CurrentTime);
XSync (dpy, true);
break; break;
case KEYPAD_1: case KEYPAD_1:
mykeysym = XStringToKeysym ("KP_1"); mykeysym = XStringToKeysym ("KP_1");
xkeycode = XKeysymToKeycode (dpy, mykeysym);
XTestFakeKeyEvent (dpy, xkeycode, true, CurrentTime);
XSync (dpy, true);
XTestFakeKeyEvent (dpy, xkeycode, false, CurrentTime);
XSync (dpy, true);
break; break;
case KEYPAD_2: case KEYPAD_2:
mykeysym = XStringToKeysym ("KP_2"); mykeysym = XStringToKeysym ("KP_2");
xkeycode = XKeysymToKeycode (dpy, mykeysym);
XTestFakeKeyEvent (dpy, xkeycode, true, CurrentTime);
XSync (dpy, true);
XTestFakeKeyEvent (dpy, xkeycode, false, CurrentTime);
XSync (dpy, true);
break; break;
case KEYPAD_3: case KEYPAD_3:
mykeysym = XStringToKeysym ("KP_3"); mykeysym = XStringToKeysym ("KP_3");
xkeycode = XKeysymToKeycode (dpy, mykeysym);
XTestFakeKeyEvent (dpy, xkeycode, true, CurrentTime);
XSync (dpy, true);
XTestFakeKeyEvent (dpy, xkeycode, false, CurrentTime);
XSync (dpy, true);
break; break;
case KEYPAD_4: case KEYPAD_4:
mykeysym = XStringToKeysym ("KP_4"); mykeysym = XStringToKeysym ("KP_4");
xkeycode = XKeysymToKeycode (dpy, mykeysym);
XTestFakeKeyEvent (dpy, xkeycode, true, CurrentTime);
XSync (dpy, true);
XTestFakeKeyEvent (dpy, xkeycode, false, CurrentTime);
XSync (dpy, true);
break; break;
case KEYPAD_5: case KEYPAD_5:
mykeysym = XStringToKeysym ("KP_5"); mykeysym = XStringToKeysym ("KP_5");
xkeycode = XKeysymToKeycode (dpy, mykeysym);
XTestFakeKeyEvent (dpy, xkeycode, true, CurrentTime);
XSync (dpy, true);
XTestFakeKeyEvent (dpy, xkeycode, false, CurrentTime);
XSync (dpy, true);
break; break;
case KEYPAD_6: case KEYPAD_6:
mykeysym = XStringToKeysym ("KP_6"); mykeysym = XStringToKeysym ("KP_6");
xkeycode = XKeysymToKeycode (dpy, mykeysym);
XTestFakeKeyEvent (dpy, xkeycode, true, CurrentTime);
XSync (dpy, true);
XTestFakeKeyEvent (dpy, xkeycode, false, CurrentTime);
XSync (dpy, true);
break; break;
case KEYPAD_7: case KEYPAD_7:
mykeysym = XStringToKeysym ("KP_7"); mykeysym = XStringToKeysym ("KP_7");
xkeycode = XKeysymToKeycode (dpy, mykeysym);
XTestFakeKeyEvent (dpy, xkeycode, true, CurrentTime);
XSync (dpy, true);
XTestFakeKeyEvent (dpy, xkeycode, false, CurrentTime);
XSync (dpy, true);
break; break;
case KEYPAD_8: case KEYPAD_8:
mykeysym = XStringToKeysym ("KP_8"); mykeysym = XStringToKeysym ("KP_8");
xkeycode = XKeysymToKeycode (dpy, mykeysym);
XTestFakeKeyEvent (dpy, xkeycode, true, CurrentTime);
XSync (dpy, true);
XTestFakeKeyEvent (dpy, xkeycode, false, CurrentTime);
XSync (dpy, true);
break; break;
case KEYPAD_9: case KEYPAD_9:
mykeysym = XStringToKeysym ("KP_9"); mykeysym = XStringToKeysym ("KP_9");
xkeycode = XKeysymToKeycode (dpy, mykeysym);
XTestFakeKeyEvent (dpy, xkeycode, true, CurrentTime);
XSync (dpy, true);
XTestFakeKeyEvent (dpy, xkeycode, false, CurrentTime);
XSync (dpy, true);
break; break;
case KEYPAD_DECIMAL_POINT: case KEYPAD_DECIMAL_POINT:
mykeysym = XStringToKeysym ("KP_Decimal"); mykeysym = XStringToKeysym ("KP_Decimal");
xkeycode = XKeysymToKeycode (dpy, mykeysym);
XTestFakeKeyEvent (dpy, xkeycode, true, CurrentTime);
XSync (dpy, true);
XTestFakeKeyEvent (dpy, xkeycode, false, CurrentTime);
XSync (dpy, true);
break; break;
} }
xkeycode = XKeysymToKeycode (dpy, mykeysym);
XTestFakeKeyEvent (dpy, xkeycode, true, CurrentTime);
XSync (dpy, true);
XTestFakeKeyEvent (dpy, xkeycode, false, CurrentTime);
XSync (dpy, true);
usleep(20000); usleep(20000);
} }
if (currAttr.map_state == IsUnmapped) if (currAttr.map_state == IsUnmapped)

@ -27,6 +27,9 @@ distribution.
#include "Export.h" #include "Export.h"
namespace DFHack
{
struct t_matgloss struct t_matgloss
{ {
char id[128]; char id[128];
@ -675,7 +678,7 @@ enum t_special
PAGE_UP, PAGE_UP,
PAGE_DOWN, PAGE_DOWN,
INSERT, INSERT,
KEY_DELETE, // DELETE is already defined in winnt.h, so can't redefine it here DELETE,
HOME, HOME,
END, END,
KEYPAD_DIVIDE, KEYPAD_DIVIDE,
@ -701,4 +704,6 @@ struct t_viewscreen
int32_t type; int32_t type;
//There is more info in these objects, but I don't know what it is yet //There is more info in these objects, but I don't know what it is yet
}; };
}// namespace DFHack
#endif // TYPES_H_INCLUDED #endif // TYPES_H_INCLUDED

@ -127,7 +127,7 @@ int main (int argc,const char* argv[])
ins >> lines; // Reads the integers from the string. ins >> lines; // Reads the integers from the string.
} }
vector<t_matgloss> creaturestypes; vector<DFHack::t_matgloss> creaturestypes;
DFHack::API DF ("Memory.xml"); DFHack::API DF ("Memory.xml");
if(!DF.Attach()) if(!DF.Attach())
@ -141,7 +141,7 @@ int main (int argc,const char* argv[])
vector < uint32_t > addresses; vector < uint32_t > addresses;
for(uint32_t i = 0; i < numBuildings; i++) for(uint32_t i = 0; i < numBuildings; i++)
{ {
t_building temp; DFHack::t_building temp;
DF.ReadBuilding(i, temp); DF.ReadBuilding(i, temp);
if(buildingtypes[temp.type] == argv[1]) if(buildingtypes[temp.type] == argv[1])
{ {

@ -13,7 +13,7 @@ int main (void)
uint32_t x_max,y_max,z_max; uint32_t x_max,y_max,z_max;
uint32_t num_blocks = 0; uint32_t num_blocks = 0;
uint32_t bytes_read = 0; uint32_t bytes_read = 0;
t_occupancy occupancies[256]; DFHack::t_occupancy occupancies[256];
DFHack::API DF ("Memory.xml"); DFHack::API DF ("Memory.xml");
if(!DF.Attach()) if(!DF.Attach())

@ -24,7 +24,7 @@ void print_bits ( T val, std::ostream& out )
int main (void) int main (void)
{ {
vector<t_matgloss> creaturestypes; vector<DFHack::t_matgloss> creaturestypes;
DFHack::API DF("Memory.xml"); DFHack::API DF("Memory.xml");
if(!DF.Attach()) if(!DF.Attach())
@ -46,7 +46,7 @@ int main (void)
uint32_t numCreatures = DF.InitReadCreatures(); uint32_t numCreatures = DF.InitReadCreatures();
for(uint32_t i = 0; i < numCreatures; i++) for(uint32_t i = 0; i < numCreatures; i++)
{ {
t_creature temp; DFHack::t_creature temp;
DF.ReadCreature(i, temp); DF.ReadCreature(i, temp);
cout << "address: " << temp.origin << " creature type: " << creaturestypes[temp.type].id << ", position: " << temp.x << "x " << temp.y << "y "<< temp.z << "z" << endl; cout << "address: " << temp.origin << " creature type: " << creaturestypes[temp.type].id << ", position: " << temp.x << "x " << temp.y << "y "<< temp.z << "z" << endl;
bool addendl = false; bool addendl = false;

@ -24,13 +24,13 @@ void print_bits ( T val, std::ostream& out )
vector <string> buildingtypes; vector <string> buildingtypes;
map<string, vector<string> > names; map<string, vector<string> > names;
uint32_t numCreatures; uint32_t numCreatures;
vector<t_matgloss> creaturestypes; vector<DFHack::t_matgloss> creaturestypes;
void printDwarves(DFHack::API & DF) void printDwarves(DFHack::API & DF)
{ {
int dwarfCounter = 0; int dwarfCounter = 0;
for(uint32_t i = 0; i < numCreatures; i++) for(uint32_t i = 0; i < numCreatures; i++)
{ {
t_creature temp; DFHack::t_creature temp;
DF.ReadCreature(i, temp); DF.ReadCreature(i, temp);
string type = creaturestypes[temp.type].id; string type = creaturestypes[temp.type].id;
if(type == "DWARF" && !temp.flags1.bits.dead && !temp.flags2.bits.killed){ if(type == "DWARF" && !temp.flags1.bits.dead && !temp.flags2.bits.killed){
@ -55,7 +55,7 @@ void printDwarves(DFHack::API & DF)
} }
} }
bool getDwarfSelection(DFHack::API & DF, t_creature & toChange,string & changeString, string & commandString,int & eraseAmount,int &dwarfNum,bool &isName) bool getDwarfSelection(DFHack::API & DF, DFHack::t_creature & toChange,string & changeString, string & commandString,int & eraseAmount,int &dwarfNum,bool &isName)
{ {
DF.ForceResume(); DF.ForceResume();
static string lastText; static string lastText;
@ -138,14 +138,14 @@ bool getDwarfSelection(DFHack::API & DF, t_creature & toChange,string & changeSt
bool waitTillChanged(DFHack::API &DF, int creatureToCheck, string changeValue, bool isName) bool waitTillChanged(DFHack::API &DF, int creatureToCheck, string changeValue, bool isName)
{ {
DF.Suspend(); DF.Suspend();
t_creature testCre; DFHack::t_creature testCre;
DF.ReadCreature(creatureToCheck,testCre); DF.ReadCreature(creatureToCheck,testCre);
int tryCount = 0; int tryCount = 0;
if(isName) if(isName)
{ {
while(testCre.nick_name != changeValue && tryCount <50) while(testCre.nick_name != changeValue && tryCount <50)
{ {
DF.TypeSpecial(WAIT,1,100); DF.TypeSpecial(DFHack::WAIT,1,100);
DF.Suspend(); DF.Suspend();
DF.ReadCreature(creatureToCheck,testCre); DF.ReadCreature(creatureToCheck,testCre);
tryCount++; tryCount++;
@ -155,7 +155,7 @@ bool waitTillChanged(DFHack::API &DF, int creatureToCheck, string changeValue, b
{ {
while(testCre.custom_profession != changeValue && tryCount < 50) while(testCre.custom_profession != changeValue && tryCount < 50)
{ {
DF.TypeSpecial(WAIT,1,100); DF.TypeSpecial(DFHack::WAIT,1,100);
DF.Suspend(); DF.Suspend();
DF.ReadCreature(creatureToCheck,testCre); DF.ReadCreature(creatureToCheck,testCre);
tryCount++; tryCount++;
@ -169,12 +169,12 @@ bool waitTillChanged(DFHack::API &DF, int creatureToCheck, string changeValue, b
} }
bool waitTillScreenState(DFHack::API &DF, string screenState) bool waitTillScreenState(DFHack::API &DF, string screenState)
{ {
t_viewscreen current; DFHack::t_viewscreen current;
DF.Suspend(); DF.Suspend();
DF.ReadViewScreen(current); DF.ReadViewScreen(current);
int tryCount = 0; int tryCount = 0;
while(buildingtypes[current.type] != screenState && tryCount < 50){ while(buildingtypes[current.type] != screenState && tryCount < 50){
DF.TypeSpecial(WAIT,1,100); DF.TypeSpecial(DFHack::WAIT,1,100);
DF.Suspend(); DF.Suspend();
DF.ReadViewScreen(current); DF.ReadViewScreen(current);
tryCount++; tryCount++;
@ -194,7 +194,7 @@ bool waitTillCursorState(DFHack::API &DF, bool On)
bool cursorResult = DF.getCursorCoords(x,y,z); bool cursorResult = DF.getCursorCoords(x,y,z);
while(tryCount < 50 && On && !cursorResult || !On && cursorResult) while(tryCount < 50 && On && !cursorResult || !On && cursorResult)
{ {
DF.TypeSpecial(WAIT,1,100); DF.TypeSpecial(DFHack::WAIT,1,100);
tryCount++; tryCount++;
DF.Suspend(); DF.Suspend();
cursorResult = DF.getCursorCoords(x,y,z); cursorResult = DF.getCursorCoords(x,y,z);
@ -230,7 +230,7 @@ int main (void)
DF.InitViewAndCursor(); DF.InitViewAndCursor();
DF.Suspend(); DF.Suspend();
printDwarves(DF); printDwarves(DF);
t_creature toChange; DFHack::t_creature toChange;
string changeString,commandString; string changeString,commandString;
int eraseAmount; int eraseAmount;
int toChangeNum; int toChangeNum;
@ -252,7 +252,7 @@ int main (void)
vector<uint32_t> underCursor; vector<uint32_t> underCursor;
while(!DF.getCurrentCursorCreatures(underCursor)) while(!DF.getCurrentCursorCreatures(underCursor))
{ {
DF.TypeSpecial(WAIT,1,100); DF.TypeSpecial(DFHack::WAIT,1,100);
DF.Suspend(); DF.Suspend();
DF.setCursorCoords(toChange.x, toChange.y,toChange.z); DF.setCursorCoords(toChange.x, toChange.y,toChange.z);
} }
@ -275,20 +275,20 @@ int main (void)
DF.TypeStr(commandString.c_str()); DF.TypeStr(commandString.c_str());
if(waitTillScreenState(DF,"viewscreen_customize_unit")) if(waitTillScreenState(DF,"viewscreen_customize_unit"))
{ {
DF.TypeSpecial(BACK_SPACE,eraseAmount); DF.TypeSpecial(DFHack::BACK_SPACE,eraseAmount);
if(waitTillChanged(DF,toChangeNum,"",isName)) if(waitTillChanged(DF,toChangeNum,"",isName))
{ {
DF.TypeStr(changeString.c_str()); DF.TypeStr(changeString.c_str());
if(waitTillChanged(DF,toChangeNum,changeString,isName)) if(waitTillChanged(DF,toChangeNum,changeString,isName))
{ {
DF.TypeSpecial(ENTER); DF.TypeSpecial(DFHack::ENTER);
DF.TypeSpecial(SPACE); // should take you to unit screen if everything worked DF.TypeSpecial(DFHack::SPACE); // should take you to unit screen if everything worked
if(waitTillScreenState(DF,"viewscreen_unit")) if(waitTillScreenState(DF,"viewscreen_unit"))
{ {
DF.TypeSpecial(SPACE); DF.TypeSpecial(DFHack::SPACE);
if(waitTillScreenState(DF,"viewscreen_dwarfmode")) if(waitTillScreenState(DF,"viewscreen_dwarfmode"))
{ {
DF.TypeSpecial(SPACE); DF.TypeSpecial(DFHack::SPACE);
if(waitTillCursorState(DF,false)) if(waitTillCursorState(DF,false))
{ {
completed = true; completed = true;

@ -13,14 +13,14 @@ using namespace std;
struct matGlosses struct matGlosses
{ {
vector<t_matgloss> plantMat; vector<DFHack::t_matgloss> plantMat;
vector<t_matgloss> woodMat; vector<DFHack::t_matgloss> woodMat;
vector<t_matgloss> stoneMat; vector<DFHack::t_matgloss> stoneMat;
vector<t_matgloss> metalMat; vector<DFHack::t_matgloss> metalMat;
vector<t_matgloss> creatureMat; vector<DFHack::t_matgloss> creatureMat;
}; };
void printItem(t_item item, const vector<string> & buildingTypes,const matGlosses & mat){ void printItem(DFHack::t_item item, const vector<string> & buildingTypes,const matGlosses & mat){
cout << dec << "Item at x:" << item.x << " y:" << item.y << " z:" << item.z << endl; cout << dec << "Item at x:" << item.x << " y:" << item.y << " z:" << item.z << endl;
cout << "Type: " << (int) item.type << " " << buildingTypes[item.type] << " Address: " << hex << item.origin << endl; cout << "Type: " << (int) item.type << " " << buildingTypes[item.type] << " Address: " << hex << item.origin << endl;
cout << "Material: "; cout << "Material: ";
@ -120,10 +120,10 @@ int main ()
// } // }
int32_t x,y,z; int32_t x,y,z;
DF.getCursorCoords(x,y,z); DF.getCursorCoords(x,y,z);
vector <t_item> foundItems; vector <DFHack::t_item> foundItems;
for(uint32_t i = 0; i < numItems; i++) for(uint32_t i = 0; i < numItems; i++)
{ {
t_item temp; DFHack::t_item temp;
DF.ReadItem(i, temp); DF.ReadItem(i, temp);
if(temp.x == x && temp.y == y && temp.z == z) if(temp.x == x && temp.y == y && temp.z == z)
{ {

@ -18,8 +18,8 @@ int main (void)
uint32_t num_blocks = 0; uint32_t num_blocks = 0;
uint32_t bytes_read = 0; uint32_t bytes_read = 0;
uint16_t tiletypes[16][16]; uint16_t tiletypes[16][16];
t_designation designations[16][16]; DFHack::t_designation designations[16][16];
t_occupancy occupancies[16][16]; DFHack::t_occupancy occupancies[16][16];
DFHack::API DF("Memory.xml"); DFHack::API DF("Memory.xml");
if(!DF.Attach()) if(!DF.Attach())

@ -19,16 +19,16 @@ int main (void)
cerr << "DF not found" << endl; cerr << "DF not found" << endl;
return 1; return 1;
} }
vector <t_matgloss> Plants; vector <DFHack::t_matgloss> Plants;
DF.ReadPlantMatgloss(Plants); DF.ReadPlantMatgloss(Plants);
vector <t_matgloss> Metals; vector <DFHack::t_matgloss> Metals;
DF.ReadMetalMatgloss(Metals); DF.ReadMetalMatgloss(Metals);
vector <t_matgloss> Stones; vector <DFHack::t_matgloss> Stones;
DF.ReadStoneMatgloss(Stones); DF.ReadStoneMatgloss(Stones);
vector <t_matgloss> CreatureTypes; vector <DFHack::t_matgloss> CreatureTypes;
DF.ReadCreatureMatgloss(CreatureTypes); DF.ReadCreatureMatgloss(CreatureTypes);
cout << "Plant: " << Plants[0].id << endl; cout << "Plant: " << Plants[0].id << endl;

@ -47,11 +47,11 @@ int main (int argc, const char* argv[])
#endif #endif
uint32_t x_max,y_max,z_max; uint32_t x_max,y_max,z_max;
uint16_t tiletypes[16][16]; uint16_t tiletypes[16][16];
t_designation designations[16][16]; DFHack::t_designation designations[16][16];
uint8_t regionoffsets[16]; uint8_t regionoffsets[16];
map <int16_t, uint32_t> materials; map <int16_t, uint32_t> materials;
materials.clear(); materials.clear();
vector<t_matgloss> stonetypes; vector<DFHack::t_matgloss> stonetypes;
vector< vector <uint16_t> > layerassign; vector< vector <uint16_t> > layerassign;
// init the API // init the API
@ -84,7 +84,7 @@ int main (int argc, const char* argv[])
} }
int16_t tempvein [16][16]; int16_t tempvein [16][16];
vector <t_vein> veins; vector <DFHack::t_vein> veins;
// walk the map! // walk the map!
for(uint32_t x = 0; x< x_max;x++) for(uint32_t x = 0; x< x_max;x++)
{ {

@ -13,7 +13,7 @@ int main (void)
uint32_t x_max,y_max,z_max; uint32_t x_max,y_max,z_max;
uint32_t num_blocks = 0; uint32_t num_blocks = 0;
uint32_t bytes_read = 0; uint32_t bytes_read = 0;
t_designation designations[256]; DFHack::t_designation designations[256];
DFHack::API DF("Memory.xml"); DFHack::API DF("Memory.xml");
if(!DF.Attach()) if(!DF.Attach())