Exemple #1
0
        public static bool LoadFromFile(PrepareCarefully loadout, Page_ConfigureStartingPawnsCarefully charMakerPage, string colonistName)
        {
            string version = "";
            bool   result  = false;

            try {
                Scribe.InitLoading(ColonistFiles.FilePathForSavedColonist(colonistName));
                Scribe_Values.LookValue <string>(ref version, "version", "unknown", false);
            }
            catch (Exception e) {
                Log.Error("Failed to load preset file");
                throw e;
            }
            finally {
                Scribe.mode = LoadSaveMode.Inactive;
            }

            if ("2".Equals(version))
            {
                Messages.Message("EdB.PrepareCarefully.SavedColonistVersionNotSupported".Translate(), MessageSound.SeriousAlert);
                return(false);
            }
            else if ("3".Equals(version))
            {
                result = new ColonistLoaderVersion3().Load(loadout, charMakerPage, colonistName);
            }
            else
            {
                throw new Exception("Invalid preset version");
            }

            return(result);
        }
Exemple #2
0
        public CustomPawn Load(PrepareCarefully loadout, string name)
        {
            SaveRecordPawnV3 pawnRecord = new SaveRecordPawnV3();
            string           modString  = "";
            string           version    = "";

            try {
                Scribe.loader.InitLoading(ColonistFiles.FilePathForSavedColonist(name));
                Scribe_Values.Look <string>(ref version, "version", "unknown", false);
                Scribe_Values.Look <string>(ref modString, "mods", "", false);

                try {
                    Scribe_Deep.Look <SaveRecordPawnV3>(ref pawnRecord, "colonist", null);
                }
                catch (Exception e) {
                    Messages.Message(modString, MessageTypeDefOf.SilentInput);
                    Messages.Message("EdB.PC.Dialog.PawnPreset.Error.Failed".Translate(), MessageTypeDefOf.RejectInput);
                    Log.Warning(e.ToString());
                    Log.Warning("Colonist was created with the following mods: " + modString);
                    return(null);
                }
            }
            catch (Exception e) {
                Log.Error("Failed to load preset file");
                throw e;
            }
            finally {
                PresetLoader.ClearSaveablesAndCrossRefs();
            }

            if (pawnRecord == null)
            {
                Messages.Message(modString, MessageTypeDefOf.SilentInput);
                Messages.Message("EdB.PC.Dialog.PawnPreset.Error.Failed".Translate(), MessageTypeDefOf.RejectInput);
                Log.Warning("Colonist was created with the following mods: " + modString);
                return(null);
            }

            PresetLoaderVersion3 loader     = new PresetLoaderVersion3();
            CustomPawn           loadedPawn = loader.LoadPawn(pawnRecord);

            if (loadedPawn != null)
            {
                CustomPawn idConflictPawn = PrepareCarefully.Instance.Pawns.FirstOrDefault((CustomPawn p) => {
                    return(p.Id == loadedPawn.Id);
                });
                if (idConflictPawn != null)
                {
                    loadedPawn.GenerateId();
                }
                return(loadedPawn);
            }
            else
            {
                loadout.State.AddError(loader.ModString);
                loadout.State.AddError("EdB.PC.Dialog.Preset.Error.NoCharacter".Translate());
                Log.Warning("Preset was created with the following mods: " + modString);
                return(null);
            }
        }
        public static CustomPawn LoadFromFile(PrepareCarefully loadout, string name)
        {
            string version = "";

            try {
                Scribe.loader.InitLoading(ColonistFiles.FilePathForSavedColonist(name));
                Scribe_Values.Look <string>(ref version, "version", "unknown", false);
            }
            catch (Exception e) {
                Log.Error("Failed to load preset file");
                throw e;
            }
            finally {
                Scribe.mode = LoadSaveMode.Inactive;
            }

            if ("2".Equals(version))
            {
                Messages.Message("EdB.PC.Dialog.PawnPreset.Error.PreAlpha13NotSupported".Translate(), MessageTypeDefOf.ThreatBig);
                return(null);
            }
            else if ("3".Equals(version))
            {
                return(new ColonistLoaderVersion3().Load(loadout, name));
            }
            else
            {
                throw new Exception("Invalid preset version");
            }
        }
        public bool Load(PrepareCarefully loadout, Page_ConfigureStartingPawnsCarefully charMakerPage, string colonistName)
        {
            SaveRecordPawnV3 pawnRecord = new SaveRecordPawnV3();
            string           modString  = "";
            string           version    = "";

            try {
                Scribe.InitLoading(ColonistFiles.FilePathForSavedColonist(colonistName));
                Scribe_Values.LookValue <string>(ref version, "version", "unknown", false);
                Scribe_Values.LookValue <string>(ref modString, "mods", "", false);

                try {
                    Scribe_Deep.LookDeep <SaveRecordPawnV3>(ref pawnRecord, "colonist", null);
                }
                catch (Exception e) {
                    Messages.Message(modString, MessageSound.Silent);
                    Messages.Message("EdB.ColonistLoadFailed".Translate(), MessageSound.RejectInput);
                    Log.Warning(e.ToString());
                    Log.Warning("Colonist was created with the following mods: " + modString);
                    return(false);
                }
            }
            catch (Exception e) {
                Log.Error("Failed to load preset file");
                throw e;
            }
            finally {
                Scribe.mode = LoadSaveMode.Inactive;
            }

            PresetLoaderVersion3 loader = new PresetLoaderVersion3();

            charMakerPage.AddColonist(loader.LoadPawn(pawnRecord));
            if (loader.Failed)
            {
                Messages.Message(loader.ModString, MessageSound.Silent);
                Messages.Message("EdB.ColonistThingDefFailed".Translate(), MessageSound.SeriousAlert);
                Log.Warning("Preset was created with the following mods: " + modString);
                return(false);
            }

            return(true);
        }
Exemple #5
0
        public CustomPawn Load(PrepareCarefully loadout, string name)
        {
            SaveRecordPawnV5 pawnRecord = new SaveRecordPawnV5();
            string           modString  = "";
            string           version    = "";

            try {
                Scribe.loader.InitLoading(ColonistFiles.FilePathForSavedColonist(name));
                Scribe_Values.Look <string>(ref version, "version", "unknown", false);
                Scribe_Values.Look <string>(ref modString, "mods", "", false);

                try {
                    Scribe_Deep.Look <SaveRecordPawnV5>(ref pawnRecord, "pawn", null);
                }
                catch (Exception e) {
                    Messages.Message(modString, MessageTypeDefOf.SilentInput);
                    Messages.Message("EdB.PC.Dialog.PawnPreset.Error.Failed".Translate(), MessageTypeDefOf.RejectInput);
                    Log.Warning(e.ToString());
                    Log.Warning("Colonist was created with the following mods: " + modString);
                    return(null);
                }
            }
            catch (Exception e) {
                Log.Error("Failed to load preset file");
                throw e;
            }
            finally {
                PresetLoader.ClearSaveablesAndCrossRefs();
            }

            if (pawnRecord == null)
            {
                Messages.Message(modString, MessageTypeDefOf.SilentInput);
                Messages.Message("EdB.PC.Dialog.PawnPreset.Error.Failed".Translate(), MessageTypeDefOf.RejectInput);
                Log.Warning("Colonist was created with the following mods: " + modString);
                return(null);
            }

            CustomPawn pawn = ConvertSaveRecordToPawn(pawnRecord);

            return(pawn);
        }
        //
        // Static Methods
        //
        public static void SaveToFile(PrepareCarefully loadout, Page_ConfigureStartingPawnsCarefully page, string colonistName)
        {
            try {
                Scribe.InitWriting(ColonistFiles.FilePathForSavedColonist(colonistName), "colonist");
                string versionStringFull = "3";
                Scribe_Values.LookValue <string>(ref versionStringFull, "version", null, false);
                string modString = GenText.ToCommaList(Enumerable.Select <ModContentPack, string>(LoadedModManager.RunningMods, (Func <ModContentPack, string>)(mod => mod.Name)), true);
                Scribe_Values.LookValue <string>(ref modString, "mods", null, false);

                SaveRecordPawnV3 pawn = new SaveRecordPawnV3(page.SelectedPawn);
                Scribe_Deep.LookDeep <SaveRecordPawnV3>(ref pawn, "colonist");
            }
            catch (Exception e) {
                Log.Error("Failed to save preset file");
                throw e;
            }
            finally {
                Scribe.FinalizeWriting();
                Scribe.mode = LoadSaveMode.Inactive;
            }
        }
        //
        // Static Methods
        //
        public static void SaveToFile(CustomPawn customPawn, string colonistName)
        {
            try {
                Scribe.saver.InitSaving(ColonistFiles.FilePathForSavedColonist(colonistName), "character");
                string versionStringFull = "4";
                Scribe_Values.Look <string>(ref versionStringFull, "version", null, false);
                string modString = GenText.ToCommaList(Enumerable.Select <ModContentPack, string>(LoadedModManager.RunningMods, (Func <ModContentPack, string>)(mod => mod.Name)), true);
                Scribe_Values.Look <string>(ref modString, "mods", null, false);

                SaveRecordPawnV4 pawn = new SaveRecordPawnV4(customPawn);
                Scribe_Deep.Look <SaveRecordPawnV4>(ref pawn, "pawn");
            }
            catch (Exception e) {
                Log.Error("Failed to save preset file");
                throw e;
            }
            finally {
                Scribe.saver.FinalizeSaving();
                Scribe.mode = LoadSaveMode.Inactive;
            }
        }
Exemple #8
0
        public CustomPawn Load(PrepareCarefully loadout, string name)
        {
            SaveRecordPawnV3 pawnRecord = new SaveRecordPawnV3();
            string           modString  = "";
            string           version    = "";

            try {
                Scribe.loader.InitLoading(ColonistFiles.FilePathForSavedColonist(name));
                Scribe_Values.Look <string>(ref version, "version", "unknown", false);
                Scribe_Values.Look <string>(ref modString, "mods", "", false);

                try {
                    Scribe_Deep.Look <SaveRecordPawnV3>(ref pawnRecord, "colonist", null);
                }
                catch (Exception e) {
                    Messages.Message(modString, MessageTypeDefOf.SilentInput);
                    Messages.Message("EdB.PC.Dialog.PawnPreset.Error.Failed".Translate(), MessageTypeDefOf.RejectInput);
                    Log.Warning(e.ToString());
                    Log.Warning("Colonist was created with the following mods: " + modString);
                    return(null);
                }
            }
            catch (Exception e) {
                Log.Error("Failed to load preset file");
                throw e;
            }
            finally {
                // I don't fully understand how these cross-references and saveables are resolved, but
                // if we don't clear them out, we get null pointer exceptions.
                HashSet <IExposable> saveables = (HashSet <IExposable>)(typeof(PostLoadIniter).GetField("saveablesToPostLoad", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(Scribe.loader.initer));
                saveables.Clear();
                List <IExposable> crossReferencingExposables = (List <IExposable>)(typeof(CrossRefHandler).GetField("crossReferencingExposables", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(Scribe.loader.crossRefs));
                crossReferencingExposables.Clear();
                Scribe.loader.FinalizeLoading();
            }

            if (pawnRecord == null)
            {
                Messages.Message(modString, MessageTypeDefOf.SilentInput);
                Messages.Message("EdB.PC.Dialog.PawnPreset.Error.Failed".Translate(), MessageTypeDefOf.RejectInput);
                Log.Warning("Colonist was created with the following mods: " + modString);
                return(null);
            }

            PresetLoaderVersion3 loader     = new PresetLoaderVersion3();
            CustomPawn           loadedPawn = loader.LoadPawn(pawnRecord);

            if (loadedPawn != null)
            {
                CustomPawn idConflictPawn = PrepareCarefully.Instance.Pawns.FirstOrDefault((CustomPawn p) => {
                    return(p.Id == loadedPawn.Id);
                });
                if (idConflictPawn != null)
                {
                    loadedPawn.GenerateId();
                }
                return(loadedPawn);
            }
            else
            {
                loadout.State.AddError(loader.ModString);
                loadout.State.AddError("EdB.PC.Dialog.Preset.Error.NoCharacter".Translate());
                Log.Warning("Preset was created with the following mods: " + modString);
                return(null);
            }
        }