diff options
author | Sean Dague | 2007-09-13 11:41:42 +0000 |
---|---|---|
committer | Sean Dague | 2007-09-13 11:41:42 +0000 |
commit | afea5f22055fd645e95c4e1dcad01e68716fa049 (patch) | |
tree | 73dbc6fff4cba36c559234b66d24c84e00f3f162 /OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSO/LSO_Parser.cs | |
parent | adding eol-style attributes on new files (diff) | |
download | opensim-SC_OLD-afea5f22055fd645e95c4e1dcad01e68716fa049.zip opensim-SC_OLD-afea5f22055fd645e95c4e1dcad01e68716fa049.tar.gz opensim-SC_OLD-afea5f22055fd645e95c4e1dcad01e68716fa049.tar.bz2 opensim-SC_OLD-afea5f22055fd645e95c4e1dcad01e68716fa049.tar.xz |
remove ^M, as native storage should be UNIX format, and ^M in/out mashing
will happen on the windows side now that eol-style is correct
Diffstat (limited to 'OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSO/LSO_Parser.cs')
-rw-r--r-- | OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSO/LSO_Parser.cs | 1444 |
1 files changed, 722 insertions, 722 deletions
diff --git a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSO/LSO_Parser.cs b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSO/LSO_Parser.cs index c3e3e73..ba97375 100644 --- a/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSO/LSO_Parser.cs +++ b/OpenSim/Region/ScriptEngine/DotNetEngine/Compiler/LSO/LSO_Parser.cs | |||
@@ -1,722 +1,722 @@ | |||
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 */ |
29 | using System; | 29 | using System; |
30 | using System.Collections.Generic; | 30 | using System.Collections.Generic; |
31 | using System.Text; | 31 | using System.Text; |
32 | using System.IO; | 32 | using System.IO; |
33 | using System.Reflection; | 33 | using System.Reflection; |
34 | using System.Reflection.Emit; | 34 | using System.Reflection.Emit; |
35 | 35 | ||
36 | namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSO | 36 | namespace OpenSim.Region.ScriptEngine.DotNetEngine.Compiler.LSO |
37 | { | 37 | { |
38 | partial class LSO_Parser | 38 | partial class LSO_Parser |
39 | { | 39 | { |
40 | private string FileName; | 40 | private string FileName; |
41 | private FileStream fs; | 41 | private FileStream fs; |
42 | private BinaryReader br; | 42 | private BinaryReader br; |
43 | internal LSO_Struct.Header myHeader; | 43 | internal LSO_Struct.Header myHeader; |
44 | internal Dictionary<long, LSO_Struct.StaticBlock> StaticBlocks = new Dictionary<long, LSO_Struct.StaticBlock>(); | 44 | internal Dictionary<long, LSO_Struct.StaticBlock> StaticBlocks = new Dictionary<long, LSO_Struct.StaticBlock>(); |
45 | //private System.Collections.Hashtable StaticBlocks = new System.Collections.Hashtable(); | 45 | //private System.Collections.Hashtable StaticBlocks = new System.Collections.Hashtable(); |
46 | 46 | ||
47 | private TypeBuilder typeBuilder; | 47 | private TypeBuilder typeBuilder; |
48 | private System.Collections.Generic.List<string> EventList = new System.Collections.Generic.List<string>(); | 48 | private System.Collections.Generic.List<string> EventList = new System.Collections.Generic.List<string>(); |
49 | 49 | ||
50 | public LSO_Parser(string _FileName, TypeBuilder _typeBuilder) | 50 | public LSO_Parser(string _FileName, TypeBuilder _typeBuilder) |
51 | { | 51 | { |
52 | FileName = _FileName; | 52 | FileName = _FileName; |
53 | typeBuilder = _typeBuilder; | 53 | typeBuilder = _typeBuilder; |
54 | } | 54 | } |
55 | 55 | ||
56 | internal void OpenFile() | 56 | internal void OpenFile() |
57 | { | 57 | { |
58 | // Open | 58 | // Open |
59 | Common.SendToDebug("Opening filename: " + FileName); | 59 | Common.SendToDebug("Opening filename: " + FileName); |
60 | fs = File.Open(FileName, FileMode.Open, FileAccess.Read, FileShare.Read); | 60 | fs = File.Open(FileName, FileMode.Open, FileAccess.Read, FileShare.Read); |
61 | br = new BinaryReader(fs, Encoding.BigEndianUnicode); | 61 | br = new BinaryReader(fs, Encoding.BigEndianUnicode); |
62 | 62 | ||
63 | } | 63 | } |
64 | internal void CloseFile() | 64 | internal void CloseFile() |
65 | { | 65 | { |
66 | 66 | ||
67 | // Close | 67 | // Close |
68 | br.Close(); | 68 | br.Close(); |
69 | fs.Close(); | 69 | fs.Close(); |
70 | } | 70 | } |
71 | 71 | ||
72 | 72 | ||
73 | /// <summary> | 73 | /// <summary> |
74 | /// Parse LSO file. | 74 | /// Parse LSO file. |
75 | /// </summary> | 75 | /// </summary> |
76 | public void Parse() | 76 | public void Parse() |
77 | { | 77 | { |
78 | 78 | ||
79 | 79 | ||
80 | 80 | ||
81 | // The LSO Format consist of 6 major blocks: header, statics, functions, states, heap, and stack. | 81 | // The LSO Format consist of 6 major blocks: header, statics, functions, states, heap, and stack. |
82 | 82 | ||
83 | 83 | ||
84 | // HEADER BLOCK | 84 | // HEADER BLOCK |
85 | Common.SendToDebug("Reading HEADER BLOCK at: 0"); | 85 | Common.SendToDebug("Reading HEADER BLOCK at: 0"); |
86 | fs.Seek(0, SeekOrigin.Begin); | 86 | fs.Seek(0, SeekOrigin.Begin); |
87 | myHeader = new LSO_Struct.Header(); | 87 | myHeader = new LSO_Struct.Header(); |
88 | myHeader.TM = BitConverter.ToUInt32(br_read(4), 0); | 88 | myHeader.TM = BitConverter.ToUInt32(br_read(4), 0); |
89 | myHeader.IP = BitConverter.ToUInt32(br_read(4), 0); | 89 | myHeader.IP = BitConverter.ToUInt32(br_read(4), 0); |
90 | myHeader.VN = BitConverter.ToUInt32(br_read(4), 0); | 90 | myHeader.VN = BitConverter.ToUInt32(br_read(4), 0); |
91 | myHeader.BP = BitConverter.ToUInt32(br_read(4), 0); | 91 | myHeader.BP = BitConverter.ToUInt32(br_read(4), 0); |
92 | myHeader.SP = BitConverter.ToUInt32(br_read(4), 0); | 92 | myHeader.SP = BitConverter.ToUInt32(br_read(4), 0); |
93 | myHeader.HR = BitConverter.ToUInt32(br_read(4), 0); | 93 | myHeader.HR = BitConverter.ToUInt32(br_read(4), 0); |
94 | myHeader.HP = BitConverter.ToUInt32(br_read(4), 0); | 94 | myHeader.HP = BitConverter.ToUInt32(br_read(4), 0); |
95 | myHeader.CS = BitConverter.ToUInt32(br_read(4), 0); | 95 | myHeader.CS = BitConverter.ToUInt32(br_read(4), 0); |
96 | myHeader.NS = BitConverter.ToUInt32(br_read(4), 0); | 96 | myHeader.NS = BitConverter.ToUInt32(br_read(4), 0); |
97 | myHeader.CE = BitConverter.ToUInt32(br_read(4), 0); | 97 | myHeader.CE = BitConverter.ToUInt32(br_read(4), 0); |
98 | myHeader.IE = BitConverter.ToUInt32(br_read(4), 0); | 98 | myHeader.IE = BitConverter.ToUInt32(br_read(4), 0); |
99 | myHeader.ER = BitConverter.ToUInt32(br_read(4), 0); | 99 | myHeader.ER = BitConverter.ToUInt32(br_read(4), 0); |
100 | myHeader.FR = BitConverter.ToUInt32(br_read(4), 0); | 100 | myHeader.FR = BitConverter.ToUInt32(br_read(4), 0); |
101 | myHeader.SLR = BitConverter.ToUInt32(br_read(4), 0); | 101 | myHeader.SLR = BitConverter.ToUInt32(br_read(4), 0); |
102 | myHeader.GVR = BitConverter.ToUInt32(br_read(4), 0); | 102 | myHeader.GVR = BitConverter.ToUInt32(br_read(4), 0); |
103 | myHeader.GFR = BitConverter.ToUInt32(br_read(4), 0); | 103 | myHeader.GFR = BitConverter.ToUInt32(br_read(4), 0); |
104 | myHeader.PR = BitConverter.ToUInt32(br_read(4), 0); | 104 | myHeader.PR = BitConverter.ToUInt32(br_read(4), 0); |
105 | myHeader.ESR = BitConverter.ToUInt32(br_read(4), 0); | 105 | myHeader.ESR = BitConverter.ToUInt32(br_read(4), 0); |
106 | myHeader.SR = BitConverter.ToUInt32(br_read(4), 0); | 106 | myHeader.SR = BitConverter.ToUInt32(br_read(4), 0); |
107 | myHeader.NCE = BitConverter.ToUInt64(br_read(8), 0); | 107 | myHeader.NCE = BitConverter.ToUInt64(br_read(8), 0); |
108 | myHeader.NIE = BitConverter.ToUInt64(br_read(8), 0); | 108 | myHeader.NIE = BitConverter.ToUInt64(br_read(8), 0); |
109 | myHeader.NER = BitConverter.ToUInt64(br_read(8), 0); | 109 | myHeader.NER = BitConverter.ToUInt64(br_read(8), 0); |
110 | 110 | ||
111 | // Print Header Block to debug | 111 | // Print Header Block to debug |
112 | Common.SendToDebug("TM - Top of memory (size): " + myHeader.TM); | 112 | Common.SendToDebug("TM - Top of memory (size): " + myHeader.TM); |
113 | Common.SendToDebug("IP - Instruction Pointer (0=not running): " + myHeader.IP); | 113 | Common.SendToDebug("IP - Instruction Pointer (0=not running): " + myHeader.IP); |
114 | Common.SendToDebug("VN - Version number: " + myHeader.VN); | 114 | Common.SendToDebug("VN - Version number: " + myHeader.VN); |
115 | Common.SendToDebug("BP - Local Frame Pointer: " + myHeader.BP); | 115 | Common.SendToDebug("BP - Local Frame Pointer: " + myHeader.BP); |
116 | Common.SendToDebug("SP - Stack Pointer: " + myHeader.SP); | 116 | Common.SendToDebug("SP - Stack Pointer: " + myHeader.SP); |
117 | Common.SendToDebug("HR - Heap Register: " + myHeader.HR); | 117 | Common.SendToDebug("HR - Heap Register: " + myHeader.HR); |
118 | Common.SendToDebug("HP - Heap Pointer: " + myHeader.HP); | 118 | Common.SendToDebug("HP - Heap Pointer: " + myHeader.HP); |
119 | Common.SendToDebug("CS - Current State: " + myHeader.CS); | 119 | Common.SendToDebug("CS - Current State: " + myHeader.CS); |
120 | Common.SendToDebug("NS - Next State: " + myHeader.NS); | 120 | Common.SendToDebug("NS - Next State: " + myHeader.NS); |
121 | Common.SendToDebug("CE - Current Events: " + myHeader.CE); | 121 | Common.SendToDebug("CE - Current Events: " + myHeader.CE); |
122 | Common.SendToDebug("IE - In Event: " + myHeader.IE); | 122 | Common.SendToDebug("IE - In Event: " + myHeader.IE); |
123 | Common.SendToDebug("ER - Event Register: " + myHeader.ER); | 123 | Common.SendToDebug("ER - Event Register: " + myHeader.ER); |
124 | Common.SendToDebug("FR - Fault Register: " + myHeader.FR); | 124 | Common.SendToDebug("FR - Fault Register: " + myHeader.FR); |
125 | Common.SendToDebug("SLR - Sleep Register: " + myHeader.SLR); | 125 | Common.SendToDebug("SLR - Sleep Register: " + myHeader.SLR); |
126 | Common.SendToDebug("GVR - Global Variable Register: " + myHeader.GVR); | 126 | Common.SendToDebug("GVR - Global Variable Register: " + myHeader.GVR); |
127 | Common.SendToDebug("GFR - Global Function Register: " + myHeader.GFR); | 127 | Common.SendToDebug("GFR - Global Function Register: " + myHeader.GFR); |
128 | Common.SendToDebug("PR - Parameter Register: " + myHeader.PR); | 128 | Common.SendToDebug("PR - Parameter Register: " + myHeader.PR); |
129 | Common.SendToDebug("ESR - Energy Supply Register: " + myHeader.ESR); | 129 | Common.SendToDebug("ESR - Energy Supply Register: " + myHeader.ESR); |
130 | Common.SendToDebug("SR - State Register: " + myHeader.SR); | 130 | Common.SendToDebug("SR - State Register: " + myHeader.SR); |
131 | Common.SendToDebug("NCE - 64-bit Current Events: " + myHeader.NCE); | 131 | Common.SendToDebug("NCE - 64-bit Current Events: " + myHeader.NCE); |
132 | Common.SendToDebug("NIE - 64-bit In Events: " + myHeader.NIE); | 132 | Common.SendToDebug("NIE - 64-bit In Events: " + myHeader.NIE); |
133 | Common.SendToDebug("NER - 64-bit Event Register: " + myHeader.NER); | 133 | Common.SendToDebug("NER - 64-bit Event Register: " + myHeader.NER); |
134 | Common.SendToDebug("Read position when exiting HEADER BLOCK: " + fs.Position); | 134 | Common.SendToDebug("Read position when exiting HEADER BLOCK: " + fs.Position); |
135 | 135 | ||
136 | // STATIC BLOCK | 136 | // STATIC BLOCK |
137 | Common.SendToDebug("Reading STATIC BLOCK at: " + myHeader.GVR); | 137 | Common.SendToDebug("Reading STATIC BLOCK at: " + myHeader.GVR); |
138 | fs.Seek(myHeader.GVR, SeekOrigin.Begin); | 138 | fs.Seek(myHeader.GVR, SeekOrigin.Begin); |
139 | int StaticBlockCount = 0; | 139 | int StaticBlockCount = 0; |
140 | // Read function blocks until we hit GFR | 140 | // Read function blocks until we hit GFR |
141 | while (fs.Position < myHeader.GFR) | 141 | while (fs.Position < myHeader.GFR) |
142 | { | 142 | { |
143 | StaticBlockCount++; | 143 | StaticBlockCount++; |
144 | long startReadPos = fs.Position; | 144 | long startReadPos = fs.Position; |
145 | Common.SendToDebug("Reading Static Block " + StaticBlockCount + " at: " + startReadPos); | 145 | Common.SendToDebug("Reading Static Block " + StaticBlockCount + " at: " + startReadPos); |
146 | 146 | ||
147 | //fs.Seek(myHeader.GVR, SeekOrigin.Begin); | 147 | //fs.Seek(myHeader.GVR, SeekOrigin.Begin); |
148 | LSO_Struct.StaticBlock myStaticBlock = new LSO_Struct.StaticBlock(); | 148 | LSO_Struct.StaticBlock myStaticBlock = new LSO_Struct.StaticBlock(); |
149 | myStaticBlock.Static_Chunk_Header_Size = BitConverter.ToUInt32(br_read(4), 0); | 149 | myStaticBlock.Static_Chunk_Header_Size = BitConverter.ToUInt32(br_read(4), 0); |
150 | myStaticBlock.ObjectType = br_read(1)[0]; | 150 | myStaticBlock.ObjectType = br_read(1)[0]; |
151 | Common.SendToDebug("Static Block ObjectType: " + ((LSO_Enums.Variable_Type_Codes)myStaticBlock.ObjectType).ToString()); | 151 | Common.SendToDebug("Static Block ObjectType: " + ((LSO_Enums.Variable_Type_Codes)myStaticBlock.ObjectType).ToString()); |
152 | myStaticBlock.Unknown = br_read(1)[0]; | 152 | myStaticBlock.Unknown = br_read(1)[0]; |
153 | // Size of datatype varies -- what about strings? | 153 | // Size of datatype varies -- what about strings? |
154 | if (myStaticBlock.ObjectType != 0) | 154 | if (myStaticBlock.ObjectType != 0) |
155 | myStaticBlock.BlockVariable = br_read(getObjectSize(myStaticBlock.ObjectType)); | 155 | myStaticBlock.BlockVariable = br_read(getObjectSize(myStaticBlock.ObjectType)); |
156 | 156 | ||
157 | StaticBlocks.Add((UInt32)startReadPos, myStaticBlock); | 157 | StaticBlocks.Add((UInt32)startReadPos, myStaticBlock); |
158 | 158 | ||
159 | } | 159 | } |
160 | Common.SendToDebug("Number of Static Blocks read: " + StaticBlockCount); | 160 | Common.SendToDebug("Number of Static Blocks read: " + StaticBlockCount); |
161 | 161 | ||
162 | 162 | ||
163 | // FUNCTION BLOCK | 163 | // FUNCTION BLOCK |
164 | // Always right after STATIC BLOCK | 164 | // Always right after STATIC BLOCK |
165 | LSO_Struct.FunctionBlock myFunctionBlock = new LSO_Struct.FunctionBlock(); | 165 | LSO_Struct.FunctionBlock myFunctionBlock = new LSO_Struct.FunctionBlock(); |
166 | if (myHeader.GFR == myHeader.SR) | 166 | if (myHeader.GFR == myHeader.SR) |
167 | { | 167 | { |
168 | // If GFR and SR are at same position then there is no fuction block | 168 | // If GFR and SR are at same position then there is no fuction block |
169 | Common.SendToDebug("No FUNCTION BLOCK found"); | 169 | Common.SendToDebug("No FUNCTION BLOCK found"); |
170 | } | 170 | } |
171 | else | 171 | else |
172 | { | 172 | { |
173 | Common.SendToDebug("Reading FUNCTION BLOCK at: " + myHeader.GFR); | 173 | Common.SendToDebug("Reading FUNCTION BLOCK at: " + myHeader.GFR); |
174 | fs.Seek(myHeader.GFR, SeekOrigin.Begin); | 174 | fs.Seek(myHeader.GFR, SeekOrigin.Begin); |
175 | myFunctionBlock.FunctionCount = BitConverter.ToUInt32(br_read(4), 0); | 175 | myFunctionBlock.FunctionCount = BitConverter.ToUInt32(br_read(4), 0); |
176 | Common.SendToDebug("Number of functions in Fuction Block: " + myFunctionBlock.FunctionCount); | 176 | Common.SendToDebug("Number of functions in Fuction Block: " + myFunctionBlock.FunctionCount); |
177 | if (myFunctionBlock.FunctionCount > 0) | 177 | if (myFunctionBlock.FunctionCount > 0) |
178 | { | 178 | { |
179 | myFunctionBlock.CodeChunkPointer = new UInt32[myFunctionBlock.FunctionCount]; | 179 | myFunctionBlock.CodeChunkPointer = new UInt32[myFunctionBlock.FunctionCount]; |
180 | for (int i = 0; i < myFunctionBlock.FunctionCount; i++) | 180 | for (int i = 0; i < myFunctionBlock.FunctionCount; i++) |
181 | { | 181 | { |
182 | Common.SendToDebug("Reading function " + i + " at: " + fs.Position); | 182 | Common.SendToDebug("Reading function " + i + " at: " + fs.Position); |
183 | // TODO: ADD TO FUNCTION LIST (How do we identify it later?) | 183 | // TODO: ADD TO FUNCTION LIST (How do we identify it later?) |
184 | // Note! Absolute position | 184 | // Note! Absolute position |
185 | myFunctionBlock.CodeChunkPointer[i] = BitConverter.ToUInt32(br_read(4), 0) + myHeader.GFR; | 185 | myFunctionBlock.CodeChunkPointer[i] = BitConverter.ToUInt32(br_read(4), 0) + myHeader.GFR; |
186 | Common.SendToDebug("Fuction " + i + " code chunk position: " + myFunctionBlock.CodeChunkPointer[i]); | 186 | Common.SendToDebug("Fuction " + i + " code chunk position: " + myFunctionBlock.CodeChunkPointer[i]); |
187 | } | 187 | } |
188 | } | 188 | } |
189 | } | 189 | } |
190 | 190 | ||
191 | 191 | ||
192 | // STATE FRAME BLOCK | 192 | // STATE FRAME BLOCK |
193 | // Always right after FUNCTION BLOCK | 193 | // Always right after FUNCTION BLOCK |
194 | Common.SendToDebug("Reading STATE BLOCK at: " + myHeader.SR); | 194 | Common.SendToDebug("Reading STATE BLOCK at: " + myHeader.SR); |
195 | fs.Seek(myHeader.SR, SeekOrigin.Begin); | 195 | fs.Seek(myHeader.SR, SeekOrigin.Begin); |
196 | LSO_Struct.StateFrameBlock myStateFrameBlock = new LSO_Struct.StateFrameBlock(); | 196 | LSO_Struct.StateFrameBlock myStateFrameBlock = new LSO_Struct.StateFrameBlock(); |
197 | myStateFrameBlock.StateCount = BitConverter.ToUInt32(br_read(4), 0); | 197 | myStateFrameBlock.StateCount = BitConverter.ToUInt32(br_read(4), 0); |
198 | if (myStateFrameBlock.StateCount > 0) | 198 | if (myStateFrameBlock.StateCount > 0) |
199 | { | 199 | { |
200 | // Initialize array | 200 | // Initialize array |
201 | myStateFrameBlock.StatePointer = new LSO_Struct.StatePointerBlock[myStateFrameBlock.StateCount]; | 201 | myStateFrameBlock.StatePointer = new LSO_Struct.StatePointerBlock[myStateFrameBlock.StateCount]; |
202 | for (int i = 0; i < myStateFrameBlock.StateCount; i++) | 202 | for (int i = 0; i < myStateFrameBlock.StateCount; i++) |
203 | { | 203 | { |
204 | Common.SendToDebug("Reading STATE POINTER BLOCK " + (i + 1) + " at: " + fs.Position); | 204 | Common.SendToDebug("Reading STATE POINTER BLOCK " + (i + 1) + " at: " + fs.Position); |
205 | // Position is relative to state frame | 205 | // Position is relative to state frame |
206 | myStateFrameBlock.StatePointer[i].Location = myHeader.SR + BitConverter.ToUInt32(br_read(4), 0); | 206 | myStateFrameBlock.StatePointer[i].Location = myHeader.SR + BitConverter.ToUInt32(br_read(4), 0); |
207 | myStateFrameBlock.StatePointer[i].EventMask = new System.Collections.BitArray(br_read(8)); | 207 | myStateFrameBlock.StatePointer[i].EventMask = new System.Collections.BitArray(br_read(8)); |
208 | Common.SendToDebug("Pointer: " + myStateFrameBlock.StatePointer[i].Location); | 208 | Common.SendToDebug("Pointer: " + myStateFrameBlock.StatePointer[i].Location); |
209 | Common.SendToDebug("Total potential EventMask bits: " + myStateFrameBlock.StatePointer[i].EventMask.Count); | 209 | Common.SendToDebug("Total potential EventMask bits: " + myStateFrameBlock.StatePointer[i].EventMask.Count); |
210 | 210 | ||
211 | //// Read STATE BLOCK | 211 | //// Read STATE BLOCK |
212 | //long CurPos = fs.Position; | 212 | //long CurPos = fs.Position; |
213 | //fs.Seek(CurPos, SeekOrigin.Begin); | 213 | //fs.Seek(CurPos, SeekOrigin.Begin); |
214 | 214 | ||
215 | } | 215 | } |
216 | } | 216 | } |
217 | 217 | ||
218 | 218 | ||
219 | // STATE BLOCK | 219 | // STATE BLOCK |
220 | // For each StateFrameBlock there is one StateBlock with multiple event handlers | 220 | // For each StateFrameBlock there is one StateBlock with multiple event handlers |
221 | 221 | ||
222 | if (myStateFrameBlock.StateCount > 0) | 222 | if (myStateFrameBlock.StateCount > 0) |
223 | { | 223 | { |
224 | // Go through all State Frame Pointers found | 224 | // Go through all State Frame Pointers found |
225 | for (int i = 0; i < myStateFrameBlock.StateCount; i++) | 225 | for (int i = 0; i < myStateFrameBlock.StateCount; i++) |
226 | { | 226 | { |
227 | 227 | ||
228 | fs.Seek(myStateFrameBlock.StatePointer[i].Location, SeekOrigin.Begin); | 228 | fs.Seek(myStateFrameBlock.StatePointer[i].Location, SeekOrigin.Begin); |
229 | Common.SendToDebug("Reading STATE BLOCK " + (i + 1) + " at: " + fs.Position); | 229 | Common.SendToDebug("Reading STATE BLOCK " + (i + 1) + " at: " + fs.Position); |
230 | 230 | ||
231 | // READ: STATE BLOCK HEADER | 231 | // READ: STATE BLOCK HEADER |
232 | myStateFrameBlock.StatePointer[i].StateBlock = new LSO_Struct.StateBlock(); | 232 | myStateFrameBlock.StatePointer[i].StateBlock = new LSO_Struct.StateBlock(); |
233 | myStateFrameBlock.StatePointer[i].StateBlock.StartPos = (UInt32)fs.Position; // Note | 233 | myStateFrameBlock.StatePointer[i].StateBlock.StartPos = (UInt32)fs.Position; // Note |
234 | myStateFrameBlock.StatePointer[i].StateBlock.HeaderSize = BitConverter.ToUInt32(br_read(4), 0); | 234 | myStateFrameBlock.StatePointer[i].StateBlock.HeaderSize = BitConverter.ToUInt32(br_read(4), 0); |
235 | myStateFrameBlock.StatePointer[i].StateBlock.Unknown = br_read(1)[0]; | 235 | myStateFrameBlock.StatePointer[i].StateBlock.Unknown = br_read(1)[0]; |
236 | myStateFrameBlock.StatePointer[i].StateBlock.EndPos = (UInt32)fs.Position; // Note | 236 | myStateFrameBlock.StatePointer[i].StateBlock.EndPos = (UInt32)fs.Position; // Note |
237 | Common.SendToDebug("State block Start Pos: " + myStateFrameBlock.StatePointer[i].StateBlock.StartPos); | 237 | Common.SendToDebug("State block Start Pos: " + myStateFrameBlock.StatePointer[i].StateBlock.StartPos); |
238 | Common.SendToDebug("State block Header Size: " + myStateFrameBlock.StatePointer[i].StateBlock.HeaderSize); | 238 | Common.SendToDebug("State block Header Size: " + myStateFrameBlock.StatePointer[i].StateBlock.HeaderSize); |
239 | Common.SendToDebug("State block Header End Pos: " + myStateFrameBlock.StatePointer[i].StateBlock.EndPos); | 239 | Common.SendToDebug("State block Header End Pos: " + myStateFrameBlock.StatePointer[i].StateBlock.EndPos); |
240 | 240 | ||
241 | // We need to count number of bits flagged in EventMask? | 241 | // We need to count number of bits flagged in EventMask? |
242 | 242 | ||
243 | 243 | ||
244 | // for each bit in myStateFrameBlock.StatePointer[i].EventMask | 244 | // for each bit in myStateFrameBlock.StatePointer[i].EventMask |
245 | 245 | ||
246 | // ADDING TO ALL RIGHT NOW, SHOULD LIMIT TO ONLY THE ONES IN USE | 246 | // ADDING TO ALL RIGHT NOW, SHOULD LIMIT TO ONLY THE ONES IN USE |
247 | //TODO: Create event hooks | 247 | //TODO: Create event hooks |
248 | myStateFrameBlock.StatePointer[i].StateBlock.StateBlockHandlers = new LSO_Struct.StateBlockHandler[myStateFrameBlock.StatePointer[i].EventMask.Count - 1]; | 248 | myStateFrameBlock.StatePointer[i].StateBlock.StateBlockHandlers = new LSO_Struct.StateBlockHandler[myStateFrameBlock.StatePointer[i].EventMask.Count - 1]; |
249 | for (int ii = 0; ii < myStateFrameBlock.StatePointer[i].EventMask.Count - 1; ii++) | 249 | for (int ii = 0; ii < myStateFrameBlock.StatePointer[i].EventMask.Count - 1; ii++) |
250 | { | 250 | { |
251 | 251 | ||
252 | if (myStateFrameBlock.StatePointer[i].EventMask.Get(ii) == true) | 252 | if (myStateFrameBlock.StatePointer[i].EventMask.Get(ii) == true) |
253 | { | 253 | { |
254 | // We got an event | 254 | // We got an event |
255 | // READ: STATE BLOCK HANDLER | 255 | // READ: STATE BLOCK HANDLER |
256 | Common.SendToDebug("Reading STATE BLOCK " + (i + 1) + " HANDLER matching EVENT MASK " + ii + " (" + ((LSO_Enums.Event_Mask_Values)ii).ToString() + ") at: " + fs.Position); | 256 | Common.SendToDebug("Reading STATE BLOCK " + (i + 1) + " HANDLER matching EVENT MASK " + ii + " (" + ((LSO_Enums.Event_Mask_Values)ii).ToString() + ") at: " + fs.Position); |
257 | myStateFrameBlock.StatePointer[i].StateBlock.StateBlockHandlers[ii].CodeChunkPointer = myStateFrameBlock.StatePointer[i].StateBlock.EndPos + BitConverter.ToUInt32(br_read(4), 0); | 257 | myStateFrameBlock.StatePointer[i].StateBlock.StateBlockHandlers[ii].CodeChunkPointer = myStateFrameBlock.StatePointer[i].StateBlock.EndPos + BitConverter.ToUInt32(br_read(4), 0); |
258 | myStateFrameBlock.StatePointer[i].StateBlock.StateBlockHandlers[ii].CallFrameSize = BitConverter.ToUInt32(br_read(4), 0); | 258 | myStateFrameBlock.StatePointer[i].StateBlock.StateBlockHandlers[ii].CallFrameSize = BitConverter.ToUInt32(br_read(4), 0); |
259 | 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); | 259 | 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); |
260 | 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); | 260 | 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); |
261 | } | 261 | } |
262 | } | 262 | } |
263 | } | 263 | } |
264 | } | 264 | } |
265 | 265 | ||
266 | 266 | ||
267 | 267 | ||
268 | 268 | ||
269 | //// READ FUNCTION CODE CHUNKS | 269 | //// READ FUNCTION CODE CHUNKS |
270 | //// Functions + Function start pos (GFR) | 270 | //// Functions + Function start pos (GFR) |
271 | //// TODO: Somehow be able to identify and reference this | 271 | //// TODO: Somehow be able to identify and reference this |
272 | //LSO_Struct.CodeChunk[] myFunctionCodeChunk; | 272 | //LSO_Struct.CodeChunk[] myFunctionCodeChunk; |
273 | //if (myFunctionBlock.FunctionCount > 0) | 273 | //if (myFunctionBlock.FunctionCount > 0) |
274 | //{ | 274 | //{ |
275 | // myFunctionCodeChunk = new LSO_Struct.CodeChunk[myFunctionBlock.FunctionCount]; | 275 | // myFunctionCodeChunk = new LSO_Struct.CodeChunk[myFunctionBlock.FunctionCount]; |
276 | // for (int i = 0; i < myFunctionBlock.FunctionCount; i++) | 276 | // for (int i = 0; i < myFunctionBlock.FunctionCount; i++) |
277 | // { | 277 | // { |
278 | // Common.SendToDebug("Reading Function Code Chunk " + i); | 278 | // Common.SendToDebug("Reading Function Code Chunk " + i); |
279 | // myFunctionCodeChunk[i] = GetCodeChunk((UInt32)myFunctionBlock.CodeChunkPointer[i]); | 279 | // myFunctionCodeChunk[i] = GetCodeChunk((UInt32)myFunctionBlock.CodeChunkPointer[i]); |
280 | // } | 280 | // } |
281 | 281 | ||
282 | //} | 282 | //} |
283 | // READ EVENT CODE CHUNKS | 283 | // READ EVENT CODE CHUNKS |
284 | LSO_Struct.CodeChunk[] myEventCodeChunk; | 284 | LSO_Struct.CodeChunk[] myEventCodeChunk; |
285 | if (myStateFrameBlock.StateCount > 0) | 285 | if (myStateFrameBlock.StateCount > 0) |
286 | { | 286 | { |
287 | myEventCodeChunk = new LSO_Struct.CodeChunk[myStateFrameBlock.StateCount]; | 287 | myEventCodeChunk = new LSO_Struct.CodeChunk[myStateFrameBlock.StateCount]; |
288 | for (int i = 0; i < myStateFrameBlock.StateCount; i++) | 288 | for (int i = 0; i < myStateFrameBlock.StateCount; i++) |
289 | { | 289 | { |
290 | // TODO: Somehow organize events and functions so they can be found again, | 290 | // TODO: Somehow organize events and functions so they can be found again, |
291 | // two level search ain't no good | 291 | // two level search ain't no good |
292 | for (int ii = 0; ii < myStateFrameBlock.StatePointer[i].EventMask.Count - 1; ii++) | 292 | for (int ii = 0; ii < myStateFrameBlock.StatePointer[i].EventMask.Count - 1; ii++) |
293 | { | 293 | { |
294 | 294 | ||
295 | 295 | ||
296 | if (myStateFrameBlock.StatePointer[i].StateBlock.StateBlockHandlers[ii].CodeChunkPointer > 0) | 296 | if (myStateFrameBlock.StatePointer[i].StateBlock.StateBlockHandlers[ii].CodeChunkPointer > 0) |
297 | { | 297 | { |
298 | Common.SendToDebug("Reading Event Code Chunk state " + i + ", event " + (LSO_Enums.Event_Mask_Values)ii); | 298 | Common.SendToDebug("Reading Event Code Chunk state " + i + ", event " + (LSO_Enums.Event_Mask_Values)ii); |
299 | 299 | ||
300 | 300 | ||
301 | // Override a Method / Function | 301 | // Override a Method / Function |
302 | string eventname = i + "_event_" + (LSO_Enums.Event_Mask_Values)ii; | 302 | string eventname = i + "_event_" + (LSO_Enums.Event_Mask_Values)ii; |
303 | Common.SendToDebug("Event Name: " + eventname); | 303 | Common.SendToDebug("Event Name: " + eventname); |
304 | if (Common.IL_ProcessCodeChunks) | 304 | if (Common.IL_ProcessCodeChunks) |
305 | { | 305 | { |
306 | EventList.Add(eventname); | 306 | EventList.Add(eventname); |
307 | 307 | ||
308 | // JUMP TO CODE PROCESSOR | 308 | // JUMP TO CODE PROCESSOR |
309 | ProcessCodeChunk(myStateFrameBlock.StatePointer[i].StateBlock.StateBlockHandlers[ii].CodeChunkPointer, typeBuilder, eventname); | 309 | ProcessCodeChunk(myStateFrameBlock.StatePointer[i].StateBlock.StateBlockHandlers[ii].CodeChunkPointer, typeBuilder, eventname); |
310 | } | 310 | } |
311 | } | 311 | } |
312 | 312 | ||
313 | } | 313 | } |
314 | 314 | ||
315 | } | 315 | } |
316 | 316 | ||
317 | } | 317 | } |
318 | 318 | ||
319 | 319 | ||
320 | 320 | ||
321 | 321 | ||
322 | if (Common.IL_CreateFunctionList) | 322 | if (Common.IL_CreateFunctionList) |
323 | IL_INSERT_FUNCTIONLIST(); | 323 | IL_INSERT_FUNCTIONLIST(); |
324 | 324 | ||
325 | } | 325 | } |
326 | 326 | ||
327 | internal LSO_Struct.HeapBlock GetHeap(UInt32 pos) | 327 | internal LSO_Struct.HeapBlock GetHeap(UInt32 pos) |
328 | { | 328 | { |
329 | // HEAP BLOCK | 329 | // HEAP BLOCK |
330 | // TODO:? Special read for strings/keys (null terminated) and lists (pointers to other HEAP entries) | 330 | // TODO:? Special read for strings/keys (null terminated) and lists (pointers to other HEAP entries) |
331 | Common.SendToDebug("Reading HEAP BLOCK at: " + pos); | 331 | Common.SendToDebug("Reading HEAP BLOCK at: " + pos); |
332 | fs.Seek(pos, SeekOrigin.Begin); | 332 | fs.Seek(pos, SeekOrigin.Begin); |
333 | 333 | ||
334 | LSO_Struct.HeapBlock myHeapBlock = new LSO_Struct.HeapBlock(); | 334 | LSO_Struct.HeapBlock myHeapBlock = new LSO_Struct.HeapBlock(); |
335 | myHeapBlock.DataBlockSize = BitConverter.ToInt32(br_read(4), 0); | 335 | myHeapBlock.DataBlockSize = BitConverter.ToInt32(br_read(4), 0); |
336 | myHeapBlock.ObjectType = br_read(1)[0]; | 336 | myHeapBlock.ObjectType = br_read(1)[0]; |
337 | myHeapBlock.ReferenceCount = BitConverter.ToUInt16(br_read(2), 0); | 337 | myHeapBlock.ReferenceCount = BitConverter.ToUInt16(br_read(2), 0); |
338 | //myHeapBlock.Data = br_read(getObjectSize(myHeapBlock.ObjectType)); | 338 | //myHeapBlock.Data = br_read(getObjectSize(myHeapBlock.ObjectType)); |
339 | // Don't read it reversed | 339 | // Don't read it reversed |
340 | myHeapBlock.Data = new byte[myHeapBlock.DataBlockSize - 1]; | 340 | myHeapBlock.Data = new byte[myHeapBlock.DataBlockSize - 1]; |
341 | br.Read(myHeapBlock.Data, 0, myHeapBlock.DataBlockSize - 1); | 341 | br.Read(myHeapBlock.Data, 0, myHeapBlock.DataBlockSize - 1); |
342 | 342 | ||
343 | 343 | ||
344 | Common.SendToDebug("Heap Block Data Block Size: " + myHeapBlock.DataBlockSize); | 344 | Common.SendToDebug("Heap Block Data Block Size: " + myHeapBlock.DataBlockSize); |
345 | Common.SendToDebug("Heap Block ObjectType: " + ((LSO_Enums.Variable_Type_Codes)myHeapBlock.ObjectType).ToString()); | 345 | Common.SendToDebug("Heap Block ObjectType: " + ((LSO_Enums.Variable_Type_Codes)myHeapBlock.ObjectType).ToString()); |
346 | Common.SendToDebug("Heap Block Reference Count: " + myHeapBlock.ReferenceCount); | 346 | Common.SendToDebug("Heap Block Reference Count: " + myHeapBlock.ReferenceCount); |
347 | 347 | ||
348 | return myHeapBlock; | 348 | return myHeapBlock; |
349 | } | 349 | } |
350 | private byte[] br_read(int len) | 350 | private byte[] br_read(int len) |
351 | { | 351 | { |
352 | if (len <= 0) | 352 | if (len <= 0) |
353 | return null; | 353 | return null; |
354 | 354 | ||
355 | try | 355 | try |
356 | { | 356 | { |
357 | byte[] bytes = new byte[len]; | 357 | byte[] bytes = new byte[len]; |
358 | for (int i = len - 1; i > -1; i--) | 358 | for (int i = len - 1; i > -1; i--) |
359 | bytes[i] = br.ReadByte(); | 359 | bytes[i] = br.ReadByte(); |
360 | return bytes; | 360 | return bytes; |
361 | } | 361 | } |
362 | catch (Exception e) | 362 | catch (Exception e) |
363 | { | 363 | { |
364 | Common.SendToDebug("Exception: " + e.ToString()); | 364 | Common.SendToDebug("Exception: " + e.ToString()); |
365 | throw (e); | 365 | throw (e); |
366 | } | 366 | } |
367 | } | 367 | } |
368 | //private byte[] br_read_smallendian(int len) | 368 | //private byte[] br_read_smallendian(int len) |
369 | //{ | 369 | //{ |
370 | // byte[] bytes = new byte[len]; | 370 | // byte[] bytes = new byte[len]; |
371 | // br.Read(bytes,0, len); | 371 | // br.Read(bytes,0, len); |
372 | // return bytes; | 372 | // return bytes; |
373 | //} | 373 | //} |
374 | private Type getLLObjectType(byte objectCode) | 374 | private Type getLLObjectType(byte objectCode) |
375 | { | 375 | { |
376 | switch ((LSO_Enums.Variable_Type_Codes)objectCode) | 376 | switch ((LSO_Enums.Variable_Type_Codes)objectCode) |
377 | { | 377 | { |
378 | case LSO_Enums.Variable_Type_Codes.Void: return typeof(void); | 378 | case LSO_Enums.Variable_Type_Codes.Void: return typeof(void); |
379 | case LSO_Enums.Variable_Type_Codes.Integer: return typeof(UInt32); | 379 | case LSO_Enums.Variable_Type_Codes.Integer: return typeof(UInt32); |
380 | case LSO_Enums.Variable_Type_Codes.Float: return typeof(float); | 380 | case LSO_Enums.Variable_Type_Codes.Float: return typeof(float); |
381 | case LSO_Enums.Variable_Type_Codes.String: return typeof(string); | 381 | case LSO_Enums.Variable_Type_Codes.String: return typeof(string); |
382 | case LSO_Enums.Variable_Type_Codes.Key: return typeof(string); | 382 | case LSO_Enums.Variable_Type_Codes.Key: return typeof(string); |
383 | case LSO_Enums.Variable_Type_Codes.Vector: return typeof(LSO_Enums.Vector); | 383 | case LSO_Enums.Variable_Type_Codes.Vector: return typeof(LSO_Enums.Vector); |
384 | case LSO_Enums.Variable_Type_Codes.Rotation: return typeof(LSO_Enums.Rotation); | 384 | case LSO_Enums.Variable_Type_Codes.Rotation: return typeof(LSO_Enums.Rotation); |
385 | case LSO_Enums.Variable_Type_Codes.List: | 385 | case LSO_Enums.Variable_Type_Codes.List: |
386 | Common.SendToDebug("TODO: List datatype not implemented yet!"); | 386 | Common.SendToDebug("TODO: List datatype not implemented yet!"); |
387 | return typeof(System.Collections.ArrayList); | 387 | return typeof(System.Collections.ArrayList); |
388 | case LSO_Enums.Variable_Type_Codes.Null: | 388 | case LSO_Enums.Variable_Type_Codes.Null: |
389 | Common.SendToDebug("TODO: Datatype null is not implemented, using string instead.!"); | 389 | Common.SendToDebug("TODO: Datatype null is not implemented, using string instead.!"); |
390 | return typeof(string); | 390 | return typeof(string); |
391 | default: | 391 | default: |
392 | Common.SendToDebug("Lookup of LSL datatype " + objectCode + " to .Net datatype failed: Unknown LSL datatype. Defaulting to object."); | 392 | Common.SendToDebug("Lookup of LSL datatype " + objectCode + " to .Net datatype failed: Unknown LSL datatype. Defaulting to object."); |
393 | return typeof(object); | 393 | return typeof(object); |
394 | } | 394 | } |
395 | } | 395 | } |
396 | private int getObjectSize(byte ObjectType) | 396 | private int getObjectSize(byte ObjectType) |
397 | { | 397 | { |
398 | switch ((LSO_Enums.Variable_Type_Codes)ObjectType) | 398 | switch ((LSO_Enums.Variable_Type_Codes)ObjectType) |
399 | { | 399 | { |
400 | case LSO_Enums.Variable_Type_Codes.Integer: | 400 | case LSO_Enums.Variable_Type_Codes.Integer: |
401 | case LSO_Enums.Variable_Type_Codes.Float: | 401 | case LSO_Enums.Variable_Type_Codes.Float: |
402 | case LSO_Enums.Variable_Type_Codes.String: | 402 | case LSO_Enums.Variable_Type_Codes.String: |
403 | case LSO_Enums.Variable_Type_Codes.Key: | 403 | case LSO_Enums.Variable_Type_Codes.Key: |
404 | case LSO_Enums.Variable_Type_Codes.List: | 404 | case LSO_Enums.Variable_Type_Codes.List: |
405 | return 4; | 405 | return 4; |
406 | case LSO_Enums.Variable_Type_Codes.Vector: | 406 | case LSO_Enums.Variable_Type_Codes.Vector: |
407 | return 12; | 407 | return 12; |
408 | case LSO_Enums.Variable_Type_Codes.Rotation: | 408 | case LSO_Enums.Variable_Type_Codes.Rotation: |
409 | return 16; | 409 | return 16; |
410 | default: | 410 | default: |
411 | return 0; | 411 | return 0; |
412 | } | 412 | } |
413 | } | 413 | } |
414 | private string Read_String() | 414 | private string Read_String() |
415 | { | 415 | { |
416 | string ret = ""; | 416 | string ret = ""; |
417 | byte reader = br_read(1)[0]; | 417 | byte reader = br_read(1)[0]; |
418 | while (reader != 0x000) | 418 | while (reader != 0x000) |
419 | { | 419 | { |
420 | ret += (char)reader; | 420 | ret += (char)reader; |
421 | reader = br_read(1)[0]; | 421 | reader = br_read(1)[0]; |
422 | } | 422 | } |
423 | return ret; | 423 | return ret; |
424 | } | 424 | } |
425 | 425 | ||
426 | /// <summary> | 426 | /// <summary> |
427 | /// Reads a code chunk and creates IL | 427 | /// Reads a code chunk and creates IL |
428 | /// </summary> | 428 | /// </summary> |
429 | /// <param name="pos">Absolute position in file. REMEMBER TO ADD myHeader.GFR!</param> | 429 | /// <param name="pos">Absolute position in file. REMEMBER TO ADD myHeader.GFR!</param> |
430 | /// <param name="typeBuilder">TypeBuilder for assembly</param> | 430 | /// <param name="typeBuilder">TypeBuilder for assembly</param> |
431 | /// <param name="eventname">Name of event (function) to generate</param> | 431 | /// <param name="eventname">Name of event (function) to generate</param> |
432 | private void ProcessCodeChunk(UInt32 pos, TypeBuilder typeBuilder, string eventname) | 432 | private void ProcessCodeChunk(UInt32 pos, TypeBuilder typeBuilder, string eventname) |
433 | { | 433 | { |
434 | 434 | ||
435 | LSO_Struct.CodeChunk myCodeChunk = new LSO_Struct.CodeChunk(); | 435 | LSO_Struct.CodeChunk myCodeChunk = new LSO_Struct.CodeChunk(); |
436 | 436 | ||
437 | Common.SendToDebug("Reading Function Code Chunk at: " + pos); | 437 | Common.SendToDebug("Reading Function Code Chunk at: " + pos); |
438 | fs.Seek(pos, SeekOrigin.Begin); | 438 | fs.Seek(pos, SeekOrigin.Begin); |
439 | myCodeChunk.CodeChunkHeaderSize = BitConverter.ToUInt32(br_read(4), 0); | 439 | myCodeChunk.CodeChunkHeaderSize = BitConverter.ToUInt32(br_read(4), 0); |
440 | Common.SendToDebug("CodeChunk Header Size: " + myCodeChunk.CodeChunkHeaderSize); | 440 | Common.SendToDebug("CodeChunk Header Size: " + myCodeChunk.CodeChunkHeaderSize); |
441 | // Read until null | 441 | // Read until null |
442 | myCodeChunk.Comment = Read_String(); | 442 | myCodeChunk.Comment = Read_String(); |
443 | Common.SendToDebug("Function comment: " + myCodeChunk.Comment); | 443 | Common.SendToDebug("Function comment: " + myCodeChunk.Comment); |
444 | myCodeChunk.ReturnTypePos = br_read(1)[0]; | 444 | myCodeChunk.ReturnTypePos = br_read(1)[0]; |
445 | myCodeChunk.ReturnType = GetStaticBlock((long)myCodeChunk.ReturnTypePos + (long)myHeader.GVR); | 445 | myCodeChunk.ReturnType = GetStaticBlock((long)myCodeChunk.ReturnTypePos + (long)myHeader.GVR); |
446 | Common.SendToDebug("Return type #" + myCodeChunk.ReturnType.ObjectType + ": " + ((LSO_Enums.Variable_Type_Codes)myCodeChunk.ReturnType.ObjectType).ToString()); | 446 | Common.SendToDebug("Return type #" + myCodeChunk.ReturnType.ObjectType + ": " + ((LSO_Enums.Variable_Type_Codes)myCodeChunk.ReturnType.ObjectType).ToString()); |
447 | 447 | ||
448 | 448 | ||
449 | // TODO: How to determine number of codechunks -- does this method work? | 449 | // TODO: How to determine number of codechunks -- does this method work? |
450 | myCodeChunk.CodeChunkArguments = new System.Collections.Generic.List<LSO_Struct.CodeChunkArgument>(); | 450 | myCodeChunk.CodeChunkArguments = new System.Collections.Generic.List<LSO_Struct.CodeChunkArgument>(); |
451 | byte reader = br_read(1)[0]; | 451 | byte reader = br_read(1)[0]; |
452 | reader = br_read(1)[0]; | 452 | reader = br_read(1)[0]; |
453 | 453 | ||
454 | // NOTE ON CODE CHUNK ARGUMENTS | 454 | // NOTE ON CODE CHUNK ARGUMENTS |
455 | // This determins type definition | 455 | // This determins type definition |
456 | int ccount = 0; | 456 | int ccount = 0; |
457 | while (reader != 0x000) | 457 | while (reader != 0x000) |
458 | { | 458 | { |
459 | ccount++; | 459 | ccount++; |
460 | Common.SendToDebug("Reading Code Chunk Argument " + ccount); | 460 | Common.SendToDebug("Reading Code Chunk Argument " + ccount); |
461 | LSO_Struct.CodeChunkArgument CCA = new LSO_Struct.CodeChunkArgument(); | 461 | LSO_Struct.CodeChunkArgument CCA = new LSO_Struct.CodeChunkArgument(); |
462 | CCA.FunctionReturnTypePos = reader; | 462 | CCA.FunctionReturnTypePos = reader; |
463 | reader = br_read(1)[0]; | 463 | reader = br_read(1)[0]; |
464 | CCA.NullString = reader; | 464 | CCA.NullString = reader; |
465 | CCA.FunctionReturnType = GetStaticBlock(CCA.FunctionReturnTypePos + myHeader.GVR); | 465 | CCA.FunctionReturnType = GetStaticBlock(CCA.FunctionReturnTypePos + myHeader.GVR); |
466 | myCodeChunk.CodeChunkArguments.Add(CCA); | 466 | myCodeChunk.CodeChunkArguments.Add(CCA); |
467 | Common.SendToDebug("Code Chunk Argument " + ccount + " type #" + CCA.FunctionReturnType.ObjectType + ": " + (LSO_Enums.Variable_Type_Codes)CCA.FunctionReturnType.ObjectType); | 467 | Common.SendToDebug("Code Chunk Argument " + ccount + " type #" + CCA.FunctionReturnType.ObjectType + ": " + (LSO_Enums.Variable_Type_Codes)CCA.FunctionReturnType.ObjectType); |
468 | } | 468 | } |
469 | // Create string array | 469 | // Create string array |
470 | Type[] MethodArgs = new Type[myCodeChunk.CodeChunkArguments.Count]; | 470 | Type[] MethodArgs = new Type[myCodeChunk.CodeChunkArguments.Count]; |
471 | for (int _ic = 0; _ic < myCodeChunk.CodeChunkArguments.Count; _ic++) | 471 | for (int _ic = 0; _ic < myCodeChunk.CodeChunkArguments.Count; _ic++) |
472 | { | 472 | { |
473 | MethodArgs[_ic] = getLLObjectType(myCodeChunk.CodeChunkArguments[_ic].FunctionReturnType.ObjectType); | 473 | MethodArgs[_ic] = getLLObjectType(myCodeChunk.CodeChunkArguments[_ic].FunctionReturnType.ObjectType); |
474 | Common.SendToDebug("Method argument " + _ic + ": " + getLLObjectType(myCodeChunk.CodeChunkArguments[_ic].FunctionReturnType.ObjectType).ToString()); | 474 | Common.SendToDebug("Method argument " + _ic + ": " + getLLObjectType(myCodeChunk.CodeChunkArguments[_ic].FunctionReturnType.ObjectType).ToString()); |
475 | } | 475 | } |
476 | // End marker is 0x000 | 476 | // End marker is 0x000 |
477 | myCodeChunk.EndMarker = reader; | 477 | myCodeChunk.EndMarker = reader; |
478 | 478 | ||
479 | 479 | ||
480 | // | 480 | // |
481 | // Emit: START OF METHOD (FUNCTION) | 481 | // Emit: START OF METHOD (FUNCTION) |
482 | // | 482 | // |
483 | 483 | ||
484 | Common.SendToDebug("CLR:" + eventname + ":MethodBuilder methodBuilder = typeBuilder.DefineMethod..."); | 484 | Common.SendToDebug("CLR:" + eventname + ":MethodBuilder methodBuilder = typeBuilder.DefineMethod..."); |
485 | MethodBuilder methodBuilder = typeBuilder.DefineMethod(eventname, | 485 | MethodBuilder methodBuilder = typeBuilder.DefineMethod(eventname, |
486 | MethodAttributes.Public, | 486 | MethodAttributes.Public, |
487 | typeof(void), | 487 | typeof(void), |
488 | new Type[] { typeof(object) }); | 488 | new Type[] { typeof(object) }); |
489 | //MethodArgs); | 489 | //MethodArgs); |
490 | //typeof(void), //getLLObjectType(myCodeChunk.ReturnType), | 490 | //typeof(void), //getLLObjectType(myCodeChunk.ReturnType), |
491 | // new Type[] { typeof(object) }, //); | 491 | // new Type[] { typeof(object) }, //); |
492 | 492 | ||
493 | //Common.SendToDebug("CLR:" + eventname + ":typeBuilder.DefineMethodOverride(methodBuilder..."); | 493 | //Common.SendToDebug("CLR:" + eventname + ":typeBuilder.DefineMethodOverride(methodBuilder..."); |
494 | //typeBuilder.DefineMethodOverride(methodBuilder, | 494 | //typeBuilder.DefineMethodOverride(methodBuilder, |
495 | // typeof(LSL_CLRInterface.LSLScript).GetMethod(eventname)); | 495 | // typeof(LSL_CLRInterface.LSLScript).GetMethod(eventname)); |
496 | 496 | ||
497 | // Create the IL generator | 497 | // Create the IL generator |
498 | 498 | ||
499 | Common.SendToDebug("CLR:" + eventname + ":ILGenerator il = methodBuilder.GetILGenerator();"); | 499 | Common.SendToDebug("CLR:" + eventname + ":ILGenerator il = methodBuilder.GetILGenerator();"); |
500 | ILGenerator il = methodBuilder.GetILGenerator(); | 500 | ILGenerator il = methodBuilder.GetILGenerator(); |
501 | 501 | ||
502 | 502 | ||
503 | if (Common.IL_UseTryCatch) | 503 | if (Common.IL_UseTryCatch) |
504 | IL_INSERT_TRY(il, eventname); | 504 | IL_INSERT_TRY(il, eventname); |
505 | 505 | ||
506 | 506 | ||
507 | 507 | ||
508 | // Push Console.WriteLine command to stack ... Console.WriteLine("Hello World!"); | 508 | // Push Console.WriteLine command to stack ... Console.WriteLine("Hello World!"); |
509 | //Common.SendToDebug("CLR:" + eventname + ":il.Emit(OpCodes.Call..."); | 509 | //Common.SendToDebug("CLR:" + eventname + ":il.Emit(OpCodes.Call..."); |
510 | //il.Emit(OpCodes.Call, typeof(Console).GetMethod | 510 | //il.Emit(OpCodes.Call, typeof(Console).GetMethod |
511 | // ("WriteLine", new Type[] { typeof(string) })); | 511 | // ("WriteLine", new Type[] { typeof(string) })); |
512 | 512 | ||
513 | //Common.SendToDebug("STARTUP: il.Emit(OpCodes.Ldc_I4_S, 0);"); | 513 | //Common.SendToDebug("STARTUP: il.Emit(OpCodes.Ldc_I4_S, 0);"); |
514 | 514 | ||
515 | //il.Emit(OpCodes.Ldc_I4_S, 0); | 515 | //il.Emit(OpCodes.Ldc_I4_S, 0); |
516 | for (int _ic = 0; _ic < myCodeChunk.CodeChunkArguments.Count; _ic++) | 516 | for (int _ic = 0; _ic < myCodeChunk.CodeChunkArguments.Count; _ic++) |
517 | { | 517 | { |
518 | Common.SendToDebug("PARAMS: il.Emit(OpCodes.Ldarg, " + _ic + ");"); | 518 | Common.SendToDebug("PARAMS: il.Emit(OpCodes.Ldarg, " + _ic + ");"); |
519 | il.Emit(OpCodes.Ldarg, _ic); | 519 | il.Emit(OpCodes.Ldarg, _ic); |
520 | } | 520 | } |
521 | 521 | ||
522 | 522 | ||
523 | 523 | ||
524 | // | 524 | // |
525 | // CALLING OPCODE PROCESSOR, one command at the time TO GENERATE IL | 525 | // CALLING OPCODE PROCESSOR, one command at the time TO GENERATE IL |
526 | // | 526 | // |
527 | bool FoundRet = false; | 527 | bool FoundRet = false; |
528 | while (FoundRet == false) | 528 | while (FoundRet == false) |
529 | { | 529 | { |
530 | FoundRet = LSL_PROCESS_OPCODE(il); | 530 | FoundRet = LSL_PROCESS_OPCODE(il); |
531 | } | 531 | } |
532 | 532 | ||
533 | 533 | ||
534 | if (Common.IL_UseTryCatch) | 534 | if (Common.IL_UseTryCatch) |
535 | IL_INSERT_END_TRY(il, eventname); | 535 | IL_INSERT_END_TRY(il, eventname); |
536 | 536 | ||
537 | // Emit: RETURN FROM METHOD | 537 | // Emit: RETURN FROM METHOD |
538 | il.Emit(OpCodes.Ret); | 538 | il.Emit(OpCodes.Ret); |
539 | 539 | ||
540 | return; | 540 | return; |
541 | 541 | ||
542 | } | 542 | } |
543 | 543 | ||
544 | private void IL_INSERT_FUNCTIONLIST() | 544 | private void IL_INSERT_FUNCTIONLIST() |
545 | { | 545 | { |
546 | 546 | ||
547 | Common.SendToDebug("Creating function list"); | 547 | Common.SendToDebug("Creating function list"); |
548 | 548 | ||
549 | 549 | ||
550 | string eventname = "GetFunctions"; | 550 | string eventname = "GetFunctions"; |
551 | 551 | ||
552 | Common.SendToDebug("Creating IL " + eventname); | 552 | Common.SendToDebug("Creating IL " + eventname); |
553 | // Define a private String field. | 553 | // Define a private String field. |
554 | //FieldBuilder myField = myTypeBuilder.DefineField("EventList", typeof(String[]), FieldAttributes.Public); | 554 | //FieldBuilder myField = myTypeBuilder.DefineField("EventList", typeof(String[]), FieldAttributes.Public); |
555 | 555 | ||
556 | 556 | ||
557 | //FieldBuilder mem = typeBuilder.DefineField("mem", typeof(Array), FieldAttributes.Private); | 557 | //FieldBuilder mem = typeBuilder.DefineField("mem", typeof(Array), FieldAttributes.Private); |
558 | 558 | ||
559 | 559 | ||
560 | 560 | ||
561 | MethodBuilder methodBuilder = typeBuilder.DefineMethod(eventname, | 561 | MethodBuilder methodBuilder = typeBuilder.DefineMethod(eventname, |
562 | MethodAttributes.Public, | 562 | MethodAttributes.Public, |
563 | typeof(string[]), | 563 | typeof(string[]), |
564 | null); | 564 | null); |
565 | 565 | ||
566 | //typeBuilder.DefineMethodOverride(methodBuilder, | 566 | //typeBuilder.DefineMethodOverride(methodBuilder, |
567 | // typeof(LSL_CLRInterface.LSLScript).GetMethod(eventname)); | 567 | // typeof(LSL_CLRInterface.LSLScript).GetMethod(eventname)); |
568 | 568 | ||
569 | ILGenerator il = methodBuilder.GetILGenerator(); | 569 | ILGenerator il = methodBuilder.GetILGenerator(); |
570 | 570 | ||
571 | 571 | ||
572 | 572 | ||
573 | 573 | ||
574 | // IL_INSERT_TRY(il, eventname); | 574 | // IL_INSERT_TRY(il, eventname); |
575 | 575 | ||
576 | // // Push string to stack | 576 | // // Push string to stack |
577 | // il.Emit(OpCodes.Ldstr, "Inside " + eventname); | 577 | // il.Emit(OpCodes.Ldstr, "Inside " + eventname); |
578 | 578 | ||
579 | //// Push Console.WriteLine command to stack ... Console.WriteLine("Hello World!"); | 579 | //// Push Console.WriteLine command to stack ... Console.WriteLine("Hello World!"); |
580 | //il.Emit(OpCodes.Call, typeof(Console).GetMethod | 580 | //il.Emit(OpCodes.Call, typeof(Console).GetMethod |
581 | // ("WriteLine", new Type[] { typeof(string) })); | 581 | // ("WriteLine", new Type[] { typeof(string) })); |
582 | 582 | ||
583 | //initIL.Emit(OpCodes.Newobj, typeof(string[])); | 583 | //initIL.Emit(OpCodes.Newobj, typeof(string[])); |
584 | 584 | ||
585 | //string[] MyArray = new string[2] { "TestItem1" , "TestItem2" }; | 585 | //string[] MyArray = new string[2] { "TestItem1" , "TestItem2" }; |
586 | 586 | ||
587 | ////il.Emit(OpCodes.Ldarg_0); | 587 | ////il.Emit(OpCodes.Ldarg_0); |
588 | 588 | ||
589 | il.DeclareLocal(typeof(string[])); | 589 | il.DeclareLocal(typeof(string[])); |
590 | 590 | ||
591 | ////il.Emit(OpCodes.Ldarg_0); | 591 | ////il.Emit(OpCodes.Ldarg_0); |
592 | il.Emit(OpCodes.Ldc_I4, EventList.Count); // Specify array length | 592 | il.Emit(OpCodes.Ldc_I4, EventList.Count); // Specify array length |
593 | il.Emit(OpCodes.Newarr, typeof(String)); // create new string array | 593 | il.Emit(OpCodes.Newarr, typeof(String)); // create new string array |
594 | il.Emit(OpCodes.Stloc_0); // Store array as local variable 0 in stack | 594 | il.Emit(OpCodes.Stloc_0); // Store array as local variable 0 in stack |
595 | ////SetFunctionList | 595 | ////SetFunctionList |
596 | 596 | ||
597 | for (int lv = 0; lv < EventList.Count; lv++) | 597 | for (int lv = 0; lv < EventList.Count; lv++) |
598 | { | 598 | { |
599 | il.Emit(OpCodes.Ldloc_0); // Load local variable 0 onto stack | 599 | il.Emit(OpCodes.Ldloc_0); // Load local variable 0 onto stack |
600 | il.Emit(OpCodes.Ldc_I4, lv); // Push index position | 600 | il.Emit(OpCodes.Ldc_I4, lv); // Push index position |
601 | il.Emit(OpCodes.Ldstr, EventList[lv]); // Push value | 601 | il.Emit(OpCodes.Ldstr, EventList[lv]); // Push value |
602 | il.Emit(OpCodes.Stelem_Ref); // Perform array[index] = value | 602 | il.Emit(OpCodes.Stelem_Ref); // Perform array[index] = value |
603 | 603 | ||
604 | //il.Emit(OpCodes.Ldarg_0); | 604 | //il.Emit(OpCodes.Ldarg_0); |
605 | //il.Emit(OpCodes.Ldstr, EventList[lv]); // Push value | 605 | //il.Emit(OpCodes.Ldstr, EventList[lv]); // Push value |
606 | //il.Emit(OpCodes.Call, typeof(LSL_BaseClass).GetMethod("AddFunction", new Type[] { typeof(string) })); | 606 | //il.Emit(OpCodes.Call, typeof(LSL_BaseClass).GetMethod("AddFunction", new Type[] { typeof(string) })); |
607 | 607 | ||
608 | } | 608 | } |
609 | 609 | ||
610 | 610 | ||
611 | 611 | ||
612 | // IL_INSERT_END_TRY(il, eventname); | 612 | // IL_INSERT_END_TRY(il, eventname); |
613 | 613 | ||
614 | 614 | ||
615 | il.Emit(OpCodes.Ldloc_0); // Load local variable 0 onto stack | 615 | il.Emit(OpCodes.Ldloc_0); // Load local variable 0 onto stack |
616 | // il.Emit(OpCodes.Call, typeof(LSL_BaseClass).GetMethod("SetFunctionList", new Type[] { typeof(Array) })); | 616 | // il.Emit(OpCodes.Call, typeof(LSL_BaseClass).GetMethod("SetFunctionList", new Type[] { typeof(Array) })); |
617 | 617 | ||
618 | il.Emit(OpCodes.Ret); // Return | 618 | il.Emit(OpCodes.Ret); // Return |
619 | 619 | ||
620 | } | 620 | } |
621 | 621 | ||
622 | 622 | ||
623 | private void IL_INSERT_TRY(ILGenerator il, string eventname) | 623 | private void IL_INSERT_TRY(ILGenerator il, string eventname) |
624 | { | 624 | { |
625 | /* | 625 | /* |
626 | * CLR TRY | 626 | * CLR TRY |
627 | */ | 627 | */ |
628 | //Common.SendToDebug("CLR:" + eventname + ":il.BeginExceptionBlock()"); | 628 | //Common.SendToDebug("CLR:" + eventname + ":il.BeginExceptionBlock()"); |
629 | il.BeginExceptionBlock(); | 629 | il.BeginExceptionBlock(); |
630 | 630 | ||
631 | // Push "Hello World!" string to stack | 631 | // Push "Hello World!" string to stack |
632 | //Common.SendToDebug("CLR:" + eventname + ":il.Emit(OpCodes.Ldstr..."); | 632 | //Common.SendToDebug("CLR:" + eventname + ":il.Emit(OpCodes.Ldstr..."); |
633 | //il.Emit(OpCodes.Ldstr, "Starting CLR dynamic execution of: " + eventname); | 633 | //il.Emit(OpCodes.Ldstr, "Starting CLR dynamic execution of: " + eventname); |
634 | 634 | ||
635 | } | 635 | } |
636 | 636 | ||
637 | private void IL_INSERT_END_TRY(ILGenerator il, string eventname) | 637 | private void IL_INSERT_END_TRY(ILGenerator il, string eventname) |
638 | { | 638 | { |
639 | /* | 639 | /* |
640 | * CATCH | 640 | * CATCH |
641 | */ | 641 | */ |
642 | Common.SendToDebug("CLR:" + eventname + ":il.BeginCatchBlock(typeof(Exception));"); | 642 | Common.SendToDebug("CLR:" + eventname + ":il.BeginCatchBlock(typeof(Exception));"); |
643 | il.BeginCatchBlock(typeof(Exception)); | 643 | il.BeginCatchBlock(typeof(Exception)); |
644 | 644 | ||
645 | // Push "Hello World!" string to stack | 645 | // Push "Hello World!" string to stack |
646 | Common.SendToDebug("CLR:" + eventname + ":il.Emit(OpCodes.Ldstr..."); | 646 | Common.SendToDebug("CLR:" + eventname + ":il.Emit(OpCodes.Ldstr..."); |
647 | il.Emit(OpCodes.Ldstr, "Execption executing dynamic CLR function " + eventname + ": "); | 647 | il.Emit(OpCodes.Ldstr, "Execption executing dynamic CLR function " + eventname + ": "); |
648 | 648 | ||
649 | //call void [mscorlib]System.Console::WriteLine(string) | 649 | //call void [mscorlib]System.Console::WriteLine(string) |
650 | Common.SendToDebug("CLR:" + eventname + ":il.Emit(OpCodes.Call..."); | 650 | Common.SendToDebug("CLR:" + eventname + ":il.Emit(OpCodes.Call..."); |
651 | il.Emit(OpCodes.Call, typeof(Console).GetMethod | 651 | il.Emit(OpCodes.Call, typeof(Console).GetMethod |
652 | ("Write", new Type[] { typeof(string) })); | 652 | ("Write", new Type[] { typeof(string) })); |
653 | 653 | ||
654 | //callvirt instance string [mscorlib]System.Exception::get_Message() | 654 | //callvirt instance string [mscorlib]System.Exception::get_Message() |
655 | Common.SendToDebug("CLR:" + eventname + ":il.Emit(OpCodes.Callvirt..."); | 655 | Common.SendToDebug("CLR:" + eventname + ":il.Emit(OpCodes.Callvirt..."); |
656 | il.Emit(OpCodes.Callvirt, typeof(Exception).GetMethod | 656 | il.Emit(OpCodes.Callvirt, typeof(Exception).GetMethod |
657 | ("get_Message")); | 657 | ("get_Message")); |
658 | 658 | ||
659 | //call void [mscorlib]System.Console::WriteLine(string) | 659 | //call void [mscorlib]System.Console::WriteLine(string) |
660 | Common.SendToDebug("CLR:" + eventname + ":il.Emit(OpCodes.Call..."); | 660 | Common.SendToDebug("CLR:" + eventname + ":il.Emit(OpCodes.Call..."); |
661 | il.Emit(OpCodes.Call, typeof(Console).GetMethod | 661 | il.Emit(OpCodes.Call, typeof(Console).GetMethod |
662 | ("WriteLine", new Type[] { typeof(string) })); | 662 | ("WriteLine", new Type[] { typeof(string) })); |
663 | 663 | ||
664 | /* | 664 | /* |
665 | * CLR END TRY | 665 | * CLR END TRY |
666 | */ | 666 | */ |
667 | //Common.SendToDebug("CLR:" + eventname + ":il.EndExceptionBlock();"); | 667 | //Common.SendToDebug("CLR:" + eventname + ":il.EndExceptionBlock();"); |
668 | il.EndExceptionBlock(); | 668 | il.EndExceptionBlock(); |
669 | } | 669 | } |
670 | 670 | ||
671 | private LSO_Struct.StaticBlock GetStaticBlock(long pos) | 671 | private LSO_Struct.StaticBlock GetStaticBlock(long pos) |
672 | { | 672 | { |
673 | long FirstPos = fs.Position; | 673 | long FirstPos = fs.Position; |
674 | try | 674 | try |
675 | { | 675 | { |
676 | UInt32 position = (UInt32)pos; | 676 | UInt32 position = (UInt32)pos; |
677 | // STATIC BLOCK | 677 | // STATIC BLOCK |
678 | Common.SendToDebug("Reading STATIC BLOCK at: " + position); | 678 | Common.SendToDebug("Reading STATIC BLOCK at: " + position); |
679 | fs.Seek(position, SeekOrigin.Begin); | 679 | fs.Seek(position, SeekOrigin.Begin); |
680 | 680 | ||
681 | if (StaticBlocks.ContainsKey(position) == true) | 681 | if (StaticBlocks.ContainsKey(position) == true) |
682 | { | 682 | { |
683 | Common.SendToDebug("Found cached STATIC BLOCK"); | 683 | Common.SendToDebug("Found cached STATIC BLOCK"); |
684 | 684 | ||
685 | 685 | ||
686 | 686 | ||
687 | return StaticBlocks[pos]; | 687 | return StaticBlocks[pos]; |
688 | } | 688 | } |
689 | 689 | ||
690 | //int StaticBlockCount = 0; | 690 | //int StaticBlockCount = 0; |
691 | // Read function blocks until we hit GFR | 691 | // Read function blocks until we hit GFR |
692 | //while (fs.Position < myHeader.GFR) | 692 | //while (fs.Position < myHeader.GFR) |
693 | //{ | 693 | //{ |
694 | //StaticBlockCount++; | 694 | //StaticBlockCount++; |
695 | 695 | ||
696 | //Common.SendToDebug("Reading Static Block at: " + position); | 696 | //Common.SendToDebug("Reading Static Block at: " + position); |
697 | 697 | ||
698 | //fs.Seek(myHeader.GVR, SeekOrigin.Begin); | 698 | //fs.Seek(myHeader.GVR, SeekOrigin.Begin); |
699 | LSO_Struct.StaticBlock myStaticBlock = new LSO_Struct.StaticBlock(); | 699 | LSO_Struct.StaticBlock myStaticBlock = new LSO_Struct.StaticBlock(); |
700 | myStaticBlock.Static_Chunk_Header_Size = BitConverter.ToUInt32(br_read(4), 0); | 700 | myStaticBlock.Static_Chunk_Header_Size = BitConverter.ToUInt32(br_read(4), 0); |
701 | myStaticBlock.ObjectType = br_read(1)[0]; | 701 | myStaticBlock.ObjectType = br_read(1)[0]; |
702 | Common.SendToDebug("Static Block ObjectType: " + ((LSO_Enums.Variable_Type_Codes)myStaticBlock.ObjectType).ToString()); | 702 | Common.SendToDebug("Static Block ObjectType: " + ((LSO_Enums.Variable_Type_Codes)myStaticBlock.ObjectType).ToString()); |
703 | myStaticBlock.Unknown = br_read(1)[0]; | 703 | myStaticBlock.Unknown = br_read(1)[0]; |
704 | // Size of datatype varies | 704 | // Size of datatype varies |
705 | if (myStaticBlock.ObjectType != 0) | 705 | if (myStaticBlock.ObjectType != 0) |
706 | myStaticBlock.BlockVariable = br_read(getObjectSize(myStaticBlock.ObjectType)); | 706 | myStaticBlock.BlockVariable = br_read(getObjectSize(myStaticBlock.ObjectType)); |
707 | 707 | ||
708 | StaticBlocks.Add(position, myStaticBlock); | 708 | StaticBlocks.Add(position, myStaticBlock); |
709 | //} | 709 | //} |
710 | Common.SendToDebug("Done reading Static Block."); | 710 | Common.SendToDebug("Done reading Static Block."); |
711 | return myStaticBlock; | 711 | return myStaticBlock; |
712 | } | 712 | } |
713 | finally | 713 | finally |
714 | { | 714 | { |
715 | // Go back to original read pos | 715 | // Go back to original read pos |
716 | fs.Seek(FirstPos, SeekOrigin.Begin); | 716 | fs.Seek(FirstPos, SeekOrigin.Begin); |
717 | } | 717 | } |
718 | 718 | ||
719 | } | 719 | } |
720 | 720 | ||
721 | } | 721 | } |
722 | } | 722 | } |