Diff
checker
文本
文本
图像
文档
Excel
文件夹
Legal
Enterprise
桌面版
定价
登录
下载 Diffchecker 桌面版
比较文本
查找两个文本文件之间的差异
工具
历史
显示
视图
拆分
统一
实时编辑器
隐藏空白更改
折叠未更改行
关闭换行
比对精度
智能
语法
无
更改外观
处理
忽略
文本转换
转到第一个差异
编辑输入
Diffchecker Desktop
运行Diffchecker最安全的方式。获取Diffchecker桌面应用:您的差异永远不会离开您的电脑!
获取桌面版
Untitled diff
创建于
12年前
差异永不过期
清除
导出
分享
解释
0 删除
行
总计
删除
字符
总计
删除
要继续使用此功能,请升级到
Diff
checker
Pro
查看价格
195 行
全部复制
1 添加
行
总计
添加
字符
总计
添加
要继续使用此功能,请升级到
Diff
checker
Pro
查看价格
196 行
全部复制
/** © 2013, Brandon T. All Rights Reserved.
/** © 2013, Brandon T. All Rights Reserved.
*
*
* This file is part of the DXI Library.
* This file is part of the DXI Library.
* DXI is free software: you can redistribute it and/or modify
* DXI is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* (at your option) any later version.
*
*
* DXI is distributed in the hope that it will be useful,
* DXI is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public License
* You should have received a copy of the GNU General Public License
* along with DXI. If not, see <http://www.gnu.org/licenses/>.
* along with DXI. If not, see <http://www.gnu.org/licenses/>.
*/
*/
#include "SmartPlugin.hpp"
#include "SmartPlugin.hpp"
IDirect3DTexture9* Texture = nullptr;
IDirect3DTexture9* Texture = nullptr;
std::uint8_t* TexturePixels = nullptr;
std::uint8_t* TexturePixels = nullptr;
SMARTInfo* SmartGlobal = nullptr;
SMARTInfo* SmartGlobal = nullptr;
bool SmartDebugEnabled = false;
bool SmartDebugEnabled = false;
bool SmartDirectXEnabled = true;
bool SmartDirectXEnabled = true;
void SMARTButtonPressed(int ID, bool State)
void SMARTButtonPressed(int ID, bool State)
{
{
switch(ID)
switch(ID)
{
{
case 100:
case 100:
if (State)
if (State)
{
{
SmartGlobal->setCapture(false);
SmartGlobal->setCapture(false);
SmartDirectXEnabled = true;
SmartDirectXEnabled = true;
}
}
else
else
{
{
SmartGlobal->setCapture(true);
SmartGlobal->setCapture(true);
SmartDirectXEnabled = false;
SmartDirectXEnabled = false;
}
}
break;
break;
case 101:
case 101:
SmartDebugEnabled = State ? false : true;
SmartDebugEnabled = State ? false : true;
break;
break;
}
}
}
}
extern "C" void SMARTPluginInit(SMARTInfo* ptr, bool* ReplaceButtons, int* ButtonCount, char** * ButtonText, int** ButtonIDs, _SMARTButtonPressed* ButtonCallback)
extern "C" void SMARTPluginInit(SMARTInfo* ptr, bool* ReplaceButtons, int* ButtonCount, char** * ButtonText, int** ButtonIDs, _SMARTButtonPressed* ButtonCallback)
{
{
SmartGlobal = ptr;
SmartGlobal = ptr;
if (ptr)
if (ptr)
{
{
*ReplaceButtons = true;
*ReplaceButtons = true;
char** ButtonTexts = new char* [2];
char** ButtonTexts = new char* [2];
ButtonTexts[0] = const_cast<char*>("Disable Direct-X_Enable Direct-X");
ButtonTexts[0] = const_cast<char*>("Disable Direct-X_Enable Direct-X");
ButtonTexts[1] = const_cast<char*>("Enable Debug_Disable dxDebug");
ButtonTexts[1] = const_cast<char*>("Enable Debug_Disable dxDebug");
int* IDs = new int[2];
int* IDs = new int[2];
IDs[0] = 100;
IDs[0] = 100;
IDs[1] = 101;
IDs[1] = 101;
*ButtonCount = 2;
*ButtonCount = 2;
*ButtonText = ButtonTexts;
*ButtonText = ButtonTexts;
*ButtonIDs = IDs;
*ButtonIDs = IDs;
*ButtonCallback = &SMARTButtonPressed;
*ButtonCallback = &SMARTButtonPressed;
}
}
}
}
#define VERTEX_FVF (D3DFVF_XYZRHW | D3DFVF_DIFFUSE)
#define VERTEX_FVF (D3DFVF_XYZRHW | D3DFVF_DIFFUSE)
#define VERTEX_FVF_TEX (D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1)
#define VERTEX_FVF_TEX (D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1)
struct D3DVertex
struct D3DVertex
{
{
float X, Y, Z, RHW;
float X, Y, Z, RHW;
unsigned int Colour;
unsigned int Colour;
float U, V;
float U, V;
};
};
void LoadTexture(IDirect3DDevice9* Device, std::uint8_t* buffer, int width, int height, IDirect3DTexture9* &Texture)
void LoadTexture(IDirect3DDevice9* Device, std::uint8_t* buffer, int width, int height, IDirect3DTexture9* &Texture)
{
{
Device->CreateTexture(width, height, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &Texture, 0);
Device->CreateTexture(width, height, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &Texture, 0);
D3DLOCKED_RECT rect;
D3DLOCKED_RECT rect;
Texture->LockRect(0, &rect, nullptr, D3DLOCK_DISCARD);
Texture->LockRect(0, &rect, nullptr, D3DLOCK_DISCARD);
TexturePixels = static_cast<std::uint8_t*>(rect.pBits);
TexturePixels = static_cast<std::uint8_t*>(rect.pBits);
Texture->UnlockRect(0);
Texture->UnlockRect(0);
memcpy(TexturePixels, &buffer[0], width * height * 4);
memcpy(TexturePixels, &buffer[0], width * height * 4);
}
}
void DrawTexture(IDirect3DDevice9* Device, IDirect3DTexture9* Texture, float X1, float Y1, float X2, float Y2)
void DrawTexture(IDirect3DDevice9* Device, IDirect3DTexture9* Texture, float X1, float Y1, float X2, float Y2)
{
{
/**http://msdn.microsoft.com/en-us/library/windows/desktop/bb219690%28v=vs.85%29.aspx**/
/**http://msdn.microsoft.com/en-us/library/windows/desktop/bb219690%28v=vs.85%29.aspx**/
/**Offsets needed because of the above**/
/**Offsets needed because of the above**/
float UOffset = 0.5f / (float)(X2 - X1);
float UOffset = 0.5f / (float)(X2 - X1);
float VOffset = 0.5f / (float)(Y2 - Y1);
float VOffset = 0.5f / (float)(Y2 - Y1);
D3DVertex Vertices[] =
D3DVertex Vertices[] =
{
{
{X1, Y1, 1.0f, 1.0f, D3DCOLOR_RGBA(0xFF, 0xFF, 0xFF, 0xFF), 0.0f + UOffset, 0.0f + VOffset},
{X1, Y1, 1.0f, 1.0f, D3DCOLOR_RGBA(0xFF, 0xFF, 0xFF, 0xFF), 0.0f + UOffset, 0.0f + VOffset},
{X2, Y1, 1.0f, 1.0f, D3DCOLOR_RGBA(0xFF, 0xFF, 0xFF, 0xFF), 1.0f + UOffset, 0.0f + VOffset},
{X2, Y1, 1.0f, 1.0f, D3DCOLOR_RGBA(0xFF, 0xFF, 0xFF, 0xFF), 1.0f + UOffset, 0.0f + VOffset},
{X1, Y2, 1.0f, 1.0f, D3DCOLOR_RGBA(0xFF, 0xFF, 0xFF, 0xFF), 0.0f + UOffset, 1.0f + VOffset},
{X1, Y2, 1.0f, 1.0f, D3DCOLOR_RGBA(0xFF, 0xFF, 0xFF, 0xFF), 0.0f + UOffset, 1.0f + VOffset},
{X2, Y2, 1.0f, 1.0f, D3DCOLOR_RGBA(0xFF, 0xFF, 0xFF, 0xFF), 1.0f + UOffset, 1.0f + VOffset}
{X2, Y2, 1.0f, 1.0f, D3DCOLOR_RGBA(0xFF, 0xFF, 0xFF, 0xFF), 1.0f + UOffset, 1.0f + VOffset}
};
};
Device->SetFVF(VERTEX_FVF_TEX);
Device->SetFVF(VERTEX_FVF_TEX);
Device->SetTexture(0, Texture);
Device->SetTexture(0, Texture);
Device->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, Vertices, sizeof(D3DVertex));
Device->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, Vertices, sizeof(D3DVertex));
Device->SetTexture(0, nullptr);
Device->SetTexture(0, nullptr);
}
}
void DrawCircle(IDirect3DDevice9* Device, float CX, float CY, float Radius, D3DCOLOR Colour)
void DrawCircle(IDirect3DDevice9* Device, float CX, float CY, float Radius, D3DCOLOR Colour)
{
{
static const int Resolution = 10;
static const int Resolution = 10;
D3DVertex Vertices[Resolution];
D3DVertex Vertices[Resolution];
for (int I = 0; I < Resolution; ++I)
for (int I = 0; I < Resolution; ++I)
{
{
Vertices[I].X = CX + Radius * std::cos(3.141592654f * (I / (Resolution / 2.0f)));
Vertices[I].X = CX + Radius * std::cos(3.141592654f * (I / (Resolution / 2.0f)));
Vertices[I].Y = CY + Radius * std::sin(3.141592654f * (I / (Resolution / 2.0f)));
Vertices[I].Y = CY + Radius * std::sin(3.141592654f * (I / (Resolution / 2.0f)));
Vertices[I].Z = 0.0f;
Vertices[I].Z = 0.0f;
Vertices[I].RHW = 1.0f;
Vertices[I].RHW = 1.0f;
Vertices[I].Colour = Colour;
Vertices[I].Colour = Colour;
Vertices[I].U = 0.0f;
Vertices[I].U = 0.0f;
Vertices[I].V = 0.0f;
Vertices[I].V = 0.0f;
}
}
Device->SetFVF(VERTEX_FVF_TEX);
Device->SetFVF(VERTEX_FVF_TEX);
Device->DrawPrimitiveUP(D3DPT_TRIANGLEFAN, Resolution - 2, Vertices, sizeof(D3DVertex));
Device->DrawPrimitiveUP(D3DPT_TRIANGLEFAN, Resolution - 2, Vertices, sizeof(D3DVertex));
}
}
void BltSmartBuffer(IDirect3DDevice9* Device)
void BltSmartBuffer(IDirect3DDevice9* Device)
{
{
if (SmartGlobal != nullptr)
if (SmartGlobal != nullptr)
{
{
std::uint8_t* Ptr = reinterpret_cast<std::uint8_t*>(SmartGlobal->dbg);
std::uint8_t* Ptr = reinterpret_cast<std::uint8_t*>(SmartGlobal->dbg);
for (int I = 0; I < SmartGlobal->height; ++I)
for (int I = 0; I < SmartGlobal->height; ++I)
{
{
for (int J = 0; J < SmartGlobal->width; ++J)
for (int J = 0; J < SmartGlobal->width; ++J)
{
{
std::uint8_t B = *(Ptr++);
std::uint8_t B = *(Ptr++);
std::uint8_t G = *(Ptr++);
std::uint8_t G = *(Ptr++);
std::uint8_t R = *(Ptr++);
std::uint8_t R = *(Ptr++);
*(Ptr++) = (B == 0 && G == 0 && R == 0) ? 0 : 0xFF;
*(Ptr++) = (B == 0 && G == 0 && R == 0) ? 0 : 0xFF;
}
}
}
}
if (!Texture) /**Set Device->Reset for more info.**/
if (!Texture) /**Set Device->Reset for more info.**/
{
{
LoadTexture(Device, static_cast<unsigned char*>(SmartGlobal->dbg), SmartGlobal->width, SmartGlobal->height, Texture);
LoadTexture(Device, static_cast<unsigned char*>(SmartGlobal->dbg), SmartGlobal->width, SmartGlobal->height, Texture);
}
}
else
else
{
{
memcpy(TexturePixels, SmartGlobal->dbg, SmartGlobal->width * SmartGlobal->height * 4);
memcpy(TexturePixels, SmartGlobal->dbg, SmartGlobal->width * SmartGlobal->height * 4);
}
}
DrawTexture(Device, Texture, 0, 0, SmartGlobal->width, SmartGlobal->height);
DrawTexture(Device, Texture, 0, 0, SmartGlobal->width, SmartGlobal->height);
复制
已复制
复制
已复制
SafeRelease(Texture);
}
}
}
}
HRESULT dxReadPixels(IDirect3DDevice9* Device, void* Buffer, HDC& DC, int& Width, int& Height, D3DFORMAT Format)
HRESULT dxReadPixels(IDirect3DDevice9* Device, void* Buffer, HDC& DC, int& Width, int& Height, D3DFORMAT Format)
{
{
IDirect3DSurface9* RenderTarget = nullptr;
IDirect3DSurface9* RenderTarget = nullptr;
IDirect3DSurface9* DestTarget = nullptr;
IDirect3DSurface9* DestTarget = nullptr;
HRESULT result = Device->GetRenderTarget(0, &RenderTarget);
HRESULT result = Device->GetRenderTarget(0, &RenderTarget);
if (result == S_OK)
if (result == S_OK)
{
{
if (Width == 0 || Height == 0 || Format == D3DFMT_UNKNOWN)
if (Width == 0 || Height == 0 || Format == D3DFMT_UNKNOWN)
{
{
D3DSURFACE_DESC descriptor = {};
D3DSURFACE_DESC descriptor = {};
RenderTarget->GetDesc(&descriptor);
RenderTarget->GetDesc(&descriptor);
Width = descriptor.Width;
Width = descriptor.Width;
Height = descriptor.Height;
Height = descriptor.Height;
Format = descriptor.Format;
Format = descriptor.Format;
}
}
RenderTarget->GetDC(&DC);
RenderTarget->GetDC(&DC);
result = Device->CreateOffscreenPlainSurface(Width, Height, Format, D3DPOOL_SYSTEMMEM, &DestTarget, nullptr);
result = Device->CreateOffscreenPlainSurface(Width, Height, Format, D3DPOOL_SYSTEMMEM, &DestTarget, nullptr);
result = Device->GetRenderTargetData(RenderTarget, DestTarget);
result = Device->GetRenderTargetData(RenderTarget, DestTarget);
D3DLOCKED_RECT rect;
D3DLOCKED_RECT rect;
DestTarget->LockRect(&rect, 0, D3DLOCK_READONLY);
DestTarget->LockRect(&rect, 0, D3DLOCK_READONLY);
memcpy(Buffer, rect.pBits, Width * Height * 4);
memcpy(Buffer, rect.pBits, Width * Height * 4);
DestTarget->UnlockRect();
DestTarget->UnlockRect();
}
}
SafeRelease(RenderTarget);
SafeRelease(RenderTarget);
SafeRelease(DestTarget);
SafeRelease(DestTarget);
return result;
return result;
}
}
已保存差异
原始文本
打开文件
/** © 2013, Brandon T. All Rights Reserved. * * This file is part of the DXI Library. * DXI is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * DXI is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with DXI. If not, see <http://www.gnu.org/licenses/>. */ #include "SmartPlugin.hpp" IDirect3DTexture9* Texture = nullptr; std::uint8_t* TexturePixels = nullptr; SMARTInfo* SmartGlobal = nullptr; bool SmartDebugEnabled = false; bool SmartDirectXEnabled = true; void SMARTButtonPressed(int ID, bool State) { switch(ID) { case 100: if (State) { SmartGlobal->setCapture(false); SmartDirectXEnabled = true; } else { SmartGlobal->setCapture(true); SmartDirectXEnabled = false; } break; case 101: SmartDebugEnabled = State ? false : true; break; } } extern "C" void SMARTPluginInit(SMARTInfo* ptr, bool* ReplaceButtons, int* ButtonCount, char** * ButtonText, int** ButtonIDs, _SMARTButtonPressed* ButtonCallback) { SmartGlobal = ptr; if (ptr) { *ReplaceButtons = true; char** ButtonTexts = new char* [2]; ButtonTexts[0] = const_cast<char*>("Disable Direct-X_Enable Direct-X"); ButtonTexts[1] = const_cast<char*>("Enable Debug_Disable dxDebug"); int* IDs = new int[2]; IDs[0] = 100; IDs[1] = 101; *ButtonCount = 2; *ButtonText = ButtonTexts; *ButtonIDs = IDs; *ButtonCallback = &SMARTButtonPressed; } } #define VERTEX_FVF (D3DFVF_XYZRHW | D3DFVF_DIFFUSE) #define VERTEX_FVF_TEX (D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1) struct D3DVertex { float X, Y, Z, RHW; unsigned int Colour; float U, V; }; void LoadTexture(IDirect3DDevice9* Device, std::uint8_t* buffer, int width, int height, IDirect3DTexture9* &Texture) { Device->CreateTexture(width, height, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &Texture, 0); D3DLOCKED_RECT rect; Texture->LockRect(0, &rect, nullptr, D3DLOCK_DISCARD); TexturePixels = static_cast<std::uint8_t*>(rect.pBits); Texture->UnlockRect(0); memcpy(TexturePixels, &buffer[0], width * height * 4); } void DrawTexture(IDirect3DDevice9* Device, IDirect3DTexture9* Texture, float X1, float Y1, float X2, float Y2) { /**http://msdn.microsoft.com/en-us/library/windows/desktop/bb219690%28v=vs.85%29.aspx**/ /**Offsets needed because of the above**/ float UOffset = 0.5f / (float)(X2 - X1); float VOffset = 0.5f / (float)(Y2 - Y1); D3DVertex Vertices[] = { {X1, Y1, 1.0f, 1.0f, D3DCOLOR_RGBA(0xFF, 0xFF, 0xFF, 0xFF), 0.0f + UOffset, 0.0f + VOffset}, {X2, Y1, 1.0f, 1.0f, D3DCOLOR_RGBA(0xFF, 0xFF, 0xFF, 0xFF), 1.0f + UOffset, 0.0f + VOffset}, {X1, Y2, 1.0f, 1.0f, D3DCOLOR_RGBA(0xFF, 0xFF, 0xFF, 0xFF), 0.0f + UOffset, 1.0f + VOffset}, {X2, Y2, 1.0f, 1.0f, D3DCOLOR_RGBA(0xFF, 0xFF, 0xFF, 0xFF), 1.0f + UOffset, 1.0f + VOffset} }; Device->SetFVF(VERTEX_FVF_TEX); Device->SetTexture(0, Texture); Device->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, Vertices, sizeof(D3DVertex)); Device->SetTexture(0, nullptr); } void DrawCircle(IDirect3DDevice9* Device, float CX, float CY, float Radius, D3DCOLOR Colour) { static const int Resolution = 10; D3DVertex Vertices[Resolution]; for (int I = 0; I < Resolution; ++I) { Vertices[I].X = CX + Radius * std::cos(3.141592654f * (I / (Resolution / 2.0f))); Vertices[I].Y = CY + Radius * std::sin(3.141592654f * (I / (Resolution / 2.0f))); Vertices[I].Z = 0.0f; Vertices[I].RHW = 1.0f; Vertices[I].Colour = Colour; Vertices[I].U = 0.0f; Vertices[I].V = 0.0f; } Device->SetFVF(VERTEX_FVF_TEX); Device->DrawPrimitiveUP(D3DPT_TRIANGLEFAN, Resolution - 2, Vertices, sizeof(D3DVertex)); } void BltSmartBuffer(IDirect3DDevice9* Device) { if (SmartGlobal != nullptr) { std::uint8_t* Ptr = reinterpret_cast<std::uint8_t*>(SmartGlobal->dbg); for (int I = 0; I < SmartGlobal->height; ++I) { for (int J = 0; J < SmartGlobal->width; ++J) { std::uint8_t B = *(Ptr++); std::uint8_t G = *(Ptr++); std::uint8_t R = *(Ptr++); *(Ptr++) = (B == 0 && G == 0 && R == 0) ? 0 : 0xFF; } } if (!Texture) /**Set Device->Reset for more info.**/ { LoadTexture(Device, static_cast<unsigned char*>(SmartGlobal->dbg), SmartGlobal->width, SmartGlobal->height, Texture); } else { memcpy(TexturePixels, SmartGlobal->dbg, SmartGlobal->width * SmartGlobal->height * 4); } DrawTexture(Device, Texture, 0, 0, SmartGlobal->width, SmartGlobal->height); } } HRESULT dxReadPixels(IDirect3DDevice9* Device, void* Buffer, HDC& DC, int& Width, int& Height, D3DFORMAT Format) { IDirect3DSurface9* RenderTarget = nullptr; IDirect3DSurface9* DestTarget = nullptr; HRESULT result = Device->GetRenderTarget(0, &RenderTarget); if (result == S_OK) { if (Width == 0 || Height == 0 || Format == D3DFMT_UNKNOWN) { D3DSURFACE_DESC descriptor = {}; RenderTarget->GetDesc(&descriptor); Width = descriptor.Width; Height = descriptor.Height; Format = descriptor.Format; } RenderTarget->GetDC(&DC); result = Device->CreateOffscreenPlainSurface(Width, Height, Format, D3DPOOL_SYSTEMMEM, &DestTarget, nullptr); result = Device->GetRenderTargetData(RenderTarget, DestTarget); D3DLOCKED_RECT rect; DestTarget->LockRect(&rect, 0, D3DLOCK_READONLY); memcpy(Buffer, rect.pBits, Width * Height * 4); DestTarget->UnlockRect(); } SafeRelease(RenderTarget); SafeRelease(DestTarget); return result; }
更改后文本
打开文件
/** © 2013, Brandon T. All Rights Reserved. * * This file is part of the DXI Library. * DXI is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * DXI is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with DXI. If not, see <http://www.gnu.org/licenses/>. */ #include "SmartPlugin.hpp" IDirect3DTexture9* Texture = nullptr; std::uint8_t* TexturePixels = nullptr; SMARTInfo* SmartGlobal = nullptr; bool SmartDebugEnabled = false; bool SmartDirectXEnabled = true; void SMARTButtonPressed(int ID, bool State) { switch(ID) { case 100: if (State) { SmartGlobal->setCapture(false); SmartDirectXEnabled = true; } else { SmartGlobal->setCapture(true); SmartDirectXEnabled = false; } break; case 101: SmartDebugEnabled = State ? false : true; break; } } extern "C" void SMARTPluginInit(SMARTInfo* ptr, bool* ReplaceButtons, int* ButtonCount, char** * ButtonText, int** ButtonIDs, _SMARTButtonPressed* ButtonCallback) { SmartGlobal = ptr; if (ptr) { *ReplaceButtons = true; char** ButtonTexts = new char* [2]; ButtonTexts[0] = const_cast<char*>("Disable Direct-X_Enable Direct-X"); ButtonTexts[1] = const_cast<char*>("Enable Debug_Disable dxDebug"); int* IDs = new int[2]; IDs[0] = 100; IDs[1] = 101; *ButtonCount = 2; *ButtonText = ButtonTexts; *ButtonIDs = IDs; *ButtonCallback = &SMARTButtonPressed; } } #define VERTEX_FVF (D3DFVF_XYZRHW | D3DFVF_DIFFUSE) #define VERTEX_FVF_TEX (D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_TEX1) struct D3DVertex { float X, Y, Z, RHW; unsigned int Colour; float U, V; }; void LoadTexture(IDirect3DDevice9* Device, std::uint8_t* buffer, int width, int height, IDirect3DTexture9* &Texture) { Device->CreateTexture(width, height, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, &Texture, 0); D3DLOCKED_RECT rect; Texture->LockRect(0, &rect, nullptr, D3DLOCK_DISCARD); TexturePixels = static_cast<std::uint8_t*>(rect.pBits); Texture->UnlockRect(0); memcpy(TexturePixels, &buffer[0], width * height * 4); } void DrawTexture(IDirect3DDevice9* Device, IDirect3DTexture9* Texture, float X1, float Y1, float X2, float Y2) { /**http://msdn.microsoft.com/en-us/library/windows/desktop/bb219690%28v=vs.85%29.aspx**/ /**Offsets needed because of the above**/ float UOffset = 0.5f / (float)(X2 - X1); float VOffset = 0.5f / (float)(Y2 - Y1); D3DVertex Vertices[] = { {X1, Y1, 1.0f, 1.0f, D3DCOLOR_RGBA(0xFF, 0xFF, 0xFF, 0xFF), 0.0f + UOffset, 0.0f + VOffset}, {X2, Y1, 1.0f, 1.0f, D3DCOLOR_RGBA(0xFF, 0xFF, 0xFF, 0xFF), 1.0f + UOffset, 0.0f + VOffset}, {X1, Y2, 1.0f, 1.0f, D3DCOLOR_RGBA(0xFF, 0xFF, 0xFF, 0xFF), 0.0f + UOffset, 1.0f + VOffset}, {X2, Y2, 1.0f, 1.0f, D3DCOLOR_RGBA(0xFF, 0xFF, 0xFF, 0xFF), 1.0f + UOffset, 1.0f + VOffset} }; Device->SetFVF(VERTEX_FVF_TEX); Device->SetTexture(0, Texture); Device->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, Vertices, sizeof(D3DVertex)); Device->SetTexture(0, nullptr); } void DrawCircle(IDirect3DDevice9* Device, float CX, float CY, float Radius, D3DCOLOR Colour) { static const int Resolution = 10; D3DVertex Vertices[Resolution]; for (int I = 0; I < Resolution; ++I) { Vertices[I].X = CX + Radius * std::cos(3.141592654f * (I / (Resolution / 2.0f))); Vertices[I].Y = CY + Radius * std::sin(3.141592654f * (I / (Resolution / 2.0f))); Vertices[I].Z = 0.0f; Vertices[I].RHW = 1.0f; Vertices[I].Colour = Colour; Vertices[I].U = 0.0f; Vertices[I].V = 0.0f; } Device->SetFVF(VERTEX_FVF_TEX); Device->DrawPrimitiveUP(D3DPT_TRIANGLEFAN, Resolution - 2, Vertices, sizeof(D3DVertex)); } void BltSmartBuffer(IDirect3DDevice9* Device) { if (SmartGlobal != nullptr) { std::uint8_t* Ptr = reinterpret_cast<std::uint8_t*>(SmartGlobal->dbg); for (int I = 0; I < SmartGlobal->height; ++I) { for (int J = 0; J < SmartGlobal->width; ++J) { std::uint8_t B = *(Ptr++); std::uint8_t G = *(Ptr++); std::uint8_t R = *(Ptr++); *(Ptr++) = (B == 0 && G == 0 && R == 0) ? 0 : 0xFF; } } if (!Texture) /**Set Device->Reset for more info.**/ { LoadTexture(Device, static_cast<unsigned char*>(SmartGlobal->dbg), SmartGlobal->width, SmartGlobal->height, Texture); } else { memcpy(TexturePixels, SmartGlobal->dbg, SmartGlobal->width * SmartGlobal->height * 4); } DrawTexture(Device, Texture, 0, 0, SmartGlobal->width, SmartGlobal->height); SafeRelease(Texture); } } HRESULT dxReadPixels(IDirect3DDevice9* Device, void* Buffer, HDC& DC, int& Width, int& Height, D3DFORMAT Format) { IDirect3DSurface9* RenderTarget = nullptr; IDirect3DSurface9* DestTarget = nullptr; HRESULT result = Device->GetRenderTarget(0, &RenderTarget); if (result == S_OK) { if (Width == 0 || Height == 0 || Format == D3DFMT_UNKNOWN) { D3DSURFACE_DESC descriptor = {}; RenderTarget->GetDesc(&descriptor); Width = descriptor.Width; Height = descriptor.Height; Format = descriptor.Format; } RenderTarget->GetDC(&DC); result = Device->CreateOffscreenPlainSurface(Width, Height, Format, D3DPOOL_SYSTEMMEM, &DestTarget, nullptr); result = Device->GetRenderTargetData(RenderTarget, DestTarget); D3DLOCKED_RECT rect; DestTarget->LockRect(&rect, 0, D3DLOCK_READONLY); memcpy(Buffer, rect.pBits, Width * Height * 4); DestTarget->UnlockRect(); } SafeRelease(RenderTarget); SafeRelease(DestTarget); return result; }
查找差异