C # Use WebBrowser to create key technical analysis of web game Auxiliary Tools

Source: Internet
Author: User

Using the WebBrowser control is really convenient to implement, but it is less flexible than sending packets in a direct group. For the Three Kingdoms web game, WebBrowser can theoretically implement the desired function if it is used well (I only implement the automatic "referral" on the whole point ",

The principle is the same ).
You can use the packet capture tool to check which packages are available during the game.
Some web games are Flash interfaces, such as happy farm in the school. WebBrowser is not suitable for auxiliary tools for this game .. NET also has the Flash control, but this control function is very weak, a lot of Flash is not available. The only method that comes up with is

There are original group packages.

WebBrowser has a disadvantage that it can only exist in the main thread. When the webBrowser processes data, the entire program is busy. clicking the program does not respond (not responding ). When the program is running, reduce the time required to process data in webBrowser as much as possible,

WebBrowser updates data. Others are implemented in other threads.

WebBrowser. Navigate (strURL );

You can obtain the string content through webBrowser:
WebBrowser. Document. Body. InnerHtml;

The "game guide" is actually a link:
<A class = topbutton-guide title = game guide href = "javascript: MM_iframePost (guide. nation);"> game guide </A>
You only need to execute the "javascript: MM_iframePost (guide. nation);" script in the code, which is equivalent to clicking the "game guide" in the game ".
You can use HtmlElement. InvokeMember to execute the script.

...
HtmlElementCollection aHtml = webBrowser. Document. GetElementsByTagName ("");
DoClick ("game guide ");

Private void DoClick (string name)
{
Foreach (HtmlElement h in aHtml)
{
If (h. InnerText! = Null & h. InnerText. Contains (name ))
{
H. InvokeMember ("click ");
// Wait until the webBrowser refresh is complete
WaitForEventCompleted (1000 );
Break;
}
Else
{
Continue;
}
}
}

Private void WaitForEventCompleted (int time)
{
AutoResetEvent. Reset ();
While (autoResetEvent. WaitOne (time, false) = false)
{
Application. DoEvents ();
}
}

After clicking the corresponding link, the webBrowser must refresh the data accordingly. Therefore, after the operation, you must wait until the webBrowser updates the data. Each time data is updated, the webBrowser_DocumentCompleted event is not executed once,
It seems that it was three times, but I found the cause, and now I forgot it. The code is not stable yet. You can capture the packet to investigate the cause.

Regularly execute the "", and use DoCallback and Invoke between different threads:
Private void TimerDoFamous ()
{
While (true)
{
If (DateTime. Now. Second = 10 & DateTime. Now. Minute = 2)
{
If (webBrowser. InvokeRequired)
{
DoCallback d = new DoCallback (DoFamousGeneral );
This. Invoke (d );
D = new DoCallback (Wait );
This. Invoke (d );
D = new DoCallback (DoAnotherGeneral );
This. Invoke (d );
}
Else
{
DoCallback d = new DoCallback (DoFamousGeneral );
This. Invoke (d );
D = new DoCallback (Wait );
This. Invoke (d );
D = new DoCallback (DoAnotherGeneral );
This. Invoke (d );
}
}
}
}

How to get the desired html element from webBrowser. Document. Body. InnerHtml using a regular expression. The regular expression can also be used to obtain all the data of the current town, such as the number of resources and the building level.
Obtain the regular expression of the number of iron ore:
 

// Iron
Public const string IronNowPat = @ "<SPAN id = iron_now> d * </SPAN> ";
Public const string IronNowHeader
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.