Alan72104

osu! triangles animation in Autoit

Feb 19th, 2021
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 18.03 KB | None | 0 0
  1. Global Const $width = 960; / 4 * 3
  2. Global Const $height = $width / 16 * 9
  3. Global Const $title = "osu!tris"
  4. Global $g_bPaused = False
  5. Global $hGui
  6. Global Const $bgColorRGB = 0x121543
  7. Global Const $bgColorARGB = 0xFF000000 + $bgColorRGB
  8. Global $hGraphics
  9. Global $frameBuffer
  10. Global $hFrameBuffer
  11. Global $osuLogo
  12. Global $hBrushTris[10]
  13. Global $hBrushRed, $hBrushGreen, $hBrushParticle
  14. Global $deleteCount = 0
  15. Global Const $maxTriAmount = 100
  16. Global Enum $TRIX, $TRIY, $TRISCALE, $TRISHADE
  17. Global $tris[$maxTriAmount + 1][4] = [ _
  18.                                      [2    ,    "",   "",""], _
  19.                                      [115.0, 250.0, 52.7, 2], _
  20.                                      [137.0, 367.0, 88.9, 7]]  ; Pure placeholder
  21. Global $triVelocityMultiplier = 3.9
  22. Global Const $triVelocityMultiplierMin = 1
  23. Global $hTimerBeat, $hTimerFrame, $hTimerEffet
  24. Global $smoothedFrameTime = 0.0
  25. Global Const $frameTimeSmoothingRatio = 0.3
  26. Global $effectLast, $effextOffset
  27. Global $effectCycleTime = 375, $effectPixels = 5
  28. Global $effectZoomInRatio = 4/5  ; How much of the cycle time is for the zoom-in part
  29. Global $effectMillisPerPixel = $effectCycleTime * $effectZoomInRatio / $effectPixels
  30. Global Const $applyEffectAndLogo = False
  31. Global Const $osuWhiteBgEnable = False
  32. Global $hAudioStream
  33. Global $channelDataBuffer
  34. Global $currentAudioLevel = 0
  35. Global $channelLevel
  36. Global $beat = False
  37. Global Const $useSystemSoundLevel = True
  38. Global $audioLevelIndex = 0
  39. Global Const $audioLevelMaxIndex = 15
  40. Global $aAudioLevel[$audioLevelMaxIndex]
  41. Global $audioLevelAverage = 0
  42. Global $hDllCallback
  43. Global $wndprocPreviousValue
  44. Global Const $maxParticleAmount = 100
  45. Global Const $maxParticleLife = 125
  46. Global Enum $PARTICLEX, $PARTICLEY, $PARTICLEVX, $PARTICLEVY, $PARTICLELIFE
  47. Global $particles[$maxParticleAmount + 1][5] = [ _
  48.                                                [2,  "",  "",  "", ""], _
  49.                                                [15, 25, 0.1, 0.3,  5], _
  50.                                                [81, 14, 0.2, 0.1,  5]]  ; Pure placeholder again
  51. Global $_LD_Debug = True
  52.  
  53. #include <GDIPlus.au3>
  54. #include <GUIConstantsEx.au3>
  55. #include <WinAPISys.au3>
  56. #include <WindowsConstants.au3>
  57. ;#include "..\LibDebug.au3"
  58. ;#include "osu!tris.vars.au3"
  59. #include "Bass.au3"
  60.  
  61.  
  62. #include <StringConstants.au3>
  63.  
  64. ; HotKeySet("{F6}", "TogglePause")  ; F6 - Pause the whole thing
  65. HotKeySet("{F7}", "Terminate")    ; F7 - Exit
  66. ; HotKeySet("{F8}", "plus")         ; F8 - Increase triangle speed
  67. ; HotKeySet("^{F8}", "subt")        ; Ctrl+F8 - Decrease triangle speed
  68. ; HotKeySet("{F9}", "plus2")        ; F9 - Increase effect scale - if effect is applied
  69. ; HotKeySet("^{F9}", "subt2")       ; Ctrl+F9 - Decrease effect scale - if effect is applied
  70. ; HotKeySet("{F10}", "plus3")       ; F10 - Increase effect speed - if effect is applied
  71. ; HotKeySet("^{F10}", "subt3")      ; Ctrl+F10 - Decrease effect speed - if effect is applied
  72.  
  73. ; AdlibRegister("UpdateTitle", 300)
  74. SRandom(@MSEC)
  75.  
  76. Func plus()
  77.     $triVelocityMultiplier += 1
  78. EndFunc
  79. Func subt()
  80.     $triVelocityMultiplier -= 1
  81. EndFunc
  82. Func plus2()
  83.     $effectPixels += 1
  84. EndFunc
  85. Func subt2()
  86.     $effectPixels -= 1
  87. EndFunc
  88. Func plus3()
  89.     $effectCycleTime += 5
  90. EndFunc
  91. Func subt3()
  92.     $effectCycleTime -= 5
  93. EndFunc
  94.  
  95. Func GenerateTriangle()
  96.     $tris[$tris[0][0] + 1][$TRIX] = Random(-30, $width + 30, 1)
  97.     $tris[$tris[0][0] + 1][$TRIY] = Random($height + 125, $height + 150, 1)
  98.     $tris[$tris[0][0] + 1][$TRISCALE] = Random(50, 150)
  99.     ; $tris[$tris[0][0] + 1][$TRISCALE] = Random($width / 10, $width / 4)
  100.     $tris[$tris[0][0] + 1][$TRISHADE] = Random(0, 9, 1)
  101.     $tris[0][0] += 1
  102. EndFunc
  103.  
  104. Func RemoveTriangle($ele)
  105.     If $ele = $maxTriAmount Then
  106.         ; Don't set things back to 0 due to performance reason
  107.     Else
  108.         For $i = $ele To $tris[0][0] - 1
  109.             $tris[$i][$TRIX] = $tris[$i + 1][$TRIX]
  110.             $tris[$i][$TRIY] = $tris[$i + 1][$TRIY]
  111.             $tris[$i][$TRISCALE] = $tris[$i + 1][$TRISCALE]
  112.             $tris[$i][$TRISHADE] = $tris[$i + 1][$TRISHADE]
  113.             ; Don't set things back to 0 due to perfoxrmance reason
  114.         Next
  115.     EndIf
  116.     $tris[0][0] -= 1
  117. EndFunc
  118.  
  119. Func GenerateParticle()
  120.     $particles[$particles[0][0] + 1][$PARTICLEX] = Random(40, $width - 40, 1)
  121.     $particles[$particles[0][0] + 1][$PARTICLEY] = 0
  122.     $particles[$particles[0][0] + 1][$PARTICLEVX] = Random(-0.5, 0.5)
  123.     $particles[$particles[0][0] + 1][$PARTICLEVY] = Random(0.5, 1)
  124.     $particles[$particles[0][0] + 1][$PARTICLELIFE] = Random(0, 50, 1)
  125.     $particles[0][0] += 1
  126. EndFunc
  127.  
  128. Func RemoveParticle($ele)
  129.     If $ele = $maxParticleAmount Then
  130.     Else
  131.         For $i = $ele To $particles[0][0] - 1
  132.             $particles[$i][$PARTICLEX] = $particles[$i + 1][$PARTICLEX]
  133.             $particles[$i][$PARTICLEY] = $particles[$i + 1][$PARTICLEY]
  134.             $particles[$i][$PARTICLEVX] = $particles[$i + 1][$PARTICLEVX]
  135.             $particles[$i][$PARTICLEVY] = $particles[$i + 1][$PARTICLEVY]
  136.             $particles[$i][$PARTICLELIFE] = $particles[$i + 1][$PARTICLELIFE]
  137.         Next
  138.     EndIf
  139.     $particles[0][0] -= 1
  140. EndFunc
  141.  
  142. Global $audioLevelsum
  143. Func AudioLevelAdd(ByRef $value)
  144.     $aAudioLevel[$audioLevelIndex] = $value  ; Add the value into array
  145.     $audioLevelIndex += 1  ; Current index plus 1
  146.     If $audioLevelIndex = $audioLevelMaxIndex Then  ; Return to 0 when cur. index reach max
  147.         $audioLevelIndex = 0
  148.     EndIf
  149.     $audioLevelsum = 0  ; Reset sum
  150.     For $i = 0 To $audioLevelMaxIndex - 1 ; Add each array element together
  151.         $audioLevelsum += $aAudioLevel[$i]
  152.     Next
  153.     $audioLevelAverage = $audioLevelsum / $audioLevelMaxIndex  ; Set the average
  154. EndFunc
  155.  
  156. ; Global $hTimerUpdate
  157. ; Global $nTimerUpdate = 0
  158. Func Update()
  159.     ; $hTimerUpdate = TimerInit()
  160.     $channelLevel = _Bass_ChannelGetLevel($hAudioStream)  ; 32 bits returned, high part is left channel, low part is right channel
  161.     $currentAudioLevel = (BitShift($channelLevel, 16) + BitAND($channelLevel, 0xFFFF)) / 2
  162.     AudioLevelAdd($currentAudioLevel)
  163.     If $currentAudioLevel > $audioLevelAverage + 500 And TimerDiff($hTimerBeat) > 100 Then
  164.         $beat = True
  165.         $triVelocityMultiplier += 15
  166.         ; $triVelocityMultiplier += $currentAudioLevel / 32767 * 35
  167.         $hTimerBeat = TimerInit()
  168.     Else
  169.         $beat = False
  170.     EndIf
  171.     $deleteCount = 0
  172.     For $i = 1 To $tris[0][0]  ; Delete triangles that exceed the range
  173.         If $tris[$i - $deleteCount][$TRIY] < 0 Then
  174.             RemoveTriangle($i - $deleteCount)
  175.             $deleteCount += 1
  176.         EndIf
  177.     Next
  178.     While $tris[0][0] < $maxTriAmount  ; Generate triangles until count is reached
  179.         GenerateTriangle()
  180.     WEnd
  181.     If $triVelocityMultiplier > $triVelocityMultiplierMin Then
  182.         $triVelocityMultiplier -= ($triVelocityMultiplier - $triVelocityMultiplierMin) / 3
  183.     EndIf
  184.     For $i = 1 To $tris[0][0]  ; Apply movement
  185.         $tris[$i][$TRIY] +=  -(($tris[$i][$TRISCALE] / 50 - 1) * (0.5 / 2) + 0.5) * $triVelocityMultiplier
  186.     Next
  187.     $deleteCount = 0
  188.     For $i = 1 To $particles[0][0]  ; Delete particles that reach it's life
  189.         If $particles[$i][$PARTICLELIFE] > $maxParticleLife Then
  190.             RemoveParticle($i - $deleteCount)
  191.             $deleteCount += 1
  192.         EndIf
  193.     Next
  194.     While $particles[0][0] < $maxParticleAmount
  195.         GenerateParticle()
  196.     WEnd
  197.     For $i = 1 To $particles[0][0]
  198.         $particles[$i][$PARTICLEX] += 3 * $particles[$i][$PARTICLEVX]
  199.         $particles[$i][$PARTICLEY] += 3 * $particles[$i][$PARTICLEVY]
  200.         $particles[$i][$PARTICLELIFE] += 1
  201.     Next
  202.     ; $nTimerUpdate = TimerDiff($hTimerUpdate)
  203. EndFunc
  204.  
  205. ; Global $hTimerDraw
  206. ; Global $nTimerDraw = 0
  207. Func Draw()
  208.     Local Static $triBuffer[4][2] = [[3, ""], [-50.0, 150.0], [300.0, 500.0], [550.0, 150.0]]
  209.     ; $hTimerDraw = TimerInit()
  210.     _GDIPlus_GraphicsClear($hFrameBuffer, $bgColorARGB)
  211.     ; Draw the triangles
  212.     For $i = 1 To $tris[0][0]
  213.              ; 3
  214.             ; / \
  215.            ; /   \
  216.         ; 1 ------- 2
  217.         $triBuffer[1][0] = $tris[$i][$TRIX]
  218.         $triBuffer[1][1] = $tris[$i][$TRIY]
  219.         $triBuffer[2][0] = $tris[$i][$TRIX] + $tris[$i][$TRISCALE]
  220.         $triBuffer[2][1] = $tris[$i][$TRIY]
  221.         $triBuffer[3][0] = $tris[$i][$TRIX] + $tris[$i][$TRISCALE] / 2
  222.         $triBuffer[3][1] = $tris[$i][$TRIY] - $tris[$i][$TRISCALE]
  223.         _GDIPlus_GraphicsFillPolygon($hFrameBuffer, $triBuffer, $hBrushTris[$tris[$i][$TRISHADE]])
  224.     Next
  225.     ; Draw the particles
  226.     For $i = 1 to $particles[0][0]
  227.         _GDIPlus_GraphicsFillEllipse($hFrameBuffer, $particles[$i][$PARTICLEX], $height - $particles[$i][$PARTICLEY], 5, 5, $hBrushParticle)
  228.     Next
  229.     ; Draw the osu! text and circle
  230.     If $applyEffectAndLogo Then
  231.         _GDIPlus_GraphicsDrawImageRect($hFrameBuffer, $osuLogo, $effectPixels, $effectPixels, $width - 2 * $effectPixels, $height - 2 * $effectPixels)
  232.     EndIf
  233.     ; $nTimerDraw = TimerDiff($hTimerDraw)
  234.     ; Current audio level and average value
  235.     _GDIPlus_GraphicsFillRect($hFrameBuffer, 5, $height - 5 - 5, _
  236.                                             $currentAudioLevel / 32768 * 50, 5, $hBrushRed)
  237.     _GDIPlus_GraphicsFillRect($hFrameBuffer, 5 + $audioLevelAverage / 32768 * 50, $height - 5 - 5, _
  238.                                             2, 5, $hBrushGreen)
  239.     ; Current FPS
  240.     _GDIPlus_GraphicsDrawString($hFrameBuffer, "FPS: " & Round(1000 / $smoothedFrameTime, 1), 150, $height - 15)
  241.     ; _GDIPlus_GraphicsDrawString($hFrameBuffer, "VelocityMultiplier: " & Round($triVelocityMultiplier, 1), 300, $height - 15)
  242. EndFunc
  243.  
  244. ; Why do we want/need frame buffer?
  245. ; A frame buffer holds the "unfinished" frame data we're still drawing onto,
  246. ; While keeping the actual screen clean/untouched from different drawing steps
  247.  
  248. ; Global $hTimerSwapbuffer
  249. ; Global $nTimerSwapbuffer = 0
  250. Func FrameBufferTransfer()
  251.     ; $hTimerSwapbuffer = TimerInit()
  252.     ; Draw the framebuffer onto the screen,
  253.     ; Also apply the time based zoom-in zoom-out effect
  254.     If $applyEffectAndLogo Then
  255.         $effectLast = TimerDiff($hTimerEffect)
  256.         $effectElapsed = Mod($effectLast, $effectCycleTime)  ; Remove repeating parts of the elapsed time
  257.         If $effectElapsed <= $effectCycleTime * $effectZoomInRatio Then  ; Zoom in part
  258.             $effectOffset = -1 * $effectElapsed / $effectMillisPerPixel
  259.         Else  ; Zoom out part
  260.             $effectOffset = -$effectPixels + ($effectElapsed - $effectCycleTime * $effectZoomInRatio) / $effectMillisPerPixel
  261.         EndIf
  262.         _GDIPlus_GraphicsDrawImageRect($hGraphics, $frameBuffer, 0 + $effectOffset, 0 + $effectOffset, _
  263.                                                                 $width + 2 * Abs($effectOffset), $height + 2 * Abs($effectOffset))
  264.         If $effectLast > $effectCycleTime Then
  265.         $hTimerEffect = TimerInit()
  266.         EndIf
  267.     Else
  268.         _GDIPlus_GraphicsDrawImage($hGraphics, $frameBuffer, 0, 0)
  269.     EndIf
  270.     ; $nTimerSwapbuffer = TimerDiff($hTimerSwapbuffer)
  271. EndFunc
  272.  
  273. Global $nTimerFrame = 0
  274. Func Main()
  275.     _DebugOn()
  276.     _GDIPlus_Startup()  ; Start GDI library
  277.     $hGui = GUICreate($title, $width, $height, Default, Default, Default)  ; Create GUI
  278.     ; $hGui = GUICreate($title, $width, $height, Default, Default, Default, $WS_EX_TOPMOST)
  279.     ; $hGui = GUICreate($title, $width, $height, Default, Default, Default, $WS_POPUP)
  280.     $hGraphics = _GDIPlus_GraphicsCreateFromHWND($hGui)
  281.     CreateBrushes()
  282.     GUISetBkColor($bgColorRGB, $hGui)
  283.     $frameBuffer = _GDIPlus_BitmapCreateFromGraphics($width, $height, $hGraphics)  ; Create framebuffer bitmap
  284.     $hFrameBuffer = _GDIPlus_ImageGetGraphicsContext($frameBuffer)  ; Get the handle to the context of the bitmap in order to pass it to other drawing funcs
  285.     If $osuWhiteBgEnable Then ; Create logo bitmap from the file
  286.         $osuLogo = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\osu!logo with bg.png")
  287.     Else
  288.         $osuLogo = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\osu!logo.png")
  289.     EndIf
  290.     ; GUIRegisterMsg($WM_SIZE, "WM_SIZE")  ; TODO: Dynamic resizing
  291.     _BASS_Startup(@Scriptdir & "\bass.dll")  ; Start bass library
  292.     _Bass_Init(0)
  293.     If $useSystemSoundLevel Then
  294.         _BASS_RecordInit(-1)
  295.         $hAudioStream = _BASS_RecordStart(48000, 2, 0, 0)
  296.         _BASS_ChannelPlay($hAudioStream, 0)
  297.     Else
  298.         LoadAudioAndPlay(@Scriptdir & "\music.mp3")
  299.         _BASS_ChannelSetPosition($hAudioStream, _BASS_ChannelGetLength($hAudioStream, $BASS_POS_BYTE) / 100 * 80, $BASS_POS_BYTE)
  300.     EndIf
  301.     $hDllCallback = DllCallbackRegister('WndProc', 'ptr', 'hwnd;uint;wparam;lparam')
  302.     $pDllCallback = DllCallbackGetPtr($hDllCallback)
  303.     $wndprocPreviousValue = _WinAPI_SetWindowLong($hGui, $GWL_WNDPROC, $pDllCallback)
  304.     _WinAPI_DragAcceptFiles($hGui, True)  ; Enable drag and drop for the gui
  305.     GUISetState(@SW_SHOW)
  306.     While 1
  307.         $hTimerFrame = TimerInit()
  308.         Update()
  309.         Draw()
  310.         FrameBufferTransfer()
  311.         $nTimerFrame = TimerDiff($hTimerFrame)
  312.         $smoothedFrameTime = ($smoothedFrameTime * (1 - $frameTimeSmoothingRatio)) + $nTimerFrame * $frameTimeSmoothingRatio
  313.         Switch GUIGetMsg()
  314.             Case $GUI_EVENT_CLOSE
  315.                 Terminate()
  316.         EndSwitch
  317.     WEnd
  318. EndFunc
  319.  
  320. Main()
  321.  
  322. Func LoadAudioAndPlay($filePath)
  323.     If _BASS_ChannelIsActive($hAudioStream) Then
  324.         _BASS_RecordFree()
  325.         _BASS_ChannelStop($hAudioStream)
  326.         _BASS_StreamFree($hAudioStream)
  327.     EndIf
  328.     $hAudioStream = _BASS_StreamCreateFile(0, $filePath, 0, 0, $BASS_SAMPLE_LOOP)
  329.     _Bass_ChannelPlay($hAudioStream, 0)
  330. EndFunc
  331.  
  332. ; WindowProc callback function that processes messages sent to the window
  333. Func WndProc($hWnd, $idMsg, $wParam, $lParam)
  334.     Switch $idMsg
  335.         Case $WM_DROPFILES
  336.             Local $fileList = _WinAPI_DragQueryFileEx($wParam, 1)  ; The first element is file amount
  337.             ; Only accept .mp3 file here (case insensitive)
  338.             ; Can also use "xxx" = "xxx"
  339.             If StringCompare(StringRight($fileList[1], 4), ".mp3") = 0 Then
  340.                 LoadAudioAndPlay($fileList[1])
  341.             EndIf
  342.             _WinAPI_DragFinish($wParam)
  343.             Return 0
  344.     EndSwitch
  345.     Return _WinAPI_CallWindowProc($wndprocPreviousValue, $hWnd, $idMsg, $wParam, $lParam)
  346. EndFunc
  347.  
  348. Func CreateBrushes()
  349.     $hBrushRed = _GDIPlus_BrushCreateSolid(0xFFFF0000)
  350.     $hBrushGreen = _GDIPlus_BrushCreateSolid(0xFF00FF00)
  351.     #cs normal tinting and shading
  352.     Local $shadedColor
  353.     Local $r = BitAND(BitShift($bgColorRGB, 16), 0xFF)
  354.     Local $g = BitAND(BitShift($bgColorRGB, 8), 0xFF)
  355.     Local $b = BitAND($bgColorRGB, 0xFF)
  356.     For $i = 0 To 9  ; Create 2 shades + og color + 7 tints of brushes
  357.         $shadedColor = Round($r + (255 - $r) * ($i - 2) / 30) * 256 * 256 + _
  358.                        Round($g + (255 - $g) * ($i - 2) / 30) * 256 + _
  359.                        Round($b + (255 - $b) * ($i - 2) / 30)
  360.         $hBrushTris[$i] = _GDIPlus_BrushCreateSolid(0xFF000000 + $shadedColor)
  361.     Next
  362.     #ce
  363.     ; Gradient colors
  364.     Local $shadedColor
  365.     Local $ogR = BitAND(BitShift($bgColorRGB, 16), 0xFF)
  366.     Local $ogG = BitAND(BitShift($bgColorRGB, 8), 0xFF)
  367.     Local $ogB = BitAND($bgColorRGB, 0xFF)
  368.     Local $toR = 0x39
  369.     Local $toG = 0x4D
  370.     Local $toB = 0xDE
  371.     For $i = 0 To 9
  372.         $shadedColor = Round($ogR + ($toR - $ogR) * $i / 10) * 256 * 256 + _
  373.                        Round($ogG + ($toG - $ogG) * $i / 10) * 256 + _
  374.                        Round($ogB + ($toB - $ogB) * $i / 10)
  375.         $hBrushTris[$i] = _GDIPlus_BrushCreateSolid(0xFF000000 + $shadedColor)
  376.     Next
  377.     $hBrushParticle = _GDIPlus_BrushCreateSolid(0x40FF6D1F)
  378. EndFunc
  379.  
  380. Func UpdateTitle()
  381.     ; WinSetTitle($hGui, "", $title & " | FPS: " & Round(1000 / $smoothedFrameTime, 1) & _
  382.                                     ; " | $triVmul: " & $triVelocityMultiplier)
  383.     cv(1, 'smoothedFrameTime', 'nTimerUpdate', 'nTimerDraw', 'nTimerSwapbuffer')
  384. EndFunc
  385.  
  386. Func GdiPlusClose()
  387.     _GDIPlus_BrushDispose($hBrushRed)
  388.     For $i = 0 To 9
  389.         _GDIPlus_BrushDispose($hBrushTris[$i])
  390.     Next
  391.     _GDIPlus_BrushDispose($hBrushParticle)
  392.     _GDIPlus_BitmapDispose($frameBuffer)
  393.     _GDIPlus_BitmapDispose($osuLogo)
  394.     _GDIPlus_GraphicsDispose($hGraphics)
  395.     _GDIPlus_Shutdown()
  396. EndFunc
  397.  
  398. Func Terminate()
  399.     _BASS_RecordFree()
  400.     _Bass_Free()
  401.     GdiPlusClose()
  402.     _WinAPI_SetWindowLong($hGui, $GWL_WNDPROC, $wndprocPreviousValue)
  403.     DllCallbackFree($hDllCallback)
  404.     GUIDelete($hGui)
  405.     Exit 0
  406. EndFunc
  407.  
  408. Func TogglePause()
  409.     $g_bPaused = Not $g_bPaused
  410.     While $g_bPaused
  411.         Sleep(500)
  412.         ToolTip('Script is "Paused"', @desktopWidth / 2, @desktopHeight / 2, Default, Default, $TIP_CENTER)
  413.     WEnd
  414.     ToolTip("")
  415. EndFunc
  416.  
  417.  
  418.  
  419. Func _DebugOff()
  420.     $_LD_Debug = False
  421. EndFunc
  422.  
  423. Func _DebugOn()
  424.     $_LD_Debug = True
  425. EndFunc
  426.  
  427. ; Consoleout
  428. ; Automatically replaces $ to variables given
  429. ; Escape $ using $$
  430. Func c($s = "", $nl = True, $v1 = 0x0, $v2 = 0x0, $v3 = 0x0, _
  431.                             $v4 = 0x0, $v5 = 0x0, $v6 = 0x0, _
  432.                             $v7 = 0x0, $v8 = 0x0, $v9 = 0x0, $v10 = 0x0)
  433.     If Not $_LD_Debug Then
  434.         Return
  435.     EndIf
  436.     If @NumParams > 2 Then
  437.         $s = StringReplace($s, "$$", "@PH@")
  438.         $s = StringReplace($s, "$", "@PH2@")
  439.         For $i = 1 To @NumParams - 2
  440.             $s = StringReplace($s, "@PH2@", Eval("v" & $i), 1)
  441.             If @extended = 0 Then ExitLoop
  442.         Next
  443.         $s = StringReplace($s, "@PH@", "$")
  444.     EndIf
  445.     If $nl Then
  446.         $s &= @CRLF
  447.     EndIf
  448.     ConsoleWrite($s)
  449.     If @NumParams = 1 Then
  450.         Return $s
  451.     EndIf
  452. EndFunc
  453.  
  454. ; Insert variable
  455. ; Returns a string with all given variables inserted into
  456. Func iv($s = "", $v1 = 0x0, $v2 = 0x0, $v3 = 0x0, _
  457.                 $v4 = 0x0, $v5 = 0x0, $v6 = 0x0, _
  458.                 $v7 = 0x0, $v8 = 0x0, $v9 = 0x0, $v10 = 0x0)
  459.     If @NumParams > 1 Then
  460.         $s = StringReplace($s, "$$", "@PH@")
  461.         $s = StringReplace($s, "$", "@PH2@")
  462.         For $i = 1 To @NumParams - 1
  463.             $s = StringReplace($s, "@PH2@", Eval("v" & $i), 1)
  464.             If @extended = 0 Then ExitLoop
  465.         Next
  466.         $s = StringReplace($s, "@PH@", "$")
  467.     EndIf
  468.     Return $s
  469. EndFunc
  470.  
  471. ; Consoleout Line
  472. Func cl()
  473.     If Not $_LD_Debug Then
  474.         Return
  475.     EndIf
  476.     ConsoleWrite(@CRLF)
  477. EndFunc
  478.  
  479. ; Consoleout Variable
  480. ; Only accepts the name of variable without the $ as string
  481. Func cv($nl = True, $v1 = 0x0, $v2 = 0x0, $v3 = 0x0, $v4 = 0x0, $v5 = 0x0, _
  482.                         $v6 = 0x0, $v7 = 0x0, $v8 = 0x0, $v9 = 0x0, $v10 = 0x0)
  483.     If Not $_LD_Debug Then
  484.         Return
  485.     EndIf
  486.     Local $s = ""
  487.     For $i = 1 To @NumParams - 1
  488.         $s &= "$" & Eval("v" & $i) & " = " & Eval(Eval("v" & $i))
  489.         If $i < @NumParams - 1 Then
  490.             $s &= " | "
  491.         EndIf
  492.     Next
  493.     If $nl Then
  494.         $s &= @CRLF
  495.     EndIf
  496.     ConsoleWrite($s)
  497. EndFunc
  498.  
  499. ; Consoleout Array
  500. Func ca($a = [], $nl = True)
  501.     Local $s = "["
  502.     Switch UBound($a, 0)
  503.         Case 1
  504.             For $i = 0 To UBound($a) - 1
  505.                 If IsString($a[$i]) Then
  506.                     $s &= '"'
  507.                 EndIf
  508.                 $s &= $a[$i]
  509.                 If IsString($a[$i]) Then
  510.                     $s &= '"'
  511.                 EndIf
  512.                 If $i < UBound($a) - 1 Then
  513.                     $s &= ", "
  514.                 EndIf
  515.             Next
  516.         Case 2
  517.             For $i = 0 To UBound($a, 1) - 1
  518.                 $s &= "["
  519.                 For $j = 0 To UBound($a, 2) - 1
  520.                     If IsString($a[$i]) Then
  521.                         $s &= '"'
  522.                     EndIf
  523.                     $s &= $a[$i][$j]
  524.                     If IsString($a[$i]) Then
  525.                         $s &= '"'
  526.                     EndIf
  527.                     If $j < UBound($a, 2) - 1 Then
  528.                         $s &= ", "
  529.                     EndIf
  530.                 Next
  531.                 $s &= "]"
  532.                 If $i < UBound($a, 1) -1 Then
  533.                     $s &= ", "
  534.                 EndIf
  535.             Next
  536.     EndSwitch
  537.     $s &= "]"
  538.     If $nl Then
  539.         $s &= @CRLF
  540.     EndIf
  541.     ConsoleWrite($s)
  542. EndFunc
  543.  
  544. ; Consoleout Error
  545. Func ce($nl = True)
  546.     $nl ? ConsoleWrite(@ERROR & @CRLF) : ConsoleWrite(@ERROR)
  547. EndFunc
Add Comment
Please, Sign In to add comment