Modifying the Sfall hook.

Mulligun

Still Mildly Glowing
I'd like to modify the TargetObjectHook hook function from ddraw.dll so that i can dispatch the object type passed to the function as object parameter:

Code:
static long __fastcall TargetObjectHook(DWORD isValid, DWORD object, long type)

Is there any function i can use to parse out the type of object given in object param?
 
So you want to know the object type of the returned object? Why not do that in script?
 
Ok, thx, for help with this.
Now i have another problem.
I'd like to use the PrintFloatText function to output a floating text above the critter (inside my new implementation of the TargetObjectHook hook function).
Here is my code:
Code:
static long __fastcall TargetObjectHook(DWORD isValid, DWORD object, long type) {
    if (isValid > 1) isValid = 1;

    BeginHook();
    argCount = 3;

    args[0] = type;    // 0 - mouse hovering over target, 1 - mouse clicking on target
    args[1] = isValid; // 1 - target is valid
    args[2] = object;  // target object

    if (isValid == 0) object = 0; // it is necessary for the proper operation of the engine code
    if (type == 0) targetRet = 0; // unset ret from the previous execution of the hook

    RunHookScript(HOOK_TARGETOBJECT);

    if (object != 0) {

        fo::GameObject* obj = reinterpret_cast<fo::GameObject*>(object);

        if (obj->IsCritter()) {
            fo::PrintFloatText(obj, "message", 1);
        }
    }
...
}
Unfortunately i get an error:
The instruction at ... referenced memory at
.... The memory could not be written.
What's wrong with the code and how to fix it?
I have to do it in the dll code itself because I'd like to some
So you want to know the object type of the returned object? Why not do that in script?

stuff using WinApi.
it's just a pointer to memory with an object structure (fo::GameObject*)
 
What you're trying to do in that code can be done in hook script.
Code:
procedure start begin
   if game_loaded then begin
      register_hook_proc(HOOK_TARGETOBJECT, hook_test);
   end
end

procedure hook_test begin
   variable
      event   := get_sfall_arg,
      isValid := get_sfall_arg,
      obj     := get_sfall_arg,
      msg;

   if (obj_type(obj) == OBJ_TYPE_CRITTER) then begin
      msg := "My name is " + obj_name(obj);
      float_msg(obj, msg, FLOAT_MSG_GREEN);
   end
end
Result:
targetobj_float.png
 
Yes, I know that friend, but i have to do it just in the dll code... Script version it's suitable for me. Do You know how to fix this code in dll souce as I've tried?
What you're trying to do in that code can be done in hook script.
Code:
procedure start begin
   if game_loaded then begin
      register_hook_proc(HOOK_TARGETOBJECT, hook_test);
   end
end

procedure hook_test begin
   variable
      event   := get_sfall_arg,
      isValid := get_sfall_arg,
      obj     := get_sfall_arg,
      msg;

   if (obj_type(obj) == OBJ_TYPE_CRITTER) then begin
      msg := "My name is " + obj_name(obj);
      float_msg(obj, msg, FLOAT_MSG_GREEN);
   end
end
Result:
View attachment 19569
 
fo:: PrintFloatText(obj, "message", 1); ???
Code:
void PrintFloatText(fo::GameObject* object, const char* text, long colorText, long colorOutline, long font)
 
Yes, that:
Code:
fo:: PrintFloatText(obj, "message", 1);
is OK, see the declaration:
Code:
void PrintFloatText(fo::GameObject* object, const char* text, long colorText, long colorOutline = 207, long font = 101);
The last 2 params are optional since thy have default values defined (207, 101)!

fo:: PrintFloatText(obj, "message", 1); ???
Code:
void PrintFloatText(fo::GameObject* object, const char* text, long colorText, long colorOutline, long font)
 
Back
Top