internal static ObjectLoadData CreateLoadData(
            LoadData loadData,
            int i,
            ObjectHeaderLoadData header)
        {
            ArchiveDeserializer archiveDeserializer = new ArchiveDeserializer();

            archiveDeserializer.LoadFrom(loadData.GameData.ObjectData[i]);
            SaveEntryFolder rootFolder     = archiveDeserializer.RootFolder;
            ObjectLoadData  objectLoadData = new ObjectLoadData(header);
            FolderId        folderId       = new FolderId(i, SaveFolderExtension.Object);
            SaveEntryFolder childFolder    = rootFolder.GetChildFolder(folderId);

            objectLoadData.InitializeReaders(childFolder);
            objectLoadData.FillCreatedObject();
            objectLoadData.Read();
            objectLoadData.FillObject();
            return(objectLoadData);
        }
Example #2
0
 public void InitializeObjects()
 {
     using (new PerformanceTestBlock("LoadContext::Callbacks"))
     {
         for (int i = 0; i < this._objectCount; ++i)
         {
             ObjectHeaderLoadData objectHeaderLoadData = this._objectHeaderLoadDatas[i];
             if (objectHeaderLoadData.Target != null)
             {
                 IEnumerable <MethodInfo> initializationCallbacks = objectHeaderLoadData.TypeDefinition?.InitializationCallbacks;
                 if (initializationCallbacks != null)
                 {
                     foreach (MethodInfo methodInfo in initializationCallbacks)
                     {
                         ParameterInfo[] parameters = methodInfo.GetParameters();
                         if (((IEnumerable <ParameterInfo>)parameters).Count <ParameterInfo>() > 1 && parameters[1].ParameterType == typeof(ObjectLoadData))
                         {
                             ObjectLoadData loadData = LoadContext.CreateLoadData(this._loadData, i, objectHeaderLoadData);
                             methodInfo.Invoke(objectHeaderLoadData.Target, new object[2]
                             {
                                 (object)this._loadData.MetaData,
                                 (object)loadData
                             });
                         }
                         else
                         {
                             methodInfo.Invoke(objectHeaderLoadData.Target, new object[1]
                             {
                                 (object)this._loadData.MetaData
                             });
                         }
                     }
                 }
             }
         }
     }
     GC.Collect();
     GC.WaitForPendingFinalizers();
 }
Example #3
0
 public void InitializeReaders(SaveEntryFolder saveEntryFolder)
 {
     foreach (FolderId childStructName in this.GetChildStructNames(saveEntryFolder))
     {
         int            localId        = childStructName.LocalId;
         ObjectLoadData objectLoadData = new ObjectLoadData(this.Context, localId);
         this._childStructs.Add(localId, objectLoadData);
     }
     for (int id = 0; id < this._elementCount; ++id)
     {
         ElementLoadData elementLoadData1 = new ElementLoadData(this, (IReader)saveEntryFolder.GetEntry(new EntryId(id, SaveEntryExtension.Value)).GetBinaryReader());
         this._values[id] = elementLoadData1;
         if (this._containerType == ContainerType.Dictionary)
         {
             ElementLoadData elementLoadData2 = new ElementLoadData(this, (IReader)saveEntryFolder.GetEntry(new EntryId(id, SaveEntryExtension.Key)).GetBinaryReader());
             this._keys[id] = elementLoadData2;
         }
     }
     foreach (KeyValuePair <int, ObjectLoadData> childStruct in this._childStructs)
     {
         int key = childStruct.Key;
         childStruct.Value.InitializeReaders(saveEntryFolder.GetChildFolder(new FolderId(key, SaveFolderExtension.Struct)));
     }
 }
 public FieldLoadData(ObjectLoadData objectLoadData, IReader reader)
     : base(objectLoadData, reader)
 {
 }
 protected MemberLoadData(ObjectLoadData objectLoadData, IReader reader)
     : base(objectLoadData.Context, reader)
 {
     this.ObjectLoadData = objectLoadData;
 }
 public bool Load(LoadData loadData, bool loadAsLateInitialize)
 {
     try
     {
         using (new PerformanceTestBlock("LoadContext::Load Headers"))
         {
             using (new PerformanceTestBlock("LoadContext::Load And Create Header"))
             {
                 ArchiveDeserializer archiveDeserializer = new ArchiveDeserializer();
                 archiveDeserializer.LoadFrom(loadData.GameData.Header);
                 SaveEntryFolder headerRootFolder = archiveDeserializer.RootFolder;
                 BinaryReader    binaryReader     = headerRootFolder.GetEntry(new EntryId(-1, SaveEntryExtension.Config)).GetBinaryReader();
                 this._objectCount              = binaryReader.ReadInt();
                 this._stringCount              = binaryReader.ReadInt();
                 this._containerCount           = binaryReader.ReadInt();
                 this._objectHeaderLoadDatas    = new ObjectHeaderLoadData[this._objectCount];
                 this._containerHeaderLoadDatas = new ContainerHeaderLoadData[this._containerCount];
                 this._strings = new string[this._stringCount];
                 TWParallel.For(0, this._objectCount, (Action <int>)(i =>
                 {
                     ObjectHeaderLoadData objectHeaderLoadData = new ObjectHeaderLoadData(this, i);
                     SaveEntryFolder childFolder = headerRootFolder.GetChildFolder(new FolderId(i, SaveFolderExtension.Object));
                     objectHeaderLoadData.InitialieReaders(childFolder);
                     this._objectHeaderLoadDatas[i] = objectHeaderLoadData;
                 }));
                 TWParallel.For(0, this._containerCount, (Action <int>)(i =>
                 {
                     ContainerHeaderLoadData containerHeaderLoadData = new ContainerHeaderLoadData(this, i);
                     SaveEntryFolder childFolder = headerRootFolder.GetChildFolder(new FolderId(i, SaveFolderExtension.Container));
                     containerHeaderLoadData.InitialieReaders(childFolder);
                     this._containerHeaderLoadDatas[i] = containerHeaderLoadData;
                 }));
             }
             using (new PerformanceTestBlock("LoadContext::Create Objects"))
             {
                 foreach (ObjectHeaderLoadData objectHeaderLoadData in this._objectHeaderLoadDatas)
                 {
                     objectHeaderLoadData.CreateObject();
                     if (objectHeaderLoadData.Id == 0)
                     {
                         this.RootObject = objectHeaderLoadData.Target;
                     }
                 }
                 foreach (ContainerHeaderLoadData containerHeaderLoadData in this._containerHeaderLoadDatas)
                 {
                     if (containerHeaderLoadData.GetObjectTypeDefinition())
                     {
                         containerHeaderLoadData.CreateObject();
                     }
                 }
             }
         }
         GC.Collect();
         GC.WaitForPendingFinalizers();
         using (new PerformanceTestBlock("LoadContext::Load Strings"))
         {
             ArchiveDeserializer saveArchive = new ArchiveDeserializer();
             saveArchive.LoadFrom(loadData.GameData.Strings);
             for (int id = 0; id < this._stringCount; ++id)
             {
                 string str = LoadContext.LoadString(saveArchive, id);
                 this._strings[id] = str;
             }
         }
         GC.Collect();
         GC.WaitForPendingFinalizers();
         using (new PerformanceTestBlock("LoadContext::Resolve Objects"))
         {
             for (int i = 0; i < this._objectHeaderLoadDatas.Length; ++i)
             {
                 ObjectHeaderLoadData objectHeaderLoadData = this._objectHeaderLoadDatas[i];
                 TypeDefinition       typeDefinition       = objectHeaderLoadData.TypeDefinition;
                 if (typeDefinition != null)
                 {
                     object loadedObject = objectHeaderLoadData.LoadedObject;
                     if (typeDefinition.ObjectResolver.CheckIfRequiresAdvancedResolving(loadedObject))
                     {
                         ObjectLoadData loadData1 = LoadContext.CreateLoadData(loadData, i, objectHeaderLoadData);
                         objectHeaderLoadData.AdvancedResolveObject(loadData.MetaData, loadData1);
                     }
                     else
                     {
                         objectHeaderLoadData.ResolveObject();
                     }
                 }
             }
         }
         GC.Collect();
         GC.WaitForPendingFinalizers();
         using (new PerformanceTestBlock("LoadContext::Load Object Datas"))
             TWParallel.For(0, this._objectCount, (Action <int>)(i =>
             {
                 ObjectHeaderLoadData objectHeaderLoadData = this._objectHeaderLoadDatas[i];
                 if (objectHeaderLoadData.Target != objectHeaderLoadData.LoadedObject)
                 {
                     return;
                 }
                 LoadContext.CreateLoadData(loadData, i, objectHeaderLoadData);
             }));
         using (new PerformanceTestBlock("LoadContext::Load Container Datas"))
             TWParallel.For(0, this._containerCount, (Action <int>)(i =>
             {
                 byte[] binaryArchive = loadData.GameData.ContainerData[i];
                 ArchiveDeserializer archiveDeserializer = new ArchiveDeserializer();
                 archiveDeserializer.LoadFrom(binaryArchive);
                 SaveEntryFolder rootFolder          = archiveDeserializer.RootFolder;
                 ContainerLoadData containerLoadData = new ContainerLoadData(this._containerHeaderLoadDatas[i]);
                 containerLoadData.InitializeReaders(rootFolder.GetChildFolder(new FolderId(i, SaveFolderExtension.Container)));
                 containerLoadData.FillCreatedObject();
                 containerLoadData.Read();
                 containerLoadData.FillObject();
             }));
         GC.Collect();
         GC.WaitForPendingFinalizers();
         if (!loadAsLateInitialize)
         {
             this.CreateLoadCallbackInitializator(loadData).InitializeObjects();
         }
         return(true);
     }
     catch
     {
         return(false);
     }
 }
 public void AdvancedResolveObject(MetaData metaData, ObjectLoadData objectLoadData) => this.Target = this.TypeDefinition.ObjectResolver.AdvancedResolveObject(this.LoadedObject, metaData, objectLoadData);
Example #8
0
 public void FillObject()
 {
     foreach (ObjectLoadData objectLoadData in this._childStructs.Values)
     {
         objectLoadData.FillObject();
     }
     for (int index1 = 0; index1 < this._elementCount; ++index1)
     {
         if (this._containerType == ContainerType.List)
         {
             IList           target          = (IList)this.Target;
             ElementLoadData elementLoadData = this._values[index1];
             if (elementLoadData.SavedMemberType == SavedMemberType.CustomStruct)
             {
                 ObjectLoadData childStruct = this._childStructs[(int)elementLoadData.Data];
                 elementLoadData.SetCustomStructData(childStruct.Target);
             }
             object dataToUse = elementLoadData.GetDataToUse();
             target?.Add(dataToUse);
         }
         else if (this._containerType == ContainerType.Dictionary)
         {
             IDictionary     target          = (IDictionary)this.Target;
             ElementLoadData key             = this._keys[index1];
             ElementLoadData elementLoadData = this._values[index1];
             if (key.SavedMemberType == SavedMemberType.CustomStruct)
             {
                 ObjectLoadData childStruct = this._childStructs[(int)key.Data];
                 key.SetCustomStructData(childStruct.Target);
             }
             if (elementLoadData.SavedMemberType == SavedMemberType.CustomStruct)
             {
                 ObjectLoadData childStruct = this._childStructs[(int)elementLoadData.Data];
                 elementLoadData.SetCustomStructData(childStruct.Target);
             }
             object dataToUse1 = key.GetDataToUse();
             object dataToUse2 = elementLoadData.GetDataToUse();
             if (target != null && dataToUse1 != null)
             {
                 target.Add(dataToUse1, dataToUse2);
             }
         }
         else if (this._containerType == ContainerType.Array)
         {
             Array           target          = (Array)this.Target;
             ElementLoadData elementLoadData = this._values[index1];
             if (elementLoadData.SavedMemberType == SavedMemberType.CustomStruct)
             {
                 ObjectLoadData childStruct = this._childStructs[(int)elementLoadData.Data];
                 elementLoadData.SetCustomStructData(childStruct.Target);
             }
             object dataToUse = elementLoadData.GetDataToUse();
             int    index2    = index1;
             target.SetValue(dataToUse, index2);
         }
         else if (this._containerType == ContainerType.Queue)
         {
             ICollection     target          = (ICollection)this.Target;
             ElementLoadData elementLoadData = this._values[index1];
             if (elementLoadData.SavedMemberType == SavedMemberType.CustomStruct)
             {
                 ObjectLoadData childStruct = this._childStructs[(int)elementLoadData.Data];
                 elementLoadData.SetCustomStructData(childStruct.Target);
             }
             object dataToUse = elementLoadData.GetDataToUse();
             target.GetType().GetMethod("Enqueue").Invoke((object)target, new object[1]
             {
                 dataToUse
             });
         }
     }
 }
 public PropertyLoadData(ObjectLoadData objectLoadData, IReader reader)
     : base(objectLoadData, reader)
 {
 }