Merge branch 'master' into chatter-fixes-and-improvements
This commit is contained in:
commit
92af7495ea
16 changed files with 386 additions and 193 deletions
115
inc/fakeping.h
Normal file
115
inc/fakeping.h
Normal file
|
|
@ -0,0 +1,115 @@
|
|||
//
|
||||
// YaPB, based on PODBot by Markus Klinge ("CountFloyd").
|
||||
// Copyright © YaPB Project Developers <yapb@jeefo.net>.
|
||||
//
|
||||
// SPDX-License-Identifier: MIT
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
// adopted from pingfaker amxx plugin
|
||||
class PingBitMsg final {
|
||||
private:
|
||||
int32_t bits_ {};
|
||||
int32_t used_ {};
|
||||
|
||||
MessageWriter msg_ {};
|
||||
bool started_ {};
|
||||
|
||||
public:
|
||||
enum : int32_t {
|
||||
Single = 1,
|
||||
PlayerID = 5,
|
||||
Loss = 7,
|
||||
Ping = 12
|
||||
};
|
||||
|
||||
public:
|
||||
PingBitMsg () = default;
|
||||
~PingBitMsg () = default;
|
||||
|
||||
public:
|
||||
void write (int32_t bit, int32_t size) {
|
||||
if (size > 32 - used_ || size < 1) {
|
||||
return;
|
||||
}
|
||||
const auto maxSize = cr::bit (size);
|
||||
|
||||
if (bit >= maxSize) {
|
||||
bit = maxSize - 1;
|
||||
}
|
||||
bits_ = bits_ + (bit << used_);
|
||||
used_ += size;
|
||||
}
|
||||
|
||||
void send (bool remaining = false) {
|
||||
while (used_ >= 8) {
|
||||
msg_.writeByte (bits_ & (cr::bit (8) - 1));
|
||||
bits_ = (bits_ >> 8);
|
||||
used_ -= 8;
|
||||
}
|
||||
|
||||
if (remaining && used_ > 0) {
|
||||
msg_.writeByte (bits_);
|
||||
bits_ = used_ = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void start (edict_t *ent) {
|
||||
if (started_) {
|
||||
return;
|
||||
}
|
||||
msg_.start (MSG_ONE_UNRELIABLE, SVC_PINGS, nullptr, ent);
|
||||
started_ = true;
|
||||
}
|
||||
|
||||
void flush () {
|
||||
if (!started_) {
|
||||
return;
|
||||
}
|
||||
write (0, Single);
|
||||
send (true);
|
||||
|
||||
started_ = false;
|
||||
msg_.end ();
|
||||
}
|
||||
};
|
||||
|
||||
// bot fakeping manager
|
||||
class BotFakePingManager final : public Singleton <BotFakePingManager> {
|
||||
private:
|
||||
mutable Mutex m_cs {};
|
||||
|
||||
private:
|
||||
CountdownTimer m_recalcTime {};
|
||||
|
||||
public:
|
||||
explicit BotFakePingManager () = default;
|
||||
~BotFakePingManager () = default;
|
||||
|
||||
public:
|
||||
// verify game supports fakeping and it's enabled
|
||||
bool hasFeature () const;
|
||||
|
||||
// reset the ping on disconnecting player
|
||||
void reset (edict_t *ent);
|
||||
|
||||
// calculate our own pings for all the bots
|
||||
void syncCalculate ();
|
||||
|
||||
// calculate our own pings for all the bots
|
||||
void calculate ();
|
||||
|
||||
// emit pings in update client data hook
|
||||
void emit (edict_t *ent);
|
||||
|
||||
// resetarts update timers
|
||||
void restartTimer ();
|
||||
|
||||
// get random base ping
|
||||
int randomBase () const;
|
||||
};
|
||||
|
||||
// expose fakeping manager
|
||||
CR_EXPOSE_GLOBAL_SINGLETON (BotFakePingManager, fakeping);
|
||||
|
||||
|
|
@ -8,9 +8,6 @@
|
|||
#pragma once
|
||||
|
||||
class BotSupport final : public Singleton <BotSupport> {
|
||||
private:
|
||||
mutable Mutex m_cs {};
|
||||
|
||||
private:
|
||||
bool m_needToSendWelcome {};
|
||||
float m_welcomeReceiveTime {};
|
||||
|
|
@ -70,21 +67,6 @@ public:
|
|||
// update stats on clients
|
||||
void updateClients ();
|
||||
|
||||
// generates ping bitmask for SVC_PINGS message
|
||||
int getPingBitmask (edict_t *ent, int loss, int ping);
|
||||
|
||||
// calculate our own pings for all the players
|
||||
void syncCalculatePings ();
|
||||
|
||||
// calculate our own pings for all the players
|
||||
void calculatePings ();
|
||||
|
||||
// send modified pings to all the clients
|
||||
void emitPings (edict_t *to);
|
||||
|
||||
// reset ping to zero values
|
||||
void resetPings (edict_t *to);
|
||||
|
||||
// checks if same model omitting the models directory
|
||||
bool isModel (const edict_t *ent, StringRef model);
|
||||
|
||||
|
|
|
|||
|
|
@ -103,7 +103,6 @@ struct Client {
|
|||
int flags; // client flags
|
||||
int radio; // radio orders
|
||||
int menu; // identifier to opened menu
|
||||
int ping; // when bot latency is enabled, client ping stored here
|
||||
int iconFlags[kGameMaxPlayers]; // flag holding chatter icons
|
||||
float iconTimestamp[kGameMaxPlayers]; // timers for chatter icons
|
||||
ClientNoise noise;
|
||||
|
|
@ -506,6 +505,7 @@ private:
|
|||
void updatePredictedIndex ();
|
||||
void refreshCreatureStatus (char *infobuffer);
|
||||
void updateRightRef ();
|
||||
void donateC4ToHuman ();
|
||||
|
||||
void completeTask ();
|
||||
void executeTasks ();
|
||||
|
|
@ -592,6 +592,9 @@ public:
|
|||
int m_difficulty {}; // bots hard level
|
||||
int m_moneyAmount {}; // amount of money in bot's bank
|
||||
|
||||
int m_pingBase {}; // base ping level for randomizing
|
||||
int m_ping {}; // bot's acutal ping
|
||||
|
||||
float m_spawnTime {}; // time this bot spawned
|
||||
float m_timeTeamOrder {}; // time of last radio command
|
||||
float m_slowFrameTimestamp {}; // time to per-second think
|
||||
|
|
@ -630,7 +633,6 @@ public:
|
|||
|
||||
int m_blindNodeIndex {}; // node index to cover when blind
|
||||
int m_flashLevel {}; // flashlight level
|
||||
int m_basePing {}; // base ping for bot
|
||||
int m_numEnemiesLeft {}; // number of enemies alive left on map
|
||||
int m_numFriendsLeft {}; // number of friend alive left on map
|
||||
int m_retryJoin {}; // retry count for choosing team/class
|
||||
|
|
@ -880,6 +882,7 @@ private:
|
|||
#include "planner.h"
|
||||
#include "storage.h"
|
||||
#include "analyze.h"
|
||||
#include "fakeping.h"
|
||||
|
||||
// very global convars
|
||||
extern ConVar cv_jasonmode;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue