Commit Graph

22 Commits

Author SHA1 Message Date
Peace-Maker
891fa5352e Add support for the "fastcall" calling convention
Callee cleans the stack and first two arguments are passed in registers ecx and edx.
You could emulate this by choosing stdcall and setting the custom_registers on the arguments manually, but this is easier.
2019-06-20 02:14:07 +02:00
Peace-Maker
70eee8482a Fix compilation against SourceMod 1.10
MacroAssembler base is now in the |sp| namespace.
2019-05-06 18:29:40 +02:00
Peace-Maker
274b4276c0 Fix crash on unaligned SSE instructions
movaps requires the memory address to be 16-byte aligned. Make sure our buffer is properly aligned for the xmm0-7 registers.
2018-10-05 14:13:12 +02:00
Peace-Maker
a89eb67124 Fix detour of functions returning a float
Floats are always returned in FPU register st0. Since the value in st0 doesn't matter in a pre-hook before the function was executed, don't try to save and restore the value of the FPU stack top for a pre-hook.
Only replace st0 after a post hook.
2018-08-18 12:54:30 +02:00
Peace-Maker
382287b86a Improve error message on bad detour argument setup 2018-08-08 01:03:06 +02:00
Peace-Maker
9da7e666f6 Fix |thiscall| on linux for functions with arguments
The previous fix messed up parameter getters and setters.
2018-06-02 13:36:52 +02:00
Peace-Maker
30fc311738 Fix linux build 2018-04-22 15:56:40 +02:00
Peace-Maker
2df53be4a5 Fix signed - unsigned comparison warning 2018-04-21 13:41:50 +02:00
Peace-Maker
274758c4ff Fix not using passed alignment value for argument sizes 2018-04-18 00:58:56 +02:00
Peace-Maker
b16d1f9f3f Fix crash when accessing invalid argument index
Just return null if a user tries to access an invalid argument that wasn't defined when detouring the function.
2018-04-18 00:57:58 +02:00
Peace-Maker
9bbca712b6 Fix detouring |thiscall| on linux
The this-pointer is always pushed first on the stack.
2018-04-18 00:50:26 +02:00
Peace-Maker
b365b775c9 Fix linux build 2018-01-27 17:24:02 +01:00
Peace-Maker
94181be280 Fix assert when the pre-hook was fired, but the post hook was skipped
The post hook would have cleared the esp value from the return address map, but there seems to be a case where the post hook isn't called, but the function gets called with the same esp again. This is probably just masking a different error :(
2018-01-23 03:16:46 +01:00
Peace-Maker
1b9fa3743f Add support for custom calling convention passing arguments in registers
If the compiler decided to pass an argument in a register on an internal function instead of pushing it on the stack to save time, allow us to specify the register the parameter is going to be in.

DHookAddParam received another parameter to set the register.
2018-01-23 03:15:03 +01:00
Peace-Maker
5d21350e9e Fix not clearing return address cache after use
The esp pointer wasn't removed from the map after the function was called and the original return address was retrieved.
If the same function was called again with the same esp this would fail due to there already being an (old) return address associated with the esp.
2018-01-22 00:11:28 +01:00
Peace-Maker
8221a6522b Save this pointer on windows after calling original function
ecx might get cleared before the original function returns leading to garbage in the post handler.
2016-12-13 17:47:59 -07:00
Peace-Maker
b18e3284e1 Fix overriding return value
The custom return value was lost when calling the original function.
Save and restore our own return value, if we're about to call the original function.
2016-12-13 17:45:22 -07:00
Peace-Maker
6e96e0fb84 Don't use std::list at all in DynamicHooks
Switch to amtl Vector.
2016-12-13 17:37:12 -07:00
Peace-Maker
c70d3b9ee0 Use AMTL instead of the stdlib in DynamicHooks 2016-12-13 00:34:28 -07:00
Peace-Maker
63c6addc30 Fix new - free mismatch 2016-12-12 22:47:35 -07:00
Peace-Maker
764b325a1e Switch to sp::MacroAssembler instead of AsmJit 2016-12-12 22:18:43 -07:00
Peace-Maker
2e52ab24b7 First draft of dynamic detours using Ayuto's DynamicHooks library
https://github.com/Ayuto/DynamicHooks
2016-12-11 22:02:10 -07:00