Advertisement
Absol

Untitled

Sep 16th, 2016
910
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 107.61 KB | None | 0 0
  1. // Absol (d3scene.ru), Abs0l (d3scene.com)
  2. // 2016 All Right Reserved :)
  3. #define INI_USE_STACK 0
  4. #define WIN32_LEAN_AND_MEAN
  5. #include <stdexcept>
  6. #include <Windows.h>
  7. #include <string>
  8. #include <vector>
  9. #include <time.h>
  10. #include <eh.h>
  11. #include <Psapi.h>
  12. #include <string>
  13. #include <sstream>
  14. #include <iostream>
  15. #include <TlHelp32.h>
  16.  
  17. #include <exception>
  18. #include "ini.h"
  19. #include "verinfo.h"
  20. #include "INIReader.h"
  21. const char * absolfogclicker = "./AbsolFogClickWatcher.ini";
  22.  
  23.  
  24. #define IsKeyPressed(CODE) (GetAsyncKeyState(CODE) & 0x8000) > 0
  25.  
  26. using namespace std;
  27. typedef LONG    NTSTATUS;
  28.  
  29. typedef NTSTATUS( WINAPI *pNtQIT )( HANDLE, LONG, PVOID, ULONG, PULONG );
  30.  
  31. #define STATUS_SUCCESS    ((NTSTATUS)0x00000000L)
  32.  
  33. #define ThreadQuerySetWin32StartAddress 9
  34.  
  35.  
  36.  
  37.  
  38.  
  39.  
  40. union DWFP
  41. {
  42.     DWORD dw;
  43.     float fl;
  44. };
  45.  
  46. int GameID = 0;
  47.  
  48. int GameDll = 0;
  49.  
  50. HMODULE MainModule = 0;
  51.  
  52. BOOL FirstInitialized = FALSE;
  53.  
  54. int IsInGame = 0;
  55.  
  56. BOOL GameStarted = FALSE;
  57.  
  58. int pJassEnvAddress = 0;
  59.  
  60. int pW3XGlobalClass = 0;
  61.  
  62. int pPrintText2 = 0;
  63.  
  64. int GameVersion = 0x126a;
  65.  
  66. BOOL DetectRightClickOnlyHeroes = TRUE;
  67.  
  68. BOOL SkipIllusions = TRUE;
  69.  
  70. BOOL MinimapPingFogClick = FALSE;
  71.  
  72. BOOL DetectImpossibleClicks = FALSE;
  73.  
  74. BOOL DetectItemDestroyer = FALSE;
  75.  
  76. BOOL DetectOwnItems = FALSE;
  77.  
  78. BOOL DetectPointClicks = FALSE;
  79.  
  80. BOOL DetectMeepoKey = TRUE;
  81.  
  82. BOOL DebugLog = FALSE;
  83.  
  84. int DetectQuality = 2;
  85.  
  86. BOOL ExceptionFilterHooked = FALSE;
  87.  
  88. struct UnitSelected
  89. {
  90.     DWORD LatestTime[ 20 ];
  91.     int SelectCount;
  92.     int LatestPlayer;
  93.     int UnitAddr;
  94. };
  95.  
  96. struct FogHelper
  97. {
  98.     int UnitAddr;
  99.     BOOL FogState[ 20 ][ 2 ];
  100. };
  101.  
  102. vector<UnitSelected> ClickCount( 100000 );
  103.  
  104. vector<FogHelper> FogHelperList( 100000 );
  105.  
  106. HANDLE MainThread = NULL;
  107.  
  108. DWORD GetCurrentLocalTime( )
  109. {
  110.     time_t rawtime;
  111.     struct tm timeinfo;
  112.  
  113.     time( &rawtime );
  114.     localtime_s( &timeinfo, &rawtime );
  115.     return ( timeinfo.tm_hour * 3600 + timeinfo.tm_min * 60 + timeinfo.tm_sec ) * 1000;
  116. }
  117.  
  118. typedef unsigned int( __cdecl * pGetPlayerColor )( int whichPlayer );
  119. pGetPlayerColor GetPlayerColor;
  120.  
  121.  
  122. int         PLAYER_COLOR_RED = 0;
  123. int         PLAYER_COLOR_BLUE = 1;
  124. int         PLAYER_COLOR_CYAN = 2;
  125. int         PLAYER_COLOR_PURPLE = 3;
  126. int         PLAYER_COLOR_YELLOW = 4;
  127. int         PLAYER_COLOR_ORANGE = 5;
  128. int         PLAYER_COLOR_GREEN = 6;
  129. int         PLAYER_COLOR_PINK = 7;
  130. int         PLAYER_COLOR_LIGHT_GRAY = 8;
  131. int         PLAYER_COLOR_LIGHT_BLUE = 9;
  132. int         PLAYER_COLOR_AQUA = 10;
  133. int         PLAYER_COLOR_BROWN = 11;
  134.  
  135.  
  136. const char * GetPlayerColorString( int player )
  137. {
  138.     int c = GetPlayerColor( player );
  139.     if ( c == PLAYER_COLOR_RED )
  140.         return "|cffFF0202";
  141.     else if ( c == PLAYER_COLOR_BLUE )
  142.         return "|cff0041FF";
  143.     else if ( c == PLAYER_COLOR_CYAN )
  144.         return "|cff1BE5B8";
  145.     else if ( c == PLAYER_COLOR_PURPLE )
  146.         return "|cff530080";
  147.     else if ( c == PLAYER_COLOR_YELLOW )
  148.         return "|cffFFFC00";
  149.     else if ( c == PLAYER_COLOR_ORANGE )
  150.         return "|cffFE890D";
  151.     else if ( c == PLAYER_COLOR_GREEN )
  152.         return "|cff1FBF00";
  153.     else if ( c == PLAYER_COLOR_PINK )
  154.         return "|cffE45AAF";
  155.     else if ( c == PLAYER_COLOR_LIGHT_GRAY )
  156.         return "|cff949596";
  157.     else if ( c == PLAYER_COLOR_LIGHT_BLUE )
  158.         return "|cff7DBEF1";
  159.     else if ( c == PLAYER_COLOR_AQUA )
  160.         return "|cff0F6145";
  161.     else if ( c == PLAYER_COLOR_BROWN )
  162.         return "|cff4D2903";
  163.     else
  164.         return "|cffFFFFFF";
  165.  
  166. }
  167.  
  168. unsigned int GetPlayerColorUINT( int player )
  169. {
  170.     int c = GetPlayerColor( player );
  171.     if ( c == PLAYER_COLOR_RED )
  172.         return 0xffFF0202;
  173.     else if ( c == PLAYER_COLOR_BLUE )
  174.         return 0xff0041FF;
  175.     else if ( c == PLAYER_COLOR_CYAN )
  176.         return 0xff1BE5B8;
  177.     else if ( c == PLAYER_COLOR_PURPLE )
  178.         return 0xff530080;
  179.     else if ( c == PLAYER_COLOR_YELLOW )
  180.         return 0xffFFFC00;
  181.     else if ( c == PLAYER_COLOR_ORANGE )
  182.         return 0xffFE890D;
  183.     else if ( c == PLAYER_COLOR_GREEN )
  184.         return 0xff1FBF00;
  185.     else if ( c == PLAYER_COLOR_PINK )
  186.         return 0xffE45AAF;
  187.     else if ( c == PLAYER_COLOR_LIGHT_GRAY )
  188.         return 0xff949596;
  189.     else if ( c == PLAYER_COLOR_LIGHT_BLUE )
  190.         return 0xff7DBEF1;
  191.     else if ( c == PLAYER_COLOR_AQUA )
  192.         return 0xff0F6145;
  193.     else if ( c == PLAYER_COLOR_BROWN )
  194.         return 0xff4D2903;
  195.     else
  196.         return 0xffFFFFFF;
  197. }
  198.  
  199. char * DefaultString = "DefaultString\0\xa..........................................................................................................";
  200.  
  201. int GetObjectClassID( int unit_or_item_addr )
  202. {
  203.     if ( unit_or_item_addr )
  204.         return *( int* ) ( unit_or_item_addr + 0x30 );
  205.     return 0;
  206. }
  207.  
  208. UINT GetUnitOwnerSlot( int unitaddr )
  209. {
  210.     if ( unitaddr )
  211.         return *( int* ) ( unitaddr + 88 );
  212.     return -1;
  213. }
  214.  
  215. int pGlobalPlayerData;
  216.  
  217. void * GetGlobalPlayerData( )
  218. {
  219.     if ( *( int * ) ( pGlobalPlayerData ) > 0 )
  220.     {
  221.         return ( void * ) *( int* ) ( pGlobalPlayerData );
  222.     }
  223.     return nullptr;
  224. }
  225.  
  226.  
  227.  
  228. int GetPlayerByNumber( int number )
  229. {
  230.     void * arg1 = GetGlobalPlayerData( );
  231.     int result = -1;
  232.     if ( arg1 != nullptr && arg1 )
  233.     {
  234.         result = ( int ) arg1 + ( number * 4 ) + 0x58;
  235.  
  236.         if ( result )
  237.         {
  238.             result = *( int* ) result;
  239.         }
  240.         else
  241.         {
  242.             return 0;
  243.         }
  244.     }
  245.     return result;
  246. }
  247.  
  248. int GameTimeOffset = 0;
  249.  
  250. DWORD GetGameTime( )
  251. {
  252.     return *( DWORD* ) GameTimeOffset;
  253. }
  254.  
  255.  
  256. __inline void SleepGameTime( int sleeptime )
  257. {
  258.     int currentgametime = *( DWORD* ) GameTimeOffset;
  259.     int newgametime = 0;
  260.     if ( currentgametime > 0 )
  261.     {
  262.         while ( ( DWORD ) ( currentgametime + sleeptime ) > *( DWORD* ) GameTimeOffset )
  263.         {
  264.             Sleep( 10 );
  265.             if ( *( DWORD* ) GameTimeOffset == 0 )
  266.             {
  267.                 Sleep( sleeptime );
  268.                 break;
  269.             }
  270.         }
  271.     }
  272.     else
  273.     {
  274.         Sleep( sleeptime );
  275.     }
  276. }
  277.  
  278. BOOL PrintOrderName = FALSE;
  279.  
  280. char convitostr[ 126 ];
  281.  
  282. const char * ConvertIdToString( int id )
  283. {
  284.  
  285.     if ( !PrintOrderName )
  286.     {
  287.         return "-ORDER-";
  288.     }
  289.  
  290.     if ( id == 0xD000F ) { return "-ATTACK-"; }
  291.     if ( id == 0xD0010 ) { return "-attackground-"; }
  292.     if ( id == 0xD0011 ) { return "-attackonce-"; }
  293.     if ( id == 0xD01F2 ) { return "-awaken-"; }
  294.     if ( id == 0xD0012 || id == 0xD0003 ) { return "-MOVE-"; }
  295.     if ( id == 0xD0014 ) { return "-AImove-"; }
  296.     if ( id == 0xD0016 ) { return "-patrol-"; }
  297.     if ( id == 0xD0019 ) { return "-holdposition-"; }
  298.     if ( id == 0xD001A ) { return "-build-"; }
  299.     if ( id == 0xD001B ) { return "-humanbuild-"; }
  300.     if ( id == 0xD001C ) { return "-orcbuild-"; }
  301.     if ( id == 0xD001D ) { return "-nightelfbuild-"; }
  302.     if ( id == 0xD001E ) { return "-undeadbuild-"; }
  303.     if ( id == 0xD01F3 ) { return "-nagabuild-"; }
  304.     if ( id == 0xD001F ) { return "-resumebuild-"; }
  305.     if ( id == 0xD0021 ) { return "-dropitem-"; }
  306.     if ( id == 0xD004B ) { return "-board-"; }
  307.     if ( id == 0xD002F ) { return "-detectaoe-"; }
  308.     if ( id == 0xD000D ) { return "-getitem-"; }
  309.     if ( id == 0xD0032 ) { return "-harvest-"; }
  310.     if ( id == 0xD0035 ) { return "-autoharvestgold-"; }
  311.     if ( id == 0xD0036 ) { return "-autoharvestlumber-"; }
  312.     if ( id == 0xD0031 ) { return "-resumeharvesting-"; }
  313.     if ( id == 0xD0034 ) { return "-returnresources-"; }
  314.     if ( id == 0xD004C ) { return "-forceboard-"; }
  315.     if ( id == 0xD004E ) { return "-load-"; }
  316.     if ( id == 0xD004F ) { return "-unload-"; }
  317.     if ( id == 0xD0050 ) { return "-unloadall-"; }
  318.     if ( id == 0xD0051 ) { return "-unloadallinstant-"; }
  319.     if ( id == 0xD0052 ) { return "-loadcorpse-"; }
  320.     if ( id == 0xD0056 ) { return "-unloadallcorpses-"; }
  321.     if ( id == 0xD0055 ) { return "-loadcorpseinstant-"; }
  322.     if ( id == 0xD01F5 ) { return "-mount-"; }
  323.     if ( id == 0xD01F6 ) { return "-dismount-"; }
  324.     if ( id == 0xD0037 ) { return "-neutraldetectaoe-"; }
  325.     if ( id == 0xD00BD ) { return "-recharge-"; }
  326.     if ( id == 0xD0038 ) { return "-repair-"; }
  327.     if ( id == 0xD0039 ) { return "-repairon-"; }
  328.     if ( id == 0xD003A ) { return "-repairoff-"; }
  329.     if ( id == 0xD0047 ) { return "-revive-"; }
  330.     if ( id == 0xD0048 ) { return "-selfdestruct-"; }
  331.     if ( id == 0xD0049 ) { return "-selfdestructon-"; }
  332.     if ( id == 0xD004A ) { return "-selfdestructoff-"; }
  333.     if ( id == 0xD000C ) { return "-setrally-"; }
  334.     if ( id == 0xD0004 ) { return "-stop-"; }
  335.     if ( id == 0xD01F9 ) { return "-cloudoffog-"; }
  336.     if ( id == 0xD01FA ) { return "-controlmagic-"; }
  337.     if ( id == 0xD0057 ) { return "-defend-"; }
  338.     if ( id == 0xD0058 ) { return "-undefend-"; }
  339.     if ( id == 0xD0059 ) { return "-dispel-"; }
  340.     if ( id == 0xD005C ) { return "-flare-"; }
  341.     if ( id == 0xD005F ) { return "-heal-"; }
  342.     if ( id == 0xD0060 ) { return "-healon-"; }
  343.     if ( id == 0xD0061 ) { return "-healoff-"; }
  344.     if ( id == 0xD0062 ) { return "-innerfire-"; }
  345.     if ( id == 0xD0063 ) { return "-innerfireon-"; }
  346.     if ( id == 0xD0064 ) { return "-innerfireoff-"; }
  347.     if ( id == 0xD0065 ) { return "-invisibility-"; }
  348.     if ( id == 0xD01FE ) { return "-magicdefense-"; }
  349.     if ( id == 0xD01FF ) { return "-magicundefense-"; }
  350.     if ( id == 0xD0200 ) { return "-magicleash-"; }
  351.     if ( id == 0xD0067 ) { return "-militiaconvert-"; }
  352.     if ( id == 0xD02AB ) { return "-militiaunconvert-"; }
  353.     if ( id == 0xD0068 ) { return "-militia-"; }
  354.     if ( id == 0xD0069 ) { return "-militiaoff-"; }
  355.     if ( id == 0xD0201 ) { return "-phoenixfire-"; }
  356.     if ( id == 0xD0202 ) { return "-phoenixmorph-"; }
  357.     if ( id == 0xD006A ) { return "-polymorph-"; }
  358.     if ( id == 0xD006B ) { return "-slow-"; }
  359.     if ( id == 0xD006C ) { return "-slowon-"; }
  360.     if ( id == 0xD006D ) { return "-slowoff-"; }
  361.     if ( id == 0xD0203 ) { return "-spellsteal-"; }
  362.     if ( id == 0xD0204 ) { return "-spellstealon-"; }
  363.     if ( id == 0xD0205 ) { return "-spellstealoff-"; }
  364.     if ( id == 0xD006F ) { return "-tankdroppilot-"; }
  365.     if ( id == 0xD0070 ) { return "-tankloadpilot-"; }
  366.     if ( id == 0xD0071 ) { return "-tankpilot-"; }
  367.     if ( id == 0xD0072 ) { return "-townbellon-"; }
  368.     if ( id == 0xD0073 ) { return "-townbelloff-"; }
  369.     if ( id == 0xD0076 ) { return "-avatar-"; }
  370.     if ( id == 0xD0077 ) { return "-unavatar-"; }
  371.     if ( id == 0xD0206 ) { return "-banish-"; }
  372.     if ( id == 0xD0079 ) { return "-blizzard-"; }
  373.     if ( id == 0xD007A ) { return "-divineshield-"; }
  374.     if ( id == 0xD007B ) { return "-undivineshield-"; }
  375.     if ( id == 0xD0208 ) { return "-flamestrike-"; }
  376.     if ( id == 0xD007C ) { return "-holybolt-"; }
  377.     if ( id == 0xD026D ) { return "-manashieldon-"; }
  378.     if ( id == 0xD026E ) { return "-manashieldoff-"; }
  379.     if ( id == 0xD007D ) { return "-massteleport-"; }
  380.     if ( id == 0xD0209 ) { return "-summonphoenix-"; }
  381.     if ( id == 0xD007E ) { return "-resurrection-"; }
  382.     if ( id == 0xD007F ) { return "-thunderbolt-"; }
  383.     if ( id == 0xD0080 ) { return "-thunderclap-"; }
  384.     if ( id == 0xD0081 ) { return "-waterelemental-"; }
  385.     if ( id == 0xD020A ) { return "-ancestralspirit-"; }
  386.     if ( id == 0xD020B ) { return "-ancestralspirittarget-"; }
  387.     if ( id == 0xD0083 ) { return "-battlestations-"; }
  388.     if ( id == 0xD0084 ) { return "-berserk-"; }
  389.     if ( id == 0xD0085 ) { return "-bloodlust-"; }
  390.     if ( id == 0xD0086 ) { return "-bloodluston-"; }
  391.     if ( id == 0xD0087 ) { return "-bloodlustoff-"; }
  392.     if ( id == 0xD020D ) { return "-corporealform-"; }
  393.     if ( id == 0xD020E ) { return "-uncorporealform-"; }
  394.     if ( id == 0xD0088 ) { return "-devour-"; }
  395.     if ( id == 0xD020F ) { return "-disenchant-"; }
  396.     if ( id == 0xD008A ) { return "-ensnare-"; }
  397.     if ( id == 0xD008B ) { return "-ensnareon-"; }
  398.     if ( id == 0xD008C ) { return "-ensnareoff-"; }
  399.     if ( id == 0xD0210 ) { return "-etherealform-"; }
  400.     if ( id == 0xD0211 ) { return "-unetherealform-"; }
  401.     if ( id == 0xD0089 ) { return "-evileye-"; }
  402.     if ( id == 0xD008D ) { return "-healingward-"; }
  403.     if ( id == 0xD008E ) { return "-lightningshield-"; }
  404.     if ( id == 0xD008F ) { return "-purge-"; }
  405.     if ( id == 0xD0213 ) { return "-spiritlink-"; }
  406.     if ( id == 0xD0091 ) { return "-standdown-"; }
  407.     if ( id == 0xD0092 ) { return "-stasistrap-"; }
  408.     if ( id == 0xD0214 ) { return "-unstableconcoction-"; }
  409.     if ( id == 0xD0097 ) { return "-chainlightning-"; }
  410.     if ( id == 0xD0099 ) { return "-earthquake-"; }
  411.     if ( id == 0xD009A ) { return "-farsight-"; }
  412.     if ( id == 0xD0215 ) { return "-healingwave-"; }
  413.     if ( id == 0xD0216 ) { return "-hex-"; }
  414.     if ( id == 0xD009B ) { return "-mirrorimage-"; }
  415.     if ( id == 0xD009D ) { return "-shockwave-"; }
  416.     if ( id == 0xD009E ) { return "-spiritwolf-"; }
  417.     if ( id == 0xD009F ) { return "-stomp-"; }
  418.     if ( id == 0xD0217 ) { return "-voodoo-"; }
  419.     if ( id == 0xD0218 ) { return "-ward-"; }
  420.     if ( id == 0xD00A0 ) { return "-whirlwind-"; }
  421.     if ( id == 0xD00A1 ) { return "-windwalk-"; }
  422.     if ( id == 0xD00A2 ) { return "-unwindwalk-"; }
  423.     if ( id == 0xD00A3 ) { return "-ambush-"; }
  424.     if ( id == 0xD00A4 ) { return "-autodispel-"; }
  425.     if ( id == 0xD00A5 ) { return "-autodispelon-"; }
  426.     if ( id == 0xD00A6 ) { return "-autodispeloff-"; }
  427.     if ( id == 0xD00A7 ) { return "-barkskin-"; }
  428.     if ( id == 0xD00A8 ) { return "-barkskinon-"; }
  429.     if ( id == 0xD00A9 ) { return "-barkskinoff-"; }
  430.     if ( id == 0xD00AA ) { return "-bearform-"; }
  431.     if ( id == 0xD00AB ) { return "-unbearform-"; }
  432.     if ( id == 0xD00AC ) { return "-corrosivebreath-"; }
  433.     if ( id == 0xD00AE ) { return "-loadarcher-"; }
  434.     if ( id == 0xD00AF ) { return "-mounthippogryph-"; }
  435.     if ( id == 0xD021C ) { return "-coupleinstant-"; }
  436.     if ( id == 0xD021B ) { return "-coupletarget-"; }
  437.     if ( id == 0xD00B0 ) { return "-cyclone-"; }
  438.     if ( id == 0xD021D ) { return "-decouple-"; }
  439.     if ( id == 0xD00B1 ) { return "-detonate-"; }
  440.     if ( id == 0xD00B2 ) { return "-eattree-"; }
  441.     if ( id == 0xD00B3 ) { return "-entangle-"; }
  442.     if ( id == 0xD00B4 ) { return "-entangleinstant-"; }
  443.     if ( id == 0xD0219 ) { return "-autoentangle-"; }
  444.     if ( id == 0xD021A ) { return "-autoentangleinstant-"; }
  445.     if ( id == 0xD00B5 ) { return "-faeriefire-"; }
  446.     if ( id == 0xD00B6 ) { return "-faeriefireon-"; }
  447.     if ( id == 0xD00B7 ) { return "-faeriefireoff-"; }
  448.     if ( id == 0xD021F ) { return "-grabtree-"; }
  449.     if ( id == 0xD0220 ) { return "-manaflareon-"; }
  450.     if ( id == 0xD0221 ) { return "-manaflareoff-"; }
  451.     if ( id == 0xD0222 ) { return "-phaseshift-"; }
  452.     if ( id == 0xD0223 ) { return "-phaseshifton-"; }
  453.     if ( id == 0xD0224 ) { return "-phaseshiftoff-"; }
  454.     if ( id == 0xD0225 ) { return "-phaseshiftinstant-"; }
  455.     if ( id == 0xD00BB ) { return "-ravenform-"; }
  456.     if ( id == 0xD00BC ) { return "-unravenform-"; }
  457.     if ( id == 0xD00BD ) { return "-recharge-"; }
  458.     if ( id == 0xD00BE ) { return "-rechargeon-"; }
  459.     if ( id == 0xD00BF ) { return "-rechargeoff-"; }
  460.     if ( id == 0xD00C0 ) { return "-rejuvination-"; }
  461.     if ( id == 0xD00C1 ) { return "-renew-"; }
  462.     if ( id == 0xD00C2 ) { return "-renewon-"; }
  463.     if ( id == 0xD00C3 ) { return "-renewoff-"; }
  464.     if ( id == 0xD00C4 ) { return "-roar-"; }
  465.     if ( id == 0xD00C5 ) { return "-root-"; }
  466.     if ( id == 0xD00C6 ) { return "-unroot-"; }
  467.     if ( id == 0xD00D6 ) { return "-sentinel-"; }
  468.     if ( id == 0xD0228 ) { return "-taunt-"; }
  469.     if ( id == 0xD0229 ) { return "-vengeance-"; }
  470.     if ( id == 0xD022A ) { return "-vengeanceon-"; }
  471.     if ( id == 0xD022B ) { return "-vengeanceoff-"; }
  472.     if ( id == 0xD022C ) { return "-vengeanceinstant-"; }
  473.     if ( id == 0xD00F6 ) { return "-wispharvest-"; }
  474.     if ( id == 0xD022D ) { return "-blink-"; }
  475.     if ( id == 0xD00CB ) { return "-entanglingroots-"; }
  476.     if ( id == 0xD022E ) { return "-fanofknives-"; }
  477.     if ( id == 0xD00CD ) { return "-flamingarrowstarg-"; }
  478.     if ( id == 0xD00CE ) { return "-flamingarrows-"; }
  479.     if ( id == 0xD00CF ) { return "-unflamingarrows-"; }
  480.     if ( id == 0xD00D0 ) { return "-forceofnature-"; }
  481.     if ( id == 0xD00D1 ) { return "-immolation-"; }
  482.     if ( id == 0xD00D2 ) { return "-unimmolation-"; }
  483.     if ( id == 0xD00D3 ) { return "-manaburn-"; }
  484.     if ( id == 0xD00D4 ) { return "-metamorphosis-"; }
  485.     if ( id == 0xD00D5 ) { return "-scout-"; }
  486.     if ( id == 0xD022F ) { return "-shadowstrike-"; }
  487.     if ( id == 0xD0230 ) { return "-spiritofvengeance-"; }
  488.     if ( id == 0xD00D7 ) { return "-starfall-"; }
  489.     if ( id == 0xD00D8 ) { return "-tranquility-"; }
  490.     if ( id == 0xD0231 ) { return "-absorb-"; }
  491.     if ( id == 0xD00D9 ) { return "-acolyteharvest-"; }
  492.     if ( id == 0xD00DA ) { return "-antimagicshell-"; }
  493.     if ( id == 0xD0233 ) { return "-avengerform-"; }
  494.     if ( id == 0xD0234 ) { return "-unavengerform-"; }
  495.     if ( id == 0xD00DB ) { return "-blight-"; }
  496.     if ( id == 0xD0235 ) { return "-burrow-"; }
  497.     if ( id == 0xD0236 ) { return "-unburrow-"; }
  498.     if ( id == 0xD00DC ) { return "-cannibalize-"; }
  499.     if ( id == 0xD00DD ) { return "-cripple-"; }
  500.     if ( id == 0xD00DE ) { return "-curse-"; }
  501.     if ( id == 0xD00DF ) { return "-curseon-"; }
  502.     if ( id == 0xD00E0 ) { return "-curseoff-"; }
  503.     if ( id == 0xD0238 ) { return "-devourmagic-"; }
  504.     if ( id == 0xD023B ) { return "-flamingattacktarg-"; }
  505.     if ( id == 0xD023C ) { return "-flamingattack-"; }
  506.     if ( id == 0xD023D ) { return "-unflamingattack-"; }
  507.     if ( id == 0xD00E3 ) { return "-freezingbreath-"; }
  508.     if ( id == 0xD00E4 ) { return "-possession-"; }
  509.     if ( id == 0xD00E5 ) { return "-raisedead-"; }
  510.     if ( id == 0xD00E6 ) { return "-raisedeadon-"; }
  511.     if ( id == 0xD00E7 ) { return "-raisedeadoff-"; }
  512.     if ( id == 0xD00E8 ) { return "-instant-"; }
  513.     if ( id == 0xD023E ) { return "-replenish-"; }
  514.     if ( id == 0xD023F ) { return "-replenishon-"; }
  515.     if ( id == 0xD0240 ) { return "-replenishoff-"; }
  516.     if ( id == 0xD0241 ) { return "-replenishlife-"; }
  517.     if ( id == 0xD0242 ) { return "-replenishlifeon-"; }
  518.     if ( id == 0xD0243 ) { return "-replenishlifeoff-"; }
  519.     if ( id == 0xD0244 ) { return "-replenishmana-"; }
  520.     if ( id == 0xD0245 ) { return "-replenishmanaon-"; }
  521.     if ( id == 0xD0246 ) { return "-replenishmanaoff-"; }
  522.     if ( id == 0xD00E9 ) { return "-requestsacrifice-"; }
  523.     if ( id == 0xD00EA ) { return "-restoration-"; }
  524.     if ( id == 0xD00EB ) { return "-restorationon-"; }
  525.     if ( id == 0xD00EC ) { return "-restorationoff-"; }
  526.     if ( id == 0xD00ED ) { return "-sacrifice-"; }
  527.     if ( id == 0xD00EE ) { return "-stoneform-"; }
  528.     if ( id == 0xD00EF ) { return "-unstoneform-"; }
  529.     if ( id == 0xD00F1 ) { return "-unholyfrenzy-"; }
  530.     if ( id == 0xD00F2 ) { return "-unsummon-"; }
  531.     if ( id == 0xD00F3 ) { return "-web-"; }
  532.     if ( id == 0xD00F4 ) { return "-webon-"; }
  533.     if ( id == 0xD00F5 ) { return "-weboff-"; }
  534.     if ( id == 0xD00F9 ) { return "-animatedead-"; }
  535.     if ( id == 0xD00F7 ) { return "-auraunholy-"; }
  536.     if ( id == 0xD00F8 ) { return "-auravampiric-"; }
  537.     if ( id == 0xD0247 ) { return "-carrionscarabs-"; }
  538.     if ( id == 0xD0248 ) { return "-carrionscarabson-"; }
  539.     if ( id == 0xD0249 ) { return "-carrionscarabsoff-"; }
  540.     if ( id == 0xD024A ) { return "-carrionscarabsinstant-"; }
  541.     if ( id == 0xD00FA ) { return "-carrionswarm-"; }
  542.     if ( id == 0xD00FB ) { return "-darkritual-"; }
  543.     if ( id == 0xD00FC ) { return "-darksummoning-"; }
  544.     if ( id == 0xD00FD ) { return "-deathanddecay-"; }
  545.     if ( id == 0xD00FE ) { return "-deathcoil-"; }
  546.     if ( id == 0xD00FF ) { return "-deathpact-"; }
  547.     if ( id == 0xD0100 ) { return "-dreadlordinferno-"; }
  548.     if ( id == 0xD0101 ) { return "-frostarmor-"; }
  549.     if ( id == 0xD01EA ) { return "-frostarmoron-"; }
  550.     if ( id == 0xD01EB ) { return "-frostarmoroff-"; }
  551.     if ( id == 0xD0102 ) { return "-frostnova-"; }
  552.     if ( id == 0xD024B ) { return "-impale-"; }
  553.     if ( id == 0xD024C ) { return "-locustswarm-"; }
  554.     if ( id == 0xD0103 ) { return "-sleep-"; }
  555.     if ( id == 0xD0250 ) { return "-breathoffrost-"; }
  556.     if ( id == 0xD0116 ) { return "-creepanimatedead-"; }
  557.     if ( id == 0xD0117 ) { return "-creepdevour-"; }
  558.     if ( id == 0xD0118 ) { return "-creepheal-"; }
  559.     if ( id == 0xD0119 ) { return "-creephealon-"; }
  560.     if ( id == 0xD011A ) { return "-creephealoff-"; }
  561.     if ( id == 0xD011C ) { return "-creepthunderbolt-"; }
  562.     if ( id == 0xD011D ) { return "-creepthunderclap-"; }
  563.     if ( id == 0xD0251 ) { return "-frenzy-"; }
  564.     if ( id == 0xD0252 ) { return "-frenzyon-"; }
  565.     if ( id == 0xD0253 ) { return "-frenzyoff-"; }
  566.     if ( id == 0xD0254 ) { return "-mechanicalcritter-"; }
  567.     if ( id == 0xD0255 ) { return "-mindrot-"; }
  568.     if ( id == 0xD0109 ) { return "-gold2lumber-"; }
  569.     if ( id == 0xD010A ) { return "-lumber2gold-"; }
  570.     if ( id == 0xD0256 ) { return "-neutralinteract-"; }
  571.     if ( id == 0xD010B ) { return "-spies-"; }
  572.     if ( id == 0xD0258 ) { return "-preservation-"; }
  573.     if ( id == 0xD010F ) { return "-request_hero-"; }
  574.     if ( id == 0xD0259 ) { return "-sanctuary-"; }
  575.     if ( id == 0xD025A ) { return "-shadowsight-"; }
  576.     if ( id == 0xD025B ) { return "-spellshield-"; }
  577.     if ( id == 0xD025C ) { return "-spellshieldaoe-"; }
  578.     if ( id == 0xD025D ) { return "-spirittroll-"; }
  579.     if ( id == 0xD025E ) { return "-steal-"; }
  580.     if ( id == 0xD0260 ) { return "-attributemodskill-"; }
  581.     if ( id == 0xD0261 ) { return "-blackarrow-"; }
  582.     if ( id == 0xD0262 ) { return "-blackarrowon-"; }
  583.     if ( id == 0xD0263 ) { return "-blackarrowoff-"; }
  584.     if ( id == 0xD0264 ) { return "-breathoffire-"; }
  585.     if ( id == 0xD0265 ) { return "-charm-"; }
  586.     if ( id == 0xD0113 ) { return "-coldarrowstarg-"; }
  587.     if ( id == 0xD0114 ) { return "-coldarrows-"; }
  588.     if ( id == 0xD0115 ) { return "-uncoldarrows-"; }
  589.     if ( id == 0xD0267 ) { return "-doom-"; }
  590.     if ( id == 0xD0207 ) { return "-drain-"; }
  591.     if ( id == 0xD0269 ) { return "-drunkenhaze-"; }
  592.     if ( id == 0xD026A ) { return "-elementalfury-"; }
  593.     if ( id == 0xD026B ) { return "-forkedlightning-"; }
  594.     if ( id == 0xD026C ) { return "-howlofterror-"; }
  595.     if ( id == 0xD0108 ) { return "-inferno-"; }
  596.     if ( id == 0xD026F ) { return "-monsoon-"; }
  597.     if ( id == 0xD011E ) { return "-poisonarrowstarg-"; }
  598.     if ( id == 0xD011F ) { return "-poisonarrows-"; }
  599.     if ( id == 0xD0120 ) { return "-unpoisonarrows-"; }
  600.     if ( id == 0xD0270 ) { return "-silence-"; }
  601.     if ( id == 0xD0271 ) { return "-stampede-"; }
  602.     if ( id == 0xD0272 ) { return "-summongrizzly-"; }
  603.     if ( id == 0xD0273 ) { return "-summonquillbeast-"; }
  604.     if ( id == 0xD0274 ) { return "-summonwareagle-"; }
  605.     if ( id == 0xD0275 ) { return "-tornado-"; }
  606.     if ( id == 0xD0276 ) { return "-wateryminion-"; }
  607.     if ( id == 0xD02B6 ) { return "-acidbomb-"; }
  608.     if ( id == 0xD02B7 ) { return "-chemicalrage-"; }
  609.     if ( id == 0xD02B8 ) { return "-healingspray-"; }
  610.     if ( id == 0xD02B9 ) { return "-transmute-"; }
  611.     if ( id == 0xD02AC ) { return "-clusterrockets-"; }
  612.     if ( id == 0xD02B0 ) { return "-robogoblin-"; }
  613.     if ( id == 0xD02B1 ) { return "-unrobogoblin-"; }
  614.     if ( id == 0xD02B2 ) { return "-summonfactory-"; }
  615.     if ( id == 0xD02BE ) { return "-incineratearrow-"; }
  616.     if ( id == 0xD02BF ) { return "-incineratearrowon-"; }
  617.     if ( id == 0xD02C0 ) { return "-incineratearrowoff-"; }
  618.     if ( id == 0xD02BB ) { return "-lavamonster-"; }
  619.     if ( id == 0xD02BC ) { return "-soulburn-"; }
  620.     if ( id == 0xD02BD ) { return "-volcano-"; }
  621.     if ( id == 0xD0277 ) { return "-battleroar-"; }
  622.     if ( id == 0xD0278 ) { return "-channel-"; }
  623.     if ( id == 0xD0104 ) { return "-darkconversion-"; }
  624.     if ( id == 0xD0105 ) { return "-darkportal-"; }
  625.     if ( id == 0xD0106 ) { return "-fingerofdeath-"; }
  626.     if ( id == 0xD0107 ) { return "-firebolt-"; }
  627.     if ( id == 0xD0279 ) { return "-parasite-"; }
  628.     if ( id == 0xD027A ) { return "-parasiteon-"; }
  629.     if ( id == 0xD027B ) { return "-parasiteoff-"; }
  630.     if ( id == 0xD010D ) { return "-rainofchaos-"; }
  631.     if ( id == 0xD010E ) { return "-rainoffire-"; }
  632.     if ( id == 0xD0111 ) { return "-revenge-"; }
  633.     if ( id == 0xD0112 ) { return "-soulpreservation-"; }
  634.     if ( id == 0xD027C ) { return "-submerge-"; }
  635.     if ( id == 0xD027D ) { return "-unsubmerge-"; }
  636.     if ( id == 0xD0110 ) { return "-disassociate-"; }
  637.     if ( id == 0xD0296 ) { return "-neutralspell-"; }
  638.  
  639.     if ( id >= 0xD0022 && id <= 0xD0028 )
  640.         return "-dropitem-";
  641.     if ( id >= 0xD0028 && id <= 0xd002d )
  642.         return "-inventory-";
  643.     _itoa_s( id, convitostr, 126, 16 );
  644.     return convitostr;
  645. }
  646.  
  647.  
  648. BOOL LocalPlayerDisabled = FALSE;
  649.  
  650. BOOL FileExists( LPCTSTR fname )
  651. {
  652.     return ::GetFileAttributes( fname ) != DWORD( -1 );
  653. }
  654.  
  655. int GetLocalPlayerNumber( )
  656. {
  657.     if ( LocalPlayerDisabled )
  658.         return -2;
  659.  
  660.     void * gldata = GetGlobalPlayerData( );
  661.     if ( gldata != nullptr && gldata )
  662.     {
  663.         int playerslotaddr = ( int ) gldata + 0x28;
  664.         return ( int ) *( short * ) ( playerslotaddr );
  665.     }
  666.     else
  667.         return -1;
  668. }
  669.  
  670.  
  671.  
  672. UINT GetItemCountAndItemArray( int ** itemarray )
  673. {
  674.     int GlobalClassOffset = *( int* ) ( pW3XGlobalClass );
  675.     if ( GlobalClassOffset > 0 )
  676.     {
  677.         int ItemOffset1 = *( int* ) ( GlobalClassOffset + 0x3BC ) + 0x10;
  678.         int ItemCount = *( int* ) ( ItemOffset1 + 0x604 );
  679.         if ( ItemCount > 0 && ItemOffset1 > 0 )
  680.         {
  681.             *itemarray = ( int * ) *( int* ) ( ItemOffset1 + 0x608 );
  682.             return ItemCount;
  683.         }
  684.     }
  685.     *itemarray = 0;
  686.     return 0;
  687. }
  688.  
  689. int * GetUnitCountAndUnitArray( int ** unitarray )
  690. {
  691.     int GlobalClassOffset = *( int* ) ( pW3XGlobalClass );
  692.     if ( GlobalClassOffset )
  693.     {
  694.         int UnitsOffset1 = *( int* ) ( GlobalClassOffset + 0x3BC );
  695.         if ( UnitsOffset1 )
  696.         {
  697.             int * UnitsCount = ( int * ) ( UnitsOffset1 + 0x604 );
  698.             if ( *UnitsCount > 0 )
  699.             {
  700.                 *unitarray = ( int * ) *( int* ) ( UnitsOffset1 + 0x608 );
  701.                 return UnitsCount;
  702.             }
  703.         }
  704.     }
  705.  
  706.     *unitarray = 0;
  707.     return 0;
  708. }
  709.  
  710.  
  711. BOOL IsUnitDead( int unitaddr )
  712. {
  713.     if ( unitaddr )
  714.     {
  715.         unsigned int unitflag = *( unsigned int* ) ( unitaddr + 0x5C );
  716.         BOOL UnitNotDead = ( ( unitflag & 0x100u ) == 0 );
  717.         return UnitNotDead == FALSE;
  718.     }
  719.     return TRUE;
  720. }
  721.  
  722. BOOL IsUnitTower( int unitaddr )
  723. {
  724.     if ( unitaddr )
  725.     {
  726.         unsigned int unitflag = *( unsigned int* ) ( unitaddr + 0x5C );
  727.         BOOL UnitNotTower = ( ( unitflag & 0x10000u ) == 0 );
  728.         return UnitNotTower == FALSE;
  729.     }
  730.     return TRUE;
  731. }
  732.  
  733. BOOL UnitHaveItems( int unitaddr )
  734. {
  735.     if ( unitaddr )
  736.     {
  737.         return *( int* ) ( unitaddr + 0x1F8 ) > 0;
  738.     }
  739.     return FALSE;
  740. }
  741.  
  742. BOOL UnitHaveAttack( int unitaddr )
  743. {
  744.     if ( unitaddr )
  745.     {
  746.         return *( int* ) ( unitaddr + 0x1e8 ) > 0;
  747.     }
  748.     return FALSE;
  749. }
  750.  
  751.  
  752. BOOL IsHero( int unitaddr )
  753. {
  754.     if ( unitaddr )
  755.     {
  756.         unsigned int ishero = *( unsigned int* ) ( unitaddr + 48 );
  757.         ishero = ishero >> 24;
  758.         ishero = ishero - 64;
  759.         return ishero < 0x19;
  760.     }
  761.     return FALSE;
  762. }
  763.  
  764.  
  765. BOOL IsDetectedTower( int unitaddr )
  766. {
  767.     if ( unitaddr )
  768.     {
  769.         unsigned int unitflag = *( unsigned int* ) ( unitaddr + 0x5C );
  770.         unsigned int unitflag2 = *( unsigned int* ) ( unitaddr + 32 );
  771.         BOOL UnitNotTower = ( ( unitflag & 0x10000u ) == 0 );
  772.         if ( !UnitNotTower )
  773.         {
  774.             BOOL UnitNotVulnerable = ( ( unitflag2 & 0x8u ) == 0 );
  775.             BOOL UnitClickable = ( ( unitflag2 & 0x4u ) == 0 );
  776.             if ( !UnitNotVulnerable && !UnitClickable )
  777.             {
  778.                 return !IsHero( unitaddr ) && !UnitHaveItems( unitaddr ) && UnitHaveAttack( unitaddr );
  779.             }
  780.         }
  781.     }
  782.     return FALSE;
  783. }
  784.  
  785.  
  786. int UnitVtable = 0;
  787. int ItemVtable = 0;
  788.  
  789. BOOL IsOkayPtr( void * addr, unsigned int size )
  790. {
  791.     return !IsBadReadPtr( addr, size );
  792. }
  793.  
  794. float GetUnitTimer( int unitaddr )
  795. {
  796.     int unitdataddr = *( int* ) ( unitaddr + 0x28 );
  797.     if ( unitdataddr <= 0 )
  798.         return 0.0f;
  799. #ifdef BOTDEBUG
  800.     PrintDebugInfo( "CheckBadUnit - ENDCHExCK5" );
  801. #endif
  802.     if ( IsOkayPtr( ( void* ) ( unitdataddr + 0xA4 ), 4 ) )
  803.         return *( float* ) ( unitdataddr + 0xA0 );
  804.     return 0.0f;
  805. }
  806. int sub_6F03FA30_Addr = 0;
  807.  
  808. __declspec( naked ) int __fastcall sub_6F03FA30( UINT a1, UINT a2 )
  809. {
  810.     __asm
  811.     {
  812.         JMP sub_6F03FA30_Addr;
  813.     }
  814. }
  815.  
  816.  
  817. BOOL IsNotBadUnit( int unitaddr, BOOL onlymemcheck = FALSE )
  818. {
  819.  
  820.     if ( unitaddr > 0 && IsOkayPtr( ( void* ) unitaddr, 0x290 ) )
  821.     {
  822.         int xaddr = GameDll + 0x931934;
  823.         int xaddraddr = ( int ) &xaddr;
  824.  
  825.  
  826.  
  827.         if ( *( BYTE* ) xaddraddr != *( BYTE* ) unitaddr )
  828.             return FALSE;
  829.         else if ( *( BYTE* ) ( xaddraddr + 1 ) != *( BYTE* ) ( unitaddr + 1 ) )
  830.             return FALSE;
  831.         else if ( *( BYTE* ) ( xaddraddr + 2 ) != *( BYTE* ) ( unitaddr + 2 ) )
  832.             return FALSE;
  833.         else if ( *( BYTE* ) ( xaddraddr + 3 ) != *( BYTE* ) ( unitaddr + 3 ) )
  834.             return FALSE;
  835.  
  836.  
  837.         if ( !IsOkayPtr( ( void* ) ( unitaddr + 0x5C ),4 ) )
  838.         {
  839.             return FALSE;
  840.         }
  841.  
  842.         if ( onlymemcheck )
  843.             return TRUE;
  844.  
  845.         unsigned int isdolbany = *( unsigned int* ) ( unitaddr + 0x5C );
  846.  
  847.         BOOL returnvalue = isdolbany != 0x1001u && !IsUnitDead( unitaddr ) && ( isdolbany & 0x40000000u ) == 0;
  848.  
  849.  
  850.         if ( returnvalue )
  851.         {
  852.             if ( *( BYTE * ) ( unitaddr + 32 ) & 2 )
  853.             {
  854.                 float unittimer = GetUnitTimer( unitaddr );
  855.  
  856.                 if ( unittimer > 2.0 )
  857.                 {
  858.                     int testval = *( UINT* ) ( unitaddr + 12 ) & *( UINT* ) ( unitaddr + 16 );
  859.                     if ( testval != -1 && *( UINT* ) ( unitaddr + 12 ) != -1 && *( UINT* ) ( unitaddr + 16 ) != -1 )
  860.                     {
  861.                         int valnew = sub_6F03FA30( *( UINT* ) ( unitaddr + 12 ), *( UINT* ) ( unitaddr + 16 ) );
  862.                         int val2 = 0;
  863.                         if ( *( UINT * ) ( valnew + 12 ) == 727803756 )
  864.                             val2 = valnew;
  865.                         if ( val2 )
  866.                         {
  867.                             if ( !*( int * ) ( val2 + 32 ) )
  868.                             {
  869.                                 return TRUE;
  870.                             }
  871.                         }
  872.                     }
  873.                 }
  874.             }
  875.  
  876.         }
  877.     }
  878.  
  879.     return FALSE;
  880. }
  881.  
  882. BOOL IsNotBadItem( int itemaddr, BOOL onlymemcheck = FALSE )
  883. {
  884.     if ( itemaddr > 0 )
  885.     {
  886.         int xaddraddr = ( int ) &ItemVtable;
  887.  
  888.         if ( *( BYTE* ) xaddraddr != *( BYTE* ) itemaddr )
  889.             return FALSE;
  890.         else if ( *( BYTE* ) ( xaddraddr + 1 ) != *( BYTE* ) ( itemaddr + 1 ) )
  891.             return FALSE;
  892.         else if ( *( BYTE* ) ( xaddraddr + 2 ) != *( BYTE* ) ( itemaddr + 2 ) )
  893.             return FALSE;
  894.         else if ( *( BYTE* ) ( xaddraddr + 3 ) != *( BYTE* ) ( itemaddr + 3 ) )
  895.             return FALSE;
  896.  
  897.  
  898.  
  899.         if ( *( int * ) ( itemaddr + 0x20 ) & 1 )
  900.             return FALSE;
  901.  
  902.         float hitpoint = *( float * ) ( itemaddr + 0x58 );
  903.  
  904.         return hitpoint != 0.0f;
  905.     }
  906.  
  907.     return FALSE;
  908. }
  909.  
  910.  
  911.  
  912.  
  913. typedef int( __cdecl * pPlayer )( int number );
  914. pPlayer PlayerReal;
  915.  
  916. int Player( int number )
  917. {
  918.     int returnplayer = PlayerReal( number );
  919.     if ( returnplayer >= 0x10000 )
  920.         return returnplayer;
  921.     return -1;
  922. }
  923.  
  924.  
  925. int IsUnitVisibledAddr = 0;
  926.  
  927. BOOL __declspec( naked ) __cdecl IsUnitVisibled126a( int unitaddr, int player )
  928. {
  929.     __asm
  930.     {
  931.         MOV ECX, [ ESP + 0x4 ];
  932.         PUSH ESI;
  933.         MOV EAX, ECX;
  934.         JMP IsUnitVisibledAddr;
  935.     }
  936. }
  937.  
  938. BOOL __declspec( naked ) __cdecl IsUnitVisibled127a( int unitaddr, int player )
  939. {
  940.     __asm
  941.     {
  942.         PUSH EBP;
  943.         MOV EBP, ESP;
  944.         MOV ECX, [ EBP + 0x8 ];
  945.         PUSH ESI;
  946.         MOV EAX, ECX;
  947.         JMP IsUnitVisibledAddr;
  948.     }
  949. }
  950.  
  951. BOOL __cdecl IsUnitVisibled( int unitaddr, int player )
  952. {
  953.     if ( !unitaddr || !player )
  954.         return TRUE;
  955.     if ( GameVersion == 0x126a )
  956.         return IsUnitVisibled126a( unitaddr, player );
  957.     else if ( GameVersion == 0x127a )
  958.         return IsUnitVisibled127a( unitaddr, player );
  959.     return TRUE;
  960. }
  961.  
  962. int IsUnitSelectedAddr = 0;
  963.  
  964.  
  965. BOOL __declspec( naked ) __cdecl IsUnitSelected126a( int unitaddr, int player )
  966. {
  967.     __asm
  968.     {
  969.         MOV ECX, [ ESP + 0x4 ];
  970.         PUSH EDI;
  971.         MOV EAX, ECX;
  972.         JMP IsUnitSelectedAddr;
  973.     }
  974. }
  975.  
  976. BOOL __declspec( naked ) __cdecl IsUnitSelected127a( int unitaddr, int player )
  977. {
  978.     __asm
  979.     {
  980.         PUSH EBP;
  981.         MOV EBP, ESP;
  982.         MOV ECX, [ EBP + 0x8 ];
  983.         PUSH ESI;
  984.         MOV EAX, ECX;
  985.         JMP IsUnitSelectedAddr;
  986.     }
  987. }
  988.  
  989. BOOL __cdecl IsUnitSelected( int unitaddr, int player )
  990. {
  991.     if ( !unitaddr || !player )
  992.         return FALSE;
  993.     if ( GameVersion == 0x126a )
  994.         return IsUnitSelected126a( unitaddr, player );
  995.     else if ( GameVersion == 0x127a )
  996.         return IsUnitSelected127a( unitaddr, player );
  997.     return FALSE;
  998. }
  999.  
  1000. char PrintBuffer[ 2048 ];
  1001.  
  1002. DWORD GAME_PrintToScreen = 0;
  1003.  
  1004. DWORD StartGameTime = 0;
  1005.  
  1006. BOOL LogEnabled = FALSE;
  1007.  
  1008. char LogBuffer[ 2048 ];
  1009.  
  1010. FILE * logfile;
  1011.  
  1012. void WatcherLog( const char * format, ... )
  1013. {
  1014.     if ( !LogEnabled )
  1015.         return;
  1016.     if ( !logfile )
  1017.         return;
  1018.     /*char buffer[ 256 ]; va_list args; va_start( args , format );
  1019.     vsprintf_s( buffer , 256 , format , args ); va_end( args );
  1020.     int lentowrite = strlen( buffer );
  1021.     fwrite( &buffer , lentowrite , 1 , logfile ); fflush( logfile );*/
  1022.     va_list args; va_start( args, format ); vfprintf_s( logfile, format, args ); va_end( args ); fflush( logfile );
  1023. }
  1024.  
  1025. DWORD ActionTime = GetTickCount( );
  1026.  
  1027. void AddStringToLogFile( const char * line )
  1028. {
  1029.     int seconds = ( int ) ( ActionTime / 1000 ) % 60;
  1030.     int minutes = ( int ) ( ( ActionTime / ( 1000 * 60 ) ) % 60 );
  1031.     int hours = ( int ) ( ( ActionTime / ( 1000 * 60 * 60 ) ) % 24 );
  1032.     WatcherLog( "[%.2d:%.2d:%.2d] : %s\n", hours, minutes, seconds, line );
  1033. }
  1034.  
  1035. void DisplayText( char *szText, float fDuration )
  1036. {
  1037.  
  1038.     DWORD dwDuration = *( ( DWORD * ) &fDuration );
  1039.  
  1040.     if ( LogEnabled )
  1041.     {
  1042.         AddStringToLogFile( szText );
  1043.     }
  1044.  
  1045.     if ( GameStarted && *( BOOL* ) IsInGame )
  1046.     {
  1047.         __asm
  1048.         {
  1049.             PUSH 0xFFFFFFFF;
  1050.             PUSH fDuration;
  1051.             PUSH szText;
  1052.             MOV     ECX, [ pW3XGlobalClass ];
  1053.             MOV     ECX, [ ECX ];
  1054.             MOV     EAX, pPrintText2;
  1055.             CALL    EAX;
  1056.         }
  1057.     }
  1058. }
  1059.  
  1060.  
  1061. DWORD latestcheck = GetTickCount( );
  1062.  
  1063.  
  1064. int GetSelectedItem( int slot )
  1065. {
  1066.     int plr = GetPlayerByNumber( slot );
  1067.     if ( plr != -1 && plr )
  1068.     {
  1069.         int itemaddr;
  1070.         __asm
  1071.         {
  1072.             MOV EAX, plr;
  1073.             MOV ECX, DWORD PTR DS : [ EAX + 0x34 ];
  1074.             CMP ECX, 0;
  1075.             JNE NORET;
  1076.             MOV EAX, 0;
  1077.             ret;
  1078.             NORET:
  1079.             MOV EAX, DWORD PTR DS : [ ECX + 0x1A8 ];
  1080.             MOV itemaddr, EAX;
  1081.         }
  1082.  
  1083.         return itemaddr;
  1084.     }
  1085.  
  1086.     return NULL;
  1087. }
  1088.  
  1089. int UnitDetectionMethod = 3;
  1090.  
  1091. int GetSelectedUnitCount( int slot )
  1092. {
  1093.     int plr = GetPlayerByNumber( slot );
  1094.     if ( plr != -1 && plr )
  1095.     {
  1096.         int PlayerData1 = *( int* ) ( plr + 0x34 );
  1097.         if ( PlayerData1 )
  1098.         {
  1099.             int unit1 = *( int* ) ( PlayerData1 + 0x1E0 );
  1100.             int unit2 = *( int* ) ( PlayerData1 + 0x1A4 );
  1101.             int unitcount = *( int * ) ( PlayerData1 + 0x10 );
  1102.             int unitcount2 = *( int * ) ( PlayerData1 + 0x1D4 );
  1103.  
  1104.             if ( unit1 != NULL && unit2 != NULL )
  1105.             {
  1106.                 if ( unitcount == unitcount2 )
  1107.                 {
  1108.                     return unitcount;
  1109.                 }
  1110.                 return unitcount2;
  1111.             }
  1112.  
  1113.         }
  1114.     }
  1115.  
  1116.     return NULL;
  1117. }
  1118.  
  1119. int GetSelectedUnit( int slot )
  1120. {
  1121.  
  1122.     int plr = GetPlayerByNumber( slot );
  1123.     if ( plr != -1 && plr )
  1124.     {
  1125.         int PlayerData1 = *( int* ) ( plr + 0x34 );
  1126.         if ( PlayerData1 )
  1127.         {
  1128.             int unit1 = *( int* ) ( PlayerData1 + 0x1E0 );
  1129.             int unit2 = *( int* ) ( PlayerData1 + 0x1A4 );
  1130.             int unitcount = *( int * ) ( PlayerData1 + 0x10 );
  1131.             int unitcount2 = *( int * ) ( PlayerData1 + 0x1D4 );
  1132.  
  1133.             if ( UnitDetectionMethod == 1 )
  1134.             {
  1135.                 int unitaddr = unit1;
  1136.                 if ( unitaddr > 0 && unitcount == 1 && unitcount2 == 1 )
  1137.                 {
  1138.                     if ( IsNotBadUnit( unitaddr ) && IsUnitSelected( unitaddr, Player( slot ) ) )
  1139.                     {
  1140.                         return unitaddr;
  1141.                     }
  1142.                 }
  1143.             }
  1144.             else if ( UnitDetectionMethod == 2 )
  1145.             {
  1146.                 int unitaddr = unit2;
  1147.                 if ( unitaddr > 0 && unitcount == 1 && unitcount2 == 1 )
  1148.                 {
  1149.                     if ( IsNotBadUnit( unitaddr ) && IsUnitSelected( unitaddr, Player( slot ) ) )
  1150.                     {
  1151.                         return unitaddr;
  1152.                     }
  1153.                 }
  1154.             }
  1155.             else if ( UnitDetectionMethod == 3 )
  1156.             {
  1157.                 if ( unit1 == unit2 )
  1158.                 {
  1159.                     int unitaddr = unit1;
  1160.                     if ( unitaddr > 0 && unitcount == 1 && unitcount2 == 1 )
  1161.                     {
  1162.                         if ( IsNotBadUnit( unitaddr ) && IsUnitSelected( unitaddr, Player( slot ) ) )
  1163.                         {
  1164.                             return unitaddr;
  1165.                         }
  1166.                     }
  1167.                 }
  1168.             }
  1169.  
  1170.         }
  1171.         return NULL;
  1172.     }
  1173.     return NULL;
  1174. }
  1175.  
  1176.  
  1177.  
  1178.  
  1179. //sub_6F32C880 126a
  1180. //sub_6F327020 127a
  1181. typedef int( __fastcall * p_GetTypeInfo )( int unit_item_code, int unused );
  1182. p_GetTypeInfo GetTypeInfo = NULL;
  1183.  
  1184. //sub_6F2F8F90 126a
  1185. //sub_6F34F730 127a
  1186. typedef char *( __fastcall * p_GetPlayerName )( int a1, int a2 );
  1187. p_GetPlayerName GetPlayerName = NULL;
  1188.  
  1189.  
  1190. char * GetObjectNameByID( int clid )
  1191. {
  1192.     if ( clid > 0 )
  1193.     {
  1194.         int v3 = GetTypeInfo( clid, 0 );
  1195.         int v4, v5;
  1196.         if ( v3 && ( v4 = *( int * ) ( v3 + 40 ) ) != 0 )
  1197.         {
  1198.             v5 = v4 - 1;
  1199.             if ( v5 >= ( unsigned int ) 0 )
  1200.                 v5 = 0;
  1201.             return ( char * ) *( int * ) ( *( int * ) ( v3 + 44 ) + 4 * v5 );
  1202.         }
  1203.         else
  1204.         {
  1205.             return DefaultString;
  1206.         }
  1207.     }
  1208.     return DefaultString;
  1209. }
  1210.  
  1211.  
  1212.  
  1213.  
  1214.  
  1215. char * GetObjectName( int objaddress )
  1216. {
  1217.     return GetObjectNameByID( GetObjectClassID( objaddress ) );
  1218. }
  1219.  
  1220.  
  1221.  
  1222. int CreateJassNativeHook( int oldaddress, int newaddress )
  1223. {
  1224.     int FirstAddress = *( int * ) pJassEnvAddress;
  1225.     if ( FirstAddress )
  1226.     {
  1227.         FirstAddress = *( int * ) ( FirstAddress + 20 );
  1228.         if ( FirstAddress )
  1229.         {
  1230.  
  1231.             FirstAddress = *( int * ) ( FirstAddress + 32 );
  1232.             if ( FirstAddress )
  1233.             {
  1234.  
  1235.                 int NextAddress = FirstAddress;
  1236.  
  1237.                 while ( TRUE )
  1238.                 {
  1239.                     if ( *( int * ) ( NextAddress + 12 ) == oldaddress )
  1240.                     {
  1241.                         *( int * ) ( NextAddress + 12 ) = newaddress;
  1242.  
  1243.                         return NextAddress + 12;
  1244.                     }
  1245.  
  1246.                     NextAddress = *( int* ) NextAddress;
  1247.  
  1248.                     if ( NextAddress == FirstAddress || NextAddress <= 0 )
  1249.                         break;
  1250.                 }
  1251.             }
  1252.         }
  1253.  
  1254.     }
  1255.     return 0;
  1256. }
  1257.  
  1258. typedef int( __cdecl * pGetSpellAbilityId )( );
  1259. pGetSpellAbilityId GetSpellAbilityId_real;
  1260. int pRecoveryJassNative1 = 0;
  1261.  
  1262. typedef int( __cdecl * pGetTriggerEventId )( );
  1263. pGetTriggerEventId GetTriggerEventId_real;
  1264. int pRecoveryJassNative2 = 0;
  1265.  
  1266. typedef int( __cdecl * pGetIssuedOrderId )( );
  1267. pGetIssuedOrderId GetIssuedOrderId_real;
  1268. int pRecoveryJassNative3 = 0;
  1269.  
  1270. typedef int( __cdecl * pGetSpellAbilityUnit )( );
  1271. pGetSpellAbilityUnit GetSpellAbilityUnit_real;
  1272. int pRecoveryJassNative4 = 0;
  1273.  
  1274. typedef int( __cdecl * pGetAttacker )( );
  1275. pGetAttacker GetAttacker_real;
  1276. int pRecoveryJassNative5 = 0;
  1277.  
  1278. typedef int( __cdecl * pGetSpellTargetUnit )( );
  1279. pGetSpellTargetUnit GetSpellTargetUnit;
  1280.  
  1281. typedef DWFP( __cdecl * pGetSpellTargetX )( );
  1282. pGetSpellTargetX GetSpellTargetX;
  1283.  
  1284. typedef DWFP( __cdecl * pGetSpellTargetY )( );
  1285. pGetSpellTargetY GetSpellTargetY;
  1286.  
  1287. typedef int( __fastcall * pGetHandleUnitAddress ) ( int HandleID, int unused );
  1288. pGetHandleUnitAddress GetHandleUnitAddress;
  1289. pGetHandleUnitAddress GetHandleItemAddress;
  1290.  
  1291. typedef BOOL( __cdecl * pIsPlayerEnemy )( int whichPlayer, int otherPlayer );
  1292. pIsPlayerEnemy IsPlayerEnemyReal;
  1293.  
  1294. typedef int( __cdecl * pGetPlayerController )( int whichPlayer );
  1295. pGetPlayerController GetPlayerController;
  1296.  
  1297. typedef int( __cdecl * pGetPlayerSlotState )( int whichPlayer );
  1298. pGetPlayerSlotState GetPlayerSlotState;
  1299.  
  1300.  
  1301. BOOL __cdecl IsPlayerEnemy( int player1, int player2 )
  1302. {
  1303.     if ( player1 != player2 )
  1304.     {
  1305.         if ( player1 > 0 && player2 > 0 )
  1306.         {
  1307.             return IsPlayerEnemyReal( player1, player2 ) && IsPlayerEnemyReal( player2, player1 );
  1308.         }
  1309.     }
  1310.     return FALSE;
  1311. }
  1312.  
  1313. typedef int( __cdecl * pGetTriggerUnit )( );
  1314. pGetTriggerUnit GetTriggerUnit;
  1315.  
  1316. typedef int( __cdecl * pGetOrderTargetUnit )( );
  1317. pGetOrderTargetUnit GetOrderTargetUnit;
  1318.  
  1319. typedef int( __cdecl * pGetOrderTargetItem )( );
  1320. pGetOrderTargetItem GetOrderTargetItem;
  1321.  
  1322. typedef DWFP( __cdecl * pGetOrderPointX )( );
  1323. pGetOrderPointX GetOrderPointX;
  1324.  
  1325. typedef DWFP( __cdecl * pGetOrderPointY )( );
  1326. pGetOrderPointY GetOrderPointY;
  1327.  
  1328.  
  1329.  
  1330.  
  1331. typedef BOOL( __cdecl * pIsFoggedToPlayer )( float *x, float *y, int whichPlayer );
  1332. pIsFoggedToPlayer IsFoggedToPlayerReal;
  1333.  
  1334. int GetItemOwner( int itemaddr )
  1335. {
  1336.     if ( itemaddr )
  1337.         return  *( int* ) ( itemaddr + 0x74 );
  1338.     return 0;
  1339. }
  1340.  
  1341. BOOL __cdecl IsFoggedToPlayerMy( float * pX, float * pY, int player )
  1342. {
  1343.     // CENTER
  1344.     float x1 = *pX;
  1345.     float y1 = *pY;
  1346.     // RIGHT
  1347.     float x2 = x1 + 128;
  1348.     float y2 = y1;
  1349.     // LEFT
  1350.     float x3 = x1 - 128;
  1351.     float y3 = y1;
  1352.     // TOP
  1353.     float x4 = x1;
  1354.     float y4 = y1 + 128;
  1355.     // BOT
  1356.     float x5 = x1;
  1357.     float y5 = y1 - 128;
  1358.  
  1359.  
  1360.  
  1361.     BOOL CheckCenter = IsFoggedToPlayerReal( &x1, &y1, player );
  1362.  
  1363.     if ( DetectQuality >= 2 )
  1364.     {
  1365.         BOOL CheckRight = IsFoggedToPlayerReal( &x2, &y2, player );
  1366.         BOOL CheckLeft = IsFoggedToPlayerReal( &x3, &y3, player );
  1367.         BOOL CheckTop = IsFoggedToPlayerReal( &x4, &y4, player );
  1368.         BOOL CheckBot = IsFoggedToPlayerReal( &x5, &y5, player );
  1369.         if ( DetectQuality >= 3 )
  1370.         {
  1371.             return CheckCenter && CheckRight && CheckLeft && CheckTop && CheckBot;
  1372.         }
  1373.         return CheckCenter && CheckRight && CheckLeft && CheckTop && CheckBot;
  1374.     }
  1375.     return CheckCenter;
  1376. }
  1377.  
  1378. DWORD LatestAbilSpell = GetTickCount( );
  1379.  
  1380.  
  1381. void GetUnitLocation2D( int unitaddr, float * x, float * y )
  1382. {
  1383.     if ( unitaddr )
  1384.     {
  1385.         *x = *( float* ) ( unitaddr + 0x284 );
  1386.         *y = *( float* ) ( unitaddr + 0x288 );
  1387.     }
  1388.     else
  1389.     {
  1390.         *x = 0.0;
  1391.         *y = 0.0;
  1392.     }
  1393. }
  1394.  
  1395.  
  1396. void GetItemLocation2D( int itemaddr, float * x, float * y )
  1397. {
  1398.     if ( itemaddr )
  1399.     {
  1400.         int iteminfo = *( int * ) ( itemaddr + 0x28 );
  1401.         if ( iteminfo )
  1402.         {
  1403.             *x = *( float* ) ( iteminfo + 0x88 );
  1404.             *y = *( float* ) ( iteminfo + 0x8C );
  1405.         }
  1406.         else
  1407.         {
  1408.             *x = 0.0;
  1409.             *y = 0.0;
  1410.         }
  1411.     }
  1412.     else
  1413.     {
  1414.         *x = 0.0;
  1415.         *y = 0.0;
  1416.     }
  1417. }
  1418.  
  1419.  
  1420. float Distance( float x1, float y1, float x2, float y2 )
  1421. {
  1422.     return ( float ) sqrt( ( ( double ) x2 - ( double ) x1 )*( ( double ) x2 - ( double ) x1 ) + ( ( double ) y2 - ( double ) y1 )*( ( double ) y2 - ( double ) y1 ) );
  1423. }
  1424.  
  1425. float pingduration = 1.5;
  1426.  
  1427. typedef void( __cdecl * pPingMinimapEx )( float *x, float *y, float *duration, int red, int green, int blue, BOOL extraEffects );
  1428. pPingMinimapEx PingMinimapEx;
  1429.  
  1430. void __cdecl PingMinimapMy( float *x, float *y, float *duration, int red, int green, int blue, BOOL extraEffects )
  1431. {
  1432.     float newx = *x + ( float ) ( -200 + rand( ) % 200 );
  1433.     float newy = *y + ( float ) ( -200 + rand( ) % 200 );
  1434.  
  1435.     return PingMinimapEx( &newx, &newy, &pingduration, red, green, blue, extraEffects );
  1436. }
  1437.  
  1438. int GetItemByXY( float x, float y, int player )
  1439. {
  1440.     int * itemsarray = 0;
  1441.     int itemsCount = GetItemCountAndItemArray( &itemsarray );
  1442.     if ( itemsCount > 0 && itemsarray )
  1443.     {
  1444.         for ( int i = 0; i < itemsCount; i++ )
  1445.         {
  1446.             if ( itemsarray[ i ] )
  1447.             {
  1448.                 if ( IsNotBadItem( itemsarray[ i ] ) )
  1449.                 {
  1450.                     float itemx = 0.0f, itemy = 0.0f;
  1451.                     GetItemLocation2D( itemsarray[ i ], &itemx, &itemy );
  1452.                     if ( Distance( itemx, itemy, x, y ) < 19 )
  1453.                         return itemsarray[ i ];
  1454.                 }
  1455.             }
  1456.         }
  1457.     }
  1458.     return 0;
  1459. }
  1460.  
  1461.  
  1462. BOOL ImpossibleClick = FALSE;
  1463.  
  1464. int GetUnitByXY( float x, float y, int player, BOOL onlyunits = FALSE )
  1465. {
  1466.     if ( player == GetLocalPlayerNumber( ) )
  1467.         return 0;
  1468.     int * unitsarray = 0;
  1469.     int * UnitsCount = GetUnitCountAndUnitArray( &unitsarray );
  1470.     if ( UnitsCount > 0 && * UnitsCount > 0 && unitsarray )
  1471.     {
  1472.         for ( int i = 0; i < *UnitsCount; i++ )
  1473.         {
  1474.             if ( unitsarray[ i ] )
  1475.             {
  1476.                 if ( IsNotBadUnit( unitsarray[ i ] ) )
  1477.                 {
  1478.                     if ( IsHero( unitsarray[ i ] ) || ( DetectImpossibleClicks && IsDetectedTower( unitsarray[ i ] ) ) || ( !DetectRightClickOnlyHeroes && !IsUnitTower( unitsarray[ i ] ) ) )
  1479.                     {
  1480.                         if ( player != GetUnitOwnerSlot( unitsarray[ i ] ) )
  1481.                         {
  1482.                             int hPlayerFinder = Player( player );
  1483.                             int hPlayerOwner = Player( GetUnitOwnerSlot( unitsarray[ i ] ) );
  1484.  
  1485.                             if ( hPlayerFinder && hPlayerOwner )
  1486.                             {
  1487.                                 if ( IsPlayerEnemy( hPlayerFinder, hPlayerOwner ) )
  1488.                                 {
  1489.                                     ImpossibleClick = FALSE;
  1490.                                     float unitx = 0.0f, unity = 0.0f;
  1491.                                     GetUnitLocation2D( unitsarray[ i ], &unitx, &unity );
  1492.                                     if ( DetectImpossibleClicks && IsDetectedTower( unitsarray[ i ] ) )
  1493.                                     {
  1494.                                         if ( Distance( unitx, unity, x, y ) < 22 && Distance( unitx, unity, x, y ) > 1 )
  1495.                                         {
  1496.                                             ImpossibleClick = TRUE;
  1497.                                             return unitsarray[ i ];
  1498.                                         }
  1499.                                     }
  1500.  
  1501.                                     if ( IsDetectedTower( unitsarray[ i ] ) )
  1502.                                     {
  1503.                                         if ( Distance( unitx, unity, x, y ) <= 1 )
  1504.                                             continue;
  1505.                                     }
  1506.                                     if ( Distance( unitx, unity, x, y ) < 19 )
  1507.                                         return unitsarray[ i ];
  1508.                                 }
  1509.                             }
  1510.                         }
  1511.                     }
  1512.                 }
  1513.             }
  1514.         }
  1515.     }
  1516.     if ( onlyunits )
  1517.     {
  1518.         return 0;
  1519.     }
  1520.     return GetItemByXY( x, y, player );
  1521. }
  1522.  
  1523. int LastEventID, LastSkillID, LastCasterID;
  1524. DWORD LastEventTime = 0;
  1525.  
  1526. struct PlayerEvent
  1527. {
  1528.     int EventID;
  1529.     int SkillID;
  1530.     int Caster;
  1531.     int SelectedUnits;
  1532.     DWORD Time;
  1533. };
  1534.  
  1535. PlayerEvent PlayerEventList[ 20 ][ 15 ];
  1536.  
  1537. BOOL PlayerMeepoDetect[ 20 ];
  1538.  
  1539. void ShiftLeftAndAddNewActionScanForBot( int PlayerID, PlayerEvent NewPlayerEvent )
  1540. {
  1541.     if ( GetLocalPlayerNumber( ) != PlayerID )
  1542.     {
  1543.  
  1544.         if ( NewPlayerEvent.EventID == 272 )
  1545.         {
  1546.             if ( DebugLog )
  1547.                 WatcherLog( "[DEBUG][+%u ms][LogActions] : Event:%i - Skill:%X - Caster:%X \n", NewPlayerEvent.Time, NewPlayerEvent.EventID, NewPlayerEvent.SkillID, NewPlayerEvent.Caster );
  1548.  
  1549.             for ( int i = 0; i < 14; i++ )
  1550.             {
  1551.                 CopyMemory( &PlayerEventList[ PlayerID ][ i ], &PlayerEventList[ PlayerID ][ i + 1 ], sizeof( PlayerEvent ) );
  1552.             }
  1553.             CopyMemory( &PlayerEventList[ PlayerID ][ 14 ], &NewPlayerEvent, sizeof( PlayerEvent ) );
  1554.  
  1555.             PlayerEvent Event1 = PlayerEventList[ PlayerID ][ 0 ];
  1556.             PlayerEvent Event2 = PlayerEventList[ PlayerID ][ 1 ];
  1557.             PlayerEvent Event3 = PlayerEventList[ PlayerID ][ 2 ];
  1558.             PlayerEvent Event4 = PlayerEventList[ PlayerID ][ 3 ];
  1559.  
  1560.  
  1561.             /*WatcherLog( "[event1][+%u ms][LogActions] : Event:%i - Skill:%X - Caster:%X - units %i \n", Event1.Time, Event1.EventID, Event1.SkillID, Event1.Caster,Event1.SelectedUnits );
  1562.             WatcherLog( "[event2][+%u ms][LogActions] : Event:%i - Skill:%X - Caster:%X - units %i\n", Event2.Time, Event2.EventID, Event2.SkillID, Event2.Caster, Event1.SelectedUnits );
  1563.             WatcherLog( "[event3][+%u ms][LogActions] : Event:%i - Skill:%X - Caster:%X - units %i\n", Event3.Time, Event3.EventID, Event3.SkillID, Event3.Caster, Event1.SelectedUnits );
  1564.             WatcherLog( "[event4][+%u ms][LogActions] : Event:%i - Skill:%X - Caster:%X - units %i\n", Event4.Time, Event4.EventID, Event4.SkillID, Event4.Caster, Event1.SelectedUnits );
  1565.             */
  1566.  
  1567.             if ( DetectMeepoKey )
  1568.             {
  1569.  
  1570.  
  1571.                 if ( Event1.SkillID == 0x41304E38 &&
  1572.                      Event2.SkillID == 0x41304E38 &&
  1573.                      Event3.SkillID == 0x41304E38 &&
  1574.                      Event4.SkillID == 0x41304E38 )
  1575.                 {
  1576.                     if ( Event1.Caster != Event2.Caster &&
  1577.                          Event2.Caster != Event3.Caster &&
  1578.                          Event3.Caster != Event4.Caster &&
  1579.                          Event4.Caster != Event1.Caster )
  1580.                     {
  1581.                         if ( Event1.Caster != 0 &&
  1582.                              Event2.Caster != 0 &&
  1583.                              Event3.Caster != 0 &&
  1584.                              Event4.Caster != 0 )
  1585.                         {
  1586.                             /*WatcherLog( "[event1][+%u ms][LogActions] : Event:%i - Skill:%X - Caster:%X - units %i\n", Event1.Time, Event1.EventID, Event1.SkillID, Event1.Caster, Event1.SelectedUnits );
  1587.                             WatcherLog( "[event2][+%u ms][LogActions] : Event:%i - Skill:%X - Caster:%X - units %i\n", Event2.Time, Event2.EventID, Event2.SkillID, Event2.Caster, Event1.SelectedUnits );
  1588.                             WatcherLog( "[event3][+%u ms][LogActions] : Event:%i - Skill:%X - Caster:%X - units %i\n", Event3.Time, Event3.EventID, Event3.SkillID, Event3.Caster, Event1.SelectedUnits );
  1589.                             WatcherLog( "[event4][+%u ms][LogActions] : Event:%i - Skill:%X - Caster:%X - units %i\n", Event4.Time, Event4.EventID, Event4.SkillID, Event4.Caster, Event1.SelectedUnits );
  1590.                             */
  1591.                             if ( Event2.Time < 120 &&
  1592.                                  Event3.Time < 120 )
  1593.                             {
  1594.                                 if ( ( Event1.SelectedUnits == 1 || Event4.SelectedUnits == 1 ) &&
  1595.                                      Event2.SelectedUnits == 1 &&
  1596.                                      Event3.SelectedUnits == 1
  1597.                                      )
  1598.                                 {
  1599.                                     if ( !PlayerMeepoDetect[ PlayerID ] )
  1600.                                     {
  1601.                                         PlayerMeepoDetect[ PlayerID ] = TRUE;
  1602.                                         LatestAbilSpell = GetTickCount( );
  1603.  
  1604.  
  1605.                                         sprintf_s( PrintBuffer, 2048, "|c00FF5000[FogCW v10.9]|r: Player %s%s|r use MeepoKey!!\0",
  1606.                                                    GetPlayerColorString( PlayerID ),
  1607.                                                    GetPlayerName( PlayerID, 0 ) );
  1608.                                         ActionTime = GetGameTime( );
  1609.                                         DisplayText( PrintBuffer, 15.0f );
  1610.                                     }
  1611.                                 }
  1612.                             }
  1613.                         }
  1614.                     }
  1615.                 }
  1616.             }
  1617.         }
  1618.  
  1619.     }
  1620. }
  1621.  
  1622. void BotDetector( )
  1623. {
  1624.     // THE BOT DETECTOR!
  1625.     int EventID = GetTriggerEventId_real( );
  1626.     int SkillID = GetSpellAbilityId_real( );
  1627.     int CasterID = GetTriggerUnit( );
  1628.  
  1629.     if ( EventID != LastEventID || SkillID != LastSkillID || CasterID != LastCasterID )
  1630.     {
  1631.         LastEventID = EventID;
  1632.         LastSkillID = SkillID;
  1633.         LastCasterID = CasterID;
  1634.         if ( CasterID > 0 )
  1635.         {
  1636.             int CasterAddr = GetHandleUnitAddress( CasterID, 0 );
  1637.             if ( CasterAddr > 0 )
  1638.             {
  1639.                 int CasterSlot = GetUnitOwnerSlot( CasterAddr );
  1640.                 if ( CasterSlot < 12 && CasterSlot >= 0 )
  1641.                 {
  1642.                     if ( EventID == 272 )
  1643.                     {
  1644.                         PlayerEvent NewPlayerEvent;
  1645.                         NewPlayerEvent.Caster = CasterAddr;
  1646.                         NewPlayerEvent.EventID = EventID;
  1647.                         NewPlayerEvent.SkillID = SkillID;
  1648.                         DWORD CurrentTickCount = GetTickCount( );
  1649.                         NewPlayerEvent.Time = CurrentTickCount - LastEventTime;
  1650.                         NewPlayerEvent.SelectedUnits = GetSelectedUnitCount( CasterSlot );
  1651.                         ShiftLeftAndAddNewActionScanForBot( CasterSlot, NewPlayerEvent );
  1652.                         LastEventTime = CurrentTickCount;
  1653.                     }
  1654.                 }
  1655.             }
  1656.         }
  1657.  
  1658.     }
  1659.  
  1660.     //WatcherLog( "[+%ims][LogActions] : Event:%i - Skill:%X - Caster:%X \n", GetGameTime( ) - LastEventTime, EventID, SkillID, CasterID );
  1661.  
  1662. }
  1663.  
  1664. BOOL GetTriggerEventIdCalled = FALSE;
  1665. int GetTriggerEventId_hooked( )
  1666. {
  1667.     if ( !MainThread )
  1668.         MainThread = GetCurrentThread( );
  1669.  
  1670.  
  1671.     int EventID = GetTriggerEventId_real( );
  1672.  
  1673.     if ( !GameStarted || GetTriggerEventIdCalled )
  1674.         return EventID;
  1675.  
  1676.     GetTriggerEventIdCalled = TRUE;
  1677.  
  1678.     BotDetector( );
  1679.  
  1680.     if ( GetTickCount( ) - LatestAbilSpell > 1000 )
  1681.     {
  1682.         if ( EventID == 77 || EventID == 40 )
  1683.         {
  1684.             try
  1685.             {
  1686.                 int CasterUnitHandle = GetTriggerUnit( );
  1687.                 int TargetUnitHandle = GetOrderTargetUnit( );
  1688.                 BOOL IsItem = FALSE;
  1689.                 if ( TargetUnitHandle == 0 )
  1690.                 {
  1691.                     TargetUnitHandle = GetOrderTargetItem( );
  1692.                     if ( TargetUnitHandle > 0 )
  1693.                         IsItem = TRUE;
  1694.                     else
  1695.                         return EventID;
  1696.                 }
  1697.  
  1698.                 if ( CasterUnitHandle > 0 && TargetUnitHandle > 0 )
  1699.                 {
  1700.                     int CasterAddr = GetHandleUnitAddress( CasterUnitHandle, 0 );
  1701.                     int TargetAddr = ( IsItem ? GetHandleItemAddress( TargetUnitHandle, 0 ) : GetHandleUnitAddress( TargetUnitHandle, 0 ) );
  1702.                     if ( CasterAddr > 0 && TargetAddr > 0 )
  1703.                     {
  1704.                         int CasterSlot = GetUnitOwnerSlot( CasterAddr );
  1705.                         int TargetSlot = ( IsItem ? 15 : GetUnitOwnerSlot( TargetAddr ) );
  1706.  
  1707.                         if ( Player( CasterSlot ) > 0 && Player( TargetSlot ) > 0 )
  1708.                         {
  1709.                            
  1710.                             BOOL IsOkay = ( IsItem ? ( IsNotBadItem( TargetAddr ) && !( GetIssuedOrderId_real( ) >= 0xD0022 && GetIssuedOrderId_real( ) <= 0xD0028 ) )
  1711.                                             : ( IsNotBadUnit( TargetAddr ) && ( IsHero( TargetAddr ) || ( !DetectRightClickOnlyHeroes && !IsUnitTower( TargetAddr ) ) ) ) );
  1712.  
  1713.                             if ( TargetSlot != CasterSlot && CasterSlot != GetLocalPlayerNumber( ) && IsOkay && ( TargetSlot > 11 || IsPlayerEnemy( Player( CasterSlot ), Player( TargetSlot ) ) ) )
  1714.                             {
  1715.                                 if ( GetPlayerController( Player( CasterSlot ) ) == 0 && GetPlayerSlotState( Player( CasterSlot ) ) == 1 )
  1716.                                 {
  1717.                                     BOOL needcontinue = FALSE;
  1718.  
  1719.                                     if ( !IsItem )
  1720.                                     {
  1721.                                         if ( DetectQuality >= 3 )
  1722.                                         {
  1723.                                             if ( FogHelperList.size( ) > 90000 )
  1724.                                                 FogHelperList.clear( );
  1725.                                             for ( unsigned int z = 0; z < FogHelperList.size( ); z++ )
  1726.                                             {
  1727.                                                 if ( TargetAddr == FogHelperList[ z ].UnitAddr )
  1728.                                                 {
  1729.                                                     if ( !( FogHelperList[ z ].FogState[ CasterSlot ][ 0 ] && FogHelperList[ z ].FogState[ CasterSlot ][ 1 ] ) )
  1730.                                                     {
  1731.                                                         needcontinue = TRUE;
  1732.                                                     }
  1733.                                                 }
  1734.                                             }
  1735.                                         }
  1736.                                     }
  1737.  
  1738.  
  1739.                                     if ( !needcontinue )
  1740.                                     {
  1741.  
  1742.                                         float unitx = 0.0f, unity = 0.0f;
  1743.                                         if ( IsItem )
  1744.                                         {
  1745.                                             GetItemLocation2D( TargetAddr, &unitx, &unity );
  1746.                                         }
  1747.                                         else
  1748.                                         {
  1749.                                             GetUnitLocation2D( TargetAddr, &unitx, &unity );
  1750.                                         }
  1751.                                         if ( IsFoggedToPlayerMy( &unitx, &unity, Player( CasterSlot ) ) )
  1752.                                         {
  1753.                                             LatestAbilSpell = GetTickCount( );
  1754.                                             if ( MinimapPingFogClick )
  1755.                                             {
  1756.                                                 unsigned int PlayerColorInt = GetPlayerColorUINT( Player( CasterSlot ) );
  1757.                                                 PingMinimapMy( &unitx, &unity, &pingduration, PlayerColorInt & 0x00FF0000, PlayerColorInt & 0x0000FF00, PlayerColorInt & 0x000000FF, false );
  1758.                                             }
  1759.                                             sprintf_s( PrintBuffer, 2048, "|c00FF5000[FogCW v10.9]|r: Player %s%s|r use %s in fogged %s %s%s|r|r[TARGET]\0",
  1760.                                                        GetPlayerColorString( Player( CasterSlot ) ),
  1761.                                                        GetPlayerName( CasterSlot, 0 ),
  1762.                                                        ConvertIdToString( GetIssuedOrderId_real( ) ),
  1763.                                                        IsItem ? "[item]" : "[unit]",
  1764.                                                        IsItem ? "|cFF4B4B4B" : GetPlayerColorString( Player( TargetSlot ) ),
  1765.                                                        GetObjectName( TargetAddr ) );
  1766.                                             ActionTime = GetGameTime( );
  1767.                                             DisplayText( PrintBuffer, 6.0f );
  1768.                                         }
  1769.                                         else if ( !IsItem && !IsUnitVisibled( TargetAddr, Player( CasterSlot ) ) )
  1770.                                         {
  1771.                                             LatestAbilSpell = GetTickCount( );
  1772.                                             if ( MinimapPingFogClick )
  1773.                                             {
  1774.                                                 unsigned int PlayerColorInt = GetPlayerColorUINT( Player( CasterSlot ) );
  1775.                                                 PingMinimapMy( &unitx, &unity, &pingduration, PlayerColorInt & 0x00FF0000, PlayerColorInt & 0x0000FF00, PlayerColorInt & 0x000000FF, false );
  1776.                                             }
  1777.                                             sprintf_s( PrintBuffer, 2048, "|c00FF5000[FogCW v10.9]|r: Player %s%s|r use %s in invisibled %s%s|r|r[TARGET]\0",
  1778.                                                        GetPlayerColorString( Player( CasterSlot ) ),
  1779.                                                        GetPlayerName( CasterSlot, 0 ),
  1780.                                                        ConvertIdToString( GetIssuedOrderId_real( ) ),
  1781.                                                        GetPlayerColorString( Player( TargetSlot ) ),
  1782.                                                        GetObjectName( TargetAddr ) );
  1783.                                             ActionTime = GetGameTime( );
  1784.                                             DisplayText( PrintBuffer, 6.0f );
  1785.                                         }
  1786.                                         else if ( IsItem && DetectItemDestroyer && GetIssuedOrderId_real( ) == 0xD000F )
  1787.                                         {
  1788.  
  1789.                                             if ( GetItemOwner( TargetAddr ) != CasterSlot || DetectOwnItems )
  1790.                                             {
  1791.  
  1792.                                                 if ( !IsPlayerEnemy( Player( CasterSlot ), GetItemOwner( TargetAddr ) ) )
  1793.                                                 {
  1794.                                                     if ( MinimapPingFogClick )
  1795.                                                     {
  1796.                                                         unsigned int PlayerColorInt = GetPlayerColorUINT( Player( CasterSlot ) );
  1797.                                                         PingMinimapMy( &unitx, &unity, &pingduration, PlayerColorInt & 0x00FF0000, PlayerColorInt & 0x0000FF00, PlayerColorInt & 0x000000FF, false );
  1798.                                                     }
  1799.                                                     LatestAbilSpell = GetTickCount( );
  1800.                                                     sprintf_s( PrintBuffer, 2048, "|c00FF5000[FogCW v10.9]|r: Player %s%s|r try to destroy item %s%s|r|r\0",
  1801.                                                                GetPlayerColorString( Player( CasterSlot ) ),
  1802.                                                                GetPlayerName( CasterSlot, 0 ),
  1803.                                                                GetPlayerColorString( Player( TargetSlot ) ),
  1804.                                                                GetObjectName( TargetAddr ) );
  1805.                                                     ActionTime = GetGameTime( );
  1806.                                                     DisplayText( PrintBuffer, 6.0f );
  1807.                                                 }
  1808.                                             }
  1809.                                         }
  1810.                                     }
  1811.                                 }
  1812.                             }
  1813.                         }
  1814.                     }
  1815.                 }
  1816.             }
  1817.             catch ( ... )
  1818.             {
  1819.                 ActionTime = GetGameTime( );
  1820.                 AddStringToLogFile( "Error GetTriggerEventId_hooked part 1. Skip exception : catch ( ... )" );
  1821.             }
  1822.         }
  1823.  
  1824.         if ( EventID == 76 || EventID == 39 )
  1825.         {
  1826.  
  1827.             try
  1828.             {
  1829.  
  1830.                 int CasterUnitHandle = GetTriggerUnit( );
  1831.  
  1832.                 if ( CasterUnitHandle > 0 )
  1833.                 {
  1834.                     int CasterAddr = GetHandleUnitAddress( CasterUnitHandle, 0 );
  1835.  
  1836.                     float x = GetOrderPointX( ).fl;
  1837.                     float y = GetOrderPointY( ).fl;
  1838.                     float unitx = 0.0f, unity = 0.0f;
  1839.                     if ( CasterAddr > 0 && GetOrderPointX( ).dw != 0 && GetOrderPointY( ).dw != 0 )
  1840.                     {
  1841.                         if ( GetPlayerController( Player( GetUnitOwnerSlot( CasterAddr ) ) ) == 0 && GetPlayerSlotState( Player( GetUnitOwnerSlot( CasterAddr ) ) ) == 1 )
  1842.                         {
  1843.  
  1844.                             int TargetAddr = GetUnitByXY( x, y, GetUnitOwnerSlot( CasterAddr ) );
  1845.                             BOOL DetectionImpossibleClick = FALSE;
  1846.  
  1847.                             if ( TargetAddr > 0 && ( IsNotBadUnit( TargetAddr ) && ( IsHero( TargetAddr ) || ( DetectImpossibleClicks && IsDetectedTower( TargetAddr ) ) || ( !DetectRightClickOnlyHeroes && !IsUnitTower( TargetAddr ) ) ) ) )
  1848.                             {
  1849.  
  1850.                                 BOOL needcontinue = FALSE;
  1851.  
  1852.                                 if ( DetectQuality >= 3 )
  1853.                                 {
  1854.                                     for ( unsigned int z = 0; z < FogHelperList.size( ); z++ )
  1855.                                     {
  1856.                                         if ( TargetAddr == FogHelperList[ z ].UnitAddr )
  1857.                                         {
  1858.                                             if ( !( FogHelperList[ z ].FogState[ GetUnitOwnerSlot( CasterAddr ) ][ 0 ] && FogHelperList[ z ].FogState[ GetUnitOwnerSlot( CasterAddr ) ][ 1 ] ) )
  1859.                                             {
  1860.                                                 needcontinue = TRUE;
  1861.                                             }
  1862.                                         }
  1863.                                     }
  1864.                                 }
  1865.  
  1866.                                 if ( !needcontinue )
  1867.                                 {
  1868.                                     GetUnitLocation2D( TargetAddr, &unitx, &unity );
  1869.                                     if ( DetectImpossibleClicks && IsDetectedTower( TargetAddr ) )
  1870.                                     {
  1871.                                         DetectionImpossibleClick = TRUE;
  1872.                                     }
  1873.                                 }
  1874.  
  1875.  
  1876.                                 if ( !needcontinue )
  1877.                                 {
  1878.  
  1879.  
  1880.                                     if ( ( DetectPointClicks || DetectionImpossibleClick ) && IsFoggedToPlayerMy( &unitx, &unity, Player( GetUnitOwnerSlot( CasterAddr ) ) ) )
  1881.                                     {
  1882.                                         LatestAbilSpell = GetTickCount( );
  1883.                                         if ( MinimapPingFogClick )
  1884.                                         {
  1885.                                             unsigned int PlayerColorInt = GetPlayerColorUINT( Player( GetUnitOwnerSlot( CasterAddr ) ) );
  1886.                                             PingMinimapMy( &unitx, &unity, &pingduration, PlayerColorInt & 0x00FF0000, PlayerColorInt & 0x0000FF00, PlayerColorInt & 0x000000FF, false );
  1887.                                         }
  1888.  
  1889.                                         sprintf_s( PrintBuffer, 2048, "|c00FF5000[FogCW v10.9]|r: Player %s%s|r use %s in fogged [unit] %s%s|r|r[POINT]\0",
  1890.                                                    GetPlayerColorString( Player( GetUnitOwnerSlot( CasterAddr ) ) ),
  1891.                                                    GetPlayerName( GetUnitOwnerSlot( CasterAddr ), 0 ),
  1892.                                                    ImpossibleClick ? "-IMPOSSIBLECLICK-" : ConvertIdToString( GetIssuedOrderId_real( ) ),
  1893.                                                    GetPlayerColorString( Player( GetUnitOwnerSlot( TargetAddr ) ) ),
  1894.                                                    GetObjectName( TargetAddr ) );
  1895.                                         ActionTime = GetGameTime( );
  1896.                                         DisplayText( PrintBuffer, 6.0f );
  1897.                                         ImpossibleClick = FALSE;
  1898.                                     }
  1899.                                     else if ( DetectPointClicks && !DetectionImpossibleClick && !IsUnitVisibled( TargetAddr, Player( GetUnitOwnerSlot( CasterAddr ) ) ) )
  1900.                                     {
  1901.                                         LatestAbilSpell = GetTickCount( );
  1902.                                         if ( MinimapPingFogClick )
  1903.                                         {
  1904.                                             unsigned int PlayerColorInt = GetPlayerColorUINT( Player( GetUnitOwnerSlot( CasterAddr ) ) );
  1905.                                             PingMinimapMy( &unitx, &unity, &pingduration, PlayerColorInt & 0x00FF0000, PlayerColorInt & 0x0000FF00, PlayerColorInt & 0x000000FF, false );
  1906.                                         }
  1907.  
  1908.                                         sprintf_s( PrintBuffer, 2048, "|c00FF5000[FogCW v10.9]|r: Player %s%s|r use %s in invisibled %s%s|r|r[POINT]\0",
  1909.                                                    GetPlayerColorString( Player( GetUnitOwnerSlot( CasterAddr ) ) ),
  1910.                                                    GetPlayerName( GetUnitOwnerSlot( CasterAddr ), 0 ),
  1911.                                                    ConvertIdToString( GetIssuedOrderId_real( ) ),
  1912.                                                    GetPlayerColorString( Player( GetUnitOwnerSlot( TargetAddr ) ) ),
  1913.                                                    GetObjectName( TargetAddr ) );
  1914.                                         ActionTime = GetGameTime( );
  1915.                                         DisplayText( PrintBuffer, 6.0f );
  1916.                                     }
  1917.                                 }
  1918.                             }
  1919.                             else if ( DetectPointClicks && TargetAddr > 0 && IsNotBadItem( TargetAddr ) && !( GetIssuedOrderId_real( ) >= 0xD0022 && GetIssuedOrderId_real( ) <= 0xD0028 ) )
  1920.                             {
  1921.                                 float unitx = 0.0f, unity = 0.0f;
  1922.                                 GetItemLocation2D( TargetAddr, &unitx, &unity );
  1923.                                 if ( IsFoggedToPlayerMy( &unitx, &unity, Player( GetUnitOwnerSlot( CasterAddr ) ) ) )
  1924.                                 {
  1925.                                     LatestAbilSpell = GetTickCount( );
  1926.                                     if ( MinimapPingFogClick )
  1927.                                     {
  1928.                                         unsigned int PlayerColorInt = GetPlayerColorUINT( Player( GetUnitOwnerSlot( CasterAddr ) ) );
  1929.                                         PingMinimapMy( &unitx, &unity, &pingduration, PlayerColorInt & 0x00FF0000, PlayerColorInt & 0x0000FF00, PlayerColorInt & 0x000000FF, false );
  1930.                                     }
  1931.  
  1932.  
  1933.                                     sprintf_s( PrintBuffer, 2048, "|c00FF5000[FogCW v10.9]|r: Player %s%s|r use %s in fogged [item] %s%s|r|r[POINT]\0",
  1934.                                                GetPlayerColorString( Player( GetUnitOwnerSlot( CasterAddr ) ) ),
  1935.                                                GetPlayerName( GetUnitOwnerSlot( CasterAddr ), 0 ),
  1936.                                                ConvertIdToString( GetIssuedOrderId_real( ) ),
  1937.                                                "|cFF4B4B4B",
  1938.                                                GetObjectName( TargetAddr ) );
  1939.                                     ActionTime = GetGameTime( );
  1940.                                     DisplayText( PrintBuffer, 6.0f );
  1941.                                 }
  1942.                             }
  1943.                         }
  1944.                     }
  1945.                     else if ( CasterAddr > 0 && GetUnitOwnerSlot( CasterAddr ) != GetLocalPlayerNumber( ) && x == 0.0f && y == 0.0f )
  1946.                     {
  1947.                         if ( GetIssuedOrderId_real( ) == 851971 )
  1948.                         {
  1949.                             LatestAbilSpell = GetTickCount( );
  1950.  
  1951.                             sprintf_s( PrintBuffer, 2048, "|c00FF5000[FogCW v10.9]|r: Player %s%s|r activate GuAI Maphack!!\0",
  1952.                                        GetPlayerColorString( Player( GetUnitOwnerSlot( CasterAddr ) ) ),
  1953.                                        GetPlayerName( GetUnitOwnerSlot( CasterAddr ), 0 ) );
  1954.                             ActionTime = GetGameTime( );
  1955.                             DisplayText( PrintBuffer, 6.0f );
  1956.  
  1957.                         }
  1958.                     }
  1959.                 }
  1960.             }
  1961.             catch ( ... )
  1962.             {
  1963.                 ActionTime = GetGameTime( );
  1964.                 AddStringToLogFile( "Error GetTriggerEventId_hooked part 2. Skip exception : catch ( ... )" );
  1965.             }
  1966.         }
  1967.     }
  1968.  
  1969.     GetTriggerEventIdCalled = FALSE;
  1970.     return EventID;
  1971. }
  1972.  
  1973.  
  1974. BOOL GetSpellAbilityIdCalled = FALSE;
  1975. int GetSpellAbilityId_hooked( )
  1976. {
  1977.     if ( !MainThread )
  1978.         MainThread = GetCurrentThread( );
  1979.  
  1980.     int SpellAbilCode = GetSpellAbilityId_real( );
  1981.     if ( !GameStarted || GetSpellAbilityIdCalled )
  1982.         return SpellAbilCode;
  1983.  
  1984.     GetSpellAbilityIdCalled = TRUE;
  1985.     BotDetector( );
  1986.  
  1987.     if ( GetTickCount( ) - LatestAbilSpell > 1000 )
  1988.     {
  1989.         try
  1990.         {
  1991.             int CasterUnitHandle = GetSpellAbilityUnit_real( );
  1992.             int TargetUnitHandle = GetSpellTargetUnit( );
  1993.  
  1994.             if ( CasterUnitHandle > 0 )
  1995.             {
  1996.                 if ( CasterUnitHandle > 0 && TargetUnitHandle > 0 )
  1997.                 {
  1998.                     int CasterAddr = GetHandleUnitAddress( CasterUnitHandle, 0 );
  1999.                     int TargetAddr = GetHandleUnitAddress( TargetUnitHandle, 0 );
  2000.                     if ( CasterAddr > 0 && TargetAddr > 0 )
  2001.                     {
  2002.                         int CasterSlot = GetUnitOwnerSlot( CasterAddr );
  2003.                         int TargetSlot = GetUnitOwnerSlot( TargetAddr );
  2004.                         if ( ( IsNotBadUnit( TargetAddr ) && ( IsHero( TargetAddr ) || ( !DetectRightClickOnlyHeroes && !IsUnitTower( TargetAddr ) ) ) ) && CasterSlot != GetLocalPlayerNumber( ) && TargetSlot != CasterSlot && IsPlayerEnemy( Player( CasterSlot ), Player( TargetSlot ) ) )
  2005.                         {
  2006.                             if ( GetPlayerController( Player( CasterSlot ) ) == 0 && GetPlayerSlotState( Player( CasterSlot ) ) == 1 )
  2007.                             {
  2008.                                 BOOL needcontinue = FALSE;
  2009.  
  2010.                                 if ( DetectQuality >= 3 )
  2011.                                 {
  2012.                                     for ( unsigned int z = 0; z < FogHelperList.size( ); z++ )
  2013.                                     {
  2014.                                         if ( TargetAddr == FogHelperList[ z ].UnitAddr )
  2015.                                         {
  2016.                                             if ( !( FogHelperList[ z ].FogState[ CasterSlot ][ 0 ] && FogHelperList[ z ].FogState[ CasterSlot ][ 1 ] ) )
  2017.                                             {
  2018.                                                 needcontinue = TRUE;
  2019.                                             }
  2020.                                         }
  2021.                                     }
  2022.                                 }
  2023.  
  2024.  
  2025.                                 if ( !needcontinue )
  2026.                                 {
  2027.                                     float unitx = 0.0f, unity = 0.0f;
  2028.                                     GetUnitLocation2D( TargetAddr, &unitx, &unity );
  2029.                                     if ( IsFoggedToPlayerMy( &unitx, &unity, Player( GetUnitOwnerSlot( CasterAddr ) ) ) )
  2030.                                     {
  2031.                                         LatestAbilSpell = GetTickCount( );
  2032.                                         if ( MinimapPingFogClick )
  2033.                                         {
  2034.                                             unsigned int PlayerColorInt = GetPlayerColorUINT( Player( GetUnitOwnerSlot( CasterAddr ) ) );
  2035.                                             PingMinimapMy( &unitx, &unity, &pingduration, PlayerColorInt & 0x00FF0000, PlayerColorInt & 0x0000FF00, PlayerColorInt & 0x000000FF, false );
  2036.                                         }
  2037.  
  2038.                                         sprintf_s( PrintBuffer, 2048, "|c00FF5000[FogCW v10.9]|r: Player %s%s|r use ability(%s) in fogged %s%s|r|r[TARGET]\0",
  2039.                                                    GetPlayerColorString( Player( GetUnitOwnerSlot( CasterAddr ) ) ),
  2040.                                                    GetPlayerName( GetUnitOwnerSlot( CasterAddr ), 0 ),
  2041.                                                    ConvertIdToString( GetIssuedOrderId_real( ) ),
  2042.                                                    GetPlayerColorString( Player( GetUnitOwnerSlot( TargetAddr ) ) ),
  2043.                                                    GetObjectName( TargetAddr ) );
  2044.                                         ActionTime = GetGameTime( );
  2045.                                         DisplayText( PrintBuffer, 6.0f );
  2046.                                     }
  2047.                                     else if ( !IsUnitVisibled( TargetAddr, Player( GetUnitOwnerSlot( CasterAddr ) ) ) )
  2048.                                     {
  2049.                                         LatestAbilSpell = GetTickCount( );
  2050.                                         if ( MinimapPingFogClick )
  2051.                                         {
  2052.                                             unsigned int PlayerColorInt = GetPlayerColorUINT( Player( GetUnitOwnerSlot( CasterAddr ) ) );
  2053.                                             PingMinimapMy( &unitx, &unity, &pingduration, PlayerColorInt & 0x00FF0000, PlayerColorInt & 0x0000FF00, PlayerColorInt & 0x000000FF, false );
  2054.                                         }
  2055.  
  2056.                                         sprintf_s( PrintBuffer, 2048, "|c00FF5000[FogCW v10.9]|r: Player %s%s|r use ability(%s) in invisibled %s%s|r|r[TARGET]\0",
  2057.                                                    GetPlayerColorString( Player( GetUnitOwnerSlot( CasterAddr ) ) ),
  2058.                                                    GetPlayerName( GetUnitOwnerSlot( CasterAddr ), 0 ),
  2059.                                                    ConvertIdToString( GetIssuedOrderId_real( ) ),
  2060.                                                    GetPlayerColorString( Player( GetUnitOwnerSlot( TargetAddr ) ) ),
  2061.                                                    GetObjectName( TargetAddr ) );
  2062.                                         ActionTime = GetGameTime( );
  2063.                                         DisplayText( PrintBuffer, 6.0f );
  2064.                                     }
  2065.                                 }
  2066.                             }
  2067.                         }
  2068.                     }
  2069.                 }
  2070.                 else if ( DetectPointClicks && CasterUnitHandle > 0 && GetSpellTargetX( ).dw != 0 && GetSpellTargetY( ).dw != 0 )
  2071.                 {
  2072.                     int CasterAddr = GetHandleUnitAddress( CasterUnitHandle, 0 );
  2073.  
  2074.                     if ( CasterAddr > 0 )
  2075.                     {
  2076.                         float x = GetSpellTargetX( ).fl;
  2077.                         float y = GetSpellTargetY( ).fl;
  2078.                         int TargetAddr = GetUnitByXY( x, y, GetUnitOwnerSlot( CasterAddr ), TRUE );
  2079.  
  2080.                         if ( TargetAddr > 0 && ( IsNotBadUnit( TargetAddr ) && ( IsHero( TargetAddr ) || ( !DetectRightClickOnlyHeroes && !IsUnitTower( TargetAddr ) ) ) ) )
  2081.                         {
  2082.                             BOOL needcontinue = FALSE;
  2083.                             if ( DetectQuality >= 3 )
  2084.                             {
  2085.                                 for ( unsigned int z = 0; z < FogHelperList.size( ); z++ )
  2086.                                 {
  2087.                                     if ( TargetAddr == FogHelperList[ z ].UnitAddr )
  2088.                                     {
  2089.                                         if ( !( FogHelperList[ z ].FogState[ GetUnitOwnerSlot( CasterAddr ) ][ 0 ] && FogHelperList[ z ].FogState[ GetUnitOwnerSlot( CasterAddr ) ][ 1 ] ) )
  2090.                                         {
  2091.                                             needcontinue = TRUE;
  2092.                                         }
  2093.                                     }
  2094.                                 }
  2095.                             }
  2096.  
  2097.  
  2098.  
  2099.                             if ( !needcontinue )
  2100.                             {
  2101.                                 if ( GetPlayerController( Player( GetUnitOwnerSlot( CasterAddr ) ) ) == 0 && GetPlayerSlotState( Player( GetUnitOwnerSlot( CasterAddr ) ) ) == 1 )
  2102.                                 {
  2103.                                     float unitx = 0.0f, unity = 0.0f;
  2104.                                     GetUnitLocation2D( TargetAddr, &unitx, &unity );
  2105.                                     if ( IsFoggedToPlayerMy( &unitx, &unity, Player( GetUnitOwnerSlot( CasterAddr ) ) ) )
  2106.                                     {
  2107.                                         LatestAbilSpell = GetTickCount( );
  2108.                                         if ( MinimapPingFogClick )
  2109.                                         {
  2110.                                             unsigned int PlayerColorInt = GetPlayerColorUINT( Player( GetUnitOwnerSlot( CasterAddr ) ) );
  2111.                                             PingMinimapMy( &unitx, &unity, &pingduration, PlayerColorInt & 0x00FF0000, PlayerColorInt & 0x0000FF00, PlayerColorInt & 0x000000FF, false );
  2112.                                         }
  2113.  
  2114.                                         sprintf_s( PrintBuffer, 2048, "|c00FF5000[FogCW v10.9]|r: Player %s%s|r use ability(%s) in fogged %s%s|r|r[POINT]\0",
  2115.                                                    GetPlayerColorString( Player( GetUnitOwnerSlot( CasterAddr ) ) ),
  2116.                                                    GetPlayerName( GetUnitOwnerSlot( CasterAddr ), 0 ),
  2117.                                                    ConvertIdToString( GetIssuedOrderId_real( ) ),
  2118.                                                    GetPlayerColorString( Player( GetUnitOwnerSlot( TargetAddr ) ) ),
  2119.                                                    GetObjectName( TargetAddr ) );
  2120.                                         ActionTime = GetGameTime( );
  2121.                                         DisplayText( PrintBuffer, 6.0f );
  2122.                                     }
  2123.                                     else if ( !IsUnitVisibled( TargetAddr, Player( GetUnitOwnerSlot( CasterAddr ) ) ) )
  2124.                                     {
  2125.                                         LatestAbilSpell = GetTickCount( );
  2126.                                         if ( MinimapPingFogClick )
  2127.                                         {
  2128.                                             unsigned int PlayerColorInt = GetPlayerColorUINT( Player( GetUnitOwnerSlot( CasterAddr ) ) );
  2129.                                             PingMinimapMy( &unitx, &unity, &pingduration, PlayerColorInt & 0x00FF0000, PlayerColorInt & 0x0000FF00, PlayerColorInt & 0x000000FF, false );
  2130.                                         }
  2131.  
  2132.                                         sprintf_s( PrintBuffer, 2048, "|c00FF5000[FogCW v10.9]|r: Player %s%s|r use ability(%s) in invisibled %s%s|r|r[POINT]\0",
  2133.                                                    GetPlayerColorString( Player( GetUnitOwnerSlot( CasterAddr ) ) ),
  2134.                                                    GetPlayerName( GetUnitOwnerSlot( CasterAddr ), 0 ),
  2135.                                                    ConvertIdToString( GetIssuedOrderId_real( ) ),
  2136.                                                    GetPlayerColorString( Player( GetUnitOwnerSlot( TargetAddr ) ) ),
  2137.                                                    GetObjectName( TargetAddr ) );
  2138.                                         ActionTime = GetGameTime( );
  2139.                                         DisplayText( PrintBuffer, 6.0f );
  2140.                                     }
  2141.                                 }
  2142.                             }
  2143.                         }
  2144.                     }
  2145.                 }
  2146.             }
  2147.         }
  2148.         catch ( ... )
  2149.         {
  2150.             ActionTime = GetGameTime( );
  2151.             AddStringToLogFile( "Error GetSpellAbilityId_hooked part 1. Skip exception : catch ( ... )" );
  2152.         }
  2153.     }
  2154.     GetSpellAbilityIdCalled = FALSE;
  2155.     return SpellAbilCode;
  2156. }
  2157.  
  2158. int GetIssuedOrderId_hooked( )
  2159. {
  2160.     if ( !MainThread )
  2161.         MainThread = GetCurrentThread( );
  2162.     int OrderID = GetIssuedOrderId_real( );
  2163.     GetTriggerEventId_hooked( );
  2164.     return OrderID;
  2165. }
  2166.  
  2167. int GetSpellAbilityUnit_hooked( )
  2168. {
  2169.     if ( !MainThread )
  2170.         MainThread = GetCurrentThread( );
  2171.     int SpellCaster = GetSpellAbilityUnit_real( );
  2172.     if ( GetSpellAbilityId_hooked( ) > 0 )
  2173.     {
  2174.         return SpellCaster;
  2175.     }
  2176.     GetTriggerEventId_hooked( );
  2177.     return SpellCaster;
  2178. }
  2179.  
  2180. int GetAttacker_hooked( )
  2181. {
  2182.     if ( !MainThread )
  2183.         MainThread = GetCurrentThread( );
  2184.     int Attacker = GetAttacker_real( );
  2185.     if ( GetTriggerEventId_hooked( ) > 0 )
  2186.     {
  2187.         return Attacker;
  2188.     }
  2189.     GetSpellAbilityId_hooked( );
  2190.     return Attacker;
  2191. }
  2192.  
  2193.  
  2194.  
  2195.  
  2196. int LatestUnit = 0;
  2197. int LatestPlayer = 0;
  2198. //FogHelperListTemp.clear( );
  2199.  
  2200. DWORD LatestFogCheck = 0;
  2201.  
  2202. void UpdateFogHelper( )
  2203. {
  2204.     if ( GetTickCount( ) - LatestFogCheck > 350 )
  2205.     {
  2206.         LatestFogCheck = GetTickCount( );
  2207.         for ( int n = 0; n < 12; n++ )
  2208.         {
  2209.             if ( GetLocalPlayerNumber( ) == n )
  2210.                 continue;
  2211.  
  2212.             if ( !Player( n ) )
  2213.                 continue;
  2214.  
  2215.             if ( GetPlayerController( Player( n ) ) != 0 || GetPlayerSlotState( Player( n ) ) != 1 )
  2216.                 continue;
  2217.  
  2218.             int * unitsarray = 0;
  2219.             int * UnitsCount = GetUnitCountAndUnitArray( &unitsarray );
  2220.             if ( UnitsCount > 0 && * UnitsCount > 0 && unitsarray )
  2221.             {
  2222.                 for ( int i = 0; i < ( *UnitsCount ); i++ )
  2223.                 {
  2224.                     if ( unitsarray[ i ] )
  2225.                     {
  2226.                         if ( IsNotBadUnit( unitsarray[ i ] ) )
  2227.                         {
  2228.                             if ( IsHero( unitsarray[ i ] ) || !DetectRightClickOnlyHeroes )
  2229.                             {
  2230.                                 float unitx, unity;
  2231.  
  2232.                                 GetUnitLocation2D( unitsarray[ i ], &unitx, &unity );
  2233.  
  2234.                                 BOOL FoundUnit = FALSE;
  2235.  
  2236.                                 for ( unsigned int m = 0; m < FogHelperList.size( ); m++ )
  2237.                                 {
  2238.                                     if ( unitsarray[ i ] == FogHelperList[ m ].UnitAddr )
  2239.                                     {
  2240.                                         FoundUnit = TRUE;
  2241.                                         FogHelperList[ m ].FogState[ n ][ 1 ] = FogHelperList[ m ].FogState[ n ][ 0 ];
  2242.                                         FogHelperList[ m ].FogState[ n ][ 0 ] = ( IsFoggedToPlayerMy( &unitx, &unity, Player( n ) ) || !IsUnitVisibled( unitsarray[ i ], Player( n ) ) );
  2243.                                     }
  2244.                                 }
  2245.  
  2246.                                 if ( !FoundUnit )
  2247.                                 {
  2248.                                     FogHelper tmpghelp;
  2249.                                     for ( int z = 0; z < 20; z++ )
  2250.                                     {
  2251.                                         tmpghelp.FogState[ z ][ 0 ] = TRUE;
  2252.                                         tmpghelp.FogState[ z ][ 1 ] = TRUE;
  2253.                                     }
  2254.                                     tmpghelp.UnitAddr = unitsarray[ i ];
  2255.                                     FogHelperList.push_back( tmpghelp );
  2256.                                 }
  2257.  
  2258.                             }
  2259.                         }
  2260.                     }
  2261.                 }
  2262.             }
  2263.  
  2264.         }
  2265.  
  2266.  
  2267.     }
  2268. }
  2269.  
  2270.  
  2271. int PlayerSelectedItems[ 20 ];
  2272.  
  2273.  
  2274. void SearchPlayersFogSelect( )
  2275. {
  2276.     try
  2277.     {
  2278.  
  2279.         if ( DetectQuality >= 3 )
  2280.             UpdateFogHelper( );
  2281.  
  2282.         for ( int i = 0; i < 12; i++ )
  2283.         {
  2284.  
  2285.             if ( GetLocalPlayerNumber( ) == i )
  2286.                 continue;
  2287.  
  2288.             if ( !Player( i ) )
  2289.                 continue;
  2290.  
  2291.             if ( GetPlayerController( Player( i ) ) != 0 || GetPlayerSlotState( Player( i ) ) != 1 )
  2292.                 continue;
  2293.  
  2294.             int selectedunit = 0;
  2295.             int hCurrentPlayer = Player( i );
  2296.  
  2297.  
  2298.             if ( hCurrentPlayer )
  2299.             {
  2300.  
  2301.                 selectedunit = GetSelectedUnit( i );
  2302.                 if ( !selectedunit )
  2303.                     continue;
  2304.  
  2305.                 int OwnedPlayerSlot = GetUnitOwnerSlot( selectedunit );
  2306.  
  2307.                 if ( OwnedPlayerSlot < 0 || OwnedPlayerSlot > 15 )
  2308.                     continue;
  2309.  
  2310.                 int hOwnerPlayer = Player( OwnedPlayerSlot );
  2311.  
  2312.                 if ( !hOwnerPlayer || ( hCurrentPlayer == LatestPlayer && LatestUnit == selectedunit ) )
  2313.                     continue;
  2314.  
  2315.                 if ( hOwnerPlayer == hCurrentPlayer )
  2316.                     continue;
  2317.  
  2318.  
  2319.                 DWORD tmpActionTime = GetGameTime( );
  2320.  
  2321.                 if ( IsPlayerEnemy( hOwnerPlayer, hCurrentPlayer ) || OwnedPlayerSlot > 11 )
  2322.                 {
  2323.                     if ( selectedunit == GetSelectedUnit( i ) )
  2324.                     {
  2325.  
  2326.                         float unitx = 0.0f, unity = 0.0f;
  2327.                         GetUnitLocation2D( selectedunit, &unitx, &unity );
  2328.                         if ( IsFoggedToPlayerMy( &unitx, &unity, hCurrentPlayer ) || !IsUnitVisibled( selectedunit, hCurrentPlayer ) )
  2329.                         {
  2330.  
  2331.                             BOOL found = FALSE;
  2332.                             BOOL needcontinue = FALSE;
  2333.  
  2334.                             if ( ClickCount.size( ) > 90000 )
  2335.                                 ClickCount.clear( );
  2336.  
  2337.  
  2338.                             UnitSelected * tmpunitselected = NULL;
  2339.  
  2340.                             for ( unsigned int n = 0; n < ClickCount.size( ); n++ )
  2341.                             {
  2342.                                 if ( ClickCount[ n ].UnitAddr == selectedunit )
  2343.                                 {
  2344.                                     found = TRUE;
  2345.                                     if ( GetTickCount( ) - ClickCount[ n ].LatestTime[ i ] < 5000 )
  2346.                                     {
  2347.                                         needcontinue = TRUE;
  2348.                                     }
  2349.                                     else
  2350.                                     {
  2351.                                         tmpunitselected = &ClickCount[ n ];
  2352.                                     }
  2353.                                 }
  2354.                             }
  2355.  
  2356.                             if ( !found )
  2357.                             {
  2358.                                 UnitSelected tmpus;
  2359.                                 tmpus.LatestPlayer = i;
  2360.                                 for ( int n = 0; n < 20; n++ )
  2361.                                     tmpus.LatestTime[ n ] = GetTickCount( );
  2362.                                 tmpus.SelectCount = 0;
  2363.                                 tmpus.UnitAddr = selectedunit;
  2364.                                 ClickCount.push_back( tmpus );
  2365.                                 tmpunitselected = &ClickCount[ ClickCount.size( ) - 1 ];
  2366.                             }
  2367.  
  2368.  
  2369.                             if ( DetectQuality >= 3 )
  2370.                             {
  2371.                                 for ( unsigned int z = 0; z < FogHelperList.size( ); z++ )
  2372.                                 {
  2373.                                     if ( selectedunit == FogHelperList[ z ].UnitAddr )
  2374.                                     {
  2375.                                         if ( !( FogHelperList[ z ].FogState[ i ][ 0 ] && FogHelperList[ z ].FogState[ i ][ 1 ] ) )
  2376.                                         {
  2377.                                             needcontinue = TRUE;
  2378.                                         }
  2379.                                     }
  2380.                                 }
  2381.                             }
  2382.  
  2383.                             if ( needcontinue )
  2384.                             {
  2385.                                 continue;
  2386.                             }
  2387.  
  2388.                             SleepGameTime( 50 * DetectQuality );
  2389.                             if ( !*( BOOL* ) IsInGame || !GetGameTime( ) )
  2390.                             {
  2391.                                 return;
  2392.                             }
  2393.  
  2394.  
  2395.                             hCurrentPlayer = Player( i );
  2396.                             hOwnerPlayer = Player( OwnedPlayerSlot );
  2397.                             unitx = 0.0f, unity = 0.0f;
  2398.                             if ( !hCurrentPlayer || !hOwnerPlayer || GetSelectedUnit( i ) != selectedunit )
  2399.                             {
  2400.                                 continue;
  2401.                             }
  2402.                             GetUnitLocation2D( selectedunit, &unitx, &unity );
  2403.                             if ( !( IsFoggedToPlayerMy( &unitx, &unity, hCurrentPlayer ) || !IsUnitVisibled( selectedunit, hCurrentPlayer ) ) )
  2404.                             {
  2405.                                 continue;
  2406.                             }
  2407.  
  2408.  
  2409.                             SleepGameTime( 50 * DetectQuality );
  2410.                             if ( !*( BOOL* ) IsInGame || !GetGameTime( ) )
  2411.                             {
  2412.                                 return;
  2413.                             }
  2414.  
  2415.                             hCurrentPlayer = Player( i );
  2416.                             hOwnerPlayer = Player( OwnedPlayerSlot );
  2417.                             unitx = 0.0f, unity = 0.0f;
  2418.                             if ( !hCurrentPlayer || !hOwnerPlayer || GetSelectedUnit( i ) != selectedunit )
  2419.                             {
  2420.                                 continue;
  2421.                             }
  2422.                             GetUnitLocation2D( selectedunit, &unitx, &unity );
  2423.  
  2424.                             if ( IsFoggedToPlayerMy( &unitx, &unity, hCurrentPlayer ) || !IsUnitVisibled( selectedunit, hCurrentPlayer ) )
  2425.                             {
  2426.                                 SleepGameTime( 300 );
  2427.                                 if ( !*( BOOL* ) IsInGame || !GetGameTime( ) )
  2428.                                 {
  2429.                                     return;
  2430.                                 }
  2431.  
  2432.                                 hCurrentPlayer = Player( i );
  2433.                                 hOwnerPlayer = Player( OwnedPlayerSlot );
  2434.                                 unitx = 0.0f, unity = 0.0f;
  2435.                                 if ( !hCurrentPlayer || !hOwnerPlayer || GetSelectedUnit( i ) != selectedunit )
  2436.                                 {
  2437.                                     goto PossibledDetect;
  2438.                                 }
  2439.                                 GetUnitLocation2D( selectedunit, &unitx, &unity );
  2440.                                 if ( IsFoggedToPlayerMy( &unitx, &unity, hCurrentPlayer ) || !IsUnitVisibled( selectedunit, hCurrentPlayer ) )
  2441.                                 {
  2442.                                     if ( !IsFoggedToPlayerMy( &unitx, &unity, hCurrentPlayer ) )
  2443.                                     {
  2444.                                         if ( MinimapPingFogClick )
  2445.                                         {
  2446.                                             unsigned int PlayerColorInt = GetPlayerColorUINT( Player( i ) );
  2447.                                             PingMinimapMy( &unitx, &unity, &pingduration, PlayerColorInt & 0x00FF0000, PlayerColorInt & 0x0000FF00, PlayerColorInt & 0x000000FF, false );
  2448.                                         }
  2449.  
  2450.                                         tmpunitselected->LatestTime[ i ] = GetTickCount( );
  2451.  
  2452.                                         sprintf_s( PrintBuffer, 2048, "|c00FF5000[FogCW v10.9]|r: Player %s%s|r select invisibled %s%s|r|r [DETECTED]",
  2453.  
  2454.                                                    GetPlayerColorString( Player( i ) ),
  2455.                                                    GetPlayerName( i, 0 ),
  2456.                                                    GetPlayerColorString( Player( OwnedPlayerSlot ) ),
  2457.                                                    GetObjectName( selectedunit ) );
  2458.                                     }
  2459.                                     else
  2460.                                     {
  2461.                                         if ( MinimapPingFogClick )
  2462.                                         {
  2463.                                             unsigned int PlayerColorInt = GetPlayerColorUINT( Player( i ) );
  2464.                                             PingMinimapMy( &unitx, &unity, &pingduration, PlayerColorInt & 0x00FF0000, PlayerColorInt & 0x0000FF00, PlayerColorInt & 0x000000FF, false );
  2465.                                         }
  2466.  
  2467.                                         tmpunitselected->LatestTime[ i ] = GetTickCount( );
  2468.  
  2469.                                         sprintf_s( PrintBuffer, 2048, "|c00FF5000[FogCW v10.9]|r: Player %s%s|r select fogged %s%s|r|r [DETECTED]\0",
  2470.  
  2471.                                                    GetPlayerColorString( Player( i ) ),
  2472.                                                    GetPlayerName( i, 0 ),
  2473.                                                    GetPlayerColorString( Player( OwnedPlayerSlot ) ),
  2474.                                                    GetObjectName( selectedunit ) );
  2475.                                     }
  2476.  
  2477.                                     ActionTime = tmpActionTime;
  2478.                                     DisplayText( PrintBuffer, 6.0f );
  2479.                                     LatestPlayer = hCurrentPlayer;
  2480.                                     LatestUnit = selectedunit;
  2481.  
  2482.                                     break;
  2483.                                 }
  2484.                                 else
  2485.                                 {
  2486.                                     PossibledDetect:
  2487.                                     if ( !IsFoggedToPlayerMy( &unitx, &unity, hCurrentPlayer ) )
  2488.                                     {
  2489.                                         tmpunitselected->LatestTime[ i ] = GetTickCount( );
  2490.  
  2491.                                         sprintf_s( PrintBuffer, 2048, "|c00FF5000[FogCW v10.9]|r: Player %s%s|r select invisibled %s%s|r|r [POSSIBLE]\0",
  2492.                                                    GetPlayerColorString( Player( i ) ),
  2493.                                                    GetPlayerName( i, 0 ),
  2494.                                                    GetPlayerColorString( Player( OwnedPlayerSlot ) ),
  2495.                                                    GetObjectName( selectedunit ) );
  2496.                                     }
  2497.                                     else
  2498.                                     {
  2499.                                         tmpunitselected->LatestTime[ i ] = GetTickCount( );
  2500.  
  2501.                                         sprintf_s( PrintBuffer, 2048, "|c00FF5000[FogCW v10.9]|r: Player %s%s|r select fogged %s%s|r|r [POSSIBLE]\0",
  2502.                                                    GetPlayerColorString( Player( i ) ),
  2503.                                                    GetPlayerName( i, 0 ),
  2504.                                                    GetPlayerColorString( Player( OwnedPlayerSlot ) ),
  2505.                                                    GetObjectName( selectedunit ) );
  2506.                                     }
  2507.                                     ActionTime = tmpActionTime;
  2508.                                     DisplayText( PrintBuffer, 6.0f );
  2509.                                     LatestPlayer = hCurrentPlayer;
  2510.                                     LatestUnit = selectedunit;
  2511.  
  2512.  
  2513.                                     break;
  2514.                                 }
  2515.  
  2516.                             }
  2517.                         }
  2518.                     }
  2519.                 }
  2520.             }
  2521.         }
  2522.     }
  2523.     catch ( ... )
  2524.     {
  2525.         try
  2526.         {
  2527.             sprintf_s( PrintBuffer, 2048, "%s", "|c00FF2000[FogCW v10.9 by Absol]: ERROR!! Warning thread FogWatcher aborted! ERROR SKIPPED.|r" );
  2528.             ActionTime = GetGameTime( );
  2529.             AddStringToLogFile( PrintBuffer );
  2530.             sprintf_s( PrintBuffer, 2048, "%s", "|c00FF2000[FogCW v10.9 by Absol]: ERROR: %X.|r", GetLastError( ) );
  2531.             ActionTime = GetGameTime( );
  2532.             AddStringToLogFile( PrintBuffer );
  2533.         }
  2534.         catch ( ... )
  2535.         {
  2536.             MessageBox( 0, L"UNHANDLED EXCEPTION 1 FOG CLICK!", L"ERROR", 0 );
  2537.         }
  2538.     }
  2539. }
  2540. char absbuf[ 100 ];
  2541.  
  2542.  
  2543. void InitOtherFunctions( )
  2544. {
  2545.  
  2546.     if ( !FileExists( L".\\AbsolFogClickWatcher.ini" ) )
  2547.     {
  2548.         int pOldRecoveryJassNative1 = pRecoveryJassNative1;
  2549.         pRecoveryJassNative1 = CreateJassNativeHook( ( int ) GetSpellAbilityId_real, ( int ) &GetSpellAbilityId_hooked );
  2550.         if ( pRecoveryJassNative1 == 0 )
  2551.             pRecoveryJassNative1 = pOldRecoveryJassNative1;
  2552.  
  2553.         int pOldRecoveryJassNative2 = pRecoveryJassNative2;
  2554.         pRecoveryJassNative2 = CreateJassNativeHook( ( int ) GetTriggerEventId_real, ( int ) &GetTriggerEventId_hooked );
  2555.         if ( pRecoveryJassNative2 == 0 )
  2556.             pRecoveryJassNative2 = pOldRecoveryJassNative2;
  2557.  
  2558.         int pOldRecoveryJassNative3 = pRecoveryJassNative3;
  2559.         pRecoveryJassNative3 = CreateJassNativeHook( ( int ) GetIssuedOrderId_real, ( int ) &GetIssuedOrderId_hooked );
  2560.         if ( pRecoveryJassNative3 == 0 )
  2561.             pRecoveryJassNative3 = pOldRecoveryJassNative3;
  2562.  
  2563.         int pOldRecoveryJassNative4 = pRecoveryJassNative4;
  2564.         pRecoveryJassNative4 = CreateJassNativeHook( ( int ) GetSpellAbilityUnit_real, ( int ) &GetSpellAbilityUnit_hooked );
  2565.         if ( pRecoveryJassNative4 == 0 )
  2566.             pRecoveryJassNative4 = pOldRecoveryJassNative4;
  2567.  
  2568.         int pOldRecoveryJassNative5 = pRecoveryJassNative5;
  2569.         pRecoveryJassNative5 = CreateJassNativeHook( ( int ) GetAttacker_real, ( int ) &GetAttacker_hooked );
  2570.         if ( pRecoveryJassNative5 == 0 )
  2571.             pRecoveryJassNative5 = pOldRecoveryJassNative5;
  2572.  
  2573.         LocalPlayerDisabled = FALSE;
  2574.         LogEnabled = FALSE;
  2575.         UnitDetectionMethod = 3;
  2576.         DetectQuality = 2;
  2577.         PrintOrderName = FALSE;
  2578.         SkipIllusions = TRUE;
  2579.         DetectRightClickOnlyHeroes = FALSE;
  2580.         DetectImpossibleClicks = FALSE;
  2581.     }
  2582.     else
  2583.     {
  2584.  
  2585.  
  2586.         sprintf_s( absbuf, 100, "%s%s%s%s%s", "./", "Abs", "ol", "Fog", "ClickWatcher.ini" );
  2587.  
  2588.         if ( _stricmp( absolfogclicker, absbuf ) != 0 )
  2589.         {
  2590.             return;
  2591.         }
  2592.  
  2593.  
  2594.         INIReader fogwatcherconf( absolfogclicker );
  2595.  
  2596.         if ( fogwatcherconf.GetBoolean( "FogClickWatcher", "LogEnabled", TRUE ) )
  2597.         {
  2598.             if ( !logfile )
  2599.             {
  2600.                 logfile = _fsopen( "UnrealFogClickWatcherLog.txt", "a+", _SH_DENYWR );
  2601.                 setvbuf( logfile, NULL, _IOLBF, 256 );
  2602.             }
  2603.             LogEnabled = TRUE;
  2604.             if ( !FirstInitialized )
  2605.                 WatcherLog( "Write clicks in log %s\n", "TRUE" );
  2606.         }
  2607.  
  2608.  
  2609.         if ( fogwatcherconf.GetBoolean( "FogClickWatcher", "LocalPlayerEnable", FALSE ) )
  2610.         {
  2611.             if ( !FirstInitialized )
  2612.                 WatcherLog( "Config:LocalPlayerEnable->%s\n", "TRUE" );
  2613.             LocalPlayerDisabled = TRUE;
  2614.         }
  2615.         else
  2616.         {
  2617.             if ( !FirstInitialized )
  2618.                 WatcherLog( "Config:LocalPlayerEnable->%s\n", "FALSE" );
  2619.         }
  2620.  
  2621.  
  2622.         if ( fogwatcherconf.GetBoolean( "FogClickWatcher", "GetTriggerEventId", TRUE ) )
  2623.         {
  2624.             if ( !FirstInitialized )
  2625.                 WatcherLog( "Config:GetTriggerEventId->%s\n", "TRUE" );
  2626.             int pOldRecoveryJassNative2 = pRecoveryJassNative2;
  2627.             pRecoveryJassNative2 = CreateJassNativeHook( ( int ) GetTriggerEventId_real, ( int ) &GetTriggerEventId_hooked );
  2628.             if ( pRecoveryJassNative2 == 0 )
  2629.                 pRecoveryJassNative2 = pOldRecoveryJassNative2;
  2630.         }
  2631.         else
  2632.         {
  2633.             if ( !FirstInitialized )
  2634.                 WatcherLog( "Config:GetTriggerEventId->%s\n", "FALSE" );
  2635.         }
  2636.  
  2637.         if ( fogwatcherconf.GetBoolean( "FogClickWatcher", "GetSpellAbilityId", TRUE ) )
  2638.         {
  2639.             if ( !FirstInitialized )
  2640.                 WatcherLog( "Config:GetSpellAbilityId->%s\n", "TRUE" );
  2641.             int pOldRecoveryJassNative1 = pRecoveryJassNative1;
  2642.             pRecoveryJassNative1 = CreateJassNativeHook( ( int ) GetSpellAbilityId_real, ( int ) &GetSpellAbilityId_hooked );
  2643.             if ( pRecoveryJassNative1 == 0 )
  2644.                 pRecoveryJassNative1 = pOldRecoveryJassNative1;
  2645.         }
  2646.         else
  2647.         {
  2648.             if ( !FirstInitialized )
  2649.                 WatcherLog( "Config:GetSpellAbilityId->%s\n", "FALSE" );
  2650.         }
  2651.  
  2652.  
  2653.         if ( fogwatcherconf.GetBoolean( "FogClickWatcher", "GetIssuedOrderId", TRUE ) )
  2654.         {
  2655.             if ( !FirstInitialized )
  2656.                 WatcherLog( "Config:GetIssuedOrderId->%s\n", "TRUE" );
  2657.             int pOldRecoveryJassNative3 = pRecoveryJassNative3;
  2658.             pRecoveryJassNative3 = CreateJassNativeHook( ( int ) GetIssuedOrderId_real, ( int ) &GetIssuedOrderId_hooked );
  2659.             if ( pRecoveryJassNative3 == 0 )
  2660.                 pRecoveryJassNative3 = pOldRecoveryJassNative3;
  2661.         }
  2662.         else
  2663.         {
  2664.             if ( !FirstInitialized )
  2665.                 WatcherLog( "Config:GetIssuedOrderId->%s\n", "FALSE" );
  2666.         }
  2667.  
  2668.         if ( fogwatcherconf.GetBoolean( "FogClickWatcher", "GetAttacker", TRUE ) )
  2669.         {
  2670.             if ( !FirstInitialized )
  2671.                 WatcherLog( "Config:GetAttacker->%s\n", "TRUE" );
  2672.             int pOldRecoveryJassNative5 = pRecoveryJassNative5;
  2673.             pRecoveryJassNative5 = CreateJassNativeHook( ( int ) GetAttacker_real, ( int ) &GetAttacker_hooked );
  2674.             if ( pRecoveryJassNative5 == 0 )
  2675.                 pRecoveryJassNative5 = pOldRecoveryJassNative5;
  2676.         }
  2677.         else
  2678.         {
  2679.             if ( !FirstInitialized )
  2680.                 WatcherLog( "Config:GetAttacker->%s\n", "TRUE" );
  2681.         }
  2682.  
  2683.         if ( fogwatcherconf.GetBoolean( "FogClickWatcher", "GetSpellAbilityUnit", TRUE ) )
  2684.         {
  2685.             if ( !FirstInitialized )
  2686.                 WatcherLog( "Config:GetSpellAbilityUnit->%s\n", "TRUE" );
  2687.             int pOldRecoveryJassNative4 = pRecoveryJassNative4;
  2688.             pRecoveryJassNative4 = CreateJassNativeHook( ( int ) GetSpellAbilityUnit_real, ( int ) &GetSpellAbilityUnit_hooked );
  2689.             if ( pRecoveryJassNative4 == 0 )
  2690.                 pRecoveryJassNative4 = pOldRecoveryJassNative4;
  2691.  
  2692.         }
  2693.         else
  2694.         {
  2695.             if ( !FirstInitialized )
  2696.                 WatcherLog( "Config:GetSpellAbilityUnit->%s\n", "TRUE" );
  2697.         }
  2698.  
  2699.  
  2700.         if ( UnitDetectionMethod = fogwatcherconf.GetInteger( "FogClickWatcher", "UnitDetectionMethod", 3 ) )
  2701.         {
  2702.             if ( !FirstInitialized )
  2703.                 WatcherLog( "Config:UnitDetectionMethod->%i\n", UnitDetectionMethod );
  2704.         }
  2705.         else
  2706.         {
  2707.             if ( !FirstInitialized )
  2708.                 WatcherLog( "Config:UnitDetectionMethod->%i\n", 3 );
  2709.         }
  2710.  
  2711.  
  2712.  
  2713.  
  2714.  
  2715.  
  2716.         if ( !fogwatcherconf.GetBoolean( "FogClickWatcher", "DetectRightClickOnlyHeroes", FALSE ) )
  2717.         {
  2718.             if ( !FirstInitialized )
  2719.                 WatcherLog( "Config:DetectRightClickOnlyHeroes->%s\n", "FALSE" );
  2720.             DetectRightClickOnlyHeroes = FALSE;
  2721.         }
  2722.         else
  2723.         {
  2724.             if ( !FirstInitialized )
  2725.                 WatcherLog( "Config:DetectRightClickOnlyHeroes->%s\n", "TRUE" );
  2726.         }
  2727.  
  2728.  
  2729.         if ( fogwatcherconf.GetBoolean( "FogClickWatcher", "MinimapPingFogClick", FALSE ) )
  2730.         {
  2731.             if ( !FirstInitialized )
  2732.                 WatcherLog( "Config:MinimapPingFogClick->%s\n", "TRUE" );
  2733.             MinimapPingFogClick = TRUE;
  2734.         }
  2735.         else
  2736.         {
  2737.             if ( !FirstInitialized )
  2738.                 WatcherLog( "Config:MinimapPingFogClick->%s\n", "FALSE" );
  2739.         }
  2740.  
  2741.  
  2742.         if ( DetectQuality = fogwatcherconf.GetInteger( "FogClickWatcher", "DetectQuality", 2 ) )
  2743.         {
  2744.             if ( !FirstInitialized )
  2745.                 WatcherLog( "Config:DetectQuality->%i\n", DetectQuality );
  2746.         }
  2747.         else
  2748.         {
  2749.             if ( !FirstInitialized )
  2750.                 WatcherLog( "Config:DetectQuality->%i\n", 2 );
  2751.         }
  2752.  
  2753.  
  2754.         if ( fogwatcherconf.GetBoolean( "FogClickWatcher", "PrintOrderName", FALSE ) )
  2755.         {
  2756.             if ( !FirstInitialized )
  2757.                 WatcherLog( "Config:PrintOrderName->%s\n", "TRUE" );
  2758.             PrintOrderName = TRUE;
  2759.         }
  2760.         else
  2761.         {
  2762.             if ( !FirstInitialized )
  2763.                 WatcherLog( "Config:PrintOrderName->%s\n", "FALSE" );
  2764.         }
  2765.  
  2766.  
  2767.  
  2768.  
  2769.         if ( !fogwatcherconf.GetBoolean( "FogClickWatcher", "SkipIllusions", FALSE ) )
  2770.         {
  2771.             if ( !FirstInitialized )
  2772.                 WatcherLog( "Config:SkipIllusions->%s\n", "FALSE" );
  2773.             SkipIllusions = FALSE;
  2774.         }
  2775.         else
  2776.         {
  2777.             if ( !FirstInitialized )
  2778.                 WatcherLog( "Config:SkipIllusions->%s\n", "TRUE" );
  2779.         }
  2780.  
  2781.         if ( fogwatcherconf.GetBoolean( "FogClickWatcher", "DetectImpossibleClicks", FALSE ) )
  2782.         {
  2783.             if ( !FirstInitialized )
  2784.                 WatcherLog( "Config:DetectImpossibleClicks->%s\n", "TRUE" );
  2785.             DetectImpossibleClicks = TRUE;
  2786.         }
  2787.         else
  2788.         {
  2789.             if ( !FirstInitialized )
  2790.                 WatcherLog( "Config:DetectImpossibleClicks->%s\n", "FALSE" );
  2791.         }
  2792.  
  2793.         if ( fogwatcherconf.GetBoolean( "FogClickWatcher", "DetectItemDestroyer", FALSE ) )
  2794.         {
  2795.             if ( !FirstInitialized )
  2796.                 WatcherLog( "Config:DetectItemDestroyer->%s\n", "TRUE" );
  2797.             DetectItemDestroyer = TRUE;
  2798.         }
  2799.         else
  2800.         {
  2801.             if ( !FirstInitialized )
  2802.                 WatcherLog( "Config:DetectItemDestroyer->%s\n", "FALSE" );
  2803.         }
  2804.  
  2805.  
  2806.         if ( fogwatcherconf.GetBoolean( "FogClickWatcher", "DetectOwnItems", FALSE ) )
  2807.         {
  2808.             if ( !FirstInitialized )
  2809.                 WatcherLog( "Config:DetectOwnItems->%s\n", "TRUE" );
  2810.             DetectOwnItems = TRUE;
  2811.         }
  2812.         else
  2813.         {
  2814.             if ( !FirstInitialized )
  2815.                 WatcherLog( "Config:DetectOwnItems->%s\n", "FALSE" );
  2816.         }
  2817.  
  2818.  
  2819.  
  2820.         if ( fogwatcherconf.GetBoolean( "FogClickWatcher", "DetectPointClicks", FALSE ) )
  2821.         {
  2822.             if ( !FirstInitialized )
  2823.                 WatcherLog( "Config:DetectPointClicks->%s\n", "TRUE" );
  2824.             DetectPointClicks = TRUE;
  2825.         }
  2826.         else
  2827.         {
  2828.             if ( !FirstInitialized )
  2829.                 WatcherLog( "Config:DetectPointClicks->%s\n", "FALSE" );
  2830.         }
  2831.  
  2832.  
  2833.         if ( fogwatcherconf.GetBoolean( "FogClickWatcher", "DebugLog", FALSE ) )
  2834.         {
  2835.             if ( !FirstInitialized )
  2836.                 WatcherLog( "Config:DebugLog->%s\n", "TRUE" );
  2837.             DebugLog = TRUE;
  2838.         }
  2839.         else
  2840.         {
  2841.             if ( !FirstInitialized )
  2842.                 WatcherLog( "Config:DebugLog->%s\n", "FALSE" );
  2843.         }
  2844.  
  2845.  
  2846.  
  2847.         //DetectRightClickOnlyHeroes
  2848.         FirstInitialized = TRUE;
  2849.     }
  2850.  
  2851.     ActionTime = GetCurrentLocalTime( );
  2852.     AddStringToLogFile( ".......UnrealFogClickWatcher v10.9 for Warcraft 1.26a/1.27a by Absol......" );
  2853. }
  2854.  
  2855. LPVOID TlsValue;
  2856. DWORD TlsIndex;
  2857. DWORD _W3XTlsIndex;
  2858.  
  2859. DWORD GetIndex( )
  2860. {
  2861.     return *( DWORD* ) ( _W3XTlsIndex );
  2862. }
  2863.  
  2864. DWORD GetW3TlsForIndex( DWORD index )
  2865. {
  2866.     DWORD pid = GetCurrentProcessId( );
  2867.     THREADENTRY32 te32;
  2868.     HANDLE hSnap = CreateToolhelp32Snapshot( TH32CS_SNAPTHREAD, pid );
  2869.     te32.dwSize = sizeof( THREADENTRY32 );
  2870.  
  2871.     if ( Thread32First( hSnap, &te32 ) )
  2872.     {
  2873.         do
  2874.         {
  2875.             if ( te32.th32OwnerProcessID == pid )
  2876.             {
  2877.                 HANDLE hThread = OpenThread( THREAD_ALL_ACCESS, false, te32.th32ThreadID );
  2878.                 CONTEXT ctx = { CONTEXT_SEGMENTS };
  2879.                 LDT_ENTRY ldt;
  2880.                 GetThreadContext( hThread, &ctx );
  2881.                 GetThreadSelectorEntry( hThread, ctx.SegFs, &ldt );
  2882.                 DWORD dwThreadBase = ldt.BaseLow | ( ldt.HighWord.Bytes.BaseMid <<
  2883.                                                      16 ) | ( ldt.HighWord.Bytes.BaseHi << 24 );
  2884.                 CloseHandle( hThread );
  2885.                 if ( dwThreadBase == NULL )
  2886.                     continue;
  2887.                 DWORD* dwTLS = *( DWORD** ) ( dwThreadBase + 0xE10 + 4 * index );
  2888.                 if ( dwTLS == NULL )
  2889.                     continue;
  2890.                 return ( DWORD ) dwTLS;
  2891.             }
  2892.         }
  2893.         while ( Thread32Next( hSnap, &te32 ) );
  2894.     }
  2895.  
  2896.     return NULL;
  2897. }
  2898.  
  2899. void SetTlsForMe( )
  2900. {
  2901.     TlsIndex = GetIndex( );
  2902.     LPVOID tls = ( LPVOID ) GetW3TlsForIndex( TlsIndex );
  2903.     TlsValue = tls;
  2904. }
  2905.  
  2906.  
  2907.  
  2908. void * PlayerWatchThread = 0;
  2909.  
  2910. BOOL GameStartedReally = FALSE;
  2911.  
  2912. DWORD __stdcall SelectFogWatcher126a( void * )
  2913. {
  2914.     TlsSetValue( TlsIndex, TlsValue );
  2915.  
  2916.     try
  2917.     {
  2918.         while ( TRUE )
  2919.         {
  2920.             if ( GameStarted && *( BOOL* ) IsInGame && GetGameTime( ) > 0 )
  2921.             {
  2922.                 SearchPlayersFogSelect( );
  2923.                 if ( !GameStartedReally )
  2924.                 {
  2925.                     GameStartedReally = TRUE;
  2926.                     sprintf_s( PrintBuffer, 2048, "%s", "|c00FF2000[FogCW v10.9 by Absol]: Initialized. (d3scene.com/d3scene.ru)|r\0" );
  2927.                     ActionTime = 0;
  2928.                     DisplayText( PrintBuffer, 6.0f );
  2929.                     Sleep( 4000 );
  2930.                 }
  2931.             }
  2932.             else
  2933.             {
  2934.                 if ( GameStartedReally )
  2935.                 {
  2936.  
  2937.                 }
  2938.                 GameStartedReally = FALSE;
  2939.             }
  2940.             Sleep( 200 );
  2941.         }
  2942.     }
  2943.     catch ( ... )
  2944.     {
  2945.         try
  2946.         {
  2947.             PlayerWatchThread = CreateThread( 0, 0, SelectFogWatcher126a, 0, 0, 0 );
  2948.             sprintf_s( PrintBuffer, 2048, "%s", "|c00FF2000[FogCW v10.9 by Absol]: ERROR!! Warning thread FogWatcher aborted! ERROR SKIPPED.|r" );
  2949.             ActionTime = GetGameTime( );
  2950.             AddStringToLogFile( PrintBuffer );
  2951.             sprintf_s( PrintBuffer, 2048, "%s", "|c00FF2000[FogCW v10.9 by Absol]: ERROR: %X.|r", GetLastError( ) );
  2952.             ActionTime = GetGameTime( );
  2953.             AddStringToLogFile( PrintBuffer );
  2954.             return 0;
  2955.         }
  2956.         catch ( ... )
  2957.         {
  2958.             MessageBox( 0, L"UNHANDLED EXCEPTION 1 FOG CLICK!", L"ERROR", 0 );
  2959.         }
  2960.     }
  2961.  
  2962.     return 0;
  2963. }
  2964.  
  2965.  
  2966.  
  2967. DWORD __stdcall SelectFogWatcher127a( void * )
  2968. {
  2969.     TlsSetValue( TlsIndex, TlsValue );
  2970.  
  2971.     try
  2972.     {
  2973.         while ( TRUE )
  2974.         {
  2975.             if ( GameStarted  && *( BOOL* ) IsInGame && GetGameTime( ) > 0 )
  2976.             {
  2977.                 if ( !GameStartedReally )
  2978.                 {
  2979.                     GameStartedReally = TRUE;
  2980.                     sprintf_s( PrintBuffer, 2048, "%s", "|c00FF2000[FogCW v10.9 by Absol]: Initialized. (d3scene.com/d3scene.ru)|r\0" );
  2981.                     ActionTime = 0;
  2982.                     DisplayText( PrintBuffer, 6.0f );
  2983.                     Sleep( 4000 );
  2984.                 }
  2985.                 SearchPlayersFogSelect( );
  2986.             }
  2987.             else
  2988.             {
  2989.                 GameStartedReally = FALSE;
  2990.             }
  2991.             Sleep( 150 );
  2992.         }
  2993.     }
  2994.     catch ( ... )
  2995.     {
  2996.         try
  2997.         {
  2998.             PlayerWatchThread = CreateThread( 0, 0, SelectFogWatcher126a, 0, 0, 0 );
  2999.             sprintf_s( PrintBuffer, 2048, "%s", "|c00FF2000[FogCW v10.9 by Absol]: ERROR!! Warning thread FogWatcher aborted! ERROR SKIPPED.|r" );
  3000.             ActionTime = GetGameTime( );
  3001.             AddStringToLogFile( PrintBuffer );
  3002.             sprintf_s( PrintBuffer, 2048, "%s", "|c00FF2000[FogCW v10.9 by Absol]: ERROR: %X.|r", GetLastError( ) );
  3003.             ActionTime = GetGameTime( );
  3004.             AddStringToLogFile( PrintBuffer );
  3005.             return 0;
  3006.         }
  3007.         catch ( ... )
  3008.         {
  3009.             MessageBox( 0, L"UNHANDLED EXCEPTION 1 FOG CLICK!", L"ERROR", 0 );
  3010.         }
  3011.     }
  3012.  
  3013.     return 0;
  3014. }
  3015.  
  3016.  
  3017. DWORD WINAPI RecoveryJass( LPVOID )
  3018. {
  3019.  
  3020.     try
  3021.     {
  3022.  
  3023.         if ( pRecoveryJassNative1 > 0 )
  3024.         {
  3025.             if ( !IsBadReadPtr( ( void* ) pRecoveryJassNative1, 4 ) )
  3026.             {
  3027.                 if ( !IsBadWritePtr( ( void* ) pRecoveryJassNative1, 4 ) )
  3028.                 {
  3029.                     *( int* ) pRecoveryJassNative1 = ( int ) GetSpellAbilityId_real;
  3030.                 }
  3031.             }
  3032.         }
  3033.     }
  3034.     catch ( ... )
  3035.     {
  3036.  
  3037.     }
  3038.     try
  3039.     {
  3040.         if ( pRecoveryJassNative2 > 0 )
  3041.         {
  3042.             if ( !IsBadReadPtr( ( void* ) pRecoveryJassNative2, 4 ) )
  3043.             {
  3044.                 if ( !IsBadWritePtr( ( void* ) pRecoveryJassNative2, 4 ) )
  3045.                 {
  3046.                     *( int* ) pRecoveryJassNative2 = ( int ) GetTriggerEventId_real;
  3047.                 }
  3048.             }
  3049.         }
  3050.     }
  3051.     catch ( ... )
  3052.     {
  3053.  
  3054.     }
  3055.  
  3056.     try
  3057.     {
  3058.         if ( pRecoveryJassNative3 > 0 )
  3059.         {
  3060.             if ( !IsBadReadPtr( ( void* ) pRecoveryJassNative3, 4 ) )
  3061.             {
  3062.                 if ( !IsBadWritePtr( ( void* ) pRecoveryJassNative3, 4 ) )
  3063.                 {
  3064.                     *( int* ) pRecoveryJassNative3 = ( int ) GetIssuedOrderId_real;
  3065.                 }
  3066.             }
  3067.         }
  3068.     }
  3069.     catch ( ... )
  3070.     {
  3071.  
  3072.     }
  3073.     try
  3074.     {
  3075.         if ( pRecoveryJassNative4 > 0 )
  3076.         {
  3077.             if ( !IsBadReadPtr( ( void* ) pRecoveryJassNative4, 4 ) )
  3078.             {
  3079.                 if ( !IsBadWritePtr( ( void* ) pRecoveryJassNative4, 4 ) )
  3080.                 {
  3081.                     *( int* ) pRecoveryJassNative4 = ( int ) GetSpellAbilityUnit_real;
  3082.                 }
  3083.             }
  3084.         }
  3085.     }
  3086.     catch ( ... )
  3087.     {
  3088.  
  3089.     }
  3090.  
  3091.     try
  3092.     {
  3093.         if ( pRecoveryJassNative5 > 0 )
  3094.         {
  3095.             if ( !IsBadReadPtr( ( void* ) pRecoveryJassNative5, 4 ) )
  3096.             {
  3097.                 if ( !IsBadWritePtr( ( void* ) pRecoveryJassNative5, 4 ) )
  3098.                 {
  3099.                     *( int* ) pRecoveryJassNative5 = ( int ) GetAttacker_real;
  3100.                 }
  3101.             }
  3102.         }
  3103.     }
  3104.     catch ( ... )
  3105.     {
  3106.  
  3107.     }
  3108.  
  3109.     return 0;
  3110. }
  3111.  
  3112. void * GameWaitThreadID = 0;
  3113. DWORD __stdcall GameWaiting( void * )
  3114. {
  3115.     while ( TRUE )
  3116.     {
  3117.         if ( *( BOOL* ) IsInGame  && GetGameTime( ) > 0 )
  3118.         {
  3119.             if ( !GameStarted )
  3120.             {
  3121.                 StartGameTime = GetTickCount( );
  3122.                 ClickCount.clear( );
  3123.                 FogHelperList.clear( );
  3124.                 LatestUnit = 0;
  3125.                 LatestPlayer = 0;
  3126.                 LatestAbilSpell = 0;
  3127.                 memset( PlayerSelectedItems, 0, sizeof( PlayerSelectedItems ) );
  3128.                 memset( PlayerEventList, 0, sizeof( PlayerEventList ) );
  3129.                 memset( PlayerMeepoDetect, 0, sizeof( PlayerMeepoDetect ) );
  3130.  
  3131.                 LastEventTime = 0;
  3132.  
  3133.                 latestcheck = 0;
  3134.                 ActionTime = 0;
  3135.  
  3136.                 if ( LogEnabled )
  3137.                 {
  3138.                     ActionTime = GetCurrentLocalTime( );
  3139.                     WatcherLog( "Watch fog clicks for Game id : %i\n", GameID++ );
  3140.                 }
  3141.  
  3142.                 GameStarted = TRUE;
  3143.                 InitOtherFunctions( );
  3144.             }
  3145.         }
  3146.         else
  3147.         {
  3148.             if ( GameStarted )
  3149.             {
  3150.                 CreateThread( 0, 0, RecoveryJass, 0, 0, 0 );
  3151.                 StartGameTime = GetTickCount( );
  3152.                 ClickCount.clear( );
  3153.                 FogHelperList.clear( );
  3154.                 LatestUnit = 0;
  3155.                 LatestPlayer = 0;
  3156.                 LatestAbilSpell = 0;
  3157.                 memset( PlayerSelectedItems, 0, sizeof( PlayerSelectedItems ) );
  3158.                 memset( PlayerEventList, 0, sizeof( PlayerEventList ) );
  3159.                 memset( PlayerMeepoDetect, 0, sizeof( PlayerMeepoDetect ) );
  3160.  
  3161.                 LastEventTime = 0;
  3162.  
  3163.                 latestcheck = 0;
  3164.                 ActionTime = 0;
  3165.                 GameStarted = FALSE;
  3166.             }
  3167.  
  3168.    
  3169.         }
  3170.  
  3171.         Sleep( 20 );
  3172.     }
  3173.  
  3174.     return 0;
  3175. }
  3176.  
  3177.  
  3178.  
  3179. void Init126aVer( )
  3180. {
  3181.     GameVersion = 0x126a;
  3182.     IsInGame = GameDll + 0xAB62A4;
  3183.     pJassEnvAddress = GameDll + 0xADA848;
  3184.     GetTypeInfo = ( p_GetTypeInfo ) ( GameDll + 0x32C880 );
  3185.     GetPlayerName = ( p_GetPlayerName ) ( GameDll + 0x2F8F90 );
  3186.     GetSpellAbilityId_real = ( pGetSpellAbilityId ) ( GameDll + 0x3C32A0 );
  3187.     GetSpellAbilityUnit_real = ( pGetSpellAbilityUnit ) ( GameDll + 0x3C3470 );
  3188.     GetSpellTargetUnit = ( pGetSpellTargetUnit ) ( GameDll + 0x3C3A80 );
  3189.     GetSpellTargetX = ( pGetSpellTargetX ) ( GameDll + 0x3C3580 );
  3190.     GetSpellTargetY = ( pGetSpellTargetY ) ( GameDll + 0x3C3670 );
  3191.     GetHandleUnitAddress = ( pGetHandleUnitAddress ) ( GameDll + 0x3BDCB0 );
  3192.     GetHandleItemAddress = ( pGetHandleUnitAddress ) ( GameDll + 0x3BEB50 );
  3193.     IsUnitSelectedAddr = GameDll + 0x3C7E00 + 0xA;
  3194.     IsUnitVisibledAddr = GameDll + 0x3C7AF0 + 0xA;
  3195.     pW3XGlobalClass = GameDll + 0xAB4F80;
  3196.     pPrintText2 = GameDll + 0x2F69A0;
  3197.     GAME_PrintToScreen = GameDll + 0x2F8E40;
  3198.     GetPlayerColor = ( pGetPlayerColor ) ( GameDll + 0x3C1240 );
  3199.     UnitVtable = GameDll + 0x931934;
  3200.     ItemVtable = GameDll + 0x9320B4;
  3201.     IsPlayerEnemyReal = ( pIsPlayerEnemy ) ( GameDll + 0x3C9580 );
  3202.     PlayerReal = ( pPlayer ) ( GameDll + 0x3BBB30 );
  3203.     IsFoggedToPlayerReal = ( pIsFoggedToPlayer ) ( GameDll + 0x3C9980 );
  3204.     GetTriggerEventId_real = ( pGetTriggerEventId ) ( GameDll + 0x3BB2C0 );
  3205.     GetIssuedOrderId_real = ( pGetIssuedOrderId ) ( GameDll + 0x3C2C80 );
  3206.     GetAttacker_real = ( pGetAttacker ) ( GameDll + 0x3C20F0 );
  3207.     GetTriggerUnit = ( pGetTriggerUnit ) ( GameDll + 0x3BB240 );
  3208.     GetOrderTargetUnit = ( pGetOrderTargetUnit ) ( GameDll + 0x3C3170 );
  3209.     GetOrderTargetItem = ( pGetOrderTargetItem ) ( GameDll + 0x3C3040 );
  3210.     GetOrderPointX = ( pGetOrderPointX ) ( GameDll + 0x3C2D00 );
  3211.     GetOrderPointY = ( pGetOrderPointY ) ( GameDll + 0x3C2D50 );
  3212.     GameTimeOffset = GameDll + 0xAB7E98;
  3213.     GetPlayerController = ( pGetPlayerController ) ( GameDll + 0x3C12B0 );
  3214.     GetPlayerSlotState = ( pGetPlayerSlotState ) ( GameDll + 0x3C12D0 );
  3215.     pGlobalPlayerData = 0xAB65F4 + GameDll;
  3216.     PingMinimapEx = ( pPingMinimapEx ) ( GameDll + 0x3B8660 );
  3217.     _W3XTlsIndex = 0xAB7BF4 + GameDll;
  3218.     sub_6F03FA30_Addr = 0x03FA30 + GameDll;
  3219.     GameStarted = TRUE;
  3220.  
  3221.     //InitOtherFunctions( );
  3222.  
  3223.     GameWaitThreadID = CreateThread( 0, 0, GameWaiting, 0, 0, 0 );
  3224.     PlayerWatchThread = CreateThread( 0, 0, SelectFogWatcher126a, 0, 0, 0 );
  3225.  
  3226. }
  3227.  
  3228.  
  3229. void Init127aVer( )
  3230. {
  3231.     GameVersion = 0x127a;
  3232.     IsInGame = GameDll + 0xBE6530;
  3233.     pJassEnvAddress = GameDll + 0xBE3740;
  3234.     GetTypeInfo = ( p_GetTypeInfo ) ( GameDll + 0x327020 );
  3235.     GetPlayerName = ( p_GetPlayerName ) ( GameDll + 0x34F730 );
  3236.     GetSpellAbilityId_real = ( pGetSpellAbilityId ) ( GameDll + 0x1E4DD0 );
  3237.     GetSpellAbilityUnit_real = ( pGetSpellAbilityUnit ) ( GameDll + 0x1E4E40 );
  3238.     GetSpellTargetUnit = ( pGetSpellTargetUnit ) ( GameDll + 0x1E52B0 );
  3239.     GetSpellTargetX = ( pGetSpellTargetX ) ( GameDll + 0x1E53E0 );
  3240.     GetSpellTargetY = ( pGetSpellTargetY ) ( GameDll + 0x1E54C0 );
  3241.     GetHandleUnitAddress = ( pGetHandleUnitAddress ) ( GameDll + 0x1D1550 );
  3242.     GetHandleItemAddress = ( pGetHandleUnitAddress ) ( GameDll + 0x1CFC50 );
  3243.     IsUnitSelectedAddr = GameDll + 0x1E8C40 + 0xC;
  3244.     IsUnitVisibledAddr = GameDll + 0x1E8E80 + 0xC;
  3245.     pW3XGlobalClass = GameDll + 0xBE6350;
  3246.     pPrintText2 = GameDll + 0x3577B0;
  3247.     GAME_PrintToScreen = GameDll + 0x357640;
  3248.     GetPlayerColor = ( pGetPlayerColor ) ( GameDll + 0x1E3CA0 );
  3249.     UnitVtable = GameDll + 0xA4A704;
  3250.     ItemVtable = GameDll + 0xA4A2EC;
  3251.     IsPlayerEnemyReal = ( pIsPlayerEnemy ) ( GameDll + 0x1E8090 );
  3252.     PlayerReal = ( pPlayer ) ( GameDll + 0x1F1E70 );
  3253.     IsFoggedToPlayerReal = ( pIsFoggedToPlayer ) ( GameDll + 0x1E7A10 );
  3254.     GetTriggerEventId_real = ( pGetTriggerEventId ) ( GameDll + 0x1E5D90 );
  3255.     GetIssuedOrderId_real = ( pGetIssuedOrderId ) ( GameDll + 0x1E2B60 );
  3256.     GetAttacker_real = ( pGetAttacker ) ( GameDll + 0x1E16B0 );
  3257.     GetTriggerUnit = ( pGetTriggerUnit ) ( GameDll + 0x1E5E10 );
  3258.     GetOrderTargetUnit = ( pGetOrderTargetUnit ) ( GameDll + 0x1E3A00 );
  3259.     GetOrderTargetItem = ( pGetOrderTargetItem ) ( GameDll + 0x1E38E0 );
  3260.     GetOrderPointX = ( pGetOrderPointX ) ( GameDll + 0x1E35C0 );
  3261.     GetOrderPointY = ( pGetOrderPointY ) ( GameDll + 0x1E3610 );
  3262.     GameTimeOffset = GameDll + 0xBE3D70;
  3263.     GetPlayerController = ( pGetPlayerController ) ( GameDll + 0x1E3CC0 );
  3264.     GetPlayerSlotState = ( pGetPlayerSlotState ) ( GameDll + 0x1E3FE0 );
  3265.     pGlobalPlayerData = 0xBE4238 + GameDll;
  3266.     PingMinimapEx = ( pPingMinimapEx ) ( GameDll + 0x1F1C30 );
  3267.     _W3XTlsIndex = 0xBB8628 + GameDll;
  3268.     sub_6F03FA30_Addr = 0x037350 + GameDll;
  3269.     GameStarted = TRUE;
  3270.     //InitOtherFunctions( );
  3271.     GameWaitThreadID = CreateThread( 0, 0, GameWaiting, 0, 0, 0 );
  3272.     PlayerWatchThread = CreateThread( 0, 0, SelectFogWatcher127a, 0, 0, 0 );
  3273. }
  3274.  
  3275.  
  3276. void InitializeFogClickWatcher( )
  3277. {
  3278.     HMODULE hGameDll = GetModuleHandle( L"Game.dll" );
  3279.     if ( !hGameDll )
  3280.     {
  3281.         MessageBox( 0, L"UnrealFogClickWatcher problem!\nNo game.dll found.", L"Game.dll not found", 0 );
  3282.         return;
  3283.     }
  3284.  
  3285.     GameDll = ( int ) hGameDll;
  3286.  
  3287.     CFileVersionInfo gdllver;
  3288.     gdllver.Open( hGameDll );
  3289.     // Game.dll version (1.XX)
  3290.     int GameDllVer = gdllver.GetFileVersionQFE( );
  3291.     gdllver.Close( );
  3292.  
  3293.     if ( GameDllVer == 6401 )
  3294.     {
  3295.         Init126aVer( );
  3296.     }
  3297.     else if ( GameDllVer == 52240 )
  3298.     {
  3299.         Init127aVer( );
  3300.     }
  3301.     else
  3302.     {
  3303.         MessageBox( 0, L"UnrealFogClickWatcher problem!\nGame version not supported.", L"\nGame version not supported", 0 );
  3304.         return;
  3305.     }
  3306.  
  3307.     SetTlsForMe( );
  3308.     TlsSetValue( TlsIndex, TlsValue );
  3309.  
  3310.  
  3311.     // 6401 - 126
  3312.     // 52240 - 127
  3313.  
  3314. }
  3315.  
  3316. BOOL NeedExit = FALSE;
  3317.  
  3318. int maxcontinuetime = 50;
  3319.  
  3320. DWORD WINAPI GetThreadStartAddress( HANDLE hThread )
  3321. {
  3322.     NTSTATUS ntStatus;
  3323.     HANDLE hDupHandle;
  3324.     DWORD dwStartAddress;
  3325.  
  3326.     pNtQIT NtQueryInformationThread = ( pNtQIT ) GetProcAddress( GetModuleHandle( L"ntdll.dll" ), "NtQueryInformationThread" );
  3327.  
  3328.     if ( NtQueryInformationThread == NULL )
  3329.         return 0;
  3330.  
  3331.     HANDLE hCurrentProcess = GetCurrentProcess( );
  3332.     if ( !DuplicateHandle( hCurrentProcess, hThread, hCurrentProcess, &hDupHandle, THREAD_QUERY_INFORMATION, FALSE, 0 ) )
  3333.     {
  3334.         SetLastError( ERROR_ACCESS_DENIED );
  3335.  
  3336.         return 0;
  3337.     }
  3338.  
  3339.     ntStatus = NtQueryInformationThread( hDupHandle, ThreadQuerySetWin32StartAddress, &dwStartAddress, sizeof( DWORD ), NULL );
  3340.     CloseHandle( hDupHandle );
  3341.     if ( ntStatus != STATUS_SUCCESS )
  3342.         return 0;
  3343.  
  3344.     return dwStartAddress;
  3345.  
  3346. }
  3347.  
  3348.  
  3349. LONG WINAPI OurCrashHandler( EXCEPTION_POINTERS * pExcept )
  3350. {
  3351.     const DWORD exceptionCode = pExcept->ExceptionRecord->ExceptionCode;
  3352.  
  3353.    
  3354.     if ( ( exceptionCode & ERROR_SEVERITY_ERROR ) != ERROR_SEVERITY_ERROR )
  3355.     {
  3356.         return ExceptionContinueExecution;
  3357.     }
  3358.  
  3359.     // Ignore custom exception codes.
  3360.     // MSXML likes to raise 0xE0000001 while parsing.
  3361.     // Note the C++ SEH (0xE06D7363) also fails in that range.
  3362.     if ( exceptionCode & APPLICATION_ERROR_MASK )
  3363.     {
  3364.         return ExceptionContinueExecution;
  3365.     }
  3366.  
  3367.  
  3368.     if ( NeedExit )
  3369.     {
  3370.         WatcherLog( "Force unload UnrealFogClickWatcher.\n" );
  3371.         TerminateProcess( GetCurrentProcess( ), 0 );
  3372.     }
  3373.  
  3374.  
  3375.     if ( pExcept )
  3376.     {
  3377.         if ( pExcept->ExceptionRecord->ExceptionCode == 0x406D1388 )
  3378.             return ExceptionContinueExecution;
  3379.  
  3380.         maxcontinuetime--;
  3381.         if ( maxcontinuetime > 0 )
  3382.         {
  3383.             if ( GetCurrentThread( ) == PlayerWatchThread )
  3384.             {
  3385.                 ActionTime = GetGameTime( );
  3386.                 WatcherLog( "Critical Error in fog selection detector! Addr:%X, Code:%X, Win32:%X\n", pExcept->ExceptionRecord->ExceptionAddress, pExcept->ExceptionRecord->ExceptionCode, GetLastError( ) );
  3387.                 WatcherLog( "Game.dll base: %X\n", GetModuleHandle( L"Game.dll" ) );
  3388.                 WatcherLog( "FogClickWatcher base: %X\n", MainModule );
  3389.                 WatcherLog( "Game version: 0x%X\n", GameVersion );
  3390.                 if ( GameStarted )
  3391.                 {
  3392.                     WatcherLog( "MAIN::GameStarted->TRUE\n" );
  3393.                 }
  3394.                 else
  3395.                 {
  3396.                     WatcherLog( "MAIN::GameStarted->FALSE\n" );
  3397.                 }
  3398.  
  3399.                 if ( *( BOOL* ) IsInGame )
  3400.                 {
  3401.                     WatcherLog( "MAIN::IsInGame->TRUE\n" );
  3402.                 }
  3403.                 else
  3404.                 {
  3405.                     WatcherLog( "MAIN::IsInGame->FALSE\n" );
  3406.                 }
  3407.  
  3408.                 WatcherLog( "Try to restart thread if it possibled.\n" );
  3409.                 CreateThread( 0, 0, (LPTHREAD_START_ROUTINE)GetThreadStartAddress( GetCurrentThread( ) ), 0, 0, 0 );
  3410.                 TerminateThread( GetCurrentThread( ), 0 );
  3411.             }
  3412.             else if ( GetCurrentThread( ) == MainThread )
  3413.             {
  3414.                 ActionTime = GetGameTime( );
  3415.                 if ( GetLastError( ) == 0x36B7 )
  3416.                 {
  3417.                     WatcherLog( "No error! Just need terminate process!\n" );
  3418.                     TerminateProcess( GetCurrentProcess( ), 0 );
  3419.                 }
  3420.  
  3421.            
  3422.                 WatcherLog( "Critical Error in Warcraft 3. Addr:%X, Code:%X, Win32:%X\n", pExcept->ExceptionRecord->ExceptionAddress, pExcept->ExceptionRecord->ExceptionCode, GetLastError( ) );
  3423.                 if ( ExceptionFilterHooked )
  3424.                 {
  3425.                     WatcherLog( "Impossible to skip error.\n" );
  3426.                 }
  3427.                 else
  3428.                 {
  3429.                     WatcherLog( "Possible to pass error to Storm.dll Exception Filter.\n" );
  3430.                 }
  3431.  
  3432.                 if ( GetLastError( ) == 0x7E )
  3433.                 {
  3434.                     WatcherLog( "But try to skip!\n" );
  3435.                     SetLastError( ERROR_SUCCESS );
  3436.                     return ExceptionContinueExecution;
  3437.                 }
  3438.  
  3439.  
  3440.                 WatcherLog( "Game.dll base: %X\n", GetModuleHandle( L"Game.dll" ) );
  3441.                 WatcherLog( "FogClickWatcher base: %X\n", MainModule );
  3442.                 WatcherLog( "Game version: 0x%X\n", GameVersion );
  3443.                 if ( GameStarted )
  3444.                 {
  3445.                     WatcherLog( "MAIN::GameStarted->TRUE\n" );
  3446.                 }
  3447.                 else
  3448.                 {
  3449.                     WatcherLog( "MAIN::GameStarted->FALSE\n" );
  3450.                 }
  3451.  
  3452.                 if ( *( BOOL* ) IsInGame )
  3453.                 {
  3454.                     WatcherLog( "MAIN::IsInGame->TRUE\n" );
  3455.                 }
  3456.                 else
  3457.                 {
  3458.                     WatcherLog( "MAIN::IsInGame->FALSE\n" );
  3459.                 }
  3460.  
  3461.                 if ( ExceptionFilterHooked )
  3462.                 {
  3463.                     WatcherLog( "ExceptionFilterHooked->TRUE\nNeed terminate process.\n" );
  3464.                     ExitProcess( 0 );
  3465.                     return TRUE;
  3466.                 }
  3467.  
  3468.  
  3469.  
  3470.                 return ExceptionContinueSearch;
  3471.             }
  3472.             else
  3473.             {
  3474.                 ActionTime = GetGameTime( );
  3475.                 WatcherLog( "Unknown module cause crash! Try skip! Addr:%X, Code:%X, Win32:%X\n", pExcept->ExceptionRecord->ExceptionAddress, pExcept->ExceptionRecord->ExceptionCode, GetLastError( ) );
  3476.             }
  3477.  
  3478.             if ( GetLastError( ) == 0x36B7 )
  3479.             {
  3480.                 WatcherLog( "Need terminate process!\n" );
  3481.                 TerminateProcess( GetCurrentProcess( ), 0 );
  3482.             }
  3483.         }
  3484.         else
  3485.         {
  3486.             WatcherLog( "Warning, error can't be skipped! Try to disable error...\n", pExcept->ExceptionRecord->ExceptionAddress, pExcept->ExceptionRecord->ExceptionCode, GetLastError( ) );
  3487.             if ( GetCurrentThread( ) == MainThread )
  3488.             {
  3489.                 WatcherLog( "Warning. Need terminate process. (Error in main war3 module)!\n" );
  3490.                 WatcherLog( "Game.dll base: %X\n", GetModuleHandle( L"Game.dll" ) );
  3491.                 WatcherLog( "FogClickWatcher base: %X\n", MainModule );
  3492.                 WatcherLog( "Game version: 0x%X\n", GameVersion );
  3493.                 if ( GameStarted )
  3494.                 {
  3495.                     WatcherLog( "MAIN::GameStarted->TRUE\n" );
  3496.                 }
  3497.                 else
  3498.                 {
  3499.                     WatcherLog( "MAIN::GameStarted->FALSE\n" );
  3500.                 }
  3501.  
  3502.                 if ( *( BOOL* ) IsInGame )
  3503.                 {
  3504.                     WatcherLog( "MAIN::IsInGame->TRUE\n" );
  3505.                 }
  3506.                 else
  3507.                 {
  3508.                     WatcherLog( "MAIN::IsInGame->FALSE\n" );
  3509.                 }
  3510.                 TerminateProcess( GetCurrentProcess( ), 0 );
  3511.                 return 0;
  3512.             }
  3513.  
  3514.            
  3515.             WatcherLog( "Error skipped. (terminate thread)!\n" );
  3516.             WatcherLog( "Game.dll base: %X\n", GetModuleHandle( L"Game.dll" ) );
  3517.             WatcherLog( "FogClickWatcher base: %X\n", MainModule );
  3518.             WatcherLog( "Game version: 0x%X\n", GameVersion );
  3519.             if ( GameStarted )
  3520.             {
  3521.                 WatcherLog( "MAIN::GameStarted->TRUE\n" );
  3522.             }
  3523.             else
  3524.             {
  3525.                 WatcherLog( "MAIN::GameStarted->FALSE\n" );
  3526.             }
  3527.  
  3528.             if ( *( BOOL* ) IsInGame )
  3529.             {
  3530.                 WatcherLog( "MAIN::IsInGame->TRUE\n" );
  3531.             }
  3532.             else
  3533.             {
  3534.                 WatcherLog( "MAIN::IsInGame->FALSE\n" );
  3535.             }
  3536.  
  3537.             WatcherLog( "Try to restart thread if it possibled.\n" );
  3538.             CreateThread( 0, 0, ( LPTHREAD_START_ROUTINE ) GetThreadStartAddress( GetCurrentThread( ) ), 0, 0, 0 );
  3539.             TerminateThread( GetCurrentThread( ), 0 );
  3540.            
  3541.             return 0;
  3542.         }
  3543.     }
  3544.     return ExceptionContinueExecution;
  3545. }
  3546.  
  3547. BOOL __stdcall DllMain( HINSTANCE i, DWORD r, LPVOID )
  3548. {
  3549.     if ( r == DLL_PROCESS_ATTACH )
  3550.     {
  3551.  
  3552.  
  3553.         MainModule = i;
  3554.  
  3555.         DisableThreadLibraryCalls( i );
  3556.  
  3557.         MainThread = GetCurrentThread( );
  3558.  
  3559.  
  3560.         //_set_se_translator( translator );
  3561.  
  3562.         InitializeFogClickWatcher( );
  3563.  
  3564.         //WatcherLog( "%X", SetUnhandledExceptionFilter( OurCrashHandler ) );
  3565.         LPTOP_LEVEL_EXCEPTION_FILTER DefaultGameFilter = SetUnhandledExceptionFilter( OurCrashHandler );
  3566.         SetUnhandledExceptionFilter( DefaultGameFilter );
  3567.  
  3568.         if ( ( int ) DefaultGameFilter - ( int ) GetModuleHandle( L"Storm.dll" ) > 0 &&
  3569.              ( int ) DefaultGameFilter - ( int ) GetModuleHandle( L"Storm.dll" ) < 5000000 )
  3570.         {
  3571.             AddVectoredExceptionHandler( 1, OurCrashHandler );
  3572.         }
  3573.         else
  3574.         {
  3575.             WatcherLog( "Warning. Top level filter - hooked.!\nImpossible to pass control to TopLevelExceptionFilter from Storm.dll\n" );
  3576.             ExceptionFilterHooked = TRUE;
  3577.             AddVectoredExceptionHandler( 1, OurCrashHandler );
  3578.         }
  3579.  
  3580.         maxcontinuetime = 50;
  3581.  
  3582.     }
  3583.     else if ( r == DLL_PROCESS_DETACH )
  3584.     {
  3585.  
  3586.         NeedExit = TRUE;
  3587.  
  3588.  
  3589.         //AddVectoredExceptionHandler( 1, OurCrashHandler );
  3590.         try
  3591.         {
  3592.  
  3593.             if ( GameWaitThreadID )
  3594.                 TerminateThread( GameWaitThreadID, 0 );
  3595.  
  3596.             if ( PlayerWatchThread )
  3597.                 TerminateThread( PlayerWatchThread, 0 );
  3598.         }
  3599.         catch ( ... )
  3600.         {
  3601.  
  3602.         }
  3603.  
  3604.         try
  3605.         {
  3606.  
  3607.             if ( pRecoveryJassNative1 > 0 )
  3608.             {
  3609.                 if ( !IsBadReadPtr( ( void* ) pRecoveryJassNative1, 4 ) )
  3610.                 {
  3611.                     if ( !IsBadWritePtr( ( void* ) pRecoveryJassNative1, 4 ) )
  3612.                     {
  3613.                         *( int* ) pRecoveryJassNative1 = ( int ) GetSpellAbilityId_real;
  3614.                     }
  3615.                 }
  3616.             }
  3617.         }
  3618.         catch ( ... )
  3619.         {
  3620.  
  3621.         }
  3622.         try
  3623.         {
  3624.             if ( pRecoveryJassNative2 > 0 )
  3625.             {
  3626.                 if ( !IsBadReadPtr( ( void* ) pRecoveryJassNative2, 4 ) )
  3627.                 {
  3628.                     if ( !IsBadWritePtr( ( void* ) pRecoveryJassNative2, 4 ) )
  3629.                     {
  3630.                         *( int* ) pRecoveryJassNative2 = ( int ) GetTriggerEventId_real;
  3631.                     }
  3632.                 }
  3633.             }
  3634.         }
  3635.         catch ( ... )
  3636.         {
  3637.  
  3638.         }
  3639.  
  3640.         try
  3641.         {
  3642.             if ( pRecoveryJassNative3 > 0 )
  3643.             {
  3644.                 if ( !IsBadReadPtr( ( void* ) pRecoveryJassNative3, 4 ) )
  3645.                 {
  3646.                     if ( !IsBadWritePtr( ( void* ) pRecoveryJassNative3, 4 ) )
  3647.                     {
  3648.                         *( int* ) pRecoveryJassNative3 = ( int ) GetIssuedOrderId_real;
  3649.                     }
  3650.                 }
  3651.             }
  3652.         }
  3653.         catch ( ... )
  3654.         {
  3655.  
  3656.         }
  3657.         try
  3658.         {
  3659.             if ( pRecoveryJassNative4 > 0 )
  3660.             {
  3661.                 if ( !IsBadReadPtr( ( void* ) pRecoveryJassNative4, 4 ) )
  3662.                 {
  3663.                     if ( !IsBadWritePtr( ( void* ) pRecoveryJassNative4, 4 ) )
  3664.                     {
  3665.                         *( int* ) pRecoveryJassNative4 = ( int ) GetSpellAbilityUnit_real;
  3666.                     }
  3667.                 }
  3668.             }
  3669.         }
  3670.         catch ( ... )
  3671.         {
  3672.  
  3673.         }
  3674.  
  3675.         try
  3676.         {
  3677.             if ( pRecoveryJassNative5 > 0 )
  3678.             {
  3679.                 if ( !IsBadReadPtr( ( void* ) pRecoveryJassNative5, 4 ) )
  3680.                 {
  3681.                     if ( !IsBadWritePtr( ( void* ) pRecoveryJassNative5, 4 ) )
  3682.                     {
  3683.                         *( int* ) pRecoveryJassNative5 = ( int ) GetAttacker_real;
  3684.                     }
  3685.                 }
  3686.             }
  3687.         }
  3688.         catch ( ... )
  3689.         {
  3690.  
  3691.         }
  3692.  
  3693.         NeedExit = FALSE;
  3694.  
  3695.  
  3696.  
  3697.     }
  3698.  
  3699.     return TRUE;
  3700. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement