LogoLogo
简体中文
简体中文
  • 主页
  • 联系我们
  • 感谢名单
  • 维基101 - 如何开始?
    • 修改指南
      • 如何备份,解包和重新打包
      • 如何配置修改用一个工作环境
      • 修改工具
        • 如何使用RSPNVPK
        • 资源
          • 游戏目录
          • BSP
            • BSPSource
            • BSP Viewer
            • BSP2MAP
            • BSPZIP
            • EntEd
            • Entspy
            • Map Analyst
            • PackBsp
            • Pakrat
            • VBSP_h4xed
            • VIDE
            • VMEX
            • WinBSPC
            • WinBSPZip
          • Hammer
            • 位移Luxel密度
          • VTF & VMT
            • VTFEdit
            • Vtex
              • Vtex - 编译参数
              • Vtex - 疑难解答
  • 信息
    • 纹理
      • Valve纹理格式-VTF
        • 创建材质
        • 创建动画粒子
        • 修改动画粒子-Wanty的方法
      • Valve材质类型-VMT
      • 纹理和颜色
        • 颜色和纹理信息
      • 着色器
        • $basetexture
        • $color
        • $reflectivity
        • 材质标志
      • 反照率贴图
      • 凹凸贴图
        • $bumpmap
        • $ssbump
      • 立方环境贴图
      • 光照贴图
      • 矢量材质
      • 纹理映射
      • 内容丢失
      • 基础天空盒
        • 2D天空盒
        • 3D天空盒
    • 脚本
      • 关键值
        • Gameinfo.txt
        • 武器配置
      • VScript
    • 文件格式
      • NUT & GNUT-Squirrel游戏语言
      • PSD-Photoshop文档
      • TGA-Truevision图像文件
      • TXT-文本文件
      • VPK-Valve包文件
    • 文件位置
      • VPK
      • 武器
        • 武器模型
        • 武器脚本
        • 武器配置
      • 模型
        • 模型-天空背景
        • 铁驭
          • 模型-铁驭能力
          • 模型-铁驭武器
        • 泰坦
        • 模型-引导标志
        • 模型-容器
        • 模型- Fixtures
        • 模型-IMC基础
        • 模型-工业
        • 模型- 虎大前进基地_live_fire
        • 模型-NPC
        • 模型-边境防御
  • 修改
    • 武器
      • 自定义武器皮肤
        • 使用\应用自定义武器皮肤
          • VTF文件制作
        • 制作武器自定义皮肤
          • 2D图像线框渲染模式(Wireframe mode)
        • 武器自定义皮肤样例
      • 武器效果
      • 准星修改
        • 批量修改准星
        • 准星样例
      • 武器定位
      • 武器视野
      • 一键更换武器视野
      • 特殊/独特武器修改
        • 电能步枪-电弧枪
        • 电能步枪-蓄力颜色
        • LSTAR-蓄力颜色
    • 铁驭
      • 模型-铁驭类
    • 泰坦
      • 泰坦的穹顶护盾
      • 北极星
        • 线缆-钩爪和绊索陷阱
        • 电浆磁轨炮-蓄力特效
        • 北极星-重力特效
        • 北极星-铝热剂特效
      • 浪人
        • 剑封颜色
      • 军团
        • 强大火力-蓄力颜色
      • 离子
        • 镭射炮-蓄力颜色
        • 漩涡防护罩颜色
    • 地图
      • 地图-天空背景
      • 地图-立体地图
      • 战争游戏
        • 全息墙颜色
    • 用户界面
      • 游戏文本修改-r1_language
      • 游戏中
        • 计分板背景
      • 菜单
        • 暂停菜单模糊
        • 主菜单背景
        • 网路-菜单
        • 新闻和聚焦
        • 设置
          • 控制
          • 按键设置
    • 声音
      • 击杀音效
      • 大厅背景音乐
    • 杂项
      • 电缆-滑索
      • 马文机器人-胸部显示屏
      • 脉冲刀范围特效
      • 被声呐探测到的效果
      • 模型-炸蛛
      • 尼斯湖水怪模型
  • 脚本数据
    • 准星
    • 特效(FX)
    • 特效
      • 特效-铁驭
        • 特效-铁驭武器
          • 特效-突击步枪
          • 特效-冲锋枪
          • 特效-轻机枪
          • 特效-狙击步枪
          • 特效-散弹枪
          • 特效-榴弹发射器
          • 特效-副手武器和手枪
          • 特效-反泰坦武器
          • 特效-特殊武器
        • 特效-铁驭投掷物
          • 特效-电弧效果
          • 特效-飞火星
          • 特效-重力星
        • 特效-铁驭能力
      • 特效-泰坦
        • 特效-离子
        • 特效-强力
        • 特效-北极星
          • 特效-电浆轨道炮
          • 特效- Holo Railgun
          • 特效-毒蛇
        • 特效-帝王
          • 特效-Monarch Beam
        • 特效-浪人
        • 特效-烈焰
          • 特效-铝热剂发射器
          • 特效-Meteor First
          • 特效-火墙
        • 特效-军团
      • 特效-NPC和炮台
        • 特效-NPC
          • 特效-无人机
          • FX - Drone Cloak
          • FX - Drone Frag
          • FX - MRVN
          • FX - Mortar
          • FX - Holo Spectre
        • 特效-炮台
      • 特效-杂项和未知项
        • FX - Holo Map
        • FX - Beacon
        • FX - Skybox
          • FX - Skybox 1K
          • FX - Skybox Carrier
          • FX - Skybox Creature
          • FX - Skybox Nuke
          • FX - Skybox Station Traffic
        • FX - Skyway
        • FX - Dev
          • FX - Bug Repro
        • FX - Droppod
        • FX - Scan
      • 特效-原始数据
        • FX - EMP
        • FX - Env
        • FX - Grenade
        • FX - Harvester
          • FX - Coop Harvester FX
        • FX - HUD
          • FX - HUD AR FX
          • FX - HUD AR Impacts
          • FX - HUD AR Lines
          • FX - HUD AR Ordinance
          • FX - HUD AR Pings
          • FX - HUD AR Titandroppoint
        • FX - Impact
          • FX - Impact FX EXP Cutom
        • FX - Light
        • FX - Orbital Strike
        • FX - Projectile Plasma
        • FX - Reload
        • FX - Shell Eject
        • FX - Smoke
        • FX - Tracers
        • FX - Weapon
          • FX - Arc Cannon
          • FX - Dragonbreath
          • FX - Flamethrower
          • FX - Malta Gun
          • FX - Triple Threat
    • 声音
      • 声音-默认语音
      • 声音-铁驭
        • 铁驭武器
          • 突击步枪
          • 冲锋枪
          • 轻机枪
          • 狙击步枪
          • 散弹枪
          • 榴弹枪
          • 副手武器及手枪
          • 反泰坦武器
        • 铁驭投掷物
        • 铁驭能力
      • 声音-泰坦
        • 声音-离子
        • 声音-强力
        • 声音-北极星
        • 声音-帝王
        • 声音-浪人
        • 声音-烈焰
        • 声音-军团
      • 声音-无人机和NPC
        • 声音 -巨型炮塔
      • 声音-杂项和未知项
        • 声音-电弧炮
        • 声音-电弧枪
        • 声音- Flamethrower
        • 声音- Triplethreat
    • 图标和HUD
      • 菜单
        • 私房加载界面
        • 私人比赛
        • 计分板
  • 修改样例
    • 低配模式
    • 无HUD修改
  • 导出资源
    • 导出地图
    • 导出模型
    • 使用Legion的方式导出
  • 资源
    • 纹理库
Powered by GitBook
On this page
  • 文件格式
  • 关于关键值的文本文件格式:
  • 定义
  • 数值类型
  • 例子
  • 重要提示
  • CLeakTrack
  • 举例
  • 修复
  • 不该做什么
  • 有用的循环
  • 所有子键
  • 所有数值

Was this helpful?

  1. 信息
  2. 脚本

关键值

The KeyValues format is used in the Source engine to store meta data for resources, scripts, materials, VGUI elements, and more.

文件格式

The KeyValues format is used in the Source engine to store meta data for resources, scripts, materials, VGUI elements, and more. The KeyValues.h header in the Source SDK code defines the file format in the following manner

关于关键值的文本文件格式:

  • It has 3 control characters {, } and ". Names and values may be quoted or not. The quote " character must not be used within name or values, only for quoting whole tokens. You may use escape sequences while parsing and add within a quoted token a \" to add quotes within your name or token.

  • When using Escape Sequences, the parser must know that by setting KeyValues::UsesEscapeSequences( true ), which is off by default.

  • Non-quoted tokens ends with a whitespace, {, } and ". So you may use { and } within quoted tokens, but not for non-quoted tokens.

  • An open bracket { after a key name indicates a list of subkeys which is finished with a closing bracket }. Subkeys use the same definitions recursively.

  • Whitespaces are space, return, newline and tabulator. Allowed Escape sequences are \n, \t, \\, and \".

  • The number character # is used for macro purposes (eg #include), don't use it as first character in key names.

Please note that the above is only an informal description of the format. It is not a definitive guide for how the format should be interpreted by parsers. It has not been tested whether the KeyValues parser in the Source SDK Code parses exactly as according to the above. The KeyValues parser might not handle very long keyvalues correctly.

It appears from the source code that:

  • You can use include statements in keyvalues scripts to include other text files.

    #include "file path"

    You can also use the base statement that appears to do the exact same thing.

    #base "file path"

Bug: It appears that the #include statement does not work. The #base statement does work, and actually acts as you would expect from a typical include command: it reads the file and creates the controls as children of the panel that called the include statement.

Example: Say you want to include panelBase.res in your resource file called specificPanel.res. You would then write the following:

"#base" "panelBase.res"

"Resource/specificPanel.res"
{
	// Specify panel-specific controls here
}
  • The file format specification allows for C++ style comments. However, the implementation of this in Valve's Key-Value code is poor, and assumes anything following a single forward slash is a comment.

// This is a comment until the line ends
/ This is also a comment until the line ends
bool CUtlBuffer::EatCPPComment()
{
	if ( IsText() && IsValid() )
	{
		// If we don't have a a c++ style comment next, we're done
		const char *pPeek = (const char *)PeekGet( 2 * sizeof(char), 0 );
		if ( !pPeek || ( pPeek[0] != '/' ) || ( pPeek[1] != '/' ) )
			return false;

		// Deal with c++ style comments
		m_Get += 2;

		// read complete line
		for ( char c = GetChar(); IsValid(); c = GetChar() )
		{
			if ( c == '\n' )
				break;
		}
		return true;
	}
	return false;
}
  • There is no support for block comments, and if contained in a single line, they will eliminate everything after them (due to being treated as a single-line comment).

    /* This is an inline comment, which will not work in this file format. */ "this_pair_is_ignored" "true"
  • You can use conditional statements that will be ignored if non true, this will work on any key value and its children. If you prepend a key value statement with a [$X360] token or a [$WIN32] token it will be ignored depending on the platform in use. Since we have the source code for the keyvalues parser, you might be able to create your own conditional statements.

  • Each token can be up to 1024 characters long (including null-termination, and double quotes, that will leave room for 1021 actual characters). Note that some functions in the KeyValues class will not handle strings with over 256 characters correctly. Searching for a key name over 256 characters containing a '/' causes a buffer overrun on the stack in the KeyValues::FindKey function.

定义

The KeyValues class handles data buffer input, file input, and file output.

A KeyValue is defined recursively as a named key either with a value or children. All keys have names set to them and a search can be performed by the names. If a KeyValue is a parent key, it contains other KeyValues.

数值类型

Note:The KeyValue type gets set automatically when a set value function (i.e. SetFloat) is called.

  • TYPE_NONE

  • TYPE_STRING

  • TYPE_INT

  • TYPE_FLOAT

  • TYPE_PTR

  • TYPE_WSTRING

  • TYPE_COLOR

例子

"ParentKey1"
{
	"ValueKey1"	"1"
	"ParentKey2"
	{
		...
	}
}

重要提示

  • It is important to note that you must include filesystem.h. Not doing this will result in the inability to reliably call LoadFromFile and SaveToFile. Symptoms are crashes in datastore.dll or a fail-state.

  • SaveToFile will not save any keyvalues whose value string is empty, although these can be loaded without any problems.

  • In tier1/KeyValues.cpp, uncomment this line to hit the ~CLeakTrack assert to see what's looking like it's leaking

// #define LEAKTRACK
  • When you have completed using a KeyValues object, if you are unsure, check if is NULL and if not, call the object's deleteThis function.

  • If you, or any code utilizing the KeyValues object, fail to delete your KeyValues objects, you will end up with memory leaks.

  • Many instances of the usage of the KeyValues in the SDK do not call their deleteThis function, therefore making memory leaks.

CLeakTrack

This class is in tier1/KeyValues.cpp.

Replacing the deconstructor for the CLeakTrack class can help you stomp out KeyValues leaks when the engine shuts down.

	~CLeakTrack()
	{
		AssertMsg ( keys.Count() == 0, VarArgs("keys.Count() is %i",keys.Count()) );

		for(int x=0;x<keys.Count();x++)
		{
			keys[x].kv->deleteThis();
			keys.Remove(x);
		}
	}

When you do this in debug build, you should get told how many leaks you get when you shutdown the game. This number may vary for the amount of activity done within the game.

Although this modification can remove all leaked memory, it should not be relied on to take care of them. Some memory leaks are caused by the engine, so this is a last resort for those kinds of leaks.

举例

ComboBox *pCombo = new ComboBox(...);
pCombo->AddItem("Text", new KeyValues("UserData", "Key", "Value"));

It's important to note that if you were to follow what is called by the AddItem function, you would see that the UserData KeyValues are copied, rather than used directly. Copying KeyValues is a common source of confusion of how your KeyValues objects are used, so make sure to follow where they go. If you are unsure, you could try calling the deleteThis function and see if the same functionality as before still exists.

修复

ComboBox *pCombo = new ComboBox(...);
KeyValues *kv = new KeyValues("UserData", "Key", "Value");
pCombo->AddItem("Text", kv);
kv->deleteThis();

不该做什么

ComboBox *pCombo = new ComboBox(...);
pCombo->AddItem("Text", new KeyValues("UserData", "Key", "Value"));
Button *pButton = new Button(...);
KeyValues *kv = new KeyValues("ButtonCommand");
pButton->SetCommand(kv);
kv->deleteThis();

有用的循环

The following loops are contained in the following function: void Traverse(KeyValues *pKV);

所有子键

for ( KeyValues *sub = pKV->GetFirstSubKey(); sub; sub = sub->GetNextKey() )

This loop steps through all subkeys contained in pKV.To handle subkeys with their own subkeys in pKV, you may want use a recursive loop. To check if a subkey has subkeys, do the following:

if(sub->GetFirstSubKey())
{
	Traverse(sub);
}

所有数值

for ( KeyValues *sub = pKV->GetFirstValue(); sub; sub = sub->GetNextValue() )

This loop steps through all subkeys contained in a pKV that have values.It is also valid to use the KeyValues member function GetDataType in the loop to do a type specific traverse.

Previous脚本NextGameinfo.txt

Last updated 3 years ago

Was this helpful?

EDIT : This does not appear to be the case (Refer or codeblock bellow).

Source:

this
https://developer.valvesoftware.com/wiki/KeyValues