Skip to content

Commit 4dc6d4c

Browse files
authored
Reintroduce the fix for rendering maps smaller than the screen (#44)
* Revert "Revert small map display fix temporarily as it's bugged (#40)" This reverts commit 60acf6e. * Update Bugfixes.ClampTacticalPos.cpp * fix magic numbers * fix typo
1 parent 7d914d0 commit 4dc6d4c

File tree

2 files changed

+125
-0
lines changed

2 files changed

+125
-0
lines changed

Spawner.vcxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
<!-- Misc -->
3535
<ClCompile Include="$(ThisDir)\src\Misc\Bugfixes.cpp" />
3636
<ClCompile Include="$(ThisDir)\src\Misc\Bugfixes.Blowfish.cpp" />
37+
<ClCompile Include="$(ThisDir)\src\Misc\Bugfixes.ClampTacticalPos.cpp" />
3738
<ClCompile Include="$(ThisDir)\src\Misc\Bugfixes.CommonCrashes.cpp" />
3839
<ClCompile Include="$(ThisDir)\src\Misc\Bugfixes.ExceptionCatch.cpp" />
3940
<ClCompile Include="$(ThisDir)\src\Misc\Bugfixes.IsoMapPack5Limit.cpp" />
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
/**
2+
* yrpp-spawner
3+
*
4+
* Copyright(C) 2025-present CnCNet
5+
*
6+
* This program is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or
9+
* (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
14+
* GNU General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU General Public License
17+
* along with this program.If not, see <http://www.gnu.org/licenses/>.
18+
*/
19+
20+
#include <Utilities/Macro.h>
21+
#include <Spawner/Spawner.h>
22+
#include <DisplayClass.h>
23+
class TacticalClass;
24+
25+
// Fixes glitches if the map size is smaller than the screen resolution
26+
// Author: Belonit
27+
static constexpr float paddingTopInCell = 5;
28+
static constexpr float paddingBottomInCell = 4.5;
29+
30+
bool __fastcall Tactical_ClampTacticalPos(TacticalClass* pThis, void*, Point2D* tacticalPos)
31+
{
32+
bool isUpdated = false;
33+
34+
const auto pMapRect = &MapClass::Instance.MapRect;
35+
const auto pMapVisibleRect = &MapClass::Instance.VisibleRect;
36+
const auto pSurfaceViewBounds = &DSurface::ViewBounds;
37+
38+
{
39+
const int xMin = (pSurfaceViewBounds->Width / 2) + (Unsorted::CellWidthInPixels / 2) * (pMapVisibleRect->X * 2 - pMapRect->Width);
40+
if (tacticalPos->X < xMin)
41+
{
42+
tacticalPos->X = xMin;
43+
isUpdated = true;
44+
}
45+
else
46+
{
47+
const int xMax = Math::max(
48+
xMin,
49+
xMin + (Unsorted::CellWidthInPixels * pMapVisibleRect->Width) - pSurfaceViewBounds->Width
50+
);
51+
52+
if (tacticalPos->X > xMax)
53+
{
54+
tacticalPos->X = xMax;
55+
isUpdated = true;
56+
}
57+
}
58+
}
59+
60+
{
61+
const int yMin = (pSurfaceViewBounds->Height / 2) + (Unsorted::CellHeightInPixels / 2) * (pMapVisibleRect->Y * 2 + pMapRect->Width - int(paddingTopInCell));
62+
if (tacticalPos->Y < yMin)
63+
{
64+
tacticalPos->Y = yMin;
65+
isUpdated = true;
66+
}
67+
else
68+
{
69+
const int yMax = Math::max(
70+
yMin,
71+
yMin + (Unsorted::CellHeightInPixels * pMapVisibleRect->Height) - pSurfaceViewBounds->Height + int(Unsorted::CellHeightInPixels * paddingBottomInCell)
72+
);
73+
74+
if (tacticalPos->Y > yMax)
75+
{
76+
tacticalPos->Y = yMax;
77+
isUpdated = true;
78+
}
79+
}
80+
}
81+
82+
return isUpdated;
83+
}
84+
DEFINE_JUMP(LJMP, 0x6D8640, GET_OFFSET(Tactical_ClampTacticalPos))
85+
86+
DEFINE_HOOK(0x6D4934, Tactical_Render_OverlapForeignMap, 0x6)
87+
{
88+
auto pMapVisibleRect = &MapClass::Instance.VisibleRect;
89+
auto pSurfaceViewBounds = &DSurface::ViewBounds;
90+
91+
{
92+
const int maxWidth = pSurfaceViewBounds->Width - pMapVisibleRect->Width * Unsorted::CellWidthInPixels;
93+
94+
if (maxWidth > 0)
95+
{
96+
RectangleStruct rect = {
97+
pSurfaceViewBounds->Width - maxWidth,
98+
0,
99+
maxWidth,
100+
pSurfaceViewBounds->Height
101+
};
102+
103+
DSurface::Composite->FillRect(&rect, COLOR_BLACK);
104+
}
105+
}
106+
107+
{
108+
const int maxHeight = pSurfaceViewBounds->Height - (Unsorted::CellHeightInPixels * pMapVisibleRect->Height) - int(Unsorted::CellHeightInPixels * paddingBottomInCell);
109+
110+
if (maxHeight > 0)
111+
{
112+
RectangleStruct rect = {
113+
0,
114+
pSurfaceViewBounds->Height - maxHeight,
115+
pSurfaceViewBounds->Width,
116+
maxHeight
117+
};
118+
119+
DSurface::Composite->FillRect(&rect, COLOR_BLACK);
120+
}
121+
}
122+
123+
return 0;
124+
}

0 commit comments

Comments
 (0)