修訂 | 81592854ffbe85605746675762b6d0f867feb957 (tree) |
---|---|
時間 | 2021-04-14 23:08:26 |
作者 | majiponi <majiponi@yaho...> |
Commiter | majiponi |
Now you can save project via -o switch.
@@ -161,6 +161,7 @@ | ||
161 | 161 | </ItemDefinitionGroup> |
162 | 162 | <ItemGroup> |
163 | 163 | <ClInclude Include="apihook.h" /> |
164 | + <ClInclude Include="command.h" /> | |
164 | 165 | <ClInclude Include="core.h" /> |
165 | 166 | <ClInclude Include="parser.h" /> |
166 | 167 | <ClInclude Include="filter.h" /> |
@@ -170,6 +171,7 @@ | ||
170 | 171 | </ItemGroup> |
171 | 172 | <ItemGroup> |
172 | 173 | <ClCompile Include="apihook.cpp" /> |
174 | + <ClCompile Include="command.cpp" /> | |
173 | 175 | <ClCompile Include="core.cpp" /> |
174 | 176 | <ClCompile Include="parser.cpp" /> |
175 | 177 | <ClCompile Include="stdafx.cpp"> |
@@ -36,6 +36,9 @@ | ||
36 | 36 | <ClInclude Include="parser.h"> |
37 | 37 | <Filter>ヘッダー ファイル</Filter> |
38 | 38 | </ClInclude> |
39 | + <ClInclude Include="command.h"> | |
40 | + <Filter>ヘッダー ファイル</Filter> | |
41 | + </ClInclude> | |
39 | 42 | </ItemGroup> |
40 | 43 | <ItemGroup> |
41 | 44 | <ClCompile Include="stdafx.cpp"> |
@@ -53,6 +56,9 @@ | ||
53 | 56 | <ClCompile Include="parser.cpp"> |
54 | 57 | <Filter>ソース ファイル</Filter> |
55 | 58 | </ClCompile> |
59 | + <ClCompile Include="command.cpp"> | |
60 | + <Filter>ソース ファイル</Filter> | |
61 | + </ClCompile> | |
56 | 62 | </ItemGroup> |
57 | 63 | <ItemGroup> |
58 | 64 | <None Include="aus.def"> |
@@ -0,0 +1,125 @@ | ||
1 | +#include "stdafx.h" | |
2 | +#include <commdlg.h> | |
3 | +#include <algorithm> | |
4 | +#include <typeinfo> | |
5 | + | |
6 | +#include "apihook.h" | |
7 | +#include "ui.h" | |
8 | + | |
9 | +namespace | |
10 | +{ | |
11 | + HWND getExeditWindow(); | |
12 | + | |
13 | + union{ | |
14 | + int scene_no; | |
15 | + struct{ unsigned int cx, cy, fps, freq; }* videoinfo; | |
16 | + const char* path; | |
17 | + bool transparent; | |
18 | + } dlgdata; | |
19 | +} | |
20 | + | |
21 | +namespace AviUtlCommand | |
22 | +{ | |
23 | + void CreateProject(size_t cx, size_t cy, size_t fps, size_t freq) | |
24 | + { | |
25 | + HMODULE ex = GetModuleHandleA("exedit.auf"); | |
26 | + if(!ex) return; | |
27 | + | |
28 | + std::remove_pointer<decltype(dlgdata.videoinfo)>::type data{ cx, cy, fps, freq }; | |
29 | + dlgdata.videoinfo = &data; | |
30 | + | |
31 | + IATModifier hook1{ "user32.dll", "DialogBoxParamA", static_cast<decltype(DialogBoxParamA)*>([](HINSTANCE, LPCSTR, HWND, DLGPROC proc, LPARAM) -> INT_PTR { | |
32 | + proc(nullptr, WM_COMMAND, IDOK, 0); | |
33 | + return IDOK; | |
34 | + }), ex }; | |
35 | + IATModifier hook2{ "user32.dll", "GetDlgItemInt", static_cast<decltype(GetDlgItemInt)*>([](HWND, int id, BOOL*, BOOL) -> UINT { | |
36 | + if(id == 171) return dlgdata.videoinfo->cx; | |
37 | + if(id == 172) return dlgdata.videoinfo->cy; | |
38 | + return dlgdata.videoinfo->freq; | |
39 | + }), ex }; | |
40 | + IATModifier hook3{ "user32.dll", "GetDlgItemTextA", static_cast<decltype(GetDlgItemTextA)*>([](HWND, int, char* buf, int nmax) -> UINT { | |
41 | + return sprintf_s(buf, nmax, "%d", dlgdata.videoinfo->fps); | |
42 | + }), ex }; | |
43 | + | |
44 | + SendMessageA(getExeditWindow(), WM_COMMAND, 1030, 0xFFFFFFFF); | |
45 | + } | |
46 | + | |
47 | + void OpenExoFile(const char* path) | |
48 | + { | |
49 | + dlgdata.path = path; | |
50 | + IATModifier hook3{ "comdlg32.dll", "GetOpenFileNameA", static_cast<decltype(GetOpenFileNameA)*>([](LPOPENFILENAMEA pofn) -> BOOL { | |
51 | + strcpy_s(pofn->lpstrFile, pofn->nMaxFile, dlgdata.path); | |
52 | + return TRUE; | |
53 | + }), GetModuleHandleA(nullptr) }; | |
54 | + | |
55 | + SendMessageA(getExeditWindow(), WM_COMMAND, 1037, 0xFFFFFFFF); | |
56 | + } | |
57 | + | |
58 | + void Quit() | |
59 | + { | |
60 | + PostMessageA(AviUtlUI::GetMainWindow(), WM_CLOSE, 0, 0); | |
61 | + } | |
62 | + | |
63 | + void SaveProject(const char* path) | |
64 | + { | |
65 | + dlgdata.path = path; | |
66 | + IATModifier hook3{ "comdlg32.dll", "GetSaveFileNameA", static_cast<decltype(GetSaveFileNameA)*>([](LPOPENFILENAMEA pofn) -> BOOL { | |
67 | + strcpy_s(pofn->lpstrFile, pofn->nMaxFile, dlgdata.path); | |
68 | + return TRUE; | |
69 | + }), GetModuleHandleA(nullptr) }; | |
70 | + | |
71 | + SendMessageA(AviUtlUI::GetMainWindow(), WM_COMMAND, 1023, 0xFFFFFFFF); | |
72 | + } | |
73 | + | |
74 | + void SwitchScene(size_t n) | |
75 | + { | |
76 | + HMODULE ex = GetModuleHandleA("exedit.auf"); | |
77 | + if(!ex || n < 0 || n >= 50) return; | |
78 | + | |
79 | + dlgdata.scene_no = n; | |
80 | + IATModifier hook1{ "user32.dll", "DialogBoxParamA", static_cast<decltype(DialogBoxParamA)*>([](HINSTANCE, LPCSTR, HWND, DLGPROC proc, LPARAM) -> INT_PTR { | |
81 | + proc(nullptr, WM_COMMAND, MAKEWPARAM(190, LBN_SELCHANGE), 0); | |
82 | + return dlgdata.scene_no; | |
83 | + }), ex }; | |
84 | + IATModifier hook2{ "user32.dll", "SendDlgItemMessageA", static_cast<decltype(SendDlgItemMessageA)*>([](HWND, int, UINT, WPARAM, LPARAM) -> LRESULT { | |
85 | + return dlgdata.scene_no; | |
86 | + }), ex }; | |
87 | + | |
88 | + SendMessageA(getExeditWindow(), WM_LBUTTONDOWN, MK_LBUTTON, 0); | |
89 | + } | |
90 | + | |
91 | + void TransparentScene(bool b) | |
92 | + { | |
93 | + HMODULE ex = GetModuleHandleA("exedit.auf"); | |
94 | + if(!ex) return; | |
95 | + | |
96 | + dlgdata.transparent = b; | |
97 | + IATModifier hook1{ "user32.dll", "DialogBoxParamA", static_cast<decltype(DialogBoxParamA)*>([](HINSTANCE, LPCSTR, HWND, DLGPROC proc, LPARAM) -> INT_PTR { | |
98 | + proc(nullptr, WM_COMMAND, IDOK, 0); | |
99 | + return IDOK; | |
100 | + }), ex }; | |
101 | + IATModifier hook2{ "user32.dll", "IsDlgButtonChecked", static_cast<decltype(IsDlgButtonChecked)*>([](HWND, int) -> UINT { | |
102 | + return dlgdata.transparent ? BST_CHECKED : BST_UNCHECKED; | |
103 | + }), ex }; | |
104 | + | |
105 | + SendMessageA(getExeditWindow(), WM_COMMAND, 1096, 0xFFFFFFFF); | |
106 | + } | |
107 | + | |
108 | +} | |
109 | + | |
110 | +namespace | |
111 | +{ | |
112 | + HWND getExeditWindow() | |
113 | + { | |
114 | + HWND ret = nullptr; | |
115 | + EnumThreadWindows(GetCurrentThreadId(), static_cast<WNDENUMPROC>([](HWND hwnd, LPARAM data) -> BOOL { | |
116 | + static constexpr char head[] = "拡張編集"; | |
117 | + char buf[16]; | |
118 | + GetWindowTextA(hwnd, buf, std::size(buf)); | |
119 | + if(std::memcmp(buf, head, sizeof(head)-1)) return TRUE; | |
120 | + *reinterpret_cast<HWND*>(data) = hwnd; | |
121 | + return FALSE; | |
122 | + }), reinterpret_cast<LPARAM>(&ret)); | |
123 | + return ret; | |
124 | + } | |
125 | +} |
@@ -0,0 +1,11 @@ | ||
1 | +#pragma once | |
2 | + | |
3 | +namespace AviUtlCommand | |
4 | +{ | |
5 | + void CreateProject(size_t cx, size_t cy, size_t fps, size_t freq); | |
6 | + void OpenExoFile(const char* path); | |
7 | + void Quit(); | |
8 | + void SaveProject(const char* path); | |
9 | + void SwitchScene(size_t n); | |
10 | + void TransparentScene(bool b); | |
11 | +} |
@@ -1,5 +1,7 @@ | ||
1 | 1 | #include "stdafx.h" |
2 | 2 | #include <utility> |
3 | +#include "command.h" | |
4 | +#include "core.h" | |
3 | 5 | #include "parser.h" |
4 | 6 | #include "ui.h" |
5 | 7 |
@@ -16,7 +18,7 @@ namespace | ||
16 | 18 | size_t offset; |
17 | 19 | void* proc; |
18 | 20 | size_t bytes; |
19 | - } patch[4]; | |
21 | + } patch[5]; | |
20 | 22 | }; |
21 | 23 | |
22 | 24 | BOOL init(FILTER*); |
@@ -26,13 +28,18 @@ namespace | ||
26 | 28 | void Reload1(); |
27 | 29 | void Reset1(); |
28 | 30 | void Loader1(); |
29 | - constexpr patchdata makeVer2Patch(size_t, size_t); | |
31 | + void Save1(); | |
32 | + constexpr patchdata makeVer2Patch(size_t, size_t, size_t); | |
30 | 33 | void Socket(void*, const char*); |
31 | 34 | void ClearBuffer2(); |
32 | 35 | void Reload2(); |
33 | 36 | void Reset2(); |
34 | 37 | void Loader2(); |
38 | + void Save2(); | |
35 | 39 | size_t recalc(size_t, size_t, const char*); |
40 | + bool is_aup_path(const char*); | |
41 | + void ModifyReturnAddress(size_t); | |
42 | + | |
36 | 43 | inline const IMAGE_NT_HEADERS32* getNtHeaders(HMODULE); |
37 | 44 | inline DWORD getTimeStamp(HMODULE); |
38 | 45 | inline size_t getTextSectionSize(HMODULE); |
@@ -50,12 +57,13 @@ namespace | ||
50 | 57 | constexpr size_t bufsize = 0x1000; |
51 | 58 | } |
52 | 59 | |
60 | + | |
53 | 61 | extern "C" const FILTER_DLL* CALLBACK GetFilterTable() |
54 | 62 | { |
55 | 63 | static constexpr FILTER_DLL filter = { |
56 | 64 | FILTER_FLAG_ALWAYS_ACTIVE | FILTER_FLAG_NO_CONFIG | FILTER_FLAG_IMPORT, |
57 | 65 | 0, 0, const_cast<char*>("Script Engine"), 0, nullptr, nullptr, 0, 0, 0, nullptr, nullptr, nullptr, |
58 | - init, nullptr, nullptr, wndproc, nullptr, nullptr, nullptr, 0, nullptr, nullptr, nullptr | |
66 | + init, nullptr, nullptr, AviUtlUI::WndProc, nullptr, nullptr, nullptr, 0, nullptr, nullptr, nullptr | |
59 | 67 | }; |
60 | 68 | return &filter; |
61 | 69 | } |
@@ -67,12 +75,12 @@ namespace | ||
67 | 75 | const patchdata* p = getpatch(); |
68 | 76 | if(!p) return FALSE; |
69 | 77 | |
70 | - addmenu(); | |
78 | + AviUtlUI::AddMenu(); | |
71 | 79 | applypatch(p); |
72 | 80 | return TRUE; |
73 | 81 | } |
74 | 82 | |
75 | - constexpr patchdata makeVer1Patch(size_t offset_engine, size_t offset_parser) | |
83 | + constexpr patchdata makeVer1Patch(size_t offset_engine, size_t offset_saver, size_t offset_parser) | |
76 | 84 | { |
77 | 85 | return { offset_parser + 0x48, offset_parser + 0x40, |
78 | 86 | { offset_engine, nullptr }, |
@@ -80,7 +88,8 @@ namespace | ||
80 | 88 | { offset_engine + 0x2D, ClearBuffer1, 5 }, |
81 | 89 | { offset_parser + 0x07, Reload1, 6 }, |
82 | 90 | { offset_parser + 0x2E, Reset1, 5 }, |
83 | - { offset_engine + 0x47, Loader1, 5 } | |
91 | + { offset_engine + 0x47, Loader1, 5 }, | |
92 | + { offset_saver + 0x7D3, Save1, 7 } | |
84 | 93 | } |
85 | 94 | }; |
86 | 95 | } |
@@ -136,7 +145,7 @@ namespace | ||
136 | 145 | lea edx, [esp+12] |
137 | 146 | push edx |
138 | 147 | push edx |
139 | - call ScriptParser | |
148 | + call SubParser | |
140 | 149 | add esp, 4 |
141 | 150 | xor ecx, ecx |
142 | 151 | pop edx |
@@ -149,7 +158,38 @@ namespace | ||
149 | 158 | } |
150 | 159 | } |
151 | 160 | |
152 | - constexpr patchdata makeVer2Patch(size_t offset_engine, size_t offset_parser) | |
161 | + __declspec(naked) void Save1() | |
162 | + { | |
163 | + __asm{ | |
164 | + lea eax, [ebp+0x108] | |
165 | + push eax | |
166 | + call is_aup_path | |
167 | + add esp, 4 | |
168 | + test eax, eax | |
169 | + jne SAVE_AUP | |
170 | + mov eax, [esp] | |
171 | + cmp [ebp+0x4BC498], 2 | |
172 | + jl SAVE_AVI | |
173 | + add eax, 8 | |
174 | + mov [esp], eax | |
175 | + ret | |
176 | + SAVE_AVI: | |
177 | + add eax, 0x110 | |
178 | + mov [esp], eax | |
179 | + ret | |
180 | + SAVE_AUP: | |
181 | + mov eax, [esp] | |
182 | + add eax, 0x6A | |
183 | + mov [esp], eax | |
184 | + lea eax, [ebp+0x108] | |
185 | + push eax | |
186 | + call AviUtlCommand::SaveProject | |
187 | + add esp, 4 | |
188 | + ret | |
189 | + } | |
190 | + } | |
191 | + | |
192 | + constexpr patchdata makeVer2Patch(size_t offset_engine, size_t offset_saver, size_t offset_parser) | |
153 | 193 | { |
154 | 194 | return { offset_parser + 0x64, offset_parser + 0x5E, |
155 | 195 | { offset_engine, Socket }, |
@@ -157,7 +197,8 @@ namespace | ||
157 | 197 | { offset_engine + 0x42D, ClearBuffer2, 7 }, |
158 | 198 | { offset_parser + 0x20, Reload2, 5 }, |
159 | 199 | { offset_parser + 0x48, Reset2, 8 }, |
160 | - { offset_engine + 0x450, Loader2, 7 } | |
200 | + { offset_engine + 0x450, Loader2, 7 }, | |
201 | + { offset_saver + 0xAE9, Save2, 7 } | |
161 | 202 | } |
162 | 203 | }; |
163 | 204 | } |
@@ -216,7 +257,7 @@ namespace | ||
216 | 257 | lea edx, [esp+44Ch] |
217 | 258 | push edx |
218 | 259 | push edx |
219 | - call ScriptParser | |
260 | + call SubParser | |
220 | 261 | add esp, 4 |
221 | 262 | xor ecx, ecx |
222 | 263 | pop edx |
@@ -226,6 +267,42 @@ namespace | ||
226 | 267 | } |
227 | 268 | } |
228 | 269 | |
270 | + __declspec(naked) void Save2() | |
271 | + { | |
272 | + __asm{ | |
273 | + lea eax, [ebx+0x108] | |
274 | + push eax | |
275 | + call is_aup_path | |
276 | + add esp, 4 | |
277 | + test eax, eax | |
278 | + jne SAVE_AUP | |
279 | + mov eax, [esp] | |
280 | + cmp dword ptr [ebx+004BC498h],2 | |
281 | + mov dword ptr [esp+3Ch],edx | |
282 | + jl SAVE_AVI | |
283 | + add eax, 12 | |
284 | + mov [esp], eax | |
285 | + ret | |
286 | + SAVE_AVI: | |
287 | + add eax, 0x19F | |
288 | + mov [esp], eax | |
289 | + ret | |
290 | + SAVE_AUP: | |
291 | +// mov eax, [esp] | |
292 | +// add eax, 0x11C | |
293 | +// mov [esp], eax | |
294 | + lea eax, [ebx+0x108] | |
295 | + push eax | |
296 | + call AviUtlCommand::SaveProject | |
297 | + add esp, 4 | |
298 | + xor eax, eax | |
299 | + push 0x11C | |
300 | + call ModifyReturnAddress | |
301 | + add esp, 4 | |
302 | + ret | |
303 | + } | |
304 | + } | |
305 | + | |
229 | 306 | void applypatch(const patchdata* p) |
230 | 307 | { |
231 | 308 | HMODULE base = GetModuleHandleA(nullptr); |
@@ -256,6 +333,26 @@ namespace | ||
256 | 333 | return offset; |
257 | 334 | } |
258 | 335 | |
336 | + bool is_aup_path(const char* path) | |
337 | + { | |
338 | + static constexpr char ext[] = ".aup"; | |
339 | + static constexpr size_t extlen = sizeof(ext) - 1; | |
340 | + | |
341 | + size_t len = std::strlen(path); | |
342 | + return len > extlen && !_strcmpi(path + len - extlen, ext); | |
343 | + } | |
344 | + | |
345 | + void ModifyReturnAddress(size_t off) | |
346 | + { | |
347 | + _asm{ | |
348 | + push eax | |
349 | + mov eax, [ebp+12] | |
350 | + add eax, off | |
351 | + mov [ebp+12], eax | |
352 | + pop eax | |
353 | + } | |
354 | + } | |
355 | + | |
259 | 356 | inline const IMAGE_NT_HEADERS32* getNtHeaders(HMODULE base) |
260 | 357 | { |
261 | 358 | const IMAGE_DOS_HEADER* dos = reinterpret_cast<const IMAGE_DOS_HEADER*>(base); |
@@ -274,15 +371,15 @@ namespace | ||
274 | 371 | |
275 | 372 | const patchdata* getpatch() |
276 | 373 | { |
277 | - static constexpr patchdata VER_0_99_k = makeVer1Patch(0xC7F0, 0x22A80); | |
278 | - static constexpr patchdata VER_0_99_k2 = makeVer1Patch(0xC830, 0x22BF0); | |
279 | - static constexpr patchdata VER_0_99_l = makeVer1Patch(0xC8F0, 0x22DC0); | |
280 | - static constexpr patchdata VER_0_99_m = makeVer1Patch(0xC950, 0x22EA0); | |
281 | - static constexpr patchdata VER_1_00 = makeVer1Patch(0xC990, 0x22F70); | |
282 | - | |
283 | - static constexpr patchdata VER_1_10_rc1 = makeVer2Patch(0xF910, 0x2C010); | |
284 | - static constexpr patchdata VER_1_10_rc2 = makeVer2Patch(0xFAE0, 0x2C1E0); | |
285 | - static constexpr patchdata VER_1_10 = makeVer2Patch(0xFA20, 0x2C0F0); | |
374 | + static constexpr patchdata VER_0_99_k = makeVer1Patch(0xC7F0, 0x14F60, 0x22A80); | |
375 | + static constexpr patchdata VER_0_99_k2 = makeVer1Patch(0xC830, 0x14F90, 0x22BF0); | |
376 | + static constexpr patchdata VER_0_99_l = makeVer1Patch(0xC8F0, 0x15120, 0x22DC0); | |
377 | + static constexpr patchdata VER_0_99_m = makeVer1Patch(0xC950, 0x151B0, 0x22EA0); | |
378 | + static constexpr patchdata VER_1_00 = makeVer1Patch(0xC990, 0x15260, 0x22F70); | |
379 | + | |
380 | + static constexpr patchdata VER_1_10_rc1 = makeVer2Patch(0xF910, 0x1A0A0, 0x2C010); | |
381 | + static constexpr patchdata VER_1_10_rc2 = makeVer2Patch(0xFAE0, 0x1A270, 0x2C1E0); | |
382 | + static constexpr patchdata VER_1_10 = makeVer2Patch(0xFA20, 0x1A1A0, 0x2C0F0); | |
286 | 383 | |
287 | 384 | switch(getTimeStamp(GetModuleHandleA(nullptr))){ |
288 | 385 | case 0x4F01F831: return &VER_0_99_k; |
@@ -4,187 +4,74 @@ | ||
4 | 4 | #include <typeinfo> |
5 | 5 | |
6 | 6 | #include "apihook.h" |
7 | +#include "command.h" | |
8 | +#include "core.h" | |
7 | 9 | #include "parser.h" |
8 | 10 | #include "ui.h" |
9 | 11 | |
10 | 12 | namespace |
11 | 13 | { |
12 | - void quit(); | |
13 | - void save(const char* path); | |
14 | - | |
15 | - void newproject(size_t cx, size_t cy, size_t fps, size_t freq); | |
16 | - void openexo(const char* path); | |
17 | - void switchscene(size_t n); | |
18 | - void transparentscene(bool b); | |
19 | - | |
20 | - HWND getExeditWindow(); | |
21 | - | |
22 | 14 | bool is_comment(const char*); |
23 | 15 | bool is_loading_script(const char*); |
24 | 16 | size_t starts_with(const char*, const char*); |
25 | 17 | size_t ends_with(const char*, const char*); |
18 | + bool has_argument(const char*); | |
26 | 19 | const char* skiparg(const char*); |
27 | - | |
28 | - | |
29 | - union{ | |
30 | - int scene_no; | |
31 | - struct{ unsigned int cx, cy, fps, freq; }* videoinfo; | |
32 | - const char* path; | |
33 | - bool transparent; | |
34 | - } dlgdata; | |
35 | 20 | } |
36 | 21 | |
37 | -BOOL ScriptParser(const char* script) | |
22 | +bool SubParser(const char* script) | |
38 | 23 | { |
39 | - OutputDebugStringA(script); | |
40 | - OutputDebugStringA("\r\n"); | |
41 | - | |
42 | - if(is_comment(script)) return FALSE; | |
43 | - if(is_loading_script(script)) return FALSE; | |
24 | + if(is_comment(script)) return false; | |
25 | + if(is_loading_script(script)) return false; | |
44 | 26 | |
45 | 27 | size_t match; |
46 | 28 | if(match = starts_with(script, "exedit ")){ |
47 | 29 | HMODULE base = GetModuleHandleA("exedit.auf"); |
48 | - if(!base) return FALSE; | |
30 | + if(!base) return false; | |
49 | 31 | |
50 | 32 | script += match; |
51 | 33 | |
52 | 34 | unsigned int params[4]; |
53 | 35 | if(sscanf_s(script, "new %u, %u, %u, %u", ¶ms[0], ¶ms[1], ¶ms[2], ¶ms[3]) == 4){ |
54 | - newproject(params[0], params[1], params[2], params[3]); | |
55 | - return FALSE; | |
36 | + AviUtlCommand::CreateProject(params[0], params[1], params[2], params[3]); | |
37 | + return false; | |
56 | 38 | } |
57 | 39 | else if(match = starts_with(script, "openexo ")){ |
58 | 40 | script += match; |
59 | - openexo(script); | |
60 | - return FALSE; | |
41 | + AviUtlCommand::OpenExoFile(script); | |
42 | + return false; | |
61 | 43 | } |
62 | 44 | else if(sscanf_s(script, "switchscene #%u", ¶ms[0]) == 1){ |
63 | - switchscene(params[0]); | |
64 | - return FALSE; | |
45 | + AviUtlCommand::SwitchScene(params[0]); | |
46 | + return false; | |
65 | 47 | } |
66 | 48 | else if(match = starts_with(script, "transparentscene ")){ |
67 | 49 | script += match; |
68 | - transparentscene(script[0] != 'f'); | |
69 | - return FALSE; | |
50 | + AviUtlCommand::TransparentScene(script[0] != 'f'); | |
51 | + return false; | |
70 | 52 | } |
71 | 53 | } |
72 | 54 | else{ |
73 | 55 | script = skiparg(script); |
74 | - if(script[0] == '-' && script[1] == 'q'){ | |
75 | - quit(); | |
76 | - return FALSE; | |
56 | + if((script[0] == '-' || script[0] == '/') && (script[1] == 'q' || script[1] == 'Q')){ | |
57 | + script += 2; | |
58 | + if(!has_argument(script)){ | |
59 | + AviUtlCommand::Quit(); | |
60 | + return false; | |
61 | + } | |
77 | 62 | } |
78 | - else if(script[0] == '-' && script[1] == 's'){ | |
63 | + else if((script[0] == '-' || script[0] == '/') && (script[1] == 'o' || script[1] == 'O')){ | |
79 | 64 | script += 2; |
80 | 65 | while(*script == ' ') script++; |
81 | - save(script); | |
82 | - return FALSE; | |
66 | + AviUtlCommand::SaveProject(script); | |
67 | + return false; | |
83 | 68 | } |
84 | 69 | } |
85 | - return TRUE; | |
70 | + return true; | |
86 | 71 | } |
87 | 72 | |
88 | 73 | namespace |
89 | 74 | { |
90 | - void quit() | |
91 | - { | |
92 | - PostMessageA(getmainwindow(), WM_CLOSE, 0, 0); | |
93 | - } | |
94 | - | |
95 | - void save(const char* path) | |
96 | - { | |
97 | - dlgdata.path = path; | |
98 | - IATModifier hook3{ "comdlg32.dll", "GetSaveFileNameA", static_cast<decltype(GetSaveFileNameA)*>([](LPOPENFILENAMEA pofn) -> BOOL { | |
99 | - strcpy_s(pofn->lpstrFile, pofn->nMaxFile, dlgdata.path); | |
100 | - return TRUE; | |
101 | - }), GetModuleHandleA(nullptr) }; | |
102 | - | |
103 | - SendMessageA(getmainwindow(), WM_COMMAND, 1023, 0xFFFFFFFF); | |
104 | - } | |
105 | - | |
106 | - void newproject(size_t cx, size_t cy, size_t fps, size_t freq) | |
107 | - { | |
108 | - HMODULE ex = GetModuleHandleA("exedit.auf"); | |
109 | - if(!ex) return; | |
110 | - | |
111 | - std::remove_pointer<decltype(dlgdata.videoinfo)>::type data{ cx, cy, fps, freq }; | |
112 | - dlgdata.videoinfo = &data; | |
113 | - | |
114 | - IATModifier hook1{ "user32.dll", "DialogBoxParamA", static_cast<decltype(DialogBoxParamA)*>([](HINSTANCE, LPCSTR, HWND, DLGPROC proc, LPARAM) -> INT_PTR { | |
115 | - proc(nullptr, WM_COMMAND, IDOK, 0); | |
116 | - return IDOK; | |
117 | - }), ex }; | |
118 | - IATModifier hook2{ "user32.dll", "GetDlgItemInt", static_cast<decltype(GetDlgItemInt)*>([](HWND, int id, BOOL*, BOOL) -> UINT { | |
119 | - if(id == 171) return dlgdata.videoinfo->cx; | |
120 | - if(id == 172) return dlgdata.videoinfo->cy; | |
121 | - return dlgdata.videoinfo->freq; | |
122 | - }), ex }; | |
123 | - IATModifier hook3{ "user32.dll", "GetDlgItemTextA", static_cast<decltype(GetDlgItemTextA)*>([](HWND, int, char* buf, int nmax) -> UINT { | |
124 | - return sprintf_s(buf, nmax, "%d", dlgdata.videoinfo->fps); | |
125 | - }), ex }; | |
126 | - | |
127 | - SendMessageA(getExeditWindow(), WM_COMMAND, 1030, 0xFFFFFFFF); | |
128 | - } | |
129 | - | |
130 | - void openexo(const char* path) | |
131 | - { | |
132 | - dlgdata.path = path; | |
133 | - IATModifier hook3{ "comdlg32.dll", "GetOpenFileNameA", static_cast<decltype(GetOpenFileNameA)*>([](LPOPENFILENAMEA pofn) -> BOOL { | |
134 | - strcpy_s(pofn->lpstrFile, pofn->nMaxFile, dlgdata.path); | |
135 | - return TRUE; | |
136 | - }), GetModuleHandleA(nullptr) }; | |
137 | - | |
138 | - SendMessageA(getExeditWindow(), WM_COMMAND, 1037, 0xFFFFFFFF); | |
139 | - } | |
140 | - | |
141 | - void switchscene(size_t n) | |
142 | - { | |
143 | - HMODULE ex = GetModuleHandleA("exedit.auf"); | |
144 | - if(!ex || n < 0 || n >= 50) return; | |
145 | - | |
146 | - dlgdata.scene_no = n; | |
147 | - IATModifier hook1{ "user32.dll", "DialogBoxParamA", static_cast<decltype(DialogBoxParamA)*>([](HINSTANCE, LPCSTR, HWND, DLGPROC proc, LPARAM) -> INT_PTR { | |
148 | - proc(nullptr, WM_COMMAND, MAKEWPARAM(190, LBN_SELCHANGE), 0); | |
149 | - return dlgdata.scene_no; | |
150 | - }), ex }; | |
151 | - IATModifier hook2{ "user32.dll", "SendDlgItemMessageA", static_cast<decltype(SendDlgItemMessageA)*>([](HWND, int, UINT, WPARAM, LPARAM) -> LRESULT { | |
152 | - return dlgdata.scene_no; | |
153 | - }), ex }; | |
154 | - | |
155 | - SendMessageA(getExeditWindow(), WM_LBUTTONDOWN, MK_LBUTTON, 0); | |
156 | - } | |
157 | - | |
158 | - void transparentscene(bool b) | |
159 | - { | |
160 | - HMODULE ex = GetModuleHandleA("exedit.auf"); | |
161 | - if(!ex) return; | |
162 | - | |
163 | - dlgdata.transparent = b; | |
164 | - IATModifier hook1{ "user32.dll", "DialogBoxParamA", static_cast<decltype(DialogBoxParamA)*>([](HINSTANCE, LPCSTR, HWND, DLGPROC proc, LPARAM) -> INT_PTR { | |
165 | - proc(nullptr, WM_COMMAND, IDOK, 0); | |
166 | - return IDOK; | |
167 | - }), ex }; | |
168 | - IATModifier hook2{ "user32.dll", "IsDlgButtonChecked", static_cast<decltype(IsDlgButtonChecked)*>([](HWND, int) -> UINT { | |
169 | - return dlgdata.transparent ? BST_CHECKED : BST_UNCHECKED; | |
170 | - }), ex }; | |
171 | - | |
172 | - SendMessageA(getExeditWindow(), WM_COMMAND, 1096, 0xFFFFFFFF); | |
173 | - } | |
174 | - | |
175 | - HWND getExeditWindow() | |
176 | - { | |
177 | - HWND ret = nullptr; | |
178 | - EnumThreadWindows(GetCurrentThreadId(), static_cast<WNDENUMPROC>([](HWND hwnd, LPARAM data) -> BOOL { | |
179 | - char buf[16]; | |
180 | - GetWindowTextA(hwnd, buf, std::size(buf)); | |
181 | - if(!starts_with(buf, "拡張編集")) return TRUE; | |
182 | - *reinterpret_cast<HWND*>(data) = hwnd; | |
183 | - return FALSE; | |
184 | - }), reinterpret_cast<LPARAM>(&ret)); | |
185 | - return ret; | |
186 | - } | |
187 | - | |
188 | 75 | bool is_comment(const char* str) |
189 | 76 | { |
190 | 77 | return str[0] == ';'; |
@@ -210,7 +97,7 @@ namespace | ||
210 | 97 | size_t starts_with(const char* str, const char* pat) |
211 | 98 | { |
212 | 99 | size_t n = std::strlen(pat); |
213 | - if(!std::strncmp(pat, str, n)) return n; | |
100 | + if(!_strnicmp(pat, str, n)) return n; | |
214 | 101 | return 0; |
215 | 102 | } |
216 | 103 |
@@ -218,10 +105,16 @@ namespace | ||
218 | 105 | { |
219 | 106 | size_t m = std::strlen(str); |
220 | 107 | size_t n = std::strlen(pat); |
221 | - if(m >= n && !std::strncmp(pat, str + m - n, n)) return n; | |
108 | + if(m >= n && !_strnicmp(pat, str + m - n, n)) return n; | |
222 | 109 | return 0; |
223 | 110 | } |
224 | 111 | |
112 | + bool has_argument(const char* script) | |
113 | + { | |
114 | + while(*script == ' ') script++; | |
115 | + return !!*script; | |
116 | + } | |
117 | + | |
225 | 118 | const char* skiparg(const char* script) |
226 | 119 | { |
227 | 120 | while(*script == ' ') script++; |
@@ -1,5 +1,3 @@ | ||
1 | 1 | #pragma once |
2 | 2 | |
3 | -#include <windows.h> | |
4 | - | |
5 | -BOOL ScriptParser(const char*); | |
3 | +bool SubParser(const char*); |
@@ -9,41 +9,56 @@ namespace | ||
9 | 9 | int findmenu(HMENU, const char*, HMENU*); |
10 | 10 | } |
11 | 11 | |
12 | -HWND getmainwindow() | |
12 | +namespace AviUtlUI | |
13 | 13 | { |
14 | - HWND ret = nullptr; | |
15 | - EnumThreadWindows(GetCurrentThreadId(), static_cast<WNDENUMPROC>([](HWND hwnd, LPARAM data) -> BOOL { | |
16 | - char buf[16]; | |
17 | - GetClassNameA(hwnd, buf, std::size(buf)); | |
18 | - if(_strcmpi(buf, "AviUtl")) return TRUE; | |
14 | + HWND GetMainWindow() | |
15 | + { | |
16 | + HWND ret = nullptr; | |
17 | + EnumThreadWindows(GetCurrentThreadId(), static_cast<WNDENUMPROC>([](HWND hwnd, LPARAM data) -> BOOL { | |
18 | + char buf[16]; | |
19 | + GetClassNameA(hwnd, buf, std::size(buf)); | |
20 | + if(_strcmpi(buf, "AviUtl")) return TRUE; | |
19 | 21 | |
20 | - *reinterpret_cast<HWND*>(data) = hwnd; | |
21 | - return FALSE; | |
22 | - }), reinterpret_cast<LPARAM>(&ret)); | |
22 | + *reinterpret_cast<HWND*>(data) = hwnd; | |
23 | + return FALSE; | |
24 | + }), reinterpret_cast<LPARAM>(&ret)); | |
23 | 25 | |
24 | - while(HWND owner = GetWindow(ret, GW_OWNER)) ret = owner; | |
26 | + while(HWND owner = GetWindow(ret, GW_OWNER)) ret = owner; | |
25 | 27 | |
26 | - return ret; | |
27 | -} | |
28 | + return ret; | |
29 | + } | |
28 | 30 | |
29 | -void addmenu() | |
30 | -{ | |
31 | - HMENU file = GetSubMenu(GetMenu(getmainwindow()), 0); | |
32 | - HMENU imp = nullptr; | |
33 | - findmenu(file, "インポート", &imp); | |
34 | - const int delpos = findmenu(imp, "Script Engine", nullptr); | |
35 | - if(delpos < 0) return; | |
36 | - const int inspos = findmenu(file, "AVI出力 (Ctrl+S)", nullptr); | |
37 | - if(inspos < 0) return; | |
31 | + void AddMenu() | |
32 | + { | |
33 | + HMENU file = GetSubMenu(GetMenu(GetMainWindow()), 0); | |
34 | + HMENU imp = nullptr; | |
35 | + findmenu(file, "インポート", &imp); | |
36 | + const int delpos = findmenu(imp, "Script Engine", nullptr); | |
37 | + if(delpos < 0) return; | |
38 | + const int inspos = findmenu(file, "AVI出力 (Ctrl+S)", nullptr); | |
39 | + if(inspos < 0) return; | |
40 | + | |
41 | + UINT id = GetMenuItemID(imp, delpos); | |
42 | + DeleteMenu(imp, delpos, MF_BYPOSITION); | |
38 | 43 | |
39 | - UINT id = GetMenuItemID(imp, delpos); | |
40 | - DeleteMenu(imp, delpos, MF_BYPOSITION); | |
44 | + const MENUITEMINFOA load { sizeof(load), MIIM_ID | MIIM_TYPE, MFT_STRING, MFS_ENABLED, id, nullptr, nullptr, nullptr, 0, const_cast<char*>("スクリプト読み込み"), 0, nullptr }; | |
45 | + InsertMenuItemA(file, inspos, TRUE, &load); | |
46 | + | |
47 | + constexpr MENUITEMINFOA sep { sizeof(sep), MIIM_TYPE, MFT_SEPARATOR, MFS_DEFAULT, 0, nullptr, nullptr, nullptr, 0, nullptr, 0, nullptr }; | |
48 | + InsertMenuItemA(file, inspos + 1, TRUE, &sep); | |
49 | + } | |
41 | 50 | |
42 | - const MENUITEMINFOA load { sizeof(load), MIIM_ID | MIIM_TYPE, MFT_STRING, MFS_ENABLED, id, nullptr, nullptr, nullptr, 0, const_cast<char*>("スクリプト読み込み"), 0, nullptr }; | |
43 | - InsertMenuItemA(file, inspos, TRUE, &load); | |
51 | + BOOL WndProc(HWND hwnd, UINT msg, WPARAM, LPARAM, void* editp, FILTER*) | |
52 | + { | |
53 | + if(msg == WM_FILTER_IMPORT){ | |
54 | + char path[MAX_PATH] = ""; | |
55 | + OPENFILENAMEA ofn{ sizeof(ofn), hwnd, nullptr, "Script Files(*.aus)\0*.aus\0\0", nullptr, 0, 1, path, std::size(path), nullptr, 0, "", nullptr, OFN_HIDEREADONLY | OFN_FILEMUSTEXIST, 0, 0, "aus", 0, nullptr, nullptr, nullptr, 0, 0 }; | |
56 | + if(!GetOpenFileNameA(&ofn)) return FALSE; | |
44 | 57 | |
45 | - constexpr MENUITEMINFOA sep { sizeof(sep), MIIM_TYPE, MFT_SEPARATOR, MFS_DEFAULT, 0, nullptr, nullptr, nullptr, 0, nullptr, 0, nullptr }; | |
46 | - InsertMenuItemA(file, inspos + 1, TRUE, &sep); | |
58 | + LoadScript(path, editp); | |
59 | + } | |
60 | + return FALSE; | |
61 | + } | |
47 | 62 | } |
48 | 63 | |
49 | 64 | namespace |
@@ -65,15 +80,3 @@ namespace | ||
65 | 80 | return -1; |
66 | 81 | } |
67 | 82 | } |
68 | - | |
69 | -BOOL wndproc(HWND hwnd, UINT msg, WPARAM, LPARAM, void* editp, FILTER*) | |
70 | -{ | |
71 | - if(msg == WM_FILTER_IMPORT){ | |
72 | - char path[MAX_PATH] = ""; | |
73 | - OPENFILENAMEA ofn{ sizeof(ofn), hwnd, nullptr, "Script Files(*.aus)\0*.aus\0\0", nullptr, 0, 1, path, std::size(path), nullptr, 0, "", nullptr, OFN_HIDEREADONLY | OFN_FILEMUSTEXIST, 0, 0, "aus", 0, nullptr, nullptr, nullptr, 0, 0 }; | |
74 | - if(!GetOpenFileNameA(&ofn)) return FALSE; | |
75 | - | |
76 | - LoadScript(path, editp); | |
77 | - } | |
78 | - return FALSE; | |
79 | -} |
@@ -3,7 +3,10 @@ | ||
3 | 3 | #include <windows.h> |
4 | 4 | #include "filter.h" |
5 | 5 | |
6 | -HWND getmainwindow(); | |
6 | +namespace AviUtlUI | |
7 | +{ | |
8 | + HWND GetMainWindow(); | |
7 | 9 | |
8 | -void addmenu(); | |
9 | -BOOL wndproc(HWND, UINT, WPARAM, LPARAM, void*, FILTER*); | |
10 | + void AddMenu(); | |
11 | + BOOL WndProc(HWND, UINT, WPARAM, LPARAM, void*, FILTER*); | |
12 | +} |