From 49594990093f75f46b7aa891582dd20db9834cc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Thu, 16 Sep 2010 03:53:32 +0200 Subject: [PATCH 01/13] Fun and games of the offset kind. Most of Linux support for 31.13. Weather is wrong. --- data/Memory-ng.xml | 61 +++++++++++++++++++++++++++++++++ tools/examples/creaturedump.cpp | 6 ++-- 2 files changed, 64 insertions(+), 3 deletions(-) diff --git a/data/Memory-ng.xml b/data/Memory-ng.xml index f331c10d2..1db405dae 100644 --- a/data/Memory-ng.xml +++ b/data/Memory-ng.xml @@ -1747,6 +1747,67 @@ + + + + +
+ + +
+ + +
+
+
+ + +
+
+
+
+
+
+
+
+
+
+
+
+ + +
+ + +
+ + + +
+
+ + + +
+
+
+
+
+
+ + +
+ + +
+ + +
+
+
+ + + diff --git a/tools/examples/creaturedump.cpp b/tools/examples/creaturedump.cpp index eb611eefe..dddd6e018 100644 --- a/tools/examples/creaturedump.cpp +++ b/tools/examples/creaturedump.cpp @@ -134,7 +134,7 @@ likeType printLike40d(DFHack::t_like like, const matGlosses & mat,const vector< 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 + cout << "address: " << hex << creature.origin << dec << ", creature race: " << creature.race << "/" << Materials->raceEx[creature.race].rawname << "[" << Materials->raceEx[creature.race].tile_character << "," << Materials->raceEx[creature.race].tilecolor.fore << "," << Materials->raceEx[creature.race].tilecolor.back @@ -172,7 +172,7 @@ void printCreature(DFHack::Context * DF, const DFHack::t_creature & creature) if(creature.civ) { - cout << "civilization: " << creature.civ; + cout << ", civilization: " << creature.civ; addendl = true; } @@ -191,7 +191,7 @@ void printCreature(DFHack::Context * DF, const DFHack::t_creature & creature) cout << endl; addendl = false; } - cout << "profession: " << mem->getProfession(creature.profession) << "(" << (int) creature.profession << ")"; + cout << ", profession: " << mem->getProfession(creature.profession) << "(" << (int) creature.profession << ")"; if(creature.custom_profession[0]) { From 3592748a50c6951eab0cf440b1556379dd44c89d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Thu, 16 Sep 2010 15:09:42 +0200 Subject: [PATCH 02/13] Bits and pieces --- data/Memory-ng.xml | 31 ++++++++++++++++++++++++++++--- library/modules/World.cpp | 14 ++++++++++++-- 2 files changed, 40 insertions(+), 5 deletions(-) diff --git a/data/Memory-ng.xml b/data/Memory-ng.xml index 1db405dae..d34825c3e 100644 --- a/data/Memory-ng.xml +++ b/data/Memory-ng.xml @@ -885,7 +885,7 @@
-
+
@@ -1454,7 +1454,32 @@ - + + + + +
+ 0x01482874 - current race + +
+
+
+
+
+
+ + +
+ + +
+ + +
+ + + + 31.13 WEATHER_START 0147E94E .-"""-. ' \ |,. ,-. | _________________________ @@ -1804,7 +1829,7 @@
-
+
diff --git a/library/modules/World.cpp b/library/modules/World.cpp index 009b696ac..3e1a670de 100644 --- a/library/modules/World.cpp +++ b/library/modules/World.cpp @@ -133,12 +133,22 @@ uint32_t World::ReadCurrentDay() uint8_t World::ReadCurrentWeather() { if (d->Inited && d->StartedWeather) - return(d->owner->readByte(d->weather_offset)); + return(d->owner->readByte(d->weather_offset + 12)); return 0; } - +/* void World::SetCurrentWeather(uint8_t weather) { if (d->Inited && d->StartedWeather) d->owner->writeByte(d->weather_offset,weather); } +*/ +void World::SetCurrentWeather(uint8_t weather) +{ + if (d->Inited && d->StartedWeather) + { + uint8_t buf[25]; + memset(&buf,weather, sizeof(buf)); + d->owner->write(d->weather_offset,sizeof(buf),buf); + } +} From 38f50f4a46d2373aae6c123306c2a65267b0eb89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Fri, 17 Sep 2010 13:49:49 +0200 Subject: [PATCH 03/13] More 31.13 offsets - bits of the Maps module, many offsets are bad. --- data/Memory-ng.xml | 93 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 91 insertions(+), 2 deletions(-) diff --git a/data/Memory-ng.xml b/data/Memory-ng.xml index d34825c3e..04149ede2 100644 --- a/data/Memory-ng.xml +++ b/data/Memory-ng.xml @@ -1459,6 +1459,19 @@
+ + + + + 0x01482874 - current race
@@ -1472,10 +1485,86 @@
-
+
-
+
+ + +
+
+
+
+
+
+
+
+ +
+ +
+ +
+
+ + + +
+ + + +
+ + + + +
+
+ + + + + +
+
+
+
+
+
+ +
+
+
+ From dfdd1467ffad6adccf2aef40e66b00e5b3bef71b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Sat, 18 Sep 2010 04:36:14 +0200 Subject: [PATCH 04/13] Offset stuff --- data/Memory-ng.xml | 76 +++++++++++++++++++++++--- library/DFProcess-linux-wine.cpp | 42 +++++--------- library/DFProcess-windows.cpp | 43 +++++---------- tools/playground/SegmentedFinder.h | 7 +++ tools/playground/incrementalsearch.cpp | 25 ++++++++- 5 files changed, 125 insertions(+), 68 deletions(-) diff --git a/data/Memory-ng.xml b/data/Memory-ng.xml index 04149ede2..ade3190fc 100644 --- a/data/Memory-ng.xml +++ b/data/Memory-ng.xml @@ -674,6 +674,22 @@ + + + + + + @@ -938,6 +954,11 @@ + + + + + @@ -1217,7 +1238,6 @@
-
@@ -1472,6 +1492,14 @@ NOT FINAL, needs research --> + + + + + + + + 0x01482874 - current race
@@ -1552,14 +1580,46 @@ --> - -
-
-
-
-
-
+
+
+
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
+ + +
+ + + +
+
diff --git a/library/DFProcess-linux-wine.cpp b/library/DFProcess-linux-wine.cpp index 8e8e3c1f5..891a4f820 100644 --- a/library/DFProcess-linux-wine.cpp +++ b/library/DFProcess-linux-wine.cpp @@ -53,6 +53,9 @@ class WineProcess::Private bool attached; bool suspended; bool identified; + uint32_t STLSTR_buf_off; + uint32_t STLSTR_size_off; + uint32_t STLSTR_cap_off; bool validate(char * exe_file, uint32_t pid, char * mem_file, vector & known_versions); }; @@ -155,6 +158,10 @@ bool WineProcess::Private::validate(char* exe_file, uint32_t pid, char* mem_file // tell WineProcess about the /proc/PID/mem file memFile = mem_file; identified = true; + OffsetGroup * strGrp = m->getGroup("string")->getGroup("MSVC"); + STLSTR_buf_off = strGrp->getOffset("buffer"); + STLSTR_size_off = strGrp->getOffset("size"); + STLSTR_cap_off = strGrp->getOffset("capacity"); return true; } } @@ -563,21 +570,10 @@ const std::string WineProcess::readCString (uint32_t offset) size_t WineProcess::readSTLString (uint32_t offset, char * buffer, size_t bufcapacity) { - /* - MSVC++ string - ptr allocator - union - { - char[16] start; - char * start_ptr - } - Uint32 length - Uint32 capacity - */ - uint32_t start_offset = offset + 4; - size_t length = readDWord(offset + 20); + uint32_t start_offset = offset + d->STLSTR_buf_off; + size_t length = readDWord(offset + d->STLSTR_size_off); + size_t capacity = readDWord(offset + d->STLSTR_cap_off); - size_t capacity = readDWord(offset + 24); size_t read_real = min(length, bufcapacity-1);// keep space for null termination // read data from inside the string structure @@ -597,20 +593,10 @@ size_t WineProcess::readSTLString (uint32_t offset, char * buffer, size_t bufcap const string WineProcess::readSTLString (uint32_t offset) { - /* - MSVC++ string - ptr allocator - union - { - char[16] start; - char * start_ptr - } - Uint32 length - Uint32 capacity - */ - uint32_t start_offset = offset + 4; - uint32_t length = readDWord(offset + 20); - uint32_t capacity = readDWord(offset + 24); + uint32_t start_offset = offset + d->STLSTR_buf_off; + size_t length = readDWord(offset + d->STLSTR_size_off); + size_t capacity = readDWord(offset + d->STLSTR_cap_off); + char * temp = new char[capacity+1]; // read data from inside the string structure diff --git a/library/DFProcess-windows.cpp b/library/DFProcess-windows.cpp index a658b49a7..0b3d7959d 100644 --- a/library/DFProcess-windows.cpp +++ b/library/DFProcess-windows.cpp @@ -48,6 +48,9 @@ class NormalProcess::Private bool attached; bool suspended; bool identified; + uint32_t STLSTR_buf_off; + uint32_t STLSTR_size_off; + uint32_t STLSTR_cap_off; }; NormalProcess::NormalProcess(uint32_t pid, vector & known_versions) @@ -134,7 +137,10 @@ NormalProcess::NormalProcess(uint32_t pid, vector & known_versio vector threads; getThreadIDs( threads ); d->my_main_thread = OpenThread(THREAD_ALL_ACCESS, FALSE, (DWORD) threads[0]); - + OffsetGroup * strGrp = m->getGroup("string")->getGroup("MSVC"); + d->STLSTR_buf_off = strGrp->getOffset("buffer"); + d->STLSTR_size_off = strGrp->getOffset("size"); + d->STLSTR_cap_off = strGrp->getOffset("capacity"); found = true; break; // break the iterator loop } @@ -430,21 +436,9 @@ const string NormalProcess::readCString (const uint32_t offset) size_t NormalProcess::readSTLString (uint32_t offset, char * buffer, size_t bufcapacity) { - /* - MSVC++ string - ptr allocator - union - { - char[16] start; - char * start_ptr -} -Uint32 length -Uint32 capacity -*/ - uint32_t start_offset = offset + 4; - size_t length = readDWord(offset + 20); - - size_t capacity = readDWord(offset + 24); + uint32_t start_offset = offset + d->STLSTR_buf_off; + size_t length = readDWord(offset + d->STLSTR_size_off); + size_t capacity = readDWord(offset + d->STLSTR_cap_off); size_t read_real = min(length, bufcapacity-1);// keep space for null termination // read data from inside the string structure @@ -464,20 +458,9 @@ Uint32 capacity const string NormalProcess::readSTLString (uint32_t offset) { - /* - MSVC++ string - ptr allocator - union - { - char[16] start; - char * start_ptr - } - Uint32 length - Uint32 capacity - */ - uint32_t start_offset = offset + 4; - uint32_t length = readDWord(offset + 20); - uint32_t capacity = readDWord(offset + 24); + uint32_t start_offset = offset + d->STLSTR_buf_off; + size_t length = readDWord(offset + d->STLSTR_size_off); + size_t capacity = readDWord(offset + d->STLSTR_cap_off); char * temp = new char[capacity+1]; // read data from inside the string structure diff --git a/tools/playground/SegmentedFinder.h b/tools/playground/SegmentedFinder.h index c50cc4c6f..98de87711 100644 --- a/tools/playground/SegmentedFinder.h +++ b/tools/playground/SegmentedFinder.h @@ -311,4 +311,11 @@ bool findString (SegmentedFinder* s, uint32_t *addr, const char * compare ) return false; } +bool findStrBuffer (SegmentedFinder* s, uint32_t *addr, const char * compare ) +{ + if(strcmp((const char *)addr, compare) == 0) + return true; + return false; +} + #endif // SEGMENTED_FINDER_H \ No newline at end of file diff --git a/tools/playground/incrementalsearch.cpp b/tools/playground/incrementalsearch.cpp index 68ce20014..918577944 100644 --- a/tools/playground/incrementalsearch.cpp +++ b/tools/playground/incrementalsearch.cpp @@ -482,6 +482,22 @@ void FindPtrVectorsByObjectAddress(DFHack::ContextManager & DFMgr, vector & ranges) +{ + vector found; + string select; + while (Incremental(found,"buffer",select,"buffer","buffers")) + { + DFMgr.Refresh(); + DFHack::Context * DF = DFMgr.getSingleContext(); + DF->Attach(); + SegmentedFinder sf(ranges,DF); + sf.Find< const char * ,uint32_t>(select.c_str(),1,found, findStrBuffer); + DF->Detach(); + } +} + + void FindStrings(DFHack::ContextManager & DFMgr, vector & ranges) { @@ -799,12 +815,13 @@ int main (void) string prompt = "Select search type: 1=number(default), 2=vector by length, 3=vector>object>string,\n" " 4=string, 5=automated offset search, 6=vector by address in its array,\n" - " 7=pointer vector by address of an object, 8=vector>first object>string\n"; + " 7=pointer vector by address of an object, 8=vector>first object>string\n" + " 9=string buffers\n"; int mode; do { getNumber(prompt,mode, 1, false); - } while (mode < 1 || mode > 8 ); + } while (mode < 1 || mode > 9 ); switch (mode) { case 1: @@ -838,6 +855,10 @@ int main (void) DF->Detach(); FindVectorByFirstObjectRawname(DFMgr, selected_ranges); break; + case 9: + DF->Detach(); + FindStrBufs(DFMgr, selected_ranges); + break; default: cout << "not implemented :(" << endl; } From d9955a3b43fc6dc87c905e6b5bb2c20c48a16038 Mon Sep 17 00:00:00 2001 From: John Beisley Date: Sat, 18 Sep 2010 10:48:06 +0100 Subject: [PATCH 05/13] Added memory layout for creatures in Linux DF v0.31.09 onwards (although only tested with DF v0.31.12 and v0.31.13. --- data/Memory-ng.xml | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/data/Memory-ng.xml b/data/Memory-ng.xml index ade3190fc..f2fd178f5 100644 --- a/data/Memory-ng.xml +++ b/data/Memory-ng.xml @@ -1867,6 +1867,24 @@ + + + + + + + + + + + + + + CHMOD + + + + @@ -1905,6 +1923,9 @@
+ +
+
From c4403561d514afd4e0b234d0093ff1d6b962e32e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Sat, 18 Sep 2010 14:04:13 +0200 Subject: [PATCH 06/13] Offsets, Materials, 31.13, windows --- data/Memory-ng.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/data/Memory-ng.xml b/data/Memory-ng.xml index ade3190fc..872842ccf 100644 --- a/data/Memory-ng.xml +++ b/data/Memory-ng.xml @@ -1588,12 +1588,12 @@
- - + + - + From 88934f0add6bd571380a2fb4f4fe9e7bf14f4a32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Sun, 19 Sep 2010 06:17:48 +0200 Subject: [PATCH 07/13] Materials done --- data/Memory-ng.xml | 73 ++++++++++++++++------------------- library/modules/Materials.cpp | 4 ++ 2 files changed, 38 insertions(+), 39 deletions(-) diff --git a/data/Memory-ng.xml b/data/Memory-ng.xml index fdb84d2b1..0b4293d55 100644 --- a/data/Memory-ng.xml +++ b/data/Memory-ng.xml @@ -1481,13 +1481,13 @@
- + @@ -1516,7 +1516,7 @@
-
+
@@ -1551,7 +1551,7 @@ --> -
+
-
+
this is crap it seems - -
- - - -
- - -
-
-
+ +
+ + + +
diff --git a/library/modules/Materials.cpp b/library/modules/Materials.cpp index 2ad78361e..608e7b663 100644 --- a/library/modules/Materials.cpp +++ b/library/modules/Materials.cpp @@ -402,19 +402,23 @@ bool Materials::ReadCreatureTypesEx (void) p->readSTLString (caste_start + sizeof_string, caste.singular, sizeof(caste.singular)); p->readSTLString (caste_start + 2 * sizeof_string, caste.plural, sizeof(caste.plural)); p->readSTLString (caste_start + 3 * sizeof_string, caste.adjective, sizeof(caste.adjective)); + cout << "Caste " << caste.rawname << " " << caste.singular << ": 0x" << hex << caste_start << endl; if(have_advanced) { /* color mod reading */ + // Caste + offset > color mod vector DfVector p_colormod(p, caste_start + caste_colormod_offset); sizecolormod = p_colormod.size(); caste.ColorModifier.resize(sizecolormod); for(uint32_t k = 0; k < sizecolormod;k++) { + // color mod [0] -> color list DfVector p_colorlist(p, p_colormod[k]); sizecolorlist = p_colorlist.size(); caste.ColorModifier[k].colorlist.resize(sizecolorlist); for(uint32_t l = 0; l < sizecolorlist; l++) caste.ColorModifier[k].colorlist[l] = p_colorlist[l]; + // color mod [color_modifier_part_offset] = string part p->readSTLString( p_colormod[k] + color_modifier_part_offset, caste.ColorModifier[k].part, sizeof(caste.ColorModifier[k].part)); caste.ColorModifier[k].startdate = p->readDWord( p_colormod[k] + color_modifier_startdate_offset ); caste.ColorModifier[k].enddate = p->readDWord( p_colormod[k] + color_modifier_enddate_offset ); From 8eb67af2d63c9b212fb36f5ea6571cfb9ff3157f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Mon, 20 Sep 2010 05:47:15 +0200 Subject: [PATCH 08/13] Maps without geology and features --- data/Memory-ng.xml | 47 ++++++++++++++++++++++------------------------ 1 file changed, 22 insertions(+), 25 deletions(-) diff --git a/data/Memory-ng.xml b/data/Memory-ng.xml index 0b4293d55..1825fc0a9 100644 --- a/data/Memory-ng.xml +++ b/data/Memory-ng.xml @@ -1519,36 +1519,33 @@
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
-
+
-
+
-
-
-
@@ -1580,7 +1577,7 @@ --> - + YES
From 310b1629b671866c126ab1cf82876436a014b5a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Mon, 20 Sep 2010 05:56:33 +0200 Subject: [PATCH 09/13] Fix tiletype offset --- data/Memory-ng.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/Memory-ng.xml b/data/Memory-ng.xml index 1825fc0a9..9925c8924 100644 --- a/data/Memory-ng.xml +++ b/data/Memory-ng.xml @@ -1538,7 +1538,7 @@ - + From 768f382a5e94036c61da44bf2c559a8244f503b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Tue, 21 Sep 2010 00:44:41 +0200 Subject: [PATCH 10/13] Map Features --- data/Memory-ng.xml | 20 +++++++------------- tools/supported/reveal.cpp | 16 +++++++++++++++- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/data/Memory-ng.xml b/data/Memory-ng.xml index 9925c8924..aa9f62c8b 100644 --- a/data/Memory-ng.xml +++ b/data/Memory-ng.xml @@ -1548,21 +1548,15 @@ -
- +
+ + + -
- +
+ + diff --git a/tools/supported/reveal.cpp b/tools/supported/reveal.cpp index 2c82075f7..e2a1579b2 100644 --- a/tools/supported/reveal.cpp +++ b/tools/supported/reveal.cpp @@ -8,6 +8,20 @@ using namespace std; #include #include +#ifdef LINUX_BUILD +#include +void waitmsec (int delay) +{ + usleep(delay); +} +#else +#include +void waitmsec (int delay) +{ + Sleep(delay); +} +#endif + struct hideblock { uint32_t x; @@ -48,7 +62,7 @@ int main (void) // this here hack sets the pause state, resumes DF, waits a second for it to enter the pause (I know, BS value.) and suspends. Gui->SetPauseState(true); DF->Resume(); - sleep(1); + waitmsec(1000); DF->Suspend(); // init the map From 717bfb491c316a5cd12353d19ec22b15978a701f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Tue, 21 Sep 2010 01:13:34 +0200 Subject: [PATCH 11/13] Geology --- data/Memory-ng.xml | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/data/Memory-ng.xml b/data/Memory-ng.xml index aa9f62c8b..f3395edfa 100644 --- a/data/Memory-ng.xml +++ b/data/Memory-ng.xml @@ -1560,15 +1560,12 @@ -
-
- YES From 0fe5ac98eba8f10910341ecdc83f3592ce51ff0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Tue, 21 Sep 2010 01:54:28 +0200 Subject: [PATCH 12/13] Updated Readme to have info about dfweather, current version support info. --- README.rst | 10 ++++-- Readme.html | 100 +++++++++++++++++++++++++++++----------------------- 2 files changed, 64 insertions(+), 46 deletions(-) diff --git a/README.rst b/README.rst index 1e479d107..cc4686bde 100644 --- a/README.rst +++ b/README.rst @@ -45,11 +45,12 @@ Windows fix it :) 0.31.01 - 0.31.03 legacy -0.31.04 - 0.31.12 SDL +0.31.04 - 0.31.13 SDL +There are missing offsets but Map tools should be OK. Wait for updates... Linux ===== -0.31.05 - 0.31.12 native. +0.31.05 - 0.31.13 native. There are missing offsets but Map tools should be OK. Linux support is a bit lacking, I'm working on it. All supported Windows versions running in wine can be used with native DFHack binaries. @@ -128,6 +129,11 @@ dfcleartask =========== Solves the problem of unusable items after reclaim by clearing the 'in_job' bit of all items. +dfweather +=========== +Lets you change the current weather to 'clear sky', 'rainy' or 'snowing'. Fill those ponds without mucking around with dfliquids +:D Rain can also stop brush fires. + Your tool here ============== Write one ;) diff --git a/Readme.html b/Readme.html index 98eb64c8a..40689908c 100644 --- a/Readme.html +++ b/Readme.html @@ -338,35 +338,37 @@ allow for easier development of new tools.

  • dfliquids
  • dfposition
  • dfprospector
  • -
  • dfreveal
  • -
  • dfunstuck
  • -
  • dfvdig
  • -
  • dfflows
  • -
  • dfattachtest
  • -
  • dfsuspend
  • -
  • dfexpbench
  • -
  • dfdoffsets
  • -
  • dfcleartask
  • -
  • Your tool here
  • +
  • dfprobe
  • +
  • dfreveal
  • +
  • dfunstuck
  • +
  • dfvdig
  • +
  • dfflows
  • +
  • dfattachtest
  • +
  • dfsuspend
  • +
  • dfexpbench
  • +
  • dfdoffsets
  • +
  • dfcleartask
  • +
  • dfweather
  • +
  • Your tool here
  • -
  • Using the library as a developer