Skip to content
This repository has been archived by the owner on Oct 16, 2024. It is now read-only.

Commit

Permalink
Obsessive documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
misandrie committed Oct 29, 2023
1 parent e4403c9 commit a4a7775
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 33 deletions.
23 changes: 7 additions & 16 deletions Marsey/FileHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,16 @@ public static void PrepAssemblies()

foreach (string file in GetPatches(path)) File.Delete(file);

foreach (var p in PatchAssemblyManager.GetPatchList())
{
if (p.Enabled)
{
string asmLocation = p.Asm.Location;

File.Copy(p.Asm.Location,
Path.Combine(
Directory.GetCurrentDirectory(),
"Marsey",
"Enabled",
Path.GetFileName(asmLocation)), true );
}

}
PatchAssemblyManager.GetPatchList()
.Where(p => p.Enabled)
.ToList()
.ForEach(p => File.Copy(p.Asm.Location,
Path.Combine(Directory.GetCurrentDirectory(), "Marsey",
"Enabled", Path.GetFileName(p.Asm.Location)), true));
}

/// <summary>
/// Loads assemblies from a specified (lie) folder.
/// Loads assemblies from a specified folder.
/// </summary>
/// <param name="path">folder with patch dll's</param>
public static void LoadAssemblies(string[]? path = null)
Expand Down
13 changes: 8 additions & 5 deletions Marsey/GameAssemblyManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class GameAssemblyManager
private static Harmony? _harmony;

/// <summary>
/// Sets the _harmony field in the class
/// Sets the _harmony field in the class.
/// </summary>
/// <param name="harmony">A Harmony instance</param>
public static void Init(Harmony harmony)
Expand All @@ -37,12 +37,14 @@ public static void PatchProc()
}

/// <summary>
/// Obtains game assemblies
/// Obtains game assemblies.
/// The function ends only when Robust.Shared,
/// Content.Client and Content.Shared are initialized by the game,
/// or 100 loops have been made without obtaining all the assemblies.
///
/// Executed only by the Loader.
/// </summary>
/// <exception cref="Exception">Excepts if manager couldn't get game assemblies after 100 loops.</exception>
public static void GetGameAssemblies(out Assembly? clientAss, out Assembly? robustSharedAss, out Assembly? clientSharedAss)
{
clientAss = null;
Expand Down Expand Up @@ -77,8 +79,9 @@ public static void GetGameAssemblies(out Assembly? clientAss, out Assembly? robu
Thread.Sleep(200);
}

Console.WriteLine(loops >= 100
? $"[MARSEY] Failed to receive assemblies within 20 seconds."
: $"[MARSEY] Received assemblies.");
if (loops >= 100)
throw new Exception("Failed to receive assemblies within 100 loops.");
else
Console.WriteLine("[MARSEY] Received assemblies.");
}
}
2 changes: 1 addition & 1 deletion Marsey/MarseyPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Marsey;

/// <summary>
/// Generic class for a patch accepted by MarseyPatcher
/// Generic class for a patch accepted by MarseyPatcher.
/// </summary>
public class MarseyPatch
{
Expand Down
2 changes: 2 additions & 0 deletions Marsey/MarseyPatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public void Boot(Assembly? robClientAssembly)

GameAssemblyManager.Init(new Harmony("com.validhunters.marseyloader"));

// Exception from this function halts execution.
// Patcher won't work if any of the 3 variables are null
GameAssemblyManager.GetGameAssemblies(out var clientAss, out var robustSharedAss, out var clientSharedAss);

PatchAssemblyManager.SetAssemblies(robClientAssembly, clientAss, robustSharedAss, clientSharedAss);
Expand Down
21 changes: 11 additions & 10 deletions Marsey/PatchAssemblyManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ public static void InitAssembly(Assembly assembly)
/// Obtains fields for each of the game's assemblies.
/// Returns null if any of the fields is null.
/// </summary>
/// <returns>List of fields of assemblies within a MarseyPatch</returns>
/// <exception cref="Nullable">Returns null if any field in MarseyPatch is missing</exception>
private static List<FieldInfo>? GetPatchAssemblyFields(Type marseyPatchType)
{
var fieldNames = new[] { "RobustClient", "RobustShared", "ContentClient", "ContentShared" };
Expand All @@ -71,6 +73,7 @@ public static void InitAssembly(Assembly assembly)

/// <summary>
/// Sets the assembly target in the patch assembly.
/// In order: Robust.Client, Robust.Shared, Content.Client, Content.Shared
/// </summary>
/// <param name="targets">Array of assemblies from the MarseyPatch class</param>
private static void SetAssemblyTargets(List<FieldInfo> targets)
Expand All @@ -81,30 +84,28 @@ private static void SetAssemblyTargets(List<FieldInfo> targets)
targets[3].SetValue(null,_clientSharedAss);
}

/// <returns>Patch list</returns>
public static List<MarseyPatch> GetPatchList()
{
return _patchAssemblies;
}

/// <summary>
/// Checks if the amount of patches in folder equals the amount of patches in list.
/// If not - resets the list.
/// </summary>
public static void RecheckPatches()
{
if (FileHandler.GetPatches(new []{"Marsey"}).Length == _patchAssemblies.Count)
return;

_patchAssemblies = new List<MarseyPatch>();
if (FileHandler.GetPatches(new []{"Marsey"}).Length != _patchAssemblies.Count)
_patchAssemblies.Clear();
}

/// <summary>
/// Sets assemblies to fields in class
/// </summary>
public static void SetAssemblies(Assembly? robustAss, Assembly? clientAss, Assembly? robustSharedAss, Assembly? clientSharedAss)
{
_robustAss = robustAss;
_clientAss = clientAss;
_robustSharedAss = robustSharedAss;
_clientSharedAss = clientSharedAss;
}

/// <returns>Patch list</returns>
public static List<MarseyPatch> GetPatchList() => _patchAssemblies;
}

13 changes: 13 additions & 0 deletions MarseyPatcher/MarseyPatcher.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Lib.Harmony" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion SS14.Launcher/Models/Connector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ private async Task<ContentLaunchInfo> InstallContentBundleAsync(
}
*/

Log.Information("Starting.");
Log.Debug("Preparing patch assemblies.");
FileHandler.PrepAssemblies();

var process = Process.Start(startInfo);
Expand Down

0 comments on commit a4a7775

Please sign in to comment.