DreamDancer

Simple Dream Map Reader

Sep 4th, 2016
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ' simple map reader
  2. ' designed to run as VBA in an excel workbook
  3. ' there may variables declared here that are not used for this demo
  4.  
  5. Sub BreakMap()
  6. Dim RowIndex As Integer, Work As String, InIndex As Long
  7. Dim MapWidthIndex As Integer, MapHeightIndex As Integer, MapWidth As Integer, MapHeight As Integer
  8. Dim WhichWall As Long
  9. Dim FileName As String, FileIn As Integer, IntegerLow As Integer, Pump As Long
  10. Dim FeedMe As String * 1, FileOut As Integer
  11. Dim FSO As Object, Folder As Object
  12. Dim FloorData() As Long, ItemData() As Long
  13. Dim WallDataLeft() As Long, WallDataRight() As Long
  14. Dim EffectData() As Long, RegionData() As Long
  15. Dim AmbienceData() As Long, LightingData() As Long
  16. Dim PatchPath As String
  17.  
  18. Sheets("Map Data").Activate
  19. On Error GoTo Whoops
  20. GoTo Skip
  21. Whoops:
  22.   Debug.Print Err.Description
  23.   Stop
  24.   Resume
  25. Skip:
  26.  
  27. Set FSO = CreateObject("Scripting.FileSystemObject")
  28. Close
  29. RowIndex = 2: InIndex = 0
  30. FileIn = FreeFile
  31. ' file name is stored in the first cell of the excel worksheet
  32. FileName = Cells(1, 1)
  33. Open FileName For Random As FileIn Len = 1
  34. Set Folder = FSO.GetFile(FileName)
  35. Do
  36.     InIndex = InIndex + 1
  37.     Get #FileIn, InIndex, FeedMe
  38.     IntegerLow = Asc(FeedMe)
  39.     If IntegerLow = 10 Then
  40.       Cells(RowIndex, 1) = Work
  41.         RowIndex = RowIndex + 1
  42.         If LCase(Work) = "body" Then Exit Do
  43.         If (InStr(1, Work, "height", vbTextCompare) > 0) Then
  44.           MapHeight = Val(Mid(Work, InStr(Work, "=") + 1))
  45.         End If
  46.         If (InStr(1, Work, "width", vbTextCompare) > 0) Then
  47.           MapWidth = Val(Mid(Work, InStr(Work, "=") + 1))
  48.         End If
  49.         If (InStr(1, Work, "patchs", vbTextCompare) > 0) Then
  50.           PatchPath = Folder.ParentFolder & "\" & Mid(Work, InStr(Work, "=") + 1) & "\"
  51.         End If
  52.         Work = ""
  53.     Else
  54.         Work = Work + Chr(IntegerLow)
  55.     End If
  56. Loop
  57.  
  58. ' loop through FloorData
  59. Cells(RowIndex, 1).Activate
  60. ReDim FloorData(MapHeight, MapWidth)
  61. For MapWidthIndex = 0 To MapWidth - 1
  62.     For MapHeightIndex = 0 To MapHeight - 1
  63.         InIndex = InIndex + 1
  64.         Get #FileIn, InIndex, FeedMe
  65.         Pump = Asc(FeedMe)
  66.         InIndex = InIndex + 1
  67.         Get #FileIn, InIndex, FeedMe
  68.         Pump = Pump + Asc(FeedMe) * 256
  69.         FloorData(MapHeightIndex, MapWidthIndex) = Pump
  70.     Next MapHeightIndex
  71. Next MapWidthIndex
  72.  
  73.  
  74. ' loop through ItemData
  75. ReDim ItemData(MapHeight, MapWidth)
  76. For MapWidthIndex = 0 To MapWidth - 1
  77.     For MapHeightIndex = 0 To MapHeight - 1
  78.         InIndex = InIndex + 1
  79.         Get #FileIn, InIndex, FeedMe
  80.         Pump = Asc(FeedMe)
  81.         InIndex = InIndex + 1
  82.         Get #FileIn, InIndex, FeedMe
  83.         Pump = Pump + (Asc(FeedMe) * 256)
  84.         ItemData(MapHeightIndex, MapWidthIndex) = Pump
  85.     Next MapHeightIndex
  86. Next MapWidthIndex
  87.  
  88.  
  89. ' loop though wall data
  90. ReDim WallDataLeft(MapHeight, MapWidth)
  91. ReDim WallDataRight(MapHeight, MapWidth)
  92. For MapWidthIndex = 0 To MapWidth - 1
  93.     For WhichWall = 1 To 2
  94.         For MapHeightIndex = 0 To MapHeight - 1
  95.             InIndex = InIndex + 1
  96.             Get #FileIn, InIndex, FeedMe
  97.             Pump = Asc(FeedMe)
  98.             If WhichWall = 1 Then
  99.               WallDataLeft(MapHeightIndex, MapWidthIndex) = Pump
  100.             Else
  101.               WallDataRight(MapHeightIndex, MapWidthIndex) = Pump
  102.             End If
  103.         Next MapHeightIndex
  104.     Next WhichWall
  105. Next MapWidthIndex
  106.  
  107.  
  108. If (Seek(FileIn) < FileLen(FileName)) Then
  109.  
  110.   ' loop through RegionData
  111.  ReDim RegionData(MapHeight, MapWidth)
  112.   For MapWidthIndex = 0 To MapWidth - 1
  113.       For MapHeightIndex = 0 To MapHeight - 1
  114.           InIndex = InIndex + 1
  115.           Get #FileIn, InIndex, FeedMe
  116.           Pump = Asc(FeedMe)
  117.           InIndex = InIndex + 1
  118.           Get #FileIn, InIndex, FeedMe
  119.           Pump = Pump + (Asc(FeedMe) * 256)
  120.           RegionData(MapHeightIndex, MapWidthIndex) = Pump
  121.       Next MapHeightIndex
  122.   Next MapWidthIndex
  123.  
  124.   ' loop through EffectData
  125.  ReDim EffectData(MapHeight, MapWidth)
  126.   For MapWidthIndex = 0 To MapWidth - 1
  127.       For MapHeightIndex = 0 To MapHeight - 1
  128.           InIndex = InIndex + 1
  129.           Get #FileIn, InIndex, FeedMe
  130.           Pump = Asc(FeedMe)
  131.           InIndex = InIndex + 1
  132.           Get #FileIn, InIndex, FeedMe
  133.           Pump = Pump + (Asc(FeedMe) * 256)
  134.           EffectData(MapHeightIndex, MapWidthIndex) = Pump
  135.       Next MapHeightIndex
  136.   Next MapWidthIndex
  137.  
  138.  
  139.   If (Seek(FileIn) < FileLen(FileName)) Then
  140.  
  141.     ' loop through LightingData
  142.    ReDim LightingData(MapHeight, MapWidth)
  143.     For MapWidthIndex = 0 To MapWidth - 1
  144.         For MapHeightIndex = 0 To MapHeight - 1
  145.             InIndex = InIndex + 1
  146.             Get #FileIn, InIndex, FeedMe
  147.             Pump = Asc(FeedMe)
  148.             InIndex = InIndex + 1
  149.             Get #FileIn, InIndex, FeedMe
  150.             Pump = Pump + (Asc(FeedMe) * 256)
  151.             LightingData(MapHeightIndex, MapWidthIndex) = Pump
  152.         Next MapHeightIndex
  153.     Next MapWidthIndex
  154.  
  155.    
  156.     ' loop through AmbienceData
  157.    ReDim AmbienceData(MapHeight, MapWidth)
  158.     For MapWidthIndex = 0 To MapWidth - 1
  159.         For MapHeightIndex = 0 To MapHeight - 1
  160.             InIndex = InIndex + 1
  161.             Get #FileIn, InIndex, FeedMe
  162.             Pump = Asc(FeedMe)
  163.             InIndex = InIndex + 1
  164.             Get #FileIn, InIndex, FeedMe
  165.             Pump = Pump + (Asc(FeedMe) * 256)
  166.             AmbienceData(MapHeightIndex, MapWidthIndex) = Pump
  167.         Next MapHeightIndex
  168.     Next MapWidthIndex
  169.    
  170.   End If
  171.  
  172. End If
  173.  
  174. Debug.Print Seek(FileIn), FileLen(FileName)
  175.  
  176. Close FileIn
  177.  
  178. ' dump the data to a file organized by X,Y
  179.  
  180. FileOut = FreeFile
  181. FileName = Replace$(FileName, ".map", ".mbox")
  182. Open FileName For Output As FileOut
  183.     For MapWidthIndex = 0 To MapWidth - 1
  184.         For MapHeightIndex = 0 To MapHeight - 1
  185.           Write #FileOut, MapHeightIndex, MapWidthIndex * 2, _
  186.             FloorData(MapHeightIndex, MapWidthIndex), _
  187.             ItemData(MapHeightIndex, MapWidthIndex), _
  188.             WallDataLeft(MapHeightIndex, MapWidthIndex), _
  189.             WallDataRight(MapHeightIndex, MapWidthIndex), _
  190.             EffectData(MapHeightIndex, MapWidthIndex), _
  191.             RegionData(MapHeightIndex, MapWidthIndex), _
  192.             AmbienceData(MapHeightIndex, MapWidthIndex), _
  193.             LightingData(MapHeightIndex, MapWidthIndex)
  194.         Next MapHeightIndex
  195.     Next MapWidthIndex
  196. Close FileOut
Advertisement
Add Comment
Please, Sign In to add comment