using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using System.Text; using System.Text.Json.Serialization; using GDWeave; using GDWeave.Godot; using GDWeave.Godot.Variants; using GDWeave.Modding; using util.LexicalTransformer; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(/*Could not decode attribute arguments.*/)] [assembly: TargetFramework(".NETCoreApp,Version=v8.0", FrameworkDisplayName = ".NET 8.0")] [assembly: AssemblyCompany("Toes")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("0.0.1.0")] [assembly: AssemblyInformationalVersion("0.0.1+abfb4f9fcf2a1ef83ebed2e0ad986f4fd486f133")] [assembly: AssemblyProduct("Shaderade")] [assembly: AssemblyTitle("Shaderade")] [assembly: AssemblyVersion("0.0.1.0")] [module: RefSafetyRules(11)] namespace util { public enum BuiltinFunc : uint { sin, cos, tan, sinh, cosh, tanh, asin, acos, atan, atan2, sqrt, fmod, fposmod, posmod, floor, ceil, round, abs, sign, pow, log, exp, is_nan, is_inf, is_equal_approx, is_zero_approx, ease, decimals, step_decimals, stepify, lerp, lerp_angle, inverse_lerp, range_lerp, smoothstep, move_toward, dectime, randomize, randi, randf, rand_range, seed, rand_seed, deg2rad, rad2deg, linear2db, db2linear, polar2cartesian, cartesian2polar, wrapi, wrapf, max, min, clamp, nearest_po2, weakref, funcref, convert, @typeof, type_exists, @char, ord, str, print, printt, prints, printerr, printraw, print_debug, push_error, push_warning, var2str, str2var, var2bytes, bytes2var, range, load, inst2dict, dict2inst, validate_json, parse_json, to_json, hash, Color8, ColorN, print_stack, get_stack, instance_from_id, len, is_instance_valid, deep_equal, MAX } public static class ScriptTokenizer { [StructLayout(3)] [CompilerGenerated] private struct <>c__DisplayClass7_0 { public StringBuilder builder; } [CompilerGenerated] private sealed class d__6 : global::System.Collections.Generic.IEnumerable, global::System.Collections.IEnumerable, global::System.Collections.Generic.IEnumerator, global::System.Collections.IEnumerator, global::System.IDisposable { private int <>1__state; private string <>2__current; private int <>l__initialThreadId; private global::System.Collections.Generic.IEnumerable tokens; public global::System.Collections.Generic.IEnumerable <>3__tokens; private global::System.Collections.Generic.IEnumerator <>7__wrap1; string global::System.Collections.Generic.IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } object global::System.Collections.IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public d__6(int <>1__state) { this.<>1__state = <>1__state; <>l__initialThreadId = Environment.CurrentManagedThreadId; } [DebuggerHidden] void global::System.IDisposable.Dispose() { int num = <>1__state; if (num == -3 || num == 1) { try { } finally { <>m__Finally1(); } } <>7__wrap1 = null; <>1__state = -2; } private bool MoveNext() { try { switch (<>1__state) { default: return false; case 0: <>1__state = -1; <>7__wrap1 = tokens.GetEnumerator(); <>1__state = -3; break; case 1: <>1__state = -3; break; } while (((global::System.Collections.IEnumerator)<>7__wrap1).MoveNext()) { string current = <>7__wrap1.Current; if (!(current != "\n") || !string.IsNullOrWhiteSpace(current)) { <>2__current = current; <>1__state = 1; return true; } } <>m__Finally1(); <>7__wrap1 = null; return false; } catch { //try-fault ((global::System.IDisposable)this).Dispose(); throw; } } bool global::System.Collections.IEnumerator.MoveNext() { //ILSpy generated this explicit interface implementation from .override directive in MoveNext return this.MoveNext(); } private void <>m__Finally1() { <>1__state = -1; if (<>7__wrap1 != null) { ((global::System.IDisposable)<>7__wrap1).Dispose(); } } [DebuggerHidden] void global::System.Collections.IEnumerator.Reset() { //IL_0000: Unknown result type (might be due to invalid IL or missing references) throw new NotSupportedException(); } [DebuggerHidden] global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() { d__6 d__; if (<>1__state == -2 && <>l__initialThreadId == Environment.CurrentManagedThreadId) { <>1__state = 0; d__ = this; } else { d__ = new d__6(0); } d__.tokens = <>3__tokens; return d__; } [DebuggerHidden] global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() { return (global::System.Collections.IEnumerator)((global::System.Collections.Generic.IEnumerable)this).GetEnumerator(); } } [CompilerGenerated] private sealed class d__7 : global::System.Collections.Generic.IEnumerable, global::System.Collections.IEnumerable, global::System.Collections.Generic.IEnumerator, global::System.Collections.IEnumerator, global::System.IDisposable { private int <>1__state; private string <>2__current; private int <>l__initialThreadId; private string text; public string <>3__text; private <>c__DisplayClass7_0 <>8__1; private int 5__2; private char 5__3; private int 5__4; private global::System.Collections.Generic.IEnumerator <>7__wrap4; private string 5__6; string global::System.Collections.Generic.IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } object global::System.Collections.IEnumerator.Current { [DebuggerHidden] get { return <>2__current; } } [DebuggerHidden] public d__7(int <>1__state) { this.<>1__state = <>1__state; <>l__initialThreadId = Environment.CurrentManagedThreadId; } [DebuggerHidden] void global::System.IDisposable.Dispose() { int num = <>1__state; if (num == -3 || (uint)(num - 6) <= 1u) { try { } finally { <>m__Finally1(); } } <>8__1 = default(<>c__DisplayClass7_0); <>7__wrap4 = null; 5__6 = null; <>1__state = -2; } private bool MoveNext() { //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Expected O, but got Unknown try { bool flag; switch (<>1__state) { default: return false; case 0: <>1__state = -1; <>8__1.builder = new StringBuilder(20); 5__2 = 0; goto IL_03e0; case 1: <>1__state = -1; <>8__1.builder.Append(5__3); 5__2++; while (5__2 < text.Length) { <>8__1.builder.Append(text[5__2]); if (text[5__2] == 5__3) { break; } 5__2++; } <>2__current = g__ClearBuilder|7_0(ref <>8__1); <>1__state = 2; return true; case 2: <>1__state = -1; goto IL_03d0; case 3: <>1__state = -1; 5__4 = 5__2; 5__2++; while (5__2 < text.Length && text[5__2] == '\t') { 5__2++; } 5__2--; <>2__current = "\n"; <>1__state = 4; return true; case 4: <>1__state = -1; <>2__current = $"{5__2 - 5__4}"; <>1__state = 5; return true; case 5: <>1__state = -1; goto IL_03d0; case 6: <>1__state = -3; <>2__current = 5__6; <>1__state = 7; return true; case 7: <>1__state = -3; 5__2 += 5__6.Length - 1; flag = true; goto IL_0364; case 8: <>1__state = -1; goto IL_03d0; case 9: { <>1__state = -1; return false; } IL_03e0: if (5__2 < text.Length) { if (text[5__2] == '\'' || text[5__2] == '"') { 5__3 = text[5__2]; <>2__current = g__ClearBuilder|7_0(ref <>8__1); <>1__state = 1; return true; } if (text[5__2] != '\r') { if (text[5__2] == '\n') { <>2__current = g__ClearBuilder|7_0(ref <>8__1); <>1__state = 3; return true; } flag = false; <>7__wrap4 = ((global::System.Collections.Generic.IEnumerable)Symbols).GetEnumerator(); <>1__state = -3; while (((global::System.Collections.IEnumerator)<>7__wrap4).MoveNext()) { 5__6 = <>7__wrap4.Current; if (Match(text, 5__2, 5__6)) { <>2__current = g__ClearBuilder|7_0(ref <>8__1); <>1__state = 6; return true; } 5__6 = null; } goto IL_0364; } goto IL_03d0; } <>2__current = "\n"; <>1__state = 9; return true; IL_0364: <>m__Finally1(); <>7__wrap4 = null; if (!flag) { if (text[5__2] == ' ') { <>2__current = g__ClearBuilder|7_0(ref <>8__1); <>1__state = 8; return true; } <>8__1.builder.Append(text[5__2]); } goto IL_03d0; IL_03d0: 5__2++; goto IL_03e0; } } catch { //try-fault ((global::System.IDisposable)this).Dispose(); throw; } } bool global::System.Collections.IEnumerator.MoveNext() { //ILSpy generated this explicit interface implementation from .override directive in MoveNext return this.MoveNext(); } private void <>m__Finally1() { <>1__state = -1; if (<>7__wrap4 != null) { ((global::System.IDisposable)<>7__wrap4).Dispose(); } } [DebuggerHidden] void global::System.Collections.IEnumerator.Reset() { //IL_0000: Unknown result type (might be due to invalid IL or missing references) throw new NotSupportedException(); } [DebuggerHidden] global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() { d__7 d__; if (<>1__state == -2 && <>l__initialThreadId == Environment.CurrentManagedThreadId) { <>1__state = 0; d__ = this; } else { d__ = new d__7(0); } d__.text = <>3__text; return d__; } [DebuggerHidden] global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() { return (global::System.Collections.IEnumerator)((global::System.Collections.Generic.IEnumerable)this).GetEnumerator(); } } private static readonly IReadOnlyDictionary Tokens; private static readonly IReadOnlySet Symbols; private static readonly IReadOnlyDictionary BuiltinTypeIds; private static void InsertNewLine(global::System.Collections.Generic.IEnumerator enumerator, uint baseIndent, List toFlush) { //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Expected O, but got Unknown if (((global::System.Collections.IEnumerator)enumerator).MoveNext()) { uint num = uint.Parse(enumerator.Current); toFlush.Add(new Token((TokenType)89, (uint?)(num + baseIndent))); } } private static void BuildNumber(global::System.Collections.Generic.IEnumerator enumerator, List toFlush, out bool foundFull) { //IL_003e: Unknown result type (might be due to invalid IL or missing references) //IL_0048: Expected O, but got Unknown //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_0077: Expected O, but got Unknown //IL_0072: Unknown result type (might be due to invalid IL or missing references) //IL_007c: Expected O, but got Unknown //IL_00c1: Unknown result type (might be due to invalid IL or missing references) //IL_00cb: Expected O, but got Unknown //IL_00c6: Unknown result type (might be due to invalid IL or missing references) //IL_00d0: Expected O, but got Unknown foundFull = true; int num = 1; if (enumerator.Current == "-") { num = -1; if (!((global::System.Collections.IEnumerator)enumerator).MoveNext()) { return; } } long num2 = default(long); if (!long.TryParse(enumerator.Current, ref num2)) { toFlush.Add(new Token((TokenType)17, (uint?)null)); foundFull = false; } else if (((global::System.Collections.IEnumerator)enumerator).MoveNext()) { long num3 = default(long); if (enumerator.Current != ".") { toFlush.Add((Token)new ConstantToken((Variant)new IntVariant(num2 * num, false))); foundFull = false; } else if (((global::System.Collections.IEnumerator)enumerator).MoveNext() && long.TryParse(enumerator.Current, ref num3)) { double num4 = (double)num2 + (double)num3 / Math.Pow(10.0, (double)num3.ToString().Length); toFlush.Add((Token)new ConstantToken((Variant)new RealVariant(num4 * (double)num, false))); } } } public static global::System.Collections.Generic.IEnumerable Tokenize(string gdScript, uint baseIndent = 0u) { //IL_00f5: Unknown result type (might be due to invalid IL or missing references) //IL_00ff: Expected O, but got Unknown //IL_0128: Unknown result type (might be due to invalid IL or missing references) //IL_0132: Expected O, but got Unknown //IL_012d: Unknown result type (might be due to invalid IL or missing references) //IL_0137: Expected O, but got Unknown //IL_0165: Unknown result type (might be due to invalid IL or missing references) //IL_016f: Expected O, but got Unknown //IL_019a: Unknown result type (might be due to invalid IL or missing references) //IL_01a6: Unknown result type (might be due to invalid IL or missing references) //IL_01b0: Expected O, but got Unknown //IL_0208: Unknown result type (might be due to invalid IL or missing references) //IL_0212: Expected O, but got Unknown //IL_020d: Unknown result type (might be due to invalid IL or missing references) //IL_0217: Expected O, but got Unknown //IL_023c: Unknown result type (might be due to invalid IL or missing references) //IL_0246: Expected O, but got Unknown //IL_0241: Unknown result type (might be due to invalid IL or missing references) //IL_024b: Expected O, but got Unknown List finalTokens = new List(); global::System.Collections.Generic.IEnumerable enumerable = SanitizeInput(TokenizeString(gdScript + " ")); string previous = string.Empty; string idName = string.Empty; List toFlush = new List(2); global::System.Collections.Generic.IEnumerator enumerator = enumerable.GetEnumerator(); bool flag = false; uint num = default(uint); BuiltinFunc builtinFunc = default(BuiltinFunc); TokenType val = default(TokenType); bool flag2 = default(bool); while (flag || ((global::System.Collections.IEnumerator)enumerator).MoveNext()) { flag = false; if (enumerator.Current == "\n") { InsertNewLine(enumerator, baseIndent, toFlush); endAndFlushId(); } else if (char.IsDigit(enumerator.Current[0])) { BuildNumber(enumerator, toFlush, out var foundFull); flag = !foundFull; endAndFlushId(); } else if (BuiltinTypeIds.TryGetValue(enumerator.Current, ref num)) { toFlush.Add(new Token((TokenType)4, (uint?)num)); endAndFlushId(); } else if (enumerator.Current == "null") { toFlush.Add((Token)new ConstantToken((Variant)new NilVariant())); endAndFlushId(); } else if (global::System.Enum.TryParse(enumerator.Current, ref builtinFunc)) { toFlush.Add(new Token((TokenType)5, (uint?)(uint)builtinFunc)); endAndFlushId(); } else if (Tokens.TryGetValue(enumerator.Current, ref val)) { toFlush.Add(new Token(val, (uint?)null)); endAndFlushId(); } else if (enumerator.Current.StartsWith('"') || enumerator.Current.StartsWith('\'')) { string current = enumerator.Current; toFlush.Add((Token)new ConstantToken((Variant)new StringVariant(current.Substring(1, current.Length - 2)))); endAndFlushId(); } else if (bool.TryParse(enumerator.Current, ref flag2)) { toFlush.Add((Token)new ConstantToken((Variant)new BoolVariant(flag2))); endAndFlushId(); } else { idName += enumerator.Current; end(); } } return finalTokens.ToArray(); [CompilerGenerated] void end() { previous = enumerator.Current; finalTokens.AddRange((global::System.Collections.Generic.IEnumerable)toFlush); toFlush.Clear(); } [CompilerGenerated] void endAndFlushId() { //IL_002a: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Expected O, but got Unknown if (idName == string.Empty) { end(); } else { finalTokens.Add((Token)new IdentifierToken(idName.Trim())); idName = string.Empty; end(); } } } [IteratorStateMachine(typeof(d__6))] private static global::System.Collections.Generic.IEnumerable SanitizeInput(global::System.Collections.Generic.IEnumerable tokens) { //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new d__6(-2) { <>3__tokens = tokens }; } [IteratorStateMachine(typeof(d__7))] private static global::System.Collections.Generic.IEnumerable TokenizeString(string text) { //yield-return decompiler failed: Unexpected instruction in Iterator.Dispose() return new d__7(-2) { <>3__text = text }; } private static bool Match(string text, int index, string match) { if (index + match.Length > text.Length) { return false; } for (int i = 0; i < match.Length; i++) { if (text[index + i] != match[i]) { return false; } } return true; } static ScriptTokenizer() { Dictionary obj = new Dictionary(); obj.Add("continue", (TokenType)44); obj.Add("return", (TokenType)46); obj.Add("break", (TokenType)43); obj.Add("match", (TokenType)47); obj.Add("while", (TokenType)42); obj.Add("elif", (TokenType)39); obj.Add("else", (TokenType)40); obj.Add("pass", (TokenType)45); obj.Add("for", (TokenType)41); obj.Add("if", (TokenType)38); obj.Add("const", (TokenType)58); obj.Add("var", (TokenType)59); obj.Add("func", (TokenType)48); obj.Add("class", (TokenType)49); obj.Add("extends", (TokenType)51); obj.Add("is", (TokenType)52); obj.Add("as", (TokenType)60); obj.Add("onready", (TokenType)53); obj.Add("@tool", (TokenType)54); obj.Add("@export", (TokenType)56); obj.Add("yield", (TokenType)65); obj.Add("setget", (TokenType)57); obj.Add("static", (TokenType)55); obj.Add("void", (TokenType)61); obj.Add("enum", (TokenType)62); obj.Add("preload", (TokenType)63); obj.Add("assert", (TokenType)64); obj.Add("signal", (TokenType)66); obj.Add("breakpoint", (TokenType)67); obj.Add("sync", (TokenType)69); obj.Add("remote", (TokenType)68); obj.Add("master", (TokenType)70); obj.Add("slave", (TokenType)71); obj.Add("puppet", (TokenType)72); obj.Add("remotesync", (TokenType)73); obj.Add("mastersync", (TokenType)74); obj.Add("puppetsync", (TokenType)75); obj.Add("\n", (TokenType)89); obj.Add("PI", (TokenType)90); obj.Add("TAU", (TokenType)91); obj.Add("INF", (TokenType)93); obj.Add("NAN", (TokenType)94); obj.Add("error", (TokenType)95); obj.Add("cursor", (TokenType)97); obj.Add("self", (TokenType)3); obj.Add("in", (TokenType)6); obj.Add("or", (TokenType)14); obj.Add("and", (TokenType)13); obj.Add("not", (TokenType)15); obj.Add("_", (TokenType)92); obj.Add("[", (TokenType)76); obj.Add("]", (TokenType)77); obj.Add("{", (TokenType)78); obj.Add("}", (TokenType)79); obj.Add("(", (TokenType)80); obj.Add(")", (TokenType)81); obj.Add(",", (TokenType)82); obj.Add(";", (TokenType)83); obj.Add(".", (TokenType)84); obj.Add("?", (TokenType)85); obj.Add(":", (TokenType)86); obj.Add("$", (TokenType)87); obj.Add("->", (TokenType)88); obj.Add(">>=", (TokenType)30); obj.Add("<<=", (TokenType)29); obj.Add(">>", (TokenType)22); obj.Add("<<", (TokenType)21); obj.Add("==", (TokenType)7); obj.Add("!=", (TokenType)8); obj.Add("&&", (TokenType)13); obj.Add("||", (TokenType)14); obj.Add("!", (TokenType)15); obj.Add("+=", (TokenType)24); obj.Add("-=", (TokenType)25); obj.Add("*=", (TokenType)26); obj.Add("/=", (TokenType)27); obj.Add("%=", (TokenType)28); obj.Add("&=", (TokenType)31); obj.Add("|=", (TokenType)32); obj.Add("^=", (TokenType)33); obj.Add("+", (TokenType)16); obj.Add("-", (TokenType)17); obj.Add("*", (TokenType)18); obj.Add("/", (TokenType)19); obj.Add("%", (TokenType)20); obj.Add("~", (TokenType)37); obj.Add("&", (TokenType)34); obj.Add("|", (TokenType)35); obj.Add("^", (TokenType)36); obj.Add("<=", (TokenType)10); obj.Add(">=", (TokenType)12); obj.Add("<", (TokenType)9); obj.Add(">", (TokenType)11); obj.Add("=", (TokenType)23); Tokens = (IReadOnlyDictionary)(object)obj; HashSet obj2 = new HashSet(); obj2.Add("->"); obj2.Add(">>="); obj2.Add("<<="); obj2.Add(">>"); obj2.Add("<<"); obj2.Add("=="); obj2.Add("!="); obj2.Add("&&"); obj2.Add("||"); obj2.Add("!"); obj2.Add("+="); obj2.Add("-="); obj2.Add("*="); obj2.Add("/="); obj2.Add("%="); obj2.Add("&="); obj2.Add("|="); obj2.Add("^="); obj2.Add("["); obj2.Add("]"); obj2.Add("{"); obj2.Add("}"); obj2.Add("("); obj2.Add(")"); obj2.Add(","); obj2.Add(";"); obj2.Add("."); obj2.Add("?"); obj2.Add(":"); obj2.Add("$"); obj2.Add("+"); obj2.Add("-"); obj2.Add("*"); obj2.Add("/"); obj2.Add("%"); obj2.Add("~"); obj2.Add("&"); obj2.Add("|"); obj2.Add("^"); obj2.Add("<="); obj2.Add(">="); obj2.Add("<"); obj2.Add(">"); obj2.Add("="); Symbols = (IReadOnlySet)(object)obj2; Dictionary obj3 = new Dictionary(); obj3.Add("int", 2u); obj3.Add("Vector3", 7u); obj3.Add("Color", 14u); BuiltinTypeIds = (IReadOnlyDictionary)(object)obj3; } [CompilerGenerated] internal static string g__ClearBuilder|7_0(ref <>c__DisplayClass7_0 P_0) { string result = ((object)P_0.builder).ToString(); P_0.builder.Clear(); return result; } } } namespace util.LexicalTransformer { public static class TransformationPatternFactory { public static Func[] CreateGlobalsPattern() { return new Func[3] { (Token t) => (int)t.Type == 51, (Token t) => (int)t.Type == 1, (Token t) => (int)t.Type == 89 }; } public static Func[] CreateFunctionDefinitionPattern(string name, string[]? args = null) { string name2 = name; List> val = new List>(); val.Add((Func)((Token t) => (int)t.Type == 48)); val.Add((Func)delegate(Token t) { IdentifierToken val3 = (IdentifierToken)(object)((t is IdentifierToken) ? t : null); return val3 != null && val3.Name == name2; }); val.Add((Func)((Token t) => (int)t.Type == 80)); if (args != null && args.Length > 0) { foreach (string arg in args) { val.Add((Func)delegate(Token t) { IdentifierToken val2 = (IdentifierToken)(object)((t is IdentifierToken) ? t : null); return val2 != null && val2.Name == arg; }); val.Add((Func)((Token t) => (int)t.Type == 82)); } val.RemoveAt(val.Count - 1); } val.Add((Func)((Token t) => (int)t.Type == 81)); val.Add((Func)((Token t) => (int)t.Type == 86)); return val.ToArray(); } public static Func[] CreateGdSnippetPattern(string snippet, uint indent = 0u) { return Enumerable.ToArray>(Enumerable.Select>(ScriptTokenizer.Tokenize(snippet, indent), (Func>)((Token snippetToken) => delegate(Token t) { //IL_0001: Unknown result type (might be due to invalid IL or missing references) //IL_0007: Invalid comparison between Unknown and I4 //IL_0037: Unknown result type (might be due to invalid IL or missing references) //IL_003d: Invalid comparison between Unknown and I4 //IL_006d: Unknown result type (might be due to invalid IL or missing references) //IL_0078: Unknown result type (might be due to invalid IL or missing references) if ((int)t.Type == 1) { Token obj = snippetToken; IdentifierToken val = (IdentifierToken)(object)((obj is IdentifierToken) ? obj : null); if (val != null) { IdentifierToken val2 = (IdentifierToken)(object)((t is IdentifierToken) ? t : null); if (val2 != null) { return val.Name == val2.Name; } } return false; } if ((int)t.Type == 2) { Token obj2 = snippetToken; ConstantToken val3 = (ConstantToken)(object)((obj2 is ConstantToken) ? obj2 : null); if (val3 != null) { ConstantToken val4 = (ConstantToken)(object)((t is ConstantToken) ? t : null); if (val4 != null) { return val3.Value.Equals(val4.Value); } } return false; } return t.Type == snippetToken.Type; }))); } } public enum Operation { None, ReplaceAll, ReplaceLast, Append, Prepend } public static class OperationExtensions { public static bool RequiresBuffer(this Operation operation) { if (operation == Operation.ReplaceAll || operation == Operation.Prepend) { return true; } return false; } public static bool YieldTokenBeforeOperation(this Operation operation) { if (operation == Operation.None || operation == Operation.Append) { return true; } return false; } public static bool YieldTokenAfterOperation(this Operation operation) { if (!operation.RequiresBuffer() && !operation.YieldTokenBeforeOperation()) { return operation != Operation.ReplaceLast; } return false; } } public record TransformationRule(string Name, Func[] Pattern, Func[] ScopePattern, global::System.Collections.Generic.IEnumerable Tokens, Operation Operation, uint Times, Func Predicate) { [CompilerGenerated] protected virtual global::System.Type EqualityContract { [CompilerGenerated] get { return typeof(TransformationRule); } } public MultiTokenWaiter CreateMultiTokenWaiter() { //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_000e: Expected O, but got Unknown return new MultiTokenWaiter(Pattern, false, false); } public MultiTokenWaiter CreateMultiTokenWaiterForScope() { //IL_0008: Unknown result type (might be due to invalid IL or missing references) //IL_000e: Expected O, but got Unknown return new MultiTokenWaiter(ScopePattern, false, false); } [CompilerGenerated] public override string ToString() { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0006: Expected O, but got Unknown StringBuilder val = new StringBuilder(); val.Append("TransformationRule"); val.Append(" { "); if (PrintMembers(val)) { val.Append(' '); } val.Append('}'); return ((object)val).ToString(); } [CompilerGenerated] protected virtual bool PrintMembers(StringBuilder builder) { RuntimeHelpers.EnsureSufficientExecutionStack(); builder.Append("Name = "); builder.Append((object)Name); builder.Append(", Pattern = "); builder.Append((object)Pattern); builder.Append(", ScopePattern = "); builder.Append((object)ScopePattern); builder.Append(", Tokens = "); builder.Append((object)Tokens); builder.Append(", Operation = "); builder.Append(((object)Operation).ToString()); builder.Append(", Times = "); builder.Append(((object)Times).ToString()); builder.Append(", Predicate = "); builder.Append((object)Predicate); return true; } [CompilerGenerated] public virtual bool Equals(TransformationRule? other) { if ((object)this != other) { if ((object)other != null && EqualityContract == other.EqualityContract && EqualityComparer.Default.Equals(Name, other.Name) && EqualityComparer[]>.Default.Equals(Pattern, other.Pattern) && EqualityComparer[]>.Default.Equals(ScopePattern, other.ScopePattern) && EqualityComparer>.Default.Equals(Tokens, other.Tokens) && EqualityComparer.Default.Equals(Operation, other.Operation) && EqualityComparer.Default.Equals(Times, other.Times)) { return EqualityComparer>.Default.Equals(Predicate, other.Predicate); } return false; } return true; } } public class TransformationRuleBuilder { private string? _name; private Func[]? _pattern; private Func[] _scopePattern = global::System.Array.Empty>(); private global::System.Collections.Generic.IEnumerable? _tokens; private uint _times = 1u; private Operation _operation = Operation.Append; private Func _predicate = () => true; public TransformationRuleBuilder Named(string name) { _name = name; return this; } public TransformationRuleBuilder Matching(Func[] pattern) { _pattern = pattern; return this; } public TransformationRuleBuilder With(global::System.Collections.Generic.IEnumerable tokens) { _tokens = tokens; return this; } public TransformationRuleBuilder With(Token token) { _tokens = new <>z__ReadOnlySingleElementList(token); return this; } public TransformationRuleBuilder With(string snippet, uint indent = 0u) { _tokens = ScriptTokenizer.Tokenize(snippet, indent); return this; } public TransformationRuleBuilder Do(Operation operation) { _operation = operation; return this; } public TransformationRuleBuilder ExpectTimes(uint times) { _times = times; return this; } public TransformationRuleBuilder ScopedTo(Func[] scopePattern) { _scopePattern = scopePattern; return this; } public TransformationRuleBuilder When(Func predicate) { _predicate = predicate; return this; } public TransformationRuleBuilder When(bool eligible) { _predicate = () => eligible; return this; } public TransformationRule Build() { //IL_0017: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Unknown result type (might be due to invalid IL or missing references) if (string.IsNullOrEmpty(_name)) { throw new ArgumentNullException("_name", "Name cannot be null or empty"); } if (_pattern == null) { throw new ArgumentNullException("_pattern", "Pattern cannot be null"); } if (_tokens == null) { throw new ArgumentNullException("_tokens", "Tokens cannot be null"); } return new TransformationRule(_name, _pattern, _scopePattern, _tokens, _operation, _times, _predicate); } } public class TransformationRuleScriptMod : IScriptMod { [CompilerGenerated] private IModInterface P; [CompilerGenerated] private string P; [CompilerGenerated] private string P; [CompilerGenerated] private Func P; [CompilerGenerated] private TransformationRule[] P; public TransformationRuleScriptMod(IModInterface mod, string name, string scriptPath, Func predicate, TransformationRule[] rules) { P = mod; P = name; P = scriptPath; P = predicate; P = rules; base..ctor(); } public bool ShouldRun(string path) { if (path != P) { return false; } if (!P.Invoke()) { P.Logger.Warning(string.Concat(Enumerable.Repeat("!", 15))); P.Logger.Warning("[" + P + "] Predicate failed!!!!!!, not patching."); P.Logger.Warning(string.Concat(Enumerable.Repeat("!", 15))); return false; } return true; } public global::System.Collections.Generic.IEnumerable Modify(string path, global::System.Collections.Generic.IEnumerable tokens) { //IL_00c8: Unknown result type (might be due to invalid IL or missing references) //IL_00cd: Unknown result type (might be due to invalid IL or missing references) //IL_00d6: Unknown result type (might be due to invalid IL or missing references) //IL_00db: Unknown result type (might be due to invalid IL or missing references) //IL_00dd: Unknown result type (might be due to invalid IL or missing references) //IL_00fe: Unknown result type (might be due to invalid IL or missing references) //IL_010d: Unknown result type (might be due to invalid IL or missing references) //IL_0112: Unknown result type (might be due to invalid IL or missing references) //IL_0134: Unknown result type (might be due to invalid IL or missing references) //IL_013b: Invalid comparison between Unknown and I4 //IL_041d: Unknown result type (might be due to invalid IL or missing references) //IL_0422: Unknown result type (might be due to invalid IL or missing references) //IL_047c: Unknown result type (might be due to invalid IL or missing references) //IL_049b: Unknown result type (might be due to invalid IL or missing references) //IL_01b9: Unknown result type (might be due to invalid IL or missing references) //IL_01c8: Unknown result type (might be due to invalid IL or missing references) //IL_015d: Unknown result type (might be due to invalid IL or missing references) //IL_0164: Invalid comparison between Unknown and I4 //IL_01f5: Unknown result type (might be due to invalid IL or missing references) //IL_01d8: Unknown result type (might be due to invalid IL or missing references) //IL_01e4: Unknown result type (might be due to invalid IL or missing references) //IL_0218: Unknown result type (might be due to invalid IL or missing references) //IL_0208: Unknown result type (might be due to invalid IL or missing references) //IL_0229: Unknown result type (might be due to invalid IL or missing references) //IL_0235: Unknown result type (might be due to invalid IL or missing references) //IL_0255: Unknown result type (might be due to invalid IL or missing references) //IL_0267: Unknown result type (might be due to invalid IL or missing references) //IL_031c: Unknown result type (might be due to invalid IL or missing references) //IL_0346: Unknown result type (might be due to invalid IL or missing references) //IL_0353: Unknown result type (might be due to invalid IL or missing references) //IL_035f: Unknown result type (might be due to invalid IL or missing references) //IL_0364: Unknown result type (might be due to invalid IL or missing references) //IL_0369: Unknown result type (might be due to invalid IL or missing references) //IL_0375: Unknown result type (might be due to invalid IL or missing references) //IL_0386: Unknown result type (might be due to invalid IL or missing references) //IL_02c1: Unknown result type (might be due to invalid IL or missing references) //IL_02cf: Unknown result type (might be due to invalid IL or missing references) //IL_0294: Unknown result type (might be due to invalid IL or missing references) //IL_02a7: Unknown result type (might be due to invalid IL or missing references) //IL_02b3: Unknown result type (might be due to invalid IL or missing references) List obj = Enumerable.ToList(Enumerable.Where((global::System.Collections.Generic.IEnumerable)P, (Func)([CompilerGenerated] (TransformationRule rule) => { bool num2 = rule.Predicate.Invoke(); if (!num2) { P.Logger.Information($"[{P}] Skipping patch {rule.Name}..."); } return num2; }))); List>> val = Enumerable.ToList>>(Enumerable.Select>>((global::System.Collections.Generic.IEnumerable)obj, (Func>>)((TransformationRule rule) => new ValueTuple>(rule, rule.CreateMultiTokenWaiter(), new List())))); P.Logger.Information("[" + P + "] Patching " + path); Dictionary> val2 = Enumerable.ToDictionary>((global::System.Collections.Generic.IEnumerable)obj, (Func)((TransformationRule r) => r.Name), (Func>)((TransformationRule r) => new ValueTuple(0, r.Times))); bool flag = true; List val3 = new List(); val3.AddRange(tokens); List val4 = new List(); Enumerator>> enumerator = val.GetEnumerator(); try { while (enumerator.MoveNext()) { ValueTuple> current = enumerator.Current; bool flag2 = current.Item1.ScopePattern.Length != 0; bool flag3 = !flag2; uint? num = null; MultiTokenWaiter val5 = current.Item1.CreateMultiTokenWaiterForScope(); Enumerator enumerator2 = val3.GetEnumerator(); try { while (enumerator2.MoveNext()) { Token current2 = enumerator2.Current; if (flag3 && flag2) { if (!num.HasValue && (int)current2.Type == 89) { num = current2.AssociatedData.GetValueOrDefault(); } else if (num.HasValue && (int)current2.Type == 89) { flag3 = current2.AssociatedData.GetValueOrDefault() >= num; } } else if (flag2 && val5.Check(current2)) { val5.Reset(); flag3 = true; } if (!flag3) { val4.Add(current2); continue; } current.Item2.Check(current2); if (current.Item2.Step == 0) { val4.AddRange((global::System.Collections.Generic.IEnumerable)current.Item3); current.Item3.Clear(); } else { if (current.Item1.Operation.RequiresBuffer()) { current.Item3.Add(current2); flag = false; } if (current.Item2.Matched) { current.Item2.Reset(); if (current.Item1.Operation.YieldTokenBeforeOperation()) { val4.Add(current2); flag = false; } else { flag = current.Item1.Operation.YieldTokenAfterOperation(); } switch (current.Item1.Operation) { case Operation.Prepend: val4.AddRange(current.Item1.Tokens); val4.AddRange((global::System.Collections.Generic.IEnumerable)current.Item3); current.Item3.Clear(); break; case Operation.ReplaceAll: case Operation.ReplaceLast: case Operation.Append: current.Item3.Clear(); val4.AddRange(current.Item1.Tokens); break; } P.Logger.Information($"[{P}] Patch {current.Item1.Name} OK!"); string name = current.Item1.Name; ValueTuple val6 = val2[current.Item1.Name]; val6.Item1 = val2[current.Item1.Name].Item1 + 1; val2[name] = val6; } } if (flag) { val4.Add(current2); } else { flag = true; } } } finally { ((global::System.IDisposable)enumerator2).Dispose(); } val3.Clear(); val3.AddRange((global::System.Collections.Generic.IEnumerable)val4); val4.Clear(); } } finally { ((global::System.IDisposable)enumerator).Dispose(); } global::System.Collections.Generic.IEnumerator>> enumerator3 = Enumerable.Where>>((global::System.Collections.Generic.IEnumerable>>)val2, (Func>, bool>)((KeyValuePair> result) => result.Value.Item1 != result.Value.Item2)).GetEnumerator(); try { while (((global::System.Collections.IEnumerator)enumerator3).MoveNext()) { KeyValuePair> current3 = enumerator3.Current; P.Logger.Error($"[{P}] Patch {current3.Key} FAILED!!!!!!! Times expected={current3.Value.Item2}, actual={current3.Value.Item1}"); } return (global::System.Collections.Generic.IEnumerable)val3; } finally { ((global::System.IDisposable)enumerator3)?.Dispose(); } } } public class TransformationRuleScriptModBuilder { private IModInterface? _mod; private string? _name; private string? _scriptPath; private Func _predicate = () => true; private List _rules = new List(); public TransformationRuleScriptModBuilder ForMod(IModInterface mod) { _mod = mod; return this; } public TransformationRuleScriptModBuilder When(Func predicate) { _predicate = predicate; return this; } public TransformationRuleScriptModBuilder Named(string name) { _name = name; return this; } public TransformationRuleScriptModBuilder Patching(string scriptPath) { //IL_0019: Unknown result type (might be due to invalid IL or missing references) _scriptPath = scriptPath; if (scriptPath.EndsWith(".gd")) { throw new ArgumentException("Your script path should end in gdc NOT gd"); } return this; } public TransformationRuleScriptModBuilder AddRule(TransformationRule rule) { //IL_004c: Unknown result type (might be due to invalid IL or missing references) if (Enumerable.Contains(Enumerable.Select((global::System.Collections.Generic.IEnumerable)_rules, (Func)((TransformationRule r) => r.Name)), rule.Name)) { throw new InvalidOperationException("Another rule with the name '" + rule.Name + "' already exists!"); } _rules.Add(rule); return this; } public TransformationRuleScriptModBuilder AddRule(TransformationRuleBuilder rule) { return AddRule(rule.Build()); } public TransformationRuleScriptMod Build() { //IL_0012: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Unknown result type (might be due to invalid IL or missing references) if (_mod == null) { throw new ArgumentNullException("_mod", "Mod cannot be null"); } if (string.IsNullOrEmpty(_name)) { throw new ArgumentNullException("_name", "Name cannot be null or empty"); } if (string.IsNullOrEmpty(_scriptPath)) { throw new ArgumentNullException("_scriptPath", "Script path cannot be null or empty"); } return new TransformationRuleScriptMod(_mod, _name, _scriptPath, _predicate, _rules.ToArray()); } } } namespace Shaderade { public class Config { [JsonInclude] public float red = configFile.red; public float green = configFile.green; public float blue = configFile.blue; public Config(ConfigFileSchema configFile) { } } public class ConfigFileSchema { [JsonInclude] public float red = 0.1f; public float green = 0.1f; public float blue = 0.1f; } public class Mod : IMod, global::System.IDisposable { public Mod(IModInterface mi) { new Config(mi.ReadConfig()); mi.RegisterScriptMod((IScriptMod)(object)new TransformationRuleScriptModBuilder().ForMod(mi).Named("Map Environment linear interpolation speed adjustment").Patching("res://Scenes/Map/game_worldenv.gd") .AddRule(new TransformationRuleBuilder().Named("Change lerp speed to non-molasses").Do(Operation.ReplaceLast).Matching(TransformationPatternFactory.CreateGdSnippetPattern("lerp_val = 0.01")) .With("0.6", 1u)) .Build()); } public void Dispose() { } } } [CompilerGenerated] internal sealed class <>z__ReadOnlySingleElementList : global::System.Collections.IEnumerable, global::System.Collections.ICollection, global::System.Collections.IList, global::System.Collections.Generic.IEnumerable, global::System.Collections.Generic.IReadOnlyCollection, global::System.Collections.Generic.IReadOnlyList, global::System.Collections.Generic.ICollection, global::System.Collections.Generic.IList { private sealed class Enumerator : global::System.IDisposable, global::System.Collections.IEnumerator, global::System.Collections.Generic.IEnumerator { object global::System.Collections.IEnumerator.Current => _item; T global::System.Collections.Generic.IEnumerator.Current => _item; public Enumerator(T item) { _item = item; } bool global::System.Collections.IEnumerator.MoveNext() { if (!_moveNextCalled) { return _moveNextCalled = true; } return false; } void global::System.Collections.IEnumerator.Reset() { _moveNextCalled = false; } void global::System.IDisposable.Dispose() { } } int global::System.Collections.ICollection.Count => 1; bool global::System.Collections.ICollection.IsSynchronized => false; object global::System.Collections.ICollection.SyncRoot => this; object global::System.Collections.IList.this[int index] { get { //IL_0003: Unknown result type (might be due to invalid IL or missing references) if (index != 0) { throw new IndexOutOfRangeException(); } return _item; } set { //IL_0000: Unknown result type (might be due to invalid IL or missing references) throw new NotSupportedException(); } } bool global::System.Collections.IList.IsFixedSize => true; bool global::System.Collections.IList.IsReadOnly => true; int global::System.Collections.Generic.IReadOnlyCollection.Count => 1; T global::System.Collections.Generic.IReadOnlyList.this[int index] { get { //IL_0003: Unknown result type (might be due to invalid IL or missing references) if (index != 0) { throw new IndexOutOfRangeException(); } return _item; } } int global::System.Collections.Generic.ICollection.Count => 1; bool global::System.Collections.Generic.ICollection.IsReadOnly => true; T global::System.Collections.Generic.IList.this[int index] { get { //IL_0003: Unknown result type (might be due to invalid IL or missing references) if (index != 0) { throw new IndexOutOfRangeException(); } return _item; } set { //IL_0000: Unknown result type (might be due to invalid IL or missing references) throw new NotSupportedException(); } } public <>z__ReadOnlySingleElementList(T item) { _item = item; } global::System.Collections.IEnumerator global::System.Collections.IEnumerable.GetEnumerator() { return new Enumerator(_item); } void global::System.Collections.ICollection.CopyTo(global::System.Array array, int index) { array.SetValue((object)_item, index); } int global::System.Collections.IList.Add(object? value) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) throw new NotSupportedException(); } void global::System.Collections.IList.Clear() { //IL_0000: Unknown result type (might be due to invalid IL or missing references) throw new NotSupportedException(); } bool global::System.Collections.IList.Contains(object? value) { return EqualityComparer.Default.Equals(_item, (T)value); } int global::System.Collections.IList.IndexOf(object? value) { if (!EqualityComparer.Default.Equals(_item, (T)value)) { return -1; } return 0; } void global::System.Collections.IList.Insert(int index, object? value) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) throw new NotSupportedException(); } void global::System.Collections.IList.Remove(object? value) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) throw new NotSupportedException(); } void global::System.Collections.IList.RemoveAt(int index) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) throw new NotSupportedException(); } global::System.Collections.Generic.IEnumerator global::System.Collections.Generic.IEnumerable.GetEnumerator() { return new Enumerator(_item); } void global::System.Collections.Generic.ICollection.Add(T item) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) throw new NotSupportedException(); } void global::System.Collections.Generic.ICollection.Clear() { //IL_0000: Unknown result type (might be due to invalid IL or missing references) throw new NotSupportedException(); } bool global::System.Collections.Generic.ICollection.Contains(T item) { return EqualityComparer.Default.Equals(_item, item); } void global::System.Collections.Generic.ICollection.CopyTo(T[] array, int arrayIndex) { array[arrayIndex] = _item; } bool global::System.Collections.Generic.ICollection.Remove(T item) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) throw new NotSupportedException(); } int global::System.Collections.Generic.IList.IndexOf(T item) { if (!EqualityComparer.Default.Equals(_item, item)) { return -1; } return 0; } void global::System.Collections.Generic.IList.Insert(int index, T item) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) throw new NotSupportedException(); } void global::System.Collections.Generic.IList.RemoveAt(int index) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) throw new NotSupportedException(); } }