diff --git a/Pathfinder.csproj b/Pathfinder.csproj
index b8d364da..692d4909 100644
--- a/Pathfinder.csproj
+++ b/Pathfinder.csproj
@@ -94,6 +94,7 @@
+
diff --git a/Pathfinder/Event/BasicEvents.cs b/Pathfinder/Event/BasicEvents.cs
index 2fcb8838..1a834e95 100644
--- a/Pathfinder/Event/BasicEvents.cs
+++ b/Pathfinder/Event/BasicEvents.cs
@@ -1,5 +1,16 @@
namespace Pathfinder.Event
{
+ public class ActionsLoadIntoOSEvent : PathfinderEvent
+ {
+ public Hacknet.OS OS { get; }
+ public string FilePath { get; }
+
+ public ActionsLoadIntoOSEvent(string filePath, Hacknet.OS os)
+ {
+ FilePath = filePath;
+ OS = os;
+ }
+ }
public class NetworkMapLoadContentEvent : PathfinderEvent
{
public Hacknet.NetworkMap NetMap { get; }
diff --git a/Pathfinder/Exceptions/EventException.cs b/Pathfinder/Exceptions/EventException.cs
new file mode 100644
index 00000000..ee49270f
--- /dev/null
+++ b/Pathfinder/Exceptions/EventException.cs
@@ -0,0 +1,32 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace Pathfinder.Exceptions
+{
+ public class EventException : Exception
+ {
+ public Dictionary Exceptions { get; }
+
+ private static string GenMessage(string message, Dictionary excepts)
+ {
+ var builder = new StringBuilder();
+ builder.Append(message);
+ if (excepts.Count > 0)
+ {
+ builder.Append(": ");
+ foreach (var entry in excepts)
+ builder.Append($"\n-----> Event Listener {entry.Key} threw: {entry.Value}");
+ }
+ else
+ builder.Append(".");
+
+ return builder.ToString();
+ }
+ public EventException(string message, Dictionary excepts)
+ : base(GenMessage(message, excepts))
+ {
+ Exceptions = excepts;
+ }
+ }
+}
\ No newline at end of file
diff --git a/Pathfinder/Internal/HandlerListener.cs b/Pathfinder/Internal/HandlerListener.cs
index 0baaf469..eb8141fb 100644
--- a/Pathfinder/Internal/HandlerListener.cs
+++ b/Pathfinder/Internal/HandlerListener.cs
@@ -44,6 +44,13 @@ public static void LoadContentComputerReplacementStart(LoadContentComputerStartE
e.IsCancelled = true;
}
+ public static void LoadActionsIntoOSListener(ActionsLoadIntoOSEvent e)
+ {
+ var actions = ActionsLoader.LoadConditionalActionsFromFile(e.FilePath);
+ e.OS.ConditionalActions.Actions.AddRange(actions.Actions);
+ e.IsCancelled = true;
+ }
+
public static void DaemonLoadListener(Computer c, EventExecutor exec)
{
exec.AddExecutor("Computer.ModdedDaemon", (executor, info) =>
diff --git a/Pathfinder/Pathfinder.cs b/Pathfinder/Pathfinder.cs
index 3bd5e108..8b053718 100644
--- a/Pathfinder/Pathfinder.cs
+++ b/Pathfinder/Pathfinder.cs
@@ -97,6 +97,8 @@ internal static void Initialize()
EventManager.RegisterListener(Manager.UnloadMods);
+ EventManager.RegisterListener(Internal.HandlerListener.LoadActionsIntoOSListener);
+
ActionsLoader.InitActionLoaders();
ActionsLoader.InitConditionLoaders();
diff --git a/Pathfinder/PathfinderHooks.cs b/Pathfinder/PathfinderHooks.cs
index 7a154cd2..b9b00631 100644
--- a/Pathfinder/PathfinderHooks.cs
+++ b/Pathfinder/PathfinderHooks.cs
@@ -9,6 +9,7 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Pathfinder.Attribute;
+using Pathfinder.Exceptions;
using Pathfinder.Game;
using Pathfinder.GameFilesystem;
using Pathfinder.GUI;
@@ -691,6 +692,17 @@ public static void onOptionsApply(OptionsMenu self)
optionsMenuApplyEvent.CallEvent();
}
+ [Patch("Hacknet.RunnableConditionalActions.LoadIntoOS",
+ flags: InjectFlags.PassParametersVal | InjectFlags.ModifyReturn)]
+ public static bool onLoadRunnableActionsIntoOS(string filepath, object OSobj)
+ {
+ var evt = new Event.ActionsLoadIntoOSEvent(filepath, (OS) OSobj);
+ var except = evt.CallEvent();
+ if(except.Count > 0)
+ throw new EventException("Failed to load conditional actions", except);
+ return evt.IsCancelled;
+ }
+
/* pure bug-fix patch */
[Patch("Hacknet.SCInstantly.Check", flags:
@@ -748,44 +760,6 @@ public static bool onSCOnConnectCheck(SCOnConnect self, out bool retVal, ref Com
return true;
}
- /* TODO : Fix this to use the new XML system
- [Patch("Hacknet.RunnableConditionalActions.Deserialize", flags: InjectFlags.PassParametersRef | InjectFlags.ModifyReturn)]
- public static bool onDeserializeRunnableConditionalActions(out RunnableConditionalActions result, ref XmlReader reader)
- {
- var runnable = new RunnableConditionalActions();
- var processor = new SaxProcessor();
- processor.AddActionForTag("ConditionalActions", info =>
- {
- foreach (var serialInfo in info.Elements)
- {
- var actionSet = new SerializableConditionalActionSet
- {
- Condition = Serializable.Handler.LoadCondition(serialInfo)
- };
- foreach (var actionInfo in serialInfo.Elements)
- actionSet.Actions.Add(Serializable.Handler.LoadAction(actionInfo));
- runnable.Actions.Add(actionSet);
- }
- });
- processor.Process(reader.ToStream(reader.BaseURI));
- result = runnable;
- return true;
- }*/
-
- /*public static void onAddSerializableConditions(ref Dictionary> dict)
- {
- // HACKNET BUG FIX : DoesNotHaveFlags not in dictionary
- dict.Add("DoesNotHaveFlags", info => new SCDoesNotHaveFlags { Flags = info.Attributes.GetValue("Flags") });
-
- foreach (var pair in SC.Handler.Deserializers)
- dict.Add(pair.Key, pair.Value);
- }
-
- public static void onAddSerializableActions(ref Dictionary> dict)
- {
- foreach (var pair in SA.Handler.Deserializers)
- dict.Add(pair.Key, pair.Value);
- }*/
[Patch("Hacknet.ComputerLoader.filter", flags: InjectFlags.PassParametersRef | InjectFlags.ModifyReturn)]
public static bool onFilterString(out string result, ref string input)