Exemplo n.º 1
0
 public StructColor(ArkArchive archive, ArkName structType) : base(structType)
 {
     B = archive.GetByte();
     G = archive.GetByte();
     R = archive.GetByte();
     A = archive.GetByte();
 }
Exemplo n.º 2
0
        public static T ReadBinary <T>(this IConversionSupport conversionSupport, string filePath, ReadingOptions readingOptions) where T : IConversionSupport
        {
            if (new FileInfo(filePath).Length > int.MaxValue)
            {
                throw new Exception("Input file is too large.");
            }

            Stream stream;

            if (readingOptions.UsesMemoryMapping)
            {
                MemoryMappedFile memoryMappedFile = MemoryMappedFile.CreateFromFile(filePath);
                stream = memoryMappedFile.CreateViewStream();
            }
            else
            {
                stream = new MemoryStream(File.ReadAllBytes(filePath));
            }

            using (ArkArchive archive = new ArkArchive(stream)) {
                conversionSupport.ReadBinary(archive, readingOptions);
            }

            return((T)conversionSupport);
        }
Exemplo n.º 3
0
 public override void Init(ArkArchive archive)
 {
     B = archive.ReadByte();
     G = archive.ReadByte();
     R = archive.ReadByte();
     A = archive.ReadByte();
 }
Exemplo n.º 4
0
        //public int getSize(bool nameTable)
        //{
        //    return _fromEnum ? ArkArchive.GetNameLength(_nameValue, nameTable) : 1;
        //}

        public void read(ArkArchive archive, ArkName enumName, bool propertyIsExcluded = false)
        {
            _enumName = enumName;
            _fromEnum = !enumName.Equals(ArkName.NONE_NAME);
            if (propertyIsExcluded)
            {
                if (_fromEnum)
                {
                    archive.SkipName();
                }
                else
                {
                    archive.Position += 1;
                }
            }
            else
            {
                if (_fromEnum)
                {
                    _nameValue = archive.GetName();
                }
                else
                {
                    _byteValue = archive.GetByte();
                }
            }
        }
Exemplo n.º 5
0
        private void readBinary(ArkArchive archive)
        {
            if (Length >= 8)
            {
                ObjectType = archive.ReadInt();
                switch (ObjectType)
                {
                case TypeId:
                    ObjectId = archive.ReadInt();
                    break;

                case TypePath:
                    ObjectString = archive.ReadName();
                    break;

                default:
                    archive.Position = archive.Position - 4;
                    ObjectType       = TypePathNoType;
                    ObjectString     = archive.ReadName();
                    break;
                }
            }
            else if (Length == 4)
            {
                // Only seems to happen in Version 5
                ObjectType = TypeId;
                ObjectId   = archive.ReadInt();
            }
            else
            {
                Debug.WriteLine($"Warning: ObjectReference with length value {Length} at {archive.Position:X}");
                archive.Position = archive.Position + Length;
            }
        }
 public override void WriteBinary(ArkArchive archive)
 {
     archive.WriteFloat(R);
     archive.WriteFloat(G);
     archive.WriteFloat(B);
     archive.WriteFloat(A);
 }
Exemplo n.º 7
0
        public static void WriteBinary(this IConversionSupport conversionSupport, string filePath, WritingOptions writingOptions)
        {
            int size = conversionSupport.CalculateSize();

            Stream stream;

            if (writingOptions.UsesMemoryMapping)
            {
                File.Create(filePath).Dispose();
                MemoryMappedFile memoryMappedFile = MemoryMappedFile.CreateFromFile(filePath, FileMode.Open, null, size, MemoryMappedFileAccess.Write);
                stream = memoryMappedFile.CreateViewStream();
            }
            else
            {
                stream = new MemoryStream(new byte[size], true);
            }

            using (ArkArchive archive = new ArkArchive(stream)) {
                conversionSupport.WriteBinary(archive, writingOptions);

                if (!writingOptions.UsesMemoryMapping)
                {
                    using (FileStream file = File.Create(filePath)) {
                        stream.Position = 0;
                        stream.CopyTo(file);
                    }
                }
            }
        }
Exemplo n.º 8
0
 public PropertyBase(ArkArchive archive, PropertyArgs args)
 {
     Name     = args.Name;
     TypeName = args.TypeName;
     DataSize = archive.GetInt();
     Index    = archive.GetInt();
 }
Exemplo n.º 9
0
        public override void Init(ArkArchive archive, ArkName name)
        {
            base.Init(archive, name);

            ArkName arrayType = archive.ReadName();

            long position = archive.Position;

            try {
                Value = ArkArrayRegistry.ReadBinary(archive, arrayType, this);

                if (Value == null)
                {
                    throw new UnreadablePropertyException("ArkArrayRegistry returned null");
                }
            } catch (UnreadablePropertyException upe) {
                archive.Position = position;

                Value = new ArkArrayUnknown(archive, DataSize, arrayType);

                archive.HasUnknownNames = true;
                Debug.WriteLine($"Reading ArrayProperty of type {arrayType} with name {name} as byte blob because:");
                Debug.WriteLine(upe.Message);
                Debug.WriteLine(upe.StackTrace);
            }
        }
 public void Read(ArkArchive archive)
 {
     if (Length >= 8)
     {
         ObjectType = archive.GetInt();
         if (ObjectType == TYPE_ID)
         {
             ObjectId = archive.GetInt();
         }
         else if (ObjectType == TYPE_PATH)
         {
             ObjectString = archive.GetName();
         }
         else
         {
             //No longer used: ObjectReference with possibly unknown type {objectType} at {archive.Position:X};
             archive.Position -= 4;
             ObjectType        = TYPE_PATH_NO_TYPE;
             ObjectString      = archive.GetName();
         }
     }
     else if (Length == 4)
     {
         // Only seems to happen in Version 5
         ObjectType = TYPE_ID;
         ObjectId   = archive.GetInt();
     }
     else
     {
         _logger.Warn($"ObjectReference with length value {Length} at {archive.Position:X}");
         archive.Position += Length;
     }
 }
Exemplo n.º 11
0
        public static IProperty ReadBinary(ArkArchive archive)
        {
            ArkName name = archive.ReadName();

            if (name == null || string.IsNullOrEmpty(name.ToString()))
            {
                archive.HasUnknownData = true;
                throw new UnreadablePropertyException(
                          $"Property name is {(name == null ? "null" : "empty")}, indicating a corrupt file. Ignoring remaining properties.");
            }

            if (name == ArkName.NameNone)
            {
                return(null);
            }

            ArkName type = archive.ReadName();

            if (type != null && typeMap.TryGetValue(type, out PropertyConstructor constructor))
            {
                return(constructor.BinaryConstructor(archive, name));
            }

            archive.DebugMessage($"Unknown property type {name}");
            archive.HasUnknownNames = true;
            return(new PropertyUnknown(archive, name));
        }
Exemplo n.º 12
0
 public override void WriteBinary(ArkArchive archive)
 {
     archive.WriteFloat(X);
     archive.WriteFloat(Y);
     archive.WriteFloat(Z);
     archive.WriteFloat(W);
 }
Exemplo n.º 13
0
        public override void Init(ArkArchive archive, PropertyArray property)
        {
            int size = archive.ReadInt();

            ArkName structType = StructRegistry.MapArrayNameToTypeName(property.Name);

            if (structType == null)
            {
                if (size * 4 + 4 == property.DataSize)
                {
                    structType = color;
                }
                else if (size * 12 + 4 == property.DataSize)
                {
                    structType = vector;
                }
                else if (size * 16 + 4 == property.DataSize)
                {
                    structType = linearColor;
                }
            }

            for (int n = 0; n < size; n++)
            {
                Add(StructRegistry.ReadBinary(archive, structType));
            }
        }
Exemplo n.º 14
0
 public override void Init(ArkArchive archive)
 {
     X = archive.ReadFloat();
     Y = archive.ReadFloat();
     Z = archive.ReadFloat();
     W = archive.ReadFloat();
 }
 public StructLinearColor(ArkArchive archive, ArkName structType) : base(structType)
 {
     R = archive.GetFloat();
     G = archive.GetFloat();
     B = archive.GetFloat();
     A = archive.GetFloat();
 }
Exemplo n.º 16
0
 public void WriteBinary(ArkArchive archive)
 {
     if (Data != null)
     {
         archive.WriteBytes(Data);
     }
 }
 public override void Init(ArkArchive archive)
 {
     R = archive.ReadFloat();
     G = archive.ReadFloat();
     B = archive.ReadFloat();
     A = archive.ReadFloat();
 }
Exemplo n.º 18
0
        public PropertyArray(ArkArchive archive, PropertyArgs args, bool propertyIsExcluded = false) : base(archive, args, propertyIsExcluded)
        {
            if (propertyIsExcluded)
            {
                archive.SkipName();
                archive.Position += DataSize;
                return;
            }

            ArrayType = archive.GetName();

            var position = archive.Position;

            try
            {
                _value = ArkArrayRegistry.read(archive, ArrayType, DataSize);

                if (_value == null)
                {
                    throw new UnreadablePropertyException();
                }
            }
            catch (UnreadablePropertyException)
            {
                archive.Position += DataSize;
                _logger.Error($"Unreadable ArrayProperty with name {Name}, skipping.");
                throw new UnreadablePropertyException();
            }
        }
Exemplo n.º 19
0
 public StructQuat(ArkArchive archive, ArkName structType) : base(structType)
 {
     X = archive.GetFloat();
     Y = archive.GetFloat();
     Z = archive.GetFloat();
     W = archive.GetFloat();
 }
Exemplo n.º 20
0
 public override void WriteBinary(ArkArchive archive)
 {
     archive.WriteByte(B);
     archive.WriteByte(G);
     archive.WriteByte(R);
     archive.WriteByte(A);
 }
Exemplo n.º 21
0
 public override void WriteBinary(ArkArchive archive)
 {
     archive.WriteInt(Count);
     foreach (ArkByteValue bv in this)
     {
         archive.WriteName(bv.NameValue);
     }
 }
Exemplo n.º 22
0
        //public long Size
        //{
        //    get
        //    {
        //        return Float.BYTES * 6;
        //    }
        //}

        public void read(ArkArchive archive)
        {
            X     = archive.GetFloat();
            Y     = archive.GetFloat();
            Z     = archive.GetFloat();
            Pitch = archive.GetFloat();
            Yaw   = archive.GetFloat();
            Roll  = archive.GetFloat();
        }
Exemplo n.º 23
0
        //private static long serialVersionUID = 1L;

        public override void Init(ArkArchive archive, PropertyArray property)
        {
            int size = archive.ReadInt();

            for (int n = 0; n < size; n++)
            {
                Add(archive.ReadShort());
            }
        }
Exemplo n.º 24
0
        public void WriteBinary(ArkArchive archive)
        {
            archive.WriteName(Name);
            archive.WriteName(Type);
            archive.WriteInt(DataSize);
            archive.WriteInt(Index);

            writeBinaryValue(archive);
        }
Exemplo n.º 25
0
        public ArkArrayInt16(ArkArchive archive, int dataSize)
        {
            var size = archive.GetInt();

            for (int n = 0; n < size; n++)
            {
                Add(archive.GetShort());
            }
        }
Exemplo n.º 26
0
        public ArkArrayObjectReference(ArkArchive archive, int dataSize)
        {
            var size = archive.GetInt();

            for (int n = 0; n < size; n++)
            {
                Add(new ObjectReference(archive, 8)); // Fixed size?
            }
        }
Exemplo n.º 27
0
        public ArkArrayBool(ArkArchive archive, int dataSize)
        {
            var size = archive.GetInt();

            for (int n = 0; n < size; n++)
            {
                Add(archive.GetByte() != 0);
            }
        }
Exemplo n.º 28
0
        public ArkArrayDouble(ArkArchive archive, int dataSize)
        {
            var size = archive.GetInt();

            for (int n = 0; n < size; n++)
            {
                Add(archive.GetDouble());
            }
        }
Exemplo n.º 29
0
        //private static long serialVersionUID = 1L;

        public override void Init(ArkArchive archive, PropertyArray property)
        {
            int size = archive.ReadInt();

            for (int n = 0; n < size; n++)
            {
                Add(new ObjectReference(archive, 8)); // Fixed size?
            }
        }
Exemplo n.º 30
0
        public ArkArrayInteger(ArkArchive archive, int dataSize)
        {
            int size = archive.GetInt();

            for (int n = 0; n < size; n++)
            {
                Add(archive.GetInt());
            }
        }