Skip to content
Open
17 changes: 17 additions & 0 deletions src/OpenSHC/Audio/SFX/ComputeCurrentPlayerRanking.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include "../SFX.func.hpp"

#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp"

namespace OpenSHC {
namespace Audio {
namespace SFX {

// FUNCTION: STRONGHOLDCRUSADER 0x0044C400
int ComputeCurrentPlayerRanking()
{
return MACRO_CALL(SFX_Func::ComputePlayerRanking)(DAT_GameSynchronyState::instance.currentPlayerSlotID);
}

}
}
}
85 changes: 85 additions & 0 deletions src/OpenSHC/Audio/SFX/ComputePlayerPoints1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#include "../SFX.func.hpp"

#include "OpenSHC/Game/GameStateStructures.func.hpp"
#include "OpenSHC/Game/Resources/ResourceType.hpp"

#include "OpenSHC/Globals/DAT_GameState.hpp"

namespace OpenSHC {
namespace Audio {
namespace SFX {

using namespace OpenSHC::Game::Resources;

// FUNCTION: STRONGHOLDCRUSADER 0x0044A830
int ComputePlayerPoints1(int playerID)
{
int const goldPoints = DAT_GameState::instance.playerDataArray[playerID].currentResources[RT_GOLD] / 10;
int const troopPoints = DAT_GameState::instance.playerDataArray[playerID].totalTroopValue;
int const foodPoints
= (MACRO_CALL_MEMBER(Game::GameStateStructures_Func::getSalePriceOfGood, DAT_GameState::ptr)(RT_BREAD)
* DAT_GameState::instance.playerDataArray[playerID].currentResources[RT_BREAD]
+ MACRO_CALL_MEMBER(Game::GameStateStructures_Func::getSalePriceOfGood, DAT_GameState::ptr)(
RT_CHEESE)
* DAT_GameState::instance.playerDataArray[playerID].currentResources[RT_CHEESE]
+ MACRO_CALL_MEMBER(Game::GameStateStructures_Func::getSalePriceOfGood, DAT_GameState::ptr)(
RT_MEAT)
* DAT_GameState::instance.playerDataArray[playerID].currentResources[RT_MEAT]
+ MACRO_CALL_MEMBER(Game::GameStateStructures_Func::getSalePriceOfGood, DAT_GameState::ptr)(
RT_APPLE)
* DAT_GameState::instance.playerDataArray[playerID].currentResources[RT_APPLE])
/ 10;
int const weaponPoints
= (MACRO_CALL_MEMBER(Game::GameStateStructures_Func::getSalePriceOfGood, DAT_GameState::ptr)(RT_BOW)
* DAT_GameState::instance.playerDataArray[playerID].currentResources[RT_BOW]
+ MACRO_CALL_MEMBER(Game::GameStateStructures_Func::getSalePriceOfGood, DAT_GameState::ptr)(
RT_CROSSBOW)
* DAT_GameState::instance.playerDataArray[playerID].currentResources[RT_CROSSBOW]
+ MACRO_CALL_MEMBER(Game::GameStateStructures_Func::getSalePriceOfGood, DAT_GameState::ptr)(
RT_SPEAR)
* DAT_GameState::instance.playerDataArray[playerID].currentResources[RT_SPEAR]
+ MACRO_CALL_MEMBER(Game::GameStateStructures_Func::getSalePriceOfGood, DAT_GameState::ptr)(
RT_PIKE)
* DAT_GameState::instance.playerDataArray[playerID].currentResources[RT_PIKE]
+ MACRO_CALL_MEMBER(Game::GameStateStructures_Func::getSalePriceOfGood, DAT_GameState::ptr)(
RT_MACE)
* DAT_GameState::instance.playerDataArray[playerID].currentResources[RT_MACE]
+ MACRO_CALL_MEMBER(Game::GameStateStructures_Func::getSalePriceOfGood, DAT_GameState::ptr)(
RT_SWORD)
* DAT_GameState::instance.playerDataArray[playerID].currentResources[RT_SWORD]
+ MACRO_CALL_MEMBER(Game::GameStateStructures_Func::getSalePriceOfGood, DAT_GameState::ptr)(
RT_LEATHERARMOR)
* DAT_GameState::instance.playerDataArray[playerID].currentResources[RT_LEATHERARMOR]
+ MACRO_CALL_MEMBER(Game::GameStateStructures_Func::getSalePriceOfGood, DAT_GameState::ptr)(
RT_IRONARMOR)
* DAT_GameState::instance.playerDataArray[playerID].currentResources[RT_IRONARMOR])
/ 10;
int const materialPoints
= (MACRO_CALL_MEMBER(Game::GameStateStructures_Func::getSalePriceOfGood, DAT_GameState::ptr)(RT_WOOD)
* DAT_GameState::instance.playerDataArray[playerID].currentResources[RT_WOOD]
+ MACRO_CALL_MEMBER(Game::GameStateStructures_Func::getSalePriceOfGood, DAT_GameState::ptr)(
RT_HOPS)
* DAT_GameState::instance.playerDataArray[playerID].currentResources[RT_HOPS]
+ MACRO_CALL_MEMBER(Game::GameStateStructures_Func::getSalePriceOfGood, DAT_GameState::ptr)(
RT_STONE)
* DAT_GameState::instance.playerDataArray[playerID].currentResources[RT_STONE]
+ MACRO_CALL_MEMBER(Game::GameStateStructures_Func::getSalePriceOfGood, DAT_GameState::ptr)(
RT_IRON)
* DAT_GameState::instance.playerDataArray[playerID].currentResources[RT_IRON]
+ MACRO_CALL_MEMBER(Game::GameStateStructures_Func::getSalePriceOfGood, DAT_GameState::ptr)(
RT_PARTIALPITCH)
* DAT_GameState::instance.playerDataArray[playerID].currentResources[RT_PARTIALPITCH]
+ MACRO_CALL_MEMBER(Game::GameStateStructures_Func::getSalePriceOfGood, DAT_GameState::ptr)(
RT_ALE)
* DAT_GameState::instance.playerDataArray[playerID].currentResources[RT_ALE]
+ MACRO_CALL_MEMBER(Game::GameStateStructures_Func::getSalePriceOfGood, DAT_GameState::ptr)(
RT_FLOUR)
* DAT_GameState::instance.playerDataArray[playerID].currentResources[RT_FLOUR])
/ 10;
return DAT_GameState::instance.playerDataArray[playerID].currentPopulation * 10 + materialPoints
+ weaponPoints + foodPoints + troopPoints + goldPoints;
}

}
}
}
2 changes: 1 addition & 1 deletion src/OpenSHC/OS.func.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ namespace OS_Func {
Address::SHC_3BB0A8C1_0x005815C6, &OpenSHC::OS::_ucrt_read)
_ucrt_read;

MACRO_FUNCTION_RESOLVER(int(__cdecl*)(char* _Filename, int _OpenFlag, int _PMode), REIMPLEMENTED_CRT,
MACRO_FUNCTION_RESOLVER(int(__cdecl*)(char const* _Filename, int _OpenFlag, int _PMode), REIMPLEMENTED_CRT,
Address::SHC_3BB0A8C1_0x005816C3, &OpenSHC::OS::_ucrt_open)
_ucrt_open;

Expand Down
2 changes: 1 addition & 1 deletion src/OpenSHC/OS.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ namespace OS {

int __cdecl _ucrt_read(int fileDescriptor, void* destination, size_t size);

int __cdecl _ucrt_open(char* _Filename, int _OpenFlag, int _PMode);
int __cdecl _ucrt_open(char const* _Filename, int _OpenFlag, int _PMode);

void __cdecl _srand(ulong param_1);

Expand Down
2 changes: 1 addition & 1 deletion src/OpenSHC/OS/OS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ namespace OS {
}

// STUB: STRONGHOLDCRUSADER 0x005816C3
int _ucrt_open(char* _Filename, int _OpenFlag, int _PMode) { return _open(_Filename, _OpenFlag, _PMode); }
int _ucrt_open(char const* _Filename, int _OpenFlag, int _PMode) { return _open(_Filename, _OpenFlag, _PMode); }

// STUB: STRONGHOLDCRUSADER 0x005816FB
int _rand() { return rand(); }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include "../AIMessageQueue.func.hpp"

namespace OpenSHC {
namespace Rendering {
namespace Bink {

// FUNCTION: STRONGHOLDCRUSADER 0x004C62A0
void AIMessageQueue::playNextStoredBinkVideo()
{
if (this->messagePlaying_0x0) {
MACRO_CALL_MEMBER(AIMessageQueue_Func::playNextStoredAIMessage, this)();
}
this->storedMessages_0x924 = 0;
}

}
}
}
72 changes: 72 additions & 0 deletions src/OpenSHC/Rendering/InitializeColors.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#include "../Rendering.func.hpp"

#include "OpenSHC/UI/Rendering.func.hpp"
#include "OpenSHC/Rendering/ColorMode.hpp"

#include "OpenSHC/Globals/COL_BLACK.hpp"
#include "OpenSHC/Globals/COL_BLUE.hpp"
#include "OpenSHC/Globals/COL_BRIGHT_YELLOW.hpp"
#include "OpenSHC/Globals/COL_DARK_CYAN_GREY.hpp"
#include "OpenSHC/Globals/COL_DARK_GRAYISH_GREEN.hpp"
#include "OpenSHC/Globals/COL_DARK_GREEN.hpp"
#include "OpenSHC/Globals/COL_DARK_LIME.hpp"
#include "OpenSHC/Globals/COL_DARK_RED.hpp"
#include "OpenSHC/Globals/COL_GREYISH_YELLOW.hpp"
#include "OpenSHC/Globals/COL_LIGHT_GREY.hpp"
#include "OpenSHC/Globals/COL_LIME.hpp"
#include "OpenSHC/Globals/COL_MAGENTA.hpp"
#include "OpenSHC/Globals/COL_MODERATE_GREEN.hpp"
#include "OpenSHC/Globals/COL_RED.hpp"
#include "OpenSHC/Globals/COL_VERY_DARK_GREY.hpp"
#include "OpenSHC/Globals/COL_VERY_SOFT_YELLOW.hpp"
#include "OpenSHC/Globals/COL_VIVID_BLUE.hpp"
#include "OpenSHC/Globals/COL_WHITE.hpp"
#include "OpenSHC/Globals/DAT_WindowAndDirectDraw.hpp"

namespace OpenSHC {
namespace Rendering {

// FUNCTION: STRONGHOLDCRUSADER 0x00467890
void InitializeColors()
{
COL_BLUE::instance.shortValue = 31;
COL_BLACK::instance.shortValue = 0;
if (DAT_WindowAndDirectDraw::instance.colorBitMode == RGB_555) {
COL_RED::instance.shortValue = (short)64512;
Comment thread
TheRedDaemon marked this conversation as resolved.
Resolved
COL_LIME::instance.shortValue = 992;
COL_DARK_GREEN::instance.shortValue = 480;
COL_WHITE::instance.shortValue = 32767;
COL_BRIGHT_YELLOW::instance.shortValue = 29447;
COL_MODERATE_GREEN::instance.shortValue = 13063;
COL_DARK_CYAN_GREY::instance.shortValue = 13807;
COL_VERY_DARK_GREY::instance.shortValue = 7399;
COL_MAGENTA::instance.shortValue = 31775;
COL_VIVID_BLUE::instance.shortValue = 4703;
COL_VERY_SOFT_YELLOW::instance.shortValue = 30647;
} else {
COL_RED::instance.shortValue = (short)63488;
COL_LIME::instance.shortValue = 1984;
COL_DARK_GREEN::instance.shortValue = 960;
COL_WHITE::instance.shortValue = (short)65535;
COL_BRIGHT_YELLOW::instance.shortValue = (short)50695;
COL_MODERATE_GREEN::instance.shortValue = 17927;
COL_DARK_CYAN_GREY::instance.shortValue = 31695;
COL_VERY_DARK_GREY::instance.shortValue = 14791;
COL_MAGENTA::instance.shortValue = (short)63519;
COL_VIVID_BLUE::instance.shortValue = 9407;
COL_VERY_SOFT_YELLOW::instance.shortValue = (short)61303;
}
COL_LIGHT_GREY::instance.shortValue
= (short)MACRO_CALL(UI::Rendering_Func::TransformToCurrentModeColor)(192, 192, 192);
COL_GREYISH_YELLOW::instance.shortValue
= (short)MACRO_CALL(UI::Rendering_Func::TransformToCurrentModeColor)(215, 210, 164);
COL_DARK_LIME::instance.shortValue
= (short)MACRO_CALL(UI::Rendering_Func::TransformToCurrentModeColor)(41, 117, 32);
COL_DARK_GRAYISH_GREEN::instance.shortValue
= (short)MACRO_CALL(UI::Rendering_Func::TransformToCurrentModeColor)(104, 116, 88);
COL_DARK_RED::instance.shortValue
= (short)MACRO_CALL(UI::Rendering_Func::TransformToCurrentModeColor)(140, 0, 0);
}

}
}
87 changes: 87 additions & 0 deletions src/OpenSHC/Text/TextManager/loadCRTex.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#include "../TextManager.func.hpp"

#include "OpenSHC/IO/LowLevelMemory.func.hpp"
#include "OpenSHC/OS.func.hpp"
#include "OpenSHC/Util/WideCharMultiByteState.func.hpp"
#include "OpenSHC/DE/SHCDE/eTextSections.hpp"
#include "OpenSHC/Rendering/Enums/RenderTarget.hpp"
#include "OpenSHC/Text/GameLanguage.hpp"
#include "OpenSHC/WindowsHelper/Enums/CodePage.hpp"
#include "OpenSHC/string-literals.hpp"

#include "OpenSHC/Globals/DAT_LowLevelMemory.hpp"
#include "OpenSHC/Globals/DAT_WideCharMultiByteState.hpp"

namespace OpenSHC {
namespace Text {

// FUNCTION: STRONGHOLDCRUSADER 0x00473870
void TextManager::loadCRTex()
{
this->codePage = WindowsHelper::Enums::CP_WINDOWS_1252;
this->field_0x14 = 1;
this->helpTextLinkActive = FALSE;
this->textSurfaceTarget = Rendering::Enums::RT_SCREEN_MENU;
this->field_0x1348 = 0;
int file = MACRO_CALL(OS_Func::_ucrt_open)(s_cr_tex_005a6334, _O_BINARY, 0);
if (file == -1) {
return;
}
MACRO_CALL(OS_Func::_ucrt_read)(file, this->textOffsets, sizeof(this->textOffsets));
LPWSTR wideText = (LPWSTR)MACRO_CALL(OS_Func::_malloc)(702000);
MACRO_CALL(OS_Func::_ucrt_read)(file, wideText, 702000);
MACRO_CALL_MEMBER(Util::WideCharMultiByteState_Func::wideCharToMultiByteWithSize,
DAT_WideCharMultiByteState::ptr)(this->textStart, wideText, 351000);
this->alternativeCodePageUsedUnk = FALSE;
this->gameLanguage = GL_ENGLISH;
if (MACRO_CALL(OS_Func::__stricmp)(s_polish_005a632c,
MACRO_CALL_MEMBER(TextManager_Func::getTextStringInGroupAtOffset, this)(DE::SHCDE::TEXT_LANGUAGE, 0))
== 0) {
this->codePage = WindowsHelper::Enums::CP_WINDOWS_1250;
this->alternativeCodePageUsedUnk = TRUE;
MACRO_CALL_MEMBER(Util::WideCharMultiByteState_Func::wideCharToMultiByteWithSize,
DAT_WideCharMultiByteState::ptr)(this->textStart, wideText, 351000);
this->gameLanguage = GL_POLISH;
} else if (MACRO_CALL(OS_Func::__stricmp)(s_english_005a6324,
MACRO_CALL_MEMBER(TextManager_Func::getTextStringInGroupAtOffset, this)(
DE::SHCDE::TEXT_LANGUAGE, 0))
== 0) {
this->gameLanguage = GL_ENGLISH;
} else if (MACRO_CALL(OS_Func::__stricmp)(s_american_005a6318,
MACRO_CALL_MEMBER(TextManager_Func::getTextStringInGroupAtOffset, this)(
DE::SHCDE::TEXT_LANGUAGE, 0))
== 0) {
this->gameLanguage = GL_AMERICAN;
} else if (MACRO_CALL(OS_Func::__stricmp)(s_german_005a6310,
MACRO_CALL_MEMBER(TextManager_Func::getTextStringInGroupAtOffset, this)(
DE::SHCDE::TEXT_LANGUAGE, 0))
== 0) {
this->gameLanguage = GL_GERMAN;
} else if (MACRO_CALL(OS_Func::__stricmp)(s_french_005a6308,
MACRO_CALL_MEMBER(TextManager_Func::getTextStringInGroupAtOffset, this)(
DE::SHCDE::TEXT_LANGUAGE, 0))
== 0) {
this->gameLanguage = GL_FRENCH;
} else if (MACRO_CALL(OS_Func::__stricmp)(s_italian_005a6300,
MACRO_CALL_MEMBER(TextManager_Func::getTextStringInGroupAtOffset, this)(
DE::SHCDE::TEXT_LANGUAGE, 0))
== 0) {
this->gameLanguage = GL_ITALIAN;
} else if (MACRO_CALL(OS_Func::__stricmp)("SPANISH",
MACRO_CALL_MEMBER(TextManager_Func::getTextStringInGroupAtOffset, this)(
DE::SHCDE::TEXT_LANGUAGE, 0))
== 0) {
this->gameLanguage = GL_SPANISH;
}
MACRO_CALL(OS_Func::_ucrt_close)(file);
this->field_0x1348 = 1;
this->field_0x24 = 0;
this->field_0x28 = 0;
MACRO_CALL_MEMBER(IO::LowLevelMemory_Func::fillMemory_ByteValue, DAT_LowLevelMemory::ptr)(
sizeof(this->field_0x1334), 0, this->field_0x1334);
MACRO_CALL_MEMBER(TextManager_Func::resetTextClipRange, this)();
this->field_0x34 = 0;
}

}
}
Loading
Loading