dfhack/tools/examples/spatterdump.cpp

198 lines
5.0 KiB
C++

2010-04-07 14:28:05 -06:00
// Just show some position data
#include <iostream>
#include <iomanip>
#include <climits>
#include <vector>
#include <sstream>
#include <ctime>
#include <cstdio>
using namespace std;
2010-06-04 16:02:02 -06:00
#define DFHACK_WANT_MISCUTILS
2010-05-25 22:48:23 -06:00
#include <DFHack.h>
2010-04-07 14:28:05 -06:00
using namespace DFHack;
2011-05-15 14:24:40 -06:00
//FIXME: A pile of magic numbers. looks like decompiled number
2010-04-08 11:48:06 -06:00
typedef uint32_t _DWORD;
int get_material_vector(uint32_t vein_8, uint16_t vein_4, int WORLD_)
{
int result; // eax@2
int v4; // ecx@11
int v5; // eax@12
if ( (uint16_t)(vein_4 - 0x1A3) > 0xC7u )
{
if ( ((int16_t)vein_4 < 19 || (int16_t)vein_4 > 0xDAu)
&& (uint16_t)(vein_4 - 219) > 0xC7u )
{
if ( vein_4 )
{
if ( vein_4 > 0x292u )
result = 0;
else
result = *(_DWORD *)(WORLD_ + 4 * (int16_t)vein_4 + 0x5DF44);
}
else
{
if ( (signed int)vein_8 >= 0
&& (v4 = *(_DWORD *)(WORLD_ + 0x54B88), vein_8 < (*(_DWORD *)(WORLD_ + 0x54B8C) - v4) >> 2)
&& (v5 = *(_DWORD *)(v4 + 4 * vein_8)) != 0 )
result = v5 + 0x178;
else
result = *(_DWORD *)(WORLD_ + 0x5DF44);
}
}
else
{
/*
result = sub_4D47A0(vein_8, vein_4, WORLD_ + 0x54C84);
if ( !result )
result = *(_DWORD *)(WORLD_ + 0x5DF90);
*/
}
}
else
{
/*
result = sub_41F430(WORLD_ + 0x54B94, vein_4);
if ( !result )
result = *(_DWORD *)(WORLD_ + 0x5E5D0);
*/
}
return result;
}
char shades[10] = {'#','$','O','=','+','|','-','^','.',' '};
2010-04-08 11:48:06 -06:00
void printSpatter(DFHack::Context * DF, t_spattervein & spatter)
{
DFHack::Materials *Mats = DF->getMaterials();
printf("Splatter\nmat1: %d\nunknown: %d\nmat2: %d\n",spatter.mat1,spatter.unk1,spatter.mat2);
printf ("Material : %d - ", spatter.matter_state);
// FIXME: stupid
switch(spatter.matter_state)
{
case state_gas:
printf("Gas ");
break;
case state_solid:
printf("Solid ");
break;
case state_liquid:
printf("Liquid ");
break;
case state_paste:
printf("Paste ");
break;
case state_powder:
printf("Powder ");
break;
case state_pressed:
printf("Pressed ");
break;
default:
printf("Unknown state ");
}
cout << PrintSplatterType(spatter.mat1,spatter.mat2,Mats->race) << endl;
printf("Address 0x%08x\n",spatter.address_of);
for(uint32_t yyy = 0; yyy < 16; yyy++)
{
cout << "|";
for(uint32_t xxx = 0; xxx < 16; xxx++)
{
uint8_t intensity = spatter.intensity[xxx][yyy];
cout << shades[9 - (intensity / 28)];
}
cout << "|" << endl;
}
hexdump(DF, spatter.address_of,20*16);
}
2010-04-08 11:48:06 -06:00
2010-04-07 14:28:05 -06:00
int main (int numargs, const char ** args)
{
uint32_t x_max,y_max,z_max;
vector<t_vein> veinVector;
vector<t_frozenliquidvein> IceVeinVector;
vector<t_spattervein> splatter;
2010-05-23 15:06:10 -06:00
DFHack::ContextManager DFMgr("Memory.xml");
DFHack::Context * DF;
2010-04-07 14:28:05 -06:00
try
{
2010-05-23 15:06:10 -06:00
DF = DFMgr.getSingleContext();
DF->Attach();
2010-04-07 14:28:05 -06:00
}
catch (exception& e)
{
cerr << e.what() << endl;
#ifndef LINUX_BUILD
cin.ignore();
#endif
return 1;
}
2010-05-23 15:06:10 -06:00
DFHack::Maps *Maps =DF->getMaps();
2011-03-18 04:38:37 -06:00
DFHack::Gui *Gui =DF->getGui();
2010-05-23 15:06:10 -06:00
DFHack::Materials *Mats =DF->getMaterials();
2010-04-07 15:56:23 -06:00
2010-04-28 10:09:32 -06:00
Mats->ReadCreatureTypes();
2010-04-07 15:56:23 -06:00
2010-04-07 14:28:05 -06:00
// init the map
if(!Maps->Start())
{
cerr << "Can't init map." << endl;
#ifndef LINUX_BUILD
cin.ignore();
#endif
return 1;
}
2010-04-07 15:56:23 -06:00
2010-04-07 14:28:05 -06:00
int32_t cx, cy, cz;
Maps->getSize(x_max,y_max,z_max);
2011-03-18 04:38:37 -06:00
Gui->getCursorCoords(cx,cy,cz);
2010-04-07 14:28:05 -06:00
if(cx == -30000)
{
// walk the map
for(uint32_t x = 0; x< x_max;x++) for(uint32_t y = 0; y< y_max;y++) for(uint32_t z = 0; z< z_max;z++)
{
if(Maps->isValidBlock(x,y,z))
{
// look for splater veins
Maps->ReadVeins(x,y,z,0,0,&splatter);
2010-04-07 14:28:05 -06:00
if(splatter.size())
{
printf("Block %d/%d/%d\n",x,y,z);
2010-04-09 19:49:37 -06:00
for(uint32_t i = 0; i < splatter.size(); i++)
2010-04-07 14:28:05 -06:00
{
cout << i << ":" << endl;
printSpatter(DF,splatter[i]);
2010-04-07 14:28:05 -06:00
}
}
}
}
}
else
{
uint32_t bx,by,bz;
bx = cx / 16;
by = cy / 16;
bz = cz;
// look for splater veins
Maps->ReadVeins(bx,by,bz,0,0,&splatter);
2010-04-07 14:28:05 -06:00
if(splatter.size())
{
printf("Block %d/%d/%d\n",bx,by,bz);
2010-04-09 19:49:37 -06:00
for(uint32_t i = 0; i < splatter.size(); i++)
2010-04-07 14:28:05 -06:00
{
printSpatter(DF,splatter[i]);
2010-04-07 14:28:05 -06:00
cout << endl;
}
}
}
#ifndef LINUX_BUILD
cout << "Done. Press any key to continue" << endl;
cin.ignore();
#endif
return 0;
}