diff --git a/src/game_interpreter.cpp b/src/game_interpreter.cpp index 68d5f01ff3..5fefca8996 100644 --- a/src/game_interpreter.cpp +++ b/src/game_interpreter.cpp @@ -566,56 +566,6 @@ void Game_Interpreter::SkipToNextConditional(std::initializer_list codes, i } } -int Game_Interpreter::DecodeInt(lcf::DBArray::const_iterator& it) { - int value = 0; - - for (;;) { - int x = *it++; - value <<= 7; - value |= x & 0x7F; - if (!(x & 0x80)) - break; - } - - return value; -} - -const std::string Game_Interpreter::DecodeString(lcf::DBArray::const_iterator& it) { - std::ostringstream out; - int len = DecodeInt(it); - - for (int i = 0; i < len; i++) - out << (char)*it++; - - std::string result = lcf::ReaderUtil::Recode(out.str(), Player::encoding); - - return result; -} - -lcf::rpg::MoveCommand Game_Interpreter::DecodeMove(lcf::DBArray::const_iterator& it) { - lcf::rpg::MoveCommand cmd; - cmd.command_id = *it++; - - switch (cmd.command_id) { - case 32: // Switch ON - case 33: // Switch OFF - cmd.parameter_a = DecodeInt(it); - break; - case 34: // Change Graphic - cmd.parameter_string = lcf::DBString(DecodeString(it)); - cmd.parameter_a = DecodeInt(it); - break; - case 35: // Play Sound Effect - cmd.parameter_string = lcf::DBString(DecodeString(it)); - cmd.parameter_a = DecodeInt(it); - cmd.parameter_b = DecodeInt(it); - cmd.parameter_c = DecodeInt(it); - break; - } - - return cmd; -} - // Execute Command. bool Game_Interpreter::ExecuteCommand() { auto& frame = GetFrame(); @@ -5056,23 +5006,6 @@ bool Game_Interpreter::IsWaitingForWaitCommand() const { return (_state.wait_time > 0) || _state.wait_key_enter; } -bool Game_Interpreter::ManiacCheckContinueLoop(int val, int val2, int type, int op) const { - switch (type) { - case 0: // Infinite loop - return true; - case 1: // X times - case 2: // Count up - return val <= val2; - case 3: // Count down - return val >= val2; - case 4: // While - case 5: // Do While - return CheckOperator(val, val2, op); - default: - return false; - } -} - int Game_Interpreter::ManiacBitmask(int value, int mask) const { if (Player::IsPatchManiac()) { return value & mask; diff --git a/src/game_interpreter.h b/src/game_interpreter.h index 665be1da7f..a6b370cbb2 100644 --- a/src/game_interpreter.h +++ b/src/game_interpreter.h @@ -286,10 +286,6 @@ class Game_Interpreter : public Game_BaseInterpreterContext bool CommandManiacCallCommand(lcf::rpg::EventCommand const& com); bool CommandEasyRpgSetInterpreterFlag(lcf::rpg::EventCommand const& com); - int DecodeInt(lcf::DBArray::const_iterator& it); - const std::string DecodeString(lcf::DBArray::const_iterator& it); - lcf::rpg::MoveCommand DecodeMove(lcf::DBArray::const_iterator& it); - void SetSubcommandIndex(int indent, int idx); uint8_t& ReserveSubcommandIndex(int indent); int GetSubcommandIndex(int indent) const; @@ -329,7 +325,6 @@ class Game_Interpreter : public Game_BaseInterpreterContext void toSave(lcf::rpg::SaveEventExecState& save) const; }; - bool ManiacCheckContinueLoop(int val, int val2, int type, int op) const; int ManiacBitmask(int value, int mask) const; lcf::rpg::SaveEventExecState _state; diff --git a/src/game_interpreter_shared.cpp b/src/game_interpreter_shared.cpp index 96ff559d54..8e5b5ef873 100644 --- a/src/game_interpreter_shared.cpp +++ b/src/game_interpreter_shared.cpp @@ -36,6 +36,7 @@ #include #include #include +#include using Main_Data::game_switches, Main_Data::game_variables, Main_Data::game_strings; @@ -185,3 +186,54 @@ StringView Game_Interpreter_Shared::CommandStringOrVariableBitfield(lcf::rpg::Ev return com.string; } + + +int Game_Interpreter_Shared::DecodeInt(lcf::DBArray::const_iterator& it) { + int value = 0; + + for (;;) { + int x = *it++; + value <<= 7; + value |= x & 0x7F; + if (!(x & 0x80)) + break; + } + + return value; +} + +const std::string Game_Interpreter_Shared::DecodeString(lcf::DBArray::const_iterator& it) { + std::ostringstream out; + int len = DecodeInt(it); + + for (int i = 0; i < len; i++) + out << (char)*it++; + + std::string result = lcf::ReaderUtil::Recode(out.str(), Player::encoding); + + return result; +} + +lcf::rpg::MoveCommand Game_Interpreter_Shared::DecodeMove(lcf::DBArray::const_iterator& it) { + lcf::rpg::MoveCommand cmd; + cmd.command_id = *it++; + + switch (cmd.command_id) { + case 32: // Switch ON + case 33: // Switch OFF + cmd.parameter_a = DecodeInt(it); + break; + case 34: // Change Graphic + cmd.parameter_string = lcf::DBString(DecodeString(it)); + cmd.parameter_a = DecodeInt(it); + break; + case 35: // Play Sound Effect + cmd.parameter_string = lcf::DBString(DecodeString(it)); + cmd.parameter_a = DecodeInt(it); + cmd.parameter_b = DecodeInt(it); + cmd.parameter_c = DecodeInt(it); + break; + } + + return cmd; +} diff --git a/src/game_interpreter_shared.h b/src/game_interpreter_shared.h index 223cd48bf5..4d8742e46a 100644 --- a/src/game_interpreter_shared.h +++ b/src/game_interpreter_shared.h @@ -20,6 +20,7 @@ #define EP_GAME_INTERPRETER_SHARED #include +#include #include #include @@ -60,18 +61,18 @@ namespace Game_Interpreter_Shared { * Indicates how the target of an interpreter operation (lvalue) should be evaluated. */ enum TargetEvalMode : std::int8_t { // 4 bits - eTargetEval_Single = 0, // v[x] - eTargetEval_Range = 1, // v[x...y] - eTargetEval_IndirectSingle = 2, // v[v[x]] - eTargetEval_IndirectRange = 3, // v[v[x]...v[y]] (ManiacPatch) - eTargetEval_Expression = 4 // ManiacPatch expression + eTargetEval_Single = 0, // v[x] + eTargetEval_Range = 1, // v[x...y] + eTargetEval_IndirectSingle = 2, // v[v[x]] + eTargetEval_IndirectRange = 3, // v[v[x]...v[y]] (ManiacPatch) + eTargetEval_Expression = 4 // ManiacPatch expression }; /* * Indicates how an operand of an interpreter operation (rvalue) should be evaluted. */ enum ValueEvalMode : std::int8_t { // 4 bits - eValueEval_Constant = 0, // Constant value is given + eValueEval_Constant = 0, // Constant value is given eValueEval_Variable = 1, eValueEval_VariableIndirect = 2, eValueEval_Switch = 3, @@ -123,6 +124,12 @@ namespace Game_Interpreter_Shared { StringView CommandStringOrVariableBitfield(lcf::rpg::EventCommand const& com, int mode_idx, int shift, int val_idx); bool CheckOperator(int val, int val2, int op); + + int DecodeInt(lcf::DBArray::const_iterator& it); + const std::string DecodeString(lcf::DBArray::const_iterator& it); + lcf::rpg::MoveCommand DecodeMove(lcf::DBArray::const_iterator& it); + + bool ManiacCheckContinueLoop(int val, int val2, int type, int op); } inline bool Game_Interpreter_Shared::CheckOperator(int val, int val2, int op) { @@ -144,6 +151,23 @@ inline bool Game_Interpreter_Shared::CheckOperator(int val, int val2, int op) { } } +inline bool Game_Interpreter_Shared::ManiacCheckContinueLoop(int val, int val2, int type, int op) { + switch (type) { + case 0: // Infinite loop + return true; + case 1: // X times + case 2: // Count up + return val <= val2; + case 3: // Count down + return val >= val2; + case 4: // While + case 5: // Do While + return CheckOperator(val, val2, op); + default: + return false; + } +} + //explicit declarations for target evaluation logic shared between ControlSwitches/ControlVariables/ControlStrings template bool Game_BaseInterpreterContext::DecodeTargetEvaluationMode(lcf::rpg::EventCommand const&, int&, int&) const; template bool Game_BaseInterpreterContext::DecodeTargetEvaluationMode(lcf::rpg::EventCommand const&, int&, int&) const;