Skip to content

Commit

Permalink
Update scale-down-volume-of-sounds fix (#37)
Browse files Browse the repository at this point in the history
* Update scale-down-volume-of-sounds fix

* Update version and changelog
* Update readme
* Update main readme
* Update changelog
* Update copyright years
* Add separate changelog for patcher
  • Loading branch information
bibendovsky authored Jan 10, 2023
1 parent 31cbcaa commit bad8d22
Show file tree
Hide file tree
Showing 9 changed files with 206 additions and 92 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# EAXEFX changelog


## [1.0.10] - 2023-10-01
### Changed
- Patch for Doom 3 (2004) to scale down volume of all sounds (see https://github.com/dhewm/dhewm3/commit/4567f265392b5ab95a335f8896ff003a743990e4 for details).

## [1.0.9] - 2022-12-18
### Fixed
- Doom 3 (2004) "idSoundCache: error unloading data from OpenAL hardware buffer" patch.
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ OR OTHER DEALINGS IN THE SOFTWARE.


cmake_minimum_required (VERSION 3.8.2 FATAL_ERROR)
project (eaxefx_solution VERSION 1.0.9 LANGUAGES NONE)
project (eaxefx_solution VERSION 1.0.10 LANGUAGES NONE)


add_subdirectory (src/eaxefx_sys_lib)
Expand Down
76 changes: 49 additions & 27 deletions doc/doom_3_2004_channel_contribution_fix.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,47 +2,69 @@ Doom 3 channel contribution fix
===============================

Fix for source port [DHEWM3](https://github.com/dhewm/dhewm3):
https://github.com/dhewm/dhewm3/commit/3c01757d27a22a3858737f6b51e85895d2fac887
https://github.com/dhewm/dhewm3/commit/c8321ddd1ffa4ea3fea351a362ad091201348bd9

The idea is to scale volume down in method `idSoundWorldLocal::AddChannelContribution` (file "snd_world.cpp").
The main idea is to clamp the volume to 1.0,
and then to scale volume down by one third
in method `idSoundWorldLocal::AddChannelContribution` (file "snd_world.cpp").


Original block
Original blocks
```
...
004f7155 84 db TEST BL, BL
004f7157 8b 8c 24 18 81 00 00 MOV this, dword ptr [ESP + sound]
004f715e d9 5c 24 10 FSTP dword ptr [ESP + volume]
004f70e6 d8 4c 24 10 FMUL dword ptr [ESP + volume ]
...
0074a794-0074a7ad 00 (26 bytes)
004f70f9 d9 5c 24 14 FSTP dword ptr [ESP + volume ]
...
004f720c d9 44 24 10 FLD dword ptr [ESP + volume ]
004f7210 8b 8c 24 1c 81 00 00 MOV this ,dword ptr [ESP + chan ]
...
0074a794-0074a7ca 00 (55 bytes)
...
```


FIX
---
Put one-third into local variable `volume` and multiply it by ST(0).
Clamp.
Put extra code at address `0074a794`.
```
...
____to_patch_1:
004f7155 e9 3a 36 25 00 JMP ___patch_1
004f715a 90
004f715b 90
004f715c 90
004f715d 90
____from_patch_1:
004f715e d9 5c 24 10 FSTP dword ptr [ESP + volume]
...
____patch_1:
; Set `volume` to one-third.
0074a794 c7 44 24 10 ab aa aa 3e MOV dword ptr [ESP + 0x10], 0x3eaaaaab
; Multiplicate it.
0074a79c d8 4c 24 10 FMUL dword ptr [ESP + 0x10]
; Execute the preserved fragment of code.
0074a7a0 84 db TEST BL, BL
0074a7a2 8b 8c 24 18 81 00 00 MOV ECX, dword ptr [ESP + 0x8118]
; Go back.
0074a7a9 e9 b0 c9 da ff JMP ____from_patch_1
004f70e6 d9 5c 24 38 FSTP dword ptr [ESP + 0x38 ] ; Save "s_volume" gain.
...
004f70f9 90 NOP ; Don't multiply by "s_volume" here.
004f70fa 90 NOP
004f70fb 90 NOP
004f70fc 90 NOP
...
____to_patch_3:
004f720c e9 83 35 25 00 JMP ____patch_3
004f7211 90 NOP
004f7212 90 NOP
004f7213 90 NOP
004f7214 90 NOP
004f7215 90 NOP
004f7216 90 NOP
____from_patch_3:
...
____patch_3:
0074a794 d9 44 24 10 FLD dword ptr [ESP + 0x10 ] ; volume -> ST1
0074a798 d9 e8 FLD1 ; 1.0F -> ST0
0074a79a de d9 FCOMPP
0074a79c df e0 FNSTSW AX
0074a79e f6 c4 01 TEST AH ,0x1
0074a7a1 74 04 JZ ____patch_3_keep_current ; if (1.0F >= volume)
0074a7a3 d9 e8 FLD1 ; volume = 1.0F;
0074a7a5 eb 04 JMP ____patch_3_exit_clamp
____patch_3_keep_current XREF[1]: 0074a7a1 (j)
0074a7a7 d9 44 24 10 FLD dword ptr [ESP + 0x10 ] ; volume -> ST0;
____patch_3_exit_clamp XREF[1]: 0074a7a5 (j)
0074a7ab c7 44 24 10 ab aa aa 3e MOV dword ptr [ESP + 0x10 ],0x3eaaaaab ; 0.(3)
0074a7b3 d8 4c 24 10 FMUL dword ptr [ESP + 0x10 ] ; volume /= 3;
0074a7b7 d8 4c 24 38 FMUL dword ptr [ESP + 0x38 ] ; volume *= <saved "s_volume" gain>;
0074a7bb d9 54 24 10 FST dword ptr [ESP + 0x10 ] ; ST0 -> volume
0074a7bf 8b 8c 24 1c 81 00 00 MOV ECX ,dword ptr [ESP + 0x811c ] ; saved code
0074a7c6 e9 4c ca da ff JMP ____from_patch_3
...
```
32 changes: 16 additions & 16 deletions doc/doom_3_2004_init_reverb_props.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ Original blocks:
004ecf83 52 PUSH EDX
...
0074a7ae 00
0074a840 00
... 00
0074a7cb 00
0074a85d 00
...
007ce558 00
... 00
Expand All @@ -30,28 +30,28 @@ Modified blocks:
```
...
____to_patch_1:
004ecf7f e9 2a d8 25 00 JMP ____patch_1
004ecf7f e9 bc d8 25 00 JMP ____patch_1
...
____patch_1:
; Preserve registers
0074a7ae 56 PUSH ESI
0074a7af 57 PUSH EDI
0074a7b0 51 PUSH ECX
0074a840 56 PUSH ESI
0074a841 57 PUSH EDI
0074a842 51 PUSH ECX
; Copy default reverb properties.
0074a7b1 be 58 e5 7c 00 MOV ESI, 0x7ce558
0074a7b6 89 ef MOV EDI, EBP
0074a843 be 58 e5 7c 00 MOV ESI, 0x7ce558
0074a848 89 ef MOV EDI, EBP
; 28 (0x1c) properties.
0074a7b8 b9 1c 00 00 00 MOV ECX, 0x1c
0074a7bd f3 a5 MOVSD.REP ES:EDI, ESI
0074a84a b9 1c 00 00 00 MOV ECX, 0x1c
0074a84f f3 a5 MOVSD.REP ES:EDI, ESI
; Restore registers.
0074a7bf 59 POP ECX
0074a7c0 5f POP EDI
0074a7c1 5e POP ESI
0074a851 59 POP ECX
0074a852 5f POP EDI
0074a853 5e POP ESI
; Execute preserved code fragment.
0074a7c2 8d 54 24 10 LEA EDX, [ESP + 0x10]
0074a7c6 52 PUSH EDX
0074a854 8d 54 24 10 LEA EDX, [ESP + 0x10]
0074a858 52 PUSH EDX
; Go back.
0074a7c7 e9 b8 27 da ff JMP idEFXFile::ReadEffect::____from_patch_1
0074a859 e9 26 27 da ff JMP ____from_patch_1
...
____dat_default_reverb:
007ce558 00 00 00 00 ulong 0 ; ulEnvironment
Expand Down
30 changes: 30 additions & 0 deletions src/eaxefx_app_patcher/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# EAXEFX App Patcher changelog


## [1.0.4] - 2023-10-01
### Changed
- Patch for Doom 3 (2004) to scale down volume of all sounds (see https://github.com/dhewm/dhewm3/commit/4567f265392b5ab95a335f8896ff003a743990e4 for details).

## [1.0.3] - 2022-12-18
### Fixed
- Doom 3 (2004) "idSoundCache: error unloading data from OpenAL hardware buffer" patch.

### Changed
- Rewritten patcher to achieve a small size of executable.

## [1.0.2] - 2022-08-09
### Added
- Patch for Doom 3 (2004) to fix error "idSoundCache: error unloading data from OpenAL hardware buffer".


## [1.0.1] - 2022-08-04
### Added
- Patch for Doom 3 (2004) to scale down volume of all sounds (see https://github.com/dhewm/dhewm3/commit/3c01757d27a22a3858737f6b51e85895d2fac887 for details).
- Patch for Doom 3 (2004) to initialize reverb properties with default values (https://www.pcgamingwiki.com/wiki/Doom_3#Incorrect_EAX_effect_in_Doom3:_Ressurection_of_evil_with_OpenAL.2FEAX).


## [1.0.0] - 2021-04-23
### Added
- Patch for Doom 3 (2004) to fix visual twitch bug (https://www.pcgamingwiki.com/wiki/Doom_3#Visual_twitch_bug_with_OpenAL.2FEAX).
- Quake 4 (2005) source occlusion out of range patch.
- Prey (2006) source occlusion out of range patch.
10 changes: 8 additions & 2 deletions src/eaxefx_app_patcher/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#[[
EAX App Patcher
Copyright (c) 2020-2022 Boris I. Bendovsky (bibendovsky@hotmail.com) and Contributors.
Copyright (c) 2020-2023 Boris I. Bendovsky (bibendovsky@hotmail.com) and Contributors.
SPDX-License-Identifier: MIT
]]

cmake_minimum_required(VERSION 3.8.2 FATAL_ERROR)
project(eaxefx_app_patcher VERSION 1.0.3 LANGUAGES C)
project(eaxefx_app_patcher VERSION 1.0.4 LANGUAGES C)

set(EAXEFX_APP_PATCHER_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}")
message(STATUS "[${PROJECT_NAME}] v${EAXEFX_APP_PATCHER_VERSION}")
Expand Down Expand Up @@ -117,3 +117,9 @@ install(
DESTINATION "."
RENAME "${PROJECT_NAME}.txt"
)

install(
FILES CHANGELOG.md
DESTINATION "."
RENAME "${PROJECT_NAME}_changelog.txt"
)
2 changes: 1 addition & 1 deletion src/eaxefx_app_patcher/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ With custom CRT:
6 - Disclaimer
==============

Copyright (c) 2020-2022 Boris I. Bendovsky (bibendovsky@hotmail.com) and Contributors.
Copyright (c) 2020-2023 Boris I. Bendovsky (bibendovsky@hotmail.com) and Contributors.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
Loading

0 comments on commit bad8d22

Please sign in to comment.