From 2af82cb8bebc24047620799245466b53e5556dbc Mon Sep 17 00:00:00 2001 From: PandaTeemo Date: Sat, 3 Aug 2019 23:04:33 -0700 Subject: [PATCH] version 0.11.2 --- build/Core/Core.vcxproj | 2 + build/Core/Core.vcxproj.filters | 6 + build/Installer32/Product.wxs | 2 +- build/Installer64/Product.wxs | 2 +- .../YoloMouse.Loader/YoloMouse.Loader.vcxproj | 22 +- .../YoloMouse.Loader.vcxproj.filters | 48 ++ source/Core/Container/Array.hpp | 109 +++++ source/Core/Container/String.hpp | 33 ++ source/Core/Math/Math.cpp | 24 +- source/Core/Math/Number.cpp | 117 +++++ source/Core/Math/Number.hpp | 34 ++ source/Core/Math/Vector2.cpp | 3 +- source/Core/Math/Vector3.cpp | 4 +- source/Core/Math/Vector3.hpp | 1 + source/Core/Root.hpp | 7 +- source/Core/Support/Settings.cpp | 2 +- source/Core/Support/Settings.hpp | 2 +- source/Core/System/SystemTools.cpp | 13 + source/Core/System/SystemTools.hpp | 2 + source/YoloMouse/Loader/Core/App.cpp | 52 ++- source/YoloMouse/Loader/Core/App.hpp | 3 +- .../YoloMouse/Loader/Inject/InjectSession.cpp | 2 +- .../Overlay/Cursor/Cursors/ArrowCursor.cpp | 19 +- .../Overlay/Cursor/Cursors/ArrowCursor.hpp | 2 +- .../Overlay/Cursor/Cursors/BaseCursor.cpp | 396 ++++------------- .../Overlay/Cursor/Cursors/BaseCursor.hpp | 60 +-- .../Overlay/Cursor/Cursors/BasicCursor.cpp | 44 +- .../Overlay/Cursor/Cursors/BasicCursor.hpp | 2 +- .../Overlay/Cursor/Cursors/CircleCursor.cpp | 56 ++- .../Overlay/Cursor/Cursors/CircleCursor.hpp | 4 +- .../Loader/Overlay/Cursor/IOverlayCursor.hpp | 28 +- .../Overlay/Mouse/MousePositionMonitor.cpp | 44 +- .../Overlay/Mouse/MousePositionMonitor.hpp | 6 +- source/YoloMouse/Loader/Overlay/Overlay.cpp | 169 +++++-- source/YoloMouse/Loader/Overlay/Overlay.hpp | 29 +- .../Loader/Overlay/Rendering/Assets/Mesh.cpp | 104 +++++ .../Loader/Overlay/Rendering/Assets/Mesh.hpp | 40 ++ .../Overlay/Rendering/Assets/Texture.cpp | 102 +++++ .../Overlay/Rendering/Assets/Texture.hpp | 39 ++ .../Overlay/Rendering/RenderContext.cpp | 71 ++- .../Overlay/Rendering/RenderContext.hpp | 8 +- .../Shaders/Default/PixelShader.hlsl | 38 +- .../Rendering/Shaders/Default/PixelShader.hpp | 366 ++++++++------- .../Shaders/Default/VertexShader.hlsl | 2 +- .../Shaders/Default/VertexShader.hpp | 417 +++++++++--------- .../Overlay/Rendering/Shaders/ShaderTypes.hpp | 19 +- .../Support/RenderTimingController.cpp | 71 +-- .../Support/RenderTimingController.hpp | 16 +- .../Overlay/Rendering/Support/RenderTools.cpp | 21 + .../Overlay/Rendering/Support/RenderTools.hpp | 13 + .../Loader/Overlay/Rendering/Types.hpp | 4 +- .../Loader/Overlay/Text/FontAtlas.cpp | 137 ++++++ .../Loader/Overlay/Text/FontAtlas.hpp | 45 ++ .../Loader/Overlay/Text/FontMapBuilder.cpp | 155 +++++++ .../Loader/Overlay/Text/FontMapBuilder.hpp | 41 ++ .../Loader/Overlay/Text/TextMesh.cpp | 183 ++++++++ .../Loader/Overlay/Text/TextMesh.hpp | 42 ++ .../Loader/Overlay/Text/TextPopup.cpp | 256 +++++++++++ .../Loader/Overlay/Text/TextPopup.hpp | 63 +++ source/YoloMouse/Loader/Target/Target.cpp | 67 ++- source/YoloMouse/Loader/Target/Target.hpp | 7 +- .../Loader/Target/TargetController.cpp | 32 +- .../Loader/Target/TargetController.hpp | 4 +- source/YoloMouse/Share/Constants.cpp | 13 +- source/YoloMouse/Share/Constants.hpp | 43 +- source/YoloMouse/Share/Cursor/CursorVault.cpp | 4 +- source/YoloMouse/Share/Enums.hpp | 4 +- 67 files changed, 2711 insertions(+), 1065 deletions(-) create mode 100644 source/Core/Math/Number.cpp create mode 100644 source/Core/Math/Number.hpp create mode 100644 source/YoloMouse/Loader/Overlay/Rendering/Assets/Mesh.cpp create mode 100644 source/YoloMouse/Loader/Overlay/Rendering/Assets/Mesh.hpp create mode 100644 source/YoloMouse/Loader/Overlay/Rendering/Assets/Texture.cpp create mode 100644 source/YoloMouse/Loader/Overlay/Rendering/Assets/Texture.hpp create mode 100644 source/YoloMouse/Loader/Overlay/Rendering/Support/RenderTools.cpp create mode 100644 source/YoloMouse/Loader/Overlay/Rendering/Support/RenderTools.hpp create mode 100644 source/YoloMouse/Loader/Overlay/Text/FontAtlas.cpp create mode 100644 source/YoloMouse/Loader/Overlay/Text/FontAtlas.hpp create mode 100644 source/YoloMouse/Loader/Overlay/Text/FontMapBuilder.cpp create mode 100644 source/YoloMouse/Loader/Overlay/Text/FontMapBuilder.hpp create mode 100644 source/YoloMouse/Loader/Overlay/Text/TextMesh.cpp create mode 100644 source/YoloMouse/Loader/Overlay/Text/TextMesh.hpp create mode 100644 source/YoloMouse/Loader/Overlay/Text/TextPopup.cpp create mode 100644 source/YoloMouse/Loader/Overlay/Text/TextPopup.hpp diff --git a/build/Core/Core.vcxproj b/build/Core/Core.vcxproj index 38337e2..d7b36a4 100644 --- a/build/Core/Core.vcxproj +++ b/build/Core/Core.vcxproj @@ -29,6 +29,7 @@ + @@ -56,6 +57,7 @@ + diff --git a/build/Core/Core.vcxproj.filters b/build/Core/Core.vcxproj.filters index 8a58bf3..e000f60 100644 --- a/build/Core/Core.vcxproj.filters +++ b/build/Core/Core.vcxproj.filters @@ -120,6 +120,9 @@ Events + + Math + @@ -174,5 +177,8 @@ UI + + Math + \ No newline at end of file diff --git a/build/Installer32/Product.wxs b/build/Installer32/Product.wxs index dac52ee..5f0a53b 100644 --- a/build/Installer32/Product.wxs +++ b/build/Installer32/Product.wxs @@ -1,6 +1,6 @@ - + diff --git a/build/Installer64/Product.wxs b/build/Installer64/Product.wxs index 03e40b5..d7accfd 100644 --- a/build/Installer64/Product.wxs +++ b/build/Installer64/Product.wxs @@ -1,6 +1,6 @@ - + diff --git a/build/YoloMouse.Loader/YoloMouse.Loader.vcxproj b/build/YoloMouse.Loader/YoloMouse.Loader.vcxproj index d7d5621..6ab2dd4 100644 --- a/build/YoloMouse.Loader/YoloMouse.Loader.vcxproj +++ b/build/YoloMouse.Loader/YoloMouse.Loader.vcxproj @@ -112,7 +112,7 @@ Windows true - d3d11.lib;dxgi.lib;dwmapi.lib;%(AdditionalDependencies) + Gdiplus.lib;d3d11.lib;dxgi.lib;dwmapi.lib;%(AdditionalDependencies) @@ -130,7 +130,7 @@ Windows true - d3d11.lib;dxgi.lib;dwmapi.lib;%(AdditionalDependencies) + Gdiplus.lib;d3d11.lib;dxgi.lib;dwmapi.lib;%(AdditionalDependencies) @@ -152,7 +152,7 @@ true true true - d3d11.lib;dxgi.lib;dwmapi.lib;%(AdditionalDependencies) + Gdiplus.lib;d3d11.lib;dxgi.lib;dwmapi.lib;%(AdditionalDependencies) @@ -174,7 +174,7 @@ true true true - d3d11.lib;dxgi.lib;dwmapi.lib;%(AdditionalDependencies) + Gdiplus.lib;d3d11.lib;dxgi.lib;dwmapi.lib;%(AdditionalDependencies) @@ -190,8 +190,15 @@ + + + + + + + @@ -211,12 +218,19 @@ + + + + + + + diff --git a/build/YoloMouse.Loader/YoloMouse.Loader.vcxproj.filters b/build/YoloMouse.Loader/YoloMouse.Loader.vcxproj.filters index 5ea8f98..d575cb0 100644 --- a/build/YoloMouse.Loader/YoloMouse.Loader.vcxproj.filters +++ b/build/YoloMouse.Loader/YoloMouse.Loader.vcxproj.filters @@ -46,6 +46,12 @@ {4938d3f7-9383-41fa-945a-a8fae4fcdbf1} + + {e937feb4-036c-4353-8d79-8d5d13542376} + + + {f2c36add-91f4-4ff5-a514-661cbc09eb51} + @@ -97,6 +103,27 @@ Overlay\Mouse + + Overlay\Text + + + Overlay\Rendering\Support + + + Overlay\Text + + + Overlay\Text + + + Overlay\Text + + + Overlay\Rendering\Assets + + + Overlay\Rendering\Assets + @@ -171,6 +198,27 @@ Overlay\Mouse + + Overlay\Text + + + Overlay\Rendering\Support + + + Overlay\Text + + + Overlay\Text + + + Overlay\Text + + + Overlay\Rendering\Assets + + + Overlay\Rendering\Assets + diff --git a/source/Core/Container/Array.hpp b/source/Core/Container/Array.hpp index fbf2d53..9f53a26 100644 --- a/source/Core/Container/Array.hpp +++ b/source/Core/Container/Array.hpp @@ -424,6 +424,115 @@ namespace Core } }; + /* + memory: allocated + count: variable + limit: =count + */ + template + class SimpleArray: + public Array + { + public: + /**/ + SimpleArray() = default; + + SimpleArray( ULong count ) + { + _Construct(count); + } + + SimpleArray( const std::initializer_list& ilist ) + { + _Copy(ilist.begin(), static_cast(ilist.size())); + } + + SimpleArray( const SimpleArray& other ) + { + _Copy(other.GetMemory(), other.GetCount()); + } + + template + SimpleArray( const ARRAY& other ) + { + _Copy(other.GetMemory(), other.GetCount()); + } + + ~SimpleArray() + { + if( _memory != nullptr ) + _Destruct(); + } + + /**/ + void operator=( const SimpleArray& other ) + { + Copy( other ); + } + template + void operator=( const ARRAY& other ) + { + Copy( other ); + } + + /**/ + void Empty() + { + // if not already empty + if( _memory != nullptr ) + { + _Destruct(); + _count = 0; + _memory = nullptr; + } + } + + /**/ + void SetCount( ULong count ) + { + if( _memory != nullptr ) + _Destruct(); + _Construct(count); + } + + /**/ + void Copy( const TYPE* data, ULong count ) + { + if( _memory != nullptr ) + _Destruct(); + _Copy( data, count ); + } + template + void Copy( const ARRAY& other ) + { + Copy(other.GetMemory(), other.GetCount()); + } + + protected: + /**/ + inline void _Construct( ULong count ) + { + // allocate and construct data + _memory = new TYPE[count]; + + // set count + _count = count; + } + + inline void _Destruct() + { + // destruct and free data + delete[] _memory; + } + + /**/ + void _Copy( const TYPE* data, ULong count ) + { + _Construct(count); + BaseArray::Copy(data, count); + } + }; + /**/ typedef Array ByteArray; typedef BufferArray ByteBufferArray; diff --git a/source/Core/Container/String.hpp b/source/Core/Container/String.hpp index aee4f90..da3a858 100644 --- a/source/Core/Container/String.hpp +++ b/source/Core/Container/String.hpp @@ -147,6 +147,39 @@ namespace Core } }; + /**/ + class SimpleString: + public BaseString> + { + public: + /**/ + SimpleString() = default; + SimpleString( const Char* cstring ); + template + SimpleString( const STRING& other ) + { + _Construct(other.GetCount()); + Copy(other); + } + + /**/ + operator String() const + { + return String(_memory, _count); + } + + /**/ + void operator=( const SimpleArray& other ) + { + SimpleArray::Copy( other ); + } + template + void operator=( const STRING& other ) + { + SimpleArray::Copy( other ); + } + }; + /**/ typedef FixedString> ShortString; typedef FixedString> MediumString; diff --git a/source/Core/Math/Math.cpp b/source/Core/Math/Math.cpp index 8835b9b..21203a2 100644 --- a/source/Core/Math/Math.cpp +++ b/source/Core/Math/Math.cpp @@ -7,13 +7,16 @@ namespace Core //------------------------------------------------------------------------- template class Math; template class Math; + template class Math; // statics //------------------------------------------------------------------------- template<> const Float Math::PI = 3.14159274f; template<> const Long Math::PI = 3; + template<> const ULong Math::PI = 3; template<> const Float Math::PI2 = 6.28318530f; template<> const Long Math::PI2 = 6; + template<> const ULong Math::PI2 = 6; //------------------------------------------------------------------------- template<> @@ -26,12 +29,27 @@ namespace Core { return 0; } + template<> + ULong Math::SquareRoot( ULong value ) + { + return 0; + } //------------------------------------------------------------------------- - template - TYPE Math::Absolute( TYPE value ) + template<> + Float Math::Absolute( Float value ) + { + return static_cast(std::fabs( value )); + } + template<> + Long Math::Absolute( Long value ) + { + return static_cast(std::abs( value )); + } + template<> + ULong Math::Absolute( ULong value ) { - return static_cast(std::abs( value )); + return value; } //------------------------------------------------------------------------- diff --git a/source/Core/Math/Number.cpp b/source/Core/Math/Number.cpp new file mode 100644 index 0000000..05bc4fb --- /dev/null +++ b/source/Core/Math/Number.cpp @@ -0,0 +1,117 @@ +#include +#include + +namespace Core +{ + // explicit instantiations + //------------------------------------------------------------------------- + template class Number; + template class Number; + template class Number; + template class Number; + template class Number; + template class Number; + + // local + //------------------------------------------------------------------------- + namespace + { + /**/ + template + Index _GetLowBit( TYPE value ) + { + ASSERT( value != 0 ); + Index index = 0; + + while( true ) + { + if( value & 1 ) + return index; + ++index; + value >>= 1; + } + } + + template + Index _GetHighBit( TYPE value ) + { + ASSERT( value != 0 ); + Index index = (sizeof(TYPE) * 8) - 1; + + while( value >>= 1 ) + --index; + + return index; + } + } + + // public + //------------------------------------------------------------------------- + template + Number::Number( TYPE value ): + _value(value) + {} + + //------------------------------------------------------------------------- + template + Number::operator TYPE() const + { + return _value; + } + template + Number Number::operator=( TYPE value ) + { + _value = value; + return *this; + } + + template<> + Number Number::operator - () const + { + return 0; + } + template<> + Number Number::operator - () const + { + return 0; + } + template + Number Number::operator - () const + { + return -_value; + } + + //------------------------------------------------------------------------- + template + Bool Number::IsNaN() const + { + return _value != _value; + } + + //------------------------------------------------------------------------- + template<> + Number Number::GetRandom( Float min, Float max ) + { + return static_cast(::rand()) * (max - min) / static_cast(RAND_MAX) + min; + } + template<> + Number Number::GetRandom( Double min, Double max ) + { + ASSERT_TODO; + return 0; + } + template + Number Number::GetRandom( TYPE min, TYPE max ) + { + ASSERT( max >= min ); + //TODO3: improve + return min + static_cast(((TYPE)::rand() * (TYPE)::rand()) % static_cast(max - min + 1)); + } + + //------------------------------------------------------------------------- + template + void Number::SetRandomSeed( TYPE value ) + { + return ::srand( static_cast(value) ); + } +} diff --git a/source/Core/Math/Number.hpp b/source/Core/Math/Number.hpp new file mode 100644 index 0000000..77516b2 --- /dev/null +++ b/source/Core/Math/Number.hpp @@ -0,0 +1,34 @@ +#pragma once +#include + +namespace Core +{ + /**/ + template + class Number + { + public: + /**/ + Number() = default; + Number( TYPE value ); + + /**/ + operator TYPE () const; + Number operator = ( TYPE value ); + Number operator - () const; + + /**/ + Bool IsNaN() const; + + /**/ + static Number GetRandom( TYPE min, TYPE max ); + + /**/ + static void SetRandomSeed( TYPE value ); + /**/ + + private: + // fields + TYPE _value; + }; +} diff --git a/source/Core/Math/Vector2.cpp b/source/Core/Math/Vector2.cpp index e878171..4320a68 100644 --- a/source/Core/Math/Vector2.cpp +++ b/source/Core/Math/Vector2.cpp @@ -1,4 +1,5 @@ #include +#include namespace Core { @@ -133,7 +134,7 @@ namespace Core template BaseVector2 BaseVector2::operator - () const { - return BaseVector2(-x, -y); + return BaseVector2(-Number(x), -Number(y)); } //------------------------------------------------------------------------- diff --git a/source/Core/Math/Vector3.cpp b/source/Core/Math/Vector3.cpp index d26ca81..885e652 100644 --- a/source/Core/Math/Vector3.cpp +++ b/source/Core/Math/Vector3.cpp @@ -1,11 +1,13 @@ #include #include +#include namespace Core { // explicit instantiations //------------------------------------------------------------------------- template class BaseVector3; + template class BaseVector3; // statics //------------------------------------------------------------------------- @@ -140,7 +142,7 @@ namespace Core template BaseVector3 BaseVector3::operator - () const { - return BaseVector3(-x, -y, -z); + return BaseVector3(-Number(x), -Number(y), -Number(z)); } //------------------------------------------------------------------------- diff --git a/source/Core/Math/Vector3.hpp b/source/Core/Math/Vector3.hpp index 3333ccc..d31d144 100644 --- a/source/Core/Math/Vector3.hpp +++ b/source/Core/Math/Vector3.hpp @@ -56,4 +56,5 @@ namespace Core // common typedefs //------------------------------------------------------------------------- typedef BaseVector3 Vector3f; + typedef BaseVector3 Vector3u; } diff --git a/source/Core/Root.hpp b/source/Core/Root.hpp index af4a853..e15b772 100644 --- a/source/Core/Root.hpp +++ b/source/Core/Root.hpp @@ -59,6 +59,7 @@ namespace Core typedef bool Bool; typedef char Char; + typedef wchar_t WChar; typedef unsigned char Byte; typedef short Short; typedef unsigned short UShort; @@ -88,12 +89,6 @@ namespace Core typedef ULong UNative; #endif - #ifdef PRECISION_DOUBLE - typedef Double Real; - #else - typedef Float Real; - #endif - #if 0 /**/ #ifdef NDEBUG diff --git a/source/Core/Support/Settings.cpp b/source/Core/Support/Settings.cpp index 831ebaf..4ac51da 100644 --- a/source/Core/Support/Settings.cpp +++ b/source/Core/Support/Settings.cpp @@ -92,7 +92,7 @@ namespace Core } //------------------------------------------------------------------------- - void Settings::Set( Id id, String value ) + void Settings::Set( Id id, const String& value ) { return _keyvalues[id].value.CopyZ(value); } diff --git a/source/Core/Support/Settings.hpp b/source/Core/Support/Settings.hpp index 6838a73..ad173a2 100644 --- a/source/Core/Support/Settings.hpp +++ b/source/Core/Support/Settings.hpp @@ -36,7 +36,7 @@ namespace Core const KeyValueCollection& GetCollection() const; /**/ - void Set( Id id, String value ); + void Set( Id id, const String& value ); void SetBoolean( Id id, Bool boolean ); void SetNumber( Id id, Long number ); diff --git a/source/Core/System/SystemTools.cpp b/source/Core/System/SystemTools.cpp index 35259fa..cd97cb9 100644 --- a/source/Core/System/SystemTools.cpp +++ b/source/Core/System/SystemTools.cpp @@ -49,6 +49,11 @@ namespace Core return true; } + ULong SystemTools::GetTimeMs() + { + return GetTickCount(); + } + UHuge SystemTools::GetTickTime() { UHuge counter = 0; @@ -62,6 +67,14 @@ namespace Core QueryPerformanceFrequency((LARGE_INTEGER*)&frequency); return frequency; } + + Float SystemTools::GetTicksToSeconds( UHuge ticks ) + { + static UHuge frequency = SystemTools::GetTickFrequency(); + + // calculate frame time + return static_cast((ticks * 1000000) / frequency) / 1000000.0f; + } //------------------------------------------------------------------------- Bool SystemTools::AccessUserPath( PathString& path, const WCHAR* app_name ) diff --git a/source/Core/System/SystemTools.hpp b/source/Core/System/SystemTools.hpp index ff39370..ced04e1 100644 --- a/source/Core/System/SystemTools.hpp +++ b/source/Core/System/SystemTools.hpp @@ -11,8 +11,10 @@ namespace Core /**/ static Bitness GetProcessBitness( HANDLE process ); static Bool GetProcessDirectory( PathString& path ); + static ULong GetTimeMs(); static UHuge GetTickTime(); static UHuge GetTickFrequency(); + static Float GetTicksToSeconds( UHuge ticks ); /**/ static Bool AccessUserPath( PathString& path, const WCHAR* app_name ); diff --git a/source/YoloMouse/Loader/Core/App.cpp b/source/YoloMouse/Loader/Core/App.cpp index f005e8e..b42773f 100644 --- a/source/YoloMouse/Loader/Core/App.cpp +++ b/source/YoloMouse/Loader/Core/App.cpp @@ -137,6 +137,11 @@ namespace Yolomouse return _initialized; } + Bool App::IsElevated() const + { + return IsUserAnAdmin() == TRUE; + } + //------------------------------------------------------------------------- Bool App::GetElevate() const { @@ -165,7 +170,7 @@ namespace Yolomouse Target* target; // access current target - if( TargetController::Instance().AccessTarget( target ) ) + if( TargetController::Instance().AccessTarget( target, IsElevated() ) ) { // handle by combo id switch (combo_id) @@ -226,6 +231,13 @@ namespace Yolomouse _ui.SetMenuOption(MENU_OPTION_AUTOSTART, !enabled); return true; + // reduce overlay lag + case MENU_OPTION_REDUCEOVERLAYLAG: + // toggle reduce overlay lag + _OptionReduceOverlayLag( !enabled, true ); + _ui.SetMenuOption(MENU_OPTION_REDUCEOVERLAYLAG, !enabled); + return true; + // run as administrator case MENU_OPTION_RUNASADMIN: _OptionRunAsAdmin(); @@ -295,12 +307,14 @@ namespace Yolomouse _ui.AddMenuBreak(); // add show settings _ui.AddMenuOption(MENU_OPTION_SETTINGSFOLDER, APP_MENU_STRINGS[MENU_OPTION_SETTINGSFOLDER], false); - // add run-as-administrator option if not already admin - if( !IsUserAnAdmin() ) + // add run-as-administrator option if not already elevated/admin + if( !IsElevated() ) _ui.AddMenuOption(MENU_OPTION_RUNASADMIN, APP_MENU_STRINGS[MENU_OPTION_RUNASADMIN], false); // add menu break _ui.AddMenuBreak(); + // add reduce overlay lag option + _ui.AddMenuOption(MENU_OPTION_REDUCEOVERLAYLAG, APP_MENU_STRINGS[MENU_OPTION_REDUCEOVERLAYLAG], _settings.GetBoolean(SETTING_REDUCEOVERLAYLAG)); // add autostart option _ui.AddMenuOption(MENU_OPTION_AUTOSTART, APP_MENU_STRINGS[MENU_OPTION_AUTOSTART], _settings.GetBoolean(SETTING_AUTOSTART)); @@ -345,8 +359,8 @@ namespace Yolomouse if( _settings.GetBoolean(SETTING_AUTOSTART) ) _OptionAutoStart(true, false); - // update "games only" option - _OptionGamesOnly(_settings.GetBoolean(SETTING_GAMESONLY), false); + // update "reduce overlay lag" option + _OptionReduceOverlayLag(_settings.GetBoolean(SETTING_REDUCEOVERLAYLAG), false); return true; } @@ -484,20 +498,6 @@ namespace Yolomouse WindowTools::MessagePopup(APP_NAMEC, false, TEXT_NOLOG); } - void App::_OptionGamesOnly( Bool enable, Bool save ) - { - // update games only state - TargetController::Instance().SetGamesOnly(enable); - - // update settings - if( save ) - { - _settings.SetBoolean(SETTING_GAMESONLY, enable); - if( !_settings.Save() ) - LOG("App.OptionGamesOnly.Save"); - } - } - Bool App::_OptionAutoStart( Bool enable, Bool save ) { PathString path; @@ -528,6 +528,20 @@ namespace Yolomouse return false; } + void App::_OptionReduceOverlayLag( Bool enable, Bool save ) + { + // update games only state + Overlay::Instance().SetReduceLatency(enable); + + // update settings + if( save ) + { + _settings.SetBoolean(SETTING_REDUCEOVERLAYLAG, enable); + if( !_settings.Save() ) + LOG("App.ReduceOverlayLag.Save"); + } + } + Bool App::_OptionRunAsAdmin() { // exit current process diff --git a/source/YoloMouse/Loader/Core/App.hpp b/source/YoloMouse/Loader/Core/App.hpp index 7bc0384..9d19466 100644 --- a/source/YoloMouse/Loader/Core/App.hpp +++ b/source/YoloMouse/Loader/Core/App.hpp @@ -24,6 +24,7 @@ namespace Yolomouse /**/ Bool IsInitialized() const; + Bool IsElevated() const; /**/ Bool GetElevate() const; @@ -56,8 +57,8 @@ namespace Yolomouse /**/ void _OptionAbout(); void _OptionErrors(); - void _OptionGamesOnly( Bool enable, Bool save ); Bool _OptionAutoStart( Bool enable, Bool save ); + void _OptionReduceOverlayLag( Bool enable, Bool save ); Bool _OptionRunAsAdmin(); void _OptionSettingsFolder(); diff --git a/source/YoloMouse/Loader/Inject/InjectSession.cpp b/source/YoloMouse/Loader/Inject/InjectSession.cpp index e0fb654..255a65f 100644 --- a/source/YoloMouse/Loader/Inject/InjectSession.cpp +++ b/source/YoloMouse/Loader/Inject/InjectSession.cpp @@ -72,7 +72,7 @@ namespace Yolomouse ASSERT( IsInitialized() ); // open process with necessary privileges required by the tools that will use it - HANDLE process = OpenProcess(PROCESS_VM_OPERATION|PROCESS_CREATE_THREAD|PROCESS_VM_WRITE, FALSE, _process_id); + HANDLE process = OpenProcess(PROCESS_VM_OPERATION|PROCESS_CREATE_THREAD|PROCESS_VM_WRITE|PROCESS_QUERY_INFORMATION, FALSE, _process_id); if( process != NULL ) { // choose inject dll diff --git a/source/YoloMouse/Loader/Overlay/Cursor/Cursors/ArrowCursor.cpp b/source/YoloMouse/Loader/Overlay/Cursor/Cursors/ArrowCursor.cpp index 4138da9..cb54b59 100644 --- a/source/YoloMouse/Loader/Overlay/Cursor/Cursors/ArrowCursor.cpp +++ b/source/YoloMouse/Loader/Overlay/Cursor/Cursors/ArrowCursor.cpp @@ -10,7 +10,7 @@ namespace Yolomouse { // constants //--------------------------------------------------------------------- - const Float ROTATION_SPEED = 0.13f; // rotations/sec + const Float ROTATION_SPEED = 0.2f; // rotations/sec const Vector3f LIGHT_VECTOR = Vector3f(0,-1,0).Normal(); // vertices @@ -62,12 +62,8 @@ namespace Yolomouse // calculate face normals _CalculateFaceNormals( VERTICES, INDICES ); - // initialize blending - if( !_InitializeBlending({D3D11_BLEND_SRC_ALPHA, D3D11_BLEND_INV_SRC_ALPHA}) ) - return false; - - // initialize geometry - if( !_InitializeGeometry({VERTICES, INDICES}) ) + // initialize mesh + if( !BaseCursor::_mesh.Initialize({*_render_context,INDICES,VERTICES}) ) return false; return true; @@ -77,14 +73,11 @@ namespace Yolomouse { ASSERT( IsInitialized() ); - // shutdown geometry - _ShutdownGeometry(); - - // shutdown blending - _ShutdownBlending(); + // shutdown mesh + _mesh.Shutdown(); } - void ArrowCursor::_OnUpdate( UpdateDef2& def ) + void ArrowCursor::_OnUpdate( UpdateDef& def ) { // update light vector def.light_vector = LIGHT_VECTOR; diff --git a/source/YoloMouse/Loader/Overlay/Cursor/Cursors/ArrowCursor.hpp b/source/YoloMouse/Loader/Overlay/Cursor/Cursors/ArrowCursor.hpp index d4c6099..32fddb3 100644 --- a/source/YoloMouse/Loader/Overlay/Cursor/Cursors/ArrowCursor.hpp +++ b/source/YoloMouse/Loader/Overlay/Cursor/Cursors/ArrowCursor.hpp @@ -20,7 +20,7 @@ namespace Yolomouse void _OnShutdown(); /**/ - void _OnUpdate( UpdateDef2& def ); + void _OnUpdate( UpdateDef& def ); private: // fields: state diff --git a/source/YoloMouse/Loader/Overlay/Cursor/Cursors/BaseCursor.cpp b/source/YoloMouse/Loader/Overlay/Cursor/Cursors/BaseCursor.cpp index a61df1b..da838d4 100644 --- a/source/YoloMouse/Loader/Overlay/Cursor/Cursors/BaseCursor.cpp +++ b/source/YoloMouse/Loader/Overlay/Cursor/Cursors/BaseCursor.cpp @@ -1,6 +1,7 @@ #include #include #include +#include namespace Yolomouse { @@ -20,61 +21,21 @@ namespace Yolomouse {1, 0, 0, 1}, {0, 0.36f, 1, 1}, {0.63f, 0, 1, 1}, - {0.78f, 0.78f, 0.78f, 1}, + {0.5f, 0.5f, 0.5f, 1}, {1, 1, 1, 1}, }; } // public //------------------------------------------------------------------------- - Bool BaseCursor::IsInitialized() const - { - return _render_context != nullptr; - } - - Bool BaseCursor::IsTextureInitialized() const - { - return _texture_view != nullptr; - } - - Bool BaseCursor::IsGeometryInitialized() const - { - return _shape_vertex_buffer != nullptr; - } - - //------------------------------------------------------------------------- - CursorId BaseCursor::GetId() const - { - return _id; - } - - CursorVariation BaseCursor::GetVariation() const - { - return _variation; - } - - CursorSize BaseCursor::GetSize() const - { - return _size; - } - - // protected - //------------------------------------------------------------------------- BaseCursor::BaseCursor(): - _render_context (nullptr), - _aspect_ratio (0), - _id (0), - _variation (0), - _size (CURSOR_SIZE_DEFAULT), - _cursor_scale (static_cast(CURSOR_SIZE_DEFAULT) * SIZEID_TO_SCALE), - _auto_scale (true), - _projection_matrix (Matrix4f::IDENTITY()), - _blend_state (nullptr), - _shape_index_count (0), - _shape_index_buffer (nullptr), - _shape_vertex_buffer (nullptr), - _texture (nullptr), - _texture_view (nullptr) + _render_context (nullptr), + _id (0), + _variation (0), + _size (CURSOR_SIZE_DEFAULT), + _cursor_scale (static_cast(CURSOR_SIZE_DEFAULT) * SIZEID_TO_SCALE), + _auto_scale (true), + _projection_matrix (Matrix4f::IDENTITY()) { } @@ -84,153 +45,51 @@ namespace Yolomouse } //------------------------------------------------------------------------- - Bool BaseCursor::_InitializeBlending( const BlendingDef& def ) + Bool BaseCursor::Initialize( RenderContext& render_context ) { - D3D11_BLEND_DESC blend_desc = {}; - HRESULT hresult; + ASSERT( !IsInitialized() ); - // describe blend state - blend_desc.RenderTarget[0].BlendEnable = TRUE; - blend_desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL; - blend_desc.RenderTarget[0].SrcBlend = def.src; - blend_desc.RenderTarget[0].DestBlend = def.dest; - blend_desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE; - blend_desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO; - blend_desc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD; - blend_desc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_ADD; + // set fields + _render_context = &render_context; - // create blend state - if( (hresult = _render_context->GetDevice().CreateBlendState(&blend_desc, &_blend_state)) != S_OK ) - { - LOG( "BaseCursor.InitializeBlending.CreateBlendState" ); + // notify initialize subclass + if( !_OnInitialize() ) return false; - } - - // set blend state - _render_context->GetDeviceContext().OMSetBlendState(_blend_state, NULL, 0xffffffff); return true; } - Bool BaseCursor::_InitializeGeometry( const GeometryDef& def ) + void BaseCursor::Shutdown() { - D3D11_BUFFER_DESC index_buffer_desc = {}; - D3D11_BUFFER_DESC vertex_buffer_desc = {}; - D3D11_SUBRESOURCE_DATA subresource_data = {}; - HRESULT hresult; - ID3D11Device& device = _render_context->GetDevice(); + ASSERT( IsInitialized() ); - // save index count - _shape_index_count = def.indices.GetCount() * 3; + // notify shutdown subclass + _OnShutdown(); - // describe index buffer - index_buffer_desc.Usage = D3D11_USAGE_DEFAULT; - index_buffer_desc.ByteWidth = sizeof(Index) * _shape_index_count; - index_buffer_desc.BindFlags = D3D11_BIND_INDEX_BUFFER; - - // create index buffer - subresource_data.pSysMem = def.indices.GetMemory(); - if( (hresult = device.CreateBuffer(&index_buffer_desc, &subresource_data, &_shape_index_buffer)) != S_OK ) - return false; - - // describe vertex buffer - vertex_buffer_desc.Usage = D3D11_USAGE_DEFAULT; - vertex_buffer_desc.ByteWidth = sizeof(ShaderVertex) * def.vertices.GetCount(); - vertex_buffer_desc.BindFlags = D3D11_BIND_VERTEX_BUFFER; - vertex_buffer_desc.CPUAccessFlags = 0; - vertex_buffer_desc.MiscFlags = 0; - - // create vertex buffer - subresource_data.pSysMem = def.vertices.GetMemory(); - if( (hresult = device.CreateBuffer(&vertex_buffer_desc, &subresource_data, &_shape_vertex_buffer)) != S_OK ) - return false; - - return true; + // reset fields + _render_context = nullptr; } - Bool BaseCursor::_InitializeTexture( const TextureDef& def ) + //------------------------------------------------------------------------- + Bool BaseCursor::IsInitialized() const { - D3D11_TEXTURE2D_DESC texture2d_desc = {}; - D3D11_SHADER_RESOURCE_VIEW_DESC shader_resource_view_desc = {}; - HRESULT hresult; - D3D11_SUBRESOURCE_DATA subresource_data = {}; - ID3D11Device& device = _render_context->GetDevice(); - - // describe subresource data - subresource_data.pSysMem = def.pixels; - subresource_data.SysMemPitch = sizeof(Byte4) * def.size.x; - - // describe texture - texture2d_desc.Width = def.size.x; - texture2d_desc.Height = def.size.y; - texture2d_desc.MipLevels = texture2d_desc.ArraySize = 1; - texture2d_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; - texture2d_desc.SampleDesc.Count = 1; - texture2d_desc.Usage = D3D11_USAGE_DYNAMIC;//D3D11_USAGE_IMMUTABLE - texture2d_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE; - texture2d_desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; - texture2d_desc.MiscFlags = 0; - - // create texture - if( (hresult = device.CreateTexture2D( &texture2d_desc, &subresource_data, &_texture )) != S_OK ) - return false; - - // describe shader resource view - shader_resource_view_desc.Format = texture2d_desc.Format; - shader_resource_view_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D; - shader_resource_view_desc.Texture2D.MostDetailedMip = 0; - shader_resource_view_desc.Texture2D.MipLevels = -1; - - // create texture view - if( (hresult = device.CreateShaderResourceView(_texture, &shader_resource_view_desc, &_texture_view)) != S_OK ) - return false; - - return true; + return _render_context != nullptr; } //------------------------------------------------------------------------- - void BaseCursor::_ShutdownBlending() + CursorId BaseCursor::GetId() const { - // shutdown blend state - if( _blend_state ) - { - _blend_state->Release(); - _blend_state = nullptr; - } + return _id; } - void BaseCursor::_ShutdownGeometry() + CursorVariation BaseCursor::GetVariation() const { - // shutdown shape vertex buffer - if( _shape_vertex_buffer ) - { - _shape_vertex_buffer->Release(); - _shape_vertex_buffer = nullptr; - } - - // shutdown shape index buffer - if( _shape_index_buffer ) - { - _shape_index_buffer->Release(); - _shape_index_buffer = nullptr; - } + return _variation; } - void BaseCursor::_ShutdownTexture() + CursorSize BaseCursor::GetSize() const { - // shutdown texture view - if( _texture_view ) - { - _texture_view->Release(); - _texture_view = nullptr; - } - - // shutdown texture - if( _texture ) - { - _texture->Release(); - _texture = nullptr; - } + return _size; } //------------------------------------------------------------------------- @@ -250,161 +109,96 @@ namespace Yolomouse return true; } - - void BaseCursor::_SetAutoScale( Bool enable ) - { - _auto_scale = enable; - } - - //------------------------------------------------------------------------- - void BaseCursor::_CalculateFaceNormals( Array& vertices, const Array& indices ) - { - // for each index - for( Index i = 0; i < indices.GetCount(); ++i ) - { - const Index3& index = indices[i]; - Index i0 = index.a; - Index i1 = index.b; - Index i2 = index.c; - Vector3f v10 = vertices[i1].position - vertices[i0].position; - Vector3f v20 = vertices[i2].position - vertices[i0].position; - Vector3f normal = v10.CrossProduct( v20 ).Normal(); - vertices[i0].normal = normal; - vertices[i1].normal = normal; - vertices[i2].normal = normal; - } - } - - // impl:IOverlayCursor - //------------------------------------------------------------------------- - Bool BaseCursor::Initialize( const InitializeDef& def ) - { - ASSERT( !IsInitialized() ); - - // set fields - _render_context = &def.render_context; - _aspect_ratio = def.aspect_ratio; - - // initialize camera - _InitializeCamera(); - - // notify initialize subclass - if( !_OnInitialize() ) - return false; - - return true; - } - void BaseCursor::Shutdown() + void BaseCursor::SetAspectRatio( Float aspect_ratio ) { - ASSERT( IsInitialized() ); - - // notify shutdown subclass - _OnShutdown(); - - // reset fields - _render_context = nullptr; + // update projection matrix + RenderTools::BuildOrthoProjectionMatrix( _projection_matrix, aspect_ratio ); } - + //------------------------------------------------------------------------- - void BaseCursor::Update( const UpdateDef& def ) + void BaseCursor::Draw( const Vector2f& position ) { - Transform3f transform = Transform3f::IDENTITY(); - Matrix4f mscale = Matrix4f::IDENTITY(); - Matrix4f mtransform = Matrix4f::IDENTITY(); + // if mesh initialized + if( _mesh.IsInitialized() ) + { + Transform3f transform = Transform3f::IDENTITY(); + Matrix4f mscale = Matrix4f::IDENTITY(); + Matrix4f mtransform = Matrix4f::IDENTITY(); + VertexShaderConstantValue vs_constant_value; + PixelShaderConstantValue ps_constant_value; + ID3D11DeviceContext& device_context = _render_context->GetDeviceContext(); - // notify update - UpdateDef2 sup_def = { - _render_context->GetRenderTimingController().GetFrameTime(), - _ps_constant_value.light_vector, - transform.orientation - }; - _OnUpdate( sup_def ); - - // calculate model matrix at origin and without scale - transform.ToMatrix4(_vs_constant_value.model); + // notify base for updates + UpdateDef sup_def = { + _render_context->GetRenderTimingController().GetFrameTime(), + ps_constant_value.light_vector, + transform.orientation + }; + _OnUpdate( sup_def ); - // create transform - transform.translation.x = def.cursor_position.x; - transform.translation.y = def.cursor_position.y; - transform.ToMatrix4(mtransform); + // calculate model matrix at origin and without scale + transform.ToMatrix4(vs_constant_value.model); - // create scale matrix - if( _auto_scale ) - mscale.Scale( _cursor_scale, _cursor_scale, _cursor_scale ); + // create transform + transform.translation.x = position.x; + transform.translation.y = position.y; + transform.ToMatrix4(mtransform); - // create mvp and transpose cuz directx sucks, vulkan rules! xD - _vs_constant_value.mvp = (_projection_matrix * mtransform * mscale).Transpose(); + // create scale matrix + if( _auto_scale ) + mscale.Scale( _cursor_scale, _cursor_scale, _cursor_scale ); - // update variation color based on variation - _vs_constant_value.variation_color = VARIATION_TABLE[_variation]; + // create mvp and transpose cuz directx sucks, vulkan rules! xD + vs_constant_value.mvp = (_projection_matrix * mtransform * mscale).Transpose(); - // update texturing state - _ps_constant_value.texturing = IsTextureInitialized(); - - // commit constant values - _render_context->CommitShaderContants(_vs_constant_value, _ps_constant_value); - } - - //------------------------------------------------------------------------- - void BaseCursor::Draw() const - { - // if geometry initialized - if( IsGeometryInitialized() ) - { - ID3D11DeviceContext& device_context = _render_context->GetDeviceContext(); + // update variation color based on variation + vs_constant_value.variation_color = VARIATION_TABLE[_variation]; // if texture initialized - if( IsTextureInitialized() ) + if( _texture.IsInitialized() ) { - // bind texture to pixel shader - device_context.PSSetShaderResources(0, 1, &_texture_view); - } + // draw texture + _texture.Draw(); - // set index buffer - device_context.IASetIndexBuffer(_shape_index_buffer, DXGI_FORMAT_R32_UINT, 0); + // set texture type + ps_constant_value.type = PIXELSHADERTYPE_UNLIT_TEXTURE; + } + // else set basic type + else + ps_constant_value.type = PIXELSHADERTYPE_LIT_BASIC; - // set vertex buffer - UINT stride = sizeof(ShaderVertex); - UINT offset = 0; - device_context.IASetVertexBuffers(0, 1, &_shape_vertex_buffer, &stride, &offset); + // commit constant values + _render_context->CommitShaderContants(vs_constant_value, ps_constant_value); - // draw shape - device_context.DrawIndexed(_shape_index_count, 0, 0); + // draw mesh + _mesh.Draw(); } } + // protected //------------------------------------------------------------------------- - void BaseCursor::OnResize( const ResizeDef& def ) - { - // update fields - _aspect_ratio = def.aspect_ratio; - - // reinitialize camera - _InitializeCamera(); - } - - // private - //------------------------------------------------------------------------- - void BaseCursor::_InitializeCamera() + void BaseCursor::_SetAutoScale( Bool enable ) { - // calculoate projection matrix - _CalculateOrthoProjection(); + _auto_scale = enable; } //------------------------------------------------------------------------- - void BaseCursor::_CalculateOrthoProjection() + void BaseCursor::_CalculateFaceNormals( Array& vertices, const Array& indices ) { - // calculate x,y cells. scale to NDC (normalized device coordinates) - Float xx = 2.0f / _aspect_ratio; - Float yy = 2.0f; - - // update projection matrix - _projection_matrix.Set( - xx, 0, 0, 0, - 0, -yy, 0, 0, - 0, 0, 1, 0, - 0, 0, 0, 1 - ); + // for each index + for( Index i = 0; i < indices.GetCount(); ++i ) + { + const Index3& index = indices[i]; + Index i0 = index.x; + Index i1 = index.y; + Index i2 = index.z; + Vector3f v10 = vertices[i1].position - vertices[i0].position; + Vector3f v20 = vertices[i2].position - vertices[i0].position; + Vector3f normal = v10.CrossProduct( v20 ).Normal(); + vertices[i0].normal = normal; + vertices[i1].normal = normal; + vertices[i2].normal = normal; + } } } diff --git a/source/YoloMouse/Loader/Overlay/Cursor/Cursors/BaseCursor.hpp b/source/YoloMouse/Loader/Overlay/Cursor/Cursors/BaseCursor.hpp index bd0eeca..4047871 100644 --- a/source/YoloMouse/Loader/Overlay/Cursor/Cursors/BaseCursor.hpp +++ b/source/YoloMouse/Loader/Overlay/Cursor/Cursors/BaseCursor.hpp @@ -2,7 +2,8 @@ #include #include #include -#include +#include +#include namespace Yolomouse { @@ -12,12 +13,6 @@ namespace Yolomouse { public: // types - struct BlendingDef - { - D3D11_BLEND src; - D3D11_BLEND dest; - }; - struct GeometryDef { Array vertices; @@ -30,7 +25,7 @@ namespace Yolomouse void* pixels; }; - struct UpdateDef2 + struct UpdateDef { Float frame_time; Vector3f& light_vector; @@ -47,15 +42,12 @@ namespace Yolomouse BaseCursor(); ~BaseCursor(); - // impl:IOverlayCursor /**/ - Bool Initialize( const InitializeDef& def ); + Bool Initialize( RenderContext& render_context ); void Shutdown(); /**/ Bool IsInitialized() const; - Bool IsTextureInitialized() const; - Bool IsGeometryInitialized() const; /**/ CursorId GetId() const; @@ -64,31 +56,16 @@ namespace Yolomouse /**/ virtual Bool SetCursor( CursorId id, CursorVariation variation, CursorSize size ); + void SetAspectRatio( Float aspect_ratio ); /**/ - void Update( const UpdateDef& def ); - - /**/ - void Draw() const; - - /**/ - void OnResize( const ResizeDef& def ); + void Draw( const Vector2f& position ); protected: /**/ virtual Bool _OnInitialize() = 0; - Bool _InitializeBlending( const BlendingDef& def ); - Bool _InitializeGeometry( const GeometryDef& def ); - Bool _InitializeTexture( const TextureDef& def ); - - /**/ virtual void _OnShutdown() = 0; - void _ShutdownBlending(); - void _ShutdownGeometry(); - void _ShutdownTexture(); - - /**/ - virtual void _OnUpdate( UpdateDef2& def ) = 0; + virtual void _OnUpdate( UpdateDef& def ) = 0; /**/ void _SetAutoScale( Bool enable ); @@ -96,34 +73,23 @@ namespace Yolomouse /**/ void _CalculateFaceNormals( Array& vertices, const Array& indices ); + // fields + Mesh _mesh; + Texture _texture; + RenderContext* _render_context; + private: // constants // SIZEID_TO_SCALE * SizeId = cursor size relative to resolution height static constexpr Float SIZEID_TO_SCALE = 0.0032f; - /**/ - void _InitializeCamera(); - - /**/ - void _CalculateOrthoProjection(); - // fields: parameters - RenderContext* _render_context; - Float _aspect_ratio; CursorId _id; CursorVariation _variation; CursorSize _size; Float _cursor_scale; Bool _auto_scale; // fields: state - ID3D11BlendState* _blend_state; - Index _shape_index_count; - ID3D11Buffer* _shape_index_buffer; - ID3D11Buffer* _shape_vertex_buffer; - ID3D11Texture2D* _texture; - ID3D11ShaderResourceView* _texture_view; Matrix4f _projection_matrix; - VertexShaderConstantValue _vs_constant_value; - PixelShaderConstantValue _ps_constant_value; }; -} \ No newline at end of file +} diff --git a/source/YoloMouse/Loader/Overlay/Cursor/Cursors/BasicCursor.cpp b/source/YoloMouse/Loader/Overlay/Cursor/Cursors/BasicCursor.cpp index 3ea0d9c..df34da4 100644 --- a/source/YoloMouse/Loader/Overlay/Cursor/Cursors/BasicCursor.cpp +++ b/source/YoloMouse/Loader/Overlay/Cursor/Cursors/BasicCursor.cpp @@ -55,10 +55,6 @@ namespace Yolomouse // initialized cursor vault _cursor_vault.Initialize( App::Instance().GetHostPath() ); - // initialize blending - if( !_InitializeBlending({D3D11_BLEND_SRC_ALPHA, D3D11_BLEND_INV_SRC_ALPHA}) ) - return false; - return true; } @@ -67,21 +63,18 @@ namespace Yolomouse ASSERT( IsInitialized() ); // shutdown texture - if( IsTextureInitialized() ) - _ShutdownTexture(); - - // shutdown geometry - if( IsGeometryInitialized() ) - _ShutdownGeometry(); + if( _texture.IsInitialized() ) + _texture.Shutdown(); - // shutdown blending - _ShutdownBlending(); + // shutdown mesh + if( _mesh.IsInitialized() ) + _mesh.Shutdown(); // shutdown cursor vault _cursor_vault.Shutdown(); } - void BasicCursor::_OnUpdate( UpdateDef2& def ) + void BasicCursor::_OnUpdate( UpdateDef& def ) { // static position, no animation } @@ -95,10 +88,10 @@ namespace Yolomouse // define vertices ShaderVertex VERTICES[] = { - { { tl.x, tl.y, 0 }, {1,0,0,1}, {0,0,1}, {0,0} }, - { { br.x, tl.y, 0 }, {1,1,0,1}, {0,0,1}, {1,0} }, - { { br.x, br.y, 0 }, {1,0,1,1}, {0,0,1}, {1,1} }, - { { tl.x, br.y, 0 }, {0,1,1,1}, {0,0,1}, {0,1} }, + { { tl.x, tl.y, 0 }, {1,1,1,1}, {0,0,1}, {0,0} }, + { { br.x, tl.y, 0 }, {1,1,1,1}, {0,0,1}, {1,0} }, + { { br.x, br.y, 0 }, {1,1,1,1}, {0,0,1}, {1,1} }, + { { tl.x, br.y, 0 }, {1,1,1,1}, {0,0,1}, {0,1} }, }; // define indices @@ -108,9 +101,10 @@ namespace Yolomouse }; // initialize geometry - return BaseCursor::_InitializeGeometry({ - Array(VERTICES, COUNT(VERTICES)), - Array (INDICES, COUNT(INDICES)) + return BaseCursor::_mesh.Initialize({ + *_render_context, + Array (INDICES, COUNT(INDICES)), + Array(VERTICES, COUNT(VERTICES)) }); } @@ -165,14 +159,14 @@ namespace Yolomouse Vector2f nds_size = color_size.Cast() / resolution_y; // shutdown previous - if( IsTextureInitialized() ) - _ShutdownTexture(); - if( IsGeometryInitialized() ) - _ShutdownGeometry(); + if( _texture.IsInitialized() ) + _texture.Shutdown(); + if( _mesh.IsInitialized() ) + _mesh.Shutdown(); // initialize geometry and texture if (_InitializeGeometry( nds_hotspot, nds_size ) && - _InitializeTexture({ color_size, color_pixels })) + _texture.Initialize({ *_render_context, color_pixels, color_size })) status = true; // cleanup diff --git a/source/YoloMouse/Loader/Overlay/Cursor/Cursors/BasicCursor.hpp b/source/YoloMouse/Loader/Overlay/Cursor/Cursors/BasicCursor.hpp index db75fd5..e83bf4f 100644 --- a/source/YoloMouse/Loader/Overlay/Cursor/Cursors/BasicCursor.hpp +++ b/source/YoloMouse/Loader/Overlay/Cursor/Cursors/BasicCursor.hpp @@ -24,7 +24,7 @@ namespace Yolomouse void _OnShutdown(); /**/ - void _OnUpdate( UpdateDef2& def ); + void _OnUpdate( UpdateDef& def ); /**/ Bool _InitializeGeometry( const Vector2f& hotspot, const Vector2f& size ); diff --git a/source/YoloMouse/Loader/Overlay/Cursor/Cursors/CircleCursor.cpp b/source/YoloMouse/Loader/Overlay/Cursor/Cursors/CircleCursor.cpp index f03ac30..0bb76ee 100644 --- a/source/YoloMouse/Loader/Overlay/Cursor/Cursors/CircleCursor.cpp +++ b/source/YoloMouse/Loader/Overlay/Cursor/Cursors/CircleCursor.cpp @@ -10,7 +10,7 @@ namespace Yolomouse { // constants //--------------------------------------------------------------------- - const Float ROTATION_SPEED = 0.04f; // rotations/sec + const Float ROTATION_SPEED = 0.06f; // rotations/sec const ULong SEGMENT_COUNT = 32; const Float RING_RADIUS0 = 1.10f; const Float RING_RADIUS1 = 1.30f; @@ -37,12 +37,8 @@ namespace Yolomouse //------------------------------------------------------------------------- Bool CircleCursor::_OnInitialize() { - // initialize blending - if( !_InitializeBlending({D3D11_BLEND_SRC_ALPHA, D3D11_BLEND_INV_SRC_ALPHA}) ) - return false; - - // initialize geometry - if( !_InitializeGeometry() ) + // initialize mesh + if( !_InitializeMesh() ) return false; return true; @@ -52,14 +48,11 @@ namespace Yolomouse { ASSERT( IsInitialized() ); - // shutdown geometry - _ShutdownGeometry(); - - // shutdown blending - _ShutdownBlending(); + // shutdown mesh + _mesh.Shutdown(); } - void CircleCursor::_OnUpdate( UpdateDef2& def ) + void CircleCursor::_OnUpdate( UpdateDef& def ) { // calculate rotation Float ux = Math::Cos(_rotater); @@ -76,7 +69,7 @@ namespace Yolomouse // private //------------------------------------------------------------------------- - Bool CircleCursor::_InitializeGeometry() + Bool CircleCursor::_InitializeMesh() { // constants static const ULong VINDEX_RING_ORIGIN = SEGMENT_COUNT * 3; @@ -91,8 +84,8 @@ namespace Yolomouse }; // buffers - static ShaderVertex vertex_data[VERTEX_COUNT]; - static Index3 index_data[INDEX_COUNT]; + ShaderVertex vertex_data[VERTEX_COUNT]; + Index3 index_data[INDEX_COUNT]; // set ring origin vertex ShaderVertex& v_ring_origin = vertex_data[VINDEX_RING_ORIGIN]; @@ -127,17 +120,17 @@ namespace Yolomouse v1.normal = v0b.normal; // create polys - i0.a = VINDEX_RING_ORIGIN; - i0.b = vi; - i0.c = i == (SEGMENT_COUNT - 1) ? 0 : vi + 3; + i0.x = VINDEX_RING_ORIGIN; + i0.y = vi; + i0.z = i == (SEGMENT_COUNT - 1) ? 0 : vi + 3; - i1.a = vi + 1; - i1.b = vi + 2; - i1.c = i0.c + 2; + i1.x = vi + 1; + i1.y = vi + 2; + i1.z = i0.z + 2; - i2.a = vi + 1; - i2.b = i0.c + 2; - i2.c = i0.c + 1; + i2.x = vi + 1; + i2.y = i0.z + 2; + i2.z = i0.z + 1; } // for each center vertex @@ -162,15 +155,16 @@ namespace Yolomouse v0.normal = v1.normal = v2.normal = Vector3f(off0.x * CENTER_HEIGHT, off0.y * CENTER_HEIGHT, CENTER_RADIUS).Normal(); // create poly - i0.a = vi; - i0.b = vi + 1; - i0.c = vi + 2; + i0.x = vi; + i0.y = vi + 1; + i0.z = vi + 2; } // initialize geometry - return BaseCursor::_InitializeGeometry({ - Array(vertex_data, VERTEX_COUNT), - Array (index_data, INDEX_COUNT) + return BaseCursor::_mesh.Initialize({ + *_render_context, + Array (index_data, INDEX_COUNT), + Array(vertex_data, VERTEX_COUNT) }); } } diff --git a/source/YoloMouse/Loader/Overlay/Cursor/Cursors/CircleCursor.hpp b/source/YoloMouse/Loader/Overlay/Cursor/Cursors/CircleCursor.hpp index 6f624a1..27fea61 100644 --- a/source/YoloMouse/Loader/Overlay/Cursor/Cursors/CircleCursor.hpp +++ b/source/YoloMouse/Loader/Overlay/Cursor/Cursors/CircleCursor.hpp @@ -20,11 +20,11 @@ namespace Yolomouse void _OnShutdown(); /**/ - void _OnUpdate( UpdateDef2& def ); + void _OnUpdate( UpdateDef& def ); private: /**/ - Bool _InitializeGeometry(); + Bool _InitializeMesh(); // fields: state Float _rotater; diff --git a/source/YoloMouse/Loader/Overlay/Cursor/IOverlayCursor.hpp b/source/YoloMouse/Loader/Overlay/Cursor/IOverlayCursor.hpp index 032acf4..73407b6 100644 --- a/source/YoloMouse/Loader/Overlay/Cursor/IOverlayCursor.hpp +++ b/source/YoloMouse/Loader/Overlay/Cursor/IOverlayCursor.hpp @@ -9,25 +9,8 @@ namespace Yolomouse class IOverlayCursor { public: - // types - struct InitializeDef - { - RenderContext& render_context; - Float aspect_ratio; - }; - - struct ResizeDef - { - Float aspect_ratio; - }; - - struct UpdateDef - { - const Vector2f cursor_position; - }; - /**/ - virtual Bool Initialize( const InitializeDef& def ) = 0; + virtual Bool Initialize( RenderContext& render_context ) = 0; virtual void Shutdown() = 0; /**/ @@ -35,14 +18,9 @@ namespace Yolomouse /**/ virtual Bool SetCursor( CursorId id, CursorVariation variation, CursorSize size ) = 0; + virtual void SetAspectRatio( Float aspect_ratio ) = 0; /**/ - virtual void Update( const UpdateDef& def ) = 0; - - /**/ - virtual void Draw() const = 0; - - /**/ - virtual void OnResize( const ResizeDef& def ) = 0; + virtual void Draw( const Vector2f& position ) = 0; }; } diff --git a/source/YoloMouse/Loader/Overlay/Mouse/MousePositionMonitor.cpp b/source/YoloMouse/Loader/Overlay/Mouse/MousePositionMonitor.cpp index 67e4f0c..b918306 100644 --- a/source/YoloMouse/Loader/Overlay/Mouse/MousePositionMonitor.cpp +++ b/source/YoloMouse/Loader/Overlay/Mouse/MousePositionMonitor.cpp @@ -6,12 +6,13 @@ namespace Yolomouse //------------------------------------------------------------------------- MousePositionMonitor::MousePositionMonitor(): // fields: parameters - _window (nullptr), + _window (nullptr), + _option_improved_precision (false), // fields: state - _mickey_multiplier (0), - _initialized (false), - _cursor_position_delta (0,0), - _hover_hwnd (NULL) + _mickey_multiplier (0), + _initialized (false), + _cursor_position_delta (0,0), + _hover_hwnd (NULL) { } @@ -74,22 +75,28 @@ namespace Yolomouse } //------------------------------------------------------------------------- - Bool MousePositionMonitor::GetCursorPosition( Vector2l& windows_position, Vector2l& adjusted_position, Vector2f& nds_position ) + Bool MousePositionMonitor::GetCursorPosition( Vector2l& windows_position, Vector2f& nds_position ) { - POINT point; - Vector2l size = _window->GetSize(); + POINT point; + Vector2l adjusted_position; + Vector2l size = _window->GetSize(); // get cursor position (1 frame behind) if( !GetCursorPos( &point ) ) return false; // convert point to windows position - windows_position.x = point.x; - windows_position.y = point.y; + windows_position.Set( point.x, point.y ); - // adjust by cursor position delta from raw input adjusted by mickey multiplier (depends on windows mouse settings) - adjusted_position.x = windows_position.x + static_cast(static_cast(_cursor_position_delta.x) * _mickey_multiplier); - adjusted_position.y = windows_position.y + static_cast(static_cast(_cursor_position_delta.y) * _mickey_multiplier); + // if rawinput mickeys are to be included to improve precision + if( _option_improved_precision ) + { + // adjust by cursor position delta from raw input adjusted by mickey multiplier (depends on windows mouse settings) + adjusted_position = windows_position + ( _cursor_position_delta.Cast() * _mickey_multiplier ).Cast(); + } + // else use base window position + else + adjusted_position = windows_position; // convert to NDS coordinates given current resolution nds_position.x = (static_cast(adjusted_position.x) / static_cast(size.y)) - (_window->GetAspectRatio() * 0.5f); @@ -101,6 +108,12 @@ namespace Yolomouse return true; } + //------------------------------------------------------------------------- + void MousePositionMonitor::SetImprovedPrecision( Bool enabled ) + { + _option_improved_precision = enabled; + } + // private //------------------------------------------------------------------------- void MousePositionMonitor::_UpdateMouseSettings() @@ -156,9 +169,10 @@ namespace Yolomouse // if acceleration enabled if( mouse_settings[2] ) { - //TODO4 acceleration more complicated, read following to improve + //TODO4 acceleration more complicated, read following to improve. // https://www.esreality.com/index.php?a=post&id=1945096 - _mickey_multiplier = entry.enhanced * MICKEY_MULTIPLIER_DAMPENER; + // for now increase dampening by 2x + _mickey_multiplier = entry.enhanced * MICKEY_MULTIPLIER_DAMPENER * 0.5f; } // else use normal factor else diff --git a/source/YoloMouse/Loader/Overlay/Mouse/MousePositionMonitor.hpp b/source/YoloMouse/Loader/Overlay/Mouse/MousePositionMonitor.hpp index 8d77c44..372622b 100644 --- a/source/YoloMouse/Loader/Overlay/Mouse/MousePositionMonitor.hpp +++ b/source/YoloMouse/Loader/Overlay/Mouse/MousePositionMonitor.hpp @@ -44,7 +44,10 @@ namespace Yolomouse Bool IsInitialized() const; /**/ - Bool GetCursorPosition( Vector2l& windows_position, Vector2l& adjusted_position, Vector2f& nds_position ); + Bool GetCursorPosition( Vector2l& windows_position, Vector2f& nds_position ); + + /**/ + void SetImprovedPrecision( Bool enabled ); private: // constants @@ -61,6 +64,7 @@ namespace Yolomouse // fields: parameters Window* _window; + Bool _option_improved_precision; // fields: state Bool _initialized; Float _mickey_multiplier; diff --git a/source/YoloMouse/Loader/Overlay/Overlay.cpp b/source/YoloMouse/Loader/Overlay/Overlay.cpp index fe5f292..663035b 100644 --- a/source/YoloMouse/Loader/Overlay/Overlay.cpp +++ b/source/YoloMouse/Loader/Overlay/Overlay.cpp @@ -9,8 +9,9 @@ namespace Yolomouse namespace { // constants - constexpr ULong TOPMOST_UPDATE_COUNT = 8; // frames - constexpr ULong TOPMOST_ROUTINE_COUNT = 200; // frames + constexpr ULong TOPMOST_UPDATE_COUNT = 8; // frames + constexpr ULong TOPMOST_ROUTINE_COUNT = 200; // frames + constexpr ULong MESSAGE_TIMEOUT_PER_CHARACTER = 40; // ms } // public @@ -19,14 +20,16 @@ namespace Yolomouse // fields: parameters _active_cursor (nullptr), // fields: state - _thread (NULL), _initialized (false), _started (false), _active (false), _hover_hwnd (NULL), + // fields: events _pre_frame_events (0), _in_frame_events (0), - _resize_event (0, 0) + _resize_event (0, 0), + // fields: objects + _thread (NULL) { _cursors.Zero(); } @@ -125,8 +128,26 @@ namespace Yolomouse void Overlay::SetCursorHidden() { + // activate (remove any inflight set cursor event) + _in_frame_events = IN_FRAME_EVENT_HIDE_CURSOR | (_in_frame_events & ~IN_FRAME_EVENT_SET_CURSOR); + } + + void Overlay::SetMessage( const String& message ) + { + // copy message + _message_event = message; + // activate - _in_frame_events |= IN_FRAME_EVENT_HIDE_CURSOR; + _in_frame_events |= IN_FRAME_EVENT_SET_MESSAGE; + } + + void Overlay::SetReduceLatency( Bool enable ) + { + // set improved mouse precision + _mouse.SetImprovedPrecision( enable ); + + // set reduced rendering latency + _render_context.SetReduceLatency( enable ); } //------------------------------------------------------------------------- @@ -136,8 +157,9 @@ namespace Yolomouse ASSERT( _cursors[id] == nullptr ); // initialize cursor - if( !cursor.Initialize({ _render_context, _window.GetAspectRatio() }) ) + if( !cursor.Initialize( _render_context) ) return false; + cursor.SetAspectRatio( _window.GetAspectRatio() ); // add cursor to table _cursors[id] = &cursor; @@ -178,6 +200,7 @@ namespace Yolomouse #ifdef BUILD_DEBUG CursorInfo cursor = { CURSOR_TYPE_OVERLAY, 0, 0, 10 }; SetCursorIterated( cursor ); + SetMessage( "Test Message 123" ); #endif return true; @@ -214,8 +237,14 @@ namespace Yolomouse return false; // initialize basic cursor - if( !_basic_cursor.Initialize({ _render_context, _window.GetAspectRatio() }) ) + if( !_basic_cursor.Initialize( _render_context ) ) return false; + _basic_cursor.SetAspectRatio( _window.GetAspectRatio() ); + + // initialize text popup + if( !_text_popup.Initialize(_render_context) ) + return false; + _text_popup.SetAspectRatio( _window.GetAspectRatio() ); // register events _window.events.Add( *this ); @@ -245,6 +274,9 @@ namespace Yolomouse // unregister events _window.events.Remove( *this ); + // shutdown text popup + _text_popup.Shutdown(); + // shutdown basic cursor _basic_cursor.Shutdown(); @@ -272,6 +304,48 @@ namespace Yolomouse } //------------------------------------------------------------------------- + void Overlay::_FrameLoop() + { + Vector2l windows_position; + Vector2f nds_position; + + // run frame loop + while(_active) + { + Bool idle = true; + + // process pre frame events + _ProcessPreFrameEvents(); + + // being render session + _render_context.RenderBegin(); + + // get mouse monitor cursor position + if( _mouse.GetCursorPosition(windows_position, nds_position) ) + { + // update hover state using windows cursor position + _UpdateHoverState(windows_position); + + // process in frame events + _ProcessInFrameEvents(); + + // update text popup and reset idle if active + if( _UpdateTextPopup() ) + idle = false; + + // if active cursor exists, draw cursor and reset idle + if( _active_cursor != nullptr ) + { + _active_cursor->Draw(nds_position); + idle = false; + } + } + + // complete render session + _render_context.RenderComplete(idle); + } + } + void Overlay::_ProcessPreFrameEvents() { // if pending pre frame events exist @@ -279,7 +353,7 @@ namespace Yolomouse { // handle resize if( _pre_frame_events & PRE_FRAME_EVENT_RESIZE ) - _FrameResize( _resize_event ); + _OnFrameEventResize( _resize_event ); // reset pre frame events _pre_frame_events = 0; @@ -291,19 +365,23 @@ namespace Yolomouse // if pending in frame events exist if( _in_frame_events != 0 ) { - // if cursor hide, reset active cursor + // reset active cursor if( _in_frame_events & IN_FRAME_EVENT_HIDE_CURSOR ) _active_cursor = nullptr; - // if cursor set, if set new cursor + // set new cursor (ensure called after hide cursor in case hide+set event at same time) if( _in_frame_events & IN_FRAME_EVENT_SET_CURSOR ) _active_cursor = _cursor_event; + // set message popup + if( _in_frame_events & IN_FRAME_EVENT_SET_MESSAGE ) + _OnFrameEventMessage( _message_event ); // reset in frame events _in_frame_events = 0; } } - void Overlay::_FrameResize( const Vector2l& size ) + //------------------------------------------------------------------------- + void Overlay::_OnFrameEventResize( const Vector2l& size ) { // update window size _window.SetSize(size); @@ -311,55 +389,36 @@ namespace Yolomouse // resize render context _render_context.Resize(size); - // notify cursors - _basic_cursor.OnResize( { _window.GetAspectRatio() } ); + // update cursor aspect ratios + _basic_cursor.SetAspectRatio( _window.GetAspectRatio() ); for( IOverlayCursor* cursor : _cursors ) if( cursor != nullptr ) - cursor->OnResize( { _window.GetAspectRatio() } ); + cursor->SetAspectRatio( _window.GetAspectRatio() ); + + // update text popup aspect ratio + _text_popup.SetAspectRatio( _window.GetAspectRatio() ); } - void Overlay::_FrameLoop() + void Overlay::_OnFrameEventMessage( const String& message ) { - Vector2l windows_position; - Vector2l adjusted_position; - Vector2f nds_position; + RECT rect; - // run frame loop - while(_active) + // get window bounds + if( GetWindowRect( _hover_hwnd, &rect ) ) { - Bool idle = true; - - // process pre frame events - _ProcessPreFrameEvents(); - - // being render session - _render_context.RenderBegin(); - - // get mouse monitor cursor position - if( _mouse.GetCursorPosition(windows_position, adjusted_position, nds_position) ) - { - // update hover state using windows cursor position - _UpdateHoverState(windows_position); + Vector2f wsize = _window.GetSize().Cast(); - // process in frame events - _ProcessInFrameEvents(); + // center of window in screen coordinates + Vector2f position(rect.left + (rect.right - rect.left) * 0.5f, rect.top + (rect.bottom - rect.top) * 0.5f); - // if active cursor exists - if( _active_cursor != nullptr ) - { - // update cursor - _active_cursor->Update({ nds_position }); - - // draw cursor - _active_cursor->Draw(); + // calculate center of window in NDS coordinates + position = (position - wsize / 2.0f) / wsize.y; - // set render - idle = false; - } - } + // determine timeout based on text length + ULong timeout = message.GetCount() * MESSAGE_TIMEOUT_PER_CHARACTER + 1000; - // complete render session - _render_context.RenderComplete(idle); + // set text popup message, position, and timeout + _text_popup.SetText( message, position, timeout); } } @@ -379,6 +438,18 @@ namespace Yolomouse events.Notify( {OverlayEvent::WINDOW_HOVER, _hover_hwnd } ); } + Bool Overlay::_UpdateTextPopup() + { + // draw text popup if active + if( _text_popup.IsActive() ) + { + _text_popup.Draw(); + return true; + } + + return false; + } + //------------------------------------------------------------------------- IOverlayCursor* Overlay::_LoadCursor( const CursorInfo& info ) { diff --git a/source/YoloMouse/Loader/Overlay/Overlay.hpp b/source/YoloMouse/Loader/Overlay/Overlay.hpp index dfb4368..4a2fa80 100644 --- a/source/YoloMouse/Loader/Overlay/Overlay.hpp +++ b/source/YoloMouse/Loader/Overlay/Overlay.hpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include @@ -44,6 +45,8 @@ namespace Yolomouse Bool SetCursor( const CursorInfo& info ); Bool SetCursorIterated( CursorInfo& info ); void SetCursorHidden(); + void SetMessage( const String& message ); + void SetReduceLatency( Bool enable ); /**/ Bool InstallCursor( CursorId id, IOverlayCursor& cursor ); @@ -66,7 +69,8 @@ namespace Yolomouse enum: Bits { IN_FRAME_EVENT_SET_CURSOR = BIT(0), - IN_FRAME_EVENT_HIDE_CURSOR = BIT(1) + IN_FRAME_EVENT_HIDE_CURSOR = BIT(1), + IN_FRAME_EVENT_SET_MESSAGE = BIT(2) }; typedef Bits InFrameEvents; @@ -89,13 +93,17 @@ namespace Yolomouse void _ShutdownThread(); /**/ + void _FrameLoop(); void _ProcessPreFrameEvents(); void _ProcessInFrameEvents(); - void _FrameResize( const Vector2l& size ); - void _FrameLoop(); + + /**/ + void _OnFrameEventResize( const Vector2l& size ); + void _OnFrameEventMessage( const String& message ); /**/ void _UpdateHoverState( const Vector2l& cursor_position ); + Bool _UpdateTextPopup(); /**/ IOverlayCursor* _LoadCursor( const CursorInfo& info ); @@ -112,19 +120,22 @@ namespace Yolomouse CursorTable _cursors; IOverlayCursor* _active_cursor; // fields: state - Window _window; - MousePositionMonitor _mouse; - HANDLE _thread; Bool _initialized; Bool _started; Bool _active; - BasicCursor _basic_cursor; HWND _hover_hwnd; - RenderContext _render_context; - // fields: local events + // fields: events PreFrameEvents _pre_frame_events; InFrameEvents _in_frame_events; Vector2l _resize_event; IOverlayCursor* _cursor_event; + SimpleString _message_event; + // fields: objects + Window _window; + MousePositionMonitor _mouse; + RenderContext _render_context; + HANDLE _thread; + BasicCursor _basic_cursor; + TextPopup _text_popup; }; } diff --git a/source/YoloMouse/Loader/Overlay/Rendering/Assets/Mesh.cpp b/source/YoloMouse/Loader/Overlay/Rendering/Assets/Mesh.cpp new file mode 100644 index 0000000..ed0178c --- /dev/null +++ b/source/YoloMouse/Loader/Overlay/Rendering/Assets/Mesh.cpp @@ -0,0 +1,104 @@ +#include + +namespace Yolomouse +{ + // public + //------------------------------------------------------------------------- + Mesh::Mesh(): + _render_context (nullptr), + _index_count (0), + _index_buffer (nullptr), + _vertex_buffer (nullptr) + { + } + + Mesh::~Mesh() + { + ASSERT( !IsInitialized() ); + } + + //------------------------------------------------------------------------- + Bool Mesh::Initialize( const InitializeDef& def ) + { + ASSERT( !IsInitialized() ); + D3D11_BUFFER_DESC index_buffer_desc = {}; + D3D11_BUFFER_DESC vertex_buffer_desc = {}; + D3D11_SUBRESOURCE_DATA subresource_data = {}; + HRESULT hresult; + + // set fields + _render_context = &def.render_context; + + // save index count + _index_count = def.indices.GetCount() * 3; + + // describe index buffer + index_buffer_desc.Usage = D3D11_USAGE_DEFAULT; + index_buffer_desc.ByteWidth = sizeof(Index) * _index_count; + index_buffer_desc.BindFlags = D3D11_BIND_INDEX_BUFFER; + + // create index buffer + subresource_data.pSysMem = def.indices.GetMemory(); + if( (hresult = _render_context->GetDevice().CreateBuffer(&index_buffer_desc, &subresource_data, &_index_buffer)) != S_OK ) + return false; + + // describe vertex buffer + vertex_buffer_desc.Usage = D3D11_USAGE_DEFAULT; + vertex_buffer_desc.ByteWidth = sizeof(ShaderVertex) * def.vertices.GetCount(); + vertex_buffer_desc.BindFlags = D3D11_BIND_VERTEX_BUFFER; + vertex_buffer_desc.CPUAccessFlags = 0; + vertex_buffer_desc.MiscFlags = 0; + + // create vertex buffer + subresource_data.pSysMem = def.vertices.GetMemory(); + if( (hresult = _render_context->GetDevice().CreateBuffer(&vertex_buffer_desc, &subresource_data, &_vertex_buffer)) != S_OK ) + return false; + + return true; + } + + void Mesh::Shutdown() + { + ASSERT( IsInitialized() ); + + // shutdown vertex buffer + if( _vertex_buffer ) + { + _vertex_buffer->Release(); + _vertex_buffer = nullptr; + } + + // shutdown index buffer + if( _index_buffer ) + { + _index_buffer->Release(); + _index_buffer = nullptr; + } + + // reset fields + _render_context = nullptr; + } + + //------------------------------------------------------------------------- + Bool Mesh::IsInitialized() const + { + return _render_context != nullptr; + } + + //------------------------------------------------------------------------- + void Mesh::Draw() const + { + ID3D11DeviceContext& device_context = _render_context->GetDeviceContext(); + + // set index buffer + device_context.IASetIndexBuffer(_index_buffer, DXGI_FORMAT_R32_UINT, 0); + + // set vertex buffer + UINT stride = sizeof(ShaderVertex); + UINT offset = 0; + device_context.IASetVertexBuffers(0, 1, &_vertex_buffer, &stride, &offset); + + // draw shape + device_context.DrawIndexed(_index_count, 0, 0); + } +} diff --git a/source/YoloMouse/Loader/Overlay/Rendering/Assets/Mesh.hpp b/source/YoloMouse/Loader/Overlay/Rendering/Assets/Mesh.hpp new file mode 100644 index 0000000..df262b6 --- /dev/null +++ b/source/YoloMouse/Loader/Overlay/Rendering/Assets/Mesh.hpp @@ -0,0 +1,40 @@ +#pragma once +#include +#include + +namespace Yolomouse +{ + /**/ + class Mesh + { + public: + // types + struct InitializeDef + { + RenderContext& render_context; + Array indices; + Array vertices; + }; + + /**/ + Mesh(); + ~Mesh(); + + /**/ + Bool Initialize( const InitializeDef& def ); + void Shutdown(); + + /**/ + Bool IsInitialized() const; + + /**/ + void Draw() const; + + private: + // fields + RenderContext* _render_context; + Index _index_count; + ID3D11Buffer* _index_buffer; + ID3D11Buffer* _vertex_buffer; + }; +} diff --git a/source/YoloMouse/Loader/Overlay/Rendering/Assets/Texture.cpp b/source/YoloMouse/Loader/Overlay/Rendering/Assets/Texture.cpp new file mode 100644 index 0000000..14a01d9 --- /dev/null +++ b/source/YoloMouse/Loader/Overlay/Rendering/Assets/Texture.cpp @@ -0,0 +1,102 @@ +#include + +namespace Yolomouse +{ + // public + //------------------------------------------------------------------------- + Texture::Texture(): + _render_context (nullptr), + _texture (nullptr), + _texture_view (nullptr) + { + } + + Texture::~Texture() + { + ASSERT( !IsInitialized() ); + } + + //------------------------------------------------------------------------- + Bool Texture::Initialize( const InitializeDef& def ) + { + ASSERT( !IsInitialized() ); + D3D11_TEXTURE2D_DESC texture_desc = {}; + D3D11_SUBRESOURCE_DATA subresource_data = {}; + ID3D11Device& device = def.render_context.GetDevice(); + + // set fields + _render_context = &def.render_context; + + // define texture + texture_desc.Width = def.size.x; + texture_desc.Height = def.size.y; + texture_desc.MipLevels = 1; + texture_desc.ArraySize = 1; + texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; + texture_desc.SampleDesc.Count = 1; + texture_desc.SampleDesc.Quality = 0; + texture_desc.Usage = D3D11_USAGE_IMMUTABLE; + texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE; + texture_desc.CPUAccessFlags = 0; + texture_desc.MiscFlags = 0; + + // define subresource data + subresource_data.pSysMem = def.pixel_data; + subresource_data.SysMemPitch = def.size.x * 4; + + // create texture + if( device.CreateTexture2D( &texture_desc, &subresource_data, &_texture ) == S_OK ) + { + D3D11_SHADER_RESOURCE_VIEW_DESC shader_resource_view_desc = {}; + + // define shader resource view desc + shader_resource_view_desc.Format = texture_desc.Format; + shader_resource_view_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D; + shader_resource_view_desc.Texture2D.MipLevels = -1; + shader_resource_view_desc.Texture2D.MostDetailedMip = 0; + + // create texture view + if( device.CreateShaderResourceView( _texture, &shader_resource_view_desc, &_texture_view ) == S_OK ) + return true; + } + + return false; + } + + void Texture::Shutdown() + { + ASSERT( IsInitialized() ); + + // shutdown texture view + if( _texture_view ) + { + _texture_view->Release(); + _texture_view = nullptr; + } + + // shutdown texture + if( _texture ) + { + _texture->Release(); + _texture = nullptr; + } + + // reset fields + _render_context = nullptr; + } + + //------------------------------------------------------------------------- + Bool Texture::IsInitialized() const + { + return _render_context != nullptr; + } + + //------------------------------------------------------------------------- + void Texture::Draw() const + { + ID3D11DeviceContext& device_context = _render_context->GetDeviceContext(); + + // bind texture to pixel shader + device_context.PSSetShaderResources(0, 1, &_texture_view); + } +} diff --git a/source/YoloMouse/Loader/Overlay/Rendering/Assets/Texture.hpp b/source/YoloMouse/Loader/Overlay/Rendering/Assets/Texture.hpp new file mode 100644 index 0000000..32d715e --- /dev/null +++ b/source/YoloMouse/Loader/Overlay/Rendering/Assets/Texture.hpp @@ -0,0 +1,39 @@ +#pragma once +#include +#include + +namespace Yolomouse +{ + /**/ + class Texture + { + public: + // types + struct InitializeDef + { + RenderContext& render_context; + const void* pixel_data; + Vector2l size; + }; + + /**/ + Texture(); + ~Texture(); + + /**/ + Bool Initialize( const InitializeDef& def ); + void Shutdown(); + + /**/ + Bool IsInitialized() const; + + /**/ + void Draw() const; + + private: + // fields + RenderContext* _render_context; + ID3D11Texture2D* _texture; + ID3D11ShaderResourceView* _texture_view; + }; +} diff --git a/source/YoloMouse/Loader/Overlay/Rendering/RenderContext.cpp b/source/YoloMouse/Loader/Overlay/Rendering/RenderContext.cpp index 08385ec..25eac68 100644 --- a/source/YoloMouse/Loader/Overlay/Rendering/RenderContext.cpp +++ b/source/YoloMouse/Loader/Overlay/Rendering/RenderContext.cpp @@ -11,7 +11,7 @@ namespace Yolomouse { // constants //--------------------------------------------------------------------- - static const Float CLEAR_COLOR[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; + static const Float CLEAR_COLOR[4] = { 0, 0, 0, 0 }; } // public @@ -32,6 +32,7 @@ namespace Yolomouse _depthstencil_state (nullptr), _depthstencil_buffer (nullptr), _depthstencil_view (nullptr), + _blend_state (nullptr), _render_target_view (nullptr), _vertex_shader (nullptr), _pixel_shader (nullptr), @@ -60,13 +61,16 @@ namespace Yolomouse if( !_InitializeD3d(hwnd) ) return false; - // initialize render timing controller - _render_timing_controller.SetResolution( _size ); - _render_timing_controller.Initialize( *_swapchain_output ); + // initialize blending + if( !_InitializeBlending() ) + return false; // initialize view _InitializeView(); + // initialize render timing controller + _render_timing_controller.Initialize( *_swapchain_output, _size ); + // set initialized _initialized = true; @@ -82,6 +86,9 @@ namespace Yolomouse if( _render_timing_controller.IsInitialized() ) _render_timing_controller.Shutdown(); + // shutdown blending + _ShutdownBlending(); + // shutdown direct3d _ShutdownD3d(); @@ -123,6 +130,13 @@ namespace Yolomouse return _size; } + //------------------------------------------------------------------------- + void RenderContext::SetReduceLatency( Bool enabled ) + { + // set render timing controller fill time option + _render_timing_controller.SetFillTime( enabled ); + } + //------------------------------------------------------------------------- Bool RenderContext::Resize( const Vector2l& size ) { @@ -132,8 +146,8 @@ namespace Yolomouse // set new size _size = size; - // update render timing controller - _render_timing_controller.SetResolution( size ); + // shutdown render timing controller + _render_timing_controller.Shutdown(); // shutdown render target view _ShutdownD3dRenderTargetView(); @@ -160,6 +174,9 @@ namespace Yolomouse // reinitialize view _InitializeView(); + // reinitialize render timing controller + _render_timing_controller.Initialize( *_swapchain_output, _size ); + return true; } @@ -186,6 +203,9 @@ namespace Yolomouse // begin render timing controller _render_timing_controller.Begin(); + + // set blend state + _device_context->OMSetBlendState(_blend_state, NULL, 0xffffffff); } void RenderContext::RenderComplete( Bool idle ) @@ -393,6 +413,7 @@ namespace Yolomouse // create sampler if( (hresult = _device->CreateSamplerState( &sampler_desc, &_sampler )) != S_OK ) return false; + _device_context->PSSetSamplers(0, 1, &_sampler); // create vertex shader object constant buffer if( !_InitializeD3dBuffer( _vs_constant_buffer, D3D11_USAGE_DEFAULT, sizeof( VertexShaderConstantValue ), D3D11_BIND_CONSTANT_BUFFER ) ) @@ -454,8 +475,7 @@ namespace Yolomouse // describe depth stencil view depthstencil_view_desc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT; - //depthstencil_view_desc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D; - depthstencil_view_desc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2DMS; + depthstencil_view_desc.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2DMS; // to get antialiasing working depthstencil_view_desc.Texture2D.MipSlice = 0; // describe depth stencil texture @@ -514,6 +534,31 @@ namespace Yolomouse return true; } + Bool RenderContext::_InitializeBlending() + { + D3D11_BLEND_DESC blend_desc = {}; + HRESULT hresult; + + // describe blend state + blend_desc.RenderTarget[0].BlendEnable = TRUE; + blend_desc.RenderTarget[0].RenderTargetWriteMask = D3D11_COLOR_WRITE_ENABLE_ALL; + blend_desc.RenderTarget[0].SrcBlend = D3D11_BLEND_SRC_ALPHA; + blend_desc.RenderTarget[0].DestBlend = D3D11_BLEND_INV_SRC_ALPHA; + blend_desc.RenderTarget[0].SrcBlendAlpha = D3D11_BLEND_ONE; + blend_desc.RenderTarget[0].DestBlendAlpha = D3D11_BLEND_ZERO; + blend_desc.RenderTarget[0].BlendOp = D3D11_BLEND_OP_ADD; + blend_desc.RenderTarget[0].BlendOpAlpha = D3D11_BLEND_OP_MAX; + + // create blend state + if( (hresult = _device->CreateBlendState(&blend_desc, &_blend_state)) != S_OK ) + { + LOG( "BaseCursor.InitializeBlending.CreateBlendState" ); + return false; + } + + return true; + } + void RenderContext::_InitializeView() { D3D11_VIEWPORT viewport = {}; @@ -648,6 +693,16 @@ namespace Yolomouse } } + void RenderContext::_ShutdownBlending() + { + // shutdown blend state + if( _blend_state ) + { + _blend_state->Release(); + _blend_state = nullptr; + } + } + void RenderContext::_ShutdownD3dRenderTargetView() { // shutdown render target view diff --git a/source/YoloMouse/Loader/Overlay/Rendering/RenderContext.hpp b/source/YoloMouse/Loader/Overlay/Rendering/RenderContext.hpp index b98a701..0ce06c0 100644 --- a/source/YoloMouse/Loader/Overlay/Rendering/RenderContext.hpp +++ b/source/YoloMouse/Loader/Overlay/Rendering/RenderContext.hpp @@ -30,7 +30,10 @@ namespace Yolomouse const Vector2l& GetSize() const; /**/ - Bool Resize(const Vector2l& size); + void SetReduceLatency( Bool enabled ); + + /**/ + Bool Resize( const Vector2l& size ); /**/ void CommitShaderContants( const VertexShaderConstantValue& vs, const PixelShaderConstantValue& ps ); @@ -45,11 +48,13 @@ namespace Yolomouse Bool _InitializeD3dBuffer( ID3D11Buffer*& buffer, D3D11_USAGE usage, ULong size, UINT BindFlags ); Bool _InitializeD3dDepthStencilView(); Bool _InitializeD3dRenderTargetView(); + Bool _InitializeBlending(); void _InitializeView(); /**/ void _ShutdownD3d(); void _ShutdownD3dDepthStencilView(); + void _ShutdownBlending(); void _ShutdownD3dRenderTargetView(); /**/ @@ -71,6 +76,7 @@ namespace Yolomouse ID3D11DepthStencilState* _depthstencil_state; ID3D11Texture2D* _depthstencil_buffer; ID3D11DepthStencilView* _depthstencil_view; + ID3D11BlendState* _blend_state; ID3D11RenderTargetView* _render_target_view; ID3D11VertexShader* _vertex_shader; ID3D11PixelShader* _pixel_shader; diff --git a/source/YoloMouse/Loader/Overlay/Rendering/Shaders/Default/PixelShader.hlsl b/source/YoloMouse/Loader/Overlay/Rendering/Shaders/Default/PixelShader.hlsl index 1dcce38..373b9f2 100644 --- a/source/YoloMouse/Loader/Overlay/Rendering/Shaders/Default/PixelShader.hlsl +++ b/source/YoloMouse/Loader/Overlay/Rendering/Shaders/Default/PixelShader.hlsl @@ -1,12 +1,23 @@ +// enums +static const uint TYPE_UNLIT_BASIC = 0; +static const uint TYPE_LIT_BASIC = 1; +static const uint TYPE_UNLIT_TEXTURE = 2; + +// constants +static const float SATURATION = 1.5; + +// texture SamplerState sampler0: register( s0 ); Texture2D texture0; +// constants cbuffer ConstantBuffer { float3 light_vector; - uint texturing; + uint type; }; +// input struct PS_INPUT { float4 position : SV_POSITION; @@ -15,15 +26,26 @@ struct PS_INPUT float2 uv : UV; }; +// main float4 PS(PS_INPUT input) : SV_Target { //return float4(1,1,1,1); - float intensity = (dot(input.normal, light_vector) + 1) / 1; - float4 vintensity = float4(intensity, intensity, intensity, 1); - - if( texturing != 0 ) - return texture0.Sample(sampler0, input.uv); - else - return input.color * vintensity; + switch( type ) + { + case TYPE_UNLIT_BASIC: + return input.color; + + case TYPE_LIT_BASIC: + { + float light = dot( input.normal, light_vector ); + return float4(input.color.rgb * SATURATION + light, input.color.a); + } + + case TYPE_UNLIT_TEXTURE: + return texture0.Sample( sampler0, input.uv ) * input.color; + + default: + return float4(1,1,1,1); + } } diff --git a/source/YoloMouse/Loader/Overlay/Rendering/Shaders/Default/PixelShader.hpp b/source/YoloMouse/Loader/Overlay/Rendering/Shaders/Default/PixelShader.hpp index 88900a2..12b68a9 100644 --- a/source/YoloMouse/Loader/Overlay/Rendering/Shaders/Default/PixelShader.hpp +++ b/source/YoloMouse/Loader/Overlay/Rendering/Shaders/Default/PixelShader.hpp @@ -9,7 +9,7 @@ // { // // float3 light_vector; // Offset: 0 Size: 12 -// uint texturing; // Offset: 12 Size: 4 +// uint type; // Offset: 12 Size: 4 // // } // @@ -58,20 +58,27 @@ // Level9 shader bytecode: // ps_2_0 - def c1, 1, 0, 0, 0 + def c1, -1, 1.5, -2, 1 dcl t0 dcl t1.xyz dcl t2.xy dcl_2d s0 texld r0, t2, s0 - dp3 r1.w, t1, c0 - add r1.xyz, r1.w, c1.x - mov r1.w, c1.x - mul r1, r1, t0 - cmp r0, -c0.w, r1, r0 + mov r1.w, c0.w + add r1.x, r1.w, c1.z + mul r1.x, r1.x, r1.x + mul r0, r0, t0 + cmp r0, -r1.x, r0, c1.w + add r1.x, r1.w, c1.x + mul r1.x, r1.x, r1.x + dp3 r1.y, t1, c0 + mad r2.xyz, t0, c1.y, r1.y + mov r2.w, t0.w + cmp r0, -r1.x, r2, r0 + cmp r0, -c0.w, t0, r0 mov oC0, r0 -// approximately 7 instruction slots used (1 texture, 6 arithmetic) +// approximately 14 instruction slots used (1 texture, 13 arithmetic) ps_4_0 dcl_constantbuffer cb0[1], immediateIndexed dcl_sampler s0, mode_default @@ -81,35 +88,42 @@ dcl_input_ps linear v2.xyz dcl_input_ps linear v3.xy dcl_output o0.xyzw dcl_temps 1 -if_nz cb0[0].w - sample o0.xyzw, v3.xyxx, t0.xyzw, s0 +switch cb0[0].w + case l(0) + mov o0.xyzw, v1.xyzw ret -else + case l(1) dp3 r0.x, v2.xyzx, cb0[0].xyzx - add r0.xyz, r0.xxxx, l(1.000000, 1.000000, 1.000000, 0.000000) - mov r0.w, l(1.000000) + mad o0.xyz, v1.xyzx, l(1.500000, 1.500000, 1.500000, 0.000000), r0.xxxx + mov o0.w, v1.w + ret + case l(2) + sample r0.xyzw, v3.xyxx, t0.xyzw, s0 mul o0.xyzw, r0.xyzw, v1.xyzw ret -endif + default + mov o0.xyzw, l(1.000000,1.000000,1.000000,1.000000) + ret +endswitch ret -// Approximately 11 instruction slots used +// Approximately 18 instruction slots used #endif const BYTE g_PS[] = { - 68, 88, 66, 67, 107, 76, - 224, 17, 28, 251, 204, 245, - 251, 196, 251, 186, 76, 32, - 85, 255, 1, 0, 0, 0, - 0, 5, 0, 0, 6, 0, + 68, 88, 66, 67, 213, 23, + 25, 184, 195, 32, 116, 161, + 243, 184, 193, 77, 97, 102, + 85, 59, 1, 0, 0, 0, + 220, 5, 0, 0, 6, 0, 0, 0, 56, 0, 0, 0, - 48, 1, 0, 0, 100, 2, - 0, 0, 224, 2, 0, 0, - 64, 4, 0, 0, 204, 4, + 168, 1, 0, 0, 68, 3, + 0, 0, 192, 3, 0, 0, + 28, 5, 0, 0, 168, 5, 0, 0, 65, 111, 110, 57, - 240, 0, 0, 0, 240, 0, + 104, 1, 0, 0, 104, 1, 0, 0, 0, 2, 255, 255, - 188, 0, 0, 0, 52, 0, + 52, 1, 0, 0, 52, 0, 0, 0, 1, 0, 40, 0, 0, 0, 52, 0, 0, 0, 52, 0, 1, 0, 36, 0, @@ -118,9 +132,9 @@ const BYTE g_PS[] = 1, 0, 0, 0, 0, 0, 0, 3, 0, 2, 255, 255, 81, 0, 0, 5, 1, 0, - 15, 160, 0, 0, 128, 63, - 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, + 15, 160, 0, 0, 128, 191, + 0, 0, 192, 63, 0, 0, + 0, 192, 0, 0, 128, 63, 31, 0, 0, 2, 0, 0, 0, 128, 0, 0, 15, 176, 31, 0, 0, 2, 0, 0, @@ -131,25 +145,45 @@ const BYTE g_PS[] = 0, 144, 0, 8, 15, 160, 66, 0, 0, 3, 0, 0, 15, 128, 2, 0, 228, 176, - 0, 8, 228, 160, 8, 0, - 0, 3, 1, 0, 8, 128, - 1, 0, 228, 176, 0, 0, - 228, 160, 2, 0, 0, 3, - 1, 0, 7, 128, 1, 0, - 255, 128, 1, 0, 0, 160, - 1, 0, 0, 2, 1, 0, - 8, 128, 1, 0, 0, 160, - 5, 0, 0, 3, 1, 0, - 15, 128, 1, 0, 228, 128, + 0, 8, 228, 160, 1, 0, + 0, 2, 1, 0, 8, 128, + 0, 0, 255, 160, 2, 0, + 0, 3, 1, 0, 1, 128, + 1, 0, 255, 128, 1, 0, + 170, 160, 5, 0, 0, 3, + 1, 0, 1, 128, 1, 0, + 0, 128, 1, 0, 0, 128, + 5, 0, 0, 3, 0, 0, + 15, 128, 0, 0, 228, 128, 0, 0, 228, 176, 88, 0, 0, 4, 0, 0, 15, 128, - 0, 0, 255, 161, 1, 0, - 228, 128, 0, 0, 228, 128, + 1, 0, 0, 129, 0, 0, + 228, 128, 1, 0, 255, 160, + 2, 0, 0, 3, 1, 0, + 1, 128, 1, 0, 255, 128, + 1, 0, 0, 160, 5, 0, + 0, 3, 1, 0, 1, 128, + 1, 0, 0, 128, 1, 0, + 0, 128, 8, 0, 0, 3, + 1, 0, 2, 128, 1, 0, + 228, 176, 0, 0, 228, 160, + 4, 0, 0, 4, 2, 0, + 7, 128, 0, 0, 228, 176, + 1, 0, 85, 160, 1, 0, + 85, 128, 1, 0, 0, 2, + 2, 0, 8, 128, 0, 0, + 255, 176, 88, 0, 0, 4, + 0, 0, 15, 128, 1, 0, + 0, 129, 2, 0, 228, 128, + 0, 0, 228, 128, 88, 0, + 0, 4, 0, 0, 15, 128, + 0, 0, 255, 161, 0, 0, + 228, 176, 0, 0, 228, 128, 1, 0, 0, 2, 0, 8, 15, 128, 0, 0, 228, 128, 255, 255, 0, 0, 83, 72, - 68, 82, 44, 1, 0, 0, - 64, 0, 0, 0, 75, 0, + 68, 82, 148, 1, 0, 0, + 64, 0, 0, 0, 101, 0, 0, 0, 89, 0, 0, 4, 70, 142, 32, 0, 0, 0, 0, 0, 1, 0, 0, 0, @@ -167,148 +201,164 @@ const BYTE g_PS[] = 0, 3, 242, 32, 16, 0, 0, 0, 0, 0, 104, 0, 0, 2, 1, 0, 0, 0, - 31, 0, 4, 4, 58, 128, + 76, 0, 0, 4, 58, 128, 32, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 69, 0, - 0, 9, 242, 32, 16, 0, - 0, 0, 0, 0, 70, 16, - 16, 0, 3, 0, 0, 0, - 70, 126, 16, 0, 0, 0, - 0, 0, 0, 96, 16, 0, - 0, 0, 0, 0, 62, 0, - 0, 1, 18, 0, 0, 1, - 16, 0, 0, 8, 18, 0, - 16, 0, 0, 0, 0, 0, - 70, 18, 16, 0, 2, 0, - 0, 0, 70, 130, 32, 0, - 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 10, - 114, 0, 16, 0, 0, 0, - 0, 0, 6, 0, 16, 0, - 0, 0, 0, 0, 2, 64, - 0, 0, 0, 0, 128, 63, - 0, 0, 128, 63, 0, 0, - 128, 63, 0, 0, 0, 0, - 54, 0, 0, 5, 130, 0, - 16, 0, 0, 0, 0, 0, - 1, 64, 0, 0, 0, 0, - 128, 63, 56, 0, 0, 7, - 242, 32, 16, 0, 0, 0, - 0, 0, 70, 14, 16, 0, + 0, 0, 0, 0, 6, 0, + 0, 3, 1, 64, 0, 0, + 0, 0, 0, 0, 54, 0, + 0, 5, 242, 32, 16, 0, 0, 0, 0, 0, 70, 30, 16, 0, 1, 0, 0, 0, - 62, 0, 0, 1, 21, 0, - 0, 1, 62, 0, 0, 1, - 83, 84, 65, 84, 116, 0, - 0, 0, 11, 0, 0, 0, - 1, 0, 0, 0, 0, 0, - 0, 0, 4, 0, 0, 0, - 3, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, - 4, 0, 0, 0, 0, 0, + 62, 0, 0, 1, 6, 0, + 0, 3, 1, 64, 0, 0, + 1, 0, 0, 0, 16, 0, + 0, 8, 18, 0, 16, 0, + 0, 0, 0, 0, 70, 18, + 16, 0, 2, 0, 0, 0, + 70, 130, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 50, 0, 0, 12, 114, 32, + 16, 0, 0, 0, 0, 0, + 70, 18, 16, 0, 1, 0, + 0, 0, 2, 64, 0, 0, + 0, 0, 192, 63, 0, 0, + 192, 63, 0, 0, 192, 63, + 0, 0, 0, 0, 6, 0, + 16, 0, 0, 0, 0, 0, + 54, 0, 0, 5, 130, 32, + 16, 0, 0, 0, 0, 0, + 58, 16, 16, 0, 1, 0, + 0, 0, 62, 0, 0, 1, + 6, 0, 0, 3, 1, 64, + 0, 0, 2, 0, 0, 0, + 69, 0, 0, 9, 242, 0, + 16, 0, 0, 0, 0, 0, + 70, 16, 16, 0, 3, 0, + 0, 0, 70, 126, 16, 0, + 0, 0, 0, 0, 0, 96, + 16, 0, 0, 0, 0, 0, + 56, 0, 0, 7, 242, 32, + 16, 0, 0, 0, 0, 0, + 70, 14, 16, 0, 0, 0, + 0, 0, 70, 30, 16, 0, + 1, 0, 0, 0, 62, 0, + 0, 1, 10, 0, 0, 1, + 54, 0, 0, 8, 242, 32, + 16, 0, 0, 0, 0, 0, + 2, 64, 0, 0, 0, 0, + 128, 63, 0, 0, 128, 63, + 0, 0, 128, 63, 0, 0, + 128, 63, 62, 0, 0, 1, + 23, 0, 0, 1, 62, 0, + 0, 1, 83, 84, 65, 84, + 116, 0, 0, 0, 18, 0, + 0, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 4, 0, + 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 82, 68, - 69, 70, 88, 1, 0, 0, - 1, 0, 0, 0, 160, 0, - 0, 0, 3, 0, 0, 0, - 28, 0, 0, 0, 0, 4, - 255, 255, 0, 1, 0, 0, - 36, 1, 0, 0, 124, 0, - 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 82, 68, 69, 70, 84, 1, 0, 0, 1, 0, 0, 0, - 133, 0, 0, 0, 2, 0, - 0, 0, 5, 0, 0, 0, - 4, 0, 0, 0, 255, 255, - 255, 255, 0, 0, 0, 0, - 1, 0, 0, 0, 12, 0, - 0, 0, 142, 0, 0, 0, + 160, 0, 0, 0, 3, 0, + 0, 0, 28, 0, 0, 0, + 0, 4, 255, 255, 0, 1, + 0, 0, 32, 1, 0, 0, + 124, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 1, 0, + 0, 0, 133, 0, 0, 0, + 2, 0, 0, 0, 5, 0, + 0, 0, 4, 0, 0, 0, + 255, 255, 255, 255, 0, 0, 0, 0, 1, 0, 0, 0, - 0, 0, 0, 0, 115, 97, - 109, 112, 108, 101, 114, 48, - 0, 116, 101, 120, 116, 117, - 114, 101, 48, 0, 67, 111, - 110, 115, 116, 97, 110, 116, - 66, 117, 102, 102, 101, 114, - 0, 171, 171, 171, 142, 0, - 0, 0, 2, 0, 0, 0, - 184, 0, 0, 0, 16, 0, + 12, 0, 0, 0, 142, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 232, 0, 0, 0, 0, 0, 0, 0, - 12, 0, 0, 0, 2, 0, - 0, 0, 248, 0, 0, 0, - 0, 0, 0, 0, 8, 1, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 115, 97, 109, 112, 108, 101, + 114, 48, 0, 116, 101, 120, + 116, 117, 114, 101, 48, 0, + 67, 111, 110, 115, 116, 97, + 110, 116, 66, 117, 102, 102, + 101, 114, 0, 171, 171, 171, + 142, 0, 0, 0, 2, 0, + 0, 0, 184, 0, 0, 0, + 16, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 232, 0, 0, 0, 0, 0, 0, 0, 12, 0, 0, 0, - 4, 0, 0, 0, 2, 0, - 0, 0, 20, 1, 0, 0, - 0, 0, 0, 0, 108, 105, - 103, 104, 116, 95, 118, 101, - 99, 116, 111, 114, 0, 171, - 171, 171, 1, 0, 3, 0, - 1, 0, 3, 0, 0, 0, - 0, 0, 0, 0, 0, 0, - 116, 101, 120, 116, 117, 114, - 105, 110, 103, 0, 171, 171, - 0, 0, 19, 0, 1, 0, - 1, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 77, 105, - 99, 114, 111, 115, 111, 102, - 116, 32, 40, 82, 41, 32, - 72, 76, 83, 76, 32, 83, - 104, 97, 100, 101, 114, 32, - 67, 111, 109, 112, 105, 108, - 101, 114, 32, 54, 46, 51, - 46, 57, 54, 48, 48, 46, - 49, 54, 51, 56, 52, 0, - 171, 171, 73, 83, 71, 78, - 132, 0, 0, 0, 4, 0, - 0, 0, 8, 0, 0, 0, - 104, 0, 0, 0, 0, 0, + 2, 0, 0, 0, 248, 0, + 0, 0, 0, 0, 0, 0, + 8, 1, 0, 0, 12, 0, + 0, 0, 4, 0, 0, 0, + 2, 0, 0, 0, 16, 1, + 0, 0, 0, 0, 0, 0, + 108, 105, 103, 104, 116, 95, + 118, 101, 99, 116, 111, 114, + 0, 171, 171, 171, 1, 0, + 3, 0, 1, 0, 3, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 116, 121, 112, 101, + 0, 171, 171, 171, 0, 0, + 19, 0, 1, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 77, 105, 99, 114, + 111, 115, 111, 102, 116, 32, + 40, 82, 41, 32, 72, 76, + 83, 76, 32, 83, 104, 97, + 100, 101, 114, 32, 67, 111, + 109, 112, 105, 108, 101, 114, + 32, 54, 46, 51, 46, 57, + 54, 48, 48, 46, 49, 54, + 51, 56, 52, 0, 171, 171, + 73, 83, 71, 78, 132, 0, + 0, 0, 4, 0, 0, 0, + 8, 0, 0, 0, 104, 0, + 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 3, 0, + 0, 0, 0, 0, 0, 0, + 15, 0, 0, 0, 116, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, 0, 0, 1, 0, 0, 0, - 3, 0, 0, 0, 0, 0, - 0, 0, 15, 0, 0, 0, - 116, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, - 3, 0, 0, 0, 1, 0, - 0, 0, 15, 15, 0, 0, - 122, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, - 3, 0, 0, 0, 2, 0, - 0, 0, 7, 7, 0, 0, - 129, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, - 3, 0, 0, 0, 3, 0, - 0, 0, 3, 3, 0, 0, - 83, 86, 95, 80, 79, 83, - 73, 84, 73, 79, 78, 0, - 67, 79, 76, 79, 82, 0, - 78, 79, 82, 77, 65, 76, - 0, 85, 86, 0, 79, 83, - 71, 78, 44, 0, 0, 0, - 1, 0, 0, 0, 8, 0, - 0, 0, 32, 0, 0, 0, + 15, 15, 0, 0, 122, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 2, 0, 0, 0, + 7, 7, 0, 0, 129, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, 0, 0, 3, 0, 0, 0, - 0, 0, 0, 0, 15, 0, - 0, 0, 83, 86, 95, 84, - 97, 114, 103, 101, 116, 0, - 171, 171 + 3, 3, 0, 0, 83, 86, + 95, 80, 79, 83, 73, 84, + 73, 79, 78, 0, 67, 79, + 76, 79, 82, 0, 78, 79, + 82, 77, 65, 76, 0, 85, + 86, 0, 79, 83, 71, 78, + 44, 0, 0, 0, 1, 0, + 0, 0, 8, 0, 0, 0, + 32, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 0, 0, + 0, 0, 15, 0, 0, 0, + 83, 86, 95, 84, 97, 114, + 103, 101, 116, 0, 171, 171 }; diff --git a/source/YoloMouse/Loader/Overlay/Rendering/Shaders/Default/VertexShader.hlsl b/source/YoloMouse/Loader/Overlay/Rendering/Shaders/Default/VertexShader.hlsl index 0dfba98..5b4c46d 100644 --- a/source/YoloMouse/Loader/Overlay/Rendering/Shaders/Default/VertexShader.hlsl +++ b/source/YoloMouse/Loader/Overlay/Rendering/Shaders/Default/VertexShader.hlsl @@ -30,7 +30,7 @@ VS_OUTPUT VS(const VS_INPUT input) output.uv = input.uv; if( input.color.r == 0 && input.color.g == 0 && input.color.b == 0 ) - output.color = float4(variation_color.r, variation_color.g, variation_color.b, input.color.a); + output.color = float4(variation_color.r, variation_color.g, variation_color.b, input.color.a * variation_color.a); else output.color = input.color; diff --git a/source/YoloMouse/Loader/Overlay/Rendering/Shaders/Default/VertexShader.hpp b/source/YoloMouse/Loader/Overlay/Rendering/Shaders/Default/VertexShader.hpp index 3e75312..0aa3bfd 100644 --- a/source/YoloMouse/Loader/Overlay/Rendering/Shaders/Default/VertexShader.hpp +++ b/source/YoloMouse/Loader/Overlay/Rendering/Shaders/Default/VertexShader.hpp @@ -75,14 +75,14 @@ sge r1.xyz, -r1, r1 mul r1.x, r1.y, r1.x mul r1.x, r1.z, r1.x - add r1.yzw, -v1.xxyz, c9.xxyz - mad oT0.xyz, r1.x, r1.yzww, v1 + add r2.xyz, -v1, c9 + mad r2.w, v1.w, c9.w, -v1.w + mad oT0, r1.x, r2, v1 dp4 r1.x, r0, c1 dp4 r1.y, r0, c2 dp4 r0.x, r0, c4 mad oPos.xy, r0.x, c0, r1 mov oPos.w, r0.x - mov oT0.w, v1.w mov oT2.xy, v3 // approximately 19 instruction slots used @@ -106,32 +106,33 @@ dp4 o0.w, r0.xyzw, cb0[3].xyzw eq r0.xyz, v1.xyzx, l(0.000000, 0.000000, 0.000000, 0.000000) and r0.x, r0.y, r0.x and r0.x, r0.z, r0.x +mul r0.y, v1.w, cb0[8].w +movc o1.w, r0.x, r0.y, v1.w movc o1.xyz, r0.xxxx, cb0[8].xyzx, v1.xyzx -mov o1.w, v1.w mul r0.xyz, v2.yyyy, cb0[5].xyzx mad r0.xyz, cb0[4].xyzx, v2.xxxx, r0.xyzx mad r0.xyz, cb0[6].xyzx, v2.zzzz, r0.xyzx add o2.xyz, r0.xyzx, cb0[7].xyzx mov o3.xy, v3.xyxx ret -// Approximately 17 instruction slots used +// Approximately 18 instruction slots used #endif const BYTE g_VS[] = { - 68, 88, 66, 67, 170, 48, - 204, 247, 105, 149, 212, 249, - 69, 97, 193, 114, 12, 178, - 73, 171, 1, 0, 0, 0, - 44, 7, 0, 0, 6, 0, + 68, 88, 66, 67, 111, 101, + 246, 203, 190, 19, 24, 216, + 1, 109, 228, 46, 113, 92, + 9, 22, 1, 0, 0, 0, + 100, 7, 0, 0, 6, 0, 0, 0, 56, 0, 0, 0, - 252, 1, 0, 0, 116, 4, - 0, 0, 240, 4, 0, 0, - 20, 6, 0, 0, 160, 6, + 4, 2, 0, 0, 172, 4, + 0, 0, 40, 5, 0, 0, + 76, 6, 0, 0, 216, 6, 0, 0, 65, 111, 110, 57, - 188, 1, 0, 0, 188, 1, + 196, 1, 0, 0, 196, 1, 0, 0, 0, 2, 254, 255, - 136, 1, 0, 0, 52, 0, + 144, 1, 0, 0, 52, 0, 0, 0, 1, 0, 36, 0, 0, 0, 48, 0, 0, 0, 48, 0, 0, 0, 36, 0, @@ -180,142 +181,151 @@ const BYTE g_VS[] = 5, 0, 0, 3, 1, 0, 1, 128, 1, 0, 170, 128, 1, 0, 0, 128, 2, 0, - 0, 3, 1, 0, 14, 128, - 1, 0, 144, 145, 9, 0, - 144, 160, 4, 0, 0, 4, - 0, 0, 7, 224, 1, 0, - 0, 128, 1, 0, 249, 128, - 1, 0, 228, 144, 9, 0, - 0, 3, 1, 0, 1, 128, - 0, 0, 228, 128, 1, 0, - 228, 160, 9, 0, 0, 3, - 1, 0, 2, 128, 0, 0, - 228, 128, 2, 0, 228, 160, - 9, 0, 0, 3, 0, 0, + 0, 3, 2, 0, 7, 128, + 1, 0, 228, 145, 9, 0, + 228, 160, 4, 0, 0, 4, + 2, 0, 8, 128, 1, 0, + 255, 144, 9, 0, 255, 160, + 1, 0, 255, 145, 4, 0, + 0, 4, 0, 0, 15, 224, + 1, 0, 0, 128, 2, 0, + 228, 128, 1, 0, 228, 144, + 9, 0, 0, 3, 1, 0, 1, 128, 0, 0, 228, 128, - 4, 0, 228, 160, 4, 0, - 0, 4, 0, 0, 3, 192, - 0, 0, 0, 128, 0, 0, - 228, 160, 1, 0, 228, 128, - 1, 0, 0, 2, 0, 0, - 8, 192, 0, 0, 0, 128, - 1, 0, 0, 2, 0, 0, - 8, 224, 1, 0, 255, 144, - 1, 0, 0, 2, 2, 0, - 3, 224, 3, 0, 228, 144, - 255, 255, 0, 0, 83, 72, - 68, 82, 112, 2, 0, 0, - 64, 0, 1, 0, 156, 0, - 0, 0, 89, 0, 0, 4, - 70, 142, 32, 0, 0, 0, - 0, 0, 9, 0, 0, 0, - 95, 0, 0, 3, 114, 16, - 16, 0, 0, 0, 0, 0, - 95, 0, 0, 3, 242, 16, + 1, 0, 228, 160, 9, 0, + 0, 3, 1, 0, 2, 128, + 0, 0, 228, 128, 2, 0, + 228, 160, 9, 0, 0, 3, + 0, 0, 1, 128, 0, 0, + 228, 128, 4, 0, 228, 160, + 4, 0, 0, 4, 0, 0, + 3, 192, 0, 0, 0, 128, + 0, 0, 228, 160, 1, 0, + 228, 128, 1, 0, 0, 2, + 0, 0, 8, 192, 0, 0, + 0, 128, 1, 0, 0, 2, + 2, 0, 3, 224, 3, 0, + 228, 144, 255, 255, 0, 0, + 83, 72, 68, 82, 160, 2, + 0, 0, 64, 0, 1, 0, + 168, 0, 0, 0, 89, 0, + 0, 4, 70, 142, 32, 0, + 0, 0, 0, 0, 9, 0, + 0, 0, 95, 0, 0, 3, + 114, 16, 16, 0, 0, 0, + 0, 0, 95, 0, 0, 3, + 242, 16, 16, 0, 1, 0, + 0, 0, 95, 0, 0, 3, + 114, 16, 16, 0, 2, 0, + 0, 0, 95, 0, 0, 3, + 50, 16, 16, 0, 3, 0, + 0, 0, 103, 0, 0, 4, + 242, 32, 16, 0, 0, 0, + 0, 0, 1, 0, 0, 0, + 101, 0, 0, 3, 242, 32, 16, 0, 1, 0, 0, 0, - 95, 0, 0, 3, 114, 16, + 101, 0, 0, 3, 114, 32, 16, 0, 2, 0, 0, 0, - 95, 0, 0, 3, 50, 16, + 101, 0, 0, 3, 50, 32, 16, 0, 3, 0, 0, 0, - 103, 0, 0, 4, 242, 32, - 16, 0, 0, 0, 0, 0, - 1, 0, 0, 0, 101, 0, - 0, 3, 242, 32, 16, 0, - 1, 0, 0, 0, 101, 0, - 0, 3, 114, 32, 16, 0, - 2, 0, 0, 0, 101, 0, - 0, 3, 50, 32, 16, 0, - 3, 0, 0, 0, 104, 0, - 0, 2, 1, 0, 0, 0, - 54, 0, 0, 5, 114, 0, - 16, 0, 0, 0, 0, 0, - 70, 18, 16, 0, 0, 0, + 104, 0, 0, 2, 1, 0, 0, 0, 54, 0, 0, 5, - 130, 0, 16, 0, 0, 0, - 0, 0, 1, 64, 0, 0, - 0, 0, 128, 63, 17, 0, - 0, 8, 18, 32, 16, 0, - 0, 0, 0, 0, 70, 14, - 16, 0, 0, 0, 0, 0, - 70, 142, 32, 0, 0, 0, - 0, 0, 0, 0, 0, 0, - 17, 0, 0, 8, 34, 32, + 114, 0, 16, 0, 0, 0, + 0, 0, 70, 18, 16, 0, + 0, 0, 0, 0, 54, 0, + 0, 5, 130, 0, 16, 0, + 0, 0, 0, 0, 1, 64, + 0, 0, 0, 0, 128, 63, + 17, 0, 0, 8, 18, 32, 16, 0, 0, 0, 0, 0, 70, 14, 16, 0, 0, 0, 0, 0, 70, 142, 32, 0, - 0, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 17, 0, 0, 8, - 66, 32, 16, 0, 0, 0, + 34, 32, 16, 0, 0, 0, 0, 0, 70, 14, 16, 0, 0, 0, 0, 0, 70, 142, 32, 0, 0, 0, 0, 0, - 2, 0, 0, 0, 17, 0, - 0, 8, 130, 32, 16, 0, + 1, 0, 0, 0, 17, 0, + 0, 8, 66, 32, 16, 0, 0, 0, 0, 0, 70, 14, 16, 0, 0, 0, 0, 0, 70, 142, 32, 0, 0, 0, - 0, 0, 3, 0, 0, 0, - 24, 0, 0, 10, 114, 0, + 0, 0, 2, 0, 0, 0, + 17, 0, 0, 8, 130, 32, 16, 0, 0, 0, 0, 0, - 70, 18, 16, 0, 1, 0, - 0, 0, 2, 64, 0, 0, + 70, 14, 16, 0, 0, 0, + 0, 0, 70, 142, 32, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 24, 0, 0, 10, + 114, 0, 16, 0, 0, 0, + 0, 0, 70, 18, 16, 0, + 1, 0, 0, 0, 2, 64, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 1, 0, 0, 7, 18, 0, + 16, 0, 0, 0, 0, 0, + 26, 0, 16, 0, 0, 0, + 0, 0, 10, 0, 16, 0, 0, 0, 0, 0, 1, 0, 0, 7, 18, 0, 16, 0, - 0, 0, 0, 0, 26, 0, + 0, 0, 0, 0, 42, 0, 16, 0, 0, 0, 0, 0, 10, 0, 16, 0, 0, 0, - 0, 0, 1, 0, 0, 7, - 18, 0, 16, 0, 0, 0, - 0, 0, 42, 0, 16, 0, - 0, 0, 0, 0, 10, 0, + 0, 0, 56, 0, 0, 8, + 34, 0, 16, 0, 0, 0, + 0, 0, 58, 16, 16, 0, + 1, 0, 0, 0, 58, 128, + 32, 0, 0, 0, 0, 0, + 8, 0, 0, 0, 55, 0, + 0, 9, 130, 32, 16, 0, + 1, 0, 0, 0, 10, 0, 16, 0, 0, 0, 0, 0, - 55, 0, 0, 10, 114, 32, - 16, 0, 1, 0, 0, 0, - 6, 0, 16, 0, 0, 0, - 0, 0, 70, 130, 32, 0, - 0, 0, 0, 0, 8, 0, - 0, 0, 70, 18, 16, 0, - 1, 0, 0, 0, 54, 0, - 0, 5, 130, 32, 16, 0, - 1, 0, 0, 0, 58, 16, - 16, 0, 1, 0, 0, 0, - 56, 0, 0, 8, 114, 0, + 26, 0, 16, 0, 0, 0, + 0, 0, 58, 16, 16, 0, + 1, 0, 0, 0, 55, 0, + 0, 10, 114, 32, 16, 0, + 1, 0, 0, 0, 6, 0, 16, 0, 0, 0, 0, 0, - 86, 21, 16, 0, 2, 0, - 0, 0, 70, 130, 32, 0, - 0, 0, 0, 0, 5, 0, + 70, 130, 32, 0, 0, 0, + 0, 0, 8, 0, 0, 0, + 70, 18, 16, 0, 1, 0, + 0, 0, 56, 0, 0, 8, + 114, 0, 16, 0, 0, 0, + 0, 0, 86, 21, 16, 0, + 2, 0, 0, 0, 70, 130, + 32, 0, 0, 0, 0, 0, + 5, 0, 0, 0, 50, 0, + 0, 10, 114, 0, 16, 0, + 0, 0, 0, 0, 70, 130, + 32, 0, 0, 0, 0, 0, + 4, 0, 0, 0, 6, 16, + 16, 0, 2, 0, 0, 0, + 70, 2, 16, 0, 0, 0, 0, 0, 50, 0, 0, 10, 114, 0, 16, 0, 0, 0, 0, 0, 70, 130, 32, 0, - 0, 0, 0, 0, 4, 0, - 0, 0, 6, 16, 16, 0, - 2, 0, 0, 0, 70, 2, - 16, 0, 0, 0, 0, 0, - 50, 0, 0, 10, 114, 0, - 16, 0, 0, 0, 0, 0, - 70, 130, 32, 0, 0, 0, - 0, 0, 6, 0, 0, 0, - 166, 26, 16, 0, 2, 0, - 0, 0, 70, 2, 16, 0, - 0, 0, 0, 0, 0, 0, - 0, 8, 114, 32, 16, 0, + 0, 0, 0, 0, 6, 0, + 0, 0, 166, 26, 16, 0, 2, 0, 0, 0, 70, 2, 16, 0, 0, 0, 0, 0, - 70, 130, 32, 0, 0, 0, - 0, 0, 7, 0, 0, 0, - 54, 0, 0, 5, 50, 32, - 16, 0, 3, 0, 0, 0, - 70, 16, 16, 0, 3, 0, - 0, 0, 62, 0, 0, 1, - 83, 84, 65, 84, 116, 0, - 0, 0, 17, 0, 0, 0, - 1, 0, 0, 0, 0, 0, - 0, 0, 8, 0, 0, 0, - 9, 0, 0, 0, 0, 0, - 0, 0, 2, 0, 0, 0, - 1, 0, 0, 0, 0, 0, + 0, 0, 0, 8, 114, 32, + 16, 0, 2, 0, 0, 0, + 70, 2, 16, 0, 0, 0, + 0, 0, 70, 130, 32, 0, + 0, 0, 0, 0, 7, 0, + 0, 0, 54, 0, 0, 5, + 50, 32, 16, 0, 3, 0, + 0, 0, 70, 16, 16, 0, + 3, 0, 0, 0, 62, 0, + 0, 1, 83, 84, 65, 84, + 116, 0, 0, 0, 18, 0, + 0, 0, 1, 0, 0, 0, + 0, 0, 0, 0, 8, 0, + 0, 0, 10, 0, 0, 0, + 0, 0, 0, 0, 2, 0, + 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -323,106 +333,107 @@ const BYTE g_VS[] = 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 4, 0, 0, 0, 1, 0, + 0, 0, 3, 0, 0, 0, + 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 82, 68, - 69, 70, 28, 1, 0, 0, - 1, 0, 0, 0, 76, 0, + 82, 68, 69, 70, 28, 1, 0, 0, 1, 0, 0, 0, - 28, 0, 0, 0, 0, 4, - 254, 255, 0, 1, 0, 0, - 232, 0, 0, 0, 60, 0, - 0, 0, 0, 0, 0, 0, + 76, 0, 0, 0, 1, 0, + 0, 0, 28, 0, 0, 0, + 0, 4, 254, 255, 0, 1, + 0, 0, 232, 0, 0, 0, + 60, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 1, 0, - 0, 0, 0, 0, 0, 0, - 67, 111, 110, 115, 116, 97, - 110, 116, 66, 117, 102, 102, - 101, 114, 0, 171, 60, 0, - 0, 0, 3, 0, 0, 0, - 100, 0, 0, 0, 144, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 172, 0, + 1, 0, 0, 0, 0, 0, + 0, 0, 67, 111, 110, 115, + 116, 97, 110, 116, 66, 117, + 102, 102, 101, 114, 0, 171, + 60, 0, 0, 0, 3, 0, + 0, 0, 100, 0, 0, 0, + 144, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 172, 0, 0, 0, 0, 0, + 0, 0, 64, 0, 0, 0, + 2, 0, 0, 0, 176, 0, 0, 0, 0, 0, 0, 0, - 64, 0, 0, 0, 2, 0, - 0, 0, 176, 0, 0, 0, - 0, 0, 0, 0, 192, 0, + 192, 0, 0, 0, 64, 0, 0, 0, 64, 0, 0, 0, - 64, 0, 0, 0, 2, 0, - 0, 0, 176, 0, 0, 0, - 0, 0, 0, 0, 198, 0, - 0, 0, 128, 0, 0, 0, - 16, 0, 0, 0, 2, 0, - 0, 0, 216, 0, 0, 0, - 0, 0, 0, 0, 109, 118, - 112, 0, 3, 0, 3, 0, - 4, 0, 4, 0, 0, 0, - 0, 0, 0, 0, 0, 0, - 109, 111, 100, 101, 108, 0, - 118, 97, 114, 105, 97, 116, - 105, 111, 110, 95, 99, 111, - 108, 111, 114, 0, 171, 171, - 1, 0, 3, 0, 1, 0, - 4, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 77, 105, - 99, 114, 111, 115, 111, 102, - 116, 32, 40, 82, 41, 32, - 72, 76, 83, 76, 32, 83, - 104, 97, 100, 101, 114, 32, - 67, 111, 109, 112, 105, 108, - 101, 114, 32, 54, 46, 51, - 46, 57, 54, 48, 48, 46, - 49, 54, 51, 56, 52, 0, - 171, 171, 73, 83, 71, 78, - 132, 0, 0, 0, 4, 0, - 0, 0, 8, 0, 0, 0, - 104, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, - 3, 0, 0, 0, 0, 0, - 0, 0, 7, 7, 0, 0, - 113, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, - 3, 0, 0, 0, 1, 0, - 0, 0, 15, 15, 0, 0, - 119, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, - 3, 0, 0, 0, 2, 0, - 0, 0, 7, 7, 0, 0, - 126, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, - 3, 0, 0, 0, 3, 0, - 0, 0, 3, 3, 0, 0, - 80, 79, 83, 73, 84, 73, - 79, 78, 0, 67, 79, 76, - 79, 82, 0, 78, 79, 82, - 77, 65, 76, 0, 85, 86, - 0, 171, 171, 171, 79, 83, + 2, 0, 0, 0, 176, 0, + 0, 0, 0, 0, 0, 0, + 198, 0, 0, 0, 128, 0, + 0, 0, 16, 0, 0, 0, + 2, 0, 0, 0, 216, 0, + 0, 0, 0, 0, 0, 0, + 109, 118, 112, 0, 3, 0, + 3, 0, 4, 0, 4, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 109, 111, 100, 101, + 108, 0, 118, 97, 114, 105, + 97, 116, 105, 111, 110, 95, + 99, 111, 108, 111, 114, 0, + 171, 171, 1, 0, 3, 0, + 1, 0, 4, 0, 0, 0, + 0, 0, 0, 0, 0, 0, + 77, 105, 99, 114, 111, 115, + 111, 102, 116, 32, 40, 82, + 41, 32, 72, 76, 83, 76, + 32, 83, 104, 97, 100, 101, + 114, 32, 67, 111, 109, 112, + 105, 108, 101, 114, 32, 54, + 46, 51, 46, 57, 54, 48, + 48, 46, 49, 54, 51, 56, + 52, 0, 171, 171, 73, 83, 71, 78, 132, 0, 0, 0, 4, 0, 0, 0, 8, 0, 0, 0, 104, 0, 0, 0, - 0, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 3, 0, 0, 0, + 0, 0, 0, 0, 7, 7, + 0, 0, 113, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, - 0, 0, 0, 0, 15, 0, - 0, 0, 116, 0, 0, 0, + 1, 0, 0, 0, 15, 15, + 0, 0, 119, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, - 1, 0, 0, 0, 15, 0, - 0, 0, 122, 0, 0, 0, + 2, 0, 0, 0, 7, 7, + 0, 0, 126, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, - 2, 0, 0, 0, 7, 8, - 0, 0, 129, 0, 0, 0, + 3, 0, 0, 0, 3, 3, + 0, 0, 80, 79, 83, 73, + 84, 73, 79, 78, 0, 67, + 79, 76, 79, 82, 0, 78, + 79, 82, 77, 65, 76, 0, + 85, 86, 0, 171, 171, 171, + 79, 83, 71, 78, 132, 0, + 0, 0, 4, 0, 0, 0, + 8, 0, 0, 0, 104, 0, + 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 3, 0, + 0, 0, 0, 0, 0, 0, + 15, 0, 0, 0, 116, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 1, 0, 0, 0, + 15, 0, 0, 0, 122, 0, + 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, + 0, 0, 2, 0, 0, 0, + 7, 8, 0, 0, 129, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 3, 0, 0, 0, 3, 0, 0, 0, - 3, 0, 0, 0, 3, 12, - 0, 0, 83, 86, 95, 80, - 79, 83, 73, 84, 73, 79, - 78, 0, 67, 79, 76, 79, - 82, 0, 78, 79, 82, 77, - 65, 76, 0, 85, 86, 0 + 3, 12, 0, 0, 83, 86, + 95, 80, 79, 83, 73, 84, + 73, 79, 78, 0, 67, 79, + 76, 79, 82, 0, 78, 79, + 82, 77, 65, 76, 0, 85, + 86, 0 }; diff --git a/source/YoloMouse/Loader/Overlay/Rendering/Shaders/ShaderTypes.hpp b/source/YoloMouse/Loader/Overlay/Rendering/Shaders/ShaderTypes.hpp index d543721..5b8e386 100644 --- a/source/YoloMouse/Loader/Overlay/Rendering/Shaders/ShaderTypes.hpp +++ b/source/YoloMouse/Loader/Overlay/Rendering/Shaders/ShaderTypes.hpp @@ -7,6 +7,15 @@ namespace Yolomouse { + // enum + // TODO3: convert to flags + enum PixelShaderType : Byte4 + { + PIXELSHADERTYPE_UNLIT_BASIC = 0, + PIXELSHADERTYPE_LIT_BASIC = 1, + PIXELSHADERTYPE_UNLIT_TEXTURE = 2, + }; + // types struct ShaderVertex { @@ -18,14 +27,14 @@ namespace Yolomouse struct VertexShaderConstantValue { - Matrix4f mvp = Matrix4f::IDENTITY(); - Matrix4f model = Matrix4f::IDENTITY(); - Vector4f variation_color = Vector4f(1,1,1,1); + Matrix4f mvp; + Matrix4f model; + Vector4f variation_color; }; struct PixelShaderConstantValue { - Vector3f light_vector = Vector3f(0,0,1); - Byte4 texturing = false; + Vector3f light_vector; + PixelShaderType type; }; } diff --git a/source/YoloMouse/Loader/Overlay/Rendering/Support/RenderTimingController.cpp b/source/YoloMouse/Loader/Overlay/Rendering/Support/RenderTimingController.cpp index c5e9381..8972b7b 100644 --- a/source/YoloMouse/Loader/Overlay/Rendering/Support/RenderTimingController.cpp +++ b/source/YoloMouse/Loader/Overlay/Rendering/Support/RenderTimingController.cpp @@ -4,12 +4,24 @@ namespace Yolomouse { + // local + //------------------------------------------------------------------------- + namespace + { + // constants + //--------------------------------------------------------------------- + static constexpr Float DEFAULT_REFRESH_RATE = 59.94f; // hz + static constexpr Float RENDER_TIME_INITIAL = 0.002f; // sec. initial render time + static constexpr Float RENDER_TIME_INCREMENT = 0.0012f; // sec. time to increase render time by during detected lag + static constexpr Float RENDER_TIME_RECOVER = 0.000001f; // sec. time to decrease render time by each frame. + static constexpr Float RENDER_TIME_LIMIT = 0.5f; // as factor of refresh rate + } + // public //------------------------------------------------------------------------- RenderTimingController::RenderTimingController(): _dxgi_output (nullptr), - _resolution (0, 0), - _tick_frequency (0), + _option_fill_time (false), _refresh_time (0), _render_time (RENDER_TIME_INITIAL), _frameskip_threshold(0), @@ -25,18 +37,15 @@ namespace Yolomouse } //------------------------------------------------------------------------- - void RenderTimingController::Initialize( IDXGIOutput& dxgi_output ) + void RenderTimingController::Initialize( IDXGIOutput& dxgi_output, const Vector2l& resolution ) { ASSERT( !IsInitialized() ); // set fields _dxgi_output = &dxgi_output; - // get tick frequency - _tick_frequency = SystemTools::GetTickFrequency(); - // calculate refresh rate - _CalculateRefreshRate(); + _CalculateRefreshRate(resolution); // update fill time _UpdateFillTime(); @@ -66,9 +75,9 @@ namespace Yolomouse } //------------------------------------------------------------------------- - void RenderTimingController::SetResolution( const Vector2l& resolution ) + void RenderTimingController::SetFillTime( Bool enabled ) { - _resolution = resolution; + _option_fill_time = enabled; } //------------------------------------------------------------------------- @@ -76,8 +85,12 @@ namespace Yolomouse { ASSERT( IsInitialized() ); - // sleep fill time (estimated render time - refresh time) - Sleep( _fill_time ); + // if fill time option enabled + if( _option_fill_time ) + { + // sleep fill time (estimated render time - refresh time) + Sleep( _fill_time ); + } } void RenderTimingController::End() @@ -88,20 +101,24 @@ namespace Yolomouse UHuge current_ticks = SystemTools::GetTickTime(); // calculate frame time - _frame_time = _TicksToSeconds(current_ticks - _begin_ticks); + _frame_time = SystemTools::GetTicksToSeconds(current_ticks - _begin_ticks); // update begin ticks _begin_ticks = current_ticks; - // if we're skipping frames, increase render time estimate. limit to half refresh time - if( _frame_time > _frameskip_threshold ) - _render_time = Tools::Min( _render_time + RENDER_TIME_INCREMENT, _refresh_time * 0.5f ); - // else decrease render time estimate a little. limit to initial render time - else - _render_time = Tools::Max( _render_time - RENDER_TIME_RECOVER, RENDER_TIME_INITIAL ); - - // update fill time - _UpdateFillTime(); + // if fill time option enabled + if( _option_fill_time ) + { + // if we're skipping frames, increase render time estimate. limit to half refresh time + if( _frame_time > _frameskip_threshold ) + _render_time = Tools::Min( _render_time + RENDER_TIME_INCREMENT, _refresh_time * RENDER_TIME_LIMIT ); + // else decrease render time estimate a little. limit to initial render time + else + _render_time = Tools::Max( _render_time - RENDER_TIME_RECOVER, RENDER_TIME_INITIAL ); + + // update fill time + _UpdateFillTime(); + } // log LOG3( "RenderTimingController.FrameTime FRAME:%f FILL:%u", _frame_time, _fill_time ); @@ -114,7 +131,7 @@ namespace Yolomouse _fill_time = static_cast((_refresh_time - _render_time) * 1000.0f); } - void RenderTimingController::_CalculateRefreshRate() + void RenderTimingController::_CalculateRefreshRate( const Vector2l& resolution ) { UINT num_modes = 0; @@ -139,8 +156,8 @@ namespace Yolomouse // calculate resolution nearness score ULong score = Math::Absolute( - (static_cast(mode.Width) - _resolution.x) + - (static_cast(mode.Height) - _resolution.y)); + (static_cast(mode.Width) - resolution.x) + + (static_cast(mode.Height) - resolution.y)); // if better than best, update best score and mode if( score < best_score ) @@ -162,10 +179,4 @@ namespace Yolomouse // update frameskip threshold _frameskip_threshold = _refresh_time * 1.5f; } - - Float RenderTimingController::_TicksToSeconds( UHuge ticks ) - { - // calculate frame time - return static_cast((ticks * 1000000) / _tick_frequency) / 1000000.0f; - } } diff --git a/source/YoloMouse/Loader/Overlay/Rendering/Support/RenderTimingController.hpp b/source/YoloMouse/Loader/Overlay/Rendering/Support/RenderTimingController.hpp index a839991..a99c6e8 100644 --- a/source/YoloMouse/Loader/Overlay/Rendering/Support/RenderTimingController.hpp +++ b/source/YoloMouse/Loader/Overlay/Rendering/Support/RenderTimingController.hpp @@ -19,7 +19,7 @@ namespace Yolomouse ~RenderTimingController(); /**/ - void Initialize( IDXGIOutput& dxgi_output ); + void Initialize( IDXGIOutput& dxgi_output, const Vector2l& resolution ); void Shutdown(); /**/ @@ -29,29 +29,21 @@ namespace Yolomouse Float GetFrameTime() const; // sec /**/ - void SetResolution( const Vector2l& resolution ); + void SetFillTime( Bool enabled ); /**/ void Begin(); void End(); private: - // constants - static constexpr Float DEFAULT_REFRESH_RATE = 59.94f; // hz - static constexpr Float RENDER_TIME_INITIAL = 0.002f; // sec. initial render time - static constexpr Float RENDER_TIME_INCREMENT = 0.0012f; // sec. time to increase render time by during detected lag - static constexpr Float RENDER_TIME_RECOVER = 0.000001f; // sec. time to decrease render time by each frame. - /**/ void _UpdateFillTime(); - void _CalculateRefreshRate(); - Float _TicksToSeconds( UHuge ticks ); + void _CalculateRefreshRate( const Vector2l& resolution ); // fields: parameters IDXGIOutput* _dxgi_output; - Vector2l _resolution; + Bool _option_fill_time; // fields: info - UHuge _tick_frequency; Float _refresh_time; Float _frameskip_threshold; // fields: state diff --git a/source/YoloMouse/Loader/Overlay/Rendering/Support/RenderTools.cpp b/source/YoloMouse/Loader/Overlay/Rendering/Support/RenderTools.cpp new file mode 100644 index 0000000..242f5d7 --- /dev/null +++ b/source/YoloMouse/Loader/Overlay/Rendering/Support/RenderTools.cpp @@ -0,0 +1,21 @@ +#include + +namespace Yolomouse +{ + // public + //------------------------------------------------------------------------- + void RenderTools::BuildOrthoProjectionMatrix( Matrix4f& matrix, Float aspect_ratio ) + { + // calculate x,y cells. scale to NDC (normalized device coordinates) + Float xx = 2.0f / aspect_ratio; + Float yy = 2.0f; + + // update projection matrix + matrix.Set( + xx, 0, 0, 0, + 0, -yy, 0, 0, + 0, 0, 1, 0, + 0, 0, 0, 1 + ); + } +} diff --git a/source/YoloMouse/Loader/Overlay/Rendering/Support/RenderTools.hpp b/source/YoloMouse/Loader/Overlay/Rendering/Support/RenderTools.hpp new file mode 100644 index 0000000..6e63c5a --- /dev/null +++ b/source/YoloMouse/Loader/Overlay/Rendering/Support/RenderTools.hpp @@ -0,0 +1,13 @@ +#pragma once +#include +#include + +namespace Yolomouse +{ + /**/ + struct RenderTools + { + /**/ + static void BuildOrthoProjectionMatrix( Matrix4f& matrix, Float aspect_ratio ); + }; +} \ No newline at end of file diff --git a/source/YoloMouse/Loader/Overlay/Rendering/Types.hpp b/source/YoloMouse/Loader/Overlay/Rendering/Types.hpp index a77b7ce..d411cab 100644 --- a/source/YoloMouse/Loader/Overlay/Rendering/Types.hpp +++ b/source/YoloMouse/Loader/Overlay/Rendering/Types.hpp @@ -1,9 +1,9 @@ #pragma once #include -#include +#include namespace Yolomouse { // types - typedef Tuple Index3; + typedef Vector3u Index3; } diff --git a/source/YoloMouse/Loader/Overlay/Text/FontAtlas.cpp b/source/YoloMouse/Loader/Overlay/Text/FontAtlas.cpp new file mode 100644 index 0000000..f96a2b7 --- /dev/null +++ b/source/YoloMouse/Loader/Overlay/Text/FontAtlas.cpp @@ -0,0 +1,137 @@ +//TODO5: SDF support +#include +#include +#include + +namespace Yolomouse +{ + // local + //------------------------------------------------------------------------- + namespace + { + // constants + //--------------------------------------------------------------------- + static constexpr ULong MAP_SIZE = 512; // must be power of 2 or the universe will implode + static constexpr Float FONT_SIZE = 64.0f; + static constexpr Char CHARACTERS[] = " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.,-=+[]"; + } + + // public + //------------------------------------------------------------------------- + FontAtlas::FontAtlas(): + _render_context (nullptr) + { + } + + FontAtlas::~FontAtlas() + { + ASSERT( !IsInitialized() ); + } + + //------------------------------------------------------------------------- + Bool FontAtlas::Initialize( RenderContext& render_context, const WChar* font_name ) + { + ASSERT( !IsInitialized() ); + FontMapBuilder font_map_builder; + Bool status = false; + + // set fields + _render_context = &render_context; + + // initialize font map builder + if( font_map_builder.Initialize( font_name, FONT_SIZE, MAP_SIZE ) ) + { + Vector2f offset( 1, 1 ); + Float row_height = 0; + Float fmap_size = static_cast( MAP_SIZE ); + + // for each character + for( const Char* character = CHARACTERS; *character; ++character ) + { + // get glyph entry + Glyph& glyph = _glyphs[*character]; + + // get character sizing + if( font_map_builder.GetCharacterSize( glyph.size, *character ) ) + { + // update row height + row_height = Tools::Max( row_height, glyph.size.y ); + + // if offset over map size + if( ( offset.x + glyph.size.x ) > fmap_size ) + { + // reset x offset to 1 (instead of 0 to avoid overlap) + offset.x = 1; + + // update y offset + padding to avoid overlap + offset.y += row_height + 1; + + // reset row height + row_height = 0; + } + + // write character to map and get its size + if( font_map_builder.WriteCharacter( offset, *character ) ) + { + // update glyph entry + glyph.active = true; + glyph.offset = offset; + glyph.uv_min = offset / fmap_size; + glyph.uv_max = (offset + glyph.size) / fmap_size; + + // update x offset + padding to avoid overlap + offset.x += glyph.size.x + 4; + } + } + } + + // build directx map + if( font_map_builder.ToDxMap( _texture, *_render_context ) ) + status = true; + + // shutdown builder + font_map_builder.Shutdown(); + } + + return status; + + return true; + } + + void FontAtlas::Shutdown() + { + ASSERT( IsInitialized() ); + + // shutdown texture + _texture.Shutdown(); + + // reset fields + _render_context = nullptr; + } + + //------------------------------------------------------------------------- + Bool FontAtlas::IsInitialized() const + { + return _render_context != nullptr; + } + + //------------------------------------------------------------------------- + const FontAtlas::Glyph* FontAtlas::GetGlyph( Char character ) const + { + ASSERT( character >= 0 && character < 0x80 ); + + // get glyph + const Glyph& glyph = _glyphs[character]; + + // if active + if( glyph.active ) + return &glyph; + + return nullptr; + } + + const Texture& FontAtlas::GetTexture() const + { + return _texture; + } +} diff --git a/source/YoloMouse/Loader/Overlay/Text/FontAtlas.hpp b/source/YoloMouse/Loader/Overlay/Text/FontAtlas.hpp new file mode 100644 index 0000000..c533f70 --- /dev/null +++ b/source/YoloMouse/Loader/Overlay/Text/FontAtlas.hpp @@ -0,0 +1,45 @@ +#pragma once +#include +#include + +namespace Yolomouse +{ + /**/ + class FontAtlas + { + public: + // types + struct Glyph + { + Bool active = false; + Vector2f offset; + Vector2f size; + Vector2f uv_min; + Vector2f uv_max; + }; + + /**/ + FontAtlas(); + ~FontAtlas(); + + /**/ + Bool Initialize( RenderContext& render_context, const WChar* font_name ); + void Shutdown(); + + /**/ + Bool IsInitialized() const; + + /**/ + const Glyph* GetGlyph( Char character ) const; + const Texture& GetTexture() const; + + private: + // aliases + typedef FlatArray GlyphTable; + + // fields: parameters + RenderContext* _render_context; + Texture _texture; + GlyphTable _glyphs; + }; +} diff --git a/source/YoloMouse/Loader/Overlay/Text/FontMapBuilder.cpp b/source/YoloMouse/Loader/Overlay/Text/FontMapBuilder.cpp new file mode 100644 index 0000000..8a74ad2 --- /dev/null +++ b/source/YoloMouse/Loader/Overlay/Text/FontMapBuilder.cpp @@ -0,0 +1,155 @@ +#include + +namespace Yolomouse +{ + // public + //--------------------------------------------------------------------- + FontMapBuilder::FontMapBuilder(): + _map_size (0), + _token (NULL), + _graphics (nullptr), + _font (nullptr), + _bitmap (nullptr), + _string_format (nullptr) + { + } + + /**/ + FontMapBuilder::~FontMapBuilder() + { + ASSERT( !IsInitialized() ); + } + + /**/ + Bool FontMapBuilder::Initialize( const WChar* font_name, Float font_size, ULong map_size ) + { + ASSERT( !IsInitialized() ); + + Gdiplus::GdiplusStartupInput startup_input(NULL, TRUE, TRUE); + Gdiplus::GdiplusStartupOutput startup_output; + + // set fields + _map_size = map_size; + + // initialize gdi+ + if( Gdiplus::GdiplusStartup( &_token, &startup_input, &startup_output ) == Gdiplus::Status::Ok ) + { + Gdiplus::CharacterRange range( 0, 1 ); + + // create font + _font = new Gdiplus::Font( font_name, font_size, Gdiplus::FontStyleRegular, Gdiplus::UnitPixel ); + + // create bitmap + _bitmap = new Gdiplus::Bitmap( map_size, map_size, PixelFormat32bppARGB ); + + // create graphics + _graphics = new Gdiplus::Graphics( _bitmap ); + _graphics->SetTextRenderingHint( Gdiplus::TextRenderingHintAntiAlias ); + _graphics->Clear( Gdiplus::Color( 255, 0, 0, 0 ) ); + _graphics->SetPageUnit( Gdiplus::UnitPixel ); + + // create string format + _string_format = new Gdiplus::StringFormat(Gdiplus::StringFormat::GenericTypographic()); + _string_format->SetFormatFlags( Gdiplus::StringFormatFlagsMeasureTrailingSpaces ); + _string_format->SetMeasurableCharacterRanges( 1, &range ); + + // set status ok + return true; + } + + return false; + } + + void FontMapBuilder::Shutdown() + { + ASSERT( IsInitialized() ); + + // if gdi+ initialized + if( _token != NULL ) + { + // free objects + delete _string_format; + delete _graphics; + delete _bitmap; + delete _font; + + // shutdown gdi+ + Gdiplus::GdiplusShutdown(_token); + _token = NULL; + } + } + + /**/ + Bool FontMapBuilder::IsInitialized() const + { + return _token != NULL; + } + + /**/ + Bool FontMapBuilder::GetCharacterSize( Vector2f& size, WChar character ) + { + Gdiplus::RectF layout( 0, 0, 1000, 1000 ); + Gdiplus::RectF region_rect; + Gdiplus::Region region; + WCHAR string[1] = { character }; + + // get region from single character + if( _graphics->MeasureCharacterRanges( string, 1, _font, layout, _string_format, 1, ®ion ) != Gdiplus::Status::Ok ) + return false; + + // extract size from region + if( region.GetBounds( ®ion_rect, _graphics ) != Gdiplus::Status::Ok ) + return false; + + // return size + size.Set( region_rect.Width, region_rect.Height ); + + return true; + } + + /**/ + Bool FontMapBuilder::WriteCharacter( const Vector2f& offset, WChar character ) + { + WCHAR string[1] = { character }; + Gdiplus::SolidBrush brush(Gdiplus::Color(255, 255, 255, 255)); + + // write character to bitmap + return _graphics->DrawString(string, 1, _font, Gdiplus::PointF(offset.x, offset.y), _string_format, &brush) == Gdiplus::Status::Ok; + } + + /**/ + Bool FontMapBuilder::ToDxMap( Texture& texture, RenderContext& render_context ) + { + Gdiplus::BitmapData bitmap_data; + Bool status = false; + + // get bitmap memory access + if( _bitmap->LockBits( &Gdiplus::Rect( 0, 0, _map_size, _map_size ), Gdiplus::ImageLockModeRead, PixelFormat32bppARGB, &bitmap_data ) == Gdiplus::Status::Ok ) + { + D3D11_TEXTURE2D_DESC texture_desc = {}; + D3D11_SUBRESOURCE_DATA subresource_data = {}; + Byte* pixels_begin = reinterpret_cast( bitmap_data.Scan0 ); + Byte* pixels_end = pixels_begin + (_map_size * _map_size * 4); + + // tweak pixel alphas cuz microshit sux. background must be BGRA=000000ff and foreground BGRA=ffffffff + for( Byte* pixel = pixels_begin; pixel < pixels_end; pixel += 4 ) + { + // if not fully opaque + if( pixel[0] != 0xff ) + { + // make alpha one of RGB values and rest fully opaque + pixel[3] = pixel[0]; + pixel[0] = pixel[1] = pixel[2] = 0xff; + } + } + + // initialize texture + status = texture.Initialize( { render_context, pixels_begin, Vector2l(_map_size) } ); + } + + // unget bitmap memory access + _bitmap->UnlockBits(&bitmap_data); + + return status; + } +} diff --git a/source/YoloMouse/Loader/Overlay/Text/FontMapBuilder.hpp b/source/YoloMouse/Loader/Overlay/Text/FontMapBuilder.hpp new file mode 100644 index 0000000..073c95e --- /dev/null +++ b/source/YoloMouse/Loader/Overlay/Text/FontMapBuilder.hpp @@ -0,0 +1,41 @@ +#pragma once +#include +#include +#include + +namespace Yolomouse +{ + /**/ + class FontMapBuilder + { + public: + /**/ + FontMapBuilder(); + ~FontMapBuilder(); + + /**/ + Bool Initialize( const WChar* font_name, Float font_size, ULong map_size ); + void Shutdown(); + + /**/ + Bool IsInitialized() const; + + /**/ + Bool GetCharacterSize( Vector2f& size, WChar character ); + + /**/ + Bool WriteCharacter( const Vector2f& offset, WChar character ); + + /**/ + Bool ToDxMap( Texture& texture, RenderContext& render_context ); + + private: + // fields + ULong _map_size; + ULONG_PTR _token; + Gdiplus::Graphics* _graphics; + Gdiplus::Font* _font; + Gdiplus::Bitmap* _bitmap; + Gdiplus::StringFormat* _string_format; + }; +} diff --git a/source/YoloMouse/Loader/Overlay/Text/TextMesh.cpp b/source/YoloMouse/Loader/Overlay/Text/TextMesh.cpp new file mode 100644 index 0000000..e4c17e4 --- /dev/null +++ b/source/YoloMouse/Loader/Overlay/Text/TextMesh.cpp @@ -0,0 +1,183 @@ +#include +#include +#include + +namespace Yolomouse +{ + // public + //------------------------------------------------------------------------- + TextMesh::TextMesh() + { + } + + TextMesh::~TextMesh() + { + ASSERT( !IsInitialized() ); + } + + //------------------------------------------------------------------------- + void TextMesh::Initialize( RenderContext& render_context, const FontAtlas& atlas ) + { + ASSERT( !IsInitialized() ); + + // set fields + _render_context = &render_context; + _atlas = &atlas; + } + + void TextMesh::Shutdown() + { + ASSERT( IsInitialized() ); + + // shutdown mesh if used + if( _mesh.IsInitialized() ) + _mesh.Shutdown(); + + // reset fields + _render_context = nullptr; + _atlas = nullptr; + } + + //------------------------------------------------------------------------- + Bool TextMesh::IsInitialized() const + { + return _render_context != nullptr; + } + + //------------------------------------------------------------------------- + Bool TextMesh::SetText( Float& total_width, const String& text, Float height ) + { + ASSERT( IsInitialized() ); + + // shutdown previous mesh + if( _mesh.IsInitialized() ) + _mesh.Shutdown(); + + // build text mesh + return _BuildTextMesh( total_width, text, height ); + } + + void TextMesh::SetAspectRatio( Float aspect_ratio ) + { + // update projection matrix + RenderTools::BuildOrthoProjectionMatrix( _projection_matrix, aspect_ratio ); + } + + //------------------------------------------------------------------------- + void TextMesh::Draw( const Vector2f& position, const Vector4f& color ) const + { + Transform3f transform = Transform3f::IDENTITY(); + Matrix4f mtransform = Matrix4f::IDENTITY(); + VertexShaderConstantValue vs_constant_value; + PixelShaderConstantValue ps_constant_value; + ID3D11DeviceContext& device_context = _render_context->GetDeviceContext(); + + // set model matrix + vs_constant_value.model = Matrix4f::IDENTITY(); + + // create transform + transform.translation.x = position.x; + transform.translation.y = position.y; + transform.ToMatrix4(mtransform); + + // create mvp and transpose cuz directx sucks, vulkan rules! xD + vs_constant_value.mvp = (_projection_matrix * mtransform).Transpose(); + vs_constant_value.variation_color = color; + + // set texturing state + ps_constant_value.type = PIXELSHADERTYPE_UNLIT_TEXTURE; + + // commit constant values + _render_context->CommitShaderContants(vs_constant_value, ps_constant_value); + + // draw texture + _atlas->GetTexture().Draw(); + + // draw mesh + _mesh.Draw(); + } + + // private + //------------------------------------------------------------------------- + Bool TextMesh::_BuildTextMesh( Float& total_width, const String& text, Float height ) + { + /* shows font atlas + Float s = 0.4f; + ShaderVertex VERTICES[] = { + { { 0, 0, 0 }, {1,0,0,1}, {0,0,1}, {0,0} }, + { { s, 0, 0 }, {1,1,0,1}, {0,0,1}, {1,0} }, + { { s, s, 0 }, {1,0,1,1}, {0,0,1}, {1,1} }, + { { 0, s, 0 }, {0,1,1,1}, {0,0,1}, {0,1} }, + }; + Index3 INDICES[] = { + { 0, 1, 2 }, + { 0, 2, 3 }, + }; + return _mesh.Initialize( {*_render_context, Array( INDICES, 2 ), Array( VERTICES, 4 )} ); + //*/ + SimpleArray vertices; + SimpleArray indices; + ULong n = text.GetCount(); + Float z = 0; + const Vector3f normal(0,0,1); + + // preallocate vertices and indices + indices.SetCount(n * 2); + vertices.SetCount(n * 4); + + // set initial total width + total_width = 0; + + // for each character + for( Index ci = 0, vi = 0, ii = 0; ci < text.GetCount(); ++ci, vi += 4, ii += 2 ) + { + // get font glyph + const FontAtlas::Glyph* glyph = _atlas->GetGlyph( text[ci] ); + + // ignore if not found + if( glyph != nullptr ) + { + ShaderVertex& v0 = vertices[vi]; + ShaderVertex& v1 = vertices[vi + 1]; + ShaderVertex& v2 = vertices[vi + 2]; + ShaderVertex& v3 = vertices[vi + 3]; + Index3& i0 = indices[ii]; + Index3& i1 = indices[ii + 1]; + + // get character width + Float width = (glyph->size.x / glyph->size.y) * height; + + // build positions + v0.position.Set( total_width, 0, z ); + v1.position.Set( total_width, height, z ); + v2.position.Set( total_width + width, height, z ); + v3.position.Set( total_width + width, 0, z ); + + // build normals + v0.normal = normal; + v1.normal = normal; + v2.normal = normal; + v3.normal = normal; + + // build uvs + v0.uv = glyph->uv_min; + v1.uv.Set( glyph->uv_min.x, glyph->uv_max.y ); + v2.uv = glyph->uv_max; + v3.uv.Set( glyph->uv_max.x, glyph->uv_min.y ); + + // build variable color + v0.color = v1.color = v2.color = v3.color = Vector4f( 0, 0, 0, 1 ); + + // build indices + i0.Set( vi, vi + 2, vi + 1 ); + i1.Set( vi, vi + 3, vi + 2 ); + + // increment display offset + total_width += width; + } + } + + // initialize mesh + return _mesh.Initialize( {*_render_context, indices, vertices} ); + } +} diff --git a/source/YoloMouse/Loader/Overlay/Text/TextMesh.hpp b/source/YoloMouse/Loader/Overlay/Text/TextMesh.hpp new file mode 100644 index 0000000..331f04e --- /dev/null +++ b/source/YoloMouse/Loader/Overlay/Text/TextMesh.hpp @@ -0,0 +1,42 @@ +#pragma once +#include +#include +#include +#include + +namespace Yolomouse +{ + /**/ + class TextMesh + { + public: + /**/ + TextMesh(); + ~TextMesh(); + + /**/ + void Initialize( RenderContext& render_context, const FontAtlas& atlas ); + void Shutdown(); + + /**/ + Bool IsInitialized() const; + + /**/ + Bool SetText( Float& total_width, const String& text, Float height ); + void SetAspectRatio( Float aspect_ratio ); + + /**/ + void Draw( const Vector2f& position, const Vector4f& color ) const; + + private: + /**/ + Bool _BuildTextMesh( Float& total_width, const String& text, Float height ); + + // fields: parameters + RenderContext* _render_context; + const FontAtlas* _atlas; + // fields: state + Mesh _mesh; + Matrix4f _projection_matrix; + }; +} diff --git a/source/YoloMouse/Loader/Overlay/Text/TextPopup.cpp b/source/YoloMouse/Loader/Overlay/Text/TextPopup.cpp new file mode 100644 index 0000000..df6d553 --- /dev/null +++ b/source/YoloMouse/Loader/Overlay/Text/TextPopup.cpp @@ -0,0 +1,256 @@ +#include +#include +#include +#include + +namespace Yolomouse +{ + // local + //------------------------------------------------------------------------- + namespace + { + // constants + //--------------------------------------------------------------------- + static constexpr WChar* FONT_FAMILY = L"Arial"; + static constexpr Float MESSAGE_SIZE = 0.02f; + static constexpr Char* HEADER_TEXT = "Yolomouse"; + static constexpr Float HEADER_SIZE = 0.01f; + static constexpr Float MESSAGE_OFFSET = 0.005f; + static const Vector2f HEADER_PADDING ( 0.003f, 0.002f ); + static const Vector2f BACKGROUND_PADDING ( 0.03f, 0.017f ); + static const Vector4f BACKGROUND_COLOR ( 0, 0, 0, 0.5f ); + static const Vector4f MESSAGE_COLOR ( 1, 1, 1, 1 ); + static const Vector4f HEADER_COLOR ( 0, 0.8f, 1, 1 ); + static constexpr Float FADE_RATE = 0.5f; + } + + // public + //------------------------------------------------------------------------- + TextPopup::TextPopup(): + _render_context (nullptr), + _position (0,0), + _timeout (0), + _state (STATE_IDLE), + _fade (0), + _message_width (0), + _message_position (0,0), + _header_position (0,0), + _projection_matrix (Matrix4f::IDENTITY()) + { + } + + TextPopup::~TextPopup() + { + ASSERT( !IsInitialized() ); + } + + //------------------------------------------------------------------------- + Bool TextPopup::Initialize( RenderContext& render_context ) + { + ASSERT( !IsInitialized() ); + + // set fields + _render_context = &render_context; + + // initialize font atlas + if( !_font_atlas.Initialize( render_context, FONT_FAMILY ) ) + return false; + + // initialize text mesh + _message_mesh.Initialize( render_context, _font_atlas ); + + // initialize header mesh + _header_mesh.Initialize( render_context, _font_atlas ); + + return true; + } + + void TextPopup::Shutdown() + { + ASSERT( IsInitialized() ); + + // shutdown header mesh + if( _header_mesh.IsInitialized() ) + _header_mesh.Shutdown(); + + // shutdown message mesh + if( _message_mesh.IsInitialized() ) + _message_mesh.Shutdown(); + + // shutdown background mesh + if( _background_mesh.IsInitialized() ) + _background_mesh.Shutdown(); + + // shutdown font atlas + if( _font_atlas.IsInitialized() ) + _font_atlas.Shutdown(); + + // reset fields + _render_context = nullptr; + } + + //------------------------------------------------------------------------- + Bool TextPopup::IsInitialized() const + { + return _render_context != nullptr; + } + + Bool TextPopup::IsActive() const + { + return _state != STATE_IDLE; + } + + //------------------------------------------------------------------------- + Bool TextPopup::SetText( const String& text, const Vector2f& position, ULong timeout ) + { + ASSERT( IsInitialized() ); + Float fdummy; + + // set fields + _position = position; + _timeout = SystemTools::GetTimeMs() + timeout; + + // update build header mesh + if( !_header_mesh.SetText( fdummy, HEADER_TEXT, HEADER_SIZE ) ) + return false; + + // update build text mesh + if( !_message_mesh.SetText( _message_width, text, MESSAGE_SIZE ) ) + return false; + + // shutdown previous background mesh + if( _background_mesh.IsInitialized() ) + _background_mesh.Shutdown(); + + // initialize background mesh + if( !_InitializeBackgrounMesh( {_message_width + BACKGROUND_PADDING.x, MESSAGE_SIZE + BACKGROUND_PADDING.y} ) ) + return false; + + // calculate message display position + _message_position.Set(position.x - _message_width / 2.0f, position.y + MESSAGE_OFFSET ); + + // calculate header display position + _header_position.Set(position.x - (_message_width + BACKGROUND_PADDING.x) / 2.0f + HEADER_PADDING.x, position.y - BACKGROUND_PADDING.y / 2.0f + HEADER_PADDING.y); + + // set initial fade + _fade = 1; + + // enter visible state + _state = STATE_VISIBLE; + + return true; + } + + void TextPopup::SetAspectRatio( Float aspect_ratio ) + { + // update message aspect ratio + _message_mesh.SetAspectRatio( aspect_ratio ); + + // update header aspect ratio + _header_mesh.SetAspectRatio( aspect_ratio ); + + // update projection matrix + RenderTools::BuildOrthoProjectionMatrix( _projection_matrix, aspect_ratio ); + } + + //------------------------------------------------------------------------- + void TextPopup::Draw() + { + // by state + switch( _state ) + { + case STATE_IDLE: + break; + + case STATE_VISIBLE: + // if timeout expired, enter fading state + if( SystemTools::GetTimeMs() > _timeout ) + _state = STATE_FADING; + + // draw popup + _DrawPopup(); + break; + + case STATE_FADING: + // fade relative to fame time + _fade -= _render_context->GetRenderTimingController().GetFrameTime() * FADE_RATE; + + // if still fading, draw popup, else enter idle state + if( _fade > 0 ) + _DrawPopup(); + else + _state = STATE_IDLE; + break; + } + } + + // private + //------------------------------------------------------------------------- + Bool TextPopup::_InitializeBackgrounMesh( const Vector2f& size ) + { + Float w = size.x / 2; + Float h = size.y / 2; + + ShaderVertex vertices[] = { + { { -w, -h, 0 }, { 0, 0, 0, 1 }, {0,0,1}, {0,0} }, + { { w, -h, 0 }, { 0, 0, 0, 1 }, {0,0,1}, {1,0} }, + { { w, h, 0 }, { 0, 0, 0, 1 }, {0,0,1}, {1,1} }, + { { -w, h, 0 }, { 0, 0, 0, 1 }, {0,0,1}, {0,1} }, + }; + Index3 indices[] = { + { 0, 1, 2 }, + { 0, 2, 3 }, + }; + + // initialize mesh + return _background_mesh.Initialize( { + *_render_context, + Array(indices, 2), + Array(vertices, 4)} ); + } + + //------------------------------------------------------------------------- + void TextPopup::_DrawPopup() const + { + Vector4f fade_color(1, 1, 1, _fade); + + // draw background mesh + _DrawBackgrounMesh(_position, BACKGROUND_COLOR * fade_color); + + // draw header text + _header_mesh.Draw(_header_position, HEADER_COLOR * fade_color); + + // draw message text + _message_mesh.Draw(_message_position, MESSAGE_COLOR * fade_color); + } + + void TextPopup::_DrawBackgrounMesh( const Vector2f& position, const Vector4f& color ) const + { + Transform3f transform = Transform3f::IDENTITY(); + Matrix4f mtransform = Matrix4f::IDENTITY(); + VertexShaderConstantValue vs_constant_value; + PixelShaderConstantValue ps_constant_value; + ID3D11DeviceContext& device_context = _render_context->GetDeviceContext(); + + // set model matrix + vs_constant_value.model = Matrix4f::IDENTITY(); + + // create transform + transform.translation.x = position.x; + transform.translation.y = position.y + MESSAGE_SIZE / 2.0f; + transform.ToMatrix4(mtransform); + + // create mvp and transpose cuz directx sucks, vulkan rules! xD + vs_constant_value.mvp = (_projection_matrix * mtransform).Transpose(); + vs_constant_value.variation_color = color; + + // set texturing state + ps_constant_value.type = PIXELSHADERTYPE_UNLIT_BASIC; + + // commit constant values + _render_context->CommitShaderContants(vs_constant_value, ps_constant_value); + + // draw mesh + _background_mesh.Draw(); + } +} diff --git a/source/YoloMouse/Loader/Overlay/Text/TextPopup.hpp b/source/YoloMouse/Loader/Overlay/Text/TextPopup.hpp new file mode 100644 index 0000000..58becd6 --- /dev/null +++ b/source/YoloMouse/Loader/Overlay/Text/TextPopup.hpp @@ -0,0 +1,63 @@ +#pragma once +#include +#include + +namespace Yolomouse +{ + /**/ + class TextPopup + { + public: + /**/ + TextPopup(); + ~TextPopup(); + + /**/ + Bool Initialize( RenderContext& render_context ); + void Shutdown(); + + /**/ + Bool IsInitialized() const; + Bool IsActive() const; + + /**/ + Bool SetText( const String& text, const Vector2f& position, ULong timeout ); + void SetAspectRatio( Float aspect_ratio ); + + /**/ + void Draw(); + + private: + // enums + enum State: Byte + { + STATE_IDLE, + STATE_VISIBLE, + STATE_FADING + }; + /**/ + Bool _InitializeBackgrounMesh( const Vector2f& size ); + + /**/ + void _DrawPopup() const; + void _DrawBackgrounMesh( const Vector2f& position, const Vector4f& color ) const; + + // fields: parameters + RenderContext* _render_context; + Vector2f _position; + ULong _timeout; + // fields: state + State _state; + Float _fade; + Float _message_width; + Vector2f _message_position; + Vector2f _header_position; + //TODO2: put into view/scene constantbuffer and call for whole sene + Matrix4f _projection_matrix; + // fields: objects + FontAtlas _font_atlas; + TextMesh _message_mesh; + TextMesh _header_mesh; + Mesh _background_mesh; + }; +} diff --git a/source/YoloMouse/Loader/Target/Target.cpp b/source/YoloMouse/Loader/Target/Target.cpp index a6e1c2b..937139f 100644 --- a/source/YoloMouse/Loader/Target/Target.cpp +++ b/source/YoloMouse/Loader/Target/Target.cpp @@ -11,13 +11,13 @@ namespace Yolomouse // public //------------------------------------------------------------------------- Target::Target(): - _process_id (INVALID_ID), - _initialized (false), - _started (false), - _hover_hwnd (NULL), - _showing (true), - _process (NULL), - _wait_handle (NULL) + _process_id (INVALID_ID), + _initialized(false), + _started (false), + _hover_hwnd (NULL), + _showing (true), + _process (NULL), + _wait_handle(NULL) { _bindings_path.Zero(); } @@ -65,8 +65,9 @@ namespace Yolomouse // activate with default _BuildDefaultCursor(_active_cursor); } + // update binding - else if( !_UpdateRestrictedBinding( updates, flags ) ) + if( !_SetRestrictedBinding( updates, flags ) ) return false; // update cursor @@ -98,8 +99,8 @@ namespace Yolomouse // if restricted state if( IsRestricted() ) { - // reset cursor - _active_cursor = CursorInfo(); + // reset binding + _ResetRestrictedBinding(); // update cursor _UpdateCursor(); @@ -155,7 +156,7 @@ namespace Yolomouse } //------------------------------------------------------------------------- - Bool Target::Start() + Bool Target::Start( Bool allow_restricted_mode ) { ASSERT( !IsStarted() ); @@ -174,6 +175,10 @@ namespace Yolomouse // if restricted state (inject session failed) if( IsRestricted() ) { + // fail if not allowed + if( !allow_restricted_mode ) + return false; + //TODO2: also notify user via overlay that this happened LOG( "Target.Start: Entering Restricted Mode" ); @@ -292,7 +297,7 @@ namespace Yolomouse } //------------------------------------------------------------------------- - Bool Target::_UpdateRestrictedBinding( const CursorInfo& updates, CursorUpdateFlags flags ) + Bool Target::_SetRestrictedBinding( const CursorInfo& updates, CursorUpdateFlags flags ) { CursorInfo cursor = _active_cursor; @@ -303,7 +308,7 @@ namespace Yolomouse if( !_IsValidCursor(cursor) ) return false; - // update cursor + // update active cursor _active_cursor = cursor; // update default restricted binding @@ -315,6 +320,18 @@ namespace Yolomouse return true; } + void Target::_ResetRestrictedBinding() + { + // reset active cursor + _active_cursor = CursorInfo(); + + // update default restricted binding + _restricted_bindings.GetDefaultBinding() = _active_cursor; + + // save cursor bindings (can fail) + CursorBindingsSerializer::Save( _restricted_bindings, _bindings_path ); + } + void Target::_UpdateCursor() { Overlay& overlay = Overlay::Instance(); @@ -354,30 +371,6 @@ namespace Yolomouse // else ensure overlay cursor hidden (this should happen first before new target gets hover control) else overlay.SetCursorHidden(); - - - -/* - // if hovering, showing, and binding is overlay type, update overlay cursor - if( _hover_hwnd != NULL && _showing && _binding.type == CURSOR_TYPE_OVERLAY ) - { - // show overlay cursor - overlay.SetCursorIterated( _binding ); - - // if restricted state, hack hide application cursor - if( IsRestricted() ) - CursorVisibilityHacker::Instance().Hide(_hover_hwnd, HACK_VISIBILITY_TIMEOUT); - } - else - { - // hide overlay cursor - overlay.SetCursorHidden(); - - // if hovering and restricted state, hack show application cursor - if( _hover_hwnd != NULL && IsRestricted() ) - CursorVisibilityHacker::Instance().Show(_hover_hwnd, HACK_VISIBILITY_TIMEOUT); - } -*/ } //------------------------------------------------------------------------- diff --git a/source/YoloMouse/Loader/Target/Target.hpp b/source/YoloMouse/Loader/Target/Target.hpp index a2f0867..eab485b 100644 --- a/source/YoloMouse/Loader/Target/Target.hpp +++ b/source/YoloMouse/Loader/Target/Target.hpp @@ -41,7 +41,7 @@ namespace Yolomouse void Shutdown(); /**/ - Bool Start(); + Bool Start( Bool allow_restricted_mode ); void Stop(); /**/ @@ -60,7 +60,10 @@ namespace Yolomouse static Bool _IsValidCursor( const CursorInfo& properties ); /**/ - Bool _UpdateRestrictedBinding( const CursorInfo& updates, CursorUpdateFlags flags ); + Bool _SetRestrictedBinding( const CursorInfo& updates, CursorUpdateFlags flags ); + void _ResetRestrictedBinding(); + + /**/ void _UpdateCursor(); /**/ diff --git a/source/YoloMouse/Loader/Target/TargetController.cpp b/source/YoloMouse/Loader/Target/TargetController.cpp index 93f6469..09fd414 100644 --- a/source/YoloMouse/Loader/Target/TargetController.cpp +++ b/source/YoloMouse/Loader/Target/TargetController.cpp @@ -4,6 +4,7 @@ #include #include #include +#include namespace Yolomouse { @@ -79,7 +80,7 @@ namespace Yolomouse } //------------------------------------------------------------------------- - Bool TargetController::AccessTarget( Target*& target ) + Bool TargetController::AccessTarget( Target*& target, Bool allow_restricted_mode ) { ASSERT( IsInitialized() ); DWORD process_id = 0; @@ -102,9 +103,26 @@ namespace Yolomouse // find existing target entry target = _targets.Get( process_id ); - // if not found, spawn new one + // if not found if( target == nullptr ) - target = _SpawnTarget( process_id, false ); + { + // spawn new target + target = _SpawnTarget( process_id, false, allow_restricted_mode ); + + // if failed + if( target == nullptr ) + { + // if restricted mode not allowed, notify user to allow it + if( !allow_restricted_mode ) + Overlay::Instance().SetMessage( NOTIFY_REQUIRE_RESTRICTED_MODE ); + } + else + { + // notify user if entered restricted mode + if( target->IsRestricted() ) + Overlay::Instance().SetMessage( NOTIFY_ENTERED_RESTRICTED_MODE ); + } + } return target != nullptr; } @@ -144,7 +162,7 @@ namespace Yolomouse } //------------------------------------------------------------------------- - Target* TargetController::_SpawnTarget( Id process_id, Bool require_configured ) + Target* TargetController::_SpawnTarget( Id process_id, Bool require_configured, Bool allow_restricted_mode ) { // add new target Target& target = _targets.Set( process_id ); @@ -153,7 +171,7 @@ namespace Yolomouse if( target.Initialize( process_id, require_configured, *this ) ) { // start target - if( target.Start() ) + if( target.Start(allow_restricted_mode) ) return ⌖ // if fail shutdown target @@ -179,7 +197,7 @@ namespace Yolomouse // if not found, spawn target if installed if( target == nullptr ) - _SpawnTarget( process_id, true ); + _SpawnTarget( process_id, true, true ); } } @@ -204,7 +222,7 @@ namespace Yolomouse _hover_target = _targets.Get( process_id ); } } - // else looup hover target + // else lookup hover target else _hover_target = _targets.Get( process_id ); diff --git a/source/YoloMouse/Loader/Target/TargetController.hpp b/source/YoloMouse/Loader/Target/TargetController.hpp index faa57f3..ad5453e 100644 --- a/source/YoloMouse/Loader/Target/TargetController.hpp +++ b/source/YoloMouse/Loader/Target/TargetController.hpp @@ -32,7 +32,7 @@ namespace Yolomouse void SetGamesOnly( Bool enable ); /**/ - Bool AccessTarget( Target*& target ); + Bool AccessTarget( Target*& target, Bool allow_restricted_mode ); private: // impl @@ -46,7 +46,7 @@ namespace Yolomouse void _ShutdownTargets(); /**/ - Target* _SpawnTarget( Id process_id, Bool require_configured ); + Target* _SpawnTarget( Id process_id, Bool require_configured, Bool allow_restricted_mode ); /**/ void _OnWindowForeground( HWND hwnd ); diff --git a/source/YoloMouse/Share/Constants.cpp b/source/YoloMouse/Share/Constants.cpp index b82185f..141c496 100644 --- a/source/YoloMouse/Share/Constants.cpp +++ b/source/YoloMouse/Share/Constants.cpp @@ -6,13 +6,14 @@ namespace Yolomouse const WCHAR* APP_MENU_STRINGS[MENU_OPTION_COUNT] = { // info - L"About", //MENU_OPTION_ABOUT - L"Errors", //MENU_OPTION_ERRORS + L"About", //MENU_OPTION_ABOUT + L"Errors", //MENU_OPTION_ERRORS // settings - L"Start with Windows", //MENU_OPTION_AUTOSTART + L"Start with Windows", //MENU_OPTION_AUTOSTART + L"Reduce overlay pointer lag", //MENU_OPTION_REDUCEOVERLAYLAG // etc - L"Run as Administrator", //MENU_OPTION_RUNASADMIN - L"Open settings folder", //MENU_OPTION_SETTINGSFOLDER + L"Run as Administrator", //MENU_OPTION_RUNASADMIN + L"Open settings folder", //MENU_OPTION_SETTINGSFOLDER }; //------------------------------------------------------------------------ @@ -25,8 +26,8 @@ namespace Yolomouse { "CursorKeyReset", "CONTROL ALT 0" }, { "CursorKeySmaller", "CONTROL ALT -" }, { "CursorKeyLarger", "CONTROL ALT =" }, - { "GamesOnly", "1" }, { "AutoStart", "1" }, + { "ReduceOverlayLag", "0" }, { "ShowMenu", "1" }, }; Settings::KeyValueCollection SETTINGS_ITEMS(_settings, SETTING_COUNT); diff --git a/source/YoloMouse/Share/Constants.hpp b/source/YoloMouse/Share/Constants.hpp index a70fb1a..7e0e3d1 100644 --- a/source/YoloMouse/Share/Constants.hpp +++ b/source/YoloMouse/Share/Constants.hpp @@ -6,33 +6,36 @@ namespace Yolomouse { // numeric //------------------------------------------------------------------------- - static const ULong APP_VERSION[] = { 0, 11, 1 }; - static const ULong CURSOR_CACHE_LIMIT = 50; + static const ULong APP_VERSION[] = { 0, 11, 2 }; + static const ULong CURSOR_CACHE_LIMIT = 50; // strings //------------------------------------------------------------------------- extern const WCHAR* APP_MENU_STRINGS[]; - static const WCHAR* APP_NAME = L"YoloMouse"; - static const Char* APP_NAMEC = "YoloMouse"; - static const WCHAR* OVERLAY_NAME = L"YoloCursorOverlay"; - static const WCHAR* OVERLAY_CLASS = L"YoloCursorClass"; + static const WCHAR* APP_NAME = L"YoloMouse"; + static const Char* APP_NAMEC = "YoloMouse"; + static const WCHAR* OVERLAY_NAME = L"YoloCursorOverlay"; + static const WCHAR* OVERLAY_CLASS = L"YoloCursorClass"; - static const WCHAR* PATH_LOADER = L"YoloMouse.exe"; - static const CHAR* PATH_DLL32 = "Yolo32.dll"; - static const CHAR* PATH_DLL64 = "Yolo64.dll"; - static const WCHAR* PATH_LOG_NAME = L"log.txt"; - static const WCHAR* PATH_SETTINGS = L"Settings.ini"; - static const WCHAR* PATH_CURSORS_CUSTOM = L"Cursors"; - static const WCHAR* PATH_CURSORS_DEFAULT = L"Cursors\\Default"; - static const WCHAR* EXTENSION_INI = L"ini"; - static const WCHAR* EXTENSION_STATIC_CURSOR = L"cur"; - static const WCHAR* EXTENSION_ANIMATED_CURSOR = L"ani"; + static const WCHAR* PATH_LOADER = L"YoloMouse.exe"; + static const CHAR* PATH_DLL32 = "Yolo32.dll"; + static const CHAR* PATH_DLL64 = "Yolo64.dll"; + static const WCHAR* PATH_LOG_NAME = L"log.txt"; + static const WCHAR* PATH_SETTINGS = L"Settings.ini"; + static const WCHAR* PATH_CURSORS_CUSTOM = L"Cursors"; + static const WCHAR* PATH_CURSORS_DEFAULT = L"Cursors\\Default"; + static const WCHAR* EXTENSION_INI = L"ini"; + static const WCHAR* EXTENSION_STATIC_CURSOR = L"cur"; + static const WCHAR* EXTENSION_ANIMATED_CURSOR = L"ani"; - static const WCHAR* IPC_MUTEX_NAME = L"YoloMouseMutex"; - static const WCHAR* IPC_MEMORY_NAME = L"YoloMouseMemory"; + static const WCHAR* IPC_MUTEX_NAME = L"YoloMouseMutex"; + static const WCHAR* IPC_MEMORY_NAME = L"YoloMouseMemory"; - static const Char* TEXT_ABOUT = "Version %u.%u.%u %u-Bit\nBy HaPpY :)"; - static const Char* TEXT_NOLOG = "No log :P"; + static const Char* NOTIFY_REQUIRE_RESTRICTED_MODE = "Cursor binding failed. Try running Yolomouse as Administrator."; + static const Char* NOTIFY_ENTERED_RESTRICTED_MODE = "Cursor binding failed. Using overlay cursors instead."; + + static const Char* TEXT_ABOUT = "Version %u.%u.%u %u-Bit\nBy HaPpY :)"; + static const Char* TEXT_NOLOG = "No log :P"; // tables //------------------------------------------------------------------------- diff --git a/source/YoloMouse/Share/Cursor/CursorVault.cpp b/source/YoloMouse/Share/Cursor/CursorVault.cpp index 24c1f49..924a3ff 100644 --- a/source/YoloMouse/Share/Cursor/CursorVault.cpp +++ b/source/YoloMouse/Share/Cursor/CursorVault.cpp @@ -292,7 +292,9 @@ namespace Yolomouse // mark failed to avoid attempting again entry.state = RESOURCE_FAILED; - LOG("CursorVault.CacheInit.NotFound: %u", index); + // log + LOG1("CursorVault.CacheInit.NotFound: %u", index); + return false; } diff --git a/source/YoloMouse/Share/Enums.hpp b/source/YoloMouse/Share/Enums.hpp index bc8498b..3b66abb 100644 --- a/source/YoloMouse/Share/Enums.hpp +++ b/source/YoloMouse/Share/Enums.hpp @@ -27,8 +27,8 @@ namespace Yolomouse SETTING_CURSORKEY_RESET, SETTING_CURSORKEY_SMALLER, SETTING_CURSORKEY_LARGER, - SETTING_GAMESONLY, SETTING_AUTOSTART, + SETTING_REDUCEOVERLAYLAG, SETTING_SHOWMENU, SETTING_COUNT }; @@ -39,8 +39,8 @@ namespace Yolomouse MENU_OPTION_ABOUT, MENU_OPTION_ERRORS, // options - //MENU_OPTION_GAMESONLY, MENU_OPTION_AUTOSTART, + MENU_OPTION_REDUCEOVERLAYLAG, // etc MENU_OPTION_RUNASADMIN, MENU_OPTION_SETTINGSFOLDER,