Advertisement
Guest User

Map Converter V0.6 program.exe source code

a guest
May 11th, 2015
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 35.42 KB | None | 0 0
  1. #cs ----------------------------------------------------------------------------
  2.  
  3.  AutoIt Version: 3.3.10.2
  4.  Author:         JBRWolf
  5.  
  6.  Script Function:
  7.     Convert Feral Heart Maps into Impressive Title server ones.
  8.  
  9. #ce ----------------------------------------------------------------------------
  10.  
  11. ;---------------Includes---------------
  12. #include <WindowsConstants.au3>
  13. #include <GUIConstantsEx.au3>
  14. #include <EditConstants.au3>
  15. #include <GuiEdit.au3>
  16. #include <ScrollBarsConstants.au3>
  17. #include <File.au3>
  18. #include <Array.au3>
  19. ;--------------------------------------
  20.  
  21. ;---Program Resource Location Variables---
  22.  
  23. ;--Should exist--
  24. $resourceDir = @ScriptDir&"\resources"
  25. $dataDir = $resourceDir&"\data"
  26. $tempDir = $resourceDir&"\temp"
  27. $optionsApp = $resourceDir&"\changeOptions.exe"
  28. ;----------------
  29.  
  30. ;--Dynamic Files--
  31. $errorLog = @ScriptDir&"\Error Log.txt"
  32. $normalLog = @ScriptDir&"\log.txt"
  33. $optionsFile = $dataDir&"\options.dat"
  34. $tempFolder = ""
  35. ;-----------------
  36.  
  37. ;-
  38. $mapName = ""
  39. $FHFolder = ""
  40. $FHTerrainsFolder = ""
  41. $FHMapFile = ""
  42. $FHMapFolder = ""
  43. $FHObjectsFolder = ""
  44. $CopyObjectFiles = ""
  45. $OutputFolder = ""
  46. ;----
  47.  
  48. ;--
  49. $mapXSize = 0
  50. $mapZSize = 0
  51. $mapHeight = 0
  52.  
  53. $mapDisplayName = ""
  54. ;----
  55.  
  56. ;-----------------------------------------
  57.  
  58. ;-Resource Check-
  59. if Not FileExists($resourceDir) Then
  60.    error("Missing dirctory '"&$resourceDir&"'",1,True)
  61. EndIf
  62. if Not FileExists($dataDir) Then
  63.    error("Missing dirctory '"&$dataDir&"'",2,True)
  64. EndIf
  65. if Not FileExists($optionsApp) Then
  66.    error("Missing file '"&$optionsApp&"'",3,True)
  67. EndIf
  68. if Not FileExists($tempDir) Then
  69.    error("Missing dirctory '"&$tempDir&"'",9,True)
  70. EndIf
  71. ;----------------
  72.  
  73. Run($optionsApp)
  74. while ProcessExists("changeOptions.exe")
  75.    Sleep(100)
  76. WEnd
  77.  
  78. if FileExists($normalLog) Then
  79.    FileDelete($normalLog)
  80. EndIf
  81.  
  82. ;----------------------------------------GUI----------------------------------------
  83.  
  84. $GuiWin = GUICreate("Map Converter Version 0.6", 500, 300,-1,-1)
  85. $skin = GUICtrlCreatePic("",0,0,0,0) ; --------------- Background image
  86. GUICtrlSetState(-1, $GUI_DISABLE)
  87.  
  88. $optionsButton = GUICtrlCreateButton("Options",200,10,100,50)
  89. GUICtrlSetFont(-1,14)
  90.  
  91. $objectscovertButton = GUICtrlCreateButton("Objects Only Convert",160,75,180,50) ;place holder
  92. GUICtrlSetState(-1,$GUI_DISABLE )
  93. GUICtrlSetFont(-1,12)
  94.  
  95. $convertButton = GUICtrlCreateButton("Convert",200,140,100,50)
  96. GUICtrlSetFont(-1,14)
  97.  
  98. $credit = GUICtrlCreateLabel("-By JBRWolf-",5,5,100,20)
  99.  
  100. $outputBox = GUICtrlCreateEdit("",0,200,500,80,BitOR($WS_VSCROLL,$ES_READONLY,$ES_CENTER))
  101. GUISetState(@SW_SHOW)
  102. ;-----------------------------------------------------------------------------------
  103.  
  104. ;============================ Run Time ============================
  105.  
  106. outputPrint("================================== Startup ==================================")
  107. loadOptions()
  108. outputPrint("Clearing temp files..")
  109. ClearFoldersInFolder($tempDir)
  110. outputPrint("Temp files cleared")
  111. While 1
  112.    $msg = GUIGetMsg()
  113.    If $msg == $GUI_EVENT_CLOSE Then ExitLoop
  114.  
  115.    If $msg == $optionsButton Then
  116.       Run($optionsApp)
  117.       while ProcessExists("changeOptions.exe")
  118.          Sleep(100)
  119.       WEnd
  120.       loadOptions()
  121.    EndIf
  122.  
  123.    if $msg == $convertButton Then
  124.       loadOptions()
  125.       outputPrint("")
  126.       outputPrint("-Checking file existance -")
  127.       outputPrint("")
  128.       if FileExists($FHMapFile) Then
  129.           outputPrint($FHMapFile&" exists!")
  130.          if FileExists($FHObjectsFolder) Then
  131.              outputPrint($FHObjectsFolder&" exists!")
  132.             if FileExists($OutputFolder) Then
  133.                outputPrint($OutputFolder&" exists!")
  134.                if FileExists($FHMapFolder) Then
  135.                   outputPrint($FHMapFolder&" exists!")
  136.                   outputPrint("-----------------")
  137.                   outputPrint("")
  138.                   outputPrint("Finding terrain file..")
  139.                   $terrainFile = $FHMapFolder&"\"&$mapName&"Terrain.cfg"
  140.                   outputPrint("Checking for "&$terrainFile)
  141.                   if FileExists($terrainFile) Then
  142.                      outputPrint("Terrain file detected: "&$terrainFile)
  143.  
  144.                      outputPrint("Clearing temp files..")
  145.                      ClearFoldersInFolder($tempDir)
  146.                      outputPrint("Temp files cleared")
  147.  
  148.                      $tempFolder = $tempDir&"\"&$mapName
  149.                      outputPrint("Creating temp folder "&$tempFolder)
  150.                      if FileExists($tempDir) then
  151.                         if FileExists($tempFolder) Then
  152.                            DirRemove($tempFolder,1)
  153.                            outputPrint("Removed already existing temp folder "&$tempFolder)
  154.                         EndIf
  155.                         DirCreate($tempFolder)
  156.                         outputPrint("Temp folder created")
  157.  
  158.                         outputPrint("Reading map dimensions..")
  159.                         $no_lines = _FileCountLines($terrainFile)
  160.                         outputPrint("Terrain file is "&$no_lines&" lines long")
  161.                         if $no_lines > 3 Then
  162.                            $foundx = False
  163.                            $foundz = False
  164.                            $foundh = False
  165.                            for $i = 0 To $no_lines
  166.                               $line = FileReadLine($terrainFile,$i)
  167.                               outputPrint("Reading line "&$i&": "&$line)
  168.                               $line = StringLower($line)
  169.                               if StringLeft($line,11) == "pageworldx=" Then
  170.                                  $mapXSize = Number(StringTrimLeft($line,11))
  171.                                  $foundx = True
  172.                                  outputPrint("Found map x size: "&$mapXSize)
  173.                               Else
  174.                                  if StringLeft($line,11) == "pageworldz=" Then
  175.                                     $mapZSize = Number(StringTrimLeft($line,11))
  176.                                     $foundz = True
  177.                                     outputPrint("Found map z size: "&$mapZSize)
  178.                                  Else
  179.                                     if StringLeft($line,10) == "maxheight=" Then
  180.                                        $mapHeight = Number(StringTrimLeft($line,10))
  181.                                        $foundh = True
  182.                                        outputPrint("Found map height: "&$mapHeight)
  183.                                     EndIf
  184.                                  EndIf
  185.                               EndIf
  186.                               if $foundx and $foundz and $foundh Then
  187.                                  ExitLoop
  188.                               EndIf
  189.                            Next
  190.                            if $foundx and $foundz and $foundh Then
  191.                               outputPrint("")
  192.                               outputPrint("---Dimensions found---")
  193.                               outputPrint("$mapXSize = "&$mapXSize)
  194.                               outputPrint("$mapZSize = "&$mapZSize)
  195.                               outputPrint("$mapHeight = "&$mapHeight)
  196.                               outputPrint("----------------------")
  197.                               outputPrint("")
  198.                               outputPrint("Copying terrain file to temp folder")
  199.                               FileCopy($terrainFile,$tempFolder&"\"&$mapName&"Terrain.cfg")
  200.                               outputPrint("Copied '"&$terrainFile&"' to '"&$tempFolder&"\"&$mapName&"Terrain.cfg"&"'")
  201.                               outputPrint("")
  202.                               outputPrint("==================== .world file ====================")
  203.                               outputPrint("")
  204.                               outputPrint("Getting map display name and spawn position...")
  205.                               $no_lines = _FileCountLines($FHMapFile)
  206.                               outputPrint("Map file is "&$no_lines&" lines long")
  207.                               if $no_lines > 3 Then
  208.                                  $foundDisplayName = False
  209.                                  $foundSpawn = False
  210.                                  $spawnPos = ""
  211.                                  $hasPortal = False
  212.                                  $section = ""
  213.                                  for $i = 0 To $no_lines ;Could of done all the reading now but oh well
  214.                                     $line = FileReadLine($FHMapFile,$i)
  215.                                     outputPrint("Reading line "&$i&": "&$line)
  216.                                     $lowerline = StringLower($line)
  217.                                     if StringLeft($lowerline,5) == "name=" Then
  218.                                        if $section == "map" Then
  219.                                           $mapDisplayName = StringTrimLeft($line,5)
  220.                                           $foundDisplayName = True
  221.                                           outputPrint("Found map display name: "&$mapDisplayName)
  222.                                        EndIf
  223.                                     Else
  224.                                        if StringLeft($lowerline,1) == "[" Then
  225.                                           $section = StringTrimRight(StringTrimLeft($lowerline,1),1)
  226.                                        Else
  227.                                           if $section == "portal" Then
  228.                                              If StringLeft($lowerline,10) == "hasportal=" Then
  229.                                                 if StringTrimLeft($lowerline,10) == "true" Then
  230.                                                    $hasPortal = True
  231.                                                 EndIf
  232.                                              Else
  233.                                                 if $hasPortal Then
  234.                                                    If StringLeft($lowerline,9) == "position=" Then
  235.                                                       $spawnPos = StringTrimLeft($lowerline,9)
  236.                                                       outputPrint("Found map spawn pos: "&$spawnPos)
  237.                                                       $foundSpawn = True
  238.                                                    EndIf
  239.                                                 EndIf
  240.                                              EndIf
  241.                                           EndIf
  242.                                        EndIf
  243.                                     EndIf
  244.                                  Next
  245.                                  if $foundDisplayName Then
  246.                                     $worldFile = $tempFolder&"\"&$mapDisplayName&".world"
  247.                                     outputPrint("")
  248.                                     outputPrint("Writing world file basics...")
  249.                                     FileWriteLine($worldFile,"[Initialize]")
  250.                                     FileWriteLine($worldFile,$mapName&"Terrain.cfg")
  251.                                     FileWriteLine($worldFile,$mapXSize)
  252.                                     FileWriteLine($worldFile,$mapZSize)
  253.                                     ;Spawn position?
  254.                                     if $foundSpawn Then
  255.                                        FileWriteLine($worldFile,$spawnPos)
  256.                                     Else
  257.                                        FileWriteLine($worldFile,$mapXSize/2&" "&$mapHeight/2&" "&$mapZSize/2)
  258.                                     EndIf
  259.                                     ;---
  260.                                     outputPrint("Reading and writing weather, water and music sections(if any)..")
  261.                                     outputPrint("")
  262.                                     $section = ""
  263.                                     $mapWeather = ""
  264.                                     $mapSong = ""
  265.                                     $mapOceanPos = ""
  266.                                     $mapOceanSize = ""
  267.                                     $foundMapOceanPos = False
  268.                                     $foundMapOceanSize = False
  269.                                     for $i = 0 To $no_lines
  270.                                        $line = FileReadLine($FHMapFile,$i)
  271.                                        outputPrint("Reading line "&$i&": "&$line)
  272.                                        $lowerline = StringLower($line)
  273.                                        if StringLeft($lowerline,1) == "[" Then
  274.                                           $section = StringTrimRight(StringTrimLeft($lowerline,1),1)
  275.                                           outputPrint("Now reading section: "&$section)
  276.                                        Else
  277.                                           if $section == "weather" Then
  278.                                              if StringLeft($lowerline,9) == "filename=" Then
  279.                                                 $mapWeather = StringTrimLeft($line,9)
  280.                                                 outputPrint("Found and writing weather cycle: "&$mapWeather)
  281.                                                 FileWriteLine($worldFile,"[WeatherCycle]")
  282.                                                 FileWriteLine($worldFile,$mapWeather)
  283.                                              EndIf
  284.                                           EndIf
  285.  
  286.                                           if $section == "music" Then
  287.                                              if StringLeft($lowerline,5) == "name=" Then
  288.                                                 $mapSong = StringTrimLeft($line,5)
  289.                                                 outputPrint("Found and writing music: "&$mapSong)
  290.                                                 FileWriteLine($worldFile,"[Music]")
  291.                                                 FileWriteLine($worldFile,$mapSong)
  292.                                              EndIf
  293.                                           EndIf
  294.  
  295.                                           if $section == "water" Then
  296.                                              if StringLeft($lowerline,6) == "ocean=" Then
  297.                                                 $mapOceanPos= StringTrimLeft($line,6)
  298.                                                 $foundMapOceanPos = True
  299.                                                 outputPrint("Found water pos: "&$mapOceanPos)
  300.                                              Else
  301.                                                 if StringLeft($lowerline,10) == "oceansize=" Then
  302.                                                    $mapOceanSize= StringTrimLeft($line,10)
  303.                                                    $foundMapOceanSize = True
  304.                                                    outputPrint("Found water size: "&$mapOceanSize)
  305.                                                 EndIf
  306.                                              EndIf
  307.  
  308.                                              if $foundMapOceanPos and $foundMapOceanSize Then
  309.                                                 outputPrint("Writing Water Plane")
  310.                                                 FileWriteLine($worldFile,"[WaterPlane]")
  311.                                                 FileWriteLine($worldFile,$mapOceanPos)
  312.                                                 Local $osize = StringSplit($mapOceanSize, " ")
  313.                                                 outputPrint("X: "&$osize[1])
  314.                                                 outputPrint("Z: "&$osize[2])
  315.                                                 FileWriteLine($worldFile,$osize[1])
  316.                                                 FileWriteLine($worldFile,$osize[2])
  317.                                              EndIf
  318.                                           EndIf
  319.                                        EndIf
  320.                                     Next
  321.  
  322.                                     outputPrint("")
  323.                                     outputPrint("Reading gates file..")
  324.                                     $gatesFile = $FHMapFolder&"\"&$mapName&"Gates.cfg"
  325.                                     if FileExists($gatesFile) Then
  326.                                        $no_lines = _FileCountLines($gatesFile)
  327.                                        outputPrint("Gates file is "&$no_lines&" lines long")
  328.                                        if $no_lines > 1 Then
  329.                                           if FileReadLine($gatesFile,1) == "" Then
  330.                                              outputPrint("No gates found")
  331.                                           Else
  332.                                              for $i = 0 To $no_lines
  333.                                                 $line = FileReadLine($gatesFile,$i)
  334.                                                 outputPrint("Reading line "&$i&": "&$line)
  335.                                                 Local $gateParts = StringSplit($line,";")
  336.                                                 $gatePartsLen = UBound($gateParts)
  337.                                                 if $gatePartsLen > 4 Then
  338.                                                    $gatePos = $gateParts[1]
  339.                                                    $gateEndPos = $gateParts[5]
  340.                                                    $gateName = $gateParts[4]
  341.                                                    outputPrint("Writing gate "&$gateName&" with pos "&$gatePos&" to pos "&$gateEndPos)
  342.                                                    FileWriteLine($worldFile,"[Gate]")
  343.                                                    FileWriteLine($worldFile,"GateMatBlack")
  344.                                                    FileWriteLine($worldFile,$gatePos)
  345.                                                    FileWriteLine($worldFile,$gateName)
  346.                                                    FileWriteLine($worldFile,$gateEndPos)
  347.                                                 EndIf
  348.                                              Next
  349.                                           EndIf
  350.                                        Else
  351.                                           outputPrint("No gates found")
  352.                                        EndIf
  353.                                     Else
  354.                                        outputPrint("Failed to find gates file("&$gatesFile&")")
  355.                                     EndIf
  356.  
  357.  
  358.                                     outputPrint("")
  359.                                     outputPrint("Reading objects file..")
  360.                                     $objectsFile = $FHMapFolder&"\"&$mapName&"Objects.cfg"
  361.                                     if FileExists($objectsFile) Then
  362.                                        $no_lines = _FileCountLines($objectsFile)
  363.                                        outputPrint("Objects file is "&$no_lines&" lines long")
  364.                                        if $no_lines > 1 Then
  365.                                           if FileReadLine($objectsFile,1) == "" Then
  366.                                              outputPrint("No objects found")
  367.                                           Else
  368.  
  369.                                              $curObj = ""
  370.                                              $objectBlueprintFile = ""
  371.                                              $objFileLen = 0
  372.                                              $objLinePos = 0
  373.  
  374.                                              Global $EmptyArray[1]
  375.                                              Global $blueprintMeshes[1]
  376.                                              Global $blueprintColls[1]
  377.                                              $blueprintMeshes = $EmptyArray
  378.                                              $blueprintColls = $EmptyArray
  379.  
  380.                                              for $i = 0 To $no_lines
  381.                                                 $line = FileReadLine($objectsFile,$i)
  382.                                                 outputPrint("Reading line "&$i&": "&$line)
  383.  
  384.                                                 if StringLeft($line,1) == "[" Then
  385.                                                    $curObj = StringTrimRight(StringTrimLeft($line,1),1)
  386.                                                    outputPrint("Current object: "&$curObj)
  387.                                                    Local $objparts = StringSplit($curObj,"/")
  388.                                                    if UBound($objparts) == 3 Then
  389.                                                       $objectBlueprintFile = $FHObjectsFolder&"\"&$objparts[1]&".object"
  390.                                                       if FileExists($objectBlueprintFile) Then
  391.                                                          outputPrint("")
  392.                                                          outputPrint("Reading file "&$objectBlueprintFile)
  393.                                                          $objFileLen = _FileCountLines($objectBlueprintFile)
  394.                                                          outputPrint("Object blueprint file is "&$no_lines&" lines long")
  395.                                                          outputPrint("")
  396.                                                          outputPrint("Searching for object "&$objparts[2])
  397.                                                          outputPrint("")
  398.  
  399.                                                          $foundLine = False
  400.                                                          $inBPSection = False
  401.  
  402.                                                          $blueprintMeshes = $EmptyArray ;# Version 0.6
  403.                                                          $blueprintColls = $EmptyArray
  404.                                                          for $z = 0 To $objFileLen
  405.                                                             $line2 = FileReadLine($objectBlueprintFile,$z)
  406.                                                             outputPrint("  > Reading(object blueprint file) line "&$z&": "&$line2)
  407.                                                             if StringLeft($line2,1) == "[" Then
  408.                                                                $tempObjBlue = StringTrimRight(StringTrimLeft($line2,1),1);Sometimes you just run out of things to name your variables xD
  409.                                                                if $tempObjBlue == $objparts[2] Then
  410.                                                                   outputPrint("Found object blueprint at line "&$z)
  411.                                                                   $objLinePos = $z
  412.                                                                   $inBPSection = True
  413.                                                                   $foundLine = True
  414.                                                                Else
  415.                                                                   $inBPSection = False
  416.                                                                EndIf
  417.                                                             EndIf
  418.  
  419.                                                             if $inBPSection Then
  420.                                                                if StringLeft($line2,4) == "mesh" Then
  421.                                                                   $linetrimmed = StringReplace($line2,"%","")
  422.                                                                   $linetrimmed = StringTrimLeft($linetrimmed,StringInStr($linetrimmed,"="))
  423.                                                                   outputPrint("Found mesh "&$linetrimmed)
  424.                                                                   _ArrayInsert($blueprintMeshes, 1, $linetrimmed)
  425.                                                                Else
  426.                                                                   if StringLeft($line2,4) == "coll" Then
  427.                                                                      $linetrimmed = StringReplace($line2,"%","")
  428.                                                                      $linetrimmed = StringTrimLeft($linetrimmed,StringInStr($linetrimmed,"="))
  429.                                                                      outputPrint("Found collision "&$linetrimmed)
  430.                                                                      _ArrayInsert($blueprintColls, 1, $linetrimmed)
  431.                                                                   EndIf
  432.                                                                EndIf
  433.                                                             EndIf
  434.  
  435.  
  436.                                                          Next
  437.                                                          if Not $foundLine Then
  438.                                                             $curObj = ""
  439.                                                             outputPrint("Failed to find object blueprint")
  440.                                                          EndIf
  441.                                                       Else
  442.                                                          outputPrint("Failed to find object blueprint file")
  443.                                                          $curObj = ""
  444.                                                       EndIf
  445.                                                    Else
  446.                                                       outputPrint("Error reading object name")
  447.                                                       $curObj = ""
  448.                                                    EndIf
  449.  
  450.  
  451.                                                 Else
  452.                                                    if $line == "" Then
  453.  
  454.                                                    Else
  455.                                                       ;This is starting to get confusing xD
  456.                                                       outputPrint("")
  457.                                                       outputPrint("Reading placement details..")
  458.                                                       outputPrint("")
  459.                                                       $myObjectPos = ""
  460.                                                       $myObjectPosX = 0
  461.                                                       $myObjectPosY = 0
  462.                                                       $myObjectPosZ = 0
  463.  
  464.                                                       $myObjectScale = ""
  465.                                                       $myObjectScaleX = 0
  466.                                                       $myObjectScaleY = 0
  467.                                                       $myObjectScaleZ = 0
  468.  
  469.                                                       $myObjectRot = ""
  470.                                                       $myObjectRotP = 0 ;pitch
  471.                                                       $myObjectRotY = 0 ;yaw
  472.                                                       $myObjectRotR = 0 ;roll
  473.                                                       $myObjectRotX = 0 ; ? Lol
  474.  
  475.                                                       if StringInStr($line,";") Then
  476.                                                          local $myObjectTmpArr = StringSplit($line,";")
  477.                                                          $TmpArrSize = UBound($myObjectTmpArr)
  478.                                                          ;pos
  479.                                                          local $myObjectTmpPosArr = StringSplit($myObjectTmpArr[1]," ");You can tell I did this second because it doesn't have the winner comment
  480.                                                          if UBound($myObjectTmpPosArr) == 4 then
  481.                                                             $myObjectPos = $myObjectTmpArr[1]
  482.                                                             $myObjectPosX = Number($myObjectTmpPosArr[1])
  483.                                                             $myObjectPosY = Number($myObjectTmpPosArr[2])
  484.                                                             $myObjectPosZ = Number($myObjectTmpPosArr[3])
  485.                                                          EndIf
  486.  
  487.                                                          ;scale
  488.                                                          if $TmpArrSize > 2 then
  489.                                                             local $myObjectTmpScaleArr = StringSplit($myObjectTmpArr[2]," ");This variable is actually longer xD
  490.                                                             if UBound($myObjectTmpScaleArr) == 4 then
  491.                                                                $myObjectScale = $myObjectTmpArr[2]
  492.                                                                $myObjectScaleX = Number($myObjectTmpScaleArr[1])
  493.                                                                $myObjectScaleY = Number($myObjectTmpScaleArr[2])
  494.                                                                $myObjectScaleZ = Number($myObjectTmpScaleArr[3])
  495.                                                             EndIf
  496.                                                          EndIf
  497.  
  498.                                                          ;Rot
  499.                                                          if $TmpArrSize > 3 then
  500.                                                             local $myObjectTmpRotArr = StringSplit($myObjectTmpArr[3]," ")
  501.                                                             if UBound($myObjectTmpRotArr) == 5 then
  502.                                                                $myObjectRot = $myObjectTmpArr[3]
  503.                                                                $myObjectRotP = Number($myObjectTmpRotArr[1])
  504.                                                                $myObjectRotY = Number($myObjectTmpRotArr[2])
  505.                                                                $myObjectRotR = Number($myObjectTmpRotArr[3])
  506.                                                                $myObjectRotX = Number($myObjectTmpRotArr[4])
  507.                                                             EndIf
  508.                                                          EndIf
  509.                                                          outputPrint("Object x:"&$myObjectPosX)
  510.                                                          outputPrint("Object y:"&$myObjectPosY)
  511.                                                          outputPrint("Object z:"&$myObjectPosZ)
  512.                                                          ;Can't be bothered to output the rest xD
  513.  
  514.                                                       Else ;Only position info available for this obj
  515.                                                          $myObjectPos = $line
  516.                                                          local $myObjectTmpPosArr = StringSplit($myObjectPos," ");And the winner of the longest variable name goes to
  517.                                                          if UBound($myObjectTmpPosArr) == 4 then
  518.                                                             $myObjectPosX = Number($myObjectTmpPosArr[1])
  519.                                                             $myObjectPosY = Number($myObjectTmpPosArr[2])
  520.                                                             $myObjectPosZ = Number($myObjectTmpPosArr[3])
  521.                                                             outputPrint("Object x:"&$myObjectPosX)
  522.                                                             outputPrint("Object y:"&$myObjectPosY)
  523.                                                             outputPrint("Object z:"&$myObjectPosZ)
  524.  
  525.                                                             ;default scale and rotation
  526.  
  527.                                                             $myObjectScale = "1 1 1"
  528.                                                             $myObjectScaleX = 1
  529.                                                             $myObjectScaleY = 1
  530.                                                             $myObjectScaleZ = 1
  531.  
  532.                                                             $myObjectRot = "0 0 0 0"
  533.                                                             $myObjectRotP = 0
  534.                                                             $myObjectRotY = 0
  535.                                                             $myObjectRotR = 0
  536.                                                             $myObjectRotX = 0
  537.  
  538.                                                          EndIf
  539.                                                       EndIf
  540.  
  541.                                                       ;Time to go backwards in the script and make an array system for the blueprint
  542.                                                       ;Guess who's back? Back again. Welp time for the hard part?  Hah, I'm gonna go make a cup of tea
  543.                                                       ;-Slurps tea- Anyway, enough procastination(probably spelt that wrong) time to write dis thing
  544.  
  545.                                                       $meshListLen = UBound($blueprintMeshes)
  546.                                                       $collListLen = UBound($blueprintColls)
  547.  
  548.                                                       outputPrint("")
  549.                                                       outputPrint("Blueprint meshes len: "&$meshListLen)
  550.                                                       ;_ArrayDisplay($blueprintMeshes)
  551.                                                       outputPrint("Blueprint colls len: "&$collListLen)
  552.                                                       ;_ArrayDisplay($blueprintColls)
  553.  
  554.                                                       if $meshListLen > 1 Then
  555.                                                          for $y = 0 To $meshListLen-1 ; the amount of for loops in this script xD
  556.                                                             $MEMeshName = ""
  557.                                                             if $blueprintMeshes[$y] == "" Then
  558.  
  559.                                                             Else
  560.                                                                if StringInStr($blueprintMeshes[$y],";") Then
  561.                                                                   Local $meshExplode = StringSplit($blueprintMeshes[$y],";")
  562.                                                                   if UBound($meshExplode) > 4 Then
  563.                                                                      $MEMeshName = $meshExplode[1]
  564.                                                                      $MEMeshPos = $meshExplode[2]
  565.                                                                      $MEMeshPosX = 0
  566.                                                                      $MEMeshPosY = 0
  567.                                                                      $MEMeshPosZ = 0
  568.  
  569.                                                                      local $posExplode = StringSplit($meshExplode[2]," ")
  570.                                                                      if UBound($posExplode) == 4 Then
  571.                                                                         $MEMeshPosX = Number($posExplode[1])
  572.                                                                         $MEMeshPosY = Number($posExplode[2])
  573.                                                                         $MEMeshPosZ = Number($posExplode[3])
  574.                                                                      EndIf
  575.  
  576.                                                                      $MEMeshScale = $meshExplode[3]
  577.                                                                      $MEMeshScaleX = 1
  578.                                                                      $MEMeshScaleY = 1
  579.                                                                      $MEMeshScaleZ = 1
  580.  
  581.                                                                      local $scaleExplode = StringSplit($meshExplode[3]," ")
  582.                                                                      if UBound($scaleExplode) == 4 Then
  583.                                                                         $MEMeshScaleX = Number($scaleExplode[1])
  584.                                                                         $MEMeshScaleY = Number($scaleExplode[2])
  585.                                                                         $MEMeshScaleZ = Number($scaleExplode[3])
  586.                                                                      EndIf
  587.  
  588.                                                                      $MEMeshRot = $meshExplode[4]
  589.                                                                      $MEMeshRotP = 0
  590.                                                                      $MEMeshRotY = 0
  591.                                                                      $MEMeshRotR = 0
  592.                                                                      $MEMeshRotX = 0
  593.  
  594.                                                                      local $rotExplode = StringSplit($meshExplode[4]," ")
  595.                                                                      if UBound($rotExplode) == 5 Then
  596.                                                                         $MEMeshRotP = Number($rotExplode[1])
  597.                                                                         $MEMeshRotY = Number($rotExplode[2])
  598.                                                                         $MEMeshRotR = Number($rotExplode[3])
  599.                                                                         $MEMeshRotX = Number($rotExplode[4])
  600.                                                                      EndIf
  601.  
  602.                                                                      if UBound($meshExplode) == 6 Then
  603.                                                                         ;insert get mesh blueprint material code here(possible future feature)
  604.                                                                      EndIf
  605.  
  606.                                                                      if $MEMeshName == "" Then
  607.  
  608.                                                                      Else
  609.                                                                         outputPrint("Writing object "&$MEMeshName)
  610.                                                                         FileWriteLine($worldFile,"[Object]")
  611.                                                                         FileWriteLine($worldFile,$MEMeshName)
  612.                                                                         $myObjectPos = $myObjectPosX+$MEMeshPosX&" "&$myObjectPosY+$MEMeshPosY&" "&$myObjectPosZ+$MEMeshPosZ
  613.                                                                         outputPrint("Pos: "&$myObjectPos)
  614.                                                                         FileWriteLine($worldFile,$myObjectPos)
  615.                                                                         $myObjectScale = $MEMeshScaleX*$myObjectScaleX&" "&$MEMeshScaleY*$myObjectScaleY&" "&$MEMeshScaleZ*$myObjectScaleZ
  616.                                                                         outputPrint("Scale: "&$myObjectScale)
  617.                                                                         FileWriteLine($worldFile,$myObjectScale)
  618.                                                                         $myObjectRot = $myObjectRotP+$MEMeshRotP&" "&$myObjectRotY+$MEMeshRotY&" "&$myObjectRotR+$MEMeshRotR&" "&$myObjectRotX+$MEMeshRotX
  619.                                                                         outputPrint("Rot: "&$myObjectRot)
  620.                                                                         FileWriteLine($worldFile,$myObjectRot)
  621.                                                                         outputPrint("")
  622.                                                                      EndIf
  623.                                                                   EndIf
  624.                                                                EndIf
  625.                                                             EndIf
  626.                                                          Next
  627.                                                       EndIf
  628.  
  629.                                                       ;halfway done ^^ now for collisions
  630.  
  631.                                                       if $collListLen > 1 Then
  632.                                                          for $y = 0 To $collListLen-1
  633.                                                             $MECollType = ""
  634.                                                             if $blueprintColls[$y] == "" Then
  635.  
  636.                                                             Else
  637.                                                                if StringInStr($blueprintColls[$y],";") Then
  638.                                                                   Local $meshExplode = StringSplit($blueprintColls[$y],";")
  639.                                                                   if UBound($meshExplode) > 3 Then
  640.                                                                      $MEMeshPosX = 0
  641.                                                                      $MEMeshPosY = 0
  642.                                                                      $MEMeshPosZ = 0
  643.  
  644.                                                                      if $meshExplode[1] == "b" Then
  645.                                                                         $MECollType = "CollBox"
  646.  
  647.                                                                         local $posExplode = StringSplit($meshExplode[2]," ")
  648.                                                                         if UBound($posExplode) == 4 Then
  649.                                                                            $MEMeshPosX = Number($posExplode[1])
  650.                                                                            $MEMeshPosY = Number($posExplode[2])
  651.                                                                            $MEMeshPosZ = Number($posExplode[3])
  652.                                                                         EndIf
  653.  
  654.                                                                         $MEMeshScaleX = 1
  655.                                                                         $MEMeshScaleY = 1
  656.                                                                         $MEMeshScaleZ = 1
  657.  
  658.                                                                         local $scaleExplode = StringSplit($meshExplode[3]," ")
  659.                                                                         if UBound($scaleExplode) == 4 Then
  660.                                                                            $MEMeshScaleX = Number($scaleExplode[1])
  661.                                                                            $MEMeshScaleY = Number($scaleExplode[2])
  662.                                                                            $MEMeshScaleZ = Number($scaleExplode[3])
  663.                                                                         EndIf
  664.  
  665.                                                                         outputPrint("Writing collision "&$MECollType)
  666.                                                                         FileWriteLine($worldFile,"["&$MECollType&"]")
  667.                                                                         $myObjectPos = $myObjectPosX+$MEMeshPosX&" "&$myObjectPosY+$MEMeshPosY&" "&$myObjectPosZ+$MEMeshPosZ
  668.                                                                         outputPrint("Pos: "&$myObjectPos)
  669.                                                                         FileWriteLine($worldFile,$myObjectPos)
  670.                                                                         $myObjectScale = $MEMeshScaleX*$myObjectScaleX&" "&$MEMeshScaleY*$myObjectScaleY&" "&$MEMeshScaleZ*$myObjectScaleZ
  671.                                                                         outputPrint("Scale: "&$myObjectScale)
  672.                                                                         FileWriteLine($worldFile,$myObjectScale)
  673.                                                                         outputPrint("")
  674.  
  675.                                                                      Else
  676.                                                                         if $meshExplode[1] == "s" Then
  677.                                                                            $MECollType = "CollSphere"
  678.  
  679.                                                                            local $posExplode = StringSplit($meshExplode[2]," ")
  680.                                                                            if UBound($posExplode) == 4 Then
  681.                                                                               $MEMeshPosX = Number($posExplode[1])
  682.                                                                               $MEMeshPosY = Number($posExplode[2])
  683.                                                                               $MEMeshPosZ = Number($posExplode[3])
  684.                                                                            EndIf
  685.                                                                            $MEMeshScale = 1
  686.                                                                            $MEMeshScale = $meshExplode[3]
  687.  
  688.                                                                            outputPrint("Writing collision "&$MECollType)
  689.                                                                            FileWriteLine($worldFile,"["&$MECollType&"]")
  690.                                                                            $myObjectPos = $myObjectPosX+$MEMeshPosX&" "&$myObjectPosY+$MEMeshPosY&" "&$myObjectPosZ+$MEMeshPosZ
  691.                                                                            outputPrint("Pos: "&$myObjectPos)
  692.                                                                            FileWriteLine($worldFile,$myObjectPos)
  693.                                                                            $scalemultiplier = ($myObjectScaleX+$myObjectScaleY+$myObjectScaleZ)/3
  694.                                                                            outputPrint("Scale multiplier: "&$scalemultiplier)
  695.                                                                            $myObjectScale = $MEMeshScale*$scalemultiplier
  696.                                                                            outputPrint("Scale: "&$myObjectScale)
  697.                                                                            FileWriteLine($worldFile,$myObjectScale)
  698.                                                                            outputPrint("")
  699.                                                                         EndIf
  700.                                                                      EndIf
  701.                                                                   EndIf
  702.                                                                EndIf
  703.                                                             EndIf
  704.                                                          Next
  705.                                                       EndIf
  706.  
  707.                                                       outputPrint("")
  708.                                                    EndIf
  709.                                                 EndIf
  710.                                              Next
  711.  
  712.                                           EndIf
  713.                                        Else
  714.                                           outputPrint("No objects found")
  715.                                        EndIf
  716.                                     EndIf
  717.  
  718.                                     ;Yay finished the objects converter finally
  719.  
  720.                                     outputPrint("")
  721.                                     outputPrint("Copying other files to temp folder...")
  722.                                     CopyFolderFiles($FHMapFolder,$tempFolder)
  723.                                     outputPrint("")
  724.                                     outputPrint("Copying files to output...")
  725.                                     $outoutFile = $OutputFolder&"\"&$mapDisplayName
  726.  
  727.                                     if FileExists($outoutFile) Then
  728.                                        outputPrint("Removing already existing folder "&$outoutFile)
  729.                                        DirRemove($outoutFile,1)
  730.                                     EndIf
  731.                                     outputPrint("Creating output directory "&$outoutFile)
  732.                                     DirCreate($outoutFile)
  733.  
  734.                                     CopyFolderFiles2($tempFolder,$outoutFile)
  735.  
  736.  
  737.                                     outputPrint("")
  738.                                     outputPrint("")
  739.                                     outputPrint("=================================================")
  740.                                     outputPrint("=================================================")
  741.                                     outputPrint("Done!")
  742.                                     outputPrint("=================================================")
  743.                                     outputPrint("=================================================")
  744.  
  745.                                  Else
  746.                                     error("Error finding map display name",14,False)
  747.                                  EndIf
  748.                               Else
  749.                                  error("Error reading map file",13,False)
  750.                               EndIf
  751.                            Else
  752.                               error("Couldn't read map dimensions",12,False)
  753.                            EndIf
  754.                         Else
  755.                            error("Error reading terrain file",11,False)
  756.  
  757.                         EndIf
  758.  
  759.                      Else
  760.                         error("Failed to create temp folder",10,False)
  761.                      EndIf
  762.                   Else
  763.                      error("Failed to find terrain file",4,False)
  764.                   EndIf
  765.                Else
  766.                    error("Failed to find map folder",5,False)
  767.                EndIf
  768.             Else
  769.                error("Failed to find output folder",6,False)
  770.             EndIf
  771.          Else
  772.             error("Failed to find FH objects folder",7,False)
  773.          EndIf
  774.       Else
  775.          error("Failed to find map file",8,False)
  776.       EndIf
  777.    EndIf
  778.    Sleep(0)
  779. WEnd
  780.  
  781.  
  782. ;==================================================================
  783.  
  784.  
  785. ;----------------------------Functions----------------------------
  786. Func error($errorText,$errorNumber,$fatal)
  787.    ConsoleWrite("--Error--"&@CRLF)
  788.    ConsoleWrite($errorNumber&": "&$errorText&@CRLF)
  789.    ConsoleWrite("---------"&@CRLF)
  790.    if $fatal Then
  791.       outputPrint("Fatal Error("&$errorNumber&"): "&$errorText)
  792.       MsgBox(0,"Fatal Error("&$errorNumber&")",$errorText)
  793.       FileWriteLine($errorLog, "["&@MDAY&"/"&@MON&"/"&@YEAR&" "&@HOUR&":"&@MIN&":"&@SEC&"] Fatal Error("&$errorNumber&"): "&$errorText) ;Notice how the date is in the format day/month/year, yay British errors!
  794.       Exit
  795.    Else
  796.       outputPrint("Error("&$errorNumber&"): "&$errorText)
  797.       MsgBox(0,"Error("&$errorNumber&")",$errorText)
  798.       FileWriteLine($errorLog, "["&@MDAY&"/"&@MON&"/"&@YEAR&" "&@HOUR&":"&@MIN&":"&@SEC&"] Error("&$errorNumber&"): "&$errorText)
  799.    EndIf
  800.    outputPrint("Clearing temp files..")
  801.    ClearFoldersInFolder($tempDir)
  802.    outputPrint("Temp files cleared")
  803. EndFunc
  804.  
  805. Func loadOptions()
  806.    if FileExists($optionsFile) Then
  807.       Local $ops
  808.       _FileReadToArray($optionsFile, $ops)
  809.       outputPrint("")
  810.       outputPrint("-Loading Options-")
  811.       outputPrint("")
  812.       if UBound($ops) == 9 Then
  813.          $mapName = $ops[1]
  814.          outputPrint("Loaded Option 1:"&$ops[1])
  815.          $FHFolder = $ops[2]
  816.          outputPrint("Loaded Option 2:"&$ops[2])
  817.          $FHTerrainsFolder = $ops[3]
  818.          outputPrint("Loaded Option 3:"&$ops[3])
  819.          $FHMapFile = $ops[4]
  820.          outputPrint("Loaded Option 4:"&$ops[4])
  821.          $FHMapFolder = $ops[5]
  822.          outputPrint("Loaded Option 5:"&$ops[5])
  823.          $FHObjectsFolder = $ops[6]
  824.          outputPrint("Loaded Option 6:"&$ops[6])
  825.          $CopyObjectFiles = $ops[7]
  826.          outputPrint("Loaded Option 7:"&$ops[7])
  827.          $OutputFolder = $ops[8]
  828.          outputPrint("Loaded Option 8:"&$ops[8])
  829.          outputPrint("-----------------")
  830.          outputPrint("")
  831.          Return
  832.       EndIf
  833.    EndIf
  834.    $mapName = ""
  835.    $FHFolder = ""
  836.    $FHTerrainsFolder = ""
  837.    $FHMapFile = ""
  838.    $FHMapFolder = ""
  839.    $FHObjectsFolder = ""
  840.    $CopyObjectFiles = ""
  841.    $OutputFolder = ""
  842.    outputPrint("-----------------")
  843.    outputPrint("")
  844. EndFunc
  845.  
  846. Func saveOptions()
  847.    outputPrint("")
  848.    outputPrint("-Saving Options-")
  849.    outputPrint("")
  850.    if FileExists($optionsFile) Then
  851.       outputPrint("-Deleting old options-")
  852.       FileDelete($optionsFile)
  853.    EndIf
  854.    FileWriteLine($optionsFile,$mapName)
  855.    outputPrint("Saved Option 1($mapName):"&$mapName)
  856.    FileWriteLine($optionsFile,$FHFolder)
  857.    outputPrint("Saved Option 2($FHFolder):"&$FHFolder)
  858.    FileWriteLine($optionsFile,$FHTerrainsFolder)
  859.    outputPrint("Saved Option 3($FHTerrainsFolder):"&$FHTerrainsFolder)
  860.    FileWriteLine($optionsFile,$FHMapFile)
  861.    outputPrint("Saved Option 4($FHMapFile):"&$FHMapFile)
  862.    FileWriteLine($optionsFile,$FHMapFolder)
  863.    outputPrint("Saved Option 4($FHMapFolder):"&$FHMapFolder)
  864.    FileWriteLine($optionsFile,$FHObjectsFolder)
  865.    outputPrint("Saved Option 5($FHObjectsFolder):"&$FHObjectsFolder)
  866.    FileWriteLine($optionsFile,$CopyObjectFiles)
  867.    outputPrint("Saved Option 5($CopyObjectFiles):"&$CopyObjectFiles)
  868.    FileWriteLine($optionsFile,$OutputFolder)
  869.    outputPrint("Saved Option 6($OutputFolder):"&$OutputFolder)
  870.    outputPrint("-----------------")
  871.    outputPrint("")
  872. EndFunc
  873.  
  874. Func outputPrint($outtxt)
  875.    FileWriteLine($normalLog,$outtxt)
  876.    GUICtrlSetData($outputBox,StringRight(GUICtrlRead($outputBox)&@CRLF&$outtxt,5000))
  877.    _GUICtrlEdit_Scroll($outputBox, $SB_SCROLLCARET)
  878. EndFunc
  879.  
  880. Func ClearFoldersInFolder($SourceFolder)
  881.     Local $Search
  882.     Local $File
  883.     Local $FileAttributes
  884.     Local $FullFilePath
  885.  
  886.     $Search = FileFindFirstFile($SourceFolder & "\*.*")
  887.  
  888.     While 1
  889.         If $Search = -1 Then
  890.             ExitLoop
  891.         EndIf
  892.  
  893.         $File = FileFindNextFile($Search)
  894.         If @error Then ExitLoop
  895.  
  896.         $FullFilePath = $SourceFolder & "\" & $File
  897.         $FileAttributes = FileGetAttrib($FullFilePath)
  898.  
  899.         If StringInStr($FileAttributes,"D") Then
  900.             DirRemove($FullFilePath,1)
  901.             outputPrint("Deleted folder "&$FullFilePath)
  902.         EndIf
  903.  
  904.     WEnd
  905.  
  906.     FileClose($Search)
  907.  EndFunc
  908.  
  909.  Func ScanFolder($SourceFolder)
  910.    Local $Search
  911.    Local $File
  912.    Local $FileAttributes
  913.    Local $FullFilePath
  914.    Local $scanfolderarray[1]
  915.    $Search = FileFindFirstFile($SourceFolder & "\*.*")
  916.  
  917.    While 1
  918.       If $Search = -1 Then
  919.          ExitLoop
  920.       EndIf
  921.  
  922.         $File = FileFindNextFile($Search)
  923.         If @error Then ExitLoop
  924.  
  925.         $FullFilePath = $SourceFolder & "\" & $File
  926.         $FileAttributes = FileGetAttrib($FullFilePath)
  927.  
  928.          If StringInStr($FileAttributes,"D") Then
  929.  
  930.          Else
  931.             ;if $sExtension == ".cfg" Then
  932.              ;  outputPrint("EXTENSION: "&$sExtension)
  933.             ;Else
  934.                _ArrayInsert($scanfolderarray, 1, $File)
  935.             ;EndIf
  936.          EndIf
  937.  
  938.     WEnd
  939.     FileClose($Search)
  940.     Return $scanfolderarray
  941.  EndFunc
  942.  
  943. Func CopyFolderFiles($OldFolder, $NewFolder)
  944.    Local $files = ScanFolder($OldFolder)
  945.    Local $size = UBound($files)
  946.    If $size > 0 Then
  947.       for $iz = 1 to $size-1
  948.          $f = $NewFolder&"\"&$files[$iz]
  949.          $of = $OldFolder&"\"&$files[$iz]
  950.          Local $sDrive = "", $sDir = "", $sFilename = "", $sExtension = ""
  951.          Local $aPathSplit = _PathSplit($of, $sDrive, $sDir, $sFilename, $sExtension)
  952.          if $sExtension == ".cfg" Then
  953.  
  954.          Else
  955.             If FileExists($f) Then
  956.                outputPrint("Deleting alreadying existing file "&$f)
  957.                FileDelete($f)
  958.             EndIf
  959.             outputPrint("Copying '"&$of&"' to '"&$f&"'")
  960.             FileCopy($of,$f)
  961.          EndIf
  962.       Next
  963.    EndIf
  964. EndFunc
  965.  
  966. Func CopyFolderFiles2($OldFolder, $NewFolder)
  967.    Local $files = ScanFolder($OldFolder)
  968.    Local $size = UBound($files)
  969.    If $size > 0 Then
  970.       for $iz = 1 to $size-1
  971.          $f = $NewFolder&"\"&$files[$iz]
  972.          $of = $OldFolder&"\"&$files[$iz]
  973.          ;Local $sDrive = "", $sDir = "", $sFilename = "", $sExtension = ""
  974.         ; Local $aPathSplit = _PathSplit($of, $sDrive, $sDir, $sFilename, $sExtension)
  975.          ;if $sExtension == ".cfg" Then
  976.  
  977.          ;Else
  978.             If FileExists($f) Then
  979.                outputPrint("Deleting alreadying existing file "&$f)
  980.                FileDelete($f)
  981.             EndIf
  982.             outputPrint("Copying '"&$of&"' to '"&$f&"'")
  983.             FileCopy($of,$f)
  984.         ; EndIf
  985.       Next
  986.    EndIf
  987. EndFunc
  988. ;-----------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement