Closed IgnacioFDM closed 6 years ago
At least in this particular scenario, it correctly triggers if I remove /GL (Whole program optimization)
So, looking at the generated assembly, what's happening is pretty obvious. VC++ is removing the virtual function lookup, and inlining code when CXM1014::Reload is called from one place, but not from another.
I wonder if with whole program optimization disabled, other virtual function lookups that one would hook from hamsandwich are being replaced by static calls. I would assume yes.
I was unable to find a solution with the settings of visual c++ compiler, so in my opinion the only solution is to change the code to make the visual c++ compiler to think differently.
One simple hack I can think of, would be creating dummy classes that extend anything you could hook with hamsandwich. This way, the compiler can never skip virtual table lookup if a class is derived any further.
Edit: Furthermore, if you have whole program optimizations enabled, I think maybe the compiler can detect even though a class is derived, if the virtual functions are never overriden it can skip vtable lookup. So you would need to disable WPO (but with it disabled, you are now guaranteed that compiler never optimizes away vtable lookups I think), or override all virtual functions in addition.
This will not be enough, since these dummy classes will be marked as NOXREF.
The easiest way to do the cast before calling
(reinterpret_cast<CBasePlayerWeapon *>(this))->Reload();
Although one would need to replace every call in the entire codebase, which would take a lot of time (and the resulting code would be pretty ugly).
@IgnacioFDM please let me know if the issue persists
This fixes it. There are surely a lot more cases other than weaponxm1014 (and weapon*) where this happens. It would be needed to do the same with many (most) classes, which would be quite a big effort.
Off the top of my head:
player func* info* grenade weaponbox armoury_entity weapon_shield
Hi, thank you for hard working 1.i want to report the "csdm spawn when bomb planted" problem with zbot after the C4 planted, if the zbot respawned,they seems don't know that they are respawned, they kept standing there and do nothing (although he's still in navigation mesh area)
Is it normal that some Hamsandwich hooks don't trigger on some situations (but consistently) when ReGameDLL is compiled with MSVC optimizations enabled (as it is in Release configuration), and trigger correctly with optimizations disabled?
With MSVC /Od it triggers not only after pressing R, but also each time a shell comes into the shotgun (as it should). With /O2, it doesn't trigger every time a shell comes in.
Is there some workaround to this, so that it's not needed to entirely disable optimizations?