Skip to content

Commit a2786c2

Browse files
Use Panorama event handlers for handling slider value changes
Disabled build::kHideExecutableMemory because of incompatibility with event handler entry points
1 parent d614927 commit a2786c2

File tree

17 files changed

+214
-101
lines changed

17 files changed

+214
-101
lines changed

Source/BuildConfig.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace build
88

99
constexpr auto MEMORY_CAPACITY = 1'000'000;
1010

11-
constexpr auto kHideExecutableMemory{true};
11+
constexpr auto kHideExecutableMemory{false};
1212

1313
constexpr std::basic_string_view kOsirisDirectoryName{WIN64_LINUX(L"OsirisCS2", "OsirisCS2")};
1414
constexpr std::basic_string_view kConfigDirectoryName{WIN64_LINUX(L"configs", "configs")};
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#pragma once
2+
3+
#include <cassert>
4+
#include <cstdint>
5+
#include <type_traits>
6+
7+
#include <Platform/Macros/PlatformSpecific.h>
8+
9+
namespace cs2
10+
{
11+
12+
#if IS_WIN64()
13+
14+
struct CUtlAbstractDelegate {
15+
template <typename F>
16+
requires (std::is_pointer_v<F>&& std::is_function_v<std::remove_pointer_t<F>>)
17+
CUtlAbstractDelegate(F f)
18+
: function{std::uintptr_t(f)}
19+
{
20+
}
21+
22+
void* thisptr{};
23+
std::uintptr_t function{};
24+
};
25+
static_assert(sizeof(CUtlAbstractDelegate) == 16);
26+
27+
#elif IS_LINUX()
28+
29+
struct CUtlAbstractDelegate {
30+
template <typename F>
31+
requires (std::is_pointer_v<F>&& std::is_function_v<std::remove_pointer_t<F>>)
32+
CUtlAbstractDelegate(F f)
33+
: functionOrVirtualMethodOffset{std::uintptr_t(f)}
34+
{
35+
assert(isUsingFunctionPointer());
36+
}
37+
38+
[[nodiscard]] bool isUsingFunctionPointer() const noexcept
39+
{
40+
return (functionOrVirtualMethodOffset & 1) == 0;
41+
}
42+
43+
void* thisptr{};
44+
std::uintptr_t functionOrVirtualMethodOffset{};
45+
std::ptrdiff_t offsetToThis{};
46+
};
47+
static_assert(sizeof(CUtlAbstractDelegate) == 24);
48+
49+
#endif
50+
}

Source/CS2/Panorama/CSlider.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ namespace cs2
77

88
struct CSlider : CPanel2D {
99
using SetValue = void(CSlider* thisptr, float value);
10+
11+
using SliderValueChangedEventHandler = bool(void* delegateThisptr, CPanel2D* panel, float value);
1012
};
1113

1214
}

Source/CS2/Panorama/CUIEngine.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include <cstdint>
44

5+
#include <CS2/Classes/CUtlAbstractDelegate.h>
56
#include <Platform/Macros/IsPlatform.h>
67
#include "CPanel2D.h"
78
#include "CPanoramaSymbol.h"
@@ -16,6 +17,7 @@ struct CUIEngine {
1617
using runScript = void (*)(CUIEngine* thisptr, CUIPanel* contextPanel, const char* scriptSource, const char* originFile, std::uint64_t line);
1718
using makeSymbol = CPanoramaSymbol(*)(CUIEngine* thisptr, int type, const char* text);
1819
using onDeletePanel = void (*)(CUIEngine* thisptr, CPanel2D* panel);
20+
using RegisterEventHandler = void (*)(CUIEngine* thisptr, CPanoramaSymbol eventName, CUIPanel* panel, CUtlAbstractDelegate* handler);
1921
};
2022

2123
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#pragma once
2+
3+
#include <CS2/Panorama/CPanel2D.h>
4+
#include <Utils/TemplateParameterCstring.h>
5+
6+
template <typename HookContext, typename ConfigVariable, TemplateParameterCstring kPanelName>
7+
class GuiEntryPoints {
8+
public:
9+
LINUX_ONLY([[gnu::aligned(8)]]) static bool hueSliderValueChanged(void* /* thisptr */, cs2::CPanel2D* /* panel */, float value)
10+
{
11+
HookContext hookContext;
12+
hookContext.gui().template onHueSliderValueChanged<ConfigVariable>(kPanelName, value);
13+
return true;
14+
}
15+
};

Source/GameClient/Panorama/PanoramaUiEngine.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ class PanoramaUiEngine {
4242
return -1;
4343
}
4444

45+
void registerEventHandler(cs2::CPanoramaSymbol symbol, cs2::CUIPanel* panel, cs2::CUtlAbstractDelegate handler) noexcept
46+
{
47+
if (hookContext.patternSearchResults().template get<RegisterEventHandlerFunctionPointer>() && thisptr())
48+
hookContext.patternSearchResults().template get<RegisterEventHandlerFunctionPointer>()(*thisptr(), symbol, panel, &handler);
49+
}
50+
4551
private:
4652
[[nodiscard]] auto thisptr() const noexcept
4753
{

Source/MemoryPatterns/Linux/PanoramaUiEnginePatternsLinux.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ struct PanoramaUiEnginePatterns {
1616
.template addPattern<GetPanelPointerFunctionPointer, CodePattern{"8B 16 31 C9"}>()
1717
.template addPattern<RunScriptFunctionPointer, CodePattern{"55 48 8D 05 ? ? ? ? 48 89 E5 41 57 49 89 D7 41 56 49"}>()
1818
.template addPattern<MakeSymbolFunctionPointer, CodePattern{"55 48 89 E5 41 57 41 56 41 55 41 54 53 48 83 EC ? 48 85 D2"}>()
19-
.template addPattern<OnDeletePanelFunctionPointer, CodePattern{"48 85 F6 0F 84 ? ? ? ? 55 48 89 E5 41 56 41 55 41 54 49 89 F4 53 48 8B 06 48 89 FB 48 89 F7 FF 10"}>();
19+
.template addPattern<OnDeletePanelFunctionPointer, CodePattern{"48 85 F6 0F 84 ? ? ? ? 55 48 89 E5 41 56 41 55 41 54 49 89 F4 53 48 8B 06 48 89 FB 48 89 F7 FF 10"}>()
20+
.template addPattern<RegisterEventHandlerFunctionPointer, CodePattern{"55 48 8D 05 ? ? ? ? 48 89 E5 41 57 41 56 49 89 FE 41 55 48 8D 3D ? ? ? ? 49 89 CD"}>();
2021
}
2122
};

Source/MemoryPatterns/PatternTypes/UiEnginePatternTypes.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ STRONG_TYPE_ALIAS(GetPanelPointerFunctionPointer, cs2::CUIEngine::getPanelPointe
88
STRONG_TYPE_ALIAS(RunScriptFunctionPointer, cs2::CUIEngine::runScript);
99
STRONG_TYPE_ALIAS(MakeSymbolFunctionPointer, cs2::CUIEngine::makeSymbol);
1010
STRONG_TYPE_ALIAS(OnDeletePanelFunctionPointer, cs2::CUIEngine::onDeletePanel);
11+
STRONG_TYPE_ALIAS(RegisterEventHandlerFunctionPointer, cs2::CUIEngine::RegisterEventHandler);

Source/MemoryPatterns/Windows/PanoramaUiEnginePatternsWindows.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ struct PanoramaUiEnginePatterns {
1616
.template addPattern<GetPanelPointerFunctionPointer, CodePattern{"4C 63 0A 4C 8B DA"}>()
1717
.template addPattern<RunScriptFunctionPointer, CodePattern{"48 89 5C 24 ? 4C 89 4C 24 ? 48 89 54 24 ? 55 56 57 41 54 41 55 41 56 41 57 48 8D"}>()
1818
.template addPattern<MakeSymbolFunctionPointer, CodePattern{"40 55 56 48 83 EC ? 48 63"}>()
19-
.template addPattern<OnDeletePanelFunctionPointer, CodePattern{"48 85 D2 0F 84 ? ? ? ? 48 89 5C 24 ? 57 48 83 EC ? 48"}>();
19+
.template addPattern<OnDeletePanelFunctionPointer, CodePattern{"48 85 D2 0F 84 ? ? ? ? 48 89 5C 24 ? 57 48 83 EC ? 48"}>()
20+
.template addPattern<RegisterEventHandlerFunctionPointer, CodePattern{"48 89 5C 24 ? 66 89 54 24 ? 55 56 57 41 56 41 57 48 83 EC ? 48 8D 05 ? ? ? ? 48 C7 44 24 28 ? ? ? ? 48 89 44 24 ? 4D"}>();
2021
}
2122
};

Source/Osiris.vcxproj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
<ClInclude Include="CS2\Classes\CRenderComponent.h" />
4444
<ClInclude Include="CS2\Classes\CSceneObject.h" />
4545
<ClInclude Include="CS2\Classes\CSceneSystem.h" />
46+
<ClInclude Include="CS2\Classes\CUtlAbstractDelegate.h" />
4647
<ClInclude Include="CS2\Classes\CUtlFilenameSymbolTable.h" />
4748
<ClInclude Include="CS2\Classes\CUtlLinkedList.h" />
4849
<ClInclude Include="CS2\Classes\CUtlMap.h" />
@@ -116,6 +117,7 @@
116117
<ClInclude Include="CS2\Panorama\StyleProperties.h" />
117118
<ClInclude Include="CS2\Panorama\Transform3D.h" />
118119
<ClInclude Include="Endpoints.h" />
120+
<ClInclude Include="EntryPoints\GuiEntryPoints.h" />
119121
<ClInclude Include="Features\Combat\SniperRifles\NoScopeInaccuracyVis\NoScopeInaccuracyVis.h" />
120122
<ClInclude Include="Features\Combat\SniperRifles\NoScopeInaccuracyVis\NoScopeInaccuracyVisConfigVariables.h" />
121123
<ClInclude Include="Features\Combat\SniperRifles\NoScopeInaccuracyVis\NoScopeInaccuracyVisParams.h" />
@@ -384,7 +386,6 @@
384386
<ClInclude Include="MemoryPatterns\PatternTypes\GlowPropertyPatternTypes.h" />
385387
<ClInclude Include="MemoryPatterns\PatternTypes\GlowSceneObjectPatternTypes.h" />
386388
<ClInclude Include="MemoryPatterns\PatternTypes\HostageServicesPatternTypes.h" />
387-
<ClInclude Include="MemoryPatterns\PatternTypes\MapPreviewPanelPatternTypes.h" />
388389
<ClInclude Include="MemoryPatterns\PatternTypes\MemAllocPatternTypes.h" />
389390
<ClInclude Include="MemoryPatterns\PatternTypes\PanelPatternTypes.h" />
390391
<ClInclude Include="MemoryPatterns\PatternTypes\PanelStylePatternTypes.h" />
@@ -564,6 +565,7 @@
564565
<ClInclude Include="Utils\StringBuilder.h" />
565566
<ClInclude Include="Utils\StringParser.h" />
566567
<ClInclude Include="Utils\StrongTypeAlias.h" />
568+
<ClInclude Include="Utils\TemplateParameterCstring.h" />
567569
<ClInclude Include="Utils\ToUnderlying.h" />
568570
<ClInclude Include="Utils\TypeBitFlags.h" />
569571
<ClInclude Include="Utils\TypedStaticStringPool.h" />

0 commit comments

Comments
 (0)