SRB2 Message Board  

Go Back   SRB2 Message Board > Sonic Robo Blast 2 > Releases > Mods

Reply
 
Thread Tools
SRB2+I/O - Input/Output support for Lua! Details »»
SRB2+I/O - Input/Output support for Lua!
Version: 1.0, by Wolfy (Lumberjack Yandere) Wolfy is offline
Developer Last Online: Aug 2017

Category: Version: SRB2 Rating: (3 votes - 3.40 average)
Released: 01-24-2016 Last Update: Never Installs: 0
Re-Useable Content Code Changes

Hi, wolfs is back!

This is probably the biggest expansion Lua has gotten in a long time. Originally removed for being too dangerous, this mod reimplements the input/output library into SRB2's Lua API. With this, you can now read, edit, or create files using Lua scripts! Of course, for sanity purposes, a lot of security restrictions had to be put in place. They are as follows:
  • .., :, and % cannot be used in path strings. Any attempt to do so will result in Lua throwing a warning.
  • Path strings cannot start with / or \\. This, along with the changes above, was done to prevent users from leaving the SRB2 directory.
  • All files are written into a new directory named luafiles by default. This was done for security and organization reasons.
  • You can specify non-existent subdirectories in your path string and the game will automatically create them for you.
  • io.popen() has been removed. This function would allow scripters to open programs with the Lua API. Naturally this is a terrible idea.
  • File size has been limited to 1MB. If a file is over 1MB and you attempt to append it, it will not be modified. If a file is under 1MB and your change would bring it over, it is discarded. (contents erased if mode is "w", contents unmodified if mode is "a+")
  • A whitelist has been included for specific filetypes. Any attempts to use different file types will result in Lua throwing a warning. Supported filetypes are .txt, .sav2, .cfg, .png, and .bmp.

I/O is pretty new, and is not documented on the SRB2 Wiki yet. For a reference on I/O functions in Lua and how they are used, check here.

The zip here includes the SDL2 build (srb2io.exe) and a DirectDraw build. (srb2iodd.exe) Linux guys, I'm sorry, but you're gonna have to compile your own binaries. I have no stable Linux testing environment aside from a VPS with a really specific compile setup.

About netgame compatibility:
The build here is compiled off of the latest public master branch of the SRB2 repo. The io branch itself is based on the next branch, but changing that requires copying a mere three files into any other repo. As it is compiled on master, it *should* be netgame compatible with 2.1.14, but I wouldn't rely on it much. If you are hosting with an I/O build, I strongly urge you not to use any functions that would affect other players. Use the functions locally and have them only apply to the server. Alternatively, you can avoid playing netgames with this build entirely and wait until I/O becomes a vanilla feature in 2.2. The choice is yours.

Please remember to report any and all bugs you find. I/O can be a rather volatile thing so it's important that any major system security issues are taken care of.

With that said, have fun, and please don't use the I/O library to be an asshole. :3


Source Code
LightDash Mirror

Download Now

File Type: zip SRB2+IO.zip (2.00 MB, 435 views)

Screenshots

Click image for larger version

Name:	srb20027.jpg
Views:	1468
Size:	150.8 KB
ID:	7323  

Supporters / CoAuthors

Show Your Support

  • The author of this addon has given explicit permission for its content to be re-used and/or reproduced.

Comments
Old 01-24-2016   #2
Charybdizs
Excelsior
Judge
 
Charybdizs's Avatar
Default

Great! This is working just fine, I think!
Charybdizs is offline   Reply With Quote
Old 01-24-2016   #3
chi.miru
Developer
 
chi.miru's Avatar
Default

I'll make sure to try it later, could maybe come in handy or something .
__________________
=- SRB2 Projects Page -=
chi.miru is offline   Reply With Quote
Old 01-24-2016   #4
RedEnchilada
happy, pretty, lovely!
Developer
 
RedEnchilada's Avatar
Default

The more important question is "Why can we read/write to BMP and PNG files if there are no libraries accessible to Lua to process them in the first place?"
__________________
Quote:
<@toaster> '"sonic robot explosion 2", the hot new sensation for teens looking for a good time, tempts many children away from god each year'
RedEnchilada is offline   Reply With Quote
Old 01-24-2016   #5
toaster
トースタちゃん
Developer
 
toaster's Avatar
Default

Code your own! BMPs are a simple filetype, so writing small images should be relatively simple if you have even a basic understanding of the file format (although I may be at an advantage because I had to write an essay on image file formats a couple weeks ago)... I might even try and give a BMP library for modders a shot myself at some point. This page is particularily helpful on the matter in the meantime...

I'm excited to see this be a thing and I can't wait to have actual free time to take advantage of this! In, like. Ten weeks or something. [gentle sobbing]
__________________
Quote:
<MonsterIestyn> surely it's good ass though
Quote:
<MonsterIestyn> watch porm to keep warm

Last edited by toaster; 01-24-2016 at 05:38 PM.
toaster is offline   Reply With Quote
Old 01-24-2016   #6
RedEnchilada
happy, pretty, lovely!
Developer
 
RedEnchilada's Avatar
Default

Yes, write a hefty script to parse PNGs that the game has no use for. Are we preparing for someone to create photoshop.lua or something?
__________________
Quote:
<@toaster> '"sonic robot explosion 2", the hot new sensation for teens looking for a good time, tempts many children away from god each year'
RedEnchilada is offline   Reply With Quote
Old 01-24-2016   #7
toaster
トースタちゃん
Developer
 
toaster's Avatar
Default

That would be amazing, but I was just thinking the ability to write them would be useful for... silly Pokemon Snap style photographs that aren't just taking a regular screenshot with you in the way? I dunno.
__________________
Quote:
<MonsterIestyn> surely it's good ass though
Quote:
<MonsterIestyn> watch porm to keep warm
toaster is offline   Reply With Quote
Old 01-24-2016   #8
Wolfy
Lumberjack Yandere
Developer
 
Wolfy's Avatar
Default The fires of greed will burn the weak; so we'll make freedom obsolete

Quote:
Originally Posted by RedEnchilada View Post
The more important question is "Why can we read/write to BMP and PNG files if there are no libraries accessible to Lua to process them in the first place?"
toaster asked for them, and adding support was as simple as adding two lines to an array.
__________________
Quote:
[23:56:36] <SM-MaxX> prisma illya is a gift to this impure earth and a shining beacon for all anime

Last edited by Wolfy; 01-25-2016 at 12:58 AM.
Wolfy is offline   Reply With Quote
Old 04-22-2016   #9
Blaze The Cat
& Knuckles
 
Blaze The Cat's Avatar
Default

Is there any way to prevent other Lua scripts from overwriting the files saved by your own Lua? Or, do we have to try not to "conflict" one another?
Blaze The Cat is offline   Reply With Quote
Old 04-22-2016   #10
Wolfy
Lumberjack Yandere
Developer
 
Wolfy's Avatar
Default I give my people the lives they need; the righteous will succeed

Quote:
Originally Posted by Blaze The Cat View Post
Is there any way to prevent other Lua scripts from overwriting the files saved by your own Lua? Or, do we have to try not to "conflict" one another?
To my knowledge the answer to this is no. If two scripts save the same file, all sorts of stuff can break. Nothing was done in hardcode regarding this in order to avoid creating more limitations.
__________________
Quote:
[23:56:36] <SM-MaxX> prisma illya is a gift to this impure earth and a shining beacon for all anime
Wolfy is offline   Reply With Quote
Old 04-23-2016   #11
Blaze The Cat
& Knuckles
 
Blaze The Cat's Avatar
Default

The best we can do, is at least write in the file "In use by thisismylua.lua" And hope that other Luas read it and complain to the user.
Blaze The Cat is offline   Reply With Quote
Old 04-23-2016   #12
742mph
I make Sonic look like me
 
742mph's Avatar
Default

Quote:
Originally Posted by Blaze The Cat View Post
The best we can do, is at least write in the file "In use by thisismylua.lua" And hope that other Luas read it and complain to the user.
You could always just prefix the name of your file with the name of your mod. Unless they were specifically trying to mess with you, the developer of, say, "Mystic Realm" would never read or write to a file called "torturedplanet_data.sav2."
__________________
Quote:
<Evilgasm> the opposite of egoraptor is Toa Tahu
742mph is offline   Reply With Quote
Old 04-24-2016   #13
Ritz
cornstar
 
Ritz's Avatar
Default

So, what can we do with this besides writing custom save files? What would be really cool is if we could modify lumps as the game is running, like palettes, colormaps... Blockmaps? That's not happening, right?
__________________
http://funkvessel.tumblr.com/
Ritz is offline   Reply With Quote
Old 04-24-2016   #14
Zwip-Zwap Zapony
Please just call me Zappy.
 
Zwip-Zwap Zapony's Avatar
Default

Quote:
Originally Posted by Ritz View Post
So, what can we do with this besides writing custom save files?
You can also import them. With enough patience and skill and such, you could make something like Super Mario 64 (with multiple "missions" in each level, being able to go back and complete previous ones, and needing to clear X amount of "missions" to advance to more levels). Or you could save the values of custom Lua variables, so people don't have to re-input them every time.
Zwip-Zwap Zapony is offline   Reply With Quote
Old 04-24-2016   #15
Wolfy
Lumberjack Yandere
Developer
 
Wolfy's Avatar
Default I've carved my own path, you followed your wrath; but maybe we're both the same

Quote:
Originally Posted by Ritz View Post
So, what can we do with this besides writing custom save files? What would be really cool is if we could modify lumps as the game is running, like palettes, colormaps... Blockmaps? That's not happening, right?
As expected, no, you can't do any of that with I/O. What you can do with I/O is create parsers for scripts of different languages, store saves or config files used by Lua scripts, or write hilarious and impractical memes.

I should also note that I/O has no access to any of the game's assets (or, well, anything outside of the luafiles folder) for super obvious security reasons.
__________________
Quote:
[23:56:36] <SM-MaxX> prisma illya is a gift to this impure earth and a shining beacon for all anime
Wolfy is offline   Reply With Quote
Old 04-24-2016   #16
Blaze The Cat
& Knuckles
 
Blaze The Cat's Avatar
Default

Yeah, we don't want players creating viruses ... do we?

I/O is also useful for Terminal, because it lets you save those permissions now.
Blaze The Cat is offline   Reply With Quote
Old 03-05-2017   #17
Kitoko
Click on me for help! YAHOO
 
Kitoko's Avatar
Default

I wish this were updated for 2.1.17

That's pretty much all I can say.
__________________
<Chaos> go hitneo
<Chaos> she can walk on lava
Kitoko is offline   Reply With Quote
Reply

Thread Tools

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 Off

Forum Jump


All times are GMT. The time now is 03:03 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2017, vBulletin Solutions, Inc.