Managing mod files

Locked
hacknorris
Member
Posts: 68
Joined: Mon Mar 28, 2022 21:34
GitHub: hacknorris-aka-penguin
IRC: hacknorris
In-game: hacknorris

Managing mod files

by hacknorris » Post

(I know nooby question, but...)
Someone know how to manage files in minetest mods? Means - create file, remove file, edit content of file (both binary and text), create folder, remove folder and best would be permissions (like chmod, yep im a linux fan)

ronoaldo
Member
Posts: 177
Joined: Mon Dec 07, 2020 01:04
GitHub: ronoaldo
IRC: ronoaldo
In-game: RonoaldoKakashi
Location: São Paulo, Brasil
Contact:

Re: Managing mod files

by ronoaldo » Post

Hi! welcome to the forums and Minetest :D

If I understood your question right, you want to make changes to the mod files, correct?

The mods are basically scripts written in the Lua programming language, so if you want to change the code any text file editor will be OK! If you already know how to code and use an IDE, just open the files there. If you prefer to use the terminal on Linux, Vi/Vim or even Nano are some good options too. I personally use VS Code, but the default text editor on most linux desktop environments will come with syntax highlight for Lua (Kwrite, Gedit, Leafpad, ...). For directories, no special things needed: just mkdir from terminal or use the file manager (Dolphin, Nautlius, Thunar, ...) for that.

For textures and models, you need specific programs for that. Gimp is good for editing the PNG files but if you want to change, say, a model 3d object, you usually will go for something like blender. For blender, you also need something to convert it to b3d and there is an extension to do the conversion that keeps all animations so you can use them on Minetest.

If you are into modding, this is a great starting point: https://rubenwardy.com/minetest_modding ... index.html

Also, there is a Youtube video series that walks over the process step by step, which is also great: https://www.youtube.com/watch?v=GgG9MHUGnew

Feel free to share error messages you may be receiving if you are trying to make changes so we may help with that... Depending on the issue you may need to debug it yourself :(

Yep, I'm also a Linux for for... like, 20 years O.O - I use Debian KDE by the way :-P
Servers: Mercurio | Tools: ContentDB CLI | Mods: minenews

User avatar
Blockhead
Member
Posts: 1622
Joined: Wed Jul 17, 2019 10:14
GitHub: Montandalar
IRC: Blockhead256
In-game: Blockhead Blockhead256
Location: Land Down Under
Contact:

Re: Managing mod files

by Blockhead » Post

The Lua standard library includes an I/O Library. These functions are accessible in Minetest. I don't think they can be used to set file permission though, since Lua is cross-platform to Windows where the UNIX permissions system isn't used (therefore introducing a platform-specific operation wouldn't make sense necessarily).

For security, you can only modify files within the current running world directory. Otherwise you could write a virus in Minetest Lua code. So you should start all filename strings with a call to minetest.get_worldpath() then concatenate file and directory names. Also, you should usually use modstorage (another link) unless you need to save binary data or access the same files as another mod*.

An example:

Code: Select all

f = io.open(minetest.get_worldpath().."/mymodname/filename", "w")
f:write("Hello, world!")
f:close()
*Someone with more info should answer: Is this line in the documentation still relevant now that modstorage has moved to a database backend instead of flat files?
/˳˳_˳˳]_[˳˳_˳˳]_[˳˳_˳˳\ Advtrains enthusiast | My map: Noah's Railyard | My Content on ContentDB ✝️♂

hacknorris
Member
Posts: 68
Joined: Mon Mar 28, 2022 21:34
GitHub: hacknorris-aka-penguin
IRC: hacknorris
In-game: hacknorris

Re: Managing mod files

by hacknorris » Post

Thx. Thought it was from minetest to modify files tho :’D

hacknorris
Member
Posts: 68
Joined: Mon Mar 28, 2022 21:34
GitHub: hacknorris-aka-penguin
IRC: hacknorris
In-game: hacknorris

Re: Managing mod files

by hacknorris » Post

oh, and modifying binary is also possible via lua?

ronoaldo
Member
Posts: 177
Joined: Mon Dec 07, 2020 01:04
GitHub: ronoaldo
IRC: ronoaldo
In-game: RonoaldoKakashi
Location: São Paulo, Brasil
Contact:

Re: Managing mod files

by ronoaldo » Post

Sorry, I misinterpreted your question. You can in theory use any lua libraries, but I guess you need to embed them in your mod and use the `dofile` instruction for that.

What do you mean by binary files? Binary files are random bytes / blobs, any specific format you have in mind?

Keep in mind that Minetest sandboxes your mod code, so it don't have arbitrary access to any file in the client/server it is running on. If you need to change arbitrary files, like other mod code or files outside the world directory, you need to request what is defined as a "insecure environment". See this chapter for more about security https://rubenwardy.com/minetest_modding ... vironments

Honestly, I would not allow such access to a mod though, so if the users don't add the mod and enable the insecure environment, your cod will not work as expected.
Servers: Mercurio | Tools: ContentDB CLI | Mods: minenews

hacknorris
Member
Posts: 68
Joined: Mon Mar 28, 2022 21:34
GitHub: hacknorris-aka-penguin
IRC: hacknorris
In-game: hacknorris

Re: Managing mod files

by hacknorris » Post

also next question - what about running other programming languages in lua? like C or bash
Spoiler
(or assembly...)

hacknorris
Member
Posts: 68
Joined: Mon Mar 28, 2022 21:34
GitHub: hacknorris-aka-penguin
IRC: hacknorris
In-game: hacknorris

Re: Managing mod files

by hacknorris » Post

and also - someone knows if its possible to embed other folders to init.lua ? like /games /root or /misc ?

User avatar
joe7575
Member
Posts: 851
Joined: Mon Apr 24, 2017 20:38
GitHub: joe7575
In-game: JoSto wuffi
Location: Germany, in the deep south

Re: Managing mod files

by joe7575 » Post

hacknorris wrote:
Thu Mar 31, 2022 18:08
and also - someone knows if its possible to embed other folders to init.lua ? like /games /root or /misc ?
This is possible by accepting that this mod becomes insecure and has to be added to the list of 'secure.trusted_mods'.

E. g. PDP-13 is a mod, with provides a file system for each computer.
Sent from my Commodore 64. Some of my Mods: Tech Age, TechPack, Hyperloop, Tower Crane, Lumberjack, vm16, Minecart, Signs Bot.

hacknorris
Member
Posts: 68
Joined: Mon Mar 28, 2022 21:34
GitHub: hacknorris-aka-penguin
IRC: hacknorris
In-game: hacknorris

Re: Managing mod files

by hacknorris » Post

joe7575 wrote:
Fri Apr 01, 2022 11:27
hacknorris wrote:
Thu Mar 31, 2022 18:08
and also - someone knows if its possible to embed other folders to init.lua ? like /games /root or /misc ?
This is possible by accepting that this mod becomes insecure and has to be added to the list of 'secure.trusted_mods'.

E. g. PDP-13 is a mod, with provides a file system for each computer.
thanks for saying that. now i dont have project :/

hacknorris
Member
Posts: 68
Joined: Mon Mar 28, 2022 21:34
GitHub: hacknorris-aka-penguin
IRC: hacknorris
In-game: hacknorris

Re: Managing mod files

by hacknorris » Post

last question - is it possible if such mod with insecure env gets approved to contentdb or i can only github?

User avatar
rubenwardy
Moderator
Posts: 6972
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy
Location: Bristol, United Kingdom
Contact:

Re: Managing mod files

by rubenwardy » Post

hacknorris wrote:
Sun Apr 03, 2022 11:31
last question - is it possible if such mod with insecure env gets approved to contentdb or i can only github?
Yes, ContentDB allows that.

It only disallows mods that ask for the sandbox to be fully disabled, rather than using insecure env
Renewed Tab (my browser add-on) | Donate | Mods | Minetest Modding Book

Hello profile reader

hacknorris
Member
Posts: 68
Joined: Mon Mar 28, 2022 21:34
GitHub: hacknorris-aka-penguin
IRC: hacknorris
In-game: hacknorris

Re: Managing mod files

by hacknorris » Post

so if i create something that writes to mod subdirs and reads from it can be?

User avatar
rubenwardy
Moderator
Posts: 6972
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy
Location: Bristol, United Kingdom
Contact:

Re: Managing mod files

by rubenwardy » Post

Yeah, but be aware that mod files are overwritten when the mod updates. So any new files or changes in mod directories will be lost

Oh, and if this is a hack and there's a better way to do it then you'll be asked to do that
Renewed Tab (my browser add-on) | Donate | Mods | Minetest Modding Book

Hello profile reader

hacknorris
Member
Posts: 68
Joined: Mon Mar 28, 2022 21:34
GitHub: hacknorris-aka-penguin
IRC: hacknorris
In-game: hacknorris

Re: Managing mod files

by hacknorris » Post

well... then i'd rather put it in github as i did with mtMod.... (yes, this is my acc again )

User avatar
Blockhead
Member
Posts: 1622
Joined: Wed Jul 17, 2019 10:14
GitHub: Montandalar
IRC: Blockhead256
In-game: Blockhead Blockhead256
Location: Land Down Under
Contact:

Re: Managing mod files

by Blockhead » Post

Thread recap:
Hacknorris wants to write a mod that will use unnecessary self-modifying code techniques or other obscure methods without giving a justification.

Response from Rubenwardy: Well you know you probably don't need to and shouldn't do it that way

Response from Hacknorris: Uhh well then I'm not going to publish it on ContentDB.

Ok but seriously though are you trying to write something super special that we haven't seen before, for which you need this technique, or are you just going to create a big mess that would never pass code review?
/˳˳_˳˳]_[˳˳_˳˳]_[˳˳_˳˳\ Advtrains enthusiast | My map: Noah's Railyard | My Content on ContentDB ✝️♂

hacknorris
Member
Posts: 68
Joined: Mon Mar 28, 2022 21:34
GitHub: hacknorris-aka-penguin
IRC: hacknorris
In-game: hacknorris

Re: Managing mod files

by hacknorris » Post

well... its not even special and im slowly moving out of it cause i saw that someone already did it... (vm16 and pdp-13)

User avatar
Miniontoby
Member
Posts: 616
Joined: Fri Mar 01, 2019 19:25
GitHub: Miniontoby
IRC: Miniontoby
In-game: Miniontoby
Location: The Netherlands

Re: Managing mod files

by Miniontoby » Post

hacknorris wrote:
Tue Mar 29, 2022 15:33
also next question - what about running other programming languages in lua? like C or bash
Spoiler
(or assembly...)
Possible but difficult... and only at server side mods...
Working on mtctl ---- Check my mod "Doorbell" -- Stay safe

User avatar
Linuxdirk
Member
Posts: 3217
Joined: Wed Sep 17, 2014 11:21
In-game: Linuxdirk
Location: Germany
Contact:

Re: Managing mod files

by Linuxdirk » Post

hacknorris wrote:
Sun Apr 03, 2022 14:29
so if i create something that writes to mod subdirs and reads from it can be?
You should not write to mod sub directories. Better write to the world directory. This also allows the mod to be used in multiple worlds with own individual settings/data.

hacknorris
Member
Posts: 68
Joined: Mon Mar 28, 2022 21:34
GitHub: hacknorris-aka-penguin
IRC: hacknorris
In-game: hacknorris

Re: Managing mod files

by hacknorris » Post

anyways - why i still get reply to this? someone can close thread as done? pls...

i already gave up and doing very other things...

User avatar
Linuxdirk
Member
Posts: 3217
Joined: Wed Sep 17, 2014 11:21
In-game: Linuxdirk
Location: Germany
Contact:

Re: Managing mod files

by Linuxdirk » Post

hacknorris wrote:
Sat Jun 25, 2022 15:50
someone can close thread as done?
Report your initial post and ask for the thread being closed.

Locked

Who is online

Users browsing this forum: Google [Bot] and 7 guests