Addeed ability to load mods

This commit is contained in:
strongleong 2022-02-06 21:59:08 +11:00
parent 4d34f4eaa6
commit cb4c8ac90d
4 changed files with 32 additions and 4 deletions

View File

@ -55,9 +55,9 @@
</TabControl>
</Grid>
</TabItem>
<TabItem Header="Settings" Height="22" Margin="-2,0,-2,0" VerticalAlignment="Bottom">
<!--<TabItem Header="Settings" Height="22" Margin="-2,0,-2,0" VerticalAlignment="Bottom">
<Grid Background="#FEFEFE"/>
</TabItem>
</TabItem>-->
</TabControl>
<Grid Grid.Row="1" Margin="10,10,10,10">
<Grid.ColumnDefinitions>

View File

@ -157,14 +157,17 @@ namespace ScrapModLoader
private void ButtonRunScrapland_Click(Object sender, RoutedEventArgs e)
{
String executablePath = ScraplandVersion.SelectedIndex == 0
String gamePath = ScraplandVersion.SelectedIndex == 0
? modsLauncher.ScraplandPath : modsLauncher.ScraplandRemasteredPath;
modsLauncher.LoadMods(gamePath);
String args = "-fullscreen:1";
if (Windowed.IsChecked ?? false)
args = "-fullscreen:0";
Process.Start(executablePath + @"\bin\Scrap.exe", args);
Process.Start(gamePath + @"\bin\Scrap.exe", args);
if (CloseLauncher.IsChecked ?? false)
Close();

View File

@ -2,6 +2,8 @@
using System.Collections.Generic;
using System.IO;
using Ionic.Zip;
using Microsoft.Win32;
namespace ScrapModLoader
@ -75,5 +77,11 @@ namespace ScrapModLoader
return isFound;
}
internal void LoadMods(String gamePath)
{
foreach (ScrapMod mod in Mods.FindAll(mod => mod.Checked))
mod.LoadModToGame(gamePath);
}
}
}

View File

@ -38,6 +38,23 @@ namespace ScrapModLoader
LoadFromFile(path);
}
public void LoadModToGame(String gamePath)
{
gamePath += @"Mods\" + Name;
Directory.CreateDirectory(gamePath);
using (ZipFile zipFile = ZipFile.Read(ModPath))
{
foreach (ZipEntry zipEntry in zipFile)
{
if (Path.GetExtension(zipEntry.FileName) == ".packed")
{
zipEntry.Extract(gamePath);
}
}
}
}
private void LoadFromFile(String path)
{
using (ZipFile zipFile = ZipFile.Read(path))