Thread Tools Display Modes
06-03-14, 01:46 PM   #1
Digital_Utopia
A Flamescale Wyrmkin
 
Digital_Utopia's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2012
Posts: 110
Making PHP (and gd) do tricks

Because converting just takes too much time.

Code:
<?
$fh=imagecreatefromblp("CHARACTER/BloodElf/HAIR00_00.BLP");
imagesavealpha($fh,true);
imagealphablending($fh, 1);
header('Content-Type: image/png');
imagepng($fh);
?>
This is the code for the first successful test of an upcoming PHP extension, that uses the same code used in my other BLP related projects, to convert the format into a gd compatible image resource, allowing you to work with it, and output it to a web-compatible format on the fly.

For instance, let's say that php file is called "BLP.php". With that script, you could essentially do this on a web page:

Code:
<img src="BLP.php"/>
and your image will appear like any other. Or, if you wanted something a little bit more flexible...

Code:
<?
$im=$_GET['f'];
$fh=imagecreatefromblp($im);
imagesavealpha($fh,true);
imagealphablending($fh, 1);
header('Content-Type: image/png');
imagepng($fh);
?>
and then you could do

Code:
<img src="BLP.php?f=CHARACTER/BloodElf/HAIR00_00.BLP"/>
fun stuff, right? So, now you might be asking...

Do you have some kind of weird ADHD, that just makes you jump around random projects?

And the answer is...kinda.

Believe it or not, this is actually related to that model viewer I mentioned below, and if you're prepared for a wall of text, keep on reading.

First and foremost - JavaScript is awesome, and as far as scripting languages go, it's pretty damn fast. Unfortunately, when it comes to parsing file formats, it's far, far too slow. And PHP itself is even worse.

So, I could go ahead and convert the models to the end format, but that means every time there's an update, I have to reconvert the model. And although a project should be maintained, there's a difference between maintenance, and babysitting.

So, then I thought - what's superfast? Compiled code. How to get compiled code running in a web environment, when using PHP? PHP Extensions.

So, cool. I'll make a PHP extension that does the parsing! But that still requires extracting from the game archives, and uploading a metric ton of files. So, not so cool.

But! What if I made an extension that would load up all the MPQ files on init (well, the handles to them - i.e. using StormLib), and any calling script could grab the resource(s) it needs, by simply passing it the requested file path? Now, that would be pretty sexy. But where to start? I've never written an extension before - and have no idea if it's even possible to pass resources between extensions!

But...gd uses a resource, and I have a BLP library... So why not see if I can't make a BLP extension that provides an image resource, that gd will accept? If I can pull that off, everything else is just applying the same methods.

And that, above - is step 1.
__________________

Last edited by Digital_Utopia : 06-03-14 at 01:48 PM.
  Reply With Quote
06-03-14, 01:52 PM   #2
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,877
"But! What if I made an extension that would load up all the MPQ files on init..."

I'm not sure if you've heard but with WoD Blizzard will be moving to a new, propriatory I think, file format and will be converting the mpq files to it.

Other than that , it looks cool.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote
06-03-14, 05:02 PM   #3
Digital_Utopia
A Flamescale Wyrmkin
 
Digital_Utopia's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2012
Posts: 110
Originally Posted by Fizzlemizz View Post
"But! What if I made an extension that would load up all the MPQ files on init..."

I'm not sure if you've heard but with WoD Blizzard will be moving to a new, propriatory I think, file format and will be converting the mpq files to it.

Other than that , it looks cool.
Yup, I've been keeping my eyes on it - and it looks like the brilliant folks over at ownedcore have pretty much got it down. Until/unless Blizzard adds a listfile, an explorer type UI will require a community generated/updated one - but getting files by path/name apparently works.

I haven't had much time to actually test things out with the sample code they've put up there, but currently the test code for the MPQ part, acts as sort of a wrapper for StormLib - meaning neither what goes in, or what goes out, is dependent on the format itself. So whether it be a library, or just some code - all that needs to change is the interaction between the wrapper and what accesses the format, letting the other extensions work regardless.

So now the real fun begins
__________________
  Reply With Quote
06-03-14, 06:43 PM   #4
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,877
Sounds interesting, do you have a location for any discussions or the test code?
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote
06-04-14, 11:15 AM   #5
Digital_Utopia
A Flamescale Wyrmkin
 
Digital_Utopia's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2012
Posts: 110
Originally Posted by Fizzlemizz View Post
Sounds interesting, do you have a location for any discussions or the test code?
here's the github for the CASC explorer

https://github.com/tomrus88/CASCExplorer

Currently it's written to require a listfile, as it attempts to be an "Explorer" - but I imagine if I spent some time playing with it, I could get it to just use it to get a file by name. It's written in c#, and if you fix what appears to be a typo, it will compile and run. But with no listfile, it will basically crash on attempting to load (unhandled IO error).

Someone in the Model Editing forum on ownedcore seems to have created some kind of monitor to get file names as they're loaded by the client, to generate listfiles, but since I don't have access to the alpha of WoD, it doesn't help much. Maybe someone in that thread has shared one, or maybe it will work with MPQ listfiles - haven't really had a chance to check.

There's also a thread in that same forum with attachments, complete with some sample code, that describes what's been discovered about the format so far.

I would link, but I'm not sure about WOWI's policy with linking to that site - as it pretty much covers all kinds of WoW editing - TOS approved, or not. But simply Googling for ownecore CASC should give you the result you want.
__________________
  Reply With Quote
06-04-14, 11:39 AM   #6
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,877
Thank you for the information.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.
  Reply With Quote

WoWInterface » General Discussion » General WoW Chat » Making PHP (and gd) do tricks


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off