News: 11 March 2016 - Forum Rules
Current Moderators - DarkSol, KingMike, MathOnNapkins, Azkadellia, Danke

Author Topic: Trying to create a utility, no idea where to start. Help?  (Read 1389 times)

Millertime2325

  • Jr. Member
  • **
  • Posts: 8
    • View Profile
Trying to create a utility, no idea where to start. Help?
« on: April 15, 2016, 08:07:49 pm »
Hey guys, a year or two ago I was working on an NBA Jam roster hack, but it eventually became too much of a pain in the ass to finish. Since then, I've completed a class in vb.net, but it was really basic. Now I'm trying to get back into my project, and I'm thinking if I could make a good editor in .net I would be more likely to see my project through.

Can anyone point me in the right direction? I have literally all of the hex values I need, but I've been looking through the net and can't find any basic tutorials on the matter. If anyone can let me know some concepts to look up or some sample code for editing a SNES rom with hex, I'd very much appreciate it. Thanks!

dougeff

  • Sr. Member
  • ****
  • Posts: 359
    • View Profile
Re: Trying to create a utility, no idea where to start. Help?
« Reply #1 on: April 15, 2016, 08:25:33 pm »
Are you going to make a winform GUI in VB? Which part are you having problems with? Setting up the GUI? Modifying the ROM? Programming the functions of the form?
nesdoug.com -- blog/tutorial on programming for the NES

Millertime2325

  • Jr. Member
  • **
  • Posts: 8
    • View Profile
Re: Trying to create a utility, no idea where to start. Help?
« Reply #2 on: April 16, 2016, 12:07:52 am »
Are you going to make a winform GUI in VB? Which part are you having problems with? Setting up the GUI? Modifying the ROM? Programming the functions of the form?
Yeah that was the plan, I'm good with the GUI stuff, but I'm just not too familiar with how I'd code it, ie how to load the file and specify which offsets and attributes are associated with the data for each player in the game

rafaelinio

  • Jr. Member
  • **
  • Posts: 20
    • View Profile
Re: Trying to create a utility, no idea where to start. Help?
« Reply #3 on: April 16, 2016, 02:12:24 am »
This is not something you can do with just the basics(not sure what you are able to do) I'd suggest learning more about programming in general before you actually start programming an utility for ROM hacking. Either way you should be familiar with file I/O (input/output).
Btw just some simple googleing: http://www.pokecommunity.com/showthread.php?t=303158
Not exactly what you want but shows you how to modify the values etc

Madsiur

  • RHDN Patreon Supporter!
  • Full Member
  • *****
  • Posts: 174
  • FF6 hacker
    • View Profile
Re: Trying to create a utility, no idea where to start. Help?
« Reply #4 on: April 16, 2016, 04:28:55 pm »
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:

Code: [Select]
Dim data() as Byte = File.ReadAllBytes(path1)
File.WriteAllBytes(path2, data)

I also have a C# class from the FF6 level editor ZoneDoctor that allows to manipulate bytes and bit (setByte(s), readByte(s), get/setInt24/32, etc...). You'll have to make some modification at least for the fact that arrays seems to be Dim objects in VB (I never coded in VB): http://madsiur.net/Bits.zip


zhade

  • Full Member
  • ***
  • Posts: 193
    • View Profile
    • zhaDe's stuff
Re: Trying to create a utility, no idea where to start. Help?
« Reply #5 on: April 18, 2016, 04:57:41 pm »

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:

Code: [Select]
Dim data() as Byte = File.ReadAllBytes(path1)
File.WriteAllBytes(path2, data)

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:

Code: [Select]

    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
        End While

        Return sOut
    End Function

    Public Function fromHexStringSingle(ByRef _string As String) As Byte
        Dim btOut As Byte = Convert.ToByte(_string, 16)
        Return btOut
    End Function

    Public Function fromHexStringMulti(ByRef _string As String) As Integer
        Dim iOut As Integer = Convert.ToInt32(_string, 16)
        Return iOut
    End Function


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:

Code: [Select]

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)

my.computer.filesystem.writeAllBytes("C://snesroms/nbajam.smc",rom)

« Last Edit: April 18, 2016, 06:09:25 pm by zhade »