added dfbauxite by Alex Legg to tools, started working on d17 support

develop
Petr Mrázek 2010-02-07 02:55:54 +00:00
parent 193a6f4d62
commit 70bf6954a6
4 changed files with 369 additions and 171 deletions

@ -1379,7 +1379,7 @@
<VTable rebase="0x260" /> <VTable rebase="0x260" />
<!--<class vtable="0x086c78c8" name="door"/>--> <!--<class vtable="0x086c78c8" name="door"/>-->
</Entry> </Entry>
<Entry version="v0.28.181.40d16" os="linux" base="40d15lin"> <Entry version="v0.28.181.40d16" os="linux" id="40d16lin" base="40d15lin">
<!-- identification --> <!-- identification -->
<String name="md5">022b933926e08da49c6df8649295f2b7</String> <String name="md5">022b933926e08da49c6df8649295f2b7</String>
<!-- map_data = 0x8F9ABDC --> <!-- map_data = 0x8F9ABDC -->
@ -1562,6 +1562,51 @@
<Offset name="matgloss_plant_food">0x1C</Offset> <Offset name="matgloss_plant_food">0x1C</Offset>
<Offset name="matgloss_plant_extract">0x20</Offset> <Offset name="matgloss_plant_extract">0x20</Offset>
</Entry> </Entry>
<Entry version="v0.28.181.40d17" os="linux" id="40d17lin" base="40d16lin">
<!-- identification -->
<String name="md5">8f55a6250f2550e28535b79db43d5f1a</String>
<!-- positions -->
<Address name="cursor_xyz">0x878c340</Address> <!-- 0x0877B33C -->
<Address name="window_x">0x8947d54</Address> <!--0x893ABD4-->
<Address name="window_y">0x8947d58</Address> <!--0x893ABD8-->
<Address name="window_z">0x8947d5c</Address> <!-- 0x893ABDC -->
<Address name="window_dims">0x91b35fc</Address> <!-- 0x091a647c -->
<Address name="pause_state">0x8f3d960</Address> <!-- 0x8F35800 -->
<!-- map data -->
<Address name="map_data">0x08FA2D3C</Address><!-- 0x08F95BBC -->
<!-- matgloss -->
<!--<Address name="matgloss">0x08F97A84</Address>-->
<Address name="matgloss">0x08FA4C04</Address>
<!-- the world base -->
<Address name="world">0x08FA4368</Address>
<!-- size of the map -->
<Address name="x_count">0x8FA2D50</Address> <!-- 0x08F95BD0 -->
<Address name="y_count">0x8FA2D54</Address>
<Address name="z_count">0x8FA2D58</Address>
<!-- position of the map in world coords -->
<Address name="region_x">0x8FA2D68</Address>
<Address name="region_y">0x8FA2D6C</Address>
<Address name="region_z">0x8FA2D70</Address>
<!--<class vtable="0x086c78c8" name="door"/>-->
<!--
<Address name="constructions">0x08F41918</Address>
<Address name="buildings">0x08F55740</Address>
<Address name="vegetation">0x08F58890</Address>
<Address name="creatures">0x08F55250</Address>
-->
<!-- translation tables -->
<!--
<Address name="translation_vector">0x08F97BA4</Address>
<Address name="language_vector">0x08F97B8C</Address>
-->
<!--<VTable rebase="-0xd6f00" />-->
<!--<class vtable="0x086C3968" name="door"/>-->
</Entry>
</MemoryDescriptors> </MemoryDescriptors>
<!-- Windows logo by M$, spiderweb by jgs --> <!-- Windows logo by M$, spiderweb by jgs -->
</DFExtractor> </DFExtractor>

@ -57,6 +57,11 @@ TARGET_LINK_LIBRARIES(dfsuspend dfhack)
ADD_EXECUTABLE(dfitemdump dfitemdump.cpp) ADD_EXECUTABLE(dfitemdump dfitemdump.cpp)
TARGET_LINK_LIBRARIES(dfitemdump dfhack) TARGET_LINK_LIBRARIES(dfitemdump dfhack)
# bauxite - turn all mechanisms into bauxite mechanisms
# Author: Alex Legg
ADD_EXECUTABLE(dfbauxite dfbauxite.cpp)
TARGET_LINK_LIBRARIES(dfbauxite dfhack)
# itemdesignator - change some item designations (dump, forbid, on-fire) for all items of a given type and material # itemdesignator - change some item designations (dump, forbid, on-fire) for all items of a given type and material
ADD_EXECUTABLE(dfitemdesignator itemdesignator.cpp) ADD_EXECUTABLE(dfitemdesignator itemdesignator.cpp)
TARGET_LINK_LIBRARIES(dfitemdesignator dfhack) TARGET_LINK_LIBRARIES(dfitemdesignator dfhack)

@ -0,0 +1,145 @@
/*
DFBauxite - Converts all your mechanisms to bauxite (for use in magma).
Author: Alex Legg
Based on code from and uses DFHack - www.sourceforge.net/projects/dfhack
*/
#include "DFCommonInternal.h"
#include <sstream>
using namespace std;
int main ()
{
DFHack::Process *proc;
DFHack::memory_info *meminfo;
DFHack::DfVector *items_vector;
DFHack::t_item_df40d item_40d;
DFHack::t_matglossPair item_40d_material;
vector<DFHack::t_matgloss> stoneMat;
uint32_t item_material_offset;
uint32_t temp;
int32_t type;
int items;
int found = 0, converted = 0;
DFHack::API DF ("Memory.xml");
if(!DF.Attach())
{
cerr << "DF not found" << endl;
return 1;
}
DF.Suspend();
/*
* Find out which material is bauxite
*/
if(!DF.ReadStoneMatgloss(stoneMat))
{
cout << "Materials not supported for this version of DF, exiting." << endl;
#ifndef LINUX_BUILD
cin.ignore();
#endif
DF.Detach();
return EXIT_FAILURE;
}
int bauxiteIndex = -1;
for (int i = 0; i < stoneMat.size();i++)
{
if(strcmp(stoneMat[i].id, "BAUXITE") == 0)
{
bauxiteIndex = i;
break;
}
}
if(bauxiteIndex == -1)
{
cout << "Cannot locate bauxite in the DF raws, exiting" << endl;
#ifndef LINUX_BUILD
cin.ignore();
#endif
DF.Detach();
return EXIT_FAILURE;
}
//FIXME: very counter-intuitive, fix the API. This returns a mapping from the internal ID to the object name
// internal IDs can be obtained by using resolveClassId
//FIXME: Proper error reporting/exceptions support is sorely needed
/*
* Get the object name/ID mapping
*/
vector <string> buildingtypes;
uint32_t numBuildings = DF.InitReadBuildings(buildingtypes);
proc = DF.getProcess();
meminfo = proc->getDescriptor();
//FIXME: work on the 'supported features' system required
/*
* Check availability of required addresses and offsets (doing custom stuff here)
*/
items = meminfo->getAddress("items");
item_material_offset = meminfo->getOffset("item_materials");
if( !items || ! item_material_offset)
{
cout << "Items not supported for this DF version, exiting" << endl;
#ifndef LINUX_BUILD
cin.ignore();
#endif
DF.Detach();
return EXIT_FAILURE;
}
items_vector = new DFHack::DfVector (proc->getDataModel()->readVector (items, 4));
for(uint32_t i = 0; i < items_vector->getSize(); i++)
{
// get pointer to object
temp = * (uint32_t *) items_vector->at (i);
// read object
proc->read (temp, sizeof (DFHack::t_item_df40d), (uint8_t *) &item_40d);
// resolve object type
type = -1;
// skip things we can't identify
if(!meminfo->resolveClassId (temp, type))
continue;
if(buildingtypes[type] == "item_trapparts")
{
proc->read (temp + item_material_offset, sizeof (DFHack::t_matglossPair), (uint8_t *) &item_40d_material);
cout << dec << "Mechanism at x:" << item_40d.x << " y:" << item_40d.y << " z:" << item_40d.z << " ID:" << item_40d.ID << endl;
if (item_40d_material.index != bauxiteIndex)
{
item_40d_material.index = bauxiteIndex;
proc->write (temp + item_material_offset, sizeof (DFHack::t_matglossPair), (uint8_t *) &item_40d_material);
converted++;
}
found++;
}
}
if (found == 0)
{
cout << "No mechanisms to convert" << endl;
} else {
cout << found << " mechanisms found" << endl;
cout << converted << " mechanisms converted" << endl;
}
DF.Resume();
DF.Detach();
delete items_vector;
#ifndef LINUX_BUILD
cout << "Done. Press any key to continue" << endl;
cin.ignore();
#endif
return 0;
}

@ -84,6 +84,7 @@ int main ()
cerr << "DF not found" << endl; cerr << "DF not found" << endl;
return 1; return 1;
} }
DF.Suspend();
DF.InitViewAndCursor(); DF.InitViewAndCursor();
matGlosses mat; matGlosses mat;
DF.ReadPlantMatgloss(mat.plantMat); DF.ReadPlantMatgloss(mat.plantMat);
@ -96,6 +97,7 @@ int main ()
vector <string> buildingtypes; vector <string> buildingtypes;
DF.InitReadBuildings(buildingtypes); DF.InitReadBuildings(buildingtypes);
uint32_t numItems = DF.InitReadItems(); uint32_t numItems = DF.InitReadItems();
/*
map< string, map<string,vector<uint32_t> > > count; map< string, map<string,vector<uint32_t> > > count;
for(uint32_t i=0; i< numItems; i++){ for(uint32_t i=0; i< numItems; i++){
DFHack::t_item temp; DFHack::t_item temp;
@ -103,6 +105,7 @@ int main ()
// cout << int(temp.type) << endl; // cout << int(temp.type) << endl;
count[buildingtypes[temp.type]][getMaterialType(temp,buildingtypes,mat)].push_back(i); count[buildingtypes[temp.type]][getMaterialType(temp,buildingtypes,mat)].push_back(i);
} }
*/
DF.InitViewAndCursor(); DF.InitViewAndCursor();
cout << "q to quit, anything else to look up items at that location\n"; cout << "q to quit, anything else to look up items at that location\n";