Ejemplo n.º 1
0
        public static Blueprint LoadFromFile(string fileName)
        {
            Blueprint blueprint = new Blueprint();

            try
            {
                Scribe.InitLoading(BlueprintFiles.FilePathForSavedBlueprint(fileName));
                try
                {
                    Scribe_Deep.LookDeep(ref blueprint, "Blueprint", null);
                }
                catch (Exception e)
                {
                    Messages.Message("Error when loading blueprint", MessageSound.RejectInput);
                    Log.Error(e.ToString());
                }
            }
            catch (Exception e)
            {
                Log.Error(e.ToString());
            }
            finally
            {
                Scribe.mode = LoadSaveMode.Inactive;
            }
            return(blueprint);
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
        public static PathDataLog LoadFromFile(string filename)
        {
            var pathData = new PathDataLog();

            try
            {
                Scribe.InitLoading(filename);
                ScribeMetaHeaderUtility.LoadGameDataHeader(ScribeMetaHeaderUtility.ScribeHeaderMode.Map, false);
                Scribe.EnterNode("PathData");
                pathData.ExposeData();
                Scribe.ExitNode();
            }
            catch (Exception e)
            {
                Log.Error("Exception while loading: " + e);
            }
            finally
            {
                // done loading
                Scribe.FinalizeLoading();
                Scribe.mode = LoadSaveMode.Inactive;
            }

            return(pathData);
        }
        private void DoImport(SaveFileInfo file)
        {
            try
            {
                // load stuff
                Scribe.InitLoading(_folder + "/" + file.FileInfo.Name);
                Manager.LoadSaveMode = Manager.Modes.ImportExport;
                ScribeMetaHeaderUtility.LoadGameDataHeader(ScribeMetaHeaderUtility.ScribeHeaderMode.Map, false);
                Scribe.EnterNode("JobStack");
                _jobStackIO.ExposeData();
                Scribe.ExitNode();
                Scribe.FinalizeLoading();

                // resolve crossreferences
                // these are registered during the loading stage, and cleared afterwards
                // will most definitely give errors/warnings on crossgame imports
                CrossRefResolver.ResolveAllCrossReferences();

                // replace the old jobstack
                Manager.For(manager).NewJobStack(_jobStackIO);

                // remove invalid jobs
                var invalid = 0;
                foreach (ManagerJob job in Manager.For(manager).JobStack.FullStack())
                {
                    if (!job.IsValid)
                    {
                        invalid++;
                        job.Delete(false);
                    }
                }

                // provide some feedback on failed import(s)
                // if debug is enabled the screen will also pop up with reference errors.
                if (invalid > 0)
                {
                    Messages.Message("FM.InvalidJobsDeleted".Translate(invalid), MessageSound.SeriousAlert);
                }
            }
            catch (Exception e)
            {
                Log.Error("Exception while loading jobstack: " + e);
            }
            finally
            {
                // done?
                Scribe.mode          = LoadSaveMode.Inactive;
                Manager.LoadSaveMode = Manager.Modes.Normal;
                Messages.Message("FM.JobsImported".Translate(_jobStackIO.FullStack().Count), MessageSound.Standard);
                Refresh();
            }
        }
        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);
        }
Ejemplo n.º 6
0
        internal static Blueprint LoadFromXML(SaveFileInfo file)
        {
            // set up empty blueprint
            Blueprint blueprint = new Blueprint();

#if DEBUG
            Log.Message("Attempting to load from: " + file.FileInfo.FullName);
#endif

            // load stuff
            try
            {
                Scribe.InitLoading(BlueprintSaveLocation + "/" + file.FileInfo.Name);
                ScribeMetaHeaderUtility.LoadGameDataHeader(ScribeMetaHeaderUtility.ScribeHeaderMode.Map, true);
                Scribe.EnterNode("Blueprint");
                blueprint.ExposeData();
                Scribe.ExitNode();
            }
            catch (Exception e)
            {
                Log.Error("Exception while loading blueprint: " + e);
            }
            finally
            {
                // done loading
                Scribe.FinalizeLoading();
                Scribe.mode = LoadSaveMode.Inactive;
            }

            // if a def used in the blueprint doesn't exist, exposeData will throw an error,
            // which is fine. in addition, it'll set the field to null - which may result in problems down the road.
            // Make sure each item in the blueprint has a def set, if not - remove it.
            // This check itself will throw another error, which is also fine. User will have to resolve the issue manually.
            blueprint.contents = blueprint.contents.Where(item => item.BuildableDef != null).ToList();

            // return blueprint.
            return(blueprint);
        }
Ejemplo n.º 7
0
        public static void load(ref List <Thing> thingsToLoad, string fileLocation, Thing currentSource)
        {
            Log.Message("ScribeINIT, loding from:" + fileLocation);
            Scribe.InitLoading(fileLocation);

            //Scribe.EnterNode("Stargate");

            Log.Message("DeepProfiler.Start()");
            DeepProfiler.Start("Load non-compressed things");

            // List<Thing> list2 = (List<Thing>)null;
            Log.Message("Scribe_Collections.LookList");
            Scribe_Collections.LookList <Thing>(ref thingsToLoad, "things", LookMode.Deep);
            Log.Message("List1Count:" + thingsToLoad.Count);

            Log.Message("DeepProfiler.End()");
            DeepProfiler.End();

            //Scribe.ExitNode();
            Scribe.mode = LoadSaveMode.Inactive;

            //Log.Message("list: " + thingsToLoad.Count.ToString());


            Log.Message("Exit Node");
            //Scribe.ExitNode();


            Log.Message("ResolveAllCrossReferences");
            CrossRefResolver.ResolveAllCrossReferences();


            Log.Message("DoAllPostLoadInits");
            PostLoadInitter.DoAllPostLoadInits();

            Log.Message("Return");
        }
Ejemplo n.º 8
0
        public static void LoadHostData(MCMHost host)
        {
            var filePath = HostFilePath(host);

            if (!File.Exists(filePath))
            {
                return;
            }

            try
            {
                // Open it for reading
                Scribe.InitLoading(filePath);
                if (Scribe.mode == LoadSaveMode.LoadingVars)
                {
                    // Version check
                    string version = "";
                    Scribe_Values.LookValue <string>(ref version, "ccl_version");

                    bool okToLoad = true;
                    var  result   = Version.Compare(version);
                    if (result == Version.VersionCompare.GreaterThanMax)
                    {
                        CCL_Log.Trace(
                            Verbosity.NonFatalErrors,
                            string.Format("Data for {0} is newer ({1}) than the version you are using ({2}).", host.Label, version, Version.Current.ToString()),
                            "Mod Configuration Menu");
                        okToLoad = false;
                    }
                    else if (result == Version.VersionCompare.Invalid)
                    {
                        CCL_Log.Trace(
                            Verbosity.NonFatalErrors,
                            string.Format("Data for {0} is corrupt and will be discarded", host.Label),
                            "Mod Configuration Menu");
                        okToLoad = false;
                    }

                    if (okToLoad)
                    {
                        // Call the worker scribe
                        var args = new object[]
                        {
                            host.Label,
                            host.worker
                        };
                        Scribe_Deep.LookDeep <MCMHost>(ref host, host.key, args);
                    }
                }
            }
            catch (Exception e)
            {
                CCL_Log.Trace(
                    Verbosity.NonFatalErrors,
                    string.Format("Unexpected error scribing data for mod {0}\n{1}", host.Label, e.ToString()),
                    "Mod Configuration Menu");
            }
            finally
            {
                // Finish
                Scribe.FinalizeLoading();
                Scribe.mode = LoadSaveMode.Inactive;
            }
        }
Ejemplo n.º 9
0
        public bool Load(PrepareCarefully loadout, string presetName)
        {
            List <SaveRecordPawnV3>         pawns = new List <SaveRecordPawnV3>();
            List <SaveRecordRelationshipV3> savedRelationships = new List <SaveRecordRelationshipV3>();

            Failed = false;
            int  startingPoints = 0;
            bool usePoints      = false;

            try {
                Scribe.InitLoading(PresetFiles.FilePathForSavedPreset(presetName));

                Scribe_Values.LookValue <bool>(ref usePoints, "usePoints", true, false);
                Scribe_Values.LookValue <int>(ref startingPoints, "startingPoints", 0, false);
                Scribe_Values.LookValue <string>(ref ModString, "mods", "", false);

                try {
                    Scribe_Collections.LookList <SaveRecordPawnV3>(ref pawns, "colonists", LookMode.Deep, null);
                }
                catch (Exception e) {
                    Messages.Message(ModString, MessageSound.Silent);
                    Messages.Message("EdB.PresetPawnLoadFailed".Translate(), MessageSound.SeriousAlert);
                    Log.Warning(e.ToString());
                    Log.Warning("Preset was created with the following mods: " + ModString);
                    return(false);
                }

                try {
                    Scribe_Collections.LookList <SaveRecordRelationshipV3>(ref savedRelationships, "relationships", LookMode.Deep, null);
                }
                catch (Exception e) {
                    Messages.Message(ModString, MessageSound.Silent);
                    Messages.Message("EdB.PresetPawnLoadFailed".Translate(), MessageSound.SeriousAlert);
                    Log.Warning(e.ToString());
                    Log.Warning("Preset was created with the following mods: " + ModString);
                    return(false);
                }

                List <LoadableEquipment> tempEquipment = new List <LoadableEquipment>();
                Scribe_Collections.LookList <LoadableEquipment>(ref tempEquipment, "equipment", LookMode.Deep, null);

                List <SelectedEquipment> equipment = new List <SelectedEquipment>(tempEquipment.Count);
                foreach (var e in tempEquipment)
                {
                    ThingDef thingDef = DefDatabase <ThingDef> .GetNamedSilentFail(e.def);

                    ThingDef stuffDef = null;
                    Gender   gender   = Gender.None;
                    if (!string.IsNullOrEmpty(e.stuffDef))
                    {
                        stuffDef = DefDatabase <ThingDef> .GetNamedSilentFail(e.stuffDef);
                    }
                    if (!string.IsNullOrEmpty(e.gender))
                    {
                        try {
                            gender = (Gender)Enum.Parse(typeof(Gender), e.gender);
                        }
                        catch (Exception) {
                            Log.Warning("Failed to load gender value for animal.");
                            Failed = true;
                            continue;
                        }
                    }
                    if (thingDef != null)
                    {
                        if (string.IsNullOrEmpty(e.stuffDef))
                        {
                            equipment.Add(new SelectedEquipment(thingDef, null, gender, e.count));
                        }
                        else
                        {
                            if (stuffDef != null)
                            {
                                EquipmentDatabaseEntry entry = PrepareCarefully.Instance.EquipmentEntries[new EquipmentKey(thingDef, stuffDef, gender)];
                                if (entry == null)
                                {
                                    string thing = thingDef != null ? thingDef.defName : "null";
                                    string stuff = stuffDef != null ? stuffDef.defName : "null";
                                    Log.Warning(string.Format("Could not load equipment/resource from the preset.  This may be caused by an invalid thing/stuff combination. (thing = {0}, stuff={1})", thing, stuff));
                                    Failed = true;
                                    continue;
                                }
                                else
                                {
                                    equipment.Add(new SelectedEquipment(thingDef, stuffDef, gender, e.count));
                                }
                            }
                            else
                            {
                                Log.Warning("Could not load stuff definition \"" + e.stuffDef + "\" for item \"" + e.def + "\"");
                                Failed = true;
                            }
                        }
                    }
                    else
                    {
                        Log.Warning("Could not load thing definition \"" + e.def + "\"");
                        Failed = true;
                    }
                }
                loadout.Equipment.Clear();
                foreach (var e in equipment)
                {
                    loadout.Equipment.Add(e);
                }

                // After loading items using the Scribe methods, the saveables that were loaded get
                // put into this saveablesToPostLoad map.  This post-load initialization is only
                // applicable for when we load a save game.  We need to clear our saveables out of
                // there so that they don't cause errors later.
                HashSet <IExposable> saveables = (HashSet <IExposable>)(typeof(PostLoadInitter).GetField("saveablesToPostLoad", BindingFlags.NonPublic | BindingFlags.Static).GetValue(null));
                saveables.Clear();

                //PrepareCarefully.Instance.Config.pointsEnabled = usePoints;
            }
            catch (Exception e) {
                Log.Error("Failed to load preset file");
                throw e;
            }
            finally {
                Scribe.mode = LoadSaveMode.Inactive;
            }

            List <CustomPawn> pawnModels = new List <CustomPawn>();

            try {
                foreach (SaveRecordPawnV3 p in pawns)
                {
                    pawnModels.Add(LoadPawn(p));
                }
            }
            catch (Exception e) {
                Messages.Message(ModString, MessageSound.Silent);
                Messages.Message("EdB.PresetPawnLoadFailed".Translate(), MessageSound.SeriousAlert);
                Log.Warning(e.ToString());
                Log.Warning("Preset was created with the following mods: " + ModString);
                return(false);
            }


            List <CustomRelationship> relationships = new List <CustomRelationship>();

            try {
                foreach (SaveRecordRelationshipV3 r in savedRelationships)
                {
                    CustomRelationship relationship = LoadRelationship(r, pawnModels);
                    if (relationship == null)
                    {
                        Messages.Message(ModString, MessageSound.Silent);
                        Messages.Message("EdB.PresetRelationshipLoadFailed".Translate(), MessageSound.SeriousAlert);
                        Log.Warning("Failed to load relationship: " + r.relation);
                        Log.Warning("Preset was created with the following mods: " + ModString);
                    }
                    else
                    {
                        relationships.Add(relationship);
                    }
                }
            }
            catch (Exception e) {
                Messages.Message(ModString, MessageSound.Silent);
                Messages.Message("EdB.PresetRelationshipLoadFailed".Translate(), MessageSound.SeriousAlert);
                Log.Warning(e.ToString());
                Log.Warning("Preset was created with the following mods: " + ModString);
                return(false);
            }

            loadout.ClearPawns();
            foreach (CustomPawn p in pawnModels)
            {
                loadout.AddPawn(p);
            }

            loadout.RelationshipManager.Clear();
            foreach (CustomRelationship r in relationships)
            {
                loadout.RelationshipManager.AddRelationship(r.def, r.source, r.target);
            }

            if (Failed)
            {
                Messages.Message(ModString, MessageSound.Silent);
                Messages.Message("EdB.PresetThingDefFailed".Translate(), MessageSound.SeriousAlert);
                Log.Warning("Preset was created with the following mods: " + ModString);
                return(false);
            }

            return(true);
        }