What's new

Write to an Offset with VB

  • Thread starter Visual Studio
  • Start date
  • Views 1,319
Visual Studio

XeMen Demon

The Original Shiba Inu
Odysseus' Summit Nevar gon' happen in your lifetime Programmer
Messages
2,748
Reaction score
1,488
Points
1,162
Sin$
7
I was wondering how do I make a program that when I press a button it will write whatever I tell it to a certain offset in a file.
 
A

AsparagusMan

Enthusiast
Messages
493
Reaction score
115
Points
125
Sin$
7
1) Go back to programming 101, this is basic stream stuff which is taught in the top of the beginner tutorials.
2) (Ignore if you aren't making a mod program for Xbox) If you are planning on making a gamesave mod program, a program that Seeks to "X" position and writes the data is not correct. With packages, the same data could be at another location in another package, or half the data could be say at 0xDFFE and the rest at 0x1E000
 
kiwimoosical

kiwimoosical

Getting There
Messages
1,123
Reaction score
474
Points
205
Sin$
7
Stop calling it a ****ing offset, its an address...
Code:
int address = 0x8200;
int addressBeingOffset = address + 0xEE; //0xEE is the offset...
But,
Code:
Public Sub Write(ByVal address As Long, ByVal fileName As String, ByVal data() As Byte)
Dim writer As New IO.BinaryWriter(New IO.FileStream(fileName, IO.FileMode.Open, IO.FileAccess.Write))
writer.BaseStream.Position = address
writer.Write(data)
End Sub

Yeah I know there are better ways of doing this, don't feel like doing much work today...
 
mirGantrophy

xGrim

Enthusiast
Messages
1,228
Reaction score
112
Points
165
Sin$
7
Assuming you are using VB.net 2008/2010

Code:
Dim fs As System.IO.FileStream
Dim bw As System.IO.BinaryWriter
fs = New System.IO.FileStream(OFD1.FileName, IO.FileMode.OpenOrCreate) 'Uses the file you just opened
bw = New System.IO.BinaryWriter(fs) 'tells the binary writer to write to the file you opened

fs.Position = &H '&H is the hex code position
bw.Write() 'put the value in parenthesis that you want it to write
 
Top Bottom
Login
Register