From 70bf6954a69d060056624ad6ea5f3820e9db2502 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Sun, 7 Feb 2010 02:55:54 +0000 Subject: [PATCH] added dfbauxite by Alex Legg to tools, started working on d17 support --- output/Memory.xml | 385 ++++++++++++++++++++++++------------------- tools/CMakeLists.txt | 5 + tools/dfbauxite.cpp | 145 ++++++++++++++++ tools/dfitemdump.cpp | 5 +- 4 files changed, 369 insertions(+), 171 deletions(-) create mode 100644 tools/dfbauxite.cpp diff --git a/output/Memory.xml b/output/Memory.xml index d050695e1..c7bed9307 100644 --- a/output/Memory.xml +++ b/output/Memory.xml @@ -1174,7 +1174,7 @@ 0x0338 0x033C 0x0340 - 0x034C + 0x034C 0x0364 0x0400 0x0490 @@ -1379,179 +1379,179 @@ - + 022b933926e08da49c6df8649295f2b7 -
0x91ab420
-
0x8F5A2EC
- 0x50 -
0x8F35800
-
0x878493c
-
0x8f467e0
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
0x91ab420
+
0x8F5A2EC
+ 0x50 +
0x8F35800
+
0x878493c
+
0x8f467e0
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 0xC 0x4 0x10 @@ -1562,6 +1562,51 @@ 0x1C 0x20
+ + + 8f55a6250f2550e28535b79db43d5f1a + +
0x878c340
+
0x8947d54
+
0x8947d58
+
0x8947d5c
+
0x91b35fc
+
0x8f3d960
+ +
0x08FA2D3C
+ + +
0x08FA4C04
+ +
0x08FA4368
+ + +
0x8FA2D50
+
0x8FA2D54
+
0x8FA2D58
+ + +
0x8FA2D68
+
0x8FA2D6C
+
0x8FA2D70
+ + + + + + + + + +
diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index 9a70197ef..1e4811df1 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -57,6 +57,11 @@ TARGET_LINK_LIBRARIES(dfsuspend dfhack) ADD_EXECUTABLE(dfitemdump dfitemdump.cpp) 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 ADD_EXECUTABLE(dfitemdesignator itemdesignator.cpp) TARGET_LINK_LIBRARIES(dfitemdesignator dfhack) diff --git a/tools/dfbauxite.cpp b/tools/dfbauxite.cpp new file mode 100644 index 000000000..a17870ac6 --- /dev/null +++ b/tools/dfbauxite.cpp @@ -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 +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 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 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; +} diff --git a/tools/dfitemdump.cpp b/tools/dfitemdump.cpp index 1fa7e6462..85930ec7a 100644 --- a/tools/dfitemdump.cpp +++ b/tools/dfitemdump.cpp @@ -84,6 +84,7 @@ int main () cerr << "DF not found" << endl; return 1; } + DF.Suspend(); DF.InitViewAndCursor(); matGlosses mat; DF.ReadPlantMatgloss(mat.plantMat); @@ -96,6 +97,7 @@ int main () vector buildingtypes; DF.InitReadBuildings(buildingtypes); uint32_t numItems = DF.InitReadItems(); + /* map< string, map > > count; for(uint32_t i=0; i< numItems; i++){ DFHack::t_item temp; @@ -103,7 +105,8 @@ int main () // cout << int(temp.type) << endl; count[buildingtypes[temp.type]][getMaterialType(temp,buildingtypes,mat)].push_back(i); } - + */ + DF.InitViewAndCursor(); cout << "q to quit, anything else to look up items at that location\n"; while(1)