Exemplo n.º 1
0
    protected void Q(ScriptFunction function)
    {
        player.AcceptingInput = false;
        if (q == null) {
            q = new Queue<ScriptFunction>();
        }

        q.Enqueue(function);
    }
Exemplo n.º 2
0
			public ScriptFunctionArg(ScriptFunction func, ProjectState state, IO.XmlStream s)
			{
				string type_name = null;
				s.ReadAttribute("type", ref type_name);

				if (!state.scriptingInterface.Types.Contains(type_name))
					throw new Debug.ExceptionLog("CheApe: value type '{0}' does not exist", type_name);

				type = state.scriptingInterface.GetValueType(type_name);
			}
 protected override void Execute(ScriptFunction.ScriptEnvironment env, Robot robot)
 {
 }
Exemplo n.º 4
0
        /// <summary>
        /// Parse scriptobject header, without decompiling the code
        /// </summary>
        private void ParseHeader()
        {
            string magic1 = new string(br.ReadChars(8));
            if (magic1 != "SCRIPT03") Error("Invalid magic in ScriptObject header, SCRIPT03 expected");

            int count;
            // String table
            ValidateToken("STRG");
            count = br.ReadInt32();
            ScriptStringTable = new string[count];
            for (int i = 0; i < count; i++) ScriptStringTable[i] = new string(br.ReadChars(br.ReadInt32()));

            // Functions
            ValidateToken("CODE");
            count = br.ReadInt32();
            Functions = new List<ScriptFunction>(count);
            for (int i = 0; i < count; i++)
            {
                // Function header
                ValidateToken("FUNC");
                string fname = new string(br.ReadChars(br.ReadInt32()));
                int returns = br.ReadInt32();
                int numargs = br.ReadInt32();
                if (returns > 1) Error("Return is not a boolean! O_o");

                ScriptFunction func = new ScriptFunction(fname, numargs, (returns == 1 ? true : false));
                // Variables (symbols)
                ValidateToken("SYMB");
                int scount = br.ReadInt32();
                br.ReadInt32(); // always ignored
                for (int s = 0; s < scount; s++)
                {
                    string format = "var_{0}";
                    if (numargs > 0)
                    {
                        numargs--;
                        format = "arg_{0}";
                    }
                    if (i == 1) // GLOBAL
                    {
                        if (s > 3)
                            format = "Gvar_{0}";
                        else if (s == 0)
                            format = "Trigger";
                        else if (s == 1)
                            format = "Caller";
                        else if (s == 2)
                            format = "true";
                        else if (s == 3)
                            format = "false";
                    }
                    func.Variables.Add(new ScriptFunction.ScriptVariable(
                        String.Format(format, s), VarType.INTEGER, br.ReadInt32()));
                }
                // Binary code
                ValidateToken("DATA");
                func.CompiledCode = br.ReadBytes(br.ReadInt32());
                // Add to list
                Functions.Add(func);
            }
            // Finish
            ValidateToken("DONE");
        }
Exemplo n.º 5
0
 /// <summary>
 /// Create a ServiceScript with Reference to Function and Service Parameter:
 /// <para/>ID=ScriptName:FunctionName
 /// <para/>Description=ScriptName:FunctionName  (used to display the function)
 /// <para/>Help=Function.Description            (used to show help, not description!!)
 /// </summary>
 /// <param name="function"></param>
 public ServiceScript(ScriptFunction function) : base($"{function.Owner.Name}:{function.Name}", $"{function.Owner.Name}:{function.Name}", function.Description)
 {
     Function = function;
 }
Exemplo n.º 6
0
        private static void ConstructCache(Script scriptToCache, bool isBackgroundThread)
        {
            string originalText              = scriptToCache.Text;
            ScriptAutoCompleteData newCache  = new ScriptAutoCompleteData();
            List <ScriptVariable>  variables = newCache.Variables;
            List <ScriptFunction>  functions = newCache.Functions;
            List <ScriptDefine>    defines   = newCache.Defines;
            List <ScriptEnum>      enums     = newCache.Enums;
            List <ScriptStruct>    structs   = newCache.Structs;

            variables.Clear();
            functions.Clear();
            defines.Clear();
            enums.Clear();
            structs.Clear();
            FastString script                    = originalText;
            AutoCompleteParserState state        = new AutoCompleteParserState();
            ScriptFunction          lastFunction = null;
            int counter = 0;

            while (script.Length > 0)
            {
                if (isBackgroundThread)
                {
                    counter++;
                    if (counter % 20 == 0)
                    {
                        Thread.Sleep(2);
                    }
                }
                SkipWhitespace(ref script);
                state.CurrentScriptCharacterIndex = originalText.Length - script.Length;

                if (script.Length == 0)
                {
                    break;
                }
                if (script.StartsWith("//"))
                {
                    FastString scriptAtComment = script;
                    GoToNextLine(ref script);

                    if (scriptAtComment.StartsWith("///"))
                    {
                        FastString commentText = scriptAtComment.Substring(3, (scriptAtComment.Length - script.Length) - 4);
                        state.PreviousComment = commentText.ToString().Trim();
                    }
                    continue;
                }
                if (script.StartsWith("/*"))
                {
                    int endOfComment = script.IndexOf("*/");
                    if (endOfComment < 0)
                    {
                        break;
                    }
                    script = script.Substring(endOfComment + 2);
                    continue;
                }
                if (script.StartsWith("#"))
                {
                    ProcessPreProcessorDirective(defines, ref script, state);
                    continue;
                }
                if (script.StartsWith("{"))
                {
                    if (state.WordBeforeLast == "enum")
                    {
                        state.InsideEnumDefinition = new ScriptEnum(state.LastWord, state.InsideIfDefBlock, state.InsideIfNDefBlock);
                    }
                    else if (state.WordBeforeLast == "extends")
                    {
                        // inherited struct
                        foreach (ScriptStruct baseStruct in structs)
                        {
                            if (baseStruct.Name == state.LastWord)
                            {
                                state.InsideStructDefinition = CreateInheritedStruct(baseStruct, state);
                                functions = state.InsideStructDefinition.Functions;
                                variables = state.InsideStructDefinition.Variables;
                                break;
                            }
                        }
                    }
                    else if (state.WordBeforeLast == "struct")
                    {
                        state.InsideStructDefinition = new ScriptStruct(state.LastWord, state.InsideIfDefBlock, state.InsideIfNDefBlock, state.CurrentScriptCharacterIndex);
                        functions = state.InsideStructDefinition.Functions;
                        variables = state.InsideStructDefinition.Variables;
                    }
                    else
                    {
                        state.ClearPreviousWords();

                        SkipUntilMatchingClosingBrace(ref script);

                        if ((lastFunction != null) && (lastFunction.EndsAtCharacterIndex == 0))
                        {
                            lastFunction.EndsAtCharacterIndex = originalText.Length - script.Length;
                        }
                        continue;
                    }
                }

                string thisWord = GetNextWord(ref script);
                if (thisWord == "(")
                {
                    List <ScriptFunction> functionList = functions;
                    bool isExtenderMethod = AdjustFunctionListForExtenderFunction(structs, ref functionList, ref script);
                    if (AddFunctionDeclaration(functionList, ref script, thisWord, state, isExtenderMethod))
                    {
                        lastFunction = functionList[functionList.Count - 1];
                    }
                    state.ClearPreviousWords();
                }
                else if ((thisWord == "[") && (PeekNextWord(script) == "]"))
                {
                    GetNextWord(ref script);
                    state.DynamicArrayDefinition = true;
                    state.AddNextWord("[]");
                }
                else if ((thisWord == "=") || (thisWord == ";") ||
                         (thisWord == ",") || (thisWord == "["))
                {
                    if (state.InsideEnumDefinition != null)
                    {
                        AddEnumValue(state.InsideEnumDefinition, script, state.LastWord);

                        if (thisWord == "=")
                        {
                            // skip whatever the value of the enum is
                            GetNextWord(ref script);
                        }
                    }
                    else
                    {
                        AddVariableDeclaration(variables, ref script, thisWord, state);
                        if (thisWord == "=")
                        {
                            while ((thisWord != ";") && (thisWord != ",") && (script.Length > 0))
                            {
                                thisWord = GetNextWord(ref script);
                            }
                        }
                        if (thisWord == ",")
                        {
                            // eg. "int x,y"; ensure "y" gets recorded next time round
                            state.UndoLastWord();
                            continue;
                        }
                        if (thisWord == "[")
                        {
                            // eg. "int a[10], b[10], c[10];"
                            SkipWhitespace(ref script);
                            if (script.StartsWith(","))
                            {
                                GetNextWord(ref script);
                                state.UndoLastWord();
                                continue;
                            }
                        }
                    }
                    state.ClearPreviousWords();
                    state.DynamicArrayDefinition = false;
                }
                else if ((thisWord == "}") && (state.InsideEnumDefinition != null))
                {
                    // add the last value (unless it's an empty enum)
                    if (state.LastWord != "{")
                    {
                        AddEnumValue(state.InsideEnumDefinition, script, state.LastWord);
                    }
                    enums.Add(state.InsideEnumDefinition);
                    state.InsideEnumDefinition = null;
                    state.ClearPreviousWords();
                }
                else if ((thisWord == "}") && (state.InsideStructDefinition != null))
                {
                    structs.Add(state.InsideStructDefinition);
                    functions = newCache.Functions;
                    variables = newCache.Variables;
                    state.InsideStructDefinition = null;
                    state.ClearPreviousWords();
                }
                else
                {
                    state.AddNextWord(thisWord);
                }
            }
            scriptToCache.AutoCompleteData.CopyFrom(newCache);
            scriptToCache.AutoCompleteData.Populated = true;
        }
Exemplo n.º 7
0
 public CmdDefintion(String _name, ScriptFunction fun, String args)
 {
     name = _name;
     mFunction = fun;
     param = args;
 }
Exemplo n.º 8
0
		void ScriptingDefinitionsToStream(Import import)
		{
			if (Head.ScriptFunctionsCount > 0)
			{
				var sfunc = new ScriptFunction();
				foreach (Import.ScriptFunction sc in import.ScriptFunctions.Values)
				{
					sfunc.Reset(sc);
					sfunc.Write(MemoryStream);
				}
			}

			if (Head.ScriptGlobalsCount > 0)
			{
				var sglob = new ScriptGlobal();
				foreach (Import.ScriptGlobal sc in import.ScriptGlobals.Values)
				{
					sglob.Reset(sc);
					sglob.Write(MemoryStream);
				}
			}
		}
Exemplo n.º 9
0
 public uint SetInterval(ScriptFunction fn, int ms)
 {
     return(CreateTimer(fn, ms, false));
 }
Exemplo n.º 10
0
 public uint SetTimeout(ScriptFunction fn, int ms)
 {
     return(CreateTimer(fn, ms, true));
 }
Exemplo n.º 11
0
        /// <summary>
        /// Process a XML file containing CheApe definitions
        /// </summary>
        /// <param name="state"></param>
        /// <param name="s"></param>
        private void ProcessFile(ProjectState state, BlamLib.IO.XmlStream s)
        {
            int complexity = 1 +
                             PreprocessXmlNodeComplexity();

            BlamVersion def_engine = BlamVersion.Unknown;

            s.ReadAttribute("game", ref def_engine);
            if (def_engine != state.Definition.Engine)
            {
                Debug.Assert.If(false, "CheApe definition '{0}' is for {1}. Expected a {2} definition.", s.FileName, def_engine, state.Definition.Engine);
            }
            else
            {
                string name_str;
                foreach (XmlNode n in s.Cursor.ChildNodes)
                {
                    switch (n.Name)
                    {
                        #region Enums
                    case "enums":
                        s.SaveCursor(n);
                        foreach (XmlNode n2 in s.Cursor.ChildNodes)
                        {
                            if (n2.Name != "Enum")
                            {
                                continue;
                            }

                            s.SaveCursor(n2);
                            StringList list = new StringList(state, s);
                            s.RestoreCursor();
                            name_str = list.ToString();

                            try { Enums.Add(name_str, list); }
                            catch (ArgumentException) { Debug.LogFile.WriteLine(kDuplicateErrorStr, "enum definition", name_str); }
                        }
                        s.RestoreCursor();
                        break;
                        #endregion

                        #region Flags
                    case "flags":
                        s.SaveCursor(n);
                        foreach (XmlNode n2 in s.Cursor.ChildNodes)
                        {
                            if (n2.Name != "Flag")
                            {
                                continue;
                            }

                            s.SaveCursor(n2);
                            StringList list = new StringList(state, s);
                            s.RestoreCursor();
                            name_str = list.ToString();

                            try { Flags.Add(name_str, list); }
                            catch (ArgumentException) { Debug.LogFile.WriteLine(kDuplicateErrorStr, "flag definition", name_str); }
                        }
                        s.RestoreCursor();
                        break;
                        #endregion

                        #region Tag References
                    case "references":
                        s.SaveCursor(n);
                        foreach (XmlNode n2 in s.Cursor.ChildNodes)
                        {
                            if (n2.Name != "Reference")
                            {
                                continue;
                            }

                            s.SaveCursor(n2);
                            TagReference tagref = new TagReference(state, s);
                            s.RestoreCursor();
                            name_str = tagref.ToString();

                            try { References.Add(name_str, tagref); }
                            catch (ArgumentException) { Debug.LogFile.WriteLine(kDuplicateErrorStr, "tag reference definition", name_str); }
                        }
                        s.RestoreCursor();
                        break;
                        #endregion

                        #region Tag Data
                    case "data":
                        s.SaveCursor(n);
                        foreach (XmlNode n2 in s.Cursor.ChildNodes)
                        {
                            if (n2.Name != "TagData")
                            {
                                continue;
                            }

                            s.SaveCursor(n2);
                            TagData tagdata = new TagData(state, s);
                            s.RestoreCursor();
                            name_str = tagdata.ToString();

                            try { Data.Add(name_str, tagdata); }
                            catch (ArgumentException) { Debug.LogFile.WriteLine(kDuplicateErrorStr, "tag data definition", name_str); }
                        }
                        s.RestoreCursor();
                        break;
                        #endregion

                        #region Script Functions
                    case "scriptFunctions":
                        if (state.scriptingInterface == null)
                        {
                            break;
                        }

                        s.SaveCursor(n);
                        foreach (XmlNode n2 in s.Cursor.ChildNodes)
                        {
                            if (n2.Name != "function")
                            {
                                continue;
                            }

                            s.SaveCursor(n2);
                            ScriptFunction sc = new ScriptFunction(state, s);
                            s.RestoreCursor();
                            name_str = sc.ToString();

                            if (state.scriptingInterface.Functions.Contains(name_str))
                            {
                                Debug.LogFile.WriteLine("Engine already contains a {0} named '{1}', skipping...", "script function", name_str);
                                continue;
                            }

                            try { ScriptFunctions.Add(name_str, sc); }
                            catch (ArgumentException) { Debug.LogFile.WriteLine(kDuplicateErrorStr, "script function definition", name_str); }
                        }
                        s.RestoreCursor();
                        break;
                        #endregion

                        #region Script Globals
                    case "scriptGlobals":
                        if (state.scriptingInterface == null)
                        {
                            break;
                        }

                        s.SaveCursor(n);
                        foreach (XmlNode n2 in s.Cursor.ChildNodes)
                        {
                            if (n2.Name != "global")
                            {
                                continue;
                            }

                            s.SaveCursor(n2);
                            ScriptGlobal sc = new ScriptGlobal(state, s);
                            s.RestoreCursor();
                            name_str = sc.ToString();

                            if (state.scriptingInterface.Globals.Contains(name_str))
                            {
                                Debug.LogFile.WriteLine("Engine already contains a {0} named '{1}', ignoring...", "script global", name_str);
                                continue;
                            }

                            try { ScriptGlobals.Add(name_str, sc); }
                            catch (ArgumentException) { Debug.LogFile.WriteLine(kDuplicateErrorStr, "script global definition", name_str); }
                        }
                        s.RestoreCursor();
                        break;
                        #endregion

                        #region Fix-ups
                    case "fixups":
                        s.SaveCursor(n);
                        foreach (XmlNode n2 in s.Cursor.ChildNodes)
                        {
                            if (n2.Name != "fixup")
                            {
                                continue;
                            }

                            s.SaveCursor(n2);
                            Fixup fu = new Fixup(state, s);
                            s.RestoreCursor();
                            name_str = fu.ToString();

                            try { Fixups.Add(name_str, fu); }
                            catch (ArgumentException) { Debug.LogFile.WriteLine(kDuplicateErrorStr, "fix-up definition", name_str); }
                        }
                        s.RestoreCursor();
                        break;
                        #endregion

                    default:
                        ProcessDefinition(n, state, s);
                        break;
                    }
                }
            }
        }
Exemplo n.º 12
0
 public Delegate CreateDelegate(ScriptFunction func)
 {
     return(MethodFactory.CreateDelegate(m_DelegateType, new DynamicDelegate(func, m_ReturnType)));
 }
Exemplo n.º 13
0
 public DynamicDelegate(ScriptFunction function, Type returnType)
 {
     m_Function   = function;
     m_ReturnType = returnType;
 }
Exemplo n.º 14
0
        public static void RegisterEvents(object target)
        {
            MethodIndexer.Index(target, new[] { typeof(Event), typeof(ScriptEvent) },
                                (baseEvent, eventMethod, eventMethodDelegate) =>
            {
                switch (baseEvent)
                {
                case ScriptEvent scriptEvent:
                    var scriptEventType = scriptEvent.EventType;
                    ScriptFunction scriptFunction;
                    switch (scriptEventType)
                    {
                    case ScriptEventType.Checkpoint:
                        scriptFunction = ScriptFunction.Create(eventMethodDelegate,
                                                               new[] { typeof(ICheckpoint), typeof(IEntity), typeof(bool) });
                        if (scriptFunction == null)
                        {
                            return;
                        }
                        Alt.OnCheckpoint += (checkpoint, entity, state) =>
                        {
                            scriptFunction.Set(checkpoint);
                            scriptFunction.Set(entity);
                            scriptFunction.Set(state);
                            scriptFunction.Call();
                        };
                        break;

                    case ScriptEventType.PlayerConnect:
                        scriptFunction = ScriptFunction.Create(eventMethodDelegate,
                                                               new[] { typeof(IPlayer), typeof(string) });
                        if (scriptFunction == null)
                        {
                            return;
                        }
                        Alt.OnPlayerConnect += (player, reason) =>
                        {
                            scriptFunction.Set(player);
                            scriptFunction.Set(reason);
                            scriptFunction.Call();
                        };
                        break;

                    case ScriptEventType.PlayerDamage:
                        scriptFunction = ScriptFunction.Create(eventMethodDelegate,
                                                               new[] { typeof(IPlayer), typeof(IEntity), typeof(uint), typeof(ushort) });
                        if (scriptFunction == null)
                        {
                            return;
                        }
                        Alt.OnPlayerDamage += (player, attacker, weapon, damage) =>
                        {
                            scriptFunction.Set(player);
                            scriptFunction.Set(attacker);
                            scriptFunction.Set(weapon);
                            scriptFunction.Set(damage);
                            scriptFunction.Call();
                        };
                        break;

                    case ScriptEventType.PlayerDead:
                        scriptFunction = ScriptFunction.Create(eventMethodDelegate,
                                                               new[] { typeof(IPlayer), typeof(IEntity), typeof(uint) });
                        if (scriptFunction == null)
                        {
                            return;
                        }
                        Alt.OnPlayerDead += (player, attacker, weapon) =>
                        {
                            scriptFunction.Set(player);
                            scriptFunction.Set(attacker);
                            scriptFunction.Set(weapon);
                            scriptFunction.Call();
                        };
                        break;

                    case ScriptEventType.PlayerDisconnect:
                        scriptFunction = ScriptFunction.Create(eventMethodDelegate,
                                                               new[] { typeof(IPlayer), typeof(string) });
                        if (scriptFunction == null)
                        {
                            return;
                        }
                        Alt.OnPlayerDisconnect += (player, reason) =>
                        {
                            scriptFunction.Set(player);
                            scriptFunction.Set(reason);
                            scriptFunction.Call();
                        };
                        break;

                    case ScriptEventType.PlayerRemove:
                        scriptFunction =
                            ScriptFunction.Create(eventMethodDelegate, new[] { typeof(IPlayer) });
                        if (scriptFunction == null)
                        {
                            return;
                        }
                        Alt.OnPlayerRemove += player =>
                        {
                            scriptFunction.Set(player);
                            scriptFunction.Call();
                        };
                        break;

                    case ScriptEventType.VehicleRemove:
                        scriptFunction =
                            ScriptFunction.Create(eventMethodDelegate, new[] { typeof(IVehicle) });
                        if (scriptFunction == null)
                        {
                            return;
                        }
                        Alt.OnVehicleRemove += vehicle =>
                        {
                            scriptFunction.Set(vehicle);
                            scriptFunction.Call();
                        };
                        break;

                    case ScriptEventType.PlayerChangeVehicleSeat:
                        scriptFunction =
                            ScriptFunction.Create(eventMethodDelegate,
                                                  new[] { typeof(IVehicle), typeof(IPlayer), typeof(byte), typeof(byte) });
                        if (scriptFunction == null)
                        {
                            return;
                        }
                        Alt.OnPlayerChangeVehicleSeat += (vehicle, player, seat, newSeat) =>
                        {
                            scriptFunction.Set(vehicle);
                            scriptFunction.Set(player);
                            scriptFunction.Set(seat);
                            scriptFunction.Set(newSeat);
                            scriptFunction.Call();
                        };
                        break;

                    case ScriptEventType.PlayerEnterVehicle:
                        scriptFunction =
                            ScriptFunction.Create(eventMethodDelegate,
                                                  new[] { typeof(IVehicle), typeof(IPlayer), typeof(byte) });
                        if (scriptFunction == null)
                        {
                            return;
                        }
                        Alt.OnPlayerEnterVehicle += (vehicle, player, seat) =>
                        {
                            scriptFunction.Set(vehicle);
                            scriptFunction.Set(player);
                            scriptFunction.Set(seat);
                            scriptFunction.Call();
                        };
                        break;

                    case ScriptEventType.PlayerLeaveVehicle:
                        scriptFunction =
                            ScriptFunction.Create(eventMethodDelegate,
                                                  new[] { typeof(IVehicle), typeof(IPlayer), typeof(byte) });
                        if (scriptFunction == null)
                        {
                            return;
                        }
                        Alt.OnPlayerLeaveVehicle += (vehicle, player, seat) =>
                        {
                            scriptFunction.Set(vehicle);
                            scriptFunction.Set(player);
                            scriptFunction.Set(seat);
                            scriptFunction.Call();
                        };
                        break;

                    case ScriptEventType.PlayerEvent:
                        scriptFunction =
                            ScriptFunction.Create(eventMethodDelegate,
                                                  new[] { typeof(IPlayer), typeof(string), typeof(object[]) });
                        if (scriptFunction == null)
                        {
                            return;
                        }
                        Alt.OnPlayerEvent += (player, name, args) =>
                        {
                            scriptFunction.Set(player);
                            scriptFunction.Set(name);
                            scriptFunction.Set(args);
                            scriptFunction.Call();
                        };
                        break;

                    case ScriptEventType.PlayerCustomEvent:
                        scriptFunction =
                            ScriptFunction.Create(eventMethodDelegate,
                                                  new[] { typeof(IPlayer), typeof(string), typeof(MValueArray) });
                        if (scriptFunction == null)
                        {
                            return;
                        }
                        Alt.OnPlayerCustomEvent += (IPlayer player, string name, ref MValueArray array) =>
                        {
                            scriptFunction.Set(player);
                            scriptFunction.Set(name);
                            scriptFunction.Set(array);
                            scriptFunction.Call();
                        };
                        break;

                    case ScriptEventType.ServerEvent:
                        scriptFunction = ScriptFunction.Create(eventMethodDelegate,
                                                               new[] { typeof(string), typeof(object[]) });
                        if (scriptFunction == null)
                        {
                            return;
                        }
                        Alt.OnServerEvent += (serverEventName, serverEventArgs) =>
                        {
                            scriptFunction.Set(serverEventName);
                            scriptFunction.Set(serverEventArgs);
                            scriptFunction.Call();
                        };
                        break;

                    case ScriptEventType.ServerCustomEvent:
                        scriptFunction = ScriptFunction.Create(eventMethodDelegate,
                                                               new[] { typeof(string), typeof(MValueArray) });
                        if (scriptFunction == null)
                        {
                            return;
                        }
                        Alt.OnServerCustomEvent += (string name, ref MValueArray array) =>
                        {
                            scriptFunction.Set(name);
                            scriptFunction.Set(array);
                            scriptFunction.Call();
                        };
                        break;

                    case ScriptEventType.ConsoleCommand:
                        scriptFunction = ScriptFunction.Create(eventMethodDelegate,
                                                               new[] { typeof(string), typeof(string[]) });
                        if (scriptFunction == null)
                        {
                            return;
                        }
                        Alt.OnConsoleCommand += (name, args) =>
                        {
                            scriptFunction.Set(name);
                            scriptFunction.Set(args);
                            scriptFunction.Call();
                        };
                        break;

                    case ScriptEventType.MetaDataChange:
                        scriptFunction = ScriptFunction.Create(eventMethodDelegate,
                                                               new[] { typeof(IEntity), typeof(string), typeof(object) });
                        if (scriptFunction == null)
                        {
                            return;
                        }
                        Alt.OnMetaDataChange += (entity, key, value) =>
                        {
                            scriptFunction.Set(entity);
                            scriptFunction.Set(key);
                            scriptFunction.Set(value);
                            scriptFunction.Call();
                        };
                        break;

                    case ScriptEventType.SyncedMetaDataChange:
                        scriptFunction = ScriptFunction.Create(eventMethodDelegate,
                                                               new[] { typeof(IEntity), typeof(string), typeof(object) });
                        if (scriptFunction == null)
                        {
                            return;
                        }
                        Alt.OnSyncedMetaDataChange += (entity, key, value) =>
                        {
                            scriptFunction.Set(entity);
                            scriptFunction.Set(key);
                            scriptFunction.Set(value);
                            scriptFunction.Call();
                        };
                        break;

                    case ScriptEventType.ColShape:
                        scriptFunction = ScriptFunction.Create(eventMethodDelegate,
                                                               new[] { typeof(IColShape), typeof(IEntity), typeof(bool) });
                        if (scriptFunction == null)
                        {
                            return;
                        }
                        Alt.OnColShape += (shape, entity, state) =>
                        {
                            scriptFunction.Set(shape);
                            scriptFunction.Set(entity);
                            scriptFunction.Set(state);
                            scriptFunction.Call();
                        };
                        break;
                    }

                    break;

                case Event @event:
                    var eventName = @event.Name ?? eventMethod.Name;
                    Module.On(eventName, Function.Create(eventMethodDelegate));
                    break;
                }
            });
        }
Exemplo n.º 15
0
 public void CustomScreen_OnKey_Add(CustomScreen screen, ScriptFunction script)
 {
     screen.KeyPressed += (sender, args) => script.Run((int)args.Button);
 }
Exemplo n.º 16
0
 public void BindNativeFunction(string name, int minParam, int maxParam, ScriptFunction function)
 {
     Function MyFunc = new Function();
     MyFunc.name = name;
     MyFunc.isNative = true;
     MyFunc.NativeFunction = function;
     MyFunc.minParam = minParam;
     MyFunc.maxParam = maxParam;
     functions[name] = MyFunc;
 }
Exemplo n.º 17
0
        private string ConstructFunctionCalltipText(ScriptFunction func, ScriptStruct owningStruct, int selectedParameter, out int selectionStart, out int selectionEnd)
        {
            string callTip = func.Type + " ";
            if (owningStruct != null)
            {
                callTip += owningStruct.Name + ".";
            }
            callTip += func.FunctionName + "(";

            selectionStart = 0;
            selectionEnd = 0;

            string[] paramList = func.ParamList.Split(',');
            for (int i = 0; i < paramList.Length; i++)
            {
                string thisParam = paramList[i].Trim();
                if (thisParam.IndexOf('=') > 0)
                {
                    thisParam = "optional " + thisParam.Substring(0, thisParam.IndexOf('='));
                }
                if (i == selectedParameter)
                {
                    selectionStart = callTip.Length;
                    selectionEnd = callTip.Length + thisParam.Length;

                    if (ShowEnumForParameterIfAppropriate(thisParam))
                    {
                        // showing enum list rather than calltip
                        return null;
                    }
                }
                callTip += thisParam;
                if (i < paramList.Length - 1)
                {
                    callTip += ", ";
                }
            }

            callTip += ")";
            return callTip;
        }
 public ScriptFuntionWrapper(ScriptFunction function)
 {
     _function = function;
 }
Exemplo n.º 19
0
 public void CustomScreen_SetTimer(CustomScreen screen, int ms, ScriptFunction script)
 {
     screen.SetTimer(ms, (sender, args) => script.Run());
 }
 public ScriptFuntionWrapper(ScriptFunction function, bool isErrorOutput)
 {
     _function      = function;
     _isErrorOutput = isErrorOutput;
 }
Exemplo n.º 21
0
        private void RegisterEvents(object target /*, Chat chat*/)
        {
            ModuleScriptMethodIndexer.Index(target, new[] { typeof(Command), typeof(CommandEvent) },
                                            (baseEvent, eventMethod, eventMethodDelegate) =>
            {
                if (baseEvent is Command command)
                {
                    var commandName = command.Name ?? eventMethod.Name;
                    Handles.AddLast(GCHandle.Alloc(eventMethodDelegate));
                    var function = Function.Create(eventMethodDelegate);
                    if (function == null)
                    {
                        Alt.Log("Unsupported Command method: " + eventMethod);
                        return;
                    }

                    Functions.AddLast(function);

                    /*chat.RegisterCommand(commandName,
                     *  (player, arguments) =>
                     *  {
                     *      function.InvokeNoResult(function.CalculateStringInvokeValues(arguments, player));
                     *  });*/
                    LinkedList <CommandDelegate> delegates;
                    if (!commandDelegates.TryGetValue(commandName, out delegates))
                    {
                        delegates = new LinkedList <CommandDelegate>();
                        commandDelegates[commandName] = delegates;
                    }

                    if (command.GreedyArg)
                    {
                        delegates.AddLast((player, arguments) =>
                        {
                            function.Call(player, new[] { string.Join(" ", arguments) });
                        });
                    }
                    else
                    {
                        delegates.AddLast((player, arguments) => { function.Call(player, arguments); });
                    }

                    var aliases = command.Aliases;
                    if (aliases != null)
                    {
                        foreach (var alias in aliases)
                        {
                            if (!commandDelegates.TryGetValue(alias, out delegates))
                            {
                                delegates = new LinkedList <CommandDelegate>();
                                commandDelegates[alias] = delegates;
                            }

                            if (command.GreedyArg)
                            {
                                delegates.AddLast((player, arguments) =>
                                {
                                    function.Call(player, new[] { string.Join(" ", arguments) });
                                });
                            }
                            else
                            {
                                delegates.AddLast((player, arguments) => { function.Call(player, arguments); });
                            }
                        }
                    }
                }
                else if (baseEvent is CommandEvent commandEvent)
                {
                    var commandEventType = commandEvent.EventType;
                    ScriptFunction scriptFunction;
                    switch (commandEventType)
                    {
                    case CommandEventType.CommandNotFound:
                        scriptFunction = ScriptFunction.Create(eventMethodDelegate,
                                                               new[] { typeof(IPlayer), typeof(string) });
                        if (scriptFunction == null)
                        {
                            return;
                        }
                        AltChat.OnCommandDoesNotExists += (player, commandName) =>
                        {
                            scriptFunction.Set(player);
                            scriptFunction.Set(commandName);
                            scriptFunction.Call();
                        };
                        break;
                    }
                }
            });
        }
Exemplo n.º 22
0
        public static void ConstructCache(Script scriptToCache, IEnumerable <Script> importScripts)
        {
            string originalText              = scriptToCache.Text;
            ScriptAutoCompleteData newCache  = new ScriptAutoCompleteData();
            List <ScriptVariable>  variables = newCache.Variables;
            List <ScriptFunction>  functions = newCache.Functions;
            List <ScriptDefine>    defines   = newCache.Defines;
            List <ScriptEnum>      enums     = newCache.Enums;
            List <ScriptStruct>    structs   = newCache.Structs;

            variables.Clear();
            functions.Clear();
            defines.Clear();
            enums.Clear();
            structs.Clear();
            FastString script                    = originalText;
            AutoCompleteParserState state        = new AutoCompleteParserState();
            ScriptFunction          lastFunction = null;
            // Struct lookup will have both local and imported types
            List <ScriptStruct> structsLookup = new List <ScriptStruct>();

            if (importScripts != null)
            {
                foreach (var import in importScripts)
                {
                    structsLookup.AddRange(import.AutoCompleteData.Structs);
                }
            }

            while (script.Length > 0)
            {
                SkipWhitespace(ref script);
                state.CurrentScriptCharacterIndex = originalText.Length - script.Length;

                if (script.Length == 0)
                {
                    break;
                }
                if (script.StartsWith("//"))
                {
                    FastString scriptAtComment = script;
                    GoToNextLine(ref script);

                    if (scriptAtComment.StartsWith("///"))
                    {
                        FastString commentText = scriptAtComment.Substring(3, (scriptAtComment.Length - script.Length) - 3);
                        state.PreviousComment = commentText.ToString().Trim();
                    }
                    continue;
                }
                if (script.StartsWith("/*"))
                {
                    int endOfComment = script.IndexOf("*/");
                    if (endOfComment < 0)
                    {
                        break;
                    }
                    script = script.Substring(endOfComment + 2);
                    continue;
                }
                if (script.StartsWith("#"))
                {
                    ProcessPreProcessorDirective(defines, ref script, state);
                    continue;
                }
                if (script.StartsWith("{"))
                {
                    if (state.WordBeforeLast == "enum")
                    {
                        state.InsideEnumDefinition = new ScriptEnum(state.LastWord, state.InsideIfDefBlock, state.InsideIfNDefBlock);
                    }
                    else if (state.WordBeforeLast == "extends")
                    {
                        // inherited struct
                        foreach (ScriptStruct baseStruct in structsLookup)
                        {
                            if (baseStruct.Name == state.LastWord)
                            {
                                state.InsideStructDefinition = CreateInheritedStruct(baseStruct, state);
                                functions = state.InsideStructDefinition.Functions;
                                variables = state.InsideStructDefinition.Variables;
                                break;
                            }
                        }
                    }
                    else if (state.WordBeforeLast == "struct")
                    {
                        state.InsideStructDefinition = new ScriptStruct(state.LastWord, state.InsideIfDefBlock, state.InsideIfNDefBlock, state.CurrentScriptCharacterIndex);
                        functions = state.InsideStructDefinition.Functions;
                        variables = state.InsideStructDefinition.Variables;
                    }
                    else
                    {
                        state.ClearPreviousWords();

                        SkipUntilMatchingClosingBrace(ref script);

                        if ((lastFunction != null) && (lastFunction.EndsAtCharacterIndex == 0))
                        {
                            lastFunction.EndsAtCharacterIndex = originalText.Length - script.Length;
                        }
                        continue;
                    }
                }

                string thisWord = GetNextWord(ref script);
                if (thisWord == "(")
                {
                    List <ScriptFunction> functionList = functions;
                    bool isStaticExtender = script.StartsWith("static ");
                    bool isExtenderMethod = isStaticExtender || script.StartsWith("this ");
                    if (isExtenderMethod)
                    {
                        ScriptStruct newStruct = null;
                        // NOTE: for extenders we DO NOT look up the global struct list;
                        // the reason is a bit complicated, but in a nutshell:
                        // we need to have a list of extender functions bound to the
                        // struct defs in the *local* script's autocomplete cache, not the
                        // imported script's cache. The struct defs may be duplicated this
                        // way, but that's mostly fine, as these may be merged together;
                        // e.g. see ScintillaWrapper.GetAllStructsWithMatchingName().
                        AdjustFunctionListForExtenderFunction(structs, ref functionList, ref newStruct, ref script);
                        if (newStruct != null)
                        {
                            structs.Add(newStruct);
                            structsLookup.Add(newStruct);
                        }
                    }
                    if (AddFunctionDeclaration(functionList, ref script, thisWord, state, isExtenderMethod, isStaticExtender, isStaticExtender))
                    {
                        lastFunction = functionList[functionList.Count - 1];
                    }
                    state.ClearPreviousWords();
                }
                else if ((thisWord == "[") && (PeekNextWord(script) == "]"))
                {
                    GetNextWord(ref script);
                    state.DynamicArrayDefinition = true;
                    state.AddNextWord("[]");
                }
                else if ((thisWord == "=") || (thisWord == ";") ||
                         (thisWord == ",") || (thisWord == "["))
                {
                    if (state.InsideEnumDefinition != null)
                    {
                        AddEnumValue(state.InsideEnumDefinition, script, state.LastWord);

                        if (thisWord == "=")
                        {
                            // skip whatever the value of the enum is
                            GetNextWord(ref script);
                        }
                    }
                    else
                    {
                        AddVariableDeclaration(variables, ref script, thisWord, state);
                        if (thisWord == "=")
                        {
                            while ((thisWord != ";") && (thisWord != ",") && (script.Length > 0))
                            {
                                thisWord = GetNextWord(ref script);
                            }
                        }
                        if (thisWord == ",")
                        {
                            // eg. "int x,y"; ensure "y" gets recorded next time round
                            state.UndoLastWord();
                            continue;
                        }
                        if (thisWord == "[")
                        {
                            // eg. "int a[10], b[10], c[10];"
                            SkipWhitespace(ref script);
                            if (script.StartsWith(","))
                            {
                                GetNextWord(ref script);
                                state.UndoLastWord();
                                continue;
                            }
                        }
                    }
                    state.ClearPreviousWords();
                    state.DynamicArrayDefinition = false;
                }
                else if ((thisWord == "}") && (state.InsideEnumDefinition != null))
                {
                    // add the last value (unless it's an empty enum)
                    if (state.LastWord != "{")
                    {
                        AddEnumValue(state.InsideEnumDefinition, script, state.LastWord);
                    }
                    enums.Add(state.InsideEnumDefinition);
                    state.InsideEnumDefinition = null;
                    state.ClearPreviousWords();
                }
                else if ((thisWord == "}") && (state.InsideStructDefinition != null))
                {
                    structs.Add(state.InsideStructDefinition);
                    structsLookup.Add(state.InsideStructDefinition);
                    // Restore struct member references to global script ones
                    functions = newCache.Functions;
                    variables = newCache.Variables;
                    state.InsideStructDefinition = null;
                    state.ClearPreviousWords();
                }
                else
                {
                    state.AddNextWord(thisWord);
                }
            }
            scriptToCache.AutoCompleteData.CopyFrom(newCache);
            scriptToCache.AutoCompleteData.Populated = true;
        }
Exemplo n.º 23
0
        private static bool AddFunctionDeclaration(List <ScriptFunction> functions, ref FastString script, string thisWord, AutoCompleteParserState state, bool isExtenderMethod)
        {
            bool succeeded = false;

            if ((state.LastWord.Length > 0) && (state.WordBeforeLast.Length > 0))
            {
                if (!DoesCurrentLineHaveToken(script, AUTO_COMPLETE_IGNORE))
                {
                    string functionName = state.LastWord;
                    string type = state.WordBeforeLast;
                    bool   isPointer = false, isNoInherit = false;
                    bool   isStatic = false, isStaticOnly = false;
                    bool   isProtected = false;
                    if (type == "::")
                    {
                        functionName = state.WordBeforeWordBeforeLast + "::" + functionName;
                        type         = (state.PreviousWords.Length > 3) ? state.PreviousWords[3] : "unknown";
                    }
                    if (type == "*")
                    {
                        isPointer = true;
                        type      = state.WordBeforeWordBeforeLast;
                    }
                    if (state.DynamicArrayDefinition)
                    {
                        // get the type name and the []
                        type = state.WordBeforeWordBeforeLast + state.WordBeforeLast;
                    }
                    if (state.IsWordInPreviousList("static"))
                    {
                        isStatic = true;
                    }
                    if (state.IsWordInPreviousList("protected"))
                    {
                        isProtected = true;
                    }
                    if (DoesCurrentLineHaveToken(script, AUTO_COMPLETE_STATIC_ONLY))
                    {
                        isStaticOnly = true;
                    }
                    if (DoesCurrentLineHaveToken(script, AUTO_COMPLETE_NO_INHERIT))
                    {
                        isNoInherit = true;
                    }

                    int parameterListEndIndex = script.IndexOf(')');
                    if (parameterListEndIndex >= 0)
                    {
                        string parameterList = script.Substring(0, parameterListEndIndex);
                        script = script.Substring(parameterListEndIndex + 1);
                        ScriptFunction newFunc = new ScriptFunction(functionName, type, parameterList, state.InsideIfDefBlock, state.InsideIfNDefBlock, isPointer, isStatic, isStaticOnly, isNoInherit, isProtected, isExtenderMethod, state.CurrentScriptCharacterIndex - 1);
                        if (!string.IsNullOrEmpty(state.PreviousComment))
                        {
                            newFunc.Description   = state.PreviousComment;
                            state.PreviousComment = null;
                        }
                        functions.Add(newFunc);
                        succeeded = true;
                    }
                    state.DynamicArrayDefinition = false;
                }
            }

            return(succeeded);
        }
Exemplo n.º 24
0
 public ServicesConfigScript(int pos, ScriptFunction function, string buttonText)
     : base(pos, $"{function.Owner.Name}:{function.Name}", buttonText)
 {
     Function = function;
 }
Exemplo n.º 25
0
		/// <summary>
		/// Process a XML file containing CheApe definitions
		/// </summary>
		/// <param name="state"></param>
		/// <param name="s"></param>
		private void ProcessFile(ProjectState state, BlamLib.IO.XmlStream s)
		{
			int complexity = 1 + 
				PreprocessXmlNodeComplexity();

			BlamVersion def_engine = BlamVersion.Unknown;
			s.ReadAttribute("game", ref def_engine);
			if (def_engine != state.Definition.Engine)
			{
				Debug.Assert.If(false, "CheApe definition '{0}' is for {1}. Expected a {2} definition.", s.FileName, def_engine, state.Definition.Engine);
			}
			else
			{
				string name_str;
				foreach (XmlNode n in s.Cursor.ChildNodes)
				{
					switch (n.Name)
					{
						#region Enums
						case "enums":
							s.SaveCursor(n);
							foreach (XmlNode n2 in s.Cursor.ChildNodes)
							{
								if (n2.Name != "Enum") continue;

								s.SaveCursor(n2);
								StringList list = new StringList(state, s);
								s.RestoreCursor();
								name_str = list.ToString();

								try { Enums.Add(name_str, list); }
								catch (ArgumentException) { Debug.LogFile.WriteLine(kDuplicateErrorStr, "enum definition", name_str); }
							}
							s.RestoreCursor();
							break;
						#endregion

						#region Flags
						case "flags":
							s.SaveCursor(n);
							foreach (XmlNode n2 in s.Cursor.ChildNodes)
							{
								if (n2.Name != "Flag") continue;

								s.SaveCursor(n2);
								StringList list = new StringList(state, s);
								s.RestoreCursor();
								name_str = list.ToString();

								try { Flags.Add(name_str, list); }
								catch (ArgumentException) { Debug.LogFile.WriteLine(kDuplicateErrorStr, "flag definition", name_str); }
							}
							s.RestoreCursor();
							break;
						#endregion

						#region Tag References
						case "references":
							s.SaveCursor(n);
							foreach (XmlNode n2 in s.Cursor.ChildNodes)
							{
								if (n2.Name != "Reference") continue;

								s.SaveCursor(n2);
								TagReference tagref = new TagReference(state, s);
								s.RestoreCursor();
								name_str = tagref.ToString();

								try { References.Add(name_str, tagref); }
								catch (ArgumentException) { Debug.LogFile.WriteLine(kDuplicateErrorStr, "tag reference definition", name_str); }
							}
							s.RestoreCursor();
							break;
						#endregion

						#region Tag Data
						case "data":
							s.SaveCursor(n);
							foreach (XmlNode n2 in s.Cursor.ChildNodes)
							{
								if (n2.Name != "TagData") continue;

								s.SaveCursor(n2);
								TagData tagdata = new TagData(state, s);
								s.RestoreCursor();
								name_str = tagdata.ToString();

								try { Data.Add(name_str, tagdata); }
								catch (ArgumentException) { Debug.LogFile.WriteLine(kDuplicateErrorStr, "tag data definition", name_str); }
							}
							s.RestoreCursor();
							break;
						#endregion

						#region Script Functions
						case "scriptFunctions":
							if (state.scriptingInterface == null) break;

							s.SaveCursor(n);
							foreach (XmlNode n2 in s.Cursor.ChildNodes)
							{
								if (n2.Name != "function") continue;

								s.SaveCursor(n2);
								ScriptFunction sc = new ScriptFunction(state, s);
								s.RestoreCursor();
								name_str = sc.ToString();

								if (state.scriptingInterface.Functions.Contains(name_str))
								{
									Debug.LogFile.WriteLine("Engine already contains a {0} named '{1}', skipping...", "script function", name_str);
									continue;
								}

								try { ScriptFunctions.Add(name_str, sc); }
								catch (ArgumentException) { Debug.LogFile.WriteLine(kDuplicateErrorStr, "script function definition", name_str); }
							}
							s.RestoreCursor();
							break;
						#endregion

						#region Script Globals
						case "scriptGlobals":
							if (state.scriptingInterface == null) break;

							s.SaveCursor(n);
							foreach (XmlNode n2 in s.Cursor.ChildNodes)
							{
								if (n2.Name != "global") continue;

								s.SaveCursor(n2);
								ScriptGlobal sc = new ScriptGlobal(state, s);
								s.RestoreCursor();
								name_str = sc.ToString();

								if (state.scriptingInterface.Globals.Contains(name_str))
								{
									Debug.LogFile.WriteLine("Engine already contains a {0} named '{1}', ignoring...", "script global", name_str);
									continue;
								}

								try { ScriptGlobals.Add(name_str, sc); }
								catch (ArgumentException) { Debug.LogFile.WriteLine(kDuplicateErrorStr, "script global definition", name_str); }
							}
							s.RestoreCursor();
							break;
						#endregion

						#region Fix-ups
						case "fixups":
							s.SaveCursor(n);
							foreach (XmlNode n2 in s.Cursor.ChildNodes)
							{
								if (n2.Name != "fixup") continue;

								s.SaveCursor(n2);
								Fixup fu = new Fixup(state, s);
								s.RestoreCursor();
								name_str = fu.ToString();

								try { Fixups.Add(name_str, fu); }
								catch (ArgumentException) { Debug.LogFile.WriteLine(kDuplicateErrorStr, "fix-up definition", name_str); }
							}
							s.RestoreCursor();
							break;
						#endregion

						default:
							ProcessDefinition(n, state, s);
							break;
					}
				}
			}
		}
Exemplo n.º 26
0
        }                                                                                                            //new Control().Invoke может быть создан уже в другом потоке

        public object AddHandler(object obj, string eventName, ScriptFunction func)
        {
            return(JSEventHelper.AddHandler(obj, eventName, func));
        }
 public DynamicDelegate(Script script, ScriptFunction function, Type returnType)
 {
     m_Script = script;
     m_Function = function;
     m_ReturnType = returnType;
 }
Exemplo n.º 28
0
 internal JSFunction(ScriptFunction function, JSEvalEngine engine)
 {
     _engine = engine; _this = function is Closure ? engine : null /*delegate*/; this.function = function;
 }
Exemplo n.º 29
0
		void ProcessScriptFunctions(ProjectState state, IO.XmlStream s)
		{
			foreach (XmlNode n in s.Cursor.ChildNodes)
			{
				if (n.Name != "function") continue;

				s.SaveCursor(n);
				var sc = new ScriptFunction(state, s);
				s.RestoreCursor();
				string name_str = sc.ToString();

				if (state.scriptingInterface.Functions.Contains(name_str))
				{
					Debug.LogFile.WriteLine("Engine already contains a {0} named '{1}', skipping...", "script function", name_str);
					continue;
				}

				try { ScriptFunctions.Add(name_str, sc); }
				catch (ArgumentException) { Debug.LogFile.WriteLine(kDuplicateErrorStr, "script function definition", name_str); }
			}
		}
        public static void RegisterEvents(object target)
        {
            ModuleScriptMethodIndexer.Index(target,
                                            new[] { typeof(ServerEventAttribute), typeof(ClientEventAttribute), typeof(ScriptEventAttribute) },
                                            (baseEvent, eventMethod, eventMethodDelegate) =>
            {
                switch (baseEvent)
                {
                case ScriptEventAttribute scriptEvent:
                    var scriptEventType = scriptEvent.EventType;
                    ScriptFunction scriptFunction;
                    switch (scriptEventType)
                    {
                    case ScriptEventType.Checkpoint:
                        scriptFunction = ScriptFunction.Create(eventMethodDelegate,
                                                               new[] { typeof(ICheckpoint), typeof(IEntity), typeof(bool) });
                        if (scriptFunction == null)
                        {
                            return;
                        }
                        OnCheckpoint += (checkpoint, entity, state) =>
                        {
                            scriptFunction.Set(checkpoint);
                            scriptFunction.Set(entity);
                            scriptFunction.Set(state);
                            scriptFunction.Call();
                        };
                        break;

                    case ScriptEventType.PlayerConnect:
                        scriptFunction = ScriptFunction.Create(eventMethodDelegate,
                                                               new[] { typeof(IPlayer), typeof(string) });
                        if (scriptFunction == null)
                        {
                            return;
                        }
                        OnPlayerConnect += (player, reason) =>
                        {
                            scriptFunction.Set(player);
                            scriptFunction.Set(reason);
                            scriptFunction.Call();
                        };
                        break;

                    case ScriptEventType.PlayerBeforeConnect:
                        scriptFunction = ScriptFunction.Create(eventMethodDelegate,
                                                               new[] { typeof(PlayerConnectionInfo), typeof(string) });
                        if (scriptFunction == null)
                        {
                            return;
                        }
                        OnPlayerBeforeConnect += (connectionInfo, reason) =>
                        {
                            scriptFunction.Set(connectionInfo);
                            scriptFunction.Set(reason);
                            if (scriptFunction.Call() is string value)
                            {
                                return(value);
                            }

                            return(null);
                        };
                        break;

                    case ScriptEventType.PlayerDamage:
                        scriptFunction = ScriptFunction.Create(eventMethodDelegate,
                                                               new[] { typeof(IPlayer), typeof(IEntity), typeof(uint), typeof(ushort), typeof(ushort) });
                        if (scriptFunction == null)
                        {
                            return;
                        }
                        OnPlayerDamage += (player, attacker, weapon, healthDamage, armourDamage) =>
                        {
                            scriptFunction.Set(player);
                            scriptFunction.Set(attacker);
                            scriptFunction.Set(weapon);
                            scriptFunction.Set(healthDamage);
                            scriptFunction.Set(armourDamage);
                            scriptFunction.Call();
                        };
                        break;

                    case ScriptEventType.PlayerDead:
                        scriptFunction = ScriptFunction.Create(eventMethodDelegate,
                                                               new[] { typeof(IPlayer), typeof(IEntity), typeof(uint) });
                        if (scriptFunction == null)
                        {
                            return;
                        }
                        OnPlayerDead += (player, attacker, weapon) =>
                        {
                            scriptFunction.Set(player);
                            scriptFunction.Set(attacker);
                            scriptFunction.Set(weapon);
                            scriptFunction.Call();
                        };
                        break;

                    case ScriptEventType.PlayerDisconnect:
                        scriptFunction = ScriptFunction.Create(eventMethodDelegate,
                                                               new[] { typeof(IPlayer), typeof(string) });
                        if (scriptFunction == null)
                        {
                            return;
                        }
                        OnPlayerDisconnect += (player, reason) =>
                        {
                            scriptFunction.Set(player);
                            scriptFunction.Set(reason);
                            scriptFunction.Call();
                        };
                        break;

                    case ScriptEventType.PlayerRemove:
                        scriptFunction =
                            ScriptFunction.Create(eventMethodDelegate, new[] { typeof(IPlayer) });
                        if (scriptFunction == null)
                        {
                            return;
                        }
                        OnPlayerRemove += player =>
                        {
                            scriptFunction.Set(player);
                            scriptFunction.Call();
                        };
                        break;

                    case ScriptEventType.VehicleRemove:
                        scriptFunction =
                            ScriptFunction.Create(eventMethodDelegate, new[] { typeof(IVehicle) });
                        if (scriptFunction == null)
                        {
                            return;
                        }
                        OnVehicleRemove += vehicle =>
                        {
                            scriptFunction.Set(vehicle);
                            scriptFunction.Call();
                        };
                        break;

                    case ScriptEventType.PlayerChangeVehicleSeat:
                        scriptFunction =
                            ScriptFunction.Create(eventMethodDelegate,
                                                  new[] { typeof(IVehicle), typeof(IPlayer), typeof(byte), typeof(byte) });
                        if (scriptFunction == null)
                        {
                            return;
                        }
                        OnPlayerChangeVehicleSeat += (vehicle, player, seat, newSeat) =>
                        {
                            scriptFunction.Set(vehicle);
                            scriptFunction.Set(player);
                            scriptFunction.Set(seat);
                            scriptFunction.Set(newSeat);
                            scriptFunction.Call();
                        };
                        break;

                    case ScriptEventType.PlayerEnterVehicle:
                        scriptFunction =
                            ScriptFunction.Create(eventMethodDelegate,
                                                  new[] { typeof(IVehicle), typeof(IPlayer), typeof(byte) });
                        if (scriptFunction == null)
                        {
                            return;
                        }
                        OnPlayerEnterVehicle += (vehicle, player, seat) =>
                        {
                            scriptFunction.Set(vehicle);
                            scriptFunction.Set(player);
                            scriptFunction.Set(seat);
                            scriptFunction.Call();
                        };
                        break;

                    case ScriptEventType.PlayerEnteringVehicle:
                        scriptFunction =
                            ScriptFunction.Create(eventMethodDelegate,
                                                  new[] { typeof(IVehicle), typeof(IPlayer), typeof(byte) });
                        if (scriptFunction == null)
                        {
                            return;
                        }
                        OnPlayerEnteringVehicle += (vehicle, player, seat) =>
                        {
                            scriptFunction.Set(vehicle);
                            scriptFunction.Set(player);
                            scriptFunction.Set(seat);
                            scriptFunction.Call();
                        };
                        break;

                    case ScriptEventType.PlayerLeaveVehicle:
                        scriptFunction =
                            ScriptFunction.Create(eventMethodDelegate,
                                                  new[] { typeof(IVehicle), typeof(IPlayer), typeof(byte) });
                        if (scriptFunction == null)
                        {
                            return;
                        }
                        OnPlayerLeaveVehicle += (vehicle, player, seat) =>
                        {
                            scriptFunction.Set(vehicle);
                            scriptFunction.Set(player);
                            scriptFunction.Set(seat);
                            scriptFunction.Call();
                        };
                        break;

                    case ScriptEventType.PlayerEvent:
                        scriptFunction =
                            ScriptFunction.Create(eventMethodDelegate,
                                                  new[] { typeof(IPlayer), typeof(string), typeof(object[]) });
                        if (scriptFunction == null)
                        {
                            return;
                        }
                        OnPlayerEvent += (player, name, args) =>
                        {
                            scriptFunction.Set(player);
                            scriptFunction.Set(name);
                            scriptFunction.Set(args);
                            scriptFunction.Call();
                        };
                        break;

                    case ScriptEventType.PlayerCustomEvent:
                        scriptFunction =
                            ScriptFunction.Create(eventMethodDelegate,
                                                  new[] { typeof(IPlayer), typeof(string), typeof(MValueConst[]) });
                        if (scriptFunction == null)
                        {
                            return;
                        }
                        OnPlayerCustomEvent += (player, name, array) =>
                        {
                            scriptFunction.Set(player);
                            scriptFunction.Set(name);
                            scriptFunction.Set(array);
                            scriptFunction.Call();
                        };
                        break;

                    case ScriptEventType.ServerEvent:
                        scriptFunction = ScriptFunction.Create(eventMethodDelegate,
                                                               new[] { typeof(string), typeof(object[]) });
                        if (scriptFunction == null)
                        {
                            return;
                        }
                        OnServerEvent += (scriptEventName, scriptEventArgs) =>
                        {
                            scriptFunction.Set(scriptEventName);
                            scriptFunction.Set(scriptEventArgs);
                            scriptFunction.Call();
                        };
                        break;

                    case ScriptEventType.ServerCustomEvent:
                        scriptFunction = ScriptFunction.Create(eventMethodDelegate,
                                                               new[] { typeof(string), typeof(MValueConst[]) });
                        if (scriptFunction == null)
                        {
                            return;
                        }
                        OnServerCustomEvent += (name, array) =>
                        {
                            scriptFunction.Set(name);
                            scriptFunction.Set(array);
                            scriptFunction.Call();
                        };
                        break;

                    case ScriptEventType.ConsoleCommand:
                        scriptFunction = ScriptFunction.Create(eventMethodDelegate,
                                                               new[] { typeof(string), typeof(string[]) });
                        if (scriptFunction == null)
                        {
                            return;
                        }
                        OnConsoleCommand += (name, args) =>
                        {
                            scriptFunction.Set(name);
                            scriptFunction.Set(args);
                            scriptFunction.Call();
                        };
                        break;

                    case ScriptEventType.MetaDataChange:
                        scriptFunction = ScriptFunction.Create(eventMethodDelegate,
                                                               new[] { typeof(IEntity), typeof(string), typeof(object) });
                        if (scriptFunction == null)
                        {
                            return;
                        }
                        OnMetaDataChange += (entity, key, value) =>
                        {
                            scriptFunction.Set(entity);
                            scriptFunction.Set(key);
                            scriptFunction.Set(value);
                            scriptFunction.Call();
                        };
                        break;

                    case ScriptEventType.SyncedMetaDataChange:
                        scriptFunction = ScriptFunction.Create(eventMethodDelegate,
                                                               new[] { typeof(IEntity), typeof(string), typeof(object) });
                        if (scriptFunction == null)
                        {
                            return;
                        }
                        OnSyncedMetaDataChange += (entity, key, value) =>
                        {
                            scriptFunction.Set(entity);
                            scriptFunction.Set(key);
                            scriptFunction.Set(value);
                            scriptFunction.Call();
                        };
                        break;

                    case ScriptEventType.ColShape:
                        scriptFunction = ScriptFunction.Create(eventMethodDelegate,
                                                               new[] { typeof(IColShape), typeof(IEntity), typeof(bool) });
                        if (scriptFunction == null)
                        {
                            return;
                        }
                        OnColShape += (shape, entity, state) =>
                        {
                            scriptFunction.Set(shape);
                            scriptFunction.Set(entity);
                            scriptFunction.Set(state);
                            scriptFunction.Call();
                        };
                        break;

                    case ScriptEventType.WeaponDamage:
                        scriptFunction = ScriptFunction.Create(eventMethodDelegate,
                                                               new[]
                        {
                            typeof(IPlayer), typeof(IEntity), typeof(uint), typeof(ushort),
                            typeof(Position), typeof(BodyPart)
                        });
                        if (scriptFunction == null)
                        {
                            return;
                        }
                        OnWeaponDamage +=
                            (player, targetEntity, weapon, damage, shotOffset, damageOffset) =>
                        {
                            scriptFunction.Set(player);
                            scriptFunction.Set(targetEntity);
                            scriptFunction.Set(weapon);
                            scriptFunction.Set(damage);
                            scriptFunction.Set(shotOffset);
                            scriptFunction.Set(damageOffset);
                            if (scriptFunction.Call() is bool value)
                            {
                                return(value);
                            }

                            return(true);
                        };
                        break;

                    case ScriptEventType.VehicleDestroy:
                        scriptFunction = ScriptFunction.Create(eventMethodDelegate,
                                                               new[]
                        {
                            typeof(IVehicle)
                        });
                        if (scriptFunction == null)
                        {
                            return;
                        }
                        OnVehicleDestroy +=
                            vehicle =>
                        {
                            scriptFunction.Set(vehicle);
                            scriptFunction.Call();
                        };
                        break;

                    case ScriptEventType.Explosion:
                        scriptFunction = ScriptFunction.Create(eventMethodDelegate,
                                                               new[]
                        {
                            typeof(IPlayer), typeof(ExplosionType), typeof(Position), typeof(uint),
                            typeof(IEntity)
                        });
                        if (scriptFunction == null)
                        {
                            return;
                        }
                        OnExplosion += (player, explosionType, position, explosionFx, targetEntity) =>
                        {
                            scriptFunction.Set(player);
                            scriptFunction.Set(explosionType);
                            scriptFunction.Set(position);
                            scriptFunction.Set(explosionFx);
                            scriptFunction.Set(targetEntity);
                            if (scriptFunction.Call() is bool value)
                            {
                                return(value);
                            }

                            return(true);
                        };
                        break;

                    case ScriptEventType.Fire:
                        scriptFunction = ScriptFunction.Create(eventMethodDelegate,
                                                               new[]
                        {
                            typeof(IPlayer), typeof(FireInfo[])
                        });
                        if (scriptFunction == null)
                        {
                            return;
                        }
                        OnFire += (player, fireInfos) =>
                        {
                            scriptFunction.Set(player);
                            scriptFunction.Set(fireInfos);
                            if (scriptFunction.Call() is bool value)
                            {
                                return(value);
                            }

                            return(true);
                        };
                        break;

                    case ScriptEventType.StartProjectile:
                        scriptFunction = ScriptFunction.Create(eventMethodDelegate,
                                                               new[]
                        {
                            typeof(IPlayer), typeof(Position), typeof(Position), typeof(uint),
                            typeof(uint)
                        });
                        if (scriptFunction == null)
                        {
                            return;
                        }
                        OnStartProjectile += (player, startPosition, direction, ammoHash, weaponHash) =>
                        {
                            scriptFunction.Set(player);
                            scriptFunction.Set(startPosition);
                            scriptFunction.Set(direction);
                            scriptFunction.Set(ammoHash);
                            scriptFunction.Set(weaponHash);
                            if (scriptFunction.Call() is bool value)
                            {
                                return(value);
                            }

                            return(true);
                        };
                        break;

                    case ScriptEventType.PlayerWeaponChange:
                        scriptFunction = ScriptFunction.Create(eventMethodDelegate,
                                                               new[]
                        {
                            typeof(IPlayer), typeof(uint), typeof(uint)
                        });
                        if (scriptFunction == null)
                        {
                            return;
                        }
                        OnPlayerWeaponChange += (player, oldWeapon, newWeapon) =>
                        {
                            scriptFunction.Set(player);
                            scriptFunction.Set(oldWeapon);
                            scriptFunction.Set(newWeapon);
                            if (scriptFunction.Call() is bool value)
                            {
                                return(value);
                            }

                            return(true);
                        };
                        break;

                    case ScriptEventType.NetOwnerChange:
                        scriptFunction = ScriptFunction.Create(eventMethodDelegate,
                                                               new[]
                        {
                            typeof(IEntity), typeof(IPlayer), typeof(IPlayer)
                        });
                        if (scriptFunction == null)
                        {
                            return;
                        }
                        OnNetworkOwnerChange += (targetEntity, oldNetOwner, newNetOwner) =>
                        {
                            scriptFunction.Set(targetEntity);
                            scriptFunction.Set(oldNetOwner);
                            scriptFunction.Set(newNetOwner);
                            scriptFunction.Call();
                        };
                        break;

                    case ScriptEventType.VehicleAttach:
                        scriptFunction = ScriptFunction.Create(eventMethodDelegate,
                                                               new[]
                        {
                            typeof(IVehicle), typeof(IVehicle)
                        });
                        if (scriptFunction == null)
                        {
                            return;
                        }
                        OnVehicleAttach += (targetVehicle, attachedVehicle) =>
                        {
                            scriptFunction.Set(targetVehicle);
                            scriptFunction.Set(attachedVehicle);
                            scriptFunction.Call();
                        };
                        break;

                    case ScriptEventType.VehicleDetach:
                        scriptFunction = ScriptFunction.Create(eventMethodDelegate,
                                                               new[]
                        {
                            typeof(IVehicle), typeof(IVehicle)
                        });
                        if (scriptFunction == null)
                        {
                            return;
                        }
                        OnVehicleDetach += (targetVehicle, detachedVehicle) =>
                        {
                            scriptFunction.Set(targetVehicle);
                            scriptFunction.Set(detachedVehicle);
                            scriptFunction.Call();
                        };
                        break;

                    case ScriptEventType.VehicleDamage:
                        scriptFunction = ScriptFunction.Create(eventMethodDelegate,
                                                               new[]
                        {
                            typeof(IVehicle), typeof(IEntity), typeof(uint), typeof(uint),
                            typeof(uint), typeof(uint), typeof(uint)
                        });
                        if (scriptFunction == null)
                        {
                            return;
                        }
                        OnVehicleDamage +=
                            (vehicle, targetEntity, bodyHealthDamage, additionalBodyHealthDamage, engineHealthDamage, petrolTankDamage, weaponHash) =>
                        {
                            scriptFunction.Set(vehicle);
                            scriptFunction.Set(targetEntity);
                            scriptFunction.Set(bodyHealthDamage);
                            scriptFunction.Set(additionalBodyHealthDamage);
                            scriptFunction.Set(engineHealthDamage);
                            scriptFunction.Set(petrolTankDamage);
                            scriptFunction.Set(weaponHash);
                            scriptFunction.Call();
                        };
                        break;

                    case ScriptEventType.ConnectionQueueAdd:
                        scriptFunction = ScriptFunction.Create(eventMethodDelegate,
                                                               new[]
                        {
                            typeof(IConnectionInfo)
                        });
                        if (scriptFunction == null)
                        {
                            return;
                        }
                        OnConnectionQueueAdd +=
                            (connectionInfo) =>
                        {
                            scriptFunction.Set(connectionInfo);
                            scriptFunction.Call();
                        };
                        break;

                    case ScriptEventType.ConnectionQueueRemove:
                        scriptFunction = ScriptFunction.Create(eventMethodDelegate,
                                                               new[]
                        {
                            typeof(IConnectionInfo)
                        });
                        if (scriptFunction == null)
                        {
                            return;
                        }
                        OnConnectionQueueRemove +=
                            (connectionInfo) =>
                        {
                            scriptFunction.Set(connectionInfo);
                            scriptFunction.Call();
                        };
                        break;

                    case ScriptEventType.ServerStarted:
                        scriptFunction = ScriptFunction.Create(eventMethodDelegate,
                                                               Array.Empty <Type>());
                        if (scriptFunction == null)
                        {
                            return;
                        }
                        OnServerStarted +=
                            () =>
                        {
                            scriptFunction.Call();
                        };
                        break;

                    case ScriptEventType.PlayerRequestControl:
                        scriptFunction = ScriptFunction.Create(eventMethodDelegate,
                                                               new []
                        {
                            typeof(IEntity), typeof(IPlayer)
                        });
                        if (scriptFunction == null)
                        {
                            return;
                        }
                        OnPlayerRequestControl +=
                            (entity, player) =>
                        {
                            scriptFunction.Set(entity);
                            scriptFunction.Set(player);
                            scriptFunction.Call();
                        };
                        break;

                    case ScriptEventType.PlayerChangeAnimation:
                        scriptFunction = ScriptFunction.Create(eventMethodDelegate,
                                                               new []
                        {
                            typeof(IEntity), typeof(uint), typeof(uint), typeof(uint), typeof(uint)
                        });
                        if (scriptFunction == null)
                        {
                            return;
                        }
                        OnPlayerChangeAnimation +=
                            (entity, oldDict, newDict, oldName, newName) =>
                        {
                            scriptFunction.Set(entity);
                            scriptFunction.Set(oldDict);
                            scriptFunction.Set(newDict);
                            scriptFunction.Set(oldName);
                            scriptFunction.Set(newName);
                            scriptFunction.Call();
                        };
                        break;

                    case ScriptEventType.PlayerChangeInterior:
                        scriptFunction = ScriptFunction.Create(eventMethodDelegate,
                                                               new []
                        {
                            typeof(IEntity), typeof(uint), typeof(uint)
                        });
                        if (scriptFunction == null)
                        {
                            return;
                        }
                        OnPlayerChangeInterior +=
                            (entity, oldIntLoc, newIntLoc) =>
                        {
                            scriptFunction.Set(entity);
                            scriptFunction.Set(oldIntLoc);
                            scriptFunction.Set(newIntLoc);
                            scriptFunction.Call();
                        };
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }

                    break;

                case ServerEventAttribute @event:
                    var serverEventName = @event.Name ?? eventMethod.Name;
                    CoreImpl.OnServer(serverEventName, Function.Create(Core, eventMethodDelegate));
                    break;

                case ClientEventAttribute @event:
                    var clientEventName = @event.Name ?? eventMethod.Name;
                    CoreImpl.OnClient(clientEventName, Function.Create(Core, eventMethodDelegate));
                    break;
                }
            });
        }
Exemplo n.º 31
0
 public Delegate CreateDelegate(Type type, ScriptFunction func)
 {
     if (type == typeof(UIEventListener.VoidDelegate))
         return new UIEventListener.VoidDelegate((go) => { func.call(go); });
     return null;
 }
Exemplo n.º 32
0
 public CmdDefintion(String _name, ScriptFunction fun, String args)
 {
     name      = _name;
     mFunction = fun;
     param     = args;
 }
Exemplo n.º 33
0
 private List<ScriptVariable> CheckFunctionForLocalVariables(int currentPos, ScriptFunction func, string scriptExtract, bool searchWholeFunction)
 {
     if ((func.EndsAtCharacterIndex > currentPos) &&
         (func.StartsAtCharacterIndex >= 0))
     {
         if ((scriptExtract.Length > currentPos) &&
             (currentPos > func.StartsAtCharacterIndex))
         {
             int startPos = func.StartsAtCharacterIndex;
             int endPos = searchWholeFunction ? func.EndsAtCharacterIndex :
                 currentPos;
             scriptExtract = scriptExtract.Substring(func.StartsAtCharacterIndex, (endPos - func.StartsAtCharacterIndex));
             int openBracketOffset = scriptExtract.IndexOf("{");
             if (openBracketOffset > 0)
             {
                 startPos += openBracketOffset;
                 scriptExtract = scriptExtract.Substring(openBracketOffset);
             }
             List<ScriptVariable> localVars = AutoComplete.GetLocalVariableDeclarationsFromScriptExtract(scriptExtract, startPos);
             AddFunctionParametersToVariableList(func, localVars);
             return localVars;
         }
     }
     return null;
 }
Exemplo n.º 34
0
        public static void RegisterEvents(object target)
        {
            ModuleScriptMethodIndexer.Index(target,
                                            new[] { typeof(ServerEventAttribute), typeof(ClientEventAttribute), typeof(ScriptEventAttribute) },
                                            (baseEvent, eventMethod, eventMethodDelegate) =>
            {
                switch (baseEvent)
                {
                case ScriptEventAttribute scriptEvent:
                    var scriptEventType = scriptEvent.EventType;
                    ScriptFunction scriptFunction;
                    switch (scriptEventType)
                    {
                    case ScriptEventType.Checkpoint:
                        scriptFunction = ScriptFunction.Create(eventMethodDelegate,
                                                               new[] { typeof(ICheckpoint), typeof(IEntity), typeof(bool) });
                        if (scriptFunction == null)
                        {
                            return;
                        }
                        OnCheckpoint += (checkpoint, entity, state) =>
                        {
                            scriptFunction.Set(checkpoint);
                            scriptFunction.Set(entity);
                            scriptFunction.Set(state);
                            scriptFunction.Call();
                        };
                        break;

                    case ScriptEventType.PlayerConnect:
                        scriptFunction = ScriptFunction.Create(eventMethodDelegate,
                                                               new[] { typeof(IPlayer), typeof(string) });
                        if (scriptFunction == null)
                        {
                            return;
                        }
                        OnPlayerConnect += (player, reason) =>
                        {
                            scriptFunction.Set(player);
                            scriptFunction.Set(reason);
                            scriptFunction.Call();
                        };
                        break;

                    case ScriptEventType.PlayerDamage:
                        scriptFunction = ScriptFunction.Create(eventMethodDelegate,
                                                               new[] { typeof(IPlayer), typeof(IEntity), typeof(uint), typeof(ushort) });
                        if (scriptFunction == null)
                        {
                            return;
                        }
                        OnPlayerDamage += (player, attacker, weapon, damage) =>
                        {
                            scriptFunction.Set(player);
                            scriptFunction.Set(attacker);
                            scriptFunction.Set(weapon);
                            scriptFunction.Set(damage);
                            scriptFunction.Call();
                        };
                        break;

                    case ScriptEventType.PlayerDead:
                        scriptFunction = ScriptFunction.Create(eventMethodDelegate,
                                                               new[] { typeof(IPlayer), typeof(IEntity), typeof(uint) });
                        if (scriptFunction == null)
                        {
                            return;
                        }
                        OnPlayerDead += (player, attacker, weapon) =>
                        {
                            scriptFunction.Set(player);
                            scriptFunction.Set(attacker);
                            scriptFunction.Set(weapon);
                            scriptFunction.Call();
                        };
                        break;

                    case ScriptEventType.PlayerDisconnect:
                        scriptFunction = ScriptFunction.Create(eventMethodDelegate,
                                                               new[] { typeof(IPlayer), typeof(string) });
                        if (scriptFunction == null)
                        {
                            return;
                        }
                        OnPlayerDisconnect += (player, reason) =>
                        {
                            scriptFunction.Set(player);
                            scriptFunction.Set(reason);
                            scriptFunction.Call();
                        };
                        break;

                    case ScriptEventType.PlayerRemove:
                        scriptFunction =
                            ScriptFunction.Create(eventMethodDelegate, new[] { typeof(IPlayer) });
                        if (scriptFunction == null)
                        {
                            return;
                        }
                        OnPlayerRemove += player =>
                        {
                            scriptFunction.Set(player);
                            scriptFunction.Call();
                        };
                        break;

                    case ScriptEventType.VehicleRemove:
                        scriptFunction =
                            ScriptFunction.Create(eventMethodDelegate, new[] { typeof(IVehicle) });
                        if (scriptFunction == null)
                        {
                            return;
                        }
                        OnVehicleRemove += vehicle =>
                        {
                            scriptFunction.Set(vehicle);
                            scriptFunction.Call();
                        };
                        break;

                    case ScriptEventType.PlayerChangeVehicleSeat:
                        scriptFunction =
                            ScriptFunction.Create(eventMethodDelegate,
                                                  new[] { typeof(IVehicle), typeof(IPlayer), typeof(byte), typeof(byte) });
                        if (scriptFunction == null)
                        {
                            return;
                        }
                        OnPlayerChangeVehicleSeat += (vehicle, player, seat, newSeat) =>
                        {
                            scriptFunction.Set(vehicle);
                            scriptFunction.Set(player);
                            scriptFunction.Set(seat);
                            scriptFunction.Set(newSeat);
                            scriptFunction.Call();
                        };
                        break;

                    case ScriptEventType.PlayerEnterVehicle:
                        scriptFunction =
                            ScriptFunction.Create(eventMethodDelegate,
                                                  new[] { typeof(IVehicle), typeof(IPlayer), typeof(byte) });
                        if (scriptFunction == null)
                        {
                            return;
                        }
                        OnPlayerEnterVehicle += (vehicle, player, seat) =>
                        {
                            scriptFunction.Set(vehicle);
                            scriptFunction.Set(player);
                            scriptFunction.Set(seat);
                            scriptFunction.Call();
                        };
                        break;

                    case ScriptEventType.PlayerLeaveVehicle:
                        scriptFunction =
                            ScriptFunction.Create(eventMethodDelegate,
                                                  new[] { typeof(IVehicle), typeof(IPlayer), typeof(byte) });
                        if (scriptFunction == null)
                        {
                            return;
                        }
                        OnPlayerLeaveVehicle += (vehicle, player, seat) =>
                        {
                            scriptFunction.Set(vehicle);
                            scriptFunction.Set(player);
                            scriptFunction.Set(seat);
                            scriptFunction.Call();
                        };
                        break;

                    case ScriptEventType.PlayerEvent:
                        scriptFunction =
                            ScriptFunction.Create(eventMethodDelegate,
                                                  new[] { typeof(IPlayer), typeof(string), typeof(object[]) });
                        if (scriptFunction == null)
                        {
                            return;
                        }
                        OnPlayerEvent += (player, name, args) =>
                        {
                            scriptFunction.Set(player);
                            scriptFunction.Set(name);
                            scriptFunction.Set(args);
                            scriptFunction.Call();
                        };
                        break;

                    case ScriptEventType.PlayerCustomEvent:
                        scriptFunction =
                            ScriptFunction.Create(eventMethodDelegate,
                                                  new[] { typeof(IPlayer), typeof(string), typeof(MValueConst[]) });
                        if (scriptFunction == null)
                        {
                            return;
                        }
                        OnPlayerCustomEvent += (player, name, array) =>
                        {
                            scriptFunction.Set(player);
                            scriptFunction.Set(name);
                            scriptFunction.Set(array);
                            scriptFunction.Call();
                        };
                        break;

                    case ScriptEventType.ServerEvent:
                        scriptFunction = ScriptFunction.Create(eventMethodDelegate,
                                                               new[] { typeof(string), typeof(object[]) });
                        if (scriptFunction == null)
                        {
                            return;
                        }
                        OnServerEvent += (scriptEventName, scriptEventArgs) =>
                        {
                            scriptFunction.Set(scriptEventName);
                            scriptFunction.Set(scriptEventArgs);
                            scriptFunction.Call();
                        };
                        break;

                    case ScriptEventType.ServerCustomEvent:
                        scriptFunction = ScriptFunction.Create(eventMethodDelegate,
                                                               new[] { typeof(string), typeof(MValueConst[]) });
                        if (scriptFunction == null)
                        {
                            return;
                        }
                        OnServerCustomEvent += (name, array) =>
                        {
                            scriptFunction.Set(name);
                            scriptFunction.Set(array);
                            scriptFunction.Call();
                        };
                        break;

                    case ScriptEventType.ConsoleCommand:
                        scriptFunction = ScriptFunction.Create(eventMethodDelegate,
                                                               new[] { typeof(string), typeof(string[]) });
                        if (scriptFunction == null)
                        {
                            return;
                        }
                        OnConsoleCommand += (name, args) =>
                        {
                            scriptFunction.Set(name);
                            scriptFunction.Set(args);
                            scriptFunction.Call();
                        };
                        break;

                    case ScriptEventType.MetaDataChange:
                        scriptFunction = ScriptFunction.Create(eventMethodDelegate,
                                                               new[] { typeof(IEntity), typeof(string), typeof(object) });
                        if (scriptFunction == null)
                        {
                            return;
                        }
                        OnMetaDataChange += (entity, key, value) =>
                        {
                            scriptFunction.Set(entity);
                            scriptFunction.Set(key);
                            scriptFunction.Set(value);
                            scriptFunction.Call();
                        };
                        break;

                    case ScriptEventType.SyncedMetaDataChange:
                        scriptFunction = ScriptFunction.Create(eventMethodDelegate,
                                                               new[] { typeof(IEntity), typeof(string), typeof(object) });
                        if (scriptFunction == null)
                        {
                            return;
                        }
                        OnSyncedMetaDataChange += (entity, key, value) =>
                        {
                            scriptFunction.Set(entity);
                            scriptFunction.Set(key);
                            scriptFunction.Set(value);
                            scriptFunction.Call();
                        };
                        break;

                    case ScriptEventType.ColShape:
                        scriptFunction = ScriptFunction.Create(eventMethodDelegate,
                                                               new[] { typeof(IColShape), typeof(IEntity), typeof(bool) });
                        if (scriptFunction == null)
                        {
                            return;
                        }
                        OnColShape += (shape, entity, state) =>
                        {
                            scriptFunction.Set(shape);
                            scriptFunction.Set(entity);
                            scriptFunction.Set(state);
                            scriptFunction.Call();
                        };
                        break;

                    case ScriptEventType.WeaponDamage:
                        scriptFunction = ScriptFunction.Create(eventMethodDelegate,
                                                               new[]
                        {
                            typeof(IPlayer), typeof(IEntity), typeof(uint), typeof(ushort),
                            typeof(Position), typeof(BodyPart)
                        });
                        if (scriptFunction == null)
                        {
                            return;
                        }
                        OnWeaponDamage +=
                            (player, targetEntity, weapon, damage, shotOffset, damageOffset) =>
                        {
                            scriptFunction.Set(player);
                            scriptFunction.Set(targetEntity);
                            scriptFunction.Set(weapon);
                            scriptFunction.Set(damage);
                            scriptFunction.Set(shotOffset);
                            scriptFunction.Set(damageOffset);
                            if (scriptFunction.Call() is bool value)
                            {
                                return(value);
                            }

                            return(true);
                        };
                        break;

                    case ScriptEventType.VehicleDestroy:
                        scriptFunction = ScriptFunction.Create(eventMethodDelegate,
                                                               new[]
                        {
                            typeof(IVehicle)
                        });
                        if (scriptFunction == null)
                        {
                            return;
                        }
                        OnVehicleDestroy +=
                            vehicle =>
                        {
                            scriptFunction.Set(vehicle);
                            scriptFunction.Call();
                        };
                        break;

                    case ScriptEventType.Explosion:
                        scriptFunction = ScriptFunction.Create(eventMethodDelegate,
                                                               new[]
                        {
                            typeof(IPlayer), typeof(ExplosionType), typeof(Position), typeof(uint),
                            typeof(IEntity)
                        });
                        if (scriptFunction == null)
                        {
                            return;
                        }
                        OnExplosion += (player, explosionType, position, explosionFx, targetEntity) =>
                        {
                            scriptFunction.Set(player);
                            scriptFunction.Set(explosionType);
                            scriptFunction.Set(position);
                            scriptFunction.Set(explosionFx);
                            scriptFunction.Set(targetEntity);
                            if (scriptFunction.Call() is bool value)
                            {
                                return(value);
                            }

                            return(true);
                        };
                        break;

                    case ScriptEventType.Fire:
                        scriptFunction = ScriptFunction.Create(eventMethodDelegate,
                                                               new[]
                        {
                            typeof(IPlayer), typeof(FireInfo[])
                        });
                        if (scriptFunction == null)
                        {
                            return;
                        }
                        OnFire += (player, fireInfos) =>
                        {
                            scriptFunction.Set(player);
                            scriptFunction.Set(fireInfos);
                            if (scriptFunction.Call() is bool value)
                            {
                                return(value);
                            }

                            return(true);
                        };
                        break;

                    case ScriptEventType.StartProjectile:
                        scriptFunction = ScriptFunction.Create(eventMethodDelegate,
                                                               new[]
                        {
                            typeof(IPlayer), typeof(Position), typeof(Position), typeof(uint),
                            typeof(uint)
                        });
                        if (scriptFunction == null)
                        {
                            return;
                        }
                        OnStartProjectile += (player, startPosition, direction, ammoHash, weaponHash) =>
                        {
                            scriptFunction.Set(player);
                            scriptFunction.Set(startPosition);
                            scriptFunction.Set(direction);
                            scriptFunction.Set(ammoHash);
                            scriptFunction.Set(weaponHash);
                            if (scriptFunction.Call() is bool value)
                            {
                                return(value);
                            }

                            return(true);
                        };
                        break;

                    case ScriptEventType.PlayerWeaponChange:
                        scriptFunction = ScriptFunction.Create(eventMethodDelegate,
                                                               new[]
                        {
                            typeof(IPlayer), typeof(uint), typeof(uint)
                        });
                        if (scriptFunction == null)
                        {
                            return;
                        }
                        OnPlayerWeaponChange += (player, oldWeapon, newWeapon) =>
                        {
                            scriptFunction.Set(player);
                            scriptFunction.Set(oldWeapon);
                            scriptFunction.Set(newWeapon);
                            if (scriptFunction.Call() is bool value)
                            {
                                return(value);
                            }

                            return(true);
                        };
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }

                    break;

                case ServerEventAttribute @event:
                    var serverEventName = @event.Name ?? eventMethod.Name;
                    Module.OnServer(serverEventName, Function.Create(eventMethodDelegate));
                    break;

                case ClientEventAttribute @event:
                    var clientEventName = @event.Name ?? eventMethod.Name;
                    Module.OnClient(clientEventName, Function.Create(eventMethodDelegate));
                    break;
                }
            });
        }
Exemplo n.º 35
0
 private void AddFunctionParametersToVariableList(ScriptFunction func, List<ScriptVariable> variables)
 {
     if (func.ParamList.Length == 0)
     {
         return;
     }
     string[] parameters = func.ParamList.Split(',');
     foreach (string thisParam in parameters)
     {
         string param = thisParam.Trim();
         if (param.StartsWith("optional "))
         {
             param = param.Substring(9).Trim();
         }
         int index = param.Length - 1;
         while ((index >= 0) &&
                (Char.IsLetterOrDigit(param[index]) || param[index] == '_'))
         {
             index--;
         }
         string paramName = param.Substring(index + 1);
         string paramType = param.Substring(0, index + 1).Trim();
         bool isPointer = false;
         if (paramType.EndsWith("*"))
         {
             isPointer = true;
             paramType = paramType.Substring(0, paramType.Length - 1).Trim();
         }
         if ((paramName.Length > 0) && (paramType.Length > 0))
         {
             variables.Add(new ScriptVariable(paramName, paramType, false, isPointer, null, null, false, false, false, false, func.StartsAtCharacterIndex));
         }
     }
 }
        /// <summary>
        /// Run selected script with 2/3 parameters for all rows of SQL.
        /// If you choose isWithAsk=true
        /// </summary>
        /// <param name="model"></param>
        /// <param name="sql"></param>
        /// <param name="function"></param>
        /// <param name="isWithAsk">Ask if execute, skip script execution or break altogether</param>
        /// <returns></returns>
        public static bool RunScriptWithAsk(Model model, string sql, ScriptFunction function, bool isWithAsk = false)
        {
            string scriptName     = function.Owner.Name;
            string functionName   = function.Name;
            int    scriptParCount = function.NumberOfParameters;

            // Check parameter count of function
            if (scriptParCount < 2 || scriptParCount > 3)
            {
                MessageBox.Show($"Function: '{scriptName}:{functionName} count of parameters={scriptParCount}", @"Count of parameters for function shall be 2 or 3 (object_type, Id, Model), Break!!!!");
                return(false);
            }

            // get SQL
            string xml = model.SqlQueryWithException(sql);

            if (xml == null)
            {
                return(false);
            }

            // Output the query in EA Search Window
            string target = model.MakeEaXmlOutput(xml);

            model.Repository.RunModelSearch("", "", "", target);

            // get rows / items to call function
            List <EaItem> eaItemList   = model.MakeEaItemListFromQuery(XDocument.Parse(xml));
            int           countCurrent = 0;
            int           count        = eaItemList.Count;

            foreach (EaItem item in eaItemList)
            {
                switch (scriptParCount)
                {
                case 2:
                case 3:
                    // run script
                    bool run = true;
                    if (isWithAsk)
                    {
                        // run the function with two or three parameters
                        DialogResult result = MessageBox.Show($"Function '{functionName}', Item {countCurrent} of {count}", @"YES=Execute,No=Skip execution, Cancel=Break,", MessageBoxButtons.YesNoCancel);
                        if (result.Equals(DialogResult.No))
                        {
                            run = false;
                        }
                        if (result.Equals(DialogResult.Cancel))
                        {
                            return(false);
                        }
                    }
                    if (run)      // run script
                    {
                        countCurrent += 1;
                        if (countCurrent % 20 == 0)
                        {
                            model.Repository.WriteOutput("Script", $"{functionName}: {countCurrent} of {count}", 0);
                        }
                        if (ScriptUtility.RunScriptFunction(model, function, item.EaObjectType, item.EaObject) == false)
                        {
                            return(false);
                        }
                    }
                    continue;

                default:
                    MessageBox.Show($"Script parameter count shall be 2 or 3, is {scriptParCount}", @"Invalid count of function parameters, Break!!!!");
                    break;
                }
            }
            return(true);
        }
Exemplo n.º 37
0
        private void AdjustStartOfFunctionIfAppropriate(ScriptFunction func, int currentPos, int adjustment)
        {
            if (func.StartsAtCharacterIndex > currentPos)
            {
                func.StartsAtCharacterIndex += adjustment;
            }

            if (func.EndsAtCharacterIndex > currentPos)
            {
                func.EndsAtCharacterIndex += adjustment;
            }

            if (func.StartsAtCharacterIndex < 0)
            {
                // Function has probably just been deleted
                func.StartsAtCharacterIndex = -1;
                func.EndsAtCharacterIndex = -1;
            }
        }
        public static void RegisterEvents(object target)
        {
#pragma warning disable 612, 618
            ModuleScriptMethodIndexer.Index(target,
                                            new[]
            {
                typeof(AsyncEventAttribute), typeof(AsyncServerEventAttribute), typeof(AsyncClientEventAttribute),
                typeof(AsyncScriptEventAttribute)
            },
#pragma warning restore 612, 618
                                            (baseEvent, eventMethod, eventMethodDelegate) =>
            {
                switch (baseEvent)
                {
                case AsyncScriptEventAttribute scriptEvent:
                    var scriptEventType = scriptEvent.EventType;
                    ScriptFunction scriptFunction;
                    switch (scriptEventType)
                    {
                    case ScriptEventType.Checkpoint:
                        scriptFunction = ScriptFunction.Create(eventMethodDelegate,
                                                               new[] { typeof(ICheckpoint), typeof(IEntity), typeof(bool) });
                        if (scriptFunction == null)
                        {
                            return;
                        }
                        OnCheckpoint += (checkpoint, entity, state) =>
                        {
                            var currScriptFunction = scriptFunction.Clone();
                            currScriptFunction.Set(checkpoint);
                            currScriptFunction.Set(entity);
                            currScriptFunction.Set(state);
                            return(currScriptFunction.CallAsync());
                        };
                        break;

                    case ScriptEventType.PlayerConnect:
                        scriptFunction = ScriptFunction.Create(eventMethodDelegate,
                                                               new[] { typeof(IPlayer), typeof(string) });
                        if (scriptFunction == null)
                        {
                            return;
                        }
                        OnPlayerConnect += (player, reason) =>
                        {
                            var currScriptFunction = scriptFunction.Clone();
                            currScriptFunction.Set(player);
                            currScriptFunction.Set(reason);
                            return(currScriptFunction.CallAsync());
                        };
                        break;

                    case ScriptEventType.PlayerDamage:
                        scriptFunction = ScriptFunction.Create(eventMethodDelegate,
                                                               new[] { typeof(IPlayer), typeof(IEntity), typeof(uint), typeof(ushort) });
                        if (scriptFunction == null)
                        {
                            return;
                        }
                        OnPlayerDamage += (player, attacker,
                                           oldHealth, oldArmor,
                                           oldMaxHealth, oldMaxArmor,
                                           weapon, damage) =>
                        {
                            var currScriptFunction = scriptFunction.Clone();
                            currScriptFunction.Set(player);
                            currScriptFunction.Set(attacker);
                            currScriptFunction.Set(weapon);
                            currScriptFunction.Set(damage);
                            return(currScriptFunction.CallAsync());
                        };
                        break;

                    case ScriptEventType.PlayerDead:
                        scriptFunction = ScriptFunction.Create(eventMethodDelegate,
                                                               new[] { typeof(IPlayer), typeof(IEntity), typeof(uint) });
                        if (scriptFunction == null)
                        {
                            return;
                        }
                        OnPlayerDead += (player, attacker, weapon) =>
                        {
                            var currScriptFunction = scriptFunction.Clone();
                            currScriptFunction.Set(player);
                            currScriptFunction.Set(attacker);
                            currScriptFunction.Set(weapon);
                            return(currScriptFunction.CallAsync());
                        };
                        break;

                    case ScriptEventType.PlayerDisconnect:
                        scriptFunction = ScriptFunction.Create(eventMethodDelegate,
                                                               new[] { typeof(IPlayer), typeof(string) });
                        if (scriptFunction == null)
                        {
                            return;
                        }
                        OnPlayerDisconnect += (player, reason) =>
                        {
                            var currScriptFunction = scriptFunction.Clone();
                            currScriptFunction.Set(player);
                            currScriptFunction.Set(reason);
                            return(currScriptFunction.CallAsync());
                        };
                        break;

                    case ScriptEventType.PlayerRemove:
                        scriptFunction =
                            ScriptFunction.Create(eventMethodDelegate, new[] { typeof(IPlayer) });
                        if (scriptFunction == null)
                        {
                            return;
                        }
                        OnPlayerRemove += player =>
                        {
                            var currScriptFunction = scriptFunction.Clone();
                            currScriptFunction.Set(player);
                            return(currScriptFunction.CallAsync());
                        };
                        break;

                    case ScriptEventType.VehicleRemove:
                        scriptFunction =
                            ScriptFunction.Create(eventMethodDelegate, new[] { typeof(IVehicle) });
                        if (scriptFunction == null)
                        {
                            return;
                        }
                        OnVehicleRemove += vehicle =>
                        {
                            var currScriptFunction = scriptFunction.Clone();
                            currScriptFunction.Set(vehicle);
                            return(currScriptFunction.CallAsync());
                        };
                        break;

                    case ScriptEventType.PlayerChangeVehicleSeat:
                        scriptFunction =
                            ScriptFunction.Create(eventMethodDelegate,
                                                  new[] { typeof(IVehicle), typeof(IPlayer), typeof(byte), typeof(byte) });
                        if (scriptFunction == null)
                        {
                            return;
                        }
                        OnPlayerChangeVehicleSeat += (vehicle, player, seat, newSeat) =>
                        {
                            var currScriptFunction = scriptFunction.Clone();
                            currScriptFunction.Set(vehicle);
                            currScriptFunction.Set(player);
                            currScriptFunction.Set(seat);
                            currScriptFunction.Set(newSeat);
                            return(currScriptFunction.CallAsync());
                        };
                        break;

                    case ScriptEventType.PlayerEnterVehicle:
                        scriptFunction =
                            ScriptFunction.Create(eventMethodDelegate,
                                                  new[] { typeof(IVehicle), typeof(IPlayer), typeof(byte) });
                        if (scriptFunction == null)
                        {
                            return;
                        }
                        OnPlayerEnterVehicle += (vehicle, player, seat) =>
                        {
                            var currScriptFunction = scriptFunction.Clone();
                            currScriptFunction.Set(vehicle);
                            currScriptFunction.Set(player);
                            currScriptFunction.Set(seat);
                            return(currScriptFunction.CallAsync());
                        };
                        break;

                    case ScriptEventType.PlayerLeaveVehicle:
                        scriptFunction =
                            ScriptFunction.Create(eventMethodDelegate,
                                                  new[] { typeof(IVehicle), typeof(IPlayer), typeof(byte) });
                        if (scriptFunction == null)
                        {
                            return;
                        }
                        OnPlayerLeaveVehicle += (vehicle, player, seat) =>
                        {
                            var currScriptFunction = scriptFunction.Clone();
                            currScriptFunction.Set(vehicle);
                            currScriptFunction.Set(player);
                            currScriptFunction.Set(seat);
                            return(currScriptFunction.CallAsync());
                        };
                        break;

                    case ScriptEventType.PlayerEvent:
                        scriptFunction =
                            ScriptFunction.Create(eventMethodDelegate,
                                                  new[] { typeof(IPlayer), typeof(string), typeof(object[]) });
                        if (scriptFunction == null)
                        {
                            return;
                        }
                        OnPlayerEvent += (player, name, args) =>
                        {
                            var currScriptFunction = scriptFunction.Clone();
                            currScriptFunction.Set(player);
                            currScriptFunction.Set(name);
                            currScriptFunction.Set(args);
                            return(currScriptFunction.CallAsync());
                        };
                        break;

                    case ScriptEventType.PlayerCustomEvent:
                        Alt.Log("PlayerCustomEvent does not exists in async");
                        break;

                    case ScriptEventType.ServerEvent:
                        Alt.Log("PlayerCustomEvent does not exists in async");
                        break;

                    case ScriptEventType.ServerCustomEvent:
                        Alt.Log("PlayerCustomEvent does not exists in async");
                        break;

                    case ScriptEventType.ConsoleCommand:
                        scriptFunction = ScriptFunction.Create(eventMethodDelegate,
                                                               new[] { typeof(string), typeof(string[]) });
                        if (scriptFunction == null)
                        {
                            return;
                        }
                        OnConsoleCommand += (name, args) =>
                        {
                            var currScriptFunction = scriptFunction.Clone();
                            currScriptFunction.Set(name);
                            currScriptFunction.Set(args);
                            return(currScriptFunction.CallAsync());
                        };
                        break;

                    case ScriptEventType.MetaDataChange:
                        scriptFunction = ScriptFunction.Create(eventMethodDelegate,
                                                               new[] { typeof(IEntity), typeof(string), typeof(object) });
                        if (scriptFunction == null)
                        {
                            return;
                        }
                        OnMetaDataChange += (entity, key, value) =>
                        {
                            var currScriptFunction = scriptFunction.Clone();
                            currScriptFunction.Set(entity);
                            currScriptFunction.Set(key);
                            currScriptFunction.Set(value);
                            return(currScriptFunction.CallAsync());
                        };
                        break;

                    case ScriptEventType.SyncedMetaDataChange:
                        scriptFunction = ScriptFunction.Create(eventMethodDelegate,
                                                               new[] { typeof(IEntity), typeof(string), typeof(object) });
                        if (scriptFunction == null)
                        {
                            return;
                        }
                        OnSyncedMetaDataChange += (entity, key, value) =>
                        {
                            var currScriptFunction = scriptFunction.Clone();
                            currScriptFunction.Set(entity);
                            currScriptFunction.Set(key);
                            currScriptFunction.Set(value);
                            return(currScriptFunction.CallAsync());
                        };
                        break;

                    case ScriptEventType.ColShape:
                        scriptFunction = ScriptFunction.Create(eventMethodDelegate,
                                                               new[] { typeof(IColShape), typeof(IEntity), typeof(bool) });
                        if (scriptFunction == null)
                        {
                            return;
                        }
                        OnColShape += (shape, entity, state) =>
                        {
                            var currScriptFunction = scriptFunction.Clone();
                            currScriptFunction.Set(shape);
                            currScriptFunction.Set(entity);
                            currScriptFunction.Set(state);
                            return(currScriptFunction.CallAsync());
                        };
                        break;

                    case ScriptEventType.WeaponDamage:
                        scriptFunction = ScriptFunction.Create(eventMethodDelegate,
                                                               new[]
                        {
                            typeof(IPlayer), typeof(IEntity), typeof(uint), typeof(ushort),
                            typeof(Position), typeof(BodyPart)
                        });
                        if (scriptFunction == null)
                        {
                            return;
                        }
                        OnWeaponDamage +=
                            (player, targetEntity, weapon, damage, shotOffset, damageOffset) =>
                        {
                            var currScriptFunction = scriptFunction.Clone();
                            currScriptFunction.Set(player);
                            currScriptFunction.Set(targetEntity);
                            currScriptFunction.Set(weapon);
                            currScriptFunction.Set(damage);
                            currScriptFunction.Set(shotOffset);
                            currScriptFunction.Set(damageOffset);
                            return(currScriptFunction.CallAsync());
                        };
                        break;
                    }

                    break;

#pragma warning disable 612, 618
                case AsyncEventAttribute @event:
                    var eventName = @event.Name ?? eventMethod.Name;
                    Module.On(eventName, Function.Create(eventMethodDelegate));
                    break;

#pragma warning restore 612, 618
                case AsyncServerEventAttribute @event:
                    var serverEventName = @event.Name ?? eventMethod.Name;
                    Module.OnServer(serverEventName, Function.Create(eventMethodDelegate));
                    break;

                case AsyncClientEventAttribute @event:
                    var clientEventName = @event.Name ?? eventMethod.Name;
                    Module.OnClient(clientEventName, Function.Create(eventMethodDelegate));
                    break;
                }
            });
        }