rpfm_lib 4.7.4

This crate contains the basic functionality for interacting with Total War files.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
//---------------------------------------------------------------------------//
// Copyright (c) 2017-2024 Ismael Gutiérrez González. All rights reserved.
//
// This file is part of the Rusted PackFile Manager (RPFM) project,
// which can be found here: https://github.com/Frodo45127/rpfm.
//
// This file is licensed under the MIT license, which can be found here:
// https://github.com/Frodo45127/rpfm/blob/master/LICENSE.
//---------------------------------------------------------------------------//

//! Module that contains the GameInfo definition and stuff related with it.

use directories::ProjectDirs;
use getset::*;
#[cfg(feature = "integration_log")] use log::{info, warn};
use steamlocate::SteamDir;

use std::collections::HashMap;
use std::{fmt, fmt::Display};
use std::fs::{DirBuilder, File};
use std::io::{BufReader, Read};
use std::path::{Path, PathBuf};
use std::sync::{Arc, RwLock};

use crate::compression::CompressionFormat;
use crate::error::{RLibError, Result};
use crate::utils::*;

use self::supported_games::*;
use self::manifest::Manifest;
use self::pfh_file_type::PFHFileType;
use self::pfh_version::PFHVersion;

pub mod supported_games;
pub mod manifest;
pub mod pfh_file_type;
pub mod pfh_version;

pub const BRAZILIAN: &str = "br";
pub const SIMPLIFIED_CHINESE: &str = "cn";
pub const CZECH: &str = "cz";
pub const ENGLISH: &str = "en";
pub const FRENCH: &str = "fr";
pub const GERMAN: &str = "ge";
pub const ITALIAN: &str = "it";
pub const KOREAN: &str = "kr";
pub const POLISH: &str = "pl";
pub const RUSSIAN: &str = "ru";
pub const SPANISH: &str = "sp";
pub const TURKISH: &str = "tr";
pub const TRADITIONAL_CHINESE: &str = "zh";

pub const LUA_AUTOGEN_FOLDER: &str = "tw_autogen";
pub const LUA_REPO: &str = "https://github.com/chadvandy/tw_autogen";
pub const LUA_REMOTE: &str = "origin";
pub const LUA_BRANCH: &str = "main";

pub const OLD_AK_REPO: &str = "https://github.com/Frodo45127/total_war_ak_files_pre_shogun_2";
pub const OLD_AK_REMOTE: &str = "origin";
pub const OLD_AK_BRANCH: &str = "master";

pub const TRANSLATIONS_REPO: &str = "https://github.com/Frodo45127/total_war_translation_hub";
pub const TRANSLATIONS_REMOTE: &str = "origin";
pub const TRANSLATIONS_BRANCH: &str = "master";

//-------------------------------------------------------------------------------//
//                              Enums & Structs
//-------------------------------------------------------------------------------//

/// This struct holds all the info needed for a game to be "supported" by RPFM.
#[derive(Getters, Clone, Debug)]
#[getset(get = "pub")]
pub struct GameInfo {

    /// This is the internal key of the game.
    #[getset(skip)]
    key: &'static str,

    /// This is the name it'll show up for the user. The *pretty name*. For example, in a dropdown (Warhammer 2).
    display_name: &'static str,

    /// This is the PFHVersion used at the start of every PackFile for that game.
    /// It's in a hashmap of PFHFileType => PFHVersion, so we can have different PackFile versions depending on their type.
    pfh_versions: HashMap<PFHFileType, PFHVersion>,

    /// This is the full name of the schema file used for the game. For example: `schema_wh2.ron`.
    schema_file_name: String,

    /// This is the name of the file containing the dependencies cache for this game.
    dependencies_cache_file_name: String,

    /// This is the **type** of raw files the game uses. -1 is "Don't have Assembly Kit". 0 is Empire/Nappy. 1 is Shogun 2. 2 is anything newer than Shogun 2.
    raw_db_version: i16,

    /// This is the version used when generating PortraitSettings files for each game.
    portrait_settings_version: Option<u32>,

    /// If we can save `PackFile` files for the game.
    supports_editing: bool,

    /// If the db tables should have a GUID in their headers.
    db_tables_have_guid: bool,

    /// If the game has locales for all languages, and we only need to load our own locales. Contains the name of the locale file.
    locale_file_name: Option<String>,

    /// List of tables (table_name) which the program should NOT EDIT UNDER ANY CIRCUnSTANCE.
    banned_packedfiles: Vec<String>,

    /// Name of the icon used to display the game as `Game Selected`, in an UI.
    icon_small: String,

    /// Name of the big icon used to display the game as `Game Selected`, in an UI.
    icon_big: String,

    /// Logic used to name vanilla tables.
    vanilla_db_table_name_logic: VanillaDBTableNameLogic,

    /// Installation-dependant data.
    #[getset(skip)]
    install_data: HashMap<InstallType, InstallData>,

    /// Tool-specific vars for each game.
    tool_vars: HashMap<String, String>,

    /// Subfolder under Lua Autogen's folder where the files for this game are, if it's supported.
    lua_autogen_folder: Option<String>,

    /// Table/fields ignored on the assembly kit integration for this game. These are fields that are "lost" when exporting the tables from Dave.
    ak_lost_fields: Vec<String>,

    /// Internal cache to speedup operations related with the install type.
    #[getset(skip)]
    install_type_cache: Arc<RwLock<HashMap<PathBuf, InstallType>>>,

    /// List of compression formats supported by the game, sorted from newer to older.
    compression_formats_supported: Vec<CompressionFormat>,

    /// Max version of the cs2.parsed format this game supports, for supporting between-game conversion of models.
    max_cs2_parsed_version: u32,
}

/// This enum holds the info about each game approach at naming db tables.
#[derive(Clone, Debug)]
pub enum VanillaDBTableNameLogic {

    /// This variant is for games where the table name is their folder's name.
    FolderName,

    /// This variant is for games where all tables are called the same.
    DefaultName(String),
}

/// This enum represents the different installations of games the game support.
#[derive(Clone, Debug, Hash, PartialEq, Eq)]
pub enum InstallType {

    /// Windows - Steam variant.
    WinSteam,

    /// Linux - Steam variant.
    LnxSteam,

    /// Windows - Epic Store Variant.
    WinEpic,

    /// Windows - Wargaming Variant.
    WinWargaming,
}

/// This struct contains installation-dependant data about each game.
///
/// NOTE: All PackFile paths contained in this struct are RELATIVE, either to the data folder, or to the game's folder.
#[derive(Getters, Clone, Debug)]
#[getset(get = "pub")]
pub struct InstallData {

    /// List of vanilla packs, to be use as reference for knowing what PackFiles are vanilla in games without a manifest file.
    /// Currently only used for Empire and Napoleon. Relative to data_path.
    vanilla_packs: Vec<String>,

    /// If the manifest of the game should be used to get the vanilla PackFile list, or should we use the hardcoded list.
    use_manifest: bool,

    /// StoreID of the game.
    store_id: u64,

    /// StoreID of the AK.
    store_id_ak: u64,

    /// Name of the executable of the game, including extension if it has it.
    executable: String,

    /// /data path of the game, or equivalent. Relative to the game's path.
    data_path: String,

    /// Path where the language.txt file of the game is expected to be. Usually /data, but it's different on linux builds. Relative to the game's path.
    language_path: String,

    /// Folder where local (your own) mods are stored. Relative to the game's path.
    local_mods_path: String,

    /// Folder where downloaded (other peoples's) mods are stored. Relative to the game's path.
    downloaded_mods_path: String,

    /// Name of the folder where the config for this specific game installation are stored.
    config_folder: Option<String>,
}

//-------------------------------------------------------------------------------//
//                             Implementations
//-------------------------------------------------------------------------------//

impl Display for InstallType {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        Display::fmt(match self {
            Self::WinSteam => "Windows - Steam",
            Self::LnxSteam => "Linux - Steam",
            Self::WinEpic => "Windows - Epic",
            Self::WinWargaming => "Windows - Wargaming",
        }, f)
    }
}

/// Implementation of GameInfo.
impl GameInfo {

    //---------------------------------------------------------------------------//
    // Getters.
    //---------------------------------------------------------------------------//

    /// This function returns the "Key" name of the Game, meaning in lowercase and without spaces.
    pub fn key(&self) -> &str {
        self.key
    }

    /// This function returns the PFHVersion corresponding to the provided PackFile type. If it's not found, it defaults to the one used by mods.
    pub fn pfh_version_by_file_type(&self, pfh_file_type: PFHFileType) -> PFHVersion {
        match self.pfh_versions.get(&pfh_file_type) {
            Some(pfh_version) => *pfh_version,
            None => *self.pfh_versions.get(&PFHFileType::Mod).unwrap(),
        }
    }

    //---------------------------------------------------------------------------//
    // Advanced getters.
    //---------------------------------------------------------------------------//

    /// This function tries to get the correct InstallType for the currently configured installation of the game.
    pub fn install_type(&self, game_path: &Path) -> Result<InstallType> {

        // This function takes 10ms to execute. In a few places, it's executed 2-5 times, and quickly adds up.
        // So before executing it, check the cache to see if it has been executed before.
        if let Some(install_type) = self.install_type_cache.read().unwrap().get(game_path) {
            return Ok(install_type.clone());
        }

        // Checks to guess what kind of installation we have.
        let base_path_files = files_from_subdir(game_path, false)?;
        let install_type_by_exe = self.install_data.iter().filter_map(|(install_type, install_data)|
            if base_path_files.iter().filter_map(|path| if path.is_file() { path.file_name() } else { None }).any(|filename| filename.to_ascii_lowercase() == &*install_data.executable().to_lowercase()) {
                Some(install_type)
            } else { None }
        ).collect::<Vec<&InstallType>>();

        // If no compatible install data was found, use the first one we have.
        if install_type_by_exe.is_empty() {
            let install_type = self.install_data.keys().next().unwrap();
            self.install_type_cache.write().unwrap().insert(game_path.to_path_buf(), install_type.clone());
            Ok(install_type.clone())
        }

        // If we only have one install type compatible with the executable we have, return it.
        else if install_type_by_exe.len() == 1 {
            self.install_type_cache.write().unwrap().insert(game_path.to_path_buf(), install_type_by_exe[0].clone());
            Ok(install_type_by_exe[0].clone())
        }

        // If we have multiple install data compatible, it gets more complex.
        else {

            // First, identify if we have a windows or linux build (mac only exists in your dreams.....).
            // Can't be both because they have different exe names. Unless you're retarded and you merge both, in which case, fuck you.
            let is_windows = install_type_by_exe.iter().any(|install_type| install_type == &&InstallType::WinSteam || install_type == &&InstallType::WinEpic || install_type == &&InstallType::WinWargaming);
            if is_windows {

                // Steam versions of the game have a "steam_api.dll" or "steam_api64.dll" file. Epic has "EOSSDK-Win64-Shipping.dll".
                let has_steam_api_dll = base_path_files.iter().filter_map(|path| path.file_name()).any(|filename| filename == "steam_api.dll" || filename == "steam_api64.dll");
                let has_eos_sdk_dll = base_path_files.iter().filter_map(|path| path.file_name()).any(|filename| filename == "EOSSDK-Win64-Shipping.dll");
                if has_steam_api_dll && install_type_by_exe.contains(&&InstallType::WinSteam) {
                    self.install_type_cache.write().unwrap().insert(game_path.to_path_buf(), InstallType::WinSteam);
                    Ok(InstallType::WinSteam)
                }

                // If not, check wether we have epic libs.
                else if has_eos_sdk_dll && install_type_by_exe.contains(&&InstallType::WinEpic) {
                    self.install_type_cache.write().unwrap().insert(game_path.to_path_buf(), InstallType::WinEpic);
                    Ok(InstallType::WinEpic)
                }

                // If neither of those are true, assume it's wargaming/netease (arena?).
                else {
                    self.install_type_cache.write().unwrap().insert(game_path.to_path_buf(), InstallType::WinWargaming);
                    Ok(InstallType::WinWargaming)
                }
            }

            // Otherwise, assume it's linux
            else {
                self.install_type_cache.write().unwrap().insert(game_path.to_path_buf(), InstallType::LnxSteam);
                Ok(InstallType::LnxSteam)
            }
        }
    }

    /// This function gets the install data for the game, if it's a supported installation.
    pub fn install_data(&self, game_path: &Path) -> Result<&InstallData> {
        let install_type = self.install_type(game_path)?;
        let install_data = self.install_data.get(&install_type).ok_or_else(|| RLibError::GameInstallTypeNotSupported(self.display_name.to_string(), install_type.to_string()))?;
        Ok(install_data)
    }

    /// This function gets the `/data` path or equivalent of the game selected, if said game it's configured in the settings.
    pub fn data_path(&self, game_path: &Path) -> Result<PathBuf> {
        let install_type = self.install_type(game_path)?;
        let install_data = self.install_data.get(&install_type).ok_or_else(|| RLibError::GameInstallTypeNotSupported(self.display_name.to_string(), install_type.to_string()))?;
        Ok(game_path.join(install_data.data_path()))
    }

    /// This function gets the `/contents` path or equivalent of the game selected, if said game it's configured in the settings.
    pub fn content_path(&self, game_path: &Path) -> Result<PathBuf> {
        let install_type = self.install_type(game_path)?;
        let install_data = self.install_data.get(&install_type).ok_or_else(|| RLibError::GameInstallTypeNotSupported(self.display_name.to_string(), install_type.to_string()))?;
        Ok(game_path.join(install_data.downloaded_mods_path()))
    }

    /// This function gets the `language.txt` path of the game selected, if said game uses it and it's configured in the settings.
    pub fn language_path(&self, game_path: &Path) -> Result<PathBuf> {

        // For games that don't support
        let language_file_name = self.locale_file_name().clone().unwrap_or_else(|| "language.txt".to_owned());

        let install_type = self.install_type(game_path)?;
        let install_data = self.install_data.get(&install_type).ok_or_else(|| RLibError::GameInstallTypeNotSupported(self.display_name.to_string(), install_type.to_string()))?;
        let base_path = game_path.join(install_data.language_path());

        // The language files are either in this folder, or in a folder with the locale value inside this folder.
        let path_with_file = base_path.join(language_file_name);
        if path_with_file.is_file() {
            Ok(base_path)
        } else {

            // Yes, this is ugly. But I'm not the retarded idiot that decided to put the file that sets the language used inside a folder specific of the language used.
            let path = base_path.join(BRAZILIAN);
            if path.is_dir() {
                return Ok(path);
            }
            let path = base_path.join(SIMPLIFIED_CHINESE);
            if path.is_dir() {
                return Ok(path);
            }
            let path = base_path.join(CZECH);
            if path.is_dir() {
                return Ok(path);
            }
            let path = base_path.join(ENGLISH);
            if path.is_dir() {
                return Ok(path);
            }
            let path = base_path.join(FRENCH);
            if path.is_dir() {
                return Ok(path);
            }
            let path = base_path.join(GERMAN);
            if path.is_dir() {
                return Ok(path);
            }
            let path = base_path.join(ITALIAN);
            if path.is_dir() {
                return Ok(path);
            }
            let path = base_path.join(KOREAN);
            if path.is_dir() {
                return Ok(path);
            }
            let path = base_path.join(POLISH);
            if path.is_dir() {
                return Ok(path);
            }
            let path = base_path.join(RUSSIAN);
            if path.is_dir() {
                return Ok(path);
            }
            let path = base_path.join(SPANISH);
            if path.is_dir() {
                return Ok(path);
            }
            let path = base_path.join(TURKISH);
            if path.is_dir() {
                return Ok(path);
            }
            let path = base_path.join(TRADITIONAL_CHINESE);
            if path.is_dir() {
                return Ok(path);
            }

            // If no path exists, we just return the base path.
            Ok(base_path)
        }
    }

    /// This function gets the `/data` path or equivalent (the folder local mods are installed during development) of the game selected, if said game it's configured in the settings
    pub fn local_mods_path(&self, game_path: &Path) -> Result<PathBuf> {
        let install_type = self.install_type(game_path)?;
        let install_data = self.install_data.get(&install_type).ok_or_else(|| RLibError::GameInstallTypeNotSupported(self.display_name.to_string(), install_type.to_string()))?;
        Ok(game_path.join(install_data.local_mods_path()))
    }

    /// This function gets the `/mods` path or equivalent of the game selected, if said game it's configured in the settings.
    pub fn content_packs_paths(&self, game_path: &Path) -> Option<Vec<PathBuf>> {
        let install_type = self.install_type(game_path).ok()?;
        let install_data = self.install_data.get(&install_type)?;
        let downloaded_mods_path = install_data.downloaded_mods_path();

        // If the path is empty, it means this game does not support downloaded mods.
        if downloaded_mods_path.is_empty() {
            return None;
        }

        let path = std::fs::canonicalize(game_path.join(downloaded_mods_path)).ok()?;
        let mut paths = vec![];

        for path in files_from_subdir(&path, true).ok()?.iter() {
            match path.extension() {
                Some(extension) => if extension == "pack" || extension == "bin" { paths.push(path.to_path_buf()); }
                None => continue,
            }
        }

        paths.sort();
        Some(paths)
    }

    /// This function gets the paths of the Packs from the `/secondary` path or equivalent of the game selected, if it's configured in the settings.
    ///
    /// Secondary path must be absolute.
    pub fn secondary_packs_paths(&self, secondary_path: &Path) -> Option<Vec<PathBuf>> {
        if !secondary_path.is_dir() || !secondary_path.exists() || !secondary_path.is_absolute() {
            return None;
        }

        let game_path = secondary_path.join(self.key());
        if !game_path.is_dir() || !game_path.exists() {
            return None;
        }

        let mut paths = vec![];

        for path in files_from_subdir(&game_path, false).ok()?.iter() {
            match path.extension() {
                Some(extension) => if extension == "pack" {
                    paths.push(path.to_path_buf());
                }
                None => continue,
            }
        }

        paths.sort();
        Some(paths)
    }

    /// This function gets the `/data` path or equivalent of the game selected, if said game it's configured in the settings.
    pub fn data_packs_paths(&self, game_path: &Path) -> Option<Vec<PathBuf>> {
        let game_path = self.data_path(game_path).ok()?;
        let mut paths = vec![];

        for path in files_from_subdir(&game_path, false).ok()?.iter() {
            match path.extension() {
                Some(extension) => if extension == "pack" { paths.push(path.to_path_buf()); }
                None => continue,
            }
        }

        paths.sort();
        Some(paths)
    }


    /// This function gets the destination folder for MyMod packs.
    pub fn mymod_install_path(&self, game_path: &Path) -> Option<PathBuf> {
        let install_type = self.install_type(game_path).ok()?;
        let install_data = self.install_data.get(&install_type)?;
        let path = game_path.join(PathBuf::from(install_data.local_mods_path()));

        // Make sure the folder exists.
        DirBuilder::new().recursive(true).create(&path).ok()?;

        Some(path)
    }

    /// This function returns if we should use the manifest of the game (if found) to get the vanilla PackFiles, or if we should get them from out hardcoded list.
    pub fn use_manifest(&self, game_path: &Path) -> Result<bool> {
        let install_type = self.install_type(game_path)?;
        let install_data = self.install_data.get(&install_type).ok_or_else(|| RLibError::GameInstallTypeNotSupported(self.display_name.to_string(), install_type.to_string()))?;

        // If the install_type is linux, or we actually have a hardcoded list, ignore all Manifests.
        Ok(*install_data.use_manifest())
    }

    /// This function returns the steam id for a specific game installation.
    pub fn steam_id(&self, game_path: &Path) -> Result<u64> {
        let install_type = self.install_type(game_path)?;
        let install_data = match install_type {
            InstallType::WinSteam |
            InstallType::LnxSteam => self.install_data.get(&install_type).ok_or_else(|| RLibError::GameInstallTypeNotSupported(self.display_name.to_string(), install_type.to_string()))?,
            _ => return Err(RLibError::ReservedFiles)
        };

        Ok(*install_data.store_id())
    }

    /// This function is used to get the paths of all CA PackFiles on the data folder of the game selected.
    ///
    /// If it fails to find a manifest, it falls back to all non-mod files!
    ///
    /// NOTE: For WH3, this is language-sensitive. Meaning, if you have the game on spanish, it'll try to load the spanish localization files ONLY.
    pub fn ca_packs_paths(&self, game_path: &Path) -> Result<Vec<PathBuf>> {

        // Check if we have to filter by language, to avoid overwriting our language with another one.
        let language = self.game_locale_from_file(game_path)?;

        // Check if we can use the manifest for this.
        if !self.use_manifest(game_path)? {
            self.ca_packs_paths_no_manifest(game_path, &language)
        } else {

            // Try to get the manifest, if exists.
            match Manifest::read_from_game_path(self, game_path) {
                Ok(manifest) => {
                    let data_path = self.data_path(game_path)?;
                    let mut paths = manifest.0.iter().filter_map(|entry|
                        if entry.relative_path().ends_with(".pack") {

                            let mut pack_file_path = data_path.to_path_buf();
                            pack_file_path.push(entry.relative_path());
                            match &language {
                                Some(language) => {

                                    // Filter out other language's packfiles.
                                    if entry.relative_path().contains("local_") {
                                        let language = "local_".to_owned() + language;
                                        if entry.relative_path().contains(&language) {
                                            entry.path_from_manifest_entry(pack_file_path)
                                        } else {
                                            None
                                        }
                                    } else {
                                        entry.path_from_manifest_entry(pack_file_path)
                                    }
                                }
                                None => entry.path_from_manifest_entry(pack_file_path),
                            }
                        } else { None }
                        ).collect::<Vec<PathBuf>>();

                    paths.sort();
                    Ok(paths)
                }

                // If there is no manifest, use the hardcoded file list for the game, if it has one.
                Err(_) => self.ca_packs_paths_no_manifest(game_path, &language)
            }
        }
    }

    /// This function tries to get the ca PackFiles without depending on a Manifest. For internal use only.
    fn ca_packs_paths_no_manifest(&self, game_path: &Path, language: &Option<String>) -> Result<Vec<PathBuf>> {
        let data_path = self.data_path(game_path)?;
        let install_type = self.install_type(game_path)?;
        let vanilla_packs = &self.install_data.get(&install_type).ok_or_else(|| RLibError::GameInstallTypeNotSupported(self.display_name.to_string(), install_type.to_string()))?.vanilla_packs;
        let language_pack = language.clone().map(|lang| format!("local_{lang}"));
        if !vanilla_packs.is_empty() {
            Ok(vanilla_packs.iter().filter_map(|pack_name| {

                let mut pack_file_path = data_path.to_path_buf();
                pack_file_path.push(pack_name);
                match language_pack {
                    Some(ref language_pack) => {

                        // Filter out other language's packfiles.
                        if !pack_name.is_empty() && pack_name.starts_with("local_") {
                            if pack_name.starts_with(language_pack) {
                                std::fs::canonicalize(pack_file_path).ok()
                            } else {
                                None
                            }
                        } else {
                            std::fs::canonicalize(pack_file_path).ok()
                        }
                    }
                    None => std::fs::canonicalize(pack_file_path).ok(),
                }
            }).collect::<Vec<PathBuf>>())
        }

        // If there is no hardcoded list, get every path.
        else {
            Ok(files_from_subdir(&data_path, false)?.iter()
                .filter_map(|x| if let Some(extension) = x.extension() {
                    if extension.to_string_lossy().to_lowercase() == "pack" {
                        Some(x.to_owned())
                    } else { None }
                } else { None }).collect::<Vec<PathBuf>>()
            )
        }
    }

    /// This command returns the "launch" command for executing this game's installation.
    pub fn game_launch_command(&self, game_path: &Path) -> Result<String> {
        let install_type = self.install_type(game_path)?;

        match install_type {
            InstallType::LnxSteam |
            InstallType::WinSteam => {
                let store_id = self.install_data.get(&install_type).ok_or_else(|| RLibError::GameInstallTypeNotSupported(self.display_name.to_string(), install_type.to_string()))?.store_id();
                Ok(format!("steam://rungameid/{store_id}"))
            },
            _ => Err(RLibError::GameInstallLaunchNotSupported(self.display_name.to_string(), install_type.to_string())),
        }
    }

    /// This command returns the "Executable" path for the game's installation.
    pub fn executable_path(&self, game_path: &Path) -> Option<PathBuf> {
        let install_type = self.install_type(game_path).ok()?;
        let install_data = self.install_data.get(&install_type)?;
        let executable_path = game_path.join(install_data.executable());

        Some(executable_path)
    }

    /// This command returns the "config" path for the game's installation.
    pub fn config_path(&self, game_path: &Path) -> Option<PathBuf> {
        let install_type = self.install_type(game_path).ok()?;
        let install_data = self.install_data.get(&install_type)?;
        let config_folder = install_data.config_folder.as_ref()?;

        ProjectDirs::from("com", "The Creative Assembly", config_folder).map(|dir| {
            let mut dir = dir.config_dir().to_path_buf();
            dir.pop();
            dir
        })
    }

    /// Check if a specific file is banned.
    pub fn is_file_banned(&self, path: &str) -> bool {
        let path = path.to_lowercase();
        self.banned_packedfiles.iter().any(|x| path.starts_with(x))
    }

    /// Tries to retrieve a tool var for the game.
    pub fn tool_var(&self, var: &str) -> Option<&String> {
        self.tool_vars.get(var)
    }

    /// This function tries to get the language of the game. Defaults to english if not found.
    pub fn game_locale_from_file(&self, game_path: &Path) -> Result<Option<String>> {
        match self.locale_file_name() {
            Some(locale_file) => {
                let language_path = self.language_path(game_path)?;
                let locale_path = language_path.join(locale_file);
                let mut language = String::new();
                if let Ok(mut file) = File::open(locale_path) {
                    file.read_to_string(&mut language)?;

                    let language = match &*language {
                        "BR" => BRAZILIAN.to_owned(),
                        "CN" => SIMPLIFIED_CHINESE.to_owned(),
                        "CZ" => CZECH.to_owned(),
                        "EN" => ENGLISH.to_owned(),
                        "FR" => FRENCH.to_owned(),
                        "DE" => GERMAN.to_owned(),
                        "IT" => ITALIAN.to_owned(),
                        "KR" => KOREAN.to_owned(),
                        "PO" => POLISH.to_owned(),
                        "RU" => RUSSIAN.to_owned(),
                        "ES" => SPANISH.to_owned(),
                        "TR" => TURKISH.to_owned(),
                        "ZH" => TRADITIONAL_CHINESE.to_owned(),

                        // Default to english if we can't find the proper one.
                        _ => ENGLISH.to_owned(),
                    };

                    #[cfg(feature = "integration_log")] {
                        info!("Language file found, using {language} language.");
                    }

                    Ok(Some(language))
                } else {
                    #[cfg(feature = "integration_log")] {
                        warn!("Missing or unreadable language file under {}. Using english language.", game_path.to_string_lossy());
                    }
                    Ok(Some(ENGLISH.to_owned()))
                }
            }
            None => Ok(None),
        }
    }

    /// This function gets the version number of the exe for the current GameSelected, if it exists.
    pub fn game_version_number(&self, game_path: &Path) -> Option<u32> {
        match self.key() {
            KEY_TROY => {
                let exe_path = self.executable_path(game_path)?;
                if exe_path.is_file() {
                    let mut data = vec![];
                    let mut file = BufReader::new(File::open(exe_path).ok()?);
                    file.read_to_end(&mut data).ok()?;

                    let version_info = pe_version_info(&data).ok()?;
                    let version_info = version_info.fixed()?;
                    let mut version: u32 = 0;

                    // The CA format is limited so these can only be u8 when encoded, so we can safetly convert them.
                    let major = version_info.dwFileVersion.Major as u32;
                    let minor = version_info.dwFileVersion.Minor as u32;
                    let patch = version_info.dwFileVersion.Patch as u32;
                    let build = version_info.dwFileVersion.Build as u32;

                    version += major << 24;
                    version += minor << 16;
                    version += patch << 8;
                    version += build;
                    Some(version)
                }

                // If we have no exe, return a default value.
                else {
                    None
                }

            }

            _ => None,
        }
    }

    /// This function searches for installed total war games.
    ///
    /// NOTE: Only works for steam-installed games.
    pub fn find_game_install_location(&self) -> Result<Option<PathBuf>> {

        // Steam install data. We don't care if it's windows or linux, as the data we want is the same in both.
        let install_data = if let Some(install_data) = self.install_data.get(&InstallType::WinSteam) {
            install_data
        } else if let Some(install_data) = self.install_data.get(&InstallType::LnxSteam) {
            install_data
        } else {
            return Ok(None);
        };

        if install_data.store_id() > &0 {
            if let Ok(steamdir) = SteamDir::locate() {
                return match steamdir.find_app(*install_data.store_id() as u32) {
                    Ok(Some((app, lib))) => {
                        let app_path = lib.resolve_app_dir(&app);
                        if app_path.is_dir() {
                            Ok(Some(app_path.to_path_buf()))
                        } else {
                            Ok(None)
                        }
                    }
                    _ => Ok(None)
                }
            }
        }

        Ok(None)
    }

    /// This function searches for installed total war Assembly Kits.
    ///
    /// NOTE: Only works for steam-installed games.
    pub fn find_assembly_kit_install_location(&self) -> Result<Option<PathBuf>> {

        // Steam install data. We don't care if it's windows or linux, as the data we want is the same in both.
        let install_data = if let Some(install_data) = self.install_data.get(&InstallType::WinSteam) {
            install_data
        } else if let Some(install_data) = self.install_data.get(&InstallType::LnxSteam) {
            install_data
        } else {
            return Ok(None);
        };

        if install_data.store_id_ak() > &0 {
            if let Ok(steamdir) = SteamDir::locate() {
                return match steamdir.find_app(*install_data.store_id_ak() as u32) {
                    Ok(Some((app, lib))) => {
                        let app_path = lib.resolve_app_dir(&app);
                        if app_path.is_dir() {
                            Ok(Some(app_path.to_path_buf()))
                        } else {
                            Ok(None)
                        }
                    }
                    _ => Ok(None)
                }
            }
        }

        Ok(None)
    }

    /// This function returns the list of public tags available in the workshop for each game.
    pub fn steam_workshop_tags(&self) -> Result<Vec<String>> {
        Ok(match self.key() {
            KEY_PHARAOH_DYNASTIES => vec![
                String::from("mod"),
                String::from("graphical"),
                String::from("campaign"),
                String::from("ui"),
                String::from("battle"),
                String::from("overhaul"),
                String::from("units"),
            ],
            KEY_PHARAOH => vec![
                String::from("mod"),
                String::from("graphical"),
                String::from("campaign"),
                String::from("ui"),
                String::from("battle"),
                String::from("overhaul"),
                String::from("units"),
            ],
            KEY_WARHAMMER_3 => vec![
                String::from("graphical"),
                String::from("campaign"),
                String::from("units"),
                String::from("battle"),
                String::from("ui"),
                String::from("maps"),
                String::from("overhaul"),
                String::from("compilation"),
                String::from("cheat"),
            ],
            KEY_TROY => vec![
                String::from("mod"),
                String::from("ui"),
                String::from("graphical"),
                String::from("units"),
                String::from("battle"),
                String::from("campaign"),
                String::from("overhaul"),
                String::from("compilation"),
            ],
            KEY_THREE_KINGDOMS => vec![
                String::from("mod"),
                String::from("graphical"),
                String::from("overhaul"),
                String::from("ui"),
                String::from("battle"),
                String::from("campaign"),
                String::from("maps"),
                String::from("units"),
                String::from("compilation"),
            ],
            KEY_WARHAMMER_2 => vec![
                String::from("mod"),
                String::from("Units"),
                String::from("Battle"),
                String::from("Graphical"),
                String::from("UI"),
                String::from("Campaign"),
                String::from("Maps"),
                String::from("Overhaul"),
                String::from("Compilation"),
                String::from("Mod Manager"),
                String::from("Skills"),
                String::from("map"),
            ],
            KEY_WARHAMMER => vec![
                String::from("mod"),
                String::from("UI"),
                String::from("Graphical"),
                String::from("Overhaul"),
                String::from("Battle"),
                String::from("Campaign"),
                String::from("Compilation"),
                String::from("Units"),
                String::from("Maps"),
                String::from("Spanish"),
                String::from("English"),
                String::from("undefined"),
                String::from("map"),
            ],
            KEY_THRONES_OF_BRITANNIA => vec![
                String::from("mod"),
                String::from("ui"),
                String::from("battle"),
                String::from("campaign"),
                String::from("units"),
                String::from("compilation"),
                String::from("graphical"),
                String::from("overhaul"),
                String::from("maps"),
            ],
            KEY_ATTILA => vec![
                String::from("mod"),
                String::from("UI"),
                String::from("Graphical"),
                String::from("Battle"),
                String::from("Campaign"),
                String::from("Units"),
                String::from("Overhaul"),
                String::from("Compilation"),
                String::from("Maps"),
                String::from("version_2"),
                String::from("Czech"),
                String::from("Danish"),
                String::from("English"),
                String::from("Finnish"),
                String::from("French"),
                String::from("German"),
                String::from("Hungarian"),
                String::from("Italian"),
                String::from("Japanese"),
                String::from("Korean"),
                String::from("Norwegian"),
                String::from("Romanian"),
                String::from("Russian"),
                String::from("Spanish"),
                String::from("Swedish"),
                String::from("Thai"),
                String::from("Turkish"),
            ],
            KEY_ROME_2 => vec![
                String::from("mod"),
                String::from("Units"),
                String::from("Battle"),
                String::from("Overhaul"),
                String::from("Compilation"),
                String::from("Campaign"),
                String::from("Graphical"),
                String::from("UI"),
                String::from("Maps"),
                String::from("version_2"),
                String::from("English"),
                String::from("gribble"),
                String::from("tribble"),
            ],
            KEY_SHOGUN_2 => vec![
                String::from("map"),
                String::from("historical"),
                String::from("multiplayer"),
                String::from("mod"),
                String::from("version_2"),
                String::from("English"),
                String::from("ui"),
                String::from("graphical"),
                String::from("overhaul"),
                String::from("units"),
                String::from("campaign"),
                String::from("battle"),
            ],
            _ => return Err(RLibError::GameDoesntSupportWorkshop(self.key().to_owned()))
        })
    }

    /// This function returns the game that corresponds to the provided Steam ID, if any.
    pub fn game_by_steam_id(steam_id: u64) -> Result<Self> {
        let games = SupportedGames::default();
        for game in games.games() {

            // No need to check LnxSteam, as they share the same id.
            match game.install_data.get(&InstallType::WinSteam) {
                Some(install_data) => if install_data.store_id == steam_id {
                    return Ok(game.clone());
                } else {
                    continue;
                }
                None => continue,
            }
        }

        Err(RLibError::SteamIDDoesntBelongToKnownGame(steam_id))
    }
}