• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Simply Jarvis

C# DLL Plugin System, I want some input.

7 posts in this topic

So earlier today I saw the needs for a dll plugin system and coded one.  There is a API.dll and a Default.dll along with my Program.exe

 

Plugins/Default.dll

API.dll

Program.exe

 

My question is whats the best way to go about this ?  I want Program.exe to have the same types in API.dll but if I put those types in Program.exe and reference it from API.dll I would be able to explicity add the classes from 'Default.dll' via Assembly into Program.exe via static calls.  But then I would need to re-define the type in API.dll which wouldnt be to hard as I can just reference the ones already in Program.exe

So whats your thoughts and opinions on this one ?

 

 

0

Share this post


Link to post
Share on other sites

Thanks for the reply "PhillipHamlyn" but I can already load the classes and such within the plugins into my program so there is no need for external libraries, I simply want some input regarding how I should have the structure.

 

Example:

API.dll references Program.exe

Default.dll references API.dll

Program.exe loads all 'Plugins/*.dll' and pulls the classes from the plugins storing there types.

Program.exe then when in need of using the plugin types does "IMyPluginBaseType TheCreatedClass = (IMyPluginBaseType) Assembly.CreateInstance( Type.FullName );"

I store the data as such, Dictionary<String,Type>;  The string being a unique id generated when the type is parsed from the dll.

 

Currently I have Program.exe and Default.dll referencing API.dll as it's the easier meens of doing things.

Edited by Simply Jarvis
0

Share this post


Link to post
Share on other sites

Oh, I see.

 

If its a true plugin, the Program should not know about the Types inside the plugin - it should only share a set of Types (probably only Interfaces) made available for the plugin to consume, so for each plugin, as you say, there is only one Type you care about (which is the name of the Type implementing the Plugin interface). I'd probably parse the plugin assembly using reflection and pick up the class implementing the plugin Interface and instantiate it using CreateInstance as you suggest. Where is the need for Program to store the Types in the plugin ? I think I'm missing something ?

 

Philip

0

Share this post


Link to post
Share on other sites

Well thats actually how I am doing things, as  for the types that get loaded into the program they get parsed by a static class in my Main file.  It grabs all the types from the plugins that implement classes or interfaces within API.dll So the types that implement ANY class in API.dll get added to a list for usage later in my program.

 

My main reason for posting this thread was to get input on how I should go about this and it would seem given your response that the way I've been planing to do it would indeed by recommended by you.

0

Share this post


Link to post
Share on other sites

Sounds a lot like a thread I wrote ages ago? Would you be looking for this:

http://nccastaff.bournemouth.ac.uk/jmacey/RobTheBloke/www/CSPluginExample2.zip

 

I actually ported that to the latest .NET framework the other day. The code more or less still works (although I had to create new project files because for some unknown reason I couldn't get the project files to upgrade successfully - and couldn't be bothered to find out why). If you want to avoid the compiler warnings, modify the code like so:

 

[source]

    public static bool ExecuteVB(string source)
    {
        VBCodeProvider prov = new VBCodeProvider();
        return ExecuteScript(prov, source);
    }
    public static bool ExecuteCS(string source)
    {
        CSharpCodeProvider prov = new CSharpCodeProvider();
        return ExecuteScript(prov, source);
    }
 
    private static bool ExecuteScript(CodeDomProvider compiler, string code)
    {
        CompilerParameters cp = new CompilerParameters();
        cp.GenerateExecutable = false;
        cp.GenerateInMemory = true;
 
        //
        // add any default libs you want to expose to the scripting API
        //
        cp.ReferencedAssemblies.Add("system.dll");
        cp.ReferencedAssemblies.Add("system.data.dll");
        cp.ReferencedAssemblies.Add("system.drawing.dll");
        cp.ReferencedAssemblies.Add("system.windows.forms.dll");
 
        //
        // add reference to the core dll(s) of the application. The scripts
        // will then be able to access the core functionality of the APP.
        //
        cp.ReferencedAssemblies.Add("CoreAPI.dll");
 
        CompilerResults cr;
        cr = compiler.CompileAssemblyFromSource(cp, code);
 
        // check for any errors in the script
        if (cr.Errors.HasErrors)
        {
            StringBuilder sbErr;
            sbErr = new StringBuilder();
            foreach (CompilerError err in cr.Errors)
            {
                sbErr.AppendFormat("{0} at line {1} column {2} ",
                     err.ErrorText,
                     err.Line,
                     err.Column);
                sbErr.Append("\n");
            }
            MessageBox.Show(sbErr.ToString(), "Script - Error");
            return false;
        }
 
        // get the assembly code generated
        Assembly a = cr.CompiledAssembly;
        try
        {
            return InvokeAssembly(a);
        }
        catch (Exception ex)
        {
            // this is called if an error gets generated when running the script
            MessageBox.Show(ex.Message);
        }
        return false;
    }
[/source]

The basic premise is that you define the base types in the API.dll, load the plugin assembly, and then use reflection to hunt for any classes in the plugin that support any of your supported interfaces. It's probably easier to do this with interfaces rather than base classes!

 

\edit

 

Found the original thread: http://www.gamedev.net/topic/473195-saveload-as-plugin/

Edited by RobTheBloke
0

Share this post


Link to post
Share on other sites

I already have what I was looking for...  But anyway that is very intresting code non the less, though I don't currently have use for it.

0

Share this post


Link to post
Share on other sites

For everyone interested, here is the article (from GameDev) that taught me how to build plugin systems over 10 years ago:

 

http://www.gamedev.net/page/resources/_/technical/multiplayer-and-network-programming/why-pluggable-factories-rock-my-multiplayer-world-r841

 

it is a very helpful article and I have used its core ideas a dozen times since (the implementation details vary by language - but the core concept of derived types "registering" themselves is the key).

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0