예제 #1
0
        private PyObject Evaluate(PySharp.PySharp pySharp, PyObject pyObject)
        {
            // TODO: Better part splitting (e.g. bla('bla', const.bla)
            var parts = _evaluate.Split('.');

            if (parts.Length == 0)
            {
                // TODO: List imports
                return(null);
            }

            if (pyObject == null)
            {
                pyObject = pySharp.Import(parts[0]);
            }

            for (var i = 1; i < parts.Length; i++)
            {
                if (parts[i].Contains("("))
                {
                    // TODO: Call
                }
                else if (parts[i].Contains("["))
                {
                    var attr = parts[i].Substring(0, parts[i].IndexOf('['));

                    var key = parts[i].Substring(parts[i].IndexOf('[') + 1, parts[i].IndexOf(']') - parts[i].IndexOf('[') - 1);
                    if (key.StartsWith("'") || key.StartsWith("\""))
                    {
                        key = key.Substring(1, key.Length - 2);
                    }

                    if (!string.IsNullOrEmpty(attr))
                    {
                        pyObject = pyObject.Attribute(attr);
                    }

                    if (pyObject.GetPyType() == PyType.DictType ||
                        pyObject.GetPyType() == PyType.DerivedDictType ||
                        pyObject.GetPyType() == PyType.DictProxyType ||
                        pyObject.GetPyType() == PyType.DerivedDictProxyType)
                    {
                        var dict = pyObject.ToDictionary();

                        pyObject = PySharp.PySharp.PyZero;
                        foreach (var dictItem in dict)
                        {
                            if (GetPyValue(dictItem.Key) == key)
                            {
                                pyObject = dictItem.Value;
                            }
                        }
                    }
                    else
                    {
                        int index;
                        pyObject = int.TryParse(key, out index) ? pyObject.Item(index) : PySharp.PySharp.PyZero;
                    }
                }
                else
                {
                    pyObject = pyObject.Attribute(parts[i]);
                }
            }

            return(pyObject);
        }
예제 #2
0
        private void OnFrame(object sender, LSEventArgs e)
        {
            try
            {
                using (dynamic pySharp = new PySharp.PySharp())
                {
                    dynamic pyObject = null;

                    if (_doTest)
                    {
                        _doTest = false;

                        pyObject = pySharp.__builtin__.eve.session;

                        var file = pySharp.__builtin__.open("c:/blaat.txt", "wb");
                        file.write("hello world");
                        file.close();

                        //// Make eve reload the compiled code file (stupid DiscardCode function :)
                        //pySharp.Import("nasty").Attribute("nasty").Attribute("compiler").Call("Load", pySharp.Import("nasty").Attribute("nasty").Attribute("compiledCodeFile"));

                        //// Get a reference to all code files
                        //var dict = pySharp.Import("nasty").Attribute("nasty").Attribute("compiler").Attribute("code").ToDictionary();

                        //// Get the magic once
                        //var magic = pySharp.Import("imp").Call("get_magic");

                        //foreach (var item in dict)
                        //{
                        //    // Clean up the path
                        //    var path = (string)item.Key.Item(0);
                        //    if (path.IndexOf(":") >= 0)
                        //        path = path.Substring(path.IndexOf(":") + 1);
                        //    while (path.StartsWith("/.."))
                        //        path = path.Substring(3);
                        //    path = "c:/dump/code" + path + "c";

                        //    // Create the directory
                        //    Directory.CreateDirectory(Path.GetDirectoryName(path));

                        //    var file = pySharp.Import("__builtin__").Call("open", path, "wb");
                        //    var time = pySharp.Import("os").Attribute("path").Call("getmtime", path);

                        //    // Write the magic
                        //    file.Call("write", magic);
                        //    // Write the time
                        //    file.Call("write", pySharp.Import("struct").Call("pack", "<i", time));
                        //    // Write the code
                        //    pySharp.Import("marshal").Call("dump", item.Value.Item(0), file);
                        //    // Close the file
                        //    file.Call("close");
                        //}
                        InnerSpace.Echo("Done");
                    }

                    if (_doEvaluate)
                    {
                        _doEvaluate = false;
                        pyObject    = Evaluate(pySharp, pyObject);
                    }

                    if (pyObject != null)
                    {
                        ListPyObject(pyObject);
                    }
                }
            }
            finally
            {
                _done = true;
            }
        }
예제 #3
0
        private void OnFrame(object sender, LSEventArgs e)
        {
            try
            {
                using (dynamic pySharp = new PySharp.PySharp())
                {
                    dynamic pyObject = null;

                    if (_doTest)
                    {
                        _doTest = false;

                        pyObject = pySharp.__builtin__.eve.session;

                        var file = pySharp.__builtin__.open("c:/blaat.txt", "wb");
                        file.write("hello world");
                        file.close();

                        //// Make eve reload the compiled code file (stupid DiscardCode function :)
                        //pySharp.Import("nasty").Attribute("nasty").Attribute("compiler").Call("Load", pySharp.Import("nasty").Attribute("nasty").Attribute("compiledCodeFile"));

                        //// Get a reference to all code files
                        //var dict = pySharp.Import("nasty").Attribute("nasty").Attribute("compiler").Attribute("code").ToDictionary();

                        //// Get the magic once
                        //var magic = pySharp.Import("imp").Call("get_magic");

                        //foreach (var item in dict)
                        //{
                        //    // Clean up the path
                        //    var path = (string)item.Key.Item(0);
                        //    if (path.IndexOf(":") >= 0)
                        //        path = path.Substring(path.IndexOf(":") + 1);
                        //    while (path.StartsWith("/.."))
                        //        path = path.Substring(3);
                        //    path = "c:/dump/code" + path + "c";

                        //    // Create the directory
                        //    Directory.CreateDirectory(Path.GetDirectoryName(path));

                        //    var file = pySharp.Import("__builtin__").Call("open", path, "wb");
                        //    var time = pySharp.Import("os").Attribute("path").Call("getmtime", path);

                        //    // Write the magic
                        //    file.Call("write", magic);
                        //    // Write the time
                        //    file.Call("write", pySharp.Import("struct").Call("pack", "<i", time));
                        //    // Write the code
                        //    pySharp.Import("marshal").Call("dump", item.Value.Item(0), file);
                        //    // Close the file
                        //    file.Call("close");
                        //}
                        InnerSpace.Echo("Done");
                    }

                    if (_doEvaluate)
                    {
                        _doEvaluate = false;
                        pyObject = Evaluate(pySharp, pyObject);
                    }

                    if (pyObject != null)
                        ListPyObject(pyObject);
                }
            }
            finally
            {
                _done = true;
            }
        }
예제 #4
0
        /// <summary>
        ///     Internal "OnFrame" handler
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void FrameworkOnFrame(object sender, EventArgs e)
        {
            var st = new Stopwatch();
            st.Start();
            using (var pySharp = new PySharp.PySharp(true))
            {
                // Make the link to the instance
                PySharp = pySharp;

            //#if !NO_DIRECTEVE_SECURITY
            //                // Pulse security
            //                if (_security == null || !_security.Pulse())
            //                {
            //                    if (!_securityCheckFailed)
            //                    {
            //                        _securityCheckFailed = true;
            //                        Log("DirectEve supported instance check failed!");
            //                    }
            //                    return;
            //                }

            //                if (_securityCheckFailed)
            //                {
            //                    _securityCheckFailed = false;
            //                    Log("DirectEve supported instance check succeeded, continuing...");
            //                }
            //#endif
                // Get current target list
                dynamic ps = pySharp;
                // targetsByID and targeting are now dictionaries
                List<long> targets = ps.__builtin__.sm.services["target"].targetsByID.keys().ToList<long>();
                targets.AddRange(ps.__builtin__.sm.services["target"].targeting.keys().ToList<long>());

                // Update currently locked targets
                targets.ForEach(t => _lastKnownTargets[t] = DateTime.Now);
                // Remove all targets that have not been locked for 3 seconds
                foreach (var t in _lastKnownTargets.Keys.ToArray())
                {
                    if (DateTime.Now.AddSeconds(-3) < _lastKnownTargets[t])
                        continue;

                    _lastKnownTargets.Remove(t);
                }

                ////Populate the statistic variables
                if (_enableStatisticsModifying)
                {
                    CheckStatistics();
                }

                // Check if we're still valid
                if (OnFrame != null)
                    OnFrame(this, new EventArgs());

                // Clear any cache that we had during this frame
                _localSvcCache.Clear();
                _entitiesById = null;
                _windows = null;
                _modules = null;
                _const = null;
                _bookmarks = null;
                _agentMissions = null;

                _containers.Clear();
                _itemHangar = null;
                _shipHangar = null;
                _shipsCargo = null;
                _shipsOreHold = null;
                _shipsModules = null;
                _shipsDroneBay = null;
                _listGlobalAssets = null;
                _me = null;
                _activeShip = null;
                _standings = null;
                _navigation = null;
                _session = null;
                _login = null;
                _skills = null;

                // Remove the link
                PySharp = null;

                st.Stop();
                _lastOnframeTook = st.ElapsedMilliseconds;
            }
        }
예제 #5
0
        /// <summary>
        ///     Internal "OnFrame" handler
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void FrameworkOnFrame(object sender, EventArgs e)
        {
            var st = new Stopwatch();

            st.Start();
            using (var pySharp = new PySharp.PySharp(true))
            {
                // Make the link to the instance
                PySharp = pySharp;

//#if !NO_DIRECTEVE_SECURITY
//                // Pulse security
//                if (_security == null || !_security.Pulse())
//                {
//                    if (!_securityCheckFailed)
//                    {
//                        _securityCheckFailed = true;
//                        Log("DirectEve supported instance check failed!");
//                    }
//                    return;
//                }

//                if (_securityCheckFailed)
//                {
//                    _securityCheckFailed = false;
//                    Log("DirectEve supported instance check succeeded, continuing...");
//                }
//#endif
                // Get current target list
                dynamic ps = pySharp;
                // targetsByID and targeting are now dictionaries
                List <long> targets = ps.__builtin__.sm.services["target"].targetsByID.keys().ToList <long>();
                targets.AddRange(ps.__builtin__.sm.services["target"].targeting.keys().ToList <long>());

                // Update currently locked targets
                targets.ForEach(t => _lastKnownTargets[t] = DateTime.Now);
                // Remove all targets that have not been locked for 3 seconds
                foreach (var t in _lastKnownTargets.Keys.ToArray())
                {
                    if (DateTime.Now.AddSeconds(-3) < _lastKnownTargets[t])
                    {
                        continue;
                    }

                    _lastKnownTargets.Remove(t);
                }

                ////Populate the statistic variables
                if (_enableStatisticsModifying)
                {
                    CheckStatistics();
                }

                // Check if we're still valid
                if (OnFrame != null)
                {
                    OnFrame(this, new EventArgs());
                }

                // Clear any cache that we had during this frame
                _localSvcCache.Clear();
                _entitiesById  = null;
                _windows       = null;
                _modules       = null;
                _const         = null;
                _bookmarks     = null;
                _agentMissions = null;

                _containers.Clear();
                _itemHangar       = null;
                _shipHangar       = null;
                _shipsCargo       = null;
                _shipsOreHold     = null;
                _shipsModules     = null;
                _shipsDroneBay    = null;
                _listGlobalAssets = null;
                _me         = null;
                _activeShip = null;
                _standings  = null;
                _navigation = null;
                _session    = null;
                _login      = null;
                _skills     = null;

                // Remove the link
                PySharp = null;

                st.Stop();
                _lastOnframeTook = st.ElapsedMilliseconds;
            }
        }