Freelancer Community Network
Reminder: Internet Explorer 6 or below are NOT supported.
HomeHome
ForumForum
WikiWiki
DownloadsDownloads
ForgeForge
Multiplayer Connection Tutorial
Collapse/Expand Random Image
Collapse/Expand Login
Username:

Password:

Remember me



Lost Password?

Register now!
Collapse/Expand Chat
Collapse/Expand Who's Online
57 user(s) are online (24 user(s) are browsing Forum)

Members: 0
Guests: 57

more...
Collapse/Expand Donations
Monthly costs: -30€
Income (ads): +5€
Donations (last month): +10€

Current balance: -300€
(last updated 11/2017)

Please make a donation if you want to help keeping The-Starport online:

Bitcoin address:
Thanks!
Collapse/Expand Links
Collapse/Expand Advertisement
There are currently 58 users playing Freelancer on 33 servers.
November. 23, 2017

Browsing this Thread:   1 Anonymous Users



 Bottom   Previous Topic   Next Topic  Register To Post



CObject* to IObjInspectImpl*?
Starport Admin
Joined:
2009/2/21 21:42
Group:
Webmasters
Registered Users
Posts: 3458
Offline
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?

Posted on: 2014/5/9 19:02
"Cynicism is not realistic and tough. It's unrealistic and kind of cowardly because it means you don't have to try."
-Peggy Noonan
Top
Re: CObject* to IObjInspectImpl*?
Home away from home
Joined:
2009/8/16 2:58
From Qld, Aus.
Group:
Registered Users
FLServer Admins
Trusted Speciality Developers
Senior Members
Posts: 1805
Offline
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:

Code:
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;
  }
}

Posted on: 2014/5/10 17:01
Top
Re: CObject* to IObjInspectImpl*?
Starport Admin
Joined:
2009/2/21 21:42
Group:
Webmasters
Registered Users
Posts: 3458
Offline
Huh, I wouldn't have thought to go that way around. I'll check if that works, thanks!

Posted on: 2014/5/10 23:07
"Cynicism is not realistic and tough. It's unrealistic and kind of cowardly because it means you don't have to try."
-Peggy Noonan
Top
Re: CObject* to IObjInspectImpl*?
Starport Admin
Joined:
2009/2/21 21:42
Group:
Webmasters
Registered Users
Posts: 3458
Offline
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.

Posted on: 2015/4/2 22:54
"Cynicism is not realistic and tough. It's unrealistic and kind of cowardly because it means you don't have to try."
-Peggy Noonan
Top
Re: CObject* to IObjInspectImpl*?
Home away from home
Joined:
2009/8/16 2:58
From Qld, Aus.
Group:
Registered Users
FLServer Admins
Trusted Speciality Developers
Senior Members
Posts: 1805
Offline
There still doesn't seem to be any way to get the inspector from the object. I think you'd have to hook CBase::advise 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.

Posted on: 2015/4/3 9:20
Top
Re: CObject* to IObjInspectImpl*?
Starport Admin
Joined:
2009/2/21 21:42
Group:
Webmasters
Registered Users
Posts: 3458
Offline
You mean that the game builds the IObjInspectImpl when the CObject contained within is created?

Posted on: 2015/4/3 15:38
"Cynicism is not realistic and tough. It's unrealistic and kind of cowardly because it means you don't have to try."
-Peggy Noonan
Top
Re: CObject* to IObjInspectImpl*?
Home away from home
Joined:
2009/8/16 2:58
From Qld, Aus.
Group:
Registered Users
FLServer Admins
Trusted Speciality Developers
Senior Members
Posts: 1805
Offline
Looks that way. Turns out removing old ones is simple: CBase::advise is called with a bool parameter - true for creation, false for destruction.

Posted on: 2015/4/4 14:06
Top
Re: CObject* to IObjInspectImpl*?
Starport Admin
Joined:
2009/2/21 21:42
Group:
Webmasters
Registered Users
Posts: 3458
Offline
Excellent then, thanks!

Posted on: 2015/4/4 15:21
"Cynicism is not realistic and tough. It's unrealistic and kind of cowardly because it means you don't have to try."
-Peggy Noonan
Top
Re: CObject* to IObjInspectImpl*?
Starport Admin
Joined:
2009/2/21 21:42
Group:
Webmasters
Registered Users
Posts: 3458
Offline
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.

Posted on: 2015/4/5 3:07
"Cynicism is not realistic and tough. It's unrealistic and kind of cowardly because it means you don't have to try."
-Peggy Noonan
Top
Re: CObject* to IObjInspectImpl*?
Home away from home
Joined:
2009/8/16 2:58
From Qld, Aus.
Group:
Registered Users
FLServer Admins
Trusted Speciality Developers
Senior Members
Posts: 1805
Offline
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).

Posted on: 2015/4/6 1:54
Top
Re: CObject* to IObjInspectImpl*?
Starport Admin
Joined:
2009/2/21 21:42
Group:
Webmasters
Registered Users
Posts: 3458
Offline
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.

Posted on: 2015/4/9 20:23
"Cynicism is not realistic and tough. It's unrealistic and kind of cowardly because it means you don't have to try."
-Peggy Noonan
Top
Re: CObject* to IObjInspectImpl*?
Starport Admin
Joined:
2009/2/21 21:42
Group:
Webmasters
Registered Users
Posts: 3458
Offline
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.

Posted on: 2016/1/10 18:58
"Cynicism is not realistic and tough. It's unrealistic and kind of cowardly because it means you don't have to try."
-Peggy Noonan
Top
Re: CObject* to IObjInspectImpl*?
Starport Admin
Joined:
2009/2/21 21:42
Group:
Webmasters
Registered Users
Posts: 3458
Offline
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.

Posted on: 2016/1/15 1:00
"Cynicism is not realistic and tough. It's unrealistic and kind of cowardly because it means you don't have to try."
-Peggy Noonan
Top