diff options
| author | Petr Mrázek | 2012-01-05 23:54:33 +0100 |
|---|---|---|
| committer | Petr Mrázek | 2012-01-05 23:54:33 +0100 |
| commit | 72a4698968bc251ea31b0a9ab9c545696e697fc3 (patch) | |
| tree | 887744c6fb50eef011b57837bfabc3adc91b3b2e /library/DataDefs.cpp | |
| parent | 8e993fedc3c4498c4f1f089851c8c2ee50126df5 (diff) | |
| parent | 687245abd92f11db0f6fdff405c77f708344eb07 (diff) | |
| download | dfhack-72a4698968bc251ea31b0a9ab9c545696e697fc3.tar.gz dfhack-72a4698968bc251ea31b0a9ab9c545696e697fc3.tar.bz2 dfhack-72a4698968bc251ea31b0a9ab9c545696e697fc3.tar.xz | |
Merge https://github.com/angavrilov/dfhack
Diffstat (limited to 'library/DataDefs.cpp')
| -rw-r--r-- | library/DataDefs.cpp | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/library/DataDefs.cpp b/library/DataDefs.cpp index 312252b4..6c40ec81 100644 --- a/library/DataDefs.cpp +++ b/library/DataDefs.cpp @@ -35,6 +35,8 @@ distribution. // must be last due to MS stupidity #include "DataDefs.h" +#include "MiscUtils.h" + using namespace DFHack; /* The order of global object constructor calls is @@ -160,6 +162,41 @@ void virtual_identity::Init(Core *core) } } +std::string DFHack::bitfieldToString(const void *p, int size, const bitfield_item_info *items) +{ + std::string res; + const char *data = (const char*)p; + + for (int i = 0; i < size*8; i++) { + unsigned v; + + if (items[i].size > 1) { + unsigned pdv = *(unsigned*)&data[i/8]; + v = (pdv >> (i%8)) & ((1 << items[i].size)-1); + } else { + v = (data[i/8]>>(i%8)) & 1; + } + + if (v) { + if (!res.empty()) + res += ' '; + + if (items[i].name) + res += items[i].name; + else + res += stl_sprintf("UNK_%d", i); + + if (items[i].size > 1) + res += stl_sprintf("=%u", v); + } + + if (items[i].size > 1) + i += items[i].size-1; + } + + return res; +} + #define SIMPLE_GLOBAL(name,tname) \ tname *df::global::name = NULL; #define GLOBAL(name,tname) SIMPLE_GLOBAL(name,df::tname) |
