Skip to content

Commit

Permalink
fix: papyrus misc (#272)
Browse files Browse the repository at this point in the history
  • Loading branch information
qudix authored Sep 20, 2024
1 parent c9d6e22 commit 565f629
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 23 deletions.
4 changes: 1 addition & 3 deletions include/RE/B/BSScriptUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -782,12 +782,10 @@ namespace RE::BSScript
return T();
}

using value_type = typename T::value_type;

T out;
const auto in = get<Array>(a_var);
for (const auto& var : in->elements) {
out.push_back(detail::UnpackVariable<value_type>(var));
out.push_back(detail::UnpackVariable<typename T::value_type>(var));
}

return out;
Expand Down
21 changes: 19 additions & 2 deletions include/RE/T/TypeInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,37 +76,54 @@ namespace RE::BSScript
}
}

[[nodiscard]] bool IsComplex() const noexcept { return data.rawType >= RawType::kArrayEnd; }
[[nodiscard]] bool IsComplex() const noexcept
{
// do not use GetRawType() here, may cause infinite recursion
return data.rawType >= RawType::kArrayEnd;
}

[[nodiscard]] bool IsObjectArray() const noexcept
{
return GetRawType() == RawType::kArrayObject;
}

[[nodiscard]] bool IsStructArray() const noexcept
{
return GetRawType() == RawType::kArrayStruct;
}

[[nodiscard]] bool IsComplexTypeArray() const noexcept
{
return (IsComplex() && IsArray());
}

[[nodiscard]] bool IsNone() const { return GetRawType() == RawType::kNone; }
[[nodiscard]] bool IsObject() const { return GetRawType() == RawType::kObject; }
[[nodiscard]] bool IsString() const { return GetRawType() == RawType::kString; }
[[nodiscard]] bool IsInt() const { return GetRawType() == RawType::kInt; }
[[nodiscard]] bool IsFloat() const { return GetRawType() == RawType::kFloat; }
[[nodiscard]] bool IsBool() const { return GetRawType() == RawType::kBool; }
[[nodiscard]] bool IsVar() const { return GetRawType() == RawType::kVar; }
[[nodiscard]] bool IsStruct() const { return GetRawType() == RawType::kStruct; }
IComplexType* GetComplexType() const

IComplexType* GetComplexType() const
{
return IsComplex() ? reinterpret_cast<IComplexType*>(
reinterpret_cast<std::uintptr_t>(data.complexTypeInfo) &
~static_cast<std::uintptr_t>(1)) :
nullptr;
}

ObjectTypeInfo* GetObjectTypeInfo() const
{
return IsObject() || IsObjectArray() ? reinterpret_cast<ObjectTypeInfo*>(GetComplexType()) : nullptr;
}

StructTypeInfo* GetStructTypeInfo() const
{
return IsStruct() || IsStructArray() ? reinterpret_cast<StructTypeInfo*>(GetComplexType()) : nullptr;
}

void SetArray(bool a_set) noexcept
{
if (IsComplex()) {
Expand Down
36 changes: 18 additions & 18 deletions include/RE/V/Variable.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,67 +119,67 @@ namespace RE::BSScript
SF_HEAP_REDEFINE_NEW(Variable);

template <class T>
[[nodiscard]] bool is() const //
[[nodiscard]] bool is() const
requires(std::same_as<T, std::nullptr_t>)
{
return varType.GetRawType() == RawType::kNone;
return varType.IsNone();
}

template <class T>
[[nodiscard]] bool is() const //
[[nodiscard]] bool is() const
requires(std::same_as<T, Object>)
{
return varType.GetRawType() == RawType::kObject;
return varType.IsObject();
}

template <class T>
[[nodiscard]] bool is() const //
[[nodiscard]] bool is() const
requires(std::same_as<T, BSFixedString>)
{
return varType.GetRawType() == RawType::kString;
return varType.IsString();
}

template <class T>
[[nodiscard]] bool is() const //
[[nodiscard]] bool is() const
requires(std::same_as<T, std::uint32_t> ||
std::same_as<T, std::int32_t>)
{
return varType.GetRawType() == RawType::kInt;
return varType.IsInt();
}

template <class T>
[[nodiscard]] bool is() const //
[[nodiscard]] bool is() const
requires(std::same_as<T, float>)
{
return varType.GetRawType() == RawType::kFloat;
return varType.IsFloat();
}

template <class T>
[[nodiscard]] bool is() const //
[[nodiscard]] bool is() const
requires(std::same_as<T, bool>)
{
return varType.GetRawType() == RawType::kBool;
return varType.IsBool();
}

template <class T>
[[nodiscard]] bool is() const //
[[nodiscard]] bool is() const
requires(std::same_as<T, Variable>)
{
return varType.GetRawType() == RawType::kVar;
return varType.IsVar();
}

template <class T>
[[nodiscard]] bool is() const //
[[nodiscard]] bool is() const
requires(std::same_as<T, Struct>)
{
return varType.GetRawType() == RawType::kStruct;
return varType.IsStruct() && value.t;
}

template <class T>
[[nodiscard]] bool is() const //
[[nodiscard]] bool is() const
requires(std::same_as<T, Array>)
{
return varType.IsArray();
return varType.IsArray() && value.a;
}

TypeInfo GetType() const
Expand Down

0 comments on commit 565f629

Please sign in to comment.