help with MCode
Posted: 25 Nov 2019, 00:20
so i've downloaded joedf's MCode4GCC and installed tdm-gcc 32bit
i've pasted in this pixelsearch function:
http://autohotkey.com/board/topic/89283-mcode-function-onlinegenerator-x86-and-x64/?p=584519
but i cannot get it to work. i have a full test script working with tic's pixelsearch which is included, but i cannot get rseding's to work
code below, and haystack image attached. please help. @Helgef @joedf @nnnik
maybe it has something to do with Rseding's version allowing me to pass multiple colors to search for? i'm not sure how i would pass multiple colors as unsigned char * through dllcall.
i've pasted in this pixelsearch function:
http://autohotkey.com/board/topic/89283-mcode-function-onlinegenerator-x86-and-x64/?p=584519
but i cannot get it to work. i have a full test script working with tic's pixelsearch which is included, but i cannot get rseding's to work
code below, and haystack image attached. please help. @Helgef @joedf @nnnik
maybe it has something to do with Rseding's version allowing me to pass multiple colors to search for? i'm not sure how i would pass multiple colors as unsigned char * through dllcall.
Code: Select all
#include Gdip_All.ahk
; My42Function := MCode("2,x86:uCoAAADD,x64:uCoAAADD")
; Msgbox % DllCall(My42Function,"cdecl") ; works
pToken := Gdip_Startup()
pBitmapHaystack := Gdip_CreateBitmapFromFile("red_dot.png")
color := 0xFFFF0000
ret := Tic_PixelSearch(pBitmapHaystack, color, outx, outy)
msgbox, works!`n%ret%`n%outx%`n%outy%
ret := Rseding91_PixelSearch(pBitmapHaystack, color, outx, outy)
msgbox, fails!`n%ret%`n%outx%`n%outy%
Gdip_DisposeImage(pBitmapHaystack)
Gdip_Shutdown(pToken)
return
;// https://autohotkey.com/board/topic/89283-mcode-function-onlinegenerator-x86-and-x64/page-2#entry584519
Rseding91_PixelSearch(pBitmap, color, ByRef x, ByRef y)
{
static PixSearch
if (!PixSearch)
{
code := "2,x86:VVdWU4PsEIN8JFABi2wkMItcJDQPhfAAAACLRCRIOUQkQA+N4gAAAItEJECLdCQ8"
. "D69EJDiNBLADRCQsiUQkDItEJAyJRCQEi0QkPIlEJAiLRCREOUQkPA+NkQAAAGaQ"
. "hdt+c4tEJASLVCRMD7ZIAjHAAcorTCRMiQwkkI10JgAPtkyFAjnRf0c7DCR8Qot8"
. "JAQPtnSFAQ+2TwGLfCRMAc85/n8rK0wkTDnOfCOLfCQED7Z0hQAPtg+LfCRMAc85"
. "/n8NK0wkTDnOfWCQjXQmAIPAATnDdamDRCQIAYNEJAQEi0QkCDlEJEQPhXH///+D"
. "RCRAAYt0JDiLRCRAAXQkDDlEJEgPhTb///+LRCQkxwD/////i0QkKMcA/////4PE"
. "ELin5P//W15fXcOLRCQki3QkCIkwi0QkKIt0JECJMIPEEDHAW15fXcOQkJCQkJCQ"
PixSearch := MCode(code)
}
Gdip_GetImageDimensions(pBitmap, Width, Height)
if !(Width && Height)
return -1
if (E1 := Gdip_LockBits(pBitmap, 0, 0, Width, Height, Stride1, Scan01, BitmapData1))
return -2
x := y := 0
E := DllCall(PixSearch, "int*", x, "int*", y, "uint", Scan01, "uint", color, "int", 1, "int", Stride1, "int", 0, "int", 0, "int", Width, "int", Height, "int", 0, "int", 1, "cdecl uint")
; MsgBox, %ErrorLevel%`n%A_LastError%
Gdip_UnlockBits(pBitmap, BitmapData1)
return E
}
MCode(mcode)
{
static e1 := 4, e2 := 1
static c, ptr
c := (A_PtrSize=8) ? "x64" : "x86"
ptr := A_PtrSize ? "Ptr" : "UInt"
if (!regexmatch(mcode, "^([0-9]+),(" c ":|.*?," c ":)([^,]+)", m))
return
if (!DllCall("crypt32\CryptStringToBinary" (A_IsUnicode ? "W" : "A"), "str", m3, "uint", 0, "uint", e%m1%, ptr, 0, "uint*", s, ptr, 0, ptr, 0))
return
p := DllCall("GlobalAlloc", "uint", 0, ptr, s, ptr)
DllCall("VirtualProtect", ptr, p, ptr, s, "uint", 0x40, "uint*", op)
if (DllCall("crypt32\CryptStringToBinary" (A_IsUnicode ? "W" : "A"), "str", m3, "uint", 0, "uint", e%m1%, ptr, p, "uint*", s, ptr, 0, ptr, 0))
return p
DllCall("GlobalFree", ptr, p)
}
;// https://autohotkey.com/board/topic/79077-gdip-pixelsearch/
Tic_PixelSearch(pBitmap, ARGB, ByRef x, ByRef y)
{
static _PixelSearch
if !_PixelSearch
{
MCode_PixelSearch := "8B44241099535583E2035603C233F6C1F80239742418577E388B7C24148B6C24248B5424188D1C85000000008D64240033C085"
. "D27E108BCF3929743183C00183C1043BC27CF283C60103FB3B74241C7CDF8B4424288B4C242C5F5EC700FFFFFFFF5DC701FFFFFFFF83C8FF5BC38B4C2"
. "4288B54242C5F890189325E5D33C05BC3"
VarSetCapacity(_PixelSearch, StrLen(MCode_PixelSearch)//2)
Loop % StrLen(MCode_PixelSearch)//2 ;%
NumPut("0x" SubStr(MCode_PixelSearch, (2*A_Index)-1, 2), _PixelSearch, A_Index-1, "char")
}
Gdip_GetImageDimensions(pBitmap, Width, Height)
if !(Width && Height)
return -1
if (E1 := Gdip_LockBits(pBitmap, 0, 0, Width, Height, Stride1, Scan01, BitmapData1))
return -2
x := y := 0
E := DllCall(&_PixelSearch, "uint", Scan01, "int", Width, "int", Height, "int", Stride1, "uint", ARGB, "int*", x, "int*", y)
Gdip_UnlockBits(pBitmap, BitmapData1)
return (E = "") ? -3 : E
}