Skip to content

Commit

Permalink
only add when runtime var can be created
Browse files Browse the repository at this point in the history
  • Loading branch information
jackhumbert committed Jun 23, 2023
1 parent cd191ea commit 9643848
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/red4ext/ModSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,17 @@ void __fastcall ModSettings::ProcessScriptData(ScriptData *scriptData) {
}
auto &category = modClass.categories[categoryName];

category.variables[prop->name] = {
ModVariable variable = {
.name = prop->name,
.type = CRTTISystem::Get()->GetType(prop->type->name),
.configVarType = CRTTISystem::Get()->GetClass(ToConfigVar(prop->type->name)),
.dependency = *prop->ReadDependency(scriptClass->name),
.category = &category,
.implicitOrder = (uint32_t)category.variables.size()
};
auto &variable = category.variables[prop->name];

if (variable.SetRuntimeVariable(prop)) {
category.variables[prop->name] = variable;
modClass.UpdateDefault(variable.name, variable.runtimeVar->GetValuePtr());
sdk->logger->InfoF(pluginHandle, "Loaded %s.%s", modClass.name.ToString(), variable.name.ToString());
} else {
Expand Down Expand Up @@ -121,17 +121,17 @@ void __fastcall ModSettings::ProcessScriptData(ScriptData *scriptData) {
auto &category = modClass.categories[categoryName];

auto variableName = CNamePool::Add(var->propertyName);
category.variables[variableName] = {
ModVariable variable = {
.name = variableName,
.type = CRTTISystem::Get()->GetType(var->type),
.configVarType = CRTTISystem::Get()->GetClass(ToConfigVar(var->type)),
.dependency = var->dependency,
.category = &category,
.implicitOrder = (uint32_t)category.variables.size()
};
auto &variable = category.variables[variableName];

if (variable.CreateRuntimeVariable(*var)) {
category.variables[variableName] = variable;
modClass.RegisterCallback(var->callback);
(*var->callback)(var->categoryName, var->propertyName, *(ModVariableType*)variable.runtimeVar->GetValuePtr());
sdk->logger->InfoF(pluginHandle, "Loaded '%s'.%s", var->modName, var->propertyName);
Expand Down
2 changes: 1 addition & 1 deletion src/red4ext/Variable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const CName ToConfigVar(CName typeName) noexcept;

struct ModVariable {
uint32_t GetOrder() const {
return (runtimeVar && runtimeVar->order != (uint32_t)-1) ? runtimeVar->order : implicitOrder;
return runtimeVar->order != (uint32_t)-1 ? runtimeVar->order : implicitOrder;
}

bool operator< (const ModVariable &other) const {
Expand Down

0 comments on commit 9643848

Please sign in to comment.