Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Overlay using raphook.dll

0.00/5 (No votes)
21 Sep 2008 1  
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:

[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):

/// <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:

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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here