Skip to content

Commit 91c1cc8

Browse files
committed
Allow added files to be enabled/disabled via index file descriptor addition/deletion.
1 parent 2936695 commit 91c1cc8

File tree

4 files changed

+78
-34
lines changed

4 files changed

+78
-34
lines changed

xivModdingFramework/Mods/Enums/XivModStatus.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ namespace xivModdingFramework.Mods.Enums
1919
public enum XivModStatus
2020
{
2121
Original,
22-
MatAdd,
2322
Enabled,
2423
Disabled
2524
}

xivModdingFramework/Mods/Modding.cs

Lines changed: 66 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -241,12 +241,6 @@ public async Task<XivModStatus> IsModEnabled(string internalPath, bool indexChec
241241
{
242242
return XivModStatus.Original;
243243
}
244-
// If modEntry not null but modded offset and original offset are the same as is the case with matadd textures
245-
if (modEntry.data.modOffset == modEntry.data.originalOffset)
246-
{
247-
// Return original to disable the disable/enable button as there's nothing to toggle between
248-
return XivModStatus.MatAdd;
249-
}
250244

251245
return modEntry.enabled ? XivModStatus.Enabled : XivModStatus.Disabled;
252246
}
@@ -276,17 +270,28 @@ public async Task ToggleModStatus(string internalFilePath, bool enable)
276270
// Matadd textures have the same mod offset as original so nothing to toggle
277271
if (modEntry.data.originalOffset == modEntry.data.modOffset)
278272
{
279-
return;
280-
}
281-
273+
// Added file.
274+
if (enable && !modEntry.enabled)
275+
{
276+
await index.AddFileDescriptor(modEntry.fullPath, modEntry.data.modOffset, IOUtil.GetDataFileFromPath(modEntry.fullPath));
277+
}
278+
else if (!enable && modEntry.enabled)
279+
{
280+
await index.DeleteFileDescriptor(modEntry.fullPath, IOUtil.GetDataFileFromPath(modEntry.fullPath));
281+
}
282282

283-
if (enable)
284-
{
285-
await index.UpdateDataOffset(modEntry.data.modOffset, internalFilePath);
286283
}
287284
else
288-
{
289-
await index.UpdateDataOffset(modEntry.data.originalOffset, internalFilePath);
285+
{
286+
// Standard mod (file replacement)
287+
if (enable)
288+
{
289+
await index.UpdateDataOffset(modEntry.data.modOffset, internalFilePath);
290+
}
291+
else
292+
{
293+
await index.UpdateDataOffset(modEntry.data.originalOffset, internalFilePath);
294+
}
290295
}
291296

292297
var modListDirectory = new DirectoryInfo(Path.Combine(_gameDirectory.Parent.Parent.FullName, XivStrings.ModlistFilePath));
@@ -338,17 +343,32 @@ public async Task ToggleModPackStatus(string modPackName, bool enable)
338343
{
339344
if (modEntry.name.Equals(string.Empty)) continue;
340345
// Matadd textures have the same mod offset as original so nothing to toggle
341-
if (modEntry.data.modOffset == modEntry.data.originalOffset) continue;
342-
343-
if (enable)
346+
if (modEntry.data.originalOffset == modEntry.data.modOffset)
344347
{
345-
await index.UpdateDataOffset(modEntry.data.modOffset, modEntry.fullPath);
346-
modEntry.enabled = true;
348+
// Added file.
349+
if (enable && !modEntry.enabled)
350+
{
351+
await index.AddFileDescriptor(modEntry.fullPath, modEntry.data.modOffset, IOUtil.GetDataFileFromPath(modEntry.fullPath));
352+
}
353+
else if (!enable && modEntry.enabled)
354+
{
355+
await index.DeleteFileDescriptor(modEntry.fullPath, IOUtil.GetDataFileFromPath(modEntry.fullPath));
356+
}
357+
347358
}
348359
else
349360
{
350-
await index.UpdateDataOffset(modEntry.data.originalOffset, modEntry.fullPath);
351-
modEntry.enabled = false;
361+
// Standard file (file replacement)
362+
if (enable)
363+
{
364+
await index.UpdateDataOffset(modEntry.data.modOffset, modEntry.fullPath);
365+
modEntry.enabled = true;
366+
}
367+
else
368+
{
369+
await index.UpdateDataOffset(modEntry.data.originalOffset, modEntry.fullPath);
370+
modEntry.enabled = false;
371+
}
352372
}
353373
}
354374

@@ -372,18 +392,34 @@ public async Task ToggleAllMods(bool enable, IProgress<(int current, int total,
372392
{
373393
if(string.IsNullOrEmpty(modEntry.name)) continue;
374394
if(string.IsNullOrEmpty(modEntry.fullPath)) continue;
375-
// Matadd textures have the same mod offset as original so nothing to toggle
376-
if (modEntry.data.modOffset == modEntry.data.originalOffset) continue;
377-
378-
if (enable && !modEntry.enabled)
395+
if (modEntry.data.modOffset == modEntry.data.originalOffset)
379396
{
380-
await index.UpdateDataOffset(modEntry.data.modOffset, modEntry.fullPath);
381-
modEntry.enabled = true;
397+
// Added file.
398+
if (enable && !modEntry.enabled)
399+
{
400+
await index.AddFileDescriptor(modEntry.fullPath, modEntry.data.modOffset, IOUtil.GetDataFileFromPath(modEntry.fullPath));
401+
modEntry.enabled = true;
402+
}
403+
else if (!enable && modEntry.enabled)
404+
{
405+
await index.DeleteFileDescriptor(modEntry.fullPath, IOUtil.GetDataFileFromPath(modEntry.fullPath));
406+
modEntry.enabled = false;
407+
}
408+
382409
}
383-
else if (!enable && modEntry.enabled)
410+
else
384411
{
385-
await index.UpdateDataOffset(modEntry.data.originalOffset, modEntry.fullPath);
386-
modEntry.enabled = false;
412+
// Standard mod.
413+
if (enable && !modEntry.enabled)
414+
{
415+
await index.UpdateDataOffset(modEntry.data.modOffset, modEntry.fullPath);
416+
modEntry.enabled = true;
417+
}
418+
else if (!enable && modEntry.enabled)
419+
{
420+
await index.UpdateDataOffset(modEntry.data.originalOffset, modEntry.fullPath);
421+
modEntry.enabled = false;
422+
}
387423
}
388424

389425
progress?.Report((++modNum, modList.Mods.Count, string.Empty));

xivModdingFramework/SqPack/FileTypes/Dat.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1440,7 +1440,6 @@ where entry.fullPath.Equals(modEntry.fullPath)
14401440
{
14411441
var success = true;
14421442
success = success && await index.AddFileDescriptor(internalFilePath, mod.data.modOffset, dataFile);
1443-
success = success && await index.AddFileDescriptor($"{internalFilePath}.flag", -1, dataFile);
14441443
if (!success)
14451444
{
14461445
throw new Exception("Failed to create file descriptor.");
@@ -1541,7 +1540,6 @@ where entry.fullPath.Equals(modEntry.fullPath)
15411540
{
15421541
var success = true;
15431542
success = success && await index.AddFileDescriptor(internalFilePath, offset, dataFile);
1544-
success = success && await index.AddFileDescriptor($"{internalFilePath}.flag", -1, dataFile);
15451543
if (!success)
15461544
{
15471545
throw new Exception("Failed to create file descriptor.");

xivModdingFramework/SqPack/FileTypes/Index.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1101,6 +1101,12 @@ public async Task<bool> DeleteFileDescriptor(string fullPath, XivDataFile dataFi
11011101
_semaphoreSlim.Release();
11021102

11031103

1104+
if (!fullPath.Contains(".flag"))
1105+
{
1106+
await DeleteFileDescriptor(fullPath + ".flag", dataFile);
1107+
}
1108+
1109+
11041110
// Queue us for updating.
11051111
XivCache.QueueDependencyUpdate(fullPath);
11061112

@@ -1117,6 +1123,11 @@ public async Task<bool> DeleteFileDescriptor(string fullPath, XivDataFile dataFi
11171123
/// <returns></returns>
11181124
public async Task<bool> AddFileDescriptor(string fullPath, int dataOffset, XivDataFile dataFile)
11191125
{
1126+
if(!fullPath.Contains(".flag"))
1127+
{
1128+
await AddFileDescriptor(fullPath + ".flag", -1, dataFile);
1129+
}
1130+
11201131
await _semaphoreSlim.WaitAsync();
11211132

11221133
// Test both index files for write access.
@@ -1265,7 +1276,7 @@ public async Task<bool> AddFileDescriptor(string fullPath, int dataOffset, XivDa
12651276
// Set the actual Injected Data
12661277
Array.Copy(BitConverter.GetBytes(fileHash), 0, modifiedIndex, injectLocation, 4);
12671278
Array.Copy(BitConverter.GetBytes(pathHash), 0, modifiedIndex, injectLocation + 4, 4);
1268-
Array.Copy(BitConverter.GetBytes(dataOffset), 0, modifiedIndex, injectLocation + 8, 4);
1279+
Array.Copy(BitConverter.GetBytes(dataOffset / 8), 0, modifiedIndex, injectLocation + 8, 4);
12691280

12701281
// Update the folder structure
12711282
var folderCount = SegmentSizes[3] / 16;

0 commit comments

Comments
 (0)