Skip to main content
The BinaryKV3 class represents a binary KeyValues3 data block.

Properties

Data
KVObject
Gets the deserialized KeyValues3 data.
Encoding
KV3ID?
Gets the encoding identifier for this KV3 data.
Format
KV3ID
Gets the format identifier for this KV3 data.

Methods

GetKV3File

Gets the KeyValues3 data as a KV3File object.
returns
KV3File
A KV3File object containing the data and format.

IsBinaryKV3 (static)

Checks if the given magic number represents a binary KV3 format.
magic
uint
The magic number to check.
returns
bool
True if the magic number is a valid binary KV3 format.

ConvertBinaryKV3ToText (static)

Converts binary KV3 data to text format. This method is exposed for unmanaged callers.
dataPtr
IntPtr
Pointer to the binary KV3 data.
dataLength
int
Length of the binary data.
returns
IntPtr
Pointer to the text representation of the KV3 data.

Constants

MAGIC0
int
Magic number for VKV3 format.
MAGIC1
int
Magic number for KV3 version 1.
MAGIC2
int
Magic number for KV3 version 2.
MAGIC3
int
Magic number for KV3 version 3.
MAGIC4
int
Magic number for KV3 version 4.
MAGIC5
int
Magic number for KV3 version 5.

Usage Example

var resource = new Resource();
var binaryKV3 = resource.DataBlock as BinaryKV3;

if (binaryKV3 != null)
{
    Console.WriteLine($"Format: {binaryKV3.Format}");
    Console.WriteLine($"Encoding: {binaryKV3.Encoding}");
    
    // Access the data
    var data = binaryKV3.Data;
    Console.WriteLine($"Root properties: {data.Properties.Count}");
    
    // Iterate through properties
    foreach (var property in data.Properties)
    {
        Console.WriteLine($"{property.Key}: {property.Value}");
    }
    
    // Get specific properties
    if (data.ContainsKey("m_name"))
    {
        var name = data.GetProperty<string>("m_name");
        Console.WriteLine($"Name: {name}");
    }
    
    // Get arrays
    var arrayData = data.GetArray("m_someArray");
    foreach (var item in arrayData)
    {
        Console.WriteLine($"Array item: {item}");
    }
    
    // Convert to KV3File for text output
    var kv3File = binaryKV3.GetKV3File();
    using var writer = new StringWriter();
    kv3File.WriteText(new IndentedTextWriter(writer));
    Console.WriteLine(writer.ToString());
}

// Check if data is binary KV3
using var stream = File.OpenRead("data.vdata_c");
using var reader = new BinaryReader(stream);
var magic = reader.ReadUInt32();
if (BinaryKV3.IsBinaryKV3(magic))
{
    Console.WriteLine("This is a binary KV3 file");
}

Build docs developers (and LLMs) love