Files
zzz_REBIRTH__Utils/Harmony/Harmony_XmlPatchConditionEvaluator.cs
2025-06-04 16:44:53 +09:30

64 lines
2.2 KiB
C#

using NCalc;
using System.Xml.Linq;
namespace Harmony.XmlPatchConditionEvaluatorPatches
{
[HarmonyPatch(typeof(XmlPatchConditionEvaluator))]
[HarmonyPatch("NCalcEvaluateFunction")]
public class NCalcEvaluateFunctionPatch
{
public static void isediting(FunctionArgs _args, bool invert = false)
{
bool result = GameModeEditWorld.TypeName.Equals(GamePrefs.GetString(EnumGamePrefs.GameMode));
//Log.Out("XmlPatchConditionEvaluatorPatches-isediting result: " + result);
if (invert)
{
result = !result;
}
_args.Result = result;
}
public static void scenario_selected(FunctionArgs _args, bool invert = false)
{
if (_args.Parameters.Length != 1)
throw new ArgumentException(string.Format("Calling function {0} with invalid number of arguments ({1}, expected {2})", (object)nameof(scenario_selected), (object)_args.Parameters.Length, (object)1));
if (!(_args.Parameters[0].Evaluate() is string str))
throw new ArgumentException("Calling function scenario_selected: Expected string argument");
//Log.Out("XmlPatchConditionEvaluatorPatches-scenario_selected str: " + str);
//Log.Out("XmlPatchConditionEvaluatorPatches-scenario_selected RebirthVariables.customScenario: " + RebirthVariables.customScenario);
bool result = RebirthVariables.customScenario == str.Trim();
if (invert)
{
result = !result;
}
_args.Result = result;
}
public static bool Prefix(string _name, FunctionArgs _args, bool _ignoreCase)
{
//Log.Out("XmlPatchConditionEvaluatorPatches-NCalcEvaluateFunction _name: " + _name);
if (_name.EqualsCaseInsensitive("isediting"))
isediting(_args);
if (_name.EqualsCaseInsensitive("isnotediting"))
isediting(_args, true);
if (_name.EqualsCaseInsensitive("rebirth_scenario"))
scenario_selected(_args);
if (_name.EqualsCaseInsensitive("not_rebirth_scenario"))
scenario_selected(_args, true);
return true;
}
}
}