reckfellENGINE

ConfigFile

In-memory sections, keys and typed Variants with explicit file loading and saving.

On this page
class ConfigFileReckfellSharpInherits RefCounted

SetValue changes memory; Save writes a file. Load and Parse merge into an existing instance. For independent loading, use a new ConfigFile, check Error and only then change game state.

Ordinary Save produces text using Variant syntax. Encrypted variants are separate methods; ConfigFile itself does not establish that progress is trustworthy. Comments and original file formatting are not preserved.

GetValue returns a Variant. Values needing cleanup have a finalizer as a fallback; using releases them predictably when leaving scope. The example checks position type and finiteness before returning it to the caller. The ConfigFile must already contain the loaded data.

C#
using Reckfell;

public static class ConfigPositionExample
{
    public static bool TryReadPosition(ConfigFile data, out Vector3 position)
    {
        position = default;
        if (!data.HasSectionKey("player", "position"))
            return false;
        using Variant value = data.GetValue("player", "position");
        if (value.VariantType != Variant.Type.Vector3)
            return false;
        Vector3 candidate = value.AsVector3();
        if (!candidate.IsFinite())
            return false;
        position = candidate;
        return true;
    }
}

For writing with a backup, see saving progress.

Declarations checked against C# SDK 1.0.0. Expand a name to see declarations and documentation.

Constructors1

ConfigFileConstructor
# ConfigFile
C#
public ConfigFile();

Creates an empty in-memory store of sections, keys and Variants. Does not itself open a file or load earlier data.

Methods19

Clearvoid
# Clear
C#
public void Clear();

Removes every section and value from this instance's memory only. Neither deletes a file nor saves the change to disk.

EncodeToTextstring
# EncodeToText
C#
public string EncodeToText();

Creates a text representation of current values without writing a file. Does not preserve comments or original formatting. It is not guaranteed to match Save byte for byte: the current engine writes section a]b here as [a]b], whereas Save escapes the closing bracket. Use Save for files with such section names.

Returns string

Section/value text; an empty string for an empty ConfigFile.

EraseSectionvoid
# EraseSection
C#
public void EraseSection(string section);

Removes the section and all its keys in memory. A missing section reports a native error rather than a guaranteed CLR exception. Check HasSection first when absence is expected. Does not change the disk file.

Parameters
NameTypeDefault
sectionstring—
section

Existing section name.

EraseSectionKeyvoid
# EraseSectionKey
C#
public void EraseSectionKey(string section, string key);

Removes a key from an in-memory section. Removing its last key also removes the section. A missing section or key reports a native error; use HasSectionKey before conditional removal. Persist the change with a separate Save.

Parameters
NameTypeDefault
sectionstring—
keystring—
section

Existing section name.

key

Existing key name.

GetSectionKeysstring[]
# GetSectionKeys
C#
public string[] GetSectionKeys(string section);

Returns key names from an existing section. A missing section reports a native error and returns an empty array. Use HasSection when absence is expected to avoid that error.

Parameters
NameTypeDefault
sectionstring—
section

In-memory section name, not a file path.

Returns string[]

A string[] array of key names.

GetSectionsstring[]
# GetSections
C#
public string[] GetSections();

Returns an array of this instance's section names. It is neither a file listing nor the section values. Do not tie save-format logic to a name's position in the array.

Returns string[]

A string[] array; empty when no sections exist.

GetValueVariant
# GetValue
C#
public Variant GetValue(string section, string key, Variant @default = default);

Returns the specified key value. If the section or key is absent, returns the supplied default. A missing value with a Nil default also produces an engine error; this does not replace explicitly checking whether the key exists.

Parameters
NameTypeDefault
sectionstring—
keystring—
defaultVariantdefault
section

Section name. An empty string identifies values outside a section.

key

Key name within the specified section.

default

Fallback when the section or key is missing. Supply an explicit non-Nil Variant, such as 7 or false, to handle a missing value normally.

Returns Variant

The stored Variant or the supplied default. Its type depends on the stored data; the caller converts it to the required C# type.

HasSectionbool
# HasSection
C#
public bool HasSection(string section);

Checks in-memory section existence without loading a file or reporting a missing-section error. Does not establish that its values have the required types.

Parameters
NameTypeDefault
sectionstring—
section

Section name to check.

Returns bool

true if the section exists; otherwise false.

HasSectionKeybool
# HasSectionKey
C#
public bool HasSectionKey(string section, string key);

Checks whether an in-memory section/key pair exists. A missing section returns false without an error. Check the value type and range separately after GetValue.

Parameters
NameTypeDefault
sectionstring—
keystring—
section

Section name.

key

Key name within the section.

Returns bool

true only when both the section and key exist.

LoadError
# Load
C#
public Error Load(string path);

Reads and parses a file into this ConfigFile. Matching values are replaced, but existing values absent from the file remain: Load does not clear the object. Use a new ConfigFile or call Clear() first for replacement. Check the returned Error.

Parameters
NameTypeDefault
pathstring—
path

Path to the configuration file to read, for example user://settings.ini. Load does not create a missing file.

Returns Error

Error.Ok after successful reading and parsing; otherwise a file-opening or parsing error. Do not assume a failed load cleared the object.

LoadEncrypted2 overloads
# LoadEncrypted · 1/2
C#
public Error LoadEncrypted(string path, byte[] key);

Opens an encrypted file using the supplied 32-byte key, then parses values into this instance. Like Load, merges data without clearing earlier values. A wrong key, damaged file or parse error is not a successful load: check Error and apply data from a fresh object only after validation.

Parameters
NameTypeDefault
pathstring—
keybyte[]—
path

File path; normally user:// for user data.

key

Exactly 32 AES key bytes. byte[] and ReadOnlySpan<byte> pass the same kind of key; they are not different file formats.

Returns Error

Error.Ok after successful decryption and parsing; otherwise an open, format, key or parse error.

# LoadEncrypted · 2/2
C#
public Error LoadEncrypted(string path, ReadOnlySpan<byte> key);

Opens an encrypted file using the supplied 32-byte key, then parses values into this instance. Like Load, merges data without clearing earlier values. A wrong key, damaged file or parse error is not a successful load: check Error and apply data from a fresh object only after validation.

Parameters
NameTypeDefault
pathstring—
keyReadOnlySpan<byte>—
path

File path; normally user:// for user data.

key

Exactly 32 AES key bytes. byte[] and ReadOnlySpan<byte> pass the same kind of key; they are not different file formats.

Returns Error

Error.Ok after successful decryption and parsing; otherwise an open, format, key or parse error.

LoadEncryptedPassError
# LoadEncryptedPass
C#
public Error LoadEncryptedPass(string path, string password);

Loads a SaveEncryptedPass file using the same password, then merges values into the current object. Neither clears earlier state nor establishes that gameplay data is valid: check Error, types and ranges.

Parameters
NameTypeDefault
pathstring—
passwordstring—
path

File path; its parent directory must exist.

password

Password used by the built-in key derivation. Use the same password for reading; do not substitute its string for a byte[] key in another overload.

Returns Error

Error.Ok on successful loading; otherwise a decryption, open or parse error.

ParseError
# Parse
C#
public Error Parse(string data);

Parses text into this instance, adding values and replacing matching keys. Does not clear earlier data. Mutates the object while parsing: an error does not guarantee rollback of values already read. For independent loading, parse into a new ConfigFile and check Error before applying data to the game.

Parameters
NameTypeDefault
datastring—
data

ConfigFile-format text, not a filename. Values use Variant syntax; do not assume full compatibility with arbitrary INI parsers.

Returns Error

Error.Ok on successful parsing; otherwise a parse error. The object may be partially changed.

SaveError
# Save
C#
public Error Save(string path);

Writes the current ConfigFile values to a file with an INI-style structure. SetValue changes memory only; writing requires a separate Save. Missing parent directories are not created.

Parameters
NameTypeDefault
pathstring—
path

Destination file path. Use a writable location such as user://settings.ini for user settings.

Returns Error

Error.Ok on successful writing; otherwise an error code. Check it before reporting a successful save.

SaveEncrypted2 overloads
# SaveEncrypted · 1/2
C#
public Error SaveEncrypted(string path, byte[] key);

Writes current values using AES-256 and the supplied 32-byte key. Does not create parent directories or perform an atomic replacement with a backup. An error does not guarantee preservation of the old file: the destination is opened for writing before the operation finishes.

Parameters
NameTypeDefault
pathstring—
keybyte[]—
path

File path; normally user:// for user data.

key

Exactly 32 AES key bytes. byte[] and ReadOnlySpan<byte> pass the same kind of key; they are not different file formats.

Returns Error

Error.Ok on successful execution; otherwise an error code. Does not guarantee durability across power loss.

# SaveEncrypted · 2/2
C#
public Error SaveEncrypted(string path, ReadOnlySpan<byte> key);

Writes current values using AES-256 and the supplied 32-byte key. Does not create parent directories or perform an atomic replacement with a backup. An error does not guarantee preservation of the old file: the destination is opened for writing before the operation finishes.

Parameters
NameTypeDefault
pathstring—
keyReadOnlySpan<byte>—
path

File path; normally user:// for user data.

key

Exactly 32 AES key bytes. byte[] and ReadOnlySpan<byte> pass the same kind of key; they are not different file formats.

Returns Error

Error.Ok on successful execution; otherwise an error code. Does not guarantee durability across power loss.

SaveEncryptedPassError
# SaveEncryptedPass
C#
public Error SaveEncryptedPass(string path, string password);

Saves values with encryption using the built-in password-derived key. This is a different key-input method from passing 32 bytes to SaveEncrypted. Does not back up or atomically replace an existing file.

Parameters
NameTypeDefault
pathstring—
passwordstring—
path

File path; its parent directory must exist.

password

Password used by the built-in key derivation. Use the same password for reading; do not substitute its string for a byte[] key in another overload.

Returns Error

Error.Ok on successful execution; otherwise an error code.

SetValuevoid
# SetValue
C#
public void SetValue(string section, string key, Variant value);

Assigns a value in memory, creating the section and key when needed. A Nil value, including default(Variant), removes the key and removes its section if empty. The file is not changed until Save.

Parameters
NameTypeDefault
sectionstring—
keystring—
valueVariant—
section

Section name. An empty string identifies values outside a section.

key

Key name within the specified section.

value

Variant value to store in memory. Nil means deleting the key, rather than storing an empty value.

Reckfell Engine documentationBack to top ↑
QUICK LINKSGetting startedEntity hierarchyC# & .NET 10Scenes and prefabs
Reckfell guides and full API K
reckfellENGINE
RECKFELL ACCOUNT

Sign in

Sign in to your Reckfell account.

One account for the entire Reckfell platform.