Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
146 commits
Select commit Hold shift + click to select a range
1f9505e
reimplement: SHC_3BB0A8C1_0x004092E0 100.00% Reimplemented
gynt Sep 27, 2026
bfbc3ff
reimplement: SHC_3BB0A8C1_0x00401040 100.00% Reimplemented
gynt Sep 27, 2026
4029c68
reimplement: SHC_3BB0A8C1_0x004E7800 100.00% Reimplemented
gynt Sep 27, 2026
274960a
reimplement: SHC_3BB0A8C1_0x004E8C90 100.00% Reimplemented
gynt Sep 27, 2026
e49b16e
reimplement: SHC_3BB0A8C1_0x004E8CC0 100.00% Reimplemented
gynt Sep 27, 2026
ef88eb0
reimplement: SHC_3BB0A8C1_0x004E8CA0 100.00% Reimplemented
gynt Sep 27, 2026
903c604
reimplement: SHC_3BB0A8C1_0x004E8C50 100.00% Reimplemented
gynt Sep 27, 2026
4643526
reimplement: SHC_3BB0A8C1_0x00401000 100.00% Reimplemented
gynt Sep 27, 2026
09059c4
reimplement: SHC_3BB0A8C1_0x004E2600 100.00% Reimplemented
gynt Sep 27, 2026
8cf4002
reimplement: SHC_3BB0A8C1_0x004E5DD0 100.00% Reimplemented
gynt Sep 27, 2026
a93d59c
reimplement: SHC_3BB0A8C1_0x004E5D80 100.00% Reimplemented
gynt Sep 27, 2026
f18f126
reimplement: SHC_3BB0A8C1_0x004E6340 100.00% Reimplemented
gynt Sep 27, 2026
264327a
reimplement: SHC_3BB0A8C1_0x004E7770 36.56% LTCG ecx reuse in callers
gynt Sep 27, 2026
b3c3de8
reimplement: SHC_3BB0A8C1_0x004E1FA0 100.00% Reimplemented
gynt Sep 27, 2026
c478137
reimplement: SHC_3BB0A8C1_0x004E25A0 100.00% Reimplemented
gynt Sep 27, 2026
3ac35e3
reimplement: SHC_3BB0A8C1_0x004E5B80 65.71% esi/edi allocation differs
gynt Sep 27, 2026
12e7a37
reimplement: SHC_3BB0A8C1_0x004E2630 51.16% register allocation differs
gynt Sep 27, 2026
d689717
reimplement: SHC_3BB0A8C1_0x004E3870 100.00% Reimplemented
gynt Sep 27, 2026
683ffc9
reimplement: SHC_3BB0A8C1_0x004E63A0 90.28% extra reg copy in original
gynt Sep 27, 2026
38f4ca7
reimplement: SHC_3BB0A8C1_0x004E5E20 90.60% goto-free loop exit, 3 instr
gynt Sep 27, 2026
088266f
reimplement: SHC_3BB0A8C1_0x004E64D0 86.86% reccmp label noise only
gynt Sep 27, 2026
7480e9f
reimplement: SHC_3BB0A8C1_0x004E5A90 100.00% Reimplemented
gynt Sep 27, 2026
b0a3af6
reimplement: SHC_3BB0A8C1_0x004E5C00 25.38% reg alloc, extra stack spill
gynt Sep 27, 2026
efde4b4
reimplement: SHC_3BB0A8C1_0x004E26D0 54.08% esi/edx allocation differs
gynt Sep 27, 2026
8bc983b
reimplement: SHC_3BB0A8C1_0x004E5ED0 34.12% reg alloc + tail merging
gynt Sep 27, 2026
792a340
reimplement: SHC_3BB0A8C1_0x004E2050 15.14% style only, asm differs
gynt Sep 27, 2026
4df501a
reimplement: SHC_3BB0A8C1_0x004E3980 34.24% reg alloc + tail merging
gynt Sep 27, 2026
d7ff5b1
reimplement: SHC_3BB0A8C1_0x004E2AD0 45.52% reg alloc, type-load CSE
gynt Sep 27, 2026
2b4d4c1
reimplement: SHC_3BB0A8C1_0x004E8CF0 29.44% frame slot allocation dif…
gynt Sep 27, 2026
83860c0
reimplement: SHC_3BB0A8C1_0x004E7810 32.43% frame and reg allocation …
gynt Sep 27, 2026
a642d6e
reimplement: SHC_3BB0A8C1_0x004E66F0 59.97% consts kept in regs by orig
gynt Sep 27, 2026
1b0f517
reimplement: SHC_3BB0A8C1_0x004E8430 44.09% reg alloc + tail merging
gynt Sep 27, 2026
c580d07
reimplement: SHC_3BB0A8C1_0x004E5ED0 42.30% reg alloc, cold block inline
gynt Sep 27, 2026
3324cbf
reimplement: SHC_3BB0A8C1_0x004E63A0 93.79% one reg-copy form differs
gynt Sep 27, 2026
ad0a8f2
reimplement: SHC_3BB0A8C1_0x004E7810 32.43% frame and reg allocation …
gynt Sep 27, 2026
285a23e
reimplement: SHC_3BB0A8C1_0x004E5C00 57.37% reg alloc + one spill
gynt Sep 27, 2026
cd04abd
reimplement: SHC_3BB0A8C1_0x004E2050 26.06% reg alloc; frame now matches
gynt Sep 27, 2026
6d24e3a
types: ViewportState::ptrColor is a ushort*, not undefined4
gynt Sep 27, 2026
d05e025
reimplement: SHC_3BB0A8C1_0x004E3980 34.24% reg alloc + tail merging
gynt Sep 27, 2026
4655fa2
reimplement: SHC_3BB0A8C1_0x004E2AD0 45.52% reg alloc, type-load CSE
gynt Sep 27, 2026
cb38d67
reimplement: SHC_3BB0A8C1_0x004E8CF0 29.44% frame slot allocation dif…
gynt Sep 27, 2026
e8194a9
reimplement: SHC_3BB0A8C1_0x004E7810 34.46% frame and reg allocation …
gynt Sep 27, 2026
a586ce1
reimplement: SHC_3BB0A8C1_0x004E2050 26.06% reg alloc; frame now matches
gynt Sep 27, 2026
078dce2
reimplement: SHC_3BB0A8C1_0x004E66F0 59.97% consts kept in regs by orig
gynt Sep 27, 2026
426d7e1
reimplement: SHC_3BB0A8C1_0x004E3980 34.24% reg alloc + tail merging
gynt Sep 27, 2026
59266bc
reimplement: SHC_3BB0A8C1_0x004E2AD0 45.52% reg alloc, type-load CSE
gynt Sep 27, 2026
1a20b50
reimplement: SHC_3BB0A8C1_0x004E8CF0 31.81% reg alloc + stack slot order
gynt Sep 27, 2026
09c1445
reimplement: SHC_3BB0A8C1_0x004E3980 44.97% reg alloc, const-in-reg
gynt Sep 27, 2026
0b41fd7
build: give each worktree its own mspdbsrv endpoint
gynt Sep 27, 2026
503ff52
types: the batch/floater counters are signed ints, not undefined4
gynt Sep 27, 2026
dd46e3c
reimplement: SHC_3BB0A8C1_0x004E6340 100.00% Reimplemented
gynt Sep 27, 2026
934a20a
reimplement: SHC_3BB0A8C1_0x004E63A0 93.79% one reg-copy form differs
gynt Sep 27, 2026
c8dc438
reimplement: SHC_3BB0A8C1_0x004E7810 34.46% frame and reg allocation …
gynt Sep 27, 2026
c04f4eb
reimplement: SHC_3BB0A8C1_0x004E26D0 54.08% esi/edx allocation differs
gynt Sep 27, 2026
ba307f4
reimplement: SHC_3BB0A8C1_0x004E2050 28.69% reg alloc; rowStart kept …
gynt Sep 27, 2026
93e4126
reimplement: SHC_3BB0A8C1_0x004E8430 49.45% reg alloc + tail merging
gynt Sep 28, 2026
f8dab5c
reimplement: SHC_3BB0A8C1_0x004E7770 38.71% LTCG ecx reuse in callers
gynt Sep 28, 2026
52481b9
reimplement: SHC_3BB0A8C1_0x004E2050 28.91% reg alloc; frame matches
gynt Sep 28, 2026
b49debc
reimplement: SHC_3BB0A8C1_0x004E2AD0 45.91% reg alloc, type-load CSE
gynt Sep 28, 2026
4f0ad4f
reimplement: SHC_3BB0A8C1_0x004E8430 49.62% reg alloc + tail merging
gynt Sep 28, 2026
6559b71
reimplement: SHC_3BB0A8C1_0x004E8CF0 31.83% reg alloc + stack slot order
gynt Sep 28, 2026
b832da8
reimplement: SHC_3BB0A8C1_0x004E7810 34.69% frame and reg allocation …
gynt Sep 28, 2026
6fda8f1
reimplement: SHC_3BB0A8C1_0x004E5ED0 43.08% reg alloc, one extra spill
gynt Sep 28, 2026
dd92b02
Merge origin/main (build.bat mspdbsrv fix, orig_asm.py, analysis help…
gynt Sep 28, 2026
e9d91c4
Merge origin/main (orig_asm.py fixes)
gynt Sep 28, 2026
8a0b988
reimplement: SHC_3BB0A8C1_0x004E2AD0 47.42% Block order, reg alloc di…
gynt Sep 28, 2026
ec3ba04
reimplement: SHC_3BB0A8C1_0x004E5ED0 43.36% Block order, reg alloc di…
gynt Sep 28, 2026
b2c4f18
reimplement: SHC_3BB0A8C1_0x004E3980 44.97% Style pass, reg alloc dif…
gynt Sep 28, 2026
2d1bcb1
reimplement: SHC_3BB0A8C1_0x004E8CF0 31.88% Style pass, reg alloc dif…
gynt Sep 28, 2026
e37d63f
reimplement: SHC_3BB0A8C1_0x004E8430 49.62% Style pass, reg alloc dif…
gynt Sep 28, 2026
c6ad821
reimplement: SHC_3BB0A8C1_0x004E3980 44.97% Style pass, reg alloc dif…
gynt Sep 28, 2026
74c1b69
reimplement: SHC_3BB0A8C1_0x004E8CF0 31.88% Style pass, reg alloc dif…
gynt Sep 28, 2026
f361ea4
reimplement: SHC_3BB0A8C1_0x004E7810 34.69% Style pass, reg alloc dif…
gynt Sep 28, 2026
2b14689
reimplement: SHC_3BB0A8C1_0x004E2050 30.73% for loops, reg alloc differs
gynt Sep 28, 2026
2d91118
reimplement: SHC_3BB0A8C1_0x004E8430 49.62% Off-by-one fix, reg alloc
gynt Sep 29, 2026
e0479c4
reimplement: SHC_3BB0A8C1_0x004E2050 33.02% Walking pointers, reg alloc
gynt Sep 29, 2026
8921124
reimplement: SHC_3BB0A8C1_0x004E2050 33.02% Walking pointers, reg alloc
gynt Sep 29, 2026
1f82e1c
tools: give the batch build scripts build.bat PDB server fix
gynt Sep 29, 2026
ecaa96f
tools/batch: retry on a fresh PDB endpoint, not just a fresh server
gynt Sep 29, 2026
039f98d
Merge remote-tracking branch 'origin/main' into reimpl/ViewportRender…
gynt Oct 23, 2026
14128b9
fix(ViewportRenderState): make the branch build and measure against c…
gynt Oct 23, 2026
ee2fd91
reimplement: SHC_3BB0A8C1_0x004E5ED0 49.65% divisions restored, was 4…
gynt Oct 23, 2026
75287e4
reimplement: SHC_3BB0A8C1_0x004E8430 56.09% divisions and do-while co…
gynt Oct 23, 2026
f83e6ca
style(ViewportRenderState): apply the style guide to the matching sou…
gynt Nov 1, 2026
91f1a91
Merge remote-tracking branch 'origin/main' into reimpl/ViewportRender…
gynt Nov 7, 2026
46ba7ed
fix(ViewportRenderState): build against main's header sync
gynt Nov 7, 2026
979202d
reimplement: SHC_3BB0A8C1_0x004E63A0 100.00% Reimplemented
gynt Nov 7, 2026
ab37272
reimplement: SHC_3BB0A8C1_0x004E5B80 100.00% Reimplemented
gynt Nov 7, 2026
3b9aaf4
reimplement: SHC_3BB0A8C1_0x004E5E20 100.00% Reimplemented
gynt Nov 7, 2026
613699b
reimplement: SHC_3BB0A8C1_0x004E26D0 100.00% Reimplemented
gynt Nov 7, 2026
3a8e837
reimplement: SHC_3BB0A8C1_0x004E5C00 100.00% Reimplemented
gynt Nov 7, 2026
1ef60cf
style(ViewportRenderState): clang-format after the renames
gynt Nov 7, 2026
35dba16
reimplement: SHC_3BB0A8C1_0x004E7770 100.00% Reimplemented
gynt Nov 7, 2026
3d3c686
build: compile resetupViewport and its callees with /GL
gynt Nov 7, 2026
74962e6
reimplement: SHC_3BB0A8C1_0x004E5ED0 85.16% orientation tail duplicated
gynt Nov 8, 2026
78dd87e
reimplement: SHC_3BB0A8C1_0x004E8430 68.85% gate >= 0 fix, reg alloc …
gynt Nov 8, 2026
ae11782
reimplement: SHC_3BB0A8C1_0x004E66F0 87.15% cross-jumped arm suffixes…
gynt Nov 8, 2026
fc12ca2
reimplement: SHC_3BB0A8C1_0x004E3980 36.60% modulo restored, reg allo…
gynt Nov 8, 2026
9f9f26b
reimplement: SHC_3BB0A8C1_0x004E8CF0 33.58% division restored, struct…
gynt Nov 8, 2026
3636f28
reimplement: SHC_3BB0A8C1_0x004E8CF0 33.09% GMImageOffsets fix, struc…
gynt Nov 8, 2026
122a299
reimplement: SHC_3BB0A8C1_0x004E7810 36.05% GMImageOffsets fix, reg a…
gynt Nov 8, 2026
160c716
reimplement: SHC_3BB0A8C1_0x004E2AD0 85.93% 5 - damage test restored
gynt Nov 8, 2026
4a99b72
reimplement: SHC_3BB0A8C1_0x004E2AD0 100.00% Reimplemented
gynt Nov 8, 2026
ac2d9a9
style(ViewportRenderState): move the renderGmOverlayBuilding2 drawbri…
gynt Nov 8, 2026
a2a84c9
reimplement: SHC_3BB0A8C1_0x004E5ED0 85.71% orientation tail duplicated
gynt Nov 8, 2026
11ca70a
reimplement: SHC_3BB0A8C1_0x004E3980 37.17% switch arms differ, tail …
gynt Nov 8, 2026
cf336ed
style(ViewportRenderState): rules 15 and 18 across the namespace
gynt Nov 8, 2026
04e3bd1
style(ViewportRenderState): rule 9 for focusOnTile, document the comp…
gynt Nov 8, 2026
07c5c6a
reimplement: SHC_3BB0A8C1_0x004E7810 36.17% alpha arms ordered, prolo…
gynt Nov 8, 2026
0f97b61
types(ViewportRenderState): window position and size fields are int
gynt Nov 8, 2026
1a108ec
reimplement: SHC_3BB0A8C1_0x004E8430 75.09% hitbox table [11][10][2],…
gynt Nov 8, 2026
31dfb2b
reimplement: SHC_3BB0A8C1_0x004E2050 39.30% rewritten from the origin…
gynt Nov 8, 2026
8a01e4a
types(Unit): field_0x41a is a signed short
gynt Nov 8, 2026
87bfbb2
style(ViewportRenderState): drop (int) casts on short and byte operands
gynt Nov 8, 2026
ecbbd55
types(ViewportRenderState): animation intervals and overlay frame are…
gynt Nov 8, 2026
c529d34
types(ColorUnion): add the ushortValue view
gynt Nov 8, 2026
afc6b74
reimplement: SHC_3BB0A8C1_0x004E7810 36.84% batch counters read per a…
gynt Nov 8, 2026
c24107b
style(ViewportRenderState): drop (int) casts around int expressions
gynt Nov 8, 2026
b59dcd2
types(Globals): renderMap's scalar draw globals are int
gynt Nov 8, 2026
1885185
style(ViewportRenderState): drop the casts the int globals no longer …
gynt Nov 8, 2026
4529131
types(Unit): fixedRng is a signed int
gynt Nov 8, 2026
8d52ef8
reimplement: SHC_3BB0A8C1_0x004E7810 43.6% selection block after the …
gynt Nov 8, 2026
5ff6d13
reimplement: SHC_3BB0A8C1_0x004E7810 49.7% graphicSize tests written …
gynt Nov 8, 2026
12da80c
reimplement: SHC_3BB0A8C1_0x004E3980 60.2% switch cases in the origin…
gynt Nov 8, 2026
b285c10
reimplement: SHC_3BB0A8C1_0x004E7810 50.6% siege offset cases in the …
gynt Nov 8, 2026
8ed1812
reimplement: SHC_3BB0A8C1_0x004E3980 60.6% fix chopping block fall-th…
gynt Nov 8, 2026
8db1f68
reimplement: SHC_3BB0A8C1_0x004E3980 62.7% stables blend pairs, miner…
gynt Nov 8, 2026
723bf10
reimplement: SHC_3BB0A8C1_0x004E3980 63.3% fade frame as an if/else-i…
gynt Nov 8, 2026
31dde3e
style(ViewportRenderState): renderGmOverlayBuilding call sites and sl…
gynt Nov 8, 2026
2154ead
reimplement: SHC_3BB0A8C1_0x004E8CF0 37.9% terrain chain in the origi…
gynt Nov 8, 2026
1a8874f
reimplement: SHC_3BB0A8C1_0x004E8CF0 39.8% value tests non-zero first…
gynt Nov 8, 2026
1c0fa79
reimplement: SHC_3BB0A8C1_0x004E8CF0 40.7% unit arms, wave and wall c…
gynt Nov 8, 2026
16d473f
reimplement: SHC_3BB0A8C1_0x004E8CF0 41.1% flat-view chains test 0x10…
gynt Nov 8, 2026
241fa2d
style(ViewportRenderState): renderMap construction overlay tests the …
gynt Nov 8, 2026
7efdcab
style(ViewportRenderState): renderMap entity loop as a do-while with …
gynt Nov 8, 2026
d26c43c
reimplement: SHC_3BB0A8C1_0x004E8CF0 41.3% editor layer rotation with…
gynt Nov 8, 2026
b461852
reimplement: SHC_3BB0A8C1_0x004E8CF0 41.4% siege overlay switches in …
gynt Nov 9, 2026
022a6a0
tools: switch_order.py, flip_branches.py and dropcast.py, the block-o…
gynt Nov 9, 2026
40aa82e
Merge origin/main into reimpl/ViewportRenderState
gynt Dec 2, 2026
8decfff
fix(ViewportRenderState): build against main's headers after the merge
gynt Dec 2, 2026
a78c427
Merge origin/main into reimpl/ViewportRenderState
gynt Dec 3, 2026
35c91c2
reimplement: SHC_3BB0A8C1_0x004E8CF0 41.46% structure, frame 0x68 vs …
gynt Dec 3, 2026
f46a51b
status: record measured % and blockers for ViewportRenderState functions
gynt Dec 3, 2026
2bd79fe
reimplement: SHC_3BB0A8C1_0x004E8430 77.18% reg alloc: mouseX/mouseY …
gynt Dec 3, 2026
9638699
Merge origin/main into reimpl/ViewportRenderState
gynt Dec 5, 2026
dfacf89
status: record the blockers found for three ViewportRenderState funct…
gynt Dec 5, 2026
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
8 changes: 8 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,14 @@ style question - see the note on unpredictable styles below. `declare_at_use.py`
`undiv.py` undo decompiler artefacts across a whole selection; run `test_deparen.py` and `test_undiv.py` after
touching the precedence table or the division patterns those two rely on.

On a large decompiled function most of the gap is usually block *order*, not code, and two tools restore it
before anything else is worth measuring: `switch_order.py` puts every switch's case bodies in the order of the
original's jump table (MSVC emits them in source order, Ghidra prints them by value; 37% -> 60% on
`renderGmOverlayBuilding` alone), and `flip_branches.py --find` lists the if/else statements whose arms the
original lays out the other way round (Ghidra prints the jump target first, so `if ((x & m) == 0) {A} else {B}`
was usually `!= 0` with the arms swapped). `quick_diff.py -r --runs N` then lists what still differs with the
source lines it comes from.

The rewriting scripts take a path filter and default to a dry run. Read the diff before building, then run
`syntax_check.py` on what you touched: reviewing a diff catches a wrong transformation but not a rewrite that leaves
the surrounding text unparseable, and `/Zs` finds that in seconds instead of a full build.
Expand Down
3 changes: 3 additions & 0 deletions cmake/compiler-flags-gl.txt
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,9 @@ src/OpenSHC/Map/Units/UpdateJester.cpp
src/OpenSHC/Map/Units/UpdateSlave.cpp
src/OpenSHC/Map/Units/UpdateHealer.cpp
src/OpenSHC/Map/Units/UpdateSpearman.cpp
src/OpenSHC/Rendering/ViewportRenderState/resetupViewport.cpp
src/OpenSHC/Rendering/ViewportRenderState/setupViewport.cpp
src/OpenSHC/Rendering/ViewportRenderState/setViewportBasedOnMapSize.cpp
src/OpenSHC/Map/Units/UpdateSlinger.cpp
src/OpenSHC/Map/Units/UpdateWoodcutter.cpp
src/OpenSHC/Map/Units/UpdateFletcher.cpp
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
#include "../ViewportRenderState.func.hpp"

#include "OpenSHC/Map/Buildings/BuildingsState.func.hpp"
#include "OpenSHC/Map/TileMapState.func.hpp"
#include "OpenSHC/Map/LogicHelpers/Logic1.hpp"

#include "OpenSHC/Globals/DAT_BuildingsState.hpp"
#include "OpenSHC/Globals/DAT_GameState.hpp"
#include "OpenSHC/Globals/DAT_GameSynchronyState.hpp"
#include "OpenSHC/Globals/DAT_MapRenderDefinedData.hpp"
#include "OpenSHC/Globals/DAT_TileMapState.hpp"

namespace OpenSHC {
namespace Rendering {

// FUNCTION: STRONGHOLDCRUSADER 0x004E5ED0
void ViewportRenderState::computeMouseTileFromScreenPosition(int screenX, int screenY)
{
int probeScreenY = screenY - 8;
int foundTile = 0;
int orientationBase = 8;

this->viewportState.field_0x6c = 0;
this->viewportState.cursorTile = 0;
this->viewportState.mouseX = 0;
this->viewportState.mouseY = 0;
if (this->viewportState.field_0x0 == 0) {
return;
}

int const& isZoomedOut = this->viewportState.isZoomedOutUnk;
int quadrantX;
if (isZoomedOut == 0) {
quadrantX = ((this->viewportState.viewportX % 32 - this->windowX) + screenX) >> 1 & 0xf;
} else {
quadrantX = ((this->viewportState.viewportX % 32 + screenX * 2) - this->windowX) >> 1 & 0xf;
}

if (DAT_TileMapState::instance.mapOrientation == 0) {
orientationBase = 8;
} else if (DAT_TileMapState::instance.mapOrientation == 6) {
orientationBase = 80408;
} else if (DAT_TileMapState::instance.mapOrientation == 4) {
orientationBase = 160808;
} else if (DAT_TileMapState::instance.mapOrientation == 2) {
orientationBase = 241208;
}
int probeDoubledY = probeScreenY * 2 + 8;
int probeOffset = probeScreenY - screenY;

// a do-while on purpose: the same loop as a for adds an entry test the original does not have (0.88 -> 0.59)
do {
if ((DAT_TileMapState::instance.disableElevationRendering != 0
|| DAT_TileMapState::instance.flatViewToggleValue2 != 0)
&& probeOffset != -8) {
break;
}

int lookupIndex;
int tileRowY;
if (this->viewportState.isZoomedOutUnk == 0) {
int unclampedY = (this->viewportState.viewportY - this->windowY) + 8 + probeScreenY;
tileRowY = ((this->viewportState.viewportY % 16 - this->windowY) + probeScreenY - 8) & 0xf;
int unclampedX = (screenX - this->windowX) + this->viewportState.viewportX;
lookupIndex = (unclampedX / 32) + (unclampedY / 16) * 401 + orientationBase;
} else {
int unclampedX = ((screenX * 2 + 160) - this->windowX) + this->viewportState.viewportX;
tileRowY = ((this->viewportState.viewportY % 16 - this->windowY) + probeDoubledY) & 0xf;
int unclampedY = (probeDoubledY - this->windowY) + this->viewportState.viewportY;
lookupIndex = (unclampedY / 16) * 401 + (unclampedX / 32) + orientationBase;
}

int quadrant = DAT_MapRenderDefinedData::instance.field_0xc24[tileRowY][quadrantX];
if (quadrant == 1) {
lookupIndex = lookupIndex + 200;
} else if (quadrant == 2) {
lookupIndex = lookupIndex + 201;
} else if (quadrant == 3) {
lookupIndex = lookupIndex + 401;
}

int tile = this->screenPointToTileNumber[lookupIndex];
if ((DAT_TileMapState::instance.LogicLayer[tile]
& (Map::LogicHelpers::L_BORDER | Map::LogicHelpers::L_BORDER_EDGE))
!= 0) {
break;
}

int tileHeightOffset
= DAT_TileMapState::instance.heightBasedScreenYOffset[DAT_TileMapState::instance.HeightLayer[tile]];
if ((DAT_TileMapState::instance.LogicLayer[tile] & Map::LogicHelpers::L_KEEP_NON_MANOR_HOUSE) != 0) {
tileHeightOffset = tileHeightOffset
+ MACRO_CALL_MEMBER(OpenSHC::Map::Buildings::BuildingsState_Func::getBuildingHeightForBuildingID,
DAT_BuildingsState::ptr)(DAT_TileMapState::instance.BuildingLayer[tile]);
}
if (this->viewportState.isZoomedOutUnk != 0) {
tileHeightOffset = tileHeightOffset / 2;
}

if ((probeOffset - tileHeightOffset) + 8 + screenY <= screenY
|| DAT_TileMapState::instance.disableElevationRendering != 0
|| DAT_TileMapState::instance.flatViewToggleValue2 != 0) {
foundTile = tile;
}

probeScreenY = probeScreenY + 1;
probeDoubledY = probeDoubledY + 2;
probeOffset = probeOffset + 1;
} while (probeOffset < 255);

this->viewportState.mouseAtomRefFloorTile = foundTile;
if (DAT_TileMapState::instance.PathConnectionLayer[foundTile] == 0
|| (DAT_TileMapState::instance.LogicLayer[foundTile] & Map::LogicHelpers::L_CRENEL) != 0) {
int neighbourTile
= DAT_TileMapState::instance
.directionTranslationMatrix[this->tileTranslationMatrix_YComponent[foundTile]]
[(DAT_TileMapState::instance.screenSouthEastDirection + 4) % 8]
+ foundTile;
uint tileFlags = DAT_TileMapState::instance.LogicLayer[foundTile];
if ((tileFlags & Map::LogicHelpers::L_MOAT) == 0) {
if ((tileFlags & Map::LogicHelpers::L_CRENEL) != 0) {
if ((DAT_TileMapState::instance.LogicLayer[neighbourTile] & Map::LogicHelpers::L_WALL_OR_GATEHOUSE)
!= 0) {
foundTile = neighbourTile;
}
} else if ((tileFlags & Map::LogicHelpers::L_BUILDING) != 0) {
switch (DAT_BuildingsState::instance.buildings[DAT_TileMapState::instance.BuildingLayer[foundTile]]
.buildingType) {
case OpenSHC::Map::Buildings::BT_MANORHOUSE:
case OpenSHC::Map::Buildings::BT_STONEKEEP:
case OpenSHC::Map::Buildings::BT_STRONGHOLD:
case OpenSHC::Map::Buildings::BT_KEEPFOUR:
case OpenSHC::Map::Buildings::BT_KEEPFIVE:
case OpenSHC::Map::Buildings::BT_TOWER:
case OpenSHC::Map::Buildings::BT_TOWER1:
case OpenSHC::Map::Buildings::BT_TOWER2:
case OpenSHC::Map::Buildings::BT_TOWER3:
case OpenSHC::Map::Buildings::BT_TOWER4:
case OpenSHC::Map::Buildings::BT_TOWER5:
if ((DAT_TileMapState::instance.LogicLayer[neighbourTile]
& Map::LogicHelpers::L_KEEP_NON_MANOR_HOUSE)
!= 0) {
foundTile = neighbourTile;
}
break;
default:
foundTile = 0;
break;
}
} else {
foundTile = 0;
}
}
}

if ((DAT_TileMapState::instance.LogicLayer[foundTile]
& (Map::LogicHelpers::L_WALL_OR_GATEHOUSE | Map::LogicHelpers::L_CRENEL
| Map::LogicHelpers::L_KEEP_NON_MANOR_HOUSE))
!= 0
&& (DAT_TileMapState::instance.LogicLayer[foundTile] & 2) == 0) {
this->viewportState.field_0x6c = 1;
}
this->viewportState.cursorTile = foundTile;
this->viewportState.somePitchDitchID = 0;
if (foundTile == 0) {
this->viewportState.mouseY = 0;
this->viewportState.mouseX = 0;
this->viewportState.field_0x6c = 0;
this->viewportState.field_0x38 = 0;
this->viewportState.field_0x40 = 0;
this->viewportState.field_0x3c = 0;
return;
}

this->viewportState.mouseY = this->tileTranslationMatrix_YComponent[foundTile];
this->viewportState.mouseX = foundTile - this->translationMatrix[this->viewportState.mouseY].addXgetTile;
if (DAT_TileMapState::instance.flatViewToggleValue1 != 0) {
foundTile = this->viewportState.mouseFlatTile;
}
this->viewportState.field_0x38 = DAT_TileMapState::instance.LogicLayer[foundTile] & Map::LogicHelpers::L_MOAT;
this->viewportState.field_0x40
= DAT_TileMapState::instance.LogicLayer[foundTile] & Map::LogicHelpers::L_MOAT_DUG_OR_PLANNED;
int moatID = MACRO_CALL_MEMBER(OpenSHC::Map::TileMapState_Func::returnOwnedMoatAtTile, DAT_TileMapState::ptr)(
foundTile);
if (moatID == 0) {
this->viewportState.field_0x38 = 0;
this->viewportState.field_0x40 = 0;
}
this->viewportState.field_0x3c = this->viewportState.field_0x38;
if (DAT_GameState::instance.mapAndTime.playerTeams[DAT_TileMapState::instance.moats[moatID].owner]
== DAT_GameState::instance.mapAndTime.playerTeams[DAT_GameSynchronyState::instance.currentPlayerSlotID]) {
this->viewportState.field_0x38 = 0;
} else {
this->viewportState.field_0x40 = 0;
this->viewportState.field_0x3c = 0;
}
if ((DAT_TileMapState::instance.LogicLayer[foundTile] & 8) != 0) {
this->viewportState.somePitchDitchID = MACRO_CALL_MEMBER(
OpenSHC::Map::TileMapState_Func::getPitchDitchIDForTile, DAT_TileMapState::ptr)(foundTile);
}
}

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include "../ViewportRenderState.func.hpp"

#include "OpenSHC/UI/Rendering/TextureRenderCore.func.hpp"

#include "OpenSHC/Globals/DAT_TextureRenderCoreObject.hpp"
#include "OpenSHC/Globals/DAT_UnitsState.hpp"

namespace OpenSHC {
namespace Rendering {

// FUNCTION: STRONGHOLDCRUSADER 0x004E2630
void ViewportRenderState::renderAssassinClimbingOverlay(int unitID)
{
short facingDirection = DAT_UnitsState::instance.units[unitID].facingDirectionMapOrientationCorrected;
short assassinHeightDifference = DAT_UnitsState::instance.units[unitID].assassinHeightDifference;
if (assassinHeightDifference <= 0) {
return;
}
int imageID = DAT_UnitsState::instance.units[unitID].imageIDUnk;
if (imageID <= 0) {
return;
}

if (DAT_UnitsState::instance.units[unitID].assassinClimbingUpUnk_OR_previousFacingDirection == 0) {
if (facingDirection != 4 && facingDirection != 2 && facingDirection != 3 && facingDirection != 1
&& facingDirection != 5) {
return;
}
} else {
if (facingDirection != 0 && facingDirection != 6 && facingDirection != 7 && facingDirection != 1
&& facingDirection != 5) {
return;
}
}

MACRO_CALL_MEMBER(
OpenSHC::UI::Rendering::TextureRenderCore_Func::renderGMWithBlending, DAT_TextureRenderCoreObject::ptr)
((OpenSHC::IO::Graphics::GmID)DAT_UnitsState::instance.units[unitID].gmIDUnk, imageID,
DAT_UnitsState::instance.units[unitID].field_0x41c,
DAT_UnitsState::instance.units[unitID].field_0x420 - assassinHeightDifference,
DAT_UnitsState::instance.units[unitID].field_0x41a);
}

}
}
Loading