ACS Read/Write to file -- Idiot-proof edition!

Moderator: GZDoom Developers

User avatar
Xaser
 
 
Posts: 10774
Joined: Sun Jul 20, 2003 12:15 pm
Contact:

ACS Read/Write to file -- Idiot-proof edition!

Post by Xaser »

Okay, this has been requested before, and was quickly dismissed, due to the fact that it could be used too easily in a malicious sort of way (overwriting files and such). However, I never gave up on the idea, since I saw many, many possibilities with this system (Highscore tables, anyone?) I thought for a bit, and I realized that with a few limitations, this system could be rendered completely idiot-proof.


Anyway, you all have probably heard of this feature request before... the ability to use ACS to read from and write to files. This could enable things such as saving information for, say, a High-scores table, for permanent storage. But that's not all... the possibilities are nearly endless! You could have something like Chrono Trigger's "New Game+" option (start a new game, but keep all the character stats from the old one). You could have a class system in a game, where the character can design their own player classes, from stats to weapons, to everything... and all of this can be saved and be retrieved between games. Just think... with something this powerful, ZDoom will become unstoppable!

However, the most controversial part of this is the fact that it can be easily abused. The most problematic situation is if someone creates a malicious script that overwrites your essential system files with bogus ones, effectively destroying Windows. Or it can be used to create insane amounts of huge (100mb or something) files, eating your disk space like candy. So how do we put a stop to this? Read on to find out!


Limitations:

To avoid the aforementioned problems, we need to set a few basic limitations... nothing regarding functionality, but just how the files are written.

The two most obvious problems (which I mentioned above) are as follows:

1) A script overwrites important system files, thus destroying windows completely.
2) A script fills the user's hard drive with several insanely large files, eating up disk-space.

The solutions?

1) First of all, we need to limit the places where the files can be saved... in fact, we probably won't need more than one "write file" per wad, do we? So therefore, if we were to limit the available file we can write to, that would solve the first problem.

The easiest way would simply be to make the "write-file" have the same name as the wad. For example, if a map in 'tehcool.wad' wants to use this feature, it would write it to a file called 'tehcool.acx' (though hopefully with a better extension, heh). Since there's no chance of overwriting anything with a fixed filename, we don't have to worry about people trying to destroy other people's computers. :P


2) To stop people from adding ridiculous amounts of bogus information just for the sake of wasting filesize, why not just set a size limit for the 'write-file' itself? I'm sure that nobody will ever create a script that uses over 1 megabyte of pure code, so that would probably be a good place to start. Still, this could be increased in later ZDoom versions if someone somehow creates a wad that breaks this limit (in a sensible way).


Implementation:

So... one big question is this: How exactly would the system work? Well, there are certainly several methods. For now, I'll outline one that's relatively simple, but pretty good, really. If Randy or Graf comes up with a better method though, feel free to use that, since I'm not exactly a programmer, so I have no clue how hard any of this is to implement. :P


The entire purpose of these files is to save variables and such for later use (from what I can think of at the moment, that is). However... how should we do this? First of all, we'll obviously need specials to use within ACS. I'll use ACS_FileRead and ACS_FileWrite for this example.

Their purposes are quite obvious, really. ACS_FileWrite writes, and ACS_FileRead... well, you get the picture. :P

However, if we were to just scatter all the individual variables in the "write-file", it would look quite messy, wouldn't it? You wouldn't want something like this:

Code: Select all

map = 3;
playerclass = "Fighter";
randomvariable5 = 838841;
So therefore, I propose that we sort the variables in different categories, or labels. For example, if you want to store information about Map02 in a wad (for an information display screen, for example), you could group them like this:

Code: Select all

label Map01
{
	name = "Tech Base";
	levelnum = 1;
	difficulty = 2;
	description = "Take control of an enemy infested Techbase before it's too late!";
}
(My syntax probably sucks, but like I said... I'm no programmer. :P)

As for the ACS commands themselves, here's an example of how they might be set up:

ACS_FileWrite(label,variable,value);
ACS_FileRead(label,readvariable,writevariable);

For FileRead, the 'readvariable' is what the chosen variable name in the "write-file" is, and 'writevariable' is what it's saved as in the script. In case you have a variable in the write-file named "tehone", but you want it saved in your script as "tehtwo", you can do that without any hassle.

To sum this up, if you want to store some information, your ACS code might look like this:

Code: Select all

ACS_FileWrite("Map02",name,s:"The Gateway");
ACS_FileWrite("Map02",levelnum,i:2);
The resulting code in the "write-file" would then look like this:

Code: Select all

label Map02
{
	name = "The Gateway";
	levelnum = 2;
}
Later, you might want to retrieve that information, so you would use this in your ACS script:

Code: Select all

ACS_FileRead("Map02",name,map02name);
ACS_FileRead("Map02",levelnum,map02num);
So then in your ACS script, you would have a value of 2 in the variable called map02num, and "The Gateway" in the variable named map02name.



This is mainly aimed towards Graf, for GZdoom or something... I think this feature would kick major ass, and with its major bugs ironed out... why not? :P

If you're unclear about parts of this (which you probably are), I'll explain them out later. I'm tired as hell right now, and I really need to get some sleep. Peace out! :P
User avatar
Doomguy0505
Posts: 625
Joined: Tue Mar 29, 2005 4:53 am
Contact:

Post by Doomguy0505 »

Great idea (no sarcasm). A way of skipping the memory hogging hubs to store info.
User avatar
wildweasel
Posts: 21706
Joined: Tue Jul 15, 2003 7:33 pm
Preferred Pronouns: He/Him
Operating System Version (Optional): A lot of them
Graphics Processor: Not Listed
Contact:

Post by wildweasel »

Sounds like a winning idea.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49234
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Post by Graf Zahl »

This whole idea fails for a very profound reason: ACS's strings are static constants and non-modifiable so half of it is doomed already.
User avatar
Doomguy0505
Posts: 625
Joined: Tue Mar 29, 2005 4:53 am
Contact:

Post by Doomguy0505 »

Code: Select all

#include "zcommon.acs"
script 1 OPEN
{
str turd;
turd = "lol";
print(s:turd);
delay(35*2);
turd = "O_o";
print(s:turd);
}
and

Code: Select all

#include "zcommon.acs"
script 1 OPEN
{
int turd; // WHY DO WE HAVE STR AND NOT JUST USE INT?
turd = "lol";
print(s:turd);
delay(35*2);
turd = "O_o";
print(s:turd);
}
EXPLAIN!!!
User avatar
TheDarkArchon
Posts: 7656
Joined: Sat Aug 07, 2004 5:14 am
Location: Some cold place

Post by TheDarkArchon »

:laff:

Int == Integer, Str == String. Making a string an integer won't work, since they have to handled differently (I.E You can't do maths with a string now, can you?)
User avatar
Doomguy0505
Posts: 625
Joined: Tue Mar 29, 2005 4:53 am
Contact:

Post by Doomguy0505 »

what makes them static constants?
if int's can hold strings why bother with goddamn str's?

in C++

Code: Select all

char turd[4];
turd = "hobo";
Would get me an error

in ACS

Code: Select all

str turd;
turd = "hobo";
Would not give me an error
User avatar
TheDarkArchon
Posts: 7656
Joined: Sat Aug 07, 2004 5:14 am
Location: Some cold place

Post by TheDarkArchon »

That isn't an integer, though. You're setting a string up and then making that string mean "hobo". You can set things using "=" but not do real maths with it, which WOULD cause an error.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49234
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Post by Graf Zahl »

Strings in ACS are just integers holding an index into a static string table. You can't change the string.

And if you add 2 strings you add their indices so you won't get the concatenation but just another string from the string table. After all it's just an integer.
User avatar
David Ferstat
Posts: 1113
Joined: Wed Jul 16, 2003 8:53 am
Location: Perth, Western Australia
Contact:

Re: ACS Read/Write to file -- Idiot-proof edition!

Post by David Ferstat »

Xaser wrote:... I realized that with a few limitations, this system could be rendered completely idiot-proof...
Pardon my cynicism, but do you realise what happens when you try to make something idiot-proof?
Somebody simply builds a better idiot. :(
Jonathan
Posts: 44
Joined: Fri Dec 05, 2003 5:35 am

Post by Jonathan »

Graf Zahl wrote:This whole idea fails for a very profound reason: ACS's strings are static constants and non-modifiable so half of it is doomed already.
Forgive me, but hasn't there already been a submission of an ACS patch to introduce c-style char array strings?
User avatar
Hirogen2
Posts: 2033
Joined: Sat Jul 19, 2003 6:15 am
Operating System Version (Optional): Tumbleweed x64
Graphics Processor: Intel with Vulkan/Metal Support
Location: Central Germany
Contact:

Post by Hirogen2 »

User avatar
jallamann
Posts: 2271
Joined: Mon May 24, 2004 8:25 am
Location: Ålesund, Norway
Contact:

Post by jallamann »

...........how?
User avatar
DoomRater
Posts: 8270
Joined: Wed Jul 28, 2004 8:21 am
Preferred Pronouns: He/Him
Location: WATR HQ
Contact:

Post by DoomRater »

Graf Zahl wrote:Strings in ACS are just integers holding an index into a static string table. You can't change the string.

And if you add 2 strings you add their indices so you won't get the concatenation but just another string from the string table. After all it's just an integer.
Why isn't it an offset pointing to the exact location of the string? I've wondered why that is for some time.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49234
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Post by Graf Zahl »

Because that's the way it was defined - and because it's the only safe way it can be handled with a type-less language. Hexen didn't need more so it wasn't implemented.
Post Reply

Return to “Closed Feature Suggestions [GZDoom]”