| 153 | } |
| 154 | |
| 155 | DWORD WINAPI PersistentPatch(LPVOID) |
| 156 | { |
| 157 | RegisterThreadName("BWAPI Persistent Patch"); |
| 158 | for (;;) |
| 159 | { |
| 160 | std::this_thread::sleep_for(std::chrono::milliseconds{ 300 }); |
| 161 | |
| 162 | // If version is correct |
| 163 | if ( isCorrectVersion ) |
| 164 | { |
| 165 | // dialog/menu layer |
| 166 | if ( BW::BWDATA::ScreenLayers[2].pUpdate != DrawDialogHook && |
| 167 | BW::BWDATA::ScreenLayers[2].pUpdate != nullptr ) |
| 168 | { |
| 169 | BW::pOldDrawDialogProc = BW::BWDATA::ScreenLayers[2].pUpdate; |
| 170 | BW::BWDATA::ScreenLayers[2].pUpdate = DrawDialogHook; |
| 171 | } |
| 172 | |
| 173 | // game layer |
| 174 | if ( BW::BWDATA::ScreenLayers[5].pUpdate != DrawHook && BW::BWDATA::ScreenLayers[5].pUpdate != nullptr ) |
| 175 | { |
| 176 | BW::pOldDrawGameProc = BW::BWDATA::ScreenLayers[5].pUpdate; |
| 177 | BW::BWDATA::ScreenLayers[5].pUpdate = DrawHook; |
| 178 | } |
| 179 | } |
| 180 | |
| 181 | // Only grab this info if we are not currently detouring the CreateWindowEx procedure |
| 182 | if ( !detourCreateWindow ) |
| 183 | { |
| 184 | if ( !ghMainWnd ) |
| 185 | ghMainWnd = SDrawGetFrameWindow(); |
| 186 | |
| 187 | if ( ghMainWnd ) |
| 188 | { |
| 189 | WNDPROC thisProc = (WNDPROC)GetWindowLong(ghMainWnd, GWLP_WNDPROC); |
| 190 | if ( thisProc != &WindowProc ) |
| 191 | { |
| 192 | wOriginalProc = thisProc; |
| 193 | SetWindowLong(ghMainWnd, GWLP_WNDPROC, (LONG)&WindowProc); |
| 194 | } |
| 195 | } |
| 196 | } |
| 197 | |
| 198 | // Checks and names all registered threads, does not need to be called elsewhere |
| 199 | CheckRegisteredThreads(); |
| 200 | } //loop |
| 201 | } |
| 202 | |
| 203 | void CheckAttachConsole() |
| 204 | { |
nothing calls this directly
no test coverage detected