@@ -191,31 +191,32 @@ public object CreateHandler(MethodInfo method, object instance)
191
191
private sealed class TmodFile : ITmodFile
192
192
{
193
193
private readonly TmodFileImplementation _impl ;
194
- private readonly object _modFile ;
194
+
195
+ public object Instance { get ; }
195
196
196
197
public TmodFile ( string path , TmodFileImplementation impl )
197
198
{
198
199
_impl = impl ;
199
- _modFile = impl . CreateTmodFile ( path ) ;
200
+ Instance = impl . CreateTmodFile ( path ) ;
200
201
}
201
202
202
203
public string Name
203
204
{
204
- get => _impl . InvokeMethod < string > ( _modFile , TmodFileImplementation . GetName ) ;
205
- set => _impl . InvokeMethod < object > ( _modFile , TmodFileImplementation . SetName , value ) ;
205
+ get => _impl . InvokeMethod < string > ( Instance , TmodFileImplementation . GetName ) ;
206
+ set => _impl . InvokeMethod < object > ( Instance , TmodFileImplementation . SetName , value ) ;
206
207
}
207
208
208
- public string Path => _impl . GetFieldValue < string > ( _modFile , TmodFileImplementation . Path ) ;
209
+ public string Path => _impl . GetFieldValue < string > ( Instance , TmodFileImplementation . Path ) ;
209
210
210
211
public Version Version
211
212
{
212
- get => _impl . InvokeMethod < Version > ( _modFile , TmodFileImplementation . GetVersion ) ;
213
- set => _impl . InvokeMethod < object > ( _modFile , TmodFileImplementation . SetVersion , value ) ;
213
+ get => _impl . InvokeMethod < Version > ( Instance , TmodFileImplementation . GetVersion ) ;
214
+ set => _impl . InvokeMethod < object > ( Instance , TmodFileImplementation . SetVersion , value ) ;
214
215
}
215
216
216
217
public void AddFile ( string fileName , byte [ ] data )
217
218
{
218
- _impl . InvokeMethod < object > ( _modFile , TmodFileImplementation . AddFile , fileName , data ) ;
219
+ _impl . InvokeMethod < object > ( Instance , TmodFileImplementation . AddFile , fileName , data ) ;
219
220
}
220
221
221
222
public byte [ ] GetMainAssembly ( bool ? windows = null )
@@ -238,13 +239,13 @@ public byte[] GetMainPdb(bool? windows = null)
238
239
}
239
240
240
241
public IDictionary < string , byte [ ] > Files =>
241
- _impl . GetFieldValue < IDictionary < string , byte [ ] > > ( _modFile , TmodFileImplementation . Files ) ;
242
+ _impl . GetFieldValue < IDictionary < string , byte [ ] > > ( Instance , TmodFileImplementation . Files ) ;
242
243
243
244
public bool HasFile ( string fileName ) =>
244
- _impl . InvokeMethod < bool > ( _modFile , TmodFileImplementation . HasFile , fileName ) ;
245
+ _impl . InvokeMethod < bool > ( Instance , TmodFileImplementation . HasFile , fileName ) ;
245
246
246
247
public byte [ ] GetFile ( string fileName ) =>
247
- _impl . InvokeMethod < byte [ ] > ( _modFile , TmodFileImplementation . GetFile , fileName ) ;
248
+ _impl . InvokeMethod < byte [ ] > ( Instance , TmodFileImplementation . GetFile , fileName ) ;
248
249
249
250
public void Read ( )
250
251
{
@@ -254,9 +255,9 @@ public void Read()
254
255
255
256
// invoke TmodFile.Read() with state and handler
256
257
// state will be random number greater than 4 (see TmodFile.cs#L19)
257
- _impl . InvokeMethod < object > ( _modFile , TmodFileImplementation . Read , int . MaxValue , handler ) ;
258
+ _impl . InvokeMethod < object > ( Instance , TmodFileImplementation . Read , int . MaxValue , handler ) ;
258
259
259
- var ex = _impl . GetFieldValue < Exception > ( _modFile , TmodFileImplementation . ReadException ) ;
260
+ var ex = _impl . GetFieldValue < Exception > ( Instance , TmodFileImplementation . ReadException ) ;
260
261
if ( ex != null )
261
262
{
262
263
throw ex ;
@@ -265,12 +266,12 @@ public void Read()
265
266
266
267
public void RemoveFile ( string fileName )
267
268
{
268
- _impl . InvokeMethod < object > ( _modFile , TmodFileImplementation . RemoveFile , fileName ) ;
269
+ _impl . InvokeMethod < object > ( Instance , TmodFileImplementation . RemoveFile , fileName ) ;
269
270
}
270
271
271
272
public void Save ( )
272
273
{
273
- _impl . InvokeMethod < object > ( _modFile , TmodFileImplementation . Save ) ;
274
+ _impl . InvokeMethod < object > ( Instance , TmodFileImplementation . Save ) ;
274
275
}
275
276
276
277
public void Write ( string path )
@@ -279,11 +280,11 @@ public void Write(string path)
279
280
var originPath = Path ;
280
281
281
282
// invoke save method
282
- _impl . SetFieldValue ( _modFile , TmodFileImplementation . Path , path ) ;
283
+ _impl . SetFieldValue ( Instance , TmodFileImplementation . Path , path ) ;
283
284
Save ( ) ;
284
285
285
286
// recover its original value
286
- _impl . SetFieldValue ( _modFile , TmodFileImplementation . Path , originPath ) ;
287
+ _impl . SetFieldValue ( Instance , TmodFileImplementation . Path , originPath ) ;
287
288
}
288
289
289
290
// ReSharper disable MemberCanBePrivate.Local
@@ -324,6 +325,8 @@ public interface ITmodFile
324
325
byte [ ] GetMainAssembly ( bool ? windows = null ) ;
325
326
326
327
byte [ ] GetMainPdb ( bool ? windows = null ) ;
328
+
329
+ object Instance { get ; }
327
330
}
328
331
}
329
332
}
0 commit comments