Janilabo

Janilabo | Shadow Worlds Map.scar

Aug 5th, 2012
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 4.75 KB | None | 0 0
  1. procedure MapSetup;
  2. var
  3.   TSA: TStrArray;
  4.   h, i, id: Integer;
  5.   str: string;
  6. begin
  7.   SetLength(SW.map.info, MAPS_COUNT);
  8.   if not FileExists(IncludesPath + 'MSSL\[' + MSSL_ShortBuiltString + ']\Library\Games\Shadow_Worlds\Configuration\maps\map_info.cfg') then
  9.     Exit;                            
  10.   str := GrabFileData(IncludesPath + 'MSSL\[' + MSSL_ShortBuiltString + ']\Library\Games\Shadow_Worlds\Configuration\maps\map_info.cfg');
  11.   if str <> '' then
  12.   begin                          
  13.     TSA := Explode(#13#10, str);
  14.     h := High(TSA);
  15.     str := '';
  16.     for i := 0 to h do
  17.     begin  
  18.       id := StrToIntDef(Between('ID="', '", ', TSA[i]), -1);
  19.       if InRange(id, 0, (MAPS_COUNT - 1)) then
  20.       begin
  21.         SW.map.info[id].name := Between('Name="', '", ', TSA[i]);
  22.         SW.map.info[id].width := StrToIntDef(Between('Width="', '", ', TSA[i]), -1);
  23.         SW.map.info[id].height := StrToIntDef(Between('Height="', '", ', TSA[i]), -1);
  24.         SW.map.info[id].pvp := StrToBoolDef(Between('PVP="', '";', TSA[i]), True);
  25.       end;
  26.     end;
  27.     SetLength(TSA, 0);  
  28.   end;
  29. end;
  30.  
  31. procedure MapUnsetup;
  32. begin
  33.   SetLength(SW.map.info, 0);
  34. end;
  35.  
  36. function GetPlayerPositionInMap(mapID: Integer; var playerPos: TPoint): Boolean;
  37. var
  38.   minimap, map: TSCARBitmap;
  39.   client: TSCARClient;
  40.   pX, pY, x, y: Integer;
  41.   cPt: TPoint;
  42. begin
  43.   if (not InRange(mapID, 0, (MAPS_COUNT - 1)) or not FileExists(IncludesPath + 'MSSL\[' + MSSL_ShortBuiltString + ']\Library\Games\Shadow_Worlds\Configuration\maps\' + IntToStr(mapID) + '.bmp')) then
  44.     Exit;
  45.   try
  46.     minimap := GetClient.CaptureEx(490, 112, 569, 191);
  47.     ReplaceColorMulti(minimap, [16777215, 3289855, 10198015], 0);
  48.     minimap.TranspColor := 0;
  49.     cPt := AreaCenter(490, 112, 569, 191);
  50.     if FindColorSpiral(cPt.X, cPt.Y, pX, pY, 16777215, 490, 112, 569, 191) then                                              
  51.     try                                              
  52.       map.LoadFromBMP(IncludesPath + 'MSSL\[' + MSSL_ShortBuiltString + ']\Library\Games\Shadow_Worlds\Configuration\maps\' + IntToStr(mapID) + '.bmp');  
  53.       try
  54.         client := SetClient(TSCARBitmapClient.Create(map));        
  55.         Result := FindBitmap(x, y, minimap, 0, 0, (map.Width - 1), (map.Height - 1));
  56.         if Result then
  57.           playerPos := Point(((pX - 490) + x), ((pY - 112) + y));
  58.       finally
  59.         SetClient(client).Free;
  60.       end;  
  61.     finally
  62.       map.Free;
  63.     end;
  64.   finally              
  65.     minimap.Free;
  66.   end;
  67. end;
  68.  
  69. function GetMap: Integer;
  70. var
  71.   minimap, map: TSCARBitmap;
  72.   client: TSCARClient;
  73.   x, y, i: Integer;
  74. begin
  75.   Result := -1;
  76.   try        
  77.     minimap := GetClient.CaptureEx(490, 112, 569, 191);
  78.     minimap.TranspColor := 0;
  79.     ReplaceColorMulti(minimap, [16777215, 3289855, 10198015], 0);
  80.     for i := 0 to (MAPS_COUNT - 1) do
  81.       if FileExists(IncludesPath + 'MSSL\[' + MSSL_ShortBuiltString + ']\Library\Games\Shadow_Worlds\Configuration\maps\' + IntToStr(i) + '.bmp') then
  82.       try
  83.         map.LoadFromBMP(IncludesPath + 'MSSL\[' + MSSL_ShortBuiltString + ']\Library\Games\Shadow_Worlds\Configuration\maps\' + IntToStr(i) + '.bmp');
  84.         try  
  85.           client := SetClient(TSCARBitmapClient.Create(map));
  86.           if FindBitmap(x, y, minimap, 0, 0, (map.Width - 1), (map.Height - 1)) then
  87.           begin
  88.             Result := i;
  89.             Break;
  90.           end;
  91.         finally      
  92.           SetClient(client).Free;  
  93.         end;
  94.       finally
  95.         map.Free;    
  96.       end;          
  97.     FreeBitmap(minimap);
  98.     SetClientWindowHandle(SW_Client.wHandle);
  99.   finally
  100.     minimap.Free;        
  101.   end;
  102. end;
  103.  
  104. function GetMatchedMaps: TIntArray;
  105. var
  106.   minimap, map: TSCARBitmap;
  107.   client: TSCARClient;
  108.   x, y, i, r: Integer;
  109. begin
  110.   try
  111.     minimap := GetClient.CaptureEx(490, 112, 569, 191);
  112.     minimap.TranspColor := 0;
  113.     ReplaceColorMulti(minimap, [16777215, 3289855, 10198015], 0);
  114.     SetLength(Result, MAPS_COUNT);
  115.     for i := 0 to (MAPS_COUNT - 1) do
  116.       if FileExists(IncludesPath + 'MSSL\[' + MSSL_ShortBuiltString + ']\Library\Games\Shadow_Worlds\Configuration\maps\' + IntToStr(i) + '.bmp') then
  117.       try
  118.         map.LoadFromBMP(IncludesPath + 'MSSL\[' + MSSL_ShortBuiltString + ']\Library\Games\Shadow_Worlds\Configuration\maps\' + IntToStr(i) + '.bmp');
  119.         try
  120.           client := SetClient(TSCARBitmapClient.Create(map));
  121.           if FindBitmap(minimap, x, y, 0, 0, (map.Width - 1), (map.Height - 1)) then
  122.           begin
  123.             Result[r] := i;
  124.             Inc(r);
  125.           end;
  126.         finally
  127.           SetClient(client).Free;    
  128.         end;
  129.       finally
  130.         map.Free;    
  131.       end;        
  132.     SetLength(Result, r);  
  133.   finally
  134.     minimap.Free;  
  135.   end;
  136. end;
Advertisement
Add Comment
Please, Sign In to add comment