Beispiel #1
0
        public InterfaceManager(Dalamud dalamud, SigScanner scanner)
        {
            this.dalamud = dalamud;

            try {
                var sigResolver = new SwapChainSigResolver();
                sigResolver.Setup(scanner);

                Log.Verbose("Found SwapChain via signatures.");

                Address = sigResolver;
            } catch (Exception ex) {
                // The SigScanner method fails on wine/proton since DXGI is not a real DLL. We fall back to vtable to detect our Present function address.
                Log.Debug(ex, "Could not get SwapChain address via sig method, falling back to vtable...");

                var vtableResolver = new SwapChainVtableResolver();
                vtableResolver.Setup(scanner);

                Log.Verbose("Found SwapChain via vtable.");

                Address = vtableResolver;
            }

            try {
                var rtss = NativeFunctions.GetModuleHandle("RTSSHooks64.dll");

                if (rtss != IntPtr.Zero)
                {
                    var fileName = new StringBuilder(255);
                    NativeFunctions.GetModuleFileName(rtss, fileName, fileName.Capacity);
                    this.rtssPath = fileName.ToString();
                    Log.Verbose("RTSS at {0}", this.rtssPath);

                    if (!NativeFunctions.FreeLibrary(rtss))
                    {
                        throw new Win32Exception();
                    }
                }
            } catch (Exception e) {
                Log.Error(e, "RTSS Free failed");
            }


            var setCursorAddr = LocalHook.GetProcAddress("user32.dll", "SetCursor");

            Log.Verbose("===== S W A P C H A I N =====");
            Log.Verbose("SetCursor address {SetCursor}", setCursorAddr);
            Log.Verbose("Present address {Present}", Address.Present);
            Log.Verbose("ResizeBuffers address {ResizeBuffers}", Address.ResizeBuffers);

            this.setCursorHook = new Hook <SetCursorDelegate>(setCursorAddr, new SetCursorDelegate(SetCursorDetour), this);

            this.presentHook =
                new Hook <PresentDelegate>(Address.Present,
                                           new PresentDelegate(PresentDetour),
                                           this);

            this.resizeBuffersHook =
                new Hook <ResizeBuffersDelegate>(Address.ResizeBuffers,
                                                 new ResizeBuffersDelegate(ResizeBuffersDetour),
                                                 this);
        }