Skip to content

Commit

Permalink
Gamefix RA2: CnCNet is now default / refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Root-Core authored Mar 20, 2024
1 parent 883b45e commit d9773f4
Showing 1 changed file with 40 additions and 23 deletions.
63 changes: 40 additions & 23 deletions gamefixes-steam/2229850.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
""" Game fix for Command & Conquer Red Alert™ 2 and Yuris Revenge™
""" Game fix for Command & Conquer Red Alert™ 2 and Yuri's Revenge™
"""
#pylint: disable=C0103

Expand All @@ -8,34 +8,51 @@
from protonfixes.logger import log

def main():
""" Launch CnCNet Launcher - if installed, install it if requested
""" Install and launch the CnCNet Launcher
The game crashes, when the launcher and it's patches are installed
and Ra2.exe or RA2MD.exe are called directly by Steam.
For this reason we must always use the launcher, if present.
It fixes several issues, allows multiplayer and provides a working UI,
while the game has sometimes problems like missing or shifted buttons.
The game will just show a black screen without cnc-ddraw or the patch in place.
"""

# User requested to install the CnCnet Launcher
if os.environ.get('INSTALL_CNCNET'):
log('User wants to install CnCnet Launcher')
util.protontricks('cncnet_ra2')
# Opt out of CnCNet with 'NO_CNCNET=1 %command%'
no_cncnet = os.getenv('NO_CNCNET', '')
if str.lower(no_cncnet) in ['y', 'yes', 'true', 'on', '1']:
log('Skipping CnCNet on user\'s request.')
use_cnc_ddraw()
return

# CnCnet Launcher is in place, run it
# Install the CnCNet Launcher
if not util.checkinstalled('cncnet_ra2') and not util.protontricks('cncnet_ra2'):
log('Failed to install CnCNet Launcher, let\'s try cnc-ddraw.')
use_cnc_ddraw()

# CnCNet Launcher is in place, run it
if os.path.isfile('CnCNetYRLauncher.exe'):
log('CnCnet Launcher found, bypass game execution!')
log('CnCNet Launcher found, bypass game execution!')
util.replace_command('Ra2.exe', 'CnCNetYRLauncher.exe')
util.replace_command('RA2MD.exe', 'CnCNetYRLauncher.exe')
else:
# Return early, if cnc_ddraw is installed or failed to install
if not util.protontricks('cnc_ddraw'):
log('cnc-ddraw found!')
return

# After installing cnc_ddraw, we need to prevent the game
# from loading the local ddraw.dll, instead of our override.
# Note: This is only done once.
if os.path.isfile('ddraw.dll'):
log('Renaming local ddraw.dll to ddraw.dll.bak')
os.rename('ddraw.dll', 'ddraw.dll.bak')

def use_cnc_ddraw():
""" Install cnc-ddraw, the current replacement from EA isn't working.
"""

log('Using cnc-ddraw.')

# Return early, if cnc-ddraw is installed
if util.checkinstalled('cnc_ddraw'):
log('cnc-ddraw found, nothing to do!')
return

# Install cnc-ddraw
if not util.protontricks('cnc_ddraw'):
log('Failed to install cnc-ddraw')
return

# After installing cnc_ddraw, we need to prevent the game
# from loading the local ddraw.dll, instead of our override.
# Note: This is only done once.
if os.path.isfile('ddraw.dll'):
log('Renaming local ddraw.dll to ddraw.dll.bak')
os.rename('ddraw.dll', 'ddraw.dll.bak')

0 comments on commit d9773f4

Please sign in to comment.