ThreadPoolClientBranch
Tedd Hansen 2008-01-12 15:52:34 +00:00
parent 27859faf7a
commit f9c981007d
12 changed files with 3006 additions and 3006 deletions

View File

@ -1,86 +1,86 @@
/* /*
* Copyright (c) Contributors, http://opensimulator.org/ * Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders. * See CONTRIBUTORS.TXT for a full list of copyright holders.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright * * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer. * notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright * * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the * notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution. * documentation and/or other materials provided with the distribution.
* * Neither the name of the OpenSim Project nor the * * Neither the name of the OpenSim Project nor the
* names of its contributors may be used to endorse or promote products * names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission. * derived from this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * 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 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
*/ */
/* Original code: Tedd Hansen */ /* Original code: Tedd Hansen */
using System; using System;
namespace OpenSim.Region.ScriptEngine.LSOEngine.LSO namespace OpenSim.Region.ScriptEngine.LSOEngine.LSO
{ {
public static class Common public static class Common
{ {
public static bool Debug = true; public static bool Debug = true;
public static bool IL_UseTryCatch = true; public static bool IL_UseTryCatch = true;
public static bool IL_CreateConstructor = true; public static bool IL_CreateConstructor = true;
public static bool IL_CreateFunctionList = true; public static bool IL_CreateFunctionList = true;
public static bool IL_ProcessCodeChunks = true; public static bool IL_ProcessCodeChunks = true;
public delegate void SendToDebugEventDelegate(string Message); public delegate void SendToDebugEventDelegate(string Message);
public delegate void SendToLogEventDelegate(string Message); public delegate void SendToLogEventDelegate(string Message);
public static event SendToDebugEventDelegate SendToDebugEvent; public static event SendToDebugEventDelegate SendToDebugEvent;
public static event SendToLogEventDelegate SendToLogEvent; public static event SendToLogEventDelegate SendToLogEvent;
public static void SendToDebug(string Message) public static void SendToDebug(string Message)
{ {
//if (Debug == true) //if (Debug == true)
Console.WriteLine("COMPILER:Debug: " + Message); Console.WriteLine("COMPILER:Debug: " + Message);
SendToDebugEvent("\r\n" + DateTime.Now.ToString("[HH:mm:ss] ") + Message); SendToDebugEvent("\r\n" + DateTime.Now.ToString("[HH:mm:ss] ") + Message);
} }
public static void SendToLog(string Message) public static void SendToLog(string Message)
{ {
//if (Debug == true) //if (Debug == true)
Console.WriteLine("COMPILER:LOG: " + Message); Console.WriteLine("COMPILER:LOG: " + Message);
SendToLogEvent("\r\n" + DateTime.Now.ToString("[HH:mm:ss] ") + Message); SendToLogEvent("\r\n" + DateTime.Now.ToString("[HH:mm:ss] ") + Message);
} }
} }
public static class IL_Helper public static class IL_Helper
{ {
public static string ReverseFormatString(string text1, string format) public static string ReverseFormatString(string text1, string format)
{ {
Common.SendToDebug("ReverseFormatString text1: " + text1); Common.SendToDebug("ReverseFormatString text1: " + text1);
Common.SendToDebug("ReverseFormatString format: " + format); Common.SendToDebug("ReverseFormatString format: " + format);
return string.Format(format, text1); return string.Format(format, text1);
} }
public static string ReverseFormatString(string text1, UInt32 text2, string format) public static string ReverseFormatString(string text1, UInt32 text2, string format)
{ {
Common.SendToDebug("ReverseFormatString text1: " + text1); Common.SendToDebug("ReverseFormatString text1: " + text1);
Common.SendToDebug("ReverseFormatString text2: " + text2.ToString()); Common.SendToDebug("ReverseFormatString text2: " + text2.ToString());
Common.SendToDebug("ReverseFormatString format: " + format); Common.SendToDebug("ReverseFormatString format: " + format);
return string.Format(format, text1, text2.ToString()); return string.Format(format, text1, text2.ToString());
} }
public static string Cast_ToString(object obj) public static string Cast_ToString(object obj)
{ {
Common.SendToDebug("OBJECT TO BE CASTED: " + obj.GetType().ToString()); Common.SendToDebug("OBJECT TO BE CASTED: " + obj.GetType().ToString());
return "ABCDEFGIHJKLMNOPQ123"; return "ABCDEFGIHJKLMNOPQ123";
} }
} }
} }

View File

@ -1,293 +1,293 @@
/* /*
* Copyright (c) Contributors, http://opensimulator.org/ * Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders. * See CONTRIBUTORS.TXT for a full list of copyright holders.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright * * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer. * notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright * * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the * notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution. * documentation and/or other materials provided with the distribution.
* * Neither the name of the OpenSim Project nor the * * Neither the name of the OpenSim Project nor the
* names of its contributors may be used to endorse or promote products * names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission. * derived from this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * 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 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
*/ */
/* Original code: Tedd Hansen */ /* Original code: Tedd Hansen */
using System; using System;
using System.IO; using System.IO;
using System.Reflection; using System.Reflection;
using System.Reflection.Emit; using System.Reflection.Emit;
using System.Text; using System.Text;
using System.Threading; using System.Threading;
using OpenSim.Region.ScriptEngine.Common; using OpenSim.Region.ScriptEngine.Common;
using OpenSim.Region.ScriptEngine.LSOEngine.LSO; using OpenSim.Region.ScriptEngine.LSOEngine.LSO;
namespace OpenSim.Region.ScriptEngine.LSOEngine.LSO namespace OpenSim.Region.ScriptEngine.LSOEngine.LSO
{ {
public class Engine public class Engine
{ {
//private string LSO_FileName = @"LSO\AdditionTest.lso"; //private string LSO_FileName = @"LSO\AdditionTest.lso";
private string LSO_FileName; // = @"LSO\CloseToDefault.lso"; private string LSO_FileName; // = @"LSO\CloseToDefault.lso";
private AppDomain appDomain; private AppDomain appDomain;
public string Compile(string LSOFileName) public string Compile(string LSOFileName)
{ {
LSO_FileName = LSOFileName; LSO_FileName = LSOFileName;
//appDomain = AppDomain.CreateDomain("AlternateAppDomain"); //appDomain = AppDomain.CreateDomain("AlternateAppDomain");
appDomain = Thread.GetDomain(); appDomain = Thread.GetDomain();
// Create Assembly Name // Create Assembly Name
AssemblyName asmName = new AssemblyName(); AssemblyName asmName = new AssemblyName();
asmName.Name = Path.GetFileNameWithoutExtension(LSO_FileName); asmName.Name = Path.GetFileNameWithoutExtension(LSO_FileName);
//asmName.Name = "TestAssembly"; //asmName.Name = "TestAssembly";
string DLL_FileName = asmName.Name + ".dll"; string DLL_FileName = asmName.Name + ".dll";
string DLL_FileName_WithPath = Path.GetDirectoryName(LSO_FileName) + @"\" + DLL_FileName; string DLL_FileName_WithPath = Path.GetDirectoryName(LSO_FileName) + @"\" + DLL_FileName;
LSOEngine.LSO.Common.SendToLog("LSO File Name: " + Path.GetFileName(LSO_FileName)); LSOEngine.LSO.Common.SendToLog("LSO File Name: " + Path.GetFileName(LSO_FileName));
LSOEngine.LSO.Common.SendToLog("Assembly name: " + asmName.Name); LSOEngine.LSO.Common.SendToLog("Assembly name: " + asmName.Name);
LSOEngine.LSO.Common.SendToLog("Assembly File Name: " + asmName.Name + ".dll"); LSOEngine.LSO.Common.SendToLog("Assembly File Name: " + asmName.Name + ".dll");
LSOEngine.LSO.Common.SendToLog("Starting processing of LSL ByteCode..."); LSOEngine.LSO.Common.SendToLog("Starting processing of LSL ByteCode...");
LSOEngine.LSO.Common.SendToLog(""); LSOEngine.LSO.Common.SendToLog("");
// Create Assembly // Create Assembly
AssemblyBuilder asmBuilder = appDomain.DefineDynamicAssembly( AssemblyBuilder asmBuilder = appDomain.DefineDynamicAssembly(
asmName, asmName,
AssemblyBuilderAccess.RunAndSave AssemblyBuilderAccess.RunAndSave
); );
//// Create Assembly //// Create Assembly
//AssemblyBuilder asmBuilder = //AssemblyBuilder asmBuilder =
// Thread.GetDomain().DefineDynamicAssembly // Thread.GetDomain().DefineDynamicAssembly
//(asmName, AssemblyBuilderAccess.RunAndSave); //(asmName, AssemblyBuilderAccess.RunAndSave);
// Create a module (and save to disk) // Create a module (and save to disk)
ModuleBuilder modBuilder = asmBuilder.DefineDynamicModule ModuleBuilder modBuilder = asmBuilder.DefineDynamicModule
(asmName.Name, (asmName.Name,
DLL_FileName); DLL_FileName);
//Common.SendToDebug("asmName.Name is still \"" + asmName.Name + "\""); //Common.SendToDebug("asmName.Name is still \"" + asmName.Name + "\"");
// Create a Class (/Type) // Create a Class (/Type)
TypeBuilder typeBuilder = modBuilder.DefineType( TypeBuilder typeBuilder = modBuilder.DefineType(
"LSL_ScriptObject", "LSL_ScriptObject",
TypeAttributes.Public | TypeAttributes.BeforeFieldInit, TypeAttributes.Public | TypeAttributes.BeforeFieldInit,
typeof (LSL_BaseClass)); typeof (LSL_BaseClass));
//, //,
// typeof()); // typeof());
//, typeof(LSL_BuiltIn_Commands_Interface)); //, typeof(LSL_BuiltIn_Commands_Interface));
//, //,
// typeof(object), // typeof(object),
// new Type[] { typeof(LSL_CLRInterface.LSLScript) }); // new Type[] { typeof(LSL_CLRInterface.LSLScript) });
/* /*
* Generate the IL itself * Generate the IL itself
*/ */
LSO_Parser LSOP = new LSO_Parser(LSO_FileName, typeBuilder); LSO_Parser LSOP = new LSO_Parser(LSO_FileName, typeBuilder);
LSOP.OpenFile(); LSOP.OpenFile();
LSOP.Parse(); LSOP.Parse();
// Constructor has to be created AFTER LSO_Parser because of accumulated variables // Constructor has to be created AFTER LSO_Parser because of accumulated variables
if (LSOEngine.LSO.Common.IL_CreateConstructor) if (LSOEngine.LSO.Common.IL_CreateConstructor)
IL_CREATE_CONSTRUCTOR(typeBuilder, LSOP); IL_CREATE_CONSTRUCTOR(typeBuilder, LSOP);
LSOP.CloseFile(); LSOP.CloseFile();
/* /*
* Done generating. Create a type and run it. * Done generating. Create a type and run it.
*/ */
LSOEngine.LSO.Common.SendToLog("Attempting to compile assembly..."); LSOEngine.LSO.Common.SendToLog("Attempting to compile assembly...");
// Compile it // Compile it
Type type = typeBuilder.CreateType(); Type type = typeBuilder.CreateType();
LSOEngine.LSO.Common.SendToLog("Compilation successful!"); LSOEngine.LSO.Common.SendToLog("Compilation successful!");
LSOEngine.LSO.Common.SendToLog("Saving assembly: " + DLL_FileName); LSOEngine.LSO.Common.SendToLog("Saving assembly: " + DLL_FileName);
asmBuilder.Save(DLL_FileName); asmBuilder.Save(DLL_FileName);
LSOEngine.LSO.Common.SendToLog("Returning assembly filename: " + DLL_FileName); LSOEngine.LSO.Common.SendToLog("Returning assembly filename: " + DLL_FileName);
return DLL_FileName; return DLL_FileName;
//Common.SendToLog("Creating an instance of new assembly..."); //Common.SendToLog("Creating an instance of new assembly...");
//// Create an instance we can play with //// Create an instance we can play with
////LSLScript hello = (LSLScript)Activator.CreateInstance(type); ////LSLScript hello = (LSLScript)Activator.CreateInstance(type);
////LSL_CLRInterface.LSLScript MyScript = (LSL_CLRInterface.LSLScript)Activator.CreateInstance(type); ////LSL_CLRInterface.LSLScript MyScript = (LSL_CLRInterface.LSLScript)Activator.CreateInstance(type);
//object MyScript = (object)Activator.CreateInstance(type); //object MyScript = (object)Activator.CreateInstance(type);
//System.Reflection.MemberInfo[] Members = type.GetMembers(); //System.Reflection.MemberInfo[] Members = type.GetMembers();
//Common.SendToLog("Members of assembly " + type.ToString() + ":"); //Common.SendToLog("Members of assembly " + type.ToString() + ":");
//foreach (MemberInfo member in Members) //foreach (MemberInfo member in Members)
// Common.SendToLog(member.ToString()); // Common.SendToLog(member.ToString());
//// Play with it //// Play with it
////MyScript.event_state_entry("Test"); ////MyScript.event_state_entry("Test");
//object[] args = { null }; //object[] args = { null };
////System.Collections.Generic.List<string> Functions = (System.Collections.Generic.List<string>)type.InvokeMember("GetFunctions", BindingFlags.InvokeMethod, null, MyScript, null); ////System.Collections.Generic.List<string> Functions = (System.Collections.Generic.List<string>)type.InvokeMember("GetFunctions", BindingFlags.InvokeMethod, null, MyScript, null);
//string[] ret = { }; //string[] ret = { };
//if (Common.IL_CreateFunctionList) //if (Common.IL_CreateFunctionList)
// ret = (string[])type.InvokeMember("GetFunctions", BindingFlags.InvokeMethod, null, MyScript, null); // ret = (string[])type.InvokeMember("GetFunctions", BindingFlags.InvokeMethod, null, MyScript, null);
//foreach (string s in ret) //foreach (string s in ret)
//{ //{
// Common.SendToLog(""); // Common.SendToLog("");
// Common.SendToLog("*** Executing LSL Server Event: " + s); // Common.SendToLog("*** Executing LSL Server Event: " + s);
// //object test = type.GetMember(s); // //object test = type.GetMember(s);
// //object runner = type.InvokeMember(s, BindingFlags.Public | BindingFlags.InvokeMethod | BindingFlags.Instance, null, MyScript, args); // //object runner = type.InvokeMember(s, BindingFlags.Public | BindingFlags.InvokeMethod | BindingFlags.Instance, null, MyScript, args);
// //runner(); // //runner();
// //objBooks_Late = type.InvokeMember(s, BindingFlags.CreateInstance, null, objApp_Late, null); // //objBooks_Late = type.InvokeMember(s, BindingFlags.CreateInstance, null, objApp_Late, null);
// type.InvokeMember(s, BindingFlags.InvokeMethod, null, MyScript, new object[] { "Test" }); // type.InvokeMember(s, BindingFlags.InvokeMethod, null, MyScript, new object[] { "Test" });
//} //}
} }
private static void IL_CREATE_CONSTRUCTOR(TypeBuilder typeBuilder, LSO_Parser LSOP) private static void IL_CREATE_CONSTRUCTOR(TypeBuilder typeBuilder, LSO_Parser LSOP)
{ {
LSOEngine.LSO.Common.SendToDebug("IL_CREATE_CONSTRUCTOR()"); LSOEngine.LSO.Common.SendToDebug("IL_CREATE_CONSTRUCTOR()");
//ConstructorBuilder constructor = typeBuilder.DefineConstructor( //ConstructorBuilder constructor = typeBuilder.DefineConstructor(
// MethodAttributes.Public, // MethodAttributes.Public,
// CallingConventions.Standard, // CallingConventions.Standard,
// new Type[0]); // new Type[0]);
ConstructorBuilder constructor = typeBuilder.DefineConstructor( ConstructorBuilder constructor = typeBuilder.DefineConstructor(
MethodAttributes.Public | MethodAttributes.Public |
MethodAttributes.SpecialName | MethodAttributes.SpecialName |
MethodAttributes.RTSpecialName, MethodAttributes.RTSpecialName,
CallingConventions.Standard, CallingConventions.Standard,
new Type[0]); new Type[0]);
//Define the reflection ConstructorInfor for System.Object //Define the reflection ConstructorInfor for System.Object
ConstructorInfo conObj = typeof (LSL_BaseClass).GetConstructor(new Type[0]); ConstructorInfo conObj = typeof (LSL_BaseClass).GetConstructor(new Type[0]);
//call constructor of base object //call constructor of base object
ILGenerator il = constructor.GetILGenerator(); ILGenerator il = constructor.GetILGenerator();
il.Emit(OpCodes.Ldarg_0); il.Emit(OpCodes.Ldarg_0);
il.Emit(OpCodes.Call, conObj); il.Emit(OpCodes.Call, conObj);
//Common.SendToDebug("IL_CREATE_CONSTRUCTOR: Creating global: UInt32 State = 0;"); //Common.SendToDebug("IL_CREATE_CONSTRUCTOR: Creating global: UInt32 State = 0;");
//string FieldName; //string FieldName;
//// Create state object //// Create state object
//FieldName = "State"; //FieldName = "State";
//FieldBuilder State_fb = typeBuilder.DefineField( //FieldBuilder State_fb = typeBuilder.DefineField(
// FieldName, // FieldName,
// typeof(UInt32), // typeof(UInt32),
// FieldAttributes.Public); // FieldAttributes.Public);
//il.Emit(OpCodes.Ldarg_0); //il.Emit(OpCodes.Ldarg_0);
//il.Emit(OpCodes.Ldc_I4, 0); //il.Emit(OpCodes.Ldc_I4, 0);
//il.Emit(OpCodes.Stfld, State_fb); //il.Emit(OpCodes.Stfld, State_fb);
//Common.SendToDebug("IL_CREATE_CONSTRUCTOR: Creating global: LSL_BuiltIn_Commands_TestImplementation LSL_BuiltIns = New LSL_BuiltIn_Commands_TestImplementation();"); //Common.SendToDebug("IL_CREATE_CONSTRUCTOR: Creating global: LSL_BuiltIn_Commands_TestImplementation LSL_BuiltIns = New LSL_BuiltIn_Commands_TestImplementation();");
////Type objType1 = typeof(object); ////Type objType1 = typeof(object);
//Type objType1 = typeof(LSL_BuiltIn_Commands_TestImplementation); //Type objType1 = typeof(LSL_BuiltIn_Commands_TestImplementation);
//FieldName = "LSL_BuiltIns"; //FieldName = "LSL_BuiltIns";
//FieldBuilder LSL_BuiltIns_fb = typeBuilder.DefineField( //FieldBuilder LSL_BuiltIns_fb = typeBuilder.DefineField(
// FieldName, // FieldName,
// objType1, // objType1,
// FieldAttributes.Public); // FieldAttributes.Public);
////LSL_BuiltIn_Commands_TestImplementation _ti = new LSL_BuiltIn_Commands_TestImplementation(); ////LSL_BuiltIn_Commands_TestImplementation _ti = new LSL_BuiltIn_Commands_TestImplementation();
//il.Emit(OpCodes.Ldarg_0); //il.Emit(OpCodes.Ldarg_0);
////il.Emit(OpCodes.Ldstr, "Test 123"); ////il.Emit(OpCodes.Ldstr, "Test 123");
//il.Emit(OpCodes.Newobj, objType1.GetConstructor(new Type[] { })); //il.Emit(OpCodes.Newobj, objType1.GetConstructor(new Type[] { }));
//il.Emit(OpCodes.Stfld, LSL_BuiltIns_fb); //il.Emit(OpCodes.Stfld, LSL_BuiltIns_fb);
foreach (UInt32 pos in LSOP.StaticBlocks.Keys) foreach (UInt32 pos in LSOP.StaticBlocks.Keys)
{ {
LSO_Struct.StaticBlock sb; LSO_Struct.StaticBlock sb;
LSOP.StaticBlocks.TryGetValue(pos, out sb); LSOP.StaticBlocks.TryGetValue(pos, out sb);
if (sb.ObjectType > 0 && sb.ObjectType < 8) if (sb.ObjectType > 0 && sb.ObjectType < 8)
{ {
// We don't want void or null's // We don't want void or null's
il.Emit(OpCodes.Ldarg_0); il.Emit(OpCodes.Ldarg_0);
// Push position to stack // Push position to stack
il.Emit(OpCodes.Ldc_I4, pos); il.Emit(OpCodes.Ldc_I4, pos);
//il.Emit(OpCodes.Box, typeof(UInt32)); //il.Emit(OpCodes.Box, typeof(UInt32));
Type datatype = null; Type datatype = null;
// Push data to stack // Push data to stack
LSOEngine.LSO.Common.SendToDebug("Adding to static (" + pos + ") type: " + LSOEngine.LSO.Common.SendToDebug("Adding to static (" + pos + ") type: " +
((LSO_Enums.Variable_Type_Codes) sb.ObjectType).ToString() + " (" + sb.ObjectType + ((LSO_Enums.Variable_Type_Codes) sb.ObjectType).ToString() + " (" + sb.ObjectType +
")"); ")");
switch ((LSO_Enums.Variable_Type_Codes) sb.ObjectType) switch ((LSO_Enums.Variable_Type_Codes) sb.ObjectType)
{ {
case LSO_Enums.Variable_Type_Codes.Float: case LSO_Enums.Variable_Type_Codes.Float:
case LSO_Enums.Variable_Type_Codes.Integer: case LSO_Enums.Variable_Type_Codes.Integer:
//UInt32 //UInt32
il.Emit(OpCodes.Ldc_I4, BitConverter.ToUInt32(sb.BlockVariable, 0)); il.Emit(OpCodes.Ldc_I4, BitConverter.ToUInt32(sb.BlockVariable, 0));
datatype = typeof (UInt32); datatype = typeof (UInt32);
il.Emit(OpCodes.Box, datatype); il.Emit(OpCodes.Box, datatype);
break; break;
case LSO_Enums.Variable_Type_Codes.String: case LSO_Enums.Variable_Type_Codes.String:
case LSO_Enums.Variable_Type_Codes.Key: case LSO_Enums.Variable_Type_Codes.Key:
//String //String
LSO_Struct.HeapBlock hb = LSO_Struct.HeapBlock hb =
LSOP.GetHeap(LSOP.myHeader.HR + BitConverter.ToUInt32(sb.BlockVariable, 0) - 1); LSOP.GetHeap(LSOP.myHeader.HR + BitConverter.ToUInt32(sb.BlockVariable, 0) - 1);
il.Emit(OpCodes.Ldstr, Encoding.UTF8.GetString(hb.Data)); il.Emit(OpCodes.Ldstr, Encoding.UTF8.GetString(hb.Data));
datatype = typeof (string); datatype = typeof (string);
break; break;
case LSO_Enums.Variable_Type_Codes.Vector: case LSO_Enums.Variable_Type_Codes.Vector:
datatype = typeof (LSO_Enums.Vector); datatype = typeof (LSO_Enums.Vector);
//TODO: Not implemented //TODO: Not implemented
break; break;
case LSO_Enums.Variable_Type_Codes.Rotation: case LSO_Enums.Variable_Type_Codes.Rotation:
//Object //Object
//TODO: Not implemented //TODO: Not implemented
datatype = typeof (LSO_Enums.Rotation); datatype = typeof (LSO_Enums.Rotation);
break; break;
default: default:
datatype = typeof (object); datatype = typeof (object);
break; break;
} }
// Make call // Make call
il.Emit(OpCodes.Call, il.Emit(OpCodes.Call,
typeof (LSL_BaseClass).GetMethod("AddToStatic", new Type[] {typeof (UInt32), datatype})); typeof (LSL_BaseClass).GetMethod("AddToStatic", new Type[] {typeof (UInt32), datatype}));
} }
} }
////il.Emit(OpCodes.Newobj, typeof(UInt32)); ////il.Emit(OpCodes.Newobj, typeof(UInt32));
//il.Emit(OpCodes.Starg_0); //il.Emit(OpCodes.Starg_0);
//// Create LSL function library //// Create LSL function library
//FieldBuilder LSL_BuiltIns_fb = typeBuilder.DefineField("LSL_BuiltIns", typeof(LSL_BuiltIn_Commands_Interface), FieldAttributes.Public); //FieldBuilder LSL_BuiltIns_fb = typeBuilder.DefineField("LSL_BuiltIns", typeof(LSL_BuiltIn_Commands_Interface), FieldAttributes.Public);
//il.Emit(OpCodes.Newobj, typeof(LSL_BuiltIn_Commands_Interface)); //il.Emit(OpCodes.Newobj, typeof(LSL_BuiltIn_Commands_Interface));
//il.Emit(OpCodes.Stloc_1); //il.Emit(OpCodes.Stloc_1);
il.Emit(OpCodes.Ret); il.Emit(OpCodes.Ret);
} }
// End of class // End of class
} }
} }

View File

@ -1,51 +1,51 @@
/* /*
* Copyright (c) Contributors, http://opensimulator.org/ * Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders. * See CONTRIBUTORS.TXT for a full list of copyright holders.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright * * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer. * notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright * * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the * notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution. * documentation and/or other materials provided with the distribution.
* * Neither the name of the OpenSim Project nor the * * Neither the name of the OpenSim Project nor the
* names of its contributors may be used to endorse or promote products * names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission. * derived from this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * 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 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
*/ */
/* Original code: Tedd Hansen */ /* Original code: Tedd Hansen */
using System; using System;
using System.Reflection; using System.Reflection;
using System.Reflection.Emit; using System.Reflection.Emit;
namespace OpenSim.Region.ScriptEngine.LSOEngine.LSO namespace OpenSim.Region.ScriptEngine.LSOEngine.LSO
{ {
internal partial class LSO_Parser internal partial class LSO_Parser
{ {
private static TypeBuilder CreateType(ModuleBuilder modBuilder, string typeName) private static TypeBuilder CreateType(ModuleBuilder modBuilder, string typeName)
{ {
TypeBuilder typeBuilder = modBuilder.DefineType(typeName, TypeBuilder typeBuilder = modBuilder.DefineType(typeName,
TypeAttributes.Public | TypeAttributes.Public |
TypeAttributes.Class | TypeAttributes.Class |
TypeAttributes.AutoClass | TypeAttributes.AutoClass |
TypeAttributes.AnsiClass | TypeAttributes.AnsiClass |
TypeAttributes.BeforeFieldInit | TypeAttributes.BeforeFieldInit |
TypeAttributes.AutoLayout, TypeAttributes.AutoLayout,
typeof (object), typeof (object),
new Type[] {typeof (object)}); new Type[] {typeof (object)});
return typeBuilder; return typeBuilder;
} }
} }
} }

View File

@ -1,395 +1,395 @@
/* /*
* Copyright (c) Contributors, http://opensimulator.org/ * Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders. * See CONTRIBUTORS.TXT for a full list of copyright holders.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright * * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer. * notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright * * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the * notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution. * documentation and/or other materials provided with the distribution.
* * Neither the name of the OpenSim Project nor the * * Neither the name of the OpenSim Project nor the
* names of its contributors may be used to endorse or promote products * names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission. * derived from this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS AS IS AND ANY * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * 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 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
*/ */
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
namespace OpenSim.Region.ScriptEngine.LSOEngine.LSO namespace OpenSim.Region.ScriptEngine.LSOEngine.LSO
{ {
//public partial class LSL_BaseClass //public partial class LSL_BaseClass
//{ //{
// /* // /*
// * OPCODES // * OPCODES
// * // *
// * These are internal "assembly" commands, // * These are internal "assembly" commands,
// * basic operators like "ADD", "PUSH" and "POP" // * basic operators like "ADD", "PUSH" and "POP"
// * // *
// * It also contains managed stack and keeps track of internal variables, etc. // * It also contains managed stack and keeps track of internal variables, etc.
// * // *
// */ // */
// public void StoreToLocal(UInt32 index) // public void StoreToLocal(UInt32 index)
// { // {
// // TODO: How to determine local? // // TODO: How to determine local?
// LSOEngine.LSO.Common.SendToDebug("::StoreToLocal " + index); // LSOEngine.LSO.Common.SendToDebug("::StoreToLocal " + index);
// if (LocalVariables.ContainsKey(index)) // if (LocalVariables.ContainsKey(index))
// LocalVariables.Remove(index); // LocalVariables.Remove(index);
// LocalVariables.Add(index, LSLStack.Peek()); // LocalVariables.Add(index, LSLStack.Peek());
// } // }
// public void StoreToGlobal(UInt32 index) // public void StoreToGlobal(UInt32 index)
// { // {
// LSOEngine.LSO.Common.SendToDebug("::StoreToGlobal " + index); // LSOEngine.LSO.Common.SendToDebug("::StoreToGlobal " + index);
// if (GlobalVariables.ContainsKey(index)) // if (GlobalVariables.ContainsKey(index))
// GlobalVariables.Remove(index); // GlobalVariables.Remove(index);
// GlobalVariables.Add(index, LSLStack.Peek()); // GlobalVariables.Add(index, LSLStack.Peek());
// } // }
// public void StoreToStatic(UInt32 index) // public void StoreToStatic(UInt32 index)
// { // {
// LSOEngine.LSO.Common.SendToDebug("::StoreToStatic " + index); // LSOEngine.LSO.Common.SendToDebug("::StoreToStatic " + index);
// //if (StaticVariables.ContainsKey(index)) // //if (StaticVariables.ContainsKey(index))
// // StaticVariables.Remove(index); // // StaticVariables.Remove(index);
// StaticVariables.Add(index, LSLStack.Peek()); // StaticVariables.Add(index, LSLStack.Peek());
// } // }
// public void GetFromLocal(UInt32 index) // public void GetFromLocal(UInt32 index)
// { // {
// // TODO: How to determine local? // // TODO: How to determine local?
// LSOEngine.LSO.Common.SendToDebug("::GetFromLocal " + index); // LSOEngine.LSO.Common.SendToDebug("::GetFromLocal " + index);
// object ret; // object ret;
// LocalVariables.TryGetValue(index, out ret); // LocalVariables.TryGetValue(index, out ret);
// LSLStack.Push(ret); // LSLStack.Push(ret);
// //return ret; // //return ret;
// } // }
// public void GetFromGlobal(UInt32 index) // public void GetFromGlobal(UInt32 index)
// { // {
// LSOEngine.LSO.Common.SendToDebug("::GetFromGlobal " + index); // LSOEngine.LSO.Common.SendToDebug("::GetFromGlobal " + index);
// object ret; // object ret;
// GlobalVariables.TryGetValue(index, out ret); // GlobalVariables.TryGetValue(index, out ret);
// LSLStack.Push(ret); // LSLStack.Push(ret);
// //return ret; // //return ret;
// } // }
// public void GetFromStatic(UInt32 index) // public void GetFromStatic(UInt32 index)
// { // {
// LSOEngine.LSO.Common.SendToDebug("::GetFromStatic " + index); // LSOEngine.LSO.Common.SendToDebug("::GetFromStatic " + index);
// object ret; // object ret;
// StaticVariables.TryGetValue(index, out ret); // StaticVariables.TryGetValue(index, out ret);
// LSOEngine.LSO.Common.SendToDebug("::GetFromStatic - ObjectType: " + ret.GetType().ToString()); // LSOEngine.LSO.Common.SendToDebug("::GetFromStatic - ObjectType: " + ret.GetType().ToString());
// LSLStack.Push(ret); // LSLStack.Push(ret);
// //return ret; // //return ret;
// } // }
// public object POPToStack() // public object POPToStack()
// { // {
// LSOEngine.LSO.Common.SendToDebug("::POPToStack"); // LSOEngine.LSO.Common.SendToDebug("::POPToStack");
// //return LSLStack.Pop(); // //return LSLStack.Pop();
// object p = LSLStack.Pop(); // object p = LSLStack.Pop();
// if (p.GetType() == typeof (UInt32)) // if (p.GetType() == typeof (UInt32))
// return (UInt32) p; // return (UInt32) p;
// if (p.GetType() == typeof (string)) // if (p.GetType() == typeof (string))
// return (string) p; // return (string) p;
// if (p.GetType() == typeof (Int32)) // if (p.GetType() == typeof (Int32))
// return (Int32) p; // return (Int32) p;
// if (p.GetType() == typeof (UInt16)) // if (p.GetType() == typeof (UInt16))
// return (UInt16) p; // return (UInt16) p;
// if (p.GetType() == typeof (float)) // if (p.GetType() == typeof (float))
// return (float) p; // return (float) p;
// if (p.GetType() == typeof (LSO_Enums.Vector)) // if (p.GetType() == typeof (LSO_Enums.Vector))
// return (LSO_Enums.Vector) p; // return (LSO_Enums.Vector) p;
// if (p.GetType() == typeof (LSO_Enums.Rotation)) // if (p.GetType() == typeof (LSO_Enums.Rotation))
// return (LSO_Enums.Rotation) p; // return (LSO_Enums.Rotation) p;
// if (p.GetType() == typeof (LSO_Enums.Key)) // if (p.GetType() == typeof (LSO_Enums.Key))
// return (LSO_Enums.Key) p; // return (LSO_Enums.Key) p;
// return p; // return p;
// } // }
// //public object POPToStack(UInt32 count) // //public object POPToStack(UInt32 count)
// //{ // //{
// // // POP NUMBER FROM TOP OF STACK // // // POP NUMBER FROM TOP OF STACK
// // //LSLStack.SetLength(LSLStack.Length - 4); // // //LSLStack.SetLength(LSLStack.Length - 4);
// // Common.SendToDebug("::POPToStack " + count); // // Common.SendToDebug("::POPToStack " + count);
// // if (count < 2) // // if (count < 2)
// // return LSLStack.Pop(); // // return LSLStack.Pop();
// // Stack<object> s = new Stack<object>(); // // Stack<object> s = new Stack<object>();
// // for (int i = 0; i < count; i++) // // for (int i = 0; i < count; i++)
// // { // // {
// // s.Push(LSLStack.Pop); // // s.Push(LSLStack.Pop);
// // } // // }
// //} // //}
// public void POP() // public void POP()
// { // {
// // POP NUMBER FROM TOP OF STACK // // POP NUMBER FROM TOP OF STACK
// //LSLStack.SetLength(LSLStack.Length - 4); // //LSLStack.SetLength(LSLStack.Length - 4);
// LSOEngine.LSO.Common.SendToDebug("::POP"); // LSOEngine.LSO.Common.SendToDebug("::POP");
// if (LSLStack.Count < 1) // if (LSLStack.Count < 1)
// { // {
// //TODO: Temporary fix // //TODO: Temporary fix
// LSOEngine.LSO.Common.SendToDebug("ERROR: TRYING TO POP EMPTY STACK!"); // LSOEngine.LSO.Common.SendToDebug("ERROR: TRYING TO POP EMPTY STACK!");
// } // }
// else // else
// { // {
// LSLStack.Pop(); // LSLStack.Pop();
// } // }
// } // }
// public void PUSH(object Param) // public void PUSH(object Param)
// { // {
// if (Param == null) // if (Param == null)
// { // {
// LSOEngine.LSO.Common.SendToDebug("::PUSH: <null>"); // LSOEngine.LSO.Common.SendToDebug("::PUSH: <null>");
// } // }
// else // else
// { // {
// //Common.SendToDebug("::PUSH: " + Param.GetType()); // //Common.SendToDebug("::PUSH: " + Param.GetType());
// } // }
// LSLStack.Push(Param); // LSLStack.Push(Param);
// } // }
// public void ADD(UInt32 Param) // public void ADD(UInt32 Param)
// { // {
// LSOEngine.LSO.Common.SendToDebug("::ADD: " + Param); // LSOEngine.LSO.Common.SendToDebug("::ADD: " + Param);
// object o2 = LSLStack.Pop(); // object o2 = LSLStack.Pop();
// object o1 = LSLStack.Pop(); // object o1 = LSLStack.Pop();
// LSOEngine.LSO.Common.SendToDebug("::ADD: Debug: o1: " + o1.GetType() + " (" + o1.ToString() + "), o2: " + o2.GetType() + // LSOEngine.LSO.Common.SendToDebug("::ADD: Debug: o1: " + o1.GetType() + " (" + o1.ToString() + "), o2: " + o2.GetType() +
// " (" + o2.ToString() + ")"); // " (" + o2.ToString() + ")");
// if (o2.GetType() == typeof (string)) // if (o2.GetType() == typeof (string))
// { // {
// LSLStack.Push((string) o1 + (string) o2); // LSLStack.Push((string) o1 + (string) o2);
// return; // return;
// } // }
// if (o2.GetType() == typeof (UInt32)) // if (o2.GetType() == typeof (UInt32))
// { // {
// LSLStack.Push((UInt32) o1 + (UInt32) o2); // LSLStack.Push((UInt32) o1 + (UInt32) o2);
// return; // return;
// } // }
// } // }
// public void SUB(UInt32 Param) // public void SUB(UInt32 Param)
// { // {
// LSOEngine.LSO.Common.SendToDebug("::SUB: " + Param); // LSOEngine.LSO.Common.SendToDebug("::SUB: " + Param);
// UInt32 i2 = (UInt32) LSLStack.Pop(); // UInt32 i2 = (UInt32) LSLStack.Pop();
// UInt32 i1 = (UInt32) LSLStack.Pop(); // UInt32 i1 = (UInt32) LSLStack.Pop();
// LSLStack.Push((UInt32) (i1 - i2)); // LSLStack.Push((UInt32) (i1 - i2));
// } // }
// public void MUL(UInt32 Param) // public void MUL(UInt32 Param)
// { // {
// LSOEngine.LSO.Common.SendToDebug("::SUB: " + Param); // LSOEngine.LSO.Common.SendToDebug("::SUB: " + Param);
// UInt32 i2 = (UInt32) LSLStack.Pop(); // UInt32 i2 = (UInt32) LSLStack.Pop();
// UInt32 i1 = (UInt32) LSLStack.Pop(); // UInt32 i1 = (UInt32) LSLStack.Pop();
// LSLStack.Push((UInt32) (i1*i2)); // LSLStack.Push((UInt32) (i1*i2));
// } // }
// public void DIV(UInt32 Param) // public void DIV(UInt32 Param)
// { // {
// LSOEngine.LSO.Common.SendToDebug("::DIV: " + Param); // LSOEngine.LSO.Common.SendToDebug("::DIV: " + Param);
// UInt32 i2 = (UInt32) LSLStack.Pop(); // UInt32 i2 = (UInt32) LSLStack.Pop();
// UInt32 i1 = (UInt32) LSLStack.Pop(); // UInt32 i1 = (UInt32) LSLStack.Pop();
// LSLStack.Push((UInt32) (i1/i2)); // LSLStack.Push((UInt32) (i1/i2));
// } // }
// public void MOD(UInt32 Param) // public void MOD(UInt32 Param)
// { // {
// LSOEngine.LSO.Common.SendToDebug("::MOD: " + Param); // LSOEngine.LSO.Common.SendToDebug("::MOD: " + Param);
// UInt32 i2 = (UInt32) LSLStack.Pop(); // UInt32 i2 = (UInt32) LSLStack.Pop();
// UInt32 i1 = (UInt32) LSLStack.Pop(); // UInt32 i1 = (UInt32) LSLStack.Pop();
// LSLStack.Push((UInt32) (i1%i2)); // LSLStack.Push((UInt32) (i1%i2));
// } // }
// public void EQ(UInt32 Param) // public void EQ(UInt32 Param)
// { // {
// LSOEngine.LSO.Common.SendToDebug("::EQ: " + Param); // LSOEngine.LSO.Common.SendToDebug("::EQ: " + Param);
// UInt32 i2 = (UInt32) LSLStack.Pop(); // UInt32 i2 = (UInt32) LSLStack.Pop();
// UInt32 i1 = (UInt32) LSLStack.Pop(); // UInt32 i1 = (UInt32) LSLStack.Pop();
// if (i1 == i2) // if (i1 == i2)
// { // {
// LSLStack.Push((UInt32) 1); // LSLStack.Push((UInt32) 1);
// } // }
// else // else
// { // {
// LSLStack.Push((UInt32) 0); // LSLStack.Push((UInt32) 0);
// } // }
// } // }
// public void NEQ(UInt32 Param) // public void NEQ(UInt32 Param)
// { // {
// LSOEngine.LSO.Common.SendToDebug("::NEQ: " + Param); // LSOEngine.LSO.Common.SendToDebug("::NEQ: " + Param);
// UInt32 i2 = (UInt32) LSLStack.Pop(); // UInt32 i2 = (UInt32) LSLStack.Pop();
// UInt32 i1 = (UInt32) LSLStack.Pop(); // UInt32 i1 = (UInt32) LSLStack.Pop();
// if (i1 != i2) // if (i1 != i2)
// { // {
// LSLStack.Push((UInt32) 1); // LSLStack.Push((UInt32) 1);
// } // }
// else // else
// { // {
// LSLStack.Push((UInt32) 0); // LSLStack.Push((UInt32) 0);
// } // }
// } // }
// public void LEQ(UInt32 Param) // public void LEQ(UInt32 Param)
// { // {
// LSOEngine.LSO.Common.SendToDebug("::LEQ: " + Param); // LSOEngine.LSO.Common.SendToDebug("::LEQ: " + Param);
// UInt32 i2 = (UInt32) LSLStack.Pop(); // UInt32 i2 = (UInt32) LSLStack.Pop();
// UInt32 i1 = (UInt32) LSLStack.Pop(); // UInt32 i1 = (UInt32) LSLStack.Pop();
// if (i1 <= i2) // if (i1 <= i2)
// { // {
// LSLStack.Push((UInt32) 1); // LSLStack.Push((UInt32) 1);
// } // }
// else // else
// { // {
// LSLStack.Push((UInt32) 0); // LSLStack.Push((UInt32) 0);
// } // }
// } // }
// public void GEQ(UInt32 Param) // public void GEQ(UInt32 Param)
// { // {
// LSOEngine.LSO.Common.SendToDebug("::GEQ: " + Param); // LSOEngine.LSO.Common.SendToDebug("::GEQ: " + Param);
// UInt32 i2 = (UInt32) LSLStack.Pop(); // UInt32 i2 = (UInt32) LSLStack.Pop();
// UInt32 i1 = (UInt32) LSLStack.Pop(); // UInt32 i1 = (UInt32) LSLStack.Pop();
// if (i1 >= i2) // if (i1 >= i2)
// { // {
// LSLStack.Push((UInt32) 1); // LSLStack.Push((UInt32) 1);
// } // }
// else // else
// { // {
// LSLStack.Push((UInt32) 0); // LSLStack.Push((UInt32) 0);
// } // }
// } // }
// public void LESS(UInt32 Param) // public void LESS(UInt32 Param)
// { // {
// LSOEngine.LSO.Common.SendToDebug("::LESS: " + Param); // LSOEngine.LSO.Common.SendToDebug("::LESS: " + Param);
// UInt32 i2 = (UInt32) LSLStack.Pop(); // UInt32 i2 = (UInt32) LSLStack.Pop();
// UInt32 i1 = (UInt32) LSLStack.Pop(); // UInt32 i1 = (UInt32) LSLStack.Pop();
// if (i1 < i2) // if (i1 < i2)
// { // {
// LSLStack.Push((UInt32) 1); // LSLStack.Push((UInt32) 1);
// } // }
// else // else
// { // {
// LSLStack.Push((UInt32) 0); // LSLStack.Push((UInt32) 0);
// } // }
// } // }
// public void GREATER(UInt32 Param) // public void GREATER(UInt32 Param)
// { // {
// LSOEngine.LSO.Common.SendToDebug("::GREATER: " + Param); // LSOEngine.LSO.Common.SendToDebug("::GREATER: " + Param);
// UInt32 i2 = (UInt32) LSLStack.Pop(); // UInt32 i2 = (UInt32) LSLStack.Pop();
// UInt32 i1 = (UInt32) LSLStack.Pop(); // UInt32 i1 = (UInt32) LSLStack.Pop();
// if (i1 > i2) // if (i1 > i2)
// { // {
// LSLStack.Push((UInt32) 1); // LSLStack.Push((UInt32) 1);
// } // }
// else // else
// { // {
// LSLStack.Push((UInt32) 0); // LSLStack.Push((UInt32) 0);
// } // }
// } // }
// public void BITAND() // public void BITAND()
// { // {
// LSOEngine.LSO.Common.SendToDebug("::BITAND"); // LSOEngine.LSO.Common.SendToDebug("::BITAND");
// UInt32 i2 = (UInt32) LSLStack.Pop(); // UInt32 i2 = (UInt32) LSLStack.Pop();
// UInt32 i1 = (UInt32) LSLStack.Pop(); // UInt32 i1 = (UInt32) LSLStack.Pop();
// LSLStack.Push((UInt32) (i1 & i2)); // LSLStack.Push((UInt32) (i1 & i2));
// } // }
// public void BITOR() // public void BITOR()
// { // {
// LSOEngine.LSO.Common.SendToDebug("::BITOR"); // LSOEngine.LSO.Common.SendToDebug("::BITOR");
// UInt32 i2 = (UInt32) LSLStack.Pop(); // UInt32 i2 = (UInt32) LSLStack.Pop();
// UInt32 i1 = (UInt32) LSLStack.Pop(); // UInt32 i1 = (UInt32) LSLStack.Pop();
// LSLStack.Push((UInt32) (i1 | i2)); // LSLStack.Push((UInt32) (i1 | i2));
// } // }
// public void BITXOR() // public void BITXOR()
// { // {
// LSOEngine.LSO.Common.SendToDebug("::BITXOR"); // LSOEngine.LSO.Common.SendToDebug("::BITXOR");
// UInt32 i2 = (UInt32) LSLStack.Pop(); // UInt32 i2 = (UInt32) LSLStack.Pop();
// UInt32 i1 = (UInt32) LSLStack.Pop(); // UInt32 i1 = (UInt32) LSLStack.Pop();
// LSLStack.Push((UInt32) (i1 ^ i2)); // LSLStack.Push((UInt32) (i1 ^ i2));
// } // }
// public void BOOLAND() // public void BOOLAND()
// { // {
// LSOEngine.LSO.Common.SendToDebug("::BOOLAND"); // LSOEngine.LSO.Common.SendToDebug("::BOOLAND");
// bool b2 = bool.Parse((string) LSLStack.Pop()); // bool b2 = bool.Parse((string) LSLStack.Pop());
// bool b1 = bool.Parse((string) LSLStack.Pop()); // bool b1 = bool.Parse((string) LSLStack.Pop());
// if (b1 && b2) // if (b1 && b2)
// { // {
// LSLStack.Push((UInt32) 1); // LSLStack.Push((UInt32) 1);
// } // }
// else // else
// { // {
// LSLStack.Push((UInt32) 0); // LSLStack.Push((UInt32) 0);
// } // }
// } // }
// public void BOOLOR() // public void BOOLOR()
// { // {
// LSOEngine.LSO.Common.SendToDebug("::BOOLOR"); // LSOEngine.LSO.Common.SendToDebug("::BOOLOR");
// bool b2 = bool.Parse((string) LSLStack.Pop()); // bool b2 = bool.Parse((string) LSLStack.Pop());
// bool b1 = bool.Parse((string) LSLStack.Pop()); // bool b1 = bool.Parse((string) LSLStack.Pop());
// if (b1 || b2) // if (b1 || b2)
// { // {
// LSLStack.Push((UInt32) 1); // LSLStack.Push((UInt32) 1);
// } // }
// else // else
// { // {
// LSLStack.Push((UInt32) 0); // LSLStack.Push((UInt32) 0);
// } // }
// } // }
// public void NEG(UInt32 Param) // public void NEG(UInt32 Param)
// { // {
// LSOEngine.LSO.Common.SendToDebug("::NEG: " + Param); // LSOEngine.LSO.Common.SendToDebug("::NEG: " + Param);
// //UInt32 i2 = (UInt32)LSLStack.Pop(); // //UInt32 i2 = (UInt32)LSLStack.Pop();
// UInt32 i1 = (UInt32) LSLStack.Pop(); // UInt32 i1 = (UInt32) LSLStack.Pop();
// LSLStack.Push((UInt32) (i1*-1)); // LSLStack.Push((UInt32) (i1*-1));
// } // }
// public void BITNOT() // public void BITNOT()
// { // {
// //Common.SendToDebug("::BITNOT"); // //Common.SendToDebug("::BITNOT");
// //UInt32 i2 = (UInt32)LSLStack.Pop(); // //UInt32 i2 = (UInt32)LSLStack.Pop();
// //UInt32 i1 = (UInt32)LSLStack.Pop(); // //UInt32 i1 = (UInt32)LSLStack.Pop();
// //LSLStack.Push((UInt32)(i1 / i2)); // //LSLStack.Push((UInt32)(i1 / i2));
// } // }
// public void BOOLNOT() // public void BOOLNOT()
// { // {
// //Common.SendToDebug("::BOOLNOT"); // //Common.SendToDebug("::BOOLNOT");
// ////UInt32 i2 = (UInt32)LSLStack.Pop(); // ////UInt32 i2 = (UInt32)LSLStack.Pop();
// //UInt32 i1 = (UInt32)LSLStack.Pop(); // //UInt32 i1 = (UInt32)LSLStack.Pop();
// //LSLStack.Push((UInt32)(i1)); // //LSLStack.Push((UInt32)(i1));
// } // }
//} //}
} }

View File

@ -1,75 +1,75 @@
/* /*
* Copyright (c) Contributors, http://opensimulator.org/ * Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders. * See CONTRIBUTORS.TXT for a full list of copyright holders.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright * * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer. * notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright * * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the * notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution. * documentation and/or other materials provided with the distribution.
* * Neither the name of the OpenSim Project nor the * * Neither the name of the OpenSim Project nor the
* names of its contributors may be used to endorse or promote products * names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission. * derived from this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * 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 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
*/ */
/* Original code: Tedd Hansen */ /* Original code: Tedd Hansen */
namespace OpenSim.Region.ScriptEngine.LSOEngine.LSO namespace OpenSim.Region.ScriptEngine.LSOEngine.LSO
{ {
public class LSL_CLRInterface public class LSL_CLRInterface
{ {
public interface LSLScript public interface LSLScript
{ {
//public virtual void Run(object arg) //public virtual void Run(object arg)
//{ //{
//} //}
//void Run(object arg); //void Run(object arg);
//void event_state_entry(object arg); //void event_state_entry(object arg);
//void event_state_exit(); //void event_state_exit();
//void event_touch_start(object arg); //void event_touch_start(object arg);
//void event_touch(); //void event_touch();
//void event_touch_end(); //void event_touch_end();
//void event_collision_start(); //void event_collision_start();
//void event_collision(); //void event_collision();
//void event_collision_end(); //void event_collision_end();
//void event_land_collision_start(); //void event_land_collision_start();
//void event_land_collision(); //void event_land_collision();
//void event_land_collision_end(); //void event_land_collision_end();
//void event_timer(); //void event_timer();
//void event_listen(); //void event_listen();
//void event_on_rez(); //void event_on_rez();
//void event_sensor(); //void event_sensor();
//void event_no_sensor(); //void event_no_sensor();
//void event_control(); //void event_control();
//void event_money(); //void event_money();
//void event_email(); //void event_email();
//void event_at_target(); //void event_at_target();
//void event_not_at_target(); //void event_not_at_target();
//void event_at_rot_target(); //void event_at_rot_target();
//void event_not_at_rot_target(); //void event_not_at_rot_target();
//void event_run_time_permissions(); //void event_run_time_permissions();
//void event_changed(); //void event_changed();
//void event_attach(); //void event_attach();
//void event_dataserver(); //void event_dataserver();
//void event_link_message(); //void event_link_message();
//void event_moving_start(); //void event_moving_start();
//void event_moving_end(); //void event_moving_end();
//void event_object_rez(); //void event_object_rez();
//void event_remote_data(); //void event_remote_data();
//void event_http_response(); //void event_http_response();
} }
} }
} }

View File

@ -1,435 +1,435 @@
/* /*
* Copyright (c) Contributors, http://opensimulator.org/ * Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders. * See CONTRIBUTORS.TXT for a full list of copyright holders.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright * * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer. * notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright * * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the * notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution. * documentation and/or other materials provided with the distribution.
* * Neither the name of the OpenSim Project nor the * * Neither the name of the OpenSim Project nor the
* names of its contributors may be used to endorse or promote products * names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission. * derived from this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * 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 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
*/ */
/* Original code: Tedd Hansen */ /* Original code: Tedd Hansen */
using System; using System;
using System.Reflection; using System.Reflection;
using System.Reflection.Emit; using System.Reflection.Emit;
using OpenSim.Region.ScriptEngine.Common; using OpenSim.Region.ScriptEngine.Common;
namespace OpenSim.Region.ScriptEngine.LSOEngine.LSO namespace OpenSim.Region.ScriptEngine.LSOEngine.LSO
{ {
internal partial class LSO_Parser internal partial class LSO_Parser
{ {
//internal Stack<Type> ILStack = new Stack<Type>(); //internal Stack<Type> ILStack = new Stack<Type>();
//LSO_Enums MyLSO_Enums = new LSO_Enums(); //LSO_Enums MyLSO_Enums = new LSO_Enums();
internal bool LSL_PROCESS_OPCODE(ILGenerator il) internal bool LSL_PROCESS_OPCODE(ILGenerator il)
{ {
byte bp1; byte bp1;
UInt32 u32p1; UInt32 u32p1;
float fp1; float fp1;
UInt16 opcode = br_read(1)[0]; UInt16 opcode = br_read(1)[0];
Common.SendToDebug("OPCODE: " + ((LSO_Enums.Operation_Table) opcode).ToString()); Common.SendToDebug("OPCODE: " + ((LSO_Enums.Operation_Table) opcode).ToString());
string idesc = ((LSO_Enums.Operation_Table) opcode).ToString(); string idesc = ((LSO_Enums.Operation_Table) opcode).ToString();
switch ((LSO_Enums.Operation_Table) opcode) switch ((LSO_Enums.Operation_Table) opcode)
{ {
/*************** /***************
* IMPLEMENTED * * IMPLEMENTED *
***************/ ***************/
case LSO_Enums.Operation_Table.NOOP: case LSO_Enums.Operation_Table.NOOP:
break; break;
case LSO_Enums.Operation_Table.PUSHSP: case LSO_Enums.Operation_Table.PUSHSP:
// Push Stack Top (Memory Address) to stack // Push Stack Top (Memory Address) to stack
Common.SendToDebug("Instruction " + idesc); Common.SendToDebug("Instruction " + idesc);
Common.SendToDebug("Instruction " + idesc + Common.SendToDebug("Instruction " + idesc +
": Description: Pushing Stack Top (Memory Address from header) to stack"); ": Description: Pushing Stack Top (Memory Address from header) to stack");
IL_Push(il, (UInt32) myHeader.SP); IL_Push(il, (UInt32) myHeader.SP);
break; break;
// BYTE // BYTE
case LSO_Enums.Operation_Table.PUSHARGB: case LSO_Enums.Operation_Table.PUSHARGB:
Common.SendToDebug("Param1: " + br_read(1)[0]); Common.SendToDebug("Param1: " + br_read(1)[0]);
break; break;
// INTEGER // INTEGER
case LSO_Enums.Operation_Table.PUSHARGI: case LSO_Enums.Operation_Table.PUSHARGI:
u32p1 = BitConverter.ToUInt32(br_read(4), 0); u32p1 = BitConverter.ToUInt32(br_read(4), 0);
Common.SendToDebug("Instruction " + idesc + ", Param1: " + u32p1); Common.SendToDebug("Instruction " + idesc + ", Param1: " + u32p1);
IL_Push(il, u32p1); IL_Push(il, u32p1);
break; break;
// FLOAT // FLOAT
case LSO_Enums.Operation_Table.PUSHARGF: case LSO_Enums.Operation_Table.PUSHARGF:
fp1 = BitConverter.ToUInt32(br_read(4), 0); fp1 = BitConverter.ToUInt32(br_read(4), 0);
Common.SendToDebug("Instruction " + idesc + ", Param1: " + fp1); Common.SendToDebug("Instruction " + idesc + ", Param1: " + fp1);
IL_Push(il, fp1); IL_Push(il, fp1);
break; break;
// STRING // STRING
case LSO_Enums.Operation_Table.PUSHARGS: case LSO_Enums.Operation_Table.PUSHARGS:
string s = Read_String(); string s = Read_String();
Common.SendToDebug("Instruction " + idesc + ", Param1: " + s); Common.SendToDebug("Instruction " + idesc + ", Param1: " + s);
IL_Debug(il, "OPCODE: " + idesc + ":" + s); IL_Debug(il, "OPCODE: " + idesc + ":" + s);
IL_Push(il, s); IL_Push(il, s);
break; break;
// VECTOR z,y,x // VECTOR z,y,x
case LSO_Enums.Operation_Table.PUSHARGV: case LSO_Enums.Operation_Table.PUSHARGV:
LSO_Enums.Vector v = new LSO_Enums.Vector(); LSO_Enums.Vector v = new LSO_Enums.Vector();
v.Z = BitConverter.ToUInt32(br_read(4), 0); v.Z = BitConverter.ToUInt32(br_read(4), 0);
v.Y = BitConverter.ToUInt32(br_read(4), 0); v.Y = BitConverter.ToUInt32(br_read(4), 0);
v.X = BitConverter.ToUInt32(br_read(4), 0); v.X = BitConverter.ToUInt32(br_read(4), 0);
Common.SendToDebug("Param1 Z: " + v.Z); Common.SendToDebug("Param1 Z: " + v.Z);
Common.SendToDebug("Param1 Y: " + v.Y); Common.SendToDebug("Param1 Y: " + v.Y);
Common.SendToDebug("Param1 X: " + v.X); Common.SendToDebug("Param1 X: " + v.X);
IL_Push(il, v); IL_Push(il, v);
break; break;
// ROTATION s,z,y,x // ROTATION s,z,y,x
case LSO_Enums.Operation_Table.PUSHARGQ: case LSO_Enums.Operation_Table.PUSHARGQ:
LSO_Enums.Rotation r = new LSO_Enums.Rotation(); LSO_Enums.Rotation r = new LSO_Enums.Rotation();
r.S = BitConverter.ToUInt32(br_read(4), 0); r.S = BitConverter.ToUInt32(br_read(4), 0);
r.Z = BitConverter.ToUInt32(br_read(4), 0); r.Z = BitConverter.ToUInt32(br_read(4), 0);
r.Y = BitConverter.ToUInt32(br_read(4), 0); r.Y = BitConverter.ToUInt32(br_read(4), 0);
r.X = BitConverter.ToUInt32(br_read(4), 0); r.X = BitConverter.ToUInt32(br_read(4), 0);
Common.SendToDebug("Param1 S: " + r.S); Common.SendToDebug("Param1 S: " + r.S);
Common.SendToDebug("Param1 Z: " + r.Z); Common.SendToDebug("Param1 Z: " + r.Z);
Common.SendToDebug("Param1 Y: " + r.Y); Common.SendToDebug("Param1 Y: " + r.Y);
Common.SendToDebug("Param1 X: " + r.X); Common.SendToDebug("Param1 X: " + r.X);
IL_Push(il, r); IL_Push(il, r);
break; break;
case LSO_Enums.Operation_Table.PUSHE: case LSO_Enums.Operation_Table.PUSHE:
IL_Push(il, (UInt32) 0); IL_Push(il, (UInt32) 0);
break; break;
case LSO_Enums.Operation_Table.PUSHARGE: case LSO_Enums.Operation_Table.PUSHARGE:
u32p1 = BitConverter.ToUInt32(br_read(4), 0); u32p1 = BitConverter.ToUInt32(br_read(4), 0);
Common.SendToDebug("Param1: " + u32p1); Common.SendToDebug("Param1: " + u32p1);
//IL_Push(il, new string(" ".ToCharArray()[0], Convert.ToInt32(u32p1))); //IL_Push(il, new string(" ".ToCharArray()[0], Convert.ToInt32(u32p1)));
IL_Push(il, u32p1); IL_Push(il, u32p1);
break; break;
// BYTE // BYTE
case LSO_Enums.Operation_Table.ADD: case LSO_Enums.Operation_Table.ADD:
case LSO_Enums.Operation_Table.SUB: case LSO_Enums.Operation_Table.SUB:
case LSO_Enums.Operation_Table.MUL: case LSO_Enums.Operation_Table.MUL:
case LSO_Enums.Operation_Table.DIV: case LSO_Enums.Operation_Table.DIV:
case LSO_Enums.Operation_Table.EQ: case LSO_Enums.Operation_Table.EQ:
case LSO_Enums.Operation_Table.NEQ: case LSO_Enums.Operation_Table.NEQ:
case LSO_Enums.Operation_Table.LEQ: case LSO_Enums.Operation_Table.LEQ:
case LSO_Enums.Operation_Table.GEQ: case LSO_Enums.Operation_Table.GEQ:
case LSO_Enums.Operation_Table.LESS: case LSO_Enums.Operation_Table.LESS:
case LSO_Enums.Operation_Table.GREATER: case LSO_Enums.Operation_Table.GREATER:
case LSO_Enums.Operation_Table.NEG: case LSO_Enums.Operation_Table.NEG:
case LSO_Enums.Operation_Table.MOD: case LSO_Enums.Operation_Table.MOD:
bp1 = br_read(1)[0]; bp1 = br_read(1)[0];
Common.SendToDebug("Param1: " + bp1); Common.SendToDebug("Param1: " + bp1);
IL_CallBaseFunction(il, idesc, (UInt32) bp1); IL_CallBaseFunction(il, idesc, (UInt32) bp1);
break; break;
// NO ARGUMENTS // NO ARGUMENTS
case LSO_Enums.Operation_Table.BITAND: case LSO_Enums.Operation_Table.BITAND:
case LSO_Enums.Operation_Table.BITOR: case LSO_Enums.Operation_Table.BITOR:
case LSO_Enums.Operation_Table.BITXOR: case LSO_Enums.Operation_Table.BITXOR:
case LSO_Enums.Operation_Table.BOOLAND: case LSO_Enums.Operation_Table.BOOLAND:
case LSO_Enums.Operation_Table.BOOLOR: case LSO_Enums.Operation_Table.BOOLOR:
case LSO_Enums.Operation_Table.BITNOT: case LSO_Enums.Operation_Table.BITNOT:
case LSO_Enums.Operation_Table.BOOLNOT: case LSO_Enums.Operation_Table.BOOLNOT:
IL_CallBaseFunction(il, idesc); IL_CallBaseFunction(il, idesc);
break; break;
// SHORT // SHORT
case LSO_Enums.Operation_Table.CALLLIB_TWO_BYTE: case LSO_Enums.Operation_Table.CALLLIB_TWO_BYTE:
// TODO: What is size of short? // TODO: What is size of short?
UInt16 U16p1 = BitConverter.ToUInt16(br_read(2), 0); UInt16 U16p1 = BitConverter.ToUInt16(br_read(2), 0);
Common.SendToDebug("Instruction " + idesc + ": Builtin Command: " + Common.SendToDebug("Instruction " + idesc + ": Builtin Command: " +
((LSO_Enums.BuiltIn_Functions) U16p1).ToString()); ((LSO_Enums.BuiltIn_Functions) U16p1).ToString());
//Common.SendToDebug("Param1: " + U16p1); //Common.SendToDebug("Param1: " + U16p1);
string fname = ((LSO_Enums.BuiltIn_Functions) U16p1).ToString(); string fname = ((LSO_Enums.BuiltIn_Functions) U16p1).ToString();
bool cmdFound = false; bool cmdFound = false;
foreach (MethodInfo mi in typeof (LSL_BuiltIn_Commands_Interface).GetMethods()) foreach (MethodInfo mi in typeof (LSL_BuiltIn_Commands_Interface).GetMethods())
{ {
// Found command // Found command
if (mi.Name == fname) if (mi.Name == fname)
{ {
il.Emit(OpCodes.Ldarg_0); il.Emit(OpCodes.Ldarg_0);
il.Emit(OpCodes.Call, typeof (LSL_BaseClass).GetMethod("GetLSL_BuiltIn", new Type[] {})); il.Emit(OpCodes.Call, typeof (LSL_BaseClass).GetMethod("GetLSL_BuiltIn", new Type[] {}));
// Pop required number of items from my stack to .Net stack // Pop required number of items from my stack to .Net stack
IL_PopToStack(il, mi.GetParameters().Length); IL_PopToStack(il, mi.GetParameters().Length);
il.Emit(OpCodes.Callvirt, mi); il.Emit(OpCodes.Callvirt, mi);
cmdFound = true; cmdFound = true;
break; break;
} }
} }
if (cmdFound == false) if (cmdFound == false)
{ {
Common.SendToDebug("ERROR: UNABLE TO LOCATE OPCODE " + idesc + " IN BASECLASS"); Common.SendToDebug("ERROR: UNABLE TO LOCATE OPCODE " + idesc + " IN BASECLASS");
} }
break; break;
// RETURN // RETURN
case LSO_Enums.Operation_Table.RETURN: case LSO_Enums.Operation_Table.RETURN:
Common.SendToDebug("OPCODE: RETURN"); Common.SendToDebug("OPCODE: RETURN");
return true; return true;
case LSO_Enums.Operation_Table.POP: case LSO_Enums.Operation_Table.POP:
case LSO_Enums.Operation_Table.POPS: case LSO_Enums.Operation_Table.POPS:
case LSO_Enums.Operation_Table.POPL: case LSO_Enums.Operation_Table.POPL:
case LSO_Enums.Operation_Table.POPV: case LSO_Enums.Operation_Table.POPV:
case LSO_Enums.Operation_Table.POPQ: case LSO_Enums.Operation_Table.POPQ:
// Pops a specific datatype from the stack // Pops a specific datatype from the stack
// We just ignore the datatype for now // We just ignore the datatype for now
IL_Pop(il); IL_Pop(il);
break; break;
// LONG // LONG
case LSO_Enums.Operation_Table.STORE: case LSO_Enums.Operation_Table.STORE:
case LSO_Enums.Operation_Table.STORES: case LSO_Enums.Operation_Table.STORES:
case LSO_Enums.Operation_Table.STOREL: case LSO_Enums.Operation_Table.STOREL:
case LSO_Enums.Operation_Table.STOREV: case LSO_Enums.Operation_Table.STOREV:
case LSO_Enums.Operation_Table.STOREQ: case LSO_Enums.Operation_Table.STOREQ:
u32p1 = BitConverter.ToUInt32(br_read(4), 0); u32p1 = BitConverter.ToUInt32(br_read(4), 0);
Common.SendToDebug("Param1: " + u32p1.ToString()); Common.SendToDebug("Param1: " + u32p1.ToString());
IL_CallBaseFunction(il, "StoreToLocal", u32p1); IL_CallBaseFunction(il, "StoreToLocal", u32p1);
break; break;
case LSO_Enums.Operation_Table.STOREG: case LSO_Enums.Operation_Table.STOREG:
case LSO_Enums.Operation_Table.STOREGS: case LSO_Enums.Operation_Table.STOREGS:
case LSO_Enums.Operation_Table.STOREGL: case LSO_Enums.Operation_Table.STOREGL:
case LSO_Enums.Operation_Table.STOREGV: case LSO_Enums.Operation_Table.STOREGV:
case LSO_Enums.Operation_Table.STOREGQ: case LSO_Enums.Operation_Table.STOREGQ:
u32p1 = BitConverter.ToUInt32(br_read(4), 0); u32p1 = BitConverter.ToUInt32(br_read(4), 0);
Common.SendToDebug("Param1: " + u32p1.ToString()); Common.SendToDebug("Param1: " + u32p1.ToString());
IL_CallBaseFunction(il, "StoreToGlobal", u32p1); IL_CallBaseFunction(il, "StoreToGlobal", u32p1);
break; break;
case LSO_Enums.Operation_Table.LOADP: case LSO_Enums.Operation_Table.LOADP:
case LSO_Enums.Operation_Table.LOADSP: case LSO_Enums.Operation_Table.LOADSP:
case LSO_Enums.Operation_Table.LOADLP: case LSO_Enums.Operation_Table.LOADLP:
case LSO_Enums.Operation_Table.LOADVP: case LSO_Enums.Operation_Table.LOADVP:
case LSO_Enums.Operation_Table.LOADQP: case LSO_Enums.Operation_Table.LOADQP:
u32p1 = BitConverter.ToUInt32(br_read(4), 0); u32p1 = BitConverter.ToUInt32(br_read(4), 0);
Common.SendToDebug("Param1: " + u32p1.ToString()); Common.SendToDebug("Param1: " + u32p1.ToString());
IL_CallBaseFunction(il, "StoreToLocal", u32p1); IL_CallBaseFunction(il, "StoreToLocal", u32p1);
IL_Pop(il); IL_Pop(il);
break; break;
case LSO_Enums.Operation_Table.LOADGP: case LSO_Enums.Operation_Table.LOADGP:
case LSO_Enums.Operation_Table.LOADGSP: case LSO_Enums.Operation_Table.LOADGSP:
case LSO_Enums.Operation_Table.LOADGLP: case LSO_Enums.Operation_Table.LOADGLP:
case LSO_Enums.Operation_Table.LOADGVP: case LSO_Enums.Operation_Table.LOADGVP:
case LSO_Enums.Operation_Table.LOADGQP: case LSO_Enums.Operation_Table.LOADGQP:
u32p1 = BitConverter.ToUInt32(br_read(4), 0); u32p1 = BitConverter.ToUInt32(br_read(4), 0);
Common.SendToDebug("Param1: " + u32p1.ToString()); Common.SendToDebug("Param1: " + u32p1.ToString());
IL_CallBaseFunction(il, "StoreToStatic", u32p1 - 6 + myHeader.GVR); IL_CallBaseFunction(il, "StoreToStatic", u32p1 - 6 + myHeader.GVR);
IL_Pop(il); IL_Pop(il);
break; break;
// PUSH FROM LOCAL FRAME // PUSH FROM LOCAL FRAME
case LSO_Enums.Operation_Table.PUSH: case LSO_Enums.Operation_Table.PUSH:
case LSO_Enums.Operation_Table.PUSHS: case LSO_Enums.Operation_Table.PUSHS:
case LSO_Enums.Operation_Table.PUSHL: case LSO_Enums.Operation_Table.PUSHL:
case LSO_Enums.Operation_Table.PUSHV: case LSO_Enums.Operation_Table.PUSHV:
case LSO_Enums.Operation_Table.PUSHQ: case LSO_Enums.Operation_Table.PUSHQ:
u32p1 = BitConverter.ToUInt32(br_read(4), 0); u32p1 = BitConverter.ToUInt32(br_read(4), 0);
Common.SendToDebug("Param1: " + u32p1.ToString()); Common.SendToDebug("Param1: " + u32p1.ToString());
IL_CallBaseFunction(il, "GetFromLocal", u32p1); IL_CallBaseFunction(il, "GetFromLocal", u32p1);
break; break;
// PUSH FROM STATIC FRAME // PUSH FROM STATIC FRAME
case LSO_Enums.Operation_Table.PUSHG: case LSO_Enums.Operation_Table.PUSHG:
case LSO_Enums.Operation_Table.PUSHGS: case LSO_Enums.Operation_Table.PUSHGS:
case LSO_Enums.Operation_Table.PUSHGL: case LSO_Enums.Operation_Table.PUSHGL:
case LSO_Enums.Operation_Table.PUSHGV: case LSO_Enums.Operation_Table.PUSHGV:
case LSO_Enums.Operation_Table.PUSHGQ: case LSO_Enums.Operation_Table.PUSHGQ:
u32p1 = BitConverter.ToUInt32(br_read(4), 0); u32p1 = BitConverter.ToUInt32(br_read(4), 0);
Common.SendToDebug("Param1: " + u32p1.ToString()); Common.SendToDebug("Param1: " + u32p1.ToString());
IL_CallBaseFunction(il, "GetFromStatic", u32p1 - 6 + myHeader.GVR); IL_CallBaseFunction(il, "GetFromStatic", u32p1 - 6 + myHeader.GVR);
break; break;
/*********************** /***********************
* NOT IMPLEMENTED YET * * NOT IMPLEMENTED YET *
***********************/ ***********************/
case LSO_Enums.Operation_Table.POPIP: case LSO_Enums.Operation_Table.POPIP:
case LSO_Enums.Operation_Table.POPSP: case LSO_Enums.Operation_Table.POPSP:
case LSO_Enums.Operation_Table.POPSLR: case LSO_Enums.Operation_Table.POPSLR:
case LSO_Enums.Operation_Table.POPARG: case LSO_Enums.Operation_Table.POPARG:
case LSO_Enums.Operation_Table.POPBP: case LSO_Enums.Operation_Table.POPBP:
//Common.SendToDebug("Instruction " + idesc + ": Ignored"); //Common.SendToDebug("Instruction " + idesc + ": Ignored");
Common.SendToDebug("Instruction " + idesc + Common.SendToDebug("Instruction " + idesc +
": Description: Drop x bytes from the stack (TODO: Only popping 1)"); ": Description: Drop x bytes from the stack (TODO: Only popping 1)");
//Common.SendToDebug("Param1: " + BitConverter.ToUInt32(br_read(4), 0)); //Common.SendToDebug("Param1: " + BitConverter.ToUInt32(br_read(4), 0));
IL_Pop(il); IL_Pop(il);
break; break;
// None // None
case LSO_Enums.Operation_Table.PUSHIP: case LSO_Enums.Operation_Table.PUSHIP:
// PUSH INSTRUCTION POINTER // PUSH INSTRUCTION POINTER
break; break;
case LSO_Enums.Operation_Table.PUSHBP: case LSO_Enums.Operation_Table.PUSHBP:
case LSO_Enums.Operation_Table.PUSHEV: case LSO_Enums.Operation_Table.PUSHEV:
break; break;
case LSO_Enums.Operation_Table.PUSHEQ: case LSO_Enums.Operation_Table.PUSHEQ:
break; break;
// LONG // LONG
case LSO_Enums.Operation_Table.JUMP: case LSO_Enums.Operation_Table.JUMP:
Common.SendToDebug("Param1: " + BitConverter.ToUInt32(br_read(4), 0)); Common.SendToDebug("Param1: " + BitConverter.ToUInt32(br_read(4), 0));
break; break;
// BYTE, LONG // BYTE, LONG
case LSO_Enums.Operation_Table.JUMPIF: case LSO_Enums.Operation_Table.JUMPIF:
case LSO_Enums.Operation_Table.JUMPNIF: case LSO_Enums.Operation_Table.JUMPNIF:
Common.SendToDebug("Param1: " + br_read(1)[0]); Common.SendToDebug("Param1: " + br_read(1)[0]);
Common.SendToDebug("Param2: " + BitConverter.ToUInt32(br_read(4), 0)); Common.SendToDebug("Param2: " + BitConverter.ToUInt32(br_read(4), 0));
break; break;
// LONG // LONG
case LSO_Enums.Operation_Table.STATE: case LSO_Enums.Operation_Table.STATE:
bp1 = br_read(1)[0]; bp1 = br_read(1)[0];
//il.Emit(OpCodes.Ld); // Load local variable 0 onto stack //il.Emit(OpCodes.Ld); // Load local variable 0 onto stack
//il.Emit(OpCodes.Ldc_I4, 0); // Push index position //il.Emit(OpCodes.Ldc_I4, 0); // Push index position
//il.Emit(OpCodes.Ldstr, EventList[p1]); // Push value //il.Emit(OpCodes.Ldstr, EventList[p1]); // Push value
//il.Emit(OpCodes.Stelem_Ref); // Perform array[index] = value //il.Emit(OpCodes.Stelem_Ref); // Perform array[index] = value
break; break;
case LSO_Enums.Operation_Table.CALL: case LSO_Enums.Operation_Table.CALL:
Common.SendToDebug("Param1: " + BitConverter.ToUInt32(br_read(4), 0)); Common.SendToDebug("Param1: " + BitConverter.ToUInt32(br_read(4), 0));
Common.SendToDebug("ERROR: Function CALL not implemented yet."); Common.SendToDebug("ERROR: Function CALL not implemented yet.");
break; break;
// BYTE // BYTE
case LSO_Enums.Operation_Table.CAST: case LSO_Enums.Operation_Table.CAST:
bp1 = br_read(1)[0]; bp1 = br_read(1)[0];
Common.SendToDebug("Instruction " + idesc + ": Cast to type: " + Common.SendToDebug("Instruction " + idesc + ": Cast to type: " +
((LSO_Enums.OpCode_Cast_TypeDefs) bp1)); ((LSO_Enums.OpCode_Cast_TypeDefs) bp1));
Common.SendToDebug("Param1: " + bp1); Common.SendToDebug("Param1: " + bp1);
switch ((LSO_Enums.OpCode_Cast_TypeDefs) bp1) switch ((LSO_Enums.OpCode_Cast_TypeDefs) bp1)
{ {
case LSO_Enums.OpCode_Cast_TypeDefs.String: case LSO_Enums.OpCode_Cast_TypeDefs.String:
Common.SendToDebug("Instruction " + idesc + ": il.Emit(OpCodes.Box, ILStack.Pop());"); Common.SendToDebug("Instruction " + idesc + ": il.Emit(OpCodes.Box, ILStack.Pop());");
break; break;
default: default:
Common.SendToDebug("Instruction " + idesc + ": Unknown cast type!"); Common.SendToDebug("Instruction " + idesc + ": Unknown cast type!");
break; break;
} }
break; break;
// LONG // LONG
case LSO_Enums.Operation_Table.STACKTOS: case LSO_Enums.Operation_Table.STACKTOS:
case LSO_Enums.Operation_Table.STACKTOL: case LSO_Enums.Operation_Table.STACKTOL:
Common.SendToDebug("Param1: " + BitConverter.ToUInt32(br_read(4), 0)); Common.SendToDebug("Param1: " + BitConverter.ToUInt32(br_read(4), 0));
break; break;
// BYTE // BYTE
case LSO_Enums.Operation_Table.PRINT: case LSO_Enums.Operation_Table.PRINT:
case LSO_Enums.Operation_Table.CALLLIB: case LSO_Enums.Operation_Table.CALLLIB:
Common.SendToDebug("Param1: " + br_read(1)[0]); Common.SendToDebug("Param1: " + br_read(1)[0]);
break; break;
} }
return false; return false;
} }
private void IL_PopToStack(ILGenerator il) private void IL_PopToStack(ILGenerator il)
{ {
IL_PopToStack(il, 1); IL_PopToStack(il, 1);
} }
private void IL_PopToStack(ILGenerator il, int count) private void IL_PopToStack(ILGenerator il, int count)
{ {
Common.SendToDebug("IL_PopToStack();"); Common.SendToDebug("IL_PopToStack();");
for (int i = 0; i < count; i++) for (int i = 0; i < count; i++)
{ {
IL_CallBaseFunction(il, "POPToStack"); IL_CallBaseFunction(il, "POPToStack");
//il.Emit(OpCodes.Ldarg_0); //il.Emit(OpCodes.Ldarg_0);
//il.Emit(OpCodes.Call, //il.Emit(OpCodes.Call,
// typeof(LSL_BaseClass).GetMethod("POPToStack", // typeof(LSL_BaseClass).GetMethod("POPToStack",
// new Type[] { })); // new Type[] { }));
} }
} }
private void IL_Pop(ILGenerator il) private void IL_Pop(ILGenerator il)
{ {
Common.SendToDebug("IL_Pop();"); Common.SendToDebug("IL_Pop();");
IL_CallBaseFunction(il, "POP"); IL_CallBaseFunction(il, "POP");
} }
private void IL_Debug(ILGenerator il, string text) private void IL_Debug(ILGenerator il, string text)
{ {
il.Emit(OpCodes.Ldstr, text); il.Emit(OpCodes.Ldstr, text);
il.Emit(OpCodes.Call, typeof (Common).GetMethod("SendToDebug", il.Emit(OpCodes.Call, typeof (Common).GetMethod("SendToDebug",
new Type[] {typeof (string)} new Type[] {typeof (string)}
)); ));
} }
private void IL_CallBaseFunction(ILGenerator il, string methodname) private void IL_CallBaseFunction(ILGenerator il, string methodname)
{ {
il.Emit(OpCodes.Ldarg_0); il.Emit(OpCodes.Ldarg_0);
il.Emit(OpCodes.Call, typeof (LSL_BaseClass).GetMethod(methodname, new Type[] {})); il.Emit(OpCodes.Call, typeof (LSL_BaseClass).GetMethod(methodname, new Type[] {}));
} }
private void IL_CallBaseFunction(ILGenerator il, string methodname, object data) private void IL_CallBaseFunction(ILGenerator il, string methodname, object data)
{ {
il.Emit(OpCodes.Ldarg_0); il.Emit(OpCodes.Ldarg_0);
if (data.GetType() == typeof (string)) if (data.GetType() == typeof (string))
il.Emit(OpCodes.Ldstr, (string) data); il.Emit(OpCodes.Ldstr, (string) data);
if (data.GetType() == typeof (UInt32)) if (data.GetType() == typeof (UInt32))
il.Emit(OpCodes.Ldc_I4, (UInt32) data); il.Emit(OpCodes.Ldc_I4, (UInt32) data);
il.Emit(OpCodes.Call, typeof (LSL_BaseClass).GetMethod(methodname, new Type[] {data.GetType()})); il.Emit(OpCodes.Call, typeof (LSL_BaseClass).GetMethod(methodname, new Type[] {data.GetType()}));
} }
private void IL_Push(ILGenerator il, object data) private void IL_Push(ILGenerator il, object data)
{ {
il.Emit(OpCodes.Ldarg_0); il.Emit(OpCodes.Ldarg_0);
Common.SendToDebug("PUSH datatype: " + data.GetType()); Common.SendToDebug("PUSH datatype: " + data.GetType());
IL_PushDataTypeToILStack(il, data); IL_PushDataTypeToILStack(il, data);
il.Emit(OpCodes.Call, typeof (LSL_BaseClass).GetMethod("PUSH", new Type[] {data.GetType()})); il.Emit(OpCodes.Call, typeof (LSL_BaseClass).GetMethod("PUSH", new Type[] {data.GetType()}));
} }
private void IL_PushDataTypeToILStack(ILGenerator il, object data) private void IL_PushDataTypeToILStack(ILGenerator il, object data)
{ {
if (data.GetType() == typeof (UInt16)) if (data.GetType() == typeof (UInt16))
{ {
il.Emit(OpCodes.Ldc_I4, (UInt16) data); il.Emit(OpCodes.Ldc_I4, (UInt16) data);
il.Emit(OpCodes.Box, data.GetType()); il.Emit(OpCodes.Box, data.GetType());
} }
if (data.GetType() == typeof (UInt32)) if (data.GetType() == typeof (UInt32))
{ {
il.Emit(OpCodes.Ldc_I4, (UInt32) data); il.Emit(OpCodes.Ldc_I4, (UInt32) data);
il.Emit(OpCodes.Box, data.GetType()); il.Emit(OpCodes.Box, data.GetType());
} }
if (data.GetType() == typeof (Int32)) if (data.GetType() == typeof (Int32))
{ {
il.Emit(OpCodes.Ldc_I4, (Int32) data); il.Emit(OpCodes.Ldc_I4, (Int32) data);
il.Emit(OpCodes.Box, data.GetType()); il.Emit(OpCodes.Box, data.GetType());
} }
if (data.GetType() == typeof (float)) if (data.GetType() == typeof (float))
{ {
il.Emit(OpCodes.Ldc_I4, (float) data); il.Emit(OpCodes.Ldc_I4, (float) data);
il.Emit(OpCodes.Box, data.GetType()); il.Emit(OpCodes.Box, data.GetType());
} }
if (data.GetType() == typeof (string)) if (data.GetType() == typeof (string))
il.Emit(OpCodes.Ldstr, (string) data); il.Emit(OpCodes.Ldstr, (string) data);
//if (data.GetType() == typeof(LSO_Enums.Rotation)) //if (data.GetType() == typeof(LSO_Enums.Rotation))
// il.Emit(OpCodes.Ldobj, (LSO_Enums.Rotation)data); // il.Emit(OpCodes.Ldobj, (LSO_Enums.Rotation)data);
//if (data.GetType() == typeof(LSO_Enums.Vector)) //if (data.GetType() == typeof(LSO_Enums.Vector))
// il.Emit(OpCodes.Ldobj, (LSO_Enums.Vector)data); // il.Emit(OpCodes.Ldobj, (LSO_Enums.Vector)data);
//if (data.GetType() == typeof(LSO_Enums.Key)) //if (data.GetType() == typeof(LSO_Enums.Key))
// il.Emit(OpCodes.Ldobj, (LSO_Enums.Key)data); // il.Emit(OpCodes.Ldobj, (LSO_Enums.Key)data);
} }
} }
} }

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,143 +1,143 @@
/* /*
* Copyright (c) Contributors, http://opensimulator.org/ * Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders. * See CONTRIBUTORS.TXT for a full list of copyright holders.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright * * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer. * notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright * * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the * notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution. * documentation and/or other materials provided with the distribution.
* * Neither the name of the OpenSim Project nor the * * Neither the name of the OpenSim Project nor the
* names of its contributors may be used to endorse or promote products * names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission. * derived from this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * 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 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
*/ */
/* Original code: Tedd Hansen */ /* Original code: Tedd Hansen */
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
namespace OpenSim.Region.ScriptEngine.LSOEngine.LSO namespace OpenSim.Region.ScriptEngine.LSOEngine.LSO
{ {
internal static class LSO_Struct internal static class LSO_Struct
{ {
public struct Header public struct Header
{ {
public UInt32 TM; public UInt32 TM;
public UInt32 IP; public UInt32 IP;
public UInt32 VN; public UInt32 VN;
public UInt32 BP; public UInt32 BP;
public UInt32 SP; public UInt32 SP;
public UInt32 HR; public UInt32 HR;
public UInt32 HP; public UInt32 HP;
public UInt32 CS; public UInt32 CS;
public UInt32 NS; public UInt32 NS;
public UInt32 CE; public UInt32 CE;
public UInt32 IE; public UInt32 IE;
public UInt32 ER; public UInt32 ER;
public UInt32 FR; public UInt32 FR;
public UInt32 SLR; public UInt32 SLR;
public UInt32 GVR; public UInt32 GVR;
public UInt32 GFR; public UInt32 GFR;
public UInt32 PR; public UInt32 PR;
public UInt32 ESR; public UInt32 ESR;
public UInt32 SR; public UInt32 SR;
public UInt64 NCE; public UInt64 NCE;
public UInt64 NIE; public UInt64 NIE;
public UInt64 NER; public UInt64 NER;
} }
public struct StaticBlock public struct StaticBlock
{ {
public UInt32 Static_Chunk_Header_Size; public UInt32 Static_Chunk_Header_Size;
public byte ObjectType; public byte ObjectType;
public byte Unknown; public byte Unknown;
public byte[] BlockVariable; public byte[] BlockVariable;
} }
/* Not actually a structure /* Not actually a structure
public struct StaticBlockVariable public struct StaticBlockVariable
{ {
public UInt32 Integer1; public UInt32 Integer1;
public UInt32 Float1; public UInt32 Float1;
public UInt32 HeapPointer_String; public UInt32 HeapPointer_String;
public UInt32 HeapPointer_Key; public UInt32 HeapPointer_Key;
public byte[] Vector_12; public byte[] Vector_12;
public byte[] Rotation_16; public byte[] Rotation_16;
public UInt32 Pointer_List_Structure; public UInt32 Pointer_List_Structure;
} */ } */
public struct HeapBlock public struct HeapBlock
{ {
public Int32 DataBlockSize; public Int32 DataBlockSize;
public byte ObjectType; public byte ObjectType;
public UInt16 ReferenceCount; public UInt16 ReferenceCount;
public byte[] Data; public byte[] Data;
} }
public struct StateFrameBlock public struct StateFrameBlock
{ {
public UInt32 StateCount; public UInt32 StateCount;
public StatePointerBlock[] StatePointer; public StatePointerBlock[] StatePointer;
} }
public struct StatePointerBlock public struct StatePointerBlock
{ {
public UInt32 Location; public UInt32 Location;
public BitArray EventMask; public BitArray EventMask;
public StateBlock StateBlock; public StateBlock StateBlock;
} }
public struct StateBlock public struct StateBlock
{ {
public UInt32 StartPos; public UInt32 StartPos;
public UInt32 EndPos; public UInt32 EndPos;
public UInt32 HeaderSize; public UInt32 HeaderSize;
public byte Unknown; public byte Unknown;
public StateBlockHandler[] StateBlockHandlers; public StateBlockHandler[] StateBlockHandlers;
} }
public struct StateBlockHandler public struct StateBlockHandler
{ {
public UInt32 CodeChunkPointer; public UInt32 CodeChunkPointer;
public UInt32 CallFrameSize; public UInt32 CallFrameSize;
} }
public struct FunctionBlock public struct FunctionBlock
{ {
public UInt32 FunctionCount; public UInt32 FunctionCount;
public UInt32[] CodeChunkPointer; public UInt32[] CodeChunkPointer;
} }
public struct CodeChunk public struct CodeChunk
{ {
public UInt32 CodeChunkHeaderSize; public UInt32 CodeChunkHeaderSize;
public string Comment; public string Comment;
public List<CodeChunkArgument> CodeChunkArguments; public List<CodeChunkArgument> CodeChunkArguments;
public byte EndMarker; public byte EndMarker;
public byte ReturnTypePos; public byte ReturnTypePos;
public StaticBlock ReturnType; public StaticBlock ReturnType;
} }
public struct CodeChunkArgument public struct CodeChunkArgument
{ {
public byte FunctionReturnTypePos; public byte FunctionReturnTypePos;
public byte NullString; public byte NullString;
public StaticBlock FunctionReturnType; public StaticBlock FunctionReturnType;
} }
} }
} }

View File

@ -1,38 +1,38 @@
using System.Reflection; using System.Reflection;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following // General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information // set of attributes. Change these attribute values to modify the information
// associated with an assembly. // associated with an assembly.
[assembly: AssemblyTitle("OpenSim.Region.ScriptEngine.LSOEngine")] [assembly: AssemblyTitle("OpenSim.Region.ScriptEngine.LSOEngine")]
[assembly : AssemblyDescription("")] [assembly : AssemblyDescription("")]
[assembly : AssemblyConfiguration("")] [assembly : AssemblyConfiguration("")]
[assembly : AssemblyCompany("")] [assembly : AssemblyCompany("")]
[assembly: AssemblyProduct("OpenSim.Region.ScriptEngine.LSOEngine")] [assembly: AssemblyProduct("OpenSim.Region.ScriptEngine.LSOEngine")]
[assembly : AssemblyCopyright("Copyright © 2007")] [assembly : AssemblyCopyright("Copyright © 2007")]
[assembly : AssemblyTrademark("")] [assembly : AssemblyTrademark("")]
[assembly : AssemblyCulture("")] [assembly : AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible // Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from // to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type. // COM, set the ComVisible attribute to true on that type.
[assembly : ComVisible(false)] [assembly : ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM // The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly : Guid("2842257e-6fde-4460-9368-4cde57fa9cc4")] [assembly : Guid("2842257e-6fde-4460-9368-4cde57fa9cc4")]
// Version information for an assembly consists of the following four values: // Version information for an assembly consists of the following four values:
// //
// Major Version // Major Version
// Minor Version // Minor Version
// Build Number // Build Number
// Revision // Revision
// //
// You can specify all the values or you can default the Revision and Build Numbers // You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below: // by using the '*' as shown below:
[assembly : AssemblyVersion("1.0.0.0")] [assembly : AssemblyVersion("1.0.0.0")]
[assembly : AssemblyFileVersion("1.0.0.0")] [assembly : AssemblyFileVersion("1.0.0.0")]

View File

@ -1,55 +1,55 @@
/* /*
* Copyright (c) Contributors, http://opensimulator.org/ * Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders. * See CONTRIBUTORS.TXT for a full list of copyright holders.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright * * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer. * notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright * * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the * notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution. * documentation and/or other materials provided with the distribution.
* * Neither the name of the OpenSim Project nor the * * Neither the name of the OpenSim Project nor the
* names of its contributors may be used to endorse or promote products * names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission. * derived from this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS AS IS AND ANY * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * 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 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
*/ */
using System; using System;
using Nini.Config; using Nini.Config;
using OpenSim.Framework.Console; using OpenSim.Framework.Console;
using OpenSim.Region.Environment.Interfaces; using OpenSim.Region.Environment.Interfaces;
using OpenSim.Region.Environment.Scenes; using OpenSim.Region.Environment.Scenes;
using OpenSim.Region.ScriptEngine.Common; using OpenSim.Region.ScriptEngine.Common;
using OpenSim.Region.ScriptEngine.Common.ScriptEngineBase; using OpenSim.Region.ScriptEngine.Common.ScriptEngineBase;
using EventManager = OpenSim.Region.ScriptEngine.Common.ScriptEngineBase.EventManager; using EventManager = OpenSim.Region.ScriptEngine.Common.ScriptEngineBase.EventManager;
using ScriptManager=OpenSim.Region.ScriptEngine.LSOEngine.ScriptManager; using ScriptManager=OpenSim.Region.ScriptEngine.LSOEngine.ScriptManager;
namespace OpenSim.Region.ScriptEngine.LSOEngine namespace OpenSim.Region.ScriptEngine.LSOEngine
{ {
[Serializable] [Serializable]
public class ScriptEngine : OpenSim.Region.ScriptEngine.Common.ScriptEngineBase.ScriptEngine public class ScriptEngine : OpenSim.Region.ScriptEngine.Common.ScriptEngineBase.ScriptEngine
{ {
// We need to override a few things for our DotNetEngine // We need to override a few things for our DotNetEngine
public override void Initialise(Scene scene, IConfigSource config) public override void Initialise(Scene scene, IConfigSource config)
{ {
InitializeEngine(scene, MainLog.Instance, true, GetScriptManager()); InitializeEngine(scene, MainLog.Instance, true, GetScriptManager());
} }
public override OpenSim.Region.ScriptEngine.Common.ScriptEngineBase.ScriptManager _GetScriptManager() public override OpenSim.Region.ScriptEngine.Common.ScriptEngineBase.ScriptManager _GetScriptManager()
{ {
return new ScriptManager(this); return new ScriptManager(this);
} }
} }
} }

View File

@ -1,158 +1,158 @@
/* /*
* Copyright (c) Contributors, http://opensimulator.org/ * Copyright (c) Contributors, http://opensimulator.org/
* See CONTRIBUTORS.TXT for a full list of copyright holders. * See CONTRIBUTORS.TXT for a full list of copyright holders.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright * * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer. * notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright * * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the * notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution. * documentation and/or other materials provided with the distribution.
* * Neither the name of the OpenSim Project nor the * * Neither the name of the OpenSim Project nor the
* names of its contributors may be used to endorse or promote products * names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission. * derived from this software without specific prior written permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS AS IS AND ANY * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS AS IS AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * 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 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
*/ */
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Reflection; using System.Reflection;
using System.Runtime.Serialization.Formatters.Binary; using System.Runtime.Serialization.Formatters.Binary;
using System.Threading; using System.Threading;
using libsecondlife; using libsecondlife;
using OpenSim.Framework; using OpenSim.Framework;
using OpenSim.Region.Environment.Scenes; using OpenSim.Region.Environment.Scenes;
using OpenSim.Region.ScriptEngine.Common; using OpenSim.Region.ScriptEngine.Common;
namespace OpenSim.Region.ScriptEngine.LSOEngine namespace OpenSim.Region.ScriptEngine.LSOEngine
{ {
public class ScriptManager : OpenSim.Region.ScriptEngine.Common.ScriptEngineBase.ScriptManager public class ScriptManager : OpenSim.Region.ScriptEngine.Common.ScriptEngineBase.ScriptManager
{ {
public ScriptManager(Common.ScriptEngineBase.ScriptEngine scriptEngine) public ScriptManager(Common.ScriptEngineBase.ScriptEngine scriptEngine)
: base(scriptEngine) : base(scriptEngine)
{ {
base.m_scriptEngine = scriptEngine; base.m_scriptEngine = scriptEngine;
} }
// KEEP TRACK OF SCRIPTS <int id, whatever script> // KEEP TRACK OF SCRIPTS <int id, whatever script>
//internal Dictionary<uint, Dictionary<LLUUID, LSL_BaseClass>> Scripts = new Dictionary<uint, Dictionary<LLUUID, LSL_BaseClass>>(); //internal Dictionary<uint, Dictionary<LLUUID, LSL_BaseClass>> Scripts = new Dictionary<uint, Dictionary<LLUUID, LSL_BaseClass>>();
// LOAD SCRIPT // LOAD SCRIPT
// UNLOAD SCRIPT // UNLOAD SCRIPT
// PROVIDE SCRIPT WITH ITS INTERFACE TO OpenSim // PROVIDE SCRIPT WITH ITS INTERFACE TO OpenSim
public override void _StartScript(uint localID, LLUUID itemID, string Script) public override void _StartScript(uint localID, LLUUID itemID, string Script)
{ {
//IScriptHost root = host.GetRoot(); //IScriptHost root = host.GetRoot();
Console.WriteLine("ScriptManager StartScript: localID: " + localID + ", itemID: " + itemID); Console.WriteLine("ScriptManager StartScript: localID: " + localID + ", itemID: " + itemID);
// We will initialize and start the script. // We will initialize and start the script.
// It will be up to the script itself to hook up the correct events. // It will be up to the script itself to hook up the correct events.
string ScriptSource = ""; string ScriptSource = "";
SceneObjectPart m_host = World.GetSceneObjectPart(localID); SceneObjectPart m_host = World.GetSceneObjectPart(localID);
try try
{ {
// Compile (We assume LSL) // Compile (We assume LSL)
//ScriptSource = LSLCompiler.CompileFromLSLText(Script); //ScriptSource = LSLCompiler.CompileFromLSLText(Script);
#if DEBUG #if DEBUG
long before; long before;
before = GC.GetTotalMemory(true); before = GC.GetTotalMemory(true);
#endif #endif
IScript CompiledScript; IScript CompiledScript;
CompiledScript = m_scriptEngine.m_AppDomainManager.LoadScript(ScriptSource); CompiledScript = m_scriptEngine.m_AppDomainManager.LoadScript(ScriptSource);
#if DEBUG #if DEBUG
Console.WriteLine("Script " + itemID + " occupies {0} bytes", GC.GetTotalMemory(true) - before); Console.WriteLine("Script " + itemID + " occupies {0} bytes", GC.GetTotalMemory(true) - before);
#endif #endif
CompiledScript.Source = ScriptSource; CompiledScript.Source = ScriptSource;
// Add it to our script memstruct // Add it to our script memstruct
SetScript(localID, itemID, CompiledScript); SetScript(localID, itemID, CompiledScript);
// We need to give (untrusted) assembly a private instance of BuiltIns // We need to give (untrusted) assembly a private instance of BuiltIns
// this private copy will contain Read-Only FullitemID so that it can bring that on to the server whenever needed. // this private copy will contain Read-Only FullitemID so that it can bring that on to the server whenever needed.
LSL_BuiltIn_Commands LSLB = new LSL_BuiltIn_Commands(m_scriptEngine, m_host, localID, itemID); LSL_BuiltIn_Commands LSLB = new LSL_BuiltIn_Commands(m_scriptEngine, m_host, localID, itemID);
// Start the script - giving it BuiltIns // Start the script - giving it BuiltIns
CompiledScript.Start(LSLB); CompiledScript.Start(LSLB);
// Fire the first start-event // Fire the first start-event
m_scriptEngine.m_EventQueueManager.AddToScriptQueue(localID, itemID, "state_entry", new object[] { }); m_scriptEngine.m_EventQueueManager.AddToScriptQueue(localID, itemID, "state_entry", new object[] { });
} }
catch (Exception e) catch (Exception e)
{ {
//m_scriptEngine.Log.Error("ScriptEngine", "Error compiling script: " + e.ToString()); //m_scriptEngine.Log.Error("ScriptEngine", "Error compiling script: " + e.ToString());
try try
{ {
// DISPLAY ERROR INWORLD // DISPLAY ERROR INWORLD
string text = "Error compiling script:\r\n" + e.Message.ToString(); string text = "Error compiling script:\r\n" + e.Message.ToString();
if (text.Length > 1500) if (text.Length > 1500)
text = text.Substring(0, 1500); text = text.Substring(0, 1500);
World.SimChat(Helpers.StringToField(text), ChatTypeEnum.Say, 0, m_host.AbsolutePosition, World.SimChat(Helpers.StringToField(text), ChatTypeEnum.Say, 0, m_host.AbsolutePosition,
m_host.Name, m_host.UUID); m_host.Name, m_host.UUID);
} }
catch (Exception e2) catch (Exception e2)
{ {
m_scriptEngine.Log.Error("ScriptEngine", "Error displaying error in-world: " + e2.ToString()); m_scriptEngine.Log.Error("ScriptEngine", "Error displaying error in-world: " + e2.ToString());
m_scriptEngine.Log.Error("ScriptEngine", m_scriptEngine.Log.Error("ScriptEngine",
"Errormessage: Error compiling script:\r\n" + e.Message.ToString()); "Errormessage: Error compiling script:\r\n" + e.Message.ToString());
} }
} }
} }
public override void _StopScript(uint localID, LLUUID itemID) public override void _StopScript(uint localID, LLUUID itemID)
{ {
// Stop script // Stop script
Console.WriteLine("Stop script localID: " + localID + " LLUID: " + itemID.ToString()); Console.WriteLine("Stop script localID: " + localID + " LLUID: " + itemID.ToString());
// Stop long command on script // Stop long command on script
m_scriptEngine.m_LSLLongCmdHandler.RemoveScript(localID, itemID); m_scriptEngine.m_LSLLongCmdHandler.RemoveScript(localID, itemID);
IScript LSLBC = GetScript(localID, itemID); IScript LSLBC = GetScript(localID, itemID);
if (LSLBC == null) if (LSLBC == null)
return; return;
// TEMP: First serialize it // TEMP: First serialize it
//GetSerializedScript(localID, itemID); //GetSerializedScript(localID, itemID);
try try
{ {
// Get AppDomain // Get AppDomain
AppDomain ad = LSLBC.Exec.GetAppDomain(); AppDomain ad = LSLBC.Exec.GetAppDomain();
// Tell script not to accept new requests // Tell script not to accept new requests
GetScript(localID, itemID).Exec.StopScript(); GetScript(localID, itemID).Exec.StopScript();
// Remove from internal structure // Remove from internal structure
RemoveScript(localID, itemID); RemoveScript(localID, itemID);
// Tell AppDomain that we have stopped script // Tell AppDomain that we have stopped script
m_scriptEngine.m_AppDomainManager.StopScript(ad); m_scriptEngine.m_AppDomainManager.StopScript(ad);
} }
catch (Exception e) catch (Exception e)
{ {
Console.WriteLine("Exception stopping script localID: " + localID + " LLUID: " + itemID.ToString() + Console.WriteLine("Exception stopping script localID: " + localID + " LLUID: " + itemID.ToString() +
": " + e.ToString()); ": " + e.ToString());
} }
} }
} }
} }