Beispiel #1
0
        /**
         * This deserializes a byte stream we've retrieved from other sources (used on the main menu)
         */
        public static bool LoadFromBytes(byte[] bytes, out DeathRunSaveData target)
        {
            try
            {
                string @jsonData = Encoding.UTF8.GetString(bytes);

                var jsonSerializerSettings = new JsonSerializerSettings
                {
                    MissingMemberHandling = MissingMemberHandling.Ignore,
                    NullValueHandling     = NullValueHandling.Ignore,
                };


                // This deserializes the whole saveData object all at once.
                target = JsonConvert.DeserializeObject <DeathRunSaveData>(jsonData, jsonSerializerSettings);
            }
            catch (Exception e)
            {
                CattleLogger.GenericError(e);
                CattleLogger.Message("Death Run thumbnail data not found - using defaults");
                CattleLogger.Message(e.StackTrace);

                target = null;
                return(false);
            }

            return(true);
        }
Beispiel #2
0
        public void Save()
        {
            string saveDirectory = SaveUtils.GetCurrentSaveDataDir();

            DeathRun.saveData.countSave.AboutToSaveGame();
            DeathRun.saveData.playerSave.AboutToSaveGame();

            try
            {
                var settings = new JsonSerializerSettings
                {
                    NullValueHandling     = NullValueHandling.Ignore,
                    ReferenceLoopHandling = ReferenceLoopHandling.Ignore, // Keeps our Vector3's etc from generating infinite references
                    //PreserveReferencesHandling = PreserveReferencesHandling.Objects
                };

                var saveDataJson = JsonConvert.SerializeObject(this, Formatting.Indented, settings);

                if (!Directory.Exists(saveDirectory))
                {
                    Directory.CreateDirectory(saveDirectory);
                }

                File.WriteAllText(Path.Combine(saveDirectory, DeathRun.SaveFile), saveDataJson);
            }
            catch (Exception e)
            {
                CattleLogger.GenericError(e);
                CattleLogger.Message("Failed");
            }
        }
Beispiel #3
0
        public void SaveStats()
        {
            if (DeathRun.patchFailed)
            {
                return;
            }

            Version = DeathRunUtils.VERSION;

            try
            {
                var settings = new JsonSerializerSettings
                {
                    NullValueHandling     = NullValueHandling.Ignore,
                    ReferenceLoopHandling = ReferenceLoopHandling.Ignore, // Keeps our Vector3's etc from generating infinite references
                    //PreserveReferencesHandling = PreserveReferencesHandling.Objects
                };

                var statsDataJson = JsonConvert.SerializeObject(this, Formatting.Indented, settings);

                File.WriteAllText(Path.Combine(DeathRun.modFolder, DeathRun.StatsFile), statsDataJson);
            }
            catch (Exception e)
            {
                CattleLogger.GenericError(e);
                CattleLogger.Message("Failed");
            }
        }
Beispiel #4
0
        public void Load()
        {
            var path = Path.Combine(SaveUtils.GetCurrentSaveDataDir(), DeathRun.SaveFile);

            if (!File.Exists(path))
            {
                CattleLogger.Message("Death Run data not found - using defaults");
                setDefaults();
                return;
            }

            try
            {
                var save = File.ReadAllText(path);

                var jsonSerializerSettings = new JsonSerializerSettings
                {
                    MissingMemberHandling = MissingMemberHandling.Ignore,
                    NullValueHandling     = NullValueHandling.Ignore,
                    //PreserveReferencesHandling = PreserveReferencesHandling.Objects,
                };

                //var json = JsonConvert.DeserializeObject<DeathRunSaveData>(save, jsonSerializerSettings);
                //this.exampleString = json.exampleString;
                //this.exampleData = json.exampleData;

                // This deserializes the whole saveData object all at once.
                DeathRun.saveData = JsonConvert.DeserializeObject <DeathRunSaveData>(save, jsonSerializerSettings);

                DeathRun.saveData.countSave.JustLoadedGame();
                DeathRun.saveData.playerSave.JustLoadedGame();

                // Special escape-pod re-adjustments
                EscapePod_FixedUpdate_Patch.JustLoadedGame();

                DeathRunUtils.JustLoadedGame();
            }
            catch (Exception e)
            {
                CattleLogger.GenericError(e);
                CattleLogger.Message("Death Run data not found - using defaults");
                CattleLogger.Message(e.StackTrace);
                setDefaults();
            }
        }
Beispiel #5
0
        public static bool Prefix(DamageType damageType)
        {
            try
            {
                setCauseOfDeath(damageType);

                DeathRun.saveData.playerSave.numDeaths++;

                DeathRun.saveData.playerSave.timeOfDeath = DayNightCycle.main.timePassedAsFloat;
                DeathRun.saveData.playerSave.spanAtDeath = DeathRun.saveData.playerSave.allLives;

                TimeSpan timeSpan = TimeSpan.FromSeconds((double)DeathRun.saveData.playerSave.currentLife);

                string text = "Time of Death";
                if (DeathRun.saveData.playerSave.numDeaths > 1)
                {
                    text += " #" + DeathRun.saveData.playerSave.numDeaths;
                }
                text += ": ";

                text += DeathRunUtils.sayTime(timeSpan);

                DeathRunUtils.CenterMessage(text, 10);
                CattleLogger.Message(text);

                text = "Cause of Death: " + DeathRun.cause;
                DeathRunUtils.CenterMessage(text, 10, 1);

                //ErrorMessage.AddMessage(text);

                DeathRun.saveData.playerSave.killOpening = true;
                DeathRun.saveData.runData.updateVitals(false);

                DeathRun.saveData.nitroSave.setDefaults(); // Reset all nitrogen state

                DeathRun.playerIsDead = true;
            }
            catch (Exception ex)
            {
                CattleLogger.GenericError("During Player.OnKill - ", ex);
            }

            return(true);
        }
Beispiel #6
0
        public static void RegisterSave(string slotName, DeathRunSaveData saveData)
        {
            DeathRunSaveData already = new DeathRunSaveData();

            if (saveList.TryGetValue(slotName, out already))
            {
                saveList.Remove(slotName);
            }

            try
            {
                saveList.Add(slotName, saveData);
            }
            catch (Exception ex)
            {
                CattleLogger.Message("Failed to add to dictionary");
                CattleLogger.GenericError(ex);
            }
        }
Beispiel #7
0
        public void LoadStats()
        {
            var path = Path.Combine(DeathRun.modFolder, DeathRun.StatsFile);

            if (!File.Exists(path))
            {
                CattleLogger.Message("Death Run `Stats` data not found - starting new Stats");
                setDefaults();
                SaveStats();
                return;
            }

            try
            {
                var save = File.ReadAllText(path);

                var jsonSerializerSettings = new JsonSerializerSettings
                {
                    MissingMemberHandling = MissingMemberHandling.Ignore,
                    NullValueHandling     = NullValueHandling.Ignore,
                    //PreserveReferencesHandling = PreserveReferencesHandling.Objects,
                };

                // This deserializes the whole statsData object all at once.
                DeathRun.statsData = JsonConvert.DeserializeObject <DeathRunStats>(save, jsonSerializerSettings);

                DeathRun.statsData.JustLoadedStats();
            }
            catch (Exception e)
            {
                CattleLogger.GenericError(e);
                CattleLogger.Message("Death Run Stats not found - starting new Stats");
                CattleLogger.Message(e.StackTrace);
                setDefaults();
                SaveStats();
            }
        }
Beispiel #8
0
        static void setCauseOfDeath(DamageType damageType)
        {
            try
            {
                switch (damageType)
                {
                case DamageType.Acid:
                    DeathRun.setCause("Acid");
                    break;

                case DamageType.Collide:
                    DeathRun.setCause("Collision");
                    break;

                case DamageType.Electrical:
                    DeathRun.setCause("Electrocution");
                    break;

                case DamageType.Explosive:
                    DeathRun.setCause("Explosion");
                    break;

                case DamageType.Fire:
                    DeathRun.setCause("Burned to Death");
                    break;

                case DamageType.Heat:
                    DeathRun.setCause("Extreme Heat");
                    break;

                case DamageType.Poison:
                    DeathRun.setCause("Poison");
                    break;

                case DamageType.Pressure:
                    DeathRun.setCause("Pressure");
                    break;

                case DamageType.Puncture:
                    DeathRun.setCause("Puncture Wounds");
                    break;

                case DamageType.Radiation:
                    DeathRun.setCause("Radiation");
                    break;

                case DamageType.Smoke:
                    DeathRun.setCause("Smoke Asphyxiation");
                    break;

                //case DamageType.Starve:
                //case DamageType.Normal:
                default:
                    if (DeathRun.CAUSE_UNKNOWN_CREATURE.Equals(DeathRun.cause))
                    {
                        if (DeathRun.causeObject != null)
                        {
                            GameObject go;
                            TechType   t = CraftData.GetTechType(DeathRun.causeObject, out go);

                            if (t != TechType.None)
                            {
                                DeathRun.setCause(Language.main.Get(t.AsString(false)));

                                CattleLogger.Message("Cause of Death: " + DeathRun.cause);
                            }
                            else
                            {
                                CattleLogger.Message("(Couldn't find creature that caused player death) - ");
                            }
                        }
                    }
                    break;
                }
            }
            catch (Exception ex)
            {
                CattleLogger.GenericError("Getting cause of death", ex);
            }
        }