Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 14 15 [16] 17 18 ... 108

Author Topic: DFHack 0.5.15 (legacy)  (Read 401034 times)

peterix

  • Bay Watcher
    • View Profile
    • Dethware
Re: DFHack 0.4.0.7b - tools and memory access library
« Reply #225 on: August 23, 2010, 05:04:01 am »

I'm looking for a way to only return one value per call so that dllcall can handle it. Any help would be appreciated, but I hope you don't feel obligated to do much.  :D

You want to write a simple DLL that just calls DFHack and then returns only 1 of the co-ordinates.

edit: @peterix: is there any kind of standard for making GUI apps with DFHack so that they remain cross-platform?
Not really a standard, but it should be possible to use the Qt libraries for example. I'll be using those for GUI DFHack tools. Any cross-platform GUI framework (or 3D engine) should work though.

sizeak

  • Bay Watcher
    • View Profile
Re: DFHack 0.4.0.7b - tools and memory access library
« Reply #226 on: August 23, 2010, 05:16:37 am »

Runesmith uses Qt too and I believe Dwarf Foreman might as well.
Logged
Runesmith - http://www.bay12forums.com/smf/index.php?topic=59056.0 - A Dwarf Companion like tool

Shukaro

  • Bay Watcher
    • View Profile
Re: DFHack 0.4.0.7b - tools and memory access library
« Reply #227 on: August 23, 2010, 12:13:55 pm »

mLegion: Thanks, that's what I'm doing now, just have to read up on C++ syntax first.  :D
Logged
Urist McHauler Cancels Give Food: Patient Insane
------------------------------------------------------------------
Mouse Fortress | Custom Menu and Hotkey Framework
Dwarven Higher Learning Mod | Alternative Skill Training

Quietust

  • Bay Watcher
  • Does not suffer fools gladly
    • View Profile
    • QMT Productions
Re: DFHack 0.4.0.7b - tools and memory access library
« Reply #228 on: August 23, 2010, 03:08:58 pm »

I've got another simple tool to submit: getting rid of water sitting in buckets (and thus preventing said buckets from being used for anything).

Code: [Select]
// boils away all pools of liquid water (generally sitting in buckets)
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <climits>
#include <vector>
using namespace std;

#include <DFHack.h>
#include <dfhack/DFVector.h>
#include <dfhack/DFTypes.h>
#include <dfhack/modules/Items.h>

DFHack::Items * Items;

int main ()
{
    DFHack::Process * p;
    unsigned int i;
    DFHack::ContextManager DFMgr("Memory.xml");
    DFHack::Context * DF;
    try
    {
        DF = DFMgr.getSingleContext();
        DF->Attach();
    }
    catch (exception& e)
    {
        cerr << e.what() << endl;
#ifndef LINUX_BUILD
        cin.ignore();
#endif
        return 1;
    }

    DFHack::memory_info * mem = DF->getMemoryInfo();
    p = DF->getProcess();
    DFHack::DfVector <uint32_t> p_items (p, p->getDescriptor()->getAddress ("items_vector"));
    uint32_t size = p_items.size();
    Items = DF->getItems();

    int numboiled = 0;
    for (i=0;i<size;i++)
    {
        DFHack::t_item item;
        if (!Items->getItemData(p_items[i], item))
            continue;
        if (item.matdesc.itemType != 72) // LIQUID_MISC
            continue;
        // haven't checked, but one of the other members of item.matdesc might contain this value as well
        if (p->readWord(p_items[i] + 0x0090) != 6) // WATER
            continue;
        // technically, the temperature just needs to be raised far enough so that it's still above 10180 after one step
        p->writeDWord(p_items[i] + 0x0078, 10200);
        numboiled++;
    }
    cout << "Found and boiled away " << numboiled << " puddles of water." << endl;

#ifndef LINUX_BUILD
    cout << "Done. Press any key to continue" << endl;
    cin.ignore();
#endif
    return 0;
}

Disclaimer: the water is removed by making it boil away, and the resulting steam may or may not do damage to your dwarves.
« Last Edit: August 23, 2010, 03:11:03 pm by Quietust »
Logged
P.S. If you don't get this note, let me know and I'll write you another.
It's amazing how dwarves can make a stack of bones completely waterproof and magmaproof.
It's amazing how they can make an entire floodgate out of the bones of 2 cats.

Teocali

  • Escaped Lunatic
    • View Profile
Re: DFHack 0.4.0.7b - tools and memory access library
« Reply #229 on: August 25, 2010, 03:51:03 am »

Hello,

I'm not sure that the good place to ask a dev. question, but as I don't find any forum or FAQ page on the DFHack Github page...

So, I'm really new at Linux Dev, but I'm trying to compile DFhack on my Ubuntu (as the only package version is available for ArchLinux)

Aftert having some probleme with the X11 lib and the Doxygen tool, I'm currently stuck with some ncurse file entry missing. I have tried to install every ncurse package on Synaptic (and restarting Cmake and/or deleting the CMakeCache.txt file), but I'm still having some CMake entries marked as "NOTFOUND".

Here the list, extracted from the CMakeCache.txt file.
Code: [Select]
CURSES_EXTRA_LIBRARY:FILEPATH=CURSES_EXTRA_LIBRARY-NOTFOUND
CURSES_HAVE_NCURSESW_H:FILEPATH=CURSES_HAVE_NCURSESW_H-NOTFOUND
CURSES_HAVE_NCURSES_CURSES_H:FILEPATH=CURSES_HAVE_NCURSES_CURSES_H-NOTFOUND
CURSES_HAVE_NCURSES_H:FILEPATH=CURSES_HAVE_NCURSES_H-NOTFOUND
CURSES_HAVE_NCURSES_NCURSES_H:FILEPATH=CURSES_HAVE_NCURSES_NCURSES_H-NOTFOUND
CURSES_INCLUDE_PATH:FILEPATH=CURSES_CURSES_H_PATH-NOTFOUND CURSES_CURSESW_H_PATH-NOTFOUND
CURSES_NCURSES_INCLUDE_PATH:PATH=CURSES_NCURSES_INCLUDE_PATH-NOTFOUND
FORM_LIBRARY:FILEPATH=CURSES_FORM_LIBRARY-NOTFOUND
Any hints will be welcome. Thanks in advance.

EDIT : Ok, forget this.  The make file are now correctly generated. I think i had deleted the wrong file, somewhere. Sorry about that.

Regards,
Teocali
« Last Edit: August 25, 2010, 04:05:53 am by Teocali »
Logged

Teocali

  • Escaped Lunatic
    • View Profile
Re: DFHack 0.4.0.7b - tools and memory access library
« Reply #230 on: August 25, 2010, 06:28:51 am »

Yey, another question from the newb'

As said juste before, i'm trying to use DFHack on the latest version of DF on an Ubuntu Linux.

After some aventures with CMake, I have compiled the tools for Linux, but when I try to launch the dfcreaturedump tool, I just get an std::bad_alloc exception.

I've tried to look in the code, and this exception is raised when the program is trying to read all the materials of DF (line 443, Search the string "Just Here" if you're interested)
Code: [Select]

// Creature dump

#include <iostream>
#include <climits>
#include <string.h>
#include <vector>
#include <stdio.h>
using namespace std;

#define DFHACK_WANT_MISCUTILS
#include <DFHack.h>

enum likeType
{
    FAIL = 0,
    MATERIAL = 1,
    ITEM = 2,
    FOOD = 3
};

DFHack::Materials * Materials;
DFHack::memory_info *mem;
vector< vector<string> > englishWords;
vector< vector<string> > foreignWords;
DFHack::Creatures * Creatures = NULL;
uint32_t current_year;
uint32_t current_tick;
/*
likeType printLike40d(DFHack::t_like like, const matGlosses & mat,const vector< vector <DFHack::t_itemType> > & itemTypes)
{ // The function in DF which prints out the likes is a monster, it is a huge switch statement with tons of options and calls a ton of other functions as well,
    //so I am not going to try and put all the possibilites here, only the low hanging fruit, with stones and metals, as well as items,
    //you can easily find good canidates for military duty for instance
    //The ideal thing to do would be to call the df function directly with the desired likes, the df function modifies a string, so it should be possible to do...
    if(like.active){
        if(like.type ==0){
            switch (like.material.type)
            {
            case 0:
                cout << mat.woodMat[like.material.index].name;
                return(MATERIAL);
            case 1:
                cout << mat.stoneMat[like.material.index].name;
                return(MATERIAL);
            case 2:
                cout << mat.metalMat[like.material.index].name;
                return(MATERIAL);
            case 12: // don't ask me why this has such a large jump, maybe this is not actually the matType for plants, but they all have this set to 12
                cout << mat.plantMat[like.material.index].name;
                return(MATERIAL);
            case 32:
                cout << mat.plantMat[like.material.index].name;
                return(MATERIAL);
            case 121:
                cout << mat.creatureMat[like.material.index].name;
                return(MATERIAL);
            default:
                return(FAIL);
            }
        }
        else if(like.type == 4 && like.itemIndex != -1){
            switch(like.itemClass)
            {
            case 24:
                cout << itemTypes[0][like.itemIndex].name;
                return(ITEM);
            case 25:
                cout << itemTypes[4][like.itemIndex].name;
                return(ITEM);
            case 26:
                cout << itemTypes[8][like.itemIndex].name;
                return(ITEM);
            case 27:
                cout << itemTypes[9][like.itemIndex].name;
                return(ITEM);
            case 28:
                cout << itemTypes[10][like.itemIndex].name;
                return(ITEM);
            case 29:
                cout << itemTypes[7][like.itemIndex].name;
                return(ITEM);
            case 38:
                cout << itemTypes[5][like.itemIndex].name;
                return(ITEM);
            case 63:
                cout << itemTypes[11][like.itemIndex].name;
                return(ITEM);
            case 68:
            case 69:
                cout << itemTypes[6][like.itemIndex].name;
                return(ITEM);
            case 70:
                cout << itemTypes[1][like.itemIndex].name;
                return(ITEM);
            default:
          //      cout << like.itemClass << ":" << like.itemIndex;
                return(FAIL);
            }
        }
        else if(like.material.type != -1){// && like.material.index == -1){
            if(like.type == 2){
                switch(like.itemClass)
                {
                case 52:
                case 53:
                case 58:
                    cout << mat.plantMat[like.material.type].name;
                    return(FOOD);
                case 72:
                    if(like.material.type =! 10){ // 10 is for milk stuff, which I don't know how to do
                        cout << mat.plantMat[like.material.index].extract_name;
                        return(FOOD);
                    }
                    return(FAIL);
                case 74:
                    cout << mat.plantMat[like.material.index].drink_name;
                    return(FOOD);
                case 75:
                    cout << mat.plantMat[like.material.index].food_name;
                    return(FOOD);
                case 47:
                case 48:
                    cout << mat.creatureMat[like.material.type].name;
                    return(FOOD);
                default:
                    return(FAIL);
                }
            }
        }
    }
    return(FAIL);
}
*/

void printCreature(DFHack::Context * DF, const DFHack::t_creature & creature)
{
    uint32_t dayoflife;
cout << "address: " << hex <<  creature.origin << dec << " creature type: " << Materials->raceEx[creature.race].rawname
                << "[" << Materials->raceEx[creature.race].tile_character
                << "," << Materials->raceEx[creature.race].tilecolor.fore
                << "," << Materials->raceEx[creature.race].tilecolor.back
                << "," << Materials->raceEx[creature.race].tilecolor.bright
                << "]"
                << ", position: " << creature.x << "x " << creature.y << "y "<< creature.z << "z" << endl;
        bool addendl = false;
        if(creature.name.first_name[0])
        {
            cout << "first name: " << creature.name.first_name;
            addendl = true;
        }
        if(creature.name.nickname[0])
        {
            cout << ", nick name: " << creature.name.nickname;
            addendl = true;
        }

        DFHack::Translation *Tran = DF->getTranslation();
        DFHack::memory_info *mem = DF->getMemoryInfo();

        string transName = Tran->TranslateName(creature.name,false);
        if(!transName.empty())
        {
            cout << ", trans name: " << transName;
            addendl=true;
        }

        transName = Tran->TranslateName(creature.name,true);
        if(!transName.empty())
        {
            cout << ", last name: " << transName;
            addendl=true;
        }

        if(creature.civ)
        {
            cout << "civilization: " << creature.civ;
            addendl = true;
        }

        /*
        cout << ", likes: ";
        for(uint32_t i = 0;i<creature.numLikes; i++)
        {
            if(printLike(creature.likes[i],mat,itemTypes))
            {
                cout << ", ";
            }
        }
        */
        if(addendl)
        {
            cout << endl;
            addendl = false;
        }
        cout << "profession: " << mem->getProfession(creature.profession) << "(" << (int) creature.profession << ")";

        if(creature.custom_profession[0])
        {
            cout << ", custom profession: " << creature.custom_profession;
        }
        /*
        if(creature.current_job.active)
        {
            cout << ", current job: " << mem->getJob(creature.current_job.jobId);
        }
        */
        cout << endl;
        dayoflife = creature.birth_year*12*28 + creature.birth_time/1200;
        cout << "Born on the year " << creature.birth_year << ", month " << (creature.birth_time/1200/28) << ", day " << ((creature.birth_time/1200) % 28 + 1) << ", " << dayoflife << " days lived." << endl;
        cout << "Appearance : ";
        for(unsigned int i = 0; i<creature.nbcolors ; i++)
        {
            cout << Materials->raceEx[creature.race].castes[creature.caste].ColorModifier[i].part << " ";
            uint32_t color = Materials->raceEx[creature.race].castes[creature.caste].ColorModifier[i].colorlist[creature.color[i]];
            if(color<Materials->color.size())
                cout << Materials->color[color].name << "["
                    << (unsigned int) (Materials->color[color].r*255) << ":"
                    << (unsigned int) (Materials->color[color].v*255) << ":"
                    << (unsigned int) (Materials->color[color].b*255) << "]";
            else
                cout << Materials->alldesc[color].id;
            if( Materials->raceEx[creature.race].castes[creature.caste].ColorModifier[i].startdate > 0 )
            {
                if( (Materials->raceEx[creature.race].castes[creature.caste].ColorModifier[i].startdate <= dayoflife) &&
                    (Materials->raceEx[creature.race].castes[creature.caste].ColorModifier[i].enddate > dayoflife) )
                    cout << "[active]";
                else
                    cout << "[inactive]";
            }
            cout << " - ";

        }
        cout << endl;
        cout << "happiness: "   << creature.happiness
             << ", strength: "  << creature.strength.level
             << ", agility: "   << creature.agility.level
             << ", toughness: " << creature.toughness.level
             << ", endurance: " << creature.endurance.level
             << ", recuperation: " << creature.recuperation.level
             << ", disease resistance: " << creature.disease_resistance.level
             //<< ", money: " << creature.money
             << ", id: " << creature.id;
        /*
        if(creature.squad_leader_id != -1)
        {
            cout << ", squad_leader_id: " << creature.squad_leader_id;
        }
        if(creature.mood != -1){
            cout << ", mood: " << creature.mood << " ";
        }*/
        cout << ", sex: ";
        if(creature.sex == 0)
        {
            cout << "Female";
        }
        else
        {
            cout <<"Male";
        }
        cout << endl;

        if((creature.mood != -1) && (creature.mood<5))
        {
            cout << "mood: " << creature.mood << ", skill: " << mem->getSkill(creature.mood_skill) << endl;
            vector<DFHack::t_material> mymat;
            if(Creatures->ReadJob(&creature, mymat))
            {
                for(unsigned int i = 0; i < mymat.size(); i++)
                {
                    printf("\t%s(%d)\t%d %d %d - %.8x\n", Materials->getDescription(mymat[i]).c_str(), mymat[i].itemType, mymat[i].subType, mymat[i].subIndex, mymat[i].index, mymat[i].flags);
                }
            }
        }

        /*
        if(creature.pregnancy_timer > 0)
            cout << "gives birth in " << creature.pregnancy_timer/1200 << " days. ";
        cout << "Blood: " << creature.blood_current << "/" << creature.blood_max << " bleeding: " << creature.bleed_rate;
        */
        cout << endl;

        if(creature.has_default_soul)
        {
            //skills
            cout << "Skills" << endl;
            for(unsigned int i = 0; i < creature.defaultSoul.numSkills;i++)
            {
                if(i > 0)
                {
                    cout << ", ";
                }
                cout << mem->getSkill(creature.defaultSoul.skills[i].id) << ": " << creature.defaultSoul.skills[i].rating;
            }
            cout << endl;
            cout << "Traits" << endl;
            for(uint32_t i = 0; i < 30;i++)
            {
                string trait = mem->getTrait (i, creature.defaultSoul.traits[i]);
                if(!trait.empty()) cout << trait << ", ";
            }
            cout << endl;

            // labors
            cout << "Labors" << endl;
            for(unsigned int i = 0; i < NUM_CREATURE_LABORS;i++)
            {
                if(!creature.labors[i])
                    continue;
                string laborname;
                try
                {
                    laborname = mem->getLabor(i);
                }
                catch(exception &)
                {
                    break;
                }
                cout << laborname << ", ";
            }
            cout << endl;
        }
        /*
         * FLAGS 1
         */
        cout << "flags1: ";
        print_bits(creature.flags1.whole, cout);
        cout << endl;
        if(creature.flags1.bits.dead)
        {
            cout << "dead ";
        }
        if(creature.flags1.bits.on_ground)
        {
            cout << "on the ground, ";
        }
        if(creature.flags1.bits.skeleton)
        {
            cout << "skeletal ";
        }
        if(creature.flags1.bits.zombie)
        {
            cout << "zombie ";
        }
        if(creature.flags1.bits.tame)
        {
            cout << "tame ";
        }
        if(creature.flags1.bits.royal_guard)
        {
            cout << "royal_guard ";
        }
        if(creature.flags1.bits.fortress_guard)
        {
            cout << "fortress_guard ";
        }
        /*
        * FLAGS 2
        */
        cout << endl << "flags2: ";
        print_bits(creature.flags2.whole, cout);
        cout << endl;
        if(creature.flags2.bits.killed)
        {
            cout << "killed by kill function, ";
        }
        if(creature.flags2.bits.resident)
        {
            cout << "resident, ";
        }
        if(creature.flags2.bits.gutted)
        {
            cout << "gutted, ";
        }
        if(creature.flags2.bits.slaughter)
        {
            cout << "marked for slaughter, ";
        }
        if(creature.flags2.bits.underworld)
        {
            cout << "from the underworld, ";
        }
        cout << endl;

        if(creature.flags1.bits.had_mood && (creature.mood == -1 || creature.mood == 8 ) )
        {
            string artifact_name = Tran->TranslateName(creature.artifact_name,false);
            cout << "artifact: " << artifact_name << endl;
        }


    cout << endl;
}


int main (int numargs, char ** args)
{
    DFHack::World * World;
    DFHack::ContextManager DFMgr("Memory.xml");
    DFHack::Context* DF;
    try
    {
        DF = DFMgr.getSingleContext();
        DF->Attach();
    }
    catch (exception& e)
    {
        cerr << e.what() << endl;
        #ifndef LINUX_BUILD
            cin.ignore();
        #endif
        return 1;
    }
    string check = "";
    if(numargs == 2)
        check = args[1];

    Creatures = DF->getCreatures();
    Materials = DF->getMaterials();
    World = DF->getWorld();
    current_year = World->ReadCurrentYear();
    current_tick = World->ReadCurrentTick();
    DFHack::Translation * Tran = DF->getTranslation();

    uint32_t numCreatures;
    if(!Creatures->Start(numCreatures))
    {
        cerr << "Can't get creatures" << endl;
        #ifndef LINUX_BUILD
            cin.ignore();
        #endif
        return 1;
    }
    if(!numCreatures)
    {
        cerr << "No creatures to print" << endl;
        #ifndef LINUX_BUILD
            cin.ignore();
        #endif
        return 1;
    }

    mem = DF->getMemoryInfo();
    Materials->ReadAllMaterials(); <== Just here !

    if(!Tran->Start())
    {
        cerr << "Can't get name tables" << endl;
        return 1;
    }
    vector<uint32_t> addrs;
    //DF.InitViewAndCursor();
    for(uint32_t i = 0; i < numCreatures; i++)
    {
        DFHack::t_creature temp;
        Creatures->ReadCreature(i,temp);
        if(check.empty() || string(Materials->raceEx[temp.race].rawname) == check)
        {
            cout << "index " << i << " ";

            printCreature(DF,temp);
            addrs.push_back(temp.origin);
        }
    }
    if(addrs.size() <= 10)
    {
        interleave_hex(DF,addrs,200);
    }
    /*
    uint32_t currentIdx;
    DFHack::t_creature currentCreature;
    DF.getCurrentCursorCreature(currentIdx);
    cout << "current creature at index " << currentIdx << endl;

    DF.ReadCreature(currentIdx, currentCreature);
    printCreature(DF,currentCreature);
    */
    Creatures->Finish();
    DF->Detach();
    #ifndef LINUX_BUILD
    cout << "Done. Press any key to continue" << endl;
    cin.ignore();
    #endif
    return 0;
}
I was wondering if the problem was coming from DF, so I just get a look in the df-hacked script, in the ./precompiled/linux directory of the DFHack distrib, and it seems that the library libdfconnect.so in the same dir must be moved in the libs directory of the DF distribution

So, i made the three following things :
  • Copy the libdfconnect.so from its origin dir to the libs dir of the DF distribution
  • Copy the fd-hacked script from its origine dir to the root of the DF distribution
  • Modify the fd-hacked script for using the ./libs/Dwarf_Fortress exec instead of dwarfort.exe

But again, no luck, same error.

So, at the end, I have two questions :
  • Does the last version of DFHack works with the last Linux version of DF ? EDIT : Work for some tool. Seems to be, only the dump tools are not working
  • If yes, how can I use the DFHack tools (and later, the lib) with DF ?

Regards,
Teocali
« Last Edit: August 25, 2010, 06:54:28 am by Teocali »
Logged

sizeak

  • Bay Watcher
    • View Profile
Re: DFHack 0.4.0.7b - tools and memory access library
« Reply #231 on: August 25, 2010, 07:41:37 am »

Think there is a bad/missing offset
Logged
Runesmith - http://www.bay12forums.com/smf/index.php?topic=59056.0 - A Dwarf Companion like tool

peterix

  • Bay Watcher
    • View Profile
    • Dethware
Re: DFHack 0.4.0.7b - tools and memory access library
« Reply #232 on: August 25, 2010, 09:12:16 am »

Think there is a bad/missing offset
Exactly.
The tools from the 'tools/supported' directory work. Those are also normally in the binary releases. Things from 'tools/playground' probably won't. Unfortunately, that's also true for most of the stuff in 'tools/examples'.

I'm working on solving the problem on a bigger scale -- redoing the memory.xml format and writing a GUI tool to edit the file. That should make maintaining the offsets easier.

Teocali

  • Escaped Lunatic
    • View Profile
Re: DFHack 0.4.0.7b - tools and memory access library
« Reply #233 on: August 25, 2010, 09:54:36 am »

Ok, Thanks for your work.

Regards,
Teocali
Logged

devek

  • Bay Watcher
  • [KILL_EVERYTHING]
    • View Profile
Re: DFHack 0.4.0.7b - tools and memory access library
« Reply #234 on: August 27, 2010, 12:31:32 am »

How hard would it be to get something better from item dump than "COPPER weapon" ?
Logged
"Why do people rebuild things that they know are going to be destroyed? Why do people cling to life when they know they can't live forever?"

mLegion

  • Bay Watcher
    • View Profile
Re: DFHack 0.4.0.7b - tools and memory access library
« Reply #235 on: August 27, 2010, 01:01:26 pm »

I don't suppose someone as written a utility to remove ownership flags from items so i can finally dump all those 'xXpig tail socksXx'?
Logged

devek

  • Bay Watcher
  • [KILL_EVERYTHING]
    • View Profile
Re: DFHack 0.4.0.7b - tools and memory access library
« Reply #236 on: August 28, 2010, 07:33:06 am »

How hard would it be to get something better from item dump than "COPPER weapon" ?

sigh,

OK, if you're using IDA the function that turns an item into a textual description is sub_CD7420.

it switches on the type multiple times...

so a weapon which is type 24 calls sub_B37750, which looks up the weapon name from unk_1d5a27c.
.....
edit: it looks kind of like..
Code: [Select]
    string item = "[";

    switch(dfitem.matdesc.itemType)
    {
        case 24: // weapon
        {
            string material = Materials->getDescription(dfitem.matdesc);
            transform(material.begin(), material.end(), material.begin(), ::tolower);
            item.append(material);
            item.append(" ");
        }
            break;
        default:
            item.append("unknown item]");
            return item;
    }

    switch(dfitem.matdesc.itemType)
    {
    case 24: //weapon
        {
            uint32_t a = p->readDWord(dfbase+0x12DA27C + 0x24);
            uint32_t b = p->readDWord(a + (dfitem.matdesc.subType * 4));
            item.append(p->readCString(b+0x28));
        }
        break;
    default:
        item.append("unknown item]");
        return item;

    }

    item.append("]");

which looks kind of ugly, but that is how toady has to do it :(
....
edit2: !#$#@, why do material names have to be at different offsets?!?!?!
....
Now, the only tool that will really benefit from getting exact textual representation of items is Dwarf Foreman. So I guess it is up to me to write it :/ It will be super annoying to do, so I hope you have a better idea peter :P It would require dfhack tracking lots of new offsets, but they will all be super easy to automate the finding of.

Thoughts?
« Last Edit: August 28, 2010, 05:05:29 pm by devek »
Logged
"Why do people rebuild things that they know are going to be destroyed? Why do people cling to life when they know they can't live forever?"

peterix

  • Bay Watcher
    • View Profile
    • Dethware
Re: DFHack 0.4.0.7b - tools and memory access library
« Reply #237 on: August 28, 2010, 07:19:36 pm »


How hard would it be to get something better from item dump than "COPPER weapon" ?
In my books, the item dump doesn't work at all. The whole Items module is something that either needs a lot of work poured into it (documenting what's going on at least) or replacing with the old one, which could do almost the same with a lot less complexity. The old module determined item types by looking at the item's vtable pointer alone.

What's required is copying the item class hierarchy of DF. Depending on the vtable pointer from DF, the right classes would be used for the DFHack item objects. This way reading items won't involve things like creating text descriptions... that can be left for another layer or be implemented as Item::getDescription().

A problem to solve here is the amount of items that can be present -- those have to be read, processed and later disposed of. Maybe using a design pattern like flyweight could provide a lot of benefits. Have a set of vectors of items. A vector for each type. Keep away from constructors and destructors and use one real object whose data is supplied by the vector.

Those are two layers - one that loads individual items based on type and second that provides the cache/storage.
edit2: !#$#@, why do material names have to be at different offsets?!?!?!
* peterix doesn't understand.

Now, the only tool that will really benefit from getting exact textual representation of items is Dwarf Foreman. So I guess it is up to me to write it :/ It will be super annoying to do, so I hope you have a better idea peter :P It would require dfhack tracking lots of new offsets, but they will all be super easy to automate the finding of.

Thoughts?
No more thoughts really. Items are just plain broken in their current state. The module only works on Windows too.
If the problem of reading DF types with a virtual base class like Items is solved, the solution can be applied elsewhere. For example for reading building details.
« Last Edit: August 28, 2010, 07:23:20 pm by peterix »
Logged

peterix

  • Bay Watcher
    • View Profile
    • Dethware
Re: DFHack 0.4.0.7b - tools and memory access library
« Reply #238 on: August 28, 2010, 07:35:00 pm »

Also: double posting!

The memory.xml rewrite is pretty much done and the modules needed by the supported DFHack tools (not third-party utils) have been updated. The offset dumper can now print out offsets that are missing. I'll have to document this stuff.

Next up:
* Update rest of the modules to use the new offsets
* Work on memory.xml editor. I want to take it a bit further than previously planned and add a way to actually explore DF's memory space, probably forking this along the way. Unlike rest of DFHack, the utility will be GPL.

devek

  • Bay Watcher
  • [KILL_EVERYTHING]
    • View Profile
Re: DFHack 0.4.0.7b - tools and memory access library
« Reply #239 on: August 28, 2010, 09:53:29 pm »

How hard would it be to get something better from item dump than "COPPER weapon" ?
In my books, the item dump doesn't work at all. The whole Items module is something that either needs a lot of work poured into it (documenting what's going on at least) or replacing with the old one, which could do almost the same with a lot less complexity. The old module determined item types by looking at the item's vtable pointer alone.

I'm not really certain it is dfhack that is broken, dwarf fortress is.. Toady's use of polymorphism is a sham. It is basically a bunch of objects put into an array that get dealt with by hand. When it looks at an item like a steel mace, it has to go through elaborate nested switch statements to figure out what the item is. The same applies to materials...

edit2: !#$#@, why do material names have to be at different offsets?!?!?!
* peterix doesn't understand.

Whoever wrote the materials module ran into the same problem...

If you look at the t_matgloss structure.. the char name[128] member isn't used! He started to read the data, but commented the code out. That is because the offset required based off the material also requires nested switch statements AND THEN you then a series of if/then statements. It isn't just the items module that needs to be fixed.

I'm divided between actually untangling the mess or rewriting my program to run inside of dwarf fortress and calling its own functions to get this information.

Look at this shit


That is the graph of code DF uses to figure out what an item is. That is more branches than all of dfhack put together, and it doesn't include the myriad of functions called from within that function..  it is just one function.

DF is chock full of this crap and I run into it wherever I go. I have no choice but to push ahead. Despite the fact this isn't my first rodeo, this is turning into the single most complicated piece of code I have untangled in my entire life.
Logged
"Why do people rebuild things that they know are going to be destroyed? Why do people cling to life when they know they can't live forever?"
Pages: 1 ... 14 15 [16] 17 18 ... 108