From 943a3acc24c7fb4359a00ce6ebc086a7e902acdb Mon Sep 17 00:00:00 2001 From: Silent Date: Sun, 5 Mar 2017 22:25:46 +0100 Subject: [PATCH] add Patternies --- SilentPatch/Patterns.cpp | 269 +++++ SilentPatch/Patterns.h | 175 ++++ SilentPatch/string_view.hpp | 919 ++++++++++++++++++ SilentPatchIII/SilentPatchIII.vcxproj | 5 + SilentPatchIII/SilentPatchIII.vcxproj.filters | 6 + SilentPatchSA/SilentPatchSA.vcxproj | 5 + SilentPatchSA/SilentPatchSA.vcxproj.filters | 6 + SilentPatchVC/SilentPatchVC.vcxproj | 5 + SilentPatchVC/SilentPatchVC.vcxproj.filters | 6 + 9 files changed, 1396 insertions(+) create mode 100644 SilentPatch/Patterns.cpp create mode 100644 SilentPatch/Patterns.h create mode 100644 SilentPatch/string_view.hpp diff --git a/SilentPatch/Patterns.cpp b/SilentPatch/Patterns.cpp new file mode 100644 index 0000000..5e0f054 --- /dev/null +++ b/SilentPatch/Patterns.cpp @@ -0,0 +1,269 @@ +/* + * This file is part of the CitizenFX project - http://citizen.re/ + * + * See LICENSE and MENTIONS in the root of the source tree for information + * regarding licensing. + */ + +#include "Patterns.h" + +#define WIN32_LEAN_AND_MEAN +#define NOMINMAX +#include +#include +#include "string_view.hpp" + +#if PATTERNS_USE_HINTS +#include +#endif + + +#if PATTERNS_USE_HINTS + +// from boost someplace +template +struct basic_fnv_1 +{ + std::uint64_t operator()(libcxx_strviewclone::string_view text) const + { + std::uint64_t hash = OffsetBasis; + for (auto it : text) + { + hash *= FnvPrime; + hash ^= it; + } + + return hash; + } +}; + +const std::uint64_t fnv_prime = 1099511628211u; +const std::uint64_t fnv_offset_basis = 14695981039346656037u; + +typedef basic_fnv_1 fnv_1; + +#endif + +namespace hook +{ + ptrdiff_t baseAddressDifference; + + // sets the base to the process main base + void set_base() + { + set_base((uintptr_t)GetModuleHandle(nullptr)); + } + + +#if PATTERNS_USE_HINTS +static std::multimap g_hints; +#endif + +static void TransformPattern(libcxx_strviewclone::string_view pattern, std::string& data, std::string& mask) +{ + uint8_t tempDigit = 0; + bool tempFlag = false; + + auto tol = [] (char ch) -> uint8_t + { + if (ch >= 'A' && ch <= 'F') return uint8_t(ch - 'A' + 10); + if (ch >= 'a' && ch <= 'f') return uint8_t(ch - 'a' + 10); + return uint8_t(ch - '0'); + }; + + for (auto ch : pattern) + { + if (ch == ' ') + { + continue; + } + else if (ch == '?') + { + data.push_back(0); + mask.push_back('?'); + } + else if ((ch >= '0' && ch <= '9') || (ch >= 'A' && ch <= 'F') || (ch >= 'a' && ch <= 'f')) + { + uint8_t thisDigit = tol(ch); + + if (!tempFlag) + { + tempDigit = thisDigit << 4; + tempFlag = true; + } + else + { + tempDigit |= thisDigit; + tempFlag = false; + + data.push_back(tempDigit); + mask.push_back('x'); + } + } + } +} + +class executable_meta +{ +private: + uintptr_t m_begin; + uintptr_t m_end; + +public: + template + TReturn* getRVA(TOffset rva) + { + return (TReturn*)(m_begin + rva); + } + + executable_meta(void* module) + : m_begin((uintptr_t)module) + { + PIMAGE_DOS_HEADER dosHeader = getRVA(0); + PIMAGE_NT_HEADERS ntHeader = getRVA(dosHeader->e_lfanew); + + m_end = m_begin + ntHeader->OptionalHeader.SizeOfCode; + } + + inline uintptr_t begin() const { return m_begin; } + inline uintptr_t end() const { return m_end; } +}; + +void pattern::Initialize(const char* pattern, size_t length) +{ + // get the hash for the base pattern +#if PATTERNS_USE_HINTS + m_hash = fnv_1()(libcxx_strviewclone::string_view(pattern, length)); +#endif + + // transform the base pattern from IDA format to canonical format + TransformPattern(libcxx_strviewclone::string_view(pattern, length), m_bytes, m_mask); + + m_size = m_mask.size(); + +#if PATTERNS_USE_HINTS + // if there's hints, try those first + if (m_module == GetModuleHandle(nullptr)) + { + auto range = g_hints.equal_range(m_hash); + + if (range.first != range.second) + { + std::for_each(range.first, range.second, [&] (const std::pair& hint) + { + ConsiderMatch(hint.second); + }); + + // if the hints succeeded, we don't need to do anything more + if (!m_matches.empty()) + { + m_matched = true; + return; + } + } + } +#endif +} + +void pattern::EnsureMatches(uint32_t maxCount) +{ + if (m_matched) + { + return; + } + + // scan the executable for code + executable_meta executable(m_module); + + auto matchSuccess = [&] (uintptr_t address) + { +#if PATTERNS_USE_HINTS + g_hints.emplace(m_hash, address); +#else + (void)address; +#endif + + return (m_matches.size() == maxCount); + }; + + const uint8_t* pattern = reinterpret_cast(m_bytes.c_str()); + const char* mask = m_mask.c_str(); + size_t lastWild = m_mask.find_last_of('?'); + + ptrdiff_t Last[256]; + + std::fill(std::begin(Last), std::end(Last), lastWild == std::string::npos ? -1 : static_cast(lastWild) ); + + for ( ptrdiff_t i = 0; i < static_cast(m_size); ++i ) + { + if ( Last[ pattern[i] ] < i ) + { + Last[ pattern[i] ] = i; + } + } + + for (uintptr_t i = executable.begin(), end = executable.end() - m_size; i <= end;) + { + uint8_t* ptr = reinterpret_cast(i); + ptrdiff_t j = m_size - 1; + + while((j >= 0) && (mask[j] == '?' || pattern[j] == ptr[j])) j--; + + if(j < 0) + { + m_matches.emplace_back(ptr); + + if (matchSuccess(i)) + { + break; + } + i++; + } + else i += std::max(1, j - Last[ ptr[j] ]); + } + + m_matched = true; +} + +bool pattern::ConsiderMatch(uintptr_t offset) +{ + const char* pattern = m_bytes.c_str(); + const char* mask = m_mask.c_str(); + + char* ptr = reinterpret_cast(offset); + + for (size_t i = 0; i < m_size; i++) + { + if (mask[i] == '?') + { + continue; + } + + if (pattern[i] != ptr[i]) + { + return false; + } + } + + m_matches.emplace_back(ptr); + + return true; +} + +#if PATTERNS_USE_HINTS +void pattern::hint(uint64_t hash, uintptr_t address) +{ + auto range = g_hints.equal_range(hash); + + for (auto it = range.first; it != range.second; it++) + { + if (it->second == address) + { + return; + } + } + + g_hints.emplace(hash, address); +} +#endif +} \ No newline at end of file diff --git a/SilentPatch/Patterns.h b/SilentPatch/Patterns.h new file mode 100644 index 0000000..4882742 --- /dev/null +++ b/SilentPatch/Patterns.h @@ -0,0 +1,175 @@ +/* + * This file is part of the CitizenFX project - http://citizen.re/ + * + * See LICENSE and MENTIONS in the root of the source tree for information + * regarding licensing. + */ + +#pragma once + +#include +#include + +#define PATTERNS_USE_HINTS 0 + +namespace hook +{ + extern ptrdiff_t baseAddressDifference; + + // sets the base address difference based on an obtained pointer + inline void set_base(uintptr_t address) + { +#ifdef _M_IX86 + uintptr_t addressDiff = (address - 0x400000); +#elif defined(_M_AMD64) + uintptr_t addressDiff = (address - 0x140000000); +#endif + + // pointer-style cast to ensure unsigned overflow ends up copied directly into a signed value + baseAddressDifference = *(ptrdiff_t*)&addressDiff; + } + + // sets the base to the process main base + void set_base(); + + template + inline T* getRVA(uintptr_t rva) + { + set_base(); +#ifdef _M_IX86 + return (T*)(baseAddressDifference + 0x400000 + rva); +#elif defined(_M_AMD64) + return (T*)(0x140000000 + rva); +#endif + } + + class pattern_match + { + private: + void* m_pointer; + + public: + inline pattern_match(void* pointer) + : m_pointer(pointer) + { + } + + template + T* get(ptrdiff_t offset = 0) const + { + char* ptr = reinterpret_cast(m_pointer); + return reinterpret_cast(ptr + offset); + } + }; + + class pattern + { + private: + std::string m_bytes; + std::string m_mask; + +#if PATTERNS_USE_HINTS + uint64_t m_hash; +#endif + + size_t m_size; + + std::vector m_matches; + + bool m_matched; + + void* m_module; + + protected: + inline pattern(void* module) + : m_module(module), m_matched(false) + { + } + + void Initialize(const char* pattern, size_t length); + + private: + bool ConsiderMatch(uintptr_t offset); + + void EnsureMatches(uint32_t maxCount); + + inline const pattern_match& _get_internal(size_t index) + { + return m_matches[index]; + } + + public: + template + pattern(const char (&pattern)[Len]) + : pattern(getRVA(0)) + { + Initialize(pattern, Len); + } + + inline pattern& count(uint32_t expected) + { + EnsureMatches(expected); + assert(m_matches.size() == expected); + return *this; + } + + inline pattern& count_hint(uint32_t expected) + { + EnsureMatches(expected); + return *this; + } + + inline size_t size() + { + EnsureMatches(UINT32_MAX); + return m_matches.size(); + } + + inline bool empty() + { + return size() == 0; + } + + inline const pattern_match& get(size_t index) + { + EnsureMatches(UINT32_MAX); + return _get_internal(index); + } + + inline const pattern_match& get_one() + { + return count(1)._get_internal(0); + } + + template + inline auto get_first(ptrdiff_t offset = 0) + { + return get_one().get(offset); + } + + public: +#if PATTERNS_USE_HINTS + // define a hint + static void hint(uint64_t hash, uintptr_t address); +#endif + }; + + class module_pattern + : public pattern + { + public: + template + module_pattern(void* module, const char(&pattern)[Len]) + : pattern(module) + { + Initialize(pattern, Len); + } + }; + + + template + auto get_pattern(const char(&pattern_string)[Len], ptrdiff_t offset = 0) + { + return pattern(pattern_string).get_first(offset); + } +} \ No newline at end of file diff --git a/SilentPatch/string_view.hpp b/SilentPatch/string_view.hpp new file mode 100644 index 0000000..1619d4e --- /dev/null +++ b/SilentPatch/string_view.hpp @@ -0,0 +1,919 @@ +// -*- C++ -*- +//===------------------------ string_view ---------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// This is a clone of the libcxx std::experimental::string_view (on ) +// sighly edited (by Denilson das Merces Amorim ) to be independent of the +// libcxx library stack, so this can be used as a library on other compilers. +// This should be useful/fun until all the compilers have a string_view implementation. + +#ifndef _LIBCPP_STRVIEWCLONE_LFTS_STRING_VIEW +#define _LIBCPP_STRVIEWCLONE_LFTS_STRING_VIEW + +// Some LIBCPP macros left here because they are somewhat useful. +// (renamed to LIBCPP_STRVIEWCLONE, 'course) +#include +#define __LIBCPP_STRVIEWCLONE_throw(ex) throw (ex) // Might undefine this if -fno-exceptions? Dunno. +#define _LIBCPP_STRVIEWCLONE_ASSERT(x, m) assert(x && m) // Translate libcxx assertion to C assert +#if __cplusplus < 201402L +# define _LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 +#else +# define _LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 constexpr +#endif + +/* +string_view synopsis +namespace std { + namespace experimental { + inline namespace library_fundamentals_v1 { + // 7.2, Class template basic_string_view + template> + class basic_string_view; + // 7.9, basic_string_view non-member comparison functions + template + constexpr bool operator==(basic_string_view x, + basic_string_view y) noexcept; + template + constexpr bool operator!=(basic_string_view x, + basic_string_view y) noexcept; + template + constexpr bool operator< (basic_string_view x, + basic_string_view y) noexcept; + template + constexpr bool operator> (basic_string_view x, + basic_string_view y) noexcept; + template + constexpr bool operator<=(basic_string_view x, + basic_string_view y) noexcept; + template + constexpr bool operator>=(basic_string_view x, + basic_string_view y) noexcept; + // see below, sufficient additional overloads of comparison functions + // 7.10, Inserters and extractors + template + basic_ostream& + operator<<(basic_ostream& os, + basic_string_view str); + // basic_string_view typedef names + typedef basic_string_view string_view; + typedef basic_string_view u16string_view; + typedef basic_string_view u32string_view; + typedef basic_string_view wstring_view; + template> + class basic_string_view { + public: + // types + typedef traits traits_type; + typedef charT value_type; + typedef charT* pointer; + typedef const charT* const_pointer; + typedef charT& reference; + typedef const charT& const_reference; + typedef implementation-defined const_iterator; + typedef const_iterator iterator; + typedef reverse_iterator const_reverse_iterator; + typedef const_reverse_iterator reverse_iterator; + typedef size_t size_type; + typedef ptrdiff_t difference_type; + static constexpr size_type npos = size_type(-1); + // 7.3, basic_string_view constructors and assignment operators + constexpr basic_string_view() noexcept; + constexpr basic_string_view(const basic_string_view&) noexcept = default; + basic_string_view& operator=(const basic_string_view&) noexcept = default; + template + basic_string_view(const std::basic_string& str) noexcept; + constexpr basic_string_view(const charT* str); + constexpr basic_string_view(const charT* str, size_type len); + // 7.4, basic_string_view iterator support + constexpr const_iterator begin() const noexcept; + constexpr const_iterator end() const noexcept; + constexpr const_iterator cbegin() const noexcept; + constexpr const_iterator cend() const noexcept; + const_reverse_iterator rbegin() const noexcept; + const_reverse_iterator rend() const noexcept; + const_reverse_iterator crbegin() const noexcept; + const_reverse_iterator crend() const noexcept; + // 7.5, basic_string_view capacity + constexpr size_type size() const noexcept; + constexpr size_type length() const noexcept; + constexpr size_type max_size() const noexcept; + constexpr bool empty() const noexcept; + // 7.6, basic_string_view element access + constexpr const_reference operator[](size_type pos) const; + constexpr const_reference at(size_type pos) const; + constexpr const_reference front() const; + constexpr const_reference back() const; + constexpr const_pointer data() const noexcept; + // 7.7, basic_string_view modifiers + constexpr void clear() noexcept; + constexpr void remove_prefix(size_type n); + constexpr void remove_suffix(size_type n); + constexpr void swap(basic_string_view& s) noexcept; + // 7.8, basic_string_view string operations + template + explicit operator std::basic_string() const; + template> + std::basic_string to_string( + const Allocator& a = Allocator()) const; + size_type copy(charT* s, size_type n, size_type pos = 0) const; + constexpr basic_string_view substr(size_type pos = 0, size_type n = npos) const; + constexpr int compare(basic_string_view s) const noexcept; + constexpr int compare(size_type pos1, size_type n1, basic_string_view s) const; + constexpr int compare(size_type pos1, size_type n1, + basic_string_view s, size_type pos2, size_type n2) const; + constexpr int compare(const charT* s) const; + constexpr int compare(size_type pos1, size_type n1, const charT* s) const; + constexpr int compare(size_type pos1, size_type n1, + const charT* s, size_type n2) const; + constexpr size_type find(basic_string_view s, size_type pos = 0) const noexcept; + constexpr size_type find(charT c, size_type pos = 0) const noexcept; + constexpr size_type find(const charT* s, size_type pos, size_type n) const; + constexpr size_type find(const charT* s, size_type pos = 0) const; + constexpr size_type rfind(basic_string_view s, size_type pos = npos) const noexcept; + constexpr size_type rfind(charT c, size_type pos = npos) const noexcept; + constexpr size_type rfind(const charT* s, size_type pos, size_type n) const; + constexpr size_type rfind(const charT* s, size_type pos = npos) const; + constexpr size_type find_first_of(basic_string_view s, size_type pos = 0) const noexcept; + constexpr size_type find_first_of(charT c, size_type pos = 0) const noexcept; + constexpr size_type find_first_of(const charT* s, size_type pos, size_type n) const; + constexpr size_type find_first_of(const charT* s, size_type pos = 0) const; + constexpr size_type find_last_of(basic_string_view s, size_type pos = npos) const noexcept; + constexpr size_type find_last_of(charT c, size_type pos = npos) const noexcept; + constexpr size_type find_last_of(const charT* s, size_type pos, size_type n) const; + constexpr size_type find_last_of(const charT* s, size_type pos = npos) const; + constexpr size_type find_first_not_of(basic_string_view s, size_type pos = 0) const noexcept; + constexpr size_type find_first_not_of(charT c, size_type pos = 0) const noexcept; + constexpr size_type find_first_not_of(const charT* s, size_type pos, size_type n) const; + constexpr size_type find_first_not_of(const charT* s, size_type pos = 0) const; + constexpr size_type find_last_not_of(basic_string_view s, size_type pos = npos) const noexcept; + constexpr size_type find_last_not_of(charT c, size_type pos = npos) const noexcept; + constexpr size_type find_last_not_of(const charT* s, size_type pos, size_type n) const; + constexpr size_type find_last_not_of(const charT* s, size_type pos = npos) const; + private: + const_pointer data_; // exposition only + size_type size_; // exposition only + }; + } // namespace fundamentals_v1 + } // namespace experimental + // 7.11, Hash support + template struct hash; + template <> struct hash; + template <> struct hash; + template <> struct hash; + template <> struct hash; +} // namespace std +*/ + +#include +#include +#include +#include +#include +#include +#include + +namespace libcxx_strviewclone { + + template > + class basic_string_view { + public: + // types + typedef _Traits traits_type; + typedef _CharT value_type; + typedef const _CharT* pointer; + typedef const _CharT* const_pointer; + typedef const _CharT& reference; + typedef const _CharT& const_reference; + typedef const_pointer const_iterator; // See [string.view.iterators] + typedef const_iterator iterator; + typedef std::reverse_iterator const_reverse_iterator; + typedef const_reverse_iterator reverse_iterator; + typedef size_t size_type; + typedef ptrdiff_t difference_type; + static constexpr const size_type npos = size_type(-1); + + // [string.view.cons], construct/copy + constexpr inline + basic_string_view() noexcept : __data (nullptr), __size(0) {} + + constexpr inline + basic_string_view(const basic_string_view&) noexcept = default; + + inline + basic_string_view& operator=(const basic_string_view&) noexcept = default; + + template + inline + basic_string_view(const std::basic_string<_CharT, _Traits, _Allocator>& __str) noexcept + : __data (__str.data()), __size(__str.size()) {} + + constexpr inline + basic_string_view(const _CharT* __s, size_type __len) + : __data(__s), __size(__len) + { +// _LIBCPP_STRVIEWCLONE_ASSERT(__len == 0 || __s != nullptr, "string_view::string_view(_CharT *, size_t): received nullptr"); + } + + constexpr inline + basic_string_view(const _CharT* __s) + : __data(__s), __size(_Traits::length(__s)) {} + + // [string.view.iterators], iterators + constexpr inline + const_iterator begin() const noexcept { return cbegin(); } + + constexpr inline + const_iterator end() const noexcept { return cend(); } + + constexpr inline + const_iterator cbegin() const noexcept { return __data; } + + constexpr inline + const_iterator cend() const noexcept { return __data + __size; } + + inline + const_reverse_iterator rbegin() const noexcept { return const_reverse_iterator(cend()); } + + inline + const_reverse_iterator rend() const noexcept { return const_reverse_iterator(cbegin()); } + + inline + const_reverse_iterator crbegin() const noexcept { return const_reverse_iterator(cend()); } + + inline + const_reverse_iterator crend() const noexcept { return const_reverse_iterator(cbegin()); } + + // [string.view.capacity], capacity + constexpr inline + size_type size() const noexcept { return __size; } + + constexpr inline + size_type length() const noexcept { return __size; } + + constexpr inline + size_type max_size() const noexcept { return std::numeric_limits::max(); } + + constexpr bool inline + empty() const noexcept { return __size == 0; } + + // [string.view.access], element access + constexpr inline + const_reference operator[](size_type __pos) const { return __data[__pos]; } + + constexpr inline + const_reference at(size_type __pos) const + { + return __pos >= size() + ? (__LIBCPP_STRVIEWCLONE_throw(std::out_of_range("string_view::at")), __data[0]) + : __data[__pos]; + } + + constexpr inline + const_reference front() const + { + return _LIBCPP_STRVIEWCLONE_ASSERT(!empty(), "string_view::front(): string is empty"), __data[0]; + } + + constexpr inline + const_reference back() const + { + return _LIBCPP_STRVIEWCLONE_ASSERT(!empty(), "string_view::back(): string is empty"), __data[__size-1]; + } + + constexpr inline + const_pointer data() const noexcept { return __data; } + + // [string.view.modifiers], modifiers: + _LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline + void clear() noexcept + { + __data = nullptr; + __size = 0; + } + + _LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline + void remove_prefix(size_type __n) noexcept + { + _LIBCPP_STRVIEWCLONE_ASSERT(__n <= size(), "remove_prefix() can't remove more than size()"); + __data += __n; + __size -= __n; + } + + _LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline + void remove_suffix(size_type __n) noexcept + { + _LIBCPP_STRVIEWCLONE_ASSERT(__n <= size(), "remove_suffix() can't remove more than size()"); + __size -= __n; + } + + _LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline + void swap(basic_string_view& __other) noexcept + { + const value_type *__p = __data; + __data = __other.__data; + __other.__data = __p; + + size_type __sz = __size; + __size = __other.__size; + __other.__size = __sz; +// std::swap( __data, __other.__data ); +// std::swap( __size, __other.__size ); + } + + // [string.view.ops], string operations: + template + inline + explicit operator std::basic_string<_CharT, _Traits, _Allocator>() const + { return std::basic_string<_CharT, _Traits, _Allocator>( begin(), end()); } + + template > + inline + std::basic_string<_CharT, _Traits, _Allocator> + to_string( const _Allocator& __a = _Allocator()) const + { return std::basic_string<_CharT, _Traits, _Allocator> ( begin(), end(), __a ); } + + size_type copy(_CharT* __s, size_type __n, size_type __pos = 0) const + { + if ( __pos > size()) + __LIBCPP_STRVIEWCLONE_throw(std::out_of_range("string_view::copy")); + size_type __rlen = std::min( __n, size() - __pos ); + std::copy_n(begin() + __pos, __rlen, __s ); + return __rlen; + } + + constexpr + basic_string_view substr(size_type __pos = 0, size_type __n = npos) const + { +// if (__pos > size()) +// throw out_of_range("string_view::substr"); +// size_type __rlen = std::min( __n, size() - __pos ); +// return basic_string_view(data() + __pos, __rlen); + return __pos > size() + ? (__LIBCPP_STRVIEWCLONE_throw((std::out_of_range("string_view::substr"))), basic_string_view()) + : basic_string_view(data() + __pos, std::min(__n, size() - __pos)); + } + + _LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 int compare(basic_string_view __sv) const noexcept + { + size_type __rlen = std::min( size(), __sv.size()); + int __retval = _Traits::compare(data(), __sv.data(), __rlen); + if ( __retval == 0 ) // first __rlen chars matched + __retval = size() == __sv.size() ? 0 : ( size() < __sv.size() ? -1 : 1 ); + return __retval; + } + + _LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline + int compare(size_type __pos1, size_type __n1, basic_string_view __sv) const + { + return substr(__pos1, __n1).compare(__sv); + } + + _LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline + int compare( size_type __pos1, size_type __n1, + basic_string_view _sv, size_type __pos2, size_type __n2) const + { + return substr(__pos1, __n1).compare(_sv.substr(__pos2, __n2)); + } + + _LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline + int compare(const _CharT* __s) const + { + return compare(basic_string_view(__s)); + } + + _LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline + int compare(size_type __pos1, size_type __n1, const _CharT* __s) const + { + return substr(__pos1, __n1).compare(basic_string_view(__s)); + } + + _LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline + int compare(size_type __pos1, size_type __n1, const _CharT* __s, size_type __n2) const + { + return substr(__pos1, __n1).compare(basic_string_view(__s, __n2)); + } + + // find + _LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline + size_type find(basic_string_view __s, size_type __pos = 0) const noexcept + { + _LIBCPP_STRVIEWCLONE_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find(): received nullptr"); + return this->__str_find + (data(), size(), __s.data(), __pos, __s.size()); + } + + _LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline + size_type find(_CharT __c, size_type __pos = 0) const noexcept + { + return this->__str_find + (data(), size(), __c, __pos); + } + + _LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline + size_type find(const _CharT* __s, size_type __pos, size_type __n) const + { + _LIBCPP_STRVIEWCLONE_ASSERT(__n == 0 || __s != nullptr, "string_view::find(): received nullptr"); + return this->__str_find + (data(), size(), __s, __pos, __n); + } + + _LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline + size_type find(const _CharT* __s, size_type __pos = 0) const + { + _LIBCPP_STRVIEWCLONE_ASSERT(__s != nullptr, "string_view::find(): received nullptr"); + return this->__str_find + (data(), size(), __s, __pos, traits_type::length(__s)); + } + + // rfind + _LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline + size_type rfind(basic_string_view __s, size_type __pos = npos) const noexcept + { + _LIBCPP_STRVIEWCLONE_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find(): received nullptr"); + return this->__str_rfind + (data(), size(), __s.data(), __pos, __s.size()); + } + + _LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline + size_type rfind(_CharT __c, size_type __pos = npos) const noexcept + { + return this->__str_rfind + (data(), size(), __c, __pos); + } + + _LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline + size_type rfind(const _CharT* __s, size_type __pos, size_type __n) const + { + _LIBCPP_STRVIEWCLONE_ASSERT(__n == 0 || __s != nullptr, "string_view::rfind(): received nullptr"); + return this->__str_rfind + (data(), size(), __s, __pos, __n); + } + + _LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline + size_type rfind(const _CharT* __s, size_type __pos=npos) const + { + _LIBCPP_STRVIEWCLONE_ASSERT(__s != nullptr, "string_view::rfind(): received nullptr"); + return this->__str_rfind + (data(), size(), __s, __pos, traits_type::length(__s)); + } + + // find_first_of + _LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline + size_type find_first_of(basic_string_view __s, size_type __pos = 0) const noexcept + { + _LIBCPP_STRVIEWCLONE_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find_first_of(): received nullptr"); + return this->__str_find_first_of + (data(), size(), __s.data(), __pos, __s.size()); + } + + _LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline + size_type find_first_of(_CharT __c, size_type __pos = 0) const noexcept + { return find(__c, __pos); } + + _LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline + size_type find_first_of(const _CharT* __s, size_type __pos, size_type __n) const + { + _LIBCPP_STRVIEWCLONE_ASSERT(__n == 0 || __s != nullptr, "string_view::find_first_of(): received nullptr"); + return this->__str_find_first_of + (data(), size(), __s, __pos, __n); + } + + _LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline + size_type find_first_of(const _CharT* __s, size_type __pos=0) const + { + _LIBCPP_STRVIEWCLONE_ASSERT(__s != nullptr, "string_view::find_first_of(): received nullptr"); + return this->__str_find_first_of + (data(), size(), __s, __pos, traits_type::length(__s)); + } + + // find_last_of + _LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline + size_type find_last_of(basic_string_view __s, size_type __pos=npos) const noexcept + { + _LIBCPP_STRVIEWCLONE_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find_last_of(): received nullptr"); + return this->__str_find_last_of + (data(), size(), __s.data(), __pos, __s.size()); + } + + _LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline + size_type find_last_of(_CharT __c, size_type __pos = npos) const noexcept + { return rfind(__c, __pos); } + + _LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline + size_type find_last_of(const _CharT* __s, size_type __pos, size_type __n) const + { + _LIBCPP_STRVIEWCLONE_ASSERT(__n == 0 || __s != nullptr, "string_view::find_last_of(): received nullptr"); + return this->__str_find_last_of + (data(), size(), __s, __pos, __n); + } + + _LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline + size_type find_last_of(const _CharT* __s, size_type __pos=npos) const + { + _LIBCPP_STRVIEWCLONE_ASSERT(__s != nullptr, "string_view::find_last_of(): received nullptr"); + return this->__str_find_last_of + (data(), size(), __s, __pos, traits_type::length(__s)); + } + + // find_first_not_of + _LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline + size_type find_first_not_of(basic_string_view __s, size_type __pos=0) const noexcept + { + _LIBCPP_STRVIEWCLONE_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find_first_not_of(): received nullptr"); + return this->__str_find_first_not_of + (data(), size(), __s.data(), __pos, __s.size()); + } + + _LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline + size_type find_first_not_of(_CharT __c, size_type __pos=0) const noexcept + { + return this->__str_find_first_not_of + (data(), size(), __c, __pos); + } + + _LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline + size_type find_first_not_of(const _CharT* __s, size_type __pos, size_type __n) const + { + _LIBCPP_STRVIEWCLONE_ASSERT(__n == 0 || __s != nullptr, "string_view::find_first_not_of(): received nullptr"); + return this->__str_find_first_not_of + (data(), size(), __s, __pos, __n); + } + + _LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline + size_type find_first_not_of(const _CharT* __s, size_type __pos=0) const + { + _LIBCPP_STRVIEWCLONE_ASSERT(__s != nullptr, "string_view::find_first_not_of(): received nullptr"); + return this->__str_find_first_not_of + (data(), size(), __s, __pos, traits_type::length(__s)); + } + + // find_last_not_of + _LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline + size_type find_last_not_of(basic_string_view __s, size_type __pos=npos) const noexcept + { + _LIBCPP_STRVIEWCLONE_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find_last_not_of(): received nullptr"); + return this->__str_find_last_not_of + (data(), size(), __s.data(), __pos, __s.size()); + } + + _LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline + size_type find_last_not_of(_CharT __c, size_type __pos=npos) const noexcept + { + return this->__str_find_last_not_of + (data(), size(), __c, __pos); + } + + _LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline + size_type find_last_not_of(const _CharT* __s, size_type __pos, size_type __n) const + { + _LIBCPP_STRVIEWCLONE_ASSERT(__n == 0 || __s != nullptr, "string_view::find_last_not_of(): received nullptr"); + return this->__str_find_last_not_of + (data(), size(), __s, __pos, __n); + } + + _LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline + size_type find_last_not_of(const _CharT* __s, size_type __pos=npos) const + { + _LIBCPP_STRVIEWCLONE_ASSERT(__s != nullptr, "string_view::find_last_not_of(): received nullptr"); + return this->__str_find_last_not_of + (data(), size(), __s, __pos, traits_type::length(__s)); + } + + private: + // + // Some function taken from libcxx internals and put here, as private methods of string_view. + // + + // __str_find + template + static _SizeT _LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline + __str_find(const _CharT *__p, _SizeT __sz, + const _CharT* __s, _SizeT __pos, _SizeT __n) noexcept + { + if (__pos > __sz || __sz - __pos < __n) + return __npos; + if (__n == 0) + return __pos; + const _CharT* __r = + std::search(__p + __pos, __p + __sz, + __s, __s + __n, _Traits::eq); + if (__r == __p + __sz) + return __npos; + return static_cast<_SizeT>(__r - __p); + } + + // __str_rfind + template + static _SizeT _LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline + __str_rfind(const _CharT *__p, _SizeT __sz, + const _CharT* __s, _SizeT __pos, _SizeT __n) noexcept + { + __pos = std::min(__pos, __sz); + if (__n < __sz - __pos) + __pos += __n; + else + __pos = __sz; + const _CharT* __r = std::find_end( + __p, __p + __pos, __s, __s + __n, _Traits::eq); + if (__n > 0 && __r == __p + __pos) + return __npos; + return static_cast<_SizeT>(__r - __p); + } + + // __str_find_first_of + template + static _SizeT _LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline + __str_find_first_of(const _CharT *__p, _SizeT __sz, + const _CharT* __s, _SizeT __pos, _SizeT __n) noexcept + { + if (__pos >= __sz || __n == 0) + return __npos; + const _CharT* __r = std::find_first_of + (__p + __pos, __p + __sz, __s, __s + __n, _Traits::eq ); + if (__r == __p + __sz) + return __npos; + return static_cast<_SizeT>(__r - __p); + } + + + // __str_find_last_of + template + static _SizeT _LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline + __str_find_last_of(const _CharT *__p, _SizeT __sz, + const _CharT* __s, _SizeT __pos, _SizeT __n) noexcept + { + if (__n != 0) + { + if (__pos < __sz) + ++__pos; + else + __pos = __sz; + for (const _CharT* __ps = __p + __pos; __ps != __p;) + { + const _CharT* __r = _Traits::find(__s, __n, *--__ps); + if (__r) + return static_cast<_SizeT>(__ps - __p); + } + } + return __npos; + } + + + // __str_find_first_not_of + template + static _SizeT _LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline + __str_find_first_not_of(const _CharT *__p, _SizeT __sz, + const _CharT* __s, _SizeT __pos, _SizeT __n) noexcept + { + if (__pos < __sz) + { + const _CharT* __pe = __p + __sz; + for (const _CharT* __ps = __p + __pos; __ps != __pe; ++__ps) + if (_Traits::find(__s, __n, *__ps) == 0) + return static_cast<_SizeT>(__ps - __p); + } + return __npos; + } + + + // __str_find_last_not_of + template + static _SizeT _LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline + __str_find_last_not_of(const _CharT *__p, _SizeT __sz, + const _CharT* __s, _SizeT __pos, _SizeT __n) noexcept + { + if (__pos < __sz) + ++__pos; + else + __pos = __sz; + for (const _CharT* __ps = __p + __pos; __ps != __p;) + if (_Traits::find(__s, __n, *--__ps) == 0) + return static_cast<_SizeT>(__ps - __p); + return __npos; + } + + private: + const value_type* __data; + size_type __size; + }; + + + // [string.view.comparison] + // operator == + template + _LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline + bool operator==(basic_string_view<_CharT, _Traits> __lhs, + basic_string_view<_CharT, _Traits> __rhs) noexcept + { + if ( __lhs.size() != __rhs.size()) return false; + return __lhs.compare(__rhs) == 0; + } + + template + _LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline + bool operator==(basic_string_view<_CharT, _Traits> __lhs, + typename std::common_type >::type __rhs) noexcept + { + if ( __lhs.size() != __rhs.size()) return false; + return __lhs.compare(__rhs) == 0; + } + + template + _LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline + bool operator==(typename std::common_type >::type __lhs, + basic_string_view<_CharT, _Traits> __rhs) noexcept + { + if ( __lhs.size() != __rhs.size()) return false; + return __lhs.compare(__rhs) == 0; + } + + + // operator != + template + _LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline + bool operator!=(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) noexcept + { + if ( __lhs.size() != __rhs.size()) + return true; + return __lhs.compare(__rhs) != 0; + } + + template + _LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline + bool operator!=(basic_string_view<_CharT, _Traits> __lhs, + typename std::common_type >::type __rhs) noexcept + { + if ( __lhs.size() != __rhs.size()) + return true; + return __lhs.compare(__rhs) != 0; + } + + template + _LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline + bool operator!=(typename std::common_type >::type __lhs, + basic_string_view<_CharT, _Traits> __rhs) noexcept + { + if ( __lhs.size() != __rhs.size()) + return true; + return __lhs.compare(__rhs) != 0; + } + + + // operator < + template + _LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline + bool operator<(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) noexcept + { + return __lhs.compare(__rhs) < 0; + } + + template + _LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline + bool operator<(basic_string_view<_CharT, _Traits> __lhs, + typename std::common_type >::type __rhs) noexcept + { + return __lhs.compare(__rhs) < 0; + } + + template + _LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline + bool operator<(typename std::common_type >::type __lhs, + basic_string_view<_CharT, _Traits> __rhs) noexcept + { + return __lhs.compare(__rhs) < 0; + } + + + // operator > + template + _LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline + bool operator> (basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) noexcept + { + return __lhs.compare(__rhs) > 0; + } + + template + _LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline + bool operator>(basic_string_view<_CharT, _Traits> __lhs, + typename std::common_type >::type __rhs) noexcept + { + return __lhs.compare(__rhs) > 0; + } + + template + _LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline + bool operator>(typename std::common_type >::type __lhs, + basic_string_view<_CharT, _Traits> __rhs) noexcept + { + return __lhs.compare(__rhs) > 0; + } + + + // operator <= + template + _LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline + bool operator<=(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) noexcept + { + return __lhs.compare(__rhs) <= 0; + } + + template + _LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline + bool operator<=(basic_string_view<_CharT, _Traits> __lhs, + typename std::common_type >::type __rhs) noexcept + { + return __lhs.compare(__rhs) <= 0; + } + + template + _LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline + bool operator<=(typename std::common_type >::type __lhs, + basic_string_view<_CharT, _Traits> __rhs) noexcept + { + return __lhs.compare(__rhs) <= 0; + } + + + // operator >= + template + _LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline + bool operator>=(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) noexcept + { + return __lhs.compare(__rhs) >= 0; + } + + + template + _LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline + bool operator>=(basic_string_view<_CharT, _Traits> __lhs, + typename std::common_type >::type __rhs) noexcept + { + return __lhs.compare(__rhs) >= 0; + } + + template + _LIBCPP_STRVIEWCLONE_CONSTEXPR_AFTER_CXX11 inline + bool operator>=(typename std::common_type >::type __lhs, + basic_string_view<_CharT, _Traits> __rhs) noexcept + { + return __lhs.compare(__rhs) >= 0; + } + + + // [string.view.io] + template inline + std::basic_ostream<_CharT, _Traits>& + operator<<(std::basic_ostream<_CharT, _Traits>& __os, basic_string_view<_CharT, _Traits> __sv) + { + auto& s = __sv; + copy(s.begin(), s.end(), std::ostream_iterator(__os)); + return __os; + } + + typedef basic_string_view string_view; + typedef basic_string_view u16string_view; + typedef basic_string_view u32string_view; + typedef basic_string_view wstring_view; + +} +namespace std { + +/* +// [string.view.hash] +// Shamelessly stolen from +template +struct hash > + : public unary_function, size_t> +{ + size_t operator()(const std::experimental::basic_string_view<_CharT, _Traits>& __val) const noexcept; +}; + +template +size_t +hash >::operator()( + const std::experimental::basic_string_view<_CharT, _Traits>& __val) const noexcept +{ + return __do_string_hash(__val.data(), __val.data() + __val.size()); +} +*/ + +/* +template +__quoted_output_proxy<_CharT, const _CharT *, _Traits> +quoted ( std::experimental::basic_string_view <_CharT, _Traits> __sv, + _CharT __delim = _CharT('"'), _CharT __escape=_CharT('\\')) +{ + return __quoted_output_proxy<_CharT, const _CharT *, _Traits> + ( __sv.data(), __sv.data() + __sv.size(), __delim, __escape ); +} +*/ + +} + +#endif // _LIBCPP_STRVIEWCLONE_LFTS_STRING_VIEW \ No newline at end of file diff --git a/SilentPatchIII/SilentPatchIII.vcxproj b/SilentPatchIII/SilentPatchIII.vcxproj index 1dbdbe8..95e5240 100644 --- a/SilentPatchIII/SilentPatchIII.vcxproj +++ b/SilentPatchIII/SilentPatchIII.vcxproj @@ -11,6 +11,10 @@ + + NotUsing + NotUsing + @@ -21,6 +25,7 @@ + diff --git a/SilentPatchIII/SilentPatchIII.vcxproj.filters b/SilentPatchIII/SilentPatchIII.vcxproj.filters index 45b7272..9bcde3a 100644 --- a/SilentPatchIII/SilentPatchIII.vcxproj.filters +++ b/SilentPatchIII/SilentPatchIII.vcxproj.filters @@ -24,6 +24,9 @@ Source Files + + Source Files + @@ -38,5 +41,8 @@ Header Files + + Header Files + \ No newline at end of file diff --git a/SilentPatchSA/SilentPatchSA.vcxproj b/SilentPatchSA/SilentPatchSA.vcxproj index bc3ab0b..2c2b3a7 100644 --- a/SilentPatchSA/SilentPatchSA.vcxproj +++ b/SilentPatchSA/SilentPatchSA.vcxproj @@ -114,6 +114,10 @@ copy /y "$(TargetPath)" "D:\gry\GTA San Andreas clean\scripts\newsteam_r2_lowvio + + NotUsing + NotUsing + @@ -155,6 +159,7 @@ copy /y "$(TargetPath)" "D:\gry\GTA San Andreas clean\scripts\newsteam_r2_lowvio + diff --git a/SilentPatchSA/SilentPatchSA.vcxproj.filters b/SilentPatchSA/SilentPatchSA.vcxproj.filters index 3a79c92..e5ab7d3 100644 --- a/SilentPatchSA/SilentPatchSA.vcxproj.filters +++ b/SilentPatchSA/SilentPatchSA.vcxproj.filters @@ -60,6 +60,9 @@ Source Files\decoders + + Source Files + @@ -128,6 +131,9 @@ Source Files\decoders + + Header Files + diff --git a/SilentPatchVC/SilentPatchVC.vcxproj b/SilentPatchVC/SilentPatchVC.vcxproj index f22c8bf..d00d24c 100644 --- a/SilentPatchVC/SilentPatchVC.vcxproj +++ b/SilentPatchVC/SilentPatchVC.vcxproj @@ -103,10 +103,15 @@ + + + NotUsing + NotUsing + diff --git a/SilentPatchVC/SilentPatchVC.vcxproj.filters b/SilentPatchVC/SilentPatchVC.vcxproj.filters index e7b152e..e6b240a 100644 --- a/SilentPatchVC/SilentPatchVC.vcxproj.filters +++ b/SilentPatchVC/SilentPatchVC.vcxproj.filters @@ -27,6 +27,9 @@ Header Files + + Header Files + @@ -38,5 +41,8 @@ Source Files + + Source Files + \ No newline at end of file