예제 #1
0
        public static async Task SetLocalization(string langCode, bool forceReload)
        {
            StatusBarVm.statusBarViewModel.Set(
                string.Format(Properties.Resources.InternationalizationStatus, Properties.Resources.ResourceManager.GetString(((ELanguage)Properties.Settings.Default.AssetsLanguage).ToString())),
                Properties.Resources.Loading);

            if (forceReload)
            {
                // forceReload is used to clear the current dict
                // that way we don't clear when we load pak files (if dict is null, it's still gonna be filled, else it's not gonna be touched)
                // and we clear after selecting a new language in the settings
                // it also avoid the dict to be cleared then filled twice if user already loaded a pak, change the language, then load a new pak
                if (Text.TypeFaces.NeedReload(forceReload))
                {
                    Text.TypeFaces = new Typefaces();
                }
                Assets.ClearCachedFiles();
                _fortniteLocalizationDict.Clear();
                _hotfixLocalizationDict.Clear();
            }

            // local
            if (_fortniteLocalizationDict.Count <= 0)
            {
                foreach (var fileReader in Globals.CachedPakFiles.Values)
                {
                    foreach (var KvP in fileReader)
                    {
                        Match  m        = null;
                        string mount    = fileReader.MountPoint;
                        string gameName = Folders.GetGameName();
                        if (Globals.Game.ActualGame == EGame.Fortnite)
                        {
                            m = Regex.Match(mount + KvP.Value.Name, $"{gameName}/Content/Localization/Fortnite.*?/{langCode}/Fortnite.*", RegexOptions.IgnoreCase);
                        }
                        else if (Globals.Game.ActualGame == EGame.Valorant)
                        {
                            m = Regex.Match(mount + KvP.Value.Name, $"{gameName}/Content/Localization/Game/{langCode}/Game.locres", RegexOptions.IgnoreCase);
                        }
                        else if (Globals.Game.ActualGame == EGame.DeadByDaylight)
                        {
                            m = Regex.Match(mount + KvP.Value.Name, $"{gameName}/Content/Localization/{gameName}/{langCode}/{gameName}.locres", RegexOptions.IgnoreCase);
                        }
                        else if (Globals.Game.ActualGame == EGame.MinecraftDungeons)
                        {
                            m = Regex.Match(mount + KvP.Value.Name, $"{gameName}/Content/Localization/Game/{langCode}/Game.locres", RegexOptions.IgnoreCase);
                        }
                        else if (Globals.Game.ActualGame == EGame.BattleBreakers)
                        {
                            m = Regex.Match(mount + KvP.Value.Name, $"{gameName}/Content/Localization/Game/{langCode}/Game.locres", RegexOptions.IgnoreCase);
                        }
                        else if (Globals.Game.ActualGame == EGame.Spellbreak)
                        {
                            m = Regex.Match(mount + KvP.Value.Name, $"{gameName}/Content/Localization/Game/{langCode}/Game.locres", RegexOptions.IgnoreCase);
                        }
                        else if (Globals.Game.ActualGame == EGame.StateOfDecay2)
                        {
                            m = Regex.Match(mount + KvP.Value.Name, $"{gameName}/Content/Localization/Game/{langCode}/Game.locres", RegexOptions.IgnoreCase);
                        }
                        else if (Globals.Game.ActualGame == EGame.TheCycleEA)
                        {
                            m = Regex.Match(mount + KvP.Value.Name, $"{gameName}/Content/Localization/ProspectGame/{langCode}/ProspectGame.locres", RegexOptions.IgnoreCase);
                        }

                        if (m != null && m.Success)
                        {
                            DebugHelper.WriteLine("{0} {1} {2} {3}", "[FModel]", "[Localizations]", "[GameDict]", $"Feeding with {KvP.Value.Name} from {KvP.Value.PakFileName} Miam Miam!");

                            using var asset = Assets.GetMemoryStream(fileReader.FileName, mount + KvP.Value.GetPathWithoutExtension());
                            asset.Position  = 0;
                            foreach (var namespac in new LocResReader(asset).Entries)
                            {
                                if (!_fortniteLocalizationDict.ContainsKey(namespac.Key))
                                {
                                    _fortniteLocalizationDict.Add(namespac.Key, new Dictionary <string, string>());
                                }

                                foreach (var key in namespac.Value)
                                {
                                    _fortniteLocalizationDict[namespac.Key][key.Key] = key.Value;
                                }
                            }
                        }
                    }
                }
            }
            // online
            if (_hotfixLocalizationDict.Count <= 0)
            {
                if (Globals.Game.ActualGame == EGame.Fortnite && NetworkInterface.GetIsNetworkAvailable())
                {
                    var hotfix = await Endpoints.GetJsonEndpoint <Dictionary <string, Dictionary <string, string> > >(Endpoints.BENBOT_HOTFIXES, GetLanguageCode()).ConfigureAwait(false);

                    if (hotfix?.Count > 0)
                    {
                        DebugHelper.WriteLine("{0} {1} {2} {3}", "[FModel]", "[Localizations]", "[CloudDict]", "Feeding thank to Paul Baran & Donald Davies");
                        _hotfixLocalizationDict = hotfix;
                    }
                }
            }

            if (forceReload)
            {
                StatusBarVm.statusBarViewModel.Set(
                    string.Format(Properties.Resources.InternationalizationStatus, Properties.Resources.ResourceManager.GetString(((ELanguage)Properties.Settings.Default.AssetsLanguage).ToString())),
                    Properties.Resources.Success);
            }
        }