merged window dimension and item matgloss patches from belal

develop
Petr Mrázek 2009-11-18 03:35:43 +00:00
parent 29c0932ff7
commit dea1ce858b
8 changed files with 201 additions and 56 deletions

@ -46,6 +46,7 @@ class API::Private
uint32_t window_y_offset; uint32_t window_y_offset;
uint32_t window_z_offset; uint32_t window_z_offset;
uint32_t cursor_xyz_offset; uint32_t cursor_xyz_offset;
uint32_t window_dims_offset;
uint32_t creature_pos_offset; uint32_t creature_pos_offset;
uint32_t creature_type_offset; uint32_t creature_type_offset;
@ -72,6 +73,8 @@ class API::Private
uint32_t creature_happiness_offset; uint32_t creature_happiness_offset;
uint32_t creature_traits_offset; uint32_t creature_traits_offset;
uint32_t item_material_offset;
uint32_t dwarf_lang_table_offset; uint32_t dwarf_lang_table_offset;
ProcessEnumerator* pm; ProcessEnumerator* pm;
@ -86,6 +89,7 @@ class API::Private
bool vegetationInited; bool vegetationInited;
bool creaturesInited; bool creaturesInited;
bool cursorWindowInited; bool cursorWindowInited;
bool viewSizeInited;
bool itemsInited; bool itemsInited;
bool nameTablesInited; bool nameTablesInited;
@ -123,6 +127,7 @@ API::API(const string path_to_xml)
d->buildingsInited = false; d->buildingsInited = false;
d->vegetationInited = false; d->vegetationInited = false;
d->cursorWindowInited = false; d->cursorWindowInited = false;
d->viewSizeInited = false;
d->itemsInited = false; d->itemsInited = false;
d->pm = NULL; d->pm = NULL;
} }
@ -1154,6 +1159,7 @@ bool API::InitViewAndCursor()
d->window_y_offset = d->offset_descriptor->getAddress("window_y"); d->window_y_offset = d->offset_descriptor->getAddress("window_y");
d->window_z_offset = d->offset_descriptor->getAddress("window_z"); d->window_z_offset = d->offset_descriptor->getAddress("window_z");
d->cursor_xyz_offset = d->offset_descriptor->getAddress("cursor_xyz"); d->cursor_xyz_offset = d->offset_descriptor->getAddress("cursor_xyz");
if(d->window_x_offset && d->window_y_offset && d->window_z_offset) if(d->window_x_offset && d->window_y_offset && d->window_z_offset)
{ {
d->cursorWindowInited = true; d->cursorWindowInited = true;
@ -1165,6 +1171,20 @@ bool API::InitViewAndCursor()
} }
} }
bool API::InitViewSize()
{
d->window_dims_offset = d->offset_descriptor->getAddress("window_dims");
if(d->window_dims_offset)
{
d->viewSizeInited = true;
return true;
}
else
{
return false;
}
}
bool API::getViewCoords (int32_t &x, int32_t &y, int32_t &z) bool API::getViewCoords (int32_t &x, int32_t &y, int32_t &z)
{ {
assert(d->cursorWindowInited); assert(d->cursorWindowInited);
@ -1202,6 +1222,23 @@ bool API::setCursorCoords (const int32_t &x, const int32_t &y, const int32_t &z)
Mwrite(d->cursor_xyz_offset,3*sizeof(int32_t),(uint8_t *)coords); Mwrite(d->cursor_xyz_offset,3*sizeof(int32_t),(uint8_t *)coords);
return true; return true;
} }
bool API::getWindowSize(int32_t &width, int32_t &height)
{
assert(d->viewSizeInited);
int32_t coords[2];
Mread(d->window_dims_offset,2*sizeof(int32_t),(uint8_t *)coords);
width = coords[0];
height = coords[1];
return true;
}
////FIXME: I don't know what is going to happen if you try to set these to bad values, probably bad things...
//bool API::setWindowSize(const int32_t &width, const int32_t &height)
//{
// assert(d->viewSizeInited);
// int32_t coords[2] = {width,height};
// Mwrite(d->window_dims_offset,2*sizeof(int32_t),(uint8_t *)coords);
// return true;
//}
memory_info API::getMemoryInfo() memory_info API::getMemoryInfo()
{ {
@ -1216,6 +1253,10 @@ uint32_t API::InitReadItems()
{ {
int items = d->offset_descriptor->getAddress("items"); int items = d->offset_descriptor->getAddress("items");
assert(items); assert(items);
d->item_material_offset = d->offset_descriptor->getOffset("item_materials");
assert(d->item_material_offset);
d->p_itm = new DfVector( d->dm->readVector(items,4)); d->p_itm = new DfVector( d->dm->readVector(items,4));
d->itemsInited = true; d->itemsInited = true;
return d->p_itm->getSize(); return d->p_itm->getSize();
@ -1223,7 +1264,6 @@ uint32_t API::InitReadItems()
bool API::ReadItem(const uint32_t &index, t_item & item) bool API::ReadItem(const uint32_t &index, t_item & item)
{ {
assert(d->buildingsInited && d->itemsInited); //should change to the generic init rather than buildings assert(d->buildingsInited && d->itemsInited); //should change to the generic init rather than buildings
t_item_df40d item_40d; t_item_df40d item_40d;
// read pointer from vector at position // read pointer from vector at position
@ -1244,6 +1284,12 @@ bool API::ReadItem(const uint32_t &index, t_item & item)
item.ID = item_40d.ID; item.ID = item_40d.ID;
item.flags = item_40d.flags; item.flags = item_40d.flags;
//TODO certain item types (creature based, threads, seeds, bags do not have the first matType byte, instead they have the material index only located at 0x68
Mread(temp+d->item_material_offset, sizeof(t_matglossPair), (uint8_t *) &item.material);
//for(int i = 0; i < 0xCC; i++){ // used for item research
// uint8_t byte = MreadByte(temp+i);
// item.bytes.push_back(byte);
//}
return true; return true;
} }
void API::FinishReadItems() void API::FinishReadItems()

@ -173,6 +173,11 @@ namespace DFHack
bool getCursorCoords (int32_t &x, int32_t &y, int32_t &z); 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 setCursorCoords (const int32_t &x, const int32_t &y, const int32_t &z);
bool InitViewSize();
bool getWindowSize(int32_t & width, int32_t & height);
bool setWindowSize(const int32_t & width, const int32_t & height);
/* /*
// FIXME: add a real creature class, move these // FIXME: add a real creature class, move these
string getLastName(const uint32_t &index, bool); string getLastName(const uint32_t &index, bool);
@ -183,6 +188,7 @@ namespace DFHack
vector<t_trait> getTraits(const uint32_t &index); vector<t_trait> getTraits(const uint32_t &index);
vector<t_labor> getLabors(const uint32_t &index); vector<t_labor> getLabors(const uint32_t &index);
*/ */
void InitReadNameTables(); void InitReadNameTables();
void FinishReadNameTables(); void FinishReadNameTables();

@ -69,6 +69,7 @@ Process::Process(uint32_t pid, vector <memory_info> & known_versions)
if(EnumProcessModules(hProcess, &hmod, 1 * sizeof(HMODULE), &junk) == 0) if(EnumProcessModules(hProcess, &hmod, 1 * sizeof(HMODULE), &junk) == 0)
{ {
CloseHandle(hProcess); CloseHandle(hProcess);
return; //if enumprocessModules fails, give up
} }
// got base ;) // got base ;)

@ -538,6 +538,12 @@ struct t_item
uint32_t flags; uint32_t flags;
uint32_t ID; uint32_t ID;
uint32_t type; uint32_t type;
t_matglossPair material;
/*
uint8_t matType;
uint8_t material;
*/
// vector<uint8_t> bytes; used for item research
// FIXME: not complete, we need building presence bitmaps for stuff like farm plots and stockpiles, orientation (N,E,S,W) and state (open/closed) // FIXME: not complete, we need building presence bitmaps for stuff like farm plots and stockpiles, orientation (N,E,S,W) and state (open/closed)
}; };

@ -37,6 +37,10 @@ namespace DFHack
uint8_t* data; uint8_t* data;
public: public:
DfVector()
{
data = 0;
};
DfVector(uint32_t _start, uint32_t _size, uint32_t _item_size): DfVector(uint32_t _start, uint32_t _size, uint32_t _item_size):
start(_start),size(_size),item_size(_item_size) start(_start),size(_size),item_size(_item_size)
{ {
@ -53,6 +57,7 @@ namespace DFHack
}; };
~DfVector() ~DfVector()
{ {
if(data)
delete [] data; delete [] data;
} }
// get offset of the specified index // get offset of the specified index
@ -73,48 +78,5 @@ namespace DFHack
return size; return size;
}; };
}; };
// nice try, come again...
/*
template <typename T>
class DfVector
{
private:
// starting offset
uint32_t start;
// vector size
uint32_t size;
T* data;
public:
DfVector(uint32_t _start, uint32_t _size):
start(_start),size(_size)
{
Mread(start,size*sizeof(T),data);
};
DfVector(const DfVector <T> & vec)
{
start = vec.start;
size = vec.size;
data = new T[size];
Mread(start,size*sizeof(T),data);
};
~DfVector()
{
delete [] data;
}
// get offset of the specified index
inline T* operator[] (uint32_t index)
{
assert(index < size);
return data + index*sizeof(T);
};
// get vector size
inline uint32_t getSize ()
{
return size;
};
};*/
} }
#endif // DFVECTOR_H_INCLUDED #endif // DFVECTOR_H_INCLUDED

@ -913,6 +913,7 @@
<Address name="window_x">0x00DA061C</Address> <Address name="window_x">0x00DA061C</Address>
<Address name="window_y">0x00DCE6C8</Address> <Address name="window_y">0x00DCE6C8</Address>
<Address name="window_z">0x00DCE6A4</Address> <Address name="window_z">0x00DCE6A4</Address>
<Address name="window_dims">0x01746E98</Address>
</Entry> </Entry>
<Entry version="v0.28.181.40d16" os="windows" base="40d15win"> <Entry version="v0.28.181.40d16" os="windows" base="40d15win">
<!-- identification --> <!-- identification -->
@ -921,6 +922,7 @@
<!-- map_data = 0x01601D84 --> <!-- map_data = 0x01601D84 -->
<!-- door: 0x8e15d4, no VTable rebase needed --> <!-- door: 0x8e15d4, no VTable rebase needed -->
<Address name="items">15BDF50</Address> <Address name="items">15BDF50</Address>
<Offset name="item_materials">0x68</Offset>
<VTable> <VTable>
<class vtable="0x008E04D4" name="item_liquid_misc" /> <class vtable="0x008E04D4" name="item_liquid_misc" />
<class vtable="0x008E07AC" name="item_remains" /> <class vtable="0x008E07AC" name="item_remains" />

@ -11,9 +11,57 @@ using namespace std;
#include <DFTypes.h> #include <DFTypes.h>
#include <DFHackAPI.h> #include <DFHackAPI.h>
int main () struct matGlosses
{
vector<t_matgloss> plantMat;
vector<t_matgloss> woodMat;
vector<t_matgloss> stoneMat;
vector<t_matgloss> metalMat;
vector<t_matgloss> creatureMat;
};
void printItem(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 << "Type: " << (int) item.type << " " << buildingTypes[item.type] << " Address: " << hex << item.origin << endl;
cout << "Material: ";
//If the item is a thread, seed, or creature based, there is no MatType, so the MatType is actually the material
//This should probably be checked in the item function
if(item.type == 113 || item.type == 117) // item_thread or item_seeds
{
cout << mat.plantMat[item.material.type].id;
}
else if(item.type == 114 || item.type == 115 || item.type == 116 || item.type==128 || item.type == 129|| item.type == 130|| item.type == 131) // item_skin_raw item_bones item_skill item_fish_raw item_pet item_skin_tanned item_shell
{ {
cout << mat.creatureMat[item.material.type].id;
}
else{
switch (item.material.type)
{
case 0:
cout << mat.woodMat[item.material.index].id;
break;
case 1:
cout << mat.stoneMat[item.material.index].id;
break;
case 2:
cout << mat.metalMat[item.material.index].id;
break;
case 12: // don't ask me why this has such a large jump, maybe this is not actually the matType for plants, but they all have this set to 12
cout << mat.plantMat[item.material.index].id;
break;
case 121:
cout << mat.creatureMat[item.material.index].id;
break;
default:
cerr << "invalid mat" << (int) item.material.type << " " << (int) item.material.index << endl;
}
}
cout << endl;
}
int main ()
{
DFHack::API DF ("Memory.xml"); DFHack::API DF ("Memory.xml");
if(!DF.Attach()) if(!DF.Attach())
{ {
@ -21,6 +69,12 @@ int main ()
return 1; return 1;
} }
matGlosses mat;
DF.ReadPlantMatgloss(mat.plantMat);
DF.ReadWoodMatgloss(mat.woodMat);
DF.ReadStoneMatgloss(mat.stoneMat);
DF.ReadMetalMatgloss(mat.metalMat);
DF.ReadCreatureMatgloss(mat.creatureMat);
vector <string> buildingtypes; vector <string> buildingtypes;
uint32_t numBuildings = DF.InitReadBuildings(buildingtypes); uint32_t numBuildings = DF.InitReadBuildings(buildingtypes);
@ -37,16 +91,73 @@ int main ()
{ {
break; break;
} }
// else if(next == 'c'){
// cerr << "clearing similarity" << endl;
// similarity.clear();
// continue;
// }
// else if(next == 'p'){
// vector<bool> same(similarity[0].size(),true);
// for(int k =0; k < similarity.size(); k++){
// for(int j =0; j < similarity.size(); j++){
// if(k != j){
// for(int l =0; l < similarity[k].size(); l++){
// if(similarity[k][l] != similarity[j][l]){
// same[l] = false;
// }
// }
// }
// }
// }
// for(int itr =0; itr < same.size(); itr++){
// if(same[itr] == true && similarity[0][itr] != 0){
// cout << hex << itr << " " << hex << (int)similarity[0][itr] << endl;
// }
// }
// continue;
// }
int32_t x,y,z; int32_t x,y,z;
DF.getCursorCoords(x,y,z); DF.getCursorCoords(x,y,z);
vector <t_item> foundItems;
for(uint32_t i = 0; i < numItems; i++) for(uint32_t i = 0; i < numItems; i++)
{ {
t_item temp; 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)
{ {
cout << buildingtypes[temp.type] << " 0x" << hex << temp.origin << endl; foundItems.push_back(temp);
//cout << buildingtypes[temp.type] << " 0x" << hex << temp.origin << endl;
}
}
if(foundItems.size() == 0){
cerr << "No Items at x:" << x << " y:" << y << " z:" << z << endl;
}
else if(foundItems.size() == 1){
printItem(foundItems[0], buildingtypes,mat);
// similarity.push_back(foundItems[0].bytes);
}
else{
cerr << "Please Select which item you want to display\n";
for(int j = 0; j < foundItems.size(); ++j){
cerr << j << " " << buildingtypes[foundItems[j].type] << endl;
}
int value;
string input2;
stringstream ss;
getline(cin, input2);
ss.str(input2);
ss >> value;
while(value >= foundItems.size()){
cerr << "invalid choice, please try again" << endl;
input2.clear();
ss.clear();
getline (cin, input2);
ss.str(input2);
ss >> value;
} }
printItem(foundItems[value], buildingtypes,mat);
// similarity.push_back(foundItems[value].bytes);
} }
DF.FinishReadItems(); DF.FinishReadItems();
} }

@ -32,6 +32,17 @@ int main (void)
cerr << "cursor and window parameters are unsupported on your version of DF" << endl; cerr << "cursor and window parameters are unsupported on your version of DF" << endl;
} }
if(DF.InitViewSize())
{
int32_t width,height;
if(DF.getWindowSize(width,height))
cout << "window size : " << width << " " << height << endl;
}
else
{
cerr << "view size is unsupported on your version of DF" << endl;
}
if(!DF.Detach()) if(!DF.Detach())
{ {
cerr << "Can't detach from DF" << endl; cerr << "Can't detach from DF" << endl;