Example #1
0
        private static string requestPOSTFromURL(string _url, string _json)
        {
            var httpWebRequest = (HttpWebRequest)WebRequest.Create(_url);

            httpWebRequest.ContentType = "application/json";
            httpWebRequest.Method      = "POST";


            using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
            {
                streamWriter.Write(_json);
            }
            try
            {
                var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
                using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
                {
                    var result = streamReader.ReadToEnd();
                    return(result);
                }
            }
            catch (Exception ex)
            {
                NexHudEngine.Log(ex.Message);
            }
            return("Error in requestPOSTFromURL");
        }
Example #2
0
        public bool SendNotification(string text, string bitmapKey = null, int displayForMs = 2000)
        {
            NotificationBitmap_t bmp = new NotificationBitmap_t();

            if (bitmapKey != null)
            {
                if (!_icons.ContainsKey(bitmapKey))
                {
                    throw new Exception("Invalid Bitmap Key");
                }

                bmp.m_nBytesPerPixel = 4;
                bmp.m_nHeight        = _icons[bitmapKey].Bitmap.Height;
                bmp.m_nWidth         = _icons[bitmapKey].Bitmap.Width;
                bmp.m_pImageData     = (IntPtr)(_icons[bitmapKey].glTextureId);
            }

            uint notId = 0;
            EVRNotificationError err = EVRNotificationError.OK;

            err = OpenVR.Notifications.CreateNotification(_overlay.Handle, 0, EVRNotificationType.Transient, text, EVRNotificationStyle.Application, ref bmp, ref notId);

            if (err != EVRNotificationError.OK)
            {
                NexHudEngine.Log("Notification Failure: " + err.ToString());
                return(false);
            }
            return(true);
        }
Example #3
0
        private static string requestGETFromURL(string _url, string _params)
        {
            string html = string.Empty;
            string url  = _url + _params;

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);

            request.AutomaticDecompression = DecompressionMethods.GZip;



            string _json = "";

            try
            {
                using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
                    using (Stream stream = response.GetResponseStream())
                        using (StreamReader reader = new StreamReader(stream))
                        {
                            _json = reader.ReadToEnd();
                        }
            }
            catch (Exception ex)
            {
                NexHudEngine.Log(ex.Message);
            }
            return(_json);
        }
Example #4
0
        private static bool isURLOnline(string _url)
        {
            bool            _alive   = true;
            HttpWebResponse response = null;

            try
            {
                HttpWebRequest req = (HttpWebRequest)WebRequest.Create(_url);
                response = (HttpWebResponse)req.GetResponse();
            }
            catch (Exception ex)
            {
                NexHudEngine.Log(ex.Message);
                _alive = false;
            }

            if (response != null)
            {
                //SteamVR_NexHUD.Log("Returned status code: " + response.StatusDescription);
                _alive = response.StatusCode == HttpStatusCode.OK;
                response.Close();
            }

            return(_alive);
        }
Example #5
0
        public void WriteLog(LogMessage message)
        {
            switch (message.Severity)
            {
            case Severity.Success:
                NexHudEngine.Log(NxLog.Type.Info, message.Content);
                break;

            case Severity.Info:
                //NexHudEngine.Log(NxLog.Type.Info, message.Content);
                break;

            case Severity.Warning:
                NexHudEngine.Log(NxLog.Type.Warning, message.Content);
                break;

            case Severity.Error:
                NexHudEngine.Log(NxLog.Type.Error, message.Content);
                break;

            case Severity.Debug:
                //NexHudEngine.Log(NxLog.Type.Debug, message.Content);
                break;

            case Severity.Special:
                NexHudEngine.Log(NxLog.Type.Info, message.Content);
                break;
            }
        }
Example #6
0
        public static bool loadShortcuts(NexHudEngineMode _mode, bool _useClassic)
        {
            string _path = Environment.CurrentDirectory + autoPath;

            if (_mode == NexHudEngineMode.WindowDebug)
            {
                _path = Environment.CurrentDirectory + debugPath;
            }
            else if (_mode == NexHudEngineMode.WindowOverlay && _useClassic)
            {
                _path = Environment.CurrentDirectory + classicPath;
            }


            if (File.Exists(_path))
            {
                try
                {
                    ShortcutEntry[] _array;
                    string          _json = File.ReadAllText(_path);
                    _array = JsonConvert.DeserializeObject <ShortcutEntry[]>(_json);
                    for (int i = 0; i < _array.Length; i++)
                    {
                        if (!_array[i].compile())
                        {
                            throw new Exception(string.Format("ERROR: shortcut {0} is invalid", _array[i].id));
                        }
                        else
                        {
                            if (m_entrys.ContainsKey(_array[i].id))
                            {
                                m_entrys[_array[i].id] = _array[i];
                            }
                            else
                            {
                                m_entrys.Add(_array[i].id, _array[i]);
                            }
                        }
                    }

                    return(true);
                }
                catch (Exception ex)
                {
                    NexHudEngine.Log("ERROR while reading Shortcuts.json");
                    NexHudEngine.Log(ex.Message);
                    //Console.WriteLine("Type any key to exist...");
                    // Console.ReadKey();
                    return(false);
                }
            }
            else
            {
                NexHudEngine.Log("ERROR: {0} is missing !", _path);
                Console.WriteLine("Type any key to exist...");
                Console.ReadKey();
                return(false);
            }
        }
Example #7
0
        private static void InitEliteApi()
        {
            NexHudEngine.Log(NxLog.Type.Debug, "Elite API Initilization...");
            m_eliteApi = new EliteDangerousAPI();
            m_eliteApi.Logger.AddHandler(new EliteApiLogger());
            m_eliteApi.Start(false);

            NexHudEngine.Log(NxLog.Type.Info, "Welcome CMDR " + m_eliteApi.Commander.Commander);
            NexHudEngine.Log(NxLog.Type.Info, "Current Star system: " + m_eliteApi.Location.StarSystem);
        }
Example #8
0
        public static EDSMSystemDatas EDSMSystemBodies(string _systemName)
        {
            string _edsmParams = string.Format("systemName={0}", _systemName);


            string _json = requestGETFromURL(Url_EDSMSystemBodies, _edsmParams.ToString());

            try { return(JsonConvert.DeserializeObject <EDSMSystemDatas>(_json)); }
            catch (Exception ex)
            {
                NexHudEngine.Log(ex.Message);
            }
            return(null);
        }
Example #9
0
        public async void SearchInSystems(SpanshSearchSystems _search, Action <SpanshSystemsResult> _method, Action <SearchError> _onFailedMethod)
        {
            string      _spanshJson = string.Empty;
            SearchError error       = SearchError.None;

            try
            {
                _spanshJson = JsonConvert.SerializeObject(_search, new JsonSerializerSettings()
                {
                    NullValueHandling = NullValueHandling.Ignore
                });;
                NxLog.log(NxLog.Type.Debug, "SearchInSystems. json={0}", _spanshJson);
            }
            catch (Exception ex)
            {
                NexHudEngine.Log(NxLog.Type.Error, ex.Message);
                _onFailedMethod?.Invoke(error = SearchError.SerializationFailed);
                return;
            }

            Task <string> task = new Task <string>(() => requestPOSTFromURL(URL_SYSTEMS, _spanshJson, out error));

            task.Start();
            string json = await task;

            if (error != SearchError.None)
            {
                _onFailedMethod?.Invoke(error);
            }
            else
            {
                // string json = requestPOSTFromURL(URL_BODIES, _spanshJson);
                try
                {
                    SpanshSystemsResult result = JsonConvert.DeserializeObject <SpanshSystemsResult>(json, new JsonSerializerSettings()
                    {
                        NullValueHandling = NullValueHandling.Ignore
                    });
                    NxLog.log(NxLog.Type.Debug, "Search Successful! Search ID = " + result.search_reference);

                    _method?.Invoke(result);
                }
                catch (Exception ex)
                {
                    NexHudEngine.Log(NxLog.Type.Error, ex.Message);
                    NexHudEngine.Log(NxLog.Type.Error, ex.StackTrace);
                    _onFailedMethod?.Invoke(error = SearchError.DeserializationFailed);
                }
            }
        }
Example #10
0
        public static EDSMSystemDatas[] EDSMSystemsInSphereRadius(string _originSystem, int _minRadius, int _radius, bool _showInformation = true)
        {
            string _edsmParams = string.Format("systemName={0}&minRadius={1}&radius={2}&showCoordinates=1", _originSystem, _minRadius, _radius);

            if (_showInformation)
            {
                _edsmParams += "&showInformation=1";
            }

            string _json = requestGETFromURL(Url_SystemsInSphere, _edsmParams.ToString());

            try { return(JsonConvert.DeserializeObject <EDSMSystemDatas[]>(_json)); }
            catch (Exception ex) { NexHudEngine.Log(ex.Message); }
            return(null);
        }
Example #11
0
        public static EDSMSystemDatas EDSMSystemValue(string _systemName, int?_systemId = null)
        {
            string _edsmParams = "systemName=" + _systemName;

            if (_systemId != null)
            {
                _edsmParams += "&systemId=" + _systemId;
            }

            string _json = requestGETFromURL(Url_EDSMSystemValue, _edsmParams.ToString());

            try { return(JsonConvert.DeserializeObject <EDSMSystemDatas>(_json)); }
            catch (Exception ex) { NexHudEngine.Log("ERROR. System name={0}. message:{1}", _systemName, ex.Message); }
            return(null);
        }
Example #12
0
        public override void Update()
        {
            base.Update();

            bool select = NexHudEngine.isShortcutPressed(Shortcuts.get(ShortcutId.select));
            bool left   = NexHudEngine.isShortcutPressed(Shortcuts.get(ShortcutId.left));
            bool right  = NexHudEngine.isShortcutPressed(Shortcuts.get(ShortcutId.right));

            if (select)
            {
                if (Radio.Selected)
                {
                    if (RadioPlayer.Instance.isPlaying)
                    {
                        RadioPlayer.Instance.Pause();
                    }
                    else
                    {
                        RadioPlayer.Instance.Play();
                    }
                }
                else if (PreviousRadio.Selected)
                {
                    RadioPlayer.Instance.Prev();
                }
                else if (NextRadio.Selected)
                {
                    RadioPlayer.Instance.Next();
                }
            }

            Radio.Label = string.Format("{0} {1}", RadioPlayer.Instance.isPlaying ? "[>]" : "[ ]", RadioPlayer.Instance.getRadioInfos().name);
            // Volume.width = (int)(RadioPlayer.Instance.Volume * totalWidth);

            if (VolumeSelected)
            {
                if (right)
                {
                    RadioPlayer.Instance.VolumeUp();
                }
                else if (left)
                {
                    RadioPlayer.Instance.VolumeDown();
                }
            }
            Volume.Color = VolumeSelected ? EDColors.YELLOW : EDColors.getColor(EDColors.ORANGE, 0.6f);
            Volume.Value = (int)(RadioPlayer.Instance.Volume * 100.0f);
        }
Example #13
0
        private string requestPOSTFromURL(string _url, string _json, out SearchError error)
        {
            if (m_lastRequest != null)
            {
                m_lastRequest.Abort();
            }


            m_lastRequest             = (HttpWebRequest)WebRequest.Create(_url);
            m_lastRequest.ContentType = "application/json";
            m_lastRequest.Method      = "POST";

            using (var streamWriter = new StreamWriter(m_lastRequest.GetRequestStream()))
            {
                streamWriter.Write(_json);
            }
            try
            {
                var httpResponse = (HttpWebResponse)m_lastRequest.GetResponse();
                m_lastRequest = null;
                using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
                {
                    var result = streamReader.ReadToEnd();
                    error = SearchError.None;
                    return(result);
                }
            }
            catch (Exception ex)
            {
                error = SearchError.Unknow;
                if (ex is WebException)
                {
                    if (((WebException)ex).Status == WebExceptionStatus.RequestCanceled)
                    {
                        error = SearchError.Aborded;
                        NexHudEngine.Log(NxLog.Type.Warning, ex.Message);
                    }
                }
                else
                {
                    NexHudEngine.Log(NxLog.Type.Error, ex.Message);
                }
            }
            return(string.Empty);
        }
Example #14
0
            public string GetPropertyString(EVRApplicationProperty prop)
            {
                EVRApplicationError err            = EVRApplicationError.None;
                StringBuilder       propertyBuffer = new StringBuilder(255);

                OpenVR.Applications.GetApplicationPropertyString(AppKey, prop, propertyBuffer, 255, ref err);

#if DEBUG
                if (err != EVRApplicationError.None)
                {
                    NexHudEngine.Log("EVRApplicationError on " + AppKey + " property " + prop.ToString() + ": " + err.ToString());
                }
#endif

                //NexHUDCore.Log(propertyBuffer.ToString());

                return(propertyBuffer.ToString());
            }
Example #15
0
        private void updateCurrentSystemThread()
        {
            string _systemName = NexHudMain.EliteApi.Location.StarSystem;

            if (string.IsNullOrEmpty(_systemName))
            {
                return;
            }
            Stopwatch _watch = new Stopwatch();

            _watch.Start();
            NexHudEngine.Log(">> Retrieving current system {0} from EDSM", _systemName);
            m_systems[_systemName].updateEDSM(ApiConnection.EDSMSystemFullInfos(_systemName));
            NexHudEngine.Log(">> Retrieving value for system {0} from EDSM", _systemName);
            m_systems[_systemName].updateEDSM(ApiConnection.EDSMSystemValue(_systemName));
            NexHudEngine.Log(">> Retrieving current system {0} from EDDB", _systemName);
            m_systems[_systemName].updateEDDB(ApiConnection.EDDBSystemComplementaryInfos(_systemName));
            _watch.Stop();
            NexHudEngine.Log("--->> Update current system {0} took {1}ms", _systemName, _watch.ElapsedMilliseconds);
        }
Example #16
0
        /// <summary>
        /// Get powerplay informations
        /// </summary>
        /// <param name="_systemName"></param>
        /// <returns></returns>
        public static EddbSystemDatas EDDBSystemComplementaryInfos(string _systemName)
        {
            NexHudEngine.Log("Search complementary information EDDB for System: " + _systemName);

            string _json = requestGETFromURL(Url_EDDBSystems, string.Format("name={0}", _systemName));

            try
            {
                EddbSystemPage _systemPage = JsonConvert.DeserializeObject <EddbSystemPage>(_json);
                if (_systemPage != null && _systemPage.docs != null && _systemPage.docs.Length > 0)
                {
                    return(_systemPage.docs[0]);
                }
            }
            catch (Exception ex)
            {
                NexHudEngine.Log(ex.Message);
            }
            return(null);
        }
Example #17
0
        public static EDSMSystemDatas[] EDSMSystemsList(string[] _exactNameList, bool _showInformation = true)
        {
            string _edsmParams = "";

            foreach (string s in _exactNameList)
            {
                _edsmParams += string.Format("systemName[]={0}&", s);
            }
            _edsmParams += "showCoordinates=1";
            if (_showInformation)
            {
                _edsmParams += "&showInformation=1";
            }

            string _json = requestGETFromURL(Url_EDSMSystems, _edsmParams.ToString());

            try { return(JsonConvert.DeserializeObject <EDSMSystemDatas[]>(_json)); }
            catch (Exception ex) { NexHudEngine.Log(ex.Message); }
            return(null);
        }
Example #18
0
        public static void Load()
        {
            Searchs = new List <CustomSearch>();
            LoadLists();

            //Load bookmarks
            NexHudEngine.Log("load Bookmarks.json");
            if (File.Exists(BookmarkPath))
            {
                string         _json = File.ReadAllText(BookmarkPath);
                CustomSearch[] _list = JsonConvert.DeserializeObject <CustomSearch[]>(_json);
                foreach (CustomSearch search in _list)
                {
                    if (search.SearchSystem != null && search.SearchSystem.filters.distance_from_coords != null)
                    {
                        search.SearchSystem.filters.distance_from_coords = new SpanshValue <int?>(0, SearchEngine.DefaultSystemRange);
                    }
                }
                Searchs.AddRange(_list);
            }
        }
Example #19
0
        public uint processUserSearch(NxSearchEntry _search)
        {
            if (_search.searchDisplay == null)
            {
                return(0);
            }

            if (m_lastSearchThread != null)
            {
                m_lastSearchThread.Abort();
            }

            m_lastSearchThread = null;
            m_lastSearchId++;
            m_lastUSRs.Add(m_lastSearchId, new UserSearchResult(_search, m_lastSearchId));

            NexHudEngine.Log("New search for {0} id {1}", _search.searchType, m_lastSearchId);
            m_lastSearchThread = new Thread(() => _startResearch(m_lastSearchId));
            m_lastSearchThread.Start();

            return(m_lastSearchId);
        }
Example #20
0
        public static void readConfigFile()
        {
            string _path = Environment.CurrentDirectory + "\\Config\\Searchs.json";

            if (File.Exists(_path))
            {
                try
                {
                    string _json = File.ReadAllText(_path);
                    m_userSearchEntrys = JsonConvert.DeserializeObject <NxSearchEntry[]>(_json);
                    for (int i = 0; i < m_userSearchEntrys.Length; i++)
                    {
                        m_userSearchEntrys[i].format();
                    }
                }
                catch (Exception ex)
                {
                    NexHudEngine.Log("Error while reading Searchs.json");
                    NexHudEngine.Log(ex.Message);

                    m_userSearchEntrys = new NxSearchEntry[]
                    {
                        new NxSearchEntry()
                        {
                            searchName = "ERROR"
                        },
                        new NxSearchEntry()
                        {
                            searchName = "in your"
                        },
                        new NxSearchEntry()
                        {
                            searchName = "Searchs.json"
                        }
                    };
                }
            }
        }
Example #21
0
        public static EDSMSystemDatas EDSMSystem(EDSMSystemParameters _parameters)
        {
            string _edsmParams = "systemName=" + _parameters.name + "&showCoordinates=1";

            if (_parameters.showPermit)
            {
                _edsmParams += "&showPermit=1";
            }
            if (_parameters.showInformation)
            {
                _edsmParams += "&showInformation=1";
            }
            if (_parameters.showPrimaryStar)
            {
                _edsmParams += "&showPrimaryStar=1";
            }

            string _json = requestGETFromURL(Url_EDSMSystem, _edsmParams.ToString());

            try { return(JsonConvert.DeserializeObject <EDSMSystemDatas>(_json)); }
            catch (Exception ex) { NexHudEngine.Log(ex.Message); }
            return(null);
        }
Example #22
0
        // ===> Moved to Search engine
        public static SpanshBodiesResult SpanshBodies(string _systemOrigin, int _maxDistance, string[] _materials, bool _isLandable = true)
        {
            _maxDistance = Math.Min(_maxDistance, 100);

            Dictionary <string, string> _sParams = new Dictionary <string, string>();

            SpanshValue <double>[] _spanshMats = new SpanshValue <double> [_materials.Length];
            for (int i = 0; i < _materials.Length; i++)
            {
                _spanshMats[i] = new SpanshValue <double>(_materials[i], ">", 0);
            }
            SpanshSortValue[] _spanshMatsSort = new SpanshSortValue[_materials.Length];
            for (int i = 0; i < _materials.Length; i++)
            {
                _spanshMatsSort[i] = new SpanshSortValue(_materials[i].ToString(), false);
            }

            SpanshSearchBodies p = new SpanshSearchBodies()
            {
                size             = 11,
                reference_system = _systemOrigin,
                filters          = new SpanshFilterBodies()
                {
                    distance_from_coords = new SpanshValue <int>()
                    {
                        max = _maxDistance
                    },
                    materials   = _spanshMats,
                    is_landable = new SpanshValue <bool>(_isLandable)
                },
                sort = new SpanshSort[] { new SpanshSort()
                                          {
                                              materials = _spanshMatsSort,
                                          }, new SpanshSort()
                                          {
                                              distance_from_coords = new SpanshSortValue(true)
                                          } }
            };
            string _spanshJson = JsonConvert.SerializeObject(p, new JsonSerializerSettings()
            {
                NullValueHandling = NullValueHandling.Ignore, DefaultValueHandling = DefaultValueHandling.Ignore
            });;

            Console.WriteLine(_spanshJson);
            string json = requestPOSTFromURL(Url_SpanshBodies, _spanshJson);

            try
            {
                SpanshBodiesResult result = JsonConvert.DeserializeObject <SpanshBodiesResult>(json);
                Console.WriteLine("Result: {0} RealCount: {1}", result.count, result.results.Length);
                Console.WriteLine("Search ID: " + result.search_reference);

                return(result);
            }
            catch (Exception ex)
            {
                NexHudEngine.Log(ex.Message);
                NexHudEngine.Log(json);
            }

            return(null);
        }
Example #23
0
        private void _startResearch(uint _id)
        {
            Stopwatch _watch = new Stopwatch();

            _watch.Start();

            int _statAddedSystem   = 0;
            int _statUpdatedSystem = 0;

            if (!m_lastUSRs.ContainsKey(_id))
            {
                return;
            }

            //Check if search is still valid
            if (m_lastUSRs[_id].searchID != m_lastSearchId)
            {
                m_lastUSRs[_id].Error  = UserSearchResult.UserSearchError.Aborted;
                m_lastUSRs[_id].isDone = true;
                return;
            }
            try
            {
                if (!getCurrentSystem().receivedEdsmBasics)
                {
                    m_lastUSRs[_id].Error = UserSearchResult.UserSearchError.CurrentSystemNotCompleted;
                }
                else if (m_lastUSRs[_id].entry.searchType == NxSearchType.system)
                {
                    //If names are specified we will ignore other parameters
                    if (m_lastUSRs[_id].entry.searchParamsFormated.ContainsKey(NxSearchParam.name))
                    {
                        string[] _names      = m_lastUSRs[_id].entry.searchParamsFormated[NxSearchParam.name];
                        string[] _namesNotes = new string[0];
                        if (m_lastUSRs[_id].entry.searchParamsFormated.ContainsKey(NxSearchParam.nameNotes))
                        {
                            _namesNotes = m_lastUSRs[_id].entry.searchParamsFormated[NxSearchParam.nameNotes];
                        }


                        for (int i = 0; i < _names.Length; i++)
                        {
                            _names[i] = _names[i].Trim();
                        }


                        for (int i = 0; i < _names.Length; i++)
                        {
                            //Can be optimized with https://www.edsm.net/api-v1/systems
                            EDSMSystemDatas _edsmDatas = ApiConnection.EDSMSystemFullInfos(_names[i]);
                            if (_edsmDatas != null)
                            {
                                EDSystem _system = new EDSystem();
                                _system.updateEDSM(_edsmDatas);
                                NexHudEngine.Log("(EDSM) Found system: " + _system.name);
                                m_lastUSRs[_id].addSystem(_system);
                                if (i < _namesNotes.Length)
                                {
                                    _system.Notes = _namesNotes[i];
                                }
                            }
                        }
                    }
                    else
                    {
                        //Get systems in radius
                        int _radius = m_greatestSearchRadius;

                        int _startRardius = 40;
                        if (m_lastUSRs[_id].entry.searchMaxRadius > 0 && m_lastUSRs[_id].entry.searchMaxRadius < _startRardius)
                        {
                            _startRardius = m_lastUSRs[_id].entry.searchMaxRadius;
                        }


                        int _maxEdsmRadius = 100;
                        if (m_lastUSRs[_id].entry.searchMaxRadius > _startRardius && m_lastUSRs[_id].entry.searchMaxRadius < _maxEdsmRadius)
                        {
                            _maxEdsmRadius = m_lastUSRs[_id].entry.searchMaxRadius;
                        }

                        int[] _increments = new int[]
                        {
                            //Threshold,increment
                            60, 20,
                            90, 10,
                            100, 5
                        };

                        int _pass = 1;
                        if (_radius < _startRardius)
                        {
                            _radius = _startRardius;
                        }

                        int _radiusMinimum = 0;
                        while (m_lastUSRs[_id].Count < UiSearch.MAX_LINE_RESULT && _radius <= _maxEdsmRadius)
                        {
                            m_lastUSRs[_id].ResearchTime  = _watch.ElapsedMilliseconds;
                            m_lastUSRs[_id].CurrentPass   = _pass;
                            m_lastUSRs[_id].CurrentRadius = _radius;
                            //Building list
                            if (_radius > m_greatestSearchRadius)
                            {
                                EDSMSystemDatas[] _systemsInSphereRadius = ApiConnection.EDSMSystemsInSphereRadius(getCurrentSystem().name, m_greatestSearchRadius, _radius);
                                if (_systemsInSphereRadius != null)
                                {
                                    m_greatestSearchRadius = _radius;
                                    for (int i = 0; i < _systemsInSphereRadius.Length; i++)
                                    {
                                        if (!m_systemAround.Contains(_systemsInSphereRadius[i].name))
                                        {
                                            m_systemAround.Add(_systemsInSphereRadius[i].name);
                                        }
                                        if (!m_systems.ContainsKey(_systemsInSphereRadius[i].name))
                                        {
                                            EDSystem _newSystem = new EDSystem();
                                            _newSystem.updateEDSM(_systemsInSphereRadius[i]);
                                            _statAddedSystem++;
                                            m_systems.Add(_systemsInSphereRadius[i].name, _newSystem);
                                        }
                                    }
                                }
                            }

                            List <EDSystem> _systemInRadius = new List <EDSystem>();
                            //Recalculate distance and updating basics...
                            foreach (string _sys in m_systemAround)
                            {
                                if (!m_systems.ContainsKey(_sys))
                                {
                                    _statAddedSystem++;
                                    m_systems.Add(_sys, new EDSystem());
                                }
                                if (!m_systems[_sys].receivedEdsmInfos)
                                {
                                    NexHudEngine.Log("//WARNING// system {0} has not received informations datas. Retrieving...", _sys);
                                    m_systems[_sys].updateEDSM(ApiConnection.EDSMSystem(new ApiConnection.EDSMSystemParameters()
                                    {
                                        name = _sys, showInformation = true
                                    }));
                                    m_systems[_sys].calculDistanceFromCurrent();
                                }
                                if (m_systems[_sys].distanceFromCurrentSystem < _radius && m_systems[_sys].distanceFromCurrentSystem >= _radiusMinimum)
                                {
                                    _systemInRadius.Add(m_systems[_sys]);
                                }
                            }


                            IEnumerable <EDSystem> _ordered = _systemInRadius.OrderBy(s => s.distanceFromCurrentSystem);

                            //Allegiance
                            if (m_lastUSRs[_id].entry.searchParamsFormated.ContainsKey(NxSearchParam.allegiance))
                            {
                                _ordered = _ordered.Where(x => m_lastUSRs[_id].entry.searchParamsFormated[NxSearchParam.allegiance].Any(y => x.allegiance.ToStringFormated().Equals(y, StringComparison.InvariantCultureIgnoreCase)));
                            }

                            //Government
                            if (m_lastUSRs[_id].entry.searchParamsFormated.ContainsKey(NxSearchParam.government))
                            {
                                _ordered = _ordered.Where(x => m_lastUSRs[_id].entry.searchParamsFormated[NxSearchParam.government].Any(y => x.government.ToStringFormated().Equals(y, StringComparison.InvariantCultureIgnoreCase)));
                            }

                            //Primary economy
                            if (m_lastUSRs[_id].entry.searchParamsFormated.ContainsKey(NxSearchParam.economy))
                            {
                                _ordered = _ordered.Where(x => m_lastUSRs[_id].entry.searchParamsFormated[NxSearchParam.economy].Any(y => x.economy.ToStringFormated().Equals(y, StringComparison.InvariantCultureIgnoreCase)));
                            }

                            //Reserve
                            if (m_lastUSRs[_id].entry.searchParamsFormated.ContainsKey(NxSearchParam.reserve))
                            {
                                _ordered = _ordered.Where(x => m_lastUSRs[_id].entry.searchParamsFormated[NxSearchParam.reserve].Any(y => x.reserve.ToStringFormated().Equals(y, StringComparison.InvariantCultureIgnoreCase)));
                            }

                            //Security
                            if (m_lastUSRs[_id].entry.searchParamsFormated.ContainsKey(NxSearchParam.security))
                            {
                                _ordered = _ordered.Where(x => m_lastUSRs[_id].entry.searchParamsFormated[NxSearchParam.security].Any(y => x.security.ToStringFormated().Equals(y, StringComparison.InvariantCultureIgnoreCase)));
                            }

                            //State
                            if (m_lastUSRs[_id].entry.searchParamsFormated.ContainsKey(NxSearchParam.state))
                            {
                                _ordered = _ordered.Where(x => m_lastUSRs[_id].entry.searchParamsFormated[NxSearchParam.state].Any(y => x.state.ToStringFormated().Equals(y, StringComparison.InvariantCultureIgnoreCase)));
                            }



                            NexHudEngine.Log("+ Search total result: {0} . Pass {1}", _ordered.Count(), _pass);
                            m_lastUSRs[_id].ResearchTime = _watch.ElapsedMilliseconds;
                            foreach (EDSystem x in _ordered)
                            {
                                m_lastUSRs[_id].addSystem(x);
                                if (m_lastUSRs[_id].Count >= UiSearch.MAX_LINE_RESULT)
                                {
                                    break;
                                }
                            }
                            _radiusMinimum = _radius;

                            for (int _inc = 0; _inc < _increments.Length; _inc += 2)
                            {
                                if (_radius < _increments[_inc])
                                {
                                    _radius += _increments[_inc + 1];
                                    break;
                                }
                            }
                            if (_radius >= _maxEdsmRadius)
                            {
                                break;
                            }
                            _pass++;
                        }
                    }
                }
                else if (m_lastUSRs[_id].entry.searchType == NxSearchType.body)
                {
                    List <string> _listMaterials = new List <string>();
                    //Make sure the materials are valid
                    if (m_lastUSRs[_id].entry.searchParamsFormated.ContainsKey(NxSearchParam.rawMaterial))
                    {
                        foreach (string _material in m_lastUSRs[_id].entry.searchParamsFormated[NxSearchParam.rawMaterial])
                        {
                            if (EngineerHelper.isRawMaterial(_material))
                            {
                                _listMaterials.Add(_material);
                            }
                        }
                    }
                    bool isLandable = true;
                    if (m_lastUSRs[_id].entry.searchParamsFormated.ContainsKey(NxSearchParam.isLandable))
                    {
                        isLandable = m_lastUSRs[_id].entry.searchParamsFormated[NxSearchParam.isLandable][0] == "true";
                    }


                    if (_listMaterials.Count > 0)
                    {
                        int maxDistance = 20;

                        if (m_lastUSRs[_id].entry.searchMaxRadius > 0)
                        {
                            maxDistance = Math.Min(m_lastUSRs[_id].entry.searchMaxRadius, 100);
                        }



                        SpanshBodiesResult _spanshResult = ApiConnection.SpanshBodies(getCurrentSystem().name, maxDistance, _listMaterials.ToArray(), isLandable);

                        //Get infos about the targeted systems
                        List <string> _systemWithBodies = new List <string>();
                        foreach (SpanshBody b in _spanshResult.results)
                        {
                            if (!_systemWithBodies.Contains(b.system_name))
                            {
                                _systemWithBodies.Add(b.system_name);
                            }
                        }

                        List <string> _systemToUpdate = new List <string>();
                        //Clean list for system we already received infos
                        foreach (string s in _systemWithBodies)
                        {
                            if (m_systems.ContainsKey(s))
                            {
                                if (!m_systems[s].receivedEdsmBasics && !m_systems[s].receivedEdsmInfos)
                                {
                                    _systemToUpdate.Add(s);
                                }
                            }
                            else
                            {
                                m_systemAround.Add(s);
                                m_systems.Add(s, new EDSystem());
                                _systemToUpdate.Add(s);
                            }
                        }
                        if (_systemToUpdate.Count > 0)
                        {
                            EDSMSystemDatas[] _edsmDatas = ApiConnection.EDSMSystemsList(_systemToUpdate.ToArray(), true);
                            foreach (EDSMSystemDatas _data in _edsmDatas)
                            {
                                m_systems[_data.name].updateEDSM(_data);
                            }
                        }

                        foreach (SpanshBody b in _spanshResult.results)
                        {
                            m_lastUSRs[_id].addBody(m_systems[b.system_name].addOrUpdateBody(b));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                if (ex.InnerException is ThreadAbortException)
                {
                    m_lastUSRs[_id].Error = UserSearchResult.UserSearchError.Aborted;
                    NexHudEngine.Log("Aborting last search thread {0}. Last Id {1}", Thread.CurrentThread.Name, _id);
                }
                else
                {
                    m_lastUSRs[_id].Error = UserSearchResult.UserSearchError.UnknowError;
                    NexHudEngine.Log("ERROR: Search {0} reported an error: {1}", _id, ex.Message);
                }
            }
            finally
            {
                _watch.Stop();
                NexHudEngine.Log("Search was done in {0}ms. Error:{1} Added:{2} Updated:{3}", _watch.ElapsedMilliseconds, m_lastUSRs[_id].Error, _statAddedSystem, _statUpdatedSystem);
                m_lastUSRs[_id].isDone       = true;
                m_lastUSRs[_id].ResearchTime = _watch.ElapsedMilliseconds;
            }
        }
Example #24
0
 private static void InitEngine(NexHudEngineMode _mode)
 {
     NexHudEngine.Log("Engine Initilization...");
     NexHudEngine.Init(_mode);
     NexHudEngine.FPS = 30;
 }
Example #25
0
        public static void Main(string[] args)
        {
            m_mutex = new Mutex(true, AppName, out bool createdNew);

            if (!createdNew)
            {
                Console.WriteLine(AppName + " is already running! Exiting the application.");
                Console.ReadKey();
                return;
            }

            InitLogs();
            NexHudSettings.load();

            NexHudEngine.Log("NexHud Version: " + Version);

            NexHudEngineMode _requestedMode = NexHudSettings.GetInstance().nexHudMode;

            foreach (string a in args)
            {
                if (a == ArgAuto)
                {
                    _requestedMode = NexHudEngineMode.Auto;
                }
                else if (a == ArgDebug)
                {
                    _requestedMode = NexHudEngineMode.WindowDebug;
                }
                else if (a == ArgVr)
                {
                    _requestedMode = NexHudEngineMode.Vr;
                }
                else if (a == ArgClassic)
                {
                    _requestedMode = NexHudEngineMode.WindowOverlay;
                }
            }
            NexHudEngine.Log("Engine mode Requested: " + _requestedMode);
            //performTests();
            InitEliteApi();

            InitEngine(_requestedMode);
            NexHudEngine.Log("Engine mode: " + _requestedMode);

            LoadConfigs();


            if (NexHudEngine.engineMode == NexHudEngineMode.Vr)
            {
                InitVrConsole();
            }

            new NxMenu();

            try
            {
                NexHudEngine.Run(); // Runs update/draw calls for all active overlays. And yes, it's blocking.
            }
            catch (Exception ex)
            {
                NexHudEngine.Log(NxLog.Type.Fatal, ex.Message);
                NexHudEngine.Log(NxLog.Type.Fatal, ex.Source);
                NexHudEngine.Log(NxLog.Type.Fatal, ex.StackTrace);
            }
        }
Example #26
0
        private void SteamVR_NexHUD_PostUpdateCallback(object sender, EventArgs e)
        {
            if (m_state == MenuState.Initialize)
            {
                return;
            }


            if (Shortcuts.holdMode)
            {
                if (NexHudEngine.isShortcutIsHold(Shortcuts.get(ShortcutId.menu)))
                {
                    if (!m_frame.renderOverlay)
                    {
                        m_frame.renderOverlay = true;
                        if (NexHudSettings.GetInstance().stealFocus)
                        {
                            FocusHelper.focusonNexHud();
                        }
                    }

                    if (NexHudEngine.isShortcutPressed(Shortcuts.get(ShortcutId.back)))
                    {
                        if (m_state != MenuState.Main && m_state != MenuState.Improve && m_state != MenuState.Search)
                        {
                            changeState(MenuState.Main);
                        }
                    }
                }
                else
                {
                    if (m_frame.renderOverlay)
                    {
                        m_frame.renderOverlay = false;
                        if (NexHudSettings.GetInstance().stealFocus)
                        {
                            FocusHelper.focusOnGame();
                        }
                    }
                    return;
                }
            }
            else
            {
                if (NexHudEngine.isShortcutPressed(Shortcuts.get(ShortcutId.menu)))
                {
                    if (m_frame.renderOverlay)
                    {
                        if (m_state != MenuState.Main)
                        {
                            if (m_state != MenuState.Improve && m_state != MenuState.Search)
                            {
                                changeState(MenuState.Main);
                            }
                        }
                        else
                        {
                            m_frame.renderOverlay = false;
                            if (NexHudSettings.GetInstance().stealFocus)
                            {
                                FocusHelper.focusOnGame();
                            }
                        }
                    }
                    else
                    {
                        changeState(MenuState.Main);
                        m_frame.renderOverlay = true;
                        if (NexHudSettings.GetInstance().stealFocus)
                        {
                            FocusHelper.focusonNexHud();
                        }
                    }
                }
            }

            if (m_frame.renderOverlay)
            {
                //MAIN MENU NAVIGATION
                if (m_uiMainMenu.isVisible)
                {
                    bool up     = NexHudEngine.isShortcutPressed(Shortcuts.get(ShortcutId.up));
                    bool down   = NexHudEngine.isShortcutPressed(Shortcuts.get(ShortcutId.down));
                    bool left   = NexHudEngine.isShortcutPressed(Shortcuts.get(ShortcutId.left));
                    bool right  = NexHudEngine.isShortcutPressed(Shortcuts.get(ShortcutId.right));
                    bool select = NexHudEngine.isShortcutPressed(Shortcuts.get(ShortcutId.select));



                    if (Cursor.Y == 0)
                    {
                        if (right)
                        {
                            m_uiMainMenu.selectNext();
                        }
                        else if (left)
                        {
                            m_uiMainMenu.selectPrev();
                        }
                        else if (down)
                        {
                            Cursor = new Point(1, 1);
                        }
                        else if (select)
                        {
                            if (m_uiMainMenu.isSelectedMenuActive())
                            {
                                switch (m_uiMainMenu.SelectedMenu)
                                {
                                case UiMainMenuButton.MenuButtonType.Search:
                                    changeState(MenuState.Search);
                                    break;

                                case UiMainMenuButton.MenuButtonType.Improve:
                                    changeState(MenuState.Improve);
                                    break;

                                case UiMainMenuButton.MenuButtonType.Trade:
                                    changeState(MenuState.Trade);
                                    break;
                                }
                            }
                        }
                    }
                    else
                    {
                        if (up)
                        {
                            Cursor.Y--;
                        }
                        else if (down && Cursor.Y < 2)
                        {
                            Cursor.Y++;
                        }

                        else if (left && Cursor.X > 0 && Cursor.Y < 2)
                        {
                            Cursor.X--;
                        }
                        else if (right && Cursor.X < 2 && Cursor.Y < 2)
                        {
                            Cursor.X++;
                        }
                        m_UiRadio.PreviousRadio.Selected = Cursor == new Point(0, 1);
                        m_UiRadio.Radio.Selected         = Cursor == new Point(1, 1);
                        m_UiRadio.NextRadio.Selected     = Cursor == new Point(2, 1);

                        m_UiRadio.VolumeSelected = Cursor.Y == 2;
                    }
                }
            }
        }
Example #27
0
        public override void Update()
        {
            base.Update();
            if (!isVisible)
            {
                _skipUpdate = true;
                return;
            }
            else if (_skipUpdate)
            {
                _skipUpdate = false;
                return;
            }

            if (NexHudEngine.isShortcutPressed(Shortcuts.get(ShortcutId.right)) && m_CursorCoords.X < m_CursorMaxX)
            {
                m_CursorCoords.X++;
            }
            if (NexHudEngine.isShortcutPressed(Shortcuts.get(ShortcutId.left)) && m_CursorCoords.X > 0)
            {
                m_CursorCoords.X--;
            }
            if (NexHudEngine.isShortcutPressed(Shortcuts.get(ShortcutId.down)))
            {
                if (m_CursorCoords.Y < m_CursorMaxY[m_CursorCoords.X])
                {
                    m_CursorCoords.Y++;
                }
                else if (m_CursorCoords.X < m_CursorMaxX)
                {
                    m_CursorCoords.X++;
                    m_CursorCoords.Y = 0;
                }
            }
            if (NexHudEngine.isShortcutPressed(Shortcuts.get(ShortcutId.up)))
            {
                if (m_CursorCoords.Y > (m_CursorCoords.X == 0 ? 1 : 0))
                {
                    m_CursorCoords.Y--;
                }
                else if (m_CursorCoords.X > 0)
                {
                    m_CursorCoords.X--;
                    m_CursorCoords.Y = m_CursorMaxY[m_CursorCoords.X];
                }
            }

            //Pick the one
            NxButton _selected = null;

            while (_selected == null)
            {
                _selected = m_Buttons.Where(x => x.Coords == m_CursorCoords).FirstOrDefault();
                if (_selected != null && !_selected.isSelectable)
                {
                    if (NexHudEngine.isShortcutPressed(Shortcuts.get(ShortcutId.up)))
                    {
                        m_CursorCoords.Y--;
                    }
                    else
                    {
                        m_CursorCoords.Y++;
                    }
                    _selected = null;
                    continue;
                }
                if (_selected == null)
                {
                    if (m_CursorCoords.Y > 1)
                    {
                        m_CursorCoords.Y--;
                    }
                    else if (m_CursorCoords.X > 0)
                    {
                        m_CursorCoords.X--;
                    }
                    else
                    {
                        break;
                    }
                }
            }
            foreach (NxButton b in m_Buttons)
            {
                b.Selected = b == _selected;
            }

            if (NexHudEngine.isShortcutPressed(Shortcuts.get(ShortcutId.select)) && _selected != null)
            {
                if (_selected.Obj is string)
                {
                    m_TypeSelected = (string)_selected.Obj;
                }
                else if (_selected.Obj is BlueprintDatas)
                {
                    BlueprintDatas d         = (BlueprintDatas)_selected.Obj;
                    BlueprintDatas _maxGrade = EngineerHelper.blueprints.Where(x => x.Type == d.Type && x.Name == d.Name && x.Grade == d.MaxGrade).FirstOrDefault();
                    m_uiImprove.BlueprintDetails.setBlueprint(_maxGrade);
                    m_uiImprove.changeState(UiImprove.UiImproveState.BlueprintDetail);
                }
                refresh();
            }
        }