@@ -10,27 +10,21 @@ namespace CountEmblems
1010 class Program
1111 {
1212 // Previous amount of emblems
13- static int previousTotal ;
13+ static string previousTotal ;
1414 // Previous error in the loop
1515 static string previousError ;
1616 // 4 (version check) + 4 (playtime) + 1 (modified) + 1035 (maps visited)
17- const int SKIPPED_BYTES = 1044 ;
18- const int MAXEMBLEMS = 512 ;
19- const int MAXEXTRAEMBLEMS = 16 ;
20- const int EXIT_TIME = 10000 ;
21- const int NO_PREVIOUS_TOTAL = - 1 ;
17+ const string NO_PREVIOUS_TOTAL = "" ;
2218 const string PREVIOUS_INI_NAME = "previous.ini" ;
2319 const string CURRENT_INI_NAME = "current.ini" ;
2420 static string previousFileName ;
25- static string previousOutputName ;
2621 static Form MainForm ;
2722 static Form IOForm ;
2823 static Form EditForm ;
2924 static Label emblemLabel ;
3025 static Button button2FontColor ;
3126 static Button button2BackgroundColor ;
3227 static TextBox gamedataBox ;
33- static TextBox outputBox ;
3428 static Color previousFontColor ;
3529 static Color previousBackColor ;
3630 static Font previousFont ;
@@ -49,19 +43,6 @@ static string fileName
4943 }
5044 }
5145 }
52- static string outputNameMember ;
53- static string outputName
54- {
55- get { return outputNameMember ; }
56- set
57- {
58- outputNameMember = value ;
59- if ( outputBox != null )
60- {
61- outputBox . Text = value ;
62- }
63- }
64- }
6546 // The font's color
6647 static Color fontColorMember ;
6748 static Color fontColor
@@ -146,41 +127,18 @@ static byte ReadByte(ref byte[] bytes)
146127 bytes = bytes . Skip ( 1 ) . ToArray ( ) ;
147128 return value ;
148129 }
149- static int CountEmblems ( ref byte [ ] bytes , int max_emblems )
150- {
151- int result = 0 ;
152- for ( int i = 0 ; i < max_emblems ; )
153- {
154- // Function directly copied from SRB2 source code, where the gamedata handling happens
155- int j ;
156- byte rtemp = ReadByte ( ref bytes ) ;
157- for ( j = 0 ; j < 8 && j + i < max_emblems ; ++ j )
158- result += ( ( rtemp >> j ) & 1 ) ;
159- i += j ;
160- }
161- return result ;
162- }
163- static void Analyze_file ( string fileName , string outputName )
130+ static void Analyze_file ( string fileName )
164131 {
165- byte [ ] bytes ;
166- int total = previousTotal ;
132+ string text ;
133+ string total = previousTotal ;
167134 if ( fileName != null && fileName != "" )
168135 {
169136 try
170137 {
171- bytes = File . ReadAllBytes ( fileName ) ;
172- // We don't want to read empty/corrupted gamedata
173- if ( bytes . Length < SKIPPED_BYTES + MAXEMBLEMS + MAXEXTRAEMBLEMS && previousError != "short" )
174- {
175- //Console.WriteLine("The gamedata is too short.");
176- previousError = "short" ;
177- }
178- else
138+ text = File . ReadAllText ( fileName ) ;
139+ if ( text != "" )
179140 {
180- bytes = bytes . Skip ( SKIPPED_BYTES ) . ToArray ( ) ;
181- int emblems = CountEmblems ( ref bytes , MAXEMBLEMS ) ;
182- int extraEmblems = CountEmblems ( ref bytes , MAXEXTRAEMBLEMS ) ;
183- total = emblems + extraEmblems ;
141+ total = text ;
184142 }
185143 }
186144 catch ( FileNotFoundException e )
@@ -201,7 +159,7 @@ static void Analyze_file(string fileName, string outputName)
201159
202160 if ( total == NO_PREVIOUS_TOTAL )
203161 {
204- total = 0 ;
162+ total = "" ;
205163 }
206164 if ( total != previousTotal )
207165 {
@@ -211,15 +169,10 @@ static void Analyze_file(string fileName, string outputName)
211169 {
212170 emblemLabel . BeginInvoke ( new MethodInvoker ( delegate
213171 {
214- emblemLabel . Text = total . ToString ( ) ;
172+ emblemLabel . Text = total ;
215173 } ) ) ;
216174 }
217175
218- if ( outputName != null && outputName != "" )
219- {
220- File . WriteAllText ( outputName , total . ToString ( ) ) ;
221- }
222-
223176 previousTotal = total ;
224177 }
225178 catch ( IOException e )
@@ -242,7 +195,8 @@ static Form MakeForm(Size size, Color backcolor, string windowTitle)
242195 form . StartPosition = FormStartPosition . CenterScreen ;
243196 form . BackColor = backcolor ;
244197 form . Text = windowTitle ;
245- form . Icon = new Icon ( "icon.ico" ) ;
198+ //removed icon atm because i'm too lazy to do an other one lol
199+ //form.Icon = new Icon("icon.ico");
246200 form . ShowIcon = true ;
247201 return form ;
248202 }
@@ -330,7 +284,6 @@ static void FormExit(object sender, FormClosingEventArgs e)
330284 static void MenuIO_Options ( object sender , EventArgs e )
331285 {
332286 previousFileName = fileName ;
333- previousOutputName = outputName ;
334287 Thread . CurrentThread . IsBackground = true ;
335288 IOForm . ShowDialog ( ) ;
336289 }
@@ -394,7 +347,7 @@ static void SaveFile(string file)
394347 string size = width + "," + height ;
395348
396349 FontConverter fc = new FontConverter ( ) ;
397- string [ ] contents = { fileName , outputName , fontColorS , backColorS , fc . ConvertToString ( currentFont ) , size } ;
350+ string [ ] contents = { fileName , fontColorS , backColorS , fc . ConvertToString ( currentFont ) , size } ;
398351 File . WriteAllLines ( file , contents ) ;
399352 }
400353 catch
@@ -425,28 +378,26 @@ static void LoadFile(string file)
425378 {
426379 string [ ] contents = File . ReadAllLines ( file ) ;
427380 fileName = contents [ 0 ] ;
428- outputName = contents [ 1 ] ;
429381 gamedataBox . Text = fileName ;
430- outputBox . Text = outputName ;
431382
432- string [ ] fColor = contents [ 2 ] . Split ( ',' ) ;
383+ string [ ] fColor = contents [ 1 ] . Split ( ',' ) ;
433384 int fA = Int32 . Parse ( fColor [ 0 ] ) ;
434385 int fR = Int32 . Parse ( fColor [ 1 ] ) ;
435386 int fG = Int32 . Parse ( fColor [ 2 ] ) ;
436387 int fB = Int32 . Parse ( fColor [ 3 ] ) ;
437388 fontColor = Color . FromArgb ( fA , fR , fG , fB ) ;
438389
439- string [ ] bColor = contents [ 3 ] . Split ( ',' ) ;
390+ string [ ] bColor = contents [ 2 ] . Split ( ',' ) ;
440391 int bA = Int32 . Parse ( bColor [ 0 ] ) ;
441392 int bR = Int32 . Parse ( bColor [ 1 ] ) ;
442393 int bG = Int32 . Parse ( bColor [ 2 ] ) ;
443394 int bB = Int32 . Parse ( bColor [ 3 ] ) ;
444395 backColor = Color . FromArgb ( bA , bR , bG , bB ) ;
445396
446397 FontConverter fc = new FontConverter ( ) ;
447- currentFont = fc . ConvertFromString ( contents [ 4 ] ) as Font ;
398+ currentFont = fc . ConvertFromString ( contents [ 3 ] ) as Font ;
448399
449- string [ ] size = contents [ 5 ] . Split ( ',' ) ;
400+ string [ ] size = contents [ 4 ] . Split ( ',' ) ;
450401 windowWidth = Int32 . Parse ( size [ 0 ] ) ;
451402 windowHeight = Int32 . Parse ( size [ 1 ] ) ;
452403 }
@@ -476,7 +427,7 @@ static void BrowseGamedata(object sender, EventArgs e)
476427 {
477428 using ( OpenFileDialog openFileDialog2 = new OpenFileDialog ( ) )
478429 {
479- openFileDialog2 . Filter = "dat files (*.dat )|*.dat; " ;
430+ openFileDialog2 . Filter = "All files (*.* )|*.* " ;
480431 openFileDialog2 . RestoreDirectory = true ;
481432 openFileDialog2 . ShowDialog ( ) ;
482433
@@ -488,35 +439,15 @@ static void BrowseGamedata(object sender, EventArgs e)
488439 }
489440 }
490441 }
491- static void BrowseOutput ( object sender , EventArgs e )
492- {
493- using ( SaveFileDialog saveFileDialog2 = new SaveFileDialog ( ) )
494- {
495- saveFileDialog2 . Filter = "txt files (*.txt)|*.txt;" ;
496- saveFileDialog2 . RestoreDirectory = true ;
497- saveFileDialog2 . ShowDialog ( ) ;
498-
499- if ( saveFileDialog2 . FileName != "" )
500- {
501- outputName = saveFileDialog2 . FileName ;
502- Console . WriteLine ( "Output file : " + outputName ) ;
503- outputBox . Text = outputName ;
504- }
505- }
506- }
507442 static void OkIO ( object sender , EventArgs e )
508443 {
509444 fileName = gamedataBox . Text ;
510- outputName = outputBox . Text ;
511445 Console . WriteLine ( "Gamedata : " + fileName ) ;
512- Console . WriteLine ( "Output : " + outputName ) ;
513446 }
514447 static void CancelIO ( object sender , EventArgs e )
515448 {
516449 fileName = previousFileName ;
517- outputName = previousOutputName ;
518450 Console . WriteLine ( "Gamedata : " + fileName ) ;
519- Console . WriteLine ( "Output : " + outputName ) ;
520451 }
521452
522453 static void fontColorDialog ( object sender , EventArgs e )
@@ -599,7 +530,6 @@ static void Main()
599530 EventHandler Edit_L = new EventHandler ( MenuEdit_L ) ;
600531
601532 EventHandler gamedataButtonHandler = new EventHandler ( BrowseGamedata ) ;
602- EventHandler outputButtonHandler = new EventHandler ( BrowseOutput ) ;
603533
604534 EventHandler OkIOHandler = new EventHandler ( OkIO ) ;
605535 EventHandler CancelIOHandler = new EventHandler ( CancelIO ) ;
@@ -612,7 +542,7 @@ static void Main()
612542 EventHandler CancelEditHandler = new EventHandler ( CancelEdit ) ;
613543
614544 ContextMenu menu = new ContextMenu ( ) ;
615- menu . MenuItems . Add ( "Input/Output options " , IO_Options ) ;
545+ menu . MenuItems . Add ( "Text Input file " , IO_Options ) ;
616546 menu . MenuItems . Add ( "-" ) ;
617547 menu . MenuItems . Add ( "Save layout" , Save_L ) ;
618548 menu . MenuItems . Add ( "Save layout as..." , SaveAs_L ) ;
@@ -628,31 +558,22 @@ static void Main()
628558 {
629559 // We want to change the number in the output file on the first loop
630560 previousTotal = NO_PREVIOUS_TOTAL ;
631- Console . WriteLine ( "Game data file: " + fileName ) ;
632- Console . WriteLine ( "Output file: " + outputName ) ;
561+ Console . WriteLine ( "Input file: " + fileName ) ;
633562 while ( true )
634563 {
635- Analyze_file ( fileName , outputName ) ;
564+ Analyze_file ( fileName ) ;
636565 Thread . Sleep ( 100 ) ;
637566 }
638567 } ) . Start ( ) ;
639568
640- AddConstantLabel ( "Game data's path:" , new Point ( 10 , 10 ) , IOForm ) ;
569+ AddConstantLabel ( "Input path:" , new Point ( 10 , 10 ) , IOForm ) ;
641570 gamedataBox = new TextBox ( ) ;
642571 gamedataBox . Text = fileName ;
643572 gamedataBox . Location = new Point ( 10 , 30 ) ;
644573 gamedataBox . Size = new Size ( 180 , 20 ) ;
645574 IOForm . Controls . Add ( gamedataBox ) ;
646575 Button gamedataButton = MakeButton ( "Browse" , new Point ( 200 , 30 ) , gamedataButtonHandler , IOForm ) ;
647576
648- AddConstantLabel ( "Output file's path:" , new Point ( 10 , 60 ) , IOForm ) ;
649- outputBox = new TextBox ( ) ;
650- outputBox . Text = outputName ;
651- outputBox . Location = new Point ( 10 , 80 ) ;
652- outputBox . Size = new Size ( 180 , 20 ) ;
653- IOForm . Controls . Add ( outputBox ) ;
654- Button outputButton = MakeButton ( "Browse" , new Point ( 200 , 80 ) , outputButtonHandler , IOForm ) ;
655-
656577 Button buttonOkIO = MakeButton ( "OK" , new Point ( 110 , 140 ) , OkIOHandler , IOForm ) ;
657578 buttonOkIO . DialogResult = DialogResult . OK ;
658579 IOForm . AcceptButton = buttonOkIO ;
0 commit comments