Skip to content

Commit c3ec786

Browse files
committed
Refactored data types & implementation for constant extraction & patch detection (Properly inlined declaration of constants without much code overhead; relocation of build-related info into a new file "exe_buildinfo.h")
1 parent e9bf42d commit c3ec786

7 files changed

Lines changed: 666 additions & 370 deletions

File tree

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ add_library(${PROJECT_NAME} OBJECT
109109
src/dynrpg_textplugin.h
110110
src/enemyai.cpp
111111
src/enemyai.h
112+
src/exe_buildinfo.h
112113
src/exe_constants.h
113114
src/exe_reader.cpp
114115
src/exe_reader.h

Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ libeasyrpg_player_a_SOURCES = \
8989
src/dynrpg_textplugin.cpp \
9090
src/enemyai.cpp \
9191
src/enemyai.h \
92+
src/exe_buildinfo.h \
9293
src/exe_constants.h \
9394
src/exe_reader.cpp \
9495
src/exe_reader.h \

src/exe_buildinfo.h

Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
/*
2+
* This file is part of EasyRPG Player.
3+
*
4+
* EasyRPG Player is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* EasyRPG Player is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with EasyRPG Player. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
#ifndef EP_EXE_BUILDINFO_H
19+
#define EP_EXE_BUILDINFO_H
20+
21+
#include <cstdint>
22+
#include <lcf/enum_tags.h>
23+
#include "utils.h"
24+
25+
namespace BuildInfo {
26+
27+
enum class EngineType {
28+
UnknownEngine = 0,
29+
RPG2000,
30+
RPG2003,
31+
RM2k3_MP,
32+
EasyRPG
33+
};
34+
35+
static constexpr auto kEngineTypes = lcf::makeEnumTags<EngineType>(
36+
"Unknown",
37+
"RPG2000",
38+
"RPG2003",
39+
"RM2k3_MP",
40+
"EasyRPG"
41+
);
42+
43+
enum KnownEngineBuildVersions {
44+
UnknownBuild = 0,
45+
46+
RM2K_20000306,
47+
RM2K_2000XXXX_UNK,
48+
RM2K_20000507,
49+
RM2K_20000619,
50+
RM2K_20000711,
51+
RM2K_20001113,
52+
RM2K_20001115,
53+
RM2K_20001227,
54+
RM2K_20010505,
55+
RM2K_20030327,
56+
RM2K_20030625,
57+
RM2KE_160,
58+
RM2KE_161,
59+
RM2KE_162,
60+
61+
RM2K3_100,
62+
RM2K3_UNK_1,
63+
RM2K3_UNK_2,
64+
RM2K3_1021_1021,
65+
RM2K3_1030_1030_1,
66+
RM2K3_1030_1030_2,
67+
RM2K3_1030_1040,
68+
RM2K3_1050_1050_1,
69+
RM2K3_1050_1050_2,
70+
RM2K3_1060_1060,
71+
RM2K3_1070_1070,
72+
RM2K3_1080_1080,
73+
RM2K3_1091_1091,
74+
75+
LAST_RM2K = RM2KE_162,
76+
LAST_RM2K3 = RM2K3_1091_1091,
77+
LAST
78+
};
79+
80+
static constexpr auto kKnownEngineBuildDescriptions = lcf::makeEnumTags<KnownEngineBuildVersions>(
81+
"UnknownBuild",
82+
83+
"1.00",
84+
"2000-Unk",
85+
"2000-05-07",
86+
"2000-06-19",
87+
"2000-07-11",
88+
"2000-11-13",
89+
"2000-11-15",
90+
"1.07",
91+
"1.10",
92+
"1.50 (VALUE!)",
93+
"1.51 (VALUE!)",
94+
"1.60 (English)",
95+
"1.61 (English)",
96+
"1.62 (English)",
97+
98+
"1.0.0",
99+
"1.0.1_UNK1",
100+
"1.0.1_UNK2",
101+
"1.0.2.1",
102+
"1.0.3.1",
103+
"1.0.3.2",
104+
"1.0.4.0",
105+
"1.0.5.1",
106+
"1.0.5.2",
107+
"1.0.6",
108+
"1.0.7",
109+
"1.0.8",
110+
"1.0.9.1"
111+
);
112+
113+
static_assert(kKnownEngineBuildDescriptions.size() == static_cast<size_t>(KnownEngineBuildVersions::LAST));
114+
115+
constexpr size_t count_known_engine_builds = KnownEngineBuildVersions::LAST;
116+
constexpr size_t count_known_rm2k_builds = 1 + KnownEngineBuildVersions::LAST_RM2K - KnownEngineBuildVersions::RM2K_20000306;
117+
constexpr size_t count_known_rm2k3_builds = 1 + KnownEngineBuildVersions::LAST_RM2K3 - KnownEngineBuildVersions::RM2K3_100;
118+
119+
struct EngineBuildInfo {
120+
EngineType engine_type;
121+
int32_t code_size;
122+
int32_t entrypoint;
123+
124+
constexpr EngineBuildInfo() :
125+
engine_type(EngineType::UnknownEngine), code_size(0), entrypoint(0) {
126+
}
127+
128+
constexpr EngineBuildInfo(EngineType engine_type, int32_t code_size, int32_t entrypoint) :
129+
engine_type(engine_type), code_size(code_size), entrypoint(entrypoint) {
130+
}
131+
};
132+
133+
using engine_buildinfo_map = std::array<std::pair<KnownEngineBuildVersions, EngineBuildInfo>, count_known_engine_builds>;
134+
135+
constexpr engine_buildinfo_map known_engine_builds = {{
136+
{ UnknownBuild, { EngineType::UnknownEngine, 0, 0 } },
137+
138+
{ RM2K_20000306, { EngineType::RPG2000, 0x96400, 0x097220 } },
139+
{ RM2K_2000XXXX_UNK, { EngineType::RPG2000, 0x96600, 0x0972C4 } },
140+
{ RM2K_20000507, { EngineType::RPG2000, 0x96600, 0x0972D8 } },
141+
{ RM2K_20000619, { EngineType::RPG2000, 0x96C00, 0x097940 } },
142+
{ RM2K_20000711, { EngineType::RPG2000, 0x96E00, 0x097B50 } },
143+
{ RM2K_20001113, { EngineType::RPG2000, 0x96800, 0x0975E4 } },
144+
{ RM2K_20001115, { EngineType::RPG2000, 0x96800, 0x0975EC } },
145+
{ RM2K_20001227, { EngineType::RPG2000, 0x96A00, 0x097744 } },
146+
{ RM2K_20010505, { EngineType::RPG2000, 0x96A00, 0x097710 } },
147+
{ RM2K_20030327, { EngineType::RPG2000, 0x9BC00, 0x09CA80 } },
148+
{ RM2K_20030625, { EngineType::RPG2000, 0x9BE00, 0x09CC30 } },
149+
{ RM2KE_160, { EngineType::RPG2000, 0x9C000, 0x09CC78 } },
150+
{ RM2KE_161, { EngineType::RPG2000, 0x9CA00, 0x09D708 } },
151+
{ RM2KE_162, { EngineType::RPG2000, 0x9CC00, 0x09D930 } },
152+
153+
{ RM2K3_100, { EngineType::RPG2003, 0xBD600, 0x0BE3F4 } },
154+
{ RM2K3_UNK_1, { EngineType::RPG2003, 0xBF200, 0x0BFF50 } },
155+
{ RM2K3_UNK_2, { EngineType::RPG2003, 0xBE800, 0x0BF6A8 } },
156+
{ RM2K3_1021_1021, { EngineType::RPG2003, 0xBF400, 0x0C00CC } },
157+
{ RM2K3_1030_1030_1, { EngineType::RPG2003, 0xBFE00, 0x0C0B90 } },
158+
{ RM2K3_1030_1030_2, { EngineType::RPG2003, 0xC0A00, 0x0C1878 } },
159+
{ RM2K3_1030_1040, { EngineType::RPG2003, 0xC0800, 0x0C14D8 } },
160+
{ RM2K3_1050_1050_1, { EngineType::RPG2003, 0xC7400, 0x0C81C4 } },
161+
{ RM2K3_1050_1050_2, { EngineType::RPG2003, 0xC7400, 0x0C81F0 } },
162+
{ RM2K3_1060_1060, { EngineType::RPG2003, 0xC8A00, 0x0C9804 } },
163+
{ RM2K3_1070_1070, { EngineType::RPG2003, 0xC8C00, 0x0C9984 } },
164+
{ RM2K3_1080_1080, { EngineType::RPG2003, 0xC8E00, 0x0C9C1C } },
165+
{ RM2K3_1091_1091, { EngineType::RPG2003, 0xC9000, 0x0C9D24 } }
166+
}};
167+
}
168+
169+
#endif

0 commit comments

Comments
 (0)