2021-03-31 16:42:58 -05:00
// Decompiled with JetBrains decompiler
// Type: Microsoft.Iris.Markup.CompiledMarkupLoader
// Assembly: UIX, Version=4.8.0.0, Culture=neutral, PublicKeyToken=ddd0da4d3e678217
// MVID: A56C6C9D-B7F6-46A9-8BDE-B3D9B8D60B11
// Assembly location: C:\Program Files\Zune\UIX.dll
using Microsoft.Iris.Data ;
using Microsoft.Iris.Markup.UIX ;
using Microsoft.Iris.OS ;
using Microsoft.Iris.Session ;
using System ;
namespace Microsoft.Iris.Markup
{
internal class CompiledMarkupLoader
{
private const uint c_LineNumberRecordSize = 12 ;
private CompiledMarkupLoadResult _loadResultTarget ;
private ByteCodeReader _reader ;
private bool _hasErrors ;
private LoadPass _currentDepersistPass ;
private MarkupLoadResult _binaryDataTableLoadResult ;
private MarkupBinaryDataTable _binaryDataTable ;
private bool _usingSharedDataTable ;
private uint _objectSectionStart ;
private uint _objectSectionEnd ;
private uint _lineNumberTableStart ;
private uint _lineNumberTableEnd ;
private TypeSchema [][] _typeSchemaArrays ;
2021-04-02 19:10:51 -05:00
public static CompiledMarkupLoader Load ( CompiledMarkupLoadResult loadResult , Resource resource )
2021-03-31 16:42:58 -05:00
{
return new CompiledMarkupLoader ( loadResult , resource );
}
private CompiledMarkupLoader ( CompiledMarkupLoadResult loadResultTarget , Resource resource )
{
2021-04-02 19:10:51 -05:00
_loadResultTarget = loadResultTarget ;
_reader = new ByteCodeReader ( resource . Buffer , resource . Length , false );
2021-03-31 16:42:58 -05:00
if ( resource is DllResource )
2021-04-02 19:10:51 -05:00
_reader . MarkAsInFixedMemory ();
uint num1 = _reader . ReadUInt32 ();
uint num2 = _reader . ReadUInt32 ();
2021-03-31 16:42:58 -05:00
if ( num1 != 440551765 U )
2021-04-02 19:10:51 -05:00
ReportError ( "Invalid compiled UIX file" );
2021-03-31 16:42:58 -05:00
if ( num2 == 1012 U )
return ;
2021-04-02 19:10:51 -05:00
ReportError ( "Compiled UIX file '{0}' was compiled for the runtime with version {1}, but the current runtime is version {2}" , resource . Uri , num2 . ToString (), 1012 U . ToString ());
2021-03-31 16:42:58 -05:00
}
public void Depersist ( LoadPass currentPass )
{
2021-04-02 19:10:51 -05:00
if ( _currentDepersistPass >= currentPass )
2021-03-31 16:42:58 -05:00
return ;
2021-04-02 19:10:51 -05:00
_currentDepersistPass = currentPass ;
if ( _binaryDataTableLoadResult != null )
_binaryDataTableLoadResult . Load ( _currentDepersistPass );
if ( _currentDepersistPass == LoadPass . DeclareTypes )
DoLoadPassDeclareTypes ();
else if ( _currentDepersistPass == LoadPass . PopulatePublicModel )
DoLoadPassPopulatePublicModel ();
else if ( _currentDepersistPass == LoadPass . Full )
2021-03-31 16:42:58 -05:00
{
2021-04-02 19:10:51 -05:00
DoLoadPassFull ();
2021-03-31 16:42:58 -05:00
}
else
{
2021-04-02 19:10:51 -05:00
foreach ( MarkupTypeSchema markupTypeSchema in _loadResultTarget . ExportTable )
2021-03-31 16:42:58 -05:00
markupTypeSchema . Seal ();
2021-04-02 19:10:51 -05:00
_reader = null ;
2021-03-31 16:42:58 -05:00
}
2021-04-02 19:10:51 -05:00
foreach ( LoadResult dependency in _loadResultTarget . Dependencies )
2021-03-31 16:42:58 -05:00
{
2021-04-02 19:10:51 -05:00
if ( dependency != _loadResultTarget )
2021-03-31 16:42:58 -05:00
{
2021-04-02 19:10:51 -05:00
dependency . Load ( _currentDepersistPass );
2021-03-31 16:42:58 -05:00
if ( dependency . Status == LoadResultStatus . Error )
2021-04-02 19:10:51 -05:00
MarkHasErrors ();
2021-03-31 16:42:58 -05:00
}
}
}
private void DoLoadPassDeclareTypes ()
{
2021-04-02 19:10:51 -05:00
if ( HasErrors )
2021-03-31 16:42:58 -05:00
return ;
2021-04-02 19:10:51 -05:00
DepersistTableOfContents ();
if ( HasErrors )
2021-03-31 16:42:58 -05:00
return ;
2021-04-02 19:10:51 -05:00
DepersistDependencies ();
if ( HasErrors )
2021-03-31 16:42:58 -05:00
return ;
2021-04-02 19:10:51 -05:00
DepersistTypeExportDeclarations ();
if (! HasErrors )
2021-03-31 16:42:58 -05:00
;
}
private void DoLoadPassPopulatePublicModel ()
{
2021-04-02 19:10:51 -05:00
if ( HasErrors )
2021-03-31 16:42:58 -05:00
return ;
2021-04-02 19:10:51 -05:00
DepersistTypeImportTable ();
if ( HasErrors )
2021-03-31 16:42:58 -05:00
return ;
2021-04-02 19:10:51 -05:00
DepersistTypeExportDefinitions ();
if (! HasErrors )
2021-03-31 16:42:58 -05:00
;
}
private void DoLoadPassFull ()
{
2021-04-02 19:10:51 -05:00
if ( HasErrors )
2021-03-31 16:42:58 -05:00
return ;
2021-04-02 19:10:51 -05:00
DepersistMemberImportTables ();
if ( HasErrors )
2021-03-31 16:42:58 -05:00
return ;
2021-04-02 19:10:51 -05:00
DepersistDataMappingsTable ();
if ( HasErrors )
2021-03-31 16:42:58 -05:00
return ;
2021-04-02 19:10:51 -05:00
DepersistConstantsTable ();
if ( HasErrors )
2021-03-31 16:42:58 -05:00
return ;
2021-04-02 19:10:51 -05:00
DepersistLineNumberTable ();
if ( HasErrors )
2021-03-31 16:42:58 -05:00
return ;
2021-04-02 19:10:51 -05:00
DepersistObjectSection ();
if (! HasErrors )
2021-03-31 16:42:58 -05:00
;
}
private void DepersistTableOfContents ()
{
2021-04-02 19:10:51 -05:00
_objectSectionStart = _reader . ReadUInt32 ();
_objectSectionEnd = _reader . ReadUInt32 ();
_lineNumberTableStart = _reader . ReadUInt32 ();
_lineNumberTableEnd = _reader . ReadUInt32 ();
string uri = _reader . ReadString ();
2021-03-31 16:42:58 -05:00
if ( uri != null )
{
2021-04-02 19:10:51 -05:00
_binaryDataTableLoadResult = MarkupSystem . ResolveLoadResult ( uri , _loadResultTarget . IslandReferences ) as MarkupLoadResult ;
if ( _binaryDataTableLoadResult != null )
2021-03-31 16:42:58 -05:00
{
2021-04-02 19:10:51 -05:00
_binaryDataTableLoadResult . Load ( _currentDepersistPass );
_binaryDataTable = _binaryDataTableLoadResult . BinaryDataTable ;
_loadResultTarget . SetBinaryDataTable ( _binaryDataTable );
if ( _binaryDataTable . SharedDependenciesTableWithBinaryDataTable == null )
_binaryDataTable . SharedDependenciesTableWithBinaryDataTable = new LoadResult [ 1 ]
2021-03-31 16:42:58 -05:00
{
2021-03-31 17:15:06 -05:00
_binaryDataTableLoadResult
2021-03-31 16:42:58 -05:00
};
2021-04-02 19:10:51 -05:00
_loadResultTarget . SetDependenciesTable ( _binaryDataTable . SharedDependenciesTableWithBinaryDataTable );
_usingSharedDataTable = true ;
2021-03-31 16:42:58 -05:00
}
else
2021-04-02 19:10:51 -05:00
MarkHasErrors ();
2021-03-31 16:42:58 -05:00
}
else
2021-04-02 19:10:51 -05:00
DepersistBinaryDataTable ( _reader . ReadUInt32 ());
2021-03-31 16:42:58 -05:00
}
private void DepersistDependencies ()
{
2021-04-02 19:10:51 -05:00
if ( _usingSharedDataTable )
2021-03-31 16:42:58 -05:00
return ;
2021-04-02 19:10:51 -05:00
ushort num = _reader . ReadUInt16 ();
2021-03-31 17:15:06 -05:00
LoadResult [] dependenciesTable = new LoadResult [ num ];
for ( ushort index = 0 ; index < num ; ++ index )
2021-03-31 16:42:58 -05:00
{
2021-04-02 19:10:51 -05:00
_reader . ReadBool ();
string uri = ReadDataTableString ();
LoadResult loadResult = MarkupSystem . ResolveLoadResult ( uri , _loadResultTarget . IslandReferences );
2021-03-31 16:42:58 -05:00
if ( loadResult == null || loadResult . Status == LoadResultStatus . Error )
{
2021-04-02 19:10:51 -05:00
ReportError ( "Import of '{0}' failed" , uri );
2021-03-31 16:42:58 -05:00
return ;
}
2021-03-31 17:15:06 -05:00
dependenciesTable [ index ] = loadResult ;
2021-03-31 16:42:58 -05:00
}
2021-04-02 19:10:51 -05:00
_loadResultTarget . SetDependenciesTable ( dependenciesTable );
2021-03-31 16:42:58 -05:00
}
private void DepersistTypeExportDeclarations ()
{
2021-04-02 19:10:51 -05:00
ushort num1 = _reader . ReadUInt16 ();
2021-03-31 17:15:06 -05:00
TypeSchema [] exportTable = new TypeSchema [ num1 ];
for ( int index = 0 ; index < num1 ; ++ index )
2021-03-31 16:42:58 -05:00
{
2021-04-02 19:10:51 -05:00
string name = ReadDataTableString ();
MarkupTypeSchema markupTypeSchema = MarkupTypeSchema . Build ( MarkupTypeToDefinition (( MarkupType ) _reader . ReadInt32 ()), _loadResultTarget , name );
2021-03-31 17:15:06 -05:00
exportTable [ index ] = markupTypeSchema ;
2021-03-31 16:42:58 -05:00
}
2021-04-02 19:10:51 -05:00
_loadResultTarget . SetExportTable ( exportTable );
ushort num2 = _reader . ReadUInt16 ();
2021-03-31 17:15:06 -05:00
if ( num2 <= 0 )
2021-03-31 16:42:58 -05:00
return ;
2021-03-31 17:15:06 -05:00
AliasMapping [] aliasTable = new AliasMapping [ num2 ];
for ( int index1 = 0 ; index1 < num2 ; ++ index1 )
2021-03-31 16:42:58 -05:00
{
2021-04-02 19:10:51 -05:00
string alias = ReadDataTableString ();
ushort index2 = _reader . ReadUInt16 ();
string targetType = ReadDataTableString ();
LoadResult dependent = MapIndexToDependent ( index2 );
2021-03-31 16:42:58 -05:00
aliasTable [ index1 ] = new AliasMapping ( alias , dependent , targetType );
}
2021-04-02 19:10:51 -05:00
_loadResultTarget . SetAliasTable ( aliasTable );
2021-03-31 16:42:58 -05:00
}
private void DepersistTypeImportTable ()
{
2021-04-02 19:10:51 -05:00
if ( _usingSharedDataTable )
2021-03-31 16:42:58 -05:00
return ;
MarkupImportTables importTables = new MarkupImportTables ();
2021-04-02 19:10:51 -05:00
_loadResultTarget . BinaryDataTable . SetImportTables ( importTables );
ushort num = _reader . ReadUInt16 ();
2021-03-31 17:15:06 -05:00
if ( num <= 0 )
2021-03-31 16:42:58 -05:00
return ;
2021-03-31 17:15:06 -05:00
TypeSchema [] typeSchemaArray = new TypeSchema [ num ];
for ( ushort index = 0 ; index < num ; ++ index )
2021-03-31 16:42:58 -05:00
{
2021-04-02 19:10:51 -05:00
LoadResult dependent = MapIndexToDependent ( _reader . ReadUInt16 ());
string name = ReadDataTableString ();
2021-03-31 16:42:58 -05:00
TypeSchema type = dependent . FindType ( name );
if ( type == null )
2021-04-02 19:10:51 -05:00
ReportError ( "Import of {0} named '{1}' from '{2}' failed" , "type" , name , dependent . Uri );
2021-03-31 16:42:58 -05:00
else
2021-03-31 17:15:06 -05:00
typeSchemaArray [ index ] = type ;
2021-03-31 16:42:58 -05:00
}
importTables . TypeImports = typeSchemaArray ;
}
private void DepersistTypeExportDefinitions ()
{
2021-04-02 19:10:51 -05:00
TypeSchema [] typeImports = _loadResultTarget . ImportTables . TypeImports ;
foreach ( MarkupTypeSchema markupTypeSchema in _loadResultTarget . ExportTable )
2021-03-31 16:42:58 -05:00
{
MarkupType markupType = markupTypeSchema . MarkupType ;
2021-04-02 19:10:51 -05:00
TypeSchema definition = MarkupTypeToDefinition ( markupType );
uint typeDepth = _reader . ReadUInt16 ();
2021-03-31 16:42:58 -05:00
markupTypeSchema . SetTypeDepth ( typeDepth );
if ( typeDepth > 1 U )
{
2021-04-02 19:10:51 -05:00
ushort num = _reader . ReadUInt16 ();
2021-03-31 17:15:06 -05:00
TypeSchema typeSchema = typeImports [ num ];
2021-03-31 16:42:58 -05:00
markupTypeSchema . SetBaseType (( MarkupTypeSchema ) typeSchema );
}
2021-04-02 19:10:51 -05:00
uint offset1 = _reader . ReadUInt32 ();
2021-03-31 16:42:58 -05:00
markupTypeSchema . SetInitializePropertiesOffset ( offset1 );
2021-04-02 19:10:51 -05:00
uint offset2 = _reader . ReadUInt32 ();
2021-03-31 16:42:58 -05:00
markupTypeSchema . SetInitializeLocalsInputOffset ( offset2 );
2021-04-02 19:10:51 -05:00
uint offset3 = _reader . ReadUInt32 ();
2021-03-31 16:42:58 -05:00
markupTypeSchema . SetInitializeContentOffset ( offset3 );
2021-04-02 19:10:51 -05:00
markupTypeSchema . SetInitialEvaluateOffsets ( ReadUInt32ArrayHelper ());
markupTypeSchema . SetFinalEvaluateOffsets ( ReadUInt32ArrayHelper ());
markupTypeSchema . SetRefreshListenerGroupOffsets ( ReadUInt32ArrayHelper ());
uint listenerCount = _reader . ReadUInt32 ();
2021-03-31 16:42:58 -05:00
markupTypeSchema . SetListenerCount ( listenerCount );
2021-04-02 19:10:51 -05:00
uint num1 = _reader . ReadUInt32 ();
2021-03-31 16:42:58 -05:00
if ( num1 > 0 U )
{
SymbolReference [] symbolTable = new SymbolReference [ num1 ];
2021-03-31 17:15:06 -05:00
for ( int index = 0 ; index < num1 ; ++ index )
2021-03-31 16:42:58 -05:00
{
2021-04-02 19:10:51 -05:00
SymbolReference symbolReference = new SymbolReference ( ReadDataTableString (), ( SymbolOrigin ) _reader . ReadByte ());
2021-03-31 16:42:58 -05:00
symbolTable [ index ] = symbolReference ;
}
markupTypeSchema . SetSymbolReferenceTable ( symbolTable );
}
2021-04-02 19:10:51 -05:00
DepersistInheritedSymbolTable ( markupTypeSchema );
int totalPropertiesAndLocalsCount = _reader . ReadInt32 ();
2021-03-31 16:42:58 -05:00
markupTypeSchema . SetTotalPropertiesAndLocalsCount ( totalPropertiesAndLocalsCount );
if ( markupType == MarkupType . UI )
{
2021-04-02 19:10:51 -05:00
ushort num2 = _reader . ReadUInt16 ();
2021-03-31 17:15:06 -05:00
if ( num2 > 0 )
2021-03-31 16:42:58 -05:00
{
2021-03-31 17:15:06 -05:00
NamedContentRecord [] namedContentTable = new NamedContentRecord [ num2 ];
for ( int index = 0 ; index < num2 ; ++ index )
2021-03-31 16:42:58 -05:00
{
2021-04-02 19:10:51 -05:00
string name = ReadDataTableString ();
uint offset4 = _reader . ReadUInt32 ();
2021-03-31 16:42:58 -05:00
namedContentTable [ index ] = new NamedContentRecord ( name );
namedContentTable [ index ]. SetOffset ( offset4 );
}
(( UIClassTypeSchema ) markupTypeSchema ). SetNamedContentTable ( namedContentTable );
}
}
else
{
2021-04-02 19:10:51 -05:00
if ( _reader . ReadBool ())
2021-03-31 16:42:58 -05:00
(( ClassTypeSchema ) markupTypeSchema ). MarkShareable ();
if ( markupType == MarkupType . Effect )
{
EffectClassTypeSchema effectClassTypeSchema = ( EffectClassTypeSchema ) markupTypeSchema ;
2021-04-02 19:10:51 -05:00
effectClassTypeSchema . SetTechniqueOffsets ( ReadUInt32ArrayHelper ());
effectClassTypeSchema . SetInstancePropertyAssignments ( ReadUInt32ArrayHelper ());
effectClassTypeSchema . SetDynamicElementAssignments ( ReadStringArrayHelper ());
int symbolIndex = _reader . ReadInt32 ();
2021-03-31 16:42:58 -05:00
effectClassTypeSchema . SetDefaultElementSymbolIndex ( symbolIndex );
}
if ( markupType == MarkupType . DataQuery )
{
MarkupDataQuerySchema markupDataQuerySchema = ( MarkupDataQuerySchema ) markupTypeSchema ;
2021-04-02 19:10:51 -05:00
markupDataQuerySchema . ProviderName = ReadDataTableString ();
ushort index = _reader . ReadUInt16 ();
markupDataQuerySchema . ResultType = MapIndexToType ( index );
2021-03-31 16:42:58 -05:00
}
}
2021-04-02 19:10:51 -05:00
ushort num3 = _reader . ReadUInt16 ();
2021-03-31 17:15:06 -05:00
if ( num3 > 0 )
2021-03-31 16:42:58 -05:00
{
2021-03-31 17:15:06 -05:00
PropertySchema [] properties = new PropertySchema [ num3 ];
for ( int index1 = 0 ; index1 < num3 ; ++ index1 )
2021-03-31 16:42:58 -05:00
{
2021-04-02 19:10:51 -05:00
string name = ReadDataTableString ();
bool requiredForCreation = _reader . ReadBool ();
bool flag = _reader . ReadBool ();
2021-03-31 17:15:06 -05:00
PropertyOverrideCriteriaTypeConstraint criteriaTypeConstraint = null ;
2021-03-31 16:42:58 -05:00
if ( flag )
{
2021-04-02 19:10:51 -05:00
ushort num2 = _reader . ReadUInt16 ();
ushort num4 = _reader . ReadUInt16 ();
2021-03-31 17:15:06 -05:00
TypeSchema constraint = typeImports [ num2 ];
criteriaTypeConstraint = new PropertyOverrideCriteriaTypeConstraint ( typeImports [ num4 ], constraint );
2021-03-31 16:42:58 -05:00
}
2021-04-02 19:10:51 -05:00
ushort num5 = _reader . ReadUInt16 ();
2021-03-31 17:15:06 -05:00
TypeSchema propertyType = typeImports [ num5 ];
2021-03-31 16:42:58 -05:00
MarkupPropertySchema markupPropertySchema = MarkupPropertySchema . Build ( definition , markupTypeSchema , name , propertyType );
markupPropertySchema . SetRequiredForCreation ( requiredForCreation );
2021-03-31 17:15:06 -05:00
markupPropertySchema . SetOverrideCriteria ( criteriaTypeConstraint );
2021-03-31 16:42:58 -05:00
if ( markupType == MarkupType . DataType )
{
MarkupDataTypePropertySchema typePropertySchema = ( MarkupDataTypePropertySchema ) markupPropertySchema ;
2021-04-02 19:10:51 -05:00
ushort index2 = _reader . ReadUInt16 ();
2021-03-31 16:42:58 -05:00
if ( index2 != ushort . MaxValue )
2021-04-02 19:10:51 -05:00
typePropertySchema . SetUnderlyingCollectionType ( MapIndexToType ( index2 ));
2021-03-31 16:42:58 -05:00
}
if ( markupType == MarkupType . DataQuery )
{
MarkupDataQueryPropertySchema queryPropertySchema = ( MarkupDataQueryPropertySchema ) markupPropertySchema ;
2021-04-02 19:10:51 -05:00
if ( _reader . ReadBool ())
queryPropertySchema . DefaultValue = queryPropertySchema . PropertyType . DecodeBinary ( _reader );
queryPropertySchema . InvalidatesQuery = _reader . ReadBool ();
ushort index2 = _reader . ReadUInt16 ();
2021-03-31 16:42:58 -05:00
if ( index2 != ushort . MaxValue )
2021-04-02 19:10:51 -05:00
queryPropertySchema . SetUnderlyingCollectionType ( MapIndexToType ( index2 ));
2021-03-31 16:42:58 -05:00
}
2021-03-31 17:15:06 -05:00
properties [ index1 ] = markupPropertySchema ;
2021-03-31 16:42:58 -05:00
}
markupTypeSchema . SetPropertyList ( properties );
}
2021-04-02 19:10:51 -05:00
MethodSchema [] methods = ReadMarkupMethodArrayHelper ( definition , markupTypeSchema );
2021-03-31 16:42:58 -05:00
if ( methods != null )
markupTypeSchema . SetMethodList ( methods );
2021-04-02 19:10:51 -05:00
MethodSchema [] virtualMethods = ReadMarkupMethodArrayHelper ( definition , markupTypeSchema );
2021-03-31 16:42:58 -05:00
if ( virtualMethods != null )
markupTypeSchema . SetVirtualMethodList ( virtualMethods );
}
2021-04-02 19:10:51 -05:00
foreach ( MarkupTypeSchema markupTypeSchema in _loadResultTarget . ExportTable )
2021-03-31 16:42:58 -05:00
markupTypeSchema . BuildProperties ();
}
private void DepersistMemberImportTables ()
{
2021-04-02 19:10:51 -05:00
if ( _usingSharedDataTable )
2021-03-31 16:42:58 -05:00
return ;
2021-04-02 19:10:51 -05:00
MarkupImportTables importTables = _loadResultTarget . ImportTables ;
ushort num1 = _reader . ReadUInt16 ();
2021-03-31 17:15:06 -05:00
if ( num1 > 0 )
2021-03-31 16:42:58 -05:00
{
2021-03-31 17:15:06 -05:00
ConstructorSchema [] constructorSchemaArray = new ConstructorSchema [ num1 ];
for ( int index1 = 0 ; index1 < num1 ; ++ index1 )
2021-03-31 16:42:58 -05:00
{
2021-04-02 19:10:51 -05:00
TypeSchema type = MapIndexToType ( _reader . ReadUInt16 ());
ushort num2 = _reader . ReadUInt16 ();
2021-03-31 16:42:58 -05:00
TypeSchema [] parameters = TypeSchema . EmptyList ;
2021-03-31 17:15:06 -05:00
if ( num2 > 0 )
2021-03-31 16:42:58 -05:00
{
2021-04-02 19:10:51 -05:00
parameters = GetTempParameterArray ( num2 );
2021-03-31 17:15:06 -05:00
for ( ushort index2 = 0 ; index2 < num2 ; ++ index2 )
2021-03-31 16:42:58 -05:00
{
2021-04-02 19:10:51 -05:00
ushort index3 = _reader . ReadUInt16 ();
parameters [ index2 ] = MapIndexToType ( index3 );
2021-03-31 16:42:58 -05:00
}
}
ConstructorSchema constructor = type . FindConstructor ( parameters );
if ( constructor == null )
2021-04-02 19:10:51 -05:00
ReportError ( "Import of {0} named '{1}' from '{2}' failed" , "constructor" , type . Name , type . Owner . Uri );
2021-03-31 16:42:58 -05:00
else
constructorSchemaArray [ index1 ] = constructor ;
}
importTables . ConstructorImports = constructorSchemaArray ;
}
2021-04-02 19:10:51 -05:00
ushort num3 = _reader . ReadUInt16 ();
2021-03-31 17:15:06 -05:00
if ( num3 > 0 )
2021-03-31 16:42:58 -05:00
{
2021-03-31 17:15:06 -05:00
PropertySchema [] propertySchemaArray = new PropertySchema [ num3 ];
for ( int index = 0 ; index < num3 ; ++ index )
2021-03-31 16:42:58 -05:00
{
2021-04-02 19:10:51 -05:00
TypeSchema type = MapIndexToType ( _reader . ReadUInt16 ());
string name = ReadDataTableString ();
2021-03-31 16:42:58 -05:00
PropertySchema property = type . FindProperty ( name );
if ( property == null )
2021-04-02 19:10:51 -05:00
ReportError ( "Import of {0} named '{1}' from '{2}' failed" , "property" , name , type . Name );
2021-03-31 16:42:58 -05:00
else
propertySchemaArray [ index ] = property ;
}
importTables . PropertyImports = propertySchemaArray ;
}
2021-04-02 19:10:51 -05:00
ushort num4 = _reader . ReadUInt16 ();
2021-03-31 17:15:06 -05:00
if ( num4 > 0 )
2021-03-31 16:42:58 -05:00
{
2021-03-31 17:15:06 -05:00
MethodSchema [] methodSchemaArray = new MethodSchema [ num4 ];
for ( int index1 = 0 ; index1 < num4 ; ++ index1 )
2021-03-31 16:42:58 -05:00
{
2021-03-31 17:15:06 -05:00
MethodSchema methodSchema = null ;
2021-04-02 19:10:51 -05:00
TypeSchema type = MapIndexToType ( _reader . ReadUInt16 ());
if (! _reader . ReadBool ())
2021-03-31 16:42:58 -05:00
{
2021-04-02 19:10:51 -05:00
string name = ReadDataTableString ();
ushort num2 = _reader . ReadUInt16 ();
2021-03-31 16:42:58 -05:00
TypeSchema [] parameters = TypeSchema . EmptyList ;
2021-03-31 17:15:06 -05:00
if ( num2 > 0 )
2021-03-31 16:42:58 -05:00
{
2021-04-02 19:10:51 -05:00
parameters = GetTempParameterArray ( num2 );
2021-03-31 17:15:06 -05:00
for ( ushort index2 = 0 ; index2 < num2 ; ++ index2 )
2021-03-31 16:42:58 -05:00
{
2021-04-02 19:10:51 -05:00
ushort index3 = _reader . ReadUInt16 ();
parameters [ index2 ] = MapIndexToType ( index3 );
2021-03-31 16:42:58 -05:00
}
}
methodSchema = type . FindMethod ( name , parameters );
if ( methodSchema == null )
2021-04-02 19:10:51 -05:00
ReportError ( "Import of {0} named '{1}' from '{2}' failed" , "method" , name , type . Name );
2021-03-31 16:42:58 -05:00
}
else
{
2021-04-02 19:10:51 -05:00
int num2 = _reader . ReadInt32 ();
2021-03-31 16:42:58 -05:00
if ( type is MarkupTypeSchema markupTypeSchema )
{
foreach ( MarkupMethodSchema virtualMethod in markupTypeSchema . VirtualMethods )
{
if ( virtualMethod . VirtualId == num2 )
{
2021-03-31 17:15:06 -05:00
methodSchema = virtualMethod ;
2021-03-31 16:42:58 -05:00
break ;
}
}
}
if ( methodSchema == null )
2021-04-02 19:10:51 -05:00
ReportError ( "Import of virtual method with index {0} from '{1}' failed" , num2 . ToString (), type . Name );
2021-03-31 16:42:58 -05:00
}
methodSchemaArray [ index1 ] = methodSchema ;
}
importTables . MethodImports = methodSchemaArray ;
}
2021-04-02 19:10:51 -05:00
ushort num5 = _reader . ReadUInt16 ();
2021-03-31 17:15:06 -05:00
if ( num5 <= 0 )
2021-03-31 16:42:58 -05:00
return ;
2021-03-31 17:15:06 -05:00
EventSchema [] eventSchemaArray = new EventSchema [ num5 ];
for ( int index = 0 ; index < num5 ; ++ index )
2021-03-31 16:42:58 -05:00
{
2021-04-02 19:10:51 -05:00
TypeSchema type = MapIndexToType ( _reader . ReadUInt16 ());
string name = ReadDataTableString ();
2021-03-31 16:42:58 -05:00
EventSchema eventSchema = type . FindEvent ( name );
if ( eventSchema == null )
2021-04-02 19:10:51 -05:00
ReportError ( "Import of {0} named '{1}' from '{2}' failed" , "event" , name , type . Name );
2021-03-31 16:42:58 -05:00
else
eventSchemaArray [ index ] = eventSchema ;
}
importTables . EventImports = eventSchemaArray ;
}
private void DepersistDataMappingsTable ()
{
2021-04-02 19:10:51 -05:00
ushort num1 = _reader . ReadUInt16 ();
2021-03-31 17:15:06 -05:00
if ( num1 <= 0 )
2021-03-31 16:42:58 -05:00
return ;
2021-03-31 17:15:06 -05:00
MarkupDataMapping [] dataMappingsTable = new MarkupDataMapping [ num1 ];
for ( int index1 = 0 ; index1 < num1 ; ++ index1 )
2021-03-31 16:42:58 -05:00
{
2021-03-31 17:15:06 -05:00
MarkupDataMapping markupDataMapping = new MarkupDataMapping ( null );
2021-04-02 19:10:51 -05:00
ushort index2 = _reader . ReadUInt16 ();
markupDataMapping . TargetType = ( MarkupDataTypeSchema ) MapIndexToType ( index2 );
markupDataMapping . Provider = ReadDataTableString ();
ushort num2 = _reader . ReadUInt16 ();
2021-03-31 17:15:06 -05:00
markupDataMapping . Mappings = new MarkupDataMappingEntry [ num2 ];
for ( int index3 = 0 ; index3 < num2 ; ++ index3 )
2021-03-31 16:42:58 -05:00
{
MarkupDataMappingEntry dataMappingEntry = new MarkupDataMappingEntry ();
2021-04-02 19:10:51 -05:00
dataMappingEntry . Source = ReadDataTableString ();
dataMappingEntry . Target = ReadDataTableString ();
ushort num3 = _reader . ReadUInt16 ();
dataMappingEntry . Property = ( MarkupDataTypePropertySchema ) _loadResultTarget . ImportTables . PropertyImports [ num3 ];
dataMappingEntry . DefaultValue = ! _reader . ReadBool () ? MarkupDataProvider . GetDefaultValueForType ( dataMappingEntry . Property . PropertyType ) : dataMappingEntry . Property . PropertyType . DecodeBinary ( _reader );
2021-03-31 16:42:58 -05:00
markupDataMapping . Mappings [ index3 ] = dataMappingEntry ;
}
dataMappingsTable [ index1 ] = markupDataMapping ;
}
2021-04-02 19:10:51 -05:00
_loadResultTarget . SetDataMappingsTable ( dataMappingsTable );
2021-03-31 16:42:58 -05:00
}
2021-04-02 19:10:51 -05:00
public static void DecodeInheritableSymbolTable ( MarkupTypeSchema typeExport , ByteCodeReader reader , IntPtr startAddress )
2021-03-31 16:42:58 -05:00
{
if ( reader == null )
{
uint size = ByteCodeReader . ReadUInt32 ( startAddress );
reader = new ByteCodeReader ( new IntPtr ( startAddress . ToInt64 () + 4L ), size , false );
}
else
{
int num1 = ( int ) reader . ReadUInt32 ();
}
MarkupLoadResult owner = typeExport . Owner as MarkupLoadResult ;
MarkupBinaryDataTable binaryDataTable = owner . BinaryDataTable ;
uint num2 = reader . ReadUInt32 ();
SymbolRecord [] symbolTable ;
if ( num2 > 0 U )
{
symbolTable = new SymbolRecord [ num2 ];
2021-03-31 17:15:06 -05:00
for ( int index = 0 ; index < num2 ; ++ index )
2021-03-31 16:42:58 -05:00
{
SymbolRecord symbolRecord = new SymbolRecord ();
2021-03-31 17:20:20 -05:00
symbolRecord . Name = ReadDataTableString ( reader , binaryDataTable );
2021-03-31 16:42:58 -05:00
symbolRecord . SymbolOrigin = ( SymbolOrigin ) reader . ReadByte ();
ushort num3 = reader . ReadUInt16 ();
2021-03-31 17:15:06 -05:00
symbolRecord . Type = owner . ImportTables . TypeImports [ num3 ];
2021-03-31 16:42:58 -05:00
symbolTable [ index ] = symbolRecord ;
}
}
else
symbolTable = SymbolRecord . EmptyList ;
typeExport . SetInheritableSymbolsTable ( symbolTable );
}
private void DepersistInheritedSymbolTable ( MarkupTypeSchema typeExport )
{
2021-04-02 19:10:51 -05:00
if ( _reader . IsInFixedMemory )
2021-03-31 16:42:58 -05:00
{
2021-04-02 19:10:51 -05:00
typeExport . SetAddressOfInheritableSymbolTable ( _reader . CurrentAddress );
uint num = _reader . ReadUInt32 ();
_reader . CurrentOffset += num ;
2021-03-31 16:42:58 -05:00
}
else
2021-04-02 19:10:51 -05:00
DecodeInheritableSymbolTable ( typeExport , _reader , IntPtr . Zero );
2021-03-31 16:42:58 -05:00
}
private void DepersistConstantsTable ()
{
2021-04-02 19:10:51 -05:00
ushort num = _reader . ReadUInt16 ();
2021-03-31 17:15:06 -05:00
if ( num <= 0 )
2021-03-31 16:42:58 -05:00
return ;
2021-03-31 17:15:06 -05:00
object [] runtimeList = new object [ num ];
2021-03-31 16:42:58 -05:00
MarkupConstantsTable constantsTable = new MarkupConstantsTable ( runtimeList );
2021-04-02 19:10:51 -05:00
if (! _reader . IsInFixedMemory )
2021-03-31 16:42:58 -05:00
{
2021-04-02 19:10:51 -05:00
_reader . CurrentOffset += ( uint )(( num + 1 ) * 4 );
2021-03-31 17:15:06 -05:00
for ( int index = 0 ; index < num ; ++ index )
2021-03-31 16:42:58 -05:00
{
2021-04-02 19:10:51 -05:00
object obj = DepersistConstant ( _reader , _loadResultTarget );
2021-03-31 16:42:58 -05:00
runtimeList [ index ] = obj ;
}
}
else
{
2021-04-02 19:10:51 -05:00
ByteCodeReader constantsTableReader = new ByteCodeReader ( _reader . CurrentAddress , ByteCodeReader . ReadUInt32 ( _reader . GetAddress ( _reader . CurrentOffset + num * 4 U )), false );
2021-03-31 17:15:06 -05:00
constantsTable . SetConstantsTableReader ( constantsTableReader , _loadResultTarget );
2021-03-31 16:42:58 -05:00
}
2021-04-02 19:10:51 -05:00
_loadResultTarget . BinaryDataTable . SetConstantsTable ( constantsTable );
2021-03-31 16:42:58 -05:00
}
public static object DepersistConstant ( ByteCodeReader reader , MarkupLoadResult loadResult )
{
ushort num = reader . ReadUInt16 ();
2021-03-31 17:15:06 -05:00
TypeSchema typeImport = loadResult . ImportTables . TypeImports [ num ];
2021-03-31 16:42:58 -05:00
MarkupConstantPersistMode constantPersistMode = ( MarkupConstantPersistMode ) reader . ReadByte ();
2021-03-31 17:15:06 -05:00
object instance = null ;
2021-03-31 16:42:58 -05:00
switch ( constantPersistMode )
{
case MarkupConstantPersistMode . Binary :
instance = typeImport . DecodeBinary ( reader );
break ;
case MarkupConstantPersistMode . FromString :
2021-03-31 17:20:20 -05:00
string str = ReadDataTableString ( reader , loadResult . BinaryDataTable );
2021-03-31 17:15:06 -05:00
typeImport . TypeConverter ( str , StringSchema . Type , out instance );
2021-03-31 16:42:58 -05:00
break ;
case MarkupConstantPersistMode . Canonical :
2021-03-31 17:20:20 -05:00
string name = ReadDataTableString ( reader , loadResult . BinaryDataTable );
2021-03-31 16:42:58 -05:00
instance = typeImport . FindCanonicalInstance ( name );
break ;
}
return instance ;
}
2021-04-02 19:10:51 -05:00
private static MarkupLineNumberTable DecodeLineNumberTable ( ByteCodeReader reader )
2021-03-31 16:42:58 -05:00
{
ushort num = reader . ReadUInt16 ();
2021-03-31 17:15:06 -05:00
ulong [] runtimeList = new ulong [ num ];
for ( int index = 0 ; index < num ; ++ index )
2021-03-31 16:42:58 -05:00
runtimeList [ index ] = reader . ReadUInt64 ();
return new MarkupLineNumberTable ( runtimeList );
}
public static MarkupLineNumberTable DecodeLineNumberTable ( IntPtr address )
{
2021-03-31 17:15:06 -05:00
uint size = ( uint )( ByteCodeReader . ReadUInt16 ( address ) * 12 + 2 );
2021-03-31 17:20:20 -05:00
return DecodeLineNumberTable ( new ByteCodeReader ( address , size , false ));
2021-03-31 16:42:58 -05:00
}
private void DepersistLineNumberTable ()
{
2021-04-02 19:10:51 -05:00
if ( _reader . IsInFixedMemory )
2021-03-31 16:42:58 -05:00
{
2021-04-02 19:10:51 -05:00
_loadResultTarget . SetAddressOfLineNumberData ( _reader . GetAddress ( _lineNumberTableStart ));
2021-03-31 16:42:58 -05:00
}
else
{
2021-04-02 19:10:51 -05:00
uint currentOffset = _reader . CurrentOffset ;
_reader . CurrentOffset = _lineNumberTableStart ;
_loadResultTarget . SetLineNumberTable ( DecodeLineNumberTable ( _reader ));
_reader . CurrentOffset = currentOffset ;
2021-03-31 16:42:58 -05:00
}
}
private void DepersistObjectSection ()
{
2021-04-02 19:10:51 -05:00
uint num = _objectSectionEnd - _objectSectionStart ;
2021-03-31 16:42:58 -05:00
ByteCodeReader reader ;
2021-04-02 19:10:51 -05:00
if ( _reader . IsInFixedMemory )
2021-03-31 16:42:58 -05:00
{
2021-04-02 19:10:51 -05:00
reader = new ByteCodeReader ( _reader . GetAddress ( _objectSectionStart ), num , false );
2021-03-31 16:42:58 -05:00
}
else
{
ByteCodeWriter byteCodeWriter = new ByteCodeWriter ();
2021-04-02 19:10:51 -05:00
byteCodeWriter . Write ( _reader . GetAddress ( _objectSectionStart ), num );
2021-03-31 16:42:58 -05:00
reader = byteCodeWriter . CreateReader ();
}
2021-04-02 19:10:51 -05:00
_loadResultTarget . SetObjectSection ( reader );
2021-03-31 16:42:58 -05:00
}
private void DepersistBinaryDataTable ( uint binaryDataTableOffset )
{
2021-04-02 19:10:51 -05:00
uint currentOffset = _reader . CurrentOffset ;
_reader . CurrentOffset = binaryDataTableOffset ;
int stringCount = _reader . ReadInt32 ();
_binaryDataTable = new MarkupBinaryDataTable ( null , stringCount );
if (! _reader . IsInFixedMemory )
2021-03-31 16:42:58 -05:00
{
2021-04-02 19:10:51 -05:00
_reader . CurrentOffset += ( uint )(( stringCount + 1 ) * 4 );
Vector < string > strings = _binaryDataTable . Strings ;
2021-03-31 16:42:58 -05:00
for ( int index = 0 ; index < stringCount ; ++ index )
{
2021-04-02 19:10:51 -05:00
string str = _reader . ReadString ();
2021-03-31 16:42:58 -05:00
strings [ index ] = str ;
}
}
else
2021-04-02 19:10:51 -05:00
_binaryDataTable . SetStringTableReader ( new ByteCodeReader ( _reader . CurrentAddress , ByteCodeReader . ReadUInt32 ( _reader . GetAddress ( _reader . CurrentOffset + ( uint )( stringCount * 4 ))), false ));
_loadResultTarget . SetBinaryDataTable ( _binaryDataTable );
_reader . CurrentOffset = currentOffset ;
2021-03-31 16:42:58 -05:00
}
private LoadResult MapIndexToDependent ( ushort index )
{
LoadResult loadResult ;
switch ( index )
{
case 65533 :
2021-03-31 17:15:06 -05:00
loadResult = _loadResultTarget ;
2021-03-31 16:42:58 -05:00
break ;
case 65534 :
2021-03-31 17:15:06 -05:00
loadResult = MarkupSystem . UIXGlobal ;
2021-03-31 16:42:58 -05:00
break ;
default :
2021-04-02 19:10:51 -05:00
loadResult = _binaryDataTableLoadResult == null ? _loadResultTarget . Dependencies [ index ] : _binaryDataTableLoadResult . Dependencies [ index ];
2021-03-31 16:42:58 -05:00
break ;
}
return loadResult ;
}
2021-04-02 19:10:51 -05:00
private TypeSchema MapIndexToType ( ushort index ) => _loadResultTarget . ImportTables . TypeImports [ index ];
2021-03-31 16:42:58 -05:00
2021-04-02 19:10:51 -05:00
private string ReadDataTableString () => _binaryDataTable . GetStringByIndex ( _reader . ReadInt32 ());
2021-03-31 16:42:58 -05:00
2021-04-02 19:10:51 -05:00
private static string ReadDataTableString ( ByteCodeReader reader , MarkupBinaryDataTable binaryDataTable )
2021-03-31 16:42:58 -05:00
{
int index = reader . ReadInt32 ();
return binaryDataTable . GetStringByIndex ( index );
}
private uint [] ReadUInt32ArrayHelper ()
{
2021-04-02 19:10:51 -05:00
uint num = _reader . ReadUInt32 ();
2021-03-31 16:42:58 -05:00
if ( num <= 0 U )
2021-03-31 17:15:06 -05:00
return null ;
2021-03-31 16:42:58 -05:00
uint [] numArray = new uint [ num ];
2021-03-31 17:15:06 -05:00
for ( int index = 0 ; index < num ; ++ index )
2021-04-02 19:10:51 -05:00
numArray [ index ] = _reader . ReadUInt32 ();
2021-03-31 16:42:58 -05:00
return numArray ;
}
private string [] ReadStringArrayHelper ()
{
2021-04-02 19:10:51 -05:00
uint num = _reader . ReadUInt32 ();
2021-03-31 16:42:58 -05:00
if ( num <= 0 U )
2021-03-31 17:15:06 -05:00
return null ;
2021-03-31 16:42:58 -05:00
string [] strArray = new string [ num ];
2021-03-31 17:15:06 -05:00
for ( int index = 0 ; index < num ; ++ index )
2021-04-02 19:10:51 -05:00
strArray [ index ] = ReadDataTableString ();
2021-03-31 16:42:58 -05:00
return strArray ;
}
2021-04-02 19:10:51 -05:00
private MethodSchema [] ReadMarkupMethodArrayHelper ( TypeSchema markupTypeDefinition , MarkupTypeSchema typeExport )
2021-03-31 16:42:58 -05:00
{
2021-03-31 17:15:06 -05:00
MethodSchema [] methodSchemaArray = null ;
2021-04-02 19:10:51 -05:00
ushort num1 = _reader . ReadUInt16 ();
2021-03-31 17:15:06 -05:00
if ( num1 > 0 )
2021-03-31 16:42:58 -05:00
{
2021-03-31 17:15:06 -05:00
methodSchemaArray = new MethodSchema [ num1 ];
for ( int index1 = 0 ; index1 < num1 ; ++ index1 )
2021-03-31 16:42:58 -05:00
{
2021-04-02 19:10:51 -05:00
string name = ReadDataTableString ();
TypeSchema type = MapIndexToType ( _reader . ReadUInt16 ());
uint num2 = _reader . ReadUInt32 ();
2021-03-31 16:42:58 -05:00
TypeSchema [] parameterTypes = TypeSchema . EmptyList ;
if ( num2 > 0 U )
{
parameterTypes = new TypeSchema [ num2 ];
2021-03-31 17:15:06 -05:00
for ( int index2 = 0 ; index2 < num2 ; ++ index2 )
2021-03-31 16:42:58 -05:00
{
2021-04-02 19:10:51 -05:00
ushort index3 = _reader . ReadUInt16 ();
parameterTypes [ index2 ] = MapIndexToType ( index3 );
2021-03-31 16:42:58 -05:00
}
}
2021-04-02 19:10:51 -05:00
string [] parameterNames = ReadStringArrayHelper () ?? MarkupMethodSchema . s_emptyStringArray ;
int virtualId = _reader . ReadInt32 ();
bool isVirtualThunk = _reader . ReadBool ();
uint codeOffset = _reader . ReadUInt32 ();
2021-03-31 16:42:58 -05:00
MarkupMethodSchema markupMethodSchema = MarkupMethodSchema . Build ( markupTypeDefinition , typeExport , name , type , parameterTypes , parameterNames , isVirtualThunk );
markupMethodSchema . SetCodeOffset ( codeOffset );
markupMethodSchema . SetVirtualId ( virtualId );
2021-03-31 17:15:06 -05:00
methodSchemaArray [ index1 ] = markupMethodSchema ;
2021-03-31 16:42:58 -05:00
}
}
return methodSchemaArray ;
}
private TypeSchema MarkupTypeToDefinition ( MarkupType markupType )
{
switch ( markupType )
{
case MarkupType . UI :
2021-03-31 17:15:06 -05:00
return UISchema . Type ;
2021-03-31 16:42:58 -05:00
case MarkupType . Effect :
2021-03-31 17:15:06 -05:00
return EffectSchema . Type ;
2021-03-31 16:42:58 -05:00
case MarkupType . DataType :
2021-03-31 17:15:06 -05:00
return DataTypeSchema . Type ;
2021-03-31 16:42:58 -05:00
case MarkupType . DataQuery :
2021-03-31 17:15:06 -05:00
return DataQuerySchema . Type ;
2021-03-31 16:42:58 -05:00
default :
2021-03-31 17:15:06 -05:00
return ClassSchema . Type ;
2021-03-31 16:42:58 -05:00
}
}
private TypeSchema [] GetTempParameterArray ( int count )
{
2021-04-02 19:10:51 -05:00
if ( _typeSchemaArrays == null )
_typeSchemaArrays = new TypeSchema [ 5 ][];
if ( count >= _typeSchemaArrays . Length )
2021-03-31 16:42:58 -05:00
return new TypeSchema [ count ];
int index = count - 1 ;
2021-04-02 19:10:51 -05:00
if ( _typeSchemaArrays [ index ] == null )
_typeSchemaArrays [ index ] = new TypeSchema [ count ];
return _typeSchemaArrays [ index ];
2021-03-31 16:42:58 -05:00
}
2021-04-02 19:10:51 -05:00
public void ReportError ( string error , string param0 , string param1 , string param2 ) => ReportError ( string . Format ( error , param0 , param1 , param2 ));
2021-03-31 16:42:58 -05:00
2021-04-02 19:10:51 -05:00
public void ReportError ( string error , string param0 , string param1 ) => ReportError ( string . Format ( error , param0 , param1 ));
2021-03-31 16:42:58 -05:00
2021-04-02 19:10:51 -05:00
public void ReportError ( string error , string param0 ) => ReportError ( string . Format ( error , param0 ));
2021-03-31 16:42:58 -05:00
public void ReportError ( string error )
{
2021-04-02 19:10:51 -05:00
MarkHasErrors ();
2021-03-31 16:42:58 -05:00
ErrorManager . ReportError ( error );
}
public void MarkHasErrors ()
{
2021-04-02 19:10:51 -05:00
if ( _hasErrors )
2021-03-31 16:42:58 -05:00
return ;
2021-04-02 19:10:51 -05:00
_hasErrors = true ;
_loadResultTarget . MarkLoadFailed ();
2021-03-31 16:42:58 -05:00
}
2021-04-02 19:10:51 -05:00
public bool HasErrors => _hasErrors ;
2021-03-31 16:42:58 -05:00
public static bool IsUIB ( Resource resource )
{
bool flag = false ;
if ( resource . Length > 4 U && ByteCodeReader . ReadUInt32 ( resource . Buffer ) == 440551765 U )
flag = true ;
return flag ;
}
}
}