Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PMLSave merge #43

Merged
merged 2 commits into from
Aug 23, 2022
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
5 changes: 4 additions & 1 deletion PulsarModLoader/Patches/PLGlobalStart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ static void Prefix()

//Modmanager GUI Init.
new GameObject("ModManager", typeof(CustomGUI.GUIMain)) { hideFlags = HideFlags.HideAndDontSave };


//SaveDataManager Init()
new SaveData.SaveDataManager();

//ModLoading
string modsDir = Path.Combine(Directory.GetCurrentDirectory(), "Mods");
ModManager.Instance.LoadModsDirectory(modsDir);
Expand Down
3 changes: 3 additions & 0 deletions PulsarModLoader/PulsarModLoader.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,9 @@
<Compile Include="ModManager.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Patches\HarmonyHelpers.cs" />
<Compile Include="SaveData\DisplayModdedSavePatch.cs" />
<Compile Include="SaveData\PMLSaveData.cs" />
<Compile Include="SaveData\SaveDataManager.cs" />
<Compile Include="Utilities\Clipboard.cs" />
<Compile Include="Utilities\HelperMethods.cs" />
<Compile Include="Utilities\ExceptionWarningPatch.cs" />
Expand Down
95 changes: 95 additions & 0 deletions PulsarModLoader/SaveData/DisplayModdedSavePatch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
using HarmonyLib;
using PulsarModLoader.Patches;
using PulsarModLoader.Utilities;
using System.Collections.Generic;
using System.IO;
using System.Reflection.Emit;

namespace PulsarModLoader.SaveData
{
[HarmonyPatch(typeof(PLUILoadMenu), "Update")]
class DisplayModdedSavePatch
{
public static List<string> MFileNames = new List<string>();
static string AppendModdedLine(string originalText, PLUILoadMenu instance)
{
string Cachedname = PLNetworkManager.Instance.FileNameToRelative(instance.DataToLoad.FileName);
if (Cachedname.StartsWith("Saves/"))
{
Cachedname = Cachedname.Remove(0, 6);
}
if (instance.DataToLoad != null && MFileNames.Contains(Cachedname))
{
//Logger.Info("Appending GameInfo Line");
originalText += "\n<color=yellow>Modded</color>" + SaveDataManager.ReadMods;
}
return originalText;
}
static string CheckAddPMLSaveFileTag(string inFileName)
{
if(MFileNames.Contains(inFileName))
{
return "<color=yellow>M</color> " + inFileName;
}
else
{
return inFileName;
}
}
static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
//Handle Load Preview display
List<CodeInstruction> targetsequence = new List<CodeInstruction>()
{
new CodeInstruction(OpCodes.Ldarg_0),
new CodeInstruction(OpCodes.Ldfld, AccessTools.Field(typeof(PLUILoadMenu), "GameInfoLabel")),
new CodeInstruction(OpCodes.Ldloc_S) //(byte)14
};
List<CodeInstruction> injectedsequence = new List<CodeInstruction>()
{
new CodeInstruction(OpCodes.Ldarg_0),
new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(DisplayModdedSavePatch), "AppendModdedLine"))
};

IEnumerable<CodeInstruction> patchedInstructions = HarmonyHelpers.PatchBySequence(instructions, targetsequence, injectedsequence, checkMode: HarmonyHelpers.CheckMode.NONNULL);

//Handle Loadmenu Elements display
targetsequence = new List<CodeInstruction>()
{
new CodeInstruction(OpCodes.Ldloc_S), //(byte)7
new CodeInstruction(OpCodes.Ldfld),
new CodeInstruction(OpCodes.Ldloc_S) //(byte)8
};
injectedsequence = new List<CodeInstruction>()
{
new CodeInstruction(OpCodes.Call, AccessTools.Method(typeof(DisplayModdedSavePatch), "CheckAddPMLSaveFileTag"))
};
return HarmonyHelpers.PatchBySequence(patchedInstructions, targetsequence, injectedsequence, checkMode: HarmonyHelpers.CheckMode.NONNULL);
}
}


[HarmonyPatch(typeof(PLSaveGameIO), "AddSaveGameDataBasicFromDir")]
class ListModdedSavesPatch
{
static void Postfix()
{
List<string> MFiles = new List<string>();
foreach(SaveGameDataBasic saveDataBasic in PLSaveGameIO.Instance.SaveGamesBasic)
{
string Cachedname = saveDataBasic.FileName;
string moddedFileName = SaveDataManager.getPMLSaveFileName(Cachedname);
if (File.Exists(moddedFileName))
{
Cachedname = PLNetworkManager.Instance.FileNameToRelative(Cachedname);
if (Cachedname.StartsWith("Saves/"))
{
Cachedname = Cachedname.Remove(0, 6);
}
MFiles.Add(Cachedname);
}
}
DisplayModdedSavePatch.MFileNames = MFiles;
}
}
}
13 changes: 13 additions & 0 deletions PulsarModLoader/SaveData/PMLSaveData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System.IO;

namespace PulsarModLoader.SaveData
{
public abstract class PMLSaveData
{
public PulsarMod MyMod;
public abstract string Identifier();
public virtual uint VersionID => 0;
public abstract MemoryStream SaveData();
public abstract void LoadData(MemoryStream dataStream, uint VersionID);
}
}
Loading