<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Серый форум &mdash; AHK: Хук DirectX 9 сохранение экрана и добавление надписи]]></title>
		<link>http://forum.script-coding.com/viewtopic.php?id=14971</link>
		<atom:link href="http://forum.script-coding.com/extern.php?action=feed&amp;tid=14971&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[Недавние сообщения в теме «AHK: Хук DirectX 9 сохранение экрана и добавление надписи».]]></description>
		<lastBuildDate>Tue, 17 Sep 2019 01:38:55 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: AHK: Хук DirectX 9 сохранение экрана и добавление надписи]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=136080#p136080</link>
			<description><![CDATA[<p>Добавление надписи &quot;Hello, World!&quot; в тестируемое приложение.<br />minhook.ahk<br /></p><div class="codebox"><pre><code>MinhookDll := A_ScriptDir &quot;\MinHook.dll&quot;
global d3dx9_Version := &quot;d3dx9_24&quot;
global pOriginal_EndScene

SetWorkingDir %A_ScriptDir%
d3d := Direct3DCreate9(D3D_SDK_VERSION := 32) 
d3dx9()
VarSetCapacity(D3DPRESENT_PARAMETERS, 48+2*A_PtrSize, 0) 
NumPut(1, D3DPRESENT_PARAMETERS, 0)   ; BackBufferWidth
NumPut(1, D3DPRESENT_PARAMETERS, 4)   ; BackBufferHeight
NumPut(1, D3DPRESENT_PARAMETERS, 24)   ; D3DSWAPEFFECT_DISCARD
NumPut(1, D3DPRESENT_PARAMETERS, 24+2*A_PtrSize)   ; Windowed
IDirect3D9_CreateDevice(d3d, D3DADAPTER_DEFAULT := 0, D3DDEVTYPE_HAL := 1, 0, D3DCREATE_HARDWARE_VERTEXPROCESSING := 0x00000040, &amp;D3DPRESENT_PARAMETERS, device)
EndScene := IDirect3DDevice9_Get_EndScene(device)

Release(device)
Release(d3d)

MinHook_Init(MinhookDll)
MH_CreateHook(EndScene, RegisterCallback(&quot;EndScene_Hook&quot;, &quot;F&quot;), pOriginal_EndScene)
MH_EnableHook()
return


EndScene_Hook(device)
{
   Critical
   static n, font
   if (n = &quot;&quot;)
   {
      if (font != &quot;&quot;)
      {
         Release(font)
         font := &quot;&quot;
      }
      D3DXCreateFont(device, 70, autowidth := 0, FW_BOLD := 700, 0, false, DEFAULT_CHARSET := 0x1, OUT_DEFAULT_PRECIS := 0, ANTIALIASED_QUALITY := 0x4, DEFAULT_PITCH_I_FF_DONTCARE := 0, &quot;Arial&quot;, font)
      VarSetCapacity(Rect, 16, 0)
      NumPut(0, Rect, 0, &quot;int&quot;)
      NumPut(0, Rect, 4, &quot;int&quot;)
      NumPut(640, Rect, 8, &quot;int&quot;)
      NumPut(480, Rect, 12, &quot;int&quot;)
      n := 1
   }
   ID3DXFont_DrawTextW(font, 0, &quot;Hello, World!&quot;, -1, &amp;Rect, DT_CENTER_I_DT_VCENTER := 1|4, 0xFFFFFFFF)
   DllCall(pOriginal_EndScene, &quot;ptr&quot;, device)
   return 
}




D3DXCreateFont(pDevice, Height, Width, Weight, MipLevels, Italic, CharSet, OutputPrecision, Quality, PitchAndFamily, pFacename, ByRef ppFont)
{
   hr := DllCall(d3dx9_Version &quot;\D3DXCreateFont&quot;, &quot;ptr&quot;, pDevice, &quot;int&quot;, Height, &quot;uint&quot;, Width, &quot;uint&quot;, Weight, &quot;uint&quot;, MipLevels, &quot;int&quot;, Italic, &quot;uint&quot;, CharSet, &quot;uint&quot;, OutputPrecision, &quot;uint&quot;, Quality, &quot;uint&quot;, PitchAndFamily, &quot;str&quot;, pFacename, &quot;ptr*&quot;, ppFont)
   if hr
      _Error(A_ThisFunc &quot; error: &quot; hr &quot;`nErrorLevel: &quot; ErrorLevel)
}

ID3DXFont_DrawTextW(this, pSprite, pString, Count, pRect, Format, Color)
{
   hr := DllCall(NumGet(NumGet(this+0)+15*A_PtrSize), &quot;ptr&quot;, this, &quot;ptr&quot;, pSprite, &quot;str&quot;, pString, &quot;int&quot;, Count, &quot;ptr&quot;, pRect, &quot;uint&quot;, Format, &quot;uint&quot;, Color)
   if !hr
      _Error(A_ThisFunc &quot; error: &quot; hr &quot;`nErrorLevel: &quot; ErrorLevel)
}

d3dx9()
{
   if !DllCall(&quot;GetModuleHandle&quot;, &quot;str&quot;, d3dx9_Version, &quot;ptr&quot;)
   {
      if !DllCall(&quot;LoadLibrary&quot;,&quot;str&quot;, d3dx9_Version)
      {
         MsgBox, 16, Error, %d3dx9_Version% failed.
         ExitApp
      }
   }
}

Direct3DCreate9(SDKVersion)
{
   if !DllCall(&quot;GetModuleHandle&quot;,&quot;str&quot;,&quot;d3d9&quot;, &quot;PTR&quot;)
   {
      MsgBox, 16, Error, d3d9 failed.
      ExitApp
   }
   return DllCall(&quot;d3d9\Direct3DCreate9&quot;, &quot;uint&quot;, SDKVersion)
}

IDirect3D9_CreateDevice(this,Adapter,DeviceType,hFocusWindow,BehaviorFlags,pPresentationParameters,ByRef ppReturnedDeviceInterface)
{
   hr := DllCall(NumGet(NumGet(this+0)+16*A_PtrSize),&quot;ptr&quot;,this,&quot;uint&quot;,Adapter,&quot;uint&quot;,DeviceType,&quot;ptr&quot;,hFocusWindow,&quot;uint&quot;,BehaviorFlags,&quot;ptr&quot;,pPresentationParameters,&quot;ptr*&quot;,ppReturnedDeviceInterface)
   if hr
      _Error(A_ThisFunc &quot; error: &quot; hr &quot;`nErrorLevel: &quot; ErrorLevel)
}

IDirect3DDevice9_Get_EndScene(this)
{
   return NumGet(NumGet(this+0)+42*A_PtrSize)
}

Release(this)
{
   DllCall(NumGet(NumGet(this+0)+2*A_PtrSize), &quot;ptr&quot;, this)
   if ErrorLevel
      _Error(A_ThisFunc &quot; error: &quot; hr &quot;`nErrorLevel: &quot; ErrorLevel)
}

_Error(val)
{
   msgbox % val
   ExitApp
}




MinHook_Init(MinhookDll)
{
   Static h
   If Not h
   {
      h:=DllCall(&quot;LoadLibrary&quot;,&quot;Str&quot;,MinhookDll, &quot;Ptr&quot;)
      MH_Initialize()
   }
}

; Creates a Hook for the specified target function, in disabled state.
; Parameters:
;   pTarget    [in]  A pointer to the target function, which will be
;                    overridden by the detour function.
;   pDetour    [in]  A pointer to the detour function, which will override
;                    the target function.
;   ppOriginal [out] A pointer to the trampoline function, which will be
;                    used to call the original target function.
;                    This parameter can be NULL.
MH_CreateHook(pTarget, pDetour, ByRef ppOriginal := 0) {
	return DllCall(&quot;MinHook\MH_CreateHook&quot;
	               , &quot;ptr&quot;, pTarget
	               , &quot;ptr&quot;, pDetour
	               , &quot;uptr*&quot;, ppOriginal )
}

; Initialize the MinHook library. You must call this function EXACTLY ONCE
; at the beginning of your program.
MH_Initialize() {
	return DllCall(&quot;MinHook\MH_Initialize&quot;)
}

; Uninitialize the MinHook library. You must call this function EXACTLY
; ONCE at the end of your program.
MH_Uninitialize() {
	return DllCall(&quot;MinHook\MH_Uninitialize&quot;)
}

; Removes an already created hook.
; Parameters:
;   pTarget [in] A pointer to the target function.
MH_RemoveHook(pTarget) {
	return DllCall(&quot;MinHook\MH_RemoveHook&quot;, &quot;ptr&quot;, pTarget)
}

/*
	#define MH_ALL_HOOKS NULL
*/

; Enables an already created hook.
; Parameters:
;   pTarget [in] A pointer to the target function.
;                If this parameter is MH_ALL_HOOKS, all created hooks are
;                enabled in one go.
MH_EnableHook(pTarget := 0) {
	return DllCall(&quot;MinHook\MH_EnableHook&quot;, &quot;ptr&quot;, pTarget)
}

; Disables an already created hook.
; Parameters:
;   pTarget [in] A pointer to the target function.
;                If this parameter is MH_ALL_HOOKS, all created hooks are
;                disabled in one go.
MH_DisableHook(pTarget := 0) {
	return DllCall(&quot;MinHook\MH_DisableHook&quot;, &quot;ptr&quot;, pTarget)
}</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (Malcev)]]></author>
			<pubDate>Tue, 17 Sep 2019 01:38:55 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=136080#p136080</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Хук DirectX 9 сохранение экрана и добавление надписи]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=136064#p136064</link>
			<description><![CDATA[<p>А, понял, она у тебя в minhook.ahk прописана, теперь работает. Я думал, minhook.ahk — это просто библиотека. User-friendly добавить надо. <img src="//forum.script-coding.com/img/smilies/smile.png" width="15" height="15" /></p>]]></description>
			<author><![CDATA[null@example.com (teadrinker)]]></author>
			<pubDate>Sun, 15 Sep 2019 20:51:20 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=136064#p136064</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Хук DirectX 9 сохранение экрана и добавление надписи]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=136063#p136063</link>
			<description><![CDATA[<p>Похоже ошибка связана с путем файла.<br />Папка для сохранения файлов существует?</p>]]></description>
			<author><![CDATA[null@example.com (Malcev)]]></author>
			<pubDate>Sun, 15 Sep 2019 20:38:38 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=136063#p136063</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Хук DirectX 9 сохранение экрана и добавление надписи]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=136062#p136062</link>
			<description><![CDATA[<div class="quotebox"><cite>Malcev пишет:</cite><blockquote><p>В принципе код должен работать и на 32 бит и на 64бит, только длл нужны соответствующие.</p></blockquote></div><p>Да, неправильно выразился.<br /></p><div class="quotebox"><cite>Malcev пишет:</cite><blockquote><p>А приложение, которое хукаешь 64-битное?</p></blockquote></div><p>То, что в архиве.</p>]]></description>
			<author><![CDATA[null@example.com (teadrinker)]]></author>
			<pubDate>Sun, 15 Sep 2019 20:34:36 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=136062#p136062</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Хук DirectX 9 сохранение экрана и добавление надписи]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=136061#p136061</link>
			<description><![CDATA[<p>А приложение, которое хукаешь 64-битное?<br />В принципе код должен работать и на 32 бит и на 64бит, только длл нужны соответствующие.</p>]]></description>
			<author><![CDATA[null@example.com (Malcev)]]></author>
			<pubDate>Sun, 15 Sep 2019 20:30:19 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=136061#p136061</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Хук DirectX 9 сохранение экрана и добавление надписи]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=136060#p136060</link>
			<description><![CDATA[<p>У меня на Windows 7 выдаёт ошибку:<br /></p><div class="quotebox"><blockquote><p>IWICStream_InitializeFromFilename error: -2147024893<br />ErrorLevel: 0</p></blockquote></div><p>Надо ещё уточнить, что код для 32 бит.</p>]]></description>
			<author><![CDATA[null@example.com (teadrinker)]]></author>
			<pubDate>Sun, 15 Sep 2019 20:20:59 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=136060#p136060</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Хук DirectX 9 сохранение экрана и добавление надписи]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=136056#p136056</link>
			<description><![CDATA[<p>Задача перехватывать directx интерфейс для своих нужд, типа фрапса.<br />После того, как мы его перехватили, в принципе, мы можем делать с ним всё, что угодно - накладывать свои оверлеи или сохранять экран через backbuffer с огромной скоростью. <br />Делал по алгоритму:<br /><a href="http://spazzarama.com/2010/03/29/screen-capture-with-direct3d-api-hooks/">http://spazzarama.com/2010/03/29/screen … api-hooks/</a><br />Поправил первый пост.</p>]]></description>
			<author><![CDATA[null@example.com (Malcev)]]></author>
			<pubDate>Sun, 15 Sep 2019 14:53:24 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=136056#p136056</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Хук DirectX 9 сохранение экрана и добавление надписи]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=136055#p136055</link>
			<description><![CDATA[<p>Объяснил бы хоть для непосвящённых, какая задача решается, зачем DirectX9, зачем хук. Я например совсем не в теме.</p>]]></description>
			<author><![CDATA[null@example.com (teadrinker)]]></author>
			<pubDate>Sun, 15 Sep 2019 11:40:27 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=136055#p136055</guid>
		</item>
		<item>
			<title><![CDATA[AHK: Хук DirectX 9 сохранение экрана и добавление надписи]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=136052#p136052</link>
			<description><![CDATA[<p>Тема для обсуждения &quot;Хук DirectX 9 сохранение экрана и добавление надписи&quot;.<br /><a href="http://forum.script-coding.com/viewtopic.php?id=17678">http://forum.script-coding.com/viewtopic.php?id=17678</a></p>]]></description>
			<author><![CDATA[null@example.com (Malcev)]]></author>
			<pubDate>Sat, 14 Sep 2019 21:28:53 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=136052#p136052</guid>
		</item>
	</channel>
</rss>
