diff --git a/xinput1_3/fnv1a.hpp b/xinput1_3/fnv1a.hpp new file mode 100644 index 0000000..1d1b017 --- /dev/null +++ b/xinput1_3/fnv1a.hpp @@ -0,0 +1,44 @@ +#pragma once +/* +VCSamples +Copyright (c) Microsoft Corporation +All rights reserved. +MIT License +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +of the Software, and to permit persons to whom the Software is furnished to do +so, subject to the following conditions: +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. +THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ +#include + +inline size_t fnv1a_hash_bytes(const unsigned char* first, size_t count) { +#if defined(_WIN64) + static_assert(sizeof(size_t) == 8, "This code is for 64-bit size_t."); + const size_t fnv_offset_basis = 14695981039346656037ULL; + const size_t fnv_prime = 1099511628211ULL; + +#else /* defined(_WIN64) */ + static_assert(sizeof(size_t) == 4, "This code is for 32-bit size_t."); + const size_t fnv_offset_basis = 2166136261U; + const size_t fnv_prime = 16777619U; +#endif /* defined(_WIN64) */ + + size_t result = fnv_offset_basis; + for (size_t next = 0; next < count; ++next) + { // fold in another byte + result ^= (size_t)first[next]; + result *= fnv_prime; + } + return (result); +} \ No newline at end of file diff --git a/xinput1_3/xinput1_3.cpp b/xinput1_3/xinput1_3.cpp index 3c5f878..871db17 100644 --- a/xinput1_3/xinput1_3.cpp +++ b/xinput1_3/xinput1_3.cpp @@ -1,9 +1,21 @@ #include "stdafx.h" #include "wrapped.h" +#include "fnv1a.hpp" // Hashing structure for GUID namespace std { + template + struct _Bitwise_hash + { // hash functor for plain old data + typedef _Kty argument_type; + typedef size_t result_type; + + size_t operator()(const _Kty& _Keyval) const + { // hash _Keyval to size_t value by pseudorandomizing transform + return (fnv1a_hash_bytes((const unsigned char*)&_Keyval, sizeof(_Kty))); + } + }; template<> struct hash : public std::_Bitwise_hash{}; } // DI stuff diff --git a/xinput1_3/xinput1_3.vcxproj b/xinput1_3/xinput1_3.vcxproj index 35c6332..0d1fd20 100644 --- a/xinput1_3/xinput1_3.vcxproj +++ b/xinput1_3/xinput1_3.vcxproj @@ -30,27 +30,27 @@ {3941E9F8-2E29-4D69-8717-F74562ED5301} Win32Proj xinput1_3 - 8.1 + 10.0 DynamicLibrary true NotSet - v140 + v142 DynamicLibrary true NotSet - v140 + v142 DynamicLibrary false true MultiByte - v140 + v142 false false @@ -59,7 +59,7 @@ false true MultiByte - v140 + v142 false false @@ -68,7 +68,7 @@ false true MultiByte - v140 + v142 false false @@ -77,7 +77,7 @@ false true MultiByte - v140 + v142 false false @@ -271,6 +271,7 @@ + diff --git a/xinput1_3/xinput1_3.vcxproj.filters b/xinput1_3/xinput1_3.vcxproj.filters index 8c57b2e..06e3a45 100644 --- a/xinput1_3/xinput1_3.vcxproj.filters +++ b/xinput1_3/xinput1_3.vcxproj.filters @@ -38,6 +38,9 @@ Header Files + + Header Files +