Read CON?

Discussion in 'Programming & Scripting' started by ChitySnipa, Feb 16, 2009 with 4 replies and 293 views.

  1. ChitySnipa

    ChitySnipa Banned

    Messages:
    255
    Ratings:
    53
    Well, ive been wanting to make a modding program and would like somebody to tell me how to read lines in a Container file so like on cod4 or 5 when somebody opens a save file i can let them check boxes off if they want a certain thing done.
    Kinda like modio.
    I would be so grateful for help here and full credit will be added.

     
  2. iDecryption

    iDecryption Enthusiast

    Messages:
    202
    Ratings:
    35
    This will go in the form.vb

    Code:
            Public Shared Function BytesToHexString(ByVal data() As Byte) As String
    Dim str As String = ""
    
    For i As Integer = 0 To data.Length - 1
    Dim str2 As String = data(i).ToString("X")
    
    Do While str2.Length <> 2
    str2 = "0" & str2
    Loop
    str = str & str2
    Next i
    
    Return str
    End Function
    This is the container header. this reads the profile ID, Device ID, and the container's image

    Code:
    Namespace Container_Header
    Friend Class Container_Header
    Public Structure FileDescriptionEntry
    Public Enum language
    English = 0
    Japanese = 1
    German = 2
    French = 3
    Spanish = 4
    Italian = 5
    Korean = 6
    Chinese = 7
    Portuguese = 8
    End Enum
    
    Public lang As language
    Public description As String
    Public title As String
    
    End Structure
    
    Public Shared deviceID(19) As Byte
    Public Shared profileID(7) As Byte
    
    Public Shared firstIcon As Image
    Public Shared firstIconLength As Integer
    
    Public Shared secondIcon As Image
    Public Shared secondIconLength As Integer
    
    Public Shared fdeList As New List(Of FileDescriptionEntry)()
    
    Public Shared Sub Load(ByVal CONpath As String)
    Dim br As New BinaryReader(New FileStream(CONpath, FileMode.Open, FileAccess.Read, FileShare.Read))
    
    br.BaseStream.Position = &H371L
    
    profileID = br.ReadBytes(8)
    
    br.BaseStream.Position = &H3FDL
    
    deviceID = br.ReadBytes(20)
    
    br.BaseStream.Position = &H412L
    
    Dim item As New FileDescriptionEntry()
    
    
    item.lang = FileDescriptionEntry.language.English
    item.title = BytesToString(br.ReadBytes(&H100)).Replace(Constants.vbNullChar, "")
    br.BaseStream.Position = &HD12L
    item.description = BytesToString(br.ReadBytes(&H100)).Replace(Constants.vbNullChar, "")
    
    
    fdeList.Add(item)
    
    br.BaseStream.Position = &H512L
    item = New FileDescriptionEntry()
    
    
    item.lang = FileDescriptionEntry.language.Japanese
    item.title = BytesToString(br.ReadBytes(&H100)).Replace(Constants.vbNullChar, "")
    br.BaseStream.Position = &HE12L
    item.description = BytesToString(br.ReadBytes(&H100)).Replace(Constants.vbNullChar, "")
    
    fdeList.Add(item)
    
    br.BaseStream.Position = &H612L
    item = New FileDescriptionEntry()
    
    
    item.lang = FileDescriptionEntry.language.German
    item.title = BytesToString(br.ReadBytes(&H100)).Replace(Constants.vbNullChar, "")
    br.BaseStream.Position = &HF12L
    item.description = BytesToString(br.ReadBytes(&H100)).Replace(Constants.vbNullChar, "")
    
    
    fdeList.Add(item)
    
    br.BaseStream.Position = &H712L
    item = New FileDescriptionEntry()
    
    
    item.lang = FileDescriptionEntry.language.French
    item.title = BytesToString(br.ReadBytes(&H100)).Replace(Constants.vbNullChar, "")
    br.BaseStream.Position = &H1012L
    item.description = BytesToString(br.ReadBytes(&H100)).Replace(Constants.vbNullChar, "")
    
    fdeList.Add(item)
    
    br.BaseStream.Position = &H812L
    item = New FileDescriptionEntry()
    
    
    item.lang = FileDescriptionEntry.language.Spanish
    item.title = BytesToString(br.ReadBytes(&H100)).Replace(Constants.vbNullChar, "")
    br.BaseStream.Position = &H1112L
    item.description = BytesToString(br.ReadBytes(&H100)).Replace(Constants.vbNullChar, "")
    
    fdeList.Add(item)
    
    br.BaseStream.Position = &H912L
    item = New FileDescriptionEntry()
    
    
    item.lang = FileDescriptionEntry.language.Italian
    item.title = BytesToString(br.ReadBytes(&H100)).Replace(Constants.vbNullChar, "")
    br.BaseStream.Position = &H1212L
    item.description = BytesToString(br.ReadBytes(&H100)).Replace(Constants.vbNullChar, "")
    
    fdeList.Add(item)
    
    br.BaseStream.Position = &HA12L
    item = New FileDescriptionEntry()
    
    
    item.lang = FileDescriptionEntry.language.Korean
    item.title = BytesToString(br.ReadBytes(&H100)).Replace(Constants.vbNullChar, "")
    br.BaseStream.Position = &H1312L
    item.description = BytesToString(br.ReadBytes(&H100)).Replace(Constants.vbNullChar, "")
    
    fdeList.Add(item)
    
    br.BaseStream.Position = &HB12L
    item = New FileDescriptionEntry()
    
    
    item.lang = FileDescriptionEntry.language.Chinese
    item.title = BytesToString(br.ReadBytes(&H100)).Replace(Constants.vbNullChar, "")
    br.BaseStream.Position = &H1412L
    item.description = BytesToString(br.ReadBytes(&H100)).Replace(Constants.vbNullChar, "")
    
    
    fdeList.Add(item)
    
    br.BaseStream.Position = &HC12L
    item = New FileDescriptionEntry()
    
    
    item.lang = FileDescriptionEntry.language.Portuguese
    item.title = BytesToString(br.ReadBytes(&H100)).Replace(Constants.vbNullChar, "")
    br.BaseStream.Position = &H1512L
    item.description = BytesToString(br.ReadBytes(&H100)).Replace(Constants.vbNullChar, "")
    
    fdeList.Add(item)
    
    br.BaseStream.Position = &H1712L
    
    firstIconLength = CInt(Fix(Bits.GetValue(br.ReadBytes(4), "i32")))
    secondIconLength = CInt(Fix(Bits.GetValue(br.ReadBytes(4), "i32")))
    
    firstIcon = ImageFromBytes(br.ReadBytes(firstIconLength))
    
    br.BaseStream.Position = &H571AL
    
    secondIcon = ImageFromBytes(br.ReadBytes(secondIconLength))
    
    br.Close()
    End Sub
    
    Public Shared Function BytesToString(ByVal data() As Byte) As String
    Return Encoding.ASCII.GetString(data)
    End Function
    
    Public Shared Function ImageFromBytes(ByVal data() As Byte) As Image
    Dim stream As New MemoryStream(data)
    Dim image As Image = Image.FromStream(stream)
    
    stream.Close()
    
    Return image
    End Function
    End Class
    End Namespace
    Then this is used to read container bytes.

    Code:
    Namespace Container_Header
    Friend Class CON_Bit
    Public Shared Function GetValue(ByVal bytesToConvert() As Byte, ByVal type As String) As Object
    Dim valueToReturn As Object = 0
    
    Dim tmpBytes() As Byte = bytesToConvert
    Array.Reverse(tmpBytes)
    
    If type = "i16" Then
    valueToReturn = BitConverter.ToInt16(tmpBytes, 0)
    ElseIf type = "i32" Then
    valueToReturn = BitConverter.ToInt32(tmpBytes, 0)
    End If
    
    Return valueToReturn
    End Function
    End Class
    End Namespace
    I hope this is what you were looking for.
     
    • Like Like x 1
  3. GoldBl4d3

    GoldBl4d3 Retired Retired

    Messages:
    3,758
    Ratings:
    1,328
    the container header looks alot like mine. Is it becuase its just like it but its converted into vb code.
     
  4. OP
    ChitySnipa

    ChitySnipa Banned

    Messages:
    255
    Ratings:
    53
    Can you be a little bit more specific on where to put this stuff?
     
  5. jjmpsp2

    jjmpsp2 Newbie

    Messages:
    1
    Ratings:
    0
    you would need a picturebox, open file dialog, 3 labels and 3 texboxes and as many buttons as you need.