Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Converting Fixed Length String in Binary
#1
Remember, this is only for knowledge. I used more variables in the ItemRec since thats what my game has. So this is not copy paste. Just knowledge. Im also pretty certain that you can do ItemD(i) = Item(i), its just that I felt like doing ItemD(i).Pic = Item(i).Pic etc....

If you have the fixed length string as the default in MS you will only be able to have a item name of 20 characters. In order to fix that you will need to make a external program and include these things:

In form_load:
Code:
For i = 1 To MAX_ITEMS
        FileName = App.Path & "\data\Items\Item" & i & ".dat"
        f = FreeFile
        Open FileName For Binary As #f
        Get #f, , Item(i)
        Close #f

        DoEvents
    Next
A convert button with this:
Code:
Dim i As Long

For i = 1 To MAX_ITEMS
    ItemD(i).Name = Item(i).Name
    
    ItemD(i).Pic = Item(i).Pic
    ItemD(i).Type = Item(i).Type
    ItemD(i).Data1 = Item(i).Data1
    ItemD(i).Data2 = Item(i).Data2
    ItemD(i).Data3 = Item(i).Data3
    ItemD(i).StrReq = Item(i).StrReq
    ItemD(i).DefReq = Item(i).DefReq
    ItemD(i).SpeedReq = Item(i).SpeedReq
    ItemD(i).WisReq = Item(i).WisReq
    ItemD(i).InteReq = Item(i).InteReq
    ItemD(i).DropAble = Item(i).DropAble
    
    ItemD(i).AddHP = Item(i).AddHP
    ItemD(i).AddMP = Item(i).AddMP
    ItemD(i).AddSP = Item(i).AddSP
    ItemD(i).AddStr = Item(i).AddStr
    ItemD(i).AddDef = Item(i).AddDef
    ItemD(i).AddMagi = Item(i).AddMagi
    ItemD(i).AddSpeed = Item(i).AddSpeed
    ItemD(i).AttackSpeed = Item(i).AttackSpeed
    ItemD(i).AddInte = Item(i).AddInte
Next i

Another button that saves the new file with the new length of the name:
Code:
Dim FileName As String
    Dim i As Long
    Dim f As Long

    For i = 1 To MAX_ITEMS
        FileName = App.Path & "\data\ITEMNEW\Item" & i & ".dat"
        f = FreeFile
        Open FileName For Binary As #f
                Put #f, , ItemD(i)
        Close #f
        DoEvents
    Next

And also make a module and add this:
Code:
Public Const MAX_ITEMS = 200

And also the current item rec, 20 on the name is the same as on a default MS item name length. I changed it to 30 on the ItemD():
Code:
Type ItemRec
    Name As String * 20
    
    Pic As Integer
    Type As Byte
    Data1 As Integer
    Data2 As Integer
    Data3 As Integer
    StrReq As Long
    DefReq As Long
    SpeedReq As Long
    WisReq As Long
    InteReq As Long
    DropAble As Long
    
    AddHP As Long
    AddMP As Long
    AddSP As Long
    AddStr As Long
    AddDef As Long
    AddMagi As Long
    AddSpeed As Long
    AttackSpeed As Long
    AddInte As Long
End Type

Type ItemDRec
    Name As String * 30
    
    Pic As Integer
    Type As Byte
    Data1 As Integer
    Data2 As Integer
    Data3 As Integer
    StrReq As Long
    DefReq As Long
    SpeedReq As Long
    WisReq As Long
    InteReq As Long
    DropAble As Long
    
    AddHP As Long
    AddMP As Long
    AddSP As Long
    AddStr As Long
    AddDef As Long
    AddMagi As Long
    AddSpeed As Long
    AttackSpeed As Long
    AddInte As Long
End Type
And below that in the module, add this:
Code:
Public Item(0 To MAX_ITEMS) As ItemRec
Public ItemD(0 To MAX_ITEMS) As ItemDRec

Now when you press convert and then save it will write to a new folder and you'll just replace the old. Also remember to change the NAME_LENGTH in the itemRec to 30 instead.

Just felt like posting this cause I was bored doing math.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)