From 92ff4d3f285f7070327d86d38952000f97623369 Mon Sep 17 00:00:00 2001 From: Lucent Date: Fri, 27 Oct 2023 23:47:09 +0200 Subject: [PATCH] cleanup & format --- MainForm.cs | 2 - ROMFile.cs | 131 +++++++++++++++++++++++++++------------------------- 2 files changed, 68 insertions(+), 65 deletions(-) diff --git a/MainForm.cs b/MainForm.cs index b870519..037dc89 100644 --- a/MainForm.cs +++ b/MainForm.cs @@ -1,6 +1,4 @@ -using System.Security.Cryptography; using System.Text; -using System.Windows.Forms; namespace SharpCreditsCrediter { diff --git a/ROMFile.cs b/ROMFile.cs index 3dffeb6..08488b1 100644 --- a/ROMFile.cs +++ b/ROMFile.cs @@ -2,88 +2,91 @@ namespace SharpCreditsCrediter { - internal class ROMFile - { - private FileStream? romFile; + internal class ROMFile + { + private FileStream? romFile; const long ZM_credits_start = 0x54C10C; const long ZM_credits_end = 0x54E2A9; const long MF_credits_start = 0x74B0B0; const long MF_credits_end = 0x74DC25; private bool isZM = true; - private readonly Dictionary textToIntTable = new Dictionary() { - { ' ', 0x20 }, { 'A', 0x41 }, { 'B', 0x42 }, { 'C', 0x43 }, { 'D', 0x44 }, { 'E', 0x45 }, { 'F', 0x46 }, { 'G', 0x47 }, - { 'H', 0x48 }, { 'I', 0x49 }, { 'J', 0x4A }, { 'K', 0x4B }, { 'L', 0x4C }, { 'M', 0x4D }, { 'N', 0x4E }, { 'O', 0x4F }, - { 'P', 0x50 }, { 'Q', 0x51 }, { 'R', 0x52 }, { 'S', 0x53 }, { 'T', 0x54 }, { 'U', 0x55 }, { 'V', 0x56 }, { 'W', 0x57 }, - { 'X', 0x58 }, { 'Y', 0x59 }, { 'Z', 0x5A }, { 'a', 0x61 }, { 'b', 0x62 }, { 'c', 0x63 }, { 'd', 0x64 }, { 'e', 0x65 }, - { 'f', 0x66 }, { 'g', 0x67 }, { 'h', 0x68 }, { 'i', 0x69 }, { 'j', 0x6A }, { 'k', 0x6B }, { 'l', 0x6C }, { 'm', 0x6D }, - { 'n', 0x6E }, { 'o', 0x6F }, { 'p', 0x70 }, { 'q', 0x71 }, { 'r', 0x72 }, { 's', 0x73 }, { 't', 0x74 }, { 'u', 0x75 }, - { 'v', 0x76 }, { 'w', 0x77 }, { 'x', 0x78 }, { 'y', 0x79 }, { 'z', 0x7A }, { '&', 0x26 } - }; + private readonly Dictionary textToIntTable = new Dictionary() { + { ' ', 0x20 }, { 'A', 0x41 }, { 'B', 0x42 }, { 'C', 0x43 }, { 'D', 0x44 }, { 'E', 0x45 }, { 'F', 0x46 }, { 'G', 0x47 }, + { 'H', 0x48 }, { 'I', 0x49 }, { 'J', 0x4A }, { 'K', 0x4B }, { 'L', 0x4C }, { 'M', 0x4D }, { 'N', 0x4E }, { 'O', 0x4F }, + { 'P', 0x50 }, { 'Q', 0x51 }, { 'R', 0x52 }, { 'S', 0x53 }, { 'T', 0x54 }, { 'U', 0x55 }, { 'V', 0x56 }, { 'W', 0x57 }, + { 'X', 0x58 }, { 'Y', 0x59 }, { 'Z', 0x5A }, { 'a', 0x61 }, { 'b', 0x62 }, { 'c', 0x63 }, { 'd', 0x64 }, { 'e', 0x65 }, + { 'f', 0x66 }, { 'g', 0x67 }, { 'h', 0x68 }, { 'i', 0x69 }, { 'j', 0x6A }, { 'k', 0x6B }, { 'l', 0x6C }, { 'm', 0x6D }, + { 'n', 0x6E }, { 'o', 0x6F }, { 'p', 0x70 }, { 'q', 0x71 }, { 'r', 0x72 }, { 's', 0x73 }, { 't', 0x74 }, { 'u', 0x75 }, + { 'v', 0x76 }, { 'w', 0x77 }, { 'x', 0x78 }, { 'y', 0x79 }, { 'z', 0x7A }, { '&', 0x26 } + }; - private readonly Dictionary intToTextTable = new Dictionary() { - { 0x20, " " }, { 0x41, "A" }, { 0x42, "B" }, { 0x43, "C" }, { 0x44, "D" }, { 0x45, "E" }, { 0x46, "F" }, { 0x47, "G" }, - { 0x48, "H" }, { 0x49, "I" }, { 0x4A, "J" }, { 0x4B, "K" }, { 0x4C, "L" }, { 0x4D, "M" }, { 0x4E, "N" }, { 0x4F, "O" }, - { 0x50, "P" }, { 0x51, "Q" }, { 0x52, "R" }, { 0x53, "S" }, { 0x54, "T" }, { 0x55, "U" }, { 0x56, "V" }, { 0x57, "W" }, - { 0x58, "X" }, { 0x59, "Y" }, { 0x5A, "Z" }, { 0x61, "a" }, { 0x62, "b" }, { 0x63, "c" }, { 0x64, "d" }, { 0x65, "e" }, - { 0x66, "f" }, { 0x67, "g" }, { 0x68, "h" }, { 0x69, "i" }, { 0x6A, "j" }, { 0x6B, "k" }, { 0x6C, "l" }, { 0x6D, "m" }, - { 0x6E, "n" }, { 0x6F, "o" }, { 0x70, "p" }, { 0x71, "q" }, { 0x72, "r" }, { 0x73, "s" }, { 0x74, "t" }, { 0x75, "u" }, + private readonly Dictionary intToTextTable = new Dictionary() { + { 0x20, " " }, { 0x41, "A" }, { 0x42, "B" }, { 0x43, "C" }, { 0x44, "D" }, { 0x45, "E" }, { 0x46, "F" }, { 0x47, "G" }, + { 0x48, "H" }, { 0x49, "I" }, { 0x4A, "J" }, { 0x4B, "K" }, { 0x4C, "L" }, { 0x4D, "M" }, { 0x4E, "N" }, { 0x4F, "O" }, + { 0x50, "P" }, { 0x51, "Q" }, { 0x52, "R" }, { 0x53, "S" }, { 0x54, "T" }, { 0x55, "U" }, { 0x56, "V" }, { 0x57, "W" }, + { 0x58, "X" }, { 0x59, "Y" }, { 0x5A, "Z" }, { 0x61, "a" }, { 0x62, "b" }, { 0x63, "c" }, { 0x64, "d" }, { 0x65, "e" }, + { 0x66, "f" }, { 0x67, "g" }, { 0x68, "h" }, { 0x69, "i" }, { 0x6A, "j" }, { 0x6B, "k" }, { 0x6C, "l" }, { 0x6D, "m" }, + { 0x6E, "n" }, { 0x6F, "o" }, { 0x70, "p" }, { 0x71, "q" }, { 0x72, "r" }, { 0x73, "s" }, { 0x74, "t" }, { 0x75, "u" }, { 0x76, "v" }, { 0x77, "w" }, { 0x78, "x" }, { 0x79, "y" }, { 0x7A, "z" }, { 0x26, "&" } }; private string intToText(int value) { - try { + try + { return intToTextTable[value]; - } catch(Exception) + } + catch (Exception) { return String.Format("{0:X2}", Convert.ToInt32(value)); } } - private int textToInt(char value) - { - try - { - return textToIntTable[value]; - } - catch (Exception) - { - return 0; - } - } + private int textToInt(char value) + { + try + { + return textToIntTable[value]; + } + catch (Exception) + { + return 0; + } + } - public ROMFile(String pathToROM) - { + public ROMFile(String pathToROM) + { this.changeFile(pathToROM); - } + } private void probeGame() { - if(this.isLoaded()) + if (this.isLoaded()) { #pragma warning disable CS8602 // isLoaded checks already if romFile is null or not - byte[] gameCodeBuf = new byte[4]; + byte[] gameCodeBuf = new byte[4]; romFile.Position = 0xAC; if (romFile.Read(gameCodeBuf, 0, 4) == 4) { string gameCode = Encoding.ASCII.GetString(gameCodeBuf); - if (gameCode == "AMTE") + if (gameCode == "AMTE") { this.isZM = false; - } else + } + else { this.isZM = true; } } #pragma warning restore CS8602 - } - } + } + } public void changeFile(String pathToROM) { if (this.isLoaded()) this.Dispose(); - romFile = File.Open(pathToROM, FileMode.Open); + romFile = File.Open(pathToROM, FileMode.Open); this.probeGame(); - } + } public bool isLoaded() { @@ -95,12 +98,12 @@ namespace SharpCreditsCrediter this.isZM = isZM; } - public bool getisZM() - { - return isZM; - } + public bool getisZM() + { + return isZM; + } - public void Dispose() + public void Dispose() { romFile?.Dispose(); } @@ -112,26 +115,26 @@ namespace SharpCreditsCrediter { long credits_start = isZM ? ZM_credits_start : MF_credits_start; long credits_end = isZM ? ZM_credits_end : MF_credits_end; - romFile.Position = credits_start; + romFile.Position = credits_start; bool end_reached = false; while (romFile.Position < credits_end && !end_reached) { int curChar = romFile.ReadByte(); - if (curChar == 6) end_reached = true; + if (curChar == 6) end_reached = true; - credits += intToText(curChar) + " "; + credits += intToText(curChar) + " "; - for (int i = 0; i < 35; i++) + for (int i = 0; i < 35; i++) { - curChar = romFile.ReadByte(); - if (curChar != 0) + curChar = romFile.ReadByte(); + if (curChar != 0) credits += intToText(curChar); } credits += Environment.NewLine; - } - } + } + } return credits; } @@ -149,7 +152,8 @@ namespace SharpCreditsCrediter var currentLine = credits.ReadLine(); if (currentLine != null) { - if (currentLine.Length > 38) { + if (currentLine.Length > 38) + { currentLine = currentLine[..38]; } @@ -177,16 +181,17 @@ namespace SharpCreditsCrediter } } romFile.Flush(); - + return true; } return false; - } catch (Exception) + } + catch (Exception) { - return false; - } - + return false; + } + } - } + } }