Skip to content

Commit

Permalink
No Dynamic Difficulty (#17)
Browse files Browse the repository at this point in the history
* Create the RankPointType enum.

* Rename `post_update_pitch_yaw`.

* Hook `GameRankSystem::addRankPointDirect`.

* Implement the `addRankPointDirect` hook.

* Add comment.

* Make `rankType` const.

* formatting
  • Loading branch information
TheTedder authored Nov 22, 2022
1 parent 7500a89 commit 58021c8
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 4 deletions.
17 changes: 17 additions & 0 deletions Enums.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#pragma once
#include <cstdint>

namespace REFix {
enum class RankPointType : int32_t {
PlAttackHit = 0,
PlGetItem = 1,
PlDamage = 2,
PlRetry = 3,
FromFsm = 4,
FromScript = 5,
FromDirectSet = 6,
PlUseWeapon = 7,
PlUseDefenceItem = 8,
FromDebug = 9
};
}
17 changes: 16 additions & 1 deletion Hooks.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
#include "Hooks.h"
#include "Enums.h"

namespace REFix {
const float DEFAULT_FOV = 90.0f;
extern const REF::API::Field* camera_param_field;
extern const REF::API::Field* field_of_view_field;

void post_hook_null(void** ret_val, REFrameworkTypeDefinitionHandle ret_ty) {}

int pre_update_pitch_yaw(int argc, void** argv, REFrameworkTypeDefinitionHandle* arg_tys) {
REF::API::ManagedObject* const camera_param = camera_param_field->get_data<REF::API::ManagedObject*>(argv[1]);
const float fov = *(float*)field_of_view_field->get_data_raw(camera_param);
Expand All @@ -14,5 +17,17 @@ namespace REFix {
return REFRAMEWORK_HOOK_CALL_ORIGINAL;
}

void post_update_pitch_yaw(void** ret_val, REFrameworkTypeDefinitionHandle ret_ty) {}
int pre_add_rank_point_direct(int argc, void** argv, REFrameworkTypeDefinitionHandle* arg_tys)
{
const RankPointType rankType = *(RankPointType*)&argv[3];

if (rankType == RankPointType::FromFsm ||
rankType == RankPointType::FromScript ||
rankType == RankPointType::FromDirectSet ||
rankType == RankPointType::FromDebug) {
return REFRAMEWORK_HOOK_CALL_ORIGINAL;
}

return REFRAMEWORK_HOOK_SKIP_ORIGINAL;
}
}
3 changes: 2 additions & 1 deletion Hooks.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "REFix.h"

namespace REFix {
void post_hook_null(void** ret_val, REFrameworkTypeDefinitionHandle ret_ty);
int pre_update_pitch_yaw(int argc, void** argv, REFrameworkTypeDefinitionHandle* arg_tys);
void post_update_pitch_yaw(void** ret_val, REFrameworkTypeDefinitionHandle ret_ty);
int pre_add_rank_point_direct(int argc, void** argv, REFrameworkTypeDefinitionHandle* arg_tys);
}
1 change: 1 addition & 0 deletions REFix.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@
<ClInclude Include="AnimationCurveMutator.h" />
<ClInclude Include="AnimCurveStraightener.h" />
<ClInclude Include="AnimCurveFlattener.h" />
<ClInclude Include="Enums.h" />
<ClInclude Include="Hooks.h" />
<ClInclude Include="init.h" />
<ClInclude Include="REFix.h" />
Expand Down
3 changes: 3 additions & 0 deletions REFix.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
<ClInclude Include="Hooks.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Enums.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="AnimationCurveMutator.cpp">
Expand Down
8 changes: 6 additions & 2 deletions init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,11 @@ bool reframework_plugin_initialize(const REFrameworkPluginInitializeParam* param

// Scale the input by the current FOV.

twirler_camera_controller_root_type->find_method("updatePitch")->add_hook(REFix::pre_update_pitch_yaw, REFix::post_update_pitch_yaw, false);
twirler_camera_controller_root_type->find_method("updateYaw")->add_hook(REFix::pre_update_pitch_yaw, REFix::post_update_pitch_yaw, false);
twirler_camera_controller_root_type->find_method("updatePitch")->add_hook(REFix::pre_update_pitch_yaw, REFix::post_hook_null, false);
twirler_camera_controller_root_type->find_method("updateYaw")->add_hook(REFix::pre_update_pitch_yaw, REFix::post_hook_null, false);

// Remove dynamic difficulty modulation.

tdb->find_method("app.ropeway.GameRankSystem", "addRankPointDirect")->add_hook(REFix::pre_add_rank_point_direct, REFix::post_hook_null, false);
return true;
}

0 comments on commit 58021c8

Please sign in to comment.