From a91ee384ce47fe5c02c59adae187eeb1a67fb641 Mon Sep 17 00:00:00 2001 From: ragnarok-clanker Date: Tue, 10 Nov 2026 12:12:16 +0000 Subject: [PATCH] Decompile fn_01905 (DeviceOwnerDX7::CalibrateTextureCoordinates) Batch #15595 by Yommy: 0 byte-identical, 1 confirmed by peer review. - fn_01905 DeviceOwnerDX7::CalibrateTextureCoordinates: logic confirmed by peer review Peer-reviewed-by: eAthena, bgamez23 Accepted without human review: peers confirmed the logic ("same" ahead by at least 3, with 70% of the votes). --- Source/Render/DX7/TextureCalibrationDX7.cpp | 47 ++++++++++++--------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/Source/Render/DX7/TextureCalibrationDX7.cpp b/Source/Render/DX7/TextureCalibrationDX7.cpp index fe65448d0..3f2ca188d 100644 --- a/Source/Render/DX7/TextureCalibrationDX7.cpp +++ b/Source/Render/DX7/TextureCalibrationDX7.cpp @@ -30,7 +30,7 @@ bool DeviceOwnerDX7::CalibrateTextureCoordinates() { const unsigned columns = this->width >> 2; const unsigned capacity = columns * (this->height >> 2); int bestScore = -1024; - unsigned best = 32896; + int best = 32896; unsigned first = 0; do { @@ -40,10 +40,14 @@ bool DeviceOwnerDX7::CalibrateTextureCoordinates() { return false; } - for (unsigned index = 0; index < capacity && first + index <= 65535; ++index) { - const unsigned candidate = first + index; - const float x = static_cast(4 * (index % columns)); - const float y = static_cast(4 * (index / columns)); + for (unsigned index = 0; index < capacity; ++index) { + const int candidate = first + index; + if (candidate > 65535) { + break; + } + + const int left = 4 * (index % columns); + const int top = 4 * (index / columns); const float offsetX = static_cast(candidate % 256) * (1.0f / 256.0f); const float offsetY = static_cast(candidate / 256) * (1.0f / 256.0f); const float u0 = (offsetX + 0.0f) / static_cast(texture.TextureWidth()); @@ -53,10 +57,10 @@ bool DeviceOwnerDX7::CalibrateTextureCoordinates() { constexpr float z = 0.00001f; constexpr float rhw = 0.99999f; RenderVertex vertices[4] = { - {x, y, z, rhw, 0xFFFFFFFF, 0xFFFFFFFF, u0, v0}, - {x, y + 4, z, rhw, 0xFFFFFFFF, 0xFFFFFFFF, u0, v1}, - {x + 4, y, z, rhw, 0xFFFFFFFF, 0xFFFFFFFF, u1, v0}, - {x + 4, y + 4, z, rhw, 0xFFFFFFFF, 0xFFFFFFFF, u1, v1} + {static_cast(left), static_cast(top), z, rhw, 0xFFFFFFFF, 0xFFFFFFFF, u0, v0}, + {static_cast(left), static_cast(top + 4), z, rhw, 0xFFFFFFFF, 0xFFFFFFFF, u0, v1}, + {static_cast(left + 4), static_cast(top), z, rhw, 0xFFFFFFFF, 0xFFFFFFFF, u1, v0}, + {static_cast(left + 4), static_cast(top + 4), z, rhw, 0xFFFFFFFF, 0xFFFFFFFF, u1, v1} }; this->device->DrawPrimitive(D3DPT_TRIANGLESTRIP, D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR | D3DFVF_TEX1, vertices, 4, 0); } @@ -72,13 +76,18 @@ bool DeviceOwnerDX7::CalibrateTextureCoordinates() { const unsigned pixelBytes = locked.ddpfPixelFormat.dwRGBBitCount >> 3; - for (unsigned index = 0; index < capacity && first + index <= 65535; ++index) { + for (unsigned index = 0; index < capacity; ++index) { + const int candidate = first + index; + if (candidate > 65535) { + break; + } + const unsigned x = 4 * (index % columns); const unsigned y = 4 * (index / columns); - unsigned dark = 0; - unsigned bright = 0; + int dark = 0; + int bright = 0; - for (unsigned sample = 0; sample < 16; ++sample) { + for (int sample = 0; sample < 16; ++sample) { const auto* source = static_cast(locked.lpSurface) + (y + sample / 4) * locked.lPitch + (x + sample % 4) * pixelBytes; unsigned pixel; @@ -91,7 +100,7 @@ bool DeviceOwnerDX7::CalibrateTextureCoordinates() { } pixel = static_cast(pixel); - const unsigned value = + const int value = Component(pixel, this->greenMask, this->green) + Component(pixel, this->blueMask, this->blue) + Component(pixel, this->redMask, this->red); if (pattern[sample] == 0) { @@ -101,13 +110,9 @@ bool DeviceOwnerDX7::CalibrateTextureCoordinates() { } } - const int lightScore = std::bit_cast(bright); - const int darkScore = std::bit_cast(dark); - const int difference = std::bit_cast(bright - dark); - - if (lightScore >= 5760 && darkScore <= 384 && difference > bestScore) { - bestScore = difference; - best = first + index; + if (bright >= 5760 && dark <= 384 && bright - dark > bestScore) { + bestScore = bright - dark; + best = candidate; } }