From 26894c8a696c7e1d8f571f796dc4d619fe049776 Mon Sep 17 00:00:00 2001 From: gsemaj Date: Sat, 1 May 2021 21:19:36 -0400 Subject: [PATCH] Implement automatic tdata patching --- src/TableData.cpp | 15 ++++++++++++++- src/TableData.hpp | 1 + 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/TableData.cpp b/src/TableData.cpp index 4f8255c..15f12e3 100644 --- a/src/TableData.cpp +++ b/src/TableData.cpp @@ -1013,7 +1013,20 @@ void TableData::init() { } fstream.close(); - // patching + // patching: loop through every directory within the patch directory, looking for a matching file + json patch; + for (const auto& patchModule : std::filesystem::directory_iterator(settings::PATCHDIR)) { + // this is the theoretical path of a corresponding patch for this file + std::string patchFile = patchModule.path().generic_u8string() + "/" + table.second; + if (std::filesystem::exists(patchFile)) { + // file exists + std::cout << "[INFO] Patching " << patchFile << std::endl; + fstream.open(patchFile); + fstream >> patch; // load into temporary json object + patchJSON(table.first, &patch); // patch + fstream.close(); + } + } } // fetch data from patched tables and load them appropriately diff --git a/src/TableData.hpp b/src/TableData.hpp index b3eaa64..f062868 100644 --- a/src/TableData.hpp +++ b/src/TableData.hpp @@ -1,5 +1,6 @@ #pragma once #include +#include #include "NPCManager.hpp"