protected MsmqIntegrationInputMessage(SizeQuota bufferSizeQuota) : base(22, bufferSizeQuota) { this.acknowledge = new ByteProperty(this, UnsafeNativeMethods.PROPID_M_ACKNOWLEDGE); this.adminQueue = new StringProperty(this, UnsafeNativeMethods.PROPID_M_ADMIN_QUEUE, initialQueueNameLength); this.adminQueueLength = new IntProperty(this, UnsafeNativeMethods.PROPID_M_ADMIN_QUEUE_LEN, initialQueueNameLength); this.appSpecific = new IntProperty(this, UnsafeNativeMethods.PROPID_M_APPSPECIFIC); this.arrivedTime = new IntProperty(this, UnsafeNativeMethods.PROPID_M_ARRIVEDTIME); this.senderIdType = new IntProperty(this, UnsafeNativeMethods.PROPID_M_SENDERID_TYPE); this.authenticated = new ByteProperty(this, UnsafeNativeMethods.PROPID_M_AUTHENTICATED); this.bodyType = new IntProperty(this, UnsafeNativeMethods.PROPID_M_BODY_TYPE); this.correlationId = new BufferProperty(this, UnsafeNativeMethods.PROPID_M_CORRELATIONID, UnsafeNativeMethods.PROPID_M_CORRELATIONID_SIZE); this.destinationQueue = new StringProperty(this, UnsafeNativeMethods.PROPID_M_DEST_FORMAT_NAME, initialQueueNameLength); this.destinationQueueLength = new IntProperty(this, UnsafeNativeMethods.PROPID_M_DEST_FORMAT_NAME_LEN, initialQueueNameLength); this.extension = new BufferProperty(this, UnsafeNativeMethods.PROPID_M_EXTENSION, bufferSizeQuota.AllocIfAvailable(initialExtensionLength)); this.extensionLength = new IntProperty(this, UnsafeNativeMethods.PROPID_M_EXTENSION_LEN, initialExtensionLength); this.label = new StringProperty(this, UnsafeNativeMethods.PROPID_M_LABEL, initialLabelLength); this.labelLength = new IntProperty(this, UnsafeNativeMethods.PROPID_M_LABEL_LEN, initialLabelLength); this.priority = new ByteProperty(this, UnsafeNativeMethods.PROPID_M_PRIORITY); this.responseFormatName = new StringProperty(this, UnsafeNativeMethods.PROPID_M_RESP_FORMAT_NAME, initialQueueNameLength); this.responseFormatNameLength = new IntProperty(this, UnsafeNativeMethods.PROPID_M_RESP_FORMAT_NAME_LEN, initialQueueNameLength); this.sentTime = new IntProperty(this, UnsafeNativeMethods.PROPID_M_SENTTIME); this.timeToReachQueue = new IntProperty(this, UnsafeNativeMethods.PROPID_M_TIME_TO_REACH_QUEUE); this.privacyLevel = new IntProperty(this, UnsafeNativeMethods.PROPID_M_PRIV_LEVEL); }
public override int GetHashCode() { unchecked { // Choose large primes to avoid hashing collisions const int HashingBase = (int)2166136261; const int HashingMultiplier = 16777619; int hash = HashingBase; hash = (hash * HashingMultiplier) ^ ByteProperty.GetHashCode(); hash = (hash * HashingMultiplier) ^ ShortByteProperty.GetHashCode(); hash = (hash * HashingMultiplier) ^ IntProperty.GetHashCode(); hash = (hash * HashingMultiplier) ^ UIntProperty.GetHashCode(); hash = (hash * HashingMultiplier) ^ ShortProperty.GetHashCode(); hash = (hash * HashingMultiplier) ^ UShortProperty.GetHashCode(); hash = (hash * HashingMultiplier) ^ LongProperty.GetHashCode(); hash = (hash * HashingMultiplier) ^ ULongProperty.GetHashCode(); hash = (hash * HashingMultiplier) ^ FloatPropertyOne.GetHashCode(); hash = (hash * HashingMultiplier) ^ FloatPropertyTwo.GetHashCode(); hash = (hash * HashingMultiplier) ^ DoublePropertyOne.GetHashCode(); hash = (hash * HashingMultiplier) ^ DoublePropertyTwo.GetHashCode(); hash = (hash * HashingMultiplier) ^ CharProperty.GetHashCode(); hash = (hash * HashingMultiplier) ^ BoolProperty.GetHashCode(); hash = (hash * HashingMultiplier) ^ DecimalProperty.GetHashCode(); return(hash); } }
public void Initialize_ByteProperty() { IBusinessObjectNumericProperty property = new ByteProperty( GetPropertyParameters(GetPropertyInfo(typeof(ClassWithAllDataTypes), "Byte"), _businessObjectProvider)); Assert.That(property.Type, Is.SameAs(typeof(Byte))); Assert.That(property.AllowNegative, Is.False); }
void EnsureAcknowledgeProperty(byte value) { if (this.acknowledge == null) { this.acknowledge = new ByteProperty(this, UnsafeNativeMethods.PROPID_M_ACKNOWLEDGE); } this.acknowledge.Value = value; }
protected void EnsureJournalProperty(byte flag, bool isFlagSet) { if (this.journal == null) { this.journal = new ByteProperty(this, UnsafeNativeMethods.PROPID_M_JOURNAL); } if (isFlagSet) { this.journal.Value |= flag; } else { this.journal.Value &= (byte)(~flag); } }
public void BytePropertyEnumWrite() { using (var stream = new MemoryStream()) using (var writer = new BinaryWriter(stream)) { var prop = new ByteProperty(ByteEnumName) { Type = ByteEnumType, Value = ByteEnumValue }; prop.Serialize(writer); Assert.AreEqual(16, prop.SerializedLength); CollectionAssert.AreEqual(ByteEnumBytes, stream.ToArray()); } }
public void BytePropertyNumberWrite() { using (var stream = new MemoryStream()) using (var writer = new BinaryWriter(stream)) { var prop = new ByteProperty(ByteNumberName) { Type = "None", Value = "0" }; prop.Serialize(writer); Assert.AreEqual(1, prop.SerializedLength); CollectionAssert.AreEqual(ByteNumberBytes, stream.ToArray()); } }
public static DotArkProperty ReadPropertyFromDisk(DotArkDeserializer d) { var ms = d.ms; //First, read a name and open it. ArkClassName name = ms.ReadArkClassname(d); //If this name is null, we've done something wrong. if (name == null) { throw new Exception("A property reading error occurred and got an unexpected NULL value; do not save"); } //If the name is None, we've read to the final property and we can stop. if (name.IsNone()) { return(null); } //Now, read the type ArkClassName type = ms.ReadArkClassname(d); //If the type is None or unreadable, something has gone wrong. if (type == null) { throw new Exception($"A property name was identified as {name.classname}, but the type failed to read."); } //Read in the index and size int size = ms.ReadInt(); int index = ms.ReadInt(); //Based on the type, deserialize this. DotArkProperty prop; switch (type.classname) { case "IntProperty": prop = new IntProperty(d, index, size); break; case "UInt32Property": prop = new UInt32Property(d, index, size); break; case "Int8Property": prop = new Int8Property(d, index, size); break; case "Int16Property": prop = new Int16Property(d, index, size); break; case "UInt16Property": prop = new UInt16Property(d, index, size); break; case "UInt64Property": prop = new UInt64Property(d, index, size); break; case "BoolProperty": prop = new BoolProperty(d, index, size); break; case "ByteProperty": prop = new ByteProperty(d, index, size); break; case "FloatProperty": prop = new FloatProperty(d, index, size); break; case "DoubleProperty": prop = new DoubleProperty(d, index, size); break; case "NameProperty": prop = new NameProperty(d, index, size); break; case "ObjectProperty": prop = new ObjectProperty(d, index, size); break; case "StrProperty": prop = new StrProperty(d, index, size); break; case "StructProperty": prop = new StructProperty(d, index, size); break; case "ArrayProperty": prop = DotArkArray.ReadArray(d, index, size); //UNFINISHED break; case "TextProperty": prop = new TextProperty(d, index, size); break; default: //Unknown throw new Exception($"Type {type.classname} was not a valid property type. Something failed to read."); } //Set additional values in the property and return it. prop.type = type; prop.name = name; prop.index = index; prop.size = size; return(prop); }
public void SetValue(object value) { string typeName = value.GetType().ToString(); switch (typeName) { case "byte": { if (type == EPropertyType.EPropertyType_Byte) { ByteProperty prop = this as ByteProperty; prop.SetValue((byte)value); return; } } break; case "bool": { if (type == EPropertyType.EPropertyType_Bool) { BoolProperty prop = this as BoolProperty; prop.SetValue((bool)value); return; } } break; case "short": { if (type == EPropertyType.EPropertyType_Short) { ShortProperty prop = this as ShortProperty; prop.SetValue((short)value); return; } } break; case "int": { if (type == EPropertyType.EPropertyType_Int) { IntProperty prop = this as IntProperty; prop.SetValue((int)value); return; } } break; case "long": { if (type == EPropertyType.EPropertyType_Long) { LongProperty prop = this as LongProperty; prop.SetValue((long)value); return; } } break; case "float": { if (type == EPropertyType.EPropertyType_Float) { FloatProperty prop = this as FloatProperty; prop.SetValue((float)value); return; } } break; case "double": { if (type == EPropertyType.EPropertyType_Double) { DoubleProperty prop = this as DoubleProperty; prop.SetValue((double)value); return; } } break; case "Vector2": { if (type == EPropertyType.EPropertyType_Vector2) { Vector2Property prop = this as Vector2Property; prop.SetValue((Vector2)value); return; } } break; case "Vector3": { if (type == EPropertyType.EPropertyType_Vector3) { Vector3Property prop = this as Vector3Property; prop.SetValue((Vector3)value); return; } } break; case "Vector4": { if (type == EPropertyType.EPropertyType_Vector4) { Vector4Property prop = this as Vector4Property; prop.SetValue((Vector4)value); return; } } break; case "Quaternion": { if (type == EPropertyType.EPropertyType_Quaternion) { QuaternionProperty prop = this as QuaternionProperty; prop.SetValue((Quaternion)value); return; } } break; case "Matrix4x4": { if (type == EPropertyType.EPropertyType_Matrix4x4) { Matrix4x4Property prop = this as Matrix4x4Property; prop.SetValue((Matrix4x4)value); return; } } break; case "Color": { if (type == EPropertyType.EPropertyType_Color) { ColorProperty prop = this as ColorProperty; prop.SetValue((Color)value); return; } } break; case "string": { if (type == EPropertyType.EPropertyType_String) { StringProperty prop = this as StringProperty; prop.SetValue((string)value); return; } } break; case "object": { if (type == EPropertyType.EPropertyType_Object) { m_value = value; return; } } break; } return; }
public bool equals(ByteProperty other) { return(this.GetValue() == other.GetValue()); }
public QueueTransactionProperties() : base(1) { this.transaction = new ByteProperty(this, UnsafeNativeMethods.PROPID_Q_TRANSACTION); }
private static DbDino ParseDinoData(DbServer server, string inventoryId, ulong revisionId, byte revisionIndex, int inventoryType, ulong inventoryItemId, string request) { //Decode data as bytes and read byte[] data = new byte[request.Length / 2]; for (int index = 0; index < data.Length; index++) { data[index] = byte.Parse(request.Substring(index * 2, 2), System.Globalization.NumberStyles.HexNumber); } //Now, decode and parse ARKDinoDataObject[] parts = ARKDinoDataTool.ReadData(data); Console.WriteLine(JsonConvert.SerializeObject(parts)); //Get dino part ARKDinoDataObject d = parts[0]; //Convert colors List <string> colors = new List <string>(); for (int i = 0; true; i++) { ByteProperty colorProp = d.GetPropertyByName <ByteProperty>("ColorSetIndices", i); if (colorProp == null) { break; } byte color = colorProp.byteValue; if (color <= 0 || color > ArkStatics.ARK_COLOR_IDS.Length) { colors.Add("#FFFFFF"); } else { colors.Add(ArkStatics.ARK_COLOR_IDS[colorProp.byteValue - 1]); //Look this up in the color table to get the nice HTML value. } } //Get status component ARKDinoDataObject status = d.GetPropertyByName <ObjectProperty>("MyCharacterStatusComponent").localLinkObject; //Read as dino, adding required fields first DbDino dino = new DbDino { revision_id = revisionId, revision_type = revisionIndex, is_cryo = true, cryo_inventory_id = inventoryId, dino_id = Program.GetMultipartID(d.GetPropertyByName <UInt32Property>("DinoID1").value, d.GetPropertyByName <UInt32Property>("DinoID2").value), tribe_id = d.GetPropertyByName <IntProperty>("TargetingTeam").value, tamed_name = d.GetStringProperty("TamedName", 0, ""), classname = Program.TrimArkClassname(d.name), tamer_name = d.GetStringProperty("TamerString", 0, ""), baby_age = d.GetFloatProperty("BabyAge", 0, 1), is_baby = d.GetBoolProperty("bIsBaby", 0, false), next_imprint_time = d.GetDoubleProperty("BabyNextCuddleTime", 0, 0), imprint_quality = d.GetFloatProperty("DinoImprintingQuality", 0, 0), color_indexes = new int[6], experience = status.GetFloatProperty("ExperiencePoints", 0, 0), server_id = server._id, location = new DbLocation(0, 0, 0), is_female = d.GetBoolProperty("bIsFemale", 0, false), level = status.GetIntProperty("BaseCharacterLevel", 0, 0) + status.GetUInt16Property("ExtraCharacterLevel", 0, 0), base_level = status.GetIntProperty("BaseCharacterLevel", 0, 0), is_tamed = true, taming_effectiveness = 1, max_stats = ConvertStatsFloat(status, "MaxStatusValues"), current_stats = ConvertStatsFloat(status, "CurrentStatusValues"), tamed_levelups_applied = ConvertStatsInt(status, "NumberOfLevelUpPointsAppliedTamed"), base_levelups_applied = ConvertStatsInt(status, "NumberOfLevelUpPointsApplied"), status = ConvertStatus(d), cryo_inventory_type = inventoryType, cryo_inventory_itemid = inventoryItemId, experience_points = status.GetFloatProperty("ExperiencePoints", 0, 0) }; return(dino); }
public static UProperty ReadProp(IOMemoryStream ms, UAssetFile f, string arrayType, bool isStruct) { //Read the name long start = ms.position; //Read the remainder of the properties string name; int u1; string type; int u2; int length; int index; if (arrayType == null) { //Not an array name = ms.ReadNameTableEntry(f); //Return null if this is "None". That means we're done reading if (name == "None") { return(null); } u1 = ms.ReadInt(); type = ms.ReadNameTableEntry(f); u2 = ms.ReadInt(); length = ms.ReadInt(); index = ms.ReadInt(); } else { name = null; u1 = 0; type = arrayType; u2 = 0; length = 0; index = 0; } long payloadStart = ms.position; //Create the object UProperty u; switch (type) { case "ArrayProperty": u = new ArrayProperty(ms, f); break; case "BoolProperty": u = new BoolProperty(ms, f); break; case "ByteProperty": u = new ByteProperty(ms, f); break; case "DoubleProperty": u = new DoubleProperty(ms, f); break; case "FloatProperty": u = new FloatProperty(ms, f); break; case "Int16Property": u = new Int16Property(ms, f); break; case "Int8Property": u = new Int8Property(ms, f); break; case "IntProperty": u = new IntProperty(ms, f); break; case "NameProperty": u = new NameProperty(ms, f); break; case "ObjectProperty": u = new ObjectProperty(ms, f); break; case "StrProperty": u = new StrProperty(ms, f); break; case "StructProperty": u = new StructProperty(ms, f); break; case "TextProperty": u = new TextProperty(ms, f); break; case "UInt16Property": u = new UInt16Property(ms, f); break; case "UInt32Property": u = new UInt32Property(ms, f); break; case "UInt64Property": u = new UInt64Property(ms, f); break; default: throw new Exception($"FAILED TO READ UPROPERTY: Type {type} was not a valid type. Name={name}, u1={u1}, u2={u2}, length={length}, index={index}, position={start}"); } //Set attributes u.name = name; u.unknown1 = u1; u.type = type; u.unknown2 = u2; u.length = length; u.index = index; u.start = start; u.payloadStart = payloadStart; u.isArray = arrayType != null; //Dump f.DebugDump("UProperty Reading", ConsoleColor.Green, "name", name, "u1", u1.ToString(), "type", type, "u2", u2.ToString(), "length", length.ToString(), "index", index.ToString(), "start", start.ToString(), "payloadStart", payloadStart.ToString()); //Read u.Read(ms, f); //Log string msg = u.WriteString(); f.Debug("UProperty Read " + type, msg, ConsoleColor.DarkGreen); return(u); }
public MsmqIntegrationOutputMessage( MsmqChannelFactoryBase <IOutputChannel> factory, int bodySize, EndpointAddress remoteAddress, MsmqIntegrationMessageProperty property) : base(factory, bodySize, remoteAddress, 8) { if (null == property) { Fx.Assert("MsmqIntegrationMessageProperty expected"); } if (property.AcknowledgeType.HasValue) { EnsureAcknowledgeProperty((byte)property.AcknowledgeType.Value); } if (null != property.AdministrationQueue) { EnsureAdminQueueProperty(property.AdministrationQueue, false); } if (property.AppSpecific.HasValue) { this.appSpecific = new IntProperty(this, UnsafeNativeMethods.PROPID_M_APPSPECIFIC, property.AppSpecific.Value); } if (property.BodyType.HasValue) { EnsureBodyTypeProperty(property.BodyType.Value); } if (null != property.CorrelationId) { this.correlationId = new BufferProperty(this, UnsafeNativeMethods.PROPID_M_CORRELATIONID, MsmqMessageId.FromString(property.CorrelationId)); } if (null != property.Extension) { this.extension = new BufferProperty(this, UnsafeNativeMethods.PROPID_M_EXTENSION, property.Extension); } if (null != property.Label) { this.label = new StringProperty(this, UnsafeNativeMethods.PROPID_M_LABEL, property.Label); } if (property.Priority.HasValue) { this.priority = new ByteProperty(this, UnsafeNativeMethods.PROPID_M_PRIORITY, (byte)property.Priority.Value); } if (null != property.ResponseQueue) { EnsureResponseQueueProperty(property.ResponseQueue); } if (property.TimeToReachQueue.HasValue) { EnsureTimeToReachQueueProperty(MsmqDuration.FromTimeSpan(property.TimeToReachQueue.Value)); } }
protected MsmqOutputMessage(MsmqChannelFactoryBase <TChannel> factory, int bodySize, EndpointAddress remoteAddress, int additionalPropertyCount) : base(15 + additionalPropertyCount) { this.body = new BufferProperty(this, UnsafeNativeMethods.PROPID_M_BODY, bodySize); this.messageId = new BufferProperty(this, UnsafeNativeMethods.PROPID_M_MSGID, UnsafeNativeMethods.PROPID_M_MSGID_SIZE); EnsureBodyTypeProperty(UnsafeNativeMethods.VT_VECTOR | UnsafeNativeMethods.VT_UI1); EnsureJournalProperty((byte)UnsafeNativeMethods.MQMSG_JOURNAL, factory.UseSourceJournal); this.delivery = new ByteProperty(this, UnsafeNativeMethods.PROPID_M_DELIVERY); if (factory.Durable) { this.delivery.Value = (byte)UnsafeNativeMethods.MQMSG_DELIVERY_RECOVERABLE; } else { this.delivery.Value = (byte)UnsafeNativeMethods.MQMSG_DELIVERY_EXPRESS; } if (factory.TimeToLive != TimeSpan.MaxValue) { int totalSeconds = MsmqDuration.FromTimeSpan(factory.TimeToLive); EnsureTimeToReachQueueProperty(totalSeconds); this.timeToBeReceived = new IntProperty(this, UnsafeNativeMethods.PROPID_M_TIME_TO_BE_RECEIVED, totalSeconds); } switch (factory.DeadLetterQueue) { case DeadLetterQueue.None: EnsureJournalProperty((byte)UnsafeNativeMethods.MQMSG_DEADLETTER, false); break; case DeadLetterQueue.System: EnsureJournalProperty((byte)UnsafeNativeMethods.MQMSG_DEADLETTER, true); break; case DeadLetterQueue.Custom: EnsureJournalProperty((byte)UnsafeNativeMethods.MQMSG_DEADLETTER, true); EnsureDeadLetterQueueProperty(factory.DeadLetterQueuePathName); break; } if (MsmqAuthenticationMode.WindowsDomain == factory.MsmqTransportSecurity.MsmqAuthenticationMode) { EnsureSenderIdTypeProperty(UnsafeNativeMethods.MQMSG_SENDERID_TYPE_SID); this.authLevel = new IntProperty(this, UnsafeNativeMethods.PROPID_M_AUTH_LEVEL, UnsafeNativeMethods.MQMSG_AUTH_LEVEL_ALWAYS); this.hashAlgorithm = new IntProperty( this, UnsafeNativeMethods.PROPID_M_HASH_ALG, MsmqSecureHashAlgorithmHelper.ToInt32(factory.MsmqTransportSecurity.MsmqSecureHashAlgorithm)); if (ProtectionLevel.EncryptAndSign == factory.MsmqTransportSecurity.MsmqProtectionLevel) { this.privLevel = new IntProperty(this, UnsafeNativeMethods.PROPID_M_PRIV_LEVEL, UnsafeNativeMethods.MQMSG_PRIV_LEVEL_BODY_ENHANCED); this.encryptionAlgorithm = new IntProperty( this, UnsafeNativeMethods.PROPID_M_ENCRYPTION_ALG, MsmqEncryptionAlgorithmHelper.ToInt32(factory.MsmqTransportSecurity.MsmqEncryptionAlgorithm)); } } else if (MsmqAuthenticationMode.Certificate == factory.MsmqTransportSecurity.MsmqAuthenticationMode) { this.authLevel = new IntProperty(this, UnsafeNativeMethods.PROPID_M_AUTH_LEVEL, UnsafeNativeMethods.MQMSG_AUTH_LEVEL_ALWAYS); this.hashAlgorithm = new IntProperty( this, UnsafeNativeMethods.PROPID_M_HASH_ALG, MsmqSecureHashAlgorithmHelper.ToInt32(factory.MsmqTransportSecurity.MsmqSecureHashAlgorithm)); if (ProtectionLevel.EncryptAndSign == factory.MsmqTransportSecurity.MsmqProtectionLevel) { this.privLevel = new IntProperty(this, UnsafeNativeMethods.PROPID_M_PRIV_LEVEL, UnsafeNativeMethods.MQMSG_PRIV_LEVEL_BODY_ENHANCED); this.encryptionAlgorithm = new IntProperty( this, UnsafeNativeMethods.PROPID_M_ENCRYPTION_ALG, MsmqEncryptionAlgorithmHelper.ToInt32(factory.MsmqTransportSecurity.MsmqEncryptionAlgorithm)); } EnsureSenderIdTypeProperty(UnsafeNativeMethods.MQMSG_SENDERID_TYPE_NONE); this.senderCert = new BufferProperty(this, UnsafeNativeMethods.PROPID_M_SENDER_CERT); } else { this.authLevel = new IntProperty(this, UnsafeNativeMethods.PROPID_M_AUTH_LEVEL, UnsafeNativeMethods.MQMSG_AUTH_LEVEL_NONE); EnsureSenderIdTypeProperty(UnsafeNativeMethods.MQMSG_SENDERID_TYPE_NONE); } this.trace = new ByteProperty(this, UnsafeNativeMethods.PROPID_M_TRACE, (byte)(factory.UseMsmqTracing ? UnsafeNativeMethods.MQMSG_SEND_ROUTE_TO_REPORT_QUEUE : UnsafeNativeMethods.MQMSG_TRACE_NONE)); }
public static Property Clone(Property target) { Property prop = null; int id = target.PropertyId; PropertyBag bag = target.Owner; switch (target.PropertyType) { case (int)PropertyKind.WispObject: prop = new WispProperty(target.Name, id, ((WispProperty)target).Value, bag); break; case (int)PropertyKind.WispArray: prop = new WispArrayProperty(target.Name, id, ((WispArrayProperty)target).Value, bag); break; case (int)PropertyKind.Int32: prop = new Int32Property(target.Name, id, ((Int32Property)target).Value, bag); break; case (int)PropertyKind.String: prop = new StringProperty(target.Name, id, ((StringProperty)target).Value, bag); break; case (int)PropertyKind.Bool: prop = new BoolProperty(target.Name, id, ((BoolProperty)target).Value, bag); break; case (int)PropertyKind.Guid: prop = new GuidProperty(target.Name, id, ((GuidProperty)target).Value, bag); break; case (int)PropertyKind.Single: prop = new SingleProperty(target.Name, id, ((SingleProperty)target).Value, bag); break; case (int)PropertyKind.Int32Array: prop = new Int32ArrayProperty(target.Name, id, ((Int32ArrayProperty)target).Value, bag); break; case (int)PropertyKind.StringArray: prop = new StringArrayProperty(target.Name, id, ((StringArrayProperty)target).Value, bag); break; case (int)PropertyKind.DateTime: prop = new DateTimeProperty(target.Name, id, ((DateTimeProperty)target).Value, bag); break; case (int)PropertyKind.GuidArray: prop = new GuidArrayProperty(target.Name, id, ((GuidArrayProperty)target).Value, bag); break; case (int)PropertyKind.Double: prop = new DoubleProperty(target.Name, id, ((DoubleProperty)target).Value, bag); break; case (int)PropertyKind.Byte: prop = new ByteProperty(target.Name, id, ((ByteProperty)target).Value, bag); break; case (int)PropertyKind.Component: prop = new ComponentProperty(target.Name, id, ((ComponentProperty)target).Value, bag); break; case (int)PropertyKind.SingleArray: prop = new SingleArrayProperty(target.Name, id, ((SingleArrayProperty)target).Value, bag); break; case (int)PropertyKind.Int64: prop = new Int64Property(target.Name, id, ((Int64Property)target).Value, bag); break; case (int)PropertyKind.ComponentArray: prop = new ComponentArrayProperty(target.Name, id, ((ComponentArrayProperty)target).Value, bag); break; case (int)PropertyKind.DateTimeArray: prop = new DateTimeArrayProperty(target.Name, id, ((DateTimeArrayProperty)target).Value, bag); break; case (int)PropertyKind.ByteArray: prop = new ByteArrayProperty(target.Name, id, ((ByteArrayProperty)target).Value, bag); break; case (int)PropertyKind.DoubleArray: prop = new DoubleArrayProperty(target.Name, id, ((DoubleArrayProperty)target).Value, bag); break; case (int)PropertyKind.Int16Array: prop = new Int16ArrayProperty(target.Name, id, ((Int16ArrayProperty)target).Value, bag); break; case (int)PropertyKind.Int16: prop = new Int16Property(target.Name, id, ((Int16Property)target).Value, bag); break; case (int)PropertyKind.Int64Array: prop = new Int64ArrayProperty(target.Name, id, ((Int64ArrayProperty)target).Value, bag); break; case (int)PropertyKind.BoolArray: prop = new BoolArrayProperty(target.Name, id, ((BoolArrayProperty)target).Value, bag); break; } prop.Name = target.Name; return prop; }
public static SerializedFields Parse(int length, BinaryReader reader) { var start = reader.BaseStream.Position; var result = new SerializedFields(); while (true) { var propertyName = reader.ReadLengthPrefixedString(); if (propertyName == "None") { break; } var fieldType = reader.ReadLengthPrefixedString(); var size = reader.ReadInt32(); var index = reader.ReadInt32(); int overhead; var before = reader.BaseStream.Position; switch (fieldType) { case ArrayProperty.TypeName: result.Add(ArrayProperty.Parse(propertyName, index, reader, size, out overhead)); break; case FloatProperty.TypeName: overhead = 1; result.Add(FloatProperty.Parse(propertyName, index, reader)); break; case IntProperty.TypeName: overhead = 1; result.Add(IntProperty.Parse(propertyName, index, reader)); break; case ByteProperty.TypeName: result.Add(ByteProperty.Parse(propertyName, index, reader, out overhead)); break; case EnumProperty.TypeName: result.Add(EnumProperty.Parse(propertyName, index, reader, out overhead)); break; case BoolProperty.TypeName: overhead = 2; result.Add(BoolProperty.Parse(propertyName, index, reader)); break; case StrProperty.TypeName: overhead = 1; result.Add(StrProperty.Parse(propertyName, index, reader)); break; case NameProperty.TypeName: overhead = 1; result.Add(NameProperty.Parse(propertyName, index, reader)); break; case ObjectProperty.TypeName: overhead = 1; result.Add(ObjectProperty.Parse(propertyName, index, reader)); break; case StructProperty.TypeName: result.Add(StructProperty.Parse(propertyName, index, reader, size, out overhead)); break; case MapProperty.TypeName: result.Add(MapProperty.Parse(propertyName, index, reader, size, out overhead)); break; case TextProperty.TypeName: overhead = 1; result.Add(TextProperty.Parse(propertyName, index, reader)); break; default: throw new NotImplementedException(fieldType); } var after = reader.BaseStream.Position; if (before + size + overhead != after) { throw new InvalidOperationException($"Expected {size} bytes read but got {after - before - overhead}"); } } var int1 = reader.ReadInt32(); Trace.Assert(int1 == 0); var remainingBytes = start + length - reader.BaseStream.Position; if (remainingBytes > 0) { result.TrailingData = reader.ReadBytes((int)remainingBytes); } //if (remainingBytes == 4) ////if(result.Fields.Count > 0) //{ // var int2 = reader.ReadInt32(); //} //else if (remainingBytes > 0 && result.Any(f => f is ArrayProperty && ((ArrayProperty)f).Type == StructProperty.TypeName)) //{ // var unk = reader.ReadBytes((int)remainingBytes); //} //else if (remainingBytes > 4) //{ // var int2 = reader.ReadInt32(); // var str2 = reader.ReadLengthPrefixedString(); // var str3 = reader.ReadLengthPrefixedString(); //} return(result); }