Creating A Batch File: Difference between revisions

From DF21 Wiki
(Created page with " === Batch File Details === We've talked [https://df-21.net/wiki/?title=Converting_Classic_Maps#4._Simple_Batch_File_Creation earlier] about creating a batch file to start the mission. Now let's look at the details of what the batch file must contain. We need a uniform way to start all the missions. To do that we will create a batch file named '''anchor.bat''' ( or generally '''<missionname>.bat''' ) that will start our mission automatically. We start with this simple...")
 
No edit summary
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
Here we will discuss batch file creation for Dark Forces missions. These are '''only''' required when making a mission that is supported by DOS or the Dark Forces Remaster versions. They are not needed to support '''The Force Engine.'''  You can skip this tutorial if that is the case.
For this batch file example we will be using the mission '''Anchor Hed''' found [https://df-21.net/downloads/missions.php?viewid=48824574 here]


=== Batch File Details ===
=== Batch File Details ===
We've talked [https://df-21.net/wiki/?title=Converting_Classic_Maps#4._Simple_Batch_File_Creation earlier]  about creating a batch file to start the mission. Now let's look at the details of what the batch file must contain. We need a uniform way to start all the missions. To do that we will create a batch file named '''anchor.bat''' ( or generally '''<missionname>.bat''' ) that will start our mission automatically.
Let's look at the details of what the batch file must contain. We need a uniform way to start all the missions. To do that we will create a batch file named '''anchor.bat''' ( or generally '''<missionname>.bat''' ) that will start our mission automatically.


We start with this simple code in our batch file and go from there.
We start with this simple code in our batch file and go from there.
Line 62: Line 67:
  exit
  exit
This is what it looks like for the mission '''anchor.gob.''' When you run '''anchor.bat'''  we will be able to run the missions in the remaster, tfe or dos.
This is what it looks like for the mission '''anchor.gob.''' When you run '''anchor.bat'''  we will be able to run the missions in the remaster, tfe or dos.
[[?title=File:Anchormap.png|center|thumb|728x728px]]
[[File:Anchormap.png|center|thumb|663x663px]]
'''Important:''' When you save your '''anchor.bat''' make sure you '''TEST IT !!''' It is easy to make a typo and we don't want players fail attempting to play the mission. Be absolutely sure your batch file works without problems! Don't skip this step.
'''Important:''' When you save your '''anchor.bat''' make sure you '''TEST IT !!''' It is easy to make a typo and we don't want players fail attempting to play the mission. Be absolutely sure your batch file works without problems! Don't skip this step.

Latest revision as of 12:13, 7 August 2024

Here we will discuss batch file creation for Dark Forces missions. These are only required when making a mission that is supported by DOS or the Dark Forces Remaster versions. They are not needed to support The Force Engine. You can skip this tutorial if that is the case.


For this batch file example we will be using the mission Anchor Hed found here

Batch File Details

Let's look at the details of what the batch file must contain. We need a uniform way to start all the missions. To do that we will create a batch file named anchor.bat ( or generally <missionname>.bat ) that will start our mission automatically.

We start with this simple code in our batch file and go from there.

dark -u<MISSIONNAME>.GOB

Great - now we need to ensure that the batch file supports multiple Dark Forces executables!

1. Dark Forces Executable Support

There are multiple versions of Dark Forces out there. Some own Dark Forces through DOS, some have it through Night Dive's Remaster. Because of this variety, it is important to support all types of executables. The application name we always expect to have is dark.exe . It is the default name in DOS but is different in Night Dive's release. For Steam the executable is named khonsu_Shipping_Steam_x64.exe and for GOG it is called khonsu_Shipping_Galaxy_x64.exe. We must ensure we have a copy of dark.exe in the folder where the mission GOB is located, so the batch script would be needed to make a copy of the executable if it is missing.

Here is how we do it in the batch file.

set dark_executable=dark.exe
set steam=khonsu_shipping_steam_x64.exe
set gog=khonsu_shipping_galaxy_x64.exe
if not exist "%dark_executable%" (
    if exist "%steam%" (
        copy "%steam%" "%dark_executable%"
    ) 
    else (
        if exist "%gog%" (
            copy "%gog%" "%dark_executable%"
        ) else (
            echo "Cannot find Dark Forces executable!"
            exit
        )
    )
)

Without going into details, this script ensures you have dark.exe in your game directory. Simply add this to your batch file.

2. Handling DFBRIEF.LFD

We need the DFBIEF.LFD file to override the default mission briefings in the game. However, if we do not clean it up after playing a custom mission the briefing will always override the original game briefings and also for any other mod you choose to play. This is why it is important to clean up this briefing file, or simply, rename the briefing file when you start and end the mission.

Here is the template to rename the briefing file inside the batch script. Just replace <gobname> with the name of the mission in the script below.

if exist <gobname>.tmp ren <gobname>.tmp dfbrief.lfd
DARK -u<gobname>
ren dfbrief.lfd <gobname>.tmp 
exit

Note, we also add an exit call at the end so the script always exits and we don't get a hanging window after finishing a mission.

3. Combined Batch Script Example

Combining all the parts here is what the batch script anchor.bat should look like. Don't forget to replace <gobname> with your own level (Ex: anchor)

set dark_executable=dark.exe
set steam=khonsu_shipping_steam_x64.exe
set gog=khonsu_shipping_galaxy_x64.exe
if not exist "%dark_executable%" (
    if exist "%steam%" (
        copy "%steam%" "%dark_executable%"
    ) 
    else (
        if exist "%gog%" (
            copy "%gog%" "%dark_executable%"
        ) else (
            echo "Cannot find Dark Forces executable!"
            exit
        )
    )
)
if exist <gobname>.tmp ren <gobname>.tmp dfbrief.lfd
DARK -u<gobname>.gob
ren dfbrief.lfd <gobname>.tmp 
exit

This is what it looks like for the mission anchor.gob. When you run anchor.bat we will be able to run the missions in the remaster, tfe or dos.

Important: When you save your anchor.bat make sure you TEST IT !! It is easy to make a typo and we don't want players fail attempting to play the mission. Be absolutely sure your batch file works without problems! Don't skip this step.