Skip to content

Commit 7f7d700

Browse files
committed
Remove the .sqlite file
1 parent 2159046 commit 7f7d700

5 files changed

Lines changed: 72 additions & 493 deletions

File tree

ColorMod/FFTColorCustomizer.csproj

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
<PackageReference Include="Reloaded.Mod.Loader.IO" Version="2.5.0" />
3333
<PackageReference Include="Reloaded.SharedLib.Hooks" Version="1.9.0" />
3434
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
35-
<PackageReference Include="Microsoft.Data.Sqlite" Version="8.0.0" />
3635
</ItemGroup>
3736

3837

@@ -52,7 +51,6 @@
5251
<ItemGroup>
5352
<None Include="Data\**\*.json" CopyToOutputDirectory="PreserveNewest" />
5453
<None Include="Data\nxd\charclut.nxd" CopyToOutputDirectory="PreserveNewest" />
55-
<None Include="Data\nxd\charclut.sqlite" CopyToOutputDirectory="PreserveNewest" />
5654
</ItemGroup>
5755

5856
</Project>

ColorMod/Services/NxdPatcher.cs

Lines changed: 1 addition & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,12 @@
22
using System.Collections.Generic;
33
using System.IO;
44
using System.Text.Json;
5-
using Microsoft.Data.Sqlite;
65

76
namespace FFTColorCustomizer.Services
87
{
98
/// <summary>
109
/// Patches charclut.nxd files by updating CLUTData bytes in place.
11-
/// This avoids the need to fully reimplement the NXD format - we just
12-
/// read the SQLite, convert JSON to bytes, and patch the NXD template.
10+
/// Uses known byte offsets to directly modify the NXD binary.
1311
/// </summary>
1412
public class NxdPatcher
1513
{
@@ -43,79 +41,6 @@ public class NxdPatcher
4341

4442
private const int ClutDataSize = 48; // 16 colors × 3 RGB bytes
4543

46-
/// <summary>
47-
/// Creates a patched NXD file from the SQLite database.
48-
/// </summary>
49-
/// <param name="templateNxdPath">Path to the template charclut.nxd</param>
50-
/// <param name="sqlitePath">Path to the modified charclut.sqlite</param>
51-
/// <param name="outputNxdPath">Path for the output NXD file</param>
52-
/// <returns>True if patching was successful</returns>
53-
public bool PatchNxdFromSqlite(string templateNxdPath, string sqlitePath, string outputNxdPath)
54-
{
55-
if (!File.Exists(templateNxdPath))
56-
throw new FileNotFoundException("Template NXD file not found", templateNxdPath);
57-
58-
if (!File.Exists(sqlitePath))
59-
throw new FileNotFoundException("SQLite database not found", sqlitePath);
60-
61-
// Read the template NXD
62-
byte[] nxdBytes = File.ReadAllBytes(templateNxdPath);
63-
64-
// Verify it's a valid NXD file
65-
if (nxdBytes.Length < 4 ||
66-
nxdBytes[0] != 'N' || nxdBytes[1] != 'X' ||
67-
nxdBytes[2] != 'D' || nxdBytes[3] != 'F')
68-
{
69-
throw new InvalidDataException("Invalid NXD file - missing NXDF magic");
70-
}
71-
72-
try
73-
{
74-
// Read CLUTData from SQLite and patch into NXD
75-
using var connection = new SqliteConnection($"Data Source={sqlitePath}");
76-
connection.Open();
77-
78-
using var command = connection.CreateCommand();
79-
command.CommandText = "SELECT Key, Key2, CLUTData FROM CharCLUT";
80-
81-
using var reader = command.ExecuteReader();
82-
while (reader.Read())
83-
{
84-
int key = reader.GetInt32(0);
85-
int key2 = reader.GetInt32(1);
86-
string clutDataJson = reader.GetString(2);
87-
88-
if (ClutDataOffsets.TryGetValue((key, key2), out int offset))
89-
{
90-
byte[] clutBytes = JsonToClutBytes(clutDataJson);
91-
if (clutBytes.Length == ClutDataSize)
92-
{
93-
Array.Copy(clutBytes, 0, nxdBytes, offset, ClutDataSize);
94-
}
95-
}
96-
}
97-
98-
connection.Close();
99-
}
100-
finally
101-
{
102-
// Clear connection pool to release file handles
103-
SqliteConnection.ClearAllPools();
104-
}
105-
106-
// Ensure output directory exists
107-
var outputDir = Path.GetDirectoryName(outputNxdPath);
108-
if (!string.IsNullOrEmpty(outputDir) && !Directory.Exists(outputDir))
109-
{
110-
Directory.CreateDirectory(outputDir);
111-
}
112-
113-
// Write the patched NXD
114-
File.WriteAllBytes(outputNxdPath, nxdBytes);
115-
116-
return true;
117-
}
118-
11944
/// <summary>
12045
/// Patches a single CLUTData entry in an NXD file.
12146
/// </summary>

0 commit comments

Comments
 (0)