try
{
Assembly assembly = Assembly.LoadFile(loadfilename);
- instance.PluginManager.LoadAssembly(loadfilename, assembly);
+ instance.PluginManager.LoadAssembly(loadfilename, assembly, true);
}
catch (Exception ex)
{
using System.Linq;
using System.Text;
using System.IO;
+using System.Threading;
using System.Reflection;
+using System.CodeDom.Compiler;
using System.Windows.Forms;
using OpenMetaverse;
+using Microsoft.CSharp;
namespace Radegast
{
}
}
+ public void LoadCSharpScriptFile(string filename)
+ {
+ try { LoadCSharpScript(File.ReadAllText(filename)); }
+ catch (Exception ex)
+ {
+ Logger.Log("Failed loading C# script " + filename + ": ", Helpers.LogLevel.Warning, ex);
+ }
+ }
+
+ public void LoadCSharpScript(string code)
+ {
+ ThreadPool.QueueUserWorkItem(sender =>
+ {
+ try
+ {
+ // *** Generate dynamic compiler
+ Dictionary<string, string> loCompilerOptions = new Dictionary<string, string>();
+ loCompilerOptions.Add("CompilerVersion", "v3.5");
+ CSharpCodeProvider loCompiler = new CSharpCodeProvider(loCompilerOptions);
+ CompilerParameters loParameters = new CompilerParameters();
+
+ // *** Start by adding any referenced assemblies
+ loParameters.ReferencedAssemblies.Add("OpenMetaverse.StructuredData.dll");
+ loParameters.ReferencedAssemblies.Add("OpenMetaverseTypes.dll");
+ loParameters.ReferencedAssemblies.Add("OpenMetaverse.dll");
+ loParameters.ReferencedAssemblies.Add("Radegast.exe");
+ loParameters.ReferencedAssemblies.Add("System.dll");
+ loParameters.ReferencedAssemblies.Add("System.Core.dll");
+ loParameters.ReferencedAssemblies.Add("System.Drawing.dll");
+ loParameters.ReferencedAssemblies.Add("System.Windows.Forms.dll");
+
+ // *** Load the resulting assembly into memory
+ loParameters.GenerateInMemory = true;
+ loParameters.GenerateExecutable = false;
+
+ // *** Now compile the whole thing
+ CompilerResults loCompiled =
+ loCompiler.CompileAssemblyFromSource(loParameters, code);
+
+ // *** Check for compilation erros
+ if (loCompiled.Errors.HasErrors)
+ {
+ string lcErrorMsg = "";
+ lcErrorMsg = "Compilation failed: " + loCompiled.Errors.Count.ToString() + " errors:";
+
+ for (int x = 0; x < loCompiled.Errors.Count; x++)
+ lcErrorMsg += "\r\nLine: " +
+ loCompiled.Errors[x].Line.ToString() + " - " +
+ loCompiled.Errors[x].ErrorText;
+
+ instance.TabConsole.DisplayNotificationInChat(lcErrorMsg, ChatBufferTextStyle.Alert);
+ return;
+ }
+
+ instance.TabConsole.DisplayNotificationInChat("Compilation successful.");
+ Assembly loAssembly = loCompiled.CompiledAssembly;
+ instance.MainForm.Invoke(new MethodInvoker(() => LoadAssembly("Dynamically compiled", loAssembly, true)));
+ }
+ catch (Exception ex)
+ {
+ Logger.Log("Failed loading C# script: ", Helpers.LogLevel.Warning, ex);
+ }
+ });
+ }
+
public void LoadAssembly(string loadfilename, Assembly assembly)
{
+ LoadAssembly(loadfilename, assembly, false);
+ }
+
+ public void LoadAssembly(string loadfilename, Assembly assembly, bool startPlugins)
+ {
foreach (Type type in assembly.GetTypes())
{
if (typeof(IRadegastPlugin).IsAssignableFrom(type))
if (type.IsInterface) continue;
try
{
- IRadegastPlugin plug;
+ IRadegastPlugin plug = null;
ConstructorInfo constructorInfo = type.GetConstructor(new Type[] { typeof(RadegastInstance) });
if (constructorInfo != null)
- plug = (IRadegastPlugin)constructorInfo.Invoke(new[] { this });
+ plug = (IRadegastPlugin)constructorInfo.Invoke(new[] { instance });
else
{
constructorInfo = type.GetConstructor(new Type[] { });
}
}
lock (PluginsLoaded) PluginsLoaded.Add(plug);
+ if (startPlugins && plug != null)
+ {
+ plug.StartPlugin(instance);
+ }
}
catch (Exception ex)
{
client.Groups.GroupDropped += new EventHandler<GroupDroppedEventArgs>(Groups_GroupsChanged);
client.Groups.GroupJoinedReply += new EventHandler<GroupOperationEventArgs>(Groups_GroupsChanged);
client.Avatars.UUIDNameReply += new EventHandler<UUIDNameReplyEventArgs>(Avatars_UUIDNameReply);
- netcom.ClientConnected += new EventHandler<EventArgs>(netcom_ClientConnected);
+ if (netcom != null)
+ netcom.ClientConnected += new EventHandler<EventArgs>(netcom_ClientConnected);
}
private void UnregisterClientEvents(GridClient client)
client.Groups.GroupDropped -= new EventHandler<GroupDroppedEventArgs>(Groups_GroupsChanged);
client.Groups.GroupJoinedReply -= new EventHandler<GroupOperationEventArgs>(Groups_GroupsChanged);
client.Avatars.UUIDNameReply -= new EventHandler<UUIDNameReplyEventArgs>(Avatars_UUIDNameReply);
- netcom.ClientConnected -= new EventHandler<EventArgs>(netcom_ClientConnected);
+ if (netcom != null)
+ netcom.ClientConnected -= new EventHandler<EventArgs>(netcom_ClientConnected);
}
public void Reconnect()
this.homeToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.autopilotToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.cleanCacheToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
+ this.reloadInventoryToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.setAppearanceToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.rebakeTexturesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.tbnPlugins = new System.Windows.Forms.ToolStripDropDownButton();
+ this.btnLoadScript = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator();
this.tbtnFriends = new System.Windows.Forms.ToolStripButton();
this.tbtnGroups = new System.Windows.Forms.ToolStripButton();
this.toolStripContainer1 = new System.Windows.Forms.ToolStripContainer();
this.pnlDialog = new System.Windows.Forms.Panel();
this.timerWorldClock = new System.Windows.Forms.Timer(this.components);
- this.reloadInventoryToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.toolStrip1.SuspendLayout();
this.statusStrip1.SuspendLayout();
this.toolStripContainer1.TopToolStripPanel.SuspendLayout();
this.cleanCacheToolStripMenuItem.Text = "Clean Cache";
this.cleanCacheToolStripMenuItem.Click += new System.EventHandler(this.cleanCacheToolStripMenuItem_Click);
//
+ // reloadInventoryToolStripMenuItem
+ //
+ this.reloadInventoryToolStripMenuItem.Name = "reloadInventoryToolStripMenuItem";
+ this.reloadInventoryToolStripMenuItem.Size = new System.Drawing.Size(163, 22);
+ this.reloadInventoryToolStripMenuItem.Text = "Reload Inventory";
+ this.reloadInventoryToolStripMenuItem.Click += new System.EventHandler(this.reloadInventoryToolStripMenuItem_Click);
+ //
// setAppearanceToolStripMenuItem
//
this.setAppearanceToolStripMenuItem.Name = "setAppearanceToolStripMenuItem";
// tbnPlugins
//
this.tbnPlugins.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text;
+ this.tbnPlugins.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
+ this.btnLoadScript});
this.tbnPlugins.Image = ((System.Drawing.Image)(resources.GetObject("tbnPlugins.Image")));
this.tbnPlugins.ImageTransparentColor = System.Drawing.Color.Magenta;
this.tbnPlugins.Name = "tbnPlugins";
this.tbnPlugins.Size = new System.Drawing.Size(59, 22);
this.tbnPlugins.Text = "&Plugins";
- this.tbnPlugins.Visible = false;
+ //
+ // btnLoadScript
+ //
+ this.btnLoadScript.Name = "btnLoadScript";
+ this.btnLoadScript.Size = new System.Drawing.Size(160, 22);
+ this.btnLoadScript.Text = "Load C# Script...";
+ this.btnLoadScript.Visible = false;
+ this.btnLoadScript.Click += new System.EventHandler(this.btnLoadScript_Click);
//
// toolStripSeparator1
//
this.timerWorldClock.Interval = 1000;
this.timerWorldClock.Tick += new System.EventHandler(this.timerWorldClock_Tick);
//
- // reloadInventoryToolStripMenuItem
- //
- this.reloadInventoryToolStripMenuItem.Name = "reloadInventoryToolStripMenuItem";
- this.reloadInventoryToolStripMenuItem.Size = new System.Drawing.Size(163, 22);
- this.reloadInventoryToolStripMenuItem.Text = "Reload Inventory";
- this.reloadInventoryToolStripMenuItem.Click += new System.EventHandler(this.reloadInventoryToolStripMenuItem_Click);
- //
// frmMain
//
this.AutoSavePosition = true;
private System.Windows.Forms.ToolStripButton tbtnVoice;
public System.Windows.Forms.ToolStripMenuItem testToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem reloadInventoryToolStripMenuItem;
+ private System.Windows.Forms.ToolStripMenuItem btnLoadScript;
}
}
void frmMain_Disposed(object sender, EventArgs e)
{
- netcom.NetcomSync = null;
- netcom.ClientLoginStatus -= new EventHandler<LoginProgressEventArgs>(netcom_ClientLoginStatus);
- netcom.ClientLoggedOut -= new EventHandler(netcom_ClientLoggedOut);
- netcom.ClientDisconnected -= new EventHandler<DisconnectedEventArgs>(netcom_ClientDisconnected);
- UnregisterClientEvents(client);
+ if (netcom != null)
+ {
+ netcom.NetcomSync = null;
+ netcom.ClientLoginStatus -= new EventHandler<LoginProgressEventArgs>(netcom_ClientLoginStatus);
+ netcom.ClientLoggedOut -= new EventHandler(netcom_ClientLoggedOut);
+ netcom.ClientDisconnected -= new EventHandler<DisconnectedEventArgs>(netcom_ClientDisconnected);
+ }
+ if (client != null)
+ {
+ UnregisterClientEvents(client);
+ }
this.instance.CleanUp();
}
#endregion
}
}
+ private void btnLoadScript_Click(object sender, EventArgs e)
+ {
+ //instance.PluginManager.LoadCSharpScriptFile("DemoPlugin.cs");
+ }
#endregion
}
}
\ No newline at end of file
//
using System;
using System.Collections.Generic;
-using System.Linq;
using System.Text;
using System.Threading;
using System.Windows.Forms;