1 (изменено: Dworkin, 2013-04-05 00:51:58)

Тема: AHK: В GUI дублируются функции

Здравствуйте помогите пожалуйста со скриптом.

У вас на форуме нашел скрипт , который работает с памятью и все отлично у меня работает.
Я хотел сделать чтобы при нажатии кнопки в GUI мне давало определенное количество одного предмета, а при нажатии другой кнопки давало определенное количество другого предмета.

По отдельности в GUI они работают, но если их соединить вместе то пишет что функции дублируются.

Вот сам код с GUI:

Gui, Add, Button, default, Health 
Gui, Add, Button, default, Armour
Gui, Show,, Simple Input Example
return 

GuiClose:

ButtonHealth:
      Try
        SetActorHP(9)
    Catch e
        MsgBox,, Error, % e.Message
    return

SetActorHP(value)
{
    baseAddress := ReadMemory(0xB7CD98, "gta_sa.exe", "Ptr", A_PtrSize)
    WriteMemory(value, baseAddress + 0x540, "gta_sa.exe", "float")
}

ReadMemory(address, processIDorName, type = "Int", numBytes = 4)
{
    VarSetCapacity(MVALUE, numBytes, 0)
    VarSetCapacity(numBytesRead, A_PtrSize, 0)

    Process, Exist, %processIDorName%
    if !processID := ErrorLevel
        Throw Exception("Invalid process name or process ID:`n`n""" . processIDorName . 

"""")

    if !processHandle := DllCall("OpenProcess", "Int", 24, "UInt", 0, "UInt", processID, 

"Ptr")
        Throw Exception("Failed to open process.`n`nError code:`t" . A_LastError)

    result := DllCall("ReadProcessMemory", "Ptr", processHandle, "Ptr", address, "Ptr", 

&MVALUE, "UInt", numBytes, "UIntP", numBytesRead, "UInt")

    if !DllCall("CloseHandle", "Ptr", processHandle, "UInt") && !result
        Throw Exception("Failed to close process handle.`n`nError code:`t" . A_LastError)

    if !result
        Throw Exception("Failed to read process memory.`n`nError code:`t" . A_LastError)

    if !numBytesRead
        Throw Exception("Read 0 bytes from the`n`nprocess:`t" processIDorName "`naddress:`t" 

address)

    return NumGet(MVALUE, 0, type)
}

WriteMemory(data, address, processIDorName, type = "Int", numBytes = 4)
{
    VarSetCapacity(buf, numBytes, 0)
    NumPut(data, buf, 0, type)

    Process, Exist, %processIDorName%
    if !processID := ErrorLevel
        Throw Exception("Invalid process name or process ID:`n`n""" . processIDorName . 

"""")

    if !processHandle := DllCall("OpenProcess", "Int", 40, "UInt", 0, "UInt", processID, 

"Ptr")
        Throw Exception("Failed to open process.`n`nError code:`t" . A_LastError)

    result := DllCall("WriteProcessMemory", "Ptr", processHandle, "Ptr", address, "Ptr", 

&buf, "UInt", numBytes, "UInt", 0, "UInt")

    if !DllCall("CloseHandle", "Ptr", processHandle, "UInt") && !result
        Throw Exception("Failed to close process handle.`n`nError code:`t" . A_LastError)

    if !result
        Throw Exception("Failed to write process memory.`n`nError code:`t" . A_LastError)

    return result
}

ButtonArmour:
     Try
        SetActorAr(50)
    Catch e
        MsgBox,, Error, % e.Message
    return

SetActorAr(value)
{
    baseAddress := ReadMemory(0xB7CD98, "gta_sa.exe", "Ptr", A_PtrSize)
    WriteMemory(value, baseAddress + 0x548, "gta_sa.exe", "float")
}

ReadMemory(address, processIDorName, type = "Int", numBytes = 4)
{
    VarSetCapacity(MVALUE, numBytes, 0)
    VarSetCapacity(numBytesRead, A_PtrSize, 0)

    Process, Exist, %processIDorName%
    if !processID := ErrorLevel
        Throw Exception("Invalid process name or process ID:`n`n""" . processIDorName . 

"""")

    if !processHandle := DllCall("OpenProcess", "Int", 24, "UInt", 0, "UInt", processID, 

"Ptr")
        Throw Exception("Failed to open process.`n`nError code:`t" . A_LastError)

    result := DllCall("ReadProcessMemory", "Ptr", processHandle, "Ptr", address, "Ptr", 

&MVALUE, "UInt", numBytes, "UIntP", numBytesRead, "UInt")

    if !DllCall("CloseHandle", "Ptr", processHandle, "UInt") && !result
        Throw Exception("Failed to close process handle.`n`nError code:`t" . A_LastError)

    if !result
        Throw Exception("Failed to read process memory.`n`nError code:`t" . A_LastError)

    if !numBytesRead
        Throw Exception("Read 0 bytes from the`n`nprocess:`t" processIDorName "`naddress:`t" 

address)

    return NumGet(MVALUE, 0, type)
}

WriteMemory(data, address, processIDorName, type = "Int", numBytes = 4)
{
    VarSetCapacity(buf, numBytes, 0)
    NumPut(data, buf, 0, type)

    Process, Exist, %processIDorName%
    if !processID := ErrorLevel
        Throw Exception("Invalid process name or process ID:`n`n""" . processIDorName . 

"""")

    if !processHandle := DllCall("OpenProcess", "Int", 40, "UInt", 0, "UInt", processID, 

"Ptr")
        Throw Exception("Failed to open process.`n`nError code:`t" . A_LastError)

    result := DllCall("WriteProcessMemory", "Ptr", processHandle, "Ptr", address, "Ptr", 

&buf, "UInt", numBytes, "UInt", 0, "UInt")

    if !DllCall("CloseHandle", "Ptr", processHandle, "UInt") && !result
        Throw Exception("Failed to close process handle.`n`nError code:`t" . A_LastError)

    if !result
        Throw Exception("Failed to write process memory.`n`nError code:`t" . A_LastError)

    return result
}
ExitApp

Пробовал переименовать функции, но мне сложно понять что изменять и поэтому не получается(

2 (изменено: creature.ws, 2013-05-19 22:37:13)

Re: AHK: В GUI дублируются функции

Код, приведенный ниже, подразумевается использовать вместо примера из первого сообщения.

processName := "gta_sa.exe"
baseAddressPointer := 0xB7CD98
healthOffset := 0x540
armourOffset := 0x548

Gui Margin, 20, 10
Gui Add, Edit, w30 vhealthValue, 9
Gui Add, Button, x+10 yp Section gHealth, Set Health
Gui Add, Edit, w30 xm varmourValue, 50
Gui Add, Button, xs yp gArmour, Set Armour
Gui Show
return

GuiClose:
    ExitApp

Health:
Armour:
    GuiControlGet healthValue
    GuiControlGet armourValue

    try {
        if !baseAddress {
            baseAddress := ProcessReadMemory(baseAddressPointer, processName)
            healthAddress := baseAddress + healthOffset
            armourAddress := baseAddress + armourOffset
        }
        ProcessWriteMemory(%A_ThisLabel%Value, %A_ThisLabel%Address, processName, "float")
    }
    catch e
        MsgBox % e.Message
    return

ProcessReadMemory(address, processIDorName, type := "Int", numBytes := 4) {
    VarSetCapacity(buf, numBytes, 0)

    Process Exist, %processIDorName%
    if !processID := ErrorLevel
        throw Exception("Invalid process name or process ID:`n`n""" . processIDorName . """")

    if !processHandle := DllCall("OpenProcess", "Int", 24, "UInt", 0, "UInt", processID, "Ptr")
        throw Exception("Failed to open process.`n`nError code:`t" . A_LastError)

    result := DllCall("ReadProcessMemory", "Ptr", processHandle, "Ptr", address, "Ptr", &buf, "Ptr", numBytes, "PtrP", numBytesRead, "UInt")

    if !DllCall("CloseHandle", "Ptr", processHandle, "UInt") && !result
        throw Exception("Failed to close process handle.`n`nError code:`t" . A_LastError)

    if !result
        throw Exception("Failed to read process memory.`n`nError code:`t" . A_LastError)

    if !numBytesRead
        throw Exception("Read 0 bytes from the`n`nprocess:`t" . processIDorName . "`naddress:`t" . address)

    return (type = "Str")
        ? StrGet(&buf, numBytes)
        : NumGet(buf, type)
}

ProcessWriteMemory(ByRef data, address, processIDorName, type := "Int", numBytes := 4) {
    VarSetCapacity(buf, numBytes, 0)
    (type = "Str")
        ? StrPut(data, &buf, numBytes)
        : NumPut(data, buf, type)

    Process Exist, %processIDorName%
    if !processID := ErrorLevel
        throw Exception("Invalid process name or process ID:`n`n""" . processIDorName . """")

    if !processHandle := DllCall("OpenProcess", "Int", 40, "UInt", 0, "UInt", processID, "Ptr")
        throw Exception("Failed to open process.`n`nError code:`t" . A_LastError)

    result := DllCall("WriteProcessMemory", "Ptr", processHandle, "Ptr", address, "Ptr", &buf, "Ptr", numBytes, "UInt", 0, "UInt")

    if !DllCall("CloseHandle", "Ptr", processHandle, "UInt") && !result
        throw Exception("Failed to close process handle.`n`nError code:`t" . A_LastError)

    if !result
        throw Exception("Failed to write process memory.`n`nError code:`t" . A_LastError)

    return result
}

3

Re: AHK: В GUI дублируются функции

Спасибо все работает

Но как в этот код вставить другой оффсет если оно не float и изменять его не надо?

Базовый адрес тот же, offset = 0x474, value = 2(делает игрока невидимым) тип данных dword. Я пробовал пробовал, но у меня не получалось, ошибки не выдавало, но перс не становился невидимым, либо во обще ничего не работало ни невидимость ни жизни ни броня(

4 (изменено: creature.ws, 2013-04-03 21:31:32)

Re: AHK: В GUI дублируются функции

изменять его не надо

А что с ним следует сделать?

как в этот код вставить другой оффсет

При нажатии кнопок Set Armour или Set Health выполняются подпрограммы начинающиеся с метки Armour или Health соответственно. «Другой оффсет» к установке значения armour или health отношения не имеет.
Определитесь, что с значением по смещению 0x474 нужно делать и как эти действия должны выполнятся, после — добавьте соответствующий фрагмент кода.
Dword это Uint.

5 (изменено: Dworkin, 2013-04-03 22:26:52)

Re: AHK: В GUI дублируются функции

creature.ws пишет:

изменять его не надо

А что с ним следует сделать?

Я имел ввиду что не надо создавать в GUI "Gui Add, Edit".

Знаю что без code, но в code нельзя выставить цвет текста, так что извиняюсь.

Красным я выделил что добавил.


AutoHotkey script пишет:

processName := "gta_sa.exe"
baseAddressPointer := 0xB7CD98
healthOffset := 0x540
armourOffset := 0x548
invisibleoffset := 0x470

Gui Margin, 20, 10
Gui Add, Edit, w30 vhealthValue, 9
Gui Add, Button, x+10 yp Section gHealth, Set Health
Gui Add, Edit, w30 xm varmourValue, 50
Gui Add, Button, xs yp gArmour, Set Armour
Gui Add, Button, xs y+20 gInvisible, Invisible
Gui Show
return

GuiClose:
    ExitApp

Health:
Armour:
    GuiControlGet healthValue
    GuiControlGet armourValue

    try {
        if !baseAddress {
            baseAddress := ProcessReadMemory(baseAddressPointer, processName)
            healthAddress := baseAddress + healthOffset
            armourAddress := baseAddress + armourOffset
        }
        ProcessWriteMemory(%A_ThisLabel%Value, %A_ThisLabel%Address, processName, "float")
    }
    catch e
        MsgBox % e.Message
    return

Invisible:

try
invisibleValue(3)


invisibleValue(value)
    GuiControlGet invisiblehValue
try {
        if !baseAddress {
            baseAddress := ProcessReadMemory(baseAddressPointer, processName)
            invisibleAddress := baseAddress + invisibleOffset
        }
        WriteMemory(value, invisibleAddress, "gta_sa.exe", "Uint")
    }
    catch e
        MsgBox % e.Message
    return

ProcessReadMemory(address, processIDorName, type := "Int", numBytes := 4) {
    VarSetCapacity(buf, numBytes, 0)
    VarSetCapacity(numBytesRead, A_PtrSize, 0)

    Process Exist, %processIDorName%
    if !processID := ErrorLevel
        throw Exception("Invalid process name or process ID:`n`n""" . processIDorName .

"""")

    if !processHandle := DllCall("OpenProcess", "Int", 24, "UInt", 0, "UInt", processID,

"Ptr")
        throw Exception("Failed to open process.`n`nError code:`t" . A_LastError)

    result := DllCall("ReadProcessMemory", "Ptr", processHandle, "Ptr", address, "Ptr",

&buf, "Ptr", numBytes, "PtrP", numBytesRead, "UInt")

    if !DllCall("CloseHandle", "Ptr", processHandle, "UInt") && !result
        throw Exception("Failed to close process handle.`n`nError code:`t" . A_LastError)

    if !result
        throw Exception("Failed to read process memory.`n`nError code:`t" . A_LastError)

    if !numBytesRead
        throw Exception("Read 0 bytes from the`n`nprocess:`t" . processIDorName .

"`naddress:`t" . address)

    return NumGet(buf, 0, type)
}

ProcessWriteMemory(data, address, processIDorName, type := "Int", numBytes := 4) {
    VarSetCapacity(buf, numBytes, 0)
    NumPut(data, buf, 0, type)

    Process Exist, %processIDorName%
    if !processID := ErrorLevel
        throw Exception("Invalid process name or process ID:`n`n""" . processIDorName .

"""")

    if !processHandle := DllCall("OpenProcess", "Int", 40, "UInt", 0, "UInt", processID,

"Ptr")
        throw Exception("Failed to open process.`n`nError code:`t" . A_LastError)

    result := DllCall("WriteProcessMemory", "Ptr", processHandle, "Ptr", address, "Ptr",

&buf, "Ptr", numBytes, "UInt", 0, "UInt")

    if !DllCall("CloseHandle", "Ptr", processHandle, "UInt") && !result
        throw Exception("Failed to close process handle.`n`nError code:`t" . A_LastError)

    if !result
        throw Exception("Failed to write process memory.`n`nError code:`t" . A_LastError)

    return result
}

6 (изменено: creature.ws, 2013-05-19 22:36:44)

Re: AHK: В GUI дублируются функции

По смещению 0x474 находятся 4 байта (dword), 4 байта  это 32 бита, каждый бит может принимать значение 0 или 1, т.е. в 4 байта можно записать аж 32 логических значения «что-то включено или выключено».
+2 подразумевает, что второй бит dword'а по смещению 0x474 отвечает за «невидимость».

processName := "gta_sa.exe"
baseAddressPointer := 0xB7CD98
healthOffset := 0x540
armourOffset := 0x548
pedStateOffset := 0x474 ; и не спрашивайте, что такое Ped

Gui Margin, 20, 10
Gui Add, Edit, w30 vhealthValue, 9
Gui Add, Button, x+10 yp Section gHealth, Set Health
Gui Add, Edit, w30 xm varmourValue, 50
Gui Add, Button, xs yp gArmour, Set Armour
Gui Add, Button, xm gInvisibility, Toggle invisibility
Gui Show
return

GuiClose:
    ExitApp

Invisibility:
    if !baseAddress
        InitAddresses()

    pedState := ProcessReadMemory(pedStateAddress, processName, "UInt")

    if (A_ThisLabel = "Invisibility") ; на случай добавления кнопок и меток переключающих значения в pedState
        ToggleInvisibilityBit(pedState)

    ProcessWriteMemory(pedState, pedStateAddress, processName, "UInt")
    return

Health:
Armour:
    GuiControlGet healthValue
    GuiControlGet armourValue

    if !baseAddress
        InitAddresses()

    ProcessWriteMemory(%A_ThisLabel%Value, %A_ThisLabel%Address, processName, "float")
    return

InitAddresses() {
    global
    baseAddress := ProcessReadMemory(baseAddressPointer, processName)
    healthAddress := baseAddress + healthOffset
    armourAddress := baseAddress + armourOffset
    pedStateAddress := baseAddress + pedStateOffset
}

ToggleInvisibilityBit(ByRef pedState ) {
    pedState ^= 1 << 1 ; так переключается 2-й бит.
}


ProcessReadMemory(address, processIDorName, type := "Int", numBytes := 4) {
    VarSetCapacity(buf, numBytes, 0)

    Process Exist, %processIDorName%
    if !processID := ErrorLevel
        throw Exception("Invalid process name or process ID:`n`n""" . processIDorName . """")

    if !processHandle := DllCall("OpenProcess", "Int", 24, "UInt", 0, "UInt", processID, "Ptr")
        throw Exception("Failed to open process.`n`nError code:`t" . A_LastError)

    result := DllCall("ReadProcessMemory", "Ptr", processHandle, "Ptr", address, "Ptr", &buf, "Ptr", numBytes, "PtrP", numBytesRead, "UInt")

    if !DllCall("CloseHandle", "Ptr", processHandle, "UInt") && !result
        throw Exception("Failed to close process handle.`n`nError code:`t" . A_LastError)

    if !result
        throw Exception("Failed to read process memory.`n`nError code:`t" . A_LastError)

    if !numBytesRead
        throw Exception("Read 0 bytes from the`n`nprocess:`t" . processIDorName . "`naddress:`t" . address)

    return (type = "Str")
        ? StrGet(&buf, numBytes)
        : NumGet(buf, type)
}

ProcessWriteMemory(ByRef data, address, processIDorName, type := "Int", numBytes := 4) {
    VarSetCapacity(buf, numBytes, 0)
    (type = "Str")
        ? StrPut(data, &buf, numBytes)
        : NumPut(data, buf, type)

    Process Exist, %processIDorName%
    if !processID := ErrorLevel
        throw Exception("Invalid process name or process ID:`n`n""" . processIDorName . """")

    if !processHandle := DllCall("OpenProcess", "Int", 40, "UInt", 0, "UInt", processID, "Ptr")
        throw Exception("Failed to open process.`n`nError code:`t" . A_LastError)

    result := DllCall("WriteProcessMemory", "Ptr", processHandle, "Ptr", address, "Ptr", &buf, "Ptr", numBytes, "UInt", 0, "UInt")

    if !DllCall("CloseHandle", "Ptr", processHandle, "UInt") && !result
        throw Exception("Failed to close process handle.`n`nError code:`t" . A_LastError)

    if !result
        throw Exception("Failed to write process memory.`n`nError code:`t" . A_LastError)

    return result
}

7

Re: AHK: В GUI дублируются функции

Спасибо огромное все работает, смог добавить что-то еще сам

8

Re: AHK: В GUI дублируются функции

Я изменил кое-что в первом сообщении.

Спасибо, так лучше!