From e206c242c6b7011f424e0da975d7aeb2d0b450d5 Mon Sep 17 00:00:00 2001 From: lethosor Date: Tue, 2 Dec 2014 21:29:13 -0500 Subject: [PATCH 1/6] Add a plugin_globals vector to aid in safety checks for plugins that require globals This allows "using df::global::foo" to be replaced by "REQUIRE_GLOBAL(foo)", and DFHack will refuse to load the plugin if df::global::foo is NULL --- library/PluginManager.cpp | 25 +++++++++++++++++++++++-- library/include/PluginManager.h | 10 +++++++++- plugins/3dveins.cpp | 7 +++---- 3 files changed, 35 insertions(+), 7 deletions(-) diff --git a/library/PluginManager.cpp b/library/PluginManager.cpp index ad390d507..713c442c3 100644 --- a/library/PluginManager.cpp +++ b/library/PluginManager.cpp @@ -30,6 +30,7 @@ distribution. #include "RemoteServer.h" #include "Console.h" #include "Types.h" +#include "VersionInfo.h" #include "DataDefs.h" #include "MiscUtils.h" @@ -167,6 +168,7 @@ Plugin::Plugin(Core * core, const std::string & filepath, const std::string & _f } plugin_lib = 0; plugin_init = 0; + plugin_globals = 0; plugin_shutdown = 0; plugin_status = 0; plugin_onupdate = 0; @@ -235,13 +237,32 @@ bool Plugin::load(color_ostream &con) *plug_self = this; RefAutolock lock(access); plugin_init = (command_result (*)(color_ostream &, std::vector &)) LookupPlugin(plug, "plugin_init"); - if(!plugin_init) + std::vector** plugin_globals_ptr = (std::vector**) LookupPlugin(plug, "plugin_globals"); + if(!plugin_init || !plugin_globals_ptr) { - con.printerr("Plugin %s has no init function.\n", filename.c_str()); + con.printerr("Plugin %s has no init function or globals vector.\n", filename.c_str()); ClosePlugin(plug); state = PS_BROKEN; return false; } + plugin_globals = *plugin_globals_ptr; + if (plugin_globals->size()) + { + std::vector missing_globals; + for (auto it = plugin_globals->begin(); it != plugin_globals->end(); ++it) + { + if (!Core::getInstance().vinfo->getAddress(it->c_str())) + missing_globals.push_back(*it); + } + if (missing_globals.size()) + { + con.printerr("Plugin %s is missing required globals: %s\n", + filename.c_str(), join_strings(", ", missing_globals).c_str()); + ClosePlugin(plug); + state = PS_BROKEN; + return false; + } + } plugin_status = (command_result (*)(color_ostream &, std::string &)) LookupPlugin(plug, "plugin_status"); plugin_onupdate = (command_result (*)(color_ostream &)) LookupPlugin(plug, "plugin_onupdate"); plugin_shutdown = (command_result (*)(color_ostream &)) LookupPlugin(plug, "plugin_shutdown"); diff --git a/library/include/PluginManager.h b/library/include/PluginManager.h index b47863d48..ba5b76b62 100644 --- a/library/include/PluginManager.h +++ b/library/include/PluginManager.h @@ -205,6 +205,7 @@ namespace DFHack void reset_lua(); bool *plugin_is_enabled; + std::vector* plugin_globals; command_result (*plugin_init)(color_ostream &, std::vector &); command_result (*plugin_status)(color_ostream &, std::string &); command_result (*plugin_shutdown)(color_ostream &); @@ -264,7 +265,9 @@ namespace DFHack #define DFHACK_PLUGIN(plugin_name) \ DFhackDataExport const char * version = DFHACK_VERSION;\ DFhackDataExport const char * name = plugin_name;\ - DFhackDataExport Plugin *plugin_self = NULL; + DFhackDataExport Plugin *plugin_self = NULL;\ + std::vector _plugin_globals;\ + DFhackDataExport std::vector* plugin_globals = &_plugin_globals; #define DFHACK_PLUGIN_IS_ENABLED(varname) \ DFhackDataExport bool plugin_is_enabled = false; \ @@ -281,3 +284,8 @@ namespace DFHack #define DFHACK_LUA_FUNCTION(name) { #name, df::wrap_function(name,true) } #define DFHACK_LUA_EVENT(name) { #name, &name##_event } #define DFHACK_LUA_END { NULL, NULL } + +#define REQUIRE_GLOBAL(global_name) \ + using df::global::global_name; \ + static int VARIABLE_IS_NOT_USED CONCAT_TOKENS(required_globals_, __LINE__) = \ + (plugin_globals->push_back(#global_name), 0); diff --git a/plugins/3dveins.cpp b/plugins/3dveins.cpp index 9802ff5eb..d57a80662 100644 --- a/plugins/3dveins.cpp +++ b/plugins/3dveins.cpp @@ -41,13 +41,12 @@ using namespace DFHack; using namespace MapExtras; using namespace DFHack::Random; -using df::global::world; -using df::global::gametype; +DFHACK_PLUGIN("3dveins"); +REQUIRE_GLOBAL(world); +REQUIRE_GLOBAL(gametype); command_result cmd_3dveins(color_ostream &out, std::vector & parameters); -DFHACK_PLUGIN("3dveins"); - DFhackCExport command_result plugin_init ( color_ostream &out, std::vector &commands) { commands.push_back(PluginCommand( From cac22454388e266b9b6cf0d4ab9fcd88e968c7f8 Mon Sep 17 00:00:00 2001 From: lethosor Date: Tue, 2 Dec 2014 21:44:20 -0500 Subject: [PATCH 2/6] Update some plugins to use REQUIRE_GLOBAL --- library/include/PluginManager.h | 1 + plugins/add-spatter.cpp | 11 +++++------ plugins/advtools.cpp | 9 ++++----- plugins/autochop.cpp | 6 ++---- plugins/autodump.cpp | 2 +- plugins/autolabor.cpp | 10 ++++------ plugins/automaterial.cpp | 6 +++--- plugins/automelt.cpp | 6 +++--- plugins/autotrade.cpp | 6 +++--- plugins/building-hacks.cpp | 3 ++- plugins/buildingplan.cpp | 7 +++---- plugins/burrows.cpp | 9 ++++----- plugins/catsplosion.cpp | 6 +++--- plugins/changeitem.cpp | 2 +- plugins/changelayer.cpp | 7 +++---- plugins/changevein.cpp | 7 +++---- plugins/cleanconst.cpp | 3 +-- plugins/cleaners.cpp | 5 ++--- plugins/cleanowned.cpp | 5 ++--- plugins/colonies.cpp | 1 + plugins/command-prompt.cpp | 9 +++++---- plugins/createitem.cpp | 7 +++---- plugins/cursecheck.cpp | 8 ++++---- plugins/deramp.cpp | 3 +-- plugins/dfstream.cpp | 8 ++++---- plugins/dig.cpp | 1 + plugins/digFlood.cpp | 7 ++----- plugins/diggingInvaders/diggingInvaders.cpp | 7 ++++--- plugins/drybuckets.cpp | 3 +-- plugins/dwarfmonitor.cpp | 11 +++++------ plugins/eventful.cpp | 9 ++++----- 31 files changed, 85 insertions(+), 100 deletions(-) diff --git a/library/include/PluginManager.h b/library/include/PluginManager.h index ba5b76b62..663dde90a 100644 --- a/library/include/PluginManager.h +++ b/library/include/PluginManager.h @@ -27,6 +27,7 @@ distribution. #include "Export.h" #include "Hooks.h" #include "ColorText.h" +#include "MiscUtils.h" #include #include #include diff --git a/plugins/add-spatter.cpp b/plugins/add-spatter.cpp index 52e95e88b..cb2858d06 100644 --- a/plugins/add-spatter.cpp +++ b/plugins/add-spatter.cpp @@ -41,14 +41,13 @@ using std::stack; using namespace DFHack; using namespace df::enums; -using df::global::gps; -using df::global::world; -using df::global::ui; - -typedef df::reaction_product_item_improvementst improvement_product; - DFHACK_PLUGIN("add-spatter"); DFHACK_PLUGIN_IS_ENABLED(is_enabled); +REQUIRE_GLOBAL(gps); +REQUIRE_GLOBAL(world); +REQUIRE_GLOBAL(ui); + +typedef df::reaction_product_item_improvementst improvement_product; struct ReagentSource { int idx; diff --git a/plugins/advtools.cpp b/plugins/advtools.cpp index ad50dbe5d..8f613d1cc 100644 --- a/plugins/advtools.cpp +++ b/plugins/advtools.cpp @@ -37,14 +37,15 @@ using namespace DFHack; using namespace df::enums; -using df::global::world; -using df::global::ui_advmode; - using df::nemesis_record; using df::historical_figure; using namespace DFHack::Translation; +DFHACK_PLUGIN("advtools"); +REQUIRE_GLOBAL(world); +REQUIRE_GLOBAL(ui_advmode); + /********************* * PLUGIN INTERFACE * *********************/ @@ -54,8 +55,6 @@ static bool bodyswap_hotkey(df::viewscreen *top); command_result adv_bodyswap (color_ostream &out, std::vector & parameters); command_result adv_tools (color_ostream &out, std::vector & parameters); -DFHACK_PLUGIN("advtools"); - DFhackCExport command_result plugin_init (color_ostream &out, std::vector &commands) { if (!ui_advmode) diff --git a/plugins/autochop.cpp b/plugins/autochop.cpp index 5dab8f69b..ee5f6c492 100644 --- a/plugins/autochop.cpp +++ b/plugins/autochop.cpp @@ -36,12 +36,10 @@ using std::set; using namespace DFHack; using namespace df::enums; -using df::global::world; -using df::global::ui; - #define PLUGIN_VERSION 0.3 DFHACK_PLUGIN("autochop"); - +REQUIRE_GLOBAL(world); +REQUIRE_GLOBAL(ui); static bool autochop_enabled = false; static int min_logs, max_logs; diff --git a/plugins/autodump.cpp b/plugins/autodump.cpp index dcbc7c083..efb58a10c 100644 --- a/plugins/autodump.cpp +++ b/plugins/autodump.cpp @@ -34,10 +34,10 @@ using namespace df::enums; using MapExtras::Block; using MapExtras::MapCache; -using df::global::world; using df::building_stockpilest; DFHACK_PLUGIN("autodump"); +REQUIRE_GLOBAL(world); // Stockpile interface START static const string PERSISTENCE_KEY = "autodump/stockpiles"; diff --git a/plugins/autolabor.cpp b/plugins/autolabor.cpp index ad7992038..c1dfc5d2e 100644 --- a/plugins/autolabor.cpp +++ b/plugins/autolabor.cpp @@ -44,8 +44,10 @@ using std::endl; using std::vector; using namespace DFHack; using namespace df::enums; -using df::global::ui; -using df::global::world; + +DFHACK_PLUGIN("autolabor"); +REQUIRE_GLOBAL(ui); +REQUIRE_GLOBAL(world); #define ARRAY_COUNT(array) (sizeof(array)/sizeof((array)[0])) @@ -91,10 +93,6 @@ enum ConfigFlags { // mostly to allow having the mandatory stuff on top of the file and commands on the bottom command_result autolabor (color_ostream &out, std::vector & parameters); -// A plugin must be able to return its name and version. -// The name string provided must correspond to the filename - autolabor.plug.so or autolabor.plug.dll in this case -DFHACK_PLUGIN("autolabor"); - static void generate_labor_to_skill_map(); enum labor_mode { diff --git a/plugins/automaterial.cpp b/plugins/automaterial.cpp index b795622d9..b49b04ee8 100644 --- a/plugins/automaterial.cpp +++ b/plugins/automaterial.cpp @@ -43,11 +43,11 @@ using std::vector; using namespace DFHack; using namespace df::enums; -using df::global::gps; -using df::global::ui; -using df::global::ui_build_selector; DFHACK_PLUGIN("automaterial"); +REQUIRE_GLOBAL(gps); +REQUIRE_GLOBAL(ui); +REQUIRE_GLOBAL(ui_build_selector); struct MaterialDescriptor { diff --git a/plugins/automelt.cpp b/plugins/automelt.cpp index 042d8e082..ccbf3489c 100644 --- a/plugins/automelt.cpp +++ b/plugins/automelt.cpp @@ -14,13 +14,13 @@ #include "modules/World.h" #include "df/item_quality.h" -using df::global::world; -using df::global::cursor; -using df::global::ui; using df::building_stockpilest; DFHACK_PLUGIN("automelt"); #define PLUGIN_VERSION 0.3 +REQUIRE_GLOBAL(world); +REQUIRE_GLOBAL(cursor); +REQUIRE_GLOBAL(ui); static const string PERSISTENCE_KEY = "automelt/stockpiles"; diff --git a/plugins/autotrade.cpp b/plugins/autotrade.cpp index e6156b0c3..e238cc514 100644 --- a/plugins/autotrade.cpp +++ b/plugins/autotrade.cpp @@ -19,12 +19,12 @@ #include "df/mandate.h" #include "modules/Maps.h" -using df::global::world; -using df::global::cursor; -using df::global::ui; using df::building_stockpilest; DFHACK_PLUGIN("autotrade"); +REQUIRE_GLOBAL(world); +REQUIRE_GLOBAL(cursor); +REQUIRE_GLOBAL(ui); static const string PERSISTENCE_KEY = "autotrade/stockpiles"; diff --git a/plugins/building-hacks.cpp b/plugins/building-hacks.cpp index d56215fda..152e4568b 100644 --- a/plugins/building-hacks.cpp +++ b/plugins/building-hacks.cpp @@ -24,9 +24,10 @@ using namespace DFHack; using namespace df::enums; -using df::global::world; DFHACK_PLUGIN("building-hacks"); +REQUIRE_GLOBAL(world); + struct graphic_tile //could do just 31x31 and be done, but it's nicer to have flexible imho. { int16_t tile; //originally uint8_t but we need to indicate non-animated tiles diff --git a/plugins/buildingplan.cpp b/plugins/buildingplan.cpp index d916ba2e3..e9bb6eda4 100644 --- a/plugins/buildingplan.cpp +++ b/plugins/buildingplan.cpp @@ -35,12 +35,11 @@ #include "df/building.h" #include "df/building_doorst.h" -using df::global::ui; -using df::global::ui_build_selector; -using df::global::world; - DFHACK_PLUGIN("buildingplan"); #define PLUGIN_VERSION 0.14 +REQUIRE_GLOBAL(ui); +REQUIRE_GLOBAL(ui_build_selector); +REQUIRE_GLOBAL(world); struct MaterialDescriptor { diff --git a/plugins/burrows.cpp b/plugins/burrows.cpp index 214fb0582..87adbe734 100644 --- a/plugins/burrows.cpp +++ b/plugins/burrows.cpp @@ -37,9 +37,10 @@ using namespace DFHack; using namespace df::enums; using namespace dfproto; -using df::global::ui; -using df::global::world; -using df::global::gamemode; +DFHACK_PLUGIN("burrows"); +REQUIRE_GLOBAL(ui); +REQUIRE_GLOBAL(world); +REQUIRE_GLOBAL(gamemode); /* * Initialization. @@ -47,8 +48,6 @@ using df::global::gamemode; static command_result burrow(color_ostream &out, vector & parameters); -DFHACK_PLUGIN("burrows"); - static void init_map(color_ostream &out); static void deinit_map(color_ostream &out); diff --git a/plugins/catsplosion.cpp b/plugins/catsplosion.cpp index 1c323de22..725aaf492 100644 --- a/plugins/catsplosion.cpp +++ b/plugins/catsplosion.cpp @@ -25,11 +25,11 @@ using namespace std; #include using namespace DFHack; -using df::global::world; - -command_result catsplosion (color_ostream &out, std::vector & parameters); DFHACK_PLUGIN("catsplosion"); +REQUIRE_GLOBAL(world); + +command_result catsplosion (color_ostream &out, std::vector & parameters); // Mandatory init function. If you have some global state, create it here. DFhackCExport command_result plugin_init ( color_ostream &out, std::vector &commands) diff --git a/plugins/changeitem.cpp b/plugins/changeitem.cpp index 9c0a55ad9..b73f24097 100644 --- a/plugins/changeitem.cpp +++ b/plugins/changeitem.cpp @@ -31,9 +31,9 @@ using namespace df::enums; using MapExtras::Block; using MapExtras::MapCache; -using df::global::world; DFHACK_PLUGIN("changeitem"); +REQUIRE_GLOBAL(world); command_result df_changeitem(color_ostream &out, vector & parameters); diff --git a/plugins/changelayer.cpp b/plugins/changelayer.cpp index 3ab1899af..727fae56c 100644 --- a/plugins/changelayer.cpp +++ b/plugins/changelayer.cpp @@ -28,8 +28,9 @@ using namespace std; using std::vector; using std::string; -using df::global::world; -using df::global::cursor; +DFHACK_PLUGIN("changelayer"); +REQUIRE_GLOBAL(world); +REQUIRE_GLOBAL(cursor); const string changelayer_help = " Allows to change the material of whole geology layers.\n" @@ -83,8 +84,6 @@ const string changelayer_trouble = command_result changelayer (color_ostream &out, std::vector & parameters); -DFHACK_PLUGIN("changelayer"); - DFhackCExport command_result plugin_init ( color_ostream &out, std::vector &commands) { commands.push_back(PluginCommand( diff --git a/plugins/changevein.cpp b/plugins/changevein.cpp index 1d08cfeaf..9c17af292 100644 --- a/plugins/changevein.cpp +++ b/plugins/changevein.cpp @@ -15,8 +15,9 @@ using std::string; using namespace DFHack; using namespace df::enums; -using df::global::world; -using df::global::cursor; +DFHACK_PLUGIN("changevein"); +REQUIRE_GLOBAL(world); +REQUIRE_GLOBAL(cursor); command_result df_changevein (color_ostream &out, vector & parameters) { @@ -77,8 +78,6 @@ command_result df_changevein (color_ostream &out, vector & parameters) return CR_OK; } -DFHACK_PLUGIN("changevein"); - DFhackCExport command_result plugin_init ( color_ostream &out, std::vector &commands) { commands.push_back(PluginCommand("changevein", diff --git a/plugins/cleanconst.cpp b/plugins/cleanconst.cpp index 3efdadecb..2d5bf77f6 100644 --- a/plugins/cleanconst.cpp +++ b/plugins/cleanconst.cpp @@ -16,9 +16,8 @@ using namespace std; using namespace DFHack; -using df::global::world; - DFHACK_PLUGIN("cleanconst"); +REQUIRE_GLOBAL(world); command_result df_cleanconst(color_ostream &out, vector & parameters) { diff --git a/plugins/cleaners.cpp b/plugins/cleaners.cpp index ab1ccda2b..953ff5305 100644 --- a/plugins/cleaners.cpp +++ b/plugins/cleaners.cpp @@ -18,10 +18,9 @@ using std::string; using namespace DFHack; using namespace df::enums; -using df::global::world; -using df::global::cursor; - DFHACK_PLUGIN("cleaners"); +REQUIRE_GLOBAL(world); +REQUIRE_GLOBAL(cursor); command_result cleanmap (color_ostream &out, bool snow, bool mud, bool item_spatter) { diff --git a/plugins/cleanowned.cpp b/plugins/cleanowned.cpp index 28314d3f0..4dd3fd212 100644 --- a/plugins/cleanowned.cpp +++ b/plugins/cleanowned.cpp @@ -23,12 +23,11 @@ using namespace std; using namespace DFHack; using namespace df::enums; -using df::global::world; +DFHACK_PLUGIN("cleanowned"); +REQUIRE_GLOBAL(world); command_result df_cleanowned (color_ostream &out, vector & parameters); -DFHACK_PLUGIN("cleanowned"); - DFhackCExport command_result plugin_init ( color_ostream &out, std::vector &commands) { commands.push_back(PluginCommand( diff --git a/plugins/colonies.cpp b/plugins/colonies.cpp index 3ebfc324c..bea595bf9 100644 --- a/plugins/colonies.cpp +++ b/plugins/colonies.cpp @@ -14,6 +14,7 @@ using namespace DFHack; command_result colonies (color_ostream &out, vector & parameters); DFHACK_PLUGIN("colonies"); +REQUIRE_GLOBAL(world); // used by Materials DFhackCExport command_result plugin_init ( color_ostream &out, std::vector &commands) { diff --git a/plugins/command-prompt.cpp b/plugins/command-prompt.cpp index cf1e78763..bc3b89610 100644 --- a/plugins/command-prompt.cpp +++ b/plugins/command-prompt.cpp @@ -22,9 +22,10 @@ using namespace DFHack; using namespace df::enums; -using df::global::ui; -using df::global::gps; -using df::global::enabler; +DFHACK_PLUGIN("command-prompt"); +REQUIRE_GLOBAL(ui); +REQUIRE_GLOBAL(gps); +REQUIRE_GLOBAL(enabler); std::vector command_history; @@ -303,7 +304,7 @@ void viewscreen_commandpromptst::feed(std::set *events) frame = 0; } -DFHACK_PLUGIN("command-prompt"); + command_result show_prompt(color_ostream &out, std::vector & parameters) { if (Gui::getCurFocus() == "dfhack/commandprompt") diff --git a/plugins/createitem.cpp b/plugins/createitem.cpp index 89c2ade36..c4c0c6ebb 100644 --- a/plugins/createitem.cpp +++ b/plugins/createitem.cpp @@ -31,11 +31,10 @@ using std::vector; using namespace DFHack; using namespace df::enums; -using df::global::world; -using df::global::ui; -using df::global::gametype; - DFHACK_PLUGIN("createitem"); +REQUIRE_GLOBAL(world); +REQUIRE_GLOBAL(ui); +REQUIRE_GLOBAL(gametype); int dest_container = -1, dest_building = -1; diff --git a/plugins/cursecheck.cpp b/plugins/cursecheck.cpp index f7c6d2fd9..dc7fd2f3c 100644 --- a/plugins/cursecheck.cpp +++ b/plugins/cursecheck.cpp @@ -48,12 +48,12 @@ using std::vector; using std::string; using namespace DFHack; using namespace df::enums; -using df::global::world; -using df::global::cursor; - -command_result cursecheck (color_ostream &out, vector & parameters); DFHACK_PLUGIN("cursecheck"); +REQUIRE_GLOBAL(world); +REQUIRE_GLOBAL(cursor); + +command_result cursecheck (color_ostream &out, vector & parameters); DFhackCExport command_result plugin_init ( color_ostream &out, std::vector &commands) { diff --git a/plugins/deramp.cpp b/plugins/deramp.cpp index e5d0331d9..dc2651db7 100644 --- a/plugins/deramp.cpp +++ b/plugins/deramp.cpp @@ -14,9 +14,8 @@ using std::string; using namespace DFHack; using namespace df::enums; -using df::global::world; - DFHACK_PLUGIN("deramp"); +REQUIRE_GLOBAL(world); command_result df_deramp (color_ostream &out, vector & parameters) { diff --git a/plugins/dfstream.cpp b/plugins/dfstream.cpp index 19334abae..c8e99d678 100644 --- a/plugins/dfstream.cpp +++ b/plugins/dfstream.cpp @@ -18,8 +18,10 @@ using namespace df::enums; using std::string; using std::vector; -using df::global::gps; -using df::global::enabler; + +DFHACK_PLUGIN("dfstream"); +REQUIRE_GLOBAL(gps); +REQUIRE_GLOBAL(enabler); // The error messages are taken from the clsocket source code const char * translate_socket_error(CSimpleSocket::CSocketError err) { @@ -283,8 +285,6 @@ public: } }; -DFHACK_PLUGIN("dfstream"); - inline df::renderer *& active_renderer() { return enabler->renderer; } diff --git a/plugins/dig.cpp b/plugins/dig.cpp index 082e6a04a..922a47477 100644 --- a/plugins/dig.cpp +++ b/plugins/dig.cpp @@ -27,6 +27,7 @@ command_result digcircle (color_ostream &out, vector & parameters); command_result digtype (color_ostream &out, vector & parameters); DFHACK_PLUGIN("dig"); +REQUIRE_GLOBAL(world); DFhackCExport command_result plugin_init ( color_ostream &out, std::vector &commands) { diff --git a/plugins/digFlood.cpp b/plugins/digFlood.cpp index 1646f4deb..170427bf6 100644 --- a/plugins/digFlood.cpp +++ b/plugins/digFlood.cpp @@ -21,14 +21,11 @@ using namespace DFHack; using namespace std; -using df::global::world; -// using df::global::process_jobs; -// using df::global::process_dig; +DFHACK_PLUGIN("digFlood"); +REQUIRE_GLOBAL(world); command_result digFlood (color_ostream &out, std::vector & parameters); -DFHACK_PLUGIN("digFlood"); - void onDig(color_ostream& out, void* ptr); void maybeExplore(color_ostream& out, MapExtras::MapCache& cache, df::coord pt, set& jobLocations); EventManager::EventHandler digHandler(onDig, 0); diff --git a/plugins/diggingInvaders/diggingInvaders.cpp b/plugins/diggingInvaders/diggingInvaders.cpp index 48c34d5d4..cd171f527 100644 --- a/plugins/diggingInvaders/diggingInvaders.cpp +++ b/plugins/diggingInvaders/diggingInvaders.cpp @@ -77,6 +77,7 @@ void findAndAssignInvasionJob(color_ostream& out, void*); DFHACK_PLUGIN_IS_ENABLED(enabled); DFHACK_PLUGIN("diggingInvaders"); +REQUIRE_GLOBAL(world); //TODO: when world unloads static int32_t lastInvasionJob=-1; @@ -386,8 +387,8 @@ void findAndAssignInvasionJob(color_ostream& out, void* tickTime) { unordered_set localConnectivity; //find all locals and invaders - for ( size_t a = 0; a < df::global::world->units.all.size(); a++ ) { - df::unit* unit = df::global::world->units.all[a]; + for ( size_t a = 0; a < world->units.all.size(); a++ ) { + df::unit* unit = world->units.all[a]; if ( unit->flags1.bits.dead ) continue; if ( Units::isCitizen(unit) ) { @@ -597,7 +598,7 @@ void findAndAssignInvasionJob(color_ostream& out, void* tickTime) { lastInvasionDigger = firstInvader->id; lastInvasionJob = firstInvader->job.current_job ? firstInvader->job.current_job->id : -1; invaderJobs.erase(lastInvasionJob); - for ( df::job_list_link* link = &df::global::world->job_list; link != NULL; link = link->next ) { + for ( df::job_list_link* link = &world->job_list; link != NULL; link = link->next ) { if ( link->item == NULL ) continue; df::job* job = link->item; diff --git a/plugins/drybuckets.cpp b/plugins/drybuckets.cpp index e54d2b90c..711a05928 100644 --- a/plugins/drybuckets.cpp +++ b/plugins/drybuckets.cpp @@ -15,9 +15,8 @@ using std::vector; using namespace DFHack; using namespace df::enums; -using df::global::world; - DFHACK_PLUGIN("drybuckets"); +REQUIRE_GLOBAL(world); command_result df_drybuckets (color_ostream &out, vector & parameters) { diff --git a/plugins/dwarfmonitor.cpp b/plugins/dwarfmonitor.cpp index cda764f54..8a90b3378 100644 --- a/plugins/dwarfmonitor.cpp +++ b/plugins/dwarfmonitor.cpp @@ -43,9 +43,11 @@ using std::deque; -using df::global::current_weather; -using df::global::world; -using df::global::ui; +DFHACK_PLUGIN("dwarfmonitor"); +DFHACK_PLUGIN_IS_ENABLED(is_enabled); +REQUIRE_GLOBAL(current_weather); +REQUIRE_GLOBAL(world); +REQUIRE_GLOBAL(ui); typedef int16_t activity_type; @@ -1775,9 +1777,6 @@ struct dwarf_monitor_hook : public df::viewscreen_dwarfmodest IMPLEMENT_VMETHOD_INTERPOSE(dwarf_monitor_hook, feed); IMPLEMENT_VMETHOD_INTERPOSE(dwarf_monitor_hook, render); -DFHACK_PLUGIN("dwarfmonitor"); -DFHACK_PLUGIN_IS_ENABLED(is_enabled); - static bool set_monitoring_mode(const string &mode, const bool &state) { bool mode_recognized = false; diff --git a/plugins/eventful.cpp b/plugins/eventful.cpp index 6a264ab95..8cf1d7832 100644 --- a/plugins/eventful.cpp +++ b/plugins/eventful.cpp @@ -34,14 +34,13 @@ using std::stack; using namespace DFHack; using namespace df::enums; -using df::global::gps; -using df::global::world; -using df::global::ui; +DFHACK_PLUGIN("eventful"); +REQUIRE_GLOBAL(gps); +REQUIRE_GLOBAL(world); +REQUIRE_GLOBAL(ui); typedef df::reaction_product_itemst item_product; -DFHACK_PLUGIN("eventful"); - struct ReagentSource { int idx; df::reaction_reagent *reagent; From f1a863eb795ad4c9aca602112c8da7d84298212b Mon Sep 17 00:00:00 2001 From: lethosor Date: Wed, 3 Dec 2014 23:27:52 -0500 Subject: [PATCH 3/6] Use short plugin name --- library/PluginManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/PluginManager.cpp b/library/PluginManager.cpp index 713c442c3..f108b9047 100644 --- a/library/PluginManager.cpp +++ b/library/PluginManager.cpp @@ -257,7 +257,7 @@ bool Plugin::load(color_ostream &con) if (missing_globals.size()) { con.printerr("Plugin %s is missing required globals: %s\n", - filename.c_str(), join_strings(", ", missing_globals).c_str()); + *plug_name, join_strings(", ", missing_globals).c_str()); ClosePlugin(plug); state = PS_BROKEN; return false; From a615723b381be211097de7e2fb31c8c07b7c4d7a Mon Sep 17 00:00:00 2001 From: lethosor Date: Sat, 6 Dec 2014 18:47:35 -0500 Subject: [PATCH 4/6] Update remaining plugins to use REQUIRE_GLOBAL --- plugins/fastdwarf.cpp | 7 ++-- plugins/feature.cpp | 5 ++- plugins/fixpositions.cpp | 5 ++- plugins/fixveins.cpp | 5 ++- plugins/flows.cpp | 5 ++- plugins/follow.cpp | 7 ++-- plugins/forceequip.cpp | 6 ++-- plugins/getplants.cpp | 5 ++- plugins/infiniteSky.cpp | 5 ++- plugins/initflags.cpp | 5 ++- plugins/isoworldremote.cpp | 14 +++----- plugins/jobutils.cpp | 13 ++++--- plugins/lair.cpp | 2 +- plugins/liquids.cpp | 6 ++-- plugins/manipulator.cpp | 14 ++++---- plugins/misery.cpp | 9 +++-- plugins/mousequery.cpp | 9 +++-- plugins/petcapRemover.cpp | 8 ++--- plugins/plants.cpp | 6 ++-- plugins/power-meter.cpp | 9 +++-- plugins/probe.cpp | 8 ++--- plugins/prospector.cpp | 6 ++-- plugins/regrass.cpp | 3 +- plugins/remotefortressreader.cpp | 19 +++++------ plugins/rename.cpp | 12 +++---- plugins/rendermax/rendermax.cpp | 58 +++++++++++++++++++------------- plugins/resume.cpp | 8 ++--- plugins/reveal.cpp | 9 +++-- plugins/search.cpp | 13 ++++--- plugins/seedwatch.cpp | 9 ++--- plugins/showmood.cpp | 5 ++- plugins/siege-engine.cpp | 13 ++++--- plugins/sort.cpp | 19 +++++------ plugins/steam-engine.cpp | 12 +++---- plugins/stockflow.cpp | 8 ++--- plugins/stockpiles.cpp | 9 +++-- plugins/stocks.cpp | 4 +-- plugins/strangemood.cpp | 22 ++++++------ plugins/tiletypes.cpp | 5 ++- plugins/trackstop.cpp | 14 ++------ plugins/treefarm.cpp | 10 +++--- plugins/tubefill.cpp | 6 ++-- plugins/tweak/tweak.cpp | 15 +++++---- plugins/weather.cpp | 6 ++-- plugins/workNow.cpp | 5 ++- plugins/workflow.cpp | 12 +++---- plugins/zone.cpp | 42 +++++++++++------------ 47 files changed, 236 insertions(+), 261 deletions(-) diff --git a/plugins/fastdwarf.cpp b/plugins/fastdwarf.cpp index 5416f6d00..47b2d5cac 100644 --- a/plugins/fastdwarf.cpp +++ b/plugins/fastdwarf.cpp @@ -17,13 +17,10 @@ using std::vector; using namespace DFHack; using namespace df::enums; -using df::global::world; -using df::global::debug_turbospeed; - -// dfhack interface DFHACK_PLUGIN("fastdwarf"); - DFHACK_PLUGIN_IS_ENABLED(active); +REQUIRE_GLOBAL(world); +using df::global::debug_turbospeed; // not required static bool enable_fastdwarf = false; static bool enable_teledwarf = false; diff --git a/plugins/feature.cpp b/plugins/feature.cpp index cbfd7b5e0..30c71cda2 100644 --- a/plugins/feature.cpp +++ b/plugins/feature.cpp @@ -17,7 +17,8 @@ using std::endl; using namespace DFHack; using namespace df::enums; -using df::global::world; +DFHACK_PLUGIN("feature"); +REQUIRE_GLOBAL(world); static command_result feature(color_ostream &out, vector ¶meters) @@ -92,8 +93,6 @@ static command_result feature(color_ostream &out, vector ¶meters) return CR_OK; } -DFHACK_PLUGIN("feature"); - DFhackCExport command_result plugin_init (color_ostream &out, std::vector &commands) { commands.push_back(PluginCommand( diff --git a/plugins/fixpositions.cpp b/plugins/fixpositions.cpp index bd8fb2791..7a22fd2b8 100644 --- a/plugins/fixpositions.cpp +++ b/plugins/fixpositions.cpp @@ -18,7 +18,8 @@ using std::vector; using namespace DFHack; using namespace df::enums; -using df::global::world; +DFHACK_PLUGIN("fixpositions"); +REQUIRE_GLOBAL(world); command_result df_fixdiplomats (color_ostream &out, vector ¶meters) { @@ -226,8 +227,6 @@ command_result df_fixmerchants (color_ostream &out, vector ¶meters) return CR_OK; } -DFHACK_PLUGIN("fixpositions"); - DFhackCExport command_result plugin_init ( color_ostream &out, std::vector &commands) { commands.push_back(PluginCommand( diff --git a/plugins/fixveins.cpp b/plugins/fixveins.cpp index f02f61673..5f612c9ad 100644 --- a/plugins/fixveins.cpp +++ b/plugins/fixveins.cpp @@ -19,7 +19,8 @@ using std::string; using namespace DFHack; using namespace df::enums; -using df::global::world; +DFHACK_PLUGIN("fixveins"); +REQUIRE_GLOBAL(world); bool setTileMaterial(df::tiletype &tile, const df::tiletype_material mat) { @@ -95,8 +96,6 @@ command_result df_fixveins (color_ostream &out, vector & parameters) return CR_OK; } -DFHACK_PLUGIN("fixveins"); - DFhackCExport command_result plugin_init ( color_ostream &out, std::vector &commands) { commands.push_back(PluginCommand("fixveins", diff --git a/plugins/flows.cpp b/plugins/flows.cpp index 26188f512..070776b10 100644 --- a/plugins/flows.cpp +++ b/plugins/flows.cpp @@ -15,7 +15,8 @@ using std::vector; using namespace DFHack; using namespace df::enums; -using df::global::world; +DFHACK_PLUGIN("flows"); +REQUIRE_GLOBAL(world); command_result df_flows (color_ostream &out, vector & parameters) { @@ -56,8 +57,6 @@ command_result df_flows (color_ostream &out, vector & parameters) return CR_OK; } -DFHACK_PLUGIN("flows"); - DFhackCExport command_result plugin_init ( color_ostream &out, std::vector &commands) { commands.push_back(PluginCommand("flows", diff --git a/plugins/follow.cpp b/plugins/follow.cpp index de3428300..ff0a94787 100644 --- a/plugins/follow.cpp +++ b/plugins/follow.cpp @@ -16,7 +16,9 @@ using namespace DFHack; using namespace df::enums; -using df::global::world; +DFHACK_PLUGIN("follow"); +DFHACK_PLUGIN_IS_ENABLED(is_enabled); +REQUIRE_GLOBAL(world); command_result follow (color_ostream &out, std::vector & parameters); @@ -24,9 +26,6 @@ df::unit *followedUnit; int32_t prevX, prevY, prevZ; uint8_t prevMenuWidth; -DFHACK_PLUGIN("follow"); -DFHACK_PLUGIN_IS_ENABLED(is_enabled); - DFhackCExport command_result plugin_init ( color_ostream &out, std::vector &commands) { commands.push_back(PluginCommand( diff --git a/plugins/forceequip.cpp b/plugins/forceequip.cpp index 54da374b5..1f1eb1ce6 100644 --- a/plugins/forceequip.cpp +++ b/plugins/forceequip.cpp @@ -46,13 +46,13 @@ using namespace df::enums; using MapExtras::Block; using MapExtras::MapCache; -using df::global::world; + +DFHACK_PLUGIN("forceequip"); +REQUIRE_GLOBAL(world); const int const_GloveRightHandedness = 1; const int const_GloveLeftHandedness = 2; -DFHACK_PLUGIN("forceequip"); - command_result df_forceequip(color_ostream &out, vector & parameters); const string forceequip_help = diff --git a/plugins/getplants.cpp b/plugins/getplants.cpp index f4771b58b..ed3272265 100644 --- a/plugins/getplants.cpp +++ b/plugins/getplants.cpp @@ -22,7 +22,8 @@ using std::set; using namespace DFHack; using namespace df::enums; -using df::global::world; +DFHACK_PLUGIN("getplants"); +REQUIRE_GLOBAL(world); command_result df_getplants (color_ostream &out, vector & parameters) { @@ -148,8 +149,6 @@ command_result df_getplants (color_ostream &out, vector & parameters) return CR_OK; } -DFHACK_PLUGIN("getplants"); - DFhackCExport command_result plugin_init ( color_ostream &out, vector &commands) { commands.push_back(PluginCommand( diff --git a/plugins/infiniteSky.cpp b/plugins/infiniteSky.cpp index 774ac4d51..f2853f128 100644 --- a/plugins/infiniteSky.cpp +++ b/plugins/infiniteSky.cpp @@ -23,12 +23,11 @@ using namespace std; using namespace DFHack; using namespace df::enums; -using df::global::world; +DFHACK_PLUGIN("infiniteSky"); +REQUIRE_GLOBAL(world); command_result infiniteSky (color_ostream &out, std::vector & parameters); -DFHACK_PLUGIN("infiniteSky"); - DFhackCExport command_result plugin_init ( color_ostream &out, std::vector &commands) { commands.push_back(PluginCommand( diff --git a/plugins/initflags.cpp b/plugins/initflags.cpp index 6aa78930a..24c773679 100644 --- a/plugins/initflags.cpp +++ b/plugins/initflags.cpp @@ -12,13 +12,12 @@ using std::endl; using namespace DFHack; using namespace df::enums; -using df::global::d_init; +DFHACK_PLUGIN("initflags"); +REQUIRE_GLOBAL(d_init); command_result twaterlvl(color_ostream &out, vector & parameters); command_result tidlers(color_ostream &out, vector & parameters); -DFHACK_PLUGIN("initflags"); - DFhackCExport command_result plugin_init (color_ostream &out, std::vector &commands) { if (d_init) { diff --git a/plugins/isoworldremote.cpp b/plugins/isoworldremote.cpp index 78baad1e1..607035d7b 100644 --- a/plugins/isoworldremote.cpp +++ b/plugins/isoworldremote.cpp @@ -31,10 +31,11 @@ using namespace DFHack; using namespace df::enums; using namespace isoworldremote; -using df::global::gamemode; -using df::global::world; -using df::global::cur_year; -using df::global::cur_season; +DFHACK_PLUGIN("isoworldremote"); +REQUIRE_GLOBAL(gamemode); +REQUIRE_GLOBAL(world); +REQUIRE_GLOBAL(cur_year); +REQUIRE_GLOBAL(cur_season); // Here go all the command declarations... // mostly to allow having the mandatory stuff on top of the file and commands on the bottom @@ -47,11 +48,6 @@ static command_result GetRawNames(color_ostream &stream, const MapRequest *in, R bool gather_embark_tile_layer(int EmbX, int EmbY, int EmbZ, EmbarkTileLayer * tile, MapExtras::MapCache * MP); bool gather_embark_tile(int EmbX, int EmbY, EmbarkTile * tile, MapExtras::MapCache * MP); - -// A plugin must be able to return its name and version. -// The name string provided must correspond to the filename - skeleton.plug.so or skeleton.plug.dll in this case -DFHACK_PLUGIN("isoworldremote"); - // Mandatory init function. If you have some global state, create it here. DFhackCExport command_result plugin_init ( color_ostream &out, std::vector &commands) { diff --git a/plugins/jobutils.cpp b/plugins/jobutils.cpp index dbfe26b90..3e3b6b2a0 100644 --- a/plugins/jobutils.cpp +++ b/plugins/jobutils.cpp @@ -31,11 +31,12 @@ using std::endl; using namespace DFHack; using namespace df::enums; -using df::global::world; -using df::global::ui; -using df::global::ui_build_selector; -using df::global::ui_workshop_job_cursor; -using df::global::job_next_id; +DFHACK_PLUGIN("jobutils"); +REQUIRE_GLOBAL(world); +REQUIRE_GLOBAL(ui); +REQUIRE_GLOBAL(ui_build_selector); +REQUIRE_GLOBAL(ui_workshop_job_cursor); +REQUIRE_GLOBAL(job_next_id); /* Plugin registration */ @@ -45,8 +46,6 @@ static command_result job_material(color_ostream &out, vector & paramet static command_result job_duplicate(color_ostream &out, vector & parameters); static command_result job_cmd(color_ostream &out, vector & parameters); -DFHACK_PLUGIN("jobutils"); - DFhackCExport command_result plugin_init (color_ostream &out, std::vector &commands) { if (!world || !ui) diff --git a/plugins/lair.cpp b/plugins/lair.cpp index cafbbcc33..0ae612e07 100644 --- a/plugins/lair.cpp +++ b/plugins/lair.cpp @@ -12,9 +12,9 @@ #include "modules/Gui.h" using namespace DFHack; using namespace df::enums; -using df::global::world; DFHACK_PLUGIN("lair"); +REQUIRE_GLOBAL(world); enum state { diff --git a/plugins/liquids.cpp b/plugins/liquids.cpp index 5ec25de34..68229aaa3 100644 --- a/plugins/liquids.cpp +++ b/plugins/liquids.cpp @@ -46,15 +46,15 @@ using std::set; using namespace MapExtras; using namespace DFHack; using namespace df::enums; -using df::global::world; + +DFHACK_PLUGIN("liquids"); +REQUIRE_GLOBAL(world); CommandHistory liquids_hist; command_result df_liquids (color_ostream &out, vector & parameters); command_result df_liquids_here (color_ostream &out, vector & parameters); -DFHACK_PLUGIN("liquids"); - DFhackCExport command_result plugin_init ( color_ostream &out, std::vector &commands) { liquids_hist.load("liquids.history"); diff --git a/plugins/manipulator.cpp b/plugins/manipulator.cpp index 93459e732..776100bd7 100644 --- a/plugins/manipulator.cpp +++ b/plugins/manipulator.cpp @@ -36,10 +36,12 @@ using std::string; using namespace DFHack; using namespace df::enums; -using df::global::world; -using df::global::ui; -using df::global::gps; -using df::global::enabler; +DFHACK_PLUGIN("manipulator"); +DFHACK_PLUGIN_IS_ENABLED(is_enabled); +REQUIRE_GLOBAL(world); +REQUIRE_GLOBAL(ui); +REQUIRE_GLOBAL(gps); +REQUIRE_GLOBAL(enabler); struct SkillLevel { @@ -1291,10 +1293,6 @@ struct unitlist_hook : df::viewscreen_unitlistst IMPLEMENT_VMETHOD_INTERPOSE(unitlist_hook, feed); IMPLEMENT_VMETHOD_INTERPOSE(unitlist_hook, render); -DFHACK_PLUGIN("manipulator"); - -DFHACK_PLUGIN_IS_ENABLED(is_enabled); - DFhackCExport command_result plugin_enable(color_ostream &out, bool enable) { if (!gps) diff --git a/plugins/misery.cpp b/plugins/misery.cpp index bc617b906..bc4ba3777 100644 --- a/plugins/misery.cpp +++ b/plugins/misery.cpp @@ -15,11 +15,12 @@ using namespace std; using namespace DFHack; -using df::global::world; -using df::global::ui; - +DFHACK_PLUGIN("misery"); DFHACK_PLUGIN_IS_ENABLED(is_enabled); +REQUIRE_GLOBAL(world); +REQUIRE_GLOBAL(ui); + static int factor = 1; static map processedThoughtCountTable; @@ -28,8 +29,6 @@ static vector > fakeThoughts; static int count; const int maxCount = 1000; -DFHACK_PLUGIN("misery"); - command_result misery(color_ostream& out, vector& parameters); DFhackCExport command_result plugin_shutdown(color_ostream& out) { diff --git a/plugins/mousequery.cpp b/plugins/mousequery.cpp index c0143e830..1b9eedd96 100644 --- a/plugins/mousequery.cpp +++ b/plugins/mousequery.cpp @@ -21,14 +21,13 @@ #include "TileTypes.h" #include "DataFuncs.h" -using df::global::world; -using df::global::ui; -using df::global::ui_build_selector; +DFHACK_PLUGIN("mousequery"); +REQUIRE_GLOBAL(world); +REQUIRE_GLOBAL(ui); +REQUIRE_GLOBAL(ui_build_selector); using namespace df::enums::ui_sidebar_mode; -DFHACK_PLUGIN("mousequery"); - #define PLUGIN_VERSION 0.18 static int32_t last_clicked_x, last_clicked_y, last_clicked_z; diff --git a/plugins/petcapRemover.cpp b/plugins/petcapRemover.cpp index 44870eb76..7eaa3b1e2 100644 --- a/plugins/petcapRemover.cpp +++ b/plugins/petcapRemover.cpp @@ -20,17 +20,17 @@ using namespace DFHack; using namespace std; -using df::global::world; +DFHACK_PLUGIN("petcapRemover"); +DFHACK_PLUGIN_IS_ENABLED(is_enabled); + +REQUIRE_GLOBAL(world); static int32_t howOften = 10000; static int32_t popcap = 100; static int32_t pregtime = 200000; -DFHACK_PLUGIN_IS_ENABLED(is_enabled); command_result petcapRemover (color_ostream &out, std::vector & parameters); -DFHACK_PLUGIN("petcapRemover"); - DFhackCExport command_result plugin_init ( color_ostream &out, std::vector &commands) { commands.push_back(PluginCommand( diff --git a/plugins/plants.cpp b/plugins/plants.cpp index 9509e07f8..5d84ca96e 100644 --- a/plugins/plants.cpp +++ b/plugins/plants.cpp @@ -18,11 +18,11 @@ using std::vector; using std::string; using namespace DFHack; -using df::global::world; - -const uint32_t sapling_to_tree_threshold = 120 * 28 * 12 * 3 - 1; // 3 years minus 1 - let the game handle the actual growing-up DFHACK_PLUGIN("plants"); +REQUIRE_GLOBAL(world); + +const uint32_t sapling_to_tree_threshold = 120 * 28 * 12 * 3 - 1; // 3 years minus 1 - let the game handle the actual growing-up /* Immolate/Extirpate no longer work in 0.40 enum do_what diff --git a/plugins/power-meter.cpp b/plugins/power-meter.cpp index 0f8135eed..039b133f2 100644 --- a/plugins/power-meter.cpp +++ b/plugins/power-meter.cpp @@ -38,12 +38,11 @@ using std::stack; using namespace DFHack; using namespace df::enums; -using df::global::gps; -using df::global::world; -using df::global::ui; -using df::global::ui_build_selector; - DFHACK_PLUGIN("power-meter"); +REQUIRE_GLOBAL(gps); +REQUIRE_GLOBAL(world); +REQUIRE_GLOBAL(ui); +REQUIRE_GLOBAL(ui_build_selector); static const uint32_t METER_BIT = 0x80000000U; diff --git a/plugins/probe.cpp b/plugins/probe.cpp index 28b62c24e..045326d62 100644 --- a/plugins/probe.cpp +++ b/plugins/probe.cpp @@ -33,15 +33,15 @@ using std::vector; using std::string; using namespace DFHack; using namespace df::enums; -using df::global::world; -using df::global::cursor; + +DFHACK_PLUGIN("probe"); +REQUIRE_GLOBAL(world); +REQUIRE_GLOBAL(cursor); command_result df_probe (color_ostream &out, vector & parameters); command_result df_cprobe (color_ostream &out, vector & parameters); command_result df_bprobe (color_ostream &out, vector & parameters); -DFHACK_PLUGIN("probe"); - DFhackCExport command_result plugin_init ( color_ostream &out, std::vector &commands) { commands.push_back(PluginCommand("probe", diff --git a/plugins/prospector.cpp b/plugins/prospector.cpp index 8b505c221..995dea9ba 100644 --- a/plugins/prospector.cpp +++ b/plugins/prospector.cpp @@ -38,9 +38,11 @@ using namespace std; using namespace DFHack; using namespace df::enums; -using df::global::world; using df::coord2d; +DFHACK_PLUGIN("prospector"); +REQUIRE_GLOBAL(world); + struct matdata { const static int invalid_z = -30000; @@ -198,8 +200,6 @@ void printVeins(color_ostream &con, MatMap &mat_map, command_result prospector (color_ostream &out, vector & parameters); -DFHACK_PLUGIN("prospector"); - DFhackCExport command_result plugin_init ( color_ostream &out, std::vector &commands) { commands.push_back(PluginCommand( diff --git a/plugins/regrass.cpp b/plugins/regrass.cpp index 9c687ad7d..22b6a6747 100644 --- a/plugins/regrass.cpp +++ b/plugins/regrass.cpp @@ -22,9 +22,8 @@ using std::vector; using namespace std; using namespace DFHack; -using df::global::world; - DFHACK_PLUGIN("regrass"); +REQUIRE_GLOBAL(world); command_result df_regrass (color_ostream &out, vector & parameters); diff --git a/plugins/remotefortressreader.cpp b/plugins/remotefortressreader.cpp index 3ef673119..8c1307f61 100644 --- a/plugins/remotefortressreader.cpp +++ b/plugins/remotefortressreader.cpp @@ -56,6 +56,9 @@ using namespace df::enums; using namespace RemoteFortressReader; using namespace std; +DFHACK_PLUGIN("RemoteFortressReader"); +REQUIRE_GLOBAL(world); + // Here go all the command declarations... // mostly to allow having the mandatory stuff on top of the file and commands on the bottom @@ -80,10 +83,6 @@ const char* growth_locations[] = { }; #define GROWTH_LOCATIONS_SIZE 8 -// A plugin must be able to return its name and version. -// The name string provided must correspond to the filename - skeleton.plug.so or skeleton.plug.dll in this case -DFHACK_PLUGIN("RemoteFortressReader"); - // Mandatory init function. If you have some global state, create it here. DFhackCExport command_result plugin_init(color_ostream &out, std::vector &commands) { @@ -387,9 +386,9 @@ RemoteFortressReader::TiletypeVariant TranslateVariant(df::tiletype_variant vari static command_result CheckHashes(color_ostream &stream, const EmptyMessage *in) { clock_t start = clock(); - for (int i = 0; i < df::global::world->map.map_blocks.size(); i++) + for (int i = 0; i < world->map.map_blocks.size(); i++) { - df::map_block * block = df::global::world->map.map_blocks[i]; + df::map_block * block = world->map.map_blocks[i]; fletcher16((uint8_t*)(block->tiletype), 16 * 16 * sizeof(df::enums::tiletype::tiletype)); } clock_t end = clock(); @@ -417,7 +416,7 @@ static command_result GetMaterialList(color_ostream &stream, const EmptyMessage - df::world_raws *raws = &df::global::world->raws; + df::world_raws *raws = &world->raws; MaterialInfo mat; for (int i = 0; i < raws->inorganics.size(); i++) { @@ -509,7 +508,7 @@ static command_result GetGrowthList(color_ostream &stream, const EmptyMessage *i - df::world_raws *raws = &df::global::world->raws; + df::world_raws *raws = &world->raws; if (!raws) return CR_OK;//'. @@ -617,9 +616,9 @@ static command_result GetPlantList(color_ostream &stream, const BlockRequest *in for (int xx = min_x; xx < max_x; xx++) for (int yy = min_y; yy < max_y; yy++) { - if (xx < 0 || yy < 0 || xx >= df::global::world->map.x_count_block || yy >= df::global::world->map.y_count_block) + if (xx < 0 || yy < 0 || xx >= world->map.x_count_block || yy >= world->map.y_count_block) continue; - df::map_block_column * column = df::global::world->map.column_index[xx][yy]; + df::map_block_column * column = world->map.column_index[xx][yy]; for (int i = 0; i < column->plants.size(); i++) { df::plant * plant = column->plants[i]; diff --git a/plugins/rename.cpp b/plugins/rename.cpp index 383066b5e..0ef3e02d5 100644 --- a/plugins/rename.cpp +++ b/plugins/rename.cpp @@ -46,17 +46,17 @@ using namespace DFHack; using namespace df::enums; using namespace dfproto; -using df::global::ui; -using df::global::ui_sidebar_menus; -using df::global::world; +DFHACK_PLUGIN("rename"); +DFHACK_PLUGIN_IS_ENABLED(is_enabled); + +REQUIRE_GLOBAL(ui); +REQUIRE_GLOBAL(ui_sidebar_menus); +REQUIRE_GLOBAL(world); DFhackCExport command_result plugin_onstatechange(color_ostream &out, state_change_event event); static command_result rename(color_ostream &out, vector & parameters); -DFHACK_PLUGIN("rename"); -DFHACK_PLUGIN_IS_ENABLED(is_enabled); - DFhackCExport command_result plugin_init (color_ostream &out, std::vector &commands) { if (world && ui) { diff --git a/plugins/rendermax/rendermax.cpp b/plugins/rendermax/rendermax.cpp index a6b2f17c7..a2edd3b0a 100644 --- a/plugins/rendermax/rendermax.cpp +++ b/plugins/rendermax/rendermax.cpp @@ -28,6 +28,21 @@ using df::viewscreen_dwarfmodest; using namespace DFHack; using std::vector; using std::string; + +DFHACK_PLUGIN("rendermax"); +REQUIRE_GLOBAL(cur_year_tick); +REQUIRE_GLOBAL(cursor); +REQUIRE_GLOBAL(enabler); +REQUIRE_GLOBAL(gametype); +REQUIRE_GLOBAL(gps); +REQUIRE_GLOBAL(ui); +REQUIRE_GLOBAL(ui_area_map_width); +REQUIRE_GLOBAL(ui_menu_width); +REQUIRE_GLOBAL(window_x); +REQUIRE_GLOBAL(window_y); +REQUIRE_GLOBAL(window_z); +REQUIRE_GLOBAL(world); + enum RENDERER_MODE { MODE_DEFAULT,MODE_TRIPPY,MODE_TRUECOLOR,MODE_LUA,MODE_LIGHT @@ -37,9 +52,6 @@ lightingEngine *engine=NULL; static command_result rendermax(color_ostream &out, vector & parameters); -DFHACK_PLUGIN("rendermax"); - - DFhackCExport command_result plugin_init (color_ostream &out, std::vector &commands) { commands.push_back(PluginCommand( @@ -93,34 +105,34 @@ void removeOld() engine=0; } if(current_mode!=MODE_DEFAULT) - delete df::global::enabler->renderer; + delete enabler->renderer; current_mode=MODE_DEFAULT; } void installNew(df::renderer* r,RENDERER_MODE newMode) { - df::global::enabler->renderer=r; + enabler->renderer=r; current_mode=newMode; } static void lockGrids() { if(current_mode!=MODE_LUA) return ; - renderer_lua* r=reinterpret_cast(df::global::enabler->renderer); + renderer_lua* r=reinterpret_cast(enabler->renderer); r->dataMutex.lock(); } static void unlockGrids() { if(current_mode!=MODE_LUA) return ; - renderer_lua* r=reinterpret_cast(df::global::enabler->renderer); + renderer_lua* r=reinterpret_cast(enabler->renderer); r->dataMutex.unlock(); } static void resetGrids() { if(current_mode!=MODE_LUA) return ; - renderer_lua* r=reinterpret_cast(df::global::enabler->renderer); + renderer_lua* r=reinterpret_cast(enabler->renderer); for(size_t i=0;iforeMult.size();i++) { r->foreMult[i]=rgbf(1,1,1); @@ -133,16 +145,16 @@ static int getGridsSize(lua_State* L) { if(current_mode!=MODE_LUA) return -1; - renderer_lua* r=reinterpret_cast(df::global::enabler->renderer); - lua_pushnumber(L,df::global::gps->dimx); - lua_pushnumber(L,df::global::gps->dimy); + renderer_lua* r=reinterpret_cast(enabler->renderer); + lua_pushnumber(L,gps->dimx); + lua_pushnumber(L,gps->dimy); return 2; } static int getCell(lua_State* L) { if(current_mode!=MODE_LUA) return 0; - renderer_lua* r=reinterpret_cast(df::global::enabler->renderer); + renderer_lua* r=reinterpret_cast(enabler->renderer); int x=luaL_checknumber(L,1); int y=luaL_checknumber(L,2); int id=r->xyToTile(x,y); @@ -193,7 +205,7 @@ static int setCell(lua_State* L) { if(current_mode!=MODE_LUA) return 0; - renderer_lua* r=reinterpret_cast(df::global::enabler->renderer); + renderer_lua* r=reinterpret_cast(enabler->renderer); int x=luaL_checknumber(L,1); int y=luaL_checknumber(L,2); @@ -242,7 +254,7 @@ static int invalidate(lua_State* L) { if(current_mode!=MODE_LUA) return 0; - renderer_lua* r=reinterpret_cast(df::global::enabler->renderer); + renderer_lua* r=reinterpret_cast(enabler->renderer); if(lua_gettop(L)==0) { r->invalidate(); @@ -324,7 +336,7 @@ static command_result rendermax(color_ostream &out, vector & parameters { if(parameters.size()==0) return CR_WRONG_USAGE; - if(!df::global::enabler->renderer->uses_opengl()) + if(!enabler->renderer->uses_opengl()) { out.printerr("Sorry, this plugin needs open gl enabled printmode. Try STANDARD or other non-2D\n"); return CR_FAILURE; @@ -333,7 +345,7 @@ static command_result rendermax(color_ostream &out, vector & parameters if(cmd=="trippy") { removeOld(); - installNew(new renderer_trippy(df::global::enabler->renderer),MODE_TRIPPY); + installNew(new renderer_trippy(enabler->renderer),MODE_TRIPPY); return CR_OK; } else if(cmd=="truecolor") @@ -341,7 +353,7 @@ static command_result rendermax(color_ostream &out, vector & parameters if(current_mode!=MODE_TRUECOLOR) { removeOld(); - installNew(new renderer_test(df::global::enabler->renderer),MODE_TRUECOLOR); + installNew(new renderer_test(enabler->renderer),MODE_TRUECOLOR); } if(current_mode==MODE_TRUECOLOR && parameters.size()==2) { @@ -356,10 +368,10 @@ static command_result rendermax(color_ostream &out, vector & parameters else if(col=="blue") cur=blue; - renderer_test* r=reinterpret_cast(df::global::enabler->renderer); + renderer_test* r=reinterpret_cast(enabler->renderer); tthread::lock_guard guard(r->dataMutex); - int h=df::global::gps->dimy; - int w=df::global::gps->dimx; + int h=gps->dimy; + int w=gps->dimx; int cx=w/2; int cy=h/2; int rad=cx; @@ -385,7 +397,7 @@ static command_result rendermax(color_ostream &out, vector & parameters else if(cmd=="lua") { removeOld(); - installNew(new renderer_lua(df::global::enabler->renderer),MODE_LUA); + installNew(new renderer_lua(enabler->renderer),MODE_LUA); lockGrids(); resetGrids(); unlockGrids(); @@ -396,7 +408,7 @@ static command_result rendermax(color_ostream &out, vector & parameters if(current_mode!=MODE_LIGHT) { removeOld(); - renderer_light *myRender=new renderer_light(df::global::enabler->renderer); + renderer_light *myRender=new renderer_light(enabler->renderer); installNew(myRender,MODE_LIGHT); engine=new lightingEngineViewscreen(myRender); @@ -444,7 +456,7 @@ static command_result rendermax(color_ostream &out, vector & parameters else removeOld(); CoreSuspender guard; - df::global::gps->force_full_display_count++; + gps->force_full_display_count++; return CR_OK; } return CR_WRONG_USAGE; diff --git a/plugins/resume.cpp b/plugins/resume.cpp index 01127ef94..e0db688ff 100644 --- a/plugins/resume.cpp +++ b/plugins/resume.cpp @@ -34,13 +34,13 @@ using std::vector; using namespace DFHack; using namespace df::enums; -using df::global::gps; -using df::global::ui; -using df::global::world; - DFHACK_PLUGIN("resume"); #define PLUGIN_VERSION 0.2 +REQUIRE_GLOBAL(gps); +REQUIRE_GLOBAL(ui); +REQUIRE_GLOBAL(world); + #ifndef HAVE_NULLPTR #define nullptr 0L #endif diff --git a/plugins/reveal.cpp b/plugins/reveal.cpp index c0d71bb7b..c6b7cafbf 100644 --- a/plugins/reveal.cpp +++ b/plugins/reveal.cpp @@ -20,7 +20,10 @@ using std::vector; using namespace DFHack; using namespace df::enums; -using df::global::world; +DFHACK_PLUGIN("reveal"); +DFHACK_PLUGIN_IS_ENABLED(is_active); + +REQUIRE_GLOBAL(world); /* * Anything that might reveal Hell is unsafe. @@ -72,8 +75,6 @@ command_result revflood(color_ostream &out, vector & params); command_result revforget(color_ostream &out, vector & params); command_result nopause(color_ostream &out, vector & params); -DFHACK_PLUGIN("reveal"); - DFhackCExport command_result plugin_init ( color_ostream &out, vector &commands) { commands.push_back(PluginCommand("reveal","Reveal the map. 'reveal hell' will also reveal hell. 'reveal demon' won't pause.",reveal,false, @@ -96,8 +97,6 @@ DFhackCExport command_result plugin_init ( color_ostream &out, vector abbreviations; @@ -250,8 +253,6 @@ command_result df_seedwatch(color_ostream &out, vector& parameters) return CR_OK; } -DFHACK_PLUGIN("seedwatch"); - DFhackCExport command_result plugin_init(color_ostream &out, vector& commands) { commands.push_back(PluginCommand("seedwatch", "Switches cookery based on quantity of seeds, to keep reserves", df_seedwatch)); diff --git a/plugins/showmood.cpp b/plugins/showmood.cpp index e0bc5a08d..34b2c8f44 100644 --- a/plugins/showmood.cpp +++ b/plugins/showmood.cpp @@ -25,7 +25,8 @@ using std::vector; using namespace DFHack; using namespace df::enums; -using df::global::world; +DFHACK_PLUGIN("showmood"); +REQUIRE_GLOBAL(world); command_result df_showmood (color_ostream &out, vector & parameters) { @@ -291,8 +292,6 @@ command_result df_showmood (color_ostream &out, vector & parameters) return CR_OK; } -DFHACK_PLUGIN("showmood"); - DFhackCExport command_result plugin_init (color_ostream &out, std::vector &commands) { commands.push_back(PluginCommand("showmood", "Shows items needed for current strange mood.", df_showmood, false, diff --git a/plugins/siege-engine.cpp b/plugins/siege-engine.cpp index b3e5a208d..4ad8fa341 100644 --- a/plugins/siege-engine.cpp +++ b/plugins/siege-engine.cpp @@ -65,16 +65,15 @@ using std::stack; using namespace DFHack; using namespace df::enums; -using df::global::gamemode; -using df::global::gps; -using df::global::world; -using df::global::ui; -using df::global::ui_build_selector; -using df::global::process_jobs; - using Screen::Pen; DFHACK_PLUGIN("siege-engine"); +REQUIRE_GLOBAL(gamemode); +REQUIRE_GLOBAL(gps); +REQUIRE_GLOBAL(world); +REQUIRE_GLOBAL(ui); +REQUIRE_GLOBAL(ui_build_selector); +REQUIRE_GLOBAL(process_jobs); /* Aiming is simulated by using a normal distribution to perturb X and Y. diff --git a/plugins/sort.cpp b/plugins/sort.cpp index e4aad61e2..7d80b4aa1 100644 --- a/plugins/sort.cpp +++ b/plugins/sort.cpp @@ -37,14 +37,15 @@ using std::endl; using namespace DFHack; using namespace df::enums; -using df::global::ui; -using df::global::world; -using df::global::ui_building_in_assign; -using df::global::ui_building_item_cursor; -using df::global::ui_building_assign_type; -using df::global::ui_building_assign_is_marked; -using df::global::ui_building_assign_units; -using df::global::ui_building_assign_items; +DFHACK_PLUGIN("sort"); +REQUIRE_GLOBAL(ui); +REQUIRE_GLOBAL(world); +REQUIRE_GLOBAL(ui_building_in_assign); +REQUIRE_GLOBAL(ui_building_item_cursor); +REQUIRE_GLOBAL(ui_building_assign_type); +REQUIRE_GLOBAL(ui_building_assign_is_marked); +REQUIRE_GLOBAL(ui_building_assign_units); +REQUIRE_GLOBAL(ui_building_assign_items); static bool unit_list_hotkey(df::viewscreen *top); static bool item_list_hotkey(df::viewscreen *top); @@ -52,8 +53,6 @@ static bool item_list_hotkey(df::viewscreen *top); static command_result sort_units(color_ostream &out, vector & parameters); static command_result sort_items(color_ostream &out, vector & parameters); -DFHACK_PLUGIN("sort"); - DFhackCExport command_result plugin_init (color_ostream &out, std::vector &commands) { commands.push_back(PluginCommand( diff --git a/plugins/steam-engine.cpp b/plugins/steam-engine.cpp index 138de3916..2a22d5953 100644 --- a/plugins/steam-engine.cpp +++ b/plugins/steam-engine.cpp @@ -117,14 +117,14 @@ using std::set; using namespace DFHack; using namespace df::enums; -using df::global::gps; -using df::global::world; -using df::global::ui; -using df::global::ui_build_selector; -using df::global::cursor; - DFHACK_PLUGIN("steam-engine"); +REQUIRE_GLOBAL(gps); +REQUIRE_GLOBAL(world); +REQUIRE_GLOBAL(ui); +REQUIRE_GLOBAL(ui_build_selector); +REQUIRE_GLOBAL(cursor); + /* * List of known steam engine workshop raws. */ diff --git a/plugins/stockflow.cpp b/plugins/stockflow.cpp index 257680682..33068479e 100644 --- a/plugins/stockflow.cpp +++ b/plugins/stockflow.cpp @@ -18,12 +18,9 @@ using namespace DFHack; using namespace std; -using df::global::world; -using df::global::ui; using df::building_stockpilest; DFHACK_PLUGIN("stockflow"); - #define AUTOENABLE false #ifdef DFHACK_PLUGIN_IS_ENABLED DFHACK_PLUGIN_IS_ENABLED(enabled); @@ -31,6 +28,9 @@ DFHACK_PLUGIN_IS_ENABLED(enabled); bool enabled = false; #endif +REQUIRE_GLOBAL(world); +REQUIRE_GLOBAL(ui); + bool fast = false; const char *tagline = "Allows the fortress bookkeeper to queue jobs through the manager."; const char *usage = ( @@ -72,7 +72,7 @@ public: } else { // Gather orders when the bookkeeper starts updating stockpile records, // and enqueue them when the job is done. - for (df::job_list_link* link = &df::global::world->job_list; link != NULL; link = link->next) { + for (df::job_list_link* link = &world->job_list; link != NULL; link = link->next) { if (link->item == NULL) continue; if (link->item->job_type == job_type::UpdateStockpileRecords) { found = true; diff --git a/plugins/stockpiles.cpp b/plugins/stockpiles.cpp index ebf4b0d40..ae257c55a 100644 --- a/plugins/stockpiles.cpp +++ b/plugins/stockpiles.cpp @@ -58,9 +58,10 @@ using namespace df::enums; using namespace google::protobuf; using namespace dfstockpiles; -using df::global::world; -using df::global::ui; -using df::global::selection_rect; +DFHACK_PLUGIN ( "stockpiles" ); +REQUIRE_GLOBAL ( world ); +REQUIRE_GLOBAL ( ui ); +REQUIRE_GLOBAL ( selection_rect ); using df::building_stockpilest; using std::placeholders::_1; @@ -74,8 +75,6 @@ static bool savestock_guard ( df::viewscreen *top ); static command_result loadstock ( color_ostream &out, vector & parameters ); static bool loadstock_guard ( df::viewscreen *top ); -DFHACK_PLUGIN ( "stockpiles" ); - DFhackCExport command_result plugin_init ( color_ostream &out, std::vector &commands ) { if ( world && ui ) diff --git a/plugins/stocks.cpp b/plugins/stocks.cpp index c5fbed4d5..56692d5c4 100644 --- a/plugins/stocks.cpp +++ b/plugins/stocks.cpp @@ -28,11 +28,11 @@ #include "df/building_cagest.h" #include "df/ui_advmode.h" -using df::global::world; - DFHACK_PLUGIN("stocks"); #define PLUGIN_VERSION 0.12 +REQUIRE_GLOBAL(world); + DFhackCExport command_result plugin_shutdown ( color_ostream &out ) { return CR_OK; diff --git a/plugins/strangemood.cpp b/plugins/strangemood.cpp index 74c717816..09c4ead11 100644 --- a/plugins/strangemood.cpp +++ b/plugins/strangemood.cpp @@ -32,15 +32,17 @@ using std::vector; using namespace DFHack; using namespace df::enums; -using df::global::world; -using df::global::ui; -using df::global::d_init; -using df::global::created_item_count; -using df::global::created_item_type; -using df::global::created_item_subtype; -using df::global::created_item_mattype; -using df::global::created_item_matindex; -using df::global::debug_nomoods; +DFHACK_PLUGIN("strangemood"); + +REQUIRE_GLOBAL(world); +REQUIRE_GLOBAL(ui); +REQUIRE_GLOBAL(d_init); +REQUIRE_GLOBAL(created_item_count); +REQUIRE_GLOBAL(created_item_type); +REQUIRE_GLOBAL(created_item_subtype); +REQUIRE_GLOBAL(created_item_mattype); +REQUIRE_GLOBAL(created_item_matindex); +REQUIRE_GLOBAL(debug_nomoods); Random::MersenneRNG rng; @@ -1302,8 +1304,6 @@ command_result df_strangemood (color_ostream &out, vector & parameters) return CR_OK; } -DFHACK_PLUGIN("strangemood"); - DFhackCExport command_result plugin_init (color_ostream &out, std::vector &commands) { commands.push_back(PluginCommand("strangemood", "Force a strange mood to happen.\n", df_strangemood, false, diff --git a/plugins/tiletypes.cpp b/plugins/tiletypes.cpp index b624b944f..1a249825c 100644 --- a/plugins/tiletypes.cpp +++ b/plugins/tiletypes.cpp @@ -44,7 +44,8 @@ using namespace MapExtras; using namespace DFHack; using namespace df::enums; -using df::global::world; +DFHACK_PLUGIN("tiletypes"); +REQUIRE_GLOBAL(world); CommandHistory tiletypes_hist; @@ -53,8 +54,6 @@ command_result df_tiletypes_command (color_ostream &out, vector & param command_result df_tiletypes_here (color_ostream &out, vector & parameters); command_result df_tiletypes_here_point (color_ostream &out, vector & parameters); -DFHACK_PLUGIN("tiletypes"); - DFhackCExport command_result plugin_init ( color_ostream &out, std::vector &commands) { tiletypes_hist.load("tiletypes.history"); diff --git a/plugins/trackstop.cpp b/plugins/trackstop.cpp index c7109191a..a10b0105b 100644 --- a/plugins/trackstop.cpp +++ b/plugins/trackstop.cpp @@ -15,18 +15,18 @@ using namespace DFHack; using namespace std; -using df::global::world; -using df::global::ui; using df::building_rollersst; using df::building_trapst; using df::enums::trap_type::trap_type; using df::enums::screw_pump_direction::screw_pump_direction; DFHACK_PLUGIN("trackstop"); - #define AUTOENABLE false DFHACK_PLUGIN_IS_ENABLED(enabled); +REQUIRE_GLOBAL(gps); +REQUIRE_GLOBAL(ui); +REQUIRE_GLOBAL(world); /* * Interface hooks @@ -270,14 +270,6 @@ IMPLEMENT_VMETHOD_INTERPOSE(roller_hook, render); DFhackCExport command_result plugin_enable(color_ostream& out, bool enable) { // Accept the "enable trackstop" / "disable trackstop" commands. if (enable != enabled) { - // Check for global variables that, if missing, result in total failure. - // Missing enabler and ui_menu_width also produce visible effects, but not nearly as severe. - // This could be moved to the plugin_init step, but that's louder for no real benefit. - if (!(gps && ui && world)) { - out.printerr("trackstop: Missing required global variables.\n"); - return CR_FAILURE; - } - if (!INTERPOSE_HOOK(trackstop_hook, feed).apply(enable) || !INTERPOSE_HOOK(trackstop_hook, render).apply(enable) || !INTERPOSE_HOOK(roller_hook, feed).apply(enable) || diff --git a/plugins/treefarm.cpp b/plugins/treefarm.cpp index 6660b07f8..1578bf373 100644 --- a/plugins/treefarm.cpp +++ b/plugins/treefarm.cpp @@ -21,8 +21,11 @@ using namespace DFHack; -using df::global::world; -using df::global::ui; +DFHACK_PLUGIN("treefarm"); +DFHACK_PLUGIN_IS_ENABLED(enabled); + +REQUIRE_GLOBAL(world); +REQUIRE_GLOBAL(ui); void checkFarms(color_ostream& out, void* ptr); command_result treefarm (color_ostream &out, std::vector & parameters); @@ -30,9 +33,6 @@ command_result treefarm (color_ostream &out, std::vector & paramet EventManager::EventHandler handler(&checkFarms, -1); int32_t frequency = 1200*30; -DFHACK_PLUGIN_IS_ENABLED(enabled); -DFHACK_PLUGIN("treefarm"); - DFhackCExport command_result plugin_init ( color_ostream &out, std::vector &commands) { commands.push_back(PluginCommand( diff --git a/plugins/tubefill.cpp b/plugins/tubefill.cpp index efdc6f1a9..73c615c9b 100644 --- a/plugins/tubefill.cpp +++ b/plugins/tubefill.cpp @@ -17,7 +17,9 @@ using namespace DFHack; using namespace df::enums; -using df::global::world; + +DFHACK_PLUGIN("tubefill"); +REQUIRE_GLOBAL(world); bool isDesignatedHollow(df::coord pos) { @@ -33,8 +35,6 @@ bool isDesignatedHollow(df::coord pos) command_result tubefill(color_ostream &out, std::vector & params); -DFHACK_PLUGIN("tubefill"); - DFhackCExport command_result plugin_init ( color_ostream &out, std::vector &commands) { commands.push_back(PluginCommand("tubefill","Fill in all the adamantine tubes again.",tubefill, false, diff --git a/plugins/tweak/tweak.cpp b/plugins/tweak/tweak.cpp index d49fbe2da..8e53dc0a7 100644 --- a/plugins/tweak/tweak.cpp +++ b/plugins/tweak/tweak.cpp @@ -92,19 +92,20 @@ using std::endl; using namespace DFHack; using namespace df::enums; -using df::global::ui; -using df::global::world; -using df::global::ui_build_selector; -using df::global::ui_menu_width; -using df::global::ui_area_map_width; +DFHACK_PLUGIN("tweak"); + +REQUIRE_GLOBAL(ui); +REQUIRE_GLOBAL(ui_build_selector); +REQUIRE_GLOBAL(ui_building_item_cursor); +REQUIRE_GLOBAL(ui_menu_width); +REQUIRE_GLOBAL(ui_area_map_width); +REQUIRE_GLOBAL(world); using namespace DFHack::Gui; static command_result tweak(color_ostream &out, vector & parameters); static std::multimap tweak_hooks; -DFHACK_PLUGIN("tweak"); - #define TWEAK_HOOK(tweak, cls, func) tweak_hooks.insert(std::pair\ (tweak, INTERPOSE_HOOK(cls, func))) diff --git a/plugins/weather.cpp b/plugins/weather.cpp index e94f56dab..481c1a779 100644 --- a/plugins/weather.cpp +++ b/plugins/weather.cpp @@ -13,15 +13,15 @@ using std::string; using namespace DFHack; using namespace df::enums; -using df::global::current_weather; +DFHACK_PLUGIN("weather"); + +REQUIRE_GLOBAL(current_weather); bool locked = false; unsigned char locked_data[25]; command_result weather (color_ostream &out, vector & parameters); -DFHACK_PLUGIN("weather"); - DFhackCExport command_result plugin_init ( color_ostream &out, std::vector &commands) { commands.push_back(PluginCommand( diff --git a/plugins/workNow.cpp b/plugins/workNow.cpp index e8f34939a..b26428f8a 100644 --- a/plugins/workNow.cpp +++ b/plugins/workNow.cpp @@ -14,10 +14,9 @@ using namespace std; using namespace DFHack; -using df::global::process_jobs; -using df::global::process_dig; - DFHACK_PLUGIN("workNow"); +REQUIRE_GLOBAL(process_jobs); +REQUIRE_GLOBAL(process_dig); static int mode = 0; diff --git a/plugins/workflow.cpp b/plugins/workflow.cpp index 16baec260..3ee0097df 100644 --- a/plugins/workflow.cpp +++ b/plugins/workflow.cpp @@ -49,10 +49,12 @@ using std::flush; using namespace DFHack; using namespace df::enums; -using df::global::world; -using df::global::ui; -using df::global::ui_workshop_job_cursor; -using df::global::job_next_id; +DFHACK_PLUGIN("workflow"); + +REQUIRE_GLOBAL(world); +REQUIRE_GLOBAL(ui); +REQUIRE_GLOBAL(ui_workshop_job_cursor); +REQUIRE_GLOBAL(job_next_id); /* Plugin registration */ @@ -61,8 +63,6 @@ static command_result workflow_cmd(color_ostream &out, vector & paramet static void init_state(color_ostream &out); static void cleanup_state(color_ostream &out); -DFHACK_PLUGIN("workflow"); - DFhackCExport command_result plugin_init (color_ostream &out, std::vector &commands) { if (!world || !ui) diff --git a/plugins/zone.cpp b/plugins/zone.cpp index c88e82154..386200d41 100644 --- a/plugins/zone.cpp +++ b/plugins/zone.cpp @@ -74,23 +74,27 @@ using std::vector; using std::string; using namespace DFHack; using namespace df::enums; -using df::global::world; -using df::global::cursor; -using df::global::ui; -using df::global::ui_build_selector; -using df::global::gps; -using df::global::cur_year; -using df::global::cur_year_tick; - -using df::global::ui_building_item_cursor; -using df::global::ui_building_assign_type; -using df::global::ui_building_assign_is_marked; -using df::global::ui_building_assign_units; -using df::global::ui_building_assign_items; -using df::global::ui_building_in_assign; - -using df::global::ui_menu_width; -using df::global::ui_area_map_width; + +DFHACK_PLUGIN("zone"); +DFHACK_PLUGIN_IS_ENABLED(is_enabled); + +REQUIRE_GLOBAL(world); +REQUIRE_GLOBAL(cursor); +REQUIRE_GLOBAL(ui); +REQUIRE_GLOBAL(ui_build_selector); +REQUIRE_GLOBAL(gps); +REQUIRE_GLOBAL(cur_year); +REQUIRE_GLOBAL(cur_year_tick); + +REQUIRE_GLOBAL(ui_building_item_cursor); +REQUIRE_GLOBAL(ui_building_assign_type); +REQUIRE_GLOBAL(ui_building_assign_is_marked); +REQUIRE_GLOBAL(ui_building_assign_units); +REQUIRE_GLOBAL(ui_building_assign_items); +REQUIRE_GLOBAL(ui_building_in_assign); + +REQUIRE_GLOBAL(ui_menu_width); +REQUIRE_GLOBAL(ui_area_map_width); using namespace DFHack::Gui; @@ -98,10 +102,6 @@ command_result df_zone (color_ostream &out, vector & parameters); command_result df_autonestbox (color_ostream &out, vector & parameters); command_result df_autobutcher(color_ostream &out, vector & parameters); -DFHACK_PLUGIN("zone"); - -DFHACK_PLUGIN_IS_ENABLED(is_enabled); - DFhackCExport command_result plugin_enable ( color_ostream &out, bool enable); const string zone_help = From 88b51fcb5b5ba23fca194555253cb7051afe0cb9 Mon Sep 17 00:00:00 2001 From: lethosor Date: Sat, 6 Dec 2014 20:29:08 -0500 Subject: [PATCH 5/6] Allow strangemood to work if debug_nomoods is not available --- plugins/strangemood.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/strangemood.cpp b/plugins/strangemood.cpp index 09c4ead11..22bafc056 100644 --- a/plugins/strangemood.cpp +++ b/plugins/strangemood.cpp @@ -42,7 +42,7 @@ REQUIRE_GLOBAL(created_item_type); REQUIRE_GLOBAL(created_item_subtype); REQUIRE_GLOBAL(created_item_mattype); REQUIRE_GLOBAL(created_item_matindex); -REQUIRE_GLOBAL(debug_nomoods); +using df::global::debug_nomoods; Random::MersenneRNG rng; @@ -476,7 +476,7 @@ command_result df_strangemood (color_ostream &out, vector & parameters) out.printerr("ARTIFACTS are not enabled!\n"); return CR_FAILURE; } - if (*debug_nomoods) + if (debug_nomoods && *debug_nomoods) { out.printerr("Strange moods disabled via debug flag!\n"); return CR_FAILURE; From 09681cf029993a2e8c5d0bae055e2f9f06d3d631 Mon Sep 17 00:00:00 2001 From: lethosor Date: Sat, 6 Dec 2014 20:55:57 -0500 Subject: [PATCH 6/6] Update skeleton plugin --- plugins/skeleton/skeleton.cpp | 22 ++++++++++++++-------- plugins/skeleton/skeletonShort.cpp | 9 +++++---- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/plugins/skeleton/skeleton.cpp b/plugins/skeleton/skeleton.cpp index 293e43c8d..ea2f4fb4a 100644 --- a/plugins/skeleton/skeleton.cpp +++ b/plugins/skeleton/skeleton.cpp @@ -10,23 +10,29 @@ #include "DataDefs.h" //#include "df/world.h" +// our own, empty header. +#include "skeleton.h" + using namespace DFHack; using namespace df::enums; -// our own, empty header. -#include "skeleton.h" +// A plugin must be able to return its name and version. +// The name string provided must correspond to the filename - +// skeleton.plug.so, skeleton.plug.dylib, or skeleton.plug.dll in this case +DFHACK_PLUGIN("skeleton"); +// Any globals a plugin requires (e.g. world) should be listed here. +// For example, this line expands to "using df::global::world" and prevents the +// plugin from being loaded if df::global::world is null (i.e. missing from symbols.xml): +// +// REQUIRE_GLOBAL(world); // Here go all the command declarations... // mostly to allow having the mandatory stuff on top of the file and commands on the bottom command_result skeleton (color_ostream &out, std::vector & parameters); -// A plugin must be able to return its name and version. -// The name string provided must correspond to the filename - skeleton.plug.so or skeleton.plug.dll in this case -DFHACK_PLUGIN("skeleton"); - // Mandatory init function. If you have some global state, create it here. -DFhackCExport command_result plugin_init ( color_ostream &out, std::vector &commands) +DFhackCExport command_result plugin_init (color_ostream &out, std::vector &commands) { // Fill the command list with your commands. commands.push_back(PluginCommand( @@ -42,7 +48,7 @@ DFhackCExport command_result plugin_init ( color_ostream &out, std::vector & parameters); - DFHACK_PLUGIN("skeleton2"); +//REQUIRE_GLOBAL(world); + +command_result skeleton2 (color_ostream &out, std::vector & parameters); -DFhackCExport command_result plugin_init ( color_ostream &out, std::vector &commands) +DFhackCExport command_result plugin_init (color_ostream &out, std::vector &commands) { commands.push_back(PluginCommand( "skeleton2", @@ -24,7 +25,7 @@ DFhackCExport command_result plugin_init ( color_ostream &out, std::vector