12#include <entity2/entityclass.h>
13#include <entity2/entitysystem.h>
17#include <gameentitysystem.h>
18#include <interfaces/interfaces.h>
19#include <schemasystem/schemasystem.h>
28static constexpr std::string_view
DumpPath =
"addons/voltmod/gamedata/dumps/schema.json";
31static std::string
DumpedBuild(
const std::filesystem::path& path)
33 std::ifstream file(path, std::ios::binary);
39 std::string head(256,
'\0');
40 file.read(head.data(),
static_cast<std::streamsize
>(head.size()));
41 head.resize(
static_cast<size_t>(file.gcount()));
43 constexpr std::string_view key =
"\"build\":";
44 const size_t at = head.find(key);
45 if (at == std::string::npos)
50 const size_t open = head.find(
'"', at + key.size());
51 const size_t close = open == std::string::npos ? std::string::npos : head.find(
'"', open + 1);
52 return close == std::string::npos ? std::string() : head.substr(open + 1, close - open - 1);
55static CSchemaSystemTypeScope*
ServerScope(ISchemaSystem* schema)
57 if (!schema || !schema->SchemaSystemIsReady())
62 return schema->FindTypeScopeForModule(moduleName.c_str());
67 static bool attempted =
false;
68 if (attempted || !entities)
73 CSchemaSystemTypeScope* server =
ServerScope(schema);
81 const CEntityClass* entityClass = entities->FindClassByName(
"CBaseEntity");
82 const CNetworkSerializerClassInfo* serializer = entityClass ? entityClass->m_NetworkSerializerInfo :
nullptr;
83 if (!serializer || !serializer->m_pDatabase)
93 Log::Warn(
"Schema: no dump written to {}: {}", output.string(), written.error().Detail);
101 CSchemaSystemTypeScope* server =
ServerScope(schema);
107 const std::string name(className);
108 CSchemaClassInfo* live = server->FindDeclaredClass(name.c_str()).Get();
109 if (CSchemaSystemTypeScope* global = schema->GlobalTypeScope(); !live && global)
111 live = global->FindDeclaredClass(name.c_str()).Get();
114 const SchemaClassFieldData_t* found = live ?
FindField(live, field) :
nullptr;
121 uint8_t alignment = 0;
122 const bool sized = found->m_pType && found->m_pType->GetSizeAndAlignment(size, alignment);
123 return {.Offset = found->m_nSingleInheritanceOffset, .Size = sized ? size : 0};
133 _registry.SetSchemaFields([schema](std::string_view className, std::string_view field) {
149void SchemaCheck::Check()
154 Log::Error(
"Schema: the server schema scope is not ready");
164 Log::Error(
"Schema: {}", resolved.error().Detail);
The loaded plugins and the engine events raised on them, one per process.
SchemaCheck(PluginRegistry ®istry, ISchemaSystem *schema)
void Error(std::format_string< Args... > fmt, Args &&... args)
void Info(std::format_string< Args... > fmt, Args &&... args)
void Warn(std::format_string< Args... > fmt, Args &&... args)
static CSchemaSystemTypeScope * ServerScope(ISchemaSystem *schema)
const SchemaClassFieldData_t * FindField(const CSchemaClassInfo *klass, std::string_view field)
static std::string DumpedBuild(const std::filesystem::path &path)
LiveField FindLiveField(ISchemaSystem *schema, std::string_view className, std::string_view field)
static constexpr std::string_view DumpPath
Status WriteDumpFile(CSchemaSystemTypeScope *global, CSchemaSystemTypeScope *server, const CNetworkSerializerCodeGenDatabase &network, std::string_view path, std::string_view gameBuild)
Status ResolveLayout(std::span< FieldLayout > fields, const LiveFieldLookup &lookup)
std::span< FieldLayout > GeneratedLayout()
void WriteSchemaDump(ISchemaSystem *schema, CGameEntitySystem *entities)
std::filesystem::path ResolvePath(std::string_view relativePath)
a relative path against the base directory. If the path is already absolute, returns it as-is.
std::expected< void, Error > Status
std::string_view GameBuild()
std::string PlatformModuleName(std::string_view moduleName)