forked from DFHack/dfhack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdfitemdump.cpp
More file actions
241 lines (228 loc) · 7.37 KB
/
Copy pathdfitemdump.cpp
File metadata and controls
241 lines (228 loc) · 7.37 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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
// Item dump
#include <iostream>
#include <iomanip>
#include <sstream>
#include <climits>
#include <integers.h>
#include <vector>
using namespace std;
#include <DFTypes.h>
#include <DFHackAPI.h>
#include <DFMemInfo.h>
struct matGlosses
{
vector<DFHack::t_matgloss> plantMat;
vector<DFHack::t_matgloss> woodMat;
vector<DFHack::t_matgloss> stoneMat;
vector<DFHack::t_matgloss> metalMat;
vector<DFHack::t_matgloss> creatureMat;
};
string getMaterialType(DFHack::t_item item, const string & itemtype,const matGlosses & mat)
{
// plant thread seeds
if(itemtype == "item_plant" || itemtype == "item_thread" || itemtype == "item_seeds" || itemtype == "item_leaves" )
{
return mat.plantMat[item.material.type].id;
}
else if (itemtype == "item_drink") // drinks must have different offset for materials
{
return "Booze or something";
}
// item_skin_raw item_bones item_skull item_fish_raw item_pet item_skin_tanned item_shell
else if(itemtype == "item_skin_raw" ||
itemtype == "item_skin_tanned" ||
itemtype == "item_fish_raw" ||
itemtype == "item_pet" ||
itemtype == "item_shell" ||
itemtype == "item_horn"||
itemtype == "item_skull" ||
itemtype == "item_bones" ||
itemtype == "item_corpse" ||
itemtype == "item_meat"
)
{
return mat.creatureMat[item.material.type].id;
}
else if(itemtype == "item_wood")
{
return mat.woodMat[item.material.type].id;
}
else if(itemtype == "item_bar")
{
return mat.metalMat[item.material.type].id;
}
else
{
/*
Mat_Wood,
Mat_Stone,
Mat_Metal,
Mat_Plant,
Mat_Leather = 10,
Mat_SilkCloth = 11,
Mat_PlantCloth = 12,
Mat_GreenGlass = 13,
Mat_ClearGlass = 14,
Mat_CrystalGlass = 15,
Mat_Ice = 17,
Mat_Charcoal =18,
Mat_Potash = 19,
Mat_Ashes = 20,
Mat_PearlAsh = 21,
Mat_Soap = 24,
*/
switch (item.material.type)
{
case DFHack::Mat_Wood:
return mat.woodMat[item.material.index].id;
break;
case DFHack::Mat_Stone:
return mat.stoneMat[item.material.index].id;
break;
case DFHack::Mat_Metal:
return mat.metalMat[item.material.index].id;
break;
//case DFHack::Mat_Plant:
case DFHack::Mat_PlantCloth:
//return mat.plantMat[item.material.index].id;
return string(mat.plantMat[item.material.index].id) + " plant";
break;
case 3: // bone
return string(mat.creatureMat[item.material.index].id) + " bone";
case 25: // fat
return string(mat.creatureMat[item.material.index].id) + " fat";
case 23: // tallow
return string(mat.creatureMat[item.material.index].id) + " tallow";
case 9: // shell
return string(mat.creatureMat[item.material.index].id) + " shell";
case DFHack::Mat_Leather: // really a generic creature material. meat for item_food, leather for item_box...
return string(mat.creatureMat[item.material.index].id);
case DFHack::Mat_SilkCloth:
return string(mat.creatureMat[item.material.index].id) + " silk";
case DFHack::Mat_Soap:
return string(mat.creatureMat[item.material.index].id) + " soap";
case DFHack::Mat_GreenGlass:
return "Green Glass";
case DFHack::Mat_ClearGlass:
return "Clear Glass";
case DFHack::Mat_CrystalGlass:
return "Crystal Glass";
case DFHack::Mat_Ice:
return "Ice";
case DFHack::Mat_Charcoal:
return "Charcoal";
/*case DFHack::Mat_Potash:
return "Potash";*/
case DFHack::Mat_Ashes:
return "Ashes";
case DFHack::Mat_PearlAsh:
return "Pearlash";
default:
cout << "unknown material hit: " << item.material.type << " " << item.material.index << " " << itemtype << endl;
return "Invalid";
}
}
return "Invalid";
}
void printItem(DFHack::t_item item, const string & typeString,const matGlosses & mat)
{
cout << dec << "Item at x:" << item.x << " y:" << item.y << " z:" << item.z << endl;
cout << "Type: " << (int) item.type << " " << typeString << " Address: " << hex << item.origin << endl;
cout << "Material: ";
string itemType = getMaterialType(item,typeString,mat);
cout << itemType << endl;
}
int main ()
{
DFHack::API DF ("Memory.xml");
if(!DF.Attach())
{
cerr << "DF not found" << endl;
return 1;
}
DFHack::memory_info * mem = DF.getMemoryInfo();
DF.InitViewAndCursor();
matGlosses mat;
DF.ReadPlantMatgloss(mat.plantMat);
DF.ReadWoodMatgloss(mat.woodMat);
DF.ReadStoneMatgloss(mat.stoneMat);
DF.ReadMetalMatgloss(mat.metalMat);
DF.ReadCreatureMatgloss(mat.creatureMat);
// vector <string> objecttypes;
// DF.getClassIDMapping(objecttypes);
uint32_t numItems;
DF.InitReadItems(numItems);
DF.InitViewAndCursor();
cout << "q to quit, anything else to look up items at that location\n";
while(1)
{
string input;
DF.ForceResume();
getline (cin, input);
DF.Suspend();
//FIXME: why twice?
uint32_t numItems;
DF.InitReadItems(numItems);
if(input == "q")
{
break;
}
int32_t x,y,z;
DF.getCursorCoords(x,y,z);
vector <DFHack::t_item> foundItems;
for(uint32_t i = 0; i < numItems; i++)
{
DFHack::t_item temp;
DF.ReadItem(i, temp);
if(temp.x == x && temp.y == y && temp.z == z)
{
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)
{
string itemtype;
mem->resolveClassIDToClassname(foundItems[0].type,itemtype);
printItem(foundItems[0], itemtype ,mat);
}
else
{
cerr << "Please Select which item you want to display\n";
string itemtype;
for(uint32_t j = 0; j < foundItems.size(); ++j)
{
mem->resolveClassIDToClassname(foundItems[j].type,itemtype);
cerr << j << " " << itemtype << endl;
}
uint32_t 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;
}
mem->resolveClassIDToClassname(foundItems[value].type,itemtype);
printItem(foundItems[value], itemtype ,mat);
}
DF.FinishReadItems();
}
DF.FinishReadBuildings();
DF.Detach();
#ifndef LINUX_BUILD
cout << "Done. Press any key to continue" << endl;
cin.ignore();
#endif
return 0;
}