Page 1 of 1
VISUAL BASIC ERROR(s).
Posted: Wed Feb 27, 2008 2:15 am
by fudgy
Re: VISUAL BASIC ERROR(s).
Posted: Wed Feb 27, 2008 8:33 am
by Prey
- You don't fullstop methods.
- Methods must be contained within a class or struct.
- You're initialising your H2Tag array as H2Map's..
- It's "indexOffset - primaryMagicConstantMagic".. not "indexOffsetprimaryMagicConstantMagic"..
- Comments are started with the apostrophe(') character.
- Different instructions are normally put on different lines for clarity.. if you want them on one line, you must separate them with the colon(:) character.
- Closing brackets()) are meant to close initially opened open-brackets(()..
- Learn how to use "if" statements with open file dialogs..
Fixed code..
Code: Select all
Imports System.IO
Public Class Form1
Public HaloMap As H2Map
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim OFD As New OpenFileDialog
OFD.Filter = "Halo 2 Map (*.map)|*.map"
If OFD.ShowDialog() = Windows.Forms.DialogResult.OK Then
HaloMap.MapLocation = OFD.FileName
HaloMap.LoadH2Map()
HaloMap.LoadIntoTreeView(TreeView1, ProgressBar1)
HaloMap.LoadIntoListBox(ListBox1, ProgressBar1)
HaloMap.LoadIntoListBox(ListBox2, ProgressBar1, "bipd")
End If
End Sub
Private Sub ListBox2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox2.SelectedIndexChanged
Dim TempInteger As Integer = HaloMap.FindTagIndexByPath(ListBox1.Text)
If TempInteger = 0 Then Exit Sub
'This is the TagMeta offset that we will be editing
Dim TagMetaOffset As Long = HaloMap.H2Tag(TempInteger).MetaOffset
'This is the offset thats on the XML plugin or the offset in the meta you want to edit
Dim PluginValue As Long = ("504")
'Open up a BinaryReader so we can read our value
Dim BR As New BinaryReader(New FileStream(HaloMap.MapLocation, FileMode.Open, FileAccess.Read, FileShare.Read))
'Move to the Offset of the value we want to edit
BR.BaseStream.Position = TagMetaOffset + PluginValue
'Read the value
'Note: Not all values are Singles some can be other data types
TextBox1.Text = BR.ReadSingle
'Close the map
BR.Close()
End Sub
End Class
Public Class H2Map
'Basic Map Info
Public MapLocation As String
Public MapLoaded As Boolean
Public H2Tag() As H2Tag
Public mapMagic As Long
Public mapSecondaryMagic As Long
Public mapName As String
'Basic Header Info
Public indexOffset As Long
Public indexSize As Long
Public metaSize As Long
Public fileTableOffset As Long
'Basic Index Info
Public primaryMagicConstantMagic As Long
Public objectIndexOffset As Long
Public objectCount As Long
Public Sub LoadH2Map()
Dim BR As New BinaryReader(New FileStream(MapLocation, FileMode.Open, FileAccess.Read, FileShare.Read))
BR.BaseStream.Position = 16
indexOffset = BR.ReadInt32()
indexSize = BR.ReadInt32()
metaSize = BR.ReadInt32()
BR.BaseStream.Position = 708
fileTableOffset = BR.ReadInt32()
BR.BaseStream.Position = 408
Dim tempcharforname As Char = " "
Do While tempcharforname <> Chr(0)
tempcharforname = BR.ReadChar
If tempcharforname <> Chr(0) Then mapName &= tempcharforname
Loop
BR.BaseStream.Position = indexOffset - primaryMagicConstantMagic = BR.ReadInt32()
BR.BaseStream.Position += 4
objectIndexOffset = BR.ReadInt32()
BR.BaseStream.Position += 12
objectCount = BR.ReadInt32()
Dim TagStart As Long = indexOffset + 32 + (objectIndexOffset - primaryMagicConstantMagic)
ReDim H2Tag(0 To objectCount + 1)
BR.BaseStream.Position = TagStart
For i As Integer = 1 To objectCount Step 1
H2Tag(i).TagClass = StrReverse(BR.ReadChars(4))
H2Tag(i).TagID = BR.ReadInt32()
H2Tag(i).MetaOffset = BR.ReadInt32()
H2Tag(i).MetaSize = BR.ReadInt32()
Next
mapMagic = H2Tag(1).MetaOffset - (indexOffset + indexSize)
mapSecondaryMagic = primaryMagicConstantMagic - indexOffset - 32
For i As Integer = 1 To objectCount Step 1
H2Tag(i).MetaOffset = H2Tag(i).MetaOffset - mapMagic
Next
BR.BaseStream.Position = fileTableOffset
For i As Integer = 1 To objectCount Step 1
Dim tempchar As Char = " "
Do While tempchar <> Chr(0)
tempchar = BR.ReadChar()
H2Tag(i).TagPath &= tempchar
Loop
Next
BR.Close()
MapLoaded = True
End Sub
Public Sub LoadIntoTreeView(ByVal TreeView1 As TreeView, ByVal ProgressBar1 As ProgressBar)
TreeView1.Nodes.Add("Map(" & mapName & ")")
TreeView1.Sorted = True
ProgressBar1.Maximum = objectCount + 1
ProgressBar1.Minimum = 0
ProgressBar1.Value = 0
Dim templistbox As New ListBox
For x As Integer = 1 To objectCount Step 1
'If the templistbox dosent have the class in it then add it to it and also add it to the treeview
If templistbox.Items.Contains(H2Tag(x).TagClass) = False Then
templistbox.Items.Add(H2Tag(x).TagClass)
TreeView1.Nodes(0).Nodes.Add(BuildClassNode(H2Tag(x).TagClass))
Application.DoEvents()
End If
'Increase the Progressbar
ProgressBar1.Value += 1
Next
'Dispose the templistbox
templistbox.Dispose()
'Expand the TreeView
TreeView1.Nodes(0).Expand()
'Reset the Progressbar to 0
ProgressBar1.Value = 0
End Sub
Private Function BuildClassNode(ByVal tagClass As String)
'create a temp TreeNode
Dim ClassNode As New TreeNode
'Set the text to the tagclass
ClassNode.Text = "[" & tagClass & "]"
'Loop through all the tags and if its of the class we want then add to the node
For i As Integer = 1 To objectCount Step 1
If H2Tag(i).TagClass = tagClass Then
ClassNode.Nodes.Add(H2Tag(i).TagPath)
End If
Next
'return the node we put together
Return ClassNode
End Function
Public Sub LoadIntoListBox(ByVal Listbox1 As ListBox, ByVal ProgressBar1 As ProgressBar, Optional ByVal TagClass As String = "")
'Set up the ProgressBars
ProgressBar1.Maximum = objectCount + 1
ProgressBar1.Minimum = 0
ProgressBar1.Value = 0
'If they dont specify A tagClass then do all then if they do then do just that class
If TagClass = "" Then
'This will let you use a Listbox
For i As Integer = 1 To objectCount Step 1
Listbox1.Items.Add(H2Tag(i).TagPath)
ProgressBar1.Value += 1
Next
Else
'This will let you use a Listbox with only 1 tag class
For i As Integer = 1 To objectCount Step 1
If H2Tag(i).TagClass = TagClass Then
Listbox1.Items.Add(H2Tag(i).TagPath)
End If
ProgressBar1.Value += 1
Next
End If
ProgressBar1.Value = 0
End Sub
Public Function FindTagIndexByPath(ByVal TagPath As String) As Integer
Dim index As Integer = 0
'Loop through all the tags and if we find a matching path then we return then index of it
For i As Integer = 1 To objectCount Step 1
If H2Tag(i).TagPath = TagPath Then
index = i
Exit For
End If
Next
Return index
End Function
End Class
Public Structure H2Tag
Public TagID As Long
Public TagClass As String
Public MetaOffset As Long
Public MetaSize As Long
Public TagPath As String
End Structure
Re: VISUAL BASIC ERROR(s).
Posted: Wed Feb 27, 2008 8:35 am
by Prey
Prey wrote:- You don't fullstop methods.
- Methods must be contained within a class or struct.
- You're initialising your H2Tag array as H2Map's..
- It's "indexOffset - primaryMagicConstantMagic".. not "indexOffsetprimaryMagicConstantMagic"..
- Comments are started with the apostrophe(') character.
- Different instructions are normally put on different lines for clarity.. if you want them on one line, you must separate them with the colon(:) character.
- Closing brackets()) are meant to close initially opened open-brackets(()..
- Learn how to use "if" statements with open file dialogs..
Fixed code..
Code: Select all
Imports System.IO
Public Class Form1
Public HaloMap As H2Map
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim OFD As New OpenFileDialog
OFD.Filter = "Halo 2 Map (*.map)|*.map"
If OFD.ShowDialog() = Windows.Forms.DialogResult.OK Then
HaloMap.MapLocation = OFD.FileName
HaloMap.LoadH2Map()
HaloMap.LoadIntoTreeView(TreeView1, ProgressBar1)
HaloMap.LoadIntoListBox(ListBox1, ProgressBar1)
HaloMap.LoadIntoListBox(ListBox2, ProgressBar1, "bipd")
End If
End Sub
Private Sub ListBox2_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox2.SelectedIndexChanged
Dim TempInteger As Integer = HaloMap.FindTagIndexByPath(ListBox1.Text)
If TempInteger = 0 Then Exit Sub
'This is the TagMeta offset that we will be editing
Dim TagMetaOffset As Long = HaloMap.H2Tag(TempInteger).MetaOffset
'This is the offset thats on the XML plugin or the offset in the meta you want to edit
Dim PluginValue As Long = ("504")
'Open up a BinaryReader so we can read our value
Dim BR As New BinaryReader(New FileStream(HaloMap.MapLocation, FileMode.Open, FileAccess.Read, FileShare.Read))
'Move to the Offset of the value we want to edit
BR.BaseStream.Position = TagMetaOffset + PluginValue
'Read the value
'Note: Not all values are Singles some can be other data types
TextBox1.Text = BR.ReadSingle
'Close the map
BR.Close()
End Sub
End Class
Public Class H2Map
'Basic Map Info
Public MapLocation As String
Public MapLoaded As Boolean
Public H2Tag() As H2Tag
Public mapMagic As Long
Public mapSecondaryMagic As Long
Public mapName As String
'Basic Header Info
Public indexOffset As Long
Public indexSize As Long
Public metaSize As Long
Public fileTableOffset As Long
'Basic Index Info
Public primaryMagicConstantMagic As Long
Public objectIndexOffset As Long
Public objectCount As Long
Public Sub LoadH2Map()
Dim BR As New BinaryReader(New FileStream(MapLocation, FileMode.Open, FileAccess.Read, FileShare.Read))
BR.BaseStream.Position = 16
indexOffset = BR.ReadInt32()
indexSize = BR.ReadInt32()
metaSize = BR.ReadInt32()
BR.BaseStream.Position = 708
fileTableOffset = BR.ReadInt32()
BR.BaseStream.Position = 408
Dim tempcharforname As Char = " "
Do While tempcharforname <> Chr(0)
tempcharforname = BR.ReadChar
If tempcharforname <> Chr(0) Then mapName &= tempcharforname
Loop
BR.BaseStream.Position = indexOffset - primaryMagicConstantMagic = BR.ReadInt32()
BR.BaseStream.Position += 4
objectIndexOffset = BR.ReadInt32()
BR.BaseStream.Position += 12
objectCount = BR.ReadInt32()
Dim TagStart As Long = indexOffset + 32 + (objectIndexOffset - primaryMagicConstantMagic)
ReDim H2Tag(0 To objectCount + 1)
BR.BaseStream.Position = TagStart
For i As Integer = 1 To objectCount Step 1
H2Tag(i).TagClass = StrReverse(BR.ReadChars(4))
H2Tag(i).TagID = BR.ReadInt32()
H2Tag(i).MetaOffset = BR.ReadInt32()
H2Tag(i).MetaSize = BR.ReadInt32()
Next
mapMagic = H2Tag(1).MetaOffset - (indexOffset + indexSize)
mapSecondaryMagic = primaryMagicConstantMagic - indexOffset - 32
For i As Integer = 1 To objectCount Step 1
H2Tag(i).MetaOffset = H2Tag(i).MetaOffset - mapMagic
Next
BR.BaseStream.Position = fileTableOffset
For i As Integer = 1 To objectCount Step 1
Dim tempchar As Char = " "
Do While tempchar <> Chr(0)
tempchar = BR.ReadChar()
H2Tag(i).TagPath &= tempchar
Loop
Next
BR.Close()
MapLoaded = True
End Sub
Public Sub LoadIntoTreeView(ByVal TreeView1 As TreeView, ByVal ProgressBar1 As ProgressBar)
TreeView1.Nodes.Add("Map(" & mapName & ")")
TreeView1.Sorted = True
ProgressBar1.Maximum = objectCount + 1
ProgressBar1.Minimum = 0
ProgressBar1.Value = 0
Dim templistbox As New ListBox
For x As Integer = 1 To objectCount Step 1
'If the templistbox dosent have the class in it then add it to it and also add it to the treeview
If templistbox.Items.Contains(H2Tag(x).TagClass) = False Then
templistbox.Items.Add(H2Tag(x).TagClass)
TreeView1.Nodes(0).Nodes.Add(BuildClassNode(H2Tag(x).TagClass))
Application.DoEvents()
End If
'Increase the Progressbar
ProgressBar1.Value += 1
Next
'Dispose the templistbox
templistbox.Dispose()
'Expand the TreeView
TreeView1.Nodes(0).Expand()
'Reset the Progressbar to 0
ProgressBar1.Value = 0
End Sub
Private Function BuildClassNode(ByVal tagClass As String)
'create a temp TreeNode
Dim ClassNode As New TreeNode
'Set the text to the tagclass
ClassNode.Text = "[" & tagClass & "]"
'Loop through all the tags and if its of the class we want then add to the node
For i As Integer = 1 To objectCount Step 1
If H2Tag(i).TagClass = tagClass Then
ClassNode.Nodes.Add(H2Tag(i).TagPath)
End If
Next
'return the node we put together
Return ClassNode
End Function
Public Sub LoadIntoListBox(ByVal Listbox1 As ListBox, ByVal ProgressBar1 As ProgressBar, Optional ByVal TagClass As String = "")
'Set up the ProgressBars
ProgressBar1.Maximum = objectCount + 1
ProgressBar1.Minimum = 0
ProgressBar1.Value = 0
'If they dont specify A tagClass then do all then if they do then do just that class
If TagClass = "" Then
'This will let you use a Listbox
For i As Integer = 1 To objectCount Step 1
Listbox1.Items.Add(H2Tag(i).TagPath)
ProgressBar1.Value += 1
Next
Else
'This will let you use a Listbox with only 1 tag class
For i As Integer = 1 To objectCount Step 1
If H2Tag(i).TagClass = TagClass Then
Listbox1.Items.Add(H2Tag(i).TagPath)
End If
ProgressBar1.Value += 1
Next
End If
ProgressBar1.Value = 0
End Sub
Public Function FindTagIndexByPath(ByVal TagPath As String) As Integer
Dim index As Integer = 0
'Loop through all the tags and if we find a matching path then we return then index of it
For i As Integer = 1 To objectCount Step 1
If H2Tag(i).TagPath = TagPath Then
index = i
Exit For
End If
Next
Return index
End Function
End Class
Public Structure H2Tag
Public TagID As Long
Public TagClass As String
Public MetaOffset As Long
Public MetaSize As Long
Public TagPath As String
End Structure
Edit: I just looked over the actual code, wow that's terrible..
Posted: Wed Feb 27, 2008 11:14 am
by xzodia
thats because its a clone of anthony's code XD
thanks you
Posted: Thu Feb 28, 2008 6:41 pm
by fudgy
thank you, please lock/delete.