Exemplo n.º 1
0
		public static Order Deserialize(World world, BinaryReader r)
		{
			switch (r.ReadByte())
			{
				case 0xFF:
					{
						var order = r.ReadString();
						var subjectId = r.ReadUInt32();
						var flags = (OrderFields)r.ReadByte();

						var targetActorId = flags.HasField(OrderFields.TargetActor) ? r.ReadUInt32() : uint.MaxValue;
						var targetLocation = (CPos)(flags.HasField(OrderFields.TargetLocation) ? r.ReadInt2() : int2.Zero);
						var targetString = flags.HasField(OrderFields.TargetString) ? r.ReadString() : null;
						var queued = flags.HasField(OrderFields.Queued);
						var extraLocation = (CPos)(flags.HasField(OrderFields.ExtraLocation) ? r.ReadInt2() : int2.Zero);
						var extraData = flags.HasField(OrderFields.ExtraData) ? r.ReadUInt32() : 0;

						if (world == null)
							return new Order(order, null, null, targetLocation, targetString, queued, extraLocation, extraData);

						Actor subject, targetActor;
						if (!TryGetActorFromUInt(world, subjectId, out subject) || !TryGetActorFromUInt(world, targetActorId, out targetActor))
							return null;

						return new Order(order, subject, targetActor, targetLocation, targetString, queued, extraLocation, extraData);
					}

				case 0xfe:
					{
						var name = r.ReadString();
						var data = r.ReadString();

						return new Order(name, null, false) { IsImmediate = true, TargetString = data };
					}

				default:
					throw new NotImplementedException();
			}
		}
Exemplo n.º 2
0
        static object Read(World world, BinaryReader r, Type t, ref bool result)
        {
            if (t == typeof(byte))
                return r.ReadByte();

            if (t == typeof(sbyte))
                return r.ReadSByte();

            if (t == typeof(char))
                return r.ReadChar();

            if (t == typeof(int))
                return r.ReadInt32();

            if (t == typeof(uint))
                return r.ReadUInt32();

            if (t == typeof(bool))
                return r.ReadBoolean();

            if (t == typeof(string))
                return r.ReadString(true);

            if (t == typeof(int2))
                return r.ReadInt2();

            if (t == typeof(long))
                return r.ReadInt64();

            if (t == typeof(ulong))
                return r.ReadUInt64();

            if (t == typeof(short))
                return r.ReadInt16();

            if (t == typeof(ushort))
                return r.ReadUInt16();

            if (t == typeof(Actor))
            {
                Actor ret;
                if (result)
                    result = TryGetActorFromUInt(world, r.ReadUInt32(), out ret);
                else
                    TryGetActorFromUInt(world, r.ReadUInt32(), out ret);

                return ret;
            }

            throw new Exception("Tried to deserialize unhandled type.");
        }