Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: Obtaining available actions  (Read 819 times)

Nilwater

  • Escaped Lunatic
    • View Profile
Obtaining available actions
« on: December 02, 2013, 01:23:26 pm »

Hello!

I'm using Linux and trying to obtain all the current actions available to me in the game's current state.
For example at the default screen I would have these actions:
Code: [Select]
{ "Main" :
    { "a" : "View Announcements"
    , "b" : "Building"
    , "c" : "View Civilizations"
    , ... etc
    }
}

And if I press b to get the building menu I would simple get:
Code: [Select]
{ "Building :
    { "a" : "Armor Stand"
    , "b" : "Bed"
    , "c" : "Seat"
    , ... etc
    }
}
I've been trying to achieve this by reading the game's memory, however I am very unfamiliar with reading a process's memory and it proved to be very challenging.
Using scanmem I've been able to find simple things such as population count but I wasn't able to get even close to my actual goal.

Screen Scraping isn't really an option since font changes with tilesets and it doesn't seem like a clean solution.

If anyone has knowledge on how to tackle this problem, any help is appreciated. I'm not asking for someone to solve this problem for me, just any guidance or tips would help.

Thanks in advance!
« Last Edit: December 02, 2013, 01:44:41 pm by Nilwater »
Logged

Quietust

  • Bay Watcher
  • Does not suffer fools gladly
    • View Profile
    • QMT Productions
Re: Obtaining available actions
« Reply #1 on: December 02, 2013, 04:21:33 pm »

You aren't going to get anything useful from reading the game's memory because of how key bindings are implemented - what's actually going on is that each viewscreen has a special function which gets called for handling input, and those functions simply check for the keybindings they're meant to handle.

For an example, look at "interface.cpp" in the g_src folder (which is only present in the Linux version) and jump down to the "viewscreen_movieplayerst::feed" function.

The only way to do this reliably would be to detect the currently active viewscreen and its current state (which can be done using DFHack) and then look up the keybindings used there from a static list which you would prepare in advance.
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.

Nilwater

  • Escaped Lunatic
    • View Profile
Re: Obtaining available actions
« Reply #2 on: December 02, 2013, 07:23:12 pm »

Thanks a lot! That's exactly what I was looking for. Now I can use this in conjunction with dfhack-run. I'd probably want to integrate it into a plugin but dfhack-run will do the trick for now.
Thanks again!
Logged

Quietust

  • Bay Watcher
  • Does not suffer fools gladly
    • View Profile
    • QMT Productions
Re: Obtaining available actions
« Reply #3 on: December 02, 2013, 09:09:15 pm »

"dfhack-run" is nothing more than an alternative to running commands from the DFHack console, and commands can only come from plugins (C++) and scripts (Lua or Ruby).
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.