设为首页收藏本站官方微博

【汉化资料】在DirectX中使用代理DLL技术

[复制链接]
查看: 3463|回复: 0
打印 上一主题 下一主题

【汉化资料】在DirectX中使用代理DLL技术

跳转到指定楼层
楼主
发表于 2009-3-20 07:34 | 只看该作者 回帖奖励 |正序浏览 |阅读模式

【汉化资料】在DirectX中使用代理DLL技术

http://www.codeguru.com/cpp/g-m/ ... /article.php/c11453
. |2 E% S4 T+ l# `8 D& l, S0 d4 r- V1 |
Intercept Calls to DirectX with a Proxy DLL ( x, B( T% w7 Q7 y6 y6 F8 d
Show own content on top of a full screen DirectX application
' J7 L+ D+ U9 FRating: none - Z% l4 @. X3 o5 q7 {( A" d  v, N

* }0 d0 ^' Z4 hMichael Koch (view profile) ( X/ ~3 F! u8 {7 z$ y5 G5 @9 O' v
March 13, 2006  6 ?# \7 W, C; D( o( u0 a, \0 Z
) Y3 ]. ]+ T( P) c' J, ]  p
Environment:  Windows, DirectX 8/9, Visual C++ 2003
2 J9 T8 Q+ U; @* x* i8 {0 u* V
$ O7 ~9 j( m+ ?+ }) u( N  E: P) V
3 R: k6 R) L7 `4 h6 v6 J
5 X9 L4 `  m* t0 g# b* D6 }: GIntroduction 2 t2 Y4 |6 m* V) z! n/ ?5 B/ R$ l
Have you ever wanted to paint your own graphics (or text) on top of a DirectX application (for example, to show TeamSpeak information, or a self-created map, within a game)?
: Q+ y# `" a7 A2 d  J0 L& A) V! S$ ^  w/ \6 P" M( U6 g; G
) P8 H2 M, b3 b0 |, y
(continued) 4 i$ E7 y0 w' j$ d/ ?

  R. Q. Y$ y: c7 L
7 P# H7 P0 e+ i7 Z3 p1 l2 l3 i7 x& T

) O/ }/ k: M  j* g& [( q) B0 Y/ RMARKETPLACE
% |3 B- ~/ i$ X& W; f) BFlowcharts from C/C++ code -- Free trial download
. d3 |2 C% m$ ?+ RUnderstand C/C++ code in less time. Flowcharts, DataFlow, Rich Trees, Static Checking, Documentation
$ F( Z; x" Z% _, ?! v' C( \www.sgvsarc.com
0 o! @+ l" j  E! e, e$ Q( P; iNew Webcast: How to Profit with Remote Support.
/ S: |2 U: I; |/ I0 {Discover how REMOTE SUPPORT can fuel your IT business in ways you've never thought of before.
- i' Y. I, l; p8 ]Listen to this valuable Webcast Today! www.LogMeInRescue.com 7 j  E* p( w; f: J9 X
Advertiser Here  
, d0 V# i* M; j0 {, TIf so, the solution discussed below might help you. By using a "proxy DLL," calls to DirectX can be intercepted, data altered, and even new objects can be created and be shown within another application (read: the source code of this application does not need to be available).
2 C0 h: R6 W  O  Y; b$ T( T. o1 W2 q  f4 m3 `
This article's topics cover the creation of a basic proxy DLL for DirectX8/9 3D-calls (d3d8/d3d9.dll), including the full source. Based on your imagination and knowledge, you might enhance this for your very own applications and needs.
0 V3 D8 P: w( k
3 X9 o: P' F# [9 ~The following picture shows an example application, adding graphical objects to a game. Testing application: Krakout-Arkanoid (http://www.wegroup.org/Games/Ark ... ut-RE-Arkanoid.html). This was done using a DirectX8 proxy DLL. The yellow rectangle in the upper left corner and the cube in the middle aren't part of the original game; they were created within the proxy DLL and added.   b& ~4 U& u  u& u) {" \
. p$ X: E: v) k9 X4 `' W: N
5 a! c* s" S6 s# N! I( z

1 ?- i% E- T1 n5 o5 q# E- B" @, U, k+ u9 d, S0 C$ n
Concept $ w' F$ n* Z! p  r
To obtain DirectX functionality, an application needs to load certain dynamic link libraries (DLLs); for example, d3d9.dll. A "proxy DLL" names exactly like a DLL in question and manages to get loaded by the application instead of the "real, original" one. Once loaded, the proxy loads the "real" DLL by itself and passes all calls from the application on to it. ( R) O+ D& B) v

8 f- X, {1 t. E" g  `So, a "filter" is installed between the application and its calls to regular DLL functions. Obviously, your own, new functionality now can be added when intercepting or altering certain function calls. 1 |1 Y: |/ H% W" z" A

6 c7 H+ G" a' l7 X6 F: rRegular setup:  Application <-> d3d9.dll (system) 3 W! {; K7 G/ P) l
Proxy setup:  Application <-> d3d9.dll(proxy) <-> d3d9.dll (system)
+ K' ~3 y( n# L5 `  |/ h. L  l2 B4 x* F& I2 o% Z
By the way, this concept is very similar to one used by a Microsoft DirectX programming utility, named D3DSpy. Quote from the D3DSpy help file: 1 I3 H  Z+ s" h* M+ c6 P# L' d

! v9 T" T2 ~% g"D3DSpy works by providing a proxy DLL, which the application connects to and treats like the real D3D9.DLL. It intercepts all the calls and gathers various information before making the real D3D call."   F4 E( e2 f9 d+ M: r! u
The proxy concept doesn't work with all applications due to several reasons. It has to be tested thoroughly with an application (game) before making it available to a wider range of users.
) r4 ^! t& g' E; ~
7 F: \8 y! _' J! Y3 X6 TThere are other approaches on how to draw your own stuff in a DirectX application (like "run-time code-injection," or even altering the code of an executable file). In case the proxy DLL concept doesn't work for you, you may want to look for one of those (not covered here).
: t  u' e$ a7 t# m- r
9 B# {: T- s& ~( [% Q) xRealisation : ]" s3 |5 Y8 F* u2 S
I focus on Direct8/9 3D calls here. This said, you need to create a d3d8/d3d9.dll that will be called by the application instead of the "real" (system-provided) library.
+ w' z1 `1 H  X: U% }' m2 w$ [+ x& F" _# T9 \( t
Note: To test the proxy DLL, I used Krakout-Arkanoid (DX8) and Flatspace Demo (DX9), amongst others. Both are nice games, and they were on hand at that time. For debugging purposes, DebugView is a nice tool. Ah, and check out dependency walker for the examination of DLLs.
: X! k% d2 a: ?. pFirst, take a look at an application that uses DirectX 3D calls. It enables D3D support by loading the d3d8/d3d9.dll, and then obtains the IDirect3D8/9 interface via Direct3DCreate8/9 and creates a IDirect3DDevice8/9 with CreateDevice. , X( J9 h4 P( ]1 T( a
) |3 j! D7 j7 i7 c
If you can manage to get your d3d8/d3d9.dll loaded by the application, thus getting the call to Direct3DCreate8/9 redirected to your code, you could create a IDirect3D8/9 Interface object by yourself. The same goes for the IDirect3DDevice8/9 Interface. You then would offer all funcionality like the original interfaces to the caller's code (in fact, just by redirecting each call to a IDirect3D/IDirect3DDevice you secretly created of your own). This gives you the possibility to change data and/or add new things. 1 S5 U/ x% ^. c0 e" D
, S6 T# j- c  H8 I+ ]' F
9 }+ l5 d' A/ \7 P! x. Q% ~+ t

) P4 D+ @7 I9 Y+ ]. J& d3 BAny drawbacks on that? Yes.
$ S6 o) I" F9 Z& x" U& N& m) |
* d; I$ b" d) o9 b+ `2 S8 [Normally, an application looks for a DLL within its working directory first, and then by browsing the system's path. Applications may prevent that by directly targetting the system directory (this is especially true for online games; they could consider a proxy DLL being a "hack"). And, you can't just replace the system's d3d8/d3d9.dll because you need its functions as described above. 2 J; ?/ f% |/ w- y! e
: z; p! h" |" {# U6 Z; r# |
Having said this, I strongly advise to not touch the original system DLL. You might destroy your DirectX installation. Furthermore, an application might implement its own texture manager (or even use undocumented calls). Because you will not be able to handle such calls (obviously), the app possibly would not work with a proxy DLL.
5 v9 f+ J8 w7 N2 N
' c9 U# b! |  ?; l4 W8 D7 \. |Finally, you know what you need:
+ V- i4 `: G) Z6 F  V0 x; g1 L4 W$ t2 v! \: F2 y% ^9 ~
a file named d3d8/d3d9.dll that will be placed within the application's working directory (and hopefully get loaded by the app)
# ]/ c9 F& B3 o! l" w) ra function named "Direct3DCreate8/9" being exposed by that DLL
" S- H4 n& ?7 a; o' C2 O* K1 _! F+ Yan interface provided by the DLL that looks exactly the same as the "real" IDirect3D interface 5 o# `7 i) D$ U) K: d- `7 o1 T- |
an interface provided by the DLL that looks exactly the same as the "real" IDirect3DDevice interface & p& m& D0 ~8 C( ^3 g# P  F
Luckily enough, some header files that come with the DX SDK point out what calls should be handled by your "stub" Interfaces.
+ A, c# G: b$ R$ t: F; v6 u
' r& i1 Q0 e5 |The Demo Project
* A2 @8 E/ a0 G; v+ C5 R4 F2 |My "basic proxy DLL" implementation consists of these items: 1 ?- z" G: I! @; R
2 m0 l0 ]) W3 M) b& {0 ^! X
global routines for the DLL handling (entry point, load the system d3d8/d3d9.dll, and so on) , ^% k3 f' r1 P% s, b
an object called myIDirect3D8/9, derived from Direct3D8/9, exposing over a dozen functions
8 ~+ ^: p) ]* ~! ?% V) Pan object called myIDirect3DDevice8/9, derived from IDirect3DDevice8/9, exposing about 100 functions
% l% S/ x9 V! I3 o5 ]Basically, all functions within the "my..." objects pass parameters on to the original system DLL, providing the possibility to change or add data. A few routines need special attention, though. : r" y- |' H* }4 w
! w6 ~# K+ m: Z- H! \6 p4 P
::Release (both Objects)
; c; o7 x8 u0 ~, tIn case the application releases the interface (and no more references are present), you destroy your own object as well.
; r# X: G1 }. y- I- {) @; {  \6 J2 J: ^8 W
::QueryInterface (both Objects) 6 O3 c& j' Q/ y
If the application queries for certain interfaces, you do of course pass the address of your very own routine, not passing the system DLL response this time.
# w: C" j7 v0 @& X9 X# E
6 L6 C! W! t( E- U5 f3 I) B. v4 CmyIDirect3D9::CreateDevice
! i+ Y+ T2 W7 A  b, i: k( `1 t3 l. }Once this is called, you create your own D3DDevice (internally) because you need it to process the application calls. Then, you respond by sending your own object's address.
$ `# C4 e8 F# `6 u
/ t2 q6 X/ }1 kFor testing purposes, the myIDirect3DDevice8/9::ShowWeAreHere function was added to the demo source code. It is called within myIDirect3DDevice8/9::Present and does nothing but create a yellow rectangle in the upper left screen. This might give you an impression of how to add you own content. 0 W2 B8 y' q5 \4 E2 {2 Q. q

0 x. I- a! r6 S- ZThis is a compilation from my work on http://www.proxy.mikoweb.de & g4 e) h* j0 I7 i- G) Z. E; W% c
rev1.1: added DX8 source, corrected typos % t9 f# U1 j9 O* C. h

* K+ A* [3 f- ?4 m* W, a+ {About the Author
" {" m5 e6 r9 r8 ^( w, c% w7 iI'm a hobby programmer, using VC++ .net 2003 " q/ S6 s! t- i" e
1 n2 P7 K' d; i
Downloads " Q/ w: |. ^; ~- Y9 [: L0 r
* B' u; V. B+ ^/ j9 H

+ |% K% Q5 `- F& s! `0 k0 o- Pproxydll_8_src.zip - Demo Project (d3d8.dll proxy, Visual C++ 2003) " K! b* ?7 u% q7 ]
8 E5 [5 ]( Y; \* p
proxydll_9_src.zip - Demo Project (d3d9.dll proxy, Visual C++ 2003)

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享 很美好很美好 很差劲很差劲
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

冒险解谜游戏中文网 ChinaAVG

官方微博官方微信号小黑屋 微信玩家群  

(C) ChinaAVG 2004 - 2019 All Right Reserved. Powered by Discuz! X3.2
辽ICP备11008827号 | 桂公网安备 45010702000051号

冒险,与你同在。 冒险解谜游戏中文网ChinaAVG诞生于2004年9月9日,是全球华人共同的冒险解谜类游戏家园。我们致力于提供各类冒险游戏资讯供大家学习交流。本站所有资源均不用于商业用途。

快速回复 返回顶部 返回列表