Skip to content

Commit

Permalink
Attempt at tackling artifacts in unopened/unopenable chests
Browse files Browse the repository at this point in the history
  • Loading branch information
GrayFace committed Dec 28, 2021
1 parent 5c9f7c6 commit 6a44d1c
Show file tree
Hide file tree
Showing 6 changed files with 231 additions and 68 deletions.
5 changes: 0 additions & 5 deletions MMPatches/MM7Patch/Common.pas
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ interface
_ScreenBuffer = pptr($E31B54);
_TimeDelta = pint($50BA7C);
_Flying = pint($ACD53C);
_MapMonsters = $5FEFD8;
_IsD3D = pbool($DF1A68);
_startinwindow = pbool($DF1A6C);
_PlayersArray = $ACD804;
Expand Down Expand Up @@ -132,10 +131,6 @@ interface

_Chest_CanPlaceItem: function(n1, itemType, pos, chest: int): BOOL = ptr($41FE1A);
_Chest_PlaceItem: procedure(n1, itemIndex, pos, chest: int) = ptr($4200E7);
_ChestWidth = $4E2BEC;
_ChestHeight = $4E2C0C;
_Chests = $5E4FD0;
_ChestOff_Size = 5324;

_Character_GetWeaponDelay: function(n1, n2: int; this:ptr; ranged: LongBool):int = ptr($48E19B);
_Character_IsAlive: function(a1,a2, member:ptr):Bool = ptr($492C03);
Expand Down
41 changes: 1 addition & 40 deletions MMPatches/MM7Patch/Hooks.pas
Original file line number Diff line number Diff line change
Expand Up @@ -964,42 +964,6 @@ procedure ChangeTrackHook;
test byte ptr [$6BE1E4], $10
end;

//----- Fix chests: place items that were left over

procedure FixChest(p, chest: int);
var
ItemsToPlace: array[0..139] of int;
i, j, h: int;
begin
h:= pint(_ChestWidth + 4*pword(p)^)^*pint(_ChestHeight + 4*pword(p)^)^ - 1;
inc(p, 4);
for i := 0 to 139 do
ItemsToPlace[i]:= pint(p + _ItemOff_Size*i)^;
inc(p, _ItemOff_Size*140);
for i := 0 to h do
if pint2(p + i*2)^ > 0 then
ItemsToPlace[pint2(p + i*2)^ - 1]:= 0;
for i := 0 to 139 do
if ItemsToPlace[i] <> 0 then
for j := 0 to h do
if (pint2(p + j*2)^ = 0) and _Chest_CanPlaceItem(0, ItemsToPlace[i], j, chest) then
begin
_Chest_PlaceItem(0, i, j, chest);
break;
end;
end;

procedure FixChestHook;
asm
test byte ptr [edi], 2
jz @exit
lea eax, [edi - 2]
mov edx, ecx
call FixChest
mov [esp], $42041C
@exit:
end;

//----- Limit blaster & bow speed with BlasterRecovery

procedure FixBlasterSpeed;
Expand Down Expand Up @@ -3211,7 +3175,7 @@ procedure FixSimpleMessagePersist;
//----- HooksList

var
HooksList: array[1..325] of TRSHookInfo = (
HooksList: array[1..324] of TRSHookInfo = (
(p: $45B0D1; newp: @KeysHook; t: RShtCall; size: 6), // My keys handler
(p: $4655FE; old: $452C75; backup: @@SaveNamesStd; newp: @SaveNamesHook; t: RShtCall), // Buggy autosave file name localization
(p: $45E5A4; old: $45E2D0; backup: @FillSaveSlotsStd; newp: @FillSaveSlotsHook; t: RShtCall), // Fix Save/Load Slots
Expand Down Expand Up @@ -3287,7 +3251,6 @@ procedure FixSimpleMessagePersist;
(p: $466E5D; newp: @ErrorHook3; t: RShtCall; size: 6), // Report errors
(p: $4AA0CF; newp: @ChangeTrackHook; t: RShtCall; size: 7), // MusicLoopsCount
(p: $432AC8; old: $7B; new: $71; t: RSht1), // Fix menu return
(p: $420412; newp: @FixChestHook; t: RShtCall; Querry: 11), // Fix chests: place items that were left over
(p: $48E4E3; newp: @FixBlasterSpeed; t: RShtCall; size: 6), // Limit blaster & bow speed with BlasterRecovery
(p: $466CD8; newp: @DDrawErrorHook; t: RShtJmp), // Ignore DDraw errors
(p: $42262C; old: $D75; new: $22EB; t: RSht2), // Remove code left from MM6 (pretty harmless, but still a bug)
Expand Down Expand Up @@ -3625,8 +3588,6 @@ procedure ApplyDeferredHooks;
RSApplyHooks(HooksList, 9);
if Options.ProgressiveDaggerTrippleDamage then
RSApplyHooks(HooksList, 10);
if Options.FixChests then
RSApplyHooks(HooksList, 11);
if Options.DataFiles then
RSApplyHooks(HooksList, 12);
if Options.FixGMStaff then
Expand Down
9 changes: 9 additions & 0 deletions MMPatches/MM7Patch/MM7patch.dpr
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,15 @@ Version 2.5.2:
[-] "Nothing here" was shown on the screen after a dialog with a guard
[-] My bug: List of all conditions wasn't displayed in right click menu for Condition in Stats screen
Version 2.5.4:
(MM6-MM8)
[-]
(MM7, MM8)
[-] My bug: FixMonstersBlockingShots didn't work right
(MM7)
[-] My bug: IndoorFovMul was only working in UILayout mode
[!!] MM8 https://discord.com/channels/296507109997019137/296508593744773120/924945750427861033
[!!] https://discord.com/channels/296507109997019137/296508593744773120/900738954477834260
[!!] Configure controls like in MM6, keyboard layout-independant in-game Controls
[!!] Show videos from MM6 without black bars, support HD videos
Expand Down
4 changes: 2 additions & 2 deletions MMPatches/MMCommon/D3DHooks.pas
Original file line number Diff line number Diff line change
Expand Up @@ -1016,7 +1016,7 @@ procedure MouseItemDrawHook(f: TRightClickDrawProc; _, this: int);

procedure FixIndoorFOVProcD3D(var v: Single);
begin
if (m8 = 1) or IsLayoutActive then
if FixIndoorFOV or IsLayoutActive then
with Options.RenderRect do
v:= IndoorAntiFov*ViewMulFactor*DynamicFovFactor(Right - Left, Bottom - Top);
end;
Expand Down Expand Up @@ -1483,7 +1483,7 @@ procedure ApplyHooksD3D;
end;
ApplyHooks(hqLayout);
end;
if (Options.UILayout <> nil) or (IndoorAntiFov <> 369) {$IFDEF MM8}or FixIndoorFOV{$ENDIF} then
if (Options.UILayout <> nil) or FixIndoorFOV then
ApplyHooks(hqFixIndoorFOV);
end;

Expand Down
48 changes: 46 additions & 2 deletions MMPatches/MMCommon/MMCommon.pas
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ interface

const
hqPostponeIntro = 2;
hqFixChests = 11;
hqFixObelisks = 26;
hqWindowSize = 27;
hqBorderless = 28;
Expand Down Expand Up @@ -248,7 +249,7 @@ interface
MouseLookChanged2, BorderlessTopmost: Boolean;
DoubleSpeed: BOOL;
{$IFNDEF mm6}
NoVideoDelays, DisableAsyncMouse, ShowTreeHints: Boolean;
NoVideoDelays, DisableAsyncMouse, ShowTreeHints, FixIndoorFOV: Boolean;
TurnBasedWalkDelay, TreeHintsVal: int;
MipmapsBase, MipmapsBasePat: TStringList;
ViewMulFactor: ext = 1;
Expand All @@ -270,7 +271,7 @@ interface
UseMM7text, SupportMM7ResTool: Boolean;
FlyNPCScreen: int = 4;
{$ELSEIF defined(mm8)}
NoWaterShoreBumpsSW, FixQuickSpell, FixIndoorFOV: Boolean;
NoWaterShoreBumpsSW, FixQuickSpell: Boolean;
MouseBorder, StartupCopyrightDelay: int;
{$IFEND}

Expand Down Expand Up @@ -513,6 +514,29 @@ TSpellBuff = record
PSpellInfoArray = ^TSpellInfoArray;
TSpellInfoArray = array[0..99 + m8*33] of TSpellInfo;

PItem = ^TItem;
TItem = packed record
Number: int;
Bonus: int;
BonusStrength: int;
Bonus2: int;
Charges: int;
Condition: int;
BodyLocation: byte;
MaxCharges: byte;
Owner: byte;
unk: byte;
{$IFNDEF mm6}BonusExpireTime: int64;{$ENDIF}
end;

PChest = ^TChest;
TChest = packed record
Pic: int2;
Bits: uint2;
Items: array[1..140] of TItem;
Inventory: array[0..139] of int2;
end;

{$IFDEF mm6}
PSkills = PByteArray;
{$ELSE}
Expand Down Expand Up @@ -593,6 +617,23 @@ TSpellBuff = record
__MonstersLimit = m6*$4A35FA + m7*$4BBED6 + m8*$4BA086;
_MonstersLimit = pint(__MonstersLimit);
__MonstersSummonLimit = m6*$4A35FA + m7*$44F6FD + m8*$44CE1F;
__pMapMonsters = m6*$4014BB + m7*$40123A + m8*$40123F;
_pMapMonsters = ppchar(__pMapMonsters);
__pChestWidth = m6*$41DEC0 + m7*$41FE3D + m8*$41F2B1;
__pChestHeight = m6*$41DEC7 + m7*$41FE43 + m8*$41F2B7;
__pChests = m6*$41DEB9 + m7*$41FE31 + m8*$41F2A5;
__pChestsEnd = m6*$456695 + m7*$450537 + m8*$44DC7F;
_pChestWidth = ppchar(__pChestWidth);
_pChestHeight = ppchar(__pChestHeight);
_pChests = ppchar(__pChests);
_pChestsEnd = pptr(__pChestsEnd);
__pArtifactsFound = m6*$448A90 + m7*$4568F7 + m8*$454169;
_pArtifactsFound = ppchar(__pArtifactsFound);
__ArtifactsFoundBase = m6*$448ADF + m7*$45693A + m8*$4541C0;
_ArtifactsFoundBase = pint(__ArtifactsFoundBase);
__ArtifactsFoundCount = m6*$448A99 + m7*$456901 + m8*$454176;
_ArtifactsFoundCount = pbyte(__ArtifactsFoundCount);


_ItemOff_Number = 0;
_ItemOff_Bonus = 4;
Expand All @@ -607,9 +648,11 @@ TSpellBuff = record
_ItemCond_TemporaryBonus = 8;
_ItemCond_Stolen = $100*(1 - m6);
_ItemCond_Hardened = $200*(1 - m6);
_ItemCond_ChestArtifact = $400;

_ChestOff_Items = 4;
_ChestOff_Inventory = 4 + _ItemOff_Size*140;
_ChestOff_Size = 284 + 140*_ItemOff_Size;

_CharOff_ItemMainHand = m6*$142C + m7*$194C + m8*$1C08;
_CharOff_Items = m6*$128 + m7*$1F0 + m8*$484; // The actual offset is bigger, because they're indexed from 1 instead of 0
Expand Down Expand Up @@ -1184,6 +1227,7 @@ procedure LoadIni;
FixIceBoltBlast:= ReadBool('FixIceBoltBlast', true, false);
FixMonsterAttackTypes:= ReadBool('FixMonsterAttackTypes', true, false);
IndoorAntiFov:= Round(300/ReadFloat('IndoorFovMul', 300/369, false));
FixIndoorFOV:= FixIndoorFOV or (IndoorAntiFov <> 369);
FixSouldrinker:= ReadBool('FixSouldrinker', true, false);
FixClubsDelay:= ReadBool('FixClubsDelay', true, false);
ClimbBetter:= ReadBool('ClimbBetter', true, false);
Expand Down
Loading

0 comments on commit 6a44d1c

Please sign in to comment.