Exemplo n.º 1
0
        public LodFile Resolve(Heroes3Master master, string fileName)
        {
            List <string> masterResoucesForFile;

            if (!master.NameToFileMap.TryGetValue(fileName.ToLower(), out masterResoucesForFile))
            {
                return(null);
            }
            // if no, exception is thrown

            if (masterResoucesForFile.Count == 1)
            {
                return(master.GetByName(masterResoucesForFile[0]));
            }


            if (ExplicitRules.Count > 0)
            {
                var explicitRule = ExplicitRules.FirstOrDefault(s => string.Compare(fileName, s.FileName, true) == 0);
                if (explicitRule != null)
                {
                    if (explicitRule.ResourseFilePriorities != null && explicitRule.ResourseFilePriorities.Length > 0)
                    {
                        foreach (var rName in explicitRule.ResourseFilePriorities)
                        {
                            if (masterResoucesForFile.Any(s => string.Compare(s, rName, true) == 0))
                            {
                                return(master.GetByName(rName));
                            }
                        }
                    }
                }
            }

            foreach (var defaultResource in DefaultResourcePriorities)
            {
                if (masterResoucesForFile.Any(s => string.Compare(s, defaultResource, true) == 0))
                {
                    return(master.GetByName(defaultResource));
                }
            }

            if (Fallback != null)
            {
                return(Fallback.Resolve(master, fileName));
            }

            //throw new Exception("File: " + fileName + " was not found for routing " + Name);
            return(null);
        }
Exemplo n.º 2
0
        public static Heroes3Master LoadInfo(string executablePath)
        {
            var master = new Heroes3Master();

            master.Executable    = new ExeFile(executablePath);
            master.ResourceFiles = new List <LodFile>();

            master.OriginalDataFolder = Path.Combine(Path.GetDirectoryName(executablePath), "Data");

            master.LoadAllWithExtension(master.OriginalDataFolder, ".lod");
            master.LoadAllWithExtension(master.OriginalDataFolder, ".pac");

            master.BuildMap();
            if (master.GetByName("HotA.lod") != null)
            {
                master.Routing = Routing.Hota;
            }

            master.RefreshData();
            Master = master;
            return(Master);
        }
Exemplo n.º 3
0
        public static void LoadInfo(Heroes3Master master)
        {
            Unload();
            AnyChanges = false;

            var lod1 = master.Resolve(TXT_BIOGRAPHIES_FNAME);

            var lod2 = master.Resolve(H_SPECS);
            var lod3 = master.Resolve(H_HEROES);
            // TO DO: fix this
            var imageLodFile = master.GetByName("h3bitmap.lod");// master.Resolve("HPL000EL.pcx");
            //int index = lodFile.IndexOf("HPL000EL.pcx");
            int index = imageLodFile.IndexOf("HPL000EL.pcx");

            int bound  = imageLodFile.FilesTable.FindLastIndex(index + types.Length * 22, fat => fat.FileName.Contains("HPL"));
            var heroes = new Dictionary <string, List <string> >(types.Length);

            for (int i = index; i < bound; i++)
            {
                List <string> list = null;
                string        end  = imageLodFile[i].FileName.Substring(6, 2);
                if (!heroes.TryGetValue(end, out list))
                {
                    heroes.Add(end, new List <string> {
                        imageLodFile[i].FileName
                    });
                }
                else
                {
                    list.Add(imageLodFile[i].FileName);
                }
            }
            List <string> stringList = new List <string>(types.Length * 16);

            for (int i = 0; i < types.Length; i++)
            {
                stringList.AddRange(heroes[types[i]]);
            }

            HeroesOrder = stringList.ToArray();

            bio_rows  = Encoding.Default.GetString(lod1.GetRawData(TXT_BIOGRAPHIES_FNAME)).Split(new[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
            spec_rows = Encoding.Default.GetString(lod2.GetRawData(H_SPECS)).Split(new[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
            hero_rows = Encoding.Default.GetString(lod3.GetRawData(H_HEROES)).Split(new[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);

            AllHeroes = new List <HeroStats>(HeroesOrder.Length);
            for (int i = 0; i < HeroesOrder.Length; i++)
            {
                string[] traits = hero_rows[2 + i].Split('\t');
                AllHeroes.Add(new HeroStats()
                {
                    Biography   = bio_rows[i],
                    Speciality  = spec_rows[2 + i],
                    CastleIndex = types[i / 16],
                    Name        = traits[0],
                    ImageIndex  = i,
                    LowStack1   = int.Parse(traits[1]),
                    HighStack1  = int.Parse(traits[2]),
                    LowStack2   = int.Parse(traits[4]),
                    HighStack2  = int.Parse(traits[5]),
                    LowStack3   = int.Parse(traits[7]),
                    HighStack3  = int.Parse(traits[8])
                });
            }
        }