Results 1 to 2 of 2

Thread: C# Simba Plugins

  1. #1
    Join Date
    Dec 2006
    12 Post(s)
    98 Post(s)

    Default C# Simba Plugins

    Unsure where this should go, please move. Didn't see a tutorials section. Someone ended up asking about this so I decided to post it just in case.
    (EDIT: My bad, found it --

    Most of the magic that happens is in the NuGet package "DllExport." Due to the use of this package you will need to use Visual Studio to compile the project. If you read this far enough in the future feel free to try with the dotnet CLI.

    The clonable project is at In the interest of preserving information I reproduce the main file below. Besides adding the NuGet package DllExport to the project via the Visual Studio GUI you only need the one file.

    csharp Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Runtime.InteropServices;

    namespace SimbaPlugin
        public class Class1
            static int GetPluginABIVersion() { return 2; }
            static int GetFunctionCount() { return 2; }
            static int GetTypeCount() { return 0;  }

            //int GetFunctionInfo(int Index, void** Address, char** Definition)
            //int GetTypeInfo(int Index, char** Type, char** Definition)
            //void OnAttach(void *info)
            //void OnDetach()

            static string[] functionInfo =
                "AFunc", "procedure AFunc;",
                "Return0", "function Return0: Integer;"

            [DllImport("kernel32.dll", CharSet = CharSet.Auto)]
            public static extern IntPtr GetModuleHandle(string lpModuleName);
            [DllImport("kernel32", CharSet = CharSet.Ansi, ExactSpelling = true, SetLastError = true)]
            static extern IntPtr GetProcAddress(IntPtr hModule, string procName);

            // int GetFunctionInfo(int, void **, char **);
            static int GetFunctionInfo(int index, IntPtr address, IntPtr definition)
                IntPtr addr = GetProcAddress(GetModuleHandle("SimbaPlugin"), functionInfo[index * 2]);
                Marshal.WriteIntPtr(address, addr);

                // TODO: Cleaner way?
                IntPtr[] defin = { IntPtr.Zero };
                Marshal.Copy(definition, defin, 0, 1);
                byte[] raw = Encoding.ASCII.GetBytes(functionInfo[index * 2 + 1]);
                Marshal.Copy(raw, 0, defin[0], raw.Length);
                return index;

            static int GetTypeInfo(int index, IntPtr type, IntPtr definition) { return index; }

            [DllExport("OnAttach", CallingConvention.Cdecl)]
            static void OnAttach(IntPtr info) { }

            [DllExport("OnDetach", CallingConvention.Cdecl)]
            static void OnDetach() { }

            [DllExport("AFunc", CallingConvention.Cdecl)]
            static void AFunc() { }

            [DllExport("Return0", CallingConvention.Cdecl)]
            static int Return0() { return 0; }

    Drop it in the plugin folder.
    Last edited by R0b0t1; 03-13-2021 at 07:00 PM. Reason: Syntax highlighting
    The jealous temper of mankind, ever more disposed to censure than
    to praise the work of others, has constantly made the pursuit of new
    methods and systems no less perilous than the search after unknown
    lands and seas.

  2. #2
    Join Date
    Dec 2011
    East Coast, USA
    112 Post(s)
    1861 Post(s)


    Nice syntax highlighting man, rep+
    GitLab projects | Simba 1.4 | Find me on IRC or Discord | ScapeRune scripts | Come play bot ScapeRune!

    <BenLand100> we're just in the transitional phase where society reclassifies guns as Badâ„¢ before everyone gets laser pistols

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts