Example #1
0
        public void Read(DecimaCoreFile file, DecimaManagerCollection manager)
        {
            // ReSharper disable once MergeConditionalExpression
            var streamData = StreamData == default ? Span <byte> .Empty : StreamData.Data.Span.Slice(0, StreamedImageSize);

            Data = new TextureBase(ImageData, streamData, Format, Width & 0xFFF, Height & 0xFFF, TotalMips, StreamedMips);
        }
        public static Array ReadData(DecimaCoreFile data, Type propertyType, DecimaManagerCollection managers, long count)
        {
            if (propertyType.IsPrimitive || propertyType.IsEnum || propertyType.IsValueType)
            {
                return(StreamHelper.Read(propertyType, data, count));
            }


            if (propertyType.FullName == "System.Guid")
            {
                var guidData  = StreamHelper.ReadData(data, count * 0x10);
                var guidArray = new Guid[count];
                for (var i = 0; i < count; ++i)
                {
                    guidArray[i] = new Guid(guidData.Slice(i * 0x10, 0x10));
                }
                return(guidArray);
            }

            Debug.Assert(typeof(IComplexStruct).IsAssignableFrom(propertyType), "typeof(IComplexStruct).IsAssignableFrom(propertyType)");

            var instArray = Array.CreateInstance(propertyType, count);

            for (var i = 0; i < count; ++i)
            {
                var inst = Activator.CreateInstance(propertyType);
                instArray.SetValue(Read(inst, propertyType, data, managers), i);
            }

            return(instArray);
        }
Example #3
0
 /// <summary>
 /// </summary>
 /// <param name="data"></param>
 /// <param name="managers"></param>
 /// <exception cref="InvalidDataException"></exception>
 public void Work(DecimaCoreFile data, DecimaManagerCollection managers)
 {
     if (data.FileType != DecimaFileTypeMagic.Texture)
     {
         throw new InvalidDataException("This is not a texture file");
     }
     Core = data;
 }
 public DecimaCoreFile GetRef(DecimaManagerCollection manager)
 {
     Managers = manager;
     if (RefData == default)
     {
         if (string.IsNullOrWhiteSpace(RefFile))
         {
             return(default);
 public void Work(DecimaCoreFile data, DecimaManagerCollection managers)
 {
     if (data.FileType != DecimaFileTypeMagic.GameSettings)
     {
         throw new InvalidDataException("This is not a game settings file");
     }
     Core = data;
 }
 public virtual void Work(DecimaCoreFile data, DecimaManagerCollection managers)
 {
     if (data.FileType != DecimaFileTypeMagic.LevelProperty)
     {
         throw new InvalidDataException("This is not a level property file");
     }
     Core = data;
 }
 public void Work(DecimaCoreFile data, DecimaManagerCollection managers)
 {
     if (data.FileType != DecimaFileTypeMagic.DrawableMapTiles)
     {
         throw new InvalidDataException("This is not a drawable map tiles file");
     }
     Core = data;
 }
 public void Read(DecimaCoreFile file, DecimaManagerCollection manager)
 {
     TextureData.ElementAt(0).Data.Name = Name1;
     if (TextureData.Length == 2)
     {
         TextureData.ElementAt(1).Data.Name = Name2;
     }
     Textures = TextureData.Select(x => x.Data).ToArray();
 }
        public static object Read(object instance, Type type, DecimaCoreFile data, DecimaManagerCollection managers)
        {
            var allProperties = GetTypeInfoAll(type);
            var properties    = GetTypeInfo(type);

            foreach (var(name, property) in properties)
            {
                var propertyType = property.PropertyType;
                var info         = GetInfo(property);
                if (info?.Conditional != default && allProperties.TryGetValue(info.Conditional, out var conditionalProperty))
                {
                    if (Convert.ToUInt64(conditionalProperty.GetValue(instance)) == 0)
                    {
                        continue;
                    }
                }
                if (propertyType.IsArray || propertyType.FullName == "System.String")
                {
                    if (info == null)
                    {
                        throw new InvalidOperationException($"{type.FullName}.{name} is trying to load an array without {nameof(ComplexInfoAttribute)}");
                    }
                    var count = info.Count;
                    if (count == 0)
                    {
                        if (!allProperties.TryGetValue(info.FieldName, out var sizeProperty))
                        {
                            throw new InvalidOperationException($"{type.FullName}.{name} is trying to load an array with dynamic size property ");
                        }

                        count = Convert.ToInt64(sizeProperty.GetValue(instance));
                    }

                    if (propertyType.FullName == "System.String")
                    {
                        property.SetValue(instance, Encoding.UTF8.GetString(ReadData(info.FromUnknownData ? data.Unknown1 : data, typeof(byte), managers, count).Cast <byte>().ToArray()));
                    }
                    else
                    {
                        property.SetValue(instance, ReadData(info.FromUnknownData ? data.Unknown1 : data, propertyType.GetElementType(), managers, count));
                    }
                }
                else
                {
                    property.SetValue(instance, ReadData(info?.FromUnknownData == true ? data.Unknown1 : data, propertyType, managers, 1).GetValue(0));
                }
            }

            if (instance is IComplexStruct @struct)
            {
                @struct.Read(data, managers);
            }

            return(instance);
        }
 /// <summary>
 ///     Load prefetch data by stream
 /// </summary>
 /// <param name="data"></param>
 /// <param name="managers"></param>
 /// <exception cref="InvalidDataException">when data magic does not match file type</exception>
 public void Work(DecimaCoreFile data, DecimaManagerCollection managers)
 {
     if (IsValid)
     {
         return;
     }
     if (data.FileType != DecimaFileTypeMagic.Prefetch)
     {
         throw new InvalidDataException("This is not a prefetch file");
     }
     Core = data;
 }
Example #11
0
        public static T ToStructured <T>(this IEnumerable <DecimaCoreFile> array, DecimaManagerCollection managers) where T : IDecimaStructuredFile
        {
            if (DecimaFileTypeFactory.TypeMapReverse == default)
            {
                DecimaFileTypeFactory.LoadTypes();
            }

            if (DecimaFileTypeFactory.TypeMapReverse == default)
            {
                throw new InvalidOperationException("Failed to load types");
            }

            if (!DecimaFileTypeFactory.TypeMapReverse.TryGetValue(typeof(T), out var fileType))
            {
                return(default);
Example #12
0
        public void Read(DecimaCoreFile file, DecimaManagerCollection manager)
        {
            var entriesActual = new List <DecimaCoreFileRef <IDecimaStructuredFile> >();

            foreach (var entry in EntryRefsOriginal)
            {
                if (entry.LoadMethod == DecimaCoreLoadMethod.ImmediateCoreFile && entry.Ref?.FileType == DecimaFileTypeMagic.Collection)
                {
                    entriesActual.AddRange(entry.Ref.ToStructured <DecimaCollection>(manager).EntryRefs);
                }
                else
                {
                    entriesActual.Add(entry);
                }
            }
            EntryRefs = entriesActual.ToArray();

            Entries = EntryRefs.Select(x => x.GetStruct(manager)).ToArray();
        }
        public void Read(DecimaCoreFile file, DecimaManagerCollection manager)
        {
            Managers = manager;
            switch (LoadMethod)
            {
            case DecimaCoreLoadMethod.WorkOnly:
            case DecimaCoreLoadMethod.NotPresent:
                break;

            case DecimaCoreLoadMethod.Embedded:
                RefData = file.Split().FirstOrDefault(x => x.Checksum == Checksum);
                Debug.Assert(RefData != default, "Ref != default", nameof(DecimaCoreLoadMethod.Embedded));
                break;

            case DecimaCoreLoadMethod.ImmediateCoreFile:
            case DecimaCoreLoadMethod.CoreFile:
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Example #14
0
 public void Read(DecimaCoreFile file, DecimaManagerCollection manager)
 {
     TextureData.Data.Name = Name;
     Textures = new[] { TextureData.Data };
 }
Example #15
0
        private static void Main()
        {
            var manager = new DecimaManagerCollection();

            InteractivePrompt.Run((cmd, list, completions) =>
            {
                try
                {
                    var args           = CmdToArgs(cmd);
                    var argsEnumerable = args as string[] ?? args.ToArray();
                    var command        = argsEnumerable.FirstOrDefault()?.ToLower();
                    switch (command)
                    {
                    case "exit":
                    case "quit":
                        manager.Clean();
                        Environment.Exit(0);
                        break;

                    case "unload":
                        manager.Clean();
                        return("Unloaded." + Environment.NewLine);

                    case "load":
                        {
                            var path = argsEnumerable.ElementAtOrDefault(1) ?? Environment.GetEnvironmentVariable("HZD_PACKED_PINK");
                            if (string.IsNullOrWhiteSpace(path))
                            {
                                return($@"Usage: {command} C:\Path" + Environment.NewLine);
                            }

                            var cache = manager.GetOrCreateManager <DecimaCacheManager>();
                            if (cache.Prefetch.IsValid)
                            {
                                return("Already loaded" + Environment.NewLine);
                            }
                            cache.LoadCaches(path);
                            cache.GenerateFileMap();
                            cache.LoadPrefetch(manager);
                            return("Loaded." + Environment.NewLine);
                        }

                    case "search-term":
                        {
                            var term = argsEnumerable.ElementAtOrDefault(1);
                            return(string.Join(Environment.NewLine, manager.GetOrCreateManager <DecimaCacheManager>().Prefetch.Names.Where(x => x.Text.Contains(term))) + Environment.NewLine);
                        }

                    case "test-03":
                        {
                            var path = argsEnumerable.ElementAtOrDefault(1);
                            if (string.IsNullOrWhiteSpace(path))
                            {
                                return($@"Usage: {command} C:\Path" + Environment.NewLine);
                            }

                            if (!manager.GetOrCreateManager <DecimaCacheManager>().Prefetch.IsValid)
                            {
                                return(@"Run load C:\Path first" + Environment.NewLine);
                            }
                            SaveMapTiles(manager, path);
                            break;
                        }

                    case "test-04":
                        {
                            var path = argsEnumerable.ElementAtOrDefault(1);
                            if (string.IsNullOrWhiteSpace(path))
                            {
                                return($@"Usage: {command} C:\Path" + Environment.NewLine);
                            }

                            if (!manager.GetOrCreateManager <DecimaCacheManager>().Prefetch.IsValid)
                            {
                                return(@"Run load C:\Path first" + Environment.NewLine);
                            }
                            SaveUserInterfaceTex(manager, path);
                            break;
                        }

                    case "split-core":
                        {
                            var path = argsEnumerable.ElementAtOrDefault(1);
                            if (string.IsNullOrWhiteSpace(path))
                            {
                                return($@"Usage: {command} C:\Path.core C:\OutPath" + Environment.NewLine);
                            }
                            var outPath = argsEnumerable.ElementAtOrDefault(2);
                            if (string.IsNullOrWhiteSpace(path))
                            {
                                return($@"Usage: {command} {$"\"{path}\""} C:\OutPath" + Environment.NewLine);
                            }
                            DumpCore(path, outPath);
                            break;
                        }

                    case "open-core":
                        {
                            var path = argsEnumerable.ElementAtOrDefault(1);
                            if (string.IsNullOrWhiteSpace(path))
                            {
                                return($@"Usage: {command} C:\Path.core" + Environment.NewLine);
                            }
                            using (var stream = File.OpenRead(path))
                                using (var core = new DecimaCoreFile(stream))
                                {
                                    foreach (var c in core.Split())
                                    {
                                        c.ToStructured(manager);
                                    }
                                }

                            break;
                        }

                    case "save-type":
                        {
                            void SaveTypeM(CoreTuple tuple, ISet <long> hashSet, DecimaCacheManager decimaCacheManager, string s)
                            {
                                var(masterCore, hash, text) = tuple;
                                if (masterCore == default)
                                {
                                    return;
                                }
                                hashSet.Add(hash);
                                hashSet.Add(decimaCacheManager.GetFileHash(text + ".stream"));
                                var cores = masterCore.Split();

                                foreach (var(core, i) in cores.WithIndex())
                                {
                                    var dest = Path.Combine(s, core.FileTypeProxy, text);
                                    if (!Directory.Exists(dest))
                                    {
                                        Directory.CreateDirectory(dest);
                                    }

                                    var target = Path.Combine(dest, $"{i:X}_{core.Checksum:N}.core");

                                    Logger.Log24Bit(ConsoleSwatch.XTermColor.OrangeRed, true, Console.Out, default, $"{target}... ");
                                    using (var stream = File.OpenWrite(target))
                                    {
                                        stream.SetLength(0);
                                        core.Dump(stream);
                                    }
                                }
                            }

                            var done  = new HashSet <long>();
                            var cache = manager.GetOrCreateManager <DecimaCacheManager>();
                            if (!cache.Prefetch.IsValid)
                            {
                                return(@"Run load C:\Path first" + Environment.NewLine);
                            }
                            var path = argsEnumerable.ElementAtOrDefault(1);
                            if (string.IsNullOrWhiteSpace(path))
                            {
                                return($@"Usage: {command} C:\Path.core" + Environment.NewLine);
                            }
                            foreach (var prefetchPath in cache.Prefetch)
                            {
                                Logger.Log24Bit(ConsoleSwatch.XTermColor.White, true, Console.Out, default, $"extracting {prefetchPath}... ");
 public void Read(DecimaCoreFile file, DecimaManagerCollection manager)
 {
     IsValid = true;
 }
        /// <summary>
        ///     Open Structured File by <paramref name="fileType" />
        /// </summary>
        /// <param name="file"></param>
        /// <param name="fileType"></param>
        /// <param name="managers"></param>
        /// <returns>
        ///     <see cref="IDecimaStructuredFile" />
        /// </returns>
        /// <exception cref="InvalidOperationException"></exception>
        private static IDecimaStructuredFile OpenFile(DecimaCoreFile file, DecimaFileTypeMagic fileType, DecimaManagerCollection managers)
        {
            if (TypeMap == default)
            {
                LoadTypes();
            }

            if (TypeMap == default)
            {
                throw new InvalidOperationException("Failed to load types");
            }

            if (!TypeMap.TryGetValue(fileType, out var type))
            {
                return(default);
 /// <summary>
 ///     Open Structured File <typeparamref name="T" /> by Core File
 /// </summary>
 /// <param name="file"></param>
 /// <param name="managers"></param>
 /// <typeparam name="T">
 ///     <see cref="IDecimaStructuredFile" />
 /// </typeparam>
 /// <returns>
 ///     <see cref="IDecimaStructuredFile" />
 /// </returns>
 public static T OpenFile <T>(DecimaCoreFile file, DecimaManagerCollection managers) where T : IDecimaStructuredFile
 {
     return(OpenFile <T>(file, file.FileType, managers));
 }
Example #19
0
 public void Read(DecimaCoreFile file, DecimaManagerCollection manager)
 {
     Debug.Assert(Unknown == "", "Unknown == ''");
 }
 public T GetStruct(DecimaManagerCollection managers)
 {
     Managers = managers;
     return(Ref?.ToStructured(managers) as T);
 }
Example #21
0
 public void Read(DecimaCoreFile file, DecimaManagerCollection manager)
 {
 }
 /// <summary>
 ///     Open Structured File by Core File
 /// </summary>
 /// <param name="file"></param>
 /// <param name="managers"></param>
 /// <returns>
 ///     <see cref="IDecimaStructuredFile" />
 /// </returns>
 public static IDecimaStructuredFile OpenFile(DecimaCoreFile file, DecimaManagerCollection managers)
 {
     return(OpenFile(file, file.FileType, managers));
 }