VERSION 5.00
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.2#0"; "COMDLG32.OCX"
Object = "{0D452EE1-E08F-101A-852E-02608C4D0BB4}#2.0#0"; "FM20.DLL"
Begin VB.Form HexEditor 
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Hex Editor"
   ClientHeight    =   6150
   ClientLeft      =   2715
   ClientTop       =   2430
   ClientWidth     =   6630
   LinkTopic       =   "Hex Editor"
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   6150
   ScaleWidth      =   6630
   Begin VB.TextBox Contents 
      BeginProperty Font 
         Name            =   "Courier New"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Height          =   5415
      Left            =   120
      Locked          =   -1  'True
      MultiLine       =   -1  'True
      ScrollBars      =   2  'Vertical
      TabIndex        =   0
      Top             =   120
      Width           =   6375
   End
   Begin MSComDlg.CommonDialog dlg 
      Left            =   1680
      Top             =   5640
      _ExtentX        =   847
      _ExtentY        =   847
      _Version        =   393216
   End
   Begin MSForms.CommandButton Ok 
      Default         =   -1  'True
      Height          =   375
      Left            =   120
      TabIndex        =   4
      Top             =   5640
      Width           =   1335
      Caption         =   "Ok"
      Size            =   "2355;661"
      FontHeight      =   165
      FontCharSet     =   0
      FontPitchAndFamily=   2
      ParagraphAlign  =   3
   End
   Begin MSForms.CommandButton Import 
      Height          =   375
      Left            =   2280
      TabIndex        =   3
      Top             =   5640
      Width           =   1335
      Caption         =   "Import"
      Size            =   "2355;661"
      FontHeight      =   165
      FontCharSet     =   0
      FontPitchAndFamily=   2
      ParagraphAlign  =   3
   End
   Begin MSForms.CommandButton Export 
      Height          =   375
      Left            =   3720
      TabIndex        =   2
      Top             =   5640
      Width           =   1335
      Caption         =   "Export"
      Size            =   "2355;661"
      FontHeight      =   165
      FontCharSet     =   0
      FontPitchAndFamily=   2
      ParagraphAlign  =   3
   End
   Begin MSForms.CommandButton Cancel 
      Cancel          =   -1  'True
      Height          =   375
      Left            =   5160
      TabIndex        =   1
      Top             =   5640
      Width           =   1335
      Caption         =   "Cancel"
      Size            =   "2355;661"
      FontHeight      =   165
      FontCharSet     =   0
      FontPitchAndFamily=   2
      ParagraphAlign  =   3
   End
End
Attribute VB_Name = "HexEditor"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False

Public itemnum As Integer
Public ItemType As String
Public itemdata As String
Public itemlen As Long


Public Sub init()
    
    ItemType = App.mapfile.gettype(itemnum)
    'itemdata = App.graphics.itemstr(itemnum)
    'itemlen = App.graphics.itemsize(itemnum)
    itemdata = App.graphics.getgitemdata(itemnum)
    itemlen = App.graphics.getgitemsize(itemnum)
    init_contents
    
End Sub

Public Sub init_contents()

    Dim s As String
    Dim masked As Long
    Dim data As Byte
    
    masked = 65536
    s = s + Right(Hex(masked), 4) + " :: "
    For i = 1 To itemlen
        data = AscB(MidB(itemdata, i, 1))
        
        If data < 16 Then
            s = s + "0"
        End If
        
        s = s + Hex(data)
        masked = i - 1 And 15
        
        If masked = 15 Then
            s = s + chr(13) + chr(10)
            masked = i
            masked = masked + 65536
            s = s + Right(Hex(masked), 4) + " :: "
        Else
            s = s + " "
        End If
    Next
    Contents.Text = s
    
End Sub
Private Sub MaskEdBox1_Change()

End Sub

Private Sub Cancel_Click()
    unload Me
End Sub

Private Sub Export_Click()
    Dim sfile As String
    
    With dlg
    On Error GoTo canceled
        .DialogTitle = "Export"
        .CancelError = True
        .Flags = cdlOFNOverwritePrompt
        'ToDo: set the flags and attributes of the common dialog control
        .Filter = "*.dat|*.dat|All Files (*.*)|*.*"
        .FileName = zerostr(itemnum, 4) + " " + mapfile.getname(itemnum) + ".dat"
        .ShowSave
        If Len(.FileTitle) = 0 Then
            Exit Sub
        End If
        sfile = .FileName
        'curlevel = 0
    End With
        
    App.graphics.gexport_raw itemnum, sfile
    'App.graphics.export_raw itemdata, sfile
canceled:
End Sub

Private Sub Form_Load()

End Sub

Private Sub Import_Click()
    Dim sfile As String
    Dim fs
    
    
    With dlg
        On Error GoTo canceled
        .DialogTitle = "Import"
        .CancelError = True
        'ToDo: set the flags and attributes of the common dialog control
        .Filter = "*.dat|*.dat|All Files (*.*)|*.*"
        .FileName = Str(itemnum) + " " + mapfile.getname(itemnum) + ".dat"
        '.CancelError = True
        
        .ShowOpen
        
        If Len(.FileTitle) = 0 Then
            Exit Sub
        End If
        'curlevel = 0
        Set fs = CreateObject("Scripting.FileSystemObject")
        Set f = fs.GetFile(.FileName)
        sfile = .FileName
        itemlen = f.Size
    
    
    itemlen = graphics.import_raw(itemdata, sfile)
    End With
    
    init_contents
canceled:
End Sub

Private Sub Ok_Click()
    Dim newtype As String
    
    'App.graphics.setitemstr itemnum, itemdata
    'App.graphics.setitemsize itemnum, itemlen
    
    App.graphics.setgitemdata itemnum, itemdata
    App.graphics.setgitemsize itemnum, itemlen
    
    newtype = mapfile.gettype(itemnum)
    If newtype = "IMG1" Then
        'graphics.reloadgraphic itemnum, 0
        graphics.buildbmp itemnum
    End If
    
    unload Me
End Sub
