Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions CodeResources.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using Serilog;

namespace ModShardLauncher
{
internal static class CodeResources
{
private static readonly Lazy<Dictionary<string, string>> _scripts = new(LoadAllScripts);
public static string GetGML(string name)
{
if (_scripts.Value.TryGetValue(name, out var script)) return script;

throw new ArgumentException($"GML script '{name}' not found");
}
private static Dictionary<string, string> LoadAllScripts()
{
Dictionary<string, string> scripts = new();
Assembly assembly = Assembly.GetExecutingAssembly();

// Load all .gml resources
IEnumerable<string> resourceNames = assembly.GetManifestResourceNames()
.Where(name => name.EndsWith(".gml"));
foreach (string resourceName in resourceNames)
{
string? scriptName = Path.GetFileNameWithoutExtension(resourceName);

using Stream? stream =
assembly.GetManifestResourceStream(resourceName) ??
throw new FileNotFoundException($"GML script '{scriptName}' not found");
using StreamReader reader = new(stream);
scripts[scriptName.Split('.').Last()] = reader.ReadToEnd();
}

return scripts;
}
}
}
2 changes: 1 addition & 1 deletion Controls/GeneralPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@
</ComboBox>
<Label Content="{DynamicResource SettingHeader_Log}" VerticalAlignment="Top" Margin="32,100,0,0"
Style="{StaticResource xFont}" FontSize="12" Foreground="#95796A"/>
<CheckBox HorizontalAlignment="Left" Margin="160,102,0,0" VerticalAlignment="Top" IsChecked="{Binding isEnabled, Mode=TwoWay}" Name="Logger"
<CheckBox HorizontalAlignment="Left" Margin="160,102,0,0" VerticalAlignment="Top" IsChecked="{Binding Enabled, Mode=TwoWay}" Name="Logger"
Checked="Logger_Checked" Unchecked="Logger_Checked">
<CheckBox.Style>
<Style TargetType="CheckBox">
Expand Down
2 changes: 1 addition & 1 deletion Controls/ModBar.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
<GridSplitter Width="2" Height="48" HorizontalAlignment="Center" VerticalAlignment="Bottom"
Margin="12" Background="#33323F"/>
<CheckBox HorizontalAlignment="Right" Margin="0,32,128,0" Content="{DynamicResource Enable}"
FontFamily="{StaticResource ssFont}" Foreground="#FFFFFF" IsChecked="{Binding isEnabled, Mode=TwoWay}">
FontFamily="{StaticResource ssFont}" Foreground="#FFFFFF" IsChecked="{Binding Enabled, Mode=TwoWay}">
<CheckBox.Style>
<Style TargetType="CheckBox">
<Setter Property="IsChecked" Value="False"/>
Expand Down
15 changes: 10 additions & 5 deletions Controls/ModInfos.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
Expand Down Expand Up @@ -36,23 +38,26 @@ private async void Save_Click(object sender, EventArgs e)

bool patchSucess = false;

try
Stopwatch watch = Stopwatch.StartNew();
try
{
ModLoader.PatchFile();
long elapsedMs = watch.ElapsedMilliseconds;
Main.Instance.LogModListStatus();
Log.Information("Patching lasts {{{0}}} ms", elapsedMs);
Log.Information("Successfully patch vanilla");
patchSucess = true;
Main.Instance.LogModList();
}
catch(Exception ex)
catch (Exception ex)
{
Main.Instance.LogModList();
Main.Instance.LogModListStatus();
Log.Error(ex, "Something went wrong");
Log.Information("Failed patching vanilla");
MessageBox.Show(ex.ToString(), Application.Current.FindResource("SaveDataWarning").ToString());
}

// attempt to save the patched data
if (patchSucess)
if (patchSucess)
{
Task<bool> save = DataLoader.DoSaveDialog();
await save;
Expand Down
7 changes: 0 additions & 7 deletions Controls/ModSourceInfos.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,6 @@
<ImageBrush x:Key="OverSource" ImageSource="/Resources/Sprites/open_over.png"/>
</controls:MyToggleButton.Resources>
</controls:MyToggleButton>
<controls:MyToggleButton ImageSource="/Resources/Sprites/save.png" Click="Save_Click" ToolTip="Save Data File"
Margin="64,0,0,0">
<controls:MyToggleButton.Resources>
<ImageBrush x:Key="DownSource" ImageSource="/Resources/Sprites/save_down.png"/>
<ImageBrush x:Key="OverSource" ImageSource="/Resources/Sprites/save_over.png"/>
</controls:MyToggleButton.Resources>
</controls:MyToggleButton>
<Border BorderBrush="#43424D" BorderThickness="2"/>
</Grid>
<controls:MyItemsControl MaxHeight="672" Height="672" x:Name="SourceList"
Expand Down
28 changes: 0 additions & 28 deletions Controls/ModSourceInfos.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,33 +23,5 @@ private async void Open_Click(object sender, EventArgs e)
await DataLoader.DoOpenDialog();
Main.Instance.Refresh();
}
private async void Save_Click(object sender, EventArgs e)
{
if (DataLoader.data.FORM == null)
{
MessageBox.Show(Application.Current.FindResource("LoadDataWarning").ToString());
return;
}

bool patchSucess = false;

try
{
ModLoader.PatchFile();
Log.Information("Successfully patch vanilla");
patchSucess = true;
Main.Instance.LogModList();
}
catch(Exception ex)
{
Main.Instance.LogModList();
Log.Error(ex, "Something went wrong");
Log.Information("Failed patching vanilla");
MessageBox.Show(ex.ToString(), Application.Current.FindResource("SaveDataWarning").ToString());
}

if (patchSucess) await DataLoader.DoSaveDialog();
Main.Instance.Refresh();
}
}
}
67 changes: 0 additions & 67 deletions Extensions/ModShard.cs

This file was deleted.

8 changes: 4 additions & 4 deletions FileReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@
{
public class FileChunk
{
public string name;

Check warning on line 19 in FileReader.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable field 'name' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable.
public int offset;
public int length;
}
public class ModSource
{
public string Name { get; set; }

Check warning on line 25 in FileReader.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'Name' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
public string Path { get; set; }

Check warning on line 26 in FileReader.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'Path' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
public bool isExisted => File.Exists(Path);
public bool Existed => File.Exists(Path);
public override string ToString()
{
return Name;
Expand All @@ -38,25 +38,25 @@
}
public class ModFile
{
public string Name;

Check warning on line 41 in FileReader.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable field 'Name' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable.
public string Version { get; set; }

Check warning on line 42 in FileReader.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'Version' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
public List<FileChunk> Files = new();
public Assembly Assembly;

Check warning on line 44 in FileReader.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable field 'Assembly' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable.
public int FileOffset;
public FileStream Stream;

Check warning on line 46 in FileReader.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable field 'Stream' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable.
public string Path;

Check warning on line 47 in FileReader.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable field 'Path' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable.
public Mod instance { get; set; }

Check warning on line 48 in FileReader.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'instance' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
public bool isEnabled { get; set; }
public bool Enabled { get; set; }
public PatchStatus PatchStatus { get; set; } = PatchStatus.None;
public bool isExisted => File.Exists(Path);
public bool Existed => File.Exists(Path);
public byte[] Icon { get; set; } = Array.Empty<byte>();
public override string ToString()
{
return instance.ToString();
}
public byte[] GetFile(string fileName)
{
if(!isExisted)
if(!Existed)
{
MessageBox.Show(Application.Current.FindResource("ModLostWarning").ToString() + " : " + Name);
ModLoader.LoadFiles();
Expand Down
48 changes: 25 additions & 23 deletions Main.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,27 +131,31 @@ private void SetInitialSize()
}
}

public void LogModList()
public void LogModListStatus()
{
foreach (ModFile modFile in ModPage.Mods.Where(x => x.isEnabled))
foreach (ModFile modFile in ModPage.Mods.Where(x => x.Enabled))
{
string statusMessage = "";
switch (modFile.PatchStatus)
{
case PatchStatus.Patching:
statusMessage = "Patching failed";
break;
LogModStatus(modFile);
}
}
public static void LogModStatus(ModFile modFile)
{
string statusMessage = "";
switch (modFile.PatchStatus)
{
case PatchStatus.Patching:
statusMessage = "Patching failed";
break;

case PatchStatus.Success:
statusMessage = "Patching succeeded";
break;
case PatchStatus.Success:
statusMessage = "Patching succeeded";
break;

case PatchStatus.None:
statusMessage = "Waiting to be patched";
break;
}
Log.Warning("Patching {{{2}}} for {{{0}}} {{{1}}}", modFile.Name, modFile.Version, statusMessage);
case PatchStatus.None:
statusMessage = "Waiting to be patched";
break;
}
Log.Warning("Patching {{{2}}} for {{{0}}} {{{1}}}", modFile.Name, modFile.Version, statusMessage);
}
private void MyToggleButton_Checked(object sender, EventArgs e)
{
Expand Down Expand Up @@ -219,7 +223,7 @@ public class UserSettings
{
public string Language = "English";
public bool EnableLogger = true;
public List<string> EnableMods = new();
public List<string> EnabledMods = new();
public static void LoadSettings()
{
// if no settings file, early stop
Expand All @@ -233,16 +237,14 @@ public static void LoadSettings()
CheckLog(Main.Settings.EnableLogger);

// auto check active mods
if (Main.Settings.EnableMods.Count > 0)
if (Main.Settings.EnabledMods.Count > 0)
{
List<ModFile> listModFile = ModInfos.Instance.Mods;
foreach (string i in Main.Settings.EnableMods)
foreach (string i in Main.Settings.EnabledMods)
{
(int indexMod, ModFile? modFile) = listModFile.Enumerate().FirstOrDefault(t => t.Item2.Name == i);
if (modFile != null)
listModFile[indexMod].isEnabled = true;
else
Log.Warning($"Mod {i} not found");
if (modFile != null) listModFile[indexMod].Enabled = true;
else Log.Warning($"Mod {i} not found");
}
}
}
Expand Down
Loading
Loading