public ContainerHeaderLoadData GetContainerWithId(int id)
        {
            ContainerHeaderLoadData containerHeaderLoadData = (ContainerHeaderLoadData)null;

            if (id != -1)
            {
                containerHeaderLoadData = this._containerHeaderLoadDatas[id];
            }
            return(containerHeaderLoadData);
        }
Esempio n. 2
0
 public ContainerLoadData(ContainerHeaderLoadData headerLoadData)
 {
     this.ContainerHeaderLoadData = headerLoadData;
     this._childStructs           = new Dictionary <int, ObjectLoadData>();
     this._saveId        = headerLoadData.SaveId;
     this._containerType = headerLoadData.ContainerType;
     this._elementCount  = headerLoadData.ElementCount;
     this._keys          = new ElementLoadData[this._elementCount];
     this._values        = new ElementLoadData[this._elementCount];
 }
        public object GetDataToUse()
        {
            object obj = (object)null;

            if (this.SavedMemberType == SavedMemberType.Object)
            {
                ObjectHeaderLoadData objectWithId = this.Context.GetObjectWithId((int)this.Data);
                if (objectWithId != null)
                {
                    obj = objectWithId.Target;
                }
            }
            else if (this.SavedMemberType == SavedMemberType.Container)
            {
                ContainerHeaderLoadData containerWithId = this.Context.GetContainerWithId((int)this.Data);
                if (containerWithId != null)
                {
                    obj = containerWithId.Target;
                }
            }
            else if (this.SavedMemberType == SavedMemberType.String)
            {
                obj = (object)this.Context.GetStringWithId((int)this.Data);
            }
            else if (this.SavedMemberType == SavedMemberType.Enum)
            {
                if (this._typeDefinition == null)
                {
                    obj = (object)(string)this.Data;
                }
                else
                {
                    Type type = this._typeDefinition.Type;
                    if (Enum.IsDefined(type, this.Data))
                    {
                        obj = Enum.Parse(type, (string)this.Data);
                    }
                }
            }
            else if (this.SavedMemberType == SavedMemberType.BasicType)
            {
                obj = this.Data;
            }
            else if (this.SavedMemberType == SavedMemberType.CustomStruct)
            {
                obj = this._customStructObject;
            }
            return(obj);
        }
 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);
     }
 }