Skip to content

Commit a6e839f

Browse files
committed
- fixed a few potential overflow bugs
- fixed an error which would crash the application if the user has no or poor internet connection.
1 parent 7f51afd commit a6e839f

File tree

8 files changed

+57
-50
lines changed

8 files changed

+57
-50
lines changed

D-OS Save Editor/MainWindow.xaml.cs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public partial class MainWindow
3131
private readonly string _defaultProfileDir = $"{Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)}{DirectorySeparatorChar}Larian Studios{DirectorySeparatorChar}Divinity Original Sin Enhanced Edition{DirectorySeparatorChar}PlayerProfiles";
3232
private enum BackupStatus { None, Current, Old, NoChecksum, NoImage }
3333

34-
public static string Version { get; } = "v1.4.3";
34+
public static string Version { get; } = "v1.4.4";
3535
private string _updateLink;
3636

3737
public MainWindow()
@@ -52,24 +52,18 @@ public MainWindow()
5252

5353
// update
5454
UpdatePanel.Visibility = Visibility.Collapsed;
55-
try
56-
{
57-
CheckUpdate();
58-
DataTable.GetTableFromOnline();
59-
}
60-
catch
61-
{
62-
// do nothing
63-
}
55+
CheckUpdate();
56+
DataTable.GetTableFromOnline();
6457
}
6558

6659
#region private methods
6760
/// <summary>
6861
/// Checks for update on github
6962
/// </summary>
70-
private async void CheckUpdate()
63+
private async Task CheckUpdate()
7164
{
72-
const string urlAddress = "https://github.com/tmxkn1/D-OS-Save-Editor/blob/master/UpdateCheck";
65+
Debug.WriteLine("start");
66+
const string urlAddress = "https://github.com/tmxkn1/D-OS-Save-Editor/blob/master/UpdateCheck1";
7367
_updateLink = null;
7468
UpdatePanel.Visibility = Visibility.Collapsed;
7569

@@ -113,6 +107,7 @@ private async void CheckUpdate()
113107
}
114108
}
115109
}
110+
Debug.WriteLine("done");
116111
}
117112

118113
/// <summary>

D-OS Save Editor/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,5 @@
5151
// You can specify all the values or you can default the Build and Revision Numbers
5252
// by using the '*' as shown below:
5353
// [assembly: AssemblyVersion("1.0.*")]
54-
[assembly: AssemblyVersion("1.4.3.0")]
55-
[assembly: AssemblyFileVersion("1.4.3.0")]
54+
[assembly: AssemblyVersion("1.4.4.0")]
55+
[assembly: AssemblyFileVersion("1.4.4.0")]

D-OS Save Editor/XmlUtilities.cs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,29 @@ public static bool IsBool(string val)
1212
return val == "True" | val == "False";
1313
}
1414

15+
public static bool IsNumeric(string val)
16+
{
17+
return double.TryParse(val, out _);
18+
}
19+
1520
public static bool IsInt(string val)
1621
{
1722
return int.TryParse(val, out _);
1823
}
1924

20-
public static bool IsUnint(string val)
25+
public static bool IsLong(string val)
26+
{
27+
return long.TryParse(val, out _);
28+
}
29+
30+
public static bool IsUlong(string val)
31+
{
32+
return ulong.TryParse(val, out _);
33+
}
34+
35+
public static bool IsUint(string val)
2136
{
22-
return int.TryParse(val, out var intVal) && intVal >= 0;
37+
return uint.TryParse(val, out _);
2338
}
2439

2540
public static bool IsDouble(string val)

D-OS Save Editor/savegame/DataTable.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -768,7 +768,7 @@ public enum Abilities
768768

769769
public static bool IsOnlineBoostsGenerated { get; private set; }
770770

771-
public static async void GetTableFromOnline()
771+
public static async Task GetTableFromOnline()
772772
{
773773
const string urlAddress =
774774
@"https://raw.githubusercontent.com/tmxkn1/D-OS-Save-Editor/master/GenerationBoosts.txt";

D-OS Save Editor/savegame/Item.cs

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public string Flags
5555
get => _flags;
5656
set
5757
{
58-
if (!XmlUtilities.IsInt(value))
58+
if (!XmlUtilities.IsLong(value))
5959
throw new XmlValidationException("Flag", value);
6060
_flags = value;
6161
}
@@ -88,7 +88,7 @@ public string Parent
8888
get => _parent;
8989
set
9090
{
91-
if (!XmlUtilities.IsUnint(value))
91+
if (!XmlUtilities.IsLong(value))
9292
throw new XmlValidationException("Parenet", value);
9393
_parent = value;
9494
}
@@ -102,7 +102,7 @@ public string Slot
102102
get => _slot;
103103
set
104104
{
105-
if (!XmlUtilities.IsUnint(value))
105+
if (!XmlUtilities.IsUint(value))
106106
throw new XmlValidationException("Slot", value);
107107
_slot = value;
108108
}
@@ -116,7 +116,7 @@ public string Amount
116116
get => _amount;
117117
set
118118
{
119-
if (!XmlUtilities.IsUnint(value))
119+
if (!XmlUtilities.IsUint(value))
120120
throw new XmlValidationException("Amount", value);
121121
_amount = value;
122122
}
@@ -237,7 +237,7 @@ public string Random
237237
get => _random;
238238
set
239239
{
240-
if (!XmlUtilities.IsUnint(value))
240+
if (!XmlUtilities.IsLong(value))
241241
throw new XmlValidationException("Random", value);
242242
_random = value;
243243
}
@@ -262,9 +262,11 @@ public GenerationNode(string baseStats, string random)
262262
/// <returns></returns>
263263
public GenerationNode DeepClone()
264264
{
265-
var stats = this.MemberwiseClone() as GenerationNode;
265+
if (!(MemberwiseClone() is GenerationNode stats)) return null;
266+
266267
stats.Boosts = Boosts.ToList();
267268
return stats;
269+
268270
}
269271
}
270272

@@ -312,7 +314,7 @@ public string RepairDurabilityPenalty
312314
get => _repairDurabilityPenalty;
313315
set
314316
{
315-
if (!XmlUtilities.IsInt(value))
317+
if (!XmlUtilities.IsLong(value))
316318
throw new XmlValidationException("RepairDurabilityPenalty", value);
317319
_repairDurabilityPenalty = value;
318320
}
@@ -326,7 +328,7 @@ public string Level
326328
get => _level;
327329
set
328330
{
329-
if (!XmlUtilities.IsUnint(value))
331+
if (!XmlUtilities.IsUint(value))
330332
throw new XmlValidationException("Level", value);
331333
_level = value;
332334
}
@@ -340,7 +342,7 @@ public string Charges
340342
get => _charges;
341343
set
342344
{
343-
if (!XmlUtilities.IsInt(value))
345+
if (!XmlUtilities.IsLong(value))
344346
throw new XmlValidationException("Charges", value);
345347
_charges = value;
346348
}
@@ -357,9 +359,11 @@ public string Charges
357359
/// <returns></returns>
358360
public StatsNode DeepClone()
359361
{
360-
var stats = this.MemberwiseClone() as StatsNode;
361-
stats.PermanentBoost = new Dictionary<string,string>(PermanentBoost);
362+
if (!(MemberwiseClone() is StatsNode stats)) return null;
363+
364+
stats.PermanentBoost = new Dictionary<string, string>(PermanentBoost);
362365
return stats;
366+
363367
}
364368
}
365369

@@ -369,10 +373,12 @@ public StatsNode DeepClone()
369373
/// <returns></returns>
370374
public Item DeepClone()
371375
{
372-
var item = this.MemberwiseClone() as Item;
376+
if (!(MemberwiseClone() is Item item)) return null;
377+
373378
item.Generation = Generation?.DeepClone();
374379
item.Stats = Stats?.DeepClone();
375380
return item;
381+
376382
}
377383

378384
/// <summary>

D-OS Save Editor/savegame/LsxParser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public static Player ParsePlayer(XmlNode node)
114114
nodes = node.SelectNodes("children//node [@id='Talents']");
115115
for (var j = 0; j < nodes?.Count; j++)
116116
{
117-
player.Talents.Add(j, int.Parse(nodes[j].FirstChild.Attributes[1].Value));
117+
player.Talents.Add(j, long.Parse(nodes[j].FirstChild.Attributes[1].Value));
118118
}
119119

120120
nodes = node.SelectNodes("children//node [@id='Traits']");

D-OS Save Editor/savegame/Player.cs

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using System.Collections.Generic;
33
using System.Linq;
44
using System.Xml;
5-
using LSLib.Granny;
65

76
namespace D_OS_Save_Editor
87
{
@@ -12,8 +11,6 @@ public class Player
1211

1312
private string _vitality;
1413

15-
private string _inventoryId;
16-
1714
private string _experience;
1815

1916
private string _reputation;
@@ -37,7 +34,7 @@ public string MaxVitalityPatchCheck
3734
get => _maxVitalityPatchCheck;
3835
set
3936
{
40-
if (!XmlUtilities.IsUnint(value))
37+
if (!XmlUtilities.IsUint(value))
4138
throw new XmlValidationException("MaxVitalityPatchCheck", value);
4239
_maxVitalityPatchCheck = value;
4340
}
@@ -52,7 +49,7 @@ public string Vitality
5249
get => _vitality;
5350
set
5451
{
55-
if (!XmlUtilities.IsUnint(value))
52+
if (!XmlUtilities.IsUint(value))
5653
throw new XmlValidationException("Vitality", value);
5754
_vitality = value; }
5855
}
@@ -61,15 +58,7 @@ public string Vitality
6158
/// <summary>
6259
/// The id of the inventory associated with the player. All items in the player's inventory will have a "Parent" attribute with this property as its value.
6360
/// </summary>
64-
public string InventoryId
65-
{
66-
get => _inventoryId;
67-
set
68-
{
69-
//if (!XmlUtilities.IsUnint(value))
70-
// throw new XmlValidationException("InventoryId", value);
71-
_inventoryId = value; }
72-
}
61+
public string InventoryId { get; set; }
7362

7463
#endregion
7564

@@ -84,7 +73,7 @@ public string Experience
8473
get => _experience;
8574
set
8675
{
87-
if (!XmlUtilities.IsUnint(value))
76+
if (!XmlUtilities.IsUint(value))
8877
throw new XmlValidationException("Experience", value);
8978
_experience = value; }
9079
}
@@ -128,7 +117,7 @@ public string AttributePoints
128117
get => _attributePoints;
129118
set
130119
{
131-
if (!XmlUtilities.IsUnint(value))
120+
if (!XmlUtilities.IsUint(value))
132121
throw new XmlValidationException("AttributePoints", value);
133122
_attributePoints = value; }
134123
}
@@ -142,7 +131,7 @@ public string AbilityPoints
142131
get => _abilityPoints;
143132
set
144133
{
145-
if (!XmlUtilities.IsUnint(value))
134+
if (!XmlUtilities.IsUint(value))
146135
throw new XmlValidationException("AbilityPoints", value);
147136
_abilityPoints = value; }
148137
}
@@ -156,7 +145,7 @@ public string TalentPoints
156145
get => _talentPoints;
157146
set
158147
{
159-
if (!XmlUtilities.IsUnint(value))
148+
if (!XmlUtilities.IsUint(value))
160149
throw new XmlValidationException("TalentPoints", value);
161150
_talentPoints = value; }
162151
}
@@ -184,7 +173,7 @@ public string TalentPoints
184173
/// <summary>
185174
/// Acquired talents of the player. Keys are talent ids which can be found in ConversionTable class, and Values are points that have been assigned to the corresponding talents, which should be either 1 (acquired) or 0 (not acquired) .
186175
/// </summary>
187-
public Dictionary<int, int> Talents { get; set; } = new Dictionary<int, int>();
176+
public Dictionary<int, long> Talents { get; set; } = new Dictionary<int, long>();
188177
//<node id = "Traits" >
189178
// < attribute id="Object" value="0" type="2" />
190179
//</node>
@@ -258,7 +247,7 @@ public Player DeepClone()
258247
player.Skills = new Dictionary<string, bool>(player.Skills);
259248
player.Attributes = new Dictionary<int, int>(player.Attributes);
260249
player.Abilities = new Dictionary<int, int>(player.Abilities);
261-
player.Talents = new Dictionary<int, int>(player.Attributes);
250+
player.Talents = new Dictionary<int, long>(player.Talents);
262251
player.Traits = new Dictionary<int, int>(player.Traits);
263252
player.Items = Items.Select(a => a.DeepClone()).ToArray();
264253
return player;

GenerationBoosts.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,7 @@ Weapon_Earth_Legendary_Skill_WeaponBoost_Knife
426426
Weapon_FearLarge_Mod_All
427427
Weapon_FearLarge_Mod_Spear
428428
Weapon_Fire_Legendary_Skill_WeaponBoost_Axe
429+
Weapon_Fire_Legendary_Skill_WeaponBoost_Bow
429430
Weapon_Fire_Legendary_Skill_WeaponBoost_Club
430431
Weapon_Fire_Legendary_Skill_WeaponBoost_Crossbow
431432
Weapon_Fire_Legendary_Skill_WeaponBoost_Knife
@@ -618,5 +619,6 @@ Weapon_Small_WaterDamage_ModSword
618619
Weapon_Small_WaterDamage_ModXBow
619620
Weapon_Unbreakable_Mod
620621
Weapon_Water_Legendary_Skill_WeaponBoost_Crossbow
622+
Weapon_Water_Legendary_Skill_WeaponBoost_Knife
621623
Weapon_Water_Legendary_Skill_WeaponBoost_Sword
622624
Weapon_WillPower_Mod

0 commit comments

Comments
 (0)