コード例 #1
0
 public StructColor(ArkArchive archive, ArkName structType) : base(structType)
 {
     B = archive.GetByte();
     G = archive.GetByte();
     R = archive.GetByte();
     A = archive.GetByte();
 }
コード例 #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);
        }
コード例 #3
0
 public override void Init(ArkArchive archive)
 {
     B = archive.ReadByte();
     G = archive.ReadByte();
     R = archive.ReadByte();
     A = archive.ReadByte();
 }
コード例 #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();
                }
            }
        }
コード例 #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;
            }
        }
コード例 #6
0
 public override void WriteBinary(ArkArchive archive)
 {
     archive.WriteFloat(R);
     archive.WriteFloat(G);
     archive.WriteFloat(B);
     archive.WriteFloat(A);
 }
コード例 #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);
                    }
                }
            }
        }
コード例 #8
0
 public PropertyBase(ArkArchive archive, PropertyArgs args)
 {
     Name     = args.Name;
     TypeName = args.TypeName;
     DataSize = archive.GetInt();
     Index    = archive.GetInt();
 }
コード例 #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);
            }
        }
コード例 #10
0
 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;
     }
 }
コード例 #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));
        }
コード例 #12
0
 public override void WriteBinary(ArkArchive archive)
 {
     archive.WriteFloat(X);
     archive.WriteFloat(Y);
     archive.WriteFloat(Z);
     archive.WriteFloat(W);
 }
コード例 #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));
            }
        }
コード例 #14
0
 public override void Init(ArkArchive archive)
 {
     X = archive.ReadFloat();
     Y = archive.ReadFloat();
     Z = archive.ReadFloat();
     W = archive.ReadFloat();
 }
コード例 #15
0
 public StructLinearColor(ArkArchive archive, ArkName structType) : base(structType)
 {
     R = archive.GetFloat();
     G = archive.GetFloat();
     B = archive.GetFloat();
     A = archive.GetFloat();
 }
コード例 #16
0
 public void WriteBinary(ArkArchive archive)
 {
     if (Data != null)
     {
         archive.WriteBytes(Data);
     }
 }
コード例 #17
0
 public override void Init(ArkArchive archive)
 {
     R = archive.ReadFloat();
     G = archive.ReadFloat();
     B = archive.ReadFloat();
     A = archive.ReadFloat();
 }
コード例 #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();
            }
        }
コード例 #19
0
 public StructQuat(ArkArchive archive, ArkName structType) : base(structType)
 {
     X = archive.GetFloat();
     Y = archive.GetFloat();
     Z = archive.GetFloat();
     W = archive.GetFloat();
 }
コード例 #20
0
 public override void WriteBinary(ArkArchive archive)
 {
     archive.WriteByte(B);
     archive.WriteByte(G);
     archive.WriteByte(R);
     archive.WriteByte(A);
 }
コード例 #21
0
 public override void WriteBinary(ArkArchive archive)
 {
     archive.WriteInt(Count);
     foreach (ArkByteValue bv in this)
     {
         archive.WriteName(bv.NameValue);
     }
 }
コード例 #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();
        }
コード例 #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());
            }
        }
コード例 #24
0
        public void WriteBinary(ArkArchive archive)
        {
            archive.WriteName(Name);
            archive.WriteName(Type);
            archive.WriteInt(DataSize);
            archive.WriteInt(Index);

            writeBinaryValue(archive);
        }
コード例 #25
0
        public ArkArrayInt16(ArkArchive archive, int dataSize)
        {
            var size = archive.GetInt();

            for (int n = 0; n < size; n++)
            {
                Add(archive.GetShort());
            }
        }
コード例 #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?
            }
        }
コード例 #27
0
        public ArkArrayBool(ArkArchive archive, int dataSize)
        {
            var size = archive.GetInt();

            for (int n = 0; n < size; n++)
            {
                Add(archive.GetByte() != 0);
            }
        }
コード例 #28
0
        public ArkArrayDouble(ArkArchive archive, int dataSize)
        {
            var size = archive.GetInt();

            for (int n = 0; n < size; n++)
            {
                Add(archive.GetDouble());
            }
        }
コード例 #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?
            }
        }
コード例 #30
0
        public ArkArrayInteger(ArkArchive archive, int dataSize)
        {
            int size = archive.GetInt();

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