Example #1
0
        public bool TryLoadNewestWorld()
        {
            FileInfo fileInfo = (from wf in SavedWorldsDatabase.AllWorldFiles
                                 orderby wf.LastWriteTime descending
                                 select wf).FirstOrDefault <FileInfo>();

            if (fileInfo == null)
            {
                return(false);
            }

            SaveFileInfo saveFileInfo = new SaveFileInfo(fileInfo);

            if (VersionControl.BuildFromVersionString(saveFileInfo.GameVersion)
                != VersionControl.BuildFromVersionString(VersionControl.CurrentVersionFull))
            {
                return(false);
            }

            string fullName = fileInfo.FullName;

            WorldLoader.LoadWorldFromFile(fullName);

            if (!ModListsMatch(ScribeHeaderUtility.loadedModsList, (from mod in LoadedModManager.LoadedMods
                                                                    select mod.name).ToList()))
            {
                return(false);
            }

            return(true);
        }
Example #2
0
 public static int Compatibility(this ModMetaData mod, bool careAboutBuild = false)
 {
     if (mod.VersionCompatible)
     {
         if (careAboutBuild && VersionControl.CurrentBuild == VersionControl.BuildFromVersionString(mod.TargetVersion))
         {
             return(2);
         }
         return(1);
     }
     return(0);
 }
Example #3
0
        public override void PostExposeData(object obj)
        {
            if (Scribe.mode == LoadSaveMode.PostLoadInit)
            {
                int num = VersionControl.BuildFromVersionString(ScribeMetaHeaderUtility.loadedGameVersion);
                Pawn_RoyaltyTracker pawn_RoyaltyTracker;
                if ((pawn_RoyaltyTracker = (obj as Pawn_RoyaltyTracker)) != null && num <= 2575)
                {
                    foreach (RoyalTitle item in pawn_RoyaltyTracker.AllTitlesForReading)
                    {
                        item.conceited = RoyalTitleUtility.ShouldBecomeConceitedOnNewTitle(pawn_RoyaltyTracker.pawn);
                    }
                }
                Pawn_NeedsTracker pawn_NeedsTracker;
                if ((pawn_NeedsTracker = (obj as Pawn_NeedsTracker)) != null)
                {
                    pawn_NeedsTracker.AllNeeds.RemoveAll((Need n) => n.def.defName == "Authority");
                }
            }
            Pawn pawn;

            if ((pawn = (obj as Pawn)) == null)
            {
                return;
            }
            if (pawn.abilities == null)
            {
                pawn.abilities = new Pawn_AbilityTracker(pawn);
            }
            if (pawn.health != null)
            {
                if (pawn.health.hediffSet.hediffs.RemoveAll((Hediff x) => x == null) != 0)
                {
                    Log.Error(pawn.ToStringSafe() + " had some null hediffs.");
                }
                Hediff hediff = pawn.health?.hediffSet?.GetFirstHediffOfDef(HediffDefOf.PsychicHangover);
                if (hediff != null)
                {
                    pawn.health.hediffSet.hediffs.Remove(hediff);
                }
                Hediff firstHediffOfDef = pawn.health.hediffSet.GetFirstHediffOfDef(HediffDefOf.WakeUpTolerance);
                if (firstHediffOfDef != null)
                {
                    pawn.health.hediffSet.hediffs.Remove(firstHediffOfDef);
                }
                Hediff firstHediffOfDef2 = pawn.health.hediffSet.GetFirstHediffOfDef(HediffDefOf.GoJuiceTolerance);
                if (firstHediffOfDef2 != null)
                {
                    pawn.health.hediffSet.hediffs.Remove(firstHediffOfDef2);
                }
            }
        }
Example #4
0
 public static bool IsSaveCompatibleWith(string version)
 {
     if (VersionControl.BuildFromVersionString(version) == VersionControl.CurrentBuild)
     {
         return(true);
     }
     if (VersionControl.MajorFromVersionString(version) == 0 && VersionControl.CurrentMajor == 0)
     {
         int num          = VersionControl.MinorFromVersionString(version);
         int currentMinor = VersionControl.CurrentMinor;
         for (int i = 0; i < BackCompatibility.SaveCompatibleMinorVersions.Length; i++)
         {
             if (BackCompatibility.SaveCompatibleMinorVersions[i].First == num && BackCompatibility.SaveCompatibleMinorVersions[i].Second == currentMinor)
             {
                 return(true);
             }
         }
         return(false);
     }
     return(false);
 }
Example #5
0
 private static bool VersionsMatch()
 {
     return(VersionControl.BuildFromVersionString(loadedGameVersion) == VersionControl.BuildFromVersionString(VersionControl.CurrentVersionStringWithRev));
 }
Example #6
0
        public override void PostExposeData(object obj)
        {
            if (Scribe.mode == LoadSaveMode.PostLoadInit)
            {
                int num = VersionControl.BuildFromVersionString(ScribeMetaHeaderUtility.loadedGameVersion);
                Pawn_RoyaltyTracker pawn_RoyaltyTracker;
                if ((pawn_RoyaltyTracker = obj as Pawn_RoyaltyTracker) != null && num <= 2575)
                {
                    foreach (RoyalTitle item in pawn_RoyaltyTracker.AllTitlesForReading)
                    {
                        item.conceited = RoyalTitleUtility.ShouldBecomeConceitedOnNewTitle(pawn_RoyaltyTracker.pawn);
                    }
                }
                Pawn_NeedsTracker pawn_NeedsTracker;
                if ((pawn_NeedsTracker = obj as Pawn_NeedsTracker) != null)
                {
                    pawn_NeedsTracker.AllNeeds.RemoveAll((Need n) => n.def.defName == "Authority");
                }
            }
            Pawn pawn;
            Map  map;

            if ((pawn = obj as Pawn) != null)
            {
                if (pawn.abilities == null)
                {
                    pawn.abilities = new Pawn_AbilityTracker(pawn);
                }
                if (pawn.health != null)
                {
                    if (pawn.health.hediffSet.hediffs.RemoveAll((Hediff x) => x == null) != 0)
                    {
                        Log.Error(pawn.ToStringSafe() + " had some null hediffs.");
                    }
                    Hediff hediff = pawn.health?.hediffSet?.GetFirstHediffOfDef(HediffDefOf.PsychicHangover);
                    if (hediff != null)
                    {
                        pawn.health.hediffSet.hediffs.Remove(hediff);
                    }
                    Hediff firstHediffOfDef = pawn.health.hediffSet.GetFirstHediffOfDef(HediffDefOf.WakeUpTolerance);
                    if (firstHediffOfDef != null)
                    {
                        pawn.health.hediffSet.hediffs.Remove(firstHediffOfDef);
                    }
                    Hediff firstHediffOfDef2 = pawn.health.hediffSet.GetFirstHediffOfDef(HediffDefOf.GoJuiceTolerance);
                    if (firstHediffOfDef2 != null)
                    {
                        pawn.health.hediffSet.hediffs.Remove(firstHediffOfDef2);
                    }
                }
                if (pawn.equipment == null || pawn.apparel == null || pawn.inventory == null)
                {
                    return;
                }
                List <ThingWithComps> list = null;
                for (int i = 0; i < pawn.equipment.AllEquipmentListForReading.Count; i++)
                {
                    ThingWithComps thingWithComps = pawn.equipment.AllEquipmentListForReading[i];
                    if (thingWithComps.def.defName == "OrbitalTargeterBombardment" || thingWithComps.def.defName == "OrbitalTargeterPowerBeam" || thingWithComps.def.defName == "OrbitalTargeterMechCluster" || thingWithComps.def.defName == "TornadoGenerator")
                    {
                        list = list ?? new List <ThingWithComps>();
                        list.Add(thingWithComps);
                    }
                }
                if (list == null)
                {
                    return;
                }
                foreach (Apparel item2 in list)
                {
                    pawn.equipment.Remove(item2);
                    ResetVerbs(item2);
                    if (pawn.apparel.CanWearWithoutDroppingAnything(item2.def))
                    {
                        pawn.apparel.Wear(item2);
                    }
                    else
                    {
                        pawn.inventory.innerContainer.TryAdd(item2);
                    }
                }
            }
            else if (Scribe.mode == LoadSaveMode.LoadingVars && (map = obj as Map) != null && map.temporaryThingDrawer == null)
            {
                map.temporaryThingDrawer = new TemporaryThingDrawer();
            }
        }
Example #7
0
 private static bool VersionsMatch()
 {
     return(VersionControl.BuildFromVersionString(ScribeMetaHeaderUtility.loadedGameVersion) == VersionControl.BuildFromVersionString(VersionControl.CurrentVersionStringWithRev));
 }
        public static bool Prefix(bool __result, Action confirmedAction, ScribeMetaHeaderUtility.ScribeHeaderMode ___lastMode)
        {
            string message = null;
            string title   = null;

            if (!BackCompatibility.IsSaveCompatibleWith(ScribeMetaHeaderUtility.loadedGameVersion) &&
                // ScribeMetaHeaderUtility.VersionsMatch is private, it's component parts are not...
                VersionControl.BuildFromVersionString(ScribeMetaHeaderUtility.loadedGameVersion) != VersionControl.BuildFromVersionString(VersionControl.CurrentVersionStringWithRev))
            {
                title = "VersionMismatch".Translate();
                var loadedVersion = !ScribeMetaHeaderUtility.loadedGameVersion.NullOrEmpty() ? ScribeMetaHeaderUtility.loadedGameVersion : ("(" + "UnknownLower".Translate() + ")");
                switch (___lastMode)
                {
                case ScribeMetaHeaderUtility.ScribeHeaderMode.Map:
                    message = "SaveGameIncompatibleWarningText".Translate(loadedVersion, VersionControl.CurrentVersionString);
                    break;

                case ScribeMetaHeaderUtility.ScribeHeaderMode.World:
                    message = "WorldFileVersionMismatch".Translate(loadedVersion, VersionControl.CurrentVersionString);
                    break;

                default:
                    message = "FileIncompatibleWarning".Translate(loadedVersion, VersionControl.CurrentVersionString);
                    break;
                }
            }
            bool modMismatch = false;

            if (!ScribeMetaHeaderUtility.LoadedModsMatchesActiveMods(out string loadedMods, out string activeMods))
            {
                modMismatch = true;
                string modsMismatchMessage = "We're terribly sorry this message is so useless" + "ModsMismatchWarningText".Translate(loadedMods, activeMods);
                if (message == null)
                {
                    message = modsMismatchMessage;
                }
                else
                {
                    message = message + "\n\n" + modsMismatchMessage;
                }
                if (title == null)
                {
                    title = "ModsMismatchWarningTitle".Translate();
                }
            }
            if (message != null)
            {
                var dialog = Dialog_MessageBox.CreateConfirmation(message, confirmedAction, false, title);
                dialog.buttonAText = "LoadAnyway".Translate();

                if (modMismatch)
                {
                    dialog.buttonCText   = "ChangeLoadedMods".Translate();
                    dialog.buttonCAction = delegate()
                    {
                        // TODO: load mods from save game, mod manager style.
                        // Probably want to open the mod menu?
                        // ModsConfig.RestartFromChangedMods();
                    };
                }
                Find.WindowStack.Add(dialog);
                __result = true;
            }
            else
            {
                __result = false;
            }

            return(false);
        }
        public override void PostExposeData(object obj)
        {
            if (Scribe.mode == LoadSaveMode.LoadingVars)
            {
                Game game = obj as Game;
                if (game != null && game.questManager == null)
                {
                    game.questManager = new QuestManager();
                }
                Zone zone = obj as Zone;
                if (zone != null && zone.ID == -1)
                {
                    zone.ID = Find.UniqueIDsManager.GetNextZoneID();
                }
            }
            if (Scribe.mode != LoadSaveMode.PostLoadInit)
            {
                return;
            }
            Pawn pawn = obj as Pawn;

            if (pawn != null && pawn.royalty == null)
            {
                pawn.royalty = new Pawn_RoyaltyTracker(pawn);
            }
            Pawn_NativeVerbs pawn_NativeVerbs = obj as Pawn_NativeVerbs;

            if (pawn_NativeVerbs != null && pawn_NativeVerbs.verbTracker == null)
            {
                pawn_NativeVerbs.verbTracker = new VerbTracker(pawn_NativeVerbs);
            }
            Thing thing = obj as Thing;

            if (thing != null)
            {
                if (thing.def.defName == "Sandbags" && thing.Stuff == null)
                {
                    thing.SetStuffDirect(ThingDefOf.Cloth);
                }
                if (thing.def == ThingDefOf.MechCapsule)
                {
                    foreach (XmlNode oldCrashedShipPart in oldCrashedShipParts)
                    {
                        XmlElement xmlElement  = oldCrashedShipPart["def"];
                        XmlElement xmlElement2 = oldCrashedShipPart["id"];
                        if (xmlElement != null && xmlElement2 != null && Thing.IDNumberFromThingID(xmlElement2.InnerText) == thing.thingIDNumber)
                        {
                            upgradedCrashedShipParts.Add(new UpgradedCrashedShipPart
                            {
                                originalDefName = xmlElement.InnerText,
                                thing           = thing
                            });
                        }
                    }
                }
            }
            StoryWatcher storyWatcher = obj as StoryWatcher;

            if (storyWatcher != null)
            {
                if (storyWatcher.watcherAdaptation == null)
                {
                    storyWatcher.watcherAdaptation = new StoryWatcher_Adaptation();
                }
                if (storyWatcher.watcherPopAdaptation == null)
                {
                    storyWatcher.watcherPopAdaptation = new StoryWatcher_PopAdaptation();
                }
            }
            FoodRestrictionDatabase foodRestrictionDatabase = obj as FoodRestrictionDatabase;

            if (foodRestrictionDatabase != null && VersionControl.BuildFromVersionString(ScribeMetaHeaderUtility.loadedGameVersion) < 2057)
            {
                List <FoodRestriction> allFoodRestrictions = foodRestrictionDatabase.AllFoodRestrictions;
                for (int i = 0; i < allFoodRestrictions.Count; i++)
                {
                    allFoodRestrictions[i].filter.SetAllow(ThingCategoryDefOf.CorpsesHumanlike, allow: true);
                    allFoodRestrictions[i].filter.SetAllow(ThingCategoryDefOf.CorpsesAnimal, allow: true);
                }
            }
            SitePart sitePart = obj as SitePart;

            if (sitePart != null)
            {
                sitePart.hidden = sitePart.def.defaultHidden;
            }
        }