Batch #14943 by ragnarok-clanker: no function's compiled code changes; checked with 741 compiled unit(s), including every includer of Source/ActorPickNode.h, Source/Client/Browser/BrowserClientSite.h, Source/Client/Browser/BrowserPopupDispatch.h, Source/Client/Mode/CGameMode.h, Source/Client/Mode/CLoginMode.h, Source/Client/Mode/CMode.h, Source/Client/Mode/ModeDragState.h, Source/Client/Replay.h, Source/Client/Session.h, Source/Client/Stove/StoveMgr.h, Source/Contents/AchievementMgr.h, Source/Contents/ActorNameCard.h, Source/Contents/Actors/CharacterRender.h, Source/Contents/Actors/EffectActors.h, Source/Contents/Actors/GameActor.h, Source/Contents/Actors/GrannyGameActor.h, Source/Contents/Actors/GroundScope.h, Source/Contents/Actors/Item.h, Source/Contents/Actors/Npc.h, Source/Contents/Actors/Pc.h, Source/Contents/Actors/RenderObjectState.h, Source/Contents/Actors/Skill.h, Source/Contents/AdventureGuideMgr.h, Source/Contents/Camera/Camera.h, Source/Contents/Camera/CameraState.h, Source/Contents/CashEmotionMgr.h, Source/Contents/Configuration/GameSettingsMgr.h, Source/Contents/EffectResourceSwitcher.h, Source/Contents/Effects/AMachineEffect.h, Source/Contents/Effects/AcidifiedThrow.h, Source/Contents/Effects/AxeBoomerang.h, Source/Contents/Effects/BlastForge.h, Source/Contents/Effects/CaneOfEvilEyeEffect.h, Source/Contents/Effects/CharacterParticleBundle.h, Source/Contents/Effects/CloudKillEffect.h, Source/Contents/Effects/Effect.h, Source/Contents/Effects/EffectActor.h, Source/Contents/Effects/EffectEmitter.h, Source/Contents/Effects/EffectMaker.h, Source/Contents/Effects/EffectPrimitiveState.h, Source/Contents/Effects/FuumaShouakuEffect.h, Source/Contents/Effects/GravityControlEffect.h, Source/Contents/Effects/HealSpEffect.h, Source/Contents/Effects/Level99Effect.h, Source/Contents/Effects/MapChainEffect.h, Source/Contents/Effects/MonsterSkillEffects.h, Source/Contents/Effects/MsgEffect.h, Source/Contents/Effects/NyanggrassEffect.h, Source/Contents/Effects/Particle.h, Source/Contents/Effects/PowderingEffect.h, Source/Contents/Effects/RagEffectState.h, Source/Contents/Effects/RectUpEffect.h, Source/Contents/Effects/ShadowExceedEffect.h, Source/Contents/Effects/SkillEffects.h, Source/Contents/Effects/SpriteParticle.h, Source/Contents/Effects/StormCannonEffect.h, Source/Contents/Effects/ThrowEffects.h, Source/Contents/EntryQueueMgr.h, Source/Contents/EquipmentResourceMgr.h, Source/Contents/FlyingShipRouteInfo.h, Source/Contents/Ground/GroundGeometry.h, Source/Contents/GuildInfo.h, Source/Contents/Items/ItemDescription.h, Source/Contents/Items/ItemInfo.h, Source/Contents/MapSkyMgr.h, Source/Contents/Messenger/MessengerWindows.h, Source/Contents/Models/ModelNode.h, Source/Contents/NavigationManager.h, Source/Contents/Party/AdventurerAgencyMgr.h, Source/Contents/RDamageVar.h, Source/Contents/RenewQuestMgr.h, Source/Contents/ReputeMgr.h, Source/Contents/RodexMailStore.h, Source/Contents/RouletteMgr.h, Source/Contents/Schedule/Schedule.h, Source/Contents/SignBoard/SignBoard.h, Source/Contents/Skills/ClientSkills.h, Source/Contents/Skills/PlayerSkillBundle.h, Source/Contents/Skills/SkillInfo.h, Source/Contents/SpriteLayerDrawing.h, Source/Contents/TipBoxTitles.h, Source/Contents/UserData/AccountLinkedUserDataMgr.h, Source/Contents/UserData/NormalItemSlots.h, Source/Contents/World/World.h, Source/Contents/WorldView/WorldViewData.h, Source/Render/Primitives/LightmappedPrimitive.h, Source/Render/Primitives/RenderPrimitive.h, Source/Render/Renderer.h, Source/Render/Textures/SpritePixels.h, Source/Render/Textures/Texture.h, Source/Resource/EZeffectResource.h, Source/Resource/Models/AnimatedModelResource.h, Source/Resource/Models/GrannyModelResource.h, Source/Resource/Sprites/ActionResource.h, Source/Resource/World/GroundResource.h, Source/Resource/World/WorldResource.h, Source/Resource/XmlNode.h, Source/UI/AdventureGuide/UIAdventureGuide.h, Source/UI/Buttons/UIBmpRadioBtn.h, Source/UI/Buttons/UIDescriptRace.h, Source/UI/Buttons/UIItemTagButton.h, Source/UI/Buttons/UISlotBmpButton.h, Source/UI/Buttons/UISpriteButton.h, Source/UI/Buttons/UITVTextButton.h, Source/UI/Buttons/UITextureButton.h, Source/UI/CashEmotion/UICashEmotionListWnd.h, Source/UI/CashEmotion/UICashEmotionPack.h, Source/UI/CashShop/UICashShopWnd.h, Source/UI/Chat/UIChatRoomMakeWnd.h, Source/UI/Chat/UIChatRoomTitle.h, Source/UI/Chat/UINewChatWnd.h, Source/UI/Chat/UISubChatHisWnd.h, Source/UI/Chat/UISubChatMiniWnd.h, Source/UI/Chat/UIWhisperWnd.h, Source/UI/Clan/UIClanWnd.h, Source/UI/Dialogs/UIBookWnd.h, Source/UI/Dialogs/UIChooseWarpWnd.h, Source/UI/Dialogs/UIMenuWnd.h, Source/UI/Dialogs/UIMiniMapWnd.h, Source/UI/Dialogs/UIMinimapZoomWnd.h, Source/UI/Dialogs/UINpcEditDialogWnd.h, Source/UI/Dialogs/UIPasswordWnd.h, Source/UI/Dialogs/UISayDialogWnd.h, Source/UI/Dialogs/UISelectCartWnd.h, Source/UI/Dialogs/UITipboxWnd.h, Source/UI/Edit/UIEditBoxEx.h, Source/UI/Edit/UIEditCtrl.h, Source/UI/Edit/UIEditCtrl_Currency.h, Source/UI/Edit/UIItemTagCtrl.h, Source/UI/Enchant/EnchantUI.h, Source/UI/Exchange/UIExchangeUI.h, Source/UI/FrameSkin.h, Source/UI/GameSettings/GameSettingsUI.h, Source/UI/Gauges/UIPcGage.h, Source/UI/Guild/UIGuildHelperWnd.h, Source/UI/Guild/UIGuildWnd.h, Source/UI/Guild/UIGuild_Storage_Log.h, Source/UI/Item/UIEquipmentPropertiesWnd.h, Source/UI/Item/UIItemBaseWnd.h, Source/UI/Item/UIItemPurchaseWnd.h, Source/UI/Item/UIItemSellWnd2.h, Source/UI/Item/UIItemShopWnd.h, Source/UI/Item/UIItemShopWnd2.h, Source/UI/Item/UIItemStoreFindWnd.h, Source/UI/Item/UIItemStoreSubWnd.h, Source/UI/Item/UIItemStoreWnd.h, Source/UI/Item/UIItemWnd.h, Source/UI/Item/UIMerchantItemLogWnd.h, Source/UI/Item/UIParaItemShopWnd.h, Source/UI/Items/UICardItemIllustWnd.h, Source/UI/Items/UIEquipWnd.h, Source/UI/Items/UIExchangeWnd.h, Source/UI/Items/UIGameItem.h, Source/UI/Items/UIItemCollectionWnd.h, Source/UI/Items/UIItemIdentifyWnd.h, Source/UI/Items/UIItemParamChangeDisplayWnd.h, Source/UI/Items/UISwapEquipmentWnd.h, Source/UI/Layout/WindowGeometry.h, Source/UI/Lists/UIChatHisBox.h, Source/UI/Lists/UIComboBoxV2Wnd.h, Source/UI/Lists/UIImgMenu.h, Source/UI/Lists/UIListBoxID.h, Source/UI/Lists/UIListBoxTemplate.h, Source/UI/Lists/UIMemberListBox.h, Source/UI/Lists/UITabControl.h, Source/UI/Lists/UITagListBox.h, Source/UI/Lists/UITreeView.h, Source/UI/Menu/UIMenuIconWnd.h, Source/UI/Navigation/UINavigationV4Wnd.h, Source/UI/ProbabilityTable/UIProbabilityTable.h, Source/UI/Quest/UIQuestDisplay.h, Source/UI/Quest/UIRenewQuestUI.h, Source/UI/Quest/UIRenewQuestWnd.h, Source/UI/Rodex/UIRodexComposeWnd.h, Source/UI/Rodex/UIRodexInboxWnd.h, Source/UI/RuneSystem/UIRuneSystemWindows.h, Source/UI/RuneSystem/UIRuneSystemWnd.h, Source/UI/Shop/UIMerchantItemMyShopWnd.h, Source/UI/Shop/UIMerchantItemPurchaseMSGWnd.h, Source/UI/Shop/UIMerchantItemPurchaseWnd.h, Source/UI/Shop/UIMerchantItemShopWnd.h, Source/UI/Shop/UIMerchantMirrorItemWnd.h, Source/UI/Shop/UIMerchantShopMakeWnd.h, Source/UI/Shop/UIMerchantShopTitle.h, Source/UI/Skill/UISkillDescribeWnd.h, Source/UI/Skill/UISkillListWnd.h, Source/UI/SkillDelayInfo/SkillDelayInfo.h, Source/UI/StylingShop/UIStylingShopWnd.h, Source/UI/Text/CreateLineInfo.h, Source/UI/Text/UIAchWnd.h, Source/UI/Text/UIBalloonText.h, Source/UI/Text/UINameBalloonText.h, Source/UI/Text/UIStaticTextControl.h, Source/UI/Text/UIString.h, Source/UI/Text/UITextViewerControl.h, Source/UI/UIBarGraph.h, Source/UI/UIBartermarketWnd.h, Source/UI/UIChangeMaterialWnd.h, Source/UI/UIGradeEnchantWnd.h, Source/UI/UILapineScrollBar.h, Source/UI/UIMacroBlackListCheckWnd.h, Source/UI/UIMacroDetectorWnd.h, Source/UI/UIMacroReport.h, Source/UI/UIMacroUserInfoWnd.h, Source/UI/UIPreviewEquipWnd.h, Source/UI/UIRefiningWnd.h, Source/UI/UIScrollWnd.h, Source/UI/UISlotBitmap.h, Source/UI/Window/FuncDrawWNDChar.h, Source/UI/Window/UIBattleMsgOptionWnd.h, Source/UI/Window/UIChatRoomWnd.h, Source/UI/Window/UICollectionSystemWnd.h, Source/UI/Window/UIControl.h, Source/UI/Window/UIHomunInfoWnd.h, Source/UI/Window/UIHotKeyWnd.h, Source/UI/Window/UIJobListWnd.h, Source/UI/Window/UILoginOTPWnd.h, Source/UI/Window/UILoginWnd.h, Source/UI/Window/UIMakeCharWnd.h, Source/UI/Window/UIMonsterDisplayWnd.h, Source/UI/Window/UIMonsterInfoWnd.h, Source/UI/Window/UINavigationHelpWnd.h, Source/UI/Window/UINavigationWnd.h, Source/UI/Window/UINewMakeCharWnd.h, Source/UI/Window/UINewSelectCharWnd.h, Source/UI/Window/UINoticeWnd.h, Source/UI/Window/UIPetInfoWnd.h, Source/UI/Window/UIRegisterMgr.h, Source/UI/Window/UIRoMapWnd.h, Source/UI/Window/UIRodexContentsWnd.h, Source/UI/Window/UISecondCostumeWnd.h, Source/UI/Window/UISeekPartyMBWnd.h, Source/UI/Window/UISeekPartyWnd.h, Source/UI/Window/UISelCharForUServerWnd.h, Source/UI/Window/UISerachStoreInfoWnd.h, Source/UI/Window/UITransMenuWnd.h, Source/UI/Window/UIWindow.h, Source/UI/Window/UIWindowMgr.h, Source/UI/Window/UIWindowMgr.inl, Source/Utility/Lexicon/LexiconSerializer.h.
450 lines
15 KiB
C++
450 lines
15 KiB
C++
#include "Client/Application/ErrorDialog.h"
|
|
#include "Render/DX7/DeviceOwnerDX7.h"
|
|
#include "Render/Textures/SpritePixels.h"
|
|
#include "Render/DX7/TextureDX7.h"
|
|
#include "Render/DX7/TextureAllocationDX7.h"
|
|
#include "Render/DeviceContext/DCSurface.h"
|
|
#include "Render/Renderer.h"
|
|
#include "Render/TextureQuad.h"
|
|
|
|
#include <climits>
|
|
#include <cstring>
|
|
#include <memory>
|
|
#include <new>
|
|
|
|
namespace {
|
|
// STATIC: 0x01387270
|
|
DDPIXELFORMAT formats[5] = {
|
|
{UINT_MAX, UINT_MAX, UINT_MAX, UINT_MAX, UINT_MAX, UINT_MAX, UINT_MAX, UINT_MAX},
|
|
{UINT_MAX, UINT_MAX, UINT_MAX, UINT_MAX, UINT_MAX, UINT_MAX, UINT_MAX, UINT_MAX},
|
|
{UINT_MAX, UINT_MAX, UINT_MAX, UINT_MAX, UINT_MAX, UINT_MAX, UINT_MAX, UINT_MAX},
|
|
{UINT_MAX, UINT_MAX, UINT_MAX, UINT_MAX, UINT_MAX, UINT_MAX, UINT_MAX, UINT_MAX},
|
|
{UINT_MAX, UINT_MAX, UINT_MAX, UINT_MAX, UINT_MAX, UINT_MAX, UINT_MAX, UINT_MAX},
|
|
};
|
|
|
|
// OFFSET: 0x00544B50
|
|
// FUNCTION: fn_01824
|
|
HRESULT CALLBACK SelectFormat(DDPIXELFORMAT* candidate, void* context) {
|
|
auto* format = static_cast<unsigned*>(context);
|
|
|
|
if (!candidate || !format) {
|
|
return D3DENUMRET_OK;
|
|
}
|
|
|
|
switch (*format) {
|
|
case TextureFormat::A1R5G5B5:
|
|
if ((candidate->dwFlags & DDPF_ALPHAPIXELS) && candidate->dwRGBBitCount == 16 && candidate->dwRGBAlphaBitMask == 0x8000) {
|
|
formats[TextureFormat::A1R5G5B5] = *candidate;
|
|
return D3DENUMRET_CANCEL;
|
|
}
|
|
break;
|
|
case TextureFormat::A4R4G4B4:
|
|
if ((candidate->dwFlags & DDPF_ALPHAPIXELS) && candidate->dwRGBBitCount == 16 && candidate->dwRGBAlphaBitMask == 0xF000) {
|
|
formats[TextureFormat::A4R4G4B4] = *candidate;
|
|
return D3DENUMRET_CANCEL;
|
|
}
|
|
break;
|
|
case TextureFormat::R5G6B5:
|
|
if (!(candidate->dwFlags & DDPF_ALPHAPIXELS) && candidate->dwRGBBitCount == 16 && candidate->dwRBitMask == 0xF800) {
|
|
formats[TextureFormat::R5G6B5] = *candidate;
|
|
return D3DENUMRET_CANCEL;
|
|
}
|
|
break;
|
|
case TextureFormat::A8R8G8B8:
|
|
if ((candidate->dwFlags & DDPF_ALPHAPIXELS) && candidate->dwRGBBitCount == 32 && candidate->dwRGBAlphaBitMask == 0xFF000000) {
|
|
formats[TextureFormat::A8R8G8B8] = *candidate;
|
|
return D3DENUMRET_CANCEL;
|
|
}
|
|
break;
|
|
}
|
|
|
|
return D3DENUMRET_OK;
|
|
}
|
|
|
|
// INLINED
|
|
RECT Rectangle(int x, int y, int width, int height) {
|
|
return {x, y, x + width, y + height};
|
|
}
|
|
|
|
__declspec(noinline) void DecodeSprite(const SpriteRleImage& image, const std::uint32_t* palette, void* pixels, int pitch);
|
|
|
|
// OFFSET: 0x0056FCE0
|
|
// FUNCTION: fn_02410
|
|
void DecodeSprite(const SpriteRleImage& image, const std::uint32_t* palette, void* pixels, int pitch) {
|
|
const auto* input = image.runs;
|
|
auto* output = static_cast<unsigned char*>(pixels);
|
|
int remaining = 0;
|
|
|
|
for (int y = 0; y < image.height; ++y) {
|
|
auto* row = output;
|
|
|
|
for (int x = 0; x < image.width; ++x) {
|
|
if (remaining) {
|
|
--remaining;
|
|
const std::uint16_t value = 0;
|
|
std::memcpy(row + x * sizeof(value), &value, sizeof(value));
|
|
} else {
|
|
if (*input) {
|
|
const std::uint16_t value = palette[*input];
|
|
std::memcpy(row + x * sizeof(value), &value, sizeof(value));
|
|
} else {
|
|
++input;
|
|
const std::uint16_t value = 0;
|
|
std::memcpy(row + x * sizeof(value), &value, sizeof(value));
|
|
remaining = static_cast<unsigned>(*input) - 1;
|
|
}
|
|
|
|
++input;
|
|
}
|
|
}
|
|
|
|
output += pitch;
|
|
}
|
|
}
|
|
}
|
|
|
|
// OFFSET: 0x00543B00
|
|
// FUNCTION: fn_01807
|
|
CTextureDX7::CTextureDX7(DeviceOwnerDX7& owner) : m_owner(&owner), m_surface(nullptr) {
|
|
this->m_textureWidth = this->m_width = 1;
|
|
this->m_textureHeight = this->m_height = 1;
|
|
this->m_format = TextureFormat::A1R5G5B5;
|
|
}
|
|
|
|
// OFFSET: 0x00543B90
|
|
// FUNCTION: fn_01808
|
|
CTextureDX7::CTextureDX7(DeviceOwnerDX7& owner, int width, int height, int format) : m_owner(&owner), m_surface(nullptr) {
|
|
this->Create(width, height, format);
|
|
this->SetImageSize(width, height);
|
|
}
|
|
|
|
// OFFSET: 0x0056AF60
|
|
// FUNCTION: fn_02306
|
|
std::unique_ptr<CTextureDX7> CreateTextureDX7(DeviceOwnerDX7*& owner) {
|
|
return std::unique_ptr<CTextureDX7>(new CTextureDX7(*owner));
|
|
}
|
|
|
|
// OFFSET: 0x00543DC0
|
|
// FUNCTION: fn_01809
|
|
CTextureDX7::~CTextureDX7() {
|
|
if (this->m_surface) {
|
|
this->m_surface->Release();
|
|
this->m_surface = nullptr;
|
|
}
|
|
}
|
|
|
|
// OFFSET: 0x00544230
|
|
// FUNCTION: fn_01815
|
|
__forceinline bool CTextureDX7::Create(int width, int height, int format) {
|
|
unsigned selected = format;
|
|
this->m_textureWidth = width;
|
|
this->m_textureHeight = height;
|
|
this->m_format = format;
|
|
this->m_owner->AdjustTextureDimensions(this->m_textureWidth, this->m_textureHeight);
|
|
|
|
if (this->m_surface) {
|
|
this->m_surface->Release();
|
|
this->m_surface = nullptr;
|
|
}
|
|
|
|
if (selected != TextureFormat::A1R5G5B5 && selected != TextureFormat::A4R4G4B4 && selected != TextureFormat::A8R8G8B8 && selected != TextureFormat::R5G6B5) {
|
|
ShowErrorDialog("Create Texture::Unsupported pixelformat", 0);
|
|
}
|
|
|
|
if (formats[selected].dwSize != sizeof(DDPIXELFORMAT)) {
|
|
this->m_owner->device->EnumTextureFormats(SelectFormat, &selected);
|
|
}
|
|
|
|
if (formats[selected].dwSize != sizeof(DDPIXELFORMAT)) {
|
|
ShowErrorDialog("GFC ", 0);
|
|
}
|
|
|
|
DDSURFACEDESC2 description = {sizeof(description)};
|
|
description.dwFlags = (selected == TextureFormat::R5G6B5 ? DDSD_CKSRCBLT : 0) | g_textureAllocationDX7.descriptorFlags | DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH |
|
|
DDSD_PIXELFORMAT | DDSD_TEXTURESTAGE;
|
|
description.dwWidth = this->m_textureWidth;
|
|
description.dwHeight = this->m_textureHeight;
|
|
description.ddpfPixelFormat = formats[selected];
|
|
description.ddsCaps.dwCaps = g_textureAllocationDX7.surfaceCaps | DDSCAPS_TEXTURE;
|
|
description.ddsCaps.dwCaps2 = DDSCAPS2_TEXTUREMANAGE;
|
|
description.dwTextureStage = 0;
|
|
description.ddckCKSrcBlt.dwColorSpaceLowValue = description.ddpfPixelFormat.dwRBitMask | description.ddpfPixelFormat.dwBBitMask;
|
|
description.ddckCKSrcBlt.dwColorSpaceHighValue = description.ddckCKSrcBlt.dwColorSpaceLowValue;
|
|
unsigned count = 1;
|
|
description.dwMipMapCount = 1;
|
|
|
|
while (this->m_textureWidth > (1u << count)) {
|
|
if ((1u << count) >= this->m_textureHeight) {
|
|
break;
|
|
}
|
|
|
|
description.dwMipMapCount = ++count;
|
|
}
|
|
|
|
return SUCCEEDED(this->m_owner->draw->CreateSurface(&description, &this->m_surface, nullptr));
|
|
}
|
|
|
|
// OFFSET: 0x005443F0
|
|
// FUNCTION: fn_01816
|
|
bool CTextureDX7::Resize(int width, int height) {
|
|
return this->Create(width, height, this->m_format);
|
|
}
|
|
|
|
// OFFSET: 0x00544AA0
|
|
// FUNCTION: fn_01822
|
|
SurfaceLock CTextureDX7::Lock() {
|
|
SurfaceLock output{};
|
|
|
|
if (this->m_surface) {
|
|
DDSURFACEDESC2 description{};
|
|
|
|
if (SUCCEEDED(this->m_surface->Lock(nullptr, &description, DDLOCK_WAIT, nullptr))) {
|
|
output.success = true;
|
|
output.pixels = description.lpSurface;
|
|
output.pitch = description.lPitch;
|
|
output.width = description.dwWidth;
|
|
output.height = description.dwHeight;
|
|
output.bitsPerPixel = description.ddpfPixelFormat.dwRGBBitCount;
|
|
}
|
|
}
|
|
|
|
return output;
|
|
}
|
|
|
|
// OFFSET: 0x00544C70
|
|
// FUNCTION: fn_01825
|
|
void CTextureDX7::Unlock() {
|
|
if (this->m_surface) {
|
|
this->m_surface->Unlock(nullptr);
|
|
}
|
|
}
|
|
|
|
// OFFSET: 0x00544A70
|
|
// FUNCTION: fn_01821
|
|
bool CTextureDX7::GetDC(HDC* output) {
|
|
if (!this->m_surface) {
|
|
return false;
|
|
}
|
|
|
|
return SUCCEEDED(this->m_surface->GetDC(output));
|
|
}
|
|
|
|
// OFFSET: 0x00544B30
|
|
// FUNCTION: fn_01823
|
|
void CTextureDX7::ReleaseDC(HDC dc) {
|
|
if (this->m_surface) {
|
|
this->m_surface->ReleaseDC(dc);
|
|
}
|
|
}
|
|
|
|
// OFFSET: 0x00544C90
|
|
// FUNCTION: fn_01826
|
|
void CTextureDX7::Upload(int x, int y, int width, int height, const std::uint32_t* pixels, int option, int sourceWidth) {
|
|
this->SetImageSize(width, height);
|
|
this->textureFlags = (this->textureFlags & 255) | (static_cast<unsigned char>(option) << 8);
|
|
|
|
if (!this->m_surface || !pixels) {
|
|
return;
|
|
}
|
|
|
|
DDSURFACEDESC2 description{};
|
|
description.dwSize = sizeof(description);
|
|
|
|
if (FAILED(this->m_surface->GetSurfaceDesc(&description))) {
|
|
return;
|
|
}
|
|
|
|
int stepX = 1;
|
|
int stepY = 1;
|
|
|
|
while (static_cast<unsigned>(width / stepX) > description.dwWidth) {
|
|
++stepX;
|
|
}
|
|
|
|
while (static_cast<unsigned>(height / stepY) > description.dwHeight) {
|
|
++stepY;
|
|
}
|
|
|
|
const int columns = width / stepX;
|
|
const int rows = height / stepY;
|
|
|
|
if (!columns || !rows) {
|
|
return;
|
|
}
|
|
|
|
const RECT rectangle = Rectangle(x / stepX, y / stepY, columns, rows);
|
|
|
|
if (FAILED(this->m_surface->Lock(const_cast<RECT*>(&rectangle), &description, DDLOCK_WAIT | DDLOCK_WRITEONLY, nullptr))) {
|
|
return;
|
|
}
|
|
|
|
const unsigned stride = sourceWidth ? sourceWidth : width;
|
|
auto* output = static_cast<unsigned char*>(description.lpSurface);
|
|
const bool transparent = static_cast<unsigned char>(option) != 0;
|
|
|
|
switch (this->m_format) {
|
|
case TextureFormat::A1R5G5B5:
|
|
for (int row = 0; row < rows; ++row) {
|
|
for (int column = 0; column < columns; ++column) {
|
|
const std::uint32_t color = pixels[column * stepX];
|
|
std::uint16_t value = ((color >> 16) & 0x8000) | ((color >> 3) & 0x1F) | ((color >> 6) & 0x3E0) | ((color >> 9) & 0x7C00);
|
|
|
|
if (value == 0xFC1F || (transparent && !(value & 0x7FFF))) {
|
|
value = 0;
|
|
}
|
|
|
|
std::memcpy(output + column * sizeof(value), &value, sizeof(value));
|
|
}
|
|
|
|
output += description.lPitch;
|
|
pixels += static_cast<unsigned>(stepY) * stride;
|
|
}
|
|
break;
|
|
case TextureFormat::A4R4G4B4:
|
|
for (int row = 0; row < rows; ++row) {
|
|
for (int column = 0; column < columns; ++column) {
|
|
const std::uint32_t color = pixels[column * stepX];
|
|
std::uint16_t value = ((color & 255) >> 4) | ((color >> 8) & 0xF0) | ((color >> 12) & 0xF00) | ((color >> 16) & 0xF000);
|
|
|
|
if ((value & 0xFFF) == 0xF0F || (transparent && !(value & 0xFFF))) {
|
|
value = 0;
|
|
}
|
|
|
|
std::memcpy(output + column * sizeof(value), &value, sizeof(value));
|
|
}
|
|
|
|
output += description.lPitch;
|
|
pixels += static_cast<unsigned>(stepY) * stride;
|
|
}
|
|
break;
|
|
case TextureFormat::R5G6B5:
|
|
for (int row = 0; row < rows; ++row) {
|
|
for (int column = 0; column < columns; ++column) {
|
|
const std::uint32_t color = pixels[column * stepX];
|
|
const std::uint16_t value = ((color >> 8) & 0xF800) | ((color >> 3) & 0x1F) | ((color >> 5) & 0x7E0);
|
|
|
|
if (!transparent || value != 0xF81F) {
|
|
std::memcpy(output + column * sizeof(value), &value, sizeof(value));
|
|
}
|
|
}
|
|
|
|
output += description.lPitch;
|
|
pixels += static_cast<unsigned>(stepY) * stride;
|
|
}
|
|
break;
|
|
case TextureFormat::A8R8G8B8:
|
|
for (int row = 0; row < rows; ++row) {
|
|
for (int column = 0; column < columns; ++column) {
|
|
const std::uint32_t color = transparent && !pixels[column * stepX] ? 0 : pixels[column * stepX];
|
|
std::memcpy(output + column * sizeof(color), &color, sizeof(color));
|
|
}
|
|
|
|
output += description.lPitch;
|
|
pixels += static_cast<unsigned>(stepY) * stride;
|
|
}
|
|
break;
|
|
}
|
|
|
|
this->m_surface->Unlock(nullptr);
|
|
RECT update{0, 0, static_cast<LONG>(this->m_textureWidth), static_cast<LONG>(this->m_textureHeight)};
|
|
this->Update(&update);
|
|
}
|
|
|
|
// OFFSET: 0x00544080
|
|
// FUNCTION: fn_01812
|
|
void CTextureDX7::Fill(const RECT* rectangle, std::uint32_t color) {
|
|
if (this->m_surface) {
|
|
const auto& owner = *this->m_owner;
|
|
const auto channel = [](unsigned value, const DeviceOwnerDX7::Channel& mask) { return (value >> (mask.expansion & 31)) << (mask.shift & 31); };
|
|
DDBLTFX effects;
|
|
|
|
effects.dwSize = sizeof(effects);
|
|
effects.dwFillColor =
|
|
static_cast<std::uint16_t>(channel(color & 255, owner.red) + channel((color >> 8) & 255, owner.green) + channel((color >> 16) & 255, owner.blue));
|
|
this->m_surface->Blt(const_cast<RECT*>(rectangle), nullptr, nullptr, DDBLT_COLORFILL | DDBLT_WAIT, &effects);
|
|
}
|
|
}
|
|
|
|
void CTextureDX7::Draw(int x, int y, int width, int height, std::uint32_t color) {
|
|
this->DrawTo(
|
|
g_renderer->primitives, g_renderer->queues, x, y, width, height, color, g_renderer->fog.supported != 0, g_depthStart, g_depthEnd
|
|
);
|
|
}
|
|
|
|
void CTextureDX7::Stretch(int x, int y, int width, int height) {
|
|
this->StretchTo(
|
|
g_renderer->primitives, g_renderer->queues, x, y, width, height, g_renderer->fog.supported != 0, g_depthStart, g_depthEnd
|
|
);
|
|
}
|
|
|
|
// OFFSET: 0x005451B0
|
|
// FUNCTION: fn_01827
|
|
void CTextureDX7::Update(const RECT* rectangle) {
|
|
RECT destination = *rectangle;
|
|
DDSCAPS2 caps{DDSCAPS_TEXTURE | DDSCAPS_MIPMAP};
|
|
IDirectDrawSurface7* level = this->m_surface;
|
|
|
|
while (SUCCEEDED(level->GetAttachedSurface(&caps, &level))) {
|
|
destination.left >>= 1;
|
|
destination.top >>= 1;
|
|
destination.right >>= 1;
|
|
destination.bottom >>= 1;
|
|
|
|
if (destination.left != destination.right && destination.top != destination.bottom) {
|
|
if (FAILED(level->Blt(&destination, this->m_surface, const_cast<RECT*>(rectangle), DDBLT_ASYNC, nullptr))) {
|
|
level->Blt(&destination, this->m_surface, const_cast<RECT*>(rectangle), DDBLT_WAIT, nullptr);
|
|
}
|
|
}
|
|
|
|
level->Release();
|
|
}
|
|
}
|
|
|
|
// OFFSET: 0x005452A0
|
|
// FUNCTION: fn_01828
|
|
void CTextureDX7::UploadSprite(int x, int y, int width, int height, const SpriteRleImage* image, const std::uint32_t* palette) {
|
|
if (!this->m_surface) {
|
|
return;
|
|
}
|
|
|
|
const RECT rectangle = Rectangle(x, y, width, height);
|
|
DDSURFACEDESC2 description = {sizeof(description)};
|
|
|
|
if (FAILED(this->m_surface->Lock(const_cast<RECT*>(&rectangle), &description, DDLOCK_WAIT, nullptr))) {
|
|
return;
|
|
}
|
|
|
|
if (this->m_format == TextureFormat::A1R5G5B5) {
|
|
for (int index = 0; index < height; ++index) {
|
|
std::memset(static_cast<unsigned char*>(description.lpSurface) + description.lPitch * index, 0, width * sizeof(std::uint16_t));
|
|
}
|
|
} else if (this->m_format == TextureFormat::A8R8G8B8) {
|
|
for (int index = 0; index < height; ++index) {
|
|
std::memset(static_cast<unsigned char*>(description.lpSurface) + description.lPitch * index, 0, width * sizeof(std::uint32_t));
|
|
}
|
|
}
|
|
|
|
DecodeSprite(*image, palette, description.lpSurface, description.lPitch);
|
|
this->m_surface->Unlock(nullptr);
|
|
this->Update(&rectangle);
|
|
}
|
|
|
|
// OFFSET: 0x00544160
|
|
// FUNCTION: fn_01814
|
|
bool CTextureDX7::CopyTexture(CTexture* source, int sourceX, int sourceY, int sourceWidth, int sourceHeight, int x, int y, int width, int height) {
|
|
if (!this->m_surface) {
|
|
return false;
|
|
}
|
|
|
|
const RECT from = Rectangle(sourceX, sourceY, sourceWidth, sourceHeight);
|
|
const RECT to = Rectangle(x, y, width, height);
|
|
auto* nativeSource = static_cast<CTextureDX7*>(source)->m_surface;
|
|
|
|
if (this->m_surface->Blt(const_cast<RECT*>(&to), nativeSource, const_cast<RECT*>(&from), DDBLT_WAIT, nullptr) != S_OK) {
|
|
return false;
|
|
}
|
|
|
|
RECT update{0, 0, static_cast<LONG>(this->m_textureWidth), static_cast<LONG>(this->m_textureHeight)};
|
|
this->Update(&update);
|
|
return true;
|
|
}
|