MS-Edit

From UFOpaedia
Revision as of 22:57, 18 August 2012 by NKF (talk | contribs)
Jump to navigation Jump to search

MS-Edit is an old simple text editor that was introduced as an offshoot of the QBasic IDE (integrated development environment) that was bundled with the tools in MS-Dos 6.0. In fact, MS-Edit was Qbasic but run with a separate switch so that only its plain text editor was available. As of version 2.0.026, MS-Edit was no longer tied to Qbasic and became its own separate program and came with various improvements.

One of the improvements that it gained was the ability to read and write binary files of up to 2 megabytes in size.

The binary files are opened at varying line widths. For files that simply contain series of similar data, setting MS-Edit to open them at the correct line width will allow you open these files to view them as a table.

For files with mixed data, the files can be opened at line width such as 100 and use decimal file offsets (offset by 1) to get to the part of the file you wish to work on.

Though unorthodox, particularly with entering the offsets, it's easy to master and is prepackaged with a lot of the legacy programs that come with many versions from Windows 95 to XP.


To use it

  • /Start /Run then type EDIT. Alternatively, navigate to Start --> Programs --> Accessories --> Command Prompt, then type EDIT. If you frequently use this tool for editing, you can make a shortcut to it and place it on your desktop or start menu for easy access.
    • If you want MS-Edit to display the maximum number of horizontal lines as your hardware is capable of, run it by typing EDIT /H.
  • Point to the game file of interest. This DOS tool uses common established directory conventions such as the two periods (..) at the top of the Directory list. This moves you up one directory level. Use Help (F1) for more info.
  • Once you've highlighted the file of interest, checkmark "Open Binary"
  • If you know the record length for your file of interest, enter it in "Line Width". For example, SOLDIER.DAT has record lengths of 68. This causes file entries to "line up" and makes patterns obvious like a spreadsheet.
  • If you're new to hacking, set the "Open Read-Only" field so that you cannot accidentally save over the file by mistake.


Editing

  • The "Col" and "Value" info along the bottom bar show you the current byte column you're in, and its value.
  • Many folks talk about byte positions using offsets (starts at 0, and is indicated by [square brackets]) whereas EDIT does not (starts with column 1). If the values don't seem to be jiving, try looking one column to the right (or left!).
  • WARNING: When you first start to edit, hit the Insert key once to get the big block cursor. This puts you in Overwrite mode instead of Insert mode (the small underline cursor). Be VERY CAREFUL about hitting the Insert key again. Insert mode is a Very Bad Thing(tm) for binary files. Inserting a byte moves every subsequent byte over by one, thus nuking position-based files (i.e., most XCOM files).
DOS Characters in MS-Edit
  • Likewise, be VERY CAREFUL about hitting keys like Delete, Backspace, or Enter. All these (and more!) mess with positionality. If you ever see that records aren't lining up, Close without saving!
  • Make a copy of the file if you're unsure of what you're doing. EDIT prompts you about making a .BAK backup file when you save edits, which is a nice convenience.

Entering Data

  • To enter numeric values into a byte:
    • Hold down an Alt key (either one)
    • Using the NUMERIC KEYPAD (the numbers on right side of keyboard, not the ones along the top of keyboard), type in the number you want to enter. It doesn't matter if Numlock is on or off.
    • Let go of the Alt key. In the case where your computer doesn't have a numeric keypad such as a laptop, you must press the function (Fn) key along with ALT in order to enter these values.
    • The number will now be entered.
      • One small fault in MS-Edit is that it cannot enter values less than 28 this way. To enter them, you have to go through special MS-Edit only key sequences. First, hit Control-P (^P). Then:
        • For 0, hit ^2 (don't ask why)
        • For 1-26, hit ^A to ^Z. For example, ^A is 1, ^M is 13, ^Z is 26.
        • For 27, hit ^[
  • A handy lookup table for numbers versus characters can be found as a .GIF (see right) or the same thing in a .PDF here
  • If you see that your number makes a "regular" character (e.g. 65=A), you can also simply type in that character. However, the space character (number 32) looks just like a null character (number 0); don't use a space to mean zero!


Misc Notes

Some save files store 'rubbish' in a field that's not being used. For example, not all soldier and alien names are 25 characters long (26 including the null byte, value 00, that shows where it ends). You'll usually find rubbish stored in the columns past the name end. It can be the remains of old (longer) names, or more worryingly anything that was in that particular position of RAM when the file was last in memory. Garbage characters may show up in fields that's not being used. Don't worry about them. If there's no reason for the game to use them, they're meaningless.

If you have a file open in EDIT, it is not locked by the system. You can keep the file open indefinitely even when the game is running and nothing strange will happen. Just make sure to save your changes so that they show up. In the case if the executable, it is always best to save and restart.


Fixing the Difficulty Bug with MS-Edit

In addition to general editing of game files for fun and in-game profit, MS-Edit can be used for the important task of fixing the difficulty bug that plague the dos version of X-Com Enemy Unknown/UFO Defense.

Normally this is fixed with XComUtil, fixing the difficulty bug yourself will allow you to keep the game as unaltered as possible.

Follow these easy steps to use MS-Edit to fix the bug:

Step 0


As with any editing operation, as a safety precaution, make a backup copy of the ufoexe\geoscape.exe file in your game folder before you start.


Step 1


Open Geoscape.exe in binary mode with a column setting of 100.

To do this, you can do it from the Dos console. Change into your UFO Defense/Enemy Unknown folder and type the following:

edit /100 ufoexe\geoscape.exe

Alternately, open MS-Edit, go to File then Open... and look for geoscape.exe in the game's ufoexe\ directory. Select it, then check Open Binary and set the Line Width to 100. Finally hit OK.


Step 2


The next step is to locate the affected byte and alter it. Refer to the bottom right corner of the screen for the Row, Column and Value information.

Ms edit Screen.png


Use the Page Up, Page Down and cursor keys to change the cursor so that the row and column values match the following. Pick the one appropriate to your version of the game.


Game Version Row Column
DOS Version 1.0 973 29
DOS Version 1.2 1011 69
DOS Version 1.3 1011 69
DOS Version 1.4 957 77

Note that many CD-ROM versions of the the game are v1.4 by default. The dos portion of the Steam release is 1.4.

Once you are at the specified row and column, your cursor will be resting on a < symbol and the value field should read 60. If not, you might have a different version - try referring to the other row/col values until you find this symbol.

If it's showing an @ symbol and a value of 64 - then your bug is fixed and you don't need to do anything further.


Step 3


Press Insert to switch your cursor to the block cursor.

Now the moment of truth: you need to replace the value of 60 with 64. To do this, type an @ symbol to replace the <.

Alternately, hold down alt and type 064 on the numeric keypad.

Important: If you weren't using the block cursor, make absolutely sure you use delete or backspace to remove the < symbol after entering the @. Not doing this will increase the size of the executable by 1 byte and really mess it up.


Step 4


File > Save and finish up with File > Exit

And you're done. Launch the game and enjoy it on the proper difficulty levels.

See Also