Load scripts from a library
This isn't very consequential for server performance (except a slightly faster boot up). However it's very handy if your server is on a remote machine. Here's how it works:
The server should be installed as usual, but the Scripts folder should be deleted (well it can be left where it is, it doesn't really matter). This mod will load all scripts from a file called Scripts.dll that the server expects to find in the executable directory. (I didn't add support for VB scripts since it seems no one uses those).
Whenever you wish to update the scripts, place the new Scripts.dll you wish to use in a folder called "Update" within the server directory. Here's an example structure:
(1) C:\RunUO\Server.exe
(2) C:\RunUO\Scripts.dll
(3) C:\RunUO\Update\Scripts.dll
When the server starts it will first look for the file (3) and if present it will delete (2) and then move (3) inside the base directory. And then load it up.
The mod is very simple and takes place in the Compile( bool debug ) method in the file \ScriptCompiler.cs. Here's the new method:
Note on debug mode: I'm exepcting no one will run the server in debug mode on a production shard. For local testing purposes you can just have your IDE output Scripts.dll and Scripts.pdb into the Server.exe folder, which will automatically enable debug mode.
When you need to perform a scripts update, simply recompile Scripts.dll on your machine, then upload the file into the Update directory and reboot. The mod will automatically update.
This isn't very consequential for server performance (except a slightly faster boot up). However it's very handy if your server is on a remote machine. Here's how it works:
The server should be installed as usual, but the Scripts folder should be deleted (well it can be left where it is, it doesn't really matter). This mod will load all scripts from a file called Scripts.dll that the server expects to find in the executable directory. (I didn't add support for VB scripts since it seems no one uses those).
Whenever you wish to update the scripts, place the new Scripts.dll you wish to use in a folder called "Update" within the server directory. Here's an example structure:
(1) C:\RunUO\Server.exe
(2) C:\RunUO\Scripts.dll
(3) C:\RunUO\Update\Scripts.dll
When the server starts it will first look for the file (3) and if present it will delete (2) and then move (3) inside the base directory. And then load it up.
The mod is very simple and takes place in the Compile( bool debug ) method in the file \ScriptCompiler.cs. Here's the new method:
Code:
public static bool Compile( bool debug )
{
/* Mod by Arya: We no longer compile scripts on the fly, instead we load an assembly.
* The assembly is called Scripts.dll and is located in Core.BaseDirectory.
*
* There is also a check for updates BEFORE loading the assembly. Look in
* Core.BaseDirectory\Updates for a new Scripts.dll. If present copy it over the old
* one.
*/
string path = Path.Combine( Core.BaseDirectory, "Scripts.dll" );
string updatePath = Path.Combine( Core.BaseDirectory, @"Update\Scripts.dll" );
if ( File.Exists( updatePath ) )
{
// We have a scripts update
Console.Write( "Scripts update found... " );
if ( File.Exists( path ) )
{
// Delete the old scripts.dll
try
{
File.Delete( path );
}
catch ( Exception err )
{
Console.WriteLine( "update failed. Could not delete scripts.dll: {0}", err.ToString() );
return false;
}
}
try
{
File.Move( updatePath, path );
}
catch ( Exception err )
{
Console.WriteLine( "update failed. Couldn't move scripts.dll: {0}", err.ToString() );
return false;
}
Console.WriteLine( "update succesful." );
}
if ( ! File.Exists( path ) )
{
Console.WriteLine( "Scripts.dll not found. Startup aborted." );
return false;
}
Assembly scripts = null;
try
{
scripts = Assembly.LoadFile( path );
}
catch ( Exception err )
{
Console.WriteLine( "Impossible to load Scripts.dll. Error: {0}", err.ToString() );
return false;
}
m_Assemblies = new Assembly[] { scripts };
Console.WriteLine( "Scripts.dll loaded" );
Console.Write( "Scripts: Verifying..." );
Core.VerifySerialization();
Console.WriteLine( "done ({0} items, {1} mobiles)", Core.ScriptItems, Core.ScriptMobiles );
ArrayList invoke = new ArrayList();
Type[] types = scripts.GetTypes();
for ( int i = 0; i < types.Length; ++i )
{
MethodInfo m = types[i].GetMethod( "Configure", BindingFlags.Static | BindingFlags.Public );
if ( m != null )
invoke.Add( m );
}
invoke.Sort( new CallPriorityComparer() );
for ( int i = 0; i < invoke.Count; ++i )
((MethodInfo)invoke[i]).Invoke( null, null );
invoke.Clear();
World.Load();
for ( int i = 0; i < types.Length; ++i )
{
MethodInfo m = types[i].GetMethod( "Initialize", BindingFlags.Static | BindingFlags.Public );
if ( m != null )
invoke.Add( m );
}
invoke.Sort( new CallPriorityComparer() );
for ( int i = 0; i < invoke.Count; ++i )
((MethodInfo)invoke[i]).Invoke( null, null );
return true;
}
Note on debug mode: I'm exepcting no one will run the server in debug mode on a production shard. For local testing purposes you can just have your IDE output Scripts.dll and Scripts.pdb into the Server.exe folder, which will automatically enable debug mode.
When you need to perform a scripts update, simply recompile Scripts.dll on your machine, then upload the file into the Update directory and reboot. The mod will automatically update.