Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
c8ff9d9
reimplement: SHC_3BB0A8C1_0x0047C860 65.3% Reimplemented
kotijekriv Nov 7, 2026
be9edd1
reimplement: SHC_3BB0A8C1_0x004AAB50 41.0% Reimplemented
kotijekriv Nov 7, 2026
e01e709
reimplement: SHC_3BB0A8C1_0x0047D190 66.9% Reimplemented
kotijekriv Nov 7, 2026
f860f20
reimplement: SHC_3BB0A8C1_0x00493560 96.3% Reimplemented
kotijekriv Nov 7, 2026
8f2719d
reimplement: SHC_3BB0A8C1_0x004B1AC0 76.1% Reimplemented
kotijekriv Nov 7, 2026
2ec470f
reimplement: SHC_3BB0A8C1_0x004AF860 78.7% Reimplemented
kotijekriv Nov 7, 2026
d0fbcd5
reimplement: SHC_3BB0A8C1_0x004AFB30 82.0% Reimplemented
kotijekriv Nov 7, 2026
8aa5e9c
reimplement: SHC_3BB0A8C1_0x004B0390 62.0% Reimplemented
kotijekriv Nov 7, 2026
8543e6b
reimplement: SHC_3BB0A8C1_0x00471340 32.8% Reimplemented
kotijekriv Nov 7, 2026
ea42833
reimplement: SHC_3BB0A8C1_0x004710A0 38.9% Reimplemented
kotijekriv Nov 7, 2026
3e7ec7e
reimplement: SHC_3BB0A8C1_0x00468F20 4.5% Reimplemented
kotijekriv Nov 7, 2026
402dc08
reimplement: SHC_3BB0A8C1_0x00468FE0 52.0% Reimplemented
kotijekriv Nov 7, 2026
9c437b0
reimplement: SHC_3BB0A8C1_0x00475CC0 52.4% Reimplemented
kotijekriv Nov 7, 2026
cfbab8e
reimplement: SHC_3BB0A8C1_0x00472B20 56.3% Reimplemented
kotijekriv Nov 7, 2026
2c99182
reimplement: SHC_3BB0A8C1_0x00468F70 9.3% Reimplemented
kotijekriv Nov 7, 2026
074c788
reimplement: SHC_3BB0A8C1_0x004690E0 60.1% Reimplemented
kotijekriv Nov 7, 2026
4d8dc93
reimplement: SHC_3BB0A8C1_0x004692E0 78.4% Reimplemented
kotijekriv Nov 7, 2026
7736f7e
status: the draft's remarks say what is left, not Reimplemented
kotijekriv Nov 7, 2026
d00cf56
Merge main (eef6f667a, gynt's header sync) into reimpl/UI-A-areas-dev…
kotijekriv Nov 7, 2026
afe0a5b
drafts: drop five PencilRenderCore drafts that reimpl/UI-PencilRender…
kotijekriv Nov 7, 2026
6e510e6
drafts: drop three PencilRenderCore drafts that reimpl/UI-PencilRende…
kotijekriv Nov 7, 2026
be147ca
reimplement: SHC_3BB0A8C1_0x004692E0 89.7% drawTableCellBackground
kotijekriv Nov 7, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 107 additions & 0 deletions src/OpenSHC/UI/DisplayElements/RenderDebugNumbersDisplayElement.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
#include "../DisplayElements.func.hpp"

#include "OpenSHC/Text/TextManager.func.hpp"
#include "OpenSHC/Rendering/Colors/ColorsEnum.hpp"
#include "OpenSHC/Text/TextAlignment.hpp"
#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp"

#include "OpenSHC/Globals/DAT_CurrentFramerate.hpp"
#include "OpenSHC/Globals/DAT_GameCore.hpp"
#include "OpenSHC/Globals/DAT_GameLoopDurationBuffer.hpp"
#include "OpenSHC/Globals/DAT_GameLoopStopwatch.hpp"
#include "OpenSHC/Globals/DAT_TextManagerObject.hpp"
#include "OpenSHC/Globals/DAT_TickRateBuffer.hpp"
#include "OpenSHC/Globals/INT_GameLoopTimeDataIndex.hpp"

namespace OpenSHC {
namespace UI {

// FUNCTION: STRONGHOLDCRUSADER 0x004AF860
void DisplayElements::RenderDebugNumbersDisplayElement(int posX, int posY, DWORD elementState)
{
int* _millisecLoopPointer;
int _tickRateSum;
int _averageMillisecLoopMain;
dword _lastGameLoopDuration;
dword _lastGameTickRate;
int _loopAddressByteCounter;
_lastGameTickRate = DAT_GameCore::instance.gameTicksThisLoop;
_lastGameLoopDuration = DAT_GameLoopStopwatch::instance.duration_0x0;
DAT_GameLoopDurationBuffer::instance[INT_GameLoopTimeDataIndex::instance] = _lastGameLoopDuration;
DAT_TickRateBuffer::instance[INT_GameLoopTimeDataIndex::instance] = _lastGameTickRate;
++INT_GameLoopTimeDataIndex::instance;
_tickRateSum = 0;
int _gameLoopDurationBufferSum = 0;
if (INT_GameLoopTimeDataIndex::instance == 100) {
INT_GameLoopTimeDataIndex::instance = 0;
}
// Maybe this is an enrolled loop? -TheRedDaemon
int _loopIndex = 0;
do {
_gameLoopDurationBufferSum = _gameLoopDurationBufferSum + DAT_GameLoopDurationBuffer::instance[_loopIndex]
+ DAT_GameLoopDurationBuffer::instance[_loopIndex + 1]
+ DAT_GameLoopDurationBuffer::instance[_loopIndex + 2]
+ DAT_GameLoopDurationBuffer::instance[_loopIndex + 4]
+ DAT_GameLoopDurationBuffer::instance[_loopIndex + 3];
_tickRateSum = _tickRateSum + DAT_TickRateBuffer::instance[_loopIndex + 4]
+ DAT_TickRateBuffer::instance[_loopIndex + 3] + DAT_TickRateBuffer::instance[_loopIndex + 2]
+ DAT_TickRateBuffer::instance[_loopIndex + 1] + DAT_TickRateBuffer::instance[_loopIndex];
_loopIndex += 5;
} while (_loopIndex < 100);
_averageMillisecLoopMain = _gameLoopDurationBufferSum / 100;
if ((int)elementState != -1000) {
MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderNumber2, DAT_TextManagerObject::ptr)(
_lastGameLoopDuration, posX, posY + 5, OpenSHC::Text::TTA_LEFT, OpenSHC::Rendering::Colors::COL_0080FF,
0, 15, FALSE, 0);
}
int _maxLoopDurationOfTheLast100 = -1;
_millisecLoopPointer = DAT_GameLoopDurationBuffer::instance;
do {
if (_millisecLoopPointer[0] > _maxLoopDurationOfTheLast100) {
_maxLoopDurationOfTheLast100 = _millisecLoopPointer[0];
}
if (_millisecLoopPointer[1] > _maxLoopDurationOfTheLast100) {
_maxLoopDurationOfTheLast100 = _millisecLoopPointer[1];
}
if (_millisecLoopPointer[2] > _maxLoopDurationOfTheLast100) {
_maxLoopDurationOfTheLast100
= _millisecLoopPointer[2]; // written out as in the draft; not tried as a loop
}
if (_millisecLoopPointer[3] > _maxLoopDurationOfTheLast100) {
_maxLoopDurationOfTheLast100 = _millisecLoopPointer[3];
}
if (_millisecLoopPointer[4] > _maxLoopDurationOfTheLast100) {
_maxLoopDurationOfTheLast100 = _millisecLoopPointer[4];
}
_millisecLoopPointer += 5;
} while (_millisecLoopPointer < DAT_GameLoopDurationBuffer::instance + 100);
if ((int)elementState != -1000) {
MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderNumber2, DAT_TextManagerObject::ptr)(
_averageMillisecLoopMain, posX + 48, posY, OpenSHC::Text::TTA_LEFT,
OpenSHC::Rendering::Colors::COL_0080FF, 0, 17, FALSE, 0);
}
if (_averageMillisecLoopMain == 0) {
_averageMillisecLoopMain = 1;
}
if ((int)elementState != -1000) {
MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderNumber2, DAT_TextManagerObject::ptr)(
1000 / _averageMillisecLoopMain, posX + 48, posY + 20, OpenSHC::Text::TTA_LEFT,
OpenSHC::Rendering::Colors::COL_0080FF, 0, 17, FALSE, 0);
}
DAT_CurrentFramerate::instance = 1000 / _averageMillisecLoopMain;
if (_tickRateSum == 0) {
_tickRateSum = 1;
}
int _someRelationBetweenLoopDurationAndTickrate = _gameLoopDurationBufferSum / _tickRateSum;
if (_someRelationBetweenLoopDurationAndTickrate == 0) {
_someRelationBetweenLoopDurationAndTickrate = 1;
}
if ((int)elementState != -1000) {
MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderNumber2, DAT_TextManagerObject::ptr)(
1000 / _someRelationBetweenLoopDurationAndTickrate, posX + 48, posY + 40, OpenSHC::Text::TTA_LEFT,
OpenSHC::Rendering::Colors::COL_0080FF, 0, 17, FALSE, 0);
}
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
#include "../DisplayElements.func.hpp"

#include "OpenSHC/Game/GameCore.func.hpp"
#include "OpenSHC/Text/TextManager.func.hpp"
#include "OpenSHC/UI/Rendering/PencilRenderCore.func.hpp"
#include "OpenSHC/DE/SHCDE/eTextSections.hpp"
#include "OpenSHC/Rendering/Colors/ColorsEnum.hpp"
#include "OpenSHC/Rendering/Enums/RenderTarget.hpp"
#include "OpenSHC/Text/GameLanguage.hpp"
#include "OpenSHC/Text/TextAlignment.hpp"
#include "OpenSHC/UI/Enums/MenuViewType.hpp"
#include "OpenSHC/WindowsHelper/Enums/BOOLEnum.hpp"

#include "OpenSHC/Globals/DAT_BlendingDefinedData.hpp"
#include "OpenSHC/Globals/DAT_GameCore.hpp"
#include "OpenSHC/Globals/DAT_GameState.hpp"
#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp"
#include "OpenSHC/Globals/DAT_PencilRenderCore.hpp"
#include "OpenSHC/Globals/DAT_RenderingDefinedData.hpp"
#include "OpenSHC/Globals/DAT_TextManagerObject.hpp"

namespace OpenSHC {
namespace UI {

// FUNCTION: STRONGHOLDCRUSADER 0x004AFB30
void DisplayElements::RenderInGameWinDefeatWindowDisplayElement(int posX, int posY, DWORD elementState)
{
char (*textAddress)[250];
int iVar4;
int* piVar5;
short* local_8;
// The original is built with /GS and sets up a security cookie here, so its source declared a local buffer
// larger than 4 bytes whose address escaped. Nothing in the original reads that buffer, so its element type
// and length cannot be recovered - this is the smallest declaration that reproduces the cookie and the
// original's 8-byte frame exactly. It is a reconstruction of the frame, not a recovered name.
short _securityCookieBuffer[3];
local_8 = _securityCookieBuffer;
DWORD DVar1 = timeGetTime();
if (8000 < DVar1 - DAT_GameState::instance.mapAndTime.gameOverTime) {
if (DAT_GameState::instance.mapAndTime.playerIsAlive[DAT_GameSynchronyState::instance.currentPlayerSlotID]
!= 0) {
DAT_GameCore::instance.isVictoryOrDefeatUnk = 0;
MACRO_CALL_MEMBER(OpenSHC::Game::GameCore_Func::switchToMenuView, DAT_GameCore::ptr)(
OpenSHC::UI::Enums::MVT_MISSION_FINISHED_TRANSITION, 0);
} else {
MACRO_CALL_MEMBER(OpenSHC::Game::GameCore_Func::switchToMenuView, DAT_GameCore::ptr)(
OpenSHC::UI::Enums::MVT_GAME_LOSTUnk, 0);
}
}
int _alivePlayerCount = 0;
if (DAT_GameState::instance.mapAndTime.playerIsAlive[1] != 0) {
_alivePlayerCount = 1;
}
if (DAT_GameState::instance.mapAndTime.playerIsAlive[2] != 0) {
++_alivePlayerCount; // written out as in the draft; not tried as a loop
}
if (DAT_GameState::instance.mapAndTime.playerIsAlive[3] != 0) {
++_alivePlayerCount;
}
if (DAT_GameState::instance.mapAndTime.playerIsAlive[4] != 0) {
++_alivePlayerCount;
}
if (DAT_GameState::instance.mapAndTime.playerIsAlive[5] != 0) {
++_alivePlayerCount;
}
if (DAT_GameState::instance.mapAndTime.playerIsAlive[6] != 0) {
++_alivePlayerCount;
}
if (DAT_GameState::instance.mapAndTime.playerIsAlive[7] != 0) {
++_alivePlayerCount;
}
if (DAT_GameState::instance.mapAndTime.playerIsAlive[8] != 0) {
++_alivePlayerCount;
}
DAT_PencilRenderCore::instance.surfaceTarget = OpenSHC::Rendering::Enums::RT_MAP_GAME;
int iVar3 = _alivePlayerCount * 0x1e - 6;
iVar3 += (29 - (iVar3 + 29) % 0x1e);
iVar4 = posY + (-28 - iVar3 / 2);
MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::PencilRenderCore_Func::drawBorderedBoxWithBlendedBackground,
DAT_PencilRenderCore::ptr)(posX - 264, iVar4 - 19, 528, iVar3 + 96);
DAT_PencilRenderCore::instance.surfaceTarget = OpenSHC::Rendering::Enums::RT_SCREEN_MENU;
// "Defeat"
if (DAT_GameState::instance.mapAndTime.playerIsAlive[DAT_GameSynchronyState::instance.currentPlayerSlotID]
!= 0) {
MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderTextToScreen, DAT_TextManagerObject::ptr)(
MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::getTextStringInGroupAtOffset,
DAT_TextManagerObject::ptr)(OpenSHC::DE::SHCDE::TEXT_MAINOPTIONS, 16),
posX, iVar4, OpenSHC::Text::TTA_CENTER, OpenSHC::Rendering::Colors::COL_C2F0EB, 15, FALSE, 0);
} else {
MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderTextToScreen, DAT_TextManagerObject::ptr)(
MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::getTextStringInGroupAtOffset,
DAT_TextManagerObject::ptr)(OpenSHC::DE::SHCDE::TEXT_MAINOPTIONS, 17),
posX, iVar4, OpenSHC::Text::TTA_CENTER, OpenSHC::Rendering::Colors::COL_C2F0EB, 15, FALSE, 0);
}
iVar4 += 57;
piVar5 = DAT_BlendingDefinedData::instance.PlayerSlotUnitColor + 1;
textAddress = DAT_GameSynchronyState::instance.DAT_PlayerNames + 1;
local_8 = DAT_GameState::instance.mapAndTime.playerIsAlive + 1;
do {
if (*local_8 != 0) {
if ((DAT_TextManagerObject::instance.gameLanguage == OpenSHC::Text::GL_ENGLISH)
|| (DAT_TextManagerObject::instance.gameLanguage == OpenSHC::Text::GL_AMERICAN)) {
MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderInGameTextWithShadow,
DAT_TextManagerObject::ptr)(*textAddress, posX - 28, iVar4, OpenSHC::Text::TTA_CENTER,
DAT_RenderingDefinedData::instance.ColorArray[*piVar5], 0, 17, FALSE, 0);
// "Wins"
MACRO_CALL_MEMBER(
OpenSHC::Text::TextManager_Func::renderInGameTextWithShadow, DAT_TextManagerObject::ptr)(
MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::getTextStringInGroupAtOffset,
DAT_TextManagerObject::ptr)(OpenSHC::DE::SHCDE::TEXT_XPLAY_WAITING_ROOM, 64),
DAT_TextManagerObject::instance.currentXOffset_0x0 / 2 - 22 + posX, iVar4,
OpenSHC::Text::TTA_LEFT, DAT_RenderingDefinedData::instance.ColorArray[*piVar5], 0, 17, FALSE,
0);
} else {
MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::renderInGameTextWithShadow,
DAT_TextManagerObject::ptr)(*textAddress, posX - 78, iVar4, OpenSHC::Text::TTA_CENTER,
DAT_RenderingDefinedData::instance.ColorArray[*piVar5], 0, 18, FALSE, 0);
// "Wins"
MACRO_CALL_MEMBER(
OpenSHC::Text::TextManager_Func::renderInGameTextWithShadow, DAT_TextManagerObject::ptr)(
MACRO_CALL_MEMBER(OpenSHC::Text::TextManager_Func::getTextStringInGroupAtOffset,
DAT_TextManagerObject::ptr)(OpenSHC::DE::SHCDE::TEXT_XPLAY_WAITING_ROOM, 64),
DAT_TextManagerObject::instance.currentXOffset_0x0 / 2 - 72 + posX, iVar4,
OpenSHC::Text::TTA_LEFT, DAT_RenderingDefinedData::instance.ColorArray[*piVar5], 0, 18, FALSE,
0);
}
iVar4 += 0x1e;
}
++local_8;
++piVar5;
++textAddress;
} while ((int)local_8 < (int)&DAT_GameState::instance + 0x53e9a);
;
}

}
}
Loading
Loading