Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions cmake/compiler-flags-gl.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ src/OpenSHC/IO/ResourceManager/swapMapDataWithNextMap.cpp
src/OpenSHC/UI/Rendering/WindowAndDirectDraw/takeScreenshot.cpp
src/OpenSHC/IO/ResourceManager/readFirstPartOfCurrentResourceIntoMemory.cpp
src/OpenSHC/IO/ResourceManager/readNextPartOfCurrentResourceIntoMemory.cpp
src/OpenSHC/Map/Navigation/DirectionAlgorithmState/getMouseVectorLengthBasedOnDirection.cpp
src/OpenSHC/Input/MouseState/updateRightDragCameraControl.cpp
2 changes: 1 addition & 1 deletion src/OpenSHC/Input/Mouse/ClickTypeBitMaskEnumByte.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
namespace OpenSHC {
namespace Input {
namespace Mouse {
typedef byte ClickTypeBitMaskEnumByte;
typedef char ClickTypeBitMaskEnumByte;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You sure? Changing this would mean changing all enum bytes to enum chars, which is fine I guess, since original enum is also usually int (not uint). Just want to be sure before I implement such a large change.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. While a while, I clearly remember that I was hesitant and tested around, but it is a char.


static_assert_cpp98_obj(sizeof(ClickTypeBitMaskEnumByte) == 1, ClickTypeBitMaskEnumByte);
} // namespace Mouse
Expand Down
20 changes: 10 additions & 10 deletions src/OpenSHC/Input/MouseState.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ namespace Input {
undefined4 time0; // 0x00000004 length: 4
BOOLEnum anyActivity; // 0x00000008 length: 4
undefined4 flag; // 0x0000000C length: 4
undefined4 screenSpaceX; // 0x00000010 length: 4
undefined4 screenSpaceY; // 0x00000014 length: 4
undefined4 cursorPosX; // 0x00000018 length: 4
undefined4 cursorPosY; // 0x0000001C length: 4
int screenSpaceX; // 0x00000010 length: 4
int screenSpaceY; // 0x00000014 length: 4
int cursorPosX; // 0x00000018 length: 4
int cursorPosY; // 0x0000001C length: 4
undefined4 previousScreenSpaceX; // 0x00000020 length: 4
undefined4 previousScreenSpaceY; // 0x00000024 length: 4
BOOLEnum draggingStopped; // 0x00000028 length: 4
Expand Down Expand Up @@ -64,7 +64,7 @@ namespace Input {
int previewEnabled; // 0x0000009C length: 4
MouseXYUUStruct mouseXY[10]; // 0x000000A0 length: 160
int mouseXY8[10]; // 0x00000140 length: 40
undefined4 index; // 0x00000168 length: 4
int index; // 0x00000168 length: 4
undefined4 storedScreenSpaceX; // 0x0000016C length: 4
undefined4 storedScreenSpaceY; // 0x00000170 length: 4
undefined4 field42_0x174; // 0x00000174 length: 4
Expand All @@ -81,8 +81,8 @@ namespace Input {
undefined4 currentTime1; // 0x000001A0 length: 4
undefined4 currentTime2; // 0x000001A4 length: 4
undefined4 currentTime3; // 0x000001A8 length: 4
undefined4 field56_0x1ac; // 0x000001AC length: 4
undefined4 field57_0x1b0; // 0x000001B0 length: 4
int field56_0x1ac; // 0x000001AC length: 4
int field57_0x1b0; // 0x000001B0 length: 4
undefined4 field58_0x1b4; // 0x000001B4 length: 4
undefined4 field59_0x1b8; // 0x000001B8 length: 4
undefined4 field60_0x1bc; // 0x000001BC length: 4
Expand All @@ -98,9 +98,9 @@ namespace Input {
int field70_0x1e4; // 0x000001E4 length: 4
undefined1 padding_0x1e8[8]; // 0x000001E8 length: 8
undefined4 cursorType; // 0x000001F0 length: 4
undefined2 mouseWindowX; // 0x000001F4 length: 2
undefined2 mouseWindowY; // 0x000001F6 length: 2
undefined2 mouseWheelDelta; // 0x000001F8 length: 2
short mouseWindowX; // 0x000001F4 length: 2
short mouseWindowY; // 0x000001F6 length: 2
short mouseWheelDelta; // 0x000001F8 length: 2
ClickTypeBitMaskEnumByte mouseClickTypes; // 0x000001FA length: 1
undefined1 padding1; // 0x000001FB length: 1
HCURSOR currentDefaultCursor; // 0x000001FC length: 4
Expand Down
22 changes: 22 additions & 0 deletions src/OpenSHC/Input/MouseState/Constructor_MouseState.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include "../MouseState.func.hpp"

namespace OpenSHC {
namespace Input {

// FUNCTION: STRONGHOLDCRUSADER 0x004709B0
MouseState* MouseState::Constructor_MouseState()
{
this->time0 = timeGetTime();
MACRO_CALL_MEMBER(MouseState_Func::storeXYAndResetMouseState, this)();
this->previewEnabled = 0;
this->flag = 0;
this->resetPending = 0;
this->waitCursorToggle = 0;
this->cursorType = 0;
this->field70_0x1e4 = 0;
this->field68_0x1dc = -1;
return this;
}

}
}
42 changes: 42 additions & 0 deletions src/OpenSHC/Input/MouseState/beginPointSelectionBox.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include "../MouseState.func.hpp"

#include "OpenSHC/Globals/DAT_MouseState.hpp"
#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp"

namespace OpenSHC {
namespace Input {

// FUNCTION: STRONGHOLDCRUSADER 0x00468420
void MouseState::beginPointSelectionBox()
{
this->previousSelectionBox.left
= this->screenSpaceX + DAT_ViewportRenderState::instance.viewportState.currentCameraOffsetX - 1;
this->previousSelectionBox.top
= this->screenSpaceY + DAT_ViewportRenderState::instance.viewportState.currentCameraOffsetY - 1;
this->previousSelectionBox.right
= this->screenSpaceX + DAT_ViewportRenderState::instance.viewportState.currentCameraOffsetX + 1;
this->previousSelectionBox.bottom
= this->screenSpaceY + DAT_ViewportRenderState::instance.viewportState.currentCameraOffsetY + 1;

if (DAT_ViewportRenderState::instance.viewportState.isZoomedOutUnk) {
this->selectionBox.left
= (this->screenSpaceX + DAT_ViewportRenderState::instance.viewportState.currentCameraOffsetX) * 2 - 2;
this->selectionBox.top
= (this->screenSpaceY + DAT_ViewportRenderState::instance.viewportState.currentCameraOffsetY) * 2 - 2;
this->selectionBox.right
= (this->screenSpaceX + DAT_ViewportRenderState::instance.viewportState.currentCameraOffsetX) * 2 + 2;
this->selectionBox.bottom
= (this->screenSpaceY + DAT_ViewportRenderState::instance.viewportState.currentCameraOffsetY) * 2 + 2;
} else {
this->selectionBox.left = this->previousSelectionBox.left;
this->selectionBox.top = this->previousSelectionBox.top;
this->selectionBox.right = this->previousSelectionBox.right;
this->selectionBox.bottom = this->previousSelectionBox.bottom;
}

DAT_MouseState::instance.field31_0x94 = 0;
DAT_MouseState::instance.selectionBoxMode = 1;
}

}
}
39 changes: 39 additions & 0 deletions src/OpenSHC/Input/MouseState/drawMouseBasedBox.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include "../MouseState.func.hpp"

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

#include "OpenSHC/Globals/COL_BLACK.hpp"
#include "OpenSHC/Globals/COL_WHITE.hpp"
#include "OpenSHC/Globals/DAT_MouseState.hpp"
#include "OpenSHC/Globals/DAT_PencilRenderCore.hpp"

namespace OpenSHC {
namespace Input {

// FUNCTION: STRONGHOLDCRUSADER 0x00472A90
void MouseState::drawMouseBasedBox()
{
if (!DAT_MouseState::instance.field31_0x94) {
return;
}
if (!DAT_MouseState::instance.leftClickState && !DAT_MouseState::instance.draggingStopped) {
MACRO_CALL_MEMBER(MouseState_Func::resetMouseCursorState, this)();
return;
}
int left = this->previousSelectionBox.left;
int right = this->previousSelectionBox.right;
int top = this->previousSelectionBox.top;
int bottom = this->previousSelectionBox.bottom;

DAT_PencilRenderCore::instance.surfaceTarget = Rendering::Enums::RT_MAP_GAME;
MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawBorderBox, DAT_PencilRenderCore::ptr)(
left, top, right, bottom, COL_BLACK::instance.shortValue);

MACRO_CALL_MEMBER(UI::Rendering::PencilRenderCore_Func::drawBorderBox, DAT_PencilRenderCore::ptr)(
left + 1, top + 1, right + -1, bottom + -1, COL_WHITE::instance.shortValue);

DAT_PencilRenderCore::instance.surfaceTarget = Rendering::Enums::RT_SCREEN_MENU;
}

}
}
42 changes: 42 additions & 0 deletions src/OpenSHC/Input/MouseState/extendSelectionBoxToMouse.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include "../MouseState.func.hpp"

#include "OpenSHC/Map/Navigation/DirectionAlgorithmState.func.hpp"

#include "OpenSHC/Globals/DAT_DirectionAlgorithmState.hpp"
#include "OpenSHC/Globals/DAT_MouseState.hpp"
#include "OpenSHC/Globals/DAT_ViewportRenderState.hpp"

namespace OpenSHC {
namespace Input {

// FUNCTION: STRONGHOLDCRUSADER 0x00470B30
void MouseState::extendSelectionBoxToMouse()
{
this->previousSelectionBox.right
= this->screenSpaceX + DAT_ViewportRenderState::instance.viewportState.currentCameraOffsetX;
this->previousSelectionBox.bottom
= this->screenSpaceY + DAT_ViewportRenderState::instance.viewportState.currentCameraOffsetY;

if (DAT_ViewportRenderState::instance.viewportState.isZoomedOutUnk) {
this->selectionBox.right
= (DAT_ViewportRenderState::instance.viewportState.currentCameraOffsetX + this->screenSpaceX) * 2 + 2;
this->selectionBox.bottom
= (DAT_ViewportRenderState::instance.viewportState.currentCameraOffsetY + this->screenSpaceY) * 2 + 2;
} else {
this->selectionBox.right = this->previousSelectionBox.right;
this->selectionBox.bottom = this->previousSelectionBox.bottom;
}

DAT_MouseState::instance.selectionBoxMode = 2;

MACRO_CALL_MEMBER(Map::Navigation::DirectionAlgorithmState_Func::setAxisBasedDistanceResult,
DAT_DirectionAlgorithmState::ptr)(
this->selectionBox.left, this->selectionBox.top, this->selectionBox.right, this->selectionBox.bottom);

if (16 < DAT_DirectionAlgorithmState::instance.distanceHigh) {
DAT_MouseState::instance.field31_0x94 = 1;
}
}

}
}
25 changes: 25 additions & 0 deletions src/OpenSHC/Input/MouseState/isMouseInsideBox.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include "../MouseState.func.hpp"

namespace OpenSHC {
namespace Input {

// FUNCTION: STRONGHOLDCRUSADER 0x004680C0
BOOLEnum MouseState::isMouseInsideBox(int xPos, int yPos, int width, int heigth)
{
if (xPos > this->screenSpaceX) {
return FALSE;
}
if ((xPos + width) <= this->screenSpaceX) {
return FALSE;
}
if (yPos > this->screenSpaceY) {
return FALSE;
}
if ((yPos + heigth) <= this->screenSpaceY) {
return FALSE;
}
return TRUE;
}

}
}
60 changes: 60 additions & 0 deletions src/OpenSHC/Input/MouseState/loadAndSetCursor.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#include "../MouseState.func.hpp"

#include "OpenSHC/string-literals.hpp"

#include "OpenSHC/Globals/DAT_WindowAndDirectDraw.hpp"

namespace OpenSHC {
namespace Input {

// TODO: We later also need to add the proper resources.

// FUNCTION: STRONGHOLDCRUSADER 0x00470A00
void MouseState::loadAndSetCursor(int notAniDefaultCursorRef, int notAniDeleteCursorRef,
int notAniDeleteNotCursorRef, int unused1, int unused2, int unused3, int unused4, int notAniUnknownCursorRef)
{
this->notAniDefaultCursor_0x24c
= LoadCursorA(DAT_WindowAndDirectDraw::instance.hInstanceUnk_0xa8, MAKEINTRESOURCE(notAniDefaultCursorRef));

this->notAniDeleteCursor_0x250
= LoadCursorA(DAT_WindowAndDirectDraw::instance.hInstanceUnk_0xa8, MAKEINTRESOURCE(notAniDeleteCursorRef));

this->notAniWaitCursor_0x258 = LoadCursorA(NULL, IDC_WAIT);

this->notAniHandCursor_0x25c
= LoadCursorA(DAT_WindowAndDirectDraw::instance.hInstanceUnk_0xa8, MAKEINTRESOURCE(notAniDefaultCursorRef));

this->notAniDeleteNotCursor_0x260 = LoadCursorA(
DAT_WindowAndDirectDraw::instance.hInstanceUnk_0xa8, MAKEINTRESOURCE(notAniDeleteNotCursorRef));

this->notAniDefaultArabCursor_0x264
= LoadCursorA(DAT_WindowAndDirectDraw::instance.hInstanceUnk_0xa8, MAKEINTRESOURCE(notAniDefaultCursorRef));

this->swordCursor_0x224 = LoadCursorFromFileA(s_sword_ani_005a625c);
this->deleteCursor_0x228 = LoadCursorFromFileA(s_delete_ani_005a6250);
this->jesterCursor_0x230 = LoadCursorFromFileA(s_jester_ani_005a6244);
this->handCursor_0x234 = LoadCursorFromFileA(s_hand_ani_005a6238);
this->deleteNotCursor_0x238 = LoadCursorFromFileA(s_delete_not_ani_005a6228);
this->scimitarCursor_0x23c = LoadCursorFromFileA(s_scimitar_ani_005a6218);

if (!this->cursorType) {
if (DAT_WindowAndDirectDraw::instance.not_DDCAPS2_CANBOBHARDWARE_0xe0) {
this->cursorType = 2;
} else {
this->cursorType = 1;
}
}
MACRO_CALL_MEMBER(MouseState_Func::makeSelectedCursorTypeCurrent, this)();

if (notAniDeleteNotCursorRef) {
this->unknownNotAniDeleteNotCursor_0x204 = LoadCursorA(
DAT_WindowAndDirectDraw::instance.hInstanceUnk_0xa8, MAKEINTRESOURCE(notAniDeleteNotCursorRef));
}
if (notAniUnknownCursorRef) {
this->unknownNotAniCursor_0x218 = LoadCursorA(
DAT_WindowAndDirectDraw::instance.hInstanceUnk_0xa8, MAKEINTRESOURCE(notAniUnknownCursorRef));
}
}

}
}
30 changes: 30 additions & 0 deletions src/OpenSHC/Input/MouseState/makeSelectedCursorTypeCurrent.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include "../MouseState.func.hpp"

namespace OpenSHC {
namespace Input {

// FUNCTION: STRONGHOLDCRUSADER 0x00467F80
void MouseState::makeSelectedCursorTypeCurrent()
{
if (this->cursorType == 1) {
this->currentDefaultCursor = this->swordCursor_0x224;
this->currentDeleteCursor_0x200 = this->deleteCursor_0x228;
this->currentWaitCursor_0x208 = this->jesterCursor_0x230;
this->currentHandCursor_0x20c = this->handCursor_0x234;
this->currentDeleteNotCursor_0x210 = this->deleteNotCursor_0x238;
this->currentDefaultArabCursor_0x214 = this->scimitarCursor_0x23c;
return;
}

if (this->cursorType == 2) {
this->currentDefaultCursor = this->notAniDefaultCursor_0x24c;
this->currentDeleteCursor_0x200 = this->notAniDeleteCursor_0x250;
this->currentWaitCursor_0x208 = this->notAniWaitCursor_0x258;
this->currentHandCursor_0x20c = this->notAniHandCursor_0x25c;
this->currentDeleteNotCursor_0x210 = this->notAniDeleteNotCursor_0x260;
this->currentDefaultArabCursor_0x214 = this->notAniDefaultArabCursor_0x264;
}
}

}
}
Loading