forked from twig33/ynoclient
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathdynrpg_easyrpg.cpp
117 lines (96 loc) · 2.98 KB
/
dynrpg_easyrpg.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/*
* 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 <map>
#include "dynrpg_easyrpg.h"
#include "main_data.h"
#include "game_variables.h"
#include "utils.h"
#include "version.h"
static bool EasyOput(dyn_arg_list args) {
auto func = "output";
bool okay = false;
std::string mode;
std::tie(mode, std::ignore) = DynRpg::ParseArgs<std::string, std::string>(func, args, &okay);
if (!okay)
return true;
mode = Utils::LowerCase(mode);
auto msg = DynRpg::ParseVarArg(func, args, 1, okay);
if (mode == "debug") {
Output::DebugStr(msg);
} else if (mode == "info") {
Output::InfoStr(msg);
} else if (mode == "warning") {
Output::WarningStr(msg);
} else if (mode == "error") {
Output::ErrorStr(msg);
}
return true;
}
static bool EasyCall(dyn_arg_list args) {
auto token = std::get<0>(DynRpg::ParseArgs<std::string>("call", args));
if (token.empty()) {
// empty function name
Output::Warning("call: Empty RPGSS function name");
return true;
}
if (!DynRpg::HasFunction(token)) {
// Not a supported function
Output::Warning("Unsupported RPGSS function: {}", token);
return true;
}
return DynRpg::Invoke(token, args.subspan(1));
}
static bool EasyAdd(dyn_arg_list args) {
auto func = "easyrpg_add";
bool okay = false;
int target_var;
int val;
std::tie(target_var, val) = DynRpg::ParseArgs<int, int>(func, args, &okay);
if (!okay)
return true;
for (size_t i = 2; i < args.size(); ++i) {
val += std::get<0>(DynRpg::ParseArgs<int>(func, args.subspan(i), &okay));
if (!okay)
return true;
}
Main_Data::game_variables->Set(target_var, val);
return true;
}
void DynRpg::EasyRpgPlugin::RegisterFunctions() {
DynRpg::RegisterFunction("call", EasyCall);
DynRpg::RegisterFunction("easyrpg_output", EasyOput);
DynRpg::RegisterFunction("easyrpg_add", EasyAdd);
}
void DynRpg::EasyRpgPlugin::Load(const std::vector<uint8_t>& buffer) {
if (buffer.size() < 4) {
Output::Warning("EasyRpgPlugin: Bad savegame data");
} else {
uint32_t ver;
memcpy(&ver, buffer.data(), 4);
Utils::SwapByteOrder(ver);
Output::Debug("DynRpg Savegame version {}", ver);
}
}
std::vector<uint8_t> DynRpg::EasyRpgPlugin::Save() {
std::vector<uint8_t> save_data;
save_data.resize(4);
uint32_t version = PLAYER_SAVEGAME_VERSION;
Utils::SwapByteOrder(version);
memcpy(&save_data[0], reinterpret_cast<char*>(&version), 4);
return save_data;
}