diff --git a/.gitmodules b/.gitmodules index 5fcc3ec0d..76fb139db 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,3 +4,6 @@ [submodule "plugins/df2mc"] path = plugins/df2mc url = git://github.com/peterix/DF2MC.git +[submodule "library/xml"] + path = library/xml + url = git://github.com/peterix/df-structures.git diff --git a/COMPILE.rst b/COMPILE.rst index ab6debd78..175060060 100644 --- a/COMPILE.rst +++ b/COMPILE.rst @@ -19,8 +19,8 @@ a 64-bit distribution like Arch, you'll need the multilib development tools and Before you can build anything, you'll also need ``cmake``. It is advisable to also get ``ccmake`` on distributions that split the cmake package into multiple parts. -For the code generation parts, you need perl and the XML::LibXML perl package. -You should be able to find them in your distro repositories (on Arch linux 'perl-xml-libxml'). +For the code generation parts, you need perl and the XML::LibXML and XML::LibXSLT perl packages. +You should be able to find them in your distro repositories (on Arch linux 'perl-xml-libxml' and 'perl-xml-libxslt'). Build ===== @@ -58,9 +58,11 @@ You'll need a copy of Microsoft Visual C++ 2010. The Express version is sufficie Grab it from Microsoft's site. For the code generation parts, you'll need perl and XML::LibXML. You can install them like this: + * download and install strawberry perl from http://strawberryperl.com/ * reboot so that the system can pick up the new binary path * open a cmd.exe window and run "cpan XML::LibXML" (obviously without the quotes). This can take a while to complete. +* Same with "cpan XML::LibXSLT". Build ===== diff --git a/Compile.html b/Compile.html index 95847f4f4..35e4ff3e6 100644 --- a/Compile.html +++ b/Compile.html @@ -351,8 +351,8 @@ ul.auto-toc { a 64-bit distribution like Arch, you'll need the multilib development tools and libraries.

Before you can build anything, you'll also need cmake. It is advisable to also get ccmake on distributions that split the cmake package into multiple parts.

-

For the code generation parts, you need perl and the XML::LibXML perl package. -You should be able to find them in your distro repositories (on Arch linux 'perl-xml-libxml').

+

For the code generation parts, you need perl and the XML::LibXML and XML::LibXSLT perl packages. +You should be able to find them in your distro repositories (on Arch linux 'perl-xml-libxml' and 'perl-xml-libxslt').

Build

@@ -384,10 +384,13 @@ site: +
  • download and install strawberry perl from http://strawberryperl.com/
  • +
  • reboot so that the system can pick up the new binary path
  • +
  • open a cmd.exe window and run "cpan XML::LibXML" (obviously without the quotes). This can take a while to complete.
  • +
  • Same with "cpan XML::LibXSLT".
  • +

    Build

    Open the build folder and double click the batch script there. This will eventually open diff --git a/Memory.xml b/Memory.xml index b4f7ce1f3..5360d6481 100644 --- a/Memory.xml +++ b/Memory.xml @@ -1078,12 +1078,21 @@

    + + +
    +
    +
    +
    +
    +
    +
    @@ -2316,12 +2325,24 @@
    + + + +
    +
    +
    + +
    +
    +
    +
    +
    cmake @@ -3188,12 +3209,24 @@
    + + + +
    +
    +
    + +
    +
    +
    + +
    diff --git a/build/.gitignore b/build/.gitignore index 474fe987c..990de1678 100644 --- a/build/.gitignore +++ b/build/.gitignore @@ -1 +1,2 @@ -build-real \ No newline at end of file +VC2010 +DF_PATH.txt diff --git a/build/build-debug.bat b/build/build-debug.bat new file mode 100644 index 000000000..a9492de13 --- /dev/null +++ b/build/build-debug.bat @@ -0,0 +1,4 @@ +call "%VS100COMNTOOLS%vsvars32.bat" +cd VC2010 +msbuild /m /p:Platform=Win32 /p:Configuration=RelWithDebInfo ALL_BUILD.vcxproj +cd .. \ No newline at end of file diff --git a/build/build-release.bat b/build/build-release.bat new file mode 100644 index 000000000..95c15596c --- /dev/null +++ b/build/build-release.bat @@ -0,0 +1,4 @@ +call "%VS100COMNTOOLS%vsvars32.bat" +cd VC2010 +msbuild /m /p:Platform=Win32 /p:Configuration=Release ALL_BUILD.vcxproj +cd .. \ No newline at end of file diff --git a/build/generate-MSVC-2010.bat b/build/generate-MSVC-2010.bat deleted file mode 100644 index 00c990083..000000000 --- a/build/generate-MSVC-2010.bat +++ /dev/null @@ -1,5 +0,0 @@ -mkdir VC2010 -cd VC2010 -echo Pre-generating a build folder -cmake ..\.. -G"Visual Studio 10" -cmake-gui . \ No newline at end of file diff --git a/build/generate-MSVC-all.bat b/build/generate-MSVC-all.bat new file mode 100644 index 000000000..686ec3bcf --- /dev/null +++ b/build/generate-MSVC-all.bat @@ -0,0 +1,6 @@ +IF EXIST DF_PATH.txt SET /P _DF_PATH= 0 Then + Set spoFile = fso.CreateTextFile("DF_PATH.txt", True) + spoFile.WriteLine(objF.Self.Path) + End If +End If + +Function IsValue(obj) + ' Check whether the value has been returned. + Dim tmp + On Error Resume Next + tmp = " " & obj + If Err <> 0 Then + IsValue = False + Else + IsValue = True + End If + On Error GoTo 0 +End Function \ No newline at end of file diff --git a/library/CMakeLists.txt b/library/CMakeLists.txt index 9a87db9af..f24e21fd3 100644 --- a/library/CMakeLists.txt +++ b/library/CMakeLists.txt @@ -13,60 +13,60 @@ include_directories (include) include_directories (depends/md5) include_directories (depends/tinyxml) include_directories (depends/tthread) -include_directories (private) -execute_process(COMMAND perl xml/list.pl xml include/dfhack/df ";" +execute_process(COMMAND perl xml/list.pl xml include/df ";" WORKING_DIRECTORY ${dfapi_SOURCE_DIR} OUTPUT_VARIABLE GENERATED_HDRS) SET(PROJECT_HDRS_INTERNAL - private/ContextShared.h - private/Internal.h - private/wdirent.h ) SET(PROJECT_HDRS +include/Internal.h include/DFHack.h -include/dfhack/Console.h -include/dfhack/Core.h -include/dfhack/DataDefs.h -include/dfhack/Error.h -include/dfhack/Export.h -include/dfhack/FakeSDL.h -include/dfhack/MiscUtils.h -include/dfhack/Module.h -include/dfhack/Pragma.h -include/dfhack/Process.h -include/dfhack/TileTypes.h -include/dfhack/Types.h -include/dfhack/Vector.h -include/dfhack/VersionInfo.h -include/dfhack/VersionInfoFactory.h -include/dfhack/Virtual.h -include/dfhack/extra/MapExtras.h -include/dfhack/extra/stopwatch.h -include/dfhack/extra/termutil.h -include/dfhack/modules/Buildings.h -include/dfhack/modules/Constructions.h -include/dfhack/modules/Units.h -include/dfhack/modules/Engravings.h -include/dfhack/modules/Gui.h -include/dfhack/modules/Items.h -include/dfhack/modules/kitchen.h -include/dfhack/modules/Maps.h -include/dfhack/modules/Materials.h -include/dfhack/modules/Notes.h -include/dfhack/modules/Translation.h -include/dfhack/modules/Vegetation.h -include/dfhack/modules/Vermin.h -include/dfhack/modules/World.h -include/dfhack/modules/Graphic.h +include/Console.h +include/Core.h +include/DataDefs.h +include/Error.h +include/Export.h +include/Hooks.h +include/MiscUtils.h +include/Module.h +include/Pragma.h +include/MemAccess.h +include/SDL_events.h +include/SDL_keyboard.h +include/SDL_keysym.h +include/TileTypes.h +include/Types.h +include/Vector.h +include/VersionInfo.h +include/VersionInfoFactory.h +include/Virtual.h +include/modules/Buildings.h +include/modules/Constructions.h +include/modules/Units.h +include/modules/Engravings.h +include/modules/Gui.h +include/modules/Items.h +include/modules/kitchen.h +include/modules/Maps.h +include/modules/MapCache.h +include/modules/Materials.h +include/modules/Notes.h +include/modules/Translation.h +include/modules/Vegetation.h +include/modules/Vermin.h +include/modules/World.h +include/modules/Graphic.h ) SET(PROJECT_SRCS Core.cpp DataDefs.cpp DataStatics.cpp +DataStaticsCtor.cpp +MiscUtils.cpp PluginManager.cpp TileTypes.cpp VersionInfo.cpp @@ -104,17 +104,18 @@ SET(PROJECT_HDRS_LINUX ) SET(PROJECT_HDRS_WINDOWS +include/wdirent.h ) SET(PROJECT_SRCS_LINUX Console-linux.cpp -FakeSDL-linux.cpp +Hooks-linux.cpp Process-linux.cpp ) SET(PROJECT_SRCS_WINDOWS Console-windows.cpp -FakeSDL-windows.cpp +Hooks-windows.cpp Process-windows.cpp ) @@ -134,17 +135,18 @@ LIST(APPEND PROJECT_SRCS ${PROJECT_HDRS}) SET_SOURCE_FILES_PROPERTIES(${GENERATED_HDRS} PROPERTIES HEADER_FILE_ONLY TRUE GENERATED TRUE) +FILE(GLOB GENERATE_INPUT_SCRIPTS ${dfapi_SOURCE_DIR}/xml/*.pm ${dfapi_SOURCE_DIR}/xml/*.xslt) FILE(GLOB GENERATE_INPUT_XMLS ${dfapi_SOURCE_DIR}/xml/*.xml) ADD_CUSTOM_COMMAND( - OUTPUT ${dfapi_SOURCE_DIR}/include/dfhack/df/static.inc - COMMAND perl xml/codegen.pl xml include/dfhack/df + OUTPUT ${dfapi_SOURCE_DIR}/include/df/static.inc + COMMAND perl xml/codegen.pl xml include/df WORKING_DIRECTORY ${dfapi_SOURCE_DIR} MAIN_DEPENDENCY ${dfapi_SOURCE_DIR}/xml/codegen.pl - DEPENDS ${GENERATE_INPUT_XMLS} + DEPENDS ${GENERATE_INPUT_XMLS} ${GENERATE_INPUT_SCRIPTS} ) -ADD_CUSTOM_TARGET(generate_headers DEPENDS ${dfapi_SOURCE_DIR}/include/dfhack/df/static.inc) +ADD_CUSTOM_TARGET(generate_headers DEPENDS ${dfapi_SOURCE_DIR}/include/df/static.inc) # Compilation diff --git a/library/Console-linux.cpp b/library/Console-linux.cpp index e15a6e9cb..c1bea16d6 100644 --- a/library/Console-linux.cpp +++ b/library/Console-linux.cpp @@ -61,8 +61,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include -#include "dfhack/Console.h" -#include "dfhack/FakeSDL.h" +#include "Console.h" +#include "Hooks.h" using namespace DFHack; #include "tinythread.h" diff --git a/library/Console-windows.cpp b/library/Console-windows.cpp index 4daab5c2f..de2c2aca8 100644 --- a/library/Console-windows.cpp +++ b/library/Console-windows.cpp @@ -50,8 +50,8 @@ POSSIBILITY OF SUCH DAMAGE. #include #include -#include "dfhack/Console.h" -#include "dfhack/FakeSDL.h" +#include "Console.h" +#include "Hooks.h" #include #include #include diff --git a/library/Core.cpp b/library/Core.cpp index 5296a057e..4a3dacd25 100644 --- a/library/Core.cpp +++ b/library/Core.cpp @@ -34,30 +34,37 @@ distribution. #include using namespace std; -#include "dfhack/Error.h" -#include "dfhack/Process.h" -#include "dfhack/Core.h" -#include "dfhack/DataDefs.h" -#include "dfhack/Console.h" -#include "dfhack/Module.h" -#include "dfhack/VersionInfoFactory.h" -#include "dfhack/VersionInfo.h" -#include "dfhack/PluginManager.h" +#include "Error.h" +#include "MemAccess.h" +#include "Core.h" +#include "DataDefs.h" +#include "Console.h" +#include "Module.h" +#include "VersionInfoFactory.h" +#include "VersionInfo.h" +#include "PluginManager.h" #include "ModuleFactory.h" -#include "dfhack/modules/Gui.h" -#include "dfhack/modules/World.h" -#include "dfhack/modules/Graphic.h" +#include "modules/Gui.h" +#include "modules/World.h" +#include "modules/Graphic.h" using namespace DFHack; -#include "dfhack/SDL_fakes/events.h" +#include "SDL_events.h" + +#include "df/ui.h" +#include "df/world.h" +#include "df/world_data.h" +#include "df/interface.h" +#include "df/viewscreen_dwarfmodest.h" #include #include #include #include #include "tinythread.h" -using namespace tthread; +using namespace tthread; +using namespace df::enums; struct Core::Cond { @@ -91,9 +98,35 @@ struct Core::Cond void cheap_tokenise(string const& input, vector &output) { - istringstream str(input); - istream_iterator cur(str), end; - output.assign(cur, end); + string *cur = NULL; + + for (unsigned i = 0; i < input.size(); i++) { + char c = input[i]; + if (isspace(c)) { + cur = NULL; + } else { + if (!cur) { + output.push_back(""); + cur = &output.back(); + } + + if (c == '"') { + for (i++; i < input.size(); i++) { + c = input[i]; + if (c == '"') + break; + else if (c == '\\') { + if (++i < input.size()) + cur->push_back(input[i]); + } + else + cur->push_back(c); + } + } else { + cur->push_back(c); + } + } + } } struct IODATA @@ -119,8 +152,17 @@ void fHKthread(void * iodata) std::string stuff = core->getHotkeyCmd(); // waits on mutex! if(!stuff.empty()) { - vector crap; - command_result cr = plug_mgr->InvokeCommand(stuff, crap, false); + vector args; + cheap_tokenise(stuff, args); + if (args.empty()) { + core->con.printerr("Empty hotkey command.\n"); + continue; + } + + string first = args[0]; + args.erase(args.begin()); + command_result cr = plug_mgr->InvokeCommand(first, args, false); + if(cr == CR_WOULD_BREAK) { core->con.printerr("It isn't possible to run an interactive command outside the console.\n"); @@ -129,53 +171,25 @@ void fHKthread(void * iodata) } } -// A thread function... for the interactive console. -void fIOthread(void * iodata) +static void runInteractiveCommand(Core *core, PluginManager *plug_mgr, int &clueless_counter, const string &command) { - IODATA * iod = ((IODATA*) iodata); - Core * core = iod->core; - PluginManager * plug_mgr = ((IODATA*) iodata)->plug_mgr; - CommandHistory main_history; - main_history.load("dfhack.history"); Console & con = core->con; - if(plug_mgr == 0 || core == 0) - { - con.printerr("Something horrible happened in Core's constructor...\n"); - return; - } - con.print("DFHack is ready. Have a nice day!\n" - "Type in '?' or 'help' for general help, 'ls' to see all commands.\n"); - int clueless_counter = 0; - while (true) + + if (!command.empty()) { - string command = ""; - int ret = con.lineedit("[DFHack]# ",command, main_history); - if(ret == -2) - { - cerr << "Console is shutting down properly." << endl; - return; - } - else if(ret == -1) - { - cerr << "Console caught an unspecified error." << endl; - continue; - } - else if(ret) - { - // a proper, non-empty command was entered - main_history.add(command); - main_history.save("dfhack.history"); - } // cut the input into parts vector parts; cheap_tokenise(command,parts); if(parts.size() == 0) { clueless_counter ++; - continue; + return; } string first = parts[0]; parts.erase(parts.begin()); + + if (first[0] == '#') return; + cerr << "Invoking: " << command << endl; // let's see what we actually got @@ -194,6 +208,7 @@ void fIOthread(void * iodata) " cls - Clear the console.\n" " fpause - Force DF to pause.\n" " die - Force DF to close immediately\n" + " keybinding - Modify bindings of commands to keys\n" "Plugin management (useful for developers):\n" //" belongs COMMAND - Tell which plugin a command belongs to.\n" " plug [PLUGIN|v] - List plugin state and description.\n" @@ -202,6 +217,27 @@ void fIOthread(void * iodata) " reload PLUGIN|all - Reload a plugin or all loaded plugins.\n" ); } + else if (parts.size() == 1) + { + Plugin *plug = plug_mgr->getPluginByCommand(parts[0]); + if (plug) { + for (int j = 0; j < plug->size();j++) + { + const PluginCommand & pcmd = (plug->operator[](j)); + if (pcmd.name != parts[0]) + continue; + + if (pcmd.isHotkeyCommand()) + con.color(Console::COLOR_CYAN); + con.print("%s: %s\n",pcmd.name.c_str(), pcmd.description.c_str()); + con.reset_color(); + if (!pcmd.usage.empty()) + con << "Usage:\n" << pcmd.usage << flush; + return; + } + } + con.printerr("Unknown command: %s\n", parts[0].c_str()); + } else { con.printerr("not implemented yet\n"); @@ -301,7 +337,10 @@ void fIOthread(void * iodata) else for (int j = 0; j < plug->size();j++) { const PluginCommand & pcmd = (plug->operator[](j)); + if (pcmd.isHotkeyCommand()) + con.color(Console::COLOR_CYAN); con.print(" %-22s - %s\n",pcmd.name.c_str(), pcmd.description.c_str()); + con.reset_color(); } } else @@ -329,7 +368,10 @@ void fIOthread(void * iodata) for (int j = 0; j < plug->size();j++) { const PluginCommand & pcmd = (plug->operator[](j)); + if (pcmd.isHotkeyCommand()) + con.color(Console::COLOR_CYAN); con.print(" %-22s- %s\n",pcmd.name.c_str(), pcmd.description.c_str()); + con.reset_color(); } } } @@ -344,6 +386,49 @@ void fIOthread(void * iodata) con.print("%s\n", plug->getName().c_str()); } } + else if(first == "keybinding") + { + if (parts.size() >= 3 && (parts[0] == "set" || parts[0] == "add")) + { + std::string keystr = parts[1]; + if (parts[0] == "set") + core->ClearKeyBindings(keystr); + for (int i = parts.size()-1; i >= 2; i--) + { + if (!core->AddKeyBinding(keystr, parts[i])) { + con.printerr("Invalid key spec: %s\n", keystr.c_str()); + break; + } + } + } + else if (parts.size() >= 2 && parts[0] == "clear") + { + for (unsigned i = 1; i < parts.size(); i++) + { + if (!core->ClearKeyBindings(parts[i])) { + con.printerr("Invalid key spec: %s\n", parts[i].c_str()); + break; + } + } + } + else if (parts.size() == 2 && parts[0] == "list") + { + std::vector list = core->ListKeyBindings(parts[1]); + if (list.empty()) + con << "No bindings." << endl; + for (unsigned i = 0; i < list.size(); i++) + con << " " << list[i] << endl; + } + else + { + con << "Usage:" << endl + << " keybinding list " << endl + << " keybinding clear ..." << endl + << " keybinding set \"cmdline\" \"cmdline\"..." << endl + << " keybinding add \"cmdline\" \"cmdline\"..." << endl + << "Later adds, and earlier items within one command have priority." << endl; + } + } else if(first == "fpause") { World * w = core->getWorld(); @@ -384,6 +469,70 @@ void fIOthread(void * iodata) */ } } + } +} + +static void loadInitFile(Core *core, PluginManager *plug_mgr, string fname) +{ + ifstream init(fname); + if (init.bad()) + return; + + int tmp = 0; + string command; + while (getline(init, command)) + { + if (!command.empty()) + runInteractiveCommand(core, plug_mgr, tmp, command); + } +} + +// A thread function... for the interactive console. +void fIOthread(void * iodata) +{ + IODATA * iod = ((IODATA*) iodata); + Core * core = iod->core; + PluginManager * plug_mgr = ((IODATA*) iodata)->plug_mgr; + + CommandHistory main_history; + main_history.load("dfhack.history"); + + Console & con = core->con; + if(plug_mgr == 0 || core == 0) + { + con.printerr("Something horrible happened in Core's constructor...\n"); + return; + } + + loadInitFile(core, plug_mgr, "dfhack.init"); + + con.print("DFHack is ready. Have a nice day!\n" + "Type in '?' or 'help' for general help, 'ls' to see all commands.\n"); + + int clueless_counter = 0; + while (true) + { + string command = ""; + int ret = con.lineedit("[DFHack]# ",command, main_history); + if(ret == -2) + { + cerr << "Console is shutting down properly." << endl; + return; + } + else if(ret == -1) + { + cerr << "Console caught an unspecified error." << endl; + continue; + } + else if(ret) + { + // a proper, non-empty command was entered + main_history.add(command); + main_history.save("dfhack.history"); + } + + runInteractiveCommand(core, plug_mgr, clueless_counter, command); + if(clueless_counter == 3) { con.print("Do 'help' or '?' for the list of available commands.\n"); @@ -408,11 +557,12 @@ Core::Core() StackMutex = 0; core_cond = 0; // set up hotkey capture - memset(hotkey_states,0,sizeof(hotkey_states)); hotkey_set = false; HotkeyMutex = 0; HotkeyCond = 0; misc_data_mutex=0; + last_world_data_ptr = NULL; + top_viewscreen = NULL; }; void Core::fatal (std::string output, bool deactivate) @@ -497,7 +647,7 @@ bool Core::Init() } // initialize data defs - virtual_identity::Init(); + virtual_identity::Init(this); InitDataDefGlobals(this); // create mutex for syncing with interactive tasks @@ -605,8 +755,36 @@ int Core::Update() if(errorstate) return -1; + // detect if the game was loaded or unloaded in the meantime + void *new_wdata = NULL; + if (df::global::world) { + df::world_data *wdata = df::global::world->world_data; + // when the game is unloaded, world_data isn't deleted, but its contents are + if (wdata && !wdata->sites.empty()) + new_wdata = wdata; + } + + if (new_wdata != last_world_data_ptr) { + last_world_data_ptr = new_wdata; + plug_mgr->OnStateChange(new_wdata ? SC_GAME_LOADED : SC_GAME_UNLOADED); + } + + // detect if the viewscreen changed + if (df::global::gview) + { + df::viewscreen *screen = &df::global::gview->view; + while (screen->child) + screen = screen->child; + if (screen != top_viewscreen) + { + top_viewscreen = screen; + plug_mgr->OnStateChange(SC_VIEWSCREEN_CHANGED); + } + } + // notify all the plugins that a game tick is finished plug_mgr->OnUpdate(); + // wake waiting tools // do not allow more tools to join in while we process stuff here StackMutex->lock(); @@ -695,39 +873,168 @@ int Core::SDL_Event(SDL::Event* ev, int orig_return) if(ev && ev->type == SDL::ET_KEYDOWN || ev->type == SDL::ET_KEYUP) { SDL::KeyboardEvent * ke = (SDL::KeyboardEvent *)ev; - bool shift = ke->ksym.mod & SDL::KMOD_SHIFT; - // consuming F1 .. F8 - int idx = ke->ksym.sym - SDL::K_F1; - if(idx < 0 || idx > 7) - return orig_return; - idx += 8*shift; - // now we have the real index... - if(ke->state == SDL::BTN_PRESSED && !hotkey_states[idx]) + + if(ke->state == SDL::BTN_PRESSED && !hotkey_states[ke->ksym.sym]) { - hotkey_states[idx] = 1; - Gui * g = getGui(); - if(g->hotkeys && g->df_interface && g->df_menu_state) - { - t_viewscreen * ws = g->GetCurrentScreen(); - // FIXME: put hardcoded values into memory.xml - if(ws->getClassName() == "viewscreen_dwarfmodest" && *g->df_menu_state == 0x23) - return orig_return; - else - { - t_hotkey & hotkey = (*g->hotkeys)[idx]; - setHotkeyCmd(hotkey.name); - } - } + hotkey_states[ke->ksym.sym] = true; + + int mod = 0; + if (ke->ksym.mod & SDL::KMOD_SHIFT) mod |= 1; + if (ke->ksym.mod & SDL::KMOD_CTRL) mod |= 2; + if (ke->ksym.mod & SDL::KMOD_ALT) mod |= 4; + + SelectHotkey(ke->ksym.sym, mod); } else if(ke->state == SDL::BTN_RELEASED) { - hotkey_states[idx] = 0; + hotkey_states[ke->ksym.sym] = false; } } return orig_return; // do stuff with the events... } +bool Core::SelectHotkey(int sym, int modifiers) +{ + // Find the topmost viewscreen + if (!df::global::gview || !df::global::ui) + return false; + + df::viewscreen *screen = &df::global::gview->view; + while (screen->child) + screen = screen->child; + + std::string cmd; + + { + tthread::lock_guard lock(*HotkeyMutex); + + // Check the internal keybindings + std::vector &bindings = key_bindings[sym]; + for (int i = bindings.size()-1; i >= 0; --i) { + if (bindings[i].modifiers != modifiers) + continue; + if (!plug_mgr->CanInvokeHotkey(bindings[i].command[0], screen)) + continue; + cmd = bindings[i].cmdline; + break; + } + + if (cmd.empty()) { + // Check the hotkey keybindings + int idx = sym - SDL::K_F1; + if(idx >= 0 && idx < 8) + { + if (modifiers & 1) + idx += 8; + + if (strict_virtual_cast(screen) && + df::global::ui->main.mode != ui_sidebar_mode::Hotkeys) + { + cmd = df::global::ui->main.hotkeys[idx].name; + } + } + } + } + + if (!cmd.empty()) { + setHotkeyCmd(cmd); + return true; + } + else + return false; +} + +static bool parseKeySpec(std::string keyspec, int *psym, int *pmod) +{ + *pmod = 0; + + // ugh, ugly + for (;;) { + if (keyspec.size() > 6 && keyspec.substr(0, 6) == "Shift-") { + *pmod |= 1; + keyspec = keyspec.substr(6); + } else if (keyspec.size() > 5 && keyspec.substr(0, 5) == "Ctrl-") { + *pmod |= 2; + keyspec = keyspec.substr(5); + } else if (keyspec.size() > 4 && keyspec.substr(0, 4) == "Alt-") { + *pmod |= 4; + keyspec = keyspec.substr(4); + } else + break; + } + + if (keyspec.size() == 1 && keyspec[0] >= 'A' && keyspec[0] <= 'Z') { + *psym = SDL::K_a + (keyspec[0]-'A'); + return true; + } else if (keyspec.size() == 2 && keyspec[0] == 'F' && keyspec[1] >= '1' && keyspec[1] <= '9') { + *psym = SDL::K_F1 + (keyspec[1]-'1'); + return true; + } else + return false; +} + +bool Core::ClearKeyBindings(std::string keyspec) +{ + int sym, mod; + if (!parseKeySpec(keyspec, &sym, &mod)) + return false; + + tthread::lock_guard lock(*HotkeyMutex); + + std::vector &bindings = key_bindings[sym]; + for (int i = bindings.size()-1; i >= 0; --i) { + if (bindings[i].modifiers == mod) + bindings.erase(bindings.begin()+i); + } + + return true; +} + +bool Core::AddKeyBinding(std::string keyspec, std::string cmdline) +{ + int sym; + KeyBinding binding; + if (!parseKeySpec(keyspec, &sym, &binding.modifiers)) + return false; + + cheap_tokenise(cmdline, binding.command); + if (binding.command.empty()) + return false; + + tthread::lock_guard lock(*HotkeyMutex); + + // Don't add duplicates + std::vector &bindings = key_bindings[sym]; + for (int i = bindings.size()-1; i >= 0; --i) { + if (bindings[i].modifiers == binding.modifiers && + bindings[i].cmdline == cmdline) + return true; + } + + binding.cmdline = cmdline; + bindings.push_back(binding); + return true; +} + +std::vector Core::ListKeyBindings(std::string keyspec) +{ + int sym, mod; + std::vector rv; + if (!parseKeySpec(keyspec, &sym, &mod)) + return rv; + + tthread::lock_guard lock(*HotkeyMutex); + + std::vector &bindings = key_bindings[sym]; + for (int i = bindings.size()-1; i >= 0; --i) { + if (bindings[i].modifiers == mod) + rv.push_back(bindings[i].cmdline); + } + + return rv; +} + //////////////// // ClassNamCheck //////////////// diff --git a/library/DataDefs.cpp b/library/DataDefs.cpp index 2f1f9c238..bcdb388b5 100644 --- a/library/DataDefs.cpp +++ b/library/DataDefs.cpp @@ -28,12 +28,12 @@ distribution. #include #include -#include "dfhack/Process.h" -#include "dfhack/Core.h" -#include "dfhack/VersionInfo.h" +#include "MemAccess.h" +#include "Core.h" +#include "VersionInfo.h" #include "tinythread.h" // must be last due to MS stupidity -#include "dfhack/DataDefs.h" +#include "DataDefs.h" using namespace DFHack; @@ -78,31 +78,62 @@ virtual_identity *virtual_identity::get(virtual_ptr instance_ptr) for (virtual_identity *p = list; p; p = p->next) { if (strcmp(name.c_str(), p->getOriginalName()) != 0) continue; + + if (p->vtable_ptr && p->vtable_ptr != vtable) { + std::cerr << "Conflicting vtable ptr for class '" << p->getName() + << "': found 0x" << std::hex << unsigned(vtable) + << ", previous 0x" << unsigned(p->vtable_ptr) << std::dec << std::endl; + abort(); + } else if (!p->vtable_ptr) { + std::cerr << "class '" << p->getName() << "': vtable = 0x" + << std::hex << unsigned(vtable) << std::dec << std::endl; + } + known[vtable] = p; p->vtable_ptr = vtable; return p; } + std::cerr << "UNKNOWN CLASS '" << name << "': vtable = 0x" + << std::hex << unsigned(vtable) << std::dec << std::endl; + known[vtable] = NULL; return NULL; } -bool virtual_identity::check_instance(virtual_ptr instance_ptr, bool allow_subclasses) +bool virtual_identity::is_subclass(virtual_identity *actual) { - virtual_identity *actual = get(instance_ptr); - - if (actual == this) return true; - if (!allow_subclasses || !actual) return false; - - do { - actual = actual->parent; + for (; actual; actual = actual->parent) if (actual == this) return true; - } while (actual); return false; } -void virtual_identity::Init() +void virtual_identity::adjust_vtable(virtual_ptr obj, virtual_identity *main) +{ + if (vtable_ptr) { + *(void**)obj = vtable_ptr; + return; + } + + if (main && main != this && is_subclass(main)) + return; + + std::cerr << "Attempt to create class '" << getName() << "' without known vtable." << std::endl; + abort(); +} + +virtual_ptr virtual_identity::clone(virtual_ptr obj) +{ + virtual_identity *id = get(obj); + if (!id) return NULL; + virtual_ptr copy = id->instantiate(); + if (!copy) return NULL; + id->do_copy(copy, obj); + return copy; +} + +void virtual_identity::Init(Core *core) { if (!known_mutex) known_mutex = new tthread::mutex(); @@ -119,19 +150,31 @@ void virtual_identity::Init() p->parent->has_children = true; } } + + // Read pre-filled vtable ptrs + OffsetGroup *ptr_table = core->vinfo->getGroup("vtable"); + for (virtual_identity *p = list; p; p = p->next) { + uint32_t tmp; + if (ptr_table->getSafeAddress(p->getName(),tmp)) + p->vtable_ptr = (void*)tmp; + } } -#define GLOBAL(name,tname) \ - df::tname *df::global::name = NULL; +#define SIMPLE_GLOBAL(name,tname) \ + tname *df::global::name = NULL; +#define GLOBAL(name,tname) SIMPLE_GLOBAL(name,df::tname) DF_KNOWN_GLOBALS #undef GLOBAL +#undef SIMPLE_GLOBAL void DFHack::InitDataDefGlobals(Core *core) { OffsetGroup *global_table = core->vinfo->getGroup("global"); uint32_t tmp; -#define GLOBAL(name,tname) \ - if (global_table->getSafeAddress(#name,tmp)) df::global::name = (df::tname*)tmp; +#define SIMPLE_GLOBAL(name,tname) \ + if (global_table->getSafeAddress(#name,tmp)) df::global::name = (tname*)tmp; +#define GLOBAL(name,tname) SIMPLE_GLOBAL(name,df::tname) DF_KNOWN_GLOBALS #undef GLOBAL +#undef SIMPLE_GLOBAL } diff --git a/library/DataStatics.cpp b/library/DataStatics.cpp index e3a448eac..f47c0fe05 100644 --- a/library/DataStatics.cpp +++ b/library/DataStatics.cpp @@ -1,10 +1,10 @@ #include "Internal.h" -#include "dfhack/DataDefs.h" -#include "dfhack/MiscUtils.h" +#include "DataDefs.h" +#include "MiscUtils.h" -#include "dfhack/df/world.h" -#include "dfhack/df/world_data.h" -#include "dfhack/df/ui.h" +#include "df/world.h" +#include "df/world_data.h" +#include "df/ui.h" namespace { template @@ -14,4 +14,5 @@ namespace { } // Instantiate all the static objects -#include "dfhack/df/static.inc" +#include "df/static.inc" +#include "df/static.enums.inc" diff --git a/library/DataStaticsCtor.cpp b/library/DataStaticsCtor.cpp new file mode 100644 index 000000000..2e4e84baa --- /dev/null +++ b/library/DataStaticsCtor.cpp @@ -0,0 +1,6 @@ +#include "Internal.h" +#include "DataDefs.h" +#include "MiscUtils.h" + +// Object constructors +#include "df/static.ctors.inc" diff --git a/library/FakeSDL-linux.cpp b/library/Hooks-linux.cpp similarity index 98% rename from library/FakeSDL-linux.cpp rename to library/Hooks-linux.cpp index 59ae1bbd4..69bb9f228 100644 --- a/library/FakeSDL-linux.cpp +++ b/library/Hooks-linux.cpp @@ -39,8 +39,8 @@ distribution. #include #include "DFHack.h" -#include "dfhack/Core.h" -#include "dfhack/FakeSDL.h" +#include "Core.h" +#include "Hooks.h" #include /* diff --git a/library/FakeSDL-windows.cpp b/library/Hooks-windows.cpp similarity index 99% rename from library/FakeSDL-windows.cpp rename to library/Hooks-windows.cpp index d388b75d5..51e197722 100644 --- a/library/FakeSDL-windows.cpp +++ b/library/Hooks-windows.cpp @@ -28,12 +28,12 @@ distribution. #include #include #include -#include "dfhack/Core.h" -#include "dfhack/FakeSDL.h" +#include "Core.h" +#include "Hooks.h" #include #include "tinythread.h" -#include "dfhack/modules/Graphic.h" +#include "modules/Graphic.h" /* * Plugin loading functions diff --git a/library/include/dfhack/extra/stopwatch.h b/library/MiscUtils.cpp similarity index 50% rename from library/include/dfhack/extra/stopwatch.h rename to library/MiscUtils.cpp index 5ef7d11a8..47deea04c 100644 --- a/library/include/dfhack/extra/stopwatch.h +++ b/library/MiscUtils.cpp @@ -1,6 +1,33 @@ -// Returns the amount of milliseconds elapsed since the UNIX epoch. -// Works on both windows and linux. -// source: http://stackoverflow.com/questions/1861294/how-to-calculate-execution-time-of-a-code-snippet-in-c +/* +https://github.com/peterix/dfhack +Copyright (c) 2009-2011 Petr Mrázek (peterix@gmail.com) + +This software is provided 'as-is', without any express or implied +warranty. In no event will the authors be held liable for any +damages arising from the use of this software. + +Permission is granted to anyone to use this software for any +purpose, including commercial applications, and to alter it and +redistribute it freely, subject to the following restrictions: + +1. The origin of this software must not be misrepresented; you must +not claim that you wrote the original software. If you use this +software in a product, an acknowledgment in the product documentation +would be appreciated but is not required. + +2. Altered source versions must be plainly marked as such, and +must not be misrepresented as being the original software. + +3. This notice may not be removed or altered from any source +distribution. +*/ + +#include "Internal.h" +#include "Export.h" +#include "Core.h" +#include "MiscUtils.h" + + #ifndef LINUX_BUILD #include @@ -44,4 +71,4 @@ uint64_t GetTimeMs64() return ret; } -#endif +#endif \ No newline at end of file diff --git a/library/PluginManager.cpp b/library/PluginManager.cpp index 7a7bb0981..9acd05aa4 100644 --- a/library/PluginManager.cpp +++ b/library/PluginManager.cpp @@ -23,10 +23,13 @@ distribution. */ #include "Internal.h" -#include "dfhack/Core.h" -#include "dfhack/Process.h" -#include "dfhack/PluginManager.h" -#include "dfhack/Console.h" +#include "Core.h" +#include "MemAccess.h" +#include "PluginManager.h" +#include "Console.h" + +#include "DataDefs.h" + using namespace DFHack; #include @@ -135,6 +138,7 @@ Plugin::Plugin(Core * core, const std::string & filepath, const std::string & _f plugin_shutdown = 0; plugin_status = 0; plugin_onupdate = 0; + plugin_onstatechange = 0; state = PS_UNLOADED; access = new RefLock(); } @@ -192,6 +196,7 @@ bool Plugin::load() plugin_status = (command_result (*)(Core *, std::string &)) LookupPlugin(plug, "plugin_status"); plugin_onupdate = (command_result (*)(Core *)) LookupPlugin(plug, "plugin_onupdate"); plugin_shutdown = (command_result (*)(Core *)) LookupPlugin(plug, "plugin_shutdown"); + plugin_onstatechange = (command_result (*)(Core *, state_change_event)) LookupPlugin(plug, "plugin_onstatechange"); //name = _PlugName(); plugin_lib = plug; if(plugin_init(&c,commands) == CR_OK) @@ -232,7 +237,7 @@ bool Plugin::unload() ClosePlugin(plugin_lib); state = PS_UNLOADED; access->unlock(); - return false; + return true; } else { @@ -271,13 +276,63 @@ command_result Plugin::invoke( std::string & command, std::vector { for (int i = 0; i < commands.size();i++) { - if(commands[i].name == command) + PluginCommand &cmd = commands[i]; + if(cmd.name == command) { // running interactive things from some other source than the console would break it - if(!interactive_ && commands[i].interactive) + if(!interactive_ && cmd.interactive) cr = CR_WOULD_BREAK; + else if (cmd.guard) + { + // Execute hotkey commands in a way where they can + // expect their guard conditions to be matched, + // so as to avoid duplicating checks. + // This means suspending the core beforehand. + CoreSuspender suspend(&c); + df::viewscreen *top = c.getTopViewscreen(); + + if (!cmd.guard(&c, top)) + { + c.con.printerr("Could not invoke %s: unsuitable UI state.\n", command.c_str()); + cr = CR_WRONG_USAGE; + } + else + { + cr = cmd.function(&c, parameters); + } + } else - cr = commands[i].function(&c, parameters); + { + cr = cmd.function(&c, parameters); + } + if (cr == CR_WRONG_USAGE && !cmd.usage.empty()) + c.con << "Usage:\n" << cmd.usage << flush; + break; + } + } + } + access->lock_sub(); + return cr; +} + +bool Plugin::can_invoke_hotkey( std::string & command, df::viewscreen *top ) +{ + Core & c = Core::getInstance(); + bool cr = false; + access->lock_add(); + if(state == PS_LOADED) + { + for (int i = 0; i < commands.size();i++) + { + PluginCommand &cmd = commands[i]; + if(cmd.name == command) + { + if (cmd.interactive) + cr = false; + else if (cmd.guard) + cr = cmd.guard(&c, top); + else + cr = default_hotkey(&c, top); break; } } @@ -299,6 +354,19 @@ command_result Plugin::on_update() return cr; } +command_result Plugin::on_state_change(state_change_event event) +{ + Core & c = Core::getInstance(); + command_result cr = CR_NOT_IMPLEMENTED; + access->lock_add(); + if(state == PS_LOADED && plugin_onstatechange) + { + cr = plugin_onstatechange(&c, event); + } + access->lock_sub(); + return cr; +} + Plugin::plugin_state Plugin::getState() const { return state; @@ -348,19 +416,27 @@ Plugin *PluginManager::getPluginByName (const std::string & name) return 0; } +Plugin *PluginManager::getPluginByCommand(const std::string &command) +{ + tthread::lock_guard lock(*cmdlist_mutex); + map ::iterator iter = belongs.find(command); + if (iter != belongs.end()) + return iter->second; + else + return NULL; +} + // FIXME: handle name collisions... command_result PluginManager::InvokeCommand( std::string & command, std::vector & parameters, bool interactive) { - command_result cr = CR_NOT_IMPLEMENTED; - Core * c = &Core::getInstance(); - cmdlist_mutex->lock(); - map ::iterator iter = belongs.find(command); - if(iter != belongs.end()) - { - cr = iter->second->invoke(command, parameters, interactive); - } - cmdlist_mutex->unlock(); - return cr; + Plugin *plugin = getPluginByCommand(command); + return plugin ? plugin->invoke(command, parameters, interactive) : CR_NOT_IMPLEMENTED; +} + +bool PluginManager::CanInvokeHotkey(std::string &command, df::viewscreen *top) +{ + Plugin *plugin = getPluginByCommand(command); + return plugin ? plugin->can_invoke_hotkey(command, top) : false; } void PluginManager::OnUpdate( void ) @@ -370,6 +446,15 @@ void PluginManager::OnUpdate( void ) all_plugins[i]->on_update(); } } + +void PluginManager::OnStateChange( state_change_event event ) +{ + for(int i = 0; i < all_plugins.size(); i++) + { + all_plugins[i]->on_state_change(event); + } +} + // FIXME: doesn't check name collisions! void PluginManager::registerCommands( Plugin * p ) { diff --git a/library/Process-linux.cpp b/library/Process-linux.cpp index 5fc110cc2..ee64c2740 100644 --- a/library/Process-linux.cpp +++ b/library/Process-linux.cpp @@ -36,10 +36,10 @@ distribution. using namespace std; #include -#include "dfhack/Process.h" -#include "dfhack/VersionInfoFactory.h" -#include "dfhack/VersionInfo.h" -#include "dfhack/Error.h" +#include "MemAccess.h" +#include "VersionInfoFactory.h" +#include "VersionInfo.h" +#include "Error.h" #include using namespace DFHack; diff --git a/library/Process-windows.cpp b/library/Process-windows.cpp index 88b77891e..1fba8b28a 100644 --- a/library/Process-windows.cpp +++ b/library/Process-windows.cpp @@ -91,10 +91,10 @@ extern "C" __declspec(dllimport) NTSTATUS __stdcall RtlDestroyQueryDebugBuffer( #include using namespace std; -#include "dfhack/VersionInfo.h" -#include "dfhack/VersionInfoFactory.h" -#include "dfhack/Error.h" -#include "dfhack/Process.h" +#include "VersionInfo.h" +#include "VersionInfoFactory.h" +#include "Error.h" +#include "MemAccess.h" using namespace DFHack; namespace DFHack { diff --git a/library/TileTypes.cpp b/library/TileTypes.cpp index 295e269c6..31a82eb55 100644 --- a/library/TileTypes.cpp +++ b/library/TileTypes.cpp @@ -23,8 +23,8 @@ distribution. */ #include "Internal.h" -#include "dfhack/TileTypes.h" -#include "dfhack/Export.h" +#include "TileTypes.h" +#include "Export.h" namespace DFHack { diff --git a/library/VersionInfo.cpp b/library/VersionInfo.cpp index c7a4c6893..0f0764d60 100644 --- a/library/VersionInfo.cpp +++ b/library/VersionInfo.cpp @@ -31,9 +31,9 @@ distribution. #include using namespace std; -#include "dfhack/VersionInfo.h" -#include "dfhack/Error.h" -#include "dfhack/Process.h" +#include "VersionInfo.h" +#include "Error.h" +#include "MemAccess.h" using namespace DFHack; //Inital amount of space in levels vector (since we usually know the number, efficient!) @@ -598,7 +598,48 @@ void OffsetGroup::setInvalid(INVAL_TYPE invalidity) (*iter4).second->setInvalid(invalidity); } } - +std::vector OffsetGroup::getKeys() const +{ + std::vector ret; + OffsetKey K; + K.keytype=IS_ADDRESS; + for(uint32_Iter iter = OGd->addresses.begin(); iter != OGd->addresses.end(); iter++) + { + K.key=iter->first; + K.inval=iter->second.first; + ret.push_back(K); + } + K.keytype=IS_OFFSET; + for(int32_Iter iter = OGd->offsets.begin(); iter != OGd->offsets.end(); iter++) + { + K.key=iter->first; + K.inval=iter->second.first; + ret.push_back(K); + } + K.keytype=IS_HEX_VAL; + for(uint32_Iter iter = OGd->hexvals.begin(); iter != OGd->hexvals.end(); iter++) + { + K.key=iter->first; + K.inval=iter->second.first; + ret.push_back(K); + } + K.keytype=IS_STRING; + for(strings_Iter iter = OGd->strings.begin(); iter != OGd->strings.end(); iter++) + { + K.key=iter->first; + K.inval=iter->second.first; + ret.push_back(K); + } + K.keytype=IS_GROUP; + K.inval=IS_VALID; + for(groups_Iter iter = OGd->groups.begin(); iter != OGd->groups.end(); iter++) + { + K.key=iter->first; + + ret.push_back(K); + } + return ret; +} /* * Private data */ diff --git a/library/VersionInfoFactory.cpp b/library/VersionInfoFactory.cpp index b2ec00d96..bb8c7c533 100644 --- a/library/VersionInfoFactory.cpp +++ b/library/VersionInfoFactory.cpp @@ -31,9 +31,9 @@ distribution. #include using namespace std; -#include "dfhack/VersionInfoFactory.h" -#include "dfhack/VersionInfo.h" -#include "dfhack/Error.h" +#include "VersionInfoFactory.h" +#include "VersionInfo.h" +#include "Error.h" using namespace DFHack; #include diff --git a/library/Virtual.cpp b/library/Virtual.cpp index bafdc0cc5..6706f93be 100644 --- a/library/Virtual.cpp +++ b/library/Virtual.cpp @@ -4,9 +4,9 @@ #include #include -#include "dfhack/Process.h" -#include "dfhack/Core.h" -#include "dfhack/Virtual.h" +#include "MemAccess.h" +#include "Core.h" +#include "Virtual.h" using namespace DFHack; std::string t_virtual::getClassName() const diff --git a/library/include/dfhack/BitArray.h b/library/include/BitArray.h similarity index 98% rename from library/include/dfhack/BitArray.h rename to library/include/BitArray.h index 7e4b8a915..77e2a3ac1 100644 --- a/library/include/dfhack/BitArray.h +++ b/library/include/BitArray.h @@ -23,8 +23,8 @@ distribution. */ #pragma once -#include "dfhack/Pragma.h" -#include "dfhack/Export.h" +#include "Pragma.h" +#include "Export.h" #include #include #include diff --git a/library/include/dfhack/Console.h b/library/include/Console.h similarity index 98% rename from library/include/dfhack/Console.h rename to library/include/Console.h index e4e2c44f7..70385d829 100644 --- a/library/include/dfhack/Console.h +++ b/library/include/Console.h @@ -23,8 +23,8 @@ distribution. */ #pragma once -#include "dfhack/Pragma.h" -#include "dfhack/Export.h" +#include "Pragma.h" +#include "Export.h" #include #include #include diff --git a/library/include/dfhack/Core.h b/library/include/Core.h similarity index 86% rename from library/include/dfhack/Core.h rename to library/include/Core.h index 64eae5d3e..a368e360d 100644 --- a/library/include/dfhack/Core.h +++ b/library/include/Core.h @@ -24,15 +24,15 @@ distribution. #pragma once -#include "dfhack/Pragma.h" -#include "dfhack/Export.h" -#include "dfhack/FakeSDL.h" +#include "Pragma.h" +#include "Export.h" +#include "Hooks.h" #include #include #include #include -#include "dfhack/Console.h" -#include "dfhack/modules/Graphic.h" +#include "Console.h" +#include "modules/Graphic.h" struct WINDOW; @@ -43,6 +43,11 @@ namespace tthread class thread; } +namespace df +{ + struct viewscreen; +} + namespace DFHack { class Process; @@ -134,6 +139,13 @@ namespace DFHack /// returns a named pointer. void *GetData(std::string key); + bool ClearKeyBindings(std::string keyspec); + bool AddKeyBinding(std::string keyspec, std::string cmdline); + std::vector ListKeyBindings(std::string keyspec); + + bool isWorldLoaded() { return (last_world_data_ptr != NULL); } + df::viewscreen *getTopViewscreen() { return top_viewscreen; } + DFHack::Process * p; DFHack::VersionInfo * vinfo; DFHack::Console con; @@ -178,12 +190,25 @@ namespace DFHack } s_mods; std::vector allModules; DFHack::PluginManager * plug_mgr; + // hotkey-related stuff - int hotkey_states[16]; + struct KeyBinding { + int modifiers; + std::vector command; + std::string cmdline; + }; + + std::map > key_bindings; + std::map hotkey_states; std::string hotkey_cmd; bool hotkey_set; tthread::mutex * HotkeyMutex; tthread::condition_variable * HotkeyCond; + + bool SelectHotkey(int key, int modifiers); + + void *last_world_data_ptr; // for state change tracking + df::viewscreen *top_viewscreen; // Very important! bool started; diff --git a/library/include/DFHack.h b/library/include/DFHack.h index 938decbc8..ac5d78cf0 100644 --- a/library/include/DFHack.h +++ b/library/include/DFHack.h @@ -47,34 +47,34 @@ distribution. #include // DFHack core classes and types -#include "dfhack/Error.h" -#include "dfhack/VersionInfo.h" -#include "dfhack/Process.h" -#include "dfhack/Types.h" +#include "Error.h" +#include "VersionInfo.h" +#include "MemAccess.h" +#include "Types.h" // DFHack modules -#include "dfhack/modules/Buildings.h" -#include "dfhack/modules/Engravings.h" -#include "dfhack/modules/Materials.h" -#include "dfhack/modules/Constructions.h" -#include "dfhack/modules/Units.h" -#include "dfhack/modules/Translation.h" -#include "dfhack/modules/World.h" -#include "dfhack/modules/Items.h" -#include "dfhack/modules/Vegetation.h" -#include "dfhack/modules/Maps.h" -#include "dfhack/modules/Gui.h" +#include "modules/Buildings.h" +#include "modules/Engravings.h" +#include "modules/Materials.h" +#include "modules/Constructions.h" +#include "modules/Units.h" +#include "modules/Translation.h" +#include "modules/World.h" +#include "modules/Items.h" +#include "modules/Vegetation.h" +#include "modules/Maps.h" +#include "modules/Gui.h" /* * This is a header full of ugly, volatile things. * Only for use of official DFHack tools! */ #ifdef DFHACK_WANT_MISCUTILS - #include "dfhack/MiscUtils.h" + #include "MiscUtils.h" #endif // define this to get the static tiletype->properties mapping #ifdef DFHACK_WANT_TILETYPES - #include "dfhack/TileTypes.h" + #include "TileTypes.h" #endif #endif diff --git a/library/include/dfhack/DataDefs.h b/library/include/DataDefs.h similarity index 73% rename from library/include/dfhack/DataDefs.h rename to library/include/DataDefs.h index 4308ea3ed..75b2ab2e5 100644 --- a/library/include/dfhack/DataDefs.h +++ b/library/include/DataDefs.h @@ -28,8 +28,8 @@ distribution. #include #include -#include "dfhack/Core.h" -#include "dfhack/BitArray.h" +#include "Core.h" +#include "BitArray.h" // Stop some MS stupidity #ifdef interface @@ -62,8 +62,6 @@ namespace DFHack protected: virtual_identity(const char *dfhack_name, const char *original_name, virtual_identity *parent); - bool check_instance(virtual_ptr instance_ptr, bool allow_subclasses); - static void *get_vtable(virtual_ptr instance_ptr) { return *(void**)instance_ptr; } public: @@ -73,8 +71,10 @@ namespace DFHack virtual_identity *getParent() { return parent; } const std::vector &getChildren() { return children; } + public: static virtual_identity *get(virtual_ptr instance_ptr); - + + bool is_subclass(virtual_identity *subtype); bool is_instance(virtual_ptr instance_ptr) { if (!instance_ptr) return false; if (vtable_ptr) { @@ -82,16 +82,28 @@ namespace DFHack if (vtable == vtable_ptr) return true; if (!has_children) return false; } - return check_instance(instance_ptr, true); + return is_subclass(get(instance_ptr)); } bool is_direct_instance(virtual_ptr instance_ptr) { if (!instance_ptr) return false; return vtable_ptr ? (vtable_ptr == get_vtable(instance_ptr)) - : check_instance(instance_ptr, false); + : (this == get(instance_ptr)); } - static void Init(); + public: + bool can_instantiate() { return (vtable_ptr != NULL); } + virtual_ptr instantiate() { return can_instantiate() ? do_instantiate() : NULL; } + static virtual_ptr clone(virtual_ptr obj); + + protected: + virtual virtual_ptr do_instantiate() = 0; + virtual void do_copy(virtual_ptr tgt, virtual_ptr src) = 0; + public: + static void Init(Core *core); + + // Strictly for use in virtual class constructors + void adjust_vtable(virtual_ptr obj, virtual_identity *main); }; template @@ -112,14 +124,23 @@ namespace DFHack namespace df { + using DFHack::virtual_ptr; + using DFHack::virtual_identity; using DFHack::virtual_class; using DFHack::BitArray; template - class class_virtual_identity : public DFHack::virtual_identity { + class class_virtual_identity : public virtual_identity { public: class_virtual_identity(const char *dfhack_name, const char *original_name, virtual_identity *parent) : virtual_identity(dfhack_name, original_name, parent) {}; + + T *instantiate() { return static_cast(virtual_identity::instantiate()); } + T *clone(T* obj) { return static_cast(virtual_identity::clone(obj)); } + + protected: + virtual virtual_ptr do_instantiate() { return new T(); } + virtual void do_copy(virtual_ptr tgt, virtual_ptr src) { *static_cast(tgt) = *static_cast(src); } }; template @@ -148,15 +169,24 @@ namespace df namespace df { #define DF_KNOWN_GLOBALS \ + GLOBAL(cursor,cursor) \ + GLOBAL(selection_rect,selection_rect) \ GLOBAL(world,world) \ GLOBAL(ui,ui) \ GLOBAL(gview,interface) \ GLOBAL(init,init) \ - GLOBAL(d_init,d_init) - -#define GLOBAL(name,tname) \ - struct tname; \ + GLOBAL(d_init,d_init) \ + SIMPLE_GLOBAL(ui_look_cursor,int) \ + SIMPLE_GLOBAL(ui_workshop_job_cursor,int) \ + GLOBAL(ui_sidebar_menus,ui_sidebar_menus) \ + GLOBAL(ui_build_selector,ui_build_selector) \ + GLOBAL(ui_look_list,ui_look_list) + +#define SIMPLE_GLOBAL(name,tname) \ namespace global { extern DFHACK_EXPORT tname *name; } +#define GLOBAL(name,tname) \ + struct tname; SIMPLE_GLOBAL(name,tname) DF_KNOWN_GLOBALS #undef GLOBAL +#undef SIMPLE_GLOBAL } diff --git a/library/include/dfhack/Error.h b/library/include/Error.h similarity index 99% rename from library/include/dfhack/Error.h rename to library/include/Error.h index 946cc2d4c..1a25d1cbb 100644 --- a/library/include/dfhack/Error.h +++ b/library/include/Error.h @@ -27,8 +27,8 @@ distribution. #ifndef ERROR_H_INCLUDED #define ERROR_H_INCLUDED -#include "dfhack/Export.h" -#include "dfhack/Pragma.h" +#include "Export.h" +#include "Pragma.h" #include #include #include diff --git a/library/include/dfhack/Export.h b/library/include/Export.h similarity index 100% rename from library/include/dfhack/Export.h rename to library/include/Export.h diff --git a/library/include/dfhack/FakeSDL.h b/library/include/Hooks.h similarity index 66% rename from library/include/dfhack/FakeSDL.h rename to library/include/Hooks.h index 0f3ced545..f01d58c07 100644 --- a/library/include/dfhack/FakeSDL.h +++ b/library/include/Hooks.h @@ -28,39 +28,20 @@ distribution. * Some much needed SDL fakery. */ -#include "dfhack/Pragma.h" -#include "dfhack/Export.h" +#include "Pragma.h" +#include "Export.h" #include #include // function and variable pointer... we don't try to understand what SDL does here - typedef void * fPtr; typedef void * vPtr; struct WINDOW; namespace SDL { union Event; - //struct Thread; - //struct Mutex; - //struct Cond; - //struct Library; } -/* -// mutex stuff -DFhackCExport SDL::Mutex * SDL_CreateMutex(void); -DFhackCExport int SDL_mutexP(SDL::Mutex *); -DFhackCExport int SDL_mutexV(SDL::Mutex *); -DFhackCExport void SDL_DestroyMutex(SDL::Mutex *); -// thread stuff -DFhackCExport SDL::Thread *SDL_CreateThread(int (*fn)(void *), void *data); -DFhackCExport uint32_t SDL_ThreadID(); -// condition variables -DFhackCExport SDL::Cond *SDL_CreateCond(void); -DFhackCExport void SDL_DestroyCond(SDL::Cond *cond); -DFhackCExport int SDL_CondSignal(SDL::Cond *cond); -DFhackCExport int SDL_CondWait(SDL::Cond *cond, SDL::Mutex * mut); -*/ + // these functions are here because they call into DFHack::Core and therefore need to // be declared as friend functions/known DFhackCExport int SDL_NumJoysticks(void); @@ -69,4 +50,3 @@ DFhackCExport int SDL_PollEvent(SDL::Event* event); DFhackCExport int SDL_Init(uint32_t flags); DFhackCExport int wgetch(WINDOW * win); -// Other crud is in the OS-specific core files. diff --git a/library/private/Internal.h b/library/include/Internal.h similarity index 90% rename from library/private/Internal.h rename to library/include/Internal.h index 34cc40901..12b7852a1 100644 --- a/library/private/Internal.h +++ b/library/include/Internal.h @@ -24,9 +24,6 @@ distribution. #pragma once -#ifndef DFCOMMONINTERNAL_H_INCLUDED -#define DFCOMMONINTERNAL_H_INCLUDED - // this makes everything that includes this file export symbols when using DFHACK_EXPORT (see DFExport.h) #ifndef BUILD_DFHACK_LIB #define BUILD_DFHACK_LIB @@ -38,10 +35,7 @@ distribution. #endif // one file for telling the MSVC compiler where it can shove its pointless warnings -#include "dfhack/Pragma.h" +#include "Pragma.h" // C99 integer types #include - -#endif // DFCOMMONINTERNAL_H_INCLUDED - diff --git a/library/include/dfhack/Process.h b/library/include/MemAccess.h similarity index 99% rename from library/include/dfhack/Process.h rename to library/include/MemAccess.h index 1bd2b9710..7da132c8a 100644 --- a/library/include/dfhack/Process.h +++ b/library/include/MemAccess.h @@ -28,8 +28,8 @@ distribution. #ifndef PROCESS_H_INCLUDED #define PROCESS_H_INCLUDED -#include "dfhack/Pragma.h" -#include "dfhack/Export.h" +#include "Pragma.h" +#include "Export.h" #include #include #include diff --git a/library/include/MiscUtils.h b/library/include/MiscUtils.h new file mode 100644 index 000000000..833e74104 --- /dev/null +++ b/library/include/MiscUtils.h @@ -0,0 +1,104 @@ +/* +https://github.com/peterix/dfhack +Copyright (c) 2009-2011 Petr Mrázek (peterix@gmail.com) + +This software is provided 'as-is', without any express or implied +warranty. In no event will the authors be held liable for any +damages arising from the use of this software. + +Permission is granted to anyone to use this software for any +purpose, including commercial applications, and to alter it and +redistribute it freely, subject to the following restrictions: + +1. The origin of this software must not be misrepresented; you must +not claim that you wrote the original software. If you use this +software in a product, an acknowledgment in the product documentation +would be appreciated but is not required. + +2. Altered source versions must be plainly marked as such, and +must not be misrepresented as being the original software. + +3. This notice may not be removed or altered from any source +distribution. +*/ + +#pragma once +#include "Export.h" +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +template +void print_bits ( T val, DFHack::Console& out ) +{ + stringstream strs; + T n_bits = sizeof ( val ) * CHAR_BIT; + int cnt; + for ( unsigned i = 0; i < n_bits; ++i ) + { + cnt = i/10; + strs << cnt << " "; + } + strs << endl; + for ( unsigned i = 0; i < n_bits; ++i ) + { + cnt = i%10; + strs << cnt << " "; + } + strs << endl; + for ( unsigned i = 0; i < n_bits; ++i ) + { + strs << "--"; + } + strs << endl; + for ( unsigned i = 0; i < n_bits; ++i ) + { + strs<< !!( val & 1 ) << " "; + val >>= 1; + } + strs << endl; + out.print(strs.str().c_str()); +} + +//FIXME: Error 8 error C4519: default template arguments are only allowed on a class template +template +CT *binsearch_in_vector(std::vector &vec, FT CT::*field, AT value) +{ + int min = -1, max = (int)vec.size(); + CT **p = vec.data(); + FT key = (FT)value; + for (;;) + { + int mid = (min + max)>>1; + if (mid == min) + { + return NULL; + } + FT midv = p[mid]->*field; + if (midv == key) + { + return p[mid]; + } + else if (midv < key) + { + min = mid; + } + else + { + max = mid; + } + } +} + +/** + * Returns the amount of milliseconds elapsed since the UNIX epoch. + * Works on both windows and linux. + * source: http://stackoverflow.com/questions/1861294/how-to-calculate-execution-time-of-a-code-snippet-in-c + */ +DFHACK_EXPORT uint64_t GetTimeMs64(); diff --git a/library/include/dfhack/Module.h b/library/include/Module.h similarity index 98% rename from library/include/dfhack/Module.h rename to library/include/Module.h index c583ab17c..7433fce49 100644 --- a/library/include/dfhack/Module.h +++ b/library/include/Module.h @@ -27,7 +27,7 @@ distribution. #ifndef MODULE_H_INCLUDED #define MODULE_H_INCLUDED -#include "dfhack/Export.h" +#include "Export.h" namespace DFHack { /** diff --git a/library/private/ModuleFactory.h b/library/include/ModuleFactory.h similarity index 100% rename from library/private/ModuleFactory.h rename to library/include/ModuleFactory.h diff --git a/library/include/dfhack/PluginManager.h b/library/include/PluginManager.h similarity index 67% rename from library/include/dfhack/PluginManager.h rename to library/include/PluginManager.h index fef1aea50..726734baa 100644 --- a/library/include/dfhack/PluginManager.h +++ b/library/include/PluginManager.h @@ -24,55 +24,80 @@ distribution. #pragma once -#include "dfhack/Export.h" +#include "Export.h" +#include "Hooks.h" #include #include #include -#include "FakeSDL.h" struct DFLibrary; namespace tthread { class mutex; class condition_variable; } +namespace df +{ + struct viewscreen; +} namespace DFHack { class Core; class PluginManager; + struct virtual_identity; + enum command_result { CR_WOULD_BREAK = -2, CR_NOT_IMPLEMENTED = -1, CR_FAILURE = 0, - CR_OK = 1 + CR_OK = 1, + CR_WRONG_USAGE = 2 }; - struct PluginCommand + enum state_change_event { + SC_GAME_LOADED, + SC_GAME_UNLOADED, + SC_VIEWSCREEN_CHANGED + }; + struct DFHACK_EXPORT PluginCommand + { + typedef command_result (*command_function)(Core *, std::vector &); + typedef bool (*command_hotkey_guard)(Core *, df::viewscreen *); + /// create a command with a name, description, function pointer to its code /// and saying if it needs an interactive terminal /// Most commands shouldn't require an interactive terminal! PluginCommand(const char * _name, const char * _description, - command_result (*function_)(Core *, std::vector &), - bool interactive_ = false + command_function function_, + bool interactive_ = false, + const char * usage_ = "" ) + : name(_name), description(_description), + function(function_), interactive(interactive_), + guard(NULL), usage(usage_) { - name = _name; - description = _description; - function = function_; - interactive = interactive_; } - PluginCommand (const PluginCommand & rhs) + + PluginCommand(const char * _name, + const char * _description, + command_function function_, + command_hotkey_guard guard_, + const char * usage_ = "") + : name(_name), description(_description), + function(function_), interactive(false), + guard(guard_), usage(usage_) { - name = rhs.name; - description = rhs.description; - function = rhs.function; - interactive = rhs.interactive; } + + bool isHotkeyCommand() const { return guard != NULL; } + std::string name; std::string description; - command_result (*function)(Core *, std::vector &); + command_function function; bool interactive; + command_hotkey_guard guard; + std::string usage; }; class Plugin { @@ -87,11 +112,13 @@ namespace DFHack Plugin(DFHack::Core* core, const std::string& filepath, const std::string& filename, PluginManager * pm); ~Plugin(); command_result on_update(); + command_result on_state_change(state_change_event event); public: bool load(); bool unload(); bool reload(); command_result invoke( std::string & command, std::vector & parameters, bool interactive ); + bool can_invoke_hotkey( std::string & command, df::viewscreen *top ); plugin_state getState () const; const PluginCommand& operator[] (std::size_t index) const { @@ -117,6 +144,7 @@ namespace DFHack command_result (*plugin_status)(Core *, std::string &); command_result (*plugin_shutdown)(Core *); command_result (*plugin_onupdate)(Core *); + command_result (*plugin_onstatechange)(Core *, state_change_event); }; class DFHACK_EXPORT PluginManager { @@ -126,12 +154,15 @@ namespace DFHack PluginManager(Core * core); ~PluginManager(); void OnUpdate( void ); + void OnStateChange( state_change_event event ); void registerCommands( Plugin * p ); void unregisterCommands( Plugin * p ); // PUBLIC METHODS public: Plugin *getPluginByName (const std::string & name); + Plugin *getPluginByCommand (const std::string &command); command_result InvokeCommand( std::string & command, std::vector & parameters, bool interactive = true ); + bool CanInvokeHotkey(std::string &command, df::viewscreen *top); Plugin* operator[] (std::size_t index) { if(index >= all_plugins.size()) @@ -149,5 +180,10 @@ namespace DFHack std::vector all_plugins; std::string plugin_path; }; + + // Predefined hotkey guards + DFHACK_EXPORT bool default_hotkey(Core *, df::viewscreen *); + DFHACK_EXPORT bool dwarfmode_hotkey(Core *, df::viewscreen *); + DFHACK_EXPORT bool cursor_hotkey(Core *, df::viewscreen *); } diff --git a/library/include/dfhack/Pragma.h b/library/include/Pragma.h similarity index 100% rename from library/include/dfhack/Pragma.h rename to library/include/Pragma.h diff --git a/library/include/dfhack/SDL_fakes/events.h b/library/include/SDL_events.h similarity index 99% rename from library/include/dfhack/SDL_fakes/events.h rename to library/include/SDL_events.h index b8b8b1eb6..0457dbca1 100644 --- a/library/include/dfhack/SDL_fakes/events.h +++ b/library/include/SDL_events.h @@ -24,7 +24,7 @@ // Needed for processing its event types without polluting our namespaces with C garbage #pragma once -#include "keyboard.h" +#include "SDL_keyboard.h" namespace SDL { diff --git a/library/include/dfhack/SDL_fakes/keyboard.h b/library/include/SDL_keyboard.h similarity index 98% rename from library/include/dfhack/SDL_fakes/keyboard.h rename to library/include/SDL_keyboard.h index a49cf2517..f0d325f57 100644 --- a/library/include/dfhack/SDL_fakes/keyboard.h +++ b/library/include/SDL_keyboard.h @@ -24,7 +24,7 @@ // Needed for processing its event types without polluting our namespaces with C garbage #pragma once -#include "keysym.h" +#include "SDL_keysym.h" #include namespace SDL diff --git a/library/include/dfhack/SDL_fakes/keysym.h b/library/include/SDL_keysym.h similarity index 100% rename from library/include/dfhack/SDL_fakes/keysym.h rename to library/include/SDL_keysym.h diff --git a/library/include/dfhack/TileTypes.h b/library/include/TileTypes.h similarity index 99% rename from library/include/dfhack/TileTypes.h rename to library/include/TileTypes.h index 0fba4a696..8fe53a74e 100644 --- a/library/include/dfhack/TileTypes.h +++ b/library/include/TileTypes.h @@ -27,8 +27,8 @@ distribution. #ifndef TILETYPES_H_INCLUDED #define TILETYPES_H_INCLUDED -#include "dfhack/Pragma.h" -#include "dfhack/Export.h" +#include "Pragma.h" +#include "Export.h" namespace DFHack { diff --git a/library/include/dfhack/Types.h b/library/include/Types.h similarity index 97% rename from library/include/dfhack/Types.h rename to library/include/Types.h index 2ec35692f..9ebae4c73 100644 --- a/library/include/dfhack/Types.h +++ b/library/include/Types.h @@ -25,8 +25,8 @@ distribution. #pragma once -#include "dfhack/Pragma.h" -#include "dfhack/Export.h" +#include "Pragma.h" +#include "Export.h" namespace DFHack { diff --git a/library/include/dfhack/Vector.h b/library/include/Vector.h similarity index 95% rename from library/include/dfhack/Vector.h rename to library/include/Vector.h index ec5840a0f..4ba9dd152 100644 --- a/library/include/dfhack/Vector.h +++ b/library/include/Vector.h @@ -28,10 +28,10 @@ distribution. #ifndef DFVECTOR_H_INCLUDED #define DFVECTOR_H_INCLUDED -#include "dfhack/Pragma.h" -#include "dfhack/Export.h" -#include "dfhack/VersionInfo.h" -#include "dfhack/Process.h" +#include "Pragma.h" +#include "Export.h" +#include "VersionInfo.h" +#include "MemAccess.h" #include #include diff --git a/library/include/dfhack/VersionInfo.h b/library/include/VersionInfo.h similarity index 96% rename from library/include/dfhack/VersionInfo.h rename to library/include/VersionInfo.h index dc084eaae..47c9ba211 100644 --- a/library/include/dfhack/VersionInfo.h +++ b/library/include/VersionInfo.h @@ -28,9 +28,9 @@ distribution. #ifndef MEMINFO_H_INCLUDED #define MEMINFO_H_INCLUDED -#include "dfhack/Pragma.h" -#include "dfhack/Export.h" -#include "dfhack/Types.h" +#include "Pragma.h" +#include "Export.h" +#include "Types.h" #include #include #include @@ -52,7 +52,20 @@ namespace DFHack IS_INVALID, IS_VALID }; - + enum KEY_TYPE + { + IS_OFFSET, + IS_ADDRESS, + IS_HEX_VAL, + IS_STRING, + IS_GROUP + }; + struct OffsetKey + { + std::string key; + INVAL_TYPE inval; + KEY_TYPE keytype; + }; /* * Offset Group */ @@ -96,6 +109,8 @@ namespace DFHack std::string getFullName(); OffsetGroup * getParent(); void setInvalid(INVAL_TYPE arg1); + + std::vector getKeys() const; }; /* diff --git a/library/include/dfhack/VersionInfoFactory.h b/library/include/VersionInfoFactory.h similarity index 97% rename from library/include/dfhack/VersionInfoFactory.h rename to library/include/VersionInfoFactory.h index 0803a2c7f..acfa36bd3 100644 --- a/library/include/dfhack/VersionInfoFactory.h +++ b/library/include/VersionInfoFactory.h @@ -28,8 +28,8 @@ distribution. #ifndef MEMINFO_MANAGER_H_INCLUDED #define MEMINFO_MANAGER_H_INCLUDED -#include "dfhack/Pragma.h" -#include "dfhack/Export.h" +#include "Pragma.h" +#include "Export.h" class TiXmlElement; namespace DFHack diff --git a/library/include/dfhack/Virtual.h b/library/include/Virtual.h similarity index 100% rename from library/include/dfhack/Virtual.h rename to library/include/Virtual.h diff --git a/library/include/dfhack/df/.gitignore b/library/include/df/.gitignore similarity index 62% rename from library/include/dfhack/df/.gitignore rename to library/include/df/.gitignore index 11c5ffbb1..7cd9ae481 100644 --- a/library/include/dfhack/df/.gitignore +++ b/library/include/df/.gitignore @@ -1,2 +1,3 @@ *.h *.inc +*.xml diff --git a/library/include/dfhack/MiscUtils.h b/library/include/dfhack/MiscUtils.h deleted file mode 100644 index adae44377..000000000 --- a/library/include/dfhack/MiscUtils.h +++ /dev/null @@ -1,269 +0,0 @@ -/* -https://github.com/peterix/dfhack -Copyright (c) 2009-2011 Petr Mrázek (peterix@gmail.com) - -This software is provided 'as-is', without any express or implied -warranty. In no event will the authors be held liable for any -damages arising from the use of this software. - -Permission is granted to anyone to use this software for any -purpose, including commercial applications, and to alter it and -redistribute it freely, subject to the following restrictions: - -1. The origin of this software must not be misrepresented; you must -not claim that you wrote the original software. If you use this -software in a product, an acknowledgment in the product documentation -would be appreciated but is not required. - -2. Altered source versions must be plainly marked as such, and -must not be misrepresented as being the original software. - -3. This notice may not be removed or altered from any source -distribution. -*/ - -#pragma once - -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace std; -/* -#include -#include -#include - -void DumpObjStr0Vector (const char * name, DFHack::Process *p, uint32_t addr) -{ - cout << "----==== " << name << " ====----" << endl; - DFHack::DfVector vect(p,addr); - for(uint32_t i = 0; i < vect.size();i++) - { - uint32_t addr = vect[i]; - cout << p->readSTLString(addr) << endl; - } - cout << endl; -} -void DumpObjVtables (const char * name, DFHack::Process *p, uint32_t addr) -{ - cout << "----==== " << name << " ====----" << endl; - DFHack::DfVector vect(p,addr); - for(uint32_t i = 0; i < vect.size();i++) - { - uint32_t addr = vect[i]; - uint32_t vptr = p->readDWord(addr); - cout << p->readClassName(vptr) << endl; - } - cout << endl; -} -void DumpDWordVector (const char * name, DFHack::Process *p, uint32_t addr) -{ - cout << "----==== " << name << " ====----" << endl; - DFHack::DfVector vect(p,addr); - for(uint32_t i = 0; i < vect.size();i++) - { - uint32_t number = vect[i]; - cout << number << endl; - } - cout << endl; -} -*/ -/* -address = absolute address of dump start -length = length in lines. 1 line = 16 bytes -*/ -/* -void hexdump (DFHack::Context *DF, uint32_t address, uint32_t length) -{ - char *buf = new char[length]; - DF->ReadRaw(address, length, (uint8_t *) buf); - uint32_t i = 0; - while (i < length) - { - // leading offset - if(i%16 == 0) - cout << "0x" << hex << setw(8) << address + i << "| "; - // bytes - for(int k = 0; k < 4; k++) - { - cout << hex << setw(2) << int(static_cast(buf[i])) << " "; - i++; - if(i == length) break; - } - if(i%16 == 0 || i>= length) - { - cout << endl; - } - else if(i%4 == 0) - { - cout << " "; - } - } - delete buf; -} - -void interleave_hex (DFHack::Context* DF, vector < uint32_t > & addresses, uint32_t length) -{ - vector bufs; - - for(uint32_t counter = 0; counter < addresses.size(); counter ++) - { - char * buf = new char[length * 16]; - DF->ReadRaw(addresses[counter], length * 16, (uint8_t *) buf); - bufs.push_back(buf); - } - cout << setfill('0'); - - // output a header - cout << "line offset "; - for (uint32_t obj = 0; obj < addresses.size(); obj++) - { - cout << "0x" << hex << setw(9) << addresses[obj] << " "; - } - cout << endl; - - for(uint32_t offs = 0 ; offs < length * 16; offs += 4) - { - if((!(offs % 16)) && offs != 0) - { - cout << endl; - } - cout << setfill(' '); - cout << dec << setw(4) << offs/4 << " "; - cout << setfill('0'); - cout << "0x" << hex << setw(4) << offs << " "; - for (uint32_t object = 0; object < bufs.size(); object++) - { - // bytes - for(int k = 0; k < 4; k++) - { - uint8_t data = bufs[object][offs + k]; - cout << hex << setw(2) << int(static_cast(data)) << " "; - } - cout << " "; - } - cout << endl; - } - for(uint32_t counter = 0; counter < addresses.size(); counter ++) - { - delete bufs[counter]; - } -} -*/ -template -void print_bits ( T val, DFHack::Console& out ) -{ - stringstream strs; - T n_bits = sizeof ( val ) * CHAR_BIT; - int cnt; - for ( unsigned i = 0; i < n_bits; ++i ) - { - cnt = i/10; - strs << cnt << " "; - } - strs << endl; - for ( unsigned i = 0; i < n_bits; ++i ) - { - cnt = i%10; - strs << cnt << " "; - } - strs << endl; - for ( unsigned i = 0; i < n_bits; ++i ) - { - strs << "--"; - } - strs << endl; - for ( unsigned i = 0; i < n_bits; ++i ) - { - strs<< !!( val & 1 ) << " "; - val >>= 1; - } - strs << endl; - out.print(strs.str().c_str()); -} - -/* -// this is probably completely bogus -std::string PrintSplatterType (int16_t mat1, int32_t mat2, vector &creature_types) -{ - std::string ret; - switch (mat1) - { - case 0: - return "Rock"; - case 1: - return "Amber"; - case 2: - return "Coral"; - case 3: - return "Green Glass"; - case 4: - return "Clear Glass"; - case 5: - return "Crystal Glass"; - case 6: - return "Water"; - case 7: - return "Coal"; - case 8: - return "Potash"; - case 9: - return "Ash"; - case 10: - return "Pearlash"; - case 11: - return "Lye"; - case 12: - return "Mud"; - case 13: - return "Vomit"; - case 14: - return "Salt"; - case 15: - return "Filth"; - case 16: - return "Frozen? Filth"; - case 18: - return "Grime"; - case 0xF2: - return "Very Specific Blood (references a named creature)"; - case 0x2A: - case 0x2B: - if(mat2 != -1) - { - ret += creature_types[mat2].id; - ret += " "; - } - ret += "Blood"; - return ret; - default: - return "Unknown"; - } -} -*/ - -//FIXME: Error 8 error C4519: default template arguments are only allowed on a class template -template -CT *binsearch_in_vector(std::vector &vec, FT CT::*field, AT value) { - int min = -1, max = (int)vec.size(); - CT **p = vec.data(); - FT key = (FT)value; - for (;;) { - int mid = (min + max)>>1; - if (mid == min) - return NULL; - FT midv = p[mid]->*field; - if (midv == key) - return p[mid]; - else if (midv < key) - min = mid; - else - max = mid; - } -} diff --git a/library/include/dfhack/extra/termutil.h b/library/include/dfhack/extra/termutil.h deleted file mode 100644 index 702e6ba5b..000000000 --- a/library/include/dfhack/extra/termutil.h +++ /dev/null @@ -1,54 +0,0 @@ -/* -https://github.com/peterix/dfhack -Copyright (c) 2009-2011 Petr Mrázek (peterix@gmail.com) - -This software is provided 'as-is', without any express or implied -warranty. In no event will the authors be held liable for any -damages arising from the use of this software. - -Permission is granted to anyone to use this software for any -purpose, including commercial applications, and to alter it and -redistribute it freely, subject to the following restrictions: - -1. The origin of this software must not be misrepresented; you must -not claim that you wrote the original software. If you use this -software in a product, an acknowledgment in the product documentation -would be appreciated but is not required. - -2. Altered source versions must be plainly marked as such, and -must not be misrepresented as being the original software. - -3. This notice may not be removed or altered from any source -distribution. -*/ -#pragma once - -#ifndef TERMUTIL_H -#define TERMUTIL_H - -#ifdef LINUX_BUILD -// FIXME: is this ever true? -bool TemporaryTerminal () -{ - return false; -} -#else -#include -#include -#include -bool TemporaryTerminal () -{ - CONSOLE_SCREEN_BUFFER_INFO csbi; - HANDLE hStdOutput; - hStdOutput = GetStdHandle(STD_OUTPUT_HANDLE); - if (!GetConsoleScreenBufferInfo(hStdOutput, &csbi)) - { - printf("GetConsoleScreenBufferInfo failed: %d\n", GetLastError()); - return false; - } - return ((!csbi.dwCursorPosition.X) && (!csbi.dwCursorPosition.Y)); -}; - -#endif // LINUX_BUILD - -#endif \ No newline at end of file diff --git a/library/include/dfhack/modules/Buildings.h b/library/include/modules/Buildings.h similarity index 97% rename from library/include/dfhack/modules/Buildings.h rename to library/include/modules/Buildings.h index 112a4d927..330c151dc 100644 --- a/library/include/dfhack/modules/Buildings.h +++ b/library/include/modules/Buildings.h @@ -29,8 +29,8 @@ distribution. * \defgroup grp_buildings Building module parts - also includes zones and stockpiles * @ingroup grp_modules */ -#include "dfhack/Export.h" -#include "dfhack/Module.h" +#include "Export.h" +#include "Module.h" #ifdef __cplusplus namespace DFHack diff --git a/library/include/dfhack/modules/Constructions.h b/library/include/modules/Constructions.h similarity index 98% rename from library/include/dfhack/modules/Constructions.h rename to library/include/modules/Constructions.h index 046d8a074..c7cd693e8 100644 --- a/library/include/dfhack/modules/Constructions.h +++ b/library/include/modules/Constructions.h @@ -28,8 +28,8 @@ distribution. /* * DF constructions */ -#include "dfhack/Export.h" -#include "dfhack/Module.h" +#include "Export.h" +#include "Module.h" /** * \defgroup grp_constructions Construction module parts diff --git a/library/include/dfhack/modules/Engravings.h b/library/include/modules/Engravings.h similarity index 98% rename from library/include/dfhack/modules/Engravings.h rename to library/include/modules/Engravings.h index 0dfbb3f43..7e145959b 100644 --- a/library/include/dfhack/modules/Engravings.h +++ b/library/include/modules/Engravings.h @@ -28,8 +28,8 @@ distribution. /* * DF engravings */ -#include "dfhack/Export.h" -#include "dfhack/Module.h" +#include "Export.h" +#include "Module.h" /** * \defgroup grp_engraving Engraving module parts diff --git a/library/include/dfhack/modules/Graphic.h b/library/include/modules/Graphic.h similarity index 95% rename from library/include/dfhack/modules/Graphic.h rename to library/include/modules/Graphic.h index f9d6a88ec..6c003b4bc 100644 --- a/library/include/dfhack/modules/Graphic.h +++ b/library/include/modules/Graphic.h @@ -1,6 +1,6 @@ /* https://github.com/peterix/dfhack -Copyright (c) 2009-2011 Petr Mrázek (peterix@gmail.com) +Copyright (c) 2009-2011 Petr Mr�zek (peterix@gmail.com) This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any @@ -31,8 +31,8 @@ distribution. #define CL_MOD_GRAPHIC #include -#include "dfhack/Export.h" -#include "dfhack/Module.h" +#include "Export.h" +#include "Module.h" namespace DFHack { diff --git a/library/include/dfhack/modules/Gui.h b/library/include/modules/Gui.h similarity index 97% rename from library/include/dfhack/modules/Gui.h rename to library/include/modules/Gui.h index 96f4beb9e..3d3fe81c7 100644 --- a/library/include/dfhack/modules/Gui.h +++ b/library/include/modules/Gui.h @@ -26,10 +26,10 @@ distribution. #ifndef CL_MOD_GUI #define CL_MOD_GUI -#include "dfhack/Export.h" -#include "dfhack/Module.h" -#include "dfhack/Virtual.h" -#include "dfhack/BitArray.h" +#include "Export.h" +#include "Module.h" +#include "Virtual.h" +#include "BitArray.h" #include /** diff --git a/library/include/dfhack/modules/Items.h b/library/include/modules/Items.h similarity index 99% rename from library/include/dfhack/modules/Items.h rename to library/include/modules/Items.h index f6efcc8ab..4deba6cdb 100644 --- a/library/include/dfhack/modules/Items.h +++ b/library/include/modules/Items.h @@ -26,12 +26,12 @@ distribution. /* * Items! */ -#include "dfhack/Export.h" -#include "dfhack/Module.h" -#include "dfhack/Types.h" -#include "dfhack/Virtual.h" -#include "dfhack/modules/Materials.h" -#include "dfhack/Process.h" +#include "Export.h" +#include "Module.h" +#include "Types.h" +#include "Virtual.h" +#include "modules/Materials.h" +#include "MemAccess.h" /** * \defgroup grp_items Items module and its types * @ingroup grp_modules diff --git a/library/include/dfhack/extra/MapExtras.h b/library/include/modules/MapCache.h similarity index 99% rename from library/include/dfhack/extra/MapExtras.h rename to library/include/modules/MapCache.h index 9f03d1917..ad6b91e96 100644 --- a/library/include/dfhack/extra/MapExtras.h +++ b/library/include/modules/MapCache.h @@ -26,8 +26,8 @@ distribution. #ifndef MAPEXTRAS_H #define MAPEXTRAS_H -#include "dfhack/modules/Maps.h" -#include "dfhack/TileTypes.h" +#include "modules/Maps.h" +#include "TileTypes.h" #include #include namespace MapExtras diff --git a/library/include/dfhack/modules/Maps.h b/library/include/modules/Maps.h similarity index 99% rename from library/include/dfhack/modules/Maps.h rename to library/include/modules/Maps.h index cc0c17ac3..7e01a03d1 100644 --- a/library/include/dfhack/modules/Maps.h +++ b/library/include/modules/Maps.h @@ -30,12 +30,12 @@ distribution. #ifndef CL_MOD_MAPS #define CL_MOD_MAPS -#include "dfhack/Export.h" -#include "dfhack/Module.h" -#include "dfhack/modules/Vegetation.h" +#include "Export.h" +#include "Module.h" +#include "modules/Vegetation.h" #include -#include "dfhack/Virtual.h" -#include "dfhack/BitArray.h" +#include "Virtual.h" +#include "BitArray.h" #include "Materials.h" /** diff --git a/library/include/dfhack/modules/Materials.h b/library/include/modules/Materials.h similarity index 99% rename from library/include/dfhack/modules/Materials.h rename to library/include/modules/Materials.h index 48280e7f0..8c3ce6846 100644 --- a/library/include/dfhack/modules/Materials.h +++ b/library/include/modules/Materials.h @@ -29,10 +29,10 @@ distribution. * \defgroup grp_materials Materials module - used for reading raws mostly * @ingroup grp_modules */ -#include "dfhack/Export.h" -#include "dfhack/Module.h" -#include "dfhack/Types.h" -#include "dfhack/BitArray.h" +#include "Export.h" +#include "Module.h" +#include "Types.h" +#include "BitArray.h" #include #include diff --git a/library/include/dfhack/modules/Notes.h b/library/include/modules/Notes.h similarity index 95% rename from library/include/dfhack/modules/Notes.h rename to library/include/modules/Notes.h index 8339c1cdc..14bb9db84 100644 --- a/library/include/dfhack/modules/Notes.h +++ b/library/include/modules/Notes.h @@ -5,8 +5,8 @@ * \defgroup grp_notes In game notes (and routes) * @ingroup grp_notes */ -#include "dfhack/Export.h" -#include "dfhack/Module.h" +#include "Export.h" +#include "Module.h" #include #include diff --git a/library/include/dfhack/modules/Translation.h b/library/include/modules/Translation.h similarity index 96% rename from library/include/dfhack/modules/Translation.h rename to library/include/modules/Translation.h index e21102d50..843d1afb9 100644 --- a/library/include/dfhack/modules/Translation.h +++ b/library/include/modules/Translation.h @@ -30,9 +30,9 @@ distribution. * @ingroup grp_modules */ -#include "dfhack/Export.h" -#include "dfhack/Module.h" -#include "dfhack/Types.h" +#include "Export.h" +#include "Module.h" +#include "Types.h" namespace DFHack { diff --git a/library/include/dfhack/modules/Units.h b/library/include/modules/Units.h similarity index 99% rename from library/include/dfhack/modules/Units.h rename to library/include/modules/Units.h index 886b2eeb9..d373b0a16 100644 --- a/library/include/dfhack/modules/Units.h +++ b/library/include/modules/Units.h @@ -28,9 +28,9 @@ distribution. /* * Creatures */ -#include "dfhack/Export.h" -#include "dfhack/Module.h" -#include "dfhack/modules/Items.h" +#include "Export.h" +#include "Module.h" +#include "modules/Items.h" /** * \defgroup grp_units Unit module parts * @ingroup grp_modules diff --git a/library/include/dfhack/modules/Vegetation.h b/library/include/modules/Vegetation.h similarity index 96% rename from library/include/dfhack/modules/Vegetation.h rename to library/include/modules/Vegetation.h index 91e6cac8c..c52d728d4 100644 --- a/library/include/dfhack/modules/Vegetation.h +++ b/library/include/modules/Vegetation.h @@ -30,9 +30,9 @@ distribution. * @ingroup grp_modules */ -#include "dfhack/Export.h" -#include "dfhack/Module.h" -#include "dfhack/Types.h" +#include "Export.h" +#include "Module.h" +#include "Types.h" namespace DFHack { /** diff --git a/library/include/dfhack/modules/Vermin.h b/library/include/modules/Vermin.h similarity index 96% rename from library/include/dfhack/modules/Vermin.h rename to library/include/modules/Vermin.h index 5fa345df0..01ef3d4ae 100644 --- a/library/include/dfhack/modules/Vermin.h +++ b/library/include/modules/Vermin.h @@ -5,8 +5,8 @@ * \defgroup grp_vermin Wild vermin (ants, bees, etc) * @ingroup grp_vermin */ -#include "dfhack/Export.h" -#include "dfhack/Module.h" +#include "Export.h" +#include "Module.h" #ifdef __cplusplus namespace DFHack diff --git a/library/include/dfhack/modules/World.h b/library/include/modules/World.h similarity index 98% rename from library/include/dfhack/modules/World.h rename to library/include/modules/World.h index 7203d775f..01ad231d0 100644 --- a/library/include/dfhack/modules/World.h +++ b/library/include/modules/World.h @@ -31,8 +31,8 @@ distribution. * @ingroup grp_modules */ -#include "dfhack/Export.h" -#include "dfhack/Module.h" +#include "Export.h" +#include "Module.h" #include namespace DFHack diff --git a/library/include/dfhack/modules/kitchen.h b/library/include/modules/kitchen.h similarity index 93% rename from library/include/dfhack/modules/kitchen.h rename to library/include/modules/kitchen.h index bb4e313c6..b169dfb3f 100644 --- a/library/include/dfhack/modules/kitchen.h +++ b/library/include/modules/kitchen.h @@ -26,13 +26,13 @@ distribution. /* * kitchen settings */ -#include "dfhack/Export.h" -#include "dfhack/Module.h" -#include "dfhack/Types.h" -#include "dfhack/VersionInfo.h" -#include "dfhack/modules/Materials.h" -#include "dfhack/modules/Items.h" -#include +#include "Export.h" +#include "Module.h" +#include "Types.h" +#include "VersionInfo.h" +#include "modules/Materials.h" +#include "modules/Items.h" +#include "Core.h" /** * \defgroup grp_kitchen Kitchen settings * @ingroup grp_modules diff --git a/library/private/wdirent.h b/library/include/wdirent.h similarity index 100% rename from library/private/wdirent.h rename to library/include/wdirent.h diff --git a/library/modules/Buildings.cpp b/library/modules/Buildings.cpp index 4083ac5d1..fbef81315 100644 --- a/library/modules/Buildings.cpp +++ b/library/modules/Buildings.cpp @@ -30,14 +30,14 @@ distribution. #include using namespace std; -#include "dfhack/VersionInfo.h" -#include "dfhack/Process.h" -#include "dfhack/Vector.h" -#include "dfhack/Types.h" -#include "dfhack/Error.h" -#include "dfhack/modules/Buildings.h" +#include "VersionInfo.h" +#include "MemAccess.h" +#include "Vector.h" +#include "Types.h" +#include "Error.h" +#include "modules/Buildings.h" #include "ModuleFactory.h" -#include "dfhack/Core.h" +#include "Core.h" using namespace DFHack; //raw diff --git a/library/modules/Constructions.cpp b/library/modules/Constructions.cpp index 079f37398..8081560ae 100644 --- a/library/modules/Constructions.cpp +++ b/library/modules/Constructions.cpp @@ -31,13 +31,13 @@ distribution. using namespace std; -#include "dfhack/VersionInfo.h" -#include "dfhack/Process.h" -#include "dfhack/Vector.h" -#include "dfhack/Types.h" -#include "dfhack/modules/Constructions.h" +#include "VersionInfo.h" +#include "MemAccess.h" +#include "Vector.h" +#include "Types.h" +#include "modules/Constructions.h" #include "ModuleFactory.h" -#include "dfhack/Core.h" +#include "Core.h" using namespace DFHack; diff --git a/library/modules/Engravings.cpp b/library/modules/Engravings.cpp index 8e436b849..7f3b286bf 100644 --- a/library/modules/Engravings.cpp +++ b/library/modules/Engravings.cpp @@ -30,13 +30,13 @@ distribution. #include using namespace std; -#include "dfhack/VersionInfo.h" -#include "dfhack/Process.h" -#include "dfhack/Vector.h" -#include "dfhack/Types.h" -#include "dfhack/modules/Engravings.h" +#include "VersionInfo.h" +//#include "MemAccess.h" +#include "Vector.h" +#include "Types.h" +#include "modules/Engravings.h" #include "ModuleFactory.h" -#include "dfhack/Core.h" +#include "Core.h" using namespace DFHack; diff --git a/library/modules/Graphic.cpp b/library/modules/Graphic.cpp index 25ec34f7d..b482b8e4f 100644 --- a/library/modules/Graphic.cpp +++ b/library/modules/Graphic.cpp @@ -1,6 +1,6 @@ /* https://github.com/peterix/dfhack -Copyright (c) 2009-2011 Petr Mrázek (peterix@gmail.com) +Copyright (c) 2009-2011 Petr Mr�zek (peterix@gmail.com) This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any @@ -33,13 +33,13 @@ distribution. #include using namespace std; -#include "dfhack/modules/Graphic.h" -#include "dfhack/Error.h" -#include "dfhack/VersionInfo.h" -#include "dfhack/Process.h" -#include "dfhack/Vector.h" +#include "modules/Graphic.h" +#include "Error.h" +#include "VersionInfo.h" +#include "MemAccess.h" +#include "Vector.h" #include "ModuleFactory.h" -#include +#include "Core.h" using namespace DFHack; diff --git a/library/modules/Gui.cpp b/library/modules/Gui.cpp index 46f0ad2ea..cd6f46f25 100644 --- a/library/modules/Gui.cpp +++ b/library/modules/Gui.cpp @@ -30,15 +30,51 @@ distribution. #include using namespace std; -#include "dfhack/modules/Gui.h" -#include "dfhack/Process.h" -#include "dfhack/VersionInfo.h" -#include "dfhack/Types.h" -#include "dfhack/Error.h" +#include "modules/Gui.h" +#include "MemAccess.h" +#include "VersionInfo.h" +#include "Types.h" +#include "Error.h" #include "ModuleFactory.h" -#include "dfhack/Core.h" +#include "Core.h" +#include "PluginManager.h" using namespace DFHack; +#include "DataDefs.h" +#include "df/cursor.h" +#include "df/viewscreen_dwarfmodest.h" + +// Predefined common guard functions + +bool DFHack::default_hotkey(Core *, df::viewscreen *top) +{ + // Default hotkey guard function + for (;top ;top = top->parent) + if (strict_virtual_cast(top)) + return true; + return false; +} + +bool DFHack::dwarfmode_hotkey(Core *, df::viewscreen *top) +{ + // Require the main dwarf mode screen + return !!strict_virtual_cast(top); +} + +bool DFHack::cursor_hotkey(Core *c, df::viewscreen *top) +{ + if (!dwarfmode_hotkey(c, top)) + return false; + + // Also require the cursor. + if (!df::global::cursor || df::global::cursor->x == -30000) + return false; + + return true; +} + +// + Module* DFHack::createGui() { return new Gui(); diff --git a/library/modules/Items.cpp b/library/modules/Items.cpp index 468c00c4d..0b5cef01b 100644 --- a/library/modules/Items.cpp +++ b/library/modules/Items.cpp @@ -33,16 +33,16 @@ distribution. #include using namespace std; -#include "dfhack/Types.h" -#include "dfhack/VersionInfo.h" -#include "dfhack/Process.h" -#include "dfhack/Vector.h" -#include "dfhack/modules/Materials.h" -#include "dfhack/modules/Items.h" -#include "dfhack/modules/Units.h" +#include "Types.h" +#include "VersionInfo.h" +#include "MemAccess.h" +#include "Vector.h" +#include "modules/Materials.h" +#include "modules/Items.h" +#include "modules/Units.h" #include "ModuleFactory.h" -#include -#include +#include "Core.h" +#include "Virtual.h" using namespace DFHack; diff --git a/library/modules/Maps.cpp b/library/modules/Maps.cpp index 5b68b384f..6cb34d6af 100644 --- a/library/modules/Maps.cpp +++ b/library/modules/Maps.cpp @@ -33,13 +33,13 @@ distribution. #include using namespace std; -#include "dfhack/modules/Maps.h" -#include "dfhack/Error.h" -#include "dfhack/VersionInfo.h" -#include "dfhack/Process.h" -#include "dfhack/Vector.h" +#include "modules/Maps.h" +#include "Error.h" +#include "VersionInfo.h" +#include "MemAccess.h" +#include "Vector.h" #include "ModuleFactory.h" -#include +#include "Core.h" #define MAPS_GUARD if(!d->Started) throw DFHack::Error::ModuleNotInitialized(); diff --git a/library/modules/Materials.cpp b/library/modules/Materials.cpp index 0c4b6f46b..c77a62bd7 100644 --- a/library/modules/Materials.cpp +++ b/library/modules/Materials.cpp @@ -31,14 +31,14 @@ distribution. #include using namespace std; -#include "dfhack/Types.h" -#include "dfhack/modules/Materials.h" -#include "dfhack/VersionInfo.h" -#include "dfhack/Process.h" -#include "dfhack/Vector.h" -#include +#include "Types.h" +#include "modules/Materials.h" +#include "VersionInfo.h" +#include "MemAccess.h" +#include "Vector.h" +#include "Error.h" #include "ModuleFactory.h" -#include +#include "Core.h" using namespace DFHack; diff --git a/library/modules/Notes.cpp b/library/modules/Notes.cpp index 293077a5d..bcfe6aa68 100644 --- a/library/modules/Notes.cpp +++ b/library/modules/Notes.cpp @@ -29,13 +29,13 @@ distribution. #include using namespace std; -#include "dfhack/VersionInfo.h" -#include "dfhack/Types.h" -#include "dfhack/Error.h" -#include "dfhack/Process.h" +#include "VersionInfo.h" +#include "Types.h" +#include "Error.h" +#include "MemAccess.h" #include "ModuleFactory.h" -#include "dfhack/Core.h" -#include "dfhack/modules/Notes.h" +#include "Core.h" +#include "modules/Notes.h" using namespace DFHack; Module* DFHack::createNotes() diff --git a/library/modules/Translation.cpp b/library/modules/Translation.cpp index 57fcd8757..9c2af7901 100644 --- a/library/modules/Translation.cpp +++ b/library/modules/Translation.cpp @@ -30,13 +30,13 @@ distribution. #include using namespace std; -#include "dfhack/modules/Translation.h" -#include "dfhack/VersionInfo.h" -#include "dfhack/Process.h" -#include "dfhack/Vector.h" -#include "dfhack/Types.h" +#include "modules/Translation.h" +#include "VersionInfo.h" +#include "MemAccess.h" +#include "Vector.h" +#include "Types.h" #include "ModuleFactory.h" -#include +#include "Core.h" using namespace DFHack; Module* DFHack::createTranslation() diff --git a/library/modules/Units.cpp b/library/modules/Units.cpp index 9a6a09065..368a198ec 100644 --- a/library/modules/Units.cpp +++ b/library/modules/Units.cpp @@ -34,18 +34,18 @@ distribution. using namespace std; -#include "dfhack/VersionInfo.h" -#include "dfhack/Process.h" -#include "dfhack/Vector.h" -#include "dfhack/Error.h" -#include "dfhack/Types.h" +#include "VersionInfo.h" +#include "MemAccess.h" +#include "Vector.h" +#include "Error.h" +#include "Types.h" // we connect to those -#include "dfhack/modules/Materials.h" -#include "dfhack/modules/Units.h" -#include "dfhack/modules/Translation.h" +#include "modules/Materials.h" +#include "modules/Units.h" +#include "modules/Translation.h" #include "ModuleFactory.h" -#include +#include "Core.h" using namespace DFHack; diff --git a/library/modules/Vegetation.cpp b/library/modules/Vegetation.cpp index b581928a9..c30e26157 100644 --- a/library/modules/Vegetation.cpp +++ b/library/modules/Vegetation.cpp @@ -30,14 +30,14 @@ distribution. #include using namespace std; -#include "dfhack/VersionInfo.h" -#include "dfhack/Process.h" -#include "dfhack/Vector.h" -#include "dfhack/Types.h" -#include "dfhack/modules/Vegetation.h" -#include "dfhack/modules/Translation.h" +#include "VersionInfo.h" +#include "MemAccess.h" +#include "Vector.h" +#include "Types.h" +#include "modules/Vegetation.h" +#include "modules/Translation.h" #include "ModuleFactory.h" -#include +#include "Core.h" using namespace DFHack; Module* DFHack::createVegetation() diff --git a/library/modules/Vermin.cpp b/library/modules/Vermin.cpp index 67fd623e4..f685c4eed 100644 --- a/library/modules/Vermin.cpp +++ b/library/modules/Vermin.cpp @@ -29,13 +29,13 @@ distribution. #include using namespace std; -#include "dfhack/VersionInfo.h" -#include "dfhack/Types.h" -#include "dfhack/Error.h" -#include "dfhack/Process.h" -#include "dfhack/modules/Vermin.h" +#include "VersionInfo.h" +#include "Types.h" +#include "Error.h" +#include "MemAccess.h" +#include "modules/Vermin.h" #include "ModuleFactory.h" -#include "dfhack/Core.h" +#include "Core.h" using namespace DFHack; struct Vermin::Private @@ -106,7 +106,6 @@ SpawnPoints* Vermin::getSpawnPoints() cerr << "Couldn't get spawn points: Vermin module not inited" << endl; return NULL; } - return new SpawnPoints(this); } @@ -120,15 +119,11 @@ SpawnPoints::SpawnPoints(Vermin* v_) cerr << "Couldn't get spawn points: Vermin module not inited" << endl; return; } - - //p_sp = new DfVector (v->d->spawn_points_vector); - //p_sp = new vector (v->d->spawn_points_vector); p_sp = (vector *) (v->d->spawn_points_vector); } SpawnPoints::~SpawnPoints() { - // Do NOT delete p_sp; it's a pointer to memory the game owns. } size_t SpawnPoints::size() diff --git a/library/modules/World.cpp b/library/modules/World.cpp index bb6c3bfaf..0402c7f18 100644 --- a/library/modules/World.cpp +++ b/library/modules/World.cpp @@ -30,13 +30,13 @@ distribution. #include using namespace std; -#include "dfhack/modules/World.h" -#include "dfhack/Process.h" -#include "dfhack/VersionInfo.h" -#include "dfhack/Types.h" -#include "dfhack/Error.h" +#include "modules/World.h" +#include "MemAccess.h" +#include "VersionInfo.h" +#include "Types.h" +#include "Error.h" #include "ModuleFactory.h" -#include +#include "Core.h" using namespace DFHack; diff --git a/library/modules/kitchen.cpp b/library/modules/kitchen.cpp index c98684e08..78869ae26 100644 --- a/library/modules/kitchen.cpp +++ b/library/modules/kitchen.cpp @@ -9,17 +9,17 @@ #include using namespace std; -#include "dfhack/Types.h" -#include "dfhack/VersionInfo.h" -#include "dfhack/Process.h" -#include "dfhack/Vector.h" -#include "dfhack/modules/Materials.h" -#include "dfhack/modules/Items.h" -#include "dfhack/modules/Units.h" -#include "dfhack/modules/kitchen.h" +#include "Types.h" +#include "VersionInfo.h" +#include "MemAccess.h" +#include "Vector.h" +#include "modules/Materials.h" +#include "modules/Items.h" +#include "modules/Units.h" +#include "modules/kitchen.h" #include "ModuleFactory.h" -#include -#include +#include "Core.h" +#include "Virtual.h" namespace DFHack { diff --git a/library/xml b/library/xml new file mode 160000 index 000000000..7a730830c --- /dev/null +++ b/library/xml @@ -0,0 +1 @@ +Subproject commit 7a730830c515fea701ff73b33cb604f48a4531fc diff --git a/library/xml/codegen.pl b/library/xml/codegen.pl deleted file mode 100755 index 05684732b..000000000 --- a/library/xml/codegen.pl +++ /dev/null @@ -1,944 +0,0 @@ -#!/usr/bin/perl - -use strict; -use warnings; - -use XML::LibXML; - -my $input_dir = $ARGV[0] || '.'; -my $output_dir = $ARGV[1] || 'codegen'; -my $main_namespace = $ARGV[2] || 'df'; -my $export_prefix = 'DFHACK_EXPORT '; - -my %types; -my %type_files; - -# Misc XML analysis - -our $typename; -our $filename; - -sub parse_address($;$) { - my ($str,$in_bits) = @_; - return undef unless defined $str; - - # Parse the format used by offset attributes in xml - $str =~ /^0x([0-9a-f]+)(?:\.([0-7]))?$/ - or die "Invalid address syntax: $str\n"; - my ($full, $bv) = ($1, $2); - die "Bits not allowed: $str\n" unless $in_bits; - return $in_bits ? (hex($full)*8 + ($bv||0)) : hex($full); -} - -sub check_bad_attrs($;$$) { - my ($tag, $allow_size, $allow_align) = @_; - - die "Cannot use size, alignment or offset for ".$tag->nodeName."\n" - if ((!$allow_size && defined $tag->getAttribute('size')) || - defined $tag->getAttribute('offset') || - (!$allow_align && defined $tag->getAttribute('alignment'))); -} - -sub check_name($) { - my ($name) = @_; - $name =~ /^[_a-zA-Z][_a-zA-Z0-9]*$/ - or die "Invalid identifier: $name\n"; - return $name; -} - -sub is_attr_true($$) { - my ($tag, $name) = @_; - return ($tag->getAttribute($name)||'') eq 'true'; -} - -sub type_header_def($) { - my ($name) = @_; - return uc($main_namespace).'_'.uc($name).'_H'; -} - -sub translate_lookup($) { - my ($str) = @_; - return undef unless $str && $str =~ /^\$global((\.[_a-zA-Z0-9]+)+)$/; - my @fields = split /\./, substr($1,1); - my $expr = "df::global::".shift(@fields); - for my $fn (@fields) { - $expr = "_toref($expr).$fn"; - } - return $expr; -} - -# Text generation with indentation - -our @lines; -our $indentation = 0; - -sub with_emit(&;$) { - # Executes the code block, and returns emitted lines - my ($blk, $start_indent) = @_; - local @lines; - local $indentation = ($start_indent||0); - $blk->(); - return @lines; -} - -sub emit(@) { - # Emit an indented line to be returned from with_emit - my $line = join('',map { defined($_) ? $_ : '' } @_); - $line = (' 'x$indentation).$line unless length($line) == 0; - push @lines, $line; -} - -sub indent(&) { - # Indent lines emitted from the block by one step - my ($blk) = @_; - local $indentation = $indentation+2; - $blk->(); -} - -sub outdent(&) { - # Unindent lines emitted from the block by one step - my ($blk) = @_; - local $indentation = ($indentation >= 2 ? $indentation-2 : 0); - $blk->(); -} - -sub emit_block(&;$$) { - # Emit a full {...} block with indentation - my ($blk, $prefix, $suffix) = @_; - $prefix ||= ''; - $suffix ||= ''; - emit $prefix,'{'; - &indent($blk); - emit '}',$suffix; -} - -# Static file output - -my @static_lines; -my %static_includes; - -sub with_emit_static(&) { - my ($blk) = @_; - $static_includes{$typename}++; - push @static_lines, &with_emit($blk,2); -} - -# Anonymous variable names - -our $anon_id = 0; -our $anon_prefix; - -sub ensure_name($) { - # If the name is empty, assign an auto-generated one - my ($name) = @_; - unless ($name) { - $name = $anon_prefix.(($anon_id == 0) ? '' : '_'.$anon_id); - $anon_id++; - } - return check_name($name); -} - -sub with_anon(&;$) { - # Establish a new anonymous namespace - my ($blk,$stem) = @_; - local $anon_id = $stem ? 0 : 1; - local $anon_prefix = ($stem||'anon'); - $blk->(); -} - -# Primitive types - -my @primitive_type_list = - qw(int8_t uint8_t int16_t uint16_t - int32_t uint32_t int64_t uint64_t - s-float - bool ptr-string stl-string flag-bit - pointer); - -my %primitive_aliases = ( - 'stl-string' => 'std::string', - 'ptr-string' => 'char*', - 'flag-bit' => 'void', - 'pointer' => 'void*', - 's-float' => 'float', -); - -my %primitive_types; -$primitive_types{$_}++ for @primitive_type_list; - -sub primitive_type_name($) { - my ($tag_name) = @_; - $primitive_types{$tag_name} - or die "Not primitive: $tag_name\n"; - return $primitive_aliases{$tag_name} || $tag_name; -} - -# Type references - -our %weak_refs; -our %strong_refs; - -sub register_ref($;$) { - # Register a reference to another type. - # Strong ones require the type to be included. - my ($ref, $is_strong) = @_; - - if ($ref) { - my $type = $types{$ref} - or die "Unknown type $ref referenced.\n"; - - if ($is_strong) { - $strong_refs{$ref}++; - } else { - $weak_refs{$ref}++; - } - } -} - -# Determines if referenced other types should be included or forward-declared -our $is_strong_ref = 1; - -sub with_struct_block(&$;$%) { - my ($blk, $tag, $name, %flags) = @_; - - my $kwd = (is_attr_true($tag,'is-union') ? "union" : "struct"); - my $exp = $flags{-export} ? $export_prefix : ''; - my $prefix = $kwd.' '.$exp.($name ? $name.' ' : ''); - - emit_block { - local $_; - local $is_strong_ref = 1; # reset the state - if ($flags{-no_anon}) { - $blk->(); - } else { - &with_anon($blk); - } - } $prefix, ";"; -} - -sub decode_type_name_ref($;%) { - # Interpret the type-name field of a tag - my ($tag,%flags) = @_; - my $force_type = $flags{-force_type}; - my $force_strong = $flags{-force_strong}; - my $tname = $tag->getAttribute($flags{-attr_name} || 'type-name') - or return undef; - - if ($primitive_types{$tname}) { - die "Cannot use type $tname as type-name of ".$tag->nodeName."\n" - if ($force_type && $force_type ne 'primitive'); - return primitive_type_name($tname); - } else { - register_ref $tname, ($force_strong||$is_strong_ref); - die "Cannot use type $tname as type-name of ".$tag->nodeName."\n" - if ($force_type && $force_type ne $types{$tname}->nodeName); - return $main_namespace.'::'.$tname; - } -} - -# CONDITIONALS - -sub is_conditional($) { - my ($tag) = @_; - return $tag->nodeName =~ /^(cond-if|cond-elseif)$/; -} - -sub translate_if_cond($) { - my ($tag) = @_; - - my @rules; - if (my $defvar = $tag->getAttribute('defined')) { - push @rules, "defined($defvar)"; - } - if (my $cmpvar = $tag->getAttribute('var')) { - if (my $cmpval = $tag->getAttribute('lt')) { - push @rules, "($cmpvar < $cmpval)"; - } - if (my $cmpval = $tag->getAttribute('le')) { - push @rules, "($cmpvar <= $cmpval)"; - } - if (my $cmpval = $tag->getAttribute('eq')) { - push @rules, "($cmpvar == $cmpval)"; - } - if (my $cmpval = $tag->getAttribute('ge')) { - push @rules, "($cmpvar >= $cmpval)"; - } - if (my $cmpval = $tag->getAttribute('gt')) { - push @rules, "($cmpvar > $cmpval)"; - } - if (my $cmpval = $tag->getAttribute('ne')) { - push @rules, "($cmpvar != $cmpval)"; - } - } - return '('.(join(' && ',@rules) || '1').')'; -} - -our $in_cond = 0; - -sub render_cond_if($$$;@) { - my ($tag, $in_elseif, $render_cb, @tail) = @_; - - local $in_cond = 1; - - { - local $indentation = 0; - my $op = ($in_elseif && $in_elseif >= 2) ? '#elif' : '#if'; - emit $op, ' ', translate_if_cond($tag); - } - - for my $child ($tag->findnodes('child::*')) { - &render_cond($child, $render_cb, @tail); - } - - unless ($in_elseif) { - local $indentation = 0; - emit "#endif"; - } -} - -sub render_cond($$;@) { - my ($tag, $render_cb, @tail) = @_; - - my $tag_name = $tag->nodeName; - if ($tag_name eq 'cond-if') { - render_cond_if($tag, 0, $render_cb, @tail); - } elsif ($tag_name eq 'cond-elseif') { - my $idx = 1; - for my $child ($tag->findnodes('child::*')) { - ($child->nodeName eq 'cond-if') - or die "Only cond-if tags may be inside a cond-switch: ".$child->nodeName."\n"; - render_cond_if($child, $idx++, $render_cb, @tail); - } - { - local $indentation = 0; - emit "#endif"; - } - } else { - local $_ = $tag; - $render_cb->($tag, @tail); - } -} - -# ENUM - -sub render_enum_core($$) { - my ($name,$tag) = @_; - - my $base = 0; - - emit_block { - my @items = $tag->findnodes('child::*'); - my $idx = 0; - - for my $item (@items) { - render_cond $item, sub { - my $tag = $_->nodeName; - return if $tag eq 'enum-attr'; - ($tag eq 'enum-item') - or die "Invalid enum member: ".$item->nodeName."\n"; - - my $name = ensure_name $_->getAttribute('name'); - my $value = $_->getAttribute('value'); - - $base = ($idx == 0 && !$in_cond) ? $value : undef if defined $value; - $idx++; - - emit $name, (defined($value) ? ' = '.$value : ''), ','; - }; - } - - emit "_last_item_of_$name"; - } "enum $name ", ";"; - - return $base; -} - -sub render_enum_tables($$$) { - my ($name,$tag,$base) = @_; - - # Enumerate enum attributes - - my %aidx = ('key' => 0); - my @anames = ('key'); - my @avals = ('NULL'); - my @atypes = ('const char*'); - my @atnames = (undef); - - for my $attr ($tag->findnodes('child::enum-attr')) { - my $name = $attr->getAttribute('name') or die "Unnamed enum-attr.\n"; - my $type = $attr->getAttribute('type-name'); - my $def = $attr->getAttribute('default-value'); - - die "Duplicate attribute $name.\n" if exists $aidx{$name}; - - check_name $name; - $aidx{$name} = scalar @anames; - push @anames, $name; - push @atnames, $type; - - if ($type) { - push @atypes, $type; - push @avals, (defined $def ? $def : "($type)0"); - } else { - push @atypes, 'const char*'; - push @avals, (defined $def ? "\"$def\"" : 'NULL'); - } - } - - # Emit accessor function prototypes - - emit "const $name _first_item_of_$name = ($name)$base;"; - - emit_block { - emit "return (value >= _first_item_of_$name && value < _last_item_of_$name);"; - } "inline bool is_valid($name value) "; - - for (my $i = 0; $i < @anames; $i++) { - emit "${export_prefix}$atypes[$i] get_$anames[$i]($name value);"; - } - - # Emit implementation - - with_emit_static { - emit_block { - emit_block { - # Emit the entry type - emit_block { - for (my $i = 0; $i < @anames; $i++) { - emit "$atypes[$i] $anames[$i];"; - } - } "struct _info_entry ", ";"; - - # Emit the info table - emit_block { - for my $item ($tag->findnodes('child::*')) { - render_cond $item, sub { - my $tag = $_->nodeName; - return if $tag eq 'enum-attr'; - - # Assemble item-specific attr values - my @evals = @avals; - my $name = $_->getAttribute('name'); - $evals[0] = "\"$name\"" if $name; - - for my $attr ($_->findnodes('child::item-attr')) { - my $name = $attr->getAttribute('name') or die "Unnamed item-attr.\n"; - my $value = $attr->getAttribute('value') or die "No-value item-attr.\n"; - my $idx = $aidx{$name} or die "Unknown item-attr: $name\n"; - - if ($atnames[$idx]) { - $evals[$idx] = $value; - } else { - $evals[$idx] = "\"$value\""; - } - } - - emit "{ ",join(', ',@evals)," },"; - }; - } - - emit "{ ",join(', ',@avals)," }"; - } "static const _info_entry _info[] = ", ";"; - - for (my $i = 0; $i < @anames; $i++) { - emit_block { - emit "return is_valid(value) ? _info[value - $base].$anames[$i] : $avals[$i];"; - } "$atypes[$i] get_$anames[$i]($name value) "; - } - } "namespace $name "; - } "namespace enums "; - }; -} - -sub render_enum_type { - my ($tag) = @_; - - emit_block { - emit_block { - my $base = render_enum_core($typename,$tag); - - if (defined $base) { - render_enum_tables($typename,$tag,$base); - } else { - print STDERR "Warning: complex enum: $typename\n"; - } - } "namespace $typename "; - } "namespace enums "; - - emit "using enums::",$typename,"::",$typename,";"; -} - -# BITFIELD - -sub get_primitive_base($;$) { - my ($tag, $default) = @_; - - my $base = $tag->getAttribute('base-type') || $default || 'uint32_t'; - $primitive_types{$base} or die "Must be primitive: $base\n"; - - return $base; -} - -sub render_bitfield_core { - my ($name, $tag) = @_; - - emit_block { - emit get_primitive_base($tag), ' whole;'; - - emit_block { - for my $item ($tag->findnodes('child::*')) { - render_cond $item, sub { - my ($item) = @_; - ($item->nodeName eq 'flag-bit') - or die "Invalid bitfield member:".$item->nodeName."\n"; - - check_bad_attrs($item); - my $name = ensure_name $item->getAttribute('name'); - my $size = $item->getAttribute('count') || 1; - emit "unsigned ", $name, " : ", $size, ";"; - }; - } - } "struct ", " bits;"; - } "union $name ", ";"; -} - -sub render_bitfield_type { - my ($tag) = @_; - render_bitfield_core($typename,$tag); -} - -# STRUCT - -my %struct_field_handlers; - -sub get_struct_fields($) { - # Retrieve subtags that are actual struct fields - my ($struct_tag) = @_; - local $_; - return grep { - my $tag = $_->nodeName; - die "Unknown field tag: $tag\n" - unless exists $struct_field_handlers{$tag}; - $struct_field_handlers{$tag}; - } $struct_tag->findnodes('child::*'); -} - -sub get_struct_field_type($) { - # Dispatch on the tag name, and retrieve the type prefix & suffix - my ($tag) = @_; - my $handler = $struct_field_handlers{$tag->nodeName} - or die "Unexpected tag: ".$tag->nodeName; - return $handler->($tag); -} - -sub do_render_struct_field($) { - my ($tag) = @_; - my $tag_name = $tag->nodeName; - my $field_name = $tag->getAttribute('name'); - - # Special case: anonymous compounds. - if ($tag_name eq 'compound' && !defined $field_name && - !defined $tag->getAttribute('type-name')) - { - check_bad_attrs($tag); - with_struct_block { - render_struct_field($_) for get_struct_fields($tag); - } $tag, undef, -no_anon => 1; - return; - } - - # Otherwise, create the name if necessary, and render - my $name = ensure_name $field_name; - with_anon { - my ($prefix, $postfix) = get_struct_field_type($tag); - emit $prefix, ' ', $name, $postfix, ';'; - } "T_$name"; -} - -sub render_struct_field($) { - my ($tag) = @_; - render_cond $tag, \&do_render_struct_field; -} - -sub emit_typedef($$) { - # Convert a prefix/postfix pair into a single name - my ($pre, $post) = @_; - my $name = ensure_name undef; - emit 'typedef ', $pre, ' ', $name, $post, ';'; - return $name; -} - -sub get_container_item_type($$;$) { - # Interpret the type-name and nested fields for a generic container type - my ($tag,$strong_ref,$allow_void) = @_; - - check_bad_attrs($tag); - - my $prefix; - my $postfix = ''; - local $is_strong_ref = $strong_ref; - - unless ($prefix = decode_type_name_ref($tag)) { - my @fields = get_struct_fields($tag); - - if (scalar(@fields) == 1 && !is_conditional($fields[0])) { - ($prefix, $postfix) = get_struct_field_type($fields[0]); - } elsif (scalar(@fields) == 0) { - $allow_void or die "Empty container: ".$tag->nodeName."\n"; - $prefix = $allow_void; - } else { - $prefix = ensure_name undef; - with_struct_block { - render_struct_field($_) for @fields; - } $tag, $prefix; - } - } - - return ($prefix,$postfix) if wantarray; - return emit_typedef($prefix, $postfix) if $postfix; - return $prefix; -} - -sub get_primitive_field_type { - # Primitive type handler - my ($tag,$fname) = @_; - check_bad_attrs($tag); - my $name = $tag->nodeName; - return (primitive_type_name($name), ""); -} - -sub get_static_string_type { - # Static string handler - my ($tag, $fname) = @_; - check_bad_attrs($tag, 1); - my $count = $tag->getAttribute('size') || 0; - return ('char', "[$count]"); -} - -sub get_padding_type { - # Padding handler. Supports limited alignment. - my ($tag, $fname) = @_; - - check_bad_attrs($tag, 1, 1); - my $count = $tag->getAttribute('size') || 0; - my $align = $tag->getAttribute('alignment') || 1; - - if ($align == 1) { - return ('char', "[$count]"); - } elsif ($align == 2) { - ($count % 2 == 0) or die "Size not aligned in padding: $count at $align\n"; - return ('short', "[".($count/2)."]"); - } elsif ($align == 4) { - ($count % 4 == 0) or die "Size not aligned in padding: $count at $align\n"; - return ('int', "[".($count/4)."]"); - } else { - die "Bad padding alignment $align in $typename in $filename\n"; - } -} - -sub get_static_array_type { - # static-array handler - my ($tag, $fname) = @_; - my ($pre, $post) = get_container_item_type($tag, 1); - my $count = $tag->getAttribute('count') - or die "Count is mandatory for static-array in $typename in $filename\n"; - return ($pre, "[$count]".$post); -} - -sub get_pointer_type($) { - # pointer handler - my ($tag) = @_; - my $item = get_container_item_type($tag, 0, 'void'); - return ($item.'*', ''); -} - -sub get_compound_type($) { - # compound (nested struct) handler - my ($tag) = @_; - check_bad_attrs($tag); - - my $tname = decode_type_name_ref($tag); - unless ($tname) { - $tname = ensure_name undef; - with_struct_block { - render_struct_field($_) for get_struct_fields($tag); - } $tag, $tname; - } - return ($tname,''); -} - -sub get_bitfield_type($) { - # nested bitfield handler - my ($tag) = @_; - check_bad_attrs($tag); - - my $tname = decode_type_name_ref($tag, -force_type => 'bitfield-type'); - unless ($tname) { - $tname = ensure_name undef; - with_anon { - render_bitfield_core($tname, $tag); - }; - } - return ($tname,''); -} - -sub get_enum_type($) { - # nested enum handler - my ($tag) = @_; - check_bad_attrs($tag); - - my $tname = decode_type_name_ref($tag, -force_type => 'enum-type', -force_strong => 1); - my $base = get_primitive_base($tag, 'int32_t'); - unless ($tname) { - $tname = ensure_name undef; - with_anon { - render_enum_core($tname,$tag); - }; - } - return ("enum_field<$tname,$base>", ''); -} - -sub get_stl_vector_type($) { - # STL vector - my ($tag) = @_; - my $item = get_container_item_type($tag,1,'void*'); - $item = 'char' if $item eq 'bool'; - return ("std::vector<$item>", ''); -} - -sub get_stl_bit_vector_type($) { - # STL bit vector - my ($tag) = @_; - check_bad_attrs($tag); - return ("std::vector", ''); -} - -sub get_df_flagarray_type($) { - # DF flag array - my ($tag) = @_; - check_bad_attrs($tag); - my $type = decode_type_name_ref($tag, -attr_name => 'index-enum', -force_type => 'enum-type', -force_strong => 1) || 'int'; - return ("BitArray<$type>", ''); -} - -# Struct dispatch table and core - -%struct_field_handlers = ( - 'comment' => undef, # skip - 'code-helper' => undef, # skip - 'cond-if' => sub { die "cond handling error"; }, - 'cond-elseif' => sub { die "cond handling error"; }, - 'static-string' => \&get_static_string_type, - 'padding' => \&get_padding_type, - 'static-array' => \&get_static_array_type, - 'pointer' => \&get_pointer_type, - 'compound' => \&get_compound_type, - 'bitfield' => \&get_bitfield_type, - 'enum' => \&get_enum_type, - 'stl-vector' => \&get_stl_vector_type, - 'stl-bit-vector' => \&get_stl_bit_vector_type, - 'df-flagarray' => \&get_df_flagarray_type, -); -$struct_field_handlers{$_} ||= \&get_primitive_field_type for @primitive_type_list; - -sub emit_find_instance { - my ($tag) = @_; - - my $instance_vector = translate_lookup $tag->getAttribute('instance-vector'); - if ($instance_vector) { - emit "static std::vector<$typename*> &get_vector();"; - emit "static $typename *find(int id);"; - - with_emit_static { - emit_block { - emit "return ", $instance_vector, ";"; - } "std::vector<$typename*>& ${typename}::get_vector() "; - - emit_block { - emit "std::vector<$typename*> &vec_ = get_vector();"; - - if (my $id = $tag->getAttribute('key-field')) { - emit "return binsearch_in_vector(vec_, &${typename}::$id, id_);"; - } else { - emit "return (id_ >= 0 && id_ < vec_.size()) ? vec_[id_] : NULL;"; - } - } "$typename *${typename}::find(int id_) "; - } - } -} - -sub render_struct_type { - my ($tag) = @_; - - my $tag_name = $tag->nodeName; - my $is_class = ($tag_name eq 'class-type'); - my $has_methods = $is_class || is_attr_true($tag, 'has-methods'); - my $inherits = $tag->getAttribute('inherits-from'); - my $original_name = $tag->getAttribute('original-name'); - my $ispec = ''; - - if ($inherits) { - register_ref $inherits, 1; - $ispec = ' : '.$inherits; - } elsif ($is_class) { - $ispec = ' : virtual_class'; - } - - with_struct_block { - render_struct_field($_) for get_struct_fields($tag); - - emit_find_instance($tag); - - if ($has_methods) { - if ($is_class) { - emit "static class_virtual_identity<$typename> _identity;"; - with_emit_static { - emit "class_virtual_identity<$typename> ${typename}::_identity(", - "\"$typename\",", - ($original_name ? "\"$original_name\"" : 'NULL'), ',', - ($inherits ? "&${inherits}::_identity" : 'NULL'), - ");"; - } - } - - outdent { - emit "protected:"; - }; - - if ($is_class) { - emit "virtual ~",$typename,"() {}"; - } else { - emit "~",$typename,"() {}"; - } - } - } $tag, "$typename$ispec", -export => 1; -} - -# MAIN BODY - -# Collect all type definitions from XML files - -sub add_type_to_hash($) { - my ($type) = @_; - - my $name = $type->getAttribute('type-name') - or die "Type without a name in $filename\n"; - - die "Duplicate definition of $name in $filename\n" if $types{$name}; - - local $typename = $name; - check_bad_attrs $type; - $types{$name} = $type; - $type_files{$name} = $filename; -} - -for my $fn (glob "$input_dir/*.xml") { - local $filename = $fn; - my $parser = XML::LibXML->new(); - my $doc = $parser->parse_file($filename); - - add_type_to_hash $_ foreach $doc->findnodes('/data-definition/enum-type'); - add_type_to_hash $_ foreach $doc->findnodes('/data-definition/bitfield-type'); - add_type_to_hash $_ foreach $doc->findnodes('/data-definition/struct-type'); - add_type_to_hash $_ foreach $doc->findnodes('/data-definition/class-type'); -} - -# Generate text representations - -my %type_handlers = ( - 'enum-type' => \&render_enum_type, - 'bitfield-type' => \&render_bitfield_type, - 'class-type' => \&render_struct_type, - 'struct-type' => \&render_struct_type, -); - -my %type_data; - -for my $name (sort { $a cmp $b } keys %types) { - local $typename = $name; - local $filename = $type_files{$typename}; - local %weak_refs; - local %strong_refs; - - eval { - my $type = $types{$typename}; - - # Emit the actual type definition - my @code = with_emit { - with_anon { - $type_handlers{$type->nodeName}->($type); - }; - } 2; - - delete $weak_refs{$name}; - delete $strong_refs{$name}; - - # Add wrapping - my @all = with_emit { - my $def = type_header_def($typename); - emit "#ifndef $def"; - emit "#define $def"; - - for my $strong (sort { $a cmp $b } keys %strong_refs) { - my $sdef = type_header_def($strong); - emit "#ifndef $sdef"; - emit "#include \"$strong.h\""; - emit "#endif"; - } - - emit_block { - for my $weak (sort { $a cmp $b } keys %weak_refs) { - next if $strong_refs{$weak}; - my $ttype = $types{$weak}; - my $tstr = 'struct'; - $tstr = 'enum' if $ttype->nodeName eq 'enum-type'; - $tstr = 'union' if $ttype->nodeName eq 'bitfield-type'; - $tstr = 'union' if ($ttype->nodeName eq 'struct-type' && is_attr_true($ttype,'is-union')); - emit $tstr, ' ', $weak, ';'; - } - - push @lines, @code; - } "namespace $main_namespace "; - - emit "#endif"; - }; - - $type_data{$typename} = \@all; - }; - if ($@) { - print 'Error: '.$@."Type $typename in $filename ignored\n"; - } -} - -# Write output files - -mkdir $output_dir; - -{ - # Delete the old files - for my $name (glob "$output_dir/*.h") { - unlink $name; - } - - # Write out the headers - local $, = "\n"; - local $\ = "\n"; - - for my $name (keys %type_data) { - open FH, ">$output_dir/$name.h"; - print FH "/* THIS FILE WAS GENERATED. DO NOT EDIT. */"; - print FH @{$type_data{$name}}; - close FH; - } - - # Write out the static file - open FH, ">$output_dir/static.inc"; - print FH "/* THIS FILE WAS GENERATED. DO NOT EDIT. */"; - for my $name (sort { $a cmp $b } keys %static_includes) { - print FH "#include \"$name.h\""; - } - print FH "namespace $main_namespace {"; - print FH @static_lines; - print FH '}'; - close FH; -} diff --git a/library/xml/df.building-raws.xml b/library/xml/df.building-raws.xml deleted file mode 100644 index bf522ae31..000000000 --- a/library/xml/df.building-raws.xml +++ /dev/null @@ -1,58 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/library/xml/df.buildings.xml b/library/xml/df.buildings.xml deleted file mode 100644 index 74df09eb7..000000000 --- a/library/xml/df.buildings.xml +++ /dev/null @@ -1,403 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - 0 - not room; 1 in stockpile; 2 wall; 3 inner; 4 distance boundary. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- stockpile -- - - - - - - - - - - - - - - - - - - - - - - - - - -- zone -- - - - - - - -- actual -- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- workshops -- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- misc -- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/library/xml/df.creature-raws.xml b/library/xml/df.creature-raws.xml deleted file mode 100644 index 61aa7ed7c..000000000 --- a/library/xml/df.creature-raws.xml +++ /dev/null @@ -1,592 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // 0 around of, 1 around by - - - - - - - - - - - - - - - - - - - $global.world.raws.creatures.all[$$].caste[$] - - - - - - - - - // temporary - - - - fingers[2], nose, ear, head, eyes, mouth, hair, knuckles, lips, cheek, nails, f eet, arms, hands, tongue, leg - - - - - - - - - - - - - - - - - - - - - - - - - - // NOT 32-bit! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - $global.world.raws.creatures.all[$] - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/library/xml/df.d_init.xml b/library/xml/df.d_init.xml deleted file mode 100644 index 345fa812a..000000000 --- a/library/xml/df.d_init.xml +++ /dev/null @@ -1,129 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 85266c0 - - - - diff --git a/library/xml/df.history.xml b/library/xml/df.history.xml deleted file mode 100644 index 700329ea8..000000000 --- a/library/xml/df.history.xml +++ /dev/null @@ -1,126 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - (describe-obj $.name) - (awhen (find-creature $.race) - (fmt "~:(~A ~A~)" $it.caste[$.caste].caste_id $it.creature_id)) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - dtor 8532fa0 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/library/xml/df.init.xml b/library/xml/df.init.xml deleted file mode 100644 index 6680b788a..000000000 --- a/library/xml/df.init.xml +++ /dev/null @@ -1,138 +0,0 @@ - - -- init.h - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- texture_handler.h - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/library/xml/df.item-raws.xml b/library/xml/df.item-raws.xml deleted file mode 100644 index 81d9c7671..000000000 --- a/library/xml/df.item-raws.xml +++ /dev/null @@ -1,303 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/library/xml/df.items.xml b/library/xml/df.items.xml deleted file mode 100644 index c1b989b23..000000000 --- a/library/xml/df.items.xml +++ /dev/null @@ -1,577 +0,0 @@ - - -- MISC TYPES - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- CORE ITEM - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- ACTUAL ITEM - - - -- Important - - - - - - -- Misc - - - - - - - - - - - - - - - - - - - - - - - - - - -- Wielders - - - - - - - - - - - - (if (> $.stack_size 1) (fmt "stack: ~A" $.stack_size)) - (if (> $.wear 0) (fmt "wear: ~A" $.wear)) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- CRAFTED ITEM - - - - - - - $.quality - (describe-obj (material-by-id $.matType $.matIndex)) - - - - - - - - - - -- CONSTRUCTED ITEM - - - - - - - - -- BODY COMPONENT - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- CRITTER - - - - - - - - - -- LIQUID/POWER - - - - - - - - - - - - - - - - - - -- MISC - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- CONSTRUCTED - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/library/xml/df.job-enums.xml b/library/xml/df.job-enums.xml deleted file mode 100644 index 6a84ec8f5..000000000 --- a/library/xml/df.job-enums.xml +++ /dev/null @@ -1,1785 +0,0 @@ - - ----- PROFESSION ----- - - - - - - - -- 0 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- 10 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- 20 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- 30 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- 40 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- 50 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- 60 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- 70 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- 80 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- 90 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- 100 - - - - - - - - - - - - - - - - - - - - - - ----- LABOR ----- - - - - - -- 0 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- 10 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- 20 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- 30 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- 40 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- 50 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- 60 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- 70 - - - - - - - - - - - - - ----- SKILL ----- - - - - - -- 0 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- 10 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- 20 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- 30 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- 40 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- 50 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- 60 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- 70 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- 80 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- 90 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- 100 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- 110 - - - - - - - - - - - - - - - - - - - - - - ----- JOB TYPE ----- - - - -- Declare attributes: - - - - -- 0 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- 10 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- 20 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- 30 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- 40 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- 50 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- 60 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- 70 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- 80 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- 90 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- 100 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- 110 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- 120 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- 130 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- 140 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- 150 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- 160 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- 170 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- 180 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- 190 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- 200 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- 210 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- 220 - - - - - - - - - - - - - - - - - - - - diff --git a/library/xml/df.jobs.xml b/library/xml/df.jobs.xml deleted file mode 100644 index 8c6c6d849..000000000 --- a/library/xml/df.jobs.xml +++ /dev/null @@ -1,263 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- Guess: - - - - - - - - - - - -- Either empty, or same as above: - - - - - - - - -- These are equal to the ones above: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/library/xml/df.language.xml b/library/xml/df.language.xml deleted file mode 100644 index 961057f2d..000000000 --- a/library/xml/df.language.xml +++ /dev/null @@ -1,106 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - $.word - - - - - - - - - - - - - - $.name - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - (when $.has_name - (let* ((nick $.nickname) - (language $global.world.raws.translations[$.language]) - (fname $.first_name) - (lwords $language.words)) - (fmt "~:(~@[~A ~]~@['~A' ~]~{~A~^ ~}~)" - (if (> (length fname) 0) fname) - (if (> (length nick) 0) nick) - (loop for i from 0 below 7 for word = $.words[i] - when (>= word 0) collect $lwords[word].value)))) - - - - - diff --git a/library/xml/df.legends.xml b/library/xml/df.legends.xml deleted file mode 100644 index a9d2e4a65..000000000 --- a/library/xml/df.legends.xml +++ /dev/null @@ -1,301 +0,0 @@ - - - - - - - - - - - - - (describe-obj $.name) - (describe-obj (find-creature $.race)) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - (describe-obj $.name) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - (describe-obj $.figure) - - - - - - - - - - - - - - - - (describe-obj $.name) - - - - - - - - - - diff --git a/library/xml/df.machines.xml b/library/xml/df.machines.xml deleted file mode 100644 index 000e83255..000000000 --- a/library/xml/df.machines.xml +++ /dev/null @@ -1,96 +0,0 @@ - - -- MACHINE - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- MACHINE COMPONENT BUILDINGS - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/library/xml/df.map.xml b/library/xml/df.map.xml deleted file mode 100644 index eac8bbeb9..000000000 --- a/library/xml/df.map.xml +++ /dev/null @@ -1,247 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/library/xml/df.materials.xml b/library/xml/df.materials.xml deleted file mode 100644 index ea464879a..000000000 --- a/library/xml/df.materials.xml +++ /dev/null @@ -1,341 +0,0 @@ - - - - - - - - (describe-material $) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // color token index - - - - - - - - - - - - - (material-by-id $ $$) - (describe-material $) - - - - - - - - - - - - - - - (describe-material $) - - - - - - - - - $.id - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - $.id - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/library/xml/df.military.xml b/library/xml/df.military.xml deleted file mode 100644 index d44af3d30..000000000 --- a/library/xml/df.military.xml +++ /dev/null @@ -1,236 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- May be invalid: - - - - - - - - - - - - - - - - - - - (describe-obj $.name) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - (describe-obj $.name) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/library/xml/df.projectile.xml b/library/xml/df.projectile.xml deleted file mode 100644 index 5fc9b3e4a..000000000 --- a/library/xml/df.projectile.xml +++ /dev/null @@ -1,62 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/library/xml/df.raws.xml b/library/xml/df.raws.xml deleted file mode 100644 index ed2745fb5..000000000 --- a/library/xml/df.raws.xml +++ /dev/null @@ -1,237 +0,0 @@ - - - -- Materials - - - - - - -- Inorganic - - - - - - - - - -- Plants - - - dtor 852cc20 - - - - - - - - - - - - - - - - - - - - - - - - - -- Creature RAWs - - - - dtor 89bab50 - - - dtor 8527e40 - - - - - - - - - - - - - dtor 89ba980 - - - -- Creatures - - - dtor 81448c0 - - - - - - - - - - - - - - - - -- Item RAWs - - - dtor 852e080 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- Sapient species - - - - - - -- Language RAWs - - dtor 852bc90 - - - - - - - - - - - - - - - - - - - - - - -- Words - - - - - - - - - - - - - - - - - - - - - - - - - - - -- Reaction RAWs - - - - - - -- Workshops - - - - - - - - - - - - - - - - -- Material index - - - - - - diff --git a/library/xml/df.refs.xml b/library/xml/df.refs.xml deleted file mode 100644 index 04671dc55..000000000 --- a/library/xml/df.refs.xml +++ /dev/null @@ -1,109 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/library/xml/df.stockpile.xml b/library/xml/df.stockpile.xml deleted file mode 100644 index cfd48e38d..000000000 --- a/library/xml/df.stockpile.xml +++ /dev/null @@ -1,254 +0,0 @@ - - - - - - - - - - - also 26 - also 31 - also 32 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 16 - - - - - - - - - - - - - - - - - - - - - 2 - - - - - - - - 5 - 5 - - - - - 659 - - - - - - - - 17 - - - - - - - - - - - - - - - - - - - - - - - - 11 - - - - - - - - - - - - - - - 11 - - - - - - - - - - - - - diff --git a/library/xml/df.ui.xml b/library/xml/df.ui.xml deleted file mode 100644 index 457617a00..000000000 --- a/library/xml/df.ui.xml +++ /dev/null @@ -1,603 +0,0 @@ - - - - - - - - - - - - - - - (describe-obj $.name) - - - - - - - - - - - - - - - - - - -- 2 - - - - - - - - - - - - - - - -- 14 - - - - - - -- 17 - - - - - - - - -- 22 - - - - - - -- 25 - - - - - - - - - - - -- 33 - - - - - -- 35 - - - - -- 36 - - - - - - - -- 40 - - - - - - - -- 44 - - - - - - - - - - - - - - - - - - - - - - - - - - ctor 86e33c0 x - dtor 8534190 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - dtor: 0x85272c0 - - - - diff --git a/library/xml/df.units.xml b/library/xml/df.units.xml deleted file mode 100644 index fdad8cd56..000000000 --- a/library/xml/df.units.xml +++ /dev/null @@ -1,701 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Scuttle creature: causes creature to be killed, leaving a behind - corpse and generating negative thoughts like a real kill. - - - - - - - - - - - - (describe-obj $.name) - (awhen (find-creature $.race) - (fmt "~:(~A ~A~)" $it.caste[$.caste].caste_id $it.creature_id)) - - - - - - - - - - - - - - - - E.g. for a dead miner, holds the place where he - was likely hanging around when he got the command - to mine in an aquifer. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- If shot by a ranged weapon: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // fight related - // fight related - - - // increments every tick - - - - - - - - - // 87*0 ? - - - - - // 238*0 - // 238*0 - // 238*0 - // 238*0 - // 238*0 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // 490 - - - - - - - - - - - - - - - - - - - - - - - - // 53c decrements every job_counter reroll, set when changing jobs - // 540 current_job unit/walk done when reach -1, decremented every tick - // if set, decrements every job_counter reroll - - - // 54c decrements every tick, unstun at 0 - - - - - // coords ? (-30.000x3) - - - // coords again - - - - - - - - - - - - - - - - - - - - - - - - // counter, decrement to 0 - // same as 58c - - // fluctuate - - - - - - - - - - - - - - - - - - - - - - - - // 0x3e8 (1000) - // 0x3e8 (1000) - - - - - - - - - - - - - - - - // item ids? - - // 6f0: dined in a legendary dinning room, etc - - - - // 710 - - - - - // 738 - - - - // coords (-30000*3) - - - - - - - - - - - // 794 - // 796 - // 798 - // 79a - - - - - - - - - - - - - - - - - - - - - - // combat log? - - - - - - - - - - - - - // item related - - - - - - // age ? incremented every tick - - - - - - - - - - // items ids? - - // same size as 8e8, soldier related? - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - (fmt "value=~A" $.value) - - - - - - - - - - - - - - - (describe-obj $.name) - (awhen (find-creature $.race) - (fmt "~:(~A ~A~)" $it.caste[$.caste].caste_id $it.creature_id)) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/library/xml/df.viewscreen.xml b/library/xml/df.viewscreen.xml deleted file mode 100644 index 3874c445a..000000000 --- a/library/xml/df.viewscreen.xml +++ /dev/null @@ -1,88 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/library/xml/df.world-data.xml b/library/xml/df.world-data.xml deleted file mode 100644 index 2f0faa3a2..000000000 --- a/library/xml/df.world-data.xml +++ /dev/null @@ -1,374 +0,0 @@ - - - - - - - - - - - - - - - - - - - - (describe-obj $.name) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/library/xml/df.world.xml b/library/xml/df.world.xml deleted file mode 100644 index 3058b0a64..000000000 --- a/library/xml/df.world.xml +++ /dev/null @@ -1,503 +0,0 @@ - - - dtor 89fff80 - - - dtor 8532540 - - - - - - - - - - - - - - - - - -- - - - - - - - - - - -- Entities - - - - - - - - - - - - -- Unknown - - - - -- Units - - - - - - - - - - - - - - - - - - -- Unknown - - - - - - - - - -- Nemesis - - - - - - - - - - - - - - -- Items - - - dtor 852f4b0 - - - - - - - - - - - - - - - - - - - -- Artifacts - - - - - - - - - - - - -- Jobs and projectiles - - - - - - -- Buildings - - - dtor 85316f0 - - - - - - - - - - - - - - - - - - - - -- Machines (connected groups of gears and so on) - - - - - - - - - - - -- Unknown - - - - - - - - - - - - - - - - - - - - - - - - -- Plants - - - - - - - - - -- Unknown - - - - -- Unknown - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- Drills - - - - - - - - - - - -- Reports and announcements - - - dtor 85356e0 - - - - - - - - - - Written to by code at 0x80fd7b0 - - - - - - - - - - - - - - - - - - - - - - 52cdc - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 547f8 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- RAWs - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ctor 87ae880 - - - - - - - - - - - dtor 83bed90 - - - - - - - - - - - - -- hist figures - - - - - - - - - - - - - - - - Looks like a temporary buffer for pathfinding or something. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 192be0 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/library/xml/list.pl b/library/xml/list.pl deleted file mode 100755 index 206565843..000000000 --- a/library/xml/list.pl +++ /dev/null @@ -1,33 +0,0 @@ -#!/usr/bin/perl - -use strict; -use warnings; - -use XML::LibXML; - -my $input_dir = $ARGV[0] || '.'; -my $output_dir = $ARGV[1] || 'codegen'; -my $separator = $ARGV[2] || "\n"; - -print "$output_dir/static.inc"; - -for my $filename (glob "$input_dir/*.xml") { - my $parser = XML::LibXML->new(); - my $doc = $parser->parse_file($filename); - - my @nodes = ( - $doc->findnodes('/data-definition/enum-type'), - $doc->findnodes('/data-definition/bitfield-type'), - $doc->findnodes('/data-definition/struct-type'), - $doc->findnodes('/data-definition/class-type') - ); - - for my $node (@nodes) { - my $name = $node->getAttribute('type-name') - or die "Unnamed type in $filename\n"; - print "$separator$output_dir/$name.h"; - } -} - -print $separator if $separator eq "\n"; - diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txt index ab7e039a4..133905727 100644 --- a/plugins/CMakeLists.txt +++ b/plugins/CMakeLists.txt @@ -59,6 +59,8 @@ DFHACK_PLUGIN(filltraffic filltraffic.cpp) DFHACK_PLUGIN(seedwatch seedwatch.cpp) DFHACK_PLUGIN(initflags initflags.cpp) DFHACK_PLUGIN(stockpiles stockpiles.cpp) +DFHACK_PLUGIN(rename rename.cpp) +DFHACK_PLUGIN(fixwagons fixwagons.cpp) #DFHACK_PLUGIN(versionosd versionosd.cpp) # this is the skeleton plugin. If you want to make your own, make a copy and then change it diff --git a/plugins/Dfusion/CMakeLists.txt b/plugins/Dfusion/CMakeLists.txt index 7b6724dde..8ac2e79e9 100644 --- a/plugins/Dfusion/CMakeLists.txt +++ b/plugins/Dfusion/CMakeLists.txt @@ -7,6 +7,9 @@ set( ${dfhack_SOURCE_DIR}/library/depends/tthread/tinythread.cpp ${DFUSION_CPPS} ) -DFHACK_PLUGIN(dfusion ${DFUSION_CPPS_ALL} LINK_LIBRARIES lua) +FILE(GLOB DFUSION_HS include/*) +SET_SOURCE_FILES_PROPERTIES( ${DFUSION_HS} PROPERTIES HEADER_FILE_ONLY TRUE ) +DFHACK_PLUGIN(dfusion ${DFUSION_CPPS_ALL} ${DFUSION_HS} LINK_LIBRARIES lua) + # installs into DF root install(DIRECTORY luafiles/ DESTINATION dfusion) diff --git a/plugins/Dfusion/dfusion.cpp b/plugins/Dfusion/dfusion.cpp index 7aa4aba84..7bba2217b 100644 --- a/plugins/Dfusion/dfusion.cpp +++ b/plugins/Dfusion/dfusion.cpp @@ -1,9 +1,9 @@ -#include -#include -#include -#include -#include -#include "dfhack/extra/stopwatch.h" +#include "Core.h" +#include "Console.h" +#include "Export.h" +#include "PluginManager.h" +#include "MemAccess.h" +#include "MiscUtils.h" #include #include @@ -18,6 +18,7 @@ #include "lua_Misc.h" #include "lua_VersionInfo.h" #include "functioncall.h" +#include "lua_FunctionCall.h" using std::vector; using std::string; @@ -45,6 +46,8 @@ DFhackCExport command_result plugin_init ( Core * c, std::vector lua::RegisterHexsearch(st); lua::RegisterMisc(st); lua::RegisterVersionInfo(st); + lua::RegisterFunctionCall(st); + #ifdef LINUX_BUILD st.push(1); st.setglobal("LINUX"); @@ -53,7 +56,7 @@ DFhackCExport command_result plugin_init ( Core * c, std::vector st.setglobal("WINDOWS"); #endif - commands.push_back(PluginCommand("dfusion","Init dfusion system. Use 'dfusion thready' to spawn a different thread.",dfusion)); + commands.push_back(PluginCommand("dfusion","Init dfusion system. Use 'dfusion init' to run dfusion in init mode (not interactive).",dfusion)); commands.push_back(PluginCommand("lua", "Run interactive interpreter. Use 'lua ' to run instead.",lua_run)); mymutex=new tthread::mutex; @@ -171,13 +174,18 @@ void RunDfusion(void *p) } DFhackCExport command_result dfusion (Core * c, vector & parameters) { - if(thread_dfusion==0) - thread_dfusion=new tthread::thread(RunDfusion,c); - if(parameters[0]!="thready") + if(parameters[0]=="init") { - thread_dfusion->join(); - delete thread_dfusion; - thread_dfusion=0; + lua::state s=lua::glua::Get(); + s.push(1); + s.setglobal("INIT"); + } + else + { + lua::state s=lua::glua::Get(); + s.push(); + s.setglobal("INIT"); } + RunDfusion(c); return CR_OK; } diff --git a/plugins/Dfusion/include/hexsearch.h b/plugins/Dfusion/include/hexsearch.h index b4ffb84d8..3a939b088 100644 --- a/plugins/Dfusion/include/hexsearch.h +++ b/plugins/Dfusion/include/hexsearch.h @@ -1,8 +1,8 @@ #ifndef HEXSEARCH_H #define HEXSEARCH_H #include -#include "dfhack/Core.h" //for some reason process.h needs core -#include "dfhack/Process.h" +#include "Core.h" //for some reason process.h needs core +#include "MemAccess.h" //(not yet)implemented using Boyer-Moore algorithm diff --git a/plugins/Dfusion/include/lua_Console.h b/plugins/Dfusion/include/lua_Console.h index a6430dcbf..2ced33645 100644 --- a/plugins/Dfusion/include/lua_Console.h +++ b/plugins/Dfusion/include/lua_Console.h @@ -1,6 +1,6 @@ #ifndef LUA_CONSOLE_H #define LUA_CONSOLE_H -#include +#include #include "luamain.h" namespace lua diff --git a/plugins/Dfusion/include/lua_FunctionCall.h b/plugins/Dfusion/include/lua_FunctionCall.h new file mode 100644 index 000000000..bc1af5685 --- /dev/null +++ b/plugins/Dfusion/include/lua_FunctionCall.h @@ -0,0 +1,14 @@ +#ifndef LUA_FUNCTIONCALL__H +#define LUA_FUNCTIONCALL__H + +#include "luamain.h" +#include "functioncall.h" + +namespace lua +{ + + +void RegisterFunctionCall(lua::state &st); + +} +#endif \ No newline at end of file diff --git a/plugins/Dfusion/include/lua_Misc.h b/plugins/Dfusion/include/lua_Misc.h index 3254ed3d0..8bada83c4 100644 --- a/plugins/Dfusion/include/lua_Misc.h +++ b/plugins/Dfusion/include/lua_Misc.h @@ -3,8 +3,8 @@ #include -#include -#include +#include "Core.h" +#include #include "luamain.h" #include "OutFile.h" #include "bit.h" diff --git a/plugins/Dfusion/include/lua_Process.h b/plugins/Dfusion/include/lua_Process.h index 515aa55af..e6639cfc8 100644 --- a/plugins/Dfusion/include/lua_Process.h +++ b/plugins/Dfusion/include/lua_Process.h @@ -1,8 +1,8 @@ #ifndef LUA_PROCESS_H #define LUA_PROCESS_H -#include -#include +#include "Core.h" +#include #include "luamain.h" diff --git a/plugins/Dfusion/include/lua_VersionInfo.h b/plugins/Dfusion/include/lua_VersionInfo.h index 26cdc96db..99010f590 100644 --- a/plugins/Dfusion/include/lua_VersionInfo.h +++ b/plugins/Dfusion/include/lua_VersionInfo.h @@ -1,7 +1,7 @@ #ifndef LUA_VERSIONINFO_H #define LUA_VERSIONINFO_H -#include -#include +#include "Core.h" +#include #include "luamain.h" namespace lua { @@ -28,6 +28,7 @@ public: int getName(lua_State *L); int getFullName(lua_State *L); int getParent(lua_State *L); + int getKeys(lua_State *L); DEF_LUNE(OffsetGroup); }; diff --git a/plugins/Dfusion/luafiles/common.lua b/plugins/Dfusion/luafiles/common.lua index 610b5f598..98043f463 100644 --- a/plugins/Dfusion/luafiles/common.lua +++ b/plugins/Dfusion/luafiles/common.lua @@ -3,6 +3,11 @@ STD_STRING=0 DWORD=1 WORD=2 BYTE=3 +function printd(...) + if DEBUG then + print(...) + end +end function GetTextRegion() if __TEXT ~=nil then --Chache this, not going to change. return __TEXT @@ -324,7 +329,7 @@ function findVectors() local loc1,loc2 loc1=engine.peekd(v+2) loc2=engine.peekd(v+8) - print(string.format("%x - %x=%x",loc1,loc2,loc1-loc2)) + --print(string.format("%x - %x=%x",loc1,loc2,loc1-loc2)) if(loc1-loc2==4) then if T[loc1-4]~=nil then T[loc1-4]=T[loc1-4]+1 diff --git a/plugins/Dfusion/luafiles/embark/init.lua b/plugins/Dfusion/luafiles/embark/init.lua new file mode 100644 index 000000000..477e0255a --- /dev/null +++ b/plugins/Dfusion/luafiles/embark/init.lua @@ -0,0 +1,71 @@ +function MakeTable(modpos,modsize,names) + count=0 + castes={} + --print("Making table") + for _,line in pairs(names) do + --print("Line:"..line) + tpos=string.find(line,":") + if tpos~=nil then + --print("Was line:"..line) + table.insert(castes,tonumber(string.sub(line,tpos+1))) + line=string.sub(line,1,tpos-1) + --print("IS line:"..line) + else + table.insert(castes,-1) + end + if RaceTable[line] == nil then + error("Failure, "..line.." not found!") + end + engine.pokew(modpos+modsize+count*2,RaceTable[line]) -- add race + count = count + 1 + end + i=0 + for _,caste in pairs(castes) do + + engine.pokew(modpos+modsize+count*2+i*2,caste) -- add caste + i= i+1 + end + + engine.poked(stoff,count) + return count +end +function embark(names) + RaceTable=RaceTable or BuildNameTable() + mypos=engine.getmod('Embark') + stoff=offsets.getEx('StartDwarfs') + if mypos then --if mod already loaded + print("Mod already loaded @:"..mypos.." just updating") + modpos=mypos + _,modsize=engine.loadobj('dfusion/embark/embark.o') + + count=MakeTable(modpos,modsize,names) --just remake tables + else + + tofind=VersionInfo.getGroup("Creatures"):getAddress("current_race")--offsets.getEx('CurrentRace') + + loc=offsets.find(stoff,0xa1,DWORD_,tofind) + + print("found:"..loc) + + if((loc~=0)and(loc-stoff<1000)) then + modpos,modsize=engine.loadmod('dfusion/embark/embark.o','Embark',256) + count=MakeTable(modpos,modsize,names) + engine.poked(modpos+0x18,modpos+modsize) --fix array start for race + engine.poked(modpos+0x08,modpos+modsize+count*2) --fix array start for caste + print("sucess loading mod @:"..modpos) + -- build race vector after module. + + + --finaly poke in the call! + engine.pokeb(loc,0x6a) + engine.pokeb(loc+1,0xFF) + engine.pokeb(loc+2,0xe8) + engine.poked(loc+3,modpos-loc-7) + --engine.pokeb(loc+5,0x90) + SetExecute(modpos) + else + error("did not find patch location, failing...") + end + + end +end \ No newline at end of file diff --git a/plugins/Dfusion/luafiles/embark/plugin.lua b/plugins/Dfusion/luafiles/embark/plugin.lua index db65da78c..039000656 100644 --- a/plugins/Dfusion/luafiles/embark/plugin.lua +++ b/plugins/Dfusion/luafiles/embark/plugin.lua @@ -1,74 +1,4 @@ -function MakeTable(modpos,modsize,names) - count=0 - castes={} - --print("Making table") - for _,line in pairs(names) do - --print("Line:"..line) - tpos=string.find(line,":") - if tpos~=nil then - --print("Was line:"..line) - table.insert(castes,tonumber(string.sub(line,tpos+1))) - line=string.sub(line,1,tpos-1) - --print("IS line:"..line) - else - table.insert(castes,-1) - end - if RaceTable[line] == nil then - error("Failure, "..line.." not found!") - end - engine.pokew(modpos+modsize+count*2,RaceTable[line]) -- add race - count = count + 1 - end - i=0 - for _,caste in pairs(castes) do - - engine.pokew(modpos+modsize+count*2+i*2,caste) -- add caste - i= i+1 - end - - engine.poked(stoff,count) - return count -end -function embark(names) - RaceTable=RaceTable or BuildNameTable() - mypos=engine.getmod('Embark') - stoff=offsets.getEx('StartDwarfs') - if mypos then --if mod already loaded - print("Mod already loaded @:"..mypos.." just updating") - modpos=mypos - _,modsize=engine.loadobj('dfusion/embark/embark.o') - - count=MakeTable(modpos,modsize,names) --just remake tables - else - - tofind=VersionInfo.getGroup("Creatures"):getAddress("current_race")--offsets.getEx('CurrentRace') - loc=offsets.find(stoff,0xa1,DWORD_,tofind) - - print("found:"..loc) - - if((loc~=0)and(loc-stoff<1000)) then - modpos,modsize=engine.loadmod('dfusion/embark/embark.o','Embark',256) - count=MakeTable(modpos,modsize,names) - engine.poked(modpos+0x18,modpos+modsize) --fix array start for race - engine.poked(modpos+0x08,modpos+modsize+count*2) --fix array start for caste - print("sucess loading mod @:"..modpos) - -- build race vector after module. - - - --finaly poke in the call! - engine.pokeb(loc,0x6a) - engine.pokeb(loc+1,0xFF) - engine.pokeb(loc+2,0xe8) - engine.poked(loc+3,modpos-loc-7) - --engine.pokeb(loc+5,0x90) - SetExecute(modpos) - else - error("did not find patch location, failing...") - end - - end -end if not(FILE)then names=ParseNames("dfusion/embark/races.txt")--io.open("plugins/embark/races.txt"):lines() embark(names) diff --git a/plugins/Dfusion/luafiles/friendship_civ/compile.bat b/plugins/Dfusion/luafiles/friendship_civ/compile.bat new file mode 100644 index 000000000..64d4d4440 --- /dev/null +++ b/plugins/Dfusion/luafiles/friendship_civ/compile.bat @@ -0,0 +1 @@ +as -anl --32 -o friendship_c.o friendship_c.asm \ No newline at end of file diff --git a/plugins/Dfusion/luafiles/friendship_civ/friendship_c.asm b/plugins/Dfusion/luafiles/friendship_civ/friendship_c.asm new file mode 100644 index 000000000..b2b49ee78 --- /dev/null +++ b/plugins/Dfusion/luafiles/friendship_civ/friendship_c.asm @@ -0,0 +1,41 @@ +.intel_syntax +eaxpart: +push eax +push ecx +jmp compare +ecxpart: +push eax +push ecx +mov eax,ecx + +compare: +push ebx +mov ebx,0xDEADBEEF #write a pointer to the list of allowed civs +mov ecx,2000 #write a number of allowed civs +loop1: +cmp [ebx+ecx*4],eax +jnz endok +dec ecx +cmp ecx ,-1 +jnz loop1 + +pop ebx + +jmp fail + +endok: +pop ebx + +cmp eax,eax +jmp endfinal +fail: + +xor ecx,ecx +xor eax,eax +inc eax +cmp eax,ebx +endfinal: + +pop ecx +pop eax +ret \ No newline at end of file diff --git a/plugins/Dfusion/luafiles/friendship_civ/friendship_c.o b/plugins/Dfusion/luafiles/friendship_civ/friendship_c.o new file mode 100644 index 000000000..d85134682 Binary files /dev/null and b/plugins/Dfusion/luafiles/friendship_civ/friendship_c.o differ diff --git a/plugins/Dfusion/luafiles/friendship_civ/init.lua b/plugins/Dfusion/luafiles/friendship_civ/init.lua new file mode 100644 index 000000000..5390829de --- /dev/null +++ b/plugins/Dfusion/luafiles/friendship_civ/init.lua @@ -0,0 +1,89 @@ +friendship_civ={} +function friendship_civ.init() + friendship_civ.count=0x0f + friendship_civ.firsttime=true + local mypos=engine.getmod("Friendship_civ") + local modpos=0 + if mypos then + modpos=mypos + _,modsize=engine.loadobj("dfusion/friendship_civ/friendship_c.o") + _=nil + friendship_civ.firsttime=false + else + modpos,modsize=engine.loadmod("dfusion/friendship_civ/friendship_c.o","Friendship_civ",1024) + print(string.format("Loaded module @:%x",modpos)) + end + friendship_civ.modpos=modpos + friendship_civ.modsize=modsize +end +function friendship_civ.install(civs) + friendship_civ.init() + local count=0 + for _,v in pairs(civs) do + engine.poked(friendship_civ.modpos+friendship_civ.modsize+count*4,v) -- for some reason it compiled strangely + -- cmp word[ebx+ecx*2],ax -> cmp word[ebx+ecx*2+2],ax + count = count + 1 + end + engine.poked(friendship_civ.modpos+0x0a,friendship_civ.modpos+friendship_civ.modsize) -- set ptr to civ ids + engine.poked(friendship_civ.modpos+friendship_civ.count,count-1) -- set count of civs + SetExecute(friendship_civ.modpos) + + if(friendship_civ.firsttime) then + friendship_civ.patch() + end +end +function friendship_civ.getcivs() + if(friendship_civ.firsttime==nil)then + return nil + end + friendship_civ.init() + local count=engine.peekd(friendship_civ.modpos+friendship_civ.count)+1 + local ret={} + for i=0, count-1 do + table.insert(ret,engine.peekd(friendship_civ.modpos+friendship_civ.modsize+i*4)) + end + return ret +end +function friendship_civ.addciv(civ) --if called with nil add current civ :) + if civ==nil then + local cciv=engine.peekd(VersionInfo.getGroup("Creatures"):getAddress("current_civ")) + friendship_civ.install({cciv}) + return + end + local oldcivs=friendship_civ.getcivs() + oldcivs=oldcivs or {} + if type(civ)=="table" then + for k,v in ipairs(civ) do + table.insert(oldcivs,v) + end + else + table.insert(oldcivs,civ) + end + friendship_civ.install(oldcivs) +end +function friendship_civ.patch_call(off,iseax) + local calltrg=friendship_civ.modpos + if not iseax then + calltrg=calltrg+4 + end + engine.pokeb(off,0xe8) --this is a call + engine.poked(off+1,calltrg-off-5) --offset to call to (relative) + engine.pokeb(off+5,0x90) --nop +end +function friendship_civ.patch() + --UpdateRanges() + local civloc= VersionInfo.getGroup("Creatures"):getAddress("current_civ") + local pos1=offsets.findall(0,0x3B,0x05,DWORD_,civloc) --eax + for k,v in pairs(pos1) do print(string.format("%d %x",k,v)) end + local pos2=offsets.findall(0,0x3B,0x0D,DWORD_,civloc) --ecx + for k,v in pairs(pos2) do print(string.format("%d %x",k,v)) end + + for k,v in pairs(pos1) do + print(string.format("Patching eax compare %d: %x",k,v)) + friendship_civ.patch_call(v,true) + end + for k,v in pairs(pos2) do + print(string.format("Patching ecx compare %d: %x",k,v)) + friendship_civ.patch_call(v,false) + end +end diff --git a/plugins/Dfusion/luafiles/friendship_civ/plugin.lua b/plugins/Dfusion/luafiles/friendship_civ/plugin.lua new file mode 100644 index 000000000..12f334fcf --- /dev/null +++ b/plugins/Dfusion/luafiles/friendship_civ/plugin.lua @@ -0,0 +1,57 @@ +fc_ui={} +fc_ui.menu=MakeMenu() +function fc_ui.get() + local mycivs=friendship_civ.getcivs() + if mycivs~= nil then + print(" Currently friendly civs:") + for k,v in pairs(mycivs) do + print(string.format("%d. %d",k,v)) + end + else + print(" Plugin no yet activated.") + end +end +function fc_ui.add() + print("Type in civ id to add (leave empty to add current, q cancels):") + local r + while r==nil and r~='q' do + r=io.stdin:read() + if r=="" then + r=nil + break + end + if r~='q' then r=tonumber(r) else + return + end + end + friendship_civ.addciv(r) +end +function fc_ui.remove() + local mycivs=friendship_civ.getcivs() + if mycivs~= nil then + print(" Currently friendly civs:") + for k,v in pairs(mycivs) do + print(string.format("%d. %d",k,v)) + end + else + print(" Plugin no yet activated, nothing to remove.") + return + end + print("Type in civ id to remove( q cancels):") + local r + while r==nil and r~='q' do + r=io.stdin:read() + if r~='q' then + r=tonumber(r) + if r>#mycivs then r=nil end + else + return + end + end + table.remove(mycivs,r) + friendship_civ.install(mycivs) +end +fc_ui.menu:add("Add civ",fc_ui.add) +fc_ui.menu:add("Get civs",fc_ui.get) +fc_ui.menu:add("Remove civ",fc_ui.remove) +fc_ui.menu:display() \ No newline at end of file diff --git a/plugins/Dfusion/luafiles/init.lua b/plugins/Dfusion/luafiles/init.lua index 427682e45..5adb9abe3 100644 --- a/plugins/Dfusion/luafiles/init.lua +++ b/plugins/Dfusion/luafiles/init.lua @@ -43,12 +43,14 @@ function mainmenu(t1) end end dofile("dfusion/common.lua") +dofile("dfusion/utils.lua") unlockDF() plugins={} table.insert(plugins,{"simple_embark","A simple embark dwarf count editor"}) table.insert(plugins,{"items","A collection of item hacking tools"}) table.insert(plugins,{"offsets","Find all offsets"}) table.insert(plugins,{"friendship","Multi race fort enabler"}) +table.insert(plugins,{"friendship_civ","Multi civ fort enabler"}) table.insert(plugins,{"embark","Multi race embark"}) table.insert(plugins,{"adv_tools","some tools for (mainly) advneturer hacking"}) table.insert(plugins,{"tools","some misc tools"}) @@ -56,6 +58,14 @@ table.insert(plugins,{"triggers","a function calling plug (discontinued...)"}) table.insert(plugins,{"migrants","multi race imigrations"}) table.insert(plugins,{"onfunction","run lua on some df function"}) loadall(plugins) +dofile_silent("dfusion/initcustom.lua") + +print("Locating saves...") +local str=engine.peekstr(0x1447A40+offsets.base()) +print("Current region:"..str) +str="data/save/"..str.."/dfusion/init.lua" +dofile_silent(str) + if not INIT then mainmenu(plugins) end diff --git a/plugins/Dfusion/luafiles/migrants/init.lua b/plugins/Dfusion/luafiles/migrants/init.lua new file mode 100644 index 000000000..85463fe7e --- /dev/null +++ b/plugins/Dfusion/luafiles/migrants/init.lua @@ -0,0 +1,61 @@ +--install part +function migrants(names) +RaceTable=RaceTable or BuildNameTable() +mypos=engine.getmod("Migrants") +if mypos then + print("Migrant mod is running already @:"..mypos) + modpos=mypos + _,modsize=engine.loadobj("dfusion/migrants/migrants.o") + count=0 + for _,v in pairs(names) do + if RaceTable[v] == nil then + print("Failure, "..v.." not found!") + break --maybe some indication of failure? and cleanup? + end + engine.pokew(modpos+modsize+count*2+4,RaceTable[v]) + count = count + 1 + end + seedpos=modpos+modsize + engine.poked(seedpos,math.random(1234567)) -- seed the generator :) + engine.poked(modpos+0x1c,count) --max size for div + +else + modpos,modsize=engine.loadmod("dfusion/migrants/migrants.o","Migrants") + print(string.format("Loaded module @:%x",modpos)) + count=0 + for _,v in pairs(names) do + if RaceTable[v] == nil then + print("Failure, "..v.." not found!") + break --maybe some indication of failure? and cleanup? + end + engine.pokew(modpos+modsize+count*2+4,RaceTable[v]) + + count = count + 1 + end + + seedpos=modpos+modsize + engine.poked(modpos+0x04,seedpos) + engine.poked(modpos+0x15,seedpos) + + engine.poked(seedpos,math.random(1234567)) -- seed the generator :) + engine.poked(modpos+0x1c,count) --max size for div + + engine.poked(modpos+0x26,seedpos+4) --start of array + + --patch part + --pos=62873C+DF + -- pattern: A1,DWORD_,"CURRENTRACE",56,89,ANYBYTE,ANYBYTE,34,e8 + pos=offsets.find(offsets.base(),0xa1,DWORD_,offsets.getEx("CurrentRace"),0x56,0x89,ANYBYTE,ANYBYTE,0x34,0xe8) + function pokeCall(off) + engine.pokeb(off,0xe8) + engine.poked(off+1,modpos-off-5) + end + if pos~=0 then + print(string.format("Found @:%x",pos)) + pokeCall(pos) + else + print("Not found patch location!!!") + end + end + +end \ No newline at end of file diff --git a/plugins/Dfusion/luafiles/migrants/plugin.lua b/plugins/Dfusion/luafiles/migrants/plugin.lua index 0e1e46160..651e4900c 100644 --- a/plugins/Dfusion/luafiles/migrants/plugin.lua +++ b/plugins/Dfusion/luafiles/migrants/plugin.lua @@ -1,64 +1,4 @@ ---install part -function migrants(names) -RaceTable=RaceTable or BuildNameTable() -mypos=engine.getmod("Migrants") -if mypos then - print("Migrant mod is running already @:"..mypos) - modpos=mypos - _,modsize=engine.loadobj("dfusion/migrants/migrants.o") - count=0 - for _,v in pairs(names) do - if RaceTable[v] == nil then - print("Failure, "..v.." not found!") - break --maybe some indication of failure? and cleanup? - end - engine.pokew(modpos+modsize+count*2+4,RaceTable[v]) - count = count + 1 - end - seedpos=modpos+modsize - engine.poked(seedpos,math.random(1234567)) -- seed the generator :) - engine.poked(modpos+0x1c,count) --max size for div - -else - modpos,modsize=engine.loadmod("dfusion/migrants/migrants.o","Migrants") - print(string.format("Loaded module @:%x",modpos)) - count=0 - for _,v in pairs(names) do - if RaceTable[v] == nil then - print("Failure, "..v.." not found!") - break --maybe some indication of failure? and cleanup? - end - engine.pokew(modpos+modsize+count*2+4,RaceTable[v]) - - count = count + 1 - end - seedpos=modpos+modsize - engine.poked(modpos+0x04,seedpos) - engine.poked(modpos+0x15,seedpos) - - engine.poked(seedpos,math.random(1234567)) -- seed the generator :) - engine.poked(modpos+0x1c,count) --max size for div - - engine.poked(modpos+0x26,seedpos+4) --start of array - - --patch part - --pos=62873C+DF - -- pattern: A1,DWORD_,"CURRENTRACE",56,89,ANYBYTE,ANYBYTE,34,e8 - pos=offsets.find(offsets.base(),0xa1,DWORD_,offsets.getEx("CurrentRace"),0x56,0x89,ANYBYTE,ANYBYTE,0x34,0xe8) - function pokeCall(off) - engine.pokeb(off,0xe8) - engine.poked(off+1,modpos-off-5) - end - if pos~=0 then - print(string.format("Found @:%x",pos)) - pokeCall(pos) - else - print("Not found patch location!!!") - end - end - -end if not(FILE) then names=ParseNames("dfusion/migrants/races.txt")--io.open("plugins/migrants/races.txt"):lines() migrants(names) diff --git a/plugins/Dfusion/luafiles/onfunction/locations.lua b/plugins/Dfusion/luafiles/onfunction/locations.lua index 677771392..57043b7a3 100644 --- a/plugins/Dfusion/luafiles/onfunction/locations.lua +++ b/plugins/Dfusion/luafiles/onfunction/locations.lua @@ -7,6 +7,7 @@ if WINDOWS then --windows function defintions onfunction.AddFunction(0x3d4301+offsets.base(),"Make_Item",{item_type="esp"}) onfunction.AddFunction(0x5af826+offsets.base(),"Hurt",{target="esi",attacker={off=0x74,rtype=DWORD,reg="esp"}}) onfunction.AddFunction(0x3D5886+offsets.base(),"Flip",{building="esi"}) + onfunction.AddFunction(0x35E340+offsets.base(),"ItemCreate") else --linux onfunction.AddFunction(0x899befe+offsets.base(),"Move") -- found out by attaching watch... onfunction.AddFunction(0x850eecd+offsets.base(),"Die",{creature="ebx"}) -- same diff --git a/plugins/Dfusion/luafiles/patterns.lua b/plugins/Dfusion/luafiles/patterns.lua index 1d15741eb..c9f0e8c37 100644 --- a/plugins/Dfusion/luafiles/patterns.lua +++ b/plugins/Dfusion/luafiles/patterns.lua @@ -195,7 +195,7 @@ ptr_CrGloss.castes={off=296,rtype=ptr_vector} ptr_CrCaste={} ptr_CrCaste.name={off=0,rtype=ptt_dfstring} -ptr_CrCaste.flags_ptr={off=0x524,rtype=DWORD} --size 17? +ptr_CrCaste.flags_ptr={off=0x5A0,rtype=DWORD} --size 17? --[=[ Flags: 57 - is sentient (allows setting labours) diff --git a/plugins/Dfusion/luafiles/tools/init.lua b/plugins/Dfusion/luafiles/tools/init.lua new file mode 100644 index 000000000..b6720d2b7 --- /dev/null +++ b/plugins/Dfusion/luafiles/tools/init.lua @@ -0,0 +1,497 @@ +tools={} +tools.menu=MakeMenu() +function tools.setrace() + RaceTable=RaceTable or BuildNameTable() --slow.If loaded don't load again + print("Your current race is:"..GetRaceToken(engine.peekw(offsets.getEx('CurrentRace')))) + print("Type new race's token name in full caps:") + repeat + entry=io.stdin:read() + id=RaceTable[entry] + until id~=nil + engine.pokew(offsets.getEx('CurrentRace'),id) +end +tools.menu:add("Set current race",tools.setrace) +function tools.GiveSentience(names) --TODO make pattern... + RaceTable=RaceTable or BuildNameTable() --slow.If loaded don't load again + if names ==nil then + ids={} + print("Type race's token name in full caps to give sentience to:") + repeat + entry=io.stdin:read() + id=RaceTable[entry] + until id~=nil + table.insert(ids,id) + else + ids={} + for _,name in pairs(names) do + id=RaceTable[name] + table.insert(ids,id) + end + end + for _,id in pairs(ids) do + local off=offsets.getEx('CreatureGloss') + local races=engine.peek(off,ptr_vector) + --print("Vector start:"..off) + + off=races:getval(id) + print(string.format("race location:%x",off)) + local castes=engine.peek(off,ptr_CrGloss.castes) + print(string.format("Caste count:%i",castes:size())) + local flagPattern=ptt_dfflag.new(17) + for i =0,castes:size()-1 do + local offCaste=castes:getval(i) + print("Caste name:"..engine.peek(offCaste,ptr_CrCaste.name):getval().."...") + local flagoffset=engine.peek(offCaste,ptr_CrCaste.flags_ptr) + local flags=engine.peek(flagoffset,flagPattern) + --print(string.format("%x",flagoffset)) + if flags:get(57) then + print("\tis sentient.") + else + print("\tnon sentient. Allocating IQ...") + flags:set(57,1) + engine.poke(flagoffset,flagPattern,flags) + end + end + end +end +tools.menu:add("Give Sentience",tools.GiveSentience) +function tools.embark() + off=offsets.find(0,0x66, 0x83, 0x7F ,0x1A ,0xFF,0x74,0x04) + if off~=0 then + engine.pokeb(off+5,0x90) + engine.pokeb(off+6,0x90) + print("Found and patched") + else + print("not found") + end +end +tools.menu:add("Embark anywhere",tools.embark) +function tools.getlegendsid(croff) + local vec=engine.peek(croff,ptr_Creature.legends) + if vec:size()==0 then + return 0 + end + for i =0,vector:size()-1 do + --if engine.peekd(vec:getval(i))~=0 then + -- print(string.format("%x",engine.peekd(vec:getval(i))-offsets.base())) + --end + if(engine.peekd(vec:getval(i))==offsets.getEx("vtableLegends")) then --easy to get.. just copy from player's-base + return engine.peekd(vec:getval(i)+4) + end + end + return 0 +end +function tools.getCreatureId(vector) + + tnames={} + rnames={} + --[[print("vector1 size:"..vector:size()) + print("vector2 size:"..vector2:size())]]-- + for i=0,vector:size()-1 do + --print(string.format("%x",vector:getval(i))) + + local name=engine.peek(vector:getval(i),ptt_dfstring):getval() + local lid= tools.getlegendsid(vector:getval(i)) + if lid ~=0 then + print(i..")*Creature Name:"..name.." race="..engine.peekw(vector:getval(i)+ptr_Creature.race.off).." legendid="..lid) + else + print(i..") Creature Name:"..name.." race="..engine.peekw(vector:getval(i)+ptr_Creature.race.off)) + end + if name ~="" and name~=nil then + tnames[i]=name + rnames[name]=i + end + end + print("=====================================") + print("type in name or number:") + r=io.stdin:read() + if tonumber(r) ==nil then + indx=rnames[r] + if indx==nil then return end + else + r=tonumber(r) + if rLOVE), q to quit:") + names={} + repeat + w=io.stdin:read(); + + if rwords[w]~=nil then + table.insert(names,w) + print("--added--") + end + + until w=='q' + end + + tnames={} + for _,v in pairs(names) do + if rwords[v] ~=nil then + table.insert(tnames,rwords[v]) --get word numbers + end + end + + local offsites=engine.peekd(offsets.getEx("SiteData"))+0x120 + snames={" pfort"," dfort"," cave","mohall","forest","hamlet","imploc"," lair"," fort"," camp"} + vector=engine.peek(offsites,ptr_vector) + print("Number of sites:"..vector:size()) + print("List of hits:") + for i =0,vector:size()-1 do + off=vector:getval(i) + + good=true + r="" + hits=0 + sname=engine.peek(off,ptr_site.name) + for k=0,6 do + vnum=sname[k]--engine.peekd(off+0x38+k*4) + tgood=false + + if vnum~=0xFFFFFFFF then + --print(string.format("%x",vnum)) + if names[vnum]~=nil then + r=r..names[vnum].." " + end + for _,v in pairs(tnames) do + if vnum==v then + tgood=true + --print("Match") + hits=hits+1 + break + end + end + if not tgood then + good=false + end + end + end + + if(good) and (hits>0)then + --if true then + --print("=====================") + typ=engine.peek(off,ptr_site.type)--engine.peekw(off+0x78) + flg=engine.peekd(engine.peek(off,ptr_site.flagptr)) + --flg=engine.peekd(off+224) + --flg2=engine.peekw(off) + --tv=engine.peek(off+0x84,ptr_vector) + --tv2=engine.peek(off+0xA4,ptr_vector) + + print(string.format("%d)%s off=%x type=%s\t flags=%x",i,r,off,snames[typ+1],flg)) + + if i%100==99 then + r=io.stdin:read() + end + + end + end + print("Type which to change (q cancels):") + repeat + r=io.stdin:read() + n=tonumber(r) + if(r=='q') then return end + until n~=nil + return vector:getval(n) +end +function tools.changesite(names) + off=tools.getsite(names) + snames={"Mountain halls (yours)","Dark fort","Cave","Mountain hall (NPC)","Forest retreat","Hamlet","Important location","Lair","Fort","Camp"} + + print("Type in the site type (q cancels):") + for k,v in pairs(snames) do + print((k-1).."->"..v) + end + repeat + r=io.stdin:read() + n2=tonumber(r) + if(r=='q') then return end + until n2~=nil + --off=vector:getval(n) + print(string.format("%x->%d",off,n2)) + engine.poke(off,ptr_site.type,n2) +end +function tools.changeflags(names) + myflag_pattern=ptt_dfflag.new(3*8) + off=tools.getsite(names) + offflgs=engine.peek(off,ptr_site.flagptr) + q='' + print(string.format("Site offset %x flags offset %x",off,offflgs)) + repeat + print("flags:") + + --off=vector:getval(n) + flg=engine.peek(offflgs,myflag_pattern) + r="" + for i=0,3*8-1 do + if flg:get(i)==1 then + r=r.."x" + else + r=r.."o" + end + if i%8==7 then + print(i-7 .."->"..r) + r="" + end + end + print("Type number to flip, or 'q' to quit.") + q=io.stdin:read() + n2=tonumber(q) + if n2~=nil then + + flg:flip(n2) + engine.poke(offflgs,myflag_pattern,flg) + end + until q=='q' +end +function tools.hostilate() + vector=engine.peek(offsets.getEx("CreatureVec"),ptr_vector) + id=engine.peekd(offsets.getEx("CreaturePtr")) + print(string.format("Vec:%d cr:%d",vector:size(),id)) + off=vector:getval(id) + crciv=engine.peek(off,ptr_Creature.civ) + print("Creatures civ:"..crciv) + curciv=engine.peekd(offsets.getEx("CurrentRace")-12) + print("My civ:"..curciv) + if curciv==crciv then + print("Friendly-making enemy") + engine.poke(off,ptr_Creature.civ,-1) + flg=engine.peek(off,ptr_Creature.flags) + flg:set(17,0) + print("flag 51:"..tostring(flg:get(51))) + engine.poke(off,ptr_Creature.flags,flg) + else + print("Enemy- making friendly") + engine.poke(off,ptr_Creature.civ,curciv) + flg=engine.peek(off,ptr_Creature.flags) + flg:set(17,1) + flg:set(19,0) + engine.poke(off,ptr_Creature.flags,flg) + end +end +function tools.mouseBlock() + local xs,ys,zs + xs,ys,zs=getxyz() + xs=math.floor(xs/16) + ys=math.floor(ys/16) + print("Mouse block is:"..xs.." "..ys.." "..zs) +end +function tools.protectsite() + local mapoffset=offsets.getEx("WorldData")--0x131C128+offsets.base() + local x=engine.peek(mapoffset+24,DWORD) + local y=engine.peek(mapoffset+28,DWORD) + local z=engine.peek(mapoffset+32,DWORD) + --vec=engine.peek(mapoffset,ptr_vector) + + print("Blocks loaded:"..x.." "..y.." "..z) + print("Select type:") + print("1. All (SLOW)") + print("2. range (x0 x1 y0 y1 z0 z1)") + print("3. One block around pointer") + print("anything else- quit") + q=io.stdin:read() + n2=tonumber(q) + if n2==nil then return end + if n2>3 or n2<1 then return end + local xs,xe,ys,ye,zs,ze + if n2==1 then + xs=0 + xe=x-1 + ys=0 + ye=y-1 + zs=0 + ze=z-1 + elseif n2==2 then + print("enter x0:") + xs=tonumber(io.stdin:read()) + print("enter x1:") + xe=tonumber(io.stdin:read()) + print("enter y0:") + ys=tonumber(io.stdin:read()) + print("enter y1:") + ye=tonumber(io.stdin:read()) + print("enter z0:") + zs=tonumber(io.stdin:read()) + print("enter z1:") + ze=tonumber(io.stdin:read()) + function clamp(t,vmin,vmax) + if t> vmax then return vmax end + if t< vmin then return vmin end + return t + end + xs=clamp(xs,0,x-1) + ys=clamp(ys,0,y-1) + zs=clamp(zs,0,z-1) + xe=clamp(xe,xs,x-1) + ye=clamp(ye,ys,y-1) + ze=clamp(ze,zs,z-1) + else + xs,ys,zs=getxyz() + xs=math.floor(xs/16) + ys=math.floor(ys/16) + xe=xs + ye=ys + ze=zs + end + local xblocks=engine.peek(mapoffset,DWORD) + local flg=bit.lshift(1,14) + for xx=xs,xe do + local yblocks=engine.peek(xblocks+xx*4,DWORD) + for yy=ys,ye do + local zblocks=engine.peek(yblocks+yy*4,DWORD) + for zz=zs,ze do + + + + local myblock=engine.peek(zblocks+zz*4,DWORD) + if myblock~=0 then + for i=0,255 do + local ff=engine.peek(myblock+0x67c+i*4,DWORD) + ff=bit.bor(ff,flg) --set 14 flag to 1 + engine.poke(myblock+0x67c+i*4,DWORD,ff) + end + end + end + print("Blocks done:"..xx.." "..yy) + end + end +end +function tools.fixwarp() + local mapoffset=offsets.getEx("WorldData")--0x131C128+offsets.base() + local x=engine.peek(mapoffset+24,DWORD) + local y=engine.peek(mapoffset+28,DWORD) + local z=engine.peek(mapoffset+32,DWORD) + --vec=engine.peek(mapoffset,ptr_vector) + + print("Blocks loaded:"..x.." "..y.." "..z) + print("Select type:") + print("1. All (SLOW)") + print("2. range (x0 x1 y0 y1 z0 z1)") + print("3. One block around pointer") + print("anything else- quit") + q=io.stdin:read() + n2=tonumber(q) + if n2==nil then return end + if n2>3 or n2<1 then return end + local xs,xe,ys,ye,zs,ze + if n2==1 then + xs=0 + xe=x-1 + ys=0 + ye=y-1 + zs=0 + ze=z-1 + elseif n2==2 then + print("enter x0:") + xs=tonumber(io.stdin:read()) + print("enter x1:") + xe=tonumber(io.stdin:read()) + print("enter y0:") + ys=tonumber(io.stdin:read()) + print("enter y1:") + ye=tonumber(io.stdin:read()) + print("enter z0:") + zs=tonumber(io.stdin:read()) + print("enter z1:") + ze=tonumber(io.stdin:read()) + function clamp(t,vmin,vmax) + if t> vmax then return vmax end + if t< vmin then return vmin end + return t + end + xs=clamp(xs,0,x-1) + ys=clamp(ys,0,y-1) + zs=clamp(zs,0,z-1) + xe=clamp(xe,xs,x-1) + ye=clamp(ye,ys,y-1) + ze=clamp(ze,zs,z-1) + else + xs,ys,zs=getxyz() + xs=math.floor(xs/16) + ys=math.floor(ys/16) + xe=xs + ye=ys + ze=zs + end + local xblocks=engine.peek(mapoffset,DWORD) + local flg=bit.bnot(bit.lshift(1,3)) + for xx=xs,xe do + local yblocks=engine.peek(xblocks+xx*4,DWORD) + for yy=ys,ye do + local zblocks=engine.peek(yblocks+yy*4,DWORD) + for zz=zs,ze do + local myblock=engine.peek(zblocks+zz*4,DWORD) + if myblock~=0 then + for i=0,255 do + local ff=engine.peek(myblock+0x67c+i*4,DWORD) + ff=bit.band(ff,flg) --set 14 flag to 1 + engine.poke(myblock+0x67c+i*4,DWORD,ff) + end + end + end + print("Blocks done:"..xx.." "..yy) + end + end +end \ No newline at end of file diff --git a/plugins/Dfusion/luafiles/tools/plugin.lua b/plugins/Dfusion/luafiles/tools/plugin.lua index 0a7bbc872..511b73205 100644 --- a/plugins/Dfusion/luafiles/tools/plugin.lua +++ b/plugins/Dfusion/luafiles/tools/plugin.lua @@ -1,501 +1,5 @@ --local bit = require("bit") -tools={} -tools.menu=MakeMenu() -function tools.setrace() - RaceTable=RaceTable or BuildNameTable() --slow.If loaded don't load again - print("Your current race is:"..GetRaceToken(engine.peekw(offsets.getEx('CurrentRace')))) - print("Type new race's token name in full caps:") - repeat - entry=io.stdin:read() - id=RaceTable[entry] - until id~=nil - engine.pokew(offsets.getEx('CurrentRace'),id) -end -tools.menu:add("Set current race",tools.setrace) -function tools.GiveSentience(names) --TODO make pattern... - RaceTable=RaceTable or BuildNameTable() --slow.If loaded don't load again - if names ==nil then - ids={} - print("Type race's token name in full caps to give sentience to:") - repeat - entry=io.stdin:read() - id=RaceTable[entry] - until id~=nil - table.insert(ids,id) - else - ids={} - for _,name in pairs(names) do - id=RaceTable[name] - table.insert(ids,id) - end - end - for _,id in pairs(ids) do - local off=offsets.getEx('CreatureGloss') - local races=engine.peek(off,ptr_vector) - --print("Vector start:"..off) - - off=races:getval(id) - print(string.format("race location:%x",off)) - local castes=engine.peek(off,ptr_CrGloss.castes) - print(string.format("Caste count:%i",castes:size())) - local flagPattern=ptt_dfflag.new(17) - for i =0,castes:size()-1 do - local offCaste=castes:getval(i) - print("Caste name:"..engine.peek(offCaste,ptr_CrCaste.name):getval().."...") - local flagoffset=engine.peek(offCaste,ptr_CrCaste.flags_ptr) - local flags=engine.peek(flagoffset,flagPattern) - --print(string.format("%x",flagoffset)) - if flags:get(57) then - print("\tis sentient.") - else - print("\tnon sentient. Allocating IQ...") - flags:set(57,1) - engine.poke(flagoffset,flagPattern,flags) - end - end - end -end -tools.menu:add("Give Sentience",tools.GiveSentience) -function tools.embark() - off=offsets.find(0,0x66, 0x83, 0x7F ,0x1A ,0xFF,0x74,0x04) - if off~=0 then - engine.pokeb(off+5,0x90) - engine.pokeb(off+6,0x90) - print("Found and patched") - else - print("not found") - end -end -tools.menu:add("Embark anywhere",tools.embark) -function tools.getlegendsid(croff) - local vec=engine.peek(croff,ptr_Creature.legends) - if vec:size()==0 then - return 0 - end - for i =0,vector:size()-1 do - --if engine.peekd(vec:getval(i))~=0 then - -- print(string.format("%x",engine.peekd(vec:getval(i))-offsets.base())) - --end - if(engine.peekd(vec:getval(i))==offsets.getEx("vtableLegends")) then --easy to get.. just copy from player's-base - return engine.peekd(vec:getval(i)+4) - end - end - return 0 -end -function tools.getCreatureId(vector) - tnames={} - rnames={} - --[[print("vector1 size:"..vector:size()) - print("vector2 size:"..vector2:size())]]-- - for i=0,vector:size()-1 do - --print(string.format("%x",vector:getval(i))) - - local name=engine.peek(vector:getval(i),ptt_dfstring):getval() - local lid= tools.getlegendsid(vector:getval(i)) - if lid ~=0 then - print(i..")*Creature Name:"..name.." race="..engine.peekw(vector:getval(i)+ptr_Creature.race.off).." legendid="..lid) - else - print(i..") Creature Name:"..name.." race="..engine.peekw(vector:getval(i)+ptr_Creature.race.off)) - end - if name ~="" and name~=nil then - tnames[i]=name - rnames[name]=i - end - end - print("=====================================") - print("type in name or number:") - r=io.stdin:read() - if tonumber(r) ==nil then - indx=rnames[r] - if indx==nil then return end - else - r=tonumber(r) - if rLOVE), q to quit:") - names={} - repeat - w=io.stdin:read(); - - if rwords[w]~=nil then - table.insert(names,w) - print("--added--") - end - - until w=='q' - end - - tnames={} - for _,v in pairs(names) do - if rwords[v] ~=nil then - table.insert(tnames,rwords[v]) --get word numbers - end - end - - local offsites=engine.peekd(offsets.getEx("SiteData"))+0x120 - snames={" pfort"," dfort"," cave","mohall","forest","hamlet","imploc"," lair"," fort"," camp"} - vector=engine.peek(offsites,ptr_vector) - print("Number of sites:"..vector:size()) - print("List of hits:") - for i =0,vector:size()-1 do - off=vector:getval(i) - - good=true - r="" - hits=0 - sname=engine.peek(off,ptr_site.name) - for k=0,6 do - vnum=sname[k]--engine.peekd(off+0x38+k*4) - tgood=false - - if vnum~=0xFFFFFFFF then - --print(string.format("%x",vnum)) - if names[vnum]~=nil then - r=r..names[vnum].." " - end - for _,v in pairs(tnames) do - if vnum==v then - tgood=true - --print("Match") - hits=hits+1 - break - end - end - if not tgood then - good=false - end - end - end - - if(good) and (hits>0)then - --if true then - --print("=====================") - typ=engine.peek(off,ptr_site.type)--engine.peekw(off+0x78) - flg=engine.peekd(engine.peek(off,ptr_site.flagptr)) - --flg=engine.peekd(off+224) - --flg2=engine.peekw(off) - --tv=engine.peek(off+0x84,ptr_vector) - --tv2=engine.peek(off+0xA4,ptr_vector) - - print(string.format("%d)%s off=%x type=%s\t flags=%x",i,r,off,snames[typ+1],flg)) - - if i%100==99 then - r=io.stdin:read() - end - - end - end - print("Type which to change (q cancels):") - repeat - r=io.stdin:read() - n=tonumber(r) - if(r=='q') then return end - until n~=nil - return vector:getval(n) -end -function tools.changesite(names) - off=tools.getsite(names) - snames={"Mountain halls (yours)","Dark fort","Cave","Mountain hall (NPC)","Forest retreat","Hamlet","Important location","Lair","Fort","Camp"} - - print("Type in the site type (q cancels):") - for k,v in pairs(snames) do - print((k-1).."->"..v) - end - repeat - r=io.stdin:read() - n2=tonumber(r) - if(r=='q') then return end - until n2~=nil - --off=vector:getval(n) - print(string.format("%x->%d",off,n2)) - engine.poke(off,ptr_site.type,n2) -end -function tools.changeflags(names) - myflag_pattern=ptt_dfflag.new(3*8) - off=tools.getsite(names) - offflgs=engine.peek(off,ptr_site.flagptr) - q='' - print(string.format("Site offset %x flags offset %x",off,offflgs)) - repeat - print("flags:") - - --off=vector:getval(n) - flg=engine.peek(offflgs,myflag_pattern) - r="" - for i=0,3*8-1 do - if flg:get(i)==1 then - r=r.."x" - else - r=r.."o" - end - if i%8==7 then - print(i-7 .."->"..r) - r="" - end - end - print("Type number to flip, or 'q' to quit.") - q=io.stdin:read() - n2=tonumber(q) - if n2~=nil then - - flg:flip(n2) - engine.poke(offflgs,myflag_pattern,flg) - end - until q=='q' -end -function tools.hostilate() - vector=engine.peek(offsets.getEx("CreatureVec"),ptr_vector) - id=engine.peekd(offsets.getEx("CreaturePtr")) - print(string.format("Vec:%d cr:%d",vector:size(),id)) - off=vector:getval(id) - crciv=engine.peek(off,ptr_Creature.civ) - print("Creatures civ:"..crciv) - curciv=engine.peekd(offsets.getEx("CurrentRace")-12) - print("My civ:"..curciv) - if curciv==crciv then - print("Friendly-making enemy") - engine.poke(off,ptr_Creature.civ,-1) - flg=engine.peek(off,ptr_Creature.flags) - flg:set(17,0) - print("flag 51:"..tostring(flg:get(51))) - engine.poke(off,ptr_Creature.flags,flg) - else - print("Enemy- making friendly") - engine.poke(off,ptr_Creature.civ,curciv) - flg=engine.peek(off,ptr_Creature.flags) - flg:set(17,1) - flg:set(19,0) - engine.poke(off,ptr_Creature.flags,flg) - end -end -function tools.mouseBlock() - local xs,ys,zs - xs,ys,zs=getxyz() - xs=math.floor(xs/16) - ys=math.floor(ys/16) - print("Mouse block is:"..xs.." "..ys.." "..zs) -end -function tools.protectsite() - local mapoffset=offsets.getEx("WorldData")--0x131C128+offsets.base() - local x=engine.peek(mapoffset+24,DWORD) - local y=engine.peek(mapoffset+28,DWORD) - local z=engine.peek(mapoffset+32,DWORD) - --vec=engine.peek(mapoffset,ptr_vector) - - print("Blocks loaded:"..x.." "..y.." "..z) - print("Select type:") - print("1. All (SLOW)") - print("2. range (x0 x1 y0 y1 z0 z1)") - print("3. One block around pointer") - print("anything else- quit") - q=io.stdin:read() - n2=tonumber(q) - if n2==nil then return end - if n2>3 or n2<1 then return end - local xs,xe,ys,ye,zs,ze - if n2==1 then - xs=0 - xe=x-1 - ys=0 - ye=y-1 - zs=0 - ze=z-1 - elseif n2==2 then - print("enter x0:") - xs=tonumber(io.stdin:read()) - print("enter x1:") - xe=tonumber(io.stdin:read()) - print("enter y0:") - ys=tonumber(io.stdin:read()) - print("enter y1:") - ye=tonumber(io.stdin:read()) - print("enter z0:") - zs=tonumber(io.stdin:read()) - print("enter z1:") - ze=tonumber(io.stdin:read()) - function clamp(t,vmin,vmax) - if t> vmax then return vmax end - if t< vmin then return vmin end - return t - end - xs=clamp(xs,0,x-1) - ys=clamp(ys,0,y-1) - zs=clamp(zs,0,z-1) - xe=clamp(xe,xs,x-1) - ye=clamp(ye,ys,y-1) - ze=clamp(ze,zs,z-1) - else - xs,ys,zs=getxyz() - xs=math.floor(xs/16) - ys=math.floor(ys/16) - xe=xs - ye=ys - ze=zs - end - local xblocks=engine.peek(mapoffset,DWORD) - local flg=bit.lshift(1,14) - for xx=xs,xe do - local yblocks=engine.peek(xblocks+xx*4,DWORD) - for yy=ys,ye do - local zblocks=engine.peek(yblocks+yy*4,DWORD) - for zz=zs,ze do - - - - local myblock=engine.peek(zblocks+zz*4,DWORD) - if myblock~=0 then - for i=0,255 do - local ff=engine.peek(myblock+0x67c+i*4,DWORD) - ff=bit.bor(ff,flg) --set 14 flag to 1 - engine.poke(myblock+0x67c+i*4,DWORD,ff) - end - end - end - print("Blocks done:"..xx.." "..yy) - end - end -end -function tools.fixwarp() - local mapoffset=offsets.getEx("WorldData")--0x131C128+offsets.base() - local x=engine.peek(mapoffset+24,DWORD) - local y=engine.peek(mapoffset+28,DWORD) - local z=engine.peek(mapoffset+32,DWORD) - --vec=engine.peek(mapoffset,ptr_vector) - - print("Blocks loaded:"..x.." "..y.." "..z) - print("Select type:") - print("1. All (SLOW)") - print("2. range (x0 x1 y0 y1 z0 z1)") - print("3. One block around pointer") - print("anything else- quit") - q=io.stdin:read() - n2=tonumber(q) - if n2==nil then return end - if n2>3 or n2<1 then return end - local xs,xe,ys,ye,zs,ze - if n2==1 then - xs=0 - xe=x-1 - ys=0 - ye=y-1 - zs=0 - ze=z-1 - elseif n2==2 then - print("enter x0:") - xs=tonumber(io.stdin:read()) - print("enter x1:") - xe=tonumber(io.stdin:read()) - print("enter y0:") - ys=tonumber(io.stdin:read()) - print("enter y1:") - ye=tonumber(io.stdin:read()) - print("enter z0:") - zs=tonumber(io.stdin:read()) - print("enter z1:") - ze=tonumber(io.stdin:read()) - function clamp(t,vmin,vmax) - if t> vmax then return vmax end - if t< vmin then return vmin end - return t - end - xs=clamp(xs,0,x-1) - ys=clamp(ys,0,y-1) - zs=clamp(zs,0,z-1) - xe=clamp(xe,xs,x-1) - ye=clamp(ye,ys,y-1) - ze=clamp(ze,zs,z-1) - else - xs,ys,zs=getxyz() - xs=math.floor(xs/16) - ys=math.floor(ys/16) - xe=xs - ye=ys - ze=zs - end - local xblocks=engine.peek(mapoffset,DWORD) - local flg=bit.bnot(bit.lshift(1,3)) - for xx=xs,xe do - local yblocks=engine.peek(xblocks+xx*4,DWORD) - for yy=ys,ye do - local zblocks=engine.peek(yblocks+yy*4,DWORD) - for zz=zs,ze do - local myblock=engine.peek(zblocks+zz*4,DWORD) - if myblock~=0 then - for i=0,255 do - local ff=engine.peek(myblock+0x67c+i*4,DWORD) - ff=bit.band(ff,flg) --set 14 flag to 1 - engine.poke(myblock+0x67c+i*4,DWORD,ff) - end - end - end - print("Blocks done:"..xx.." "..yy) - end - end -end if not(FILE) then tools.menu:add("Change site type",tools.changesite) tools.menu:add("Change site flags",tools.changeflags) diff --git a/plugins/Dfusion/luafiles/utils.lua b/plugins/Dfusion/luafiles/utils.lua new file mode 100644 index 000000000..0bc2a27e5 --- /dev/null +++ b/plugins/Dfusion/luafiles/utils.lua @@ -0,0 +1 @@ +function findVectorsSized(size) local ret={} local text=GetTextRegion() for k,v in pairs(offsets.getvectors()) do if GetRegionIn2(k)~=nil then --if v>4 then local tv=engine.peek(k,ptr_vector) if tv:size() == size then print(string.format("%x is size %d",k,size)) table.insert(ret,k) end end end return ret end function findMaterial(mattype,matname) --currently only stones local tbl=BuildMaterialTable() return tbl[matname] end \ No newline at end of file diff --git a/plugins/Dfusion/src/lua_FunctionCall.cpp b/plugins/Dfusion/src/lua_FunctionCall.cpp new file mode 100644 index 000000000..a537edbb5 --- /dev/null +++ b/plugins/Dfusion/src/lua_FunctionCall.cpp @@ -0,0 +1,39 @@ +#include "lua_FunctionCall.h" +using namespace lua; +int lua_FunctionCall(lua_State *L) +{ + lua::state st(L); + FunctionCaller cl(0); + size_t ptr=st.as(1); + int callconv=st.as(2); + vector arguments; + for(int i=3;i(i)); + int ret=cl.CallFunction(ptr,(FunctionCaller::callconv)callconv,arguments); + st.push(ret); + return 1;// dunno if len is needed... +} + +const luaL_Reg lua_functioncall_func[]= +{ + {"call",lua_FunctionCall}, + {NULL,NULL} +}; + +#define __ADDCONST(name) st.push(::FunctionCaller:: name); st.setglobal(#name) +void lua::RegisterFunctionCall(lua::state &st) +{ + st.getglobal("FunctionCall"); + if(st.is()) + { + st.pop(); + st.newtable(); + } + __ADDCONST(STD_CALL); + __ADDCONST(FAST_CALL); + __ADDCONST(THIS_CALL); + __ADDCONST(CDECL_CALL); + lua::RegFunctionsLocal(st, lua_functioncall_func); + st.setglobal("FunctionCall"); +} +#undef __ADDCONST \ No newline at end of file diff --git a/plugins/Dfusion/src/lua_VersionInfo.cpp b/plugins/Dfusion/src/lua_VersionInfo.cpp index 538de7360..d6f90be15 100644 --- a/plugins/Dfusion/src/lua_VersionInfo.cpp +++ b/plugins/Dfusion/src/lua_VersionInfo.cpp @@ -96,6 +96,29 @@ int OffsetGroup::getParent(lua_State *L) st.pcall(2,1); return 1; } +int OffsetGroup::getKeys(lua_State *L) +{ + const char* invalids[]={"notset","invalid","valid"}; + const char* keytypes[]={"offset","address","hexval","string","group"}; + lua::state st(L); + std::vector t= p->getKeys(); + st.newtable(); + for(size_t i=0;igetGroup(st.as(1)); - st.getglobal("OffsetGroup"); - st.getfield("new"); - st.getglobal("OffsetGroup"); - st.pushlightuserdata(t); - st.pcall(2,1); + if(st.as(1)=="") //if no argument, return version info as a groupoffset (dynamic cast) + { + st.getglobal("OffsetGroup"); + st.getfield("new"); + st.getglobal("OffsetGroup"); + st.pushlightuserdata(dynamic_cast(DFHack::Core::getInstance().vinfo)); + st.pcall(2,1); + } + else + { + DFHack::OffsetGroup* t= DFHack::Core::getInstance().vinfo->getGroup(st.as(1)); + st.getglobal("OffsetGroup"); + st.getfield("new"); + st.getglobal("OffsetGroup"); + st.pushlightuserdata(t); + st.pcall(2,1); + } return 1; } static int __lua_getParent(lua_State *S) diff --git a/plugins/autodump.cpp b/plugins/autodump.cpp index 26fe70cc2..3963bf2af 100644 --- a/plugins/autodump.cpp +++ b/plugins/autodump.cpp @@ -8,19 +8,19 @@ #include using namespace std; -#include -#include -#include -#include +#include "Core.h" +#include +#include +#include #include #include #include -#include +#include -#include -#include -#include -#include +#include +#include +#include +#include using namespace DFHack; using MapExtras::Block; diff --git a/plugins/cleaners.cpp b/plugins/cleaners.cpp index b93b18f37..8992b2078 100644 --- a/plugins/cleaners.cpp +++ b/plugins/cleaners.cpp @@ -1,11 +1,11 @@ -#include -#include -#include -#include -#include -#include -#include -#include +#include "Core.h" +#include +#include +#include +#include +#include +#include +#include using namespace DFHack; @@ -27,7 +27,7 @@ DFhackCExport command_result plugin_init ( Core * c, std::vector { commands.clear(); commands.push_back(PluginCommand("clean","Removes contaminants from map tiles, items and creatures.",clean)); - commands.push_back(PluginCommand("spotclean","Cleans map tile under cursor.",spotclean)); + commands.push_back(PluginCommand("spotclean","Cleans map tile under cursor.",spotclean,cursor_hotkey)); return CR_OK; } @@ -165,7 +165,7 @@ command_result cleanunits (Core * c) DFhackCExport command_result spotclean (Core * c, vector & parameters) { - c->Suspend(); + // HOTKEY COMMAND: CORE ALREADY SUSPENDED vector splatter; DFHack::Maps *Mapz = c->getMaps(); DFHack::Gui *Gui = c->getGui(); @@ -173,7 +173,6 @@ DFhackCExport command_result spotclean (Core * c, vector & parameters) if(!Mapz->Start()) { c->con.printerr("Can't init map.\n"); - c->Resume(); return CR_FAILURE; } int32_t cursorX, cursorY, cursorZ; @@ -181,7 +180,6 @@ DFhackCExport command_result spotclean (Core * c, vector & parameters) if(cursorX == -30000) { c->con.printerr("The cursor is not active.\n"); - c->Resume(); return CR_FAILURE; } int32_t blockX = cursorX / 16, blockY = cursorY / 16; @@ -193,7 +191,6 @@ DFhackCExport command_result spotclean (Core * c, vector & parameters) { spatters[i]->intensity[tileX][tileY] = 0; } - c->Resume(); return CR_OK; } diff --git a/plugins/cleanowned.cpp b/plugins/cleanowned.cpp index 4b1b61e63..c7d931676 100644 --- a/plugins/cleanowned.cpp +++ b/plugins/cleanowned.cpp @@ -8,17 +8,17 @@ #include using namespace std; -#include -#include -#include -#include +#include "Core.h" +#include +#include +#include #include #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include using namespace DFHack; DFhackCExport command_result df_cleanowned (Core * c, vector & parameters); diff --git a/plugins/colonies.cpp b/plugins/colonies.cpp index ce8beccb8..6b2d8a1d2 100644 --- a/plugins/colonies.cpp +++ b/plugins/colonies.cpp @@ -1,10 +1,10 @@ -#include -#include -#include -#include +#include "Core.h" +#include +#include +#include #include #include -#include +#include using std::vector; using std::string; diff --git a/plugins/deramp.cpp b/plugins/deramp.cpp index 0aab27d20..c5b1c8558 100644 --- a/plugins/deramp.cpp +++ b/plugins/deramp.cpp @@ -7,12 +7,12 @@ #include #include using namespace std; -#include -#include -#include -#include -#include -#include +#include "Core.h" +#include +#include +#include +#include +#include using namespace DFHack; DFhackCExport command_result df_deramp (Core * c, vector & parameters); diff --git a/plugins/devel/buildprobe.cpp b/plugins/devel/buildprobe.cpp index 0c7fbb7fd..9893705de 100644 --- a/plugins/devel/buildprobe.cpp +++ b/plugins/devel/buildprobe.cpp @@ -1,13 +1,13 @@ //Quick building occupancy flag test. //Individual bits had no apparent meaning. Assume it's an enum, set by number. -#include -#include -#include -#include -#include -#include -#include +#include "Core.h" +#include +#include +#include +#include +#include +#include #include #include #include diff --git a/plugins/devel/itemhacks.cpp b/plugins/devel/itemhacks.cpp index d9f045a13..0dbc94d58 100644 --- a/plugins/devel/itemhacks.cpp +++ b/plugins/devel/itemhacks.cpp @@ -1,8 +1,8 @@ -#include -#include -#include -#include -#include +#include "Core.h" +#include +#include +#include +#include #include #include #include diff --git a/plugins/devel/kittens.cpp b/plugins/devel/kittens.cpp index 7c502143c..c202331f3 100644 --- a/plugins/devel/kittens.cpp +++ b/plugins/devel/kittens.cpp @@ -1,13 +1,13 @@ -#include -#include -#include -#include +#include "Core.h" +#include "Console.h" +#include "Export.h" +#include "PluginManager.h" +#include "MiscUtils.h" #include #include -#include "dfhack/extra/stopwatch.h" -#include "dfhack/modules/Maps.h" -#include "dfhack/modules/Items.h" -#include +#include "modules/Maps.h" +#include "modules/Items.h" +#include #include using std::vector; @@ -329,8 +329,8 @@ DFhackCExport command_result kittens (Core * c, vector & parameters) } } -#include "dfhack/modules/Units.h" -#include "dfhack/VersionInfo.h" +#include "modules/Units.h" +#include "VersionInfo.h" #include command_result test_creature_offsets(Core* c, vector< string >& parameters) diff --git a/plugins/devel/memview.cpp b/plugins/devel/memview.cpp index 02727a485..a5c721101 100644 --- a/plugins/devel/memview.cpp +++ b/plugins/devel/memview.cpp @@ -1,194 +1,194 @@ -#include -#include -#include -#include -#include -#include <../depends/tthread/tinythread.h> //not sure if correct -#include -#include -#include - -using std::vector; -using std::string; -using namespace DFHack; - -uint64_t timeLast=0; -static tthread::mutex* mymutex=0; - -struct memory_data -{ - size_t addr; - size_t len; - size_t refresh; - int state; - uint8_t *buf,*lbuf; - vector ranges; -}memdata; -enum HEXVIEW_STATES -{ - STATE_OFF,STATE_ON -}; -DFhackCExport command_result memview (Core * c, vector & parameters); - -DFhackCExport const char * plugin_name ( void ) -{ - return "memview"; -} - -DFhackCExport command_result plugin_init ( Core * c, std::vector &commands) -{ - commands.clear(); - commands.push_back(PluginCommand("memview","Shows memory in real time. Params: adrr length refresh_rate. If addr==0 then stop viewing",memview)); - memdata.state=STATE_OFF; - mymutex=new tthread::mutex; - return CR_OK; -} -size_t convert(const std::string& p,bool ishex=false) -{ - size_t ret; - std::stringstream conv; - if(ishex) - conv<>ret; - return ret; -} -bool isAddr(uint32_t *trg,vector & ranges) -{ - if(trg[0]%4==0) - for(size_t i=0;i & ranges) -{ +#include "Core.h" +#include "Console.h" +#include "PluginManager.h" +#include "MemAccess.h" +#include "MiscUtils.h" +#include <../depends/tthread/tinythread.h> //not sure if correct +#include +#include +#include + +using std::vector; +using std::string; +using namespace DFHack; + +uint64_t timeLast=0; +static tthread::mutex* mymutex=0; + +struct memory_data +{ + size_t addr; + size_t len; + size_t refresh; + int state; + uint8_t *buf,*lbuf; + vector ranges; +}memdata; +enum HEXVIEW_STATES +{ + STATE_OFF,STATE_ON +}; +DFhackCExport command_result memview (Core * c, vector & parameters); + +DFhackCExport const char * plugin_name ( void ) +{ + return "memview"; +} + +DFhackCExport command_result plugin_init ( Core * c, std::vector &commands) +{ + commands.clear(); + commands.push_back(PluginCommand("memview","Shows memory in real time. Params: adrr length refresh_rate. If addr==0 then stop viewing",memview)); + memdata.state=STATE_OFF; + mymutex=new tthread::mutex; + return CR_OK; +} +size_t convert(const std::string& p,bool ishex=false) +{ + size_t ret; + std::stringstream conv; + if(ishex) + conv<>ret; + return ret; +} +bool isAddr(uint32_t *trg,vector & ranges) +{ + if(trg[0]%4==0) + for(size_t i=0;i & ranges) +{ Console &con=c->con; - const size_t page_size=16; - con.clear(); - - for(size_t i=0;i31)&&(buf[j+i]<128)) //only printable ascii - con.print("%c",buf[j+i]); - else - con.print("."); - //con.print("\n"); + //TODO make something better? + } + if(lbuf[j+i]!=buf[j+i]) + con.print("*%02X",buf[j+i]); //if modfied show a star + else + con.print(" %02X",buf[j+i]); + } + con.reset_color(); + con.print(" | "); + for(size_t j=0;(j31)&&(buf[j+i]<128)) //only printable ascii + con.print("%c",buf[j+i]); + else + con.print("."); + //con.print("\n"); } - con.print("\n"); - con.flush(); - -} -void Deinit() -{ - if(memdata.state==STATE_ON) - { - memdata.state=STATE_OFF; - delete [] memdata.buf; - delete [] memdata.lbuf; - } -} -DFhackCExport command_result plugin_onupdate ( Core * c ) -{ - - mymutex->lock(); - if(memdata.state==STATE_OFF) - { - mymutex->unlock(); - return CR_OK; - } - //Console &con=c->con; - uint64_t time2 = GetTimeMs64(); - uint64_t delta = time2-timeLast; - - if(memdata.refresh!=0) - if(deltaunlock(); - return CR_OK; - } - timeLast = time2; - - c->p->read(memdata.addr,memdata.len,memdata.buf); - outputHex(memdata.buf,memdata.lbuf,memdata.len,memdata.addr,c,memdata.ranges); - memcpy(memdata.lbuf, memdata.buf, memdata.len); - if(memdata.refresh==0) - Deinit(); - mymutex->unlock(); - return CR_OK; - -} -DFhackCExport command_result memview (Core * c, vector & parameters) -{ - mymutex->lock(); - c->p->getMemRanges(memdata.ranges); - memdata.addr=convert(parameters[0],true); - if(memdata.addr==0) - { - Deinit(); - memdata.state=STATE_OFF; - mymutex->unlock(); - return CR_OK; - } - else - { - Deinit(); - bool isValid=false; - for(size_t i=0;icon.printerr("Invalid address:%x\n",memdata.addr); - mymutex->unlock(); - return CR_OK; - } - memdata.state=STATE_ON; - } - if(parameters.size()>1) - memdata.len=convert(parameters[1]); - else - memdata.len=20*16; - - if(parameters.size()>2) - memdata.refresh=convert(parameters[2]); - else - memdata.refresh=0; - - - uint8_t *buf,*lbuf; - memdata.buf=new uint8_t[memdata.len]; - memdata.lbuf=new uint8_t[memdata.len]; - c->p->getMemRanges(memdata.ranges); - mymutex->unlock(); - return CR_OK; -} -DFhackCExport command_result plugin_shutdown ( Core * c ) -{ - mymutex->lock(); - Deinit(); - delete mymutex; - mymutex->unlock(); - return CR_OK; -} + con.print("\n"); + con.flush(); + +} +void Deinit() +{ + if(memdata.state==STATE_ON) + { + memdata.state=STATE_OFF; + delete [] memdata.buf; + delete [] memdata.lbuf; + } +} +DFhackCExport command_result plugin_onupdate ( Core * c ) +{ + + mymutex->lock(); + if(memdata.state==STATE_OFF) + { + mymutex->unlock(); + return CR_OK; + } + //Console &con=c->con; + uint64_t time2 = GetTimeMs64(); + uint64_t delta = time2-timeLast; + + if(memdata.refresh!=0) + if(deltaunlock(); + return CR_OK; + } + timeLast = time2; + + c->p->read(memdata.addr,memdata.len,memdata.buf); + outputHex(memdata.buf,memdata.lbuf,memdata.len,memdata.addr,c,memdata.ranges); + memcpy(memdata.lbuf, memdata.buf, memdata.len); + if(memdata.refresh==0) + Deinit(); + mymutex->unlock(); + return CR_OK; + +} +DFhackCExport command_result memview (Core * c, vector & parameters) +{ + mymutex->lock(); + c->p->getMemRanges(memdata.ranges); + memdata.addr=convert(parameters[0],true); + if(memdata.addr==0) + { + Deinit(); + memdata.state=STATE_OFF; + mymutex->unlock(); + return CR_OK; + } + else + { + Deinit(); + bool isValid=false; + for(size_t i=0;icon.printerr("Invalid address:%x\n",memdata.addr); + mymutex->unlock(); + return CR_OK; + } + memdata.state=STATE_ON; + } + if(parameters.size()>1) + memdata.len=convert(parameters[1]); + else + memdata.len=20*16; + + if(parameters.size()>2) + memdata.refresh=convert(parameters[2]); + else + memdata.refresh=0; + + + uint8_t *buf,*lbuf; + memdata.buf=new uint8_t[memdata.len]; + memdata.lbuf=new uint8_t[memdata.len]; + c->p->getMemRanges(memdata.ranges); + mymutex->unlock(); + return CR_OK; +} +DFhackCExport command_result plugin_shutdown ( Core * c ) +{ + mymutex->lock(); + Deinit(); + delete mymutex; + mymutex->unlock(); + return CR_OK; +} diff --git a/plugins/devel/notes.cpp b/plugins/devel/notes.cpp index 32b436121..412f64476 100644 --- a/plugins/devel/notes.cpp +++ b/plugins/devel/notes.cpp @@ -1,10 +1,10 @@ -#include -#include -#include -#include +#include "Core.h" +#include +#include +#include #include #include -#include +#include using std::vector; using std::string; diff --git a/plugins/devel/rawdump.cpp b/plugins/devel/rawdump.cpp index 0e6cac5bd..2ad840b78 100644 --- a/plugins/devel/rawdump.cpp +++ b/plugins/devel/rawdump.cpp @@ -1,10 +1,10 @@ -#include -#include -#include -#include +#include "Core.h" +#include +#include +#include #include #include -#include +#include #include using std::vector; diff --git a/plugins/devel/tiles.cpp b/plugins/devel/tiles.cpp index fc83f1891..d6ca4cbd1 100644 --- a/plugins/devel/tiles.cpp +++ b/plugins/devel/tiles.cpp @@ -7,15 +7,15 @@ using std::vector; using std::string; -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "Core.h" +#include +#include +#include +#include +#include +#include +#include +#include using namespace MapExtras; using namespace DFHack; diff --git a/plugins/devel/vectors.cpp b/plugins/devel/vectors.cpp index 320f55c00..216b69868 100644 --- a/plugins/devel/vectors.cpp +++ b/plugins/devel/vectors.cpp @@ -3,11 +3,11 @@ // // Linux only, enabled with BUILD_VECTORS cmake option. -#include -#include -#include -#include -#include +#include "Core.h" +#include +#include +#include +#include #include #include diff --git a/plugins/df2mc b/plugins/df2mc index 8ffad5163..355674a50 160000 --- a/plugins/df2mc +++ b/plugins/df2mc @@ -1 +1 @@ -Subproject commit 8ffad51635ceeae55870106a75f3dd84b044ea5a +Subproject commit 355674a508d72349983455f04791b4481b6c1515 diff --git a/plugins/drybuckets.cpp b/plugins/drybuckets.cpp index 245661736..0ea079c0c 100644 --- a/plugins/drybuckets.cpp +++ b/plugins/drybuckets.cpp @@ -7,14 +7,14 @@ #include using namespace std; -#include -#include -#include -#include +#include "Core.h" +#include +#include +#include #include #include #include -#include +#include using namespace DFHack; diff --git a/plugins/fastdwarf.cpp b/plugins/fastdwarf.cpp index 534e34614..38b7f312d 100644 --- a/plugins/fastdwarf.cpp +++ b/plugins/fastdwarf.cpp @@ -8,12 +8,12 @@ #include #include using namespace std; -#include -#include -#include -#include -#include -#include +#include "Core.h" +#include +#include +#include +#include +#include using namespace DFHack; // dfhack interface diff --git a/plugins/filltraffic.cpp b/plugins/filltraffic.cpp index c27029a85..a5c2188fe 100644 --- a/plugins/filltraffic.cpp +++ b/plugins/filltraffic.cpp @@ -1,22 +1,37 @@ // Wide-area traffic designation utility. // Flood-fill from cursor or fill entire map. -#include //For toupper(). +#include //For toupper(). +#include //for min(). #include #include -#include -#include -#include -#include -#include -#include -#include +#include "Core.h" +#include +#include +#include +#include +#include +#include using std::stack; using MapExtras::MapCache; using namespace DFHack; +//Function pointer type for whole-map tile checks. +typedef void (*checkTile)(DFHack::DFCoord, MapExtras::MapCache *); + +//Forward Declarations for Commands DFhackCExport command_result filltraffic(DFHack::Core * c, std::vector & params); -DFhackCExport command_result tiletraffic(DFHack::Core * c, std::vector & params); +DFhackCExport command_result alltraffic(DFHack::Core * c, std::vector & params); + +//Forward Declarations for Utility Functions +DFhackCExport command_result setAllMatching(DFHack::Core * c, checkTile checkProc, + DFHack::DFCoord minCoord = DFHack::DFCoord(0, 0, 0), + DFHack::DFCoord maxCoord = DFHack::DFCoord(0xFFFF, 0xFFFF, 0xFFFF)); + +void allHigh(DFHack::DFCoord coord, MapExtras::MapCache * map); +void allNormal(DFHack::DFCoord coord, MapExtras::MapCache * map); +void allLow(DFHack::DFCoord coord, MapExtras::MapCache * map); +void allRestricted(DFHack::DFCoord coord, MapExtras::MapCache * map); DFhackCExport const char * plugin_name ( void ) { @@ -27,7 +42,8 @@ DFhackCExport command_result plugin_init ( Core * c, std::vector { commands.clear(); commands.push_back(PluginCommand("filltraffic","Flood-fill with selected traffic designation from cursor",filltraffic)); - commands.push_back(PluginCommand("tiletraffic","Set traffic for all tiles based on given criteria",tiletraffic)); + commands.push_back(PluginCommand("alltraffic","Set traffic for the entire map",alltraffic)); + return CR_OK; } @@ -60,7 +76,7 @@ DFhackCExport command_result filltraffic(DFHack::Core * c, std::vector & params) +DFhackCExport command_result alltraffic(DFHack::Core * c, std::vector & params) { - //Target traffic types. - e_traffic target = traffic_normal; - //!!! Options Later !!! - + void (*proc)(DFHack::DFCoord, MapExtras::MapCache *) = allNormal; + //Loop through parameters for(int i = 0; i < params.size();i++) { @@ -248,19 +262,30 @@ DFhackCExport command_result tiletraffic(DFHack::Core * c, std::vectorSuspend(); @@ -280,27 +305,76 @@ DFhackCExport command_result tiletraffic(DFHack::Core * c, std::vector maxCoord.x) + { + c->con.printerr("Minimum x coordinate is greater than maximum x coordinate.\n"); + c->Resume(); + return CR_FAILURE; + } + if (minCoord.y > maxCoord.y) + { + c->con.printerr("Minimum y coordinate is greater than maximum y coordinate.\n"); + c->Resume(); + return CR_FAILURE; + } + if (minCoord.z > maxCoord.y) + { + c->con.printerr("Minimum z coordinate is greater than maximum z coordinate.\n"); + c->Resume(); + return CR_FAILURE; + } + MapExtras::MapCache * MCache = new MapExtras::MapCache(Maps); - c->con.print("Entire map ... FILLING!\n"); + c->con.print("Setting traffic...\n"); //Loop through every single tile - for(uint32_t x = 0; x <= tx_max; x++) + for(uint32_t x = minCoord.x; x <= maxCoord.x; x++) { - for(uint32_t y = 0; y <= ty_max; y++) + for(uint32_t y = minCoord.y; y <= maxCoord.y; y++) { - for(uint32_t z = 0; z <= z_max; z++) + for(uint32_t z = minCoord.z; z <= maxCoord.z; z++) { DFHack::DFCoord tile = DFHack::DFCoord(x, y, z); - DFHack::t_designation des = MCache->designationAt(tile); - - des.bits.traffic = target; - MCache->setDesignationAt(tile, des); + checkProc(tile, MCache); } } } MCache->WriteAll(); + c->con.print("Complete!\n"); c->Resume(); return CR_OK; +} + +//Unconditionally set map to target traffic type +void allHigh(DFHack::DFCoord coord, MapExtras::MapCache * map) +{ + DFHack::t_designation des = map->designationAt(coord); + des.bits.traffic = traffic_high; + map->setDesignationAt(coord, des); +} +void allNormal(DFHack::DFCoord coord, MapExtras::MapCache * map) +{ + DFHack::t_designation des = map->designationAt(coord); + des.bits.traffic = traffic_normal; + map->setDesignationAt(coord, des); +} +void allLow(DFHack::DFCoord coord, MapExtras::MapCache * map) +{ + DFHack::t_designation des = map->designationAt(coord); + des.bits.traffic = traffic_low; + map->setDesignationAt(coord, des); +} +void allRestricted(DFHack::DFCoord coord, MapExtras::MapCache * map) +{ + DFHack::t_designation des = map->designationAt(coord); + des.bits.traffic = traffic_restricted; + map->setDesignationAt(coord, des); } \ No newline at end of file diff --git a/plugins/fixwagons.cpp b/plugins/fixwagons.cpp new file mode 100644 index 000000000..29253880e --- /dev/null +++ b/plugins/fixwagons.cpp @@ -0,0 +1,110 @@ +// I'll fix his little red wagon... + +#include "Core.h" +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +using std::string; +using std::vector; +using namespace DFHack; + +using df::global::world; +using df::historical_entity; +using df::entity_raw_flags; +using df::creature_raw; +using df::creature_raw_flags; + +command_result df_fixwagons (Core *c, vector ¶meters) +{ + if (!parameters.empty()) + return CR_WRONG_USAGE; + + CoreSuspender suspend(c); + int32_t wagon_creature = -1, wagon_puller_creature = -1; + creature_raw *wagon, *wagon_puller; + for (int i = 0; i < world->raws.creatures.all.size(); i++) + { + creature_raw *cr = world->raws.creatures.all[i]; + if (cr->flags.is_set(creature_raw_flags::EQUIPMENT_WAGON) && (wagon_creature == -1)) + { + wagon = cr; + wagon_creature = i; + } + if ((cr->creature_id == "HORSE") && (wagon_puller_creature == -1)) + { + wagon_puller = cr; + wagon_puller_creature = i; + } + } + if (wagon_creature == -1) + { + c->con.printerr("Couldn't find a valid wagon creature!\n"); + return CR_FAILURE; + } + if (wagon_puller_creature == -1) + { + c->con.printerr("Couldn't find 'HORSE' creature for default wagon puller!\n"); + return CR_FAILURE; + } + int count = 0; + for (int i = 0; i < world->entities.all.size(); i++) + { + bool updated = false; + historical_entity *ent = world->entities.all[i]; + if (!ent->entity_raw->flags.is_set(entity_raw_flags::COMMON_DOMESTIC_PULL)) + continue; + if (ent->resources.animals.wagon_races.size() == 0) + { + updated = true; + for (int j = 0; j < wagon->caste.size(); j++) + { + ent->resources.animals.wagon_races.push_back(wagon_creature); + ent->resources.animals.wagon_castes.push_back(j); + } + } + if (ent->resources.animals.wagon_puller_races.size() == 0) + { + updated = true; + for (int j = 0; j < wagon_puller->caste.size(); j++) + { + ent->resources.animals.wagon_puller_races.push_back(wagon_puller_creature); + ent->resources.animals.wagon_puller_castes.push_back(j); + } + } + if (updated) + count++; + } + if(count) + c->con.print("Fixed %d civilizations to bring wagons once again.\n", count); + return CR_OK; +} + +DFhackCExport const char * plugin_name ( void ) +{ + return "fixwagons"; +} + +DFhackCExport command_result plugin_init ( Core * c, std::vector &commands) +{ + commands.clear(); + commands.push_back(PluginCommand( + "fixwagons", "Fix all civilizations to be able to bring wagons.", + df_fixwagons, false, + " Since DF v0.31.1 merchants no longer bring wagons due to a bug.\n" + " This command re-enables them for all appropriate civilizations.\n" + )); + return CR_OK; +} + +DFhackCExport command_result plugin_shutdown ( Core * c ) +{ + return CR_OK; +} diff --git a/plugins/flows.cpp b/plugins/flows.cpp index b82d01adb..c5b588903 100644 --- a/plugins/flows.cpp +++ b/plugins/flows.cpp @@ -6,11 +6,11 @@ #include #include using namespace std; -#include -#include -#include -#include -#include +#include "Core.h" +#include +#include +#include +#include using namespace DFHack; DFhackCExport command_result df_flows (Core * c, vector & parameters); diff --git a/plugins/getplants.cpp b/plugins/getplants.cpp index dbec990f0..14fb8b90c 100644 --- a/plugins/getplants.cpp +++ b/plugins/getplants.cpp @@ -8,14 +8,14 @@ #include #include -#include -#include -#include -#include -#include -#include -#include -#include +#include "Core.h" +#include +#include +#include +#include +#include +#include +#include using namespace std; using namespace DFHack; diff --git a/plugins/initflags.cpp b/plugins/initflags.cpp index f27a318ae..5671619e8 100644 --- a/plugins/initflags.cpp +++ b/plugins/initflags.cpp @@ -1,10 +1,10 @@ -#include -#include -#include -#include +#include "Core.h" +#include +#include +#include -#include -#include +#include +#include using std::vector; using std::string; @@ -26,8 +26,10 @@ DFhackCExport command_result plugin_init (Core *c, std::vector & { commands.clear(); if (d_init) { - commands.push_back(PluginCommand("twaterlvl", "Toggle display of water/magma depth.", twaterlvl)); - commands.push_back(PluginCommand("tidlers", "Toggle display of idlers.", tidlers)); + commands.push_back(PluginCommand("twaterlvl", "Toggle display of water/magma depth.", + twaterlvl, dwarfmode_hotkey)); + commands.push_back(PluginCommand("tidlers", "Toggle display of idlers.", + tidlers, dwarfmode_hotkey)); } std::cerr << "d_init: " << sizeof(df::d_init) << endl; return CR_OK; @@ -40,21 +42,19 @@ DFhackCExport command_result plugin_shutdown ( Core * c ) DFhackCExport command_result twaterlvl(Core * c, vector & parameters) { - c->Suspend(); + // HOTKEY COMMAND: CORE ALREADY SUSPENDED df::global::d_init->flags1.toggle(d_init_flags1::SHOW_FLOW_AMOUNTS); c->con << "Toggled the display of water/magma depth." << endl; - c->Resume(); return CR_OK; } DFhackCExport command_result tidlers(Core * c, vector & parameters) { - c->Suspend(); + // HOTKEY COMMAND: CORE ALREADY SUSPENDED df::d_init_idlers iv = df::d_init_idlers(int(d_init->idlers) + 1); if (!d_init_idlers::is_valid(iv)) iv = ENUM_FIRST_ITEM(d_init_idlers); d_init->idlers = iv; c->con << "Toggled the display of idlers to " << ENUM_KEY_STR(d_init_idlers, iv) << endl; - c->Resume(); return CR_OK; } diff --git a/plugins/liquids.cpp b/plugins/liquids.cpp index 92067ba7e..17f4e6309 100644 --- a/plugins/liquids.cpp +++ b/plugins/liquids.cpp @@ -9,15 +9,15 @@ using std::string; using std::endl; using std::set; -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "Core.h" +#include +#include +#include +#include +#include +#include +#include +#include using namespace MapExtras; using namespace DFHack; diff --git a/plugins/mode.cpp b/plugins/mode.cpp index 4a64fd2b8..2ca741ae2 100644 --- a/plugins/mode.cpp +++ b/plugins/mode.cpp @@ -1,13 +1,13 @@ #include using namespace std; -#include -#include -#include -#include +#include "Core.h" +#include +#include +#include #include #include -#include +#include #include using namespace DFHack; diff --git a/plugins/plants.cpp b/plugins/plants.cpp index 7afa0d897..4d8960cee 100644 --- a/plugins/plants.cpp +++ b/plugins/plants.cpp @@ -5,15 +5,15 @@ #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "Core.h" +#include +#include +#include +#include +#include +#include +#include +#include using std::vector; using std::string; diff --git a/plugins/probe.cpp b/plugins/probe.cpp index 59588185f..a000d9e31 100644 --- a/plugins/probe.cpp +++ b/plugins/probe.cpp @@ -9,18 +9,18 @@ #include using namespace std; -#include -#include -#include -#include +#include "Core.h" +#include +#include +#include #include #include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include using std::vector; using std::string; diff --git a/plugins/prospector.cpp b/plugins/prospector.cpp index 5e642ed5a..6287734c1 100644 --- a/plugins/prospector.cpp +++ b/plugins/prospector.cpp @@ -14,11 +14,10 @@ using namespace std; #include -#include -#include -#include -#include -#include +#include +#include "Core.h" +#include +#include using namespace DFHack; diff --git a/plugins/qtplug/qtplug.cpp b/plugins/qtplug/qtplug.cpp index 2c6dbf3ad..a33c28ad5 100644 --- a/plugins/qtplug/qtplug.cpp +++ b/plugins/qtplug/qtplug.cpp @@ -1,10 +1,10 @@ -#include -#include -#include -#include -#include -#include -#include +#include "Core.h" +#include +#include +#include +#include +#include +#include #include #include #include diff --git a/plugins/rename.cpp b/plugins/rename.cpp new file mode 100644 index 000000000..17841c5fa --- /dev/null +++ b/plugins/rename.cpp @@ -0,0 +1,90 @@ +#include "Core.h" +#include +#include +#include + +#include +#include +#include +#include + +#include + +using std::vector; +using std::string; +using std::endl; +using namespace DFHack; +using namespace df::enums; + +using df::global::ui; +using df::global::world; + +static command_result rename(Core * c, vector & parameters); + +DFhackCExport const char * plugin_name ( void ) +{ + return "rename"; +} + +DFhackCExport command_result plugin_init (Core *c, std::vector &commands) +{ + commands.clear(); + if (world && ui) { + commands.push_back(PluginCommand("rename", "Rename various things.", rename)); + } + return CR_OK; +} + +DFhackCExport command_result plugin_shutdown ( Core * c ) +{ + return CR_OK; +} + +static command_result usage(Core *c) +{ + c->con << "Usage:" << endl + << " rename squad \"name\"" << endl + << " rename hotkey \"name\"" << endl; + return CR_OK; +} + +static command_result rename(Core * c, vector ¶meters) +{ + CoreSuspender suspend(c); + + string cmd; + if (!parameters.empty()) + cmd = parameters[0]; + + if (cmd == "squad") { + if (parameters.size() != 3) + return usage(c); + + std::vector &squads = world->squads.all; + + int id = atoi(parameters[1].c_str()); + if (id < 1 || id > squads.size()) { + c->con.printerr("Invalid squad index\n"); + return usage(c); + } + + squads[id-1]->alias = parameters[2]; + } else if (cmd == "hotkey") { + if (parameters.size() != 3) + return usage(c); + + int id = atoi(parameters[1].c_str()); + if (id < 1 || id > 16) { + c->con.printerr("Invalid hotkey index\n"); + return usage(c); + } + + ui->main.hotkeys[id-1].name = parameters[2]; + } else { + if (!parameters.empty() && cmd != "?") + c->con.printerr("Invalid command: %s\n", cmd.c_str()); + return usage(c); + } + + return CR_OK; +} diff --git a/plugins/reveal.cpp b/plugins/reveal.cpp index 5d7c1df29..ce37f3f1e 100644 --- a/plugins/reveal.cpp +++ b/plugins/reveal.cpp @@ -2,14 +2,14 @@ #include #include #include -#include -#include -#include -#include -#include -#include -#include -#include +#include "Core.h" +#include +#include +#include +#include +#include +#include +#include using MapExtras::MapCache; using namespace DFHack; diff --git a/plugins/seedwatch.cpp b/plugins/seedwatch.cpp index 418398e3d..3b83338e2 100755 --- a/plugins/seedwatch.cpp +++ b/plugins/seedwatch.cpp @@ -1,19 +1,18 @@ -// This does not work with Linux Dwarf Fortress +// This does not work with Linux Dwarf Fortress // With thanks to peterix for DFHack and Quietust for information http://www.bay12forums.com/smf/index.php?topic=91166.msg2605147#msg2605147 #include #include #include -#include "dfhack/Console.h" -#include "dfhack/Core.h" -#include "dfhack/Export.h" -#include "dfhack/PluginManager.h" -#include "dfhack/Process.h" -#include "dfhack/modules/Materials.h" -#include "dfhack/modules/Items.h" -#include "dfhack/modules/World.h" -#include "dfhack/modules/kitchen.h" -#include +#include "Console.h" +#include "Core.h" +#include "Export.h" +#include "PluginManager.h" +#include "modules/Materials.h" +#include "modules/Items.h" +#include "modules/World.h" +#include "modules/kitchen.h" +#include using DFHack::t_materialType; using DFHack::t_materialIndex; @@ -288,10 +287,32 @@ DFhackCExport DFHack::command_result plugin_init(DFHack::Core* pCore, std::vecto return DFHack::CR_OK; } +DFhackCExport DFHack::command_result plugin_onstatechange(DFHack::Core* pCore, DFHack::state_change_event event) +{ + switch (event) { + case DFHack::SC_GAME_LOADED: + case DFHack::SC_GAME_UNLOADED: + if (running) + pCore->con.printerr("seedwatch deactivated due to game load/unload\n"); + running = false; + break; + default: + break; + } + + return DFHack::CR_OK; +} + DFhackCExport DFHack::command_result plugin_onupdate(DFHack::Core* pCore) { - if(running) + if (running) { + // reduce processing rate + static int counter = 0; + if (++counter < 500) + return DFHack::CR_OK; + counter = 0; + DFHack::Core& core = *pCore; DFHack::World *w = core.getWorld(); DFHack::t_gamemodes gm; diff --git a/plugins/server/main.cpp b/plugins/server/main.cpp index b47128c50..91dabc6f0 100644 --- a/plugins/server/main.cpp +++ b/plugins/server/main.cpp @@ -1,7 +1,7 @@ -#include -#include -#include -#include +#include "Core.h" +#include +#include +#include #include #ifndef LINUX_BUILD #include diff --git a/plugins/skeleton/skeleton.cpp b/plugins/skeleton/skeleton.cpp index d69a2dd95..1b3ad398d 100644 --- a/plugins/skeleton/skeleton.cpp +++ b/plugins/skeleton/skeleton.cpp @@ -1,10 +1,10 @@ // This is a generic plugin that does nothing useful apart from acting as an example... of a plugin that does nothing :D // some headers required for a plugin. Nothing special, just the basics. -#include -#include -#include -#include +#include "Core.h" +#include +#include +#include using namespace DFHack; // our own, empty header. diff --git a/plugins/stockpiles.cpp b/plugins/stockpiles.cpp index 5cd153335..e104ec908 100644 --- a/plugins/stockpiles.cpp +++ b/plugins/stockpiles.cpp @@ -1,12 +1,14 @@ -#include -#include -#include -#include - -#include -#include -#include -#include +#include "Core.h" +#include +#include +#include + +#include +#include +#include +#include +#include +#include using std::vector; using std::string; @@ -16,10 +18,12 @@ using namespace df::enums; using df::global::world; using df::global::ui; +using df::global::selection_rect; using df::building_stockpilest; -DFhackCExport command_result copystock(Core * c, vector & parameters); +static command_result copystock(Core *c, vector & parameters); +static bool copystock_guard(Core *c, df::viewscreen *top); DFhackCExport const char * plugin_name ( void ) { @@ -30,7 +34,16 @@ DFhackCExport command_result plugin_init (Core *c, std::vector & { commands.clear(); if (world && ui) { - commands.push_back(PluginCommand("copystock", "Copy stockpile under cursor.", copystock)); + commands.push_back( + PluginCommand( + "copystock", "Copy stockpile under cursor.", + copystock, copystock_guard, + " - In 'q' or 't' mode: select a stockpile and invoke in order\n" + " to switch to the 'p' stockpile creation mode, and initialize\n" + " the custom settings from the selected stockpile.\n" + " - In 'p': invoke in order to switch back to 'q'.\n" + ) + ); } std::cerr << "world: " << sizeof(df::world) << " ui: " << sizeof(df::ui) << " b_stock: " << sizeof(building_stockpilest) << endl; @@ -42,40 +55,43 @@ DFhackCExport command_result plugin_shutdown ( Core * c ) return CR_OK; } -bool inSelectMode() { +static bool copystock_guard(Core *c, df::viewscreen *top) +{ using namespace ui_sidebar_mode; + if (!dwarfmode_hotkey(c,top)) + return false; + switch (ui->main.mode) { + case Stockpiles: + return true; case BuildingItems: case QueryBuilding: - return true; + return !!virtual_cast(world->selected_building); default: return false; } } -DFhackCExport command_result copystock(Core * c, vector & parameters) +static command_result copystock(Core * c, vector & parameters) { - CoreSuspender suspend(c); + // HOTKEY COMMAND: CORE ALREADY SUSPENDED // For convenience: when used in the stockpiles mode, switch to 'q' if (ui->main.mode == ui_sidebar_mode::Stockpiles) { world->selected_building = NULL; // just in case it contains some kind of garbage ui->main.mode = ui_sidebar_mode::QueryBuilding; + selection_rect->start_x = -30000; c->con << "Switched back to query building." << endl; return CR_OK; } - if (!inSelectMode()) { - c->con << "Cannot copy stockpile in mode " << ENUM_KEY_STR(ui_sidebar_mode, ui->main.mode) << endl; - return CR_OK; - } - building_stockpilest *sp = virtual_cast(world->selected_building); - if (!sp) { - c->con << "Selected building isn't a stockpile." << endl; - return CR_OK; + if (!sp) + { + c->con.printerr("Selected building isn't a stockpile.\n"); + return CR_WRONG_USAGE; } ui->stockpile.custom_settings = sp->settings; diff --git a/plugins/stonesense b/plugins/stonesense index dbfeaf935..1b28039e2 160000 --- a/plugins/stonesense +++ b/plugins/stonesense @@ -1 +1 @@ -Subproject commit dbfeaf935df92644b72746842166baf700450e15 +Subproject commit 1b28039e2c93daa3c2f69f5e2a000ff8c96ee1f8 diff --git a/plugins/tiletypes.cpp b/plugins/tiletypes.cpp index e15d787f7..57184f013 100644 --- a/plugins/tiletypes.cpp +++ b/plugins/tiletypes.cpp @@ -10,15 +10,15 @@ using std::string; using std::endl; using std::set; -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "Core.h" +#include +#include +#include +#include +#include +#include +#include +#include using namespace MapExtras; using namespace DFHack; @@ -63,6 +63,7 @@ struct TileType DFHack::TileMaterial material; DFHack::TileSpecial special; DFHack::TileVariant variant; + int dig; int hidden; int light; int subterranean; @@ -74,6 +75,7 @@ struct TileType material = DFHack::tilematerial_invalid; special = DFHack::tilespecial_invalid; variant = DFHack::tilevariant_invalid; + dig = -1; hidden = -1; light = -1; subterranean = -1; @@ -83,7 +85,8 @@ struct TileType bool empty() { return shape == -1 && material == -1 && special == -1 && variant == -1 - && hidden == -1 && light == -1 && subterranean == -1 && skyview == -1; + && hidden == -1 && light == -1 && subterranean == -1 && skyview == -1 + && dig == -1; } }; @@ -138,6 +141,19 @@ std::ostream &operator<<(std::ostream &stream, const TileType &paint) needSpace = true; } + if (paint.dig >= 0) + { + if (needSpace) + { + stream << " "; + needSpace = false; + } + + stream << (paint.dig ? "DESIGNATED" : "UNDESIGATNED"); + used = true; + needSpace = true; + } + if (paint.hidden >= 0) { if (needSpace) @@ -300,6 +316,18 @@ bool processTileType(TileType &paint, const std::string &option, const std::stri std::cout << "Unknown tile variant: " << value << std::endl; } } + else if (option == "designated" || option == "d") + { + if (valInt >= -1 && valInt < 2) + { + paint.dig = valInt; + found = true; + } + else + { + std::cout << "Unknown designation flag: " << value << std::endl; + } + } else if (option == "hidden" || option == "h") { if (valInt >= -1 && valInt < 2) @@ -374,6 +402,7 @@ void help( std::ostream & out, const std::string &option) << " Material / mat / m: set tile material information" << std::endl << " Special / sp: set special tile information" << std::endl << " Variant / var / v: set variant tile information" << std::endl + << " Designated / d: set designated flag" << std::endl << " Hidden / h: set hidden flag" << std::endl << " Light / l: set light flag" << std::endl << " Subterranean / st: set subterranean flag" << std::endl @@ -412,6 +441,11 @@ void help( std::ostream & out, const std::string &option) out << "Available variants:" << std::endl << " ANY, 0 - " << DFHack::VAR_4 << std::endl; } + else if (option == "designated" || option == "d") + { + out << "Available designated flags:" << std::endl + << " ANY, 0, 1" << std::endl; + } else if (option == "hidden" || option == "h") { out << "Available hidden flags:" << std::endl @@ -746,11 +780,13 @@ DFhackCExport command_result df_tiletypes (Core * c, vector & parameter for (coord_vec::iterator iter = all_tiles.begin(); iter != all_tiles.end(); ++iter) { const DFHack::TileRow *source = DFHack::getTileRow(map.tiletypeAt(*iter)); + DFHack::t_designation des = map.designationAt(*iter); if ((filter.shape > -1 && filter.shape != source->shape) || (filter.material > -1 && filter.material != source->material) || (filter.special > -1 && filter.special != source->special) || (filter.variant > -1 && filter.variant != source->variant) + || (filter.dig > -1 && (filter.dig != 0) != (des.bits.dig != DFHack::designation_no)) ) { continue; @@ -812,8 +848,6 @@ DFhackCExport command_result df_tiletypes (Core * c, vector & parameter if(type != -1) map.setTiletypeAt(*iter, type); - DFHack::t_designation des = map.designationAt(*iter); - if (paint.hidden > -1) { des.bits.hidden = paint.hidden; diff --git a/plugins/tubefill.cpp b/plugins/tubefill.cpp index 1249c20fb..23e6e992a 100644 --- a/plugins/tubefill.cpp +++ b/plugins/tubefill.cpp @@ -4,14 +4,14 @@ #include #include #include -#include -#include -#include -#include -#include -#include -#include -#include +#include "Core.h" +#include +#include +#include +#include +#include +#include +#include using MapExtras::MapCache; using namespace DFHack; diff --git a/plugins/vdig.cpp b/plugins/vdig.cpp index e9cc0db3a..290b3b933 100644 --- a/plugins/vdig.cpp +++ b/plugins/vdig.cpp @@ -1,10 +1,10 @@ -#include -#include -#include -#include -#include -#include -#include +#include "Core.h" +#include +#include +#include +#include +#include +#include #include #include #include @@ -30,8 +30,17 @@ DFhackCExport const char * plugin_name ( void ) DFhackCExport command_result plugin_init ( Core * c, std::vector &commands) { commands.clear(); - commands.push_back(PluginCommand("vdig","Dig a whole vein.",vdig)); - commands.push_back(PluginCommand("vdigx","Dig a whole vein, follow vein through z-levels with stairs.",vdigx)); + commands.push_back(PluginCommand( + "vdig","Dig a whole vein.",vdig,cursor_hotkey, + " Designates a whole vein under the cursor for digging.\n" + "Options:\n" + " x - follow veins through z-levels with stairs.\n" + )); + commands.push_back(PluginCommand( + "vdigx","Dig a whole vein, following through z-levels.",vdigx,cursor_hotkey, + " Designates a whole vein under the cursor for digging.\n" + " Also follows the vein between z-levels with stairs, like 'vdig x' would.\n" + )); commands.push_back(PluginCommand("expdig","Select or designate an exploratory pattern. Use 'expdig ?' for help.",expdig)); commands.push_back(PluginCommand("digcircle","Dig desingate a circle (filled or hollow) with given radius.",digcircle)); //commands.push_back(PluginCommand("autodig","Mark a tile for continuous digging.",autodig)); @@ -760,18 +769,10 @@ DFhackCExport command_result expdig (Core * c, vector & parameters) c->Resume(); return CR_OK; } + DFhackCExport command_result vdigx (Core * c, vector & parameters) { - for(int i = 0; i < parameters.size();i++) - { - if(parameters[i] == "help" || parameters[i] == "?") - { - c->con.print("Designates a whole vein under the cursor for digging.\n" - "Also follows the vein between z-levels with stairs, like 'vdig x' would.\n" - ); - return CR_OK; - } - } + // HOTKEY COMMAND: CORE ALREADY SUSPENDED vector lol; lol.push_back("x"); return vdig(c,lol); @@ -779,32 +780,25 @@ DFhackCExport command_result vdigx (Core * c, vector & parameters) DFhackCExport command_result vdig (Core * c, vector & parameters) { + // HOTKEY COMMAND: CORE ALREADY SUSPENDED uint32_t x_max,y_max,z_max; bool updown = false; for(int i = 0; i < parameters.size();i++) { if(parameters.size() && parameters[0]=="x") updown = true; - else if(parameters[i] == "help" || parameters[i] == "?") - { - c->con.print("Designates a whole vein under the cursor for digging.\n" - "Options:\n" - "x - follow veins through z-levels with stairs.\n" - ); - return CR_OK; - } + else + return CR_WRONG_USAGE; } Console & con = c->con; - c->Suspend(); DFHack::Maps * Maps = c->getMaps(); DFHack::Gui * Gui = c->getGui(); // init the map if(!Maps->Start()) { con.printerr("Can't init map. Make sure you have a map loaded in DF.\n"); - c->Resume(); return CR_FAILURE; } @@ -816,14 +810,12 @@ DFhackCExport command_result vdig (Core * c, vector & parameters) while(cx == -30000) { con.printerr("Cursor is not active. Point the cursor at a vein.\n"); - c->Resume(); return CR_FAILURE; } DFHack::DFCoord xy ((uint32_t)cx,(uint32_t)cy,cz); if(xy.x == 0 || xy.x == tx_max - 1 || xy.y == 0 || xy.y == ty_max - 1) { con.printerr("I won't dig the borders. That would be cheating!\n"); - c->Resume(); return CR_FAILURE; } MapExtras::MapCache * MCache = new MapExtras::MapCache(Maps); @@ -834,7 +826,6 @@ DFhackCExport command_result vdig (Core * c, vector & parameters) { con.printerr("This tile is not a vein.\n"); delete MCache; - c->Resume(); return CR_FAILURE; } con.print("%d/%d/%d tiletype: %d, veinmat: %d, designation: 0x%x ... DIGGING!\n", cx,cy,cz, tt, veinmat, des.whole); @@ -944,7 +935,6 @@ DFhackCExport command_result vdig (Core * c, vector & parameters) } } MCache->WriteAll(); - c->Resume(); return CR_OK; } diff --git a/plugins/versionosd.cpp b/plugins/versionosd.cpp index 466c4a45b..5f4ff11a8 100644 --- a/plugins/versionosd.cpp +++ b/plugins/versionosd.cpp @@ -7,12 +7,12 @@ #include #include using namespace std; -#include -#include -#include -#include -#include -#include +#include "Core.h" +#include +#include +#include +#include +#include using namespace DFHack; DFhackCExport command_result df_versionosd (Core * c, vector & parameters); diff --git a/plugins/weather.cpp b/plugins/weather.cpp index d01bfcb7b..0f2325d48 100644 --- a/plugins/weather.cpp +++ b/plugins/weather.cpp @@ -1,10 +1,10 @@ -#include -#include -#include -#include +#include "Core.h" +#include +#include +#include #include #include -#include +#include using std::vector; using std::string; diff --git a/tools/examples/dfitemdump.cpp b/tools/examples/dfitemdump.cpp index a19c19734..655caf409 100644 --- a/tools/examples/dfitemdump.cpp +++ b/tools/examples/dfitemdump.cpp @@ -12,7 +12,7 @@ using namespace std; #define DFHACK_WANT_MISCUTILS #include -#include +#include int main (int argc, char *argv[]) { diff --git a/tools/examples/processenum.cpp b/tools/examples/processenum.cpp index 425b247e4..ff15c8645 100644 --- a/tools/examples/processenum.cpp +++ b/tools/examples/processenum.cpp @@ -9,7 +9,7 @@ using namespace std; #include -#include +#include using namespace DFHack; #ifndef LINUX_BUILD #endif diff --git a/tools/playground/blockflags.cpp b/tools/playground/blockflags.cpp index f46f66407..f78a8894e 100644 --- a/tools/playground/blockflags.cpp +++ b/tools/playground/blockflags.cpp @@ -6,8 +6,8 @@ using namespace std; #include -#include -#include +#include +#include int main(int argc, char *argv[]) diff --git a/tools/playground/copypaste.cpp b/tools/playground/copypaste.cpp index cc32c872f..4f584241e 100644 --- a/tools/playground/copypaste.cpp +++ b/tools/playground/copypaste.cpp @@ -13,7 +13,7 @@ #define DFHACK_WANT_MISCUTILS #define DFHACK_WANT_TILETYPES #include -#include "dfhack/modules/WindowIO.h" +#include "modules/WindowIO.h" using namespace DFHack; //bool waitTillCursorState(DFHack::Context *DF, bool On); diff --git a/tools/playground/creaturemanager.cpp b/tools/playground/creaturemanager.cpp index 59e94e9fc..0d65e9f6e 100644 --- a/tools/playground/creaturemanager.cpp +++ b/tools/playground/creaturemanager.cpp @@ -70,7 +70,7 @@ using namespace std; #define DFHACK_WANT_MISCUTILS #include -#include +#include /* Note about magic numbers: * If you have an idea how to better solve this, tell me. Currently I'd be diff --git a/tools/playground/digger.cpp b/tools/playground/digger.cpp index 16a90b682..86a9b84b2 100644 --- a/tools/playground/digger.cpp +++ b/tools/playground/digger.cpp @@ -13,7 +13,7 @@ using namespace std; #include -#include +#include #include // counts the occurances of a certain element in a vector diff --git a/tools/playground/digger2.cpp b/tools/playground/digger2.cpp index 80f202aa5..ea34b8c2c 100644 --- a/tools/playground/digger2.cpp +++ b/tools/playground/digger2.cpp @@ -22,7 +22,7 @@ using namespace std; #include -#include +#include #define BLOCK_SIZE 16 diff --git a/tools/playground/digpattern.cpp b/tools/playground/digpattern.cpp index f49df96c6..90d960ba1 100644 --- a/tools/playground/digpattern.cpp +++ b/tools/playground/digpattern.cpp @@ -9,7 +9,7 @@ using namespace std; #include -#include +#include using namespace MapExtras; //#include diff --git a/tools/playground/drawtile.cpp b/tools/playground/drawtile.cpp index 8610d7f0c..72f2beb0f 100644 --- a/tools/playground/drawtile.cpp +++ b/tools/playground/drawtile.cpp @@ -11,7 +11,7 @@ using namespace std; #include -#include +#include //Avoid including Windows.h because it causes name clashes extern "C" __declspec(dllimport) void __stdcall Sleep(unsigned long milliseconds); diff --git a/tools/playground/hellhole.cpp b/tools/playground/hellhole.cpp index ac7781a7c..a38d14cbf 100644 --- a/tools/playground/hellhole.cpp +++ b/tools/playground/hellhole.cpp @@ -16,8 +16,8 @@ using namespace std; #include -#include -#include +#include +#include using namespace DFHack; diff --git a/tools/playground/itemdesignator.cpp b/tools/playground/itemdesignator.cpp index a1211c013..63b41eb72 100644 --- a/tools/playground/itemdesignator.cpp +++ b/tools/playground/itemdesignator.cpp @@ -8,7 +8,7 @@ using namespace std; #include -#include +#include using namespace DFHack; int main () diff --git a/tools/playground/printtiletypes.cpp b/tools/playground/printtiletypes.cpp index 48fb35a44..6d37e0a1b 100644 --- a/tools/playground/printtiletypes.cpp +++ b/tools/playground/printtiletypes.cpp @@ -11,7 +11,7 @@ using namespace std; #include -#include +#include using namespace DFHack; diff --git a/tools/playground/renamer.cpp b/tools/playground/renamer.cpp index 8b3be7eb8..e82fd691e 100644 --- a/tools/playground/renamer.cpp +++ b/tools/playground/renamer.cpp @@ -8,9 +8,9 @@ using namespace std; #define DFHACK_WANT_MISCUTILS #include -#include -#include -#include +#include +#include +#include vector< vector > englishWords; vector< vector > foreignWords; diff --git a/tools/playground/veinswap.cpp b/tools/playground/veinswap.cpp index 47b83bb82..668386100 100644 --- a/tools/playground/veinswap.cpp +++ b/tools/playground/veinswap.cpp @@ -9,8 +9,8 @@ using namespace std; #include #include -#include -#include +#include +#include //Globals diff --git a/tools/supported/dfstatus.cpp b/tools/supported/dfstatus.cpp index 0ae2b3447..91c6f6589 100644 --- a/tools/supported/dfstatus.cpp +++ b/tools/supported/dfstatus.cpp @@ -24,8 +24,8 @@ #include using namespace std; #include -#include -#include +#include +#include WINDOW *create_newwin(int height, int width, int starty, int startx); diff --git a/tools/supported/lair.cpp b/tools/supported/lair.cpp index a0427f7c2..7bf3ddc28 100644 --- a/tools/supported/lair.cpp +++ b/tools/supported/lair.cpp @@ -5,7 +5,7 @@ #include using namespace std; #include -#include +#include int main (void) { diff --git a/tools/supported/position.cpp b/tools/supported/position.cpp index ca90b2532..1bf6cf098 100644 --- a/tools/supported/position.cpp +++ b/tools/supported/position.cpp @@ -7,7 +7,7 @@ using namespace std; #include -#include +#include std::ostream &operator<<(std::ostream &stream, DFHack::t_gamemodes funzies) { const char * gm[]=