private object CreateItemForWs(CoreImpl.IWritingSystem xws)
		{
			return new Item() {Label = xws.DisplayLabel, Ws = xws.Handle};
		}
Пример #2
0
 public static Function OnClient <T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16>(
     string eventName,
     Action <T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16> action) =>
 CoreImpl.OnClient(eventName, Function.Create(Core, action));
Пример #3
0
 public static Function OnClient <T1, T2>(string eventName, Func <T1, T2> action) =>
 CoreImpl.OnClient(eventName, Function.Create(Core, action));
Пример #4
0
 public static Function OnClient <T1, T2, T3, T4, T5, T6, T7>(string eventName,
                                                              Action <T1, T2, T3, T4, T5, T6, T7> action) => CoreImpl.OnClient(eventName, Function.Create(Core, action));
Пример #5
0
 public static Function OnServer <T1, T2, T3>(string eventName, Action <T1, T2, T3> action) =>
 CoreImpl.OnServer(eventName, Function.Create(Core, action));
Пример #6
0
 public static Function OnServer <T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, TResult>(
     string eventName,
     Func <T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, TResult> action) =>
 CoreImpl.OnServer(eventName, Function.Create(Core, action));
Пример #7
0
 public static Function OnClient(string eventName, Action action) =>
 CoreImpl.OnClient(eventName, Function.Create(Core, action));
Пример #8
0
 public static void OffServer(string eventName, Function function) =>
 CoreImpl.OffServer(eventName, function);
Пример #9
0
 public static void OffClient(string eventName, Function function) =>
 CoreImpl.OffClient(eventName, function);
 public static void ExportNative(string key, Action value)
 {
     CoreImpl.SetExport(key, Function.Create(Core, value));
 }
 public static void ExportNative <T1, T2, T3, T4, T5, T6>(string key, Action <T1, T2, T3, T4, T5, T6> value)
 {
     CoreImpl.SetExport(key, Function.Create(Core, value));
 }
 public static void ExportNative <T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, TResult>(
     string key,
     Func <T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, TResult> value)
 {
     CoreImpl.SetExport(key, Function.Create(Core, value));
 }
        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;
                }
            });
        }
Пример #14
0
 public static void Export <T1, T2, T3, T4>(string key, Action <T1, T2, T3, T4> value)
 {
     CoreImpl.SetExport(key, Function.Create(Core, value));
     HostWrapper.Export(key, value);
 }
Пример #15
0
 public static void Export(string key, Delegate value)
 {
     CoreImpl.SetExport(key, Function.Create(Core, value));
     HostWrapper.Export(key, value);
 }
Пример #16
0
 public static void Export <T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16>(string key,
                                                                                                   Func <T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16> value)
 {
     CoreImpl.SetExport(key, Function.Create(Core, value));
     HostWrapper.Export(key, value);
 }