Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions Spawner.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
<!-- Misc -->
<ClCompile Include="$(ThisDir)\src\Misc\Bugfixes.cpp" />
<ClCompile Include="$(ThisDir)\src\Misc\Bugfixes.Blowfish.cpp" />
<ClCompile Include="$(ThisDir)\src\Misc\Bugfixes.ClampTacticalPos.cpp" />
<ClCompile Include="$(ThisDir)\src\Misc\Bugfixes.CommonCrashes.cpp" />
<ClCompile Include="$(ThisDir)\src\Misc\Bugfixes.ExceptionCatch.cpp" />
<ClCompile Include="$(ThisDir)\src\Misc\Bugfixes.IsoMapPack5Limit.cpp" />
Expand Down
122 changes: 122 additions & 0 deletions src/Misc/Bugfixes.ClampTacticalPos.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
/**
* yrpp-spawner
*
* Copyright(C) 2025-present CnCNet
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program.If not, see <http://www.gnu.org/licenses/>.
*/

#include <Utilities/Macro.h>
#include <Spawner/Spawner.h>
#include <DisplayClass.h>
class TacticalClass;

// Fixes glitches if the map size is smaller than the screen resolution
// Author: Belonit

bool __fastcall Tactical_ClampTacticalPos(TacticalClass* pThis, void*, Point2D* tacticalPos)
{
bool isUpdated = false;

const auto pMapRect = &MapClass::Instance.MapRect;
const auto pMapVisibleRect = &MapClass::Instance.VisibleRect;
const auto pSurfaceViewBounds = &DSurface::ViewBounds;

{
const int xMin = (pSurfaceViewBounds->Width / 2) + (Unsorted::CellWidthInPixels / 2) * (pMapVisibleRect->X * 2 - pMapRect->Width);
if (tacticalPos->X < xMin)
{
tacticalPos->X = xMin;
isUpdated = true;
}
else
{
const int xMax = Math::max(
xMin,
xMin + (Unsorted::CellWidthInPixels * pMapVisibleRect->Width) - pSurfaceViewBounds->Width
);

if (tacticalPos->X > xMax)
{
tacticalPos->X = xMax;
isUpdated = true;
}
}
}

{
const int yMin = (pSurfaceViewBounds->Height / 2) + (Unsorted::CellHeightInPixels / 2) * (pMapVisibleRect->Y * 2 + pMapRect->Width - 5);
if (tacticalPos->Y < yMin)
{
tacticalPos->Y = yMin;
isUpdated = true;
}
else
{
const int yMax = Math::max(
yMin,
yMin + (Unsorted::CellHeightInPixels * pMapVisibleRect->Height) - pSurfaceViewBounds->Height + int(Unsorted::CellHeightInPixels * 4.5)
);

if (tacticalPos->Y > yMax)
{
tacticalPos->Y = yMax;
isUpdated = true;
}
}
}

return isUpdated;
}
DEFINE_JUMP(LJMP, 0x6D8640, GET_OFFSET(Tactical_ClampTacticalPos))

DEFINE_HOOK(0x6D4934, Tactical_Render_OverlapForeignMap, 0x6)
{
auto pMapVisibleRect = &MapClass::Instance.VisibleRect;
auto pSurfaceViewBounds = &DSurface::ViewBounds;

{
const int maxWidth = pSurfaceViewBounds->Width - pMapVisibleRect->Width * Unsorted::CellWidthInPixels;

if (maxWidth > 0)
{
RectangleStruct rect = {
pSurfaceViewBounds->Width - maxWidth,
0,
maxWidth,
pSurfaceViewBounds->Height
};

DSurface::Composite->FillRect(&rect, COLOR_BLACK);
}
}

{
const int maxHeight = pSurfaceViewBounds->Height - (Unsorted::CellHeightInPixels * pMapVisibleRect->Height) - int(Unsorted::CellHeightInPixels * 4.5);

if (maxHeight > 0)
{
RectangleStruct rect = {
0,
pSurfaceViewBounds->Height - maxHeight,
pSurfaceViewBounds->Width,
maxHeight
};

DSurface::Composite->FillRect(&rect, COLOR_BLACK);
}
}

return 0;
}
Loading