// Decompiled with JetBrains decompiler // Type: RefuelingNozzle.SectionScript // Assembly: RefuelingNozzle.net, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null // MVID: 78F50B7E-6755-4A9F-896E-A83F58106523 // Assembly location: D:\Programmierstuff\C#\FiveM\RefuelingNozzle\Librarys\RefuelingNozzle.net.dll using CitizenFX.Core.Native; using System; using System.Collections.Generic; using System.Linq; namespace RefuelingNozzle { internal class SectionScript : IDisposable { public char SPLIT_CHAR = ' '; public string SECTION_START = "{"; public string SECTION_END = "}"; public string COMMENT_PREFIX = "//"; public int LINES_BETWEEN_SECTIONS = 1; public string FileName = ""; private List>> LoadedData = new List>>(); private List AllSections = new List(); public SectionScript() { } public SectionScript(string FileName, bool load = false) { this.FileName = FileName; if (!load) return; this.Read(); } public string this[string section, string key, string result = ""] => this.GetValue(section, key, result); public T GetValue(string section, string key, T result) { if (!this.SectionExists(section)) return result; string data = this.GetData(section, key, result.ToString()); if (data is T data1) return data1; try { return (T)Convert.ChangeType((object)data, typeof(T)); } catch (InvalidCastException ex) { return result; } } public string GetData(string section, string key, string result) { foreach (Tuple> tuple in this.LoadedData) { if (tuple.Item1.Equals(section)) return tuple.Item2.ContainsKey(key) ? tuple.Item2[key] : result; } return result; } public bool SectionExists(string section) => this.AllSections.Contains(section); public List>> GetAllSections() => this.LoadedData.ToList>>(); public List GetAllSectionNames() => this.AllSections.ToList(); public void Read() { this.LoadedData.Clear(); this.AllSections.Clear(); string str1 = ""; Dictionary source = new Dictionary(); string str2 = API.LoadResourceFile(API.GetCurrentResourceName(), this.FileName); char[] chArray = new char[1] { '\n' }; foreach (string str3 in str2.Split(chArray)) { string text = str3.Replace("\r", ""); if (!string.IsNullOrEmpty(text) && !string.IsNullOrWhiteSpace(text)) { if (text.StartsWith(this.SECTION_START)) { str1 = text.Substring(1); if (text.EndsWith(this.SECTION_END) && !str1.Contains(this.SECTION_START)) { str1 = str1.Remove(str1.Length - 1, 1); this.LoadedData.Add( new Tuple>(str1, new Dictionary())); if (!this.AllSections.Contains(str1)) this.AllSections.Add(str1); source.Clear(); } } else if (text.EndsWith(this.SECTION_END) || text.StartsWith(this.SECTION_END)) { Dictionary dictionary = source.ToDictionary, string, string>( (Func, string>)(entry => entry.Key), (Func, string>)(entry => entry.Value)); this.LoadedData.Add(new Tuple>(str1, dictionary)); if (!this.AllSections.Contains(str1)) this.AllSections.Add(str1); source.Clear(); } else if (!text.StartsWith(this.COMMENT_PREFIX)) { Tuple data = this.ConvertToData(text); if (!source.ContainsKey(data.Item1)) source.Add(data.Item1, data.Item2); } } } } public Tuple ConvertToData(string text) { int length = text.IndexOf(this.SPLIT_CHAR); if (length == -1) return new Tuple(text, ""); string str = ""; if (length - 1 < text.Length) str = text.Substring(length + 1, text.Length - length - 1); return new Tuple(text.Substring(0, length), str); } public void Dispose() { this.Dispose(true); GC.SuppressFinalize((object)this); } protected virtual void Dispose(bool disposing) { if (!disposing) return; this.FileName = ""; this.LoadedData.Clear(); this.AllSections.Clear(); } } }