예제 #1
0
        private async Task Class1_Tick()
        {
            try
            {
                /* Text text = new Text($"ELS Build dev-v0.0.2.4\nhttp://ELS.ejb1123.tk", new PointF(640f, 10f), 0.5f);
                 * text.Alignment = Alignment.Center;
                 * text.Centered = true;
                 * text.Draw();*/

                if (LocalPlayer.Character.IsInVehicle() && LocalPlayer.Character.IsSittingInVehicle() &&
                    VCF.isELSVechicle(LocalPlayer.Character.CurrentVehicle.DisplayName) &&
                    LocalPlayer.Character.CurrentVehicle.GetPedOnSeat(VehicleSeat.Driver) == LocalPlayer.Character)
                {
                    _sirenManager.Runtick();
                    //_spotLight.RunTick();
                }
            }
            catch (Exception ex)
            {
                TriggerServerEvent($"ONDEBUG", ex.ToString());
                await Delay(5000);

                Screen.ShowNotification($"ERROR {ex}", true);
            }
        }
예제 #2
0
        private static void LoadFilesPromScript(string name)
        {
            int num = Function.Call <int>(Hash.GET_NUM_RESOURCE_METADATA, name, "file");

            CitizenFX.Core.Debug.WriteLine($"{num} files for {name}");
            for (int i = 0; i < num; i++)
            {
                var filename = Function.Call <string>(Hash.GET_RESOURCE_METADATA, name, "file", i);

                var data = Function.Call <string>(Hash.LOAD_RESOURCE_FILE, name, filename);


                if (filename.Equals("extra-files/ELS.ini"))
                {
                    if (configuration.ControlConfiguration.isValidData(data))
                    {
                        OnSettingsLoaded?.Invoke(SettingsType.Type.GLOBAL, data);
                    }
                }
                else if (Path.GetExtension(filename).ToLower() == ".xml")
                {
                    if (VCF.isValidData(data))
                    {
#if DEBUG
                        CitizenFX.Core.Debug.WriteLine("Sending data to XML parser");
#endif
                        VCF.load(SettingsType.Type.VCF, filename, data, name);
                    }
                }
            }
        }
예제 #3
0
        public static List <VCF> GetVCFs(DataTable AllLines)
        {
            List <VCF> cards = new List <VCF>();

            try
            {
                for (int i = 0; i < AllLines.Rows.Count; i++)
                {
                    var row  = AllLines.Rows[i];
                    VCF card = new VCF();
                    card.Prefix     = row[0].ToString();
                    card.FirstName  = row[1].ToString();
                    card.MiddleName = row[2].ToString();
                    card.LastName   = row[3].ToString();
                    card.TEL        = row[4].ToString();
                    card.TELCELL    = row[5].ToString();
                    card.TELWORK    = row[6].ToString();
                    card.TITLE      = row[7].ToString();
                    card.ORG        = row[8].ToString();
                    card.ADR        = row[9].ToString();
                    card.URL        = row[10].ToString();
                    card.EMAIL      = row[11].ToString();
                    card.NOTE1      = row[12].ToString();
                    card.EMAILHOME  = row[13].ToString();
                    card.EMAILWORK  = row[14].ToString();
                    card.TELHOME    = row[15].ToString();
                    card.TELPREF    = row[16].ToString();
                    card.TELVOICE   = row[17].ToString();
                    card.Suffix     = row[18].ToString();
                    card.ADRHOME    = row[19].ToString();
                    card.ADRWORK    = row[20].ToString();
                    card.NOTE2      = row[21].ToString();
                    card.NOTE3      = row[22].ToString();
                    card.OTHER1     = row[23].ToString();
                    card.OTHER2     = row[24].ToString();
                    card.OTHER3     = row[25].ToString();
                    card.OTHER4     = row[26].ToString();
                    card.OTHER5     = row[27].ToString();
                    card.OTHER6     = row[28].ToString();
                    card.OTHER7     = row[29].ToString();
                    card.OTHER8     = row[30].ToString();
                    card.OTHER9     = row[31].ToString();
                    cards.Add(card);
                }
                return(cards);
            }
            catch (Exception aa)
            {
                Console.WriteLine(aa.Message);
                return(null);
            }
        }
예제 #4
0
        public void RunLoadeer(string name)
        {
            if (ELS.isStopped)
            {
                return;
            }
            int num = Function.Call <int>(Hash.GET_NUM_RESOURCE_METADATA, name, "ELSFM");

#if DEBUG
            Debug.WriteLine("number of INI files to load: " + num.ToString() + " " + name);
#endif
            for (int i = 0; i < num; i++)
            {
                var filename = Function.Call <string>(Hash.GET_RESOURCE_METADATA, name, "ELSFM", i);
#if DEBUG
                Debug.WriteLine($"Name: {name}, Loading: {filename}");
#endif

                if (filename.Equals("extra-files/ELS.ini"))
                {
                    var data = Function.Call <string>(Hash.LOAD_RESOURCE_FILE, name, filename);
                    OnSettingsLoaded?.Invoke(configuration.SettingsType.Type.GLOBAL, data);
                }
                // var ldata = Function.Call<string>(Hash.LOAD_RESOURCE_FILE, name, filename);
                //Debug.WriteLine(ldata);
            }

            num = Function.Call <int>(Hash.GET_NUM_RESOURCE_METADATA, name, "ELSFMVCF");
#if DEBUG
            Debug.WriteLine("number of VCF files to load: " + num.ToString() + " " + name);
#endif
            for (int i = 0; i < num; i++)
            {
                var filename = Function.Call <string>(Hash.GET_RESOURCE_METADATA, name, "ELSFMVCF", i);
#if DEBUG
                Debug.WriteLine($"Name: {name}, Loading: {filename}");
#endif


                var data = Function.Call <string>(Hash.LOAD_RESOURCE_FILE, name, filename);
                Debug.WriteLine("Sending data to XML parser");
                VCF.load(SettingsType.Type.VCF, filename, data);
            }
        }
예제 #5
0
        public static List <VCF> GetVCFs(List <string> AllLines)
        {
            List <VCF> cards = new List <VCF>();

            try
            {
                int startCard = -1;
                int endCard   = -1;
                for (int i = 0; i < AllLines.Count; i++)
                {
                    if (endCard != -1)
                    {
                        var tmp = new List <string>();
                        for (int x = startCard; x <= endCard; x++)
                        {
                            tmp.Add(AllLines[x]);
                        }
                        var card = new VCF(tmp);
                        cards.Add(card);
                        startCard = endCard = -1;
                    }
                    if (AllLines[i] == "BEGIN:VCARD")
                    {
                        startCard = i;
                    }
                    if (AllLines[i] == "END:VCARD")
                    {
                        endCard = i;
                    }
                }
                //cards = cards.OrderByDescending(x => x.FirstName).ToList();
                return(cards);
            }
            catch (Exception aa)
            {
                Console.WriteLine(aa.Message);
                return(null);
            }
        }
예제 #6
0
        private Scalar ReadText()
        {
            ConsumeWhitespace();

            if (Parser.TryRead(out _, VCF.QUOTE))
            {
                var str = Parser.ReadWhile(VCF.IsQSafeChar, new Rune('\\'), out var matched);

                if (matched.Value.Value != VCF.QUOTE)
                {
                    throw UnexpectedCharacter(matched);
                }

                Parser.Read();
                ConsumeWhitespace();

                return(new Scalar(str.WithString(VCF.Unescape(str.StringValue))));
            }
            else
            {
                var str = Parser.ReadWhile(VCF.IsValidTextChar, new Rune('\\'), out var matched);
                return(new Scalar(str.WithString(VCF.Unescape(str.StringValue.Trim()))));
            }
        }
예제 #7
0
        private string ConvertRune(Rune r)
        {
            if (VCF.IsSafeChar(r) || (!r.IsAscii && !UseNonUTF8Escaping))
            {
                return(r.ToString());
            }

            if (r.Value == '\n')
            {
                return(UseOldEscaping ? "=\n" : "\n ");
            }

            if (UseOldEscaping || !r.IsAscii)
            {
                var b     = new byte[r.Utf8SequenceLength];
                var count = r.EncodeToUtf8(b);

                return(String.Join(String.Empty, b.Take(count).Select(b => $"={b:X2}")));
            }
            else
            {
                return($"\\{r}");
            }
        }
예제 #8
0
        private void SetupConnections()
        {
            EventHandlers["onClientResourceStop"] += new Action <string>(async(string obj) =>
            {
                if (obj == Function.Call <string>(Hash.GET_CURRENT_RESOURCE_NAME))
                {
                    _vehicleManager.CleanUP();
                    _FileLoader.UnLoadFilesFromScript(obj);
                }
            });
            //command that siren state has changed.
            //recieves a command
            //EventHandlers["ELS:SirenUpdated"] += new Action<string, int, int, bool>(_vehicleManager.UpdateRemoteSirens);
            EventHandlers["ELS:SpawnCar"] += new Action <string>((veh) =>
            {
                SpawnCar(veh);
            });
            EventHandlers["ELS:VcfSync:Client"] += new Action <List <dynamic> >((vcfs) =>
            {
                VCF.ParseVcfs(vcfs);
            });
            EventHandlers.Add("ELS:PatternSync:Client", new Action <List <dynamic> >((patterns) =>
            {
                VCF.ParsePatterns(patterns);
            }));
            EventHandlers["ELS:FullSync:NewSpawnWithData"] += new Action <System.Dynamic.ExpandoObject>((a) =>
            {
                _vehicleManager.SyncAllVehiclesOnFirstSpawn(a);
            });
            EventHandlers["ELS:FullSync:NewSpawn"] += new Action(() =>
            {
                Tick -= Class1_Tick;
                Tick += Class1_Tick;
            });

            EventHandlers.Add("playerSpawned", new Action(() => { TriggerServerEvent("ELS:FullSync:Request:All", Game.Player.ServerId); }));
            EventHandlers["ELS:VehicleEntered"] += new Action <int>((veh) =>
            {
                Utils.DebugWriteLine("Vehicle entered checking list");
                Vehicle vehicle = new Vehicle(veh);
                Delay(1000);
                try
                {
                    if (vehicle.Exists() && vehicle.IsEls())
                    {
                        if ((vehicle.GetNetworkId() == LocalPlayer.Character.CurrentVehicle.GetNetworkId()))
                        {
                            Utils.DebugWriteLine("Vehicle is in list moving on");
                            Utils.DebugWriteLine("ELS Vehicle entered syncing UI");
                            lastVehicle = vehicle.GetNetworkId();
                            if (userSettings.uiSettings.enabled)
                            {
                                ElsUiPanel.ShowUI();
                            }
                            VehicleManager.SyncUI(vehicle.GetNetworkId());

                            UserSettings.ELSUserVehicle usrVeh = userSettings.savedVehicles.Find(uveh => uveh.Model == vehicle.Model.Hash && uveh.ServerId == ServerId);
                            Utils.DebugWriteLine($"got usrveh of {usrVeh.Model} on server {usrVeh.ServerId}m");
                            if (ServerId.Equals(usrVeh.ServerId))
                            {
                                Utils.DebugWrite("Got Saved Vehicle Settings applying");
                                VehicleManager.vehicleList[vehicle.GetNetworkId()].SetSaveSettings(usrVeh);
                            }
                            VehicleManager.vehicleList[vehicle.GetNetworkId()].SetInofVeh();
                        }
                        Utils.DebugWriteLine($"Vehicle {vehicle.GetNetworkId()}({Game.PlayerPed.CurrentVehicle.GetNetworkId()}) entered");
                    }
                }
                catch (Exception e)
                {
                    Utils.ReleaseWriteLine("Exception caught via vehicle entered");
                }
            });
            EventHandlers["ELS:VehicleExited"] += new Action <int>((veh) =>
            {
                Vehicle vehicle = new Vehicle(veh);
                try
                {
                    if (vehicle.Exists() && vehicle.IsEls())
                    {
                        if (VehicleManager.vehicleList.ContainsKey(vehicle.GetNetworkId()) && (vehicle.GetNetworkId() == lastVehicle))
                        {
                            if (Global.DisableSirenOnExit)
                            {
                                VehicleManager.vehicleList[vehicle.GetNetworkId()].DisableSiren();
                            }
                            Utils.DebugWriteLine("save settings for vehicle it");
                            VehicleManager.vehicleList[vehicle.GetNetworkId()].GetSaveSettings();
                            VehicleManager.vehicleList[vehicle.GetNetworkId()].SetOutofVeh();
                        }
                        Utils.DebugWriteLine($"Vehicle {vehicle.GetNetworkId()}({Game.PlayerPed.LastVehicle.GetNetworkId()}) exited");
                    }
                }
                catch (Exception e)
                {
                    Utils.ReleaseWriteLine("Exception caught via vehicle exited");
                }
            });
            //Take in data and apply it
            EventHandlers["ELS:NewFullSyncData"] += new Action <IDictionary <string, object>, int>(_vehicleManager.SetVehicleSyncData);


            API.RegisterCommand("vcfsync", new Action <int, List <object>, string>((source, arguments, raw) =>
            {
                TriggerServerEvent("ELS:VcfSync:Server", Game.Player.ServerId);
            }), false);

            API.RegisterCommand("elsui", new Action <int, List <object>, string>((source, arguments, raw) =>
            {
                Task task = new Task(() => userSettings.SaveUI(true));
                if (arguments.Count != 1)
                {
                    return;
                }
                switch (arguments[0].ToString().ToLower())
                {
                case "enable":
                    ElsUiPanel.EnableUI();
                    break;

                case "disable":
                    ElsUiPanel.DisableUI();
                    userSettings.uiSettings.enabled = false;
                    break;

                case "show":
                    ElsUiPanel.ShowUI();
                    userSettings.uiSettings.enabled = true;
                    break;

                case "whelen":
                    userSettings.uiSettings.currentUI = UserSettings.ElsUi.Whelen;
                    break;

                case "new":
                    userSettings.uiSettings.currentUI = UserSettings.ElsUi.NewHotness;
                    break;

                case "old":
                    userSettings.uiSettings.currentUI = UserSettings.ElsUi.OldandBusted;
                    break;
                }
                task.Start();
            }), false);

            API.RegisterCommand("elslist", new Action <int, List <object>, string>((source, args, raw) =>
            {
                var listString = "";
                listString    += $"Available ELS Vehicles\n" +
                                 $"----------------------\n";
                foreach (var entry in VCF.ELSVehicle.Values)
                {
                    if (entry.modelHash.IsValid)
                    {
                        listString += $"{System.IO.Path.GetFileNameWithoutExtension(entry.filename)}\n";
                    }
                }
                CitizenFX.Core.Debug.WriteLine(listString);
            }), false);
        }
예제 #9
0
      /// <summary>
      /// Gets the value for the specified key. If the value does not exists, it is optionally created.
      /// </summary>
      public PdfItem GetValue(string key, VCF options)
      {
        PdfObject obj;
        PdfDictionary dict;
        PdfArray array;
        PdfReference iref;
        PdfItem value = this[key];
        if (value == null)
        {
          if (options != VCF.None)
          {
            Type type = GetValueType(key);
            if (type != null)
            {
              Debug.Assert(typeof(PdfItem).IsAssignableFrom(type), "Type not allowed.");
              if (typeof(PdfDictionary).IsAssignableFrom(type))
              {
                value = obj = CreateDictionary(type, null);
              }
              else if (typeof(PdfArray).IsAssignableFrom(type))
              {
                value = obj = CreateArray(type, null);
              }
              else
                throw new NotImplementedException("Type other than array or dictionary.");

              if (options == VCF.CreateIndirect)
              {
                this.owner.Owner.irefTable.Add(obj);
                this[key] = obj.Reference;
              }
              else
                this[key] = obj;
            }
            else
              throw new NotImplementedException("Cannot create value for key: " + key);
          }
        }
        else
        {
          // The value exists and can returned. But for imported documents check for neccessary
          // object type transformation.
          if ((iref = value as PdfReference) != null)
          {
            // Case: value is an indirect reference
            value = iref.Value;
            if (value == null)
            {
              // If we come here PDF file is currupt
              throw new InvalidOperationException("Indirect reference without value.");
            }
            else
            {
              if (true) // || this.owner.Document.IsImported)
              {
                Type type = GetValueType(key);
                Debug.Assert(type != null, "No value type specified in meta information. Please send this file to PDFsharp support.");

                if (type != null && type != value.GetType())
                {
                  if (typeof(PdfDictionary).IsAssignableFrom(type))
                  {
                    Debug.Assert(value is PdfDictionary, "Bug in PDFsharp. Please send this file to PDFsharp support.");
                    value = CreateDictionary(type, (PdfDictionary)value);
                  }
                  else if (typeof(PdfArray).IsAssignableFrom(type))
                  {
                    Debug.Assert(value is PdfArray, "Bug in PDFsharp. Please send this file to PDFsharp support.");
                    value = CreateArray(type, (PdfArray)value);
                  }
                  else
                    throw new NotImplementedException("Type other than array or dictionary.");
                }
              }
            }
            return value;
          }
          // Transformation is only possible after PDF import.
          if (true) // || this.owner.Document.IsImported)
          {
            // Case: value is a direct object
            if ((dict = value as PdfDictionary) != null)
            {
              Type type = GetValueType(key);
              Debug.Assert(type != null, "No value type specified in meta information. Please send this file to PDFsharp support.");
              if (dict.GetType() != type)
                dict = CreateDictionary(type, dict);
              return dict;
            }
            else if ((array = value as PdfArray) != null)
            {
              Type type = GetValueType(key);
              Debug.Assert(type != null, "No value type specified in meta information. Please send this file to PDFsharp support.");
              if (array.GetType() != type)
                array = CreateArray(type, array);
              return array;
            }
          }
        }
        return value;
      }
예제 #10
0
 internal void UnLoadFilesFromScript(string name)
 {
     VCF.unload(name);
 }
예제 #11
0
파일: ELS.cs 프로젝트: dexslab/ELS-FiveM
        private void SetupConnections()
        {
            EventHandlers["onClientResourceStop"] += new Action <string>(async(string obj) =>
            {
                if (obj == Function.Call <string>(Hash.GET_CURRENT_RESOURCE_NAME))
                {
                    _vehicleManager.CleanUP();
                    _FileLoader.UnLoadFilesFromScript(obj);
                }
            });
            //command that siren state has changed.
            //recieves a command
            //EventHandlers["ELS:SirenUpdated"] += new Action<string, int, int, bool>(_vehicleManager.UpdateRemoteSirens);
            EventHandlers["ELS:SpawnCar"] += new Action <string>((veh) =>
            {
                SpawnCar(veh);
            });
            EventHandlers["ELS:VcfSync:Client"] += new Action <List <dynamic> >((vcfs) =>
            {
                VCF.ParseVcfs(vcfs);
            });
            EventHandlers.Add("ELS:PatternSync:Client", new Action <List <dynamic> >((patterns) =>
            {
                VCF.ParsePatterns(patterns);
            }));
            EventHandlers["ELS:FullSync:NewSpawnWithData"] += new Action <System.Dynamic.ExpandoObject>((a) =>
            {
                _vehicleManager.SyncAllVehiclesOnFirstSpawn(a);
                Tick -= Class1_Tick;
                Tick += Class1_Tick;
            });
            EventHandlers["ELS:FullSync:NewSpawn"] += new Action(() =>
            {
                Tick -= Class1_Tick;
                Tick += Class1_Tick;
            });

            EventHandlers["ELS:VehicleEntered"] += new Action <int>((veh) =>
            {
                Utils.DebugWriteLine("Vehicle entered");
                Vehicle vehicle = new Vehicle(veh);
                if (vehicle.IsEls() && VehicleManager.vehicleList.ContainsKey(vehicle.GetNetworkId()))
                {
                    Utils.DebugWriteLine("ELS Vehicle entered syncing UI");
                    VehicleManager.SyncUI(vehicle.GetNetworkId());
                }
            });
            //Take in data and apply it
            EventHandlers["ELS:NewFullSyncData"] += new Action <IDictionary <string, object>, int>(_vehicleManager.SetVehicleSyncData);


            API.RegisterCommand("vcfsync", new Action <int, List <object>, string>((source, arguments, raw) =>
            {
                TriggerServerEvent("ELS:VcfSync:Server", Game.Player.ServerId);
            }), false);

            API.RegisterCommand("elsui", new Action <int, List <object>, string>((source, arguments, raw) =>
            {
                if (arguments.Count != 1)
                {
                    return;
                }
                if (arguments[0].Equals("enable"))
                {
                    ElsUiPanel.EnableUI();
                }
                else if (arguments[0].Equals("disable"))
                {
                    ElsUiPanel.DisableUI();
                }
                else if (arguments[0].Equals("show"))
                {
                    ElsUiPanel.ShowUI();
                }
            }), false);

            API.RegisterCommand("elslist", new Action <int, List <object>, string>((source, args, raw) =>
            {
                var listString = "";
                listString    += $"Available ELS Vehicles\n" +
                                 $"----------------------\n";
                foreach (var entry in VCF.ELSVehicle.Values)
                {
                    if (entry.modelHash.IsValid)
                    {
                        listString += $"{System.IO.Path.GetFileNameWithoutExtension(entry.filename)}\n";
                    }
                }
                CitizenFX.Core.Debug.WriteLine(listString);
            }), false);
        }
예제 #12
0
        public ELS()
        {
            if (API.GetConvar("dev_server", "false") == "true" || API.GetConvar("test_server", "false") == "true")
            {
                Utils.IsDeveloper = true;
                Utils.ReleaseWriteLine("Debug logging enabled!");
            }
            bool Loaded = false;

            _controlConfiguration = new ElsConfiguration();
            _FileLoader           = new FileLoader(this);
            EventHandlers["onClientResourceStart"] += new Action <string>(async(string obj) =>
            {
                if (obj == CurrentResourceName())
                {
                    Utils.Debug = bool.Parse(API.GetConvar("elsplus_debug", "false"));
                    try
                    {
                        await Delay(100);
                        ServerId     = API.GetConvar("ElsServerId", null);
                        userSettings = new UserSettings();
                        await Delay(0);
                        Task settingsTask = new Task(() => userSettings.LoadUserSettings());
                        await Delay(0);
                        Utils.ReleaseWriteLine($"Welcome to ELS Plus on {ServerId} using version {Assembly.GetExecutingAssembly().GetName().Version}");
                        settingsTask.Start();
                        await Delay(250);
                        _FileLoader.RunLoader(obj);
                        await Delay(250);
                        SetupConnections();
                        await Delay(250);
                        VcfSync.CheckResources();
                        VCF.ParseVcfs(VcfSync.VcfData);
                        CustomPatterns.CheckCustomPatterns();
                        VCF.ParsePatterns(CustomPatterns.Patterns);
                        await Delay(250);
                        Tick -= Class1_Tick;
                        Tick += Class1_Tick;
                        await Delay(1000);
                        if (float.TryParse(API.GetResourceKvpString("daybrightness"), out var dayValue))
                        {
                            Function.Call((Hash)3520272001, "car.defaultlight.day.emissive.on", dayValue);
                        }
                        else
                        {
                            Function.Call((Hash)3520272001, "car.defaultlight.day.emissive.on", Global.DayLtBrightness);
                        }
                        if (float.TryParse(API.GetResourceKvpString("nightbrightness"), out var nightValue))
                        {
                            Function.Call((Hash)3520272001, "car.defaultlight.night.emissive.on", nightValue);
                        }
                        else
                        {
                            Function.Call((Hash)3520272001, "car.defaultlight.night.emissive.on", Global.NightLtBrightness);
                        }

                        API.RequestScriptAudioBank("DLC_WMSIRENS\\SIRENPACK_ONE", false);
                    }
                    catch (Exception e)
                    {
                        Screen.ShowNotification($"ERROR:{e.Message}");
                        Screen.ShowNotification($"ERROR:{e.StackTrace}");
                        Tick -= Class1_Tick;
                        Utils.ReleaseWriteLine($"ERROR:{e.StackTrace}");
                        Utils.ReleaseWriteLine($"Error: {e.Message}");
                    }
                }
            });
        }