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

Commit

Permalink
Merge pull request #36 from Subversionary/IPCPatches
Browse files Browse the repository at this point in the history
Replace marserializer with IPC
  • Loading branch information
mynameundefined authored May 18, 2024
2 parents 2f46a2e + bba9111 commit eaee1aa
Show file tree
Hide file tree
Showing 15 changed files with 176 additions and 225 deletions.
17 changes: 0 additions & 17 deletions Marsey.IPC/Client.cs

This file was deleted.

9 changes: 0 additions & 9 deletions Marsey.IPC/Marsey.IPC.csproj

This file was deleted.

28 changes: 14 additions & 14 deletions Marsey/Game/Resources/ResMan.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@
using Marsey.Game.Resources.Dumper;
using Marsey.Game.Resources.Reflection;
using Marsey.Misc;
using Marsey.Serializer;
using Marsey.Stealthsey;

namespace Marsey.Game.Resources;

public static class ResMan
{
public static readonly string MarserializerFile = "rpacks.marsey";
private static readonly List<ResourcePack> _resourcePacks = [];
private static string? _fork;

Expand All @@ -20,22 +17,24 @@ public static class ResMan
public static void Initialize()
{
ResourceTypes.Initialize();

_fork = MarseyPortMan.fork; // Peak spaghet moment
// If were dumping the game we dont want to dump our own respack now would we

// If we're dumping the game we don't want to dump our own respack now would we
if (MarseyConf.Dumper)
{
MarseyDumper.Start();
return;
}

#if DEBUG
List<string> enabledPacks = Marserializer.Deserialize([MarseyVars.MarseyResourceFolder], MarserializerFile) ?? [];
// Retrieve enabled resource packs data through named pipe
List<string> enabledPacks = FileHandler.GetFilesFromPipe("ResourcePacksPipe");

if (enabledPacks.Count == 0) return;

MarseyLogger.Log(MarseyLogger.LogType.DEBG, $"Detecting {enabledPacks.Count} enabled resource packs.");

foreach (string dir in enabledPacks)
{
InitializeRPack(dir, !MarseyConf.DisableResPackStrict);
Expand All @@ -44,7 +43,8 @@ public static void Initialize()
ResourceSwapper.Start();
#endif
}



/// <summary>
/// Executed by the launcher
/// </summary>
Expand All @@ -66,7 +66,7 @@ public static void LoadDir()
private static void InitializeRPack(string path, bool strict = false)
{
ResourcePack rpack = new ResourcePack(path);

try
{
rpack.ParseMeta();
Expand All @@ -76,18 +76,18 @@ private static void InitializeRPack(string path, bool strict = false)
MarseyLogger.Log(MarseyLogger.LogType.FATL, e.ToString());
return;
}

AddRPack(rpack, strict);
}

private static void AddRPack(ResourcePack rpack, bool strict)
{
if (_resourcePacks.Any(rp => rp.Dir == rpack.Dir)) return;
if (strict && rpack.Target != _fork && rpack.Target != "") return;

_resourcePacks.Add(rpack);
}

public static List<ResourcePack> GetRPacks() => _resourcePacks;
public static string? GetForkID() => _fork;
}
}
27 changes: 27 additions & 0 deletions Marsey/IPC/Client.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System.IO.Pipes;
using Marsey.Misc;

namespace Marsey.IPC;

public class Client
{
public string ConnRecv(string name)
{
MarseyLogger.Log(MarseyLogger.LogType.DEBG, "IPC-Client", $"Trying to open client with pipe name {name}");
using NamedPipeClientStream pipeClient = new NamedPipeClientStream(".", name, PipeDirection.In);

try
{
pipeClient.Connect(150); // Pipe should connect immediately
}
catch(TimeoutException)
{
MarseyLogger.Log(MarseyLogger.LogType.DEBG, "IPC-Client", $"Connection timed out on pipe {name}, pipe not being created?");
return "";
}

using StreamReader reader = new StreamReader(pipeClient);
return reader.ReadToEnd();
}
}

3 changes: 3 additions & 0 deletions Marsey.IPC/Server.cs → Marsey/IPC/Server.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
using System.IO.Pipes;
using System.Text;
using Marsey.Misc;

namespace Marsey.IPC;

public class Server
{
public async Task ReadySend(string name, string data)
{
MarseyLogger.Log(MarseyLogger.LogType.INFO, "IPC-SERVER", $"Opening {name}");
await using NamedPipeServerStream pipeServer = new NamedPipeServerStream(name, PipeDirection.Out);
await pipeServer.WaitForConnectionAsync();

byte[] buffer = Encoding.UTF8.GetBytes(data);
await pipeServer.WriteAsync(buffer);

MarseyLogger.Log(MarseyLogger.LogType.INFO, "IPC-SERVER", $"Closing {name}");
pipeServer.Close();
}
}
4 changes: 0 additions & 4 deletions Marsey/Marsey.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,5 @@
<PackageReference Include="Lib.Harmony" />
<PackageReference Include="Newtonsoft.Json" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Marsey.IPC\Marsey.IPC.csproj" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion Marsey/MarseyPatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public void Boot()
private void ExecPatcher()
{
// Prepare marseypatches
FileHandler.LoadAssemblies(marserializer: true, filename: Marsyfier.MarserializerFile);
FileHandler.LoadAssemblies(pipe: true);
List<MarseyPatch> patches = Marsyfier.GetMarseyPatches();

if (patches.Count != 0)
Expand Down
Loading

0 comments on commit eaee1aa

Please sign in to comment.