From 6beac3541ea6a88ec655c40a199661706c78af03 Mon Sep 17 00:00:00 2001 From: xLinka Date: Sun, 21 Jan 2024 21:23:53 +0000 Subject: [PATCH] ALL THE STRINGS --- Bindings/Strings/CountSubstringBinding.cs | 66 ++++++++++++++++++ Bindings/Strings/DecodeBase64.cs | 61 ++++++++++++++++ Bindings/Strings/DecodeMorse.cs | 61 ++++++++++++++++ Bindings/Strings/EncodeBase64.cs | 61 ++++++++++++++++ Bindings/Strings/EncodeMD5.cs | 61 ++++++++++++++++ Bindings/Strings/EncodeMorse.cs | 61 ++++++++++++++++ Bindings/Strings/EncodeSHA256.cs | 61 ++++++++++++++++ Bindings/Strings/HMAC.cs | 69 +++++++++++++++++++ Bindings/Strings/HammingDistance.cs | 66 ++++++++++++++++++ .../Strings/HammingDistanceNonNullable.cs | 66 ++++++++++++++++++ ProtoFlux/NodeExstensions.cs | 25 +++++++ ProtoFlux/Strings/CountSubstring.cs | 27 ++++++++ ProtoFlux/Strings/DecodeBase64Node.cs | 31 +++++++++ ProtoFlux/Strings/DecodeMorseNode.cs | 39 +++++++++++ ProtoFlux/Strings/EncodeBase64Node.cs | 20 ++++++ ProtoFlux/Strings/EncodeMD5.cs | 27 ++++++++ ProtoFlux/Strings/EncodeMorse.cs | 36 ++++++++++ ProtoFlux/Strings/EncodeSHA256.cs | 29 ++++++++ ProtoFlux/Strings/HMAC.cs | 64 +++++++++++++++++ ProtoFlux/Strings/HammingDistanceNode.cs | 29 ++++++++ .../Strings/HammingDistanceNonNullableNode.cs | 30 ++++++++ 21 files changed, 990 insertions(+) create mode 100644 Bindings/Strings/CountSubstringBinding.cs create mode 100644 Bindings/Strings/DecodeBase64.cs create mode 100644 Bindings/Strings/DecodeMorse.cs create mode 100644 Bindings/Strings/EncodeBase64.cs create mode 100644 Bindings/Strings/EncodeMD5.cs create mode 100644 Bindings/Strings/EncodeMorse.cs create mode 100644 Bindings/Strings/EncodeSHA256.cs create mode 100644 Bindings/Strings/HMAC.cs create mode 100644 Bindings/Strings/HammingDistance.cs create mode 100644 Bindings/Strings/HammingDistanceNonNullable.cs create mode 100644 ProtoFlux/NodeExstensions.cs create mode 100644 ProtoFlux/Strings/CountSubstring.cs create mode 100644 ProtoFlux/Strings/DecodeBase64Node.cs create mode 100644 ProtoFlux/Strings/DecodeMorseNode.cs create mode 100644 ProtoFlux/Strings/EncodeBase64Node.cs create mode 100644 ProtoFlux/Strings/EncodeMD5.cs create mode 100644 ProtoFlux/Strings/EncodeMorse.cs create mode 100644 ProtoFlux/Strings/EncodeSHA256.cs create mode 100644 ProtoFlux/Strings/HMAC.cs create mode 100644 ProtoFlux/Strings/HammingDistanceNode.cs create mode 100644 ProtoFlux/Strings/HammingDistanceNonNullableNode.cs diff --git a/Bindings/Strings/CountSubstringBinding.cs b/Bindings/Strings/CountSubstringBinding.cs new file mode 100644 index 0000000..daf45af --- /dev/null +++ b/Bindings/Strings/CountSubstringBinding.cs @@ -0,0 +1,66 @@ +using System; +using Elements.Core; +using FrooxEngine; +using FrooxEngine.ProtoFlux; +using ProtoFlux.Core; +using ProtoFlux.Runtimes.Execution; +using ProtoFlux.Runtimes.Execution.Nodes.Strings; + +[Category(new string[] { "ProtoFlux/Runtimes/Execution/Nodes/Obsidian/String" })] +public class CountSubstringBinding : FrooxEngine.ProtoFlux.Runtimes.Execution.ValueFunctionNode +{ + public readonly SyncRef> String; + public readonly SyncRef> Pattern; + + public override Type NodeType => typeof(CountSubstringNode); + + public CountSubstringNode TypedNodeInstance { get; private set; } + + public override INode NodeInstance => TypedNodeInstance; + + public override int NodeInputCount => base.NodeInputCount + 2; + + public override N Instantiate() + { + if (TypedNodeInstance != null) + { + throw new InvalidOperationException("Node has already been instantiated"); + } + CountSubstringNode countSubstringNodeInstance = (TypedNodeInstance = new CountSubstringNode()); + return countSubstringNodeInstance as N; + } + + protected override void AssociateInstanceInternal(INode node) + { + if (node is CountSubstringNode typedNodeInstance) + { + TypedNodeInstance = typedNodeInstance; + return; + } + throw new ArgumentException("Node instance is not of type " + typeof(CountSubstringNode)); + } + + public override void ClearInstance() + { + TypedNodeInstance = null; + } + + protected override ISyncRef GetInputInternal(ref int index) + { + ISyncRef inputInternal = base.GetInputInternal(ref index); + if (inputInternal != null) + { + return inputInternal; + } + switch (index) + { + case 0: + return String; + case 1: + return Pattern; + default: + index -= 2; + return null; + } + } +} diff --git a/Bindings/Strings/DecodeBase64.cs b/Bindings/Strings/DecodeBase64.cs new file mode 100644 index 0000000..62b4724 --- /dev/null +++ b/Bindings/Strings/DecodeBase64.cs @@ -0,0 +1,61 @@ +using System; +using Elements.Core; +using FrooxEngine; +using FrooxEngine.ProtoFlux; +using ProtoFlux.Core; +using ProtoFlux.Runtimes.Execution; +using ProtoFlux.Runtimes.Execution.Nodes.Strings; + +[Category(new string[] { "ProtoFlux/Runtimes/Execution/Nodes/Obsidian/String" })] +public class DecodeBase64Binding : FrooxEngine.ProtoFlux.Runtimes.Execution.ObjectFunctionNode +{ + public readonly SyncRef> Input; + + public override Type NodeType => typeof(DecodeBase64Node); + + public DecodeBase64Node TypedNodeInstance { get; private set; } + + public override INode NodeInstance => TypedNodeInstance; + + public override int NodeInputCount => base.NodeInputCount + 1; + + public override N Instantiate() + { + if (TypedNodeInstance != null) + { + throw new InvalidOperationException("Node has already been instantiated"); + } + DecodeBase64Node decodeBase64NodeInstance = (TypedNodeInstance = new DecodeBase64Node()); + return decodeBase64NodeInstance as N; + } + + protected override void AssociateInstanceInternal(INode node) + { + if (node is DecodeBase64Node typedNodeInstance) + { + TypedNodeInstance = typedNodeInstance; + return; + } + throw new ArgumentException("Node instance is not of type " + typeof(DecodeBase64Node)); + } + + public override void ClearInstance() + { + TypedNodeInstance = null; + } + + protected override ISyncRef GetInputInternal(ref int index) + { + ISyncRef inputInternal = base.GetInputInternal(ref index); + if (inputInternal != null) + { + return inputInternal; + } + if (index == 0) + { + return Input; + } + index -= 1; + return null; + } +} diff --git a/Bindings/Strings/DecodeMorse.cs b/Bindings/Strings/DecodeMorse.cs new file mode 100644 index 0000000..8c8cfdb --- /dev/null +++ b/Bindings/Strings/DecodeMorse.cs @@ -0,0 +1,61 @@ +using System; +using Elements.Core; +using FrooxEngine; +using FrooxEngine.ProtoFlux; +using ProtoFlux.Core; +using ProtoFlux.Runtimes.Execution; +using ProtoFlux.Runtimes.Execution.Nodes.Strings; + +[Category(new string[] { "ProtoFlux/Runtimes/Execution/Nodes/Obsidian/String" })] +public class DecodeMorse : FrooxEngine.ProtoFlux.Runtimes.Execution.ObjectFunctionNode +{ + public readonly SyncRef> Input; + + public override Type NodeType => typeof(DecodeMorseNode); + + public DecodeMorseNode TypedNodeInstance { get; private set; } + + public override INode NodeInstance => TypedNodeInstance; + + public override int NodeInputCount => base.NodeInputCount + 1; + + public override N Instantiate() + { + if (TypedNodeInstance != null) + { + throw new InvalidOperationException("Node has already been instantiated"); + } + DecodeMorseNode decodeMorseNodeInstance = (TypedNodeInstance = new DecodeMorseNode()); + return decodeMorseNodeInstance as N; + } + + protected override void AssociateInstanceInternal(INode node) + { + if (node is DecodeMorseNode typedNodeInstance) + { + TypedNodeInstance = typedNodeInstance; + return; + } + throw new ArgumentException("Node instance is not of type " + typeof(DecodeMorseNode)); + } + + public override void ClearInstance() + { + TypedNodeInstance = null; + } + + protected override ISyncRef GetInputInternal(ref int index) + { + ISyncRef inputInternal = base.GetInputInternal(ref index); + if (inputInternal != null) + { + return inputInternal; + } + if (index == 0) + { + return Input; + } + index -= 1; + return null; + } +} diff --git a/Bindings/Strings/EncodeBase64.cs b/Bindings/Strings/EncodeBase64.cs new file mode 100644 index 0000000..5574ad8 --- /dev/null +++ b/Bindings/Strings/EncodeBase64.cs @@ -0,0 +1,61 @@ +using System; +using Elements.Core; +using FrooxEngine; +using FrooxEngine.ProtoFlux; +using ProtoFlux.Core; +using ProtoFlux.Runtimes.Execution; +using ProtoFlux.Runtimes.Execution.Nodes.Strings; + +[Category(new string[] { "ProtoFlux/Runtimes/Execution/Nodes/Obsidian/String" })] +public class EncodeBase64 : FrooxEngine.ProtoFlux.Runtimes.Execution.ObjectFunctionNode +{ + public readonly SyncRef> Input; + + public override Type NodeType => typeof(EncodeBase64Node); + + public EncodeBase64Node TypedNodeInstance { get; private set; } + + public override INode NodeInstance => TypedNodeInstance; + + public override int NodeInputCount => base.NodeInputCount + 1; + + public override N Instantiate() + { + if (TypedNodeInstance != null) + { + throw new InvalidOperationException("Node has already been instantiated"); + } + EncodeBase64Node encodeBase64NodeInstance = (TypedNodeInstance = new EncodeBase64Node()); + return encodeBase64NodeInstance as N; + } + + protected override void AssociateInstanceInternal(INode node) + { + if (node is EncodeBase64Node typedNodeInstance) + { + TypedNodeInstance = typedNodeInstance; + return; + } + throw new ArgumentException("Node instance is not of type " + typeof(EncodeBase64Node)); + } + + public override void ClearInstance() + { + TypedNodeInstance = null; + } + + protected override ISyncRef GetInputInternal(ref int index) + { + ISyncRef inputInternal = base.GetInputInternal(ref index); + if (inputInternal != null) + { + return inputInternal; + } + if (index == 0) + { + return Input; + } + index -= 1; + return null; + } +} diff --git a/Bindings/Strings/EncodeMD5.cs b/Bindings/Strings/EncodeMD5.cs new file mode 100644 index 0000000..6f1a169 --- /dev/null +++ b/Bindings/Strings/EncodeMD5.cs @@ -0,0 +1,61 @@ +using System; +using Elements.Core; +using FrooxEngine; +using FrooxEngine.ProtoFlux; +using ProtoFlux.Core; +using ProtoFlux.Runtimes.Execution; +using ProtoFlux.Runtimes.Execution.Nodes.Strings; + +[Category(new string[] { "ProtoFlux/Runtimes/Execution/Nodes/Obsidian/String" })] +public class EncodeMD5 : FrooxEngine.ProtoFlux.Runtimes.Execution.ObjectFunctionNode +{ + public readonly SyncRef> Input; + + public override Type NodeType => typeof(EncodeMD5Node); + + public EncodeMD5Node TypedNodeInstance { get; private set; } + + public override INode NodeInstance => TypedNodeInstance; + + public override int NodeInputCount => base.NodeInputCount + 1; + + public override N Instantiate() + { + if (TypedNodeInstance != null) + { + throw new InvalidOperationException("Node has already been instantiated"); + } + EncodeMD5Node encodeMD5NodeInstance = (TypedNodeInstance = new EncodeMD5Node()); + return encodeMD5NodeInstance as N; + } + + protected override void AssociateInstanceInternal(INode node) + { + if (node is EncodeMD5Node typedNodeInstance) + { + TypedNodeInstance = typedNodeInstance; + return; + } + throw new ArgumentException("Node instance is not of type " + typeof(EncodeMD5Node)); + } + + public override void ClearInstance() + { + TypedNodeInstance = null; + } + + protected override ISyncRef GetInputInternal(ref int index) + { + ISyncRef inputInternal = base.GetInputInternal(ref index); + if (inputInternal != null) + { + return inputInternal; + } + if (index == 0) + { + return Input; + } + index -= 1; + return null; + } +} diff --git a/Bindings/Strings/EncodeMorse.cs b/Bindings/Strings/EncodeMorse.cs new file mode 100644 index 0000000..7fdd1df --- /dev/null +++ b/Bindings/Strings/EncodeMorse.cs @@ -0,0 +1,61 @@ +using System; +using Elements.Core; +using FrooxEngine; +using FrooxEngine.ProtoFlux; +using ProtoFlux.Core; +using ProtoFlux.Runtimes.Execution; +using ProtoFlux.Runtimes.Execution.Nodes.Strings; + +[Category(new string[] { "ProtoFlux/Runtimes/Execution/Nodes/Obsidian/String" })] +public class EncodeMorse : FrooxEngine.ProtoFlux.Runtimes.Execution.ObjectFunctionNode +{ + public readonly SyncRef> Input; + + public override Type NodeType => typeof(EncodeMorseNode); + + public EncodeMorseNode TypedNodeInstance { get; private set; } + + public override INode NodeInstance => TypedNodeInstance; + + public override int NodeInputCount => base.NodeInputCount + 1; + + public override N Instantiate() + { + if (TypedNodeInstance != null) + { + throw new InvalidOperationException("Node has already been instantiated"); + } + EncodeMorseNode encodeMorseNodeInstance = (TypedNodeInstance = new EncodeMorseNode()); + return encodeMorseNodeInstance as N; + } + + protected override void AssociateInstanceInternal(INode node) + { + if (node is EncodeMorseNode typedNodeInstance) + { + TypedNodeInstance = typedNodeInstance; + return; + } + throw new ArgumentException("Node instance is not of type " + typeof(EncodeMorseNode)); + } + + public override void ClearInstance() + { + TypedNodeInstance = null; + } + + protected override ISyncRef GetInputInternal(ref int index) + { + ISyncRef inputInternal = base.GetInputInternal(ref index); + if (inputInternal != null) + { + return inputInternal; + } + if (index == 0) + { + return Input; + } + index -= 1; + return null; + } +} diff --git a/Bindings/Strings/EncodeSHA256.cs b/Bindings/Strings/EncodeSHA256.cs new file mode 100644 index 0000000..23c7142 --- /dev/null +++ b/Bindings/Strings/EncodeSHA256.cs @@ -0,0 +1,61 @@ +using System; +using Elements.Core; +using FrooxEngine; +using FrooxEngine.ProtoFlux; +using ProtoFlux.Core; +using ProtoFlux.Runtimes.Execution; +using ProtoFlux.Runtimes.Execution.Nodes.Strings; + +[Category(new string[] { "ProtoFlux/Runtimes/Execution/Nodes/Obsidian/String" })] +public class EncodeSha256Binding : FrooxEngine.ProtoFlux.Runtimes.Execution.ObjectFunctionNode +{ + public readonly SyncRef> Input; + + public override Type NodeType => typeof(EncodeSha256Node); + + public EncodeSha256Node TypedNodeInstance { get; private set; } + + public override INode NodeInstance => TypedNodeInstance; + + public override int NodeInputCount => base.NodeInputCount + 1; + + public override N Instantiate() + { + if (TypedNodeInstance != null) + { + throw new InvalidOperationException("Node has already been instantiated"); + } + EncodeSha256Node encodeSha256NodeInstance = (TypedNodeInstance = new EncodeSha256Node()); + return encodeSha256NodeInstance as N; + } + + protected override void AssociateInstanceInternal(INode node) + { + if (node is EncodeSha256Node typedNodeInstance) + { + TypedNodeInstance = typedNodeInstance; + return; + } + throw new ArgumentException("Node instance is not of type " + typeof(EncodeSha256Node)); + } + + public override void ClearInstance() + { + TypedNodeInstance = null; + } + + protected override ISyncRef GetInputInternal(ref int index) + { + ISyncRef inputInternal = base.GetInputInternal(ref index); + if (inputInternal != null) + { + return inputInternal; + } + if (index == 0) + { + return Input; + } + index -= 1; + return null; + } +} diff --git a/Bindings/Strings/HMAC.cs b/Bindings/Strings/HMAC.cs new file mode 100644 index 0000000..e0f69fe --- /dev/null +++ b/Bindings/Strings/HMAC.cs @@ -0,0 +1,69 @@ +using System; +using Elements.Core; +using FrooxEngine; +using FrooxEngine.ProtoFlux; +using ProtoFlux.Core; +using ProtoFlux.Runtimes.Execution; +using ProtoFlux.Runtimes.Execution.Nodes.Strings; + +[Category(new string[] { "ProtoFlux/Runtimes/Execution/Nodes/Obsidian/String" })] +public class EncodeHMAC : FrooxEngine.ProtoFlux.Runtimes.Execution.ObjectFunctionNode +{ + public readonly SyncRef> Message; + public readonly SyncRef> Key; + public readonly SyncRef> HashAlgorithm; + + public override Type NodeType => typeof(HMACNode); + + public HMACNode TypedNodeInstance { get; private set; } + + public override INode NodeInstance => TypedNodeInstance; + + public override int NodeInputCount => base.NodeInputCount + 3; + + public override N Instantiate() + { + if (TypedNodeInstance != null) + { + throw new InvalidOperationException("Node has already been instantiated"); + } + HMACNode hmacNodeInstance = (TypedNodeInstance = new HMACNode()); + return hmacNodeInstance as N; + } + + protected override void AssociateInstanceInternal(INode node) + { + if (node is HMACNode typedNodeInstance) + { + TypedNodeInstance = typedNodeInstance; + return; + } + throw new ArgumentException("Node instance is not of type " + typeof(HMACNode)); + } + + public override void ClearInstance() + { + TypedNodeInstance = null; + } + + protected override ISyncRef GetInputInternal(ref int index) + { + ISyncRef inputInternal = base.GetInputInternal(ref index); + if (inputInternal != null) + { + return inputInternal; + } + switch (index) + { + case 0: + return Message; + case 1: + return Key; + case 2: + return HashAlgorithm; + default: + index -= 3; + return null; + } + } +} diff --git a/Bindings/Strings/HammingDistance.cs b/Bindings/Strings/HammingDistance.cs new file mode 100644 index 0000000..fbaae3c --- /dev/null +++ b/Bindings/Strings/HammingDistance.cs @@ -0,0 +1,66 @@ +using System; +using Elements.Core; +using FrooxEngine; +using FrooxEngine.ProtoFlux; +using ProtoFlux.Core; +using ProtoFlux.Runtimes.Execution; +using ProtoFlux.Runtimes.Execution.Nodes.Strings; + +[Category(new string[] { "ProtoFlux/Runtimes/Execution/Nodes/Obsidian/String" })] +public class HammingDistanceBinding : FrooxEngine.ProtoFlux.Runtimes.Execution.ObjectFunctionNode +{ + public readonly SyncRef> String1; + public readonly SyncRef> String2; + + public override Type NodeType => typeof(HammingDistanceNode); + + public HammingDistanceNode TypedNodeInstance { get; private set; } + + public override INode NodeInstance => TypedNodeInstance; + + public override int NodeInputCount => base.NodeInputCount + 2; + + public override N Instantiate() + { + if (TypedNodeInstance != null) + { + throw new InvalidOperationException("Node has already been instantiated"); + } + HammingDistanceNode hammingDistanceNodeInstance = (TypedNodeInstance = new HammingDistanceNode()); + return hammingDistanceNodeInstance as N; + } + + protected override void AssociateInstanceInternal(INode node) + { + if (node is HammingDistanceNode typedNodeInstance) + { + TypedNodeInstance = typedNodeInstance; + return; + } + throw new ArgumentException("Node instance is not of type " + typeof(HammingDistanceNode)); + } + + public override void ClearInstance() + { + TypedNodeInstance = null; + } + + protected override ISyncRef GetInputInternal(ref int index) + { + ISyncRef inputInternal = base.GetInputInternal(ref index); + if (inputInternal != null) + { + return inputInternal; + } + switch (index) + { + case 0: + return String1; + case 1: + return String2; + default: + index -= 2; + return null; + } + } +} diff --git a/Bindings/Strings/HammingDistanceNonNullable.cs b/Bindings/Strings/HammingDistanceNonNullable.cs new file mode 100644 index 0000000..5da47f1 --- /dev/null +++ b/Bindings/Strings/HammingDistanceNonNullable.cs @@ -0,0 +1,66 @@ +using System; +using Elements.Core; +using FrooxEngine; +using FrooxEngine.ProtoFlux; +using ProtoFlux.Core; +using ProtoFlux.Runtimes.Execution; +using ProtoFlux.Runtimes.Execution.Nodes.Strings; + +[Category(new string[] { "ProtoFlux/Runtimes/Execution/Nodes/Obsidian/String" })] +public class HammingDistanceNonNullable : FrooxEngine.ProtoFlux.Runtimes.Execution.ValueFunctionNode +{ + public readonly SyncRef> String1; + public readonly SyncRef> String2; + + public override Type NodeType => typeof(HammingDistanceNonNullableNode); + + public HammingDistanceNonNullableNode TypedNodeInstance { get; private set; } + + public override INode NodeInstance => TypedNodeInstance; + + public override int NodeInputCount => base.NodeInputCount + 2; + + public override N Instantiate() + { + if (TypedNodeInstance != null) + { + throw new InvalidOperationException("Node has already been instantiated"); + } + HammingDistanceNonNullableNode hammingDistanceNonNullableNodeInstance = (TypedNodeInstance = new HammingDistanceNonNullableNode()); + return hammingDistanceNonNullableNodeInstance as N; + } + + protected override void AssociateInstanceInternal(INode node) + { + if (node is HammingDistanceNonNullableNode typedNodeInstance) + { + TypedNodeInstance = typedNodeInstance; + return; + } + throw new ArgumentException("Node instance is not of type " + typeof(HammingDistanceNonNullableNode)); + } + + public override void ClearInstance() + { + TypedNodeInstance = null; + } + + protected override ISyncRef GetInputInternal(ref int index) + { + ISyncRef inputInternal = base.GetInputInternal(ref index); + if (inputInternal != null) + { + return inputInternal; + } + switch (index) + { + case 0: + return String1; + case 1: + return String2; + default: + index -= 2; + return null; + } + } +} diff --git a/ProtoFlux/NodeExstensions.cs b/ProtoFlux/NodeExstensions.cs new file mode 100644 index 0000000..30f7f84 --- /dev/null +++ b/ProtoFlux/NodeExstensions.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using Elements.Core; +using FrooxEngine; +using FrooxEngine.ProtoFlux; +using FrooxEngine.UIX; + +namespace Obsidian; +public static class NodeExtensions +{ + public static readonly Dictionary CharToMorse = new() + { + {'A', ".-"}, {'B', "-..."}, {'C', "-.-."}, {'D', "-.."}, {'E', "."}, + {'F', "..-."}, {'G', "--."}, {'H', "...."}, {'I', ".."}, {'J', ".---"}, + {'K', "-.-"}, {'L', ".-.."}, {'M', "--"}, {'N', "-."}, {'O', "---"}, + {'P', ".--."}, {'Q', "--.-"}, {'R', ".-."}, {'S', "..."}, {'T', "-"}, + {'U', "..-"}, {'V', "...-"}, {'W', ".--"}, {'X', "-..-"}, {'Y', "-.--"}, + {'Z', "--.."}, {'1', ".----"}, {'2', "..---"}, {'3', "...--"}, {'4', "....-"}, + {'5', "....."}, {'6', "-...."}, {'7', "--..."}, {'8', "---.."}, {'9', "----."}, + {'0', "-----"} + }; + + public static readonly Dictionary MorseToChar = CharToMorse.ToDictionary(i => i.Value, j => j.Key); +} \ No newline at end of file diff --git a/ProtoFlux/Strings/CountSubstring.cs b/ProtoFlux/Strings/CountSubstring.cs new file mode 100644 index 0000000..5a5834a --- /dev/null +++ b/ProtoFlux/Strings/CountSubstring.cs @@ -0,0 +1,27 @@ +using System; +using FrooxEngine; +using ProtoFlux.Core; +using ProtoFlux.Runtimes.Execution; + +namespace ProtoFlux.Runtimes.Execution.Nodes.Strings +{ + [NodeCategory("ProtoFlux/Obsidian/String")] + public class CountSubstringNode : ValueFunctionNode + { + public readonly ObjectInput String; + public readonly ObjectInput Pattern; + + protected override int Compute(ExecutionContext context) + { + var str = String.Evaluate(context); + var pattern = Pattern.Evaluate(context); + + if (string.IsNullOrEmpty(str) || string.IsNullOrEmpty(pattern)) + { + return 0; + } + + return (str.Length - str.Replace(pattern, "").Length) / pattern.Length; + } + } +} diff --git a/ProtoFlux/Strings/DecodeBase64Node.cs b/ProtoFlux/Strings/DecodeBase64Node.cs new file mode 100644 index 0000000..7a410d5 --- /dev/null +++ b/ProtoFlux/Strings/DecodeBase64Node.cs @@ -0,0 +1,31 @@ +using System; +using System.Text; +using FrooxEngine; +using ProtoFlux.Core; +using ProtoFlux.Runtimes.Execution; + +namespace ProtoFlux.Runtimes.Execution.Nodes.Strings +{ + [NodeCategory("ProtoFlux/Obsidian/String")] + public class DecodeBase64Node : ObjectFunctionNode + { + public readonly ObjectInput Input; + + protected override string Compute(ExecutionContext context) + { + var input = Input.Evaluate(context); + if (string.IsNullOrEmpty(input)) return null; + + try + { + byte[] base64EncodedBytes = Convert.FromBase64String(input); + return Encoding.UTF8.GetString(base64EncodedBytes); + } + catch + { + // Return null or handle the error as required + return null; + } + } + } +} diff --git a/ProtoFlux/Strings/DecodeMorseNode.cs b/ProtoFlux/Strings/DecodeMorseNode.cs new file mode 100644 index 0000000..e22153f --- /dev/null +++ b/ProtoFlux/Strings/DecodeMorseNode.cs @@ -0,0 +1,39 @@ +using System; +using System.Text; +using FrooxEngine; +using Obsidian; +using ProtoFlux.Core; +using ProtoFlux.Runtimes.Execution; + +namespace ProtoFlux.Runtimes.Execution.Nodes.Strings +{ + [NodeCategory("ProtoFlux/Obsidian/String")] + public class DecodeMorseNode : ObjectFunctionNode + { + public readonly ObjectInput Input; + + protected override string Compute(ExecutionContext context) + { + var input = Input.Evaluate(context); + if (string.IsNullOrWhiteSpace(input)) + return null; + + var words = input.Split('/'); + var result = new StringBuilder(); + foreach (var word in words) + { + var characters = word.Split(' '); + if (string.IsNullOrWhiteSpace(word)) continue; + + foreach (var character in characters) + { + if (string.IsNullOrWhiteSpace(character)) continue; + if (NodeExtensions.MorseToChar.TryGetValue(character, out var ch)) + result.Append(ch); + } + result.Append(' '); + } + return result.ToString().Trim(); + } + } +} diff --git a/ProtoFlux/Strings/EncodeBase64Node.cs b/ProtoFlux/Strings/EncodeBase64Node.cs new file mode 100644 index 0000000..488b454 --- /dev/null +++ b/ProtoFlux/Strings/EncodeBase64Node.cs @@ -0,0 +1,20 @@ +using System; +using System.Text; +using FrooxEngine; +using ProtoFlux.Core; +using ProtoFlux.Runtimes.Execution; + +namespace ProtoFlux.Runtimes.Execution.Nodes.Strings +{ + [NodeCategory("ProtoFlux/Obsidian/String")] + public class EncodeBase64Node : ObjectFunctionNode + { + public readonly ObjectInput Input; + + protected override string Compute(ExecutionContext context) + { + var input = Input.Evaluate(context); + return string.IsNullOrEmpty(input) ? null : Convert.ToBase64String(Encoding.UTF8.GetBytes(input)); + } + } +} diff --git a/ProtoFlux/Strings/EncodeMD5.cs b/ProtoFlux/Strings/EncodeMD5.cs new file mode 100644 index 0000000..1ce2c72 --- /dev/null +++ b/ProtoFlux/Strings/EncodeMD5.cs @@ -0,0 +1,27 @@ +using System; +using System.Security.Cryptography; +using System.Text; +using FrooxEngine; +using ProtoFlux.Core; +using ProtoFlux.Runtimes.Execution; + +namespace ProtoFlux.Runtimes.Execution.Nodes.Strings +{ + [NodeCategory("ProtoFlux/Obsidian/String")] + public class EncodeMD5Node : ObjectFunctionNode + { + private static readonly MD5CryptoServiceProvider MD5 = new MD5CryptoServiceProvider(); + public readonly ObjectInput Input; + + protected override string Compute(ExecutionContext context) + { + var input = Input.Evaluate(context); + if (string.IsNullOrEmpty(input)) + return null; + + byte[] inputBytes = Encoding.UTF8.GetBytes(input); + byte[] hashBytes = MD5.ComputeHash(inputBytes); + return BitConverter.ToString(hashBytes).Replace("-", "").ToLower(); + } + } +} diff --git a/ProtoFlux/Strings/EncodeMorse.cs b/ProtoFlux/Strings/EncodeMorse.cs new file mode 100644 index 0000000..7f715db --- /dev/null +++ b/ProtoFlux/Strings/EncodeMorse.cs @@ -0,0 +1,36 @@ +using System; +using System.Text; +using FrooxEngine; +using ProtoFlux.Core; +using ProtoFlux.Runtimes.Execution; +using Obsidian; + +namespace ProtoFlux.Runtimes.Execution.Nodes.Strings +{ + [NodeCategory("ProtoFlux/Obsidian/String")] + public class EncodeMorseNode : ObjectFunctionNode + { + public readonly ObjectInput Input; + + protected override string Compute(ExecutionContext context) + { + var input = Input.Evaluate(context); + if (string.IsNullOrWhiteSpace(input)) + return null; + + input = input.ToUpperInvariant(); + var result = new StringBuilder(); + foreach (var c in input) + { + if (c == ' ') + { + result.Append("/ "); + continue; + } + if (NodeExtensions.CharToMorse.TryGetValue(c, out var morseChar)) + result.Append(morseChar + " "); + } + return result.ToString().TrimEnd(); + } + } +} diff --git a/ProtoFlux/Strings/EncodeSHA256.cs b/ProtoFlux/Strings/EncodeSHA256.cs new file mode 100644 index 0000000..e28332e --- /dev/null +++ b/ProtoFlux/Strings/EncodeSHA256.cs @@ -0,0 +1,29 @@ +using System; +using System.Security.Cryptography; +using System.Text; +using FrooxEngine; +using ProtoFlux.Core; +using ProtoFlux.Runtimes.Execution; + +namespace ProtoFlux.Runtimes.Execution.Nodes.Strings +{ + [NodeCategory("ProtoFlux/Obsidian/String")] + public class EncodeSha256Node : ObjectFunctionNode + { + private static readonly SHA256 SHA = SHA256.Create(); + public readonly ObjectInput Input; + + + + protected override string Compute(ExecutionContext context) + { + var input = Input.Evaluate(context); + if (string.IsNullOrEmpty(input)) + return null; + + byte[] inputBytes = Encoding.UTF8.GetBytes(input); + byte[] hashBytes = SHA.ComputeHash(inputBytes); + return BitConverter.ToString(hashBytes).Replace("-", "").ToLower(); + } + } +} diff --git a/ProtoFlux/Strings/HMAC.cs b/ProtoFlux/Strings/HMAC.cs new file mode 100644 index 0000000..edf0633 --- /dev/null +++ b/ProtoFlux/Strings/HMAC.cs @@ -0,0 +1,64 @@ +using System; +using System.Security.Cryptography; +using System.Text; +using FrooxEngine; +using ProtoFlux.Core; +using ProtoFlux.Runtimes.Execution; + +namespace ProtoFlux.Runtimes.Execution.Nodes.Strings +{ + public enum HashFunction + { + MD5, + SHA1, + SHA256, + SHA384, + SHA512 + } + + [NodeCategory("ProtoFlux/Obsidian/String")] + public class HMACNode : ObjectFunctionNode + { + public readonly ObjectInput Message; + public readonly ObjectInput Key; + public readonly ObjectInput HashAlgorithm; + + protected override string Compute(ExecutionContext context) + { + string message = Message.Evaluate(context); + string key = Key.Evaluate(context); + HashFunction hashFunction = HashAlgorithm.Evaluate(context); + + if (string.IsNullOrEmpty(message) || string.IsNullOrEmpty(key)) + return ""; + + byte[] keyBytes = Encoding.UTF8.GetBytes(key); + byte[] messageBytes = Encoding.UTF8.GetBytes(message); + + using (HMAC hmac = GetHMAC(hashFunction, keyBytes)) + { + byte[] hash = hmac.ComputeHash(messageBytes); + return BitConverter.ToString(hash).Replace("-", "").ToLower(); + } + } + + private HMAC GetHMAC(HashFunction hashFunction, byte[] key) + { + switch (hashFunction) + { + case HashFunction.MD5: + return new HMACMD5(key); + case HashFunction.SHA1: + return new HMACSHA1(key); + case HashFunction.SHA256: + return new HMACSHA256(key); + case HashFunction.SHA384: + return new HMACSHA384(key); + case HashFunction.SHA512: + return new HMACSHA512(key); + default: + throw new ArgumentException($"Unsupported hash function {hashFunction}"); + } + } + } +} diff --git a/ProtoFlux/Strings/HammingDistanceNode.cs b/ProtoFlux/Strings/HammingDistanceNode.cs new file mode 100644 index 0000000..b9c5a38 --- /dev/null +++ b/ProtoFlux/Strings/HammingDistanceNode.cs @@ -0,0 +1,29 @@ +using System; +using FrooxEngine; +using FrooxEngine.ProtoFlux; +using ProtoFlux.Core; +using ProtoFlux.Runtimes.Execution; + +namespace ProtoFlux.Runtimes.Execution.Nodes.Strings +{ + [NodeCategory("ProtoFlux/Obsidian/String")] + public class HammingDistanceNode : ObjectFunctionNode + { + public readonly ObjectInput String1; + public readonly ObjectInput String2; + + protected override int? Compute(FrooxEngineContext context) + { + var string1 = String1.Evaluate(context); + var string2 = String2.Evaluate(context); + if (string1 == null || string2 == null || string1.Length != string2.Length) + return null; + + var count = 0; + for (var i = 0; i < string1.Length; i++) + if (string1[i] != string2[i]) + count++; + return count; + } + } +} diff --git a/ProtoFlux/Strings/HammingDistanceNonNullableNode.cs b/ProtoFlux/Strings/HammingDistanceNonNullableNode.cs new file mode 100644 index 0000000..c06702b --- /dev/null +++ b/ProtoFlux/Strings/HammingDistanceNonNullableNode.cs @@ -0,0 +1,30 @@ +using System; +using FrooxEngine; +using ProtoFlux.Core; +using ProtoFlux.Runtimes.Execution; + +namespace ProtoFlux.Runtimes.Execution.Nodes.Strings +{ + [NodeCategory("ProtoFlux/Obsidian/String")] + public class HammingDistanceNonNullableNode : ValueFunctionNode + { + public readonly ObjectInput String1; + public readonly ObjectInput String2; + + + + protected override int Compute(ExecutionContext context) + { + var string1 = String1.Evaluate(context); + var string2 = String2.Evaluate(context); + if (string1 == null || string2 == null || string1.Length != string2.Length) + return -1; + + var count = 0; + for (var i = 0; i < string1.Length; i++) + if (string1[i] != string2[i]) + count++; + return count; + } + } +}