Jump to content
Moopler
Sign in to follow this  
NORBIN

Help [Solved] Looking for some advice on using AA in a Lua script.

Recommended Posts

Hey guys, haven't really formally introduced myself around here but it's nice to meet all of you!

I'm still quite a novice at scripting/hacking in general and I've been having some trouble figuring out what I am doing incorrectly here, was hoping there might be someone who's messed around with CEs Lua Engine before that could offer some input. (hopefully I didn't post in the incorrect section)

I'm using this Kami AA script by Francesco (updated for GMS v175): https://puu.sh/qBszd/ccef098a3e.txt

I have a ToggleBox and an EditBox set up like I normally would for any other script, the EditBox is supposed to change the Kami_LootWhen number of items and the ToggleBox is supposed to Enable/Disable of course. The problem is I can't seem to get the Disable part of the script working properly, after enabling it Kami starts working perfectly fine, and the EditBox changes what it's supposed to, but toggling the box won't disable it. The only way to stop it is to assign the script to your address list and enable/disable it again from there. This is the only script I've ever had this kind of issue with, and I'm curious if it's just me being a derp or if there's something that needs to be adjusted in the [Disable] section for it to work with Lua. Unfortunately I know almost next to nothing about assembly, and haven't had much luck with lurking CEF either.

Lua Script

 

--- Kami ToggleBox

function StartKamiBottingChange(sender)
  if (checkbox_getState(UDF1.StartKamiBotting) == 1) then
    autoAssemble(string.format([[

define(KEY_NORMAL,0)
define(KEY_EXTENDED,1)
define(VK_CONTROL,11)
define(Kami_HoldAttack,0)
define(Kami_AttackKey,VK_CONTROL)
define(Kami_AttackKeyType,KEY_EXTENDED)
define(Kami_LootKey,'Z')
define(Kami_LootKeyType,KEY_NORMAL)
define(Kami_RangeX,#0)
define(Kami_RangeY,#0)
define(Kami_LootWhen,%X)
define(TSingleton_CUserLocal___ms_pInstance,0225E764)
define(TSingleton_CMobPool___ms_pInstance,02262F90)
define(TSingleton_CWndMan___ms_pInstance,022630C8)
define(CWndMan__OnKey,01910D60)
define(GetVectorController,018370D0)
define(TeleportFunc,0167DAA0)
define(TSingleton_CDropPool___ms_pInstance,022639DC)
define(pUpdateFunc,01FD5F28)
define(UpdateFunc,0173C770)
define(UpdateHook_ret,0171FBFA)
define(TSingleton_CWvsPhysicalSpace2D___ms_pInstance,02262F84)
define(pPtInRect,02279D2C)
define(PtInRectHook_ret,00761A64)
define(Mob3Offset,1B4)

globalalloc(Kami,512)
globalalloc(ItemHook,128)
globalalloc(GetMobXY,512)
globalalloc(NewTeleportXY,128)
globalalloc(PressKey,128)
globalalloc(ItemX,4)
globalalloc(ItemY,4)
globalalloc(HoldAttack,1)
globalalloc(IsLooting,1)
globalalloc(LootWhen,4)

label(TeleTopLeft)
label(GetMobXYFalse)
label(GetMobXYTrue)
label(TeleportEnd)
label(NextMob)
label(Loot)
label(KamiExit)
label(NoLoot)

registersymbol(Kami_LootWhen)

HoldAttack:
db Kami_HoldAttack

LootWhen:
dw Kami_LootWhen

IsLooting:
db 0

GetMobXY:
push esi
push edx
push ebx
mov esi,[TSingleton_CMobPool___ms_pInstance]
test esi,esi
je GetMobXYFalse
mov edx,[esi+10]
test edx,edx
je GetMobXYFalse
mov esi,[esi+28]
test esi,esi
je GetMobXYFalse
sub esi,10

NextMob:
mov edx,[esi+14]
test edx,edx
je GetMobXYFalse
mov edx,[edx+Mob3Offset]
test edx,edx
je GetMobXYFalse
mov edx,[edx+24]
test edx,edx
je GetMobXYFalse
mov ebx,[edx+68]
or ebx,[edx+6C]
test ebx,ebx
jne GetMobXYTrue
mov esi,[esi+04]
test esi,esi
je GetMobXYFalse
jmp NextMob
GetMobXYFalse:
pop ebx
pop edx
pop esi
xor eax,eax
ret

GetMobXYTrue:
lea eax,[edx+60]
pop ebx
pop edx
pop esi
ret

NewTeleportXY:
mov esi,[TSingleton_CUserLocal___ms_pInstance]
lea ecx,[esi+04]
call GetVectorController
test eax,eax
je TeleportEnd
push ebx
push edx
push 00
mov ecx,eax
call TeleportFunc

TeleportEnd:
ret
define(KEY_PRESS,0)
define(KEY_UP,1)
define(MAPVK_VK_TO_VSC,0)
PressKey:
push ebx
push edx
push esi
push ecx
mov edx, [esp+10+4]
mov esi, [esp+10+8]
mov ebx, [esp+10+C]
mov ecx, edx
push MAPVK_VK_TO_VSC
push ecx
call MapVirtualKeyA
shl eax,#16
shl esi,#24
shl ebx,#31
or eax, esi
or eax, ebx
mov ecx,eax
push ecx
push edx
mov ecx,[TSingleton_CWndMan___ms_pInstance]
call CWndMan__OnKey
pop ecx
pop esi
pop edx
pop ebx
ret 000C

Kami:
cmp dword ptr [esp], UpdateHook_ret
pushad
jne KamiExit
mov eax,[TSingleton_CUserLocal___ms_pInstance]
test eax,eax
je KamiExit
call GetMobXY
test eax,eax
je Loot
cmp byte ptr [IsLooting], 1
je Loot
cmp dword ptr [LootWhen], #-1
je NoLoot
mov esi,[TSingleton_CDropPool___ms_pInstance]
mov esi,[esi+14]
cmp esi,dword ptr [LootWhen]
jge Loot

NoLoot:
mov ebx,[eax+4]
sub ebx,Kami_RangeY
mov edx,[eax]
sub edx,Kami_RangeX
call NewTeleportXY
push KEY_PRESS
push Kami_AttackKeyType
push Kami_AttackKey
call PressKey
cmp byte ptr [HoldAttack], 0
je KamiExit
push KEY_UP
push Kami_AttackKeyType
push Kami_AttackKey
call PressKey
jmp KamiExit

Loot:
mov esi,[TSingleton_CDropPool___ms_pInstance]
mov esi,[esi+14]
cmp esi,0
je TeleTopLeft
mov byte ptr [IsLooting], 1
push KEY_PRESS
push Kami_LootKeyType
push Kami_LootKey
call PressKey
mov ebx,[ItemY]
mov edx,[ItemX]
call NewTeleportXY
jmp KamiExit

TeleTopLeft:
mov byte ptr [IsLooting], 0
mov edx,[TSingleton_CWvsPhysicalSpace2D___ms_pInstance]
mov edx,[edx+0C]
mov ebx,[TSingleton_CWvsPhysicalSpace2D___ms_pInstance]
mov ebx,[ebx+10]
call NewTeleportXY

KamiExit:
popad
jmp UpdateFunc
ItemHook:
cmp [esp],PtInRectHook_ret
jne PtInRect
push eax
mov eax,[esp+0C]
mov [ItemX],eax
mov eax,[esp+10]
mov [ItemY],eax
pop eax
jmp PtInRect

pUpdateFunc:
dd Kami

pPtInRect:
dd ItemHook

     ]],tonumber(UDF1.LootWhen.Text)))
   else
     autoAssemble([[

pUpdateFunc:
dd UpdateFunc

pPtInRect:
dd PtInRect
unregistersymbol(Kami_LootWhen)

     ]])
  end
end

--- Loot when > number of items EditBox

function LootWhenChange(sender)
local value=tonumber(UDF1.LootWhen.Text)
  if (checkbox_getState(UDF1.LootWhen) == 1) then
    writeInteger("Kami_LootWhen", value)
  end
end

I also made a quick example table in case my description didn't really make sense to you, the script for Kami will be assigned to CE already so you can see the difference between the Lua vs. AA if you want to test it in-game.

2bbdafff53.png

And a big thanks in advance to anyone who might be able to help out, I really do appreciate all the knowledge the community has had to offer so far. It's been a huge help ^_^

KamiExample.CT

Edited by NORBIN

Share this post


Link to post

i think the problem is that you use pPtInRect and pUpdateFunc in [disable] section

it defined in [enable] section but not in [disable] section

so CE cannot figure out what it is

solution is that simply change it to address manually

Edited by ngnam87
  • Like 1

Share this post


Link to post

Solved thanks to @ngnam87  :) Glad it was just a simple mistake on my part :drop:

I'll leave the working .ct here for those who might read in the future & would like a reference for their own tables, it's nothing special of course but who knows maybe someone will get some use out of it. AOBs are in the puu.sh link I posted.

 

 

 

KamiExample.CT

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×