2010-02-06 19:55:54 -07:00
|
|
|
/*
|
|
|
|
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 <sstream>
|
2010-02-27 21:35:54 -07:00
|
|
|
#include <iostream>
|
|
|
|
#include <string.h>
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <assert.h>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
2010-02-06 19:55:54 -07:00
|
|
|
using namespace std;
|
|
|
|
|
2010-02-27 21:35:54 -07:00
|
|
|
|
|
|
|
#include <integers.h>
|
|
|
|
#include <Export.h>
|
|
|
|
#include <DFError.h>
|
|
|
|
#include <DFVector.h>
|
|
|
|
#include <DFMemInfo.h>
|
|
|
|
#include <DFProcess.h>
|
|
|
|
#include <DFTypes.h>
|
|
|
|
#include <DFHackAPI.h>
|
|
|
|
using namespace DFHack;
|
|
|
|
|
|
|
|
|
2010-02-06 19:55:54 -07:00
|
|
|
int main ()
|
|
|
|
{
|
|
|
|
DFHack::Process *proc;
|
|
|
|
DFHack::memory_info *meminfo;
|
2010-04-18 06:56:09 -06:00
|
|
|
DFHack::DfVector <uint32_t> *items_vector;
|
2010-02-06 19:55:54 -07:00
|
|
|
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;
|
|
|
|
|
2010-05-23 15:06:10 -06:00
|
|
|
DFHack::ContextManager DF("Memory.xml");
|
2010-03-26 06:01:46 -06:00
|
|
|
try
|
2010-02-06 19:55:54 -07:00
|
|
|
{
|
2010-03-26 06:01:46 -06:00
|
|
|
DF.Attach();
|
|
|
|
}
|
|
|
|
catch (exception& e)
|
|
|
|
{
|
|
|
|
cerr << e.what() << endl;
|
|
|
|
#ifndef LINUX_BUILD
|
|
|
|
cin.ignore();
|
|
|
|
#endif
|
2010-02-06 19:55:54 -07:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2010-02-27 21:35:54 -07:00
|
|
|
// Find out which material is bauxite
|
2010-02-06 19:55:54 -07:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2010-02-27 21:35:54 -07:00
|
|
|
// Get some basics needed for full access
|
2010-02-06 19:55:54 -07:00
|
|
|
proc = DF.getProcess();
|
|
|
|
meminfo = proc->getDescriptor();
|
|
|
|
|
2010-02-27 21:35:54 -07:00
|
|
|
// Get the object name/ID mapping
|
2010-02-06 19:55:54 -07:00
|
|
|
//FIXME: work on the 'supported features' system required
|
2010-02-27 21:35:54 -07:00
|
|
|
|
|
|
|
// Check availability of required addresses and offsets (doing custom stuff here)
|
|
|
|
|
2010-02-06 19:55:54 -07:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2010-04-18 06:56:09 -06:00
|
|
|
items_vector = new DFHack::DfVector <uint32_t> (proc, items);
|
|
|
|
for(uint32_t i = 0; i < items_vector->size(); i++)
|
2010-02-06 19:55:54 -07:00
|
|
|
{
|
|
|
|
// get pointer to object
|
2010-04-18 06:56:09 -06:00
|
|
|
temp = items_vector->at (i);
|
2010-02-06 19:55:54 -07:00
|
|
|
// 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
|
2010-02-25 05:41:57 -07:00
|
|
|
if(!meminfo->resolveObjectToClassID (temp, type))
|
|
|
|
continue;
|
|
|
|
string classname;
|
|
|
|
if(!meminfo->resolveClassIDToClassname (type, classname))
|
2010-02-06 19:55:54 -07:00
|
|
|
continue;
|
|
|
|
|
2010-02-25 05:41:57 -07:00
|
|
|
if(classname == "item_trapparts")
|
2010-02-06 19:55:54 -07:00
|
|
|
{
|
|
|
|
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
|
2010-02-27 21:35:54 -07:00
|
|
|
|
2010-02-06 19:55:54 -07:00
|
|
|
return 0;
|
|
|
|
}
|