justinstenning / Direct3DHook

DirectX Capture and Overlays by using Direct3D API hooks
http://spazzarama.com/2011/03/14/c-screen-capture-and-overlays-for-direct3d-9-10-and-11-using-api-hooks
MIT License
582 stars 176 forks source link

I added a new class to Capture.Hook.common but getting exception Index was outside the bounds of the array why ? #26

Closed Csharper1972 closed 9 years ago

Csharper1972 commented 9 years ago

Let me explain. In the class DXHookD3D11.cs there is a line that write to the screen the frames per second.

new Capture.Hook.Common.FramesPerSecond(new System.Drawing.Font("Arial", 16)) { Location = new System.Drawing.Point(5,5), Color = System.Drawing.Color.Red, AntiAliased = true },

I created inside Capture.Hook.Common a new class called it TimeRunning this is the class code:

using System; using System.Collections.Generic; using System.Linq; using System.Text;

namespace Capture.Hook.Common { public class TimeRunning : TextElement { DateTime _startTime = DateTime.Now; TimeSpan RunTime;

    string _fpsFormat = "{0:c} fps";
    public override string Texts
    {
        get
        {
            return String.Format(_fpsFormat, GetFPS());
        }
        set
        {
            _fpsFormat = value;
        }
    }

    int _frames = 0;
    int _lastTickCount = 0;
    float _lastFrameRate = 0;

    public TimeRunning(System.Drawing.Font font)
        : base(font)
    {
    }

    public override void Frame()
    {
        RunTime = DateTime.Now - _startTime;
    }

    public TimeSpan GetFPS()//float GetFPS()
    {
        return RunTime;//_lastFrameRate;
    }
}

}

Then in the DXHookD3D11.cs inside the Elements = Under the line with the FramesPerSecond:

new Capture.Hook.Common.TimeRunning(new System.Drawing.Font("Arial", 16)) { Location = new System.Drawing.Point(5,30), Color = System.Drawing.Color.Red, AntiAliased = true }

So now it look like this:

_overlayEngine.Overlays.Add(new Capture.Hook.Common.Overlay { Elements = { new Capture.Hook.Common.FramesPerSecond(new System.Drawing.Font("Arial", 16)) { Location = new System.Drawing.Point(5,5), Color = System.Drawing.Color.Red, AntiAliased = true }, new Capture.Hook.Common.TimeRunning(new System.Drawing.Font("Arial", 16)) { Location = new System.Drawing.Point(5,30), Color = System.Drawing.Color.Red, AntiAliased = true } } });

But when running the program and inject to a game i'm getting this exception:

Debug: DXHookD3D11: PresentHook: Exeception: System.IndexOutOfRangeException: System.IndexOutOfRangeException: Index was outside the bounds of the array. at Capture.Hook.DX11.DXFont.GetCharRect(Char c) in c:\Temp\hook\Direct3DHook-master\Capture\Hook\DX11\DXFont.cs:line 251 at Capture.Hook.DX11.DXSprite.DrawString(Int32 X, Int32 Y, String text, Int32 R, Int32 G, Int32 B, Int32 A, DXFont F) in c:\Temp\hook\Direct3DHook-master\Capture\Hook\DX11\DXSprite.cs:line 258 at Capture.Hook.DX11.DXOverlayEngine.Draw() in c:\Temp\hook\Direct3DHook-master\Capture\Hook\DX11\DXOverlayEngine.cs:line 145 at Capture.Hook.DXHookD3D11.PresentHook(IntPtr swapChainPtr, Int32 syncInterval, PresentFlags flags) in c:\Temp\hook\Direct3DHook-master\Capture\Hook\DXHookD3D11.cs:line 401

How can i fix it ? I want that the TimeRunning will be display on screen under the FramesPerSecond.

justinstenning commented 9 years ago

Can you include an example of what the value of the property "Texts" is please? From memory I think this is an issue with the specified character not existing within the generated font texture.

justinstenning commented 9 years ago

The other issue could have been related to the SharpDX version (change in Rectangle struct / constructor). Problem isn't occurring currently in my tests so closing this issue unless further input provided.