Move git root from Client/ to src/ to track all source code: - Client: Game client source (moved to Client/Client/) - Server: Game server source - GameTools: Development tools - CryptoSource: Encryption utilities - database: Database scripts - Script: Game scripts - rylCoder_16.02.2008_src: Legacy coder tools - GMFont, Game: Additional resources 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1091 lines
26 KiB
C++
1091 lines
26 KiB
C++
// Dds_container.cpp : implementation file
|
||
//
|
||
|
||
#include "stdafx.h"
|
||
#include "worldcreator.h"
|
||
#include "Dds_container.h"
|
||
#include "selectFolderDialog.h"
|
||
#include "CEffScript.h"
|
||
#include "ConvertTexture.h"
|
||
#include "MeshObject.h"
|
||
|
||
#ifdef _DEBUG
|
||
#define new DEBUG_NEW
|
||
#undef THIS_FILE
|
||
static char THIS_FILE[] = __FILE__;
|
||
#endif
|
||
|
||
/////////////////////////////////////////////////////////////////////////////
|
||
// CDds_container dialog
|
||
|
||
|
||
CDds_container::CDds_container(CWnd* pParent /*=NULL*/)
|
||
: CDialog(CDds_container::IDD, pParent)
|
||
{
|
||
//{{AFX_DATA_INIT(CDds_container)
|
||
m_Edit = _T("");
|
||
m_Radio = -1;
|
||
m_Radio2 = -1;
|
||
m_Radio3 = -1;
|
||
m_bDivTexture = FALSE;
|
||
//}}AFX_DATA_INIT
|
||
}
|
||
|
||
|
||
void CDds_container::DoDataExchange(CDataExchange* pDX)
|
||
{
|
||
CDialog::DoDataExchange(pDX);
|
||
|
||
//{{AFX_DATA_MAP(CDds_container)
|
||
DDX_Control(pDX, IDC_EDIT, m_econtrol);
|
||
DDX_Text(pDX, IDC_EDIT, m_Edit);
|
||
DDX_Radio(pDX, IDC_RADIO1, m_Radio);
|
||
DDX_Radio(pDX, IDC_RADIO3, m_Radio2);
|
||
DDX_Radio(pDX, IDC_RADIO8, m_Radio3);
|
||
DDX_Check(pDX, IDC_CHECK_LOWTEX, m_bDivTexture);
|
||
//}}AFX_DATA_MAP
|
||
}
|
||
|
||
|
||
BEGIN_MESSAGE_MAP(CDds_container, CDialog)
|
||
//{{AFX_MSG_MAP(CDds_container)
|
||
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
|
||
ON_EN_CHANGE(IDC_EDIT, OnChangeEdit)
|
||
ON_BN_CLICKED(IDC_BUTTON_CONVERTLOWHARDWARE, OnButtonConvertlowhardware)
|
||
ON_BN_CLICKED(IDC_ESF, OnEsf)
|
||
ON_BN_CLICKED(IDC_BUTTON_TOTALTEXTURECONVERT, OnButtonTotaltextureconvert)
|
||
ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
|
||
ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
|
||
ON_BN_CLICKED(IDC_BUTTON_DDS2TGA, OnButtonDds2tga)
|
||
ON_BN_CLICKED(IDC_BUTTON_BUMPGENERATE, OnButtonBumpgenerate)
|
||
ON_BN_CLICKED(IDC_BUTTON_TGA2DDS, OnButtonTga2dds)
|
||
ON_BN_CLICKED(IDC_MAPINFOCONV, OnMapinfoconv)
|
||
ON_BN_CLICKED(IDC_DDSHEADER, OnDdsheader)
|
||
ON_BN_CLICKED(IDC_BUTTONESFINFO, OnButtonesfinfo)
|
||
ON_BN_CLICKED(IDC_BUTTON_CONVERTMESH, OnButtonConvertmesh)
|
||
//}}AFX_MSG_MAP
|
||
END_MESSAGE_MAP()
|
||
|
||
/////////////////////////////////////////////////////////////////////////////
|
||
// CDds_container message handlers
|
||
|
||
void CDds_container::OnButton1()
|
||
{
|
||
char str[] = "BMP <20><><EFBFBD><EFBFBD>(*.bmp) |*.bmp| <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(*.*)|*.*||";
|
||
UpdateData(true);
|
||
if(m_Radio ==0) {
|
||
// TODO: Add your control notification handler code here
|
||
CString strFilter = str;
|
||
CFileDialog filedia(TRUE,NULL,NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,strFilter,this);
|
||
filedia.DoModal();
|
||
|
||
m_Edit=filedia.GetFileName();
|
||
}
|
||
else if(m_Radio == 1) {
|
||
CSelectFolderDialog SelectFolderDlg(TRUE, "C:\\", OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, NULL, this);
|
||
|
||
if(SelectFolderDlg.DoModal()!=IDOK)
|
||
{
|
||
return;
|
||
}
|
||
m_Edit=SelectFolderDlg.GetSelectedPath();
|
||
}
|
||
else
|
||
MessageBox("File or Directory must select.");
|
||
|
||
UpdateData(false);
|
||
|
||
}
|
||
|
||
void CDds_container::OnChangeEdit()
|
||
{
|
||
// TODO: If this is a RICHEDIT control, the control will not
|
||
// send this notification unless you override the CDialog::OnInitDialog()
|
||
// function and call CRichEditCtrl().SetEventMask()
|
||
// with the ENM_CHANGE flag ORed into the mask.
|
||
|
||
// TODO: Add your control notification handler code here
|
||
|
||
}
|
||
void CDds_container::Compress() {
|
||
|
||
|
||
switch(m_Radio2) {
|
||
//DXT1
|
||
case 0:
|
||
ChangeFormat(base,D3DFMT_DXT1, &ptexNew);
|
||
break;
|
||
//DXT2
|
||
case 1:
|
||
ChangeFormat(base,D3DFMT_DXT2, &ptexNew);
|
||
break;
|
||
//DXT3
|
||
case 2:
|
||
ChangeFormat(base,D3DFMT_DXT3, &ptexNew);
|
||
break;
|
||
//DXT4
|
||
case 3:
|
||
ChangeFormat(base,D3DFMT_DXT4, &ptexNew);
|
||
break;
|
||
//DXT5
|
||
case 4:
|
||
ChangeFormat(base,D3DFMT_DXT5, &ptexNew);
|
||
break;
|
||
case 5:
|
||
ChangeFormat(base,D3DFMT_A4R4G4B4,&ptexNew);
|
||
break;
|
||
|
||
}
|
||
ReleasePpo(&base);
|
||
base = ptexNew;
|
||
if(m_Radio3 != 0)
|
||
Mipmap();
|
||
|
||
}
|
||
void CDds_container::Mipmap() {
|
||
LONG lwTempH;
|
||
LONG lwTempW;
|
||
LONG lwPowsW;
|
||
LONG lwPowsH;
|
||
LPDIRECT3DTEXTURE8 pddsNew = NULL;
|
||
D3DFORMAT fmt;
|
||
HRESULT hr;
|
||
LPDIRECT3DDEVICE8 pd3ddev = BaseGraphicsLayer::GetDevice();
|
||
LPDIRECT3DTEXTURE8 pmiptex = NULL;
|
||
|
||
LPDIRECT3DTEXTURE8 pmiptexNew = NULL;
|
||
LPDIRECT3DCUBETEXTURE8 pcubetexNew = NULL;
|
||
LPDIRECT3DVOLUMETEXTURE8 pvoltexNew = NULL;
|
||
LPDIRECT3DSURFACE8 psurfSrc;
|
||
LPDIRECT3DSURFACE8 psurfDest;
|
||
// LPDIRECT3DVOLUME8 pvolSrc;
|
||
// LPDIRECT3DVOLUME8 pvolDest;
|
||
|
||
pmiptex = (LPDIRECT3DTEXTURE8)base;
|
||
|
||
D3DSURFACE_DESC sd;
|
||
pmiptex->GetLevelDesc(0, &sd);
|
||
fmt = sd.Format;
|
||
|
||
|
||
lwTempW = m_dwWidth;
|
||
lwTempH = m_dwHeight;
|
||
lwPowsW = 0;
|
||
lwPowsH = 0;
|
||
while (lwTempW > 0)
|
||
{
|
||
lwPowsW++;
|
||
lwTempW = lwTempW / 2;
|
||
}
|
||
while (lwTempH > 0)
|
||
{
|
||
lwPowsH++;
|
||
lwTempH = lwTempH / 2;
|
||
}
|
||
m_numMips = lwPowsW > lwPowsH ? lwPowsW : lwPowsH;
|
||
|
||
// Create destination mipmap surface - same format as source
|
||
hr = pd3ddev->CreateTexture(m_dwWidth, m_dwHeight, m_numMips,
|
||
0, fmt, D3DPOOL_MANAGED, &pmiptexNew);
|
||
hr = pmiptex->GetSurfaceLevel(0, &psurfSrc);
|
||
hr = pmiptexNew->GetSurfaceLevel(0, &psurfDest);
|
||
hr = D3DXLoadSurfaceFromSurface(psurfDest, NULL, NULL, psurfSrc, NULL, NULL,
|
||
D3DX_FILTER_TRIANGLE, 0);
|
||
ReleasePpo(&psurfSrc);
|
||
ReleasePpo(&psurfDest);
|
||
hr = D3DXFilterTexture(pmiptexNew, NULL, 0, D3DX_FILTER_TRIANGLE);
|
||
|
||
|
||
ReleasePpo(&base);
|
||
|
||
base = pmiptexNew;
|
||
/*
|
||
if (m_ptexNew != NULL)
|
||
{
|
||
D3DSURFACE_DESC sd;
|
||
((LPDIRECT3DCUBETEXTURE8)m_ptexNew)->GetLevelDesc(0, &sd);
|
||
fmt = sd.Format;
|
||
}
|
||
Compress(fmt, FALSE);
|
||
}
|
||
*/
|
||
return;
|
||
}
|
||
|
||
HRESULT CDds_container::ChangeFormat(LPDIRECT3DBASETEXTURE8 ptexCur, D3DFORMAT fmtTo,
|
||
LPDIRECT3DBASETEXTURE8* pptexNew)
|
||
{
|
||
HRESULT hr;
|
||
LPDIRECT3DDEVICE8 pd3ddev = BaseGraphicsLayer::GetDevice();
|
||
LPDIRECT3DTEXTURE8 pmiptex;
|
||
// LPDIRECT3DCUBETEXTURE8 pcubetex;
|
||
// LPDIRECT3DVOLUMETEXTURE8 pvoltex;
|
||
D3DFORMAT fmtFrom;
|
||
LPDIRECT3DTEXTURE8 pmiptexNew;
|
||
// LPDIRECT3DCUBETEXTURE8 pcubetexNew;
|
||
// LPDIRECT3DVOLUMETEXTURE8 pvoltexNew;
|
||
|
||
pmiptex = (LPDIRECT3DTEXTURE8)ptexCur;
|
||
D3DSURFACE_DESC sd;
|
||
pmiptex->GetLevelDesc(0, &sd);
|
||
fmtFrom = sd.Format;
|
||
|
||
|
||
hr = pd3ddev->CreateTexture(m_dwWidth, m_dwHeight, m_numMips,
|
||
0, fmtTo, D3DPOOL_MANAGED, &pmiptexNew);
|
||
if (FAILED(hr))
|
||
return hr;
|
||
*pptexNew = pmiptexNew;
|
||
if (FAILED(BltAllLevels(D3DCUBEMAP_FACE_FORCE_DWORD, ptexCur, *pptexNew)))
|
||
return hr;
|
||
|
||
return S_OK;
|
||
}
|
||
HRESULT CDds_container::BltAllLevels(D3DCUBEMAP_FACES FaceType, LPDIRECT3DBASETEXTURE8 ptexSrc,
|
||
LPDIRECT3DBASETEXTURE8 ptexDest) {
|
||
HRESULT hr;
|
||
LPDIRECT3DTEXTURE8 pmiptexSrc;
|
||
LPDIRECT3DTEXTURE8 pmiptexDest;
|
||
// LPDIRECT3DCUBETEXTURE8 pcubetexSrc;
|
||
// LPDIRECT3DCUBETEXTURE8 pcubetexDest;
|
||
// LPDIRECT3DVOLUMETEXTURE8 pvoltexSrc;
|
||
// LPDIRECT3DVOLUMETEXTURE8 pvoltexDest;
|
||
DWORD iLevel;
|
||
|
||
pmiptexSrc = (LPDIRECT3DTEXTURE8)ptexSrc;
|
||
pmiptexDest = (LPDIRECT3DTEXTURE8)ptexDest;
|
||
|
||
for (iLevel = 0; iLevel < m_numMips; iLevel++)
|
||
{
|
||
LPDIRECT3DSURFACE8 psurfSrc = NULL;
|
||
LPDIRECT3DSURFACE8 psurfDest = NULL;
|
||
hr = pmiptexSrc->GetSurfaceLevel(iLevel, &psurfSrc);
|
||
hr = pmiptexDest->GetSurfaceLevel(iLevel, &psurfDest);
|
||
hr = D3DXLoadSurfaceFromSurface(psurfDest, NULL, NULL,
|
||
psurfSrc, NULL, NULL, D3DX_FILTER_TRIANGLE, 0);
|
||
ReleasePpo(&psurfSrc);
|
||
ReleasePpo(&psurfDest);
|
||
|
||
}
|
||
|
||
return S_OK;
|
||
}
|
||
void CDds_container::OnOK()
|
||
{
|
||
char tmp[256] = {0};
|
||
char dir[256] = {0};
|
||
char tmp2[256]= {0};
|
||
|
||
D3DXIMAGE_INFO imageinfo;
|
||
|
||
char *file;
|
||
// TODO: Add extra validation here
|
||
UpdateData(true);
|
||
//file
|
||
if(m_Radio == 0) {
|
||
strcpy(tmp,m_Edit.LockBuffer());
|
||
file = strtok(tmp,".");
|
||
D3DXGetImageInfoFromFile( m_Edit, &imageinfo );
|
||
m_dwWidth = imageinfo.Width;
|
||
m_dwHeight = imageinfo.Height;
|
||
m_numMips = imageinfo.MipLevels;
|
||
|
||
D3DXCreateTextureFromFile(BaseGraphicsLayer::GetDevice(),m_Edit,(LPDIRECT3DTEXTURE8 *)&base);
|
||
m_Edit.Format("%s.dds",file);
|
||
Compress();
|
||
D3DXSaveTextureToFile(m_Edit, D3DXIFF_DDS, base, NULL );
|
||
|
||
}
|
||
|
||
//directory
|
||
else if(m_Radio == 1) {
|
||
|
||
CFileFind finder;
|
||
strcpy(dir,m_Edit);
|
||
strcat(dir,"*.bmp");
|
||
BOOL bWorking = finder.FindFile(dir);
|
||
while (bWorking)
|
||
{
|
||
bWorking = finder.FindNextFile();
|
||
strcpy(tmp2,finder.GetFileName());
|
||
strcpy(tmp,tmp2);
|
||
file = strtok(tmp,".");
|
||
D3DXGetImageInfoFromFile( tmp2, &imageinfo );
|
||
|
||
m_dwWidth = imageinfo.Width;
|
||
m_dwHeight = imageinfo.Height;
|
||
m_numMips = imageinfo.MipLevels;
|
||
|
||
D3DXCreateTextureFromFile(BaseGraphicsLayer::GetDevice(),tmp2,(LPDIRECT3DTEXTURE8 *)&base);
|
||
strcat(file,".dds");
|
||
Compress();
|
||
D3DXSaveTextureToFile(file, D3DXIFF_DDS, base, NULL );
|
||
}
|
||
|
||
}
|
||
|
||
CDialog::OnOK();
|
||
}
|
||
|
||
void CDds_container::OnButtonConvertlowhardware()
|
||
{
|
||
// TODO: Add your control notification handler code here
|
||
/*
|
||
char tmp[256] = {0};
|
||
char dir[256] = {0};
|
||
char tmp2[256]= {0};
|
||
|
||
CFileFind finder;
|
||
strcpy(dir,m_Edit);
|
||
strcat(dir,"*.dds");
|
||
BOOL bWorking = finder.FindFile(dir);
|
||
while (bWorking)
|
||
{
|
||
bWorking = finder.FindNextFile();
|
||
strcpy(tmp2,finder.GetFileName());
|
||
strcpy(tmp,tmp2);
|
||
file = strtok(tmp,".");
|
||
D3DXGetImageInfoFromFile( tmp2, &imageinfo );
|
||
|
||
m_dwWidth = imageinfo.Width;
|
||
m_dwHeight = imageinfo.Height;
|
||
m_numMips = imageinfo.MipLevels;
|
||
|
||
D3DXCreateTextureFromFile(BaseGraphicsLayer::GetDevice(),tmp2,(LPDIRECT3DTEXTURE8 *)&base);
|
||
strcat(file,".dds");
|
||
Compress();
|
||
D3DXSaveTextureToFile(file, D3DXIFF_DDS, base, NULL );
|
||
}
|
||
*/
|
||
|
||
UpdateData();
|
||
|
||
CFileFind Finder;
|
||
CString strFolder=m_Edit;
|
||
CString strFilename;
|
||
strFolder+="*.dds";
|
||
|
||
BOOL bFinding=Finder.FindFile(strFolder);
|
||
|
||
D3DXIMAGE_INFO imageinfo;
|
||
|
||
int nWidth;
|
||
int nHeight;
|
||
|
||
LPDIRECT3DTEXTURE8 pddTexture;
|
||
|
||
|
||
while(bFinding)
|
||
{
|
||
bFinding=Finder.FindNextFile();
|
||
if(bFinding==FALSE)
|
||
break;
|
||
|
||
strFilename=Finder.GetFileName();
|
||
|
||
|
||
D3DXGetImageInfoFromFile(strFilename.LockBuffer(),&imageinfo);
|
||
|
||
if(m_bDivTexture)
|
||
{
|
||
nWidth=imageinfo.Width>>1;
|
||
nHeight=imageinfo.Height>>1;
|
||
}
|
||
else
|
||
{
|
||
nWidth=imageinfo.Width;
|
||
nHeight=imageinfo.Height;
|
||
}
|
||
|
||
if(nWidth>256)
|
||
{
|
||
nWidth=nWidth>>1;
|
||
}
|
||
if(nHeight>256)
|
||
{
|
||
nHeight=nHeight>>1;
|
||
}
|
||
|
||
D3DXCreateTextureFromFileEx(BaseGraphicsLayer::GetDevice(),strFilename.LockBuffer(),nWidth,nHeight
|
||
,0,0,D3DFMT_A4R4G4B4,D3DPOOL_MANAGED,D3DX_DEFAULT,D3DX_DEFAULT,0,NULL,NULL,&pddTexture);
|
||
|
||
D3DXFilterTexture(pddTexture,NULL,0,D3DX_FILTER_BOX | D3DX_FILTER_DITHER);
|
||
|
||
D3DXSaveTextureToFile(strFilename.LockBuffer(), D3DXIFF_DDS, pddTexture, NULL );
|
||
|
||
pddTexture->Release();
|
||
}
|
||
}
|
||
|
||
void CDds_container::OnEsf()
|
||
{
|
||
// TODO: Add your control notification handler code here
|
||
char str[] = "Esf <20><><EFBFBD><EFBFBD>(*.esf) |*.esf| <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(*.*)|*.*||";
|
||
CString strFilter = str;
|
||
CString t_name;
|
||
|
||
CFileDialog filedia(TRUE,NULL,NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,strFilter,this);
|
||
filedia.DoModal();
|
||
t_name = filedia.GetFileName();
|
||
CEffScript *test_script = NULL;
|
||
|
||
test_script = new CEffScript[1];
|
||
|
||
if(t_name.GetLength() > 1)
|
||
test_script->GetScriptData(t_name.LockBuffer());
|
||
|
||
}
|
||
|
||
void CDds_container::OnButtonTotaltextureconvert()
|
||
{
|
||
// TODO: Add your control notification handler code here
|
||
|
||
|
||
char path[256];
|
||
GetCurrentDirectory(256,path);
|
||
|
||
char str[256],str2[256];
|
||
|
||
sprintf(str,"%s\\Texture\\Lightmap",path);
|
||
sprintf(str2,"%s\\LowTexture\\Lightmap",path);
|
||
AutoConvertTexture(str,str2);
|
||
|
||
sprintf(str,"%s\\Texture\\NatureObject\\Zone1",path);
|
||
sprintf(str2,"%s\\LowTexture\\NatureObject\\Zone1",path);
|
||
AutoConvertTexture(str,str2);
|
||
|
||
sprintf(str,"%s\\Texture\\Object",path);
|
||
sprintf(str2,"%s\\LowTexture\\Object",path);
|
||
AutoConvertTexture(str,str2);
|
||
|
||
sprintf(str,"%s\\Texture\\Terrain\\Zone1",path);
|
||
sprintf(str2,"%s\\LowTexture\\Terrain\\Zone1",path);
|
||
AutoConvertTexture(str,str2);
|
||
|
||
sprintf(str,"%s\\Texture\\WideTexture\\Zone1",path);
|
||
sprintf(str2,"%s\\LowTexture\\WideTexture\\Zone1",path);
|
||
AutoConvertTexture(str,str2);
|
||
|
||
//AutoConvertTexture("c:/MP-Project/Texture/Effect","c:/MP-Project/LowTexture/Effect");
|
||
|
||
|
||
//AutoConvertTexture("c:/MP-Project/Character/Data/Texture","c:/MP-Project/Character/Data/LowTexture",true,false);
|
||
|
||
//AutoConvertTexture("c:/MP-Project/Texture/Interface","c:/MP-Project/LowTexture/Interface",false,true);
|
||
|
||
//AutoConvertTexture("c:/MP-Project/Texture/Interface/Item","c:/MP-Project/LowTexture/Interface/Item",false,true);
|
||
|
||
}
|
||
void CDds_container::AutoHeaderCreate(CString strSrc)
|
||
{
|
||
char strPathAll[256];
|
||
sprintf(strPathAll,"%s/*.dds",strSrc);
|
||
|
||
WIN32_FIND_DATA wfd = {0};
|
||
HANDLE hFind = FindFirstFile(strPathAll, &wfd);
|
||
if(INVALID_HANDLE_VALUE == hFind)
|
||
return;
|
||
|
||
CString strFilePathname;
|
||
while(1)
|
||
{
|
||
strFilePathname.Format("%s/%s",strSrc,wfd.cFileName);
|
||
|
||
FILE *fp=fopen(strFilePathname.LockBuffer(),"rb+");
|
||
if(fp)
|
||
{
|
||
DWORD dwHeader= 0x20534444; //"DDS "
|
||
|
||
fwrite(&dwHeader,sizeof(DWORD),1,fp);
|
||
fclose(fp);
|
||
}
|
||
if(FindNextFile(hFind, &wfd)==FALSE)
|
||
break;
|
||
}
|
||
}
|
||
void CDds_container::AutoConvertTexture(CString strSrc, CString strTar,bool bSmall,bool bHeader)
|
||
{
|
||
TextureHeaderRestore(strSrc.LockBuffer());
|
||
|
||
CFileFind Finder;
|
||
CString strFolder=strSrc;
|
||
CString strFilename;
|
||
strFolder+="\\";
|
||
strFolder+="*.DDS";
|
||
|
||
//char strPathAll[256];
|
||
//sprintf(strPathAll,"%s/*.dds",strPath);
|
||
|
||
WIN32_FIND_DATA wfd = {0};
|
||
HANDLE hFind = FindFirstFile(strFolder.LockBuffer(), &wfd);
|
||
if(INVALID_HANDLE_VALUE == hFind)
|
||
return;
|
||
|
||
CString strFilePathname;
|
||
|
||
D3DXIMAGE_INFO imageinfo;
|
||
|
||
int nWidth;
|
||
int nHeight;
|
||
|
||
LPDIRECT3DTEXTURE8 pddTexture;
|
||
|
||
CString strSrcFilename;
|
||
|
||
while(1)
|
||
{
|
||
strSrcFilename.Format("%s/%s",strSrc.LockBuffer(),wfd.cFileName);
|
||
|
||
D3DXGetImageInfoFromFile(strSrcFilename.LockBuffer(),&imageinfo);
|
||
|
||
if(bSmall)
|
||
{
|
||
nWidth=imageinfo.Width>>1;
|
||
nHeight=imageinfo.Height>>1;
|
||
}
|
||
else
|
||
{
|
||
nWidth=imageinfo.Width;
|
||
nHeight=imageinfo.Height;
|
||
}
|
||
|
||
|
||
|
||
D3DXCreateTextureFromFileEx(BaseGraphicsLayer::GetDevice(),strSrcFilename.LockBuffer(),nWidth,nHeight
|
||
,0,0,D3DFMT_A4R4G4B4,D3DPOOL_MANAGED,D3DX_DEFAULT,D3DX_DEFAULT,0,NULL,NULL,&pddTexture);
|
||
|
||
D3DXFilterTexture(pddTexture,NULL,0,D3DX_FILTER_BOX | D3DX_FILTER_DITHER);
|
||
CString strTargetFilename;
|
||
strTargetFilename=strTar+"/"+wfd.cFileName;
|
||
D3DXSaveTextureToFile(strTargetFilename.LockBuffer(), D3DXIFF_DDS, pddTexture, NULL );
|
||
|
||
pddTexture->Release();
|
||
|
||
/*
|
||
FILE *fp=fopen(strFilePathname.LockBuffer(),"rb+");
|
||
if(fp)
|
||
{
|
||
DWORD dwHeader=0;
|
||
fwrite(&dwHeader,sizeof(DWORD),1,fp);
|
||
fclose(fp);
|
||
}
|
||
*/
|
||
if(FindNextFile(hFind, &wfd)==FALSE)
|
||
break;
|
||
}
|
||
|
||
|
||
/*
|
||
BOOL bFinding=Finder.FindFile(strFolder);
|
||
|
||
|
||
|
||
|
||
while(bFinding)
|
||
{
|
||
bFinding=Finder.FindNextFile();
|
||
if(bFinding==FALSE)
|
||
break;
|
||
strFilename=Finder.GetFileName();
|
||
|
||
CString strSrcFilename=strSrc+"/"+strFilename;
|
||
|
||
D3DXGetImageInfoFromFile(strSrcFilename.LockBuffer(),&imageinfo);
|
||
|
||
if(bSmall)
|
||
{
|
||
nWidth=imageinfo.Width>>1;
|
||
nHeight=imageinfo.Height>>1;
|
||
}
|
||
else
|
||
{
|
||
nWidth=imageinfo.Width;
|
||
nHeight=imageinfo.Height;
|
||
}
|
||
|
||
|
||
|
||
D3DXCreateTextureFromFileEx(BaseGraphicsLayer::GetDevice(),strSrcFilename.LockBuffer(),nWidth,nHeight
|
||
,0,0,D3DFMT_A4R4G4B4,D3DPOOL_MANAGED,D3DX_DEFAULT,D3DX_DEFAULT,0,NULL,NULL,&pddTexture);
|
||
|
||
D3DXFilterTexture(pddTexture,NULL,0,D3DX_FILTER_BOX | D3DX_FILTER_DITHER);
|
||
CString strTargetFilename;
|
||
strTargetFilename=strTar+"/"+strFilename;
|
||
D3DXSaveTextureToFile(strTargetFilename.LockBuffer(), D3DXIFF_DDS, pddTexture, NULL );
|
||
|
||
pddTexture->Release();
|
||
}
|
||
*/
|
||
|
||
|
||
if(bHeader)
|
||
{
|
||
TextureHeaderFix(strSrc.LockBuffer());
|
||
TextureHeaderFix(strTar.LockBuffer());
|
||
}
|
||
}
|
||
|
||
void CDds_container::TextureHeaderFix(char *strPath)
|
||
{
|
||
char strPathAll[256];
|
||
sprintf(strPathAll,"%s/*.dds",strPath);
|
||
|
||
WIN32_FIND_DATA wfd = {0};
|
||
HANDLE hFind = FindFirstFile(strPathAll, &wfd);
|
||
if(INVALID_HANDLE_VALUE == hFind)
|
||
return;
|
||
|
||
CString strFilePathname;
|
||
while(1)
|
||
{
|
||
strFilePathname.Format("%s/%s",strPath,wfd.cFileName);
|
||
|
||
FILE *fp=fopen(strFilePathname.LockBuffer(),"rb+");
|
||
if(fp)
|
||
{
|
||
DWORD dwHeader= 0;
|
||
|
||
fwrite(&dwHeader,sizeof(DWORD),1,fp);
|
||
fclose(fp);
|
||
}
|
||
if(FindNextFile(hFind, &wfd)==FALSE)
|
||
break;
|
||
}
|
||
}
|
||
|
||
void CDds_container::TextureHeaderRestore(char *strPath)
|
||
{
|
||
char strPathAll[256];
|
||
sprintf(strPathAll,"%s/*.dds",strPath);
|
||
|
||
WIN32_FIND_DATA wfd = {0};
|
||
HANDLE hFind = FindFirstFile(strPathAll, &wfd);
|
||
if(INVALID_HANDLE_VALUE == hFind)
|
||
return;
|
||
|
||
CString strFilePathname;
|
||
while(1)
|
||
{
|
||
strFilePathname.Format("%s/%s",strPath,wfd.cFileName);
|
||
|
||
FILE *fp=fopen(strFilePathname.LockBuffer(),"rb+");
|
||
if(fp)
|
||
{
|
||
DWORD dwMagic=MAKEFOURCC('D','D','S',' ');
|
||
fwrite(&dwMagic,sizeof(dwMagic),1,fp);
|
||
fclose(fp);
|
||
}
|
||
if(FindNextFile(hFind, &wfd)==FALSE)
|
||
break;
|
||
}
|
||
}
|
||
|
||
void CDds_container::OnButton2()
|
||
{
|
||
// TODO: Add your control notification handler code here
|
||
|
||
AutoConvertTexture("c:/Temp","c:/Temp/out",false,true);
|
||
}
|
||
|
||
void CDds_container::OnButton3()
|
||
{
|
||
// TODO: Add your control notification handler code here
|
||
AutoConvertTexture("c:/Temp","c:/Temp/out",true,true);
|
||
}
|
||
|
||
void CDds_container::OnButtonDds2tga()
|
||
{
|
||
// TODO: Add your control notification handler code here
|
||
|
||
CSelectFolderDialog SelectFolderDlg(TRUE, "C:\\", OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, NULL, this);
|
||
|
||
if(SelectFolderDlg.DoModal()!=IDOK)
|
||
{
|
||
return;
|
||
}
|
||
CString strFolder;
|
||
strFolder=SelectFolderDlg.GetSelectedPath();
|
||
AutoTGAConvertTexture(strFolder.LockBuffer());
|
||
|
||
}
|
||
|
||
void CDds_container::AutoTGAConvertTexture(char *strPath)
|
||
{
|
||
char strPathAll[256];
|
||
sprintf(strPathAll,"%s/*.dds",strPath);
|
||
|
||
WIN32_FIND_DATA wfd = {0};
|
||
HANDLE hFind = FindFirstFile(strPathAll, &wfd);
|
||
if(INVALID_HANDLE_VALUE == hFind)
|
||
return;
|
||
|
||
LPDIRECT3DTEXTURE8 pDDSTexture;
|
||
|
||
CString strFilePathname;
|
||
CString strTGAFilename;
|
||
while(1)
|
||
{
|
||
strFilePathname.Format("%s%s",strPath,wfd.cFileName);
|
||
|
||
D3DXCreateTextureFromFile(BaseGraphicsLayer::GetDevice(),strFilePathname.LockBuffer(),&pDDSTexture);
|
||
|
||
strTGAFilename=strFilePathname;
|
||
strTGAFilename.SetAt(strTGAFilename.GetLength()-1,'P');
|
||
strTGAFilename.SetAt(strTGAFilename.GetLength()-2,'M');
|
||
strTGAFilename.SetAt(strTGAFilename.GetLength()-3,'B');
|
||
|
||
D3DXSaveTextureToFile(strTGAFilename.LockBuffer(),D3DXIFF_BMP,pDDSTexture,NULL);
|
||
|
||
|
||
pDDSTexture->Release();
|
||
|
||
if(FindNextFile(hFind, &wfd)==FALSE)
|
||
break;
|
||
}
|
||
}
|
||
|
||
void CDds_container::OnButtonBumpgenerate()
|
||
{
|
||
// TODO: Add your control notification handler code here
|
||
CSelectFolderDialog SelectFolderDlg(TRUE, "C:\\", OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, NULL, this);
|
||
|
||
if(SelectFolderDlg.DoModal()!=IDOK)
|
||
{
|
||
return;
|
||
}
|
||
CString strFolder;
|
||
strFolder=SelectFolderDlg.GetSelectedPath();
|
||
|
||
ConvertBump(strFolder.LockBuffer());
|
||
|
||
}
|
||
|
||
void CDds_container::ConvertBump(char *strFolder)
|
||
{
|
||
char strPathAll[256];
|
||
sprintf(strPathAll,"%s/*.tga",strFolder);
|
||
|
||
WIN32_FIND_DATA wfd = {0};
|
||
HANDLE hFind = FindFirstFile(strPathAll, &wfd);
|
||
if(INVALID_HANDLE_VALUE == hFind)
|
||
return;
|
||
|
||
// LPDIRECT3DTEXTURE8 pDDSTexture;
|
||
|
||
CString strFilePathname;
|
||
CString strTGAFilename;
|
||
|
||
CString strConvert;
|
||
|
||
FILE *fp=fopen("c:/test.bat","w");
|
||
|
||
while(1)
|
||
{
|
||
strFilePathname.Format("%s%s",strFolder,wfd.cFileName);
|
||
|
||
strTGAFilename=strFilePathname;
|
||
strTGAFilename.Insert(strTGAFilename.GetLength()-4,"_bump");
|
||
|
||
//strConvert.Format("c:\\normalmapgen %s %s\n",strFilePathname.LockBuffer(),strTGAFilename.LockBuffer());
|
||
|
||
fprintf(fp,"c:\\normalmapgen %s %s\n",strFilePathname.LockBuffer(),strTGAFilename.LockBuffer());
|
||
|
||
/*
|
||
STARTUPINFO si={sizeof(STARTUPINFO),0,};
|
||
PROCESS_INFORMATION pi;
|
||
CreateProcess(strConvert.LockBuffer(),"",NULL,NULL,FALSE,NORMAL_PRIORITY_CLASS,NULL,NULL,&si,&pi);
|
||
WaitForSingleObject( pi.hProcess, INFINITE);
|
||
DeleteObject( pi.hProcess);
|
||
DeleteObject( pi.hThread );
|
||
*/
|
||
|
||
if(FindNextFile(hFind, &wfd)==FALSE)
|
||
break;
|
||
}
|
||
fclose(fp);
|
||
}
|
||
|
||
void CDds_container::OnButtonTga2dds()
|
||
{
|
||
// TODO: Add your control notification handler code here
|
||
CSelectFolderDialog SelectFolderDlg(TRUE, "C:\\", OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, NULL, this);
|
||
|
||
if(SelectFolderDlg.DoModal()!=IDOK)
|
||
{
|
||
return;
|
||
}
|
||
CString strFolder;
|
||
strFolder=SelectFolderDlg.GetSelectedPath();
|
||
|
||
ConvertTGA2DDS(strFolder.LockBuffer());
|
||
}
|
||
|
||
void CDds_container::ConvertTGA2DDS(char *strFolder)
|
||
{
|
||
char strPathAll[256];
|
||
sprintf(strPathAll,"%s/*.tga",strFolder);
|
||
|
||
WIN32_FIND_DATA wfd = {0};
|
||
HANDLE hFind = FindFirstFile(strPathAll, &wfd);
|
||
if(INVALID_HANDLE_VALUE == hFind)
|
||
return;
|
||
|
||
// LPDIRECT3DTEXTURE8 pDDSTexture;
|
||
|
||
CString strFilePathname;
|
||
CString strTGAFilename;
|
||
FILE *fp=fopen("c:/test1.bat","w");
|
||
|
||
// D3DXIMAGE_INFO Info;
|
||
while(1)
|
||
{
|
||
strFilePathname.Format("%s%s",strFolder,wfd.cFileName);
|
||
|
||
strTGAFilename=strFilePathname;
|
||
strTGAFilename.SetAt(strTGAFilename.GetLength()-1,'S');
|
||
strTGAFilename.SetAt(strTGAFilename.GetLength()-2,'D');
|
||
strTGAFilename.SetAt(strTGAFilename.GetLength()-3,'D');
|
||
|
||
fprintf(fp,"s3tc/m /3 %s %s\n",strFilePathname,strTGAFilename);
|
||
|
||
/*
|
||
D3DXCreateTextureFromFileEx(BaseGraphicsLayer::GetDevice(),
|
||
strFilePathname.LockBuffer(),
|
||
D3DX_DEFAULT,
|
||
D3DX_DEFAULT,
|
||
0,
|
||
D3DPOOL_DEFAULT,
|
||
D3DFMT_UNKNOWN,
|
||
D3DPOOL_MANAGED,
|
||
|
||
D3DX_DEFAULT,
|
||
D3DX_DEFAULT,
|
||
0,
|
||
&Info,
|
||
NULL,
|
||
&pDDSTexture);
|
||
|
||
strTGAFilename=strFilePathname;
|
||
strTGAFilename.SetAt(strTGAFilename.GetLength()-1,'S');
|
||
strTGAFilename.SetAt(strTGAFilename.GetLength()-2,'D');
|
||
strTGAFilename.SetAt(strTGAFilename.GetLength()-3,'D');
|
||
|
||
CConvertTexture DeCompressTexture;
|
||
DeCompressTexture.m_pddNewTexture=pDDSTexture;
|
||
DeCompressTexture.m_dwHeight=Info.Height;
|
||
DeCompressTexture.m_dwWidth=Info.Width;
|
||
|
||
D3DXFilterTexture(DeCompressTexture.m_pddNewTexture,NULL,0,D3DX_FILTER_BOX | D3DX_FILTER_DITHER);
|
||
DeCompressTexture.m_pddTexture=DeCompressTexture.m_pddNewTexture;
|
||
DeCompressTexture.GenerateMipMaps(true);
|
||
DeCompressTexture.Compress(D3DFMT_DXT3);
|
||
|
||
DeCompressTexture.SaveDDS(strTGAFilename.LockBuffer());
|
||
DeCompressTexture.m_pddNewTexture=NULL;
|
||
|
||
|
||
//D3DXSaveTextureToFile(strTGAFilename.LockBuffer(),D3DXIFF_DDS,pDDSTexture,NULL);
|
||
|
||
pDDSTexture->Release();
|
||
*/
|
||
|
||
if(FindNextFile(hFind, &wfd)==FALSE)
|
||
break;
|
||
}
|
||
fclose(fp);
|
||
}
|
||
|
||
void CDds_container::OnMapinfoconv()
|
||
{
|
||
|
||
char str[] = "Map Info <20><><EFBFBD><EFBFBD>(*.info) |*.info| <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>(*.*)|*.*||";
|
||
CString strFilter = str;
|
||
CString t_name;
|
||
|
||
CFileDialog filedia(TRUE,NULL,NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,strFilter,this);
|
||
filedia.DoModal();
|
||
t_name = filedia.GetFileName();
|
||
|
||
if(t_name.GetLength() > 1) {
|
||
if(MapInfoFileLoad(t_name.LockBuffer()))
|
||
MessageBox("Map Info File Convert Successed");
|
||
else
|
||
MessageBox("Map Info File Convert Failed");
|
||
}
|
||
// TODO: Add your control notification handler code here
|
||
|
||
}
|
||
bool CDds_container::MapInfoFileLoad(char *strPath)
|
||
{
|
||
FILE *fp = NULL;
|
||
|
||
char strBuf[256] = {0};
|
||
char *token = NULL;
|
||
|
||
int iValue[30] = {0};
|
||
float fValue[30];
|
||
|
||
memset(fValue,0,sizeof(float) * 30);
|
||
|
||
fp = fopen(strPath,"rt");
|
||
if(fp == NULL)
|
||
return false;
|
||
while(!feof(fp)) {
|
||
memset(strBuf,0,sizeof(char) * 256);
|
||
fgets(strBuf,sizeof(char) * 255,fp);
|
||
token = strtok(strBuf," \n\t");
|
||
if(token != NULL) {
|
||
if((*token) == '/') // <20>ּ<EFBFBD> <20><><EFBFBD><EFBFBD>
|
||
continue;
|
||
else if(!strcmp(token,"MAP:")) { // Map Size load
|
||
fValue[0] = (float)atof(token = strtok(NULL," \n\t"));
|
||
fValue[1] = (float)atof(token = strtok(NULL," \n\t"));
|
||
fValue[2] = (float)atof(token = strtok(NULL," \n\t"));
|
||
|
||
fValue[3] = (float)atof(token = strtok(NULL," \n\t"));
|
||
fValue[4] = (float)atof(token = strtok(NULL," \n\t"));
|
||
fValue[5] = (float)atof(token = strtok(NULL," \n\t"));
|
||
}
|
||
else if(!strcmp(token,"CULL:")) { // Map Culling Info (House,Object,Effect <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>..)
|
||
iValue[1] = atoi(token = strtok(NULL," \n\t"));
|
||
iValue[2] = atoi(token = strtok(NULL," \n\t"));
|
||
iValue[3] = atoi(token = strtok(NULL," \n\t"));
|
||
}
|
||
else if(!strcmp(token,"TIME:")) { // weather setting <20>ð<EFBFBD>
|
||
iValue[0] = atoi(token = strtok(NULL," \n\t"));
|
||
}
|
||
else if(!strcmp(token,"BOUND:")) {
|
||
fValue[6] = (float)atof(token = strtok(NULL," \n\t")); //Min Bound
|
||
fValue[7] = (float)atof(token = strtok(NULL," \n\t")); //Max Bound
|
||
|
||
}
|
||
else if(!strcmp(token,"PATH:")) { // <20><><EFBFBD><EFBFBD> setting
|
||
iValue[4] = atoi(token = strtok(NULL," \n\t"));
|
||
}
|
||
}
|
||
}
|
||
fclose(fp);
|
||
fp = NULL;
|
||
// Write Binary File
|
||
fp = fopen(strPath,"wb");
|
||
|
||
if(fp == NULL)
|
||
return false;
|
||
|
||
fwrite((int *)iValue,sizeof(int),30,fp);
|
||
fwrite((float *)fValue,sizeof(float),30,fp);
|
||
|
||
fclose(fp);
|
||
|
||
return true;
|
||
|
||
}
|
||
|
||
void CDds_container::OnDdsheader()
|
||
{
|
||
// TODO: Add your control notification handler code here
|
||
AutoHeaderCreate("c:/Temp");
|
||
}
|
||
|
||
void CDds_container::OnButtonesfinfo()
|
||
{
|
||
// TODO: Add your control notification handler code here
|
||
char strFilePath[256] = {0,};
|
||
char strPath[256] = {0,};
|
||
strcpy(strPath,"c:/temp");
|
||
FILE *fp;
|
||
fp = fopen("c:/temp/Esf.info","wt+");
|
||
|
||
strcpy(strFilePath,strPath);
|
||
strcat(strFilePath,"/*.esf");
|
||
WIN32_FIND_DATA FindFileData;
|
||
HANDLE hFind;
|
||
hFind = FindFirstFile(strFilePath, &FindFileData);
|
||
|
||
if (hFind == INVALID_HANDLE_VALUE)
|
||
{
|
||
MessageBox("Effect Loader<65><72> <20><><EFBFBD><EFBFBD> <20>߽<EFBFBD><DFBD>ϴ<EFBFBD>.");
|
||
return ;
|
||
}
|
||
|
||
|
||
while(1)
|
||
{
|
||
fprintf(fp,"%s\n",FindFileData.cFileName);
|
||
|
||
if(!FindNextFile(hFind,&FindFileData))
|
||
break;
|
||
}
|
||
FindClose(hFind);
|
||
fclose(fp);
|
||
MessageBox("Esf.info <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>");
|
||
|
||
}
|
||
|
||
void CDds_container::OnButtonConvertmesh()
|
||
{
|
||
// TODO: Add your control notification handler code here
|
||
ConvertR3S("c:/Temp","c:/Temp/out");
|
||
}
|
||
void CDds_container::ConvertR3S(CString strSrcPath,CString strDestPath)
|
||
{
|
||
CFileFind Finder;
|
||
CString strFolder=strSrcPath;
|
||
CString strFilename;
|
||
strFolder+="\\";
|
||
strFolder+="*.R3S";
|
||
|
||
//char strPathAll[256];
|
||
//sprintf(strPathAll,"%s/*.dds",strPath);
|
||
|
||
WIN32_FIND_DATA wfd = {0};
|
||
HANDLE hFind = FindFirstFile(strFolder.LockBuffer(), &wfd);
|
||
if(INVALID_HANDLE_VALUE == hFind)
|
||
return;
|
||
|
||
CString strFilePathname;
|
||
|
||
CString strSrcFilename;
|
||
|
||
while(1)
|
||
{
|
||
CMeshObject Mesh;
|
||
FILE *fp = NULL;
|
||
|
||
|
||
strSrcFilename.Format("%s/%s",strSrcPath.LockBuffer(),wfd.cFileName);
|
||
Mesh.Load(strSrcFilename.LockBuffer());
|
||
Mesh.SetShader(MultiFVF);
|
||
if(Mesh.m_iMethod == 0)
|
||
{
|
||
CString strTargetFilename;
|
||
strTargetFilename=strDestPath+"/"+wfd.cFileName;
|
||
|
||
|
||
char *strchr = strrchr(wfd.cFileName,'.');
|
||
if(strchr)
|
||
{
|
||
*strchr = '.'; strchr++;
|
||
*strchr = 'd'; strchr++;
|
||
*strchr = 'd'; strchr++;
|
||
*strchr = 's';
|
||
}
|
||
|
||
strSrcFilename.Format("%s/%s",strSrcPath.LockBuffer(),wfd.cFileName);
|
||
fp = fopen(strSrcFilename,"rb");
|
||
if(fp == NULL)
|
||
{
|
||
Mesh.ConvertNormal();
|
||
Mesh.SaveConvertMesh(strTargetFilename.LockBuffer(),3);
|
||
}
|
||
else
|
||
{
|
||
fclose(fp);
|
||
fp = NULL;
|
||
Mesh.Save(strTargetFilename.LockBuffer());
|
||
}
|
||
}
|
||
if(FindNextFile(hFind, &wfd)==FALSE)
|
||
break;
|
||
}
|
||
} |