Exemple #1
0
        private static void AdjustOffsets_R(TextureDirectory file, int addr)
        {
            //addr contains the real start address relative to the current top-level folder
            foreach (var folder in file.Folders)
            {
                AdjustOffsets_R(folder, folder.Address + addr);
            }
            //quick out; nothing needs to be adjusted
            if (addr == 0)
            {
                return;
            }

            foreach (var texture in file.Textures)
            {
                texture.Address += addr;
            }
        }
Exemple #2
0
        private static Texture FindPalette(ClassHelper source, TextureDirectory sourceDir, ClassHelper current,
                                           SearchField searchField, Texture sourceTexture)
        {
            var sq = (sourceTexture.Format == "ci4") ? 4 : 8;

            //Check for an existing texture in the source db
            Texture find = sourceDir.Textures.SingleOrDefault(x => x.Address == sourceTexture.Palette);

            //if the texture to find is null, create a new one to look for
            if (find == null)
            {
                find = new Texture(sourceTexture.Name + " Palette", 0, "rgb5a1", sq, sq);
            }

            try
            {
                return(FindTexture(source, find, current, searchField));
            }
            catch { }
            return(null);
        }
Exemple #3
0
        private static void DoThings(ClassHelper source, ClassHelper current, Dictionary <string, int> FileAddressPair)
        {
            foreach (var TextureDirectory in source.Data.FileDirectory.Where(x => x.Name == "icon_item_static"))
            {
                int currentAddr;
                int sourceAddr;

                if (!FileAddressPair.TryGetValue(TextureDirectory.Name, out currentAddr))
                {
                    sb.AppendLine($"Folder {TextureDirectory} not found.");
                    continue;
                }
                sb.AppendLine($"Folder: {TextureDirectory.Name}");

                sourceAddr = TextureDirectory.Address;

                source.GetFile(sourceAddr);
                current.GetFile(currentAddr);


                TextureDirectory dir = new TextureDirectory(TextureDirectory.Name,
                                                            current.File.Record.VRom.Start,
                                                            current.File.Record.VRom.Size);

                current.Data.FileDirectory.Add(dir);

                //subdirs processed, find textures within the current dir
                SearchField searchField = new SearchField(0, current.File.Record.VRom.Size);

                Dictionary <int, int?> paletteDictionary = new Dictionary <int, int?>();

                ProcessSubdirectory
                    (source, TextureDirectory,
                    current, dir,
                    searchField, paletteDictionary, true);
            }
        }
Exemple #4
0
        private static void ProcessSubdirectory(ClassHelper source, TextureDirectory sourceDir,
                                                ClassHelper current, TextureDirectory currentDir,
                                                SearchField searchField, Dictionary <int, int?> paletteDictionary, bool top = false)
        {
            //check if any subdirectories exist
            foreach (var subdir in sourceDir.Folders)
            {
                //create a temp subdirectory
                TextureDirectory currentSubDir = new TextureDirectory(subdir.Name, 0, currentDir.Size);
                //attach
                currentDir.Folders.Add(currentSubDir);

                //process subdirectory
                ProcessSubdirectory(source, subdir, current, currentSubDir, searchField, paletteDictionary);

                //all textures are found/loaded into the subfolder.
                //subdir addr/size set
            }

            foreach (var sourceTexture in sourceDir.Textures.OrderBy(x => x.Address))
            {
                Texture foundTexture = null;
                try
                {
                    if (sourceTexture.Format == "jpeg")
                    {
                        foundTexture = FindJpeg(source, sourceTexture, current, searchField);
                    }
                    else
                    {
                        foundTexture = FindTexture(source, sourceTexture, current, searchField);
                    }
                }
                catch { }


                if (foundTexture == null)
                {
                    sb.AppendLine($"Texture: {sourceTexture} not found.");
                }
                else
                {
                    if ((sourceTexture.Format == "ci8" || sourceTexture.Format == "ci4") &&
                        ShouldFindPalette(paletteDictionary, sourceTexture, ref foundTexture))
                    {
                        var foundPalTexture = FindPalette(source, sourceDir, current, searchField, sourceTexture);
                        if (foundPalTexture != null)
                        {
                            paletteDictionary.Add((int)sourceTexture.Palette, foundPalTexture.Address);
                            foundTexture.Palette = foundPalTexture.Address;
                            currentDir.Textures.Add(foundPalTexture);
                        }
                    }
                    currentDir.Textures.Add(foundTexture);
                }
            }

            //needs to re-adjust texture offsets as well. oops.
            ////if not the top node, update current folder address/size
            //if (!top && currentDir.Textures.Count != 0)
            //{
            //    var min = currentDir.Textures.Min(x => x.Address);
            //    var max = currentDir.Textures
            //        .Aggregate((maxVal, x) => x.Address > maxVal.Address ? x : maxVal);

            //    currentDir.Address = min;
            //    currentDir.Size = max.Address + max.Size - min;
            //}
        }