예제 #1
0
        public void LoadMugshot(Mugshot sheet, string overrideForm)
        {
            string formDirectory = "Forms/" + overrideForm + "/";

            using (var fileStream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                using (var zipFile = new ZipArchive(fileStream))
                {
                    using (MemoryStream ms = new MemoryStream())
                    {
                        string fullImageString = formDirectory + "Portrait.png";

                        var entry = zipFile.GetEntry(fullImageString);
                        if (entry != null)
                        {
                            using (var entryStream = entry.Open())
                            {
                                entryStream.CopyTo(ms);
                            }

                            ms.Seek(0, SeekOrigin.Begin);

                            sheet.LoadFromData(ms.ToArray());
                        }
                    }
                }
            }
        }
예제 #2
0
        public void LoadMugshot(Mugshot sheet, string overrideForm)
        {
            string formDirectory = "Forms/" + overrideForm + "/";

            using (ZipFile zipFile = ZipFile.Read(path))
            {
                using (MemoryStream ms = new MemoryStream())
                {
                    string fullImageString = formDirectory + "Portrait.png";

                    if (zipFile.ContainsEntry(fullImageString))
                    {
                        zipFile[fullImageString].Extract(ms);

                        ms.Seek(0, SeekOrigin.Begin);

                        sheet.LoadFromData(ms.ToArray());
                    }
                }
            }
        }
예제 #3
0
        public static Mugshot GetMugshot(int num, int form, int shiny, int gender)
        {
            string formString = SpriteXLoader.GetSpriteFormString(form, shiny, gender);

            Mugshot sheet = null;

            lock (mugshotCache)
            {
                sheet = mugshotCache.Get(num + formString);
            }
            if (sheet != null)
            {
                return(sheet);
            }
            // If we are still here, that means the sprite wasn't in the cache
            if (System.IO.File.Exists(IO.Paths.GfxPath + "Mugshots/Portrait" + num + ".zip"))
            {
                sheet = new Mugshot(num, formString);
                string changedFormString = formString;

                SpriteXLoader spriteXLoader = new SpriteXLoader(IO.Paths.GfxPath + "Mugshots/Portrait" + num + ".zip", false);
                List <string> forms         = spriteXLoader.LoadForms();

                using (FileStream fileStream = File.OpenRead(IO.Paths.GfxPath + "Mugshots/Portrait" + num + ".zip"))
                {
                    while (true)
                    {
                        if (mugshotCache.ContainsKey(num + changedFormString))
                        {//this point will be hit if the first fallback data to be found is already in the cache
                         //the cache needs to be updated for aliases, but that's it.  No need to load any new data.

                            sheet = mugshotCache.Get(num + changedFormString);
                            break;
                        }
                        else if (forms.Contains(changedFormString) || changedFormString == "r")
                        {//we've found a spritesheet in the file, so load it.
                            spriteXLoader.LoadMugshot(sheet, changedFormString);

                            mugshotCache.Add(num + changedFormString, sheet);

                            break;
                        }

                        // If the form specified wasn't found, continually revert to the backup until only "r" is reached
                        changedFormString = changedFormString.Substring(0, changedFormString.LastIndexOf('-'));
                    }
                }

                //continually add aliases
                string aliasString = formString;
                while (aliasString != changedFormString)
                {
                    //add aliases here
                    mugshotCache.AddAlias(num + aliasString, num + changedFormString);
                    // If the form specified wasn't found, continually revert to the backup until only "r" is reached
                    aliasString = aliasString.Substring(0, aliasString.LastIndexOf('-'));
                }

                return(sheet);
            }
            else
            {
                return(null);
            }
        }
예제 #4
0
        public static Mugshot GetMugshot(int num, int form, int shiny, int gender)
        {
            string formString = "r";

            if (form >= 0)
            {
                formString += "-" + form;
                if (shiny >= 0)
                {
                    formString += "-" + shiny;
                    if (gender >= 0)
                    {
                        formString += "-" + gender;
                    }
                }
            }

            Mugshot sheet = null;

            lock (mugshotCache)
            {
                sheet = mugshotCache.Get(num + formString);
            }
            if (sheet != null)
            {
                return(sheet);
            }
            // If we are still here, that means the sprite wasn't in the cache
            if (System.IO.File.Exists(IO.Paths.GfxPath + "Mugshots/Portrait" + num + ".portrait"))
            {
                sheet = new Mugshot(num, formString);
                string changedFormString = formString;

                using (FileStream fileStream = File.OpenRead(IO.Paths.GfxPath + "Mugshots/Portrait" + num + ".portrait"))
                {
                    using (BinaryReader reader = new BinaryReader(fileStream))
                    {
                        int formCount = reader.ReadInt32();
                        Dictionary <string, int[]> formData = new Dictionary <string, int[]>();

                        for (int i = 0; i < formCount; i++)
                        {
                            // Read the form name
                            string formName = reader.ReadString();

                            int[] formIntData = new int[2];

                            // Load form position
                            formIntData[0] = reader.ReadInt32();
                            // Load form size
                            formIntData[1] = reader.ReadInt32();

                            // Add form data to collection
                            formData.Add(formName, formIntData);
                        }

                        while (true)
                        {
                            if (mugshotCache.ContainsKey(num + changedFormString))
                            {//this point will be hit if the first fallback data to be found is already in the cache
                             //the cache needs to be updated for aliases, but that's it.  No need to load any new data.

                                sheet = mugshotCache.Get(num + changedFormString);
                                break;
                            }
                            else if (formData.ContainsKey(changedFormString) || changedFormString == "r")
                            {//we've found a spritesheet in the file, so load it.
                                int[] formInt = formData[changedFormString];

                                // Jump to the correct position
                                fileStream.Seek(formInt[0], SeekOrigin.Current);

                                int    frameCount = reader.ReadInt32();
                                int    size       = reader.ReadInt32();
                                byte[] imgData    = reader.ReadBytes(size);

                                sheet.LoadFromData(imgData);

                                mugshotCache.Add(num + changedFormString, sheet);

                                break;
                            }

                            // If the form specified wasn't found, continually revert to the backup until only "r" is reached
                            changedFormString = changedFormString.Substring(0, changedFormString.LastIndexOf('-'));
                        }
                    }
                }

                //continually add aliases
                string aliasString = formString;
                while (aliasString != changedFormString)
                {
                    //add aliases here
                    mugshotCache.AddAlias(num + aliasString, num + changedFormString);
                    // If the form specified wasn't found, continually revert to the backup until only "r" is reached
                    aliasString = aliasString.Substring(0, aliasString.LastIndexOf('-'));
                }

                return(sheet);
            }
            else
            {
                return(null);
            }
        }
예제 #5
0
        public void LoadMugshot(Mugshot sheet, string overrideForm)
        {
            string formDirectory = "Forms/" + overrideForm + "/";

            using (ZipFile zipFile = ZipFile.Read(path))
            {
                using (MemoryStream ms = new MemoryStream())
                {
                    string fullImageString = formDirectory + "Portrait.png";

                    if (zipFile.ContainsEntry(fullImageString))
                    {
                        zipFile[fullImageString].Extract(ms);

                        ms.Seek(0, SeekOrigin.Begin);

                        sheet.LoadFromData(ms.ToArray());
                    }
                }
            }
        }
예제 #6
0
        public static Mugshot GetMugshot(int num, int form, int shiny, int gender)
        {
            string formString = "r";

            if (form >= 0)
            {
                formString += "-" + form;
                if (shiny >= 0)
                {
                    formString += "-" + shiny;
                    if (gender >= 0)
                    {
                        formString += "-" + gender;
                    }
                }
            }

            Mugshot sheet = null;
            lock (mugshotCache)
            {
                sheet = mugshotCache.Get(num + formString);
            }
            if (sheet != null)
            {
                return sheet;
            }
            // If we are still here, that means the sprite wasn't in the cache
            if (System.IO.File.Exists(IO.Paths.GfxPath + "Mugshots/Portrait" + num + ".portrait"))
            {

                sheet = new Mugshot(num, formString);
                string changedFormString = formString;

                using (FileStream fileStream = File.OpenRead(IO.Paths.GfxPath + "Mugshots/Portrait" + num + ".portrait"))
                {
                    using (BinaryReader reader = new BinaryReader(fileStream))
                    {
                        int formCount = reader.ReadInt32();
                        Dictionary<string, int[]> formData = new Dictionary<string, int[]>();

                        for (int i = 0; i < formCount; i++)
                        {
                            // Read the form name
                            string formName = reader.ReadString();

                            int[] formIntData = new int[2];

                            // Load form position
                            formIntData[0] = reader.ReadInt32();
                            // Load form size
                            formIntData[1] = reader.ReadInt32();

                            // Add form data to collection
                            formData.Add(formName, formIntData);
                        }

                        while (true)
                        {
                            if (mugshotCache.ContainsKey(num + changedFormString))
                            {//this point will be hit if the first fallback data to be found is already in the cache
                                //the cache needs to be updated for aliases, but that's it.  No need to load any new data.

                                sheet = mugshotCache.Get(num + changedFormString);
                                break;
                            }
                            else if (formData.ContainsKey(changedFormString) || changedFormString == "r")
                            {//we've found a spritesheet in the file, so load it.
                                int[] formInt = formData[changedFormString];

                                // Jump to the correct position
                                fileStream.Seek(formInt[0], SeekOrigin.Current);

                                int frameCount = reader.ReadInt32();
                                int size = reader.ReadInt32();
                                byte[] imgData = reader.ReadBytes(size);

                                sheet.LoadFromData(imgData);

                                mugshotCache.Add(num + changedFormString, sheet);

                                break;
                            }

                            // If the form specified wasn't found, continually revert to the backup until only "r" is reached
                            changedFormString = changedFormString.Substring(0, changedFormString.LastIndexOf('-'));
                        }
                    }
                }

                //continually add aliases
                string aliasString = formString;
                while (aliasString != changedFormString)
                {
                    //add aliases here
                    mugshotCache.AddAlias(num + aliasString, num + changedFormString);
                    // If the form specified wasn't found, continually revert to the backup until only "r" is reached
                    aliasString = aliasString.Substring(0, aliasString.LastIndexOf('-'));
                }

                return sheet;
            }
            else
            {
                return null;
            }
        }
예제 #7
0
        public static Mugshot GetMugshot(int num, int form, int shiny, int gender)
        {
            string formString = SpriteXLoader.GetSpriteFormString(form, shiny, gender);

            Mugshot sheet = null;
            lock (mugshotCache)
            {
                sheet = mugshotCache.Get(num + formString);
            }
            if (sheet != null)
            {
                return sheet;
            }
            // If we are still here, that means the sprite wasn't in the cache
            if (System.IO.File.Exists(IO.Paths.GfxPath + "Mugshots/Portrait" + num + ".zip"))
            {

                sheet = new Mugshot(num, formString);
                string changedFormString = formString;

                SpriteXLoader spriteXLoader = new SpriteXLoader(IO.Paths.GfxPath + "Mugshots/Portrait" + num + ".zip", false);
                List<string> forms = spriteXLoader.LoadForms();

                using (FileStream fileStream = File.OpenRead(IO.Paths.GfxPath + "Mugshots/Portrait" + num + ".zip"))
                {
                    while (true)
                    {
                        if (mugshotCache.ContainsKey(num + changedFormString))
                        {//this point will be hit if the first fallback data to be found is already in the cache
                            //the cache needs to be updated for aliases, but that's it.  No need to load any new data.

                            sheet = mugshotCache.Get(num + changedFormString);
                            break;
                        }
                        else if (forms.Contains(changedFormString) || changedFormString == "r")
                        {//we've found a spritesheet in the file, so load it.
                            spriteXLoader.LoadMugshot(sheet, changedFormString);

                            mugshotCache.Add(num + changedFormString, sheet);

                            break;
                        }

                        // If the form specified wasn't found, continually revert to the backup until only "r" is reached
                        changedFormString = changedFormString.Substring(0, changedFormString.LastIndexOf('-'));
                    }
                }

                //continually add aliases
                string aliasString = formString;
                while (aliasString != changedFormString)
                {
                    //add aliases here
                    mugshotCache.AddAlias(num + aliasString, num + changedFormString);
                    // If the form specified wasn't found, continually revert to the backup until only "r" is reached
                    aliasString = aliasString.Substring(0, aliasString.LastIndexOf('-'));
                }

                return sheet;
            }
            else
            {
                return null;
            }
        }