Do not change oldtick !
You need to save it only once and then
// accelerating time by factor of "factor" return oldtick + (realtick - oldtick) * factor;
EDIT:
Another possible problem is that GetTickCount (at least on my computer, XP 32bit) does not have a standard βaccessibleβ preamble:
8B FF mov edi, edi 55 push ebp 8B EC mov ebp, esp
Without it, it can only be connected from the IAT, and this needs to be done for each module that calls it. I suspect DetourFunction works for every process, so it intercepts the APIs using the preamble.
To solve this problem, you can either try to connect the IAT of each module, or fix it manually, but then you cannot call the original version when you connect it.
EDIT2 : using a jump is the most common way, but that means we have to overwrite 5 bytes at the beginning of the function. The main problem is not the size of the function, but at the beginning of the code. Of course, everything can be overwritten, but if you want to be able to call the old function at the time of inclusion (as in this question), you should know that you are overwriting. You do not want to rewrite half of the operation code, and you need to complete the rewritten part. This means that in general you will need a complete disassembler for this.
To simplify this, most functions start with an additional 2-byte NOP: mov edi, edi , so their preamble has 5 bytes, which are standard and easy to carry.
source share