Skip to content
Open
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
3 changes: 3 additions & 0 deletions BG3Extender/BG3Extender.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ $(SolutionDir)x64\Release\ResourceBundler.exe "$(ProjectDir)LuaScripts" "$(Proje
<ClInclude Include="GameHooks\EngineHooks.h" />
<ClInclude Include="GameHooks\EngineHooksFwdDecl.h" />
<ClInclude Include="GameHooks\OsirisWrappers.h" />
<ClInclude Include="Lua\Client\CameraEvents.h" />
<ClInclude Include="Lua\Client\ClientEntityReplicationEvents.h" />
<ClInclude Include="Lua\Client\ClientEvents.h" />
<ClInclude Include="Lua\Client\LuaBindingClient.h" />
Expand Down Expand Up @@ -398,6 +399,7 @@ $(SolutionDir)x64\Release\ResourceBundler.exe "$(ProjectDir)LuaScripts" "$(Proje
<ClCompile Include="GameHooks\DataLibrariesBG3Game.cpp" />
<ClCompile Include="GameHooks\EngineHooks.cpp" />
<ClCompile Include="GameHooks\OsirisWrappers.cpp" />
<ClCompile Include="Lua\Client\CameraEvents.cpp" />
<ClCompile Include="Lua\Client\LuaClient.cpp" />
<ClCompile Include="Lua\Debugger\LuaDebug.pb.cc">
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Game Debug|x64'">NotUsing</PrecompiledHeader>
Expand Down Expand Up @@ -500,6 +502,7 @@ $(SolutionDir)x64\Release\ResourceBundler.exe "$(ProjectDir)LuaScripts" "$(Proje
<None Include="GameDefinitions\Stats\Expression.inl" />
<None Include="GameDefinitions\Stats\Functors.inl" />
<None Include="GameDefinitions\Status.inl" />
<None Include="GameDefinitions\Components\Camera.inl" />
<None Include="GameDefinitions\Surface.inl" />
<None Include="GameDefinitions\Symbols.inl" />
<None Include="GameHooks\EngineHooks.inl" />
Expand Down
5 changes: 5 additions & 0 deletions BG3Extender/BG3Extender.vcxproj.filters
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<ClCompile Include="Lua\Client\CameraEvents.cpp">
<Filter>Lua\Client</Filter>
</ClCompile>
<ClCompile Include="Lua\Shared\LuaStats.cpp">
<Filter>Lua\Shared</Filter>
</ClCompile>
Expand Down Expand Up @@ -448,6 +451,7 @@
<ClInclude Include="Lua\Shared\RawComponentRef.h" />
<ClInclude Include="GameDefinitions\Render.h" />
<ClInclude Include="GameDefinitions\UI.h" />
<ClInclude Include="Lua\Client\CameraEvents.h" />
<ClInclude Include="Lua\Client\UIEvents.h" />
<ClInclude Include="GameDefinitions\Sound.h" />
<ClInclude Include="Extender\Client\IMGUI\IMGUI.h" />
Expand Down Expand Up @@ -809,6 +813,7 @@
<None Include="GameDefinitions\Base\Lock.inl">
<Filter>GameDefinitions\Base</Filter>
</None>
<None Include="GameDefinitions\Components\Camera.inl" />
<None Include="GameDefinitions\Surface.inl">
<Filter>GameDefinitions</Filter>
</None>
Expand Down
42 changes: 42 additions & 0 deletions BG3Extender/GameDefinitions/Components/Camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,11 @@ END_SE()

BEGIN_NS(ecl)

struct CameraSystem : public BaseSystem
{
DEFINE_SYSTEM(ClientCamera, "ecl::CameraSystem")
};

struct GameCameraBehavior : public BaseComponent
{
DEFINE_COMPONENT(GameCameraBehavior, "ecl::GameCameraBehavior")
Expand Down Expand Up @@ -300,6 +305,43 @@ struct GameCameraBehavior : public BaseComponent
HashSet<int16_t> field_208;
std::optional<glm::vec3> field_238;
std::optional<glm::vec3> field_248;

//# P_GETTER(CameraDefinition, GetCameraDefinition)
CameraGlobalSwitches* GetCameraDefinition() const;
};

// Partial native argument layouts used by camera update hooks. Only the
// accessed fields are identified; these are not complete engine structures.
struct [[bg3::hidden]] CameraUpdateTime
{
uint8_t field_0[0x0c];
float DeltaTime;
};

struct [[bg3::hidden]] CameraUpdateComponentView
{
uint8_t field_0[0x30];
GameCameraBehavior* Camera;
uint8_t field_38[0x38];
EntityHandle Entity;
};

struct [[bg3::hidden]] CameraZoomUpdateComponentView
{
uint8_t field_0[0x10];
GameCameraBehavior* Camera;
};

struct [[bg3::hidden]] CameraInputComponentView
{
uint8_t field_0[0x40];
GameCameraBehavior* Camera;
};

struct [[bg3::hidden]] CameraDefaultZoomComponentView
{
uint8_t field_0[0x20];
GameCameraBehavior* Camera;
};

END_NS()
Expand Down
11 changes: 11 additions & 0 deletions BG3Extender/GameDefinitions/Components/Camera.inl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include <GameDefinitions/Components/Camera.h>

BEGIN_NS(ecl)

CameraGlobalSwitches* GameCameraBehavior::GetCameraDefinition() const
{
auto getter = GetStaticSymbols().ecl__GameCameraBehavior__GetCameraDefinition;
return getter ? getter(this) : nullptr;
}

END_NS()
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ T(ecl::EquipmentVisualsSystem)
T(ecl::VisualSystem)
T(ecl::CharacterIconRenderSystem)
T(ecl::CharacterManager)
T(ecl::CameraSystem)
T(ecl::equipment::VisualsVisibilityStateSystem)
T(ecl::effect::HandlerSystem)
T(ecl::TimelineSystem)
Expand Down
1 change: 1 addition & 0 deletions BG3Extender/GameDefinitions/Enumerations/ECS.inl
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ BEGIN_ENUM(ExtSystemType, uint32_t)
E(ClientVisual)
E(ClientCharacterIconRender)
E(ClientCharacterManager)
E(ClientCamera)
E(ClientVisualsVisibilityState)
E(ClientEffectHandler)
E(ClientTimeline)
Expand Down
1 change: 1 addition & 0 deletions BG3Extender/GameDefinitions/GameDefinitionHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <GameDefinitions/Status.inl>
#include <GameDefinitions/Surface.inl>
#include <GameDefinitions/Symbols.inl>
#include <GameDefinitions/Components/Camera.inl>
#include <GameDefinitions/Components/Effect.inl>
#include <GameDefinitions/Components/Level.inl>
#include <GameDefinitions/Components/Spell.inl>
Expand Down
7 changes: 7 additions & 0 deletions BG3Extender/GameDefinitions/Symbols.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ struct StaticSymbols : Noncopyable<StaticSymbols>
esv::GameStateThreaded__GameStateWorker__DoWorkProc* esv__GameStateThreaded__GameStateWorker__DoWork{ nullptr };
ecl::GameStateMachine__UpdateProc* ecl__GameStateMachine__Update{ nullptr };
esv::GameStateMachine__UpdateProc* esv__GameStateMachine__Update{ nullptr };
ecl::CameraSystem__UpdateCameraProc* ecl__CameraSystem__UpdateCamera{ nullptr };
ecl::CameraSystem__UpdateCameraPitchProc* ecl__CameraSystem__UpdateCameraPitch{ nullptr };
ecl::CameraSystem__UpdateCameraZoomProc* ecl__CameraSystem__UpdateCameraZoom{ nullptr };
ecl::GameCameraBehavior__GetCameraDefinitionProc* ecl__GameCameraBehavior__GetCameraDefinition{ nullptr };
ecl::GameCameraBehavior__CalculatePitchProc* ecl__GameCameraBehavior__CalculatePitch{ nullptr };
ecl::CameraSystem__HandleInputProc* ecl__CameraSystem__HandleInput{ nullptr };
ecl::CameraSystem__SetDefaultZoomProc* ecl__CameraSystem__SetDefaultZoom{ nullptr };
App__LoadGraphicSettingsProc* App__LoadGraphicSettings{ nullptr };
input::InputManager** ls__gInputManager{ nullptr };

Expand Down
59 changes: 59 additions & 0 deletions BG3Extender/GameHooks/BinaryMappings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,65 @@
<Target Type="Indirect" Offset="@ref4" Symbol="ecs__EntityWorld__Update" />
</Mapping>

<Mapping Name="ecl::CameraSystem::UpdateCamera">
@ref1 e8 ?? ?? ?? ?? // call ecl__CameraSystem__UpdateCamera
48 8d 8d f8 04 00 00 // lea rcx, [rbp+4F8h]
e8 ?? ?? ?? ?? // call cleanup
e9 af fd ff ff // jmp camera loop
<Target Type="Indirect" Offset="@ref1" Symbol="ecl__CameraSystem__UpdateCamera" />
</Mapping>

<Mapping Name="ecl::CameraSystem::UpdateCameraPitch">
f3 0f 11 6d f0 // movss [rbp-10h], xmm5
e8 ?? ?? ?? ?? // call Normalize
f2 0f 10 45 e8 // movsd xmm0, [rbp-18h]
8b 45 f0 // mov eax, [rbp-10h]
f2 0f 11 47 70 // movsd [rdi+70h], xmm0
89 47 78 // mov [rdi+78h], eax
4c 8b cb // mov r9, rbx
4c 8b c7 // mov r8, rdi
49 8b d6 // mov rdx, r14
49 8b cf // mov rcx, r15
@ref1 e8 ?? ?? ?? ?? // call ecl__CameraSystem__UpdateCameraPitch
48 8b 46 70 // mov rax, [rsi+70h]
<Target Type="Indirect" Offset="@ref1" Symbol="ecl__CameraSystem__UpdateCameraPitch" />
</Mapping>

<Mapping Name="ecl::CameraSystem::UpdateCameraZoom">
@ref1 e8 ?? ?? ?? ?? // call ecl__CameraSystem__UpdateCameraZoom
80 bf 54 02 00 00 00 // cmp byte ptr [rdi+254h], 0
<Target Type="Indirect" Offset="@ref1" Symbol="ecl__CameraSystem__UpdateCameraZoom" />
</Mapping>

<Mapping Name="ecl::GameCameraBehavior::GetCameraDefinition">
48 8b 05 ?? ?? ?? ?? // mov rax, cs:ls_GlobalSwitches
80 b8 32 13 00 00 00 // cmp byte ptr [rax+1332h], 0
74 07 // jz normal camera definition
<Target Type="Absolute" Offset="0" Symbol="ecl__GameCameraBehavior__GetCameraDefinition" />
</Mapping>

<Mapping Name="ecl::GameCameraBehavior::CalculatePitch">
@ref1 e8 ?? ?? ?? ?? // call ecl__GameCameraBehavior__CalculatePitch
80 bf 4c 01 00 00 00 // cmp byte ptr [rdi+14Ch], 0
<Target Type="Indirect" Offset="@ref1" Symbol="ecl__GameCameraBehavior__CalculatePitch" />
</Mapping>

<Mapping Name="ecl::CameraSystem::HandleInput">
@ref1 e8 ?? ?? ?? ?? // call ecl__CameraSystem__HandleInput
0f b7 08 // movzx ecx, word ptr [rax]
66 89 0b // mov [rbx], cx
80 3b 00 // cmp byte ptr [rbx], 0
<Target Type="Indirect" Offset="@ref1" Symbol="ecl__CameraSystem__HandleInput" />
</Mapping>

<Mapping Name="ecl::CameraSystem::SetDefaultZoom">
@ref1 e8 ?? ?? ?? ?? // call ecl__CameraSystem__SetDefaultZoom
48 8b cf // mov rcx, rdi
e8 ?? ?? ?? ?? // call camera mode update
e9 81 02 00 00 // jmp input handling continuation
<Target Type="Indirect" Offset="@ref1" Symbol="ecl__CameraSystem__SetDefaultZoom" />
</Mapping>

<Mapping Name="ecs__EntityWorld__FlushECBs">
48 83 be 00 03 00 00 00 // cmp qword ptr [rsi+300h], 0
74 08 // jz short loc_143693C93
Expand Down
7 changes: 7 additions & 0 deletions BG3Extender/GameHooks/DataLibrariesBG3Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,13 @@ namespace bg3se
SYM_OFF(esv__GameStateThreaded__GameStateWorker__DoWork);
SYM_OFF(ecl__GameStateMachine__Update);
SYM_OFF(esv__GameStateMachine__Update);
SYM_OFF(ecl__CameraSystem__UpdateCamera);
SYM_OFF(ecl__CameraSystem__UpdateCameraPitch);
SYM_OFF(ecl__CameraSystem__UpdateCameraZoom);
SYM_OFF(ecl__GameCameraBehavior__GetCameraDefinition);
SYM_OFF(ecl__GameCameraBehavior__CalculatePitch);
SYM_OFF(ecl__CameraSystem__HandleInput);
SYM_OFF(ecl__CameraSystem__SetDefaultZoom);
SYM_OFF(App__LoadGraphicSettings);
SYM_OFF(ls__gInputManager);

Expand Down
6 changes: 6 additions & 0 deletions BG3Extender/GameHooks/EngineHooks.inl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ HOOK_DEFN(esv__StatsSystem__ThrowDamageEvent, esv__StatsSystem__ThrowDamageEvent
HOOK_DEFN(eoc__AiGrid__FindPath, eoc__AiGrid__FindPath, AiGrid__FindPathProc)
HOOK_DEFN(ls__Visual__UpdateBlendshapeWeightsFromSkeleton, ls__Visual__UpdateBlendshapeWeightsFromSkeleton, Visual__UpdateBlendshapeWeightsFromSkeletonProc)
HOOK_DEFN(ui__DataContextProvider__ExecuteCommandQueues, ui__DataContextProvider__ExecuteCommandQueues, ui::DataContextProvider__ExecuteCommandQueuesProc)
HOOK_DEFN(ecl__CameraSystem__UpdateCamera, ecl__CameraSystem__UpdateCamera, ecl::CameraSystem__UpdateCameraProc)
HOOK_DEFN(ecl__CameraSystem__UpdateCameraPitch, ecl__CameraSystem__UpdateCameraPitch, ecl::CameraSystem__UpdateCameraPitchProc)
HOOK_DEFN(ecl__CameraSystem__UpdateCameraZoom, ecl__CameraSystem__UpdateCameraZoom, ecl::CameraSystem__UpdateCameraZoomProc)
HOOK_DEFN(ecl__GameCameraBehavior__CalculatePitch, ecl__GameCameraBehavior__CalculatePitch, ecl::GameCameraBehavior__CalculatePitchProc)
HOOK_DEFN(ecl__CameraSystem__HandleInput, ecl__CameraSystem__HandleInput, ecl::CameraSystem__HandleInputProc)
HOOK_DEFN(ecl__CameraSystem__SetDefaultZoom, ecl__CameraSystem__SetDefaultZoom, ecl::CameraSystem__SetDefaultZoomProc)

HOOK_DEFN(esv__ExecuteStatsFunctor_AttackTargetContext, esv__ExecuteStatsFunctor_AttackTargetContext, stats::ExecuteFunctorProc<stats::AttackTargetContextData>)
HOOK_DEFN(esv__ExecuteStatsFunctor_AttackPositionContext, esv__ExecuteStatsFunctor_AttackPositionContext, stats::ExecuteFunctorProc<stats::AttackPositionContextData>)
Expand Down
21 changes: 21 additions & 0 deletions BG3Extender/GameHooks/EngineHooksFwdDecl.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ struct AttackDesc;
struct FileReader;
struct AiGrid;
struct Visual;
struct CameraGlobalSwitches;

using AiPathId = int32_t;

Expand All @@ -39,6 +40,12 @@ using TextureManager__UnloadTextureProc = bool (TextureManager* self, FixedStrin

END_SE()

BEGIN_NS(input)

struct InputEvent;

END_NS()

BEGIN_NS(stats)

struct DealDamageFunctor;
Expand Down Expand Up @@ -112,11 +119,25 @@ END_NS()

BEGIN_NS(ecl)

struct GameCameraBehavior;
struct CameraUpdateTime;
struct CameraUpdateComponentView;
struct CameraZoomUpdateComponentView;
struct CameraInputComponentView;
struct CameraDefaultZoomComponentView;

using EoCClient__HandleErrorProc = void (EoCClient* self, TranslatedString const& message, bool exitGame, TranslatedString const& a4, uint8_t messageBoxLocalId);

using GameStateEventManager__ExecuteGameStateChangedEventProc = void (void* self, GameState fromState, GameState toState);
using GameStateThreaded__GameStateWorker__DoWorkProc = void (void* self);
using GameStateMachine__UpdateProc = void (void* self, GameTime* time);
using CameraSystem__UpdateCameraProc = void (void* self, void* systemContext, CameraUpdateTime const* time, CameraUpdateComponentView* view);
using CameraSystem__UpdateCameraPitchProc = void (void* self, void* entity, GameCameraBehavior* camera, CameraUpdateTime const* time);
using CameraSystem__UpdateCameraZoomProc = void (void* self, void* entity, CameraZoomUpdateComponentView* view, CameraUpdateTime const* time);
using GameCameraBehavior__GetCameraDefinitionProc = CameraGlobalSwitches* (GameCameraBehavior const* camera);
using GameCameraBehavior__CalculatePitchProc = float (GameCameraBehavior* camera, bool ignoreAvoidance, bool selectMode);
using CameraSystem__HandleInputProc = uint16_t* (void* self, uint16_t* result, CameraInputComponentView* view, input::InputEvent* inputEvent);
using CameraSystem__SetDefaultZoomProc = void (CameraDefaultZoomComponentView* view);

END_NS()

Expand Down
Loading