nosoop / rcbot2

A Metamod:Source plugin that provides customizable bot players.
http://rcbot.bots-united.com
GNU Affero General Public License v3.0
5 stars 0 forks source link

Remove rcbot_const_point_master_offset #10

Closed nosoop closed 4 years ago

nosoop commented 4 years ago

Marking this issue down for reference to other forks. It's kind of a dumb hack, but it works.

(TODO Test to ensure this actually works on DOD:S.) DOD doesn't use this

RCBot2's CTeamControlPointMaster has different offsets on Windows and Linux. The offsets are based on it being a subclass of CBaseEntity, and so the offset is sizeof(CBaseEntity).

There is ability to access the size of entities via an IEntityFactory, and conveniently we can access and perform lookups against an IEntityFactoryDictionary interface.

The following code does just that:

extern IServerTools *servertools;

// HACK: we use one of the known CBaseEntity-sized entities to compute the offset to the first subclass member for CTeamControlPointMaster / CTeamControlPointRound
size_t baseEntityOffset = servertools->GetEntityFactoryDictionary()->FindFactory("simple_physics_brush")->GetEntitySize();

uintptr_t pMasterMembers = reinterpret_cast<uintptr_t>(servergameents->EdictToBaseEntity(pMaster)) + baseEntityOffset;

m_PointMaster = (CTeamControlPointMaster*) pMasterMembers;