Skip to content

Commit

Permalink
fix fromstring reading
Browse files Browse the repository at this point in the history
  • Loading branch information
jackhumbert committed Oct 10, 2023
1 parent 7d1850a commit 5f28977
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 18 deletions.
2 changes: 1 addition & 1 deletion deps/red4ext.sdk
9 changes: 9 additions & 0 deletions src/red4ext/RuntimeVariable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,15 @@ template <> inline RuntimeVariableRange<float>::RuntimeVariableRange(ScriptPrope
prop->ReadProperty("ModSettings.max", &this->maxValue, 1.0f);
}

template <> inline RuntimeVariableRange<float>::RuntimeVariableRange(CName className, CName propertyName, CName displayName, CName description, uint32_t order,
float defaultValue, float stepValue, float minValue, float maxValue)
: RuntimeVariable<float>(className, propertyName, displayName, description, order, defaultValue) {
this->type = RED4ext::user::EConfigVarType::Float;
this->stepValue = stepValue;
this->minValue = minValue;
this->maxValue = maxValue;
}

template <> inline void __fastcall RuntimeVariable<bool>::GetValueToWrite(char *value) {
sprintf(value, "%d", valueValidated);
}
Expand Down
30 changes: 24 additions & 6 deletions src/red4ext/ScriptDefinitions/ScriptProperty.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ struct ScriptProperty : ScriptDefinition {
}

void FromString(RED4ext::ScriptInstance pointer, const RED4ext::CString& str) const {
this->GetType()->FromString(pointer, str.c_str());
RED4ext::RawBuffer buffer;
buffer.data = (void*)str.c_str();
buffer.size = str.Length();
this->GetType()->FromString(pointer, buffer);
}

// ReadProperty(CName)
Expand All @@ -68,7 +71,10 @@ struct ScriptProperty : ScriptDefinition {
auto str = this->runtimeProperties.Get(name);
if (str) {
uint32_t value;
RED4ext::CRTTISystem::Get()->GetType("Uint32")->FromString(&value, *str);
RED4ext::RawBuffer buffer;
buffer.data = (void*)str->c_str();
buffer.size = str->length;
RED4ext::CRTTISystem::Get()->GetType("Uint32")->FromString(&value, buffer);
return value;
} else {
return 0;
Expand All @@ -79,7 +85,10 @@ struct ScriptProperty : ScriptDefinition {
auto str = this->runtimeProperties.Get(name);
if (str) {
int32_t value;
RED4ext::CRTTISystem::Get()->GetType("Int32")->FromString(&value, *str);
RED4ext::RawBuffer buffer;
buffer.data = (void*)str->c_str();
buffer.size = str->length;
RED4ext::CRTTISystem::Get()->GetType("Int32")->FromString(&value, buffer);
return value;
} else {
return 0;
Expand Down Expand Up @@ -133,21 +142,30 @@ struct ScriptProperty : ScriptDefinition {
template <> void ReadProperty<uint32_t>(const RED4ext::CName &name, uint32_t *pointer) const {
auto str = this->runtimeProperties.Get(name);
if (str && pointer) {
RED4ext::CRTTISystem::Get()->GetType("Uint32")->FromString(pointer, *str);
RED4ext::RawBuffer buffer;
buffer.data = (void*)str->c_str();
buffer.size = str->length;
RED4ext::CRTTISystem::Get()->GetType("Uint32")->FromString(pointer, buffer);
}
}

template <> void ReadProperty<int32_t>(const RED4ext::CName &name, int32_t *pointer) const {
auto str = this->runtimeProperties.Get(name);
if (str && pointer) {
RED4ext::CRTTISystem::Get()->GetType("Int32")->FromString(pointer, *str);
RED4ext::RawBuffer buffer;
buffer.data = (void*)str->c_str();
buffer.size = str->length;
RED4ext::CRTTISystem::Get()->GetType("Int32")->FromString(pointer, buffer);
}
}

template <> void ReadProperty<float>(const RED4ext::CName &name, float *pointer) const {
auto str = this->runtimeProperties.Get(name);
if (str && pointer) {
RED4ext::CRTTISystem::Get()->GetType("Float")->FromString(pointer, *str);
RED4ext::RawBuffer buffer;
buffer.data = (void*)str->c_str();
buffer.size = str->length;
RED4ext::CRTTISystem::Get()->GetType("Float")->FromString(pointer, buffer);
}
}

Expand Down
55 changes: 44 additions & 11 deletions src/red4ext/Utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,47 +17,80 @@ static void RedTypeFromString(T * pointer, const RED4ext::CString& str) {
}

template<> void RedTypeFromString<bool>(bool * pointer, const RED4ext::CString& str) {
RTTITYPE(Bool)->FromString(pointer, str);
RED4ext::RawBuffer buffer;
buffer.data = (void*)str.c_str();
buffer.size = str.length;
RTTITYPE(Bool)->FromString(pointer, buffer);
}

template<> void RedTypeFromString<int8_t>(int8_t * pointer, const RED4ext::CString& str) {
RTTITYPE(Int8)->FromString(pointer, str);
RED4ext::RawBuffer buffer;
buffer.data = (void*)str.c_str();
buffer.size = str.length;
RTTITYPE(Int8)->FromString(pointer, buffer);
}

template<> void RedTypeFromString<int16_t>(int16_t * pointer, const RED4ext::CString& str) {
RTTITYPE(Int16)->FromString(pointer, str);
RED4ext::RawBuffer buffer;
buffer.data = (void*)str.c_str();
buffer.size = str.length;
RTTITYPE(Int16)->FromString(pointer, buffer);
}

template<> void RedTypeFromString<int32_t>(int32_t * pointer, const RED4ext::CString& str) {
RTTITYPE(Int32)->FromString(pointer, str);
RED4ext::RawBuffer buffer;
buffer.data = (void*)str.c_str();
buffer.size = str.length;
RTTITYPE(Int32)->FromString(pointer, buffer);
}

template<> void RedTypeFromString<int64_t>(int64_t * pointer, const RED4ext::CString& str) {
RTTITYPE(Int64)->FromString(pointer, str);
RED4ext::RawBuffer buffer;
buffer.data = (void*)str.c_str();
buffer.size = str.length;
RTTITYPE(Int64)->FromString(pointer, buffer);
}

template<> void RedTypeFromString<uint8_t>(uint8_t * pointer, const RED4ext::CString& str) {
RTTITYPE(Uint8)->FromString(pointer, str);
RED4ext::RawBuffer buffer;
buffer.data = (void*)str.c_str();
buffer.size = str.length;
RTTITYPE(Uint8)->FromString(pointer, buffer);
}

template<> void RedTypeFromString<uint16_t>(uint16_t * pointer, const RED4ext::CString& str) {
RTTITYPE(Uint16)->FromString(pointer, str);
RED4ext::RawBuffer buffer;
buffer.data = (void*)str.c_str();
buffer.size = str.length;
RTTITYPE(Uint16)->FromString(pointer, buffer);
}

template<> void RedTypeFromString<uint32_t>(uint32_t * pointer, const RED4ext::CString& str) {
RTTITYPE(Uint32)->FromString(pointer, str);
RED4ext::RawBuffer buffer;
buffer.data = (void*)str.c_str();
buffer.size = str.length;
RTTITYPE(Uint32)->FromString(pointer, buffer);
}

template<> void RedTypeFromString<uint64_t>(uint64_t * pointer, const RED4ext::CString& str) {
RTTITYPE(Uint64)->FromString(pointer, str);
RED4ext::RawBuffer buffer;
buffer.data = (void*)str.c_str();
buffer.size = str.length;
RTTITYPE(Uint64)->FromString(pointer, buffer);
}

template<> void RedTypeFromString<float>(float * pointer, const RED4ext::CString& str) {
RTTITYPE(Float)->FromString(pointer, str);
RED4ext::RawBuffer buffer;
buffer.data = (void*)str.c_str();
buffer.size = str.length;
RTTITYPE(Float)->FromString(pointer, buffer);
}

template<> void RedTypeFromString<double>(double * pointer, const RED4ext::CString& str) {
RTTITYPE(Double)->FromString(pointer, str);
RED4ext::RawBuffer buffer;
buffer.data = (void*)str.c_str();
buffer.size = str.length;
RTTITYPE(Double)->FromString(pointer, buffer);
}

template<> void RedTypeFromString<RED4ext::CName>(RED4ext::CName * pointer, const RED4ext::CString& str) {
Expand Down

0 comments on commit 5f28977

Please sign in to comment.