Skip to content

Update hash staff & engine sync #303

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 31 commits into
base: cs2
Choose a base branch
from
Draft

Conversation

Wend4r
Copy link

@Wend4r Wend4r commented Mar 11, 2025

Preparing changes before Source 2 Engine sync (HLX branch) into Counter-Strike 2. The methods/definitions were added carefully for compatibility with the current game code (so far).

Sync HL2SDK (CS2)

CBufferStringN

  • Perform an one-time Purge of CBufferStringN.
  • Set the template default size to 128 bytes (most common use case).

CUtlStringToken

  • Added constexpr constructor to inline the hash value.
  • Added operators for comparison in the utl containers.
  • Added CUtlStringTokenHashMethod class to pass the compare function into CUtlHash.
  • Expanded MakeStringToken capabilities.
  • Added MakeStringToken2 function to calculate a runtime hash with CBufferStringN.

CUtlSymbolTable

  • Added FOR_EACH_SYMBOL(_BACK) macro to iterate by the table.
  • Added Hash methods to get a hash by the sybmol.
  • Added Remove method to remove the symbol (is needed to remove the pluginself game system factory for safe unloading).
  • Added definite hash table methods.

CUtlStringMap

  • Added FOR_EACH_STRING_MAP macro to iterate by the map.
  • Added FindAndRemove method (for gsplugin's safe unloading)

CUtlSymbolTableLargeBase

  • Added FOR_EACH_SYMBOL_LARGE(_BACK) macro to iterate by the table.
  • Made String, Hash & GetNumString methods public to get the symbol large data.

CKV3MemberName

  • Added CUtlStringToken inherit for the child methods & compare operators.
  • Added constexpr constructor to inline the hash value & string.
  • Added Make method & constructors to calculate a runtime hash.

KeyValues3

  • Added FOR_EACH_KV3_ARRAY(_BACK) macro to iterate by the kv3array.
  • Added FOR_EACH_KV3_TABLE(_BACK) macro to iterate by the kv3table.
  • Added CKV3MemberNameWithStorage container (Pulse thing)
  • Added CKV3MemberNameSet definition (Pulse thing; aka KeyValues3 with KV_TYPE_ARRAY)
  • Added CKeyValues3StringAndHash definition (old CKV3MemberName name).
  • Added KeyValues3LowercaseHash_t definition (aka CUtlStringToken).
  • Added IsArray/GetArray method.
  • Added IsTable/GetTable method.
  • Added Internal_FindMember method (also in the kv3table).
  • Renamed GetMemberNameEx to GetKV3MemberName (like-in the engine).
  • Added HasInvalidMemberNames & SetHasInvalidMemberNames methods (also in/of the kv3table; used for unserialize an ekv).
  • Added RenameMember method.
  • Added OverlayKeysFrom method.
  • Expanded PrepareForType arguments to pass ones into Alloc.

Changes that will affect the current SDK's works

  • Add a new integer template argument to the base utl containers (by default 0) that usually uses together store Vulkan or animgraph containers (@gishi523 or more engine research; not to be confused with non-added CUtlVectorBase<T, I, A>; important for the named signatures of platform-overloaded functions)
  • Delete the schema static fields & add a baked unbinding field funciton (done locally, preparing)
  • Update ICvar & convar structures (in the dota branch)

@Wend4r Wend4r marked this pull request as draft March 11, 2025 06:28
Copy link
Member

@GAMMACASE GAMMACASE left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall thanks for the work, highly appreciate it!

Comment on lines +85 to +106
CUtlSymbol Insert( const char *pString, const T &item )
{
CUtlSymbol symbol = m_SymbolTable.AddString( pString ); // implicit coercion
if ( m_Vector.Count() > symbol )
{
// this string is already in the dictionary.

}
else if ( m_Vector.Count() == symbol )
{
// this is the expected case when we've added one more to the tail.
m_Vector.AddToTail( item );
}
else // ( m_Vector.Count() < symbol )
{
// this is a strange shouldn't-happen case.
AssertMsg( false, "CUtlStringMap insert unexpected entries." );
m_Vector.EnsureCount( symbol + 1 );
m_Vector[symbol] = item;
}
return symbol;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no real need in such a method as utlstringmap expects you to do insertions directly by a key, example:

stringmap[newkey] = newvalue;

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is needed to add a new string key & insert it into the expanded utlvector.
CUtlStringMap's operators are desiged for getting/setting an existing key.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are tho, how else would you expect new entries to be added there? You can test yourself these with adding new keys. This code in particular handles that

T& operator[]( const char *pString )
{
CUtlSymbol symbol = m_SymbolTable.AddString( pString );
int index = ( int )symbol;
if( m_Vector.Count() <= index )
{
m_Vector.EnsureCount( index + 1 );
}
return m_Vector[index];
}

Comment on lines +125 to +127
// Remove once symbol element.
// @Wend4r: The table is not designed for that.
void Remove( CUtlSymbol id ) { m_HashTable.Remove( id ); m_MemBlocks[ id ] = MEMBLOCKHANDLE_INVALID; }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As per your note, container isn't designed for such removals, so no need to hack them in and potentially hurting other code relying on such behavior, please, revert this.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is necessary for gsplugins to remove game system factory from &IGameSystem::sm_GameSystemFactories for safe unloading a meta plugin & map changing. Are you sure?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If all you need is to remove entry from a stringmap, just empty it like you did in the method but do that externally, there's no need for such methods just to satisfy that particular feature.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I'll think about it, how to do it without the Remove method

Copy link
Member

@GAMMACASE GAMMACASE Mar 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well since all you do in a stringmap::Remove method is vec[symbol] = {}, you can achieve the same with stringmap[key] = {}

@@ -1758,6 +1837,40 @@ void CKeyValues3Table::CopyFrom( KeyValues3 *parent, const CKeyValues3Table* src
EnableFastSearch();
}

void CKeyValues3Table::RenameMember( KeyValues3 *parent, KV3MemberId_t id, const CKV3MemberName &newName )
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While you at it, how about adding an assert to ensure the id is within valid range, for this method and any other that take id (like RemoveMember)

Comment on lines +17 to +18
#include <string.h>
#include "bufferstring.h"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These includes introduce cyclic include dependency issues which causes some parts of the code to fail. As per the comments below these are better removed from here anyway!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Solved it in the slightly different way

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think what you did is sane enough, moving stuff around like that to satisfy the needs isn't ideal especially for stuff that always been there, please, just remove the utlstring and bufferstring from stringtoken as that will fix every issue related to this.

Wend4r and others added 17 commits March 15, 2025 08:07
Co-authored-by: GAMMACASE <31375974+GAMMACASE@users.noreply.github.com>
Co-authored-by: Co-authored-by: GAMMACASE <31375974+GAMMACASE@users.noreply.github.com>
Co-authored-by: GAMMACASE <31375974+GAMMACASE@users.noreply.github.com>
Co-authored-by: GAMMACASE <31375974+GAMMACASE@users.noreply.github.com>
Co-authored-by: GAMMACASE <31375974+GAMMACASE@users.noreply.github.com>
Co-authored-by: GAMMACASE <31375974+GAMMACASE@users.noreply.github.com>
Co-authored-by: GAMMACASE <31375974+GAMMACASE@users.noreply.github.com>
Use `DefaultHashFunctor< CUtlStringToken >` instead

Co-authored-by: GAMMACASE <31375974+GAMMACASE@users.noreply.github.com>
Co-authored-by: GAMMACASE <31375974+GAMMACASE@users.noreply.github.com>
Co-authored-by: GAMMACASE <31375974+GAMMACASE@users.noreply.github.com>
Co-authored-by: GAMMACASE <31375974+GAMMACASE@users.noreply.github.com>
…alue` back

Update hash value type

Co-authored-by: GAMMACASE <31375974+GAMMACASE@users.noreply.github.com>
Co-authored-by: GAMMACASE <31375974+GAMMACASE@users.noreply.github.com>
To prevent non-kv3(array/table) values into a loop body
@Wend4r
Copy link
Author

Wend4r commented Mar 15, 2025

It works fine with CS2Fixes-based plugin (on SteamRT side), but I'll continue to work on this PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants