Raised This Month: $12 Target: $400
 3% 

[TYT] Calling functions with LTCG optimization via SDKCall on Windows


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
gubka
Veteran Member
Join Date: Jan 2012
Location: Russia
Old 01-15-2020 , 12:22   [TYT] Calling functions with LTCG optimization via SDKCall on Windows
Reply With Quote #1

Since when using LTCG, internal functions often have their own call convention, you can't just call them via SDKCall on Windows, so you need to make a "translator" function that will match stdcall and call the desired function.

For example, let's take CBaseAnimating:: Sequence Duration. it returns via xmm0, the "translator" function is as follows

PHP Code:
55                      push   ebp
89 e5                   mov    ebp
,esp
8b 45 0c                mov    eax
,DWORD PTR [ebp+0xc]
50                      push   eax
8b 45 08                mov    eax
,DWORD PTR [ebp+0x8]
50                      push   eax
b8 00 00 00 00          mov    eax
,0x0 in 0x0 write our function address which should call inside transistor func
ff d0                   call   eax
f3 0f 11 44 24 fc       movss  DWORD PTR 
[esp-0x4],xmm0 move value from xmm0 in stack
d9 44 24 fc             fld    DWORD PTR 
[esp-0x4] ; move value from stack to FPU stack (where float value should be)
89 ec                   mov    esp,ebp
5d                      pop    ebp
c2 08 00                ret    0x8 
It remains the most important thing to implement it somehow on sourcepawn and here comes to the aid of a very good article of Kailo Blog: Working with memory in SourcePawn based on it, Phoenix (PTaH author) did this example

Example: xmm0 reg parameter and return function
Spoiler


GameData:
Spoiler


I also used a similar approach to call a function with fastcall convection which not clear the stack is well. The translator function pop the param from the top of the stack to ecx, edx regs and use a trampoline to call needed function.

Example: fastcall for windows from zp core
Spoiler
__________________

Last edited by gubka; 01-16-2020 at 17:55.
gubka is offline
Send a message via ICQ to gubka
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 19:07.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode