Go Back   RunUO - Ultima Online Emulation > RunUO > Script Support

Script Support Get support for modifying RunUO Scripts, or writing your own!

Reply
 
Thread Tools Display Modes
Old 08-24-2008, 04:54 AM   #1 (permalink)
Lurker
 
Join Date: Jul 2004
Age: 41
Posts: 14
Default I am stumped on these errors. any help would be appreciated.

anybody that can help with any of them i would greatly appreciate it.

RunUO - [www.runuo.com] Version 2.0, Build 2959.20979
Core: Running on .NET Framework Version 2.0.50727
Scripts: Compiling C# scripts...failed (7 errors, 2 warnings)
Warnings:
+ Custom/TownHouses v1[1].1 for RunUO1.0/Town Houses 1.1/Gumps/ContractSetupGum
p.cs:
CS0465: Line 450: Introducing a 'Finalize' method can interfere with destruc
tor invocation. Did you intend to declare a destructor?
+ Gumps/Properties/PropsConfig.cs:
CS0429: Line 17: Unreachable expression code detected
CS0429: Line 20: Unreachable expression code detected
CS0429: Line 23: Unreachable expression code detected
Errors:
+ Commands/Generic/Extensions/Compilers/ConditionalCompiler.cs:
CS0246: Line 6: The type or namespace name 'server' could not be found (are
you missing a using directive or an assembly reference?)
CS0246: Line 7: The type or namespace name 'server' could not be found (are
you missing a using directive or an assembly reference?)
CS0246: Line 215: The type or namespace name 'Property' could not be found (
are you missing a using directive or an assembly reference?)
CS0246: Line 218: The type or namespace name 'Property' could not be found (
are you missing a using directive or an assembly reference?)
CS0246: Line 247: The type or namespace name 'Property' could not be found (
are you missing a using directive or an assembly reference?)
CS0246: Line 378: The type or namespace name 'Property' could not be found (
are you missing a using directive or an assembly reference?)
+ Spells/Spellweaving/ArcaneForm.cs:
CS1721: Line 13: Class 'Server.Spells.Spellweaving.ArcaneForm' cannot have m
ultiple base classes: 'Server.Spells.Spellweaving.ArcanistSpell' and 'Transforma
tionSpell'
+ Commands/Generic/Extensions/Compilers/DistinctCompiler.cs:
CS0246: Line 13: The type or namespace name 'Property' could not be found (a
re you missing a using directive or an assembly reference?)
+ Commands/Generic/Extensions/Compilers/SortCompiler.cs:
CS0246: Line 13: The type or namespace name 'Property' could not be found (a
re you missing a using directive or an assembly reference?)
CS0246: Line 16: The type or namespace name 'Property' could not be found (a
re you missing a using directive or an assembly reference?)
CS0118: Line 46: 'Server.Commands.Generic.OrderInfo.Property' is a 'property
' but is used like a 'type'
+ Commands/Generic/Extensions/DistinctExtension.cs:
CS0246: Line 23: The type or namespace name 'Property' could not be found (a
re you missing a using directive or an assembly reference?)
+ Commands/HelpInfo.cs:
CS0122: Line 11: 'Server.Commands.Docs.DocCommandEntry' is inaccessible due
to its protection level
CS0122: Line 12: 'Server.Commands.Docs.CommandEntrySorter' is inaccessible d
ue to its protection level
CS0051: Line 239: Inconsistent accessibility: parameter type 'System.Collect
ions.Generic.List<Server.Commands.Docs.DocCommandE ntry>' is less accessible than
method 'Server.Commands.HelpInfo.CommandListGump.CommandL istGump(int, Server.Mo
bile, System.Collections.Generic.List<Server.Commands.Do cs.DocCommandEntry>)'
CS0051: Line 364: Inconsistent accessibility: parameter type 'Server.Command
s.Docs.DocCommandEntry' is less accessible than method 'Server.Commands.HelpInfo
.CommandInfoGump.CommandInfoGump(Server.Commands.D ocs.DocCommandEntry)'
CS0051: Line 369: Inconsistent accessibility: parameter type 'Server.Command
s.Docs.DocCommandEntry' is less accessible than method 'Server.Commands.HelpInfo
.CommandInfoGump.CommandInfoGump(Server.Commands.D ocs.DocCommandEntry, int, int)
'
CS0053: Line 22: Inconsistent accessibility: property type 'System.Collectio
ns.Generic.Dictionary<string,Server.Commands.Docs. DocCommandEntry>' is less acce
ssible than property 'Server.Commands.HelpInfo.HelpInfos'
CS0053: Line 23: Inconsistent accessibility: property type 'System.Collectio
ns.Generic.List<Server.Commands.Docs.DocCommandEnt ry>' is less accessible than p
roperty 'Server.Commands.HelpInfo.SortedHelpInfo'
+ Misc/Emitter.cs:
CS0246: Line 478: The type or namespace name 'Property' could not be found (
are you missing a using directive or an assembly reference?)
Scripts: One or more scripts failed to compile or no script files were found.
- Press return to exit, or R to try again.
Treetall is offline   Reply With Quote
Old 08-24-2008, 05:35 AM   #2 (permalink)
Forum Novice
 
Soteric's Avatar
 
Join Date: Aug 2006
Location: Russia, Rostov-on-Don
Posts: 763
Send a message via ICQ to Soteric
Default

Post scripts with the errors
Soteric is offline   Reply With Quote
Old 08-24-2008, 11:16 AM   #3 (permalink)
Forum Novice
 
Arkryal's Avatar
 
Join Date: Jan 2003
Location: Rochester NY
Age: 27
Posts: 208
Default

Quote:
RunUO - [www.runuo.com] Version 2.0, Build 2959.20979
compare to this

Quote:
+ Custom/TownHouses v1[1].1 for RunUO1.0/Town Houses 1.1/Gumps/ContractSetupGum
p.cs:
Looks like a version mismatch. 1.0 scripts often choke on 2.0 server installs.
also, I don't like the looks of this...
Quote:
Errors:
+ Commands/Generic/Extensions/Compilers/ConditionalCompiler.cs:
CS0246: Line 6: The type or namespace name 'server' could not be found (are
you missing a using directive or an assembly reference?)
CS0246: Line 7: The type or namespace name 'server' could not be found (are
you missing a using directive or an assembly reference?)
CS0246: Line 215: The type or namespace name 'Property' could not be found (
are you missing a using directive or an assembly reference?)
CS0246: Line 218: The type or namespace name 'Property' could not be found (
are you missing a using directive or an assembly reference?)
CS0246: Line 247: The type or namespace name 'Property' could not be found (
are you missing a using directive or an assembly reference?)
CS0246: Line 378: The type or namespace name 'Property' could not be found (
are you missing a using directive or an assembly reference?)
Did you do any core edits? 'server' Should be 'Server' (Capital). C# is real anal about proper casing. The version mismatch could explain everything, but it looks like there are a ton of other potential problems. I would reinstall the scripts folder and add in any custom scripts one at a time, and check the forums for the latest version of them. Many 1.0 scripts have not been updated for the 2.0 server, so you may have to rewrite a few functions and verify the includes sections.
__________________
•¤•¤•Arkryal •¤•¤•
Arkryal is offline   Reply With Quote
Old 08-24-2008, 03:36 PM   #4 (permalink)
Lurker
 
Join Date: Jul 2004
Age: 41
Posts: 14
Default

RunUO - [www.runuo.com] Version 2.0, Build 2959.20979
Core: Running on .NET Framework Version 2.0.50727
Scripts: Compiling C# scripts...failed (7 errors, 2 warnings)
Warnings:
+ Custom/TownHouses v1[1].1 for RunUO1.0/Town Houses 1.1/Gumps/ContractSetupGum
p.cs:
CS0465: Line 450: Introducing a 'Finalize' method can interfere with destruc
tor invocation. Did you intend to declare a destructor?
+ Gumps/Properties/PropsConfig.cs:
CS0429: Line 17: Unreachable expression code detected
CS0429: Line 20: Unreachable expression code detected
CS0429: Line 23: Unreachable expression code detected
Errors:
+ Spells/Spellweaving/ArcaneForm.cs:
CS0246: Line 13: The type or namespace name 'ITransformationSpell' could not
be found (are you missing a using directive or an assembly reference?)
+ Commands/Generic/Extensions/Compilers/ConditionalCompiler.cs:
CS0246: Line 212: The type or namespace name 'Property' could not be found (
are you missing a using directive or an assembly reference?)
CS0246: Line 215: The type or namespace name 'Property' could not be found (
are you missing a using directive or an assembly reference?)
CS0246: Line 244: The type or namespace name 'Property' could not be found (
are you missing a using directive or an assembly reference?)
CS0246: Line 375: The type or namespace name 'Property' could not be found (
are you missing a using directive or an assembly reference?)
+ Commands/Generic/Extensions/Compilers/DistinctCompiler.cs:
CS0246: Line 13: The type or namespace name 'Property' could not be found (a
re you missing a using directive or an assembly reference?)
+ Commands/Generic/Extensions/Compilers/SortCompiler.cs:
CS0246: Line 13: The type or namespace name 'Property' could not be found (a
re you missing a using directive or an assembly reference?)
CS0246: Line 16: The type or namespace name 'Property' could not be found (a
re you missing a using directive or an assembly reference?)
CS0118: Line 46: 'Server.Commands.Generic.OrderInfo.Property' is a 'property
' but is used like a 'type'
+ Commands/Generic/Extensions/DistinctExtension.cs:
CS0246: Line 23: The type or namespace name 'Property' could not be found (a
re you missing a using directive or an assembly reference?)
+ Commands/HelpInfo.cs:
CS0122: Line 11: 'Server.Commands.Docs.DocCommandEntry' is inaccessible due
to its protection level
CS0122: Line 12: 'Server.Commands.Docs.CommandEntrySorter' is inaccessible d
ue to its protection level
CS0051: Line 239: Inconsistent accessibility: parameter type 'System.Collect
ions.Generic.List<Server.Commands.Docs.DocCommandE ntry>' is less accessible than
method 'Server.Commands.HelpInfo.CommandListGump.CommandL istGump(int, Server.Mo
bile, System.Collections.Generic.List<Server.Commands.Do cs.DocCommandEntry>)'
CS0051: Line 364: Inconsistent accessibility: parameter type 'Server.Command
s.Docs.DocCommandEntry' is less accessible than method 'Server.Commands.HelpInfo
.CommandInfoGump.CommandInfoGump(Server.Commands.D ocs.DocCommandEntry)'
CS0051: Line 369: Inconsistent accessibility: parameter type 'Server.Command
s.Docs.DocCommandEntry' is less accessible than method 'Server.Commands.HelpInfo
.CommandInfoGump.CommandInfoGump(Server.Commands.D ocs.DocCommandEntry, int, int)
'
CS0053: Line 22: Inconsistent accessibility: property type 'System.Collectio
ns.Generic.Dictionary<string,Server.Commands.Docs. DocCommandEntry>' is less acce
ssible than property 'Server.Commands.HelpInfo.HelpInfos'
CS0053: Line 23: Inconsistent accessibility: property type 'System.Collectio
ns.Generic.List<Server.Commands.Docs.DocCommandEnt ry>' is less accessible than p
roperty 'Server.Commands.HelpInfo.SortedHelpInfo'
+ Misc/Emitter.cs:
CS0246: Line 478: The type or namespace name 'Property' could not be found (
are you missing a using directive or an assembly reference?)
Scripts: One or more scripts failed to compile or no script files were found.
- Press return to exit, or R to try again.


And here are the scripts

using System;
using System.Collections;
using System.Collections.Generic;
using Server.Mobiles;
using Server.Network;
using Server.Spells.Fifth;
using Server.Spells.Seventh;
using Server.Spells.Necromancy;
using Server.Spells.Ninjitsu;

namespace Server.Spells.Spellweaving
{
public abstract class ArcaneForm : ArcanistSpell, ITransformationSpell
{
public abstract int Body { get; }
public virtual int Hue { get { return 0; } }

public virtual int PhysResistOffset { get { return 0; } }
public virtual int FireResistOffset { get { return 0; } }
public virtual int ColdResistOffset { get { return 0; } }
public virtual int PoisResistOffset { get { return 0; } }
public virtual int NrgyResistOffset { get { return 0; } }

public ArcaneForm( Mobile caster, Item scroll, SpellInfo info ) : base( caster, scroll, info )
{
}

public override bool CheckCast()
{
if( !TransformationSpellHelper.CheckCast( Caster, this ) )
return false;

return base.CheckCast();
}

public override void OnCast()
{
TransformationSpellHelper.OnCast( Caster, this );

FinishSequence();
}

public virtual double TickRate
{
get { return 1.0; }
}

public virtual void OnTick( Mobile m )
{
}

public virtual void DoEffect( Mobile m )
{
}

public virtual void RemoveEffect( Mobile m )
{
}
}
}



using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Reflection;
using System.Reflection.Emit;
using System.Text;
using Server;

namespace Server.Commands.Generic
{
public interface IConditional
{
bool Verify( object obj );
}

public interface ICondition
{
// Invoked during the constructor
void Construct( TypeBuilder typeBuilder, ILGenerator il, int index );

// Target object will be loaded on the stack
void Compile( MethodEmitter emitter );
}

public sealed class TypeCondition : ICondition
{
public static TypeCondition Default = new TypeCondition();

void ICondition.Construct( TypeBuilder typeBuilder, ILGenerator il, int index )
{
}

void ICondition.Compile( MethodEmitter emitter )
{
// The object was safely cast to be the conditionals type
// If it's null, then the type cast didn't work...

emitter.LoadNull();
emitter.Compare( OpCodes.Ceq );
emitter.LogicalNot();
}
}

public sealed class PropertyValue
{
private Type m_Type;
private object m_Value;
private FieldInfo m_Field;

public Type Type
{
get { return m_Type; }
}

public object Value
{
get { return m_Value; }
}

public FieldInfo Field
{
get { return m_Field; }
}

public bool HasField
{
get { return ( m_Field != null ); }
}

public PropertyValue( Type type, object value )
{
m_Type = type;
m_Value = value;
}

public void Load( MethodEmitter method )
{
if ( m_Field != null )
{
method.LoadArgument( 0 );
method.LoadField( m_Field );
}
else if ( m_Value == null )
{
method.LoadNull( m_Type );
}
else
{
if ( m_Value is int )
method.Load( (int) m_Value );
else if ( m_Value is long )
method.Load( (long) m_Value );
else if ( m_Value is float )
method.Load( (float) m_Value );
else if ( m_Value is double )
method.Load( (double) m_Value );
else if ( m_Value is char )
method.Load( (char) m_Value );
else if ( m_Value is bool )
method.Load( (bool) m_Value );
else if ( m_Value is string )
method.Load( (string) m_Value );
else if ( m_Value is Enum )
method.Load( (Enum) m_Value );
else
throw new InvalidOperationException( "Unrecognized comparison value." );
}
}

public void Acquire( TypeBuilder typeBuilder, ILGenerator il, string fieldName )
{
if ( m_Value is string )
{
string toParse = (string) m_Value;

if ( !m_Type.IsValueType && toParse == "null" )
{
m_Value = null;
}
else if ( m_Type == typeof( string ) )
{
if ( toParse == @"@""null""" )
toParse = "null";

m_Value = toParse;
}
else if ( m_Type.IsEnum )
{
m_Value = Enum.Parse( m_Type, toParse, true );
}
else
{
MethodInfo parseMethod = null;
object[] parseArgs = null;

MethodInfo parseNumber = m_Type.GetMethod(
"Parse",
BindingFlags.Public | BindingFlags.Static,
null,
new Type[] { typeof( string ), typeof( NumberStyles ) },
null
);

if ( parseNumber != null )
{
NumberStyles style = NumberStyles.Integer;

if ( Insensitive.StartsWith( toParse, "0x" ) )
{
style = NumberStyles.HexNumber;
toParse = toParse.Substring( 2 );
}

parseMethod = parseNumber;
parseArgs = new object[] { toParse, style };
}
else
{
MethodInfo parseGeneral = m_Type.GetMethod(
"Parse",
BindingFlags.Public | BindingFlags.Static,
null,
new Type[] { typeof( string ) },
null
);

parseMethod = parseGeneral;
parseArgs = new object[] { toParse };
}

if ( parseMethod != null )
{
m_Value = parseMethod.Invoke( null, parseArgs );

if ( !m_Type.IsPrimitive )
{
m_Field = typeBuilder.DefineField(
fieldName,
m_Type,
FieldAttributes.Private | FieldAttributes.InitOnly
);

il.Emit( OpCodes.Ldarg_0 );

il.Emit( OpCodes.Ldstr, toParse );

if ( parseArgs.Length == 2 ) // dirty evil hack :-(
il.Emit( OpCodes.Ldc_I4, (int) parseArgs[1] );

il.Emit( OpCodes.Call, parseMethod );
il.Emit( OpCodes.Stfld, m_Field );
}
}
else
{
throw new InvalidOperationException(
String.Format(
"Unable to convert string \"{0}\" into type '{1}'.",
m_Value,
m_Type
)
);
}
}
}
}
}

public abstract class PropertyCondition : ICondition
{
protected Property m_Property;
protected bool m_Not;

public PropertyCondition( Property property, bool not )
{
m_Property = property;
m_Not = not;
}

public abstract void Construct( TypeBuilder typeBuilder, ILGenerator il, int index );

public abstract void Compile( MethodEmitter emitter );
}

public enum StringOperator
{
Equal,
NotEqual,

Contains,

StartsWith,
EndsWith
}

public sealed class StringCondition : PropertyCondition
{
private StringOperator m_Operator;
private PropertyValue m_Value;

private bool m_IgnoreCase;

public StringCondition( Property property, bool not, StringOperator op, object value, bool ignoreCase )
: base( property, not )
{
m_Operator = op;
m_Value = new PropertyValue( property.Type, value );

m_IgnoreCase = ignoreCase;
}

public override void Construct( TypeBuilder typeBuilder, ILGenerator il, int index )
{
m_Value.Acquire( typeBuilder, il, "v" + index );
}

public override void Compile( MethodEmitter emitter )
{
bool inverse = false;

string methodName;

switch ( m_Operator )
{
case StringOperator.Equal:
methodName = "Equals";
break;

case StringOperator.NotEqual:
methodName = "Equals";
inverse = true;
break;

case StringOperator.Contains:
methodName = "Contains";
break;

case StringOperator.StartsWith:
methodName = "StartsWith";
break;

case StringOperator.EndsWith:
methodName = "EndsWith";
break;

default:
throw new InvalidOperationException( "Invalid string comparison operator." );
}

if ( m_IgnoreCase || methodName == "Equals" )
{
Type type = ( m_IgnoreCase ? typeof( Insensitive ) : typeof( String ) );

emitter.BeginCall(
type.GetMethod(
methodName,
BindingFlags.Public | BindingFlags.Static,
null,
new Type[]
{
typeof( string ),
typeof( string )
},
null
)
);

emitter.Chain( m_Property );
m_Value.Load( emitter );

emitter.FinishCall();
}
else
{
Label notNull = emitter.CreateLabel();
Label moveOn = emitter.CreateLabel();

LocalBuilder temp = emitter.AcquireTemp( m_Property.Type );

emitter.Chain( m_Property );

emitter.StoreLocal( temp );
emitter.LoadLocal( temp );

emitter.BranchIfTrue( notNull );

emitter.Load( false );
emitter.Pop();
emitter.Branch( moveOn );

emitter.MarkLabel( notNull );
emitter.LoadLocal( temp );

emitter.BeginCall(
typeof( string ).GetMethod(
methodName,
BindingFlags.Public | BindingFlags.Instance,
null,
new Type[]
{
typeof( string )
},
null
)
);

m_Value.Load( emitter );

emitter.FinishCall();

emitter.MarkLabel( moveOn );
}

if ( m_Not != inverse )
emitter.LogicalNot();
}
}

public enum ComparisonOperator
{
Equal,
NotEqual,
Greater,
GreaterEqual,
Lesser,
LesserEqual
}

public sealed class ComparisonCondition : PropertyCondition
{
private ComparisonOperator m_Operator;
private PropertyValue m_Value;

public ComparisonCondition( Property property, bool not, ComparisonOperator op, object value )
: base( property, not )
{
m_Operator = op;
m_Value = new PropertyValue( property.Type, value );
}

public override void Construct( TypeBuilder typeBuilder, ILGenerator il, int index )
{
m_Value.Acquire( typeBuilder, il, "v" + index );
}

public override void Compile( MethodEmitter emitter )
{
emitter.Chain( m_Property );

bool inverse = false;

bool couldCompare =
emitter.CompareTo( 1, delegate()
{
m_Value.Load( emitter );
} );

if ( couldCompare )
{
emitter.Load( 0 );

switch ( m_Operator )
{
case ComparisonOperator.Equal:
emitter.Compare( OpCodes.Ceq );
break;

case ComparisonOperator.NotEqual:
emitter.Compare( OpCodes.Ceq );
inverse = true;
break;

case ComparisonOperator.Greater:
emitter.Compare( OpCodes.Cgt );
break;

case ComparisonOperator.GreaterEqual:
emitter.Compare( OpCodes.Clt );
inverse = true;
break;

case ComparisonOperator.Lesser:
emitter.Compare( OpCodes.Clt );
break;

case ComparisonOperator.LesserEqual:
emitter.Compare( OpCodes.Cgt );
inverse = true;
break;

default:
throw new InvalidOperationException( "Invalid comparison operator." );
}
}
else
{
// This type is -not- comparable
// We can only support == and != operations

m_Value.Load( emitter );

switch ( m_Operator )
{
case ComparisonOperator.Equal:
emitter.Compare( OpCodes.Ceq );
break;

case ComparisonOperator.NotEqual:
emitter.Compare( OpCodes.Ceq );
inverse = true;
break;

case ComparisonOperator.Greater:
case ComparisonOperator.GreaterEqual:
case ComparisonOperator.Lesser:
case ComparisonOperator.LesserEqual:
throw new InvalidOperationException( "Property does not support relational comparisons." );

default:
throw new InvalidOperationException( "Invalid operator." );
}
}

if ( m_Not != inverse )
emitter.LogicalNot();
}
}

public static class ConditionalCompiler
{
public static IConditional Compile( AssemblyEmitter assembly, Type objectType, ICondition[] conditions, int index )
{
TypeBuilder typeBuilder = assembly.DefineType(
"__conditional" + index,
TypeAttributes.Public,
typeof( object )
);

#region Constructor
{
ConstructorBuilder ctor = typeBuilder.DefineConstructor(
MethodAttributes.Public,
CallingConventions.Standard,
Type.EmptyTypes
);

ILGenerator il = ctor.GetILGenerator();

// : base()
il.Emit( OpCodes.Ldarg_0 );
il.Emit( OpCodes.Call, typeof( object ).GetConstructor( Type.EmptyTypes ) );

for ( int i = 0; i < conditions.Length; ++i )
conditions[i].Construct( typeBuilder, il, i );

// return;
il.Emit( OpCodes.Ret );
}
#endregion

#region IComparer
typeBuilder.AddInterfaceImplementation( typeof( IConditional ) );

MethodBuilder compareMethod;

#region Compare
{
MethodEmitter emitter = new MethodEmitter( typeBuilder );

emitter.Define(
/* name */ "Verify",
/* attr */ MethodAttributes.Public | MethodAttributes.Virtual,
/* return */ typeof( bool ),
/* params */ new Type[] { typeof( object ) } );

LocalBuilder obj = emitter.CreateLocal( objectType );
LocalBuilder eq = emitter.CreateLocal( typeof( bool ) );

emitter.LoadArgument( 1 );
emitter.CastAs( objectType );
emitter.StoreLocal( obj );

Label done = emitter.CreateLabel();

for ( int i = 0; i < conditions.Length; ++i )
{
if ( i > 0 )
{
emitter.LoadLocal( eq );

emitter.BranchIfFalse( done );
}

emitter.LoadLocal( obj );

conditions[i].Compile( emitter );

emitter.StoreLocal( eq );
}

emitter.MarkLabel( done );

emitter.LoadLocal( eq );

emitter.Return();

typeBuilder.DefineMethodOverride(
emitter.Method,
typeof( IConditional ).GetMethod(
"Verify",
new Type[]
{
typeof( object )
}
)
);

compareMethod = emitter.Method;
}
#endregion
#endregion

Type conditionalType = typeBuilder.CreateType();

return (IConditional) Activator.CreateInstance( conditionalType );
}
}
}



using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using System.Reflection.Emit;
using System.Text;
using Server;

namespace Server.Commands.Generic
{
public static class DistinctCompiler
{
public static IComparer Compile( AssemblyEmitter assembly, Type objectType, Property[] props )
{
TypeBuilder typeBuilder = assembly.DefineType(
"__distinct",
TypeAttributes.Public,
typeof( object )
);

#region Constructor
{
ConstructorBuilder ctor = typeBuilder.DefineConstructor(
MethodAttributes.Public,
CallingConventions.Standard,
Type.EmptyTypes
);

ILGenerator il = ctor.GetILGenerator();

// : base()
il.Emit( OpCodes.Ldarg_0 );
il.Emit( OpCodes.Call, typeof( object ).GetConstructor( Type.EmptyTypes ) );

// return;
il.Emit( OpCodes.Ret );
}
#endregion

#region IComparer
typeBuilder.AddInterfaceImplementation( typeof( IComparer ) );

MethodBuilder compareMethod;

#region Compare
{
MethodEmitter emitter = new MethodEmitter( typeBuilder );

emitter.Define(
/* name */ "Compare",
/* attr */ MethodAttributes.Public | MethodAttributes.Virtual,
/* return */ typeof( int ),
/* params */ new Type[] { typeof( object ), typeof( object ) } );

LocalBuilder a = emitter.CreateLocal( objectType );
LocalBuilder b = emitter.CreateLocal( objectType );

LocalBuilder v = emitter.CreateLocal( typeof( int ) );

emitter.LoadArgument( 1 );
emitter.CastAs( objectType );
emitter.StoreLocal( a );

emitter.LoadArgument( 2 );
emitter.CastAs( objectType );
emitter.StoreLocal( b );

emitter.Load( 0 );
emitter.StoreLocal( v );

Label end = emitter.CreateLabel();

for ( int i = 0; i < props.Length; ++i )
{
if ( i > 0 )
{
emitter.LoadLocal( v );
emitter.BranchIfTrue( end ); // if ( v != 0 ) return v;
}

Property prop = props[i];

emitter.LoadLocal( a );
emitter.Chain( prop );

bool couldCompare =
emitter.CompareTo( 1, delegate()
{
emitter.LoadLocal( b );
emitter.Chain( prop );
} );

if ( !couldCompare )
throw new InvalidOperationException( "Property is not comparable." );

emitter.StoreLocal( v );
}

emitter.MarkLabel( end );

emitter.LoadLocal( v );
emitter.Return();

typeBuilder.DefineMethodOverride(
emitter.Method,
typeof( IComparer ).GetMethod(
"Compare",
new Type[]
{
typeof( object ),
typeof( object )
}
)
);

compareMethod = emitter.Method;
}
#endregion
#endregion

#region IEqualityComparer
typeBuilder.AddInterfaceImplementation( typeof( IEqualityComparer<object> ) );

#region Equals
{
MethodEmitter emitter = new MethodEmitter( typeBuilder );

emitter.Define(
/* name */ "Equals",
/* attr */ MethodAttributes.Public | MethodAttributes.Virtual,
/* return */ typeof( bool ),
/* params */ new Type[] { typeof( object ), typeof( object ) } );

emitter.Generator.Emit( OpCodes.Ldarg_0 );
emitter.Generator.Emit( OpCodes.Ldarg_1 );
emitter.Generator.Emit( OpCodes.Ldarg_2 );

emitter.Generator.Emit( OpCodes.Call, compareMethod );

emitter.Generator.Emit( OpCodes.Ldc_I4_0 );

emitter.Generator.Emit( OpCodes.Ceq );

emitter.Generator.Emit( OpCodes.Ret );

typeBuilder.DefineMethodOverride(
emitter.Method,
typeof( IEqualityComparer<object> ).GetMethod(
"Equals",
new Type[]
{
typeof( object ),
typeof( object )
}
)
);
}
#endregion

#region GetHashCode
{
MethodEmitter emitter = new MethodEmitter( typeBuilder );

emitter.Define(
/* name */ "GetHashCode",
/* attr */ MethodAttributes.Public | MethodAttributes.Virtual,
/* return */ typeof( int ),
/* params */ new Type[] { typeof( object ) } );

LocalBuilder obj = emitter.CreateLocal( objectType );

emitter.LoadArgument( 1 );
emitter.CastAs( objectType );
emitter.StoreLocal( obj );

for ( int i = 0; i < props.Length; ++i )
{
Property prop = props[i];

emitter.LoadLocal( obj );
emitter.Chain( prop );

Type active = emitter.Active;

MethodInfo getHashCode = active.GetMethod( "GetHashCode", Type.EmptyTypes );

if ( getHashCode == null )
getHashCode = typeof( object ).GetMethod( "GetHashCode", Type.EmptyTypes );

if ( active != typeof( int ) )
{
if ( !active.IsValueType )
{
LocalBuilder value = emitter.AcquireTemp( active );

Label valueNotNull = emitter.CreateLabel();
Label done = emitter.CreateLabel();

emitter.StoreLocal( value );
emitter.LoadLocal( value );

emitter.BranchIfTrue( valueNotNull );

emitter.Load( 0 );
emitter.Pop( typeof( int ) );

emitter.Branch( done );

emitter.MarkLabel( valueNotNull );

emitter.LoadLocal( value );
emitter.Call( getHashCode );

emitter.ReleaseTemp( value );

emitter.MarkLabel( done );
}
else
{
emitter.Call( getHashCode );
}
}

if ( i > 0 )
emitter.Xor();
}

emitter.Return();

typeBuilder.DefineMethodOverride(
emitter.Method,
typeof( IEqualityComparer<object> ).GetMethod(
"GetHashCode",
new Type[]
{
typeof( object )
}
)
);
}
#endregion
#endregion

Type comparerType = typeBuilder.CreateType();

return (IComparer) Activator.CreateInstance( comparerType );
}
}
}



using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using System.Reflection.Emit;
using System.Text;
using Server;

namespace Server.Commands.Generic
{
public sealed class OrderInfo
{
private Property m_Property;
private int m_Order;

public Property Property
{
get { return m_Property; }
set { m_Property = value; }
}

public bool IsAscending
{
get { return ( m_Order > 0 ); }
set { m_Order = ( value ? +1 : -1 ); }
}

public bool IsDescending
{
get { return ( m_Order < 0 ); }
set { m_Order = ( value ? -1 : +1 ); }
}

public int Sign
{
get { return Math.Sign( m_Order ); }
set
{
m_Order = Math.Sign( value );

if ( m_Order == 0 )
throw new InvalidOperationException( "Sign cannot be zero." );
}
}

public OrderInfo( Property property, bool isAscending )
{
m_Property = property;

this.IsAscending = isAscending;
}
}

public static class SortCompiler
{
public static IComparer Compile( AssemblyEmitter assembly, Type objectType, OrderInfo[] orders )
{
TypeBuilder typeBuilder = assembly.DefineType(
"__sort",
TypeAttributes.Public,
typeof( object )
);

#region Constructor
{
ConstructorBuilder ctor = typeBuilder.DefineConstructor(
MethodAttributes.Public,
CallingConventions.Standard,
Type.EmptyTypes
);

ILGenerator il = ctor.GetILGenerator();

// : base()
il.Emit( OpCodes.Ldarg_0 );
il.Emit( OpCodes.Call, typeof( object ).GetConstructor( Type.EmptyTypes ) );

// return;
il.Emit( OpCodes.Ret );
}
#endregion

#region IComparer
typeBuilder.AddInterfaceImplementation( typeof( IComparer ) );

MethodBuilder compareMethod;

#region Compare
{
MethodEmitter emitter = new MethodEmitter( typeBuilder );

emitter.Define(
/* name */ "Compare",
/* attr */ MethodAttributes.Public | MethodAttributes.Virtual,
/* return */ typeof( int ),
/* params */ new Type[] { typeof( object ), typeof( object ) } );

LocalBuilder a = emitter.CreateLocal( objectType );
LocalBuilder b = emitter.CreateLocal( objectType );

LocalBuilder v = emitter.CreateLocal( typeof( int ) );

emitter.LoadArgument( 1 );
emitter.CastAs( objectType );
emitter.StoreLocal( a );

emitter.LoadArgument( 2 );
emitter.CastAs( objectType );
emitter.StoreLocal( b );

emitter.Load( 0 );
emitter.StoreLocal( v );

Label end = emitter.CreateLabel();

for ( int i = 0; i < orders.Length; ++i )
{
if ( i > 0 )
{
emitter.LoadLocal( v );
emitter.BranchIfTrue( end ); // if ( v != 0 ) return v;
}

OrderInfo orderInfo = orders[i];

Property prop = orderInfo.Property;
int sign = orderInfo.Sign;

emitter.LoadLocal( a );
emitter.Chain( prop );

bool couldCompare =
emitter.CompareTo( sign, delegate()
{
emitter.LoadLocal( b );
emitter.Chain( prop );
} );

if ( !couldCompare )
throw new InvalidOperationException( "Property is not comparable." );

emitter.StoreLocal( v );
}

emitter.MarkLabel( end );

emitter.LoadLocal( v );
emitter.Return();

typeBuilder.DefineMethodOverride(
emitter.Method,
typeof( IComparer ).GetMethod(
"Compare",
new Type[]
{
typeof( object ),
typeof( object )
}
)
);

compareMethod = emitter.Method;
}
#endregion
#endregion

Type comparerType = typeBuilder.CreateType();

return (IComparer) Activator.CreateInstance( comparerType );
}
}
}


using System;
using System.Reflection;
using System.Collections;
using System.Collections.Generic;
using System.Text;

namespace Server.Commands.Generic
{
public sealed class DistinctExtension : BaseExtension
{
public static ExtensionInfo ExtInfo = new ExtensionInfo( 30, "Distinct", -1, delegate() { return new DistinctExtension(); } );

public static void Initialize()
{
ExtensionInfo.Register( ExtInfo );
}

public override ExtensionInfo Info
{
get { return ExtInfo; }
}

private List<Property> m_Properties;

private IComparer m_Comparer;

public DistinctExtension()
{
m_Properties = new List<Property>();
}

public override void Optimize( Mobile from, Type baseType, ref AssemblyEmitter assembly )
{
if ( baseType == null )
throw new Exception( "Distinct extension may only be used in combination with an object conditional." );

foreach ( Property prop in m_Properties )
{
prop.BindTo( baseType, PropertyAccess.Read );
prop.CheckAccess( from );
}

if ( assembly == null )
assembly = new AssemblyEmitter( "__dynamic", false );

m_Comparer = DistinctCompiler.Compile( assembly, baseType, m_Properties.ToArray() );
}

public override void Parse( Mobile from, string[] arguments, int offset, int size )
{
if ( size < 1 )
throw new Exception( "Invalid distinction syntax." );

int end = offset + size;

while ( offset < end )
{
string binding = arguments[offset++];

m_Properties.Add( new Property( binding ) );
}
}

public override void Filter( ArrayList list )
{
if ( m_Comparer == null )
throw new InvalidOperationException( "The extension must first be optimized." );

ArrayList copy = new ArrayList( list );

copy.Sort( m_Comparer );

list.Clear();

object last = null;

for ( int i = 0; i < copy.Count; ++i )
{
object obj = copy[i];

if ( last == null || m_Comparer.Compare( obj, last ) != 0 )
{
list.Add( obj );
last = obj;
}
}
}
}
}


using System;
using Server;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
using Server.Gumps;
using Server.Network;
using Server.Commands;
using Server.Commands.Generic;
using CommandInfo=Server.Commands.Docs.DocCommandEntry;
using CommandInfoSorter=Server.Commands.Docs.CommandEntr ySorter;

namespace Server.Commands
{
public class HelpInfo
{

private static Dictionary<string, CommandInfo> m_HelpInfos = new Dictionary<string, CommandInfo>();
private static List<CommandInfo> m_SortedHelpInfo = new List<CommandInfo>(); //No need for SortedList cause it's only sorted once at creation...

public static Dictionary<string, CommandInfo> HelpInfos{ get { return m_HelpInfos; } }
public static List<CommandInfo> SortedHelpInfo { get { return m_SortedHelpInfo; } }

[CallPriority( 100 )]
public static void Initialize()
{
CommandSystem.Register( "HelpInfo", AccessLevel.Player, new CommandEventHandler( HelpInfo_OnCommand ) );

FillTable();
}

[Usage( "HelpInfo [<command>]" )]
[Description( "Gives information on a specified command, or when no argument specified, displays a gump containing all commands" )]
private static void HelpInfo_OnCommand( CommandEventArgs e )
{
if( e.Length > 0 )
{
string arg = e.GetString( 0 ).ToLower();
CommandInfo c;

if( m_HelpInfos.TryGetValue( arg, out c ) )
{
Mobile m = e.Mobile;

if( m.AccessLevel >= c.AccessLevel )
m.SendGump( new CommandInfoGump( c ) );
else
m.SendMessage( "You don't have access to that command." );

return;
}
else
e.Mobile.SendMessage( String.Format( "Command '{0}' not found!", arg ) );
}

e.Mobile.SendGump( new CommandListGump( 0, e.Mobile, null ) );

}

public static void FillTable()
{
List<CommandEntry> commands = new List<CommandEntry>( CommandSystem.Entries.Values );
List<CommandInfo> list = new List<CommandInfo>();

commands.Sort();
commands.Reverse();
Docs.Clean( commands );

for( int i = 0; i < commands.Count; ++i )
{
CommandEntry e =commands[i];

MethodInfo mi = e.Handler.Method;

object[] attrs = mi.GetCustomAttributes( typeof( UsageAttribute ), false );

if( attrs.Length == 0 )
continue;

UsageAttribute usage = attrs[0] as UsageAttribute;

attrs = mi.GetCustomAttributes( typeof( DescriptionAttribute ), false );

if( attrs.Length == 0 )
continue;

DescriptionAttribute desc = attrs[0] as DescriptionAttribute;

if( usage == null || desc == null )
continue;

attrs = mi.GetCustomAttributes( typeof( AliasesAttribute ), false );

AliasesAttribute aliases = (attrs.Length == 0 ? null : attrs[0] as AliasesAttribute);

string descString = desc.Description.Replace( "<", "(" ).Replace( ">", ")" );

if( aliases == null )
list.Add( new CommandInfo( e.AccessLevel, e.Command, null, usage.Usage, descString ) );
else
{
list.Add( new CommandInfo( e.AccessLevel, e.Command, aliases.Aliases, usage.Usage, descString ) );

for( int j = 0; j < aliases.Aliases.Length; j++ )
{
string[] newAliases = new string[aliases.Aliases.Length];

aliases.Aliases.CopyTo( newAliases, 0 );

newAliases[j] = e.Command;

list.Add( new CommandInfo( e.AccessLevel, aliases.Aliases[j], newAliases, usage.Usage, descString ) );
}
}
}


for( int i = 0; i < TargetCommands.AllCommands.Count; ++i )
{
BaseCommand command = TargetCommands.AllCommands[i];

string usage = command.Usage;
string desc = command.Description;

if( usage == null || desc == null )
continue;

string[] cmds = command.Commands;
string cmd = cmds[0];
string[] aliases = new string[cmds.Length - 1];

for( int j = 0; j < aliases.Length; ++j )
aliases[j] = cmds[j + 1];

desc = desc.Replace( "<", "(" ).Replace( ">", ")" );

if( command.Supports != CommandSupport.Single )
{
StringBuilder sb = new StringBuilder( 50 + desc.Length );

sb.Append( "Modifiers: " );

if( (command.Supports & CommandSupport.Global) != 0 )
sb.Append( "<i><Global</i>, " );

if( (command.Supports & CommandSupport.Online) != 0 )
sb.Append( "<i>Online</i>, " );

if( (command.Supports & CommandSupport.Region) != 0 )
sb.Append( "<i>Region</i>, " );

if( (command.Supports & CommandSupport.Contained) != 0 )
sb.Append( "<i>Contained</i>, " );

if( (command.Supports & CommandSupport.Multi) != 0 )
sb.Append( "<i>Multi</i>, " );

if( (command.Supports & CommandSupport.Area) != 0 )
sb.Append( "<i>Area</i>, " );

if( (command.Supports & CommandSupport.Self) != 0 )
sb.Append( "<i>Self</i>, " );

sb.Remove( sb.Length - 2, 2 );
sb.Append( "<br>" );
sb.Append( desc );

desc = sb.ToString();
}

list.Add( new CommandInfo( command.AccessLevel, cmd, aliases, usage, desc ) );

for( int j = 0; j < aliases.Length; j++ )
{
string[] newAliases = new string[aliases.Length];

aliases.CopyTo( newAliases, 0 );

newAliases[j] = cmd;

list.Add( new CommandInfo( command.AccessLevel, aliases[j], newAliases, usage, desc ) );
}
}

List<BaseCommandImplementor> commandImpls = BaseCommandImplementor.Implementors;

for( int i = 0; i < commandImpls.Count; ++i )
{
BaseCommandImplementor command = commandImpls[i];

string usage = command.Usage;
string desc = command.Description;

if( usage == null || desc == null )
continue;

string[] cmds = command.Accessors;
string cmd = cmds[0];
string[] aliases = new string[cmds.Length - 1];

for( int j = 0; j < aliases.Length; ++j )
aliases[j] = cmds[j + 1];

desc = desc.Replace( "<", ")" ).Replace( ">", ")" );

list.Add( new CommandInfo( command.AccessLevel, cmd, aliases, usage, desc ) );

for( int j = 0; j < aliases.Length; j++ )
{
string[] newAliases = new string[aliases.Length];

aliases.CopyTo( newAliases, 0 );

newAliases[j] = cmd;

list.Add( new CommandInfo( command.AccessLevel, aliases[j], newAliases, usage, desc ) );
}
}

list.Sort( new CommandInfoSorter() );

m_SortedHelpInfo = list;

foreach( CommandInfo c in m_SortedHelpInfo )
{
if( !m_HelpInfos.ContainsKey( c.Name.ToLower() ) )
m_HelpInfos.Add( c.Name.ToLower(), c );
}
}

public class CommandListGump : BaseGridGump
{
private const int EntriesPerPage = 15;

int m_Page;
List<CommandInfo> m_List;

public CommandListGump( int page, Mobile from, List<CommandInfo> list )
: base( 30, 30 )
{
m_Page = page;

if( list == null )
{
m_List = new List<CommandInfo>();

foreach( CommandInfo c in m_SortedHelpInfo )
{
if( from.AccessLevel >= c.AccessLevel )
m_List.Add( c );
}
}
else
m_List = list;


AddNewPage();

if( m_Page > 0 )
AddEntryButton( 20, ArrowLeftID1, ArrowLeftID2, 1, ArrowLeftWidth, ArrowLeftHeight );
else
AddEntryHeader( 20 );

AddEntryHtml( 160, Center( String.Format( "Page {0} of {1}", m_Page+1, (m_List.Count + EntriesPerPage - 1) / EntriesPerPage ) ) );

if( (m_Page + 1) * EntriesPerPage < m_List.Count )
AddEntryButton( 20, ArrowRightID1, ArrowRightID2, 2, ArrowRightWidth, ArrowRightHeight );
else
AddEntryHeader( 20 );

int last = (int)AccessLevel.Player - 1;

for( int i = m_Page * EntriesPerPage, line = 0; line < EntriesPerPage && i < m_List.Count; ++i, ++line )
{
CommandInfo c = m_List[i];
if( from.AccessLevel >= c.AccessLevel )
{
if( (int)c.AccessLevel != last )
{
AddNewLine();

AddEntryHtml( 20 + OffsetSize + 160, Color( c.AccessLevel.ToString(), 0xFF0000 ) );
AddEntryHeader( 20 );
line++;
}

last = (int)c.AccessLevel;

AddNewLine();

AddEntryHtml( 20 + OffsetSize + 160, c.Name );

AddEntryButton( 20, ArrowRightID1, ArrowRightID2, 3 + i, ArrowRightWidth, ArrowRightHeight );
}
}

FinishPage();
}

public override void OnResponse( NetState sender, RelayInfo info )
{
Mobile m = sender.Mobile;
switch( info.ButtonID )
{
case 0:
{
m.CloseGump( typeof( CommandInfoGump ) );
break;
}
case 1:
{
if( m_Page > 0 )
m.SendGump( new CommandListGump( m_Page - 1, m, m_List ) );

break;
}
case 2:
{
if( (m_Page + 1) * EntriesPerPage < m_SortedHelpInfo.Count )
m.SendGump( new CommandListGump( m_Page + 1, m, m_List ) );

break;
}
default:
{

int v = info.ButtonID - 3;

if( v >= 0 && v < m_List.Count )
{
CommandInfo c = m_List[v];

if( m.AccessLevel >= c.AccessLevel )
{
m.SendGump( new CommandInfoGump( c ) );
m.SendGump( new CommandListGump( m_Page, m, m_List ) );
}
else
{
m.SendMessage( "You no longer have access to that command." );
m.SendGump( new CommandListGump( m_Page, m, null ) );
}
}
break;
}
}
}
}


public class CommandInfoGump : Gump
{
public string Color( string text, int color )
{
return String.Format( "<BASEFONT COLOR=#{0:X6}>{1}</BASEFONT>", color, text );
}

public string Center( string text )
{
return String.Format( "<CENTER>{0}</CENTER>", text );
}

public CommandInfoGump( CommandInfo info )
: this( info, 320, 200 )
{
}

public CommandInfoGump( CommandInfo info, int width, int height )
: base( 300, 50 )
{
AddPage( 0 );

AddBackground( 0, 0, width, height, 5054 );

//AddImageTiled( 10, 10, width - 20, 20, 2624 );
//AddAlphaRegion( 10, 10, width - 20, 20 );
//AddHtmlLocalized( 10, 10, width - 20, 20, header, headerColor, false, false );
AddHtml( 10, 10, width - 20, 20, Color( Center( info.Name ), 0xFF0000 ), false, false );

//AddImageTiled( 10, 40, width - 20, height - 80, 2624 );
//AddAlphaRegion( 10, 40, width - 20, height - 80 );

StringBuilder sb = new StringBuilder();

sb.Append( "Usage: " );
sb.Append( info.Usage.Replace( "<", "(" ).Replace( ">", ")" ) );
sb.Append( "<BR>" );

string[] aliases = info.Aliases;

if( aliases != null && aliases.Length != 0 )
{
sb.Append( String.Format( "Alias{0}: ", aliases.Length == 1 ? "" : "es" ) );

for( int i = 0; i < aliases.Length; ++i )
{
if( i != 0 )
sb.Append( ", " );

sb.Append( aliases[i] );
}

sb.Append( "<BR>" );
}

sb.Append( "AccessLevel: " );
sb.Append( info.AccessLevel.ToString() );
sb.Append( "<BR>" );
sb.Append( "<BR>" );

sb.Append( info.Description );

AddHtml( 10, 40, width - 20, height - 80, sb.ToString(), false, true );

//AddImageTiled( 10, height - 30, width - 20, 20, 2624 );
//AddAlphaRegion( 10, height - 30, width - 20, 20 );

}
}
}
}



using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
using System.Reflection.Emit;
using Emit = System.Reflection.Emit;

namespace Server
{
public class AssemblyEmitter
{
private string m_AssemblyName;

private AppDomain m_AppDomain;
private AssemblyBuilder m_AssemblyBuilder;
private ModuleBuilder m_ModuleBuilder;

public AssemblyEmitter( string assemblyName, bool canSave )
{
m_AssemblyName = assemblyName;

m_AppDomain = AppDomain.CurrentDomain;

m_AssemblyBuilder = m_AppDomain.DefineDynamicAssembly(
new AssemblyName( assemblyName ),
canSave ? AssemblyBuilderAccess.RunAndSave : AssemblyBuilderAccess.Run
);

if ( canSave )
{
m_ModuleBuilder = m_AssemblyBuilder.DefineDynamicModule(
assemblyName,
String.Format( "{0}.dll", assemblyName.ToLower() ),
false
);
}
else
{
m_ModuleBuilder = m_AssemblyBuilder.DefineDynamicModule(
assemblyName,
false
);
}
}

public TypeBuilder DefineType( string typeName, TypeAttributes attrs, Type parentType )
{
return m_ModuleBuilder.DefineType( typeName, attrs, parentType );
}

public void Save()
{
m_AssemblyBuilder.Save(
String.Format( "{0}.dll", m_AssemblyName.ToLower() )
);
}
}

public class MethodEmitter
{
private TypeBuilder m_TypeBuilder;

private MethodBuilder m_Builder;
private ILGenerator m_Generator;

private Type[] m_ArgumentTypes;

public TypeBuilder Type
{
get { return m_TypeBuilder; }
}

public ILGenerator Generator
{
get { return m_Generator; }
}

private class CallInfo
{
public Type type;
public MethodInfo method;

public int index;
public ParameterInfo[] parms;

public CallInfo( Type type, MethodInfo method )
{
this.type = type;
this.method = method;

this.parms = method.GetParameters();
}
}

private Stack<Type> m_Stack;
private Stack<CallInfo> m_Calls;

private Dictionary<Type, Queue<LocalBuilder>> m_Temps;

public MethodBuilder Method
{
get { return m_Builder; }
}

public MethodEmitter( TypeBuilder typeBuilder )
{
m_TypeBuilder = typeBuilder;

m_Temps = new Dictionary<Type, Queue<LocalBuilder>>();

m_Stack = new Stack<Type>();
m_Calls = new Stack<CallInfo>();
}

public void Define( string name, MethodAttributes attr, Type returnType, Type[] parms )
{
m_Builder = m_TypeBuilder.DefineMethod( name, attr, returnType, parms );
m_Generator = m_Builder.GetILGenerator();

m_ArgumentTypes = parms;
}

public LocalBuilder CreateLocal( Type localType )
{
return m_Generator.DeclareLocal( localType );
}

public LocalBuilder AcquireTemp( Type localType )
{
Queue<LocalBuilder> list;

if ( !m_Temps.TryGetValue( localType, out list ) )
m_Temps[localType] = list = new Queue<LocalBuilder>();

if ( list.Count > 0 )
return list.Dequeue();

return CreateLocal( localType );
}

public void ReleaseTemp( LocalBuilder local )
{
Queue<LocalBuilder> list;

if ( !m_Temps.TryGetValue( local.LocalType, out list ) )
m_Temps[local.LocalType] = list = new Queue<LocalBuilder>();

list.Enqueue( local );
}

public void Branch( Label label )
{
m_Generator.Emit( OpCodes.Br, label );
}

public void BranchIfFalse( Label label )
{
Pop( typeof( object ) );

m_Generator.Emit( OpCodes.Brfalse, label );
}

public void BranchIfTrue( Label label )
{
Pop( typeof( object ) );

m_Generator.Emit( OpCodes.Brtrue, label );
}

public Label CreateLabel()
{
return m_Generator.DefineLabel();
}

public void MarkLabel( Label label )
{
m_Generator.MarkLabel( label );
}

public void Pop()
{
m_Stack.Pop();
}

public void Pop( Type expected )
{
if ( expected == null )
throw new InvalidOperationException( "Expected type cannot be null." );

Type onStack = m_Stack.Pop();

if ( expected == typeof( bool ) )
expected = typeof( int );

if ( onStack == typeof( bool ) )
onStack = typeof( int );

if ( !expected.IsAssignableFrom( onStack ) )
throw new InvalidOperationException( "Unexpected stack state." );
}

public void Push( Type type )
{
m_Stack.Push( type );
}

public void Return()
{
if ( m_Stack.Count != ( m_Builder.ReturnType == typeof( void ) ? 0 : 1 ) )
throw new InvalidOperationException( "Stack return mismatch." );

m_Generator.Emit( OpCodes.Ret );
}

public void LoadNull()
{
LoadNull( typeof( object ) );
}

public void LoadNull( Type type )
{
Push( type );

m_Generator.Emit( OpCodes.Ldnull );
}

public void Load( string value )
{
Push( typeof( string ) );

if ( value != null )
m_Generator.Emit( OpCodes.Ldstr, value );
else
m_Generator.Emit( OpCodes.Ldnull );
}

public void Load( Enum value )
{
int toLoad = ((IConvertible)value).ToInt32( null );
Load( toLoad );

Pop();
Push( value.GetType() );
}

public void Load( long value )
{
Push( typeof( long ) );

m_Generator.Emit( OpCodes.Ldc_I8, value );
}

public void Load( float value )
{
Push( typeof( float ) );

m_Generator.Emit( OpCodes.Ldc_R4, value );
}

public void Load( double value )
{
Push( typeof( double ) );

m_Generator.Emit( OpCodes.Ldc_R8, value );
}

public void Load( char value )
{
Load( (int) value );

Pop();
Push( typeof( char ) );
}

public void Load( bool value )
{
Push( typeof( bool ) );

if ( value )
m_Generator.Emit( OpCodes.Ldc_I4_1 );
else
m_Generator.Emit( OpCodes.Ldc_I4_0 );
}

public void Load( int value )
{
Push( typeof( int ) );

switch ( value )
{
case -1:
m_Generator.Emit( OpCodes.Ldc_I4_M1 );
break;

case 0:
m_Generator.Emit( OpCodes.Ldc_I4_0 );
break;

case 1:
m_Generator.Emit( OpCodes.Ldc_I4_1 );
break;

case 2:
m_Generator.Emit( OpCodes.Ldc_I4_2 );
break;

case 3:
m_Generator.Emit( OpCodes.Ldc_I4_3 );
break;

case 4:
m_Generator.Emit( OpCodes.Ldc_I4_4 );
break;

case 5:
m_Generator.Emit( OpCodes.Ldc_I4_5 );
break;

case 6:
m_Generator.Emit( OpCodes.Ldc_I4_6 );
break;

case 7:
m_Generator.Emit( OpCodes.Ldc_I4_7 );
break;

case 8:
m_Generator.Emit( OpCodes.Ldc_I4_8 );
break;

default:
if ( value >= sbyte.MinValue && value <= sbyte.MaxValue )
m_Generator.Emit( OpCodes.Ldc_I4_S, (sbyte) value );
else
m_Generator.Emit( OpCodes.Ldc_I4, value );

break;
}
}

public void LoadField( FieldInfo field )
{
Pop( field.DeclaringType );

Push( field.FieldType );

m_Generator.Emit( OpCodes.Ldfld, field );
}

public void LoadLocal( LocalBuilder local )
{
Push( local.LocalType );

int index = local.LocalIndex;

switch ( index )
{
case 0:
m_Generator.Emit( OpCodes.Ldloc_0 );
break;

case 1:
m_Generator.Emit( OpCodes.Ldloc_1 );
break;

case 2:
m_Generator.Emit( OpCodes.Ldloc_2 );
break;

case 3:
m_Generator.Emit( OpCodes.Ldloc_3 );
break;

default:
if ( index >= byte.MinValue && index <= byte.MinValue )
m_Generator.Emit( OpCodes.Ldloc_S, (byte) index );
else
m_Generator.Emit( OpCodes.Ldloc, (short) index );

break;
}
}

public void StoreLocal( LocalBuilder local )
{
Pop( local.LocalType );

m_Generator.Emit( OpCodes.Stloc, local );
}

public void LoadArgument( int index )
{
if ( index > 0 )
Push( m_ArgumentTypes[index - 1] );
else
Push( m_TypeBuilder );

switch ( index )
{
case 0:
m_Generator.Emit( OpCodes.Ldarg_0 );
break;

case 1:
m_Generator.Emit( OpCodes.Ldarg_1 );
break;

case 2:
m_Generator.Emit( OpCodes.Ldarg_2 );
break;

case 3:
m_Generator.Emit( OpCodes.Ldarg_3 );
break;

default:
if ( index >= byte.MinValue && index <= byte.MaxValue )
m_Generator.Emit( OpCodes.Ldarg_S, (byte) index );
else
m_Generator.Emit( OpCodes.Ldarg, (short) index );

break;
}
}

public void CastAs( Type type )
{
Pop( typeof( object ) );
Push( type );

m_Generator.Emit( OpCodes.Isinst, type );
}

public void Neg()
{
Pop( typeof( int ) );

Push( typeof( int ) );

m_Generator.Emit( OpCodes.Neg );
}

public void Compare( OpCode opCode )
{
Pop();
Pop();

Push( typeof( int ) );

m_Generator.Emit( opCode );
}

public void LogicalNot()
{
Pop( typeof( int ) );

Push( typeof( int ) );

m_Generator.Emit( OpCodes.Ldc_I4_0 );
m_Generator.Emit( OpCodes.Ceq );
}

public void Xor()
{
Pop( typeof( int ) );
Pop( typeof( int ) );

Push( typeof( int ) );

m_Generator.Emit( OpCodes.Xor );
}

public Type Active
{
get { return m_Stack.Peek(); }
}

public void Chain( Property prop )
{
for ( int i = 0; i < prop.Chain.Length; ++i )
Call( prop.Chain[i].GetGetMethod() );
}

public void Call( MethodInfo method )
{
BeginCall( method );

CallInfo call = m_Calls.Peek();

if ( call.parms.Length > 0 )
throw new InvalidOperationException( "Method requires parameters." );

FinishCall();
}

public delegate void Callback();

public bool CompareTo( int sign, Callback argGenerator )
{
Type active = this.Active;

MethodInfo compareTo = active.GetMethod( "CompareTo", new Type[] { active } );

if ( compareTo == null )
{
/* This gets a little tricky...
*
* There's a scenario where we might be trying to use CompareTo on an interface
* which, while it doesn't explicitly implement CompareTo itself, is said to
* extend IComparable indirectly. The implementation is implicitly passed off
* to implementers...
*
* interface ISomeInterface : IComparable
* {
* void SomeMethod();
* }
*
* class SomeClass : ISomeInterface
* {
* void SomeMethod() { ... }
* int CompareTo( object other ) { ... }
* }
*
* In this case, calling ISomeInterface.GetMethod( "CompareTo" ) will return null.
*
* Bleh.
*/

Type[] ifaces = active.FindInterfaces( delegate( Type type, object obj )
{
return ( type.IsGenericType )
&& ( type.GetGenericTypeDefinition() == typeof( IComparable<> ) )
&& ( type.GetGenericArguments()[0].IsAssignableFrom( active ) );
}, null );

if ( ifaces.Length > 0 )
{
compareTo = ifaces[0].GetMethod( "CompareTo", new Type[] { active } );
}
else
{
ifaces = active.FindInterfaces( delegate( Type type, object obj )
{
return ( type == typeof( IComparable ) );
}, null );

if ( ifaces.Length > 0 )
compareTo = ifaces[0].GetMethod( "CompareTo", new Type[] { active } );
}
}

if ( compareTo == null )
return false;

if ( !active.IsValueType )
{
/* This object is a reference type, so we have to make it behave
*
* null.CompareTo( null ) = 0
* real.CompareTo( null ) = -1
* null.CompareTo( real ) = +1
*
*/

LocalBuilder aValue = AcquireTemp( active );
LocalBuilder bValue = AcquireTemp( active );

StoreLocal( aValue );

argGenerator();

StoreLocal( bValue );

/* if ( aValue == null )
* {
* if ( bValue == null )
* v = 0;
* else
* v = +1;
* }
* else if ( bValue == null )
* {
* v = -1;
* }
* else
* {
* v = aValue.CompareTo( bValue );
* }
*/

Label store = CreateLabel();

Label aNotNull = CreateLabel();

LoadLocal( aValue );
BranchIfTrue( aNotNull );
// if ( aValue == null )
{
Label bNotNull = CreateLabel();

LoadLocal( bValue );
BranchIfTrue( bNotNull );
// if ( bValue == null )
{
Load( 0 );
Pop( typeof( int ) );
Branch( store );
}
MarkLabel( bNotNull );
// else
{
Load( sign );
Pop( typeof( int ) );
Branch( store );
}
}
MarkLabel( aNotNull );
// else
{
Label bNotNull = CreateLabel();

LoadLocal( bValue );
BranchIfTrue( bNotNull );
// bValue == null
{
Load( -sign );
Pop( typeof( int ) );
Branch( store );
}
MarkLabel( bNotNull );
// else
{
LoadLocal( aValue );
BeginCall( compareTo );

LoadLocal( bValue );
ArgumentPushed();

FinishCall();

if ( sign == -1 )
Neg();
}
}

MarkLabel( store );

ReleaseTemp( aValue );
ReleaseTemp( bValue );
}
else
{
BeginCall( compareTo );

argGenerator();

ArgumentPushed();

FinishCall();

if ( sign == -1 )
Neg();
}

return true;
}

public void BeginCall( MethodInfo method )
{
Type type;

if ( ( method.CallingConvention & CallingConventions.HasThis ) != 0 )
type = m_Stack.Peek();
else
type = method.DeclaringType;

m_Calls.Push( new CallInfo( type, method ) );

if ( type.IsValueType )
{
LocalBuilder temp = AcquireTemp( type );

m_Generator.Emit( OpCodes.Stloc, temp );
m_Generator.Emit( OpCodes.Ldloca, temp );

ReleaseTemp( temp );
}
}

public void FinishCall()
{
CallInfo call = m_Calls.Pop();

if ( ( call.type.IsValueType || call.type.IsByRef ) && call.method.DeclaringType != call.type )
m_Generator.Emit( OpCodes.Constrained, call.type );

if ( call.method.DeclaringType.IsValueType || call.method.IsStatic )
m_Generator.Emit( OpCodes.Call, call.method );
else
m_Generator.Emit( OpCodes.Callvirt, call.method );

for ( int i = call.parms.Length - 1; i >= 0; --i )
Pop( call.parms[i].ParameterType );

if ( ( call.method.CallingConvention & CallingConventions.HasThis ) != 0 )
Pop( call.method.DeclaringType );

if ( call.method.ReturnType != typeof( void ) )
Push( call.method.ReturnType );
}

public void ArgumentPushed()
{
CallInfo call = m_Calls.Peek();

ParameterInfo parm = call.parms[call.index++];

Type argumentType = m_Stack.Peek();

if ( !parm.ParameterType.IsAssignableFrom( argumentType ) )
throw new InvalidOperationException( "Parameter type mismatch." );

if ( argumentType.IsValueType && !parm.ParameterType.IsValueType )
m_Generator.Emit( OpCodes.Box, argumentType );
}
}
}


Any help would be greatly appreciated. only a few errors away from making the upgrade. thanks again
Treetall is offline   Reply With Quote
Old 08-24-2008, 04:26 PM   #5 (permalink)
Forum Expert
 
typhoonbot's Avatar
 
Join Date: Dec 2006
Posts: 478
Default

jeez! MY EYES!!!!

Do everyone a favor m8, paste your pieces of code into "[code]" tags

You can just highlight the pieces of script and click the button labeled "#"

Regards
__________________
legendsofkaine.page.tl
typhoonbot is offline   Reply With Quote
Old 08-24-2008, 09:06 PM   #6 (permalink)
Forum Novice
 
Arkryal's Avatar
 
Join Date: Jan 2003
Location: Rochester NY
Age: 27
Posts: 208
Default

The problem is you have scripts that were made for RunUO 1.0 and you're trying to run them on RunUO 2.0.

Check the script release section for updated versions of those scripts and it will knock about half of those errors out and may shed a little light on the others.
__________________
•¤•¤•Arkryal •¤•¤•
Arkryal 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