1- using System ;
1+ using Newtonsoft . Json ;
2+ using System ;
23using System . Collections . Generic ;
34using System . Diagnostics ;
45using System . IO ;
56using System . Reflection ;
67using System . Text ;
78using System . Windows . Forms ;
8- using Newtonsoft . Json ;
99namespace ARM9Editor
1010{
1111 public partial class App : Form
@@ -31,11 +31,13 @@ public App()
3131 weatherlistBox . DoubleClick += weatherListBox_DoubleClick ;
3232 emblemlistBox . DoubleClick += emblemListBox_DoubleClick ;
3333 kartlistBox . DoubleClick += kartListBox_DoubleClick ;
34+ characterlistBox . DoubleClick += characterListBox_DoubleClick ;
3435 LoadMusicOffsets ( ) ;
3536 LoadCourseOffsets ( ) ;
3637 LoadSlotOffsets ( ) ;
3738 LoadEmblemOffsets ( ) ;
3839 LoadKartOffsets ( ) ;
40+ LoadCharacterOffsets ( ) ;
3941 }
4042 private void LoadMusicOffsets ( )
4143 {
@@ -133,6 +135,22 @@ private void LoadKartOffsets()
133135 MessageBox . Show ( $ "Failed to load kart offsets: { ex . Message } ", "Error" , MessageBoxButtons . OK , MessageBoxIcon . Error ) ;
134136 }
135137 }
138+ private void LoadCharacterOffsets ( )
139+ {
140+ var assembly = Assembly . GetExecutingAssembly ( ) ;
141+ var resourceName = "ARM9Editor.assets.json.character_offsets.json" ;
142+ try
143+ {
144+ using var stream = assembly . GetManifestResourceStream ( resourceName ) ;
145+ using var reader = new StreamReader ( stream ) ;
146+ string jsonData = reader . ReadToEnd ( ) ;
147+ characterOffsets = JsonConvert . DeserializeObject < Dictionary < string , int > > ( jsonData ) ;
148+ }
149+ catch ( Exception ex )
150+ {
151+ MessageBox . Show ( $ "Failed to load character offsets: { ex . Message } ", "Error" , MessageBoxButtons . OK , MessageBoxIcon . Error ) ;
152+ }
153+ }
136154 private string GetFileName ( int startOffset , int endOffset )
137155 {
138156 if ( armValues == null || startOffset < 0 || endOffset > armValues . Length || startOffset >= endOffset )
@@ -162,6 +180,7 @@ private void openToolStripMenuItem_Click(object sender, EventArgs e)
162180 RefreshWeatherListBox ( ) ;
163181 RefreshEmblemListBox ( ) ;
164182 RefreshKartListBox ( ) ;
183+ RefreshCharacterListBox ( ) ;
165184 }
166185 }
167186 private void saveToolStripMenuItem_Click ( object sender , EventArgs e )
@@ -259,7 +278,7 @@ private void RefreshKartListBox()
259278 {
260279 if ( emblemOffsets == null || armValues == null )
261280 {
262- MessageBox . Show ( "Emblem offsets or ARM values are not loaded." , "Error" , MessageBoxButtons . OK , MessageBoxIcon . Error ) ;
281+ MessageBox . Show ( "Kart offsets or ARM values are not loaded." , "Error" , MessageBoxButtons . OK , MessageBoxIcon . Error ) ;
263282 return ;
264283 }
265284 kartlistBox . Items . Clear ( ) ;
@@ -271,6 +290,22 @@ private void RefreshKartListBox()
271290 kartlistBox . Items . Add ( $ "{ kartName } [{ kartValue } ]") ;
272291 }
273292 }
293+ private void RefreshCharacterListBox ( )
294+ {
295+ if ( characterOffsets == null || armValues == null )
296+ {
297+ MessageBox . Show ( "Character offsets or ARM values are not loaded." , "Error" , MessageBoxButtons . OK , MessageBoxIcon . Error ) ;
298+ return ;
299+ }
300+ characterlistBox . Items . Clear ( ) ;
301+ foreach ( var kvp in characterOffsets )
302+ {
303+ string characterName = kvp . Key ;
304+ int offset = kvp . Value ;
305+ string characterValue = Encoding . ASCII . GetString ( armValues , offset , 4 ) . TrimEnd ( '\0 ' ) ;
306+ characterlistBox . Items . Add ( $ "{ characterName } [{ characterValue } ]") ;
307+ }
308+ }
274309 private void musicListBox_DoubleClick ( object sender , EventArgs e )
275310 {
276311 if ( musicOffsets == null || armValues == null )
@@ -315,7 +350,7 @@ private void courseListBox_DoubleClick(object sender, EventArgs e)
315350 string courseName = selectedItem . Split ( '[' ) [ 0 ] . Trim ( ) ;
316351 var offsets = courseOffsets [ courseName ] ;
317352
318- using var form = new ChangeFileNameForm ( armValues , offsets . Item1 , offsets . Item2 ) ;
353+ using var form = new ChangeCourseFileNameForm ( armValues , offsets . Item1 , offsets . Item2 ) ;
319354 {
320355 if ( form . ShowDialog ( ) == DialogResult . OK )
321356 {
@@ -403,6 +438,29 @@ private void kartListBox_DoubleClick(object sender, EventArgs e)
403438 }
404439 }
405440 }
441+ private void characterListBox_DoubleClick ( object sender , EventArgs e )
442+ {
443+ if ( characterOffsets == null || armValues == null )
444+ {
445+ MessageBox . Show ( "Character offsets or ARM values are not loaded." , "Error" , MessageBoxButtons . OK , MessageBoxIcon . Error ) ;
446+ return ;
447+ }
448+ if ( characterlistBox . SelectedItem != null )
449+ {
450+ string selectedItem = characterlistBox . SelectedItem . ToString ( ) ;
451+ string characterName = selectedItem . Split ( '[' ) [ 0 ] . Trim ( ) ;
452+ int offset = characterOffsets [ characterName ] ;
453+
454+ using var form = new ChangeCharacterFileNameForm ( armValues , offset ) ;
455+ {
456+ if ( form . ShowDialog ( ) == DialogResult . OK )
457+ {
458+ RefreshCharacterListBox ( ) ;
459+ MessageBox . Show ( $ "Character name for { characterName } changed to { form . NewCharacterName } .", "Success" , MessageBoxButtons . OK , MessageBoxIcon . Information ) ;
460+ }
461+ }
462+ }
463+ }
406464 private void repositoryToolStripMenuItem_Click ( object sender , EventArgs e )
407465 {
408466 string githubUrl = "https://github.com/LandonAndEmma/MKDS-ARM9-EDITOR-VS" ;
0 commit comments