/// <summary> /// ED_Write /// </summary> public unsafe void WriteEdict(StreamWriter writer, MemoryEdict ed) { writer.WriteLine("{"); if (ed.free) { writer.WriteLine("}"); return; } for (var i = 1; i < _Progs.numfielddefs; i++) { var d = _FieldDefs[i]; var name = GetString(d.s_name); if (name != null && name.Length > 2 && name[name.Length - 2] == '_') // [strlen(name) - 2] == '_') { continue; // skip _x, _y, _z vars } var type = d.type & ~ProgramDef.DEF_SAVEGLOBAL; Int32 offset1; if (ed.IsV(d.ofs, out offset1)) { fixed(void *ptr = &ed.v) { var v = ( Int32 * )ptr + offset1; if (IsEmptyField(type, v)) { continue; } writer.WriteLine("\"{0}\" \"{1}\"", name, UglyValueString(( EdictType )d.type, ( EVal * )v)); } } else { fixed(void *ptr = ed.fields) { var v = ( Int32 * )ptr + offset1; if (IsEmptyField(type, v)) { continue; } writer.WriteLine("\"{0}\" \"{1}\"", name, UglyValueString(( EdictType )d.type, ( EVal * )v)); } } } writer.WriteLine("}"); }
/// <summary> /// ED_Print /// For debugging /// </summary> public unsafe void Print(MemoryEdict ed) { if (ed.free) { Host.Console.Print("FREE\n"); return; } Host.Console.Print("\nEDICT {0}:\n", Host.Server.NumForEdict(ed)); for (var i = 1; i < _Progs.numfielddefs; i++) { var d = _FieldDefs[i]; var name = GetString(d.s_name); if (name.Length > 2 && name[name.Length - 2] == '_') { continue; // skip _x, _y, _z vars } var type = d.type & ~ProgramDef.DEF_SAVEGLOBAL; Int32 offset; if (ed.IsV(d.ofs, out offset)) { fixed(void *ptr = &ed.v) { var v = ( Int32 * )ptr + offset; if (IsEmptyField(type, v)) { continue; } Host.Console.Print("{0,15} ", name); Host.Console.Print("{0}\n", ValueString(( EdictType )d.type, ( void * )v)); } } else { fixed(void *ptr = ed.fields) { var v = ( Int32 * )ptr + offset; if (IsEmptyField(type, v)) { continue; } Host.Console.Print("{0,15} ", name); Host.Console.Print("{0}\n", ValueString(( EdictType )d.type, ( void * )v)); } } } }
/// <summary> /// Since memory block containing original edict_t plus additional data /// is split into two fiels - edict_t.v and edict_t.fields we must check key.ofs /// to choose between thistwo parts. /// Warning: Key offset is in integers not bytes! /// </summary> private unsafe Boolean ParsePair(MemoryEdict ent, ProgramDefinition key, String s) { Int32 offset1; if (ent.IsV(key.ofs, out offset1)) { fixed(EntVars *ptr = &ent.v) { return(ParsePair(( Int32 * )ptr + offset1, key, s)); } } else fixed(Single *ptr = ent.fields) { return(ParsePair(ptr + offset1, key, s)); } }