Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 9 10 [11] 12 13 ... 108

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

zwei

  • Bay Watcher
  • [ECHO][MENDING]
    • View Profile
    • Fate of Heroes
Re: DFHack 0.4.0.5 - tools and memory access library
« Reply #150 on: August 02, 2010, 08:10:58 am »

wrong button indeed :(
« Last Edit: August 02, 2010, 09:09:32 am by zwei »
Logged

Askot Bokbondeler

  • Bay Watcher
  • please line up orderly
    • View Profile
Re: DFHack 0.4.0.5 - tools and memory access library
« Reply #151 on: August 02, 2010, 08:59:12 am »

wrong button

devek

  • Bay Watcher
  • [KILL_EVERYTHING]
    • View Profile
Re: DFHack 0.4.0.5 - tools and memory access library
« Reply #152 on: August 02, 2010, 10:17:35 am »

edit: and in same vein, that cut-down-tree action in visible area just started.

When a tree is starting to be cut down its designation to be cut down is removed and there is a job assigned to the dwarf. The code I use to tell what trees are actively being cut down is...

Code: [Select]
DFHack::Process * p = DF->getProcess();
DFHack::Creatures * Creatures = DF->getCreatures();
uint32_t numCreatures;
Creatures->Start(numCreatures);

for(uint32_t i = 0; i < numCreatures; i++)

    DFHack::t_creature temp;
    Creatures->ReadCreature(i,temp);
    if((temp.race == 200) && temp.current_job.active && ((temp.current_job.jobType == 9) || (temp.current_job.jobType == 10)))
    {
        uint32_t job = p->readDWord(temp.origin + 0x390);
        printf("Tree being cut at [%hd,%hd,%hd]\n", p->readWord(job+16), p->readWord(job+18), p->readWord(job+20));
    }
}

ReadCreature is really slow though, like around 40 milliseconds to call.
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?"

TroZ_shack

  • Bay Watcher
  • Narf!
    • View Profile
    • Shacknews
Re: DFHack 0.4.0.5 - tools and memory access library
« Reply #153 on: August 02, 2010, 12:58:33 pm »

Wow, DFHack looks great.

I'm a Java developer mostly, but I do know C/C++ a bit.

I'm attempting to write a program that will convert a DF fortress to a Minecraft map by converting each 'square' in DF to a 3x3x3 area in Minecraft using appropriate material. This should work for all terrain, keeping nearly everything that was accessible in DF still be accessible in Minecraft (except for hallways that rely on diagonals being traversable - up-down stairs will need to use a different 3x3x3 setup for even and odd layers but will work).

I'm a noob at this though, and I've downloaded the DFHack source and I'm trying to compile the 'prospector' example as a test and to figure out how to start, but I'm running into some trouble.
I'm on windows, and I downloaded Microsoft Visual C++ Express 2010, and setup a project. The project compiles (the porspector.cpp and DFHack.h file), but it doesn't link.  The linker seems to want a .lib file for the DFHack.dll, but I don't see one provided.  I attempted to compile the DFHack project myself using VS Express, but that turned into a disaster that I couldn't get working.

Does anyone have a .lib for the DFHack.dll, or can talk me through setting up the project in VS Express, or am I going about this all wrong and there is something else I should be doing?

Thanks for your help.
Logged
DF2MC -> Convert DF Maps to Minecraft Levels so you can use Minecraft as a 3D visualizer for Dwarf Fortress
DF2MC - The cause of 15+ head explosions and counting!

devek

  • Bay Watcher
  • [KILL_EVERYTHING]
    • View Profile
Re: DFHack 0.4.0.5 - tools and memory access library
« Reply #154 on: August 02, 2010, 05:13:37 pm »

I don't know about visual stupio, but to compile it with qt creator is pretty simple. And since you are a java developer you really should use qt because a lot of the api is exactly the same between java and qt.

1) install qt creator
2) add c:\qt\2010.04\mingw\bin to your system path
3) install git (make sure c:\program files\git\cmd is in your system path)
4) install cmake (make sure c:\program files\cmake 2.8\bin is in your system path)
5) make a new project in qt creator that imports from git http://github.com/peterix/dfhack.git
6) when it asks for the build directory, select c:\qt\2010.04\peterix-dfhack\build'
7) when it asks for the cmake args use -G"MinGW Makefiles" -DCMAKE_BUILD_TYPE:string=Release
8) compile dfhack
9) make yourself your own project and open up the .pro file for your project and add these two lines
LIBS += -L"C:\Qt\2010.04\peterix-dfhack\output" -ldfhack
INCLUDEPATH += "C:\Qt\2010.04\peterix-dfhack\library\include"
10) make sure that when your program runs that memory.xml is in the run path and it should just work :D

 
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.5 - tools and memory access library
« Reply #155 on: August 02, 2010, 07:18:19 pm »

Or even simpler:
Get the 2005 or 2008 express version of MSVC. 2010 is too new and doesn't work right with cmake (AFAIK).

1. Install MSVC (or MinGW)
2. Install cmake
3. go into dfhack's build folder, run the right script for your MSVC version.
4. open the build-real folder that will be generated and open the MSVC project file.

After you've built dfhack, go into the output folder and copy Memory.xml into Debug or Release folders, depending on the type of build.

Also, it seems there will be Java bindings for dfhack eventually :)
« Last Edit: August 02, 2010, 08:29:37 pm by peterix »
Logged

zwei

  • Bay Watcher
  • [ECHO][MENDING]
    • View Profile
    • Fate of Heroes
Re: DFHack 0.4.0.5 - tools and memory access library
« Reply #156 on: August 03, 2010, 02:11:35 am »

edit: and in same vein, that cut-down-tree action in visible area just started.

When a tree is starting to be cut down its designation to be cut down is removed and there is a job assigned to the dwarf. The code I use to tell what trees are actively being cut down is...

Code: [Select]
DFHack::Process * p = DF->getProcess();
DFHack::Creatures * Creatures = DF->getCreatures();
uint32_t numCreatures;
Creatures->Start(numCreatures);

for(uint32_t i = 0; i < numCreatures; i++)

    DFHack::t_creature temp;
    Creatures->ReadCreature(i,temp);
    if((temp.race == 200) && temp.current_job.active && ((temp.current_job.jobType == 9) || (temp.current_job.jobType == 10)))
    {
        uint32_t job = p->readDWord(temp.origin + 0x390);
        printf("Tree being cut at [%hd,%hd,%hd]\n", p->readWord(job+16), p->readWord(job+18), p->readWord(job+20));
    }
}

ReadCreature is really slow though, like around 40 milliseconds to call.

Thank you for this.

I wonder if checking currently if currently visible rectangle and creatures in those tiles would be faster than looping throught all creatues because that is all waht i need (how is getCreatures implemented anyway, speed suggests that it checks whole embark cuboid?)

peterix

  • Bay Watcher
    • View Profile
    • Dethware
Re: DFHack 0.4.0.5 - tools and memory access library
« Reply #157 on: August 03, 2010, 08:08:13 am »

Thank you for this.

I wonder if checking currently if currently visible rectangle and creatures in those tiles would be faster than looping throught all creatues because that is all waht i need (how is getCreatures implemented anyway, speed suggests that it checks whole embark cuboid?)
getCreatures gives you the module for working with creatures.

There's a simple call meant to detect creatures in a cube defined by the programmer:
Code: [Select]
// returns index of creature actually read or -1 if no creature can be found
int32_t Creatures::ReadCreatureInBox (int32_t index, t_creature & furball,
                                const uint16_t x1, const uint16_t y1, const uint16_t z1,
                                const uint16_t x2, const uint16_t y2, const uint16_t z2)
This scans the creatures only for their x,y,z coords and gives you the first one that fits in. index is the starting index into the creature vector where the search begins. The method returns the creature found (furball) and its index. x1,y1,z1 are supposed to be smaller or equal to x2,y2,z2.
So, to scan all creatures, you call it with index=0 at first and then feed it the returned index + 1 until you get -1 back. This will give you only the creatures in the defined box.
It's used by stonesense and should be stable.

You can combine this with the methods for getting screen coords and size from the Position module (getViewCoords and getWindowSize).
« Last Edit: August 03, 2010, 08:19:31 am by peterix »
Logged

keda

  • Bay Watcher
    • View Profile
Re: DFHack 0.4.0.5 - tools and memory access library
« Reply #158 on: August 03, 2010, 08:57:18 am »

A couple of question peterix, btw I appreciate all the work you are doing, what is the rating in t_skill and does it have anything to do with the experience in the skill?

Edit: nvm figured it out
« Last Edit: August 03, 2010, 12:31:24 pm by keda »
Logged

keda

  • Bay Watcher
    • View Profile
Re: DFHack 0.4.0.5 - tools and memory access library
« Reply #159 on: August 03, 2010, 04:54:10 pm »

I have another, hopefully a less stupid question, is there a way to increase the size of the skill vector?

devek

  • Bay Watcher
  • [KILL_EVERYTHING]
    • View Profile
Re: DFHack 0.4.0.5 - tools and memory access library
« Reply #160 on: August 03, 2010, 05:19:13 pm »

The way I increase a vector is to allocate memory in the process and copy it over to it.

VirtualAllocEX is what I use, but it would be cool if dfhack had a function that worked on linux too.
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?"

keda

  • Bay Watcher
    • View Profile
Re: DFHack 0.4.0.5 - tools and memory access library
« Reply #161 on: August 03, 2010, 06:17:25 pm »

The way I increase a vector is to allocate memory in the process and copy it over to it.

VirtualAllocEX is what I use, but it would be cool if dfhack had a function that worked on linux too.
Cool, thanks a lot. I think I know what you mean, having the vector point at that newly allocated memory instead? I wonder though if theres an equivalent function for linux as well...

peterix

  • Bay Watcher
    • View Profile
    • Dethware
Re: DFHack 0.4.0.5 - tools and memory access library
« Reply #162 on: August 03, 2010, 06:47:21 pm »

The way I increase a vector is to allocate memory in the process and copy it over to it.

VirtualAllocEX is what I use, but it would be cool if dfhack had a function that worked on linux too.
That is a horrible idea. Also, there are proper functions for this already, called vector::push_back and malloc. DFHack can do something like this by sneaking in some extra code into SDL. It's just for std::string right now, but could be extended to vectors.
« Last Edit: August 03, 2010, 07:16:37 pm by peterix »
Logged

devek

  • Bay Watcher
  • [KILL_EVERYTHING]
    • View Profile
Re: DFHack 0.4.0.5 - tools and memory access library
« Reply #163 on: August 03, 2010, 07:25:40 pm »

The way I increase a vector is to allocate memory in the process and copy it over to it.

VirtualAllocEX is what I use, but it would be cool if dfhack had a function that worked on linux too.
That is a horrible idea. Also, there are proper functions for this already, called vector::push_back and malloc. DFHack can do something like this by sneaking in some extra code into SDL. It's just for std::string right now, but could be extended to vectors.

I think you misunderstood me. push_back and malloc won't work.

If my program tries to use push_back on a vector that exists in DF's memory it will (likely) crash since the memory addresses in DF won't exist in my program. If I use malloc and try to write to that address in DF's memory, it will fail because that memory address probably won't exist in DF and only in my process.

In my program I only allocate one chunk of memory in DF and I manage it myself and have my own code to work with vectors and strings in a different context. It doesn't fail because DF can always move the vector somewhere else if it wants to and I can roll with that.

Of course it is possible I misunderstood and df hack has a malloc and push_back function that runs inside of DF's process and not mine lol.
« Last Edit: August 03, 2010, 07:28:19 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.5 - tools and memory access library
« Reply #164 on: August 03, 2010, 08:53:05 pm »

In my program I only allocate one chunk of memory in DF and I manage it myself and have my own code to work with vectors and strings in a different context. It doesn't fail because DF can always move the vector somewhere else if it wants to and I can roll with that.
And it won't crash when the memory is freed by DF's allocator? I had enough problems with that to write off any such easy hacks as rubbish :)
Of course it is possible I misunderstood and df hack has a malloc and push_back function that runs inside of DF's process and not mine lol.
Yes, it's there, just not for vectors yet and it requires hooking a few SDL functions to get code in. No code caves, no assembly and no messing with virtual memory involved :)  You just need to make sure you're using the same C and STL libraries as DF for the fake SDL.
A bit of example code:
Code: [Select]
std::string * to_set = (std::string *) offset;
to_set->assign("string assigned by dfhack...");

This is the code that goes into the fake SDL: http://github.com/peterix/dfhack/tree/master/library/shm/
The client uses the SHM versions of the Process class to talk to it.
Pages: 1 ... 9 10 [11] 12 13 ... 108