The Starport
  • Categories
  • Recent
  • Users
  • Groups
  • Starport Blog
  • Knowledge Base
  • The Forge
  • Discord
  • Register
  • Login

CObject* to IObjInspectImpl*?

Scheduled Pinned Locked Moved Freelancer-related Programming
13 Posts 2 Posters 14.6k Views
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    FriendlyFire
    wrote on global:last_edited_by,
    #1

    So this has been bugging me for ages: we can easily pass from an IObjInspectImpl* to a CObject by the cobject() function, but there appears to be no straightforward manner of going the other way around.

    Is there a function which can be used to find or create an IObjInspectImpl* from a CObject* or its id? The server has GetShipInspect, which uses the id, but that doesn’t seem to exist on the client, or I haven’t found it if it does.

    Thoughts?

    1 Reply Last reply
    0
  • adoxaA Offline
    adoxaA Offline
    adoxa
    wrote on global:last_edited_by,
    #2

    It looks like some equipment contains a pointer to the Inspect, so use EquipTraverser to find one that matches. Hope I’ve done this right, I was just tracing through the debugger:

    CObject* object;
    CEquip* equip;
    IObjInspectImpl* inspect = NULL;
    // set equip from the traverser loop
    {
      char* something = *(char**)((char*)equip + 0x18);
      if (something) {
        IObjInspectImpl* ti = *(IObjInspectImpl**)(something + 8);
        if (ti->object() == object) {
            inspect = ti;
            break;
      }
    }
    
    
    1 Reply Last reply
    0
  • F Offline
    F Offline
    FriendlyFire
    wrote on global:last_edited_by,
    #3

    Huh, I wouldn’t have thought to go that way around. I’ll check if that works, thanks!

    1 Reply Last reply
    0
  • F Offline
    F Offline
    FriendlyFire
    wrote on global:last_edited_by,
    #4

    I’ll just resurrect this because I’ve stumbled on a function that may be what I was looking for.

    There’s a function at offset 0x5392D0 in Freelancer.exe which seems to initialize an IObjInspectImpl object. Looking up where it’s called I find another function at offset 0x530620 which calls this function after calling new. Moreover, its first argument is stored at offset 0x10 in the resulting object, which I know is the offset of the CObject* pointer in IObjInspectImpl.

    The only thing I’m not sure about is what the second argument is; it’s probably another pointer and it’s used in a later call, but I’m not sure why or if it’s even necessary.

    1 Reply Last reply
    0
  • adoxaA Offline
    adoxaA Offline
    adoxa
    wrote on global:last_edited_by,
    #5

    There still doesn’t seem to be any way to get the inspector from the object. I think you’d have to hook [c]CBase::advise[/c] and create your own map - (ecx - 0x0C) is the inspector and [ecx+4] the object. Not sure how you’d go about removing old ones, though.

    1 Reply Last reply
    0
  • F Offline
    F Offline
    FriendlyFire
    wrote on global:last_edited_by,
    #6

    You mean that the game builds the IObjInspectImpl when the CObject contained within is created?

    1 Reply Last reply
    0
  • adoxaA Offline
    adoxaA Offline
    adoxa
    wrote on global:last_edited_by,
    #7

    Looks that way. Turns out removing old ones is simple: [c]CBase::advise[/c] is called with a bool parameter - true for creation, false for destruction.

    1 Reply Last reply
    0
  • F Offline
    F Offline
    FriendlyFire
    wrote on global:last_edited_by,
    #8

    Excellent then, thanks!

    1 Reply Last reply
    0
  • F Offline
    F Offline
    FriendlyFire
    wrote on global:last_edited_by,
    #9

    Hmm… Just looked into CBase::advise and it looks like it’s a dummy function? IDA is giving me 0x62ED730, which is also referenced as a bunch of other functions.

    I’ve tried to hook the export address table but it doesn’t seem like the function is being called, so I’m not sure if the function is actually used or if I’m just sucking at hooking it.

    1 Reply Last reply
    0
  • adoxaA Offline
    adoxaA Offline
    adoxa
    wrote on global:last_edited_by,
    #10

    Sure, the function does nothing, but it still gets called. It’s too late to patch the export (you’d have to patch the file itself for that, or create FL suspended), so you need to patch the import. It’s used by both freelancer.exe & server.dll, and they both create an inspector for the same object (well, they did for one CSolar, so probably for many things; didn’t test if only one creates one). So depending on what it is you want it for, you may need one or the other (but they’re probably the same).

    1 Reply Last reply
    0
  • F Offline
    F Offline
    FriendlyFire
    wrote on global:last_edited_by,
    #11

    After some more work figuring out how to hook a class member function with IATs, it appears to be working.

    The only oddity is that you can’t use CBase::advise with the player’s ship, the IObjInspectImpl* pointer is always null in my mapping. Thankfully GetPlayerShip() works for that particular scenario.

    1 Reply Last reply
    0
  • F Offline
    F Offline
    FriendlyFire
    wrote on global:last_edited_by,
    #12

    Resurrecting this because of a particular annoyance: it seems like CGuided objects don’t call CBase::advise, even though they do have IObjInspects since they can be targeted.

    1 Reply Last reply
    0
  • F Offline
    F Offline
    FriendlyFire
    wrote on global:last_edited_by,
    #13

    Kept having issues with it so I dug again and I finally found it: offset 0x5416c0 contains a function of the signature IObjRW* (uint id, uint zero). Call it with the id and zero in the second parameter to get the IObjRW (which can just be cast to IObjInspectImpl) or null if there’s nothing associated.

    1 Reply Last reply
    0

  • Story Mission level requirement
    C
    CommanderArgelo
    0
    11
    52

  • Crash Offsets
    J
    josbyte
    0
    231
    251.4k

  • Capital ships shield collision detection
    C
    CommanderArgelo
    0
    3
    17

  • Dropping a phantomloot cargo from an NPC
    C
    CommanderArgelo
    0
    5
    26

  • Incorrect Shield Value on HUD
    C
    CommanderArgelo
    0
    4
    19

  • @Adoxa - Wheel Scroll plugin improvements
    AingarA
    Aingar
    0
    3
    20

  • Release: Advanced Renderer v. 1.1 beta 1
    S
    SWAT_OP-R8R
    3
    50
    428

  • German Mod Tutorials? 2024 Mod Tutorial?
    S
    SWAT_OP-R8R
    0
    18
    66
  • First post
    Last post
0
  • Categories
  • Recent
  • Users
  • Groups
  • Starport Blog
  • Knowledge Base
  • The Forge
  • Discord