LavaLit
Home
Forum
WIKI
SVN
DOWNLOADS
Help
Donations
Login
Register
Donations
Quarterly Goal:
$90.00
Due Date:
Sep 30
Total Receipts:
$30.00
Below Goal:
$60.00
Site Currency:
USD
33%
Quarterly Donations
Aug-5
DrStrange
USD20.00
Jul-18
mozenwrath...
EUR10.00
Jul-1
LeeBrother
USD10.00
Advertisement
Links
Advertisement
LavaLit
>
Forum
>
OpenBoR
>
Engine Center
>
Requests
>
File Stream Writing - Suggestions
Pages: [
1
]
Go Down
« previous
next »
Print
Author
Topic: File Stream Writing - Suggestions (Read 634 times)
0 Members and 1 Guest are viewing this topic.
kbandressen
Developer
Offline
Posts: 1347
File Stream Writing - Suggestions
«
on:
May 04, 2010, 01:15:10 AM »
Damon suggested I work on a way to do file output so mods can store save data and have more flexible persistence so I think I'll start on that (once I've got Visual Studio all set up again). So while I do that and before I start coding it, I want to know what suggestions people have.
One thing I would want is a way to encrypt data so players can't just open their save file up in notepad and edit it so they unlock everything. At first, though, I 'll probably just try to get a basic system (pretty much the complement to the file input system we have now) working.
Any suggestions/ideas would be welcomed!
Logged
Damon Caskey
Administrator
Offline
Posts: 4343
Re: File Stream Writing - Suggestions
«
Reply #1 on:
May 04, 2010, 06:48:52 AM »
My thinking was to add in "set" versions of the
getfilestreamline()
and
getfilestreamargument()
functions that simply overwrite that portion of the file stream data.
Then perhaps a third command for appending additional lines to the file stream, or automatically appending a line if the line argument of proposed
setfilestreamline()
is out of scope (in which case, it should probably return some value so we can verify).
Lastly a save command with path parameter that creates a new file or overwrites if {path} already exists and dumps the relevant file stream to it. You obviously don't want to be writing directly to the text file any more then you want to be reading from it.
I think those additions would be more then sufficient. Let the modder worry about manipulation and verifying what goes in and out. If you add encryption, maybe include a byte parameter in the save command to save with or without it. SX and I had talked about that very thing before (text hacking to get the goodies) and encryption is a great idea, but there are times when a modder might want to intentionally leave it open (among other things, debugging comes to mind).
DC
*Edit:*
Something else very important, albeit not directly related to file streams. We need a flag to disable OpenBOR's built in game save feature, and make sure the player has no way to re enable it without hacking the mod. Otherwise it will be a major nuisance to work around and completely destroy any kind of RPG style consistency a modder might be going for.
«
Last Edit: May 04, 2010, 01:28:40 PM by Damon Caskey
»
Logged
OpenBOR Wiki
.
Coming Soon:
Fatal Fury Chronicals
Bloodbane
Hero Member
Offline
Posts: 4890
Dark Dragon
Re: File Stream Writing - Suggestions
«
Reply #2 on:
May 04, 2010, 09:27:27 AM »
Quote
but there are times when a modder might want to intentionally leave it open (among other things, debugging comes to mind).
Agreed. While still WIP, let's leave it uncrypted so modders could be sure that the texts are written properly.
Logged
OpenBoR Manual
"The more often enemies attack, the more open they are to counter attacks"
Damon Caskey
Administrator
Offline
Posts: 4343
Re: File Stream Writing - Suggestions
«
Reply #3 on:
May 04, 2010, 01:23:39 PM »
I forgot something very important. See my post above.
DC
Logged
OpenBOR Wiki
.
Coming Soon:
Fatal Fury Chronicals
kbandressen
Developer
Offline
Posts: 1347
Re: File Stream Writing - Suggestions
«
Reply #4 on:
May 04, 2010, 01:41:05 PM »
Yeah, encryption would definitely be an optional thing. Aside from debugging, there's all sorts of uses for making text files like writing a report with the player's statistics once the game's done so they can see how they did.
And I definitely agree on being able to disable the default engine save code. It'd be a
much
nicer solution than having to rig up some kind of levelscript to bypass the engine's load function and start the player in the right place.
Logged
SX
Administrator
Offline
Posts: 2473
Re: File Stream Writing - Suggestions
«
Reply #5 on:
May 04, 2010, 02:04:11 PM »
Unless I'm mistaken and way off.....
I would think we should probably focus on redesigning the save system. Instead of saving at the beginning of each level we need to save a snapshot of the engine instead. Kind of how the movie system works at the moment.
Basically scan through all enities and their properties and dump it. This would also guaranty any script overrides as well to the enties, levels and so on.
We won't be storing the data, just the references to the data.
«
Last Edit: May 04, 2010, 02:06:56 PM by SX
»
Logged
OpenBOR Donation Box
Damon Caskey
Administrator
Offline
Posts: 4343
Re: File Stream Writing - Suggestions
«
Reply #6 on:
May 04, 2010, 03:04:57 PM »
SX and basteaud,
Yeah, both of these are pretty far off.
@SX:
Our current save system is fine for what it does. What we want to do though is have fully controllable persistent variables, and that's a different thing entirely. We aren't trying to reinvent the wheel for saving games.
Currently global vars are saved automatically along with saved games, but this just makes a mess more then anything else. It's almost too tedious to bother with for scripting of RPG features, and its very presence means you have to write in extra checks just to make sure a past game doesn't break your scripts.
What writing to text will do is allow seamless and elegant addition of thing like level ups, stat increases, unlockables, and so on without needing the save feature at all. You could make some awesome action RPGs (or even a plain ole RPG if that's your thing). It's essentially giving OpenBOR its own little database system, and how cool will that be?
The only modification the current save feature needs for this to happen is an "off" switch to keep it from getting in the way.
@basteaud:
Sorry friend, but your post pretty much has nothing to do with anything here, and I'm removing it to keep this thread on topic. You are welcome to post it as a request elsewhere.
DC
«
Last Edit: May 04, 2010, 03:10:48 PM by Damon Caskey
»
Logged
OpenBOR Wiki
.
Coming Soon:
Fatal Fury Chronicals
kbandressen
Developer
Offline
Posts: 1347
Re: File Stream Writing - Suggestions
«
Reply #7 on:
May 04, 2010, 05:22:33 PM »
OK, I've got Visual Studio all happy once again so I'll give this a try pretty shortly. It shouldn't be too hard as I've got the logfile code to look at as an example of how to do stuff like this cross-platform. Though from what I'm seeing it doesn't look like there's any way to do this Dreamcast, correct?
Logged
SX
Administrator
Offline
Posts: 2473
Re: File Stream Writing - Suggestions
«
Reply #8 on:
May 04, 2010, 07:03:32 PM »
@KB,
You should be able to now.... if someone spends the time at looking at VMU support since its supported in KOS.
Logged
OpenBOR Donation Box
Plombo
Developer
Offline
Posts: 953
Your source for useful modding tools!
Re: File Stream Writing - Suggestions
«
Reply #9 on:
May 04, 2010, 10:37:25 PM »
I don't have any ideas or suggestions at the moment, but I can say that this feature will be very, very useful.
Logged
LavaLit member #588
Check out my improved version of borpak!
Also check out bor2wav and borplay!
kbandressen
Developer
Offline
Posts: 1347
Re: File Stream Writing - Suggestions
«
Reply #10 on:
May 05, 2010, 01:50:46 AM »
Had some time to think about this at work today and here's some things I realized.
One pleasant coincidence I realized regarding encryption: with even just a simple encryption scheme where one modder-specified key encodes and decodes the data, it will be as secure as the SecurePak code if the mod is released in that format. Since everything in the mod is encrypted by that system, the key will be encrypted as well.
And for encryption in regular mods, I think just encrypting things with a modder-specified key would be enough as well. Players wanting to hack save data would have to open up the mod, find where in the mod's scripts the key is specified, then use some kind of program to decrypt the save data. A lot of work, and that's not all.
Crafty modders could easily set up a verification system in their save data that would make it a complete pain to hack. Like when writing data, add up all the numbers that are stored and store their sum (or a permutation of it if you're feeling really evil) as some unobtrusive value as well. Then sometime after loading, check to see if everything still matches up and if it doesn't, randomly do evil things like kill the player, give enemies ridiculous amounts of health, or spawn Rickroll cutscene entities.
Also, one little addition that'll have to be made for this to be useful is to make the file stream input code able to access files outside the pak as that's where anything that gets written by the new functions will have to be. So I'll probably just add a flag to the existing stuff that defaults to using the path specified inside the pak with the option to use it for stuff in the saves directory too.
And it's good to know that Dreamcast will potentially be able to use this as well, though I have no clue about how KOS works. Hopefully, once I get the functions done it'll be an easy matter for either someone to port them or for me to figure out the VMU code.
Logged
kbandressen
Developer
Offline
Posts: 1347
Re: File Stream Writing - Suggestions
«
Reply #11 on:
May 05, 2010, 03:53:43 PM »
Okay, I've done some experimentation/work on this and here's how things are looking to turn out. So far it's looking pretty good. I've opened up a filestream with a file from within the pak, appended stuff to it, and then used savefilestream to save it in the saves directory with no corruption.
createfilestream()
- makes a new blank filestream that can be added to, returns filestream index
openfilestream("filepath", int x)
- loads the file at filepath into a new filestream, returns filestream index
- x = 0 (default): loads file from inside the pak (or base directory if running the mod as a data folder)
- x = 1: loads file from Saves directory
savefilestream(int filestreamindex, "filepath")
- saves the specified filestream at Saves\PAKNAME\filepath
I'm thinking that the best way to do file writing would be to have each mod only be able write files in a unique subdirectory of Saves (based on its pak's name). This way, no mod can overwrite other mods' save data. I can just imagine some wit making a virus-like mod that systematically goes through replacing each save file with garbage.
File reading is a different matter though. Mods should be able to access any other mod's save data for reading, allowing for connectivity from a mod to its sequel like retaining a character customization or remembering choices made.
And I'm currently working on this function:
filestreamappend(int filestreamindex, scriptvar, 0/1/2)
- adds scriptvar to the end of the specified filestream
- 0 (default): for writing commands, creates a new line before writing
- 1: for writing arguments, adds a space before writing
There's definitely more that can be added after these functions, but once these are done, everything that's needed to store custom save data will be present. We can work on making it fancy after that.
Logged
kbandressen
Developer
Offline
Posts: 1347
Re: File Stream Writing - Suggestions
«
Reply #12 on:
May 11, 2010, 03:01:11 PM »
OK, I've got an initial release all done now. Go play around with it and see what you think!
http://lavalit.com/index.php/topic,4252.msg64733.html#msg64733
Logged
basteaud
Newbie
Offline
Posts: 21
Re: File Stream Writing - Suggestions
«
Reply #13 on:
May 22, 2010, 05:59:22 PM »
I m trying to create a savegame function.
When i use filestreamappend, here is what i get :
Filename for filestreamappend must be a string.
Script function 'filestreamappend' returned an exception, check the manual for details.
You said we have to use the index of the file, not the name. Is that an error from me or from the function ?
Here is my temporary function :
//-----------------------------------------------------------------------------------
//Save a game
//-----------------------------------------------------------------------------------
void savegame(int gamei){
void newsavegamefile=createfilestream();
void oldsavegamefile=getglobalvar("savegamefile");
void type;
void variable;
void variablevaluenewgamei;
void variablevalueoldi;
int i;
setfilestreamposition(newsavegamefile, 0);
setfilestreamposition(oldsavegamefile, 0);
do{
variable = getfilestreamargument(oldsavegamefile, 0, "string");
type = getfilestreamargument(oldsavegamefile, 1, "string");
variablevaluenewgamei=getglobalvar(variable);
filestreamappend(newsavegamefile, variable, 0);
filestreamappend(newsavegamefile, type, 1);
for (i=1,i<=7,i++){
variablevalueoldi=getfilestreamargument(oldsavegamefile, i, type);
if (i==gamei){
filestreamappend(newsavegamefile, variablevaluenewgamei, 1);
}else{
filestreamappend(newsavegamefile, variablevalueoldi, 1);
}
}
filestreamnextline(oldsavegamefile);
}while (variable != "End");
savefilestream(newsavegamefile, "data/savegames/savegames.txt");
free(oldsavegamefile);
setglobalvar("savegamefile",newsavegamefile);
}
Savegamefile is organized like a table, with globalvars i want to save/load as lines, and savegame number as columns (7 savegame slots).
globalvar int defaultvalue savegame1 savegame2 savegame3 savegame4 savegame5 savegame6
level1 int 1 1 2 3 4 5 6
level2 int 1 1 2 3 4 5 6
level3 int 1 1 2 3 4 5 6
level4 int 1 1 2 3 4 5 6
skill101 int 0 0 0 0 0 0 0
skill102 int 0 0 0 0 0 0 0
End 1
Savegame function opens existing savegamefile, reads each line completely, and copies each argument to the newsavegamefile (each argument, except for one column, that will be replaced by current globalvar values.)
My load game function is pretty similar :
//-----------------------------------------------------------------------------------
//load a game
//-----------------------------------------------------------------------------------
void loadgame(int gamei){
int i;
void savegamefile = getglobalvar("savegamefile");
void type;
void variable;
void variablevalue;
setfilestreamposition(savegamefile, 0);
do{
filestreamnextline(savegamefile);
variable = getfilestreamargument(savegamefile, 0, "string");
type = getfilestreamargument(savegamefile, 1, "string");
variablevalue = getfilestreamargument(savegamefile, gamei+1, type);
if(variablevalue!="empty"){
setglobalvar(variable,variablevalue);
}
}while (variable != "End");
}
Can you help me correcting savegame function?
EDIT : i found a solution :
Here is the new code :
//-----------------------------------------------------------------------------------
//load a game
//-----------------------------------------------------------------------------------
void loadgame(int gamei){
int i;
void savegamefile = getglobalvar("savegamefile");
void type;
void variable;
void variablevalue;
setfilestreamposition(savegamefile, 0);
do{
filestreamnextline(savegamefile);
variable = getfilestreamargument(savegamefile, 0, "string");
type = getfilestreamargument(savegamefile, 1, "string");
variablevalue = getfilestreamargument(savegamefile, gamei+1, type);
if(variablevalue!="empty"){
setglobalvar(variable,variablevalue);
}
}while (variable != "End");
}
//-----------------------------------------------------------------------------------
//Save a game
//-----------------------------------------------------------------------------------
void savegame(int gamei){
void newsavegamefile=createfilestream();
void oldsavegamefile=getglobalvar("savegamefile");
void type;
void variable;
void variablevaluenewgamei;
void variablevalueoldi;
int i;
setfilestreamposition(newsavegamefile, 0);
setfilestreamposition(oldsavegamefile, 0);
filestreamnextline(oldsavegamefile);
do{
variable = getfilestreamargument(oldsavegamefile, 0, "string");
type = getfilestreamargument(oldsavegamefile, 1, "string");
if (getglobalvar(variable)){
variablevaluenewgamei=getglobalvar(variable)+"";
}else{
variablevaluenewgamei="empty";
}
filestreamappend(newsavegamefile, variable, 0);
filestreamappend(newsavegamefile, type, 1);
for (i=1,i<=7,i++){
variablevalueoldi=getfilestreamargument(oldsavegamefile, i+1, "string");
if (i==(gamei)){
filestreamappend(newsavegamefile, variablevaluenewgamei, 1);
}else{
filestreamappend(newsavegamefile, variablevalueoldi, 1);
}
}
filestreamnextline(oldsavegamefile);
}while (variable != "End");
filestreamappend(newsavegamefile, "End", 0);
filestreamappend(newsavegamefile, "int", 1);
filestreamappend(newsavegamefile, "1", 1);
savefilestream(newsavegamefile, "savegames.txt");
//free(oldsavegamefile);
setglobalvar("savegamefile",newsavegamefile);
}
The error was I was trying to append the txt file with int, instead of string.
«
Last Edit: May 24, 2010, 03:34:34 PM by basteaud
»
Logged
Pages: [
1
]
Go Up
Print
« previous
next »
Jump to:
Please select a destination:
-----------------------------
OpenBoR
-----------------------------
=> Discussions
=> Engine Center
===> Requests
===> Issues
===> Coding
=> Platform Center
===> PSP & PS3
===> Dreamcast
===> XBOX
===> Gp2x & Wiz
===> Dingoo
===> Wii
===> Windows
===> Linux
===> Macintosh
=> Mod Center
===> Completed
===> Demos
===> Wips
===> Reviews
=> OpenBoR Editor Project
=> Help & Resources
===> Tricks & Tutorials
===> Resources
===> Scripting
-----------------------------
Mugen
-----------------------------
=> Discussions
=> Modules
=> Help and Resources
===> Tricks & Tutorials
===> Resources
===> Scripting
-----------------------------
Hobbies
-----------------------------
=> Home Theater Setups
=> Arcade Systems
=> R/C Haven
=> Music - The Band
=> Art
===> Weekly Art Challenge
=> Out-Doors
-----------------------------
Video Games
-----------------------------
=> General
=> Guilds , Clans and Online Matchmaking
===> Borderlands
===> Left 4 Dead
===> World of Warcraft
=====> The Gods of Chaos
-----------------------------
General
-----------------------------
=> News
=> Discussions
=> Cinema
=> Television
Advertisement
Recent Topics
follow# animation ...
by
Damon Caskey
[September 06, 2010, 09:35:34 AM]
Knife vs Knife
by
Damon Caskey
[September 06, 2010, 09:23:10 AM]
Dragon Duo
by
maxman
[September 06, 2010, 08:48:32 AM]
Jennifer [PC Versi...
by
mayongdorn
[September 06, 2010, 07:38:52 AM]
Konpaku
by
danno
[September 06, 2010, 05:17:59 AM]
Splashy water
by
LeeBrother
[September 06, 2010, 05:13:40 AM]
Fist Of The NorthS...
by
Plombo
[September 06, 2010, 12:56:52 AM]
Wii support is her...
by
Plombo
[September 06, 2010, 12:26:39 AM]
Mortal Kombat 9 [+...
by
bWWd
[September 05, 2010, 11:28:05 PM]
dropv doesnt work ...
by
bWWd
[September 05, 2010, 11:21:33 PM]
Online Status
Members
Total Members: 18457
Latest:
deinende
Stats
Total Posts: 68628
Total Topics: 4634
Online Today: 34
Online Ever: 117
(October 23, 2009, 03:29:26 PM)
Users Online
Users: 4
Guests: 18
Total: 22
benji
Dragone_di_Smeraldo
Hanzo
deinende
TinyPortal v1.0 beta 4 ©
Bloc
Loading...