Skip to content

Commit 7dcc313

Browse files
committed
Merge branch 'dependency_tree' into develop
2 parents 8c0fae0 + e1350c5 commit 7dcc313

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+5314
-1086
lines changed

xivModdingFramework/Cache/XivCache.cs

Lines changed: 1334 additions & 207 deletions
Large diffs are not rendered by default.

xivModdingFramework/Cache/XivDependencyGraph.cs

Lines changed: 1702 additions & 0 deletions
Large diffs are not rendered by default.

xivModdingFramework/General/Enums/XivRace.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,25 @@ public static string GetSkinPath(this XivRace startingRace, int body = 1, string
470470
/// </summary>
471471
public static class XivRaces
472472
{
473+
public static readonly List<XivRace> PlayableRaces = new List<XivRace>() {
474+
XivRace.Hyur_Midlander_Male,
475+
XivRace.Hyur_Midlander_Female,
476+
XivRace.Hyur_Highlander_Male,
477+
XivRace.Hyur_Highlander_Female,
478+
XivRace.Elezen_Male,
479+
XivRace.Elezen_Female,
480+
XivRace.Miqote_Male,
481+
XivRace.Miqote_Female,
482+
XivRace.Roegadyn_Male,
483+
XivRace.Roegadyn_Female,
484+
XivRace.Lalafell_Male,
485+
XivRace.Lalafell_Female,
486+
XivRace.AuRa_Male,
487+
XivRace.AuRa_Female,
488+
XivRace.Hrothgar,
489+
XivRace.Viera,
490+
};
491+
473492
/// <summary>
474493
/// Gets the description from the enum value, in this case the Race Code
475494
/// </summary>

xivModdingFramework/Helpers/Constants.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System;
44
using System.Collections.Generic;
55
using System.Text;
6+
using System.Text.RegularExpressions;
67

78
namespace xivModdingFramework.Helpers
89
{
@@ -13,5 +14,12 @@ public static class Constants
1314
/// The alphabet. Now in character array form.
1415
/// </summary>
1516
public static readonly char[] Alphabet = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' };
17+
public static string BinaryOffsetMarker = "::";
18+
19+
20+
21+
// This commedically long regex validates URL strings.
22+
// Came from - https://mathiasbynens.be/demo/url-regex (@scottgonzales version)
23+
public static readonly Regex UrlValidationRegex = new Regex("#([a-z]([a-z]|\\d|\\+|-|\\.)*):(\\/\\/(((([a-z]|\\d|-|\\.|_|~|[\\x00A0-\\xD7FF\\xF900-\\xFDCF\\xFDF0-\\xFFEF])|(%[\\da-f]{2})|[!\\$&'\\(\\)\\*\\+,;=]|:)*@)?((\\[(|(v[\\da-f]{1,}\\.(([a-z]|\\d|-|\\.|_|~)|[!\\$&'\\(\\)\\*\\+,;=]|:)+))\\])|((\\d|[1-9]\\d|1\\d\\d|2[0-4]\\d|25[0-5])\\.(\\d|[1-9]\\d|1\\d\\d|2[0-4]\\d|25[0-5])\\.(\\d|[1-9]\\d|1\\d\\d|2[0-4]\\d|25[0-5])\\.(\\d|[1-9]\\d|1\\d\\d|2[0-4]\\d|25[0-5]))|(([a-z]|\\d|-|\\.|_|~|[\\x00A0-\\xD7FF\\xF900-\\xFDCF\\xFDF0-\\xFFEF])|(%[\\da-f]{2})|[!\\$&'\\(\\)\\*\\+,;=])*)(:\\d*)?)(\\/(([a-z]|\\d|-|\\.|_|~|[\\x00A0-\\xD7FF\\xF900-\\xFDCF\\xFDF0-\\xFFEF])|(%[\\da-f]{2})|[!\\$&'\\(\\)\\*\\+,;=]|:|@)*)*|(\\/((([a-z]|\\d|-|\\.|_|~|[\\x00A0-\\xD7FF\\xF900-\\xFDCF\\xFDF0-\\xFFEF])|(%[\\da-f]{2})|[!\\$&'\\(\\)\\*\\+,;=]|:|@)+(\\/(([a-z]|\\d|-|\\.|_|~|[\\x00A0-\\xD7FF\\xF900-\\xFDCF\\xFDF0-\\xFFEF])|(%[\\da-f]{2})|[!\\$&'\\(\\)\\*\\+,;=]|:|@)*)*)?)|((([a-z]|\\d|-|\\.|_|~|[\\x00A0-\\xD7FF\\xF900-\\xFDCF\\xFDF0-\\xFFEF])|(%[\\da-f]{2})|[!\\$&'\\(\\)\\*\\+,;=]|:|@)+(\\/(([a-z]|\\d|-|\\.|_|~|[\\x00A0-\\xD7FF\\xF900-\\xFDCF\\xFDF0-\\xFFEF])|(%[\\da-f]{2})|[!\\$&'\\(\\)\\*\\+,;=]|:|@)*)*)|((([a-z]|\\d|-|\\.|_|~|[\\x00A0-\\xD7FF\\xF900-\\xFDCF\\xFDF0-\\xFFEF])|(%[\\da-f]{2})|[!\\$&'\\(\\)\\*\\+,;=]|:|@)){0})(\\?((([a-z]|\\d|-|\\.|_|~|[\\x00A0-\\xD7FF\\xF900-\\xFDCF\\xFDF0-\\xFFEF])|(%[\\da-f]{2})|[!\\$&'\\(\\)\\*\\+,;=]|:|@)|[\\xE000-\\xF8FF]|\\/|\\?)*)?(\\#((([a-z]|\\d|-|\\.|_|~|[\\x00A0-\\xD7FF\\xF900-\\xFDCF\\xFDF0-\\xFFEF])|(%[\\da-f]{2})|[!\\$&'\\(\\)\\*\\+,;=]|:|@)|\\/|\\?)*)?#iS");
1624
}
1725
}

xivModdingFramework/Helpers/HashGenerator.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ namespace xivModdingFramework.Helpers
2525
/// </summary>
2626
public class HashGenerator
2727
{
28-
private static int _dwCrc;
29-
3028
private static readonly uint[] CrcTable1 = new uint[]{
3129
0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, 0x706AF48F, 0xE963A535, 0x9E6495A3, 0x0EDB8832,
3230
0x79DCB8A4, 0xE0D5E91E, 0x97D2D988, 0x09B64C2B, 0x7EB17CBD, 0xE7B82D07, 0x90BF1D91, 0x1DB71064, 0x6AB020F2,
@@ -165,6 +163,7 @@ private static int ComputeCRC(byte[] ecxBytes, int offset)
165163

166164
private static int ComputeCRC(byte[] ecxBytes, int offset, int cbLength)
167165
{
166+
int _dwCrc;
168167
using (var stream = new MemoryStream(ecxBytes))
169168
{
170169
using (var reader = new BinaryReader(stream))

xivModdingFramework/Helpers/IOUtil.cs

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ public static string MakeItemSavePath(IItem item, DirectoryInfo saveDirectory, X
133133

134134
return path;
135135
}
136+
137+
136138
public static XivRace GetRaceFromPath(string path)
137139
{
138140
if(path == null)
@@ -152,7 +154,7 @@ public static XivRace GetRaceFromPath(string path)
152154
}
153155
else if (path.Contains(".tex") || path.Contains(".mdl") || path.Contains(".atex"))
154156
{
155-
if (path.Contains("accessory") || path.Contains("weapon") || path.Contains("/common/"))
157+
if (path.Contains("weapon") || path.Contains("/common/"))
156158
{
157159
xivRace = XivRace.All_Races;
158160
}
@@ -250,5 +252,46 @@ public static XivDataFile GetDataFileFromPath(string path)
250252

251253
throw new Exception("Could not resolve data file - Invalid internal FFXIV path.");
252254
}
255+
256+
/// <summary>
257+
/// Cleans a given string of unusual or potentially invalid characters for most use cases, particularly URLs.
258+
/// </summary>
259+
/// <param name="st"></param>
260+
/// <returns></returns>
261+
public static string CleanString(string st)
262+
{
263+
if(st == null)
264+
{
265+
return "";
266+
}
267+
268+
269+
const string invalids = "!\"#$%&'()*+,-./@:;<=>[\\]^_`{|}~";
270+
271+
st = st.Trim();
272+
foreach (var c in invalids)
273+
{
274+
st.Replace(c.ToString(), "");
275+
}
276+
277+
return st;
278+
}
279+
280+
/// <summary>
281+
/// Cleans up and validates a string to ensure it's a valid URL.
282+
/// If the given URL is totally invalid, NULL is returned.
283+
/// </summary>
284+
/// <param name="url"></param>
285+
/// <returns></returns>
286+
public static string ValidateUrl(string url)
287+
{
288+
url = CleanString(url);
289+
if (Constants.UrlValidationRegex.IsMatch(url))
290+
{
291+
return url;
292+
}
293+
return null;
294+
}
295+
253296
}
254297
}

xivModdingFramework/Helpers/ProblemChecker.cs

Lines changed: 19 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -162,52 +162,39 @@ public Task PerformStartOver(DirectoryInfo backupsDirectory, IProgress<string> p
162162
{
163163
return Task.Run(async () =>
164164
{
165-
progress?.Report("Deleting mods...");
166-
167165
var modding = new Modding(_gameDirectory);
168166
var backupsRestored = false;
169167

168+
// Stop the cache worker since we're blowing up the entire index file and db anyways.
169+
// The cache rebuild will start it up again after the cache is rebuilt.
170+
XivCache.CacheWorkerEnabled = false;
171+
170172
try
171173
{
172-
// Try to restore the index entries to their original values by deleting any files added by TexTools
173-
// and setting mods to disabled
174-
await modding.DeleteAllFilesAddedByTexTools();
175-
await modding.ToggleAllMods(false);
176-
progress?.Report("Restoring index file backups...");
177-
}
178-
catch
179-
{
180-
// If an exception occurred due to a corrupted modlist which couldn't be deserealized restore the backup index
181-
// files by force
174+
// Try restoring the indexes FIRST.
182175
backupsRestored = await RestoreBackups(backupsDirectory);
176+
progress?.Report("Restoring index file backups...");
183177

184178
if (!backupsRestored)
185179
{
186180
throw new Exception("Start Over Failed: Index backups missing/outdated.");
187181
}
188182
}
189-
finally
183+
catch(Exception ex)
190184
{
191-
// If no exception occured, restore the backups anyway just to be safe but don't throw an exception if it fails
192-
// due to outdated or missing backups since setting back the original index values should be enough hopefully
193-
if (!backupsRestored)
185+
try
194186
{
195-
backupsRestored = await RestoreBackups(backupsDirectory);
196-
197-
// If backups were not restored that means they were missing/outdated so try to make new backups now
198-
if (!backupsRestored)
199-
{
200-
try
201-
{
202-
await BackupIndexFiles(backupsDirectory);
203-
}
204-
catch (Exception ex)
205-
{
206-
throw new Exception("Start Over Failed: Failed to update outdated backups.\n\n" + ex.Message);
207-
}
208-
}
187+
// If the index restore failed, try just disabling.
188+
await modding.DeleteAllFilesAddedByTexTools();
189+
await modding.ToggleAllMods(false);
190+
progress?.Report("Index restore failed, attempting to delete all mods instead...");
191+
} catch
192+
{
193+
throw new Exception("Start Over Failed: Index Backups Invalid and Unable to Disable all mods.");
209194
}
210-
195+
}
196+
finally
197+
{
211198
progress?.Report("Deleting modded dat files...");
212199

213200
var dat = new Dat(_gameDirectory);
@@ -241,8 +228,7 @@ public Task PerformStartOver(DirectoryInfo backupsDirectory, IProgress<string> p
241228

242229
await Task.Run(async () =>
243230
{
244-
var _cache = new XivCache(_gameDirectory, language);
245-
_cache.RebuildCache();
231+
XivCache.RebuildCache();
246232
});
247233
}
248234
});

xivModdingFramework/Items/Categories/Character.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public Task<List<XivCharacter>> GetCharacterList()
6161
new XivCharacter
6262
{Name = XivStrings.Tail, PrimaryCategory = XivStrings.Character, SecondaryCategory = XivStrings.Tail},
6363
new XivCharacter
64-
{Name = XivStrings.Ears, PrimaryCategory = XivStrings.Character, SecondaryCategory = XivStrings.Ears},
64+
{Name = XivStrings.Ear, PrimaryCategory = XivStrings.Character, SecondaryCategory = XivStrings.Ear},
6565
new XivCharacter
6666
{
6767
Name = XivStrings.Face_Paint, PrimaryCategory = XivStrings.Character,
@@ -112,7 +112,7 @@ public async Task<Dictionary<XivRace, int[]>> GetRacesAndNumbersForTextures(XivC
112112
{
113113
folder = XivStrings.TailMtrlFolder;
114114
}
115-
else if (charaItem.SecondaryCategory == XivStrings.Ears)
115+
else if (charaItem.SecondaryCategory == XivStrings.Ear)
116116
{
117117
folder = XivStrings.EarsMtrlFolder;
118118
}
@@ -174,7 +174,7 @@ public async Task<Dictionary<XivRace, int[]>> GetRacesAndNumbersForModels(XivCha
174174
{
175175
folder = XivStrings.TailMDLFolder;
176176
}
177-
else if (charaItem.SecondaryCategory == XivStrings.Ears)
177+
else if (charaItem.SecondaryCategory == XivStrings.Ear)
178178
{
179179
folder = XivStrings.EarsMDLFolder;
180180
}
@@ -234,7 +234,7 @@ public async Task<Dictionary<string, char[]>> GetTypePartForTextures(XivCharacte
234234
typeDict = FaceSlotAbbreviationDictionary;
235235
file = XivStrings.FaceMtrlFile;
236236
}
237-
else if (charaItem.SecondaryCategory == XivStrings.Ears)
237+
else if (charaItem.SecondaryCategory == XivStrings.Ear)
238238
{
239239
folder = string.Format(XivStrings.EarsMtrlFolder, race.GetRaceCode(),
240240
num.ToString().PadLeft(4, '0'));
@@ -296,7 +296,7 @@ public async Task<char[]> GetPartForTextures(XivCharacter charaItem, XivRace rac
296296
folder = string.Format(XivStrings.TailMtrlFolder, race.GetRaceCode(), num.ToString().PadLeft(4, '0'));
297297
file = XivStrings.TailMtrlFile;
298298
}
299-
else if (charaItem.SecondaryCategory == XivStrings.Ears)
299+
else if (charaItem.SecondaryCategory == XivStrings.Ear)
300300
{
301301
folder = string.Format(XivStrings.EarsMtrlFolder, race.GetRaceCode(), num.ToString().PadLeft(4, '0'));
302302

@@ -387,7 +387,7 @@ public async Task<List<string>> GetTypeForModels(XivCharacter charaItem, XivRace
387387
typeDict = TailSlotAbbreviationDictionary;
388388
file = XivStrings.TailMDLFile;
389389
}
390-
else if (charaItem.SecondaryCategory == XivStrings.Ears)
390+
else if (charaItem.SecondaryCategory == XivStrings.Ear)
391391
{
392392
folder = string.Format(XivStrings.EarsMDLFolder, race.GetRaceCode(),
393393
num.ToString().PadLeft(4, '0'));
@@ -526,7 +526,7 @@ await Task.Run(() => Parallel.For(0, 300, (i) =>
526526
/// </summary>
527527
private static readonly Dictionary<string, string> EarsSlotAbbreviationDictionary = new Dictionary<string, string>
528528
{
529-
{XivStrings.Ears, "zer"},
529+
{XivStrings.Ear, "zer"},
530530
{XivStrings.InnerEar, "fac_"},
531531
{XivStrings.OuterEar, "" }
532532
};

xivModdingFramework/Items/Categories/Companions.cs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@ public Companions(DirectoryInfo gameDirectory, XivLanguage xivLanguage)
5353
}
5454
public async Task<List<XivMinion>> GetMinionList(string substring = null)
5555
{
56-
var cache = new XivCache(_gameDirectory, _xivLanguage);
57-
return await cache.GetCachedMinionsList(substring);
56+
return await XivCache.GetCachedMinionsList(substring);
5857
}
5958

6059
/// <summary>
@@ -125,8 +124,7 @@ await Task.Run(() => Parallel.ForEach(minionEx.Values, (minion) =>
125124

126125
public async Task<List<XivMount>> GetMountList(string substring = null, string category = null)
127126
{
128-
var cache = new XivCache(_gameDirectory, _xivLanguage);
129-
return await cache.GetCachedMountList(substring, category);
127+
return await XivCache.GetCachedMountList(substring, category);
130128
}
131129

132130
/// <summary>
@@ -265,8 +263,7 @@ await Task.Run(() => Parallel.ForEach(ornamentEx.Values, (ornament) =>
265263

266264
public async Task<List<XivPet>> GetPetList(string substring = null)
267265
{
268-
var cache = new XivCache(_gameDirectory, _xivLanguage);
269-
return await cache.GetCachedPetList(substring);
266+
return await XivCache.GetCachedPetList(substring);
270267

271268
}
272269

@@ -372,7 +369,7 @@ public async Task<Dictionary<string, char[]>> GetDemiHumanMountTextureEquipPartL
372369
var equipPartDictionary = new Dictionary<string, char[]>();
373370

374371
var index = new Index(_gameDirectory);
375-
var imc = new Imc(_gameDirectory, XivDataFile._04_Chara);
372+
var imc = new Imc(_gameDirectory);
376373
var version = (await imc.GetImcInfo(itemModel)).Variant.ToString().PadLeft(4, '0');
377374

378375
var id = itemModel.ModelInfo.PrimaryID.ToString().PadLeft(4, '0');
@@ -528,7 +525,7 @@ await Task.Run(() => Parallel.For(0, 100, (i) =>
528525
{XivStrings.Legs, "dwn"},
529526
{XivStrings.Feet, "sho"},
530527
{XivStrings.Body, "top"},
531-
{XivStrings.Ears, "ear"},
528+
{XivStrings.Earring, "ear"},
532529
{XivStrings.Neck, "nek"},
533530
{XivStrings.Rings, "rir"},
534531
{XivStrings.Wrists, "wrs"},

0 commit comments

Comments
 (0)