From 515aa519a4e7ff270faddc55b7248f553035b5a3 Mon Sep 17 00:00:00 2001 From: strongleong Date: Sun, 13 Feb 2022 01:26:00 +1100 Subject: [PATCH] Added support for different files for different versions in mod --- README.md | 35 +++++++++++++++++++++++++-------- ScrapModLoader/MainWindow.xaml | 3 ++- ScrapModLoader/ModsLauncher.cs | 9 +++------ ScrapModLoader/ScrapMod.cs | 36 +++++++++++++++++++++------------- 4 files changed, 54 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index 8b82ae6..598203f 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -WIP ScrapModLoader +WIP ScrapModLoader ============== This applications is for managing mods for Scrapland. @@ -24,11 +24,29 @@ ScrapModLoader supports both original and remastered versions of Scrapland. For now mod for Scrapland is a *.sm file that basically is a zip arhive with following content: -| Filename | Description | -|--------------------|----------------------------------------------| -| icon.png | Icon for mod that will show up in mod loader | -| config.toml | Information about mod | -| .packed | Container with all mod game assets | +| Filename | Description | +|------------------------|--------------------------------------------------| +| icon.png | Icon for mod that will show up in mod loader | +| config.toml | Information about mod | +| \ | Folder that named as game version mod made for | +| .packed | Container with all mod game assets | + +You can have as many .packed files as you want. Mod loader will load everything. + +.packed files in the root of mod will be copied to the `Mods` folder of Scrapland. + +.pakced files under game version folder will load only to the appopriate game version. + +### .sm structure sample +``` +│ icon.png +│ config.toml +│ mod_assets.packed +├──1.0/ +│ only_for_original.packed +└──1.1/ + only_for_remastered.packed +``` ### config.toml sample ```toml @@ -37,7 +55,7 @@ description = "Mod description" category = "Mod category" version = "1.0" requiredLauncher = "1.0" -requiredGame = "1.0" +supportedGameVersions = ["1.0", "1.1"] authors = [ { name = "Author 1" }, @@ -64,9 +82,10 @@ credits = [ - [X] Support for custom *.packed - [X] Supoprt for Scrapland Remastered + - [ ] Support for both Scrapland versions in single .sm file - [ ] Support for custom game files (i.e. `\Traslation\` files or custom `QuickConsole.py`) - [ ] Recompiling *.py to *.pyc - [ ] Mod settings. - - [ ] More meta info in `config.xml` + - [ ] More meta info in `config.toml` - [ ] Multilanguage support - [ ] More mods :wink: \ No newline at end of file diff --git a/ScrapModLoader/MainWindow.xaml b/ScrapModLoader/MainWindow.xaml index 02aebb3..f6dcd08 100644 --- a/ScrapModLoader/MainWindow.xaml +++ b/ScrapModLoader/MainWindow.xaml @@ -34,8 +34,9 @@ + - + diff --git a/ScrapModLoader/ModsLauncher.cs b/ScrapModLoader/ModsLauncher.cs index 43b51b9..8270437 100644 --- a/ScrapModLoader/ModsLauncher.cs +++ b/ScrapModLoader/ModsLauncher.cs @@ -86,19 +86,16 @@ namespace ScrapModLoader foreach (ScrapMod mod in Mods) { - if (mod.RequiredGame != SelectedGameVersion) + // TODO: Warning about not loading mods that not supports selected version + if (!mod.SupportedGameVersions.Contains(SelectedGameVersion)) continue; if (mod.Checked) - { if (!mod.IsEnabled(gamePath)) - mod.Enable(gamePath); - } + mod.Enable(gamePath, SelectedGameVersion); else - { if (mod.IsEnabled(gamePath)) mod.Disable(gamePath); - } } } } diff --git a/ScrapModLoader/ScrapMod.cs b/ScrapModLoader/ScrapMod.cs index 7e3f32a..5c458de 100644 --- a/ScrapModLoader/ScrapMod.cs +++ b/ScrapModLoader/ScrapMod.cs @@ -20,7 +20,16 @@ namespace ScrapModLoader public String Category { get; private set; } public String Version { get; private set; } public String RequiredLauncher { get; private set; } - public String RequiredGame { get; private set; } + public List SupportedGameVersions { get; private set; } + public String SupportedGameVersionsDisplay { + get + { + String result = String.Empty; + foreach (String version in SupportedGameVersions) + result += version + ", "; + return result.TrimEnd(',', ' '); + } + } public List Authors { get; private set; } public Dictionary> Credits { get; private set; } @@ -34,7 +43,7 @@ namespace ScrapModLoader Category = String.Empty; Version = String.Empty; RequiredLauncher = String.Empty; - RequiredGame = String.Empty; + SupportedGameVersions = new List(); Authors = new List(); Credits = new Dictionary>(); LoadFromFile(path); @@ -58,19 +67,17 @@ namespace ScrapModLoader return false; } - public void Enable(String gamePath) + public void Enable(String gamePath, String gameVersion) { if (!IsLoaded(gamePath)) - LoadModToGame(gamePath); + LoadModToGame(gamePath, gameVersion); if (IsEnabled(gamePath)) return; foreach (String file in Directory.EnumerateFiles(gamePath + @"Mods\" + Name)) - { if (Path.GetExtension(file) == ".disabled") File.Move(file, Path.ChangeExtension(file, null)); - } } public void Disable(String gamePath) @@ -79,13 +86,11 @@ namespace ScrapModLoader return; foreach (String file in Directory.EnumerateFiles(gamePath + @"Mods\" + Name)) - { if (Path.GetExtension(file) == ".packed") File.Move(file, file + ".disabled"); - } } - private void LoadModToGame(String gamePath) + private void LoadModToGame(String gamePath, String gameVersion) { gamePath += @"Mods\" + Name; Directory.CreateDirectory(gamePath); @@ -94,10 +99,11 @@ namespace ScrapModLoader { foreach (ZipEntry zipEntry in zipFile) { + if (!Path.GetFullPath(zipEntry.FileName).Contains(gameVersion)) + continue; + if (Path.GetExtension(zipEntry.FileName) == ".packed") - { zipEntry.Extract(gamePath); - } } } } @@ -151,7 +157,9 @@ namespace ScrapModLoader Category = config["category"]; Version = config["version"]; RequiredLauncher = config["requiredLauncher"]; - RequiredGame = config["requiredGame"]; + + foreach (TomlNode version in config["supportedGameVersions"]) + SupportedGameVersions.Add(version); foreach (TomlNode author in config["authors"]) Authors.Add(author["name"]); @@ -185,8 +193,8 @@ namespace ScrapModLoader if (!config.HasKey("requiredLauncher")) throw new FileFormatException("No 'name' key in 'config.toml'"); - if (!config.HasKey("requiredGame")) - throw new FileFormatException("No 'requiredGame' key in 'config.toml'"); + if (!config.HasKey("supportedGameVersions")) + throw new FileFormatException("No 'supportedGameVersions' key in 'config.toml'"); } } }