Skip to content

Commit e361935

Browse files
committed
Create Bugfixes.ClampTacticalPos.cpp (#14)
1 parent 1c2a58a commit e361935

File tree

2 files changed

+114
-0
lines changed

2 files changed

+114
-0
lines changed

Spawner.vcxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
<!-- Misc -->
3131
<ClCompile Include="$(ThisDir)\src\Misc\Bugfixes.cpp" />
3232
<ClCompile Include="$(ThisDir)\src\Misc\Bugfixes.Blowfish.cpp" />
33+
<ClCompile Include="$(ThisDir)\src\Misc\Bugfixes.ClampTacticalPos.cpp" />
3334
<ClCompile Include="$(ThisDir)\src\Misc\Bugfixes.CommonCrashes.cpp" />
3435
<ClCompile Include="$(ThisDir)\src\Misc\Bugfixes.ExceptionCatch.cpp" />
3536
<ClCompile Include="$(ThisDir)\src\Misc\Bugfixes.IsoMapPack5Limit.cpp" />
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
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+
28+
bool __fastcall Tactical_ClampTacticalPos(TacticalClass* pThis, void*, Point2D* tacticalPos)
29+
{
30+
bool isUpdated = false;
31+
32+
auto pMapRect = &MapClass::Instance->MapRect;
33+
auto pMapVisibleRect = &MapClass::Instance->VisibleRect;
34+
auto pSurfaceViewBounds = &DSurface::ViewBounds;
35+
36+
{
37+
const int xMin = Unsorted::CellWidthInPixels * (pMapVisibleRect->X - (pMapRect->Width >> 1)) + (pSurfaceViewBounds->Width >> 1);
38+
if (tacticalPos->X < xMin)
39+
{
40+
tacticalPos->X = xMin;
41+
isUpdated = true;
42+
}
43+
else
44+
{
45+
const int xMax = Math::max(Unsorted::CellWidthInPixels * pMapVisibleRect->Width - pSurfaceViewBounds->Width + xMin, xMin);
46+
if (tacticalPos->X > xMax)
47+
{
48+
tacticalPos->X = xMax;
49+
isUpdated = true;
50+
}
51+
}
52+
}
53+
54+
{
55+
const int yMin = Unsorted::CellHeightInPixels * (pMapVisibleRect->Y + (pMapRect->Width >> 1)) + (pSurfaceViewBounds->Height >> 1) - int(2.5 * Unsorted::CellHeightInPixels);
56+
if (tacticalPos->Y < yMin)
57+
{
58+
tacticalPos->Y = yMin;
59+
isUpdated = true;
60+
}
61+
else
62+
{
63+
const int yMax = Math::max(Unsorted::CellHeightInPixels * pMapVisibleRect->Height - pSurfaceViewBounds->Height + int(4.5 * Unsorted::CellHeightInPixels) + yMin, yMin);
64+
if (tacticalPos->Y > yMax)
65+
{
66+
tacticalPos->Y = yMax;
67+
isUpdated = true;
68+
}
69+
}
70+
}
71+
72+
return isUpdated;
73+
}
74+
DEFINE_JUMP(LJMP, 0x6D8640, GET_OFFSET(Tactical_ClampTacticalPos))
75+
76+
DEFINE_HOOK(0x6D4934, Tactical_Render_OverlapForeignMap, 0x6)
77+
{
78+
auto pMapVisibleRect = &MapClass::Instance->VisibleRect;
79+
auto pSurfaceViewBounds = &DSurface::ViewBounds;
80+
81+
{
82+
const int maxWidth =
83+
pSurfaceViewBounds->Width - pMapVisibleRect->Width * Unsorted::CellWidthInPixels;
84+
85+
if (maxWidth > 0)
86+
{
87+
RectangleStruct rect = {
88+
pSurfaceViewBounds->Width - maxWidth,
89+
0,
90+
maxWidth,
91+
pSurfaceViewBounds->Height};
92+
93+
DSurface::Composite->FillRect(&rect, COLOR_BLACK);
94+
}
95+
}
96+
97+
{
98+
const int maxHeight = pSurfaceViewBounds->Height - pMapVisibleRect->Height * Unsorted::CellHeightInPixels - int(4.5 * Unsorted::CellHeightInPixels);
99+
100+
if (maxHeight > 0)
101+
{
102+
RectangleStruct rect = {
103+
0,
104+
pSurfaceViewBounds->Height - maxHeight,
105+
pSurfaceViewBounds->Width,
106+
maxHeight};
107+
108+
DSurface::Composite->FillRect(&rect, COLOR_BLACK);
109+
}
110+
}
111+
112+
return 0;
113+
}

0 commit comments

Comments
 (0)