Skip to content

Commit

Permalink
MM6Patch v2.1:
Browse files Browse the repository at this point in the history
[+] 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.
[+] 32 bit color support.
[+] Custom SND and VID archives that work just like custom LOD archives.
[+] Items stack vertically, like in MM7 and MM8 (add PlaceItemsVertically=0 to INI to disable).
[+] 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 ded9040 commit 1e3ee04
Show file tree
Hide file tree
Showing 56 changed files with 2,010 additions and 163 deletions.
131 changes: 21 additions & 110 deletions MMPatches/MM6Patch/DXProxy.pas
Original file line number Diff line number Diff line change
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,19 +484,17 @@ 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 DXProxyDraw(SrcBuf: ptr; info: PDDSurfaceDesc2);
var
r: TRect;
begin
FPS;
//FPS;
if (scale.DestW <> RenderW) or (scale.DestH <> RenderH) then
begin
RSSetResampleParams(ScalingParam1, ScalingParam2);
Expand Down Expand Up @@ -615,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 @@ -630,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 @@ -718,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 @@ -739,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 @@ -826,9 +799,6 @@ 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]));
Expand All @@ -838,7 +808,7 @@ function TMyDevice.DrawPrimitive(dptPrimitiveType: TD3DPrimitiveType;
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 @@ -896,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 @@ -921,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 @@ -950,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 @@ -1009,11 +937,8 @@ 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);
Expand All @@ -1032,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 @@ -1053,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
50 changes: 1 addition & 49 deletions MMPatches/MM6Patch/Hooks.pas
Original file line number Diff line number Diff line change
Expand Up @@ -3432,49 +3432,6 @@ procedure SmackLoadHook;
@std:
end;

//----- Test

type
TRenderProc = procedure(_, __: int; PartyMoved: Bool);

procedure SetRenderSize(const r: TRect);
const
_SetRenderSize: procedure(_,__,this, vy2, vx2, vy1, vx1: int) = ptr($4A74F0);
_UpdateOutdoorSomething: procedure(_: int=0; __: int=0; this: int = $6296E0) = ptr($4789E0);
_SetGridBand: procedure(_,unk2, unk1, gridband2: int) = ptr($46ED10);
_SetFOV: procedure(_,__,this, h, w: int; fov: int = 65) = ptr($420D00);
LowQuality = pbyte($52D278);
LowRes = pbyte($52D278);
screen_vr = PRect($9DE398);
begin
_SetFOV(0,0, $4D5150, r.Bottom - r.Top + 1, r.Right - r.Left + 1);
screen_vr^:= r;
LowRes^:= 0;
pint($62976C)^:= 10;
pint($629770)^:= 15;
pint($629774)^:= 20;
pint($6296EC)^:= $2000; // dist_mist
if _IndoorOrOutdoor^ = 2 then
_SetGridBand(0, 15, 10, 20);
//LowQuality^:= min(LowQuality^, 1);
with screen_vr^ do
_SetRenderSize(0,0, int(screen_vr), Bottom, Right, Top, Left);
//if _IndoorOrOutdoor^ = 2 then
_UpdateOutdoorSomething;
end;

procedure TestHD(old: TRenderProc; _, PartyMoved: Bool);
const
vr = PRect($52D268);
var
oldBuf: ptr;
begin
SetRenderSize(Rect(1, 0, 640, 479));
old(0,0, PartyMoved);
SetRenderSize(vr^);
//vr^:= oldR;
end;

//----- Buka localization

var
Expand All @@ -3483,7 +3440,7 @@ procedure TestHD(old: TRenderProc; _, PartyMoved: Bool);
//----- HooksList

var
HooksList: array[1..272] of TRSHookInfo = (
HooksList: array[1..269] of TRSHookInfo = (
(p: $42ADE7; newp: @RunWalkHook; t: RShtCall), // Run/Walk check
(p: $453AD3; old: $42ADA0; newp: @KeysHook; t: RShtCall), // My keys handler
(p: $45456E; old: $417F90; newp: @WindowProcCharHook; t: RShtCall), // Map Keys
Expand Down Expand Up @@ -3752,11 +3709,6 @@ procedure TestHD(old: TRenderProc; _, PartyMoved: Bool);
(p: $4A66A3; newp: @SmackLoadHook; t: RShtAfter; size: 6; Querry: hqFixSmackDraw), // Compatible movie render
(p: $4573C6; size: 2; Querry: hqTrueColor), // 32 bit color support
(p: $4B9018; newp: @MyDirectDrawCreate; t: RSht4; Querry: hqTrueColor), // 32 bit color support
//(p: $469FF0; newp: @TestHD; t: RShtFunctionStart),
//(p: $437199+4; old: 640; new: 800; t: RSht4),
//(p: $4371A1+4; old: 480; new: 300; t: RSht4),
//(p: $45816B; size: 2),
(),(),(),
()
);

Expand Down
5 changes: 4 additions & 1 deletion MMPatches/MM6Patch/MM6patch.bdsproj
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,10 @@
<VersionInfoKeys Name="OriginalFilename"></VersionInfoKeys>
<VersionInfoKeys Name="ProductName">GrayFace MM6 Patch</VersionInfoKeys>
<VersionInfoKeys Name="ProductVersion">2.1.0.0</VersionInfoKeys>
</VersionInfoKeys> <Excluded_Packages>
</VersionInfoKeys>


<Excluded_Packages>
<Excluded_Packages Name="C:\Documents and Settings\Serg\Мои документы\Borland Studio Projects\Bpl\dclrx2006.bpl">File C:\Documents and Settings\Serg\Мои документы\Borland Studio Projects\Bpl\dclrx2006.bpl not found</Excluded_Packages>
<Excluded_Packages Name="C:\Documents and Settings\Serg\Мои документы\Borland Studio Projects\Bpl\dclrxbd2006.bpl">File C:\Documents and Settings\Serg\Мои документы\Borland Studio Projects\Bpl\dclrxbd2006.bpl not found</Excluded_Packages>
<Excluded_Packages Name="C:\Documents and Settings\Serg\Мои документы\Borland Studio Projects\Bpl\dclrxdb2006.bpl">File C:\Documents and Settings\Serg\Мои документы\Borland Studio Projects\Bpl\dclrxdb2006.bpl not found</Excluded_Packages>
Expand Down
3 changes: 2 additions & 1 deletion MMPatches/MM6Patch/MM6patch.dpr
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ Version 2.1:
[+] TurnBasedSpeed
[+] MouseLookRememberTime
[+] MouseLookWhileRightClick
[+] PlayMP3 option now supports WAV files
[+] Black potion isn't wasted if it has no effect
[+] Infinite view distance in dungeons
[+] FixInfiniteScrolls option controls corresponding fix
Expand All @@ -204,7 +205,7 @@ Version 2.1:
[*] Now left click (while holding right button) not only cancels right button menu, but also performs action
(MM6)
[+] NoIntro option, just like in other patches. I figured this can be more convenient than "-nomovie" cmd line switch.
[+] PlayMP3 option now supports tracks in Sounds folder, like in GOG version
[+] PlayMP3 option now supports MP3 tracks in Sounds folder, as they are in GOG version
[+] Items stack vertically, like in MM7 and MM8 (controlled by hidden PlaceItemsVertically option)
[-] Scholar NPC not giving +5% exp
[-] +2/+3 weapon skill NPCs didn't effect weapon delay
Expand Down
Binary file not shown.
Binary file not shown.
Binary file added MMPatches/MM6Patch/MM6patch/Files/MM6.exe
Binary file not shown.
Loading

0 comments on commit 1e3ee04

Please sign in to comment.