How to write "mathematical function" in script in CE 6.8.1?

Memory scanning, code injection, debugger internals and other gamemodding related discussion
Post Reply
marek1957
Expert Cheater
Expert Cheater
Posts: 283
Joined: Sat Dec 16, 2017 4:46 pm
Reputation: 4

How to write "mathematical function" in script in CE 6.8.1?

Post by marek1957 » Mon Jun 25, 2018 10:27 am

Hello guys!

First of all - thank you so much [B][USER=12587] SunBeam[/USER][/B],[B][USER=91]TheyCallMeTim13[/USER] [/B]and other people who helped me - thanks to your help I learnt a lot new things and I want still learning.

But I have new problem in my script.

And I don't have any idea how to solve this problem :)



The main problem is: I don't know how to write a "mathematical function" in my script.

But let me explain first.



I made a script:

[code]code:

push eax

mov eax,[VALUE]

movd xmm4,eax

movaps xmm1,xmm4

movss [ebp-08],xmm4

mulss xmm1,xmm2

pop eax

ret



code1:

push eax

mov eax,[VALUE]

movd xmm4,eax

movaps xmm1,xmm4

movss [ebp-18],xmm4

mulss xmm1,xmm2

pop eax

ret[/code]



This is a part of my script but script is working 100%.

Like you can see in my script, I am moving global allocating value into EAX - this is good BUT - I checked in game that: if I want to have a 10 value in a game I must write: 3.3333 in FLOAT or 40555555 in HEX or 1079334229 in 4-BYTES - these all values mean 10 VALUE in game!



So, going further, I checked that:

- If you want to have a 100 value in a game you must write in the script:

float: 100

hex: 42C80000

4 bytes: 1120403456



- If you want to have a 50 value in a game you must write in the script:

float: 16.6666

hex: 41855532

4 bytes: 1099257138



- If you want to have a 20 value in a game you must write in the script:

float: 6.6666

hex: 40d55554

4 bytes: 1087722836



and etc. etc.



So my question is: IS IT POSSIBLE to add to my script a MATHEMATICAL FUNCTION which will convert these strange values to normal values - that If I wanted to have a 50 value in game, I will write a 50 value and If I wanted to have a 20 value in game, I will write a 20 value and etc. etc. ??? Is it possible to add something like that? It is very hard to remember all that type of values to put them all the time.



I have a hope that you will understand me :)

I am waiting for your advices.



Original code where I am injecting my script is:

[code]movaps xmm1,xmm4

movss [ebp-08],xmm4

mulss xmm1,xmm2[/code]
Last edited by marek1957 on Thu Jan 01, 1970 12:00 am, edited 3 times in total.

User avatar
SunBeam
Trouble Makers
Trouble Makers
Posts: 1505
Joined: Sun Feb 04, 2018 7:16 pm
Reputation: 224

How to write "mathematical function" in script in CE 6.8.1?

Post by SunBeam » Mon Jun 25, 2018 11:02 am

Ever considered writing it like this?



[code]label( VALUE )

registersymbol( VALUE )

..

..

mov eax,[VALUE]

..

..



VALUE:

dd (float)10.0[/code]





"Does it work like that?" -- Yes :)



Then add [B]VALUE[/B] to your list, as a pointer, of type FLOAT. Then you can change that value to your liking, as float :P
Last edited by SunBeam on Thu Jan 01, 1970 12:00 am, edited 1 time in total.

marek1957
Expert Cheater
Expert Cheater
Posts: 283
Joined: Sat Dec 16, 2017 4:46 pm
Reputation: 4

How to write "mathematical function" in script in CE 6.8.1?

Post by marek1957 » Mon Jun 25, 2018 11:44 am

Ok, I will try that bro :-)

1529928195

[B]SunBeam[/B], it is working great, thank you... BUT - I cannot change value here:



[img]https://i.imgur.com/4uu0SCx.png[/img]



I want to have ability to write a value that I want not in the script, but "outside" the script like when you are using globalalloc(something,4)



And this doesn't solve my problem because if I want to have 100 value in game, I must write in float:

[img]https://i.imgur.com/9fGpQvC.png[/img]



But I am trying to ask if it is possible to add a function that will give me possibility to write the 100 value but the in the script it will inject a 33.3333 float value.



You understand SunBeam?



I also make a list with values:



[img]https://i.imgur.com/uxIkqmz.png[/img]
Last edited by marek1957 on Mon Jun 25, 2018 12:03 pm, edited 3 times in total.

User avatar
SunBeam
Trouble Makers
Trouble Makers
Posts: 1505
Joined: Sun Feb 04, 2018 7:16 pm
Reputation: 224

How to write "mathematical function" in script in CE 6.8.1?

Post by SunBeam » Mon Jun 25, 2018 12:10 pm

I'll write up a small thread in [I]Calculator.exe[/I] and test your code. If it does what I think it does, as in converting a decimal value to float, then moving it to a MMX register, then you don't need any conversion. All you need is "movss xmm0,[value]". And that's that :P Be back in a bit.

User avatar
koderkrazy
Fearless Donors
Fearless Donors
Posts: 248
Joined: Sun Jun 17, 2018 2:14 pm
Reputation: 157

How to write "mathematical function" in script in CE 6.8.1?

Post by koderkrazy » Mon Jun 25, 2018 12:42 pm

If calculations are more or there is look up. Write Lua function and call it in your Asm.



See this link:

[URL]https://fearlessrevolution.com/threads/example-log-game-data-using-simple-logger-asm-lua.7288/[/URL]

Instead of myLog write your own calculation method. And call it in Asm.

User avatar
SunBeam
Trouble Makers
Trouble Makers
Posts: 1505
Joined: Sun Feb 04, 2018 7:16 pm
Reputation: 224

How to write "mathematical function" in script in CE 6.8.1?

Post by SunBeam » Mon Jun 25, 2018 3:14 pm

[USER=11389]@marek1957[/USER]: That code you put up takes in an integer as value, converts it to float when moved to xmm4, then you don't do anything with xmm4 (the mulss is done between xmm1 and xmm2). No wonder your code doesn't work. My question is why don't you use direct floats in MMX?



[code]movss xmm0,[VALUE]

movss xmm1,[fMultiplier]

mulss xmm0,xmm1 // this does 100.0 * 2.0 == 200.0



VALUE:

dd (float)100.0



fMultiplier:

dd (float)2.0[/code]





If you want to adapt it to the table you posted, just think the math behind it: [URL]https://en.wikipedia.org/wiki/Cross-multiplication#Rule_of_Three[/URL].



So..



If 100% == (float)33.3, what's the float value for 45%? 33.3 * 100 / 45 = (float)14.985. So what you can do to get the equivalent float per percentage entry would be this:



[code][ENABLE]



alloc( RunHandlerThread, 0x1000 )

registersymbol( RunHandlerThread )

CreateThread( RunHandlerThread )

label( RunHandlerOff )

registersymbol( RunHandlerOff )



label( l_RunHandlerThread )

label( bRun )

registersymbol( bRun )



label( MyPercentage )

registersymbol( MyPercentage )

label( fMultiplier )

label( fOneHundred )

label( fCalculated )

registersymbol( fCalculated )



RunHandlerThread:

sub rsp,28



l_RunHandlerThread:

mov rcx,A

call Sleep

cmp [RunHandlerOff],1

jne short @f

add rsp,28

mov [RunHandlerOff],2

ret

@@:

cmp [bRun],0

je short @f

call short TestRun

mov [bRun],0

mov rcx,C8

call Sleep

@@:

jmp l_RunHandlerThread



align 4 CC



TestRun:

push eax

mov eax,[MyPercentage]

cvtsi2ss xmm0,eax

movss xmm1,[fOneHundred]

movss xmm2,[fMultiplier]

mulss xmm0,xmm1

mulss xmm0,xmm2

movss [fCalculated],xmm0

pop eax

ret



align 4 CC



RunHandlerOff:

dd 0



align 4 CC



bRun:

dd 0



align 4 CC



MyPercentage:

dd #45



fMultiplier:

dd (float)0.01



align 4 CC



fOneHundred:

dd (float)33.3



align 4 CC



fCalculated:

dd 0



[DISABLE]



{$lua}



if( syntaxcheck == false ) then --actual execution

local starttime = getTickCount()



if readInteger( "RunHandlerOff" ) == 0 then --could be 2 already

writeInteger( "RunHandlerOff", 1 ) --tell the thread to kill itself

end



while( getTickCount() < starttime + 1000 ) and ( readInteger( "RunHandlerOff" ) ~= 2 ) do --wait till it has finished

sleep( 20 )

end



if( getTickCount() > starttime + 1000 ) then --could happen when the window is shown

showMessage( 'Disabling the thread failed!' )

error( 'Thread disabling failed!' )

end

sleep( 1 )

end



{$asm}



unregistersymbol( fCalculated )

unregistersymbol( MyPercentage )

unregistersymbol( bRun )

unregistersymbol( RunHandlerOff )

unregistersymbol( RunHandlerThread )

dealloc( RunHandlerThread )[/code]





And see my run below:



[img]https://i.imgur.com/X7ta0Uk.png[/img]



BR,

Sun
Last edited by SunBeam on Mon Jun 25, 2018 3:31 pm, edited 1 time in total.

marek1957
Expert Cheater
Expert Cheater
Posts: 283
Joined: Sat Dec 16, 2017 4:46 pm
Reputation: 4

How to write "mathematical function" in script in CE 6.8.1?

Post by marek1957 » Mon Jun 25, 2018 3:15 pm

[B]My question is why don't you use direct floats in MMX?[/B]

Because I am little stupid and I don't have so much knowledge like you my master

User avatar
SunBeam
Trouble Makers
Trouble Makers
Posts: 1505
Joined: Sun Feb 04, 2018 7:16 pm
Reputation: 224

How to write "mathematical function" in script in CE 6.8.1?

Post by SunBeam » Mon Jun 25, 2018 3:33 pm

[USER=11389]@marek1957[/USER]:



See my above post (I edited it).



Get the code, copy-paste it to your table and try it. Target doesn't have to be [I]Calculator[/I]. Can be run in any targeted process. Once you enable the script, change [I]MyPercentage[/I] to the one you need conversion for - - I used [B]45 [/B](%) - - then set [I]bRun[/I] to [B]1[/B]. So for value 45 the operations done are 45 * 33.3 (amount for 100%) * 0.01. And I get [B]14.985[/B], which is the float value that corresponds to 45% in your table.



Is this what you wanted?



And use this link for a list of MMX instructions :p -> [URL]http://softpixel.com/~cwright/programming/simd/mmx.php[/URL]
Last edited by SunBeam on Tue Jun 26, 2018 9:56 am, edited 2 times in total.

Post Reply

Who is online

Users browsing this forum: No registered users