April 18, 2016, 04:58:19 pm - (Auto Merged - Double Posts are not allowed before 7 days.)
What I do is that I copy the whole ROM into a byte array then I make manipulations on that array. When I save, I just recopy the whole array back into the original or new file. The second option let you keep the original file as backup if anything happend while editing.
You can achieve that in VB with the following:
Dim data() as Byte = File.ReadAllBytes(path1)
thats how I do it too, it makes it very easy to make sure you read/write from the right addresses, like say you want to change the byte at address 1340 (in decimal) to 67 you just have to write : data(1340) = 67. Altho I think VB's arrays start at 1 instead of 0 so you might have to add 1 to the addresses.
The rom writing/reading is very straightforward actually, and altho it depends on what kind of utility you want to do, I don't think you need a very deep understanding of the language to make an utility.
Personally I have very bad memory for the name of commands, functions and the like, many times I will just use google and search for stuff like "VB read binary file" and most of the time the first result will be msdn or some other reference site where I will get the command's name, put it in my code and forget about it before I will have to use it again.
In VB there is this useful "My" thing that helps me alot tho. Like say you want to find that function to read a file and put all the bytes in a byte array that Madsiur talked about. You start by typing "My", *dot* and then the auto-sugestion box will pop up and you give you some choices. Its made in a way that it starts by showing very broad categories, and each time it you pick the one that fits what you are looking for and it narrows down until you find the function you were looking for. I think a methaphor would make it easier to understand so it would be like say you wanted to "vaccinate a kitten", and that there is a function in VB for that
You would type "My." then have to choose from something very large like say (Matter, Energy, Thoughts) , so since a kitten is part of the physical world you continue with"My.Matter." then have to choose from (Solid, Liquid, Gas) , well a kitten is not drinkable nor breathable so "My.Matter.Solid." you then have (Inanimate Object, Plant, Insect, Fish, Mammal) so My.Matter.Solid.Mammal, then ("Ape, Water Mammal, Bovine, feline.. etc..) you get the idea. In the end you might get a long ugly command like My.Matter.Solid.Mammal.Feline.Cat.Kitten.Cares.Vacinate() [I exagerated tho], but you wouldn't have to remember it anyway because the path to it is logical.
For putting a whole rom into a byte array it goes : My.Computer.FileSystem.ReadAllBytes(path as string) as byte()
The way you said you have "literally all of the hex values [you] need" and that you stopped because it was a pain in the a** I guess you were using an hex editor, figured out the data worked but gave up because typing it all manually was way too time consuming. If that is the case then the hard part is already done, all you need is some functions to go from decimal values to hex strings and you should be good to go.
heres what I use to do this:
Public Function toHexString(ByRef _byte As Integer, Optional ByVal _minLen As Integer = 2) As String
Dim sOut As String = Hex(_byte)
While (sOut.Length < _minLen)
sOut = "0" & sOut
Public Function fromHexStringSingle(ByRef _string As String) As Byte
Dim btOut As Byte = Convert.ToByte(_string, 16)
Public Function fromHexStringMulti(ByRef _string As String) As Integer
Dim iOut As Integer = Convert.ToInt32(_string, 16)
watch out if you use thoses, if I recall corectly the ones that take a hex string in argument will throw an exception (that I didnt bother to try/catch) if the string contains character other than "0123456789ABCDEF" and it will crash the program.
use toHexString() on the bytes you take from the rom to show them in hex in textboxes and other controls, the second param is the minimum digit count, you can use it so that for example the value 15 (in decimal) will appear as "000F" instead of "F" if the minimum is set to 4
the other 2 functons are doing the reverse operation, one returns a single byte and the other a 32-bit integer
so for example lets say that with your hex editor you had to go at the address 015C23, and increase the value in there by 2:
dim rom = my.computer.filesystem.readallbytes("c://snesroms/nbajam.smc")
dim originalValue as byte = rom(fromHexStringMulti("015C23"))
dim newValue as byte = originalValue + 2
rom(fromHexStringMulti("015C23")) = newValue
textbox1.text = "the new value is : " & toHexString(newValue,2)