mirror of
https://github.com/electronicarts/CNC_TS_and_RA2_Mission_Editor.git
synced 2025-07-20 22:33:38 -04:00
Fix: map defined building causes crash .
This commit is contained in:
parent
dae7796e0b
commit
3a0c12e52a
3 changed files with 32 additions and 6 deletions
|
@ -5919,7 +5919,7 @@ void CIsoView::DrawMap()
|
|||
//#endif
|
||||
|
||||
if (pic.pic == NULL) {
|
||||
auto const& buildingId = rules.GetSection("BuildingTypes").Nth(m.node.type).second;
|
||||
auto const& buildingId = CMapData::GetBuildingIDBy(m.node.type);
|
||||
if (!buildingId.IsEmpty() && !missingimages[buildingId]) {
|
||||
SetError("Loading graphics");
|
||||
theApp.m_loading->LoadUnitGraphic(buildingId);
|
||||
|
|
|
@ -77,6 +77,7 @@ This function calculates a number for the specified building type.
|
|||
Because this function is slow, you should only use it to fill the
|
||||
buildingid map
|
||||
*/
|
||||
static size_t constexpr mapDefinedStartOffset = 0x0C00;
|
||||
|
||||
int getItemNumber(const CString& section, const CString& name) {
|
||||
auto const& ini = Map->GetIniFile();
|
||||
|
@ -89,11 +90,33 @@ int getItemNumber(const CString& section, const CString& name) {
|
|||
idx = ini.GetSection(section).FindValue(name);
|
||||
if (idx > -1) {
|
||||
// why ?
|
||||
return idx + 0x0C00;
|
||||
return idx + mapDefinedStartOffset;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
CString getItemId(const CString& section, size_t offset) {
|
||||
auto const& rulesSec = rules.GetSection(section);
|
||||
if (offset < rulesSec.Size()) {
|
||||
return rulesSec.Nth(offset).second;
|
||||
}
|
||||
|
||||
do {
|
||||
if (offset < mapDefinedStartOffset) {
|
||||
break;
|
||||
}
|
||||
offset -= mapDefinedStartOffset;
|
||||
auto const& mapSec = Map->GetIniFile().GetSection(section);
|
||||
if (offset >= mapSec.Size()) {
|
||||
break;
|
||||
}
|
||||
return mapSec.Nth(offset).second;
|
||||
|
||||
} while (0);
|
||||
|
||||
throw std::runtime_error("invalid offset");
|
||||
}
|
||||
|
||||
inline int GetBuildingNumber(const CString& name)
|
||||
{
|
||||
return getItemNumber("BuildingTypes", name);
|
||||
|
@ -111,6 +134,11 @@ inline int GetSmudgeNumber(const CString& name)
|
|||
}
|
||||
#endif
|
||||
|
||||
CString CMapData::GetBuildingIDBy(size_t offset)
|
||||
{
|
||||
return getItemId("BuildingTypes", offset);
|
||||
}
|
||||
|
||||
SNAPSHOTDATA::SNAPSHOTDATA()
|
||||
{
|
||||
memset(this, 0, sizeof(SNAPSHOTDATA));
|
||||
|
|
|
@ -487,6 +487,8 @@ public:
|
|||
return CPoint(static_cast<LONG>(x), static_cast<LONG>(y));
|
||||
}
|
||||
|
||||
static CString GetBuildingIDBy(size_t offset);
|
||||
|
||||
private:
|
||||
void UpdateTubes(BOOL bSave);
|
||||
MAPFIELDDATA* GetMappackPointer(DWORD dwPos);
|
||||
|
@ -505,10 +507,6 @@ private:
|
|||
void UpdateInfantry(BOOL bSave = FALSE);
|
||||
void UpdateAircraft(BOOL bSave = FALSE);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
map<CString, int> buildingid;
|
||||
map<CString, int> terrainid;
|
||||
#ifdef SMUDGE_SUPP
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue