[Z] 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 "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 = @ "<span id = iron_now> ";
Public const string ironincreasepat = @ "id = iron_increase> \ D * </span> ";
Public const string ironincreaseheader = @ "id = iron_increase> ";

 

The account I tested has an escrow account.
The result of running the program is to click "button1" and then immediately execute "submitter". After your account is completed, it is automatically transferred to the managed account as the "submitter" of the managed account ". Two accounts used for my test, one of which is the managed account. So the current program can only support

With one managed account, you can change it to the same principle. Click "button2". When the computer time is 10 seconds, execute "submitter" (timed unlimited ).

When you go to the managed account, a dialog box containing "OK" is displayed. You must click "OK" to go to the managed account page. The "OK" button is an HTML element containing the "input" tag, which is similar to the "game guide" that contains ""

The HTML element of a tag is the same.

The key points mentioned above seem to be able to complete most of the functions in the Three Kingdoms game, as long as you can think of anything. Compared with group packages, it is much easier to send packets, but the efficiency is much lower.
If anyone is interested in continuing to improve this program, you are welcome to discuss it. I am not interested in this game anymore -_-!

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.