TM Racing Analyzer in VB.Net [Still in Progress]

This is the place where you can find everything related to the dedicated server, control scripts and community tools.

Moderators: Pit Crew, TM-Patrol

Post Reply
TPK
highway camper
highway camper
Posts: 3
Joined: 10 Oct 2010 06:35
Owned TM-games: TMNF

TM Racing Analyzer in VB.Net [Still in Progress]

Post by TPK » 10 Oct 2010 08:10

Hello guys,

I might be relatively new in TMForum, but I have been playing TMNF for more than a year.

I just need some assistance in developing TM Racing Analyzer, using VB.Net 2008. Unfortunately, I'm currently stuck into converting the ReplayParser that exist in GBXDataFetcher in PHP to VB.Net language.

Here are some screenshot of the software
ImageImage

And these are the codes that I wanted to translate into VB.Net

Code: Select all

	public function GBXReplayFetcher($filename, $parsexml) {

		$this->filename = $filename;
		$this->parsexml = $parsexml;
		$this->getData();
	}  // GBXReplayFetcher

	// string read function
	private function ReadGBXString($handle) {

		$data = fread($handle, 4);
		$result = unpack('Vlen', $data);
		$len = $result['len'];
		if ($len <= 0 || $len >= 0x10000) {  // for large XML blocks
			return 'read error';
		}
		$data = fread($handle, $len);
		return $data;
	}  // ReadGBXString

	// parser functions
	private function startTag($parser, $name, $attribs) {
		// echo 'startTag: ' . $name . "\n"; print_r($attribs);
		if ($name == 'DEPS') {
			$this->parsedxml['DEPS'] = array();
		} elseif ($name == 'DEP') {
			$this->parsedxml['DEPS'][] = $attribs;
		} else {  // HEADER, IDENT, DESC, TIMES
			$this->parsedxml[$name] = $attribs;
		}
	}  // startTag

	private function charData($parser, $data) {
		// nothing to do here
		// echo 'charData: ' . $data . "\n";
	}  // charData

	private function endTag($parser, $name) {
		// nothing to do here
		// echo 'endTag: ' . $name . "\n";
	}  // endTag

	private function getData() {

		if (!$handle = @fopen($this->filename, 'rb')) {
			return false;
		}

		// check for magic GBX header
		fseek($handle, 0x00, SEEK_SET);
		$data = fread($handle, 5);
		if ($data != 'GBX' . chr(6) . chr(0)) {
			fclose($handle);
			return false;
		}

		fseek($handle, 0x04, SEEK_CUR);  // "BUCR" | "BUCE"
		// get GBX type & check for Replay
		$data = fread($handle, 4);
		$r = unpack('Ngbxtype', $data);
		$t = sprintf('%08X', $r['gbxtype']);
		if ($t != '00E00724' && $t != '00F00324' && $t != '00300903') {
			fclose($handle);
			return false;
		}

		// get GBX version: 1 = TM, 2 = TMPU/TMO/TMS/TMN/TMU/TMF
		fseek($handle, 0x04, SEEK_CUR);  // data block offset
		$data = fread($handle, 4);
		$r = unpack('Vversion', $data);
		$this->version = $r['version'];
		// check for unsupported versions
		if ($this->version < 1 || $this->version > 2) {
			fclose($handle);
			return false;
		}

		// get Index (marker/lengths) table
		for ($i = 1; $i <= $this->version; $i++) {
			$data = fread($handle, 8);
			$r = unpack('Nmark'.$i . '/Vlen'.$i, $data);
			$len[$i] = $r['len'.$i];
		}
		if ($this->version == 2) {  // clear high-bit
			$len[2] &= 0x7FFFFFFF;
		}

		// start of Strings block:
		// 0x1D (TM v1), 0x25 (all v2)
		// check type of Strings block
		$data = fread($handle, 4);
		$r = unpack('Vstrtype', $data);
		$this->strtype = $r['strtype'];

		if ($this->strtype >= 3) {
			fseek($handle, 0x08, SEEK_CUR);  // 03 00 00 00 and 00 00 00 80
			$this->uid = $this->ReadGBXString($handle);
			fseek($handle, 0x04, SEEK_CUR);  // 00 00 00 40
			$this->envir = $this->ReadGBXString($handle);
			fseek($handle, 0x04, SEEK_CUR);  // 00 00 00 [40|80]
			$this->author = $this->ReadGBXString($handle);
			$data = fread($handle, 4);
			$r = unpack('Vreplay', $data);
			$this->replay = $r['replay'];
			$this->nickname = $this->ReadGBXString($handle);

			// check whether to get login (TMU/TMF, exever>="0.1.9.0")
			if ($this->strtype >= 6) {
				$this->login = $this->ReadGBXString($handle);
			}
		}

		// get optional XML block & wrap lines for readability
		if ($this->version >= 2) {
			$this->xml = $this->ReadGBXString($handle);
			$this->xml = str_replace("><", ">\n<", $this->xml);
		}

		fclose($handle);

		// parse XML block too?
		$this->parsedxml = array();
		if ($this->parsexml && $this->xml) {
			// define a dedicated parser to handle the attributes
			$xml_parser = xml_parser_create();
			xml_set_object($xml_parser, $this);
			xml_set_element_handler($xml_parser, 'startTag', 'endTag');
			xml_set_character_data_handler($xml_parser, 'charData');

			if (!xml_parse($xml_parser, utf8_encode($this->xml), true)) {
				$this->parsedxml = sprintf("GBXReplayFetcher XML error in %s: %s at line %d", $this->uid,
				                           xml_error_string(xml_get_error_code($xml_parser)),
				                           xml_get_current_line_number($xml_parser));
				xml_parser_free($xml_parser);
				return false;
			}
			xml_parser_free($xml_parser);

			// extract some specific attributes that aren't in the Header block
			$this->xmlver = $this->parsedxml['HEADER']['VERSION'];
			$this->exever = $this->parsedxml['HEADER']['EXEVER'];
			$this->respawns = $this->parsedxml['TIMES']['RESPAWNS'];
			$this->stuntscore = $this->parsedxml['TIMES']['STUNTSCORE'];
			$this->validable = $this->parsedxml['TIMES']['VALIDABLE'];
			if (isset($this->parsedxml['CHECKPOINTS'])) {
				$this->cpscur = $this->parsedxml['CHECKPOINTS']['CUR'];
				$this->cpslap = $this->parsedxml['CHECKPOINTS']['ONELAP'];
			}
		}
	}  // getData
}  // class GBXReplayFetcher
And this is for my Final Year Project and the purpose of this software is suggest improvement for the racer to improve the lap timing of the racer

I hope for any assistance here. Thanks :)

User avatar
svens
speedy pilot
speedy pilot
Posts: 304
Joined: 05 Dec 2009 23:30
Owned TM-games: TMUF, TMS, TMO
Location: Bern, CH
Contact:

Re: TM Racing Analyzer in VB.Net [Still in Progress]

Post by svens » 11 Oct 2010 13:44

FYI, there's no Trackmania specific code in the piece you posted, you could also ask for help in pure PHP/VB.Net forums.

Unfortunately you didn't tell us exactly what you don't understand. I'm sure somebody can and is willing to help, but don't expect anyone to just do all the "translating" work for you.

Btw. wish good luck with your project. Sounds interesting, but certainly won't be easy :).

User avatar
w1lla
TM-Patrol
TM-Patrol
Posts: 1466
Joined: 23 May 2007 07:20
Owned TM-games: TMU, TMN, TMF
Manialink(s): intr
Location: Venray

Re: TM Racing Analyzer in VB.Net [Still in Progress]

Post by w1lla » 12 Oct 2010 14:17

http://www.jcxsoftware.com/vs.php
VS.Php is a PHP IDE (integrated development environment) based on Visual Studio IDE. With VS.Php you can design, develop, debug and deploy PHP applications within the Visual Studio IDE. VS.Php key features are around providing rich PHP editor as well as Smarty editing capabilities. Also is the ability to debug PHP scripts locally as well as remotely.

Code: Select all

tmnforever is nations and united makes it special. tmnforever has united. I need united!

nocturne
solid chaser
solid chaser
Posts: 1390
Joined: 08 Jun 2007 18:48
Owned TM-games: all
Contact:

Re: TM Racing Analyzer in VB.Net [Still in Progress]

Post by nocturne » 12 Oct 2010 18:11

I can't exactly help a whole lot, but there has been plenty of discussion already regarding the parsing of replays...

More than anything, the GBX wiki... http://en.tm-wiki.org/wiki/GBX

That has just about all the info that's known about the GBX format. There's also several people who've also treaded down the same path as you, most notably...

Nazgul, author of EasyTM: http://easytmf.nazgulworld.com/

Electron, author of a recently posted Replay->Challenge tool: viewtopic.php?f=28&t=21420
Chief Janitorial Supervisor of the Let'sRock! TM community : www.LetsRock-TM.com

TPK
highway camper
highway camper
Posts: 3
Joined: 10 Oct 2010 06:35
Owned TM-games: TMNF

Re: TM Racing Analyzer in VB.Net [Still in Progress]

Post by TPK » 12 Oct 2010 18:15

Hi guys,

Thanks for the feedbacks. I already explored the wiki and also taking a look on what Nazgul and Electron have done. For Nazgul's part, from my understanding, he's doing it for online server if not mistaken.

As for Electron, I might going to the similar path with him since his tool is offline-based and we might share some similarities. I have already e-mailed him on Sunday and yet to receive the reply.

No worries, I try my best to complete the prototype before expanding it more further.

Cheers for the feedbacks. Really appreciate it :)

RobJ
wheelbarrow operator
wheelbarrow operator
Posts: 21
Joined: 09 Jun 2010 08:36
Owned TM-games: TMNF

Re: TM Racing Analyzer in VB.Net [Still in Progress]

Post by RobJ » 31 Oct 2010 15:38

very interresting project tbh!
Can I beta test?

User avatar
xai
happy cruiser
happy cruiser
Posts: 162
Joined: 13 Nov 2008 15:46
Owned TM-games: TMU(F),TMN(F)
Manialink(s): xai

Re: TM Racing Analyzer in VB.Net [Still in Progress]

Post by xai » 06 Nov 2010 22:51

Nice idea, do you have problems with it if I take your idea and try to develop it in Java? :P
Weeeeeeeeeeee

TPK
highway camper
highway camper
Posts: 3
Joined: 10 Oct 2010 06:35
Owned TM-games: TMNF

Re: TM Racing Analyzer in VB.Net [Still in Progress]

Post by TPK » 07 Nov 2010 01:50

Hey guys, sorry for the late reply, still busy developing stuffs

RobJ: Once I complete the software, I'll upload the software for you guys to beta test, not hopefully I don't take much time to complete it

xai: Yes, you are more than welcome to develop it in Java, but I would advise you to be quick as I might afraid my university would patent my project. Hopefully it would be an Open Source initiative so that everyone can share the ideas!

sadilza
highway camper
highway camper
Posts: 1
Joined: 29 Jan 2013 11:33
Owned TM-games: TMU

Re: TM Racing Analyzer in VB.Net [Still in Progress]

Post by sadilza » 29 Jan 2013 11:38

Still in process?? :ftw:

Post Reply