Update the devel plugins.

develop
Alexander Gavrilov 2012-03-10 17:25:00 +04:00
parent 8cc82d5876
commit 522dd1fd10
10 changed files with 185 additions and 210 deletions

@ -18,40 +18,38 @@ using std::string;
using std::stack; using std::stack;
using namespace DFHack; using namespace DFHack;
command_result readFlag (Core * c, vector <string> & parameters); command_result readFlag (color_ostream &out, vector <string> & parameters);
command_result writeFlag (Core * c, vector <string> & parameters); command_result writeFlag (color_ostream &out, vector <string> & parameters);
DFHACK_PLUGIN("buildprobe"); DFHACK_PLUGIN("buildprobe");
DFhackCExport command_result plugin_init ( Core * c, std::vector <PluginCommand> &commands) DFhackCExport command_result plugin_init ( color_ostream &out, std::vector <PluginCommand> &commands)
{ {
commands.push_back(PluginCommand("bshow","Output building occupancy value",readFlag)); commands.push_back(PluginCommand("bshow","Output building occupancy value",readFlag));
commands.push_back(PluginCommand("bset","Set building occupancy value",writeFlag)); commands.push_back(PluginCommand("bset","Set building occupancy value",writeFlag));
return CR_OK; return CR_OK;
} }
DFhackCExport command_result plugin_shutdown ( Core * c ) DFhackCExport command_result plugin_shutdown ( color_ostream &out )
{ {
return CR_OK; return CR_OK;
} }
command_result readFlag (Core * c, vector <string> & parameters) command_result readFlag (color_ostream &out, vector <string> & parameters)
{ {
c->Suspend(); CoreSuspender suspend;
// init the map // init the map
if(!Maps::IsValid()) if(!Maps::IsValid())
{ {
c->con.printerr("Can't init map. Make sure you have a map loaded in DF.\n"); out.printerr("Can't init map. Make sure you have a map loaded in DF.\n");
c->Resume();
return CR_FAILURE; return CR_FAILURE;
} }
int32_t cx, cy, cz; int32_t cx, cy, cz;
if(!Gui::getCursorCoords(cx,cy,cz)) if(!Gui::getCursorCoords(cx,cy,cz))
{ {
c->con.printerr("Cursor is not active.\n"); out.printerr("Cursor is not active.\n");
c->Resume();
return CR_FAILURE; return CR_FAILURE;
} }
@ -60,23 +58,21 @@ command_result readFlag (Core * c, vector <string> & parameters)
MapExtras::MapCache * MCache = new MapExtras::MapCache(); MapExtras::MapCache * MCache = new MapExtras::MapCache();
t_occupancy oc = MCache->occupancyAt(cursor); t_occupancy oc = MCache->occupancyAt(cursor);
c->con.print("Current Value: %d\n", oc.bits.building); out.print("Current Value: %d\n", oc.bits.building);
c->Resume();
return CR_OK; return CR_OK;
} }
command_result writeFlag (Core * c, vector <string> & parameters) command_result writeFlag (color_ostream &out, vector <string> & parameters)
{ {
if (parameters.size() == 0) if (parameters.size() == 0)
{ {
c->con.print("No value specified\n"); out.print("No value specified\n");
return CR_FAILURE; return CR_FAILURE;
} }
if (parameters[0] == "help" || parameters[0] == "?") if (parameters[0] == "help" || parameters[0] == "?")
{ {
c->con.print("Set the building occupancy flag.\n" out.print("Set the building occupancy flag.\n"
"Value must be between 0 and 7, inclusive.\n"); "Value must be between 0 and 7, inclusive.\n");
return CR_OK; return CR_OK;
} }
@ -97,26 +93,24 @@ command_result writeFlag (Core * c, vector <string> & parameters)
break; break;
default: default:
c->con.print("Invalid value specified\n"); out.print("Invalid value specified\n");
return CR_FAILURE; return CR_FAILURE;
break; //Redundant. break; //Redundant.
} }
c->Suspend(); CoreSuspender suspend;
// init the map // init the map
if(!Maps::IsValid()) if(!Maps::IsValid())
{ {
c->con.printerr("Can't init map. Make sure you have a map loaded in DF.\n"); out.printerr("Can't init map. Make sure you have a map loaded in DF.\n");
c->Resume();
return CR_FAILURE; return CR_FAILURE;
} }
int32_t cx, cy, cz; int32_t cx, cy, cz;
if(!Gui::getCursorCoords(cx,cy,cz)) if(!Gui::getCursorCoords(cx,cy,cz))
{ {
c->con.printerr("Cursor is not active.\n"); out.printerr("Cursor is not active.\n");
c->Resume();
return CR_FAILURE; return CR_FAILURE;
} }
@ -129,6 +123,5 @@ command_result writeFlag (Core * c, vector <string> & parameters)
MCache->setOccupancyAt(cursor, oc); MCache->setOccupancyAt(cursor, oc);
MCache->WriteAll(); MCache->WriteAll();
c->Resume();
return CR_OK; return CR_OK;
} }

@ -25,12 +25,12 @@ using namespace std;
using namespace DFHack; using namespace DFHack;
command_result catsplosion (Core * c, std::vector <std::string> & parameters); command_result catsplosion (color_ostream &out, std::vector <std::string> & parameters);
DFHACK_PLUGIN("catsplosion"); DFHACK_PLUGIN("catsplosion");
// Mandatory init function. If you have some global state, create it here. // Mandatory init function. If you have some global state, create it here.
DFhackCExport command_result plugin_init ( Core * c, std::vector <PluginCommand> &commands) DFhackCExport command_result plugin_init ( color_ostream &out, std::vector <PluginCommand> &commands)
{ {
// Fill the command list with your commands. // Fill the command list with your commands.
commands.push_back(PluginCommand( commands.push_back(PluginCommand(
@ -41,13 +41,13 @@ DFhackCExport command_result plugin_init ( Core * c, std::vector <PluginCommand>
return CR_OK; return CR_OK;
} }
DFhackCExport command_result plugin_shutdown ( Core * c ) DFhackCExport command_result plugin_shutdown ( color_ostream &out )
{ {
return CR_OK; return CR_OK;
} }
typedef df::unit::T_relations::T_pregnancy_ptr pregstruct; typedef df::unit::T_relations::T_pregnancy_ptr pregstruct;
command_result catsplosion (Core * c, std::vector <std::string> & parameters) command_result catsplosion (color_ostream &out, std::vector <std::string> & parameters)
{ {
list<string> s_creatures; list<string> s_creatures;
// only cats for now. // only cats for now.
@ -55,7 +55,7 @@ command_result catsplosion (Core * c, std::vector <std::string> & parameters)
// make the creature list unique ... with cats. they are always unique // make the creature list unique ... with cats. they are always unique
s_creatures.unique(); s_creatures.unique();
// SUSPEND THE CORE! ::Evil laugh:: // SUSPEND THE CORE! ::Evil laugh::
CoreSuspender susp(c); CoreSuspender susp;
uint32_t numCreatures; uint32_t numCreatures;
if(!(numCreatures = Units::getNumCreatures())) if(!(numCreatures = Units::getNumCreatures()))
@ -95,10 +95,10 @@ command_result catsplosion (Core * c, std::vector <std::string> & parameters)
// print (optional) // print (optional)
//if (showcreatures == 1) //if (showcreatures == 1)
{ {
c->con.print("Type Male # Female #\n"); out.print("Type Male # Female #\n");
for(auto it1 = male_counts.begin();it1!=male_counts.end();it1++) for(auto it1 = male_counts.begin();it1!=male_counts.end();it1++)
{ {
c->con.print("%20s %6d %8d\n", it1->first.c_str(), it1->second.size(), female_counts[it1->first].size()); out.print("%20s %6d %8d\n", it1->first.c_str(), it1->second.size(), female_counts[it1->first].size());
} }
} }
@ -133,9 +133,9 @@ command_result catsplosion (Core * c, std::vector <std::string> & parameters)
} }
} }
if(totalchanged) if(totalchanged)
c->con.print("%d pregnancies accelerated.\n", totalchanged); out.print("%d pregnancies accelerated.\n", totalchanged);
if(totalcreated) if(totalcreated)
c->con.print("%d pregnancies created.\n", totalcreated); out.print("%d pregnancies created.\n", totalcreated);
c->con.print("Total creatures checked: %d\n", totalcount); out.print("Total creatures checked: %d\n", totalcount);
return CR_OK; return CR_OK;
} }

@ -19,22 +19,22 @@ using namespace df::enums;
using df::global::world; using df::global::world;
command_result df_dumpmats (Core *c, vector<string> &parameters) command_result df_dumpmats (color_ostream &out, vector<string> &parameters)
{ {
if (!parameters.empty()) if (!parameters.empty())
return CR_WRONG_USAGE; return CR_WRONG_USAGE;
CoreSuspender suspend(c); CoreSuspender suspend;
c->con.print("hardcoded_materials\n\n"); out.print("hardcoded_materials\n\n");
c->con.print("[OBJECT:MATERIAL]\n"); out.print("[OBJECT:MATERIAL]\n");
FOR_ENUM_ITEMS(builtin_mats, mat_num) FOR_ENUM_ITEMS(builtin_mats, mat_num)
{ {
df::material *mat = world->raws.mat_table.builtin[mat_num]; df::material *mat = world->raws.mat_table.builtin[mat_num];
if (!mat) if (!mat)
continue; continue;
c->con.print("\n[MATERIAL:%s] - reconstructed from data extracted from memory\n", mat->id.c_str()); out.print("\n[MATERIAL:%s] - reconstructed from data extracted from memory\n", mat->id.c_str());
int32_t def_color[6] = {-1,-1,-1,-1,-1,-1}; int32_t def_color[6] = {-1,-1,-1,-1,-1,-1};
bool name_all = false; bool name_all = false;
@ -58,10 +58,10 @@ command_result df_dumpmats (Core *c, vector<string> &parameters)
{ {
def_color[matter_state::Liquid] = solid_color; def_color[matter_state::Liquid] = solid_color;
def_color[matter_state::Gas] = solid_color; def_color[matter_state::Gas] = solid_color;
c->con.print("\t[STATE_COLOR:ALL:%s]\n", world->raws.language.colors[solid_color]->id.c_str()); out.print("\t[STATE_COLOR:ALL:%s]\n", world->raws.language.colors[solid_color]->id.c_str());
} }
else else
c->con.print("\t[STATE_COLOR:ALL_SOLID:%s]\n", world->raws.language.colors[solid_color]->id.c_str()); out.print("\t[STATE_COLOR:ALL_SOLID:%s]\n", world->raws.language.colors[solid_color]->id.c_str());
} }
string solid_name = mat->state_name[matter_state::Solid]; string solid_name = mat->state_name[matter_state::Solid];
@ -88,10 +88,10 @@ command_result df_dumpmats (Core *c, vector<string> &parameters)
def_name[matter_state::Gas] = solid_name; def_name[matter_state::Gas] = solid_name;
def_adj[matter_state::Liquid] = solid_name; def_adj[matter_state::Liquid] = solid_name;
def_adj[matter_state::Gas] = solid_name; def_adj[matter_state::Gas] = solid_name;
c->con.print("\t[STATE_NAME_ADJ:ALL:%s]\n", solid_name.c_str()); out.print("\t[STATE_NAME_ADJ:ALL:%s]\n", solid_name.c_str());
} }
else else
c->con.print("\t[STATE_NAME_ADJ:ALL_SOLID:%s]\n", solid_name.c_str()); out.print("\t[STATE_NAME_ADJ:ALL_SOLID:%s]\n", solid_name.c_str());
} }
} }
else else
@ -110,10 +110,10 @@ command_result df_dumpmats (Core *c, vector<string> &parameters)
{ {
def_name[matter_state::Liquid] = solid_name; def_name[matter_state::Liquid] = solid_name;
def_name[matter_state::Gas] = solid_name; def_name[matter_state::Gas] = solid_name;
c->con.print("\t[STATE_NAME:ALL:%s]\n", solid_name.c_str()); out.print("\t[STATE_NAME:ALL:%s]\n", solid_name.c_str());
} }
else else
c->con.print("\t[STATE_NAME:ALL_SOLID:%s]\n", solid_name.c_str()); out.print("\t[STATE_NAME:ALL_SOLID:%s]\n", solid_name.c_str());
} }
if (solid_adj == mat->state_adj[matter_state::Powder] || if (solid_adj == mat->state_adj[matter_state::Powder] ||
solid_adj == mat->state_adj[matter_state::Paste] || solid_adj == mat->state_adj[matter_state::Paste] ||
@ -129,148 +129,148 @@ command_result df_dumpmats (Core *c, vector<string> &parameters)
{ {
def_adj[matter_state::Liquid] = solid_adj; def_adj[matter_state::Liquid] = solid_adj;
def_adj[matter_state::Gas] = solid_adj; def_adj[matter_state::Gas] = solid_adj;
c->con.print("\t[STATE_ADJ:ALL:%s]\n", solid_adj.c_str()); out.print("\t[STATE_ADJ:ALL:%s]\n", solid_adj.c_str());
} }
else else
c->con.print("\t[STATE_ADJ:ALL_SOLID:%s]\n", solid_adj.c_str()); out.print("\t[STATE_ADJ:ALL_SOLID:%s]\n", solid_adj.c_str());
} }
} }
char *state_names[6] = {"SOLID", "LIQUID", "GAS", "SOLID_POWDER", "SOLID_PASTE", "SOLID_PRESSED"}; const char *state_names[6] = {"SOLID", "LIQUID", "GAS", "SOLID_POWDER", "SOLID_PASTE", "SOLID_PRESSED"};
FOR_ENUM_ITEMS(matter_state, state) FOR_ENUM_ITEMS(matter_state, state)
{ {
if (mat->state_color[state] != -1 && mat->state_color[state] != def_color[state]) if (mat->state_color[state] != -1 && mat->state_color[state] != def_color[state])
c->con.print("\t[STATE_COLOR:%s:%s]\n", state_names[state], world->raws.language.colors[mat->state_color[state]]->id.c_str()); out.print("\t[STATE_COLOR:%s:%s]\n", state_names[state], world->raws.language.colors[mat->state_color[state]]->id.c_str());
if (mat->state_name[state] == mat->state_adj[state]) if (mat->state_name[state] == mat->state_adj[state])
{ {
if (mat->state_name[state].size() && mat->state_name[state] != def_name[state] || mat->state_adj[state].size() && mat->state_adj[state] != def_adj[state]) if (mat->state_name[state].size() && mat->state_name[state] != def_name[state] || mat->state_adj[state].size() && mat->state_adj[state] != def_adj[state])
c->con.print("\t[STATE_NAME_ADJ:%s:%s]\n", state_names[state], mat->state_name[state].c_str()); out.print("\t[STATE_NAME_ADJ:%s:%s]\n", state_names[state], mat->state_name[state].c_str());
} }
else else
{ {
if (mat->state_name[state].size() && mat->state_name[state] != def_name[state]) if (mat->state_name[state].size() && mat->state_name[state] != def_name[state])
c->con.print("\t[STATE_NAME:%s:%s]\n", state_names[state], mat->state_name[state].c_str()); out.print("\t[STATE_NAME:%s:%s]\n", state_names[state], mat->state_name[state].c_str());
if (mat->state_adj[state].size() && mat->state_adj[state] != def_adj[state]) if (mat->state_adj[state].size() && mat->state_adj[state] != def_adj[state])
c->con.print("\t[STATE_ADJ:%s:%s]\n", state_names[state], mat->state_adj[state].c_str()); out.print("\t[STATE_ADJ:%s:%s]\n", state_names[state], mat->state_adj[state].c_str());
} }
} }
if (mat->basic_color[0] != 7 || mat->basic_color[1] != 0) if (mat->basic_color[0] != 7 || mat->basic_color[1] != 0)
c->con.print("\t[BASIC_COLOR:%i:%i]\n", mat->basic_color[0], mat->basic_color[1]); out.print("\t[BASIC_COLOR:%i:%i]\n", mat->basic_color[0], mat->basic_color[1]);
if (mat->build_color[0] != 7 || mat->build_color[1] != 7 || mat->build_color[2] != 0) if (mat->build_color[0] != 7 || mat->build_color[1] != 7 || mat->build_color[2] != 0)
c->con.print("\t[BUILD_COLOR:%i:%i:%i]\n", mat->build_color[0], mat->build_color[1], mat->build_color[2]); out.print("\t[BUILD_COLOR:%i:%i:%i]\n", mat->build_color[0], mat->build_color[1], mat->build_color[2]);
if (mat->tile_color[0] != 7 || mat->tile_color[1] != 7 || mat->tile_color[2] != 0) if (mat->tile_color[0] != 7 || mat->tile_color[1] != 7 || mat->tile_color[2] != 0)
c->con.print("\t[TILE_COLOR:%i:%i:%i]\n", mat->tile_color[0], mat->tile_color[1], mat->tile_color[2]); out.print("\t[TILE_COLOR:%i:%i:%i]\n", mat->tile_color[0], mat->tile_color[1], mat->tile_color[2]);
if (mat->tile != 0xdb) if (mat->tile != 0xdb)
c->con.print("\t[TILE:%i]\n", mat->tile); out.print("\t[TILE:%i]\n", mat->tile);
if (mat->item_symbol != 0x07) if (mat->item_symbol != 0x07)
c->con.print("\t[ITEM_SYMBOL:%i]\n", mat->item_symbol); out.print("\t[ITEM_SYMBOL:%i]\n", mat->item_symbol);
if (mat->material_value != 1) if (mat->material_value != 1)
c->con.print("\t[MATERIAL_VALUE:%i]\n", mat->material_value); out.print("\t[MATERIAL_VALUE:%i]\n", mat->material_value);
if (mat->gem_name1.size()) if (mat->gem_name1.size())
c->con.print("\t[IS_GEM:%s:%s]\n", mat->gem_name1.c_str(), mat->gem_name2.c_str()); out.print("\t[IS_GEM:%s:%s]\n", mat->gem_name1.c_str(), mat->gem_name2.c_str());
if (mat->stone_name.size()) if (mat->stone_name.size())
c->con.print("\t[STONE_NAME:%s]\n", mat->stone_name.c_str()); out.print("\t[STONE_NAME:%s]\n", mat->stone_name.c_str());
if (mat->heat.spec_heat != 60001) if (mat->heat.spec_heat != 60001)
c->con.print("\t[SPEC_HEAT:%i]\n", mat->heat.spec_heat); out.print("\t[SPEC_HEAT:%i]\n", mat->heat.spec_heat);
if (mat->heat.heatdam_point != 60001) if (mat->heat.heatdam_point != 60001)
c->con.print("\t[HEATDAM_POINT:%i]\n", mat->heat.heatdam_point); out.print("\t[HEATDAM_POINT:%i]\n", mat->heat.heatdam_point);
if (mat->heat.colddam_point != 60001) if (mat->heat.colddam_point != 60001)
c->con.print("\t[COLDDAM_POINT:%i]\n", mat->heat.colddam_point); out.print("\t[COLDDAM_POINT:%i]\n", mat->heat.colddam_point);
if (mat->heat.ignite_point != 60001) if (mat->heat.ignite_point != 60001)
c->con.print("\t[IGNITE_POINT:%i]\n", mat->heat.ignite_point); out.print("\t[IGNITE_POINT:%i]\n", mat->heat.ignite_point);
if (mat->heat.melting_point != 60001) if (mat->heat.melting_point != 60001)
c->con.print("\t[MELTING_POINT:%i]\n", mat->heat.melting_point); out.print("\t[MELTING_POINT:%i]\n", mat->heat.melting_point);
if (mat->heat.boiling_point != 60001) if (mat->heat.boiling_point != 60001)
c->con.print("\t[BOILING_POINT:%i]\n", mat->heat.boiling_point); out.print("\t[BOILING_POINT:%i]\n", mat->heat.boiling_point);
if (mat->heat.mat_fixed_temp != 60001) if (mat->heat.mat_fixed_temp != 60001)
c->con.print("\t[MAT_FIXED_TEMP:%i]\n", mat->heat.mat_fixed_temp); out.print("\t[MAT_FIXED_TEMP:%i]\n", mat->heat.mat_fixed_temp);
if (mat->solid_density != 0xFBBC7818) if (mat->solid_density != 0xFBBC7818)
c->con.print("\t[SOLID_DENSITY:%i]\n", mat->solid_density); out.print("\t[SOLID_DENSITY:%i]\n", mat->solid_density);
if (mat->liquid_density != 0xFBBC7818) if (mat->liquid_density != 0xFBBC7818)
c->con.print("\t[LIQUID_DENSITY:%i]\n", mat->liquid_density); out.print("\t[LIQUID_DENSITY:%i]\n", mat->liquid_density);
if (mat->molar_mass != 0xFBBC7818) if (mat->molar_mass != 0xFBBC7818)
c->con.print("\t[MOLAR_MASS:%i]\n", mat->molar_mass); out.print("\t[MOLAR_MASS:%i]\n", mat->molar_mass);
if (mat->strength.impact_yield != 10000) if (mat->strength.impact_yield != 10000)
c->con.print("\t[IMPACT_YIELD:%i]\n", mat->strength.impact_yield); out.print("\t[IMPACT_YIELD:%i]\n", mat->strength.impact_yield);
if (mat->strength.impact_fracture != 10000) if (mat->strength.impact_fracture != 10000)
c->con.print("\t[IMPACT_FRACTURE:%i]\n", mat->strength.impact_fracture); out.print("\t[IMPACT_FRACTURE:%i]\n", mat->strength.impact_fracture);
if (mat->strength.impact_strain_at_yield != 0) if (mat->strength.impact_strain_at_yield != 0)
c->con.print("\t[IMPACT_STRAIN_AT_YIELD:%i]\n", mat->strength.impact_strain_at_yield); out.print("\t[IMPACT_STRAIN_AT_YIELD:%i]\n", mat->strength.impact_strain_at_yield);
if (mat->strength.compressive_yield != 10000) if (mat->strength.compressive_yield != 10000)
c->con.print("\t[COMPRESSIVE_YIELD:%i]\n", mat->strength.compressive_yield); out.print("\t[COMPRESSIVE_YIELD:%i]\n", mat->strength.compressive_yield);
if (mat->strength.compressive_fracture != 10000) if (mat->strength.compressive_fracture != 10000)
c->con.print("\t[COMPRESSIVE_FRACTURE:%i]\n", mat->strength.compressive_fracture); out.print("\t[COMPRESSIVE_FRACTURE:%i]\n", mat->strength.compressive_fracture);
if (mat->strength.compressive_strain_at_yield != 0) if (mat->strength.compressive_strain_at_yield != 0)
c->con.print("\t[COMPRESSIVE_STRAIN_AT_YIELD:%i]\n", mat->strength.compressive_strain_at_yield); out.print("\t[COMPRESSIVE_STRAIN_AT_YIELD:%i]\n", mat->strength.compressive_strain_at_yield);
if (mat->strength.tensile_yield != 10000) if (mat->strength.tensile_yield != 10000)
c->con.print("\t[TENSILE_YIELD:%i]\n", mat->strength.tensile_yield); out.print("\t[TENSILE_YIELD:%i]\n", mat->strength.tensile_yield);
if (mat->strength.tensile_fracture != 10000) if (mat->strength.tensile_fracture != 10000)
c->con.print("\t[TENSILE_FRACTURE:%i]\n", mat->strength.tensile_fracture); out.print("\t[TENSILE_FRACTURE:%i]\n", mat->strength.tensile_fracture);
if (mat->strength.tensile_strain_at_yield != 0) if (mat->strength.tensile_strain_at_yield != 0)
c->con.print("\t[TENSILE_STRAIN_AT_YIELD:%i]\n", mat->strength.tensile_strain_at_yield); out.print("\t[TENSILE_STRAIN_AT_YIELD:%i]\n", mat->strength.tensile_strain_at_yield);
if (mat->strength.torsion_yield != 10000) if (mat->strength.torsion_yield != 10000)
c->con.print("\t[TORSION_YIELD:%i]\n", mat->strength.torsion_yield); out.print("\t[TORSION_YIELD:%i]\n", mat->strength.torsion_yield);
if (mat->strength.torsion_fracture != 10000) if (mat->strength.torsion_fracture != 10000)
c->con.print("\t[TORSION_FRACTURE:%i]\n", mat->strength.torsion_fracture); out.print("\t[TORSION_FRACTURE:%i]\n", mat->strength.torsion_fracture);
if (mat->strength.torsion_strain_at_yield != 0) if (mat->strength.torsion_strain_at_yield != 0)
c->con.print("\t[TORSION_STRAIN_AT_YIELD:%i]\n", mat->strength.torsion_strain_at_yield); out.print("\t[TORSION_STRAIN_AT_YIELD:%i]\n", mat->strength.torsion_strain_at_yield);
if (mat->strength.shear_yield != 10000) if (mat->strength.shear_yield != 10000)
c->con.print("\t[SHEAR_YIELD:%i]\n", mat->strength.shear_yield); out.print("\t[SHEAR_YIELD:%i]\n", mat->strength.shear_yield);
if (mat->strength.shear_fracture != 10000) if (mat->strength.shear_fracture != 10000)
c->con.print("\t[SHEAR_FRACTURE:%i]\n", mat->strength.shear_fracture); out.print("\t[SHEAR_FRACTURE:%i]\n", mat->strength.shear_fracture);
if (mat->strength.shear_strain_at_yield != 0) if (mat->strength.shear_strain_at_yield != 0)
c->con.print("\t[SHEAR_STRAIN_AT_YIELD:%i]\n", mat->strength.shear_strain_at_yield); out.print("\t[SHEAR_STRAIN_AT_YIELD:%i]\n", mat->strength.shear_strain_at_yield);
if (mat->strength.bending_yield != 10000) if (mat->strength.bending_yield != 10000)
c->con.print("\t[BENDING_YIELD:%i]\n", mat->strength.bending_yield); out.print("\t[BENDING_YIELD:%i]\n", mat->strength.bending_yield);
if (mat->strength.bending_fracture != 10000) if (mat->strength.bending_fracture != 10000)
c->con.print("\t[BENDING_FRACTURE:%i]\n", mat->strength.bending_fracture); out.print("\t[BENDING_FRACTURE:%i]\n", mat->strength.bending_fracture);
if (mat->strength.bending_strain_at_yield != 0) if (mat->strength.bending_strain_at_yield != 0)
c->con.print("\t[BENDING_STRAIN_AT_YIELD:%i]\n", mat->strength.bending_strain_at_yield); out.print("\t[BENDING_STRAIN_AT_YIELD:%i]\n", mat->strength.bending_strain_at_yield);
if (mat->strength.max_edge != 0) if (mat->strength.max_edge != 0)
c->con.print("\t[MAX_EDGE:%i]\n", mat->strength.max_edge); out.print("\t[MAX_EDGE:%i]\n", mat->strength.max_edge);
if (mat->strength.absorption != 0) if (mat->strength.absorption != 0)
c->con.print("\t[ABSORPTION:%i]\n", mat->strength.absorption); out.print("\t[ABSORPTION:%i]\n", mat->strength.absorption);
FOR_ENUM_ITEMS(material_flags, i) FOR_ENUM_ITEMS(material_flags, i)
{ {
if (mat->flags.is_set(i)) if (mat->flags.is_set(i))
c->con.print("\t[%s]\n", ENUM_KEY_STR(material_flags, i)); out.print("\t[%s]\n", ENUM_KEY_STR(material_flags, i));
} }
if (mat->extract_storage != item_type::BARREL) if (mat->extract_storage != item_type::BARREL)
c->con.print("\t[EXTRACT_STORAGE:%s]\n", ENUM_KEY_STR(item_type, mat->extract_storage)); out.print("\t[EXTRACT_STORAGE:%s]\n", ENUM_KEY_STR(item_type, mat->extract_storage));
if (mat->butcher_special_type != item_type::NONE || mat->butcher_special_subtype != -1) if (mat->butcher_special_type != item_type::NONE || mat->butcher_special_subtype != -1)
c->con.print("\t[BUTCHER_SPECIAL:%s:%s]\n", ENUM_KEY_STR(item_type, mat->butcher_special_type), (mat->butcher_special_subtype == -1) ? "NONE" : "?"); out.print("\t[BUTCHER_SPECIAL:%s:%s]\n", ENUM_KEY_STR(item_type, mat->butcher_special_type), (mat->butcher_special_subtype == -1) ? "NONE" : "?");
if (mat->meat_name[0].size() || mat->meat_name[1].size() || mat->meat_name[2].size()) if (mat->meat_name[0].size() || mat->meat_name[1].size() || mat->meat_name[2].size())
c->con.print("\t[MEAT_NAME:%s:%s:%s]\n", mat->meat_name[0].c_str(), mat->meat_name[1].c_str(), mat->meat_name[2].c_str()); out.print("\t[MEAT_NAME:%s:%s:%s]\n", mat->meat_name[0].c_str(), mat->meat_name[1].c_str(), mat->meat_name[2].c_str());
if (mat->block_name[0].size() || mat->block_name[1].size()) if (mat->block_name[0].size() || mat->block_name[1].size())
c->con.print("\t[BLOCK_NAME:%s:%s]\n", mat->block_name[0].c_str(), mat->block_name[1].c_str()); out.print("\t[BLOCK_NAME:%s:%s]\n", mat->block_name[0].c_str(), mat->block_name[1].c_str());
for (int i = 0; i < mat->reaction_class.size(); i++) for (int i = 0; i < mat->reaction_class.size(); i++)
c->con.print("\t[REACTION_CLASS:%s]\n", mat->reaction_class[i]->c_str()); out.print("\t[REACTION_CLASS:%s]\n", mat->reaction_class[i]->c_str());
for (int i = 0; i < mat->reaction_product.id.size(); i++) for (int i = 0; i < mat->reaction_product.id.size(); i++)
c->con.print("\t[MATERIAL_REACTION_PRODUCT:%s:%s:%s%s%s]\n", mat->reaction_product.id[i]->c_str(), mat->reaction_product.str[0][i]->c_str(), mat->reaction_product.str[1][i]->c_str(), mat->reaction_product.str[2][i]->size() ? ":" : "", mat->reaction_product.str[2][i]->c_str()); out.print("\t[MATERIAL_REACTION_PRODUCT:%s:%s:%s%s%s]\n", mat->reaction_product.id[i]->c_str(), mat->reaction_product.str[0][i]->c_str(), mat->reaction_product.str[1][i]->c_str(), mat->reaction_product.str[2][i]->size() ? ":" : "", mat->reaction_product.str[2][i]->c_str());
if (mat->hardens_with_water.mat_type != -1) if (mat->hardens_with_water.mat_type != -1)
c->con.print("\t[HARDENS_WITH_WATER:%s:%s%s%s]\n", mat->hardens_with_water.str[0].c_str(), mat->hardens_with_water.str[1].c_str(), mat->hardens_with_water.str[2].size() ? ":" : "", mat->hardens_with_water.str[2].c_str()); out.print("\t[HARDENS_WITH_WATER:%s:%s%s%s]\n", mat->hardens_with_water.str[0].c_str(), mat->hardens_with_water.str[1].c_str(), mat->hardens_with_water.str[2].size() ? ":" : "", mat->hardens_with_water.str[2].c_str());
if (mat->powder_dye != -1) if (mat->powder_dye != -1)
c->con.print("\t[POWDER_DYE:%s]\n", world->raws.language.colors[mat->powder_dye]->id.c_str()); out.print("\t[POWDER_DYE:%s]\n", world->raws.language.colors[mat->powder_dye]->id.c_str());
if (mat->soap_level != -0) if (mat->soap_level != -0)
c->con.print("\t[SOAP_LEVEL:%o]\n", mat->soap_level); out.print("\t[SOAP_LEVEL:%o]\n", mat->soap_level);
for (int i = 0; i < mat->syndrome.size(); i++) for (int i = 0; i < mat->syndrome.size(); i++)
c->con.print("\t[SYNDROME] ...\n"); out.print("\t[SYNDROME] ...\n");
} }
return CR_OK; return CR_OK;
} }

@ -41,54 +41,54 @@ int changeLiquid (df::tile_liquid type)
return tiles; return tiles;
} }
command_result df_frozenlava (Core * c, vector <string> & parameters) command_result df_frozenlava (color_ostream &out, vector <string> & parameters)
{ {
if (parameters.size()) if (parameters.size())
return CR_WRONG_USAGE; return CR_WRONG_USAGE;
CoreSuspender suspend(c); CoreSuspender suspend;
if (!Maps::IsValid()) if (!Maps::IsValid())
{ {
c->con.printerr("Map is not available!\n"); out.printerr("Map is not available!\n");
return CR_FAILURE; return CR_FAILURE;
} }
int tiles = changeLiquid(tile_liquid::Magma); int tiles = changeLiquid(tile_liquid::Magma);
if (tiles) if (tiles)
c->con.print("Changed %i tiles of ice into frozen lava.\n", tiles); out.print("Changed %i tiles of ice into frozen lava.\n", tiles);
return CR_OK; return CR_OK;
} }
command_result df_frozenwater (Core * c, vector <string> & parameters) command_result df_frozenwater (color_ostream &out, vector <string> & parameters)
{ {
if (parameters.size()) if (parameters.size())
return CR_WRONG_USAGE; return CR_WRONG_USAGE;
CoreSuspender suspend(c); CoreSuspender suspend;
if (!Maps::IsValid()) if (!Maps::IsValid())
{ {
c->con.printerr("Map is not available!\n"); out.printerr("Map is not available!\n");
return CR_FAILURE; return CR_FAILURE;
} }
int tiles = changeLiquid(tile_liquid::Water); int tiles = changeLiquid(tile_liquid::Water);
if (tiles) if (tiles)
c->con.print("Changed %i tiles of ice into frozen water.\n", tiles); out.print("Changed %i tiles of ice into frozen water.\n", tiles);
return CR_OK; return CR_OK;
} }
DFHACK_PLUGIN("frozen"); DFHACK_PLUGIN("frozen");
DFhackCExport command_result plugin_init ( Core * c, std::vector <PluginCommand> &commands) DFhackCExport command_result plugin_init ( color_ostream &out, std::vector <PluginCommand> &commands)
{ {
commands.push_back(PluginCommand("frozenlava", "Changes all ice into frozen magma.", df_frozenlava)); commands.push_back(PluginCommand("frozenlava", "Changes all ice into frozen magma.", df_frozenlava));
commands.push_back(PluginCommand("frozenwater", "Changes all ice into frozen water.", df_frozenwater)); commands.push_back(PluginCommand("frozenwater", "Changes all ice into frozen water.", df_frozenwater));
return CR_OK; return CR_OK;
} }
DFhackCExport command_result plugin_shutdown ( Core * c ) DFhackCExport command_result plugin_shutdown ( color_ostream &out )
{ {
return CR_OK; return CR_OK;
} }

@ -27,16 +27,16 @@ int32_t last_mouse[2] = {-1, -1};
uint32_t last_menu = 0; uint32_t last_menu = 0;
uint64_t timeLast = 0; uint64_t timeLast = 0;
command_result kittens (Core * c, vector <string> & parameters); command_result kittens (color_ostream &out, vector <string> & parameters);
command_result ktimer (Core * c, vector <string> & parameters); command_result ktimer (color_ostream &out, vector <string> & parameters);
command_result trackmenu (Core * c, vector <string> & parameters); command_result trackmenu (color_ostream &out, vector <string> & parameters);
command_result trackpos (Core * c, vector <string> & parameters); command_result trackpos (color_ostream &out, vector <string> & parameters);
command_result colormods (Core * c, vector <string> & parameters); command_result colormods (color_ostream &out, vector <string> & parameters);
command_result zoom (Core * c, vector <string> & parameters); command_result zoom (color_ostream &out, vector <string> & parameters);
DFHACK_PLUGIN("kittens"); DFHACK_PLUGIN("kittens");
DFhackCExport command_result plugin_init ( Core * c, std::vector <PluginCommand> &commands) DFhackCExport command_result plugin_init ( color_ostream &out, std::vector <PluginCommand> &commands)
{ {
commands.push_back(PluginCommand("nyan","NYAN CAT INVASION!",kittens, true)); commands.push_back(PluginCommand("nyan","NYAN CAT INVASION!",kittens, true));
commands.push_back(PluginCommand("ktimer","Measure time between game updates and console lag (toggle).",ktimer)); commands.push_back(PluginCommand("ktimer","Measure time between game updates and console lag (toggle).",ktimer));
@ -47,17 +47,17 @@ DFhackCExport command_result plugin_init ( Core * c, std::vector <PluginCommand>
return CR_OK; return CR_OK;
} }
DFhackCExport command_result plugin_shutdown ( Core * c ) DFhackCExport command_result plugin_shutdown ( color_ostream &out )
{ {
shutdown_flag = true; shutdown_flag = true;
while(!final_flag) while(!final_flag)
{ {
c->con.msleep(60); Core::getInstance().getConsole().msleep(60);
} }
return CR_OK; return CR_OK;
} }
DFhackCExport command_result plugin_onupdate ( Core * c ) DFhackCExport command_result plugin_onupdate ( color_ostream &out )
{ {
if(timering == true) if(timering == true)
{ {
@ -66,14 +66,14 @@ DFhackCExport command_result plugin_onupdate ( Core * c )
uint64_t delta = time2-timeLast; uint64_t delta = time2-timeLast;
// harmless potential data race here... // harmless potential data race here...
timeLast = time2; timeLast = time2;
c->con.print("Time delta = %d ms\n", delta); out.print("Time delta = %d ms\n", delta);
} }
if(trackmenu_flg) if(trackmenu_flg)
{ {
if (last_menu != df::global::ui->main.mode) if (last_menu != df::global::ui->main.mode)
{ {
last_menu = df::global::ui->main.mode; last_menu = df::global::ui->main.mode;
c->con.print("Menu: %d\n",last_menu); out.print("Menu: %d\n",last_menu);
} }
} }
if(trackpos_flg) if(trackpos_flg)
@ -85,7 +85,7 @@ DFhackCExport command_result plugin_onupdate ( Core * c )
last_designation[0] = desig_x; last_designation[0] = desig_x;
last_designation[1] = desig_y; last_designation[1] = desig_y;
last_designation[2] = desig_z; last_designation[2] = desig_z;
c->con.print("Designation: %d %d %d\n",desig_x, desig_y, desig_z); out.print("Designation: %d %d %d\n",desig_x, desig_y, desig_z);
} }
int mouse_x, mouse_y; int mouse_x, mouse_y;
Gui::getMousePos(mouse_x,mouse_y); Gui::getMousePos(mouse_x,mouse_y);
@ -93,13 +93,13 @@ DFhackCExport command_result plugin_onupdate ( Core * c )
{ {
last_mouse[0] = mouse_x; last_mouse[0] = mouse_x;
last_mouse[1] = mouse_y; last_mouse[1] = mouse_y;
c->con.print("Mouse: %d %d\n",mouse_x, mouse_y); out.print("Mouse: %d %d\n",mouse_x, mouse_y);
} }
} }
return CR_OK; return CR_OK;
} }
command_result trackmenu (Core * c, vector <string> & parameters) command_result trackmenu (color_ostream &out, vector <string> & parameters)
{ {
if(trackmenu_flg) if(trackmenu_flg)
{ {
@ -112,42 +112,41 @@ command_result trackmenu (Core * c, vector <string> & parameters)
{ {
trackmenu_flg = true; trackmenu_flg = true;
last_menu = df::global::ui->main.mode; last_menu = df::global::ui->main.mode;
c->con.print("Menu: %d\n",last_menu); out.print("Menu: %d\n",last_menu);
return CR_OK; return CR_OK;
} }
else else
{ {
c->con.printerr("Can't read menu state\n"); out.printerr("Can't read menu state\n");
return CR_FAILURE; return CR_FAILURE;
} }
} }
} }
command_result trackpos (Core * c, vector <string> & parameters) command_result trackpos (color_ostream &out, vector <string> & parameters)
{ {
trackpos_flg = !trackpos_flg; trackpos_flg = !trackpos_flg;
return CR_OK; return CR_OK;
} }
command_result colormods (Core * c, vector <string> & parameters) command_result colormods (color_ostream &out, vector <string> & parameters)
{ {
c->Suspend(); CoreSuspender suspend;
auto & vec = df::global::world->raws.creatures.alphabetic; auto & vec = df::global::world->raws.creatures.alphabetic;
for(int i = 0; i < vec.size();i++) for(int i = 0; i < vec.size();i++)
{ {
df::creature_raw* rawlion = vec[i]; df::creature_raw* rawlion = vec[i];
df::caste_raw * caste = rawlion->caste[0]; df::caste_raw * caste = rawlion->caste[0];
c->con.print("%s\nCaste addr 0x%x\n",rawlion->creature_id.c_str(), &caste->color_modifiers); out.print("%s\nCaste addr 0x%x\n",rawlion->creature_id.c_str(), &caste->color_modifiers);
for(int j = 0; j < caste->color_modifiers.size();j++) for(int j = 0; j < caste->color_modifiers.size();j++)
{ {
c->con.print("mod %d: 0x%x\n", j, caste->color_modifiers[j]); out.print("mod %d: 0x%x\n", j, caste->color_modifiers[j]);
} }
} }
c->Resume();
return CR_OK; return CR_OK;
} }
// FIXME: move cursor properly relative to view position // FIXME: move cursor properly relative to view position
command_result zoom (Core * c, vector <string> & parameters) command_result zoom (color_ostream &out, vector <string> & parameters)
{ {
if(parameters.size() < 3) if(parameters.size() < 3)
return CR_FAILURE; return CR_FAILURE;
@ -155,7 +154,7 @@ command_result zoom (Core * c, vector <string> & parameters)
int y = atoi( parameters[1].c_str()); int y = atoi( parameters[1].c_str());
int z = atoi( parameters[2].c_str()); int z = atoi( parameters[2].c_str());
int xi, yi, zi; int xi, yi, zi;
CoreSuspender cs (c); CoreSuspender cs;
if(Gui::getCursorCoords(xi, yi, zi)) if(Gui::getCursorCoords(xi, yi, zi))
{ {
Gui::setCursorCoords(x,y,z); Gui::setCursorCoords(x,y,z);
@ -163,7 +162,7 @@ command_result zoom (Core * c, vector <string> & parameters)
Gui::setViewCoords(x,y,z); Gui::setViewCoords(x,y,z);
} }
command_result ktimer (Core * c, vector <string> & parameters) command_result ktimer (color_ostream &out, vector <string> & parameters)
{ {
if(timering) if(timering)
{ {
@ -171,20 +170,22 @@ command_result ktimer (Core * c, vector <string> & parameters)
return CR_OK; return CR_OK;
} }
uint64_t timestart = GetTimeMs64(); uint64_t timestart = GetTimeMs64();
c->Suspend(); {
c->Resume(); CoreSuspender suspend;
}
uint64_t timeend = GetTimeMs64(); uint64_t timeend = GetTimeMs64();
c->con.print("Time to suspend = %d ms\n",timeend - timestart); out.print("Time to suspend = %d ms\n",timeend - timestart);
// harmless potential data race here... // harmless potential data race here...
timeLast = timeend; timeLast = timeend;
timering = true; timering = true;
return CR_OK; return CR_OK;
} }
command_result kittens (Core * c, vector <string> & parameters) command_result kittens (color_ostream &out, vector <string> & parameters)
{ {
final_flag = false; final_flag = false;
Console & con = c->con; assert(out.is_console());
Console &con = static_cast<Console&>(out);
// http://evilzone.org/creative-arts/nyan-cat-ascii/ // http://evilzone.org/creative-arts/nyan-cat-ascii/
const char * nyan []= const char * nyan []=
{ {

@ -28,11 +28,11 @@ enum HEXVIEW_STATES
{ {
STATE_OFF,STATE_ON STATE_OFF,STATE_ON
}; };
command_result memview (Core * c, vector <string> & parameters); command_result memview (color_ostream &out, vector <string> & parameters);
DFHACK_PLUGIN("memview"); DFHACK_PLUGIN("memview");
DFhackCExport command_result plugin_init ( Core * c, std::vector <PluginCommand> &commands) DFhackCExport command_result plugin_init (color_ostream &out, std::vector <PluginCommand> &commands)
{ {
commands.push_back(PluginCommand("memview","Shows memory in real time. Params: adrr length refresh_rate. If addr==0 then stop viewing",memview)); 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; memdata.state=STATE_OFF;
@ -58,15 +58,13 @@ bool isAddr(uint32_t *trg,vector<t_memrange> & ranges)
return false; return false;
} }
void outputHex(uint8_t *buf,uint8_t *lbuf,size_t len,size_t start,Core *c,vector<t_memrange> & ranges) void outputHex(uint8_t *buf,uint8_t *lbuf,size_t len,size_t start,color_ostream &con,vector<t_memrange> & ranges)
{ {
Console &con=c->con;
const size_t page_size=16; const size_t page_size=16;
con.clear();
for(size_t i=0;i<len;i+=page_size) for(size_t i=0;i<len;i+=page_size)
{ {
con.gotoxy(1,i/page_size+1); //con.gotoxy(1,i/page_size+1);
con.print("0x%08X ",i+start); con.print("0x%08X ",i+start);
for(size_t j=0;(j<page_size) && (i+j<len);j++) for(size_t j=0;(j<page_size) && (i+j<len);j++)
{ {
@ -93,8 +91,6 @@ void outputHex(uint8_t *buf,uint8_t *lbuf,size_t len,size_t start,Core *c,vector
//con.print("\n"); //con.print("\n");
} }
con.print("\n"); con.print("\n");
con.flush();
} }
void Deinit() void Deinit()
{ {
@ -105,7 +101,7 @@ void Deinit()
delete [] memdata.lbuf; delete [] memdata.lbuf;
} }
} }
DFhackCExport command_result plugin_onupdate ( Core * c ) DFhackCExport command_result plugin_onupdate (color_ostream &out)
{ {
mymutex->lock(); mymutex->lock();
@ -114,7 +110,7 @@ DFhackCExport command_result plugin_onupdate ( Core * c )
mymutex->unlock(); mymutex->unlock();
return CR_OK; return CR_OK;
} }
//Console &con=c->con; //Console &con=out;
uint64_t time2 = GetTimeMs64(); uint64_t time2 = GetTimeMs64();
uint64_t delta = time2-timeLast; uint64_t delta = time2-timeLast;
@ -126,8 +122,8 @@ DFhackCExport command_result plugin_onupdate ( Core * c )
} }
timeLast = time2; timeLast = time2;
c->p->read(memdata.addr,memdata.len,memdata.buf); Core::getInstance().p->read(memdata.addr,memdata.len,memdata.buf);
outputHex(memdata.buf,memdata.lbuf,memdata.len,(size_t)memdata.addr,c,memdata.ranges); outputHex(memdata.buf,memdata.lbuf,memdata.len,(size_t)memdata.addr,out,memdata.ranges);
memcpy(memdata.lbuf, memdata.buf, memdata.len); memcpy(memdata.lbuf, memdata.buf, memdata.len);
if(memdata.refresh==0) if(memdata.refresh==0)
Deinit(); Deinit();
@ -135,10 +131,10 @@ DFhackCExport command_result plugin_onupdate ( Core * c )
return CR_OK; return CR_OK;
} }
command_result memview (Core * c, vector <string> & parameters) command_result memview (color_ostream &out, vector <string> & parameters)
{ {
mymutex->lock(); mymutex->lock();
c->p->getMemRanges(memdata.ranges); Core::getInstance().p->getMemRanges(memdata.ranges);
memdata.addr=(void *)convert(parameters[0],true); memdata.addr=(void *)convert(parameters[0],true);
if(memdata.addr==0) if(memdata.addr==0)
{ {
@ -156,7 +152,7 @@ command_result memview (Core * c, vector <string> & parameters)
isValid=true; isValid=true;
if(!isValid) if(!isValid)
{ {
c->con.printerr("Invalid address:%x\n",memdata.addr); out.printerr("Invalid address:%x\n",memdata.addr);
mymutex->unlock(); mymutex->unlock();
return CR_OK; return CR_OK;
} }
@ -176,11 +172,11 @@ command_result memview (Core * c, vector <string> & parameters)
uint8_t *buf,*lbuf; uint8_t *buf,*lbuf;
memdata.buf=new uint8_t[memdata.len]; memdata.buf=new uint8_t[memdata.len];
memdata.lbuf=new uint8_t[memdata.len]; memdata.lbuf=new uint8_t[memdata.len];
c->p->getMemRanges(memdata.ranges); Core::getInstance().p->getMemRanges(memdata.ranges);
mymutex->unlock(); mymutex->unlock();
return CR_OK; return CR_OK;
} }
DFhackCExport command_result plugin_shutdown ( Core * c ) DFhackCExport command_result plugin_shutdown (color_ostream &out)
{ {
mymutex->lock(); mymutex->lock();
Deinit(); Deinit();

@ -10,11 +10,11 @@ using std::vector;
using std::string; using std::string;
using namespace DFHack; using namespace DFHack;
command_result df_notes (Core * c, vector <string> & parameters); command_result df_notes (color_ostream &out, vector <string> & parameters);
DFHACK_PLUGIN("notes"); DFHACK_PLUGIN("notes");
DFhackCExport command_result plugin_init ( Core * c, std::vector <PluginCommand> &commands) DFhackCExport command_result plugin_init ( color_ostream &out, std::vector <PluginCommand> &commands)
{ {
commands.push_back(PluginCommand("dumpnotes", commands.push_back(PluginCommand("dumpnotes",
"Dumps in-game notes", "Dumps in-game notes",
@ -22,30 +22,27 @@ DFhackCExport command_result plugin_init ( Core * c, std::vector <PluginCommand>
return CR_OK; return CR_OK;
} }
DFhackCExport command_result plugin_shutdown ( Core * c ) DFhackCExport command_result plugin_shutdown ( color_ostream &out )
{ {
return CR_OK; return CR_OK;
} }
command_result df_notes (Core * c, vector <string> & parameters) command_result df_notes (color_ostream &con, vector <string> & parameters)
{ {
Console & con = c->con; CoreSuspender suspend;
c->Suspend();
DFHack::Notes * note_mod = c->getNotes(); DFHack::Notes * note_mod = Core::getInstance().getNotes();
std::vector<t_note*>* note_list = note_mod->notes; std::vector<t_note*>* note_list = note_mod->notes;
if (note_list == NULL) if (note_list == NULL)
{ {
con.printerr("Notes are not supported under this version of DF.\n"); con.printerr("Notes are not supported under this version of DF.\n");
c->Resume();
return CR_OK; return CR_OK;
} }
if (note_list->empty()) if (note_list->empty())
{ {
con << "There are no notes." << std::endl; con << "There are no notes." << std::endl;
c->Resume();
return CR_OK; return CR_OK;
} }
@ -71,6 +68,5 @@ command_result df_notes (Core * c, vector <string> & parameters)
con << std::endl; con << std::endl;
} }
c->Resume();
return CR_OK; return CR_OK;
} }

@ -17,12 +17,12 @@ using namespace DFHack;
using df::global::world; using df::global::world;
command_result df_regrass (Core * c, vector <string> & parameters) command_result df_regrass (color_ostream &out, vector <string> & parameters)
{ {
if (!parameters.empty()) if (!parameters.empty())
return CR_WRONG_USAGE; return CR_WRONG_USAGE;
CoreSuspender suspend(c); CoreSuspender suspend;
int count = 0; int count = 0;
for (size_t i = 0; i < world->map.map_blocks.size(); i++) for (size_t i = 0; i < world->map.map_blocks.size(); i++)
@ -48,20 +48,20 @@ command_result df_regrass (Core * c, vector <string> & parameters)
} }
if (count) if (count)
c->con.print("Regrew %d tiles of grass.\n", count); out.print("Regrew %d tiles of grass.\n", count);
return CR_OK; return CR_OK;
} }
DFHACK_PLUGIN("regrass"); DFHACK_PLUGIN("regrass");
DFhackCExport command_result plugin_init (Core *c, std::vector<PluginCommand> &commands) DFhackCExport command_result plugin_init (color_ostream &out, std::vector<PluginCommand> &commands)
{ {
commands.clear(); commands.clear();
commands.push_back(PluginCommand("regrass", "Regrows all surface grass, restoring outdoor plant growth for pre-0.31.19 worlds.", df_regrass)); commands.push_back(PluginCommand("regrass", "Regrows all surface grass, restoring outdoor plant growth for pre-0.31.19 worlds.", df_regrass));
return CR_OK; return CR_OK;
} }
DFhackCExport command_result plugin_shutdown ( Core * c ) DFhackCExport command_result plugin_shutdown ( color_ostream &out )
{ {
return CR_OK; return CR_OK;
} }

@ -18,13 +18,13 @@ using df::global::world;
// Here go all the command declarations... // Here go all the command declarations...
// mostly to allow having the mandatory stuff on top of the file and commands on the bottom // mostly to allow having the mandatory stuff on top of the file and commands on the bottom
command_result tilesieve (Core * c, std::vector <std::string> & parameters); command_result tilesieve (color_ostream &out, std::vector <std::string> & parameters);
// A plugin must be able to return its name. This must correspond to the filename - skeleton.plug.so or skeleton.plug.dll // A plugin must be able to return its name. This must correspond to the filename - skeleton.plug.so or skeleton.plug.dll
DFHACK_PLUGIN("tilesieve"); DFHACK_PLUGIN("tilesieve");
// Mandatory init function. If you have some global state, create it here. // Mandatory init function. If you have some global state, create it here.
DFhackCExport command_result plugin_init ( Core * c, std::vector <PluginCommand> &commands) DFhackCExport command_result plugin_init ( color_ostream &out, std::vector <PluginCommand> &commands)
{ {
// Fill the command list with your commands. // Fill the command list with your commands.
commands.push_back(PluginCommand( commands.push_back(PluginCommand(
@ -37,7 +37,7 @@ DFhackCExport command_result plugin_init ( Core * c, std::vector <PluginCommand>
} }
// This is called right before the plugin library is removed from memory. // This is called right before the plugin library is removed from memory.
DFhackCExport command_result plugin_shutdown ( Core * c ) DFhackCExport command_result plugin_shutdown ( color_ostream &out )
{ {
return CR_OK; return CR_OK;
} }
@ -48,16 +48,16 @@ struct xyz
int z; int z;
}; };
command_result tilesieve(DFHack::Core * c, std::vector<std::string> & params) command_result tilesieve(color_ostream &out, std::vector<std::string> & params)
{ {
Console & con = c->con; CoreSuspender suspend;
CoreSuspender suspend(c);
if (!Maps::IsValid()) if (!Maps::IsValid())
{ {
c->con.printerr("Map is not available!\n"); out.printerr("Map is not available!\n");
return CR_FAILURE; return CR_FAILURE;
} }
c->con.print("Scanning.\n"); out.print("Scanning.\n");
std::set <df::tiletype> seen; std::set <df::tiletype> seen;
for (auto iter = world->map.map_blocks.begin(); iter != world->map.map_blocks.end(); iter++) for (auto iter = world->map.map_blocks.begin(); iter != world->map.map_blocks.end(); iter++)
{ {
@ -75,7 +75,7 @@ command_result tilesieve(DFHack::Core * c, std::vector<std::string> & params)
if(seen.count(tt)) if(seen.count(tt))
continue; continue;
seen.insert(tt); seen.insert(tt);
c->con.print("Found tile %x @ %d %d %d\n", tt, block->map_pos.x + x, block->map_pos.y + y, block->map_pos.z); out.print("Found tile %x @ %d %d %d\n", tt, block->map_pos.x + x, block->map_pos.y + y, block->map_pos.z);
} }
} }
return CR_OK; return CR_OK;

@ -24,14 +24,12 @@ struct t_vecTriplet
void * alloc_end; void * alloc_end;
}; };
command_result df_vectors (Core * c, command_result df_vectors (color_ostream &out, vector <string> & parameters);
vector <string> & parameters); command_result df_clearvec (color_ostream &out, vector <string> & parameters);
command_result df_clearvec (Core * c,
vector <string> & parameters);
DFHACK_PLUGIN("vectors"); DFHACK_PLUGIN("vectors");
DFhackCExport command_result plugin_init ( Core * c, std::vector <PluginCommand> &commands) DFhackCExport command_result plugin_init ( color_ostream &out, std::vector <PluginCommand> &commands)
{ {
commands.push_back(PluginCommand("vectors", commands.push_back(PluginCommand("vectors",
"Scan memory for vectors.\ "Scan memory for vectors.\
@ -45,7 +43,7 @@ DFhackCExport command_result plugin_init ( Core * c, std::vector <PluginCommand>
return CR_OK; return CR_OK;
} }
DFhackCExport command_result plugin_shutdown ( Core * c ) DFhackCExport command_result plugin_shutdown ( color_ostream &out )
{ {
return CR_OK; return CR_OK;
} }
@ -94,11 +92,11 @@ static bool inAnyRange(vector<t_memrange> &ranges, void * ptr)
return false; return false;
} }
static bool getHeapRanges(Core * c, std::vector<t_memrange> &heap_ranges) static bool getHeapRanges(color_ostream &out, std::vector<t_memrange> &heap_ranges)
{ {
std::vector<t_memrange> ranges; std::vector<t_memrange> ranges;
c->p->getMemRanges(ranges); Core::getInstance().p->getMemRanges(ranges);
for (size_t i = 0; i < ranges.size(); i++) for (size_t i = 0; i < ranges.size(); i++)
{ {
@ -116,7 +114,7 @@ static bool getHeapRanges(Core * c, std::vector<t_memrange> &heap_ranges)
if (heap_ranges.empty()) if (heap_ranges.empty())
{ {
c->con << "No possible heap segments." << std::endl; out << "No possible heap segments." << std::endl;
return false; return false;
} }
@ -127,13 +125,13 @@ static bool getHeapRanges(Core * c, std::vector<t_memrange> &heap_ranges)
// COMMAND: vectors // COMMAND: vectors
//////////////////////////////////////// ////////////////////////////////////////
static void vectorsUsage(Console &con) static void vectorsUsage(color_ostream &con)
{ {
con << "Usage: vectors <start of scan address> <# bytes to scan>" con << "Usage: vectors <start of scan address> <# bytes to scan>"
<< std::endl; << std::endl;
} }
static void printVec(Console &con, const char* msg, t_vecTriplet *vec, static void printVec(color_ostream &con, const char* msg, t_vecTriplet *vec,
uint32_t start, uint32_t pos) uint32_t start, uint32_t pos)
{ {
uint32_t length = (int)vec->end - (int)vec->start; uint32_t length = (int)vec->end - (int)vec->start;
@ -143,10 +141,8 @@ static void printVec(Console &con, const char* msg, t_vecTriplet *vec,
msg, offset, pos, vec->start, length); msg, offset, pos, vec->start, length);
} }
command_result df_vectors (Core * c, vector <string> & parameters) command_result df_vectors (color_ostream &con, vector <string> & parameters)
{ {
Console & con = c->con;
if (parameters.size() != 2) if (parameters.size() != 2)
{ {
vectorsUsage(con); vectorsUsage(con);
@ -173,14 +169,13 @@ command_result df_vectors (Core * c, vector <string> & parameters)
while (start % 4 != 0) while (start % 4 != 0)
start++; start++;
c->Suspend(); CoreSuspender suspend;
std::vector<t_memrange> heap_ranges; std::vector<t_memrange> heap_ranges;
if (!getHeapRanges(c, heap_ranges)) if (!getHeapRanges(con, heap_ranges))
{ {
return CR_FAILURE; return CR_FAILURE;
c->Resume();
} }
bool startInRange = false; bool startInRange = false;
@ -208,7 +203,6 @@ command_result df_vectors (Core * c, vector <string> & parameters)
if (!startInRange) if (!startInRange)
{ {
con << "Address not in any memory range." << std::endl; con << "Address not in any memory range." << std::endl;
c->Resume();
return CR_FAILURE; return CR_FAILURE;
} }
@ -250,7 +244,6 @@ command_result df_vectors (Core * c, vector <string> & parameters)
} }
} // for (uint32_t pos = start; pos < end; pos += ptr_size) } // for (uint32_t pos = start; pos < end; pos += ptr_size)
c->Resume();
return CR_OK; return CR_OK;
} }
@ -258,17 +251,15 @@ command_result df_vectors (Core * c, vector <string> & parameters)
// COMMAND: clearvec // COMMAND: clearvec
//////////////////////////////////////// ////////////////////////////////////////
static void clearUsage(Console &con) static void clearUsage(color_ostream &con)
{ {
con << "Usage: clearvec <vector1 addr> [vector2 addr] ..." << std::endl; con << "Usage: clearvec <vector1 addr> [vector2 addr] ..." << std::endl;
con << "Address can be either for vector or pointer to vector." con << "Address can be either for vector or pointer to vector."
<< std::endl; << std::endl;
} }
command_result df_clearvec (Core * c, vector <string> & parameters) command_result df_clearvec (color_ostream &con, vector <string> & parameters)
{ {
Console & con = c->con;
if (parameters.size() == 0) if (parameters.size() == 0)
{ {
clearUsage(con); clearUsage(con);
@ -289,13 +280,12 @@ command_result df_clearvec (Core * c, vector <string> & parameters)
return CR_FAILURE; return CR_FAILURE;
} }
c->Suspend(); CoreSuspender suspend;
std::vector<t_memrange> heap_ranges; std::vector<t_memrange> heap_ranges;
if (!getHeapRanges(c, heap_ranges)) if (!getHeapRanges(con, heap_ranges))
{ {
c->Resume();
return CR_FAILURE; return CR_FAILURE;
} }
@ -356,6 +346,5 @@ command_result df_clearvec (Core * c, vector <string> & parameters)
con << addr_str << " set to zero length." << std::endl; con << addr_str << " set to zero length." << std::endl;
} // for (size_t i = 0; i < parameters.size(); i++) } // for (size_t i = 0; i < parameters.size(); i++)
c->Resume();
return CR_OK; return CR_OK;
} }