aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Environment/Scenes/_scripting
diff options
context:
space:
mode:
authorlbsa712007-08-06 12:54:13 +0000
committerlbsa712007-08-06 12:54:13 +0000
commit74cd26b7228f20bcd9fb2503a81045a36d80a63a (patch)
tree77770b931db549155b9340fb6f8d60fa8d601287 /OpenSim/Region/Environment/Scenes/_scripting
parent* Now we have boxes. Yay! (diff)
downloadopensim-SC-74cd26b7228f20bcd9fb2503a81045a36d80a63a.zip
opensim-SC-74cd26b7228f20bcd9fb2503a81045a36d80a63a.tar.gz
opensim-SC-74cd26b7228f20bcd9fb2503a81045a36d80a63a.tar.bz2
opensim-SC-74cd26b7228f20bcd9fb2503a81045a36d80a63a.tar.xz
Part 1 of a two-part commit to change caps of 'scripting' dir...
Diffstat (limited to 'OpenSim/Region/Environment/Scenes/_scripting')
-rw-r--r--OpenSim/Region/Environment/Scenes/_scripting/Engines/CSharpEngine/CSharpScriptEngine.cs102
-rw-r--r--OpenSim/Region/Environment/Scenes/_scripting/Engines/CSharpEngine/Examples/ExportRegionToLSL.cs70
-rw-r--r--OpenSim/Region/Environment/Scenes/_scripting/Engines/JScriptEngine/JScriptEngine.cs102
-rw-r--r--OpenSim/Region/Environment/Scenes/_scripting/Engines/JVMEngine/JVM/ClassInstance.cs46
-rw-r--r--OpenSim/Region/Environment/Scenes/_scripting/Engines/JVMEngine/JVM/ClassRecord.cs640
-rw-r--r--OpenSim/Region/Environment/Scenes/_scripting/Engines/JVMEngine/JVM/Heap.cs43
-rw-r--r--OpenSim/Region/Environment/Scenes/_scripting/Engines/JVMEngine/JVM/Interpreter.Logic.cs551
-rw-r--r--OpenSim/Region/Environment/Scenes/_scripting/Engines/JVMEngine/JVM/Interpreter.Methods.cs96
-rw-r--r--OpenSim/Region/Environment/Scenes/_scripting/Engines/JVMEngine/JVM/Interpreter.Return.cs40
-rw-r--r--OpenSim/Region/Environment/Scenes/_scripting/Engines/JVMEngine/JVM/Interpreter.cs135
-rw-r--r--OpenSim/Region/Environment/Scenes/_scripting/Engines/JVMEngine/JVM/MainMemory.cs45
-rw-r--r--OpenSim/Region/Environment/Scenes/_scripting/Engines/JVMEngine/JVM/MethodMemory.cs46
-rw-r--r--OpenSim/Region/Environment/Scenes/_scripting/Engines/JVMEngine/JVM/Object.cs37
-rw-r--r--OpenSim/Region/Environment/Scenes/_scripting/Engines/JVMEngine/JVM/OpCodes.cs56
-rw-r--r--OpenSim/Region/Environment/Scenes/_scripting/Engines/JVMEngine/JVM/Stack.cs42
-rw-r--r--OpenSim/Region/Environment/Scenes/_scripting/Engines/JVMEngine/JVM/StackFrame.cs49
-rw-r--r--OpenSim/Region/Environment/Scenes/_scripting/Engines/JVMEngine/JVM/Thread.cs119
-rw-r--r--OpenSim/Region/Environment/Scenes/_scripting/Engines/JVMEngine/JavaEngine.cs29
-rw-r--r--OpenSim/Region/Environment/Scenes/_scripting/Engines/JVMEngine/OpenSimJVM.cs170
-rw-r--r--OpenSim/Region/Environment/Scenes/_scripting/Engines/JVMEngine/Types/ArrayReference.cs10
-rw-r--r--OpenSim/Region/Environment/Scenes/_scripting/Engines/JVMEngine/Types/BaseType.cs10
-rw-r--r--OpenSim/Region/Environment/Scenes/_scripting/Engines/JVMEngine/Types/ObjectReference.cs16
-rw-r--r--OpenSim/Region/Environment/Scenes/_scripting/Engines/JVMEngine/Types/PrimitiveTypes/Byte.cs10
-rw-r--r--OpenSim/Region/Environment/Scenes/_scripting/Engines/JVMEngine/Types/PrimitiveTypes/Char.cs10
-rw-r--r--OpenSim/Region/Environment/Scenes/_scripting/Engines/JVMEngine/Types/PrimitiveTypes/Float.cs16
-rw-r--r--OpenSim/Region/Environment/Scenes/_scripting/Engines/JVMEngine/Types/PrimitiveTypes/Int.cs16
-rw-r--r--OpenSim/Region/Environment/Scenes/_scripting/Engines/LSLEngine/LSLHandler/Common.cs84
-rw-r--r--OpenSim/Region/Environment/Scenes/_scripting/Engines/LSLEngine/LSLHandler/Engine.cs228
-rw-r--r--OpenSim/Region/Environment/Scenes/_scripting/Engines/LSLEngine/LSLHandler/IL_common_functions.cs56
-rw-r--r--OpenSim/Region/Environment/Scenes/_scripting/Engines/LSLEngine/LSLHandler/LSL_BuiltIn_Commands_Interface.cs366
-rw-r--r--OpenSim/Region/Environment/Scenes/_scripting/Engines/LSLEngine/LSLHandler/LSL_BuiltIn_Commands_TestImplementation.cs377
-rw-r--r--OpenSim/Region/Environment/Scenes/_scripting/Engines/LSLEngine/LSLHandler/LSL_CLRInterface.cs79
-rw-r--r--OpenSim/Region/Environment/Scenes/_scripting/Engines/LSLEngine/LSLHandler/LSL_OPCODE_IL_processor.cs351
-rw-r--r--OpenSim/Region/Environment/Scenes/_scripting/Engines/LSLEngine/LSLHandler/LSO_Enums.cs548
-rw-r--r--OpenSim/Region/Environment/Scenes/_scripting/Engines/LSLEngine/LSLHandler/LSO_Parser.cs629
-rw-r--r--OpenSim/Region/Environment/Scenes/_scripting/Engines/LSLEngine/LSLHandler/LSO_Struct.cs133
-rw-r--r--OpenSim/Region/Environment/Scenes/_scripting/Engines/LSLEngine/LSLScript.cs33
-rw-r--r--OpenSim/Region/Environment/Scenes/_scripting/Engines/LSLEngine/LSLScriptEngine.cs27
-rw-r--r--OpenSim/Region/Environment/Scenes/_scripting/Script.cs64
-rw-r--r--OpenSim/Region/Environment/Scenes/_scripting/ScriptAPI.cs32
-rw-r--r--OpenSim/Region/Environment/Scenes/_scripting/ScriptInfo.cs63
-rw-r--r--OpenSim/Region/Environment/Scenes/_scripting/ScriptInterpretedAPI.cs266
-rw-r--r--OpenSim/Region/Environment/Scenes/_scripting/ScriptInterpretedEvents.cs23
-rw-r--r--OpenSim/Region/Environment/Scenes/_scripting/ScriptManager.cs107
44 files changed, 5972 insertions, 0 deletions
diff --git a/OpenSim/Region/Environment/Scenes/_scripting/Engines/CSharpEngine/CSharpScriptEngine.cs b/OpenSim/Region/Environment/Scenes/_scripting/Engines/CSharpEngine/CSharpScriptEngine.cs
new file mode 100644
index 0000000..b0ccd22
--- /dev/null
+++ b/OpenSim/Region/Environment/Scenes/_scripting/Engines/CSharpEngine/CSharpScriptEngine.cs
@@ -0,0 +1,102 @@
1/*
2* Copyright (c) Contributors, http://www.openmetaverse.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders.
4*
5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met:
7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission.
15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*
27*/
28using System;
29using System.CodeDom.Compiler;
30using System.Collections.Generic;
31using Microsoft.CSharp;
32using OpenSim.Framework.Console;
33
34namespace OpenSim.Region.Scripting
35{
36 public class CSharpScriptEngine : IScriptCompiler
37 {
38 public string FileExt()
39 {
40 return ".cs";
41 }
42
43 private Dictionary<string,IScript> LoadDotNetScript(CodeDomProvider compiler, string filename)
44 {
45 CompilerParameters compilerParams = new CompilerParameters();
46 CompilerResults compilerResults;
47 compilerParams.GenerateExecutable = false;
48 compilerParams.GenerateInMemory = true;
49 compilerParams.IncludeDebugInformation = false;
50 compilerParams.ReferencedAssemblies.Add("OpenSim.Region.dll");
51 compilerParams.ReferencedAssemblies.Add("OpenSim.Region.Environment.dll");
52 compilerParams.ReferencedAssemblies.Add("OpenSim.Framework.dll");
53 compilerParams.ReferencedAssemblies.Add("libsecondlife.dll");
54 compilerParams.ReferencedAssemblies.Add("System.dll");
55
56 compilerResults = compiler.CompileAssemblyFromFile(compilerParams, filename);
57
58 if (compilerResults.Errors.Count > 0)
59 {
60 MainLog.Instance.Error("Compile errors");
61 foreach (CompilerError error in compilerResults.Errors)
62 {
63 MainLog.Instance.Error(error.Line.ToString() + ": " + error.ErrorText.ToString());
64 }
65 }
66 else
67 {
68 Dictionary<string,IScript> scripts = new Dictionary<string,IScript>();
69
70 foreach (Type pluginType in compilerResults.CompiledAssembly.GetExportedTypes())
71 {
72 Type testInterface = pluginType.GetInterface("IScript", true);
73
74 if (testInterface != null)
75 {
76 IScript script = (IScript)compilerResults.CompiledAssembly.CreateInstance(pluginType.ToString());
77
78 string scriptName = "C#/" + script.getName();
79 Console.WriteLine("Script: " + scriptName + " loaded.");
80
81 if (!scripts.ContainsKey(scriptName))
82 {
83 scripts.Add(scriptName, script);
84 }
85 else
86 {
87 scripts[scriptName] = script;
88 }
89 }
90 }
91 return scripts;
92 }
93 return null;
94 }
95
96 public Dictionary<string,IScript> compile(string filename)
97 {
98 CSharpCodeProvider csharpProvider = new CSharpCodeProvider();
99 return LoadDotNetScript(csharpProvider, filename);
100 }
101 }
102}
diff --git a/OpenSim/Region/Environment/Scenes/_scripting/Engines/CSharpEngine/Examples/ExportRegionToLSL.cs b/OpenSim/Region/Environment/Scenes/_scripting/Engines/CSharpEngine/Examples/ExportRegionToLSL.cs
new file mode 100644
index 0000000..f753b30
--- /dev/null
+++ b/OpenSim/Region/Environment/Scenes/_scripting/Engines/CSharpEngine/Examples/ExportRegionToLSL.cs
@@ -0,0 +1,70 @@
1using OpenSim.Framework.Console;
2using OpenSim.Framework;
3using OpenSim.Region.Environment;
4using OpenSim.Region.Environment.Scenes;
5
6using System.Collections.Generic;
7using libsecondlife;
8
9namespace OpenSim.Region.Scripting.Examples
10{
11 public class LSLExportScript : IScript
12 {
13 ScriptInfo script;
14
15 public string getName()
16 {
17 return "LSL Export Script 0.1";
18 }
19
20 public void Initialise(ScriptInfo scriptInfo)
21 {
22 script = scriptInfo;
23
24 script.events.OnScriptConsole += new EventManager.OnScriptConsoleDelegate(ProcessConsoleMsg);
25 }
26
27 void ProcessConsoleMsg(string[] args)
28 {
29 if (args[0].ToLower() == "lslexport")
30 {
31 string sequence = "";
32
33 foreach (KeyValuePair<LLUUID, SceneObject> obj in script.world.Objects)
34 {
35 SceneObject root = obj.Value;
36
37 sequence += "NEWOBJ::" + obj.Key.ToStringHyphenated() + "\n";
38
39 string rootPrim = processPrimitiveToString(root.rootPrimitive);
40
41 sequence += "ROOT:" + rootPrim;
42
43 foreach (KeyValuePair<LLUUID, OpenSim.Region.Environment.Scenes.Primitive> prim in root.Children)
44 {
45 string child = processPrimitiveToString(prim.Value);
46 sequence += "CHILD:" + child;
47 }
48 }
49
50 System.Console.WriteLine(sequence);
51 }
52 }
53
54 string processPrimitiveToString(OpenSim.Region.Environment.Scenes.Primitive prim)
55 {
56 string desc = prim.Description;
57 string name = prim.Name;
58 LLVector3 pos = prim.Pos;
59 LLQuaternion rot = new LLQuaternion(prim.Rotation.x, prim.Rotation.y, prim.Rotation.z, prim.Rotation.w);
60 LLVector3 scale = prim.Scale;
61 LLVector3 rootPos = prim.WorldPos;
62
63 string setPrimParams = "";
64
65 setPrimParams += "[PRIM_SCALE, " + scale.ToString() + ", PRIM_POS, " + rootPos.ToString() + ", PRIM_ROTATION, " + rot.ToString() + "]\n";
66
67 return setPrimParams;
68 }
69 }
70} \ No newline at end of file
diff --git a/OpenSim/Region/Environment/Scenes/_scripting/Engines/JScriptEngine/JScriptEngine.cs b/OpenSim/Region/Environment/Scenes/_scripting/Engines/JScriptEngine/JScriptEngine.cs
new file mode 100644
index 0000000..af4f8b4
--- /dev/null
+++ b/OpenSim/Region/Environment/Scenes/_scripting/Engines/JScriptEngine/JScriptEngine.cs
@@ -0,0 +1,102 @@
1/*
2* Copyright (c) Contributors, http://www.openmetaverse.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders.
4*
5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met:
7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission.
15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*
27*/
28using System;
29using System.CodeDom.Compiler;
30using System.Collections.Generic;
31using Microsoft.JScript;
32using OpenSim.Framework.Console;
33
34namespace OpenSim.Region.Scripting
35{
36 public class JScriptEngine : IScriptCompiler
37 {
38 public string FileExt()
39 {
40 return ".js";
41 }
42
43 private Dictionary<string, IScript> LoadDotNetScript(CodeDomProvider compiler, string filename)
44 {
45 CompilerParameters compilerParams = new CompilerParameters();
46 CompilerResults compilerResults;
47 compilerParams.GenerateExecutable = false;
48 compilerParams.GenerateInMemory = true;
49 compilerParams.IncludeDebugInformation = false;
50 compilerParams.ReferencedAssemblies.Add("OpenSim.Region.dll");
51 compilerParams.ReferencedAssemblies.Add("OpenSim.Region.Environment.dll");
52 compilerParams.ReferencedAssemblies.Add("OpenSim.Framework.dll");
53 compilerParams.ReferencedAssemblies.Add("libsecondlife.dll");
54 compilerParams.ReferencedAssemblies.Add("System.dll");
55
56 compilerResults = compiler.CompileAssemblyFromFile(compilerParams, filename);
57
58 if (compilerResults.Errors.Count > 0)
59 {
60 MainLog.Instance.Error("Compile errors");
61 foreach (CompilerError error in compilerResults.Errors)
62 {
63 MainLog.Instance.Error(error.Line.ToString() + ": " + error.ErrorText.ToString());
64 }
65 }
66 else
67 {
68 Dictionary<string, IScript> scripts = new Dictionary<string, IScript>();
69
70 foreach (Type pluginType in compilerResults.CompiledAssembly.GetExportedTypes())
71 {
72 Type testInterface = pluginType.GetInterface("IScript", true);
73
74 if (testInterface != null)
75 {
76 IScript script = (IScript)compilerResults.CompiledAssembly.CreateInstance(pluginType.ToString());
77
78 string scriptName = "JS.NET/" + script.getName();
79 Console.WriteLine("Script: " + scriptName + " loaded.");
80
81 if (!scripts.ContainsKey(scriptName))
82 {
83 scripts.Add(scriptName, script);
84 }
85 else
86 {
87 scripts[scriptName] = script;
88 }
89 }
90 }
91 return scripts;
92 }
93 return null;
94 }
95
96 public Dictionary<string, IScript> compile(string filename)
97 {
98 JScriptCodeProvider jscriptProvider = new JScriptCodeProvider();
99 return LoadDotNetScript(jscriptProvider, filename);
100 }
101 }
102}
diff --git a/OpenSim/Region/Environment/Scenes/_scripting/Engines/JVMEngine/JVM/ClassInstance.cs b/OpenSim/Region/Environment/Scenes/_scripting/Engines/JVMEngine/JVM/ClassInstance.cs
new file mode 100644
index 0000000..4b734a3
--- /dev/null
+++ b/OpenSim/Region/Environment/Scenes/_scripting/Engines/JVMEngine/JVM/ClassInstance.cs
@@ -0,0 +1,46 @@
1/*
2* Copyright (c) Contributors, http://www.openmetaverse.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders.
4*
5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met:
7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission.
15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*
27*/
28using System;
29using System.Collections.Generic;
30using System.Text;
31using OpenSim.Region.Scripting.EmbeddedJVM.Types;
32
33namespace OpenSim.Region.Scripting.EmbeddedJVM
34{
35 public class ClassInstance : Object
36 {
37 public int Size;
38 public ClassRecord ClassRec;
39 public Dictionary<string, BaseType> Fields = new Dictionary<string, BaseType>();
40
41 public ClassInstance()
42 {
43
44 }
45 }
46}
diff --git a/OpenSim/Region/Environment/Scenes/_scripting/Engines/JVMEngine/JVM/ClassRecord.cs b/OpenSim/Region/Environment/Scenes/_scripting/Engines/JVMEngine/JVM/ClassRecord.cs
new file mode 100644
index 0000000..4b2aec3
--- /dev/null
+++ b/OpenSim/Region/Environment/Scenes/_scripting/Engines/JVMEngine/JVM/ClassRecord.cs
@@ -0,0 +1,640 @@
1/*
2* Copyright (c) Contributors, http://www.openmetaverse.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders.
4*
5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met:
7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission.
15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*
27*/
28using System;
29using System.IO;
30using System.Collections.Generic;
31using System.Text;
32using OpenSim.Region.Scripting.EmbeddedJVM.Types;
33using OpenSim.Region.Scripting.EmbeddedJVM.Types.PrimitiveTypes;
34
35namespace OpenSim.Region.Scripting.EmbeddedJVM
36{
37 public class ClassRecord
38 {
39 private ushort m_majorVersion;
40 private ushort m_minorVersion;
41 private ushort m_constantPoolCount;
42 private ushort m_accessFlags;
43 private ushort m_thisClass;
44 private ushort m_supperClass;
45 private ushort m_interfaceCount;
46 private ushort m_fieldCount;
47 private ushort m_methodCount;
48 //private ushort _attributeCount;
49 //private string _name;
50 public Dictionary<string, BaseType> StaticFields = new Dictionary<string, BaseType>();
51 public PoolClass MClass;
52
53 public List<PoolItem> m_constantsPool = new List<PoolItem>();
54 private List<MethodInfo> m_methodsList = new List<MethodInfo>();
55 private List<FieldInfo> m_fieldList = new List<FieldInfo>();
56
57 public ClassRecord()
58 {
59
60 }
61
62 public ClassInstance CreateNewInstance()
63 {
64 ClassInstance classInst = new ClassInstance();
65 classInst.ClassRec = this;
66 //TODO: set fields
67
68 return classInst;
69 }
70
71 public void LoadClassFromFile(string fileName)
72 {
73 Console.WriteLine("loading script " + fileName);
74 FileStream fs = File.OpenRead(fileName);
75 this.LoadClassFromBytes(ReadFully(fs));
76 fs.Close();
77 }
78
79 public void LoadClassFromBytes(byte[] data)
80 {
81 int i = 0;
82 i += 4;
83 m_minorVersion = (ushort)((data[i++] << 8) + data[i++]);
84 m_majorVersion = (ushort)((data[i++] << 8) + data[i++]);
85 m_constantPoolCount = (ushort)((data[i++] << 8) + data[i++]);
86 Console.WriteLine("there should be " + m_constantPoolCount + " items in the pool");
87 for (int count = 0; count < (m_constantPoolCount - 1); count++)
88 {
89 //read in the constant pool
90 byte pooltype = data[i++];
91 Console.WriteLine("#" + count + ": new constant type = " + pooltype);
92 //Console.WriteLine("start position is: " + i);
93 switch (pooltype)
94 {
95 case 1: //Utf8
96 ushort uLength = (ushort)((data[i++] << 8) + data[i++]);
97
98 // Console.WriteLine("new utf8 type, length is " + uLength);
99 PoolUtf8 utf8 = new PoolUtf8();
100 utf8.readValue(data, ref i, uLength);
101 this.m_constantsPool.Add(utf8);
102 break;
103 case 3: //Int
104 break;
105 case 4: //Float
106 break;
107 case 7: //Class
108 PoolClass pClass = new PoolClass(this);
109 pClass.readValue(data, ref i);
110 this.m_constantsPool.Add(pClass);
111 break;
112 case 9: //FieldRef
113 PoolFieldRef pField = new PoolFieldRef(this);
114 pField.readValue(data, ref i);
115 this.m_constantsPool.Add(pField);
116 break;
117 case 10: //Method
118 PoolMethodRef pMeth = new PoolMethodRef(this);
119 pMeth.readValue(data, ref i);
120 this.m_constantsPool.Add(pMeth);
121 break;
122 case 12: //NamedType
123 PoolNamedType pNamed = new PoolNamedType(this);
124 pNamed.readValue(data, ref i);
125 this.m_constantsPool.Add(pNamed);
126 break;
127 }
128 }
129
130 m_accessFlags = (ushort)((data[i++] << 8) + data[i++]);
131 m_thisClass = (ushort)((data[i++] << 8) + data[i++]);
132 m_supperClass = (ushort)((data[i++] << 8) + data[i++]);
133
134 if (this.m_constantsPool[this.m_thisClass - 1] is PoolClass)
135 {
136 this.MClass = ((PoolClass)this.m_constantsPool[this.m_thisClass - 1]);
137 }
138
139 m_interfaceCount = (ushort)((data[i++] << 8) + data[i++]);
140 //should now read in the info for each interface
141
142 m_fieldCount = (ushort)((data[i++] << 8) + data[i++]);
143 //should now read in the info for each field
144 for (int count = 0; count < m_fieldCount; count++)
145 {
146 FieldInfo fieldInf = new FieldInfo(this);
147 fieldInf.ReadData(data, ref i);
148 this.m_fieldList.Add(fieldInf);
149 }
150
151 m_methodCount = (ushort)((data[i++] << 8) + data[i++]);
152 for (int count = 0; count < m_methodCount; count++)
153 {
154 MethodInfo methInf = new MethodInfo(this);
155 methInf.ReadData(data, ref i);
156 this.m_methodsList.Add(methInf);
157 }
158 }
159
160 public void AddMethodsToMemory(MethodMemory memory)
161 {
162 for (int count = 0; count < m_methodCount; count++)
163 {
164 this.m_methodsList[count].AddMethodCode(memory);
165 }
166 }
167
168 public bool StartMethod(Thread thread, string methodName)
169 {
170 for (int count = 0; count < m_methodCount; count++)
171 {
172 if (this.m_constantsPool[this.m_methodsList[count].NameIndex - 1] is PoolUtf8)
173 {
174 if (((PoolUtf8)this.m_constantsPool[this.m_methodsList[count].NameIndex - 1]).Value == methodName)
175 {
176 //Console.WriteLine("found method: " + ((PoolUtf8)this._constantsPool[this._methodsList[count].NameIndex - 1]).Value);
177 thread.SetPC(this.m_methodsList[count].CodePointer);
178 return true;
179 }
180 }
181 }
182 return false;
183 }
184
185 public void PrintToConsole()
186 {
187 Console.WriteLine("Class File:");
188 Console.WriteLine("Major version: " + m_majorVersion);
189 Console.WriteLine("Minor version: " + m_minorVersion);
190 Console.WriteLine("Pool size: " + m_constantPoolCount);
191
192 for (int i = 0; i < m_constantsPool.Count; i++)
193 {
194 this.m_constantsPool[i].Print();
195 }
196
197 Console.WriteLine("Access flags: " + m_accessFlags);
198 Console.WriteLine("This class: " + m_thisClass);
199 Console.WriteLine("Super class: " + m_supperClass);
200
201 for (int count = 0; count < m_fieldCount; count++)
202 {
203 Console.WriteLine();
204 this.m_fieldList[count].Print();
205 }
206
207 for (int count = 0; count < m_methodCount; count++)
208 {
209 Console.WriteLine();
210 this.m_methodsList[count].Print();
211 }
212
213 Console.WriteLine("class name is " + this.MClass.Name.Value);
214 }
215
216 public static byte[] ReadFully(Stream stream)
217 {
218 byte[] buffer = new byte[1024];
219 using (MemoryStream ms = new MemoryStream())
220 {
221 while (true)
222 {
223 int read = stream.Read(buffer, 0, buffer.Length);
224 if (read <= 0)
225 return ms.ToArray();
226 ms.Write(buffer, 0, read);
227 }
228 }
229 }
230
231 #region nested classes
232 public class PoolItem
233 {
234 public virtual void Print()
235 {
236
237 }
238 }
239
240 public class PoolUtf8 : PoolItem
241 {
242 public string Value = "";
243
244 public void readValue(byte[] data, ref int pointer, int length)
245 {
246 for (int i = 0; i < length; i++)
247 {
248 int a = (int)data[pointer++];
249 if ((a & 0x80) == 0)
250 {
251 Value = Value + (char)a;
252 }
253 else if ((a & 0x20) == 0)
254 {
255 int b = (int)data[pointer++];
256 Value = Value + (char)(((a & 0x1f) << 6) + (b & 0x3f));
257 }
258 else
259 {
260 int b = (int)data[pointer++];
261 int c = (int)data[pointer++];
262 Value = Value + (char)(((a & 0xf) << 12) + ((b & 0x3f) << 6) + (c & 0x3f));
263 }
264 }
265 }
266
267 public override void Print()
268 {
269 Console.WriteLine("Utf8 type: " + Value);
270 }
271 }
272
273 private class PoolInt : PoolItem
274 {
275
276 }
277
278 public class PoolClass : PoolItem
279 {
280 //public string name = "";
281 public ushort namePointer = 0;
282 private ClassRecord parent;
283 public PoolUtf8 Name;
284
285 public PoolClass(ClassRecord paren)
286 {
287 parent = paren;
288 }
289
290 public void readValue(byte[] data, ref int pointer)
291 {
292 namePointer = (ushort)((data[pointer++] << 8) + data[pointer++]);
293 }
294
295 public override void Print()
296 {
297 this.Name = ((PoolUtf8)this.parent.m_constantsPool[namePointer - 1]);
298 Console.Write("Class type: " + namePointer);
299 Console.WriteLine(" // " + ((PoolUtf8)this.parent.m_constantsPool[namePointer - 1]).Value);
300
301 }
302 }
303
304 public class PoolFieldRef : PoolItem
305 {
306 public ushort classPointer = 0;
307 public ushort nameTypePointer = 0;
308 public PoolNamedType mNameType;
309 public PoolClass mClass;
310 private ClassRecord parent;
311
312 public PoolFieldRef(ClassRecord paren)
313 {
314 parent = paren;
315 }
316
317 public void readValue(byte[] data, ref int pointer)
318 {
319 classPointer = (ushort)((data[pointer++] << 8) + data[pointer++]);
320 nameTypePointer = (ushort)((data[pointer++] << 8) + data[pointer++]);
321 }
322
323 public override void Print()
324 {
325 this.mNameType = ((PoolNamedType)this.parent.m_constantsPool[nameTypePointer - 1]);
326 this.mClass = ((PoolClass)this.parent.m_constantsPool[classPointer - 1]);
327 Console.WriteLine("FieldRef type: " + classPointer + " , " + nameTypePointer);
328 }
329 }
330
331 public class PoolMethodRef : PoolItem
332 {
333 public ushort classPointer = 0;
334 public ushort nameTypePointer = 0;
335 public PoolNamedType mNameType;
336 public PoolClass mClass;
337 private ClassRecord parent;
338
339 public PoolMethodRef(ClassRecord paren)
340 {
341 parent = paren;
342 }
343
344 public void readValue(byte[] data, ref int pointer)
345 {
346 classPointer = (ushort)((data[pointer++] << 8) + data[pointer++]);
347 nameTypePointer = (ushort)((data[pointer++] << 8) + data[pointer++]);
348 }
349
350 public override void Print()
351 {
352 this.mNameType = ((PoolNamedType)this.parent.m_constantsPool[nameTypePointer - 1]);
353 this.mClass = ((PoolClass)this.parent.m_constantsPool[classPointer - 1]);
354 Console.WriteLine("MethodRef type: " + classPointer + " , " + nameTypePointer);
355 }
356 }
357
358 public class PoolNamedType : PoolItem
359 {
360 public ushort namePointer = 0;
361 public ushort typePointer = 0;
362 private ClassRecord parent;
363 public PoolUtf8 Name;
364 public PoolUtf8 Type;
365
366 public PoolNamedType(ClassRecord paren)
367 {
368 parent = paren;
369 }
370
371 public void readValue(byte[] data, ref int pointer)
372 {
373 namePointer = (ushort)((data[pointer++] << 8) + data[pointer++]);
374 typePointer = (ushort)((data[pointer++] << 8) + data[pointer++]);
375 }
376
377 public override void Print()
378 {
379 Name = ((PoolUtf8)this.parent.m_constantsPool[namePointer - 1]);
380 Type = ((PoolUtf8)this.parent.m_constantsPool[typePointer - 1]);
381 Console.Write("Named type: " + namePointer + " , " + typePointer);
382 Console.WriteLine(" // " + ((PoolUtf8)this.parent.m_constantsPool[namePointer - 1]).Value);
383 }
384 }
385
386 //***********************
387 public class MethodInfo
388 {
389 public ushort AccessFlags = 0;
390 public ushort NameIndex = 0;
391 public string Name = "";
392 public ushort DescriptorIndex = 0;
393 public ushort AttributeCount = 0;
394 public List<MethodAttribute> Attributes = new List<MethodAttribute>();
395 private ClassRecord parent;
396 public int CodePointer = 0;
397
398 public MethodInfo(ClassRecord paren)
399 {
400 parent = paren;
401 }
402
403 public void AddMethodCode(MethodMemory memory)
404 {
405 Array.Copy(this.Attributes[0].Code, 0, memory.MethodBuffer, memory.NextMethodPC, this.Attributes[0].Code.Length);
406 memory.Methodcount++;
407 this.CodePointer = memory.NextMethodPC;
408 memory.NextMethodPC += this.Attributes[0].Code.Length;
409 }
410
411 public void ReadData(byte[] data, ref int pointer)
412 {
413 AccessFlags = (ushort)((data[pointer++] << 8) + data[pointer++]);
414 NameIndex = (ushort)((data[pointer++] << 8) + data[pointer++]);
415 DescriptorIndex = (ushort)((data[pointer++] << 8) + data[pointer++]);
416 AttributeCount = (ushort)((data[pointer++] << 8) + data[pointer++]);
417 for (int i = 0; i < AttributeCount; i++)
418 {
419 MethodAttribute attri = new MethodAttribute(this.parent);
420 attri.ReadData(data, ref pointer);
421 this.Attributes.Add(attri);
422 }
423 }
424
425 public void Print()
426 {
427 Console.WriteLine("Method Info Struct: ");
428 Console.WriteLine("AccessFlags: " + AccessFlags);
429 Console.WriteLine("NameIndex: " + NameIndex + " // " + ((PoolUtf8)this.parent.m_constantsPool[NameIndex - 1]).Value);
430 Console.WriteLine("DescriptorIndex: " + DescriptorIndex + " // " + ((PoolUtf8)this.parent.m_constantsPool[DescriptorIndex - 1]).Value);
431 Console.WriteLine("Attribute Count:" + AttributeCount);
432 for (int i = 0; i < AttributeCount; i++)
433 {
434 this.Attributes[i].Print();
435 }
436 }
437
438 public class MethodAttribute
439 {
440 public ushort NameIndex = 0;
441 public string Name = "";
442 public Int32 Length = 0;
443 //for now only support code attribute
444 public ushort MaxStack = 0;
445 public ushort MaxLocals = 0;
446 public Int32 CodeLength = 0;
447 public byte[] Code;
448 public ushort ExceptionTableLength = 0;
449 public ushort SubAttributeCount = 0;
450 public List<SubAttribute> SubAttributes = new List<SubAttribute>();
451 private ClassRecord parent;
452
453 public MethodAttribute(ClassRecord paren)
454 {
455 parent = paren;
456 }
457
458 public void ReadData(byte[] data, ref int pointer)
459 {
460 NameIndex = (ushort)((data[pointer++] << 8) + data[pointer++]);
461 Length = (Int32)((data[pointer++] << 24) + (data[pointer++] << 16) + (data[pointer++] << 8) + data[pointer++]);
462 MaxStack = (ushort)((data[pointer++] << 8) + data[pointer++]);
463 MaxLocals = (ushort)((data[pointer++] << 8) + data[pointer++]);
464 CodeLength = (Int32)((data[pointer++] << 24) + (data[pointer++] << 16) + (data[pointer++] << 8) + data[pointer++]);
465 Code = new byte[CodeLength];
466 for (int i = 0; i < CodeLength; i++)
467 {
468 Code[i] = data[pointer++];
469 }
470 ExceptionTableLength = (ushort)((data[pointer++] << 8) + data[pointer++]);
471 SubAttributeCount = (ushort)((data[pointer++] << 8) + data[pointer++]);
472 for (int i = 0; i < SubAttributeCount; i++)
473 {
474 SubAttribute subAttri = new SubAttribute(this.parent);
475 subAttri.ReadData(data, ref pointer);
476 this.SubAttributes.Add(subAttri);
477 }
478 }
479
480 public void Print()
481 {
482 Console.WriteLine("Method Attribute: ");
483 Console.WriteLine("Name Index: " + NameIndex + " // " + ((PoolUtf8)this.parent.m_constantsPool[NameIndex - 1]).Value);
484 Console.WriteLine("Length: " + Length);
485 Console.WriteLine("MaxStack: " + MaxStack);
486 Console.WriteLine("MaxLocals: " + MaxLocals);
487 Console.WriteLine("CodeLength: " + CodeLength);
488 for (int i = 0; i < Code.Length; i++)
489 {
490 Console.WriteLine("OpCode #" + i + " is: " + Code[i]);
491 }
492 Console.WriteLine("SubAttributes: " + SubAttributeCount);
493 for (int i = 0; i < SubAttributeCount; i++)
494 {
495 this.SubAttributes[i].Print();
496 }
497 }
498
499 public class SubAttribute
500 {
501 public ushort NameIndex = 0;
502 public string Name = "";
503 public Int32 Length = 0;
504 public byte[] Data;
505 private ClassRecord parent;
506
507 public SubAttribute(ClassRecord paren)
508 {
509 parent = paren;
510 }
511
512 public void ReadData(byte[] data, ref int pointer)
513 {
514 NameIndex = (ushort)((data[pointer++] << 8) + data[pointer++]);
515 Length = (Int32)((data[pointer++] << 24) + (data[pointer++] << 16) + (data[pointer++] << 8) + data[pointer++]);
516 Data = new byte[Length];
517 for (int i = 0; i < Length; i++)
518 {
519 Data[i] = data[pointer++];
520 }
521 }
522
523 public void Print()
524 {
525 Console.WriteLine("SubAttribute: NameIndex: " + NameIndex + " // " + ((PoolUtf8)this.parent.m_constantsPool[NameIndex - 1]).Value);
526 }
527
528 }
529 }
530
531 }
532 private class InterfaceInfo
533 {
534 public void ReadData(byte[] data, ref int i)
535 {
536
537 }
538 }
539
540 public class FieldInfo
541 {
542 public ushort AccessFlags = 0;
543 public ushort NameIndex = 0;
544 public string Name = "";
545 public ushort DescriptorIndex = 0;
546 public ushort AttributeCount = 0;
547 public List<FieldAttribute> Attributes = new List<FieldAttribute>();
548 private ClassRecord parent;
549
550 public FieldInfo(ClassRecord paren)
551 {
552 parent = paren;
553 }
554
555 public void ReadData(byte[] data, ref int pointer)
556 {
557 AccessFlags = (ushort)((data[pointer++] << 8) + data[pointer++]);
558 NameIndex = (ushort)((data[pointer++] << 8) + data[pointer++]);
559 DescriptorIndex = (ushort)((data[pointer++] << 8) + data[pointer++]);
560 AttributeCount = (ushort)((data[pointer++] << 8) + data[pointer++]);
561 for (int i = 0; i < AttributeCount; i++)
562 {
563 FieldAttribute attri = new FieldAttribute(this.parent);
564 attri.ReadData(data, ref pointer);
565 this.Attributes.Add(attri);
566 }
567 }
568
569 public void Print()
570 {
571 Console.WriteLine("Field Info Struct: ");
572 Console.WriteLine("AccessFlags: " + AccessFlags);
573 Console.WriteLine("NameIndex: " + NameIndex + " // " + ((PoolUtf8)this.parent.m_constantsPool[NameIndex - 1]).Value);
574 Console.WriteLine("DescriptorIndex: " + DescriptorIndex + " // " + ((PoolUtf8)this.parent.m_constantsPool[DescriptorIndex - 1]).Value);
575 Console.WriteLine("Attribute Count:" + AttributeCount);
576 //if static, add to static field list
577 // if (this.AccessFlags == 9) //public and static
578 if ((this.AccessFlags & 0x08) != 0)
579 {
580 switch (((PoolUtf8)this.parent.m_constantsPool[DescriptorIndex - 1]).Value)
581 {
582 case "I":
583 Int newin = new Int();
584 this.parent.StaticFields.Add(((PoolUtf8)this.parent.m_constantsPool[NameIndex - 1]).Value, newin);
585 break;
586 case "F":
587 Float newfl = new Float();
588 this.parent.StaticFields.Add(((PoolUtf8)this.parent.m_constantsPool[NameIndex - 1]).Value, newfl);
589 break;
590 }
591
592 }
593 for (int i = 0; i < AttributeCount; i++)
594 {
595 this.Attributes[i].Print();
596 }
597 }
598
599 public class FieldAttribute
600 {
601 public ushort NameIndex = 0;
602 public string Name = "";
603 public Int32 Length = 0;
604 public byte[] Data;
605 private ClassRecord parent;
606
607 public FieldAttribute(ClassRecord paren)
608 {
609 parent = paren;
610 }
611
612 public void ReadData(byte[] data, ref int pointer)
613 {
614 NameIndex = (ushort)((data[pointer++] << 8) + data[pointer++]);
615 Length = (Int32)((data[pointer++] << 24) + (data[pointer++] << 16) + (data[pointer++] << 8) + data[pointer++]);
616 Data = new byte[Length];
617 for (int i = 0; i < Length; i++)
618 {
619 Data[i] = data[pointer++];
620 }
621 }
622
623 public void Print()
624 {
625 Console.WriteLine("FieldAttribute: NameIndex: " + NameIndex + " // " + ((PoolUtf8)this.parent.m_constantsPool[NameIndex - 1]).Value);
626 }
627 }
628 }
629
630 private class AttributeInfo
631 {
632 public void ReadData(byte[] data, ref int i)
633 {
634
635 }
636 }
637 #endregion
638
639 }
640} \ No newline at end of file
diff --git a/OpenSim/Region/Environment/Scenes/_scripting/Engines/JVMEngine/JVM/Heap.cs b/OpenSim/Region/Environment/Scenes/_scripting/Engines/JVMEngine/JVM/Heap.cs
new file mode 100644
index 0000000..c6423fc
--- /dev/null
+++ b/OpenSim/Region/Environment/Scenes/_scripting/Engines/JVMEngine/JVM/Heap.cs
@@ -0,0 +1,43 @@
1/*
2* Copyright (c) Contributors, http://www.openmetaverse.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders.
4*
5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met:
7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission.
15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*
27*/
28using System;
29using System.Collections.Generic;
30using System.Text;
31
32namespace OpenSim.Region.Scripting.EmbeddedJVM
33{
34 public class Heap
35 {
36 public List<ClassInstance> ClassObjects = new List<ClassInstance>();
37
38 public Heap()
39 {
40
41 }
42 }
43}
diff --git a/OpenSim/Region/Environment/Scenes/_scripting/Engines/JVMEngine/JVM/Interpreter.Logic.cs b/OpenSim/Region/Environment/Scenes/_scripting/Engines/JVMEngine/JVM/Interpreter.Logic.cs
new file mode 100644
index 0000000..ef6570d
--- /dev/null
+++ b/OpenSim/Region/Environment/Scenes/_scripting/Engines/JVMEngine/JVM/Interpreter.Logic.cs
@@ -0,0 +1,551 @@
1/*
2* Copyright (c) Contributors, http://www.openmetaverse.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders.
4*
5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met:
7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission.
15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*
27*/
28using System;
29using System.Collections.Generic;
30using System.Text;
31using OpenSim.Region.Scripting.EmbeddedJVM.Types;
32using OpenSim.Region.Scripting.EmbeddedJVM.Types.PrimitiveTypes;
33
34namespace OpenSim.Region.Scripting.EmbeddedJVM
35{
36 partial class Thread
37 {
38 private partial class Interpreter
39 {
40 private bool IsLogicOpCode(byte opcode)
41 {
42 bool result = false;
43 switch (opcode)
44 {
45 case (byte)(byte)OpCode.iconst_m1:
46 Int m_int = new Int();
47 m_int.mValue = -1;
48 this.m_thread.m_currentFrame.OpStack.Push(m_int);
49 result = true;
50 break;
51 case (byte)(byte)OpCode.iconst_0:
52 m_int = new Int();
53 m_int.mValue = 0;
54 this.m_thread.m_currentFrame.OpStack.Push(m_int);
55 result = true;
56 break;
57 case (byte)(byte)OpCode.iconst_1:
58 m_int = new Int();
59 m_int.mValue = 1;
60 this.m_thread.m_currentFrame.OpStack.Push(m_int);
61 result = true;
62 break;
63 case (byte)(byte)OpCode.iconst_2:
64 m_int = new Int();
65 m_int.mValue = 2;
66 this.m_thread.m_currentFrame.OpStack.Push(m_int);
67 result = true;
68 break;
69 case (byte)(byte)OpCode.iconst_3:
70 m_int = new Int();
71 m_int.mValue = 3;
72 this.m_thread.m_currentFrame.OpStack.Push(m_int);
73 break;
74 case (byte)(byte)OpCode.iconst_4:
75 m_int = new Int();
76 m_int.mValue = 4;
77 this.m_thread.m_currentFrame.OpStack.Push(m_int);
78 result = true;
79 break;
80 case (byte)OpCode.iconst_5:
81 m_int = new Int();
82 m_int.mValue = 5;
83 this.m_thread.m_currentFrame.OpStack.Push(m_int);
84 result = true;
85 break;
86 case (byte)OpCode.fconst_0:
87 Float m_float = new Float();
88 m_float.mValue = 0.0f;
89 this.m_thread.m_currentFrame.OpStack.Push(m_float);
90 result = true;
91 break;
92 case (byte)OpCode.fconst_1:
93 m_float = new Float();
94 m_float.mValue = 1.0f;
95 this.m_thread.m_currentFrame.OpStack.Push(m_float);
96 result = true;
97 break;
98 case (byte)OpCode.fconst_2:
99 m_float = new Float();
100 m_float.mValue = 2.0f;
101 this.m_thread.m_currentFrame.OpStack.Push(m_float);
102 result = true;
103 break;
104 case (byte)OpCode.bipush: //is this right? this should be pushing a byte onto stack not int?
105 int pushvalue = (int)GlobalMemory.MethodArea.MethodBuffer[this.m_thread.PC];
106 Int pushInt = new Int();
107 pushInt.mValue = pushvalue;
108 this.m_thread.m_currentFrame.OpStack.Push(pushInt);
109 this.m_thread.PC++;
110 result = true;
111 break;
112 case (byte)OpCode.sipush:
113 short pushvalue2 = (short)((GlobalMemory.MethodArea.MethodBuffer[this.m_thread.PC] << 8) + GlobalMemory.MethodArea.MethodBuffer[this.m_thread.PC + 1]);
114 Int pushInt2 = new Int();
115 pushInt2.mValue = pushvalue2;
116 this.m_thread.m_currentFrame.OpStack.Push(pushInt2);
117 this.m_thread.PC += 2;
118 result = true;
119 break;
120 case (byte)OpCode.fload:
121 short findex1 = (short)((GlobalMemory.MethodArea.MethodBuffer[this.m_thread.PC]));
122 Float fload = new Float();
123 if (this.m_thread.m_currentFrame.LocalVariables[findex1] != null)
124 {
125 if (this.m_thread.m_currentFrame.LocalVariables[findex1] is Float)
126 {
127 fload.mValue = ((Float)this.m_thread.m_currentFrame.LocalVariables[findex1]).mValue;
128 this.m_thread.m_currentFrame.OpStack.Push(fload);
129 }
130 }
131 this.m_thread.PC++;
132 result = true;
133 break;
134 case (byte)OpCode.iload_0:
135 if (this.m_thread.m_currentFrame.LocalVariables[0] != null)
136 {
137 if (this.m_thread.m_currentFrame.LocalVariables[0] is Int)
138 {
139 Int newInt = new Int();
140 newInt.mValue = ((Int)this.m_thread.m_currentFrame.LocalVariables[0]).mValue;
141 this.m_thread.m_currentFrame.OpStack.Push(newInt);
142 }
143 }
144 result = true;
145 break;
146 case (byte)OpCode.iload_1:
147 if (this.m_thread.m_currentFrame.LocalVariables[1] != null)
148 {
149 if (this.m_thread.m_currentFrame.LocalVariables[1] is Int)
150 {
151 Int newInt = new Int();
152 newInt.mValue = ((Int)this.m_thread.m_currentFrame.LocalVariables[1]).mValue;
153 this.m_thread.m_currentFrame.OpStack.Push(newInt);
154 }
155 }
156 result = true;
157 break;
158 case (byte)OpCode.fload_0:
159 if (this.m_thread.m_currentFrame.LocalVariables[0] != null)
160 {
161 if (this.m_thread.m_currentFrame.LocalVariables[0] is Float)
162 {
163 Float newfloat = new Float();
164 newfloat.mValue = ((Float)this.m_thread.m_currentFrame.LocalVariables[0]).mValue;
165 this.m_thread.m_currentFrame.OpStack.Push(newfloat);
166 }
167 }
168 result = true;
169 break;
170 case (byte)OpCode.fload_1:
171 if (this.m_thread.m_currentFrame.LocalVariables[1] != null)
172 {
173 if (this.m_thread.m_currentFrame.LocalVariables[1] is Float)
174 {
175 Float newfloat = new Float();
176 newfloat.mValue = ((Float)this.m_thread.m_currentFrame.LocalVariables[1]).mValue;
177 this.m_thread.m_currentFrame.OpStack.Push(newfloat);
178 }
179 }
180 result = true;
181 break;
182 case (byte)OpCode.fload_2:
183 if (this.m_thread.m_currentFrame.LocalVariables[2] != null)
184 {
185 if (this.m_thread.m_currentFrame.LocalVariables[2] is Float)
186 {
187 Float newfloat = new Float();
188 newfloat.mValue = ((Float)this.m_thread.m_currentFrame.LocalVariables[2]).mValue;
189 this.m_thread.m_currentFrame.OpStack.Push(newfloat);
190 }
191 }
192 result = true;
193 break;
194 case (byte)OpCode.fload_3:
195 if (this.m_thread.m_currentFrame.LocalVariables[3] != null)
196 {
197 if (this.m_thread.m_currentFrame.LocalVariables[3] is Float)
198 {
199 Float newfloat = new Float();
200 newfloat.mValue = ((Float)this.m_thread.m_currentFrame.LocalVariables[3]).mValue;
201 this.m_thread.m_currentFrame.OpStack.Push(newfloat);
202 }
203 }
204 result = true;
205 break;
206 case (byte)OpCode.istore:
207 short findex3 = (short)((GlobalMemory.MethodArea.MethodBuffer[this.m_thread.PC]));
208 BaseType istor = this.m_thread.m_currentFrame.OpStack.Pop();
209 if (istor is Int)
210 {
211 this.m_thread.m_currentFrame.LocalVariables[findex3] = (Int)istor;
212 }
213 this.m_thread.PC++;
214 result = true;
215 break;
216 case (byte)OpCode.fstore:
217 short findex = (short)((GlobalMemory.MethodArea.MethodBuffer[this.m_thread.PC]));
218 BaseType fstor = this.m_thread.m_currentFrame.OpStack.Pop();
219 if (fstor is Float)
220 {
221 this.m_thread.m_currentFrame.LocalVariables[findex] = (Float)fstor;
222 }
223 this.m_thread.PC++;
224 result = true;
225 break;
226 case (byte)OpCode.istore_0:
227 BaseType baset = this.m_thread.m_currentFrame.OpStack.Pop();
228 if (baset is Int)
229 {
230 this.m_thread.m_currentFrame.LocalVariables[0] = (Int)baset;
231 }
232 result = true;
233 break;
234 case (byte)OpCode.istore_1:
235 baset = this.m_thread.m_currentFrame.OpStack.Pop();
236 if (baset is Int)
237 {
238 this.m_thread.m_currentFrame.LocalVariables[1] = (Int)baset;
239 }
240 result = true;
241 break;
242 case (byte)OpCode.fstore_0:
243 baset = this.m_thread.m_currentFrame.OpStack.Pop();
244 if (baset is Float)
245 {
246 this.m_thread.m_currentFrame.LocalVariables[0] = (Float)baset;
247 }
248 result = true;
249 break;
250 case (byte)OpCode.fstore_1:
251 baset = this.m_thread.m_currentFrame.OpStack.Pop();
252 if (baset is Float)
253 {
254 this.m_thread.m_currentFrame.LocalVariables[1] = (Float)baset;
255 }
256 result = true;
257 break;
258 case (byte)OpCode.fstore_2:
259 baset = this.m_thread.m_currentFrame.OpStack.Pop();
260 if (baset is Float)
261 {
262 this.m_thread.m_currentFrame.LocalVariables[2] = (Float)baset;
263 }
264 result = true;
265 break;
266 case (byte)OpCode.fstore_3:
267 baset = this.m_thread.m_currentFrame.OpStack.Pop();
268 if (baset is Float)
269 {
270 this.m_thread.m_currentFrame.LocalVariables[3] = (Float)baset;
271 }
272 result = true;
273 break;
274 case (byte)OpCode.pop:
275 this.m_thread.m_currentFrame.OpStack.Pop();
276 result = true;
277 break;
278 case (byte)OpCode.fadd:
279 BaseType bf2 = this.m_thread.m_currentFrame.OpStack.Pop();
280 BaseType bf1 = this.m_thread.m_currentFrame.OpStack.Pop();
281 if (bf1 is Float && bf2 is Float)
282 {
283 Float nflt = new Float();
284 nflt.mValue = ((Float)bf1).mValue + ((Float)bf2).mValue;
285 this.m_thread.m_currentFrame.OpStack.Push(nflt);
286 }
287 result = true;
288 break;
289 case (byte)OpCode.fsub:
290 BaseType bsf2 = this.m_thread.m_currentFrame.OpStack.Pop();
291 BaseType bsf1 = this.m_thread.m_currentFrame.OpStack.Pop();
292 if (bsf1 is Float && bsf2 is Float)
293 {
294 Float resf = new Float();
295 resf.mValue = ((Float)bsf1).mValue - ((Float)bsf2).mValue;
296 this.m_thread.m_currentFrame.OpStack.Push(resf);
297 }
298 result = true;
299 break;
300 case (byte)OpCode.imul: //check the order of the two values off the stack is correct
301 BaseType bs2 = this.m_thread.m_currentFrame.OpStack.Pop();
302 BaseType bs1 = this.m_thread.m_currentFrame.OpStack.Pop();
303 if (bs1 is Int && bs2 is Int)
304 {
305 Int nInt = new Int();
306 nInt.mValue = ((Int)bs1).mValue * ((Int)bs2).mValue;
307 this.m_thread.m_currentFrame.OpStack.Push(nInt);
308 }
309 result = true;
310 break;
311 case (byte)OpCode.iinc:
312 if (this.m_thread.m_currentFrame.LocalVariables[GlobalMemory.MethodArea.MethodBuffer[this.m_thread.PC]] != null)
313 {
314 if (this.m_thread.m_currentFrame.LocalVariables[GlobalMemory.MethodArea.MethodBuffer[this.m_thread.PC]] is Int)
315 {
316 ((Int)this.m_thread.m_currentFrame.LocalVariables[GlobalMemory.MethodArea.MethodBuffer[this.m_thread.PC]]).mValue += (sbyte)GlobalMemory.MethodArea.MethodBuffer[this.m_thread.PC + 1];
317 }
318 }
319 this.m_thread.PC += 2;
320 result = true;
321 break;
322 case (byte)OpCode.f2i:
323 BaseType conv1 = this.m_thread.m_currentFrame.OpStack.Pop();
324 if (conv1 is Float)
325 {
326 Int newconv = new Int();
327 newconv.mValue = (int)((Float)conv1).mValue;
328 this.m_thread.m_currentFrame.OpStack.Push(newconv);
329 }
330 result = true;
331 break;
332 case (byte)OpCode.fcmpl:
333 BaseType flcom2 = this.m_thread.m_currentFrame.OpStack.Pop();
334 BaseType flcom1 = this.m_thread.m_currentFrame.OpStack.Pop();
335 if (flcom1 is Float && flcom2 is Float)
336 {
337 Int compres = new Int();
338 if (((Float)flcom1).mValue < ((Float)flcom2).mValue)
339 {
340 compres.mValue = -1;
341 }
342 else if (((Float)flcom1).mValue > ((Float)flcom2).mValue)
343 {
344 compres.mValue = 1;
345 }
346 else
347 {
348 compres.mValue = 0;
349 }
350 this.m_thread.m_currentFrame.OpStack.Push(compres);
351 }
352 result = true;
353 break;
354 case (byte)OpCode.fcmpg:
355 flcom2 = this.m_thread.m_currentFrame.OpStack.Pop();
356 flcom1 = this.m_thread.m_currentFrame.OpStack.Pop();
357 if (flcom1 is Float && flcom2 is Float)
358 {
359 Int compres = new Int();
360 if (((Float)flcom1).mValue < ((Float)flcom2).mValue)
361 {
362 compres.mValue = -1;
363 }
364 else if (((Float)flcom1).mValue > ((Float)flcom2).mValue)
365 {
366 compres.mValue = 1;
367 }
368 else
369 {
370 compres.mValue = 0;
371 }
372 this.m_thread.m_currentFrame.OpStack.Push(compres);
373 }
374 result = true;
375 break;
376 case (byte)OpCode.ifge:
377 short compareoffset2 = (short)((GlobalMemory.MethodArea.MethodBuffer[this.m_thread.PC] << 8) + GlobalMemory.MethodArea.MethodBuffer[this.m_thread.PC + 1]);
378 BaseType compe1 = this.m_thread.m_currentFrame.OpStack.Pop();
379 if (compe1 is Int)
380 {
381 if (((Int)compe1).mValue >= 0)
382 {
383 this.m_thread.PC += -1 + compareoffset2;
384 }
385 else
386 {
387 this.m_thread.PC += 2;
388 }
389 }
390 else
391 {
392 this.m_thread.PC += 2;
393 }
394 result = true;
395 break;
396 case (byte)OpCode.ifle:
397 short compareoffset1 = (short)((GlobalMemory.MethodArea.MethodBuffer[this.m_thread.PC] << 8) + GlobalMemory.MethodArea.MethodBuffer[this.m_thread.PC + 1]);
398 BaseType comp1 = this.m_thread.m_currentFrame.OpStack.Pop();
399 if (comp1 is Int)
400 {
401 if (((Int)comp1).mValue <= 0)
402 {
403 this.m_thread.PC += -1 + compareoffset1;
404 }
405 else
406 {
407 this.m_thread.PC += 2;
408 }
409 }
410 else
411 {
412 this.m_thread.PC += 2;
413 }
414 result = true;
415 break;
416 case (byte)OpCode.if_icmpge:
417 short compareoffset = (short)((GlobalMemory.MethodArea.MethodBuffer[this.m_thread.PC] << 8) + GlobalMemory.MethodArea.MethodBuffer[this.m_thread.PC + 1]);
418 BaseType bc2 = this.m_thread.m_currentFrame.OpStack.Pop();
419 BaseType bc1 = this.m_thread.m_currentFrame.OpStack.Pop();
420 if (bc1 is Int && bc2 is Int)
421 {
422 //Console.WriteLine("comparing " + ((Int)bc1).mValue + " and " + ((Int)bc2).mValue);
423 if (((Int)bc1).mValue >= ((Int)bc2).mValue)
424 {
425 // Console.WriteLine("branch compare true , offset is " +compareoffset);
426 // Console.WriteLine("current PC is " + this._mThread.PC);
427 this.m_thread.PC += -1 + compareoffset;
428 //Console.WriteLine("new PC is " + this._mThread.PC);
429 }
430 else
431 {
432 //Console.WriteLine("branch compare false");
433 this.m_thread.PC += 2;
434 }
435 }
436 else
437 {
438 this.m_thread.PC += 2;
439 }
440 result = true;
441 break;
442 case (byte)OpCode.if_icmple:
443 short compareloffset = (short)((GlobalMemory.MethodArea.MethodBuffer[this.m_thread.PC] << 8) + GlobalMemory.MethodArea.MethodBuffer[this.m_thread.PC + 1]);
444 BaseType bcl2 = this.m_thread.m_currentFrame.OpStack.Pop();
445 BaseType bcl1 = this.m_thread.m_currentFrame.OpStack.Pop();
446 if (bcl1 is Int && bcl2 is Int)
447 {
448 //Console.WriteLine("comparing " + ((Int)bcl1).mValue + " and " + ((Int)bcl2).mValue);
449 if (((Int)bcl1).mValue <= ((Int)bcl2).mValue)
450 {
451 // Console.WriteLine("branch compare true , offset is " + compareloffset);
452 // Console.WriteLine("current PC is " + this._mThread.PC);
453 this.m_thread.PC += -1 + compareloffset;
454 // Console.WriteLine("new PC is " + this._mThread.PC);
455 }
456 else
457 {
458 //Console.WriteLine("branch compare false");
459 this.m_thread.PC += 2;
460 }
461 }
462 else
463 {
464 this.m_thread.PC += 2;
465 }
466 result = true;
467 break;
468 case (byte)OpCode._goto:
469 short offset = (short)((GlobalMemory.MethodArea.MethodBuffer[this.m_thread.PC] << 8) + GlobalMemory.MethodArea.MethodBuffer[this.m_thread.PC + 1]);
470 this.m_thread.PC += -1 + offset;
471 result = true;
472 break;
473 case (byte)OpCode.getstatic:
474 short fieldrefIndex = (short)((GlobalMemory.MethodArea.MethodBuffer[this.m_thread.PC] << 8) + GlobalMemory.MethodArea.MethodBuffer[this.m_thread.PC + 1]);
475 if (this.m_thread.currentClass.m_constantsPool[fieldrefIndex - 1] is ClassRecord.PoolFieldRef)
476 {
477 if (((ClassRecord.PoolFieldRef)this.m_thread.currentClass.m_constantsPool[fieldrefIndex - 1]).mClass.Name.Value == this.m_thread.currentClass.MClass.Name.Value)
478 {
479 //from this class
480 if (this.m_thread.currentClass.StaticFields.ContainsKey(((ClassRecord.PoolFieldRef)this.m_thread.currentClass.m_constantsPool[fieldrefIndex - 1]).mNameType.Name.Value))
481 {
482 if (this.m_thread.currentClass.StaticFields[((ClassRecord.PoolFieldRef)this.m_thread.currentClass.m_constantsPool[fieldrefIndex - 1]).mNameType.Name.Value] is Float)
483 {
484 Float retFloat = new Float();
485 retFloat.mValue = ((Float)this.m_thread.currentClass.StaticFields[((ClassRecord.PoolFieldRef)this.m_thread.currentClass.m_constantsPool[fieldrefIndex - 1]).mNameType.Name.Value]).mValue;
486 this.m_thread.m_currentFrame.OpStack.Push(retFloat);
487 }
488 else if (this.m_thread.currentClass.StaticFields[((ClassRecord.PoolFieldRef)this.m_thread.currentClass.m_constantsPool[fieldrefIndex - 1]).mNameType.Name.Value] is Int)
489 {
490 Int retInt = new Int();
491 retInt.mValue = ((Int)this.m_thread.currentClass.StaticFields[((ClassRecord.PoolFieldRef)this.m_thread.currentClass.m_constantsPool[fieldrefIndex - 1]).mNameType.Name.Value]).mValue;
492 // Console.WriteLine("getting static field, " + retInt.mValue);
493 this.m_thread.m_currentFrame.OpStack.Push(retInt);
494 }
495 }
496 }
497 else
498 {
499 //get from a different class
500 }
501 }
502 this.m_thread.PC += 2;
503 result = true;
504 break;
505 case (byte)OpCode.putstatic:
506 fieldrefIndex = (short)((GlobalMemory.MethodArea.MethodBuffer[this.m_thread.PC] << 8) + GlobalMemory.MethodArea.MethodBuffer[this.m_thread.PC + 1]);
507 BaseType addstatic = this.m_thread.m_currentFrame.OpStack.Pop();
508 if (this.m_thread.currentClass.m_constantsPool[fieldrefIndex - 1] is ClassRecord.PoolFieldRef)
509 {
510 if (((ClassRecord.PoolFieldRef)this.m_thread.currentClass.m_constantsPool[fieldrefIndex - 1]).mClass.Name.Value == this.m_thread.currentClass.MClass.Name.Value)
511 {
512 // this class
513 if (this.m_thread.currentClass.StaticFields.ContainsKey(((ClassRecord.PoolFieldRef)this.m_thread.currentClass.m_constantsPool[fieldrefIndex - 1]).mNameType.Name.Value))
514 {
515 if (addstatic is Float)
516 {
517 if (this.m_thread.currentClass.StaticFields[((ClassRecord.PoolFieldRef)this.m_thread.currentClass.m_constantsPool[fieldrefIndex - 1]).mNameType.Name.Value] is Float)
518 {
519 Float newf = new Float();
520 newf.mValue = ((Float)addstatic).mValue;
521 this.m_thread.currentClass.StaticFields[((ClassRecord.PoolFieldRef)this.m_thread.currentClass.m_constantsPool[fieldrefIndex - 1]).mNameType.Name.Value] = newf;
522 }
523 }
524 else if (addstatic is Int)
525 {
526 if (this.m_thread.currentClass.StaticFields[((ClassRecord.PoolFieldRef)this.m_thread.currentClass.m_constantsPool[fieldrefIndex - 1]).mNameType.Name.Value] is Int)
527 {
528 //Console.WriteLine("setting static field to " + ((Int)addstatic).mValue);
529 Int newi = new Int();
530 newi.mValue = ((Int)addstatic).mValue;
531 this.m_thread.currentClass.StaticFields[((ClassRecord.PoolFieldRef)this.m_thread.currentClass.m_constantsPool[fieldrefIndex - 1]).mNameType.Name.Value] = newi;
532 }
533 }
534 }
535 }
536 else
537 {
538 // a different class
539 }
540 }
541 this.m_thread.PC += 2;
542 result = true;
543 break;
544
545 }
546
547 return result;
548 }
549 }
550 }
551} \ No newline at end of file
diff --git a/OpenSim/Region/Environment/Scenes/_scripting/Engines/JVMEngine/JVM/Interpreter.Methods.cs b/OpenSim/Region/Environment/Scenes/_scripting/Engines/JVMEngine/JVM/Interpreter.Methods.cs
new file mode 100644
index 0000000..42fd299
--- /dev/null
+++ b/OpenSim/Region/Environment/Scenes/_scripting/Engines/JVMEngine/JVM/Interpreter.Methods.cs
@@ -0,0 +1,96 @@
1/*
2* Copyright (c) Contributors, http://www.openmetaverse.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders.
4*
5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met:
7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission.
15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*
27*/
28using System;
29using System.Collections.Generic;
30using System.Text;
31using OpenSim.Region.Scripting.EmbeddedJVM.Types;
32using OpenSim.Region.Scripting.EmbeddedJVM.Types.PrimitiveTypes;
33using OpenSim.Framework.Interfaces;
34using OpenSim.Framework;
35using OpenSim.Framework.Types;
36
37namespace OpenSim.Region.Scripting.EmbeddedJVM
38{
39 partial class Thread
40 {
41 private partial class Interpreter
42 {
43 private bool IsMethodOpCode(byte opcode)
44 {
45 bool result = false;
46 switch (opcode)
47 {
48 case 184:
49 short refIndex = (short) ((GlobalMemory.MethodArea.MethodBuffer[this.m_thread.PC] << 8) + GlobalMemory.MethodArea.MethodBuffer[this.m_thread.PC+1]);
50 if (this.m_thread.currentClass.m_constantsPool[refIndex - 1] is ClassRecord.PoolMethodRef)
51 {
52 string typ = ((ClassRecord.PoolMethodRef)this.m_thread.currentClass.m_constantsPool[refIndex - 1]).mNameType.Type.Value;
53 string typeparam = "";
54 string typereturn = "";
55 int firstbrak = 0;
56 int secondbrak = 0;
57 firstbrak = typ.LastIndexOf('(');
58 secondbrak = typ.LastIndexOf(')');
59 typeparam = typ.Substring(firstbrak + 1, secondbrak - firstbrak - 1);
60 typereturn = typ.Substring(secondbrak + 1, typ.Length - secondbrak - 1);
61 if (((ClassRecord.PoolMethodRef)this.m_thread.currentClass.m_constantsPool[refIndex - 1]).mClass.Name.Value == this.m_thread.currentClass.MClass.Name.Value)
62 {
63 //calling a method in this class
64 if (typeparam.Length == 0)
65 {
66 this.m_thread.JumpToStaticVoidMethod(((ClassRecord.PoolMethodRef)this.m_thread.currentClass.m_constantsPool[refIndex - 1]).mNameType.Name.Value, (this.m_thread.PC + 2));
67 }
68 else
69 {
70 this.m_thread.JumpToStaticParamMethod(((ClassRecord.PoolMethodRef)this.m_thread.currentClass.m_constantsPool[refIndex - 1]).mNameType.Name.Value, typeparam, (this.m_thread.PC + 2));
71 }
72 }
73 else
74 {
75 //calling a method of a different class
76
77 // OpenSimAPI Class
78 if (((ClassRecord.PoolMethodRef)this.m_thread.currentClass.m_constantsPool[refIndex - 1]).mClass.Name.Value == "OpenSimAPI")
79 {
80 this.m_thread.scriptInfo.api.CallMethod(((ClassRecord.PoolMethodRef)this.m_thread.currentClass.m_constantsPool[refIndex - 1]).mNameType.Name.Value, null);
81 }
82 }
83 }
84 else
85 {
86 this.m_thread.PC += 2;
87 }
88 result = true;
89 break;
90 }
91
92 return result;
93 }
94 }
95 }
96}
diff --git a/OpenSim/Region/Environment/Scenes/_scripting/Engines/JVMEngine/JVM/Interpreter.Return.cs b/OpenSim/Region/Environment/Scenes/_scripting/Engines/JVMEngine/JVM/Interpreter.Return.cs
new file mode 100644
index 0000000..3c18a11
--- /dev/null
+++ b/OpenSim/Region/Environment/Scenes/_scripting/Engines/JVMEngine/JVM/Interpreter.Return.cs
@@ -0,0 +1,40 @@
1/*
2* Copyright (c) Contributors, http://www.openmetaverse.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders.
4*
5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met:
7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission.
15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*
27*/
28using System;
29using System.Collections.Generic;
30using System.Text;
31
32namespace OpenSim.Region.Scripting.EmbeddedJVM
33{
34 partial class Thread
35 {
36 private partial class Interpreter
37 {
38 }
39 }
40}
diff --git a/OpenSim/Region/Environment/Scenes/_scripting/Engines/JVMEngine/JVM/Interpreter.cs b/OpenSim/Region/Environment/Scenes/_scripting/Engines/JVMEngine/JVM/Interpreter.cs
new file mode 100644
index 0000000..e718328
--- /dev/null
+++ b/OpenSim/Region/Environment/Scenes/_scripting/Engines/JVMEngine/JVM/Interpreter.cs
@@ -0,0 +1,135 @@
1/*
2* Copyright (c) Contributors, http://www.openmetaverse.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders.
4*
5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met:
7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission.
15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*
27*/
28using System;
29using System.Collections.Generic;
30using System.Text;
31using OpenSim.Region.Scripting.EmbeddedJVM.Types;
32using OpenSim.Region.Scripting.EmbeddedJVM.Types.PrimitiveTypes;
33
34namespace OpenSim.Region.Scripting.EmbeddedJVM
35{
36 partial class Thread
37 {
38 private partial class Interpreter
39 {
40 private Thread m_thread;
41
42 public Interpreter(Thread parentThread)
43 {
44 m_thread = parentThread;
45 }
46
47 public bool Excute()
48 {
49 bool run = true;
50 byte currentOpCode = GlobalMemory.MethodArea.MethodBuffer[this.m_thread.PC++];
51 // Console.WriteLine("opCode is: " + currentOpCode);
52 bool handled = false;
53
54 handled = this.IsLogicOpCode(currentOpCode);
55 if (!handled)
56 {
57 handled = this.IsMethodOpCode(currentOpCode);
58 }
59 if (!handled)
60 {
61 if (currentOpCode == 172)
62 {
63 if (this.m_thread.stack.StackFrames.Count > 1)
64 {
65 Console.WriteLine("returning int from function");
66 int retPC1 = this.m_thread.m_currentFrame.ReturnPC;
67 BaseType bas1 = this.m_thread.m_currentFrame.OpStack.Pop();
68 this.m_thread.stack.StackFrames.Pop();
69 this.m_thread.m_currentFrame = this.m_thread.stack.StackFrames.Peek();
70 this.m_thread.PC = retPC1;
71 if (bas1 is Int)
72 {
73 this.m_thread.m_currentFrame.OpStack.Push((Int)bas1);
74 }
75 }
76 else
77 {
78 // Console.WriteLine("No parent function so ending program");
79 this.m_thread.stack.StackFrames.Pop();
80 run = false;
81 }
82 handled = true;
83 }
84 if (currentOpCode == 174)
85 {
86 if (this.m_thread.stack.StackFrames.Count > 1)
87 {
88 Console.WriteLine("returning float from function");
89 int retPC1 = this.m_thread.m_currentFrame.ReturnPC;
90 BaseType bas1 = this.m_thread.m_currentFrame.OpStack.Pop();
91 this.m_thread.stack.StackFrames.Pop();
92 this.m_thread.m_currentFrame = this.m_thread.stack.StackFrames.Peek();
93 this.m_thread.PC = retPC1;
94 if (bas1 is Float)
95 {
96 this.m_thread.m_currentFrame.OpStack.Push((Float)bas1);
97 }
98 }
99 else
100 {
101 // Console.WriteLine("No parent function so ending program");
102 this.m_thread.stack.StackFrames.Pop();
103 run = false;
104 }
105 handled = true;
106 }
107 if (currentOpCode == 177)
108 {
109 if (this.m_thread.stack.StackFrames.Count > 1)
110 {
111 Console.WriteLine("returning from function");
112 int retPC = this.m_thread.m_currentFrame.ReturnPC;
113 this.m_thread.stack.StackFrames.Pop();
114 this.m_thread.m_currentFrame = this.m_thread.stack.StackFrames.Peek();
115 this.m_thread.PC = retPC;
116 }
117 else
118 {
119 // Console.WriteLine("No parent function so ending program");
120 this.m_thread.stack.StackFrames.Pop();
121 run = false;
122 }
123 handled = true;
124 }
125 }
126 if (!handled)
127 {
128 Console.WriteLine("opcode " + currentOpCode + " not been handled ");
129 }
130 return run;
131
132 }
133 }
134 }
135}
diff --git a/OpenSim/Region/Environment/Scenes/_scripting/Engines/JVMEngine/JVM/MainMemory.cs b/OpenSim/Region/Environment/Scenes/_scripting/Engines/JVMEngine/JVM/MainMemory.cs
new file mode 100644
index 0000000..7174975
--- /dev/null
+++ b/OpenSim/Region/Environment/Scenes/_scripting/Engines/JVMEngine/JVM/MainMemory.cs
@@ -0,0 +1,45 @@
1/*
2* Copyright (c) Contributors, http://www.openmetaverse.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders.
4*
5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met:
7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission.
15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*
27*/
28using System;
29using System.Collections.Generic;
30using System.Text;
31
32namespace OpenSim.Region.Scripting.EmbeddedJVM
33{
34 public class MainMemory
35 {
36 public Heap HeapArea;
37 public MethodMemory MethodArea;
38
39 public MainMemory()
40 {
41 MethodArea = new MethodMemory();
42 HeapArea = new Heap();
43 }
44 }
45}
diff --git a/OpenSim/Region/Environment/Scenes/_scripting/Engines/JVMEngine/JVM/MethodMemory.cs b/OpenSim/Region/Environment/Scenes/_scripting/Engines/JVMEngine/JVM/MethodMemory.cs
new file mode 100644
index 0000000..5f29091
--- /dev/null
+++ b/OpenSim/Region/Environment/Scenes/_scripting/Engines/JVMEngine/JVM/MethodMemory.cs
@@ -0,0 +1,46 @@
1/*
2* Copyright (c) Contributors, http://www.openmetaverse.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders.
4*
5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met:
7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission.
15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*
27*/
28using System;
29using System.Collections.Generic;
30using System.Text;
31
32namespace OpenSim.Region.Scripting.EmbeddedJVM
33{
34 public class MethodMemory
35 {
36 public byte[] MethodBuffer;
37 public List<ClassRecord> Classes = new List<ClassRecord>();
38 public int NextMethodPC = 0;
39 public int Methodcount = 0;
40
41 public MethodMemory()
42 {
43 MethodBuffer = new byte[20000];
44 }
45 }
46}
diff --git a/OpenSim/Region/Environment/Scenes/_scripting/Engines/JVMEngine/JVM/Object.cs b/OpenSim/Region/Environment/Scenes/_scripting/Engines/JVMEngine/JVM/Object.cs
new file mode 100644
index 0000000..8acb2bd
--- /dev/null
+++ b/OpenSim/Region/Environment/Scenes/_scripting/Engines/JVMEngine/JVM/Object.cs
@@ -0,0 +1,37 @@
1/*
2* Copyright (c) Contributors, http://www.openmetaverse.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders.
4*
5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met:
7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission.
15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*
27*/
28using System;
29using System.Collections.Generic;
30using System.Text;
31
32namespace OpenSim.Region.Scripting.EmbeddedJVM
33{
34 public class Object
35 {
36 }
37}
diff --git a/OpenSim/Region/Environment/Scenes/_scripting/Engines/JVMEngine/JVM/OpCodes.cs b/OpenSim/Region/Environment/Scenes/_scripting/Engines/JVMEngine/JVM/OpCodes.cs
new file mode 100644
index 0000000..22a9f12
--- /dev/null
+++ b/OpenSim/Region/Environment/Scenes/_scripting/Engines/JVMEngine/JVM/OpCodes.cs
@@ -0,0 +1,56 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4
5namespace OpenSim.Region.Scripting.EmbeddedJVM
6{
7 public enum OpCode : byte
8 {
9 iconst_m1 = 2,
10 iconst_0 = 3,
11 iconst_1 = 4,
12 iconst_2 = 5,
13 iconst_3 = 6,
14 iconst_4 = 7,
15 iconst_5 = 8,
16 fconst_0 = 11,
17 fconst_1 = 12,
18 fconst_2 = 13,
19 bipush = 16,
20 sipush = 17,
21 fload = 23,
22 iload_0 = 26,
23 iload_1 = 27,
24 fload_0 = 34,
25 fload_1 = 35,
26 fload_2 = 36,
27 fload_3 = 37,
28 istore = 54,
29 fstore = 56,
30 istore_0 = 59,
31 istore_1 = 60,
32 istore_2 = 61,
33 istore_3 = 62,
34 fstore_0 = 67,
35 fstore_1 = 68,
36 fstore_2 = 69,
37 fstore_3 = 70,
38 pop = 87,
39 fadd = 98,
40 fsub = 102,
41 imul = 104,
42 iinc = 132,
43 f2i = 139,
44 fcmpl = 149,
45 fcmpg = 150,
46 ifge = 156,
47 ifgt = 157,
48 ifle = 158,
49 if_icmpge = 162,
50 if_icmpgt = 163,
51 if_icmple = 164,
52 _goto = 167,
53 getstatic = 178,
54 putstatic = 179
55 }
56}
diff --git a/OpenSim/Region/Environment/Scenes/_scripting/Engines/JVMEngine/JVM/Stack.cs b/OpenSim/Region/Environment/Scenes/_scripting/Engines/JVMEngine/JVM/Stack.cs
new file mode 100644
index 0000000..7c12678
--- /dev/null
+++ b/OpenSim/Region/Environment/Scenes/_scripting/Engines/JVMEngine/JVM/Stack.cs
@@ -0,0 +1,42 @@
1/*
2* Copyright (c) Contributors, http://www.openmetaverse.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders.
4*
5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met:
7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission.
15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*
27*/
28using System;
29using System.Collections.Generic;
30using System.Text;
31
32namespace OpenSim.Region.Scripting.EmbeddedJVM
33{
34 public class Stack
35 {
36 public Stack<StackFrame> StackFrames = new Stack<StackFrame>();
37
38 public Stack()
39 {
40 }
41 }
42}
diff --git a/OpenSim/Region/Environment/Scenes/_scripting/Engines/JVMEngine/JVM/StackFrame.cs b/OpenSim/Region/Environment/Scenes/_scripting/Engines/JVMEngine/JVM/StackFrame.cs
new file mode 100644
index 0000000..76257b8
--- /dev/null
+++ b/OpenSim/Region/Environment/Scenes/_scripting/Engines/JVMEngine/JVM/StackFrame.cs
@@ -0,0 +1,49 @@
1/*
2* Copyright (c) Contributors, http://www.openmetaverse.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders.
4*
5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met:
7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission.
15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*
27*/
28using System;
29using System.Collections.Generic;
30using System.Text;
31using OpenSim.Region.Scripting.EmbeddedJVM.Types;
32
33namespace OpenSim.Region.Scripting.EmbeddedJVM
34{
35 public class StackFrame
36 {
37 public BaseType[] LocalVariables;
38 public Stack<BaseType> OpStack = new Stack<BaseType>();
39
40 public int ReturnPC = 0;
41 public ClassRecord CallingClass = null;
42
43 public StackFrame()
44 {
45 LocalVariables = new BaseType[20];
46 }
47
48 }
49}
diff --git a/OpenSim/Region/Environment/Scenes/_scripting/Engines/JVMEngine/JVM/Thread.cs b/OpenSim/Region/Environment/Scenes/_scripting/Engines/JVMEngine/JVM/Thread.cs
new file mode 100644
index 0000000..aad1f47
--- /dev/null
+++ b/OpenSim/Region/Environment/Scenes/_scripting/Engines/JVMEngine/JVM/Thread.cs
@@ -0,0 +1,119 @@
1/*
2* Copyright (c) Contributors, http://www.openmetaverse.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders.
4*
5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met:
7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission.
15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*
27*/
28using System;
29using System.Collections.Generic;
30using System.Text;
31using OpenSim.Region.Scripting.EmbeddedJVM.Types;
32using OpenSim.Region.Scripting.EmbeddedJVM.Types.PrimitiveTypes;
33using OpenSim.Framework;
34using OpenSim.Framework.Interfaces;
35using OpenSim.Region.Environment.Scenes;
36using OpenSim.Region.Scripting;
37
38namespace OpenSim.Region.Scripting.EmbeddedJVM
39{
40 public partial class Thread
41 {
42 // Is this smart?
43 public static MainMemory GlobalMemory;
44 public static Scene World;
45 private int PC = 0;
46 private Stack stack;
47 private Interpreter m_Interpreter;
48 public ClassRecord currentClass;
49 public ClassInstance currentInstance;
50 private StackFrame m_currentFrame;
51 public int excutionCounter = 0;
52 public bool running = false;
53
54 public ScriptInfo scriptInfo;
55
56 public Thread()
57 {
58 this.m_Interpreter = new Interpreter(this);
59 this.stack = new Stack();
60 }
61
62 public void SetPC(int methodpointer)
63 {
64 //Console.WriteLine("Thread PC has been set to " + methodpointer);
65 PC = methodpointer;
66 }
67
68 public void StartMethod(ClassRecord rec, string methName)
69 {
70 m_currentFrame = new StackFrame();
71 this.stack.StackFrames.Push(m_currentFrame);
72 this.currentClass = rec;
73 currentClass.StartMethod(this, methName);
74 }
75
76 public void StartMethod( string methName)
77 {
78 m_currentFrame = new StackFrame();
79 this.stack.StackFrames.Push(m_currentFrame);
80 currentClass.StartMethod(this, methName);
81 }
82
83 public void JumpToStaticVoidMethod(string methName, int returnPC)
84 {
85 m_currentFrame = new StackFrame();
86 m_currentFrame.ReturnPC = returnPC;
87 this.stack.StackFrames.Push(m_currentFrame);
88 currentClass.StartMethod(this, methName);
89 }
90
91 public void JumpToStaticParamMethod(string methName, string param, int returnPC)
92 {
93 if (param == "I")
94 {
95 BaseType bs1 = m_currentFrame.OpStack.Pop();
96 m_currentFrame = new StackFrame();
97 m_currentFrame.ReturnPC = returnPC;
98 this.stack.StackFrames.Push(m_currentFrame);
99 m_currentFrame.LocalVariables[0] = ((Int)bs1);
100 currentClass.StartMethod(this, methName);
101 }
102 if (param == "F")
103 {
104
105 }
106 }
107
108 public void JumpToClassStaticVoidMethod(string className, string methName, int returnPC)
109 {
110
111 }
112
113 public bool Excute()
114 {
115 excutionCounter++;
116 return this.m_Interpreter.Excute();
117 }
118 }
119}
diff --git a/OpenSim/Region/Environment/Scenes/_scripting/Engines/JVMEngine/JavaEngine.cs b/OpenSim/Region/Environment/Scenes/_scripting/Engines/JVMEngine/JavaEngine.cs
new file mode 100644
index 0000000..58cdf49
--- /dev/null
+++ b/OpenSim/Region/Environment/Scenes/_scripting/Engines/JVMEngine/JavaEngine.cs
@@ -0,0 +1,29 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4
5using OpenSim.Region.Scripting;
6using OpenSim.Region.Scripting.EmbeddedJVM;
7
8namespace OpenSim.Region.Scripting
9{
10 public class JavaEngine : IScriptCompiler
11 {
12 public string FileExt()
13 {
14 return ".java";
15 }
16
17 public Dictionary<string, IScript> compile(string filename)
18 {
19 JVMScript script = new JVMScript();
20 Dictionary<string, IScript> returns = new Dictionary<string, IScript>();
21
22 script.LoadScript(filename);
23
24 returns.Add(filename, script);
25
26 return returns;
27 }
28 }
29}
diff --git a/OpenSim/Region/Environment/Scenes/_scripting/Engines/JVMEngine/OpenSimJVM.cs b/OpenSim/Region/Environment/Scenes/_scripting/Engines/JVMEngine/OpenSimJVM.cs
new file mode 100644
index 0000000..78c6f67
--- /dev/null
+++ b/OpenSim/Region/Environment/Scenes/_scripting/Engines/JVMEngine/OpenSimJVM.cs
@@ -0,0 +1,170 @@
1/*
2* Copyright (c) Contributors, http://www.openmetaverse.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders.
4*
5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met:
7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission.
15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*
27*/
28using System;
29using System.Collections.Generic;
30using System.Text;
31using System.IO;
32using System.Threading;
33using OpenSim.Framework;
34using OpenSim.Framework.Interfaces;
35using OpenSim.Framework.Utilities;
36using OpenSim.Region.Scripting;
37using OpenSim.Region.Environment.Scenes;
38
39namespace OpenSim.Region.Scripting.EmbeddedJVM
40{
41 public class JVMScript : IScript
42 {
43 private List<Thread> _threads = new List<Thread>();
44 private BlockingQueue<CompileInfo> CompileScripts = new BlockingQueue<CompileInfo>();
45 private MainMemory _mainMemory;
46
47 ScriptInfo scriptInfo;
48
49 public void Initialise(ScriptInfo info)
50 {
51 scriptInfo = info;
52
53 _mainMemory = new MainMemory();
54 Thread.GlobalMemory = this._mainMemory;
55 Thread.World = info.world;
56 CompileScript();
57
58 scriptInfo.events.OnFrame += new EventManager.OnFrameDelegate(events_OnFrame);
59 scriptInfo.events.OnNewPresence += new EventManager.OnNewPresenceDelegate(events_OnNewPresence);
60 }
61
62 void events_OnNewPresence(ScenePresence presence)
63 {
64 for (int i = 0; i < this._threads.Count; i++)
65 {
66 if (!this._threads[i].running)
67 {
68 this._threads[i].StartMethod("OnNewPresence");
69 bool run = true;
70 while (run)
71 {
72 run = this._threads[i].Excute();
73 }
74 }
75 }
76 }
77
78 void events_OnFrame()
79 {
80 for (int i = 0; i < this._threads.Count; i++)
81 {
82 if (!this._threads[i].running)
83 {
84 this._threads[i].StartMethod("OnFrame");
85 bool run = true;
86 while (run)
87 {
88 run = this._threads[i].Excute();
89 }
90 }
91 }
92 }
93
94 public string getName()
95 {
96 return "JVM Scripting Engine";
97 }
98
99 public void LoadScript(string script)
100 {
101 Console.WriteLine("OpenSimJVM - loading new script: " + script);
102 CompileInfo comp = new CompileInfo();
103 comp.script = script;
104 comp.scriptName = script;
105 this.CompileScripts.Enqueue(comp);
106 }
107
108 public void CompileScript()
109 {
110 CompileInfo comp = this.CompileScripts.Dequeue();
111 string script = comp.script;
112 string scriptName = comp.scriptName;
113 try
114 {
115 //need to compile the script into a java class file
116
117 //first save it to a java source file
118 TextWriter tw = new StreamWriter(scriptName + ".java");
119 tw.WriteLine(script);
120 tw.Close();
121
122 //now compile
123 System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo("javac.exe", "*.java");
124 // psi.RedirectStandardOutput = true;
125 psi.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
126 psi.UseShellExecute = false;
127
128 System.Diagnostics.Process javacomp;
129 javacomp = System.Diagnostics.Process.Start(psi);
130 javacomp.WaitForExit();
131
132
133 //now load in class file
134 ClassRecord class1 = new ClassRecord();
135 class1.LoadClassFromFile(scriptName + ".class");
136 class1.PrintToConsole();
137 //Console.WriteLine();
138 this._mainMemory.MethodArea.Classes.Add(class1);
139 class1.AddMethodsToMemory(this._mainMemory.MethodArea);
140
141 Thread newThread = new Thread();
142 this._threads.Add(newThread);
143 newThread.currentClass = class1;
144 newThread.scriptInfo = scriptInfo;
145
146 //now delete the created files
147 System.IO.File.Delete(scriptName + ".java");
148 System.IO.File.Delete(scriptName + ".class");
149 //this.OnFrame();
150 }
151 catch (Exception e)
152 {
153 Console.WriteLine("exception");
154 Console.WriteLine(e.StackTrace);
155 Console.WriteLine(e.Message);
156 }
157 }
158
159 private class CompileInfo
160 {
161 public string script;
162 public string scriptName;
163
164 public CompileInfo()
165 {
166
167 }
168 }
169 }
170}
diff --git a/OpenSim/Region/Environment/Scenes/_scripting/Engines/JVMEngine/Types/ArrayReference.cs b/OpenSim/Region/Environment/Scenes/_scripting/Engines/JVMEngine/Types/ArrayReference.cs
new file mode 100644
index 0000000..0c4d623
--- /dev/null
+++ b/OpenSim/Region/Environment/Scenes/_scripting/Engines/JVMEngine/Types/ArrayReference.cs
@@ -0,0 +1,10 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4
5namespace OpenSim.Region.Scripting.EmbeddedJVM.Types
6{
7 public class ArrayReference :BaseType
8 {
9 }
10}
diff --git a/OpenSim/Region/Environment/Scenes/_scripting/Engines/JVMEngine/Types/BaseType.cs b/OpenSim/Region/Environment/Scenes/_scripting/Engines/JVMEngine/Types/BaseType.cs
new file mode 100644
index 0000000..7fc0a4f
--- /dev/null
+++ b/OpenSim/Region/Environment/Scenes/_scripting/Engines/JVMEngine/Types/BaseType.cs
@@ -0,0 +1,10 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4
5namespace OpenSim.Region.Scripting.EmbeddedJVM.Types
6{
7 public class BaseType : Object
8 {
9 }
10}
diff --git a/OpenSim/Region/Environment/Scenes/_scripting/Engines/JVMEngine/Types/ObjectReference.cs b/OpenSim/Region/Environment/Scenes/_scripting/Engines/JVMEngine/Types/ObjectReference.cs
new file mode 100644
index 0000000..7718765
--- /dev/null
+++ b/OpenSim/Region/Environment/Scenes/_scripting/Engines/JVMEngine/Types/ObjectReference.cs
@@ -0,0 +1,16 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4
5namespace OpenSim.Region.Scripting.EmbeddedJVM.Types
6{
7 public class ObjectReference : BaseType
8 {
9 public ushort Reference;
10
11 public ObjectReference()
12 {
13
14 }
15 }
16}
diff --git a/OpenSim/Region/Environment/Scenes/_scripting/Engines/JVMEngine/Types/PrimitiveTypes/Byte.cs b/OpenSim/Region/Environment/Scenes/_scripting/Engines/JVMEngine/Types/PrimitiveTypes/Byte.cs
new file mode 100644
index 0000000..5a7b780
--- /dev/null
+++ b/OpenSim/Region/Environment/Scenes/_scripting/Engines/JVMEngine/Types/PrimitiveTypes/Byte.cs
@@ -0,0 +1,10 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4
5namespace OpenSim.Region.Scripting.EmbeddedJVM.Types.PrimitiveTypes
6{
7 public class Byte : BaseType
8 {
9 }
10}
diff --git a/OpenSim/Region/Environment/Scenes/_scripting/Engines/JVMEngine/Types/PrimitiveTypes/Char.cs b/OpenSim/Region/Environment/Scenes/_scripting/Engines/JVMEngine/Types/PrimitiveTypes/Char.cs
new file mode 100644
index 0000000..c87ee8f
--- /dev/null
+++ b/OpenSim/Region/Environment/Scenes/_scripting/Engines/JVMEngine/Types/PrimitiveTypes/Char.cs
@@ -0,0 +1,10 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4
5namespace OpenSim.Region.Scripting.EmbeddedJVM.Types.PrimitiveTypes
6{
7 public class Char : BaseType
8 {
9 }
10}
diff --git a/OpenSim/Region/Environment/Scenes/_scripting/Engines/JVMEngine/Types/PrimitiveTypes/Float.cs b/OpenSim/Region/Environment/Scenes/_scripting/Engines/JVMEngine/Types/PrimitiveTypes/Float.cs
new file mode 100644
index 0000000..982e748
--- /dev/null
+++ b/OpenSim/Region/Environment/Scenes/_scripting/Engines/JVMEngine/Types/PrimitiveTypes/Float.cs
@@ -0,0 +1,16 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4
5namespace OpenSim.Region.Scripting.EmbeddedJVM.Types.PrimitiveTypes
6{
7 public class Float : BaseType
8 {
9 public float mValue = 0;
10
11 public Float()
12 {
13
14 }
15 }
16}
diff --git a/OpenSim/Region/Environment/Scenes/_scripting/Engines/JVMEngine/Types/PrimitiveTypes/Int.cs b/OpenSim/Region/Environment/Scenes/_scripting/Engines/JVMEngine/Types/PrimitiveTypes/Int.cs
new file mode 100644
index 0000000..073a9b3
--- /dev/null
+++ b/OpenSim/Region/Environment/Scenes/_scripting/Engines/JVMEngine/Types/PrimitiveTypes/Int.cs
@@ -0,0 +1,16 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4
5namespace OpenSim.Region.Scripting.EmbeddedJVM.Types.PrimitiveTypes
6{
7 public class Int : BaseType
8 {
9 public int mValue = 0;
10
11 public Int()
12 {
13
14 }
15 }
16}
diff --git a/OpenSim/Region/Environment/Scenes/_scripting/Engines/LSLEngine/LSLHandler/Common.cs b/OpenSim/Region/Environment/Scenes/_scripting/Engines/LSLEngine/LSLHandler/Common.cs
new file mode 100644
index 0000000..554ba1a
--- /dev/null
+++ b/OpenSim/Region/Environment/Scenes/_scripting/Engines/LSLEngine/LSLHandler/Common.cs
@@ -0,0 +1,84 @@
1/*
2* Copyright (c) Contributors, http://www.openmetaverse.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders.
4*
5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met:
7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission.
15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*
27*/
28/* Original code: Tedd Hansen */
29using System;
30using System.Collections.Generic;
31using System.Text;
32
33namespace OpenSim.Region.Scripting.LSL
34{
35 public static class Common
36 {
37 static public bool Debug = true;
38 static public bool IL_UseTryCatch = true;
39 static public bool IL_CreateConstructor = true;
40 static public bool IL_CreateFunctionList = true;
41 static public bool IL_ProcessCodeChunks = true;
42
43 public delegate void SendToDebugEventDelegate(string Message);
44 public delegate void SendToLogEventDelegate(string Message);
45 static public event SendToDebugEventDelegate SendToDebugEvent;
46 static public event SendToLogEventDelegate SendToLogEvent;
47
48 static public void SendToDebug(string Message)
49 {
50 //if (Debug == true)
51 Console.WriteLine("Debug: " + Message);
52 SendToDebugEvent(DateTime.Now.ToString("[HH:mm:ss] ") + Message + "\r\n");
53 }
54 static public void SendToLog(string Message)
55 {
56 //if (Debug == true)
57 Console.WriteLine("LOG: " + Message);
58 SendToLogEvent(DateTime.Now.ToString("[HH:mm:ss] ") + Message + "\r\n");
59 }
60 }
61
62 // TEMPORARY TEST THINGIES
63 public static class IL_Helper
64 {
65 public static string ReverseFormatString(string text1, string format)
66 {
67 Common.SendToDebug("ReverseFormatString text1: " + text1);
68 Common.SendToDebug("ReverseFormatString format: " + format);
69 return string.Format(format, text1);
70 }
71 public static string ReverseFormatString(string text1, UInt32 text2, string format)
72 {
73 Common.SendToDebug("ReverseFormatString text1: " + text1);
74 Common.SendToDebug("ReverseFormatString text2: " + text2.ToString());
75 Common.SendToDebug("ReverseFormatString format: " + format);
76 return string.Format(format, text1, text2.ToString());
77 }
78 public static string Cast_ToString(object obj)
79 {
80 Common.SendToDebug("OBJECT TO BE CASTED: " + obj.GetType().ToString());
81 return "ABCDEFGIHJKLMNOPQ123";
82 }
83 }
84}
diff --git a/OpenSim/Region/Environment/Scenes/_scripting/Engines/LSLEngine/LSLHandler/Engine.cs b/OpenSim/Region/Environment/Scenes/_scripting/Engines/LSLEngine/LSLHandler/Engine.cs
new file mode 100644
index 0000000..5cd1f71
--- /dev/null
+++ b/OpenSim/Region/Environment/Scenes/_scripting/Engines/LSLEngine/LSLHandler/Engine.cs
@@ -0,0 +1,228 @@
1/*
2* Copyright (c) Contributors, http://www.openmetaverse.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders.
4*
5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met:
7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission.
15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*
27*/
28/* Original code: Tedd Hansen */
29using System;
30 using System.Reflection;
31 using System.Reflection.Emit;
32 using System.Threading;
33
34 namespace OpenSim.Region.Scripting.LSL
35 {
36
37
38 public class Engine
39 {
40 //private string LSO_FileName = @"LSO\AdditionTest.lso";
41 private string LSO_FileName;// = @"LSO\CloseToDefault.lso";
42 AppDomain appDomain;
43
44 public void Start(string FileName)
45 {
46 LSO_FileName = FileName;
47
48
49 //appDomain = AppDomain.CreateDomain("AlternateAppDomain");
50 appDomain = Thread.GetDomain();
51
52 // Create Assembly Name
53 AssemblyName asmName = new AssemblyName();
54 asmName.Name = System.IO.Path.GetFileNameWithoutExtension(LSO_FileName);
55 //asmName.Name = "TestAssembly";
56
57 string DLL_FileName = asmName.Name + ".dll";
58 string DLL_FileName_WithPath = System.IO.Path.GetDirectoryName(FileName) + @"\" + DLL_FileName;
59
60 Common.SendToLog("LSO File Name: " + System.IO.Path.GetFileName(FileName));
61 Common.SendToLog("Assembly name: " + asmName.Name);
62 Common.SendToLog("Assembly File Name: " + asmName.Name + ".dll");
63 Common.SendToLog("Starting processing of LSL ByteCode...");
64 Common.SendToLog("");
65
66
67
68 // Create Assembly
69 AssemblyBuilder asmBuilder = appDomain.DefineDynamicAssembly(
70 asmName,
71 AssemblyBuilderAccess.RunAndSave
72 );
73 //// Create Assembly
74 //AssemblyBuilder asmBuilder =
75 // Thread.GetDomain().DefineDynamicAssembly
76 //(asmName, AssemblyBuilderAccess.RunAndSave);
77
78 // Create a module (and save to disk)
79 ModuleBuilder modBuilder = asmBuilder.DefineDynamicModule
80 (asmName.Name,
81 DLL_FileName);
82
83 //Common.SendToDebug("asmName.Name is still \"" + asmName.Name + "\"");
84 // Create a Class (/Type)
85 TypeBuilder typeBuilder = modBuilder.DefineType(
86 "LSL_ScriptObject",
87 TypeAttributes.Public | TypeAttributes.BeforeFieldInit);
88 //,
89 // typeof());
90 //, typeof(LSL_BuiltIn_Commands_Interface));
91 //,
92 // typeof(object),
93 // new Type[] { typeof(LSL_CLRInterface.LSLScript) });
94
95
96 if (Common.IL_CreateConstructor)
97 IL_CREATE_CONSTRUCTOR(typeBuilder);
98
99
100 /*
101 * Generate the IL itself
102 */
103
104 LSO_Parser LSOP = new LSO_Parser();
105 LSOP.ParseFile(LSO_FileName, typeBuilder);
106
107 /*
108 * Done generating. Create a type and run it.
109 */
110
111
112
113 Common.SendToLog("Attempting to compile assembly...");
114 // Compile it
115 Type type = typeBuilder.CreateType();
116 Common.SendToLog("Compilation successful!");
117
118 Common.SendToLog("Saving assembly: " + DLL_FileName);
119 asmBuilder.Save(DLL_FileName);
120
121
122 Common.SendToLog("Creating an instance of new assembly...");
123 // Create an instance we can play with
124 //LSLScript hello = (LSLScript)Activator.CreateInstance(type);
125 //LSL_CLRInterface.LSLScript MyScript = (LSL_CLRInterface.LSLScript)Activator.CreateInstance(type);
126 object MyScript = (object)Activator.CreateInstance(type);
127
128
129 Common.SendToLog("");
130
131 System.Reflection.MemberInfo[] Members = type.GetMembers();
132
133 Common.SendToLog("Members of assembly " + type.ToString () + ":");
134 foreach (MemberInfo member in Members )
135 Common.SendToLog(member.ToString());
136
137
138 // Play with it
139 //MyScript.event_state_entry("Test");
140 object[] args = { null } ;
141 //System.Collections.Generic.List<string> Functions = (System.Collections.Generic.List<string>)type.InvokeMember("GetFunctions", BindingFlags.InvokeMethod, null, MyScript, null);
142
143 string[] ret = { };
144 if (Common.IL_CreateFunctionList)
145 ret = (string[])type.InvokeMember("GetFunctions", BindingFlags.InvokeMethod, null, MyScript, null);
146
147 foreach (string s in ret)
148 {
149 Common.SendToLog("");
150 Common.SendToLog("*** Executing LSL Server Event: " + s);
151 //object test = type.GetMember(s);
152 //object runner = type.InvokeMember(s, BindingFlags.Public | BindingFlags.InvokeMethod | BindingFlags.Instance, null, MyScript, args);
153 //runner();
154 //objBooks_Late = type.InvokeMember(s, BindingFlags.CreateInstance, null, objApp_Late, null);
155 type.InvokeMember(s, BindingFlags.InvokeMethod, null, MyScript, new object[] { "Test" });
156
157 }
158
159 }
160
161
162 private static void IL_CREATE_CONSTRUCTOR(TypeBuilder typeBuilder)
163 {
164
165
166 Common.SendToDebug("IL_CREATE_CONSTRUCTOR()");
167 //ConstructorBuilder constructor = typeBuilder.DefineConstructor(
168 // MethodAttributes.Public,
169 // CallingConventions.Standard,
170 // new Type[0]);
171 ConstructorBuilder constructor = typeBuilder.DefineConstructor(
172 MethodAttributes.Public |
173 MethodAttributes.SpecialName |
174 MethodAttributes.RTSpecialName,
175 CallingConventions.Standard,
176 new Type[0]);
177
178 //Define the reflection ConstructorInfor for System.Object
179 ConstructorInfo conObj = typeof(object).GetConstructor(new Type[0]);
180
181 //call constructor of base object
182 ILGenerator il = constructor.GetILGenerator();
183
184 Common.SendToDebug("IL_CREATE_CONSTRUCTOR: Creating global: UInt32 State = 0;");
185 string FieldName;
186 // Create state object
187 FieldName = "State";
188 FieldBuilder State_fb = typeBuilder.DefineField(
189 FieldName,
190 typeof(UInt32),
191 FieldAttributes.Public);
192 il.Emit(OpCodes.Ldarg_0);
193 il.Emit(OpCodes.Ldc_I4, 0);
194 il.Emit(OpCodes.Stfld, State_fb);
195
196
197 Common.SendToDebug("IL_CREATE_CONSTRUCTOR: Creating global: LSL_BuiltIn_Commands_TestImplementation LSL_BuiltIns = New LSL_BuiltIn_Commands_TestImplementation();");
198 //Type objType1 = typeof(object);
199 Type objType1 = typeof(LSL_BuiltIn_Commands_TestImplementation);
200
201 FieldName = "LSL_BuiltIns";
202 FieldBuilder LSL_BuiltIns_fb = typeBuilder.DefineField(
203 FieldName,
204 objType1,
205 FieldAttributes.Public);
206
207 //LSL_BuiltIn_Commands_TestImplementation _ti = new LSL_BuiltIn_Commands_TestImplementation();
208 il.Emit(OpCodes.Ldarg_0);
209 //il.Emit(OpCodes.Ldstr, "Test 123");
210 il.Emit(OpCodes.Newobj, objType1.GetConstructor(new Type[] { }));
211 il.Emit(OpCodes.Stfld, LSL_BuiltIns_fb);
212
213 il.Emit(OpCodes.Ldarg_0);
214 il.Emit(OpCodes.Call, conObj);
215
216
217
218 ////il.Emit(OpCodes.Newobj, typeof(UInt32));
219 //il.Emit(OpCodes.Starg_0);
220 //// Create LSL function library
221 //FieldBuilder LSL_BuiltIns_fb = typeBuilder.DefineField("LSL_BuiltIns", typeof(LSL_BuiltIn_Commands_Interface), FieldAttributes.Public);
222 //il.Emit(OpCodes.Newobj, typeof(LSL_BuiltIn_Commands_Interface));
223 //il.Emit(OpCodes.Stloc_1);
224
225 il.Emit(OpCodes.Ret);
226 }
227 }
228 }
diff --git a/OpenSim/Region/Environment/Scenes/_scripting/Engines/LSLEngine/LSLHandler/IL_common_functions.cs b/OpenSim/Region/Environment/Scenes/_scripting/Engines/LSLEngine/LSLHandler/IL_common_functions.cs
new file mode 100644
index 0000000..2f23a91
--- /dev/null
+++ b/OpenSim/Region/Environment/Scenes/_scripting/Engines/LSLEngine/LSLHandler/IL_common_functions.cs
@@ -0,0 +1,56 @@
1/*
2* Copyright (c) Contributors, http://www.openmetaverse.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders.
4*
5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met:
7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission.
15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*
27*/
28/* Original code: Tedd Hansen */
29using System;
30using System.Collections.Generic;
31using System.Text;
32using System.Reflection;
33using System.Reflection.Emit;
34
35namespace OpenSim.Region.Scripting.LSL
36{
37 partial class LSO_Parser
38 {
39 private static TypeBuilder CreateType(ModuleBuilder modBuilder, string typeName)
40 {
41 TypeBuilder typeBuilder = modBuilder.DefineType(typeName,
42 TypeAttributes.Public |
43 TypeAttributes.Class |
44 TypeAttributes.AutoClass |
45 TypeAttributes.AnsiClass |
46 TypeAttributes.BeforeFieldInit |
47 TypeAttributes.AutoLayout,
48 typeof(object),
49 new Type[] { typeof(object) });
50 return typeBuilder;
51
52 }
53
54
55 }
56}
diff --git a/OpenSim/Region/Environment/Scenes/_scripting/Engines/LSLEngine/LSLHandler/LSL_BuiltIn_Commands_Interface.cs b/OpenSim/Region/Environment/Scenes/_scripting/Engines/LSLEngine/LSLHandler/LSL_BuiltIn_Commands_Interface.cs
new file mode 100644
index 0000000..d8a0ce3
--- /dev/null
+++ b/OpenSim/Region/Environment/Scenes/_scripting/Engines/LSLEngine/LSLHandler/LSL_BuiltIn_Commands_Interface.cs
@@ -0,0 +1,366 @@
1/*
2* Copyright (c) Contributors, http://www.openmetaverse.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders.
4*
5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met:
7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission.
15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*
27*/
28/* Original code: Tedd Hansen */
29using System;
30 using System.Collections.Generic;
31 using System.Text;
32
33 namespace OpenSim.Region.Scripting.LSL
34 {
35 public interface LSL_BuiltIn_Commands_Interface
36 {
37 void llSin();
38 void llCos();
39 void llTan();
40 void llAtan2();
41 void llSqrt();
42 void llPow();
43 void llAbs();
44 void llFabs();
45 void llFrand();
46 void llFloor();
47 void llCeil();
48 void llRound();
49 void llVecMag();
50 void llVecNorm();
51 void llVecDist();
52 void llRot2Euler();
53 void llEuler2Rot();
54 void llAxes2Rot();
55 void llRot2Fwd();
56 void llRot2Left();
57 void llRot2Up();
58 void llRotBetween();
59 void llWhisper();
60 void llSay(UInt32 channelID, string text);
61 void llShout();
62 void llListen();
63 void llListenControl();
64 void llListenRemove();
65 void llSensor();
66 void llSensorRepeat();
67 void llSensorRemove();
68 void llDetectedName();
69 void llDetectedKey();
70 void llDetectedOwner();
71 void llDetectedType();
72 void llDetectedPos();
73 void llDetectedVel();
74 void llDetectedGrab();
75 void llDetectedRot();
76 void llDetectedGroup();
77 void llDetectedLinkNumber();
78 void llDie();
79 void llGround();
80 void llCloud();
81 void llWind();
82 void llSetStatus();
83 void llGetStatus();
84 void llSetScale();
85 void llGetScale();
86 void llSetColor();
87 void llGetAlpha();
88 void llSetAlpha();
89 void llGetColor();
90 void llSetTexture();
91 void llScaleTexture();
92 void llOffsetTexture();
93 void llRotateTexture();
94 void llGetTexture();
95 void llSetPos();
96 void llGetPos();
97 void llGetLocalPos();
98 void llSetRot();
99 void llGetRot();
100 void llGetLocalRot();
101 void llSetForce();
102 void llGetForce();
103 void llTarget();
104 void llTargetRemove();
105 void llRotTarget();
106 void llRotTargetRemove();
107 void llMoveToTarget();
108 void llStopMoveToTarget();
109 void llApplyImpulse();
110 void llApplyRotationalImpulse();
111 void llSetTorque();
112 void llGetTorque();
113 void llSetForceAndTorque();
114 void llGetVel();
115 void llGetAccel();
116 void llGetOmega();
117 void llGetTimeOfDay();
118 void llGetWallclock();
119 void llGetTime();
120 void llResetTime();
121 void llGetAndResetTime();
122 void llSound();
123 void llPlaySound();
124 void llLoopSound();
125 void llLoopSoundMaster();
126 void llLoopSoundSlave();
127 void llPlaySoundSlave();
128 void llTriggerSound();
129 void llStopSound();
130 void llPreloadSound();
131 void llGetSubString();
132 void llDeleteSubString();
133 void llInsertString();
134 void llToUpper();
135 void llToLower();
136 void llGiveMoney();
137 void llMakeExplosion();
138 void llMakeFountain();
139 void llMakeSmoke();
140 void llMakeFire();
141 void llRezObject();
142 void llLookAt();
143 void llStopLookAt();
144 void llSetTimerEvent();
145 void llSleep();
146 void llGetMass();
147 void llCollisionFilter();
148 void llTakeControls();
149 void llReleaseControls();
150 void llAttachToAvatar();
151 void llDetachFromAvatar();
152 void llTakeCamera();
153 void llReleaseCamera();
154 void llGetOwner();
155 void llInstantMessage();
156 void llEmail();
157 void llGetNextEmail();
158 void llGetKey();
159 void llSetBuoyancy();
160 void llSetHoverHeight();
161 void llStopHover();
162 void llMinEventDelay();
163 void llSoundPreload();
164 void llRotLookAt();
165 void llStringLength();
166 void llStartAnimation();
167 void llStopAnimation();
168 void llPointAt();
169 void llStopPointAt();
170 void llTargetOmega();
171 void llGetStartParameter();
172 void llGodLikeRezObject();
173 void llRequestPermissions();
174 void llGetPermissionsKey();
175 void llGetPermissions();
176 void llGetLinkNumber();
177 void llSetLinkColor();
178 void llCreateLink();
179 void llBreakLink();
180 void llBreakAllLinks();
181 void llGetLinkKey();
182 void llGetLinkName();
183 void llGetInventoryNumber();
184 void llGetInventoryName();
185 void llSetScriptState();
186 void llGetEnergy();
187 void llGiveInventory();
188 void llRemoveInventory();
189 void llSetText();
190 void llWater();
191 void llPassTouches();
192 void llRequestAgentData();
193 void llRequestInventoryData();
194 void llSetDamage();
195 void llTeleportAgentHome();
196 void llModifyLand();
197 void llCollisionSound();
198 void llCollisionSprite();
199 void llGetAnimation();
200 void llResetScript();
201 void llMessageLinked();
202 void llPushObject();
203 void llPassCollisions();
204 void llGetScriptName();
205 void llGetNumberOfSides();
206 void llAxisAngle2Rot();
207 void llRot2Axis();
208 void llRot2Angle();
209 void llAcos();
210 void llAsin();
211 void llAngleBetween();
212 void llGetInventoryKey();
213 void llAllowInventoryDrop();
214 void llGetSunDirection();
215 void llGetTextureOffset();
216 void llGetTextureScale();
217 void llGetTextureRot();
218 void llSubStringIndex();
219 void llGetOwnerKey();
220 void llGetCenterOfMass();
221 void llListSort();
222 void llGetListLength();
223 void llList2Integer();
224 void llList2Float();
225 void llList2String();
226 void llList2Key();
227 void llList2Vector();
228 void llList2Rot();
229 void llList2List();
230 void llDeleteSubList();
231 void llGetListEntryType();
232 void llList2CSV();
233 void llCSV2List();
234 void llListRandomize();
235 void llList2ListStrided();
236 void llGetRegionCorner();
237 void llListInsertList();
238 void llListFindList();
239 void llGetObjectName();
240 void llSetObjectName();
241 void llGetDate();
242 void llEdgeOfWorld();
243 void llGetAgentInfo();
244 void llAdjustSoundVolume();
245 void llSetSoundQueueing();
246 void llSetSoundRadius();
247 void llKey2Name();
248 void llSetTextureAnim();
249 void llTriggerSoundLimited();
250 void llEjectFromLand();
251 void llParseString2List();
252 void llOverMyLand();
253 void llGetLandOwnerAt();
254 void llGetNotecardLine();
255 void llGetAgentSize();
256 void llSameGroup();
257 void llUnSit();
258 void llGroundSlope();
259 void llGroundNormal();
260 void llGroundContour();
261 void llGetAttached();
262 void llGetFreeMemory();
263 void llGetRegionName();
264 void llGetRegionTimeDilation();
265 void llGetRegionFPS();
266 void llParticleSystem();
267 void llGroundRepel();
268 void llGiveInventoryList();
269 void llSetVehicleType();
270 void llSetVehicleFloatParam();
271 void llSetVehicleVectorParam();
272 void llSetVehicleRotationParam();
273 void llSetVehicleFlags();
274 void llRemoveVehicleFlags();
275 void llSitTarget();
276 void llAvatarOnSitTarget();
277 void llAddToLandPassList();
278 void llSetTouchText();
279 void llSetSitText();
280 void llSetCameraEyeOffset();
281 void llSetCameraAtOffset();
282 void llDumpList2String();
283 void llScriptDanger();
284 void llDialog();
285 void llVolumeDetect();
286 void llResetOtherScript();
287 void llGetScriptState();
288 void llRemoteLoadScript();
289 void llSetRemoteScriptAccessPin();
290 void llRemoteLoadScriptPin();
291 void llOpenRemoteDataChannel();
292 void llSendRemoteData();
293 void llRemoteDataReply();
294 void llCloseRemoteDataChannel();
295 void llMD5String();
296 void llSetPrimitiveParams();
297 void llStringToBase64();
298 void llBase64ToString();
299 void llXorBase64Strings();
300 void llRemoteDataSetRegion();
301 void llLog10();
302 void llLog();
303 void llGetAnimationList();
304 void llSetParcelMusicURL();
305 void llGetRootPosition();
306 void llGetRootRotation();
307 void llGetObjectDesc();
308 void llSetObjectDesc();
309 void llGetCreator();
310 void llGetTimestamp();
311 void llSetLinkAlpha();
312 void llGetNumberOfPrims();
313 void llGetNumberOfNotecardLines();
314 void llGetBoundingBox();
315 void llGetGeometricCenter();
316 void llGetPrimitiveParams();
317 void llIntegerToBase64();
318 void llBase64ToInteger();
319 void llGetGMTclock();
320 void llGetSimulatorHostname();
321 void llSetLocalRot();
322 void llParseStringKeepNulls();
323 void llRezAtRoot();
324 void llGetObjectPermMask();
325 void llSetObjectPermMask();
326 void llGetInventoryPermMask();
327 void llSetInventoryPermMask();
328 void llGetInventoryCreator();
329 void llOwnerSay();
330 void llRequestSimulatorData();
331 void llForceMouselook();
332 void llGetObjectMass();
333 void llListReplaceList();
334 void llLoadURL();
335 void llParcelMediaCommandList();
336 void llParcelMediaQuery();
337 void llModPow();
338 void llGetInventoryType();
339 void llSetPayPrice();
340 void llGetCameraPos();
341 void llGetCameraRot();
342 void llSetPrimURL();
343 void llRefreshPrimURL();
344 void llEscapeURL();
345 void llUnescapeURL();
346 void llMapDestination();
347 void llAddToLandBanList();
348 void llRemoveFromLandPassList();
349 void llRemoveFromLandBanList();
350 void llSetCameraParams();
351 void llClearCameraParams();
352 void llListStatistics();
353 void llGetUnixTime();
354 void llGetParcelFlags();
355 void llGetRegionFlags();
356 void llXorBase64StringsCorrect();
357 void llHTTPRequest();
358 void llResetLandBanList();
359 void llResetLandPassList();
360 void llGetParcelPrimCount();
361 void llGetParcelPrimOwners();
362 void llGetObjectPrimCount();
363 void llGetParcelMaxPrims();
364 void llGetParcelDetails();
365 }
366 }
diff --git a/OpenSim/Region/Environment/Scenes/_scripting/Engines/LSLEngine/LSLHandler/LSL_BuiltIn_Commands_TestImplementation.cs b/OpenSim/Region/Environment/Scenes/_scripting/Engines/LSLEngine/LSLHandler/LSL_BuiltIn_Commands_TestImplementation.cs
new file mode 100644
index 0000000..4b0fa7e
--- /dev/null
+++ b/OpenSim/Region/Environment/Scenes/_scripting/Engines/LSLEngine/LSLHandler/LSL_BuiltIn_Commands_TestImplementation.cs
@@ -0,0 +1,377 @@
1/*
2* Copyright (c) Contributors, http://www.openmetaverse.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders.
4*
5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met:
7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission.
15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*
27*/
28/* Original code: Tedd Hansen */
29using System;
30using System.Collections.Generic;
31using System.Text;
32
33namespace OpenSim.Region.Scripting.LSL
34{
35 public class LSL_BuiltIn_Commands_TestImplementation: LSL_BuiltIn_Commands_Interface
36 {
37 public LSL_BuiltIn_Commands_TestImplementation()
38 {
39 Common.SendToDebug("LSL_BuiltIn_Commands_TestImplementation: Creating object");
40 }
41
42 public void llSin() { }
43 public void llCos() { }
44 public void llTan() { }
45 public void llAtan2() { }
46 public void llSqrt() { }
47 public void llPow() { }
48 public void llAbs() { }
49 public void llFabs() { }
50 public void llFrand() { }
51 public void llFloor() { }
52 public void llCeil() { }
53 public void llRound() { }
54 public void llVecMag() { }
55 public void llVecNorm() { }
56 public void llVecDist() { }
57 public void llRot2Euler() { }
58 public void llEuler2Rot() { }
59 public void llAxes2Rot() { }
60 public void llRot2Fwd() { }
61 public void llRot2Left() { }
62 public void llRot2Up() { }
63 public void llRotBetween() { }
64 public void llWhisper() { }
65 public void llSay(UInt32 channelID, string text)
66 {
67 Common.SendToDebug("INTERNAL FUNCTION llSay(" + channelID + ", \"" + text + "\");");
68 }
69 public void llShout() { }
70 public void llListen() { }
71 public void llListenControl() { }
72 public void llListenRemove() { }
73 public void llSensor() { }
74 public void llSensorRepeat() { }
75 public void llSensorRemove() { }
76 public void llDetectedName() { }
77 public void llDetectedKey() { }
78 public void llDetectedOwner() { }
79 public void llDetectedType() { }
80 public void llDetectedPos() { }
81 public void llDetectedVel() { }
82 public void llDetectedGrab() { }
83 public void llDetectedRot() { }
84 public void llDetectedGroup() { }
85 public void llDetectedLinkNumber() { }
86 public void llDie() { }
87 public void llGround() { }
88 public void llCloud() { }
89 public void llWind() { }
90 public void llSetStatus() { }
91 public void llGetStatus() { }
92 public void llSetScale() { }
93 public void llGetScale() { }
94 public void llSetColor() { }
95 public void llGetAlpha() { }
96 public void llSetAlpha() { }
97 public void llGetColor() { }
98 public void llSetTexture() { }
99 public void llScaleTexture() { }
100 public void llOffsetTexture() { }
101 public void llRotateTexture() { }
102 public void llGetTexture() { }
103 public void llSetPos() { }
104 public void llGetPos() { }
105 public void llGetLocalPos() { }
106 public void llSetRot() { }
107 public void llGetRot() { }
108 public void llGetLocalRot() { }
109 public void llSetForce() { }
110 public void llGetForce() { }
111 public void llTarget() { }
112 public void llTargetRemove() { }
113 public void llRotTarget() { }
114 public void llRotTargetRemove() { }
115 public void llMoveToTarget() { }
116 public void llStopMoveToTarget() { }
117 public void llApplyImpulse() { }
118 public void llApplyRotationalImpulse() { }
119 public void llSetTorque() { }
120 public void llGetTorque() { }
121 public void llSetForceAndTorque() { }
122 public void llGetVel() { }
123 public void llGetAccel() { }
124 public void llGetOmega() { }
125 public void llGetTimeOfDay() { }
126 public void llGetWallclock() { }
127 public void llGetTime() { }
128 public void llResetTime() { }
129 public void llGetAndResetTime() { }
130 public void llSound() { }
131 public void llPlaySound() { }
132 public void llLoopSound() { }
133 public void llLoopSoundMaster() { }
134 public void llLoopSoundSlave() { }
135 public void llPlaySoundSlave() { }
136 public void llTriggerSound() { }
137 public void llStopSound() { }
138 public void llPreloadSound() { }
139 public void llGetSubString() { }
140 public void llDeleteSubString() { }
141 public void llInsertString() { }
142 public void llToUpper() { }
143 public void llToLower() { }
144 public void llGiveMoney() { }
145 public void llMakeExplosion() { }
146 public void llMakeFountain() { }
147 public void llMakeSmoke() { }
148 public void llMakeFire() { }
149 public void llRezObject() { }
150 public void llLookAt() { }
151 public void llStopLookAt() { }
152 public void llSetTimerEvent() { }
153 public void llSleep() { }
154 public void llGetMass() { }
155 public void llCollisionFilter() { }
156 public void llTakeControls() { }
157 public void llReleaseControls() { }
158 public void llAttachToAvatar() { }
159 public void llDetachFromAvatar() { }
160 public void llTakeCamera() { }
161 public void llReleaseCamera() { }
162 public void llGetOwner() { }
163 public void llInstantMessage() { }
164 public void llEmail() { }
165 public void llGetNextEmail() { }
166 public void llGetKey() { }
167 public void llSetBuoyancy() { }
168 public void llSetHoverHeight() { }
169 public void llStopHover() { }
170 public void llMinEventDelay() { }
171 public void llSoundPreload() { }
172 public void llRotLookAt() { }
173 public void llStringLength() { }
174 public void llStartAnimation() { }
175 public void llStopAnimation() { }
176 public void llPointAt() { }
177 public void llStopPointAt() { }
178 public void llTargetOmega() { }
179 public void llGetStartParameter() { }
180 public void llGodLikeRezObject() { }
181 public void llRequestPermissions() { }
182 public void llGetPermissionsKey() { }
183 public void llGetPermissions() { }
184 public void llGetLinkNumber() { }
185 public void llSetLinkColor() { }
186 public void llCreateLink() { }
187 public void llBreakLink() { }
188 public void llBreakAllLinks() { }
189 public void llGetLinkKey() { }
190 public void llGetLinkName() { }
191 public void llGetInventoryNumber() { }
192 public void llGetInventoryName() { }
193 public void llSetScriptState() { }
194 public void llGetEnergy() { }
195 public void llGiveInventory() { }
196 public void llRemoveInventory() { }
197 public void llSetText() { }
198 public void llWater() { }
199 public void llPassTouches() { }
200 public void llRequestAgentData() { }
201 public void llRequestInventoryData() { }
202 public void llSetDamage() { }
203 public void llTeleportAgentHome() { }
204 public void llModifyLand() { }
205 public void llCollisionSound() { }
206 public void llCollisionSprite() { }
207 public void llGetAnimation() { }
208 public void llResetScript() { }
209 public void llMessageLinked() { }
210 public void llPushObject() { }
211 public void llPassCollisions() { }
212 public void llGetScriptName() { }
213 public void llGetNumberOfSides() { }
214 public void llAxisAngle2Rot() { }
215 public void llRot2Axis() { }
216 public void llRot2Angle() { }
217 public void llAcos() { }
218 public void llAsin() { }
219 public void llAngleBetween() { }
220 public void llGetInventoryKey() { }
221 public void llAllowInventoryDrop() { }
222 public void llGetSunDirection() { }
223 public void llGetTextureOffset() { }
224 public void llGetTextureScale() { }
225 public void llGetTextureRot() { }
226 public void llSubStringIndex() { }
227 public void llGetOwnerKey() { }
228 public void llGetCenterOfMass() { }
229 public void llListSort() { }
230 public void llGetListLength() { }
231 public void llList2Integer() { }
232 public void llList2Float() { }
233 public void llList2String() { }
234 public void llList2Key() { }
235 public void llList2Vector() { }
236 public void llList2Rot() { }
237 public void llList2List() { }
238 public void llDeleteSubList() { }
239 public void llGetListEntryType() { }
240 public void llList2CSV() { }
241 public void llCSV2List() { }
242 public void llListRandomize() { }
243 public void llList2ListStrided() { }
244 public void llGetRegionCorner() { }
245 public void llListInsertList() { }
246 public void llListFindList() { }
247 public void llGetObjectName() { }
248 public void llSetObjectName() { }
249 public void llGetDate() { }
250 public void llEdgeOfWorld() { }
251 public void llGetAgentInfo() { }
252 public void llAdjustSoundVolume() { }
253 public void llSetSoundQueueing() { }
254 public void llSetSoundRadius() { }
255 public void llKey2Name() { }
256 public void llSetTextureAnim() { }
257 public void llTriggerSoundLimited() { }
258 public void llEjectFromLand() { }
259 public void llParseString2List() { }
260 public void llOverMyLand() { }
261 public void llGetLandOwnerAt() { }
262 public void llGetNotecardLine() { }
263 public void llGetAgentSize() { }
264 public void llSameGroup() { }
265 public void llUnSit() { }
266 public void llGroundSlope() { }
267 public void llGroundNormal() { }
268 public void llGroundContour() { }
269 public void llGetAttached() { }
270 public void llGetFreeMemory() { }
271 public void llGetRegionName() { }
272 public void llGetRegionTimeDilation() { }
273 public void llGetRegionFPS() { }
274 public void llParticleSystem() { }
275 public void llGroundRepel() { }
276 public void llGiveInventoryList() { }
277 public void llSetVehicleType() { }
278 public void llSetVehicleFloatParam() { }
279 public void llSetVehicleVectorParam() { }
280 public void llSetVehicleRotationParam() { }
281 public void llSetVehicleFlags() { }
282 public void llRemoveVehicleFlags() { }
283 public void llSitTarget() { }
284 public void llAvatarOnSitTarget() { }
285 public void llAddToLandPassList() { }
286 public void llSetTouchText() { }
287 public void llSetSitText() { }
288 public void llSetCameraEyeOffset() { }
289 public void llSetCameraAtOffset() { }
290 public void llDumpList2String() { }
291 public void llScriptDanger() { }
292 public void llDialog() { }
293 public void llVolumeDetect() { }
294 public void llResetOtherScript() { }
295 public void llGetScriptState() { }
296 public void llRemoteLoadScript() { }
297 public void llSetRemoteScriptAccessPin() { }
298 public void llRemoteLoadScriptPin() { }
299 public void llOpenRemoteDataChannel() { }
300 public void llSendRemoteData() { }
301 public void llRemoteDataReply() { }
302 public void llCloseRemoteDataChannel() { }
303 public void llMD5String() { }
304 public void llSetPrimitiveParams() { }
305 public void llStringToBase64() { }
306 public void llBase64ToString() { }
307 public void llXorBase64Strings() { }
308 public void llRemoteDataSetRegion() { }
309 public void llLog10() { }
310 public void llLog() { }
311 public void llGetAnimationList() { }
312 public void llSetParcelMusicURL() { }
313 public void llGetRootPosition() { }
314 public void llGetRootRotation() { }
315 public void llGetObjectDesc() { }
316 public void llSetObjectDesc() { }
317 public void llGetCreator() { }
318 public void llGetTimestamp() { }
319 public void llSetLinkAlpha() { }
320 public void llGetNumberOfPrims() { }
321 public void llGetNumberOfNotecardLines() { }
322 public void llGetBoundingBox() { }
323 public void llGetGeometricCenter() { }
324 public void llGetPrimitiveParams() { }
325 public void llIntegerToBase64() { }
326 public void llBase64ToInteger() { }
327 public void llGetGMTclock() { }
328 public void llGetSimulatorHostname() { }
329 public void llSetLocalRot() { }
330 public void llParseStringKeepNulls() { }
331 public void llRezAtRoot() { }
332 public void llGetObjectPermMask() { }
333 public void llSetObjectPermMask() { }
334 public void llGetInventoryPermMask() { }
335 public void llSetInventoryPermMask() { }
336 public void llGetInventoryCreator() { }
337 public void llOwnerSay() { }
338 public void llRequestSimulatorData() { }
339 public void llForceMouselook() { }
340 public void llGetObjectMass() { }
341 public void llListReplaceList() { }
342 public void llLoadURL() { }
343 public void llParcelMediaCommandList() { }
344 public void llParcelMediaQuery() { }
345 public void llModPow() { }
346 public void llGetInventoryType() { }
347 public void llSetPayPrice() { }
348 public void llGetCameraPos() { }
349 public void llGetCameraRot() { }
350 public void llSetPrimURL() { }
351 public void llRefreshPrimURL() { }
352 public void llEscapeURL() { }
353 public void llUnescapeURL() { }
354 public void llMapDestination() { }
355 public void llAddToLandBanList() { }
356 public void llRemoveFromLandPassList() { }
357 public void llRemoveFromLandBanList() { }
358 public void llSetCameraParams() { }
359 public void llClearCameraParams() { }
360 public void llListStatistics() { }
361 public void llGetUnixTime() { }
362 public void llGetParcelFlags() { }
363 public void llGetRegionFlags() { }
364 public void llXorBase64StringsCorrect() { }
365 public void llHTTPRequest() { }
366 public void llResetLandBanList() { }
367 public void llResetLandPassList() { }
368 public void llGetParcelPrimCount() { }
369 public void llGetParcelPrimOwners() { }
370 public void llGetObjectPrimCount() { }
371 public void llGetParcelMaxPrims() { }
372 public void llGetParcelDetails() { }
373
374
375
376 }
377}
diff --git a/OpenSim/Region/Environment/Scenes/_scripting/Engines/LSLEngine/LSLHandler/LSL_CLRInterface.cs b/OpenSim/Region/Environment/Scenes/_scripting/Engines/LSLEngine/LSLHandler/LSL_CLRInterface.cs
new file mode 100644
index 0000000..ed22c8c
--- /dev/null
+++ b/OpenSim/Region/Environment/Scenes/_scripting/Engines/LSLEngine/LSLHandler/LSL_CLRInterface.cs
@@ -0,0 +1,79 @@
1/*
2* Copyright (c) Contributors, http://www.openmetaverse.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders.
4*
5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met:
7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission.
15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*
27*/
28/* Original code: Tedd Hansen */
29using System;
30using System.Collections.Generic;
31using System.Text;
32
33namespace OpenSim.Region.Scripting.LSL
34{
35 public class LSL_CLRInterface
36 {
37 public interface LSLScript
38 {
39 //public virtual void Run(object arg)
40 //{
41 //}
42 //void Run(object arg);
43
44 //void event_state_entry(object arg);
45 //void event_state_exit();
46 //void event_touch_start(object arg);
47 //void event_touch();
48 //void event_touch_end();
49 //void event_collision_start();
50 //void event_collision();
51 //void event_collision_end();
52 //void event_land_collision_start();
53 //void event_land_collision();
54 //void event_land_collision_end();
55 //void event_timer();
56 //void event_listen();
57 //void event_on_rez();
58 //void event_sensor();
59 //void event_no_sensor();
60 //void event_control();
61 //void event_money();
62 //void event_email();
63 //void event_at_target();
64 //void event_not_at_target();
65 //void event_at_rot_target();
66 //void event_not_at_rot_target();
67 //void event_run_time_permissions();
68 //void event_changed();
69 //void event_attach();
70 //void event_dataserver();
71 //void event_link_message();
72 //void event_moving_start();
73 //void event_moving_end();
74 //void event_object_rez();
75 //void event_remote_data();
76 //void event_http_response();
77 }
78 }
79}
diff --git a/OpenSim/Region/Environment/Scenes/_scripting/Engines/LSLEngine/LSLHandler/LSL_OPCODE_IL_processor.cs b/OpenSim/Region/Environment/Scenes/_scripting/Engines/LSLEngine/LSLHandler/LSL_OPCODE_IL_processor.cs
new file mode 100644
index 0000000..e85c1d0
--- /dev/null
+++ b/OpenSim/Region/Environment/Scenes/_scripting/Engines/LSLEngine/LSLHandler/LSL_OPCODE_IL_processor.cs
@@ -0,0 +1,351 @@
1/*
2* Copyright (c) Contributors, http://www.openmetaverse.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders.
4*
5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met:
7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission.
15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*
27*/
28/* Original code: Tedd Hansen */
29using System;
30using System.Collections.Generic;
31using System.Text;
32using System.Reflection;
33using System.Reflection.Emit;
34
35namespace OpenSim.Region.Scripting.LSL
36{
37 partial class LSO_Parser
38 {
39 //LSO_Enums MyLSO_Enums = new LSO_Enums();
40
41 internal bool LSL_PROCESS_OPCODE(ILGenerator il)
42 {
43
44 byte bp1;
45 UInt32 u32p1;
46 UInt16 opcode = br_read(1)[0];
47 Common.SendToDebug("OPCODE: " + ((LSO_Enums.Operation_Table)opcode).ToString());
48 string idesc = ((LSO_Enums.Operation_Table)opcode).ToString();
49 switch ((LSO_Enums.Operation_Table)opcode)
50 {
51
52 case LSO_Enums.Operation_Table.POP:
53 case LSO_Enums.Operation_Table.POPL:
54 case LSO_Enums.Operation_Table.POPV:
55 case LSO_Enums.Operation_Table.POPQ:
56 case LSO_Enums.Operation_Table.POPIP:
57 case LSO_Enums.Operation_Table.POPBP:
58 case LSO_Enums.Operation_Table.POPSP:
59 case LSO_Enums.Operation_Table.POPSLR:
60 // ignore -- builds callframe
61 Common.SendToDebug("Instruction " + idesc + ": il.Emit(OpCodes.Pop);");
62 il.Emit(OpCodes.Pop);
63 break;
64 case LSO_Enums.Operation_Table.POPARG:
65 Common.SendToDebug("Instruction " + idesc + ": Ignored");
66 Common.SendToDebug("Instruction " + idesc + ": Description: Drop x bytes from the stack ");
67 Common.SendToDebug("Param1: " + BitConverter.ToUInt32(br_read(4), 0));
68 break;
69
70 // LONG
71 case LSO_Enums.Operation_Table.STORE:
72 case LSO_Enums.Operation_Table.STORES:
73 case LSO_Enums.Operation_Table.STOREL:
74 case LSO_Enums.Operation_Table.STOREV:
75 case LSO_Enums.Operation_Table.STOREQ:
76 case LSO_Enums.Operation_Table.STOREG:
77 case LSO_Enums.Operation_Table.STOREGS:
78 case LSO_Enums.Operation_Table.STOREGL:
79 case LSO_Enums.Operation_Table.STOREGV:
80 case LSO_Enums.Operation_Table.STOREGQ:
81 case LSO_Enums.Operation_Table.LOADP:
82 case LSO_Enums.Operation_Table.LOADSP:
83 case LSO_Enums.Operation_Table.LOADLP:
84 case LSO_Enums.Operation_Table.LOADVP:
85 case LSO_Enums.Operation_Table.LOADQP:
86 case LSO_Enums.Operation_Table.PUSH:
87 case LSO_Enums.Operation_Table.PUSHS:
88 case LSO_Enums.Operation_Table.PUSHL:
89 case LSO_Enums.Operation_Table.PUSHV:
90 case LSO_Enums.Operation_Table.PUSHQ:
91 case LSO_Enums.Operation_Table.PUSHG:
92 case LSO_Enums.Operation_Table.PUSHGS:
93 case LSO_Enums.Operation_Table.PUSHGL:
94 case LSO_Enums.Operation_Table.PUSHGV:
95 case LSO_Enums.Operation_Table.PUSHGQ:
96 Common.SendToDebug("Param1: " + BitConverter.ToUInt32(br_read(4), 0));
97 break;
98 // None
99 case LSO_Enums.Operation_Table.PUSHIP:
100 case LSO_Enums.Operation_Table.PUSHBP:
101 case LSO_Enums.Operation_Table.PUSHSP:
102 // Push Stack Top (Memory Address) to stack
103 Common.SendToDebug("Instruction " + idesc + ": il.Emit(OpCodes.Ldc_I4, " + myHeader.SP + ");");
104 Common.SendToDebug("Instruction " + idesc + ": Description: Pushing Stack Top (Memory Address from header) to stack");
105 il.Emit(OpCodes.Ldc_I4, myHeader.SP);
106 break;
107 // BYTE
108 case LSO_Enums.Operation_Table.PUSHARGB:
109 Common.SendToDebug("Param1: " + br_read(1)[0]);
110 break;
111 // INTEGER
112 case LSO_Enums.Operation_Table.PUSHARGI:
113 // TODO: What is size of integer?
114 u32p1 = BitConverter.ToUInt32(br_read(4), 0);
115 Common.SendToDebug("Instruction PUSHSP: il.Emit(OpCodes.Ldc_I4, " + u32p1 + ");");
116 Common.SendToDebug("Param1: " + u32p1);
117 il.Emit(OpCodes.Ldc_I4, u32p1);
118 break;
119 // FLOAT
120 case LSO_Enums.Operation_Table.PUSHARGF:
121 // TODO: What is size of float?
122 Common.SendToDebug("Param1: " + BitConverter.ToUInt32(br_read(4), 0));
123 break;
124 // STRING
125 case LSO_Enums.Operation_Table.PUSHARGS:
126 string s = Read_String();
127 Common.SendToDebug("Instruction " + idesc + ": il.Emit(OpCodes.Ldstr, \"" + s + "\");");
128 Common.SendToDebug("Param1: " + s);
129 il.Emit(OpCodes.Ldstr, s);
130 break;
131 // VECTOR z,y,x
132 case LSO_Enums.Operation_Table.PUSHARGV:
133 Common.SendToDebug("Param1 Z: " + BitConverter.ToUInt32(br_read(4), 0));
134 Common.SendToDebug("Param1 Y: " + BitConverter.ToUInt32(br_read(4), 0));
135 Common.SendToDebug("Param1 X: " + BitConverter.ToUInt32(br_read(4), 0));
136 break;
137 // ROTATION s,z,y,x
138 case LSO_Enums.Operation_Table.PUSHARGQ:
139 Common.SendToDebug("Param1 S: " + BitConverter.ToUInt32(br_read(4), 0));
140 Common.SendToDebug("Param1 Z: " + BitConverter.ToUInt32(br_read(4), 0));
141 Common.SendToDebug("Param1 Y: " + BitConverter.ToUInt32(br_read(4), 0));
142 Common.SendToDebug("Param1 X: " + BitConverter.ToUInt32(br_read(4), 0));
143 break;
144 // LONG
145 case LSO_Enums.Operation_Table.PUSHARGE:
146 u32p1 = BitConverter.ToUInt32(br_read(4), 0);
147 //Common.SendToDebug("Instruction PUSHSP: il.Emit(OpCodes., " + u32p1 + ");");
148 Common.SendToDebug("Instruction " + idesc + ": Ignoring (not in use according to doc)");
149 //Common.SendToDebug("Instruction " + idesc + ": Description: Pushes X bytes of $00 onto the stack (used to put space for local variable memory for a call)");
150 Common.SendToDebug("Param1: " + u32p1);
151 //il.Emit(OpCodes.ldc_i4, u32p1);
152 //if (u32p1 > 0) {
153 //for (int _ic=0; _ic < u32p1; _ic++)
154 //{
155 // Common.SendToDebug("Instruction " + idesc + ": il.Emit(OpCodes.Ldnull);");
156 // il.Emit(OpCodes.Ldnull);
157 //}
158 break;
159 // BYTE
160 case LSO_Enums.Operation_Table.ADD:
161 bp1 = br_read(1)[0];
162 Common.SendToDebug("Instruction " + idesc + ": Add type: " + ((LSO_Enums.OpCode_Add_TypeDefs)bp1).ToString());
163 Common.SendToDebug("Param1: " + bp1);
164 switch ((LSO_Enums.OpCode_Add_TypeDefs)bp1)
165 {
166 case LSO_Enums.OpCode_Add_TypeDefs.String:
167 Common.SendToDebug("Instruction " + idesc
168 + ": il.Emit(OpCodes.Call, typeof(System.String).GetMethod(\"Concat\", new Type[] { typeof(object), typeof(object) }));");
169 il.Emit(OpCodes.Call, typeof(System.String).GetMethod
170 ("Concat", new Type[] { typeof(object), typeof(object) }));
171
172 break;
173 case LSO_Enums.OpCode_Add_TypeDefs.UInt32:
174 default:
175 Common.SendToDebug("Instruction " + idesc + ": il.Emit(OpCodes.Add);");
176 il.Emit(OpCodes.Add);
177 break;
178 }
179
180
181 //il.Emit(OpCodes.Add, p1);
182 break;
183 case LSO_Enums.Operation_Table.SUB:
184 Common.SendToDebug("Instruction " + idesc + ": il.Emit(OpCodes.Sub);");
185 bp1 = br_read(1)[0];
186 Common.SendToDebug("Param1: " + bp1);
187 il.Emit(OpCodes.Sub);
188 //il.Emit(OpCodes.Sub, p1);
189 break;
190 case LSO_Enums.Operation_Table.MUL:
191 Common.SendToDebug("Instruction " + idesc + ": il.Emit(OpCodes.Mul);");
192 bp1 = br_read(1)[0];
193 Common.SendToDebug("Param1: " + bp1);
194 il.Emit(OpCodes.Mul);
195 //il.Emit(OpCodes.Mul, p1);
196 break;
197 case LSO_Enums.Operation_Table.DIV:
198 Common.SendToDebug("Instruction " + idesc + ": il.Emit(OpCodes.Div);");
199 bp1 = br_read(1)[0];
200 Common.SendToDebug("Param1: " + bp1);
201 il.Emit(OpCodes.Div);
202 //il.Emit(OpCodes.Div, p1);
203 break;
204 case LSO_Enums.Operation_Table.EQ:
205 Common.SendToDebug("Instruction " + idesc + ": il.Emit(OpCodes.Ceq);");
206 bp1 = br_read(1)[0];
207 Common.SendToDebug("Param1: " + bp1);
208 il.Emit(OpCodes.Ceq);
209 //il.Emit(OpCodes.Ceq, p1);
210 break;
211 case LSO_Enums.Operation_Table.NEQ:
212 case LSO_Enums.Operation_Table.LEQ:
213 case LSO_Enums.Operation_Table.GEQ:
214 case LSO_Enums.Operation_Table.LESS:
215 Common.SendToDebug("Instruction " + idesc + ": il.Emit(OpCodes.Clt_Un);");
216 bp1 = br_read(1)[0];
217 Common.SendToDebug("Param1: " + bp1);
218 il.Emit(OpCodes.Clt_Un);
219 //il.Emit(OpCodes.Clt, p1);
220 break;
221 case LSO_Enums.Operation_Table.GREATER:
222 Common.SendToDebug("Instruction " + idesc + ": il.Emit(OpCodes.Cgt_Un);");
223 bp1 = br_read(1)[0];
224 Common.SendToDebug("Param1: " + bp1);
225 il.Emit(OpCodes.Cgt_Un);
226 //il.Emit(OpCodes.Cgt, p1);
227 break;
228 case LSO_Enums.Operation_Table.MOD:
229 case LSO_Enums.Operation_Table.BOOLOR:
230 bp1 = br_read(1)[0];
231 Common.SendToDebug("Param1: " + bp1);
232 break;
233 // LONG
234 case LSO_Enums.Operation_Table.JUMP:
235 Common.SendToDebug("Param1: " + BitConverter.ToUInt32(br_read(4), 0));
236 break;
237 // BYTE, LONG
238 case LSO_Enums.Operation_Table.JUMPIF:
239 case LSO_Enums.Operation_Table.JUMPNIF:
240 Common.SendToDebug("Param1: " + br_read(1)[0]);
241 Common.SendToDebug("Param2: " + BitConverter.ToUInt32(br_read(4), 0));
242 break;
243 // LONG
244 case LSO_Enums.Operation_Table.STATE:
245 bp1 = br_read(1)[0];
246 //il.Emit(OpCodes.Ld); // Load local variable 0 onto stack
247 //il.Emit(OpCodes.Ldc_I4, 0); // Push index position
248 //il.Emit(OpCodes.Ldstr, EventList[p1]); // Push value
249 //il.Emit(OpCodes.Stelem_Ref); // Perform array[index] = value
250 break;
251 case LSO_Enums.Operation_Table.CALL:
252 Common.SendToDebug("Param1: " + BitConverter.ToUInt32(br_read(4), 0));
253 break;
254 // BYTE
255 case LSO_Enums.Operation_Table.CAST:
256 bp1 = br_read(1)[0];
257 Common.SendToDebug("Instruction " + idesc + ": Cast to type: " + ((LSO_Enums.OpCode_Cast_TypeDefs)bp1));
258 Common.SendToDebug("Param1: " + bp1);
259 switch ((LSO_Enums.OpCode_Cast_TypeDefs)bp1)
260 {
261 case LSO_Enums.OpCode_Cast_TypeDefs.String:
262 Common.SendToDebug("Instruction " + idesc + ": il.Emit(OpCodes.Calli, typeof(System.Convert).GetMethod(\"ToString\", new Type[] { typeof(object) }));");
263 //il.Emit(OpCodes.Box, typeof (UInt32));
264 il.Emit(OpCodes.Calli, typeof(Common).GetMethod
265 ("Cast_ToString", new Type[] { typeof(object) }));
266
267 //il.Emit(OpCodes.Box, typeof(System.UInt32) );
268 //il.Emit(OpCodes.Box, typeof(string));
269
270 //il.Emit(OpCodes.Conv_R8);
271 //il.Emit(OpCodes.Call, typeof(System.Convert).GetMethod
272 // ("ToString", new Type[] { typeof(float) }));
273
274 break;
275 default:
276 Common.SendToDebug("Instruction " + idesc + ": Unknown cast type!");
277 break;
278 }
279 break;
280 // LONG
281 case LSO_Enums.Operation_Table.STACKTOS:
282 case LSO_Enums.Operation_Table.STACKTOL:
283 Common.SendToDebug("Param1: " + BitConverter.ToUInt32(br_read(4), 0));
284 break;
285 // BYTE
286 case LSO_Enums.Operation_Table.PRINT:
287 case LSO_Enums.Operation_Table.CALLLIB:
288 Common.SendToDebug("Param1: " + br_read(1)[0]);
289 break;
290 // SHORT
291 case LSO_Enums.Operation_Table.CALLLIB_TWO_BYTE:
292 // TODO: What is size of short?
293 UInt16 U16p1 = BitConverter.ToUInt16(br_read(2), 0);
294 Common.SendToDebug("Instruction " + idesc + ": Builtin Command: " + ((LSO_Enums.BuiltIn_Functions)U16p1).ToString());
295 Common.SendToDebug("Param1: " + U16p1);
296 switch ((LSO_Enums.BuiltIn_Functions)U16p1)
297 {
298 case LSO_Enums.BuiltIn_Functions.llSay:
299 Common.SendToDebug("Instruction " + idesc + " " + ((LSO_Enums.BuiltIn_Functions)U16p1).ToString()
300 + ": Mapped to internal function");
301
302 //il.Emit(OpCodes.Ldstr, "INTERNAL COMMAND: llSay({0}, \"{1}\"");
303 //il.Emit(OpCodes.Call, typeof(IL_Helper).GetMethod("ReverseFormatString",
304 // new Type[] { typeof(string), typeof(UInt32), typeof(string) }
305 //));
306
307
308 //il.Emit(OpCodes.Pop);
309 //il.Emit(OpCodes.Call,
310 // typeof(Console).GetMethod("WriteLine",
311 // new Type[] { typeof(string) }
312 //));
313
314
315 il.Emit(OpCodes.Call,
316 typeof(Common).GetMethod("SendToLog",
317 new Type[] { typeof(string) }
318 ));
319
320
321
322 //il.Emit(OpCodes.Pop);
323
324 //il.Emit(OpCodes.Ldind_I2, 0);
325
326 //il.Emit(OpCodes.Call, typeof(string).GetMethod("Format", new Type[] { typeof(string), typeof(object) }));
327 //il.EmitCalli(OpCodes.Calli,
328 //il.Emit(OpCodes.Call, typeof().GetMethod
329 // ("llSay", new Type[] { typeof(UInt32), typeof(string) }));
330 break;
331 default:
332 Common.SendToDebug("Instruction " + idesc + ": " + ((LSO_Enums.BuiltIn_Functions)U16p1).ToString() + ": INTERNAL COMMAND NOT IMPLEMENTED");
333 break;
334 }
335
336 //Common.SendToDebug("Instruction " + idesc + ": DEBUG: Faking return code:");
337 //Common.SendToDebug("Instruction " + idesc + ": il.Emit(OpCodes.Ldc_I4, 0);");
338 //il.Emit(OpCodes.Ldc_I4, 0);
339 break;
340
341 // RETURN
342 case LSO_Enums.Operation_Table.RETURN:
343
344 Common.SendToDebug("Last OPCODE was return command. Code chunk execution complete.");
345 return true;
346 }
347 return false;
348 }
349
350 }
351}
diff --git a/OpenSim/Region/Environment/Scenes/_scripting/Engines/LSLEngine/LSLHandler/LSO_Enums.cs b/OpenSim/Region/Environment/Scenes/_scripting/Engines/LSLEngine/LSLHandler/LSO_Enums.cs
new file mode 100644
index 0000000..7cac152
--- /dev/null
+++ b/OpenSim/Region/Environment/Scenes/_scripting/Engines/LSLEngine/LSLHandler/LSO_Enums.cs
@@ -0,0 +1,548 @@
1/*
2* Copyright (c) Contributors, http://www.openmetaverse.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders.
4*
5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met:
7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission.
15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*
27*/
28/* Original code: Tedd Hansen */
29using System;
30using System.Collections.Generic;
31using System.Text;
32
33namespace OpenSim.Region.Scripting.LSL
34{
35 static class LSO_Enums
36 {
37 //public System.Collections.Generic.Dictionary<Byte, Type> OpCode_Add_Types;
38
39 //LSO_Enums() {
40 // OpCode_Add_Types.Add(51, typeof(String));
41 // OpCode_Add_Types.Add(17, typeof(UInt32));
42 //}
43
44 public enum OpCode_Add_TypeDefs
45 {
46 String = 51,
47 UInt32 = 17
48 }
49 public enum OpCode_Cast_TypeDefs
50 {
51 String = 19
52 }
53
54#pragma warning disable 649
55
56 public struct Vector
57 {
58 public UInt32 Z;
59 public UInt32 Y;
60 public UInt32 X;
61 }
62
63 public struct Rotation
64 {
65 public UInt32 S;
66 public UInt32 Z;
67 public UInt32 Y;
68 public UInt32 X;
69 }
70
71#pragma warning restore 649
72
73 public enum Variable_Type_Codes
74 {
75 Void = 0,
76 Integer = 1,
77 Float = 2,
78 String = 3,
79 Key = 4,
80 Vector = 5,
81 Rotation = 6,
82 List = 7
83 }
84 public enum Event_Mask_Values
85 {
86 state_entry = 0,
87 state_exit = 1,
88 touch_start = 2,
89 touch = 3,
90 touch_end = 4,
91 collision_start = 5,
92 collision = 6,
93 collision_end = 7,
94 land_collision_start = 8,
95 land_collision = 9,
96 land_collision_end = 10,
97 timer = 11,
98 listen = 12,
99 on_rez = 13,
100 sensor = 14,
101 no_sensor = 15,
102 control = 16,
103 money = 17,
104 email = 18,
105 at_target = 19,
106 not_at_target = 20,
107 at_rot_target = 21,
108 not_at_rot_target = 22,
109 run_time_permissions = 23,
110 changed = 24,
111 attach = 25,
112 dataserver = 26,
113 link_message = 27,
114 moving_start = 28,
115 moving_end = 29,
116 object_rez = 30,
117 remote_data = 31,
118 http_response = 32
119 }
120 public enum Operation_Table
121 {
122 NOOP = 0x0,
123 POP = 0x1,
124 POPS = 0x2,
125 POPL = 0x3,
126 POPV = 0x4,
127 POPQ = 0x5,
128 POPARG = 0x6,
129 POPIP = 0x7,
130 POPBP = 0x8,
131 POPSP = 0x9,
132 POPSLR = 0xa,
133 DUP = 0x20,
134 DUPS = 0x21,
135 DUPL = 0x22,
136 DUPV = 0x23,
137 DUPQ = 0x24,
138 STORE = 0x30,
139 STORES = 0x31,
140 STOREL = 0x32,
141 STOREV = 0x33,
142 STOREQ = 0x34,
143 STOREG = 0x35,
144 STOREGS = 0x36,
145 STOREGL = 0x37,
146 STOREGV = 0x38,
147 STOREGQ = 0x39,
148 LOADP = 0x3a,
149 LOADSP = 0x3b,
150 LOADLP = 0x3c,
151 LOADVP = 0x3d,
152 LOADQP = 0x3e,
153 LOADGP = 0x3f,
154 LOADGSP = 0x40,
155 LOADGLP = 0x41,
156 LOADGVP = 0x42,
157 LOADGQP = 0x43,
158 PUSH = 0x50,
159 PUSHS = 0x51,
160 PUSHL = 0x52,
161 PUSHV = 0x53,
162 PUSHQ = 0x54,
163 PUSHG = 0x55,
164 PUSHGS = 0x56,
165 PUSHGL = 0x57,
166 PUSHGV = 0x58,
167 PUSHGQ = 0x59,
168 PUSHIP = 0x5a,
169 PUSHBP = 0x5b,
170 PUSHSP = 0x5c,
171 PUSHARGB = 0x5d,
172 PUSHARGI = 0x5e,
173 PUSHARGF = 0x5f,
174 PUSHARGS = 0x60,
175 PUSHARGV = 0x61,
176 PUSHARGQ = 0x62,
177 PUSHE = 0x63,
178 PUSHEV = 0x64,
179 PUSHEQ = 0x65,
180 PUSHARGE = 0x66,
181 ADD = 0x70,
182 SUB = 0x71,
183 MUL = 0x72,
184 DIV = 0x73,
185 MOD = 0x74,
186 EQ = 0x75,
187 NEQ = 0x76,
188 LEQ = 0x77,
189 GEQ = 0x78,
190 LESS = 0x79,
191 GREATER = 0x7a,
192 BITAND = 0x7b,
193 BITOR = 0x7c,
194 BITXOR = 0x7d,
195 BOOLAND = 0x7e,
196 BOOLOR = 0x7f,
197 NEG = 0x80,
198 BITNOT = 0x81,
199 BOOLNOT = 0x82,
200 JUMP = 0x90,
201 JUMPIF = 0x91,
202 JUMPNIF = 0x92,
203 STATE = 0x93,
204 CALL = 0x94,
205 RETURN = 0x95,
206 CAST = 0xa0,
207 STACKTOS = 0xb0,
208 STACKTOL = 0xb1,
209 PRINT = 0xc0,
210 CALLLIB = 0xd0,
211 CALLLIB_TWO_BYTE = 0xd1,
212 SHL = 0xe0,
213 SHR = 0xe1
214 }
215 public enum BuiltIn_Functions
216 {
217 llSin = 0,
218 llCos = 1,
219 llTan = 2,
220 llAtan2 = 3,
221 llSqrt = 4,
222 llPow = 5,
223 llAbs = 6,
224 llFabs = 7,
225 llFrand = 8,
226 llFloor = 9,
227 llCeil = 10,
228 llRound = 11,
229 llVecMag = 12,
230 llVecNorm = 13,
231 llVecDist = 14,
232 llRot2Euler = 15,
233 llEuler2Rot = 16,
234 llAxes2Rot = 17,
235 llRot2Fwd = 18,
236 llRot2Left = 19,
237 llRot2Up = 20,
238 llRotBetween = 21,
239 llWhisper = 22,
240 llSay = 23,
241 llShout = 24,
242 llListen = 25,
243 llListenControl = 26,
244 llListenRemove = 27,
245 llSensor = 28,
246 llSensorRepeat = 29,
247 llSensorRemove = 30,
248 llDetectedName = 31,
249 llDetectedKey = 32,
250 llDetectedOwner = 33,
251 llDetectedType = 34,
252 llDetectedPos = 35,
253 llDetectedVel = 36,
254 llDetectedGrab = 37,
255 llDetectedRot = 38,
256 llDetectedGroup = 39,
257 llDetectedLinkNumber = 40,
258 llDie = 41,
259 llGround = 42,
260 llCloud = 43,
261 llWind = 44,
262 llSetStatus = 45,
263 llGetStatus = 46,
264 llSetScale = 47,
265 llGetScale = 48,
266 llSetColor = 49,
267 llGetAlpha = 50,
268 llSetAlpha = 51,
269 llGetColor = 52,
270 llSetTexture = 53,
271 llScaleTexture = 54,
272 llOffsetTexture = 55,
273 llRotateTexture = 56,
274 llGetTexture = 57,
275 llSetPos = 58,
276 llGetPos = 59,
277 llGetLocalPos = 60,
278 llSetRot = 61,
279 llGetRot = 62,
280 llGetLocalRot = 63,
281 llSetForce = 64,
282 llGetForce = 65,
283 llTarget = 66,
284 llTargetRemove = 67,
285 llRotTarget = 68,
286 llRotTargetRemove = 69,
287 llMoveToTarget = 70,
288 llStopMoveToTarget = 71,
289 llApplyImpulse = 72,
290 llApplyRotationalImpulse = 73,
291 llSetTorque = 74,
292 llGetTorque = 75,
293 llSetForceAndTorque = 76,
294 llGetVel = 77,
295 llGetAccel = 78,
296 llGetOmega = 79,
297 llGetTimeOfDay = 80,
298 llGetWallclock = 81,
299 llGetTime = 82,
300 llResetTime = 83,
301 llGetAndResetTime = 84,
302 llSound = 85,
303 llPlaySound = 86,
304 llLoopSound = 87,
305 llLoopSoundMaster = 88,
306 llLoopSoundSlave = 89,
307 llPlaySoundSlave = 90,
308 llTriggerSound = 91,
309 llStopSound = 92,
310 llPreloadSound = 93,
311 llGetSubString = 94,
312 llDeleteSubString = 95,
313 llInsertString = 96,
314 llToUpper = 97,
315 llToLower = 98,
316 llGiveMoney = 99,
317 llMakeExplosion = 100,
318 llMakeFountain = 101,
319 llMakeSmoke = 102,
320 llMakeFire = 103,
321 llRezObject = 104,
322 llLookAt = 105,
323 llStopLookAt = 106,
324 llSetTimerEvent = 107,
325 llSleep = 108,
326 llGetMass = 109,
327 llCollisionFilter = 110,
328 llTakeControls = 111,
329 llReleaseControls = 112,
330 llAttachToAvatar = 113,
331 llDetachFromAvatar = 114,
332 llTakeCamera = 115,
333 llReleaseCamera = 116,
334 llGetOwner = 117,
335 llInstantMessage = 118,
336 llEmail = 119,
337 llGetNextEmail = 120,
338 llGetKey = 121,
339 llSetBuoyancy = 122,
340 llSetHoverHeight = 123,
341 llStopHover = 124,
342 llMinEventDelay = 125,
343 llSoundPreload = 126,
344 llRotLookAt = 127,
345 llStringLength = 128,
346 llStartAnimation = 129,
347 llStopAnimation = 130,
348 llPointAt = 131,
349 llStopPointAt = 132,
350 llTargetOmega = 133,
351 llGetStartParameter = 134,
352 llGodLikeRezObject = 135,
353 llRequestPermissions = 136,
354 llGetPermissionsKey = 137,
355 llGetPermissions = 138,
356 llGetLinkNumber = 139,
357 llSetLinkColor = 140,
358 llCreateLink = 141,
359 llBreakLink = 142,
360 llBreakAllLinks = 143,
361 llGetLinkKey = 144,
362 llGetLinkName = 145,
363 llGetInventoryNumber = 146,
364 llGetInventoryName = 147,
365 llSetScriptState = 148,
366 llGetEnergy = 149,
367 llGiveInventory = 150,
368 llRemoveInventory = 151,
369 llSetText = 152,
370 llWater = 153,
371 llPassTouches = 154,
372 llRequestAgentData = 155,
373 llRequestInventoryData = 156,
374 llSetDamage = 157,
375 llTeleportAgentHome = 158,
376 llModifyLand = 159,
377 llCollisionSound = 160,
378 llCollisionSprite = 161,
379 llGetAnimation = 162,
380 llResetScript = 163,
381 llMessageLinked = 164,
382 llPushObject = 165,
383 llPassCollisions = 166,
384 llGetScriptName = 167,
385 llGetNumberOfSides = 168,
386 llAxisAngle2Rot = 169,
387 llRot2Axis = 170,
388 llRot2Angle = 171,
389 llAcos = 172,
390 llAsin = 173,
391 llAngleBetween = 174,
392 llGetInventoryKey = 175,
393 llAllowInventoryDrop = 176,
394 llGetSunDirection = 177,
395 llGetTextureOffset = 178,
396 llGetTextureScale = 179,
397 llGetTextureRot = 180,
398 llSubStringIndex = 181,
399 llGetOwnerKey = 182,
400 llGetCenterOfMass = 183,
401 llListSort = 184,
402 llGetListLength = 185,
403 llList2Integer = 186,
404 llList2Float = 187,
405 llList2String = 188,
406 llList2Key = 189,
407 llList2Vector = 190,
408 llList2Rot = 191,
409 llList2List = 192,
410 llDeleteSubList = 193,
411 llGetListEntryType = 194,
412 llList2CSV = 195,
413 llCSV2List = 196,
414 llListRandomize = 197,
415 llList2ListStrided = 198,
416 llGetRegionCorner = 199,
417 llListInsertList = 200,
418 llListFindList = 201,
419 llGetObjectName = 202,
420 llSetObjectName = 203,
421 llGetDate = 204,
422 llEdgeOfWorld = 205,
423 llGetAgentInfo = 206,
424 llAdjustSoundVolume = 207,
425 llSetSoundQueueing = 208,
426 llSetSoundRadius = 209,
427 llKey2Name = 210,
428 llSetTextureAnim = 211,
429 llTriggerSoundLimited = 212,
430 llEjectFromLand = 213,
431 llParseString2List = 214,
432 llOverMyLand = 215,
433 llGetLandOwnerAt = 216,
434 llGetNotecardLine = 217,
435 llGetAgentSize = 218,
436 llSameGroup = 219,
437 llUnSit = 220,
438 llGroundSlope = 221,
439 llGroundNormal = 222,
440 llGroundContour = 223,
441 llGetAttached = 224,
442 llGetFreeMemory = 225,
443 llGetRegionName = 226,
444 llGetRegionTimeDilation = 227,
445 llGetRegionFPS = 228,
446 llParticleSystem = 229,
447 llGroundRepel = 230,
448 llGiveInventoryList = 231,
449 llSetVehicleType = 232,
450 llSetVehicleFloatParam = 233,
451 llSetVehicleVectorParam = 234,
452 llSetVehicleRotationParam = 235,
453 llSetVehicleFlags = 236,
454 llRemoveVehicleFlags = 237,
455 llSitTarget = 238,
456 llAvatarOnSitTarget = 239,
457 llAddToLandPassList = 240,
458 llSetTouchText = 241,
459 llSetSitText = 242,
460 llSetCameraEyeOffset = 243,
461 llSetCameraAtOffset = 244,
462 llDumpList2String = 245,
463 llScriptDanger = 246,
464 llDialog = 247,
465 llVolumeDetect = 248,
466 llResetOtherScript = 249,
467 llGetScriptState = 250,
468 llRemoteLoadScript = 251,
469 llSetRemoteScriptAccessPin = 252,
470 llRemoteLoadScriptPin = 253,
471 llOpenRemoteDataChannel = 254,
472 llSendRemoteData = 255,
473 llRemoteDataReply = 256,
474 llCloseRemoteDataChannel = 257,
475 llMD5String = 258,
476 llSetPrimitiveParams = 259,
477 llStringToBase64 = 260,
478 llBase64ToString = 261,
479 llXorBase64Strings = 262,
480 llRemoteDataSetRegion = 263,
481 llLog10 = 264,
482 llLog = 265,
483 llGetAnimationList = 266,
484 llSetParcelMusicURL = 267,
485 llGetRootPosition = 268,
486 llGetRootRotation = 269,
487 llGetObjectDesc = 270,
488 llSetObjectDesc = 271,
489 llGetCreator = 272,
490 llGetTimestamp = 273,
491 llSetLinkAlpha = 274,
492 llGetNumberOfPrims = 275,
493 llGetNumberOfNotecardLines = 276,
494 llGetBoundingBox = 277,
495 llGetGeometricCenter = 278,
496 llGetPrimitiveParams = 279,
497 llIntegerToBase64 = 280,
498 llBase64ToInteger = 281,
499 llGetGMTclock = 282,
500 llGetSimulatorHostname = 283,
501 llSetLocalRot = 284,
502 llParseStringKeepNulls = 285,
503 llRezAtRoot = 286,
504 llGetObjectPermMask = 287,
505 llSetObjectPermMask = 288,
506 llGetInventoryPermMask = 289,
507 llSetInventoryPermMask = 290,
508 llGetInventoryCreator = 291,
509 llOwnerSay = 292,
510 llRequestSimulatorData = 293,
511 llForceMouselook = 294,
512 llGetObjectMass = 295,
513 llListReplaceList = 296,
514 llLoadURL = 297,
515 llParcelMediaCommandList = 298,
516 llParcelMediaQuery = 299,
517 llModPow = 300,
518 llGetInventoryType = 301,
519 llSetPayPrice = 302,
520 llGetCameraPos = 303,
521 llGetCameraRot = 304,
522 llSetPrimURL = 305,
523 llRefreshPrimURL = 306,
524 llEscapeURL = 307,
525 llUnescapeURL = 308,
526 llMapDestination = 309,
527 llAddToLandBanList = 310,
528 llRemoveFromLandPassList = 311,
529 llRemoveFromLandBanList = 312,
530 llSetCameraParams = 313,
531 llClearCameraParams = 314,
532 llListStatistics = 315,
533 llGetUnixTime = 316,
534 llGetParcelFlags = 317,
535 llGetRegionFlags = 318,
536 llXorBase64StringsCorrect = 319,
537 llHTTPRequest = 320,
538 llResetLandBanList = 321,
539 llResetLandPassList = 322,
540 llGetParcelPrimCount = 323,
541 llGetParcelPrimOwners = 324,
542 llGetObjectPrimCount = 325,
543 llGetParcelMaxPrims = 326,
544 llGetParcelDetails = 327
545 }
546
547 }
548}
diff --git a/OpenSim/Region/Environment/Scenes/_scripting/Engines/LSLEngine/LSLHandler/LSO_Parser.cs b/OpenSim/Region/Environment/Scenes/_scripting/Engines/LSLEngine/LSLHandler/LSO_Parser.cs
new file mode 100644
index 0000000..4ad1f83
--- /dev/null
+++ b/OpenSim/Region/Environment/Scenes/_scripting/Engines/LSLEngine/LSLHandler/LSO_Parser.cs
@@ -0,0 +1,629 @@
1/*
2* Copyright (c) Contributors, http://www.openmetaverse.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders.
4*
5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met:
7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission.
15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*
27*/
28/* Original code: Tedd Hansen */
29using System;
30using System.Collections.Generic;
31using System.Text;
32using System.IO;
33using System.Reflection;
34using System.Reflection.Emit;
35
36namespace OpenSim.Region.Scripting.LSL
37{
38 partial class LSO_Parser
39 {
40 private FileStream fs;
41 private BinaryReader br;
42 private LSO_Struct.Header myHeader;
43
44 private TypeBuilder typeBuilder;
45 private System.Collections.Generic.List<string> EventList = new System.Collections.Generic.List<string>();
46
47 /// <summary>
48 /// Parse LSO file.
49 /// Reads LSO ByteCode into memory structures.
50 /// TODO: What else does it do?
51 /// </summary>
52 /// <param name="FileName">FileName of LSO ByteCode file</param>
53 public void ParseFile(string FileName, TypeBuilder _typeBuilder)
54 {
55 typeBuilder = _typeBuilder;
56 //WorldAPI = _WorldAPI;
57 // Open
58 Common.SendToDebug("Opening filename: " + FileName);
59 fs = File.Open(FileName, FileMode.Open, FileAccess.Read, FileShare.Read);
60 br = new BinaryReader(fs, Encoding.BigEndianUnicode);
61
62
63 // The LSO Format consist of 6 major blocks: header, statics, functions, states, heap, and stack.
64
65
66 // HEADER BLOCK
67 Common.SendToDebug("Reading HEADER BLOCK at: 0");
68 fs.Seek(0, SeekOrigin.Begin);
69 myHeader = new LSO_Struct.Header();
70 myHeader.TM = BitConverter.ToUInt32(br_read(4), 0);
71 myHeader.IP = BitConverter.ToUInt32(br_read(4), 0);
72 myHeader.VN = BitConverter.ToUInt32(br_read(4), 0);
73 myHeader.BP = BitConverter.ToUInt32(br_read(4), 0);
74 myHeader.SP = BitConverter.ToUInt32(br_read(4), 0);
75 myHeader.HR = BitConverter.ToUInt32(br_read(4), 0);
76 myHeader.HP = BitConverter.ToUInt32(br_read(4), 0);
77 myHeader.CS = BitConverter.ToUInt32(br_read(4), 0);
78 myHeader.NS = BitConverter.ToUInt32(br_read(4), 0);
79 myHeader.CE = BitConverter.ToUInt32(br_read(4), 0);
80 myHeader.IE = BitConverter.ToUInt32(br_read(4), 0);
81 myHeader.ER = BitConverter.ToUInt32(br_read(4), 0);
82 myHeader.FR = BitConverter.ToUInt32(br_read(4), 0);
83 myHeader.SLR = BitConverter.ToUInt32(br_read(4), 0);
84 myHeader.GVR = BitConverter.ToUInt32(br_read(4), 0);
85 myHeader.GFR = BitConverter.ToUInt32(br_read(4), 0);
86 myHeader.PR = BitConverter.ToUInt32(br_read(4), 0);
87 myHeader.ESR = BitConverter.ToUInt32(br_read(4), 0);
88 myHeader.SR = BitConverter.ToUInt32(br_read(4), 0);
89 myHeader.NCE = BitConverter.ToUInt64(br_read(8), 0);
90 myHeader.NIE = BitConverter.ToUInt64(br_read(8), 0);
91 myHeader.NER = BitConverter.ToUInt64(br_read(8), 0);
92
93 // Print Header Block to debug
94 Common.SendToDebug("TM - Top of memory (size): " + myHeader.TM);
95 Common.SendToDebug("IP - Instruction Pointer (0=not running): " + myHeader.IP);
96 Common.SendToDebug("VN - Version number: " + myHeader.VN);
97 Common.SendToDebug("BP - Local Frame Pointer: " + myHeader.BP);
98 Common.SendToDebug("SP - Stack Pointer: " + myHeader.SP);
99 Common.SendToDebug("HR - Heap Register: " + myHeader.HR);
100 Common.SendToDebug("HP - Heap Pointer: " + myHeader.HP);
101 Common.SendToDebug("CS - Current State: " + myHeader.CS);
102 Common.SendToDebug("NS - Next State: " + myHeader.NS);
103 Common.SendToDebug("CE - Current Events: " + myHeader.CE);
104 Common.SendToDebug("IE - In Event: " + myHeader.IE);
105 Common.SendToDebug("ER - Event Register: " + myHeader.ER);
106 Common.SendToDebug("FR - Fault Register: " + myHeader.FR);
107 Common.SendToDebug("SLR - Sleep Register: " + myHeader.SLR);
108 Common.SendToDebug("GVR - Global Variable Register: " + myHeader.GVR);
109 Common.SendToDebug("GFR - Global Function Register: " + myHeader.GFR);
110 Common.SendToDebug("PR - Parameter Register: " + myHeader.PR);
111 Common.SendToDebug("ESR - Energy Supply Register: " + myHeader.ESR);
112 Common.SendToDebug("SR - State Register: " + myHeader.SR);
113 Common.SendToDebug("NCE - 64-bit Current Events: " + myHeader.NCE);
114 Common.SendToDebug("NIE - 64-bit In Events: " + myHeader.NIE);
115 Common.SendToDebug("NER - 64-bit Event Register: " + myHeader.NER);
116 Common.SendToDebug("Read position when exiting HEADER BLOCK: " + fs.Position);
117
118 // STATIC BLOCK
119 Common.SendToDebug("Reading STATIC BLOCK at: " + myHeader.GVR);
120 fs.Seek(myHeader.GVR, SeekOrigin.Begin);
121 int StaticBlockCount = 0;
122 // Read function blocks until we hit GFR
123 while (fs.Position < myHeader.GFR)
124 {
125 StaticBlockCount++;
126 Common.SendToDebug("Reading Static Block " + StaticBlockCount + " at: " + fs.Position);
127 //fs.Seek(myHeader.GVR, SeekOrigin.Begin);
128 LSO_Struct.StaticBlock myStaticBlock = new LSO_Struct.StaticBlock();
129 myStaticBlock.Static_Chunk_Header_Size = BitConverter.ToUInt32(br_read(4), 0);
130 myStaticBlock.ObjectType = br_read(1)[0];
131 Common.SendToDebug("Static Block ObjectType: " + ((LSO_Enums.Variable_Type_Codes)myStaticBlock.ObjectType).ToString());
132 myStaticBlock.Unknown = br_read(1)[0];
133 // Size of datatype varies
134 if (myStaticBlock.ObjectType != 0)
135 myStaticBlock.BlockVariable = br_read(getObjectSize(myStaticBlock.ObjectType));
136 }
137 Common.SendToDebug("Number of Static Blocks read: " + StaticBlockCount);
138
139
140 // FUNCTION BLOCK
141 // Always right after STATIC BLOCK
142 LSO_Struct.FunctionBlock myFunctionBlock = new LSO_Struct.FunctionBlock();
143 if (myHeader.GFR == myHeader.SR)
144 {
145 // If GFR and SR are at same position then there is no fuction block
146 Common.SendToDebug("No FUNCTION BLOCK found");
147 }
148 else
149 {
150 Common.SendToDebug("Reading FUNCTION BLOCK at: " + myHeader.GFR);
151 fs.Seek(myHeader.GFR, SeekOrigin.Begin);
152 myFunctionBlock.FunctionCount = BitConverter.ToUInt32(br_read(4), 0);
153 Common.SendToDebug("Number of functions in Fuction Block: " + myFunctionBlock.FunctionCount);
154 if (myFunctionBlock.FunctionCount > 0)
155 {
156 myFunctionBlock.CodeChunkPointer = new UInt32[myFunctionBlock.FunctionCount];
157 for (int i = 0; i < myFunctionBlock.FunctionCount; i++)
158 {
159 Common.SendToDebug("Reading function " + i + " at: " + fs.Position);
160 // TODO: ADD TO FUNCTION LIST (How do we identify it later?)
161 // Note! Absolute position
162 myFunctionBlock.CodeChunkPointer[i] = BitConverter.ToUInt32(br_read(4), 0) + myHeader.GFR;
163 Common.SendToDebug("Fuction " + i + " code chunk position: " + myFunctionBlock.CodeChunkPointer[i]);
164 }
165 }
166 }
167
168
169 // STATE FRAME BLOCK
170 // Always right after FUNCTION BLOCK
171 Common.SendToDebug("Reading STATE BLOCK at: " + myHeader.SR);
172 fs.Seek(myHeader.SR, SeekOrigin.Begin);
173 LSO_Struct.StateFrameBlock myStateFrameBlock = new LSO_Struct.StateFrameBlock();
174 myStateFrameBlock.StateCount = BitConverter.ToUInt32(br_read(4), 0);
175 if (myStateFrameBlock.StateCount > 0)
176 {
177 // Initialize array
178 myStateFrameBlock.StatePointer = new LSO_Struct.StatePointerBlock[myStateFrameBlock.StateCount];
179 for (int i = 0; i < myStateFrameBlock.StateCount; i++)
180 {
181 Common.SendToDebug("Reading STATE POINTER BLOCK " + (i + 1) + " at: " + fs.Position);
182 // Position is relative to state frame
183 myStateFrameBlock.StatePointer[i].Location = myHeader.SR + BitConverter.ToUInt32(br_read(4), 0);
184 myStateFrameBlock.StatePointer[i].EventMask = new System.Collections.BitArray(br_read(8));
185 Common.SendToDebug("Pointer: " + myStateFrameBlock.StatePointer[i].Location);
186 Common.SendToDebug("Total potential EventMask bits: " + myStateFrameBlock.StatePointer[i].EventMask.Count);
187
188 //// Read STATE BLOCK
189 //long CurPos = fs.Position;
190 //fs.Seek(CurPos, SeekOrigin.Begin);
191
192 }
193 }
194
195
196 // STATE BLOCK
197 // For each StateFrameBlock there is one StateBlock with multiple event handlers
198
199 if (myStateFrameBlock.StateCount > 0)
200 {
201 // Go through all State Frame Pointers found
202 for (int i = 0; i < myStateFrameBlock.StateCount; i++)
203 {
204
205 fs.Seek(myStateFrameBlock.StatePointer[i].Location, SeekOrigin.Begin);
206 Common.SendToDebug("Reading STATE BLOCK " + (i + 1) + " at: " + fs.Position);
207
208 // READ: STATE BLOCK HEADER
209 myStateFrameBlock.StatePointer[i].StateBlock = new LSO_Struct.StateBlock();
210 myStateFrameBlock.StatePointer[i].StateBlock.StartPos = (UInt32)fs.Position; // Note
211 myStateFrameBlock.StatePointer[i].StateBlock.HeaderSize = BitConverter.ToUInt32(br_read(4), 0);
212 myStateFrameBlock.StatePointer[i].StateBlock.Unknown = br_read(1)[0];
213 myStateFrameBlock.StatePointer[i].StateBlock.EndPos = (UInt32)fs.Position; // Note
214 Common.SendToDebug("State block Start Pos: " + myStateFrameBlock.StatePointer[i].StateBlock.StartPos);
215 Common.SendToDebug("State block Header Size: " + myStateFrameBlock.StatePointer[i].StateBlock.HeaderSize);
216 Common.SendToDebug("State block Header End Pos: " + myStateFrameBlock.StatePointer[i].StateBlock.EndPos);
217
218 // We need to count number of bits flagged in EventMask?
219
220
221 // for each bit in myStateFrameBlock.StatePointer[i].EventMask
222
223 // ADDING TO ALL RIGHT NOW, SHOULD LIMIT TO ONLY THE ONES IN USE
224 //TODO: Create event hooks
225 myStateFrameBlock.StatePointer[i].StateBlock.StateBlockHandlers = new LSO_Struct.StateBlockHandler[myStateFrameBlock.StatePointer[i].EventMask.Count - 1];
226 for (int ii = 0; ii < myStateFrameBlock.StatePointer[i].EventMask.Count - 1; ii++)
227 {
228
229 if (myStateFrameBlock.StatePointer[i].EventMask.Get(ii) == true)
230 {
231 // We got an event
232 // READ: STATE BLOCK HANDLER
233 Common.SendToDebug("Reading STATE BLOCK " + (i + 1) + " HANDLER matching EVENT MASK " + ii + " (" + ((LSO_Enums.Event_Mask_Values)ii).ToString() + ") at: " + fs.Position);
234 myStateFrameBlock.StatePointer[i].StateBlock.StateBlockHandlers[ii].CodeChunkPointer = myStateFrameBlock.StatePointer[i].StateBlock.EndPos + BitConverter.ToUInt32(br_read(4), 0);
235 myStateFrameBlock.StatePointer[i].StateBlock.StateBlockHandlers[ii].CallFrameSize = BitConverter.ToUInt32(br_read(4), 0);
236 Common.SendToDebug("Reading STATE BLOCK " + (i + 1) + " HANDLER EVENT MASK " + ii + " (" + ((LSO_Enums.Event_Mask_Values)ii).ToString() + ") Code Chunk Pointer: " + myStateFrameBlock.StatePointer[i].StateBlock.StateBlockHandlers[ii].CodeChunkPointer);
237 Common.SendToDebug("Reading STATE BLOCK " + (i + 1) + " HANDLER EVENT MASK " + ii + " (" + ((LSO_Enums.Event_Mask_Values)ii).ToString() + ") Call Frame Size: " + myStateFrameBlock.StatePointer[i].StateBlock.StateBlockHandlers[ii].CallFrameSize);
238 }
239 }
240 }
241 }
242
243
244
245
246 //// READ FUNCTION CODE CHUNKS
247 //// Functions + Function start pos (GFR)
248 //// TODO: Somehow be able to identify and reference this
249 //LSO_Struct.CodeChunk[] myFunctionCodeChunk;
250 //if (myFunctionBlock.FunctionCount > 0)
251 //{
252 // myFunctionCodeChunk = new LSO_Struct.CodeChunk[myFunctionBlock.FunctionCount];
253 // for (int i = 0; i < myFunctionBlock.FunctionCount; i++)
254 // {
255 // Common.SendToDebug("Reading Function Code Chunk " + i);
256 // myFunctionCodeChunk[i] = GetCodeChunk((UInt32)myFunctionBlock.CodeChunkPointer[i]);
257 // }
258
259 //}
260 // READ EVENT CODE CHUNKS
261 LSO_Struct.CodeChunk[] myEventCodeChunk;
262 if (myStateFrameBlock.StateCount > 0)
263 {
264 myEventCodeChunk = new LSO_Struct.CodeChunk[myStateFrameBlock.StateCount];
265 for (int i = 0; i < myStateFrameBlock.StateCount; i++)
266 {
267 // TODO: Somehow organize events and functions so they can be found again,
268 // two level search ain't no good
269 for (int ii = 0; ii < myStateFrameBlock.StatePointer[i].EventMask.Count - 1; ii++)
270 {
271
272
273 if (myStateFrameBlock.StatePointer[i].StateBlock.StateBlockHandlers[ii].CodeChunkPointer > 0)
274 {
275 Common.SendToDebug("Reading Event Code Chunk state " + i + ", event " + (LSO_Enums.Event_Mask_Values)ii);
276
277
278 // Override a Method / Function
279 string eventname = i + "_event_" + (LSO_Enums.Event_Mask_Values)ii;
280 Common.SendToDebug("Event Name: " + eventname);
281 if (Common.IL_ProcessCodeChunks)
282 {
283 EventList.Add(eventname);
284
285 // JUMP TO CODE PROCESSOR
286 ProcessCodeChunk(myStateFrameBlock.StatePointer[i].StateBlock.StateBlockHandlers[ii].CodeChunkPointer, typeBuilder, eventname);
287 }
288 }
289
290 }
291
292 }
293
294 }
295
296
297 // Close
298 br.Close();
299 fs.Close();
300
301 if (Common.IL_CreateFunctionList)
302 IL_INSERT_FUNCTIONLIST();
303
304 }
305
306 private LSO_Struct.HeapBlock GetHeap(UInt32 pos)
307 {
308 // HEAP BLOCK
309 // TODO:? Special read for strings/keys (null terminated) and lists (pointers to other HEAP entries)
310 Common.SendToDebug("Reading HEAP BLOCK at: " + pos);
311 fs.Seek(pos, SeekOrigin.Begin);
312
313 LSO_Struct.HeapBlock myHeapBlock = new LSO_Struct.HeapBlock();
314 myHeapBlock.DataBlockSize = BitConverter.ToUInt32(br_read(4), 0);
315 myHeapBlock.ObjectType = br_read(1)[0];
316 myHeapBlock.ReferenceCount = BitConverter.ToUInt16(br_read(2), 0);
317 myHeapBlock.Data = br_read(getObjectSize(myHeapBlock.ObjectType));
318
319 Common.SendToDebug("Heap Block Data Block Size: " + myHeapBlock.DataBlockSize);
320 Common.SendToDebug("Heap Block ObjectType: " + ((LSO_Enums.Variable_Type_Codes)myHeapBlock.ObjectType).ToString());
321 Common.SendToDebug("Heap Block Reference Count: " + myHeapBlock.ReferenceCount);
322
323 return myHeapBlock;
324 }
325 private byte[] br_read(int len)
326 {
327 if (len <= 0)
328 return null;
329
330 try
331 {
332 byte[] bytes = new byte[len];
333 for (int i = len - 1; i > -1; i--)
334 bytes[i] = br.ReadByte();
335 return bytes;
336 }
337 catch (Exception e)
338 {
339 Common.SendToDebug("Exception: " + e.ToString());
340 throw (e);
341 }
342 }
343 //private byte[] br_read_smallendian(int len)
344 //{
345 // byte[] bytes = new byte[len];
346 // br.Read(bytes,0, len);
347 // return bytes;
348 //}
349 private Type getLLObjectType(byte objectCode)
350 {
351 switch ((LSO_Enums.Variable_Type_Codes)objectCode)
352 {
353 case LSO_Enums.Variable_Type_Codes.Void: return typeof(void);
354 case LSO_Enums.Variable_Type_Codes.Integer: return typeof(UInt32);
355 case LSO_Enums.Variable_Type_Codes.Float: return typeof(float);
356 case LSO_Enums.Variable_Type_Codes.String: return typeof(string);
357 case LSO_Enums.Variable_Type_Codes.Key: return typeof(string);
358 case LSO_Enums.Variable_Type_Codes.Vector: return typeof(LSO_Enums.Vector);
359 case LSO_Enums.Variable_Type_Codes.Rotation: return typeof(LSO_Enums.Rotation);
360 case LSO_Enums.Variable_Type_Codes.List:
361 Common.SendToDebug("TODO: List datatype not implemented yet!");
362 return typeof(System.Collections.ArrayList);
363 default:
364 Common.SendToDebug("Lookup of LSL datatype " + objectCode + " to .Net datatype failed: Unknown LSL datatype. Defaulting to object.");
365 return typeof(object);
366 }
367 }
368 private int getObjectSize(byte ObjectType)
369 {
370 switch (ObjectType)
371 {
372 case 1:
373 case 2:
374 case 3:
375 case 4:
376 case 7:
377 return 4;
378 case 5:
379 return 12;
380 case 6:
381 return 16;
382 default:
383 return 0;
384 }
385 }
386 private string Read_String()
387 {
388 string ret = "";
389 byte reader = br_read(1)[0];
390 while (reader != 0x000)
391 {
392 ret += (char)reader;
393 reader = br_read(1)[0];
394 }
395 return ret;
396 }
397
398 /// <summary>
399 /// Reads a code chunk and creates IL
400 /// </summary>
401 /// <param name="pos">Absolute position in file. REMEMBER TO ADD myHeader.GFR!</param>
402 /// <param name="typeBuilder">TypeBuilder for assembly</param>
403 /// <param name="eventname">Name of event (function) to generate</param>
404 private void ProcessCodeChunk(UInt32 pos, TypeBuilder typeBuilder, string eventname)
405 {
406
407 LSO_Struct.CodeChunk myCodeChunk = new LSO_Struct.CodeChunk();
408
409 Common.SendToDebug("Reading Function Code Chunk at: " + pos);
410 fs.Seek(pos, SeekOrigin.Begin);
411 myCodeChunk.CodeChunkHeaderSize = BitConverter.ToUInt32(br_read(4), 0);
412 Common.SendToDebug("CodeChunk Header Size: " + myCodeChunk.CodeChunkHeaderSize);
413 // Read until null
414 myCodeChunk.Comment = Read_String();
415 Common.SendToDebug("Function comment: " + myCodeChunk.Comment);
416 myCodeChunk.ReturnType = br_read(1)[0];
417 Common.SendToDebug("Return type #" + myCodeChunk.ReturnType + ": " + (getLLObjectType(myCodeChunk.ReturnType).ToString()));
418
419 // TODO: How to determine number of codechunks -- does this method work?
420 myCodeChunk.CodeChunkArguments = new System.Collections.Generic.List<LSO_Struct.CodeChunkArgument>();
421 byte reader = br_read(1)[0];
422 reader = br_read(1)[0];
423
424 // NOTE ON CODE CHUNK ARGUMENTS
425 // This determins type definition
426 int ccount = 0;
427 while (reader != 0x000)
428 {
429 ccount++;
430 Common.SendToDebug("Reading Code Chunk Argument " + ccount);
431 LSO_Struct.CodeChunkArgument CCA = new LSO_Struct.CodeChunkArgument();
432 CCA.FunctionReturnType = reader;
433 reader = br_read(1)[0];
434 CCA.NullString = reader;
435 myCodeChunk.CodeChunkArguments.Add(CCA);
436 Common.SendToDebug("Code Chunk Argument " + ccount + " type: " + (LSO_Enums.Variable_Type_Codes)CCA.FunctionReturnType);
437 }
438 // Create string array
439 Type[] MethodArgs = new Type[myCodeChunk.CodeChunkArguments.Count];
440 for (int _ic = 0; _ic < myCodeChunk.CodeChunkArguments.Count; _ic++)
441 {
442 MethodArgs[_ic] = getLLObjectType(myCodeChunk.CodeChunkArguments[_ic].FunctionReturnType);
443 Common.SendToDebug("Method argument " + _ic + ": " + getLLObjectType(myCodeChunk.CodeChunkArguments[_ic].FunctionReturnType).ToString());
444 }
445 // End marker is 0x000
446 myCodeChunk.EndMarker = reader;
447
448
449 //
450 // Emit: START OF METHOD (FUNCTION)
451 //
452
453 Common.SendToDebug("CLR:" + eventname + ":MethodBuilder methodBuilder = typeBuilder.DefineMethod...");
454 MethodBuilder methodBuilder = typeBuilder.DefineMethod(eventname,
455 MethodAttributes.Public,
456 typeof(void),
457 MethodArgs);
458 //typeof(void), //getLLObjectType(myCodeChunk.ReturnType),
459 // new Type[] { typeof(object) }, //);
460
461 //Common.SendToDebug("CLR:" + eventname + ":typeBuilder.DefineMethodOverride(methodBuilder...");
462 //typeBuilder.DefineMethodOverride(methodBuilder,
463 // typeof(LSL_CLRInterface.LSLScript).GetMethod(eventname));
464
465 // Create the IL generator
466
467 Common.SendToDebug("CLR:" + eventname + ":ILGenerator il = methodBuilder.GetILGenerator();");
468 ILGenerator il = methodBuilder.GetILGenerator();
469
470
471 if (Common.IL_UseTryCatch)
472 IL_INSERT_TRY(il, eventname);
473
474
475
476 // Push Console.WriteLine command to stack ... Console.WriteLine("Hello World!");
477 //Common.SendToDebug("CLR:" + eventname + ":il.Emit(OpCodes.Call...");
478 //il.Emit(OpCodes.Call, typeof(Console).GetMethod
479 // ("WriteLine", new Type[] { typeof(string) }));
480
481 //Common.SendToDebug("STARTUP: il.Emit(OpCodes.Ldc_I4_S, 0);");
482
483 //il.Emit(OpCodes.Ldc_I4_S, 0);
484 for (int _ic = 0; _ic < myCodeChunk.CodeChunkArguments.Count; _ic++)
485 {
486 Common.SendToDebug("PARAMS: il.Emit(OpCodes.Ldarg, " + _ic + ");");
487 il.Emit(OpCodes.Ldarg, _ic);
488 }
489
490
491
492 //
493 // CALLING OPCODE PROCESSOR, one command at the time TO GENERATE IL
494 //
495 bool FoundRet = false;
496 while (FoundRet == false)
497 {
498 FoundRet = LSL_PROCESS_OPCODE(il);
499 }
500
501
502 if (Common.IL_UseTryCatch)
503 IL_INSERT_END_TRY(il, eventname);
504
505 // Emit: RETURN FROM METHOD
506 il.Emit(OpCodes.Ret);
507
508 return;
509
510 }
511
512 private void IL_INSERT_FUNCTIONLIST()
513 {
514
515 Common.SendToDebug("Creating function list");
516
517
518 string eventname = "GetFunctions";
519
520 Common.SendToDebug("Creating IL " + eventname);
521 // Define a private String field.
522 //FieldBuilder myField = myTypeBuilder.DefineField("EventList", typeof(String[]), FieldAttributes.Public);
523
524
525 //FieldBuilder mem = typeBuilder.DefineField("mem", typeof(Array), FieldAttributes.Private);
526
527
528
529 MethodBuilder methodBuilder = typeBuilder.DefineMethod(eventname,
530 MethodAttributes.Public,
531 typeof(string[]),
532 null);
533
534 //typeBuilder.DefineMethodOverride(methodBuilder,
535 // typeof(LSL_CLRInterface.LSLScript).GetMethod(eventname));
536
537 ILGenerator il = methodBuilder.GetILGenerator();
538
539
540
541
542 // IL_INSERT_TRY(il, eventname);
543
544 // // Push string to stack
545 // il.Emit(OpCodes.Ldstr, "Inside " + eventname);
546
547 //// Push Console.WriteLine command to stack ... Console.WriteLine("Hello World!");
548 //il.Emit(OpCodes.Call, typeof(Console).GetMethod
549 // ("WriteLine", new Type[] { typeof(string) }));
550
551 //initIL.Emit(OpCodes.Newobj, typeof(string[]));
552
553 //string[] MyArray = new string[2] { "TestItem1" , "TestItem2" };
554
555 il.DeclareLocal(typeof(string[]));
556
557 //il.Emit(OpCodes.Ldarg_0);
558 il.Emit(OpCodes.Ldc_I4, EventList.Count); // Specify array length
559 il.Emit(OpCodes.Newarr, typeof(String)); // create new string array
560 il.Emit(OpCodes.Stloc_0); // Store array as local variable 0 in stack
561
562 for (int lv = 0; lv < EventList.Count; lv++)
563 {
564 il.Emit(OpCodes.Ldloc_0); // Load local variable 0 onto stack
565 il.Emit(OpCodes.Ldc_I4, lv); // Push index position
566 il.Emit(OpCodes.Ldstr, EventList[lv]); // Push value
567 il.Emit(OpCodes.Stelem_Ref); // Perform array[index] = value
568 }
569
570
571
572 // IL_INSERT_END_TRY(il, eventname);
573
574 il.Emit(OpCodes.Ldloc_0); // Load local variable 0 onto stack
575 il.Emit(OpCodes.Ret); // Return
576
577 }
578
579
580 private void IL_INSERT_TRY(ILGenerator il, string eventname)
581 {
582 /*
583 * CLR TRY
584 */
585 //Common.SendToDebug("CLR:" + eventname + ":il.BeginExceptionBlock()");
586 il.BeginExceptionBlock();
587
588 // Push "Hello World!" string to stack
589 //Common.SendToDebug("CLR:" + eventname + ":il.Emit(OpCodes.Ldstr...");
590 il.Emit(OpCodes.Ldstr, "Starting CLR dynamic execution of: " + eventname);
591
592 }
593
594 private void IL_INSERT_END_TRY(ILGenerator il, string eventname)
595 {
596 /*
597 * CATCH
598 */
599 Common.SendToDebug("CLR:" + eventname + ":il.BeginCatchBlock(typeof(Exception));");
600 il.BeginCatchBlock(typeof(Exception));
601
602 // Push "Hello World!" string to stack
603 Common.SendToDebug("CLR:" + eventname + ":il.Emit(OpCodes.Ldstr...");
604 il.Emit(OpCodes.Ldstr, "Execption executing dynamic CLR function " + eventname + ": ");
605
606 //call void [mscorlib]System.Console::WriteLine(string)
607 Common.SendToDebug("CLR:" + eventname + ":il.Emit(OpCodes.Call...");
608 il.Emit(OpCodes.Call, typeof(Console).GetMethod
609 ("Write", new Type[] { typeof(string) }));
610
611 //callvirt instance string [mscorlib]System.Exception::get_Message()
612 Common.SendToDebug("CLR:" + eventname + ":il.Emit(OpCodes.Callvirt...");
613 il.Emit(OpCodes.Callvirt, typeof(Exception).GetMethod
614 ("get_Message"));
615
616 //call void [mscorlib]System.Console::WriteLine(string)
617 Common.SendToDebug("CLR:" + eventname + ":il.Emit(OpCodes.Call...");
618 il.Emit(OpCodes.Call, typeof(Console).GetMethod
619 ("WriteLine", new Type[] { typeof(string) }));
620
621 /*
622 * CLR END TRY
623 */
624 //Common.SendToDebug("CLR:" + eventname + ":il.EndExceptionBlock();");
625 il.EndExceptionBlock();
626 }
627
628 }
629}
diff --git a/OpenSim/Region/Environment/Scenes/_scripting/Engines/LSLEngine/LSLHandler/LSO_Struct.cs b/OpenSim/Region/Environment/Scenes/_scripting/Engines/LSLEngine/LSLHandler/LSO_Struct.cs
new file mode 100644
index 0000000..4d9be5d
--- /dev/null
+++ b/OpenSim/Region/Environment/Scenes/_scripting/Engines/LSLEngine/LSLHandler/LSO_Struct.cs
@@ -0,0 +1,133 @@
1/*
2* Copyright (c) Contributors, http://www.openmetaverse.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders.
4*
5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met:
7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission.
15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*
27*/
28/* Original code: Tedd Hansen */
29
30using System;
31using System.Collections.Generic;
32using System.Text;
33
34namespace OpenSim.Region.Scripting.LSL
35{
36 static class LSO_Struct
37 {
38
39 public struct Header
40 {
41 public UInt32 TM;
42 public UInt32 IP;
43 public UInt32 VN;
44 public UInt32 BP;
45 public UInt32 SP;
46 public UInt32 HR;
47 public UInt32 HP;
48 public UInt32 CS;
49 public UInt32 NS;
50 public UInt32 CE;
51 public UInt32 IE;
52 public UInt32 ER;
53 public UInt32 FR;
54 public UInt32 SLR;
55 public UInt32 GVR;
56 public UInt32 GFR;
57 public UInt32 PR;
58 public UInt32 ESR;
59 public UInt32 SR;
60 public UInt64 NCE;
61 public UInt64 NIE;
62 public UInt64 NER;
63 }
64
65 public struct StaticBlock
66 {
67 public UInt32 Static_Chunk_Header_Size;
68 public byte ObjectType;
69 public byte Unknown;
70 public byte[] BlockVariable;
71 }
72 /* Not actually a structure
73 public struct StaticBlockVariable
74 {
75 public UInt32 Integer1;
76 public UInt32 Float1;
77 public UInt32 HeapPointer_String;
78 public UInt32 HeapPointer_Key;
79 public byte[] Vector_12;
80 public byte[] Rotation_16;
81 public UInt32 Pointer_List_Structure;
82 } */
83 public struct HeapBlock
84 {
85 public UInt32 DataBlockSize;
86 public byte ObjectType;
87 public UInt16 ReferenceCount;
88 public byte[] Data;
89 }
90 public struct StateFrameBlock
91 {
92 public UInt32 StateCount;
93 public StatePointerBlock[] StatePointer;
94 }
95 public struct StatePointerBlock
96 {
97 public UInt32 Location;
98 public System.Collections.BitArray EventMask;
99 public StateBlock StateBlock;
100 }
101 public struct StateBlock
102 {
103 public UInt32 StartPos;
104 public UInt32 EndPos;
105 public UInt32 HeaderSize;
106 public byte Unknown;
107 public StateBlockHandler[] StateBlockHandlers;
108 }
109 public struct StateBlockHandler
110 {
111 public UInt32 CodeChunkPointer;
112 public UInt32 CallFrameSize;
113 }
114 public struct FunctionBlock
115 {
116 public UInt32 FunctionCount;
117 public UInt32[] CodeChunkPointer;
118 }
119 public struct CodeChunk
120 {
121 public UInt32 CodeChunkHeaderSize;
122 public string Comment;
123 public System.Collections.Generic.List<CodeChunkArgument> CodeChunkArguments;
124 public byte EndMarker;
125 public byte ReturnType;
126 }
127 public struct CodeChunkArgument
128 {
129 public byte FunctionReturnType;
130 public byte NullString;
131 }
132 }
133}
diff --git a/OpenSim/Region/Environment/Scenes/_scripting/Engines/LSLEngine/LSLScript.cs b/OpenSim/Region/Environment/Scenes/_scripting/Engines/LSLEngine/LSLScript.cs
new file mode 100644
index 0000000..49357f5
--- /dev/null
+++ b/OpenSim/Region/Environment/Scenes/_scripting/Engines/LSLEngine/LSLScript.cs
@@ -0,0 +1,33 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4
5using OpenSim.Region.Scripting;
6using OpenSim.Region.Scripting.LSL;
7
8namespace OpenSim.Region.Scripting.LSL
9{
10 class LSLScript : IScript
11 {
12 ScriptInfo scriptInfo;
13 LSL.Engine lindenScriptEngine;
14
15 public LSLScript(string filename, libsecondlife.LLUUID taskObject)
16 {
17 scriptInfo.CreateTaskAPI(taskObject);
18
19 lindenScriptEngine = new Engine();
20 lindenScriptEngine.Start(filename);
21 }
22
23 public void Initialise(ScriptInfo info)
24 {
25 scriptInfo = info;
26 }
27
28 public string getName()
29 {
30 return "LSL Script";
31 }
32 }
33}
diff --git a/OpenSim/Region/Environment/Scenes/_scripting/Engines/LSLEngine/LSLScriptEngine.cs b/OpenSim/Region/Environment/Scenes/_scripting/Engines/LSLEngine/LSLScriptEngine.cs
new file mode 100644
index 0000000..c232c2f
--- /dev/null
+++ b/OpenSim/Region/Environment/Scenes/_scripting/Engines/LSLEngine/LSLScriptEngine.cs
@@ -0,0 +1,27 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4
5using OpenSim.Region.Scripting;
6using OpenSim.Region.Scripting.LSL;
7
8namespace OpenSim.Region.Scripting
9{
10 public class LSLEngine : IScriptCompiler
11 {
12 public string FileExt()
13 {
14 return ".lso";
15 }
16
17 public Dictionary<string, IScript> compile(string filename)
18 {
19 LSLScript script = new LSLScript(filename, libsecondlife.LLUUID.Zero);
20 Dictionary<string, IScript> returns = new Dictionary<string, IScript>();
21
22 returns.Add(filename, script);
23
24 return returns;
25 }
26 }
27} \ No newline at end of file
diff --git a/OpenSim/Region/Environment/Scenes/_scripting/Script.cs b/OpenSim/Region/Environment/Scenes/_scripting/Script.cs
new file mode 100644
index 0000000..40825c0
--- /dev/null
+++ b/OpenSim/Region/Environment/Scenes/_scripting/Script.cs
@@ -0,0 +1,64 @@
1/*
2* Copyright (c) Contributors, http://www.openmetaverse.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders.
4*
5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met:
7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission.
15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*
27*/
28using OpenSim.Region.Environment.Scenes;
29
30namespace OpenSim.Region.Scripting
31{
32 public interface IScript
33 {
34 void Initialise(ScriptInfo scriptInfo);
35 string getName();
36 }
37
38 public class TestScript : IScript
39 {
40 ScriptInfo script;
41
42 public string getName()
43 {
44 return "TestScript 0.1";
45 }
46
47 public void Initialise(ScriptInfo scriptInfo)
48 {
49 script = scriptInfo;
50 script.events.OnFrame += new EventManager.OnFrameDelegate(events_OnFrame);
51 script.events.OnNewPresence += new EventManager.OnNewPresenceDelegate(events_OnNewPresence);
52 }
53
54 void events_OnNewPresence(ScenePresence presence)
55 {
56 script.logger.Verbose("Hello " + presence.firstname.ToString() + "!");
57 }
58
59 void events_OnFrame()
60 {
61 //script.logger.Verbose("Hello World!");
62 }
63 }
64}
diff --git a/OpenSim/Region/Environment/Scenes/_scripting/ScriptAPI.cs b/OpenSim/Region/Environment/Scenes/_scripting/ScriptAPI.cs
new file mode 100644
index 0000000..b3a804d
--- /dev/null
+++ b/OpenSim/Region/Environment/Scenes/_scripting/ScriptAPI.cs
@@ -0,0 +1,32 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4using Key = libsecondlife.LLUUID;
5using Rotation = libsecondlife.LLQuaternion;
6using Vector = libsecondlife.LLVector3;
7using LSLList = System.Collections.Generic.List<string>;
8
9
10using OpenSim.Region.Environment.Scenes;
11
12namespace OpenSim.Region.Scripting
13{
14 // This class is to be used for engines which may not be able to access the Scene directly.
15 // Scene access is preffered, but obviously not possible on some non-.NET languages.
16 public class ScriptAPI
17 {
18 Scene scene;
19 ScriptInterpretedAPI interpretedAPI;
20
21 public ScriptAPI(Scene world, Key taskID)
22 {
23 scene = world;
24 interpretedAPI = new ScriptInterpretedAPI(world, taskID);
25 }
26
27 public Object CallMethod(String method, Object[] args)
28 {
29 return null;
30 }
31 }
32}
diff --git a/OpenSim/Region/Environment/Scenes/_scripting/ScriptInfo.cs b/OpenSim/Region/Environment/Scenes/_scripting/ScriptInfo.cs
new file mode 100644
index 0000000..35a6d9f
--- /dev/null
+++ b/OpenSim/Region/Environment/Scenes/_scripting/ScriptInfo.cs
@@ -0,0 +1,63 @@
1/*
2* Copyright (c) Contributors, http://www.openmetaverse.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders.
4*
5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met:
7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission.
15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*
27*/
28using OpenSim.Framework.Console;
29using OpenSim.Region.Environment.Scenes;
30
31namespace OpenSim.Region.Scripting
32{
33 /// <summary>
34 /// Class which provides access to the world
35 /// </summary>
36 public class ScriptInfo
37 {
38 // Reference to world.eventsManager provided for convenience
39 public EventManager events;
40
41 // The main world
42 public Scene world;
43
44 // The console
45 public LogBase logger;
46
47 // API Access
48 public ScriptAPI api;
49
50 public ScriptInfo(Scene scene)
51 {
52 world = scene;
53 events = world.EventManager;
54 logger = MainLog.Instance;
55 api = new ScriptAPI(world, libsecondlife.LLUUID.Zero);
56 }
57
58 public void CreateTaskAPI(libsecondlife.LLUUID task)
59 {
60 api = new ScriptAPI(world, task);
61 }
62 }
63}
diff --git a/OpenSim/Region/Environment/Scenes/_scripting/ScriptInterpretedAPI.cs b/OpenSim/Region/Environment/Scenes/_scripting/ScriptInterpretedAPI.cs
new file mode 100644
index 0000000..284ae74
--- /dev/null
+++ b/OpenSim/Region/Environment/Scenes/_scripting/ScriptInterpretedAPI.cs
@@ -0,0 +1,266 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4using Key = libsecondlife.LLUUID;
5using Rotation = libsecondlife.LLQuaternion;
6using Vector = libsecondlife.LLVector3;
7using LSLList = System.Collections.Generic.List<string>;
8
9using OpenSim.Region.Environment.Scenes;
10using OpenSim.Region.Environment.LandManagement;
11
12namespace OpenSim.Region.Scripting
13{
14 /// <summary>
15 /// A class inteded to act as an API for LSL-styled interpreted languages
16 /// </summary>
17 /// <remarks>Avoid at all costs. This should ONLY be used for LSL.</remarks>
18 class ScriptInterpretedAPI
19 {
20 protected libsecondlife.LLUUID m_object;
21 protected Scene m_scene;
22
23 /// <summary>
24 /// The scene in which this script is acting
25 /// </summary>
26 public Scene World
27 {
28 get { return m_scene; }
29 }
30
31 /// <summary>
32 /// The id of the object our script is supposed to be acting in
33 /// </summary>
34 public Key ObjectID
35 {
36 get { return m_object; }
37 }
38
39 /// <summary>
40 /// The object our script is supposed to be in
41 /// </summary>
42 public SceneObject Task
43 {
44 get { return World.Objects[ObjectID]; }
45 }
46
47 /// <summary>
48 /// Creates a new ScriptInterpretedAPI for a specified object
49 /// </summary>
50 /// <param name="world">The scene the object is located in</param>
51 /// <param name="member">The specific member being 'occupied' by the script</param>
52 public ScriptInterpretedAPI(Scene world, libsecondlife.LLUUID member)
53 {
54 m_scene = world;
55 m_object = member;
56 }
57
58 /// <summary>
59 /// Returns the absolute number of a integer value.
60 /// </summary>
61 /// <param name="val">Input</param>
62 /// <returns>Absolute number of input</returns>
63 public int osAbs(int val)
64 {
65 return Math.Abs(val);
66 }
67
68 public float osAcos(float val)
69 {
70 return (float)Math.Acos(val);
71 }
72
73 [Obsolete("Unimplemented")]
74 public void osAddToLandPassList(Key avatar, float hours)
75 {
76 Vector myPosition = Task.Pos;
77 Land myParcel = World.LandManager.getLandObject(myPosition.X, myPosition.Y);
78
79 OpenSim.Framework.Console.MainLog.Instance.Warn("script", "Unimplemented function called by script: osAddToLandPassList(Key avatar, float hours)");
80 return;
81 }
82
83 [Obsolete("Unimplemented")]
84 public void osAdjustSoundVolume(float volume)
85 {
86 OpenSim.Framework.Console.MainLog.Instance.Warn("script", "Unimplemented function called by script: osAdjustSoundVolume(float volume)");
87 return;
88 }
89
90 [Obsolete("Unimplemented")]
91 public void osAllowInventoryDrop(int add)
92 {
93 return;
94 }
95
96 [Obsolete("Unimplemented")]
97 public float osAngleBetween(Rotation a, Rotation b)
98 {
99 Axiom.Math.Quaternion axA = new Axiom.Math.Quaternion(a.W, a.X, a.Y, a.Z);
100 Axiom.Math.Quaternion axB = new Axiom.Math.Quaternion(b.W, b.X, b.Y, b.Z);
101
102 return 0;
103 }
104
105 [Obsolete("Unimplemented")]
106 public void osApplyImpulse(Vector force, int local)
107 {
108 return;
109 }
110
111 [Obsolete("Unimplemented")]
112 public void osApplyRotationalImpulse(Vector force, int local)
113 {
114 return;
115 }
116
117 public float osAsin(float val)
118 {
119 return (float)Math.Asin(val);
120 }
121
122 public float osAtan2(float x, float y)
123 {
124 return (float)Math.Atan2(x, y);
125 }
126
127 [Obsolete("Unimplemented")]
128 public void osAttachToAvatar(Key avatar, int attachmentPoint)
129 {
130 return;
131 }
132
133 [Obsolete("Unimplemented")]
134 public Key osAvatarOnSitTarget()
135 {
136 //TODO: Follow this as Children is chanced to be of type entity to support ScenePresences
137 /*
138 foreach (KeyValuePair<Key, EntityBase> Child in Task.Children)
139 {
140 if (Child.Value is ScenePresence)
141 {
142 return Child.Value.uuid;
143 }
144 }
145 */
146
147 return Key.Zero;
148 }
149
150 public Rotation osAxes2Rot(Vector fwd, Vector left, Vector up)
151 {
152 Axiom.Math.Quaternion axQ = new Axiom.Math.Quaternion();
153 Axiom.Math.Vector3 axFwd = new Axiom.Math.Vector3(fwd.X, fwd.Y, fwd.Z);
154 Axiom.Math.Vector3 axLeft = new Axiom.Math.Vector3(left.X, left.Y, left.Z);
155 Axiom.Math.Vector3 axUp = new Axiom.Math.Vector3(up.X, up.Y, up.Z);
156
157 axQ.FromAxes(axFwd, axLeft, axUp);
158
159 return new Rotation(axQ.x, axQ.y, axQ.z, axQ.w);
160 }
161
162 public Rotation osAxisAngle2Rot(Vector axis, float angle)
163 {
164 Axiom.Math.Quaternion axQ = Axiom.Math.Quaternion.FromAngleAxis(angle, new Axiom.Math.Vector3(axis.X, axis.Y, axis.Z));
165
166 return new Rotation(axQ.x, axQ.y, axQ.z, axQ.w);
167 }
168
169 public string osBase64ToString(string str)
170 {
171 Encoding enc = System.Text.Encoding.UTF8;
172 return enc.GetString(Convert.FromBase64String(str));
173 }
174
175 [Obsolete("Unimplemented")]
176 public void osBreakAllLinks()
177 {
178 return;
179 }
180
181 [Obsolete("Unimplemented")]
182 public void osBreakLink()
183 {
184 return;
185 }
186
187 public LSLList osCSV2List(string src)
188 {
189 LSLList retVal = new LSLList();
190 retVal.AddRange(src.Split(','));
191
192 return retVal;
193 }
194
195 public int osCeil(float val)
196 {
197 return (int)Math.Ceiling(val);
198 }
199
200 [Obsolete("Unimplemented")]
201 public void osCloseRemoteDataChannel(Key channel)
202 {
203 return;
204 }
205
206 [Obsolete("Unimplemented")]
207 public float osCloud(Vector offset)
208 {
209 return 0.0f;
210 }
211
212 [Obsolete("Unimplemented")]
213 public void osCollisionFilter(string name, Key id, int accept)
214 {
215 return;
216 }
217
218 [Obsolete("Unimplemented")]
219 public void osCollisionSprite(string impact_sprite)
220 {
221 return;
222 }
223
224 public float osCos(float theta)
225 {
226 return (float)Math.Cos(theta);
227 }
228
229 public void osCreateLink(Key target, int parent)
230 {
231 if(World.Entities[target] is SceneObject)
232 Task.AddNewChildPrims((SceneObject)World.Entities[target]);
233
234 return;
235 }
236
237 [Obsolete("Partially Unimplemented")]
238 public LSLList osDeleteSubList(LSLList src, int start, int end)
239 {
240 if (start < 0 || end < 0)
241 {
242 throw new Exception("Unsupported at this time.");
243 }
244
245 src.RemoveRange(start, start - end + 1);
246 return src;
247 }
248
249 [Obsolete("Partially Unimplemented")]
250 public string osDeleteSubString(string src, int start, int end)
251 {
252 if (start < 0 || end < 0)
253 {
254 throw new Exception("Unsupported at this time.");
255 }
256
257 return src.Remove(start, start - end + 1);
258 }
259
260 [Obsolete("Unimplemented")]
261 public void osDetachFromAvatar(Key avatar)
262 {
263 return;
264 }
265 }
266}
diff --git a/OpenSim/Region/Environment/Scenes/_scripting/ScriptInterpretedEvents.cs b/OpenSim/Region/Environment/Scenes/_scripting/ScriptInterpretedEvents.cs
new file mode 100644
index 0000000..41fe9c5
--- /dev/null
+++ b/OpenSim/Region/Environment/Scenes/_scripting/ScriptInterpretedEvents.cs
@@ -0,0 +1,23 @@
1using System;
2using System.Collections.Generic;
3using System.Text;
4using OpenSim.Region.Environment.Scenes;
5using libsecondlife;
6using Key = libsecondlife.LLUUID;
7
8namespace OpenSim.Region.Scripting
9{
10
11 public class ScriptInterpretedEvents
12 {
13 public delegate void OnTouchStartDelegate(Key user);
14 public event OnTouchStartDelegate OnTouchStart;
15
16
17 public void TriggerTouchStart(Key user)
18 {
19 if (OnTouchStart != null)
20 OnTouchStart(user);
21 }
22 }
23}
diff --git a/OpenSim/Region/Environment/Scenes/_scripting/ScriptManager.cs b/OpenSim/Region/Environment/Scenes/_scripting/ScriptManager.cs
new file mode 100644
index 0000000..27e831b
--- /dev/null
+++ b/OpenSim/Region/Environment/Scenes/_scripting/ScriptManager.cs
@@ -0,0 +1,107 @@
1/*
2* Copyright (c) Contributors, http://www.openmetaverse.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders.
4*
5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met:
7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission.
15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*
27*/
28using System.Collections.Generic;
29using OpenSim.Framework.Console;
30using OpenSim.Region.Environment.Scenes;
31
32namespace OpenSim.Region.Scripting
33{
34 public class ScriptManager
35 {
36 List<IScript> scripts = new List<IScript>();
37 Scene scene;
38 Dictionary<string, IScriptCompiler> compilers = new Dictionary<string, IScriptCompiler>();
39
40 private void LoadFromCompiler(Dictionary<string, IScript> compiledscripts)
41 {
42 foreach (KeyValuePair<string, IScript> script in compiledscripts)
43 {
44 ScriptInfo scriptInfo = new ScriptInfo(scene); // Since each script could potentially corrupt their access with a stray assignment, making a new one for each script.
45 MainLog.Instance.Verbose("Loading " + script.Key);
46 script.Value.Initialise(scriptInfo);
47 scripts.Add(script.Value);
48 }
49 MainLog.Instance.Verbose("Finished loading " + compiledscripts.Count.ToString() + " script(s)");
50 }
51
52 public ScriptManager(Scene world)
53 {
54 scene = world;
55
56 // Default Engines
57 CSharpScriptEngine csharpCompiler = new CSharpScriptEngine();
58 compilers.Add(csharpCompiler.FileExt(),csharpCompiler);
59
60 JScriptEngine jscriptCompiler = new JScriptEngine();
61 compilers.Add(jscriptCompiler.FileExt(), jscriptCompiler);
62
63 JavaEngine javaCompiler = new JavaEngine();
64 compilers.Add(javaCompiler.FileExt(), javaCompiler);
65 }
66
67 public void Compile(string filename)
68 {
69 foreach (KeyValuePair<string, IScriptCompiler> compiler in compilers)
70 {
71 if (filename.EndsWith(compiler.Key))
72 {
73 LoadFromCompiler(compiler.Value.compile(filename));
74 break;
75 }
76 }
77 }
78
79 public void RunScriptCmd(string[] args)
80 {
81 switch (args[0])
82 {
83 case "load":
84 Compile(args[1]);
85 break;
86
87 default:
88 MainLog.Instance.Error("Unknown script command");
89 break;
90 }
91 }
92
93 public void AddPreCompiledScript(IScript script)
94 {
95 MainLog.Instance.Verbose("Loading script " + script.getName());
96 ScriptInfo scriptInfo = new ScriptInfo(scene); // Since each script could potentially corrupt their access with a stray assignment, making a new one for each script.
97 script.Initialise(scriptInfo);
98 scripts.Add(script);
99 }
100 }
101
102 interface IScriptCompiler
103 {
104 Dictionary<string,IScript> compile(string filename);
105 string FileExt();
106 }
107}