-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add requirements for script validation
- Loading branch information
Showing
4 changed files
with
124 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
#pragma once | ||
|
||
#ifdef RED4EXT_STATIC_LIB | ||
#include <RED4ext/Scripting/ScriptReport.hpp> | ||
#endif | ||
|
||
#include <RED4ext/RTTITypes.hpp> | ||
|
||
RED4EXT_INLINE RED4ext::ScriptReport::ScriptReport() noexcept | ||
: errors(&unk10) | ||
, maxErrors(0) | ||
, fillErrors(true) | ||
{ | ||
} | ||
|
||
RED4EXT_INLINE RED4ext::ScriptReport::ScriptReport(RED4ext::DynArray<RED4ext::CString>& aErrors, uint32_t aMaxErrors) noexcept | ||
: errors(&aErrors) | ||
, maxErrors(aMaxErrors) | ||
, fillErrors(true) | ||
{ | ||
} | ||
|
||
RED4EXT_INLINE void RED4ext::ScriptReport::AddValidationError(const char* aFormat, ...) | ||
{ | ||
if (errors && fillErrors) | ||
{ | ||
std::va_list args; | ||
va_start(args, aFormat); | ||
errors->PushBack(Format(aFormat, args)); | ||
va_end(args); | ||
} | ||
} | ||
|
||
RED4EXT_INLINE void RED4ext::ScriptReport::AddBindingError(const char* aFormat, ...) | ||
{ | ||
if (errors && fillErrors) | ||
{ | ||
std::va_list args; | ||
va_start(args, aFormat); | ||
errors->PushBack(Format(aFormat, args)); | ||
va_end(args); | ||
} | ||
} | ||
|
||
RED4EXT_INLINE [[nodiscard]] bool RED4ext::ScriptReport::HasErrors() const noexcept | ||
{ | ||
return errors && errors->size > 0; | ||
} | ||
|
||
RED4EXT_INLINE [[nodiscard]] RED4ext::CString RED4ext::ScriptReport::ToString() const noexcept | ||
{ | ||
if (!errors || errors->size == 0) | ||
{ | ||
return {}; | ||
} | ||
|
||
std::string str; | ||
bool eol = false; | ||
|
||
for (const auto& error : *errors) | ||
{ | ||
if (eol) | ||
{ | ||
str.append("\n"); | ||
} | ||
|
||
str.append(error.c_str()); | ||
eol = true; | ||
} | ||
|
||
return str.c_str(); | ||
} | ||
|
||
RED4EXT_INLINE RED4ext::CString RED4ext::ScriptReport::Format(const char* aFormat, std::va_list aArgs) | ||
{ | ||
char buffer[4096]; | ||
vsnprintf(buffer, sizeof(buffer), aFormat, aArgs); | ||
return buffer; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#pragma once | ||
|
||
#include <RED4ext/CString.hpp> | ||
#include <RED4ext/DynArray.hpp> | ||
#include <cstdarg> | ||
|
||
namespace RED4ext | ||
{ | ||
struct ScriptReport | ||
{ | ||
ScriptReport() noexcept; | ||
|
||
ScriptReport(DynArray<CString>& aErrors, uint32_t aMaxErrors = 0) noexcept; | ||
|
||
virtual ~ScriptReport() = default; | ||
|
||
virtual void AddValidationError(const char* aFormat, ...); | ||
|
||
virtual void AddBindingError(const char* aFormat, ...); | ||
|
||
[[nodiscard]] bool HasErrors() const noexcept; | ||
|
||
[[nodiscard]] CString ToString() const noexcept; | ||
|
||
static CString Format(const char* aFormat, std::va_list aArgs); | ||
|
||
bool fillErrors; // 08 - Usually equals to CBaseEngine::scriptsSilentValidation | ||
DynArray<CString> unk10; // 10 - Seems to be unused by the game | ||
DynArray<CString>* errors; // 20 - Usually points to CBaseEngine::scriptsValidationErrors | ||
uint32_t maxErrors; // 28 | ||
}; | ||
RED4EXT_ASSERT_SIZE(ScriptReport, 0x30); | ||
RED4EXT_ASSERT_OFFSET(ScriptReport, fillErrors, 0x08); | ||
RED4EXT_ASSERT_OFFSET(ScriptReport, errors, 0x20); | ||
RED4EXT_ASSERT_OFFSET(ScriptReport, maxErrors, 0x28); | ||
} // namespace RED4ext |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#ifndef RED4EXT_STATIC_LIB | ||
#error Please define 'RED4EXT_STATIC_LIB' to compile this file. | ||
#endif | ||
|
||
#include <RED4ext/Scripting/ScriptReport-inl.hpp> |