Option Strict Off
Option Explicit On

Imports System.IO

Friend Class file559
    Public itemdata As IO.MemoryStream
    Public itemloc As Integer 'Now 0 based


    'UPGRADE_WARNING: Lower bound of array bytes10340 was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
    Private bytes10340(4) As Byte
    'UPGRADE_WARNING: Lower bound of array bytes10336 was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
    Private bytes10336(256) As Byte
    'UPGRADE_WARNING: Lower bound of array bytes10080 was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
    Private bytes10080(64) As Byte
    'UPGRADE_WARNING: Lower bound of array bytes10016 was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
    Private bytes10016(256) As Byte
    'UPGRADE_WARNING: Lower bound of array Doors was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
    'UPGRADE_WARNING: Arrays can't be declared with New. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="CC9D3AE5-6B95-4B43-91C7-28276302A5E8"'
    Private Doors() As Tdoor = ADGEDotNetUt.ArrayUt(Of Tdoor).NewArray1(4)
    'UPGRADE_WARNING: Lower bound of array MonsterDrops was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
    'UPGRADE_WARNING: Arrays can't be declared with New. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="CC9D3AE5-6B95-4B43-91C7-28276302A5E8"'
    Private MonsterDrops() As monsterdrop = ADGEDotNetUt.ArrayUt(Of monsterdrop).NewArray1(40)
    'UPGRADE_WARNING: Lower bound of array soundnums was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
    Private soundnums(8) As Byte
    'UPGRADE_WARNING: Lower bound of array Monsters was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
    'UPGRADE_WARNING: Arrays can't be declared with New. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="CC9D3AE5-6B95-4B43-91C7-28276302A5E8"'
    Private Monsters() As monster = ADGEDotNetUt.ArrayUt(Of monster).NewArray1(27)
    'UPGRADE_WARNING: Lower bound of array foodvalues was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
    Private foodvalues(8) As Integer
    'UPGRADE_WARNING: Lower bound of array bytes8946 was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
    Private bytes8946(54) As Byte 'misc item weights
    Public word8892 As Integer
    'UPGRADE_WARNING: Lower bound of array armors was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
    'UPGRADE_WARNING: Arrays can't be declared with New. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="CC9D3AE5-6B95-4B43-91C7-28276302A5E8"'
    Private armors() As armor = ADGEDotNetUt.ArrayUt(Of armor).NewArray1(58)
    'UPGRADE_WARNING: Lower bound of array weapons was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
    'UPGRADE_WARNING: Arrays can't be declared with New. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="CC9D3AE5-6B95-4B43-91C7-28276302A5E8"'
    Private weapons() As weapon = ADGEDotNetUt.ArrayUt(Of weapon).NewArray1(46)
    'UPGRADE_WARNING: Lower bound of array objs was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
    'UPGRADE_WARNING: Arrays can't be declared with New. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="CC9D3AE5-6B95-4B43-91C7-28276302A5E8"'
    Private objs() As obj = ADGEDotNetUt.ArrayUt(Of obj).NewArray1(180)
    'UPGRADE_WARNING: Lower bound of array bytes7302 was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
    Private bytes7302(16) As Byte
    'UPGRADE_WARNING: Lower bound of array dbentrysizes was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
    Private dbentrysizes(16) As Byte
    'UPGRADE_WARNING: Lower bound of array deltaxs was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
    Private deltaxs(4) As Integer
    'UPGRADE_WARNING: Lower bound of array deltays was changed from 1 to 0. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="0F1C9BE1-AF9D-476E-83B1-17D43BECFF20"'
    Private deltays(4) As Integer

    Function door(ByVal num As Short) As Tdoor
        door = Doors(num)
    End Function
    Function monsterdrop(ByVal num As Short) As monsterdrop
        monsterdrop = MonsterDrops(num)
    End Function
    Function soundnum(ByVal num As Short) As Byte
        soundnum = soundnums(num)
    End Function
    Function monster(ByVal num As Short) As monster
        monster = Monsters(num)
    End Function
    Function FoodValue(ByVal num As Short) As Integer
        FoodValue = foodvalues(num)
    End Function
    'UPGRADE_NOTE: val was upgraded to val_Renamed. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A9E4979A-37FA-4718-9994-97DD76ED70A7"'
    Sub setfoodvalue(ByVal num As Short, ByVal val_Renamed As Integer)
        foodvalues(num) = val_Renamed
    End Sub
    Function Armor(ByVal num As Short) As armor
        Armor = armors(num)
    End Function
    Function weapon(ByVal num As Short) As weapon
        weapon = weapons(num)
    End Function
    Function obj(ByVal num As Short) As obj
        obj = objs(num)
    End Function
    Function dbentrysize(ByVal num As Short) As Byte
        dbentrysize = dbentrysizes(num)
    End Function
    Function deltax(ByVal num As Short) As Integer
        deltax = deltaxs(num)
    End Function
    Function deltay(ByVal num As Short) As Integer
        deltay = deltays(num)
    End Function

    Function byte10340(ByVal num As Short) As Byte
        byte10340 = bytes10340(num)
    End Function
    Function byte10336(ByVal num As Short) As Byte
        byte10336 = bytes10336(num)
    End Function
    Function byte10080(ByVal num As Short) As Byte
        byte10080 = bytes10080(num)
    End Function
    Function byte10016(ByVal num As Short) As Byte
        byte10016 = byte10016(num)
    End Function
    Function byte8946(ByVal num As Short) As Byte
        byte8946 = bytes8946(num)
    End Function
    Function byte7302(ByVal num As Short) As Byte
        byte7302 = bytes7302(num)
    End Function

    Function read_byte() As Byte
        'UPGRADE_ISSUE: MidB function is not supported. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="367764E5-F3F8-4E43-AC3E-7FE0B5E074E2"'
        'UPGRADE_ISSUE: AscB function is not supported. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="367764E5-F3F8-4E43-AC3E-7FE0B5E074E2"'
        itemdata.Position = itemloc
        read_byte = New IO.BinaryReader(itemdata).ReadByte()
        itemloc = itemloc + 1
    End Function

    Function read_int() As Integer
        Dim b1 As Byte
        Dim b2 As Byte
        b2 = read_byte()
        b1 = read_byte()
        read_int = b2
        read_int = read_int * 256
        read_int = read_int + b1
    End Function

    Sub write_byte(ByRef num As Byte)
        'UPGRADE_ISSUE: ChrB function is not supported. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="367764E5-F3F8-4E43-AC3E-7FE0B5E074E2"'
        itemdata.Position = itemloc
        itemdata.WriteByte(num)
        itemloc = itemloc + 1
    End Sub
    Sub write_int(ByRef num As Integer)
        Dim b1 As Byte
        Dim b2 As Byte
        Dim l1 As Integer
        l1 = num And &HFF00
        b1 = l1 / &H100
        b2 = num And &HFF
        write_byte(b1)
        write_byte(b2)
    End Sub


    'UPGRADE_NOTE: graphics was upgraded to graphics_Renamed. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A9E4979A-37FA-4718-9994-97DD76ED70A7"'
    Public Sub update()
        Dim i As Short

        itemdata = New IO.MemoryStream()
        itemloc = 0

        For i = 1 To 4
            write_byte(bytes10340(i))
        Next
        For i = 1 To 256
            write_byte(bytes10336(i))
        Next
        For i = 1 To 64
            write_byte(bytes10080(i))
        Next
        For i = 1 To 256
            write_byte(bytes10016(i))
        Next

        For i = 1 To 4
            write_byte((Doors(i).Byte0))
            write_byte((Doors(i).Strength))
        Next

        For i = 1 To 40
            write_int((MonsterDrops(i).word0))
        Next

        For i = 1 To 8
            write_byte(soundnums(i))
        Next

        For i = 1 To 27
            write_byte((Monsters(i).IdNum))
            write_byte((Monsters(i).attacksound))
            write_int((Monsters(i).Word2))
            write_int((Monsters(i).Word4))
            write_byte((Monsters(i).Speed))
            write_byte((Monsters(i).MinSpeed))
            write_byte((Monsters(i).Armor_Renamed))
            write_byte((Monsters(i).BaseHealth))
            write_byte((Monsters(i).quickness))
            write_byte((Monsters(i).Poison))
            write_byte((Monsters(i).power))
            write_byte((Monsters(i).Unused1))
            write_int((Monsters(i).word14))
            write_int((Monsters(i).word16))
            write_int((Monsters(i).word18))
            write_int((Monsters(i).word20))
            write_byte((Monsters(i).byte22))
            write_byte((Monsters(i).byte23))
            write_byte((Monsters(i).damagetype))
            write_byte((Monsters(i).Unused2))
        Next  '702

        For i = 1 To 8
            write_int(foodvalues(i))
        Next
        For i = 1 To 54
            write_byte(bytes8946(i))
        Next

        write_int(word8892)

        For i = 1 To 58
            write_byte((armors(i).Weight))
            write_byte((armors(i).armor_Renamed))
            write_byte((armors(i).Byte2))
            write_byte((armors(i).Unused1))
        Next  '232

        For i = 1 To 46
            write_byte((weapons(i).Weight))
            write_byte((weapons(i).Byte1))
            write_byte((weapons(i).Damage))
            write_byte((weapons(i).Distance))
            write_int((weapons(i).Word4))
        Next  '276

        For i = 1 To 180
            write_int((objs(i).ItemType))
            write_byte((objs(i).FloorGraphic))
            write_byte((objs(i).Combos))
            write_int((objs(i).WearLocs))
        Next  '1080

        For i = 1 To 16
            write_byte(bytes7302(i))
        Next

        For i = 1 To 16
            write_byte(dbentrysizes(i))
        Next

        For i = 1 To 4
            write_int(deltaxs(i))
        Next

        For i = 1 To 4
            write_int(deltays(i))
        Next

        'graphics.setitemsize 560, LenB(itemdata)
        'graphics.setitemstr 560, itemdata
        'UPGRADE_ISSUE: LenB function is not supported. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="367764E5-F3F8-4E43-AC3E-7FE0B5E074E2"'
        'UPGRADE_WARNING: Couldn't resolve default property of object graphics.setgitemsize. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
        graphics.setgitemsize(559, itemdata.Length)
        'UPGRADE_WARNING: Couldn't resolve default property of object graphics.setgitemdata. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
        graphics.setgitemdata(559, itemdata)
    End Sub


    Public Sub read()
        Dim i As Short

        itemloc = 0

        For i = 1 To 4
            bytes10340(i) = read_byte
        Next
        For i = 1 To 256
            bytes10336(i) = read_byte
        Next
        For i = 1 To 64
            bytes10080(i) = read_byte
        Next
        For i = 1 To 256
            bytes10016(i) = read_byte
        Next

        For i = 1 To 4
            Doors(i).Byte0 = read_byte
            Doors(i).Strength = read_byte
        Next

        For i = 1 To 40
            MonsterDrops(i).word0 = read_int
        Next

        For i = 1 To 8
            soundnums(i) = read_byte
        Next

        For i = 1 To 27
            Monsters(i).IdNum = read_byte
            Monsters(i).attacksound = read_byte
            Monsters(i).Word2 = read_int
            Monsters(i).Word4 = read_int
            Monsters(i).Speed = read_byte
            Monsters(i).MinSpeed = read_byte
            Monsters(i).Armor_Renamed = read_byte()
            Monsters(i).BaseHealth = read_byte
            Monsters(i).quickness = read_byte
            Monsters(i).Poison = read_byte
            Monsters(i).power = read_byte
            Monsters(i).Unused1 = read_byte
            Monsters(i).word14 = read_int
            Monsters(i).word16 = read_int
            Monsters(i).word18 = read_int
            Monsters(i).word20 = read_int
            Monsters(i).byte22 = read_byte
            Monsters(i).byte23 = read_byte
            Monsters(i).damagetype = read_byte
            Monsters(i).Unused2 = read_byte
        Next  '702

        For i = 1 To 8
            foodvalues(i) = read_int
        Next
        For i = 1 To 54
            bytes8946(i) = read_byte
        Next

        word8892 = read_int

        For i = 1 To 58
            armors(i).Weight = read_byte
            armors(i).armor_Renamed = read_byte()
            armors(i).Byte2 = read_byte
            armors(i).Unused1 = read_byte
        Next  '232

        For i = 1 To 46
            weapons(i).Weight = read_byte
            weapons(i).Byte1 = read_byte
            weapons(i).Damage = read_byte
            weapons(i).Distance = read_byte
            weapons(i).Word4 = read_int
        Next  '276

        For i = 1 To 180
            objs(i).ItemType = read_int
            objs(i).FloorGraphic = read_byte
            objs(i).Combos = read_byte
            objs(i).WearLocs = read_int
        Next  '1080

        For i = 1 To 16
            bytes7302(i) = read_byte
        Next

        For i = 1 To 16
            dbentrysizes(i) = read_byte
        Next

        For i = 1 To 4
            deltaxs(i) = read_int
        Next

        For i = 1 To 4
            deltays(i) = read_int
        Next
    End Sub



    '  i8  Byte10340[4];
    '  i8  Byte10336[256]; //       ...
    '  i8  Byte10080[64];  //       ...
    '  i8  Byte10016[256]; //       ...
    '  i16 DoorCharacteristics[4]; //9760// swapped when read.
    '  i16 MonsterDroppings[40];   //9752//
    '  ui8 uByte9672[8];   // Sound numbers???
    '  ITEM26 MonsterDescriptor[27];//9664
    '  //ITEM26 Item9664[27];//
    '  i16 FoodValue[8];//8962 // obj_Apple to obj_DragonSteak      ...
    '                   // swapped when read
    '  i8  Byte8946[54];   //
    '  i16 Word8892;       //       ...
    '  CLOTHINGDESC ClothingDesc[58]; //8890
    '  WEAPONDESC weapons[46];//8658   // Used for Database5 objects
    '                      // word4 swapped when read;
    '                      // pDB5->weaponType() is index
    '  OBJDESC ObjDesc[180];//8382
    '            // -object Type
    '            // -effect of objects when attacking?
    '            // -Words 0 and 4 swapped when read
    '            // -
    '            // -Word4 bit 0 = consumable??
    '            // -indexed by Object Index
    '            //    = scroll type   +  0 //  1 Scroll type
    '            //    = chest type    +  1 //  1 Chest types
    '            //    = potion type   +  2 // 21 Potion types
    '            //    = weapon type   + 23 // 46 Weapon types
    '            //    = clothing type + 69 // 58 Clothing types
    '            //    = food type     +127 // 53 Misc types
    '
    '  i8  Byte7302[16];   //  #extra entries in each 'misc' database     ...
    '  i8  DBEntrySize[16];//7286 // Size of entries in each 'misc' database     ...
    '                             // Always an even number! Sometimes zero.
    '  i16 DeltaY[4]; //7270  // deltay for 4 directions
    '  i16 DeltaX[4]; //7262    // deltax for 4 directions End of 22f
End Class