Skip to content

Commit cd6e144

Browse files
committed
preprocessFile override
getAvailableVariables network command
1 parent ca1137c commit cd6e144

File tree

7 files changed

+106
-9
lines changed

7 files changed

+106
-9
lines changed

BIDebugEngine/BIDebugEngine/Debugger.cpp

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,7 @@ void Debugger::SerializeHookIntegrity(JsonArchive& answer) {
546546
answer.Serialize("ScrHalt", HI.scriptHalt);
547547
answer.Serialize("Alive", HI.engineAlive);
548548
answer.Serialize("EnMouse", HI.enableMouse);
549+
answer.Serialize("PREPROCRDIR", HI.preprocRedirect);
549550
}
550551

551552
void Debugger::onScriptEcho(r_string msg) {
@@ -585,6 +586,59 @@ void Debugger::serializeScriptCommands(JsonArchive& answer) {
585586

586587
}
587588

589+
std::map<VariableScope, std::vector<r_string>> Debugger::getAvailableVariables(VariableScope scope) {
590+
std::map<VariableScope, std::vector<r_string>> ret;
591+
auto gs = intercept::client::host::functions.get_engine_allocator()->gameState;
592+
if (scope & VariableScope::local) {
593+
std::vector<r_string> list;
594+
if (gs->eval->local) {
595+
gs->eval->local->variables.for_each([&](const game_variable& var) {
596+
list.push_back(var.name);
597+
});
598+
}
599+
ret[VariableScope::local] = std::move(list);
600+
}
601+
602+
if (scope & VariableScope::missionNamespace) {
603+
std::vector<r_string> list;
604+
auto& varSpace = gs->namespaces[3]->_variables;
605+
606+
varSpace.for_each([&](const game_variable& var) {
607+
list.push_back(var.name);
608+
});
609+
ret[VariableScope::missionNamespace] = std::move(list);
610+
}
611+
612+
if (scope & VariableScope::uiNamespace) {
613+
std::vector<r_string> list;
614+
auto& varSpace = gs->namespaces[1]->_variables;
615+
varSpace.for_each([&](const game_variable& var) {
616+
list.push_back(var.name);
617+
});
618+
ret[VariableScope::uiNamespace] = std::move(list);
619+
}
620+
621+
if (scope & VariableScope::profileNamespace) {
622+
std::vector<r_string> list;
623+
auto& varSpace = gs->namespaces[0]->_variables;
624+
varSpace.for_each([&](const game_variable& var) {
625+
list.push_back(var.name);
626+
});
627+
ret[VariableScope::profileNamespace] = std::move(list);
628+
}
629+
630+
if (scope & VariableScope::parsingNamespace) {
631+
std::vector<r_string> list;
632+
auto& varSpace = gs->namespaces[2]->_variables;
633+
varSpace.for_each([&](const game_variable& var) {
634+
list.push_back(var.name);
635+
});
636+
ret[VariableScope::parsingNamespace] = std::move(list);
637+
}
638+
639+
return ret;
640+
}
641+
588642
std::vector<Debugger::VariableInfo> Debugger::getVariables(VariableScope scope, std::vector<std::string>& varNames) const {
589643
std::vector<Debugger::VariableInfo> output;
590644
if (state != DebuggerState::breakState) return output; //#TODO make global NS getVar work without breakstate

BIDebugEngine/BIDebugEngine/Debugger.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ struct HookIntegrity {
7070
bool scriptEcho{ false };
7171
bool engineAlive{ false };
7272
bool enableMouse{ false };
73+
bool preprocRedirect{ false };
7374
};
7475

7576

@@ -99,6 +100,7 @@ class Debugger {
99100
void SerializeHookIntegrity(JsonArchive& answer);
100101
void onScriptEcho(r_string msg);
101102
void serializeScriptCommands(JsonArchive& answer);
103+
std::map<VariableScope, std::vector<r_string>> getAvailableVariables(VariableScope scope_);
102104
HookIntegrity HI;
103105
GameState* lastKnownGameState;
104106

BIDebugEngine/BIDebugEngine/EngineHook.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -413,14 +413,19 @@ void EngineHook::placeHooks() {
413413
GlobalEngineHook._onScriptEcho(par);
414414
return {};
415415
}, game_data_type::NOTHING, game_data_type::STRING);
416-
static auto dumpStack = intercept::client::host::register_sqf_command("ade_dumpCallstack"sv, "", [](uintptr_t gs) -> game_value {
416+
static auto preprocHook = intercept::client::host::register_sqf_command("preprocessFile"sv, "", [](uintptr_t gs, game_value_parameter par) -> game_value {
417+
return intercept::sqf::preprocess_file_line_numbers(par);
418+
}, game_data_type::NOTHING, game_data_type::STRING);
419+
static auto dumpCallstack = intercept::client::host::register_sqf_command("ade_dumpCallstack"sv, "", [](uintptr_t gs) -> game_value {
420+
intercept::sqf::diag_log("ArmaDebugEngine Forced callstrack");
417421
GlobalDebugger.dumpStackToRPT(reinterpret_cast<GameState*>(gs));
418422
return {};
419423
}, game_data_type::NOTHING);
420424

421425
HI.scriptAssert = assertHook.has_function();
422426
HI.scriptHalt = haltHook.has_function();
423427
HI.scriptEcho = echoHook.has_function();
428+
HI.preprocRedirect = preprocHook.has_function();
424429
HI.__instructionBreakpoint = GASM.ready;
425430

426431

@@ -477,7 +482,8 @@ void EngineHook::placeHooks() {
477482
&& HI.scriptHalt
478483
&& HI.scriptEcho
479484
&& HI.engineAlive
480-
&& HI.enableMouse)) {
485+
&& HI.enableMouse
486+
&& HI.preprocRedirect)) {
481487
std::string error("Some hooks have failed. Certain functionality might not be available.\n\n");
482488

483489
bool fatal = false;
@@ -496,6 +502,7 @@ void EngineHook::placeHooks() {
496502
if (!HI.scriptEcho) error += "SCRECHO \tFAILED WARNING \n\tEffect: Script Command \"echo\" will not echo anything\n\n";
497503
if (!HI.engineAlive) error += "ALIVE \tFAILED WARNING \n\tEffect: Game might think it froze if a breakpoint is triggered\n\n";
498504
if (!HI.enableMouse) error += "ENMOUSE \tFAILED WARNING \n\tEffect: Mouse might be stuck in Game and has to be Freed by opening Task-Manager via CTRL+ALT+DEL\n\n";
505+
if (!HI.preprocRedirect) error += "PREPROCRDIR \tFAILED WARNING \n\tEffect: Line Numbers of CfgFunctions scripts that use #include will be wrong and breakpoints will not work.\n\n";
499506
if (fatal) error += "\n A Fatal error occured. Your Game version is not compatible with ArmaDebugEngine. Please tell a dev.";
500507

501508
#ifdef X64

BIDebugEngine/BIDebugEngine/NetworkController.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,31 @@ void NetworkController::incomingMessage(const std::string& message) {
150150
GlobalDebugger.serializeScriptCommands(answer);
151151
sendMessage(answer.to_string());
152152
} break;
153+
case NC_CommandType::getAvailableVariables: {
154+
JsonArchive ar(packet["data"]);
155+
uint16_t scope;
156+
ar.Serialize("scope", scope);//VariableScope::callstack not supported
157+
auto var = GlobalDebugger.getAvailableVariables(static_cast<VariableScope>(scope));
158+
159+
JsonArchive dataAr;
160+
161+
if (static_cast<VariableScope>(scope) & VariableScope::local)
162+
dataAr.Serialize("2", var[VariableScope::local]);
163+
if (static_cast<VariableScope>(scope) & VariableScope::missionNamespace)
164+
dataAr.Serialize("4", var[VariableScope::missionNamespace]);
165+
if (static_cast<VariableScope>(scope) & VariableScope::uiNamespace)
166+
dataAr.Serialize("8", var[VariableScope::uiNamespace]);
167+
if (static_cast<VariableScope>(scope) & VariableScope::profileNamespace)
168+
dataAr.Serialize("16", var[VariableScope::profileNamespace]);
169+
if (static_cast<VariableScope>(scope) & VariableScope::parsingNamespace)
170+
dataAr.Serialize("32", var[VariableScope::parsingNamespace]);
171+
172+
JsonArchive answer;
173+
answer.Serialize("data", dataAr);
174+
answer.Serialize("command", static_cast<int>(NC_OutgoingCommandType::AvailableVariablesReturn));
153175

176+
sendMessage(answer.to_string());
177+
} break;
154178
}
155179
}
156180
catch (std::exception &ex) {

BIDebugEngine/BIDebugEngine/NetworkController.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ enum class NC_CommandType {
1212
setHookEnable,
1313
getVariable,
1414
getCurrentCode, //While in breakState returns full preproced code of last Instructions script file
15-
getAllScriptCommands
15+
getAllScriptCommands,
16+
getAvailableVariables
1617
};
1718

1819
enum class NC_OutgoingCommandType {
@@ -25,7 +26,8 @@ enum class NC_OutgoingCommandType {
2526
halt_scriptHalt,
2627
halt_placeholder,
2728
ContinueExecution,
28-
VariableReturn //returning from getVariable
29+
VariableReturn, //returning from getVariable
30+
AvailableVariablesReturn, //returning from getAvailableVariables
2931
};
3032

3133
class NetworkController {

BIDebugEngine/BIDebugEngine/Serialize.h

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,20 @@ class JsonArchive {
126126
if (isReading) {
127127
if (_array.is_array()) {
128128
for (auto& it : _array) {
129-
value.push_back(it);
129+
if constexpr (std::is_convertible_v<Type, r_string>)
130+
value.emplace_back(r_string(it.get<std::string>()));
131+
else
132+
value.push_back(it);
130133
}
131134
}
132135
} else {
133-
for (Type& it : value)
134-
_array.push_back(it);
136+
for (Type& it : value) {
137+
if constexpr (std::is_convertible_v<Type, r_string>)
138+
_array.push_back(it.data());
139+
else
140+
_array.push_back(it);
141+
}
142+
135143
}
136144
}
137145

@@ -287,4 +295,4 @@ class Serialize {
287295
};
288296

289297

290-
static void from_json(const json& j, game_instruction& in) { }
298+
static void from_json(const json& j, game_instruction& in) { }

0 commit comments

Comments
 (0)