
#include "app.h"
#include "XBUtil.h"

#include <string>
#include <vector>
using namespace std;
extern int mpType;
extern int animationFrames;
extern void makeVertexListResizePB();

LPDIRECT3DTEXTURE8 TexMenu;
LPDIRECT3DTEXTURE8 TexJBoxArt;
LPDIRECT3DTEXTURE8 TexStatePreview;
LPDIRECT3DTEXTURE8 TexGUIPreview;
LPDIRECT3DTEXTURE8 TexNoStatePreview;
LPDIRECT3DTEXTURE8 TexNoBox;
LPDIRECT3DTEXTURE8 TexMainMenu;
LPDIRECT3DTEXTURE8 TexPreviewResize;
LPDIRECT3DTEXTURE8 TexImage;
LPDIRECT3DTEXTURE8 TexPreview;
LPDIRECT3DTEXTURE8 TexPreview2;
LPDIRECT3DTEXTURE8 TexPreviewMedia;
IDirect3DTexture8 *TexScreen=NULL;
IDirect3DTexture8 *TexScreenShot=NULL;
IDirect3DTexture8 *TexResize=NULL;
IDirect3DTexture8 *TexController=NULL;
IDirect3DTexture8 *TexHelp=NULL;
IDirect3DTexture8 *TexSplash=NULL;
IDirect3DTexture8 *TexSplashFinal=NULL;
IDirect3DTexture8 *TexPreviewBorder=NULL;
IDirect3DTexture8 *TexLogo=NULL;
IDirect3DTexture8 *TexLogo2=NULL;

IDirect3DTexture8 *TexStationary_0=NULL;
IDirect3DTexture8 *TexStationary_1=NULL;
IDirect3DTexture8 *TexStationary_2=NULL;
IDirect3DTexture8 *TexStationary_3=NULL;
IDirect3DTexture8 *TexStationary_4=NULL;
IDirect3DTexture8 *TexStationary_5=NULL;
IDirect3DTexture8 *TexStationary_6=NULL;
IDirect3DTexture8 *TexStationary_7=NULL;
IDirect3DTexture8 *TexStationary_8=NULL;
IDirect3DTexture8 *TexStationary_9=NULL;
IDirect3DTexture8 *TexStationary_10=NULL;
IDirect3DTexture8 *TexStationary_11=NULL;
IDirect3DTexture8 *TexStationary_12=NULL;
IDirect3DTexture8 *TexStationary_13=NULL;
IDirect3DTexture8 *TexStationary_14=NULL;
IDirect3DTexture8 *TexStationary_15=NULL;
IDirect3DTexture8 *TexStationary_16=NULL;
IDirect3DTexture8 *TexStationary_17=NULL;




extern char skinPath[512];
extern void switchMP(int i);
int TexWidth=640,TexHeight=480;

// Blank the texture:
int TexBlank()
{
	D3DLOCKED_RECT lock={0,NULL};
	unsigned char *dest=NULL;
	int y=0,line=0;
	TexScreen->LockRect(0,&lock,NULL,0); if (lock.pBits==NULL) return 1;
	dest=(unsigned char *)lock.pBits;
	for (y=0; y<TexHeight; y++,line+=lock.Pitch)
	{
		memset(dest+line,0,TexWidth<<1);
	}
	TexScreen->UnlockRect(0);
	return 0;
}

int TexBlankScreenshot()
{
	D3DLOCKED_RECT lock={0,NULL};
	unsigned char *dest=NULL;
	int y=0,line=0;

	TexScreenShot->LockRect(0,&lock,NULL,0); if (lock.pBits==NULL) return 1;

	dest=(unsigned char *)lock.pBits;
	for (y=0; y<TexHeight; y++,line+=lock.Pitch)
	{
		memset(dest+line,0,TexWidth<<1);
	}

	TexScreenShot->UnlockRect(0);
	return 0;
}
extern void makeVertexListResizeB();


void blankTexScreenShot() {
	D3DSURFACE_DESC desc;
	TexScreenShot->GetLevelDesc( 0, &desc );
	DWORD dwTexWidth  = desc.Width;
	DWORD dwTexHeight = desc.Height;
//	DWORD dwTexDepth  = 0;
	D3DLOCKED_RECT lock;
	TexScreenShot->LockRect( 0, &lock, 0, 0L );
	VOID* pBits = lock.pBits;


	//////dprintf("TexWidth: %d, TexHeight: %d, pitch: %d\n", dwTexWidth, dwTexHeight, lock.Pitch);
	// Loop through and touch the texels.
	for( DWORD y = 0; y < dwTexHeight; y++ )
	{
		for( DWORD x = 0; x < dwTexWidth; x++ )
		{
			//((WORD*)pBits)[y*dwTexWidth+x] = (WORD)(((x>>3)<<11) | ((y>>3)<<0));
			((unsigned short*)pBits)[y*dwTexWidth+x] = 0;//0x00FF;
		}
	}
	TexScreenShot->UnlockRect( 0 );
}



void clearAnimation() {
	if(TexStationary_0) { TexStationary_0->Release(); TexStationary_0 = NULL; }
	if(TexStationary_1) { TexStationary_1->Release(); TexStationary_1 = NULL; }
	if(TexStationary_2) { TexStationary_2->Release(); TexStationary_2 = NULL; }
	if(TexStationary_3) { TexStationary_3->Release(); TexStationary_3 = NULL; }
	if(TexStationary_4) { TexStationary_4->Release(); TexStationary_4 = NULL; }
	if(TexStationary_5) { TexStationary_5->Release(); TexStationary_5 = NULL; }
	if(TexStationary_6) { TexStationary_6->Release(); TexStationary_6 = NULL; }
	if(TexStationary_7) { TexStationary_7->Release(); TexStationary_7 = NULL; }
	if(TexStationary_8) { TexStationary_8->Release(); TexStationary_8 = NULL; }
	if(TexStationary_9) { TexStationary_9->Release(); TexStationary_9 = NULL; }
	if(TexStationary_10) { TexStationary_10->Release(); TexStationary_10 = NULL; }
	if(TexStationary_11) { TexStationary_11->Release(); TexStationary_11 = NULL; }
	if(TexStationary_12) { TexStationary_12->Release(); TexStationary_12 = NULL; }
	if(TexStationary_13) { TexStationary_13->Release(); TexStationary_13 = NULL; }
	if(TexStationary_14) { TexStationary_14->Release(); TexStationary_14 = NULL; }
	if(TexStationary_15) { TexStationary_15->Release(); TexStationary_15 = NULL; }
	if(TexStationary_16) { TexStationary_16->Release(); TexStationary_16 = NULL; }
	if(TexStationary_17) { TexStationary_17->Release(); TexStationary_17 = NULL; }
	if(TexMainMenu) { TexMainMenu->Release(); TexMainMenu = NULL; }
	if(TexMenu) { TexMenu->Release(); TexMenu = NULL; }
	if(TexHelp) { TexHelp->Release(); TexHelp = NULL; }
	if(TexLogo) { TexLogo->Release(); TexLogo = NULL; }
	if(TexPreviewResize) { TexPreviewResize->Release(); TexPreviewResize = NULL; }
	if(TexJBoxArt) { TexJBoxArt->Release(); TexJBoxArt = NULL; }
	if(TexPreviewBorder) { TexPreviewBorder->Release(); TexPreviewBorder = NULL; }
	if(TexLogo2) { TexLogo2->Release(); TexLogo2 = NULL; }
	if(TexPreviewMedia) { TexPreviewMedia->Release(); TexPreviewMedia = NULL; }
	if(TexGUIPreview) { TexGUIPreview->Release(); TexGUIPreview = NULL; }
	if(TexNoStatePreview) { TexNoStatePreview->Release(); TexNoStatePreview = NULL; }
}

void loadAnimation() {
	clearAnimation();

	


	std::string a14 = "D:\\skins\\";
	a14 += skinPath;
	a14 += "\\";
	a14 += "previewborder.png";
	if( FAILED( D3DXCreateTextureFromFileEx(Device, 
		a14.c_str(), 
		D3DX_DEFAULT, //Width:D3DX_DEFAULT = Take from file 
		D3DX_DEFAULT, //Height:D3DX_DEFAULT = Take from file
		1,            //MipLevels
		0,            //Usage, Is this to be used as a Render Target? 0 == No
		D3DFMT_A8R8G8B8, //32-bit with Alpha, everything should support this
		D3DPOOL_MANAGED,//Pool, let D3D Manage our memory
		D3DX_DEFAULT, D3DX_DEFAULT,
		0,            //Disable ColourKey
		NULL,         //SourceInfo, returns extra info if we want it (we don't)
		NULL,         //Palette:We're not using one
		&TexPreviewBorder ) ) )
	{

	}

	std::string a16 = "D:\\skins\\";
	a16 += skinPath;
	a16 += "\\";
	a16 += "logo2.png";
	if( FAILED( D3DXCreateTextureFromFileEx(Device, 
		a16.c_str(), 
		D3DX_DEFAULT, //Width:D3DX_DEFAULT = Take from file 
		D3DX_DEFAULT, //Height:D3DX_DEFAULT = Take from file
		1,            //MipLevels
		0,            //Usage, Is this to be used as a Render Target? 0 == No
		D3DFMT_A8R8G8B8, //32-bit with Alpha, everything should support this
		D3DPOOL_MANAGED,//Pool, let D3D Manage our memory
		D3DX_DEFAULT, D3DX_DEFAULT,
		0,            //Disable ColourKey
		NULL,         //SourceInfo, returns extra info if we want it (we don't)
		NULL,         //Palette:We're not using one
		&TexLogo2 ) ) )
	{

	}

	std::string a5 = "D:\\skins\\";
	a5 += skinPath;
	a5 += "\\";
	a5 += "previewresize.png";
	D3DXCreateTextureFromFileEx(Device, 
		a5.c_str(), 
		D3DX_DEFAULT, //Width:D3DX_DEFAULT = Take from file 
		D3DX_DEFAULT, //Height:D3DX_DEFAULT = Take from file
		1,            //MipLevels
		0,            //Usage, Is this to be used as a Render Target? 0 == No
		D3DFMT_A8R8G8B8, //32-bit with Alpha, everything should support this
		D3DPOOL_MANAGED,//Pool, let D3D Manage our memory
		D3DX_DEFAULT, D3DX_DEFAULT,
		0,            //Disable ColourKey
		NULL,         //SourceInfo, returns extra info if we want it (we don't)
		NULL,         //Palette:We're not using one
		&TexNoStatePreview );




	std::string a7 = "D:\\skins\\";
	a7 += skinPath;
	a7 += "\\";
	a7 += "mainmenu.png";

	D3DXCreateTextureFromFileEx(Device, 
		a7.c_str(), 
		D3DX_DEFAULT, //Width:D3DX_DEFAULT = Take from file 
		D3DX_DEFAULT, //Height:D3DX_DEFAULT = Take from file
		1,            //MipLevels
		0,            //Usage, Is this to be used as a Render Target? 0 == No
		D3DFMT_A8R8G8B8, //32-bit with Alpha, everything should support this
		D3DPOOL_MANAGED,//Pool, let D3D Manage our memory
		D3DX_DEFAULT, D3DX_DEFAULT,
		0,            //Disable ColourKey
		NULL,         //SourceInfo, returns extra info if we want it (we don't)
		NULL,         //Palette:We're not using one
		&TexMainMenu ); 

	std::string a = "D:\\skins\\";
	a += skinPath;
	a += "\\";
	a += "rombrowser.png";
	if( FAILED( D3DXCreateTextureFromFileEx(Device, 
		a.c_str(), 
		D3DX_DEFAULT, //Width:D3DX_DEFAULT = Take from file 
		D3DX_DEFAULT, //Height:D3DX_DEFAULT = Take from file
		1,            //MipLevels
		0,            //Usage, Is this to be used as a Render Target? 0 == No
		D3DFMT_A8R8G8B8, //32-bit with Alpha, everything should support this
		D3DPOOL_MANAGED,//Pool, let D3D Manage our memory
		D3DX_DEFAULT, D3DX_DEFAULT,
		0,            //Disable ColourKey
		NULL,         //SourceInfo, returns extra info if we want it (we don't)
		NULL,         //Palette:We're not using one
		&TexMenu ) ) )
	{
	}



	std::string a15 = "D:\\skins\\";
	a15 += skinPath;
	a15 += "\\";
	a15 += "logo.png";
	if( FAILED( D3DXCreateTextureFromFileEx(Device, 
		a15.c_str(), 
		D3DX_DEFAULT, //Width:D3DX_DEFAULT = Take from file 
		D3DX_DEFAULT, //Height:D3DX_DEFAULT = Take from file
		1,            //MipLevels
		0,            //Usage, Is this to be used as a Render Target? 0 == No
		D3DFMT_A8R8G8B8, //32-bit with Alpha, everything should support this
		D3DPOOL_MANAGED,//Pool, let D3D Manage our memory
		D3DX_DEFAULT, D3DX_DEFAULT,
		0,            //Disable ColourKey
		NULL,         //SourceInfo, returns extra info if we want it (we don't)
		NULL,         //Palette:We're not using one
		&TexLogo ) ) )
	{

	}
	

	std::string a2 = "D:\\skins\\";
	a2 += skinPath;
	a2 += "\\";
	a2 += "previewresize.png";
	D3DXCreateTextureFromFileEx(Device, 
		a2.c_str(), 
		D3DX_DEFAULT, //Width:D3DX_DEFAULT = Take from file 
		D3DX_DEFAULT, //Height:D3DX_DEFAULT = Take from file
		1,            //MipLevels
		0,            //Usage, Is this to be used as a Render Target? 0 == No
		D3DFMT_A8R8G8B8, //32-bit with Alpha, everything should support this
		D3DPOOL_MANAGED,//Pool, let D3D Manage our memory
		D3DX_DEFAULT, D3DX_DEFAULT,
		0,            //Disable ColourKey
		NULL,         //SourceInfo, returns extra info if we want it (we don't)
		NULL,         //Palette:We're not using one

		&TexPreviewResize );


	


	std::string a3 = "D:\\skins\\";
	a3 += skinPath;
	a3 += "\\";
	a3 += "jboxart.png";
	D3DXCreateTextureFromFileEx(Device, 
		a3.c_str(), 
		D3DX_DEFAULT, //Width:D3DX_DEFAULT = Take from file 
		D3DX_DEFAULT, //Height:D3DX_DEFAULT = Take from file
		1,            //MipLevels
		0,            //Usage, Is this to be used as a Render Target? 0 == No
		D3DFMT_A8R8G8B8, //32-bit with Alpha, everything should support this
		D3DPOOL_MANAGED,//Pool, let D3D Manage our memory
		D3DX_DEFAULT, D3DX_DEFAULT,
		0,            //Disable ColourKey
		NULL,         //SourceInfo, returns extra info if we want it (we don't)
		NULL,         //Palette:We're not using one
		&TexJBoxArt );




	std::string a11 = "D:\\skins\\";
	a11 += skinPath;
	a11 += "\\";
	a11 += "help.png";
	D3DXCreateTextureFromFileEx(Device, 
		a11.c_str(), 
		D3DX_DEFAULT, //Width:D3DX_DEFAULT = Take from file 
		D3DX_DEFAULT, //Height:D3DX_DEFAULT = Take from file
		1,            //MipLevels
		0,            //Usage, Is this to be used as a Render Target? 0 == No
		D3DFMT_A8R8G8B8, //32-bit with Alpha, everything should support this
		D3DPOOL_MANAGED,//Pool, let D3D Manage our memory
		D3DX_DEFAULT, D3DX_DEFAULT,
		0,            //Disable ColourKey
		NULL,         //SourceInfo, returns extra info if we want it (we don't)
		NULL,         //Palette:We're not using one
		&TexHelp );

	int q = 0;
	if(animationFrames == 0) return;
	std::string a17 = "D:\\skins\\";
	a17 += skinPath;
	a17 += "\\Animated\\";
	a17 += "0.png";
	D3DXCreateTextureFromFileEx(Device, a17.c_str(), 
		D3DX_DEFAULT, D3DX_DEFAULT, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED,D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL,        
		&TexStationary_0 );


	q++; if(q > (animationFrames-1)) return;
	std::string a18 = "D:\\skins\\";
	a18 += skinPath;
	a18 += "\\Animated\\";
	a18 += "1.png";
	D3DXCreateTextureFromFileEx(Device, a18.c_str(), 
		D3DX_DEFAULT, D3DX_DEFAULT, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED,D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL,        
		&TexStationary_1 );



	q++; if(q > (animationFrames-1)) return;
	std::string a19 = "D:\\skins\\";
	a19 += skinPath;
	a19 += "\\Animated\\";
	a19 += "2.png";
	D3DXCreateTextureFromFileEx(Device, a19.c_str(), 
		D3DX_DEFAULT, D3DX_DEFAULT, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED,D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL,        
		&TexStationary_2 );

	q++; if(q > (animationFrames-1)) return;
	std::string a20 = "D:\\skins\\";
	a20 += skinPath;
	a20 += "\\Animated\\";
	a20 += "3.png";
	D3DXCreateTextureFromFileEx(Device, a20.c_str(), 
		D3DX_DEFAULT, D3DX_DEFAULT, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED,D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL,        
		&TexStationary_3 );

	q++; if(q > (animationFrames-1)) return;
	std::string a21 = "D:\\skins\\";
	a21 += skinPath;
	a21 += "\\Animated\\";
	a21 += "4.png";
	D3DXCreateTextureFromFileEx(Device, a21.c_str(), 
		D3DX_DEFAULT, D3DX_DEFAULT, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED,D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL,        
		&TexStationary_4 );

	q++; if(q > (animationFrames-1)) return;
	std::string a22 = "D:\\skins\\";
	a22 += skinPath;
	a22 += "\\Animated\\";
	a22 += "5.png";
	D3DXCreateTextureFromFileEx(Device, a22.c_str(), 
		D3DX_DEFAULT, D3DX_DEFAULT, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED,D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL,        
		&TexStationary_5 );

	q++; if(q > (animationFrames-1)) return;
	std::string a23 = "D:\\skins\\";
	a23 += skinPath;
	a23 += "\\Animated\\";
	a23 += "6.png";
	D3DXCreateTextureFromFileEx(Device, a23.c_str(), 
		D3DX_DEFAULT, D3DX_DEFAULT, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED,D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL,        
		&TexStationary_6 );

	q++; if(q > (animationFrames-1)) return;
	std::string a24 = "D:\\skins\\";
	a24 += skinPath;
	a24 += "\\Animated\\";
	a24 += "7.png";
	D3DXCreateTextureFromFileEx(Device, a24.c_str(), 
		D3DX_DEFAULT, D3DX_DEFAULT, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED,D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL,        
		&TexStationary_7 );


	q++; if(q > (animationFrames-1)) return;
	std::string a25 = "D:\\skins\\";
	a25 += skinPath;
	a25 += "\\Animated\\";
	a25 += "8.png";
	D3DXCreateTextureFromFileEx(Device, a25.c_str(), 
		D3DX_DEFAULT, D3DX_DEFAULT, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED,D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL,        
		&TexStationary_8 );


	q++; if(q > (animationFrames-1)) return;
	std::string a26 = "D:\\skins\\";
	a26 += skinPath;
	a26 += "\\Animated\\";
	a26 += "9.png";
	D3DXCreateTextureFromFileEx(Device, a26.c_str(), 
		D3DX_DEFAULT, D3DX_DEFAULT, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED,D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL,        
		&TexStationary_9 );


	q++; if(q > (animationFrames-1)) return;
	std::string a27 = "D:\\skins\\";
	a27 += skinPath;
	a27 += "\\Animated\\";
	a27 += "10.png";
	D3DXCreateTextureFromFileEx(Device, a27.c_str(), 
		D3DX_DEFAULT, D3DX_DEFAULT, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED,D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL,        
		&TexStationary_10 );


	q++; if(q > (animationFrames-1)) return;
	std::string a28 = "D:\\skins\\";
	a28 += skinPath;
	a28 += "\\Animated\\";
	a28 += "11.png";
	D3DXCreateTextureFromFileEx(Device, a28.c_str(), 
		D3DX_DEFAULT, D3DX_DEFAULT, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED,D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL,        
		&TexStationary_11 );


	q++; if(q > (animationFrames-1)) return;
	std::string a29 = "D:\\skins\\";
	a29 += skinPath;
	a29 += "\\Animated\\";
	a29 += "12.png";
	D3DXCreateTextureFromFileEx(Device, a29.c_str(), 
		D3DX_DEFAULT, D3DX_DEFAULT, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED,D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL,        
		&TexStationary_12 );


	q++; if(q > (animationFrames-1)) return;
	std::string a30 = "D:\\skins\\";
	a30 += skinPath;
	a30 += "\\Animated\\";
	a30 += "13.png";
	D3DXCreateTextureFromFileEx(Device, a30.c_str(), 
		D3DX_DEFAULT, D3DX_DEFAULT, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED,D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL,        
		&TexStationary_13 );


	q++; if(q > (animationFrames-1)) return;
	std::string a31 = "D:\\skins\\";
	a31 += skinPath;
	a31 += "\\Animated\\";
	a31 += "14.png";
	D3DXCreateTextureFromFileEx(Device, a31.c_str(), 
		D3DX_DEFAULT, D3DX_DEFAULT, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED,D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL,        
		&TexStationary_14 );



	q++; if(q > (animationFrames-1)) return;
	std::string a32 = "D:\\skins\\";
	a32 += skinPath;
	a32 += "\\Animated\\";
	a32 += "15.png";
	D3DXCreateTextureFromFileEx(Device, a32.c_str(), 
		D3DX_DEFAULT, D3DX_DEFAULT, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED,D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL,        
		&TexStationary_15 );


	q++; if(q > (animationFrames-1)) return;
	std::string a33 = "D:\\skins\\";
	a33 += skinPath;
	a33 += "\\Animated\\";
	a33 += "16.png";
	D3DXCreateTextureFromFileEx(Device, a33.c_str(), 
		D3DX_DEFAULT, D3DX_DEFAULT, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED,D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL,        
		&TexStationary_16 );


	q++; if(q > (animationFrames-1)) return;
	std::string a34 = "D:\\skins\\";
	a34 += skinPath;
	a34 += "\\Animated\\";
	a34 += "17.png";
	////dprintf("Loading Animation: %s\n", a34.c_str());
	D3DXCreateTextureFromFileEx(Device, a34.c_str(), 
		D3DX_DEFAULT, D3DX_DEFAULT, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED,D3DX_DEFAULT, D3DX_DEFAULT, 0, NULL, NULL,        
		&TexStationary_17 );

	
}
void loadTextures(char* path, int  i) {
	

	




	std::string a4 = "D:\\skins\\";
	a4 += skinPath;
	a4 += "\\";
	a4 += "previewnotfound.png";
	D3DXCreateTextureFromFileEx(Device, 
		a4.c_str(), 
		D3DX_DEFAULT, //Width:D3DX_DEFAULT = Take from file 
		D3DX_DEFAULT, //Height:D3DX_DEFAULT = Take from file
		1,            //MipLevels
		0,            //Usage, Is this to be used as a Render Target? 0 == No
		D3DFMT_A8R8G8B8, //32-bit with Alpha, everything should support this
		D3DPOOL_MANAGED,//Pool, let D3D Manage our memory
		D3DX_DEFAULT, D3DX_DEFAULT,
		0,            //Disable ColourKey
		NULL,         //SourceInfo, returns extra info if we want it (we don't)
		NULL,         //Palette:We're not using one
		&TexStatePreview );

	std::string a5 = "D:\\skins\\";
	a5 += skinPath;
	a5 += "\\";
	a5 += "previewresize.png";
	D3DXCreateTextureFromFileEx(Device, 
		a5.c_str(), 
		D3DX_DEFAULT, //Width:D3DX_DEFAULT = Take from file 
		D3DX_DEFAULT, //Height:D3DX_DEFAULT = Take from file
		1,            //MipLevels
		0,            //Usage, Is this to be used as a Render Target? 0 == No
		D3DFMT_A8R8G8B8, //32-bit with Alpha, everything should support this
		D3DPOOL_MANAGED,//Pool, let D3D Manage our memory
		D3DX_DEFAULT, D3DX_DEFAULT,
		0,            //Disable ColourKey
		NULL,         //SourceInfo, returns extra info if we want it (we don't)
		NULL,         //Palette:We're not using one
		&TexNoStatePreview );



	std::string a6 = "D:\\skins\\";
	a6 += skinPath;
	a6 += "\\";
	a6 += "previewnotfound.png";
	D3DXCreateTextureFromFileEx(Device, 
		a6.c_str() , 
		D3DX_DEFAULT, //Width:D3DX_DEFAULT = Take from file 
		D3DX_DEFAULT, //Height:D3DX_DEFAULT = Take from file
		1,            //MipLevels
		0,            //Usage, Is this to be used as a Render Target? 0 == No
		D3DFMT_A8R8G8B8, //32-bit with Alpha, everything should support this
		D3DPOOL_MANAGED,//Pool, let D3D Manage our memory
		D3DX_DEFAULT, D3DX_DEFAULT,
		0,            //Disable ColourKey
		NULL,         //SourceInfo, returns extra info if we want it (we don't)
		NULL,         //Palette:We're not using one
		&TexNoBox );

	{
	}

	std::string a8 = "D:\\skins\\";
	a8 += skinPath;
	a8 += "\\";
	a8 += "previewnotfound.png";
	D3DXCreateTextureFromFileEx(Device, 
		a8.c_str(), 
		D3DX_DEFAULT, //Width:D3DX_DEFAULT = Take from file 
		D3DX_DEFAULT, //Height:D3DX_DEFAULT = Take from file
		1,            //MipLevels
		0,            //Usage, Is this to be used as a Render Target? 0 == No
		D3DFMT_A8R8G8B8, //32-bit with Alpha, everything should support this
		D3DPOOL_MANAGED,//Pool, let D3D Manage our memory
		D3DX_DEFAULT, D3DX_DEFAULT,
		0,            //Disable ColourKey
		NULL,         //SourceInfo, returns extra info if we want it (we don't)
		NULL,         //Palette:We're not using one
		&TexPreview2 );

	//switchMP(mpType);


	std::string a9 = "D:\\skins\\";
	a9 += skinPath;
	a9 += "\\";
	a9 += "resize.png";
	D3DXCreateTextureFromFileEx(Device, 
		a9.c_str(), 
		D3DX_DEFAULT, //Width:D3DX_DEFAULT = Take from file 
		D3DX_DEFAULT, //Height:D3DX_DEFAULT = Take from file
		1,            //MipLevels
		0,            //Usage, Is this to be used as a Render Target? 0 == No
		D3DFMT_A8R8G8B8, //32-bit with Alpha, everything should support this
		D3DPOOL_MANAGED,//Pool, let D3D Manage our memory
		D3DX_DEFAULT, D3DX_DEFAULT,
		0,            //Disable ColourKey
		NULL,         //SourceInfo, returns extra info if we want it (we don't)
		NULL,         //Palette:We're not using one
		&TexResize );


	std::string a10 = "D:\\skins\\";
	a10 += skinPath;
	a10 += "\\";
	a10 += "controller.png";
	D3DXCreateTextureFromFileEx(Device, 
		a10.c_str(), 
		D3DX_DEFAULT, //Width:D3DX_DEFAULT = Take from file 
		D3DX_DEFAULT, //Height:D3DX_DEFAULT = Take from file
		1,            //MipLevels
		0,            //Usage, Is this to be used as a Render Target? 0 == No
		D3DFMT_A8R8G8B8, //32-bit with Alpha, everything should support this
		D3DPOOL_MANAGED,//Pool, let D3D Manage our memory
		D3DX_DEFAULT, D3DX_DEFAULT,
		0,            //Disable ColourKey
		NULL,         //SourceInfo, returns extra info if we want it (we don't)
		NULL,         //Palette:We're not using one
		&TexController );

	

	std::string a12 = "D:\\skins\\";
	a12 += skinPath;
	a12 += "\\";
	a12 += "splash.png";

	D3DXCreateTextureFromFileEx(Device, 
		a12.c_str(), 
		D3DX_DEFAULT, //Width:D3DX_DEFAULT = Take from file 
		D3DX_DEFAULT, //Height:D3DX_DEFAULT = Take from file
		1,            //MipLevels
		0,            //Usage, Is this to be used as a Render Target? 0 == No
		D3DFMT_A8R8G8B8, //32-bit with Alpha, everything should support this
		D3DPOOL_MANAGED,//Pool, let D3D Manage our memory
		D3DX_DEFAULT, //Filter:Default filtering
		D3DX_DEFAULT, //MipFilter, used for filtering mipmaps
		0,            //Disable ColourKey
		NULL,         //SourceInfo, returns extra info if we want it (we don't)
		NULL,         //Palette:We're not using one
		&TexSplash);

	std::string a13 = "D:\\skins\\";
	a13 += skinPath;
	a13 += "\\";
	a13 += "splashFinal.png";
	D3DXCreateTextureFromFileEx(Device, 
		a13.c_str(), 
		D3DX_DEFAULT, //Width:D3DX_DEFAULT = Take from file 
		D3DX_DEFAULT, //Height:D3DX_DEFAULT = Take from file
		1,            //MipLevels
		0,            //Usage, Is this to be used as a Render Target? 0 == No
		D3DFMT_A8R8G8B8, //32-bit with Alpha, everything should support this
		D3DPOOL_MANAGED,//Pool, let D3D Manage our memory
		D3DX_DEFAULT, //Filter:Default filtering
		D3DX_DEFAULT, //MipFilter, used for filtering mipmaps
		0,            //Disable ColourKey
		NULL,         //SourceInfo, returns extra info if we want it (we don't)
		NULL,         //Palette:We're not using one
		&TexSplashFinal);


	std::string a14 = "D:\\skins\\";
	a14 += skinPath;
	a14 += "\\";
	a14 += "previewborder.png";
	if( FAILED( D3DXCreateTextureFromFileEx(Device, 
		a14.c_str(), 
		D3DX_DEFAULT, //Width:D3DX_DEFAULT = Take from file 
		D3DX_DEFAULT, //Height:D3DX_DEFAULT = Take from file
		1,            //MipLevels
		0,            //Usage, Is this to be used as a Render Target? 0 == No
		D3DFMT_A8R8G8B8, //32-bit with Alpha, everything should support this
		D3DPOOL_MANAGED,//Pool, let D3D Manage our memory
		D3DX_DEFAULT, D3DX_DEFAULT,
		0,            //Disable ColourKey
		NULL,         //SourceInfo, returns extra info if we want it (we don't)
		NULL,         //Palette:We're not using one
		&TexPreviewBorder ) ) )
	{

	}

	std::string a16 = "D:\\skins\\";
	a16 += skinPath;
	a16 += "\\";
	a16 += "logo2.png";
	if( FAILED( D3DXCreateTextureFromFileEx(Device, 
		a16.c_str(), 
		D3DX_DEFAULT, //Width:D3DX_DEFAULT = Take from file 
		D3DX_DEFAULT, //Height:D3DX_DEFAULT = Take from file
		1,            //MipLevels
		0,            //Usage, Is this to be used as a Render Target? 0 == No
		D3DFMT_A8R8G8B8, //32-bit with Alpha, everything should support this
		D3DPOOL_MANAGED,//Pool, let D3D Manage our memory
		D3DX_DEFAULT, D3DX_DEFAULT,
		0,            //Disable ColourKey
		NULL,         //SourceInfo, returns extra info if we want it (we don't)
		NULL,         //Palette:We're not using one
		&TexLogo2 ) ) )
	{

	}


	loadAnimation();
	


}

extern char skinPath[512];

int TexScreenInit(char* path)
{
	TexWidth =640;
	TexHeight=480;


	//g_pd3dDevice->CreateTexture(clipx * 2, clipy * 2 + 4, 1, 0, D3DFMT_LIN_R5G6B5 , NULL, &Texture);
	Device->CreateTexture(TexWidth, TexHeight, 0, 0L, D3DFMT_LIN_R5G6B5, D3DPOOL_DEFAULT, &TexScreen);
	Device->CreateTexture(TexWidth, TexHeight, 0, 0L, D3DFMT_LIN_R5G6B5, D3DPOOL_DEFAULT, &TexScreenShot);
	//////dprintf("Trying to create texture\n");
	//D3DXCreateTexture(Device, 640, 480, 0, 0, D3DFMT_LIN_R5G6B5, D3DPOOL_DEFAULT, &TexScreen);
	//D3DXCreateTexture(Device, 640, 480, 0, 0, D3DFMT_LIN_R5G6B5, D3DPOOL_DEFAULT, &TexScreen);
	if (TexScreen==NULL) {return 1; }

	loadTextures(skinPath, 0);
	D3DSURFACE_DESC desc;
	TexScreen->GetLevelDesc( 0, &desc );
	DWORD dwTexWidth  = desc.Width;
	DWORD dwTexHeight = desc.Height;
//	DWORD dwTexDepth  = 0;


	D3DLOCKED_RECT lock;
	TexScreen->LockRect( 0, &lock, 0, 0L );
	VOID* pBits = lock.pBits;


	//////dprintf("TexWidth: %d, TexHeight: %d, pitch: %d\n", dwTexWidth, dwTexHeight, lock.Pitch);
	// Loop through and touch the texels.
	for( DWORD y = 0; y < dwTexHeight; y++ )
	{
		for( DWORD x = 0; x < dwTexWidth; x++ )
		{
			//((WORD*)pBits)[y*dwTexWidth+x] = (WORD)(((x>>3)<<11) | ((y>>3)<<0));
			((unsigned short*)pBits)[y*dwTexWidth+x] = 0;//0x00FF;
		}
	}
	TexScreen->UnlockRect( 0 );

	blankTexScreenShot();
	makeVertexListResizeB();
	makeVertexListResizePB();

	return 0;
}

void TexScreenExit()
{
	RELEASE(TexScreen)
		TexWidth=TexHeight=0;
}
void freeSplash() {
	if(TexSplash) {
		TexSplash->Release();
		TexSplash = NULL;
	}
	if(TexSplashFinal) {
		TexSplashFinal->Release();
		TexSplashFinal = NULL;
	}
}
#include <xgraphics.h>

// Copy screen to a swizzled texture
int TexScreenSwizzle()
{
	D3DSURFACE_DESC desc;
	TexScreen->GetLevelDesc( 0, &desc );
	DWORD dwTexWidth  = desc.Width;
	DWORD dwTexHeight = desc.Height;
//	DWORD dwTexDepth  = 0;

	D3DLOCKED_RECT lock;
	TexScreen->LockRect( 0, &lock, 0, 0L );
	VOID* pBits = lock.pBits;


	//////dprintf("TexWidth: %d, TexHeight: %d, pitch: %d\n", dwTexWidth, dwTexHeight, lock.Pitch);
	// Loop through and touch the texels.
	for( DWORD y = 0; y < dwTexHeight; y++ )
	{
		for( DWORD x = 0; x < dwTexWidth; x++ )
		{
			//((WORD*)pBits)[y*dwTexWidth+x] = (WORD)(((x>>3)<<11) | ((y>>3)<<0));
			((unsigned short*)pBits)[y*dwTexWidth+x] = (unsigned short)(EmuScreen[y*dwTexWidth+x]);
		}
	}
	TexScreen->UnlockRect( 0 );
	return 0;
}
#include <xgraphics.h>

int TexScreenLinear()
{
	return 0;
}

void loadGUIPreview(char* path) {
	if(TexGUIPreview) {
		TexGUIPreview->Release();
		TexGUIPreview = NULL;
	}

	std::string a4 = "D:\\skins\\";
	a4 += path;
	a4 += "\\";
	a4 += "guipreview.png";
	D3DXCreateTextureFromFileEx(Device, 
		a4.c_str(), 
		D3DX_DEFAULT, //Width:D3DX_DEFAULT = Take from file 
		D3DX_DEFAULT, //Height:D3DX_DEFAULT = Take from file
		1,            //MipLevels
		0,            //Usage, Is this to be used as a Render Target? 0 == No
		D3DFMT_A8R8G8B8, //32-bit with Alpha, everything should support this
		D3DPOOL_MANAGED,//Pool, let D3D Manage our memory
		D3DX_DEFAULT, //Filter:Default filtering
		D3DX_DEFAULT, //MipFilter, used for filtering mipmaps
		0,            //Disable ColourKey
		NULL,         //SourceInfo, returns extra info if we want it (we don't)
		NULL,         //Palette:We're not using one
		&TexGUIPreview );

}
