Go Back   RunUO - Ultima Online Emulation > RunUO > Core Modifications > Other

Other Cant find a category above, use this one! Core mods not listed above go here!

Reply
 
Thread Tools Display Modes
Old 01-24-2005, 04:23 AM   #1 (permalink)
 
Join Date: Mar 2003
Location: Near a lava pool
Age: 8
Posts: 1,012
Default 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:

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.
__________________
Oxygen should be regarded as a drug.
Arya is offline   Reply With Quote
Old 01-24-2005, 04:44 AM   #2 (permalink)
Forum Expert
 
Khaz's Avatar
 
Join Date: Mar 2003
Posts: 1,754
Thumbs up

Very nice. Thank you for another great add-on.
__________________
"Misfortune shows those who are not really friends." -Aristotle
"A multitude of words is no proof of a prudent mind." -Thales
"Conceal a flaw, and the world will imagine the worst." -Marcus Martialis


Khaz is offline   Reply With Quote
Old 01-24-2005, 05:28 AM   #3 (permalink)
P3'c Orion Aviator
 
Join Date: Sep 2004
Age: 30
Posts: 1,272
Default

very impressive
sirens song is offline   Reply With Quote
Old 01-24-2005, 06:39 AM   #4 (permalink)
Forum Expert
 
Join Date: Dec 2002
Posts: 730
Default

Pretty cool
Atomic is offline   Reply With Quote
Old 01-24-2005, 07:18 AM   #5 (permalink)
 
Join Date: Feb 2003
Posts: 172
Send a message via ICQ to -=Magic=-
Default

Its can be done without any core modification.
-=Magic=- is offline   Reply With Quote
Old 01-24-2005, 07:42 AM   #6 (permalink)
Boogie Pimp
 
ditmar's Avatar
 
Join Date: Jun 2003
Location: Amsterdam - The Netherlands
Age: 25
Posts: 161
Send a message via MSN to ditmar Send a message via Yahoo to ditmar
Default

Sounds like a very helpfull addition.

Thanks!
__________________
Founder & Admin of ABC Ultima Online

UOGateway link : ABC Ultima Online
ditmar is offline   Reply With Quote
Old 01-24-2005, 07:53 AM   #7 (permalink)
 
Join Date: Mar 2003
Location: Near a lava pool
Age: 8
Posts: 1,012
Default

Quote:
Originally Posted by -=Magic=-
Its can be done without any core modification.
Edit: nevermind. Yes you can do that by using a script that loads up the assmebly in Configure, calls all Configure methods and then all Initialize methods in Initialize. Still placing it in the core makes more sense to me, perhaps not worth if it's the only mod you make, but if you plan on modifying more than this why not?
__________________
Oxygen should be regarded as a drug.
Arya is offline   Reply With Quote
Old 01-24-2005, 08:56 AM   #8 (permalink)
Forum Expert
 
Join Date: Jan 2003
Posts: 564
Default

Quote:
Originally Posted by Arya
Edit: nevermind. Yes you can do that by using a script that loads up the assmebly in Configure, calls all Configure methods and then all Initialize methods in Initialize. Still placing it in the core makes more sense to me, perhaps not worth if it's the only mod you make, but if you plan on modifying more than this why not?
i did the same thing some time ago loading the output dll files with the assembly.cfg
__________________
UO Central: O Mistério do Oculto
(Free Shard Brasileiro)

brodock is offline   Reply With Quote
Old 01-24-2005, 09:05 AM   #9 (permalink)
 
Join Date: Mar 2003
Location: Near a lava pool
Age: 8
Posts: 1,012
Default

Quote:
Originally Posted by brodockbr
i did the same thing some time ago loading the output dll files with the assembly.cfg
Does this actually call the Configure and Initialize methods? It looks like those are invoked only on the compiled assemblies, not on the referenced libraries...
__________________
Oxygen should be regarded as a drug.
Arya is offline   Reply With Quote
Old 01-24-2005, 09:10 AM   #10 (permalink)
Forum Expert
 
Join Date: Jan 2003
Posts: 564
Default

Quote:
Originally Posted by Arya
Does this actually call the Configure and Initialize methods? It looks like those are invoked only on the compiled assemblies, not on the referenced libraries...
thre process was something like this: you let scripts folder empty (i think only output folder needs to be inside)
then you get your scripts.CS.dll you created before and insert a line in data/assemblies.cfg to where your scripts.CS.dll is...
it will compile but will not find any scripts then it will load all of the from the dll (i tested this with beta 36... it's an "old method" lol.
__________________
UO Central: O Mistério do Oculto
(Free Shard Brasileiro)

brodock is offline   Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off



Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0 RC5