Discussion:
Direct3D stub/proxy not working why ?
(too old to reply)
Skybuck Flying
2015-01-05 07:50:30 UTC
Permalink
Hello,

Trying to create a simply direct3d stub/proxy, it not working, why ? I know
nothing of stupid interfaces ?! and I know nothing of stupid
DirectX/Direct3D ?!

I simply build this sucker, and then put it in microsoft sdk samples bin
folder to test with executables but they don't load... nothing happens.

I tried getting rid of 81BD string and the release thing... but no luck...
any help how to get this to work/load ?

unit SuckMyCock;

interface

uses
Windows,
DXTypes,
Direct3D9;

type
IMyDirect3D9 = interface(IUnknown)
['{81BDCBCA-64D4-426d-AE8D-AD0147F4275C}']
(*** IDirect3D9 methods ***)
function RegisterSoftwareDevice(pInitializeFunction: Pointer): HResult;
stdcall;
function GetAdapterCount: LongWord; stdcall;
function GetAdapterIdentifier(Adapter: LongWord; Flags: DWord; out
pIdentifier: TD3DAdapterIdentifier9): HResult; stdcall;
function GetAdapterModeCount(Adapter: LongWord; Format: TD3DFormat):
LongWord; stdcall;
function EnumAdapterModes(Adapter: LongWord; Format: TD3DFormat; Mode:
LongWord; out pMode: TD3DDisplayMode): HResult; stdcall;
function GetAdapterDisplayMode(Adapter: LongWord; out pMode:
TD3DDisplayMode): HResult; stdcall;
function CheckDeviceType(Adapter: LongWord; CheckType: TD3DDevType;
AdapterFormat, BackBufferFormat: TD3DFormat; Windowed: BOOL): HResult;
stdcall;
function CheckDeviceFormat(Adapter: LongWord; DeviceType: TD3DDevType;
AdapterFormat: TD3DFormat; Usage: DWord; RType: TD3DResourceType;
CheckFormat: TD3DFormat): HResult; stdcall;
function CheckDeviceMultiSampleType(Adapter: LongWord; DeviceType:
TD3DDevType; SurfaceFormat: TD3DFormat; Windowed: BOOL; MultiSampleType:
TD3DMultiSampleType; pQualityLevels: PDWORD): HResult; stdcall;
function CheckDepthStencilMatch(Adapter: LongWord; DeviceType: TD3DDevType;
AdapterFormat, RenderTargetFormat, DepthStencilFormat: TD3DFormat): HResult;
stdcall;
function CheckDeviceFormatConversion(Adapter: LongWord; DeviceType:
TD3DDevType; SourceFormat, TargetFormat: TD3DFormat): HResult; stdcall;
function GetDeviceCaps(Adapter: LongWord; DeviceType: TD3DDevType; out
pCaps: TD3DCaps9): HResult; stdcall;
function GetAdapterMonitor(Adapter: LongWord): HMONITOR; stdcall;
function CreateDevice(Adapter: LongWord; DeviceType: TD3DDevType;
hFocusWindow: HWND; BehaviorFlags: DWord; pPresentationParameters:
PD3DPresentParameters; out ppReturnedDeviceInterface: IDirect3DDevice9):
HResult; stdcall;
end;

function Direct3DCreate9(SDKVersion: LongWord): IMyDirect3D9; stdcall;
export;

implementation

function Direct3DCreate9(SDKVersion: LongWord): IMyDirect3D9; stdcall;
export;
begin
Result:= IMyDirect3D9(_Direct3DCreate9(SDKVersion));
// if Assigned(Result) then Result._Release; // Delphi autoincrement
reference count
end;


end.


library d3d9;

{ Important note about DLL memory management: ShareMem must be the
first unit in your library's USES clause AND your project's (select
Project-View Source) USES clause if your DLL exports any procedures or
functions that pass strings as parameters or function results. This
applies to all strings passed to and from your DLL--even those that
are nested in records and classes. ShareMem is the interface unit to
the BORLNDMM.DLL shared memory manager, which must be deployed along
with your DLL. To avoid using BORLNDMM.DLL, pass string information
using PChar or ShortString parameters. }

uses
System.SysUtils,
System.Classes,
SuckMyCock in 'SuckMyCock.pas';

{$R *.res}


exports
Direct3DCreate9;

begin


end.


Maybe directx headers bad ?

Using the ones that contain note like:
"
Alexey Barkovoy,
30-Oct-2006
"

Bye,
Skybuck.
Skybuck Flying
2015-01-05 07:52:40 UTC
Permalink
A delphi proxy for DX11 would be acceptable too, if anybody can make a
simple one that be nice to have.

I'll give these dx11 headers a try:

http://www.jsbmedical.co.uk/DirectXForDelphi/JSB%20DirectX%20interface%20units/

Bye,
Skybuck.
Skybuck Flying
2015-01-05 08:00:50 UTC
Permalink
Oh I think I see problem... the real dll must be loaded too ofcourse..
hmm...

Bye,
Skybuck.
Skybuck Flying
2015-01-05 08:02:13 UTC
Permalink
Oh now a second problem too...

Delphi XE7 comes with it's own directx headers... hmmm thinking.. ;) :)

Bye,
Skybuck.
Skybuck Flying
2015-01-05 08:09:31 UTC
Permalink
I'm starting to think very maybe windows 7, 64 bit edition, is protected
against api hooking ? or maybe not ?

I think I have seen some dll's do it... currently the ones I am trying not
working with microsoft's samples in folder:

C:\Tools\Microsoft DirectX SDK (June 2010)\Samples\C++\Direct3D\Bin\x86

I copy fake d3d9.dll there.

Hmm

That warcraft dll thingy did work though sometimes... not everything but
some stuff worked... but now I need something that works with delphi
compiler.

Bye,
Skybuck.
Skybuck Flying
2015-01-05 08:17:54 UTC
Permalink
This post might be inappropriate. Click to display it.
Skybuck Flying
2015-01-05 08:34:36 UTC
Permalink
Nope...

This unit a bit more advanced, still not working.

unit SuckMyCock;

interface

uses
Windows,
DXTypes,
Direct3D9;

type
IMyDirect3D9 = interface(IUnknown)
['{81BDCBCA-64D4-426d-AE8D-AD0147F4275C}']
(*** IDirect3D9 methods ***)
function RegisterSoftwareDevice(pInitializeFunction: Pointer): HResult;
stdcall;
function GetAdapterCount: LongWord; stdcall;
function GetAdapterIdentifier(Adapter: LongWord; Flags: DWord; out
pIdentifier: TD3DAdapterIdentifier9): HResult; stdcall;
function GetAdapterModeCount(Adapter: LongWord; Format: TD3DFormat):
LongWord; stdcall;
function EnumAdapterModes(Adapter: LongWord; Format: TD3DFormat; Mode:
LongWord; out pMode: TD3DDisplayMode): HResult; stdcall;
function GetAdapterDisplayMode(Adapter: LongWord; out pMode:
TD3DDisplayMode): HResult; stdcall;
function CheckDeviceType(Adapter: LongWord; CheckType: TD3DDevType;
AdapterFormat, BackBufferFormat: TD3DFormat; Windowed: BOOL): HResult;
stdcall;
function CheckDeviceFormat(Adapter: LongWord; DeviceType: TD3DDevType;
AdapterFormat: TD3DFormat; Usage: DWord; RType: TD3DResourceType;
CheckFormat: TD3DFormat): HResult; stdcall;
function CheckDeviceMultiSampleType(Adapter: LongWord; DeviceType:
TD3DDevType; SurfaceFormat: TD3DFormat; Windowed: BOOL; MultiSampleType:
TD3DMultiSampleType; pQualityLevels: PDWORD): HResult; stdcall;
function CheckDepthStencilMatch(Adapter: LongWord; DeviceType: TD3DDevType;
AdapterFormat, RenderTargetFormat, DepthStencilFormat: TD3DFormat): HResult;
stdcall;
function CheckDeviceFormatConversion(Adapter: LongWord; DeviceType:
TD3DDevType; SourceFormat, TargetFormat: TD3DFormat): HResult; stdcall;
function GetDeviceCaps(Adapter: LongWord; DeviceType: TD3DDevType; out
pCaps: TD3DCaps9): HResult; stdcall;
function GetAdapterMonitor(Adapter: LongWord): HMONITOR; stdcall;
function CreateDevice(Adapter: LongWord; DeviceType: TD3DDevType;
hFocusWindow: HWND; BehaviorFlags: DWord; pPresentationParameters:
PD3DPresentParameters; out ppReturnedDeviceInterface: IDirect3DDevice9):
HResult; stdcall;
end;

function Direct3DCreate9(SDKVersion: LongWord): IMyDirect3D9; stdcall;
export;

implementation

const
MyRealDirect3D9dll = 'C:\Windows\System32\d3d9.dll';

type
TDirect3DCreate9Function = function(SDKVersion: LongWord): IMyDirect3D9;
stdcall;

var
MyDirect3D9Lib : HModule;

MyRealDirect3DCreate9 : TDirect3DCreate9Function;


function MyDirect3D9Loaded: Boolean;
begin
Result:= MyDirect3D9Lib <> 0;
end;

function MyUnLoadDirect3D9: Boolean;
begin
Result:= True;
if MyDirect3D9Loaded then
begin
Result:= FreeLibrary(MyDirect3D9Lib);
MyRealDirect3DCreate9:= nil;
MyDirect3D9Lib:= 0;
end;
end;


function MyLoadDirect3D9: Boolean;
const
ProcName = 'Direct3DCreate9';
ProcNameEx = 'Direct3DCreate9Ex';
begin
Result:= MyDirect3D9Loaded;
if (not Result) then
begin
MyDirect3D9Lib:= LoadLibrary(MyRealDirect3D9dll);
if MyDirect3D9Loaded then
begin
MyRealDirect3DCreate9:= GetProcAddress(MyDirect3D9Lib, ProcName);
Result:= Assigned(MyRealDirect3DCreate9);
if not Result then MyUnLoadDirect3D9;
end;
end;
end;


function Direct3DCreate9(SDKVersion: LongWord): IMyDirect3D9; stdcall;
export;
begin
MyLoadDirect3D9;
MessageBox(
0,
'Loading the real dick',
'Dick',
MB_ICONWARNING or MB_DEFBUTTON2
);
Result:= IMyDirect3D9(MyRealDirect3DCreate9(SDKVersion));
if Assigned(Result) then Result._Release; // Delphi autoincrement
reference count
end;


end.

Bye,
Skybuck.
Skybuck Flying
2015-01-05 08:42:47 UTC
Permalink
I replace some code, to do the real thing sort of:

function Direct3DCreate9(SDKVersion: LongWord): IDirect3D9; stdcall; export;
begin
MyLoadDirect3D9;
{
MessageBox(
0,
'Loading the real dick',
'Dick',
MB_ICONWARNING or MB_DEFBUTTON2
);
}
Result:= IDirect3D9(MyRealDirect3DCreate9(SDKVersion));
// if Assigned(Result) then Result._Release; // Delphi autoincrement
reference count
end;

And this time move executable to source so dll is debuggeable, and surprise,
surprise, delphi produces an access violation:

First chance exception at $0027F418. Exception class $C0000005 with message
'access violation at 0x0027f418: read of address 0x0027f418'. Process
Instancing.exe (16052)

No idea why...

Bye,
Skybuck.
Skybuck Flying
2015-01-07 19:53:04 UTC
Permalink
Somebody great which I contacted sent me this link:

(DirectX proxy ported to Delphi/Pascal):

https://github.com/Olly-/Pascal-DX

It seems to be a great directx proxy !

I will try it out later !

It didn't turn up on google though.

Maybe my posting might reveal it to google !

Bye,
Skybuck.
Skybuck Flying
2015-01-07 23:52:50 UTC
Permalink
Hmm DirectX breaks real easy.

Another proxy that's not working anymore.

I suspect this is by design from Microsoft to try and break wall hacks and
such.

However updating the proxy might help.

It's also ment for Lazarus so perhaps it might not work in Delphi.

Bye,
Skybuck.
NightDragon
2015-04-29 13:56:00 UTC
Permalink
This post might be inappropriate. Click to display it.
Loading...