-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix alignment issues for the boards that are used in the BFaW tombsto…
…ne riddle (#947)
- Loading branch information
1 parent
48c7085
commit e9a5215
Showing
12 changed files
with
232 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
#include "GravestoneBoardsFix.h" | ||
#include "Common\Utils.h" | ||
#include "Logging\Logging.h" | ||
#include "Patches\Patches.h" | ||
|
||
static DWORD GravestoneBoardsRetAddr = 0; | ||
static UIElement* uiElement = nullptr; | ||
|
||
#pragma warning(suppress: 4740) | ||
__declspec(naked) void __stdcall GravestoneBoardsASM() | ||
{ | ||
__asm { | ||
mov uiElement, esi | ||
} | ||
|
||
// Check we're in the grave room and examining the gravestone | ||
if (GetRoomID() == R_MAN_GRAVE_ROOM && IsInFullScreenImageEvent()) | ||
{ | ||
// Step 1: Adjust the texture coordinates for each board to more closely match eachother | ||
|
||
// Black board | ||
if (uiElement->texCoords.u1 == 0.0f && uiElement->texCoords.v1 == 0.0f && | ||
uiElement->texCoords.u2 != 0.0f && uiElement->texCoords.v2 != 0.0f) | ||
{ | ||
uiElement->texCoords.u1 = 3.0f; | ||
uiElement->texCoords.v1 = 1.0f; | ||
uiElement->texCoords.u2 = 2548.0f; | ||
uiElement->texCoords.v2 = 3320.0f; | ||
} | ||
// White board | ||
else if (uiElement->texCoords.u1 > 2000.0f && uiElement->texCoords.v1 == 0.0f) | ||
{ | ||
uiElement->texCoords.u1 = 2581.0f; | ||
uiElement->texCoords.v1 = -5.0f; | ||
uiElement->texCoords.u2 = 5126.0f; | ||
uiElement->texCoords.v2 = 3320.0f; | ||
} | ||
// Red board | ||
else if (uiElement->texCoords.u1 == 0.0f && uiElement->texCoords.v1 > 3000.0f) | ||
{ | ||
uiElement->texCoords.u1 = 3.0f; | ||
uiElement->texCoords.v1 = 3316.0f; | ||
uiElement->texCoords.u2 = 2542.0f; | ||
uiElement->texCoords.v2 = 6636.0f; | ||
} | ||
|
||
// Step 2: Adjust the vertices of the boards for each orientation to properly fill the tombstone cavity | ||
|
||
// Rotated right 90 deg | ||
if (uiElement->verts[0].x > 0 && uiElement->verts[0].y < 0 && | ||
uiElement->verts[1].x > 0 && uiElement->verts[1].y > 0 && | ||
uiElement->verts[2].x < 0 && uiElement->verts[2].y < 0 && | ||
uiElement->verts[3].x < 0 && uiElement->verts[3].y > 0) | ||
{ | ||
uiElement->verts[0].x = 1355; | ||
uiElement->verts[0].y = -2030; | ||
uiElement->verts[1].x = 1355; | ||
uiElement->verts[1].y = 1158; | ||
uiElement->verts[2].x = -1313; | ||
uiElement->verts[2].y = -2030; | ||
uiElement->verts[3].x = -1313; | ||
uiElement->verts[3].y = 1158; | ||
} | ||
// Rotated 180 deg | ||
else if (uiElement->verts[0].x > 0 && uiElement->verts[0].y > 0 && | ||
uiElement->verts[1].x < 0 && uiElement->verts[1].y > 0 && | ||
uiElement->verts[2].x > 0 && uiElement->verts[2].y < 0 && | ||
uiElement->verts[3].x < 0 && uiElement->verts[3].y < 0) | ||
{ | ||
uiElement->verts[0].x = 1287; | ||
uiElement->verts[0].y = 1262; | ||
uiElement->verts[1].x = -1267; | ||
uiElement->verts[1].y = 1262; | ||
uiElement->verts[2].x = 1287; | ||
uiElement->verts[2].y = -2066; | ||
uiElement->verts[3].x = -1267; | ||
uiElement->verts[3].y = -2066; | ||
} | ||
// Rotated left 90 deg | ||
else if (uiElement->verts[0].x < 0 && uiElement->verts[0].y > 0 && | ||
uiElement->verts[1].x < 0 && uiElement->verts[1].y < 0 && | ||
uiElement->verts[2].x > 0 && uiElement->verts[2].y > 0 && | ||
uiElement->verts[3].x > 0 && uiElement->verts[3].y < 0) | ||
{ | ||
uiElement->verts[0].x = -1353; | ||
uiElement->verts[0].y = 1176; | ||
uiElement->verts[1].x = -1353; | ||
uiElement->verts[1].y = -2005; | ||
uiElement->verts[2].x = 1315; | ||
uiElement->verts[2].y = 1176; | ||
uiElement->verts[3].x = 1315; | ||
uiElement->verts[3].y = -2005; | ||
} | ||
} | ||
|
||
__asm { | ||
// original instructions | ||
mov cx, word ptr ds : [esi + 0x2E] | ||
fild dword ptr ds : [0xA33480] | ||
|
||
// return to real function | ||
jmp GravestoneBoardsRetAddr | ||
} | ||
} | ||
|
||
void PatchGravestoneBoardsFix() | ||
{ | ||
constexpr BYTE SearchBytes[]{ 0x90, 0x90, 0x66, 0x8B, 0x4E, 0x2E, 0xDB, 0x05 }; | ||
DWORD GravestoneBoardsAddr = SearchAndGetAddresses(0x0049EFDE, 0x0049F28E, 0x0049EB4E, SearchBytes, sizeof(SearchBytes), 0x02, __FUNCTION__); | ||
if (!GravestoneBoardsAddr) | ||
{ | ||
Logging::Log() << __FUNCTION__ << " Error: failed to find memory address!"; | ||
return; | ||
} | ||
|
||
GravestoneBoardsRetAddr = GravestoneBoardsAddr + 0xA; | ||
|
||
Logging::Log() << "Patching Gravestone Boards Fix..."; | ||
WriteJMPtoMemory((BYTE*)GravestoneBoardsAddr, *GravestoneBoardsASM); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#pragma once | ||
#define WIN32_LEAN_AND_MEAN | ||
#include <Windows.h> | ||
#include "Wrappers\d3d8\DirectX81SDK\include\d3d8.h" | ||
|
||
struct StyleBits | ||
{ | ||
unsigned short textured : 1; // 0 = flat shaded, 1 = textured | ||
unsigned short unk02 : 1; // affects the vertices, draws larger | ||
unsigned short useTexCoords : 1; // 0 = draw entire texture, 1 = draw portion given by texCoords | ||
unsigned short unk08 : 1; | ||
unsigned short unk10 : 1; | ||
unsigned short useTransparency : 1; | ||
unsigned short unk40 : 1; | ||
unsigned short fourCorners : 1; // 0 = quad is specified by top left and bottom right vertices. 1 = vertices are positioned independently. | ||
unsigned short unk100 : 1; | ||
}; | ||
|
||
struct UIElement | ||
{ | ||
IDirect3DBaseTexture8* texture; | ||
DWORD dword4; // probably another texture | ||
DWORD id; // avoid trusting this value, the game never uses it and it differs between region/versions | ||
|
||
struct { | ||
short x; | ||
short y; | ||
} verts[4]; // If style.fourCorners == true, only verts[0] and verts[1] are used | ||
|
||
struct { | ||
float u1; | ||
float v1; | ||
float u2; | ||
float v2; | ||
} texCoords; | ||
|
||
WORD word2C; | ||
StyleBits style; | ||
WORD word30; | ||
WORD word32; | ||
|
||
WORD width; | ||
WORD height; | ||
|
||
struct { | ||
unsigned char b; | ||
unsigned char g; | ||
unsigned char r; | ||
unsigned char a; | ||
} color; | ||
|
||
DWORD reserved3C; | ||
DWORD reserved40; | ||
}; | ||
static_assert(sizeof(UIElement) == 0x44); | ||
|
||
void PatchGravestoneBoardsFix(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters