From c25e3a863ed854f9d7d19aa67c23a7f1ee740509 Mon Sep 17 00:00:00 2001 From: Mauro Junior <45118493+jetrotal@users.noreply.github.com> Date: Mon, 30 Oct 2023 07:12:52 -0300 Subject: [PATCH] @easyrpg_raw DynRPG command Invoke a command using raw values, similar to how maniacs patch raw work. NOTE FIXME PLS. --- src/dynrpg.cpp | 2 +- src/dynrpg_easyrpg.cpp | 31 +++++++++++++++++++++++++++++++ src/dynrpg_easyrpg.h | 2 ++ 3 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/dynrpg.cpp b/src/dynrpg.cpp index 00870d9e341..9ecd3cd56e5 100644 --- a/src/dynrpg.cpp +++ b/src/dynrpg.cpp @@ -32,7 +32,7 @@ #include "dynrpg_textplugin.h" #include -std::unordered_set whiteList = { "@easyrpg_output" }; +std::unordered_set whiteList = { "@easyrpg_output", "@easyrpg_raw" }; enum DynRpg_ParseMode { ParseMode_Function, diff --git a/src/dynrpg_easyrpg.cpp b/src/dynrpg_easyrpg.cpp index d5ba93e1813..6878ae1ff8e 100644 --- a/src/dynrpg_easyrpg.cpp +++ b/src/dynrpg_easyrpg.cpp @@ -48,6 +48,36 @@ static bool EasyOput(dyn_arg_list args) { return true; } +static bool EasyRaw(dyn_arg_list args) { + auto func = "raw"; + bool okay = false; + + lcf::rpg::EventCommand outputCommand; + std::vector outputParams = {}; + + for (std::size_t i = 0; i < args.size(); ++i) { + std::string currValue = DynRpg::ParseVarArg(func, args, i, okay); + Output::Warning("{}", currValue); + + if (!okay) return true; + + if (i == 0) outputCommand.code = stoi(currValue); + if (i == 1) outputCommand.string = lcf::DBString(currValue); + else outputParams.push_back(stoi(currValue)); + } + + outputCommand.parameters = lcf::DBArray(outputParams.begin(), outputParams.end()); + + //FIXME: this will crash when you two interpreters run a raw command in parallel. + // The lack to access the current interpreter frame is a lack in the dynrpg API design. + // Have to fix this. The current frame should be easy to access + std::vector cmdList = { outputCommand }; + if (Game_Battle::IsBattleRunning()) Game_Battle::GetInterpreter().Push(cmdList, 0, false); + else Game_Map::GetInterpreter().Push(cmdList, 0, false); + + return true; +} + static bool EasyCall(dyn_arg_list args) { auto token = std::get<0>(DynRpg::ParseArgs("call", args)); @@ -92,6 +122,7 @@ void DynRpg::EasyRpgPlugin::RegisterFunctions() { DynRpg::RegisterFunction("call", EasyCall); DynRpg::RegisterFunction("easyrpg_output", EasyOput); DynRpg::RegisterFunction("easyrpg_add", EasyAdd); + DynRpg::RegisterFunction("easyrpg_raw", EasyRaw); } void DynRpg::EasyRpgPlugin::Load(const std::vector& buffer) { diff --git a/src/dynrpg_easyrpg.h b/src/dynrpg_easyrpg.h index 4afd71197b8..b4ba98f4569 100644 --- a/src/dynrpg_easyrpg.h +++ b/src/dynrpg_easyrpg.h @@ -19,6 +19,8 @@ #define EP_DYNRPG_EASYRPG_H #include "dynrpg.h" +#include "game_battle.h" +#include "game_map.h" namespace DynRpg { /**