Exemple #1
0
        private static void DoBuildSaveList()
        {
            saveFiles.Clear();
            string path = GetSavesPath();

            Dbgl($"Checking directory {path}");

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
                if (!Directory.Exists(path))
                {
                    Dbgl($"(OnShowGUI) Directory {path} does not exist and could not be created!");
                }
                return;
            }
            foreach (string file in Directory.GetFiles(path))
            {
                if (file.EndsWith(".xml"))
                {
                    continue;
                }
                CustomSaveFile csf = new CustomSaveFile(Path.GetFileName(file));
                if (csf.isValid())
                {
                    saveFiles.Add(csf);
                }
            }
            saveFiles.Sort(delegate(CustomSaveFile x, CustomSaveFile y)
            {
                string datex = x.fileName.Split('_')[2];
                string datey = y.fileName.Split('_')[2];
                return(datex.CompareTo(datey));
            });
        }
        private static IEnumerator LoadGameFromArchive(string fileName)
        {
            string         filePath = Path.Combine(GetSavesPath(), fileName);
            CustomSaveFile csf      = new CustomSaveFile(fileName);

            if (!csf.isValid())
            {
                Dbgl("invalid save name:" + filePath);
                yield break;
            }
            if (!File.Exists(filePath))
            {
                Dbgl("file does not exist:" + filePath);
                yield break;
            }

            isLoading = true;
            Dbgl("file exists " + filePath);
            Module <GameConfigModule> .Self.IgnoreCloseDoorAudio = true;

            Singleton <GameRunner> .Instance.Rest();

            Singleton <LoadingMask.Mgr> .Instance.Begin(null);

            yield return(null);

            Dbgl("starting load routine");
            Singleton <SleepTipMgr> .Self.SleepState(true);

            Dbgl("Checking if in game");
            int state = (int)typeof(GameMgr).GetField("state", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(Module <GameMgr> .Self);

            Dbgl("state: " + state);
            if (state != (int)typeof(GameMgr).GetNestedType("State", BindingFlags.NonPublic | BindingFlags.Instance).GetField("Max", BindingFlags.Static | BindingFlags.Public).GetValue(Module <GameMgr> .Self))
            {
                Dbgl("Terminating");
                Singleton <ModuleMgr> .Instance.Terminate();
            }
            else
            {
                Dbgl("not in game");
            }

            UIStateMgr.Instance.PopToState(UIStateMgr.StateType.Play, true);

            Dbgl("Initializing modules");
            Singleton <ModuleMgr> .Instance.Init();

            Dbgl("Setting state");
            AccessTools.FieldRefAccess <GameMgr, object>(Module <GameMgr> .Self, "state") = typeof(GameMgr).GetNestedType("State", BindingFlags.NonPublic | BindingFlags.Instance).GetField("LoadGame", BindingFlags.Static | BindingFlags.Public).GetValue(Module <GameMgr> .Self);
            Dbgl("state: " + AccessTools.FieldRefAccess <GameMgr, object>(Module <GameMgr> .Self, "state"));

            lastLoadedSave = csf;
            Module <ScenarioModule> .Self.EndLoadEventor += OnSceneLoaded;

            Dbgl("Loading Archive");
            if (!Singleton <Archive> .Instance.LoadArchive(filePath))
            {
                Dbgl("Load archive failed:" + filePath);
                Module <ScenarioModule> .Self.EndLoadEventor -= OnSceneLoaded;
                isLoading = false;
                yield break;
            }

            Dbgl("Starting story");
            Module <Story> .Self.Start();

            yield break;
        }