Skip to content

Commit

Permalink
Add initial Ineluki Key Patch support
Browse files Browse the repository at this point in the history
  • Loading branch information
Ghabry committed Jan 18, 2018
1 parent c8db865 commit 1dcf81b
Show file tree
Hide file tree
Showing 12 changed files with 260 additions and 11 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ set(PLAYER_SRCS
src/game_enemy.cpp
src/game_enemyparty.cpp
src/game_event.cpp
src/game_ineluki.cpp
src/game_interpreter_battle.cpp
src/game_interpreter.cpp
src/game_interpreter_map.cpp
Expand Down
2 changes: 2 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ libeasyrpg_player_la_SOURCES = \
src/game_enemyparty.h \
src/game_event.cpp \
src/game_event.h \
src/game_ineluki.cpp \
src/game_ineluki.h \
src/game_interpreter_battle.cpp \
src/game_interpreter_battle.h \
src/game_interpreter.cpp \
Expand Down
2 changes: 2 additions & 0 deletions builds/vs2015/PlayerLib.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,7 @@
<ClCompile Include="..\..\src\game_enemy.cpp" />
<ClCompile Include="..\..\src\game_enemyparty.cpp" />
<ClCompile Include="..\..\src\game_event.cpp" />
<ClCompile Include="..\..\src\game_ineluki.cpp" />
<ClCompile Include="..\..\src\game_interpreter.cpp" />
<ClCompile Include="..\..\src\game_interpreter_battle.cpp" />
<ClCompile Include="..\..\src\game_interpreter_map.cpp" />
Expand Down Expand Up @@ -627,6 +628,7 @@
<ClInclude Include="..\..\src\game_enemy.h" />
<ClInclude Include="..\..\src\game_enemyparty.h" />
<ClInclude Include="..\..\src\game_event.h" />
<ClInclude Include="..\..\src\game_ineluki.h" />
<ClInclude Include="..\..\src\game_interpreter.h" />
<ClInclude Include="..\..\src\game_interpreter_battle.h" />
<ClInclude Include="..\..\src\game_interpreter_map.h" />
Expand Down
6 changes: 6 additions & 0 deletions builds/vs2015/PlayerLib.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,9 @@
<ClCompile Include="..\..\src\game_event.cpp">
<Filter>Source Files\Engine\Game</Filter>
</ClCompile>
<ClCompile Include="..\..\src\game_ineluki.cpp">
<Filter>Source Files\Engine\Game</Filter>
</ClCompile>
<ClCompile Include="..\..\src\game_interpreter.cpp">
<Filter>Source Files\Engine\Game</Filter>
</ClCompile>
Expand Down Expand Up @@ -664,6 +667,9 @@
<ClInclude Include="..\..\src\game_event.h">
<Filter>Source Files\Engine\Game</Filter>
</ClInclude>
<ClInclude Include="..\..\src\game_ineluki.h">
<Filter>Source Files\Engine\Game</Filter>
</ClInclude>
<ClInclude Include="..\..\src\game_interpreter.h">
<Filter>Source Files\Engine\Game</Filter>
</ClInclude>
Expand Down
169 changes: 169 additions & 0 deletions src/game_ineluki.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
/*
* This file is part of EasyRPG Player.
*
* EasyRPG Player is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* EasyRPG Player is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with EasyRPG Player. If not, see <http://www.gnu.org/licenses/>.
*/

// Headers
#include "game_ineluki.h"
#include "filefinder.h"
#include "inireader.h"
#include "utils.h"
#include "output.h"
#include "audio.h"
#include "input.h"

Game_Ineluki::Game_Ineluki() {

}

bool Game_Ineluki::Execute(const RPG::Sound& se) {
if (functions.find(se.name) == functions.end()) {
if (!Parse(se)) {
return false;
}
}

for (const auto& cmd : functions[se.name]) {
Output::Debug("Ineluki %s %s", cmd.name.c_str(), cmd.arg.c_str());

if (cmd.name == "writetolog") {
Output::PostStr(cmd.arg);
} else if (cmd.name == "execprogram") {
Output::Warning("Ineluki ExecProgram %s: Not supported", cmd.arg.c_str());
} else if (cmd.name == "mcicommand") {
Output::Warning("Ineluki MciProgram %s: Not supported", cmd.arg.c_str());
} else if (cmd.name == "miditickfunction") {
std::string arg = Utils::LowerCase(cmd.arg);
if (arg == "original") {
output_mode = OutputMode::Original;
} else if (arg == "output") {
output_mode = OutputMode::Output;
} else if (arg == "clear") {
output_list.clear();
}
} else if (cmd.name == "addoutput") {
output_list.push_back(atoi(cmd.arg.c_str()));
} else if (cmd.name == "enablekeysupport") {
key_support = Utils::LowerCase(cmd.arg) == "true";
} else if (cmd.name == "registerkeydownevent") {
// TODO
} else if (cmd.name == "registerkeyupevent") {
// TODO
} else if (cmd.name == "enablemousesupport") {
mouse_support = Utils::LowerCase(cmd.arg) == "true";
mouse_id_prefix = atoi(cmd.arg2.c_str());
// automatic
} else if (cmd.name == "getmouseposition") {
int mouse_x;
int mouse_y;

Input::GetMousePosition(mouse_x, mouse_y);

bool left = Input::IsKeyPressed(Input::Keys::MOUSE_LEFT);
bool right = Input::IsKeyPressed(Input::Keys::MOUSE_RIGHT);

int key = left && right ? 3 : right ? 2 : left ? 1 : 0;

output_list.push_back(key);
output_list.push_back(mouse_y);
output_list.push_back(mouse_x);
output_list.push_back(mouse_id_prefix);
} else if (cmd.name == "setdebuglevel") {
// no-op
}
}

return true;
}

bool Game_Ineluki::Parse(const RPG::Sound& se) {
std::string ini_file = FileFinder::FindSound(se.name);

INIReader ini(ini_file);
if (ini.ParseError() == -1) {
return false;
}

command_list commands;
std::string section = "execute";

do {
InelukiCommand cmd;
cmd.name = Utils::LowerCase(ini.Get(section, "action", std::string()));
bool valid = true;

if (cmd.name == "writetolog") {
cmd.arg = ini.Get(section, "text", std::string());
} else if (cmd.name == "execprogram") {
cmd.arg = ini.Get(section, "command", std::string());
} else if (cmd.name == "mcicommand") {
cmd.arg = ini.Get(section, "command", std::string());
} else if (cmd.name == "miditickfunction") {
cmd.arg = ini.Get(section, "command", std::string());
if (cmd.arg.empty()) {
cmd.arg = ini.Get(section, "value", std::string());
}
} else if (cmd.name == "addoutput") {
cmd.arg = ini.Get(section, "value", std::string());
} else if (cmd.name == "enablekeysupport") {
cmd.arg = ini.Get(section, "enable", std::string());
} else if (cmd.name == "registerkeydownevent") {
cmd.arg = ini.Get(section, "key", std::string());
cmd.arg2 = ini.Get(section, "value", std::string());
} else if (cmd.name == "registerkeyupevent") {
cmd.arg = ini.Get(section, "key", std::string());
cmd.arg2 = ini.Get(section, "value", std::string());
} else if (cmd.name == "enablemousesupport") {
cmd.arg = ini.Get(section, "enable", std::string());
cmd.arg2 = ini.Get(section, "id", std::string());
cmd.arg3 = ini.Get(section, "automatic", std::string());
} else if (cmd.name == "getmouseposition") {
// no args
} else if (cmd.name == "setdebuglevel") {
cmd.arg = ini.Get(section, "level", std::string());
} else {
valid = false;
}

if (valid) {
commands.push_back(cmd);
}

section = ini.Get(section, "next", std::string());
} while (!section.empty());

functions[se.name] = commands;

return true;
}

int Game_Ineluki::GetMidiTicks() {
if (output_mode == OutputMode::Original) {
return Audio().BGM_GetTicks();
} else {
int val = 0;
if (!output_list.empty()) {
val = output_list.back();
output_list.pop_back();
}
return val;
}
}

void Game_Ineluki::Update() {
if (mouse_support) {

}
}
65 changes: 65 additions & 0 deletions src/game_ineluki.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* This file is part of EasyRPG Player.
*
* EasyRPG Player is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* EasyRPG Player is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with EasyRPG Player. If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef EP_GAME_INELUKI_H
#define EP_GAME_INELUKI_H

// Headers
#include <string>
#include <vector>
#include <map>

#include "rpg_sound.h"

class Game_Ineluki {
public:
Game_Ineluki();

bool Execute(const RPG::Sound& se);

int GetMidiTicks();

void Update();

private:
bool Parse(const RPG::Sound& se);

struct InelukiCommand {
std::string name;
std::string arg;
std::string arg2;
std::string arg3;
};

using command_list = std::vector<InelukiCommand>;

std::map<std::string, command_list> functions;

enum class OutputMode {
Original,
Output
};

OutputMode output_mode = OutputMode::Original;
std::vector<int> output_list;

bool key_support = false;
bool mouse_support = false;
int mouse_id_prefix = 0;
};

#endif
3 changes: 2 additions & 1 deletion src/game_interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "game_map.h"
#include "game_event.h"
#include "game_enemyparty.h"
#include "game_ineluki.h"
#include "game_player.h"
#include "game_targets.h"
#include "game_temp.h"
Expand Down Expand Up @@ -912,7 +913,7 @@ bool Game_Interpreter::CommandControlVariables(RPG::EventCommand const& com) { /
break;
case 8:
// MIDI play position
value = Audio().BGM_GetTicks();
value = Main_Data::game_ineluki->GetMidiTicks();
break;
case 9:
value = Main_Data::game_party->GetTimer(Main_Data::game_party->Timer2);
Expand Down
8 changes: 2 additions & 6 deletions src/game_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "bitmap.h"
#include "cache.h"
#include "output.h"
#include "game_ineluki.h"
#include "graphics.h"
#include "main_data.h"
#include "player.h"
Expand Down Expand Up @@ -117,12 +118,7 @@ void Game_System::SePlay(RPG::Sound const& se) {
std::string end = ".script";
if (se.name.length() >= end.length() &&
0 == se.name.compare(se.name.length() - end.length(), end.length(), end)) {
if (!ineluki_warning_shown) {
Output::Warning("This game seems to use Ineluki's key patch to support "
"additional keys, mouse or scripts. Such patches are "
"unsupported, so this functionality will not work!");
ineluki_warning_shown = true;
}
Main_Data::game_ineluki->Execute(se);
return;
}

Expand Down
4 changes: 2 additions & 2 deletions src/input_buttons_desktop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ void Input::InitButtons() {
buttons[FAST_FORWARD].push_back(Keys::F);

#if defined(USE_MOUSE) && defined(SUPPORT_MOUSE)
buttons[DECISION].push_back(Keys::MOUSE_LEFT);
buttons[CANCEL].push_back(Keys::MOUSE_RIGHT);
//buttons[DECISION].push_back(Keys::MOUSE_LEFT);
//buttons[CANCEL].push_back(Keys::MOUSE_RIGHT);
buttons[SHIFT].push_back(Keys::MOUSE_MIDDLE);
buttons[SCROLL_UP].push_back(Keys::MOUSE_SCROLLUP);
buttons[SCROLL_DOWN].push_back(Keys::MOUSE_SCROLLDOWN);
Expand Down
3 changes: 3 additions & 0 deletions src/main_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "game_actors.h"
#include "game_party.h"
#include "game_enemyparty.h"
#include "game_ineluki.h"
#include "game_player.h"
#include "game_screen.h"
#include "game_map.h"
Expand Down Expand Up @@ -68,6 +69,7 @@ namespace Main_Data {
std::unique_ptr<Game_Player> game_player;
std::unique_ptr<Game_Party> game_party;
std::unique_ptr<Game_EnemyParty> game_enemyparty;
std::unique_ptr<Game_Ineluki> game_ineluki;

RPG::Save game_data;
}
Expand Down Expand Up @@ -171,6 +173,7 @@ void Main_Data::Cleanup() {
game_player.reset();
game_party.reset();
game_enemyparty.reset();
game_ineluki.reset();

game_data = RPG::Save();
}
Expand Down
6 changes: 4 additions & 2 deletions src/main_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,23 @@ class Game_Player;
class Game_Screen;
class Game_Party;
class Game_EnemyParty;
class Game_Ineluki;

namespace Main_Data {
// Dynamic Game Data
extern std::unique_ptr<Game_Screen> game_screen;
extern std::unique_ptr<Game_Player> game_player;
extern std::unique_ptr<Game_Party> game_party;
extern std::unique_ptr<Game_EnemyParty> game_enemyparty;
extern std::unique_ptr<Game_Ineluki> game_ineluki;
extern RPG::Save game_data;

void Init();
void Cleanup();

const std::string& GetProjectPath();
void SetProjectPath(const std::string& path);

const std::string& GetSavePath();
void SetSavePath(const std::string& path);
}
Expand Down
Loading

0 comments on commit 1dcf81b

Please sign in to comment.