BF2.US bf2-rsdeveloper wiki Parity Discord bf2.us
generated from the code
On this page

Timers and handlers

9 functions of the host module. Generated from the bf2-rs sources; see the reference index for the cross-game table.

timer_getWallTime#

BF22142Heroes
python
host.timer_getWallTime()
FactDetail
Arguments (as parsed)-
Returnsfloat
Original codebf2_w32ded.exe!0x00429b80, BF2.exe!0x0045dbc0, BFHeroes.exe (1.89)!0x0049219b
bf2-rscrates/bf2-server/src/hostfns.rs:496

What it does (from the original code). Clock (DAT_0083b120) vt+0x14() as double. Same clock drives timer firing.

Shipped scripts use it like this:

BF2: python/bf2/stats/fragalyzer_log.py:199
return host.timer_getWallTime()
2142: mods/bf2142/python/game/scoringCommon.py:872
return host.timer_getWallTime()
Heroes: mods/bfheroes/python/game/scoringCommon.py:976
return host.timer_getWallTime()

timer_getTimers#

BF22142Heroes
python
host.timer_getTimers()
FactDetail
Arguments (as parsed)-
Returnstuple
Original codebf2_w32ded.exe!0x0042ada0, BF2.exe!0x0045f510, BFHeroes.exe (1.89)!0x00493239
bf2-rscrates/bf2-python/src/host_state.rs:538

What it does (from the original code). Bug: tuple has len(timer set) but every element is stored into slot 0 (last timer wins), other slots stay NULL. Unused by retail scripts.

timer_created#

BF22142Heroes
python
host.timer_created(timer)
FactDetail
Arguments (as parsed)args[0] raw
ReturnsNone
Errorsno arguments,IndexError
Original codebf2_w32ded.exe!0x0042b1d0, BF2.exe!0x00460360, BFHeroes.exe (1.89)!0x00493495
bf2-rscrates/bf2-python/src/host_state.rs:540

What it does (from the original code). Inserts timer (incref) into the timer std::set<PyObject*> (state+0x20), ordered by object address.

Shipped scripts use it like this:

BF2: python/bf2/Timer.py:12
host.timer_created(self)
2142: python/bf2/Timer.py:12
host.timer_created(self)
Heroes: python/bf2/Timer.py:12
host.timer_created(self)

timer_destroy#

BF22142Heroes
python
host.timer_destroy(timer)
FactDetail
Arguments (as parsed)args[0] raw
ReturnsNone
Errorsno arguments,IndexError
Original codebf2_w32ded.exe!0x0042b260, BF2.exe!0x004603f0, BFHeroes.exe (1.89)!0x004934ca
bf2-rscrates/bf2-python/src/host_state.rs:542

What it does (from the original code). Queues timer on the pending-destroy list (state+0x2c); it is erased from the set after the next updateTimers pass, so a due timer still fires once more.

Shipped scripts use it like this:

BF2: python/bf2/Timer.py:18
host.timer_destroy(self)
2142: python/bf2/Timer.py:18
host.timer_destroy(self)
Heroes: python/bf2/Timer.py:18
host.timer_destroy(self)

registerHandler#

BF22142Heroes
python
host.registerHandler(eventName, callable[, alwaysTrigger])
FactDetail
Arguments (as parsed)s@0 O@1 [i@2 if len(args)>=3]
ReturnsNone
ErrorsTypeError (wrong arg type),missing arg,"not callable","illegal event name"
Original codebf2_w32ded.exe!0x0042ba50, BF2.exe!0x00461ec0, BFHeroes.exe (1.89)!0x00493bff
bf2-rscrates/bf2-python/src/host_state.rs:544

What it does (from the original code). No-op returning None in minimal mode (state+1). eventName matched case-sensitively against s_eventNames; appends {callable, alwaysTrigger>0} to the per-event vector unless that callable object is already registered for the event.

Shipped scripts use it like this:

BF2: python/bf2/stats/stats.py:45
host.registerHandler('Reset', onReset, 1)
2142: mods/bf2142/python/game/scoringCommon.py:127
host.registerHandler('Emp', onEmp)
Heroes: python/bf2/Missions.py:1032
host.registerHandler( 'Stomp', onStomp )

registerGameStatusHandler#

BF22142Heroes
python
host.registerGameStatusHandler(callable)
FactDetail
Arguments (as parsed)O@0
ReturnsNone
ErrorsTypeError (wrong arg type),"not callable"
Original codebf2_w32ded.exe!0x0042b2c0, BF2.exe!0x00460450, BFHeroes.exe (1.89)!0x004934ff
bf2-rscrates/bf2-python/src/host_state.rs:549

What it does (from the original code). No-op in minimal mode. push_back onto the status-handler std::list (state+0x18); duplicates allowed.

Shipped scripts use it like this:

BF2: mods/bf2/python/game/gamemodes/gpm_coop.py:28
host.registerGameStatusHandler(onGameStatusChanged)
2142: mods/bf2142/python/game/gamemodes/gpm_ca.py:28
host.registerGameStatusHandler(onGameStatusChanged)
Heroes: mods/bfheroes/python/game/gamemodes/gpm_cdm.py:72
host.registerGameStatusHandler(onGameStatusChanged)

unregisterGameStatusHandler#

BF22142Heroes
python
host.unregisterGameStatusHandler(callable)
FactDetail
Arguments (as parsed)O@0
ReturnsNone
ErrorsTypeError (wrong arg type),"not callable"
Original codebf2_w32ded.exe!0x0042b370, BF2.exe!0x00460500, BFHeroes.exe (1.89)!0x0049358e
bf2-rscrates/bf2-python/src/host_state.rs:551

What it does (from the original code). No-op in minimal mode. Removes every list entry whose PyObject* is identical to callable.

Shipped scripts use it like this:

BF2: mods/bf2/python/game/gamemodes/gpm_coop.py:44
host.unregisterGameStatusHandler(onGameStatusChanged)
2142: mods/bf2142/python/game/gamemodes/gpm_ca.py:45
host.unregisterGameStatusHandler(onGameStatusChanged)
Heroes: mods/bfheroes/python/game/gamemodes/gpm_cdm.py:87
host.unregisterGameStatusHandler(onGameStatusChanged)

timer_getGameSpyTime#

2142
python
host.timer_getGameSpyTime(...)
FactDetail
bf2-rscrates/bf2-server/src/hostfns_2142.rs:66

What it does (from the bf2-rs port). timer_getGameSpyTime (bf2142ded!0x0816ede0, BF2142.exe!0x004424b0): time(NULL) plus the "GameSpyAuth" service's vt+0x14 offset (GameSpyAuth::getTimeDiff, set from getbackendinfo.aspx).

unregisterHandler#

2142Heroes
python
host.unregisterHandler(...)
FactDetail
Original codeBFHeroes.exe (1.89)!0x004938c5
bf2-rscrates/bf2-python/src/host_state.rs:547

What it does (from the bf2-rs port). BFHeroes.exe!0x004938c5: same behaviour (the key chain and calls match, vtable offsets shifted). Only in 2142's table (crate::pythonhost::HOST_FUNCTIONS_2142).

Shipped scripts use it like this:

2142: mods/bf2142/python/game/gamemodes/gpm_ca.py:53
host.unregisterHandler('PlayerSpawn', onPlayerSpawn)
Heroes: mods/bfheroes/python/game/gamemodes/gpm_cdm.py:94
host.unregisterHandler('PlayerSpawn', onPlayerSpawn)
Source: tools/devwiki/refs_python.py · built from bf2-rs e3b4f05 · part of the Battlefield 2 / 2142 / Heroes reimplementation. Not affiliated with EA or DICE.