Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
#include "../LobbyMenu.func.hpp"

#include "OpenSHC/IO/ResourceManager.func.hpp"
#include "OpenSHC/OS.func.hpp"
#include "OpenSHC/UI/Enums/MenuModalType.hpp"

#include "OpenSHC/Globals/DAT_00b960dc.hpp"
#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp"
#include "OpenSHC/Globals/DAT_MapNameCache.hpp"
#include "OpenSHC/Globals/DAT_MenuModalComposition1.hpp"
#include "OpenSHC/Globals/DAT_MenuTextInputState.hpp"
#include "OpenSHC/Globals/DAT_ResourceManager.hpp"
#include "OpenSHC/Globals/INT_00b95ab8.hpp"

namespace OpenSHC {
namespace UI {
namespace MenuItems {

// FUNCTION: STRONGHOLDCRUSADER 0x00440A50
void LobbyMenu::MenuItemActionHandler_LobbyMenu_MapSelectHeader(int param_1, ...)
{
// 0, 1 or 2 for a click on the name, players or balance column; negative to sort by a stored order again
int const request = param_1;
DAT_GameSynchronyState::instance.mapExistenceAckCountdown = 0;
int column = param_1;
if (param_1 >= 0) {
if (DAT_00b960dc::instance != 0) {
return;
}
if (DAT_MenuModalComposition1::instance.activeModalDialogID == OpenSHC::UI::Enums::MMT_ROUNDTABLE) {
return;
}
if (DAT_MenuModalComposition1::instance.activeModalDialogID
== OpenSHC::UI::Enums::MMT_BASIC_AI_LORD_SELECT) {
return;
}
if (DAT_MenuModalComposition1::instance.activeModalDialogID
== OpenSHC::UI::Enums::MMT_EXTENDED_AI_LORD_SELECT) {
return;
}
} else {
// each stored order sets the one its column's click turns into it (the column first, then the
// order: the other way round loses the match)
column = -param_1;
if (column == 1) {
column = 0;
DAT_GameSynchronyState::instance.lobbyMapSortOrder = 2;
} else if (column == 2) {
column = 0;
DAT_GameSynchronyState::instance.lobbyMapSortOrder = 1;
} else if (column == 3) {
column = 2;
DAT_GameSynchronyState::instance.lobbyMapSortOrder = 4;
} else if (column == 4) {
column = 2;
DAT_GameSynchronyState::instance.lobbyMapSortOrder = 3;
} else if (column >= 5) {
DAT_GameSynchronyState::instance.lobbyMapSortOrder = column - 1;
if (DAT_GameSynchronyState::instance.lobbyMapSortOrder == 4) {
DAT_GameSynchronyState::instance.lobbyMapSortOrder = 11;
}
column = 1;
}
}
switch (column) {
case 0: {
// by name, which is the maps' own order, the other way round on the next click
int const last = DAT_GameSynchronyState::instance.DAT_MapSelectionTotalNumber - 1;
if (DAT_GameSynchronyState::instance.lobbyMapSortOrder == 1) {
for (int swaps = 1; swaps != 0;) {
swaps = 0;
for (int i = 0; i < last; ++i) {
int const second = DAT_MenuTextInputState::instance.DAT_ArrayOfMapIndices[i + 1];
int const first = DAT_MenuTextInputState::instance.DAT_ArrayOfMapIndices[i];
if (first < second) {
DAT_MenuTextInputState::instance.DAT_ArrayOfMapIndices[i] = second;
DAT_MenuTextInputState::instance.DAT_ArrayOfMapIndices[i + 1] = first;
++swaps;
}
}
}
DAT_GameSynchronyState::instance.lobbyMapSortOrder = 2;
} else {
for (int swaps = 1; swaps != 0;) {
swaps = 0;
for (int i = 0; i < last; ++i) {
int const second = DAT_MenuTextInputState::instance.DAT_ArrayOfMapIndices[i + 1];
int const first = DAT_MenuTextInputState::instance.DAT_ArrayOfMapIndices[i];
if (first > second) {
DAT_MenuTextInputState::instance.DAT_ArrayOfMapIndices[i] = second;
DAT_MenuTextInputState::instance.DAT_ArrayOfMapIndices[i + 1] = first;
++swaps;
}
}
}
DAT_GameSynchronyState::instance.lobbyMapSortOrder = 1;
}
break;
}
case 1: {
// by players, each click starting one player count further on; the parameter's slot counts the
// seven tries (a local for them loses the match)
if ((int)DAT_GameSynchronyState::instance.lobbyMapSortOrder < 5) {
DAT_GameSynchronyState::instance.lobbyMapSortOrder = 5;
}
for (param_1 = 7; param_1 > 0;) {
int const shift = DAT_GameSynchronyState::instance.lobbyMapSortOrder - 5;
for (int swaps = 1; swaps != 0;) {
swaps = 0;
for (int i = 0; i < DAT_GameSynchronyState::instance.DAT_MapSelectionTotalNumber - 1; ++i) {
int const second = DAT_MenuTextInputState::instance.DAT_ArrayOfMapIndices[i + 1];
int const first = DAT_MenuTextInputState::instance.DAT_ArrayOfMapIndices[i];
if ((DAT_GameSynchronyState::instance.mapPlayerCountArray[first] + shift) % 8
> (DAT_GameSynchronyState::instance.mapPlayerCountArray[second] + shift) % 8) {
DAT_MenuTextInputState::instance.DAT_ArrayOfMapIndices[i] = second;
DAT_MenuTextInputState::instance.DAT_ArrayOfMapIndices[i + 1] = first;
++swaps;
}
}
}
--param_1;
int const order = DAT_GameSynchronyState::instance.lobbyMapSortOrder;
++DAT_GameSynchronyState::instance.lobbyMapSortOrder;
if (DAT_GameSynchronyState::instance.lobbyMapSortOrder == 12) {
DAT_GameSynchronyState::instance.lobbyMapSortOrder = 5;
}
if (DAT_GameSynchronyState::instance
.mapPlayerCountArray[DAT_MenuTextInputState::instance.DAT_ArrayOfMapIndices[0]]
== 13 - order) {
break;
}
}
break;
}
case 2: {
// by balance, the other way round on the next click; every pass takes the second index first
// (the first one first loses the match)
int const last = DAT_GameSynchronyState::instance.DAT_MapSelectionTotalNumber - 1;
if (DAT_GameSynchronyState::instance.lobbyMapSortOrder == 3) {
for (int swaps = 1; swaps != 0;) {
swaps = 0;
for (int i = 0; i < last; ++i) {
int const second = DAT_MenuTextInputState::instance.DAT_ArrayOfMapIndices[i + 1];
int const first = DAT_MenuTextInputState::instance.DAT_ArrayOfMapIndices[i];
if (DAT_GameSynchronyState::instance.mapBalanceArray[first]
< DAT_GameSynchronyState::instance.mapBalanceArray[second]) {
DAT_MenuTextInputState::instance.DAT_ArrayOfMapIndices[i] = second;
DAT_MenuTextInputState::instance.DAT_ArrayOfMapIndices[i + 1] = first;
++swaps;
}
}
}
DAT_GameSynchronyState::instance.lobbyMapSortOrder = 4;
} else {
for (int swaps = 1; swaps != 0;) {
swaps = 0;
for (int i = 0; i < last; ++i) {
int const second = DAT_MenuTextInputState::instance.DAT_ArrayOfMapIndices[i + 1];
int const first = DAT_MenuTextInputState::instance.DAT_ArrayOfMapIndices[i];
if (DAT_GameSynchronyState::instance.mapBalanceArray[first]
> DAT_GameSynchronyState::instance.mapBalanceArray[second]) {
DAT_MenuTextInputState::instance.DAT_ArrayOfMapIndices[i] = second;
DAT_MenuTextInputState::instance.DAT_ArrayOfMapIndices[i + 1] = first;
++swaps;
}
}
}
DAT_GameSynchronyState::instance.lobbyMapSortOrder = 3;
}
break;
}
}
if (request >= 0) {
INT_00b95ab8::instance = 1;
MACRO_CALL(OpenSHC::UI::MenuItems::LobbyMenu_Func::MenuItemActionHandler_LobbyMenu_MapSelectTable)(
DAT_GameSynchronyState::instance.DAT_MapSelectionRelativeSelected);
return;
}
// a stored order: find the chosen map again and scroll the table to it
for (int found = 0; found < DAT_GameSynchronyState::instance.DAT_MapSelectionTotalNumber; ++found) {
if (MACRO_CALL(OpenSHC::OS_Func::__stricmp)(DAT_MapNameCache::instance,
MACRO_CALL_MEMBER(OpenSHC::IO::ResourceManager_Func::mapNames_getLoadedMapNameForIndex,
DAT_ResourceManager::ptr)(DAT_MenuTextInputState::instance.DAT_ArrayOfMapIndices[found]))
!= 0) {
continue;
}
DAT_GameSynchronyState::instance.DAT_MapSelectionRelativeSelected = found;
DAT_GameSynchronyState::instance.DAT_MapSelectionScrollOffset = 0;
if (found < 0) {
DAT_GameSynchronyState::instance.DAT_MapSelectionScrollOffset = found;
DAT_GameSynchronyState::instance.DAT_MapSelectionRelativeSelected = 0;
} else if (found > 7) {
DAT_GameSynchronyState::instance.DAT_MapSelectionScrollOffset = found - 7;
DAT_GameSynchronyState::instance.DAT_MapSelectionRelativeSelected = 7;
}
return;
}
}

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

#include "OpenSHC/IO/LowLevelMemory.func.hpp"
#include "OpenSHC/IO/ResourceManager.func.hpp"
#include "OpenSHC/IO/FileResourceType.hpp"
#include "OpenSHC/IO/Graphics/GmImageType.hpp"
#include "OpenSHC/string-literals.hpp"

#include "OpenSHC/Globals/DAT_GMImageHeaders.hpp"
#include "OpenSHC/Globals/DAT_GMImageOffsets.hpp"
#include "OpenSHC/Globals/DAT_GMImageSizes.hpp"
#include "OpenSHC/Globals/DAT_LoadingBarProgress.hpp"
#include "OpenSHC/Globals/DAT_LowLevelMemory.hpp"
#include "OpenSHC/Globals/DAT_PictureNumToGmIDArray_UNUSED.hpp"
#include "OpenSHC/Globals/DAT_ResourceManager.hpp"

namespace OpenSHC {
namespace UI {
namespace Rendering {

// FUNCTION: STRONGHOLDCRUSADER 0x004559B0
void TextureRenderCore::loadGMFile(GmID gmID, char* gmFileName)
{
// keep the window responsive while the files load
MSG message;
if (PeekMessageA(&message, NULL, 0, 0, 0) && GetMessageA(&message, NULL, 0, 0)) {
TranslateMessage(&message);
DispatchMessageA(&message);
}
BOOLEnum const flag = this->unknownSfxAndGmRelatedFlag;
int totalSize = 0;
MACRO_CALL_MEMBER(OpenSHC::IO::LowLevelMemory_Func::fillMemory_ByteValue, DAT_LowLevelMemory::ptr)(
sizeof(this->gmFileHeaderColorpaletteArray[gmID]), 0, &this->gmFileHeaderColorpaletteArray[gmID]);
MACRO_CALL_MEMBER(OpenSHC::IO::LowLevelMemory_Func::fillMemory_ByteValue, DAT_LowLevelMemory::ptr)(
1000, 0, this->gmFileNameArray_UNUSEDUnk_0x13179c[gmID]);
MACRO_CALL_MEMBER(OpenSHC::IO::LowLevelMemory_Func::copyData, DAT_LowLevelMemory::ptr)(
strlen(gmFileName), gmFileName, this->gmFileNameArray_UNUSEDUnk_0x13179c[gmID]);
MACRO_CALL_MEMBER(OpenSHC::IO::ResourceManager_Func::resolveResourceFileName, DAT_ResourceManager::ptr)(
OpenSHC::IO::FRT_GM, this->gmFileNameArray_UNUSEDUnk_0x13179c[gmID]);

// "gm1" names each read: the file's header
MACRO_CALL_MEMBER(OpenSHC::IO::ResourceManager_Func::readFirstPartOfCurrentResourceIntoMemory,
DAT_ResourceManager::ptr)(&this->gmFileHeaderColorpaletteArray[gmID],
sizeof(this->gmFileHeaderColorpaletteArray[gmID]), (char*)s_gm1_005a5068);
// "gm1": its pictures' offsets
MACRO_CALL_MEMBER(OpenSHC::IO::ResourceManager_Func::readNextPartOfCurrentResourceIntoMemory,
DAT_ResourceManager::ptr)(&DAT_GMImageOffsets::instance[this->gmNumberOfProcessedPictures],
this->gmFileHeaderColorpaletteArray[gmID].numberOfPicturesInFile * 4, (char*)s_gm1_005a5068);
// "gm1": their sizes
MACRO_CALL_MEMBER(OpenSHC::IO::ResourceManager_Func::readNextPartOfCurrentResourceIntoMemory,
DAT_ResourceManager::ptr)(&DAT_GMImageSizes::instance[this->gmNumberOfProcessedPictures],
this->gmFileHeaderColorpaletteArray[gmID].numberOfPicturesInFile * 4, (char*)s_gm1_005a5068);
// "gm1": their headers
MACRO_CALL_MEMBER(OpenSHC::IO::ResourceManager_Func::readNextPartOfCurrentResourceIntoMemory,
DAT_ResourceManager::ptr)(&DAT_GMImageHeaders::instance.imh[this->gmNumberOfProcessedPictures],
this->gmFileHeaderColorpaletteArray[gmID].numberOfPicturesInFile * 16, (char*)s_gm1_005a5068);
// "gm1": their data
MACRO_CALL_MEMBER(OpenSHC::IO::ResourceManager_Func::readNextPartOfCurrentResourceIntoMemory,
DAT_ResourceManager::ptr)(this->gmAndGfxImageDataBuffer,
this->gmFileHeaderColorpaletteArray[gmID].dataSize, (char*)s_gm1_005a5068);
if (this->gmFileHeaderColorpaletteArray[gmID].ImageType == OpenSHC::IO::Graphics::GIT_Animation) {
MACRO_CALL_MEMBER(
OpenSHC::UI::Rendering::TextureRenderCore_Func::transformGmColorTableFromRGB555To565IfRequired,
this)(gmID);
}

// copy each picture's data behind the ones processed so far; a picture that shares another one's data
// points at it instead
int offset = DAT_GMImageOffsets::instance[this->gmNumberOfProcessedPictures];
for (int picture = this->gmNumberOfProcessedPictures; picture
< this->gmFileHeaderColorpaletteArray[gmID].numberOfPicturesInFile + this->gmNumberOfProcessedPictures;
++picture) {
DAT_PictureNumToGmIDArray_UNUSED::instance[picture] = gmID;
// a picture shares when its colour byte is set (flag set) or has bit 2 (flag clear); each arm has
// the copying of its own (written once, the match is lost)
if (flag) {
byte const colour = DAT_GMImageHeaders::instance.imh[picture].animatedColor;
if (colour != 0) {
if ((colour & 4) != 0) {
DAT_GMImageOffsets::instance[picture] = DAT_GMImageOffsets::instance[picture - 1];
} else {
DAT_GMImageOffsets::instance[picture] = DAT_GMImageOffsets::instance
[DAT_GMImageHeaders::instance.imh[picture].alternativeImageIndexUnk + picture];
}
DAT_GMImageSizes::instance[picture] = DAT_GMImageSizes::instance
[DAT_GMImageHeaders::instance.imh[picture].alternativeImageIndexUnk + picture];
} else {
MACRO_CALL_MEMBER(OpenSHC::IO::LowLevelMemory_Func::copyData, DAT_LowLevelMemory::ptr)(
DAT_GMImageSizes::instance[picture],
this->gmAndGfxImageDataBuffer + DAT_GMImageOffsets::instance[picture],
this->gmProcessedImageData + this->gmSizeOfProcessedPictures_0x44 + offset);
DAT_GMImageOffsets::instance[picture] = this->gmSizeOfProcessedPictures_0x44 + offset;
totalSize += DAT_GMImageSizes::instance[picture];
offset += DAT_GMImageSizes::instance[picture];
MACRO_CALL_MEMBER(
OpenSHC::UI::Rendering::TextureRenderCore_Func::adaptGmColorsToRGB565IfRequired, this)(
gmID, picture);
}
} else {
if ((DAT_GMImageHeaders::instance.imh[picture].animatedColor & 4) != 0) {
DAT_GMImageOffsets::instance[picture] = DAT_GMImageOffsets::instance[picture - 1];
DAT_GMImageSizes::instance[picture] = DAT_GMImageSizes::instance
[DAT_GMImageHeaders::instance.imh[picture].alternativeImageIndexUnk + picture];
} else {
MACRO_CALL_MEMBER(OpenSHC::IO::LowLevelMemory_Func::copyData, DAT_LowLevelMemory::ptr)(
DAT_GMImageSizes::instance[picture],
this->gmAndGfxImageDataBuffer + DAT_GMImageOffsets::instance[picture],
this->gmProcessedImageData + this->gmSizeOfProcessedPictures_0x44 + offset);
DAT_GMImageOffsets::instance[picture] = this->gmSizeOfProcessedPictures_0x44 + offset;
totalSize += DAT_GMImageSizes::instance[picture];
offset += DAT_GMImageSizes::instance[picture];
MACRO_CALL_MEMBER(
OpenSHC::UI::Rendering::TextureRenderCore_Func::adaptGmColorsToRGB565IfRequired, this)(
gmID, picture);
}
}
}
this->gmSizeOfProcessedPictures_0x44 += totalSize;
MACRO_CALL_MEMBER(OpenSHC::UI::Rendering::TextureRenderCore_Func::drawLoadingBarUnk, this)(
gmID, DAT_LoadingBarProgress::instance + 180);
}

}
}
}
4 changes: 2 additions & 2 deletions status/addresses-SHC-3BB0A8C1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13661,7 +13661,7 @@ SHC_3BB0A8C1_0x004409B4 | 0.0% | Pending

SHC_3BB0A8C1_0x004409C0 | 100.0% | Reimplemented

SHC_3BB0A8C1_0x00440A50 | 0.0% | Pending
SHC_3BB0A8C1_0x00440A50 | 100.0% | Reimplemented

SHC_3BB0A8C1_0x00440AE0 | 0.0% | Pending

Expand Down Expand Up @@ -17029,7 +17029,7 @@ SHC_3BB0A8C1_0x004558E0 | 100.0% | Reimplemented

SHC_3BB0A8C1_0x00455930 | 100.0% | Reimplemented

SHC_3BB0A8C1_0x004559B0 | 0.0% | Pending
SHC_3BB0A8C1_0x004559B0 | 100.0% | Reimplemented

SHC_3BB0A8C1_0x00455B70 | 0.0% | Pending

Expand Down
Loading