praydog / REFramework

Scripting platform, modding framework and VR support for all RE Engine games
https://cursey.github.io/reframework-book/
MIT License
2.68k stars 337 forks source link

Pre hook argument values are sometimes incorrect. #1015

Closed infinitY0369 closed 3 months ago

infinitY0369 commented 3 months ago

Describe the bug Pre hook argument values are sometimes incorrect. Only tested with MHRISE.

Identify the REFramework version This could not be reproduced before this commit. https://github.com/praydog/REFramework/commit/0721d018ec0cd2d5677c23133c32fc023ee8908e

To Reproduce The following snippet reproduces it. The same thing happens with the C++ API. As an example, args[3] was 8.0 when 1.0 was expected. It was not clear whether it only happens in certain functions or only in variables of certain types.

sdk.hook(sdk.find_type_definition("snow.player.PlayerQuestBase"):get_method("checkDamage_calcDamage(System.Single, System.Single, snow.player.PlayerDamageInfo, System.Boolean)"),
         function(args)
             local damage = sdk.to_float(args[3]) -- Sometimes different value.
             print(damage)
         end,
         function(retval)
         end)

Additional context The probability of incorrect values is reduced if the function is called many times.

praydog commented 3 months ago

Does this only happen with System.Single arguments?

infinitY0369 commented 3 months ago

I think it is working correctly, at least with pointers like thread context and this pointer. I'm not at my PC right now, so I'll look into it more later.

praydog commented 3 months ago

Can you try it again with the changes in 381c67756fd801d9357c34eb98e9cf725256862a?

There was some corruption of XMM arguments going on, this should fix it.

infinitY0369 commented 3 months ago

It works as expected. Thank you!