This repository has been archived by the owner on Oct 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from ValidHunters/ResSwap
Prep ResPacks
- Loading branch information
Showing
26 changed files
with
426 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace Marsey.Game.ResourcePack.Reflection; | ||
|
||
public static class Patches | ||
{ | ||
private static bool PrefixCFF(ref object __instance, ref dynamic path) | ||
{ | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using Marsey.Handbreak; | ||
|
||
namespace Marsey.Game.ResourcePack.Reflection; | ||
|
||
/// <summary> | ||
/// Holds reflection data related to Resources | ||
/// </summary> | ||
public static class ResourceTypes | ||
{ | ||
public static Type? ProtoMan { get; private set; } | ||
public static Type? ResPath { get; private set; } | ||
|
||
public static void Initialize() | ||
{ | ||
ProtoMan = Helpers.TypeFromQualifiedName("Robust.Shared.ContentPack.ResourceManager"); | ||
ResPath = Helpers.TypeFromQualifiedName("Robust.Shared.Utility.ResPath"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
using Marsey.Config; | ||
using Marsey.Game.ResourcePack.Reflection; | ||
using Marsey.Misc; | ||
using Marsey.Serializer; | ||
using Marsey.Stealthsey; | ||
|
||
namespace Marsey.Game.ResourcePack; | ||
|
||
public static class ResMan | ||
{ | ||
public static readonly string MarserializerFile = "rpacks.marsey"; | ||
private static readonly List<ResourcePack> _resourcePacks = []; | ||
private static string? _fork; | ||
private static readonly string _forkEnvVar = "MARSEY_FORKID"; | ||
|
||
/// <summary> | ||
/// Executed by the loader | ||
/// </summary> | ||
public static void Initialize() | ||
{ | ||
ResourceTypes.Initialize(); | ||
|
||
_fork = Environment.GetEnvironmentVariable(_forkEnvVar) ?? "marsey"; | ||
Envsey.CleanFlag(_forkEnvVar); | ||
|
||
List<string> enabledPacks = Marserializer.Deserialize([MarseyVars.MarseyResourceFolder], MarserializerFile) ?? []; | ||
foreach (string dir in enabledPacks) | ||
{ | ||
InitializeRPack(dir, !MarseyConf.DisableResPackStrict); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Executed by the launcher | ||
/// </summary> | ||
public static void LoadDir() | ||
{ | ||
_resourcePacks.Clear(); | ||
string[] subDirs = Directory.GetDirectories(MarseyVars.MarseyResourceFolder); | ||
foreach (string subdir in subDirs) | ||
{ | ||
InitializeRPack(subdir); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Creates a ResourcePack object from a given path to a directory | ||
/// </summary> | ||
/// <param name="path">resource pack directory</param> | ||
/// <param name="strict">match fork id</param> | ||
private static void InitializeRPack(string path, bool strict = false) | ||
{ | ||
ResourcePack rpack = new ResourcePack(path); | ||
|
||
try | ||
{ | ||
rpack.ParseMeta(); | ||
} | ||
catch (RPackException e) | ||
{ | ||
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using Marsey.Misc; | ||
using Newtonsoft.Json; | ||
|
||
namespace Marsey.Game.ResourcePack; | ||
|
||
/// <summary> | ||
/// Metadata class for Resource Packs | ||
/// </summary> | ||
public class ResourcePack(string dir) | ||
{ | ||
public string Dir { get; } = dir; | ||
public string? Name { get; private set; } | ||
public string? Desc { get; private set; } | ||
public string? Target { get; private set; } // Specify fork for which this is used | ||
public bool Enabled { get; set; } | ||
|
||
public void ParseMeta() | ||
{ | ||
string metaPath = Path.Combine(Dir, "meta.json"); | ||
if (!File.Exists(metaPath)) | ||
throw new RPackException($"Found folder {Dir}, but it didn't have a meta.json"); | ||
|
||
string jsonData = File.ReadAllText(metaPath); | ||
dynamic? meta = JsonConvert.DeserializeObject(jsonData); | ||
|
||
if (meta == null || meta?.Name == null || meta?.Description == null || meta?.Target == null) | ||
throw new RPackException("Meta.json is incorrectly formatted."); | ||
|
||
Name = meta?.Name ?? string.Empty; | ||
Desc = meta?.Description ?? string.Empty; | ||
Target = meta?.Target ?? string.Empty; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using System.Reflection; | ||
using HarmonyLib; | ||
using Marsey.Game.ResourcePack.Reflection; | ||
|
||
namespace Marsey.Game.ResourcePack; | ||
|
||
public static class ResourceSwapper | ||
{ | ||
private static List<string> filepaths = []; | ||
|
||
public static void Start() | ||
{ | ||
List<ResourcePack> RPacks = ResMan.GetRPacks(); | ||
foreach (ResourcePack rpack in RPacks) | ||
PopulateFiles(rpack.Dir); | ||
} | ||
|
||
private static void PopulateFiles(string directory) | ||
{ | ||
string[] files = Directory.GetFiles(directory, "*", SearchOption.AllDirectories); | ||
foreach (string file in files) | ||
{ | ||
if (file.EndsWith("meta.json")) continue; | ||
string relativePath = file.Replace(directory + Path.DirectorySeparatorChar, ""); | ||
filepaths.Add(relativePath); | ||
} | ||
} | ||
|
||
public static List<string> ResourceFiles() => filepaths; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.