提供一个API,用于通过内容或创意工坊ID检查玩家是否拥有DLC物品和皮肤
Workshop ID 是你在 steam 上看到的(例如 https://steamcommunity.com/sharedfiles/filedetails/?id=513329998),大多数皮肤插件将使用 Workshop ID。
Content ID 是 Rust 自己的付费内容标识符
我将讨论他声明的两部分,这两部分与这个插件相关。
原生的CheckSkinOwnership方法,需要你提供要检查的DLC的ID。如果你只有像大多数插件一样只有workshop ID,那就没有用了。但假设你确实有DLC ID。
函数执行的第一件事是调用ItemSkinDirectoryFindByInventoryDefinitionId方法来查找DLC信息。该方法进行了两次Linq调用,每次都会为每个检查的ID生成垃圾,Where和FirstOrDefault。(见:https://www.jacksondunstan.com/articles/4840 )
这个插件有2个API方法,其结果与原生函数相同;
CheckContentOwnership 接收一个 DLC ID,与原生方法相同,但没有垃圾分配。
IsOwnedOrFreeSkin 接受的是一个创意工坊ID而不是DLC ID,对于存储创意工坊ID的插件非常有用,并且没有垃圾分配
通过Oxides hook API调用这两个API方法比运行原生的CheckSkinOwnership函数更快。
以下是3种方法连续3次与每种批准的皮肤进行基准测试的结果。
-------------------------------------------------
[API] IsOwnedOrFreeSkin: 5469 iterations
Totals: Time: 7.5846ms | Allocations: 0 bytes
Average: Time: 0.0014ms | Allocations: 0 bytes
-------------------------------------------------
[API] CheckContentOwnership: 5469 iterations
Totals: Time: 6.0259ms | Allocations: 0 bytes
Average: Time: 0.0011ms | Allocations: 0 bytes
-------------------------------------------------
[Native] CheckSkinOwnership: 5469 iterations
Totals: Time: 14.4965ms | Allocations: 143360 bytes
Average: Time: 0.0027ms | Allocations: 26 bytes
-------------------------------------------------
[API] IsOwnedOrFreeSkin: 5469 iterations
Totals: Time: 5.9590ms | Allocations: 0 bytes
Average: Time: 0.0011ms | Allocations: 0 bytes
-------------------------------------------------
[API] CheckContentOwnership: 5469 iterations
Totals: Time: 5.6988ms | Allocations: 0 bytes
Average: Time: 0.0010ms | Allocations: 0 bytes
-------------------------------------------------
[Native] CheckSkinOwnership: 5469 iterations
Totals: Time: 14.4887ms | Allocations: 139264 bytes
Average: Time: 0.0026ms | Allocations: 25 bytes
-------------------------------------------------
[API] IsOwnedOrFreeSkin: 5469 iterations
Totals: Time: 6.3950ms | Allocations: 0 bytes
Average: Time: 0.0012ms | Allocations: 0 bytes
-------------------------------------------------
[API] CheckContentOwnership: 5469 iterations
Totals: Time: 5.5006ms | Allocations: 0 bytes
Average: Time: 0.0010ms | Allocations: 0 bytes
-------------------------------------------------
[Native] CheckSkinOwnership: 5469 iterations
Totals: Time: 14.1449ms | Allocations: 135168 bytes
Average: Time: 0.0026ms | Allocations: 24 bytes
这个插件不仅为DLC ID和以及创意工坊ID提供了更快且不分配内存的方法,它还允许你在一个调用中过滤一个玩家的整个DLC/创意工坊ID列表,从而只留下玩家允许使用的ID列表。
The HasLicense 函数要求您已经创建了该物品。然后它会调用 steam_api64.dll 管理二进制文件。我们无法在那里访问 C 源代码,但很可能会向 Steam 发送 API 请求进行比较。
归根结底,我不在乎其他开发者是否想使用这个插件。我会在我的所有插件中使用它,以便快速轻松地过滤出内容玩家无法使用的内容。
如果有人想自己尝试,我可以发布用于基准测试的插件。
Workshop ID 是你在 steam 上看到的(例如 https://steamcommunity.com/sharedfiles/filedetails/?id=513329998),大多数皮肤插件将使用 Workshop ID。
Content ID 是 Rust 自己的付费内容标识符
为什么这个插件有用
我必须这样做真是太蠢了,但来自codefling的Death认为这个插件是过度复杂化,并且有昂贵的API调用。Death不知道他在说什么,因为我没有使用codefling,所以我将在这里发布我对他的指控的反驳。我将讨论他声明的两部分,这两部分与这个插件相关。
原生的CheckSkinOwnership方法,需要你提供要检查的DLC的ID。如果你只有像大多数插件一样只有workshop ID,那就没有用了。但假设你确实有DLC ID。
函数执行的第一件事是调用ItemSkinDirectoryFindByInventoryDefinitionId方法来查找DLC信息。该方法进行了两次Linq调用,每次都会为每个检查的ID生成垃圾,Where和FirstOrDefault。(见:https://www.jacksondunstan.com/articles/4840 )
这个插件有2个API方法,其结果与原生函数相同;
CheckContentOwnership 接收一个 DLC ID,与原生方法相同,但没有垃圾分配。
IsOwnedOrFreeSkin 接受的是一个创意工坊ID而不是DLC ID,对于存储创意工坊ID的插件非常有用,并且没有垃圾分配
通过Oxides hook API调用这两个API方法比运行原生的CheckSkinOwnership函数更快。
以下是3种方法连续3次与每种批准的皮肤进行基准测试的结果。
-------------------------------------------------
[API] IsOwnedOrFreeSkin: 5469 iterations
Totals: Time: 7.5846ms | Allocations: 0 bytes
Average: Time: 0.0014ms | Allocations: 0 bytes
-------------------------------------------------
[API] CheckContentOwnership: 5469 iterations
Totals: Time: 6.0259ms | Allocations: 0 bytes
Average: Time: 0.0011ms | Allocations: 0 bytes
-------------------------------------------------
[Native] CheckSkinOwnership: 5469 iterations
Totals: Time: 14.4965ms | Allocations: 143360 bytes
Average: Time: 0.0027ms | Allocations: 26 bytes
-------------------------------------------------
[API] IsOwnedOrFreeSkin: 5469 iterations
Totals: Time: 5.9590ms | Allocations: 0 bytes
Average: Time: 0.0011ms | Allocations: 0 bytes
-------------------------------------------------
[API] CheckContentOwnership: 5469 iterations
Totals: Time: 5.6988ms | Allocations: 0 bytes
Average: Time: 0.0010ms | Allocations: 0 bytes
-------------------------------------------------
[Native] CheckSkinOwnership: 5469 iterations
Totals: Time: 14.4887ms | Allocations: 139264 bytes
Average: Time: 0.0026ms | Allocations: 25 bytes
-------------------------------------------------
[API] IsOwnedOrFreeSkin: 5469 iterations
Totals: Time: 6.3950ms | Allocations: 0 bytes
Average: Time: 0.0012ms | Allocations: 0 bytes
-------------------------------------------------
[API] CheckContentOwnership: 5469 iterations
Totals: Time: 5.5006ms | Allocations: 0 bytes
Average: Time: 0.0010ms | Allocations: 0 bytes
-------------------------------------------------
[Native] CheckSkinOwnership: 5469 iterations
Totals: Time: 14.1449ms | Allocations: 135168 bytes
Average: Time: 0.0026ms | Allocations: 24 bytes
这个插件不仅为DLC ID和以及创意工坊ID提供了更快且不分配内存的方法,它还允许你在一个调用中过滤一个玩家的整个DLC/创意工坊ID列表,从而只留下玩家允许使用的ID列表。
The HasLicense 函数要求您已经创建了该物品。然后它会调用 steam_api64.dll 管理二进制文件。我们无法在那里访问 C 源代码,但很可能会向 Steam 发送 API 请求进行比较。
归根结底,我不在乎其他开发者是否想使用这个插件。我会在我的所有插件中使用它,以便快速轻松地过滤出内容玩家无法使用的内容。
如果有人想自己尝试,我可以发布用于基准测试的插件。