internal static string GetClassName(Edict *entity) { // TODO: consider returning empty string? if (entity->v.classname == 0) { return(null); } IntPtr ptr = MetaModEngine.engineFunctions.SzFromIndex(entity->v.classname); return(Mono.Unix.UnixMarshal.PtrToString(ptr)); }
public static IEnumerable <Entity> Find(string field, string val) { Entity first = Find(null, field, val); if (first == null) { yield break; } else { yield return(first); } Entity entity = first; while ((entity = Find(entity, field, val)).Pointer != first.Pointer) { yield return(entity); } }
public static Entity CreateEntity(IntPtr entityPointer) { if (entityPointer == IntPtr.Zero) { return(null); } int index = Entity.GetIndex(entityPointer); if (entityDictionary.ContainsKey(index)) { return(entityDictionary[index]); } else { Edict *edict = (Edict *)entityPointer.ToPointer(); // TODO: 1 and maxplayer can be bot or player if (index >= 1 && index <= Server.MaxPlayers) { return(RegisterEntity(index, new Player(entityPointer))); } string classname = GetClassName(edict); if (classname.StartsWith("weapon_")) { return(RegisterEntity(index, new CounterStrike.Weapon(edict))); } switch (classname) { case "player": return(RegisterEntity(index, new Player(entityPointer))); default: return(RegisterEntity(index, new Entity(entityPointer))); } } }
internal Entity(Edict *entity) { this.entity = entity; Pointer = new IntPtr(entity); }
public static IEnumerable<Entity> Find(string field, string val) { Entity first = Find(null, field, val); if (first == null) { yield break; } else { yield return first; } Entity entity = first; while ((entity = Find(entity, field, val)).Pointer != first.Pointer) { yield return entity; } }