Skip to content

Commit

Permalink
ChaosMod/LuaScripts: Properly block most exposables during script eval
Browse files Browse the repository at this point in the history
  • Loading branch information
pongo1231 committed Jan 30, 2025
1 parent 0322a5e commit 53b281c
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions ChaosMod/Components/LuaScripts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ struct ExposableFunc
ExposeFunc(state);
}
};
static const std::vector<ExposableFunc> ms_Exposables {
static const std::vector<ExposableFunc> ms_SafeExposables {
E("GetTickCount", GetTickCount64),
E("GET_HASH_KEY", GET_HASH_KEY),
E("print", [](const sol::this_environment &curEnv, const std::string &text)
Expand All @@ -313,6 +313,11 @@ static const std::vector<ExposableFunc> ms_Exposables {

return false;
}),
E("GetChaosModVersion", []() { return MOD_VERSION; }),
E("GetGameBuild", Memory::GetGameBuild),
};
static const std::vector<ExposableFunc> ms_UnsafeExposables {
E("WAIT", WAIT),
E("APPLY_FORCE_TO_ENTITY", APPLY_FORCE_TO_ENTITY),
E("APPLY_FORCE_TO_ENTITY_CENTER_OF_MASS", APPLY_FORCE_TO_ENTITY_CENTER_OF_MASS),
E("LoadModel", LoadModel),
Expand Down Expand Up @@ -360,8 +365,6 @@ static const std::vector<ExposableFunc> ms_Exposables {
return LuaVector3(result.x, result.y, result.z);
}),
E("IsWeaponShotgun", Util::IsWeaponShotgun),
E("GetChaosModVersion", []() { return MOD_VERSION; }),
E("GetGameBuild", Memory::GetGameBuild),
E("AddCustomLabel", Hooks::AddCustomLabel),
E("DisplayHelpText", DisplayHelpText),
E("GetRandomInt",
Expand Down Expand Up @@ -467,7 +470,9 @@ LuaScripts::LuaScripts()
{
return LuaInvoke(curEnv, hash, returnType, args);
};
m_GlobalState["WAIT"] = WAIT;

for (const auto &exposable : ms_UnsafeExposables)
exposable(m_GlobalState);
}
else
{
Expand All @@ -477,10 +482,12 @@ LuaScripts::LuaScripts()
LOG("WARNING: Blocked invocation of native 0x" << std::uppercase << std::hex << hash << std::setfill(' ')
<< " during script evaluation!");
};
m_GlobalState["WAIT"] = []()
{
LOG("WARNING: Blocked invocation of WAIT during script evaluation!");
};

for (const auto &exposable : ms_UnsafeExposables)
m_GlobalState[exposable.Name] = [&]()
{
LOG("WARNING: Blocked invocation of mod function " << exposable.Name << " during script evaluation!");
};
}

for (auto dir : ms_ScriptDirs)
Expand Down Expand Up @@ -512,7 +519,9 @@ LuaScripts::LuaScripts()
{
return LuaInvoke(curEnv, hash, returnType, args);
};
m_GlobalState["WAIT"] = WAIT;

for (const auto &exposable : ms_UnsafeExposables)
exposable(m_GlobalState);
}
}

Expand Down Expand Up @@ -603,7 +612,7 @@ void LuaScripts::SetupGlobalState()
m_GlobalState.new_enum("EOverrideShaderType", "LensDistortion", OverrideShaderType::LensDistortion, "Snow",
OverrideShaderType::Snow);

for (const auto &exposable : ms_Exposables)
for (const auto &exposable : ms_SafeExposables)
exposable(m_GlobalState);
}

Expand Down

0 comments on commit 53b281c

Please sign in to comment.