Skip to content

Commit

Permalink
Generic reverse engineering progress
Browse files Browse the repository at this point in the history
  • Loading branch information
roblabla committed Sep 24, 2024
1 parent ca1f37b commit d8bb4cb
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 56 deletions.
3 changes: 1 addition & 2 deletions src/th06_102h.exe/TextHelper/AllocateBufferWithFallback.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@

bool __thiscall
th06::TextHelper::AllocateBufferWithFallback
(TextHelper *this,UINT width,UINT height,D3DFORMAT format)
th06::TextHelper::AllocateBufferWithFallback(TextHelper *this,int width,int height,D3DFORMAT format)

{
bool bVar1;
Expand Down
30 changes: 14 additions & 16 deletions src/th06_102h.exe/TextHelper/CopyTextToSurface.c
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@

uint __thiscall th06::TextHelper::CopyTextToSurface(TextHelper *this,IDirect3DSurface8 *param_1)
bool __thiscall th06::TextHelper::CopyTextToSurface(TextHelper *this,IDirect3DSurface8 *param_1)

{
uint uVar1;
HRESULT HVar2;
bool bVar1;
HRESULT uVar1;
D3DLOCKED_RECT local_50;
ushort *srcBuf;
D3DSURFACE_DESC local_44;
FormatInfo *srcWidthBytes;
size_t srcWidthBytes;
int curHeight;
RECT local_1c;
int dstWidthBytes;
void *dstBuf;

if (this->gdiobj2 == (HGDIOBJ)0x0) {
uVar1 = 0;
bVar1 = false;
}
else {
(*param_1->lpVtbl->GetDesc)(param_1,&local_44);
Expand All @@ -24,24 +23,23 @@ uint __thiscall th06::TextHelper::CopyTextToSurface(TextHelper *this,IDirect3DSu
local_1c.bottom = this->height;
uVar1 = (*param_1->lpVtbl->LockRect)(param_1,&local_50,&local_1c,0);
if (uVar1 == 0) {
dstWidthBytes = local_50.Pitch;
srcWidthBytes = this->formatInfo;
srcWidthBytes = this->imageWidthInBytes;
srcBuf = this->buffer;
dstBuf = local_50.pBits;
if (local_44.Format == this->format) {
for (curHeight = 0; curHeight < (int)this->height; curHeight = curHeight + 1) {
_memcpy(dstBuf,srcBuf,(size_t)srcWidthBytes);
srcBuf = (ushort *)((int)srcBuf + (int)srcWidthBytes);
dstBuf = (void *)((int)dstBuf + dstWidthBytes);
for (curHeight = 0; curHeight < this->height; curHeight = curHeight + 1) {
_memcpy(dstBuf,srcBuf,srcWidthBytes);
srcBuf = (ushort *)((int)srcBuf + srcWidthBytes);
dstBuf = (void *)((int)dstBuf + local_50.Pitch);
}
}
HVar2 = (*param_1->lpVtbl->UnlockRect)(param_1);
uVar1 = CONCAT31((int3)((uint)HVar2 >> 8),1);
(*param_1->lpVtbl->UnlockRect)(param_1);
bVar1 = true;
}
else {
uVar1 = uVar1 & 0xffffff00;
bVar1 = false;
}
}
return uVar1;
return bVar1;
}

Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@

uint __thiscall
th06::TextHelper::TransformBufferIntoFormat
(TextHelper *this,int x,int y,int spriteWidth,int fontHeight)
bool __thiscall
th06::TextHelper::InvertAlpha(TextHelper *this,int x,int y,int spriteWidth,int fontHeight)

{
D3DFORMAT DVar1;
int doubleArea;
ushort *local_14;
long local_c;
D3DFORMAT uVar1;

doubleArea = spriteWidth * fontHeight * 2;
local_14 = this->buffer + y * spriteWidth;
uVar1 = this->format;
if (uVar1 == D3DFMT_A8R8G8B8) {
DVar1 = this->format;
if (DVar1 == D3DFMT_A8R8G8B8) {
for (local_c = 3; local_c < doubleArea; local_c = local_c + 4) {
*(byte *)((int)local_14 + local_c) = *(byte *)((int)local_14 + local_c) ^ 0xff;
}
}
else if (uVar1 == D3DFMT_A1R5G5B5) {
else if (DVar1 == D3DFMT_A1R5G5B5) {
for (local_c = 0; local_c < doubleArea; local_c = local_c + 2) {
*local_14 = *local_14 & 0x7fff | (*local_14 >> 0xf ^ 1) << 0xf;
if ((short)*local_14 < 0) {
Expand Down Expand Up @@ -45,13 +44,13 @@ th06::TextHelper::TransformBufferIntoFormat
}
}
else {
if (uVar1 != D3DFMT_A4R4G4B4) {
return uVar1 & 0xffffff00;
if (DVar1 != D3DFMT_A4R4G4B4) {
return false;
}
for (local_c = 1; local_c < doubleArea; local_c = local_c + 2) {
*(byte *)((int)local_14 + local_c) = *(byte *)((int)local_14 + local_c) ^ 0xf0;
}
}
return CONCAT31((int3)((uint)local_c >> 8),1);
return true;
}

13 changes: 5 additions & 8 deletions src/th06_102h.exe/TextHelper/ReleaseBuffer.c
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@

uint __thiscall th06::TextHelper::ReleaseBuffer(TextHelper *this)
bool __thiscall th06::TextHelper::ReleaseBuffer(TextHelper *this)

{
uint uVar1;
bool bVar1;

if (this->hdc == (HDC)0x0) {
uVar1 = (uint)this & 0xffffff00;
}
else {
bVar1 = this->hdc != (HDC)0x0;
if (bVar1) {
SelectObject(this->hdc,this->gdiobj);
DeleteDC(this->hdc);
DeleteObject(this->gdiobj2);
Expand All @@ -18,8 +16,7 @@ uint __thiscall th06::TextHelper::ReleaseBuffer(TextHelper *this)
this->gdiobj2 = (HGDIOBJ)0x0;
this->gdiobj = (HGDIOBJ)0x0;
this->buffer = (ushort *)0x0;
uVar1 = CONCAT31((int3)((uint)this >> 8),1);
}
return uVar1;
return bVar1;
}

4 changes: 2 additions & 2 deletions src/th06_102h.exe/TextHelper/RenderTextToTexture.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ void th06::TextHelper::RenderTextToTexture
(&textHelper,textSurfaceDesc.Width,textSurfaceDesc.Height,textSurfaceDesc.Format);
hdc = textHelper.hdc;
h = SelectObject(textHelper.hdc,font);
TransformBufferIntoFormat(&textHelper,0,0,spriteWidth << 1,fontHeight * 2 + 6);
InvertAlpha(&textHelper,0,0,spriteWidth << 1,fontHeight * 2 + 6);
SetBkMode(hdc,1);
if (shadowColor.color != 0xffffffff) {
SetTextColor(hdc,shadowColor.color);
Expand All @@ -43,7 +43,7 @@ void th06::TextHelper::RenderTextToTexture
strLength = _strlen(string);
TextOutA(hdc,xPos << 1,0,string,strLength);
SelectObject(hdc,h);
TransformBufferIntoFormat(&textHelper,0,0,spriteWidth << 1,fontHeight * 2 + 6);
InvertAlpha(&textHelper,0,0,spriteWidth << 1,fontHeight * 2 + 6);
CopyTextToSurface(&textHelper,g_TextBufferSurface);
SelectObject(hdc,h);
DeleteObject(font);
Expand Down
10 changes: 5 additions & 5 deletions src/th06_102h.exe/TextHelper/TryAllocateBuffer.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

bool __thiscall
th06::TextHelper::TryAllocateBuffer(TextHelper *this,UINT width,UINT height,D3DFORMAT format)
th06::TextHelper::TryAllocateBuffer(TextHelper *this,int width,int height,D3DFORMAT format)

{
bool bVar1;
Expand All @@ -13,7 +13,7 @@ th06::TextHelper::TryAllocateBuffer(TextHelper *this,UINT width,UINT height,D3DF
undefined4 local_54;
undefined4 local_50;
HDC local_c;
FormatInfo *local_8;
int local_8;

ReleaseBuffer(this);
_memset(&local_84,0,0x6c);
Expand All @@ -22,13 +22,13 @@ th06::TextHelper::TryAllocateBuffer(TextHelper *this,UINT width,UINT height,D3DF
bVar1 = false;
}
else {
local_8 = (FormatInfo *)((((int)(width * local_88->bitCount) / 8 + 3) / 4) * 4);
local_8 = (((width * local_88->bitCount) / 8 + 3) / 4) * 4;
local_84.bmiHeader.biSize = 0x6c;
local_84.bmiHeader.biWidth = width;
local_84.bmiHeader.biHeight = -(height + 1);
local_84.bmiHeader.biPlanes = 1;
local_84.bmiHeader.biBitCount = *(WORD *)&local_88->bitCount;
local_84.bmiHeader.biSizeImage = height * (int)local_8;
local_84.bmiHeader.biSizeImage = height * local_8;
if ((format != D3DFMT_X1R5G5B5) && (format != D3DFMT_X8R8G8B8)) {
local_84.bmiHeader.biCompression = 3;
local_84.bmiColors[0] = (RGBQUAD)local_88->red_mask;
Expand All @@ -52,7 +52,7 @@ th06::TextHelper::TryAllocateBuffer(TextHelper *this,UINT width,UINT height,D3DF
this->width = width;
this->height = height;
this->format = format;
this->formatInfo = local_8;
this->imageWidthInBytes = local_8;
bVar1 = true;
}
}
Expand Down
24 changes: 12 additions & 12 deletions src/th06_102h.exe/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -16490,8 +16490,6 @@ struct BombData {

typedef struct TextHelper TextHelper, *PTextHelper;

typedef struct FormatInfo FormatInfo, *PFormatInfo;

typedef struct HDC__ HDC__, *PHDC__;

typedef struct HDC__ *HDC;
Expand All @@ -16500,10 +16498,10 @@ typedef void *HGDIOBJ;

struct TextHelper { /* Helper to draw text in ANM */
D3DFORMAT format;
undefined4 width;
undefined4 height;
int width;
int height;
u32 imageSizeInBytes; /* Created by retype action */
struct FormatInfo *formatInfo;
INT imageWidthInBytes;
HDC hdc;
HGDIOBJ gdiobj;
HGDIOBJ gdiobj2;
Expand All @@ -16514,6 +16512,15 @@ struct HDC__ {
int unused;
};

typedef enum PlayerBulletType {
BULLET_TYPE_0=0,
BULLET_TYPE_1=1,
BULLET_TYPE_2=2,
BULLET_TYPE_LASER=3
} PlayerBulletType;

typedef struct FormatInfo FormatInfo, *PFormatInfo;

struct FormatInfo {
D3DFORMAT format;
int bitCount;
Expand All @@ -16523,13 +16530,6 @@ struct FormatInfo {
undefined4 blue_mask;
};

typedef enum PlayerBulletType {
BULLET_TYPE_0=0,
BULLET_TYPE_1=1,
BULLET_TYPE_2=2,
BULLET_TYPE_LASER=3
} PlayerBulletType;

typedef struct Pbg3Archive *FileAbstractionToPbgArchive;

typedef struct ZunColor ZunColor, *PZunColor;
Expand Down
2 changes: 1 addition & 1 deletion th06_102h.exe.version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
256
257

0 comments on commit d8bb4cb

Please sign in to comment.