Counter-Strike: Global Offensive Game State Integration

因为需要长时间的查询相关文档和玩游戏实践,因此在本消息移除之前,此文章都处于持续更新状态

这破游戏打得我心态爆炸了

Csgo_logo.jpg

©️ Valve Corporation

Counter-Strike: Global Offensive 具有一个叫做 Game State Integration (游戏状态整合) 或称为 GSI 的机制。其实并不止 Counter-Strike,Valve 的另一款游戏,Dota 2 同样也携带有相关的机制。

什么是 GSI

根据 Valve Developer Community 文档 (English)的介绍 (中文版: Valve Developer Community 文档 (简体中文))

Game State Integration 或 GSI 是一套可以允许任何第三方程序与游戏整合的一套系统。例如在实时直播的竞技比赛中自动控制舞台灯光和烟火系统,也可以让程序自动控制玩家的灯光或者任何其他的周边设施。通过 Game State Integration,开发者可以收集来自游戏内的实时游戏状态,将第三方的软件或者硬件设施与游戏绑定

当 CS: GO 客户端需要向目标服务器发送状态时,CS: GO 将通过 HTTP 协议发起 POST 请求,Raw Body 的内容为标准的 JSON 格式

开始配置 GSI

如果需要在 CS: GO 中启动 GSI,需要向游戏的特定目录添加 .cfg 文件

目录路径位于: CS:GO 的根目录/csgo/cfg/

例如: /Volumes/Samsung T5/SteamLibrary/steamapps/common/Counter-Strike Global Offensive/csgo/cfg

在这个文件夹中添加如下命名的文件 gamestate_integration_consolesample.cfg

官方提供了一个配置文档示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
"Console Sample v.1"
{
"uri" "http://127.0.0.1:3000"
"timeout" "5.0"
"buffer" "0.1"
"throttle" "0.5"
"heartbeat" "60.0"
"auth"
{
"token" "CCWJu64ZV3JHDT8hZc"
}
"output"
{
"precision_time" "3"
"precision_position" "1"
"precision_vector" "3"
}
"data"
{
"provider" "1" // general info about client being listened to: game name, appid, client steamid, etc.
"map" "1" // map, gamemode, and current match phase ('warmup', 'intermission', 'gameover', 'live') and current score
"round" "1" // round phase ('freezetime', 'over', 'live'), bomb state ('planted', 'exploded', 'defused'), and round winner (if any)
"player_id" "1" // player name, clan tag, observer slot (ie key to press to observe this player) and team
"player_state" "1" // player state for this current round such as health, armor, kills this round, etc.
"player_weapons" "1" // output equipped weapons.
"player_match_stats" "1" // player stats this match such as kill, assists, score, deaths and MVPs
}
}

这是上方示例配置文件所具有的几个属性

  • uri - 需要提供 HTTP 服务器的地址 (包括端口, 路径)

  • timeout - 等待 HTTP 服务器返回的等待时间;状态码可以是 200 - 299 的区间 (second)

  • buffer - 在向 HTTP 服务器发送数据前,游戏收集数据的时间 (second)

  • throttle - 在前一次数据发送成功后,游戏将会等待一定时间后再次发送 (second)

  • heartbeat - 在一定时间内,游戏将会检测 HTTP 服务器的存活状态 (second)

  • auth - 认证

    • token - 游戏每次向 HTTP 服务器发送数据时,将会携带这个 Token;当然了,这对于局域网内的服务器必要性不大
  • output - 小数点控制

    • precision_time - 用于控制输出持续时间相关信息的小数点
    • precision_position - 用来控制输出位置相关信息的小数点
    • precision_vector - 用来控制输出矢量相关信息的小数点
  • data - 需要发送的游戏内数据

    • provider - 提供者 (游戏客户端) 自身信息
    • map - 本场比赛模式,地图,比赛进行状态,团队得分,比赛轮数 等
    • round - 本场比赛状态 (进行中,中场休息,结束),获胜团队(CT,T),炸弹状态(已部署,已爆炸,已解除)
    • player_id - 玩家数据(Steam ID,团队标签,玩家名字,观察槽位(0-9),阵营(CT,T),状态
    • player_state - 玩家瞬时状态(生命,盔甲,头盔,投放闪光弹状态,投放烟雾弹状态,投放燃烧瓶状态,资金,死亡前击杀数,死亡前爆头数,总价值)
    • player_weapons - 所有武器目前状态(武器名,皮肤,类型,弹夹,弹夹支持的最大弹药数量,储备弹药用量,状态( active - 使用中,holstered - 未使用)
    • player_match_stats - 本局比赛数据(杀敌数,助攻数,死亡数,MVP,分数)

以上是官方提供的示例配置文件中会返回的数据

完整的 data 配置对象如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
"map_round_wins" "1"          // history of round wins
"map" "1" // mode, map, phase, team scores
"player_id" "1" // steamid
"player_match_stats" "1" // scoreboard info
"player_state" "1" // armor, flashed, equip_value, health, etc.
"player_weapons" "1" // list of player weapons and weapon state
"provider" "1" // info about the game providing info
"round" "1" // round phase and the winning team

// Below this line must be spectating or observing
"allgrenades" "1" // grenade effecttime, lifetime, owner, position, type, velocity
"allplayers_id" "1" // the steam id of each player
"allplayers_match_stats" "1" // the scoreboard info for each player
"allplayers_position" "1" // player_position but for each player
"allplayers_state" "1" // the player_state for each player
"allplayers_weapons" "1" // the player_weapons for each player
"bomb" "1" // location of the bomb, who's carrying it, dropped or not
"phase_countdowns" "1" // time remaining in tenths of a second, which phase
"player_position" "1" // forward direction, position for currently spectated player

注意,有一部分数据,例如关于本局比赛所有玩家的数据炸弹数据玩家坐标和矢量数据均需要进入观察模式才能返回

更新分割线 2022/7/7