Archive Page 2

29
Apr
09

[Note] Neopets Autobidder Progress

This is the current workup for the neopets auction bot:

Currently, i have all the complex coding done, just have to work out the last few bugs here and there, and then decide how to integrate the bot with an auto stocker (wether to pass the sell price from url to url, until it reaches the stock, or to just query again later on).

Main Auction Page
Create list of items to query
Send request to php
Return list of items maxprice & sell price
Parse list
Loop through each row
Check if item is in list
If it is, check if its a NF only auction
If its not, check to see if maxprice is less than the current price
If it is, check to see if the page is on the ignore list
If it isnt, open the page in a new tab with max price as an url paramater (possibly also sell price?)
Add opened page to ignore list (greasemonkey var?)
Wait between 7 and 15 seconds, refresh page

Bid Page
Parse max price from url
Get username from page
Check to see if the auction is over/invalid/too expensive
If it is, close the page
If it isnt, Check to see if the last bidder was the user
If it is, refresh the page
If it isnt,
modify the form to pass the maxprice in the url when submitted (possibly also sell price)
submit the bid

Bid Submission
Parse max price from url
Check if bid successful (find BID SUCCESSFUL)
If yes,
find link on page (loop through ‘a’ elements)
modify link to pass the maxprice in the url when submitted (possibly also sell price)
If no, check reason
If not enough money, close
If need to wait, history back
If bid twice in a row, back : (Sorry, you are not allowed to bid on an auction two times in a row)

29
Apr
09

[PHP] Hit Counter using MySQL Database

Little script I wrote this morning which uses a database to store number of hits on a page:

<?php
	$dbhost = '1';
	$dbuser = '2';
	$dbpass = '3';
	$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('0');
	$dbname = '4';
	mysql_select_db($dbname);

	$page = $_SERVER['REQUEST_URI'];
	$result = mysql_query("SELECT HIT_COUNT FROM  Hit_Count WHERE Page_Name = '$page'");

	$any = false;
	while($row = mysql_fetch_array($result)) {
		$any = true;
		$counter = mysql_result($result, 0) + 1;
		$sql = "UPDATE Hit_Count SET HIT_COUNT = '$counter' WHERE Page_Name = '$page'";
		mysql_query($sql);
		echo($counter);
	}

	if($any == false) {
		$sql = "INSERT INTO Hit_Count (Page_Name, HIT_COUNT) VALUES ('$page', '1')";
		mysql_query($sql);
		echo("1");
	}

	mysql_close($conn);
?>

The script will output the current hit count, you would use the script like this:

<?php include("location/hitcount.php"); ?>

The tables set up is this:

Page_Name [text]		HIT_COUNT [int(11)]
/files/Image%20Gallery.php 	2
/ 				4
28
Apr
09

[Javascript/Php] Neopets Auction Bot Project (2)

A much faster script than my previous version. Instead of querying each item individually, it loops through the items in the list and uses the queryNeopetItem to send the data to another php page, which pareses the items and returns the prices of each of them. When the data is returned, it is then split and the table is formatted depending on what action should be taken (light green=no data, medium green=more expensive than data, grey = neofriend only, blue = make profit)

Neopets auction highlight


And below is the source for the greasemonkey script:

// ==UserScript==
// @name           AuctionBot test v2
// @namespace      Sim0n NeoPets
// @include        http://www.neopets.com/auctions.phtml
// ==/UserScript==

function getElementsByAttribute(oElm, strTagName, strAttributeName, strAttributeValue){
	var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
	var arrReturnElements = new Array();
	var oAttributeValue = (typeof strAttributeValue != "undefined")? new RegExp("(^|\\s)" + strAttributeValue + "(\\s|$)") : null;
	var oCurrent;
	var oAttribute;
	for(var i=0; i<arrElements.length; i++){
		oCurrent = arrElements[i];
		oAttribute = oCurrent.getAttribute && oCurrent.getAttribute(strAttributeName);
		if(typeof oAttribute == "string" && oAttribute.length > 0){
			if(typeof strAttributeValue == "undefined" || (oAttributeValue && oAttributeValue.test(oAttribute))){
				arrReturnElements.push(oCurrent);
			}
		}
	}
	return arrReturnElements;
}

function queryNeopetItem(item, complete) {
	url = "myphpquery.php?items=" + item;
	GM_xmlhttpRequest({
		method: "POST",
		url: url,
		headers:{'Content-type':'application/x-www-form-urlencoded'},
		data:encodeURI(""),
		onload: function(xhr) { complete(xhr.responseText); }
	});
}
function comp(text) {
	var items = text.split("\n");
	for(var i = 0;i<20;i++) {
		if(items[i] == "") {
			table[0].rows[i+1].setAttribute("bgcolor","#ccffd0");
		} else {
			var item = items[i].split("\t");
			var cur_price = table[0].rows[i+1].cells[6].innerHTML.replace(/<b>(\d*)<\/b> NP/, "$1");
			if(Number(cur_price)<=Number(item[0])) {
				if(table[0].rows[i+1].cells[3].innerHTML.toLowerCase().indexOf("<b>[nf]</b>") != -1) {
					table[0].rows[i+1].setAttribute("bgcolor","#aaafa0");
				} else {
					alert(table[0].rows[i+1].cells[3].innerHTML)
					table[0].rows[i+1].setAttribute("bgcolor","#00ffff");
				}
			} else {
				table[0].rows[i+1].setAttribute("bgcolor","#aaffd0");
			}
		}
	}
}
var table = getElementsByAttribute(document.body, "table", "align", "center");
var queryString = "";
for(var i=1;i<table[0].rows.length - 1;i++) {
	queryString = queryString + table[0].rows[i].cells[2].innerHTML.replace(/<a href=\".*\">(.*)<\/a>/, "$1") + "|";
}
queryString = queryString + table[0].rows[table[0].rows.length-1].cells[2].innerHTML.replace(/<a href=\".*\">(.*)<\/a>/, "$1")
queryNeopetItem(queryString, comp);

And for the php query:

<?php
	$dbhost = 'a';
	$dbuser = 'b';
	$dbpass = 'd';
	$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('0');
	$dbname = 'e';
	mysql_select_db($dbname);

	$items = explode("|", $_GET['items']);
	for($i=0;$i<count($items);$i++) {
		$sqlQuery = "ITEM_NAME = '$items[$i]'";
		$result = mysql_query("SELECT * FROM  Neopets_Items WHERE $sqlQuery");
		$any = false;
		while($row = mysql_fetch_array($result))
  		{
			$any = true;
  			echo $row['MAX_PRICE'] . "\t" . $row['SELL_PRICE'] . "\n";
  		}
		if($any==false) {
			echo "\n";
		}
	}
	mysql_close($conn);
?> 
28
Apr
09

[Javascript/Php] Neopets Auction Bot Project (1)

Ive been asked by somebody to create a bot for the game Neopets that will view the most recent auctions and bid upon items which on which money can be easily made. One of the constraints for this project, was that it must be made using Javascript + Greasemonkey, so no Perl or Python (or whatever it is people use to code bots on the net these days! Like I know -_-).
My initial attempt (below) uses the GM_xmlhttpRequest to query a database of items (that’s another project ^_^ – lots of faces today?), and it works very nicely, except for one small thing. Its ridiculously slow. It query the database for each of the items, and then either marks it with a green colour to indicate that it is loaded, but you will not make money off it, or will highlight the row brown to show that you will make money off the auction.
Remeber, its v. slow!
Still, here is the source code as it is a nice example of a recursive function and sending & retrieving data to other websites using Greasemonkey.

// ==UserScript==
// @name           Auc7i0nb0t t3s7
// @namespace      n30p375
// @include        http://www.neopets.com/auctions.phtml
// ==/UserScript==

//Some function from google - kinda overkill, but meh.
function getElementsByAttribute(oElm, strTagName, strAttributeName, strAttributeValue){
	var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
	var arrReturnElements = new Array();
	var oAttributeValue = (typeof strAttributeValue != "undefined")? new RegExp("(^|\\s)" + strAttributeValue + "(\\s|$)") : null;
	var oCurrent;
	var oAttribute;
	for(var i=0; i<arrElements.length; i++){
		oCurrent = arrElements[i];
		oAttribute = oCurrent.getAttribute && oCurrent.getAttribute(strAttributeName);
		if(typeof oAttribute == "string" && oAttribute.length > 0){
			if(typeof strAttributeValue == "undefined" || (oAttributeValue && oAttributeValue.test(oAttribute))){
				arrReturnElements.push(oCurrent);
			}
		}
	}
	return arrReturnElements;
}

function queryNeopetItem(item, complete) {
	url = "url to my item query page.php?item=" + item;
	GM_xmlhttpRequest({
		method: "POST",
		url: url,
		headers:{'Content-type':'application/x-www-form-urlencoded'},
		data:encodeURI(""),
		onload: function(xhr) { complete(xhr.responseText); }
	});
}
var x = 1;
var table = getElementsByAttribute(document.body, "table", "align", "center");
var item_name = table[0].rows[x].cells[2].innerHTML.replace(/<a href=\".*\">(.*)<\/a>/, "$1");
function comp(text) {
	var ta = text.split("\n");
	max_price = ta[1];
	sell_price = ta[2];
	if(x<table[0].rows.length) {
		item_name = table[0].rows[x].cells[2].innerHTML.replace(/<a href=\".*\">(.*)<\/a>/, "$1");
		queryNeopetItem(item_name, comp)
		table[0].rows[x-1].setAttribute("bgcolor","#ccffd0");
		if(ta[1].indexOf("www.mywebhostsname.com") == -1) {
			var str = table[0].rows[x-1].cells[6].innerHTML.replace(/<b>(\d*)<\/b> NP/, "$1");
			if(Number(str)<=Number(max_price)) {
				table[0].rows[x-1].setAttribute("bgcolor","#dc9423");
			}
		}
		x++;
	} else {
		item_name = table[0].rows[x-1].cells[2].innerHTML.replace(/<a href=\".*\">(.*)<\/a>/, "$1");
		table[0].rows[x-1].setAttribute("bgcolor","#ccffd0");
		if(ta[1].indexOf("www.mywebhostsname.com") == -1) {
			var str = table[0].rows[x-1].cells[6].innerHTML.replace(/<b>(\d*)<\/b> NP/, "$1");
			if(str<=max_price) {
				table[0].rows[x-1].setAttribute("bgcolor","#dc9423");
			}
		}
		table[0].appendChild(document.createTextNode("Complete"));
	}
}
queryNeopetItem(item_name, comp);

url to my item query page.php?item is a page that querys the database and returns the items details (Max Price and Sell Price). The above function is recursive, as queryNeopetItem calls the function comp (which parses the text returned from the httpRequest) which, in turn calls queryNeopetItem again, until all the rows items have been queried.

<php
	$dbhost = 'x';
	$dbuser = 'y';
	$dbpass = 'z';
	$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('0');
	$dbname = 'a';
	mysql_select_db($dbname);

	$item = $_GET['item'];
	$max = $_GET['max'];
	$sell = $_GET['sell']; 

	$sqlQuery = "";

		if($item != "") {
			$sqlQuery = "ITEM_NAME = '$item'";
		}
		if($max != "") {
			if($sqlQuery != "") {
				$sqlQuery = $sqlQuery . " AND MAX_PRICE = '$max'";
			} else {
				$sqlQuery = "MAX_PRICE = '$max'";
		}
		}
		if($sell != "") {
			if($sqlQuery != "") {
				$sqlQuery = $sqlQuery . " AND SELL_PRICE = '$sell'";
			} else {
				$sqlQuery = "SELL_PRICE = '$sell'";
			}
		}

		$result = mysql_query("SELECT * FROM  Neopets_Items WHERE $sqlQuery");

		while($row = mysql_fetch_array($result))
  		{
  			echo $row['ITEM_NAME'] . "\n" . $row['MAX_PRICE'] . "\n" . $row['SELL_PRICE'];
  		}

	mysql_close($conn);
?> 

That code is kind of overkill for the query that the script makes, however it also allows you to query by a combination of the items properties which will be used later on in the project (probably)

28
Apr
09

[Vb.Net] HTML Syntax Highlighter

Based very loosely on the original version I wrote in VBA for use in word.
Instead of looping through “words” this goes through each character and compares it with the colour of the last. Although this method may be slightly slower than splitting the string via spaces, the results are better as strings like Simon(“hithere”) would be incorrectly coloured.

    Private Sub SyntaxBtn_Press(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SyntaxBtn.Click
        CodeBox.SelectionStart = 0
        CodeBox.SelectionLength = 1
        Dim CurColour = CodeBox.SelectionColor
        Dim Output As String = "<div style='border: #660000 5px solid;color:#000000;'><pre style='background-color:#ffffff;padding:3px;line-height:15px;color:#000000;font-family: Courier New !important; font-size: 11px !important'>" & vbNewLine
        Output &= "<span style=""color:rgb(" & CurColour.R & ", " & CurColour.G & ", " & CurColour.B & ");"">"
        Output &= CodeBox.SelectedText
        Dim matches As System.Text.RegularExpressions.MatchCollection = System.Text.RegularExpressions.Regex.Matches(CodeBox.Text, "<")
        Progress.Maximum = CodeBox.TextLength + (matches.Count * 4)
        Progress.Value = 0
        For i As Integer = 1 To (CodeBox.TextLength + (matches.Count * 4))
            Progress.Value += 1
            CodeBox.SelectionStart = i
            CodeBox.SelectionLength = 1
            If CodeBox.SelectedText = "<" Then CodeBox.SelectedText = "\<"
            If CodeBox.SelectionColor <> CurColour Then CurColour = CodeBox.SelectionColor : Output &= "</span><span style=""color:rgb(" & CurColour.R & ", " & CurColour.G & ", " & CurColour.B & ");"">"
            Output &= CodeBox.SelectedText
        Next
        Output &= "</span> " & "</pre></div>"
        My.Computer.Clipboard.SetText(Output)
    End Sub

The example output for this is something like this:


Output &= \</span>\<span style="color:rgb(163, 21, 21);">"<span style=""color:rgb("\</span>\<span style="color:rgb(0, 0, 0);"> & CurColour.R & \</span>\<span style="color:rgb(163, 21, 21);">", "\</span>\<span style="color:rgb(0, 0, 0);"> & CurColour.G & \</span>\<span style="color:rgb(163, 21, 21);">", "\</span>\<span style="color:rgb(0, 0, 0);"> & CurColour.B & \</span>\<span style="color:rgb(163, 21, 21);">");"">"

\</span>\<span style="color:rgb(0, 0, 0);">        Output &= CodeBox.SelectedText

\</span>\<span style="color:rgb(0, 0, 255);">Dim\</span>\<span style="color:rgb(0, 0, 0);"> matches \</span>\<span style="color:rgb(0, 0, 255);">As\</span>\<span style="color:rgb(0, 0, 0);"> System.Text.RegularExpressions.MatchCollection = System.Text.RegularExpressions.Regex.Matches(CodeBox.Text, \</span>\<span style="color:rgb(163, 21, 21);">"<"\</span>\<span style="color:rgb(0, 0, 0);">)

Progress.Maximum = CodeBox.TextLength + (matches.Count * 4)

Progress.Value = 0

\</span>\<span style="color:rgb(0, 0, 255);">For\</span>\<span style="color:rgb(0, 0, 0);"> i \</span>\<span style="color:rgb(0, 0, 255);">As\</span>\<span style="color:rgb(0, 0, 0);"> \</span>\<span style="color:rgb(0, 0, 255);">Integer\</span>\<span style="color:rgb(0, 0, 0);"> = 1 \</span>\<span style="color:rgb(0, 0, 255);">To\</span>\<span style="color:rgb(0, 0, 0);"> (CodeBox.TextLength + (matches.Count * 4))

Progress.Value += 1

CodeBox.SelectionStart = i

CodeBox.SelectionLength = 1

\</span>\<span style="color:rgb(0, 0, 255);">If\</span>\<span style="color:rgb(0, 0, 0);"> CodeBox.SelectedText = \</span>\<span style="color:rgb(163, 21, 21);">"<"\</span>\<span style="color:rgb(0, 0, 0);"> \</span>\<span style="color:rgb(0, 0, 255);">Then\</span>\<span style="color:rgb(0, 0, 0);"> CodeBox.SelectedText = \</span>\<span style="color:rgb(163, 21, 21);">"\<"

\</span>\<span style="color:rgb(0, 0, 0);">            \</span>\<span style="color:rgb(0, 0, 255);">If\</span>\<span style="color:rgb(0, 0, 0);"> CodeBox.SelectionColor <> CurColour \</span>\<span style="color:rgb(0, 0, 255);">Then\</span>\<span style="color:rgb(0, 0, 0);"> CurColour = CodeBox.SelectionColor : Output &= \</span>\<span style="color:rgb(163, 21, 21);">"</span><span style=""color:rgb("\</span>\<span style="color:rgb(0, 0, 0);"> & CurColour.R & \</span>\<span style="color:rgb(163, 21, 21);">", "\</span>\<span style="color:rgb(0, 0, 0);"> & CurColour.G & \</span>\<span style="color:rgb(163, 21, 21);">", "\</span>\<span style="color:rgb(0, 0, 0);"> & CurColour.B & \</span>\<span style="color:rgb(163, 21, 21);">");"">"

\</span>\<span style="color:rgb(0, 0, 0);">            Output &= CodeBox.SelectedText

\</span>\<span style="color:rgb(0, 0, 255);">Next

\</span>\<span style="color:rgb(0, 0, 0);">        Output &= \</span>\<span style="color:rgb(163, 21, 21);">"</span> "\</span>\<span style="color:rgb(0, 0, 0);"> & \</span>\<span style="color:rgb(163, 21, 21);">"</pre></div>"

\</span>\<span style="color:rgb(0, 0, 0);">        \</span>\<span style="color:rgb(0, 0, 255);">My\</span>\<span style="color:rgb(0, 0, 0);">.Computer.Clipboard.SetText(Output)

\</span>\<span style="color:rgb(0, 0, 255);">End\</span>\<span style="color:rgb(0, 0, 0);"> \</span>\<span style="color:rgb(0, 0, 255);">Sub\</span> \</pre>\</div>
26
Apr
09

[C++] :Minesweeper: In-game Toggle Mine Visibility 2

A much cleaner solution than what I made here: /c-minesweeper-in-game-toggle-mine-visibility/
It just uses the in game “ShowMines” function rather than having to write your own.

void __stdcall ShowMines(void)
{
	typedef void (__stdcall *ptrFn)(DWORD);
	ptrFn ptrShowMinesFn = (ptrFn)(0x01002F80);
	ptrShowMinesFn(0xE);
}

You call the function ptrShowMinesFn with one of the possible values for mines, the list can be found here:
/c-minesweeper-toggle-mine-visibility/
So, for example 0xE would display flags.

25
Apr
09

[ASM] Minesweeper God Mode Testing III

Fixed the timer now so that it only stops working if you have won the game.
Original
#########################

0100347C w>    8325 64510001 00                AND DWORD PTR DS:[fTimer],0
01003483   |.  56                              PUSH ESI
01003484       8B7424 08                       MOV ESI,DWORD PTR SS:[ESP+8]

#########################
With Jump
#########################

0100347C w>   /E9 0E160000                     JMP winmine.01004A8F
01003481      |90                              NOP
01003482      |90                              NOP
01003483   |. |56                              PUSH ESI
01003484      |8B7424 08                       MOV ESI,DWORD PTR SS:[ESP+8]

#########################
Code Cave
#########################

01004A8F    > \83F8 01                         CMP EAX,1
01004A92    .^ 0F84 EBE9FFFF                   JE winmine.01003483
01004A98    .  8325 64510001 00                AND DWORD PTR DS:[fTimer],0
01004A9F    .^ E9 DFE9FFFF                     JMP winmine.01003483