├── .gitattributes
├── .github
└── FUNDING.yml
├── .gitignore
├── DigimonColorSpriteTool.sln
├── DigimonColorSpriteTool
├── DigimonColorSpriteTool.csproj
├── FirmwareInfo.cs
├── ImageConverter.cs
├── ImageImportExport.cs
├── ImageInfo.cs
└── Program.cs
└── README.md
/.gitattributes:
--------------------------------------------------------------------------------
1 | ###############################################################################
2 | # Set default behavior to automatically normalize line endings.
3 | ###############################################################################
4 | * text=auto
5 |
6 | ###############################################################################
7 | # Set default behavior for command prompt diff.
8 | #
9 | # This is need for earlier builds of msysgit that does not have it on by
10 | # default for csharp files.
11 | # Note: This is only used by command line
12 | ###############################################################################
13 | #*.cs diff=csharp
14 |
15 | ###############################################################################
16 | # Set the merge driver for project and solution files
17 | #
18 | # Merging from the command prompt will add diff markers to the files if there
19 | # are conflicts (Merging from VS is not affected by the settings below, in VS
20 | # the diff markers are never inserted). Diff markers may cause the following
21 | # file extensions to fail to load in VS. An alternative would be to treat
22 | # these files as binary and thus will always conflict and require user
23 | # intervention with every merge. To do so, just uncomment the entries below
24 | ###############################################################################
25 | #*.sln merge=binary
26 | #*.csproj merge=binary
27 | #*.vbproj merge=binary
28 | #*.vcxproj merge=binary
29 | #*.vcproj merge=binary
30 | #*.dbproj merge=binary
31 | #*.fsproj merge=binary
32 | #*.lsproj merge=binary
33 | #*.wixproj merge=binary
34 | #*.modelproj merge=binary
35 | #*.sqlproj merge=binary
36 | #*.wwaproj merge=binary
37 |
38 | ###############################################################################
39 | # behavior for image files
40 | #
41 | # image files are treated as binary by default.
42 | ###############################################################################
43 | #*.jpg binary
44 | #*.png binary
45 | #*.gif binary
46 |
47 | ###############################################################################
48 | # diff behavior for common document formats
49 | #
50 | # Convert binary document formats to text before diffing them. This feature
51 | # is only available from the command line. Turn it on by uncommenting the
52 | # entries below.
53 | ###############################################################################
54 | #*.doc diff=astextplain
55 | #*.DOC diff=astextplain
56 | #*.docx diff=astextplain
57 | #*.DOCX diff=astextplain
58 | #*.dot diff=astextplain
59 | #*.DOT diff=astextplain
60 | #*.pdf diff=astextplain
61 | #*.PDF diff=astextplain
62 | #*.rtf diff=astextplain
63 | #*.RTF diff=astextplain
64 |
--------------------------------------------------------------------------------
/.github/FUNDING.yml:
--------------------------------------------------------------------------------
1 | ko_fi: caralynx
2 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 | ##
4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
5 |
6 | # User-specific files
7 | *.rsuser
8 | *.suo
9 | *.user
10 | *.userosscache
11 | *.sln.docstates
12 |
13 | # User-specific files (MonoDevelop/Xamarin Studio)
14 | *.userprefs
15 |
16 | # Mono auto generated files
17 | mono_crash.*
18 |
19 | # Build results
20 | [Dd]ebug/
21 | [Dd]ebugPublic/
22 | [Rr]elease/
23 | [Rr]eleases/
24 | x64/
25 | x86/
26 | [Ww][Ii][Nn]32/
27 | [Aa][Rr][Mm]/
28 | [Aa][Rr][Mm]64/
29 | bld/
30 | [Bb]in/
31 | [Oo]bj/
32 | [Oo]ut/
33 | [Ll]og/
34 | [Ll]ogs/
35 |
36 | # Visual Studio 2015/2017 cache/options directory
37 | .vs/
38 | # Uncomment if you have tasks that create the project's static files in wwwroot
39 | #wwwroot/
40 |
41 | # Visual Studio 2017 auto generated files
42 | Generated\ Files/
43 |
44 | # MSTest test Results
45 | [Tt]est[Rr]esult*/
46 | [Bb]uild[Ll]og.*
47 |
48 | # NUnit
49 | *.VisualState.xml
50 | TestResult.xml
51 | nunit-*.xml
52 |
53 | # Build Results of an ATL Project
54 | [Dd]ebugPS/
55 | [Rr]eleasePS/
56 | dlldata.c
57 |
58 | # Benchmark Results
59 | BenchmarkDotNet.Artifacts/
60 |
61 | # .NET Core
62 | project.lock.json
63 | project.fragment.lock.json
64 | artifacts/
65 |
66 | # ASP.NET Scaffolding
67 | ScaffoldingReadMe.txt
68 |
69 | # StyleCop
70 | StyleCopReport.xml
71 |
72 | # Files built by Visual Studio
73 | *_i.c
74 | *_p.c
75 | *_h.h
76 | *.ilk
77 | *.meta
78 | *.obj
79 | *.iobj
80 | *.pch
81 | *.pdb
82 | *.ipdb
83 | *.pgc
84 | *.pgd
85 | *.rsp
86 | *.sbr
87 | *.tlb
88 | *.tli
89 | *.tlh
90 | *.tmp
91 | *.tmp_proj
92 | *_wpftmp.csproj
93 | *.log
94 | *.vspscc
95 | *.vssscc
96 | .builds
97 | *.pidb
98 | *.svclog
99 | *.scc
100 |
101 | # Chutzpah Test files
102 | _Chutzpah*
103 |
104 | # Visual C++ cache files
105 | ipch/
106 | *.aps
107 | *.ncb
108 | *.opendb
109 | *.opensdf
110 | *.sdf
111 | *.cachefile
112 | *.VC.db
113 | *.VC.VC.opendb
114 |
115 | # Visual Studio profiler
116 | *.psess
117 | *.vsp
118 | *.vspx
119 | *.sap
120 |
121 | # Visual Studio Trace Files
122 | *.e2e
123 |
124 | # TFS 2012 Local Workspace
125 | $tf/
126 |
127 | # Guidance Automation Toolkit
128 | *.gpState
129 |
130 | # ReSharper is a .NET coding add-in
131 | _ReSharper*/
132 | *.[Rr]e[Ss]harper
133 | *.DotSettings.user
134 |
135 | # TeamCity is a build add-in
136 | _TeamCity*
137 |
138 | # DotCover is a Code Coverage Tool
139 | *.dotCover
140 |
141 | # AxoCover is a Code Coverage Tool
142 | .axoCover/*
143 | !.axoCover/settings.json
144 |
145 | # Coverlet is a free, cross platform Code Coverage Tool
146 | coverage*.json
147 | coverage*.xml
148 | coverage*.info
149 |
150 | # Visual Studio code coverage results
151 | *.coverage
152 | *.coveragexml
153 |
154 | # NCrunch
155 | _NCrunch_*
156 | .*crunch*.local.xml
157 | nCrunchTemp_*
158 |
159 | # MightyMoose
160 | *.mm.*
161 | AutoTest.Net/
162 |
163 | # Web workbench (sass)
164 | .sass-cache/
165 |
166 | # Installshield output folder
167 | [Ee]xpress/
168 |
169 | # DocProject is a documentation generator add-in
170 | DocProject/buildhelp/
171 | DocProject/Help/*.HxT
172 | DocProject/Help/*.HxC
173 | DocProject/Help/*.hhc
174 | DocProject/Help/*.hhk
175 | DocProject/Help/*.hhp
176 | DocProject/Help/Html2
177 | DocProject/Help/html
178 |
179 | # Click-Once directory
180 | publish/
181 |
182 | # Publish Web Output
183 | *.[Pp]ublish.xml
184 | *.azurePubxml
185 | # Note: Comment the next line if you want to checkin your web deploy settings,
186 | # but database connection strings (with potential passwords) will be unencrypted
187 | *.pubxml
188 | *.publishproj
189 |
190 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
191 | # checkin your Azure Web App publish settings, but sensitive information contained
192 | # in these scripts will be unencrypted
193 | PublishScripts/
194 |
195 | # NuGet Packages
196 | *.nupkg
197 | # NuGet Symbol Packages
198 | *.snupkg
199 | # The packages folder can be ignored because of Package Restore
200 | **/[Pp]ackages/*
201 | # except build/, which is used as an MSBuild target.
202 | !**/[Pp]ackages/build/
203 | # Uncomment if necessary however generally it will be regenerated when needed
204 | #!**/[Pp]ackages/repositories.config
205 | # NuGet v3's project.json files produces more ignorable files
206 | *.nuget.props
207 | *.nuget.targets
208 |
209 | # Microsoft Azure Build Output
210 | csx/
211 | *.build.csdef
212 |
213 | # Microsoft Azure Emulator
214 | ecf/
215 | rcf/
216 |
217 | # Windows Store app package directories and files
218 | AppPackages/
219 | BundleArtifacts/
220 | Package.StoreAssociation.xml
221 | _pkginfo.txt
222 | *.appx
223 | *.appxbundle
224 | *.appxupload
225 |
226 | # Visual Studio cache files
227 | # files ending in .cache can be ignored
228 | *.[Cc]ache
229 | # but keep track of directories ending in .cache
230 | !?*.[Cc]ache/
231 |
232 | # Others
233 | ClientBin/
234 | ~$*
235 | *~
236 | *.dbmdl
237 | *.dbproj.schemaview
238 | *.jfm
239 | *.pfx
240 | *.publishsettings
241 | orleans.codegen.cs
242 |
243 | # Including strong name files can present a security risk
244 | # (https://github.com/github/gitignore/pull/2483#issue-259490424)
245 | #*.snk
246 |
247 | # Since there are multiple workflows, uncomment next line to ignore bower_components
248 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
249 | #bower_components/
250 |
251 | # RIA/Silverlight projects
252 | Generated_Code/
253 |
254 | # Backup & report files from converting an old project file
255 | # to a newer Visual Studio version. Backup files are not needed,
256 | # because we have git ;-)
257 | _UpgradeReport_Files/
258 | Backup*/
259 | UpgradeLog*.XML
260 | UpgradeLog*.htm
261 | ServiceFabricBackup/
262 | *.rptproj.bak
263 |
264 | # SQL Server files
265 | *.mdf
266 | *.ldf
267 | *.ndf
268 |
269 | # Business Intelligence projects
270 | *.rdl.data
271 | *.bim.layout
272 | *.bim_*.settings
273 | *.rptproj.rsuser
274 | *- [Bb]ackup.rdl
275 | *- [Bb]ackup ([0-9]).rdl
276 | *- [Bb]ackup ([0-9][0-9]).rdl
277 |
278 | # Microsoft Fakes
279 | FakesAssemblies/
280 |
281 | # GhostDoc plugin setting file
282 | *.GhostDoc.xml
283 |
284 | # Node.js Tools for Visual Studio
285 | .ntvs_analysis.dat
286 | node_modules/
287 |
288 | # Visual Studio 6 build log
289 | *.plg
290 |
291 | # Visual Studio 6 workspace options file
292 | *.opt
293 |
294 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
295 | *.vbw
296 |
297 | # Visual Studio LightSwitch build output
298 | **/*.HTMLClient/GeneratedArtifacts
299 | **/*.DesktopClient/GeneratedArtifacts
300 | **/*.DesktopClient/ModelManifest.xml
301 | **/*.Server/GeneratedArtifacts
302 | **/*.Server/ModelManifest.xml
303 | _Pvt_Extensions
304 |
305 | # Paket dependency manager
306 | .paket/paket.exe
307 | paket-files/
308 |
309 | # FAKE - F# Make
310 | .fake/
311 |
312 | # CodeRush personal settings
313 | .cr/personal
314 |
315 | # Python Tools for Visual Studio (PTVS)
316 | __pycache__/
317 | *.pyc
318 |
319 | # Cake - Uncomment if you are using it
320 | # tools/**
321 | # !tools/packages.config
322 |
323 | # Tabs Studio
324 | *.tss
325 |
326 | # Telerik's JustMock configuration file
327 | *.jmconfig
328 |
329 | # BizTalk build output
330 | *.btp.cs
331 | *.btm.cs
332 | *.odx.cs
333 | *.xsd.cs
334 |
335 | # OpenCover UI analysis results
336 | OpenCover/
337 |
338 | # Azure Stream Analytics local run output
339 | ASALocalRun/
340 |
341 | # MSBuild Binary and Structured Log
342 | *.binlog
343 |
344 | # NVidia Nsight GPU debugger configuration file
345 | *.nvuser
346 |
347 | # MFractors (Xamarin productivity tool) working folder
348 | .mfractor/
349 |
350 | # Local History for Visual Studio
351 | .localhistory/
352 |
353 | # BeatPulse healthcheck temp database
354 | healthchecksdb
355 |
356 | # Backup folder for Package Reference Convert tool in Visual Studio 2017
357 | MigrationBackup/
358 |
359 | # Ionide (cross platform F# VS Code tools) working folder
360 | .ionide/
361 |
362 | # Fody - auto-generated XML schema
363 | FodyWeavers.xsd
--------------------------------------------------------------------------------
/DigimonColorSpriteTool.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 17
4 | VisualStudioVersion = 17.4.33213.308
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DigimonColorSpriteTool", "DigimonColorSpriteTool\DigimonColorSpriteTool.csproj", "{078EDDD0-7B1C-4822-A0F2-D2659D1217CC}"
7 | EndProject
8 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{9E2D1D13-2F35-40F9-986F-E98CEF9F7B90}"
9 | ProjectSection(SolutionItems) = preProject
10 | README.md = README.md
11 | EndProjectSection
12 | EndProject
13 | Global
14 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
15 | Debug|Any CPU = Debug|Any CPU
16 | Release|Any CPU = Release|Any CPU
17 | EndGlobalSection
18 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
19 | {078EDDD0-7B1C-4822-A0F2-D2659D1217CC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
20 | {078EDDD0-7B1C-4822-A0F2-D2659D1217CC}.Debug|Any CPU.Build.0 = Debug|Any CPU
21 | {078EDDD0-7B1C-4822-A0F2-D2659D1217CC}.Release|Any CPU.ActiveCfg = Release|Any CPU
22 | {078EDDD0-7B1C-4822-A0F2-D2659D1217CC}.Release|Any CPU.Build.0 = Release|Any CPU
23 | EndGlobalSection
24 | GlobalSection(SolutionProperties) = preSolution
25 | HideSolutionNode = FALSE
26 | EndGlobalSection
27 | GlobalSection(ExtensibilityGlobals) = postSolution
28 | SolutionGuid = {691A1CA8-9943-4CEB-8548-3A703C49D354}
29 | EndGlobalSection
30 | EndGlobal
31 |
--------------------------------------------------------------------------------
/DigimonColorSpriteTool/DigimonColorSpriteTool.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | net8.0
6 | enable
7 | enable
8 | Digimon Color Sprite Import/Export Tool
9 | cyanic
10 | 2.1.0
11 | https://github.com/GMMan/DigimonColorSpriteTool
12 | README.md
13 | $(Title)
14 | $(RepositoryUrl)
15 |
16 |
17 |
18 |
19 | True
20 | \
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/DigimonColorSpriteTool/FirmwareInfo.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace DigimonColorSpriteTool
8 | {
9 | public class FirmwareInfo
10 | {
11 | public uint SpritePackBase { get; set; }
12 | public uint CharaSpriteWidth { get; set; } = 48;
13 | public uint CharaSpriteHeight { get; set; } = 48;
14 | public uint SizeTableOffset { get; set; }
15 | public uint NumImages { get; set; }
16 | public uint NumCharas { get; set; }
17 | public uint NumFramesPerChara { get; set; }
18 | public uint CharasStartIndex { get; set; }
19 | public uint NumJogressCharas { get; set; }
20 | public bool HasName { get; set; }
21 | public uint NumFramesPerSpecialChara { get; set; }
22 | public uint[] SpecialCharaIndexes { get; set; } = [];
23 |
24 | public static readonly Dictionary Presets = new()
25 | {
26 | { "dmc1", new FirmwareInfo
27 | {
28 | SpritePackBase = 0x80000,
29 | SizeTableOffset = 38296,
30 | NumImages = 597,
31 | NumCharas = 18,
32 | NumFramesPerChara = 15,
33 | CharasStartIndex = 210,
34 | NumJogressCharas = 0,
35 | }
36 | },
37 | { "dmc2", new FirmwareInfo
38 | {
39 | SpritePackBase = 0x80000,
40 | SizeTableOffset = 40346,
41 | NumImages = 597,
42 | NumCharas = 18,
43 | NumFramesPerChara = 15,
44 | CharasStartIndex = 210,
45 | NumJogressCharas = 1,
46 | }
47 | },
48 | { "dmc3", new FirmwareInfo
49 | {
50 | SpritePackBase = 0x80000,
51 | SizeTableOffset = 38632,
52 | NumImages = 628,
53 | NumCharas = 20,
54 | NumFramesPerChara = 15,
55 | CharasStartIndex = 210,
56 | NumJogressCharas = 0,
57 | }
58 | },
59 | { "dmc4", new FirmwareInfo
60 | {
61 | SpritePackBase = 0x80000,
62 | SizeTableOffset = 41032,
63 | NumImages = 613,
64 | NumCharas = 19,
65 | NumFramesPerChara = 15,
66 | CharasStartIndex = 210,
67 | NumJogressCharas = 1,
68 | }
69 | },
70 | { "dmc5", new FirmwareInfo
71 | {
72 | SpritePackBase = 0x80000,
73 | SizeTableOffset = 38592,
74 | NumImages = 613,
75 | NumCharas = 19,
76 | NumFramesPerChara = 15,
77 | CharasStartIndex = 210,
78 | NumJogressCharas = 2,
79 | }
80 | },
81 | { "dmcmh", new FirmwareInfo
82 | {
83 | SpritePackBase = 0x400000,
84 | SizeTableOffset = 49662,
85 | NumImages = 938,
86 | NumCharas = 38,
87 | NumFramesPerChara = 15,
88 | CharasStartIndex = 200,
89 | NumJogressCharas = 0,
90 | HasName = true,
91 | NumFramesPerSpecialChara = 20,
92 | SpecialCharaIndexes = [29, 31, 34]
93 | }
94 | },
95 | { "penc1", new FirmwareInfo
96 | {
97 | SpritePackBase = 0x400000,
98 | SizeTableOffset = 64796,
99 | NumImages = 759,
100 | NumCharas = 32,
101 | NumFramesPerChara = 12,
102 | CharasStartIndex = 240,
103 | NumJogressCharas = 0,
104 | }
105 | },
106 | { "penc2", new FirmwareInfo
107 | {
108 | SpritePackBase = 0x400000,
109 | SizeTableOffset = 64730,
110 | NumImages = 759,
111 | NumCharas = 32,
112 | NumFramesPerChara = 12,
113 | CharasStartIndex = 240,
114 | NumJogressCharas = 0,
115 | }
116 | },
117 | { "penc3", new FirmwareInfo
118 | {
119 | SpritePackBase = 0x400000,
120 | SizeTableOffset = 64736,
121 | NumImages = 759,
122 | NumCharas = 32,
123 | NumFramesPerChara = 12,
124 | CharasStartIndex = 240,
125 | NumJogressCharas = 0,
126 | }
127 | },
128 | { "penc4", new FirmwareInfo
129 | {
130 | SpritePackBase = 0x400000,
131 | SizeTableOffset = 65932,
132 | NumImages = 759,
133 | NumCharas = 32,
134 | NumFramesPerChara = 12,
135 | CharasStartIndex = 240,
136 | NumJogressCharas = 0,
137 | }
138 | },
139 | { "penc5", new FirmwareInfo
140 | {
141 | SpritePackBase = 0x400000,
142 | SizeTableOffset = 65944,
143 | NumImages = 759,
144 | NumCharas = 32,
145 | NumFramesPerChara = 12,
146 | CharasStartIndex = 240,
147 | NumJogressCharas = 0,
148 | }
149 | },
150 | { "penc0", new FirmwareInfo
151 | {
152 | SpritePackBase = 0x400000,
153 | SizeTableOffset = 66158,
154 | NumImages = 771,
155 | NumCharas = 33,
156 | NumFramesPerChara = 12,
157 | CharasStartIndex = 240,
158 | NumJogressCharas = 0,
159 | }
160 | },
161 | };
162 | }
163 | }
164 |
--------------------------------------------------------------------------------
/DigimonColorSpriteTool/ImageConverter.cs:
--------------------------------------------------------------------------------
1 | using SixLabors.ImageSharp;
2 | using SixLabors.ImageSharp.PixelFormats;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.Linq;
6 | using System.Text;
7 | using System.Threading.Tasks;
8 |
9 | namespace DigimonColorSpriteTool
10 | {
11 | public static class ImageConverter
12 | {
13 | public static Image ConvertRgb565ToImage(byte[] pixels, int width, int height, bool useGreenAsAlpha)
14 | {
15 | if (pixels == null) throw new ArgumentNullException(nameof(pixels));
16 | if (width < 0) throw new ArgumentOutOfRangeException(nameof(width), "Width cannot be negative.");
17 | if (height < 0) throw new ArgumentOutOfRangeException(nameof(height), "Height cannot be negative.");
18 | if (pixels.Length != width * height * 2) throw new ArgumentException("Image size is incorrect.");
19 |
20 | // Modified ConvertImage565 with alpha
21 | int i = 0;
22 | var img = new Image(width, height);
23 | img.ProcessPixelRows(proc =>
24 | {
25 | for (int y = 0; y < proc.Height; ++y)
26 | {
27 | var row = proc.GetRowSpan(y);
28 | for (int x = 0; x < proc.Width; ++x)
29 | {
30 | ushort c = (ushort)(pixels[i++] | (pixels[i++] << 8));
31 | float b = ((c >> 0) & 0x1f) / 31f;
32 | float g = ((c >> 5) & 0x3f) / 63f;
33 | float r = ((c >> 11) & 0x1f) / 31f;
34 | float a = 1;
35 | if (!useGreenAsAlpha && b == 0 && g == 1 && r == 0)
36 | a = 0;
37 | row[x] = new Rgba32(r, g, b, a);
38 | }
39 | }
40 | });
41 | return img;
42 | }
43 |
44 | public static byte[] ConvertImageToRgb565(Image img, bool useGreenAsAlpha)
45 | {
46 | if (img == null) throw new ArgumentNullException(nameof(img));
47 |
48 | var rgbImg = img.CloneAs();
49 | using (MemoryStream ms = new MemoryStream())
50 | {
51 | BinaryWriter bw = new BinaryWriter(ms);
52 | rgbImg.ProcessPixelRows(proc =>
53 | {
54 | for (int y = 0; y < proc.Height; ++y)
55 | {
56 | var row = proc.GetRowSpan(y);
57 | for (int x = 0; x < proc.Width; ++x)
58 | {
59 | var pixel = row[x].ToScaledVector4();
60 | int r = (int)Math.Round(pixel.X * 31);
61 | int g = (int)Math.Round(pixel.Y * 63);
62 | int b = (int)Math.Round(pixel.Z * 31);
63 | if (pixel.W == 0)
64 | {
65 | r = 0;
66 | g = 63;
67 | b = 0;
68 | }
69 | else if (!useGreenAsAlpha && r == 0 && g == 63 && b == 0)
70 | {
71 | --g;
72 | }
73 |
74 | ushort c = (ushort)((r << 11) | (g << 5) | b);
75 | bw.Write(c);
76 | }
77 | }
78 | });
79 | ms.Flush();
80 | return ms.ToArray();
81 | }
82 | }
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/DigimonColorSpriteTool/ImageImportExport.cs:
--------------------------------------------------------------------------------
1 | using SixLabors.ImageSharp;
2 | using SixLabors.ImageSharp.PixelFormats;
3 | using SixLabors.ImageSharp.Processing;
4 | using System;
5 | using System.Collections.Generic;
6 | using System.Linq;
7 | using System.Text;
8 | using System.Threading.Tasks;
9 |
10 | namespace DigimonColorSpriteTool
11 | {
12 | public class ImageImportExport : IDisposable
13 | {
14 | static readonly string[] FILE_NAME_PATTERNS =
15 | [
16 | "{0}", "{0:d3}", "{0}_0x{0:x}"
17 | ];
18 | static readonly string[] FILE_EXTENSIONS =
19 | [
20 | ".png", ".bmp"
21 | ];
22 | static readonly string NAME_SUFFIX = "_name";
23 |
24 | Stream fwStream;
25 | BinaryReader br;
26 | List imageInfos = new List();
27 | FirmwareInfo firmwareInfo;
28 | private bool disposedValue;
29 |
30 | public int NumImages => imageInfos.Count;
31 |
32 | public ImageImportExport(Stream fwStream, FirmwareInfo firmwareInfo)
33 | {
34 | this.fwStream = fwStream ?? throw new ArgumentNullException(nameof(fwStream));
35 | this.firmwareInfo = firmwareInfo ?? throw new ArgumentNullException(nameof(firmwareInfo));
36 | br = new BinaryReader(fwStream);
37 | ReadMetadata();
38 | }
39 |
40 | void ReadMetadata()
41 | {
42 | // Read size table
43 | fwStream.Seek(firmwareInfo.SizeTableOffset, SeekOrigin.Begin);
44 | for (int i = 0; i < firmwareInfo.NumImages; i++)
45 | {
46 | imageInfos.Add(new ImageInfo
47 | {
48 | Width = br.ReadUInt16(),
49 | Height = br.ReadUInt16(),
50 | });
51 | }
52 |
53 | // Read offsets
54 | fwStream.Seek(firmwareInfo.SpritePackBase, SeekOrigin.Begin);
55 | foreach (var info in imageInfos)
56 | {
57 | info.DataOffset = br.ReadInt32();
58 | }
59 | }
60 |
61 | void CheckDisposed()
62 | {
63 | if (disposedValue) throw new ObjectDisposedException(GetType().FullName);
64 | }
65 |
66 | static string? FindFile(string folderPath, int index)
67 | {
68 | foreach (var extension in FILE_EXTENSIONS)
69 | {
70 | foreach (var pattern in FILE_NAME_PATTERNS)
71 | {
72 | string filePath = Path.Combine(folderPath, string.Format(pattern, index) + extension);
73 | if (File.Exists(filePath)) return filePath;
74 | }
75 | }
76 | return null;
77 | }
78 |
79 | public void SetOverridesByFolder(string folderPath)
80 | {
81 | CheckDisposed();
82 | if (string.IsNullOrEmpty(folderPath)) throw new ArgumentNullException(nameof(folderPath));
83 | for (int i = 0; i < imageInfos.Count; ++i)
84 | {
85 | string? filePath = FindFile(folderPath, i);
86 | imageInfos[i].FilePath = filePath;
87 | imageInfos[i].OverrideData = null;
88 | }
89 | }
90 |
91 | Image GetImage(ImageInfo info, bool useGreenAsAlpha)
92 | {
93 | fwStream.Seek(firmwareInfo.SpritePackBase + info.DataOffset, SeekOrigin.Begin);
94 | return ImageConverter.ConvertRgb565ToImage(br.ReadBytes(info.Width * info.Height * 2), info.Width, info.Height, useGreenAsAlpha);
95 | }
96 |
97 | public void ExportImage(int index, string destPath, bool useGreenAsAlpha)
98 | {
99 | CheckDisposed();
100 | if (index < 0 || index >= imageInfos.Count) throw new ArgumentOutOfRangeException(nameof(index));
101 | if (string.IsNullOrEmpty(destPath)) throw new ArgumentNullException(nameof(destPath));
102 | using var img = GetImage(imageInfos[index], useGreenAsAlpha);
103 | img.Save(destPath);
104 | }
105 |
106 | public void ExportAllImages(string destFolder, string extension, bool useGreenAsAlpha)
107 | {
108 | CheckDisposed();
109 | if (string.IsNullOrEmpty(destFolder)) throw new ArgumentNullException(nameof(destFolder));
110 | if (string.IsNullOrEmpty(extension)) throw new ArgumentNullException(nameof(extension));
111 | for (int i = 0; i < imageInfos.Count; ++i)
112 | {
113 | ExportImage(i, Path.Combine(destFolder, $"{i}{extension}"), useGreenAsAlpha);
114 | }
115 | }
116 |
117 | public void Rebuild(string destPath, bool useGreenAsAlpha)
118 | {
119 | CheckDisposed();
120 | if (string.IsNullOrEmpty(destPath)) throw new ArgumentNullException(nameof(destPath));
121 | using FileStream newStream = File.Create(destPath);
122 | BinaryWriter bw = new(newStream);
123 |
124 | // Copy firmware
125 | fwStream.Seek(0, SeekOrigin.Begin);
126 | fwStream.CopyTo(newStream);
127 |
128 | // Write image data
129 | List offsets = new();
130 | newStream.Seek(firmwareInfo.SpritePackBase + imageInfos.Count * 4, SeekOrigin.Begin);
131 | int i = 0;
132 | foreach (var info in imageInfos)
133 | {
134 | offsets.Add((int)(newStream.Position - firmwareInfo.SpritePackBase));
135 | if (info.OverrideData != null)
136 | {
137 | if (info.OverrideData.Length != info.Width * info.Height * 2)
138 | Console.Error.WriteLine($"Warning: New image data {i} has different size ({info.OverrideData.Length}) than original ({info.Width * info.Height * 2}).");
139 | bw.Write(info.OverrideData);
140 | }
141 | else if (info.FilePath != null)
142 | {
143 | using (var img = Image.Load(info.FilePath))
144 | {
145 | if (img.Width != info.Width || img.Height != info.Height)
146 | {
147 | Console.Error.WriteLine($"Warning: New file {i} has different dimension ({img.Width}x{img.Height}) compared to original ({info.Width}x{info.Height}).");
148 | info.Width = (ushort)img.Width;
149 | info.Height = (ushort)img.Height;
150 | }
151 | var convertedImg = ImageConverter.ConvertImageToRgb565(img, useGreenAsAlpha);
152 | bw.Write(convertedImg);
153 | }
154 | }
155 | else
156 | {
157 | fwStream.Seek(firmwareInfo.SpritePackBase + info.DataOffset, SeekOrigin.Begin);
158 | byte[] data = br.ReadBytes(info.Width * info.Height * 2);
159 | bw.Write(data);
160 | }
161 |
162 | ++i;
163 | }
164 |
165 | // Write image offsets
166 | newStream.Seek(firmwareInfo.SpritePackBase, SeekOrigin.Begin);
167 | foreach (var offset in offsets)
168 | {
169 | bw.Write(offset);
170 | }
171 |
172 | // Write size table
173 | newStream.Seek(firmwareInfo.SizeTableOffset, SeekOrigin.Begin);
174 | foreach (var info in imageInfos)
175 | {
176 | bw.Write(info.Width);
177 | bw.Write(info.Height);
178 | }
179 | }
180 |
181 | public void ImportSpriteSheet(string path, int startImageIndex, bool useGreenAsAlpha, uint? rows, uint? cols, bool isSpecial)
182 | {
183 | CheckDisposed();
184 | if (string.IsNullOrEmpty(path)) throw new ArgumentNullException("path");
185 | uint numFrames = isSpecial ? firmwareInfo.NumFramesPerSpecialChara : firmwareInfo.NumFramesPerChara;
186 | if (startImageIndex < 0 || startImageIndex + numFrames >= imageInfos.Count)
187 | throw new ArgumentOutOfRangeException(nameof(startImageIndex), "Invalid start image index.");
188 | if (!rows.HasValue) rows = numFrames;
189 | if (!cols.HasValue) cols = 1;
190 | if (rows * cols < numFrames)
191 | throw new ArgumentException("Not enough rows and cols for number of frame per character.");
192 |
193 | using var sheetImg = Image.Load(path);
194 | int sheetFrameWidth = (int)(sheetImg.Width / cols);
195 | int sheetFrameHeight = (int)(sheetImg.Height / rows);
196 | // Do not allow oversized sprites, even if it technically would work
197 | if (sheetFrameWidth > firmwareInfo.CharaSpriteWidth || sheetFrameHeight > firmwareInfo.CharaSpriteHeight)
198 | throw new ArgumentException("Sheet frame is too large for device character frame.", nameof(path));
199 | if (firmwareInfo.CharaSpriteWidth % sheetFrameWidth != 0)
200 | throw new ArgumentException("Sheet frame width cannot be scaled by an integral factor.", nameof(path));
201 | if (firmwareInfo.CharaSpriteHeight % sheetFrameHeight != 0)
202 | throw new ArgumentException("Sheet frame height cannot be scaled by an integral factor.", nameof(path));
203 | int scaleFactorX = (int)(firmwareInfo.CharaSpriteWidth / sheetFrameWidth);
204 | int scaleFactorY = (int)(firmwareInfo.CharaSpriteHeight / sheetFrameHeight);
205 |
206 | int currRow = 0;
207 | int currCol = 0;
208 | for (int i = 0; i < numFrames; ++i)
209 | {
210 | using var frameImg = new Image(sheetFrameWidth, sheetFrameHeight);
211 | frameImg.Mutate(x => x.DrawImage(sheetImg, new Point(-sheetFrameWidth * currCol, -sheetFrameHeight * currRow), 1.0f));
212 | if (scaleFactorX != 1 || scaleFactorY != 1)
213 | {
214 | frameImg.Mutate(x => x.Resize(sheetFrameWidth * scaleFactorX, sheetFrameHeight * scaleFactorY, KnownResamplers.NearestNeighbor));
215 | }
216 | byte[] pixels = ImageConverter.ConvertImageToRgb565(frameImg, useGreenAsAlpha);
217 | imageInfos[startImageIndex + i].OverrideData = pixels;
218 | ++currCol;
219 | if (currCol >= cols)
220 | {
221 | ++currRow;
222 | currCol = 0;
223 | }
224 | }
225 |
226 | if (firmwareInfo.HasName)
227 | {
228 | string namePath = $"{Path.ChangeExtension(path, null)}{NAME_SUFFIX}{Path.GetExtension(path)}";
229 | if (File.Exists(namePath))
230 | {
231 | using var nameImg = Image.Load(namePath);
232 | byte[] pixels = ImageConverter.ConvertImageToRgb565(nameImg, useGreenAsAlpha);
233 | var nameInfo = imageInfos[(int)(startImageIndex + numFrames)];
234 | nameInfo.OverrideData = pixels;
235 | nameInfo.Width = (ushort)nameImg.Width;
236 | nameInfo.Height = (ushort)nameImg.Height;
237 | }
238 | }
239 | }
240 |
241 | public void ImportSpriteSheetFolder(string folderPath, bool useGreenAsAlpha, uint? rows, uint? cols)
242 | {
243 | CheckDisposed();
244 | if (string.IsNullOrEmpty(folderPath)) throw new ArgumentNullException(nameof(folderPath));
245 | int startImageIndex = (int)firmwareInfo.CharasStartIndex;
246 | for (int i = 0; i < firmwareInfo.NumCharas; ++i)
247 | {
248 | string? filePath = FindFile(folderPath, i);
249 | bool isSpecial = Array.IndexOf(firmwareInfo.SpecialCharaIndexes, (uint)i) != -1;
250 | if (i < firmwareInfo.NumJogressCharas) ++startImageIndex;
251 | if (filePath != null)
252 | {
253 | ImportSpriteSheet(filePath, startImageIndex, useGreenAsAlpha, rows, cols, isSpecial);
254 | }
255 | startImageIndex += (int)(isSpecial ? firmwareInfo.NumFramesPerSpecialChara : firmwareInfo.NumFramesPerChara);
256 | if (firmwareInfo.HasName) ++startImageIndex;
257 | }
258 | }
259 |
260 | public void ExportSpriteSheet(string basePath, string extension, int startImageIndex, bool useGreenAsAlpha, bool isSpecial)
261 | {
262 | CheckDisposed();
263 | if (string.IsNullOrEmpty(basePath)) throw new ArgumentNullException(nameof(basePath));
264 | if (string.IsNullOrEmpty(extension)) throw new ArgumentNullException(nameof(extension));
265 | uint numFrames = isSpecial ? firmwareInfo.NumFramesPerSpecialChara : firmwareInfo.NumFramesPerChara;
266 | if (startImageIndex < 0 || startImageIndex + numFrames >= imageInfos.Count)
267 | throw new ArgumentOutOfRangeException(nameof(startImageIndex), "Invalid start image index.");
268 | using var sheetImg = new Image((int)firmwareInfo.CharaSpriteWidth, (int)(firmwareInfo.CharaSpriteHeight * numFrames));
269 | for (int i = 0; i < numFrames; ++i)
270 | {
271 | using var frameImg = GetImage(imageInfos[startImageIndex + i], useGreenAsAlpha);
272 | sheetImg.Mutate(x => x.DrawImage(frameImg, new Point(0, i * (int)firmwareInfo.CharaSpriteHeight), 1.0f));
273 | }
274 | sheetImg.Save(basePath + extension);
275 |
276 | if (firmwareInfo.HasName)
277 | {
278 | using var nameSprite = GetImage(imageInfos[(int)(startImageIndex + numFrames)], useGreenAsAlpha);
279 | nameSprite.Save($"{basePath}{NAME_SUFFIX}{extension}");
280 | }
281 | }
282 |
283 | public void ExportSpriteSheetFolder(string folderPath, string extension, bool useGreenAsAlpha)
284 | {
285 | CheckDisposed();
286 | if (string.IsNullOrEmpty(folderPath)) throw new ArgumentNullException(nameof(folderPath));
287 | int startImageIndex = (int)firmwareInfo.CharasStartIndex;
288 | for (int i = 0; i < firmwareInfo.NumCharas; ++i)
289 | {
290 | string filePath = Path.Combine(folderPath, $"{i}");
291 | bool isSpecial = Array.IndexOf(firmwareInfo.SpecialCharaIndexes, (uint)i) != -1;
292 | if (i < firmwareInfo.NumJogressCharas) ++startImageIndex;
293 | ExportSpriteSheet(filePath, extension, startImageIndex, useGreenAsAlpha, isSpecial);
294 | startImageIndex += (int)(isSpecial ? firmwareInfo.NumFramesPerSpecialChara : firmwareInfo.NumFramesPerChara);
295 | if (firmwareInfo.HasName) ++startImageIndex;
296 | }
297 | }
298 |
299 | protected virtual void Dispose(bool disposing)
300 | {
301 | if (!disposedValue)
302 | {
303 | if (disposing)
304 | {
305 | fwStream.Close();
306 | imageInfos.Clear();
307 | }
308 |
309 | disposedValue = true;
310 | }
311 | }
312 |
313 | public void Dispose()
314 | {
315 | // Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
316 | Dispose(disposing: true);
317 | GC.SuppressFinalize(this);
318 | }
319 | }
320 | }
321 |
--------------------------------------------------------------------------------
/DigimonColorSpriteTool/ImageInfo.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Threading.Tasks;
6 |
7 | namespace DigimonColorSpriteTool
8 | {
9 | internal class ImageInfo
10 | {
11 | public ushort Width { get; set; }
12 | public ushort Height { get; set; }
13 | public int DataOffset { get; set; }
14 | public string? FilePath { get; set; }
15 | public byte[]? OverrideData { get; set; } // Override data takes precedence over FilePath
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/DigimonColorSpriteTool/Program.cs:
--------------------------------------------------------------------------------
1 | // See https://aka.ms/new-console-template for more information
2 |
3 | using DigimonColorSpriteTool;
4 | using System.CommandLine;
5 | using System.CommandLine.Parsing;
6 |
7 | var rootCommand = new RootCommand("Digimon Color Sprite Import/Export Tool");
8 |
9 | // Options
10 | var useGreenAsAlphaOption = new Option("--green-transparency", "Use full green pixel as transparency");
11 | useGreenAsAlphaOption.AddAlias("-g");
12 | var useBmpOption = new Option("--bmp", "Output as BMP");
13 | var numJogressOption = new Option("--num-jogress", () => 0, "Number of jogresses");
14 | numJogressOption.AddAlias("-j");
15 | var sheetRowsOption = new Option("--sheet-rows", "Number of rows in sprite sheet");
16 | sheetRowsOption.ArgumentHelpName = "row";
17 | sheetRowsOption.AddAlias("-sr");
18 | var sheetColsOption = new Option("--sheet-cols", "Number of columns in sprite sheet");
19 | sheetColsOption.ArgumentHelpName = "cols";
20 | sheetColsOption.AddAlias("-sc");
21 | var tortoiseshelOption = new Option("--tortoiseshel", "Use Tortoiseshel sprite sheet layout");
22 | var hasNameOption = new Option("--has-name", "Each character has a name sprite at the end");
23 | var numFramesPerSpecialCharaOption = new Option("--num-frames-per-special-chara", () => 0, "Number of frames for special characters");
24 | numFramesPerSpecialCharaOption.ArgumentHelpName = "frames";
25 | numFramesPerSpecialCharaOption.AddAlias("-nfs");
26 | var specialCharaIndexesOption = new Option("--special-chara", "List of special character indexes");
27 | specialCharaIndexesOption.ArgumentHelpName = "index";
28 | specialCharaIndexesOption.AddAlias("-sp");
29 |
30 | // Arguments
31 | var presetNameArgument = new Argument("presetName", "Device firmware preset name")
32 | .FromAmong(FirmwareInfo.Presets.Keys.ToArray());
33 | var spritePackBaseArgument = new Argument("spritePackBase", "Sprite pack offset in flash");
34 | var sizeTableOffsetArgument = new Argument("sizeTableOffset", "Size table offset");
35 | var numImagesArgument = new Argument("numImages", "Number of images in ROM");
36 | var numCharasArgument = new Argument("numCharas", "Number of characters in ROM");
37 | var numFramesPerCharaArgument = new Argument("numFramesPerChara", "Number of frames per character");
38 | var charaStartIndexArgument = new Argument("charaStartIndex", "Index of first character sprite");
39 |
40 | var romPathArgument = new Argument("romPath", "Path to flash dump").ExistingOnly();
41 | var outDirArgument = new Argument("outDir", "Output directory").LegalFilePathsOnly();
42 | var outFileArgument = new Argument("outFile", "Output file").LegalFilePathsOnly();
43 | outFileArgument.Arity = ArgumentArity.ZeroOrOne;
44 | var inDirArgument = new Argument("inDir", "Input directory").ExistingOnly();
45 |
46 | #region Command handlers
47 | void DoExport(FileInfo romFile, FirmwareInfo fwInfo, DirectoryInfo outDir, bool useBmp, bool useGreenAsAlpha)
48 | {
49 | if (useBmp) useGreenAsAlpha = true;
50 | using var impExp = new ImageImportExport(romFile.OpenRead(), fwInfo);
51 | outDir.Create();
52 | impExp.ExportAllImages(outDir.FullName, useBmp ? ".bmp" : ".png", useGreenAsAlpha);
53 | }
54 |
55 | void DoImport(FileInfo romFile, FirmwareInfo fwInfo, DirectoryInfo inDir, FileInfo? outFile, bool useGreenAsAlpha)
56 | {
57 | bool needCopyOverSrc = outFile == null || outFile.FullName == romFile.FullName; // Not foolproof
58 | if (needCopyOverSrc) outFile = new FileInfo(Path.GetTempFileName());
59 | using (var impExp = new ImageImportExport(romFile.OpenRead(), fwInfo))
60 | {
61 | impExp.SetOverridesByFolder(inDir.FullName);
62 | impExp.Rebuild(outFile.FullName, useGreenAsAlpha);
63 | }
64 | if (needCopyOverSrc)
65 | {
66 | outFile.CopyTo(romFile.FullName, true);
67 | outFile.Delete();
68 | }
69 | }
70 |
71 | void DoExportSheets(FileInfo romFile, FirmwareInfo fwInfo, DirectoryInfo outDir, bool useGreenAsAlpha, bool useBmp)
72 | {
73 | if (useBmp) useGreenAsAlpha = true;
74 | using var impExp = new ImageImportExport(romFile.OpenRead(), fwInfo);
75 | outDir.Create();
76 | impExp.ExportSpriteSheetFolder(outDir.FullName, useBmp ? ".bmp" : ".png", useGreenAsAlpha);
77 | }
78 |
79 | void DoImportSheets(FileInfo romFile, FirmwareInfo fwInfo, DirectoryInfo inDir, FileInfo? outFile, bool useGreenAsAlpha, uint? rows, uint? cols)
80 | {
81 | bool needCopyOverSrc = outFile == null || outFile.FullName == romFile.FullName; // Not foolproof
82 | if (needCopyOverSrc) outFile = new FileInfo(Path.GetTempFileName());
83 | using (var impExp = new ImageImportExport(romFile.OpenRead(), fwInfo))
84 | {
85 | impExp.ImportSpriteSheetFolder(inDir.FullName, useGreenAsAlpha, rows, cols);
86 | impExp.Rebuild(outFile.FullName, useGreenAsAlpha);
87 | }
88 | if (needCopyOverSrc)
89 | {
90 | outFile.CopyTo(romFile.FullName, true);
91 | outFile.Delete();
92 | }
93 | }
94 | #endregion
95 |
96 | #region Commands with presets
97 | var exportPresetCmd = new Command("export-preset", "Export all sprites using firmware preset")
98 | {
99 | useGreenAsAlphaOption, useBmpOption, romPathArgument, presetNameArgument, outDirArgument
100 | };
101 | rootCommand.AddCommand(exportPresetCmd);
102 |
103 | exportPresetCmd.SetHandler(context =>
104 | {
105 | var pr = context.ParseResult;
106 | var useGreenAsAlpha = pr.GetValueForOption(useGreenAsAlphaOption);
107 | var useBmp = pr.GetValueForOption(useBmpOption);
108 | var romPath = pr.GetValueForArgument(romPathArgument);
109 | var presetName = pr.GetValueForArgument(presetNameArgument);
110 | var outDir = pr.GetValueForArgument(outDirArgument);
111 |
112 | var fwInfo = FirmwareInfo.Presets[presetName];
113 |
114 | DoExport(romPath, fwInfo, outDir, useBmp, useGreenAsAlpha);
115 | });
116 |
117 | var importPresetCmd = new Command("import-preset", "Import sprites using firmware preset")
118 | {
119 | useGreenAsAlphaOption, romPathArgument, presetNameArgument, inDirArgument, outFileArgument
120 | };
121 | rootCommand.AddCommand(importPresetCmd);
122 |
123 | importPresetCmd.SetHandler(context =>
124 | {
125 | var pr = context.ParseResult;
126 | var useGreenAsAlpha = pr.GetValueForOption(useGreenAsAlphaOption);
127 | var romPath = pr.GetValueForArgument(romPathArgument);
128 | var presetName = pr.GetValueForArgument(presetNameArgument);
129 | var inDir = pr.GetValueForArgument(inDirArgument);
130 | var outFile = pr.GetValueForArgument(outFileArgument);
131 |
132 | var fwInfo = FirmwareInfo.Presets[presetName];
133 |
134 | DoImport(romPath, fwInfo, inDir, outFile, useGreenAsAlpha);
135 | });
136 |
137 | var exportSheetsPresetCmd = new Command("export-sheets-preset", "Export all character sprite sheets using firmware preset")
138 | {
139 | useGreenAsAlphaOption, useBmpOption, specialCharaIndexesOption, romPathArgument, presetNameArgument, outDirArgument
140 | };
141 | rootCommand.Add(exportSheetsPresetCmd);
142 |
143 | exportSheetsPresetCmd.SetHandler(context =>
144 | {
145 | var pr = context.ParseResult;
146 | var useGreenAsAlpha = pr.GetValueForOption(useGreenAsAlphaOption);
147 | var useBmp = pr.GetValueForOption(useBmpOption);
148 | var romPath = pr.GetValueForArgument(romPathArgument);
149 | var presetName = pr.GetValueForArgument(presetNameArgument);
150 | var outDir = pr.GetValueForArgument(outDirArgument);
151 |
152 | var fwInfo = FirmwareInfo.Presets[presetName];
153 | if (pr.HasOption(specialCharaIndexesOption))
154 | {
155 | fwInfo.SpecialCharaIndexes = pr.GetValueForOption(specialCharaIndexesOption)!;
156 | }
157 |
158 | DoExportSheets(romPath, fwInfo, outDir, useGreenAsAlpha, useBmp);
159 | });
160 |
161 | var importSheetsPresetCmd = new Command("import-sheets-preset", "Import character sprite sheets using firmware preset")
162 | {
163 | useGreenAsAlphaOption, specialCharaIndexesOption, sheetRowsOption, sheetColsOption, tortoiseshelOption,
164 | romPathArgument, presetNameArgument, inDirArgument, outFileArgument
165 | };
166 | rootCommand.AddCommand(importSheetsPresetCmd);
167 |
168 | importSheetsPresetCmd.SetHandler(context =>
169 | {
170 | var pr = context.ParseResult;
171 | var useGreenAsAlpha = pr.GetValueForOption(useGreenAsAlphaOption);
172 | var sheetRows = pr.GetValueForOption(sheetRowsOption);
173 | var sheetCols = pr.GetValueForOption(sheetColsOption);
174 | var isTortoiseshel = pr.GetValueForOption(tortoiseshelOption);
175 | var romPath = pr.GetValueForArgument(romPathArgument);
176 | var presetName = pr.GetValueForArgument(presetNameArgument);
177 | var inDir = pr.GetValueForArgument(inDirArgument);
178 | var outFile = pr.GetValueForArgument(outFileArgument);
179 |
180 | var fwInfo = FirmwareInfo.Presets[presetName];
181 | if (pr.HasOption(specialCharaIndexesOption))
182 | {
183 | fwInfo.SpecialCharaIndexes = pr.GetValueForOption(specialCharaIndexesOption)!;
184 | }
185 | if (isTortoiseshel)
186 | {
187 | sheetRows = 4;
188 | sheetCols = 3;
189 | }
190 |
191 | DoImportSheets(romPath, fwInfo, inDir, outFile, useGreenAsAlpha, sheetRows, sheetCols);
192 | });
193 |
194 | var showPresetCmd = new Command("show-preset", "Show the parameters of a preset")
195 | {
196 | presetNameArgument
197 | };
198 | rootCommand.Add(showPresetCmd);
199 |
200 | showPresetCmd.SetHandler(presetName =>
201 | {
202 | var fwInfo = FirmwareInfo.Presets[presetName];
203 | Console.WriteLine($"Name: {presetName}");
204 | Console.WriteLine($"{nameof(fwInfo.SpritePackBase)}: {fwInfo.SpritePackBase}");
205 | Console.WriteLine($"{nameof(fwInfo.CharaSpriteWidth)}: {fwInfo.CharaSpriteWidth}");
206 | Console.WriteLine($"{nameof(fwInfo.CharaSpriteHeight)}: {fwInfo.CharaSpriteHeight}");
207 | Console.WriteLine($"{nameof(fwInfo.SizeTableOffset)}: {fwInfo.SizeTableOffset}");
208 | Console.WriteLine($"{nameof(fwInfo.NumImages)}: {fwInfo.NumImages}");
209 | Console.WriteLine($"{nameof(fwInfo.NumCharas)}: {fwInfo.NumCharas}");
210 | Console.WriteLine($"{nameof(fwInfo.NumFramesPerChara)}: {fwInfo.NumFramesPerChara}");
211 | Console.WriteLine($"{nameof(fwInfo.CharasStartIndex)}: {fwInfo.CharasStartIndex}");
212 | Console.WriteLine($"{nameof(fwInfo.NumJogressCharas)}: {fwInfo.NumJogressCharas}");
213 | Console.WriteLine($"{nameof(fwInfo.HasName)}: {fwInfo.HasName}");
214 | Console.WriteLine($"{nameof(fwInfo.NumFramesPerSpecialChara)}: {fwInfo.NumFramesPerSpecialChara}");
215 | Console.WriteLine($"{nameof(fwInfo.SpecialCharaIndexes)}: [{string.Join(", ", fwInfo.SpecialCharaIndexes)}]");
216 | }, presetNameArgument);
217 | #endregion
218 |
219 | #region Commands without presets
220 | var exportCmd = new Command("export", "Export all sprites")
221 | {
222 | useGreenAsAlphaOption, useBmpOption, romPathArgument, spritePackBaseArgument, sizeTableOffsetArgument,
223 | numImagesArgument, outDirArgument
224 | };
225 | rootCommand.AddCommand(exportCmd);
226 |
227 | exportCmd.SetHandler(context =>
228 | {
229 | var pr = context.ParseResult;
230 | var useGreenAsAlpha = pr.GetValueForOption(useGreenAsAlphaOption);
231 | var useBmp = pr.GetValueForOption(useBmpOption);
232 | var romPath = pr.GetValueForArgument(romPathArgument);
233 | var spritePackBase = pr.GetValueForArgument(spritePackBaseArgument);
234 | var sizeTableOffset = pr.GetValueForArgument(sizeTableOffsetArgument);
235 | var numImages = pr.GetValueForArgument(numImagesArgument);
236 | var outDir = pr.GetValueForArgument(outDirArgument);
237 |
238 | var fwInfo = new FirmwareInfo
239 | {
240 | SpritePackBase = spritePackBase,
241 | SizeTableOffset = sizeTableOffset,
242 | NumImages = numImages,
243 | };
244 |
245 | DoExport(romPath, fwInfo, outDir, useBmp, useGreenAsAlpha);
246 | });
247 |
248 | var importCmd = new Command("import", "Import sprites")
249 | {
250 | useGreenAsAlphaOption, romPathArgument, spritePackBaseArgument, sizeTableOffsetArgument,
251 | numImagesArgument, inDirArgument, outFileArgument
252 | };
253 | rootCommand.AddCommand(importCmd);
254 |
255 | importCmd.SetHandler(context =>
256 | {
257 | var pr = context.ParseResult;
258 | var useGreenAsAlpha = pr.GetValueForOption(useGreenAsAlphaOption);
259 | var romPath = pr.GetValueForArgument(romPathArgument);
260 | var spritePackBase = pr.GetValueForArgument(spritePackBaseArgument);
261 | var sizeTableOffset = pr.GetValueForArgument(sizeTableOffsetArgument);
262 | var numImages = pr.GetValueForArgument(numImagesArgument);
263 | var inDir = pr.GetValueForArgument(inDirArgument);
264 | var outFile = pr.GetValueForArgument(outFileArgument);
265 |
266 | var fwInfo = new FirmwareInfo
267 | {
268 | SpritePackBase = spritePackBase,
269 | SizeTableOffset = sizeTableOffset,
270 | NumImages = numImages,
271 | };
272 |
273 | DoImport(romPath, fwInfo, inDir, outFile, useGreenAsAlpha);
274 | });
275 |
276 | var exportSheetsCmd = new Command("export-sheets", "Export all character sprite sheets")
277 | {
278 | useGreenAsAlphaOption, useBmpOption, numJogressOption, hasNameOption, numFramesPerSpecialCharaOption,
279 | specialCharaIndexesOption, romPathArgument, outDirArgument, spritePackBaseArgument,
280 | sizeTableOffsetArgument, numImagesArgument, numCharasArgument, numFramesPerCharaArgument,
281 | charaStartIndexArgument
282 | };
283 | rootCommand.Add(exportSheetsCmd);
284 |
285 | exportSheetsCmd.SetHandler(context =>
286 | {
287 | var pr = context.ParseResult;
288 | var useGreenAsAlpha = pr.GetValueForOption(useGreenAsAlphaOption);
289 | var useBmp = pr.GetValueForOption(useBmpOption);
290 | var numJogresses = pr.GetValueForOption(numJogressOption);
291 | var romPath = pr.GetValueForArgument(romPathArgument);
292 | var outDir = pr.GetValueForArgument(outDirArgument);
293 | var spritePackBase = pr.GetValueForArgument(spritePackBaseArgument);
294 | var sizeTableOffset = pr.GetValueForArgument(sizeTableOffsetArgument);
295 | var numImages = pr.GetValueForArgument(numImagesArgument);
296 | var numCharas = pr.GetValueForArgument(numCharasArgument);
297 | var numFramesPerChara = pr.GetValueForArgument(numFramesPerCharaArgument);
298 | var charaStartIndex = pr.GetValueForArgument(charaStartIndexArgument);
299 | var hasName = pr.GetValueForOption(hasNameOption);
300 | var numFramesPerSpecialChara = pr.GetValueForOption(numFramesPerSpecialCharaOption);
301 | var specialCharaIndexes = pr.GetValueForOption(specialCharaIndexesOption);
302 |
303 | var fwInfo = new FirmwareInfo
304 | {
305 | SpritePackBase = spritePackBase,
306 | SizeTableOffset = sizeTableOffset,
307 | NumImages = numImages,
308 | NumCharas = numCharas,
309 | NumFramesPerChara = numFramesPerChara,
310 | CharasStartIndex = charaStartIndex,
311 | NumJogressCharas = numJogresses,
312 | HasName = hasName,
313 | NumFramesPerSpecialChara = numFramesPerSpecialChara,
314 | SpecialCharaIndexes = specialCharaIndexes ?? [],
315 | };
316 |
317 | DoExportSheets(romPath, fwInfo, outDir, useGreenAsAlpha, useBmp);
318 | });
319 |
320 | var importSheetsCmd = new Command("import-sheets", "Import character sprite sheets")
321 | {
322 | useGreenAsAlphaOption, numJogressOption, hasNameOption, numFramesPerSpecialCharaOption,
323 | specialCharaIndexesOption, sheetRowsOption, sheetColsOption, tortoiseshelOption,
324 | romPathArgument, spritePackBaseArgument, sizeTableOffsetArgument, numImagesArgument,
325 | numCharasArgument, numFramesPerCharaArgument, charaStartIndexArgument, inDirArgument,
326 | outFileArgument
327 | };
328 | rootCommand.AddCommand(importSheetsCmd);
329 |
330 | importSheetsCmd.SetHandler(context =>
331 | {
332 | var pr = context.ParseResult;
333 | var useGreenAsAlpha = pr.GetValueForOption(useGreenAsAlphaOption);
334 | var numJogresses = pr.GetValueForOption(numJogressOption);
335 | var sheetRows = pr.GetValueForOption(sheetRowsOption);
336 | var sheetCols = pr.GetValueForOption(sheetColsOption);
337 | var isTortoiseshel = pr.GetValueForOption(tortoiseshelOption);
338 | var romPath = pr.GetValueForArgument(romPathArgument);
339 | var spritePackBase = pr.GetValueForArgument(spritePackBaseArgument);
340 | var sizeTableOffset = pr.GetValueForArgument(sizeTableOffsetArgument);
341 | var numImages = pr.GetValueForArgument(numImagesArgument);
342 | var numCharas = pr.GetValueForArgument(numCharasArgument);
343 | var numFramesPerChara = pr.GetValueForArgument(numFramesPerCharaArgument);
344 | var charaStartIndex = pr.GetValueForArgument(charaStartIndexArgument);
345 | var inDir = pr.GetValueForArgument(inDirArgument);
346 | var outFile = pr.GetValueForArgument(outFileArgument);
347 | var hasName = pr.GetValueForOption(hasNameOption);
348 | var numFramesPerSpecialChara = pr.GetValueForOption(numFramesPerSpecialCharaOption);
349 | var specialCharaIndexes = pr.GetValueForOption(specialCharaIndexesOption);
350 |
351 | var fwInfo = new FirmwareInfo
352 | {
353 | SpritePackBase = spritePackBase,
354 | SizeTableOffset = sizeTableOffset,
355 | NumImages = numImages,
356 | NumCharas = numCharas,
357 | NumFramesPerChara = numFramesPerChara,
358 | CharasStartIndex = charaStartIndex,
359 | NumJogressCharas = numJogresses,
360 | HasName = hasName,
361 | NumFramesPerSpecialChara = numFramesPerSpecialChara,
362 | SpecialCharaIndexes = specialCharaIndexes ?? [],
363 | };
364 | if (isTortoiseshel)
365 | {
366 | sheetRows = 4;
367 | sheetCols = 3;
368 | }
369 |
370 | DoImportSheets(romPath, fwInfo, inDir, outFile, useGreenAsAlpha, sheetRows, sheetCols);
371 | });
372 | #endregion
373 |
374 | return rootCommand.Invoke(args);
375 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Digimon Color Sprite Import/Export Tool
2 | =======================================
3 |
4 | This tool allows you to easily extract and reimport sprites for Digimon Color
5 | and Pendulum Color. It also supports exporting/importing as sprite sheets for
6 | character sprites, and also accepts sprites with different dimensions than the
7 | original.
8 |
9 | [](https://ko-fi.com/C0C81P4PX)
10 |
11 | Usage
12 | -----
13 |
14 | ### Export sprites
15 |
16 | ```
17 | DigimonColorSpriteTool.exe export-preset [options]
18 | ```
19 |
20 | Where:
21 | - `romPath`: Path to flash dump
22 | - `version`: Flash dump version, one of `dmc1`, `dmc2`, `dmc3`, `dmc4`, `dmc5`, `dmcmh`
23 | for Digimon Color versions, and `penc1`, `penc2`, `penc3`, `penc4`, `penc5`,
24 | `penc0` for Pendulum Color versions
25 | - `outDir`: The directory to export into
26 |
27 | Files are exported as PNG files into `outDir` with transparent background.
28 | You can export with green background by using the `-g` option, and to BMP with
29 | the `--bmp` option.
30 |
31 | ### Import sprites
32 |
33 | ```
34 | DigimonColorSpriteTool.exe import-preset [options] []
35 | ```
36 |
37 | `inDir` is a path to the folder that contains the sprites to import. You
38 | only need to provide the sprites you want to overwrite, named with the correct
39 | index. `outFile` is the path to the repacked ROM file. If omitted, the
40 | original file will be overwritten. Use the `-g` option if your backgrounds are
41 | green. Otherwise, any pure green pixels will be slightly adjusted so they show
42 | up as green on-device. BMPs will be imported with the `-g` option applied.
43 |
44 | ### Export sprite sheet
45 |
46 | ```
47 | DigimonColorSpriteTool.exe export-sheets-preset [options]
48 | ```
49 |
50 | Sprite sheets consist of a vertical column of character sprites. You can edit
51 | and reimport sheets. Same options as previous apply. If the characters have name
52 | sprites, it will be stored under the same name and extension as the sprite sheet
53 | except with `_name` appended to the name part, i.e. `4.png` would have a name
54 | counterpart named `4_name.png`.
55 |
56 |
57 | ### Import sprite sheet
58 |
59 | ```
60 | DigimonColorSpriteTool.exe import-sheets-preset [options] []
61 | ```
62 |
63 | Additional options:
64 | - `-g`: Same as before
65 | - `-sr`: Number of rows in sprite sheet
66 | - `-sc`: Number of columns in sprite sheet
67 | - `--tortoiseshel`: Sets columns and rows to 3x4
68 |
69 | When importing sprite sheets, by default it uses 1 column and the same number of
70 | rows as there are sprite frames per character. You can change this with `-sr`
71 | and `-sc` options. Note that there needs to be enough frames for each character,
72 | and each frame must be smaller or equal to 48x48, and can be scaled up to 48x48
73 | by whole multiples. For example, 16x16 frames can be scaled up, but 20x20 frames
74 | cannot be, and 64x64 frames are too large. All sheets in the folder must use the
75 | same layout. You can omit sheets for characters that you do not want to replace.
76 | If name sprites are supported, make sure they are named in the way described in
77 | the previous section. If the name sprite is omitted or improperly named, it will
78 | not be updated in the resulting file.
79 |
80 | ### Special characters
81 |
82 | Certain Digimon Color variants may have characters with additional sprites.
83 | These are designated as "special characters" and their indexes may be specified
84 | with one or more `-sp` options followed by the index. For example, if index 0,
85 | 2, and 9 are special, you would add the options `-sp 0 -sp 2 -sp 9`. This option
86 | is available for sprite sheet related commands: `export-sheets-preset`,
87 | `import-sheets-preset`, `export-sheets`, `import-sheets`.
88 |
89 | ### Non-preset commands
90 |
91 | Each command is also available in non-preset versions. See usage help in-program
92 | for the commands and their arguments. An explanation of the arguments is as
93 | follows:
94 |
95 | - `spritePackBase`: Flash offset of the beginning of the sprite data. It is
96 | `524288` for DMC, and `4194304` for PenC.
97 | - `sizeTableOffset`: Flash offset of the sprite sizes table
98 | - `numImages`: Total number of images in sprite data
99 | - `numCharas`: Number of characters in sprite data. This is the number of full
100 | sprite frame sets, not including single-frame jogress characters
101 | - `numFramesPerChara`: Number of frames per character. `15` for DMC, `12` for
102 | PenC
103 | - `charaStartIndex`: Start index of character sprites. `210` for DMC, `240` for
104 | PenC
105 | - `-j`: Number of jogress characters. If jogress character images are
106 | interspersed before full set characters, indicate the number of such jogress
107 | characters. Do not include jogress characters after full set characters
108 | - `--has-name`: Each character has a name sprite following the character frames
109 | - `-nfs`: Number of frames for special characters
110 | - `-sp`: Specifies the index of a special character. Can be repeated multiple
111 | times
112 |
113 | You can print the values for those arguments from presets using the
114 | `show-preset` command:
115 |
116 | ```
117 | DigimonColorSpriteTool.exe show-preset
118 | ```
119 |
120 | For special character indexes, specify each separately using the `-sp` option.
121 |
--------------------------------------------------------------------------------