GameObject convert_to_gameobject(string base64) { byte[] compression = System.Convert.FromBase64String(base64); MemoryStream stream = new MemoryStream(compression); MemoryStream other_stream = new MemoryStream(4096); // ughhhh using (DeflateStream inflater = new DeflateStream(stream, CompressionMode.Decompress)) { inflater.CopyTo(other_stream); } byte[] object_info = other_stream.ToArray(); // Magic voodoo IReader reader = new FastReader(object_info); Tag tag = TagManager.Create(reader.ReadKleiString()); // Blood sacrifice -SB KSerialization.Manager.Clear(); KSerialization.Manager.DeserializeDirectory(reader); Transform transform = this.transform; // Even more magic voodoo // The first argument gets us a blank prefab for an object defined // in the base64 string, put there by the sender // Arugments 2-4 get the position, rotation, and localScale of the // current 'this' kmonobehavior // Lastly is the Reader which is above // And finally, because its a SaveLoadRoot, that just loaded an // object, we need to get that object return(SaveLoadRoot.Load(SaveLoader.Instance.saveManager.GetPrefab(tag), transform.GetPosition(), transform.rotation, transform.localScale, reader).gameObject); }
private void OnDeserialized() { if (serializationBuffer != null) { FastReader fastReader = new FastReader(serializationBuffer); int num = fastReader.ReadInt32(); for (int i = 0; i < num; i++) { string text = fastReader.ReadKleiString(); int num2 = fastReader.ReadInt32(); int position = fastReader.Position; Type type = Type.GetType(text); if (type == null) { DebugUtil.LogWarningArgs("Type no longer exists: " + text); fastReader.SkipBytes(num2); } else { ItemType val = (typeof(ItemType) == type) ? default(ItemType) : ((ItemType)Activator.CreateInstance(type)); Deserializer.DeserializeTypeless(val, fastReader); if (fastReader.Position != position + num2) { DebugUtil.LogWarningArgs("Expected to be at offset", position + num2, "but was only at offset", fastReader.Position, ". Skipping to catch up."); fastReader.SkipBytes(position + num2 - fastReader.Position); } items.Add(val); } } } }
public unsafe static int Load(FastReader reader) { //IL_0026: Incompatible stack types: I vs Ref int num = reader.ReadInt32(); byte[] array = reader.ReadBytes(num); IntPtr intPtr; fixed(byte *msg = &((array != null && array.Length != 0) ? ref array[0] : ref *(byte *)null)) { intPtr = SIM_HandleMessage(-672538170, num, msg); } if (intPtr == IntPtr.Zero) { return(-1); } GameDataUpdate *ptr = (GameDataUpdate *)(void *)intPtr; Grid.elementIdx = ptr->elementIdx; Grid.temperature = ptr->temperature; Grid.mass = ptr->mass; Grid.properties = ptr->properties; Grid.strengthInfo = ptr->strengthInfo; Grid.insulation = ptr->insulation; Grid.diseaseIdx = ptr->diseaseIdx; Grid.diseaseCount = ptr->diseaseCount; Grid.AccumulatedFlowValues = ptr->accumulatedFlow; PropertyTextures.externalFlowTex = ptr->propertyTextureFlow; PropertyTextures.externalLiquidTex = ptr->propertyTextureLiquid; PropertyTextures.externalExposedToSunlight = ptr->propertyTextureExposedToSunlight; Grid.InitializeCells(); return(0); }
public virtual void Deserialize(FastReader fs) { m_miniRam = fs.ReadInt32(); m_maxiRam = fs.ReadInt32(); javapath = fs.ReadString(); corepath = fs.ReadString(); jvm_line = fs.ReadString(); }
public static void Load(FastReader reader) { position = reader.ReadVector3(); localScale = reader.ReadVector3(); rotation = reader.ReadQuaternion(); orthographicsSize = reader.ReadSingle(); valid = true; }
public bool LoadFromWorldGen() { DebugUtil.LogArgs("Attempting to start a new game with current world gen"); WorldGen.LoadSettings(); string worldName; try { worldName = CustomGameSettings.Instance.GetCurrentQualitySetting(CustomGameSettingConfigs.World).id; } catch { worldName = "worlds/SandstoneDefault"; } worldGen = new WorldGen(worldName, null); SimSaveFileStructure simSaveFileStructure = worldGen.LoadWorldGenSim(); if (simSaveFileStructure == null) { Debug.LogError("Attempt failed"); return(false); } worldDetailSave = simSaveFileStructure.worldDetail; if (worldDetailSave == null) { Debug.LogError("Detail is null"); } GridSettings.Reset(simSaveFileStructure.WidthInCells, simSaveFileStructure.HeightInCells); Singleton <KBatchedAnimUpdater> .Instance.InitializeGrid(); Sim.SIM_Initialize(Sim.DLL_MessageHandler); SimMessages.CreateSimElementsTable(ElementLoader.elements); SimMessages.CreateDiseaseTable(); try { FastReader reader = new FastReader(simSaveFileStructure.Sim); if (Sim.Load(reader) != 0) { DebugUtil.LogWarningArgs("\n--- Error loading save ---\nSimDLL found bad data\n"); Sim.Shutdown(); return(false); } } catch (Exception ex) { Debug.LogWarning("--- Error loading Sim FROM NEW WORLDGEN ---" + ex.Message + "\n" + ex.StackTrace); Sim.Shutdown(); return(false); } Debug.Log("Attempt success"); SceneInitializer.Instance.PostLoadPrefabs(); SceneInitializer.Instance.NewSaveGamePrefab(); worldGen.ReplayGenerate(Reset); OnWorldGenComplete.Signal(); ThreadedHttps <KleiMetrics> .Instance.StartNewGame(); return(true); }
private void OnDeserialized() { if (storedData != null) { FastReader reader = new FastReader(storedData); CreateStorageProxy(); storageProxy.Deserialize(reader); storedData = null; } }
private static void ParseHashTable(FastReader reader) { int num = reader.ReadInt32(); for (int i = 0; i < num; i++) { int hash = reader.ReadInt32(); string text = reader.ReadKleiString(); HashCache.Get().Add(hash, text); } }
public void ReadString() { var text = "hello"; var memory = new FastMemoryWriter(); memory.Write(text); memory.Seek(0, SeekOrigin.Begin); var reader = new FastReader(memory); var result = reader.ReadString(); Assert.Equal(text, result); }
public void ReadWrongByteArray() { var bytes = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, }; var memory = new FastMemoryWriter(); memory.WriteByteArray(bytes); memory.SetLength(9); memory.Seek(0, SeekOrigin.Begin); var reader = new FastReader(memory); Assert.Throws <EndOfStreamException>(() => reader.ReadByteArray()); }
public void ReadByteArray() { var bytes = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, }; var memory = new FastMemoryWriter(); memory.WriteByteArray(bytes); memory.Seek(0, SeekOrigin.Begin); var reader = new FastReader(memory); var result = reader.ReadByteArray(); Assert.True(result.SequenceEqual(bytes)); }
private static void CheckHeader(string header, FastReader reader) { char[] array = reader.ReadChars(header.Length); int num = 0; while (true) { if (num >= header.Length) { return; } if (array[num] != header[num]) { break; } num++; } throw new Exception("Expected " + header); }
public bool Load(string filename) { SetActiveSaveFilePath(filename); try { KSerialization.Manager.Clear(); byte[] array = File.ReadAllBytes(filename); IReader reader = new FastReader(array); GameInfo = SaveGame.GetHeader(reader, out SaveGame.Header header); LoadedHeader = header; DebugUtil.LogArgs(string.Format("Loading save file: {4}\n headerVersion:{0}, buildVersion:{1}, headerSize:{2}, IsCompressed:{3}", header.headerVersion, header.buildVersion, header.headerSize, header.IsCompressed, filename)); object[] obj = new object[1]; object[] obj2 = new object[7]; SaveGame.GameInfo gameInfo = GameInfo; obj2[0] = gameInfo.numberOfCycles; SaveGame.GameInfo gameInfo2 = GameInfo; obj2[1] = gameInfo2.numberOfDuplicants; SaveGame.GameInfo gameInfo3 = GameInfo; obj2[2] = gameInfo3.baseName; SaveGame.GameInfo gameInfo4 = GameInfo; obj2[3] = gameInfo4.isAutoSave; SaveGame.GameInfo gameInfo5 = GameInfo; obj2[4] = gameInfo5.originalSaveName; SaveGame.GameInfo gameInfo6 = GameInfo; obj2[5] = gameInfo6.saveMajorVersion; SaveGame.GameInfo gameInfo7 = GameInfo; obj2[6] = gameInfo7.saveMinorVersion; obj[0] = string.Format("GameInfo: numberOfCycles:{0}, numberOfDuplicants:{1}, baseName:{2}, isAutoSave:{3}, originalSaveName:{4}, saveVersion:{5}.{6}", obj2); DebugUtil.LogArgs(obj); SaveGame.GameInfo gameInfo8 = GameInfo; if (gameInfo8.saveMajorVersion == 7) { SaveGame.GameInfo gameInfo9 = GameInfo; if (gameInfo9.saveMinorVersion < 4) { Helper.SetTypeInfoMask((SerializationTypeInfo)191); } } KSerialization.Manager.DeserializeDirectory(reader); if (header.IsCompressed) { int num = array.Length - reader.Position; byte[] array2 = new byte[num]; Array.Copy(array, reader.Position, array2, 0, num); byte[] bytes = DecompressContents(array2); IReader reader2 = new FastReader(bytes); Load(reader2); } else { Load(reader); } SaveGame.GameInfo gameInfo10 = GameInfo; if (gameInfo10.isAutoSave) { SaveGame.GameInfo gameInfo11 = GameInfo; if (!string.IsNullOrEmpty(gameInfo11.originalSaveName)) { SaveGame.GameInfo gameInfo12 = GameInfo; SetActiveSaveFilePath(gameInfo12.originalSaveName); } } } catch (Exception ex) { DebugUtil.LogWarningArgs("\n--- Error loading save ---\n" + ex.Message + "\n" + ex.StackTrace); Sim.Shutdown(); SetActiveSaveFilePath(null); return(false); } Stats.Print(); DebugUtil.LogArgs("Loaded", "[" + filename + "]"); DebugUtil.LogArgs("World Seeds", "[" + worldDetailSave.globalWorldSeed + "/" + worldDetailSave.globalWorldLayoutSeed + "/" + worldDetailSave.globalTerrainSeed + "/" + worldDetailSave.globalNoiseSeed + "]"); GC.Collect(); return(true); }
public unsafe static bool DoSettleSim(WorldGenSettings settings, Sim.Cell[] cells, float[] bgTemp, Sim.DiseaseCell[] dcs, WorldGen.OfflineCallbackFunction updateProgressFn, Data data, List <KeyValuePair <Vector2I, TemplateContainer> > templateSpawnTargets, Action <OfflineWorldGen.ErrorInfo> error_cb, Action <Sim.Cell[], float[], Sim.DiseaseCell[]> onSettleComplete) { Sim.SIM_Initialize(Sim.DLL_MessageHandler); SimMessages.CreateSimElementsTable(ElementLoader.elements); SimMessages.CreateWorldGenHACKDiseaseTable(WorldGen.diseaseIds); Sim.DiseaseCell[] dc = new Sim.DiseaseCell[dcs.Length]; SimMessages.SimDataInitializeFromCells(Grid.WidthInCells, Grid.HeightInCells, cells, bgTemp, dc); int num = 500; updateProgressFn(UI.WORLDGEN.SETTLESIM.key, 0f, WorldGenProgressStages.Stages.SettleSim); Vector2I min = new Vector2I(0, 0); Vector2I max = new Vector2I(Grid.WidthInCells, Grid.HeightInCells); byte[] bytes = null; using (MemoryStream memoryStream = new MemoryStream()) { using (BinaryWriter writer = new BinaryWriter(memoryStream)) { try { Sim.Save(writer); } catch (Exception ex) { string message = ex.Message; string stackTrace = ex.StackTrace; WorldGenLogger.LogException(message, stackTrace); return(updateProgressFn(new StringKey("Exception in Sim Save"), -1f, WorldGenProgressStages.Stages.Failure)); } } bytes = memoryStream.ToArray(); } FastReader reader = new FastReader(bytes); if (Sim.Load(reader) != 0) { updateProgressFn(UI.WORLDGEN.FAILED.key, -1f, WorldGenProgressStages.Stages.Failure); return(true); } byte[] array = new byte[Grid.CellCount]; for (int i = 0; i < Grid.CellCount; i++) { array[i] = byte.MaxValue; } for (int j = 0; j < num; j++) { SimMessages.NewGameFrame(0.2f, min, max); IntPtr intPtr = Sim.HandleMessage(SimMessageHashes.PrepareGameData, array.Length, array); updateProgressFn(UI.WORLDGEN.SETTLESIM.key, (float)j / (float)num * 100f, WorldGenProgressStages.Stages.SettleSim); if (!(intPtr == IntPtr.Zero)) { Sim.GameDataUpdate *ptr = (Sim.GameDataUpdate *)(void *) intPtr; for (int k = 0; k < ptr->numSubstanceChangeInfo; k++) { Sim.SubstanceChangeInfo substanceChangeInfo = ptr->substanceChangeInfo[k]; int cellIdx = substanceChangeInfo.cellIdx; cells[cellIdx].elementIdx = ptr->elementIdx[cellIdx]; cells[cellIdx].insulation = ptr->insulation[cellIdx]; cells[cellIdx].properties = ptr->properties[cellIdx]; cells[cellIdx].temperature = ptr->temperature[cellIdx]; cells[cellIdx].mass = ptr->mass[cellIdx]; cells[cellIdx].strengthInfo = ptr->strengthInfo[cellIdx]; } foreach (KeyValuePair <Vector2I, TemplateContainer> templateSpawnTarget in templateSpawnTargets) { Cell templateCellData; for (int l = 0; l < templateSpawnTarget.Value.cells.Count; l++) { templateCellData = templateSpawnTarget.Value.cells[l]; Vector2I key = templateSpawnTarget.Key; int x = key.x; Vector2I key2 = templateSpawnTarget.Key; int num2 = Grid.OffsetCell(Grid.XYToCell(x, key2.y), templateCellData.location_x, templateCellData.location_y); if (Grid.IsValidCell(num2)) { cells[num2].elementIdx = (byte)ElementLoader.GetElementIndex(templateCellData.element); cells[num2].temperature = templateCellData.temperature; cells[num2].mass = templateCellData.mass; dcs[num2].diseaseIdx = (byte)WorldGen.diseaseIds.FindIndex((string name) => name == templateCellData.diseaseName); dcs[num2].elementCount = templateCellData.diseaseCount; } } } } } for (int m = 0; m < Grid.CellCount; m++) { int callbackIdx = (m != Grid.CellCount - 1) ? (-1) : 2147481337; SimMessages.ModifyCell(m, cells[m].elementIdx, cells[m].temperature, cells[m].mass, dcs[m].diseaseIdx, dcs[m].elementCount, SimMessages.ReplaceType.Replace, false, callbackIdx); } bool flag = false; while (!flag) { SimMessages.NewGameFrame(0.2f, min, max); IntPtr intPtr2 = Sim.HandleMessage(SimMessageHashes.PrepareGameData, array.Length, array); if (!(intPtr2 == IntPtr.Zero)) { Sim.GameDataUpdate *ptr2 = (Sim.GameDataUpdate *)(void *) intPtr2; for (int n = 0; n < ptr2->numCallbackInfo; n++) { Sim.CallbackInfo callbackInfo = ptr2->callbackInfo[n]; if (callbackInfo.callbackIdx == 2147481337) { flag = true; break; } } } } Sim.HandleMessage(SimMessageHashes.SettleWorldGen, 0, null); bool result = SaveSim(settings, data, error_cb); onSettleComplete(cells, bgTemp, dcs); Sim.Shutdown(); return(result); }
public HomeController(FastReader reader) { this.Reader = reader; }
public abstract void Deserialize(FastReader fs);
public static int ParseBuildData(KBatchGroupData data, KAnimHashedString fileNameHash, FastReader reader, List <Texture2D> textures) { CheckHeader("BILD", reader); int num = reader.ReadInt32(); if (num != 10 && num != 9) { Debug.LogError(fileNameHash + " has invalid build.bytes version [" + num + "]"); return(-1); } KAnimGroupFile.Group group = KAnimGroupFile.GetGroup(data.groupID); if (group == null) { Debug.LogErrorFormat("[{1}] Failed to get group [{0}]", data.groupID, fileNameHash.DebuggerDisplay); } KAnim.Build build = null; int num2 = reader.ReadInt32(); int num3 = reader.ReadInt32(); build = data.AddNewBuildFile(fileNameHash); build.textureCount = textures.Count; if (textures.Count > 0) { data.AddTextures(textures); } build.symbols = new KAnim.Build.Symbol[num2]; build.frames = new KAnim.Build.SymbolFrame[num3]; build.name = reader.ReadKleiString(); build.batchTag = ((!group.swapTarget.IsValid) ? data.groupID : group.target); build.fileHash = fileNameHash; int num4 = 0; for (int i = 0; i < build.symbols.Length; i++) { KAnimHashedString hash = new KAnimHashedString(reader.ReadInt32()); KAnim.Build.Symbol symbol = new KAnim.Build.Symbol(); symbol.build = build; symbol.hash = hash; if (num > 9) { symbol.path = new KAnimHashedString(reader.ReadInt32()); } symbol.colourChannel = new KAnimHashedString(reader.ReadInt32()); symbol.flags = reader.ReadInt32(); symbol.firstFrameIdx = data.symbolFrameInstances.Count; symbol.numFrames = reader.ReadInt32(); symbol.symbolIndexInSourceBuild = i; int num5 = 0; for (int j = 0; j < symbol.numFrames; j++) { KAnim.Build.SymbolFrame symbolFrame = new KAnim.Build.SymbolFrame(); KAnim.Build.SymbolFrameInstance item = default(KAnim.Build.SymbolFrameInstance); item.symbolFrame = symbolFrame; symbolFrame.fileNameHash = fileNameHash; symbolFrame.sourceFrameNum = reader.ReadInt32(); symbolFrame.duration = reader.ReadInt32(); item.buildImageIdx = data.textureStartIndex[fileNameHash] + reader.ReadInt32(); if (item.buildImageIdx >= textures.Count + data.textureStartIndex[fileNameHash]) { Debug.LogErrorFormat("{0} Symbol: [{1}] tex count: [{2}] buildImageIdx: [{3}] group total [{4}]", fileNameHash.ToString(), symbol.hash, textures.Count, item.buildImageIdx, data.textureStartIndex[fileNameHash]); } item.symbolIdx = data.GetSymbolCount(); num5 = Math.Max(symbolFrame.sourceFrameNum + symbolFrame.duration, num5); float num6 = reader.ReadSingle(); float num7 = reader.ReadSingle(); float num8 = reader.ReadSingle(); float num9 = reader.ReadSingle(); symbolFrame.bboxMin = new Vector2(num6 - num8 * 0.5f, num7 - num9 * 0.5f); symbolFrame.bboxMax = new Vector2(num6 + num8 * 0.5f, num7 + num9 * 0.5f); float x = reader.ReadSingle(); float num10 = reader.ReadSingle(); float x2 = reader.ReadSingle(); float num11 = reader.ReadSingle(); symbolFrame.uvMin = new Vector2(x, 1f - num10); symbolFrame.uvMax = new Vector2(x2, 1f - num11); build.frames[num4] = symbolFrame; data.symbolFrameInstances.Add(item); num4++; } symbol.numLookupFrames = num5; data.AddBuildSymbol(symbol); build.symbols[i] = symbol; } ParseHashTable(reader); return(build.index); }
public void LoadAll() { Debug.Assert(!hasCompletedLoadAll, "You cannot load all the anim data twice!"); fileData.Clear(); for (int i = 0; i < groups.Count; i++) { if (!groups[i].id.IsValid) { Debug.LogErrorFormat("Group invalid groupIndex [{0}]", i); } KBatchGroupData kBatchGroupData = null; kBatchGroupData = ((!groups[i].target.IsValid) ? KAnimBatchManager.Instance().GetBatchGroupData(groups[i].id) : KAnimBatchManager.Instance().GetBatchGroupData(groups[i].target)); HashedString batchTag = groups[i].id; if (groups[i].renderType == KAnimBatchGroup.RendererType.AnimOnly) { if (!groups[i].swapTarget.IsValid) { continue; } kBatchGroupData = KAnimBatchManager.Instance().GetBatchGroupData(groups[i].swapTarget); batchTag = groups[i].swapTarget; } for (int j = 0; j < groups[i].files.Count; j++) { KAnimFile kAnimFile = groups[i].files[j]; if ((UnityEngine.Object)kAnimFile != (UnityEngine.Object)null && kAnimFile.buildBytes != null && !fileData.ContainsKey(kAnimFile.GetInstanceID())) { if (kAnimFile.buildBytes.Length == 0) { Debug.LogWarning("Build File [" + kAnimFile.GetData().name + "] has 0 bytes"); } else { HashedString hash = new HashedString(kAnimFile.name); HashCache.Get().Add(hash.HashValue, kAnimFile.name); KAnimFileData file = KGlobalAnimParser.Get().GetFile(kAnimFile); file.maxVisSymbolFrames = 0; file.batchTag = batchTag; file.buildIndex = KGlobalAnimParser.ParseBuildData(kBatchGroupData, hash, new FastReader(kAnimFile.buildBytes), kAnimFile.textureList); fileData.Add(kAnimFile.GetInstanceID(), file); } } } } for (int k = 0; k < groups.Count; k++) { if (groups[k].renderType == KAnimBatchGroup.RendererType.AnimOnly) { KBatchGroupData batchGroupData = KAnimBatchManager.Instance().GetBatchGroupData(groups[k].swapTarget); KBatchGroupData batchGroupData2 = KAnimBatchManager.Instance().GetBatchGroupData(groups[k].animTarget); for (int l = 0; l < batchGroupData.builds.Count; l++) { KAnim.Build build = batchGroupData.builds[l]; if (build != null && build.symbols != null) { for (int m = 0; m < build.symbols.Length; m++) { KAnim.Build.Symbol symbol = build.symbols[m]; if (symbol != null && symbol.hash.IsValid() && batchGroupData2.GetFirstIndex(symbol.hash) == -1) { KAnim.Build.Symbol symbol2 = new KAnim.Build.Symbol(); symbol2.build = build; symbol2.hash = symbol.hash; symbol2.path = symbol.path; symbol2.colourChannel = symbol.colourChannel; symbol2.flags = symbol.flags; symbol2.firstFrameIdx = batchGroupData2.symbolFrameInstances.Count; symbol2.numFrames = symbol.numFrames; symbol2.symbolIndexInSourceBuild = batchGroupData2.frameElementSymbols.Count; for (int n = 0; n < symbol2.numFrames; n++) { KAnim.Build.SymbolFrameInstance symbolFrameInstance = batchGroupData.GetSymbolFrameInstance(n + symbol.firstFrameIdx); KAnim.Build.SymbolFrameInstance item = default(KAnim.Build.SymbolFrameInstance); item.symbolFrame = symbolFrameInstance.symbolFrame; item.buildImageIdx = -1; item.symbolIdx = batchGroupData2.GetSymbolCount(); batchGroupData2.symbolFrameInstances.Add(item); } batchGroupData2.AddBuildSymbol(symbol2); } } } } } } for (int num = 0; num < groups.Count; num++) { if (!groups[num].id.IsValid) { Debug.LogErrorFormat("Group invalid groupIndex [{0}]", num); } if (groups[num].renderType != KAnimBatchGroup.RendererType.DontRender) { KBatchGroupData kBatchGroupData2 = null; if (groups[num].animTarget.IsValid) { kBatchGroupData2 = KAnimBatchManager.Instance().GetBatchGroupData(groups[num].animTarget); if (kBatchGroupData2 == null) { Debug.LogErrorFormat("Anim group is null for [{0}] -> [{1}]", groups[num].id, groups[num].animTarget); } } else { kBatchGroupData2 = KAnimBatchManager.Instance().GetBatchGroupData(groups[num].id); if (kBatchGroupData2 == null) { Debug.LogErrorFormat("Anim group is null for [{0}]", groups[num].id); } } for (int num2 = 0; num2 < groups[num].files.Count; num2++) { KAnimFile kAnimFile2 = groups[num].files[num2]; if ((UnityEngine.Object)kAnimFile2 != (UnityEngine.Object)null && kAnimFile2.animBytes != null) { if (kAnimFile2.animBytes.Length == 0) { Debug.LogWarning("Anim File [" + kAnimFile2.GetData().name + "] has 0 bytes"); } else { if (!fileData.ContainsKey(kAnimFile2.GetInstanceID())) { KAnimFileData file2 = KGlobalAnimParser.Get().GetFile(kAnimFile2); file2.maxVisSymbolFrames = 0; file2.batchTag = groups[num].id; fileData.Add(kAnimFile2.GetInstanceID(), file2); } HashedString fileNameHash = new HashedString(kAnimFile2.name); FastReader reader = new FastReader(kAnimFile2.animBytes); KAnimFileData animFile = fileData[kAnimFile2.GetInstanceID()]; KGlobalAnimParser.ParseAnimData(kBatchGroupData2, fileNameHash, reader, animFile); } } } } } for (int num3 = 0; num3 < groups.Count; num3++) { if (!groups[num3].id.IsValid) { Debug.LogErrorFormat("Group invalid groupIndex [{0}]", num3); } KBatchGroupData kBatchGroupData3 = null; if (groups[num3].target.IsValid) { kBatchGroupData3 = KAnimBatchManager.Instance().GetBatchGroupData(groups[num3].target); if (kBatchGroupData3 == null) { Debug.LogErrorFormat("Group is null for [{0}] target [{1}]", groups[num3].id, groups[num3].target); } } else { kBatchGroupData3 = KAnimBatchManager.Instance().GetBatchGroupData(groups[num3].id); if (kBatchGroupData3 == null) { Debug.LogErrorFormat("Group is null for [{0}]", groups[num3].id); } } KGlobalAnimParser.PostParse(kBatchGroupData3); } hasCompletedLoadAll = true; }
private bool Load(IReader reader) { string a = reader.ReadKleiString(); Debug.Assert(a == "world"); Deserializer deserializer = new Deserializer(reader); SaveFileRoot saveFileRoot = new SaveFileRoot(); deserializer.Deserialize(saveFileRoot); SaveGame.GameInfo gameInfo = GameInfo; if (gameInfo.saveMajorVersion != 7) { SaveGame.GameInfo gameInfo2 = GameInfo; if (gameInfo2.saveMinorVersion >= 8) { goto IL_00f7; } } if (saveFileRoot.requiredMods != null) { saveFileRoot.active_mods = new List <Label>(); foreach (ModInfo requiredMod in saveFileRoot.requiredMods) { ModInfo current = requiredMod; saveFileRoot.active_mods.Add(new Label { id = current.assetID, version = current.lastModifiedTime, distribution_platform = Label.DistributionPlatform.Steam, title = current.description }); } saveFileRoot.requiredMods.Clear(); } goto IL_00f7; IL_00f7: KMod.Manager modManager = Global.Instance.modManager; modManager.Load(Content.LayerableFiles); if (!modManager.MatchFootprint(saveFileRoot.active_mods, Content.LayerableFiles | Content.Strings | Content.DLL | Content.Translation | Content.Animation)) { DebugUtil.LogWarningArgs("Mod footprint of save file doesn't match current mod configuration"); } Global.Instance.modManager.SendMetricsEvent(); string text = saveFileRoot.worldID; if (text == null) { try { text = CustomGameSettings.Instance.GetCurrentQualitySetting(CustomGameSettingConfigs.World).id; } catch { text = "worlds/SandstoneDefault"; } } Game.worldID = text; worldGen = new WorldGen(text, null); Game.LoadSettings(deserializer); GridSettings.Reset(saveFileRoot.WidthInCells, saveFileRoot.HeightInCells); Singleton <KBatchedAnimUpdater> .Instance.InitializeGrid(); Sim.SIM_Initialize(Sim.DLL_MessageHandler); SimMessages.CreateSimElementsTable(ElementLoader.elements); SimMessages.CreateDiseaseTable(); byte[] bytes = saveFileRoot.streamed["Sim"]; FastReader reader2 = new FastReader(bytes); if (Sim.Load(reader2) != 0) { DebugUtil.LogWarningArgs("\n--- Error loading save ---\nSimDLL found bad data\n"); Sim.Shutdown(); return(false); } SceneInitializer.Instance.PostLoadPrefabs(); mustRestartOnFail = true; if (!saveManager.Load(reader)) { Sim.Shutdown(); DebugUtil.LogWarningArgs("\n--- Error loading save ---\n"); SetActiveSaveFilePath(null); return(false); } Grid.Visible = saveFileRoot.streamed["GridVisible"]; if (saveFileRoot.streamed.ContainsKey("GridSpawnable")) { Grid.Spawnable = saveFileRoot.streamed["GridSpawnable"]; } Grid.Damage = BytesToFloat(saveFileRoot.streamed["GridDamage"]); Game.Instance.Load(deserializer); FastReader reader3 = new FastReader(saveFileRoot.streamed["Camera"]); CameraSaveData.Load(reader3); return(true); }
public AccountController(FastReader reader) { this.Reader = reader; }
public static void ParseAnimData(KBatchGroupData data, HashedString fileNameHash, FastReader reader, KAnimFileData animFile) { CheckHeader("ANIM", reader); uint num = reader.ReadUInt32(); Assert(num == 5, "Invalid anim.bytes version"); reader.ReadInt32(); reader.ReadInt32(); int num2 = reader.ReadInt32(); animFile.maxVisSymbolFrames = 0; animFile.animCount = 0; animFile.frameCount = 0; animFile.elementCount = 0; animFile.firstAnimIndex = data.anims.Count; animFile.animBatchTag = data.groupID; data.animIndex.Add(fileNameHash, data.anims.Count); animFile.firstElementIndex = data.frameElements.Count; for (int i = 0; i < num2; i++) { KAnim.Anim anim = new KAnim.Anim(animFile, data.anims.Count); anim.name = reader.ReadKleiString(); string text = animFile.name + "." + anim.name; anim.id = text; HashCache.Get().Add(anim.name); HashCache.Get().Add(text); anim.hash = anim.name; anim.rootSymbol.HashValue = reader.ReadInt32(); anim.frameRate = reader.ReadSingle(); anim.firstFrameIdx = data.animFrames.Count; anim.numFrames = reader.ReadInt32(); anim.totalTime = (float)anim.numFrames / anim.frameRate; anim.scaledBoundingRadius = 0f; for (int j = 0; j < anim.numFrames; j++) { KAnim.Anim.Frame item = default(KAnim.Anim.Frame); float num3 = reader.ReadSingle(); float num4 = reader.ReadSingle(); float num5 = reader.ReadSingle(); float num6 = reader.ReadSingle(); item.bbox = new AABB3(new Vector3(num3 - num5 * 0.5f, 0f - (num4 + num6 * 0.5f), 0f) * 0.005f, new Vector3(num3 + num5 * 0.5f, 0f - (num4 - num6 * 0.5f), 0f) * 0.005f); float num7 = Math.Max(Math.Abs(item.bbox.max.x), Math.Abs(item.bbox.min.x)); float num8 = Math.Max(Math.Abs(item.bbox.max.y), Math.Abs(item.bbox.min.y)); float num9 = Math.Max(num7, num8); anim.unScaledSize.x = Math.Max(anim.unScaledSize.x, num7 / 0.005f); anim.unScaledSize.y = Math.Max(anim.unScaledSize.y, num8 / 0.005f); anim.scaledBoundingRadius = Math.Max(anim.scaledBoundingRadius, Mathf.Sqrt(num9 * num9 + num9 * num9)); item.idx = data.animFrames.Count; item.firstElementIdx = data.frameElements.Count; item.numElements = reader.ReadInt32(); int num10 = 0; for (int k = 0; k < item.numElements; k++) { KAnim.Anim.FrameElement item2 = default(KAnim.Anim.FrameElement); item2.fileHash = fileNameHash; item2.symbol = new KAnimHashedString(reader.ReadInt32()); item2.frame = reader.ReadInt32(); item2.folder = new KAnimHashedString(reader.ReadInt32()); item2.flags = reader.ReadInt32(); float a = reader.ReadSingle(); float b = reader.ReadSingle(); float g = reader.ReadSingle(); float r = reader.ReadSingle(); item2.multColour = new Color(r, g, b, a); float m = reader.ReadSingle(); float m2 = reader.ReadSingle(); float m3 = reader.ReadSingle(); float m4 = reader.ReadSingle(); float m5 = reader.ReadSingle(); float m6 = reader.ReadSingle(); reader.ReadSingle(); item2.transform.m00 = m; item2.transform.m01 = m3; item2.transform.m02 = m5; item2.transform.m10 = m2; item2.transform.m11 = m4; item2.transform.m12 = m6; int symbolIndex = data.GetSymbolIndex(item2.symbol); if (symbolIndex == -1) { num10++; item2.symbol = MISSING_SYMBOL; } else { item2.symbolIdx = symbolIndex; data.frameElements.Add(item2); animFile.elementCount++; } } item.numElements -= num10; data.animFrames.Add(item); animFile.frameCount++; } data.AddAnim(anim); animFile.animCount++; } Debug.Assert(num2 == animFile.animCount); data.animCount[fileNameHash] = animFile.animCount; animFile.maxVisSymbolFrames = Math.Max(animFile.maxVisSymbolFrames, reader.ReadInt32()); data.UpdateMaxVisibleSymbols(animFile.maxVisSymbolFrames); ParseHashTable(reader); }