@@ -32,7 +32,7 @@ public ScriptFile Read(ScriptContainer container)
32
32
IList < ScriptFunction > functions = ReadFunctions ( container . FunctionTable , container . StringTable , length ! . Value ) ;
33
33
IList < ScriptJump > jumps = ReadJumps ( container . JumpTable , container . StringTable , length ! . Value ) ;
34
34
IList < ScriptInstruction > instructions = ReadInstructions ( container . InstructionTable , length ! . Value ) ;
35
- IList < ScriptArgument > arguments = ReadArguments ( container . ArgumentTable , container . StringTable , length ! . Value ) ;
35
+ IList < ScriptArgument > arguments = ReadArguments ( container . ArgumentTable , instructions . AsReadOnly ( ) , container . StringTable , length ! . Value ) ;
36
36
37
37
return new ScriptFile
38
38
{
@@ -69,12 +69,12 @@ public IList<ScriptInstruction> ReadInstructions(ScriptTable instructionTable)
69
69
return ReadInstructions ( instructionTable , length ! . Value ) ;
70
70
}
71
71
72
- public IList < ScriptArgument > ReadArguments ( ScriptTable argumentTable , ScriptStringTable ? stringTable )
72
+ public IList < ScriptArgument > ReadArguments ( ScriptTable argumentTable , ScriptTable instructionTable , ScriptStringTable ? stringTable )
73
73
{
74
74
if ( ! TryDetectTablePointerLength ( argumentTable , _entrySizeProvider . GetArgumentEntrySize , out PointerLength ? length ) )
75
75
throw new InvalidOperationException ( "Could not detect pointer length." ) ;
76
76
77
- return ReadArguments ( argumentTable , stringTable , length ! . Value ) ;
77
+ return ReadArguments ( argumentTable , instructionTable , stringTable , length ! . Value ) ;
78
78
}
79
79
80
80
public abstract IReadOnlyList < TFunction > ReadFunctions ( Stream functionStream , int entryCount , PointerLength length ) ;
@@ -119,60 +119,69 @@ public IList<ScriptInstruction> CreateInstructions(IReadOnlyList<TInstruction> i
119
119
return result ;
120
120
}
121
121
122
- public IList < ScriptArgument > CreateArguments ( IReadOnlyList < TArgument > arguments , ScriptStringTable ? stringTable = null )
122
+ public IList < ScriptArgument > CreateArguments ( IReadOnlyList < TArgument > arguments , IReadOnlyList < ScriptInstruction > instructions , ScriptStringTable ? stringTable = null )
123
123
{
124
124
using IBinaryReaderX ? stringReader = stringTable == null ? null : _binaryFactory . CreateReader ( stringTable . Stream , true ) ;
125
125
126
126
var result = new ScriptArgument [ arguments . Count ] ;
127
127
128
+ var instructionTypes = new ( int , int ) [ arguments . Count ] ;
129
+ foreach ( ScriptInstruction instruction in instructions )
130
+ {
131
+ for ( var i = 0 ; i < instruction . ArgumentCount ; i ++ )
132
+ instructionTypes [ instruction . ArgumentIndex + i ] = ( instruction . Type , i ) ;
133
+ }
134
+
128
135
var counter = 0 ;
129
136
foreach ( TArgument argument in arguments )
130
- result [ counter ++ ] = CreateArgument ( argument , stringReader ) ;
137
+ {
138
+ ( int instructionType , int argumentIndex ) = instructionTypes [ counter ] ;
139
+ result [ counter ++ ] = CreateArgument ( argument , instructionType , argumentIndex , stringReader ) ;
140
+ }
131
141
132
142
return result ;
133
143
}
134
144
135
145
protected abstract ScriptFunction CreateFunction ( TFunction function , IBinaryReaderX ? stringReader ) ;
136
146
protected abstract ScriptJump CreateJump ( TJump jump , IBinaryReaderX ? stringReader ) ;
137
147
protected abstract ScriptInstruction CreateInstruction ( TInstruction instruction ) ;
138
- protected abstract ScriptArgument CreateArgument ( TArgument argument , IBinaryReaderX ? stringReader ) ;
148
+ protected abstract ScriptArgument CreateArgument ( TArgument argument , int instructionType , int argumentIndex , IBinaryReaderX ? stringReader ) ;
139
149
140
150
protected abstract IEnumerable < TFunction > OrderFunctions ( IReadOnlyList < TFunction > functions ) ;
141
151
142
152
private IList < ScriptFunction > ReadFunctions ( ScriptTable functionTable , ScriptStringTable ? stringTable , PointerLength length )
143
153
{
144
- using IBinaryReaderX br = _binaryFactory . CreateReader ( functionTable . Stream , true ) ;
145
-
146
154
IReadOnlyList < TFunction > functions = ReadFunctions ( functionTable . Stream , functionTable . EntryCount , length ) ;
147
155
148
156
return CreateFunctions ( functions , stringTable ) ;
149
157
}
150
158
151
159
private IList < ScriptJump > ReadJumps ( ScriptTable jumpTable , ScriptStringTable ? stringTable , PointerLength length )
152
160
{
153
- using IBinaryReaderX br = _binaryFactory . CreateReader ( jumpTable . Stream , true ) ;
154
-
155
161
IReadOnlyList < TJump > jumps = ReadJumps ( jumpTable . Stream , jumpTable . EntryCount , length ) ;
156
162
157
163
return CreateJumps ( jumps , stringTable ) ;
158
164
}
159
165
160
166
private IList < ScriptInstruction > ReadInstructions ( ScriptTable instructionTable , PointerLength length )
161
167
{
162
- using IBinaryReaderX br = _binaryFactory . CreateReader ( instructionTable . Stream , true ) ;
163
-
164
168
IReadOnlyList < TInstruction > instructions = ReadInstructions ( instructionTable . Stream , instructionTable . EntryCount , length ) ;
165
169
166
170
return CreateInstructions ( instructions ) ;
167
171
}
168
172
169
- private IList < ScriptArgument > ReadArguments ( ScriptTable argumentTable , ScriptStringTable ? stringTable , PointerLength length )
173
+ private IList < ScriptArgument > ReadArguments ( ScriptTable argumentTable , ScriptTable instructionTable , ScriptStringTable ? stringTable , PointerLength length )
170
174
{
171
- using IBinaryReaderX br = _binaryFactory . CreateReader ( argumentTable . Stream , true ) ;
175
+ IList < ScriptInstruction > instructions = ReadInstructions ( instructionTable , length ) ;
172
176
177
+ return ReadArguments ( argumentTable , instructions . AsReadOnly ( ) , stringTable , length ) ;
178
+ }
179
+
180
+ private IList < ScriptArgument > ReadArguments ( ScriptTable argumentTable , IReadOnlyList < ScriptInstruction > instructions , ScriptStringTable ? stringTable , PointerLength length )
181
+ {
173
182
IReadOnlyList < TArgument > arguments = ReadArguments ( argumentTable . Stream , argumentTable . EntryCount , length ) ;
174
183
175
- return CreateArguments ( arguments , stringTable ) ;
184
+ return CreateArguments ( arguments , instructions , stringTable ) ;
176
185
}
177
186
178
187
private bool TryDetectPointerLength ( ScriptContainer container , out PointerLength ? length )
0 commit comments