From fda2d77ac924bec4ede9be57af107f8f56b36a4e Mon Sep 17 00:00:00 2001 From: ragnarok-clanker Date: Thu, 29 Oct 2026 23:51:37 +0000 Subject: [PATCH] Decompile fn_18254 (LoadLuaResource) Batch #3857 by ragnarok-clanker: 0 byte-identical, 1 confirmed by peer review. - fn_18254 LoadLuaResource: logic confirmed by peer review Peer-reviewed-by: Yommy, youko Accepted without human review: peers confirmed the logic ("same" ahead by at least 3, with 70% of the votes). --- Source/Script/LuaFileOperations.cpp | 23 +++++++++++++++++++++++ Source/Script/LuaFileOperations.h | 3 +++ 2 files changed, 26 insertions(+) diff --git a/Source/Script/LuaFileOperations.cpp b/Source/Script/LuaFileOperations.cpp index e924ffa3..e7320024 100644 --- a/Source/Script/LuaFileOperations.cpp +++ b/Source/Script/LuaFileOperations.cpp @@ -1,4 +1,5 @@ #include "Script/LuaFileOperations.h" +#include "File/File.h" #include "File/FileCreation.h" extern "C" { @@ -7,6 +8,7 @@ extern "C" { #include #include +#include #include // OFFSET: 0x00AFE7D0 @@ -26,3 +28,24 @@ int LuaChangeDirectoryOfDatas(lua_State* state) { return 0; } + +// OFFSET: 0x00AF6580 +// FUNCTION: fn_18254 +bool LoadLuaResource(lua_State* state, const std::string& name, unsigned char allowLuaFallback) { + std::string resolved = name; + CFile file; + if (!file.Open(name.c_str(), 0, false, false)) { + if (allowLuaFallback != 1) { + return false; + } + + resolved = std::regex_replace(name, std::regex("\\.lub$"), ".lua"); + if (!file.Open(resolved.c_str(), 0, false, false)) { + return false; + } + } + + const bool loaded = luaL_loadbuffer(state, static_cast(file.GetData()), file.GetSize(), resolved.c_str()) == 0; + file.Close(); + return loaded; +} diff --git a/Source/Script/LuaFileOperations.h b/Source/Script/LuaFileOperations.h index 4bf669c5..d5cfe7d0 100644 --- a/Source/Script/LuaFileOperations.h +++ b/Source/Script/LuaFileOperations.h @@ -1,8 +1,11 @@ #ifndef RAGNAROK_SOURCE_SCRIPT_LUAFILEOPERATIONS_H #define RAGNAROK_SOURCE_SCRIPT_LUAFILEOPERATIONS_H +#include + struct lua_State; int LuaChangeDirectoryOfDatas(lua_State* state); +bool LoadLuaResource(lua_State* state, const std::string& name, unsigned char allowLuaFallback); #endif