aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ScriptEngine/LSOEngine/LSO/LSL_OPCODE_IL_processor.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/ScriptEngine/LSOEngine/LSO/LSL_OPCODE_IL_processor.cs')
-rw-r--r--OpenSim/Region/ScriptEngine/LSOEngine/LSO/LSL_OPCODE_IL_processor.cs868
1 files changed, 434 insertions, 434 deletions
diff --git a/OpenSim/Region/ScriptEngine/LSOEngine/LSO/LSL_OPCODE_IL_processor.cs b/OpenSim/Region/ScriptEngine/LSOEngine/LSO/LSL_OPCODE_IL_processor.cs
index 68ecdca..30d3890 100644
--- a/OpenSim/Region/ScriptEngine/LSOEngine/LSO/LSL_OPCODE_IL_processor.cs
+++ b/OpenSim/Region/ScriptEngine/LSOEngine/LSO/LSL_OPCODE_IL_processor.cs
@@ -1,435 +1,435 @@
1/* 1/*
2* Copyright (c) Contributors, http://opensimulator.org/ 2* Copyright (c) Contributors, http://opensimulator.org/
3* See CONTRIBUTORS.TXT for a full list of copyright holders. 3* See CONTRIBUTORS.TXT for a full list of copyright holders.
4* 4*
5* Redistribution and use in source and binary forms, with or without 5* Redistribution and use in source and binary forms, with or without
6* modification, are permitted provided that the following conditions are met: 6* modification, are permitted provided that the following conditions are met:
7* * Redistributions of source code must retain the above copyright 7* * Redistributions of source code must retain the above copyright
8* notice, this list of conditions and the following disclaimer. 8* notice, this list of conditions and the following disclaimer.
9* * Redistributions in binary form must reproduce the above copyright 9* * Redistributions in binary form must reproduce the above copyright
10* notice, this list of conditions and the following disclaimer in the 10* notice, this list of conditions and the following disclaimer in the
11* documentation and/or other materials provided with the distribution. 11* documentation and/or other materials provided with the distribution.
12* * Neither the name of the OpenSim Project nor the 12* * Neither the name of the OpenSim Project nor the
13* names of its contributors may be used to endorse or promote products 13* names of its contributors may be used to endorse or promote products
14* derived from this software without specific prior written permission. 14* derived from this software without specific prior written permission.
15* 15*
16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY 16* THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY
17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY 19* DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 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 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 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 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. 25* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26* 26*
27*/ 27*/
28/* Original code: Tedd Hansen */ 28/* Original code: Tedd Hansen */
29using System; 29using System;
30using System.Reflection; 30using System.Reflection;
31using System.Reflection.Emit; 31using System.Reflection.Emit;
32using OpenSim.Region.ScriptEngine.Common; 32using OpenSim.Region.ScriptEngine.Common;
33 33
34namespace OpenSim.Region.ScriptEngine.LSOEngine.LSO 34namespace OpenSim.Region.ScriptEngine.LSOEngine.LSO
35{ 35{
36 internal partial class LSO_Parser 36 internal partial class LSO_Parser
37 { 37 {
38 //internal Stack<Type> ILStack = new Stack<Type>(); 38 //internal Stack<Type> ILStack = new Stack<Type>();
39 //LSO_Enums MyLSO_Enums = new LSO_Enums(); 39 //LSO_Enums MyLSO_Enums = new LSO_Enums();
40 40
41 internal bool LSL_PROCESS_OPCODE(ILGenerator il) 41 internal bool LSL_PROCESS_OPCODE(ILGenerator il)
42 { 42 {
43 byte bp1; 43 byte bp1;
44 UInt32 u32p1; 44 UInt32 u32p1;
45 float fp1; 45 float fp1;
46 UInt16 opcode = br_read(1)[0]; 46 UInt16 opcode = br_read(1)[0];
47 Common.SendToDebug("OPCODE: " + ((LSO_Enums.Operation_Table) opcode).ToString()); 47 Common.SendToDebug("OPCODE: " + ((LSO_Enums.Operation_Table) opcode).ToString());
48 string idesc = ((LSO_Enums.Operation_Table) opcode).ToString(); 48 string idesc = ((LSO_Enums.Operation_Table) opcode).ToString();
49 switch ((LSO_Enums.Operation_Table) opcode) 49 switch ((LSO_Enums.Operation_Table) opcode)
50 { 50 {
51 /*************** 51 /***************
52 * IMPLEMENTED * 52 * IMPLEMENTED *
53 ***************/ 53 ***************/
54 case LSO_Enums.Operation_Table.NOOP: 54 case LSO_Enums.Operation_Table.NOOP:
55 break; 55 break;
56 case LSO_Enums.Operation_Table.PUSHSP: 56 case LSO_Enums.Operation_Table.PUSHSP:
57 // Push Stack Top (Memory Address) to stack 57 // Push Stack Top (Memory Address) to stack
58 Common.SendToDebug("Instruction " + idesc); 58 Common.SendToDebug("Instruction " + idesc);
59 Common.SendToDebug("Instruction " + idesc + 59 Common.SendToDebug("Instruction " + idesc +
60 ": Description: Pushing Stack Top (Memory Address from header) to stack"); 60 ": Description: Pushing Stack Top (Memory Address from header) to stack");
61 IL_Push(il, (UInt32) myHeader.SP); 61 IL_Push(il, (UInt32) myHeader.SP);
62 break; 62 break;
63 // BYTE 63 // BYTE
64 case LSO_Enums.Operation_Table.PUSHARGB: 64 case LSO_Enums.Operation_Table.PUSHARGB:
65 Common.SendToDebug("Param1: " + br_read(1)[0]); 65 Common.SendToDebug("Param1: " + br_read(1)[0]);
66 break; 66 break;
67 // INTEGER 67 // INTEGER
68 case LSO_Enums.Operation_Table.PUSHARGI: 68 case LSO_Enums.Operation_Table.PUSHARGI:
69 u32p1 = BitConverter.ToUInt32(br_read(4), 0); 69 u32p1 = BitConverter.ToUInt32(br_read(4), 0);
70 Common.SendToDebug("Instruction " + idesc + ", Param1: " + u32p1); 70 Common.SendToDebug("Instruction " + idesc + ", Param1: " + u32p1);
71 IL_Push(il, u32p1); 71 IL_Push(il, u32p1);
72 break; 72 break;
73 // FLOAT 73 // FLOAT
74 case LSO_Enums.Operation_Table.PUSHARGF: 74 case LSO_Enums.Operation_Table.PUSHARGF:
75 fp1 = BitConverter.ToUInt32(br_read(4), 0); 75 fp1 = BitConverter.ToUInt32(br_read(4), 0);
76 Common.SendToDebug("Instruction " + idesc + ", Param1: " + fp1); 76 Common.SendToDebug("Instruction " + idesc + ", Param1: " + fp1);
77 IL_Push(il, fp1); 77 IL_Push(il, fp1);
78 break; 78 break;
79 // STRING 79 // STRING
80 case LSO_Enums.Operation_Table.PUSHARGS: 80 case LSO_Enums.Operation_Table.PUSHARGS:
81 string s = Read_String(); 81 string s = Read_String();
82 Common.SendToDebug("Instruction " + idesc + ", Param1: " + s); 82 Common.SendToDebug("Instruction " + idesc + ", Param1: " + s);
83 IL_Debug(il, "OPCODE: " + idesc + ":" + s); 83 IL_Debug(il, "OPCODE: " + idesc + ":" + s);
84 IL_Push(il, s); 84 IL_Push(il, s);
85 break; 85 break;
86 // VECTOR z,y,x 86 // VECTOR z,y,x
87 case LSO_Enums.Operation_Table.PUSHARGV: 87 case LSO_Enums.Operation_Table.PUSHARGV:
88 LSO_Enums.Vector v = new LSO_Enums.Vector(); 88 LSO_Enums.Vector v = new LSO_Enums.Vector();
89 v.Z = BitConverter.ToUInt32(br_read(4), 0); 89 v.Z = BitConverter.ToUInt32(br_read(4), 0);
90 v.Y = BitConverter.ToUInt32(br_read(4), 0); 90 v.Y = BitConverter.ToUInt32(br_read(4), 0);
91 v.X = BitConverter.ToUInt32(br_read(4), 0); 91 v.X = BitConverter.ToUInt32(br_read(4), 0);
92 Common.SendToDebug("Param1 Z: " + v.Z); 92 Common.SendToDebug("Param1 Z: " + v.Z);
93 Common.SendToDebug("Param1 Y: " + v.Y); 93 Common.SendToDebug("Param1 Y: " + v.Y);
94 Common.SendToDebug("Param1 X: " + v.X); 94 Common.SendToDebug("Param1 X: " + v.X);
95 IL_Push(il, v); 95 IL_Push(il, v);
96 break; 96 break;
97 // ROTATION s,z,y,x 97 // ROTATION s,z,y,x
98 case LSO_Enums.Operation_Table.PUSHARGQ: 98 case LSO_Enums.Operation_Table.PUSHARGQ:
99 LSO_Enums.Rotation r = new LSO_Enums.Rotation(); 99 LSO_Enums.Rotation r = new LSO_Enums.Rotation();
100 r.S = BitConverter.ToUInt32(br_read(4), 0); 100 r.S = BitConverter.ToUInt32(br_read(4), 0);
101 r.Z = BitConverter.ToUInt32(br_read(4), 0); 101 r.Z = BitConverter.ToUInt32(br_read(4), 0);
102 r.Y = BitConverter.ToUInt32(br_read(4), 0); 102 r.Y = BitConverter.ToUInt32(br_read(4), 0);
103 r.X = BitConverter.ToUInt32(br_read(4), 0); 103 r.X = BitConverter.ToUInt32(br_read(4), 0);
104 Common.SendToDebug("Param1 S: " + r.S); 104 Common.SendToDebug("Param1 S: " + r.S);
105 Common.SendToDebug("Param1 Z: " + r.Z); 105 Common.SendToDebug("Param1 Z: " + r.Z);
106 Common.SendToDebug("Param1 Y: " + r.Y); 106 Common.SendToDebug("Param1 Y: " + r.Y);
107 Common.SendToDebug("Param1 X: " + r.X); 107 Common.SendToDebug("Param1 X: " + r.X);
108 IL_Push(il, r); 108 IL_Push(il, r);
109 break; 109 break;
110 110
111 case LSO_Enums.Operation_Table.PUSHE: 111 case LSO_Enums.Operation_Table.PUSHE:
112 IL_Push(il, (UInt32) 0); 112 IL_Push(il, (UInt32) 0);
113 break; 113 break;
114 114
115 case LSO_Enums.Operation_Table.PUSHARGE: 115 case LSO_Enums.Operation_Table.PUSHARGE:
116 u32p1 = BitConverter.ToUInt32(br_read(4), 0); 116 u32p1 = BitConverter.ToUInt32(br_read(4), 0);
117 Common.SendToDebug("Param1: " + u32p1); 117 Common.SendToDebug("Param1: " + u32p1);
118 //IL_Push(il, new string(" ".ToCharArray()[0], Convert.ToInt32(u32p1))); 118 //IL_Push(il, new string(" ".ToCharArray()[0], Convert.ToInt32(u32p1)));
119 IL_Push(il, u32p1); 119 IL_Push(il, u32p1);
120 break; 120 break;
121 // BYTE 121 // BYTE
122 case LSO_Enums.Operation_Table.ADD: 122 case LSO_Enums.Operation_Table.ADD:
123 case LSO_Enums.Operation_Table.SUB: 123 case LSO_Enums.Operation_Table.SUB:
124 case LSO_Enums.Operation_Table.MUL: 124 case LSO_Enums.Operation_Table.MUL:
125 case LSO_Enums.Operation_Table.DIV: 125 case LSO_Enums.Operation_Table.DIV:
126 case LSO_Enums.Operation_Table.EQ: 126 case LSO_Enums.Operation_Table.EQ:
127 case LSO_Enums.Operation_Table.NEQ: 127 case LSO_Enums.Operation_Table.NEQ:
128 case LSO_Enums.Operation_Table.LEQ: 128 case LSO_Enums.Operation_Table.LEQ:
129 case LSO_Enums.Operation_Table.GEQ: 129 case LSO_Enums.Operation_Table.GEQ:
130 case LSO_Enums.Operation_Table.LESS: 130 case LSO_Enums.Operation_Table.LESS:
131 case LSO_Enums.Operation_Table.GREATER: 131 case LSO_Enums.Operation_Table.GREATER:
132 case LSO_Enums.Operation_Table.NEG: 132 case LSO_Enums.Operation_Table.NEG:
133 case LSO_Enums.Operation_Table.MOD: 133 case LSO_Enums.Operation_Table.MOD:
134 bp1 = br_read(1)[0]; 134 bp1 = br_read(1)[0];
135 Common.SendToDebug("Param1: " + bp1); 135 Common.SendToDebug("Param1: " + bp1);
136 IL_CallBaseFunction(il, idesc, (UInt32) bp1); 136 IL_CallBaseFunction(il, idesc, (UInt32) bp1);
137 break; 137 break;
138 138
139 // NO ARGUMENTS 139 // NO ARGUMENTS
140 case LSO_Enums.Operation_Table.BITAND: 140 case LSO_Enums.Operation_Table.BITAND:
141 case LSO_Enums.Operation_Table.BITOR: 141 case LSO_Enums.Operation_Table.BITOR:
142 case LSO_Enums.Operation_Table.BITXOR: 142 case LSO_Enums.Operation_Table.BITXOR:
143 case LSO_Enums.Operation_Table.BOOLAND: 143 case LSO_Enums.Operation_Table.BOOLAND:
144 case LSO_Enums.Operation_Table.BOOLOR: 144 case LSO_Enums.Operation_Table.BOOLOR:
145 case LSO_Enums.Operation_Table.BITNOT: 145 case LSO_Enums.Operation_Table.BITNOT:
146 case LSO_Enums.Operation_Table.BOOLNOT: 146 case LSO_Enums.Operation_Table.BOOLNOT:
147 IL_CallBaseFunction(il, idesc); 147 IL_CallBaseFunction(il, idesc);
148 break; 148 break;
149 // SHORT 149 // SHORT
150 case LSO_Enums.Operation_Table.CALLLIB_TWO_BYTE: 150 case LSO_Enums.Operation_Table.CALLLIB_TWO_BYTE:
151 // TODO: What is size of short? 151 // TODO: What is size of short?
152 UInt16 U16p1 = BitConverter.ToUInt16(br_read(2), 0); 152 UInt16 U16p1 = BitConverter.ToUInt16(br_read(2), 0);
153 Common.SendToDebug("Instruction " + idesc + ": Builtin Command: " + 153 Common.SendToDebug("Instruction " + idesc + ": Builtin Command: " +
154 ((LSO_Enums.BuiltIn_Functions) U16p1).ToString()); 154 ((LSO_Enums.BuiltIn_Functions) U16p1).ToString());
155 //Common.SendToDebug("Param1: " + U16p1); 155 //Common.SendToDebug("Param1: " + U16p1);
156 string fname = ((LSO_Enums.BuiltIn_Functions) U16p1).ToString(); 156 string fname = ((LSO_Enums.BuiltIn_Functions) U16p1).ToString();
157 157
158 bool cmdFound = false; 158 bool cmdFound = false;
159 foreach (MethodInfo mi in typeof (LSL_BuiltIn_Commands_Interface).GetMethods()) 159 foreach (MethodInfo mi in typeof (LSL_BuiltIn_Commands_Interface).GetMethods())
160 { 160 {
161 // Found command 161 // Found command
162 if (mi.Name == fname) 162 if (mi.Name == fname)
163 { 163 {
164 il.Emit(OpCodes.Ldarg_0); 164 il.Emit(OpCodes.Ldarg_0);
165 il.Emit(OpCodes.Call, typeof (LSL_BaseClass).GetMethod("GetLSL_BuiltIn", new Type[] {})); 165 il.Emit(OpCodes.Call, typeof (LSL_BaseClass).GetMethod("GetLSL_BuiltIn", new Type[] {}));
166 // Pop required number of items from my stack to .Net stack 166 // Pop required number of items from my stack to .Net stack
167 IL_PopToStack(il, mi.GetParameters().Length); 167 IL_PopToStack(il, mi.GetParameters().Length);
168 il.Emit(OpCodes.Callvirt, mi); 168 il.Emit(OpCodes.Callvirt, mi);
169 cmdFound = true; 169 cmdFound = true;
170 break; 170 break;
171 } 171 }
172 } 172 }
173 if (cmdFound == false) 173 if (cmdFound == false)
174 { 174 {
175 Common.SendToDebug("ERROR: UNABLE TO LOCATE OPCODE " + idesc + " IN BASECLASS"); 175 Common.SendToDebug("ERROR: UNABLE TO LOCATE OPCODE " + idesc + " IN BASECLASS");
176 } 176 }
177 177
178 break; 178 break;
179 179
180 // RETURN 180 // RETURN
181 case LSO_Enums.Operation_Table.RETURN: 181 case LSO_Enums.Operation_Table.RETURN:
182 182
183 Common.SendToDebug("OPCODE: RETURN"); 183 Common.SendToDebug("OPCODE: RETURN");
184 return true; 184 return true;
185 185
186 case LSO_Enums.Operation_Table.POP: 186 case LSO_Enums.Operation_Table.POP:
187 case LSO_Enums.Operation_Table.POPS: 187 case LSO_Enums.Operation_Table.POPS:
188 case LSO_Enums.Operation_Table.POPL: 188 case LSO_Enums.Operation_Table.POPL:
189 case LSO_Enums.Operation_Table.POPV: 189 case LSO_Enums.Operation_Table.POPV:
190 case LSO_Enums.Operation_Table.POPQ: 190 case LSO_Enums.Operation_Table.POPQ:
191 // Pops a specific datatype from the stack 191 // Pops a specific datatype from the stack
192 // We just ignore the datatype for now 192 // We just ignore the datatype for now
193 IL_Pop(il); 193 IL_Pop(il);
194 break; 194 break;
195 195
196 // LONG 196 // LONG
197 case LSO_Enums.Operation_Table.STORE: 197 case LSO_Enums.Operation_Table.STORE:
198 case LSO_Enums.Operation_Table.STORES: 198 case LSO_Enums.Operation_Table.STORES:
199 case LSO_Enums.Operation_Table.STOREL: 199 case LSO_Enums.Operation_Table.STOREL:
200 case LSO_Enums.Operation_Table.STOREV: 200 case LSO_Enums.Operation_Table.STOREV:
201 case LSO_Enums.Operation_Table.STOREQ: 201 case LSO_Enums.Operation_Table.STOREQ:
202 u32p1 = BitConverter.ToUInt32(br_read(4), 0); 202 u32p1 = BitConverter.ToUInt32(br_read(4), 0);
203 Common.SendToDebug("Param1: " + u32p1.ToString()); 203 Common.SendToDebug("Param1: " + u32p1.ToString());
204 IL_CallBaseFunction(il, "StoreToLocal", u32p1); 204 IL_CallBaseFunction(il, "StoreToLocal", u32p1);
205 break; 205 break;
206 206
207 case LSO_Enums.Operation_Table.STOREG: 207 case LSO_Enums.Operation_Table.STOREG:
208 case LSO_Enums.Operation_Table.STOREGS: 208 case LSO_Enums.Operation_Table.STOREGS:
209 case LSO_Enums.Operation_Table.STOREGL: 209 case LSO_Enums.Operation_Table.STOREGL:
210 case LSO_Enums.Operation_Table.STOREGV: 210 case LSO_Enums.Operation_Table.STOREGV:
211 case LSO_Enums.Operation_Table.STOREGQ: 211 case LSO_Enums.Operation_Table.STOREGQ:
212 u32p1 = BitConverter.ToUInt32(br_read(4), 0); 212 u32p1 = BitConverter.ToUInt32(br_read(4), 0);
213 Common.SendToDebug("Param1: " + u32p1.ToString()); 213 Common.SendToDebug("Param1: " + u32p1.ToString());
214 IL_CallBaseFunction(il, "StoreToGlobal", u32p1); 214 IL_CallBaseFunction(il, "StoreToGlobal", u32p1);
215 break; 215 break;
216 216
217 case LSO_Enums.Operation_Table.LOADP: 217 case LSO_Enums.Operation_Table.LOADP:
218 case LSO_Enums.Operation_Table.LOADSP: 218 case LSO_Enums.Operation_Table.LOADSP:
219 case LSO_Enums.Operation_Table.LOADLP: 219 case LSO_Enums.Operation_Table.LOADLP:
220 case LSO_Enums.Operation_Table.LOADVP: 220 case LSO_Enums.Operation_Table.LOADVP:
221 case LSO_Enums.Operation_Table.LOADQP: 221 case LSO_Enums.Operation_Table.LOADQP:
222 u32p1 = BitConverter.ToUInt32(br_read(4), 0); 222 u32p1 = BitConverter.ToUInt32(br_read(4), 0);
223 Common.SendToDebug("Param1: " + u32p1.ToString()); 223 Common.SendToDebug("Param1: " + u32p1.ToString());
224 IL_CallBaseFunction(il, "StoreToLocal", u32p1); 224 IL_CallBaseFunction(il, "StoreToLocal", u32p1);
225 IL_Pop(il); 225 IL_Pop(il);
226 break; 226 break;
227 227
228 case LSO_Enums.Operation_Table.LOADGP: 228 case LSO_Enums.Operation_Table.LOADGP:
229 case LSO_Enums.Operation_Table.LOADGSP: 229 case LSO_Enums.Operation_Table.LOADGSP:
230 case LSO_Enums.Operation_Table.LOADGLP: 230 case LSO_Enums.Operation_Table.LOADGLP:
231 case LSO_Enums.Operation_Table.LOADGVP: 231 case LSO_Enums.Operation_Table.LOADGVP:
232 case LSO_Enums.Operation_Table.LOADGQP: 232 case LSO_Enums.Operation_Table.LOADGQP:
233 u32p1 = BitConverter.ToUInt32(br_read(4), 0); 233 u32p1 = BitConverter.ToUInt32(br_read(4), 0);
234 Common.SendToDebug("Param1: " + u32p1.ToString()); 234 Common.SendToDebug("Param1: " + u32p1.ToString());
235 IL_CallBaseFunction(il, "StoreToStatic", u32p1 - 6 + myHeader.GVR); 235 IL_CallBaseFunction(il, "StoreToStatic", u32p1 - 6 + myHeader.GVR);
236 IL_Pop(il); 236 IL_Pop(il);
237 break; 237 break;
238 238
239 // PUSH FROM LOCAL FRAME 239 // PUSH FROM LOCAL FRAME
240 case LSO_Enums.Operation_Table.PUSH: 240 case LSO_Enums.Operation_Table.PUSH:
241 case LSO_Enums.Operation_Table.PUSHS: 241 case LSO_Enums.Operation_Table.PUSHS:
242 case LSO_Enums.Operation_Table.PUSHL: 242 case LSO_Enums.Operation_Table.PUSHL:
243 case LSO_Enums.Operation_Table.PUSHV: 243 case LSO_Enums.Operation_Table.PUSHV:
244 case LSO_Enums.Operation_Table.PUSHQ: 244 case LSO_Enums.Operation_Table.PUSHQ:
245 u32p1 = BitConverter.ToUInt32(br_read(4), 0); 245 u32p1 = BitConverter.ToUInt32(br_read(4), 0);
246 Common.SendToDebug("Param1: " + u32p1.ToString()); 246 Common.SendToDebug("Param1: " + u32p1.ToString());
247 IL_CallBaseFunction(il, "GetFromLocal", u32p1); 247 IL_CallBaseFunction(il, "GetFromLocal", u32p1);
248 248
249 break; 249 break;
250 250
251 // PUSH FROM STATIC FRAME 251 // PUSH FROM STATIC FRAME
252 case LSO_Enums.Operation_Table.PUSHG: 252 case LSO_Enums.Operation_Table.PUSHG:
253 case LSO_Enums.Operation_Table.PUSHGS: 253 case LSO_Enums.Operation_Table.PUSHGS:
254 case LSO_Enums.Operation_Table.PUSHGL: 254 case LSO_Enums.Operation_Table.PUSHGL:
255 case LSO_Enums.Operation_Table.PUSHGV: 255 case LSO_Enums.Operation_Table.PUSHGV:
256 case LSO_Enums.Operation_Table.PUSHGQ: 256 case LSO_Enums.Operation_Table.PUSHGQ:
257 u32p1 = BitConverter.ToUInt32(br_read(4), 0); 257 u32p1 = BitConverter.ToUInt32(br_read(4), 0);
258 Common.SendToDebug("Param1: " + u32p1.ToString()); 258 Common.SendToDebug("Param1: " + u32p1.ToString());
259 IL_CallBaseFunction(il, "GetFromStatic", u32p1 - 6 + myHeader.GVR); 259 IL_CallBaseFunction(il, "GetFromStatic", u32p1 - 6 + myHeader.GVR);
260 break; 260 break;
261 261
262 262
263 /*********************** 263 /***********************
264 * NOT IMPLEMENTED YET * 264 * NOT IMPLEMENTED YET *
265 ***********************/ 265 ***********************/
266 266
267 267
268 case LSO_Enums.Operation_Table.POPIP: 268 case LSO_Enums.Operation_Table.POPIP:
269 case LSO_Enums.Operation_Table.POPSP: 269 case LSO_Enums.Operation_Table.POPSP:
270 case LSO_Enums.Operation_Table.POPSLR: 270 case LSO_Enums.Operation_Table.POPSLR:
271 case LSO_Enums.Operation_Table.POPARG: 271 case LSO_Enums.Operation_Table.POPARG:
272 case LSO_Enums.Operation_Table.POPBP: 272 case LSO_Enums.Operation_Table.POPBP:
273 //Common.SendToDebug("Instruction " + idesc + ": Ignored"); 273 //Common.SendToDebug("Instruction " + idesc + ": Ignored");
274 Common.SendToDebug("Instruction " + idesc + 274 Common.SendToDebug("Instruction " + idesc +
275 ": Description: Drop x bytes from the stack (TODO: Only popping 1)"); 275 ": Description: Drop x bytes from the stack (TODO: Only popping 1)");
276 //Common.SendToDebug("Param1: " + BitConverter.ToUInt32(br_read(4), 0)); 276 //Common.SendToDebug("Param1: " + BitConverter.ToUInt32(br_read(4), 0));
277 IL_Pop(il); 277 IL_Pop(il);
278 break; 278 break;
279 279
280 280
281 // None 281 // None
282 case LSO_Enums.Operation_Table.PUSHIP: 282 case LSO_Enums.Operation_Table.PUSHIP:
283 // PUSH INSTRUCTION POINTER 283 // PUSH INSTRUCTION POINTER
284 break; 284 break;
285 case LSO_Enums.Operation_Table.PUSHBP: 285 case LSO_Enums.Operation_Table.PUSHBP:
286 286
287 case LSO_Enums.Operation_Table.PUSHEV: 287 case LSO_Enums.Operation_Table.PUSHEV:
288 break; 288 break;
289 case LSO_Enums.Operation_Table.PUSHEQ: 289 case LSO_Enums.Operation_Table.PUSHEQ:
290 break; 290 break;
291 291
292 292
293 // LONG 293 // LONG
294 case LSO_Enums.Operation_Table.JUMP: 294 case LSO_Enums.Operation_Table.JUMP:
295 Common.SendToDebug("Param1: " + BitConverter.ToUInt32(br_read(4), 0)); 295 Common.SendToDebug("Param1: " + BitConverter.ToUInt32(br_read(4), 0));
296 break; 296 break;
297 // BYTE, LONG 297 // BYTE, LONG
298 case LSO_Enums.Operation_Table.JUMPIF: 298 case LSO_Enums.Operation_Table.JUMPIF:
299 case LSO_Enums.Operation_Table.JUMPNIF: 299 case LSO_Enums.Operation_Table.JUMPNIF:
300 Common.SendToDebug("Param1: " + br_read(1)[0]); 300 Common.SendToDebug("Param1: " + br_read(1)[0]);
301 Common.SendToDebug("Param2: " + BitConverter.ToUInt32(br_read(4), 0)); 301 Common.SendToDebug("Param2: " + BitConverter.ToUInt32(br_read(4), 0));
302 break; 302 break;
303 // LONG 303 // LONG
304 case LSO_Enums.Operation_Table.STATE: 304 case LSO_Enums.Operation_Table.STATE:
305 bp1 = br_read(1)[0]; 305 bp1 = br_read(1)[0];
306 //il.Emit(OpCodes.Ld); // Load local variable 0 onto stack 306 //il.Emit(OpCodes.Ld); // Load local variable 0 onto stack
307 //il.Emit(OpCodes.Ldc_I4, 0); // Push index position 307 //il.Emit(OpCodes.Ldc_I4, 0); // Push index position
308 //il.Emit(OpCodes.Ldstr, EventList[p1]); // Push value 308 //il.Emit(OpCodes.Ldstr, EventList[p1]); // Push value
309 //il.Emit(OpCodes.Stelem_Ref); // Perform array[index] = value 309 //il.Emit(OpCodes.Stelem_Ref); // Perform array[index] = value
310 break; 310 break;
311 case LSO_Enums.Operation_Table.CALL: 311 case LSO_Enums.Operation_Table.CALL:
312 Common.SendToDebug("Param1: " + BitConverter.ToUInt32(br_read(4), 0)); 312 Common.SendToDebug("Param1: " + BitConverter.ToUInt32(br_read(4), 0));
313 Common.SendToDebug("ERROR: Function CALL not implemented yet."); 313 Common.SendToDebug("ERROR: Function CALL not implemented yet.");
314 break; 314 break;
315 // BYTE 315 // BYTE
316 case LSO_Enums.Operation_Table.CAST: 316 case LSO_Enums.Operation_Table.CAST:
317 bp1 = br_read(1)[0]; 317 bp1 = br_read(1)[0];
318 Common.SendToDebug("Instruction " + idesc + ": Cast to type: " + 318 Common.SendToDebug("Instruction " + idesc + ": Cast to type: " +
319 ((LSO_Enums.OpCode_Cast_TypeDefs) bp1)); 319 ((LSO_Enums.OpCode_Cast_TypeDefs) bp1));
320 Common.SendToDebug("Param1: " + bp1); 320 Common.SendToDebug("Param1: " + bp1);
321 switch ((LSO_Enums.OpCode_Cast_TypeDefs) bp1) 321 switch ((LSO_Enums.OpCode_Cast_TypeDefs) bp1)
322 { 322 {
323 case LSO_Enums.OpCode_Cast_TypeDefs.String: 323 case LSO_Enums.OpCode_Cast_TypeDefs.String:
324 Common.SendToDebug("Instruction " + idesc + ": il.Emit(OpCodes.Box, ILStack.Pop());"); 324 Common.SendToDebug("Instruction " + idesc + ": il.Emit(OpCodes.Box, ILStack.Pop());");
325 break; 325 break;
326 default: 326 default:
327 Common.SendToDebug("Instruction " + idesc + ": Unknown cast type!"); 327 Common.SendToDebug("Instruction " + idesc + ": Unknown cast type!");
328 break; 328 break;
329 } 329 }
330 break; 330 break;
331 // LONG 331 // LONG
332 case LSO_Enums.Operation_Table.STACKTOS: 332 case LSO_Enums.Operation_Table.STACKTOS:
333 case LSO_Enums.Operation_Table.STACKTOL: 333 case LSO_Enums.Operation_Table.STACKTOL:
334 Common.SendToDebug("Param1: " + BitConverter.ToUInt32(br_read(4), 0)); 334 Common.SendToDebug("Param1: " + BitConverter.ToUInt32(br_read(4), 0));
335 break; 335 break;
336 // BYTE 336 // BYTE
337 case LSO_Enums.Operation_Table.PRINT: 337 case LSO_Enums.Operation_Table.PRINT:
338 case LSO_Enums.Operation_Table.CALLLIB: 338 case LSO_Enums.Operation_Table.CALLLIB:
339 Common.SendToDebug("Param1: " + br_read(1)[0]); 339 Common.SendToDebug("Param1: " + br_read(1)[0]);
340 break; 340 break;
341 } 341 }
342 return false; 342 return false;
343 } 343 }
344 344
345 private void IL_PopToStack(ILGenerator il) 345 private void IL_PopToStack(ILGenerator il)
346 { 346 {
347 IL_PopToStack(il, 1); 347 IL_PopToStack(il, 1);
348 } 348 }
349 349
350 private void IL_PopToStack(ILGenerator il, int count) 350 private void IL_PopToStack(ILGenerator il, int count)
351 { 351 {
352 Common.SendToDebug("IL_PopToStack();"); 352 Common.SendToDebug("IL_PopToStack();");
353 for (int i = 0; i < count; i++) 353 for (int i = 0; i < count; i++)
354 { 354 {
355 IL_CallBaseFunction(il, "POPToStack"); 355 IL_CallBaseFunction(il, "POPToStack");
356 //il.Emit(OpCodes.Ldarg_0); 356 //il.Emit(OpCodes.Ldarg_0);
357 //il.Emit(OpCodes.Call, 357 //il.Emit(OpCodes.Call,
358 // typeof(LSL_BaseClass).GetMethod("POPToStack", 358 // typeof(LSL_BaseClass).GetMethod("POPToStack",
359 // new Type[] { })); 359 // new Type[] { }));
360 } 360 }
361 } 361 }
362 362
363 private void IL_Pop(ILGenerator il) 363 private void IL_Pop(ILGenerator il)
364 { 364 {
365 Common.SendToDebug("IL_Pop();"); 365 Common.SendToDebug("IL_Pop();");
366 IL_CallBaseFunction(il, "POP"); 366 IL_CallBaseFunction(il, "POP");
367 } 367 }
368 368
369 private void IL_Debug(ILGenerator il, string text) 369 private void IL_Debug(ILGenerator il, string text)
370 { 370 {
371 il.Emit(OpCodes.Ldstr, text); 371 il.Emit(OpCodes.Ldstr, text);
372 il.Emit(OpCodes.Call, typeof (Common).GetMethod("SendToDebug", 372 il.Emit(OpCodes.Call, typeof (Common).GetMethod("SendToDebug",
373 new Type[] {typeof (string)} 373 new Type[] {typeof (string)}
374 )); 374 ));
375 } 375 }
376 376
377 private void IL_CallBaseFunction(ILGenerator il, string methodname) 377 private void IL_CallBaseFunction(ILGenerator il, string methodname)
378 { 378 {
379 il.Emit(OpCodes.Ldarg_0); 379 il.Emit(OpCodes.Ldarg_0);
380 il.Emit(OpCodes.Call, typeof (LSL_BaseClass).GetMethod(methodname, new Type[] {})); 380 il.Emit(OpCodes.Call, typeof (LSL_BaseClass).GetMethod(methodname, new Type[] {}));
381 } 381 }
382 382
383 private void IL_CallBaseFunction(ILGenerator il, string methodname, object data) 383 private void IL_CallBaseFunction(ILGenerator il, string methodname, object data)
384 { 384 {
385 il.Emit(OpCodes.Ldarg_0); 385 il.Emit(OpCodes.Ldarg_0);
386 if (data.GetType() == typeof (string)) 386 if (data.GetType() == typeof (string))
387 il.Emit(OpCodes.Ldstr, (string) data); 387 il.Emit(OpCodes.Ldstr, (string) data);
388 if (data.GetType() == typeof (UInt32)) 388 if (data.GetType() == typeof (UInt32))
389 il.Emit(OpCodes.Ldc_I4, (UInt32) data); 389 il.Emit(OpCodes.Ldc_I4, (UInt32) data);
390 il.Emit(OpCodes.Call, typeof (LSL_BaseClass).GetMethod(methodname, new Type[] {data.GetType()})); 390 il.Emit(OpCodes.Call, typeof (LSL_BaseClass).GetMethod(methodname, new Type[] {data.GetType()}));
391 } 391 }
392 392
393 private void IL_Push(ILGenerator il, object data) 393 private void IL_Push(ILGenerator il, object data)
394 { 394 {
395 il.Emit(OpCodes.Ldarg_0); 395 il.Emit(OpCodes.Ldarg_0);
396 Common.SendToDebug("PUSH datatype: " + data.GetType()); 396 Common.SendToDebug("PUSH datatype: " + data.GetType());
397 397
398 IL_PushDataTypeToILStack(il, data); 398 IL_PushDataTypeToILStack(il, data);
399 399
400 il.Emit(OpCodes.Call, typeof (LSL_BaseClass).GetMethod("PUSH", new Type[] {data.GetType()})); 400 il.Emit(OpCodes.Call, typeof (LSL_BaseClass).GetMethod("PUSH", new Type[] {data.GetType()}));
401 } 401 }
402 402
403 private void IL_PushDataTypeToILStack(ILGenerator il, object data) 403 private void IL_PushDataTypeToILStack(ILGenerator il, object data)
404 { 404 {
405 if (data.GetType() == typeof (UInt16)) 405 if (data.GetType() == typeof (UInt16))
406 { 406 {
407 il.Emit(OpCodes.Ldc_I4, (UInt16) data); 407 il.Emit(OpCodes.Ldc_I4, (UInt16) data);
408 il.Emit(OpCodes.Box, data.GetType()); 408 il.Emit(OpCodes.Box, data.GetType());
409 } 409 }
410 if (data.GetType() == typeof (UInt32)) 410 if (data.GetType() == typeof (UInt32))
411 { 411 {
412 il.Emit(OpCodes.Ldc_I4, (UInt32) data); 412 il.Emit(OpCodes.Ldc_I4, (UInt32) data);
413 il.Emit(OpCodes.Box, data.GetType()); 413 il.Emit(OpCodes.Box, data.GetType());
414 } 414 }
415 if (data.GetType() == typeof (Int32)) 415 if (data.GetType() == typeof (Int32))
416 { 416 {
417 il.Emit(OpCodes.Ldc_I4, (Int32) data); 417 il.Emit(OpCodes.Ldc_I4, (Int32) data);
418 il.Emit(OpCodes.Box, data.GetType()); 418 il.Emit(OpCodes.Box, data.GetType());
419 } 419 }
420 if (data.GetType() == typeof (float)) 420 if (data.GetType() == typeof (float))
421 { 421 {
422 il.Emit(OpCodes.Ldc_I4, (float) data); 422 il.Emit(OpCodes.Ldc_I4, (float) data);
423 il.Emit(OpCodes.Box, data.GetType()); 423 il.Emit(OpCodes.Box, data.GetType());
424 } 424 }
425 if (data.GetType() == typeof (string)) 425 if (data.GetType() == typeof (string))
426 il.Emit(OpCodes.Ldstr, (string) data); 426 il.Emit(OpCodes.Ldstr, (string) data);
427 //if (data.GetType() == typeof(LSO_Enums.Rotation)) 427 //if (data.GetType() == typeof(LSO_Enums.Rotation))
428 // il.Emit(OpCodes.Ldobj, (LSO_Enums.Rotation)data); 428 // il.Emit(OpCodes.Ldobj, (LSO_Enums.Rotation)data);
429 //if (data.GetType() == typeof(LSO_Enums.Vector)) 429 //if (data.GetType() == typeof(LSO_Enums.Vector))
430 // il.Emit(OpCodes.Ldobj, (LSO_Enums.Vector)data); 430 // il.Emit(OpCodes.Ldobj, (LSO_Enums.Vector)data);
431 //if (data.GetType() == typeof(LSO_Enums.Key)) 431 //if (data.GetType() == typeof(LSO_Enums.Key))
432 // il.Emit(OpCodes.Ldobj, (LSO_Enums.Key)data); 432 // il.Emit(OpCodes.Ldobj, (LSO_Enums.Key)data);
433 } 433 }
434 } 434 }
435} \ No newline at end of file 435} \ No newline at end of file