Skip to content

Commit 26512ed

Browse files
Enderclem0enderclemclaude
authored
Add rom.data.add_granny_file and add_package_file Lua APIs (#27)
Allows mods to register custom GPK/PKG files for file-redirection at runtime, after the initial plugins_data scan has completed. This enables mods that generate assets during Lua plugin init (before LoadAllModelAndAnimationData runs) to have those assets picked up by the game's normal loading path without requiring a restart. Co-authored-by: enderclem <enderclem@gmail.com> Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 0b111c6 commit 26512ed

1 file changed

Lines changed: 41 additions & 0 deletions

File tree

  • src/lua_extensions/bindings/hades

src/lua_extensions/bindings/hades/data.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ namespace sgg
2020
};
2121
} // namespace sgg
2222

23+
// Defined in main.cpp — file redirect maps for custom GPK/PKG assets
24+
extern std::unordered_map<std::string, std::string> additional_granny_files;
25+
extern std::unordered_map<std::string, std::string> additional_package_files;
26+
2327
namespace lua::hades::data
2428
{
2529
static std::recursive_mutex g_load_packages_overrides_mutex;
@@ -145,6 +149,41 @@ namespace lua::hades::data
145149
LOG(INFO) << ss.str();
146150
}
147151

152+
// Lua API: Function
153+
// Table: data
154+
// Name: add_granny_file
155+
// Param: filename: string: The GPK filename (e.g. "Melinoe.gpk").
156+
// Param: full_path: string: The full filesystem path to the GPK file.
157+
// Registers a custom GPK file for file-redirection at runtime, allowing
158+
// hot-loading of GPK assets that were not present during initial scan.
159+
//
160+
// **Example Usage:**
161+
// ```lua
162+
// rom.data.add_granny_file("Melinoe.gpk", "C:/path/to/plugins_data/CG3HBuilder/Melinoe.gpk")
163+
// ```
164+
static void add_granny_file(const std::string& filename, const std::string& full_path)
165+
{
166+
additional_granny_files[filename] = full_path;
167+
LOG(INFO) << "Adding to granny files (runtime): " << full_path;
168+
}
169+
170+
// Lua API: Function
171+
// Table: data
172+
// Name: add_package_file
173+
// Param: filename: string: The PKG or PKG_MANIFEST filename.
174+
// Param: full_path: string: The full filesystem path to the file.
175+
// Registers a custom PKG/PKG_MANIFEST file for file-redirection at runtime.
176+
//
177+
// **Example Usage:**
178+
// ```lua
179+
// rom.data.add_package_file("MyMod.pkg", "C:/path/to/plugins_data/MyMod/MyMod.pkg")
180+
// ```
181+
static void add_package_file(const std::string& filename, const std::string& full_path)
182+
{
183+
additional_package_files[filename] = full_path;
184+
LOG(INFO) << "Adding to package files (runtime): " << full_path;
185+
}
186+
148187
static std::unordered_map<void*, std::filesystem::path> g_sjson_FileStream_to_filepath;
149188
static constexpr size_t g_sjson_size_multiplier_for_patches = 8;
150189

@@ -444,6 +483,8 @@ namespace lua::hades::data
444483

445484
ns.set_function("load_package_overrides_get", load_package_overrides_get);
446485
ns.set_function("load_package_overrides_set", load_package_overrides_set);
486+
ns.set_function("add_granny_file", add_granny_file);
487+
ns.set_function("add_package_file", add_package_file);
447488

448489
state["sol.__h2m_LoadPackages__"] = state["LoadPackages"];
449490
// Lua API: Function

0 commit comments

Comments
 (0)