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).
This commit is contained in:
ragnarok-clanker 2026-10-29 23:51:37 +00:00
commit fda2d77ac9
2 changed files with 26 additions and 0 deletions

View file

@ -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 <cstdio>
#include <io.h>
#include <regex>
#include <string>
// 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<const char*>(file.GetData()), file.GetSize(), resolved.c_str()) == 0;
file.Close();
return loaded;
}