diff --git a/bnowakow/old versions/3 GT7-AHK/GT7-AHKv1.00.12_test/GT7AHK.AHK b/bnowakow/old versions/3 GT7-AHK/GT7-AHKv1.00.12_test/GT7AHK.AHK new file mode 100644 index 0000000..34feb4e --- /dev/null +++ b/bnowakow/old versions/3 GT7-AHK/GT7-AHKv1.00.12_test/GT7AHK.AHK @@ -0,0 +1,493 @@ +#NoEnv +#MaxHotkeysPerInterval 99000000 +#HotkeyInterval 99000000 +#KeyHistory 0 +#Include Lib\Gdip.ahk +#Include Lib\AHK-ViGEm-Bus.ahk +#Include Lib\__utility__.ahk +#Include Lib\__controller_functions__.ahk +#Include Mod\Mods.ahk +#Include Race.ahk +#Include Menu.ahk + +hModule := DllCall("LoadLibrary", "Str", A_LineFile "\..\Lib\SuperSleep.dll", "Ptr") +SuperSleep := DllCall("GetProcAddress", "Ptr", DllCall("GetModuleHandle", "Str", A_LineFile "\..\Lib\SuperSleep.dll", "Ptr"), "AStr", "super_sleep", "Ptr") + +ListLines Off +Process, Priority, , A +SetBatchLines, -1 +SetKeyDelay, -1, -1 +SetMouseDelay, -1 +SetDefaultMouseSpeed, 0 +SendMode Input ; Recommended for new scripts due to its superior speed and reliability. + +SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory. +DetectHiddenWindows, On +#Persistent + +; --------- Constants +; Time at turn in seconds and Stablizing control +Global t := 210000 +Global debug_mode := 0 +Global remote_play_offsetY := 0 +Global MenuSelection := 0 +race_start_delay := 0 + +MenuDirect := "Right" +Menu_loops := 6 +menu_s := 1 +Global color_check1 := 0xBBE044 +color_check2 := 0xBBE044 +color_2_delay := 400 + +Global box_size := 2 +Global tolerance := 20 + +; resolution parameters and pixel search locations +ps_win_width := 640 +ps_win_height := 360 +Global pix1x := 458 +Global pix1y := 114 +Global pix2x := 607 +Global pix2y := 319 + +bm_delay := 100 +box_size := 2 + +Global ps_load_time1 := 12000 +Global ps_load_time2 := 6000 +Global ps_load_time3 := 8400 +Global SysCheck := 1 + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; Variable Save Settings ; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +; Race selection from dropdown list +IniRead, RaceChoice, config.ini, Race, RaceChoice +; Console Selection in radio group +loop, 3{ + IniRead, SysCheck%A_Index%, config.ini, Vars, SysCheck%A_Index%, 0 + + if (SysCheck%A_Index% = 1){ + + SysCheck = %A_Index% + } +} +gosub, PSystem +; Menu color Checks +IniRead, color_check1, config.ini, Vars, color_check1, 0xBBE044 +IniRead, color_check2, config.ini, Vars, color_check2, 0xBBE044 +IniRead, race_start_delay, config.ini, Vars, race_start_delay, 0 +IniRead, debug_mode, config.ini, Vars, debug_mode, 0 +IniRead, color_2_delay, config.ini, Vars, color_2_delay, 300 + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; Actual Script Starts Here ; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; Create a new controller controller +Global controller := new ViGEmDS4() +controller.SubscribeFeedback(Func("OnFeedback")) + +OnFeedback(largeMotor, smallMotor, lightbarColor){ + ;OutputDebug % "AHK| Feedback received - LargeMotor: " largeMotor ", SmallMotor: " smallMotor ", LightBarColor: " lightbarColor +} + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; GUI Setups ; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +guicolor1:="000000" ; border +guicolor2:="ffffff" ; Title +guicolor3:="c282a36" ; body background +guicolor4:="c6272a4" ; control color +guicolor5:="ce8dfe3" ; body text + +; ---------- Gui 1 Setup ------------- +; Starting Gui +; +; ----------------------------------- + +Menu, Tray, Icon, Src\gt.ico +Menu, Tray, Standard + +Gui, -MaximizeBox +Gui, 2: -MaximizeBox +Gui, 2: -MinimizeBox +Gui, Color, c282a36, c6272a4 +Gui, Font, Q5 %guicolor4% s8 w550 +Gui, Add, Button, x15 y10 w70 default, Start +Gui, Add, Button, x15 y40 w70 default gVariableWindow, Variables + +Gui, Add, Button, x110 y10 w75 default gModWindow, Mods +Gui, Add, DropDownList, w50 Choose1 vMenuDirect, Right|Left +Gui, Font, Q5 %guicolor3% s8 w550 Bold +Gui, Add, Edit, vMenu_loops w20 x165 y39, 6 + +Gui, Font, ce8dfe3 s9 w550 Bold +Gui, Add, Radio, Group x15 y75 altsubmit Checked%SysCheck1% gPSystem vSysCheck, PS5 +Gui, Add, Radio, x70 y75 altsubmit Checked%SysCheck2% gPSystem, PS4 +Gui, Add, Radio, x125 y75 altsubmit Checked%SysCheck3% gPSystem, PS4 Pro + + +Gui, Font, Q5 %guicolor4% s8 w550 +Gui, Add, Button, x15 y100 w70 default gReset, Reset +Gui, Add, Button, x110 y100 w75 default gMouseColor, Color Picker +Gui, Font, ce8dfe3 s9 w550 Bold +loop, Files, % A_ScriptDir "\Races\*.ahk*" +{ + SplitPath, A_LoopFileName,,,, FileName + List .= FileName "|" +} +List := RTrim(List, "|") +List := StrReplace(List, RaceChoice "|", RaceChoice "||",, 1) ; make first item default + +Gui, Font, Q5 %guicolor5% s8 w550 Bold +Gui, Add, Text, x10 y135, Race : +Gui, Add, DropDownList, x65 y130 w120 gSaveRace vRaceChoice, % List +Gui, Font, Q5 %guicolor4% s8 w550 +Gui, Add, Button, default gSettingsSheet, Settings / Tune +Gui, Show, w220, GT7 AFK + +;--------- Gui 2 Setup -------------- +; Variables Gui +; +; ----------------------------------- +Gui, 2: Color, c535770, c6272a4 +Gui, 2: Font, c11f s9 + +Gui, 2: Font, Q5 %guicolor5% s8 w550 Bold +Gui, 2: Add, Text,, Turn Length (time miliseconds) +Gui, 2: Add, Edit, w70 vA, %t% + +Gui, 2: Add, Text,, Race Start Delay +Gui, 2: Add, Edit, w40 vB, %race_start_delay% + +Gui, 2: Add, Text,, Color Check 1 +Gui, 2: Font, Q5 c%color_check1% s8 w550 Bold +Gui, 2: Add, Edit, vC, %color_check1% + +Gui, 2: Font, Q5 %guicolor5% s8 w550 Bold +Gui, 2: Add, Text,, Color Check 2 +Gui, 2: Font, Q5 c%color_check2% s8 w550 Bold +Gui, 2: Add, Edit, vD, %color_check2% + +Gui, 2: Font, Q5 %guicolor5% s8 w550 Bold +Gui, 2: Add, Text, x100 y100, Color 2 Delay +Gui, 2: Add, Edit, x100 y120 w40 vE, %color_2_delay% + +Gui, 2: Add, Button, x20 y200 gSaveVars Default, Save +Gui, 2: Add, Button, x100 y200 gVarDef, Defaults +Gui, 2: Add, Checkbox, x100 y160 Checked%debug_mode% vdebug_mode gDebugging, Debug Mode +Gui, 2: Font, c11f s9 + +; --------- Gui 3 Setup -------------- +; Mods Gui +; +; ----------------------------------- + +Gui, 3: -MaximizeBox +Gui, 3: -MinimizeBox +Gui, 3: Color, c535770, c6272a4 +Gui, 3: Font, c11f s9 +Gui, 3: Font, Q5 %guicolor5% s8 w550 Bold +; Load mod settings +Loop, Parse, _mod_vars, | +{ + IniRead, %A_LoopField%, config.ini, Mods, %A_LoopField%, 0 +} + +Loop, Parse, _mod_vars, | +{ + + if ( %A_LoopField% = 1){ + Gui, 3: Add, Checkbox, Checked v%A_LoopField%, % _mod_names[A_Index] + } + else { + Gui, 3: Add, Checkbox, v%A_LoopField%, % _mod_names[A_Index] + } + +} + +Gui, 3: Add, Button, gSaveMods, Save +Gui, 3: Font, c11f s9 + +; End of Gui Setup +;--------- Gui 4 Setup -------------- +; Settings/Tunings Gui +; +; ----------------------------------- + +Gui, 4: -dpiscale +Gui, 4: +resize +Gui, 4: Font, Q5 %guicolor4% s8 w550 Bold +Gui, 4: Add, Button, x10 y10 gAssists1, Assists 1 +Gui, 4: Add, Button, x85 y10 gAssists2, Assists 2 +Gui, 4: Add, Button, x155 y10 gTune1, Tuning +Gui, 4: Add, Button, x215 y10 gTune2, Gears +Gui, 4: Add, Button, x270 y10 gControllerSetting, Controller +Gui, 4: Add, Picture, w800 h-1 vCurrentPic + +return + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; GUI Functions ; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +/* + These are subroutines used by the interaction with GUIs + + Some functions may be located in Mod files +*/ + +MenuTest: + gosub, GrabRemotePlay + Gui, Submit, NoHide + loop, %menu_loops% { + controller.Dpad.SetState(MenuDirect) + Sleep, 125 + controller.Dpad.SetState("None") + Sleep, 200 + } +return + +GetColo_p: + gosub, GrabRemotePlay + color_check1 := PixelColorSimple(pix1x, pix1y) +return + +GetColo_g: + gosub, GrabRemotePlay + color_check2 := PixelColorSimple(pix2x, pix2y) +return + +Debugging: + +return + +VariableWindow: + Gui, 2: Show, AutoSize, Variables +return + +ModWindow: + Gui, 3: Show, AutoSize, Mod List +return + +SaveRace: + Gui, Submit, NoHide + IniWrite, %RaceChoice%, config.ini, Race, RaceChoice +return + +SaveVars: + Gui, 2:Submit, NoHide + GuiControlGet, t, 2:, A + GuiControlGet, race_start_delay, 2:, B + GuiControlGet, color_check1, 2:, C + GuiControlGet, color_check2, 2:, D + GuiControlGet, color_2_delay, 2:, E + + Gui, 2: Font, Q5 c%color_check1% s8 w550 Bold + GuiControl, 2: Font, C + Gui, 2: Font, Q5 c%color_check2% s8 w550 Bold + GuiControl, 2: Font, D + +return + +SaveToIni: + ; System + loop, 3{ + + if( SysCheck = A_Index){ + IniWrite, 1, config.ini, Vars, SysCheck%A_Index% + } + else { + IniWrite, 0, config.ini, Vars, SysCheck%A_Index% + } + } + ; Color Check + ; Can't find a way to change colors + IniWrite %color_check1%, config.ini, Vars, color_check1 + IniWrite %color_check2%, config.ini, Vars, color_check2 + IniWrite %race_start_delay%, config.ini, Vars, race_start_delay + IniWrite, %debug_mode%, config.ini, Vars, debug_mode + IniWrite, %color_2_delay%, config.ini, Vars, color_2_delay + +return + +VarDef: + t := 210000 + race_start_delay := 0 + color_2_delay := 400 + GuiControl, 2:, A, %t% + GuiControl, 2:, B, %race_start_delay% + GuiControl, 2:, C, 0xBBE044 + GuiControl, 2:, D, 0xBBE044 + GuiControl, 2:, E, 300 +return + +ButtonStart: + Gui, Submit, NoHide + id := "" + SetKeyDelay, 10 + Process, priority, , High + gosub, GrabRemotePlay + if (id = "") + return + gosub, PauseLoop + CoordMode, Pixel, Screen + CoordMode, ToolTip, Screen + sleep 1000 + gosub, AFKLoop + return + + + ; ---------- Gui Setup End------------- + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; Actual Race Loop ; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +AFKLoop: + loop{ + Press_X() + Sleep(race_start_delay) + gosub, Race + gosub, Menu + SetFormat, IntegerFast, d + ToolTip, %A_Index% Races completed ٩(^ ᴗ ^)۶, 100, 100, Screen + } +return + +;; General Functions for AHK + +PixelTuning: + x_ratio := ps_win_width/640 + y_ratio := ps_win_height/360 +; pix1x := Floor(pix1x*x_ratio) +; pix1y := Floor(pix1y*y_ratio) +; pix2x := Floor(pix2x*x_ratio) +; pix2y := Floor(pix2y*y_ratio) +; tyreX := Floor(tyreX*x_ratio) +; tyreY := Floor(tyreY*y_ratio) + +return + +GrabRemotePlay: + WinGet, remotePlay_id, List, ahk_exe RemotePlay.exe + if (remotePlay_id = 0) + { + MsgBox, PS4 Remote Play not found + return + } + Loop, %remotePlay_id% + { + id := remotePlay_id%A_Index% + WinGetTitle, title, % "ahk_id " id + If InStr(title, "PS Remote Play") + break + } + WinGetClass, remotePlay_class, ahk_id %id% + if(__enableRemotePlaySizer_mod__ = 1){ + gosub, RemotePlay_ChangeSize + WinMove, ahk_id %id%,, 0, 0, 640, 540 + } + else{ + WinMove, ahk_id %id%,, 0, 0, 640, 360 + } + ControlFocus,, ahk_class %remotePlay_class% + WinActivate, ahk_id %id% + GetClientSize(remotePlay_id5, ps_win_width, ps_win_height) + gosub, PixelTuning +return + + +PSystem: + Gui, Submit, NoHide + if (SysCheck = 1){ + ps_load_time1 := 12000 + ps_load_time2 := 6000 + ps_load_time3 := 8400 + } + if (SysCheck = 2){ + ps_load_time1 := 44000 + ps_load_time2 := 12000 + ps_load_time3 := 37000 + } + if (SysCheck = 3){ + ps_load_time1 := 37000 + ps_load_time2 := 12000 + ps_load_time3 := 32000 + } +return + +Reset: + gosub, PauseLoop + gosub, SaveToIni + Reload + Sleep 1000 +return + +PauseLoop: + controller.Buttons.Cross.SetState(false) + controller.Buttons.Square.SetState(false) + controller.Buttons.Triangle.SetState(false) + controller.Buttons.Circle.SetState(false) + + controller.Buttons.L1.SetState(false) + controller.Buttons.L2.SetState(false) + controller.Axes.L2.SetState(0) + controller.Buttons.R1.SetState(false) + controller.Buttons.R2.SetState(false) + controller.Axes.R2.SetState(0) + + controller.Buttons.RS.SetState(false) + controller.Axes.RX.SetState(50) + controller.Axes.RY.SetState(50) + + controller.Buttons.LS.SetState(false) + controller.Axes.LX.SetState(50) + controller.Axes.LY.SetState(50) + + controller.Dpad.SetState("None") + +return + +MouseHelp: + + coord=relative + sleep, 1000 + CoordMode, ToolTip, %coord% + CoordMode, Pixel, %coord% + CoordMode, Mouse, %coord% + CoordMode, Caret, %coord% + CoordMode, Menu, %coord% +return + +Refresh: + MouseGetPos, x, y + PixelGetColor, cBGR, %x%, %y%,, Alt RGB + WinGetPos,,, w, h, A + ToolTip,Location: %x% x %y%`nRGB: %cBGR%`nWindow Size: %w% x %h% +return + +MouseColor: + gosub, MouseHelp + SetTimer, Refresh, 75 +return + +GuiClose: + gosub, PauseLoop + gosub, SaveToIni +ExitApp +^Esc::ExitApp + +/* +Pink RUF color" + which is the standart first one to buy if you want to buy car manufactur color (for me german GT7 i think its same for everyone) + 0xFA559F + +i have put that into Color check 1 and 2 works since 5 cycles - so maybe put them in with like (not tested) +(i think the first option that gets shown to buy a new color is the easiest to explain for people to buy except for colors the car exists in anyways (venom green) +here is the Hex Code for Porsche "Sternrubin" Ruby or Starruby depending on language: +0xBA3A64 +*/ diff --git a/bnowakow/old versions/3 GT7-AHK/GT7-AHKv1.00.12_test/Lib/AHK-ViGEm-Bus.ahk b/bnowakow/old versions/3 GT7-AHK/GT7-AHKv1.00.12_test/Lib/AHK-ViGEm-Bus.ahk new file mode 100644 index 0000000..858cb3d --- /dev/null +++ b/bnowakow/old versions/3 GT7-AHK/GT7-AHKv1.00.12_test/Lib/AHK-ViGEm-Bus.ahk @@ -0,0 +1,211 @@ +#include %A_LineFile%\..\CLR.ahk + +; Static class, holds ViGEm Client instance +class ViGEmWrapper { + static asm := 0 + static client := 0 + + Init(){ + if (this.client == 0){ + this.asm := CLR_LoadLibrary(A_LineFile "\..\ViGEmWrapper.dll") + } + } + + CreateInstance(cls){ + return this.asm.CreateInstance(cls) + } + +} + +; Base class for ViGEm "Targets" (Controller types - eg xb360 / ds4) to inherit from +class ViGEmTarget { + target := 0 + helperClass := "" + controllerClass := "" + + __New(){ + ;~ this.asm := CLR_LoadLibrary(A_LineFile "\..\ViGEmWrapper.dll") + ViGEmWrapper.Init() + this.Instance := ViGEmWrapper.CreateInstance(this.helperClass) + + if (this.Instance.OkCheck() != "OK"){ + msgbox ViGEmWrapper.dll failed to load! + ExitApp + } + } + + SendReport(){ + this.Instance.SendReport() + } + + SubscribeFeedback(callback){ + this.Instance.SubscribeFeedback(callback) + } +} + +; DS4 (DualShock 4 for Playstation 4) +class ViGEmDS4 extends ViGEmTarget { + helperClass := "ViGEmWrapper.Ds4" + __New(){ + static buttons := {Square: 16, Cross: 32, Circle: 64, Triangle: 128, L1: 256, R1: 512, L2: 1024, R2: 2048 + , Share: 4096, Options: 8192, LS: 16384, RS: 32768 } + static specialButtons := {Ps: 1, TouchPad: 2} + static axes := {LX: 2, LY: 3, RX: 4, RY: 5, LT: 0, RT: 1} + + this.Buttons := {} + for name, id in buttons { + this.Buttons[name] := new this._ButtonHelper(this, id) + } + for name, id in specialButtons { + this.Buttons[name] := new this._SpecialButtonHelper(this, id) + } + + this.Axes := {} + for name, id in axes { + this.Axes[name] := new this._AxisHelper(this, id) + } + + this.Dpad := new this._DpadHelper(this) + base.__New() + } + + class _ButtonHelper { + __New(parent, id){ + this._Parent := parent + this._Id := id + } + + SetState(state){ + this._Parent.Instance.SetButtonState(this._Id, state) + this._Parent.Instance.SendReport() + return this._Parent + } + } + + class _SpecialButtonHelper { + __New(parent, id){ + this._Parent := parent + this._Id := id + } + + SetState(state){ + this._Parent.Instance.SetSpecialButtonState(this._Id, state) + this._Parent.Instance.SendReport() + return this._Parent + } + } + + class _AxisHelper { + __New(parent, id){ + this._Parent := parent + this._Id := id + } + + SetState(state){ + this._Parent.Instance.SetAxisState(this._Id, this.ConvertAxis(state)) + this._Parent.Instance.SendReport() + return this._Parent + } + + ConvertAxis(state){ + return round(state * 2.55) + } + } + + class _DpadHelper { + __New(parent){ + this._Parent := parent + this._Id := id + } + + SetState(state){ + static dPadDirections := {Up: 0, UpRight: 1, Right: 2, DownRight: 3, Down: 4, DownLeft: 5, Left: 6, UpLeft: 7, None: 8} + this._Parent.Instance.SetDpadState(dPadDirections[state]) + this._Parent.Instance.SendReport() + return this._Parent + } + } +} + +; Xb360 +class ViGEmXb360 extends ViGEmTarget { + helperClass := "ViGEmWrapper.Xb360" + __New(){ + static buttons := {A: 4096, B: 8192, X: 16384, Y: 32768, LB: 256, RB: 512, LS: 64, RS: 128, Back: 32, Start: 16, Xbox: 1024} + static axes := {LX: 2, LY: 3, RX: 4, RY: 5, LT: 0, RT: 1} + + this.Buttons := {} + for name, id in buttons { + this.Buttons[name] := new this._ButtonHelper(this, id) + } + + this.Axes := {} + for name, id in axes { + this.Axes[name] := new this._AxisHelper(this, id) + } + + this.Dpad := new this._DpadHelper(this) + + base.__New() + } + + class _ButtonHelper { + __New(parent, id){ + this._Parent := parent + this._Id := id + } + + SetState(state){ + this._Parent.Instance.SetButtonState(this._Id, state) + this._Parent.Instance.SendReport() + return this._Parent + } + } + + class _AxisHelper { + __New(parent, id){ + this._Parent := parent + this._id := id + } + + SetState(state){ + this._Parent.Instance.SetAxisState(this._Id, this.ConvertAxis(state)) + this._Parent.Instance.SendReport() + } + + ConvertAxis(state){ + value := round((state * 655.36) - 32768) + if (value == 32768) + return 32767 + return value + } + } + + class _DpadHelper { + _DpadStates := {1:0, 8:0, 2:0, 4:0} ; Up, Right, Down, Left + __New(parent){ + this._Parent := parent + } + + SetState(state){ + static dpadDirections := { None: {1:0, 8:0, 2:0, 4:0} + , Up: {1:1, 8:0, 2:0, 4:0} + , UpRight: {1:1, 8:1, 2:0, 4:0} + , Right: {1:0, 8:1, 2:0, 4:0} + , DownRight: {1:0, 8:1, 2:1, 4:0} + , Down: {1:0, 8:0, 2:1, 4:0} + , DownLeft: {1:0, 8:0, 2:1, 4:1} + , Left: {1:0, 8:0, 2:0, 4:1} + , UpLeft: {1:1, 8:0, 2:0, 4:1}} + newStates := dpadDirections[state] + for id, newState in newStates { + oldState := this._DpadStates[id] + if (oldState != newState){ + this._DpadStates[id] := newState + this._Parent.Instance.SetButtonState(id, newState) + } + this._Parent.SendReport() + } + } + } +} \ No newline at end of file diff --git a/bnowakow/old versions/3 GT7-AHK/GT7-AHKv1.00.12_test/Lib/CLR.ahk b/bnowakow/old versions/3 GT7-AHK/GT7-AHKv1.00.12_test/Lib/CLR.ahk new file mode 100644 index 0000000..d16ab68 --- /dev/null +++ b/bnowakow/old versions/3 GT7-AHK/GT7-AHKv1.00.12_test/Lib/CLR.ahk @@ -0,0 +1,151 @@ +; ========================================================== +; .NET Framework Interop +; https://autohotkey.com/boards/viewtopic.php?t=4633 +; ========================================================== +; +; Author: Lexikos +; Version: 1.2 +; Requires: AutoHotkey_L v1.0.96+ +; + +CLR_LoadLibrary(AssemblyName, AppDomain=0) +{ + if !AppDomain + AppDomain := CLR_GetDefaultDomain() + e := ComObjError(0) + Loop 1 { + if assembly := AppDomain.Load_2(AssemblyName) + break + static null := ComObject(13,0) + args := ComObjArray(0xC, 1), args[0] := AssemblyName + typeofAssembly := AppDomain.GetType().Assembly.GetType() + if assembly := typeofAssembly.InvokeMember_3("LoadWithPartialName", 0x158, null, null, args) + break + if assembly := typeofAssembly.InvokeMember_3("LoadFrom", 0x158, null, null, args) + break + } + ComObjError(e) + return assembly +} + +CLR_CreateObject(Assembly, TypeName, Args*) +{ + if !(argCount := Args.MaxIndex()) + return Assembly.CreateInstance_2(TypeName, true) + + vargs := ComObjArray(0xC, argCount) + Loop % argCount + vargs[A_Index-1] := Args[A_Index] + + static Array_Empty := ComObjArray(0xC,0), null := ComObject(13,0) + + return Assembly.CreateInstance_3(TypeName, true, 0, null, vargs, null, Array_Empty) +} + +CLR_CompileC#(Code, References="", AppDomain=0, FileName="", CompilerOptions="") +{ + return CLR_CompileAssembly(Code, References, "System", "Microsoft.CSharp.CSharpCodeProvider", AppDomain, FileName, CompilerOptions) +} + +CLR_CompileVB(Code, References="", AppDomain=0, FileName="", CompilerOptions="") +{ + return CLR_CompileAssembly(Code, References, "System", "Microsoft.VisualBasic.VBCodeProvider", AppDomain, FileName, CompilerOptions) +} + +CLR_StartDomain(ByRef AppDomain, BaseDirectory="") +{ + static null := ComObject(13,0) + args := ComObjArray(0xC, 5), args[0] := "", args[2] := BaseDirectory, args[4] := ComObject(0xB,false) + AppDomain := CLR_GetDefaultDomain().GetType().InvokeMember_3("CreateDomain", 0x158, null, null, args) + return A_LastError >= 0 +} + +CLR_StopDomain(ByRef AppDomain) +{ ; ICorRuntimeHost::UnloadDomain + DllCall("SetLastError", "uint", hr := DllCall(NumGet(NumGet(0+RtHst:=CLR_Start())+20*A_PtrSize), "ptr", RtHst, "ptr", ComObjValue(AppDomain))), AppDomain := "" + return hr >= 0 +} + +; NOTE: IT IS NOT NECESSARY TO CALL THIS FUNCTION unless you need to load a specific version. +CLR_Start(Version="") ; returns ICorRuntimeHost* +{ + static RtHst := 0 + ; The simple method gives no control over versioning, and seems to load .NET v2 even when v4 is present: + ; return RtHst ? RtHst : (RtHst:=COM_CreateObject("CLRMetaData.CorRuntimeHost","{CB2F6722-AB3A-11D2-9C40-00C04FA30A3E}"), DllCall(NumGet(NumGet(RtHst+0)+40),"uint",RtHst)) + if RtHst + return RtHst + EnvGet SystemRoot, SystemRoot + if Version = + Loop % SystemRoot "\Microsoft.NET\Framework" (A_PtrSize=8?"64":"") "\*", 2 + if (FileExist(A_LoopFileFullPath "\mscorlib.dll") && A_LoopFileName > Version) + Version := A_LoopFileName + if DllCall("mscoree\CorBindToRuntimeEx", "wstr", Version, "ptr", 0, "uint", 0 + , "ptr", CLR_GUID(CLSID_CorRuntimeHost, "{CB2F6723-AB3A-11D2-9C40-00C04FA30A3E}") + , "ptr", CLR_GUID(IID_ICorRuntimeHost, "{CB2F6722-AB3A-11D2-9C40-00C04FA30A3E}") + , "ptr*", RtHst) >= 0 + DllCall(NumGet(NumGet(RtHst+0)+10*A_PtrSize), "ptr", RtHst) ; Start + return RtHst +} + +; +; INTERNAL FUNCTIONS +; + +CLR_GetDefaultDomain() +{ + static defaultDomain := 0 + if !defaultDomain + { ; ICorRuntimeHost::GetDefaultDomain + if DllCall(NumGet(NumGet(0+RtHst:=CLR_Start())+13*A_PtrSize), "ptr", RtHst, "ptr*", p:=0) >= 0 + defaultDomain := ComObject(p), ObjRelease(p) + } + return defaultDomain +} + +CLR_CompileAssembly(Code, References, ProviderAssembly, ProviderType, AppDomain=0, FileName="", CompilerOptions="") +{ + if !AppDomain + AppDomain := CLR_GetDefaultDomain() + + if !(asmProvider := CLR_LoadLibrary(ProviderAssembly, AppDomain)) + || !(codeProvider := asmProvider.CreateInstance(ProviderType)) + || !(codeCompiler := codeProvider.CreateCompiler()) + return 0 + + if !(asmSystem := (ProviderAssembly="System") ? asmProvider : CLR_LoadLibrary("System", AppDomain)) + return 0 + + ; Convert | delimited list of references into an array. + StringSplit, Refs, References, |, %A_Space%%A_Tab% + aRefs := ComObjArray(8, Refs0) + Loop % Refs0 + aRefs[A_Index-1] := Refs%A_Index% + + ; Set parameters for compiler. + prms := CLR_CreateObject(asmSystem, "System.CodeDom.Compiler.CompilerParameters", aRefs) + , prms.OutputAssembly := FileName + , prms.GenerateInMemory := FileName="" + , prms.GenerateExecutable := SubStr(FileName,-3)=".exe" + , prms.CompilerOptions := CompilerOptions + , prms.IncludeDebugInformation := true + + ; Compile! + compilerRes := codeCompiler.CompileAssemblyFromSource(prms, Code) + + if error_count := (errors := compilerRes.Errors).Count + { + error_text := "" + Loop % error_count + error_text .= ((e := errors.Item[A_Index-1]).IsWarning ? "Warning " : "Error ") . e.ErrorNumber " on line " e.Line ": " e.ErrorText "`n`n" + MsgBox, 16, Compilation Failed, %error_text% + return 0 + } + ; Success. Return Assembly object or path. + return compilerRes[FileName="" ? "CompiledAssembly" : "PathToAssembly"] +} + +CLR_GUID(ByRef GUID, sGUID) +{ + VarSetCapacity(GUID, 16, 0) + return DllCall("ole32\CLSIDFromString", "wstr", sGUID, "ptr", &GUID) >= 0 ? &GUID : "" +} \ No newline at end of file diff --git a/bnowakow/old versions/3 GT7-AHK/GT7-AHKv1.00.12_test/Lib/Gdip.ahk b/bnowakow/old versions/3 GT7-AHK/GT7-AHKv1.00.12_test/Lib/Gdip.ahk new file mode 100644 index 0000000..3efb7ae --- /dev/null +++ b/bnowakow/old versions/3 GT7-AHK/GT7-AHKv1.00.12_test/Lib/Gdip.ahk @@ -0,0 +1,2714 @@ +; Gdip standard library v1.45 by tic (Tariq Porter) 07/09/11 +; Modifed by Rseding91 using fincs 64 bit compatible Gdip library 5/1/2013 +; Supports: Basic, _L ANSi, _L Unicode x86 and _L Unicode x64 +; +; Updated 2/20/2014 - fixed Gdip_CreateRegion() and Gdip_GetClipRegion() on AHK Unicode x86 +; Updated 5/13/2013 - fixed Gdip_SetBitmapToClipboard() on AHK Unicode x64 +; +;##################################################################################### +;##################################################################################### +; STATUS ENUMERATION +; Return values for functions specified to have status enumerated return type +;##################################################################################### +; +; Ok = = 0 +; GenericError = 1 +; InvalidParameter = 2 +; OutOfMemory = 3 +; ObjectBusy = 4 +; InsufficientBuffer = 5 +; NotImplemented = 6 +; Win32Error = 7 +; WrongState = 8 +; Aborted = 9 +; FileNotFound = 10 +; ValueOverflow = 11 +; AccessDenied = 12 +; UnknownImageFormat = 13 +; FontFamilyNotFound = 14 +; FontStyleNotFound = 15 +; NotTrueTypeFont = 16 +; UnsupportedGdiplusVersion = 17 +; GdiplusNotInitialized = 18 +; PropertyNotFound = 19 +; PropertyNotSupported = 20 +; ProfileNotFound = 21 +; +;##################################################################################### +;##################################################################################### +; FUNCTIONS +;##################################################################################### +; +; UpdateLayeredWindow(hwnd, hdc, x="", y="", w="", h="", Alpha=255) +; BitBlt(ddc, dx, dy, dw, dh, sdc, sx, sy, Raster="") +; StretchBlt(dDC, dx, dy, dw, dh, sDC, sx, sy, sw, sh, Raster="") +; SetImage(hwnd, hBitmap) +; Gdip_BitmapFromScreen(Screen=0, Raster="") +; CreateRectF(ByRef RectF, x, y, w, h) +; CreateSizeF(ByRef SizeF, w, h) +; CreateDIBSection +; +;##################################################################################### + +; Function: UpdateLayeredWindow +; Description: Updates a layered window with the handle to the DC of a gdi bitmap +; +; hwnd Handle of the layered window to update +; hdc Handle to the DC of the GDI bitmap to update the window with +; Layeredx x position to place the window +; Layeredy y position to place the window +; Layeredw Width of the window +; Layeredh Height of the window +; Alpha Default = 255 : The transparency (0-255) to set the window transparency +; +; return If the function succeeds, the return value is nonzero +; +; notes If x or y omitted, then layered window will use its current coordinates +; If w or h omitted then current width and height will be used + +UpdateLayeredWindow(hwnd, hdc, x="", y="", w="", h="", Alpha=255) +{ + Ptr := A_PtrSize ? "UPtr" : "UInt" + + if ((x != "") && (y != "")) + VarSetCapacity(pt, 8), NumPut(x, pt, 0, "UInt"), NumPut(y, pt, 4, "UInt") + + if (w = "") ||(h = "") + WinGetPos,,, w, h, ahk_id %hwnd% + + return DllCall("UpdateLayeredWindow" + , Ptr, hwnd + , Ptr, 0 + , Ptr, ((x = "") && (y = "")) ? 0 : &pt + , "int64*", w|h<<32 + , Ptr, hdc + , "int64*", 0 + , "uint", 0 + , "UInt*", Alpha<<16|1<<24 + , "uint", 2) +} + +;##################################################################################### + +; Function BitBlt +; Description The BitBlt function performs a bit-block transfer of the color data corresponding to a rectangle +; of pixels from the specified source device context into a destination device context. +; +; dDC handle to destination DC +; dx x-coord of destination upper-left corner +; dy y-coord of destination upper-left corner +; dw width of the area to copy +; dh height of the area to copy +; sDC handle to source DC +; sx x-coordinate of source upper-left corner +; sy y-coordinate of source upper-left corner +; Raster raster operation code +; +; return If the function succeeds, the return value is nonzero +; +; notes If no raster operation is specified, then SRCCOPY is used, which copies the source directly to the destination rectangle +; +; BLACKNESS = 0x00000042 +; NOTSRCERASE = 0x001100A6 +; NOTSRCCOPY = 0x00330008 +; SRCERASE = 0x00440328 +; DSTINVERT = 0x00550009 +; PATINVERT = 0x005A0049 +; SRCINVERT = 0x00660046 +; SRCAND = 0x008800C6 +; MERGEPAINT = 0x00BB0226 +; MERGECOPY = 0x00C000CA +; SRCCOPY = 0x00CC0020 +; SRCPAINT = 0x00EE0086 +; PATCOPY = 0x00F00021 +; PATPAINT = 0x00FB0A09 +; WHITENESS = 0x00FF0062 +; CAPTUREBLT = 0x40000000 +; NOMIRRORBITMAP = 0x80000000 + +BitBlt(ddc, dx, dy, dw, dh, sdc, sx, sy, Raster="") +{ + Ptr := A_PtrSize ? "UPtr" : "UInt" + + return DllCall("gdi32\BitBlt" + , Ptr, dDC + , "int", dx + , "int", dy + , "int", dw + , "int", dh + , Ptr, sDC + , "int", sx + , "int", sy + , "uint", Raster ? Raster : 0x00CC0020) +} + +;##################################################################################### + +; Function StretchBlt +; Description The StretchBlt function copies a bitmap from a source rectangle into a destination rectangle, +; stretching or compressing the bitmap to fit the dimensions of the destination rectangle, if necessary. +; The system stretches or compresses the bitmap according to the stretching mode currently set in the destination device context. +; +; ddc handle to destination DC +; dx x-coord of destination upper-left corner +; dy y-coord of destination upper-left corner +; dw width of destination rectangle +; dh height of destination rectangle +; sdc handle to source DC +; sx x-coordinate of source upper-left corner +; sy y-coordinate of source upper-left corner +; sw width of source rectangle +; sh height of source rectangle +; Raster raster operation code +; +; return If the function succeeds, the return value is nonzero +; +; notes If no raster operation is specified, then SRCCOPY is used. It uses the same raster operations as BitBlt + +StretchBlt(ddc, dx, dy, dw, dh, sdc, sx, sy, sw, sh, Raster="") +{ + Ptr := A_PtrSize ? "UPtr" : "UInt" + + return DllCall("gdi32\StretchBlt" + , Ptr, ddc + , "int", dx + , "int", dy + , "int", dw + , "int", dh + , Ptr, sdc + , "int", sx + , "int", sy + , "int", sw + , "int", sh + , "uint", Raster ? Raster : 0x00CC0020) +} + +;##################################################################################### + +; Function SetStretchBltMode +; Description The SetStretchBltMode function sets the bitmap stretching mode in the specified device context +; +; hdc handle to the DC +; iStretchMode The stretching mode, describing how the target will be stretched +; +; return If the function succeeds, the return value is the previous stretching mode. If it fails it will return 0 +; +; STRETCH_ANDSCANS = 0x01 +; STRETCH_ORSCANS = 0x02 +; STRETCH_DELETESCANS = 0x03 +; STRETCH_HALFTONE = 0x04 + +SetStretchBltMode(hdc, iStretchMode=4) +{ + return DllCall("gdi32\SetStretchBltMode" + , A_PtrSize ? "UPtr" : "UInt", hdc + , "int", iStretchMode) +} + +;##################################################################################### + +; Function SetImage +; Description Associates a new image with a static control +; +; hwnd handle of the control to update +; hBitmap a gdi bitmap to associate the static control with +; +; return If the function succeeds, the return value is nonzero + +SetImage(hwnd, hBitmap) +{ + SendMessage, 0x172, 0x0, hBitmap,, ahk_id %hwnd% + E := ErrorLevel + DeleteObject(E) + return E +} + +;##################################################################################### + +; Function SetSysColorToControl +; Description Sets a solid colour to a control +; +; hwnd handle of the control to update +; SysColor A system colour to set to the control +; +; return If the function succeeds, the return value is zero +; +; notes A control must have the 0xE style set to it so it is recognised as a bitmap +; By default SysColor=15 is used which is COLOR_3DFACE. This is the standard background for a control +; +; COLOR_3DDKSHADOW = 21 +; COLOR_3DFACE = 15 +; COLOR_3DHIGHLIGHT = 20 +; COLOR_3DHILIGHT = 20 +; COLOR_3DLIGHT = 22 +; COLOR_3DSHADOW = 16 +; COLOR_ACTIVEBORDER = 10 +; COLOR_ACTIVECAPTION = 2 +; COLOR_APPWORKSPACE = 12 +; COLOR_BACKGROUND = 1 +; COLOR_BTNFACE = 15 +; COLOR_BTNHIGHLIGHT = 20 +; COLOR_BTNHILIGHT = 20 +; COLOR_BTNSHADOW = 16 +; COLOR_BTNTEXT = 18 +; COLOR_CAPTIONTEXT = 9 +; COLOR_DESKTOP = 1 +; COLOR_GRADIENTACTIVECAPTION = 27 +; COLOR_GRADIENTINACTIVECAPTION = 28 +; COLOR_GRAYTEXT = 17 +; COLOR_HIGHLIGHT = 13 +; COLOR_HIGHLIGHTTEXT = 14 +; COLOR_HOTLIGHT = 26 +; COLOR_INACTIVEBORDER = 11 +; COLOR_INACTIVECAPTION = 3 +; COLOR_INACTIVECAPTIONTEXT = 19 +; COLOR_INFOBK = 24 +; COLOR_INFOTEXT = 23 +; COLOR_MENU = 4 +; COLOR_MENUHILIGHT = 29 +; COLOR_MENUBAR = 30 +; COLOR_MENUTEXT = 7 +; COLOR_SCROLLBAR = 0 +; COLOR_WINDOW = 5 +; COLOR_WINDOWFRAME = 6 +; COLOR_WINDOWTEXT = 8 + +SetSysColorToControl(hwnd, SysColor=15) +{ + WinGetPos,,, w, h, ahk_id %hwnd% + bc := DllCall("GetSysColor", "Int", SysColor, "UInt") + pBrushClear := Gdip_BrushCreateSolid(0xff000000 | (bc >> 16 | bc & 0xff00 | (bc & 0xff) << 16)) + pBitmap := Gdip_CreateBitmap(w, h), G := Gdip_GraphicsFromImage(pBitmap) + Gdip_FillRectangle(G, pBrushClear, 0, 0, w, h) + hBitmap := Gdip_CreateHBITMAPFromBitmap(pBitmap) + SetImage(hwnd, hBitmap) + Gdip_DeleteBrush(pBrushClear) + Gdip_DeleteGraphics(G), Gdip_DisposeImage(pBitmap), DeleteObject(hBitmap) + return 0 +} + +;##################################################################################### + +; Function Gdip_BitmapFromScreen +; Description Gets a gdi+ bitmap from the screen +; +; Screen 0 = All screens +; Any numerical value = Just that screen +; x|y|w|h = Take specific coordinates with a width and height +; Raster raster operation code +; +; return If the function succeeds, the return value is a pointer to a gdi+ bitmap +; -1: one or more of x,y,w,h not passed properly +; +; notes If no raster operation is specified, then SRCCOPY is used to the returned bitmap + +Gdip_BitmapFromScreen(Screen=0, Raster="") +{ + if (Screen = 0) + { + Sysget, x, 76 + Sysget, y, 77 + Sysget, w, 78 + Sysget, h, 79 + } + else if (SubStr(Screen, 1, 5) = "hwnd:") + { + Screen := SubStr(Screen, 6) + if !WinExist( "ahk_id " Screen) + return -2 + WinGetPos,,, w, h, ahk_id %Screen% + x := y := 0 + hhdc := GetDCEx(Screen, 3) + } + else if (Screen&1 != "") + { + Sysget, M, Monitor, %Screen% + x := MLeft, y := MTop, w := MRight-MLeft, h := MBottom-MTop + } + else + { + StringSplit, S, Screen, | + x := S1, y := S2, w := S3, h := S4 + } + + if (x = "") || (y = "") || (w = "") || (h = "") + return -1 + + chdc := CreateCompatibleDC(), hbm := CreateDIBSection(w, h, chdc), obm := SelectObject(chdc, hbm), hhdc := hhdc ? hhdc : GetDC() + BitBlt(chdc, 0, 0, w, h, hhdc, x, y, Raster) + ReleaseDC(hhdc) + + pBitmap := Gdip_CreateBitmapFromHBITMAP(hbm) + SelectObject(chdc, obm), DeleteObject(hbm), DeleteDC(hhdc), DeleteDC(chdc) + return pBitmap +} + +;##################################################################################### + +; Function Gdip_BitmapFromHWND +; Description Uses PrintWindow to get a handle to the specified window and return a bitmap from it +; +; hwnd handle to the window to get a bitmap from +; +; return If the function succeeds, the return value is a pointer to a gdi+ bitmap +; +; notes Window must not be not minimised in order to get a handle to it's client area + +Gdip_BitmapFromHWND(hwnd) +{ + WinGetPos,,, Width, Height, ahk_id %hwnd% + hbm := CreateDIBSection(Width, Height), hdc := CreateCompatibleDC(), obm := SelectObject(hdc, hbm) + RegExMatch(A_OsVersion, "\d+", Version) + PrintWindow(hwnd, hdc, Version >= 8 ? 2 : 0) + pBitmap := Gdip_CreateBitmapFromHBITMAP(hbm) + SelectObject(hdc, obm), DeleteObject(hbm), DeleteDC(hdc) + return pBitmap +} + +;##################################################################################### + +; Function CreateRectF +; Description Creates a RectF object, containing a the coordinates and dimensions of a rectangle +; +; RectF Name to call the RectF object +; x x-coordinate of the upper left corner of the rectangle +; y y-coordinate of the upper left corner of the rectangle +; w Width of the rectangle +; h Height of the rectangle +; +; return No return value + +CreateRectF(ByRef RectF, x, y, w, h) +{ + VarSetCapacity(RectF, 16) + NumPut(x, RectF, 0, "float"), NumPut(y, RectF, 4, "float"), NumPut(w, RectF, 8, "float"), NumPut(h, RectF, 12, "float") +} + +;##################################################################################### + +; Function CreateRect +; Description Creates a Rect object, containing a the coordinates and dimensions of a rectangle +; +; RectF Name to call the RectF object +; x x-coordinate of the upper left corner of the rectangle +; y y-coordinate of the upper left corner of the rectangle +; w Width of the rectangle +; h Height of the rectangle +; +; return No return value + +CreateRect(ByRef Rect, x, y, w, h) +{ + VarSetCapacity(Rect, 16) + NumPut(x, Rect, 0, "uint"), NumPut(y, Rect, 4, "uint"), NumPut(w, Rect, 8, "uint"), NumPut(h, Rect, 12, "uint") +} +;##################################################################################### + +; Function CreateSizeF +; Description Creates a SizeF object, containing an 2 values +; +; SizeF Name to call the SizeF object +; w w-value for the SizeF object +; h h-value for the SizeF object +; +; return No Return value + +CreateSizeF(ByRef SizeF, w, h) +{ + VarSetCapacity(SizeF, 8) + NumPut(w, SizeF, 0, "float"), NumPut(h, SizeF, 4, "float") +} +;##################################################################################### + +; Function CreatePointF +; Description Creates a SizeF object, containing an 2 values +; +; SizeF Name to call the SizeF object +; w w-value for the SizeF object +; h h-value for the SizeF object +; +; return No Return value + +CreatePointF(ByRef PointF, x, y) +{ + VarSetCapacity(PointF, 8) + NumPut(x, PointF, 0, "float"), NumPut(y, PointF, 4, "float") +} +;##################################################################################### + +; Function CreateDIBSection +; Description The CreateDIBSection function creates a DIB (Device Independent Bitmap) that applications can write to directly +; +; w width of the bitmap to create +; h height of the bitmap to create +; hdc a handle to the device context to use the palette from +; bpp bits per pixel (32 = ARGB) +; ppvBits A pointer to a variable that receives a pointer to the location of the DIB bit values +; +; return returns a DIB. A gdi bitmap +; +; notes ppvBits will receive the location of the pixels in the DIB + +CreateDIBSection(w, h, hdc="", bpp=32, ByRef ppvBits=0) +{ + Ptr := A_PtrSize ? "UPtr" : "UInt" + + hdc2 := hdc ? hdc : GetDC() + VarSetCapacity(bi, 40, 0) + + NumPut(w, bi, 4, "uint") + , NumPut(h, bi, 8, "uint") + , NumPut(40, bi, 0, "uint") + , NumPut(1, bi, 12, "ushort") + , NumPut(0, bi, 16, "uInt") + , NumPut(bpp, bi, 14, "ushort") + + hbm := DllCall("CreateDIBSection" + , Ptr, hdc2 + , Ptr, &bi + , "uint", 0 + , A_PtrSize ? "UPtr*" : "uint*", ppvBits + , Ptr, 0 + , "uint", 0, Ptr) + + if !hdc + ReleaseDC(hdc2) + return hbm +} + +;##################################################################################### + +; Function PrintWindow +; Description The PrintWindow function copies a visual window into the specified device context (DC), typically a printer DC +; +; hwnd A handle to the window that will be copied +; hdc A handle to the device context +; Flags Drawing options +; +; return If the function succeeds, it returns a nonzero value +; +; PW_CLIENTONLY = 1 + +PrintWindow(hwnd, hdc, Flags=0) +{ + Ptr := A_PtrSize ? "UPtr" : "UInt" + + return DllCall("PrintWindow", Ptr, hwnd, Ptr, hdc, "uint", Flags) +} + +;##################################################################################### + +; Function DestroyIcon +; Description Destroys an icon and frees any memory the icon occupied +; +; hIcon Handle to the icon to be destroyed. The icon must not be in use +; +; return If the function succeeds, the return value is nonzero + +DestroyIcon(hIcon) +{ + return DllCall("DestroyIcon", A_PtrSize ? "UPtr" : "UInt", hIcon) +} + +;##################################################################################### + +PaintDesktop(hdc) +{ + return DllCall("PaintDesktop", A_PtrSize ? "UPtr" : "UInt", hdc) +} + +;##################################################################################### + +CreateCompatibleBitmap(hdc, w, h) +{ + return DllCall("gdi32\CreateCompatibleBitmap", A_PtrSize ? "UPtr" : "UInt", hdc, "int", w, "int", h) +} + +;##################################################################################### + +; Function CreateCompatibleDC +; Description This function creates a memory device context (DC) compatible with the specified device +; +; hdc Handle to an existing device context +; +; return returns the handle to a device context or 0 on failure +; +; notes If this handle is 0 (by default), the function creates a memory device context compatible with the application's current screen + +CreateCompatibleDC(hdc=0) +{ + return DllCall("CreateCompatibleDC", A_PtrSize ? "UPtr" : "UInt", hdc) +} + +;##################################################################################### + +; Function SelectObject +; Description The SelectObject function selects an object into the specified device context (DC). The new object replaces the previous object of the same type +; +; hdc Handle to a DC +; hgdiobj A handle to the object to be selected into the DC +; +; return If the selected object is not a region and the function succeeds, the return value is a handle to the object being replaced +; +; notes The specified object must have been created by using one of the following functions +; Bitmap - CreateBitmap, CreateBitmapIndirect, CreateCompatibleBitmap, CreateDIBitmap, CreateDIBSection (A single bitmap cannot be selected into more than one DC at the same time) +; Brush - CreateBrushIndirect, CreateDIBPatternBrush, CreateDIBPatternBrushPt, CreateHatchBrush, CreatePatternBrush, CreateSolidBrush +; Font - CreateFont, CreateFontIndirect +; Pen - CreatePen, CreatePenIndirect +; Region - CombineRgn, CreateEllipticRgn, CreateEllipticRgnIndirect, CreatePolygonRgn, CreateRectRgn, CreateRectRgnIndirect +; +; notes If the selected object is a region and the function succeeds, the return value is one of the following value +; +; SIMPLEREGION = 2 Region consists of a single rectangle +; COMPLEXREGION = 3 Region consists of more than one rectangle +; NULLREGION = 1 Region is empty + +SelectObject(hdc, hgdiobj) +{ + Ptr := A_PtrSize ? "UPtr" : "UInt" + + return DllCall("SelectObject", Ptr, hdc, Ptr, hgdiobj) +} + +;##################################################################################### + +; Function DeleteObject +; Description This function deletes a logical pen, brush, font, bitmap, region, or palette, freeing all system resources associated with the object +; After the object is deleted, the specified handle is no longer valid +; +; hObject Handle to a logical pen, brush, font, bitmap, region, or palette to delete +; +; return Nonzero indicates success. Zero indicates that the specified handle is not valid or that the handle is currently selected into a device context + +DeleteObject(hObject) +{ + return DllCall("DeleteObject", A_PtrSize ? "UPtr" : "UInt", hObject) +} + +;##################################################################################### + +; Function GetDC +; Description This function retrieves a handle to a display device context (DC) for the client area of the specified window. +; The display device context can be used in subsequent graphics display interface (GDI) functions to draw in the client area of the window. +; +; hwnd Handle to the window whose device context is to be retrieved. If this value is NULL, GetDC retrieves the device context for the entire screen +; +; return The handle the device context for the specified window's client area indicates success. NULL indicates failure + +GetDC(hwnd=0) +{ + return DllCall("GetDC", A_PtrSize ? "UPtr" : "UInt", hwnd) +} + +;##################################################################################### + +; DCX_CACHE = 0x2 +; DCX_CLIPCHILDREN = 0x8 +; DCX_CLIPSIBLINGS = 0x10 +; DCX_EXCLUDERGN = 0x40 +; DCX_EXCLUDEUPDATE = 0x100 +; DCX_INTERSECTRGN = 0x80 +; DCX_INTERSECTUPDATE = 0x200 +; DCX_LOCKWINDOWUPDATE = 0x400 +; DCX_NORECOMPUTE = 0x100000 +; DCX_NORESETATTRS = 0x4 +; DCX_PARENTCLIP = 0x20 +; DCX_VALIDATE = 0x200000 +; DCX_WINDOW = 0x1 + +GetDCEx(hwnd, flags=0, hrgnClip=0) +{ + Ptr := A_PtrSize ? "UPtr" : "UInt" + + return DllCall("GetDCEx", Ptr, hwnd, Ptr, hrgnClip, "int", flags) +} + +;##################################################################################### + +; Function ReleaseDC +; Description This function releases a device context (DC), freeing it for use by other applications. The effect of ReleaseDC depends on the type of device context +; +; hdc Handle to the device context to be released +; hwnd Handle to the window whose device context is to be released +; +; return 1 = released +; 0 = not released +; +; notes The application must call the ReleaseDC function for each call to the GetWindowDC function and for each call to the GetDC function that retrieves a common device context +; An application cannot use the ReleaseDC function to release a device context that was created by calling the CreateDC function; instead, it must use the DeleteDC function. + +ReleaseDC(hdc, hwnd=0) +{ + Ptr := A_PtrSize ? "UPtr" : "UInt" + + return DllCall("ReleaseDC", Ptr, hwnd, Ptr, hdc) +} + +;##################################################################################### + +; Function DeleteDC +; Description The DeleteDC function deletes the specified device context (DC) +; +; hdc A handle to the device context +; +; return If the function succeeds, the return value is nonzero +; +; notes An application must not delete a DC whose handle was obtained by calling the GetDC function. Instead, it must call the ReleaseDC function to free the DC + +DeleteDC(hdc) +{ + return DllCall("DeleteDC", A_PtrSize ? "UPtr" : "UInt", hdc) +} +;##################################################################################### + +; Function Gdip_LibraryVersion +; Description Get the current library version +; +; return the library version +; +; notes This is useful for non compiled programs to ensure that a person doesn't run an old version when testing your scripts + +Gdip_LibraryVersion() +{ + return 1.45 +} + +;##################################################################################### + +; Function Gdip_LibrarySubVersion +; Description Get the current library sub version +; +; return the library sub version +; +; notes This is the sub-version currently maintained by Rseding91 +Gdip_LibrarySubVersion() +{ + return 1.47 +} + +;##################################################################################### + +; Function: Gdip_BitmapFromBRA +; Description: Gets a pointer to a gdi+ bitmap from a BRA file +; +; BRAFromMemIn The variable for a BRA file read to memory +; File The name of the file, or its number that you would like (This depends on alternate parameter) +; Alternate Changes whether the File parameter is the file name or its number +; +; return If the function succeeds, the return value is a pointer to a gdi+ bitmap +; -1 = The BRA variable is empty +; -2 = The BRA has an incorrect header +; -3 = The BRA has information missing +; -4 = Could not find file inside the BRA + +Gdip_BitmapFromBRA(ByRef BRAFromMemIn, File, Alternate=0) +{ + Static FName = "ObjRelease" + + if !BRAFromMemIn + return -1 + Loop, Parse, BRAFromMemIn, `n + { + if (A_Index = 1) + { + StringSplit, Header, A_LoopField, | + if (Header0 != 4 || Header2 != "BRA!") + return -2 + } + else if (A_Index = 2) + { + StringSplit, Info, A_LoopField, | + if (Info0 != 3) + return -3 + } + else + break + } + if !Alternate + StringReplace, File, File, \, \\, All + RegExMatch(BRAFromMemIn, "mi`n)^" (Alternate ? File "\|.+?\|(\d+)\|(\d+)" : "\d+\|" File "\|(\d+)\|(\d+)") "$", FileInfo) + if !FileInfo + return -4 + + hData := DllCall("GlobalAlloc", "uint", 2, Ptr, FileInfo2, Ptr) + pData := DllCall("GlobalLock", Ptr, hData, Ptr) + DllCall("RtlMoveMemory", Ptr, pData, Ptr, &BRAFromMemIn+Info2+FileInfo1, Ptr, FileInfo2) + DllCall("GlobalUnlock", Ptr, hData) + DllCall("ole32\CreateStreamOnHGlobal", Ptr, hData, "int", 1, A_PtrSize ? "UPtr*" : "UInt*", pStream) + DllCall("gdiplus\GdipCreateBitmapFromStream", Ptr, pStream, A_PtrSize ? "UPtr*" : "UInt*", pBitmap) + If (A_PtrSize) + %FName%(pStream) + Else + DllCall(NumGet(NumGet(1*pStream)+8), "uint", pStream) + return pBitmap +} + +;##################################################################################### + +; Function Gdip_DrawRectangle +; Description This function uses a pen to draw the outline of a rectangle into the Graphics of a bitmap +; +; pGraphics Pointer to the Graphics of a bitmap +; pPen Pointer to a pen +; x x-coordinate of the top left of the rectangle +; y y-coordinate of the top left of the rectangle +; w width of the rectanlge +; h height of the rectangle +; +; return status enumeration. 0 = success +; +; notes as all coordinates are taken from the top left of each pixel, then the entire width/height should be specified as subtracting the pen width + +Gdip_DrawRectangle(pGraphics, pPen, x, y, w, h) +{ + Ptr := A_PtrSize ? "UPtr" : "UInt" + + return DllCall("gdiplus\GdipDrawRectangle", Ptr, pGraphics, Ptr, pPen, "float", x, "float", y, "float", w, "float", h) +} + +;##################################################################################### + +; Function Gdip_DrawRoundedRectangle +; Description This function uses a pen to draw the outline of a rounded rectangle into the Graphics of a bitmap +; +; pGraphics Pointer to the Graphics of a bitmap +; pPen Pointer to a pen +; x x-coordinate of the top left of the rounded rectangle +; y y-coordinate of the top left of the rounded rectangle +; w width of the rectanlge +; h height of the rectangle +; r radius of the rounded corners +; +; return status enumeration. 0 = success +; +; notes as all coordinates are taken from the top left of each pixel, then the entire width/height should be specified as subtracting the pen width + +Gdip_DrawRoundedRectangle(pGraphics, pPen, x, y, w, h, r) +{ + Gdip_SetClipRect(pGraphics, x-r, y-r, 2*r, 2*r, 4) + Gdip_SetClipRect(pGraphics, x+w-r, y-r, 2*r, 2*r, 4) + Gdip_SetClipRect(pGraphics, x-r, y+h-r, 2*r, 2*r, 4) + Gdip_SetClipRect(pGraphics, x+w-r, y+h-r, 2*r, 2*r, 4) + E := Gdip_DrawRectangle(pGraphics, pPen, x, y, w, h) + Gdip_ResetClip(pGraphics) + Gdip_SetClipRect(pGraphics, x-(2*r), y+r, w+(4*r), h-(2*r), 4) + Gdip_SetClipRect(pGraphics, x+r, y-(2*r), w-(2*r), h+(4*r), 4) + Gdip_DrawEllipse(pGraphics, pPen, x, y, 2*r, 2*r) + Gdip_DrawEllipse(pGraphics, pPen, x+w-(2*r), y, 2*r, 2*r) + Gdip_DrawEllipse(pGraphics, pPen, x, y+h-(2*r), 2*r, 2*r) + Gdip_DrawEllipse(pGraphics, pPen, x+w-(2*r), y+h-(2*r), 2*r, 2*r) + Gdip_ResetClip(pGraphics) + return E +} + +;##################################################################################### + +; Function Gdip_DrawEllipse +; Description This function uses a pen to draw the outline of an ellipse into the Graphics of a bitmap +; +; pGraphics Pointer to the Graphics of a bitmap +; pPen Pointer to a pen +; x x-coordinate of the top left of the rectangle the ellipse will be drawn into +; y y-coordinate of the top left of the rectangle the ellipse will be drawn into +; w width of the ellipse +; h height of the ellipse +; +; return status enumeration. 0 = success +; +; notes as all coordinates are taken from the top left of each pixel, then the entire width/height should be specified as subtracting the pen width + +Gdip_DrawEllipse(pGraphics, pPen, x, y, w, h) +{ + Ptr := A_PtrSize ? "UPtr" : "UInt" + + return DllCall("gdiplus\GdipDrawEllipse", Ptr, pGraphics, Ptr, pPen, "float", x, "float", y, "float", w, "float", h) +} + +;##################################################################################### + +; Function Gdip_DrawBezier +; Description This function uses a pen to draw the outline of a bezier (a weighted curve) into the Graphics of a bitmap +; +; pGraphics Pointer to the Graphics of a bitmap +; pPen Pointer to a pen +; x1 x-coordinate of the start of the bezier +; y1 y-coordinate of the start of the bezier +; x2 x-coordinate of the first arc of the bezier +; y2 y-coordinate of the first arc of the bezier +; x3 x-coordinate of the second arc of the bezier +; y3 y-coordinate of the second arc of the bezier +; x4 x-coordinate of the end of the bezier +; y4 y-coordinate of the end of the bezier +; +; return status enumeration. 0 = success +; +; notes as all coordinates are taken from the top left of each pixel, then the entire width/height should be specified as subtracting the pen width + +Gdip_DrawBezier(pGraphics, pPen, x1, y1, x2, y2, x3, y3, x4, y4) +{ + Ptr := A_PtrSize ? "UPtr" : "UInt" + + return DllCall("gdiplus\GdipDrawBezier" + , Ptr, pgraphics + , Ptr, pPen + , "float", x1 + , "float", y1 + , "float", x2 + , "float", y2 + , "float", x3 + , "float", y3 + , "float", x4 + , "float", y4) +} + +;##################################################################################### + +; Function Gdip_DrawArc +; Description This function uses a pen to draw the outline of an arc into the Graphics of a bitmap +; +; pGraphics Pointer to the Graphics of a bitmap +; pPen Pointer to a pen +; x x-coordinate of the start of the arc +; y y-coordinate of the start of the arc +; w width of the arc +; h height of the arc +; StartAngle specifies the angle between the x-axis and the starting point of the arc +; SweepAngle specifies the angle between the starting and ending points of the arc +; +; return status enumeration. 0 = success +; +; notes as all coordinates are taken from the top left of each pixel, then the entire width/height should be specified as subtracting the pen width + +Gdip_DrawArc(pGraphics, pPen, x, y, w, h, StartAngle, SweepAngle) +{ + Ptr := A_PtrSize ? "UPtr" : "UInt" + + return DllCall("gdiplus\GdipDrawArc" + , Ptr, pGraphics + , Ptr, pPen + , "float", x + , "float", y + , "float", w + , "float", h + , "float", StartAngle + , "float", SweepAngle) +} + +;##################################################################################### + +; Function Gdip_DrawPie +; Description This function uses a pen to draw the outline of a pie into the Graphics of a bitmap +; +; pGraphics Pointer to the Graphics of a bitmap +; pPen Pointer to a pen +; x x-coordinate of the start of the pie +; y y-coordinate of the start of the pie +; w width of the pie +; h height of the pie +; StartAngle specifies the angle between the x-axis and the starting point of the pie +; SweepAngle specifies the angle between the starting and ending points of the pie +; +; return status enumeration. 0 = success +; +; notes as all coordinates are taken from the top left of each pixel, then the entire width/height should be specified as subtracting the pen width + +Gdip_DrawPie(pGraphics, pPen, x, y, w, h, StartAngle, SweepAngle) +{ + Ptr := A_PtrSize ? "UPtr" : "UInt" + + return DllCall("gdiplus\GdipDrawPie", Ptr, pGraphics, Ptr, pPen, "float", x, "float", y, "float", w, "float", h, "float", StartAngle, "float", SweepAngle) +} + +;##################################################################################### + +; Function Gdip_DrawLine +; Description This function uses a pen to draw a line into the Graphics of a bitmap +; +; pGraphics Pointer to the Graphics of a bitmap +; pPen Pointer to a pen +; x1 x-coordinate of the start of the line +; y1 y-coordinate of the start of the line +; x2 x-coordinate of the end of the line +; y2 y-coordinate of the end of the line +; +; return status enumeration. 0 = success + +Gdip_DrawLine(pGraphics, pPen, x1, y1, x2, y2) +{ + Ptr := A_PtrSize ? "UPtr" : "UInt" + + return DllCall("gdiplus\GdipDrawLine" + , Ptr, pGraphics + , Ptr, pPen + , "float", x1 + , "float", y1 + , "float", x2 + , "float", y2) +} + +;##################################################################################### + +; Function Gdip_DrawLines +; Description This function uses a pen to draw a series of joined lines into the Graphics of a bitmap +; +; pGraphics Pointer to the Graphics of a bitmap +; pPen Pointer to a pen +; Points the coordinates of all the points passed as x1,y1|x2,y2|x3,y3..... +; +; return status enumeration. 0 = success + +Gdip_DrawLines(pGraphics, pPen, Points) +{ + Ptr := A_PtrSize ? "UPtr" : "UInt" + StringSplit, Points, Points, | + VarSetCapacity(PointF, 8*Points0) + Loop, %Points0% + { + StringSplit, Coord, Points%A_Index%, `, + NumPut(Coord1, PointF, 8*(A_Index-1), "float"), NumPut(Coord2, PointF, (8*(A_Index-1))+4, "float") + } + return DllCall("gdiplus\GdipDrawLines", Ptr, pGraphics, Ptr, pPen, Ptr, &PointF, "int", Points0) +} + +;##################################################################################### + +; Function Gdip_FillRectangle +; Description This function uses a brush to fill a rectangle in the Graphics of a bitmap +; +; pGraphics Pointer to the Graphics of a bitmap +; pBrush Pointer to a brush +; x x-coordinate of the top left of the rectangle +; y y-coordinate of the top left of the rectangle +; w width of the rectanlge +; h height of the rectangle +; +; return status enumeration. 0 = success + +Gdip_FillRectangle(pGraphics, pBrush, x, y, w, h) +{ + Ptr := A_PtrSize ? "UPtr" : "UInt" + + return DllCall("gdiplus\GdipFillRectangle" + , Ptr, pGraphics + , Ptr, pBrush + , "float", x + , "float", y + , "float", w + , "float", h) +} + +;##################################################################################### + +; Function Gdip_FillRoundedRectangle +; Description This function uses a brush to fill a rounded rectangle in the Graphics of a bitmap +; +; pGraphics Pointer to the Graphics of a bitmap +; pBrush Pointer to a brush +; x x-coordinate of the top left of the rounded rectangle +; y y-coordinate of the top left of the rounded rectangle +; w width of the rectanlge +; h height of the rectangle +; r radius of the rounded corners +; +; return status enumeration. 0 = success + +Gdip_FillRoundedRectangle(pGraphics, pBrush, x, y, w, h, r) +{ + Region := Gdip_GetClipRegion(pGraphics) + Gdip_SetClipRect(pGraphics, x-r, y-r, 2*r, 2*r, 4) + Gdip_SetClipRect(pGraphics, x+w-r, y-r, 2*r, 2*r, 4) + Gdip_SetClipRect(pGraphics, x-r, y+h-r, 2*r, 2*r, 4) + Gdip_SetClipRect(pGraphics, x+w-r, y+h-r, 2*r, 2*r, 4) + E := Gdip_FillRectangle(pGraphics, pBrush, x, y, w, h) + Gdip_SetClipRegion(pGraphics, Region, 0) + Gdip_SetClipRect(pGraphics, x-(2*r), y+r, w+(4*r), h-(2*r), 4) + Gdip_SetClipRect(pGraphics, x+r, y-(2*r), w-(2*r), h+(4*r), 4) + Gdip_FillEllipse(pGraphics, pBrush, x, y, 2*r, 2*r) + Gdip_FillEllipse(pGraphics, pBrush, x+w-(2*r), y, 2*r, 2*r) + Gdip_FillEllipse(pGraphics, pBrush, x, y+h-(2*r), 2*r, 2*r) + Gdip_FillEllipse(pGraphics, pBrush, x+w-(2*r), y+h-(2*r), 2*r, 2*r) + Gdip_SetClipRegion(pGraphics, Region, 0) + Gdip_DeleteRegion(Region) + return E +} + +;##################################################################################### + +; Function Gdip_FillPolygon +; Description This function uses a brush to fill a polygon in the Graphics of a bitmap +; +; pGraphics Pointer to the Graphics of a bitmap +; pBrush Pointer to a brush +; Points the coordinates of all the points passed as x1,y1|x2,y2|x3,y3..... +; +; return status enumeration. 0 = success +; +; notes Alternate will fill the polygon as a whole, wheras winding will fill each new "segment" +; Alternate = 0 +; Winding = 1 + +Gdip_FillPolygon(pGraphics, pBrush, Points, FillMode=0) +{ + Ptr := A_PtrSize ? "UPtr" : "UInt" + + StringSplit, Points, Points, | + VarSetCapacity(PointF, 8*Points0) + Loop, %Points0% + { + StringSplit, Coord, Points%A_Index%, `, + NumPut(Coord1, PointF, 8*(A_Index-1), "float"), NumPut(Coord2, PointF, (8*(A_Index-1))+4, "float") + } + return DllCall("gdiplus\GdipFillPolygon", Ptr, pGraphics, Ptr, pBrush, Ptr, &PointF, "int", Points0, "int", FillMode) +} + +;##################################################################################### + +; Function Gdip_FillPie +; Description This function uses a brush to fill a pie in the Graphics of a bitmap +; +; pGraphics Pointer to the Graphics of a bitmap +; pBrush Pointer to a brush +; x x-coordinate of the top left of the pie +; y y-coordinate of the top left of the pie +; w width of the pie +; h height of the pie +; StartAngle specifies the angle between the x-axis and the starting point of the pie +; SweepAngle specifies the angle between the starting and ending points of the pie +; +; return status enumeration. 0 = success + +Gdip_FillPie(pGraphics, pBrush, x, y, w, h, StartAngle, SweepAngle) +{ + Ptr := A_PtrSize ? "UPtr" : "UInt" + + return DllCall("gdiplus\GdipFillPie" + , Ptr, pGraphics + , Ptr, pBrush + , "float", x + , "float", y + , "float", w + , "float", h + , "float", StartAngle + , "float", SweepAngle) +} + +;##################################################################################### + +; Function Gdip_FillEllipse +; Description This function uses a brush to fill an ellipse in the Graphics of a bitmap +; +; pGraphics Pointer to the Graphics of a bitmap +; pBrush Pointer to a brush +; x x-coordinate of the top left of the ellipse +; y y-coordinate of the top left of the ellipse +; w width of the ellipse +; h height of the ellipse +; +; return status enumeration. 0 = success + +Gdip_FillEllipse(pGraphics, pBrush, x, y, w, h) +{ + Ptr := A_PtrSize ? "UPtr" : "UInt" + + return DllCall("gdiplus\GdipFillEllipse", Ptr, pGraphics, Ptr, pBrush, "float", x, "float", y, "float", w, "float", h) +} + +;##################################################################################### + +; Function Gdip_FillRegion +; Description This function uses a brush to fill a region in the Graphics of a bitmap +; +; pGraphics Pointer to the Graphics of a bitmap +; pBrush Pointer to a brush +; Region Pointer to a Region +; +; return status enumeration. 0 = success +; +; notes You can create a region Gdip_CreateRegion() and then add to this + +Gdip_FillRegion(pGraphics, pBrush, Region) +{ + Ptr := A_PtrSize ? "UPtr" : "UInt" + + return DllCall("gdiplus\GdipFillRegion", Ptr, pGraphics, Ptr, pBrush, Ptr, Region) +} + +;##################################################################################### + +; Function Gdip_FillPath +; Description This function uses a brush to fill a path in the Graphics of a bitmap +; +; pGraphics Pointer to the Graphics of a bitmap +; pBrush Pointer to a brush +; Region Pointer to a Path +; +; return status enumeration. 0 = success + +Gdip_FillPath(pGraphics, pBrush, Path) +{ + Ptr := A_PtrSize ? "UPtr" : "UInt" + + return DllCall("gdiplus\GdipFillPath", Ptr, pGraphics, Ptr, pBrush, Ptr, Path) +} + +;##################################################################################### + +; Function Gdip_DrawImagePointsRect +; Description This function draws a bitmap into the Graphics of another bitmap and skews it +; +; pGraphics Pointer to the Graphics of a bitmap +; pBitmap Pointer to a bitmap to be drawn +; Points Points passed as x1,y1|x2,y2|x3,y3 (3 points: top left, top right, bottom left) describing the drawing of the bitmap +; sx x-coordinate of source upper-left corner +; sy y-coordinate of source upper-left corner +; sw width of source rectangle +; sh height of source rectangle +; Matrix a matrix used to alter image attributes when drawing +; +; return status enumeration. 0 = success +; +; notes if sx,sy,sw,sh are missed then the entire source bitmap will be used +; Matrix can be omitted to just draw with no alteration to ARGB +; Matrix may be passed as a digit from 0 - 1 to change just transparency +; Matrix can be passed as a matrix with any delimiter + +Gdip_DrawImagePointsRect(pGraphics, pBitmap, Points, sx="", sy="", sw="", sh="", Matrix=1) +{ + Ptr := A_PtrSize ? "UPtr" : "UInt" + + StringSplit, Points, Points, | + VarSetCapacity(PointF, 8*Points0) + Loop, %Points0% + { + StringSplit, Coord, Points%A_Index%, `, + NumPut(Coord1, PointF, 8*(A_Index-1), "float"), NumPut(Coord2, PointF, (8*(A_Index-1))+4, "float") + } + + if (Matrix&1 = "") + ImageAttr := Gdip_SetImageAttributesColorMatrix(Matrix) + else if (Matrix != 1) + ImageAttr := Gdip_SetImageAttributesColorMatrix("1|0|0|0|0|0|1|0|0|0|0|0|1|0|0|0|0|0|" Matrix "|0|0|0|0|0|1") + + if (sx = "" && sy = "" && sw = "" && sh = "") + { + sx := 0, sy := 0 + sw := Gdip_GetImageWidth(pBitmap) + sh := Gdip_GetImageHeight(pBitmap) + } + + E := DllCall("gdiplus\GdipDrawImagePointsRect" + , Ptr, pGraphics + , Ptr, pBitmap + , Ptr, &PointF + , "int", Points0 + , "float", sx + , "float", sy + , "float", sw + , "float", sh + , "int", 2 + , Ptr, ImageAttr + , Ptr, 0 + , Ptr, 0) + if ImageAttr + Gdip_DisposeImageAttributes(ImageAttr) + return E +} + +;##################################################################################### + +; Function Gdip_DrawImage +; Description This function draws a bitmap into the Graphics of another bitmap +; +; pGraphics Pointer to the Graphics of a bitmap +; pBitmap Pointer to a bitmap to be drawn +; dx x-coord of destination upper-left corner +; dy y-coord of destination upper-left corner +; dw width of destination image +; dh height of destination image +; sx x-coordinate of source upper-left corner +; sy y-coordinate of source upper-left corner +; sw width of source image +; sh height of source image +; Matrix a matrix used to alter image attributes when drawing +; +; return status enumeration. 0 = success +; +; notes if sx,sy,sw,sh are missed then the entire source bitmap will be used +; Gdip_DrawImage performs faster +; Matrix can be omitted to just draw with no alteration to ARGB +; Matrix may be passed as a digit from 0 - 1 to change just transparency +; Matrix can be passed as a matrix with any delimiter. For example: +; MatrixBright= +; ( +; 1.5 |0 |0 |0 |0 +; 0 |1.5 |0 |0 |0 +; 0 |0 |1.5 |0 |0 +; 0 |0 |0 |1 |0 +; 0.05 |0.05 |0.05 |0 |1 +; ) +; +; notes MatrixBright = 1.5|0|0|0|0|0|1.5|0|0|0|0|0|1.5|0|0|0|0|0|1|0|0.05|0.05|0.05|0|1 +; MatrixGreyScale = 0.299|0.299|0.299|0|0|0.587|0.587|0.587|0|0|0.114|0.114|0.114|0|0|0|0|0|1|0|0|0|0|0|1 +; MatrixNegative = -1|0|0|0|0|0|-1|0|0|0|0|0|-1|0|0|0|0|0|1|0|0|0|0|0|1 + +Gdip_DrawImage(pGraphics, pBitmap, dx="", dy="", dw="", dh="", sx="", sy="", sw="", sh="", Matrix=1) +{ + Ptr := A_PtrSize ? "UPtr" : "UInt" + + if (Matrix&1 = "") + ImageAttr := Gdip_SetImageAttributesColorMatrix(Matrix) + else if (Matrix != 1) + ImageAttr := Gdip_SetImageAttributesColorMatrix("1|0|0|0|0|0|1|0|0|0|0|0|1|0|0|0|0|0|" Matrix "|0|0|0|0|0|1") + + if (sx = "" && sy = "" && sw = "" && sh = "") + { + if (dx = "" && dy = "" && dw = "" && dh = "") + { + sx := dx := 0, sy := dy := 0 + sw := dw := Gdip_GetImageWidth(pBitmap) + sh := dh := Gdip_GetImageHeight(pBitmap) + } + else + { + sx := sy := 0 + sw := Gdip_GetImageWidth(pBitmap) + sh := Gdip_GetImageHeight(pBitmap) + } + } + + E := DllCall("gdiplus\GdipDrawImageRectRect" + , Ptr, pGraphics + , Ptr, pBitmap + , "float", dx + , "float", dy + , "float", dw + , "float", dh + , "float", sx + , "float", sy + , "float", sw + , "float", sh + , "int", 2 + , Ptr, ImageAttr + , Ptr, 0 + , Ptr, 0) + if ImageAttr + Gdip_DisposeImageAttributes(ImageAttr) + return E +} + +;##################################################################################### + +; Function Gdip_SetImageAttributesColorMatrix +; Description This function creates an image matrix ready for drawing +; +; Matrix a matrix used to alter image attributes when drawing +; passed with any delimeter +; +; return returns an image matrix on sucess or 0 if it fails +; +; notes MatrixBright = 1.5|0|0|0|0|0|1.5|0|0|0|0|0|1.5|0|0|0|0|0|1|0|0.05|0.05|0.05|0|1 +; MatrixGreyScale = 0.299|0.299|0.299|0|0|0.587|0.587|0.587|0|0|0.114|0.114|0.114|0|0|0|0|0|1|0|0|0|0|0|1 +; MatrixNegative = -1|0|0|0|0|0|-1|0|0|0|0|0|-1|0|0|0|0|0|1|0|0|0|0|0|1 + +Gdip_SetImageAttributesColorMatrix(Matrix) +{ + Ptr := A_PtrSize ? "UPtr" : "UInt" + + VarSetCapacity(ColourMatrix, 100, 0) + Matrix := RegExReplace(RegExReplace(Matrix, "^[^\d-\.]+([\d\.])", "$1", "", 1), "[^\d-\.]+", "|") + StringSplit, Matrix, Matrix, | + Loop, 25 + { + Matrix := (Matrix%A_Index% != "") ? Matrix%A_Index% : Mod(A_Index-1, 6) ? 0 : 1 + NumPut(Matrix, ColourMatrix, (A_Index-1)*4, "float") + } + DllCall("gdiplus\GdipCreateImageAttributes", A_PtrSize ? "UPtr*" : "uint*", ImageAttr) + DllCall("gdiplus\GdipSetImageAttributesColorMatrix", Ptr, ImageAttr, "int", 1, "int", 1, Ptr, &ColourMatrix, Ptr, 0, "int", 0) + return ImageAttr +} + +;##################################################################################### + +; Function Gdip_GraphicsFromImage +; Description This function gets the graphics for a bitmap used for drawing functions +; +; pBitmap Pointer to a bitmap to get the pointer to its graphics +; +; return returns a pointer to the graphics of a bitmap +; +; notes a bitmap can be drawn into the graphics of another bitmap + +Gdip_GraphicsFromImage(pBitmap) +{ + DllCall("gdiplus\GdipGetImageGraphicsContext", A_PtrSize ? "UPtr" : "UInt", pBitmap, A_PtrSize ? "UPtr*" : "UInt*", pGraphics) + return pGraphics +} + +;##################################################################################### + +; Function Gdip_GraphicsFromHDC +; Description This function gets the graphics from the handle to a device context +; +; hdc This is the handle to the device context +; +; return returns a pointer to the graphics of a bitmap +; +; notes You can draw a bitmap into the graphics of another bitmap + +Gdip_GraphicsFromHDC(hdc) +{ + DllCall("gdiplus\GdipCreateFromHDC", A_PtrSize ? "UPtr" : "UInt", hdc, A_PtrSize ? "UPtr*" : "UInt*", pGraphics) + return pGraphics +} + +;##################################################################################### + +; Function Gdip_GetDC +; Description This function gets the device context of the passed Graphics +; +; hdc This is the handle to the device context +; +; return returns the device context for the graphics of a bitmap + +Gdip_GetDC(pGraphics) +{ + DllCall("gdiplus\GdipGetDC", A_PtrSize ? "UPtr" : "UInt", pGraphics, A_PtrSize ? "UPtr*" : "UInt*", hdc) + return hdc +} + +;##################################################################################### + +; Function Gdip_ReleaseDC +; Description This function releases a device context from use for further use +; +; pGraphics Pointer to the graphics of a bitmap +; hdc This is the handle to the device context +; +; return status enumeration. 0 = success + +Gdip_ReleaseDC(pGraphics, hdc) +{ + Ptr := A_PtrSize ? "UPtr" : "UInt" + + return DllCall("gdiplus\GdipReleaseDC", Ptr, pGraphics, Ptr, hdc) +} + +;##################################################################################### + +; Function Gdip_GraphicsClear +; Description Clears the graphics of a bitmap ready for further drawing +; +; pGraphics Pointer to the graphics of a bitmap +; ARGB The colour to clear the graphics to +; +; return status enumeration. 0 = success +; +; notes By default this will make the background invisible +; Using clipping regions you can clear a particular area on the graphics rather than clearing the entire graphics + +Gdip_GraphicsClear(pGraphics, ARGB=0x00ffffff) +{ + return DllCall("gdiplus\GdipGraphicsClear", A_PtrSize ? "UPtr" : "UInt", pGraphics, "int", ARGB) +} + +;##################################################################################### + +; Function Gdip_BlurBitmap +; Description Gives a pointer to a blurred bitmap from a pointer to a bitmap +; +; pBitmap Pointer to a bitmap to be blurred +; Blur The Amount to blur a bitmap by from 1 (least blur) to 100 (most blur) +; +; return If the function succeeds, the return value is a pointer to the new blurred bitmap +; -1 = The blur parameter is outside the range 1-100 +; +; notes This function will not dispose of the original bitmap + +Gdip_BlurBitmap(pBitmap, Blur) +{ + if (Blur > 100) || (Blur < 1) + return -1 + + sWidth := Gdip_GetImageWidth(pBitmap), sHeight := Gdip_GetImageHeight(pBitmap) + dWidth := sWidth//Blur, dHeight := sHeight//Blur + + pBitmap1 := Gdip_CreateBitmap(dWidth, dHeight) + G1 := Gdip_GraphicsFromImage(pBitmap1) + Gdip_SetInterpolationMode(G1, 7) + Gdip_DrawImage(G1, pBitmap, 0, 0, dWidth, dHeight, 0, 0, sWidth, sHeight) + + Gdip_DeleteGraphics(G1) + + pBitmap2 := Gdip_CreateBitmap(sWidth, sHeight) + G2 := Gdip_GraphicsFromImage(pBitmap2) + Gdip_SetInterpolationMode(G2, 7) + Gdip_DrawImage(G2, pBitmap1, 0, 0, sWidth, sHeight, 0, 0, dWidth, dHeight) + + Gdip_DeleteGraphics(G2) + Gdip_DisposeImage(pBitmap1) + return pBitmap2 +} + +;##################################################################################### + +; Function: Gdip_SaveBitmapToFile +; Description: Saves a bitmap to a file in any supported format onto disk +; +; pBitmap Pointer to a bitmap +; sOutput The name of the file that the bitmap will be saved to. Supported extensions are: .BMP,.DIB,.RLE,.JPG,.JPEG,.JPE,.JFIF,.GIF,.TIF,.TIFF,.PNG +; Quality If saving as jpg (.JPG,.JPEG,.JPE,.JFIF) then quality can be 1-100 with default at maximum quality +; +; return If the function succeeds, the return value is zero, otherwise: +; -1 = Extension supplied is not a supported file format +; -2 = Could not get a list of encoders on system +; -3 = Could not find matching encoder for specified file format +; -4 = Could not get WideChar name of output file +; -5 = Could not save file to disk +; +; notes This function will use the extension supplied from the sOutput parameter to determine the output format + +Gdip_SaveBitmapToFile(pBitmap, sOutput, Quality=75) +{ + Ptr := A_PtrSize ? "UPtr" : "UInt" + + SplitPath, sOutput,,, Extension + if Extension not in BMP,DIB,RLE,JPG,JPEG,JPE,JFIF,GIF,TIF,TIFF,PNG + return -1 + Extension := "." Extension + + DllCall("gdiplus\GdipGetImageEncodersSize", "uint*", nCount, "uint*", nSize) + VarSetCapacity(ci, nSize) + DllCall("gdiplus\GdipGetImageEncoders", "uint", nCount, "uint", nSize, Ptr, &ci) + if !(nCount && nSize) + return -2 + + If (A_IsUnicode){ + StrGet_Name := "StrGet" + Loop, %nCount% + { + sString := %StrGet_Name%(NumGet(ci, (idx := (48+7*A_PtrSize)*(A_Index-1))+32+3*A_PtrSize), "UTF-16") + if !InStr(sString, "*" Extension) + continue + + pCodec := &ci+idx + break + } + } else { + Loop, %nCount% + { + Location := NumGet(ci, 76*(A_Index-1)+44) + nSize := DllCall("WideCharToMultiByte", "uint", 0, "uint", 0, "uint", Location, "int", -1, "uint", 0, "int", 0, "uint", 0, "uint", 0) + VarSetCapacity(sString, nSize) + DllCall("WideCharToMultiByte", "uint", 0, "uint", 0, "uint", Location, "int", -1, "str", sString, "int", nSize, "uint", 0, "uint", 0) + if !InStr(sString, "*" Extension) + continue + + pCodec := &ci+76*(A_Index-1) + break + } + } + + if !pCodec + return -3 + + if (Quality != 75) + { + Quality := (Quality < 0) ? 0 : (Quality > 100) ? 100 : Quality + if Extension in .JPG,.JPEG,.JPE,.JFIF + { + DllCall("gdiplus\GdipGetEncoderParameterListSize", Ptr, pBitmap, Ptr, pCodec, "uint*", nSize) + VarSetCapacity(EncoderParameters, nSize, 0) + DllCall("gdiplus\GdipGetEncoderParameterList", Ptr, pBitmap, Ptr, pCodec, "uint", nSize, Ptr, &EncoderParameters) + Loop, % NumGet(EncoderParameters, "UInt") ;% + { + elem := (24+(A_PtrSize ? A_PtrSize : 4))*(A_Index-1) + 4 + (pad := A_PtrSize = 8 ? 4 : 0) + if (NumGet(EncoderParameters, elem+16, "UInt") = 1) && (NumGet(EncoderParameters, elem+20, "UInt") = 6) + { + p := elem+&EncoderParameters-pad-4 + NumPut(Quality, NumGet(NumPut(4, NumPut(1, p+0)+20, "UInt")), "UInt") + break + } + } + } + } + + if (!A_IsUnicode) + { + nSize := DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, Ptr, &sOutput, "int", -1, Ptr, 0, "int", 0) + VarSetCapacity(wOutput, nSize*2) + DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, Ptr, &sOutput, "int", -1, Ptr, &wOutput, "int", nSize) + VarSetCapacity(wOutput, -1) + if !VarSetCapacity(wOutput) + return -4 + E := DllCall("gdiplus\GdipSaveImageToFile", Ptr, pBitmap, Ptr, &wOutput, Ptr, pCodec, "uint", p ? p : 0) + } + else + E := DllCall("gdiplus\GdipSaveImageToFile", Ptr, pBitmap, Ptr, &sOutput, Ptr, pCodec, "uint", p ? p : 0) + return E ? -5 : 0 +} + +;##################################################################################### + +; Function Gdip_GetPixel +; Description Gets the ARGB of a pixel in a bitmap +; +; pBitmap Pointer to a bitmap +; x x-coordinate of the pixel +; y y-coordinate of the pixel +; +; return Returns the ARGB value of the pixel + +Gdip_GetPixel(pBitmap, x, y) +{ + DllCall("gdiplus\GdipBitmapGetPixel", A_PtrSize ? "UPtr" : "UInt", pBitmap, "int", x, "int", y, "uint*", ARGB) + return ARGB +} + +;##################################################################################### + +; Function Gdip_SetPixel +; Description Sets the ARGB of a pixel in a bitmap +; +; pBitmap Pointer to a bitmap +; x x-coordinate of the pixel +; y y-coordinate of the pixel +; +; return status enumeration. 0 = success + +Gdip_SetPixel(pBitmap, x, y, ARGB) +{ + return DllCall("gdiplus\GdipBitmapSetPixel", A_PtrSize ? "UPtr" : "UInt", pBitmap, "int", x, "int", y, "int", ARGB) +} + +;##################################################################################### + +; Function Gdip_GetImageWidth +; Description Gives the width of a bitmap +; +; pBitmap Pointer to a bitmap +; +; return Returns the width in pixels of the supplied bitmap + +Gdip_GetImageWidth(pBitmap) +{ + DllCall("gdiplus\GdipGetImageWidth", A_PtrSize ? "UPtr" : "UInt", pBitmap, "uint*", Width) + return Width +} + +;##################################################################################### + +; Function Gdip_GetImageHeight +; Description Gives the height of a bitmap +; +; pBitmap Pointer to a bitmap +; +; return Returns the height in pixels of the supplied bitmap + +Gdip_GetImageHeight(pBitmap) +{ + DllCall("gdiplus\GdipGetImageHeight", A_PtrSize ? "UPtr" : "UInt", pBitmap, "uint*", Height) + return Height +} + +;##################################################################################### + +; Function Gdip_GetDimensions +; Description Gives the width and height of a bitmap +; +; pBitmap Pointer to a bitmap +; Width ByRef variable. This variable will be set to the width of the bitmap +; Height ByRef variable. This variable will be set to the height of the bitmap +; +; return No return value +; Gdip_GetDimensions(pBitmap, ThisWidth, ThisHeight) will set ThisWidth to the width and ThisHeight to the height + +Gdip_GetImageDimensions(pBitmap, ByRef Width, ByRef Height) +{ + Ptr := A_PtrSize ? "UPtr" : "UInt" + DllCall("gdiplus\GdipGetImageWidth", Ptr, pBitmap, "uint*", Width) + DllCall("gdiplus\GdipGetImageHeight", Ptr, pBitmap, "uint*", Height) +} + +;##################################################################################### + +Gdip_GetDimensions(pBitmap, ByRef Width, ByRef Height) +{ + Gdip_GetImageDimensions(pBitmap, Width, Height) +} + +;##################################################################################### + +Gdip_GetImagePixelFormat(pBitmap) +{ + DllCall("gdiplus\GdipGetImagePixelFormat", A_PtrSize ? "UPtr" : "UInt", pBitmap, A_PtrSize ? "UPtr*" : "UInt*", Format) + return Format +} + +;##################################################################################### + +; Function Gdip_GetDpiX +; Description Gives the horizontal dots per inch of the graphics of a bitmap +; +; pBitmap Pointer to a bitmap +; Width ByRef variable. This variable will be set to the width of the bitmap +; Height ByRef variable. This variable will be set to the height of the bitmap +; +; return No return value +; Gdip_GetDimensions(pBitmap, ThisWidth, ThisHeight) will set ThisWidth to the width and ThisHeight to the height + +Gdip_GetDpiX(pGraphics) +{ + DllCall("gdiplus\GdipGetDpiX", A_PtrSize ? "UPtr" : "uint", pGraphics, "float*", dpix) + return Round(dpix) +} + +;##################################################################################### + +Gdip_GetDpiY(pGraphics) +{ + DllCall("gdiplus\GdipGetDpiY", A_PtrSize ? "UPtr" : "uint", pGraphics, "float*", dpiy) + return Round(dpiy) +} + +;##################################################################################### + +Gdip_GetImageHorizontalResolution(pBitmap) +{ + DllCall("gdiplus\GdipGetImageHorizontalResolution", A_PtrSize ? "UPtr" : "uint", pBitmap, "float*", dpix) + return Round(dpix) +} + +;##################################################################################### + +Gdip_GetImageVerticalResolution(pBitmap) +{ + DllCall("gdiplus\GdipGetImageVerticalResolution", A_PtrSize ? "UPtr" : "uint", pBitmap, "float*", dpiy) + return Round(dpiy) +} + +;##################################################################################### + +Gdip_BitmapSetResolution(pBitmap, dpix, dpiy) +{ + return DllCall("gdiplus\GdipBitmapSetResolution", A_PtrSize ? "UPtr" : "uint", pBitmap, "float", dpix, "float", dpiy) +} + +;##################################################################################### + +Gdip_CreateBitmapFromFile(sFile, IconNumber=1, IconSize="") +{ + Ptr := A_PtrSize ? "UPtr" : "UInt" + , PtrA := A_PtrSize ? "UPtr*" : "UInt*" + + SplitPath, sFile,,, ext + if ext in exe,dll + { + Sizes := IconSize ? IconSize : 256 "|" 128 "|" 64 "|" 48 "|" 32 "|" 16 + BufSize := 16 + (2*(A_PtrSize ? A_PtrSize : 4)) + + VarSetCapacity(buf, BufSize, 0) + Loop, Parse, Sizes, | + { + DllCall("PrivateExtractIcons", "str", sFile, "int", IconNumber-1, "int", A_LoopField, "int", A_LoopField, PtrA, hIcon, PtrA, 0, "uint", 1, "uint", 0) + + if !hIcon + continue + + if !DllCall("GetIconInfo", Ptr, hIcon, Ptr, &buf) + { + DestroyIcon(hIcon) + continue + } + + hbmMask := NumGet(buf, 12 + ((A_PtrSize ? A_PtrSize : 4) - 4)) + hbmColor := NumGet(buf, 12 + ((A_PtrSize ? A_PtrSize : 4) - 4) + (A_PtrSize ? A_PtrSize : 4)) + if !(hbmColor && DllCall("GetObject", Ptr, hbmColor, "int", BufSize, Ptr, &buf)) + { + DestroyIcon(hIcon) + continue + } + break + } + if !hIcon + return -1 + + Width := NumGet(buf, 4, "int"), Height := NumGet(buf, 8, "int") + hbm := CreateDIBSection(Width, -Height), hdc := CreateCompatibleDC(), obm := SelectObject(hdc, hbm) + if !DllCall("DrawIconEx", Ptr, hdc, "int", 0, "int", 0, Ptr, hIcon, "uint", Width, "uint", Height, "uint", 0, Ptr, 0, "uint", 3) + { + DestroyIcon(hIcon) + return -2 + } + + VarSetCapacity(dib, 104) + DllCall("GetObject", Ptr, hbm, "int", A_PtrSize = 8 ? 104 : 84, Ptr, &dib) ; sizeof(DIBSECTION) = 76+2*(A_PtrSize=8?4:0)+2*A_PtrSize + Stride := NumGet(dib, 12, "Int"), Bits := NumGet(dib, 20 + (A_PtrSize = 8 ? 4 : 0)) ; padding + DllCall("gdiplus\GdipCreateBitmapFromScan0", "int", Width, "int", Height, "int", Stride, "int", 0x26200A, Ptr, Bits, PtrA, pBitmapOld) + pBitmap := Gdip_CreateBitmap(Width, Height) + G := Gdip_GraphicsFromImage(pBitmap) + , Gdip_DrawImage(G, pBitmapOld, 0, 0, Width, Height, 0, 0, Width, Height) + SelectObject(hdc, obm), DeleteObject(hbm), DeleteDC(hdc) + Gdip_DeleteGraphics(G), Gdip_DisposeImage(pBitmapOld) + DestroyIcon(hIcon) + } + else + { + if (!A_IsUnicode) + { + VarSetCapacity(wFile, 1024) + DllCall("kernel32\MultiByteToWideChar", "uint", 0, "uint", 0, Ptr, &sFile, "int", -1, Ptr, &wFile, "int", 512) + DllCall("gdiplus\GdipCreateBitmapFromFile", Ptr, &wFile, PtrA, pBitmap) + } + else + DllCall("gdiplus\GdipCreateBitmapFromFile", Ptr, &sFile, PtrA, pBitmap) + } + + return pBitmap +} + +;##################################################################################### + +Gdip_CreateBitmapFromHBITMAP(hBitmap, Palette=0) +{ + Ptr := A_PtrSize ? "UPtr" : "UInt" + + DllCall("gdiplus\GdipCreateBitmapFromHBITMAP", Ptr, hBitmap, Ptr, Palette, A_PtrSize ? "UPtr*" : "uint*", pBitmap) + return pBitmap +} + +;##################################################################################### + +Gdip_CreateHBITMAPFromBitmap(pBitmap, Background=0xffffffff) +{ + DllCall("gdiplus\GdipCreateHBITMAPFromBitmap", A_PtrSize ? "UPtr" : "UInt", pBitmap, A_PtrSize ? "UPtr*" : "uint*", hbm, "int", Background) + return hbm +} + +;##################################################################################### + +Gdip_CreateBitmapFromHICON(hIcon) +{ + DllCall("gdiplus\GdipCreateBitmapFromHICON", A_PtrSize ? "UPtr" : "UInt", hIcon, A_PtrSize ? "UPtr*" : "uint*", pBitmap) + return pBitmap +} + +;##################################################################################### + +Gdip_CreateHICONFromBitmap(pBitmap) +{ + DllCall("gdiplus\GdipCreateHICONFromBitmap", A_PtrSize ? "UPtr" : "UInt", pBitmap, A_PtrSize ? "UPtr*" : "uint*", hIcon) + return hIcon +} + +;##################################################################################### + +Gdip_CreateBitmap(Width, Height, Format=0x26200A) +{ + DllCall("gdiplus\GdipCreateBitmapFromScan0", "int", Width, "int", Height, "int", 0, "int", Format, A_PtrSize ? "UPtr" : "UInt", 0, A_PtrSize ? "UPtr*" : "uint*", pBitmap) + Return pBitmap +} + +;##################################################################################### + +Gdip_CreateBitmapFromClipboard() +{ + Ptr := A_PtrSize ? "UPtr" : "UInt" + + if !DllCall("OpenClipboard", Ptr, 0) + return -1 + if !DllCall("IsClipboardFormatAvailable", "uint", 8) + return -2 + if !hBitmap := DllCall("GetClipboardData", "uint", 2, Ptr) + return -3 + if !pBitmap := Gdip_CreateBitmapFromHBITMAP(hBitmap) + return -4 + if !DllCall("CloseClipboard") + return -5 + DeleteObject(hBitmap) + return pBitmap +} + +;##################################################################################### + +Gdip_SetBitmapToClipboard(pBitmap) +{ + Ptr := A_PtrSize ? "UPtr" : "UInt" + off1 := A_PtrSize = 8 ? 52 : 44, off2 := A_PtrSize = 8 ? 32 : 24 + hBitmap := Gdip_CreateHBITMAPFromBitmap(pBitmap) + DllCall("GetObject", Ptr, hBitmap, "int", VarSetCapacity(oi, A_PtrSize = 8 ? 104 : 84, 0), Ptr, &oi) + hdib := DllCall("GlobalAlloc", "uint", 2, Ptr, 40+NumGet(oi, off1, "UInt"), Ptr) + pdib := DllCall("GlobalLock", Ptr, hdib, Ptr) + DllCall("RtlMoveMemory", Ptr, pdib, Ptr, &oi+off2, Ptr, 40) + DllCall("RtlMoveMemory", Ptr, pdib+40, Ptr, NumGet(oi, off2 - (A_PtrSize ? A_PtrSize : 4), Ptr), Ptr, NumGet(oi, off1, "UInt")) + DllCall("GlobalUnlock", Ptr, hdib) + DllCall("DeleteObject", Ptr, hBitmap) + DllCall("OpenClipboard", Ptr, 0) + DllCall("EmptyClipboard") + DllCall("SetClipboardData", "uint", 8, Ptr, hdib) + DllCall("CloseClipboard") +} + +;##################################################################################### + +Gdip_CloneBitmapArea(pBitmap, x, y, w, h, Format=0x26200A) +{ + DllCall("gdiplus\GdipCloneBitmapArea" + , "float", x + , "float", y + , "float", w + , "float", h + , "int", Format + , A_PtrSize ? "UPtr" : "UInt", pBitmap + , A_PtrSize ? "UPtr*" : "UInt*", pBitmapDest) + return pBitmapDest +} + +;##################################################################################### +; Create resources +;##################################################################################### + +Gdip_CreatePen(ARGB, w) +{ + DllCall("gdiplus\GdipCreatePen1", "UInt", ARGB, "float", w, "int", 2, A_PtrSize ? "UPtr*" : "UInt*", pPen) + return pPen +} + +;##################################################################################### + +Gdip_CreatePenFromBrush(pBrush, w) +{ + DllCall("gdiplus\GdipCreatePen2", A_PtrSize ? "UPtr" : "UInt", pBrush, "float", w, "int", 2, A_PtrSize ? "UPtr*" : "UInt*", pPen) + return pPen +} + +;##################################################################################### + +Gdip_BrushCreateSolid(ARGB=0xff000000) +{ + DllCall("gdiplus\GdipCreateSolidFill", "UInt", ARGB, A_PtrSize ? "UPtr*" : "UInt*", pBrush) + return pBrush +} + +;##################################################################################### + +; HatchStyleHorizontal = 0 +; HatchStyleVertical = 1 +; HatchStyleForwardDiagonal = 2 +; HatchStyleBackwardDiagonal = 3 +; HatchStyleCross = 4 +; HatchStyleDiagonalCross = 5 +; HatchStyle05Percent = 6 +; HatchStyle10Percent = 7 +; HatchStyle20Percent = 8 +; HatchStyle25Percent = 9 +; HatchStyle30Percent = 10 +; HatchStyle40Percent = 11 +; HatchStyle50Percent = 12 +; HatchStyle60Percent = 13 +; HatchStyle70Percent = 14 +; HatchStyle75Percent = 15 +; HatchStyle80Percent = 16 +; HatchStyle90Percent = 17 +; HatchStyleLightDownwardDiagonal = 18 +; HatchStyleLightUpwardDiagonal = 19 +; HatchStyleDarkDownwardDiagonal = 20 +; HatchStyleDarkUpwardDiagonal = 21 +; HatchStyleWideDownwardDiagonal = 22 +; HatchStyleWideUpwardDiagonal = 23 +; HatchStyleLightVertical = 24 +; HatchStyleLightHorizontal = 25 +; HatchStyleNarrowVertical = 26 +; HatchStyleNarrowHorizontal = 27 +; HatchStyleDarkVertical = 28 +; HatchStyleDarkHorizontal = 29 +; HatchStyleDashedDownwardDiagonal = 30 +; HatchStyleDashedUpwardDiagonal = 31 +; HatchStyleDashedHorizontal = 32 +; HatchStyleDashedVertical = 33 +; HatchStyleSmallConfetti = 34 +; HatchStyleLargeConfetti = 35 +; HatchStyleZigZag = 36 +; HatchStyleWave = 37 +; HatchStyleDiagonalBrick = 38 +; HatchStyleHorizontalBrick = 39 +; HatchStyleWeave = 40 +; HatchStylePlaid = 41 +; HatchStyleDivot = 42 +; HatchStyleDottedGrid = 43 +; HatchStyleDottedDiamond = 44 +; HatchStyleShingle = 45 +; HatchStyleTrellis = 46 +; HatchStyleSphere = 47 +; HatchStyleSmallGrid = 48 +; HatchStyleSmallCheckerBoard = 49 +; HatchStyleLargeCheckerBoard = 50 +; HatchStyleOutlinedDiamond = 51 +; HatchStyleSolidDiamond = 52 +; HatchStyleTotal = 53 +Gdip_BrushCreateHatch(ARGBfront, ARGBback, HatchStyle=0) +{ + DllCall("gdiplus\GdipCreateHatchBrush", "int", HatchStyle, "UInt", ARGBfront, "UInt", ARGBback, A_PtrSize ? "UPtr*" : "UInt*", pBrush) + return pBrush +} + +;##################################################################################### + +Gdip_CreateTextureBrush(pBitmap, WrapMode=1, x=0, y=0, w="", h="") +{ + Ptr := A_PtrSize ? "UPtr" : "UInt" + , PtrA := A_PtrSize ? "UPtr*" : "UInt*" + + if !(w && h) + DllCall("gdiplus\GdipCreateTexture", Ptr, pBitmap, "int", WrapMode, PtrA, pBrush) + else + DllCall("gdiplus\GdipCreateTexture2", Ptr, pBitmap, "int", WrapMode, "float", x, "float", y, "float", w, "float", h, PtrA, pBrush) + return pBrush +} + +;##################################################################################### + +; WrapModeTile = 0 +; WrapModeTileFlipX = 1 +; WrapModeTileFlipY = 2 +; WrapModeTileFlipXY = 3 +; WrapModeClamp = 4 +Gdip_CreateLineBrush(x1, y1, x2, y2, ARGB1, ARGB2, WrapMode=1) +{ + Ptr := A_PtrSize ? "UPtr" : "UInt" + + CreatePointF(PointF1, x1, y1), CreatePointF(PointF2, x2, y2) + DllCall("gdiplus\GdipCreateLineBrush", Ptr, &PointF1, Ptr, &PointF2, "Uint", ARGB1, "Uint", ARGB2, "int", WrapMode, A_PtrSize ? "UPtr*" : "UInt*", LGpBrush) + return LGpBrush +} + +;##################################################################################### + +; LinearGradientModeHorizontal = 0 +; LinearGradientModeVertical = 1 +; LinearGradientModeForwardDiagonal = 2 +; LinearGradientModeBackwardDiagonal = 3 +Gdip_CreateLineBrushFromRect(x, y, w, h, ARGB1, ARGB2, LinearGradientMode=1, WrapMode=1) +{ + CreateRectF(RectF, x, y, w, h) + DllCall("gdiplus\GdipCreateLineBrushFromRect", A_PtrSize ? "UPtr" : "UInt", &RectF, "int", ARGB1, "int", ARGB2, "int", LinearGradientMode, "int", WrapMode, A_PtrSize ? "UPtr*" : "UInt*", LGpBrush) + return LGpBrush +} + +;##################################################################################### + +Gdip_CloneBrush(pBrush) +{ + DllCall("gdiplus\GdipCloneBrush", A_PtrSize ? "UPtr" : "UInt", pBrush, A_PtrSize ? "UPtr*" : "UInt*", pBrushClone) + return pBrushClone +} + +;##################################################################################### +; Delete resources +;##################################################################################### + +Gdip_DeletePen(pPen) +{ + return DllCall("gdiplus\GdipDeletePen", A_PtrSize ? "UPtr" : "UInt", pPen) +} + +;##################################################################################### + +Gdip_DeleteBrush(pBrush) +{ + return DllCall("gdiplus\GdipDeleteBrush", A_PtrSize ? "UPtr" : "UInt", pBrush) +} + +;##################################################################################### + +Gdip_DisposeImage(pBitmap) +{ + return DllCall("gdiplus\GdipDisposeImage", A_PtrSize ? "UPtr" : "UInt", pBitmap) +} + +;##################################################################################### + +Gdip_DeleteGraphics(pGraphics) +{ + return DllCall("gdiplus\GdipDeleteGraphics", A_PtrSize ? "UPtr" : "UInt", pGraphics) +} + +;##################################################################################### + +Gdip_DisposeImageAttributes(ImageAttr) +{ + return DllCall("gdiplus\GdipDisposeImageAttributes", A_PtrSize ? "UPtr" : "UInt", ImageAttr) +} + +;##################################################################################### + +Gdip_DeleteFont(hFont) +{ + return DllCall("gdiplus\GdipDeleteFont", A_PtrSize ? "UPtr" : "UInt", hFont) +} + +;##################################################################################### + +Gdip_DeleteStringFormat(hFormat) +{ + return DllCall("gdiplus\GdipDeleteStringFormat", A_PtrSize ? "UPtr" : "UInt", hFormat) +} + +;##################################################################################### + +Gdip_DeleteFontFamily(hFamily) +{ + return DllCall("gdiplus\GdipDeleteFontFamily", A_PtrSize ? "UPtr" : "UInt", hFamily) +} + +;##################################################################################### + +Gdip_DeleteMatrix(Matrix) +{ + return DllCall("gdiplus\GdipDeleteMatrix", A_PtrSize ? "UPtr" : "UInt", Matrix) +} + +;##################################################################################### +; Text functions +;##################################################################################### + +Gdip_TextToGraphics(pGraphics, Text, Options, Font="Arial", Width="", Height="", Measure=0) +{ + IWidth := Width, IHeight:= Height + + RegExMatch(Options, "i)X([\-\d\.]+)(p*)", xpos) + RegExMatch(Options, "i)Y([\-\d\.]+)(p*)", ypos) + RegExMatch(Options, "i)W([\-\d\.]+)(p*)", Width) + RegExMatch(Options, "i)H([\-\d\.]+)(p*)", Height) + RegExMatch(Options, "i)C(?!(entre|enter))([a-f\d]+)", Colour) + RegExMatch(Options, "i)Top|Up|Bottom|Down|vCentre|vCenter", vPos) + RegExMatch(Options, "i)NoWrap", NoWrap) + RegExMatch(Options, "i)R(\d)", Rendering) + RegExMatch(Options, "i)S(\d+)(p*)", Size) + + if !Gdip_DeleteBrush(Gdip_CloneBrush(Colour2)) + PassBrush := 1, pBrush := Colour2 + + if !(IWidth && IHeight) && (xpos2 || ypos2 || Width2 || Height2 || Size2) + return -1 + + Style := 0, Styles := "Regular|Bold|Italic|BoldItalic|Underline|Strikeout" + Loop, Parse, Styles, | + { + if RegExMatch(Options, "\b" A_loopField) + Style |= (A_LoopField != "StrikeOut") ? (A_Index-1) : 8 + } + + Align := 0, Alignments := "Near|Left|Centre|Center|Far|Right" + Loop, Parse, Alignments, | + { + if RegExMatch(Options, "\b" A_loopField) + Align |= A_Index//2.1 ; 0|0|1|1|2|2 + } + + xpos := (xpos1 != "") ? xpos2 ? IWidth*(xpos1/100) : xpos1 : 0 + ypos := (ypos1 != "") ? ypos2 ? IHeight*(ypos1/100) : ypos1 : 0 + Width := Width1 ? Width2 ? IWidth*(Width1/100) : Width1 : IWidth + Height := Height1 ? Height2 ? IHeight*(Height1/100) : Height1 : IHeight + if !PassBrush + Colour := "0x" (Colour2 ? Colour2 : "ff000000") + Rendering := ((Rendering1 >= 0) && (Rendering1 <= 5)) ? Rendering1 : 4 + Size := (Size1 > 0) ? Size2 ? IHeight*(Size1/100) : Size1 : 12 + + hFamily := Gdip_FontFamilyCreate(Font) + hFont := Gdip_FontCreate(hFamily, Size, Style) + FormatStyle := NoWrap ? 0x4000 | 0x1000 : 0x4000 + hFormat := Gdip_StringFormatCreate(FormatStyle) + pBrush := PassBrush ? pBrush : Gdip_BrushCreateSolid(Colour) + if !(hFamily && hFont && hFormat && pBrush && pGraphics) + return !pGraphics ? -2 : !hFamily ? -3 : !hFont ? -4 : !hFormat ? -5 : !pBrush ? -6 : 0 + + CreateRectF(RC, xpos, ypos, Width, Height) + Gdip_SetStringFormatAlign(hFormat, Align) + Gdip_SetTextRenderingHint(pGraphics, Rendering) + ReturnRC := Gdip_MeasureString(pGraphics, Text, hFont, hFormat, RC) + + if vPos + { + StringSplit, ReturnRC, ReturnRC, | + + if (vPos = "vCentre") || (vPos = "vCenter") + ypos += (Height-ReturnRC4)//2 + else if (vPos = "Top") || (vPos = "Up") + ypos := 0 + else if (vPos = "Bottom") || (vPos = "Down") + ypos := Height-ReturnRC4 + + CreateRectF(RC, xpos, ypos, Width, ReturnRC4) + ReturnRC := Gdip_MeasureString(pGraphics, Text, hFont, hFormat, RC) + } + + if !Measure + E := Gdip_DrawString(pGraphics, Text, hFont, hFormat, pBrush, RC) + + if !PassBrush + Gdip_DeleteBrush(pBrush) + Gdip_DeleteStringFormat(hFormat) + Gdip_DeleteFont(hFont) + Gdip_DeleteFontFamily(hFamily) + return E ? E : ReturnRC +} + +;##################################################################################### + +Gdip_DrawString(pGraphics, sString, hFont, hFormat, pBrush, ByRef RectF) +{ + Ptr := A_PtrSize ? "UPtr" : "UInt" + + if (!A_IsUnicode) + { + nSize := DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, Ptr, &sString, "int", -1, Ptr, 0, "int", 0) + VarSetCapacity(wString, nSize*2) + DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, Ptr, &sString, "int", -1, Ptr, &wString, "int", nSize) + } + + return DllCall("gdiplus\GdipDrawString" + , Ptr, pGraphics + , Ptr, A_IsUnicode ? &sString : &wString + , "int", -1 + , Ptr, hFont + , Ptr, &RectF + , Ptr, hFormat + , Ptr, pBrush) +} + +;##################################################################################### + +Gdip_MeasureString(pGraphics, sString, hFont, hFormat, ByRef RectF) +{ + Ptr := A_PtrSize ? "UPtr" : "UInt" + + VarSetCapacity(RC, 16) + if !A_IsUnicode + { + nSize := DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, Ptr, &sString, "int", -1, "uint", 0, "int", 0) + VarSetCapacity(wString, nSize*2) + DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, Ptr, &sString, "int", -1, Ptr, &wString, "int", nSize) + } + + DllCall("gdiplus\GdipMeasureString" + , Ptr, pGraphics + , Ptr, A_IsUnicode ? &sString : &wString + , "int", -1 + , Ptr, hFont + , Ptr, &RectF + , Ptr, hFormat + , Ptr, &RC + , "uint*", Chars + , "uint*", Lines) + + return &RC ? NumGet(RC, 0, "float") "|" NumGet(RC, 4, "float") "|" NumGet(RC, 8, "float") "|" NumGet(RC, 12, "float") "|" Chars "|" Lines : 0 +} + +; Near = 0 +; Center = 1 +; Far = 2 +Gdip_SetStringFormatAlign(hFormat, Align) +{ + return DllCall("gdiplus\GdipSetStringFormatAlign", A_PtrSize ? "UPtr" : "UInt", hFormat, "int", Align) +} + +; StringFormatFlagsDirectionRightToLeft = 0x00000001 +; StringFormatFlagsDirectionVertical = 0x00000002 +; StringFormatFlagsNoFitBlackBox = 0x00000004 +; StringFormatFlagsDisplayFormatControl = 0x00000020 +; StringFormatFlagsNoFontFallback = 0x00000400 +; StringFormatFlagsMeasureTrailingSpaces = 0x00000800 +; StringFormatFlagsNoWrap = 0x00001000 +; StringFormatFlagsLineLimit = 0x00002000 +; StringFormatFlagsNoClip = 0x00004000 +Gdip_StringFormatCreate(Format=0, Lang=0) +{ + DllCall("gdiplus\GdipCreateStringFormat", "int", Format, "int", Lang, A_PtrSize ? "UPtr*" : "UInt*", hFormat) + return hFormat +} + +; Regular = 0 +; Bold = 1 +; Italic = 2 +; BoldItalic = 3 +; Underline = 4 +; Strikeout = 8 +Gdip_FontCreate(hFamily, Size, Style=0) +{ + DllCall("gdiplus\GdipCreateFont", A_PtrSize ? "UPtr" : "UInt", hFamily, "float", Size, "int", Style, "int", 0, A_PtrSize ? "UPtr*" : "UInt*", hFont) + return hFont +} + +Gdip_FontFamilyCreate(Font) +{ + Ptr := A_PtrSize ? "UPtr" : "UInt" + + if (!A_IsUnicode) + { + nSize := DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, Ptr, &Font, "int", -1, "uint", 0, "int", 0) + VarSetCapacity(wFont, nSize*2) + DllCall("MultiByteToWideChar", "uint", 0, "uint", 0, Ptr, &Font, "int", -1, Ptr, &wFont, "int", nSize) + } + + DllCall("gdiplus\GdipCreateFontFamilyFromName" + , Ptr, A_IsUnicode ? &Font : &wFont + , "uint", 0 + , A_PtrSize ? "UPtr*" : "UInt*", hFamily) + + return hFamily +} + +;##################################################################################### +; Matrix functions +;##################################################################################### + +Gdip_CreateAffineMatrix(m11, m12, m21, m22, x, y) +{ + DllCall("gdiplus\GdipCreateMatrix2", "float", m11, "float", m12, "float", m21, "float", m22, "float", x, "float", y, A_PtrSize ? "UPtr*" : "UInt*", Matrix) + return Matrix +} + +Gdip_CreateMatrix() +{ + DllCall("gdiplus\GdipCreateMatrix", A_PtrSize ? "UPtr*" : "UInt*", Matrix) + return Matrix +} + +;##################################################################################### +; GraphicsPath functions +;##################################################################################### + +; Alternate = 0 +; Winding = 1 +Gdip_CreatePath(BrushMode=0) +{ + DllCall("gdiplus\GdipCreatePath", "int", BrushMode, A_PtrSize ? "UPtr*" : "UInt*", Path) + return Path +} + +Gdip_AddPathEllipse(Path, x, y, w, h) +{ + return DllCall("gdiplus\GdipAddPathEllipse", A_PtrSize ? "UPtr" : "UInt", Path, "float", x, "float", y, "float", w, "float", h) +} + +Gdip_AddPathPolygon(Path, Points) +{ + Ptr := A_PtrSize ? "UPtr" : "UInt" + + StringSplit, Points, Points, | + VarSetCapacity(PointF, 8*Points0) + Loop, %Points0% + { + StringSplit, Coord, Points%A_Index%, `, + NumPut(Coord1, PointF, 8*(A_Index-1), "float"), NumPut(Coord2, PointF, (8*(A_Index-1))+4, "float") + } + + return DllCall("gdiplus\GdipAddPathPolygon", Ptr, Path, Ptr, &PointF, "int", Points0) +} + +Gdip_DeletePath(Path) +{ + return DllCall("gdiplus\GdipDeletePath", A_PtrSize ? "UPtr" : "UInt", Path) +} + +;##################################################################################### +; Quality functions +;##################################################################################### + +; SystemDefault = 0 +; SingleBitPerPixelGridFit = 1 +; SingleBitPerPixel = 2 +; AntiAliasGridFit = 3 +; AntiAlias = 4 +Gdip_SetTextRenderingHint(pGraphics, RenderingHint) +{ + return DllCall("gdiplus\GdipSetTextRenderingHint", A_PtrSize ? "UPtr" : "UInt", pGraphics, "int", RenderingHint) +} + +; Default = 0 +; LowQuality = 1 +; HighQuality = 2 +; Bilinear = 3 +; Bicubic = 4 +; NearestNeighbor = 5 +; HighQualityBilinear = 6 +; HighQualityBicubic = 7 +Gdip_SetInterpolationMode(pGraphics, InterpolationMode) +{ + return DllCall("gdiplus\GdipSetInterpolationMode", A_PtrSize ? "UPtr" : "UInt", pGraphics, "int", InterpolationMode) +} + +; Default = 0 +; HighSpeed = 1 +; HighQuality = 2 +; None = 3 +; AntiAlias = 4 +Gdip_SetSmoothingMode(pGraphics, SmoothingMode) +{ + return DllCall("gdiplus\GdipSetSmoothingMode", A_PtrSize ? "UPtr" : "UInt", pGraphics, "int", SmoothingMode) +} + +; CompositingModeSourceOver = 0 (blended) +; CompositingModeSourceCopy = 1 (overwrite) +Gdip_SetCompositingMode(pGraphics, CompositingMode=0) +{ + return DllCall("gdiplus\GdipSetCompositingMode", A_PtrSize ? "UPtr" : "UInt", pGraphics, "int", CompositingMode) +} + +;##################################################################################### +; Extra functions +;##################################################################################### + +Gdip_Startup() +{ + Ptr := A_PtrSize ? "UPtr" : "UInt" + + if !DllCall("GetModuleHandle", "str", "gdiplus", Ptr) + DllCall("LoadLibrary", "str", "gdiplus") + VarSetCapacity(si, A_PtrSize = 8 ? 24 : 16, 0), si := Chr(1) + DllCall("gdiplus\GdiplusStartup", A_PtrSize ? "UPtr*" : "uint*", pToken, Ptr, &si, Ptr, 0) + return pToken +} + +Gdip_Shutdown(pToken) +{ + Ptr := A_PtrSize ? "UPtr" : "UInt" + + DllCall("gdiplus\GdiplusShutdown", Ptr, pToken) + if hModule := DllCall("GetModuleHandle", "str", "gdiplus", Ptr) + DllCall("FreeLibrary", Ptr, hModule) + return 0 +} + +; Prepend = 0; The new operation is applied before the old operation. +; Append = 1; The new operation is applied after the old operation. +Gdip_RotateWorldTransform(pGraphics, Angle, MatrixOrder=0) +{ + return DllCall("gdiplus\GdipRotateWorldTransform", A_PtrSize ? "UPtr" : "UInt", pGraphics, "float", Angle, "int", MatrixOrder) +} + +Gdip_ScaleWorldTransform(pGraphics, x, y, MatrixOrder=0) +{ + return DllCall("gdiplus\GdipScaleWorldTransform", A_PtrSize ? "UPtr" : "UInt", pGraphics, "float", x, "float", y, "int", MatrixOrder) +} + +Gdip_TranslateWorldTransform(pGraphics, x, y, MatrixOrder=0) +{ + return DllCall("gdiplus\GdipTranslateWorldTransform", A_PtrSize ? "UPtr" : "UInt", pGraphics, "float", x, "float", y, "int", MatrixOrder) +} + +Gdip_ResetWorldTransform(pGraphics) +{ + return DllCall("gdiplus\GdipResetWorldTransform", A_PtrSize ? "UPtr" : "UInt", pGraphics) +} + +Gdip_GetRotatedTranslation(Width, Height, Angle, ByRef xTranslation, ByRef yTranslation) +{ + pi := 3.14159, TAngle := Angle*(pi/180) + + Bound := (Angle >= 0) ? Mod(Angle, 360) : 360-Mod(-Angle, -360) + if ((Bound >= 0) && (Bound <= 90)) + xTranslation := Height*Sin(TAngle), yTranslation := 0 + else if ((Bound > 90) && (Bound <= 180)) + xTranslation := (Height*Sin(TAngle))-(Width*Cos(TAngle)), yTranslation := -Height*Cos(TAngle) + else if ((Bound > 180) && (Bound <= 270)) + xTranslation := -(Width*Cos(TAngle)), yTranslation := -(Height*Cos(TAngle))-(Width*Sin(TAngle)) + else if ((Bound > 270) && (Bound <= 360)) + xTranslation := 0, yTranslation := -Width*Sin(TAngle) +} + +Gdip_GetRotatedDimensions(Width, Height, Angle, ByRef RWidth, ByRef RHeight) +{ + pi := 3.14159, TAngle := Angle*(pi/180) + if !(Width && Height) + return -1 + RWidth := Ceil(Abs(Width*Cos(TAngle))+Abs(Height*Sin(TAngle))) + RHeight := Ceil(Abs(Width*Sin(TAngle))+Abs(Height*Cos(Tangle))) +} + +; RotateNoneFlipNone = 0 +; Rotate90FlipNone = 1 +; Rotate180FlipNone = 2 +; Rotate270FlipNone = 3 +; RotateNoneFlipX = 4 +; Rotate90FlipX = 5 +; Rotate180FlipX = 6 +; Rotate270FlipX = 7 +; RotateNoneFlipY = Rotate180FlipX +; Rotate90FlipY = Rotate270FlipX +; Rotate180FlipY = RotateNoneFlipX +; Rotate270FlipY = Rotate90FlipX +; RotateNoneFlipXY = Rotate180FlipNone +; Rotate90FlipXY = Rotate270FlipNone +; Rotate180FlipXY = RotateNoneFlipNone +; Rotate270FlipXY = Rotate90FlipNone + +Gdip_ImageRotateFlip(pBitmap, RotateFlipType=1) +{ + return DllCall("gdiplus\GdipImageRotateFlip", A_PtrSize ? "UPtr" : "UInt", pBitmap, "int", RotateFlipType) +} + +; Replace = 0 +; Intersect = 1 +; Union = 2 +; Xor = 3 +; Exclude = 4 +; Complement = 5 +Gdip_SetClipRect(pGraphics, x, y, w, h, CombineMode=0) +{ + return DllCall("gdiplus\GdipSetClipRect", A_PtrSize ? "UPtr" : "UInt", pGraphics, "float", x, "float", y, "float", w, "float", h, "int", CombineMode) +} + +Gdip_SetClipPath(pGraphics, Path, CombineMode=0) +{ + Ptr := A_PtrSize ? "UPtr" : "UInt" + return DllCall("gdiplus\GdipSetClipPath", Ptr, pGraphics, Ptr, Path, "int", CombineMode) +} + +Gdip_ResetClip(pGraphics) +{ + return DllCall("gdiplus\GdipResetClip", A_PtrSize ? "UPtr" : "UInt", pGraphics) +} + +Gdip_GetClipRegion(pGraphics) +{ + Region := Gdip_CreateRegion() + DllCall("gdiplus\GdipGetClip", A_PtrSize ? "UPtr" : "UInt", pGraphics, "UInt*", Region) + return Region +} + +Gdip_SetClipRegion(pGraphics, Region, CombineMode=0) +{ + Ptr := A_PtrSize ? "UPtr" : "UInt" + + return DllCall("gdiplus\GdipSetClipRegion", Ptr, pGraphics, Ptr, Region, "int", CombineMode) +} + +Gdip_CreateRegion() +{ + DllCall("gdiplus\GdipCreateRegion", "UInt*", Region) + return Region +} + +Gdip_DeleteRegion(Region) +{ + return DllCall("gdiplus\GdipDeleteRegion", A_PtrSize ? "UPtr" : "UInt", Region) +} + +;##################################################################################### +; BitmapLockBits +;##################################################################################### + +Gdip_LockBits(pBitmap, x, y, w, h, ByRef Stride, ByRef Scan0, ByRef BitmapData, LockMode = 3, PixelFormat = 0x26200a) +{ + Ptr := A_PtrSize ? "UPtr" : "UInt" + + CreateRect(Rect, x, y, w, h) + VarSetCapacity(BitmapData, 16+2*(A_PtrSize ? A_PtrSize : 4), 0) + E := DllCall("Gdiplus\GdipBitmapLockBits", Ptr, pBitmap, Ptr, &Rect, "uint", LockMode, "int", PixelFormat, Ptr, &BitmapData) + Stride := NumGet(BitmapData, 8, "Int") + Scan0 := NumGet(BitmapData, 16, Ptr) + return E +} + +;##################################################################################### + +Gdip_UnlockBits(pBitmap, ByRef BitmapData) +{ + Ptr := A_PtrSize ? "UPtr" : "UInt" + + return DllCall("Gdiplus\GdipBitmapUnlockBits", Ptr, pBitmap, Ptr, &BitmapData) +} + +;##################################################################################### + +Gdip_SetLockBitPixel(ARGB, Scan0, x, y, Stride) +{ + Numput(ARGB, Scan0+0, (x*4)+(y*Stride), "UInt") +} + +;##################################################################################### + +Gdip_GetLockBitPixel(Scan0, x, y, Stride) +{ + return NumGet(Scan0+0, (x*4)+(y*Stride), "UInt") +} + +;##################################################################################### + +Gdip_PixelateBitmap(pBitmap, ByRef pBitmapOut, BlockSize) +{ + static PixelateBitmap + + Ptr := A_PtrSize ? "UPtr" : "UInt" + + if (!PixelateBitmap) + { + if A_PtrSize != 8 ; x86 machine code + MCode_PixelateBitmap = + (LTrim Join + 558BEC83EC3C8B4514538B5D1C99F7FB56578BC88955EC894DD885C90F8E830200008B451099F7FB8365DC008365E000894DC88955F08945E833FF897DD4 + 397DE80F8E160100008BCB0FAFCB894DCC33C08945F88945FC89451C8945143BD87E608B45088D50028BC82BCA8BF02BF2418945F48B45E02955F4894DC4 + 8D0CB80FAFCB03CA895DD08BD1895DE40FB64416030145140FB60201451C8B45C40FB604100145FC8B45F40FB604020145F883C204FF4DE475D6034D18FF + 4DD075C98B4DCC8B451499F7F98945148B451C99F7F989451C8B45FC99F7F98945FC8B45F899F7F98945F885DB7E648B450C8D50028BC82BCA83C103894D + C48BC82BCA41894DF48B4DD48945E48B45E02955E48D0C880FAFCB03CA895DD08BD18BF38A45148B7DC48804178A451C8B7DF488028A45FC8804178A45F8 + 8B7DE488043A83C2044E75DA034D18FF4DD075CE8B4DCC8B7DD447897DD43B7DE80F8CF2FEFFFF837DF0000F842C01000033C08945F88945FC89451C8945 + 148945E43BD87E65837DF0007E578B4DDC034DE48B75E80FAF4D180FAFF38B45088D500203CA8D0CB18BF08BF88945F48B45F02BF22BFA2955F48945CC0F + B6440E030145140FB60101451C0FB6440F010145FC8B45F40FB604010145F883C104FF4DCC75D8FF45E4395DE47C9B8B4DF00FAFCB85C9740B8B451499F7 + F9894514EB048365140033F63BCE740B8B451C99F7F989451CEB0389751C3BCE740B8B45FC99F7F98945FCEB038975FC3BCE740B8B45F899F7F98945F8EB + 038975F88975E43BDE7E5A837DF0007E4C8B4DDC034DE48B75E80FAF4D180FAFF38B450C8D500203CA8D0CB18BF08BF82BF22BFA2BC28B55F08955CC8A55 + 1488540E038A551C88118A55FC88540F018A55F888140183C104FF4DCC75DFFF45E4395DE47CA68B45180145E0015DDCFF4DC80F8594FDFFFF8B451099F7 + FB8955F08945E885C00F8E450100008B45EC0FAFC38365DC008945D48B45E88945CC33C08945F88945FC89451C8945148945103945EC7E6085DB7E518B4D + D88B45080FAFCB034D108D50020FAF4D18034DDC8BF08BF88945F403CA2BF22BFA2955F4895DC80FB6440E030145140FB60101451C0FB6440F010145FC8B + 45F40FB604080145F883C104FF4DC875D8FF45108B45103B45EC7CA08B4DD485C9740B8B451499F7F9894514EB048365140033F63BCE740B8B451C99F7F9 + 89451CEB0389751C3BCE740B8B45FC99F7F98945FCEB038975FC3BCE740B8B45F899F7F98945F8EB038975F88975103975EC7E5585DB7E468B4DD88B450C + 0FAFCB034D108D50020FAF4D18034DDC8BF08BF803CA2BF22BFA2BC2895DC88A551488540E038A551C88118A55FC88540F018A55F888140183C104FF4DC8 + 75DFFF45108B45103B45EC7CAB8BC3C1E0020145DCFF4DCC0F85CEFEFFFF8B4DEC33C08945F88945FC89451C8945148945103BC87E6C3945F07E5C8B4DD8 + 8B75E80FAFCB034D100FAFF30FAF4D188B45088D500203CA8D0CB18BF08BF88945F48B45F02BF22BFA2955F48945C80FB6440E030145140FB60101451C0F + B6440F010145FC8B45F40FB604010145F883C104FF4DC875D833C0FF45108B4DEC394D107C940FAF4DF03BC874068B451499F7F933F68945143BCE740B8B + 451C99F7F989451CEB0389751C3BCE740B8B45FC99F7F98945FCEB038975FC3BCE740B8B45F899F7F98945F8EB038975F88975083975EC7E63EB0233F639 + 75F07E4F8B4DD88B75E80FAFCB034D080FAFF30FAF4D188B450C8D500203CA8D0CB18BF08BF82BF22BFA2BC28B55F08955108A551488540E038A551C8811 + 8A55FC88540F018A55F888140883C104FF4D1075DFFF45088B45083B45EC7C9F5F5E33C05BC9C21800 + ) + else ; x64 machine code + MCode_PixelateBitmap = + (LTrim Join + 4489442418488954241048894C24085355565741544155415641574883EC28418BC1448B8C24980000004C8BDA99488BD941F7F9448BD0448BFA8954240C + 448994248800000085C00F8E9D020000418BC04533E4458BF299448924244C8954241041F7F933C9898C24980000008BEA89542404448BE889442408EB05 + 4C8B5C24784585ED0F8E1A010000458BF1418BFD48897C2418450FAFF14533D233F633ED4533E44533ED4585C97E5B4C63BC2490000000418D040A410FAF + C148984C8D441802498BD9498BD04D8BD90FB642010FB64AFF4403E80FB60203E90FB64AFE4883C2044403E003F149FFCB75DE4D03C748FFCB75D0488B7C + 24188B8C24980000004C8B5C2478418BC59941F7FE448BE8418BC49941F7FE448BE08BC59941F7FE8BE88BC69941F7FE8BF04585C97E4048639C24900000 + 004103CA4D8BC1410FAFC94863C94A8D541902488BCA498BC144886901448821408869FF408871FE4883C10448FFC875E84803D349FFC875DA8B8C249800 + 0000488B5C24704C8B5C24784183C20448FFCF48897C24180F850AFFFFFF8B6C2404448B2424448B6C24084C8B74241085ED0F840A01000033FF33DB4533 + DB4533D24533C04585C97E53488B74247085ED7E42438D0C04418BC50FAF8C2490000000410FAFC18D04814863C8488D5431028BCD0FB642014403D00FB6 + 024883C2044403D80FB642FB03D80FB642FA03F848FFC975DE41FFC0453BC17CB28BCD410FAFC985C9740A418BC299F7F98BF0EB0233F685C9740B418BC3 + 99F7F9448BD8EB034533DB85C9740A8BC399F7F9448BD0EB034533D285C9740A8BC799F7F9448BC0EB034533C033D24585C97E4D4C8B74247885ED7E3841 + 8D0C14418BC50FAF8C2490000000410FAFC18D04814863C84A8D4431028BCD40887001448818448850FF448840FE4883C00448FFC975E8FFC2413BD17CBD + 4C8B7424108B8C2498000000038C2490000000488B5C24704503E149FFCE44892424898C24980000004C897424100F859EFDFFFF448B7C240C448B842480 + 000000418BC09941F7F98BE8448BEA89942498000000896C240C85C00F8E3B010000448BAC2488000000418BCF448BF5410FAFC9898C248000000033FF33 + ED33F64533DB4533D24533C04585FF7E524585C97E40418BC5410FAFC14103C00FAF84249000000003C74898488D541802498BD90FB642014403D00FB602 + 4883C2044403D80FB642FB03F00FB642FA03E848FFCB75DE488B5C247041FFC0453BC77CAE85C9740B418BC299F7F9448BE0EB034533E485C9740A418BC3 + 99F7F98BD8EB0233DB85C9740A8BC699F7F9448BD8EB034533DB85C9740A8BC599F7F9448BD0EB034533D24533C04585FF7E4E488B4C24784585C97E3541 + 8BC5410FAFC14103C00FAF84249000000003C74898488D540802498BC144886201881A44885AFF448852FE4883C20448FFC875E941FFC0453BC77CBE8B8C + 2480000000488B5C2470418BC1C1E00203F849FFCE0F85ECFEFFFF448BAC24980000008B6C240C448BA4248800000033FF33DB4533DB4533D24533C04585 + FF7E5A488B7424704585ED7E48418BCC8BC5410FAFC94103C80FAF8C2490000000410FAFC18D04814863C8488D543102418BCD0FB642014403D00FB60248 + 83C2044403D80FB642FB03D80FB642FA03F848FFC975DE41FFC0453BC77CAB418BCF410FAFCD85C9740A418BC299F7F98BF0EB0233F685C9740B418BC399 + F7F9448BD8EB034533DB85C9740A8BC399F7F9448BD0EB034533D285C9740A8BC799F7F9448BC0EB034533C033D24585FF7E4E4585ED7E42418BCC8BC541 + 0FAFC903CA0FAF8C2490000000410FAFC18D04814863C8488B442478488D440102418BCD40887001448818448850FF448840FE4883C00448FFC975E8FFC2 + 413BD77CB233C04883C428415F415E415D415C5F5E5D5BC3 + ) + + VarSetCapacity(PixelateBitmap, StrLen(MCode_PixelateBitmap)//2) + Loop % StrLen(MCode_PixelateBitmap)//2 ;% + NumPut("0x" SubStr(MCode_PixelateBitmap, (2*A_Index)-1, 2), PixelateBitmap, A_Index-1, "UChar") + DllCall("VirtualProtect", Ptr, &PixelateBitmap, Ptr, VarSetCapacity(PixelateBitmap), "uint", 0x40, A_PtrSize ? "UPtr*" : "UInt*", 0) + } + + Gdip_GetImageDimensions(pBitmap, Width, Height) + + if (Width != Gdip_GetImageWidth(pBitmapOut) || Height != Gdip_GetImageHeight(pBitmapOut)) + return -1 + if (BlockSize > Width || BlockSize > Height) + return -2 + + E1 := Gdip_LockBits(pBitmap, 0, 0, Width, Height, Stride1, Scan01, BitmapData1) + E2 := Gdip_LockBits(pBitmapOut, 0, 0, Width, Height, Stride2, Scan02, BitmapData2) + if (E1 || E2) + return -3 + + E := DllCall(&PixelateBitmap, Ptr, Scan01, Ptr, Scan02, "int", Width, "int", Height, "int", Stride1, "int", BlockSize) + + Gdip_UnlockBits(pBitmap, BitmapData1), Gdip_UnlockBits(pBitmapOut, BitmapData2) + return 0 +} + +;##################################################################################### + +Gdip_ToARGB(A, R, G, B) +{ + return (A << 24) | (R << 16) | (G << 8) | B +} + +;##################################################################################### + +Gdip_FromARGB(ARGB, ByRef A, ByRef R, ByRef G, ByRef B) +{ + A := (0xff000000 & ARGB) >> 24 + R := (0x00ff0000 & ARGB) >> 16 + G := (0x0000ff00 & ARGB) >> 8 + B := 0x000000ff & ARGB +} + +;##################################################################################### + +Gdip_AFromARGB(ARGB) +{ + return (0xff000000 & ARGB) >> 24 +} + +;##################################################################################### + +Gdip_RFromARGB(ARGB) +{ + return (0x00ff0000 & ARGB) >> 16 +} + +;##################################################################################### + +Gdip_GFromARGB(ARGB) +{ + return (0x0000ff00 & ARGB) >> 8 +} + +;##################################################################################### + +Gdip_BFromARGB(ARGB) +{ + return 0x000000ff & ARGB +} + +;##################################################################################### + +StrGetB(Address, Length=-1, Encoding=0) +{ + ; Flexible parameter handling: + if Length is not integer + Encoding := Length, Length := -1 + + ; Check for obvious errors. + if (Address+0 < 1024) + return + + ; Ensure 'Encoding' contains a numeric identifier. + if Encoding = UTF-16 + Encoding = 1200 + else if Encoding = UTF-8 + Encoding = 65001 + else if SubStr(Encoding,1,2)="CP" + Encoding := SubStr(Encoding,3) + + if !Encoding ; "" or 0 + { + ; No conversion necessary, but we might not want the whole string. + if (Length == -1) + Length := DllCall("lstrlen", "uint", Address) + VarSetCapacity(String, Length) + DllCall("lstrcpyn", "str", String, "uint", Address, "int", Length + 1) + } + else if Encoding = 1200 ; UTF-16 + { + char_count := DllCall("WideCharToMultiByte", "uint", 0, "uint", 0x400, "uint", Address, "int", Length, "uint", 0, "uint", 0, "uint", 0, "uint", 0) + VarSetCapacity(String, char_count) + DllCall("WideCharToMultiByte", "uint", 0, "uint", 0x400, "uint", Address, "int", Length, "str", String, "int", char_count, "uint", 0, "uint", 0) + } + else if Encoding is integer + { + ; Convert from target encoding to UTF-16 then to the active code page. + char_count := DllCall("MultiByteToWideChar", "uint", Encoding, "uint", 0, "uint", Address, "int", Length, "uint", 0, "int", 0) + VarSetCapacity(String, char_count * 2) + char_count := DllCall("MultiByteToWideChar", "uint", Encoding, "uint", 0, "uint", Address, "int", Length, "uint", &String, "int", char_count * 2) + String := StrGetB(&String, char_count, 1200) + } + + return String +} \ No newline at end of file diff --git a/bnowakow/old versions/3 GT7-AHK/GT7-AHKv1.00.12_test/Lib/SuperSleep.dll b/bnowakow/old versions/3 GT7-AHK/GT7-AHKv1.00.12_test/Lib/SuperSleep.dll new file mode 100644 index 0000000..535d320 Binary files /dev/null and b/bnowakow/old versions/3 GT7-AHK/GT7-AHKv1.00.12_test/Lib/SuperSleep.dll differ diff --git a/bnowakow/old versions/3 GT7-AHK/GT7-AHKv1.00.12_test/Lib/ViGEmWrapper.dll b/bnowakow/old versions/3 GT7-AHK/GT7-AHKv1.00.12_test/Lib/ViGEmWrapper.dll new file mode 100644 index 0000000..2a08e3a Binary files /dev/null and b/bnowakow/old versions/3 GT7-AHK/GT7-AHKv1.00.12_test/Lib/ViGEmWrapper.dll differ diff --git a/bnowakow/old versions/3 GT7-AHK/GT7-AHKv1.00.12_test/Lib/__controller_functions__.ahk b/bnowakow/old versions/3 GT7-AHK/GT7-AHKv1.00.12_test/Lib/__controller_functions__.ahk new file mode 100644 index 0000000..0a8607c --- /dev/null +++ b/bnowakow/old versions/3 GT7-AHK/GT7-AHKv1.00.12_test/Lib/__controller_functions__.ahk @@ -0,0 +1,175 @@ + +/********************************************** +* Controller methods for simplicity * +***********************************************/ +*/ + +GoTo EndControllerFunctionsDef + +;;;;;;;;;;;; Turning functions +;;;;;;;;;;;; For holding the stick in a specific position for a period of time +;;;;;;;;;;;; Note no other button may be pressed or released when these functions are ran + +; Set the time you want to turn for in miliseconds and how hard (50, 100), 100 being the most, 50 being neutral +Turn_Right(sleept, inten){ + t := sleept + controller.Axes.LX.SetState(inten) + gosub, Turn + controller.Axes.LX.SetState(50) +} + +; Set the time you want to turn for in miliseconds and how hard (0, 50), 0 being the most +Turn_Left(sleept, inten){ + t := sleept + controller.Axes.LX.SetState(inten) + gosub, Turn + controller.Axes.LX.SetState(50) +} + +;;;;;;;;;;;; Simple button press functions +;;;;;;;;;;;; You can pass a delay amount or leave it blank +;;;;;;;;;;;; Longer delays hold the button longer + +; Press X button +Press_X(delay:=200){ + controller.Buttons.Cross.SetState(true) + DllCall("Sleep", "UInt", delay) + controller.Buttons.Cross.SetState(false) + return +} + +; Press O button +Press_O(delay:=200){ + controller.Buttons.Circle.SetState(true) + DllCall("Sleep", "UInt", delay) + controller.Buttons.Circle.SetState(false) + return +} + +; Press Triangle button +Press_Triangle(delay:=200){ + controller.Buttons.Triangle.SetState(true) + DllCall("Sleep", "UInt", delay) + controller.Buttons.Triangle.SetState(false) + return +} + +; Press Square button +Press_Square(delay:=200){ + controller.Buttons.Square.SetState(true) + DllCall("Sleep", "UInt", delay) + controller.Buttons.Square.SetState(false) + return +} + +; Press R1 button +Press_L1(delay:=200){ + controller.Buttons.L1.SetState(true) + DllCall("Sleep", "UInt", delay) + controller.Buttons.L1.SetState(false) + return +} + +; Press R1 button +Press_R1(delay:=200){ + controller.Buttons.R1.SetState(true) + DllCall("Sleep", "UInt", delay) + controller.Buttons.R1.SetState(false) + return +} + +; Press Right on D-pad +Press_Right(delay:=200){ + controller.Dpad.SetState("Right") + DllCall("Sleep", "UInt", delay) + controller.Dpad.SetState("None") + return +} + +; Press Left on D-pad +Press_Left(delay:=200){ + controller.Dpad.SetState("Left") + DllCall("Sleep", "UInt", delay) + controller.Dpad.SetState("None") + return +} + +; Press Up on D-pad +Press_Up(delay:=200){ + controller.Dpad.SetState("Up") + DllCall("Sleep", "UInt", delay) + controller.Dpad.SetState("None") + return +} + +; Press Down on D-pad +Press_Down(delay:=200){ + controller.Dpad.SetState("Down") + DllCall("Sleep", "UInt", delay) + controller.Dpad.SetState("None") + return +} + +;;;;;;;;;;; Other functions specific to GT7 + +; Turn on nitrous +Nitrous_On(){ + controller.Buttons.RS.SetState(true) +} + +; Turn off nitrous +Nitrous_Off(){ + controller.Buttons.RS.SetState(false) +} + +Accel_On(control:=100){ + controller.Buttons.R2.SetState(true) + controller.Axes.RT.SetState(control) +} + +Accel_Off(){ + controller.Buttons.R2.SetState(false) + controller.Axes.RT.SetState(0) +} + +Brake_On(control:=100){ + controller.Buttons.L2.SetState(true) + controller.Axes.LT.SetState(control) +} + +Brake_Off(){ + controller.Buttons.L2.SetState(false) + controller.Axes.LT.SetState(0) +} +; given time t in miliseconds, turn right for that long, with intensity being how much the turn button is held for +Turn: + t0 := A_TickCount + tf := t0+t + loop { + Sleep(100) + } until A_TickCount > tf + return + +PressX: +; Just for menuing, does not hold X down + controller.Buttons.Cross.SetState(true) + DllCall("Sleep", "UInt", 200) + controller.Buttons.Cross.SetState(false) + return + +PressO: +; Just for menuing, does not hold O down + controller.Buttons.Circle.SetState(true) + DllCall("Sleep", "UInt", 200) + controller.Buttons.Circle.SetState(false) + return + +PressRight: +; For turning + controller.Dpad.SetState("Right") + Sleep, 50 + controller.Dpad.SetState("None") + return + + +EndControllerFunctionsDef: diff --git a/bnowakow/old versions/3 GT7-AHK/GT7-AHKv1.00.12_test/Lib/__utility__.ahk b/bnowakow/old versions/3 GT7-AHK/GT7-AHKv1.00.12_test/Lib/__utility__.ahk new file mode 100644 index 0000000..1d0470d --- /dev/null +++ b/bnowakow/old versions/3 GT7-AHK/GT7-AHKv1.00.12_test/Lib/__utility__.ahk @@ -0,0 +1,136 @@ +/********************************************** +* Only place functions here, no sub routines * +***********************************************/ + + +; Grabs the colors of the pixels (x-b, y-b) to (x+b, y+b) +; returns the array of colors +*/ + +BitGrab(x, y, b) +{ + HWND := WinExist("PS Remote Play") + pToken := Gdip_Startup() + pBitmap := Gdip_BitmapFromHWND2(hwnd) + + pixs := [] + for i in range(-1*b, b+1){ + for j in range(-1*b, b+1){ + pixel := Gdip_GetPixel(pBitmap,x+i,y+j) + rgb := ConvertARGB( pixel ) + pixs.Push(rgb) + } + } + + Gdip_DisposeImage(pBitmap) + Gdip_Shutdown(pToken) + return pixs +} + +Gdip_BitmapFromHWND2(hwnd) +{ + WinGetPos,,, Width, Height, ahk_id %hwnd% + hbm := CreateDIBSection(Width, Height), hdc := CreateCompatibleDC(), obm := SelectObject(hdc, hbm) + RegExMatch(A_OsVersion, "\d+", Version) + PrintWindow(hwnd, hdc, Version >= 8 ? 2 : 0) + pBitmap := Gdip_CreateBitmapFromHBITMAP(hbm) + SelectObject(hdc, obm), DeleteObject(hbm), DeleteDC(hdc) + return pBitmap +} + +range(start, stop:="", step:=1) { + static range := { _NewEnum: Func("_RangeNewEnum") } + if !step + throw "range(): Parameter 'step' must not be 0 or blank" + if (stop == "") + stop := start, start := 0 + ; Formula: r[i] := start + step*i ; r = range object, i = 0-based index + ; For a postive 'step', the constraints are i >= 0 and r[i] < stop + ; For a negative 'step', the constraints are i >= 0 and r[i] > stop + ; No result is returned if r[0] does not meet the value constraint + if (step > 0 ? start < stop : start > stop) ;// start == start + step*0 + return { base: range, start: start, stop: stop, step: step } +} + +_RangeNewEnum(r) { + static enum := { "Next": Func("_RangeEnumNext") } + return { base: enum, r: r, i: 0 } +} + +_RangeEnumNext(enum, ByRef k, ByRef v:="") { + stop := enum.r.stop, step := enum.r.step + , k := enum.r.start + step*enum.i + if (ret := step > 0 ? k < stop : k > stop) + enum.i += 1 + return ret +} + + +Sleep(ms=1) +{ + global timeBeginPeriodHasAlreadyBeenCalled + if (timeBeginPeriodHasAlreadyBeenCalled != 1) + { + DllCall("Winmm.dll\timeBeginPeriod", UInt, 1) + timeBeginPeriodHasAlreadyBeenCalled := 1 + } + + DllCall("Sleep", UInt, ms) +} + + + +PixelColorSimple(pc_x, pc_y) +{ + WinGet, remotePlay_id, List, ahk_exe RemotePlay.exe + if (remotePlay_id = 0) + { + MsgBox, PS4 Remote Play not found + return + } + if remotePlay_id + { + pc_wID := remotePlay_id[0] + pc_hDC := DllCall("GetDC", "UInt", pc_wID) + pc_fmtI := A_FormatInteger + SetFormat, IntegerFast, Hex + pc_c := DllCall("GetPixel", "UInt", pc_hDC, "Int", pc_x, "Int", pc_y, "UInt") + pc_c := pc_c >> 16 & 0xff | pc_c & 0xff00 | (pc_c & 0xff) << 16 + pc_c .= "" + SetFormat, IntegerFast, %pc_fmtI% + DllCall("ReleaseDC", "UInt", pc_wID, "UInt", pc_hDC) + return pc_c + + } +} + +GetClientSize(hWnd, ByRef w := "", ByRef h := "") +{ + VarSetCapacity(rect, 16) + DllCall("GetClientRect", "ptr", hWnd, "ptr", &rect) + w := NumGet(rect, 8, "int") + h := NumGet(rect, 12, "int") +} + +Distance(c1, c2) +{ ; function by [VxE], return value range = [0, 441.67295593006372] +return Sqrt((((c1>>16)-(c2>>16))**2)+(((c1>>8&255)-(c2>>8&255))**2)+(((c1&255)-(c1&255))**2)) +} + +ConvertARGB(ARGB, Convert := 0) +{ + SetFormat, IntegerFast, Hex + RGB += ARGB + RGB := RGB & 0x00FFFFFF + if (Convert) + RGB := (RGB & 0xFF000000) | ((RGB & 0xFF0000) >> 16) | (RGB & 0x00FF00) | ((RGB & 0x0000FF) << 16) + + return RGB +} + +ToolTipper(msg, x := 100, y := 100) +{ + if (debug_mode = 1) + ToolTip, %msg%, x, y, Screen + return +} diff --git a/bnowakow/old versions/3 GT7-AHK/GT7-AHKv1.00.12_test/Menu.ahk b/bnowakow/old versions/3 GT7-AHK/GT7-AHKv1.00.12_test/Menu.ahk new file mode 100644 index 0000000..6b58206 --- /dev/null +++ b/bnowakow/old versions/3 GT7-AHK/GT7-AHKv1.00.12_test/Menu.ahk @@ -0,0 +1,20 @@ +#Include Menus\ChampionshipMenuing.ahk +#Include Menus\NormalMenuing.ahk + +GoTo EndMenuDef + +Menu: + Switch MenuSelection + { + case 0: + gosub, ChampionshipMenu + return + case 1: + gosub, NormalMenu + return + } + + + return + +EndMenuDef: diff --git a/bnowakow/old versions/3 GT7-AHK/GT7-AHKv1.00.12_test/Menus/ChampionshipMenuing.ahk b/bnowakow/old versions/3 GT7-AHK/GT7-AHKv1.00.12_test/Menus/ChampionshipMenuing.ahk new file mode 100644 index 0000000..b4c435b --- /dev/null +++ b/bnowakow/old versions/3 GT7-AHK/GT7-AHKv1.00.12_test/Menus/ChampionshipMenuing.ahk @@ -0,0 +1,78 @@ +GoTo EndChampionshipMenuingDef + +ChampionshipMenu: + + loop + { + break_point := false + c2 := BitGrab(pix2x, pix2y+remote_play_offsetY, box_size) + for i, c in c2 + { + d2 := Distance(c, color_check2) + if (d2 < tolerance ) + { + break_point := true + break + } + } + if (break_point) + break + Press_X() + sleep, %color_2_delay% + sleep, %bm_delay% + } + ;ToolTip, Found color 2, 100, 100, Screen + Sleep, 100 + Press_O() + Sleep, 100 + Press_Right() + Sleep, 100 + Press_X() + Sleep, %ps_load_time1% + Press_X() + Sleep, 1000 + Press_O() + loop, 2 + { + Press_X() + Sleep, 100 + } + Sleep, %ps_load_time2% + + ;Conduct Maintenance here. + CheckForOilChange := Mod(A_Index, 87) + CheckForMaintenance := Mod(A_Index, 257) + + ;ToolTipper("CheckForOilChange " CheckForOilChange "`nCheckForMaintenance " CheckForMaintenance, 300, 100) + + ifEqual, CheckForOilChange, 0 + { + gosub, DoOilChange + } + + ifEqual, CheckForMaintenance, 0 + { + gosub, DoMaintenance + } + Press_Down() + Sleep, 100 + loop, %menu_loops% + { + controller.Dpad.SetState(MenuDirect) + Sleep, 100 + controller.Dpad.SetState("None") + Sleep, 100 + } + loop, 2 + { + Press_X() + Sleep, 500 + } + Sleep, %ps_load_time3% + loop, 2{ + gosub, PressX + Sleep, 500 + } + return + +EndChampionshipMenuingDef: diff --git a/bnowakow/old versions/3 GT7-AHK/GT7-AHKv1.00.12_test/Menus/NormalMenuing.ahk b/bnowakow/old versions/3 GT7-AHK/GT7-AHKv1.00.12_test/Menus/NormalMenuing.ahk new file mode 100644 index 0000000..f37f03a --- /dev/null +++ b/bnowakow/old versions/3 GT7-AHK/GT7-AHKv1.00.12_test/Menus/NormalMenuing.ahk @@ -0,0 +1,36 @@ +GoTo EndNormalMenuingDef + +NormalMenu: + + loop + { + break_point := false + c2 := BitGrab(pix2x, pix2y+remote_play_offsetY, box_size) + for i, c in c2 + { + d2 := Distance(c, color_check2) + if (d2 < tolerance ) + { + break_point := true + break + } + } + if (break_point) + break + Press_X() + sleep, %color_2_delay% + sleep, %bm_delay% + } + + ;ToolTip, Found color 2, 100, 100, Screen + Sleep, 200 + controller.Dpad.SetState("Right") + Sleep, 100 + controller.Dpad.SetState("None") + Sleep, 500 + gosub, PressX + Sleep, 2000 + + return + +EndNormalMenuingDef: diff --git a/bnowakow/old versions/3 GT7-AHK/GT7-AHKv1.00.12_test/Mod/CheckStuck.ahk b/bnowakow/old versions/3 GT7-AHK/GT7-AHKv1.00.12_test/Mod/CheckStuck.ahk new file mode 100644 index 0000000..7ff99f7 --- /dev/null +++ b/bnowakow/old versions/3 GT7-AHK/GT7-AHKv1.00.12_test/Mod/CheckStuck.ahk @@ -0,0 +1,35 @@ +__enableCheckStuck_mod__ := 0 + +GoTo EndCheckStuckDef + +CheckStuck: + + if (__enableCheckStuck_mod__ = 0){ + return + } + + tc := BitGrab(tyreX, tyreY, box_size) + for i, c in tc + { + td := Distance(c, color_tyre_overheat) + if (td < tolerance ){ + tyres_overheating := true + break + } + } + return + +Unstuck: + + if (__enableCheckStuck_mod__ = 0){ + return + } + controller.Buttons.RS.SetState(false) + Sleep 200 + Turn_Left(4000, 0) + tyres_overheating := false + controller.Buttons.RS.SetState(true) + ToolTip, Unstuck done - hope it worked., 100, 100, Screen + return + +EndCheckStuckDef: \ No newline at end of file diff --git a/bnowakow/old versions/3 GT7-AHK/GT7-AHKv1.00.12_test/Mod/CheckTurn.ahk b/bnowakow/old versions/3 GT7-AHK/GT7-AHKv1.00.12_test/Mod/CheckTurn.ahk new file mode 100644 index 0000000..06ecb7d --- /dev/null +++ b/bnowakow/old versions/3 GT7-AHK/GT7-AHKv1.00.12_test/Mod/CheckTurn.ahk @@ -0,0 +1,59 @@ +__enableTurn_mod__ := 0 + +;Color: C95A51 (Red=C9 Green=5A Blue=51) + +; Class TurnContainer +; Simple container for constants +; Store the starting points to look for a turn on the minimap +; You can also store the end points +class TurnContainer +{ + __New(startX, startY, endX := 0, endY := 0) + { + this.startX := startX + this.startY := startY + this.endX := endX + this.endY := endY + } +} + +; below isn't used yet +TurnTolerance := 10 + +GoTo EndTurnDef + + +CheckTurn(x,y, b_size := 2) +{ + color_player := 0xDE6E70 + if (__enableTurn_mod__ = 0){ + return + } + + turn_complete := false + + loop { + tc := BitGrab(x, y, b_size) + + for i, c in tc + { + td := Distance(c, color_player) + ToolTipper("Turn" td) + if (td < 20 ){ + turn_complete := true + + break + } + } + + } until turn_complete = true + ToolTipper("Turn Found") + + return +} + +ResetTurn: + turn_complete := false + return + +EndTurnDef: diff --git a/bnowakow/old versions/3 GT7-AHK/GT7-AHKv1.00.12_test/Mod/CheckTyres.ahk b/bnowakow/old versions/3 GT7-AHK/GT7-AHKv1.00.12_test/Mod/CheckTyres.ahk new file mode 100644 index 0000000..a835a66 --- /dev/null +++ b/bnowakow/old versions/3 GT7-AHK/GT7-AHKv1.00.12_test/Mod/CheckTyres.ahk @@ -0,0 +1,47 @@ +__enableCheckTyres_mod__ := 0 + +color_tyre_overheat := 0xD42304 +tyres_overheating := false +tyreX := 166 +tyreY := 364 + +GoTo EndCheckTyresDef + +CheckTyresOverheating: + + + if (__enableCheckTyres_mod__ = 0){ + return + } + + tc := BitGrab(tyreX, tyreY, box_size) + for i, c in tc + { + td := Distance(c, color_tyre_overheat) + if (td < tolerance ){ + tyres_overheating := true + break + } + } + return + +RetryRace: + + if (__enableCheckTyres_mod__ = 0){ + return + } + + Gosub, PauseLoop + Sleep 500 + tyres_overheating := false + controller.Buttons.Options.SetState(true) + Sleep 200 + controller.Buttons.Options.SetState(false) + Sleep, 500 + controller.Dpad.SetState("Right") + Sleep, 200 + controller.Dpad.SetState("None") + Goto, AFKLoop + return + +EndCheckTyresDef: diff --git a/bnowakow/old versions/3 GT7-AHK/GT7-AHKv1.00.12_test/Mod/Hairpin.ahk b/bnowakow/old versions/3 GT7-AHK/GT7-AHKv1.00.12_test/Mod/Hairpin.ahk new file mode 100644 index 0000000..6d380b3 --- /dev/null +++ b/bnowakow/old versions/3 GT7-AHK/GT7-AHKv1.00.12_test/Mod/Hairpin.ahk @@ -0,0 +1,48 @@ +__enableHairpin_mod__ := 0 + +;Screen: 506, 69 (less often used) +;Color: C95A51 (Red=C9 Green=5A Blue=51) + +;Screen: 588, 88 (less often used) + + +color_player := 0xDE6E70 +hairpin_complete := false +hairpinX := 506 +hairpinY := 72 +hairpinCount := 0 +hairpinTolerance := 10 + +GoTo EndHairpinDef + + + +CheckHairpin: + + + if (__enableHairpin_mod__ = 0){ + return + } + + + + tc := BitGrab(hairpinX, hairpinY,3) + + for i, c in tc + { + td := Distance(c, color_player) + if (td < 20 ){ + hairpin_complete := true + hairpinCount += 1 + ToolTip, Hairpin Found current state: %hairpinCount%, 100, 100, Screen + + break + } + } + return + +ResetHairpin: + hairpinCount := 0 + return + +EndHairpinDef: diff --git a/bnowakow/old versions/3 GT7-AHK/GT7-AHKv1.00.12_test/Mod/Maintenance.ahk b/bnowakow/old versions/3 GT7-AHK/GT7-AHKv1.00.12_test/Mod/Maintenance.ahk new file mode 100644 index 0000000..2e8e424 --- /dev/null +++ b/bnowakow/old versions/3 GT7-AHK/GT7-AHKv1.00.12_test/Mod/Maintenance.ahk @@ -0,0 +1,275 @@ +__enableMaintenance_mod__ := 0 + +GoTo EndMaintenceDef + +;This will do only an oil change. will leave user at race menu to resume. +GtAutoNav: +return + +DoOilChange: + + if (__enableMaintenance_mod__ = 0){ + return + } + + if (SysCheck = 1) { + Sleep, 1000 + Press_O() + Sleep, 2800 + loop, 2 { + Press_Right(140) + Sleep, 200 + } + Press_Down() + Sleep, 200 + + loop, 2 { + Press_X() + Sleep, 1000 + } + + Sleep, 2000 + Press_Down(140) + Sleep, 200 + loop, 2 { + Press_X() + Sleep, 500 + } + Sleep, 7000 + Press_X() + Sleep, 500 + + Press_O() + Sleep, 200 + Sleep, 3000 + Press_Up(140) + Sleep, 200 + Press_Left() + Sleep, 500 + Press_Left() + Sleep, 500 + Press_X() + Sleep, 4800 + return + } + + if (SysCheck = 2 or SysCheck = 3) { + Sleep, 1000 + Press_O() + Sleep, 8800 + loop, 2 { + Press_Right(140) + Sleep, 200 + } + Press_Down() + Sleep, 200 + + Press_X() + Sleep, 1000 + loop, 2 { ; Makes sure it gets into the oil menu regardless the cursor starting point + Press_Left(140) + Sleep, 200 + } + Press_X() + Sleep, 1000 + + Sleep, 4000 + Press_Down(140) + Sleep, 200 + loop, 2 { + Press_X() + Sleep, 1500 + } + Sleep, 7000 + Press_X() + Sleep, 500 + + Press_O() + Sleep, 200 + Sleep, 7000 + Press_Up(140) + Sleep, 200 + Press_Left() + Sleep, 500 + Press_Left() + Sleep, 500 + Press_X() + Sleep, 11800 + return + } +return + +;This will do complete maintenance on the car including oil, engine and body. will leave user at race menu to resume. +DoMaintenance: + + if (__enableCheckTyres_mod__ = 0){ + return + } + + if (SysCheck = 1) { ; PS5 + Sleep, 1000 + controller.Buttons.Circle.SetState(true) + Sleep, 200 + controller.Buttons.Circle.SetState(false) + Sleep, 2800 + loop, 2 { + controller.Dpad.SetState("Right") + Sleep, 140 + controller.Dpad.SetState("None") + Sleep, 200 + } + controller.Dpad.SetState("Down") + Sleep, 200 + controller.Dpad.SetState("None") + Sleep, 200 + + loop, 2 { + gosub, PressX + Sleep, 1000 + } + + Sleep, 2000 + controller.Dpad.SetState("Down") + Sleep, 140 + controller.Dpad.SetState("None") + Sleep, 200 + loop, 2 { + gosub, PressX + Sleep, 500 + } + Sleep, 7000 + gosub, PressX + Sleep, 500 + + controller.Dpad.SetState("Down") + Sleep, 140 + controller.Dpad.SetState("None") + Sleep, 200 + controller.Dpad.SetState("Down") + Sleep, 140 + controller.Dpad.SetState("None") + Sleep, 200 + loop, 2 { + gosub, PressX + Sleep, 500 + } + Sleep, 7000 + gosub, PressX + Sleep, 500 + + controller.Dpad.SetState("Down") + Sleep, 140 + controller.Dpad.SetState("None") + Sleep, 200 + controller.Dpad.SetState("Down") + Sleep, 140 + controller.Dpad.SetState("None") + Sleep, 200 + controller.Dpad.SetState("Down") + Sleep, 140 + controller.Dpad.SetState("None") + Sleep, 200 + loop, 2 { + gosub, PressX + Sleep, 500 + } + Sleep, 8500 + gosub, PressX + Sleep, 500 + + controller.Buttons.Circle.SetState(true) + Sleep, 200 + controller.Buttons.Circle.SetState(false) + Sleep, 200 + Sleep, 3000 + controller.Dpad.SetState("Up") + Sleep, 140 + controller.Dpad.SetState("None") + Sleep, 200 + controller.Dpad.SetState("Left") + Sleep, 200 + controller.Dpad.SetState("None") + Sleep, 500 + controller.Dpad.SetState("Left") + Sleep, 200 + controller.Dpad.SetState("None") + Sleep, 500 + gosub, PressX + Sleep, 4800 + return + } + + if (SysCheck = 2 or SysCheck = 3) { ; PS4 and PS4 Pro + Sleep, 1000 + Press_O() + Sleep, 8800 + loop, 2 { + Press_Right(140) + Sleep, 200 + } + Press_Down() + Sleep, 200 + + Press_X() + Sleep, 1000 + loop, 2 { ; Makes sure it gets into the oil menu regardless the cursor starting point + Press_Left(140) + Sleep, 200 + } + Press_X() + Sleep, 1000 + + Sleep, 4000 + Press_Down(140) + Sleep, 200 + loop, 2 { + Press_X() + Sleep, 1500 + } + Sleep, 7000 + Press_X() + Sleep, 500 + + Press_Down(140) + Sleep, 200 + Press_Down(140) + Sleep, 200 + loop, 2 { + Press_X() + Sleep, 1500 + } + Sleep, 7000 + Press_X() + Sleep, 1500 + + Press_Down(140) + Sleep, 200 + Press_Down(140) + Sleep, 200 + Press_Down(140) + Sleep, 200 + loop, 2 { + Press_X() + Sleep, 1500 + } + Sleep, 8500 + gosub, PressX + Sleep, 500 + + Press_O() + Sleep, 200 + Sleep, 7000 + Press_Up(140) + Sleep, 200 + Press_Left() + Sleep, 500 + Press_Left() + Sleep, 500 + Press_X() + Sleep, 11800 + return + } + +return + +EndMaintenceDef: diff --git a/bnowakow/old versions/3 GT7-AHK/GT7-AHKv1.00.12_test/Mod/Mods.ahk b/bnowakow/old versions/3 GT7-AHK/GT7-AHKv1.00.12_test/Mod/Mods.ahk new file mode 100644 index 0000000..279b082 --- /dev/null +++ b/bnowakow/old versions/3 GT7-AHK/GT7-AHKv1.00.12_test/Mod/Mods.ahk @@ -0,0 +1,66 @@ +/************************************************ + Rules for adding a mod + + Your mod file should only be included here + In your mod file, make a flag variable such as + + __enable_mod__ := 0 + + and put the following at the beggining of each subroutine of your mod file + + if (__enable_mod__ = 0){ + return + } + + This will allow users to disable and enable the mod + + If your mod is dependent on another mod and there is an error while running, + try switching the order around on the #Include + + Add the mod's name and variable name to the _mod objects below +************************************************* +*/ + +#Include Mod\Maintenance.ahk +#Include Mod\CheckTyres.ahk +#Include Mod\CheckStuck.ahk +#Include Mod\Hairpin.ahk +#Include Mod\CheckTurn.ahk +#Include Mod\RemotePlaySizer.ahk + +_mod_names := +( LTrim Join +[ + "Check Tyres", + "Maintenance", + "Check Stuck", + "Check Hairpin", + "Check Turns", + "Remote Play Enlarge", + "Debug Mode" +] +) + +_mod_vars = +( LTrim Join| + __enableCheckTyres_mod__ + __enableMaintenance_mod__ + __enableCheckStuck_mod__ + __enableHairpin_mod__ + __enableTurn_mod__ + __enableRemotePlaySizer_mod__ + debug_mode +) + + +GoTo EndModsDef + +SaveMods: + Gui, 3:Submit + Loop, Parse, _mod_vars, | + { + IniWrite, % %A_LoopField%, config.ini, Mods, % A_LoopField + } +return + +EndModsDef: diff --git a/bnowakow/old versions/3 GT7-AHK/GT7-AHKv1.00.12_test/Mod/RemotePlaySizer.ahk b/bnowakow/old versions/3 GT7-AHK/GT7-AHKv1.00.12_test/Mod/RemotePlaySizer.ahk new file mode 100644 index 0000000..9bd0dc7 --- /dev/null +++ b/bnowakow/old versions/3 GT7-AHK/GT7-AHKv1.00.12_test/Mod/RemotePlaySizer.ahk @@ -0,0 +1,20 @@ +__enableRemotePlaySizer_mod__ := 0 + +; For when you change the size of remote play +; Necessary because multiple scripts have different settings for the checks + +GoTo EndRemotePlaySizerDef + +RemotePlay_ChangeSize: + + + if (__enableRemotePlaySizer_mod__ = 0){ + return + } + + remote_play_offsetY := 71 + + return + + +EndRemotePlaySizerDef: diff --git a/bnowakow/old versions/3 GT7-AHK/GT7-AHKv1.00.12_test/Race.ahk b/bnowakow/old versions/3 GT7-AHK/GT7-AHKv1.00.12_test/Race.ahk new file mode 100644 index 0000000..1b917a9 --- /dev/null +++ b/bnowakow/old versions/3 GT7-AHK/GT7-AHKv1.00.12_test/Race.ahk @@ -0,0 +1,103 @@ +#Include Races\PanAm.ahk +#Include Races\Tokyo.ahk +#Include Races\DaytonaSundayCup600.ahk + + +GoTo EndRaceDef + +Race: + + Switch RaceChoice + { + + + case "DaytonaSundayCup600": + t := 135000 + MenuSelection := 1 + Race_DAYTONASUNDAYCUP600() + return + case "PanAm": + t := 210000 + MenuSelection := 0 + Race_PANAM() + return + case "Tokyo": + MenuSelection := 1 + Race_Tokyo() + return + } + + return + +SettingsSheet: + + Gui, 4: Show, AutoSize, Settings Sheet + ;///////////////////////////////////////////////////////// + ; Add images to your setup here and in the Src folder + ; + ;///////////////////////////////////////////////////////// + Switch RaceChoice + { + case "DaytonaSundayCup600": + assist_1 = %A_ScriptDir%\Setups\PanAm\Assist1.jpg + assist_2 = %A_ScriptDir%\Setups\PanAm\Assist2.jpg + tune_1 = %A_ScriptDir%\Setups\PanAm\CarSetup.jpg + tune_2 = %A_ScriptDir%\Setups\PanAm\CarGearRatio.jpg + controls = %A_ScriptDir%\Setups\PanAm\Controller.jpg + return + + case "PanAm": + + assist_1 = %A_ScriptDir%\Setups\PanAm\Assist1.jpg + assist_2 = %A_ScriptDir%\Setups\PanAm\Assist2.jpg + tune_1 = %A_ScriptDir%\Setups\PanAm\CarSetup.jpg + tune_2 = %A_ScriptDir%\Setups\PanAm\CarGearRatio.jpg + controls = %A_ScriptDir%\Setups\PanAm\Controller.jpg + return + Case "Tokyo": + + assist_1 = %A_ScriptDir%\Setups\Tokyo\tokyo_assists_1.JPG + assist_2 = %A_ScriptDir%\Setups\Tokyo\tokyo_assists_2.jpg + tune_1 = %A_ScriptDir%\Setups\Tokyo\tokyo_tune_1.jpg + tune_2 = %A_ScriptDir%\Setups\Tokyo\tokyo_tune_2.jpg + controls = %A_ScriptDir%\Setups\Tokyo\tokyo_controls.jpg + ;FileInstall, tokyo_assists_1.jpg, %assist_1%, 1 + + + return + } + + + return + +Assists1: + GuiControl, 4:, CurrentPic, %assist_1% + gosub, Guisizer + return + +Assists2: + GuiControl, 4:, CurrentPic, %assist_2% + gosub, Guisizer + return + +Tune1: + GuiControl, 4:, CurrentPic, %tune_1% + gosub, Guisizer + return + +Tune2: + GuiControl, 4:, CurrentPic, %tune_2% + gosub, Guisizer + return + +ControllerSetting: + GuiControl, 4:, CurrentPic, %controls% + gosub, Guisizer + return + +Guisizer: + GuiControl, 4: Move, CurrentPic, % "x" 10 "y" 40 "w" 1200 . " h" . 800 + Gui, 4: Show, AutoSize, Settings Sheet + return + +EndRaceDef: diff --git a/bnowakow/old versions/3 GT7-AHK/GT7-AHKv1.00.12_test/Races/DaytonaSundayCup600.ahk b/bnowakow/old versions/3 GT7-AHK/GT7-AHKv1.00.12_test/Races/DaytonaSundayCup600.ahk new file mode 100644 index 0000000..5af9bd1 --- /dev/null +++ b/bnowakow/old versions/3 GT7-AHK/GT7-AHKv1.00.12_test/Races/DaytonaSundayCup600.ahk @@ -0,0 +1,31 @@ +GoTo EndRace_DAYTONASUNDAYCUP600_Def + +Race_DAYTONASUNDAYCUP600() +{ + controller.Buttons.Cross.SetState(true) + controller.Buttons.RS.SetState(true) + DllCall("Sleep", "UInt", 8200) + controller.Axes.LX.SetState(65) + + t0 := A_TickCount + tf := t0+t + loop { + DllCall("Sleep", "UInt", 500) + ;timeleft := Format("{:d}", (tf-A_TickCount)/1000) + ;timeref := Format("{:d}", 20000101000000) + ;timeref += timeleft, seconds + ;progress := Format("{:d}", (((t/1000)-(tf-A_TickCount)/1000))/(t/100000)) + ;progress := Format("{:d}", (t-(tf-A_TickCount))) + ;FormatTime, timeleftfull, %timeref%, H:mm.ss + ; GuiControl,, ST, Time Left : %timeleftfull% + ; GuiControl,, MyProgress, %progress% + } until A_TickCount >= tf + + ;GuiControl,, MyProgress, 0 + controller.Buttons.Cross.SetState(false) + controller.Dpad.SetState("None") + controller.Axes.LX.SetState(50) + controller.Buttons.RS.SetState(false) + return +} +EndRace_DAYTONASUNDAYCUP600_Def: diff --git a/bnowakow/old versions/3 GT7-AHK/GT7-AHKv1.00.12_test/Races/PanAm.ahk b/bnowakow/old versions/3 GT7-AHK/GT7-AHKv1.00.12_test/Races/PanAm.ahk new file mode 100644 index 0000000..2835638 --- /dev/null +++ b/bnowakow/old versions/3 GT7-AHK/GT7-AHKv1.00.12_test/Races/PanAm.ahk @@ -0,0 +1,158 @@ +GoTo EndRace_PANAM_Def + +Race_PANAM() +{ + + turn1 := new TurnContainer(619, 112+remote_play_offsetY, 630, 95+remote_play_offsetY) + turn2 := new TurnContainer(544, 45+remote_play_offsetY, 511, 52+remote_play_offsetY) + turn3 := new TurnContainer(492, 84+remote_play_offsetY, 506, 111+remote_play_offsetY) + lap_marker := new TurnContainer(560, 112+remote_play_offsetY) + + ; race_start_delay := 17400 ; this is for PS5. It may vary for PS4. + Switch SysCheck { + Case 1: + race_start_delay := 19200 + Case 2: + race_start_delay := 18200 + Case 3: + race_start_delay := 18200 + } + + CheckForOilChange := Mod(30 - A_Index, 30) + SetFormat, IntegerFast, d + CheckForMaintenance := Mod(180 - A_Index, 180) + SetFormat, IntegerFast, d + + if (__enableMaintenance_mod__ != 0){ + ToolTipper("Oil: " CheckForOilChange " race(s) remaining`nEngine: " CheckForMaintenance " race(s) remaining", 250, 45) + } + + t_ExpectedRaceTime := 195000 + t_RaceStartTime := A_TickCount + t_RaceFinishTime := t_RaceStartTime + t_ExpectedRaceTime + ;ToolTipper("t_ExpectedRaceTime = " t_ExpectedRaceTime "`nt_RaceStartTime = " t_RaceStartTime "`nt_RaceFinishTime = " t_RaceFinishTime) + + race_complete := false + + ; Press X to start the race + ;Tooltip + Press_X() + + ; Hold Acceleration and manage turning + Nitrous_On() + Accel_On(100) + ;SetTimer, CheckTyresOverheating, 1000 + + ; Retry race if time is taking more than 5.5 mins + ; (assume something went wrong with race) + ;SetTimer, RetryRace, 330000 + + Sleep (race_start_delay) + controller.Axes.LX.SetState(62) /* before turn 1, to avoid queue of cars */ + + Loop { + ; Turn 1 + ; Tooltip + CheckTurn(turn1.startX, turn1.startY) + ToolTipper("Turn 1 start found") + /* + if( A_Index != 1){ + Nitrous_Off() + Accel_On(75) + + } + */ + + controller.Axes.LX.SetState(18-3*%A_Index%) + ;Sleep(500) + Accel_On(100) + CheckTurn(turn1.endX, turn1.endY) + ToolTipper("Turn 1 end found") + + Nitrous_On() + controller.Axes.LX.SetState(75) + sleep(2000) + controller.Axes.LX.SetState(65) + sleep(2500) + controller.Axes.LX.SetState(62) + sleep(2000) + + ; Turn 2 + if( A_Index = 1 || A_Index = 6){ + CheckTurn(turn2.startX, turn2.startY) + } + else{ + CheckTurn(545, turn2.startY) + } + ToolTipper("Turn 2 start found") + controller.Axes.LX.SetState(18.3) + CheckTurn(turn2.endX, turn2.endY) + ToolTipper("Turn 2 end found") + controller.Axes.LX.SetState(50) + if( A_Index = 1 || A_Index = 6){ + controller.Axes.LX.SetState(75) + sleep(2000) + + controller.Axes.LX.SetState(65) + sleep(500) + } + else{ + Turn_Left(500, 28) + } + + ; Turn 3 + CheckTurn(turn3.startX, turn3.startY) + Nitrous_Off() + ToolTipper("Turn 3 start found") + controller.Axes.LX.SetState(12) + CheckTurn(turn3.endX, turn3.endY) + Nitrous_On() + ToolTipper("Turn 3 end found") + controller.Axes.LX.SetState(42) + sleep(500) + controller.Axes.LX.SetState(58) + sleep(2000) + controller.Axes.LX.SetState(62) + sleep(2000) + CheckTurn(lap_marker.startX, lap_marker.startY) + ToolTipper("Lap Complete") + + sleep(4000) + } until A_TickCount > t_racefinishtime + controller.Axes.LX.SetState(50) + ; ToolTip, Out of Loop, 100, 100, screen + + loop { + ;ToolTip, Racing, 100, 100, Screen + break_point := false + c1 := BitGrab(pix1x, pix1y+remote_play_offsetY, box_size) + for i, c in c1 + { + d1 := Distance(c, color_check1) + ;ToolTipper( d1 " " pix1y+remote_play_offsetY " " pix1x " " c) + if (d1 < tolerance ){ + break_point := true + break + } + } + if (break_point) + break + + controller.Dpad.SetState("Right") + Sleep, 50 + controller.Dpad.SetState("None") + + Sleep, 100 + } + ToolTipper("Race End") + gosub, PauseLoop + Sleep, 500 + return +} + +Race_PANAM_Complete() { + race_complete := true + return +} + +EndRace_PANAM_Def: diff --git a/bnowakow/old versions/3 GT7-AHK/GT7-AHKv1.00.12_test/Races/Tokyo.ahk b/bnowakow/old versions/3 GT7-AHK/GT7-AHKv1.00.12_test/Races/Tokyo.ahk new file mode 100644 index 0000000..24b143d --- /dev/null +++ b/bnowakow/old versions/3 GT7-AHK/GT7-AHKv1.00.12_test/Races/Tokyo.ahk @@ -0,0 +1,485 @@ +;---------------------------------------------------------------------- +; // START TOKYO RACE SCRIPT +;---------------------------------------------------------------------- + +GoTo EndRace_Tokyo_Def +Race_Tokyo() +{ + + ; // PIT STOP MANAGER + + ; PIT IN LAP (index 0 - Example: Lapping in Lap 5 is VALUE 4) + pitlap := 5 + + ; CHANGE TIRES TO: + ; 0 = RACING HARD + ; 1 = INTERMEDIATES + tires := 1 + + ; VARIABLES + lapcounter := 0 + pitstop := 0 + outlap := 0 + + + ;---------------------------------------------------------------------- + ;---------------------------- // LAP 01 ------------------------------- + ;---------------------------------------------------------------------- + + ;---------------------------------------------------------------------- + ; 01 // CHANGE FUEL MAP TO (LEAN 5) BEFORE RACE STARTS + ;---------------------------------------------------------------------- + + Sleep(1000) + ToolTip, [LAP: 01][PITSTOPS: 0] 01 // Changing to Lean (5), 25, 250, Screen + loop 4 { + Press_Up(delay:=200) + sleep, 200 + } + Sleep(6000) + + ;---------------------------------------------------------------------- + ; 02 // ACTIVATE ACCELERATION (100%) AND SHIFT TO 7TH GEAR + ;---------------------------------------------------------------------- + + ToolTip, [LAP: 01][PITSTOPS: 0] 02 // Acceleration ON & Shifting to 7th gear, 25, 250, Screen + Accel_On(100) + ;Nitrous_On() + loop 3 { + Press_X(delay:=200) + sleep, 200 + } + + + ;---------------------------------------------------------------------- + ; 03 // TRIGGER FORCED 5 SECOND PENALTY + ;---------------------------------------------------------------------- + + ToolTip, [LAP: 01][PITSTOPS: 0] 03 // Triggering 5 sec. penalty, 25, 250, Screen + Sleep(1000) + Turn_Left(1000,10) + + Turn_Left(13000,36) + + ;---------------------------------------------------------------------- + ;---------------------------- // LAP 02-12 ---------------------------- + ;---------------------------------------------------------------------- + + ;---------------------------------------------------------------------- + ; 04 // START THE BIG LOOP + ;---------------------------------------------------------------------- + + loop + { + + ;---------------------------------------------------------------------- + ; 05 // TRIGGER FORCED 5 SECOND PENALTY AND HUG WALLS UNTIL HAIRPIN + ;---------------------------------------------------------------------- + + ; // FIRST LAP + if (lapcounter = 0){ + ToolTip, [LAP: 01][PITSTOPS: 0] 05.1 // Hugging left wall from straight to turn 1, 25, 250, Screen + Turn_Left(25000,36) + + ToolTip, [LAP: 01][PITSTOPS: 0] 05.2 // Hugging right wall from chicane to hairpin, 25, 250, Screen + Turn_Right(20000,72) + } + + ; // LAP 02+ UNTIL WE DID A PITSTOP + if (lapcounter > 0) and (pitstop = 0){ + ToolTip, [LAP: 02+][PITSTOPS: 0] 05.3 // Hugging left wall from straight to turn 1, 25, 250, Screen + Turn_Left(28000,36) + + ToolTip, [LAP: 02+][PITSTOPS: 0] 05.4 // Hugging right wall from chicane to hairpin, 25, 250, Screen + Turn_Right(25000,72) + } + + + + ; // OUTLAP AFTER PITSTOP + if (outlap = 1){ + ToolTip, [OUTLAP][LAP: 02+][PITSTOPS: 1] 05.5 // Hugging left wall from straight to turn 1, 25, 250, Screen + Turn_Left(34000,36) + + ToolTip, [OUTLAP][LAP: 02+][PITSTOPS: 1] 05.6 // Hugging right wall from chicane to hairpin, 25, 250, Screen + Turn_Right(35000,72) + } + + ; // LAPS AFTER PITSTOP AND OUTLAP + if (lapcounter > 0) and (pitstop = 1) and (outlap = 0) { + ToolTip, [LAP: 02+][PITSTOPS: 1] 05.7 // Hugging left wall from straight to turn 1, 25, 250, Screen + Turn_Left(30000,36) + + ToolTip, [LAP: 02+][PITSTOPS: 1] 05.8 // Hugging right wall from chicane to hairpin, 25, 250, Screen + Turn_Right(24000,72) + + } + outlap := 0 + ;---------------------------------------------------------------------- + ; 06 // LOOKING FOR HAIRPIN -1- + ;---------------------------------------------------------------------- + + ToolTip, // 06 Looking for hairpin -1-, 25, 250, Screen + + color_player := 0xDE6E70 + hairpin_complete := false + hairpinX := 506 + hairpinY := 72 + hairpinCount := 0 + hairpinTolerance := 10 + + loop + { + + tc := BitGrab(hairpinX, hairpinY,2) + for i, c in tc + { + td := Distance(c, color_player) + if (td < 9 ){ + hairpin_complete := true + hairpinCount += 1 + ToolTip, 06 // Hairpin -1- found, 25, 250, Screen + break + } + } + ;Turn_Left(300, 30) + if( hairpinCount = 1 ) + break + Sleep(100) + } + + ;---------------------------------------------------------------------- + ; 07 // IF HAIRPIN -1- FOUND: + ; 07 // WAIT, THEN: + ; 07 // HUG LEFT WALL THEN RIGHT UNTIL PEN LINE + ;---------------------------------------------------------------------- + + ; // LAP 01 TIMINGS + if (lapcounter = 0) { + ToolTip, [LAP: 01][PITSTOPS: 0] 07.1 // Hairpin - turn right 5700 70, 25, 250, Screen + Turn_Right(5700,70) + ToolTip, [LAP: 01][PITSTOPS: 0] 07.2 // Hairpin - turn right 12000 65, 25, 250, Screen + Turn_Right(12000,65) + controller.Axes.LX.SetState(65) + + } + + ; // LAP 02 TIMINGS + if (lapcounter = 1) and (pitstop = 0) { + ToolTip, [LAP: 02][PITSTOPS: 0] 07.3 // Hairpin - turn right 5700 70, 25, 250, Screen + Turn_Right(5700,70) + ToolTip, [LAP: 02][PITSTOPS: 0] 07.4 // Hairpin - turn right 12000 65, 25, 250, Screen + Turn_Right(12000,65) + controller.Axes.LX.SetState(65) + + } + + ; // LAP 03 TIMINGS + if (lapcounter = 2) and (pitstop = 0) { + ToolTip, [LAP: 03][PITSTOPS: 0] 07.5 // Hairpin - turn right 5700 70 - SLEEP 800, 25, 250, Screen + Turn_Right(5700,70) + + ;Sleep(800) + ToolTip, [LAP: 03][PITSTOPS: 0] 07.6 // Hairpin - turn right 12000 65 , 25, 250, Screen + + Accel_On(55) + Turn_Right(6000,65) + Accel_On(100) + Turn_Right(6000,65) + + ;OLD + ;Turn_Right(12000,65) + + controller.Axes.LX.SetState(65) + + } + + + ; // LAP 04 TIMINGS + if (lapcounter = 3) and (pitstop = 0) { + ToolTip, [LAP: 04][PITSTOPS: 0] 07.7 // Hairpin - turn right 5700 70 - SLEEP 1500, 25, 250, Screen + Turn_Right(5700,70) + ;Sleep(1500) + ToolTip, [LAP: 04][PITSTOPS: 0] 07.8 // Hairpin - turn right 12000 65, 25, 250, Screen + + + Accel_On(55) + Turn_Right(6000,65) + Accel_On(100) + Turn_Right(6000,65) + + ;OLD + ;Turn_Right(12000,65) + + controller.Axes.LX.SetState(65) + + } + + ; // LAP 05 TIMINGS + if (lapcounter = 4) and (pitstop = 0) { + ToolTip, [LAP: 05][PITSTOPS: 0] 07.9 // Hairpin - turn right 5700 70 - SLEEP 2000, 25, 250, Screen + Turn_Right(5700,70) + ;Sleep(2000) + ToolTip, [LAP: 05][PITSTOPS: 0] 07.10 // Hairpin - turn right 12000 65, 25, 250, Screen + + Accel_On(55) + Turn_Right(6000,65) + Accel_On(100) + Turn_Right(6000,65) + + ;OLD + ;Turn_Right(12000,65) + controller.Axes.LX.SetState(65) + + } + + ; // LAP 06 TIMINGS + if (lapcounter = 5) + + { + ToolTip, [LAP: 06][PITSTOPS: 0] 07.11 // Hairpin - turn right 5700 70 - SLEEP 2400, 25, 250, Screen + Accel_On(55) + Turn_Right(5700,70) + ;Sleep(2400) + ToolTip, [LAP: 06][PITSTOPS: 0] 07.12 // Hairpin - turn right 12000 65, 25, 250, Screen + + Turn_Right(6000,65) + Accel_On(100) + Turn_Right(6000,65) + + ;OLD + ;Turn_Right(12000,65) + controller.Axes.LX.SetState(65) + + } + + ; // LAP 07 TIMINGS + if (lapcounter = 6) { + ToolTip, [LAP: 07][PITSTOPS: 1] 07.13 // Hairpin - turn right 5700 70, 25, 250, Screen + Accel_On(55) + Turn_Right(5700,70) + ToolTip, [LAP: 07][PITSTOPS: 1] 07.14 // Hairpin - turn right 12000 65, 25, 250, Screen + Turn_Right(6000,65) + Accel_On(100) + Turn_Right(6000,65) + controller.Axes.LX.SetState(65) + + } + + ; // LAP 08 TIMINGS + if (lapcounter = 7) { + ToolTip, [LAP: 08][PITSTOPS: 1] 07.15 // Hairpin - turn right 5700 70, 25, 250, Screen + Accel_On(55) + Turn_Right(5700,70) + ToolTip, [LAP: 08][PITSTOPS: 1] 07.16 // Hairpin - turn right 12000 65, 25, 250, Screen + Turn_Right(6000,65) + Accel_On(100) + Turn_Right(6000,65) + controller.Axes.LX.SetState(65) + + } + ; // LAP 09 TIMINGS + if (lapcounter = 8) { + ToolTip, [LAP: 09][PITSTOPS: 1] 07.17 // Hairpin - turn right 5700 70 - SLEEP 800, 25, 250, Screen + Turn_Right(5700,70) + ToolTip, [LAP: 09][PITSTOPS: 1] 07.18 // Hairpin - turn right 12000 65, 25, 250, Screen + ;Sleep(800) + + Accel_On(55) + Turn_Right(6000,65) + Accel_On(100) + Turn_Right(6000,65) + + + ;OLD + ;Turn_Right(12000,65) + controller.Axes.LX.SetState(65) + + } + + ; // LAP 10 TIMINGS + if (lapcounter = 9) { + ToolTip, [LAP: 10][PITSTOPS: 1] 07.19 // Hairpin - turn right 5700 70 - SLEEP 1500, 25, 250, Screen + Turn_Right(5700,70) + ;Sleep(1500) + ToolTip, [LAP: 10][PITSTOPS: 1] 07.20 // Hairpin - turn right 12000 65, 25, 250, Screen + Turn_Right(12000,65) + controller.Axes.LX.SetState(65) + + } + + ; // LAP 11 TIMINGS + if (lapcounter = 10) { + ToolTip, [LAP: 11][PITSTOPS: 1] 07.21 // Hairpin - turn right 5700 70 - SLEEP 2000, 25, 250, Screen + Turn_Right(5700,70) + ;Sleep(2000) + ToolTip, [LAP: 11][PITSTOPS: 1] 07.22 // Hairpin - turn right 12000 65, 25, 250, Screen + + Accel_On(55) + Turn_Right(6000,65) + Accel_On(100) + Turn_Right(6000,65) + + ;OLD + ;Turn_Right(12000,65) + controller.Axes.LX.SetState(65) + + } + + ; // LAP 12 TIMINGS + if (lapcounter = 11) { + ToolTip, [LAP: 12][PITSTOPS: 1] 07.23 // Hairpin - turn right 5700 70 - SLEEP 2400, 25, 250, Screen + Accel_On(55) + Turn_Right(5700,70) + ;Sleep(2400) + ToolTip, [LAP: 12][PITSTOPS: 1] 07.24 // Hairpin - turn right 12000 65, 25, 250, Screen + + Turn_Right(6000,65) + Accel_On(100) + Turn_Right(6000,65) + + ;OLD + ;Turn_Right(12000,65) + + ; // DRIVE IT HOME BABY + Turn_Right(30000,65) + } + + ;---------------------------------------------------------------------- + ; 08 // LOOKING FOR HAIRPIN -2- + ;---------------------------------------------------------------------- + + ToolTip, 08.1 // Looking for hairpin -2-, 25, 250, Screen + loop + { + + tc := BitGrab(hairpinX, hairpinY,2) + + for i, c in tc + { + td := Distance(c, color_player) + if (td < 20 ){ + hairpin_complete := true + hairpinCount += 1 + ToolTip, 08.2 // Hairpin Found, 25, 250, Screen + break + } + } + + ;Turn_Left(300, 30) + if( hairpinCount = 2 ) + break + Sleep(100) + } + + controller.Axes.LX.SetState(65) + + hairpinCount := 0 + + ;---------------------------------------------------------------------- + ; 09 // IF HAIRPIN -2- FOUND: + ; 09 // START CHECK FOR LAPCOUNTER FOR PIT, IF TRUE START PIT ROUTINE + ; 09 // ELSE SETUP FORCED PEN TRIGGER + ;---------------------------------------------------------------------- + + Turn_Left(1000, 40) + ;Turn_Right(300,65) + + if (pitlap = lapcounter){ + controller.Axes.LX.SetState(35) + + ToolTip, [LAP: 02+][PITSTOPS: 0] 09.1 // Pitstop starting, 25, 250, Screen + Turn_Right(1000, 60) + controller.Axes.LX.SetState(40) + Sleep (5000) + controller.Axes.LX.SetState(0) + Sleep (20000) + Press_Up() + Sleep (100) + + if (tires = 0) { + ; // RACING HARD + ToolTip, 09.2 // CHANGING TO RACING HARD, 25, 250, Screen + loop, 5{ + Press_Left() + } + } + + if (tires = 1) { + ; // INTERMEDIATES + ToolTip, 09.3 // CHANGING TO INTERMEDIATES, 25, 250, Screen + Press_Right() + } + + Press_X() + + + ; REFILL + ;Press_Down() + ;Press_X() + controller.Axes.LX.SetState(50) + + Sleep, 18000 + ToolTip, [LAP: 02+][PITSTOPS: 0] 09.4 // // LEAVING PIT - TRIGGER PEN & SHIFTING TO 7TH GEAR, 25, 250, Screen + Turn_Left(3000,0) + controller.Axes.LX.SetState(20) + loop 4 { + Press_X(delay:=200) + sleep, 200 + } + + pitstop := 1 + outlap := 1 + + } + else { + controller.Axes.LX.SetState(65) + + /* + ; //NEW PEN TRIGGER LOGIC, NEEDS TESTING/TIMINGS + Turn_Left(2000,30) + controller.Axes.LX.SetState(0) + + ToolTip, 09.4 // Triggering 5 sec. penalty, 25, 250, Screen + Sleep, 3000 + controller.Axes.LX.SetState(59) + Sleep, 15000 + + */ + + ; // PEN TRIGGER LOGIC (UNSTABLE) + + Sleep(5000) + Turn_Left(1000, 40) + Brake_on(100) + Accel_Off() + Sleep(3000) + + ToolTip, 09.5 // Triggering 5 sec. penalty, 25, 250, Screen + controller.Axes.LX.SetState(70) + Brake_off() + Nitrous_On() + Accel_On(100) + Sleep(3000) + Turn_Right(2000, 90) + Turn_Right(11000, 65) + Sleep(3000) + Nitrous_Off() + + + + } + ;---------------------------------------------------------------------- + ; 55 // CLOSE LOOP LAP 1-12 + ;---------------------------------------------------------------------- + + lapcounter++ + + } + +;---------------------------------------------------------------------- +; 99 // CLOSE RACE SCRIPT +;---------------------------------------------------------------------- + +} +EndRace_Tokyo_Def: diff --git a/bnowakow/old versions/3 GT7-AHK/GT7-AHKv1.00.12_test/Races/Tokyo.bak.late.ahk b/bnowakow/old versions/3 GT7-AHK/GT7-AHKv1.00.12_test/Races/Tokyo.bak.late.ahk new file mode 100644 index 0000000..d9c1e3c --- /dev/null +++ b/bnowakow/old versions/3 GT7-AHK/GT7-AHKv1.00.12_test/Races/Tokyo.bak.late.ahk @@ -0,0 +1,296 @@ +;---------------------------------------------------------------------- +; // START TOKYO RACE SCRIPT +;---------------------------------------------------------------------- + +GoTo EndRace_Tokyo_Def +Race_Tokyo() +{ + ; VARIABLES + lapcounter := 0 + + ;---------------------------------------------------------------------- + ;---------------------------- // LAP 01 ------------------------------- + ;---------------------------------------------------------------------- + + ;---------------------------------------------------------------------- + ; /1/ CHANGE FUEL MAP TO (LEAN 5) BEFORE RACE STARTS + ;---------------------------------------------------------------------- + + Sleep(1000) + ToolTip, /1/ Changing to Lean (5) //, 22, 70, Screen + loop 4 { + Press_Up(delay:=200) + sleep, 200 + } + Sleep(6000) + + + ;---------------------------------------------------------------------- + ; /2/ ACTIVATE ACCELERATION (100%) AND SHIFT TO 7TH GEAR + ;---------------------------------------------------------------------- + + ToolTip, /2/ Acceleration ON & Shifting to 7th gear //, 22, 70, Screen + Accel_On(100) + ;Nitrous_On() + loop 3 { + Press_X(delay:=200) + sleep, 200 + } + + + ;---------------------------------------------------------------------- + ; /3/ TRIGGER FORCED 5 SECOND PENALTY + ;---------------------------------------------------------------------- + + ToolTip, /3/ Triggering 5 sec. penalty //, 22, 70, Screen + Sleep(1000) + Turn_Left(1000,10) + + ;---------------------------------------------------------------------- + ; /4/ CHECK IF WE GOT THE 5 SEC PENALTY + ;---------------------------------------------------------------------- + + /* + loop { + gosub, CheckPenalty + + if( Penalty_triggered = true) + break + Sleep(100) + } + ToolTip, /4/ PENALTY RECEIVED //, 22, 70, Screen + Sleep(5000) + */ + + ;---------------------------------------------------------------------- + ; /5/ WAIT, THEN STEERING TO THE LEFT SIDE TO: + ; /5/ OVERTAKE CARS LEFT, GRIND WALL, TAKE T1 FROM LEFT + ;---------------------------------------------------------------------- + + + + ;---------------------------------------------------------------------- + ;---------------------------- // LAP 02-12 ---------------------------- + ;---------------------------------------------------------------------- + + ;---------------------------------------------------------------------- + ; /6/ START THE BIG LOOP + ;---------------------------------------------------------------------- + Turn_Left(12000,36) + + loop + { + + ;---------------------------------------------------------------------- + ; /7/ TRIGGER FORCED 5 SECOND PENALTY + ;---------------------------------------------------------------------- + + if (lapcounter > 0) + { + ToolTip, /7.1/ Triggering 5 sec. penalty after tunnel //, 22, 70, Screen + ToolTip, /7.2/ HALF Acceleration for 3 sec //, 22, 70, Screen + } + + ToolTip, 5.1 // Hugging left wall from straight to chicane //, 22, 70, Screen + Turn_Left(26000,36) + + ToolTip, 5.2 // Hugging right wall from chicane to hairpin //, 22, 70, Screen + Turn_Right(33000,72) + + /* + ;---------------------------------------------------------------------- + ; /9/ START THE CHICANE SEARCH LOOP + ;---------------------------------------------------------------------- + ToolTip, /9/ Turn right through chicane //, 22, 70, Screen + Turn_Right(15000,75) + ToolTip, /9/ Looking for Chicane //, 22, 70, Screen + loop { + gosub, CheckChicane + + if( Chicane_complete = true) + break + Sleep(100) + } + + ;---------------------------------------------------------------------- + ; /10/ IF CHICANE FOUND: + ; /10/ WAIT, THEN: + ; /10/ ACCELERATION & NITRO OFF, TURN RIGHT, ACCELERATION & NITRO ON, WAIT + ;---------------------------------------------------------------------- + + Sleep(1550) + ToolTip, /10/ Acceleration & Nitro OFF //, 22, 70, Screen + Nitrous_Off() + Accel_Off() + ToolTip, /10/ Turning left //, 22, 70, Screen + Turn_Left(1500,15) + ToolTip, /10/ Acceleration & Nitro ON //, 22, 70, Screen + Accel_On(100) + Nitrous_On() + gosub, ResetChicane + + */ + + ;---------------------------------------------------------------------- + ; /11/ START THE HAIRPIN SEARCH LOOP + ;---------------------------------------------------------------------- + + ToolTip, /11/ Looking for hairpin, 22, 70, Screen + + color_player := 0xDE6E70 + hairpin_complete := false + hairpinX := 506 + hairpinY := 72 + hairpinCount := 0 + hairpinTolerance := 10 + + loop + { + + tc := BitGrab(hairpinX, hairpinY,2) + + for i, c in tc + { + td := Distance(c, color_player) + if (td < 9 ){ + hairpin_complete := true + hairpinCount += 1 + ToolTip, /11/ Hairpin Found, 22, 70, Screen + break + } + } + ;Turn_Left(300, 30) + if( hairpinCount = 1 ) + break + Sleep(100) + } + + ;---------------------------------------------------------------------- + ; /12/ IF HAIRPIN (1) FOUND: + ; /12/ WAIT, THEN: + ; /12/ HUG THE LEFT WALL TO GET 90° BUMPS + ;---------------------------------------------------------------------- + + ;ToolTip, /12/ Turning left for corner bumps //, 22, 70, Screen + ;Turn_Left(20000, 25) + + + ToolTip, /12/ Hairpin - turn right 5700 70 //, 100, 100, Screen + + Turn_Right(5700,70) + Accel_On(75) + ToolTip, /12/ Hairpin - turn right 12000 60 //, 100, 100, Screen + Turn_Right(5000,70 + lapcounter) + Sleep(1000) + Turn_Right(5000,65) + Accel_On(100) + ToolTip, /12/ Sleep //, 100, 100, Screen + Sleep(3000) + controller.Axes.LX.SetState(65) + + + + loop + { + + tc := BitGrab(hairpinX, hairpinY,2) + + for i, c in tc + { + td := Distance(c, color_player) + if (td < 20 ){ + hairpin_complete := true + hairpinCount += 1 + ToolTip, /11/ Hairpin Found, 100, 100, Screen + break + } + } + ;Turn_Left(300, 30) + if( hairpinCount = 2 ) + break + Sleep(100) + } + ToolTip, LX 65, 22, 70, Screen + + if (lapcounter = 4){ + controller.Axes.LX.SetState(35) + } + else { + controller.Axes.LX.SetState(65) + } + + + Sleep(4650) + + hairpinCount := 0 + ;---------------------------------------------------------------------- + ; /13/ HUG THE RIGHT WALL TO AVOID THE PIT ENTRANCE + ;---------------------------------------------------------------------- + + ToolTip, Left 300 - Right 300, 100, 100, Screen + + + ;Turn_Right(300,65) + + ;---------------------------------------------------------------------- + ; /7/ TRIGGER FORCED 5 SECOND PENALTY + ;---------------------------------------------------------------------- + + if (lapcounter = 4){ + ;---------------------------------------------------------------------- + ; /20/ MAKE PIT STOP CHANGE TIRES + ;---------------------------------------------------------------------- + ToolTip, Heading to pit, 100, 100, Screen + ;Turn_Right(800, 60) + controller.Axes.LX.SetState(0) + Accel_On() + Brake_off() + Sleep, 17000 + Turn_Left(5000, 20) + ToolTip, Changing tires, 100, 100, Screen + Press_Up() + loop, 5{ + Press_Left() + } + Press_X() + Press_Down() + Press_X() + controller.Axes.LX.SetState(50) + Sleep, 12000 + ToolTip, Leaving Pit, 100, 100, Screen + loop 4 { + Press_X(delay:=200) + sleep, 200 + } + } + else { + Accel_Off() + Brake_on(100) + Turn_Left(950, 40) + Sleep(3000) + + controller.Axes.LX.SetState(70) + Brake_off() + Nitrous_On() + Accel_On(100) + Sleep(3000) + Turn_Right(2000, 90) + Turn_Right(11000, 65) + Sleep(3000) + + Nitrous_Off() + } + ;---------------------------------------------------------------------- + ; /55/ CLOSE LOOP LAP 1-12 + ;---------------------------------------------------------------------- + + lapcounter++ + ToolTip, /55/ LAP %lapcounter%, 100, 100, Screen + } + +;---------------------------------------------------------------------- +; /99/ CLOSE RACE SCRIPT +;---------------------------------------------------------------------- + +} +EndRace_Tokyo_Def: diff --git a/bnowakow/old versions/3 GT7-AHK/GT7-AHKv1.00.12_test/Setups/PanAm/Assist1.jpg b/bnowakow/old versions/3 GT7-AHK/GT7-AHKv1.00.12_test/Setups/PanAm/Assist1.jpg new file mode 100644 index 0000000..aff8292 Binary files /dev/null and b/bnowakow/old versions/3 GT7-AHK/GT7-AHKv1.00.12_test/Setups/PanAm/Assist1.jpg differ diff --git a/bnowakow/old versions/3 GT7-AHK/GT7-AHKv1.00.12_test/Setups/PanAm/Assist2.jpg b/bnowakow/old versions/3 GT7-AHK/GT7-AHKv1.00.12_test/Setups/PanAm/Assist2.jpg new file mode 100644 index 0000000..a6672f7 Binary files /dev/null and b/bnowakow/old versions/3 GT7-AHK/GT7-AHKv1.00.12_test/Setups/PanAm/Assist2.jpg differ diff --git a/bnowakow/old versions/3 GT7-AHK/GT7-AHKv1.00.12_test/Setups/PanAm/CarGearRatio.jpg b/bnowakow/old versions/3 GT7-AHK/GT7-AHKv1.00.12_test/Setups/PanAm/CarGearRatio.jpg new file mode 100644 index 0000000..7dbdb1b Binary files /dev/null and b/bnowakow/old versions/3 GT7-AHK/GT7-AHKv1.00.12_test/Setups/PanAm/CarGearRatio.jpg differ diff --git a/bnowakow/old versions/3 GT7-AHK/GT7-AHKv1.00.12_test/Setups/PanAm/CarSetup.jpg b/bnowakow/old versions/3 GT7-AHK/GT7-AHKv1.00.12_test/Setups/PanAm/CarSetup.jpg new file mode 100644 index 0000000..a81b987 Binary files /dev/null and b/bnowakow/old versions/3 GT7-AHK/GT7-AHKv1.00.12_test/Setups/PanAm/CarSetup.jpg differ diff --git a/bnowakow/old versions/3 GT7-AHK/GT7-AHKv1.00.12_test/Setups/PanAm/Controller.jpg b/bnowakow/old versions/3 GT7-AHK/GT7-AHKv1.00.12_test/Setups/PanAm/Controller.jpg new file mode 100644 index 0000000..ca3eef6 Binary files /dev/null and b/bnowakow/old versions/3 GT7-AHK/GT7-AHKv1.00.12_test/Setups/PanAm/Controller.jpg differ diff --git a/bnowakow/old versions/3 GT7-AHK/GT7-AHKv1.00.12_test/Setups/PanAm/Difficulty.png b/bnowakow/old versions/3 GT7-AHK/GT7-AHKv1.00.12_test/Setups/PanAm/Difficulty.png new file mode 100644 index 0000000..1b68be6 Binary files /dev/null and b/bnowakow/old versions/3 GT7-AHK/GT7-AHKv1.00.12_test/Setups/PanAm/Difficulty.png differ diff --git a/bnowakow/old versions/3 GT7-AHK/GT7-AHKv1.00.12_test/Setups/Tokyo/tokyo_assists_1.JPG b/bnowakow/old versions/3 GT7-AHK/GT7-AHKv1.00.12_test/Setups/Tokyo/tokyo_assists_1.JPG new file mode 100644 index 0000000..99861b3 Binary files /dev/null and b/bnowakow/old versions/3 GT7-AHK/GT7-AHKv1.00.12_test/Setups/Tokyo/tokyo_assists_1.JPG differ diff --git a/bnowakow/old versions/3 GT7-AHK/GT7-AHKv1.00.12_test/Setups/Tokyo/tokyo_assists_2.JPG b/bnowakow/old versions/3 GT7-AHK/GT7-AHKv1.00.12_test/Setups/Tokyo/tokyo_assists_2.JPG new file mode 100644 index 0000000..268bf3f Binary files /dev/null and b/bnowakow/old versions/3 GT7-AHK/GT7-AHKv1.00.12_test/Setups/Tokyo/tokyo_assists_2.JPG differ diff --git a/bnowakow/old versions/3 GT7-AHK/GT7-AHKv1.00.12_test/Setups/Tokyo/tokyo_controls.JPG b/bnowakow/old versions/3 GT7-AHK/GT7-AHKv1.00.12_test/Setups/Tokyo/tokyo_controls.JPG new file mode 100644 index 0000000..7861cdb Binary files /dev/null and b/bnowakow/old versions/3 GT7-AHK/GT7-AHKv1.00.12_test/Setups/Tokyo/tokyo_controls.JPG differ diff --git a/bnowakow/old versions/3 GT7-AHK/GT7-AHKv1.00.12_test/Setups/Tokyo/tokyo_tune_1.JPG b/bnowakow/old versions/3 GT7-AHK/GT7-AHKv1.00.12_test/Setups/Tokyo/tokyo_tune_1.JPG new file mode 100644 index 0000000..b50700e Binary files /dev/null and b/bnowakow/old versions/3 GT7-AHK/GT7-AHKv1.00.12_test/Setups/Tokyo/tokyo_tune_1.JPG differ diff --git a/bnowakow/old versions/3 GT7-AHK/GT7-AHKv1.00.12_test/Setups/Tokyo/tokyo_tune_2.JPG b/bnowakow/old versions/3 GT7-AHK/GT7-AHKv1.00.12_test/Setups/Tokyo/tokyo_tune_2.JPG new file mode 100644 index 0000000..0af7661 Binary files /dev/null and b/bnowakow/old versions/3 GT7-AHK/GT7-AHKv1.00.12_test/Setups/Tokyo/tokyo_tune_2.JPG differ diff --git a/bnowakow/old versions/3 GT7-AHK/GT7-AHKv1.00.12_test/Src/gt.ico b/bnowakow/old versions/3 GT7-AHK/GT7-AHKv1.00.12_test/Src/gt.ico new file mode 100644 index 0000000..d40c53c Binary files /dev/null and b/bnowakow/old versions/3 GT7-AHK/GT7-AHKv1.00.12_test/Src/gt.ico differ diff --git a/bnowakow/old versions/3 GT7-AHK/GT7-AHKv1.00.12_test/config.ini b/bnowakow/old versions/3 GT7-AHK/GT7-AHKv1.00.12_test/config.ini new file mode 100644 index 0000000..6639de4 Binary files /dev/null and b/bnowakow/old versions/3 GT7-AHK/GT7-AHKv1.00.12_test/config.ini differ