Skip to content

Commit 41a3dee

Browse files
committed
pull
2 parents cbe252d + 82bbbba commit 41a3dee

File tree

96 files changed

+1158
-908
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+1158
-908
lines changed

.github/workflows/build.yml

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,3 @@ jobs:
7878
path: src/Snap.Hutao.Remastered.Native/x64/${{ env.BUILD_CONFIGURATION }}/*.dll
7979
retention-days: 30
8080
if-no-files-found: error
81-
82-
- name: Upload Build logs
83-
if: always()
84-
uses: actions/upload-artifact@v4
85-
with:
86-
name: build-logs
87-
path: |
88-
**/*.log
89-
**/bin/**/*.log
90-
**/obj/**/*.log
91-
retention-days: 7

src/Snap.Hutao.Remastered.Native/CustomImplements.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class CustomImplements : public Interfaces... {
4747

4848
public:
4949
// IUnknown methods
50-
HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, void** ppvObject) override {
50+
HRESULT __stdcall QueryInterface(REFIID riid, void** ppvObject) override {
5151
if (ppvObject == nullptr) {
5252
return E_POINTER;
5353
}
@@ -72,11 +72,11 @@ class CustomImplements : public Interfaces... {
7272
return E_NOINTERFACE;
7373
}
7474

75-
ULONG STDMETHODCALLTYPE AddRef() override {
75+
ULONG __stdcall AddRef() override {
7676
return InterlockedIncrement(&m_refCount);
7777
}
7878

79-
ULONG STDMETHODCALLTYPE Release() override {
79+
ULONG __stdcall Release() override {
8080
ULONG refCount = InterlockedDecrement(&m_refCount);
8181
if (refCount == 0) {
8282
delete static_cast<Derived*>(this);

src/Snap.Hutao.Remastered.Native/DllInjectionUtils.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1+
#include "pch.h"
12
#include "DllInjectionUtils.h"
23
#include "ProcessUtils.h"
34
#include "PrivilegeUtils.h"
45
#include "HookUtils.h"
56
#include "MemoryUtils.h"
67
#include "StringUtils.h"
7-
#include "Error.h"
8-
#include <Windows.h>
9-
#include <vector>
10-
#include <string>
118
#include <tlhelp32.h>
129

1310
// Windows钩子注入方法1(使用WH_GETMESSAGE钩子)

src/Snap.Hutao.Remastered.Native/Error.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include "pch.h"
12
#include "Error.h"
23
#include "WilCallbacksManager.h"
34
#include "FailureInfo.h"

src/Snap.Hutao.Remastered.Native/FirewallRuleManager.cpp

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
1-
#pragma once
2-
1+
#include "pch.h"
32
#include "FirewallRuleManager.h"
43
#include <sddl.h>
5-
#include <vector>
64
#include <icftypes.h>
75
#include <netfw.h>
8-
#include <Windows.h>
9-
#include <string>
106

117
FirewallRuleManager::FirewallRuleManager()
128
: m_policy(nullptr)
@@ -87,21 +83,21 @@ HRESULT FirewallRuleManager::AddLoopbackExempt(const std::wstring& familyName, c
8783

8884
std::wstring ruleName = GetRuleName(familyName, sid);
8985

90-
// 检查规则是否已存在
86+
// 检查规则是否已存在
9187
INetFwRule* existingRule = nullptr;
9288
hr = m_rules->Item(BSTR(ruleName.c_str()), &existingRule);
9389

9490
if (SUCCEEDED(hr) && existingRule)
9591
{
96-
// 规则已存在,启用它
92+
// 规则已存在,启用它
9793
hr = existingRule->put_Enabled(VARIANT_TRUE);
9894
SafeRelease(existingRule);
9995
return hr;
10096
}
10197

10298
SafeRelease(existingRule);
10399

104-
// 创建新规则
100+
// 创建新规则
105101
return CreateFirewallRule(
106102
ruleName,
107103
L"loopback",
@@ -152,7 +148,7 @@ HRESULT FirewallRuleManager::CreateFirewallRule(const std::wstring& ruleName, co
152148
if (FAILED(hr))
153149
return hr;
154150

155-
// 设置规则属性
151+
// 设置规则属性
156152
hr = rule->put_Name(BSTR(ruleName.c_str()));
157153
if (FAILED(hr)) goto cleanup;
158154

@@ -186,7 +182,7 @@ HRESULT FirewallRuleManager::CreateFirewallRule(const std::wstring& ruleName, co
186182
}
187183
rule->put_Grouping(BSTR(groupName.c_str()));
188184

189-
// 将规则添加到集合中
185+
// 将规则添加到集合中
190186
hr = m_rules->Add(rule);
191187

192188
cleanup:
@@ -214,7 +210,7 @@ std::wstring FirewallRuleManager::GetCurrentUserSid()
214210
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &hToken))
215211
return sidString;
216212

217-
// 获取所需缓冲区大小
213+
// 获取所需缓冲区大小
218214
DWORD tokenSize = 0;
219215
GetTokenInformation(hToken, TokenUser, nullptr, 0, &tokenSize);
220216

@@ -236,4 +232,4 @@ std::wstring FirewallRuleManager::GetCurrentUserSid()
236232

237233
CloseHandle(hToken);
238234
return sidString;
239-
}
235+
}

src/Snap.Hutao.Remastered.Native/FrameworkTheming.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1+
#include "pch.h"
12
#include "FrameworkTheming.h"
2-
#include "types.h"
3-
#include "Error.h"
4-
#include <Windows.h>
5-
#include <cstring>
63
#include <atomic>
74

85
// Global function pointers

src/Snap.Hutao.Remastered.Native/HookUtils.cpp

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
#pragma once
2-
1+
#include "pch.h"
32
#include "HookUtils.h"
43
#include "StringUtils.h"
5-
#include <Windows.h>
64

7-
// 使用Windows钩子注入DLL
5+
// 使用Windows钩子注入DLL
86
HRESULT InjectUsingHook(LPCWSTR dllPath, LPCWSTR functionName, DWORD threadId, int hookType)
97
{
108
if (!dllPath || !functionName) {
@@ -25,14 +23,14 @@ HRESULT InjectUsingHook(LPCWSTR dllPath, LPCWSTR functionName, DWORD threadId, i
2523
HOOKPROC hookProc = NULL;
2624

2725
if ((DWORD_PTR)ansiFunctionName <= 0xFFFF) {
28-
// 是序号
26+
// 是序号
2927
hookProc = (HOOKPROC)GetProcAddress(hHookDll, ansiFunctionName);
3028
}
3129
else {
32-
// 是字符串指针
30+
// 是字符串指针
3331
hookProc = (HOOKPROC)GetProcAddress(hHookDll, ansiFunctionName);
3432

35-
// 释放转换的字符串
33+
// 释放转换的字符串
3634
FreeConvertedString((LPVOID)ansiFunctionName);
3735
}
3836

@@ -41,12 +39,12 @@ HRESULT InjectUsingHook(LPCWSTR dllPath, LPCWSTR functionName, DWORD threadId, i
4139
return HRESULT_FROM_WIN32(ERROR_PROC_NOT_FOUND);
4240
}
4341

44-
// 设置Windows钩子
42+
// 设置Windows钩子
4543
HHOOK hHook = SetWindowsHookExW(
46-
hookType, // 钩子类型
47-
hookProc, // 钩子过程
48-
hHookDll, // 包含钩子过程的DLL
49-
threadId // 目标线程ID(0表示全局钩子)
44+
hookType, // 钩子类型
45+
hookProc, // 钩子过程
46+
hHookDll, // 包含钩子过程的DLL
47+
threadId // 目标线程ID(0表示全局钩子)
5048
);
5149

5250
if (!hHook) {
@@ -55,37 +53,37 @@ HRESULT InjectUsingHook(LPCWSTR dllPath, LPCWSTR functionName, DWORD threadId, i
5553
return HRESULT_FROM_WIN32(lastError);
5654
}
5755

58-
// 触发钩子 - 发送消息到目标线程的消息队列
56+
// 触发钩子 - 发送消息到目标线程的消息队列
5957
if (threadId != 0) {
60-
// 线程特定的钩子,发送线程消息
58+
// 线程特定的钩子,发送线程消息
6159
PostThreadMessageW(threadId, WM_NULL, 0, 0);
6260
}
6361
else {
64-
// 全局钩子,发送广播消息
62+
// 全局钩子,发送广播消息
6563
PostMessageW(HWND_BROADCAST, WM_NULL, 0, 0);
6664
}
6765

68-
// 等待一段时间确保DLL被加载
66+
// 等待一段时间确保DLL被加载
6967
Sleep(100);
7068

71-
// 卸载钩子(DLL已注入,不需要保持钩子)
69+
// 卸载钩子(DLL已注入,不需要保持钩子)
7270
UnhookWindowsHookEx(hHook);
7371

74-
// 释放当前进程中的DLL(不影响已注入到目标进程的DLL)
72+
// 释放当前进程中的DLL(不影响已注入到目标进程的DLL)
7573
FreeLibrary(hHookDll);
7674

7775
return S_OK;
7876
}
7977

80-
// 检查钩子是否可用
78+
// 检查钩子是否可用
8179
BOOL IsHookAvailable(int hookType)
8280
{
83-
// 临时钩子过程
81+
// 临时钩子过程
8482
HOOKPROC tempProc = [](int nCode, WPARAM wParam, LPARAM lParam) -> LRESULT {
8583
return CallNextHookEx(NULL, nCode, wParam, lParam);
8684
};
8785

88-
// 尝试设置一个临时钩子来检查是否可用
86+
// 尝试设置一个临时钩子来检查是否可用
8987
HHOOK hHook = SetWindowsHookExW(hookType, tempProc, NULL, 0);
9088

9189
if (hHook) {
@@ -96,7 +94,7 @@ BOOL IsHookAvailable(int hookType)
9694
return FALSE;
9795
}
9896

99-
// 获取钩子类型名称
97+
// 获取钩子类型名称
10098
LPCWSTR GetHookTypeName(int hookType)
10199
{
102100
switch (hookType) {
@@ -129,4 +127,4 @@ LPCWSTR GetHookTypeName(int hookType)
129127
default:
130128
return L"UNKNOWN";
131129
}
132-
}
130+
}

src/Snap.Hutao.Remastered.Native/HotKeyCallbackManager.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include "pch.h"
12
#include "HotKeyCallbackManager.h"
23
#include "HutaoNativeHotKeyBeforeSwitchCallback.h"
34

@@ -21,9 +22,9 @@ HutaoNativeHotKeyBeforeSwitchCallback HotKeyCallbackManager::GetCallback()
2122

2223
BOOL HotKeyCallbackManager::InvokeCallback()
2324
{
24-
if (callback_.value != nullptr)
25+
if (callback_.has_value())
2526
{
26-
return callback_.value();
27+
return callback_.value()();
2728
}
2829
return TRUE; // 如果没有回调,默认允许切换
2930
}
@@ -33,4 +34,4 @@ void HotKeyCallbackManager::ClearCallback()
3334
callback_ = {};
3435
}
3536

36-
HotKeyCallbackManager g_hotKeyCallbackManager = HotKeyCallbackManager();
37+
HotKeyCallbackManager gotKeyCallbackManager = HotKeyCallbackManager();

src/Snap.Hutao.Remastered.Native/HotKeyCallbackManager.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ class HotKeyCallbackManager
1818
HutaoNativeHotKeyBeforeSwitchCallback callback_ = {};
1919
};
2020

21-
extern HotKeyCallbackManager g_hotKeyCallbackManager;
21+
extern HotKeyCallbackManager gotKeyCallbackManager;

0 commit comments

Comments
 (0)