Esempio n. 1
0
        public bool Validate(List <EachHero> heroInfo, int count, int processed, int totalCount, int totalFileCount)
        {
            int fileCount   = 0;
            var directories = Directory.GetDirectories(m_dirSamples);

            foreach (var heroDir in directories)
            {
                var dirName = heroDir.Substring(heroDir.LastIndexOf('\\') + 1);
                foreach (var file in Directory.GetFiles(heroDir))
                {
                    fileCount++;

                    PrintLabel(count + " / " + processed + " / " + totalCount + "    " + fileCount + " / " + totalFileCount);
                    using (var bitmap = new Bitmap(file))
                    {
                        var result = HeroIdentifier.Identify(bitmap, heroInfo);
                        if (result.Item1.ToString() != dirName)
                        {
                            return(false);
                        }
                    }
                }
            }

            return(true);
        }
Esempio n. 2
0
 public PlanetView()
 {
     this.mapManipulator   = null;
     this.scaffolding      = new Scaffolding();
     this.targetIdentifier = new TargetIdentifier();
     this.heroIdentifier   = new HeroIdentifier();
     this.spawnProtection  = new SpawnProtectionView();
     this.Reset();
 }
Esempio n. 3
0
        public Tuple <int, double> GetBanHero(int index)
        {
            lock (ImageProcessingHelper.GDILock)
            {
                var      imageUtil = new ImageUtils();
                var      path      = Path.Combine(App.AppPath, "Images\\Heroes");
                var      path2     = string.Format("{0}x{1}", App.AppSetting.Position.Width, App.AppSetting.Position.Height);
                FilePath text      = Path.Combine(path, path2, "Ban",
                                                  string.Format("{0}_{1:yyyyMMddhhmmss}.jpg", index, DateTime.Now));

                if (!text.GetDirPath().Exists)
                {
                    Directory.CreateDirectory(text.GetDirPath());
                }

                using (var bitmap = imageUtil.CaptureBanArea(App.AppSetting.Position.BanPositions[index]))
                {
                    bitmap.Save(text);
                }
                Tuple <int, double> result = null;
                using (var bitmap = new Bitmap(text))
                {
                    var     path1  = Path.Combine(App.AppPath, "Images\\Heroes");
                    var     path12 = string.Format("{0}x{1}", App.AppSetting.Position.Width, App.AppSetting.Position.Height);
                    DirPath text2  = Path.Combine(path1, path12, "Ban\\Out");
                    if (!text2.Exists)
                    {
                        Directory.CreateDirectory(text2);
                    }

                    result = HeroIdentifier.Identify(bitmap);
                    FilePath resultFilePath = Path.Combine(text2, result.Item1 + " " + result.Item2 + ".bmp");
                    if (App.Debug)
                    {
                        bitmap.Save(resultFilePath);
                    }
                }

                if (!App.Debug)
                {
                    text.DeleteIfExists();
                }

                return(result);
            }
        }
Esempio n. 4
0
        public void Check(List <EachHero> heroInfo)
        {
            EnableAllButtons(false);
            var totalCount  = Directory.EnumerateFiles(m_dirSamples, "*.*", SearchOption.AllDirectories).Count();
            int correct     = 0;
            var directories = Directory.GetDirectories(m_dirSamples);

            foreach (var heroDir in directories)
            {
                var dirName = heroDir.Substring(heroDir.LastIndexOf('\\') + 1);
                foreach (var file in Directory.GetFiles(heroDir))
                {
                    using (var bitmap = new Bitmap(file))
                    {
                        var result = HeroIdentifier.Identify(bitmap, heroInfo);
                        if (result.Item1.ToString() == dirName)
                        {
                            correct++;
                        }
                        else
                        {
                            if (!Directory.Exists(m_badSamples + dirName))
                            {
                                Directory.CreateDirectory(m_badSamples + dirName);
                            }

                            File.Copy(file, m_badSamples + dirName + @"\" + file.Substring(file.LastIndexOf('\\') + 1));
                        }

                        PrintLabel(correct + " / " + totalCount);
                    }
                }
            }

            EnableAllButtons(true);
        }
Esempio n. 5
0
        public void Processing(List <EachHero> heroInfo)
        {
            EnableAllButtons(false);
            var  fautyFiles  = new HashSet <string>();
            var  directories = Directory.GetDirectories(m_dirSamples);
            bool done        = true;
            var  totalCount  = Directory.EnumerateFiles(m_dirSamples, "*.*", SearchOption.AllDirectories).Count();
            var  totalPassed = 0;

            do
            {
                var  passed       = 0;
                var  processed    = 0;
                bool freezePassed = false;
                done = true;
                foreach (var heroDir in directories)
                {
                    var dirName = heroDir.Substring(heroDir.LastIndexOf('\\') + 1);
                    foreach (var file in Directory.GetFiles(heroDir))
                    {
                        processed++;
                        PrintLabel(totalPassed + " / " + processed + " / " + totalCount);
                        using (var bitmap = new Bitmap(file))
                        {
                            var result = HeroIdentifier.Identify(bitmap, heroInfo);
                            if (result.Item1.ToString() == dirName)
                            {
                                var resultHero = heroInfo.First(l => l.Id.ToString() == dirName);
                                if (result.Item2 > 3 && resultHero.DHash.Count < 10)
                                {
                                    var hash = HeroIdentifier.GetHash(bitmap);
                                    if (!resultHero.DHash.Contains(hash))
                                    {
                                        resultHero.DHash.Add(hash);
                                    }
                                }

                                if (!freezePassed)
                                {
                                    passed++;
                                    if (passed > totalPassed)
                                    {
                                        totalPassed = passed;
                                    }

                                    PrintLabel(totalPassed + " / " + processed + " / " + totalCount);
                                }

                                continue;
                            }

                            freezePassed = true;

                            if (result.Item1 != 0 && result.Item2 < 5)
                            {
                                fautyFiles.Add(result.Item1 + " : " + file);
                                if (result.Item2 == 0)
                                {
                                    continue;
                                }
                            }

                            var eachHero = heroInfo.FirstOrDefault(l => l.Id.ToString() == dirName);
                            if (eachHero == null)
                            {
                                eachHero = new EachHero()
                                {
                                    Id = int.Parse(dirName)
                                };
                                heroInfo.Add(eachHero);
                            }

                            eachHero.DHash.Add(HeroIdentifier.GetHash(bitmap));

                            done = false;
                        }
                    }
                }
            }while (!done);

            File.WriteAllText(@".\FautyFile.log", string.Join(Environment.NewLine, fautyFiles));

            File.WriteAllText(@".\newHashlist.json", JsonConvert.SerializeObject(heroInfo));

            EnableAllButtons(true);
        }
Esempio n. 6
0
        private void ReadPlayerInfo(BinaryFileReader reader)
        {
            for (int i = 0; i < GameConstants.PLAYER_LIMIT_T; i++)
            {
                PlayerInfo playerInfo = new PlayerInfo();

                Console.WriteLine("Reading Player [" + i.ToString() + "]");

                playerInfo.CanHumanPlay    = reader.ReadBool();
                playerInfo.CanComputerPlay = reader.ReadBool();
                Console.WriteLine("canHumanPlay: " + playerInfo.CanHumanPlay);
                Console.WriteLine("canComputerPlay: " + playerInfo.CanComputerPlay);

                if (!playerInfo.CanHumanPlay && !playerInfo.CanComputerPlay)
                {
                    switch (mapObject.Header.Version)
                    {
                    case EMapFormat.SOD:
                    case EMapFormat.WOG:
                        reader.Skip(13);
                        break;

                    case EMapFormat.AB:
                        reader.Skip(12);
                        break;

                    case EMapFormat.ROE:
                        reader.Skip(6);
                        break;
                    }
                    continue;
                }

                playerInfo.AiTactic = (EAiTactic)reader.ReadUInt8();
                Console.WriteLine("aiTactic:" + playerInfo.AiTactic);

                if (mapObject.Header.Version == EMapFormat.SOD || mapObject.Header.Version == EMapFormat.WOG)
                {
                    playerInfo.P7 = reader.ReadUInt8();
                }
                else
                {
                    playerInfo.P7 = -1;
                }

                Console.WriteLine("p7:" + playerInfo.P7);

                // Reading the Factions for Player
                playerInfo.AllowedFactions = new List <int>();
                int allowedFactionsMask = reader.ReadUInt8();
                Console.WriteLine("allowedFactionsMask:" + allowedFactionsMask);

                int totalFactionCount = GameConstants.F_NUMBER;
                if (mapObject.Header.Version != EMapFormat.ROE)
                {
                    allowedFactionsMask += reader.ReadUInt8() << 8;
                }
                else
                {
                    totalFactionCount--; //exclude conflux for ROE
                }
                for (int fact = 0; fact < totalFactionCount; ++fact)
                {
                    if ((allowedFactionsMask & (1 << fact)) > 0)
                    {
                        playerInfo.AllowedFactions.Add(fact);
                    }
                }

                playerInfo.IsFactionRandom = reader.ReadBool();
                playerInfo.HasMainTown     = reader.ReadBool();
                Console.WriteLine("isFactionRandom:" + playerInfo.IsFactionRandom);
                Console.WriteLine("hasMainTown:" + playerInfo.HasMainTown);

                if (playerInfo.HasMainTown)
                {
                    /// Added in new version, not tested yet
                    if (mapObject.Header.Version != EMapFormat.ROE)
                    {
                        playerInfo.GenerateHeroAtMainTown = reader.ReadBool();
                        playerInfo.GenerateHero           = reader.ReadBool();
                    }
                    else
                    {
                        playerInfo.GenerateHeroAtMainTown = true;
                        playerInfo.GenerateHero           = false;
                    }

                    var townPosition = reader.ReadPosition();
                    Console.WriteLine(string.Format("Main Town Position: {0}, {1}, {2}", townPosition.PosX, townPosition.PosY, townPosition.PosZ));
                    playerInfo.MainTownPosition = townPosition;
                }

                playerInfo.HasRandomHero = reader.ReadBool();
                Console.WriteLine("hasRandomHero:" + playerInfo.HasRandomHero);

                playerInfo.MainCustomHeroId = reader.ReadUInt8();
                Console.WriteLine("mainCustomHeroId:" + playerInfo.MainCustomHeroId);

                if (playerInfo.MainCustomHeroId != 0xff)
                {
                    playerInfo.MainCustomHeroPortrait = reader.ReadUInt8();
                    if (playerInfo.MainCustomHeroPortrait == 0xff)
                    {
                        playerInfo.MainCustomHeroPortrait = -1;
                    }

                    playerInfo.MainCustomHeroName = reader.ReadString();
                    Console.WriteLine("mainCustomHeroPortrait:" + playerInfo.MainCustomHeroPortrait);
                    Console.WriteLine("heroName:" + playerInfo.MainCustomHeroName);
                }
                else
                {
                    playerInfo.MainCustomHeroId = -1;
                }

                if (mapObject.Header.Version != EMapFormat.ROE)
                {
                    playerInfo.PowerPlaceHolders = reader.ReadUInt8();
                    int heroCount = reader.ReadUInt8();
                    reader.Skip(3);

                    playerInfo.HeroIds = new List <HeroIdentifier>();
                    for (int pp = 0; pp < heroCount; ++pp)
                    {
                        HeroIdentifier heroId = new HeroIdentifier();
                        heroId.Id   = reader.ReadUInt8();
                        heroId.Name = reader.ReadString();
                        playerInfo.HeroIds.Add(heroId);
                    }
                }
            }
        }