Find offset and replace byte

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hi
Im trying to write a program that depending on the drop down menu selected it will then search for that offset position and replace the 4 bytes in that position########################
#Select Transfer Budget#
########################
Private Sub ComboBox1_DropDownClosed(sender As Object, e As EventArgs) Handles ComboBox1.DropDownClosed

Select Case ComboBox1.SelectedItem
Case Is = "-£10 million (are you crazy CHALLENGE)"
transferbudget = "100"
Case Is = "-£2 million (mid level CHALLENGE)"
transferbudget = "200"
Case Is = "-£500k (lower league CHALLENGE)"
transferbudget = "500"
Case Is = "£500k (tough)"
transferbudget = "05"
Case Is = "£5 million"
transferbudget = "5"
Case Is = "£10 million"
transferbudget = "10"
Case Is = "£25 million"
transferbudget = "25"
Case Is = "£50 million"
transferbudget = "2F-AF-08-0"
Case Is = "£99 million"
transferbudget = "99999999"
End Select
End Sub

The above code is where ive been trying various hex/numeric values that will replace the current hex value.Public Sub SaveChanges()
Dim amount As Integer
Dim fpath As String = OpenFileDialog1.FileName

Using stream = New FileStream(fpath, FileMode.Open, FileAccess.ReadWrite)
Dim result As Integer = 0
Dim buffer As Byte() = New Byte(3) {}

buffer = BitConverter.GetBytes(amount)

stream.Write(buffer, 0, 4)

stream.Position = &HD880
If btn_career_limit.Checked Then
stream.WriteByte(&HFF)
Else
stream.WriteByte(1)
End If

stream.Position = &HD5C4
If btn_trans_limit.Checked Then
stream.WriteByte(0)
Else
stream.WriteByte(0)
End If

If testbutton.Checked Then
stream.Position = &HD5DC
stream.WriteByte(32)
stream.Position = &HD5DD
stream.WriteByte(12)
stream.Position = &HD5DE
stream.WriteByte(0)
stream.Position = &HD5DF
stream.WriteByte(0)
End If
End Using
End Sub

Above is the code that i have which depending on the button/drop down selected it then replaces it with the values from the "transfer budget"
I put in the test button just to save time instead of editing all the code so that is just messy code
Cheers for any help.
Gaz

View the full article
 
Back
Top