• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[Advanced] CLI injection in WE using Grimoire

Status
Not open for further replies.
Level 5
Joined
Jun 5, 2007
Messages
73
EDIT: Total revamp of the old post since it's all obsolete by the new version.

I've created a couple of loaders that makes it possible to inject .NET assemblies into the World Editor using Grimoire.

This works by injecting a native win32 library which loads the "CLI loader" that in turn loads your .NET assembly.
The reason why we need two loaders is simple. A .NET assembly doesn't have any entry-points. Grimoire can inject it, but it won't execute since the system doesn't know which function to call. The PELoader calls the "load" function in the CLILoader, which in turn loads every assembly it can find that implements the IWePlugin interface. The second loader eliminates the need for exports in the target assembly, since CLI-assemblies doesn't export any functions by default.

UPDATE: A plugin architecture has been implemented (thanks to BlacKDicK @ Wc3Campaigns). This approach requires your plugin to inherit the IWePlugin interface (by referencing Shared.dll). I guess plugin-creation has never been easier.. Below is a short example (also included in the archive).

(pluginTest.dll)
Code:
using System;
using System.Collections.Generic;
using System.Text;
using Shared;
using System.Windows.Forms;

namespace pluginTest
{
    public class MyCoolPlugin : IWePlugin
    {
        private Version version;
        private String author;
        private IWeNotify notifier;
        public String PluginAuthor { get { return author; } }
        public Version PluginVersion { get { return version; } }
        public IWeNotify Notifier { get { return notifier; } }

        public MyCoolPlugin()
        {
            //set some properties
            author = "Risc";
            version = new Version("1.0");
        }

        public IWeNotify RegisterNotify()
        {
            notifier = new PluginNotifier();
            notifier.OnRegisterPlugin += new delegateRegisterPlugin(notifier_OnRegisterPlugin);
            notifier.WindowCreated += new delegateWindowCreated(notifier_WindowCreated);
            //the return-type is reserved for further use.
            return notifier;
        }

        void notifier_WindowCreated(string className, string windowText, IntPtr hWnd)
        {
            if(windowText == "About Warcraft III World Editor UMS")
                MessageBox.Show("Cool");
        }

        void notifier_OnRegisterPlugin()
        {
            MessageBox.Show("Hello WorldEdit!");
        }
    }
}

To use the PELoader, you'll need to reference it in "we.conf.lua":
Code:
-- CLILoader
loaddll("bin\\PELoader.dll")

CLILoader.dll, PELoader.dll and all plugins that should be loaded must reside inside Grimoire's bin-folder.
Shared.dll needs to reside in your Warcraft III folder (due to pathing).

Please submit any bugs/suggestions you can find.
Happy coding!

//Risc
 

Attachments

  • CLILoader2.0.rar
    22.5 KB · Views: 53
Last edited:
Status
Not open for further replies.
Top