Skip to content
This repository has been archived by the owner on Apr 23, 2024. It is now read-only.

String attributes preview

Pre-release
Pre-release
Compare
Choose a tag to compare
@nosoop nosoop released this 14 Feb 12:31

This prerelease adds support for string attributes! This one was a doozy.

⚠️ WARNING: This is an experimental release. I've tested the new code paths and they seem to work without issue, but let me know if you discover something in the new functionality that isn't working like it should. Any questions / comments / issues with this prerelease should be posted in the pull request or in the thread on AlliedModders (not in the issues section of this repository! this isn't a proper release yet). Accelerator logs are a big plus.

Nobody mentioned any crashes on it, so consider this a stable release.

Added

  • Native TF2Attrib_SetFromStringValue lets you provide an attribute name and value as a string, then the game just Does The Right Thing™ and parses it into a runtime attribute with the proper type. This uses the same functionality that the game uses when reading attribute key / value pairs from the schema, so it should work with most attributes you throw at it.
    • Of course, you still can't network custom strings to the client (and they are likely to crash if you use an attribute they attempt to read), so this is only useful for attributes accessed on the server (but! you can inject custom attribute classes into the server's in-memory schema now, so you can use strings for those, too).
  • Native TF2Attrib_HookValueString, which behaves similar to the other TF2Attrib_HookValue* natives — it takes advantage of the game's caching system and takes an attribute class instead of a specific attribute name. You can get the value of an attribute string this way.
  • Native TF2Attrib_UnsafeGetStringValue, which takes a raw attribute value for a string attribute (specifically, an address to a CAttribute_String instance) and reads out the containing string.
  • An internal heap-tracking system that manages heap-allocated runtime attributes. The game doesn't manage such things itself (it only does this for GC and static attributes).
  • A caching layer for the name / attribute mapping. The precedent was set with the heap-tracking functionality. I was going to commit this separately, but I already pushed more code on top and it's a pain to rebase.