Skip to content

Commit

Permalink
@easyrpg_raw DynRPG command
Browse files Browse the repository at this point in the history
Invoke a command using raw values, similar to how maniacs patch raw work.
NOTE FIXME PLS.
  • Loading branch information
jetrotal committed Oct 30, 2023
1 parent 8cf440f commit c25e3a8
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/dynrpg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#include "dynrpg_textplugin.h"
#include <unordered_set>

std::unordered_set<std::string> whiteList = { "@easyrpg_output" };
std::unordered_set<std::string> whiteList = { "@easyrpg_output", "@easyrpg_raw" };

enum DynRpg_ParseMode {
ParseMode_Function,
Expand Down
31 changes: 31 additions & 0 deletions src/dynrpg_easyrpg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int32_t> 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<int32_t>(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<lcf::rpg::EventCommand> 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<std::string>("call", args));

Expand Down Expand Up @@ -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<uint8_t>& buffer) {
Expand Down
2 changes: 2 additions & 0 deletions src/dynrpg_easyrpg.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#define EP_DYNRPG_EASYRPG_H

#include "dynrpg.h"
#include "game_battle.h"
#include "game_map.h"

namespace DynRpg {
/**
Expand Down

0 comments on commit c25e3a8

Please sign in to comment.