Visit the Ironworks Gaming Website Email the Webmaster Graphics Library Rules and Regulations Help Support Ironworks Forum with a Donation to Keep us Online - We rely totally on Donations from members Donation goal Meter

Ironworks Gaming Radio

Ironworks Gaming Forum

Go Back   Ironworks Gaming Forum > Ironworks Gaming Forums > General Discussion

Reply
 
Thread Tools Search this Thread
Old 01-20-2014, 06:20 AM   #1
Shadow Stranger
Avatar
 

Join Date: December 9, 2007
Posts: 594
Smiley Writing Source Code with a Spreadsheet

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

printf("\n,");
for (i = 912; i < 2152; i++) {
if (i % 16 == 0)
printf("%d,",i);
printf("%d,",buffer[i]);
if (i % 16 == 15)
printf("\n,");
if (i == 2151)
printf("\n,");
}

printf("\n,");
for (i = 2152; i < 4000; i++) {
if (i % 16 == 8)
printf("%d,",i);
printf("%d,",buffer[i]);
if (i % 16 == 7)
printf("\n,");
if (i == 3999)
printf("\n,");
}

(A whole lot of lines have been omitted for brevity's sake.)

printf("\n,");
for (i = 32466; i < 32983; i++) {
if (i % 16 == 2)
printf("%d,",i);
printf("%d,",buffer[i]);
if (i % 16 == 1)
printf("\n,");
if (i == 32982)
printf("\n,");
}

printf("\n,");
for (i = 32983; i < 33100; i++) {
if (i % 16 == 7)
printf("%d,",i);
printf("%d,",buffer[i]);
if (i % 16 == 6)
printf("\n,");
if (i == 33099)
printf("\n,");
}

The for clause is a common element, but the numbers contained in each clause are not.

First, we create a specimen clause of code. If a number is surrounded on both sides by tab stops, when it is pasted into a spreadsheet it will be in a cell by itself. 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.
printf("\n,");@for (i = \t912\t; i < \t2152\t; i++) {@if (i % 16 == \t0\t)@printf("%d,";i);@printf("%d,";buffer[i]);@if (i % 16 == \t15\t)@printf("\n,");@if (i == \t2151\t)@printf("\n,");@}@

The specimen line of code is now copied into a spreadsheet.

Now the the Fill Down function is used:
printf("\n,");@for (i = \t912\t; i < \t2152\t; i++) {@if (i % 16 == \t0\t)@printf("%d,";i);@printf("%d,";buffer[i]);@if (i % 16 == \t15\t)@printf("\n,");@if (i == \t2151\t)@printf("\n,");}@
printf("\n,");@for (i = \t912\t; i < \t2152\t; i++) {@if (i % 16 == \t0\t)@printf("%d,";i);@printf("%d,";buffer[i]);@if (i % 16 == \t15\t)@printf("\n,");@if (i == \t2151\t)@printf("\n,");}@
printf("\n,");@for (i = \t912\t; i < \t2152\t; i++) {@if (i % 16 == \t0\t)@printf("%d,";i);@printf("%d,";buffer[i]);@if (i % 16 == \t15\t)@printf("\n,");@if (i == \t2151\t)@printf("\n,");}@

(A whole lot of lines have been omitted for brevity's sake.)

printf("\n,");@for (i = \t912\t; i < \t2152\t; i++) {@if (i % 16 == \t0\t)@printf("%d,";i);@printf("%d,";buffer[i]);@if (i % 16 == \t15\t)@printf("\n,");@if (i == \t2151\t)@printf("\n,");}@
printf("\n,");@for (i = \t912\t; i < \t2152\t; i++) {@if (i % 16 == \t0\t)@printf("%d,";i);@printf("%d,";buffer[i]);@if (i % 16 == \t15\t)@printf("\n,");@if (i == \t2151\t)@printf("\n,");}@
printf("\n,");@for (i = \t912\t; i < \t2152\t; i++) {@if (i % 16 == \t0\t)@printf("%d,";i);@printf("%d,";buffer[i]);@if (i % 16 == \t15\t)@printf("\n,");@if (i == \t2151\t)@printf("\n,");}@


Now all the variable parts are in columns by themselves, just copy in the relevant numbers and comments:
printf("\n,");@for (i = \t912\t; i < \t2152\t; i++) {@if (i % 16 == \t0\t)@printf("%d,";i);@printf("%d,";buffer[i]);@if (i % 16 == \t15\t)@printf("\n,");@if (i == \t2151\t)@printf("\n,");}@
printf("\n,");@for (i = \t2152\t; i < \t4000\t; i++) {@if (i % 16 == \t8\t)@printf("%d,";i);@printf("%d,";buffer[i]);@if (i % 16 == \t7\t)@printf("\n,");@if (i == \t3999\t)@printf("\n,");}@
printf("\n,");@for (i = \t4000\t; i < \t5976\t; i++) {@if (i % 16 == \t0\t)@printf("%d,";i);@printf("%d,";buffer[i]);@if (i % 16 == \t15\t)@printf("\n,");@if (i == \t5975\t)@printf("\n,");}@

(A whole lot of lines have been omitted for brevity's sake.)

printf("\n,");@for (i = \t31654\t; i < \t32466\t; i++) {@if (i % 16 == \t6\t)@printf("%d,";i);@printf("%d,";buffer[i]);@if (i % 16 == \t5\t)@printf("\n,");@if (i == \t32465\t)@printf("\n,");}@
printf("\n,");@for (i = \t32466\t; i < \t32983\t; i++) {@if (i % 16 == \t2\t)@printf("%d,";i);@printf("%d,";buffer[i]);@if (i % 16 == \t1\t)@printf("\n,");@if (i == \t32982\t)@printf("\n,");}@
printf("\n,");@for (i = \t32983\t; i < \t33100\t; i++) {@if (i % 16 == \t7\t)@printf("%d,";i);@printf("%d,";buffer[i]);@if (i % 16 == \t6\t)@printf("\n,");@if (i == \t33099\t)@printf("\n,");}@

The code is then copied to a 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 method is valid for any brand of source code.
Shadow Stranger is offline   Reply With Quote
Old 01-21-2014, 06:51 PM   #2
Luvian
Ironworks Moderator
 

Join Date: June 27, 2001
Location: Montreal, Quebec, Canada
Age: 43
Posts: 6,763
Default Re: Writing Source Code with a Spreadsheet

Well that is interesting. What made you think of that?
__________________
Once upon a time in Canada...
Luvian is offline   Reply With Quote
Old 01-21-2014, 09:07 PM   #3
Shadow Stranger
Avatar
 

Join Date: December 9, 2007
Posts: 594
Default Re: Writing Source Code with a Spreadsheet

Need to draw up programs to decrypt the data structures of various computer games. Currently it is being used in Wizards and Warriors.
Shadow Stranger is offline   Reply With Quote
Reply

Tags
source code, spreadsheet


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Shadow Warrior source code released... Hivetyrant Miscellaneous Games (RPG or not) 3 04-03-2005 09:19 PM
Windows 98 Source code!!!!! Hivetyrant General Discussion 7 04-02-2005 09:56 PM
The Doom 3 source code has been stolen! Dreamer128 General Conversation Archives (11/2000 - 01/2005) 12 04-05-2004 04:30 PM
Source Code for Dungeon Craft? Mr_Tikio Dungeon Craft - RPG Game Maker 12 12-15-2001 05:38 AM
source code?? Darknight Icewind Dale | Heart of Winter | Icewind Dale II Forum 2 03-25-2001 02:27 PM


All times are GMT -4. The time now is 05:02 AM.


Powered by vBulletin® Version 3.8.3
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
©2024 Ironworks Gaming & ©2024 The Great Escape Studios TM - All Rights Reserved