@@ -90,6 +90,8 @@ fn tryIatHookUntyped(
9090        logger .err ("Failed to hook {s}. Error: {}" , .{ msg , e  });
9191        return ;
9292    };
93+     // Need to GetProcAddress instead of simply using the target_function address, because the target_function may be a 
94+     // "stub" function embedded in our DLL that invokes the real function. 
9395    const  result : * const  anyopaque  =  std .os .windows .kernel32 .GetProcAddress (target_module , target_function_name ) orelse  {
9496        const  e  =  std .os .windows .unexpectedError (std .os .windows .GetLastError ()) catch  {};
9597        logger .err ("Failed to hook {s}. Error: {}" , .{ msg , e  });
@@ -100,7 +102,12 @@ fn tryIatHookUntyped(
100102    };
101103}
102104
103- pub  fn  installHooksWindows (module : std.os.windows.HMODULE ) callconv (.c ) void  {
105+ pub  fn  installHooksWindows () void  {
106+     const  module  =  std .os .windows .kernel32 .GetModuleHandleW (std .unicode .utf8ToUtf16LeStringLiteral ("UnityPlayer" )) orelse  blk : {
107+         logger .debug ("No UnityPlayer module found! Using executable as the hook target." , .{});
108+         break  :blk  std .os .windows .kernel32 .GetModuleHandleW (null ).? ;
109+     };
110+ 
104111    tryIatHook (module , "kernel32.dll" , "GetProcAddress" , & std .os .windows .kernel32 .GetProcAddress , @ptrCast (& dlsym_hook ), "GetProcAddress" );
105112    tryIatHook (module , "kernel32.dll" , "CloseHandle" , & windows .CloseHandle , & windows .close_handle_hook , "CloseHandle" );
106113
@@ -118,7 +125,7 @@ fn tryPltHook(hook: *plthook.c.plthook_t, funcname: [:0]const u8, funcaddr: *any
118125    }
119126}
120127
121- pub  fn  installHooksNix () callconv ( .c )  void  {
128+ pub  fn  installHooksNix () void  {
122129    const  hook  =  plthook .openByFilename (comptime  "UnityPlayer"  ++  builtin .os .tag .dynamicLibSuffix ()) catch  | e |  {
123130        const  s : [* :0 ]const  u8  =  switch  (e ) {
124131            error .FileNotFound  = >  "FileNotFound" ,
0 commit comments