Datamodel.NET is a library which implements the Datamodel structure and Datamodel Exchange (DMX) file format.
Datamodel is a strongly-typed generic data structure designed by Valve Corporation. It is primarily used as a developer storage format for meshes, animations, and maps.
dotnet add package KeyValues2usingDatamodel;// Load a file with unknown layoutusingvardm=Datamodel.Load("my_file.dmx");varelement=dm.Root;varvalue=element.Get<string>("my_property");// Load a file with a known layoutusingvarmap=Datamodel.Load<CMapRootElement>("fy_pool.vmap");varroot=(CMapRootElement)map.Root;Debug.Assert(root.IsPrefab==false);// Layout definition// Full implementation can be found here:// https://github.com/ValveResourceFormat/Datamodel.NET/blob/master/Tests/ValveMap.cs[LowercaseProperties]classCMapRootElement:Element{publicboolIsPrefab{get;set;}publicintEditorBuild{get;set;}=8600;publicintEditorVersion{get;set;}=400;}- Support for all known versions of Valve's
binaryandkeyvalues2DMX encodings - Inline documentation
- Binary codec supports just-in-time attribute loading
- Write your own codecs with the
ICodecinterface - Serialize and deserialize support for Datamodel.Element subclasses
varHelloWorld=newDatamodel.Datamodel("helloworld",1);// must provide a format name (can be anything) and versionHelloWorld.Root=newDatamodel.Element(HelloWorld,"my_root");HelloWorld.Root["Hello"]="World";// any supported attribute type can be assignedvarMyString=HelloWorld.Root.Get<string>("Hello");HelloWorld.Save("hello world.dmx","keyvalues2",1);// must provide an encoding name and version<--!dmxencodingkeyvalues21formathelloworld1>
{
"Hello""string""World"
}The following .NET types are supported as Datamodel attributes:
intfloatboolstringbytebyte[]Vector2Vector3Vector4/QuaternionMatrix4x4ulongSystem.TimeSpan
Additionally, the following Datamodel.NET types are supported:
Element(a named collection of attributes)QAngle
IList<T> collections of the above types are also supported. (This can be a bit confusing given that both byte and byte[] are valid attribute types; use the ByteArray type if you run into trouble.)
Datamodel.NET is licensed under the MIT License.
The sample .dmx and .vmap files under Tests/Resources are derived from Valve
Corporation game content and are included solely as test fixtures. They are not covered by the MIT
license above and remain the property of Valve Corporation. They are not distributed in the NuGet package.