summaryrefslogtreecommitdiff
path: root/Thronefall_1_57/Decompile/I2.Loc.SimpleJSON
diff options
context:
space:
mode:
Diffstat (limited to 'Thronefall_1_57/Decompile/I2.Loc.SimpleJSON')
-rw-r--r--Thronefall_1_57/Decompile/I2.Loc.SimpleJSON/JSON.cs9
-rw-r--r--Thronefall_1_57/Decompile/I2.Loc.SimpleJSON/JSONArray.cs127
-rw-r--r--Thronefall_1_57/Decompile/I2.Loc.SimpleJSON/JSONBinaryTag.cs12
-rw-r--r--Thronefall_1_57/Decompile/I2.Loc.SimpleJSON/JSONClass.cs171
-rw-r--r--Thronefall_1_57/Decompile/I2.Loc.SimpleJSON/JSONData.cs92
-rw-r--r--Thronefall_1_57/Decompile/I2.Loc.SimpleJSON/JSONLazyCreator.cs193
-rw-r--r--Thronefall_1_57/Decompile/I2.Loc.SimpleJSON/JSONNode.cs526
7 files changed, 1130 insertions, 0 deletions
diff --git a/Thronefall_1_57/Decompile/I2.Loc.SimpleJSON/JSON.cs b/Thronefall_1_57/Decompile/I2.Loc.SimpleJSON/JSON.cs
new file mode 100644
index 0000000..de135ed
--- /dev/null
+++ b/Thronefall_1_57/Decompile/I2.Loc.SimpleJSON/JSON.cs
@@ -0,0 +1,9 @@
+namespace I2.Loc.SimpleJSON;
+
+public static class JSON
+{
+ public static JSONNode Parse(string aJSON)
+ {
+ return JSONNode.Parse(aJSON);
+ }
+}
diff --git a/Thronefall_1_57/Decompile/I2.Loc.SimpleJSON/JSONArray.cs b/Thronefall_1_57/Decompile/I2.Loc.SimpleJSON/JSONArray.cs
new file mode 100644
index 0000000..e2cbcef
--- /dev/null
+++ b/Thronefall_1_57/Decompile/I2.Loc.SimpleJSON/JSONArray.cs
@@ -0,0 +1,127 @@
+using System.Collections;
+using System.Collections.Generic;
+using System.IO;
+
+namespace I2.Loc.SimpleJSON;
+
+public class JSONArray : JSONNode, IEnumerable
+{
+ private List<JSONNode> m_List = new List<JSONNode>();
+
+ public override JSONNode this[int aIndex]
+ {
+ get
+ {
+ if (aIndex < 0 || aIndex >= m_List.Count)
+ {
+ return new JSONLazyCreator(this);
+ }
+ return m_List[aIndex];
+ }
+ set
+ {
+ if (aIndex < 0 || aIndex >= m_List.Count)
+ {
+ m_List.Add(value);
+ }
+ else
+ {
+ m_List[aIndex] = value;
+ }
+ }
+ }
+
+ public override JSONNode this[string aKey]
+ {
+ get
+ {
+ return new JSONLazyCreator(this);
+ }
+ set
+ {
+ m_List.Add(value);
+ }
+ }
+
+ public override int Count => m_List.Count;
+
+ public override IEnumerable<JSONNode> Childs
+ {
+ get
+ {
+ foreach (JSONNode item in m_List)
+ {
+ yield return item;
+ }
+ }
+ }
+
+ public override void Add(string aKey, JSONNode aItem)
+ {
+ m_List.Add(aItem);
+ }
+
+ public override JSONNode Remove(int aIndex)
+ {
+ if (aIndex < 0 || aIndex >= m_List.Count)
+ {
+ return null;
+ }
+ JSONNode result = m_List[aIndex];
+ m_List.RemoveAt(aIndex);
+ return result;
+ }
+
+ public override JSONNode Remove(JSONNode aNode)
+ {
+ m_List.Remove(aNode);
+ return aNode;
+ }
+
+ public IEnumerator GetEnumerator()
+ {
+ foreach (JSONNode item in m_List)
+ {
+ yield return item;
+ }
+ }
+
+ public override string ToString()
+ {
+ string text = "[ ";
+ foreach (JSONNode item in m_List)
+ {
+ if (text.Length > 2)
+ {
+ text += ", ";
+ }
+ text += item.ToString();
+ }
+ return text + " ]";
+ }
+
+ public override string ToString(string aPrefix)
+ {
+ string text = "[ ";
+ foreach (JSONNode item in m_List)
+ {
+ if (text.Length > 3)
+ {
+ text += ", ";
+ }
+ text = text + "\n" + aPrefix + " ";
+ text += item.ToString(aPrefix + " ");
+ }
+ return text + "\n" + aPrefix + "]";
+ }
+
+ public override void Serialize(BinaryWriter aWriter)
+ {
+ aWriter.Write((byte)1);
+ aWriter.Write(m_List.Count);
+ for (int i = 0; i < m_List.Count; i++)
+ {
+ m_List[i].Serialize(aWriter);
+ }
+ }
+}
diff --git a/Thronefall_1_57/Decompile/I2.Loc.SimpleJSON/JSONBinaryTag.cs b/Thronefall_1_57/Decompile/I2.Loc.SimpleJSON/JSONBinaryTag.cs
new file mode 100644
index 0000000..53df430
--- /dev/null
+++ b/Thronefall_1_57/Decompile/I2.Loc.SimpleJSON/JSONBinaryTag.cs
@@ -0,0 +1,12 @@
+namespace I2.Loc.SimpleJSON;
+
+public enum JSONBinaryTag
+{
+ Array = 1,
+ Class,
+ Value,
+ IntValue,
+ DoubleValue,
+ BoolValue,
+ FloatValue
+}
diff --git a/Thronefall_1_57/Decompile/I2.Loc.SimpleJSON/JSONClass.cs b/Thronefall_1_57/Decompile/I2.Loc.SimpleJSON/JSONClass.cs
new file mode 100644
index 0000000..da9c432
--- /dev/null
+++ b/Thronefall_1_57/Decompile/I2.Loc.SimpleJSON/JSONClass.cs
@@ -0,0 +1,171 @@
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+
+namespace I2.Loc.SimpleJSON;
+
+public class JSONClass : JSONNode, IEnumerable
+{
+ private Dictionary<string, JSONNode> m_Dict = new Dictionary<string, JSONNode>(StringComparer.Ordinal);
+
+ public override JSONNode this[string aKey]
+ {
+ get
+ {
+ if (m_Dict.ContainsKey(aKey))
+ {
+ return m_Dict[aKey];
+ }
+ return new JSONLazyCreator(this, aKey);
+ }
+ set
+ {
+ if (m_Dict.ContainsKey(aKey))
+ {
+ m_Dict[aKey] = value;
+ }
+ else
+ {
+ m_Dict.Add(aKey, value);
+ }
+ }
+ }
+
+ public override JSONNode this[int aIndex]
+ {
+ get
+ {
+ if (aIndex < 0 || aIndex >= m_Dict.Count)
+ {
+ return null;
+ }
+ return m_Dict.ElementAt(aIndex).Value;
+ }
+ set
+ {
+ if (aIndex >= 0 && aIndex < m_Dict.Count)
+ {
+ string key = m_Dict.ElementAt(aIndex).Key;
+ m_Dict[key] = value;
+ }
+ }
+ }
+
+ public override int Count => m_Dict.Count;
+
+ public override IEnumerable<JSONNode> Childs
+ {
+ get
+ {
+ foreach (KeyValuePair<string, JSONNode> item in m_Dict)
+ {
+ yield return item.Value;
+ }
+ }
+ }
+
+ public override void Add(string aKey, JSONNode aItem)
+ {
+ if (!string.IsNullOrEmpty(aKey))
+ {
+ if (m_Dict.ContainsKey(aKey))
+ {
+ m_Dict[aKey] = aItem;
+ }
+ else
+ {
+ m_Dict.Add(aKey, aItem);
+ }
+ }
+ else
+ {
+ m_Dict.Add(Guid.NewGuid().ToString(), aItem);
+ }
+ }
+
+ public override JSONNode Remove(string aKey)
+ {
+ if (!m_Dict.ContainsKey(aKey))
+ {
+ return null;
+ }
+ JSONNode result = m_Dict[aKey];
+ m_Dict.Remove(aKey);
+ return result;
+ }
+
+ public override JSONNode Remove(int aIndex)
+ {
+ if (aIndex < 0 || aIndex >= m_Dict.Count)
+ {
+ return null;
+ }
+ KeyValuePair<string, JSONNode> keyValuePair = m_Dict.ElementAt(aIndex);
+ m_Dict.Remove(keyValuePair.Key);
+ return keyValuePair.Value;
+ }
+
+ public override JSONNode Remove(JSONNode aNode)
+ {
+ try
+ {
+ KeyValuePair<string, JSONNode> keyValuePair = m_Dict.Where((KeyValuePair<string, JSONNode> k) => k.Value == aNode).First();
+ m_Dict.Remove(keyValuePair.Key);
+ return aNode;
+ }
+ catch
+ {
+ return null;
+ }
+ }
+
+ public IEnumerator GetEnumerator()
+ {
+ foreach (KeyValuePair<string, JSONNode> item in m_Dict)
+ {
+ yield return item;
+ }
+ }
+
+ public override string ToString()
+ {
+ string text = "{";
+ foreach (KeyValuePair<string, JSONNode> item in m_Dict)
+ {
+ if (text.Length > 2)
+ {
+ text += ", ";
+ }
+ text = text + "\"" + JSONNode.Escape(item.Key) + "\":" + item.Value;
+ }
+ return text + "}";
+ }
+
+ public override string ToString(string aPrefix)
+ {
+ string text = "{ ";
+ foreach (KeyValuePair<string, JSONNode> item in m_Dict)
+ {
+ if (text.Length > 3)
+ {
+ text += ", ";
+ }
+ text = text + "\n" + aPrefix + " ";
+ text = text + "\"" + JSONNode.Escape(item.Key) + "\" : " + item.Value.ToString(aPrefix + " ");
+ }
+ return text + "\n" + aPrefix + "}";
+ }
+
+ public override void Serialize(BinaryWriter aWriter)
+ {
+ aWriter.Write((byte)2);
+ aWriter.Write(m_Dict.Count);
+ foreach (string key in m_Dict.Keys)
+ {
+ aWriter.Write(key);
+ m_Dict[key].Serialize(aWriter);
+ }
+ }
+}
diff --git a/Thronefall_1_57/Decompile/I2.Loc.SimpleJSON/JSONData.cs b/Thronefall_1_57/Decompile/I2.Loc.SimpleJSON/JSONData.cs
new file mode 100644
index 0000000..a4c7160
--- /dev/null
+++ b/Thronefall_1_57/Decompile/I2.Loc.SimpleJSON/JSONData.cs
@@ -0,0 +1,92 @@
+using System.IO;
+
+namespace I2.Loc.SimpleJSON;
+
+public class JSONData : JSONNode
+{
+ private string m_Data;
+
+ public override string Value
+ {
+ get
+ {
+ return m_Data;
+ }
+ set
+ {
+ m_Data = value;
+ }
+ }
+
+ public JSONData(string aData)
+ {
+ m_Data = aData;
+ }
+
+ public JSONData(float aData)
+ {
+ AsFloat = aData;
+ }
+
+ public JSONData(double aData)
+ {
+ AsDouble = aData;
+ }
+
+ public JSONData(bool aData)
+ {
+ AsBool = aData;
+ }
+
+ public JSONData(int aData)
+ {
+ AsInt = aData;
+ }
+
+ public override string ToString()
+ {
+ return "\"" + JSONNode.Escape(m_Data) + "\"";
+ }
+
+ public override string ToString(string aPrefix)
+ {
+ return "\"" + JSONNode.Escape(m_Data) + "\"";
+ }
+
+ public override void Serialize(BinaryWriter aWriter)
+ {
+ JSONData jSONData = new JSONData("");
+ jSONData.AsInt = AsInt;
+ if (jSONData.m_Data == m_Data)
+ {
+ aWriter.Write((byte)4);
+ aWriter.Write(AsInt);
+ return;
+ }
+ jSONData.AsFloat = AsFloat;
+ if (jSONData.m_Data == m_Data)
+ {
+ aWriter.Write((byte)7);
+ aWriter.Write(AsFloat);
+ return;
+ }
+ jSONData.AsDouble = AsDouble;
+ if (jSONData.m_Data == m_Data)
+ {
+ aWriter.Write((byte)5);
+ aWriter.Write(AsDouble);
+ return;
+ }
+ jSONData.AsBool = AsBool;
+ if (jSONData.m_Data == m_Data)
+ {
+ aWriter.Write((byte)6);
+ aWriter.Write(AsBool);
+ }
+ else
+ {
+ aWriter.Write((byte)3);
+ aWriter.Write(m_Data);
+ }
+ }
+}
diff --git a/Thronefall_1_57/Decompile/I2.Loc.SimpleJSON/JSONLazyCreator.cs b/Thronefall_1_57/Decompile/I2.Loc.SimpleJSON/JSONLazyCreator.cs
new file mode 100644
index 0000000..28e23df
--- /dev/null
+++ b/Thronefall_1_57/Decompile/I2.Loc.SimpleJSON/JSONLazyCreator.cs
@@ -0,0 +1,193 @@
+namespace I2.Loc.SimpleJSON;
+
+internal class JSONLazyCreator : JSONNode
+{
+ private JSONNode m_Node;
+
+ private string m_Key;
+
+ public override JSONNode this[int aIndex]
+ {
+ get
+ {
+ return new JSONLazyCreator(this);
+ }
+ set
+ {
+ JSONArray jSONArray = new JSONArray();
+ jSONArray.Add(value);
+ Set(jSONArray);
+ }
+ }
+
+ public override JSONNode this[string aKey]
+ {
+ get
+ {
+ return new JSONLazyCreator(this, aKey);
+ }
+ set
+ {
+ JSONClass jSONClass = new JSONClass();
+ jSONClass.Add(aKey, value);
+ Set(jSONClass);
+ }
+ }
+
+ public override int AsInt
+ {
+ get
+ {
+ JSONData aVal = new JSONData(0);
+ Set(aVal);
+ return 0;
+ }
+ set
+ {
+ JSONData aVal = new JSONData(value);
+ Set(aVal);
+ }
+ }
+
+ public override float AsFloat
+ {
+ get
+ {
+ JSONData aVal = new JSONData(0f);
+ Set(aVal);
+ return 0f;
+ }
+ set
+ {
+ JSONData aVal = new JSONData(value);
+ Set(aVal);
+ }
+ }
+
+ public override double AsDouble
+ {
+ get
+ {
+ JSONData aVal = new JSONData(0.0);
+ Set(aVal);
+ return 0.0;
+ }
+ set
+ {
+ JSONData aVal = new JSONData(value);
+ Set(aVal);
+ }
+ }
+
+ public override bool AsBool
+ {
+ get
+ {
+ JSONData aVal = new JSONData(aData: false);
+ Set(aVal);
+ return false;
+ }
+ set
+ {
+ JSONData aVal = new JSONData(value);
+ Set(aVal);
+ }
+ }
+
+ public override JSONArray AsArray
+ {
+ get
+ {
+ JSONArray jSONArray = new JSONArray();
+ Set(jSONArray);
+ return jSONArray;
+ }
+ }
+
+ public override JSONClass AsObject
+ {
+ get
+ {
+ JSONClass jSONClass = new JSONClass();
+ Set(jSONClass);
+ return jSONClass;
+ }
+ }
+
+ public JSONLazyCreator(JSONNode aNode)
+ {
+ m_Node = aNode;
+ m_Key = null;
+ }
+
+ public JSONLazyCreator(JSONNode aNode, string aKey)
+ {
+ m_Node = aNode;
+ m_Key = aKey;
+ }
+
+ private void Set(JSONNode aVal)
+ {
+ if (m_Key == null)
+ {
+ m_Node.Add(aVal);
+ }
+ else
+ {
+ m_Node.Add(m_Key, aVal);
+ }
+ m_Node = null;
+ }
+
+ public override void Add(JSONNode aItem)
+ {
+ JSONArray jSONArray = new JSONArray();
+ jSONArray.Add(aItem);
+ Set(jSONArray);
+ }
+
+ public override void Add(string aKey, JSONNode aItem)
+ {
+ JSONClass jSONClass = new JSONClass();
+ jSONClass.Add(aKey, aItem);
+ Set(jSONClass);
+ }
+
+ public static bool operator ==(JSONLazyCreator a, object b)
+ {
+ if (b == null)
+ {
+ return true;
+ }
+ return (object)a == b;
+ }
+
+ public static bool operator !=(JSONLazyCreator a, object b)
+ {
+ return !(a == b);
+ }
+
+ public override bool Equals(object obj)
+ {
+ if (obj == null)
+ {
+ return true;
+ }
+ return (object)this == obj;
+ }
+
+ public override int GetHashCode()
+ {
+ return base.GetHashCode();
+ }
+
+ public override string ToString()
+ {
+ return "";
+ }
+
+ public override string ToString(string aPrefix)
+ {
+ return "";
+ }
+}
diff --git a/Thronefall_1_57/Decompile/I2.Loc.SimpleJSON/JSONNode.cs b/Thronefall_1_57/Decompile/I2.Loc.SimpleJSON/JSONNode.cs
new file mode 100644
index 0000000..a655045
--- /dev/null
+++ b/Thronefall_1_57/Decompile/I2.Loc.SimpleJSON/JSONNode.cs
@@ -0,0 +1,526 @@
+using System;
+using System.Collections.Generic;
+using System.Globalization;
+using System.IO;
+
+namespace I2.Loc.SimpleJSON;
+
+public class JSONNode
+{
+ public virtual JSONNode this[int aIndex]
+ {
+ get
+ {
+ return null;
+ }
+ set
+ {
+ }
+ }
+
+ public virtual JSONNode this[string aKey]
+ {
+ get
+ {
+ return null;
+ }
+ set
+ {
+ }
+ }
+
+ public virtual string Value
+ {
+ get
+ {
+ return "";
+ }
+ set
+ {
+ }
+ }
+
+ public virtual int Count => 0;
+
+ public virtual IEnumerable<JSONNode> Childs
+ {
+ get
+ {
+ yield break;
+ }
+ }
+
+ public IEnumerable<JSONNode> DeepChilds
+ {
+ get
+ {
+ foreach (JSONNode child in Childs)
+ {
+ foreach (JSONNode deepChild in child.DeepChilds)
+ {
+ yield return deepChild;
+ }
+ }
+ }
+ }
+
+ public virtual int AsInt
+ {
+ get
+ {
+ int result = 0;
+ if (int.TryParse(Value, out result))
+ {
+ return result;
+ }
+ return 0;
+ }
+ set
+ {
+ Value = value.ToString();
+ }
+ }
+
+ public virtual float AsFloat
+ {
+ get
+ {
+ float result = 0f;
+ if (float.TryParse(Value, out result))
+ {
+ return result;
+ }
+ return 0f;
+ }
+ set
+ {
+ Value = value.ToString();
+ }
+ }
+
+ public virtual double AsDouble
+ {
+ get
+ {
+ double result = 0.0;
+ if (double.TryParse(Value, out result))
+ {
+ return result;
+ }
+ return 0.0;
+ }
+ set
+ {
+ Value = value.ToString();
+ }
+ }
+
+ public virtual bool AsBool
+ {
+ get
+ {
+ bool result = false;
+ if (bool.TryParse(Value, out result))
+ {
+ return result;
+ }
+ return !string.IsNullOrEmpty(Value);
+ }
+ set
+ {
+ Value = (value ? "true" : "false");
+ }
+ }
+
+ public virtual JSONArray AsArray => this as JSONArray;
+
+ public virtual JSONClass AsObject => this as JSONClass;
+
+ public virtual void Add(string aKey, JSONNode aItem)
+ {
+ }
+
+ public virtual void Add(JSONNode aItem)
+ {
+ Add("", aItem);
+ }
+
+ public virtual JSONNode Remove(string aKey)
+ {
+ return null;
+ }
+
+ public virtual JSONNode Remove(int aIndex)
+ {
+ return null;
+ }
+
+ public virtual JSONNode Remove(JSONNode aNode)
+ {
+ return aNode;
+ }
+
+ public override string ToString()
+ {
+ return "JSONNode";
+ }
+
+ public virtual string ToString(string aPrefix)
+ {
+ return "JSONNode";
+ }
+
+ public static implicit operator JSONNode(string s)
+ {
+ return new JSONData(s);
+ }
+
+ public static implicit operator string(JSONNode d)
+ {
+ if (!(d == null))
+ {
+ return d.Value;
+ }
+ return null;
+ }
+
+ public static bool operator ==(JSONNode a, object b)
+ {
+ if (b == null && a is JSONLazyCreator)
+ {
+ return true;
+ }
+ return (object)a == b;
+ }
+
+ public static bool operator !=(JSONNode a, object b)
+ {
+ return !(a == b);
+ }
+
+ public override bool Equals(object obj)
+ {
+ return (object)this == obj;
+ }
+
+ public override int GetHashCode()
+ {
+ return base.GetHashCode();
+ }
+
+ internal static string Escape(string aText)
+ {
+ string text = "";
+ for (int i = 0; i < aText.Length; i++)
+ {
+ char c = aText[i];
+ text = c switch
+ {
+ '\\' => text + "\\\\",
+ '"' => text + "\\\"",
+ '\n' => text + "\\n",
+ '\r' => text + "\\r",
+ '\t' => text + "\\t",
+ '\b' => text + "\\b",
+ '\f' => text + "\\f",
+ _ => text + c,
+ };
+ }
+ return text;
+ }
+
+ public static JSONNode Parse(string aJSON)
+ {
+ Stack<JSONNode> stack = new Stack<JSONNode>();
+ JSONNode jSONNode = null;
+ int i = 0;
+ string text = "";
+ string text2 = "";
+ bool flag = false;
+ for (; i < aJSON.Length; i++)
+ {
+ switch (aJSON[i])
+ {
+ case '{':
+ if (flag)
+ {
+ text += aJSON[i];
+ break;
+ }
+ stack.Push(new JSONClass());
+ if (jSONNode != null)
+ {
+ text2 = text2.Trim();
+ if (jSONNode is JSONArray)
+ {
+ jSONNode.Add(stack.Peek());
+ }
+ else if (text2 != "")
+ {
+ jSONNode.Add(text2, stack.Peek());
+ }
+ }
+ text2 = "";
+ text = "";
+ jSONNode = stack.Peek();
+ break;
+ case '[':
+ if (flag)
+ {
+ text += aJSON[i];
+ break;
+ }
+ stack.Push(new JSONArray());
+ if (jSONNode != null)
+ {
+ text2 = text2.Trim();
+ if (jSONNode is JSONArray)
+ {
+ jSONNode.Add(stack.Peek());
+ }
+ else if (text2 != "")
+ {
+ jSONNode.Add(text2, stack.Peek());
+ }
+ }
+ text2 = "";
+ text = "";
+ jSONNode = stack.Peek();
+ break;
+ case ']':
+ case '}':
+ if (flag)
+ {
+ text += aJSON[i];
+ break;
+ }
+ if (stack.Count == 0)
+ {
+ throw new Exception("JSON Parse: Too many closing brackets");
+ }
+ stack.Pop();
+ if (text != "")
+ {
+ text2 = text2.Trim();
+ if (jSONNode is JSONArray)
+ {
+ jSONNode.Add(text);
+ }
+ else if (text2 != "")
+ {
+ jSONNode.Add(text2, text);
+ }
+ }
+ text2 = "";
+ text = "";
+ if (stack.Count > 0)
+ {
+ jSONNode = stack.Peek();
+ }
+ break;
+ case ':':
+ if (flag)
+ {
+ text += aJSON[i];
+ break;
+ }
+ text2 = text;
+ text = "";
+ break;
+ case '"':
+ flag = !flag;
+ break;
+ case ',':
+ if (flag)
+ {
+ text += aJSON[i];
+ break;
+ }
+ if (text != "")
+ {
+ if (jSONNode is JSONArray)
+ {
+ jSONNode.Add(text);
+ }
+ else if (text2 != "")
+ {
+ jSONNode.Add(text2, text);
+ }
+ }
+ text2 = "";
+ text = "";
+ break;
+ case '\t':
+ case ' ':
+ if (flag)
+ {
+ text += aJSON[i];
+ }
+ break;
+ case '\\':
+ i++;
+ if (flag)
+ {
+ char c = aJSON[i];
+ switch (c)
+ {
+ case 't':
+ text += "\t";
+ break;
+ case 'r':
+ text += "\r";
+ break;
+ case 'n':
+ text += "\n";
+ break;
+ case 'b':
+ text += "\b";
+ break;
+ case 'f':
+ text += "\f";
+ break;
+ case 'u':
+ {
+ string s = aJSON.Substring(i + 1, 4);
+ text += (char)int.Parse(s, NumberStyles.AllowHexSpecifier);
+ i += 4;
+ break;
+ }
+ default:
+ text += c;
+ break;
+ }
+ }
+ break;
+ default:
+ text += aJSON[i];
+ break;
+ case '\n':
+ case '\r':
+ break;
+ }
+ }
+ if (flag)
+ {
+ throw new Exception("JSON Parse: Quotation marks seems to be messed up.");
+ }
+ return jSONNode;
+ }
+
+ public virtual void Serialize(BinaryWriter aWriter)
+ {
+ }
+
+ public void SaveToStream(Stream aData)
+ {
+ BinaryWriter aWriter = new BinaryWriter(aData);
+ Serialize(aWriter);
+ }
+
+ public void SaveToCompressedStream(Stream aData)
+ {
+ throw new Exception("Can't use compressed functions. You need include the SharpZipLib and uncomment the define at the top of SimpleJSON");
+ }
+
+ public void SaveToCompressedFile(string aFileName)
+ {
+ throw new Exception("Can't use compressed functions. You need include the SharpZipLib and uncomment the define at the top of SimpleJSON");
+ }
+
+ public string SaveToCompressedBase64()
+ {
+ throw new Exception("Can't use compressed functions. You need include the SharpZipLib and uncomment the define at the top of SimpleJSON");
+ }
+
+ public void SaveToFile(string aFileName)
+ {
+ Directory.CreateDirectory(new FileInfo(aFileName).Directory.FullName);
+ using FileStream aData = File.OpenWrite(aFileName);
+ SaveToStream(aData);
+ }
+
+ public string SaveToBase64()
+ {
+ using MemoryStream memoryStream = new MemoryStream();
+ SaveToStream(memoryStream);
+ memoryStream.Position = 0L;
+ return Convert.ToBase64String(memoryStream.ToArray());
+ }
+
+ public static JSONNode Deserialize(BinaryReader aReader)
+ {
+ JSONBinaryTag jSONBinaryTag = (JSONBinaryTag)aReader.ReadByte();
+ switch (jSONBinaryTag)
+ {
+ case JSONBinaryTag.Array:
+ {
+ int num2 = aReader.ReadInt32();
+ JSONArray jSONArray = new JSONArray();
+ for (int j = 0; j < num2; j++)
+ {
+ jSONArray.Add(Deserialize(aReader));
+ }
+ return jSONArray;
+ }
+ case JSONBinaryTag.Class:
+ {
+ int num = aReader.ReadInt32();
+ JSONClass jSONClass = new JSONClass();
+ for (int i = 0; i < num; i++)
+ {
+ string aKey = aReader.ReadString();
+ JSONNode aItem = Deserialize(aReader);
+ jSONClass.Add(aKey, aItem);
+ }
+ return jSONClass;
+ }
+ case JSONBinaryTag.Value:
+ return new JSONData(aReader.ReadString());
+ case JSONBinaryTag.IntValue:
+ return new JSONData(aReader.ReadInt32());
+ case JSONBinaryTag.DoubleValue:
+ return new JSONData(aReader.ReadDouble());
+ case JSONBinaryTag.BoolValue:
+ return new JSONData(aReader.ReadBoolean());
+ case JSONBinaryTag.FloatValue:
+ return new JSONData(aReader.ReadSingle());
+ default:
+ throw new Exception("Error deserializing JSON. Unknown tag: " + jSONBinaryTag);
+ }
+ }
+
+ public static JSONNode LoadFromCompressedFile(string aFileName)
+ {
+ throw new Exception("Can't use compressed functions. You need include the SharpZipLib and uncomment the define at the top of SimpleJSON");
+ }
+
+ public static JSONNode LoadFromCompressedStream(Stream aData)
+ {
+ throw new Exception("Can't use compressed functions. You need include the SharpZipLib and uncomment the define at the top of SimpleJSON");
+ }
+
+ public static JSONNode LoadFromCompressedBase64(string aBase64)
+ {
+ throw new Exception("Can't use compressed functions. You need include the SharpZipLib and uncomment the define at the top of SimpleJSON");
+ }
+
+ public static JSONNode LoadFromStream(Stream aData)
+ {
+ using BinaryReader aReader = new BinaryReader(aData);
+ return Deserialize(aReader);
+ }
+
+ public static JSONNode LoadFromFile(string aFileName)
+ {
+ using FileStream aData = File.OpenRead(aFileName);
+ return LoadFromStream(aData);
+ }
+
+ public static JSONNode LoadFromBase64(string aBase64)
+ {
+ return LoadFromStream(new MemoryStream(Convert.FromBase64String(aBase64))
+ {
+ Position = 0L
+ });
+ }
+}