static void GetBytesUpdateValue(Hashtable tbl, MemberValue value, int field) { UpdateValueAttribute attrib = (UpdateValueAttribute)value.Attribute; if (attrib.BytesIndex < 0 || attrib.BytesIndex > 3) { throw new ObjectUpdateManagerException("BytesIndex out of range on " + value.GetName() + " BytesIndex = " + attrib.BytesIndex); } BytesUpdateValue v; if (tbl.Contains(field)) { IUpdateValue tmp = (IUpdateValue)tbl[field]; if (!(tmp is BytesUpdateValue)) { throw new ObjectUpdateManagerException("Field " + field + " was a " + tmp.GetType() + " not a BytesUpdateValue (" + value.GetName() + ")"); } v = (BytesUpdateValue)tmp; } else { v = new BytesUpdateValue(field); tbl[field] = v; } v.SetMemberValue(value, attrib.BytesIndex); }
public static void WriteDataUpdate(BinWriter w, BinaryTree values, object obj, bool clear, bool isClient) { try { //Console.WriteLine("Type: "+obj.GetType()); UpdateObjectInfo info = (UpdateObjectInfo)m_updateObjectInfos[obj.GetType()]; if (info == null) { throw new ObjectUpdateManagerException("UpdateObjectInfo is missing for type " + obj.GetType()); } if (!isClient && obj.GetType() == typeof(PlayerObject)) { info.MaxFields = (int)PLAYERFIELDS.MAX_NOTCLIENT; info.BlockSize = (byte)((info.MaxFields + 31) / 32); } w.Write(info.BlockSize); byte[] mask = new byte[info.BlockSize * 4]; IEnumerator e = values.GetEnumerator(); Hashtable tbl = info.tbl; long maskPos = w.BaseStream.Position; w.BaseStream.Position += mask.Length; while (e.MoveNext()) { if ((!isClient && ((int)e.Current <= (int)PLAYERFIELDS.MAX_NOTCLIENT)) || (isClient)) { IUpdateValue updater = (IUpdateValue)tbl[(int)e.Current]; if (updater == null) { throw new ObjectUpdateManagerException("UpdateValue Handler is missing for field " + e.Current + " in " + obj.GetType().ToString()); } updater.WriteValue(obj, w, mask); } } long pos = w.BaseStream.Position; w.BaseStream.Position = maskPos; w.Write(mask, 0, mask.Length); w.BaseStream.Position = pos; if (clear) { values.Clear(); } else { e.Reset(); } } catch (Exception exp) { DebugLogger.Log("", exp); } }
public static void WriteDataUpdate(BinWriter w, BinaryTree values, object obj, bool clear) { UpdateObjectInfo info = (UpdateObjectInfo)m_updateObjectInfos[obj.GetType()]; if (info == null) { throw new ObjectUpdateManagerException("UpdateObjectInfo is missing for type " + obj.GetType()); } w.Write(info.BlockSize); byte[] mask = new byte[info.BlockSize * 4]; IEnumerator e = values.GetEnumerator(); Hashtable tbl = info.tbl; long maskPos = w.BaseStream.Position; w.BaseStream.Position += mask.Length; while (e.MoveNext()) { IUpdateValue updater = (IUpdateValue)tbl[(int)e.Current]; if (updater == null) { throw new ObjectUpdateManagerException("UpdateValue Handler is missing for field " + e.Current + " in " + obj.GetType().ToString()); } updater.WriteValue(obj, w, mask); } long pos = w.BaseStream.Position; w.BaseStream.Position = maskPos; w.Write(mask, 0, mask.Length); w.BaseStream.Position = pos; if (clear) { values.Clear(); } else { e.Reset(); } }