📄 directx9hook.pas.svn-base
字号:
tempimage: array of byte; imageloaded:boolean; total: dword; tr: TD3DLocked_Rect; pdesc: td3dsurface_desc; bug:boolean;begin try for i:=0 to length(lockedtexturelist)-1 do begin try lockedtexturelist[i].texturehandle._Release; except //outputdebugstring('failed to release'); end; zeromemory(@lockedtexturelist[i],sizeof(TTextureInfo)); end; for i:=0 to length(texturelist)-1 do begin try texturelist[i].locked:=false; except end; end; setlength(lockedtexturelist,0); except end; LoadPhase:=1; try try aimsettings:=tfilestream.Create(keys.cedir+aimconfigfile+'.cta',fmOpenRead); try aimsettings.ReadBuffer(total,4); setlength(lockedtexturelist,total); setlength(images,total); maxposition:=length(lockedtexturelist)-1; for i:=0 to length(lockedtexturelist)-1 do begin currentposition:=i; aimsettings.ReadBuffer(lockedtexturelist[i].width,sizeof(TTextureInfo)); lockedtexturelist[i].locked:=false; try aimsettings.ReadBuffer(total,4); setlength(images[i],total); aimsettings.ReadBuffer(images[i][0],total); except exit; //failed to load..... end; sleep(1); end; finally aimsettings.free; end; //check the texturelist for these textures //outputdebugstring('Entering phase 2'); loadphase:=2; maxposition:=length(texturelist); for i:=0 to length(texturelist)-1 do begin currentposition:=i; imageloaded:=false; //check the lockedtextures to see if this is a texture that has to be locked for j:=0 to length(lockedtexturelist)-1 do begin if texturelist[i].Width<>lockedtexturelist[j].width then continue; if texturelist[i].Height<>lockedtexturelist[j].Height then continue; if texturelist[i].Levels<>lockedtexturelist[j].Levels then continue; if texturelist[i].Usage<>lockedtexturelist[j].Usage then continue; if texturelist[i].Format<>lockedtexturelist[j].Format then continue; if texturelist[i].Pool<>lockedtexturelist[j].pool then continue; if not imageloaded then begin //copy the memory of the texture to a local var try if texturelist[i].texturehandle.LockRect(0,tr,nil,{0}D3DLOCK_NOSYSLOCK )=0 then begin try texturelist[i].texturehandle.GetLevelDesc(0,pdesc); total:=(pdesc.Width*pdesc.Height); total:=total div 4; if total<length(images[j]) then continue; setlength(tempimage,total); bug:=true; while bug do begin try copymemory(@tempimage[0],tr.Bits,total); imageloaded:=true; bug:=false; except total:=total div 2; setlength(tempimage,total); if (total<length(images[j])) or (total=0) then bug:=false; end; end; finally texturelist[i].texturehandle.UnlockRect(0); sleep(5); end; end; except //doesn't exist end; end; if comparemem(@tempimage[0],@images[j][0],500) then begin //outputdebugstring('It''s the same'); texturelist[i].locked:=true; texturelist[i].xdelta:=lockedtexturelist[j].xdelta; texturelist[i].ydelta:=lockedtexturelist[j].ydelta; texturelist[i].zdelta:=lockedtexturelist[j].zdelta; copymemory(@lockedtexturelist[j].texturehandle,@texturelist[i].texturehandle,4); lockedtexturelist[j].locked:=true; try lockedtexturelist[j].texturehandle._AddRef; except //outputdebugstring('failed to addref'); end; end; sleep(1); end; sleep(1); end; except end; finally for i:=0 to length(images)-1 do setlength(images[i],0); setlength(images,0); setlength(tempimage,0); end;end;{-------------------------------------------------------------------------DirectX 9-------------------------------------------------------------------------}procedure Removetexture(j: integer);var i: integer;begin if texturepointer>j then dec(texturepointer); for i:=j to length(texturelist)-2 do begin texturelist[i].Width:=texturelist[i+1].Width; texturelist[i].Height:=texturelist[i+1].Height; texturelist[i].Levels:=texturelist[i+1].Levels; texturelist[i].Usage:=texturelist[i+1].Usage; texturelist[i].Format:=texturelist[i+1].Format; texturelist[i].Pool:=texturelist[i+1].Pool; texturelist[i].locked:=texturelist[i+1].locked; texturelist[i].xdelta:=texturelist[i+1].xdelta; texturelist[i].ydelta:=texturelist[i+1].ydelta; texturelist[i].zdelta:=texturelist[i+1].zdelta; copymemory(@texturelist[i].texturehandle,@texturelist[i+1].texturehandle,4); end; fillmemory(@texturelist[length(texturelist)-1].texturehandle,4,0); try setlength(texturelist,length(texturelist)-1); except end; if length(texturelist)=0 then texturepointer:=-1; if (texturepointer)>(length(texturelist)-1) then texturepointeR:=length(texturelist)-1;end;function Direct3DCreate9Hook(SDKVersion: DWORD): PIDirect3D9; stdcall;var x,y:dword;begin asm push esi push edi lea esi,Direct3DCreate9Info.original[0] mov edi,Direct3DCreate9Info.location movsd movsb pop edi pop esi end; outputdebugstring('CEHOOK:Creating a direct3d9 object'); result:=Direct3DCreate9(SDKVersion); x:=dword(result); //hook createdevice outputdebugstring('Hooking createdevice'); if IDirect3D9_CreateDevice.location=nil then IDirect3D9_CreateDevice.location:=pointer(pdword(pdword(x)^+4*16)^); virtualprotect(pointer(pdword(x)^+4*16),4,PAGE_EXECUTE_READWRITE,y); pdword(pdword(x)^+4*16)^:=dword(@IDirect3D9_CreateDevice_Hook); virtualprotect(pointer(pdword(x)^+4*16),4,y,y); outputdebugstring('Hooking createdevice-success');end;//Hooked IDirect3D9 methods:function Fixhook(const self:IDirect3DDevice9):boolean; stdcall;var x:dword;begin virtualprotect(pdword(pdword(dword(Self))^),4*77,PAGE_EXECUTE_READWRITE,x); //hook Reset if IDirect3DDevice9_Reset.location=nil then IDirect3DDevice9_Reset.location:=pointer(pdword(pdword(dword(Self))^+4*16)^); pdword(pdword(dword(Self))^+4*16)^:=dword(@IDirect3DDevice9_Reset_Hook); //hook createtexture if IDirect3DDevice9_CreateTexture.location=nil then IDirect3DDevice9_CreateTexture.location:=pointer(pdword(pdword(dword(Self))^+4*23)^); pdword(pdword(dword(Self))^+4*23)^:=dword(@IDirect3DDevice9_CreateTexture_Hook); //hook BeginScene if IDirect3DDevice9_BeginScene.location=nil then IDirect3DDevice9_BeginScene.location:=pointer(pdword(pdword(dword(Self))^+4*41)^); pdword(pdword(dword(Self))^+4*41)^:=dword(@IDirect3DDevice9_BeginScene_Hook); //hook EndScene if IDirect3DDevice9_EndScene.location=nil then IDirect3DDevice9_EndScene.location:=pointer(pdword(pdword(dword(Self))^+4*42)^); pdword(pdword(dword(Self))^+4*42)^:=dword(@IDirect3DDevice9_EndScene_Hook); //hook SetTransform if IDirect3DDevice9_SetTransform.location=nil then IDirect3DDevice9_SetTransform.location:=pointer(pdword(pdword(dword(Self))^+4*44)^); pdword(pdword(dword(Self))^+4*44)^:=dword(@IDirect3DDevice9_SetTransform_Hook); //hook GetTransform if IDirect3DDevice9_GetTransform.location=nil then IDirect3DDevice9_GetTransform.location:=pointer(pdword(pdword(dword(Self))^+4*45)^); pdword(pdword(dword(Self))^+4*45)^:=dword(@IDirect3DDevice9_GetTransform_Hook); //hook SetRenderState if IDirect3DDevice9_SetRenderState.location=nil then IDirect3DDevice9_SetRenderState.location:=pointer(pdword(pdword(dword(Self))^+4*57)^); pdword(pdword(dword(Self))^+4*57)^:=dword(@IDirect3DDevice9_SetRenderState_Hook); //hook SetTexture if IDirect3DDevice9_SetTexture.location=nil then IDirect3DDevice9_SetTexture.location:=pointer(pdword(pdword(dword(Self))^+4*65)^); pdword(pdword(dword(Self))^+4*65)^:=dword(@IDirect3DDevice9_SetTexture_Hook); //hook DrawPrimitive if IDirect3DDevice9_DrawPrimitive.location=nil then IDirect3DDevice9_DrawPrimitive.location:=pointer(pdword(pdword(dword(Self))^+4*81)^); pdword(pdword(dword(Self))^+4*81)^:=dword(@IDirect3DDevice9_DrawPrimitive_Hook); //hook DrawIndexedPrimitive if IDirect3DDevice9_DrawIndexedPrimitive.location=nil then IDirect3DDevice9_DrawIndexedPrimitive.location:=pointer(pdword(pdword(dword(Self))^+4*82)^); pdword(pdword(dword(Self))^+4*82)^:=dword(@IDirect3DDevice9_DrawIndexedPrimitive_Hook); //hook DrawPrimitiveUP if IDirect3DDevice9_DrawPrimitiveUP.location=nil then IDirect3DDevice9_DrawPrimitiveUP.location:=pointer(pdword(pdword(dword(Self))^+4*83)^); pdword(pdword(dword(Self))^+4*83)^:=dword(@IDirect3DDevice9_DrawPrimitiveUP_Hook); //hook DrawIndexedPrimitiveUP if IDirect3DDevice9_DrawIndexedPrimitiveUP.location=nil then IDirect3DDevice9_DrawIndexedPrimitiveUP.location:=pointer(pdword(pdword(dword(Self))^+4*84)^); pdword(pdword(dword(Self))^+4*84)^:=dword(@IDirect3DDevice9_DrawIndexedPrimitiveUP_Hook);end;function IDirect3D9_CreateDevice_Hook(const self: IDirect3D9; const Adapter : Cardinal; const DeviceType : TD3DDevType; FocusWindow : HWND; BehaviorFlags : LongWord; var PresentationParameters : TD3DPresentParameters; out ReturnedDeviceInterface : IDirect3DDevice9) : HResult; stdcall;var x: dword; logfont: tlogfont; desc:TD3DXFontDescA;begin directxversion:=directx9; setlength(xylist,0); Behaviorflags:=behaviorflags and not (D3DCREATE_PUREDEVICE); result:=TIDirect3D9_CreateDevice_Original(IDirect3D9_CreateDevice.location)(self,Adapter,DeviceType,FocusWindow,BehaviorFlags,PresentationParameters, ReturnedDeviceInterface); if result=0 then begin D3DXCreateTextureFromFile(ReturnedDeviceInterface,pchar(keys.CEDir+'lockedstring.bmp'),lockedStringTexture); D3DXCreateTextureFromFile(ReturnedDeviceInterface,pchar(keys.CEDir+'unlockedstring.bmp'),unlockedStringTexture); D3DXCreateTextureFromFile(ReturnedDeviceInterface,pchar(keys.CEDir+'texturestring.bmp'),textureStringTexture); D3DXCreateTextureFromFile(ReturnedDeviceInterface,pchar(keys.CEDir+'Black.bmp'),blackTexture); //D3DXCreateTextureFromFileEx(ReturnedDeviceInterface,pchar(keys.CEDir+'Logo3.bmp'),D3DX_DEFAULT,D3DX_DEFAULT,1,0,D3DFMT_A8R8G8B8,D3DPOOL_MANAGED,D3DX_DEFAULT,D3DX_DEFAULT,$FFFFFFFF,nil,nil,myspritetexture); D3DXCreateTextureFromFileEx(ReturnedDeviceInterface,pchar(keys.CEDir+'TargetTexture.bmp'),D3DX_DEFAULT,D3DX_DEFAULT,1,0,D3DFMT_A8R8G8B8,D3DPOOL_MANAGED,D3DX_DEFAULT,D3DX_DEFAULT,$FFFFFFFF,nil,nil,targettexture); D3DXCreateTextureFromFileEx(ReturnedDeviceInterface,pchar(keys.CEDir+'Locktexture.bmp'),D3DX_DEFAULT,D3DX_DEFAULT,1,0,D3DFMT_A8R8G8B8,D3DPOOL_MANAGED,D3DX_DEFAULT,D3DX_DEFAULT,$FFFFFFFF,nil,nil,locktexture); D3DXCreateTextureFromFileEx(ReturnedDeviceInterface,pchar(keys.CEDir+'Movementtexture.bmp'),D3DX_DEFAULT,D3DX_DEFAULT,1,0,D3DFMT_A8R8G8B8,D3DPOOL_MANAGED,D3DX_DEFAULT,D3DX_DEFAULT,$FFFFFFFF,nil,nil,movementtexture); D3DXCreateSprite(ReturnedDeviceInterface,mysprite); cefonthandle.free; cefonthandle:=tfont.Create; cefonthandle.Color:=clred; cefonthandle.Name:='Courier'; if GetObject(cefonthandle.handle, SizeOf(TLogFont), @logfont)<>0 then begin desc.Height:=logfont.lfHeight; desc.Width:=logfont.lfWidth; desc.Weight:=logfont.lfWeight; desc.MipLevels:=0; desc.Italic:=false; desc.CharSet:=logfont.lfCharSet; desc.OutputPrecision:=logfont.lfOutPrecision; desc.Quality:=logfont.lfQuality; desc.PitchAndFamily:=logfont.lfPitchAndFamily; copymemory(@desc.FaceName[0],@logfont.lfFaceName[0],32); desc.Height:=0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -