Skip to content
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

Spring.GetCEGID("nonexistent ceg") allocates a new ID #1779

Open
sprunk opened this issue Nov 20, 2024 · 1 comment
Open

Spring.GetCEGID("nonexistent ceg") allocates a new ID #1779

sprunk opened this issue Nov 20, 2024 · 1 comment
Labels
good first issue Good for newcomers

Comments

@sprunk
Copy link
Collaborator

sprunk commented Nov 20, 2024

  • it never returns invalid for nonexistent CEG names, instead it allocates a new ID for them and then returns that ID consistently for given name. So there is no way to check if given CEG actually exists or not.
  • not a realistic scenario but by allocating variable numbers of garbage CEGs you can get a desync if synced luarules ever asks about a nonexistent ceg and uses the returned ID.
@sprunk sprunk added the good first issue Good for newcomers label Nov 20, 2024
@sprunk
Copy link
Collaborator Author

sprunk commented Nov 20, 2024

It should be a matter of splitting the "find generator" part away from CExplosionGeneratorHandler::LoadGenerator and using that in Spring.GetCEGID instead of the full function that allocates a new one if missing:

{
decltype(expGenIdentNameMap)::mapped_type key = {{0}};
char* ptr = key.data();
char* sep = nullptr;
ptr += snprintf(ptr, sizeof(key) - (ptr - key.data()), "%s", pre);
ptr += snprintf(ptr, sizeof(key) - (ptr - key.data()), "%s", tag);
const auto hash = hashString(key.data());
const auto iter = expGenHashIdentMap.find(hash);
if (iter != expGenHashIdentMap.end())
return explosionGenerators[iter->second];

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

No branches or pull requests

1 participant