BF2 Internals: Difference between revisions
Line 19: | Line 19: | ||
// Unsure if there actually is a base implementation of this method, | // Unsure if there actually is a base implementation of this method, | ||
// this | // this sometimes points to a unique function in the vtable but follows this pattern. | ||
virtual int release() { | virtual int release() { | ||
if (--m_refCount == 0) { | if (--m_refCount == 0) { |
Revision as of 19:04, 21 June 2018
The BF2 engine has been written in C++ and also make heavy use of STL.
Reference Counting
A lot of the internal components of the game use intrusive reference counting through inheritance. The base class would look something like this:
class RefCounted { public: RefCounted() : m_refCount(1) {} virtual ~RefCounted() {} virtual int addRef() { return ++m_refCount; } virtual int getRefCount() const { return m_refCount; } // Unsure if there actually is a base implementation of this method, // this sometimes points to a unique function in the vtable but follows this pattern. virtual int release() { if (--m_refCount == 0) { delete (RefCounted*)this; } return m_refCount; } private: int m_refCount; };
Do note that this class is not thread-safe, as in the actual implementation.
ClassManager
The program contains a single ClassManager instance which is used to dynamically access different subsystems within the game. These subsystems are registered via a string identifier(class name), an instance pointer, the class id and another unknown integer, they can then later be accessed using the class name. The following classes are registered in BF2.exe:
- GameServerSettings
- HudInformationLayer
- DistributedLightRenderer
- LocalProfileManager
- ProfileManager
- RankManager
- ClanManager
- NewsManager
- AutoPatch
- Persistence
- MenuTeamManager
- GlobalSettings
- VideoSettings
- AudioSettings
- ControlSettings
- GeneralSettings
- HapticSettings
- ServerBrowserManager
- SwiffHost
- DemoLibrary
- ServerLogoManager
- ModInfo
The rendering module(RendDX9.dll) also registers the following classes:
- SwiffRenderer
- Terrain
- LightManager
- GeometryTemplateManager
- StaticMeshRenderer
- SkinnedMeshRenderer
- ParticleSystemManager
- HemiMapManager
- DecalManager
- DecalShadowManager
- RoadCompiledRenderer
- RoadEditableRenderer
- NametagManager
- SkyDome
- UndergrowthSystem
- LightingManager
- WeatherManager
- RainManager
- RenderView
- EnvMapManager
Common
GameEvent
The game has multiple event systems, game events are events that occur in-game and are related to gameplay.
The (incomplete) class below is the base class used by all events, events often have additional data.
A GameEvent has a maximum size of 1024 bits as defined by const uint MaximumGameEventSize
.
class GameEvent : public RefCounted { public: GameEvent() : field_8(-1) {} // multiple virtual functions here private: int field_8; };
List of Game events:
- ChallengeEvent
- ChallengeResponseEvent
- ConnectionTypeEvent
- DataBlockEvent
- CreatePlayerEvent
- CreateObjectEvent
- CreateKitEvent
- DestroyObjectEvent
- DestroyPlayerEvent
- EnterVehicleEvent
- ExitVehicleEvent
- PostRemoteEvent
- ChangePlayerNameEvent
- HandlePickupEvent
- HandleDropEvent
- StringBlockEvent
- JoinSquadEvent
- LeaveSquadEvent
- CommanderEvent
- RadioMessageEvent
- KilledByEvent
- ChangeSquadNameEvent
- SetPrivateSquadEvent
- IssueSquadOrderEvent
- InviteEvent
- RankEvent
- KickBanEvent
- SetAcceptOrderEvent
- SetSquadLeaderEvent
- SpottedEvent
- ArtilleryEvent
- StickyProjectileEvent
- AmbientEffectAreaEvent
- VoipOnOffEvent
- CommanderCamEvent
- SupplyDropEvent
- VoidPlayerMuteEvent
- VoteEvent
- TargetDirectionEvent
- BeginRoundEvent
- EndOfRoundEvent
- PythonCommandEvent
- RequestEvent
- VoipSessionEvent
- ToggleFreeCameraEvent
- MedalEvent
- UnlockEvent
- MissileInitEvent
- UAVEvent
- ContentCheckEvent
- DropVehicleEvent
- CreateSpawnGroupEvent
- RemoveSpawnGroupEvent
- UpdateTriggerEvent
- GrapplingHookContainerCreateEvent
- GrapplingHookContainerUpdateEvent
- GrapplingHookContainerDetachEvent
- GrapplingHookCreateEvent
- GrapplingHookUpdateEvent
- PlayerTearGassedEvent
- SetNightVisionEvent
- VerifyPlayerTeamEvent
- FixPlayerTeamEvent