Skip to content

Instantly share code, notes, and snippets.

@NotAdam
Last active January 16, 2021 12:34
Show Gist options
  • Save NotAdam/9eec6fb2aa200108d0d8da7ec84c1e4e to your computer and use it in GitHub Desktop.
Save NotAdam/9eec6fb2aa200108d0d8da7ec84c1e4e to your computer and use it in GitHub Desktop.
An example dalamud plugin made using MSIL
.module ILTestPlugin.dll
.corflags 1 // ILOnly
// deps
.assembly extern mscorlib
{
.ver 2:0:0:0
}
// dalamud shits
.assembly extern Dalamud
{
.ver 5:2:2:0
}
.assembly extern ImGui.NET
{
.ver 1:72:0:0
}
.assembly extern ImGuiScene
{
.ver 1:0:0:0
}
.assembly ILTestPlugin
{
.ver 1:0:0:0
}
// TestPlugin
.class public auto ansi beforefieldinit ILTestPlugin
extends [mscorlib]System.Object
implements [Dalamud]Dalamud.Plugin.IDalamudPlugin
{
// init func
.method public final hidebysig newslot virtual
instance void Initialize(
class [Dalamud]Dalamud.Plugin.DalamudPluginInterface pluginInterface
) cil managed
{
.maxstack 8
// grab the ui builder instance
ldarg.1
ldfld class [Dalamud]Dalamud.Interface.UiBuilder [Dalamud]Dalamud.Plugin.DalamudPluginInterface::UiBuilder
// grab the ptr to the draw func
ldarg.0
ldftn instance void ILTestPlugin::DrawTest()
// create the delegate with the function ptr and object instance
newobj instance void [ImGuiScene]ImGuiScene.RawDX11Scene/BuildUIDelegate::.ctor(object, native int)
// add the delegate to the list
callvirt instance void [Dalamud]Dalamud.Interface.UiBuilder::add_OnBuildUi(class [ImGuiScene]ImGuiScene.RawDX11Scene/BuildUIDelegate)
ret
}
// get name property
.property instance string Name()
{
.get instance string ILTestPlugin::get_Name()
}
.method public final hidebysig specialname newslot virtual
instance string get_Name() cil managed
{
.maxstack 8
ldstr "ILTestPlugin"
ret
}
// draw ui shit
.method public hidebysig
instance void DrawTest() cil managed
{
.maxstack 8
ldstr "test window"
call bool [ImGui.NET]ImGuiNET.ImGui::Begin(string)
// need to pop otherwise you send 2 args to the text function which only takes 1 string param
pop
ldstr "hello from il plugin :))))"
call void [ImGui.NET]ImGuiNET.ImGui::Text(string)
call void [ImGui.NET]ImGuiNET.ImGui::End()
ret
}
// required dispose func
.method public final hidebysig newslot virtual
instance void Dispose() cil managed
{
.maxstack 8
ret
}
.method public hidebysig specialname rtspecialname
instance void .ctor() cil managed
{
.maxstack 8
ldarg.0
call instance void [mscorlib]System.Object::.ctor()
ret
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment