Click here to Skip to main content
15,860,861 members
Articles / Desktop Programming / Win32
Article

Overlay using raphook.dll

Rate me:
Please Sign up or sign in to vote.
4.00/5 (3 votes)
21 Sep 2008CPOL2 min read 41K   1.4K   12   5
A OverlayMgr based on Ray Adam's raphook.dll
osdmgr_src

Introduction

The Overlay Mgr, as seen above, is a managed wrapper around the raphook.dll by Ray Adam's (ATI Tray Tools), which supports overlays in D3D and OpenGL. The application simply makes it possible to use your own plugins and display your own numbers/strings in the overlay, which was not possible on Nvidia Cards before.

s1EAB70.jpg

Background

Some of you might know my previous article about Overlay Tools. Those worked fine with my ATI card, but since I now got a Nvidia card it won't even create the overlay (DirectDraw = deprecated).  

Therefore I looked quite some time for an alternative, but haven't found anything satisfying. So I decided to go with the overlay DLL provided in ATI Tray Tools/NVTray.

Using the Code

The program is divided into three parts.

I. OverlayWrapper

The Overlay Wrapper library is a native wrapper around the raphook.dll (which seems to only support 32-bit Windows by the way) and provides the basic methods for showing/hiding the overlay, as well as editing the data shown.

The data, which can be set in the Overlay.Data property, is transferred towards the raphook.dll via shared memory/file mapping.

As the library is based upon the raphook library, it is quite limited, but should be enough for the standard needs:

C#
[Flags]
public enum eItems {
	GPUClock = 1,
	MemClock = 2,
	GPUTemp = 4,
	EnvTemp = 8,
	FanSpeed = 16,
	FTM = 32,
	RenderAPI = 64,
	SMU = 128,
	FVM = 256,
	CustomString = 1024
}

II. OverlayMgr

The Overlay Manager, the main program, uses the wrapper to display the plugins selected. The plugins are loaded via reflection (all DLLs in the plugins folder are checked):

C#
/// <summary>
/// Load Plugins
/// </summary>
public static void LoadPlugins() {
    if (!Directory.Exists("plugins"))
        Directory.CreateDirectory("plugins");

    Evidence ev = new Evidence();
    ev.AddAssembly(typeof (MainForm).Assembly);
    ev.AddAssembly(typeof (Overlay).Assembly);

    foreach (string pl in Directory.GetFiles("plugins", "*.dll", 
         SearchOption.TopDirectoryOnly)) {
        try {
            Assembly a = Assembly.LoadFile(Path.GetFullPath(pl), ev);
 
            foreach (Type t in a.GetExportedTypes()) {
                if (typeof (IPlugin).IsAssignableFrom(t) && !t.IsAbstract) {
                    IPlugin plugin;

                    string data = Path.GetDirectoryName(pl) + "\\" + 
                    Path.GetFileNameWithoutExtension(pl) + ".cfg";
                    if (t.IsSerializable && File.Exists(data)) {
                        using (FileStream fs = new FileStream
                        (data, FileMode.Open, FileAccess.Read)) {
                            BinaryFormatter bf = new BinaryFormatter();
                            bf.Binder = new FixedBinder();
                            plugin = (IPlugin) bf.Deserialize(fs);
                        }
                    }
                    else plugin = (IPlugin) Activator.CreateInstance(t);
         
                    m_Plugins.Add(plugin);

                    if (plugin.Active)
                    plugin.Load();
                } 
            }
        }
        catch (Exception e) {
            Console.WriteLine(e);
            continue;
        }
    }
} 

When writing that part of the code, I had to decide how I was going to save the settings of the individual plugins. I decided to go with standard serialization and therefore just serialize the whole IPlugin implementation of the plugin, which means that every plugin should be tagged with the [Serializable] attribute.

III. Plugins

The plugin system is quite easy: You just have to implement the IPlugin interface and put your stuff there (obvious, heh?). The interface consists of these basic methods:

C#
public interface IPlugin {
    string Name { get; }
    string Description { get; }
    bool Active { get; set; }
    bool Load();
    bool Unload();
    void ShowConfig();
    void Tick();
}

The Time plugin for the example (which is really simple) just appends the current time to the Overlay.Data.CustomString property on every Tick(); meaning that writing your own plugins shouldn't be really hard.

Advantages/Disadvantages

The main advantage of this approach is that you don't really have to bother about hooking, drivers and different manufacturers when doing everything yourself/using DirectDraw. But there is also a major disadvantage: You are quite limited in what you can do; in the end you are constrained to raphook.dll, which only supports "one" string and some numbers; so you cannot draw real images (unless you are good in one-line ASCII arts;)).

But all in all, I would say that this overlay should be enough for most purposes, especially for those people who only want to display some small data while playing games.

History

  • 21st September, 2008: Initial post

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Comments and Discussions

 
Questioncan't compile Pin
Member 99531701-Oct-14 18:18
Member 99531701-Oct-14 18:18 
GeneralDelay issue Pin
John Mautari17-May-10 18:46
John Mautari17-May-10 18:46 
GeneralDirectX Wrapper Pin
nordhaus22-Sep-08 8:35
nordhaus22-Sep-08 8:35 
GeneralRe: DirectX Wrapper Pin
Anton Afanasyev22-Sep-08 16:40
Anton Afanasyev22-Sep-08 16:40 
GeneralRe: DirectX Wrapper Pin
User 273912123-Sep-08 9:21
User 273912123-Sep-08 9:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.