Jump to content
Eternal Lands Official Forums
Entropy

Script needed to change all the maps.

Recommended Posts

Sorry for the delay, I've been sans internet in a god forsaken hole called Newcastle* for a week.

 

I will get myself switched on and mod the code so it does as you request.

 

*well actually I was in a place called Blackhall Rocks in Durham but it's still too close to the in-laws for my liking.

 

It was fun to be there when the local football teams got thrashed however.

Share this post


Link to post
Share on other sites

Oh no problem, i'm just happy you can do it at all! Sucks being without internet...although sometimes it is nice to have a break :happy:

Share this post


Link to post
Share on other sites
Sorry for the delay, I've been sans internet in a god forsaken hole called Newcastle* for a week.

I resent this statement :D

Share this post


Link to post
Share on other sites

Help! There's a really Really REALLY HUGE bug in, at least one of, these scripts. It's changing the map object ID#'s :) That means that objects such as doors no longer match up with the files on the server so you can't enter houses. It hasn't happened for ALL objects. What I think this script is doing is recounting/renumbering all the 3d objects, or some of them.

 

Can someone please fix this?

 

3d object paths converter:

<?php

ini_set('memory_limit', '64M');
$inpath = "C:/maps_original";
$outpath = "C:/maps_filepathsconverted";
$infile = "*.elm";
$common = "/3dobjects";
$match = array("$common/ground_objs/","$common/interiors/","$common/misc_objects/","$common/rocks/","$common/ruins/","$common/structures/","$common/trees/","$common/weapons/");


chdir($inpath);
mkdir($outpath); // just in case, may cause a warning
foreach(glob($infile) as $filename)
{
	$fin = fopen("$filename","rb");
	if($fin)
	{
		$fout = fopen("$outpath/$filename","wb");
		if($fout)
		{
			$data = fread($fin,$s = filesize("$filename"));
			echo "***** $filename is $s bytes long\n";
			foreach($match as $look)
			{
				$p = 0;
				$count = 0;
				$c = strlen($common) + 1;
				$l = strlen($look) - $c;
				$s = strlen($data);
				echo "\nlooking for $look";
				while($p !== false)
				{
					$q = strpos($data,$look,$p);
					$p = $q;
					if($p!==false)
					{
						echo ".";
						$p += $c;
						$count++;
						$i = 0;
						$q = strpos($data,"\0",$p);
						if($q !== false)
						{
							$t = substr($data,$p+$l,$q-$p);
							$data = substr_replace($data,$t,$p,$q - $p);
						}
					}
				}
				echo " $count replacements";
			}
			fwrite($fout,$data);
			fclose($fout);
			echo "\nnew data is ", strlen($data), " bytes long\n";
		}
		fclose($fin);
	}
}
?>

 

 

 

Tiles path converter

<?php
/************************
remove "/tiles/" and replace with "/3dobjects/"
************************/
ini_set('memory_limit', '64M');
$inpath = "C:/maps_original";
$outpath = "C:/maps_filepathsconverted";
$infile = "*.elm";
$common = "/tiles/";
$t = "/3dobjects/";
$match = array("$common");

chdir($inpath);
mkdir($outpath); // just in case, may cause a warning
foreach(glob($infile) as $filename)
{
	$fin = fopen("$filename","rb");
	if($fin)
	{
		$fout = fopen("$outpath/$filename","wb");
		if($fout)
		{
			$data = fread($fin,$s = filesize("$filename"));
			echo "***** $filename is $s bytes long\n";
			$c = strlen($common) + 1;
			foreach($match as $look)
			{
				$p = 0;
				$count = 0;
				$l = strlen($look) - $c;
				$s = strlen($data);
				echo "\nlooking for $look";
				while($p !== false)
				{
					$q = strpos($data,$look,$p);
					$p = $q;
					if($p!==false)
					{
						echo ".";
						$count++;
						$i = 0;
						$q = strpos($data,"\0",$p);
						if($q !== false)
						{
							$data = substr($data,0,$p) . $t . substr($data,$p + $c -1);
							$u = strpos($data,"\0",$p);
							$data = substr($data,0,$u) . substr($data,$u + strlen($common) - strlen($look) +4);
						}
					}
				}
				echo " $count replacements";
			}
			fwrite($fout,$data);
			fclose($fout);
			echo "\nnew data is ", strlen($data), " bytes long\n";
		}
		fclose($fin);
	}
}
?>

 

 

 

Object name Changer

<?php

ini_set('memory_limit', '64M');
$inpath = "C:/maps_original";
$outpath = "C:/maps_filepathsconverted";
$infile = "*.elm";

//This is a little awkward but will save a lot of work
//$search is the string to find
//$replace is the string to replace
//the % character is a null character to pad the strings so they are the same size in $search and $replace
//
//your example:
//exchange rock4 to tile13, rock5 to tile11, tile1 to tile01, etc.
//$search  = array("rock4.bmp","rock5.bmp","tile1.bmp");
//$replace = array("tile13.dds","tile11.dds","tile01.dds");
//by adding a % at the start and end of the $search and $replace we can match only the desired strings

//multiple simultaneous searches can be used by adding parts to the arrays

//change the below lines to your requirements
$search  = array("tent4.e3d","shrub1.e3d","shrub3.e3d","shrub2.e3d","plant7.e3d","thornbush1.e3d","thornbush2.e3d","tile25.e3d","tile26.e3d");
$replace = array("tent2.e3d","bush9.e3d","bush10.e3d","bush11.e3d","bush12.e3d","bush13.e3d","bush14.e3d","tile_stonewall1.e3d","tile_stonewall5.e3d");
//change the above lines to your requirements

$cs = count($search);
$cr = count($replace);
if($cs != $cr)
{
	die ("\$search and \$replace counts do not match\n");
}
echo "* $cs $cr\n";
for($i = 0;$i<$cs;$i++)
{
	$s = strlen($search[$i]);
	$r = strlen($replace[$i]);
	if($s<$r)
	{
		echo $search[$i]," is shorter than ",$replace[$i],"\n";
		$search[$i] = $search[$i] . str_repeat("%",$r - $s);
	}
	else if($s>$r)
	{
		echo $search[$i]," is longer than ",$replace[$i],"\n";
		$replace[$i] = $replace[$i] . str_repeat("%",$s - $r);
	}
	echo $search[$i],"\n";
	echo $replace[$i],"\n";
}

//do not change the below lines
$search  = str_replace("%","\0",$search);
$replace = str_replace("%","\0",$replace);
//do not change the above lines

chdir($inpath);
mkdir($outpath); // just in case, may cause a warning
$changedfiles = "";
foreach(glob($infile) as $filename)
{
	$fin = fopen("$filename","rb");
	if($fin)
	{
		$data = fread($fin,$s = filesize("$filename"));
		fclose($fin);
		$fout = fopen("$outpath/$filename","wb");
		if($fout)
		{
			$count = 0;
			echo "***** $filename is $s bytes long\n";

			$newdata = str_replace($search,$replace,$data);

			fwrite($fout,$newdata);
			fclose($fout);
			for($i = 0;$i<strlen($data);$i++)
			{
				if($data[$i]!=$newdata[$i])
				{
					$count++;
				}
			}
			if($count>0)
			$changedfiles = "$changedfiles$filename ";
			echo "new data is ", strlen($newdata), " bytes long and has $count bytes changed\n\n";
		}
		else
		{
			echo "File creation error in $outpath/$filename\n";
		}
	}
	else
	{
		echo "File open error in $filename\n";
	}
}
if($changedfiles == "")
	echo "There are no changed files, please check your \$search and \$replace parameters\n";
else
	echo "Changed files: $changedfiles";
?>

Share this post


Link to post
Share on other sites

I think I found the bug:

 

3d_objects.c, line 234:

 

returned_e3d = load_e3d_cache ("./3dobjects/misc_objects/badobject.e3d");

 

it has the wrong path, still the old "misc_objects" so when an object is not found, not even the badobject.e3d can be found, messing up all subsequent IDs.

 

EDIT:

 

Here is a .exe with the above change, pls check if it solves the issue.

Edited by Fedora

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×