Exemplo n.º 1
0
        public static string FixPath(string path)
        {
            if (string.IsNullOrWhiteSpace(path))
            {
                return(string.Empty);
            }

            string trigger;
            {
                string tempPath = path.Substring(1);
                trigger = tempPath.Substring(0, tempPath.IndexOf("/"));
            }

            Regex regex = new Regex(trigger);

            if (trigger.Equals("SrirachaRanch"))
            {
                trigger += $"/{trigger}Core";
            }

            string fixedPath = trigger switch
            {
                "Game" => regex.Replace(path, $"{Folders.GetGameName()}/Content", 1),
                "RegionCN" => regex.Replace(path, $"{Folders.GetGameName()}/Plugins/{trigger}/Content", 1),
                _ => regex.Replace(path, $"{Folders.GetGameName()}/Plugins/GameFeatures/{trigger}/Content", 1)
            };

            int sep = fixedPath.LastIndexOf('.');

            return(fixedPath.Substring(0, sep > 0 ? sep : fixedPath.Length));
        }
    }
Exemplo n.º 2
0
        public static string FixPath(string path)
        {
            if (string.IsNullOrWhiteSpace(path))
            {
                return(string.Empty);
            }

            Regex  regexGame = new Regex(Regex.Escape("Game"));
            string fixedPath = regexGame.Replace(path, $"{Folders.GetGameName()}/Content", 1);
            int    sep       = fixedPath.LastIndexOf('.');

            return(fixedPath.Substring(0, sep > 0 ? sep : fixedPath.Length));
        }
Exemplo n.º 3
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;
                        if (Globals.Game == EGame.Fortnite)
                        {
                            m = Regex.Match(mount + KvP.Value.Name, $"{Folders.GetGameName()}/Content/Localization/Fortnite.*?/{langCode}/Fortnite.*", RegexOptions.IgnoreCase);
                        }
                        else if (Globals.Game == EGame.Valorant)
                        {
                            m = Regex.Match(mount + KvP.Value.Name, $"{Folders.GetGameName()}/Content/Localization/Game/{langCode}/Game.locres", RegexOptions.IgnoreCase);
                        }

                        if (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(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].Add(key.Key, key.Value);
                                }
                            }
                        }
                    }
                }
            }
            // online
            if (_hotfixLocalizationDict.Count <= 0)
            {
                if (Globals.Game == 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);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// PakFileReader.ReadIndexInternal will not set AesKey because we're already checking if it works here
        /// it's good for FModel so we don't test the key, read the index and test the key again to set it
        /// </summary>
        /// <param name="disableAll"></param>
        public static void NoKeyGoodBye(bool disableAll = false)
        {
            if (MenuItems.pakFiles.AtLeastOnePak())
            {
                if (disableAll)
                {
                    foreach (PakMenuItemViewModel menuItem in MenuItems.pakFiles.GetMenuItemWithPakFiles())
                    {
                        menuItem.IsEnabled = false;
                    }
                }
                else
                {
                    Dictionary <string, string> staticKeys = new Dictionary <string, string>();
                    if (!string.IsNullOrEmpty(Properties.Settings.Default.StaticAesKeys))
                    {
                        staticKeys = JsonConvert.DeserializeObject <Dictionary <string, string> >(Properties.Settings.Default.StaticAesKeys);
                    }

                    Dictionary <string, string> dynamicKeys = new Dictionary <string, string>();
                    if (!string.IsNullOrEmpty(Properties.Settings.Default.DynamicAesKeys))
                    {
                        dynamicKeys = JsonConvert.DeserializeObject <Dictionary <string, string> >(Properties.Settings.Default.DynamicAesKeys);
                    }

                    bool isMainKey = staticKeys.TryGetValue(Globals.Game.ToString(), out var _);
                    bool mainError = false; // used to avoid notifications about all static paks not working with the key

                    StatusBarVm.statusBarViewModel.Reset();
                    foreach (PakMenuItemViewModel menuItem in MenuItems.pakFiles.GetMenuItemWithPakFiles())
                    {
                        // reset everyone
                        menuItem.PakFile.AesKey = null;

                        if (!mainError && isMainKey)
                        {
                            if (menuItem.PakFile.Info.EncryptionKeyGuid.Equals(new FGuid(0u, 0u, 0u, 0u)) &&
                                staticKeys.TryGetValue(Globals.Game.ToString(), out var sKey))
                            {
                                sKey = sKey.StartsWith("0x") ? sKey.Substring(2).ToUpperInvariant() : sKey.ToUpperInvariant();
                                try
                                {
                                    // i can use TestAesKey here but that means it's gonna test here then right after to set the key
                                    // so a try catch when setting the key seems better
                                    menuItem.PakFile.AesKey = sKey.Trim().ToBytesKey();
                                }
                                catch (System.Exception e)
                                {
                                    mainError = true;
                                    StatusBarVm.statusBarViewModel.Set(e.Message, Properties.Resources.Error);
                                    FConsole.AppendText(string.Format(Properties.Resources.StaticKeyNotWorking, $"0x{sKey}"), FColors.Red);
                                    DebugHelper.WriteLine("{0} {1} {2}", "[FModel]", "[AES]", $"0x{sKey} is NOT!!!! working with user's pak files");
                                }
                            }
                        }

                        string trigger = $"{Properties.Settings.Default.PakPath.Substring(Properties.Settings.Default.PakPath.LastIndexOf(Folders.GetGameName())).Replace("\\", "/")}/{menuItem.PakFile.FileName}";
                        if (dynamicKeys.TryGetValue(trigger, out var key))
                        {
                            string dKey = key.StartsWith("0x") ? key.Substring(2).ToUpperInvariant() : key.ToUpperInvariant();
                            try
                            {
                                // i can use TestAesKey here but that means it's gonna test here then right after to set the key
                                // so a try catch when setting the key seems better
                                menuItem.PakFile.AesKey = dKey.Trim().ToBytesKey();
                            }
                            catch (System.Exception e)
                            {
                                StatusBarVm.statusBarViewModel.Set(e.Message, Properties.Resources.Error);
                                FConsole.AppendText(string.Format(Properties.Resources.DynamicKeyNotWorking, $"0x{dKey}", menuItem.PakFile.FileName), FColors.Red);
                                DebugHelper.WriteLine("{0} {1} {2}", "[FModel]", "[AES]", $"0x{dKey} is NOT!!!! working with {menuItem.PakFile.FileName}");
                            }
                        }

                        menuItem.IsEnabled = menuItem.PakFile.AesKey != null;
                    }
                }
            }
        }