Skip to content

Commit

Permalink
DynLoader Proof-of-concept: Matching & automatically applying known I…
Browse files Browse the repository at this point in the history
…PS Patches + QuickPatches (DynRPG compatibility)
  • Loading branch information
florianessl committed Feb 27, 2025
1 parent 728e3f3 commit c29acc7
Show file tree
Hide file tree
Showing 10 changed files with 487 additions and 41 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ add_library(${PROJECT_NAME} OBJECT
src/game_destiny.h
src/game_dynrpg.cpp
src/game_dynrpg.h
src/game_dynrpg_loader.cpp
src/game_dynrpg_loader.h
src/game_enemy.cpp
src/game_enemy.h
src/game_enemyparty.cpp
Expand Down
2 changes: 2 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ libeasyrpg_player_a_SOURCES = \
src/game_destiny.h \
src/game_dynrpg.cpp \
src/game_dynrpg.h \
src/game_dynrpg_loader.cpp \
src/game_dynrpg_loader.h \
src/game_enemy.cpp \
src/game_enemy.h \
src/game_enemyparty.cpp \
Expand Down
3 changes: 3 additions & 0 deletions src/exe_buildinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,9 @@ namespace EXE::BuildInfo {
patch_segment_data chk_segment_data;
size_t extract_var_offset;

constexpr PatchDetectionInfo() :
chk_segment_offset(0), chk_segment_data({}), extract_var_offset(0) {
}
constexpr PatchDetectionInfo(size_t chk_segment_offset, patch_segment_data chk_segment_data) :
chk_segment_offset(chk_segment_offset), chk_segment_data(chk_segment_data), extract_var_offset(0) {
}
Expand Down
30 changes: 30 additions & 0 deletions src/exe_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,36 @@ namespace EXE::Constants {
}}
}
}};

inline EXE::Constants::code_address_map const* GetConstantAddressesForBuildInfo(EXE::BuildInfo::EngineType engine_type, EXE::BuildInfo::KnownEngineBuildVersions build_version) {
switch (engine_type) {
case EXE::BuildInfo::EngineType::RPG2000:
{
auto& builds = known_engine_builds_rm2k;
auto it = std::find_if(builds.begin(), builds.end(), [&](const auto& pair) {
return pair.first == build_version;
});
if (it != builds.end()) {
return &it->second;
}
}
break;
case EXE::BuildInfo::EngineType::RPG2003:
{
auto& builds = known_engine_builds_rm2k3;
auto it = std::find_if(builds.begin(), builds.end(), [&](const auto& pair) {
return pair.first == build_version;
});
if (it != builds.end()) {
return &it->second;
}
}
break;
default:
break;
}
return nullptr;
}
}

#endif
29 changes: 2 additions & 27 deletions src/exe_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ int EXEReader::FileInfo::GetEngineType(bool& is_maniac_patch) const {
return Player::EngineNone;
}

std::map<EXE::Shared::GameConstantType, int32_t> EXEReader::GetOverridenGameConstants() {
std::map<EXE::Shared::GameConstantType, int32_t> EXEReader::GetOverriddenGameConstants() {
constexpr bool debug_const_extraction = true;

std::map<EXE::Shared::GameConstantType, int32_t> game_constants;
Expand Down Expand Up @@ -597,32 +597,7 @@ std::map<EXE::Shared::GameConstantType, int32_t> EXEReader::GetOverridenGameCons
EXE::BuildInfo::kEngineTypes.tag(build_info.engine_type),
EXE::BuildInfo::kKnownEngineBuildDescriptions.tag(build_version));

EXE::Constants::code_address_map const* constant_addresses = nullptr;

switch (build_info.engine_type) {
case EXE::BuildInfo::EngineType::RPG2000:
{
auto& builds = EXE::Constants::known_engine_builds_rm2k;
auto it = std::find_if(builds.begin(), builds.end(), [&](const auto& pair) {
return pair.first == build_version;
});
if (it != builds.end()) {
constant_addresses = &it->second;
}
}
break;
case EXE::BuildInfo::EngineType::RPG2003:
{
auto& builds = EXE::Constants::known_engine_builds_rm2k3;
auto it = std::find_if(builds.begin(), builds.end(), [&](const auto& pair) {
return pair.first == build_version;
});
if (it != builds.end()) {
constant_addresses = &it->second;
}
}
break;
}
auto constant_addresses = EXE::Constants::GetConstantAddressesForBuildInfo(build_info.engine_type, build_version);

switch (build_version) {
case EXE::BuildInfo::RM2KE_162:
Expand Down
2 changes: 1 addition & 1 deletion src/exe_reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class EXEReader {

const FileInfo& GetFileInfo();

std::map<EXE::Shared::GameConstantType, int32_t> GetOverridenGameConstants();
std::map<EXE::Shared::GameConstantType, int32_t> GetOverriddenGameConstants();

std::map<EXE::Shared::EmbeddedStringTypes, std::string> GetEmbeddedStrings(std::string encoding);

Expand Down
8 changes: 8 additions & 0 deletions src/exe_shared.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#ifndef EP_EXE_SHARED_H
#define EP_EXE_SHARED_H

#include <map>
#include <string>
#include <lcf/enum_tags.h>

namespace EXE::Shared {
Expand Down Expand Up @@ -152,6 +154,12 @@ namespace EXE::Shared {
KnownPatches patch_type;
int32_t custom_var_1;
};

struct EngineCustomization {
std::map<GameConstantType, int32_t> constant_overrides;
std::map<EmbeddedStringTypes, std::string> strings;
std::map<KnownPatches, PatchSetupInfo> runtime_patches;
};
}

#endif
Loading

0 comments on commit c29acc7

Please sign in to comment.