Under certain circumstances, writing part of a program can be automated to a degree. The piece of code must follow a pattern, have a fair amount of repetition inside itself. For example, a Switch function with a large number of terms. Here we see elements that are common from one for clause to another and we also see elements that are not:

The for function is a common element, ditto i % 16, but the absolute numbers contained in each clause are not, they are variable from one clause to another.

Step 1: First, we create a specimen line of code.If a variable number is surrounded on both sides by tab stops, when it is pasted into a spreadsheet it will be in a cell by itself. Hence all numbers of its class, that occur in the same place in the clause, will occur in the same column. Numbers that vary must be created by a formula or must come from a known list of values. If numbers that vary are created by a formula, the Fill Down function can copy that formula into all the relevant cells. If numbers that vary come from a known list of values, this can be pasted right into the column concerned.That is why all numbers of the same class must occur in the same column.

Tab stops are placed before and after every variable number. Below, "\t" represents an otherwise invisible tab stop. All paragraph marks are replaced by at symbols, "@". This means the clause now occupies only one line of code, thus we have our specimen line of code:

and a record from a data table:(4) 2152.Note: deleting of line returns/paragraph marks can be done by a hex editor if the clause is large. The specimen line of code is copied to a text file, which is saved. File is then opened in a hex editor. Use Replace All to replace all of the paragraph mark and tab pairs with an at sign, @.In Windows hex terms 0D0A09h needs to be replaced by 40h.

Step 2: The specimen line of code is now copied into a spreadsheet.This is shown in the graphic below:

Step 3: Now the the Fill Down function is used.We have the required number of lines of code, all lines are identical. Now all the variable parts are in columns by themselves.

Step 4: Use Fill Down to add in those variable numbers that are created by a formula. If using a formula, once it is discovered, it will have to be written in to the top cell in the column then applied to other cells by Fill Down:This involves parts (2), (6), (8) and (10).

Step 5: If using lists of values, copy them into the relevant columns.Here this only involves part (4).

Step 6: Final Processing.The code is then copied to a text file, which is saved. File is then opened in a hex editor.All tab stops are deleted, in Windows they are all equal to 09h. Use Replace All to replace all of them with nothing, this has the effect of deleting all of them.Now at symbols, @, need to be replaced by a paragraph mark and a tab. In Windows hex terms 40h needs to be replaced by 0D0A09h. This assumes that the paragraph mark equals 0D0Ah.

Notes:This method is valid for any brand of source code.It is only useful if you have large numbers of clauses or you might be altering the number of Bytes covered by each clause.

for (i = 912; i < 2152; i++) {if (i @ 16 == 0)printf("/n@d,",i);printf("@d,",buffer[i]);if (i == 2151)printf("/n/n,");}Then the code is copied into a text editor and I(1) Use Replace All to change @ to %(2) Use Replace All to change /n to \n

This generates the correct code when the program is run. Source code is shown below:

This approach can be adapted to a program that reads from multiple files at once.Worked example, I was trying to decrypt the save games for Dark Sun 1: Shattered Lands, with the intent of creating a Universal Game Editor module. I found this tough going as the format was different to anything I had seen before.My best guess is to track the ability scores of PC#1, a Half Giant Ranger.24,15,22,14,17,15

Attached file, main.cpp, is the source file for a program ("ProjectDS2.exe") that checks for this sequence.