Пример #1
0
    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);
    }
Пример #2
0
    protected override void OnSpawn()
    {
        string activeSaveFilePath = GetActiveSaveFilePath();

        if (WorldGen.CanLoad(activeSaveFilePath))
        {
            Sim.SIM_Initialize(Sim.DLL_MessageHandler);
            SimMessages.CreateSimElementsTable(ElementLoader.elements);
            SimMessages.CreateDiseaseTable();
            loadedFromSave  = true;
            loadedFromSave  = Load(activeSaveFilePath);
            saveFileCorrupt = !loadedFromSave;
            if (!loadedFromSave)
            {
                SetActiveSaveFilePath(null);
                if (mustRestartOnFail)
                {
                    MoveCorruptFile(activeSaveFilePath);
                    Sim.Shutdown();
                    App.LoadScene("frontend");
                    return;
                }
            }
        }
        if (!loadedFromSave)
        {
            Sim.Shutdown();
            if (!string.IsNullOrEmpty(activeSaveFilePath))
            {
                DebugUtil.LogArgs("Couldn't load [" + activeSaveFilePath + "]");
            }
            if (saveFileCorrupt)
            {
                MoveCorruptFile(activeSaveFilePath);
            }
            bool flag = WorldGen.CanLoad(WorldGen.SIM_SAVE_FILENAME);
            if (!flag || !LoadFromWorldGen())
            {
                DebugUtil.LogWarningArgs("Couldn't start new game with current world gen, moving file");
                if (flag)
                {
                    KMonoBehaviour.isLoadingScene = true;
                    MoveCorruptFile(WorldGen.SIM_SAVE_FILENAME);
                }
                App.LoadScene("frontend");
            }
        }
    }
Пример #3
0
    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);
    }