FINDarkside / TLD-Save-Editor

Edit The Long Dark save files
http://www.moddb.com/mods/the-long-dark-save-editor-2/downloads
MIT License
76 stars 31 forks source link

Bug. If you do not remove the frostbite (or even frostbite risk) save editor crashes. #19

Closed Pt-Djefferson closed 4 years ago

Pt-Djefferson commented 4 years ago

Quick fix: AfflictionsContainer.cs =>

            var frostbiteRisks = afflictionDict.GetOrDefault(AfflictionType.FrostbiteRisk, new List<Affliction>()).Cast<Frostbite>().ToList();
-            proxy.m_LocationsCurrentFrostbiteDamage = new List<float>();
+            proxy.m_LocationsCurrentFrostbiteDamage = new List<float>() { 0,0,0,0,0,0,0,0,0,0,0,0 };
            proxy.m_LocationsWithActiveFrostbite = new List<int>();
            foreach (var frostbite in frostbites)
            {
                proxy.m_LocationsWithActiveFrostbite.Add(frostbite.Location);

But need to add some temporary affliction to compensate lost unnamed forstbite damage (usualy small but who knows). Example: m_LocationsCurrentFrostbiteDamage before ConvertBackFrostBite() [100.6508,0,0.001715953,0.5878856,0.001715953,0.5878856,0.001715953,0,0.001715953,97.51201,0.001715953,97.51201] m_LocationsCurrentFrostbiteDamage after ConvertBackFrostBite() [100.6508,0,0,0.5878856,0,0.5878856,0,0,0,97.51201,0,97.51201]

Pt-Djefferson commented 4 years ago

Workaround about lost frostbite damage: Enums.cs:

        [Description("Frostbite risk")]
        FrostbiteRisk,
+        [Description("Frostbite damage")]
+        FrostbiteDamage,
        [Description("Electric burn")]
        BurnsElectric,

AfflictionsContainer.cs:

        private void ConvertFrostbite(FrostbiteSaveDataProxy proxy)
        {
            if (proxy == null)
                return;

+            var FrostbiteDamage = new List<float>(proxy.m_LocationsCurrentFrostbiteDamage);

            foreach (int bodyArea in proxy.m_LocationsWithActiveFrostbite)
            {
                Negative.Add(new Frostbite(negative)
                {
                    AfflictionType = AfflictionType.Frostbite,
                    Location = bodyArea,
                    Damage = proxy.m_LocationsCurrentFrostbiteDamage[bodyArea],
                });
+                FrostbiteDamage[bodyArea] = 0;
            }
            foreach (int bodyArea in proxy.m_LocationsWithFrostbiteRisk)
            {
                Negative.Add(new Frostbite(negative)
                {
                    AfflictionType = AfflictionType.FrostbiteRisk,
                    Location = bodyArea,
                    Damage = proxy.m_LocationsCurrentFrostbiteDamage[bodyArea],
                });
+                FrostbiteDamage[bodyArea] = 0;
            }
+            int bodyPart = 0;
+            foreach (float damage in FrostbiteDamage)
+            {
+                if (damage > 0)
+                {
+                    Negative.Add(new Frostbite(negative)
+                    {
+                        AfflictionType = AfflictionType.FrostbiteDamage,
+                        Location = bodyPart,
+                        Damage = damage ,
+                    });
+                }
+               bodyPart ++;
+            }
        }
        private FrostbiteSaveDataProxy ConvertBackFrostBite(FrostbiteSaveDataProxy proxy, Dictionary<AfflictionType, List<Affliction>> afflictionDict)
        {
            proxy = proxy ?? new FrostbiteSaveDataProxy();
            var frostbites = afflictionDict.GetOrDefault(AfflictionType.Frostbite, new List<Affliction>()).Cast<Frostbite>().ToList();
            var frostbiteRisks = afflictionDict.GetOrDefault(AfflictionType.FrostbiteRisk, new List<Affliction>()).Cast<Frostbite>().ToList();
+            var frostbiteDamage = afflictionDict.GetOrDefault(AfflictionType.FrostbiteDamage, new List<Affliction>()).Cast<Frostbite>().ToList();
-            proxy.m_LocationsCurrentFrostbiteDamage = new List<float>();
+            proxy.m_LocationsCurrentFrostbiteDamage = new List<float>() { 0,0,0,0,0,0,0,0,0,0,0,0 };
            proxy.m_LocationsWithActiveFrostbite = new List<int>();
            foreach (var frostbite in frostbites)
            {
                proxy.m_LocationsWithActiveFrostbite.Add(frostbite.Location);
                proxy.m_LocationsCurrentFrostbiteDamage[frostbite.Location] = frostbite.Damage;
            }
            foreach (var frostbite in frostbiteRisks)
            {
                proxy.m_LocationsWithFrostbiteRisk.Add(frostbite.Location);
                proxy.m_LocationsCurrentFrostbiteDamage[frostbite.Location] = frostbite.Damage;
            }
+            foreach (var frostbite in frostbiteDamage)
+            {
+                proxy.m_LocationsCurrentFrostbiteDamage[frostbite.Location] = frostbite.Damage;
+            }
            return proxy;
        }
FINDarkside commented 4 years ago

Thanks, you could also create pull requests if you wish. Even if not, you're being a big help, thanks!

So is it so you can have frostbite damage while not having active frostbite? I assume adding frostbiteDamage as frostbite risk in convertBack is not intentional?

Pt-Djefferson commented 4 years ago

Example from my real save:

"m_FrostbiteSerialized":"{
    \"m_LocationsWithActiveFrostbite\":[3,5],
    \"m_LocationsWithFrostbiteRisk\":[11,9,0],
    \"m_LocationsCurrentFrostbiteDamage\":[100.6508, 0 ,0.001715953, 0.5878856, 0.001715953, 0.5878856, 0.001715953, 0, 0.001715953, 97.51201, 0.001715953, 97.51201]}",

As you can see ActiveFrostbite at 3 and 5, FrostbiteRisk at 11,9 and 0, But lil damage almost all over the body. Small damage but who knows how game calculate frostbite risk for example.

Without my addings editor just throw away damage like 0.001715953 even if just load and save.

"frostbite risk in convertBack" my bad. Just m_LocationsCurrentFrostbiteDamage.

Pt-Djefferson commented 4 years ago

Don't think that pull request will be fine. Because I don't know c# well and don`t want to know it better. May be you prefer other method.

FINDarkside commented 4 years ago

Whatever suits you, but even if you make PR I can still "clean it up" if needed before merging, so it's not a problem even if your C# is rusty.

Anyway, fixed with 3833c1d7d0e1f267d061eeacdf2fc9dd87080e6f and cda0f75c55f8cd8e7087de0fa9ba139021d477f3