Skip to content

Add engineIsModelValid #4255

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

sousateew
Copy link

This PR adds a new utility function engineIsModelValid.

Some scripts may need to check whether a model ID corresponds to a valid and loaded model. This function provides a simple way to verify if a model is within valid bounds and has a valid model info entry.
It checks whether the model ID is above the base DFF limit and ensures that the corresponding model info exists and is valid.

bool engineIsModelValid(number modelID)

@PlatinMTA
Copy link
Contributor

PlatinMTA commented Jul 5, 2025

What about CJ models (do we even need to do a check if GetCountOfAllFileIDs is used in GetModelInfo anyways)? Related #4282 somewhat

Also I'm not that good with C but wouldn't it make more sense to first check if the ID is larger than 20k and then try to get the model info?

Anyways I could use this function yes, maybe for a hard clean of all models or something similar.

@@ -2593,3 +2594,13 @@ void CLuaEngineDefs::EnginePreloadWorldArea(CVector position, std::optional<Prel
if (option == PreloadAreaOption::ALL || option == PreloadAreaOption::COLLISIONS)
g_pGame->GetStreaming()->LoadSceneCollision(&position);
}

bool CLuaEngineDefs::EngineIsModelValid(uint uiModelId)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uint -> std::uint32_t


bool CLuaEngineDefs::EngineIsModelValid(uint uiModelId)
{
CModelInfo* pModelInfo = g_pGame->GetModelInfo(uiModelId);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CModelInfo* modelInfo = g_pGame->GetModelInfo(modelId);

Comment on lines +2602 to +2605
if (uiModelId >= 20000 || !pModelInfo)
return false;

return true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return (modelId < 20000 && modelInfo);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants