public DAIGuid GetDaiGuidFieldValue(DAIField field) { Debug.Assert(field.ValueType == DAIFieldType.DAI_Guid, "this method can only be applied to GUID fields"); var guid = new DAIGuid(); uint UIntValue = field.GetUIntValue(); if ((UIntValue >> 31) == 1) { /* External Guid */ DAIExternalGuid Guid = this.ExternalGuids.ElementAt((int)(UIntValue & 0x7fffffff)); guid.external = true; guid.fileGuid = GuidToString(Guid.FileGuid); guid.instanceGuid = GuidToString(Guid.InstanceGuid); } else if (UIntValue == 0) { /* NULL Guid */ guid.instanceGuid = "null"; } else { /* Internal Guid */ byte[] Guid = this.InternalGuids[(int)(UIntValue - 1)]; guid.instanceGuid = GuidToString(Guid); } return(guid); }
private static DAIField wrapWithFakeField(DAIComplex value) { var fakeField = new DAIField(); fakeField.ValueType = DAIFieldType.DAI_Complex; fakeField.ComplexValue = value; return(fakeField); }
public DAIField ReadField(Stream s, int FieldIndex) { DAIField Field = new DAIField(); Field.Descriptor = FieldDescriptors[FieldIndex]; Field.Offset = s.Position; int FieldType = (Field.Descriptor.FieldType & 0xFFFF); if (FieldType == 0x29 || FieldType == 0xd029 || FieldType == 0x00 || FieldType == 0x8029) { Field.ComplexValue = ReadComplex(s, Field.Descriptor.ComplexReference); Field.ValueType = DAIFieldType.DAI_Complex; } else if (FieldType == 0x407d || FieldType == 0x409d) { String StrValue = ""; Int64 PrevPos = s.Position; int StringOffset = Tools.ReadInt(s); if (StringOffset == -1) { StrValue = ""; } else { s.Seek(Header.StringOffset + StringOffset, SeekOrigin.Begin); StrValue = Tools.ReadNullString(s); s.Seek(PrevPos + 4, SeekOrigin.Begin); } Field.Value = new byte[StrValue.Length]; for (int i = 0; i < StrValue.Length; i++) { Field.Value[i] = (byte)StrValue[i]; } Field.ValueType = DAIFieldType.DAI_String; } else if (FieldType == 0x35) { uint UIntValue = Tools.ReadUInt(s); Field.ValueType = DAIFieldType.DAI_Guid; Field.Value = BitConverter.GetBytes(UIntValue); } else if (FieldType == 0xc10d) { uint UIntValue = Tools.ReadUInt(s); Field.Value = BitConverter.GetBytes(UIntValue); Field.ValueType = DAIFieldType.DAI_UInt; } else if (FieldType == 0xc0fd) { int IntValue = Tools.ReadInt(s); Field.Value = BitConverter.GetBytes(IntValue); Field.ValueType = DAIFieldType.DAI_Int; } else if (FieldType == 0x417d) { Int64 LongValue = Tools.ReadLong(s); Field.Value = BitConverter.GetBytes(LongValue); Field.ValueType = DAIFieldType.DAI_Long; } else if (FieldType == 0xc13d) { float FloatValue = Tools.ReadFloat(s); Field.Value = BitConverter.GetBytes(FloatValue); Field.ValueType = DAIFieldType.DAI_Float; } else if (FieldType == 0xc0ad) { byte ByteValue = (byte)s.ReadByte(); Field.Value = new byte[] { ByteValue }; Field.ValueType = DAIFieldType.DAI_Bool; } else if (FieldType == 0xc0bd) { byte ByteValue = (byte)s.ReadByte(); Field.Value = new byte[] { ByteValue }; Field.ValueType = DAIFieldType.DAI_Byte; } else if (FieldType == 0xc0cd) { byte ByteValue = (byte)s.ReadByte(); Field.Value = new byte[] { ByteValue }; Field.ValueType = DAIFieldType.DAI_UByte; } else if (FieldType == 0xc0dd) { ushort UShortValue = Tools.ReadUShort(s); Field.Value = BitConverter.GetBytes(UShortValue); Field.ValueType = DAIFieldType.DAI_UShort; } else if (FieldType == 0xc0ed) { short ShortValue = Tools.ReadShort(s); Field.Value = BitConverter.GetBytes(ShortValue); Field.ValueType = DAIFieldType.DAI_Short; } else if (FieldType == 0xc15d) { byte[] Value = new byte[16]; for (int i = 0; i < 16; i++) { Value[i] = (byte)s.ReadByte(); } Field.Value = Value; Field.ValueType = DAIFieldType.DAI_LongLong; } else if (FieldType == 0x89 || FieldType == 0xc089) { String EnumValue = ""; int CompareValue = Tools.ReadInt(s); DAIComplexDescriptor EnumComplex = ComplexDescriptors[Field.Descriptor.ComplexReference]; if (EnumComplex.FieldCount != 0) { for (int i = EnumComplex.FieldStartIndex; i < EnumComplex.FieldStartIndex + EnumComplex.FieldCount; i++) { if (FieldDescriptors[i].PayloadOffset == CompareValue) { EnumValue = FieldDescriptors[i].FieldName; break; } } } Field.Value = new byte[EnumValue.Length]; for (int i = 0; i < EnumValue.Length; i++) { Field.Value[i] = (byte)EnumValue[i]; } Field.ValueType = DAIFieldType.DAI_Enum; } else if (FieldType == 0x41) { int Index = Tools.ReadInt(s); DAIArrayRepeater ArrayRepeater = ArrayRepeaters[Index]; DAIComplexDescriptor ArrayComplexDesc = ComplexDescriptors[Field.Descriptor.ComplexReference]; s.Seek(Header.ArraySectionStart + ArrayRepeater.Offset, SeekOrigin.Begin); DAIComplex ArrayComplex = new DAIComplex(); ArrayComplex.Descriptor = ArrayComplexDesc; ArrayComplex.Offset = s.Position; ArrayComplex.Fields = new List <DAIField>(); for (int i = 0; i < ArrayRepeater.Count; i++) { ArrayComplex.Fields.Add(ReadField(s, ArrayComplexDesc.FieldStartIndex)); } Field.ComplexValue = ArrayComplex; Field.ValueType = DAIFieldType.DAI_Array; } else { } return(Field); }
private static AValue convert(DAIField field, ConverterContext ctx) { AValue result; if (field.ValueType == DAIFieldType.DAI_Complex) { var value = field.GetComplexValue(); if (value == null) { result = new ASimpleValue("{null}"); } else { var astruct = new AStruct(); astruct.name = value.GetName(); foreach (var childField in value.Fields) { AValue convertedChild = convert(childField, ctx); var childFieldName = childField.Descriptor.FieldName; astruct.fields.Add(childFieldName, convertedChild); astruct.correspondingDaiFields.Add(childFieldName, childField); } result = astruct; } } else if (field.ValueType == DAIFieldType.DAI_Array) { var value = field.GetArrayValue(); var aarray = new AArray(); foreach (var memberField in value.Fields) { AValue convertedMember = convert(memberField, ctx); aarray.elements.Add(convertedMember); aarray.correspondingDaiFields.Add(memberField); } result = aarray; } else if (field.ValueType == DAIFieldType.DAI_Guid) { var guid = ctx.file.GetDaiGuidFieldValue(field); if (guid.instanceGuid.Equals("null")) { result = new ANullRef(); } else { if (guid.external) { var aexref = new AExRef(guid.fileGuid, guid.instanceGuid); ctx.extRefs.Add(new Tuple <AExRef, string>(aexref, ctx.instanceGuid)); result = aexref; } else { var ainref = new AIntRef(guid.instanceGuid); ctx.intReferences.Add(new Tuple <AIntRef, string>(ainref, ctx.instanceGuid)); result = ainref; } } } else { String strValue; switch (field.ValueType) { case DAIFieldType.DAI_String: strValue = field.GetStringValue(); break; case DAIFieldType.DAI_Enum: strValue = field.GetEnumValue(); break; case DAIFieldType.DAI_Int: strValue = field.GetIntValue().ToString(); break; case DAIFieldType.DAI_UInt: strValue = field.GetUIntValue().ToString(); break; case DAIFieldType.DAI_Double: case DAIFieldType.DAI_Float: strValue = field.GetFloatValue().ToString(); break; case DAIFieldType.DAI_Short: strValue = field.GetShortValue().ToString(); break; case DAIFieldType.DAI_UShort: strValue = field.GetUShortValue().ToString(); break; case DAIFieldType.DAI_Byte: case DAIFieldType.DAI_UByte: strValue = field.GetByteValue().ToString(); break; case DAIFieldType.DAI_Long: strValue = field.GetLongValue().ToString(); break; case DAIFieldType.DAI_LongLong: strValue = "LL " + DAIEbx.GuidToString(field.GetLongLongValue()); break; case DAIFieldType.DAI_Bool: strValue = field.GetBoolValue().ToString(); break; default: throw new ArgumentOutOfRangeException(); } result = new ASimpleValue(strValue, tryUnhash(strValue)); } return(result); }