#pragma once

// -----------------------------------------------------------------------------
// schema.h
// -----------------------------------------------------------------------------
// Schema system access for the current CS2 process. Two jobs:
//
//   1. ReadBuildInfo()     - reads revision + build datetime from the
//                            EngineBuildInfo global (engine2.dll), which
//                            identifies the running game build (menu).
//   2. DumpSchemaOffsets() - walks the in-game schema system (the same
//                            structures valthrun uses) and extracts every
//                            field offset of the client.dll scope. This is
//                            the primary offset source: no remote data and
//                            no per-build hardcoding.
//
// The layout constants below mirror valthrun's cs2/src/schema/schema.rs and
// are the only "hardcoded" part; Valve changes them rarely.
// -----------------------------------------------------------------------------

#include <cstdint>
#include <string>
#include <vector>

#include "memory.h"

namespace core {

// One schema field: module (scope) + class + member with its byte offset.
struct SchemaOffsetEntry
{
	std::string module;     // "client.dll" or "!GlobalTypes"
	std::string className;  // e.g. "C_BaseEntity"
	std::string member;     // e.g. "m_iHealth"
	uint64_t value = 0;     // byte offset within the class
};

// Reads the EngineBuildInfo struct and returns its "date time" string.
// Struct layout: { revision: const char* @0x00, build_date: @0x08,
//                  build_time: @0x10, product_name: @0x20 }; the revision
// only validates the struct (the menu shows the datetime).
// `engineBase` + `buildInfoOffset` must point at the struct start.
bool ReadBuildInfo(const ProcessMemory& memory, uintptr_t engineBase,
	uintptr_t buildInfoOffset, std::string& outDatetime);

// Walks the schema system (absolute address of the CSchemaSystem instance)
// and collects every field offset of the "client.dll" and "!GlobalTypes"
// scopes. Returns false when the structures cannot be read.
bool DumpSchemaOffsets(const ProcessMemory& memory, uintptr_t schemaSystemAddress,
	std::vector<SchemaOffsetEntry>& outOffsets);

} // namespace core
