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> </TabControl>
</Grid> </Grid>
</TabItem> </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"/> <Grid Background="#FEFEFE"/>
</TabItem> </TabItem>-->
</TabControl> </TabControl>
<Grid Grid.Row="1" Margin="10,10,10,10"> <Grid Grid.Row="1" Margin="10,10,10,10">
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>

View file

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

View file

@ -2,6 +2,8 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using Ionic.Zip;
using Microsoft.Win32; using Microsoft.Win32;
namespace ScrapModLoader namespace ScrapModLoader
@ -75,5 +77,11 @@ namespace ScrapModLoader
return isFound; 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); 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) private void LoadFromFile(String path)
{ {
using (ZipFile zipFile = ZipFile.Read(path)) using (ZipFile zipFile = ZipFile.Read(path))