summaryrefslogtreecommitdiff
path: root/cheat/gmod/fnv.hpp
diff options
context:
space:
mode:
authorboris <wzn@moneybot.cc>2018-11-28 16:00:02 +1300
committerboris <wzn@moneybot.cc>2018-11-28 16:00:02 +1300
commit3d412a4b30a9f7c7f51ea6562e694315948bd3da (patch)
tree26d67dfd1f3e5fd12903ad13e85d0cb8bcf8f21c /cheat/gmod/fnv.hpp
parente4729e4393d90271a3814c7a79950a660c48325a (diff)
cleaned up
in short, the cheat and loader are now separate solutions. unused stuff was moved into the legacy solution in case anyone wants to compile it or whatever. i can change this back if you want to. also, i configured the loader to compile in x64, and have separate build types for linux and win64
Diffstat (limited to 'cheat/gmod/fnv.hpp')
-rw-r--r--cheat/gmod/fnv.hpp64
1 files changed, 64 insertions, 0 deletions
diff --git a/cheat/gmod/fnv.hpp b/cheat/gmod/fnv.hpp
new file mode 100644
index 0000000..a3f2dc9
--- /dev/null
+++ b/cheat/gmod/fnv.hpp
@@ -0,0 +1,64 @@
+#pragma once
+
+#pragma warning( disable : 4307 ) // '*': integral constant overflow
+#pragma warning( disable : 4244 ) // possible loss of data
+
+#include <cstdint>
+#include <string>
+
+using hash_t = unsigned int;
+
+// used for compile-time FNV-1a 32bit hashes.
+#define fnv( str ) \
+ [&]() { \
+ constexpr hash_t out = hash::fnv1a( str ); \
+ \
+ return out; \
+ }()
+
+// used for compile-time FNV-1a 32bit hashes when above macro cant be used for constexpr variables.
+#define fnv_const( str ) Hash::fnv1a_32( str )
+
+namespace hash // FNV-1a ( Fowler-Noll-Vo hash ).
+{
+ // FNV-1a constants.
+ enum : hash_t {
+ FNV1A_PRIME = 0x1000193,
+ FNV1A_BASIS = 0x811C9DC5
+ };
+
+ // compile-time strlen.
+ __forceinline constexpr size_t ct_strlen( const char *str ) {
+ size_t out = 1;
+
+ for( ; str[ out ] != '\0'; ++out );
+
+ return out;
+ }
+
+ // hash data.
+ __forceinline constexpr hash_t fnv1a( const uint8_t *data, const size_t len ) {
+ hash_t out = FNV1A_BASIS;
+
+ for( size_t i = 0; i < len; ++i )
+ out = ( out ^ data[ i ] ) * FNV1A_PRIME;
+
+ return out;
+ }
+
+ // hash c-style string.
+ __forceinline constexpr hash_t fnv1a( const char *str ) {
+ hash_t out = FNV1A_BASIS;
+ size_t len = ct_strlen( str );
+
+ for( size_t i = 0; i < len; ++i )
+ out = ( out ^ str[ i ] ) * FNV1A_PRIME;
+
+ return out;
+ }
+
+ // hash C++-style string ( runtime only ).
+ __forceinline hash_t fnv1a( const std::string &str ) {
+ return fnv1a( ( uint8_t* )str.c_str( ), str.length( ) );
+ }
+} \ No newline at end of file