Esempio n. 1
0
        public void Start()
        {
            var hConsole = DllImports.GetStdHandle(-11);

            DllImports.SetConsoleDisplayMode(hConsole, 1, out _);
            round = 0;
//            delta = 0;
            players = 0;
            success = false;
            game    = false;
            GAME    = true;
            menu    = true;
            Console.WriteLine("1 - новая игра    2 - загрузить игру");
            switch (Console.ReadLine())
            {
            case "1":
                NewGame();
                break;

            case "2":
                LoadGame();
                break;

            default:
                Console.WriteLine("Такой команды нет");
                break;
            }
        }
Esempio n. 2
0
        /// <summary>
        ///     Shares a server resource.
        /// </summary>
        /// <param name="servername">
        ///     Pointer to a string that specifies the DNS or NetBIOS name of the remote server on which the
        ///     function is to execute. If this parameter is NULL, the local computer is used.
        /// </param>
        /// <param name="shareInfo502">
        ///     Specifies the information level of the data. This parameter can be one of the following
        ///     values.
        /// </param>
        /// <returns>Returns a NetApiResult Enumeration.</returns>
        public static Enum.NetApiResult Create(string servername, ShareInfo502 shareInfo502)
        {
            var  nativeShareInfo502 = ShareInfo502.MapToNativeShareInfo502(shareInfo502);
            uint error = 0;

            return((Enum.NetApiResult)DllImports.NetShareAdd(servername, 502, ref nativeShareInfo502, out error));
        }
Esempio n. 3
0
        /// <summary>
        ///     The current Windows default Folder Icon in the given Size (Large/Small) as System.Drawing.Icon.
        /// </summary>
        /// <param name="size">The Size of the Icon (Small or Large).</param>
        /// <param name="folderType">The folderTypeIcon (closed or Open).</param>
        /// <returns>The Folder Icon as System.Drawing.Icon.</returns>
        public static Icon GetDefaultDirectoryIcon(IconSize size, FolderType folderType)
        {
            var flags = ShgfiIcon | ShgfiUsefileattributes;

            if (FolderType.Open == folderType)
            {
                flags += ShgfiOpenicon;
            }
            if (IconSize.Small == size)
            {
                flags += ShgfiSmallicon;
            }
            else
            {
                flags += ShgfiLargeicon;
            }
            var shfi = new Structs.Shfileinfo();
            var res  = DllImports.SHGetFileInfo(@"C:\Windows", FileAttributeDirectory, out shfi, (uint)Marshal.SizeOf(shfi), flags);

            if (res == IntPtr.Zero)
            {
                throw Marshal.GetExceptionForHR(Marshal.GetHRForLastWin32Error());
            }
            Icon.FromHandle(shfi.hIcon);
            var icon = (Icon)Icon.FromHandle(shfi.hIcon).Clone();

            DllImports.DestroyIcon(shfi.hIcon);
            return(icon);
        }
Esempio n. 4
0
        public static void DrawObject(DrawingObjects drawObj)
        {
            //todo: find a way to send c# objects to c++
            switch (drawObj)
            {
            case DrawingText text:
                DllImports.DrawText(text.text, text.name, text.parentName, text.x, text.y, text.zOrder, text.visible, text.spaceBetweenChars);
                break;

            case DrawingLine line:
                DllImports.DrawLine(line.name, line.parentName, line.x, line.y, line.x2, line.y2, line.color, line.zOrder, line.visible);
                break;

            case DrawingCircle circle:
                DllImports.DrawCircle(circle.name, circle.parentName, circle.x, circle.y, circle.rad, circle.color, circle.zOrder, circle.visible);
                break;

            case DrawingRect rect:
                DllImports.DrawRect(rect.name, rect.parentName, rect.x, rect.y, rect.x2, rect.y2, rect.color, rect.zOrder, rect.visible);
                break;

            case DrawingArrow line:
                DllImports.DrawLine(line.name, line.parentName, line.x, line.y, line.x2, line.y2, line.color, line.zOrder, line.visible, true);
                break;
            }
        }
Esempio n. 5
0
        public static void Main(string[] args)
        {
            if (args.Length != 3)
            {
                Console.Error.WriteLine("usage:  minvoke.exe MapAssemblyName InputAssemblyName OutputAssemblyName");
                Environment.Exit(1);
            }
            string map_assembly_name    = args[0];
            string input_assembly_name  = args[1];
            string output_assembly_name = args[2];

            Console.WriteLine("building list of MapDllImports from map assembly {0}", map_assembly_name);

            DllImportMap map = BuildMap(map_assembly_name);

            Console.WriteLine("building list of DllImports in input assembly {0}", input_assembly_name);

            var input_assembly = AssemblyDefinition.ReadAssembly(input_assembly_name);

            DllImports imports = CollectDllImports(input_assembly);

            Console.WriteLine("retargeting assembly {0} -> {1}", input_assembly_name, output_assembly_name);

            Retarget(input_assembly, map, imports);

            input_assembly.Write(output_assembly_name);
        }
Esempio n. 6
0
        private uint InsertMenuItemPrivate(IntPtr menuHandle, string textName, int position, RightClickActionDelegate actionDelegate)
        {
            if (mMenuItemsAddedCount >= mMenuMaximumItemsWeCanAdd)
            {
                return(0);
            }

            // Create a new Menu Item to add to the popup menu
            MENUITEMINFO mii = new MENUITEMINFO();

            mii.cbSize     = ( uint )Marshal.SizeOf(typeof(MENUITEMINFO));
            mii.fMask      = ( uint )MIIM.ID | ( uint )MIIM.TYPE | ( uint )MIIM.STATE;
            mii.wID        = ( uint )(mMenuCmdFirst + mMenuItemsAddedCount);
            mii.fType      = ( uint )MF.STRING;
            mii.dwTypeData = textName;
            mii.cch        = 0;
            mii.fState     = ( uint )MF.ENABLED;

            // Add it to the item
            if (DllImports.InsertMenuItem(menuHandle, (uint)position, true, ref mii) == 0)
            {
                // failed
                //int error = Marshal.GetLastWin32Error();
                //System.Windows.Forms.MessageBox.Show( "InsertMenuItem failed + 0x" + error.ToString( "X" ) + " : " + ( new System.ComponentModel.Win32Exception( error ) ).Message );
                return(0);
            }
            else
            {
                mMenuIdsMap.Add(mMenuItemsAddedCount, actionDelegate);
                mMenuItemsAddedCount++;
                return(mii.wID);
            }
        }
Esempio n. 7
0
        public uint InsertSubMenuIntoSubMenu(IntPtr menu, IntPtr subMenu, string textName, int position)
        {
            MENUITEMINFO mii = new MENUITEMINFO();

            mii.cbSize     = (uint)Marshal.SizeOf(typeof(MENUITEMINFO));
            mii.fMask      = (uint)MIIM.ID | (uint)MIIM.STRING | (uint)MIIM.SUBMENU;
            mii.wID        = (uint)(mMenuCmdFirst + mMenuItemsAddedCount);
            mii.fType      = (uint)MF.STRING;
            mii.dwTypeData = textName;
            mii.cch        = 0;
            mii.fState     = (uint)MF.ENABLED;
            mii.hSubMenu   = subMenu;

            // Add it to the item
            if (DllImports.InsertMenuItem(menu, (uint)position, true, ref mii) == 0)
            {
                // failed
                return(0);
            }
            else
            {
                mMenuItemsAddedCount++;
                return(mii.wID);
            }
        }
Esempio n. 8
0
        public static void ToFullscreen()
        {
            IntPtr hConsole = DllImports.GetStdHandle(-11);               // get console handle

            DllImports.COORD xy = new DllImports.COORD(100, 100);
            DllImports.SetConsoleDisplayMode(hConsole, 1, out xy);
        }
Esempio n. 9
0
 public override unsafe void Push()
 {
     fixed(byte *p = _data)
     {
         DllImports.AddFont(p, _data.Length);
     }
 }
Esempio n. 10
0
        private static void Retarget(TypeDefinition type, DllImportMap map, DllImports imports)
        {
            foreach (var nested in type.NestedTypes)
            {
                Retarget(nested, map, imports);
            }

            foreach (MethodDefinition md in type.Methods)
            {
                if (!md.HasBody)
                {
                    continue;
                }

                for (int i = 0; i < md.Body.Instructions.Count; i++)
                {
                    Instruction ins = md.Body.Instructions[i];

                    if (ins.OpCode == OpCodes.Call)
                    {
                        MethodDefinition method_operand = ins.Operand as MethodDefinition;
                        if (method_operand == null)
                        {
                            continue;
                        }

                        PInvokeInfo pinfo = method_operand.PInvokeInfo;
                        if (pinfo == null)
                        {
                            continue;
                        }

                        ImportKey key = new ImportKey(pinfo.Module.Name, pinfo.EntryPoint);
                        if (imports.ContainsKey(key))
                        {
                            //Console.WriteLine ("{0} is a pinvoke, {1}/{2}", method_operand, pinfo.EntryPoint, pinfo.Module.Name);
                            if (map.ContainsKey(key))
                            {
                                Console.WriteLine("retargeting reference to method method {0}/{1}", key.module_name, key.entry_point);

                                var il = md.Body.GetILProcessor();
                                MethodDefinition mapped_method = map[key];
                                MethodReference  mapped_ref;

                                mapped_ref = type.Module.Import(mapped_method);

                                Instruction callMethod = il.Create(OpCodes.Call, mapped_ref);

                                il.Replace(ins, callMethod);
                            }
                            else
                            {
                                Console.WriteLine("WARNING: no map entry for method {0}/{1}", key.module_name, key.entry_point);
                            }
                        }
                    }
                }
            }
        }
Esempio n. 11
0
 public static void SetUp()
 {
     Console.OutputEncoding = System.Text.Encoding.Unicode;
     //DllImports.SetConsoleOutputCP(65001);
     DllImports.SetConsoleCP(65001);
     Console.SetWindowSize(Console.LargestWindowWidth, Console.LargestWindowHeight);
     DllImports.ShowWindow(DllImports.ThisConsole, DllImports.MAXIMIZE);
 }
        /// <summary>
        ///     Gets the desktop folder. Retrieves the IShellFolder interface for the desktop folder, which is the root of the
        ///     Shell's namespace.
        /// </summary>
        /// <returns>A Managed IShellFolder Object.</returns>
        public static IShellFolder GetDesktopFolder()
        {
            IShellFolder iShellFolder = null;
            IntPtr       pUnkownDesktopFolder;
            var          nResult = DllImports.SHGetDesktopFolder(out pUnkownDesktopFolder);

            return((IShellFolder)Marshal.GetTypedObjectForIUnknown(pUnkownDesktopFolder, typeof(IShellFolder)));
        }
        public new void Show(Control control, Point controlLocation)
        {
            // Prevents the context menu from causing the app to show in the taskbar
            DllImports.SetForegroundWindow(new HandleRef(this, Handle));

            Capture = true;
            base.Show(control, controlLocation);
        }
    /// Main App's Entry point
    public static void Main(string[] args)
    {
        IntPtr hConsole = DllImports.GetStdHandle(-11);           // get console handle

        DllImports.COORD xy = new DllImports.COORD(100, 100);
        DllImports.SetConsoleDisplayMode(hConsole, 1, out xy);         // set the console to fullscreen
        //SetConsoleDisplayMode(hConsole, 2);   // set the console to windowed
    }
Esempio n. 15
0
        public ShellRightClickContextMenuClass()
        {
            const int SM_CXMENUCHECK = 71;
            const int SM_CYMENUCHECK = 72;

            mBitmapCorrectWidth  = DllImports.GetSystemMetrics(SM_CXMENUCHECK);
            mBitmapCorrectHeight = DllImports.GetSystemMetrics(SM_CYMENUCHECK);
        }
Esempio n. 16
0
        static void SetFullscreen()
        {
            IntPtr consoleSession = DllImports.GetStdHandle(DllImports.CONSOLE); // get handle for current console session

            DllImports.SetConsoleDisplayMode(consoleSession, 1, out _);          // set the console to fullscreen
            // Note: 'out _' instantly disposes the out parameter. I only use the Coords struct in order to make the imported function work.
            Console.SetBufferSize(Console.BufferWidth, Console.BufferHeight);
        }
Esempio n. 17
0
        public static uint GetModifiers()
        {
            CfxEventFlags flags = CfxEventFlags.None;

            // triggered
            if ((DllImports.GetKeyState((int)Keys.CapsLock) & 65535) != 0)
            {
                flags |= CfxEventFlags.CapsLockOn;
            }
            if ((DllImports.GetKeyState((int)Keys.NumLock) & 65535) != 0)
            {
                flags |= CfxEventFlags.NumLockOn;
            }

            // down
            if ((DllImports.GetKeyState((int)Keys.LShiftKey) & 32768) == 32768)
            {
                flags |= CfxEventFlags.ShiftDown | CfxEventFlags.IsLeft;
            }
            if ((DllImports.GetKeyState((int)Keys.RShiftKey) & 32768) == 32768)
            {
                flags |= CfxEventFlags.ShiftDown | CfxEventFlags.IsRight;
            }

            if ((DllImports.GetKeyState((int)Keys.LControlKey) & 32768) == 32768)
            {
                flags |= CfxEventFlags.ControlDown | CfxEventFlags.IsLeft;
            }
            if ((DllImports.GetKeyState((int)Keys.RControlKey) & 32768) == 32768)
            {
                flags |= CfxEventFlags.ControlDown | CfxEventFlags.IsRight;
            }

            if ((DllImports.GetKeyState((int)Keys.LMenu) & 32768) == 32768)
            {
                flags |= CfxEventFlags.AltDown | CfxEventFlags.IsLeft;
            }
            if ((DllImports.GetKeyState((int)Keys.RMenu) & 32768) == 32768)
            {
                flags |= CfxEventFlags.AltDown | CfxEventFlags.IsRight;
            }

            if ((DllImports.GetKeyState((int)Keys.LButton) & 32768) == 32768)
            {
                flags |= CfxEventFlags.LeftMouseButton;
            }
            if ((DllImports.GetKeyState((int)Keys.MButton) & 32768) == 32768)
            {
                flags |= CfxEventFlags.MiddleMouseButton;
            }
            if ((DllImports.GetKeyState((int)Keys.RButton) & 32768) == 32768)
            {
                flags |= CfxEventFlags.RightMouseButton;
            }

            return((uint)flags);
        }
Esempio n. 18
0
        public static void FullScreenOn()
        {
            IntPtr      ThisConsole = DllImports.GetStdHandle(-11);
            Coordinates xy;

            DllImports.SetConsoleDisplayMode(ThisConsole, 1, out xy);

            Console.SetBufferSize(Console.WindowWidth, Console.WindowHeight + 1);
            Console.CursorVisible = false;
        }
Esempio n. 19
0
    private void Start()
    {
        int ret = DllImports.MSPLogin(null, null, loginParams);

        if (ErrorCode.MSP_SUCCESS != (ErrorCode)ret)
        {
            Utils.CustomPrint("MSPLogin failed, errCode=" + ((ErrorCode)ret).ToString("G"));
        }
        Utils.CustomPrint("+++MSPLogin");
    }
Esempio n. 20
0
    private void OnDisable()
    {
        int ret = DllImports.MSPLogout();

        if (ErrorCode.MSP_SUCCESS != (ErrorCode)ret)
        {
            Utils.CustomPrint("MSPLogout failed, errCode=" + ((ErrorCode)ret).ToString("G"));
        }
        Utils.CustomPrint("+++MSPLogout");
    }
Esempio n. 21
0
            public static void Main(string[] args)
            {
                /***************************************************************************************/
                IntPtr hConsole = DllImports.GetStdHandle(-11);   // get console handle

                DllImports.COORD xy = new DllImports.COORD(100, 100);
                DllImports.SetConsoleDisplayMode(hConsole, 1, out xy); // set the console to fullscreen
                //SetConsoleDisplayMode(hConsole, 2);   // set the console to windowed
                /***************************************************************************************/

                player     = new Player(136, 64);
                tabEnnemis = new Ennemi[15];

                tabEnnemis[nbEnnemiAfficher] = new Ennemi(76, 4);
                nbEnnemiAfficher++;
                bool finJeu = false;

                InitialiseGame(player);

                Timer timer = new Timer(UpdateTime, null, 0, 100);

                isEnnemiMoving = false;
                isPlayerMoving = false;

                Console.CursorVisible = false;

                while (!finJeu)
                {
                    player.oldPosX = player.posX;
                    player.oldPosY = player.posY;
                    for (int i = 0; i < nbEnnemiAfficher; i++)
                    {
                        tabEnnemis[i].oldPosX = tabEnnemis[i].posX;
                        tabEnnemis[i].oldPosY = tabEnnemis[i].posY;
                    }
                    UpdateVaisseau();
                    Update();
                    UpTire();
                    if (isPlayerMoving || isEnnemiMoving)
                    {
                        ClearVaisseau(player);
                        AfficherVaisseau(player);
                        //AfficherTireVaisseau(tire);
                        //ClearTireVaisseau(tire);
                        for (int i = 0; i < nbEnnemiAfficher; i++)
                        {
                            ClearEnnemi(tabEnnemis[i]);
                            AfficherEnnemi(tabEnnemis[i]);
                        }
                        isPlayerMoving = false;
                        isEnnemiMoving = false;
                        //isTireMoving = false;
                    }
                }
            }
Esempio n. 22
0
        /// <summary>
        /// Gets the index of the icon that best fits the current display device.
        /// </summary>
        /// <returns>The icon index.</returns>
        public int GetBestFitIconIndex()
        {
            int    iconIndex = 0;
            IntPtr resBits   = Marshal.AllocHGlobal(this.ResourceRawData.Length);

            Marshal.Copy(this.ResourceRawData, 0, resBits, this.ResourceRawData.Length);
            try { iconIndex = DllImports.LookupIconIdFromDirectory(resBits, true); }
            finally { Marshal.FreeHGlobal(resBits); }

            return(iconIndex);
        }
Esempio n. 23
0
    public static long GetAvailableFreeBytes(string drive)
    {
        long ignored;
        long userBytes;

        if (!DllImports.GetDiskFreeSpaceEx(drive, out userBytes, out ignored, out ignored))
        {
            throw new IOException("DriveName: " + drive + " ErrorCode:" + Marshal.GetLastWin32Error());
        }

        return(userBytes);
    }
Esempio n. 24
0
        private static void ShowContextMenuInternal(DirectoryInfo directory, Point pointScreen, IntPtr hwnd)
        {
            var pMenu            = IntPtr.Zero;
            var iContextMenuPtr  = IntPtr.Zero;
            var iContextMenuPtr2 = IntPtr.Zero;
            var iContextMenuPtr3 = IntPtr.Zero;

            try
            {
                var pidl = GetPidl(directory);
                if (directory.Parent != null && false == GetContextMenuInterfaces(GetParentFolder(directory.FullName), pidl, out iContextMenuPtr))
                {
                    ReleaseAll();
                    return;
                }
                pMenu = DllImports.CreatePopupMenu();
                _oContextMenu.QueryContextMenu(pMenu, 0, CmdFirst, CmdLast, Enums.Cmf.EXPLORE | Enums.Cmf.NORMAL | ((Control.ModifierKeys & Keys.Shift) != 0 ? Enums.Cmf.EXTENDEDVERBS : 0));
                Marshal.QueryInterface(iContextMenuPtr, ref _iidIContextMenu2, out iContextMenuPtr2);
                Marshal.QueryInterface(iContextMenuPtr, ref _iidIContextMenu3, out iContextMenuPtr3);
                _oContextMenu2 = (IContextMenu2)Marshal.GetTypedObjectForIUnknown(iContextMenuPtr2, typeof(IContextMenu2));
                _oContextMenu3 = (IContextMenu3)Marshal.GetTypedObjectForIUnknown(iContextMenuPtr3, typeof(IContextMenu3));
                var nSelected = DllImports.TrackPopupMenuEx(pMenu, Enums.Tpm.RETURNCMD, pointScreen.X, pointScreen.Y, hwnd, IntPtr.Zero);
                DllImports.DestroyMenu(pMenu);
                pMenu = IntPtr.Zero;
                if (nSelected != 0)
                {
                    InvokeCommand(_oContextMenu, nSelected, _strParentFolder, pointScreen);
                }
            }
            catch
            {
            }
            finally
            {
                if (pMenu != IntPtr.Zero)
                {
                    DllImports.DestroyMenu(pMenu);
                }
                if (iContextMenuPtr != IntPtr.Zero)
                {
                    Marshal.Release(iContextMenuPtr);
                }
                if (iContextMenuPtr2 != IntPtr.Zero)
                {
                    Marshal.Release(iContextMenuPtr2);
                }
                if (iContextMenuPtr3 != IntPtr.Zero)
                {
                    Marshal.Release(iContextMenuPtr3);
                }
                ReleaseAll();
            }
        }
Esempio n. 25
0
        private static void Retarget(AssemblyDefinition assembly, DllImportMap map, DllImports imports)
        {
            foreach (TypeDefinition t in assembly.MainModule.Types)
            {
                if (t.Name == "<Module>")
                {
                    continue;
                }

                Retarget(t, map, imports);
            }
        }
Esempio n. 26
0
 private static void ConfigureExitLogic()
 {
     if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
     {
         DllImports.SetConsoleCtrlHandler(ConsoleCtrlCheck, true);
     }
     else
     {
         Console.CancelKeyPress += CancelKeyPress;
         AppDomain.CurrentDomain.ProcessExit += ProcessExit;
     }
 }
Esempio n. 27
0
    private static bool IsReady(string drive)
    {
        const int ERROR_NOT_READY = 0x00000015;

        long ignored;

        if (!DllImports.GetDiskFreeSpaceEx(drive, out ignored, out ignored, out ignored))
        {
            return(Marshal.GetLastWin32Error() != ERROR_NOT_READY);
        }

        return(true);
    }
Esempio n. 28
0
 public override unsafe void Push()
 {
     fixed(byte *p = _image.Pixels)
     {
         DllImports.SetIcon(new DllImports.ImageData()
         {
             id     = (int)_type,
             pixels = p,
             width  = _image.Width,
             height = _image.Height
         });
     }
 }
Esempio n. 29
0
 public void ShowInSystemTray(Point screenLocation)
 {
     if (Visible)
     {
         this.Close(ToolStripDropDownCloseReason.AppFocusChange);
     }
     else
     {
         // Prevents the context menu from causing the app to show in the taskbar
         DllImports.SetForegroundWindow(new HandleRef(this, Handle));
         base.Show(screenLocation, ToolStripDropDownDirection.AboveLeft);
     }
 }
Esempio n. 30
0
        private bool SetMenuItemBitmapPrivate(IntPtr menuHandle, uint id, Bitmap uncheckBitmap, Bitmap checkedBitmap)
        {
            //	WinForms.MessageBox.Show( "Size: " + mBitmapCorrectWidth + "x" + mBitmapCorrectHeight );

            if (!DllImports.SetMenuItemBitmaps(menuHandle, id, ( uint )MF.BITMAP | (uint)MF.BYCOMMAND, uncheckBitmap != null ? uncheckBitmap.GetHbitmap() : IntPtr.Zero, checkedBitmap != null ? checkedBitmap.GetHbitmap() : IntPtr.Zero))
            {
                WinForms.MessageBox.Show("Message: " + (new System.ComponentModel.Win32Exception(Marshal.GetLastWin32Error())).Message);
                return(false);
            }
            else
            {
                return(true);
            }
        }