forked from rutice/NicoJK
-
Notifications
You must be signed in to change notification settings - Fork 7
/
NicoJK.h
250 lines (242 loc) · 8.05 KB
/
NicoJK.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
#pragma once
#include <atomic>
#include <thread>
// プラグインクラス
class CNicoJK : public TVTest::CTVTestPlugin
{
public:
// リストボックスのログ表示の最大数
static const int COMMENT_TRIMEND = 1000;
// リストボックスのログ表示の最小描画間隔
static const int COMMENT_REDRAW_INTERVAL = 250;
// 表示できるコメントの最大文字数(超えると単なる空コメントとして表示される)
static const int CHAT_TEXT_MAX = 2048;
// 勢いリストを更新する間隔(あんまり短くしちゃダメ!)
static const int UPDATE_FORCE_INTERVAL = 20000;
// コメントサーバ切断をチェックして再接続する間隔(あんまり短くしちゃダメ!)
static const int JK_WATCHDOG_INTERVAL = 20000;
// チャンネル変更などでコメントサーバ切断してから再接続するまでの猶予
static const int JK_WATCHDOG_RECONNEC_DELAY = 3000;
// ログファイルフォルダの更新をチェックする間隔
static const int READ_LOG_FOLDER_INTERVAL = 3000;
// チャンネル変更などの後に適当な実況IDのチェックを行うまでの猶予
static const int SETUP_CURJK_DELAY = 3000;
// 投稿できる最大コメント文字数(たぶん安易に変更しないほうがいい)
static const int POST_COMMENT_MAX = 76;
// 連投制限(短いと規制されるとのウワサ)
static const int POST_COMMENT_INTERVAL = 2000;
// CTVTestPlugin
CNicoJK();
bool GetPluginInfo(TVTest::PluginInfo *pInfo);
bool Initialize();
bool Finalize();
private:
struct SETTINGS {
int hideForceWindow;
int forceFontSize;
TCHAR forceFontName[LF_FACESIZE];
int timerInterval;
int halfSkipThreshold;
int commentLineMargin;
int commentFontOutline;
int commentSize;
int commentSizeMin;
int commentSizeMax;
TCHAR commentFontName[LF_FACESIZE];
TCHAR commentFontNameMulti[LF_FACESIZE];
TCHAR commentFontNameEmoji[LF_FACESIZE];
bool bCommentFontBold;
bool bCommentFontAntiAlias;
int commentDuration;
int commentDrawLineCount;
int commentShareMode;
int logfileMode;
bool bCheckProcessRecording;
tstring logfileDrivers;
tstring nonTunerDrivers;
tstring logfileFolder;
tstring execGetCookie;
tstring execGetV10Key;
std::string channelsUri;
std::string refugeUri;
bool bDropForwardedComment;
bool bRefugeMixing;
bool bPostToRefuge;
COLORREF crNicoEditBox;
COLORREF crRefugeEditBox;
COLORREF crNicoMarker;
COLORREF crRefugeMarker;
COLORREF crNicoLightShadow;
COLORREF crRefugeLightShadow;
COLORREF crNicoDarkShadow;
COLORREF crRefugeDarkShadow;
tstring mailDecorations;
bool bAnonymity;
bool bUseOsdCompositor;
bool bUseTexture;
bool bUseDrawingThread;
bool bSetChannel;
int maxAutoReplace;
tstring abone;
int dropLogfileMode;
int defaultPlaybackDelay;
int forwardList[26];
RECT rcForce;
int forceOpacity;
int commentOpacity;
int headerMask;
bool bSetRelative;
bool bUsePanel;
};
struct FORCE_ELEM {
int jkID;
int force;
bool bFixedName;
tstring name;
std::string chatStreamID;
std::string refugeChatStreamID;
};
enum LOG_ELEM_TYPE {
LOG_ELEM_TYPE_DEFAULT,
LOG_ELEM_TYPE_HIDE,
LOG_ELEM_TYPE_REFUGE,
LOG_ELEM_TYPE_REFUGE_HIDE,
LOG_ELEM_TYPE_MESSAGE,
};
struct LOG_ELEM {
SYSTEMTIME st;
LOG_ELEM_TYPE type;
int no;
COLORREF cr;
TCHAR marker[28];
tstring text;
};
struct RPL_ELEM {
int key;
tstring section;
tstring comment;
tstring pattern;
std::regex re;
std::string fmt;
bool IsEnabled() const { return !pattern.empty() && TEXT('a') <= pattern[0] && pattern[0] <= TEXT('z'); }
void SetEnabled(bool b);
bool SetPattern(LPCTSTR patt);
};
bool TogglePlugin(bool bEnabled);
void TogglePanelPopup();
void ToggleStreamCallback(bool bSet);
void SyncThread();
void CheckRecordingThread(DWORD processID);
static std::vector<NETWORK_SERVICE_ID_ELEM>::iterator LowerBoundNetworkServiceID(std::vector<NETWORK_SERVICE_ID_ELEM>::iterator first,
std::vector<NETWORK_SERVICE_ID_ELEM>::iterator last, DWORD ntsID);
static std::vector<FORCE_ELEM>::iterator LowerBoundJKID(std::vector<FORCE_ELEM>::iterator first,
std::vector<FORCE_ELEM>::iterator last, int jkID);
void LoadFromIni();
void SaveToIni();
void LoadForceListFromIni(const tstring &logfileFolder);
void LoadRplListFromIni(LPCTSTR section, std::vector<RPL_ELEM> *pRplList);
void SaveRplListToIni(LPCTSTR section, const std::vector<RPL_ELEM> &rplList, bool bClearSection = true);
HWND GetFullscreenWindow();
HWND FindVideoContainer();
DWORD GetCurrentNetworkServiceID();
bool GetChannelNetworkServiceID(int tuningSpace, int channelIndex, DWORD *pNtsID);
LONGLONG GetCurrentTot();
bool IsMatchDriverName(LPCTSTR drivers);
void WriteToLogfile(int jkID, const char *text = nullptr);
bool ReadFromLogfile(int jkID, const char **text = nullptr, unsigned int tmToRead = 0);
static LRESULT CALLBACK EventCallback(UINT Event, LPARAM lParam1, LPARAM lParam2, void *pClientData);
static BOOL CALLBACK WindowMsgCallback(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *pResult, void *pUserData);
bool ProcessChatTag(const char *tag, bool bShow = true, int showDelay = 0, bool *pbRefuge = nullptr);
void OutputMessageLog(LPCTSTR text);
void GetPostComboBoxText(LPTSTR comm, size_t commSize, LPTSTR mail = nullptr, size_t mailSize = 0);
void ProcessLocalPost(LPCTSTR comm);
void RestorePopupWindowOpacity(HWND hwnd);
void RestorePopupWindowState(HWND hwnd);
static LRESULT CALLBACK PanelWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
static LRESULT CALLBACK PanelPopupWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
static LRESULT CALLBACK ForceWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
bool CreateForceWindowItems(HWND hwnd);
void SetOpacity(HWND hwnd, int opacityOrToggle);
LRESULT ForceWindowProcMain(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
static BOOL CALLBACK StreamCallback(BYTE *pData, void *pClientData);
// 設定ファイルの名前
tstring iniFileName_;
SETTINGS s_;
std::vector<NETWORK_SERVICE_ID_ELEM> ntsIDList_;
std::vector<RPL_ELEM> rplList_;
char cookie_[2048];
bool bDragAcceptFiles_;
// 勢い窓
HWND hPanel_;
HWND hPanelPopup_;
HWND hForce_;
HWND hForcePostEditBox_;
HBRUSH hbrForcePostEditBox_;
HFONT hForceFont_;
bool bDisplayLogList_;
std::vector<FORCE_ELEM> forceList_;
std::list<LOG_ELEM> logList_;
size_t logListDisplayedSize_;
bool bPendingTimerUpdateList_;
DWORD lastUpdateListTick_;
tstring lastCalcLeftText_;
tstring lastCalcMiddleText_;
int lastCalcLeftWidth_;
int lastCalcMiddleWidth_;
// コメント描画ウィンドウ
CCommentWindow commentWindow_;
DWORD forwardTick_;
std::thread syncThread_;
std::atomic_bool bQuitSyncThread_;
std::atomic_bool bPendingTimerForward_;
std::atomic_bool bHalfSkip_;
bool bFlipFlop_;
LONGLONG forwardOffset_;
LONGLONG forwardOffsetDelta_;
// 通信用
CJKStream channelStream_;
CJKStream jkStream_;
CJKTransfer jkTransfer_;
std::vector<char> channelBuf_;
std::vector<char> jkBuf_;
int currentJKToGet_;
int currentJK_;
int currentJKChatCount_;
int currentJKForceByChatCount_;
DWORD currentJKForceByChatCountTick_;
DWORD lastPostTick_;
TCHAR lastPostComm_[POST_COMMENT_MAX];
bool bPostToRefuge_;
bool bPostToRefugeInverted_;
// 過去ログ関係
std::atomic_bool bRecording_;
std::thread checkRecordingThread_;
HANDLE hQuitCheckRecordingEvent_;
bool bUsingLogfileDriver_;
bool bSetStreamCallback_;
bool bResyncComment_;
bool bNicoReceivingPastChat_;
bool bRefugeReceivingPastChat_;
int currentLogfileJK_;
HANDLE hLogfile_;
HANDLE hLogfileLock_;
CLogReader logReader_;
LONGLONG llftTot_;
LONGLONG llftTotLast_;
LONGLONG llftTotPending_;
DWORD totTick_;
DWORD totTickLast_;
DWORD totTickPending_;
DWORD totPcr_;
DWORD pcr_;
DWORD pcrTick_;
int pcrPid_;
int pcrPids_[8];
int pcrPidCounts_[8];
recursive_mutex_ streamLock_;
// 指定ファイル再生
bool bSpecFile_;
tstring tmpSpecFileName_;
tstring dropFileName_;
int dropFileTimeout_;
};