Skip to content

Commit

Permalink
MM8Patch v2.1:
Browse files Browse the repository at this point in the history
[+] High resolution rendering in Hardware 3D, 32 bit color mode.
[+] Borderless full screen mode (the game runs in your standard resolution, stretched to full screen with black borders as needed).
[+] WindowWidth and WindowHeight options control window size in windowed mode.
[+] Custom SND and VID archives that work just like custom LOD archives.
[+] TurnBasedSpeed (for monsters' turn) and TurnBasedPartySpeed (for party turn) can help you speed up the combat.
[+] PlayMP3 option now supports WAV files in Music folder. WAV always loop properly.
[+] And more...
[-] Many fixes in game code and on maps. I finally went through all maps and fixed all bugs I could find.
  • Loading branch information
GrayFace committed Jul 6, 2018
1 parent 6453800 commit 1534817
Show file tree
Hide file tree
Showing 27 changed files with 926 additions and 138 deletions.
148 changes: 29 additions & 119 deletions MMPatches/MM8Patch/DXProxy.pas
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function MyDirectDrawCreate(lpGUID: PGUID; out lplpDD: IDirectDraw;
const pUnkOuter: IUnknown): HResult; stdcall;
function DXProxyScaleRect(const r: TRect): TRect;
procedure DXProxyOnResize;
procedure DXProxyScale(SrcBuf: ptr; info: PDDSurfaceDesc2);
procedure DXProxyDraw(SrcBuf: ptr; info: PDDSurfaceDesc2);

var
DXProxyRenderW, DXProxyRenderH: int;
Expand Down Expand Up @@ -334,10 +334,6 @@ TMyBackBufferD3D = class(TMySurface, IDirectDrawSurface4)

TMyFrontBufferD3D = class(TMySurface, IDirectDrawSurface4)
public
function Lock(lpDestRect: PRect;
out lpDDSurfaceDesc: TDDSurfaceDesc2; dwFlags: DWORD;
hEvent: THandle): HResult stdcall; reintroduce;
function Unlock(lpRect: PRect): HResult stdcall; reintroduce;
function GetPixelFormat(out fmt: TDDPixelFormat): HResult stdcall; reintroduce;
function Blt(lpDestRect: PRect;
lpDDSrcSurface: IDirectDrawSurface4; lpSrcRect: PRect;
Expand All @@ -354,31 +350,21 @@ TMySurfaceSW = class(TMySurface, IDirectDrawSurface4)
lpDDSrcSurface: IDirectDrawSurface4; lpSrcRect: PRect;
dwFlags: DWORD; lpDDBltFx: PDDBltFX): HResult stdcall; reintroduce;
function BltBatch(const lpDDBltBatch: TDDBltBatch; dwCount: DWORD;
dwFlags: DWORD): HResult stdcall; reintroduce;
dwFlags: DWORD): HResult stdcall; reintroduce; virtual; abstract;
function BltFast(dwX: DWORD; dwY: DWORD;
lpDDSrcSurface: IDirectDrawSurface4; lpSrcRect: PRect;
dwTrans: DWORD): HResult stdcall; reintroduce;
function AddAttachedSurface(lpDDSAttachedSurface: IDirectDrawSurface4) :
HResult stdcall; reintroduce;
function DeleteAttachedSurface(dwFlags: DWORD;
lpDDSAttachedSurface: IDirectDrawSurface4): HResult stdcall; reintroduce;
function EnumAttachedSurfaces(lpContext: Pointer;
lpEnumSurfacesCallback: TDDEnumSurfacesCallback2): HResult stdcall; reintroduce;
function EnumOverlayZOrders(dwFlags: DWORD; lpContext: Pointer;
lpfnCallback: TDDEnumSurfacesCallback2): HResult stdcall; reintroduce;
function Flip(lpDDSurfaceTargetOverride: IDirectDrawSurface4;
dwFlags: DWORD): HResult stdcall; reintroduce;
function GetAttachedSurface(const lpDDSCaps: TDDSCaps2;
out lplpDDAttachedSurface: IDirectDrawSurface4): HResult stdcall; reintroduce;
end;


TMyFrontBufferSW = class(TMySurfaceSW, IDirectDrawSurface4)
public
function Lock(lpDestRect: PRect;
out lpDDSurfaceDesc: TDDSurfaceDesc2; dwFlags: DWORD;
hEvent: THandle): HResult stdcall; reintroduce;
function Unlock(lpRect: PRect): HResult stdcall; reintroduce;
function GetPixelFormat(out fmt: TDDPixelFormat): HResult stdcall; reintroduce;
function Blt(lpDestRect: PRect;
lpDDSrcSurface: IDirectDrawSurface4; lpSrcRect: PRect;
Expand Down Expand Up @@ -433,11 +419,9 @@ function DXProxyScaleRect(const r: TRect): TRect;

procedure ScaleRect(var r: PRect);
begin
if r <> nil then
begin
ScaleRect_Rect:= DXProxyScaleRect(r^);
r:= @ScaleRect_Rect;
end;
if r = nil then exit;
ScaleRect_Rect:= DXProxyScaleRect(r^);
r:= @ScaleRect_Rect;
end;

procedure CalcRenderSize;
Expand Down Expand Up @@ -500,33 +484,30 @@ procedure FPS;
begin
inc(FPSUp);
k:= GetTickCount;
if k >= FPSTime then
begin
zM(FPSUp);
FPSUp:= 0;
FPSTime:= k + 1000;
end;
if k < FPSTime then exit;
zM(FPSUp);
FPSUp:= 0;
FPSTime:= k + 1000;
end;

procedure DXProxyScale(SrcBuf: ptr; info: PDDSurfaceDesc2);
procedure DXProxyDraw(SrcBuf: ptr; info: PDDSurfaceDesc2);
var
r: TRect;
begin
//FPS;
if (scale.DestW <> RenderW) or (scale.DestH <> RenderH) then
begin
RSSetResampleParams(ScalingParam1, ScalingParam2);
scale.Init(_ScreenW^, _ScreenH^, min(RenderW, (RenderH*_ScreenW^ + _ScreenH^ div 2) div _ScreenH^), RenderH);
scale.DestX:= (RenderW - min(RenderW, (RenderH*_ScreenW^ + _ScreenH^ div 2) div _ScreenH^)) div 2;
scale.Init(_ScreenW^, _ScreenH^, RenderW, RenderH);
with Options.RenderRect do
r:= DXProxyScaleRect(Rect(max(0, Left - 1), max(0, Top - 1), Right + 1, Bottom + 1));
r.Right:= min(r.Right, scale.DestW);
r.Right:= min(r.Right, RenderW);
r.Bottom:= min(r.Bottom, RenderH);
scale3D:= scale.ScaleRect(r);
scaleT:= scale.ScaleRect(Rect(0, 0, scale.DestW, r.Top));
scaleB:= scale.ScaleRect(Rect(0, r.Bottom, scale.DestW, scale.DestH));
scaleT:= scale.ScaleRect(Rect(0, 0, RenderW, r.Top));
scaleB:= scale.ScaleRect(Rect(0, r.Bottom, RenderW, RenderH));
scaleL:= scale.ScaleRect(Rect(0, r.Top, r.Left, r.Bottom));
scaleR:= scale.ScaleRect(Rect(r.Right, r.Top, scale.DestW, r.Bottom));
scaleR:= scale.ScaleRect(Rect(r.Right, r.Top, RenderW, r.Bottom));
end;
{$IFNDEF mm6}
if _IsD3D^ then
Expand Down Expand Up @@ -616,13 +597,6 @@ procedure THookedObject.InitVMT(const Obj: IUnknown; this: IUnknown; PObj: ptr;

{ TMyDirectDraw }

{function TMyDirectDraw.CreateDevice(const rclsid: TRefClsID;
lpDDS: IDirectDrawSurface4; out lplpD3DDevice: IDirect3DDevice3;
pUnkOuter: IInterface): HResult;
begin
Result:= D3D.CreateDevice(rclsid, IDirectDrawSurface4(GetRaw(lpDDS)), lplpD3DDevice, pUnkOuter);
end;}

function TMyDirectDraw.CreateDevice(const rclsid: TRefClsID;
lpDDS: IDirectDrawSurface4; out lplpD3DDevice: IDirect3DDevice3;
pUnkOuter: IInterface): HResult;
Expand All @@ -631,7 +605,7 @@ function TMyDirectDraw.CreateDevice(const rclsid: TRefClsID;
Result:= D3D.CreateDevice(rclsid, BackBuffer, lplpD3DDevice, pUnkOuter)
else
Result:= D3D.CreateDevice(rclsid, lpDDS, lplpD3DDevice, pUnkOuter);
if (Result = DD_OK) {and DXProxyActive} then
if Result = DD_OK then
TMyDevice.Hook(lplpD3DDevice);
end;

Expand Down Expand Up @@ -719,11 +693,9 @@ function TMyDirectDraw.CreateViewport(var lplpD3DViewport3: IDirect3DViewport3;
pUnkOuter: IInterface): HResult;
begin
Result:= D3D.CreateViewport(lplpD3DViewport3, pUnkOuter);
if (Result = DD_OK) {and DXProxyActive} then
begin
TMyViewport.Hook(lplpD3DViewport3);
Viewport:= lplpD3DViewport3;
end;
if Result <> DD_OK then exit;
TMyViewport.Hook(lplpD3DViewport3);
Viewport:= lplpD3DViewport3;
end;

destructor TMyDirectDraw.Destroy;
Expand All @@ -740,7 +712,7 @@ destructor TMyDirectDraw.Destroy;
function TMyDirectDraw.GetCaps(lpDDDriverCaps, lpDDHELCaps: PDDCaps): HResult;
begin
Result:= DDraw.GetCaps(lpDDDriverCaps, lpDDHELCaps);
// Avoid MouseAsync usage:
// To use buffer instead of draw surface that's painted with 5 Blt's:
// remove DDCAPS_BLT from dwSVBCaps or remove DDCKEYCAPS_SRCBLT from dwSVBCKeyCaps
lpDDDriverCaps.dwSVBCKeyCaps:= lpDDDriverCaps.dwSVBCKeyCaps and not DDCKEYCAPS_SRCBLT;
end;
Expand Down Expand Up @@ -827,19 +799,16 @@ function TMyDevice.DrawPrimitive(dptPrimitiveType: TD3DPrimitiveType;
var
i: int;
begin
Result:= DD_OK;
if dptPrimitiveType <> D3DPT_TRIANGLEFAN then
exit;
if int(dwVertexCount) > length(VertexBuf) then
SetLength(VertexBuf, dwVertexCount*2);
CopyMemory(@VertexBuf[0], @lpvVertices, dwVertexCount*SizeOf(VertexBuf[0]));
for i:= 0 to dwVertexCount - 1 do
begin
VertexBuf[i].x:= VertexBuf[i].x*RenderW/_ScreenW^*3/4;
VertexBuf[i].x:= VertexBuf[i].x*RenderW/_ScreenW^;
VertexBuf[i].y:= VertexBuf[i].y*RenderH/_ScreenH^;
end;
Result:= Obj.DrawPrimitive(dptPrimitiveType,
dwVertexTypeDesc, VertexBuf[0], dwVertexCount, dwFlags)
dwVertexTypeDesc, VertexBuf[0], dwVertexCount, dwFlags);
end;

function TMyDevice.GetCurrentViewport(
Expand Down Expand Up @@ -897,18 +866,6 @@ function TMyFrontBufferD3D.GetPixelFormat(out fmt: TDDPixelFormat): HResult;
Result:= DD_OK;
end;

function TMyFrontBufferD3D.Lock(lpDestRect: PRect;
out lpDDSurfaceDesc: TDDSurfaceDesc2; dwFlags: DWORD;
hEvent: THandle): HResult;
begin
Result:= DDERR_GENERIC;
end;

function TMyFrontBufferD3D.Unlock(lpRect: PRect): HResult;
begin
Result:= DDERR_GENERIC;
end;

{ TMySurface }

function TMySurfaceSW.AddAttachedSurface(
Expand All @@ -922,19 +879,10 @@ function TMySurfaceSW.Blt(lpDestRect: PRect; lpDDSrcSurface: IDirectDrawSurface4
begin
// ignore MM6 tricks with extra surfaces when an item is carried
if GetRaw(lpDDSrcSurface) = ptr(FrontBuffer) then
begin
Result:= DD_OK;
exit;
end;
Result:= Surf.Blt(lpDestRect, IDirectDrawSurface4(GetRaw(lpDDSrcSurface)),
lpSrcRect, dwFlags, lpDDBltFx);
end;

function TMySurfaceSW.BltBatch(const lpDDBltBatch: TDDBltBatch; dwCount,
dwFlags: DWORD): HResult;
begin
Assert(false, 'Not implemented');
Result:= DD_OK;
Result:= DD_OK
else
Result:= Surf.Blt(lpDestRect, IDirectDrawSurface4(GetRaw(lpDDSrcSurface)),
lpSrcRect, dwFlags, lpDDBltFx);
end;

function TMySurfaceSW.BltFast(dwX, dwY: DWORD;
Expand All @@ -951,33 +899,12 @@ function TMySurfaceSW.DeleteAttachedSurface(dwFlags: DWORD;
Result:= Surf.DeleteAttachedSurface(dwFlags, IDirectDrawSurface4(GetRaw(lpDDSAttachedSurface)));
end;

function TMySurfaceSW.EnumAttachedSurfaces(lpContext: Pointer;
lpEnumSurfacesCallback: TDDEnumSurfacesCallback2): HResult;
begin
Assert(false, 'Not implemented');
Result:= DD_OK;
end;

function TMySurfaceSW.EnumOverlayZOrders(dwFlags: DWORD; lpContext: Pointer;
lpfnCallback: TDDEnumSurfacesCallback2): HResult;
begin
Assert(false, 'Not implemented');
Result:= DD_OK;
end;

function TMySurfaceSW.Flip(lpDDSurfaceTargetOverride: IDirectDrawSurface4;
dwFlags: DWORD): HResult;
begin
Result:= Surf.Flip(IDirectDrawSurface4(GetRaw(lpDDSurfaceTargetOverride)), dwFlags);
end;

function TMySurfaceSW.GetAttachedSurface(const lpDDSCaps: TDDSCaps2;
out lplpDDAttachedSurface: IDirectDrawSurface4): HResult;
begin
Assert(false, 'Not implemented');
Result:= DD_OK;
end;

function TMySurfaceSW.Lock(lpDestRect: PRect;
out lpDDSurfaceDesc: TDDSurfaceDesc2; dwFlags: DWORD;
hEvent: THandle): HResult;
Expand Down Expand Up @@ -1010,16 +937,13 @@ function TMyFrontBufferSW.Blt(lpDestRect: PRect;
info: TDDSurfaceDesc2;
r: TRect;
begin
if DrawBufSW = nil then
begin
Result:= DD_OK;
exit;
end;
Result:= DD_OK;
if DrawBufSW = nil then exit;
FillChar(info, SizeOf(info), 0);
info.dwSize:= SizeOf(info);
Result:= BackBuffer.Lock(nil, info, DDLOCK_NOSYSLOCK or DDLOCK_WAIT, 0);
if Result <> DD_OK then exit;
DXProxyScale(ptr(DrawBufSW), @info);
DXProxyDraw(ptr(DrawBufSW), @info);
BackBuffer.Unlock(nil);
if lpDDSrcSurface <> MyBackBuffer then
_NeedRedraw^:= 1;
Expand All @@ -1033,18 +957,6 @@ function TMyFrontBufferSW.GetPixelFormat(out fmt: TDDPixelFormat): HResult;
Result:= DD_OK;
end;

function TMyFrontBufferSW.Lock(lpDestRect: PRect;
out lpDDSurfaceDesc: TDDSurfaceDesc2; dwFlags: DWORD;
hEvent: THandle): HResult;
begin
Result:= DDERR_GENERIC;
end;

function TMyFrontBufferSW.Unlock(lpRect: PRect): HResult;
begin
Result:= DDERR_GENERIC;
end;

{ TMyBackBufferSW }

function TMyBackBufferSW.Blt(lpDestRect: PRect;
Expand All @@ -1054,8 +966,6 @@ function TMyBackBufferSW.Blt(lpDestRect: PRect;
if (lpDDSrcSurface = nil) and (DrawBufSW <> nil) then
FillChar(DrawBufSW[0], length(DrawBufSW)*2, 0);
Result:= DD_OK;
{else
Result:= inherited Blt(lpDestRect, lpDDSrcSurface, lpSrcRect, dwFlags, lpDDBltFx);}
end;

function TMyBackBufferSW.Lock(lpDestRect: PRect;
Expand Down
Loading

0 comments on commit 1534817

Please sign in to comment.