From 2a3c79df83e800d5dfe75a1a3b140ed81da2b1d6 Mon Sep 17 00:00:00 2001
From: Sean Dague
Date: Mon, 16 Jul 2007 15:40:11 +0000
Subject: changed to native line ending encoding

---
 OpenSim/Region/Environment/Scenes/Entity.cs        |  230 +--
 OpenSim/Region/Environment/Scenes/EntityBase.cs    |  284 +--
 .../Environment/Scenes/IScenePresenceBody.cs       |   28 +-
 OpenSim/Region/Environment/Scenes/Primitive.cs     | 1296 +++++++-------
 .../Environment/Scenes/Scene.PacketHandlers.cs     | 1236 ++++++-------
 OpenSim/Region/Environment/Scenes/Scene.cs         | 1838 ++++++++++----------
 OpenSim/Region/Environment/Scenes/SceneBase.cs     |  390 ++---
 OpenSim/Region/Environment/Scenes/SceneEvents.cs   |  164 +-
 OpenSim/Region/Environment/Scenes/SceneObject.cs   |  618 +++----
 .../Environment/Scenes/ScenePresence.Animations.cs |  148 +-
 .../Environment/Scenes/ScenePresence.Body.cs       |  170 +-
 OpenSim/Region/Environment/Scenes/ScenePresence.cs | 1246 ++++++-------
 .../Engines/CSharpEngine/CSharpScriptEngine.cs     |  204 +--
 .../CSharpEngine/Examples/ExportRegionToLSL.cs     |  138 +-
 .../Engines/JScriptEngine/JScriptEngine.cs         |  204 +--
 .../Engines/JVMEngine/JVM/ClassInstance.cs         |   90 +-
 .../scripting/Engines/JVMEngine/JVM/ClassRecord.cs | 1006 +++++------
 .../Scenes/scripting/Engines/JVMEngine/JVM/Heap.cs |   86 +-
 .../Engines/JVMEngine/JVM/Interpreter.Logic.cs     |  854 ++++-----
 .../Engines/JVMEngine/JVM/Interpreter.Methods.cs   |  192 +-
 .../Engines/JVMEngine/JVM/Interpreter.Return.cs    |   80 +-
 .../scripting/Engines/JVMEngine/JVM/Interpreter.cs |  270 +--
 .../scripting/Engines/JVMEngine/JVM/MainMemory.cs  |   90 +-
 .../Engines/JVMEngine/JVM/MethodMemory.cs          |   92 +-
 .../scripting/Engines/JVMEngine/JVM/Object.cs      |   74 +-
 .../scripting/Engines/JVMEngine/JVM/Stack.cs       |   84 +-
 .../scripting/Engines/JVMEngine/JVM/StackFrame.cs  |   98 +-
 .../scripting/Engines/JVMEngine/JVM/Thread.cs      |  238 +--
 .../scripting/Engines/JVMEngine/JavaEngine.cs      |   58 +-
 .../scripting/Engines/JVMEngine/OpenSimJVM.cs      |  340 ++--
 .../Engines/JVMEngine/Types/ArrayReference.cs      |   20 +-
 .../scripting/Engines/JVMEngine/Types/BaseType.cs  |   20 +-
 .../Engines/JVMEngine/Types/ObjectReference.cs     |   32 +-
 .../Engines/JVMEngine/Types/PrimitiveTypes/Byte.cs |   20 +-
 .../Engines/JVMEngine/Types/PrimitiveTypes/Char.cs |   20 +-
 .../JVMEngine/Types/PrimitiveTypes/Float.cs        |   32 +-
 .../Engines/JVMEngine/Types/PrimitiveTypes/Int.cs  |   32 +-
 .../Engines/LSLEngine/LSLHandler/Engine.cs         |  280 +--
 .../LSLEngine/LSLHandler/LSL_CLRInterface.cs       |  102 +-
 .../Engines/LSLEngine/LSLHandler/LSO_Enums.cs      |  970 +++++------
 .../Engines/LSLEngine/LSLHandler/LSO_Parser.cs     | 1216 ++++++-------
 .../Engines/LSLEngine/LSLHandler/LSO_Struct.cs     |  210 +--
 .../Region/Environment/Scenes/scripting/Script.cs  |  128 +-
 .../Environment/Scenes/scripting/ScriptAPI.cs      |   64 +-
 .../Environment/Scenes/scripting/ScriptInfo.cs     |  116 +-
 .../Scenes/scripting/ScriptInterpretedAPI.cs       |  412 ++---
 .../Scenes/scripting/ScriptInterpretedEvents.cs    |   32 +-
 .../Environment/Scenes/scripting/ScriptManager.cs  |  214 +--
 48 files changed, 7883 insertions(+), 7883 deletions(-)

(limited to 'OpenSim/Region/Environment/Scenes')

diff --git a/OpenSim/Region/Environment/Scenes/Entity.cs b/OpenSim/Region/Environment/Scenes/Entity.cs
index 084c9ab..2456a4e 100644
--- a/OpenSim/Region/Environment/Scenes/Entity.cs
+++ b/OpenSim/Region/Environment/Scenes/Entity.cs
@@ -1,115 +1,115 @@
-/*
-* Copyright (c) Contributors, http://www.openmetaverse.org/
-* See CONTRIBUTORS.TXT for a full list of copyright holders.
-*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted provided that the following conditions are met:
-*     * Redistributions of source code must retain the above copyright
-*       notice, this list of conditions and the following disclaimer.
-*     * Redistributions in binary form must reproduce the above copyright
-*       notice, this list of conditions and the following disclaimer in the
-*       documentation and/or other materials provided with the distribution.
-*     * Neither the name of the OpenSim Project nor the
-*       names of its contributors may be used to endorse or promote products
-*       derived from this software without specific prior written permission.
-*
-* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
-* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
-* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-* 
-*/
-using System;
-using libsecondlife;
-using OpenSim.Physics.Manager;
-
-namespace OpenSim.Region.Environment.Scenes
-{
-    public abstract class Entity :EntityBase //this class (Entity) will be phased out 
-    {     
-        protected PhysicsActor _physActor;
-
-        /// <summary>
-        /// 
-        /// </summary>
-        public override LLVector3 Pos
-        {
-            get
-            {
-                if (this._physActor != null)
-                {
-                    m_pos.X = _physActor.Position.X;
-                    m_pos.Y = _physActor.Position.Y;
-                    m_pos.Z = _physActor.Position.Z;
-                }
-
-                return m_pos;
-            }
-            set
-            {
-                if (this._physActor != null)
-                {
-                    try
-                    {
-                        lock (this.m_world.SyncRoot)
-                        {
-
-                            this._physActor.Position = new PhysicsVector(value.X, value.Y, value.Z);
-                        }
-                    }
-                    catch (Exception e)
-                    {
-                        Console.WriteLine(e.Message);
-                    }
-                }
-
-                m_pos = value;
-            }
-        }
-
-       
-        /// <summary>
-        /// 
-        /// </summary>
-        public override LLVector3 Velocity
-        {
-            get
-            {
-                if (this._physActor != null)
-                {
-                    m_velocity.X = _physActor.Velocity.X;
-                    m_velocity.Y = _physActor.Velocity.Y;
-                    m_velocity.Z = _physActor.Velocity.Z;
-                }
-
-                return m_velocity;
-            }
-            set
-            {
-                if (this._physActor != null)
-                {
-                    try
-                    {
-                        lock (this.m_world.SyncRoot)
-                        {
-
-                            this._physActor.Velocity = new PhysicsVector(value.X, value.Y, value.Z);
-                        }
-                    }
-                    catch (Exception e)
-                    {
-                        Console.WriteLine(e.Message);
-                    }
-                }
-
-                m_velocity = value;
-            }
-        }
-    }
-}
+/*
+* Copyright (c) Contributors, http://www.openmetaverse.org/
+* See CONTRIBUTORS.TXT for a full list of copyright holders.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*     * Redistributions of source code must retain the above copyright
+*       notice, this list of conditions and the following disclaimer.
+*     * Redistributions in binary form must reproduce the above copyright
+*       notice, this list of conditions and the following disclaimer in the
+*       documentation and/or other materials provided with the distribution.
+*     * Neither the name of the OpenSim Project nor the
+*       names of its contributors may be used to endorse or promote products
+*       derived from this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
+* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
+* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+* 
+*/
+using System;
+using libsecondlife;
+using OpenSim.Physics.Manager;
+
+namespace OpenSim.Region.Environment.Scenes
+{
+    public abstract class Entity :EntityBase //this class (Entity) will be phased out 
+    {     
+        protected PhysicsActor _physActor;
+
+        /// <summary>
+        /// 
+        /// </summary>
+        public override LLVector3 Pos
+        {
+            get
+            {
+                if (this._physActor != null)
+                {
+                    m_pos.X = _physActor.Position.X;
+                    m_pos.Y = _physActor.Position.Y;
+                    m_pos.Z = _physActor.Position.Z;
+                }
+
+                return m_pos;
+            }
+            set
+            {
+                if (this._physActor != null)
+                {
+                    try
+                    {
+                        lock (this.m_world.SyncRoot)
+                        {
+
+                            this._physActor.Position = new PhysicsVector(value.X, value.Y, value.Z);
+                        }
+                    }
+                    catch (Exception e)
+                    {
+                        Console.WriteLine(e.Message);
+                    }
+                }
+
+                m_pos = value;
+            }
+        }
+
+       
+        /// <summary>
+        /// 
+        /// </summary>
+        public override LLVector3 Velocity
+        {
+            get
+            {
+                if (this._physActor != null)
+                {
+                    m_velocity.X = _physActor.Velocity.X;
+                    m_velocity.Y = _physActor.Velocity.Y;
+                    m_velocity.Z = _physActor.Velocity.Z;
+                }
+
+                return m_velocity;
+            }
+            set
+            {
+                if (this._physActor != null)
+                {
+                    try
+                    {
+                        lock (this.m_world.SyncRoot)
+                        {
+
+                            this._physActor.Velocity = new PhysicsVector(value.X, value.Y, value.Z);
+                        }
+                    }
+                    catch (Exception e)
+                    {
+                        Console.WriteLine(e.Message);
+                    }
+                }
+
+                m_velocity = value;
+            }
+        }
+    }
+}
diff --git a/OpenSim/Region/Environment/Scenes/EntityBase.cs b/OpenSim/Region/Environment/Scenes/EntityBase.cs
index 65a0395..04cf595 100644
--- a/OpenSim/Region/Environment/Scenes/EntityBase.cs
+++ b/OpenSim/Region/Environment/Scenes/EntityBase.cs
@@ -1,142 +1,142 @@
-using System.Collections.Generic;
-using Axiom.Math;
-using libsecondlife;
-
-namespace OpenSim.Region.Environment.Scenes
-{
-    public abstract class EntityBase
-    {
-        public LLUUID uuid;
-       
-        protected List<EntityBase> children;
-
-        protected Scene m_world;
-        protected string m_name;
-
-        /// <summary>
-        /// 
-        /// </summary>
-        public virtual string Name
-        {
-            get { return m_name; }
-            set { m_name = value; }
-        }
-
-        protected LLVector3 m_pos;
-        /// <summary>
-        /// 
-        /// </summary>
-        public virtual LLVector3 Pos
-        {
-            get
-            {       
-                return m_pos;
-            }
-            set
-            {
-                m_pos = value;
-            }
-        }
-
-        public LLVector3 m_velocity;
-
-        /// <summary>
-        /// 
-        /// </summary>
-        public virtual LLVector3 Velocity
-        {
-            get
-            {
-                return m_velocity;
-            }
-            set
-            {
-                m_velocity = value;
-            }
-        }
-
-        protected Quaternion m_rotation = new Quaternion(0,0,1,0);
-
-        public virtual Quaternion Rotation
-        {
-            get
-            {
-                return m_rotation;
-            }
-            set
-            {
-                m_rotation = value;
-            }
-        }
-
-        protected uint m_localId;
-
-        public uint LocalId
-        {
-            get { return m_localId; }
-            set { m_localId = value; }
-        }
-
-        /// <summary>
-        /// Creates a new Entity (should not occur on it's own)
-        /// </summary>
-        public EntityBase()
-        {
-            uuid = new LLUUID();
-
-            m_pos = new LLVector3();
-            m_velocity = new LLVector3();
-            Rotation = new Quaternion();
-            m_name = "(basic entity)";
-            children = new List<EntityBase>();
-        }
-
-        /// <summary>
-        /// 
-        /// </summary>
-        public virtual void updateMovement()
-        {
-            foreach (EntityBase child in children)
-            {
-                child.updateMovement();
-            }
-        }
-
-        /// <summary>
-        /// Performs any updates that need to be done at each frame. This function is overridable from it's children.
-        /// </summary>
-        public virtual void update()
-        {
-            // Do any per-frame updates needed that are applicable to every type of entity
-            foreach (EntityBase child in children)
-            {
-                child.update();
-            }
-        }
-
-        /// <summary>
-        /// Called at a set interval to inform entities that they should back themsleves up to the DB 
-        /// </summary>
-        public virtual void BackUp()
-        {
-
-        }
-
-        /// <summary>
-        /// Copies the entity
-        /// </summary>
-        /// <returns></returns>
-        public virtual EntityBase Copy()
-        {
-            return (EntityBase)this.MemberwiseClone();
-        }
-
-        /// <summary>
-        /// Infoms the entity that the land (heightmap) has changed
-        /// </summary>
-        public virtual void LandRenegerated()
-        {
-
-        }
-    }
-}
+using System.Collections.Generic;
+using Axiom.Math;
+using libsecondlife;
+
+namespace OpenSim.Region.Environment.Scenes
+{
+    public abstract class EntityBase
+    {
+        public LLUUID uuid;
+       
+        protected List<EntityBase> children;
+
+        protected Scene m_world;
+        protected string m_name;
+
+        /// <summary>
+        /// 
+        /// </summary>
+        public virtual string Name
+        {
+            get { return m_name; }
+            set { m_name = value; }
+        }
+
+        protected LLVector3 m_pos;
+        /// <summary>
+        /// 
+        /// </summary>
+        public virtual LLVector3 Pos
+        {
+            get
+            {       
+                return m_pos;
+            }
+            set
+            {
+                m_pos = value;
+            }
+        }
+
+        public LLVector3 m_velocity;
+
+        /// <summary>
+        /// 
+        /// </summary>
+        public virtual LLVector3 Velocity
+        {
+            get
+            {
+                return m_velocity;
+            }
+            set
+            {
+                m_velocity = value;
+            }
+        }
+
+        protected Quaternion m_rotation = new Quaternion(0,0,1,0);
+
+        public virtual Quaternion Rotation
+        {
+            get
+            {
+                return m_rotation;
+            }
+            set
+            {
+                m_rotation = value;
+            }
+        }
+
+        protected uint m_localId;
+
+        public uint LocalId
+        {
+            get { return m_localId; }
+            set { m_localId = value; }
+        }
+
+        /// <summary>
+        /// Creates a new Entity (should not occur on it's own)
+        /// </summary>
+        public EntityBase()
+        {
+            uuid = new LLUUID();
+
+            m_pos = new LLVector3();
+            m_velocity = new LLVector3();
+            Rotation = new Quaternion();
+            m_name = "(basic entity)";
+            children = new List<EntityBase>();
+        }
+
+        /// <summary>
+        /// 
+        /// </summary>
+        public virtual void updateMovement()
+        {
+            foreach (EntityBase child in children)
+            {
+                child.updateMovement();
+            }
+        }
+
+        /// <summary>
+        /// Performs any updates that need to be done at each frame. This function is overridable from it's children.
+        /// </summary>
+        public virtual void update()
+        {
+            // Do any per-frame updates needed that are applicable to every type of entity
+            foreach (EntityBase child in children)
+            {
+                child.update();
+            }
+        }
+
+        /// <summary>
+        /// Called at a set interval to inform entities that they should back themsleves up to the DB 
+        /// </summary>
+        public virtual void BackUp()
+        {
+
+        }
+
+        /// <summary>
+        /// Copies the entity
+        /// </summary>
+        /// <returns></returns>
+        public virtual EntityBase Copy()
+        {
+            return (EntityBase)this.MemberwiseClone();
+        }
+
+        /// <summary>
+        /// Infoms the entity that the land (heightmap) has changed
+        /// </summary>
+        public virtual void LandRenegerated()
+        {
+
+        }
+    }
+}
diff --git a/OpenSim/Region/Environment/Scenes/IScenePresenceBody.cs b/OpenSim/Region/Environment/Scenes/IScenePresenceBody.cs
index 7c3a033..8551b70 100644
--- a/OpenSim/Region/Environment/Scenes/IScenePresenceBody.cs
+++ b/OpenSim/Region/Environment/Scenes/IScenePresenceBody.cs
@@ -1,14 +1,14 @@
-using libsecondlife;
-using libsecondlife.Packets;
-using OpenSim.Framework.Interfaces;
-
-namespace OpenSim.Region.Environment.Scenes
-{
-    public interface IScenePresenceBody
-    {
-        void processMovement(IClientAPI remoteClient, uint flags, LLQuaternion bodyRotation);
-        void SetAppearance(byte[] texture, AgentSetAppearancePacket.VisualParamBlock[] visualParam);
-        void SendOurAppearance(IClientAPI OurClient);
-        void SendAppearanceToOtherAgent(ScenePresence avatarInfo);
-    }
-}
+using libsecondlife;
+using libsecondlife.Packets;
+using OpenSim.Framework.Interfaces;
+
+namespace OpenSim.Region.Environment.Scenes
+{
+    public interface IScenePresenceBody
+    {
+        void processMovement(IClientAPI remoteClient, uint flags, LLQuaternion bodyRotation);
+        void SetAppearance(byte[] texture, AgentSetAppearancePacket.VisualParamBlock[] visualParam);
+        void SendOurAppearance(IClientAPI OurClient);
+        void SendAppearanceToOtherAgent(ScenePresence avatarInfo);
+    }
+}
diff --git a/OpenSim/Region/Environment/Scenes/Primitive.cs b/OpenSim/Region/Environment/Scenes/Primitive.cs
index 0e5b083..b413758 100644
--- a/OpenSim/Region/Environment/Scenes/Primitive.cs
+++ b/OpenSim/Region/Environment/Scenes/Primitive.cs
@@ -1,648 +1,648 @@
-using System;
-using System.Collections.Generic;
-using Axiom.Math;
-using libsecondlife;
-using libsecondlife.Packets;
-using OpenSim.Framework.Interfaces;
-using OpenSim.Framework.Inventory;
-using OpenSim.Framework.Types;
-
-namespace OpenSim.Region.Environment.Scenes
-{
-    public delegate void PrimCountTaintedDelegate();
-
-    public class Primitive : EntityBase
-    {
-        private const uint FULL_MASK_PERMISSIONS = 2147483647;
-
-        private LLVector3 positionLastFrame = new LLVector3(0, 0, 0);
-        private ulong m_regionHandle;
-        private byte updateFlag = 0;
-        private uint m_flags = 32 + 65536 + 131072 + 256 + 4 + 8 + 2048 + 524288 + 268435456 + 128;
-
-        private Dictionary<LLUUID, InventoryItem> inventoryItems;
-
-        private string m_description = "";
-
-        public string SitName = "";
-        public string TouchName = "";
-        public string Text = "";
-
-        public LLUUID CreatorID;
-        public LLUUID OwnerID;
-        public LLUUID LastOwnerID;
-        public Int32 CreationDate;
-
-        public uint ParentID = 0;
-
-        public uint OwnerMask = FULL_MASK_PERMISSIONS;
-        public uint NextOwnerMask = FULL_MASK_PERMISSIONS;
-        public uint GroupMask = FULL_MASK_PERMISSIONS;
-        public uint EveryoneMask = FULL_MASK_PERMISSIONS;
-        public uint BaseMask = FULL_MASK_PERMISSIONS;
-
-        private PrimitiveBaseShape m_Shape;
-
-        public SceneObject m_RootParent;
-        public bool m_isRootPrim;
-        public EntityBase m_Parent;
-
-        private EventManager m_eventManager;
-
-        public event PrimCountTaintedDelegate OnPrimCountTainted;
-
-        #region Properties
-        /// <summary>
-        /// If rootprim, will return world position
-        /// otherwise will return local offset from rootprim
-        /// </summary>
-        public override LLVector3 Pos 
-        {
-            get
-            {
-                if (m_isRootPrim)
-                {
-                    //if we are rootprim then our offset should be zero
-                    return this.m_pos + m_Parent.Pos;
-                }
-                else
-                {
-                    return this.m_pos;
-                }
-            }
-            set
-            {
-                if (m_isRootPrim)
-                {
-                    m_Parent.Pos = value;
-                }
-                this.m_pos = value - m_Parent.Pos;
-            }
-
-        }
-
-        public PrimitiveBaseShape Shape
-        {
-            get
-            {
-                return this.m_Shape;
-            }
-        }
-
-        public LLVector3 WorldPos
-        {
-            get
-            {
-                if (!this.m_isRootPrim)
-                {
-                    Primitive parentPrim = (Primitive)this.m_Parent;
-                    Axiom.Math.Vector3 offsetPos = new Vector3(this.m_pos.X, this.m_pos.Y, this.m_pos.Z);
-                    offsetPos = parentPrim.Rotation * offsetPos;
-                    return parentPrim.WorldPos + new LLVector3(offsetPos.x, offsetPos.y, offsetPos.z);
-                }
-                else
-                {
-                    return this.Pos;
-                }
-            }
-        }
-
-        public string Description
-        {
-            get
-            {
-                return this.m_description;
-            }
-            set
-            {
-                this.m_description = value;
-            }
-        }
-
-        public LLVector3 Scale
-        {
-            set
-            {
-                this.m_Shape.Scale = value;
-            }
-            get
-            {
-                return this.m_Shape.Scale;
-            }
-        }
-        #endregion
-
-        #region Constructors
-        /// <summary>
-        /// 
-        /// </summary>
-        /// <param name="regionHandle"></param>
-        /// <param name="world"></param>
-        /// <param name="addPacket"></param>
-        /// <param name="ownerID"></param>
-        /// <param name="localID"></param>
-        /// <param name="isRoot"></param>
-        /// <param name="parent"></param>
-        /// <param name="rootObject"></param>
-        public Primitive(ulong regionHandle, Scene world, LLUUID ownerID, uint localID, bool isRoot, EntityBase parent, SceneObject rootObject, PrimitiveBaseShape shape, LLVector3 pos)
-        {
-
-            m_regionHandle = regionHandle;
-            m_world = world;
-            inventoryItems = new Dictionary<LLUUID, InventoryItem>();
-            this.m_Parent = parent;
-            this.m_isRootPrim = isRoot;
-            this.m_RootParent = rootObject;
-            this.CreateFromShape(ownerID, localID, pos, shape);
-            this.Rotation = Axiom.Math.Quaternion.Identity;
-
-            m_world.AcknowledgeNewPrim(this);
-
-            this.OnPrimCountTainted();
-        }
-
-        /// <summary>
-        /// 
-        /// </summary>
-        /// <remarks>Empty constructor for duplication</remarks>
-        public Primitive()
-        {
-           
-        }
-
-        #endregion
-
-        #region Destructors
-
-        ~Primitive()
-        {
-            this.OnPrimCountTainted();
-        }
-        #endregion
-
-        #region Duplication
-
-        public Primitive Copy(EntityBase parent, SceneObject rootParent)
-        {
-            Primitive dupe = (Primitive)this.MemberwiseClone();
-            
-            dupe.m_Parent = parent;
-            dupe.m_RootParent = rootParent;
-
-            // TODO: Copy this properly.
-            dupe.inventoryItems = this.inventoryItems;
-            dupe.children = new List<EntityBase>();
-            dupe.m_Shape = this.m_Shape.Copy();
-            dupe.m_regionHandle = this.m_regionHandle;
-            dupe.m_world = this.m_world;
-
-            uint newLocalID = this.m_world.PrimIDAllocate();
-            dupe.uuid = LLUUID.Random();
-            dupe.LocalId = newLocalID;
-
-            if (parent is SceneObject)
-            {
-               dupe.m_isRootPrim = true;
-                dupe.ParentID = 0;
-            }
-            else
-            {
-                dupe.m_isRootPrim = false;
-                dupe.ParentID = ((Primitive)parent).LocalId;
-            }
-
-            dupe.Scale = new LLVector3(this.Scale.X, this.Scale.Y, this.Scale.Z);
-            dupe.Rotation = new Quaternion(this.Rotation.w, this.Rotation.x, this.Rotation.y, this.Rotation.z);
-            dupe.m_pos = new LLVector3(this.m_pos.X, this.m_pos.Y, this.m_pos.Z);
-            
-            rootParent.AddChildToList(dupe);
-            this.m_world.AcknowledgeNewPrim(dupe);
-            dupe.TriggerOnPrimCountTainted();
-            
-            foreach (Primitive prim in this.children)
-            {
-                Primitive primClone = prim.Copy(dupe, rootParent);
-                dupe.children.Add(primClone);
-            }
-
-            return dupe;
-        }
-
-        #endregion
-
-        #region Override from EntityBase
-        /// <summary>
-        /// 
-        /// </summary>
-        public override void update()
-        {
-            if (this.updateFlag == 1) // is a new prim just been created/reloaded or has major changes
-            {
-                this.SendFullUpdateToAllClients();
-                this.updateFlag = 0;
-            }
-            if (this.updateFlag == 2) //some change has been made so update the clients
-            {
-                this.SendTerseUpdateToALLClients();
-                this.updateFlag = 0;
-            }
-
-            foreach (EntityBase child in children)
-            {
-                child.update();
-            }
-        }
-        #endregion
-
-        #region Setup
-        /// <summary>
-        /// 
-        /// </summary>
-        /// <param name="addPacket"></param>
-        /// <param name="ownerID"></param>
-        /// <param name="localID"></param>
-        public void CreateFromShape(LLUUID ownerID, uint localID, LLVector3 pos, PrimitiveBaseShape shape)
-        {
-            this.CreationDate = (Int32)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds;
-            this.OwnerID = ownerID;
-            this.CreatorID = this.OwnerID;
-            this.LastOwnerID = LLUUID.Zero;
-            this.Pos = pos;
-            this.uuid = LLUUID.Random();
-            this.m_localId = (uint)(localID);
-
-            this.m_Shape = shape;
-            this.updateFlag = 1;
-        }
-
-        #endregion
-
-        #region Linking / unlinking
-        /// <summary>
-        /// 
-        /// </summary>
-        /// <param name="linkObject"></param>
-        public void AddNewChildren(SceneObject linkObject)
-        {
-            // Console.WriteLine("linking new prims " + linkObject.rootLocalID + " to me (" + this.LocalId + ")");
-            //TODO check permissions
-            this.children.Add(linkObject.rootPrimitive);
-            linkObject.rootPrimitive.SetNewParent(this, this.m_RootParent);
-
-            this.m_world.DeleteEntity(linkObject.rootUUID);
-            linkObject.DeleteAllChildren();
-
-            this.OnPrimCountTainted();
-        }
-
-        /// <summary>
-        /// 
-        /// </summary>
-        /// <param name="newParent"></param>
-        /// <param name="rootParent"></param>
-        public void SetNewParent(Primitive newParent, SceneObject rootParent)
-        {
-            LLVector3 oldPos = new LLVector3(this.Pos.X, this.Pos.Y, this.Pos.Z);
-            this.m_isRootPrim = false;
-            this.m_Parent = newParent;
-            this.ParentID = newParent.LocalId;
-            this.m_RootParent = rootParent;
-            this.m_RootParent.AddChildToList(this);
-            this.Pos = oldPos;
-            Axiom.Math.Vector3 axPos = new Axiom.Math.Vector3(this.m_pos.X, m_pos.Y, m_pos.Z);
-            axPos = this.m_Parent.Rotation.Inverse() * axPos;
-            this.m_pos = new LLVector3(axPos.x, axPos.y, axPos.z);
-            Axiom.Math.Quaternion oldRot = new Quaternion(this.Rotation.w, this.Rotation.x, this.Rotation.y, this.Rotation.z);
-            this.Rotation =  this.m_Parent.Rotation.Inverse() * this.Rotation;
-            this.updateFlag = 1;
-
-            foreach (Primitive child in children)
-            {
-                child.SetRootParent(rootParent, newParent, oldPos, oldRot);
-            }
-            children.Clear();
-           
-
-        }
-
-        /// <summary>
-        /// 
-        /// </summary>
-        /// <param name="newRoot"></param>
-        public void SetRootParent(SceneObject newRoot , Primitive newParent, LLVector3 oldParentPosition, Axiom.Math.Quaternion oldParentRotation)
-        {
-            LLVector3 oldPos = new LLVector3(this.Pos.X, this.Pos.Y, this.Pos.Z);
-            Axiom.Math.Vector3 axOldPos = new Vector3(oldPos.X, oldPos.Y, oldPos.Z);
-            axOldPos = oldParentRotation * axOldPos;
-            oldPos = new LLVector3(axOldPos.x, axOldPos.y, axOldPos.z);
-            oldPos += oldParentPosition;
-            Axiom.Math.Quaternion oldRot = new Quaternion(this.Rotation.w, this.Rotation.x, this.Rotation.y, this.Rotation.z);
-            this.m_isRootPrim = false;
-            this.m_Parent = newParent;
-            this.ParentID = newParent.LocalId;
-            newParent.AddToChildrenList(this);
-            this.m_RootParent = newRoot;
-            this.m_RootParent.AddChildToList(this);
-            this.Pos = oldPos;
-            Axiom.Math.Vector3 axPos = new Axiom.Math.Vector3(this.m_pos.X, m_pos.Y, m_pos.Z);
-            axPos = this.m_Parent.Rotation.Inverse() * axPos;
-            this.m_pos = new LLVector3(axPos.x, axPos.y, axPos.z);
-            this.Rotation = oldParentRotation * this.Rotation;
-            this.Rotation =  this.m_Parent.Rotation.Inverse()* this.Rotation ;
-            this.updateFlag = 1;
-            foreach (Primitive child in children)
-            {
-                child.SetRootParent(newRoot, newParent, oldPos, oldRot);
-            }
-            children.Clear();
-        }
-
-        /// <summary>
-        /// 
-        /// </summary>
-        /// <param name="offset"></param>
-        public void AddOffsetToChildren(LLVector3 offset)
-        {
-            foreach (Primitive prim in this.children)
-            {
-                prim.m_pos += offset;
-                prim.updateFlag = 2;
-            }
-            this.OnPrimCountTainted();
-        }
-
-        /// <summary>
-        /// 
-        /// </summary>
-        /// <param name="prim"></param>
-        public void AddToChildrenList(Primitive prim)
-        {
-            this.children.Add(prim);
-        }
-        #endregion
-
-        #region Resizing/Scale
-        /// <summary>
-        /// 
-        /// </summary>
-        /// <param name="scale"></param>
-        public void ResizeGoup(LLVector3 scale)
-        {
-            LLVector3 offset = (scale - this.m_Shape.Scale);
-            offset.X /= 2;
-            offset.Y /= 2;
-            offset.Z /= 2;
-            if (this.m_isRootPrim)
-            {
-                this.m_Parent.Pos += offset;
-            }
-            else
-            {
-                this.m_pos += offset;
-            }
-
-            this.AddOffsetToChildren(new LLVector3(-offset.X, -offset.Y, -offset.Z));
-            this.m_Shape.Scale = scale;
-
-            this.updateFlag = 1;
-        }
-        #endregion
-
-        #region Position
-        /// <summary>
-        /// 
-        /// </summary>
-        /// <param name="pos"></param>
-        public void UpdateGroupPosition(LLVector3 pos)
-        {
-            LLVector3 newPos = new LLVector3(pos.X, pos.Y, pos.Z);
-
-            this.Pos = newPos;
-            this.updateFlag = 2;
-
-            this.OnPrimCountTainted();
-        }
-
-        /// <summary>
-        /// 
-        /// </summary>
-        /// <param name="pos"></param>
-        public void UpdateSinglePosition(LLVector3 pos)
-        {
-           // Console.WriteLine("updating single prim position");
-            if (this.m_isRootPrim)
-            {
-                LLVector3 newPos = new LLVector3(pos.X, pos.Y, pos.Z);
-                LLVector3 oldPos = new LLVector3(Pos.X, Pos.Y, Pos.Z);
-                LLVector3 diff = oldPos - newPos;
-                Axiom.Math.Vector3 axDiff = new Vector3(diff.X, diff.Y, diff.Z);
-                axDiff = this.Rotation.Inverse() * axDiff;
-                diff.X = axDiff.x;
-                diff.Y = axDiff.y;
-                diff.Z = axDiff.z;
-                this.Pos = newPos;
-
-                foreach (Primitive prim in this.children)
-                {
-                    prim.m_pos += diff;
-                    prim.updateFlag = 2;
-                }
-                this.updateFlag = 2;
-            }
-            else
-            {
-                LLVector3 newPos = new LLVector3(pos.X, pos.Y, pos.Z);
-                this.m_pos = newPos;
-                this.updateFlag = 2;
-            }
-
-            
-        }
-
-        #endregion
-
-        #region Rotation
-        /// <summary>
-        /// 
-        /// </summary>
-        /// <param name="rot"></param>
-        public void UpdateGroupRotation(LLQuaternion rot)
-        {
-            this.Rotation = new Axiom.Math.Quaternion(rot.W, rot.X, rot.Y, rot.Z);
-            this.updateFlag = 2;
-
-        }
-
-        /// <summary>
-        /// 
-        /// </summary>
-        /// <param name="pos"></param>
-        /// <param name="rot"></param>
-        public void UpdateGroupMouseRotation(LLVector3 pos, LLQuaternion rot)
-        {
-            this.Rotation = new Axiom.Math.Quaternion(rot.W, rot.X, rot.Y, rot.Z);
-            this.Pos = pos;
-            this.updateFlag = 2;
-        }
-
-        /// <summary>
-        /// 
-        /// </summary>
-        /// <param name="rot"></param>
-        public void UpdateSingleRotation(LLQuaternion rot)
-        {
-            //Console.WriteLine("updating single prim rotation");
-            Axiom.Math.Quaternion axRot = new Axiom.Math.Quaternion(rot.W, rot.X, rot.Y, rot.Z);
-            Axiom.Math.Quaternion oldParentRot = new Quaternion(this.Rotation.w, this.Rotation.x, this.Rotation.y, this.Rotation.z);
-            this.Rotation = axRot;
-            foreach (Primitive prim in this.children)
-            {
-                Axiom.Math.Vector3 axPos = new Vector3(prim.m_pos.X, prim.m_pos.Y, prim.m_pos.Z);
-                axPos = oldParentRot * axPos;
-                axPos = axRot.Inverse() * axPos;
-                prim.m_pos = new LLVector3(axPos.x, axPos.y, axPos.z);
-                prim.Rotation = oldParentRot * prim.Rotation ;
-                prim.Rotation = axRot.Inverse()* prim.Rotation;
-                prim.updateFlag = 2;
-            }
-            this.updateFlag = 2;
-        }
-        #endregion
-
-        #region Shape
-        /// <summary>
-        /// 
-        /// </summary>
-        /// <param name="shapeBlock"></param>
-        public void UpdateShape(ObjectShapePacket.ObjectDataBlock shapeBlock)
-        {
-            this.m_Shape.PathBegin = shapeBlock.PathBegin;
-            this.m_Shape.PathEnd = shapeBlock.PathEnd;
-            this.m_Shape.PathScaleX = shapeBlock.PathScaleX;
-            this.m_Shape.PathScaleY = shapeBlock.PathScaleY;
-            this.m_Shape.PathShearX = shapeBlock.PathShearX;
-            this.m_Shape.PathShearY = shapeBlock.PathShearY;
-            this.m_Shape.PathSkew = shapeBlock.PathSkew;
-            this.m_Shape.ProfileBegin = shapeBlock.ProfileBegin;
-            this.m_Shape.ProfileEnd = shapeBlock.ProfileEnd;
-            this.m_Shape.PathCurve = shapeBlock.PathCurve;
-            this.m_Shape.ProfileCurve = shapeBlock.ProfileCurve;
-            this.m_Shape.ProfileHollow = shapeBlock.ProfileHollow;
-            this.m_Shape.PathRadiusOffset = shapeBlock.PathRadiusOffset;
-            this.m_Shape.PathRevolutions = shapeBlock.PathRevolutions;
-            this.m_Shape.PathTaperX = shapeBlock.PathTaperX;
-            this.m_Shape.PathTaperY = shapeBlock.PathTaperY;
-            this.m_Shape.PathTwist = shapeBlock.PathTwist;
-            this.m_Shape.PathTwistBegin = shapeBlock.PathTwistBegin;
-            this.updateFlag = 1;
-        }
-        #endregion
-
-        #region Texture
-        /// <summary>
-        /// 
-        /// </summary>
-        /// <param name="textureEntry"></param>
-        public void UpdateTextureEntry(byte[] textureEntry)
-        {
-            this.m_Shape.TextureEntry = textureEntry;
-            this.updateFlag = 1;
-        }
-        #endregion
-
-        #region Client Update Methods
-
-        /// <summary>
-        /// 
-        /// </summary>
-        /// <param name="remoteClient"></param>
-        public void SendFullUpdateForAllChildren(IClientAPI remoteClient)
-        {
-            this.SendFullUpdateToClient(remoteClient);
-            for (int i = 0; i < this.children.Count; i++)
-            {
-                if (this.children[i] is Primitive)
-                {
-                    ((Primitive)this.children[i]).SendFullUpdateForAllChildren(remoteClient);
-                }
-            }
-        }
-
-        /// <summary>
-        /// 
-        /// </summary>
-        /// <param name="remoteClient"></param>
-        public void SendFullUpdateToClient(IClientAPI remoteClient)
-        {
-            LLVector3 lPos;
-            lPos = this.Pos;
-            LLQuaternion lRot;
-            lRot = new LLQuaternion(this.Rotation.x, this.Rotation.y, this.Rotation.z, this.Rotation.w);
-
-            remoteClient.SendPrimitiveToClient(this.m_regionHandle, 64096, this.LocalId, this.m_Shape, lPos, lRot, this.m_flags, this.uuid, this.OwnerID, this.Text, this.ParentID);
-        }
-
-        /// <summary>
-        /// 
-        /// </summary>
-        public void SendFullUpdateToAllClients()
-        {
-            List<ScenePresence> avatars = this.m_world.RequestAvatarList();
-            for (int i = 0; i < avatars.Count; i++)
-            {
-                this.SendFullUpdateToClient(avatars[i].ControllingClient);
-            }
-        }
-
-        /// <summary>
-        /// 
-        /// </summary>
-        /// <param name="remoteClient"></param>
-        public void SendTerseUpdateForAllChildren(IClientAPI remoteClient)
-        {
-            this.SendTerseUpdateToClient(remoteClient);
-            for (int i = 0; i < this.children.Count; i++)
-            {
-                if (this.children[i] is Primitive)
-                {
-                    ((Primitive)this.children[i]).SendTerseUpdateForAllChildren(remoteClient);
-                }
-            }
-        }
-
-        /// <summary>
-        /// 
-        /// </summary>
-        /// <param name="RemoteClient"></param>
-        public void SendTerseUpdateToClient(IClientAPI RemoteClient)
-        {
-            LLVector3 lPos;
-            Quaternion lRot;
-
-            lPos = this.Pos;
-            lRot = this.Rotation;
-
-            LLQuaternion mRot = new LLQuaternion(lRot.x, lRot.y, lRot.z, lRot.w);
-            RemoteClient.SendPrimTerseUpdate(this.m_regionHandle, 64096, this.LocalId, lPos, mRot);
-        }
-
-        /// <summary>
-        /// 
-        /// </summary>
-        public void SendTerseUpdateToALLClients()
-        {
-            List<ScenePresence> avatars = this.m_world.RequestAvatarList();
-            for (int i = 0; i < avatars.Count; i++)
-            {
-                this.SendTerseUpdateToClient(avatars[i].ControllingClient);
-            }
-        }
-
-        #endregion
-
-        public void TriggerOnPrimCountTainted()
-        {
-            this.OnPrimCountTainted();
-        }
-    }
-}
+using System;
+using System.Collections.Generic;
+using Axiom.Math;
+using libsecondlife;
+using libsecondlife.Packets;
+using OpenSim.Framework.Interfaces;
+using OpenSim.Framework.Inventory;
+using OpenSim.Framework.Types;
+
+namespace OpenSim.Region.Environment.Scenes
+{
+    public delegate void PrimCountTaintedDelegate();
+
+    public class Primitive : EntityBase
+    {
+        private const uint FULL_MASK_PERMISSIONS = 2147483647;
+
+        private LLVector3 positionLastFrame = new LLVector3(0, 0, 0);
+        private ulong m_regionHandle;
+        private byte updateFlag = 0;
+        private uint m_flags = 32 + 65536 + 131072 + 256 + 4 + 8 + 2048 + 524288 + 268435456 + 128;
+
+        private Dictionary<LLUUID, InventoryItem> inventoryItems;
+
+        private string m_description = "";
+
+        public string SitName = "";
+        public string TouchName = "";
+        public string Text = "";
+
+        public LLUUID CreatorID;
+        public LLUUID OwnerID;
+        public LLUUID LastOwnerID;
+        public Int32 CreationDate;
+
+        public uint ParentID = 0;
+
+        public uint OwnerMask = FULL_MASK_PERMISSIONS;
+        public uint NextOwnerMask = FULL_MASK_PERMISSIONS;
+        public uint GroupMask = FULL_MASK_PERMISSIONS;
+        public uint EveryoneMask = FULL_MASK_PERMISSIONS;
+        public uint BaseMask = FULL_MASK_PERMISSIONS;
+
+        private PrimitiveBaseShape m_Shape;
+
+        public SceneObject m_RootParent;
+        public bool m_isRootPrim;
+        public EntityBase m_Parent;
+
+        private EventManager m_eventManager;
+
+        public event PrimCountTaintedDelegate OnPrimCountTainted;
+
+        #region Properties
+        /// <summary>
+        /// If rootprim, will return world position
+        /// otherwise will return local offset from rootprim
+        /// </summary>
+        public override LLVector3 Pos 
+        {
+            get
+            {
+                if (m_isRootPrim)
+                {
+                    //if we are rootprim then our offset should be zero
+                    return this.m_pos + m_Parent.Pos;
+                }
+                else
+                {
+                    return this.m_pos;
+                }
+            }
+            set
+            {
+                if (m_isRootPrim)
+                {
+                    m_Parent.Pos = value;
+                }
+                this.m_pos = value - m_Parent.Pos;
+            }
+
+        }
+
+        public PrimitiveBaseShape Shape
+        {
+            get
+            {
+                return this.m_Shape;
+            }
+        }
+
+        public LLVector3 WorldPos
+        {
+            get
+            {
+                if (!this.m_isRootPrim)
+                {
+                    Primitive parentPrim = (Primitive)this.m_Parent;
+                    Axiom.Math.Vector3 offsetPos = new Vector3(this.m_pos.X, this.m_pos.Y, this.m_pos.Z);
+                    offsetPos = parentPrim.Rotation * offsetPos;
+                    return parentPrim.WorldPos + new LLVector3(offsetPos.x, offsetPos.y, offsetPos.z);
+                }
+                else
+                {
+                    return this.Pos;
+                }
+            }
+        }
+
+        public string Description
+        {
+            get
+            {
+                return this.m_description;
+            }
+            set
+            {
+                this.m_description = value;
+            }
+        }
+
+        public LLVector3 Scale
+        {
+            set
+            {
+                this.m_Shape.Scale = value;
+            }
+            get
+            {
+                return this.m_Shape.Scale;
+            }
+        }
+        #endregion
+
+        #region Constructors
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="regionHandle"></param>
+        /// <param name="world"></param>
+        /// <param name="addPacket"></param>
+        /// <param name="ownerID"></param>
+        /// <param name="localID"></param>
+        /// <param name="isRoot"></param>
+        /// <param name="parent"></param>
+        /// <param name="rootObject"></param>
+        public Primitive(ulong regionHandle, Scene world, LLUUID ownerID, uint localID, bool isRoot, EntityBase parent, SceneObject rootObject, PrimitiveBaseShape shape, LLVector3 pos)
+        {
+
+            m_regionHandle = regionHandle;
+            m_world = world;
+            inventoryItems = new Dictionary<LLUUID, InventoryItem>();
+            this.m_Parent = parent;
+            this.m_isRootPrim = isRoot;
+            this.m_RootParent = rootObject;
+            this.CreateFromShape(ownerID, localID, pos, shape);
+            this.Rotation = Axiom.Math.Quaternion.Identity;
+
+            m_world.AcknowledgeNewPrim(this);
+
+            this.OnPrimCountTainted();
+        }
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <remarks>Empty constructor for duplication</remarks>
+        public Primitive()
+        {
+           
+        }
+
+        #endregion
+
+        #region Destructors
+
+        ~Primitive()
+        {
+            this.OnPrimCountTainted();
+        }
+        #endregion
+
+        #region Duplication
+
+        public Primitive Copy(EntityBase parent, SceneObject rootParent)
+        {
+            Primitive dupe = (Primitive)this.MemberwiseClone();
+            
+            dupe.m_Parent = parent;
+            dupe.m_RootParent = rootParent;
+
+            // TODO: Copy this properly.
+            dupe.inventoryItems = this.inventoryItems;
+            dupe.children = new List<EntityBase>();
+            dupe.m_Shape = this.m_Shape.Copy();
+            dupe.m_regionHandle = this.m_regionHandle;
+            dupe.m_world = this.m_world;
+
+            uint newLocalID = this.m_world.PrimIDAllocate();
+            dupe.uuid = LLUUID.Random();
+            dupe.LocalId = newLocalID;
+
+            if (parent is SceneObject)
+            {
+               dupe.m_isRootPrim = true;
+                dupe.ParentID = 0;
+            }
+            else
+            {
+                dupe.m_isRootPrim = false;
+                dupe.ParentID = ((Primitive)parent).LocalId;
+            }
+
+            dupe.Scale = new LLVector3(this.Scale.X, this.Scale.Y, this.Scale.Z);
+            dupe.Rotation = new Quaternion(this.Rotation.w, this.Rotation.x, this.Rotation.y, this.Rotation.z);
+            dupe.m_pos = new LLVector3(this.m_pos.X, this.m_pos.Y, this.m_pos.Z);
+            
+            rootParent.AddChildToList(dupe);
+            this.m_world.AcknowledgeNewPrim(dupe);
+            dupe.TriggerOnPrimCountTainted();
+            
+            foreach (Primitive prim in this.children)
+            {
+                Primitive primClone = prim.Copy(dupe, rootParent);
+                dupe.children.Add(primClone);
+            }
+
+            return dupe;
+        }
+
+        #endregion
+
+        #region Override from EntityBase
+        /// <summary>
+        /// 
+        /// </summary>
+        public override void update()
+        {
+            if (this.updateFlag == 1) // is a new prim just been created/reloaded or has major changes
+            {
+                this.SendFullUpdateToAllClients();
+                this.updateFlag = 0;
+            }
+            if (this.updateFlag == 2) //some change has been made so update the clients
+            {
+                this.SendTerseUpdateToALLClients();
+                this.updateFlag = 0;
+            }
+
+            foreach (EntityBase child in children)
+            {
+                child.update();
+            }
+        }
+        #endregion
+
+        #region Setup
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="addPacket"></param>
+        /// <param name="ownerID"></param>
+        /// <param name="localID"></param>
+        public void CreateFromShape(LLUUID ownerID, uint localID, LLVector3 pos, PrimitiveBaseShape shape)
+        {
+            this.CreationDate = (Int32)(DateTime.UtcNow - new DateTime(1970, 1, 1)).TotalSeconds;
+            this.OwnerID = ownerID;
+            this.CreatorID = this.OwnerID;
+            this.LastOwnerID = LLUUID.Zero;
+            this.Pos = pos;
+            this.uuid = LLUUID.Random();
+            this.m_localId = (uint)(localID);
+
+            this.m_Shape = shape;
+            this.updateFlag = 1;
+        }
+
+        #endregion
+
+        #region Linking / unlinking
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="linkObject"></param>
+        public void AddNewChildren(SceneObject linkObject)
+        {
+            // Console.WriteLine("linking new prims " + linkObject.rootLocalID + " to me (" + this.LocalId + ")");
+            //TODO check permissions
+            this.children.Add(linkObject.rootPrimitive);
+            linkObject.rootPrimitive.SetNewParent(this, this.m_RootParent);
+
+            this.m_world.DeleteEntity(linkObject.rootUUID);
+            linkObject.DeleteAllChildren();
+
+            this.OnPrimCountTainted();
+        }
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="newParent"></param>
+        /// <param name="rootParent"></param>
+        public void SetNewParent(Primitive newParent, SceneObject rootParent)
+        {
+            LLVector3 oldPos = new LLVector3(this.Pos.X, this.Pos.Y, this.Pos.Z);
+            this.m_isRootPrim = false;
+            this.m_Parent = newParent;
+            this.ParentID = newParent.LocalId;
+            this.m_RootParent = rootParent;
+            this.m_RootParent.AddChildToList(this);
+            this.Pos = oldPos;
+            Axiom.Math.Vector3 axPos = new Axiom.Math.Vector3(this.m_pos.X, m_pos.Y, m_pos.Z);
+            axPos = this.m_Parent.Rotation.Inverse() * axPos;
+            this.m_pos = new LLVector3(axPos.x, axPos.y, axPos.z);
+            Axiom.Math.Quaternion oldRot = new Quaternion(this.Rotation.w, this.Rotation.x, this.Rotation.y, this.Rotation.z);
+            this.Rotation =  this.m_Parent.Rotation.Inverse() * this.Rotation;
+            this.updateFlag = 1;
+
+            foreach (Primitive child in children)
+            {
+                child.SetRootParent(rootParent, newParent, oldPos, oldRot);
+            }
+            children.Clear();
+           
+
+        }
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="newRoot"></param>
+        public void SetRootParent(SceneObject newRoot , Primitive newParent, LLVector3 oldParentPosition, Axiom.Math.Quaternion oldParentRotation)
+        {
+            LLVector3 oldPos = new LLVector3(this.Pos.X, this.Pos.Y, this.Pos.Z);
+            Axiom.Math.Vector3 axOldPos = new Vector3(oldPos.X, oldPos.Y, oldPos.Z);
+            axOldPos = oldParentRotation * axOldPos;
+            oldPos = new LLVector3(axOldPos.x, axOldPos.y, axOldPos.z);
+            oldPos += oldParentPosition;
+            Axiom.Math.Quaternion oldRot = new Quaternion(this.Rotation.w, this.Rotation.x, this.Rotation.y, this.Rotation.z);
+            this.m_isRootPrim = false;
+            this.m_Parent = newParent;
+            this.ParentID = newParent.LocalId;
+            newParent.AddToChildrenList(this);
+            this.m_RootParent = newRoot;
+            this.m_RootParent.AddChildToList(this);
+            this.Pos = oldPos;
+            Axiom.Math.Vector3 axPos = new Axiom.Math.Vector3(this.m_pos.X, m_pos.Y, m_pos.Z);
+            axPos = this.m_Parent.Rotation.Inverse() * axPos;
+            this.m_pos = new LLVector3(axPos.x, axPos.y, axPos.z);
+            this.Rotation = oldParentRotation * this.Rotation;
+            this.Rotation =  this.m_Parent.Rotation.Inverse()* this.Rotation ;
+            this.updateFlag = 1;
+            foreach (Primitive child in children)
+            {
+                child.SetRootParent(newRoot, newParent, oldPos, oldRot);
+            }
+            children.Clear();
+        }
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="offset"></param>
+        public void AddOffsetToChildren(LLVector3 offset)
+        {
+            foreach (Primitive prim in this.children)
+            {
+                prim.m_pos += offset;
+                prim.updateFlag = 2;
+            }
+            this.OnPrimCountTainted();
+        }
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="prim"></param>
+        public void AddToChildrenList(Primitive prim)
+        {
+            this.children.Add(prim);
+        }
+        #endregion
+
+        #region Resizing/Scale
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="scale"></param>
+        public void ResizeGoup(LLVector3 scale)
+        {
+            LLVector3 offset = (scale - this.m_Shape.Scale);
+            offset.X /= 2;
+            offset.Y /= 2;
+            offset.Z /= 2;
+            if (this.m_isRootPrim)
+            {
+                this.m_Parent.Pos += offset;
+            }
+            else
+            {
+                this.m_pos += offset;
+            }
+
+            this.AddOffsetToChildren(new LLVector3(-offset.X, -offset.Y, -offset.Z));
+            this.m_Shape.Scale = scale;
+
+            this.updateFlag = 1;
+        }
+        #endregion
+
+        #region Position
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="pos"></param>
+        public void UpdateGroupPosition(LLVector3 pos)
+        {
+            LLVector3 newPos = new LLVector3(pos.X, pos.Y, pos.Z);
+
+            this.Pos = newPos;
+            this.updateFlag = 2;
+
+            this.OnPrimCountTainted();
+        }
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="pos"></param>
+        public void UpdateSinglePosition(LLVector3 pos)
+        {
+           // Console.WriteLine("updating single prim position");
+            if (this.m_isRootPrim)
+            {
+                LLVector3 newPos = new LLVector3(pos.X, pos.Y, pos.Z);
+                LLVector3 oldPos = new LLVector3(Pos.X, Pos.Y, Pos.Z);
+                LLVector3 diff = oldPos - newPos;
+                Axiom.Math.Vector3 axDiff = new Vector3(diff.X, diff.Y, diff.Z);
+                axDiff = this.Rotation.Inverse() * axDiff;
+                diff.X = axDiff.x;
+                diff.Y = axDiff.y;
+                diff.Z = axDiff.z;
+                this.Pos = newPos;
+
+                foreach (Primitive prim in this.children)
+                {
+                    prim.m_pos += diff;
+                    prim.updateFlag = 2;
+                }
+                this.updateFlag = 2;
+            }
+            else
+            {
+                LLVector3 newPos = new LLVector3(pos.X, pos.Y, pos.Z);
+                this.m_pos = newPos;
+                this.updateFlag = 2;
+            }
+
+            
+        }
+
+        #endregion
+
+        #region Rotation
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="rot"></param>
+        public void UpdateGroupRotation(LLQuaternion rot)
+        {
+            this.Rotation = new Axiom.Math.Quaternion(rot.W, rot.X, rot.Y, rot.Z);
+            this.updateFlag = 2;
+
+        }
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="pos"></param>
+        /// <param name="rot"></param>
+        public void UpdateGroupMouseRotation(LLVector3 pos, LLQuaternion rot)
+        {
+            this.Rotation = new Axiom.Math.Quaternion(rot.W, rot.X, rot.Y, rot.Z);
+            this.Pos = pos;
+            this.updateFlag = 2;
+        }
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="rot"></param>
+        public void UpdateSingleRotation(LLQuaternion rot)
+        {
+            //Console.WriteLine("updating single prim rotation");
+            Axiom.Math.Quaternion axRot = new Axiom.Math.Quaternion(rot.W, rot.X, rot.Y, rot.Z);
+            Axiom.Math.Quaternion oldParentRot = new Quaternion(this.Rotation.w, this.Rotation.x, this.Rotation.y, this.Rotation.z);
+            this.Rotation = axRot;
+            foreach (Primitive prim in this.children)
+            {
+                Axiom.Math.Vector3 axPos = new Vector3(prim.m_pos.X, prim.m_pos.Y, prim.m_pos.Z);
+                axPos = oldParentRot * axPos;
+                axPos = axRot.Inverse() * axPos;
+                prim.m_pos = new LLVector3(axPos.x, axPos.y, axPos.z);
+                prim.Rotation = oldParentRot * prim.Rotation ;
+                prim.Rotation = axRot.Inverse()* prim.Rotation;
+                prim.updateFlag = 2;
+            }
+            this.updateFlag = 2;
+        }
+        #endregion
+
+        #region Shape
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="shapeBlock"></param>
+        public void UpdateShape(ObjectShapePacket.ObjectDataBlock shapeBlock)
+        {
+            this.m_Shape.PathBegin = shapeBlock.PathBegin;
+            this.m_Shape.PathEnd = shapeBlock.PathEnd;
+            this.m_Shape.PathScaleX = shapeBlock.PathScaleX;
+            this.m_Shape.PathScaleY = shapeBlock.PathScaleY;
+            this.m_Shape.PathShearX = shapeBlock.PathShearX;
+            this.m_Shape.PathShearY = shapeBlock.PathShearY;
+            this.m_Shape.PathSkew = shapeBlock.PathSkew;
+            this.m_Shape.ProfileBegin = shapeBlock.ProfileBegin;
+            this.m_Shape.ProfileEnd = shapeBlock.ProfileEnd;
+            this.m_Shape.PathCurve = shapeBlock.PathCurve;
+            this.m_Shape.ProfileCurve = shapeBlock.ProfileCurve;
+            this.m_Shape.ProfileHollow = shapeBlock.ProfileHollow;
+            this.m_Shape.PathRadiusOffset = shapeBlock.PathRadiusOffset;
+            this.m_Shape.PathRevolutions = shapeBlock.PathRevolutions;
+            this.m_Shape.PathTaperX = shapeBlock.PathTaperX;
+            this.m_Shape.PathTaperY = shapeBlock.PathTaperY;
+            this.m_Shape.PathTwist = shapeBlock.PathTwist;
+            this.m_Shape.PathTwistBegin = shapeBlock.PathTwistBegin;
+            this.updateFlag = 1;
+        }
+        #endregion
+
+        #region Texture
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="textureEntry"></param>
+        public void UpdateTextureEntry(byte[] textureEntry)
+        {
+            this.m_Shape.TextureEntry = textureEntry;
+            this.updateFlag = 1;
+        }
+        #endregion
+
+        #region Client Update Methods
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="remoteClient"></param>
+        public void SendFullUpdateForAllChildren(IClientAPI remoteClient)
+        {
+            this.SendFullUpdateToClient(remoteClient);
+            for (int i = 0; i < this.children.Count; i++)
+            {
+                if (this.children[i] is Primitive)
+                {
+                    ((Primitive)this.children[i]).SendFullUpdateForAllChildren(remoteClient);
+                }
+            }
+        }
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="remoteClient"></param>
+        public void SendFullUpdateToClient(IClientAPI remoteClient)
+        {
+            LLVector3 lPos;
+            lPos = this.Pos;
+            LLQuaternion lRot;
+            lRot = new LLQuaternion(this.Rotation.x, this.Rotation.y, this.Rotation.z, this.Rotation.w);
+
+            remoteClient.SendPrimitiveToClient(this.m_regionHandle, 64096, this.LocalId, this.m_Shape, lPos, lRot, this.m_flags, this.uuid, this.OwnerID, this.Text, this.ParentID);
+        }
+
+        /// <summary>
+        /// 
+        /// </summary>
+        public void SendFullUpdateToAllClients()
+        {
+            List<ScenePresence> avatars = this.m_world.RequestAvatarList();
+            for (int i = 0; i < avatars.Count; i++)
+            {
+                this.SendFullUpdateToClient(avatars[i].ControllingClient);
+            }
+        }
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="remoteClient"></param>
+        public void SendTerseUpdateForAllChildren(IClientAPI remoteClient)
+        {
+            this.SendTerseUpdateToClient(remoteClient);
+            for (int i = 0; i < this.children.Count; i++)
+            {
+                if (this.children[i] is Primitive)
+                {
+                    ((Primitive)this.children[i]).SendTerseUpdateForAllChildren(remoteClient);
+                }
+            }
+        }
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="RemoteClient"></param>
+        public void SendTerseUpdateToClient(IClientAPI RemoteClient)
+        {
+            LLVector3 lPos;
+            Quaternion lRot;
+
+            lPos = this.Pos;
+            lRot = this.Rotation;
+
+            LLQuaternion mRot = new LLQuaternion(lRot.x, lRot.y, lRot.z, lRot.w);
+            RemoteClient.SendPrimTerseUpdate(this.m_regionHandle, 64096, this.LocalId, lPos, mRot);
+        }
+
+        /// <summary>
+        /// 
+        /// </summary>
+        public void SendTerseUpdateToALLClients()
+        {
+            List<ScenePresence> avatars = this.m_world.RequestAvatarList();
+            for (int i = 0; i < avatars.Count; i++)
+            {
+                this.SendTerseUpdateToClient(avatars[i].ControllingClient);
+            }
+        }
+
+        #endregion
+
+        public void TriggerOnPrimCountTainted()
+        {
+            this.OnPrimCountTainted();
+        }
+    }
+}
diff --git a/OpenSim/Region/Environment/Scenes/Scene.PacketHandlers.cs b/OpenSim/Region/Environment/Scenes/Scene.PacketHandlers.cs
index 347625a..e37d105 100644
--- a/OpenSim/Region/Environment/Scenes/Scene.PacketHandlers.cs
+++ b/OpenSim/Region/Environment/Scenes/Scene.PacketHandlers.cs
@@ -1,618 +1,618 @@
-/*
-* Copyright (c) Contributors, http://www.openmetaverse.org/
-* See CONTRIBUTORS.TXT for a full list of copyright holders.
-*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted provided that the following conditions are met:
-*     * Redistributions of source code must retain the above copyright
-*       notice, this list of conditions and the following disclaimer.
-*     * Redistributions in binary form must reproduce the above copyright
-*       notice, this list of conditions and the following disclaimer in the
-*       documentation and/or other materials provided with the distribution.
-*     * Neither the name of the OpenSim Project nor the
-*       names of its contributors may be used to endorse or promote products
-*       derived from this software without specific prior written permission.
-*
-* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
-* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
-* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-* 
-*/
-using System;
-using System.Collections.Generic;
-using libsecondlife;
-using libsecondlife.Packets;
-using OpenSim.Framework.Interfaces;
-using OpenSim.Framework.Types;
-
-namespace OpenSim.Region.Environment.Scenes
-{
-    public partial class Scene
-    {
-        /// <summary>
-        /// Modifies terrain using the specified information
-        /// </summary>
-        /// <param name="height">The height at which the user started modifying the terrain</param>
-        /// <param name="seconds">The number of seconds the modify button was pressed</param>
-        /// <param name="brushsize">The size of the brush used</param>
-        /// <param name="action">The action to be performed</param>
-        /// <param name="north">Distance from the north border where the cursor is located</param>
-        /// <param name="west">Distance from the west border where the cursor is located</param>
-        public void ModifyTerrain(float height, float seconds, byte brushsize, byte action, float north, float west)
-        {
-            // Shiny.
-            double size = (double)(1 << brushsize);
-
-            switch (action)
-            {
-                case 0:
-                    // flatten terrain
-                    Terrain.flatten(north, west, size, (double)seconds / 100.0);
-                    RegenerateTerrain(true, (int)north, (int)west);
-                    break;
-                case 1:
-                    // raise terrain
-                    Terrain.raise(north, west, size, (double)seconds / 100.0);
-                    RegenerateTerrain(true, (int)north, (int)west);
-                    break;
-                case 2:
-                    //lower terrain
-                    Terrain.lower(north, west, size, (double)seconds / 100.0);
-                    RegenerateTerrain(true, (int)north, (int)west);
-                    break;
-                case 3:
-                    // smooth terrain
-                    Terrain.smooth(north, west, size, (double)seconds / 100.0);
-                    RegenerateTerrain(true, (int)north, (int)west);
-                    break;
-                case 4:
-                    // noise
-                    Terrain.noise(north, west, size, (double)seconds / 100.0);
-                    RegenerateTerrain(true, (int)north, (int)west);
-                    break;
-                case 5:
-                    // revert
-                    Terrain.revert(north, west, size, (double)seconds / 100.0);
-                    RegenerateTerrain(true, (int)north, (int)west);
-                    break;
-
-                // CLIENT EXTENSIONS GO HERE
-                case 128:
-                    // erode-thermal
-                    break;
-                case 129:
-                    // erode-aerobic
-                    break;
-                case 130:
-                    // erode-hydraulic
-                    break;
-            }
-            return;
-        }
-
-        /// <summary>
-        /// 
-        /// </summary>
-        /// <remarks>Inefficient. TODO: Fixme</remarks>
-        /// <param name="fromAgentID"></param>
-        /// <param name="toAgentID"></param>
-        /// <param name="timestamp"></param>
-        /// <param name="fromAgentName"></param>
-        /// <param name="message"></param>
-        public void InstantMessage(LLUUID fromAgentID, LLUUID toAgentID, uint timestamp, string fromAgentName, string message)
-        {
-            if (this.Avatars.ContainsKey(toAgentID))
-            {
-                if (this.Avatars.ContainsKey(fromAgentID))
-                {
-                    // Local sim message
-                    ScenePresence fromAvatar = this.Avatars[fromAgentID];
-                    ScenePresence toAvatar = this.Avatars[toAgentID];
-                    string fromName = fromAvatar.firstname + " " + fromAvatar.lastname;
-                    toAvatar.ControllingClient.SendInstantMessage(message, toAgentID, fromName);
-                }
-                else
-                {
-                    // Message came from a user outside the sim, ignore?
-                }
-            }
-            else
-            {
-                // Grid message
-            }
-        }
-
-        /// <summary>
-        /// 
-        /// </summary>
-        /// <param name="message"></param>
-        /// <param name="type"></param>
-        /// <param name="fromPos"></param>
-        /// <param name="fromName"></param>
-        /// <param name="fromAgentID"></param>
-        public void SimChat(byte[] message, byte type, LLVector3 fromPos, string fromName, LLUUID fromAgentID)
-        {
-             ScenePresence avatar = null;
-            if (this.Avatars.ContainsKey(fromAgentID))
-            {
-                avatar = this.Avatars[fromAgentID];
-                fromPos = avatar.Pos;
-                fromName = avatar.firstname + " " + avatar.lastname;
-                avatar = null;
-            }
-
-            this.ForEachScenePresence(delegate(ScenePresence presence)
-                                              {
-                                                  int dis = -1000;
-                                                  if (this.Avatars.ContainsKey(presence.ControllingClient.AgentId))
-                                                  {
-                                                      avatar = this.Avatars[presence.ControllingClient.AgentId];
-                                                      dis = (int)avatar.Pos.GetDistanceTo(fromPos);
-                                                  }
-
-                                                  switch (type)
-                                                  {
-                                                      case 0: // Whisper
-                                                          if ((dis < 10) && (dis > -10))
-                                                          {
-                                                              //should change so the message is sent through the avatar rather than direct to the ClientView
-                                                              presence.ControllingClient.SendChatMessage(message, type, fromPos, fromName,
-                                                                                     fromAgentID);
-                                                          }
-                                                          break;
-                                                      case 1: // Say
-                                                          if ((dis < 30) && (dis > -30))
-                                                          {
-                                                              //Console.WriteLine("sending chat");
-                                                              presence.ControllingClient.SendChatMessage(message, type, fromPos, fromName,
-                                                                                     fromAgentID);
-                                                          }
-                                                          break;
-                                                      case 2: // Shout
-                                                          if ((dis < 100) && (dis > -100))
-                                                          {
-                                                              presence.ControllingClient.SendChatMessage(message, type, fromPos, fromName,
-                                                                                     fromAgentID);
-                                                          }
-                                                          break;
-
-                                                      case 0xff: // Broadcast
-                                                          presence.ControllingClient.SendChatMessage(message, type, fromPos, fromName,
-                                                                                 fromAgentID);
-                                                          break;
-                                                  }
-                                              });
-        }
-
-        /// <summary>
-        /// 
-        /// </summary>
-        /// <param name="primAsset"></param>
-        /// <param name="pos"></param>
-        public void RezObject(AssetBase primAsset, LLVector3 pos)
-        {
-
-        }
-
-        /// <summary>
-        /// 
-        /// </summary>
-        /// <param name="packet"></param>
-        /// <param name="simClient"></param>
-        public void DeRezObject(Packet packet, IClientAPI simClient)
-        {
-
-        }
-
-        /// <summary>
-        /// 
-        /// </summary>
-        /// <param name="remoteClient"></param>
-        public void SendAvatarsToClient(IClientAPI remoteClient)
-        {
-
-        }
-
-        /// <summary>
-        /// 
-        /// </summary>
-        /// <param name="originalPrim"></param>
-        /// <param name="offset"></param>
-        /// <param name="flags"></param>
-        public void DuplicateObject(uint originalPrim, LLVector3 offset, uint flags)
-        {
-            SceneObject originPrim = null;
-            foreach (EntityBase ent in Entities.Values)
-            {
-                if (ent is SceneObject)
-                {
-                    if (((SceneObject)ent).rootLocalID == originalPrim)
-                    {
-                        originPrim = (SceneObject)ent;
-                        break;
-                    }
-                }
-            }
-
-            if (originPrim != null)
-            {
-                SceneObject copy = originPrim.Copy();
-                copy.Pos = copy.Pos + offset;
-                this.Entities.Add(copy.rootUUID, copy);
-
-                List<ScenePresence> avatars = this.RequestAvatarList();
-                for (int i = 0; i < avatars.Count; i++)
-                {
-                    copy.SendAllChildPrimsToClient(avatars[i].ControllingClient);
-                }
-
-            }
-            else
-            {
-                OpenSim.Framework.Console.MainLog.Instance.Warn("Attempted to duplicate nonexistant prim");
-            }
-
-        }
-
-        /// <summary>
-        /// 
-        /// </summary>
-        /// <param name="parentPrim"></param>
-        /// <param name="childPrims"></param>
-        public void LinkObjects(uint parentPrim, List<uint> childPrims)
-        {
-            SceneObject parenPrim = null;
-            foreach (EntityBase ent in Entities.Values)
-            {
-                if (ent is SceneObject)
-                {
-                    if (((SceneObject)ent).rootLocalID == parentPrim)
-                    {
-                        parenPrim = (SceneObject)ent;
-                        break;
-                    }
-                }
-            }
-
-            List<SceneObject> children = new List<SceneObject>();
-            if (parenPrim != null)
-            {
-                for (int i = 0; i < childPrims.Count; i++)
-                {
-                    foreach (EntityBase ent in Entities.Values)
-                    {
-                        if (ent is SceneObject)
-                        {
-                            if (((SceneObject)ent).rootLocalID == childPrims[i])
-                            {
-                                children.Add((SceneObject)ent);
-                            }
-                        }
-                    }
-                }
-            }
-
-            foreach (SceneObject sceneObj in children)
-            {
-                parenPrim.AddNewChildPrims(sceneObj);
-            }
-        }
-
-        /// <summary>
-        /// 
-        /// </summary>
-        /// <param name="primLocalID"></param>
-        /// <param name="shapeBlock"></param>
-        public void UpdatePrimShape(uint primLocalID, ObjectShapePacket.ObjectDataBlock shapeBlock)
-        {
-            Primitive prim = null;
-            foreach (EntityBase ent in Entities.Values)
-            {
-                if (ent is SceneObject)
-                {
-                    prim = ((SceneObject)ent).HasChildPrim(primLocalID);
-                    if (prim != null)
-                    {
-                        prim.UpdateShape(shapeBlock);
-                        break;
-                    }
-                }
-            }
-        }
-
-        /// <summary>
-        /// 
-        /// </summary>
-        /// <param name="primLocalID"></param>
-        /// <param name="remoteClient"></param>
-        public void SelectPrim(uint primLocalID, IClientAPI remoteClient)
-        {
-            foreach (EntityBase ent in Entities.Values)
-            {
-                if (ent is SceneObject)
-                {
-                    if (((SceneObject)ent).rootLocalID == primLocalID)
-                    {
-                        ((SceneObject)ent).GetProperites(remoteClient);
-                        ((SceneObject)ent).isSelected = true;
-                        this.ParcelManager.setPrimsTainted();
-                        break;
-                    }
-                }
-            }
-        }
-
-        /// <summary>
-        /// 
-        /// </summary>
-        /// <param name="primLocalID"></param>
-        /// <param name="remoteClient"></param>
-        public void DeselectPrim(uint primLocalID, IClientAPI remoteClient)
-        {
-            foreach (EntityBase ent in Entities.Values)
-            {
-                if (ent is SceneObject)
-                {
-                    if (((SceneObject)ent).rootLocalID == primLocalID)
-                    {
-                        ((SceneObject)ent).isSelected = false;
-                        this.ParcelManager.setPrimsTainted();
-                        break;
-                    }
-                }
-            }
-        }
-
-        /// <summary>
-        /// 
-        /// </summary>
-        /// <param name="primLocalID"></param>
-        /// <param name="description"></param>
-        public void PrimDescription(uint primLocalID, string description)
-        {
-            Primitive prim = null;
-            foreach (EntityBase ent in Entities.Values)
-            {
-                if (ent is SceneObject)
-                {
-                    prim = ((SceneObject)ent).HasChildPrim(primLocalID);
-                    if (prim != null)
-                    {
-                        prim.Description = description;
-                        break;
-                    }
-                }
-            }
-        }
-
-        /// <summary>
-        /// 
-        /// </summary>
-        /// <param name="primLocalID"></param>
-        /// <param name="description"></param>
-        public void PrimName(uint primLocalID, string name)
-        {
-            Primitive prim = null;
-            foreach (EntityBase ent in Entities.Values)
-            {
-                if (ent is SceneObject)
-                {
-                    prim = ((SceneObject)ent).HasChildPrim(primLocalID);
-                    if (prim != null)
-                    {
-                        prim.Name = name;
-                        break;
-                    }
-                }
-            }
-        }
-
-        public void MoveObject(LLUUID objectID, LLVector3 offset, LLVector3 pos, IClientAPI remoteClient)
-        {
-            Primitive prim = null;
-            foreach (EntityBase ent in Entities.Values)
-            {
-                if (ent is SceneObject)
-                {
-                    prim = ((SceneObject)ent).HasChildPrim(objectID);
-                    if (prim != null)
-                    {
-                        ((SceneObject)ent).GrapMovement(offset, pos, remoteClient);
-                        break;
-                    }
-                }
-            }
-            /*
-            if (this.Entities.ContainsKey(objectID))
-            {
-                if (this.Entities[objectID] is SceneObject)
-                {
-                    ((SceneObject)this.Entities[objectID]).GrapMovement(offset, pos, remoteClient);
-                }
-            }*/
-        }
-
-        /// <summary>
-        /// 
-        /// </summary>
-        /// <param name="localID"></param>
-        /// <param name="packet"></param>
-        /// <param name="remoteClient"></param>
-        public void UpdatePrimFlags(uint localID, Packet packet, IClientAPI remoteClient)
-        {
-
-        }
-
-        /// <summary>
-        /// 
-        /// </summary>
-        /// <param name="localID"></param>
-        /// <param name="texture"></param>
-        /// <param name="remoteClient"></param>
-        public void UpdatePrimTexture(uint localID, byte[] texture, IClientAPI remoteClient)
-        {
-            Primitive prim = null;
-            foreach (EntityBase ent in Entities.Values)
-            {
-                if (ent is SceneObject)
-                {
-                    prim = ((SceneObject)ent).HasChildPrim(localID);
-                    if (prim != null)
-                    {
-                        prim.UpdateTextureEntry(texture);
-                    }
-                }
-            }
-        }
-
-        /// <summary>
-        /// 
-        /// </summary>
-        /// <param name="localID"></param>
-        /// <param name="pos"></param>
-        /// <param name="remoteClient"></param>
-        public void UpdatePrimPosition(uint localID, LLVector3 pos, IClientAPI remoteClient)
-        {
-            Primitive prim = null;
-            foreach (EntityBase ent in Entities.Values)
-            {
-                if (ent is SceneObject)
-                {
-                    prim = ((SceneObject)ent).HasChildPrim(localID);
-                    if (prim != null)
-                    {
-                        prim.UpdateGroupPosition(pos);
-                        break;
-                    }
-                }
-            }
-        }
-
-        public void UpdatePrimSinglePosition(uint localID, LLVector3 pos, IClientAPI remoteClient)
-        {
-            Primitive prim = null;
-            foreach (EntityBase ent in Entities.Values)
-            {
-                if (ent is SceneObject)
-                {
-                    prim = ((SceneObject)ent).HasChildPrim(localID);
-                    if (prim != null)
-                    {
-                        prim.UpdateSinglePosition(pos);
-                        break;
-                    }
-                }
-            }
-        }
-
-        /// <summary>
-        /// 
-        /// </summary>
-        /// <param name="localID"></param>
-        /// <param name="pos"></param>
-        /// <param name="rot"></param>
-        /// <param name="remoteClient"></param>
-        public void UpdatePrimRotation(uint localID, LLVector3 pos, LLQuaternion rot, IClientAPI remoteClient)
-        {
-            Primitive prim = null;
-            foreach (EntityBase ent in Entities.Values)
-            {
-                if (ent is SceneObject)
-                {
-                    prim = ((SceneObject)ent).HasChildPrim(localID);
-                    if (prim != null)
-                    {
-                        prim.UpdateGroupMouseRotation(pos, rot);
-                        break;
-                    }
-                }
-            }
-        }
-
-        /// <summary>
-        /// 
-        /// </summary>
-        /// <param name="localID"></param>
-        /// <param name="rot"></param>
-        /// <param name="remoteClient"></param>
-        public void UpdatePrimRotation(uint localID, LLQuaternion rot, IClientAPI remoteClient)
-        {
-            Primitive prim = null;
-            foreach (EntityBase ent in Entities.Values)
-            {
-                if (ent is SceneObject)
-                {
-                    prim = ((SceneObject)ent).HasChildPrim(localID);
-                    if (prim != null)
-                    {
-                        prim.UpdateGroupRotation(rot);
-                        break;
-                    }
-                }
-            }
-        }
-
-        /// <summary>
-        /// 
-        /// </summary>
-        /// <param name="localID"></param>
-        /// <param name="rot"></param>
-        /// <param name="remoteClient"></param>
-        public void UpdatePrimSingleRotation(uint localID, LLQuaternion rot, IClientAPI remoteClient)
-        {
-            //Console.WriteLine("trying to update single prim rotation");
-            Primitive prim = null;
-            foreach (EntityBase ent in Entities.Values)
-            {
-                if (ent is SceneObject)
-                {
-                    prim = ((SceneObject)ent).HasChildPrim(localID);
-                    if (prim != null)
-                    {
-                        prim.UpdateSingleRotation(rot);
-                        break;
-                    }
-                }
-            }
-        }
-
-        /// <summary>
-        /// 
-        /// </summary>
-        /// <param name="localID"></param>
-        /// <param name="scale"></param>
-        /// <param name="remoteClient"></param>
-        public void UpdatePrimScale(uint localID, LLVector3 scale, IClientAPI remoteClient)
-        {
-            Primitive prim = null;
-            foreach (EntityBase ent in Entities.Values)
-            {
-                if (ent is SceneObject)
-                {
-                    prim = ((SceneObject)ent).HasChildPrim(localID);
-                    if (prim != null)
-                    {
-                        prim.ResizeGoup(scale);
-                        break;
-                    }
-                }
-            }
-        }
-
-        /// <summary>
-        /// Sends prims to a client
-        /// </summary>
-        /// <param name="RemoteClient">Client to send to</param>
-        public void GetInitialPrims(IClientAPI RemoteClient)
-        {
-
-        }
-    }
-}
+/*
+* Copyright (c) Contributors, http://www.openmetaverse.org/
+* See CONTRIBUTORS.TXT for a full list of copyright holders.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*     * Redistributions of source code must retain the above copyright
+*       notice, this list of conditions and the following disclaimer.
+*     * Redistributions in binary form must reproduce the above copyright
+*       notice, this list of conditions and the following disclaimer in the
+*       documentation and/or other materials provided with the distribution.
+*     * Neither the name of the OpenSim Project nor the
+*       names of its contributors may be used to endorse or promote products
+*       derived from this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
+* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
+* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+* 
+*/
+using System;
+using System.Collections.Generic;
+using libsecondlife;
+using libsecondlife.Packets;
+using OpenSim.Framework.Interfaces;
+using OpenSim.Framework.Types;
+
+namespace OpenSim.Region.Environment.Scenes
+{
+    public partial class Scene
+    {
+        /// <summary>
+        /// Modifies terrain using the specified information
+        /// </summary>
+        /// <param name="height">The height at which the user started modifying the terrain</param>
+        /// <param name="seconds">The number of seconds the modify button was pressed</param>
+        /// <param name="brushsize">The size of the brush used</param>
+        /// <param name="action">The action to be performed</param>
+        /// <param name="north">Distance from the north border where the cursor is located</param>
+        /// <param name="west">Distance from the west border where the cursor is located</param>
+        public void ModifyTerrain(float height, float seconds, byte brushsize, byte action, float north, float west)
+        {
+            // Shiny.
+            double size = (double)(1 << brushsize);
+
+            switch (action)
+            {
+                case 0:
+                    // flatten terrain
+                    Terrain.flatten(north, west, size, (double)seconds / 100.0);
+                    RegenerateTerrain(true, (int)north, (int)west);
+                    break;
+                case 1:
+                    // raise terrain
+                    Terrain.raise(north, west, size, (double)seconds / 100.0);
+                    RegenerateTerrain(true, (int)north, (int)west);
+                    break;
+                case 2:
+                    //lower terrain
+                    Terrain.lower(north, west, size, (double)seconds / 100.0);
+                    RegenerateTerrain(true, (int)north, (int)west);
+                    break;
+                case 3:
+                    // smooth terrain
+                    Terrain.smooth(north, west, size, (double)seconds / 100.0);
+                    RegenerateTerrain(true, (int)north, (int)west);
+                    break;
+                case 4:
+                    // noise
+                    Terrain.noise(north, west, size, (double)seconds / 100.0);
+                    RegenerateTerrain(true, (int)north, (int)west);
+                    break;
+                case 5:
+                    // revert
+                    Terrain.revert(north, west, size, (double)seconds / 100.0);
+                    RegenerateTerrain(true, (int)north, (int)west);
+                    break;
+
+                // CLIENT EXTENSIONS GO HERE
+                case 128:
+                    // erode-thermal
+                    break;
+                case 129:
+                    // erode-aerobic
+                    break;
+                case 130:
+                    // erode-hydraulic
+                    break;
+            }
+            return;
+        }
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <remarks>Inefficient. TODO: Fixme</remarks>
+        /// <param name="fromAgentID"></param>
+        /// <param name="toAgentID"></param>
+        /// <param name="timestamp"></param>
+        /// <param name="fromAgentName"></param>
+        /// <param name="message"></param>
+        public void InstantMessage(LLUUID fromAgentID, LLUUID toAgentID, uint timestamp, string fromAgentName, string message)
+        {
+            if (this.Avatars.ContainsKey(toAgentID))
+            {
+                if (this.Avatars.ContainsKey(fromAgentID))
+                {
+                    // Local sim message
+                    ScenePresence fromAvatar = this.Avatars[fromAgentID];
+                    ScenePresence toAvatar = this.Avatars[toAgentID];
+                    string fromName = fromAvatar.firstname + " " + fromAvatar.lastname;
+                    toAvatar.ControllingClient.SendInstantMessage(message, toAgentID, fromName);
+                }
+                else
+                {
+                    // Message came from a user outside the sim, ignore?
+                }
+            }
+            else
+            {
+                // Grid message
+            }
+        }
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="message"></param>
+        /// <param name="type"></param>
+        /// <param name="fromPos"></param>
+        /// <param name="fromName"></param>
+        /// <param name="fromAgentID"></param>
+        public void SimChat(byte[] message, byte type, LLVector3 fromPos, string fromName, LLUUID fromAgentID)
+        {
+             ScenePresence avatar = null;
+            if (this.Avatars.ContainsKey(fromAgentID))
+            {
+                avatar = this.Avatars[fromAgentID];
+                fromPos = avatar.Pos;
+                fromName = avatar.firstname + " " + avatar.lastname;
+                avatar = null;
+            }
+
+            this.ForEachScenePresence(delegate(ScenePresence presence)
+                                              {
+                                                  int dis = -1000;
+                                                  if (this.Avatars.ContainsKey(presence.ControllingClient.AgentId))
+                                                  {
+                                                      avatar = this.Avatars[presence.ControllingClient.AgentId];
+                                                      dis = (int)avatar.Pos.GetDistanceTo(fromPos);
+                                                  }
+
+                                                  switch (type)
+                                                  {
+                                                      case 0: // Whisper
+                                                          if ((dis < 10) && (dis > -10))
+                                                          {
+                                                              //should change so the message is sent through the avatar rather than direct to the ClientView
+                                                              presence.ControllingClient.SendChatMessage(message, type, fromPos, fromName,
+                                                                                     fromAgentID);
+                                                          }
+                                                          break;
+                                                      case 1: // Say
+                                                          if ((dis < 30) && (dis > -30))
+                                                          {
+                                                              //Console.WriteLine("sending chat");
+                                                              presence.ControllingClient.SendChatMessage(message, type, fromPos, fromName,
+                                                                                     fromAgentID);
+                                                          }
+                                                          break;
+                                                      case 2: // Shout
+                                                          if ((dis < 100) && (dis > -100))
+                                                          {
+                                                              presence.ControllingClient.SendChatMessage(message, type, fromPos, fromName,
+                                                                                     fromAgentID);
+                                                          }
+                                                          break;
+
+                                                      case 0xff: // Broadcast
+                                                          presence.ControllingClient.SendChatMessage(message, type, fromPos, fromName,
+                                                                                 fromAgentID);
+                                                          break;
+                                                  }
+                                              });
+        }
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="primAsset"></param>
+        /// <param name="pos"></param>
+        public void RezObject(AssetBase primAsset, LLVector3 pos)
+        {
+
+        }
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="packet"></param>
+        /// <param name="simClient"></param>
+        public void DeRezObject(Packet packet, IClientAPI simClient)
+        {
+
+        }
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="remoteClient"></param>
+        public void SendAvatarsToClient(IClientAPI remoteClient)
+        {
+
+        }
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="originalPrim"></param>
+        /// <param name="offset"></param>
+        /// <param name="flags"></param>
+        public void DuplicateObject(uint originalPrim, LLVector3 offset, uint flags)
+        {
+            SceneObject originPrim = null;
+            foreach (EntityBase ent in Entities.Values)
+            {
+                if (ent is SceneObject)
+                {
+                    if (((SceneObject)ent).rootLocalID == originalPrim)
+                    {
+                        originPrim = (SceneObject)ent;
+                        break;
+                    }
+                }
+            }
+
+            if (originPrim != null)
+            {
+                SceneObject copy = originPrim.Copy();
+                copy.Pos = copy.Pos + offset;
+                this.Entities.Add(copy.rootUUID, copy);
+
+                List<ScenePresence> avatars = this.RequestAvatarList();
+                for (int i = 0; i < avatars.Count; i++)
+                {
+                    copy.SendAllChildPrimsToClient(avatars[i].ControllingClient);
+                }
+
+            }
+            else
+            {
+                OpenSim.Framework.Console.MainLog.Instance.Warn("Attempted to duplicate nonexistant prim");
+            }
+
+        }
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="parentPrim"></param>
+        /// <param name="childPrims"></param>
+        public void LinkObjects(uint parentPrim, List<uint> childPrims)
+        {
+            SceneObject parenPrim = null;
+            foreach (EntityBase ent in Entities.Values)
+            {
+                if (ent is SceneObject)
+                {
+                    if (((SceneObject)ent).rootLocalID == parentPrim)
+                    {
+                        parenPrim = (SceneObject)ent;
+                        break;
+                    }
+                }
+            }
+
+            List<SceneObject> children = new List<SceneObject>();
+            if (parenPrim != null)
+            {
+                for (int i = 0; i < childPrims.Count; i++)
+                {
+                    foreach (EntityBase ent in Entities.Values)
+                    {
+                        if (ent is SceneObject)
+                        {
+                            if (((SceneObject)ent).rootLocalID == childPrims[i])
+                            {
+                                children.Add((SceneObject)ent);
+                            }
+                        }
+                    }
+                }
+            }
+
+            foreach (SceneObject sceneObj in children)
+            {
+                parenPrim.AddNewChildPrims(sceneObj);
+            }
+        }
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="primLocalID"></param>
+        /// <param name="shapeBlock"></param>
+        public void UpdatePrimShape(uint primLocalID, ObjectShapePacket.ObjectDataBlock shapeBlock)
+        {
+            Primitive prim = null;
+            foreach (EntityBase ent in Entities.Values)
+            {
+                if (ent is SceneObject)
+                {
+                    prim = ((SceneObject)ent).HasChildPrim(primLocalID);
+                    if (prim != null)
+                    {
+                        prim.UpdateShape(shapeBlock);
+                        break;
+                    }
+                }
+            }
+        }
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="primLocalID"></param>
+        /// <param name="remoteClient"></param>
+        public void SelectPrim(uint primLocalID, IClientAPI remoteClient)
+        {
+            foreach (EntityBase ent in Entities.Values)
+            {
+                if (ent is SceneObject)
+                {
+                    if (((SceneObject)ent).rootLocalID == primLocalID)
+                    {
+                        ((SceneObject)ent).GetProperites(remoteClient);
+                        ((SceneObject)ent).isSelected = true;
+                        this.ParcelManager.setPrimsTainted();
+                        break;
+                    }
+                }
+            }
+        }
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="primLocalID"></param>
+        /// <param name="remoteClient"></param>
+        public void DeselectPrim(uint primLocalID, IClientAPI remoteClient)
+        {
+            foreach (EntityBase ent in Entities.Values)
+            {
+                if (ent is SceneObject)
+                {
+                    if (((SceneObject)ent).rootLocalID == primLocalID)
+                    {
+                        ((SceneObject)ent).isSelected = false;
+                        this.ParcelManager.setPrimsTainted();
+                        break;
+                    }
+                }
+            }
+        }
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="primLocalID"></param>
+        /// <param name="description"></param>
+        public void PrimDescription(uint primLocalID, string description)
+        {
+            Primitive prim = null;
+            foreach (EntityBase ent in Entities.Values)
+            {
+                if (ent is SceneObject)
+                {
+                    prim = ((SceneObject)ent).HasChildPrim(primLocalID);
+                    if (prim != null)
+                    {
+                        prim.Description = description;
+                        break;
+                    }
+                }
+            }
+        }
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="primLocalID"></param>
+        /// <param name="description"></param>
+        public void PrimName(uint primLocalID, string name)
+        {
+            Primitive prim = null;
+            foreach (EntityBase ent in Entities.Values)
+            {
+                if (ent is SceneObject)
+                {
+                    prim = ((SceneObject)ent).HasChildPrim(primLocalID);
+                    if (prim != null)
+                    {
+                        prim.Name = name;
+                        break;
+                    }
+                }
+            }
+        }
+
+        public void MoveObject(LLUUID objectID, LLVector3 offset, LLVector3 pos, IClientAPI remoteClient)
+        {
+            Primitive prim = null;
+            foreach (EntityBase ent in Entities.Values)
+            {
+                if (ent is SceneObject)
+                {
+                    prim = ((SceneObject)ent).HasChildPrim(objectID);
+                    if (prim != null)
+                    {
+                        ((SceneObject)ent).GrapMovement(offset, pos, remoteClient);
+                        break;
+                    }
+                }
+            }
+            /*
+            if (this.Entities.ContainsKey(objectID))
+            {
+                if (this.Entities[objectID] is SceneObject)
+                {
+                    ((SceneObject)this.Entities[objectID]).GrapMovement(offset, pos, remoteClient);
+                }
+            }*/
+        }
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="localID"></param>
+        /// <param name="packet"></param>
+        /// <param name="remoteClient"></param>
+        public void UpdatePrimFlags(uint localID, Packet packet, IClientAPI remoteClient)
+        {
+
+        }
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="localID"></param>
+        /// <param name="texture"></param>
+        /// <param name="remoteClient"></param>
+        public void UpdatePrimTexture(uint localID, byte[] texture, IClientAPI remoteClient)
+        {
+            Primitive prim = null;
+            foreach (EntityBase ent in Entities.Values)
+            {
+                if (ent is SceneObject)
+                {
+                    prim = ((SceneObject)ent).HasChildPrim(localID);
+                    if (prim != null)
+                    {
+                        prim.UpdateTextureEntry(texture);
+                    }
+                }
+            }
+        }
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="localID"></param>
+        /// <param name="pos"></param>
+        /// <param name="remoteClient"></param>
+        public void UpdatePrimPosition(uint localID, LLVector3 pos, IClientAPI remoteClient)
+        {
+            Primitive prim = null;
+            foreach (EntityBase ent in Entities.Values)
+            {
+                if (ent is SceneObject)
+                {
+                    prim = ((SceneObject)ent).HasChildPrim(localID);
+                    if (prim != null)
+                    {
+                        prim.UpdateGroupPosition(pos);
+                        break;
+                    }
+                }
+            }
+        }
+
+        public void UpdatePrimSinglePosition(uint localID, LLVector3 pos, IClientAPI remoteClient)
+        {
+            Primitive prim = null;
+            foreach (EntityBase ent in Entities.Values)
+            {
+                if (ent is SceneObject)
+                {
+                    prim = ((SceneObject)ent).HasChildPrim(localID);
+                    if (prim != null)
+                    {
+                        prim.UpdateSinglePosition(pos);
+                        break;
+                    }
+                }
+            }
+        }
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="localID"></param>
+        /// <param name="pos"></param>
+        /// <param name="rot"></param>
+        /// <param name="remoteClient"></param>
+        public void UpdatePrimRotation(uint localID, LLVector3 pos, LLQuaternion rot, IClientAPI remoteClient)
+        {
+            Primitive prim = null;
+            foreach (EntityBase ent in Entities.Values)
+            {
+                if (ent is SceneObject)
+                {
+                    prim = ((SceneObject)ent).HasChildPrim(localID);
+                    if (prim != null)
+                    {
+                        prim.UpdateGroupMouseRotation(pos, rot);
+                        break;
+                    }
+                }
+            }
+        }
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="localID"></param>
+        /// <param name="rot"></param>
+        /// <param name="remoteClient"></param>
+        public void UpdatePrimRotation(uint localID, LLQuaternion rot, IClientAPI remoteClient)
+        {
+            Primitive prim = null;
+            foreach (EntityBase ent in Entities.Values)
+            {
+                if (ent is SceneObject)
+                {
+                    prim = ((SceneObject)ent).HasChildPrim(localID);
+                    if (prim != null)
+                    {
+                        prim.UpdateGroupRotation(rot);
+                        break;
+                    }
+                }
+            }
+        }
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="localID"></param>
+        /// <param name="rot"></param>
+        /// <param name="remoteClient"></param>
+        public void UpdatePrimSingleRotation(uint localID, LLQuaternion rot, IClientAPI remoteClient)
+        {
+            //Console.WriteLine("trying to update single prim rotation");
+            Primitive prim = null;
+            foreach (EntityBase ent in Entities.Values)
+            {
+                if (ent is SceneObject)
+                {
+                    prim = ((SceneObject)ent).HasChildPrim(localID);
+                    if (prim != null)
+                    {
+                        prim.UpdateSingleRotation(rot);
+                        break;
+                    }
+                }
+            }
+        }
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="localID"></param>
+        /// <param name="scale"></param>
+        /// <param name="remoteClient"></param>
+        public void UpdatePrimScale(uint localID, LLVector3 scale, IClientAPI remoteClient)
+        {
+            Primitive prim = null;
+            foreach (EntityBase ent in Entities.Values)
+            {
+                if (ent is SceneObject)
+                {
+                    prim = ((SceneObject)ent).HasChildPrim(localID);
+                    if (prim != null)
+                    {
+                        prim.ResizeGoup(scale);
+                        break;
+                    }
+                }
+            }
+        }
+
+        /// <summary>
+        /// Sends prims to a client
+        /// </summary>
+        /// <param name="RemoteClient">Client to send to</param>
+        public void GetInitialPrims(IClientAPI RemoteClient)
+        {
+
+        }
+    }
+}
diff --git a/OpenSim/Region/Environment/Scenes/Scene.cs b/OpenSim/Region/Environment/Scenes/Scene.cs
index 1e69c9e..a06d74d 100644
--- a/OpenSim/Region/Environment/Scenes/Scene.cs
+++ b/OpenSim/Region/Environment/Scenes/Scene.cs
@@ -1,919 +1,919 @@
-/*
-* Copyright (c) Contributors, http://www.openmetaverse.org/
-* See CONTRIBUTORS.TXT for a full list of copyright holders.
-*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted provided that the following conditions are met:
-*     * Redistributions of source code must retain the above copyright
-*       notice, this list of conditions and the following disclaimer.
-*     * Redistributions in binary form must reproduce the above copyright
-*       notice, this list of conditions and the following disclaimer in the
-*       documentation and/or other materials provided with the distribution.
-*     * Neither the name of the OpenSim Project nor the
-*       names of its contributors may be used to endorse or promote products
-*       derived from this software without specific prior written permission.
-*
-* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
-* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
-* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-* 
-*/
-using System;
-using System.Collections.Generic;
-using System.Threading;
-using System.Timers;
-using libsecondlife;
-using libsecondlife.Packets;
-using OpenSim.Framework;
-using OpenSim.Framework.Communications;
-using OpenSim.Framework.Console;
-using OpenSim.Framework.Interfaces;
-using OpenSim.Framework.Servers;
-using OpenSim.Framework.Types;
-using OpenSim.Physics.Manager;
-using OpenSim.Region.Caches;
-using OpenSim.Region.Interfaces;
-using OpenSim.Region.Scripting;
-using OpenSim.Region.Terrain;
-using Caps = OpenSim.Region.Capabilities.Caps;
-using Timer = System.Timers.Timer;
-
-namespace OpenSim.Region.Environment.Scenes
-{
-    public delegate bool FilterAvatarList(ScenePresence avatar);
-    public delegate void ForEachScenePresenceDelegate(ScenePresence presence);
-
-    public partial class Scene : SceneBase, ILocalStorageReceiver
-    {
-        protected Timer m_heartbeatTimer = new Timer();
-        protected Dictionary<LLUUID, ScenePresence> Avatars;
-        protected Dictionary<LLUUID, SceneObject> Prims;
-        protected PhysicsScene phyScene;
-        protected float timeStep = 0.1f;
-        private Random Rand = new Random();
-        private uint _primCount = 702000;
-        private System.Threading.Mutex _primAllocateMutex = new Mutex(false);
-        private int storageCount;
-        private int parcelPrimCheckCount;
-        private Mutex updateLock;
-
-        protected AuthenticateSessionsBase authenticateHandler;
-        protected RegionCommsListener regionCommsHost;
-        protected CommunicationsManager commsManager;
-        protected StorageManager storageManager;
-
-        protected Dictionary<LLUUID, Caps> capsHandlers = new Dictionary<LLUUID, Caps>();
-        protected BaseHttpServer httpListener;
-
-        #region Properties
-        /// <summary>
-        /// 
-        /// </summary>
-        public PhysicsScene PhysScene
-        {
-            set
-            {
-                this.phyScene = value;
-            }
-            get
-            {
-                return (this.phyScene);
-            }
-        }
-
-        private ParcelManager m_parcelManager;
-        public ParcelManager ParcelManager
-        {
-            get { return m_parcelManager; }
-        }
-
-        private EstateManager m_estateManager;
-        public EstateManager EstateManager
-        {
-            get { return m_estateManager; }
-        }
-
-        private EventManager m_eventManager;
-        public EventManager EventManager
-        {
-            get { return m_eventManager; }
-        }
-
-        private ScriptManager m_scriptManager;
-        public ScriptManager ScriptManager
-        {
-            get { return m_scriptManager; }
-        }
-
-        public Dictionary<LLUUID, SceneObject> Objects
-        {
-            get { return Prims; }
-        }
-
-        #endregion
-
-        #region Constructors
-        /// <summary>
-        /// Creates a new World class, and a region to go with it.
-        /// </summary>
-        /// <param name="clientThreads">Dictionary to contain client threads</param>
-        /// <param name="regionHandle">Region Handle for this region</param>
-        /// <param name="regionName">Region Name for this region</param>
-        public Scene(RegionInfo regInfo, AuthenticateSessionsBase authen, CommunicationsManager commsMan, AssetCache assetCach, StorageManager storeManager, BaseHttpServer httpServer)
-        {
-            updateLock = new Mutex(false);
-            this.authenticateHandler = authen;
-            this.commsManager = commsMan;
-            this.storageManager = storeManager;
-            this.assetCache = assetCach;
-            m_regInfo = regInfo;
-            m_regionHandle = m_regInfo.RegionHandle;
-            m_regionName = m_regInfo.RegionName;
-            this.m_datastore = m_regInfo.DataStore;
-            this.RegisterRegionWithComms();
-
-            m_parcelManager = new ParcelManager(this, this.m_regInfo);
-            m_estateManager = new EstateManager(this, this.m_regInfo);
-            m_scriptManager = new ScriptManager(this);
-            m_eventManager = new EventManager();
-
-            m_eventManager.OnParcelPrimCountAdd += new EventManager.OnParcelPrimCountAddDelegate(m_parcelManager.addPrimToParcelCounts);
-
-            MainLog.Instance.Verbose("World.cs - creating new entitities instance");
-            Entities = new Dictionary<LLUUID, EntityBase>();
-            Avatars = new Dictionary<LLUUID, ScenePresence>();
-            Prims = new Dictionary<LLUUID, SceneObject>();
-
-            MainLog.Instance.Verbose("World.cs - loading objects from datastore");
-            List<SceneObject> PrimsFromDB = storageManager.DataStore.LoadObjects();
-            foreach (SceneObject prim in PrimsFromDB)
-            {
-                AddEntity(prim);
-            }
-            MainLog.Instance.Verbose("World.cs - loaded " + PrimsFromDB.Count.ToString() + " object(s)");
-
-
-            MainLog.Instance.Verbose("World.cs - creating LandMap");
-            Terrain = new TerrainEngine();
-
-            ScenePresence.LoadAnims();
-
-            this.httpListener = httpServer;
-        }
-        #endregion
-
-        #region Script Handling Methods
-
-        public void SendCommandToScripts(string[] args)
-        {
-            m_eventManager.TriggerOnScriptConsole(args);
-        }
-
-        #endregion
-
-        /// <summary>
-        /// 
-        /// </summary>
-        public void StartTimer()
-        {
-            m_heartbeatTimer.Enabled = true;
-            m_heartbeatTimer.Interval = 100;
-            m_heartbeatTimer.Elapsed += new ElapsedEventHandler(this.Heartbeat);
-        }
-
-
-        #region Update Methods
-
-
-        /// <summary>
-        /// Performs per-frame updates regularly
-        /// </summary>
-        /// <param name="sender"></param>
-        /// <param name="e"></param>
-        void Heartbeat(object sender, EventArgs e)
-        {
-            this.Update();
-        }
-
-        /// <summary>
-        /// Performs per-frame updates on the world, this should be the central world loop
-        /// </summary>
-        public override void Update()
-        {
-            updateLock.WaitOne();
-            try
-            {
-                if (this.phyScene.IsThreaded)
-                {
-                    this.phyScene.GetResults();
-
-                }
-
-                foreach (LLUUID UUID in Entities.Keys)
-                {
-                    Entities[UUID].updateMovement();
-                }
-
-                lock (this.m_syncRoot)
-                {
-                    this.phyScene.Simulate(timeStep);
-                }
-
-                foreach (LLUUID UUID in Entities.Keys)
-                {
-                    Entities[UUID].update();
-                }
-
-                // General purpose event manager
-                m_eventManager.TriggerOnFrame();
-
-                //backup world data
-                this.storageCount++;
-                if (storageCount > 1200) //set to how often you want to backup 
-                {
-                    this.Backup();
-                    storageCount = 0;
-                }
-
-                this.parcelPrimCheckCount++;
-                if (this.parcelPrimCheckCount > 50) //check every 5 seconds for tainted prims
-                {
-                    if (m_parcelManager.parcelPrimCountTainted)
-                    {
-                        //Perform parcel update of prim count
-                        performParcelPrimCountUpdate();
-                        this.parcelPrimCheckCount = 0;
-                    }
-                }
-
-            }
-            catch (Exception e)
-            {
-                MainLog.Instance.Warn("World.cs: Update() - Failed with exception " + e.ToString());
-            }
-            updateLock.ReleaseMutex();
-
-        }
-
-        /// <summary>
-        /// 
-        /// </summary>
-        /// <returns></returns>
-        public bool Backup()
-        {
-            EventManager.TriggerOnBackup(this.storageManager.DataStore);
-            return true;
-        }
-        #endregion
-
-        #region Regenerate Terrain
-
-        /// <summary>
-        /// Rebuilds the terrain using a procedural algorithm
-        /// </summary>
-        public void RegenerateTerrain()
-        {
-            try
-            {
-                Terrain.hills();
-
-                lock (this.m_syncRoot)
-                {
-                    this.phyScene.SetTerrain(Terrain.getHeights1D());
-                }
-
-                this.storageManager.DataStore.StoreTerrain(Terrain.getHeights2DD());
-
-                this.ForEachScenePresence(delegate(ScenePresence presence)
-                                                  {
-                                                      this.SendLayerData(presence.ControllingClient);
-                                                  });
-
-                foreach (LLUUID UUID in Entities.Keys)
-                {
-                    Entities[UUID].LandRenegerated();
-                }
-            }
-            catch (Exception e)
-            {
-                MainLog.Instance.Warn("World.cs: RegenerateTerrain() - Failed with exception " + e.ToString());
-            }
-        }
-
-        /// <summary>
-        /// Rebuilds the terrain using a 2D float array
-        /// </summary>
-        /// <param name="newMap">256,256 float array containing heights</param>
-        public void RegenerateTerrain(float[,] newMap)
-        {
-            try
-            {
-                this.Terrain.setHeights2D(newMap);
-                lock (this.m_syncRoot)
-                {
-                    this.phyScene.SetTerrain(this.Terrain.getHeights1D());
-                }
-                this.storageManager.DataStore.StoreTerrain(Terrain.getHeights2DD());
-
-                this.ForEachScenePresence(delegate(ScenePresence presence)
-                                                  {
-                                                      this.SendLayerData(presence.ControllingClient);
-                                                  });
-
-                foreach (LLUUID UUID in Entities.Keys)
-                {
-                    Entities[UUID].LandRenegerated();
-                }
-            }
-            catch (Exception e)
-            {
-                MainLog.Instance.Warn("World.cs: RegenerateTerrain() - Failed with exception " + e.ToString());
-            }
-        }
-
-        /// <summary>
-        /// Rebuilds the terrain assuming changes occured at a specified point[?]
-        /// </summary>
-        /// <param name="changes">???</param>
-        /// <param name="pointx">???</param>
-        /// <param name="pointy">???</param>
-        public void RegenerateTerrain(bool changes, int pointx, int pointy)
-        {
-            try
-            {
-                if (changes)
-                {
-                    /* Dont save here, rely on tainting system instead */
-
-                    this.ForEachScenePresence(delegate(ScenePresence presence)
-                                                      {
-                                                          this.SendLayerData(pointx, pointy, presence.ControllingClient);
-                                                      });
-                }
-            }
-            catch (Exception e)
-            {
-                MainLog.Instance.Warn("World.cs: RegenerateTerrain() - Failed with exception " + e.ToString());
-            }
-        }
-
-        #endregion
-
-        #region Load Terrain
-        /// <summary>
-        /// Loads the World heightmap
-        /// </summary>
-        /// 
-        public override void LoadWorldMap()
-        {
-            try
-            {
-                double[,] map = this.storageManager.DataStore.LoadTerrain();
-                if (map == null)
-                {
-                    if (string.IsNullOrEmpty(this.m_regInfo.estateSettings.terrainFile))
-                    {
-                        Console.WriteLine("No default terrain, procedurally generating...");
-                        this.Terrain.hills();
-
-                        this.storageManager.DataStore.StoreTerrain(this.Terrain.getHeights2DD());
-                    }
-                    else
-                    {
-                        try
-                        {
-                            this.Terrain.loadFromFileF32(this.m_regInfo.estateSettings.terrainFile);
-                            this.Terrain *= this.m_regInfo.estateSettings.terrainMultiplier;
-                        }
-                        catch
-                        {
-                            Console.WriteLine("Unable to load default terrain, procedurally generating instead...");
-                            Terrain.hills();
-                        }
-                        this.storageManager.DataStore.StoreTerrain(this.Terrain.getHeights2DD());
-                    }
-                }
-                else
-                {
-                    this.Terrain.setHeights2D(map);
-                }
-
-                CreateTerrainTexture();
-
-            }
-            catch (Exception e)
-            {
-                MainLog.Instance.Warn("World.cs: LoadWorldMap() - Failed with exception " + e.ToString());
-            }
-        }
-
-        /// <summary>
-        /// 
-        /// </summary>
-        public void CreateTerrainTexture()
-        {
-            //create a texture asset of the terrain 
-            byte[] data = this.Terrain.exportJpegImage("defaultstripe.png");
-            this.m_regInfo.estateSettings.terrainImageID = LLUUID.Random();
-            AssetBase asset = new AssetBase();
-            asset.FullID = this.m_regInfo.estateSettings.terrainImageID;
-            asset.Data = data;
-            asset.Name = "terrainImage";
-            asset.Type = 0;
-            this.assetCache.AddAsset(asset);
-        }
-        #endregion
-
-        #region Primitives Methods
-
-
-        /// <summary>
-        /// Loads the World's objects
-        /// </summary>
-        public void LoadPrimsFromStorage()
-        {
-            try
-            {
-                MainLog.Instance.Verbose("World.cs: LoadPrimsFromStorage() - Loading primitives");
-                this.localStorage.LoadPrimitives(this);
-            }
-            catch (Exception e)
-            {
-                MainLog.Instance.Warn("World.cs: LoadPrimsFromStorage() - Failed with exception " + e.ToString());
-            }
-        }
-
-        /// <summary>
-        /// Loads a specific object from storage
-        /// </summary>
-        /// <param name="prim">The object to load</param>
-        public void PrimFromStorage(PrimData prim)
-        {
-        }
-
-        /// <summary>
-        /// Returns a new unallocated primitive ID
-        /// </summary>
-        /// <returns>A brand new primitive ID</returns>
-        public uint PrimIDAllocate()
-        {
-            uint myID;
-
-            _primAllocateMutex.WaitOne();
-            ++_primCount;
-            myID = _primCount;
-            _primAllocateMutex.ReleaseMutex();
-
-            return myID;
-        }
-
-        /// <summary>
-        /// 
-        /// </summary>
-        /// <param name="addPacket"></param>
-        /// <param name="ownerID"></param>
-        public void AddNewPrim(LLUUID ownerID, LLVector3 pos, PrimitiveBaseShape shape)
-        {
-
-            SceneObject sceneOb = new SceneObject(this, m_eventManager, ownerID, this.PrimIDAllocate(), pos, shape);
-            AddEntity(sceneOb);
-        }
-
-        public void RemovePrim(uint localID, LLUUID avatar_deleter)
-        {
-            foreach (EntityBase obj in Entities.Values)
-            {
-                if (obj is SceneObject)
-                {
-                    if (((SceneObject)obj).LocalId == localID)
-                    {
-                        RemoveEntity((SceneObject)obj);
-                        return;
-                    }
-                }
-            }
-
-        }
-
-        public void AddEntity(SceneObject sceneObject)
-        {
-            this.Entities.Add(sceneObject.rootUUID, sceneObject);
-        }
-
-        public void RemoveEntity(SceneObject sceneObject)
-        {
-            if (this.Entities.ContainsKey(sceneObject.rootUUID))
-            {
-                m_parcelManager.removePrimFromParcelCounts(sceneObject);
-                this.Entities.Remove(sceneObject.rootUUID);
-                m_parcelManager.setPrimsTainted();
-            }
-        }
-
-        /// <summary>
-        /// Called by a prim when it has been created/cloned, so that its events can be subscribed to
-        /// </summary>
-        /// <param name="prim"></param>
-        public void AcknowledgeNewPrim(Primitive prim)
-        {
-            prim.OnPrimCountTainted += m_parcelManager.setPrimsTainted;
-        }
-        #endregion
-
-        #region Add/Remove Avatar Methods
-
-        /// <summary>
-        /// 
-        /// </summary>
-        /// <param name="remoteClient"></param          
-        /// <param name="agentID"></param>
-        /// <param name="child"></param>
-        public override void AddNewClient(IClientAPI client, bool child)
-        {
-            SubscribeToClientEvents(client);
-            this.m_estateManager.sendRegionHandshake(client);
-            CreateAndAddScenePresence(client);
-            this.m_parcelManager.sendParcelOverlay(client);
-
-        }
-
-        protected virtual void SubscribeToClientEvents(IClientAPI client)
-        {
-            client.OnRegionHandShakeReply += this.SendLayerData;
-            //remoteClient.OnRequestWearables += new GenericCall(this.GetInitialPrims);
-            client.OnChatFromViewer += this.SimChat;
-            client.OnInstantMessage += this.InstantMessage;
-            client.OnRequestWearables += this.InformClientOfNeighbours;
-            client.OnAddPrim += this.AddNewPrim;
-            client.OnUpdatePrimGroupPosition += this.UpdatePrimPosition;
-            client.OnUpdatePrimSinglePosition += this.UpdatePrimSinglePosition;
-            client.OnUpdatePrimGroupRotation += this.UpdatePrimRotation;
-            client.OnUpdatePrimGroupMouseRotation += this.UpdatePrimRotation;
-            client.OnUpdatePrimSingleRotation += this.UpdatePrimSingleRotation;
-            client.OnUpdatePrimScale += this.UpdatePrimScale;
-            client.OnUpdatePrimShape += this.UpdatePrimShape;
-            client.OnRequestMapBlocks += this.RequestMapBlocks;
-            client.OnUpdatePrimTexture += this.UpdatePrimTexture;
-            client.OnTeleportLocationRequest += this.RequestTeleportLocation;
-            client.OnObjectSelect += this.SelectPrim;
-            client.OnObjectDeselect += this.DeselectPrim;
-            client.OnGrapUpdate += this.MoveObject;
-            client.OnNameFromUUIDRequest += this.commsManager.HandleUUIDNameRequest;
-            client.OnObjectDescription += this.PrimDescription;
-            client.OnObjectName += this.PrimName;
-            client.OnLinkObjects += this.LinkObjects;
-            client.OnObjectDuplicate += this.DuplicateObject;
-
-            client.OnParcelPropertiesRequest += new ParcelPropertiesRequest(m_parcelManager.handleParcelPropertiesRequest);
-            client.OnParcelDivideRequest += new ParcelDivideRequest(m_parcelManager.handleParcelDivideRequest);
-            client.OnParcelJoinRequest += new ParcelJoinRequest(m_parcelManager.handleParcelJoinRequest);
-            client.OnParcelPropertiesUpdateRequest += new ParcelPropertiesUpdateRequest(m_parcelManager.handleParcelPropertiesUpdateRequest);
-            client.OnParcelSelectObjects += new ParcelSelectObjects(m_parcelManager.handleParcelSelectObjectsRequest);
-            client.OnParcelObjectOwnerRequest += new ParcelObjectOwnerRequest(m_parcelManager.handleParcelObjectOwnersRequest);
-
-            client.OnEstateOwnerMessage += new EstateOwnerMessageRequest(m_estateManager.handleEstateOwnerMessage);
-
-        }
-
-        protected ScenePresence CreateAndAddScenePresence(IClientAPI client)
-        {
-            ScenePresence newAvatar = null;
-
-            MainLog.Instance.Verbose("World.cs:AddViewerAgent() - Creating new avatar for remote viewer agent");
-            newAvatar = new ScenePresence(client, this, this.m_regInfo);
-            MainLog.Instance.Verbose("World.cs:AddViewerAgent() - Adding new avatar to world");
-            MainLog.Instance.Verbose("World.cs:AddViewerAgent() - Starting RegionHandshake ");
-
-            PhysicsVector pVec = new PhysicsVector(newAvatar.Pos.X, newAvatar.Pos.Y, newAvatar.Pos.Z);
-            lock (this.m_syncRoot)
-            {
-                newAvatar.PhysActor = this.phyScene.AddAvatar(pVec);
-            }
-
-            lock (Entities)
-            {
-                if (!Entities.ContainsKey(client.AgentId))
-                {
-                    this.Entities.Add(client.AgentId, newAvatar);
-                }
-                else
-                {
-                    Entities[client.AgentId] = newAvatar;
-                }
-            }
-            lock (Avatars)
-            {
-                if (Avatars.ContainsKey(client.AgentId))
-                {
-                    Avatars[client.AgentId] = newAvatar;
-                }
-                else
-                {
-                    this.Avatars.Add(client.AgentId, newAvatar);
-                }
-            }
-            newAvatar.OnSignificantClientMovement += m_parcelManager.handleSignificantClientMovement;
-            return newAvatar;
-        }
-
-
-        /// <summary>
-        /// 
-        /// </summary>
-        /// <param name="agentID"></param>
-        public override void RemoveClient(LLUUID agentID)
-        {
-            m_eventManager.TriggerOnRemovePresence(agentID);
-
-            ScenePresence avatar = this.RequestAvatar(agentID);
-
-            this.ForEachScenePresence(
-            delegate(ScenePresence presence)
-            {
-                presence.ControllingClient.SendKillObject(avatar.RegionHandle, avatar.LocalId);
-            });
-
-            lock (Avatars)
-            {
-                if (Avatars.ContainsKey(agentID))
-                {
-                    Avatars.Remove(agentID);
-                }
-            }
-            lock (Entities)
-            {
-                if (Entities.ContainsKey(agentID))
-                {
-                    Entities.Remove(agentID);
-                }
-            }
-            // TODO: Add the removal from physics ?
-
-
-
-            return;
-        }
-        #endregion
-
-        #region Request Avatars List Methods
-        //The idea is to have a group of method that return a list of avatars meeting some requirement
-        // ie it could be all Avatars within a certain range of the calling prim/avatar. 
-
-        /// <summary>
-        /// Request a List of all Avatars in this World
-        /// </summary>
-        /// <returns></returns>
-        public List<ScenePresence> RequestAvatarList()
-        {
-            List<ScenePresence> result = new List<ScenePresence>();
-
-            foreach (ScenePresence avatar in Avatars.Values)
-            {
-                result.Add(avatar);
-            }
-
-            return result;
-        }
-
-        /// <summary>
-        /// Request a filtered list of Avatars in this World
-        /// </summary>
-        /// <returns></returns>
-        public List<ScenePresence> RequestAvatarList(FilterAvatarList filter)
-        {
-            List<ScenePresence> result = new List<ScenePresence>();
-
-            foreach (ScenePresence avatar in Avatars.Values)
-            {
-                if (filter(avatar))
-                {
-                    result.Add(avatar);
-                }
-            }
-
-            return result;
-        }
-
-        /// <summary>
-        /// Request a Avatar by UUID
-        /// </summary>
-        /// <param name="avatarID"></param>
-        /// <returns></returns>
-        public ScenePresence RequestAvatar(LLUUID avatarID)
-        {
-            if (this.Avatars.ContainsKey(avatarID))
-            {
-                return Avatars[avatarID];
-            }
-            return null;
-        }
-
-        public void ForEachScenePresence(ForEachScenePresenceDelegate whatToDo)
-        {
-            foreach (ScenePresence presence in this.Avatars.Values)
-            {
-                whatToDo(presence);
-            }
-        }
-        #endregion
-
-
-        /// <summary>
-        /// 
-        /// </summary>
-        /// <param name="entID"></param>
-        /// <returns></returns>
-        public bool DeleteEntity(LLUUID entID)
-        {
-            if (this.Entities.ContainsKey(entID))
-            {
-                this.Entities.Remove(entID);
-                return true;
-            }
-            return false;
-        }
-
-        public void SendAllSceneObjectsToClient(IClientAPI client)
-        {
-            foreach (EntityBase ent in Entities.Values)
-            {
-                if (ent is SceneObject)
-                {
-                    ((SceneObject)ent).SendAllChildPrimsToClient(client);
-                }
-            }
-        }
-
-        #region RegionCommsHost
-
-        /// <summary>
-        /// 
-        /// </summary>
-        public void RegisterRegionWithComms()
-        {
-
-            this.regionCommsHost = this.commsManager.GridServer.RegisterRegion(this.m_regInfo);
-            if (this.regionCommsHost != null)
-            {
-                this.regionCommsHost.OnExpectUser += this.NewUserConnection;
-                this.regionCommsHost.OnAvatarCrossingIntoRegion += this.AgentCrossing;
-            }
-        }
-
-        /// <summary>
-        /// 
-        /// </summary>
-        /// <param name="regionHandle"></param>
-        /// <param name="agent"></param>
-        public void NewUserConnection(ulong regionHandle, AgentCircuitData agent)
-        {
-            // Console.WriteLine("World.cs - add new user connection");
-            //should just check that its meant for this region 
-            if (regionHandle == this.m_regInfo.RegionHandle)
-            {
-                if (agent.CapsPath != "")
-                {
-                    //Console.WriteLine("new user, so creating caps handler for it");
-                    Caps cap = new Caps(this.assetCache, httpListener, this.m_regInfo.ExternalHostName, this.m_regInfo.ExternalEndPoint.Port, agent.CapsPath, agent.AgentID);
-                    cap.RegisterHandlers();
-                    if (capsHandlers.ContainsKey(agent.AgentID))
-                    {
-                        OpenSim.Framework.Console.MainLog.Instance.Warn("Adding duplicate CAPS entry for user " + agent.AgentID.ToStringHyphenated());
-                        this.capsHandlers[agent.AgentID] = cap;
-                    }
-                    else
-                    {
-                        this.capsHandlers.Add(agent.AgentID, cap);
-                    }
-
-                }
-                this.authenticateHandler.AddNewCircuit(agent.circuitcode, agent);
-            }
-        }
-
-        public void AgentCrossing(ulong regionHandle, LLUUID agentID, LLVector3 position)
-        {
-            if (regionHandle == this.m_regInfo.RegionHandle)
-            {
-                if (this.Avatars.ContainsKey(agentID))
-                {
-                    this.Avatars[agentID].MakeAvatar(position);
-                }
-            }
-        }
-
-        /// <summary>
-        /// 
-        /// </summary>
-        public void InformClientOfNeighbours(IClientAPI remoteClient)
-        {
-            List<RegionInfo> neighbours = this.commsManager.GridServer.RequestNeighbours(this.m_regInfo);
-
-            if (neighbours != null)
-            {
-                for (int i = 0; i < neighbours.Count; i++)
-                {
-                    AgentCircuitData agent = remoteClient.RequestClientInfo();
-                    agent.BaseFolder = LLUUID.Zero;
-                    agent.InventoryFolder = LLUUID.Zero;
-                    agent.startpos = new LLVector3(128, 128, 70);
-                    agent.child = true;
-                    this.commsManager.InterRegion.InformRegionOfChildAgent(neighbours[i].RegionHandle, agent);
-                    remoteClient.InformClientOfNeighbour(neighbours[i].RegionHandle, neighbours[i].ExternalEndPoint);
-                    //this.capsHandlers[remoteClient.AgentId].CreateEstablishAgentComms("", System.Net.IPAddress.Parse(neighbours[i].CommsIPListenAddr) + ":" + neighbours[i].CommsIPListenPort);
-                }
-            }
-        }
-
-        /// <summary>
-        /// 
-        /// </summary>
-        /// <param name="regionHandle"></param>
-        /// <returns></returns>
-        public RegionInfo RequestNeighbouringRegionInfo(ulong regionHandle)
-        {
-            return this.commsManager.GridServer.RequestNeighbourInfo(regionHandle);
-        }
-
-        /// <summary>
-        /// 
-        /// </summary>
-        /// <param name="minX"></param>
-        /// <param name="minY"></param>
-        /// <param name="maxX"></param>
-        /// <param name="maxY"></param>
-        public void RequestMapBlocks(IClientAPI remoteClient, int minX, int minY, int maxX, int maxY)
-        {
-            List<MapBlockData> mapBlocks;
-            mapBlocks = this.commsManager.GridServer.RequestNeighbourMapBlocks(minX, minY, maxX, maxY);
-            remoteClient.SendMapBlock(mapBlocks);
-        }
-
-        /// <summary>
-        /// 
-        /// </summary>
-        /// <param name="remoteClient"></param>
-        /// <param name="RegionHandle"></param>
-        /// <param name="position"></param>
-        /// <param name="lookAt"></param>
-        /// <param name="flags"></param>
-        public void RequestTeleportLocation(IClientAPI remoteClient, ulong regionHandle, LLVector3 position, LLVector3 lookAt, uint flags)
-        {
-            if (regionHandle == this.m_regionHandle)
-            {
-                if (this.Avatars.ContainsKey(remoteClient.AgentId))
-                {
-                    remoteClient.SendTeleportLocationStart();
-                    remoteClient.SendLocalTeleport(position, lookAt, flags);
-                    this.Avatars[remoteClient.AgentId].Teleport(position);
-                }
-            }
-            else
-            {
-                RegionInfo reg = this.RequestNeighbouringRegionInfo(regionHandle);
-                if (reg != null)
-                {
-                    remoteClient.SendTeleportLocationStart();
-                    AgentCircuitData agent = remoteClient.RequestClientInfo();
-                    agent.BaseFolder = LLUUID.Zero;
-                    agent.InventoryFolder = LLUUID.Zero;
-                    agent.startpos = new LLVector3(128, 128, 70);
-                    agent.child = true;
-                    this.commsManager.InterRegion.InformRegionOfChildAgent(regionHandle, agent);
-                    this.commsManager.InterRegion.ExpectAvatarCrossing(regionHandle, remoteClient.AgentId, position);
-
-                    remoteClient.SendRegionTeleport(regionHandle, 13, reg.ExternalEndPoint, 4, (1 << 4));
-
-                }
-            }
-        }
-
-        /// <summary>
-        /// 
-        /// </summary>
-        /// <param name="regionhandle"></param>
-        /// <param name="agentID"></param>
-        /// <param name="position"></param>
-        public bool InformNeighbourOfCrossing(ulong regionhandle, LLUUID agentID, LLVector3 position)
-        {
-            return this.commsManager.InterRegion.ExpectAvatarCrossing(regionhandle, agentID, position);
-        }
-
-        public void performParcelPrimCountUpdate()
-        {
-            m_parcelManager.resetAllParcelPrimCounts();
-            m_eventManager.TriggerParcelPrimCountUpdate();
-            m_parcelManager.finalizeParcelPrimCountUpdate();
-            m_parcelManager.parcelPrimCountTainted = false;
-        }
-        #endregion
-
-    }
-}
+/*
+* Copyright (c) Contributors, http://www.openmetaverse.org/
+* See CONTRIBUTORS.TXT for a full list of copyright holders.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*     * Redistributions of source code must retain the above copyright
+*       notice, this list of conditions and the following disclaimer.
+*     * Redistributions in binary form must reproduce the above copyright
+*       notice, this list of conditions and the following disclaimer in the
+*       documentation and/or other materials provided with the distribution.
+*     * Neither the name of the OpenSim Project nor the
+*       names of its contributors may be used to endorse or promote products
+*       derived from this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
+* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
+* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+* 
+*/
+using System;
+using System.Collections.Generic;
+using System.Threading;
+using System.Timers;
+using libsecondlife;
+using libsecondlife.Packets;
+using OpenSim.Framework;
+using OpenSim.Framework.Communications;
+using OpenSim.Framework.Console;
+using OpenSim.Framework.Interfaces;
+using OpenSim.Framework.Servers;
+using OpenSim.Framework.Types;
+using OpenSim.Physics.Manager;
+using OpenSim.Region.Caches;
+using OpenSim.Region.Interfaces;
+using OpenSim.Region.Scripting;
+using OpenSim.Region.Terrain;
+using Caps = OpenSim.Region.Capabilities.Caps;
+using Timer = System.Timers.Timer;
+
+namespace OpenSim.Region.Environment.Scenes
+{
+    public delegate bool FilterAvatarList(ScenePresence avatar);
+    public delegate void ForEachScenePresenceDelegate(ScenePresence presence);
+
+    public partial class Scene : SceneBase, ILocalStorageReceiver
+    {
+        protected Timer m_heartbeatTimer = new Timer();
+        protected Dictionary<LLUUID, ScenePresence> Avatars;
+        protected Dictionary<LLUUID, SceneObject> Prims;
+        protected PhysicsScene phyScene;
+        protected float timeStep = 0.1f;
+        private Random Rand = new Random();
+        private uint _primCount = 702000;
+        private System.Threading.Mutex _primAllocateMutex = new Mutex(false);
+        private int storageCount;
+        private int parcelPrimCheckCount;
+        private Mutex updateLock;
+
+        protected AuthenticateSessionsBase authenticateHandler;
+        protected RegionCommsListener regionCommsHost;
+        protected CommunicationsManager commsManager;
+        protected StorageManager storageManager;
+
+        protected Dictionary<LLUUID, Caps> capsHandlers = new Dictionary<LLUUID, Caps>();
+        protected BaseHttpServer httpListener;
+
+        #region Properties
+        /// <summary>
+        /// 
+        /// </summary>
+        public PhysicsScene PhysScene
+        {
+            set
+            {
+                this.phyScene = value;
+            }
+            get
+            {
+                return (this.phyScene);
+            }
+        }
+
+        private ParcelManager m_parcelManager;
+        public ParcelManager ParcelManager
+        {
+            get { return m_parcelManager; }
+        }
+
+        private EstateManager m_estateManager;
+        public EstateManager EstateManager
+        {
+            get { return m_estateManager; }
+        }
+
+        private EventManager m_eventManager;
+        public EventManager EventManager
+        {
+            get { return m_eventManager; }
+        }
+
+        private ScriptManager m_scriptManager;
+        public ScriptManager ScriptManager
+        {
+            get { return m_scriptManager; }
+        }
+
+        public Dictionary<LLUUID, SceneObject> Objects
+        {
+            get { return Prims; }
+        }
+
+        #endregion
+
+        #region Constructors
+        /// <summary>
+        /// Creates a new World class, and a region to go with it.
+        /// </summary>
+        /// <param name="clientThreads">Dictionary to contain client threads</param>
+        /// <param name="regionHandle">Region Handle for this region</param>
+        /// <param name="regionName">Region Name for this region</param>
+        public Scene(RegionInfo regInfo, AuthenticateSessionsBase authen, CommunicationsManager commsMan, AssetCache assetCach, StorageManager storeManager, BaseHttpServer httpServer)
+        {
+            updateLock = new Mutex(false);
+            this.authenticateHandler = authen;
+            this.commsManager = commsMan;
+            this.storageManager = storeManager;
+            this.assetCache = assetCach;
+            m_regInfo = regInfo;
+            m_regionHandle = m_regInfo.RegionHandle;
+            m_regionName = m_regInfo.RegionName;
+            this.m_datastore = m_regInfo.DataStore;
+            this.RegisterRegionWithComms();
+
+            m_parcelManager = new ParcelManager(this, this.m_regInfo);
+            m_estateManager = new EstateManager(this, this.m_regInfo);
+            m_scriptManager = new ScriptManager(this);
+            m_eventManager = new EventManager();
+
+            m_eventManager.OnParcelPrimCountAdd += new EventManager.OnParcelPrimCountAddDelegate(m_parcelManager.addPrimToParcelCounts);
+
+            MainLog.Instance.Verbose("World.cs - creating new entitities instance");
+            Entities = new Dictionary<LLUUID, EntityBase>();
+            Avatars = new Dictionary<LLUUID, ScenePresence>();
+            Prims = new Dictionary<LLUUID, SceneObject>();
+
+            MainLog.Instance.Verbose("World.cs - loading objects from datastore");
+            List<SceneObject> PrimsFromDB = storageManager.DataStore.LoadObjects();
+            foreach (SceneObject prim in PrimsFromDB)
+            {
+                AddEntity(prim);
+            }
+            MainLog.Instance.Verbose("World.cs - loaded " + PrimsFromDB.Count.ToString() + " object(s)");
+
+
+            MainLog.Instance.Verbose("World.cs - creating LandMap");
+            Terrain = new TerrainEngine();
+
+            ScenePresence.LoadAnims();
+
+            this.httpListener = httpServer;
+        }
+        #endregion
+
+        #region Script Handling Methods
+
+        public void SendCommandToScripts(string[] args)
+        {
+            m_eventManager.TriggerOnScriptConsole(args);
+        }
+
+        #endregion
+
+        /// <summary>
+        /// 
+        /// </summary>
+        public void StartTimer()
+        {
+            m_heartbeatTimer.Enabled = true;
+            m_heartbeatTimer.Interval = 100;
+            m_heartbeatTimer.Elapsed += new ElapsedEventHandler(this.Heartbeat);
+        }
+
+
+        #region Update Methods
+
+
+        /// <summary>
+        /// Performs per-frame updates regularly
+        /// </summary>
+        /// <param name="sender"></param>
+        /// <param name="e"></param>
+        void Heartbeat(object sender, EventArgs e)
+        {
+            this.Update();
+        }
+
+        /// <summary>
+        /// Performs per-frame updates on the world, this should be the central world loop
+        /// </summary>
+        public override void Update()
+        {
+            updateLock.WaitOne();
+            try
+            {
+                if (this.phyScene.IsThreaded)
+                {
+                    this.phyScene.GetResults();
+
+                }
+
+                foreach (LLUUID UUID in Entities.Keys)
+                {
+                    Entities[UUID].updateMovement();
+                }
+
+                lock (this.m_syncRoot)
+                {
+                    this.phyScene.Simulate(timeStep);
+                }
+
+                foreach (LLUUID UUID in Entities.Keys)
+                {
+                    Entities[UUID].update();
+                }
+
+                // General purpose event manager
+                m_eventManager.TriggerOnFrame();
+
+                //backup world data
+                this.storageCount++;
+                if (storageCount > 1200) //set to how often you want to backup 
+                {
+                    this.Backup();
+                    storageCount = 0;
+                }
+
+                this.parcelPrimCheckCount++;
+                if (this.parcelPrimCheckCount > 50) //check every 5 seconds for tainted prims
+                {
+                    if (m_parcelManager.parcelPrimCountTainted)
+                    {
+                        //Perform parcel update of prim count
+                        performParcelPrimCountUpdate();
+                        this.parcelPrimCheckCount = 0;
+                    }
+                }
+
+            }
+            catch (Exception e)
+            {
+                MainLog.Instance.Warn("World.cs: Update() - Failed with exception " + e.ToString());
+            }
+            updateLock.ReleaseMutex();
+
+        }
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <returns></returns>
+        public bool Backup()
+        {
+            EventManager.TriggerOnBackup(this.storageManager.DataStore);
+            return true;
+        }
+        #endregion
+
+        #region Regenerate Terrain
+
+        /// <summary>
+        /// Rebuilds the terrain using a procedural algorithm
+        /// </summary>
+        public void RegenerateTerrain()
+        {
+            try
+            {
+                Terrain.hills();
+
+                lock (this.m_syncRoot)
+                {
+                    this.phyScene.SetTerrain(Terrain.getHeights1D());
+                }
+
+                this.storageManager.DataStore.StoreTerrain(Terrain.getHeights2DD());
+
+                this.ForEachScenePresence(delegate(ScenePresence presence)
+                                                  {
+                                                      this.SendLayerData(presence.ControllingClient);
+                                                  });
+
+                foreach (LLUUID UUID in Entities.Keys)
+                {
+                    Entities[UUID].LandRenegerated();
+                }
+            }
+            catch (Exception e)
+            {
+                MainLog.Instance.Warn("World.cs: RegenerateTerrain() - Failed with exception " + e.ToString());
+            }
+        }
+
+        /// <summary>
+        /// Rebuilds the terrain using a 2D float array
+        /// </summary>
+        /// <param name="newMap">256,256 float array containing heights</param>
+        public void RegenerateTerrain(float[,] newMap)
+        {
+            try
+            {
+                this.Terrain.setHeights2D(newMap);
+                lock (this.m_syncRoot)
+                {
+                    this.phyScene.SetTerrain(this.Terrain.getHeights1D());
+                }
+                this.storageManager.DataStore.StoreTerrain(Terrain.getHeights2DD());
+
+                this.ForEachScenePresence(delegate(ScenePresence presence)
+                                                  {
+                                                      this.SendLayerData(presence.ControllingClient);
+                                                  });
+
+                foreach (LLUUID UUID in Entities.Keys)
+                {
+                    Entities[UUID].LandRenegerated();
+                }
+            }
+            catch (Exception e)
+            {
+                MainLog.Instance.Warn("World.cs: RegenerateTerrain() - Failed with exception " + e.ToString());
+            }
+        }
+
+        /// <summary>
+        /// Rebuilds the terrain assuming changes occured at a specified point[?]
+        /// </summary>
+        /// <param name="changes">???</param>
+        /// <param name="pointx">???</param>
+        /// <param name="pointy">???</param>
+        public void RegenerateTerrain(bool changes, int pointx, int pointy)
+        {
+            try
+            {
+                if (changes)
+                {
+                    /* Dont save here, rely on tainting system instead */
+
+                    this.ForEachScenePresence(delegate(ScenePresence presence)
+                                                      {
+                                                          this.SendLayerData(pointx, pointy, presence.ControllingClient);
+                                                      });
+                }
+            }
+            catch (Exception e)
+            {
+                MainLog.Instance.Warn("World.cs: RegenerateTerrain() - Failed with exception " + e.ToString());
+            }
+        }
+
+        #endregion
+
+        #region Load Terrain
+        /// <summary>
+        /// Loads the World heightmap
+        /// </summary>
+        /// 
+        public override void LoadWorldMap()
+        {
+            try
+            {
+                double[,] map = this.storageManager.DataStore.LoadTerrain();
+                if (map == null)
+                {
+                    if (string.IsNullOrEmpty(this.m_regInfo.estateSettings.terrainFile))
+                    {
+                        Console.WriteLine("No default terrain, procedurally generating...");
+                        this.Terrain.hills();
+
+                        this.storageManager.DataStore.StoreTerrain(this.Terrain.getHeights2DD());
+                    }
+                    else
+                    {
+                        try
+                        {
+                            this.Terrain.loadFromFileF32(this.m_regInfo.estateSettings.terrainFile);
+                            this.Terrain *= this.m_regInfo.estateSettings.terrainMultiplier;
+                        }
+                        catch
+                        {
+                            Console.WriteLine("Unable to load default terrain, procedurally generating instead...");
+                            Terrain.hills();
+                        }
+                        this.storageManager.DataStore.StoreTerrain(this.Terrain.getHeights2DD());
+                    }
+                }
+                else
+                {
+                    this.Terrain.setHeights2D(map);
+                }
+
+                CreateTerrainTexture();
+
+            }
+            catch (Exception e)
+            {
+                MainLog.Instance.Warn("World.cs: LoadWorldMap() - Failed with exception " + e.ToString());
+            }
+        }
+
+        /// <summary>
+        /// 
+        /// </summary>
+        public void CreateTerrainTexture()
+        {
+            //create a texture asset of the terrain 
+            byte[] data = this.Terrain.exportJpegImage("defaultstripe.png");
+            this.m_regInfo.estateSettings.terrainImageID = LLUUID.Random();
+            AssetBase asset = new AssetBase();
+            asset.FullID = this.m_regInfo.estateSettings.terrainImageID;
+            asset.Data = data;
+            asset.Name = "terrainImage";
+            asset.Type = 0;
+            this.assetCache.AddAsset(asset);
+        }
+        #endregion
+
+        #region Primitives Methods
+
+
+        /// <summary>
+        /// Loads the World's objects
+        /// </summary>
+        public void LoadPrimsFromStorage()
+        {
+            try
+            {
+                MainLog.Instance.Verbose("World.cs: LoadPrimsFromStorage() - Loading primitives");
+                this.localStorage.LoadPrimitives(this);
+            }
+            catch (Exception e)
+            {
+                MainLog.Instance.Warn("World.cs: LoadPrimsFromStorage() - Failed with exception " + e.ToString());
+            }
+        }
+
+        /// <summary>
+        /// Loads a specific object from storage
+        /// </summary>
+        /// <param name="prim">The object to load</param>
+        public void PrimFromStorage(PrimData prim)
+        {
+        }
+
+        /// <summary>
+        /// Returns a new unallocated primitive ID
+        /// </summary>
+        /// <returns>A brand new primitive ID</returns>
+        public uint PrimIDAllocate()
+        {
+            uint myID;
+
+            _primAllocateMutex.WaitOne();
+            ++_primCount;
+            myID = _primCount;
+            _primAllocateMutex.ReleaseMutex();
+
+            return myID;
+        }
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="addPacket"></param>
+        /// <param name="ownerID"></param>
+        public void AddNewPrim(LLUUID ownerID, LLVector3 pos, PrimitiveBaseShape shape)
+        {
+
+            SceneObject sceneOb = new SceneObject(this, m_eventManager, ownerID, this.PrimIDAllocate(), pos, shape);
+            AddEntity(sceneOb);
+        }
+
+        public void RemovePrim(uint localID, LLUUID avatar_deleter)
+        {
+            foreach (EntityBase obj in Entities.Values)
+            {
+                if (obj is SceneObject)
+                {
+                    if (((SceneObject)obj).LocalId == localID)
+                    {
+                        RemoveEntity((SceneObject)obj);
+                        return;
+                    }
+                }
+            }
+
+        }
+
+        public void AddEntity(SceneObject sceneObject)
+        {
+            this.Entities.Add(sceneObject.rootUUID, sceneObject);
+        }
+
+        public void RemoveEntity(SceneObject sceneObject)
+        {
+            if (this.Entities.ContainsKey(sceneObject.rootUUID))
+            {
+                m_parcelManager.removePrimFromParcelCounts(sceneObject);
+                this.Entities.Remove(sceneObject.rootUUID);
+                m_parcelManager.setPrimsTainted();
+            }
+        }
+
+        /// <summary>
+        /// Called by a prim when it has been created/cloned, so that its events can be subscribed to
+        /// </summary>
+        /// <param name="prim"></param>
+        public void AcknowledgeNewPrim(Primitive prim)
+        {
+            prim.OnPrimCountTainted += m_parcelManager.setPrimsTainted;
+        }
+        #endregion
+
+        #region Add/Remove Avatar Methods
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="remoteClient"></param          
+        /// <param name="agentID"></param>
+        /// <param name="child"></param>
+        public override void AddNewClient(IClientAPI client, bool child)
+        {
+            SubscribeToClientEvents(client);
+            this.m_estateManager.sendRegionHandshake(client);
+            CreateAndAddScenePresence(client);
+            this.m_parcelManager.sendParcelOverlay(client);
+
+        }
+
+        protected virtual void SubscribeToClientEvents(IClientAPI client)
+        {
+            client.OnRegionHandShakeReply += this.SendLayerData;
+            //remoteClient.OnRequestWearables += new GenericCall(this.GetInitialPrims);
+            client.OnChatFromViewer += this.SimChat;
+            client.OnInstantMessage += this.InstantMessage;
+            client.OnRequestWearables += this.InformClientOfNeighbours;
+            client.OnAddPrim += this.AddNewPrim;
+            client.OnUpdatePrimGroupPosition += this.UpdatePrimPosition;
+            client.OnUpdatePrimSinglePosition += this.UpdatePrimSinglePosition;
+            client.OnUpdatePrimGroupRotation += this.UpdatePrimRotation;
+            client.OnUpdatePrimGroupMouseRotation += this.UpdatePrimRotation;
+            client.OnUpdatePrimSingleRotation += this.UpdatePrimSingleRotation;
+            client.OnUpdatePrimScale += this.UpdatePrimScale;
+            client.OnUpdatePrimShape += this.UpdatePrimShape;
+            client.OnRequestMapBlocks += this.RequestMapBlocks;
+            client.OnUpdatePrimTexture += this.UpdatePrimTexture;
+            client.OnTeleportLocationRequest += this.RequestTeleportLocation;
+            client.OnObjectSelect += this.SelectPrim;
+            client.OnObjectDeselect += this.DeselectPrim;
+            client.OnGrapUpdate += this.MoveObject;
+            client.OnNameFromUUIDRequest += this.commsManager.HandleUUIDNameRequest;
+            client.OnObjectDescription += this.PrimDescription;
+            client.OnObjectName += this.PrimName;
+            client.OnLinkObjects += this.LinkObjects;
+            client.OnObjectDuplicate += this.DuplicateObject;
+
+            client.OnParcelPropertiesRequest += new ParcelPropertiesRequest(m_parcelManager.handleParcelPropertiesRequest);
+            client.OnParcelDivideRequest += new ParcelDivideRequest(m_parcelManager.handleParcelDivideRequest);
+            client.OnParcelJoinRequest += new ParcelJoinRequest(m_parcelManager.handleParcelJoinRequest);
+            client.OnParcelPropertiesUpdateRequest += new ParcelPropertiesUpdateRequest(m_parcelManager.handleParcelPropertiesUpdateRequest);
+            client.OnParcelSelectObjects += new ParcelSelectObjects(m_parcelManager.handleParcelSelectObjectsRequest);
+            client.OnParcelObjectOwnerRequest += new ParcelObjectOwnerRequest(m_parcelManager.handleParcelObjectOwnersRequest);
+
+            client.OnEstateOwnerMessage += new EstateOwnerMessageRequest(m_estateManager.handleEstateOwnerMessage);
+
+        }
+
+        protected ScenePresence CreateAndAddScenePresence(IClientAPI client)
+        {
+            ScenePresence newAvatar = null;
+
+            MainLog.Instance.Verbose("World.cs:AddViewerAgent() - Creating new avatar for remote viewer agent");
+            newAvatar = new ScenePresence(client, this, this.m_regInfo);
+            MainLog.Instance.Verbose("World.cs:AddViewerAgent() - Adding new avatar to world");
+            MainLog.Instance.Verbose("World.cs:AddViewerAgent() - Starting RegionHandshake ");
+
+            PhysicsVector pVec = new PhysicsVector(newAvatar.Pos.X, newAvatar.Pos.Y, newAvatar.Pos.Z);
+            lock (this.m_syncRoot)
+            {
+                newAvatar.PhysActor = this.phyScene.AddAvatar(pVec);
+            }
+
+            lock (Entities)
+            {
+                if (!Entities.ContainsKey(client.AgentId))
+                {
+                    this.Entities.Add(client.AgentId, newAvatar);
+                }
+                else
+                {
+                    Entities[client.AgentId] = newAvatar;
+                }
+            }
+            lock (Avatars)
+            {
+                if (Avatars.ContainsKey(client.AgentId))
+                {
+                    Avatars[client.AgentId] = newAvatar;
+                }
+                else
+                {
+                    this.Avatars.Add(client.AgentId, newAvatar);
+                }
+            }
+            newAvatar.OnSignificantClientMovement += m_parcelManager.handleSignificantClientMovement;
+            return newAvatar;
+        }
+
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="agentID"></param>
+        public override void RemoveClient(LLUUID agentID)
+        {
+            m_eventManager.TriggerOnRemovePresence(agentID);
+
+            ScenePresence avatar = this.RequestAvatar(agentID);
+
+            this.ForEachScenePresence(
+            delegate(ScenePresence presence)
+            {
+                presence.ControllingClient.SendKillObject(avatar.RegionHandle, avatar.LocalId);
+            });
+
+            lock (Avatars)
+            {
+                if (Avatars.ContainsKey(agentID))
+                {
+                    Avatars.Remove(agentID);
+                }
+            }
+            lock (Entities)
+            {
+                if (Entities.ContainsKey(agentID))
+                {
+                    Entities.Remove(agentID);
+                }
+            }
+            // TODO: Add the removal from physics ?
+
+
+
+            return;
+        }
+        #endregion
+
+        #region Request Avatars List Methods
+        //The idea is to have a group of method that return a list of avatars meeting some requirement
+        // ie it could be all Avatars within a certain range of the calling prim/avatar. 
+
+        /// <summary>
+        /// Request a List of all Avatars in this World
+        /// </summary>
+        /// <returns></returns>
+        public List<ScenePresence> RequestAvatarList()
+        {
+            List<ScenePresence> result = new List<ScenePresence>();
+
+            foreach (ScenePresence avatar in Avatars.Values)
+            {
+                result.Add(avatar);
+            }
+
+            return result;
+        }
+
+        /// <summary>
+        /// Request a filtered list of Avatars in this World
+        /// </summary>
+        /// <returns></returns>
+        public List<ScenePresence> RequestAvatarList(FilterAvatarList filter)
+        {
+            List<ScenePresence> result = new List<ScenePresence>();
+
+            foreach (ScenePresence avatar in Avatars.Values)
+            {
+                if (filter(avatar))
+                {
+                    result.Add(avatar);
+                }
+            }
+
+            return result;
+        }
+
+        /// <summary>
+        /// Request a Avatar by UUID
+        /// </summary>
+        /// <param name="avatarID"></param>
+        /// <returns></returns>
+        public ScenePresence RequestAvatar(LLUUID avatarID)
+        {
+            if (this.Avatars.ContainsKey(avatarID))
+            {
+                return Avatars[avatarID];
+            }
+            return null;
+        }
+
+        public void ForEachScenePresence(ForEachScenePresenceDelegate whatToDo)
+        {
+            foreach (ScenePresence presence in this.Avatars.Values)
+            {
+                whatToDo(presence);
+            }
+        }
+        #endregion
+
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="entID"></param>
+        /// <returns></returns>
+        public bool DeleteEntity(LLUUID entID)
+        {
+            if (this.Entities.ContainsKey(entID))
+            {
+                this.Entities.Remove(entID);
+                return true;
+            }
+            return false;
+        }
+
+        public void SendAllSceneObjectsToClient(IClientAPI client)
+        {
+            foreach (EntityBase ent in Entities.Values)
+            {
+                if (ent is SceneObject)
+                {
+                    ((SceneObject)ent).SendAllChildPrimsToClient(client);
+                }
+            }
+        }
+
+        #region RegionCommsHost
+
+        /// <summary>
+        /// 
+        /// </summary>
+        public void RegisterRegionWithComms()
+        {
+
+            this.regionCommsHost = this.commsManager.GridServer.RegisterRegion(this.m_regInfo);
+            if (this.regionCommsHost != null)
+            {
+                this.regionCommsHost.OnExpectUser += this.NewUserConnection;
+                this.regionCommsHost.OnAvatarCrossingIntoRegion += this.AgentCrossing;
+            }
+        }
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="regionHandle"></param>
+        /// <param name="agent"></param>
+        public void NewUserConnection(ulong regionHandle, AgentCircuitData agent)
+        {
+            // Console.WriteLine("World.cs - add new user connection");
+            //should just check that its meant for this region 
+            if (regionHandle == this.m_regInfo.RegionHandle)
+            {
+                if (agent.CapsPath != "")
+                {
+                    //Console.WriteLine("new user, so creating caps handler for it");
+                    Caps cap = new Caps(this.assetCache, httpListener, this.m_regInfo.ExternalHostName, this.m_regInfo.ExternalEndPoint.Port, agent.CapsPath, agent.AgentID);
+                    cap.RegisterHandlers();
+                    if (capsHandlers.ContainsKey(agent.AgentID))
+                    {
+                        OpenSim.Framework.Console.MainLog.Instance.Warn("Adding duplicate CAPS entry for user " + agent.AgentID.ToStringHyphenated());
+                        this.capsHandlers[agent.AgentID] = cap;
+                    }
+                    else
+                    {
+                        this.capsHandlers.Add(agent.AgentID, cap);
+                    }
+
+                }
+                this.authenticateHandler.AddNewCircuit(agent.circuitcode, agent);
+            }
+        }
+
+        public void AgentCrossing(ulong regionHandle, LLUUID agentID, LLVector3 position)
+        {
+            if (regionHandle == this.m_regInfo.RegionHandle)
+            {
+                if (this.Avatars.ContainsKey(agentID))
+                {
+                    this.Avatars[agentID].MakeAvatar(position);
+                }
+            }
+        }
+
+        /// <summary>
+        /// 
+        /// </summary>
+        public void InformClientOfNeighbours(IClientAPI remoteClient)
+        {
+            List<RegionInfo> neighbours = this.commsManager.GridServer.RequestNeighbours(this.m_regInfo);
+
+            if (neighbours != null)
+            {
+                for (int i = 0; i < neighbours.Count; i++)
+                {
+                    AgentCircuitData agent = remoteClient.RequestClientInfo();
+                    agent.BaseFolder = LLUUID.Zero;
+                    agent.InventoryFolder = LLUUID.Zero;
+                    agent.startpos = new LLVector3(128, 128, 70);
+                    agent.child = true;
+                    this.commsManager.InterRegion.InformRegionOfChildAgent(neighbours[i].RegionHandle, agent);
+                    remoteClient.InformClientOfNeighbour(neighbours[i].RegionHandle, neighbours[i].ExternalEndPoint);
+                    //this.capsHandlers[remoteClient.AgentId].CreateEstablishAgentComms("", System.Net.IPAddress.Parse(neighbours[i].CommsIPListenAddr) + ":" + neighbours[i].CommsIPListenPort);
+                }
+            }
+        }
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="regionHandle"></param>
+        /// <returns></returns>
+        public RegionInfo RequestNeighbouringRegionInfo(ulong regionHandle)
+        {
+            return this.commsManager.GridServer.RequestNeighbourInfo(regionHandle);
+        }
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="minX"></param>
+        /// <param name="minY"></param>
+        /// <param name="maxX"></param>
+        /// <param name="maxY"></param>
+        public void RequestMapBlocks(IClientAPI remoteClient, int minX, int minY, int maxX, int maxY)
+        {
+            List<MapBlockData> mapBlocks;
+            mapBlocks = this.commsManager.GridServer.RequestNeighbourMapBlocks(minX, minY, maxX, maxY);
+            remoteClient.SendMapBlock(mapBlocks);
+        }
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="remoteClient"></param>
+        /// <param name="RegionHandle"></param>
+        /// <param name="position"></param>
+        /// <param name="lookAt"></param>
+        /// <param name="flags"></param>
+        public void RequestTeleportLocation(IClientAPI remoteClient, ulong regionHandle, LLVector3 position, LLVector3 lookAt, uint flags)
+        {
+            if (regionHandle == this.m_regionHandle)
+            {
+                if (this.Avatars.ContainsKey(remoteClient.AgentId))
+                {
+                    remoteClient.SendTeleportLocationStart();
+                    remoteClient.SendLocalTeleport(position, lookAt, flags);
+                    this.Avatars[remoteClient.AgentId].Teleport(position);
+                }
+            }
+            else
+            {
+                RegionInfo reg = this.RequestNeighbouringRegionInfo(regionHandle);
+                if (reg != null)
+                {
+                    remoteClient.SendTeleportLocationStart();
+                    AgentCircuitData agent = remoteClient.RequestClientInfo();
+                    agent.BaseFolder = LLUUID.Zero;
+                    agent.InventoryFolder = LLUUID.Zero;
+                    agent.startpos = new LLVector3(128, 128, 70);
+                    agent.child = true;
+                    this.commsManager.InterRegion.InformRegionOfChildAgent(regionHandle, agent);
+                    this.commsManager.InterRegion.ExpectAvatarCrossing(regionHandle, remoteClient.AgentId, position);
+
+                    remoteClient.SendRegionTeleport(regionHandle, 13, reg.ExternalEndPoint, 4, (1 << 4));
+
+                }
+            }
+        }
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="regionhandle"></param>
+        /// <param name="agentID"></param>
+        /// <param name="position"></param>
+        public bool InformNeighbourOfCrossing(ulong regionhandle, LLUUID agentID, LLVector3 position)
+        {
+            return this.commsManager.InterRegion.ExpectAvatarCrossing(regionhandle, agentID, position);
+        }
+
+        public void performParcelPrimCountUpdate()
+        {
+            m_parcelManager.resetAllParcelPrimCounts();
+            m_eventManager.TriggerParcelPrimCountUpdate();
+            m_parcelManager.finalizeParcelPrimCountUpdate();
+            m_parcelManager.parcelPrimCountTainted = false;
+        }
+        #endregion
+
+    }
+}
diff --git a/OpenSim/Region/Environment/Scenes/SceneBase.cs b/OpenSim/Region/Environment/Scenes/SceneBase.cs
index 161a5cf..cbf69ac 100644
--- a/OpenSim/Region/Environment/Scenes/SceneBase.cs
+++ b/OpenSim/Region/Environment/Scenes/SceneBase.cs
@@ -1,195 +1,195 @@
-/*
-* Copyright (c) Contributors, http://www.openmetaverse.org/
-* See CONTRIBUTORS.TXT for a full list of copyright holders.
-*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted provided that the following conditions are met:
-*     * Redistributions of source code must retain the above copyright
-*       notice, this list of conditions and the following disclaimer.
-*     * Redistributions in binary form must reproduce the above copyright
-*       notice, this list of conditions and the following disclaimer in the
-*       documentation and/or other materials provided with the distribution.
-*     * Neither the name of the OpenSim Project nor the
-*       names of its contributors may be used to endorse or promote products
-*       derived from this software without specific prior written permission.
-*
-* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
-* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
-* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-* 
-*/
-using System;
-using System.Collections.Generic;
-using System.Reflection;
-using libsecondlife;
-using OpenSim.Framework.Console;
-using OpenSim.Framework.Interfaces;
-using OpenSim.Framework.Types;
-using OpenSim.Region.Caches;
-using OpenSim.Region.Terrain;
-using OpenSim.Framework;
-
-namespace OpenSim.Region.Environment.Scenes
-{
-    public abstract class SceneBase :  IWorld 
-    {
-        public Dictionary<LLUUID, EntityBase> Entities;
-        protected ulong m_regionHandle;
-        protected string m_regionName;
-        protected RegionInfo m_regInfo;
-
-        public TerrainEngine Terrain;
-
-        public string m_datastore;
-        public ILocalStorage localStorage;
-
-        protected object m_syncRoot = new object();
-        private uint m_nextLocalId = 8880000;
-        protected AssetCache assetCache;
-
-        #region Update Methods
-        /// <summary>
-        /// Normally called once every frame/tick to let the world preform anything required (like running the physics simulation)
-        /// </summary>
-        public abstract void Update();
-
-        #endregion
-
-        #region Terrain Methods
-
-        /// <summary>
-        /// Loads the World heightmap
-        /// </summary>
-        public abstract void LoadWorldMap();
-
-        /// <summary>
-        /// Loads a new storage subsystem from a named library
-        /// </summary>
-        /// <param name="dllName">Storage Library</param>
-        /// <returns>Successful or not</returns>
-        public bool LoadStorageDLL(string dllName)
-        {
-            try
-            {
-                Assembly pluginAssembly = Assembly.LoadFrom(dllName);
-                ILocalStorage store = null;
-
-                foreach (Type pluginType in pluginAssembly.GetTypes())
-                {
-                    if (pluginType.IsPublic)
-                    {
-                        if (!pluginType.IsAbstract)
-                        {
-                            Type typeInterface = pluginType.GetInterface("ILocalStorage", true);
-
-                            if (typeInterface != null)
-                            {
-                                ILocalStorage plug = (ILocalStorage)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString()));
-                                store = plug;
-
-                                store.Initialise(this.m_datastore);
-                                break;
-                            }
-
-                            typeInterface = null;
-                        }
-                    }
-                }
-                pluginAssembly = null;
-                this.localStorage = store;
-                return (store == null);
-            }
-            catch (Exception e)
-            {
-                MainLog.Instance.Warn("World.cs: LoadStorageDLL() - Failed with exception " + e.ToString());
-                return false;
-            }
-        }
-
-        
-        /// <summary>
-        /// Send the region heightmap to the client
-        /// </summary>
-        /// <param name="RemoteClient">Client to send to</param>
-        public virtual void SendLayerData(IClientAPI RemoteClient)
-        {
-            RemoteClient.SendLayerData(Terrain.getHeights1D());
-        }
-
-        /// <summary>
-        /// Sends a specified patch to a client
-        /// </summary>
-        /// <param name="px">Patch coordinate (x) 0..16</param>
-        /// <param name="py">Patch coordinate (y) 0..16</param>
-        /// <param name="RemoteClient">The client to send to</param>
-        public virtual void SendLayerData(int px, int py, IClientAPI RemoteClient)
-        {
-            RemoteClient.SendLayerData(px, py, Terrain.getHeights1D());
-        }
-
-        #endregion
-
-        #region Add/Remove Agent/Avatar
-        /// <summary>
-        /// 
-        /// </summary>
-        /// <param name="remoteClient"></param>
-        /// <param name="agentID"></param>
-        /// <param name="child"></param>
-        public abstract void AddNewClient(IClientAPI client, bool child);
-
-        /// <summary>
-        /// 
-        /// </summary>
-        /// <param name="agentID"></param>
-        public abstract void RemoveClient(LLUUID agentID);
-       
-        #endregion
-
-        /// <summary>
-        /// 
-        /// </summary>
-        /// <returns></returns>
-        public virtual RegionInfo RegionInfo
-        {
-            get { return this.m_regInfo; }
-        }
-
-        public object SyncRoot
-        {
-            get { return m_syncRoot; }
-        }
-
-        public uint NextLocalId
-        {
-            get { return m_nextLocalId++; }
-        }
-
-        #region Shutdown
-        /// <summary>
-        /// Tidy before shutdown
-        /// </summary>
-        public virtual void Close()
-        {
-            try
-            {
-                this.localStorage.ShutDown();
-            }
-            catch (Exception e)
-            {
-                MainLog.Instance.WriteLine(LogPriority.HIGH, "World.cs: Close() - Failed with exception " + e.ToString());
-            }
-        }
-
-        #endregion
-
- 
-    }
-}
+/*
+* Copyright (c) Contributors, http://www.openmetaverse.org/
+* See CONTRIBUTORS.TXT for a full list of copyright holders.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*     * Redistributions of source code must retain the above copyright
+*       notice, this list of conditions and the following disclaimer.
+*     * Redistributions in binary form must reproduce the above copyright
+*       notice, this list of conditions and the following disclaimer in the
+*       documentation and/or other materials provided with the distribution.
+*     * Neither the name of the OpenSim Project nor the
+*       names of its contributors may be used to endorse or promote products
+*       derived from this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
+* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
+* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+* 
+*/
+using System;
+using System.Collections.Generic;
+using System.Reflection;
+using libsecondlife;
+using OpenSim.Framework.Console;
+using OpenSim.Framework.Interfaces;
+using OpenSim.Framework.Types;
+using OpenSim.Region.Caches;
+using OpenSim.Region.Terrain;
+using OpenSim.Framework;
+
+namespace OpenSim.Region.Environment.Scenes
+{
+    public abstract class SceneBase :  IWorld 
+    {
+        public Dictionary<LLUUID, EntityBase> Entities;
+        protected ulong m_regionHandle;
+        protected string m_regionName;
+        protected RegionInfo m_regInfo;
+
+        public TerrainEngine Terrain;
+
+        public string m_datastore;
+        public ILocalStorage localStorage;
+
+        protected object m_syncRoot = new object();
+        private uint m_nextLocalId = 8880000;
+        protected AssetCache assetCache;
+
+        #region Update Methods
+        /// <summary>
+        /// Normally called once every frame/tick to let the world preform anything required (like running the physics simulation)
+        /// </summary>
+        public abstract void Update();
+
+        #endregion
+
+        #region Terrain Methods
+
+        /// <summary>
+        /// Loads the World heightmap
+        /// </summary>
+        public abstract void LoadWorldMap();
+
+        /// <summary>
+        /// Loads a new storage subsystem from a named library
+        /// </summary>
+        /// <param name="dllName">Storage Library</param>
+        /// <returns>Successful or not</returns>
+        public bool LoadStorageDLL(string dllName)
+        {
+            try
+            {
+                Assembly pluginAssembly = Assembly.LoadFrom(dllName);
+                ILocalStorage store = null;
+
+                foreach (Type pluginType in pluginAssembly.GetTypes())
+                {
+                    if (pluginType.IsPublic)
+                    {
+                        if (!pluginType.IsAbstract)
+                        {
+                            Type typeInterface = pluginType.GetInterface("ILocalStorage", true);
+
+                            if (typeInterface != null)
+                            {
+                                ILocalStorage plug = (ILocalStorage)Activator.CreateInstance(pluginAssembly.GetType(pluginType.ToString()));
+                                store = plug;
+
+                                store.Initialise(this.m_datastore);
+                                break;
+                            }
+
+                            typeInterface = null;
+                        }
+                    }
+                }
+                pluginAssembly = null;
+                this.localStorage = store;
+                return (store == null);
+            }
+            catch (Exception e)
+            {
+                MainLog.Instance.Warn("World.cs: LoadStorageDLL() - Failed with exception " + e.ToString());
+                return false;
+            }
+        }
+
+        
+        /// <summary>
+        /// Send the region heightmap to the client
+        /// </summary>
+        /// <param name="RemoteClient">Client to send to</param>
+        public virtual void SendLayerData(IClientAPI RemoteClient)
+        {
+            RemoteClient.SendLayerData(Terrain.getHeights1D());
+        }
+
+        /// <summary>
+        /// Sends a specified patch to a client
+        /// </summary>
+        /// <param name="px">Patch coordinate (x) 0..16</param>
+        /// <param name="py">Patch coordinate (y) 0..16</param>
+        /// <param name="RemoteClient">The client to send to</param>
+        public virtual void SendLayerData(int px, int py, IClientAPI RemoteClient)
+        {
+            RemoteClient.SendLayerData(px, py, Terrain.getHeights1D());
+        }
+
+        #endregion
+
+        #region Add/Remove Agent/Avatar
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="remoteClient"></param>
+        /// <param name="agentID"></param>
+        /// <param name="child"></param>
+        public abstract void AddNewClient(IClientAPI client, bool child);
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="agentID"></param>
+        public abstract void RemoveClient(LLUUID agentID);
+       
+        #endregion
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <returns></returns>
+        public virtual RegionInfo RegionInfo
+        {
+            get { return this.m_regInfo; }
+        }
+
+        public object SyncRoot
+        {
+            get { return m_syncRoot; }
+        }
+
+        public uint NextLocalId
+        {
+            get { return m_nextLocalId++; }
+        }
+
+        #region Shutdown
+        /// <summary>
+        /// Tidy before shutdown
+        /// </summary>
+        public virtual void Close()
+        {
+            try
+            {
+                this.localStorage.ShutDown();
+            }
+            catch (Exception e)
+            {
+                MainLog.Instance.WriteLine(LogPriority.HIGH, "World.cs: Close() - Failed with exception " + e.ToString());
+            }
+        }
+
+        #endregion
+
+ 
+    }
+}
diff --git a/OpenSim/Region/Environment/Scenes/SceneEvents.cs b/OpenSim/Region/Environment/Scenes/SceneEvents.cs
index 1e4b163..255cbf2 100644
--- a/OpenSim/Region/Environment/Scenes/SceneEvents.cs
+++ b/OpenSim/Region/Environment/Scenes/SceneEvents.cs
@@ -1,82 +1,82 @@
-using libsecondlife;
-
-namespace OpenSim.Region.Environment.Scenes
-{
-    /// <summary>
-    /// A class for triggering remote scene events.
-    /// </summary>
-    public class EventManager
-    {
-        public delegate void OnFrameDelegate();
-        public event OnFrameDelegate OnFrame;
-
-        public delegate void OnBackupDelegate(Interfaces.IRegionDataStore datastore);
-        public event OnBackupDelegate OnBackup;
-
-        public delegate void OnNewPresenceDelegate(ScenePresence presence);
-        public event OnNewPresenceDelegate OnNewPresence;
-
-        public delegate void OnRemovePresenceDelegate(LLUUID uuid);
-        public event OnRemovePresenceDelegate OnRemovePresence;
-
-        public delegate void OnParcelPrimCountUpdateDelegate();
-        public event OnParcelPrimCountUpdateDelegate OnParcelPrimCountUpdate;
-
-        public delegate void OnParcelPrimCountAddDelegate(SceneObject obj);
-        public event OnParcelPrimCountAddDelegate OnParcelPrimCountAdd;
-
-        public delegate void OnScriptConsoleDelegate(string[] args);
-        public event OnScriptConsoleDelegate OnScriptConsole;
-
-        public void TriggerOnScriptConsole(string[] args)
-        {
-            if (OnScriptConsole != null)
-                OnScriptConsole(args);
-        }
-
-        public void TriggerOnFrame()
-        {
-            if (OnFrame != null)
-            {
-                OnFrame();
-            }
-        }
-
-        public void TriggerOnNewPresence(ScenePresence presence)
-        {
-            if (OnNewPresence != null)
-                OnNewPresence(presence);
-        }
-
-        public void TriggerOnRemovePresence(LLUUID uuid)
-        {
-            if (OnRemovePresence != null)
-            {
-                OnRemovePresence(uuid);
-            }
-        }
-
-        public void TriggerOnBackup(Interfaces.IRegionDataStore dstore)
-        {
-            if (OnBackup != null)
-            {
-                OnBackup(dstore);
-            }
-        }
-
-        public void TriggerParcelPrimCountUpdate()
-        {
-            if (OnParcelPrimCountUpdate != null)
-            {
-                OnParcelPrimCountUpdate();
-            }
-        }
-        public void TriggerParcelPrimCountAdd(SceneObject obj)
-        {
-            if (OnParcelPrimCountAdd != null)
-            {
-                OnParcelPrimCountAdd(obj);
-            }
-        }
-    }
-}
+using libsecondlife;
+
+namespace OpenSim.Region.Environment.Scenes
+{
+    /// <summary>
+    /// A class for triggering remote scene events.
+    /// </summary>
+    public class EventManager
+    {
+        public delegate void OnFrameDelegate();
+        public event OnFrameDelegate OnFrame;
+
+        public delegate void OnBackupDelegate(Interfaces.IRegionDataStore datastore);
+        public event OnBackupDelegate OnBackup;
+
+        public delegate void OnNewPresenceDelegate(ScenePresence presence);
+        public event OnNewPresenceDelegate OnNewPresence;
+
+        public delegate void OnRemovePresenceDelegate(LLUUID uuid);
+        public event OnRemovePresenceDelegate OnRemovePresence;
+
+        public delegate void OnParcelPrimCountUpdateDelegate();
+        public event OnParcelPrimCountUpdateDelegate OnParcelPrimCountUpdate;
+
+        public delegate void OnParcelPrimCountAddDelegate(SceneObject obj);
+        public event OnParcelPrimCountAddDelegate OnParcelPrimCountAdd;
+
+        public delegate void OnScriptConsoleDelegate(string[] args);
+        public event OnScriptConsoleDelegate OnScriptConsole;
+
+        public void TriggerOnScriptConsole(string[] args)
+        {
+            if (OnScriptConsole != null)
+                OnScriptConsole(args);
+        }
+
+        public void TriggerOnFrame()
+        {
+            if (OnFrame != null)
+            {
+                OnFrame();
+            }
+        }
+
+        public void TriggerOnNewPresence(ScenePresence presence)
+        {
+            if (OnNewPresence != null)
+                OnNewPresence(presence);
+        }
+
+        public void TriggerOnRemovePresence(LLUUID uuid)
+        {
+            if (OnRemovePresence != null)
+            {
+                OnRemovePresence(uuid);
+            }
+        }
+
+        public void TriggerOnBackup(Interfaces.IRegionDataStore dstore)
+        {
+            if (OnBackup != null)
+            {
+                OnBackup(dstore);
+            }
+        }
+
+        public void TriggerParcelPrimCountUpdate()
+        {
+            if (OnParcelPrimCountUpdate != null)
+            {
+                OnParcelPrimCountUpdate();
+            }
+        }
+        public void TriggerParcelPrimCountAdd(SceneObject obj)
+        {
+            if (OnParcelPrimCountAdd != null)
+            {
+                OnParcelPrimCountAdd(obj);
+            }
+        }
+    }
+}
diff --git a/OpenSim/Region/Environment/Scenes/SceneObject.cs b/OpenSim/Region/Environment/Scenes/SceneObject.cs
index e615599..43d41e6 100644
--- a/OpenSim/Region/Environment/Scenes/SceneObject.cs
+++ b/OpenSim/Region/Environment/Scenes/SceneObject.cs
@@ -1,309 +1,309 @@
-/*
-* Copyright (c) Contributors, http://www.openmetaverse.org/
-* See CONTRIBUTORS.TXT for a full list of copyright holders.
-*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted provided that the following conditions are met:
-*     * Redistributions of source code must retain the above copyright
-*       notice, this list of conditions and the following disclaimer.
-*     * Redistributions in binary form must reproduce the above copyright
-*       notice, this list of conditions and the following disclaimer in the
-*       documentation and/or other materials provided with the distribution.
-*     * Neither the name of the OpenSim Project nor the
-*       names of its contributors may be used to endorse or promote products
-*       derived from this software without specific prior written permission.
-*
-* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
-* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
-* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-* 
-*/
-using System.Collections.Generic;
-using System.Text;
-using libsecondlife;
-using libsecondlife.Packets;
-using OpenSim.Framework.Interfaces;
-using OpenSim.Framework.Types;
-using OpenSim.Physics.Manager;
-
-namespace OpenSim.Region.Environment.Scenes
-{
-    public class SceneObject : EntityBase
-    {
-        private Encoding enc = Encoding.ASCII;
-        private Dictionary<LLUUID, Primitive> ChildPrimitives = new Dictionary<LLUUID, Primitive>(); //list of all primitive id's that are part of this group
-        public Primitive rootPrimitive;
-        private new Scene m_world;
-        protected ulong m_regionHandle;
-
-        private bool physicsEnabled = false;
-        private PhysicsScene m_PhysScene;
-        private PhysicsActor m_PhysActor;
-
-        private EventManager m_eventManager;
-
-        public bool isSelected = false;
-
-        public LLUUID rootUUID
-        {
-            get
-            {
-                this.uuid = this.rootPrimitive.uuid;
-                return this.uuid;
-            }
-        }
-
-        public uint rootLocalID
-        {
-            get
-            {
-                this.m_localId = this.rootPrimitive.LocalId;
-                return this.LocalId;
-            }
-        }
-
-        public int primCount
-        {
-            get
-            {
-                return this.ChildPrimitives.Count;
-            }
-        }
-
-        public Dictionary<LLUUID, Primitive> Children
-        {
-            get
-            {
-                return this.ChildPrimitives;
-            }
-        }
-
-        /// <summary>
-        /// 
-        /// </summary>
-        public SceneObject(Scene world, EventManager eventManager, LLUUID ownerID, uint localID, LLVector3 pos, PrimitiveBaseShape shape)
-        {
-            m_regionHandle = world.RegionInfo.RegionHandle;
-            m_world = world;
-            m_eventManager = eventManager;
-
-            this.Pos = pos;
-            this.CreateRootFromShape(ownerID, localID, shape, pos);
-
-            registerEvents();
-
-        }
-
-        /// <summary>
-        /// 
-        /// </summary>
-        /// <remarks>Need a null constructor for duplication</remarks>
-        public SceneObject()
-        {
-
-        }
-
-        public void registerEvents()
-        {
-            m_eventManager.OnBackup += new EventManager.OnBackupDelegate(ProcessBackup);
-            m_eventManager.OnParcelPrimCountUpdate += new EventManager.OnParcelPrimCountUpdateDelegate(ProcessParcelPrimCountUpdate);
-        }
-
-        public void unregisterEvents()
-        {
-            m_eventManager.OnBackup -= new EventManager.OnBackupDelegate(ProcessBackup);
-            m_eventManager.OnParcelPrimCountUpdate -= new EventManager.OnParcelPrimCountUpdateDelegate(ProcessParcelPrimCountUpdate);
-        }
-
-        /// <summary>
-        /// Processes backup
-        /// </summary>
-        /// <param name="datastore"></param>
-        public void ProcessBackup(OpenSim.Region.Interfaces.IRegionDataStore datastore)
-        {
-            datastore.StoreObject(this);
-        }
-
-        /// <summary>
-        /// Sends my primitive info to the parcel manager for it to keep tally of all of the prims!
-        /// </summary>
-        private void ProcessParcelPrimCountUpdate()
-        {
-
-            m_eventManager.TriggerParcelPrimCountAdd(this);         
-        }
-
-        /// <summary>
-        /// 
-        /// </summary>
-        /// <param name="addPacket"></param>
-        /// <param name="agentID"></param>
-        /// <param name="localID"></param>
-        public void CreateRootFromShape(LLUUID agentID, uint localID, PrimitiveBaseShape shape, LLVector3 pos)
-        {
-
-            this.rootPrimitive = new Primitive(this.m_regionHandle, this.m_world, agentID, localID, true, this, this, shape, pos);
-
-            this.children.Add(rootPrimitive);
-            this.ChildPrimitives.Add(this.rootUUID, this.rootPrimitive);
-        }
-
-        /// <summary>
-        /// 
-        /// </summary>
-        /// <param name="data"></param>
-        public void CreateFromBytes(byte[] data)
-        {
-
-        }
-
-        /// <summary>
-        /// Makes a copy of this SceneObject (and child primitives)
-        /// </summary>
-        /// <returns>A complete copy of the object</returns>
-        public new SceneObject Copy()
-        {
-            SceneObject dupe = new SceneObject();
-
-            dupe.m_world = this.m_world;
-            dupe.m_eventManager = this.m_eventManager;
-            dupe.m_regionHandle = this.m_regionHandle;
-            Primitive newRoot = this.rootPrimitive.Copy(dupe, dupe);
-            dupe.rootPrimitive = newRoot;
-            dupe.children.Add(dupe.rootPrimitive);
-            dupe.rootPrimitive.Pos = this.Pos;
-            dupe.Rotation = this.Rotation;
-            dupe.LocalId = m_world.PrimIDAllocate();
-
-            dupe.registerEvents();
-            return dupe;
-        }
-
-        /// <summary>
-        /// 
-        /// </summary>
-        public void DeleteAllChildren()
-        {
-            this.children.Clear();
-            this.ChildPrimitives.Clear();
-            this.rootPrimitive = null;
-            unregisterEvents();
-        }
-
-        /// <summary>
-        /// 
-        /// </summary>
-        /// <param name="primObject"></param>
-        public void AddNewChildPrims(SceneObject primObject)
-        {
-            this.rootPrimitive.AddNewChildren(primObject);
-        }
-
-        public void AddChildToList(Primitive prim)
-        {
-            if (!this.ChildPrimitives.ContainsKey(prim.uuid))
-            {
-                this.ChildPrimitives.Add(prim.uuid, prim);
-            }
-        }
-        /// <summary>
-        /// 
-        /// </summary>
-        /// <param name="primID"></param>
-        /// <returns></returns>
-        public Primitive HasChildPrim(LLUUID primID)
-        {
-            if (this.ChildPrimitives.ContainsKey(primID))
-            {
-                return this.ChildPrimitives[primID];
-            }
-
-            return null;
-        }
-
-        /// <summary>
-        /// 
-        /// </summary>
-        /// <param name="localID"></param>
-        /// <returns></returns>
-        public Primitive HasChildPrim(uint localID)
-        {
-            Primitive returnPrim = null;
-            foreach (Primitive prim in this.ChildPrimitives.Values)
-            {
-                if (prim.LocalId == localID)
-                {
-                    returnPrim = prim;
-                    break;
-                }
-            }
-            return returnPrim;
-        }
-
-        public void SendAllChildPrimsToClient(IClientAPI client)
-        {
-            this.rootPrimitive.SendFullUpdateForAllChildren(client);
-        }
-
-        /// <summary>
-        /// 
-        /// </summary>
-        public override void BackUp()
-        {
-
-        }
-
-        /// <summary>
-        /// 
-        /// </summary>
-        /// <param name="offset"></param>
-        /// <param name="pos"></param>
-        /// <param name="remoteClient"></param>
-        public void GrapMovement(LLVector3 offset, LLVector3 pos, IClientAPI remoteClient)
-        {
-            this.rootPrimitive.Pos = pos;
-            this.rootPrimitive.SendTerseUpdateForAllChildren(remoteClient);
-        }
-
-        /// <summary>
-        /// 
-        /// </summary>
-        /// <param name="client"></param>
-        public void GetProperites(IClientAPI client)
-        {
-            ObjectPropertiesPacket proper = new ObjectPropertiesPacket();
-            proper.ObjectData = new ObjectPropertiesPacket.ObjectDataBlock[1];
-            proper.ObjectData[0] = new ObjectPropertiesPacket.ObjectDataBlock();
-            proper.ObjectData[0].ItemID = LLUUID.Zero;
-            proper.ObjectData[0].CreationDate = (ulong)this.rootPrimitive.CreationDate;
-            proper.ObjectData[0].CreatorID = this.rootPrimitive.CreatorID;
-            proper.ObjectData[0].FolderID = LLUUID.Zero;
-            proper.ObjectData[0].FromTaskID = LLUUID.Zero;
-            proper.ObjectData[0].GroupID = LLUUID.Zero;
-            proper.ObjectData[0].InventorySerial = 0;
-            proper.ObjectData[0].LastOwnerID = this.rootPrimitive.LastOwnerID;
-            proper.ObjectData[0].ObjectID = this.rootUUID;
-            proper.ObjectData[0].OwnerID = this.rootPrimitive.OwnerID;
-            proper.ObjectData[0].TouchName = enc.GetBytes(this.rootPrimitive.TouchName + "\0");
-            proper.ObjectData[0].TextureID = new byte[0];
-            proper.ObjectData[0].SitName = enc.GetBytes(this.rootPrimitive.SitName + "\0");
-            proper.ObjectData[0].Name = enc.GetBytes(this.rootPrimitive.Name + "\0");
-            proper.ObjectData[0].Description = enc.GetBytes(this.rootPrimitive.Description + "\0");
-            proper.ObjectData[0].OwnerMask = this.rootPrimitive.OwnerMask;
-            proper.ObjectData[0].NextOwnerMask = this.rootPrimitive.NextOwnerMask;
-            proper.ObjectData[0].GroupMask = this.rootPrimitive.GroupMask;
-            proper.ObjectData[0].EveryoneMask = this.rootPrimitive.EveryoneMask;
-            proper.ObjectData[0].BaseMask = this.rootPrimitive.BaseMask;
-
-            client.OutPacket(proper);
-        }
-
-    }
-}
+/*
+* Copyright (c) Contributors, http://www.openmetaverse.org/
+* See CONTRIBUTORS.TXT for a full list of copyright holders.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*     * Redistributions of source code must retain the above copyright
+*       notice, this list of conditions and the following disclaimer.
+*     * Redistributions in binary form must reproduce the above copyright
+*       notice, this list of conditions and the following disclaimer in the
+*       documentation and/or other materials provided with the distribution.
+*     * Neither the name of the OpenSim Project nor the
+*       names of its contributors may be used to endorse or promote products
+*       derived from this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
+* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
+* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+* 
+*/
+using System.Collections.Generic;
+using System.Text;
+using libsecondlife;
+using libsecondlife.Packets;
+using OpenSim.Framework.Interfaces;
+using OpenSim.Framework.Types;
+using OpenSim.Physics.Manager;
+
+namespace OpenSim.Region.Environment.Scenes
+{
+    public class SceneObject : EntityBase
+    {
+        private Encoding enc = Encoding.ASCII;
+        private Dictionary<LLUUID, Primitive> ChildPrimitives = new Dictionary<LLUUID, Primitive>(); //list of all primitive id's that are part of this group
+        public Primitive rootPrimitive;
+        private new Scene m_world;
+        protected ulong m_regionHandle;
+
+        private bool physicsEnabled = false;
+        private PhysicsScene m_PhysScene;
+        private PhysicsActor m_PhysActor;
+
+        private EventManager m_eventManager;
+
+        public bool isSelected = false;
+
+        public LLUUID rootUUID
+        {
+            get
+            {
+                this.uuid = this.rootPrimitive.uuid;
+                return this.uuid;
+            }
+        }
+
+        public uint rootLocalID
+        {
+            get
+            {
+                this.m_localId = this.rootPrimitive.LocalId;
+                return this.LocalId;
+            }
+        }
+
+        public int primCount
+        {
+            get
+            {
+                return this.ChildPrimitives.Count;
+            }
+        }
+
+        public Dictionary<LLUUID, Primitive> Children
+        {
+            get
+            {
+                return this.ChildPrimitives;
+            }
+        }
+
+        /// <summary>
+        /// 
+        /// </summary>
+        public SceneObject(Scene world, EventManager eventManager, LLUUID ownerID, uint localID, LLVector3 pos, PrimitiveBaseShape shape)
+        {
+            m_regionHandle = world.RegionInfo.RegionHandle;
+            m_world = world;
+            m_eventManager = eventManager;
+
+            this.Pos = pos;
+            this.CreateRootFromShape(ownerID, localID, shape, pos);
+
+            registerEvents();
+
+        }
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <remarks>Need a null constructor for duplication</remarks>
+        public SceneObject()
+        {
+
+        }
+
+        public void registerEvents()
+        {
+            m_eventManager.OnBackup += new EventManager.OnBackupDelegate(ProcessBackup);
+            m_eventManager.OnParcelPrimCountUpdate += new EventManager.OnParcelPrimCountUpdateDelegate(ProcessParcelPrimCountUpdate);
+        }
+
+        public void unregisterEvents()
+        {
+            m_eventManager.OnBackup -= new EventManager.OnBackupDelegate(ProcessBackup);
+            m_eventManager.OnParcelPrimCountUpdate -= new EventManager.OnParcelPrimCountUpdateDelegate(ProcessParcelPrimCountUpdate);
+        }
+
+        /// <summary>
+        /// Processes backup
+        /// </summary>
+        /// <param name="datastore"></param>
+        public void ProcessBackup(OpenSim.Region.Interfaces.IRegionDataStore datastore)
+        {
+            datastore.StoreObject(this);
+        }
+
+        /// <summary>
+        /// Sends my primitive info to the parcel manager for it to keep tally of all of the prims!
+        /// </summary>
+        private void ProcessParcelPrimCountUpdate()
+        {
+
+            m_eventManager.TriggerParcelPrimCountAdd(this);         
+        }
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="addPacket"></param>
+        /// <param name="agentID"></param>
+        /// <param name="localID"></param>
+        public void CreateRootFromShape(LLUUID agentID, uint localID, PrimitiveBaseShape shape, LLVector3 pos)
+        {
+
+            this.rootPrimitive = new Primitive(this.m_regionHandle, this.m_world, agentID, localID, true, this, this, shape, pos);
+
+            this.children.Add(rootPrimitive);
+            this.ChildPrimitives.Add(this.rootUUID, this.rootPrimitive);
+        }
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="data"></param>
+        public void CreateFromBytes(byte[] data)
+        {
+
+        }
+
+        /// <summary>
+        /// Makes a copy of this SceneObject (and child primitives)
+        /// </summary>
+        /// <returns>A complete copy of the object</returns>
+        public new SceneObject Copy()
+        {
+            SceneObject dupe = new SceneObject();
+
+            dupe.m_world = this.m_world;
+            dupe.m_eventManager = this.m_eventManager;
+            dupe.m_regionHandle = this.m_regionHandle;
+            Primitive newRoot = this.rootPrimitive.Copy(dupe, dupe);
+            dupe.rootPrimitive = newRoot;
+            dupe.children.Add(dupe.rootPrimitive);
+            dupe.rootPrimitive.Pos = this.Pos;
+            dupe.Rotation = this.Rotation;
+            dupe.LocalId = m_world.PrimIDAllocate();
+
+            dupe.registerEvents();
+            return dupe;
+        }
+
+        /// <summary>
+        /// 
+        /// </summary>
+        public void DeleteAllChildren()
+        {
+            this.children.Clear();
+            this.ChildPrimitives.Clear();
+            this.rootPrimitive = null;
+            unregisterEvents();
+        }
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="primObject"></param>
+        public void AddNewChildPrims(SceneObject primObject)
+        {
+            this.rootPrimitive.AddNewChildren(primObject);
+        }
+
+        public void AddChildToList(Primitive prim)
+        {
+            if (!this.ChildPrimitives.ContainsKey(prim.uuid))
+            {
+                this.ChildPrimitives.Add(prim.uuid, prim);
+            }
+        }
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="primID"></param>
+        /// <returns></returns>
+        public Primitive HasChildPrim(LLUUID primID)
+        {
+            if (this.ChildPrimitives.ContainsKey(primID))
+            {
+                return this.ChildPrimitives[primID];
+            }
+
+            return null;
+        }
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="localID"></param>
+        /// <returns></returns>
+        public Primitive HasChildPrim(uint localID)
+        {
+            Primitive returnPrim = null;
+            foreach (Primitive prim in this.ChildPrimitives.Values)
+            {
+                if (prim.LocalId == localID)
+                {
+                    returnPrim = prim;
+                    break;
+                }
+            }
+            return returnPrim;
+        }
+
+        public void SendAllChildPrimsToClient(IClientAPI client)
+        {
+            this.rootPrimitive.SendFullUpdateForAllChildren(client);
+        }
+
+        /// <summary>
+        /// 
+        /// </summary>
+        public override void BackUp()
+        {
+
+        }
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="offset"></param>
+        /// <param name="pos"></param>
+        /// <param name="remoteClient"></param>
+        public void GrapMovement(LLVector3 offset, LLVector3 pos, IClientAPI remoteClient)
+        {
+            this.rootPrimitive.Pos = pos;
+            this.rootPrimitive.SendTerseUpdateForAllChildren(remoteClient);
+        }
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="client"></param>
+        public void GetProperites(IClientAPI client)
+        {
+            ObjectPropertiesPacket proper = new ObjectPropertiesPacket();
+            proper.ObjectData = new ObjectPropertiesPacket.ObjectDataBlock[1];
+            proper.ObjectData[0] = new ObjectPropertiesPacket.ObjectDataBlock();
+            proper.ObjectData[0].ItemID = LLUUID.Zero;
+            proper.ObjectData[0].CreationDate = (ulong)this.rootPrimitive.CreationDate;
+            proper.ObjectData[0].CreatorID = this.rootPrimitive.CreatorID;
+            proper.ObjectData[0].FolderID = LLUUID.Zero;
+            proper.ObjectData[0].FromTaskID = LLUUID.Zero;
+            proper.ObjectData[0].GroupID = LLUUID.Zero;
+            proper.ObjectData[0].InventorySerial = 0;
+            proper.ObjectData[0].LastOwnerID = this.rootPrimitive.LastOwnerID;
+            proper.ObjectData[0].ObjectID = this.rootUUID;
+            proper.ObjectData[0].OwnerID = this.rootPrimitive.OwnerID;
+            proper.ObjectData[0].TouchName = enc.GetBytes(this.rootPrimitive.TouchName + "\0");
+            proper.ObjectData[0].TextureID = new byte[0];
+            proper.ObjectData[0].SitName = enc.GetBytes(this.rootPrimitive.SitName + "\0");
+            proper.ObjectData[0].Name = enc.GetBytes(this.rootPrimitive.Name + "\0");
+            proper.ObjectData[0].Description = enc.GetBytes(this.rootPrimitive.Description + "\0");
+            proper.ObjectData[0].OwnerMask = this.rootPrimitive.OwnerMask;
+            proper.ObjectData[0].NextOwnerMask = this.rootPrimitive.NextOwnerMask;
+            proper.ObjectData[0].GroupMask = this.rootPrimitive.GroupMask;
+            proper.ObjectData[0].EveryoneMask = this.rootPrimitive.EveryoneMask;
+            proper.ObjectData[0].BaseMask = this.rootPrimitive.BaseMask;
+
+            client.OutPacket(proper);
+        }
+
+    }
+}
diff --git a/OpenSim/Region/Environment/Scenes/ScenePresence.Animations.cs b/OpenSim/Region/Environment/Scenes/ScenePresence.Animations.cs
index d1f75ed..e88ee71 100644
--- a/OpenSim/Region/Environment/Scenes/ScenePresence.Animations.cs
+++ b/OpenSim/Region/Environment/Scenes/ScenePresence.Animations.cs
@@ -1,74 +1,74 @@
-/*
-* Copyright (c) Contributors, http://www.openmetaverse.org/
-* See CONTRIBUTORS.TXT for a full list of copyright holders.
-*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted provided that the following conditions are met:
-*     * Redistributions of source code must retain the above copyright
-*       notice, this list of conditions and the following disclaimer.
-*     * Redistributions in binary form must reproduce the above copyright
-*       notice, this list of conditions and the following disclaimer in the
-*       documentation and/or other materials provided with the distribution.
-*     * Neither the name of the OpenSim Project nor the
-*       names of its contributors may be used to endorse or promote products
-*       derived from this software without specific prior written permission.
-*
-* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
-* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
-* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-* 
-*/
-using System.Collections.Generic;
-using System.Xml;
-using libsecondlife;
-
-namespace OpenSim.Region.Environment.Scenes
-{
-    partial class ScenePresence
-    {
-        public class AvatarAnimations
-        {
-
-            public Dictionary<string, LLUUID> AnimsLLUUID = new Dictionary<string, LLUUID>();
-            public Dictionary<LLUUID, string> AnimsNames = new Dictionary<LLUUID, string>();
-
-            public AvatarAnimations()
-            {
-            }
-
-            public void LoadAnims()
-            {
-                //OpenSim.Framework.Console.MainLog.Instance.Verbose("Avatar.cs:LoadAnims() - Loading avatar animations");
-                XmlTextReader reader = new XmlTextReader("data/avataranimations.xml");
-
-                XmlDocument doc = new XmlDocument();
-                doc.Load(reader);
-                foreach (XmlNode nod in doc.DocumentElement.ChildNodes)
-                {
-
-                    if (nod.Attributes["name"] != null)
-                    {
-                        AnimsLLUUID.Add(nod.Attributes["name"].Value, nod.InnerText);
-                    }
-
-                }
-
-                reader.Close();
-
-                // OpenSim.Framework.Console.MainLog.Instance.Verbose("Loaded " + AnimsLLUUID.Count.ToString() + " animation(s)");
-
-                foreach (KeyValuePair<string, LLUUID> kp in Animations.AnimsLLUUID)
-                {
-                    AnimsNames.Add(kp.Value, kp.Key);
-                }
-            }
-        }
-    }
-}
+/*
+* Copyright (c) Contributors, http://www.openmetaverse.org/
+* See CONTRIBUTORS.TXT for a full list of copyright holders.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*     * Redistributions of source code must retain the above copyright
+*       notice, this list of conditions and the following disclaimer.
+*     * Redistributions in binary form must reproduce the above copyright
+*       notice, this list of conditions and the following disclaimer in the
+*       documentation and/or other materials provided with the distribution.
+*     * Neither the name of the OpenSim Project nor the
+*       names of its contributors may be used to endorse or promote products
+*       derived from this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
+* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
+* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+* 
+*/
+using System.Collections.Generic;
+using System.Xml;
+using libsecondlife;
+
+namespace OpenSim.Region.Environment.Scenes
+{
+    partial class ScenePresence
+    {
+        public class AvatarAnimations
+        {
+
+            public Dictionary<string, LLUUID> AnimsLLUUID = new Dictionary<string, LLUUID>();
+            public Dictionary<LLUUID, string> AnimsNames = new Dictionary<LLUUID, string>();
+
+            public AvatarAnimations()
+            {
+            }
+
+            public void LoadAnims()
+            {
+                //OpenSim.Framework.Console.MainLog.Instance.Verbose("Avatar.cs:LoadAnims() - Loading avatar animations");
+                XmlTextReader reader = new XmlTextReader("data/avataranimations.xml");
+
+                XmlDocument doc = new XmlDocument();
+                doc.Load(reader);
+                foreach (XmlNode nod in doc.DocumentElement.ChildNodes)
+                {
+
+                    if (nod.Attributes["name"] != null)
+                    {
+                        AnimsLLUUID.Add(nod.Attributes["name"].Value, nod.InnerText);
+                    }
+
+                }
+
+                reader.Close();
+
+                // OpenSim.Framework.Console.MainLog.Instance.Verbose("Loaded " + AnimsLLUUID.Count.ToString() + " animation(s)");
+
+                foreach (KeyValuePair<string, LLUUID> kp in Animations.AnimsLLUUID)
+                {
+                    AnimsNames.Add(kp.Value, kp.Key);
+                }
+            }
+        }
+    }
+}
diff --git a/OpenSim/Region/Environment/Scenes/ScenePresence.Body.cs b/OpenSim/Region/Environment/Scenes/ScenePresence.Body.cs
index dbb5d3f..c2599a1 100644
--- a/OpenSim/Region/Environment/Scenes/ScenePresence.Body.cs
+++ b/OpenSim/Region/Environment/Scenes/ScenePresence.Body.cs
@@ -1,85 +1,85 @@
-/*
-* Copyright (c) Contributors, http://www.openmetaverse.org/
-* See CONTRIBUTORS.TXT for a full list of copyright holders.
-*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted provided that the following conditions are met:
-*     * Redistributions of source code must retain the above copyright
-*       notice, this list of conditions and the following disclaimer.
-*     * Redistributions in binary form must reproduce the above copyright
-*       notice, this list of conditions and the following disclaimer in the
-*       documentation and/or other materials provided with the distribution.
-*     * Neither the name of the OpenSim Project nor the
-*       names of its contributors may be used to endorse or promote products
-*       derived from this software without specific prior written permission.
-*
-* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
-* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
-* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-* 
-*/
-using libsecondlife;
-using libsecondlife.Packets;
-using OpenSim.Framework.Interfaces;
-
-namespace OpenSim.Region.Environment.Scenes
-{
-    partial class ScenePresence
-    {
-        public class Avatar : IScenePresenceBody
-        {
-            public Avatar()
-            {
-
-            }
-
-            public void processMovement(IClientAPI remoteClient, uint flags, LLQuaternion bodyRotation)
-            {
-            }
-
-            public void SetAppearance(byte[] texture, AgentSetAppearancePacket.VisualParamBlock[] visualParam)
-            {
-            }
-
-            public void SendOurAppearance(IClientAPI OurClient)
-            {
-            }
-
-            public void SendAppearanceToOtherAgent(ScenePresence avatarInfo)
-            {
-            }
-        }
-
-        public class ChildAgent : IScenePresenceBody //is a ghost
-        {
-            public ChildAgent()
-            {
-
-            }
-
-            public void processMovement(IClientAPI remoteClient, uint flags, LLQuaternion bodyRotation)
-            {
-            }
-
-            public void SetAppearance(byte[] texture, AgentSetAppearancePacket.VisualParamBlock[] visualParam)
-            {
-            }
-
-            public void SendOurAppearance(IClientAPI OurClient)
-            {
-            }
-
-            public void SendAppearanceToOtherAgent(ScenePresence avatarInfo)
-            {
-            }
-        }
-    }
-
-}
+/*
+* Copyright (c) Contributors, http://www.openmetaverse.org/
+* See CONTRIBUTORS.TXT for a full list of copyright holders.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*     * Redistributions of source code must retain the above copyright
+*       notice, this list of conditions and the following disclaimer.
+*     * Redistributions in binary form must reproduce the above copyright
+*       notice, this list of conditions and the following disclaimer in the
+*       documentation and/or other materials provided with the distribution.
+*     * Neither the name of the OpenSim Project nor the
+*       names of its contributors may be used to endorse or promote products
+*       derived from this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
+* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
+* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+* 
+*/
+using libsecondlife;
+using libsecondlife.Packets;
+using OpenSim.Framework.Interfaces;
+
+namespace OpenSim.Region.Environment.Scenes
+{
+    partial class ScenePresence
+    {
+        public class Avatar : IScenePresenceBody
+        {
+            public Avatar()
+            {
+
+            }
+
+            public void processMovement(IClientAPI remoteClient, uint flags, LLQuaternion bodyRotation)
+            {
+            }
+
+            public void SetAppearance(byte[] texture, AgentSetAppearancePacket.VisualParamBlock[] visualParam)
+            {
+            }
+
+            public void SendOurAppearance(IClientAPI OurClient)
+            {
+            }
+
+            public void SendAppearanceToOtherAgent(ScenePresence avatarInfo)
+            {
+            }
+        }
+
+        public class ChildAgent : IScenePresenceBody //is a ghost
+        {
+            public ChildAgent()
+            {
+
+            }
+
+            public void processMovement(IClientAPI remoteClient, uint flags, LLQuaternion bodyRotation)
+            {
+            }
+
+            public void SetAppearance(byte[] texture, AgentSetAppearancePacket.VisualParamBlock[] visualParam)
+            {
+            }
+
+            public void SendOurAppearance(IClientAPI OurClient)
+            {
+            }
+
+            public void SendAppearanceToOtherAgent(ScenePresence avatarInfo)
+            {
+            }
+        }
+    }
+
+}
diff --git a/OpenSim/Region/Environment/Scenes/ScenePresence.cs b/OpenSim/Region/Environment/Scenes/ScenePresence.cs
index b619b59..ae49d9f 100644
--- a/OpenSim/Region/Environment/Scenes/ScenePresence.cs
+++ b/OpenSim/Region/Environment/Scenes/ScenePresence.cs
@@ -1,623 +1,623 @@
-/*
-* Copyright (c) Contributors, http://www.openmetaverse.org/
-* See CONTRIBUTORS.TXT for a full list of copyright holders.
-*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted provided that the following conditions are met:
-*     * Redistributions of source code must retain the above copyright
-*       notice, this list of conditions and the following disclaimer.
-*     * Redistributions in binary form must reproduce the above copyright
-*       notice, this list of conditions and the following disclaimer in the
-*       documentation and/or other materials provided with the distribution.
-*     * Neither the name of the OpenSim Project nor the
-*       names of its contributors may be used to endorse or promote products
-*       derived from this software without specific prior written permission.
-*
-* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
-* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
-* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-* 
-*/
-using System;
-using System.Collections.Generic;
-using System.IO;
-using Axiom.Math;
-using libsecondlife;
-using libsecondlife.Packets;
-using OpenSim.Framework.Console;
-using OpenSim.Framework.Interfaces;
-using OpenSim.Framework.Types;
-using OpenSim.Physics.Manager;
-
-namespace OpenSim.Region.Environment.Scenes
-{
-    public partial class ScenePresence : Entity
-    {
-        public static bool PhysicsEngineFlying = false;
-        public static AvatarAnimations Animations;
-        public static byte[] DefaultTexture;
-        public string firstname;
-        public string lastname;
-        public IClientAPI ControllingClient;
-        public LLUUID current_anim;
-        public int anim_seq;
-        private bool updateflag = false;
-        private byte movementflag = 0;
-        private List<NewForce> forcesList = new List<NewForce>();
-        private short _updateCount = 0;
-        private Quaternion bodyRot;
-        private LLObject.TextureEntry avatarAppearanceTexture = null;
-        private byte[] visualParams;
-        private AvatarWearable[] Wearables;
-        private ulong m_regionHandle;
-
-        public bool childAgent = false;
-        public bool IsRestrictedToRegion = false;
-
-        private bool newForce = false;
-        private bool newAvatar = false;
-        private IScenePresenceBody m_body;
-
-        protected RegionInfo m_regionInfo;
-
-        private Vector3[] Dir_Vectors = new Vector3[6];
-        private enum Dir_ControlFlags
-        {
-            DIR_CONTROL_FLAG_FOWARD = MainAvatar.ControlFlags.AGENT_CONTROL_AT_POS,
-            DIR_CONTROL_FLAG_BACK = MainAvatar.ControlFlags.AGENT_CONTROL_AT_NEG,
-            DIR_CONTROL_FLAG_LEFT = MainAvatar.ControlFlags.AGENT_CONTROL_LEFT_POS,
-            DIR_CONTROL_FLAG_RIGHT = MainAvatar.ControlFlags.AGENT_CONTROL_LEFT_NEG,
-            DIR_CONTROL_FLAG_UP = MainAvatar.ControlFlags.AGENT_CONTROL_UP_POS,
-            DIR_CONTROL_FLAG_DOWN = MainAvatar.ControlFlags.AGENT_CONTROL_UP_NEG
-        }
-        /// <summary>
-        /// Position at which a significant movement was made
-        /// </summary>
-        private LLVector3 posLastSignificantMove = new LLVector3();
-
-        public delegate void SignificantClientMovement(IClientAPI remote_client);
-        public event SignificantClientMovement OnSignificantClientMovement;
-
-        #region Properties
-        /// <summary>
-        /// 
-        /// </summary>
-        public PhysicsActor PhysActor
-        {
-            set
-            {
-                this._physActor = value;
-            }
-            get
-            {
-                return _physActor;
-            }
-        }
-
-	public ulong RegionHandle
-	{
-	    get { return m_regionHandle; }
-	}
-
-        #endregion
-
-        #region Constructor(s)
-        /// <summary>
-        /// 
-        /// </summary>
-        /// <param name="theClient"></param>
-        /// <param name="world"></param>
-        /// <param name="clientThreads"></param>
-        /// <param name="regionDat"></param>
-        public ScenePresence(IClientAPI theClient, Scene world, RegionInfo reginfo)
-        {
-
-            m_world = world;
-            this.uuid = theClient.AgentId;
-
-            m_regionInfo = reginfo;
-            m_regionHandle = reginfo.RegionHandle;
-            MainLog.Instance.Verbose("Avatar.cs ");
-            ControllingClient = theClient;
-            this.firstname = ControllingClient.FirstName;
-            this.lastname = ControllingClient.LastName;
-            m_localId = m_world.NextLocalId;
-            Pos = ControllingClient.StartPos;
-            visualParams = new byte[218];
-            for (int i = 0; i < 218; i++)
-            {
-                visualParams[i] = 100;
-            }
-
-            Wearables = AvatarWearable.DefaultWearables;
-            Animations = new ScenePresence.AvatarAnimations();
-            Animations.LoadAnims();
-
-            this.avatarAppearanceTexture = new LLObject.TextureEntry(new LLUUID("00000000-0000-0000-5005-000000000005"));
-
-            //register for events
-            ControllingClient.OnRequestWearables += this.SendOurAppearance;
-            //ControllingClient.OnSetAppearance += new SetAppearance(this.SetAppearance);
-            ControllingClient.OnCompleteMovementToRegion += this.CompleteMovement;
-            ControllingClient.OnCompleteMovementToRegion += this.SendInitialData;
-            ControllingClient.OnAgentUpdate += this.HandleAgentUpdate;
-            // ControllingClient.OnStartAnim += new StartAnim(this.SendAnimPack);
-            // ControllingClient.OnChildAgentStatus += new StatusChange(this.ChildStatusChange);
-            //ControllingClient.OnStopMovement += new GenericCall2(this.StopMovement);
-            
-            Dir_Vectors[0] = new Vector3(1, 0, 0);  //FOWARD
-            Dir_Vectors[1] = new Vector3(-1, 0, 0); //BACK
-            Dir_Vectors[2] = new Vector3(0, 1, 0);  //LEFT
-            Dir_Vectors[3] = new Vector3(0, -1, 0); //RIGHT
-            Dir_Vectors[4] = new Vector3(0, 0, 1);  //UP
-            Dir_Vectors[5] = new Vector3(0, 0, -1); //DOWN
-
-        }
-        #endregion
-
-        #region Status Methods
-        /// <summary>
-        /// Not Used, most likely can be deleted
-        /// </summary>
-        /// <param name="status"></param>
-        public void ChildStatusChange(bool status)
-        {
-            this.childAgent = status;
-
-            if (this.childAgent == true)
-            {
-                this.Velocity = new LLVector3(0, 0, 0);
-                this.Pos = new LLVector3(128, 128, 70);
-
-            }
-        }
-
-        /// <summary>
-        /// 
-        /// </summary>
-        /// <param name="pos"></param>
-        public void MakeAvatar(LLVector3 pos)
-        {
-            //this.childAvatar = false;
-            this.Pos = pos;
-            this.newAvatar = true;
-            this.childAgent = false;
-        }
-
-        protected void MakeChildAgent()
-        {
-            this.Velocity = new LLVector3(0, 0, 0);
-            this.Pos = new LLVector3(128, 128, 70);
-            this.childAgent = true;
-        }
-
-        /// <summary>
-        /// 
-        /// </summary>
-        /// <param name="pos"></param>
-        public void Teleport(LLVector3 pos)
-        {
-            this.Pos = pos;
-            this.SendTerseUpdateToALLClients();
-        }
-
-        /// <summary>
-        /// 
-        /// </summary>
-        public void StopMovement()
-        {
-
-        }
-        #endregion
-
-        #region Event Handlers
-        /// <summary>
-        /// 
-        /// </summary>
-        /// <param name="texture"></param>
-        /// <param name="visualParam"></param>
-        public void SetAppearance(byte[] texture, AgentSetAppearancePacket.VisualParamBlock[] visualParam)
-        {
-
-        }
-
-        /// <summary>
-        /// Complete Avatar's movement into the region
-        /// </summary>
-        public void CompleteMovement()
-        {
-            LLVector3 look = this.Velocity;
-            if ((look.X == 0) && (look.Y == 0) && (look.Z == 0))
-            {
-                look = new LLVector3(0.99f, 0.042f, 0);
-            }
-            this.ControllingClient.MoveAgentIntoRegion(m_regionInfo, Pos, look);
-            if (this.childAgent)
-            {
-                this.childAgent = false;
-            }
-        }
-
-        /// <summary>
-        /// 
-        /// </summary>
-        /// <param name="pack"></param>
-        public void HandleAgentUpdate(IClientAPI remoteClient, uint flags, LLQuaternion bodyRotation)
-        {
-            int i = 0;
-            bool update_movementflag = false;
-            bool update_rotation = false;
-            bool DCFlagKeyPressed = false;
-            Vector3 agent_control_v3 = new Vector3(0, 0, 0);
-            Quaternion q = new Quaternion(bodyRotation.W, bodyRotation.X, bodyRotation.Y, bodyRotation.Z);
-
-            this.PhysActor.Flying = ((flags & (uint)MainAvatar.ControlFlags.AGENT_CONTROL_FLY) != 0);
-
-            if (q != this.bodyRot)
-            {
-                this.bodyRot = q;
-                update_rotation = true;
-            }
-            foreach (Dir_ControlFlags DCF in Enum.GetValues(typeof(Dir_ControlFlags)))
-            {
-                if ((flags & (uint)DCF) != 0)
-                {
-                    DCFlagKeyPressed = true;
-                    agent_control_v3 += Dir_Vectors[i];
-                    if ((movementflag & (uint)DCF) == 0)
-                    {
-                        movementflag += (byte)(uint)DCF;
-                        update_movementflag = true;
-                    }
-                }
-                else
-                {
-                    if ((movementflag & (uint)DCF) != 0)
-                    {
-                        movementflag -= (byte)(uint)DCF;
-                        update_movementflag = true;
-                      
-                    }
-                }
-                i++;
-            }
-            if ((update_movementflag) || (update_rotation && DCFlagKeyPressed))
-            {
-                this.AddNewMovement(agent_control_v3, q);
-            }
-            UpdateMovementAnimations(update_movementflag);
-        }
-
-        protected void UpdateMovementAnimations(bool update_movementflag)
-        {
-            if (update_movementflag)
-            {
-                if (movementflag != 0)
-                {
-                    if (this._physActor.Flying)
-                    {
-                        this.SendAnimPack(Animations.AnimsLLUUID["FLY"], 1);
-                    }
-                    else
-                    {
-                        this.SendAnimPack(Animations.AnimsLLUUID["WALK"], 1);
-                    }
-                }
-                else
-                {
-                    this.SendAnimPack(Animations.AnimsLLUUID["STAND"], 1);
-                }
-            }
-
-        }
-
-
-        protected void AddNewMovement(Vector3 vec, Quaternion rotation)
-        {
-            NewForce newVelocity = new NewForce();
-            Vector3 direc = rotation * vec;
-            direc.Normalize();
-
-            direc = direc * ((0.03f) * 128f);
-            if (this._physActor.Flying)
-                direc *= 4;
-
-            newVelocity.X = direc.x;
-            newVelocity.Y = direc.y;
-            newVelocity.Z = direc.z;
-            this.forcesList.Add(newVelocity);
-        }
-
-        #endregion
-
-        #region Overridden Methods
-        /// <summary>
-        /// 
-        /// </summary>
-        public override void LandRenegerated()
-        {
-
-        }
-
-        /// <summary>
-        /// 
-        /// </summary>
-        public override void update()
-        {
-            if (this.childAgent == false)
-            {
-                if (this.newForce)
-                {
-                    this.SendTerseUpdateToALLClients();
-                    _updateCount = 0;
-                }
-                else if (movementflag != 0)
-                {
-                    _updateCount++;
-                    if (_updateCount > 3)
-                    {
-                        this.SendTerseUpdateToALLClients();
-                        _updateCount = 0;
-                    }
-                }
-
-                this.CheckForSignificantMovement();
-                this.CheckForBorderCrossing();
-                
-            }
-        }
-        #endregion
-
-        #region Update Client(s)
-        /// <summary>
-        /// 
-        /// </summary>
-        /// <param name="RemoteClient"></param>
-        public void SendTerseUpdateToClient(IClientAPI RemoteClient)
-        {
-            LLVector3 pos = this.Pos;
-            LLVector3 vel = this.Velocity;
-            RemoteClient.SendAvatarTerseUpdate(this.m_regionHandle, 64096, this.LocalId, new LLVector3(pos.X, pos.Y, pos.Z), new LLVector3(vel.X, vel.Y, vel.Z));
-        }
-
-        /// <summary>
-        /// 
-        /// </summary>
-        public void SendTerseUpdateToALLClients()
-        {
-            List<ScenePresence> avatars = this.m_world.RequestAvatarList();
-            for (int i = 0; i < avatars.Count; i++)
-            {
-                this.SendTerseUpdateToClient(avatars[i].ControllingClient);
-            }
-        }
-
-        /// <summary>
-        /// 
-        /// </summary>
-        /// <param name="remoteAvatar"></param>
-        public void SendFullUpdateToOtherClient(ScenePresence remoteAvatar)
-        {
-            remoteAvatar.ControllingClient.SendAvatarData(m_regionInfo.RegionHandle, this.firstname, this.lastname, this.uuid, this.LocalId, this.Pos, DefaultTexture);
-        }
-
-        public void SendFullUpdateToALLClients()
-        {
-            List<ScenePresence> avatars = this.m_world.RequestAvatarList();
-            foreach (ScenePresence avatar in this.m_world.RequestAvatarList())
-            {
-                this.SendFullUpdateToOtherClient(avatar);
-                avatar.SendFullUpdateToOtherClient(this);
-            }
-        }
-
-        /// <summary>
-        /// 
-        /// </summary>
-        public void SendInitialData()
-        {
-            this.ControllingClient.SendAvatarData(m_regionInfo.RegionHandle, this.firstname, this.lastname, this.uuid, this.LocalId, this.Pos, DefaultTexture);
-            if (this.newAvatar)
-            {
-                this.m_world.InformClientOfNeighbours(this.ControllingClient);
-                this.newAvatar = false;
-            }
-        }
-
-        /// <summary>
-        /// 
-        /// </summary>
-        /// <param name="OurClient"></param>
-        public void SendOurAppearance(IClientAPI OurClient)
-        {
-            this.ControllingClient.SendWearables(this.Wearables);
-            this.SendFullUpdateToALLClients();
-            this.m_world.SendAllSceneObjectsToClient(this.ControllingClient);
-        }
-
-        /// <summary>
-        /// 
-        /// </summary>
-        /// <param name="avatarInfo"></param>
-        public void SendAppearanceToOtherAgent(ScenePresence avatarInfo)
-        {
-
-        }
-
-        /// <summary>
-        /// 
-        /// </summary>
-        /// <param name="animID"></param>
-        /// <param name="seq"></param>
-        public void SendAnimPack(LLUUID animID, int seq)
-        {
-	    this.current_anim = animID;
-	    this.anim_seq = seq;
-	    List<ScenePresence> avatars = this.m_world.RequestAvatarList();
-	    for (int i = 0; i < avatars.Count; i++)
-	    {
-	    	avatars[i].ControllingClient.SendAnimation(animID, seq, this.ControllingClient.AgentId);
-	    }
-        }
-
-        /// <summary>
-        /// 
-        /// </summary>
-        public void SendAnimPack()
-        {
-            this.SendAnimPack(this.current_anim, this.anim_seq);
-        }
-        #endregion
-
-        #region Significant Movement Method
-
-        protected void CheckForSignificantMovement()
-        {
-            if (libsecondlife.Helpers.VecDist(this.Pos, this.posLastSignificantMove) > 2.0)
-            {
-                this.posLastSignificantMove = this.Pos;
-                if (OnSignificantClientMovement != null)
-                {
-                    OnSignificantClientMovement(this.ControllingClient);
-                }
-            }
-        }
-        #endregion
-        #region Border Crossing Methods
-        /// <summary>
-        /// 
-        /// </summary>
-        protected void CheckForBorderCrossing()
-        {
-            LLVector3 pos2 = this.Pos;
-            LLVector3 vel = this.Velocity;
-
-            float timeStep = 0.2f;
-            pos2.X = pos2.X + (vel.X * timeStep);
-            pos2.Y = pos2.Y + (vel.Y * timeStep);
-            pos2.Z = pos2.Z + (vel.Z * timeStep);
-
-            if ((pos2.X < 0) || (pos2.X > 256))
-            {
-                this.CrossToNewRegion();
-            }
-
-            if ((pos2.Y < 0) || (pos2.Y > 256))
-            {
-                this.CrossToNewRegion();
-            }
-        }
-
-        /// <summary>
-        /// 
-        /// </summary>
-        protected void CrossToNewRegion()
-        {
-            LLVector3 pos = this.Pos;
-            LLVector3 newpos = new LLVector3(pos.X, pos.Y, pos.Z);
-            uint neighbourx = this.m_regionInfo.RegionLocX;
-            uint neighboury = this.m_regionInfo.RegionLocY;
-
-            if (pos.X < 2)
-            {
-                neighbourx -= 1;
-                newpos.X = 254;
-            }
-            if (pos.X > 253)
-            {
-                neighbourx += 1;
-                newpos.X = 1;
-            }
-            if (pos.Y < 2)
-            {
-                neighboury -= 1;
-                newpos.Y = 254;
-            }
-            if (pos.Y > 253)
-            {
-                neighboury += 1;
-                newpos.Y = 1;
-            }
-
-            LLVector3 vel = this.m_velocity;
-            ulong neighbourHandle = Helpers.UIntsToLong((uint)(neighbourx * 256), (uint)(neighboury * 256));
-            RegionInfo neighbourRegion = this.m_world.RequestNeighbouringRegionInfo(neighbourHandle);
-            if (neighbourRegion != null)
-            {
-                bool res = this.m_world.InformNeighbourOfCrossing(neighbourHandle, this.ControllingClient.AgentId, newpos);
-                if (res)
-                {
-                    this.MakeChildAgent();
-                    this.ControllingClient.CrossRegion(neighbourHandle, newpos, vel, neighbourRegion.InternalEndPoint);
-                }
-            }
-        }
-        #endregion
-
-        /// <summary>
-        /// 
-        /// </summary>
-        public static void LoadAnims()
-        {
-
-        }
-
-        /// <summary>
-        /// 
-        /// </summary>
-        public override void updateMovement()
-        {
-            newForce = false;
-            lock (this.forcesList)
-            {
-                if (this.forcesList.Count > 0)
-                {
-                    for (int i = 0; i < this.forcesList.Count; i++)
-                    {
-                        NewForce force = this.forcesList[i];
-
-                        this.updateflag = true;
-                        this.Velocity = new LLVector3(force.X, force.Y, force.Z);
-                        this.newForce = true;
-                    }
-                    for (int i = 0; i < this.forcesList.Count; i++)
-                    {
-                        this.forcesList.RemoveAt(0);
-                    }
-                }
-            }
-        }
-
-        public static void LoadTextureFile(string name)
-        {
-            FileInfo fInfo = new FileInfo(name);
-            long numBytes = fInfo.Length;
-            FileStream fStream = new FileStream(name, FileMode.Open, FileAccess.Read);
-            BinaryReader br = new BinaryReader(fStream);
-            byte[] data1 = br.ReadBytes((int)numBytes);
-            br.Close();
-            fStream.Close();
-            DefaultTexture = data1;
-        }
-
-        public class NewForce
-        {
-            public float X;
-            public float Y;
-            public float Z;
-
-            public NewForce()
-            {
-
-            }
-        }
-    }
-
-}
+/*
+* Copyright (c) Contributors, http://www.openmetaverse.org/
+* See CONTRIBUTORS.TXT for a full list of copyright holders.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*     * Redistributions of source code must retain the above copyright
+*       notice, this list of conditions and the following disclaimer.
+*     * Redistributions in binary form must reproduce the above copyright
+*       notice, this list of conditions and the following disclaimer in the
+*       documentation and/or other materials provided with the distribution.
+*     * Neither the name of the OpenSim Project nor the
+*       names of its contributors may be used to endorse or promote products
+*       derived from this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
+* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
+* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+* 
+*/
+using System;
+using System.Collections.Generic;
+using System.IO;
+using Axiom.Math;
+using libsecondlife;
+using libsecondlife.Packets;
+using OpenSim.Framework.Console;
+using OpenSim.Framework.Interfaces;
+using OpenSim.Framework.Types;
+using OpenSim.Physics.Manager;
+
+namespace OpenSim.Region.Environment.Scenes
+{
+    public partial class ScenePresence : Entity
+    {
+        public static bool PhysicsEngineFlying = false;
+        public static AvatarAnimations Animations;
+        public static byte[] DefaultTexture;
+        public string firstname;
+        public string lastname;
+        public IClientAPI ControllingClient;
+        public LLUUID current_anim;
+        public int anim_seq;
+        private bool updateflag = false;
+        private byte movementflag = 0;
+        private List<NewForce> forcesList = new List<NewForce>();
+        private short _updateCount = 0;
+        private Quaternion bodyRot;
+        private LLObject.TextureEntry avatarAppearanceTexture = null;
+        private byte[] visualParams;
+        private AvatarWearable[] Wearables;
+        private ulong m_regionHandle;
+
+        public bool childAgent = false;
+        public bool IsRestrictedToRegion = false;
+
+        private bool newForce = false;
+        private bool newAvatar = false;
+        private IScenePresenceBody m_body;
+
+        protected RegionInfo m_regionInfo;
+
+        private Vector3[] Dir_Vectors = new Vector3[6];
+        private enum Dir_ControlFlags
+        {
+            DIR_CONTROL_FLAG_FOWARD = MainAvatar.ControlFlags.AGENT_CONTROL_AT_POS,
+            DIR_CONTROL_FLAG_BACK = MainAvatar.ControlFlags.AGENT_CONTROL_AT_NEG,
+            DIR_CONTROL_FLAG_LEFT = MainAvatar.ControlFlags.AGENT_CONTROL_LEFT_POS,
+            DIR_CONTROL_FLAG_RIGHT = MainAvatar.ControlFlags.AGENT_CONTROL_LEFT_NEG,
+            DIR_CONTROL_FLAG_UP = MainAvatar.ControlFlags.AGENT_CONTROL_UP_POS,
+            DIR_CONTROL_FLAG_DOWN = MainAvatar.ControlFlags.AGENT_CONTROL_UP_NEG
+        }
+        /// <summary>
+        /// Position at which a significant movement was made
+        /// </summary>
+        private LLVector3 posLastSignificantMove = new LLVector3();
+
+        public delegate void SignificantClientMovement(IClientAPI remote_client);
+        public event SignificantClientMovement OnSignificantClientMovement;
+
+        #region Properties
+        /// <summary>
+        /// 
+        /// </summary>
+        public PhysicsActor PhysActor
+        {
+            set
+            {
+                this._physActor = value;
+            }
+            get
+            {
+                return _physActor;
+            }
+        }
+
+	public ulong RegionHandle
+	{
+	    get { return m_regionHandle; }
+	}
+
+        #endregion
+
+        #region Constructor(s)
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="theClient"></param>
+        /// <param name="world"></param>
+        /// <param name="clientThreads"></param>
+        /// <param name="regionDat"></param>
+        public ScenePresence(IClientAPI theClient, Scene world, RegionInfo reginfo)
+        {
+
+            m_world = world;
+            this.uuid = theClient.AgentId;
+
+            m_regionInfo = reginfo;
+            m_regionHandle = reginfo.RegionHandle;
+            MainLog.Instance.Verbose("Avatar.cs ");
+            ControllingClient = theClient;
+            this.firstname = ControllingClient.FirstName;
+            this.lastname = ControllingClient.LastName;
+            m_localId = m_world.NextLocalId;
+            Pos = ControllingClient.StartPos;
+            visualParams = new byte[218];
+            for (int i = 0; i < 218; i++)
+            {
+                visualParams[i] = 100;
+            }
+
+            Wearables = AvatarWearable.DefaultWearables;
+            Animations = new ScenePresence.AvatarAnimations();
+            Animations.LoadAnims();
+
+            this.avatarAppearanceTexture = new LLObject.TextureEntry(new LLUUID("00000000-0000-0000-5005-000000000005"));
+
+            //register for events
+            ControllingClient.OnRequestWearables += this.SendOurAppearance;
+            //ControllingClient.OnSetAppearance += new SetAppearance(this.SetAppearance);
+            ControllingClient.OnCompleteMovementToRegion += this.CompleteMovement;
+            ControllingClient.OnCompleteMovementToRegion += this.SendInitialData;
+            ControllingClient.OnAgentUpdate += this.HandleAgentUpdate;
+            // ControllingClient.OnStartAnim += new StartAnim(this.SendAnimPack);
+            // ControllingClient.OnChildAgentStatus += new StatusChange(this.ChildStatusChange);
+            //ControllingClient.OnStopMovement += new GenericCall2(this.StopMovement);
+            
+            Dir_Vectors[0] = new Vector3(1, 0, 0);  //FOWARD
+            Dir_Vectors[1] = new Vector3(-1, 0, 0); //BACK
+            Dir_Vectors[2] = new Vector3(0, 1, 0);  //LEFT
+            Dir_Vectors[3] = new Vector3(0, -1, 0); //RIGHT
+            Dir_Vectors[4] = new Vector3(0, 0, 1);  //UP
+            Dir_Vectors[5] = new Vector3(0, 0, -1); //DOWN
+
+        }
+        #endregion
+
+        #region Status Methods
+        /// <summary>
+        /// Not Used, most likely can be deleted
+        /// </summary>
+        /// <param name="status"></param>
+        public void ChildStatusChange(bool status)
+        {
+            this.childAgent = status;
+
+            if (this.childAgent == true)
+            {
+                this.Velocity = new LLVector3(0, 0, 0);
+                this.Pos = new LLVector3(128, 128, 70);
+
+            }
+        }
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="pos"></param>
+        public void MakeAvatar(LLVector3 pos)
+        {
+            //this.childAvatar = false;
+            this.Pos = pos;
+            this.newAvatar = true;
+            this.childAgent = false;
+        }
+
+        protected void MakeChildAgent()
+        {
+            this.Velocity = new LLVector3(0, 0, 0);
+            this.Pos = new LLVector3(128, 128, 70);
+            this.childAgent = true;
+        }
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="pos"></param>
+        public void Teleport(LLVector3 pos)
+        {
+            this.Pos = pos;
+            this.SendTerseUpdateToALLClients();
+        }
+
+        /// <summary>
+        /// 
+        /// </summary>
+        public void StopMovement()
+        {
+
+        }
+        #endregion
+
+        #region Event Handlers
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="texture"></param>
+        /// <param name="visualParam"></param>
+        public void SetAppearance(byte[] texture, AgentSetAppearancePacket.VisualParamBlock[] visualParam)
+        {
+
+        }
+
+        /// <summary>
+        /// Complete Avatar's movement into the region
+        /// </summary>
+        public void CompleteMovement()
+        {
+            LLVector3 look = this.Velocity;
+            if ((look.X == 0) && (look.Y == 0) && (look.Z == 0))
+            {
+                look = new LLVector3(0.99f, 0.042f, 0);
+            }
+            this.ControllingClient.MoveAgentIntoRegion(m_regionInfo, Pos, look);
+            if (this.childAgent)
+            {
+                this.childAgent = false;
+            }
+        }
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="pack"></param>
+        public void HandleAgentUpdate(IClientAPI remoteClient, uint flags, LLQuaternion bodyRotation)
+        {
+            int i = 0;
+            bool update_movementflag = false;
+            bool update_rotation = false;
+            bool DCFlagKeyPressed = false;
+            Vector3 agent_control_v3 = new Vector3(0, 0, 0);
+            Quaternion q = new Quaternion(bodyRotation.W, bodyRotation.X, bodyRotation.Y, bodyRotation.Z);
+
+            this.PhysActor.Flying = ((flags & (uint)MainAvatar.ControlFlags.AGENT_CONTROL_FLY) != 0);
+
+            if (q != this.bodyRot)
+            {
+                this.bodyRot = q;
+                update_rotation = true;
+            }
+            foreach (Dir_ControlFlags DCF in Enum.GetValues(typeof(Dir_ControlFlags)))
+            {
+                if ((flags & (uint)DCF) != 0)
+                {
+                    DCFlagKeyPressed = true;
+                    agent_control_v3 += Dir_Vectors[i];
+                    if ((movementflag & (uint)DCF) == 0)
+                    {
+                        movementflag += (byte)(uint)DCF;
+                        update_movementflag = true;
+                    }
+                }
+                else
+                {
+                    if ((movementflag & (uint)DCF) != 0)
+                    {
+                        movementflag -= (byte)(uint)DCF;
+                        update_movementflag = true;
+                      
+                    }
+                }
+                i++;
+            }
+            if ((update_movementflag) || (update_rotation && DCFlagKeyPressed))
+            {
+                this.AddNewMovement(agent_control_v3, q);
+            }
+            UpdateMovementAnimations(update_movementflag);
+        }
+
+        protected void UpdateMovementAnimations(bool update_movementflag)
+        {
+            if (update_movementflag)
+            {
+                if (movementflag != 0)
+                {
+                    if (this._physActor.Flying)
+                    {
+                        this.SendAnimPack(Animations.AnimsLLUUID["FLY"], 1);
+                    }
+                    else
+                    {
+                        this.SendAnimPack(Animations.AnimsLLUUID["WALK"], 1);
+                    }
+                }
+                else
+                {
+                    this.SendAnimPack(Animations.AnimsLLUUID["STAND"], 1);
+                }
+            }
+
+        }
+
+
+        protected void AddNewMovement(Vector3 vec, Quaternion rotation)
+        {
+            NewForce newVelocity = new NewForce();
+            Vector3 direc = rotation * vec;
+            direc.Normalize();
+
+            direc = direc * ((0.03f) * 128f);
+            if (this._physActor.Flying)
+                direc *= 4;
+
+            newVelocity.X = direc.x;
+            newVelocity.Y = direc.y;
+            newVelocity.Z = direc.z;
+            this.forcesList.Add(newVelocity);
+        }
+
+        #endregion
+
+        #region Overridden Methods
+        /// <summary>
+        /// 
+        /// </summary>
+        public override void LandRenegerated()
+        {
+
+        }
+
+        /// <summary>
+        /// 
+        /// </summary>
+        public override void update()
+        {
+            if (this.childAgent == false)
+            {
+                if (this.newForce)
+                {
+                    this.SendTerseUpdateToALLClients();
+                    _updateCount = 0;
+                }
+                else if (movementflag != 0)
+                {
+                    _updateCount++;
+                    if (_updateCount > 3)
+                    {
+                        this.SendTerseUpdateToALLClients();
+                        _updateCount = 0;
+                    }
+                }
+
+                this.CheckForSignificantMovement();
+                this.CheckForBorderCrossing();
+                
+            }
+        }
+        #endregion
+
+        #region Update Client(s)
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="RemoteClient"></param>
+        public void SendTerseUpdateToClient(IClientAPI RemoteClient)
+        {
+            LLVector3 pos = this.Pos;
+            LLVector3 vel = this.Velocity;
+            RemoteClient.SendAvatarTerseUpdate(this.m_regionHandle, 64096, this.LocalId, new LLVector3(pos.X, pos.Y, pos.Z), new LLVector3(vel.X, vel.Y, vel.Z));
+        }
+
+        /// <summary>
+        /// 
+        /// </summary>
+        public void SendTerseUpdateToALLClients()
+        {
+            List<ScenePresence> avatars = this.m_world.RequestAvatarList();
+            for (int i = 0; i < avatars.Count; i++)
+            {
+                this.SendTerseUpdateToClient(avatars[i].ControllingClient);
+            }
+        }
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="remoteAvatar"></param>
+        public void SendFullUpdateToOtherClient(ScenePresence remoteAvatar)
+        {
+            remoteAvatar.ControllingClient.SendAvatarData(m_regionInfo.RegionHandle, this.firstname, this.lastname, this.uuid, this.LocalId, this.Pos, DefaultTexture);
+        }
+
+        public void SendFullUpdateToALLClients()
+        {
+            List<ScenePresence> avatars = this.m_world.RequestAvatarList();
+            foreach (ScenePresence avatar in this.m_world.RequestAvatarList())
+            {
+                this.SendFullUpdateToOtherClient(avatar);
+                avatar.SendFullUpdateToOtherClient(this);
+            }
+        }
+
+        /// <summary>
+        /// 
+        /// </summary>
+        public void SendInitialData()
+        {
+            this.ControllingClient.SendAvatarData(m_regionInfo.RegionHandle, this.firstname, this.lastname, this.uuid, this.LocalId, this.Pos, DefaultTexture);
+            if (this.newAvatar)
+            {
+                this.m_world.InformClientOfNeighbours(this.ControllingClient);
+                this.newAvatar = false;
+            }
+        }
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="OurClient"></param>
+        public void SendOurAppearance(IClientAPI OurClient)
+        {
+            this.ControllingClient.SendWearables(this.Wearables);
+            this.SendFullUpdateToALLClients();
+            this.m_world.SendAllSceneObjectsToClient(this.ControllingClient);
+        }
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="avatarInfo"></param>
+        public void SendAppearanceToOtherAgent(ScenePresence avatarInfo)
+        {
+
+        }
+
+        /// <summary>
+        /// 
+        /// </summary>
+        /// <param name="animID"></param>
+        /// <param name="seq"></param>
+        public void SendAnimPack(LLUUID animID, int seq)
+        {
+	    this.current_anim = animID;
+	    this.anim_seq = seq;
+	    List<ScenePresence> avatars = this.m_world.RequestAvatarList();
+	    for (int i = 0; i < avatars.Count; i++)
+	    {
+	    	avatars[i].ControllingClient.SendAnimation(animID, seq, this.ControllingClient.AgentId);
+	    }
+        }
+
+        /// <summary>
+        /// 
+        /// </summary>
+        public void SendAnimPack()
+        {
+            this.SendAnimPack(this.current_anim, this.anim_seq);
+        }
+        #endregion
+
+        #region Significant Movement Method
+
+        protected void CheckForSignificantMovement()
+        {
+            if (libsecondlife.Helpers.VecDist(this.Pos, this.posLastSignificantMove) > 2.0)
+            {
+                this.posLastSignificantMove = this.Pos;
+                if (OnSignificantClientMovement != null)
+                {
+                    OnSignificantClientMovement(this.ControllingClient);
+                }
+            }
+        }
+        #endregion
+        #region Border Crossing Methods
+        /// <summary>
+        /// 
+        /// </summary>
+        protected void CheckForBorderCrossing()
+        {
+            LLVector3 pos2 = this.Pos;
+            LLVector3 vel = this.Velocity;
+
+            float timeStep = 0.2f;
+            pos2.X = pos2.X + (vel.X * timeStep);
+            pos2.Y = pos2.Y + (vel.Y * timeStep);
+            pos2.Z = pos2.Z + (vel.Z * timeStep);
+
+            if ((pos2.X < 0) || (pos2.X > 256))
+            {
+                this.CrossToNewRegion();
+            }
+
+            if ((pos2.Y < 0) || (pos2.Y > 256))
+            {
+                this.CrossToNewRegion();
+            }
+        }
+
+        /// <summary>
+        /// 
+        /// </summary>
+        protected void CrossToNewRegion()
+        {
+            LLVector3 pos = this.Pos;
+            LLVector3 newpos = new LLVector3(pos.X, pos.Y, pos.Z);
+            uint neighbourx = this.m_regionInfo.RegionLocX;
+            uint neighboury = this.m_regionInfo.RegionLocY;
+
+            if (pos.X < 2)
+            {
+                neighbourx -= 1;
+                newpos.X = 254;
+            }
+            if (pos.X > 253)
+            {
+                neighbourx += 1;
+                newpos.X = 1;
+            }
+            if (pos.Y < 2)
+            {
+                neighboury -= 1;
+                newpos.Y = 254;
+            }
+            if (pos.Y > 253)
+            {
+                neighboury += 1;
+                newpos.Y = 1;
+            }
+
+            LLVector3 vel = this.m_velocity;
+            ulong neighbourHandle = Helpers.UIntsToLong((uint)(neighbourx * 256), (uint)(neighboury * 256));
+            RegionInfo neighbourRegion = this.m_world.RequestNeighbouringRegionInfo(neighbourHandle);
+            if (neighbourRegion != null)
+            {
+                bool res = this.m_world.InformNeighbourOfCrossing(neighbourHandle, this.ControllingClient.AgentId, newpos);
+                if (res)
+                {
+                    this.MakeChildAgent();
+                    this.ControllingClient.CrossRegion(neighbourHandle, newpos, vel, neighbourRegion.InternalEndPoint);
+                }
+            }
+        }
+        #endregion
+
+        /// <summary>
+        /// 
+        /// </summary>
+        public static void LoadAnims()
+        {
+
+        }
+
+        /// <summary>
+        /// 
+        /// </summary>
+        public override void updateMovement()
+        {
+            newForce = false;
+            lock (this.forcesList)
+            {
+                if (this.forcesList.Count > 0)
+                {
+                    for (int i = 0; i < this.forcesList.Count; i++)
+                    {
+                        NewForce force = this.forcesList[i];
+
+                        this.updateflag = true;
+                        this.Velocity = new LLVector3(force.X, force.Y, force.Z);
+                        this.newForce = true;
+                    }
+                    for (int i = 0; i < this.forcesList.Count; i++)
+                    {
+                        this.forcesList.RemoveAt(0);
+                    }
+                }
+            }
+        }
+
+        public static void LoadTextureFile(string name)
+        {
+            FileInfo fInfo = new FileInfo(name);
+            long numBytes = fInfo.Length;
+            FileStream fStream = new FileStream(name, FileMode.Open, FileAccess.Read);
+            BinaryReader br = new BinaryReader(fStream);
+            byte[] data1 = br.ReadBytes((int)numBytes);
+            br.Close();
+            fStream.Close();
+            DefaultTexture = data1;
+        }
+
+        public class NewForce
+        {
+            public float X;
+            public float Y;
+            public float Z;
+
+            public NewForce()
+            {
+
+            }
+        }
+    }
+
+}
diff --git a/OpenSim/Region/Environment/Scenes/scripting/Engines/CSharpEngine/CSharpScriptEngine.cs b/OpenSim/Region/Environment/Scenes/scripting/Engines/CSharpEngine/CSharpScriptEngine.cs
index 1fc576e..b0ccd22 100644
--- a/OpenSim/Region/Environment/Scenes/scripting/Engines/CSharpEngine/CSharpScriptEngine.cs
+++ b/OpenSim/Region/Environment/Scenes/scripting/Engines/CSharpEngine/CSharpScriptEngine.cs
@@ -1,102 +1,102 @@
-/*
-* Copyright (c) Contributors, http://www.openmetaverse.org/
-* See CONTRIBUTORS.TXT for a full list of copyright holders.
-*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted provided that the following conditions are met:
-*     * Redistributions of source code must retain the above copyright
-*       notice, this list of conditions and the following disclaimer.
-*     * Redistributions in binary form must reproduce the above copyright
-*       notice, this list of conditions and the following disclaimer in the
-*       documentation and/or other materials provided with the distribution.
-*     * Neither the name of the OpenSim Project nor the
-*       names of its contributors may be used to endorse or promote products
-*       derived from this software without specific prior written permission.
-*
-* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
-* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
-* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-* 
-*/
-using System;
-using System.CodeDom.Compiler;
-using System.Collections.Generic;
-using Microsoft.CSharp;
-using OpenSim.Framework.Console;
-
-namespace OpenSim.Region.Scripting
-{
-    public class CSharpScriptEngine : IScriptCompiler
-    {
-        public string FileExt()
-        {
-            return ".cs";
-        }
-
-        private Dictionary<string,IScript> LoadDotNetScript(CodeDomProvider compiler, string filename)
-        {
-            CompilerParameters compilerParams = new CompilerParameters();
-            CompilerResults compilerResults;
-            compilerParams.GenerateExecutable = false;
-            compilerParams.GenerateInMemory = true;
-            compilerParams.IncludeDebugInformation = false;
-            compilerParams.ReferencedAssemblies.Add("OpenSim.Region.dll");
-            compilerParams.ReferencedAssemblies.Add("OpenSim.Region.Environment.dll");
-            compilerParams.ReferencedAssemblies.Add("OpenSim.Framework.dll");
-            compilerParams.ReferencedAssemblies.Add("libsecondlife.dll");
-            compilerParams.ReferencedAssemblies.Add("System.dll");
-
-            compilerResults = compiler.CompileAssemblyFromFile(compilerParams, filename);
-
-            if (compilerResults.Errors.Count > 0)
-            {
-                MainLog.Instance.Error("Compile errors");
-                foreach (CompilerError error in compilerResults.Errors)
-                {
-                    MainLog.Instance.Error(error.Line.ToString() + ": " + error.ErrorText.ToString());
-                }
-            }
-            else
-            {
-                Dictionary<string,IScript> scripts = new Dictionary<string,IScript>();
-                
-                foreach (Type pluginType in compilerResults.CompiledAssembly.GetExportedTypes())
-                {
-                    Type testInterface = pluginType.GetInterface("IScript", true);
-
-                    if (testInterface != null)
-                    {
-                        IScript script = (IScript)compilerResults.CompiledAssembly.CreateInstance(pluginType.ToString());
-
-                        string scriptName = "C#/" + script.getName();
-                        Console.WriteLine("Script: " + scriptName + " loaded.");
-
-                        if (!scripts.ContainsKey(scriptName))
-                        {
-                            scripts.Add(scriptName, script);
-                        }
-                        else
-                        {
-                            scripts[scriptName] = script;
-                        }
-                    }
-                }
-                return scripts;
-            }
-            return null;
-        }
-
-        public Dictionary<string,IScript> compile(string filename)
-        {
-            CSharpCodeProvider csharpProvider = new CSharpCodeProvider();
-            return LoadDotNetScript(csharpProvider, filename);
-        }
-    }
-}
+/*
+* Copyright (c) Contributors, http://www.openmetaverse.org/
+* See CONTRIBUTORS.TXT for a full list of copyright holders.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*     * Redistributions of source code must retain the above copyright
+*       notice, this list of conditions and the following disclaimer.
+*     * Redistributions in binary form must reproduce the above copyright
+*       notice, this list of conditions and the following disclaimer in the
+*       documentation and/or other materials provided with the distribution.
+*     * Neither the name of the OpenSim Project nor the
+*       names of its contributors may be used to endorse or promote products
+*       derived from this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
+* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
+* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+* 
+*/
+using System;
+using System.CodeDom.Compiler;
+using System.Collections.Generic;
+using Microsoft.CSharp;
+using OpenSim.Framework.Console;
+
+namespace OpenSim.Region.Scripting
+{
+    public class CSharpScriptEngine : IScriptCompiler
+    {
+        public string FileExt()
+        {
+            return ".cs";
+        }
+
+        private Dictionary<string,IScript> LoadDotNetScript(CodeDomProvider compiler, string filename)
+        {
+            CompilerParameters compilerParams = new CompilerParameters();
+            CompilerResults compilerResults;
+            compilerParams.GenerateExecutable = false;
+            compilerParams.GenerateInMemory = true;
+            compilerParams.IncludeDebugInformation = false;
+            compilerParams.ReferencedAssemblies.Add("OpenSim.Region.dll");
+            compilerParams.ReferencedAssemblies.Add("OpenSim.Region.Environment.dll");
+            compilerParams.ReferencedAssemblies.Add("OpenSim.Framework.dll");
+            compilerParams.ReferencedAssemblies.Add("libsecondlife.dll");
+            compilerParams.ReferencedAssemblies.Add("System.dll");
+
+            compilerResults = compiler.CompileAssemblyFromFile(compilerParams, filename);
+
+            if (compilerResults.Errors.Count > 0)
+            {
+                MainLog.Instance.Error("Compile errors");
+                foreach (CompilerError error in compilerResults.Errors)
+                {
+                    MainLog.Instance.Error(error.Line.ToString() + ": " + error.ErrorText.ToString());
+                }
+            }
+            else
+            {
+                Dictionary<string,IScript> scripts = new Dictionary<string,IScript>();
+                
+                foreach (Type pluginType in compilerResults.CompiledAssembly.GetExportedTypes())
+                {
+                    Type testInterface = pluginType.GetInterface("IScript", true);
+
+                    if (testInterface != null)
+                    {
+                        IScript script = (IScript)compilerResults.CompiledAssembly.CreateInstance(pluginType.ToString());
+
+                        string scriptName = "C#/" + script.getName();
+                        Console.WriteLine("Script: " + scriptName + " loaded.");
+
+                        if (!scripts.ContainsKey(scriptName))
+                        {
+                            scripts.Add(scriptName, script);
+                        }
+                        else
+                        {
+                            scripts[scriptName] = script;
+                        }
+                    }
+                }
+                return scripts;
+            }
+            return null;
+        }
+
+        public Dictionary<string,IScript> compile(string filename)
+        {
+            CSharpCodeProvider csharpProvider = new CSharpCodeProvider();
+            return LoadDotNetScript(csharpProvider, filename);
+        }
+    }
+}
diff --git a/OpenSim/Region/Environment/Scenes/scripting/Engines/CSharpEngine/Examples/ExportRegionToLSL.cs b/OpenSim/Region/Environment/Scenes/scripting/Engines/CSharpEngine/Examples/ExportRegionToLSL.cs
index d9f1f0a..79d88b1 100644
--- a/OpenSim/Region/Environment/Scenes/scripting/Engines/CSharpEngine/Examples/ExportRegionToLSL.cs
+++ b/OpenSim/Region/Environment/Scenes/scripting/Engines/CSharpEngine/Examples/ExportRegionToLSL.cs
@@ -1,70 +1,70 @@
-using OpenSim.Framework.Console;
-using OpenSim.Framework;
-using OpenSim.Region.Environment;
-using OpenSim.Region.Environment.Scenes;
-
-using System.Collections.Generic;
-using libsecondlife;
-
-namespace OpenSim.Region.Scripting.Examples
-{
-    public class LSLExportScript : IScript
-    {
-        ScriptInfo script;
-
-        public string getName()
-        {
-            return "LSL Export Script 0.1";
-        }
-
-        public void Initialise(ScriptInfo scriptInfo)
-        {
-            script = scriptInfo;
-            
-            script.events.OnScriptConsole += new EventManager.OnScriptConsoleDelegate(ProcessConsoleMsg);
-        }
-
-        void ProcessConsoleMsg(string[] args)
-        {
-            if (args[0].ToLower() == "lslexport")
-            {
-                string sequence = "";
-
-                foreach (KeyValuePair<LLUUID, SceneObject> obj in script.world.Objects)
-                {
-                    SceneObject root = obj.Value;
-
-                    sequence += "NEWOBJ::" + obj.Key.ToStringHyphenated() + "\n";
-
-                    string rootPrim = processPrimitiveToString(root.rootPrimitive);
-
-                    sequence += "ROOT:" + rootPrim;
-
-                    foreach (KeyValuePair<LLUUID, OpenSim.Region.Environment.Scenes.Primitive> prim in root.Children)
-                    {
-                        string child = processPrimitiveToString(prim.Value);
-                        sequence += "CHILD:" + child;
-                    }
-                }
-
-                System.Console.WriteLine(sequence);
-            }
-        }
-
-        string processPrimitiveToString(OpenSim.Region.Environment.Scenes.Primitive prim)
-        {
-            string desc = prim.Description;
-            string name = prim.Name;
-            LLVector3 pos = prim.Pos;
-            LLVector3 rot = new LLVector3();
-            LLVector3 scale = prim.Scale;
-            LLVector3 rootPos = prim.WorldPos;
-
-            string setPrimParams = "";
-
-            setPrimParams += "[PRIM_SCALE, " + scale.ToString() + ", PRIM_POS, " + rootPos.ToString() + ", PRIM_ROTATION, " + rot.ToString() + "]\n";
-
-            return setPrimParams;
-        }
-    }
+using OpenSim.Framework.Console;
+using OpenSim.Framework;
+using OpenSim.Region.Environment;
+using OpenSim.Region.Environment.Scenes;
+
+using System.Collections.Generic;
+using libsecondlife;
+
+namespace OpenSim.Region.Scripting.Examples
+{
+    public class LSLExportScript : IScript
+    {
+        ScriptInfo script;
+
+        public string getName()
+        {
+            return "LSL Export Script 0.1";
+        }
+
+        public void Initialise(ScriptInfo scriptInfo)
+        {
+            script = scriptInfo;
+            
+            script.events.OnScriptConsole += new EventManager.OnScriptConsoleDelegate(ProcessConsoleMsg);
+        }
+
+        void ProcessConsoleMsg(string[] args)
+        {
+            if (args[0].ToLower() == "lslexport")
+            {
+                string sequence = "";
+
+                foreach (KeyValuePair<LLUUID, SceneObject> obj in script.world.Objects)
+                {
+                    SceneObject root = obj.Value;
+
+                    sequence += "NEWOBJ::" + obj.Key.ToStringHyphenated() + "\n";
+
+                    string rootPrim = processPrimitiveToString(root.rootPrimitive);
+
+                    sequence += "ROOT:" + rootPrim;
+
+                    foreach (KeyValuePair<LLUUID, OpenSim.Region.Environment.Scenes.Primitive> prim in root.Children)
+                    {
+                        string child = processPrimitiveToString(prim.Value);
+                        sequence += "CHILD:" + child;
+                    }
+                }
+
+                System.Console.WriteLine(sequence);
+            }
+        }
+
+        string processPrimitiveToString(OpenSim.Region.Environment.Scenes.Primitive prim)
+        {
+            string desc = prim.Description;
+            string name = prim.Name;
+            LLVector3 pos = prim.Pos;
+            LLVector3 rot = new LLVector3();
+            LLVector3 scale = prim.Scale;
+            LLVector3 rootPos = prim.WorldPos;
+
+            string setPrimParams = "";
+
+            setPrimParams += "[PRIM_SCALE, " + scale.ToString() + ", PRIM_POS, " + rootPos.ToString() + ", PRIM_ROTATION, " + rot.ToString() + "]\n";
+
+            return setPrimParams;
+        }
+    }
 }
\ No newline at end of file
diff --git a/OpenSim/Region/Environment/Scenes/scripting/Engines/JScriptEngine/JScriptEngine.cs b/OpenSim/Region/Environment/Scenes/scripting/Engines/JScriptEngine/JScriptEngine.cs
index 0833e7a..af4f8b4 100644
--- a/OpenSim/Region/Environment/Scenes/scripting/Engines/JScriptEngine/JScriptEngine.cs
+++ b/OpenSim/Region/Environment/Scenes/scripting/Engines/JScriptEngine/JScriptEngine.cs
@@ -1,102 +1,102 @@
-/*
-* Copyright (c) Contributors, http://www.openmetaverse.org/
-* See CONTRIBUTORS.TXT for a full list of copyright holders.
-*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted provided that the following conditions are met:
-*     * Redistributions of source code must retain the above copyright
-*       notice, this list of conditions and the following disclaimer.
-*     * Redistributions in binary form must reproduce the above copyright
-*       notice, this list of conditions and the following disclaimer in the
-*       documentation and/or other materials provided with the distribution.
-*     * Neither the name of the OpenSim Project nor the
-*       names of its contributors may be used to endorse or promote products
-*       derived from this software without specific prior written permission.
-*
-* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
-* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
-* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-* 
-*/
-using System;
-using System.CodeDom.Compiler;
-using System.Collections.Generic;
-using Microsoft.JScript;
-using OpenSim.Framework.Console;
-
-namespace OpenSim.Region.Scripting
-{
-    public class JScriptEngine : IScriptCompiler
-    {
-        public string FileExt()
-        {
-            return ".js";
-        }
-
-        private Dictionary<string, IScript> LoadDotNetScript(CodeDomProvider compiler, string filename)
-        {
-            CompilerParameters compilerParams = new CompilerParameters();
-            CompilerResults compilerResults;
-            compilerParams.GenerateExecutable = false;
-            compilerParams.GenerateInMemory = true;
-            compilerParams.IncludeDebugInformation = false;
-            compilerParams.ReferencedAssemblies.Add("OpenSim.Region.dll");
-            compilerParams.ReferencedAssemblies.Add("OpenSim.Region.Environment.dll");
-            compilerParams.ReferencedAssemblies.Add("OpenSim.Framework.dll");
-            compilerParams.ReferencedAssemblies.Add("libsecondlife.dll");
-            compilerParams.ReferencedAssemblies.Add("System.dll");
-
-            compilerResults = compiler.CompileAssemblyFromFile(compilerParams, filename);
-
-            if (compilerResults.Errors.Count > 0)
-            {
-                MainLog.Instance.Error("Compile errors");
-                foreach (CompilerError error in compilerResults.Errors)
-                {
-                    MainLog.Instance.Error(error.Line.ToString() + ": " + error.ErrorText.ToString());
-                }
-            }
-            else
-            {
-                Dictionary<string, IScript> scripts = new Dictionary<string, IScript>();
-
-                foreach (Type pluginType in compilerResults.CompiledAssembly.GetExportedTypes())
-                {
-                    Type testInterface = pluginType.GetInterface("IScript", true);
-
-                    if (testInterface != null)
-                    {
-                        IScript script = (IScript)compilerResults.CompiledAssembly.CreateInstance(pluginType.ToString());
-
-                        string scriptName = "JS.NET/" + script.getName();
-                        Console.WriteLine("Script: " + scriptName + " loaded.");
-
-                        if (!scripts.ContainsKey(scriptName))
-                        {
-                            scripts.Add(scriptName, script);
-                        }
-                        else
-                        {
-                            scripts[scriptName] = script;
-                        }
-                    }
-                }
-                return scripts;
-            }
-            return null;
-        }
-
-        public Dictionary<string, IScript> compile(string filename)
-        {
-            JScriptCodeProvider jscriptProvider = new JScriptCodeProvider();
-            return LoadDotNetScript(jscriptProvider, filename);
-        }
-    }
-}
+/*
+* Copyright (c) Contributors, http://www.openmetaverse.org/
+* See CONTRIBUTORS.TXT for a full list of copyright holders.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*     * Redistributions of source code must retain the above copyright
+*       notice, this list of conditions and the following disclaimer.
+*     * Redistributions in binary form must reproduce the above copyright
+*       notice, this list of conditions and the following disclaimer in the
+*       documentation and/or other materials provided with the distribution.
+*     * Neither the name of the OpenSim Project nor the
+*       names of its contributors may be used to endorse or promote products
+*       derived from this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
+* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
+* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+* 
+*/
+using System;
+using System.CodeDom.Compiler;
+using System.Collections.Generic;
+using Microsoft.JScript;
+using OpenSim.Framework.Console;
+
+namespace OpenSim.Region.Scripting
+{
+    public class JScriptEngine : IScriptCompiler
+    {
+        public string FileExt()
+        {
+            return ".js";
+        }
+
+        private Dictionary<string, IScript> LoadDotNetScript(CodeDomProvider compiler, string filename)
+        {
+            CompilerParameters compilerParams = new CompilerParameters();
+            CompilerResults compilerResults;
+            compilerParams.GenerateExecutable = false;
+            compilerParams.GenerateInMemory = true;
+            compilerParams.IncludeDebugInformation = false;
+            compilerParams.ReferencedAssemblies.Add("OpenSim.Region.dll");
+            compilerParams.ReferencedAssemblies.Add("OpenSim.Region.Environment.dll");
+            compilerParams.ReferencedAssemblies.Add("OpenSim.Framework.dll");
+            compilerParams.ReferencedAssemblies.Add("libsecondlife.dll");
+            compilerParams.ReferencedAssemblies.Add("System.dll");
+
+            compilerResults = compiler.CompileAssemblyFromFile(compilerParams, filename);
+
+            if (compilerResults.Errors.Count > 0)
+            {
+                MainLog.Instance.Error("Compile errors");
+                foreach (CompilerError error in compilerResults.Errors)
+                {
+                    MainLog.Instance.Error(error.Line.ToString() + ": " + error.ErrorText.ToString());
+                }
+            }
+            else
+            {
+                Dictionary<string, IScript> scripts = new Dictionary<string, IScript>();
+
+                foreach (Type pluginType in compilerResults.CompiledAssembly.GetExportedTypes())
+                {
+                    Type testInterface = pluginType.GetInterface("IScript", true);
+
+                    if (testInterface != null)
+                    {
+                        IScript script = (IScript)compilerResults.CompiledAssembly.CreateInstance(pluginType.ToString());
+
+                        string scriptName = "JS.NET/" + script.getName();
+                        Console.WriteLine("Script: " + scriptName + " loaded.");
+
+                        if (!scripts.ContainsKey(scriptName))
+                        {
+                            scripts.Add(scriptName, script);
+                        }
+                        else
+                        {
+                            scripts[scriptName] = script;
+                        }
+                    }
+                }
+                return scripts;
+            }
+            return null;
+        }
+
+        public Dictionary<string, IScript> compile(string filename)
+        {
+            JScriptCodeProvider jscriptProvider = new JScriptCodeProvider();
+            return LoadDotNetScript(jscriptProvider, filename);
+        }
+    }
+}
diff --git a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/JVM/ClassInstance.cs b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/JVM/ClassInstance.cs
index 0b1cf41..ca729b4 100644
--- a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/JVM/ClassInstance.cs
+++ b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/JVM/ClassInstance.cs
@@ -1,45 +1,45 @@
-/*
-* Copyright (c) Contributors, http://www.openmetaverse.org/
-* See CONTRIBUTORS.TXT for a full list of copyright holders.
-*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted provided that the following conditions are met:
-*     * Redistributions of source code must retain the above copyright
-*       notice, this list of conditions and the following disclaimer.
-*     * Redistributions in binary form must reproduce the above copyright
-*       notice, this list of conditions and the following disclaimer in the
-*       documentation and/or other materials provided with the distribution.
-*     * Neither the name of the OpenSim Project nor the
-*       names of its contributors may be used to endorse or promote products
-*       derived from this software without specific prior written permission.
-*
-* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
-* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
-* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-* 
-*/
-using System;
-using System.Collections.Generic;
-using System.Text;
-using OpenSim.Region.Scripting.EmbeddedJVM.Types;
-
-namespace OpenSim.Region.Scripting.EmbeddedJVM
-{
-    public class ClassInstance : Object
-    {
-        public int size;
-        public Dictionary<string, BaseType> Fields = new Dictionary<string, BaseType>();
-
-        public ClassInstance()
-        {
-
-        }
-    }
-}
+/*
+* Copyright (c) Contributors, http://www.openmetaverse.org/
+* See CONTRIBUTORS.TXT for a full list of copyright holders.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*     * Redistributions of source code must retain the above copyright
+*       notice, this list of conditions and the following disclaimer.
+*     * Redistributions in binary form must reproduce the above copyright
+*       notice, this list of conditions and the following disclaimer in the
+*       documentation and/or other materials provided with the distribution.
+*     * Neither the name of the OpenSim Project nor the
+*       names of its contributors may be used to endorse or promote products
+*       derived from this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
+* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
+* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+* 
+*/
+using System;
+using System.Collections.Generic;
+using System.Text;
+using OpenSim.Region.Scripting.EmbeddedJVM.Types;
+
+namespace OpenSim.Region.Scripting.EmbeddedJVM
+{
+    public class ClassInstance : Object
+    {
+        public int size;
+        public Dictionary<string, BaseType> Fields = new Dictionary<string, BaseType>();
+
+        public ClassInstance()
+        {
+
+        }
+    }
+}
diff --git a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/JVM/ClassRecord.cs b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/JVM/ClassRecord.cs
index f821f52..f151b7e 100644
--- a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/JVM/ClassRecord.cs
+++ b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/JVM/ClassRecord.cs
@@ -1,503 +1,503 @@
-/*
-* Copyright (c) Contributors, http://www.openmetaverse.org/
-* See CONTRIBUTORS.TXT for a full list of copyright holders.
-*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted provided that the following conditions are met:
-*     * Redistributions of source code must retain the above copyright
-*       notice, this list of conditions and the following disclaimer.
-*     * Redistributions in binary form must reproduce the above copyright
-*       notice, this list of conditions and the following disclaimer in the
-*       documentation and/or other materials provided with the distribution.
-*     * Neither the name of the OpenSim Project nor the
-*       names of its contributors may be used to endorse or promote products
-*       derived from this software without specific prior written permission.
-*
-* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
-* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
-* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-* 
-*/
-using System;
-using System.IO;
-using System.Collections.Generic;
-using System.Text;
-using OpenSim.Region.Scripting.EmbeddedJVM.Types;
-
-namespace OpenSim.Region.Scripting.EmbeddedJVM
-{
-    public class ClassRecord
-    {
-        private ushort _majorVersion;
-        private ushort _minorVersion;
-        private ushort _constantPoolCount;
-        private ushort _accessFlags;
-        private ushort _thisClass;
-        private ushort _supperClass;
-        private ushort _interfaceCount;
-        private ushort _fieldCount;
-        private ushort _methodCount;
-        //private ushort _attributeCount;
-        //private string _name;
-        public Dictionary<string, BaseType> StaticFields = new Dictionary<string, BaseType>();
-        public PoolClass mClass;
-
-        public List<PoolItem> _constantsPool = new List<PoolItem>();
-        private List<MethodInfo> _methodsList = new List<MethodInfo>();
-        private List<FieldInfo> _fieldList = new List<FieldInfo>();
-
-        public ClassRecord()
-        {
-
-        }
-
-        public ClassInstance CreateNewInstance()
-        {
-            return new ClassInstance();
-        }
-
-        public void LoadClassFromFile(string fileName)
-        {
-            Console.WriteLine("loading script " + fileName);
-            FileStream fs = File.OpenRead(fileName);
-            this.LoadClassFromBytes(ReadFully(fs));
-            fs.Close();
-        }
-
-        public void LoadClassFromBytes(byte[] data)
-        {
-            int i = 0;
-            i += 4;
-            _minorVersion = (ushort)((data[i++] << 8) + data[i++]  );
-            _majorVersion = (ushort)((data[i++] << 8) + data[i++]  );
-            _constantPoolCount = (ushort)((data[i++] << 8) + data[i++]  );
-           // Console.WriteLine("there should be " + _constantPoolCount + " items in the pool");
-            for (int count = 0; count < _constantPoolCount -1 ; count++)
-            {
-                //read in the constant pool
-                byte pooltype = data[i++];
-                //Console.WriteLine("#" +count +": new constant type = " +pooltype);
-                //Console.WriteLine("start position is: " + i);
-                switch (pooltype)
-                {
-                    case 1:  //Utf8
-                        ushort uLength = (ushort)((data[i++] << 8) + data[i++]  );
-
-                       // Console.WriteLine("new utf8 type, length is " + uLength);
-                        PoolUtf8 utf8 = new PoolUtf8();
-                        utf8.readValue(data, ref i, uLength);
-                        this._constantsPool.Add(utf8);
-                        break;
-                    case 3: //Int
-                        break;
-                    case 7: //Class
-                        PoolClass pClass = new PoolClass(this);
-                        pClass.readValue(data, ref i);
-                        this._constantsPool.Add(pClass);
-                        break;
-                    case 10: //Method
-                        PoolMethodRef pMeth = new PoolMethodRef(this);
-                        pMeth.readValue(data, ref i);
-                        this._constantsPool.Add(pMeth);
-                        break;
-                    case 12:  //NamedType
-                        PoolNamedType pNamed = new PoolNamedType(this);
-                        pNamed.readValue(data, ref i);
-                        this._constantsPool.Add(pNamed);
-                        break;
-                }
-            }
-
-            _accessFlags = (ushort)((data[i++] << 8) + data[i++]  );
-            _thisClass = (ushort)((data[i++] << 8) + data[i++]  );
-            _supperClass = (ushort)((data[i++] << 8) + data[i++]  );
-
-            if (this._constantsPool[this._thisClass - 1] is PoolClass)
-            {
-                this.mClass = ((PoolClass)this._constantsPool[this._thisClass - 1]);
-            }
-
-            _interfaceCount = (ushort)((data[i++] << 8) + data[i++]);
-            //should now read in the info for each interface
-            _fieldCount = (ushort)((data[i++] << 8) + data[i++]);
-            //should now read in the info for each field
-            _methodCount = (ushort)((data[i++] << 8) + data[i++]);
-            for (int count = 0; count < _methodCount; count++)
-            {
-                MethodInfo methInf = new MethodInfo(this);
-                methInf.ReadData(data, ref i);
-                this._methodsList.Add(methInf);
-            }
-        }
-
-        public void AddMethodsToMemory(MethodMemory memory)
-        {
-            for (int count = 0; count < _methodCount; count++)
-            {
-                this._methodsList[count].AddMethodCode(memory);
-            }
-        }
-
-        public bool StartMethod(Thread thread, string methodName)
-        {
-            for (int count = 0; count < _methodCount; count++)
-            {
-                if (this._constantsPool[this._methodsList[count].NameIndex-1] is PoolUtf8)
-                {
-                    if (((PoolUtf8)this._constantsPool[this._methodsList[count].NameIndex-1]).Value == methodName)
-                    {
-                        //Console.WriteLine("found method: " + ((PoolUtf8)this._constantsPool[this._methodsList[count].NameIndex - 1]).Value);
-                        thread.SetPC(this._methodsList[count].CodePointer);
-                        return true;
-                    }
-                }
-            }
-            return false;
-        }
-
-        public void PrintToConsole()
-        {
-            Console.WriteLine("Class File:");
-           Console.WriteLine("Major version: " + _majorVersion);
-           Console.WriteLine("Minor version: " + _minorVersion);
-            Console.WriteLine("Pool size: " + _constantPoolCount);
-
-            for (int i = 0; i < _constantsPool.Count; i++)
-            {
-                this._constantsPool[i].Print();
-            }
-
-           Console.WriteLine("Access flags: " + _accessFlags);
-           Console.WriteLine("This class: " + _thisClass );
-           Console.WriteLine("Super class: " + _supperClass);
-
-            for (int count = 0; count < _methodCount; count++)
-            {
-                Console.WriteLine();
-                this._methodsList[count].Print();
-            }
-
-           Console.WriteLine("class name is " + this.mClass.Name.Value);
-        }
-
-        public static byte[] ReadFully(Stream stream)
-        {
-            byte[] buffer = new byte[1024];
-            using (MemoryStream ms = new MemoryStream())
-            {
-                while (true)
-                {
-                    int read = stream.Read(buffer, 0, buffer.Length);
-                    if (read <= 0)
-                        return ms.ToArray();
-                    ms.Write(buffer, 0, read);
-                }
-            }
-        }
-
-        #region nested classes
-        public class PoolItem
-        {
-            public virtual void Print()
-            {
-
-            }
-        }
-
-        public class PoolUtf8 : PoolItem
-        {
-            public string Value = "";
-
-            public void readValue(byte[] data,ref int pointer , int length)
-            {
-                for (int i = 0; i < length; i++)
-                {
-                    int a =(int) data[pointer++];
-                    if ((a & 0x80) == 0)
-                    {
-                        Value = Value + (char)a;
-                    }
-                    else if ((a & 0x20) == 0)
-                    {
-                        int b = (int) data[pointer++];
-                        Value = Value + (char)(((a & 0x1f) << 6) + (b & 0x3f));      
-                    }
-                    else
-                    {
-                        int b = (int)data[pointer++];
-                        int c = (int)data[pointer++];
-                        Value = Value + (char)(((a & 0xf) << 12) + ((b & 0x3f) << 6) + (c & 0x3f));            
-                    }
-                }
-            }
-
-            public override void Print()
-            {
-               Console.WriteLine("Utf8 type: " + Value);
-            }
-        }
-
-        private class PoolInt : PoolItem
-        {
-
-        }
-
-        public class PoolClass : PoolItem
-        {
-            //public string name = "";
-            public ushort namePointer = 0;
-            private ClassRecord parent;
-            public PoolUtf8 Name;
-
-            public PoolClass(ClassRecord paren)
-            {
-                parent = paren;
-            }
-
-            public void readValue(byte[] data, ref int pointer)
-            {
-                namePointer = (ushort)((data[pointer++] << 8) + data[pointer++] );
-            }
-
-            public override void Print()
-            {
-                this.Name = ((PoolUtf8)this.parent._constantsPool[namePointer - 1]);
-                Console.Write("Class type: " + namePointer);
-                Console.WriteLine(" // " + ((PoolUtf8)this.parent._constantsPool[namePointer - 1]).Value);
-                
-            }
-        }
-
-        public class PoolMethodRef : PoolItem
-        {
-            public ushort classPointer = 0;
-            public ushort nameTypePointer = 0;
-            public PoolNamedType mNameType;
-            public PoolClass mClass;
-            private ClassRecord parent;
-
-            public PoolMethodRef(ClassRecord paren)
-            {
-                parent = paren;
-            }
-
-            public void readValue(byte[] data, ref int pointer)
-            {
-                classPointer = (ushort)((data[pointer++] << 8) + data[pointer++]);
-                nameTypePointer = (ushort)((data[pointer++] << 8) + data[pointer++]);
-            }
-
-            public override void Print()
-            {
-                this.mNameType = ((PoolNamedType)this.parent._constantsPool[nameTypePointer - 1]);
-                this.mClass = ((PoolClass)this.parent._constantsPool[classPointer - 1]);
-               Console.WriteLine("MethodRef type: " + classPointer + " , " + nameTypePointer); 
-            }
-        }
-
-        public class PoolNamedType : PoolItem
-        {
-            public ushort namePointer = 0;
-            public ushort typePointer = 0;
-            private ClassRecord parent;
-            public PoolUtf8 Name;
-            public PoolUtf8 Type;
-
-            public PoolNamedType(ClassRecord paren)
-            {
-                parent = paren;
-            }
-
-            public void readValue(byte[] data, ref int pointer)
-            {
-                namePointer = (ushort)((data[pointer++] << 8) + data[pointer++] );
-                typePointer = (ushort)((data[pointer++] << 8) + data[pointer++] );
-            }
-
-            public override void Print()
-            {
-                Name = ((PoolUtf8)this.parent._constantsPool[namePointer-1]);
-                Type = ((PoolUtf8)this.parent._constantsPool[typePointer-1]);
-                Console.Write("Named type: " + namePointer + " , " + typePointer );
-                Console.WriteLine(" // "+ ((PoolUtf8)this.parent._constantsPool[namePointer-1]).Value);
-            }
-        }
-
-        //***********************
-        public class MethodInfo
-        {
-            public ushort AccessFlags = 0;
-            public ushort NameIndex = 0;
-            public string Name = "";
-            public ushort DescriptorIndex = 0;
-            public ushort AttributeCount = 0;
-            public List<MethodAttribute> Attributes = new List<MethodAttribute>();
-            private ClassRecord parent;
-            public int CodePointer = 0;
- 
-            public MethodInfo(ClassRecord paren)
-            {
-                parent = paren;
-            }
-
-            public void AddMethodCode(MethodMemory memory)
-            {
-                Array.Copy(this.Attributes[0].Code, 0, memory.MethodBuffer, memory.NextMethodPC, this.Attributes[0].Code.Length);
-                memory.Methodcount++;
-                this.CodePointer = memory.NextMethodPC;
-                memory.NextMethodPC += this.Attributes[0].Code.Length;
-            }
-
-            public void ReadData(byte[] data, ref int pointer)
-            {
-                AccessFlags = (ushort)((data[pointer++] << 8) + data[pointer++]);
-                NameIndex = (ushort)((data[pointer++] << 8) + data[pointer++]);
-                DescriptorIndex = (ushort)((data[pointer++] << 8) + data[pointer++]);
-                AttributeCount = (ushort)((data[pointer++] << 8) + data[pointer++]);
-                for(int i =0; i< AttributeCount; i++)
-                {
-                    MethodAttribute attri = new MethodAttribute(this.parent);
-                    attri.ReadData(data, ref pointer);
-                    this.Attributes.Add(attri);
-                }
-            }
-
-            public void Print()
-            {
-               Console.WriteLine("Method Info Struct: ");
-              Console.WriteLine("AccessFlags: " + AccessFlags);
-              Console.WriteLine("NameIndex: " + NameIndex +" // "+ ((PoolUtf8)this.parent._constantsPool[NameIndex-1]).Value);
-              Console.WriteLine("DescriptorIndex: " + DescriptorIndex + " // "+ ((PoolUtf8)this.parent._constantsPool[DescriptorIndex-1]).Value);
-              Console.WriteLine("Attribute Count:" + AttributeCount);
-                for (int i = 0; i < AttributeCount; i++)
-                {
-                    this.Attributes[i].Print();
-                }
-            }
-
-            public class MethodAttribute
-            {
-                public ushort NameIndex = 0;
-                public string Name = "";
-                public Int32 Length = 0;
-                //for now only support code attribute
-                public ushort MaxStack = 0;
-                public ushort MaxLocals = 0;
-                public Int32 CodeLength = 0;
-                public byte[] Code;
-                public ushort ExceptionTableLength = 0;
-                public ushort SubAttributeCount = 0;
-                public List<SubAttribute> SubAttributes = new List<SubAttribute>();
-                private ClassRecord parent;
-
-                public MethodAttribute(ClassRecord paren)
-                {
-                    parent = paren;
-                }
-
-                public void ReadData(byte[] data, ref int pointer)
-                {
-                    NameIndex = (ushort)((data[pointer++] << 8) + data[pointer++]);
-                    Length = (Int32)((data[pointer++] << 24) + (data[pointer++] << 16) + (data[pointer++] << 8) + data[pointer++]);
-                    MaxStack = (ushort)((data[pointer++] << 8) + data[pointer++]);
-                    MaxLocals = (ushort)((data[pointer++] << 8) + data[pointer++]);
-                    CodeLength = (Int32)((data[pointer++] << 24) + (data[pointer++] << 16) + (data[pointer++] << 8) + data[pointer++]);
-                    Code = new byte[CodeLength];
-                    for (int i = 0; i < CodeLength; i++)
-                    {
-                        Code[i] = data[pointer++];
-                    }
-                    ExceptionTableLength = (ushort)((data[pointer++] << 8) + data[pointer++]);
-                    SubAttributeCount = (ushort)((data[pointer++] << 8) + data[pointer++]);
-                    for (int i = 0; i < SubAttributeCount; i++)
-                    {
-                        SubAttribute subAttri = new SubAttribute(this.parent);
-                        subAttri.ReadData(data, ref pointer);
-                        this.SubAttributes.Add(subAttri);
-                    }
-                }
-
-                public void Print()
-                {
-                   Console.WriteLine("Method Attribute: ");
-                 Console.WriteLine("Name Index: " + NameIndex + " // "+ ((PoolUtf8)this.parent._constantsPool[NameIndex-1]).Value);
-                  Console.WriteLine("Length: " + Length);
-                  Console.WriteLine("MaxStack: " + MaxStack);
-                  Console.WriteLine("MaxLocals: " + MaxLocals);
-                 Console.WriteLine("CodeLength: " + CodeLength);
-                    for (int i = 0; i < Code.Length; i++)
-                    {
-                        Console.WriteLine("OpCode #" + i + " is: " + Code[i]);
-                    }
-                    Console.WriteLine("SubAttributes: " + SubAttributeCount);
-                    for (int i = 0; i < SubAttributeCount; i++)
-                    {
-                        this.SubAttributes[i].Print();
-                    }
-                }
-
-                public class SubAttribute
-                {
-                    public ushort NameIndex = 0;
-                    public string Name = "";
-                    public Int32 Length = 0;
-                    public byte[] Data;
-                    private ClassRecord parent;
-
-                    public SubAttribute(ClassRecord paren)
-                    {
-                        parent = paren;
-                    }
-
-                    public void ReadData(byte[] data, ref int pointer)
-                    {
-                        NameIndex = (ushort)((data[pointer++] << 8) + data[pointer++]);
-                        Length = (Int32)((data[pointer++] << 24) + (data[pointer++] << 16) + (data[pointer++] << 8) + data[pointer++]);
-                        Data = new byte[Length];
-                        for (int i = 0; i < Length; i++)
-                        {
-                            Data[i] = data[pointer++];
-                        }
-                    }
-
-                    public void Print()
-                    {
-                        Console.WriteLine("SubAttribute: NameIndex: " + NameIndex + " // " + ((PoolUtf8)this.parent._constantsPool[NameIndex - 1]).Value);
-                    }
-
-                }
-            }
-
-        }
-        private class InterfaceInfo
-        {
-            public void ReadData(byte[] data, ref int i)
-            {
-
-            }
-        }
-        private class FieldInfo
-        {
-            public void ReadData(byte[] data, ref int i)
-            {
-
-            }
-        }
-        private class AttributeInfo
-        {
-            public void ReadData(byte[] data, ref int i)
-            {
-
-            }
-        }
-        #endregion
-
-    }
-}
+/*
+* Copyright (c) Contributors, http://www.openmetaverse.org/
+* See CONTRIBUTORS.TXT for a full list of copyright holders.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*     * Redistributions of source code must retain the above copyright
+*       notice, this list of conditions and the following disclaimer.
+*     * Redistributions in binary form must reproduce the above copyright
+*       notice, this list of conditions and the following disclaimer in the
+*       documentation and/or other materials provided with the distribution.
+*     * Neither the name of the OpenSim Project nor the
+*       names of its contributors may be used to endorse or promote products
+*       derived from this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
+* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
+* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+* 
+*/
+using System;
+using System.IO;
+using System.Collections.Generic;
+using System.Text;
+using OpenSim.Region.Scripting.EmbeddedJVM.Types;
+
+namespace OpenSim.Region.Scripting.EmbeddedJVM
+{
+    public class ClassRecord
+    {
+        private ushort _majorVersion;
+        private ushort _minorVersion;
+        private ushort _constantPoolCount;
+        private ushort _accessFlags;
+        private ushort _thisClass;
+        private ushort _supperClass;
+        private ushort _interfaceCount;
+        private ushort _fieldCount;
+        private ushort _methodCount;
+        //private ushort _attributeCount;
+        //private string _name;
+        public Dictionary<string, BaseType> StaticFields = new Dictionary<string, BaseType>();
+        public PoolClass mClass;
+
+        public List<PoolItem> _constantsPool = new List<PoolItem>();
+        private List<MethodInfo> _methodsList = new List<MethodInfo>();
+        private List<FieldInfo> _fieldList = new List<FieldInfo>();
+
+        public ClassRecord()
+        {
+
+        }
+
+        public ClassInstance CreateNewInstance()
+        {
+            return new ClassInstance();
+        }
+
+        public void LoadClassFromFile(string fileName)
+        {
+            Console.WriteLine("loading script " + fileName);
+            FileStream fs = File.OpenRead(fileName);
+            this.LoadClassFromBytes(ReadFully(fs));
+            fs.Close();
+        }
+
+        public void LoadClassFromBytes(byte[] data)
+        {
+            int i = 0;
+            i += 4;
+            _minorVersion = (ushort)((data[i++] << 8) + data[i++]  );
+            _majorVersion = (ushort)((data[i++] << 8) + data[i++]  );
+            _constantPoolCount = (ushort)((data[i++] << 8) + data[i++]  );
+           // Console.WriteLine("there should be " + _constantPoolCount + " items in the pool");
+            for (int count = 0; count < _constantPoolCount -1 ; count++)
+            {
+                //read in the constant pool
+                byte pooltype = data[i++];
+                //Console.WriteLine("#" +count +": new constant type = " +pooltype);
+                //Console.WriteLine("start position is: " + i);
+                switch (pooltype)
+                {
+                    case 1:  //Utf8
+                        ushort uLength = (ushort)((data[i++] << 8) + data[i++]  );
+
+                       // Console.WriteLine("new utf8 type, length is " + uLength);
+                        PoolUtf8 utf8 = new PoolUtf8();
+                        utf8.readValue(data, ref i, uLength);
+                        this._constantsPool.Add(utf8);
+                        break;
+                    case 3: //Int
+                        break;
+                    case 7: //Class
+                        PoolClass pClass = new PoolClass(this);
+                        pClass.readValue(data, ref i);
+                        this._constantsPool.Add(pClass);
+                        break;
+                    case 10: //Method
+                        PoolMethodRef pMeth = new PoolMethodRef(this);
+                        pMeth.readValue(data, ref i);
+                        this._constantsPool.Add(pMeth);
+                        break;
+                    case 12:  //NamedType
+                        PoolNamedType pNamed = new PoolNamedType(this);
+                        pNamed.readValue(data, ref i);
+                        this._constantsPool.Add(pNamed);
+                        break;
+                }
+            }
+
+            _accessFlags = (ushort)((data[i++] << 8) + data[i++]  );
+            _thisClass = (ushort)((data[i++] << 8) + data[i++]  );
+            _supperClass = (ushort)((data[i++] << 8) + data[i++]  );
+
+            if (this._constantsPool[this._thisClass - 1] is PoolClass)
+            {
+                this.mClass = ((PoolClass)this._constantsPool[this._thisClass - 1]);
+            }
+
+            _interfaceCount = (ushort)((data[i++] << 8) + data[i++]);
+            //should now read in the info for each interface
+            _fieldCount = (ushort)((data[i++] << 8) + data[i++]);
+            //should now read in the info for each field
+            _methodCount = (ushort)((data[i++] << 8) + data[i++]);
+            for (int count = 0; count < _methodCount; count++)
+            {
+                MethodInfo methInf = new MethodInfo(this);
+                methInf.ReadData(data, ref i);
+                this._methodsList.Add(methInf);
+            }
+        }
+
+        public void AddMethodsToMemory(MethodMemory memory)
+        {
+            for (int count = 0; count < _methodCount; count++)
+            {
+                this._methodsList[count].AddMethodCode(memory);
+            }
+        }
+
+        public bool StartMethod(Thread thread, string methodName)
+        {
+            for (int count = 0; count < _methodCount; count++)
+            {
+                if (this._constantsPool[this._methodsList[count].NameIndex-1] is PoolUtf8)
+                {
+                    if (((PoolUtf8)this._constantsPool[this._methodsList[count].NameIndex-1]).Value == methodName)
+                    {
+                        //Console.WriteLine("found method: " + ((PoolUtf8)this._constantsPool[this._methodsList[count].NameIndex - 1]).Value);
+                        thread.SetPC(this._methodsList[count].CodePointer);
+                        return true;
+                    }
+                }
+            }
+            return false;
+        }
+
+        public void PrintToConsole()
+        {
+            Console.WriteLine("Class File:");
+           Console.WriteLine("Major version: " + _majorVersion);
+           Console.WriteLine("Minor version: " + _minorVersion);
+            Console.WriteLine("Pool size: " + _constantPoolCount);
+
+            for (int i = 0; i < _constantsPool.Count; i++)
+            {
+                this._constantsPool[i].Print();
+            }
+
+           Console.WriteLine("Access flags: " + _accessFlags);
+           Console.WriteLine("This class: " + _thisClass );
+           Console.WriteLine("Super class: " + _supperClass);
+
+            for (int count = 0; count < _methodCount; count++)
+            {
+                Console.WriteLine();
+                this._methodsList[count].Print();
+            }
+
+           Console.WriteLine("class name is " + this.mClass.Name.Value);
+        }
+
+        public static byte[] ReadFully(Stream stream)
+        {
+            byte[] buffer = new byte[1024];
+            using (MemoryStream ms = new MemoryStream())
+            {
+                while (true)
+                {
+                    int read = stream.Read(buffer, 0, buffer.Length);
+                    if (read <= 0)
+                        return ms.ToArray();
+                    ms.Write(buffer, 0, read);
+                }
+            }
+        }
+
+        #region nested classes
+        public class PoolItem
+        {
+            public virtual void Print()
+            {
+
+            }
+        }
+
+        public class PoolUtf8 : PoolItem
+        {
+            public string Value = "";
+
+            public void readValue(byte[] data,ref int pointer , int length)
+            {
+                for (int i = 0; i < length; i++)
+                {
+                    int a =(int) data[pointer++];
+                    if ((a & 0x80) == 0)
+                    {
+                        Value = Value + (char)a;
+                    }
+                    else if ((a & 0x20) == 0)
+                    {
+                        int b = (int) data[pointer++];
+                        Value = Value + (char)(((a & 0x1f) << 6) + (b & 0x3f));      
+                    }
+                    else
+                    {
+                        int b = (int)data[pointer++];
+                        int c = (int)data[pointer++];
+                        Value = Value + (char)(((a & 0xf) << 12) + ((b & 0x3f) << 6) + (c & 0x3f));            
+                    }
+                }
+            }
+
+            public override void Print()
+            {
+               Console.WriteLine("Utf8 type: " + Value);
+            }
+        }
+
+        private class PoolInt : PoolItem
+        {
+
+        }
+
+        public class PoolClass : PoolItem
+        {
+            //public string name = "";
+            public ushort namePointer = 0;
+            private ClassRecord parent;
+            public PoolUtf8 Name;
+
+            public PoolClass(ClassRecord paren)
+            {
+                parent = paren;
+            }
+
+            public void readValue(byte[] data, ref int pointer)
+            {
+                namePointer = (ushort)((data[pointer++] << 8) + data[pointer++] );
+            }
+
+            public override void Print()
+            {
+                this.Name = ((PoolUtf8)this.parent._constantsPool[namePointer - 1]);
+                Console.Write("Class type: " + namePointer);
+                Console.WriteLine(" // " + ((PoolUtf8)this.parent._constantsPool[namePointer - 1]).Value);
+                
+            }
+        }
+
+        public class PoolMethodRef : PoolItem
+        {
+            public ushort classPointer = 0;
+            public ushort nameTypePointer = 0;
+            public PoolNamedType mNameType;
+            public PoolClass mClass;
+            private ClassRecord parent;
+
+            public PoolMethodRef(ClassRecord paren)
+            {
+                parent = paren;
+            }
+
+            public void readValue(byte[] data, ref int pointer)
+            {
+                classPointer = (ushort)((data[pointer++] << 8) + data[pointer++]);
+                nameTypePointer = (ushort)((data[pointer++] << 8) + data[pointer++]);
+            }
+
+            public override void Print()
+            {
+                this.mNameType = ((PoolNamedType)this.parent._constantsPool[nameTypePointer - 1]);
+                this.mClass = ((PoolClass)this.parent._constantsPool[classPointer - 1]);
+               Console.WriteLine("MethodRef type: " + classPointer + " , " + nameTypePointer); 
+            }
+        }
+
+        public class PoolNamedType : PoolItem
+        {
+            public ushort namePointer = 0;
+            public ushort typePointer = 0;
+            private ClassRecord parent;
+            public PoolUtf8 Name;
+            public PoolUtf8 Type;
+
+            public PoolNamedType(ClassRecord paren)
+            {
+                parent = paren;
+            }
+
+            public void readValue(byte[] data, ref int pointer)
+            {
+                namePointer = (ushort)((data[pointer++] << 8) + data[pointer++] );
+                typePointer = (ushort)((data[pointer++] << 8) + data[pointer++] );
+            }
+
+            public override void Print()
+            {
+                Name = ((PoolUtf8)this.parent._constantsPool[namePointer-1]);
+                Type = ((PoolUtf8)this.parent._constantsPool[typePointer-1]);
+                Console.Write("Named type: " + namePointer + " , " + typePointer );
+                Console.WriteLine(" // "+ ((PoolUtf8)this.parent._constantsPool[namePointer-1]).Value);
+            }
+        }
+
+        //***********************
+        public class MethodInfo
+        {
+            public ushort AccessFlags = 0;
+            public ushort NameIndex = 0;
+            public string Name = "";
+            public ushort DescriptorIndex = 0;
+            public ushort AttributeCount = 0;
+            public List<MethodAttribute> Attributes = new List<MethodAttribute>();
+            private ClassRecord parent;
+            public int CodePointer = 0;
+ 
+            public MethodInfo(ClassRecord paren)
+            {
+                parent = paren;
+            }
+
+            public void AddMethodCode(MethodMemory memory)
+            {
+                Array.Copy(this.Attributes[0].Code, 0, memory.MethodBuffer, memory.NextMethodPC, this.Attributes[0].Code.Length);
+                memory.Methodcount++;
+                this.CodePointer = memory.NextMethodPC;
+                memory.NextMethodPC += this.Attributes[0].Code.Length;
+            }
+
+            public void ReadData(byte[] data, ref int pointer)
+            {
+                AccessFlags = (ushort)((data[pointer++] << 8) + data[pointer++]);
+                NameIndex = (ushort)((data[pointer++] << 8) + data[pointer++]);
+                DescriptorIndex = (ushort)((data[pointer++] << 8) + data[pointer++]);
+                AttributeCount = (ushort)((data[pointer++] << 8) + data[pointer++]);
+                for(int i =0; i< AttributeCount; i++)
+                {
+                    MethodAttribute attri = new MethodAttribute(this.parent);
+                    attri.ReadData(data, ref pointer);
+                    this.Attributes.Add(attri);
+                }
+            }
+
+            public void Print()
+            {
+               Console.WriteLine("Method Info Struct: ");
+              Console.WriteLine("AccessFlags: " + AccessFlags);
+              Console.WriteLine("NameIndex: " + NameIndex +" // "+ ((PoolUtf8)this.parent._constantsPool[NameIndex-1]).Value);
+              Console.WriteLine("DescriptorIndex: " + DescriptorIndex + " // "+ ((PoolUtf8)this.parent._constantsPool[DescriptorIndex-1]).Value);
+              Console.WriteLine("Attribute Count:" + AttributeCount);
+                for (int i = 0; i < AttributeCount; i++)
+                {
+                    this.Attributes[i].Print();
+                }
+            }
+
+            public class MethodAttribute
+            {
+                public ushort NameIndex = 0;
+                public string Name = "";
+                public Int32 Length = 0;
+                //for now only support code attribute
+                public ushort MaxStack = 0;
+                public ushort MaxLocals = 0;
+                public Int32 CodeLength = 0;
+                public byte[] Code;
+                public ushort ExceptionTableLength = 0;
+                public ushort SubAttributeCount = 0;
+                public List<SubAttribute> SubAttributes = new List<SubAttribute>();
+                private ClassRecord parent;
+
+                public MethodAttribute(ClassRecord paren)
+                {
+                    parent = paren;
+                }
+
+                public void ReadData(byte[] data, ref int pointer)
+                {
+                    NameIndex = (ushort)((data[pointer++] << 8) + data[pointer++]);
+                    Length = (Int32)((data[pointer++] << 24) + (data[pointer++] << 16) + (data[pointer++] << 8) + data[pointer++]);
+                    MaxStack = (ushort)((data[pointer++] << 8) + data[pointer++]);
+                    MaxLocals = (ushort)((data[pointer++] << 8) + data[pointer++]);
+                    CodeLength = (Int32)((data[pointer++] << 24) + (data[pointer++] << 16) + (data[pointer++] << 8) + data[pointer++]);
+                    Code = new byte[CodeLength];
+                    for (int i = 0; i < CodeLength; i++)
+                    {
+                        Code[i] = data[pointer++];
+                    }
+                    ExceptionTableLength = (ushort)((data[pointer++] << 8) + data[pointer++]);
+                    SubAttributeCount = (ushort)((data[pointer++] << 8) + data[pointer++]);
+                    for (int i = 0; i < SubAttributeCount; i++)
+                    {
+                        SubAttribute subAttri = new SubAttribute(this.parent);
+                        subAttri.ReadData(data, ref pointer);
+                        this.SubAttributes.Add(subAttri);
+                    }
+                }
+
+                public void Print()
+                {
+                   Console.WriteLine("Method Attribute: ");
+                 Console.WriteLine("Name Index: " + NameIndex + " // "+ ((PoolUtf8)this.parent._constantsPool[NameIndex-1]).Value);
+                  Console.WriteLine("Length: " + Length);
+                  Console.WriteLine("MaxStack: " + MaxStack);
+                  Console.WriteLine("MaxLocals: " + MaxLocals);
+                 Console.WriteLine("CodeLength: " + CodeLength);
+                    for (int i = 0; i < Code.Length; i++)
+                    {
+                        Console.WriteLine("OpCode #" + i + " is: " + Code[i]);
+                    }
+                    Console.WriteLine("SubAttributes: " + SubAttributeCount);
+                    for (int i = 0; i < SubAttributeCount; i++)
+                    {
+                        this.SubAttributes[i].Print();
+                    }
+                }
+
+                public class SubAttribute
+                {
+                    public ushort NameIndex = 0;
+                    public string Name = "";
+                    public Int32 Length = 0;
+                    public byte[] Data;
+                    private ClassRecord parent;
+
+                    public SubAttribute(ClassRecord paren)
+                    {
+                        parent = paren;
+                    }
+
+                    public void ReadData(byte[] data, ref int pointer)
+                    {
+                        NameIndex = (ushort)((data[pointer++] << 8) + data[pointer++]);
+                        Length = (Int32)((data[pointer++] << 24) + (data[pointer++] << 16) + (data[pointer++] << 8) + data[pointer++]);
+                        Data = new byte[Length];
+                        for (int i = 0; i < Length; i++)
+                        {
+                            Data[i] = data[pointer++];
+                        }
+                    }
+
+                    public void Print()
+                    {
+                        Console.WriteLine("SubAttribute: NameIndex: " + NameIndex + " // " + ((PoolUtf8)this.parent._constantsPool[NameIndex - 1]).Value);
+                    }
+
+                }
+            }
+
+        }
+        private class InterfaceInfo
+        {
+            public void ReadData(byte[] data, ref int i)
+            {
+
+            }
+        }
+        private class FieldInfo
+        {
+            public void ReadData(byte[] data, ref int i)
+            {
+
+            }
+        }
+        private class AttributeInfo
+        {
+            public void ReadData(byte[] data, ref int i)
+            {
+
+            }
+        }
+        #endregion
+
+    }
+}
diff --git a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/JVM/Heap.cs b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/JVM/Heap.cs
index 1a97b7d..c6423fc 100644
--- a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/JVM/Heap.cs
+++ b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/JVM/Heap.cs
@@ -1,43 +1,43 @@
-/*
-* Copyright (c) Contributors, http://www.openmetaverse.org/
-* See CONTRIBUTORS.TXT for a full list of copyright holders.
-*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted provided that the following conditions are met:
-*     * Redistributions of source code must retain the above copyright
-*       notice, this list of conditions and the following disclaimer.
-*     * Redistributions in binary form must reproduce the above copyright
-*       notice, this list of conditions and the following disclaimer in the
-*       documentation and/or other materials provided with the distribution.
-*     * Neither the name of the OpenSim Project nor the
-*       names of its contributors may be used to endorse or promote products
-*       derived from this software without specific prior written permission.
-*
-* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
-* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
-* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-* 
-*/
-using System;
-using System.Collections.Generic;
-using System.Text;
-
-namespace OpenSim.Region.Scripting.EmbeddedJVM
-{
-    public class Heap
-    {
-        public List<ClassInstance> ClassObjects = new List<ClassInstance>();
-
-        public Heap()
-        {
-
-        }
-    }
-}
+/*
+* Copyright (c) Contributors, http://www.openmetaverse.org/
+* See CONTRIBUTORS.TXT for a full list of copyright holders.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*     * Redistributions of source code must retain the above copyright
+*       notice, this list of conditions and the following disclaimer.
+*     * Redistributions in binary form must reproduce the above copyright
+*       notice, this list of conditions and the following disclaimer in the
+*       documentation and/or other materials provided with the distribution.
+*     * Neither the name of the OpenSim Project nor the
+*       names of its contributors may be used to endorse or promote products
+*       derived from this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
+* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
+* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+* 
+*/
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace OpenSim.Region.Scripting.EmbeddedJVM
+{
+    public class Heap
+    {
+        public List<ClassInstance> ClassObjects = new List<ClassInstance>();
+
+        public Heap()
+        {
+
+        }
+    }
+}
diff --git a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/JVM/Interpreter.Logic.cs b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/JVM/Interpreter.Logic.cs
index ef6b805..56135d3 100644
--- a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/JVM/Interpreter.Logic.cs
+++ b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/JVM/Interpreter.Logic.cs
@@ -1,427 +1,427 @@
-/*
-* Copyright (c) Contributors, http://www.openmetaverse.org/
-* See CONTRIBUTORS.TXT for a full list of copyright holders.
-*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted provided that the following conditions are met:
-*     * Redistributions of source code must retain the above copyright
-*       notice, this list of conditions and the following disclaimer.
-*     * Redistributions in binary form must reproduce the above copyright
-*       notice, this list of conditions and the following disclaimer in the
-*       documentation and/or other materials provided with the distribution.
-*     * Neither the name of the OpenSim Project nor the
-*       names of its contributors may be used to endorse or promote products
-*       derived from this software without specific prior written permission.
-*
-* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
-* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
-* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-* 
-*/
-using System;
-using System.Collections.Generic;
-using System.Text;
-using OpenSim.Region.Scripting.EmbeddedJVM.Types;
-using OpenSim.Region.Scripting.EmbeddedJVM.Types.PrimitiveTypes;
-
-namespace OpenSim.Region.Scripting.EmbeddedJVM
-{
-    partial class Thread
-    {
-        private partial class Interpreter
-        {
-            private bool IsLogicOpCode(byte opcode)
-            {
-                bool result = false;
-                switch (opcode)
-                {
-                    case 2:
-                        Int m_int= new Int();
-                        m_int.mValue = -1;
-                        this._mThread.currentFrame.OpStack.Push(m_int);
-                        result = true;
-                        break;
-                    case 3:
-                        m_int= new Int();
-                        m_int.mValue = 0;
-                        this._mThread.currentFrame.OpStack.Push(m_int);
-                        result = true;
-                        break;
-                    case 4:
-                        m_int = new Int();
-                        m_int.mValue = 1;
-                        this._mThread.currentFrame.OpStack.Push(m_int);
-                        result = true;
-                        break;
-                    case 5:
-                        m_int = new Int();
-                        m_int.mValue = 2;
-                        this._mThread.currentFrame.OpStack.Push(m_int);
-                        result = true;
-                        break;
-                    case 6:
-                        m_int = new Int();
-                        m_int.mValue = 3;
-                        this._mThread.currentFrame.OpStack.Push(m_int);
-                        break;
-                    case 7:
-                        m_int = new Int();
-                        m_int.mValue = 4;
-                        this._mThread.currentFrame.OpStack.Push(m_int);
-                        result = true;
-                        break;
-                    case 8:
-                        m_int = new Int();
-                        m_int.mValue = 5;
-                        this._mThread.currentFrame.OpStack.Push(m_int);
-                        result = true;
-                        break;
-                    case 11:
-                        Float m_float = new Float();
-                        m_float.mValue = 0.0f;
-                        this._mThread.currentFrame.OpStack.Push(m_float);
-                        result = true;
-                        break;
-                    case 12:
-                        m_float = new Float();
-                        m_float.mValue = 1.0f;
-                        this._mThread.currentFrame.OpStack.Push(m_float);
-                        result = true;
-                        break;
-                    case 13:
-                        m_float = new Float();
-                        m_float.mValue = 2.0f;
-                        this._mThread.currentFrame.OpStack.Push(m_float);
-                        result = true;
-                        break;
-                    case 16:
-                        int pushvalue = (int)GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC];
-                        Int pushInt = new Int();
-                        pushInt.mValue = pushvalue;
-                        this._mThread.currentFrame.OpStack.Push(pushInt);
-                        this._mThread.PC++;
-                        result = true;
-                        break;
-                    case 17:
-                        short pushvalue2 = (short)((GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC] << 8) + GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC + 1]);
-                        Int pushInt2 = new Int();
-                        pushInt2.mValue = pushvalue2;
-                        this._mThread.currentFrame.OpStack.Push(pushInt2);
-                        this._mThread.PC += 2;
-                        result = true;
-                        break;
-                    case 23:
-                        short findex1 = (short)((GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC]));
-                        Float fload = new Float();
-                        if (this._mThread.currentFrame.LocalVariables[findex1] != null)
-                        {
-                            if (this._mThread.currentFrame.LocalVariables[findex1] is Float)
-                            {
-                                fload.mValue = ((Float)this._mThread.currentFrame.LocalVariables[findex1]).mValue;
-                                this._mThread.currentFrame.OpStack.Push(fload);
-                            }
-                        }
-                        this._mThread.PC++;
-                        result = true;
-                        break;
-                    case 26:
-                        if (this._mThread.currentFrame.LocalVariables[0] != null)
-                        {
-                            if (this._mThread.currentFrame.LocalVariables[0] is Int)
-                            {
-                                Int newInt = new Int();
-                                newInt.mValue = ((Int)this._mThread.currentFrame.LocalVariables[0]).mValue;
-                                this._mThread.currentFrame.OpStack.Push(newInt);
-                            }
-                        }
-                        result = true;
-                        break;
-                    case 27:
-                        if (this._mThread.currentFrame.LocalVariables[1] != null)
-                        {
-                            if (this._mThread.currentFrame.LocalVariables[1] is Int)
-                            {
-                                Int newInt = new Int();
-                                newInt.mValue = ((Int)this._mThread.currentFrame.LocalVariables[1]).mValue;
-                                this._mThread.currentFrame.OpStack.Push(newInt);
-                            }
-                        }
-                        result = true;
-                        break;
-                    case 34:
-                        if (this._mThread.currentFrame.LocalVariables[0] != null)
-                        {
-                            if (this._mThread.currentFrame.LocalVariables[0] is Float)
-                            {
-                                Float newfloat = new Float();
-                                newfloat.mValue = ((Float)this._mThread.currentFrame.LocalVariables[0]).mValue;
-                                this._mThread.currentFrame.OpStack.Push(newfloat);
-                            }
-                        }
-                        result = true;
-                        break;
-                    case 35:
-                        if (this._mThread.currentFrame.LocalVariables[1] != null)
-                        {
-                            if (this._mThread.currentFrame.LocalVariables[1] is Float)
-                            {
-                                Float newfloat = new Float();
-                                newfloat.mValue = ((Float)this._mThread.currentFrame.LocalVariables[1]).mValue;
-                                this._mThread.currentFrame.OpStack.Push(newfloat);
-                            }
-                        }
-                        result = true;
-                        break;
-                    case 36:
-                        if (this._mThread.currentFrame.LocalVariables[2] != null)
-                        {
-                            if (this._mThread.currentFrame.LocalVariables[2] is Float)
-                            {
-                                Float newfloat = new Float();
-                                newfloat.mValue = ((Float)this._mThread.currentFrame.LocalVariables[2]).mValue;
-                                this._mThread.currentFrame.OpStack.Push(newfloat);
-                            }
-                        }
-                        result = true;
-                        break;
-                    case 37:
-                        if (this._mThread.currentFrame.LocalVariables[3] != null)
-                        {
-                            if (this._mThread.currentFrame.LocalVariables[3] is Float)
-                            {
-                                Float newfloat = new Float();
-                                newfloat.mValue = ((Float)this._mThread.currentFrame.LocalVariables[3]).mValue;
-                                this._mThread.currentFrame.OpStack.Push(newfloat);
-                            }
-                        }
-                        result = true;
-                        break;
-                    case 56:
-                        short findex = (short)((GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC] ));
-                        BaseType fstor = this._mThread.currentFrame.OpStack.Pop();
-                        if (fstor is Float)
-                        {
-                            this._mThread.currentFrame.LocalVariables[findex] = (Float)fstor;
-                        }
-                        this._mThread.PC++;
-                        result = true;
-                        break;
-                    case 59:
-                        BaseType baset = this._mThread.currentFrame.OpStack.Pop();
-                        if (baset is Int)
-                        {
-                            this._mThread.currentFrame.LocalVariables[0] = (Int)baset;
-                        }
-                        result = true;
-                        break;
-                    case 60:
-                        baset = this._mThread.currentFrame.OpStack.Pop();
-                        if (baset is Int)
-                        {
-                            this._mThread.currentFrame.LocalVariables[1] = (Int)baset;
-                        }
-                        result = true;
-                        break;
-                    case 67:
-                        baset = this._mThread.currentFrame.OpStack.Pop();
-                        if (baset is Float)
-                        {
-                            this._mThread.currentFrame.LocalVariables[0] = (Float)baset;
-                        }
-                        result = true;
-                        break;
-                    case 68:
-                        baset = this._mThread.currentFrame.OpStack.Pop();
-                        if (baset is Float)
-                        {
-                            this._mThread.currentFrame.LocalVariables[1] = (Float)baset;
-                        }
-                        result = true;
-                        break;
-                    case 69:
-                        baset = this._mThread.currentFrame.OpStack.Pop();
-                        if (baset is Float)
-                        {
-                            this._mThread.currentFrame.LocalVariables[2] = (Float)baset;
-                        }
-                        result = true;
-                        break;
-                    case 70:
-                        baset = this._mThread.currentFrame.OpStack.Pop();
-                        if (baset is Float)
-                        {
-                            this._mThread.currentFrame.LocalVariables[3] = (Float)baset;
-                        }
-                        result = true;
-                        break;
-                    case 87:
-                        this._mThread.currentFrame.OpStack.Pop();
-                        result = true;
-                        break;
-                    case 98:
-                        BaseType bf2 = this._mThread.currentFrame.OpStack.Pop();
-                        BaseType bf1 = this._mThread.currentFrame.OpStack.Pop();
-                        if (bf1 is Float && bf2 is Float)
-                        {
-                            Float nflt = new Float();
-                            nflt.mValue = ((Float)bf1).mValue + ((Float)bf2).mValue;
-                            this._mThread.currentFrame.OpStack.Push(nflt);
-                        }
-                        result = true;
-                        break;
-                    case 102:
-                        BaseType bsf2 = this._mThread.currentFrame.OpStack.Pop();
-                        BaseType bsf1 = this._mThread.currentFrame.OpStack.Pop();
-                        if (bsf1 is Float && bsf2 is Float)
-                        {
-                            Float resf = new Float();
-                            resf.mValue = ((Float)bsf1).mValue - ((Float)bsf2).mValue;
-                            this._mThread.currentFrame.OpStack.Push(resf);
-                        }
-                        result = true;
-                        break;
-                    case 104: //check the order of the two values off the stack is correct
-                        BaseType bs2 = this._mThread.currentFrame.OpStack.Pop();
-                        BaseType bs1 = this._mThread.currentFrame.OpStack.Pop();
-                        if (bs1 is Int && bs2 is Int)
-                        {
-                            Int nInt = new Int();
-                            nInt.mValue = ((Int)bs1).mValue * ((Int)bs2).mValue;
-                            this._mThread.currentFrame.OpStack.Push(nInt);
-                        }
-                        result = true;
-                        break;
-                    case 132:
-                        if (this._mThread.currentFrame.LocalVariables[GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC]] != null)
-                        {
-                            if (this._mThread.currentFrame.LocalVariables[GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC]] is Int)
-                            {
-                                ((Int)this._mThread.currentFrame.LocalVariables[GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC]]).mValue += (sbyte) GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC + 1];
-                            }
-                        }
-                        this._mThread.PC += 2;
-                        result = true;
-                        break;
-                    case 139:
-                        BaseType conv1 = this._mThread.currentFrame.OpStack.Pop();
-                        if (conv1 is Float)
-                        {
-                            Int newconv = new Int();
-                            newconv.mValue = (int)((Float)conv1).mValue;
-                            this._mThread.currentFrame.OpStack.Push(newconv);
-                        }
-                        result = true;
-                        break;
-                    case 149:
-                        BaseType flcom2 = this._mThread.currentFrame.OpStack.Pop();
-                        BaseType flcom1 = this._mThread.currentFrame.OpStack.Pop();
-                        if (flcom1 is Float && flcom2 is Float)
-                        {
-                            Int compres = new Int();
-                            if (((Float)flcom1).mValue < ((Float)flcom2).mValue)
-                            {
-                                compres.mValue = -1;
-                            }
-                            else if (((Float)flcom1).mValue > ((Float)flcom2).mValue)
-                            {
-                                compres.mValue = 1;
-                            }
-                            else
-                            {
-                                compres.mValue = 0;
-                            }
-                            this._mThread.currentFrame.OpStack.Push(compres);
-                        }
-                        result = true;
-                        break;
-                    case 158:
-                        short compareoffset1 = (short)((GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC] << 8) + GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC + 1]);
-                        BaseType comp1 = this._mThread.currentFrame.OpStack.Pop();
-                        if (comp1 is Int)
-                        {
-                            if (((Int)comp1).mValue <= 0)
-                            {
-                                this._mThread.PC += -1 + compareoffset1;
-                            }
-                            else
-                            {
-                                this._mThread.PC += 2;
-                            }
-                        }
-                        else
-                        {
-                            this._mThread.PC += 2;
-                        }
-                        result = true;
-                        break;
-                    case 162:
-                        short compareoffset = (short)((GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC] << 8) + GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC + 1]);
-                        BaseType bc2 = this._mThread.currentFrame.OpStack.Pop();
-                        BaseType bc1 = this._mThread.currentFrame.OpStack.Pop();
-                        if (bc1 is Int && bc2 is Int)
-                        {
-                            //Console.WriteLine("comparing " + ((Int)bc1).mValue + " and " + ((Int)bc2).mValue);
-                            if (((Int)bc1).mValue >= ((Int)bc2).mValue)
-                            {
-                               // Console.WriteLine("branch compare true , offset is " +compareoffset);
-                               // Console.WriteLine("current PC is " + this._mThread.PC);
-                                this._mThread.PC += -1 + compareoffset;
-                                //Console.WriteLine("new PC is " + this._mThread.PC);
-                            }
-                            else
-                            {
-                                //Console.WriteLine("branch compare false");
-                                this._mThread.PC += 2;
-                            }
-                        }
-                        else
-                        {
-                            this._mThread.PC += 2;
-                        }
-                        result = true;
-                        break;
-                    case 164:
-                        short compareloffset = (short)((GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC] << 8) + GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC + 1]);
-                        BaseType bcl2 = this._mThread.currentFrame.OpStack.Pop();
-                        BaseType bcl1 = this._mThread.currentFrame.OpStack.Pop();
-                        if (bcl1 is Int && bcl2 is Int)
-                        {
-                            //Console.WriteLine("comparing " + ((Int)bcl1).mValue + " and " + ((Int)bcl2).mValue);
-                            if (((Int)bcl1).mValue <= ((Int)bcl2).mValue)
-                            {
-                              // Console.WriteLine("branch compare true , offset is " + compareloffset);
-                              // Console.WriteLine("current PC is " + this._mThread.PC);
-                               this._mThread.PC += -1 + compareloffset;
-                              // Console.WriteLine("new PC is " + this._mThread.PC);
-                            }
-                            else
-                            {
-                                //Console.WriteLine("branch compare false");
-                                this._mThread.PC += 2;
-                            }
-                        }
-                        else
-                        {
-                            this._mThread.PC += 2;
-                        }
-                        result = true;
-                        break;
-                    case 167:
-                        short offset = (short)((GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC] << 8) + GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC+1]);
-                        this._mThread.PC += -1 + offset;
-                        result = true;
-                        break;
-                }
-
-                return result;
-            }
-        }
-    }
-}
+/*
+* Copyright (c) Contributors, http://www.openmetaverse.org/
+* See CONTRIBUTORS.TXT for a full list of copyright holders.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*     * Redistributions of source code must retain the above copyright
+*       notice, this list of conditions and the following disclaimer.
+*     * Redistributions in binary form must reproduce the above copyright
+*       notice, this list of conditions and the following disclaimer in the
+*       documentation and/or other materials provided with the distribution.
+*     * Neither the name of the OpenSim Project nor the
+*       names of its contributors may be used to endorse or promote products
+*       derived from this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
+* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
+* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+* 
+*/
+using System;
+using System.Collections.Generic;
+using System.Text;
+using OpenSim.Region.Scripting.EmbeddedJVM.Types;
+using OpenSim.Region.Scripting.EmbeddedJVM.Types.PrimitiveTypes;
+
+namespace OpenSim.Region.Scripting.EmbeddedJVM
+{
+    partial class Thread
+    {
+        private partial class Interpreter
+        {
+            private bool IsLogicOpCode(byte opcode)
+            {
+                bool result = false;
+                switch (opcode)
+                {
+                    case 2:
+                        Int m_int= new Int();
+                        m_int.mValue = -1;
+                        this._mThread.currentFrame.OpStack.Push(m_int);
+                        result = true;
+                        break;
+                    case 3:
+                        m_int= new Int();
+                        m_int.mValue = 0;
+                        this._mThread.currentFrame.OpStack.Push(m_int);
+                        result = true;
+                        break;
+                    case 4:
+                        m_int = new Int();
+                        m_int.mValue = 1;
+                        this._mThread.currentFrame.OpStack.Push(m_int);
+                        result = true;
+                        break;
+                    case 5:
+                        m_int = new Int();
+                        m_int.mValue = 2;
+                        this._mThread.currentFrame.OpStack.Push(m_int);
+                        result = true;
+                        break;
+                    case 6:
+                        m_int = new Int();
+                        m_int.mValue = 3;
+                        this._mThread.currentFrame.OpStack.Push(m_int);
+                        break;
+                    case 7:
+                        m_int = new Int();
+                        m_int.mValue = 4;
+                        this._mThread.currentFrame.OpStack.Push(m_int);
+                        result = true;
+                        break;
+                    case 8:
+                        m_int = new Int();
+                        m_int.mValue = 5;
+                        this._mThread.currentFrame.OpStack.Push(m_int);
+                        result = true;
+                        break;
+                    case 11:
+                        Float m_float = new Float();
+                        m_float.mValue = 0.0f;
+                        this._mThread.currentFrame.OpStack.Push(m_float);
+                        result = true;
+                        break;
+                    case 12:
+                        m_float = new Float();
+                        m_float.mValue = 1.0f;
+                        this._mThread.currentFrame.OpStack.Push(m_float);
+                        result = true;
+                        break;
+                    case 13:
+                        m_float = new Float();
+                        m_float.mValue = 2.0f;
+                        this._mThread.currentFrame.OpStack.Push(m_float);
+                        result = true;
+                        break;
+                    case 16:
+                        int pushvalue = (int)GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC];
+                        Int pushInt = new Int();
+                        pushInt.mValue = pushvalue;
+                        this._mThread.currentFrame.OpStack.Push(pushInt);
+                        this._mThread.PC++;
+                        result = true;
+                        break;
+                    case 17:
+                        short pushvalue2 = (short)((GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC] << 8) + GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC + 1]);
+                        Int pushInt2 = new Int();
+                        pushInt2.mValue = pushvalue2;
+                        this._mThread.currentFrame.OpStack.Push(pushInt2);
+                        this._mThread.PC += 2;
+                        result = true;
+                        break;
+                    case 23:
+                        short findex1 = (short)((GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC]));
+                        Float fload = new Float();
+                        if (this._mThread.currentFrame.LocalVariables[findex1] != null)
+                        {
+                            if (this._mThread.currentFrame.LocalVariables[findex1] is Float)
+                            {
+                                fload.mValue = ((Float)this._mThread.currentFrame.LocalVariables[findex1]).mValue;
+                                this._mThread.currentFrame.OpStack.Push(fload);
+                            }
+                        }
+                        this._mThread.PC++;
+                        result = true;
+                        break;
+                    case 26:
+                        if (this._mThread.currentFrame.LocalVariables[0] != null)
+                        {
+                            if (this._mThread.currentFrame.LocalVariables[0] is Int)
+                            {
+                                Int newInt = new Int();
+                                newInt.mValue = ((Int)this._mThread.currentFrame.LocalVariables[0]).mValue;
+                                this._mThread.currentFrame.OpStack.Push(newInt);
+                            }
+                        }
+                        result = true;
+                        break;
+                    case 27:
+                        if (this._mThread.currentFrame.LocalVariables[1] != null)
+                        {
+                            if (this._mThread.currentFrame.LocalVariables[1] is Int)
+                            {
+                                Int newInt = new Int();
+                                newInt.mValue = ((Int)this._mThread.currentFrame.LocalVariables[1]).mValue;
+                                this._mThread.currentFrame.OpStack.Push(newInt);
+                            }
+                        }
+                        result = true;
+                        break;
+                    case 34:
+                        if (this._mThread.currentFrame.LocalVariables[0] != null)
+                        {
+                            if (this._mThread.currentFrame.LocalVariables[0] is Float)
+                            {
+                                Float newfloat = new Float();
+                                newfloat.mValue = ((Float)this._mThread.currentFrame.LocalVariables[0]).mValue;
+                                this._mThread.currentFrame.OpStack.Push(newfloat);
+                            }
+                        }
+                        result = true;
+                        break;
+                    case 35:
+                        if (this._mThread.currentFrame.LocalVariables[1] != null)
+                        {
+                            if (this._mThread.currentFrame.LocalVariables[1] is Float)
+                            {
+                                Float newfloat = new Float();
+                                newfloat.mValue = ((Float)this._mThread.currentFrame.LocalVariables[1]).mValue;
+                                this._mThread.currentFrame.OpStack.Push(newfloat);
+                            }
+                        }
+                        result = true;
+                        break;
+                    case 36:
+                        if (this._mThread.currentFrame.LocalVariables[2] != null)
+                        {
+                            if (this._mThread.currentFrame.LocalVariables[2] is Float)
+                            {
+                                Float newfloat = new Float();
+                                newfloat.mValue = ((Float)this._mThread.currentFrame.LocalVariables[2]).mValue;
+                                this._mThread.currentFrame.OpStack.Push(newfloat);
+                            }
+                        }
+                        result = true;
+                        break;
+                    case 37:
+                        if (this._mThread.currentFrame.LocalVariables[3] != null)
+                        {
+                            if (this._mThread.currentFrame.LocalVariables[3] is Float)
+                            {
+                                Float newfloat = new Float();
+                                newfloat.mValue = ((Float)this._mThread.currentFrame.LocalVariables[3]).mValue;
+                                this._mThread.currentFrame.OpStack.Push(newfloat);
+                            }
+                        }
+                        result = true;
+                        break;
+                    case 56:
+                        short findex = (short)((GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC] ));
+                        BaseType fstor = this._mThread.currentFrame.OpStack.Pop();
+                        if (fstor is Float)
+                        {
+                            this._mThread.currentFrame.LocalVariables[findex] = (Float)fstor;
+                        }
+                        this._mThread.PC++;
+                        result = true;
+                        break;
+                    case 59:
+                        BaseType baset = this._mThread.currentFrame.OpStack.Pop();
+                        if (baset is Int)
+                        {
+                            this._mThread.currentFrame.LocalVariables[0] = (Int)baset;
+                        }
+                        result = true;
+                        break;
+                    case 60:
+                        baset = this._mThread.currentFrame.OpStack.Pop();
+                        if (baset is Int)
+                        {
+                            this._mThread.currentFrame.LocalVariables[1] = (Int)baset;
+                        }
+                        result = true;
+                        break;
+                    case 67:
+                        baset = this._mThread.currentFrame.OpStack.Pop();
+                        if (baset is Float)
+                        {
+                            this._mThread.currentFrame.LocalVariables[0] = (Float)baset;
+                        }
+                        result = true;
+                        break;
+                    case 68:
+                        baset = this._mThread.currentFrame.OpStack.Pop();
+                        if (baset is Float)
+                        {
+                            this._mThread.currentFrame.LocalVariables[1] = (Float)baset;
+                        }
+                        result = true;
+                        break;
+                    case 69:
+                        baset = this._mThread.currentFrame.OpStack.Pop();
+                        if (baset is Float)
+                        {
+                            this._mThread.currentFrame.LocalVariables[2] = (Float)baset;
+                        }
+                        result = true;
+                        break;
+                    case 70:
+                        baset = this._mThread.currentFrame.OpStack.Pop();
+                        if (baset is Float)
+                        {
+                            this._mThread.currentFrame.LocalVariables[3] = (Float)baset;
+                        }
+                        result = true;
+                        break;
+                    case 87:
+                        this._mThread.currentFrame.OpStack.Pop();
+                        result = true;
+                        break;
+                    case 98:
+                        BaseType bf2 = this._mThread.currentFrame.OpStack.Pop();
+                        BaseType bf1 = this._mThread.currentFrame.OpStack.Pop();
+                        if (bf1 is Float && bf2 is Float)
+                        {
+                            Float nflt = new Float();
+                            nflt.mValue = ((Float)bf1).mValue + ((Float)bf2).mValue;
+                            this._mThread.currentFrame.OpStack.Push(nflt);
+                        }
+                        result = true;
+                        break;
+                    case 102:
+                        BaseType bsf2 = this._mThread.currentFrame.OpStack.Pop();
+                        BaseType bsf1 = this._mThread.currentFrame.OpStack.Pop();
+                        if (bsf1 is Float && bsf2 is Float)
+                        {
+                            Float resf = new Float();
+                            resf.mValue = ((Float)bsf1).mValue - ((Float)bsf2).mValue;
+                            this._mThread.currentFrame.OpStack.Push(resf);
+                        }
+                        result = true;
+                        break;
+                    case 104: //check the order of the two values off the stack is correct
+                        BaseType bs2 = this._mThread.currentFrame.OpStack.Pop();
+                        BaseType bs1 = this._mThread.currentFrame.OpStack.Pop();
+                        if (bs1 is Int && bs2 is Int)
+                        {
+                            Int nInt = new Int();
+                            nInt.mValue = ((Int)bs1).mValue * ((Int)bs2).mValue;
+                            this._mThread.currentFrame.OpStack.Push(nInt);
+                        }
+                        result = true;
+                        break;
+                    case 132:
+                        if (this._mThread.currentFrame.LocalVariables[GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC]] != null)
+                        {
+                            if (this._mThread.currentFrame.LocalVariables[GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC]] is Int)
+                            {
+                                ((Int)this._mThread.currentFrame.LocalVariables[GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC]]).mValue += (sbyte) GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC + 1];
+                            }
+                        }
+                        this._mThread.PC += 2;
+                        result = true;
+                        break;
+                    case 139:
+                        BaseType conv1 = this._mThread.currentFrame.OpStack.Pop();
+                        if (conv1 is Float)
+                        {
+                            Int newconv = new Int();
+                            newconv.mValue = (int)((Float)conv1).mValue;
+                            this._mThread.currentFrame.OpStack.Push(newconv);
+                        }
+                        result = true;
+                        break;
+                    case 149:
+                        BaseType flcom2 = this._mThread.currentFrame.OpStack.Pop();
+                        BaseType flcom1 = this._mThread.currentFrame.OpStack.Pop();
+                        if (flcom1 is Float && flcom2 is Float)
+                        {
+                            Int compres = new Int();
+                            if (((Float)flcom1).mValue < ((Float)flcom2).mValue)
+                            {
+                                compres.mValue = -1;
+                            }
+                            else if (((Float)flcom1).mValue > ((Float)flcom2).mValue)
+                            {
+                                compres.mValue = 1;
+                            }
+                            else
+                            {
+                                compres.mValue = 0;
+                            }
+                            this._mThread.currentFrame.OpStack.Push(compres);
+                        }
+                        result = true;
+                        break;
+                    case 158:
+                        short compareoffset1 = (short)((GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC] << 8) + GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC + 1]);
+                        BaseType comp1 = this._mThread.currentFrame.OpStack.Pop();
+                        if (comp1 is Int)
+                        {
+                            if (((Int)comp1).mValue <= 0)
+                            {
+                                this._mThread.PC += -1 + compareoffset1;
+                            }
+                            else
+                            {
+                                this._mThread.PC += 2;
+                            }
+                        }
+                        else
+                        {
+                            this._mThread.PC += 2;
+                        }
+                        result = true;
+                        break;
+                    case 162:
+                        short compareoffset = (short)((GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC] << 8) + GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC + 1]);
+                        BaseType bc2 = this._mThread.currentFrame.OpStack.Pop();
+                        BaseType bc1 = this._mThread.currentFrame.OpStack.Pop();
+                        if (bc1 is Int && bc2 is Int)
+                        {
+                            //Console.WriteLine("comparing " + ((Int)bc1).mValue + " and " + ((Int)bc2).mValue);
+                            if (((Int)bc1).mValue >= ((Int)bc2).mValue)
+                            {
+                               // Console.WriteLine("branch compare true , offset is " +compareoffset);
+                               // Console.WriteLine("current PC is " + this._mThread.PC);
+                                this._mThread.PC += -1 + compareoffset;
+                                //Console.WriteLine("new PC is " + this._mThread.PC);
+                            }
+                            else
+                            {
+                                //Console.WriteLine("branch compare false");
+                                this._mThread.PC += 2;
+                            }
+                        }
+                        else
+                        {
+                            this._mThread.PC += 2;
+                        }
+                        result = true;
+                        break;
+                    case 164:
+                        short compareloffset = (short)((GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC] << 8) + GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC + 1]);
+                        BaseType bcl2 = this._mThread.currentFrame.OpStack.Pop();
+                        BaseType bcl1 = this._mThread.currentFrame.OpStack.Pop();
+                        if (bcl1 is Int && bcl2 is Int)
+                        {
+                            //Console.WriteLine("comparing " + ((Int)bcl1).mValue + " and " + ((Int)bcl2).mValue);
+                            if (((Int)bcl1).mValue <= ((Int)bcl2).mValue)
+                            {
+                              // Console.WriteLine("branch compare true , offset is " + compareloffset);
+                              // Console.WriteLine("current PC is " + this._mThread.PC);
+                               this._mThread.PC += -1 + compareloffset;
+                              // Console.WriteLine("new PC is " + this._mThread.PC);
+                            }
+                            else
+                            {
+                                //Console.WriteLine("branch compare false");
+                                this._mThread.PC += 2;
+                            }
+                        }
+                        else
+                        {
+                            this._mThread.PC += 2;
+                        }
+                        result = true;
+                        break;
+                    case 167:
+                        short offset = (short)((GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC] << 8) + GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC+1]);
+                        this._mThread.PC += -1 + offset;
+                        result = true;
+                        break;
+                }
+
+                return result;
+            }
+        }
+    }
+}
diff --git a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/JVM/Interpreter.Methods.cs b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/JVM/Interpreter.Methods.cs
index e2e2b7c..6b85fcc 100644
--- a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/JVM/Interpreter.Methods.cs
+++ b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/JVM/Interpreter.Methods.cs
@@ -1,96 +1,96 @@
-/*
-* Copyright (c) Contributors, http://www.openmetaverse.org/
-* See CONTRIBUTORS.TXT for a full list of copyright holders.
-*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted provided that the following conditions are met:
-*     * Redistributions of source code must retain the above copyright
-*       notice, this list of conditions and the following disclaimer.
-*     * Redistributions in binary form must reproduce the above copyright
-*       notice, this list of conditions and the following disclaimer in the
-*       documentation and/or other materials provided with the distribution.
-*     * Neither the name of the OpenSim Project nor the
-*       names of its contributors may be used to endorse or promote products
-*       derived from this software without specific prior written permission.
-*
-* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
-* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
-* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-* 
-*/
-using System;
-using System.Collections.Generic;
-using System.Text;
-using OpenSim.Region.Scripting.EmbeddedJVM.Types;
-using OpenSim.Region.Scripting.EmbeddedJVM.Types.PrimitiveTypes;
-using OpenSim.Framework.Interfaces;
-using OpenSim.Framework;
-using OpenSim.Framework.Types;
-
-namespace OpenSim.Region.Scripting.EmbeddedJVM
-{
-    partial class Thread
-    {
-        private partial class Interpreter
-        {
-            private bool IsMethodOpCode(byte opcode)
-            {
-                bool result = false;
-                switch (opcode)
-                {
-                    case 184:
-                        short refIndex = (short) ((GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC] << 8) + GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC+1]);
-                        if (this._mThread.currentClass._constantsPool[refIndex - 1] is ClassRecord.PoolMethodRef)
-                        {
-                            string typ = ((ClassRecord.PoolMethodRef)this._mThread.currentClass._constantsPool[refIndex - 1]).mNameType.Type.Value;
-                            string typeparam = "";
-                            string typereturn = "";
-                            int firstbrak = 0;
-                            int secondbrak = 0;
-                            firstbrak = typ.LastIndexOf('(');
-                            secondbrak = typ.LastIndexOf(')');
-                            typeparam = typ.Substring(firstbrak + 1, secondbrak - firstbrak - 1);
-                            typereturn = typ.Substring(secondbrak + 1, typ.Length - secondbrak - 1);
-                            if (((ClassRecord.PoolMethodRef)this._mThread.currentClass._constantsPool[refIndex - 1]).mClass.Name.Value == this._mThread.currentClass.mClass.Name.Value)
-                            {
-                                //calling a method in this class
-                                if (typeparam.Length == 0)
-                                {
-                                    this._mThread.JumpToStaticVoidMethod(((ClassRecord.PoolMethodRef)this._mThread.currentClass._constantsPool[refIndex - 1]).mNameType.Name.Value, (this._mThread.PC + 2));
-                                }
-                                else
-                                {
-                                    this._mThread.JumpToStaticParamMethod(((ClassRecord.PoolMethodRef)this._mThread.currentClass._constantsPool[refIndex - 1]).mNameType.Name.Value, typeparam, (this._mThread.PC + 2));
-                                }
-                            }
-                            else
-                            {
-                                //calling a method of a different class
-
-                                // OpenSimAPI Class
-                                if (((ClassRecord.PoolMethodRef)this._mThread.currentClass._constantsPool[refIndex - 1]).mClass.Name.Value == "OpenSimAPI")
-                                {
-                                    this._mThread.scriptInfo.api.CallMethod(((ClassRecord.PoolMethodRef)this._mThread.currentClass._constantsPool[refIndex - 1]).mNameType.Name.Value, null);
-                                }
-                            }
-                        }
-                        else
-                        {
-                            this._mThread.PC += 2;
-                        }
-                        result = true;
-                        break;
-                }
-
-                return result;
-            }
-        }
-    }
-}
+/*
+* Copyright (c) Contributors, http://www.openmetaverse.org/
+* See CONTRIBUTORS.TXT for a full list of copyright holders.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*     * Redistributions of source code must retain the above copyright
+*       notice, this list of conditions and the following disclaimer.
+*     * Redistributions in binary form must reproduce the above copyright
+*       notice, this list of conditions and the following disclaimer in the
+*       documentation and/or other materials provided with the distribution.
+*     * Neither the name of the OpenSim Project nor the
+*       names of its contributors may be used to endorse or promote products
+*       derived from this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
+* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
+* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+* 
+*/
+using System;
+using System.Collections.Generic;
+using System.Text;
+using OpenSim.Region.Scripting.EmbeddedJVM.Types;
+using OpenSim.Region.Scripting.EmbeddedJVM.Types.PrimitiveTypes;
+using OpenSim.Framework.Interfaces;
+using OpenSim.Framework;
+using OpenSim.Framework.Types;
+
+namespace OpenSim.Region.Scripting.EmbeddedJVM
+{
+    partial class Thread
+    {
+        private partial class Interpreter
+        {
+            private bool IsMethodOpCode(byte opcode)
+            {
+                bool result = false;
+                switch (opcode)
+                {
+                    case 184:
+                        short refIndex = (short) ((GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC] << 8) + GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC+1]);
+                        if (this._mThread.currentClass._constantsPool[refIndex - 1] is ClassRecord.PoolMethodRef)
+                        {
+                            string typ = ((ClassRecord.PoolMethodRef)this._mThread.currentClass._constantsPool[refIndex - 1]).mNameType.Type.Value;
+                            string typeparam = "";
+                            string typereturn = "";
+                            int firstbrak = 0;
+                            int secondbrak = 0;
+                            firstbrak = typ.LastIndexOf('(');
+                            secondbrak = typ.LastIndexOf(')');
+                            typeparam = typ.Substring(firstbrak + 1, secondbrak - firstbrak - 1);
+                            typereturn = typ.Substring(secondbrak + 1, typ.Length - secondbrak - 1);
+                            if (((ClassRecord.PoolMethodRef)this._mThread.currentClass._constantsPool[refIndex - 1]).mClass.Name.Value == this._mThread.currentClass.mClass.Name.Value)
+                            {
+                                //calling a method in this class
+                                if (typeparam.Length == 0)
+                                {
+                                    this._mThread.JumpToStaticVoidMethod(((ClassRecord.PoolMethodRef)this._mThread.currentClass._constantsPool[refIndex - 1]).mNameType.Name.Value, (this._mThread.PC + 2));
+                                }
+                                else
+                                {
+                                    this._mThread.JumpToStaticParamMethod(((ClassRecord.PoolMethodRef)this._mThread.currentClass._constantsPool[refIndex - 1]).mNameType.Name.Value, typeparam, (this._mThread.PC + 2));
+                                }
+                            }
+                            else
+                            {
+                                //calling a method of a different class
+
+                                // OpenSimAPI Class
+                                if (((ClassRecord.PoolMethodRef)this._mThread.currentClass._constantsPool[refIndex - 1]).mClass.Name.Value == "OpenSimAPI")
+                                {
+                                    this._mThread.scriptInfo.api.CallMethod(((ClassRecord.PoolMethodRef)this._mThread.currentClass._constantsPool[refIndex - 1]).mNameType.Name.Value, null);
+                                }
+                            }
+                        }
+                        else
+                        {
+                            this._mThread.PC += 2;
+                        }
+                        result = true;
+                        break;
+                }
+
+                return result;
+            }
+        }
+    }
+}
diff --git a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/JVM/Interpreter.Return.cs b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/JVM/Interpreter.Return.cs
index 6444776..3c18a11 100644
--- a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/JVM/Interpreter.Return.cs
+++ b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/JVM/Interpreter.Return.cs
@@ -1,40 +1,40 @@
-/*
-* Copyright (c) Contributors, http://www.openmetaverse.org/
-* See CONTRIBUTORS.TXT for a full list of copyright holders.
-*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted provided that the following conditions are met:
-*     * Redistributions of source code must retain the above copyright
-*       notice, this list of conditions and the following disclaimer.
-*     * Redistributions in binary form must reproduce the above copyright
-*       notice, this list of conditions and the following disclaimer in the
-*       documentation and/or other materials provided with the distribution.
-*     * Neither the name of the OpenSim Project nor the
-*       names of its contributors may be used to endorse or promote products
-*       derived from this software without specific prior written permission.
-*
-* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
-* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
-* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-* 
-*/
-using System;
-using System.Collections.Generic;
-using System.Text;
-
-namespace OpenSim.Region.Scripting.EmbeddedJVM
-{
-    partial class Thread
-    {
-        private partial class Interpreter
-        {
-        }
-    }
-}
+/*
+* Copyright (c) Contributors, http://www.openmetaverse.org/
+* See CONTRIBUTORS.TXT for a full list of copyright holders.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*     * Redistributions of source code must retain the above copyright
+*       notice, this list of conditions and the following disclaimer.
+*     * Redistributions in binary form must reproduce the above copyright
+*       notice, this list of conditions and the following disclaimer in the
+*       documentation and/or other materials provided with the distribution.
+*     * Neither the name of the OpenSim Project nor the
+*       names of its contributors may be used to endorse or promote products
+*       derived from this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
+* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
+* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+* 
+*/
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace OpenSim.Region.Scripting.EmbeddedJVM
+{
+    partial class Thread
+    {
+        private partial class Interpreter
+        {
+        }
+    }
+}
diff --git a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/JVM/Interpreter.cs b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/JVM/Interpreter.cs
index d44f315..9961cbd 100644
--- a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/JVM/Interpreter.cs
+++ b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/JVM/Interpreter.cs
@@ -1,135 +1,135 @@
-/*
-* Copyright (c) Contributors, http://www.openmetaverse.org/
-* See CONTRIBUTORS.TXT for a full list of copyright holders.
-*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted provided that the following conditions are met:
-*     * Redistributions of source code must retain the above copyright
-*       notice, this list of conditions and the following disclaimer.
-*     * Redistributions in binary form must reproduce the above copyright
-*       notice, this list of conditions and the following disclaimer in the
-*       documentation and/or other materials provided with the distribution.
-*     * Neither the name of the OpenSim Project nor the
-*       names of its contributors may be used to endorse or promote products
-*       derived from this software without specific prior written permission.
-*
-* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
-* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
-* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-* 
-*/
-using System;
-using System.Collections.Generic;
-using System.Text;
-using OpenSim.Region.Scripting.EmbeddedJVM.Types;
-using OpenSim.Region.Scripting.EmbeddedJVM.Types.PrimitiveTypes;
-
-namespace OpenSim.Region.Scripting.EmbeddedJVM
-{
-    partial class Thread
-    {
-        private partial class Interpreter
-        {
-            private Thread _mThread;
-
-            public Interpreter(Thread parentThread)
-            {
-                _mThread = parentThread;
-            }
-
-            public bool Excute()
-            {
-                bool run = true;
-                byte currentOpCode = GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC++];
-               // Console.WriteLine("opCode is: " + currentOpCode);
-                bool handled = false;
-
-                handled = this.IsLogicOpCode(currentOpCode);
-                if (!handled)
-                {
-                    handled = this.IsMethodOpCode(currentOpCode);
-                }
-                if (!handled)
-                {
-                    if (currentOpCode == 172)
-                    {
-                        if (this._mThread.stack.StackFrames.Count > 1)
-                        {
-                            Console.WriteLine("returning int from function");
-                            int retPC1 = this._mThread.currentFrame.ReturnPC;
-                            BaseType bas1 = this._mThread.currentFrame.OpStack.Pop();
-                            this._mThread.stack.StackFrames.Pop();
-                            this._mThread.currentFrame = this._mThread.stack.StackFrames.Peek();
-                            this._mThread.PC = retPC1;
-                            if (bas1 is Int)
-                            {
-                                this._mThread.currentFrame.OpStack.Push((Int)bas1);
-                            }
-                        }
-                        else
-                        {
-                          //  Console.WriteLine("No parent function so ending program");
-                            this._mThread.stack.StackFrames.Pop();
-                            run = false;
-                        }
-                        handled = true;
-                    }
-                    if (currentOpCode == 174)
-                    {
-                        if (this._mThread.stack.StackFrames.Count > 1)
-                        {
-                            Console.WriteLine("returning float from function");
-                            int retPC1 = this._mThread.currentFrame.ReturnPC;
-                            BaseType bas1 = this._mThread.currentFrame.OpStack.Pop();
-                            this._mThread.stack.StackFrames.Pop();
-                            this._mThread.currentFrame = this._mThread.stack.StackFrames.Peek();
-                            this._mThread.PC = retPC1;
-                            if (bas1 is Float)
-                            {
-                                this._mThread.currentFrame.OpStack.Push((Float)bas1);
-                            }
-                        }
-                        else
-                        {
-                           // Console.WriteLine("No parent function so ending program");
-                            this._mThread.stack.StackFrames.Pop();
-                            run = false;
-                        }
-                        handled = true;
-                    }
-                    if (currentOpCode == 177)
-                    {
-                        if (this._mThread.stack.StackFrames.Count > 1)
-                        {
-                            Console.WriteLine("returning from function");
-                            int retPC = this._mThread.currentFrame.ReturnPC;
-                            this._mThread.stack.StackFrames.Pop();
-                            this._mThread.currentFrame = this._mThread.stack.StackFrames.Peek();
-                            this._mThread.PC = retPC;
-                        }
-                        else
-                        {
-                           // Console.WriteLine("No parent function so ending program");
-                            this._mThread.stack.StackFrames.Pop();
-                            run = false;
-                        }
-                        handled = true;
-                    }
-                }
-                if (!handled)
-                {
-                    Console.WriteLine("opcode " + currentOpCode + " not been handled ");
-                }
-                return run;
-
-            }
-        }
-    }
-}
+/*
+* Copyright (c) Contributors, http://www.openmetaverse.org/
+* See CONTRIBUTORS.TXT for a full list of copyright holders.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*     * Redistributions of source code must retain the above copyright
+*       notice, this list of conditions and the following disclaimer.
+*     * Redistributions in binary form must reproduce the above copyright
+*       notice, this list of conditions and the following disclaimer in the
+*       documentation and/or other materials provided with the distribution.
+*     * Neither the name of the OpenSim Project nor the
+*       names of its contributors may be used to endorse or promote products
+*       derived from this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
+* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
+* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+* 
+*/
+using System;
+using System.Collections.Generic;
+using System.Text;
+using OpenSim.Region.Scripting.EmbeddedJVM.Types;
+using OpenSim.Region.Scripting.EmbeddedJVM.Types.PrimitiveTypes;
+
+namespace OpenSim.Region.Scripting.EmbeddedJVM
+{
+    partial class Thread
+    {
+        private partial class Interpreter
+        {
+            private Thread _mThread;
+
+            public Interpreter(Thread parentThread)
+            {
+                _mThread = parentThread;
+            }
+
+            public bool Excute()
+            {
+                bool run = true;
+                byte currentOpCode = GlobalMemory.MethodArea.MethodBuffer[this._mThread.PC++];
+               // Console.WriteLine("opCode is: " + currentOpCode);
+                bool handled = false;
+
+                handled = this.IsLogicOpCode(currentOpCode);
+                if (!handled)
+                {
+                    handled = this.IsMethodOpCode(currentOpCode);
+                }
+                if (!handled)
+                {
+                    if (currentOpCode == 172)
+                    {
+                        if (this._mThread.stack.StackFrames.Count > 1)
+                        {
+                            Console.WriteLine("returning int from function");
+                            int retPC1 = this._mThread.currentFrame.ReturnPC;
+                            BaseType bas1 = this._mThread.currentFrame.OpStack.Pop();
+                            this._mThread.stack.StackFrames.Pop();
+                            this._mThread.currentFrame = this._mThread.stack.StackFrames.Peek();
+                            this._mThread.PC = retPC1;
+                            if (bas1 is Int)
+                            {
+                                this._mThread.currentFrame.OpStack.Push((Int)bas1);
+                            }
+                        }
+                        else
+                        {
+                          //  Console.WriteLine("No parent function so ending program");
+                            this._mThread.stack.StackFrames.Pop();
+                            run = false;
+                        }
+                        handled = true;
+                    }
+                    if (currentOpCode == 174)
+                    {
+                        if (this._mThread.stack.StackFrames.Count > 1)
+                        {
+                            Console.WriteLine("returning float from function");
+                            int retPC1 = this._mThread.currentFrame.ReturnPC;
+                            BaseType bas1 = this._mThread.currentFrame.OpStack.Pop();
+                            this._mThread.stack.StackFrames.Pop();
+                            this._mThread.currentFrame = this._mThread.stack.StackFrames.Peek();
+                            this._mThread.PC = retPC1;
+                            if (bas1 is Float)
+                            {
+                                this._mThread.currentFrame.OpStack.Push((Float)bas1);
+                            }
+                        }
+                        else
+                        {
+                           // Console.WriteLine("No parent function so ending program");
+                            this._mThread.stack.StackFrames.Pop();
+                            run = false;
+                        }
+                        handled = true;
+                    }
+                    if (currentOpCode == 177)
+                    {
+                        if (this._mThread.stack.StackFrames.Count > 1)
+                        {
+                            Console.WriteLine("returning from function");
+                            int retPC = this._mThread.currentFrame.ReturnPC;
+                            this._mThread.stack.StackFrames.Pop();
+                            this._mThread.currentFrame = this._mThread.stack.StackFrames.Peek();
+                            this._mThread.PC = retPC;
+                        }
+                        else
+                        {
+                           // Console.WriteLine("No parent function so ending program");
+                            this._mThread.stack.StackFrames.Pop();
+                            run = false;
+                        }
+                        handled = true;
+                    }
+                }
+                if (!handled)
+                {
+                    Console.WriteLine("opcode " + currentOpCode + " not been handled ");
+                }
+                return run;
+
+            }
+        }
+    }
+}
diff --git a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/JVM/MainMemory.cs b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/JVM/MainMemory.cs
index addb6ff..7174975 100644
--- a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/JVM/MainMemory.cs
+++ b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/JVM/MainMemory.cs
@@ -1,45 +1,45 @@
-/*
-* Copyright (c) Contributors, http://www.openmetaverse.org/
-* See CONTRIBUTORS.TXT for a full list of copyright holders.
-*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted provided that the following conditions are met:
-*     * Redistributions of source code must retain the above copyright
-*       notice, this list of conditions and the following disclaimer.
-*     * Redistributions in binary form must reproduce the above copyright
-*       notice, this list of conditions and the following disclaimer in the
-*       documentation and/or other materials provided with the distribution.
-*     * Neither the name of the OpenSim Project nor the
-*       names of its contributors may be used to endorse or promote products
-*       derived from this software without specific prior written permission.
-*
-* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
-* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
-* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-* 
-*/
-using System;
-using System.Collections.Generic;
-using System.Text;
-
-namespace OpenSim.Region.Scripting.EmbeddedJVM
-{
-    public class MainMemory
-    {
-        public Heap HeapArea;
-        public MethodMemory MethodArea;
- 
-        public MainMemory()
-        {
-            MethodArea = new MethodMemory();
-            HeapArea = new Heap();
-        }
-    }
-}
+/*
+* Copyright (c) Contributors, http://www.openmetaverse.org/
+* See CONTRIBUTORS.TXT for a full list of copyright holders.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*     * Redistributions of source code must retain the above copyright
+*       notice, this list of conditions and the following disclaimer.
+*     * Redistributions in binary form must reproduce the above copyright
+*       notice, this list of conditions and the following disclaimer in the
+*       documentation and/or other materials provided with the distribution.
+*     * Neither the name of the OpenSim Project nor the
+*       names of its contributors may be used to endorse or promote products
+*       derived from this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
+* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
+* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+* 
+*/
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace OpenSim.Region.Scripting.EmbeddedJVM
+{
+    public class MainMemory
+    {
+        public Heap HeapArea;
+        public MethodMemory MethodArea;
+ 
+        public MainMemory()
+        {
+            MethodArea = new MethodMemory();
+            HeapArea = new Heap();
+        }
+    }
+}
diff --git a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/JVM/MethodMemory.cs b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/JVM/MethodMemory.cs
index 7d69e91..5f29091 100644
--- a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/JVM/MethodMemory.cs
+++ b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/JVM/MethodMemory.cs
@@ -1,46 +1,46 @@
-/*
-* Copyright (c) Contributors, http://www.openmetaverse.org/
-* See CONTRIBUTORS.TXT for a full list of copyright holders.
-*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted provided that the following conditions are met:
-*     * Redistributions of source code must retain the above copyright
-*       notice, this list of conditions and the following disclaimer.
-*     * Redistributions in binary form must reproduce the above copyright
-*       notice, this list of conditions and the following disclaimer in the
-*       documentation and/or other materials provided with the distribution.
-*     * Neither the name of the OpenSim Project nor the
-*       names of its contributors may be used to endorse or promote products
-*       derived from this software without specific prior written permission.
-*
-* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
-* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
-* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-* 
-*/
-using System;
-using System.Collections.Generic;
-using System.Text;
-
-namespace OpenSim.Region.Scripting.EmbeddedJVM
-{
-    public class MethodMemory
-    {
-        public byte[] MethodBuffer;
-        public List<ClassRecord> Classes = new List<ClassRecord>();
-        public int NextMethodPC = 0;
-        public int Methodcount = 0;
-
-        public MethodMemory()
-        {
-            MethodBuffer = new byte[20000];
-        }
-    }
-}
+/*
+* Copyright (c) Contributors, http://www.openmetaverse.org/
+* See CONTRIBUTORS.TXT for a full list of copyright holders.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*     * Redistributions of source code must retain the above copyright
+*       notice, this list of conditions and the following disclaimer.
+*     * Redistributions in binary form must reproduce the above copyright
+*       notice, this list of conditions and the following disclaimer in the
+*       documentation and/or other materials provided with the distribution.
+*     * Neither the name of the OpenSim Project nor the
+*       names of its contributors may be used to endorse or promote products
+*       derived from this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
+* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
+* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+* 
+*/
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace OpenSim.Region.Scripting.EmbeddedJVM
+{
+    public class MethodMemory
+    {
+        public byte[] MethodBuffer;
+        public List<ClassRecord> Classes = new List<ClassRecord>();
+        public int NextMethodPC = 0;
+        public int Methodcount = 0;
+
+        public MethodMemory()
+        {
+            MethodBuffer = new byte[20000];
+        }
+    }
+}
diff --git a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/JVM/Object.cs b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/JVM/Object.cs
index 6a0a1a4..8acb2bd 100644
--- a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/JVM/Object.cs
+++ b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/JVM/Object.cs
@@ -1,37 +1,37 @@
-/*
-* Copyright (c) Contributors, http://www.openmetaverse.org/
-* See CONTRIBUTORS.TXT for a full list of copyright holders.
-*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted provided that the following conditions are met:
-*     * Redistributions of source code must retain the above copyright
-*       notice, this list of conditions and the following disclaimer.
-*     * Redistributions in binary form must reproduce the above copyright
-*       notice, this list of conditions and the following disclaimer in the
-*       documentation and/or other materials provided with the distribution.
-*     * Neither the name of the OpenSim Project nor the
-*       names of its contributors may be used to endorse or promote products
-*       derived from this software without specific prior written permission.
-*
-* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
-* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
-* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-* 
-*/
-using System;
-using System.Collections.Generic;
-using System.Text;
-
-namespace OpenSim.Region.Scripting.EmbeddedJVM
-{
-    public class Object
-    {
-    }
-}
+/*
+* Copyright (c) Contributors, http://www.openmetaverse.org/
+* See CONTRIBUTORS.TXT for a full list of copyright holders.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*     * Redistributions of source code must retain the above copyright
+*       notice, this list of conditions and the following disclaimer.
+*     * Redistributions in binary form must reproduce the above copyright
+*       notice, this list of conditions and the following disclaimer in the
+*       documentation and/or other materials provided with the distribution.
+*     * Neither the name of the OpenSim Project nor the
+*       names of its contributors may be used to endorse or promote products
+*       derived from this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
+* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
+* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+* 
+*/
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace OpenSim.Region.Scripting.EmbeddedJVM
+{
+    public class Object
+    {
+    }
+}
diff --git a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/JVM/Stack.cs b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/JVM/Stack.cs
index 74f0a7f..7c12678 100644
--- a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/JVM/Stack.cs
+++ b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/JVM/Stack.cs
@@ -1,42 +1,42 @@
-/*
-* Copyright (c) Contributors, http://www.openmetaverse.org/
-* See CONTRIBUTORS.TXT for a full list of copyright holders.
-*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted provided that the following conditions are met:
-*     * Redistributions of source code must retain the above copyright
-*       notice, this list of conditions and the following disclaimer.
-*     * Redistributions in binary form must reproduce the above copyright
-*       notice, this list of conditions and the following disclaimer in the
-*       documentation and/or other materials provided with the distribution.
-*     * Neither the name of the OpenSim Project nor the
-*       names of its contributors may be used to endorse or promote products
-*       derived from this software without specific prior written permission.
-*
-* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
-* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
-* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-* 
-*/
-using System;
-using System.Collections.Generic;
-using System.Text;
-
-namespace OpenSim.Region.Scripting.EmbeddedJVM
-{
-    public class Stack
-    {
-        public Stack<StackFrame> StackFrames = new Stack<StackFrame>();
-
-        public Stack()
-        {
-        }
-    }
-}
+/*
+* Copyright (c) Contributors, http://www.openmetaverse.org/
+* See CONTRIBUTORS.TXT for a full list of copyright holders.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*     * Redistributions of source code must retain the above copyright
+*       notice, this list of conditions and the following disclaimer.
+*     * Redistributions in binary form must reproduce the above copyright
+*       notice, this list of conditions and the following disclaimer in the
+*       documentation and/or other materials provided with the distribution.
+*     * Neither the name of the OpenSim Project nor the
+*       names of its contributors may be used to endorse or promote products
+*       derived from this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
+* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
+* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+* 
+*/
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace OpenSim.Region.Scripting.EmbeddedJVM
+{
+    public class Stack
+    {
+        public Stack<StackFrame> StackFrames = new Stack<StackFrame>();
+
+        public Stack()
+        {
+        }
+    }
+}
diff --git a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/JVM/StackFrame.cs b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/JVM/StackFrame.cs
index 1072395..76257b8 100644
--- a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/JVM/StackFrame.cs
+++ b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/JVM/StackFrame.cs
@@ -1,49 +1,49 @@
-/*
-* Copyright (c) Contributors, http://www.openmetaverse.org/
-* See CONTRIBUTORS.TXT for a full list of copyright holders.
-*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted provided that the following conditions are met:
-*     * Redistributions of source code must retain the above copyright
-*       notice, this list of conditions and the following disclaimer.
-*     * Redistributions in binary form must reproduce the above copyright
-*       notice, this list of conditions and the following disclaimer in the
-*       documentation and/or other materials provided with the distribution.
-*     * Neither the name of the OpenSim Project nor the
-*       names of its contributors may be used to endorse or promote products
-*       derived from this software without specific prior written permission.
-*
-* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
-* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
-* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-* 
-*/
-using System;
-using System.Collections.Generic;
-using System.Text;
-using OpenSim.Region.Scripting.EmbeddedJVM.Types;
-
-namespace OpenSim.Region.Scripting.EmbeddedJVM
-{
-    public class StackFrame
-    {
-        public BaseType[] LocalVariables;
-        public Stack<BaseType> OpStack = new Stack<BaseType>();
-
-        public int ReturnPC = 0;
-        public ClassRecord CallingClass = null;
-
-        public StackFrame()
-        {
-            LocalVariables = new BaseType[20];
-        }
-
-    }
-}
+/*
+* Copyright (c) Contributors, http://www.openmetaverse.org/
+* See CONTRIBUTORS.TXT for a full list of copyright holders.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*     * Redistributions of source code must retain the above copyright
+*       notice, this list of conditions and the following disclaimer.
+*     * Redistributions in binary form must reproduce the above copyright
+*       notice, this list of conditions and the following disclaimer in the
+*       documentation and/or other materials provided with the distribution.
+*     * Neither the name of the OpenSim Project nor the
+*       names of its contributors may be used to endorse or promote products
+*       derived from this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
+* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
+* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+* 
+*/
+using System;
+using System.Collections.Generic;
+using System.Text;
+using OpenSim.Region.Scripting.EmbeddedJVM.Types;
+
+namespace OpenSim.Region.Scripting.EmbeddedJVM
+{
+    public class StackFrame
+    {
+        public BaseType[] LocalVariables;
+        public Stack<BaseType> OpStack = new Stack<BaseType>();
+
+        public int ReturnPC = 0;
+        public ClassRecord CallingClass = null;
+
+        public StackFrame()
+        {
+            LocalVariables = new BaseType[20];
+        }
+
+    }
+}
diff --git a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/JVM/Thread.cs b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/JVM/Thread.cs
index 59f3042..eda2640 100644
--- a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/JVM/Thread.cs
+++ b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/JVM/Thread.cs
@@ -1,119 +1,119 @@
-/*
-* Copyright (c) Contributors, http://www.openmetaverse.org/
-* See CONTRIBUTORS.TXT for a full list of copyright holders.
-*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted provided that the following conditions are met:
-*     * Redistributions of source code must retain the above copyright
-*       notice, this list of conditions and the following disclaimer.
-*     * Redistributions in binary form must reproduce the above copyright
-*       notice, this list of conditions and the following disclaimer in the
-*       documentation and/or other materials provided with the distribution.
-*     * Neither the name of the OpenSim Project nor the
-*       names of its contributors may be used to endorse or promote products
-*       derived from this software without specific prior written permission.
-*
-* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
-* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
-* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-* 
-*/
-using System;
-using System.Collections.Generic;
-using System.Text;
-using OpenSim.Region.Scripting.EmbeddedJVM.Types;
-using OpenSim.Region.Scripting.EmbeddedJVM.Types.PrimitiveTypes;
-using OpenSim.Framework;
-using OpenSim.Framework.Interfaces;
-using OpenSim.Region.Environment.Scenes;
-using OpenSim.Region.Scripting;
-
-namespace OpenSim.Region.Scripting.EmbeddedJVM
-{
-    public partial class Thread
-    {
-        // Is this smart?
-        public static MainMemory GlobalMemory;
-        public static Scene World;
-        private int PC = 0;
-        private Stack stack;
-        private Interpreter mInterpreter;
-        public ClassRecord currentClass;
-        public ClassInstance currentInstance;
-        private StackFrame currentFrame;
-        public int excutionCounter = 0;
-        public bool running = false;
-
-        public ScriptInfo scriptInfo;
-
-        public Thread()
-        {
-            this.mInterpreter = new Interpreter(this);
-            this.stack = new Stack();
-        }
-
-        public void SetPC(int methodpointer)
-        {
-            //Console.WriteLine("Thread PC has been set to " + methodpointer);
-            PC = methodpointer;
-        }
-
-        public void StartMethod(ClassRecord rec, string methName)
-        {
-            currentFrame = new StackFrame();
-            this.stack.StackFrames.Push(currentFrame);
-            this.currentClass = rec;
-            currentClass.StartMethod(this, methName);
-        }
-
-        public void StartMethod( string methName)
-        {
-            currentFrame = new StackFrame();
-            this.stack.StackFrames.Push(currentFrame);
-            currentClass.StartMethod(this, methName);
-        }
-
-        public void JumpToStaticVoidMethod(string methName, int returnPC)
-        {
-            currentFrame = new StackFrame();
-            currentFrame.ReturnPC = returnPC;
-            this.stack.StackFrames.Push(currentFrame);
-            currentClass.StartMethod(this, methName);
-        }
-
-        public void JumpToStaticParamMethod(string methName, string param, int returnPC)
-        {
-            if (param == "I")
-            {
-                BaseType bs1 = currentFrame.OpStack.Pop();
-                currentFrame = new StackFrame();
-                currentFrame.ReturnPC = returnPC;
-                this.stack.StackFrames.Push(currentFrame);
-                currentFrame.LocalVariables[0] = ((Int)bs1);
-                currentClass.StartMethod(this, methName);
-            }
-            if (param == "F")
-            {
-
-            }
-        }
-
-        public void JumpToClassStaticVoidMethod(string className, string methName, int returnPC)
-        {
-
-        }
-
-        public bool Excute()
-        {
-            excutionCounter++;
-            return this.mInterpreter.Excute();
-        }
-    }
-}
+/*
+* Copyright (c) Contributors, http://www.openmetaverse.org/
+* See CONTRIBUTORS.TXT for a full list of copyright holders.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*     * Redistributions of source code must retain the above copyright
+*       notice, this list of conditions and the following disclaimer.
+*     * Redistributions in binary form must reproduce the above copyright
+*       notice, this list of conditions and the following disclaimer in the
+*       documentation and/or other materials provided with the distribution.
+*     * Neither the name of the OpenSim Project nor the
+*       names of its contributors may be used to endorse or promote products
+*       derived from this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
+* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
+* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+* 
+*/
+using System;
+using System.Collections.Generic;
+using System.Text;
+using OpenSim.Region.Scripting.EmbeddedJVM.Types;
+using OpenSim.Region.Scripting.EmbeddedJVM.Types.PrimitiveTypes;
+using OpenSim.Framework;
+using OpenSim.Framework.Interfaces;
+using OpenSim.Region.Environment.Scenes;
+using OpenSim.Region.Scripting;
+
+namespace OpenSim.Region.Scripting.EmbeddedJVM
+{
+    public partial class Thread
+    {
+        // Is this smart?
+        public static MainMemory GlobalMemory;
+        public static Scene World;
+        private int PC = 0;
+        private Stack stack;
+        private Interpreter mInterpreter;
+        public ClassRecord currentClass;
+        public ClassInstance currentInstance;
+        private StackFrame currentFrame;
+        public int excutionCounter = 0;
+        public bool running = false;
+
+        public ScriptInfo scriptInfo;
+
+        public Thread()
+        {
+            this.mInterpreter = new Interpreter(this);
+            this.stack = new Stack();
+        }
+
+        public void SetPC(int methodpointer)
+        {
+            //Console.WriteLine("Thread PC has been set to " + methodpointer);
+            PC = methodpointer;
+        }
+
+        public void StartMethod(ClassRecord rec, string methName)
+        {
+            currentFrame = new StackFrame();
+            this.stack.StackFrames.Push(currentFrame);
+            this.currentClass = rec;
+            currentClass.StartMethod(this, methName);
+        }
+
+        public void StartMethod( string methName)
+        {
+            currentFrame = new StackFrame();
+            this.stack.StackFrames.Push(currentFrame);
+            currentClass.StartMethod(this, methName);
+        }
+
+        public void JumpToStaticVoidMethod(string methName, int returnPC)
+        {
+            currentFrame = new StackFrame();
+            currentFrame.ReturnPC = returnPC;
+            this.stack.StackFrames.Push(currentFrame);
+            currentClass.StartMethod(this, methName);
+        }
+
+        public void JumpToStaticParamMethod(string methName, string param, int returnPC)
+        {
+            if (param == "I")
+            {
+                BaseType bs1 = currentFrame.OpStack.Pop();
+                currentFrame = new StackFrame();
+                currentFrame.ReturnPC = returnPC;
+                this.stack.StackFrames.Push(currentFrame);
+                currentFrame.LocalVariables[0] = ((Int)bs1);
+                currentClass.StartMethod(this, methName);
+            }
+            if (param == "F")
+            {
+
+            }
+        }
+
+        public void JumpToClassStaticVoidMethod(string className, string methName, int returnPC)
+        {
+
+        }
+
+        public bool Excute()
+        {
+            excutionCounter++;
+            return this.mInterpreter.Excute();
+        }
+    }
+}
diff --git a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/JavaEngine.cs b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/JavaEngine.cs
index a884e2b..58cdf49 100644
--- a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/JavaEngine.cs
+++ b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/JavaEngine.cs
@@ -1,29 +1,29 @@
-using System;
-using System.Collections.Generic;
-using System.Text;
-
-using OpenSim.Region.Scripting;
-using OpenSim.Region.Scripting.EmbeddedJVM;
-
-namespace OpenSim.Region.Scripting
-{
-    public class JavaEngine : IScriptCompiler
-    {
-        public string FileExt()
-        {
-            return ".java";
-        }
-
-        public Dictionary<string, IScript> compile(string filename)
-        {
-            JVMScript script = new JVMScript();
-            Dictionary<string, IScript> returns = new Dictionary<string, IScript>();
-
-            script.LoadScript(filename);
-
-            returns.Add(filename, script);
-
-            return returns;
-        }
-    }
-}
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+using OpenSim.Region.Scripting;
+using OpenSim.Region.Scripting.EmbeddedJVM;
+
+namespace OpenSim.Region.Scripting
+{
+    public class JavaEngine : IScriptCompiler
+    {
+        public string FileExt()
+        {
+            return ".java";
+        }
+
+        public Dictionary<string, IScript> compile(string filename)
+        {
+            JVMScript script = new JVMScript();
+            Dictionary<string, IScript> returns = new Dictionary<string, IScript>();
+
+            script.LoadScript(filename);
+
+            returns.Add(filename, script);
+
+            return returns;
+        }
+    }
+}
diff --git a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/OpenSimJVM.cs b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/OpenSimJVM.cs
index 8b38951..78c6f67 100644
--- a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/OpenSimJVM.cs
+++ b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/OpenSimJVM.cs
@@ -1,170 +1,170 @@
-/*
-* Copyright (c) Contributors, http://www.openmetaverse.org/
-* See CONTRIBUTORS.TXT for a full list of copyright holders.
-*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted provided that the following conditions are met:
-*     * Redistributions of source code must retain the above copyright
-*       notice, this list of conditions and the following disclaimer.
-*     * Redistributions in binary form must reproduce the above copyright
-*       notice, this list of conditions and the following disclaimer in the
-*       documentation and/or other materials provided with the distribution.
-*     * Neither the name of the OpenSim Project nor the
-*       names of its contributors may be used to endorse or promote products
-*       derived from this software without specific prior written permission.
-*
-* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
-* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
-* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-* 
-*/
-using System;
-using System.Collections.Generic;
-using System.Text;
-using System.IO;
-using System.Threading;
-using OpenSim.Framework;
-using OpenSim.Framework.Interfaces;
-using OpenSim.Framework.Utilities;
-using OpenSim.Region.Scripting;
-using OpenSim.Region.Environment.Scenes;
-
-namespace OpenSim.Region.Scripting.EmbeddedJVM
-{
-    public class JVMScript : IScript
-    {
-        private List<Thread> _threads = new List<Thread>();
-        private BlockingQueue<CompileInfo> CompileScripts = new BlockingQueue<CompileInfo>();
-        private MainMemory _mainMemory;
-
-        ScriptInfo scriptInfo;
-
-        public void Initialise(ScriptInfo info)
-        {
-            scriptInfo = info;
-
-            _mainMemory = new MainMemory();
-            Thread.GlobalMemory = this._mainMemory;
-            Thread.World = info.world;
-            CompileScript();
-
-            scriptInfo.events.OnFrame += new EventManager.OnFrameDelegate(events_OnFrame);
-            scriptInfo.events.OnNewPresence += new EventManager.OnNewPresenceDelegate(events_OnNewPresence);
-        }
-
-        void events_OnNewPresence(ScenePresence presence)
-        {
-            for (int i = 0; i < this._threads.Count; i++)
-            {
-                if (!this._threads[i].running)
-                {
-                    this._threads[i].StartMethod("OnNewPresence");
-                    bool run = true;
-                    while (run)
-                    {
-                        run = this._threads[i].Excute();
-                    }
-                }
-            }
-        }
-
-        void events_OnFrame()
-        {
-            for (int i = 0; i < this._threads.Count; i++)
-            {
-                if (!this._threads[i].running)
-                {
-                    this._threads[i].StartMethod("OnFrame");
-                    bool run = true;
-                    while (run)
-                    {
-                        run = this._threads[i].Excute();
-                    }
-                }
-            }
-        }
-
-        public string getName()
-        {
-            return "JVM Scripting Engine";
-        }
-
-        public void LoadScript(string script)
-        {
-            Console.WriteLine("OpenSimJVM - loading new script: " + script);
-            CompileInfo comp = new CompileInfo();
-            comp.script = script;
-            comp.scriptName = script;
-            this.CompileScripts.Enqueue(comp);
-        }
-
-        public void CompileScript()
-        {
-            CompileInfo comp = this.CompileScripts.Dequeue();
-            string script = comp.script;
-            string scriptName = comp.scriptName;
-            try
-            {
-                //need to compile the script into a java class file
-
-                //first save it to a java source file
-                TextWriter tw = new StreamWriter(scriptName + ".java");
-                tw.WriteLine(script);
-                tw.Close();
-
-                //now compile
-                System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo("javac.exe", "*.java");
-                // psi.RedirectStandardOutput = true;
-                psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
-                psi.UseShellExecute = false;
-
-                System.Diagnostics.Process javacomp;
-                javacomp = System.Diagnostics.Process.Start(psi);
-                javacomp.WaitForExit();
-
-
-                //now load in class file
-                ClassRecord class1 = new ClassRecord();
-                class1.LoadClassFromFile(scriptName + ".class");
-                class1.PrintToConsole();
-                //Console.WriteLine();
-                this._mainMemory.MethodArea.Classes.Add(class1);
-                class1.AddMethodsToMemory(this._mainMemory.MethodArea);
-
-                Thread newThread = new Thread();
-                this._threads.Add(newThread);
-                newThread.currentClass = class1;
-                newThread.scriptInfo = scriptInfo;
-
-                //now delete the created files
-                System.IO.File.Delete(scriptName + ".java");
-                System.IO.File.Delete(scriptName + ".class");
-                //this.OnFrame();
-            }
-            catch (Exception e)
-            {
-                Console.WriteLine("exception");
-                Console.WriteLine(e.StackTrace);
-                Console.WriteLine(e.Message);
-            }
-        }
-
-        private class CompileInfo
-        {
-            public string script;
-            public string scriptName;
-
-            public CompileInfo()
-            {
-
-            }
-        }
-    }
-}
+/*
+* Copyright (c) Contributors, http://www.openmetaverse.org/
+* See CONTRIBUTORS.TXT for a full list of copyright holders.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*     * Redistributions of source code must retain the above copyright
+*       notice, this list of conditions and the following disclaimer.
+*     * Redistributions in binary form must reproduce the above copyright
+*       notice, this list of conditions and the following disclaimer in the
+*       documentation and/or other materials provided with the distribution.
+*     * Neither the name of the OpenSim Project nor the
+*       names of its contributors may be used to endorse or promote products
+*       derived from this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
+* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
+* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+* 
+*/
+using System;
+using System.Collections.Generic;
+using System.Text;
+using System.IO;
+using System.Threading;
+using OpenSim.Framework;
+using OpenSim.Framework.Interfaces;
+using OpenSim.Framework.Utilities;
+using OpenSim.Region.Scripting;
+using OpenSim.Region.Environment.Scenes;
+
+namespace OpenSim.Region.Scripting.EmbeddedJVM
+{
+    public class JVMScript : IScript
+    {
+        private List<Thread> _threads = new List<Thread>();
+        private BlockingQueue<CompileInfo> CompileScripts = new BlockingQueue<CompileInfo>();
+        private MainMemory _mainMemory;
+
+        ScriptInfo scriptInfo;
+
+        public void Initialise(ScriptInfo info)
+        {
+            scriptInfo = info;
+
+            _mainMemory = new MainMemory();
+            Thread.GlobalMemory = this._mainMemory;
+            Thread.World = info.world;
+            CompileScript();
+
+            scriptInfo.events.OnFrame += new EventManager.OnFrameDelegate(events_OnFrame);
+            scriptInfo.events.OnNewPresence += new EventManager.OnNewPresenceDelegate(events_OnNewPresence);
+        }
+
+        void events_OnNewPresence(ScenePresence presence)
+        {
+            for (int i = 0; i < this._threads.Count; i++)
+            {
+                if (!this._threads[i].running)
+                {
+                    this._threads[i].StartMethod("OnNewPresence");
+                    bool run = true;
+                    while (run)
+                    {
+                        run = this._threads[i].Excute();
+                    }
+                }
+            }
+        }
+
+        void events_OnFrame()
+        {
+            for (int i = 0; i < this._threads.Count; i++)
+            {
+                if (!this._threads[i].running)
+                {
+                    this._threads[i].StartMethod("OnFrame");
+                    bool run = true;
+                    while (run)
+                    {
+                        run = this._threads[i].Excute();
+                    }
+                }
+            }
+        }
+
+        public string getName()
+        {
+            return "JVM Scripting Engine";
+        }
+
+        public void LoadScript(string script)
+        {
+            Console.WriteLine("OpenSimJVM - loading new script: " + script);
+            CompileInfo comp = new CompileInfo();
+            comp.script = script;
+            comp.scriptName = script;
+            this.CompileScripts.Enqueue(comp);
+        }
+
+        public void CompileScript()
+        {
+            CompileInfo comp = this.CompileScripts.Dequeue();
+            string script = comp.script;
+            string scriptName = comp.scriptName;
+            try
+            {
+                //need to compile the script into a java class file
+
+                //first save it to a java source file
+                TextWriter tw = new StreamWriter(scriptName + ".java");
+                tw.WriteLine(script);
+                tw.Close();
+
+                //now compile
+                System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo("javac.exe", "*.java");
+                // psi.RedirectStandardOutput = true;
+                psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
+                psi.UseShellExecute = false;
+
+                System.Diagnostics.Process javacomp;
+                javacomp = System.Diagnostics.Process.Start(psi);
+                javacomp.WaitForExit();
+
+
+                //now load in class file
+                ClassRecord class1 = new ClassRecord();
+                class1.LoadClassFromFile(scriptName + ".class");
+                class1.PrintToConsole();
+                //Console.WriteLine();
+                this._mainMemory.MethodArea.Classes.Add(class1);
+                class1.AddMethodsToMemory(this._mainMemory.MethodArea);
+
+                Thread newThread = new Thread();
+                this._threads.Add(newThread);
+                newThread.currentClass = class1;
+                newThread.scriptInfo = scriptInfo;
+
+                //now delete the created files
+                System.IO.File.Delete(scriptName + ".java");
+                System.IO.File.Delete(scriptName + ".class");
+                //this.OnFrame();
+            }
+            catch (Exception e)
+            {
+                Console.WriteLine("exception");
+                Console.WriteLine(e.StackTrace);
+                Console.WriteLine(e.Message);
+            }
+        }
+
+        private class CompileInfo
+        {
+            public string script;
+            public string scriptName;
+
+            public CompileInfo()
+            {
+
+            }
+        }
+    }
+}
diff --git a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Types/ArrayReference.cs b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Types/ArrayReference.cs
index 40e2e22..0c4d623 100644
--- a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Types/ArrayReference.cs
+++ b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Types/ArrayReference.cs
@@ -1,10 +1,10 @@
-using System;
-using System.Collections.Generic;
-using System.Text;
-
-namespace OpenSim.Region.Scripting.EmbeddedJVM.Types
-{
-    public class ArrayReference :BaseType
-    {
-    }
-}
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace OpenSim.Region.Scripting.EmbeddedJVM.Types
+{
+    public class ArrayReference :BaseType
+    {
+    }
+}
diff --git a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Types/BaseType.cs b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Types/BaseType.cs
index 4ee1720..7fc0a4f 100644
--- a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Types/BaseType.cs
+++ b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Types/BaseType.cs
@@ -1,10 +1,10 @@
-using System;
-using System.Collections.Generic;
-using System.Text;
-
-namespace OpenSim.Region.Scripting.EmbeddedJVM.Types
-{
-    public class BaseType : Object
-    {
-    }
-}
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace OpenSim.Region.Scripting.EmbeddedJVM.Types
+{
+    public class BaseType : Object
+    {
+    }
+}
diff --git a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Types/ObjectReference.cs b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Types/ObjectReference.cs
index 75d8e41..7718765 100644
--- a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Types/ObjectReference.cs
+++ b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Types/ObjectReference.cs
@@ -1,16 +1,16 @@
-using System;
-using System.Collections.Generic;
-using System.Text;
-
-namespace OpenSim.Region.Scripting.EmbeddedJVM.Types
-{
-    public class ObjectReference : BaseType
-    {
-        public ushort Reference;
-
-        public ObjectReference()
-        {
-
-        }
-    }
-}
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace OpenSim.Region.Scripting.EmbeddedJVM.Types
+{
+    public class ObjectReference : BaseType
+    {
+        public ushort Reference;
+
+        public ObjectReference()
+        {
+
+        }
+    }
+}
diff --git a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Types/PrimitiveTypes/Byte.cs b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Types/PrimitiveTypes/Byte.cs
index f5446dc..5a7b780 100644
--- a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Types/PrimitiveTypes/Byte.cs
+++ b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Types/PrimitiveTypes/Byte.cs
@@ -1,10 +1,10 @@
-using System;
-using System.Collections.Generic;
-using System.Text;
-
-namespace OpenSim.Region.Scripting.EmbeddedJVM.Types.PrimitiveTypes
-{
-    public class Byte : BaseType
-    {
-    }
-}
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace OpenSim.Region.Scripting.EmbeddedJVM.Types.PrimitiveTypes
+{
+    public class Byte : BaseType
+    {
+    }
+}
diff --git a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Types/PrimitiveTypes/Char.cs b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Types/PrimitiveTypes/Char.cs
index 89824b4..c87ee8f 100644
--- a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Types/PrimitiveTypes/Char.cs
+++ b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Types/PrimitiveTypes/Char.cs
@@ -1,10 +1,10 @@
-using System;
-using System.Collections.Generic;
-using System.Text;
-
-namespace OpenSim.Region.Scripting.EmbeddedJVM.Types.PrimitiveTypes
-{
-    public class Char : BaseType
-    {
-    }
-}
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace OpenSim.Region.Scripting.EmbeddedJVM.Types.PrimitiveTypes
+{
+    public class Char : BaseType
+    {
+    }
+}
diff --git a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Types/PrimitiveTypes/Float.cs b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Types/PrimitiveTypes/Float.cs
index 2638c20..982e748 100644
--- a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Types/PrimitiveTypes/Float.cs
+++ b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Types/PrimitiveTypes/Float.cs
@@ -1,16 +1,16 @@
-using System;
-using System.Collections.Generic;
-using System.Text;
-
-namespace OpenSim.Region.Scripting.EmbeddedJVM.Types.PrimitiveTypes
-{
-    public class Float : BaseType
-    {
-        public float mValue = 0;
-
-        public Float()
-        {
-
-        }
-    }
-}
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace OpenSim.Region.Scripting.EmbeddedJVM.Types.PrimitiveTypes
+{
+    public class Float : BaseType
+    {
+        public float mValue = 0;
+
+        public Float()
+        {
+
+        }
+    }
+}
diff --git a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Types/PrimitiveTypes/Int.cs b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Types/PrimitiveTypes/Int.cs
index 0155e72..073a9b3 100644
--- a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Types/PrimitiveTypes/Int.cs
+++ b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/Types/PrimitiveTypes/Int.cs
@@ -1,16 +1,16 @@
-using System;
-using System.Collections.Generic;
-using System.Text;
-
-namespace OpenSim.Region.Scripting.EmbeddedJVM.Types.PrimitiveTypes
-{
-    public class Int : BaseType
-    {
-        public int mValue = 0;
-
-        public Int()
-        {
-
-        }
-    }
-}
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace OpenSim.Region.Scripting.EmbeddedJVM.Types.PrimitiveTypes
+{
+    public class Int : BaseType
+    {
+        public int mValue = 0;
+
+        public Int()
+        {
+
+        }
+    }
+}
diff --git a/OpenSim/Region/Environment/Scenes/scripting/Engines/LSLEngine/LSLHandler/Engine.cs b/OpenSim/Region/Environment/Scenes/scripting/Engines/LSLEngine/LSLHandler/Engine.cs
index 8b957d3..012a00e 100644
--- a/OpenSim/Region/Environment/Scenes/scripting/Engines/LSLEngine/LSLHandler/Engine.cs
+++ b/OpenSim/Region/Environment/Scenes/scripting/Engines/LSLEngine/LSLHandler/Engine.cs
@@ -1,140 +1,140 @@
-using System;
-using System.Reflection;
-using System.Reflection.Emit;
-using System.Threading;
-
-using OpenSim.Region.Scripting;
-
-namespace OpenSim.ScriptEngines.LSL
-{
-
-    
-    public class Engine
-    {
-        public void Start(ScriptInfo WorldAPI)
-        {
-            
-
-            
-            // Create Assembly Name
-            AssemblyName asmName = new AssemblyName();
-            asmName.Name = "TestAssembly";
-
-            // Create Assembly
-            AssemblyBuilder asmBuilder =
-                Thread.GetDomain().DefineDynamicAssembly
-            (asmName, AssemblyBuilderAccess.RunAndSave);
-
-            // Create a module (and save to disk)
-            ModuleBuilder modBuilder = asmBuilder.DefineDynamicModule
-                            (asmName.Name, asmName.Name  + ".dll");
-
-            // Create a Class (/Type)
-            TypeBuilder typeBuilder = modBuilder.DefineType(
-                                    "MyClass",
-                                    TypeAttributes.Public,
-                                    typeof(object),
-                                    new Type[] { typeof(LSL_CLRInterface.LSLScript) });
-
-
-
-            /*
-             * Generate the IL itself
-             */
-
-            GenerateIL(WorldAPI, typeBuilder);
-
-
-            /*
-             * Done generating, create a type and run it.
-             */
-
-            // Create type object for the class (after defining fields and methods)
-            Type type = typeBuilder.CreateType();
-
-            asmBuilder.Save("TestAssembly.dll");
-
-            // Create an instance we can play with
-            //LSLScript hello = (LSLScript)Activator.CreateInstance(type);
-            LSL_CLRInterface.LSLScript MyScript = (LSL_CLRInterface.LSLScript)Activator.CreateInstance(type);
-
-            // Play with it
-            MyScript.event_state_entry("Test");
-        }
-
-        private void GenerateIL(ScriptInfo WorldAPI, TypeBuilder typeBuilder)
-        {
-
-
-            // For debug
-            LSO_Parser LSOP = new LSO_Parser();
-            LSOP.ParseFile("LSO\\CloseToDefault.lso", WorldAPI, ref typeBuilder);
-            return;
-
-
-            // Override a Method / Function
-            MethodBuilder methodBuilder = typeBuilder.DefineMethod("event_state_entry",
-                         MethodAttributes.Private | MethodAttributes.Virtual,
-                         typeof(void),
-                         new Type[] { typeof(object) });
-
-            typeBuilder.DefineMethodOverride(methodBuilder,
-                    typeof(LSL_CLRInterface.LSLScript).GetMethod("event_state_entry"));
-
-            // Create the IL generator
-            ILGenerator il = methodBuilder.GetILGenerator();
-                
-
-            /*
-             * TRY
-             */
-            il.BeginExceptionBlock();
-
-            // Push "Hello World!" string to stack
-            il.Emit(OpCodes.Ldstr, "Hello World!");
-
-            // Push Console.WriteLine command to stack ... Console.WriteLine("Hello World!");
-            il.Emit(OpCodes.Call, typeof(Console).GetMethod
-                ("WriteLine", new Type[] { typeof(string) }));
-
-            //il.EmitCall(OpCodes.Callvirt
-            //il.Emit(OpCodes.Call, typeof(WorldAPI).GetMethod
-                //("TestFunction"));
-
-
-            //il.ThrowException(typeof(NotSupportedException));
-
-          
-            /*
-             * CATCH
-             */
-            il.BeginCatchBlock(typeof(Exception));
-
-            // Push "Hello World!" string to stack
-            il.Emit(OpCodes.Ldstr, "Something went wrong: ");
-
-            //call void [mscorlib]System.Console::WriteLine(string)
-            il.Emit(OpCodes.Call, typeof(Console).GetMethod
-                ("Write", new Type[] { typeof(string) }));
-
-            //callvirt instance string [mscorlib]System.Exception::get_Message()
-            il.Emit(OpCodes.Callvirt, typeof(Exception).GetMethod
-                ("get_Message"));
-                 
-            //call void [mscorlib]System.Console::WriteLine(string)
-            il.Emit(OpCodes.Call, typeof(Console).GetMethod
-                ("WriteLine", new Type[] { typeof(string) }));
-
-            /*
-             * END TRY
-             */
-            il.EndExceptionBlock();
-
-
-            // Push "Return from current method, with return value if present" to stack
-            il.Emit(OpCodes.Ret);
-
-
-        }
-    }
-}
+using System;
+using System.Reflection;
+using System.Reflection.Emit;
+using System.Threading;
+
+using OpenSim.Region.Scripting;
+
+namespace OpenSim.ScriptEngines.LSL
+{
+
+    
+    public class Engine
+    {
+        public void Start(ScriptInfo WorldAPI)
+        {
+            
+
+            
+            // Create Assembly Name
+            AssemblyName asmName = new AssemblyName();
+            asmName.Name = "TestAssembly";
+
+            // Create Assembly
+            AssemblyBuilder asmBuilder =
+                Thread.GetDomain().DefineDynamicAssembly
+            (asmName, AssemblyBuilderAccess.RunAndSave);
+
+            // Create a module (and save to disk)
+            ModuleBuilder modBuilder = asmBuilder.DefineDynamicModule
+                            (asmName.Name, asmName.Name  + ".dll");
+
+            // Create a Class (/Type)
+            TypeBuilder typeBuilder = modBuilder.DefineType(
+                                    "MyClass",
+                                    TypeAttributes.Public,
+                                    typeof(object),
+                                    new Type[] { typeof(LSL_CLRInterface.LSLScript) });
+
+
+
+            /*
+             * Generate the IL itself
+             */
+
+            GenerateIL(WorldAPI, typeBuilder);
+
+
+            /*
+             * Done generating, create a type and run it.
+             */
+
+            // Create type object for the class (after defining fields and methods)
+            Type type = typeBuilder.CreateType();
+
+            asmBuilder.Save("TestAssembly.dll");
+
+            // Create an instance we can play with
+            //LSLScript hello = (LSLScript)Activator.CreateInstance(type);
+            LSL_CLRInterface.LSLScript MyScript = (LSL_CLRInterface.LSLScript)Activator.CreateInstance(type);
+
+            // Play with it
+            MyScript.event_state_entry("Test");
+        }
+
+        private void GenerateIL(ScriptInfo WorldAPI, TypeBuilder typeBuilder)
+        {
+
+
+            // For debug
+            LSO_Parser LSOP = new LSO_Parser();
+            LSOP.ParseFile("LSO\\CloseToDefault.lso", WorldAPI, ref typeBuilder);
+            return;
+
+
+            // Override a Method / Function
+            MethodBuilder methodBuilder = typeBuilder.DefineMethod("event_state_entry",
+                         MethodAttributes.Private | MethodAttributes.Virtual,
+                         typeof(void),
+                         new Type[] { typeof(object) });
+
+            typeBuilder.DefineMethodOverride(methodBuilder,
+                    typeof(LSL_CLRInterface.LSLScript).GetMethod("event_state_entry"));
+
+            // Create the IL generator
+            ILGenerator il = methodBuilder.GetILGenerator();
+                
+
+            /*
+             * TRY
+             */
+            il.BeginExceptionBlock();
+
+            // Push "Hello World!" string to stack
+            il.Emit(OpCodes.Ldstr, "Hello World!");
+
+            // Push Console.WriteLine command to stack ... Console.WriteLine("Hello World!");
+            il.Emit(OpCodes.Call, typeof(Console).GetMethod
+                ("WriteLine", new Type[] { typeof(string) }));
+
+            //il.EmitCall(OpCodes.Callvirt
+            //il.Emit(OpCodes.Call, typeof(WorldAPI).GetMethod
+                //("TestFunction"));
+
+
+            //il.ThrowException(typeof(NotSupportedException));
+
+          
+            /*
+             * CATCH
+             */
+            il.BeginCatchBlock(typeof(Exception));
+
+            // Push "Hello World!" string to stack
+            il.Emit(OpCodes.Ldstr, "Something went wrong: ");
+
+            //call void [mscorlib]System.Console::WriteLine(string)
+            il.Emit(OpCodes.Call, typeof(Console).GetMethod
+                ("Write", new Type[] { typeof(string) }));
+
+            //callvirt instance string [mscorlib]System.Exception::get_Message()
+            il.Emit(OpCodes.Callvirt, typeof(Exception).GetMethod
+                ("get_Message"));
+                 
+            //call void [mscorlib]System.Console::WriteLine(string)
+            il.Emit(OpCodes.Call, typeof(Console).GetMethod
+                ("WriteLine", new Type[] { typeof(string) }));
+
+            /*
+             * END TRY
+             */
+            il.EndExceptionBlock();
+
+
+            // Push "Return from current method, with return value if present" to stack
+            il.Emit(OpCodes.Ret);
+
+
+        }
+    }
+}
diff --git a/OpenSim/Region/Environment/Scenes/scripting/Engines/LSLEngine/LSLHandler/LSL_CLRInterface.cs b/OpenSim/Region/Environment/Scenes/scripting/Engines/LSLEngine/LSLHandler/LSL_CLRInterface.cs
index dc612ff..57bbf11 100644
--- a/OpenSim/Region/Environment/Scenes/scripting/Engines/LSLEngine/LSLHandler/LSL_CLRInterface.cs
+++ b/OpenSim/Region/Environment/Scenes/scripting/Engines/LSLEngine/LSLHandler/LSL_CLRInterface.cs
@@ -1,51 +1,51 @@
-using System;
-using System.Collections.Generic;
-using System.Text;
-
-namespace OpenSim.ScriptEngines.LSL
-{
-    public class LSL_CLRInterface
-    {
-        public interface LSLScript
-        {
-            //public virtual void Run(object arg)
-            //{
-            //}
-            //void Run(object arg);
-
-            void event_state_entry(object arg);
-            //void event_state_exit();
-            void event_touch_start(object arg);
-            //void event_touch();
-            //void event_touch_end();
-            //void event_collision_start();
-            //void event_collision();
-            //void event_collision_end();
-            //void event_land_collision_start();
-            //void event_land_collision();
-            //void event_land_collision_end();
-            //void event_timer();
-            //void event_listen();
-            //void event_on_rez();
-            //void event_sensor();
-            //void event_no_sensor();
-            //void event_control();
-            //void event_money();
-            //void event_email();
-            //void event_at_target();
-            //void event_not_at_target();
-            //void event_at_rot_target();
-            //void event_not_at_rot_target();
-            //void event_run_time_permissions();
-            //void event_changed();
-            //void event_attach();
-            //void event_dataserver();
-            //void event_link_message();
-            //void event_moving_start();
-            //void event_moving_end();
-            //void event_object_rez();
-            //void event_remote_data();
-            //void event_http_response();
-        }
-    }
-}
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace OpenSim.ScriptEngines.LSL
+{
+    public class LSL_CLRInterface
+    {
+        public interface LSLScript
+        {
+            //public virtual void Run(object arg)
+            //{
+            //}
+            //void Run(object arg);
+
+            void event_state_entry(object arg);
+            //void event_state_exit();
+            void event_touch_start(object arg);
+            //void event_touch();
+            //void event_touch_end();
+            //void event_collision_start();
+            //void event_collision();
+            //void event_collision_end();
+            //void event_land_collision_start();
+            //void event_land_collision();
+            //void event_land_collision_end();
+            //void event_timer();
+            //void event_listen();
+            //void event_on_rez();
+            //void event_sensor();
+            //void event_no_sensor();
+            //void event_control();
+            //void event_money();
+            //void event_email();
+            //void event_at_target();
+            //void event_not_at_target();
+            //void event_at_rot_target();
+            //void event_not_at_rot_target();
+            //void event_run_time_permissions();
+            //void event_changed();
+            //void event_attach();
+            //void event_dataserver();
+            //void event_link_message();
+            //void event_moving_start();
+            //void event_moving_end();
+            //void event_object_rez();
+            //void event_remote_data();
+            //void event_http_response();
+        }
+    }
+}
diff --git a/OpenSim/Region/Environment/Scenes/scripting/Engines/LSLEngine/LSLHandler/LSO_Enums.cs b/OpenSim/Region/Environment/Scenes/scripting/Engines/LSLEngine/LSLHandler/LSO_Enums.cs
index edeccdd..b45abe0 100644
--- a/OpenSim/Region/Environment/Scenes/scripting/Engines/LSLEngine/LSLHandler/LSO_Enums.cs
+++ b/OpenSim/Region/Environment/Scenes/scripting/Engines/LSLEngine/LSLHandler/LSO_Enums.cs
@@ -1,485 +1,485 @@
-using System;
-using System.Collections.Generic;
-using System.Text;
-
-namespace OpenSim.ScriptEngines.LSL
-{
-    static class LSO_Enums
-    {
-
-        public enum Variable_Type_Codes
-        {
-            Void = 0,
-            Integer = 1,
-            Float = 2,
-            String = 3,
-            Key = 4,
-            Vector = 5,
-            Rotation = 6,
-            List = 7
-        }
-        public enum Event_Mask_Values
-        {
-            state_entry = 0,
-            state_exit = 1,
-            touch_start = 2,
-            touch = 3,
-            touch_end = 4,
-            collision_start = 5,
-            collision = 6,
-            collision_end = 7,
-            land_collision_start = 8,
-            land_collision = 9,
-            land_collision_end = 10,
-            timer = 11,
-            listen = 12,
-            on_rez = 13,
-            sensor = 14,
-            no_sensor = 15,
-            control = 16,
-            money = 17,
-            email = 18,
-            at_target = 19,
-            not_at_target = 20,
-            at_rot_target = 21,
-            not_at_rot_target = 22,
-            run_time_permissions = 23,
-            changed = 24,
-            attach = 25,
-            dataserver = 26,
-            link_message = 27,
-            moving_start = 28,
-            moving_end = 29,
-            object_rez = 30,
-            remote_data = 31,
-            http_response = 32
-        }
-        public enum Operation_Table
-        {
-            NOOP = 0x0,
-            POP = 0x1,
-            POPS = 0x2,
-            POPL = 0x3,
-            POPV = 0x4,
-            POPQ = 0x5,
-            POPARG = 0x6,
-            POPIP = 0x7,
-            POPBP = 0x8,
-            POPSP = 0x9,
-            POPSLR = 0xa,
-            DUP = 0x20,
-            DUPS = 0x21,
-            DUPL = 0x22,
-            DUPV = 0x23,
-            DUPQ = 0x24,
-            STORE = 0x30,
-            STORES = 0x31,
-            STOREL = 0x32,
-            STOREV = 0x33,
-            STOREQ = 0x34,
-            STOREG = 0x35,
-            STOREGS = 0x36,
-            STOREGL = 0x37,
-            STOREGV = 0x38,
-            STOREGQ = 0x39,
-            LOADP = 0x3a,
-            LOADSP = 0x3b,
-            LOADLP = 0x3c,
-            LOADVP = 0x3d,
-            LOADQP = 0x3e,
-            LOADGP = 0x3f,
-            LOADGSP = 0x40,
-            LOADGLP = 0x41,
-            LOADGVP = 0x42,
-            LOADGQP = 0x43,
-            PUSH = 0x50,
-            PUSHS = 0x51,
-            PUSHL = 0x52,
-            PUSHV = 0x53,
-            PUSHQ = 0x54,
-            PUSHG = 0x55,
-            PUSHGS = 0x56,
-            PUSHGL = 0x57,
-            PUSHGV = 0x58,
-            PUSHGQ = 0x59,
-            PUSHIP = 0x5a,
-            PUSHBP = 0x5b,
-            PUSHSP = 0x5c,
-            PUSHARGB = 0x5d,
-            PUSHARGI = 0x5e,
-            PUSHARGF = 0x5f,
-            PUSHARGS = 0x60,
-            PUSHARGV = 0x61,
-            PUSHARGQ = 0x62,
-            PUSHE = 0x63,
-            PUSHEV = 0x64,
-            PUSHEQ = 0x65,
-            PUSHARGE = 0x66,
-            ADD = 0x70,
-            SUB = 0x71,
-            MUL = 0x72,
-            DIV = 0x73,
-            MOD = 0x74,
-            EQ = 0x75,
-            NEQ = 0x76,
-            LEQ = 0x77,
-            GEQ = 0x78,
-            LESS = 0x79,
-            GREATER = 0x7a,
-            BITAND = 0x7b,
-            BITOR = 0x7c,
-            BITXOR = 0x7d,
-            BOOLAND = 0x7e,
-            BOOLOR = 0x7f,
-            NEG = 0x80,
-            BITNOT = 0x81,
-            BOOLNOT = 0x82,
-            JUMP = 0x90,
-            JUMPIF = 0x91,
-            JUMPNIF = 0x92,
-            STATE = 0x93,
-            CALL = 0x94,
-            RETURN = 0x95,
-            CAST = 0xa0,
-            STACKTOS = 0xb0,
-            STACKTOL = 0xb1,
-            PRINT = 0xc0,
-            CALLLIB = 0xd0,
-            CALLLIB_TWO_BYTE = 0xd1,
-            SHL = 0xe0,
-            SHR = 0xe1
-        }
-        public enum BuiltIn_Functions
-        {
-            llSin = 0,
-            llCos = 1,
-            llTan = 2,
-            llAtan2 = 3,
-            llSqrt = 4,
-            llPow = 5,
-            llAbs = 6,
-            llFabs = 7,
-            llFrand = 8,
-            llFloor = 9,
-            llCeil = 10,
-            llRound = 11,
-            llVecMag = 12,
-            llVecNorm = 13,
-            llVecDist = 14,
-            llRot2Euler = 15,
-            llEuler2Rot = 16,
-            llAxes2Rot = 17,
-            llRot2Fwd = 18,
-            llRot2Left = 19,
-            llRot2Up = 20,
-            llRotBetween = 21,
-            llWhisper = 22,
-            llSay = 23,
-            llShout = 24,
-            llListen = 25,
-            llListenControl = 26,
-            llListenRemove = 27,
-            llSensor = 28,
-            llSensorRepeat = 29,
-            llSensorRemove = 30,
-            llDetectedName = 31,
-            llDetectedKey = 32,
-            llDetectedOwner = 33,
-            llDetectedType = 34,
-            llDetectedPos = 35,
-            llDetectedVel = 36,
-            llDetectedGrab = 37,
-            llDetectedRot = 38,
-            llDetectedGroup = 39,
-            llDetectedLinkNumber = 40,
-            llDie = 41,
-            llGround = 42,
-            llCloud = 43,
-            llWind = 44,
-            llSetStatus = 45,
-            llGetStatus = 46,
-            llSetScale = 47,
-            llGetScale = 48,
-            llSetColor = 49,
-            llGetAlpha = 50,
-            llSetAlpha = 51,
-            llGetColor = 52,
-            llSetTexture = 53,
-            llScaleTexture = 54,
-            llOffsetTexture = 55,
-            llRotateTexture = 56,
-            llGetTexture = 57,
-            llSetPos = 58,
-            llGetPos = 59,
-            llGetLocalPos = 60,
-            llSetRot = 61,
-            llGetRot = 62,
-            llGetLocalRot = 63,
-            llSetForce = 64,
-            llGetForce = 65,
-            llTarget = 66,
-            llTargetRemove = 67,
-            llRotTarget = 68,
-            llRotTargetRemove = 69,
-            llMoveToTarget = 70,
-            llStopMoveToTarget = 71,
-            llApplyImpulse = 72,
-            llApplyRotationalImpulse = 73,
-            llSetTorque = 74,
-            llGetTorque = 75,
-            llSetForceAndTorque = 76,
-            llGetVel = 77,
-            llGetAccel = 78,
-            llGetOmega = 79,
-            llGetTimeOfDay = 80,
-            llGetWallclock = 81,
-            llGetTime = 82,
-            llResetTime = 83,
-            llGetAndResetTime = 84,
-            llSound = 85,
-            llPlaySound = 86,
-            llLoopSound = 87,
-            llLoopSoundMaster = 88,
-            llLoopSoundSlave = 89,
-            llPlaySoundSlave = 90,
-            llTriggerSound = 91,
-            llStopSound = 92,
-            llPreloadSound = 93,
-            llGetSubString = 94,
-            llDeleteSubString = 95,
-            llInsertString = 96,
-            llToUpper = 97,
-            llToLower = 98,
-            llGiveMoney = 99,
-            llMakeExplosion = 100,
-            llMakeFountain = 101,
-            llMakeSmoke = 102,
-            llMakeFire = 103,
-            llRezObject = 104,
-            llLookAt = 105,
-            llStopLookAt = 106,
-            llSetTimerEvent = 107,
-            llSleep = 108,
-            llGetMass = 109,
-            llCollisionFilter = 110,
-            llTakeControls = 111,
-            llReleaseControls = 112,
-            llAttachToAvatar = 113,
-            llDetachFromAvatar = 114,
-            llTakeCamera = 115,
-            llReleaseCamera = 116,
-            llGetOwner = 117,
-            llInstantMessage = 118,
-            llEmail = 119,
-            llGetNextEmail = 120,
-            llGetKey = 121,
-            llSetBuoyancy = 122,
-            llSetHoverHeight = 123,
-            llStopHover = 124,
-            llMinEventDelay = 125,
-            llSoundPreload = 126,
-            llRotLookAt = 127,
-            llStringLength = 128,
-            llStartAnimation = 129,
-            llStopAnimation = 130,
-            llPointAt = 131,
-            llStopPointAt = 132,
-            llTargetOmega = 133,
-            llGetStartParameter = 134,
-            llGodLikeRezObject = 135,
-            llRequestPermissions = 136,
-            llGetPermissionsKey = 137,
-            llGetPermissions = 138,
-            llGetLinkNumber = 139,
-            llSetLinkColor = 140,
-            llCreateLink = 141,
-            llBreakLink = 142,
-            llBreakAllLinks = 143,
-            llGetLinkKey = 144,
-            llGetLinkName = 145,
-            llGetInventoryNumber = 146,
-            llGetInventoryName = 147,
-            llSetScriptState = 148,
-            llGetEnergy = 149,
-            llGiveInventory = 150,
-            llRemoveInventory = 151,
-            llSetText = 152,
-            llWater = 153,
-            llPassTouches = 154,
-            llRequestAgentData = 155,
-            llRequestInventoryData = 156,
-            llSetDamage = 157,
-            llTeleportAgentHome = 158,
-            llModifyLand = 159,
-            llCollisionSound = 160,
-            llCollisionSprite = 161,
-            llGetAnimation = 162,
-            llResetScript = 163,
-            llMessageLinked = 164,
-            llPushObject = 165,
-            llPassCollisions = 166,
-            llGetScriptName = 167,
-            llGetNumberOfSides = 168,
-            llAxisAngle2Rot = 169,
-            llRot2Axis = 170,
-            llRot2Angle = 171,
-            llAcos = 172,
-            llAsin = 173,
-            llAngleBetween = 174,
-            llGetInventoryKey = 175,
-            llAllowInventoryDrop = 176,
-            llGetSunDirection = 177,
-            llGetTextureOffset = 178,
-            llGetTextureScale = 179,
-            llGetTextureRot = 180,
-            llSubStringIndex = 181,
-            llGetOwnerKey = 182,
-            llGetCenterOfMass = 183,
-            llListSort = 184,
-            llGetListLength = 185,
-            llList2Integer = 186,
-            llList2Float = 187,
-            llList2String = 188,
-            llList2Key = 189,
-            llList2Vector = 190,
-            llList2Rot = 191,
-            llList2List = 192,
-            llDeleteSubList = 193,
-            llGetListEntryType = 194,
-            llList2CSV = 195,
-            llCSV2List = 196,
-            llListRandomize = 197,
-            llList2ListStrided = 198,
-            llGetRegionCorner = 199,
-            llListInsertList = 200,
-            llListFindList = 201,
-            llGetObjectName = 202,
-            llSetObjectName = 203,
-            llGetDate = 204,
-            llEdgeOfWorld = 205,
-            llGetAgentInfo = 206,
-            llAdjustSoundVolume = 207,
-            llSetSoundQueueing = 208,
-            llSetSoundRadius = 209,
-            llKey2Name = 210,
-            llSetTextureAnim = 211,
-            llTriggerSoundLimited = 212,
-            llEjectFromLand = 213,
-            llParseString2List = 214,
-            llOverMyLand = 215,
-            llGetLandOwnerAt = 216,
-            llGetNotecardLine = 217,
-            llGetAgentSize = 218,
-            llSameGroup = 219,
-            llUnSit = 220,
-            llGroundSlope = 221,
-            llGroundNormal = 222,
-            llGroundContour = 223,
-            llGetAttached = 224,
-            llGetFreeMemory = 225,
-            llGetRegionName = 226,
-            llGetRegionTimeDilation = 227,
-            llGetRegionFPS = 228,
-            llParticleSystem = 229,
-            llGroundRepel = 230,
-            llGiveInventoryList = 231,
-            llSetVehicleType = 232,
-            llSetVehicleFloatParam = 233,
-            llSetVehicleVectorParam = 234,
-            llSetVehicleRotationParam = 235,
-            llSetVehicleFlags = 236,
-            llRemoveVehicleFlags = 237,
-            llSitTarget = 238,
-            llAvatarOnSitTarget = 239,
-            llAddToLandPassList = 240,
-            llSetTouchText = 241,
-            llSetSitText = 242,
-            llSetCameraEyeOffset = 243,
-            llSetCameraAtOffset = 244,
-            llDumpList2String = 245,
-            llScriptDanger = 246,
-            llDialog = 247,
-            llVolumeDetect = 248,
-            llResetOtherScript = 249,
-            llGetScriptState = 250,
-            llRemoteLoadScript = 251,
-            llSetRemoteScriptAccessPin = 252,
-            llRemoteLoadScriptPin = 253,
-            llOpenRemoteDataChannel = 254,
-            llSendRemoteData = 255,
-            llRemoteDataReply = 256,
-            llCloseRemoteDataChannel = 257,
-            llMD5String = 258,
-            llSetPrimitiveParams = 259,
-            llStringToBase64 = 260,
-            llBase64ToString = 261,
-            llXorBase64Strings = 262,
-            llRemoteDataSetRegion = 263,
-            llLog10 = 264,
-            llLog = 265,
-            llGetAnimationList = 266,
-            llSetParcelMusicURL = 267,
-            llGetRootPosition = 268,
-            llGetRootRotation = 269,
-            llGetObjectDesc = 270,
-            llSetObjectDesc = 271,
-            llGetCreator = 272,
-            llGetTimestamp = 273,
-            llSetLinkAlpha = 274,
-            llGetNumberOfPrims = 275,
-            llGetNumberOfNotecardLines = 276,
-            llGetBoundingBox = 277,
-            llGetGeometricCenter = 278,
-            llGetPrimitiveParams = 279,
-            llIntegerToBase64 = 280,
-            llBase64ToInteger = 281,
-            llGetGMTclock = 282,
-            llGetSimulatorHostname = 283,
-            llSetLocalRot = 284,
-            llParseStringKeepNulls = 285,
-            llRezAtRoot = 286,
-            llGetObjectPermMask = 287,
-            llSetObjectPermMask = 288,
-            llGetInventoryPermMask = 289,
-            llSetInventoryPermMask = 290,
-            llGetInventoryCreator = 291,
-            llOwnerSay = 292,
-            llRequestSimulatorData = 293,
-            llForceMouselook = 294,
-            llGetObjectMass = 295,
-            llListReplaceList = 296,
-            llLoadURL = 297,
-            llParcelMediaCommandList = 298,
-            llParcelMediaQuery = 299,
-            llModPow = 300,
-            llGetInventoryType = 301,
-            llSetPayPrice = 302,
-            llGetCameraPos = 303,
-            llGetCameraRot = 304,
-            llSetPrimURL = 305,
-            llRefreshPrimURL = 306,
-            llEscapeURL = 307,
-            llUnescapeURL = 308,
-            llMapDestination = 309,
-            llAddToLandBanList = 310,
-            llRemoveFromLandPassList = 311,
-            llRemoveFromLandBanList = 312,
-            llSetCameraParams = 313,
-            llClearCameraParams = 314,
-            llListStatistics = 315,
-            llGetUnixTime = 316,
-            llGetParcelFlags = 317,
-            llGetRegionFlags = 318,
-            llXorBase64StringsCorrect = 319,
-            llHTTPRequest = 320,
-            llResetLandBanList = 321,
-            llResetLandPassList = 322,
-            llGetParcelPrimCount = 323,
-            llGetParcelPrimOwners = 324,
-            llGetObjectPrimCount = 325,
-            llGetParcelMaxPrims = 326,
-            llGetParcelDetails = 327
-        }
-
-    }
-}
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace OpenSim.ScriptEngines.LSL
+{
+    static class LSO_Enums
+    {
+
+        public enum Variable_Type_Codes
+        {
+            Void = 0,
+            Integer = 1,
+            Float = 2,
+            String = 3,
+            Key = 4,
+            Vector = 5,
+            Rotation = 6,
+            List = 7
+        }
+        public enum Event_Mask_Values
+        {
+            state_entry = 0,
+            state_exit = 1,
+            touch_start = 2,
+            touch = 3,
+            touch_end = 4,
+            collision_start = 5,
+            collision = 6,
+            collision_end = 7,
+            land_collision_start = 8,
+            land_collision = 9,
+            land_collision_end = 10,
+            timer = 11,
+            listen = 12,
+            on_rez = 13,
+            sensor = 14,
+            no_sensor = 15,
+            control = 16,
+            money = 17,
+            email = 18,
+            at_target = 19,
+            not_at_target = 20,
+            at_rot_target = 21,
+            not_at_rot_target = 22,
+            run_time_permissions = 23,
+            changed = 24,
+            attach = 25,
+            dataserver = 26,
+            link_message = 27,
+            moving_start = 28,
+            moving_end = 29,
+            object_rez = 30,
+            remote_data = 31,
+            http_response = 32
+        }
+        public enum Operation_Table
+        {
+            NOOP = 0x0,
+            POP = 0x1,
+            POPS = 0x2,
+            POPL = 0x3,
+            POPV = 0x4,
+            POPQ = 0x5,
+            POPARG = 0x6,
+            POPIP = 0x7,
+            POPBP = 0x8,
+            POPSP = 0x9,
+            POPSLR = 0xa,
+            DUP = 0x20,
+            DUPS = 0x21,
+            DUPL = 0x22,
+            DUPV = 0x23,
+            DUPQ = 0x24,
+            STORE = 0x30,
+            STORES = 0x31,
+            STOREL = 0x32,
+            STOREV = 0x33,
+            STOREQ = 0x34,
+            STOREG = 0x35,
+            STOREGS = 0x36,
+            STOREGL = 0x37,
+            STOREGV = 0x38,
+            STOREGQ = 0x39,
+            LOADP = 0x3a,
+            LOADSP = 0x3b,
+            LOADLP = 0x3c,
+            LOADVP = 0x3d,
+            LOADQP = 0x3e,
+            LOADGP = 0x3f,
+            LOADGSP = 0x40,
+            LOADGLP = 0x41,
+            LOADGVP = 0x42,
+            LOADGQP = 0x43,
+            PUSH = 0x50,
+            PUSHS = 0x51,
+            PUSHL = 0x52,
+            PUSHV = 0x53,
+            PUSHQ = 0x54,
+            PUSHG = 0x55,
+            PUSHGS = 0x56,
+            PUSHGL = 0x57,
+            PUSHGV = 0x58,
+            PUSHGQ = 0x59,
+            PUSHIP = 0x5a,
+            PUSHBP = 0x5b,
+            PUSHSP = 0x5c,
+            PUSHARGB = 0x5d,
+            PUSHARGI = 0x5e,
+            PUSHARGF = 0x5f,
+            PUSHARGS = 0x60,
+            PUSHARGV = 0x61,
+            PUSHARGQ = 0x62,
+            PUSHE = 0x63,
+            PUSHEV = 0x64,
+            PUSHEQ = 0x65,
+            PUSHARGE = 0x66,
+            ADD = 0x70,
+            SUB = 0x71,
+            MUL = 0x72,
+            DIV = 0x73,
+            MOD = 0x74,
+            EQ = 0x75,
+            NEQ = 0x76,
+            LEQ = 0x77,
+            GEQ = 0x78,
+            LESS = 0x79,
+            GREATER = 0x7a,
+            BITAND = 0x7b,
+            BITOR = 0x7c,
+            BITXOR = 0x7d,
+            BOOLAND = 0x7e,
+            BOOLOR = 0x7f,
+            NEG = 0x80,
+            BITNOT = 0x81,
+            BOOLNOT = 0x82,
+            JUMP = 0x90,
+            JUMPIF = 0x91,
+            JUMPNIF = 0x92,
+            STATE = 0x93,
+            CALL = 0x94,
+            RETURN = 0x95,
+            CAST = 0xa0,
+            STACKTOS = 0xb0,
+            STACKTOL = 0xb1,
+            PRINT = 0xc0,
+            CALLLIB = 0xd0,
+            CALLLIB_TWO_BYTE = 0xd1,
+            SHL = 0xe0,
+            SHR = 0xe1
+        }
+        public enum BuiltIn_Functions
+        {
+            llSin = 0,
+            llCos = 1,
+            llTan = 2,
+            llAtan2 = 3,
+            llSqrt = 4,
+            llPow = 5,
+            llAbs = 6,
+            llFabs = 7,
+            llFrand = 8,
+            llFloor = 9,
+            llCeil = 10,
+            llRound = 11,
+            llVecMag = 12,
+            llVecNorm = 13,
+            llVecDist = 14,
+            llRot2Euler = 15,
+            llEuler2Rot = 16,
+            llAxes2Rot = 17,
+            llRot2Fwd = 18,
+            llRot2Left = 19,
+            llRot2Up = 20,
+            llRotBetween = 21,
+            llWhisper = 22,
+            llSay = 23,
+            llShout = 24,
+            llListen = 25,
+            llListenControl = 26,
+            llListenRemove = 27,
+            llSensor = 28,
+            llSensorRepeat = 29,
+            llSensorRemove = 30,
+            llDetectedName = 31,
+            llDetectedKey = 32,
+            llDetectedOwner = 33,
+            llDetectedType = 34,
+            llDetectedPos = 35,
+            llDetectedVel = 36,
+            llDetectedGrab = 37,
+            llDetectedRot = 38,
+            llDetectedGroup = 39,
+            llDetectedLinkNumber = 40,
+            llDie = 41,
+            llGround = 42,
+            llCloud = 43,
+            llWind = 44,
+            llSetStatus = 45,
+            llGetStatus = 46,
+            llSetScale = 47,
+            llGetScale = 48,
+            llSetColor = 49,
+            llGetAlpha = 50,
+            llSetAlpha = 51,
+            llGetColor = 52,
+            llSetTexture = 53,
+            llScaleTexture = 54,
+            llOffsetTexture = 55,
+            llRotateTexture = 56,
+            llGetTexture = 57,
+            llSetPos = 58,
+            llGetPos = 59,
+            llGetLocalPos = 60,
+            llSetRot = 61,
+            llGetRot = 62,
+            llGetLocalRot = 63,
+            llSetForce = 64,
+            llGetForce = 65,
+            llTarget = 66,
+            llTargetRemove = 67,
+            llRotTarget = 68,
+            llRotTargetRemove = 69,
+            llMoveToTarget = 70,
+            llStopMoveToTarget = 71,
+            llApplyImpulse = 72,
+            llApplyRotationalImpulse = 73,
+            llSetTorque = 74,
+            llGetTorque = 75,
+            llSetForceAndTorque = 76,
+            llGetVel = 77,
+            llGetAccel = 78,
+            llGetOmega = 79,
+            llGetTimeOfDay = 80,
+            llGetWallclock = 81,
+            llGetTime = 82,
+            llResetTime = 83,
+            llGetAndResetTime = 84,
+            llSound = 85,
+            llPlaySound = 86,
+            llLoopSound = 87,
+            llLoopSoundMaster = 88,
+            llLoopSoundSlave = 89,
+            llPlaySoundSlave = 90,
+            llTriggerSound = 91,
+            llStopSound = 92,
+            llPreloadSound = 93,
+            llGetSubString = 94,
+            llDeleteSubString = 95,
+            llInsertString = 96,
+            llToUpper = 97,
+            llToLower = 98,
+            llGiveMoney = 99,
+            llMakeExplosion = 100,
+            llMakeFountain = 101,
+            llMakeSmoke = 102,
+            llMakeFire = 103,
+            llRezObject = 104,
+            llLookAt = 105,
+            llStopLookAt = 106,
+            llSetTimerEvent = 107,
+            llSleep = 108,
+            llGetMass = 109,
+            llCollisionFilter = 110,
+            llTakeControls = 111,
+            llReleaseControls = 112,
+            llAttachToAvatar = 113,
+            llDetachFromAvatar = 114,
+            llTakeCamera = 115,
+            llReleaseCamera = 116,
+            llGetOwner = 117,
+            llInstantMessage = 118,
+            llEmail = 119,
+            llGetNextEmail = 120,
+            llGetKey = 121,
+            llSetBuoyancy = 122,
+            llSetHoverHeight = 123,
+            llStopHover = 124,
+            llMinEventDelay = 125,
+            llSoundPreload = 126,
+            llRotLookAt = 127,
+            llStringLength = 128,
+            llStartAnimation = 129,
+            llStopAnimation = 130,
+            llPointAt = 131,
+            llStopPointAt = 132,
+            llTargetOmega = 133,
+            llGetStartParameter = 134,
+            llGodLikeRezObject = 135,
+            llRequestPermissions = 136,
+            llGetPermissionsKey = 137,
+            llGetPermissions = 138,
+            llGetLinkNumber = 139,
+            llSetLinkColor = 140,
+            llCreateLink = 141,
+            llBreakLink = 142,
+            llBreakAllLinks = 143,
+            llGetLinkKey = 144,
+            llGetLinkName = 145,
+            llGetInventoryNumber = 146,
+            llGetInventoryName = 147,
+            llSetScriptState = 148,
+            llGetEnergy = 149,
+            llGiveInventory = 150,
+            llRemoveInventory = 151,
+            llSetText = 152,
+            llWater = 153,
+            llPassTouches = 154,
+            llRequestAgentData = 155,
+            llRequestInventoryData = 156,
+            llSetDamage = 157,
+            llTeleportAgentHome = 158,
+            llModifyLand = 159,
+            llCollisionSound = 160,
+            llCollisionSprite = 161,
+            llGetAnimation = 162,
+            llResetScript = 163,
+            llMessageLinked = 164,
+            llPushObject = 165,
+            llPassCollisions = 166,
+            llGetScriptName = 167,
+            llGetNumberOfSides = 168,
+            llAxisAngle2Rot = 169,
+            llRot2Axis = 170,
+            llRot2Angle = 171,
+            llAcos = 172,
+            llAsin = 173,
+            llAngleBetween = 174,
+            llGetInventoryKey = 175,
+            llAllowInventoryDrop = 176,
+            llGetSunDirection = 177,
+            llGetTextureOffset = 178,
+            llGetTextureScale = 179,
+            llGetTextureRot = 180,
+            llSubStringIndex = 181,
+            llGetOwnerKey = 182,
+            llGetCenterOfMass = 183,
+            llListSort = 184,
+            llGetListLength = 185,
+            llList2Integer = 186,
+            llList2Float = 187,
+            llList2String = 188,
+            llList2Key = 189,
+            llList2Vector = 190,
+            llList2Rot = 191,
+            llList2List = 192,
+            llDeleteSubList = 193,
+            llGetListEntryType = 194,
+            llList2CSV = 195,
+            llCSV2List = 196,
+            llListRandomize = 197,
+            llList2ListStrided = 198,
+            llGetRegionCorner = 199,
+            llListInsertList = 200,
+            llListFindList = 201,
+            llGetObjectName = 202,
+            llSetObjectName = 203,
+            llGetDate = 204,
+            llEdgeOfWorld = 205,
+            llGetAgentInfo = 206,
+            llAdjustSoundVolume = 207,
+            llSetSoundQueueing = 208,
+            llSetSoundRadius = 209,
+            llKey2Name = 210,
+            llSetTextureAnim = 211,
+            llTriggerSoundLimited = 212,
+            llEjectFromLand = 213,
+            llParseString2List = 214,
+            llOverMyLand = 215,
+            llGetLandOwnerAt = 216,
+            llGetNotecardLine = 217,
+            llGetAgentSize = 218,
+            llSameGroup = 219,
+            llUnSit = 220,
+            llGroundSlope = 221,
+            llGroundNormal = 222,
+            llGroundContour = 223,
+            llGetAttached = 224,
+            llGetFreeMemory = 225,
+            llGetRegionName = 226,
+            llGetRegionTimeDilation = 227,
+            llGetRegionFPS = 228,
+            llParticleSystem = 229,
+            llGroundRepel = 230,
+            llGiveInventoryList = 231,
+            llSetVehicleType = 232,
+            llSetVehicleFloatParam = 233,
+            llSetVehicleVectorParam = 234,
+            llSetVehicleRotationParam = 235,
+            llSetVehicleFlags = 236,
+            llRemoveVehicleFlags = 237,
+            llSitTarget = 238,
+            llAvatarOnSitTarget = 239,
+            llAddToLandPassList = 240,
+            llSetTouchText = 241,
+            llSetSitText = 242,
+            llSetCameraEyeOffset = 243,
+            llSetCameraAtOffset = 244,
+            llDumpList2String = 245,
+            llScriptDanger = 246,
+            llDialog = 247,
+            llVolumeDetect = 248,
+            llResetOtherScript = 249,
+            llGetScriptState = 250,
+            llRemoteLoadScript = 251,
+            llSetRemoteScriptAccessPin = 252,
+            llRemoteLoadScriptPin = 253,
+            llOpenRemoteDataChannel = 254,
+            llSendRemoteData = 255,
+            llRemoteDataReply = 256,
+            llCloseRemoteDataChannel = 257,
+            llMD5String = 258,
+            llSetPrimitiveParams = 259,
+            llStringToBase64 = 260,
+            llBase64ToString = 261,
+            llXorBase64Strings = 262,
+            llRemoteDataSetRegion = 263,
+            llLog10 = 264,
+            llLog = 265,
+            llGetAnimationList = 266,
+            llSetParcelMusicURL = 267,
+            llGetRootPosition = 268,
+            llGetRootRotation = 269,
+            llGetObjectDesc = 270,
+            llSetObjectDesc = 271,
+            llGetCreator = 272,
+            llGetTimestamp = 273,
+            llSetLinkAlpha = 274,
+            llGetNumberOfPrims = 275,
+            llGetNumberOfNotecardLines = 276,
+            llGetBoundingBox = 277,
+            llGetGeometricCenter = 278,
+            llGetPrimitiveParams = 279,
+            llIntegerToBase64 = 280,
+            llBase64ToInteger = 281,
+            llGetGMTclock = 282,
+            llGetSimulatorHostname = 283,
+            llSetLocalRot = 284,
+            llParseStringKeepNulls = 285,
+            llRezAtRoot = 286,
+            llGetObjectPermMask = 287,
+            llSetObjectPermMask = 288,
+            llGetInventoryPermMask = 289,
+            llSetInventoryPermMask = 290,
+            llGetInventoryCreator = 291,
+            llOwnerSay = 292,
+            llRequestSimulatorData = 293,
+            llForceMouselook = 294,
+            llGetObjectMass = 295,
+            llListReplaceList = 296,
+            llLoadURL = 297,
+            llParcelMediaCommandList = 298,
+            llParcelMediaQuery = 299,
+            llModPow = 300,
+            llGetInventoryType = 301,
+            llSetPayPrice = 302,
+            llGetCameraPos = 303,
+            llGetCameraRot = 304,
+            llSetPrimURL = 305,
+            llRefreshPrimURL = 306,
+            llEscapeURL = 307,
+            llUnescapeURL = 308,
+            llMapDestination = 309,
+            llAddToLandBanList = 310,
+            llRemoveFromLandPassList = 311,
+            llRemoveFromLandBanList = 312,
+            llSetCameraParams = 313,
+            llClearCameraParams = 314,
+            llListStatistics = 315,
+            llGetUnixTime = 316,
+            llGetParcelFlags = 317,
+            llGetRegionFlags = 318,
+            llXorBase64StringsCorrect = 319,
+            llHTTPRequest = 320,
+            llResetLandBanList = 321,
+            llResetLandPassList = 322,
+            llGetParcelPrimCount = 323,
+            llGetParcelPrimOwners = 324,
+            llGetObjectPrimCount = 325,
+            llGetParcelMaxPrims = 326,
+            llGetParcelDetails = 327
+        }
+
+    }
+}
diff --git a/OpenSim/Region/Environment/Scenes/scripting/Engines/LSLEngine/LSLHandler/LSO_Parser.cs b/OpenSim/Region/Environment/Scenes/scripting/Engines/LSLEngine/LSLHandler/LSO_Parser.cs
index 2da1189..ebe4465 100644
--- a/OpenSim/Region/Environment/Scenes/scripting/Engines/LSLEngine/LSLHandler/LSO_Parser.cs
+++ b/OpenSim/Region/Environment/Scenes/scripting/Engines/LSLEngine/LSLHandler/LSO_Parser.cs
@@ -1,608 +1,608 @@
-    using System;
-    using System.Collections.Generic;
-    using System.Text;
-    using System.IO;
-    using System.Reflection;
-    using System.Reflection.Emit;
-using OpenSim.Region.Scripting;
-
-    namespace OpenSim.ScriptEngines.LSL
-    {
-        class LSO_Parser
-        {
-            private bool Debug = true;
-            private FileStream fs;
-            private BinaryReader br;
-            private LSO_Struct.Header myHeader;
-
-            private TypeBuilder typeBuilder;
-            private ScriptInfo WorldAPI;
-
-            /// <summary>
-            /// Parse LSO file.
-            /// Reads LSO ByteCode into memory structures.
-            /// TODO: What else does it do?
-            /// </summary>
-            /// <param name="FileName">FileName of LSO ByteCode file</param>
-            public void ParseFile(string FileName, ScriptInfo _WorldAPI, ref TypeBuilder _typeBuilder)
-            {
-                typeBuilder = _typeBuilder;
-                WorldAPI = _WorldAPI;
-                // Open
-                SendToDebug("Opening filename: " + FileName);
-                fs = File.Open(FileName, FileMode.Open, FileAccess.Read, FileShare.Read);
-                br = new BinaryReader(fs, Encoding.BigEndianUnicode);
-                
-
-                // The LSO Format consist of 6 major blocks: header, statics, functions, states, heap, and stack. 
-
-
-                // HEADER BLOCK
-                SendToDebug("Reading HEADER BLOCK at: 0");
-                fs.Seek(0, SeekOrigin.Begin);
-                myHeader = new LSO_Struct.Header();
-                myHeader.TM = BitConverter.ToUInt32(br_read(4), 0); 
-                myHeader.IP = BitConverter.ToUInt32(br_read(4), 0);
-                myHeader.VN = BitConverter.ToUInt32(br_read(4), 0);
-                myHeader.BP = BitConverter.ToUInt32(br_read(4), 0);
-                myHeader.SP = BitConverter.ToUInt32(br_read(4), 0);
-                myHeader.HR = BitConverter.ToUInt32(br_read(4), 0);
-                myHeader.HP = BitConverter.ToUInt32(br_read(4), 0);
-                myHeader.CS = BitConverter.ToUInt32(br_read(4), 0);
-                myHeader.NS = BitConverter.ToUInt32(br_read(4), 0);
-                myHeader.CE = BitConverter.ToUInt32(br_read(4), 0);
-                myHeader.IE = BitConverter.ToUInt32(br_read(4), 0);
-                myHeader.ER = BitConverter.ToUInt32(br_read(4), 0);
-                myHeader.FR = BitConverter.ToUInt32(br_read(4), 0);
-                myHeader.SLR = BitConverter.ToUInt32(br_read(4), 0);
-                myHeader.GVR = BitConverter.ToUInt32(br_read(4), 0);
-                myHeader.GFR = BitConverter.ToUInt32(br_read(4), 0);
-                myHeader.PR = BitConverter.ToUInt32(br_read(4), 0);
-                myHeader.ESR = BitConverter.ToUInt32(br_read(4), 0);
-                myHeader.SR = BitConverter.ToUInt32(br_read(4), 0);
-                myHeader.NCE = BitConverter.ToUInt64(br_read(8), 0);
-                myHeader.NIE = BitConverter.ToUInt64(br_read(8), 0);
-                myHeader.NER = BitConverter.ToUInt64(br_read(8), 0);
-
-                // Print Header Block to debug
-                SendToDebug("TM - Top of memory (size): " + myHeader.TM);
-                SendToDebug("IP - Instruction Pointer (0=not running): " + myHeader.IP);
-                SendToDebug("VN - Version number: " + myHeader.VN);
-                SendToDebug("BP - Local Frame Pointer: " + myHeader.BP);
-                SendToDebug("SP - Stack Pointer: " + myHeader.SP);
-                SendToDebug("HR - Heap Register: " + myHeader.HR);
-                SendToDebug("HP - Heap Pointer: " + myHeader.HP);
-                SendToDebug("CS - Current State: " + myHeader.CS);
-                SendToDebug("NS - Next State: " + myHeader.NS);
-                SendToDebug("CE - Current Events: " + myHeader.CE);
-                SendToDebug("IE - In Event: " + myHeader.IE);
-                SendToDebug("ER - Event Register: " + myHeader.ER);
-                SendToDebug("FR - Fault Register: " + myHeader.FR);
-                SendToDebug("SLR - Sleep Register: " + myHeader.SLR);
-                SendToDebug("GVR - Global Variable Register: " + myHeader.GVR);
-                SendToDebug("GFR - Global Function Register: " + myHeader.GFR);
-                SendToDebug("PR - Parameter Register: " + myHeader.PR);
-                SendToDebug("ESR - Energy Supply Register: " + myHeader.ESR);
-                SendToDebug("SR - State Register: " + myHeader.SR);
-                SendToDebug("NCE - 64-bit Current Events: " + myHeader.NCE);
-                SendToDebug("NIE - 64-bit In Events: " + myHeader.NIE);
-                SendToDebug("NER - 64-bit Event Register: " + myHeader.NER);
-                SendToDebug("Read position when exiting HEADER BLOCK: " + fs.Position);
-
-                // STATIC BLOCK
-                SendToDebug("Reading STATIC BLOCK at: " + myHeader.GVR);
-                fs.Seek(myHeader.GVR, SeekOrigin.Begin);
-                int StaticBlockCount = 0;
-                // Read function blocks until we hit GFR
-                while (fs.Position < myHeader.GFR)
-                {
-                    StaticBlockCount++;
-                    SendToDebug("Reading Static Block " + StaticBlockCount + " at: " + fs.Position);
-                    //fs.Seek(myHeader.GVR, SeekOrigin.Begin);
-                    LSO_Struct.StaticBlock myStaticBlock = new LSO_Struct.StaticBlock();
-                    myStaticBlock.Static_Chunk_Header_Size = BitConverter.ToUInt32(br_read(4), 0);
-                    myStaticBlock.ObjectType = br_read(1)[0];
-                    SendToDebug("Static Block ObjectType: " + ((LSO_Enums.Variable_Type_Codes)myStaticBlock.ObjectType).ToString());
-                    myStaticBlock.Unknown = br_read(1)[0];
-                    // Size of datatype varies
-                    if (myStaticBlock.ObjectType != 0)
-                        myStaticBlock.BlockVariable = br_read(getObjectSize(myStaticBlock.ObjectType));
-                }
-                SendToDebug("Number of Static Blocks read: " + StaticBlockCount);
-
-
-                // FUNCTION BLOCK
-                // Always right after STATIC BLOCK
-                LSO_Struct.FunctionBlock myFunctionBlock = new LSO_Struct.FunctionBlock();
-                if (myHeader.GFR == myHeader.SR)
-                {
-                    // If GFR and SR are at same position then there is no fuction block
-                    SendToDebug("No FUNCTION BLOCK found");
-                } else {
-                    SendToDebug("Reading FUNCTION BLOCK at: " + myHeader.GFR);
-                    fs.Seek(myHeader.GFR, SeekOrigin.Begin);
-                    myFunctionBlock.FunctionCount = BitConverter.ToUInt32(br_read(4), 0);
-                    SendToDebug("Number of functions in Fuction Block: " + myFunctionBlock.FunctionCount);
-                    if (myFunctionBlock.FunctionCount > 0)
-                    {
-                        myFunctionBlock.CodeChunkPointer = new UInt32[myFunctionBlock.FunctionCount];
-                        for (int i = 0; i < myFunctionBlock.FunctionCount; i++)
-                        {
-                            SendToDebug("Reading function " + i + " at: " + fs.Position);
-                            // TODO: ADD TO FUNCTION LIST (How do we identify it later?)
-                            // Note! Absolute position
-                            myFunctionBlock.CodeChunkPointer[i] = BitConverter.ToUInt32(br_read(4), 0) + myHeader.GFR;
-                            SendToDebug("Fuction " + i + " code chunk position: " + myFunctionBlock.CodeChunkPointer[i]);
-                        }
-                    }
-                }
-
-
-                // STATE FRAME BLOCK
-                // Always right after FUNCTION BLOCK
-                SendToDebug("Reading STATE BLOCK at: " + myHeader.SR);
-                fs.Seek(myHeader.SR, SeekOrigin.Begin);
-                LSO_Struct.StateFrameBlock myStateFrameBlock = new LSO_Struct.StateFrameBlock();
-                myStateFrameBlock.StateCount = BitConverter.ToUInt32(br_read(4), 0);
-                if (myStateFrameBlock.StateCount > 0)
-                {
-                    // Initialize array
-                    myStateFrameBlock.StatePointer = new LSO_Struct.StatePointerBlock[myStateFrameBlock.StateCount];
-                    for (int i = 0; i < myStateFrameBlock.StateCount; i++)
-                    {
-                        SendToDebug("Reading STATE POINTER BLOCK " + (i+1) + " at: " + fs.Position);
-                        // Position is relative to state frame
-                        myStateFrameBlock.StatePointer[i].Location = myHeader.SR + BitConverter.ToUInt32(br_read(4), 0);
-                        myStateFrameBlock.StatePointer[i].EventMask = new System.Collections.BitArray(br_read(8));
-                        SendToDebug("Pointer: " + myStateFrameBlock.StatePointer[i].Location);
-                        SendToDebug("Total potential EventMask bits: " + myStateFrameBlock.StatePointer[i].EventMask.Count);
-
-                        //// Read STATE BLOCK
-                        //long CurPos = fs.Position;
-                        //fs.Seek(CurPos, SeekOrigin.Begin);
-
-                    }
-                }
-
-
-                // STATE BLOCK
-                // For each StateFrameBlock there is one StateBlock with multiple event handlers
-
-                if (myStateFrameBlock.StateCount > 0)
-                {
-                    // Go through all State Frame Pointers found
-                    for (int i = 0; i < myStateFrameBlock.StateCount; i++)
-                    {
-                        
-                        fs.Seek(myStateFrameBlock.StatePointer[i].Location, SeekOrigin.Begin);
-                        SendToDebug("Reading STATE BLOCK " + (i + 1) + " at: " + fs.Position);
-
-                        // READ: STATE BLOCK HEADER
-                        myStateFrameBlock.StatePointer[i].StateBlock = new LSO_Struct.StateBlock();
-                        myStateFrameBlock.StatePointer[i].StateBlock.StartPos = (UInt32)fs.Position; // Note
-                        myStateFrameBlock.StatePointer[i].StateBlock.HeaderSize = BitConverter.ToUInt32(br_read(4), 0);
-                        myStateFrameBlock.StatePointer[i].StateBlock.Unknown = br_read(1)[0];
-                        myStateFrameBlock.StatePointer[i].StateBlock.EndPos = (UInt32)fs.Position; // Note
-                        SendToDebug("State block Start Pos: " + myStateFrameBlock.StatePointer[i].StateBlock.StartPos);
-                        SendToDebug("State block Header Size: " + myStateFrameBlock.StatePointer[i].StateBlock.HeaderSize);
-                        SendToDebug("State block Header End Pos: " + myStateFrameBlock.StatePointer[i].StateBlock.EndPos);
-
-                        // We need to count number of bits flagged in EventMask?
-
-
-                        // for each bit in myStateFrameBlock.StatePointer[i].EventMask
-
-                        // ADDING TO ALL RIGHT NOW, SHOULD LIMIT TO ONLY THE ONES IN USE
-                        //TODO: Create event hooks
-                        myStateFrameBlock.StatePointer[i].StateBlock.StateBlockHandlers = new LSO_Struct.StateBlockHandler[myStateFrameBlock.StatePointer[i].EventMask.Count - 1];
-                        for (int ii = 0; ii < myStateFrameBlock.StatePointer[i].EventMask.Count - 1; ii++)
-                        {
-                            
-                            if (myStateFrameBlock.StatePointer[i].EventMask.Get(ii) == true)
-                            {
-                                // We got an event
-                                //  READ: STATE BLOCK HANDLER
-                                SendToDebug("Reading STATE BLOCK " + (i + 1) + " HANDLER matching EVENT MASK " + ii  + " (" + ((LSO_Enums.Event_Mask_Values)ii).ToString() + ") at: " + fs.Position);
-                                myStateFrameBlock.StatePointer[i].StateBlock.StateBlockHandlers[ii].CodeChunkPointer = myStateFrameBlock.StatePointer[i].StateBlock.EndPos + BitConverter.ToUInt32(br_read(4), 0);
-                                myStateFrameBlock.StatePointer[i].StateBlock.StateBlockHandlers[ii].CallFrameSize = BitConverter.ToUInt32(br_read(4), 0);
-                                SendToDebug("Reading STATE BLOCK " + (i + 1) + " HANDLER EVENT MASK " + ii + " (" + ((LSO_Enums.Event_Mask_Values)ii).ToString() + ") Code Chunk Pointer: " + myStateFrameBlock.StatePointer[i].StateBlock.StateBlockHandlers[ii].CodeChunkPointer);
-                                SendToDebug("Reading STATE BLOCK " + (i + 1) + " HANDLER EVENT MASK " + ii + " (" + ((LSO_Enums.Event_Mask_Values)ii).ToString() + ") Call Frame Size: " + myStateFrameBlock.StatePointer[i].StateBlock.StateBlockHandlers[ii].CallFrameSize );
-                            }
-                        }
-                    }
-                }
-
-
-
-
-                //// READ FUNCTION CODE CHUNKS
-                //// Functions + Function start pos (GFR)
-                //// TODO: Somehow be able to identify and reference this
-                //LSO_Struct.CodeChunk[] myFunctionCodeChunk;
-                //if (myFunctionBlock.FunctionCount > 0)
-                //{
-                //    myFunctionCodeChunk = new LSO_Struct.CodeChunk[myFunctionBlock.FunctionCount];
-                //    for (int i = 0; i < myFunctionBlock.FunctionCount; i++)
-                //    {
-                //        SendToDebug("Reading Function Code Chunk " + i);
-                //        myFunctionCodeChunk[i] = GetCodeChunk((UInt32)myFunctionBlock.CodeChunkPointer[i]);
-                //    }
-
-                //}
-                // READ EVENT CODE CHUNKS
-                LSO_Struct.CodeChunk[] myEventCodeChunk;
-                if (myStateFrameBlock.StateCount > 0)
-                {
-                    myEventCodeChunk = new LSO_Struct.CodeChunk[myStateFrameBlock.StateCount];
-                    for (int i = 0; i < myStateFrameBlock.StateCount; i++)
-                    {
-                        // TODO: Somehow organize events and functions so they can be found again, 
-                        // two level search ain't no good
-                        for (int ii = 0; ii < myStateFrameBlock.StatePointer[i].EventMask.Count - 1; ii++)
-                        {
-
-
-                            if (myStateFrameBlock.StatePointer[i].StateBlock.StateBlockHandlers[ii].CodeChunkPointer > 0)
-                            {
-                                    SendToDebug("Reading Event Code Chunk state " + i + ", event " + (LSO_Enums.Event_Mask_Values)ii);
-
-
-                                    // Override a Method / Function
-                                    string eventname = "event_" + (LSO_Enums.Event_Mask_Values)ii;
-                                    SendToDebug("CLR:" + eventname + ":MethodBuilder methodBuilder = typeBuilder.DefineMethod...");
-                                    MethodBuilder methodBuilder = typeBuilder.DefineMethod(eventname,
-                                                 MethodAttributes.Private | MethodAttributes.Virtual,
-                                                 typeof(void),
-                                                 new Type[] { typeof(object) });
-
-                                    SendToDebug("CLR:" + eventname + ":typeBuilder.DefineMethodOverride(methodBuilder...");
-                                    typeBuilder.DefineMethodOverride(methodBuilder,
-                                            typeof(LSL_CLRInterface.LSLScript).GetMethod(eventname));
-
-                                    // Create the IL generator
-
-                                    SendToDebug("CLR:" + eventname + ":ILGenerator il = methodBuilder.GetILGenerator();");
-                                    ILGenerator il = methodBuilder.GetILGenerator();
-
-
-                                    LSO_Struct.CodeChunk myECC =
-                                        GetCodeChunk(myStateFrameBlock.StatePointer[i].StateBlock.StateBlockHandlers[ii].CodeChunkPointer, il, eventname);
-                            }
-                            
-                        }
-                    }
-
-                }
-
-
-                // Close
-                br.Close();
-                fs.Close();
-
-            }
-
-            private LSO_Struct.HeapBlock GetHeap(UInt32 pos)
-            {
-                // HEAP BLOCK
-                // TODO:? Special read for strings/keys (null terminated) and lists (pointers to other HEAP entries)
-                SendToDebug("Reading HEAP BLOCK at: " + pos);
-                fs.Seek(pos, SeekOrigin.Begin);
-                
-                LSO_Struct.HeapBlock myHeapBlock = new LSO_Struct.HeapBlock();
-                myHeapBlock.DataBlockSize = BitConverter.ToUInt32(br_read(4), 0);
-                myHeapBlock.ObjectType = br_read(1)[0];
-                myHeapBlock.ReferenceCount = BitConverter.ToUInt16(br_read(2), 0);
-                myHeapBlock.Data = br_read(getObjectSize(myHeapBlock.ObjectType));
-
-                SendToDebug("Heap Block Data Block Size: " + myHeapBlock.DataBlockSize);
-                SendToDebug("Heap Block ObjectType: " + ((LSO_Enums.Variable_Type_Codes)myHeapBlock.ObjectType).ToString());
-                SendToDebug("Heap Block Reference Count: " + myHeapBlock.ReferenceCount);
-
-                return myHeapBlock;
-            }
-
-     
-
-            private byte[] br_read(int len)
-            {
-                if (len <= 0)
-                    return null;
-
-                try
-                {
-                    byte[] bytes = new byte[len];
-                    for (int i = len - 1; i > -1; i--)
-                        bytes[i] = br.ReadByte();
-                    return bytes;
-                }
-                catch (Exception e)
-                {
-                    SendToDebug("Exception: " + e.ToString());
-                    throw (e);
-                }
-            }
-            //private byte[] br_read_smallendian(int len)
-            //{
-            //    byte[] bytes = new byte[len];    
-            //    br.Read(bytes,0, len);
-            //    return bytes;
-            //}
-
-            private int getObjectSize(byte ObjectType)
-            {
-                switch (ObjectType)
-                {
-                    case 1:
-                    case 2:
-                    case 3:
-                    case 4:
-                    case 7:
-                        return 4;
-                    case 5:
-                        return 12;
-                    case 6:
-                        return 16;
-                    default:
-                        return 0;
-                }
-            }
-            private void SendToDebug(string Message)
-            {
-                if (Debug == true)
-                    Console.WriteLine("Debug: " + Message);
-            }
-
-
-            private string Read_String()
-            {
-                string ret = "";
-                byte reader = br_read(1)[0];
-                while (reader != 0x000)
-                {
-                    ret += (char)reader;
-                    reader = br_read(1)[0];
-                }
-                return ret;
-            }
-
-             /// <summary>
-            /// Reads a code chunk into structure and returns it.
-            /// </summary>
-            /// <param name="pos">Absolute position in file. REMEMBER TO ADD myHeader.GFR!</param>
-            /// <returns></returns>
-            private LSO_Struct.CodeChunk GetCodeChunk(UInt32 pos, ILGenerator il, string eventname)
-            {
-
-                /*
-                 * CLR TRY
-                 */
-                //SendToDebug("CLR:" + eventname + ":il.BeginExceptionBlock()");
-                il.BeginExceptionBlock();
-
-                // Push "Hello World!" string to stack
-                //SendToDebug("CLR:" + eventname + ":il.Emit(OpCodes.Ldstr...");
-                il.Emit(OpCodes.Ldstr, "Starting CLR dynamic execution of: " + eventname);
-
-                // Push Console.WriteLine command to stack ... Console.WriteLine("Hello World!");
-                //SendToDebug("CLR:" + eventname + ":il.Emit(OpCodes.Call...");
-                il.Emit(OpCodes.Call, typeof(Console).GetMethod
-                    ("WriteLine", new Type[] { typeof(string) }));
-
-
-                LSO_Struct.CodeChunk myCodeChunk = new LSO_Struct.CodeChunk();
-
-                SendToDebug("Reading Function Code Chunk at: " + pos);
-                fs.Seek(pos, SeekOrigin.Begin);
-                myCodeChunk.CodeChunkHeaderSize = BitConverter.ToUInt32(br_read(4), 0);
-                SendToDebug("CodeChunk Header Size: " + myCodeChunk.CodeChunkHeaderSize );
-                // Read until null
-                myCodeChunk.Comment = Read_String();
-                SendToDebug("Function comment: " + myCodeChunk.Comment);
-                myCodeChunk.ReturnType = br_read(1)[0];
-                SendToDebug("Return type: " + (LSO_Enums.Variable_Type_Codes)myCodeChunk.ReturnType);
-                // TODO: How to determine number of codechunks -- does this method work?
-                myCodeChunk.CodeChunkArguments = new System.Collections.Generic.List<LSO_Struct.CodeChunkArgument>();
-                byte reader = br_read(1)[0];
-                reader = br_read(1)[0];
-                int ccount = 0;
-                while (reader != 0x000)
-                {
-                    ccount++;
-                    SendToDebug("Reading Code Chunk Argument " + ccount);
-                    LSO_Struct.CodeChunkArgument CCA = new LSO_Struct.CodeChunkArgument();
-                    CCA.FunctionReturnType = reader;
-                    reader = br_read(1)[0];
-                    CCA.NullString = reader;
-                    myCodeChunk.CodeChunkArguments.Add(CCA);
-                    SendToDebug("Code Chunk Argument " + ccount + " return type: " + (LSO_Enums.Variable_Type_Codes)CCA.FunctionReturnType);
-                }
-                // End marker is 0x000
-                myCodeChunk.EndMarker = reader;
-                // TODO: How to read and identify following code
-                // TODO: Code is read until a return of some sort is found
-                bool FoundRet = false;
-                while (FoundRet == false)
-                {
-                        //reader = br_read(1)[0];
-                    //UInt16  opcode = BitConverter.ToUInt16(br_read(1),0);
-                    UInt16 opcode = br_read(1)[0];
-                    //long rPos = fs.Position;
-                    SendToDebug("OPCODE: " + ((LSO_Enums.Operation_Table)opcode).ToString());
-                    switch (opcode)
-                    {
-                            // LONG
-                        case (UInt16)LSO_Enums.Operation_Table.POPARG:
-                        case (UInt16)LSO_Enums.Operation_Table.STORE:
-                        case (UInt16)LSO_Enums.Operation_Table.STORES:
-                        case (UInt16)LSO_Enums.Operation_Table.STOREL:
-                        case (UInt16)LSO_Enums.Operation_Table.STOREV:
-                        case (UInt16)LSO_Enums.Operation_Table.STOREQ:
-                        case (UInt16)LSO_Enums.Operation_Table.STOREG:
-                        case (UInt16)LSO_Enums.Operation_Table.STOREGS:
-                        case (UInt16)LSO_Enums.Operation_Table.STOREGL:
-                        case (UInt16)LSO_Enums.Operation_Table.STOREGV:
-                        case (UInt16)LSO_Enums.Operation_Table.STOREGQ:
-                        case (UInt16)LSO_Enums.Operation_Table.LOADP:
-                        case (UInt16)LSO_Enums.Operation_Table.LOADSP:
-                        case (UInt16)LSO_Enums.Operation_Table.LOADLP:
-                        case (UInt16)LSO_Enums.Operation_Table.LOADVP:
-                        case (UInt16)LSO_Enums.Operation_Table.LOADQP:
-                        case (UInt16)LSO_Enums.Operation_Table.PUSH:
-                        case (UInt16)LSO_Enums.Operation_Table.PUSHS:
-                        case (UInt16)LSO_Enums.Operation_Table.PUSHL:
-                        case (UInt16)LSO_Enums.Operation_Table.PUSHV:
-                        case (UInt16)LSO_Enums.Operation_Table.PUSHQ:
-                        case (UInt16)LSO_Enums.Operation_Table.PUSHG:
-                        case (UInt16)LSO_Enums.Operation_Table.PUSHGS:
-                        case (UInt16)LSO_Enums.Operation_Table.PUSHGL:
-                        case (UInt16)LSO_Enums.Operation_Table.PUSHGV:
-                        case (UInt16)LSO_Enums.Operation_Table.PUSHGQ:
-                            SendToDebug("Param1: " + BitConverter.ToUInt32(br_read(4),0));
-                            break;
-                            // BYTE
-                        case (UInt16)LSO_Enums.Operation_Table.PUSHARGB:
-                            SendToDebug("Param1: " + br_read(1)[0]);
-                            break;
-                            // INTEGER
-                        case (UInt16)LSO_Enums.Operation_Table.PUSHARGI:
-                            // TODO: What is size of integer?
-                            SendToDebug("Param1: " + BitConverter.ToUInt32(br_read(4),0));
-                            break;
-                            // FLOAT
-                        case (UInt16)LSO_Enums.Operation_Table.PUSHARGF:
-                            // TODO: What is size of float?
-                            SendToDebug("Param1: " + BitConverter.ToUInt32(br_read(4),0));
-                            break;
-                            // STRING
-                        case (UInt16)LSO_Enums.Operation_Table.PUSHARGS:
-                            string s = Read_String();
-                            SendToDebug("Param1: " + s);
-                            il.Emit(OpCodes.Ldstr, s);
-                            break;
-                            // VECTOR z,y,x
-                        case (UInt16)LSO_Enums.Operation_Table.PUSHARGV:
-                            SendToDebug("Param1 Z: " + BitConverter.ToUInt32(br_read(4),0));
-                            SendToDebug("Param1 Y: " + BitConverter.ToUInt32(br_read(4),0));
-                            SendToDebug("Param1 X: " + BitConverter.ToUInt32(br_read(4),0));
-                            break;
-                            // ROTATION s,z,y,x
-                        case (UInt16)LSO_Enums.Operation_Table.PUSHARGQ:
-                            SendToDebug("Param1 S: " + BitConverter.ToUInt32(br_read(4),0));
-                            SendToDebug("Param1 Z: " + BitConverter.ToUInt32(br_read(4),0));
-                            SendToDebug("Param1 Y: " + BitConverter.ToUInt32(br_read(4),0));
-                            SendToDebug("Param1 X: " + BitConverter.ToUInt32(br_read(4),0));
-                            break;
-                            // LONG
-                        case (UInt16)LSO_Enums.Operation_Table.PUSHARGE:
-                            SendToDebug("Param1: " + BitConverter.ToUInt32(br_read(4),0));
-                            break;
-                            // BYTE
-                        case (UInt16)LSO_Enums.Operation_Table.ADD:
-                        case (UInt16)LSO_Enums.Operation_Table.SUB:
-                        case (UInt16)LSO_Enums.Operation_Table.MUL:
-                        case (UInt16)LSO_Enums.Operation_Table.DIV:
-                        case (UInt16)LSO_Enums.Operation_Table.MOD:
-                        case (UInt16)LSO_Enums.Operation_Table.EQ:
-                        case (UInt16)LSO_Enums.Operation_Table.NEQ:
-                        case (UInt16)LSO_Enums.Operation_Table.LEQ:
-                        case (UInt16)LSO_Enums.Operation_Table.GEQ:
-                        case (UInt16)LSO_Enums.Operation_Table.LESS:
-                        case (UInt16)LSO_Enums.Operation_Table.GREATER:
-                        case (UInt16)LSO_Enums.Operation_Table.BOOLOR:
-                            SendToDebug("Param1: " + br_read(1)[0]);
-                            break;
-                            // LONG
-                        case (UInt16)LSO_Enums.Operation_Table.JUMP:
-                            SendToDebug("Param1: " + BitConverter.ToUInt32(br_read(4),0));
-                            break;
-                            // BYTE, LONG
-                        case (UInt16)LSO_Enums.Operation_Table.JUMPIF:
-                        case (UInt16)LSO_Enums.Operation_Table.JUMPNIF:
-                            SendToDebug("Param1: " + br_read(1)[0]);
-                            SendToDebug("Param2: " + BitConverter.ToUInt32(br_read(4),0));
-                            break;
-                            // LONG
-                        case (UInt16)LSO_Enums.Operation_Table.STATE:
-                        case (UInt16)LSO_Enums.Operation_Table.CALL:
-                            SendToDebug("Param1: " + BitConverter.ToUInt32(br_read(4),0));
-                            break;
-                            // BYTE
-                        case (UInt16)LSO_Enums.Operation_Table.CAST:
-                            SendToDebug("Param1: " + br_read(1)[0]);
-                            break;
-                            // LONG
-                        case (UInt16)LSO_Enums.Operation_Table.STACKTOS:
-                        case (UInt16)LSO_Enums.Operation_Table.STACKTOL:
-                            SendToDebug("Param1: " + BitConverter.ToUInt32(br_read(4),0));
-                            break;
-                            // BYTE
-                        case (UInt16)LSO_Enums.Operation_Table.PRINT:
-                        case (UInt16)LSO_Enums.Operation_Table.CALLLIB:
-                            SendToDebug("Param1: " + br_read(1)[0]);
-                            break;
-                            // SHORT
-                        case (UInt16)LSO_Enums.Operation_Table.CALLLIB_TWO_BYTE:
-                            // TODO: What is size of short?
-                            UInt16 _i = BitConverter.ToUInt16(br_read(2), 0);
-                            SendToDebug("Param1: " + _i);
-                            switch (_i)
-                            {
-                                case (UInt16)LSO_Enums.BuiltIn_Functions.llSay:
-                                    il.Emit(OpCodes.Call, typeof(Console).GetMethod
-                                        ("WriteLine", new Type[] { typeof(string) }));
-                                    break;
-                            }
-                            break;
-
-
-                        // RETURN
-                        case (UInt16)LSO_Enums.Operation_Table.RETURN:
-                            SendToDebug("Last OPCODE was return command. Code chunk execution complete.");
-                            FoundRet = true;
-                            break;
-                    }
-                    //fs.Seek(rPos, SeekOrigin.Begin);
-
-                }
-
-
-                /*
-                 * CATCH
-                 */
-                SendToDebug("CLR:" + eventname + ":il.BeginCatchBlock(typeof(Exception));");
-                il.BeginCatchBlock(typeof(Exception));
-
-                // Push "Hello World!" string to stack
-                SendToDebug("CLR:" + eventname + ":il.Emit(OpCodes.Ldstr...");
-                il.Emit(OpCodes.Ldstr, "Execption executing dynamic CLR function " + eventname + ": ");
-
-                //call void [mscorlib]System.Console::WriteLine(string)
-                SendToDebug("CLR:" + eventname + ":il.Emit(OpCodes.Call...");
-                il.Emit(OpCodes.Call, typeof(Console).GetMethod
-                    ("Write", new Type[] { typeof(string) }));
-
-                //callvirt instance string [mscorlib]System.Exception::get_Message()
-                SendToDebug("CLR:" + eventname + ":il.Emit(OpCodes.Callvirt...");
-                il.Emit(OpCodes.Callvirt, typeof(Exception).GetMethod
-                    ("get_Message"));
-
-                //call void [mscorlib]System.Console::WriteLine(string)
-                SendToDebug("CLR:" + eventname + ":il.Emit(OpCodes.Call...");
-                il.Emit(OpCodes.Call, typeof(Console).GetMethod
-                    ("WriteLine", new Type[] { typeof(string) }));
-
-                /*
-                 * CLR END TRY
-                 */
-                //SendToDebug("CLR:" + eventname + ":il.EndExceptionBlock();");
-                il.EndExceptionBlock();
-                // Push "Return from current method, with return value if present" to stack
-                il.Emit(OpCodes.Ret);
-
-
-
-                return myCodeChunk;
-
-            }
-    }
-}
+    using System;
+    using System.Collections.Generic;
+    using System.Text;
+    using System.IO;
+    using System.Reflection;
+    using System.Reflection.Emit;
+using OpenSim.Region.Scripting;
+
+    namespace OpenSim.ScriptEngines.LSL
+    {
+        class LSO_Parser
+        {
+            private bool Debug = true;
+            private FileStream fs;
+            private BinaryReader br;
+            private LSO_Struct.Header myHeader;
+
+            private TypeBuilder typeBuilder;
+            private ScriptInfo WorldAPI;
+
+            /// <summary>
+            /// Parse LSO file.
+            /// Reads LSO ByteCode into memory structures.
+            /// TODO: What else does it do?
+            /// </summary>
+            /// <param name="FileName">FileName of LSO ByteCode file</param>
+            public void ParseFile(string FileName, ScriptInfo _WorldAPI, ref TypeBuilder _typeBuilder)
+            {
+                typeBuilder = _typeBuilder;
+                WorldAPI = _WorldAPI;
+                // Open
+                SendToDebug("Opening filename: " + FileName);
+                fs = File.Open(FileName, FileMode.Open, FileAccess.Read, FileShare.Read);
+                br = new BinaryReader(fs, Encoding.BigEndianUnicode);
+                
+
+                // The LSO Format consist of 6 major blocks: header, statics, functions, states, heap, and stack. 
+
+
+                // HEADER BLOCK
+                SendToDebug("Reading HEADER BLOCK at: 0");
+                fs.Seek(0, SeekOrigin.Begin);
+                myHeader = new LSO_Struct.Header();
+                myHeader.TM = BitConverter.ToUInt32(br_read(4), 0); 
+                myHeader.IP = BitConverter.ToUInt32(br_read(4), 0);
+                myHeader.VN = BitConverter.ToUInt32(br_read(4), 0);
+                myHeader.BP = BitConverter.ToUInt32(br_read(4), 0);
+                myHeader.SP = BitConverter.ToUInt32(br_read(4), 0);
+                myHeader.HR = BitConverter.ToUInt32(br_read(4), 0);
+                myHeader.HP = BitConverter.ToUInt32(br_read(4), 0);
+                myHeader.CS = BitConverter.ToUInt32(br_read(4), 0);
+                myHeader.NS = BitConverter.ToUInt32(br_read(4), 0);
+                myHeader.CE = BitConverter.ToUInt32(br_read(4), 0);
+                myHeader.IE = BitConverter.ToUInt32(br_read(4), 0);
+                myHeader.ER = BitConverter.ToUInt32(br_read(4), 0);
+                myHeader.FR = BitConverter.ToUInt32(br_read(4), 0);
+                myHeader.SLR = BitConverter.ToUInt32(br_read(4), 0);
+                myHeader.GVR = BitConverter.ToUInt32(br_read(4), 0);
+                myHeader.GFR = BitConverter.ToUInt32(br_read(4), 0);
+                myHeader.PR = BitConverter.ToUInt32(br_read(4), 0);
+                myHeader.ESR = BitConverter.ToUInt32(br_read(4), 0);
+                myHeader.SR = BitConverter.ToUInt32(br_read(4), 0);
+                myHeader.NCE = BitConverter.ToUInt64(br_read(8), 0);
+                myHeader.NIE = BitConverter.ToUInt64(br_read(8), 0);
+                myHeader.NER = BitConverter.ToUInt64(br_read(8), 0);
+
+                // Print Header Block to debug
+                SendToDebug("TM - Top of memory (size): " + myHeader.TM);
+                SendToDebug("IP - Instruction Pointer (0=not running): " + myHeader.IP);
+                SendToDebug("VN - Version number: " + myHeader.VN);
+                SendToDebug("BP - Local Frame Pointer: " + myHeader.BP);
+                SendToDebug("SP - Stack Pointer: " + myHeader.SP);
+                SendToDebug("HR - Heap Register: " + myHeader.HR);
+                SendToDebug("HP - Heap Pointer: " + myHeader.HP);
+                SendToDebug("CS - Current State: " + myHeader.CS);
+                SendToDebug("NS - Next State: " + myHeader.NS);
+                SendToDebug("CE - Current Events: " + myHeader.CE);
+                SendToDebug("IE - In Event: " + myHeader.IE);
+                SendToDebug("ER - Event Register: " + myHeader.ER);
+                SendToDebug("FR - Fault Register: " + myHeader.FR);
+                SendToDebug("SLR - Sleep Register: " + myHeader.SLR);
+                SendToDebug("GVR - Global Variable Register: " + myHeader.GVR);
+                SendToDebug("GFR - Global Function Register: " + myHeader.GFR);
+                SendToDebug("PR - Parameter Register: " + myHeader.PR);
+                SendToDebug("ESR - Energy Supply Register: " + myHeader.ESR);
+                SendToDebug("SR - State Register: " + myHeader.SR);
+                SendToDebug("NCE - 64-bit Current Events: " + myHeader.NCE);
+                SendToDebug("NIE - 64-bit In Events: " + myHeader.NIE);
+                SendToDebug("NER - 64-bit Event Register: " + myHeader.NER);
+                SendToDebug("Read position when exiting HEADER BLOCK: " + fs.Position);
+
+                // STATIC BLOCK
+                SendToDebug("Reading STATIC BLOCK at: " + myHeader.GVR);
+                fs.Seek(myHeader.GVR, SeekOrigin.Begin);
+                int StaticBlockCount = 0;
+                // Read function blocks until we hit GFR
+                while (fs.Position < myHeader.GFR)
+                {
+                    StaticBlockCount++;
+                    SendToDebug("Reading Static Block " + StaticBlockCount + " at: " + fs.Position);
+                    //fs.Seek(myHeader.GVR, SeekOrigin.Begin);
+                    LSO_Struct.StaticBlock myStaticBlock = new LSO_Struct.StaticBlock();
+                    myStaticBlock.Static_Chunk_Header_Size = BitConverter.ToUInt32(br_read(4), 0);
+                    myStaticBlock.ObjectType = br_read(1)[0];
+                    SendToDebug("Static Block ObjectType: " + ((LSO_Enums.Variable_Type_Codes)myStaticBlock.ObjectType).ToString());
+                    myStaticBlock.Unknown = br_read(1)[0];
+                    // Size of datatype varies
+                    if (myStaticBlock.ObjectType != 0)
+                        myStaticBlock.BlockVariable = br_read(getObjectSize(myStaticBlock.ObjectType));
+                }
+                SendToDebug("Number of Static Blocks read: " + StaticBlockCount);
+
+
+                // FUNCTION BLOCK
+                // Always right after STATIC BLOCK
+                LSO_Struct.FunctionBlock myFunctionBlock = new LSO_Struct.FunctionBlock();
+                if (myHeader.GFR == myHeader.SR)
+                {
+                    // If GFR and SR are at same position then there is no fuction block
+                    SendToDebug("No FUNCTION BLOCK found");
+                } else {
+                    SendToDebug("Reading FUNCTION BLOCK at: " + myHeader.GFR);
+                    fs.Seek(myHeader.GFR, SeekOrigin.Begin);
+                    myFunctionBlock.FunctionCount = BitConverter.ToUInt32(br_read(4), 0);
+                    SendToDebug("Number of functions in Fuction Block: " + myFunctionBlock.FunctionCount);
+                    if (myFunctionBlock.FunctionCount > 0)
+                    {
+                        myFunctionBlock.CodeChunkPointer = new UInt32[myFunctionBlock.FunctionCount];
+                        for (int i = 0; i < myFunctionBlock.FunctionCount; i++)
+                        {
+                            SendToDebug("Reading function " + i + " at: " + fs.Position);
+                            // TODO: ADD TO FUNCTION LIST (How do we identify it later?)
+                            // Note! Absolute position
+                            myFunctionBlock.CodeChunkPointer[i] = BitConverter.ToUInt32(br_read(4), 0) + myHeader.GFR;
+                            SendToDebug("Fuction " + i + " code chunk position: " + myFunctionBlock.CodeChunkPointer[i]);
+                        }
+                    }
+                }
+
+
+                // STATE FRAME BLOCK
+                // Always right after FUNCTION BLOCK
+                SendToDebug("Reading STATE BLOCK at: " + myHeader.SR);
+                fs.Seek(myHeader.SR, SeekOrigin.Begin);
+                LSO_Struct.StateFrameBlock myStateFrameBlock = new LSO_Struct.StateFrameBlock();
+                myStateFrameBlock.StateCount = BitConverter.ToUInt32(br_read(4), 0);
+                if (myStateFrameBlock.StateCount > 0)
+                {
+                    // Initialize array
+                    myStateFrameBlock.StatePointer = new LSO_Struct.StatePointerBlock[myStateFrameBlock.StateCount];
+                    for (int i = 0; i < myStateFrameBlock.StateCount; i++)
+                    {
+                        SendToDebug("Reading STATE POINTER BLOCK " + (i+1) + " at: " + fs.Position);
+                        // Position is relative to state frame
+                        myStateFrameBlock.StatePointer[i].Location = myHeader.SR + BitConverter.ToUInt32(br_read(4), 0);
+                        myStateFrameBlock.StatePointer[i].EventMask = new System.Collections.BitArray(br_read(8));
+                        SendToDebug("Pointer: " + myStateFrameBlock.StatePointer[i].Location);
+                        SendToDebug("Total potential EventMask bits: " + myStateFrameBlock.StatePointer[i].EventMask.Count);
+
+                        //// Read STATE BLOCK
+                        //long CurPos = fs.Position;
+                        //fs.Seek(CurPos, SeekOrigin.Begin);
+
+                    }
+                }
+
+
+                // STATE BLOCK
+                // For each StateFrameBlock there is one StateBlock with multiple event handlers
+
+                if (myStateFrameBlock.StateCount > 0)
+                {
+                    // Go through all State Frame Pointers found
+                    for (int i = 0; i < myStateFrameBlock.StateCount; i++)
+                    {
+                        
+                        fs.Seek(myStateFrameBlock.StatePointer[i].Location, SeekOrigin.Begin);
+                        SendToDebug("Reading STATE BLOCK " + (i + 1) + " at: " + fs.Position);
+
+                        // READ: STATE BLOCK HEADER
+                        myStateFrameBlock.StatePointer[i].StateBlock = new LSO_Struct.StateBlock();
+                        myStateFrameBlock.StatePointer[i].StateBlock.StartPos = (UInt32)fs.Position; // Note
+                        myStateFrameBlock.StatePointer[i].StateBlock.HeaderSize = BitConverter.ToUInt32(br_read(4), 0);
+                        myStateFrameBlock.StatePointer[i].StateBlock.Unknown = br_read(1)[0];
+                        myStateFrameBlock.StatePointer[i].StateBlock.EndPos = (UInt32)fs.Position; // Note
+                        SendToDebug("State block Start Pos: " + myStateFrameBlock.StatePointer[i].StateBlock.StartPos);
+                        SendToDebug("State block Header Size: " + myStateFrameBlock.StatePointer[i].StateBlock.HeaderSize);
+                        SendToDebug("State block Header End Pos: " + myStateFrameBlock.StatePointer[i].StateBlock.EndPos);
+
+                        // We need to count number of bits flagged in EventMask?
+
+
+                        // for each bit in myStateFrameBlock.StatePointer[i].EventMask
+
+                        // ADDING TO ALL RIGHT NOW, SHOULD LIMIT TO ONLY THE ONES IN USE
+                        //TODO: Create event hooks
+                        myStateFrameBlock.StatePointer[i].StateBlock.StateBlockHandlers = new LSO_Struct.StateBlockHandler[myStateFrameBlock.StatePointer[i].EventMask.Count - 1];
+                        for (int ii = 0; ii < myStateFrameBlock.StatePointer[i].EventMask.Count - 1; ii++)
+                        {
+                            
+                            if (myStateFrameBlock.StatePointer[i].EventMask.Get(ii) == true)
+                            {
+                                // We got an event
+                                //  READ: STATE BLOCK HANDLER
+                                SendToDebug("Reading STATE BLOCK " + (i + 1) + " HANDLER matching EVENT MASK " + ii  + " (" + ((LSO_Enums.Event_Mask_Values)ii).ToString() + ") at: " + fs.Position);
+                                myStateFrameBlock.StatePointer[i].StateBlock.StateBlockHandlers[ii].CodeChunkPointer = myStateFrameBlock.StatePointer[i].StateBlock.EndPos + BitConverter.ToUInt32(br_read(4), 0);
+                                myStateFrameBlock.StatePointer[i].StateBlock.StateBlockHandlers[ii].CallFrameSize = BitConverter.ToUInt32(br_read(4), 0);
+                                SendToDebug("Reading STATE BLOCK " + (i + 1) + " HANDLER EVENT MASK " + ii + " (" + ((LSO_Enums.Event_Mask_Values)ii).ToString() + ") Code Chunk Pointer: " + myStateFrameBlock.StatePointer[i].StateBlock.StateBlockHandlers[ii].CodeChunkPointer);
+                                SendToDebug("Reading STATE BLOCK " + (i + 1) + " HANDLER EVENT MASK " + ii + " (" + ((LSO_Enums.Event_Mask_Values)ii).ToString() + ") Call Frame Size: " + myStateFrameBlock.StatePointer[i].StateBlock.StateBlockHandlers[ii].CallFrameSize );
+                            }
+                        }
+                    }
+                }
+
+
+
+
+                //// READ FUNCTION CODE CHUNKS
+                //// Functions + Function start pos (GFR)
+                //// TODO: Somehow be able to identify and reference this
+                //LSO_Struct.CodeChunk[] myFunctionCodeChunk;
+                //if (myFunctionBlock.FunctionCount > 0)
+                //{
+                //    myFunctionCodeChunk = new LSO_Struct.CodeChunk[myFunctionBlock.FunctionCount];
+                //    for (int i = 0; i < myFunctionBlock.FunctionCount; i++)
+                //    {
+                //        SendToDebug("Reading Function Code Chunk " + i);
+                //        myFunctionCodeChunk[i] = GetCodeChunk((UInt32)myFunctionBlock.CodeChunkPointer[i]);
+                //    }
+
+                //}
+                // READ EVENT CODE CHUNKS
+                LSO_Struct.CodeChunk[] myEventCodeChunk;
+                if (myStateFrameBlock.StateCount > 0)
+                {
+                    myEventCodeChunk = new LSO_Struct.CodeChunk[myStateFrameBlock.StateCount];
+                    for (int i = 0; i < myStateFrameBlock.StateCount; i++)
+                    {
+                        // TODO: Somehow organize events and functions so they can be found again, 
+                        // two level search ain't no good
+                        for (int ii = 0; ii < myStateFrameBlock.StatePointer[i].EventMask.Count - 1; ii++)
+                        {
+
+
+                            if (myStateFrameBlock.StatePointer[i].StateBlock.StateBlockHandlers[ii].CodeChunkPointer > 0)
+                            {
+                                    SendToDebug("Reading Event Code Chunk state " + i + ", event " + (LSO_Enums.Event_Mask_Values)ii);
+
+
+                                    // Override a Method / Function
+                                    string eventname = "event_" + (LSO_Enums.Event_Mask_Values)ii;
+                                    SendToDebug("CLR:" + eventname + ":MethodBuilder methodBuilder = typeBuilder.DefineMethod...");
+                                    MethodBuilder methodBuilder = typeBuilder.DefineMethod(eventname,
+                                                 MethodAttributes.Private | MethodAttributes.Virtual,
+                                                 typeof(void),
+                                                 new Type[] { typeof(object) });
+
+                                    SendToDebug("CLR:" + eventname + ":typeBuilder.DefineMethodOverride(methodBuilder...");
+                                    typeBuilder.DefineMethodOverride(methodBuilder,
+                                            typeof(LSL_CLRInterface.LSLScript).GetMethod(eventname));
+
+                                    // Create the IL generator
+
+                                    SendToDebug("CLR:" + eventname + ":ILGenerator il = methodBuilder.GetILGenerator();");
+                                    ILGenerator il = methodBuilder.GetILGenerator();
+
+
+                                    LSO_Struct.CodeChunk myECC =
+                                        GetCodeChunk(myStateFrameBlock.StatePointer[i].StateBlock.StateBlockHandlers[ii].CodeChunkPointer, il, eventname);
+                            }
+                            
+                        }
+                    }
+
+                }
+
+
+                // Close
+                br.Close();
+                fs.Close();
+
+            }
+
+            private LSO_Struct.HeapBlock GetHeap(UInt32 pos)
+            {
+                // HEAP BLOCK
+                // TODO:? Special read for strings/keys (null terminated) and lists (pointers to other HEAP entries)
+                SendToDebug("Reading HEAP BLOCK at: " + pos);
+                fs.Seek(pos, SeekOrigin.Begin);
+                
+                LSO_Struct.HeapBlock myHeapBlock = new LSO_Struct.HeapBlock();
+                myHeapBlock.DataBlockSize = BitConverter.ToUInt32(br_read(4), 0);
+                myHeapBlock.ObjectType = br_read(1)[0];
+                myHeapBlock.ReferenceCount = BitConverter.ToUInt16(br_read(2), 0);
+                myHeapBlock.Data = br_read(getObjectSize(myHeapBlock.ObjectType));
+
+                SendToDebug("Heap Block Data Block Size: " + myHeapBlock.DataBlockSize);
+                SendToDebug("Heap Block ObjectType: " + ((LSO_Enums.Variable_Type_Codes)myHeapBlock.ObjectType).ToString());
+                SendToDebug("Heap Block Reference Count: " + myHeapBlock.ReferenceCount);
+
+                return myHeapBlock;
+            }
+
+     
+
+            private byte[] br_read(int len)
+            {
+                if (len <= 0)
+                    return null;
+
+                try
+                {
+                    byte[] bytes = new byte[len];
+                    for (int i = len - 1; i > -1; i--)
+                        bytes[i] = br.ReadByte();
+                    return bytes;
+                }
+                catch (Exception e)
+                {
+                    SendToDebug("Exception: " + e.ToString());
+                    throw (e);
+                }
+            }
+            //private byte[] br_read_smallendian(int len)
+            //{
+            //    byte[] bytes = new byte[len];    
+            //    br.Read(bytes,0, len);
+            //    return bytes;
+            //}
+
+            private int getObjectSize(byte ObjectType)
+            {
+                switch (ObjectType)
+                {
+                    case 1:
+                    case 2:
+                    case 3:
+                    case 4:
+                    case 7:
+                        return 4;
+                    case 5:
+                        return 12;
+                    case 6:
+                        return 16;
+                    default:
+                        return 0;
+                }
+            }
+            private void SendToDebug(string Message)
+            {
+                if (Debug == true)
+                    Console.WriteLine("Debug: " + Message);
+            }
+
+
+            private string Read_String()
+            {
+                string ret = "";
+                byte reader = br_read(1)[0];
+                while (reader != 0x000)
+                {
+                    ret += (char)reader;
+                    reader = br_read(1)[0];
+                }
+                return ret;
+            }
+
+             /// <summary>
+            /// Reads a code chunk into structure and returns it.
+            /// </summary>
+            /// <param name="pos">Absolute position in file. REMEMBER TO ADD myHeader.GFR!</param>
+            /// <returns></returns>
+            private LSO_Struct.CodeChunk GetCodeChunk(UInt32 pos, ILGenerator il, string eventname)
+            {
+
+                /*
+                 * CLR TRY
+                 */
+                //SendToDebug("CLR:" + eventname + ":il.BeginExceptionBlock()");
+                il.BeginExceptionBlock();
+
+                // Push "Hello World!" string to stack
+                //SendToDebug("CLR:" + eventname + ":il.Emit(OpCodes.Ldstr...");
+                il.Emit(OpCodes.Ldstr, "Starting CLR dynamic execution of: " + eventname);
+
+                // Push Console.WriteLine command to stack ... Console.WriteLine("Hello World!");
+                //SendToDebug("CLR:" + eventname + ":il.Emit(OpCodes.Call...");
+                il.Emit(OpCodes.Call, typeof(Console).GetMethod
+                    ("WriteLine", new Type[] { typeof(string) }));
+
+
+                LSO_Struct.CodeChunk myCodeChunk = new LSO_Struct.CodeChunk();
+
+                SendToDebug("Reading Function Code Chunk at: " + pos);
+                fs.Seek(pos, SeekOrigin.Begin);
+                myCodeChunk.CodeChunkHeaderSize = BitConverter.ToUInt32(br_read(4), 0);
+                SendToDebug("CodeChunk Header Size: " + myCodeChunk.CodeChunkHeaderSize );
+                // Read until null
+                myCodeChunk.Comment = Read_String();
+                SendToDebug("Function comment: " + myCodeChunk.Comment);
+                myCodeChunk.ReturnType = br_read(1)[0];
+                SendToDebug("Return type: " + (LSO_Enums.Variable_Type_Codes)myCodeChunk.ReturnType);
+                // TODO: How to determine number of codechunks -- does this method work?
+                myCodeChunk.CodeChunkArguments = new System.Collections.Generic.List<LSO_Struct.CodeChunkArgument>();
+                byte reader = br_read(1)[0];
+                reader = br_read(1)[0];
+                int ccount = 0;
+                while (reader != 0x000)
+                {
+                    ccount++;
+                    SendToDebug("Reading Code Chunk Argument " + ccount);
+                    LSO_Struct.CodeChunkArgument CCA = new LSO_Struct.CodeChunkArgument();
+                    CCA.FunctionReturnType = reader;
+                    reader = br_read(1)[0];
+                    CCA.NullString = reader;
+                    myCodeChunk.CodeChunkArguments.Add(CCA);
+                    SendToDebug("Code Chunk Argument " + ccount + " return type: " + (LSO_Enums.Variable_Type_Codes)CCA.FunctionReturnType);
+                }
+                // End marker is 0x000
+                myCodeChunk.EndMarker = reader;
+                // TODO: How to read and identify following code
+                // TODO: Code is read until a return of some sort is found
+                bool FoundRet = false;
+                while (FoundRet == false)
+                {
+                        //reader = br_read(1)[0];
+                    //UInt16  opcode = BitConverter.ToUInt16(br_read(1),0);
+                    UInt16 opcode = br_read(1)[0];
+                    //long rPos = fs.Position;
+                    SendToDebug("OPCODE: " + ((LSO_Enums.Operation_Table)opcode).ToString());
+                    switch (opcode)
+                    {
+                            // LONG
+                        case (UInt16)LSO_Enums.Operation_Table.POPARG:
+                        case (UInt16)LSO_Enums.Operation_Table.STORE:
+                        case (UInt16)LSO_Enums.Operation_Table.STORES:
+                        case (UInt16)LSO_Enums.Operation_Table.STOREL:
+                        case (UInt16)LSO_Enums.Operation_Table.STOREV:
+                        case (UInt16)LSO_Enums.Operation_Table.STOREQ:
+                        case (UInt16)LSO_Enums.Operation_Table.STOREG:
+                        case (UInt16)LSO_Enums.Operation_Table.STOREGS:
+                        case (UInt16)LSO_Enums.Operation_Table.STOREGL:
+                        case (UInt16)LSO_Enums.Operation_Table.STOREGV:
+                        case (UInt16)LSO_Enums.Operation_Table.STOREGQ:
+                        case (UInt16)LSO_Enums.Operation_Table.LOADP:
+                        case (UInt16)LSO_Enums.Operation_Table.LOADSP:
+                        case (UInt16)LSO_Enums.Operation_Table.LOADLP:
+                        case (UInt16)LSO_Enums.Operation_Table.LOADVP:
+                        case (UInt16)LSO_Enums.Operation_Table.LOADQP:
+                        case (UInt16)LSO_Enums.Operation_Table.PUSH:
+                        case (UInt16)LSO_Enums.Operation_Table.PUSHS:
+                        case (UInt16)LSO_Enums.Operation_Table.PUSHL:
+                        case (UInt16)LSO_Enums.Operation_Table.PUSHV:
+                        case (UInt16)LSO_Enums.Operation_Table.PUSHQ:
+                        case (UInt16)LSO_Enums.Operation_Table.PUSHG:
+                        case (UInt16)LSO_Enums.Operation_Table.PUSHGS:
+                        case (UInt16)LSO_Enums.Operation_Table.PUSHGL:
+                        case (UInt16)LSO_Enums.Operation_Table.PUSHGV:
+                        case (UInt16)LSO_Enums.Operation_Table.PUSHGQ:
+                            SendToDebug("Param1: " + BitConverter.ToUInt32(br_read(4),0));
+                            break;
+                            // BYTE
+                        case (UInt16)LSO_Enums.Operation_Table.PUSHARGB:
+                            SendToDebug("Param1: " + br_read(1)[0]);
+                            break;
+                            // INTEGER
+                        case (UInt16)LSO_Enums.Operation_Table.PUSHARGI:
+                            // TODO: What is size of integer?
+                            SendToDebug("Param1: " + BitConverter.ToUInt32(br_read(4),0));
+                            break;
+                            // FLOAT
+                        case (UInt16)LSO_Enums.Operation_Table.PUSHARGF:
+                            // TODO: What is size of float?
+                            SendToDebug("Param1: " + BitConverter.ToUInt32(br_read(4),0));
+                            break;
+                            // STRING
+                        case (UInt16)LSO_Enums.Operation_Table.PUSHARGS:
+                            string s = Read_String();
+                            SendToDebug("Param1: " + s);
+                            il.Emit(OpCodes.Ldstr, s);
+                            break;
+                            // VECTOR z,y,x
+                        case (UInt16)LSO_Enums.Operation_Table.PUSHARGV:
+                            SendToDebug("Param1 Z: " + BitConverter.ToUInt32(br_read(4),0));
+                            SendToDebug("Param1 Y: " + BitConverter.ToUInt32(br_read(4),0));
+                            SendToDebug("Param1 X: " + BitConverter.ToUInt32(br_read(4),0));
+                            break;
+                            // ROTATION s,z,y,x
+                        case (UInt16)LSO_Enums.Operation_Table.PUSHARGQ:
+                            SendToDebug("Param1 S: " + BitConverter.ToUInt32(br_read(4),0));
+                            SendToDebug("Param1 Z: " + BitConverter.ToUInt32(br_read(4),0));
+                            SendToDebug("Param1 Y: " + BitConverter.ToUInt32(br_read(4),0));
+                            SendToDebug("Param1 X: " + BitConverter.ToUInt32(br_read(4),0));
+                            break;
+                            // LONG
+                        case (UInt16)LSO_Enums.Operation_Table.PUSHARGE:
+                            SendToDebug("Param1: " + BitConverter.ToUInt32(br_read(4),0));
+                            break;
+                            // BYTE
+                        case (UInt16)LSO_Enums.Operation_Table.ADD:
+                        case (UInt16)LSO_Enums.Operation_Table.SUB:
+                        case (UInt16)LSO_Enums.Operation_Table.MUL:
+                        case (UInt16)LSO_Enums.Operation_Table.DIV:
+                        case (UInt16)LSO_Enums.Operation_Table.MOD:
+                        case (UInt16)LSO_Enums.Operation_Table.EQ:
+                        case (UInt16)LSO_Enums.Operation_Table.NEQ:
+                        case (UInt16)LSO_Enums.Operation_Table.LEQ:
+                        case (UInt16)LSO_Enums.Operation_Table.GEQ:
+                        case (UInt16)LSO_Enums.Operation_Table.LESS:
+                        case (UInt16)LSO_Enums.Operation_Table.GREATER:
+                        case (UInt16)LSO_Enums.Operation_Table.BOOLOR:
+                            SendToDebug("Param1: " + br_read(1)[0]);
+                            break;
+                            // LONG
+                        case (UInt16)LSO_Enums.Operation_Table.JUMP:
+                            SendToDebug("Param1: " + BitConverter.ToUInt32(br_read(4),0));
+                            break;
+                            // BYTE, LONG
+                        case (UInt16)LSO_Enums.Operation_Table.JUMPIF:
+                        case (UInt16)LSO_Enums.Operation_Table.JUMPNIF:
+                            SendToDebug("Param1: " + br_read(1)[0]);
+                            SendToDebug("Param2: " + BitConverter.ToUInt32(br_read(4),0));
+                            break;
+                            // LONG
+                        case (UInt16)LSO_Enums.Operation_Table.STATE:
+                        case (UInt16)LSO_Enums.Operation_Table.CALL:
+                            SendToDebug("Param1: " + BitConverter.ToUInt32(br_read(4),0));
+                            break;
+                            // BYTE
+                        case (UInt16)LSO_Enums.Operation_Table.CAST:
+                            SendToDebug("Param1: " + br_read(1)[0]);
+                            break;
+                            // LONG
+                        case (UInt16)LSO_Enums.Operation_Table.STACKTOS:
+                        case (UInt16)LSO_Enums.Operation_Table.STACKTOL:
+                            SendToDebug("Param1: " + BitConverter.ToUInt32(br_read(4),0));
+                            break;
+                            // BYTE
+                        case (UInt16)LSO_Enums.Operation_Table.PRINT:
+                        case (UInt16)LSO_Enums.Operation_Table.CALLLIB:
+                            SendToDebug("Param1: " + br_read(1)[0]);
+                            break;
+                            // SHORT
+                        case (UInt16)LSO_Enums.Operation_Table.CALLLIB_TWO_BYTE:
+                            // TODO: What is size of short?
+                            UInt16 _i = BitConverter.ToUInt16(br_read(2), 0);
+                            SendToDebug("Param1: " + _i);
+                            switch (_i)
+                            {
+                                case (UInt16)LSO_Enums.BuiltIn_Functions.llSay:
+                                    il.Emit(OpCodes.Call, typeof(Console).GetMethod
+                                        ("WriteLine", new Type[] { typeof(string) }));
+                                    break;
+                            }
+                            break;
+
+
+                        // RETURN
+                        case (UInt16)LSO_Enums.Operation_Table.RETURN:
+                            SendToDebug("Last OPCODE was return command. Code chunk execution complete.");
+                            FoundRet = true;
+                            break;
+                    }
+                    //fs.Seek(rPos, SeekOrigin.Begin);
+
+                }
+
+
+                /*
+                 * CATCH
+                 */
+                SendToDebug("CLR:" + eventname + ":il.BeginCatchBlock(typeof(Exception));");
+                il.BeginCatchBlock(typeof(Exception));
+
+                // Push "Hello World!" string to stack
+                SendToDebug("CLR:" + eventname + ":il.Emit(OpCodes.Ldstr...");
+                il.Emit(OpCodes.Ldstr, "Execption executing dynamic CLR function " + eventname + ": ");
+
+                //call void [mscorlib]System.Console::WriteLine(string)
+                SendToDebug("CLR:" + eventname + ":il.Emit(OpCodes.Call...");
+                il.Emit(OpCodes.Call, typeof(Console).GetMethod
+                    ("Write", new Type[] { typeof(string) }));
+
+                //callvirt instance string [mscorlib]System.Exception::get_Message()
+                SendToDebug("CLR:" + eventname + ":il.Emit(OpCodes.Callvirt...");
+                il.Emit(OpCodes.Callvirt, typeof(Exception).GetMethod
+                    ("get_Message"));
+
+                //call void [mscorlib]System.Console::WriteLine(string)
+                SendToDebug("CLR:" + eventname + ":il.Emit(OpCodes.Call...");
+                il.Emit(OpCodes.Call, typeof(Console).GetMethod
+                    ("WriteLine", new Type[] { typeof(string) }));
+
+                /*
+                 * CLR END TRY
+                 */
+                //SendToDebug("CLR:" + eventname + ":il.EndExceptionBlock();");
+                il.EndExceptionBlock();
+                // Push "Return from current method, with return value if present" to stack
+                il.Emit(OpCodes.Ret);
+
+
+
+                return myCodeChunk;
+
+            }
+    }
+}
diff --git a/OpenSim/Region/Environment/Scenes/scripting/Engines/LSLEngine/LSLHandler/LSO_Struct.cs b/OpenSim/Region/Environment/Scenes/scripting/Engines/LSLEngine/LSLHandler/LSO_Struct.cs
index 3b91e9f..66c6c5e 100644
--- a/OpenSim/Region/Environment/Scenes/scripting/Engines/LSLEngine/LSLHandler/LSO_Struct.cs
+++ b/OpenSim/Region/Environment/Scenes/scripting/Engines/LSLEngine/LSLHandler/LSO_Struct.cs
@@ -1,105 +1,105 @@
-
-using System;
-using System.Collections.Generic;
-using System.Text;
-
-namespace OpenSim.ScriptEngines.LSL
-{
-    static class LSO_Struct
-    {
-
-        public struct Header
-        {
-            public UInt32 TM;
-            public UInt32 IP;
-            public UInt32 VN;
-            public UInt32 BP;
-            public UInt32 SP;
-            public UInt32 HR;
-            public UInt32 HP;
-            public UInt32 CS;
-            public UInt32 NS;
-            public UInt32 CE;
-            public UInt32 IE;
-            public UInt32 ER;
-            public UInt32 FR;
-            public UInt32 SLR;
-            public UInt32 GVR;
-            public UInt32 GFR;
-            public UInt32 PR;
-            public UInt32 ESR;
-            public UInt32 SR;
-            public UInt64 NCE;
-            public UInt64 NIE;
-            public UInt64 NER;
-        }
-
-        public struct StaticBlock
-        {
-            public UInt32 Static_Chunk_Header_Size;
-            public byte ObjectType;
-            public byte Unknown;
-            public byte[] BlockVariable;
-        }
-        /* Not actually a structure
-        public struct StaticBlockVariable
-        {
-            public UInt32 Integer1;
-            public UInt32 Float1;
-            public UInt32 HeapPointer_String;
-            public UInt32 HeapPointer_Key;
-            public byte[] Vector_12;
-            public byte[] Rotation_16;
-            public UInt32 Pointer_List_Structure;
-        } */
-        public struct HeapBlock
-        {
-            public UInt32 DataBlockSize;
-            public byte ObjectType;
-            public UInt16 ReferenceCount;
-            public byte[] Data;
-        }
-        public struct StateFrameBlock
-        {
-            public UInt32 StateCount;
-            public StatePointerBlock[] StatePointer;
-        }
-        public struct StatePointerBlock
-        {
-            public UInt32 Location;
-            public System.Collections.BitArray EventMask;
-            public StateBlock StateBlock;
-        }
-        public struct StateBlock
-        {
-            public UInt32 StartPos;
-            public UInt32 EndPos;
-            public UInt32 HeaderSize;
-            public byte Unknown;
-            public StateBlockHandler[] StateBlockHandlers;
-        }
-        public struct StateBlockHandler
-        {
-            public UInt32 CodeChunkPointer;
-            public UInt32 CallFrameSize;
-        }
-        public struct FunctionBlock
-        {
-            public UInt32 FunctionCount;
-            public UInt32[] CodeChunkPointer;
-        }
-        public struct CodeChunk
-        {
-            public UInt32 CodeChunkHeaderSize;
-            public string Comment;
-            public System.Collections.Generic.List<CodeChunkArgument> CodeChunkArguments;
-            public byte EndMarker;
-            public byte ReturnType;
-        }
-        public struct CodeChunkArgument
-        {
-            public byte FunctionReturnType;
-            public byte NullString;
-        }
-    }
-}
+
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace OpenSim.ScriptEngines.LSL
+{
+    static class LSO_Struct
+    {
+
+        public struct Header
+        {
+            public UInt32 TM;
+            public UInt32 IP;
+            public UInt32 VN;
+            public UInt32 BP;
+            public UInt32 SP;
+            public UInt32 HR;
+            public UInt32 HP;
+            public UInt32 CS;
+            public UInt32 NS;
+            public UInt32 CE;
+            public UInt32 IE;
+            public UInt32 ER;
+            public UInt32 FR;
+            public UInt32 SLR;
+            public UInt32 GVR;
+            public UInt32 GFR;
+            public UInt32 PR;
+            public UInt32 ESR;
+            public UInt32 SR;
+            public UInt64 NCE;
+            public UInt64 NIE;
+            public UInt64 NER;
+        }
+
+        public struct StaticBlock
+        {
+            public UInt32 Static_Chunk_Header_Size;
+            public byte ObjectType;
+            public byte Unknown;
+            public byte[] BlockVariable;
+        }
+        /* Not actually a structure
+        public struct StaticBlockVariable
+        {
+            public UInt32 Integer1;
+            public UInt32 Float1;
+            public UInt32 HeapPointer_String;
+            public UInt32 HeapPointer_Key;
+            public byte[] Vector_12;
+            public byte[] Rotation_16;
+            public UInt32 Pointer_List_Structure;
+        } */
+        public struct HeapBlock
+        {
+            public UInt32 DataBlockSize;
+            public byte ObjectType;
+            public UInt16 ReferenceCount;
+            public byte[] Data;
+        }
+        public struct StateFrameBlock
+        {
+            public UInt32 StateCount;
+            public StatePointerBlock[] StatePointer;
+        }
+        public struct StatePointerBlock
+        {
+            public UInt32 Location;
+            public System.Collections.BitArray EventMask;
+            public StateBlock StateBlock;
+        }
+        public struct StateBlock
+        {
+            public UInt32 StartPos;
+            public UInt32 EndPos;
+            public UInt32 HeaderSize;
+            public byte Unknown;
+            public StateBlockHandler[] StateBlockHandlers;
+        }
+        public struct StateBlockHandler
+        {
+            public UInt32 CodeChunkPointer;
+            public UInt32 CallFrameSize;
+        }
+        public struct FunctionBlock
+        {
+            public UInt32 FunctionCount;
+            public UInt32[] CodeChunkPointer;
+        }
+        public struct CodeChunk
+        {
+            public UInt32 CodeChunkHeaderSize;
+            public string Comment;
+            public System.Collections.Generic.List<CodeChunkArgument> CodeChunkArguments;
+            public byte EndMarker;
+            public byte ReturnType;
+        }
+        public struct CodeChunkArgument
+        {
+            public byte FunctionReturnType;
+            public byte NullString;
+        }
+    }
+}
diff --git a/OpenSim/Region/Environment/Scenes/scripting/Script.cs b/OpenSim/Region/Environment/Scenes/scripting/Script.cs
index 99d7d04..40825c0 100644
--- a/OpenSim/Region/Environment/Scenes/scripting/Script.cs
+++ b/OpenSim/Region/Environment/Scenes/scripting/Script.cs
@@ -1,64 +1,64 @@
-/*
-* Copyright (c) Contributors, http://www.openmetaverse.org/
-* See CONTRIBUTORS.TXT for a full list of copyright holders.
-*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted provided that the following conditions are met:
-*     * Redistributions of source code must retain the above copyright
-*       notice, this list of conditions and the following disclaimer.
-*     * Redistributions in binary form must reproduce the above copyright
-*       notice, this list of conditions and the following disclaimer in the
-*       documentation and/or other materials provided with the distribution.
-*     * Neither the name of the OpenSim Project nor the
-*       names of its contributors may be used to endorse or promote products
-*       derived from this software without specific prior written permission.
-*
-* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
-* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
-* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-* 
-*/
-using OpenSim.Region.Environment.Scenes;
-
-namespace OpenSim.Region.Scripting
-{
-    public interface IScript
-    {
-        void Initialise(ScriptInfo scriptInfo);
-        string getName();
-    }
-
-    public class TestScript : IScript
-    {
-        ScriptInfo script;
-
-        public string getName()
-        {
-            return "TestScript 0.1";
-        }
-
-        public void Initialise(ScriptInfo scriptInfo)
-        {
-            script = scriptInfo;
-            script.events.OnFrame += new EventManager.OnFrameDelegate(events_OnFrame);
-            script.events.OnNewPresence += new EventManager.OnNewPresenceDelegate(events_OnNewPresence);
-        }
-
-        void events_OnNewPresence(ScenePresence presence)
-        {
-            script.logger.Verbose("Hello " + presence.firstname.ToString() + "!");
-        }
-
-        void events_OnFrame()
-        {
-            //script.logger.Verbose("Hello World!");
-        }
-    }
-}
+/*
+* Copyright (c) Contributors, http://www.openmetaverse.org/
+* See CONTRIBUTORS.TXT for a full list of copyright holders.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*     * Redistributions of source code must retain the above copyright
+*       notice, this list of conditions and the following disclaimer.
+*     * Redistributions in binary form must reproduce the above copyright
+*       notice, this list of conditions and the following disclaimer in the
+*       documentation and/or other materials provided with the distribution.
+*     * Neither the name of the OpenSim Project nor the
+*       names of its contributors may be used to endorse or promote products
+*       derived from this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
+* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
+* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+* 
+*/
+using OpenSim.Region.Environment.Scenes;
+
+namespace OpenSim.Region.Scripting
+{
+    public interface IScript
+    {
+        void Initialise(ScriptInfo scriptInfo);
+        string getName();
+    }
+
+    public class TestScript : IScript
+    {
+        ScriptInfo script;
+
+        public string getName()
+        {
+            return "TestScript 0.1";
+        }
+
+        public void Initialise(ScriptInfo scriptInfo)
+        {
+            script = scriptInfo;
+            script.events.OnFrame += new EventManager.OnFrameDelegate(events_OnFrame);
+            script.events.OnNewPresence += new EventManager.OnNewPresenceDelegate(events_OnNewPresence);
+        }
+
+        void events_OnNewPresence(ScenePresence presence)
+        {
+            script.logger.Verbose("Hello " + presence.firstname.ToString() + "!");
+        }
+
+        void events_OnFrame()
+        {
+            //script.logger.Verbose("Hello World!");
+        }
+    }
+}
diff --git a/OpenSim/Region/Environment/Scenes/scripting/ScriptAPI.cs b/OpenSim/Region/Environment/Scenes/scripting/ScriptAPI.cs
index a8f6aa5..b4f6a05 100644
--- a/OpenSim/Region/Environment/Scenes/scripting/ScriptAPI.cs
+++ b/OpenSim/Region/Environment/Scenes/scripting/ScriptAPI.cs
@@ -1,32 +1,32 @@
-using System;
-using System.Collections.Generic;
-using System.Text;
-using Key = libsecondlife.LLUUID;
-using Rotation = libsecondlife.LLQuaternion;
-using Vector = libsecondlife.LLVector3;
-using LSLList = System.Collections.Generic.List<string>;
-
-
-using OpenSim.Region.Environment.Scenes;
-
-namespace OpenSim.Region.Scripting
-{
-    // This class is to be used for engines which may not be able to access the Scene directly.
-    // Scene access is preffered, but obviously not possible on some non-.NET languages.
-    public class ScriptAPI
-    {
-        Scene scene;
-        ScriptInterpretedAPI interpretedAPI;
-
-        public ScriptAPI(Scene world)
-        {
-            scene = world;
-            interpretedAPI = new ScriptInterpretedAPI();
-        }
-
-        public Object CallMethod(String method, Object[] args)
-        {
-            return null;
-        }
-    }
-}
+using System;
+using System.Collections.Generic;
+using System.Text;
+using Key = libsecondlife.LLUUID;
+using Rotation = libsecondlife.LLQuaternion;
+using Vector = libsecondlife.LLVector3;
+using LSLList = System.Collections.Generic.List<string>;
+
+
+using OpenSim.Region.Environment.Scenes;
+
+namespace OpenSim.Region.Scripting
+{
+    // This class is to be used for engines which may not be able to access the Scene directly.
+    // Scene access is preffered, but obviously not possible on some non-.NET languages.
+    public class ScriptAPI
+    {
+        Scene scene;
+        ScriptInterpretedAPI interpretedAPI;
+
+        public ScriptAPI(Scene world)
+        {
+            scene = world;
+            interpretedAPI = new ScriptInterpretedAPI();
+        }
+
+        public Object CallMethod(String method, Object[] args)
+        {
+            return null;
+        }
+    }
+}
diff --git a/OpenSim/Region/Environment/Scenes/scripting/ScriptInfo.cs b/OpenSim/Region/Environment/Scenes/scripting/ScriptInfo.cs
index c3be22a..4a6086c 100644
--- a/OpenSim/Region/Environment/Scenes/scripting/ScriptInfo.cs
+++ b/OpenSim/Region/Environment/Scenes/scripting/ScriptInfo.cs
@@ -1,58 +1,58 @@
-/*
-* Copyright (c) Contributors, http://www.openmetaverse.org/
-* See CONTRIBUTORS.TXT for a full list of copyright holders.
-*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted provided that the following conditions are met:
-*     * Redistributions of source code must retain the above copyright
-*       notice, this list of conditions and the following disclaimer.
-*     * Redistributions in binary form must reproduce the above copyright
-*       notice, this list of conditions and the following disclaimer in the
-*       documentation and/or other materials provided with the distribution.
-*     * Neither the name of the OpenSim Project nor the
-*       names of its contributors may be used to endorse or promote products
-*       derived from this software without specific prior written permission.
-*
-* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
-* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
-* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-* 
-*/
-using OpenSim.Framework.Console;
-using OpenSim.Region.Environment.Scenes;
-
-namespace OpenSim.Region.Scripting
-{
-    /// <summary>
-    /// Class which provides access to the world
-    /// </summary>
-    public class ScriptInfo
-    {
-        // Reference to world.eventsManager provided for convenience
-        public EventManager events;
-
-        // The main world
-        public Scene world;
-
-        // The console
-        public LogBase logger;
-
-        // API Access
-        public ScriptAPI api;
-
-        public ScriptInfo(Scene scene)
-        {
-            world = scene;
-            events = world.EventManager;
-            logger = MainLog.Instance;
-            api = new ScriptAPI(scene);
-        }
-    }
-}
+/*
+* Copyright (c) Contributors, http://www.openmetaverse.org/
+* See CONTRIBUTORS.TXT for a full list of copyright holders.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*     * Redistributions of source code must retain the above copyright
+*       notice, this list of conditions and the following disclaimer.
+*     * Redistributions in binary form must reproduce the above copyright
+*       notice, this list of conditions and the following disclaimer in the
+*       documentation and/or other materials provided with the distribution.
+*     * Neither the name of the OpenSim Project nor the
+*       names of its contributors may be used to endorse or promote products
+*       derived from this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
+* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
+* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+* 
+*/
+using OpenSim.Framework.Console;
+using OpenSim.Region.Environment.Scenes;
+
+namespace OpenSim.Region.Scripting
+{
+    /// <summary>
+    /// Class which provides access to the world
+    /// </summary>
+    public class ScriptInfo
+    {
+        // Reference to world.eventsManager provided for convenience
+        public EventManager events;
+
+        // The main world
+        public Scene world;
+
+        // The console
+        public LogBase logger;
+
+        // API Access
+        public ScriptAPI api;
+
+        public ScriptInfo(Scene scene)
+        {
+            world = scene;
+            events = world.EventManager;
+            logger = MainLog.Instance;
+            api = new ScriptAPI(scene);
+        }
+    }
+}
diff --git a/OpenSim/Region/Environment/Scenes/scripting/ScriptInterpretedAPI.cs b/OpenSim/Region/Environment/Scenes/scripting/ScriptInterpretedAPI.cs
index 085d97e..b4a6019 100644
--- a/OpenSim/Region/Environment/Scenes/scripting/ScriptInterpretedAPI.cs
+++ b/OpenSim/Region/Environment/Scenes/scripting/ScriptInterpretedAPI.cs
@@ -1,206 +1,206 @@
-using System;
-using System.Collections.Generic;
-using System.Text;
-using Key = libsecondlife.LLUUID;
-using Rotation = libsecondlife.LLQuaternion;
-using Vector = libsecondlife.LLVector3;
-using LSLList = System.Collections.Generic.List<string>;
-
-using OpenSim.Region.Environment.Scenes;
-
-namespace OpenSim.Region.Scripting
-{
-    /// <summary>
-    /// A class inteded to act as an API for LSL-styled interpreted languages
-    /// </summary>
-    /// <remarks>Avoid at all costs. This should ONLY be used for LSL.</remarks>
-    class ScriptInterpretedAPI
-    {
-        public int osAbs(int val)
-        {
-            return Math.Abs(val);
-        }
-
-        public float osAcos(float val)
-        {
-            return (float)Math.Acos(val);
-        }
-
-        [Obsolete("Unimplemented")]
-        public void osAddToLandPassList(Key avatar, float hours)
-        {
-            OpenSim.Framework.Console.MainLog.Instance.Warn("Unimplemented function called by script: osAddToLandPassList(Key avatar, float hours)");
-            return;
-        }
-
-        [Obsolete("Unimplemented")]
-        public void osAdjustSoundVolume(float volume)
-        {
-            OpenSim.Framework.Console.MainLog.Instance.Warn("Unimplemented function called by script: osAdjustSoundVolume(float volume)");
-            return;
-        }
-
-        [Obsolete("Unimplemented")]
-        public void osAllowInventoryDrop(int add)
-        {
-            return;
-        }
-
-        [Obsolete("Unimplemented")]
-        public float osAngleBetween(Rotation a, Rotation b)
-        {
-            Axiom.Math.Quaternion axA = new Axiom.Math.Quaternion(a.W, a.X, a.Y, a.Z);
-            Axiom.Math.Quaternion axB = new Axiom.Math.Quaternion(b.W, b.X, b.Y, b.Z);
-
-            return 0;
-        }
-
-        [Obsolete("Unimplemented")]
-        public void osApplyImpulse(Vector force, int local)
-        {
-            return;
-        }
-
-        [Obsolete("Unimplemented")]
-        public void osApplyRotationalImpulse(Vector force, int local)
-        {
-            return;
-        }
-
-        public float osAsin(float val)
-        {
-            return (float)Math.Asin(val);
-        }
-
-        public float osAtan2(float x, float y)
-        {
-            return (float)Math.Atan2(x, y);
-        }
-
-        [Obsolete("Unimplemented")]
-        public void osAttachToAvatar(Key avatar, int attachmentPoint)
-        {
-            return;
-        }
-
-        [Obsolete("Unimplemented")]
-        public Key osAvatarOnSitTarget()
-        {
-            return Key.Zero;
-        }
-
-        public Rotation osAxes2Rot(Vector fwd, Vector left, Vector up)
-        {
-            Axiom.Math.Quaternion axQ = new Axiom.Math.Quaternion();
-            Axiom.Math.Vector3 axFwd = new Axiom.Math.Vector3(fwd.X, fwd.Y, fwd.Z);
-            Axiom.Math.Vector3 axLeft = new Axiom.Math.Vector3(left.X, left.Y, left.Z);
-            Axiom.Math.Vector3 axUp = new Axiom.Math.Vector3(up.X, up.Y, up.Z);
-
-            axQ.FromAxes(axFwd, axLeft, axUp);
-
-            return new Rotation(axQ.x, axQ.y, axQ.z, axQ.w);
-        }
-
-        public Rotation osAxisAngle2Rot(Vector axis, float angle)
-        {
-            Axiom.Math.Quaternion axQ = Axiom.Math.Quaternion.FromAngleAxis(angle, new Axiom.Math.Vector3(axis.X, axis.Y, axis.Z));
-
-            return new Rotation(axQ.x, axQ.y, axQ.z, axQ.w);
-        }
-
-        public string osBase64ToString(string str)
-        {
-            Encoding enc = System.Text.Encoding.UTF8;
-            return enc.GetString(Convert.FromBase64String(str));
-        }
-
-        [Obsolete("Unimplemented")]
-        public void osBreakAllLinks()
-        {
-            return;
-        }
-
-        [Obsolete("Unimplemented")]
-        public void osBreakLink()
-        {
-            return;
-        }
-
-        public LSLList osCSV2List(string src)
-        {
-            LSLList retVal = new LSLList();
-            retVal.AddRange(src.Split(','));
-
-            return retVal;
-        }
-
-        public int osCeil(float val)
-        {
-            return (int)Math.Ceiling(val);
-        }
-
-        [Obsolete("Unimplemented")]
-        public void osCloseRemoteDataChannel(Key channel)
-        {
-            return;
-        }
-
-        [Obsolete("Unimplemented")]
-        public float osCloud(Vector offset)
-        {
-            return 0.0f;
-        }
-
-        [Obsolete("Unimplemented")]
-        public void osCollisionFilter(string name, Key id, int accept)
-        {
-            return;
-        }
-
-        [Obsolete("Unimplemented")]
-        public void osCollisionSprite(string impact_sprite)
-        {
-            return;
-        }
-
-        public float osCos(float theta)
-        {
-            return (float)Math.Cos(theta);
-        }
-
-        [Obsolete("Unimplemented")]
-        public void osCreateLink(Key target, int parent)
-        {
-            return;
-        }
-
-        [Obsolete("Partially Unimplemented")]
-        public LSLList osDeleteSubList(LSLList src, int start, int end)
-        {
-            if (start < 0 || end < 0)
-            {
-                throw new Exception("Unsupported at this time.");
-            }
-
-            src.RemoveRange(start, start - end + 1);
-            return src;
-        }
-
-        [Obsolete("Partially Unimplemented")]
-        public string osDeleteSubString(string src, int start, int end)
-        {
-            if (start < 0 || end < 0)
-            {
-                throw new Exception("Unsupported at this time.");
-            }
-
-            return src.Remove(start, start - end + 1);
-        }
-
-        [Obsolete("Unimplemented")]
-        public void osDetachFromAvatar(Key avatar)
-        {
-            return;
-        }
-    }
-}
+using System;
+using System.Collections.Generic;
+using System.Text;
+using Key = libsecondlife.LLUUID;
+using Rotation = libsecondlife.LLQuaternion;
+using Vector = libsecondlife.LLVector3;
+using LSLList = System.Collections.Generic.List<string>;
+
+using OpenSim.Region.Environment.Scenes;
+
+namespace OpenSim.Region.Scripting
+{
+    /// <summary>
+    /// A class inteded to act as an API for LSL-styled interpreted languages
+    /// </summary>
+    /// <remarks>Avoid at all costs. This should ONLY be used for LSL.</remarks>
+    class ScriptInterpretedAPI
+    {
+        public int osAbs(int val)
+        {
+            return Math.Abs(val);
+        }
+
+        public float osAcos(float val)
+        {
+            return (float)Math.Acos(val);
+        }
+
+        [Obsolete("Unimplemented")]
+        public void osAddToLandPassList(Key avatar, float hours)
+        {
+            OpenSim.Framework.Console.MainLog.Instance.Warn("Unimplemented function called by script: osAddToLandPassList(Key avatar, float hours)");
+            return;
+        }
+
+        [Obsolete("Unimplemented")]
+        public void osAdjustSoundVolume(float volume)
+        {
+            OpenSim.Framework.Console.MainLog.Instance.Warn("Unimplemented function called by script: osAdjustSoundVolume(float volume)");
+            return;
+        }
+
+        [Obsolete("Unimplemented")]
+        public void osAllowInventoryDrop(int add)
+        {
+            return;
+        }
+
+        [Obsolete("Unimplemented")]
+        public float osAngleBetween(Rotation a, Rotation b)
+        {
+            Axiom.Math.Quaternion axA = new Axiom.Math.Quaternion(a.W, a.X, a.Y, a.Z);
+            Axiom.Math.Quaternion axB = new Axiom.Math.Quaternion(b.W, b.X, b.Y, b.Z);
+
+            return 0;
+        }
+
+        [Obsolete("Unimplemented")]
+        public void osApplyImpulse(Vector force, int local)
+        {
+            return;
+        }
+
+        [Obsolete("Unimplemented")]
+        public void osApplyRotationalImpulse(Vector force, int local)
+        {
+            return;
+        }
+
+        public float osAsin(float val)
+        {
+            return (float)Math.Asin(val);
+        }
+
+        public float osAtan2(float x, float y)
+        {
+            return (float)Math.Atan2(x, y);
+        }
+
+        [Obsolete("Unimplemented")]
+        public void osAttachToAvatar(Key avatar, int attachmentPoint)
+        {
+            return;
+        }
+
+        [Obsolete("Unimplemented")]
+        public Key osAvatarOnSitTarget()
+        {
+            return Key.Zero;
+        }
+
+        public Rotation osAxes2Rot(Vector fwd, Vector left, Vector up)
+        {
+            Axiom.Math.Quaternion axQ = new Axiom.Math.Quaternion();
+            Axiom.Math.Vector3 axFwd = new Axiom.Math.Vector3(fwd.X, fwd.Y, fwd.Z);
+            Axiom.Math.Vector3 axLeft = new Axiom.Math.Vector3(left.X, left.Y, left.Z);
+            Axiom.Math.Vector3 axUp = new Axiom.Math.Vector3(up.X, up.Y, up.Z);
+
+            axQ.FromAxes(axFwd, axLeft, axUp);
+
+            return new Rotation(axQ.x, axQ.y, axQ.z, axQ.w);
+        }
+
+        public Rotation osAxisAngle2Rot(Vector axis, float angle)
+        {
+            Axiom.Math.Quaternion axQ = Axiom.Math.Quaternion.FromAngleAxis(angle, new Axiom.Math.Vector3(axis.X, axis.Y, axis.Z));
+
+            return new Rotation(axQ.x, axQ.y, axQ.z, axQ.w);
+        }
+
+        public string osBase64ToString(string str)
+        {
+            Encoding enc = System.Text.Encoding.UTF8;
+            return enc.GetString(Convert.FromBase64String(str));
+        }
+
+        [Obsolete("Unimplemented")]
+        public void osBreakAllLinks()
+        {
+            return;
+        }
+
+        [Obsolete("Unimplemented")]
+        public void osBreakLink()
+        {
+            return;
+        }
+
+        public LSLList osCSV2List(string src)
+        {
+            LSLList retVal = new LSLList();
+            retVal.AddRange(src.Split(','));
+
+            return retVal;
+        }
+
+        public int osCeil(float val)
+        {
+            return (int)Math.Ceiling(val);
+        }
+
+        [Obsolete("Unimplemented")]
+        public void osCloseRemoteDataChannel(Key channel)
+        {
+            return;
+        }
+
+        [Obsolete("Unimplemented")]
+        public float osCloud(Vector offset)
+        {
+            return 0.0f;
+        }
+
+        [Obsolete("Unimplemented")]
+        public void osCollisionFilter(string name, Key id, int accept)
+        {
+            return;
+        }
+
+        [Obsolete("Unimplemented")]
+        public void osCollisionSprite(string impact_sprite)
+        {
+            return;
+        }
+
+        public float osCos(float theta)
+        {
+            return (float)Math.Cos(theta);
+        }
+
+        [Obsolete("Unimplemented")]
+        public void osCreateLink(Key target, int parent)
+        {
+            return;
+        }
+
+        [Obsolete("Partially Unimplemented")]
+        public LSLList osDeleteSubList(LSLList src, int start, int end)
+        {
+            if (start < 0 || end < 0)
+            {
+                throw new Exception("Unsupported at this time.");
+            }
+
+            src.RemoveRange(start, start - end + 1);
+            return src;
+        }
+
+        [Obsolete("Partially Unimplemented")]
+        public string osDeleteSubString(string src, int start, int end)
+        {
+            if (start < 0 || end < 0)
+            {
+                throw new Exception("Unsupported at this time.");
+            }
+
+            return src.Remove(start, start - end + 1);
+        }
+
+        [Obsolete("Unimplemented")]
+        public void osDetachFromAvatar(Key avatar)
+        {
+            return;
+        }
+    }
+}
diff --git a/OpenSim/Region/Environment/Scenes/scripting/ScriptInterpretedEvents.cs b/OpenSim/Region/Environment/Scenes/scripting/ScriptInterpretedEvents.cs
index 7743186..d6456a6 100644
--- a/OpenSim/Region/Environment/Scenes/scripting/ScriptInterpretedEvents.cs
+++ b/OpenSim/Region/Environment/Scenes/scripting/ScriptInterpretedEvents.cs
@@ -1,16 +1,16 @@
-using System;
-using System.Collections.Generic;
-using System.Text;
-using OpenSim.Region.Environment.Scenes;
-using libsecondlife;
-using Key = libsecondlife.LLUUID;
-
-namespace OpenSim.Region.Scripting
-{
-
-    public class ScriptInterpretedEvents
-    {
-        public delegate void OnTouchStartDelegate(Key user);
-        public event OnTouchStartDelegate OnTouchStart;
-    }
-}
+using System;
+using System.Collections.Generic;
+using System.Text;
+using OpenSim.Region.Environment.Scenes;
+using libsecondlife;
+using Key = libsecondlife.LLUUID;
+
+namespace OpenSim.Region.Scripting
+{
+
+    public class ScriptInterpretedEvents
+    {
+        public delegate void OnTouchStartDelegate(Key user);
+        public event OnTouchStartDelegate OnTouchStart;
+    }
+}
diff --git a/OpenSim/Region/Environment/Scenes/scripting/ScriptManager.cs b/OpenSim/Region/Environment/Scenes/scripting/ScriptManager.cs
index 7a08735..27e831b 100644
--- a/OpenSim/Region/Environment/Scenes/scripting/ScriptManager.cs
+++ b/OpenSim/Region/Environment/Scenes/scripting/ScriptManager.cs
@@ -1,107 +1,107 @@
-/*
-* Copyright (c) Contributors, http://www.openmetaverse.org/
-* See CONTRIBUTORS.TXT for a full list of copyright holders.
-*
-* Redistribution and use in source and binary forms, with or without
-* modification, are permitted provided that the following conditions are met:
-*     * Redistributions of source code must retain the above copyright
-*       notice, this list of conditions and the following disclaimer.
-*     * Redistributions in binary form must reproduce the above copyright
-*       notice, this list of conditions and the following disclaimer in the
-*       documentation and/or other materials provided with the distribution.
-*     * Neither the name of the OpenSim Project nor the
-*       names of its contributors may be used to endorse or promote products
-*       derived from this software without specific prior written permission.
-*
-* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
-* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
-* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-* 
-*/
-using System.Collections.Generic;
-using OpenSim.Framework.Console;
-using OpenSim.Region.Environment.Scenes;
-
-namespace OpenSim.Region.Scripting
-{
-    public class ScriptManager
-    {
-        List<IScript> scripts = new List<IScript>();
-        Scene scene;
-        Dictionary<string, IScriptCompiler> compilers = new Dictionary<string, IScriptCompiler>();
-
-        private void LoadFromCompiler(Dictionary<string, IScript> compiledscripts)
-        {
-            foreach (KeyValuePair<string, IScript> script in compiledscripts)
-            {
-                ScriptInfo scriptInfo = new ScriptInfo(scene); // Since each script could potentially corrupt their access with a stray assignment, making a new one for each script.
-                MainLog.Instance.Verbose("Loading " + script.Key);
-                script.Value.Initialise(scriptInfo);
-                scripts.Add(script.Value);
-            }
-            MainLog.Instance.Verbose("Finished loading " + compiledscripts.Count.ToString() + " script(s)");
-        }
-
-        public ScriptManager(Scene world)
-        {
-            scene = world;
-
-            // Default Engines
-            CSharpScriptEngine csharpCompiler = new CSharpScriptEngine();
-            compilers.Add(csharpCompiler.FileExt(),csharpCompiler);
-
-            JScriptEngine jscriptCompiler = new JScriptEngine();
-            compilers.Add(jscriptCompiler.FileExt(), jscriptCompiler);
-
-            JavaEngine javaCompiler = new JavaEngine();
-            compilers.Add(javaCompiler.FileExt(), javaCompiler);
-        }
-
-        public void Compile(string filename)
-        {
-            foreach (KeyValuePair<string, IScriptCompiler> compiler in compilers)
-            {
-                if (filename.EndsWith(compiler.Key))
-                {
-                    LoadFromCompiler(compiler.Value.compile(filename));
-                    break;
-                }
-            }
-        }
-
-        public void RunScriptCmd(string[] args)
-        {
-            switch (args[0])
-            {
-                case "load":
-                    Compile(args[1]);
-                    break;
-
-                default:
-                    MainLog.Instance.Error("Unknown script command");
-                    break;
-            }
-        }
-
-        public void AddPreCompiledScript(IScript script)
-        {
-            MainLog.Instance.Verbose("Loading script " + script.getName()); 
-            ScriptInfo scriptInfo = new ScriptInfo(scene); // Since each script could potentially corrupt their access with a stray assignment, making a new one for each script.
-            script.Initialise(scriptInfo);
-            scripts.Add(script);
-        }
-    }
-
-    interface IScriptCompiler
-    {
-        Dictionary<string,IScript> compile(string filename);
-        string FileExt();
-    }
-}
+/*
+* Copyright (c) Contributors, http://www.openmetaverse.org/
+* See CONTRIBUTORS.TXT for a full list of copyright holders.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*     * Redistributions of source code must retain the above copyright
+*       notice, this list of conditions and the following disclaimer.
+*     * Redistributions in binary form must reproduce the above copyright
+*       notice, this list of conditions and the following disclaimer in the
+*       documentation and/or other materials provided with the distribution.
+*     * Neither the name of the OpenSim Project nor the
+*       names of its contributors may be used to endorse or promote products
+*       derived from this software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
+* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
+* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+* 
+*/
+using System.Collections.Generic;
+using OpenSim.Framework.Console;
+using OpenSim.Region.Environment.Scenes;
+
+namespace OpenSim.Region.Scripting
+{
+    public class ScriptManager
+    {
+        List<IScript> scripts = new List<IScript>();
+        Scene scene;
+        Dictionary<string, IScriptCompiler> compilers = new Dictionary<string, IScriptCompiler>();
+
+        private void LoadFromCompiler(Dictionary<string, IScript> compiledscripts)
+        {
+            foreach (KeyValuePair<string, IScript> script in compiledscripts)
+            {
+                ScriptInfo scriptInfo = new ScriptInfo(scene); // Since each script could potentially corrupt their access with a stray assignment, making a new one for each script.
+                MainLog.Instance.Verbose("Loading " + script.Key);
+                script.Value.Initialise(scriptInfo);
+                scripts.Add(script.Value);
+            }
+            MainLog.Instance.Verbose("Finished loading " + compiledscripts.Count.ToString() + " script(s)");
+        }
+
+        public ScriptManager(Scene world)
+        {
+            scene = world;
+
+            // Default Engines
+            CSharpScriptEngine csharpCompiler = new CSharpScriptEngine();
+            compilers.Add(csharpCompiler.FileExt(),csharpCompiler);
+
+            JScriptEngine jscriptCompiler = new JScriptEngine();
+            compilers.Add(jscriptCompiler.FileExt(), jscriptCompiler);
+
+            JavaEngine javaCompiler = new JavaEngine();
+            compilers.Add(javaCompiler.FileExt(), javaCompiler);
+        }
+
+        public void Compile(string filename)
+        {
+            foreach (KeyValuePair<string, IScriptCompiler> compiler in compilers)
+            {
+                if (filename.EndsWith(compiler.Key))
+                {
+                    LoadFromCompiler(compiler.Value.compile(filename));
+                    break;
+                }
+            }
+        }
+
+        public void RunScriptCmd(string[] args)
+        {
+            switch (args[0])
+            {
+                case "load":
+                    Compile(args[1]);
+                    break;
+
+                default:
+                    MainLog.Instance.Error("Unknown script command");
+                    break;
+            }
+        }
+
+        public void AddPreCompiledScript(IScript script)
+        {
+            MainLog.Instance.Verbose("Loading script " + script.getName()); 
+            ScriptInfo scriptInfo = new ScriptInfo(scene); // Since each script could potentially corrupt their access with a stray assignment, making a new one for each script.
+            script.Initialise(scriptInfo);
+            scripts.Add(script);
+        }
+    }
+
+    interface IScriptCompiler
+    {
+        Dictionary<string,IScript> compile(string filename);
+        string FileExt();
+    }
+}
-- 
cgit v1.1