Skip to content

Commit

Permalink
Added a feature to invert shift when selecting easings.
Browse files Browse the repository at this point in the history
  • Loading branch information
sigma-axis committed Jul 11, 2024
1 parent 5160981 commit f6b1fa0
Show file tree
Hide file tree
Showing 6 changed files with 144 additions and 2 deletions.
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@

![フィルタ名表示変更](https://github.com/sigma-axis/aviutl_reactive_dlg/assets/132639613/251914ff-abf4-4854-945f-3fb15675d18c)

1. 標準描画の `X`, `Y`, `Z` などの「関連トラック」で `Shift` を押さなくても独立して変化方法を指定できるようになります.[[詳細](#関連トラックの変化方法指定時の-shift-キーを反転する機能)]

代わりに `Shift` を押しているときは関連トラックも連動して変化方法が設定されるようになります.

TODO: image.


## 動作要件

Expand Down Expand Up @@ -263,6 +269,16 @@
- ~~オリジナルと比べて書式が固定されている点で制約があります.~~
- **蛇色様のオリジナルを使う場合はこの機能は OFF にしておいてください.**

### 関連トラックの変化方法指定時の `Shift` キーを反転する機能

標準描画の `X`, `Y`, `Z` などは「関連トラック」となっていて,1つに対してトラックバー変化方法を選ぶと自動的に他の項目にも同じ変化方法が設定されるようになっています.`Shift` キーを押しながら選択することで独立して指定できますが,この挙動を反転して,

- `Shift` キーを押していないときは独立に指定
- `Shift` キーを押しているときは連動して指定

という挙動にします.

- 初期状態では OFF になっているので[設定ファイル](#easings)で有効化してください.

## 設定ファイルについて

Expand Down Expand Up @@ -494,6 +510,12 @@ rate_boost=10
- 初期値は `"{}(アニメーション効果)"` で,例えば `震える` だと `震える(アニメーション効果)` と表示されるようになります.
### `[Easings]`
[関連トラックの変化方法指定時の `Shift` キーを反転する機能](#関連トラックの変化方法指定時の-shift-キーを反転する機能)の有効,無効を切り替えられます.
- `linked_track_invert_shift` が `0` のとき無効, `1` で有効になります.初期値だと `linked_track_invert_shift=0` で無効.
## 謝辞
Expand All @@ -506,6 +528,10 @@ rate_boost=10
## 改版履歴
- **v1.50** (2024-07-??)
- 関連トラックの変化方法指定時に,`Shift` キーの認識を反転する機能を追加.
- **v1.42** (2024-07-10)
- トラックバーの数値入力ボックスのドラッグ中にホイール操作をした場合は,マウス位置に関わらずドラッグ中の数値が動くように変更.
Expand Down
13 changes: 13 additions & 0 deletions assets/reactive_dlg.ini
Original file line number Diff line number Diff line change
Expand Up @@ -258,3 +258,16 @@ anim_eff_fmt="{}(アニメーション効果)"
; ここでの指定が "" (空の文字列)の場合はこの機能を無効化します.
; 初期値は "{}(アニメーション効果)",文字数は UTF-8 で 256 バイトまで.


[Easings]
linked_track_invert_shift=0
; トラックバーの変化方法周りの UI を調整します.
; linked_track_invert_shift
; 標準描画の X, Y, Z など,「関連トラック」をの変化方法を指定する場合,
; 通常なら関連する項目全てに変化方法が適用され,
; Shift を押しながらだと1項目だけに適用されます.
; この Shift を押しているかどうかの判定を反転して,
; 「通常だと1項目だけ,Shift を押しながらだと関連トラック全て」にします.
; linked_track_invert_shift が 0 のとき無効,それ以外の整数で有効です.
; 初期値は 0 で無効.

79 changes: 79 additions & 0 deletions memory_protect.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#pragma once

#include <cstdint>
#include <memory>

#define NOMINMAX
#define WIN32_LEAN_AND_MEAN
#include <Windows.h>

//---------------------------------------------------------------------

namespace memory
{
class ProtectHelper {
uintptr_t const addr;
size_t const sz;
DWORD old_protect;

public:
template<class V> requires(!std::is_pointer_v<V>)
ProtectHelper(V address, size_t size) : addr{ static_cast<uintptr_t>(address) }, sz{ size } {
::VirtualProtect(as_ptr(), sz, PAGE_EXECUTE_READWRITE, &old_protect);
}
template<class T>
ProtectHelper(T* address, size_t size = sizeof(T)) :
ProtectHelper{ reinterpret_cast<uintptr_t>(address), size } {}
~ProtectHelper() {
::VirtualProtect(as_ptr(), sz, old_protect, &old_protect);
}

template<class T>
T& as_ref(ptrdiff_t offset = 0) const {
return *as_ptr<T>(offset);
}
template<class T = void>
T* as_ptr(ptrdiff_t offset = 0) const {
return reinterpret_cast<T*>(addr + offset);
}
size_t size() const { return sz; }

template<class T, size_t N>
void copy(T const(&src)[N], ptrdiff_t offset = 0) const {
copy(&src[0], N, offset);
}
template<class T>
void copy(T const* src, size_t count_elem, ptrdiff_t offset = 0) const {
if constexpr (!std::is_void_v<T>) count_elem *= sizeof(T);
std::memcpy(as_ptr(offset), src, count_elem);
}

static void write(auto address, auto data) {
ProtectHelper(address, sizeof(data)).as_ref<decltype(data)>() = data;
}
template<class T, size_t N>
static void copy(auto address, T const(&data)[N]) {
ProtectHelper(address, sizeof(data)).copy(data);
}
};

// ff 15 xx xx xx xx // call dword ptr ds:[xxxxxxxx]
// v
// e8 yy yy yy yy // call yyyyyyyy
// 90 // nop
inline void hook_api_call(auto* address, auto* hook_func)
{
auto const
addr = reinterpret_cast<uintptr_t>(address),
proc = reinterpret_cast<uintptr_t>(hook_func);

uint8_t code[6];
code[0] = 0xe8; // call
*reinterpret_cast<uintptr_t*>(&code[1]) = proc - (addr + 5);
code[5] = 0x90; // nop

ProtectHelper::copy(addr, code);
}
}

//---------------------------------------------------------------------
25 changes: 24 additions & 1 deletion reactive_dlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ using namespace ExEdit;

#include "modkeys.hpp"
#include "slim_formatter.hpp"
#include "memory_protect.hpp"

////////////////////////////////
// 主要情報源の変数アドレス.
Expand Down Expand Up @@ -115,6 +116,8 @@ inline constinit struct ExEdit092 {
intptr_t* exdata_table; // 0x1e0fa8
char const* basic_animation_names; // 0x0c1f08

void* call_GetKeyState_easing; // 0x02ca87

private:
void init_pointers()
{
Expand All @@ -137,6 +140,8 @@ inline constinit struct ExEdit092 {
pick_addr(filter_separators, 0x1790d8);
pick_addr(exdata_table, 0x1e0fa8);
pick_addr(basic_animation_names, 0x0c1f08);

pick_addr(call_GetKeyState_easing, 0x02ca87);
}
} exedit;

Expand Down Expand Up @@ -813,6 +818,14 @@ struct FilterName : SettingDlg {
};


////////////////////////////////
// トラックバーの変化方法の調整.
////////////////////////////////
SHORT WINAPI inv_GetKeyState(int nVirtKey) {
return 0xff80 ^ ::GetKeyState(nVirtKey);
}


////////////////////////////////
// 設定項目.
////////////////////////////////
Expand Down Expand Up @@ -923,6 +936,10 @@ inline constinit struct Settings {
bool is_enabled() const { return static_cast<bool>(anim_eff_fmt); }
} filterName{ nullptr };

struct {
bool linked_track_invert_shift;
} easings{ false };

constexpr bool is_enabled() const
{
return textFocus.is_enabled() || textTweaks.is_enabled() ||
Expand Down Expand Up @@ -1002,6 +1019,8 @@ inline constinit struct Settings {

load_str0(filterName., anim_eff_fmt, "FilterName", "{}(アニメーション効果)", filterName.max_anim_eff_fmt_length, "");

load_bool(easings., linked_track_invert_shift, "Easings");

#undef load_str
#undef load_key
#undef load_bool
Expand Down Expand Up @@ -1655,6 +1674,10 @@ BOOL func_init(FilterPlugin* fp)
fp->name, MB_OK | MB_ICONEXCLAMATION);
}

// トラックバーの変化方法の調整.
if (settings.easings.linked_track_invert_shift)
memory::hook_api_call(exedit.call_GetKeyState_easing, &inv_GetKeyState);

return TRUE;
}

Expand Down Expand Up @@ -1740,7 +1763,7 @@ BOOL WINAPI DllMain(HINSTANCE hinst, DWORD fdwReason, LPVOID lpvReserved)
// 看板.
////////////////////////////////
#define PLUGIN_NAME "Reactive Dialog"
#define PLUGIN_VERSION "v1.42"
#define PLUGIN_VERSION "v1.50-beta1"
#define PLUGIN_AUTHOR "sigma-axis"
#define PLUGIN_INFO_FMT(name, ver, author) (name##" "##ver##" by "##author)
#define PLUGIN_INFO PLUGIN_INFO_FMT(PLUGIN_NAME, PLUGIN_VERSION, PLUGIN_AUTHOR)
Expand Down
1 change: 1 addition & 0 deletions reactive_dlg.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClInclude Include="memory_protect.hpp" />
<ClInclude Include="modkeys.hpp" />
<ClInclude Include="slim_formatter.hpp" />
</ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion slim_formatter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class slim_formatter {
base = fmt;
holes.clear();

// find the patern "{*}?" (e.g. "{}", "{{{}", "{{{{{"),
// find the patern "{+}?" (e.g. "{}", "{{{}", "{{{{{"),
// and modify it for future use.
size_t i = 0;
while ((i = base.find_first_of(L'{', i)) < base.size()) {
Expand Down

0 comments on commit f6b1fa0

Please sign in to comment.