Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ' simple map reader
- ' designed to run as VBA in an excel workbook
- ' there may variables declared here that are not used for this demo
- Sub BreakMap()
- Dim RowIndex As Integer, Work As String, InIndex As Long
- Dim MapWidthIndex As Integer, MapHeightIndex As Integer, MapWidth As Integer, MapHeight As Integer
- Dim WhichWall As Long
- Dim FileName As String, FileIn As Integer, IntegerLow As Integer, Pump As Long
- Dim FeedMe As String * 1, FileOut As Integer
- Dim FSO As Object, Folder As Object
- Dim FloorData() As Long, ItemData() As Long
- Dim WallDataLeft() As Long, WallDataRight() As Long
- Dim EffectData() As Long, RegionData() As Long
- Dim AmbienceData() As Long, LightingData() As Long
- Dim PatchPath As String
- Sheets("Map Data").Activate
- On Error GoTo Whoops
- GoTo Skip
- Whoops:
- Debug.Print Err.Description
- Stop
- Resume
- Skip:
- Set FSO = CreateObject("Scripting.FileSystemObject")
- Close
- RowIndex = 2: InIndex = 0
- FileIn = FreeFile
- ' file name is stored in the first cell of the excel worksheet
- FileName = Cells(1, 1)
- Open FileName For Random As FileIn Len = 1
- Set Folder = FSO.GetFile(FileName)
- Do
- InIndex = InIndex + 1
- Get #FileIn, InIndex, FeedMe
- IntegerLow = Asc(FeedMe)
- If IntegerLow = 10 Then
- Cells(RowIndex, 1) = Work
- RowIndex = RowIndex + 1
- If LCase(Work) = "body" Then Exit Do
- If (InStr(1, Work, "height", vbTextCompare) > 0) Then
- MapHeight = Val(Mid(Work, InStr(Work, "=") + 1))
- End If
- If (InStr(1, Work, "width", vbTextCompare) > 0) Then
- MapWidth = Val(Mid(Work, InStr(Work, "=") + 1))
- End If
- If (InStr(1, Work, "patchs", vbTextCompare) > 0) Then
- PatchPath = Folder.ParentFolder & "\" & Mid(Work, InStr(Work, "=") + 1) & "\"
- End If
- Work = ""
- Else
- Work = Work + Chr(IntegerLow)
- End If
- Loop
- ' loop through FloorData
- Cells(RowIndex, 1).Activate
- ReDim FloorData(MapHeight, MapWidth)
- For MapWidthIndex = 0 To MapWidth - 1
- For MapHeightIndex = 0 To MapHeight - 1
- InIndex = InIndex + 1
- Get #FileIn, InIndex, FeedMe
- Pump = Asc(FeedMe)
- InIndex = InIndex + 1
- Get #FileIn, InIndex, FeedMe
- Pump = Pump + Asc(FeedMe) * 256
- FloorData(MapHeightIndex, MapWidthIndex) = Pump
- Next MapHeightIndex
- Next MapWidthIndex
- ' loop through ItemData
- ReDim ItemData(MapHeight, MapWidth)
- For MapWidthIndex = 0 To MapWidth - 1
- For MapHeightIndex = 0 To MapHeight - 1
- InIndex = InIndex + 1
- Get #FileIn, InIndex, FeedMe
- Pump = Asc(FeedMe)
- InIndex = InIndex + 1
- Get #FileIn, InIndex, FeedMe
- Pump = Pump + (Asc(FeedMe) * 256)
- ItemData(MapHeightIndex, MapWidthIndex) = Pump
- Next MapHeightIndex
- Next MapWidthIndex
- ' loop though wall data
- ReDim WallDataLeft(MapHeight, MapWidth)
- ReDim WallDataRight(MapHeight, MapWidth)
- For MapWidthIndex = 0 To MapWidth - 1
- For WhichWall = 1 To 2
- For MapHeightIndex = 0 To MapHeight - 1
- InIndex = InIndex + 1
- Get #FileIn, InIndex, FeedMe
- Pump = Asc(FeedMe)
- If WhichWall = 1 Then
- WallDataLeft(MapHeightIndex, MapWidthIndex) = Pump
- Else
- WallDataRight(MapHeightIndex, MapWidthIndex) = Pump
- End If
- Next MapHeightIndex
- Next WhichWall
- Next MapWidthIndex
- If (Seek(FileIn) < FileLen(FileName)) Then
- ' loop through RegionData
- ReDim RegionData(MapHeight, MapWidth)
- For MapWidthIndex = 0 To MapWidth - 1
- For MapHeightIndex = 0 To MapHeight - 1
- InIndex = InIndex + 1
- Get #FileIn, InIndex, FeedMe
- Pump = Asc(FeedMe)
- InIndex = InIndex + 1
- Get #FileIn, InIndex, FeedMe
- Pump = Pump + (Asc(FeedMe) * 256)
- RegionData(MapHeightIndex, MapWidthIndex) = Pump
- Next MapHeightIndex
- Next MapWidthIndex
- ' loop through EffectData
- ReDim EffectData(MapHeight, MapWidth)
- For MapWidthIndex = 0 To MapWidth - 1
- For MapHeightIndex = 0 To MapHeight - 1
- InIndex = InIndex + 1
- Get #FileIn, InIndex, FeedMe
- Pump = Asc(FeedMe)
- InIndex = InIndex + 1
- Get #FileIn, InIndex, FeedMe
- Pump = Pump + (Asc(FeedMe) * 256)
- EffectData(MapHeightIndex, MapWidthIndex) = Pump
- Next MapHeightIndex
- Next MapWidthIndex
- If (Seek(FileIn) < FileLen(FileName)) Then
- ' loop through LightingData
- ReDim LightingData(MapHeight, MapWidth)
- For MapWidthIndex = 0 To MapWidth - 1
- For MapHeightIndex = 0 To MapHeight - 1
- InIndex = InIndex + 1
- Get #FileIn, InIndex, FeedMe
- Pump = Asc(FeedMe)
- InIndex = InIndex + 1
- Get #FileIn, InIndex, FeedMe
- Pump = Pump + (Asc(FeedMe) * 256)
- LightingData(MapHeightIndex, MapWidthIndex) = Pump
- Next MapHeightIndex
- Next MapWidthIndex
- ' loop through AmbienceData
- ReDim AmbienceData(MapHeight, MapWidth)
- For MapWidthIndex = 0 To MapWidth - 1
- For MapHeightIndex = 0 To MapHeight - 1
- InIndex = InIndex + 1
- Get #FileIn, InIndex, FeedMe
- Pump = Asc(FeedMe)
- InIndex = InIndex + 1
- Get #FileIn, InIndex, FeedMe
- Pump = Pump + (Asc(FeedMe) * 256)
- AmbienceData(MapHeightIndex, MapWidthIndex) = Pump
- Next MapHeightIndex
- Next MapWidthIndex
- End If
- End If
- Debug.Print Seek(FileIn), FileLen(FileName)
- Close FileIn
- ' dump the data to a file organized by X,Y
- FileOut = FreeFile
- FileName = Replace$(FileName, ".map", ".mbox")
- Open FileName For Output As FileOut
- For MapWidthIndex = 0 To MapWidth - 1
- For MapHeightIndex = 0 To MapHeight - 1
- Write #FileOut, MapHeightIndex, MapWidthIndex * 2, _
- FloorData(MapHeightIndex, MapWidthIndex), _
- ItemData(MapHeightIndex, MapWidthIndex), _
- WallDataLeft(MapHeightIndex, MapWidthIndex), _
- WallDataRight(MapHeightIndex, MapWidthIndex), _
- EffectData(MapHeightIndex, MapWidthIndex), _
- RegionData(MapHeightIndex, MapWidthIndex), _
- AmbienceData(MapHeightIndex, MapWidthIndex), _
- LightingData(MapHeightIndex, MapWidthIndex)
- Next MapHeightIndex
- Next MapWidthIndex
- Close FileOut
Advertisement
Add Comment
Please, Sign In to add comment