[File] [PATCH] of Magdir/games for Godot Engine resources

yakoyoku at gmail.com yakoyoku at gmail.com
Thu Apr 15 22:44:58 UTC 2021


From: Martin Reboredo <yakoyoku at gmail.com>

Hi,
after I've sent my glTF patch (and that got accepted) I decided to send the Godot Engine [1] resources magic that I've been working on.
So far text and binary resources such as scenes, materials and textures were introduced here, but I've couldn't add magic for the GDSCript
scripts because of some syntax ambiguities that I've to deal with.

As for magic respect the official GitHub repository [2] has `shared-mime-info`s [3] for most formats that the engine uses. Text resources
have an INI like syntax while binary resources are headed with `RSRC` and `RSCC` for both uncompressed/compressed options. Following a 28
bit offset the uncompressed resources describe which kind of it the file is (e.g. ShaderMaterial for shader materials).

Text resources have a distinguishing section or a key w/ value, in this case this is an TSCN [4] text scene.
$ cat MainScene.tscn
  [gd_scene load_steps=2 format=2]

  [ext_resource path="res://MainScene.gd" type="Script" id=1]

  [node name="Spatial" type="Spatial"]
  script = ExtResource( 1 )

  [node name="Camera" type="Camera" parent="."]
  transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 6 )

The next binary resource is the `hexdump(1)` for the first 48 bytes of an spatial material.
  00000000  52 53 52 43 00 00 00 00  00 00 00 00 03 00 00 00  |RSRC............|
  00000010  02 00 00 00 03 00 00 00  10 00 00 00 53 70 61 74  |............Spat|
  00000020  69 61 6c 4d 61 74 65 72  69 61 6c 00 00 00 00 00  |ialMaterial.....|

Notice that following offset 0x14 (20 in decimal) is Zstandard data for compressed resources.
$ hexdump -C testfilecompressed.res
  00000000  52 53 43 43 02 00 00 00  00 10 00 00 07 03 00 00  |RSCC............|
  00000010  7f 01 00 00 28 b5 2f fd  60 07 02 ad 0b 00 a6 50  |....(./.`......P|

Textures are a much different case, starting with `GDST` followed by PNG data.
$ hexdump -C .import/<example-texture>.stex
  00000000  47 44 53 54 00 01 00 00  00 01 00 00 04 00 00 00  |GDST............|
  00000010  00 00 10 07 01 00 00 00  f2 03 00 00 50 4e 47 20  |............PNG |

Links:
- 1: https://godotengine.org/
- 2: https://github.com/godotengine/godot
- 3: https://github.com/godotengine/godot/blob/master/misc/dist/linux/org.godotengine.Godot.xml
- 4: https://docs.godotengine.org/en/stable/development/file_formats/tscn.html

Best Regards,
    -> Martin Reboredo
---
 magic/Magdir/games | 65 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 65 insertions(+)

diff --git a/magic/Magdir/games b/magic/Magdir/games
index 2167ce28..c8dd0998 100644
--- a/magic/Magdir/games
+++ b/magic/Magdir/games
@@ -518,3 +518,68 @@
 >2	uleshort	0x4638	version 8, used in RDR 2,
 >>4	ulelong 	x	%d bytes,
 >>>8	ulelong 	x	%d entries
+
+##############################################################################
+# Godot Engine asset files
+#
+# Summary:
+# Formats used by the Godot Engine. Text assets mostly have an INI-like
+# syntax, with the exception of the GDScript files. Binary files may come
+# compressed or not.
+#
+# References:
+# * Godot Engine official MIME types:
+#    <https://github.com/godotengine/godot/blob/master/misc/dist/linux/org.godotengine.Godot.xml>
+# * Godot Engine TSCN file format:
+#    <https://docs.godotengine.org/en/stable/development/file_formats/tscn.html>
+
+### Godot Engine project
+
+0	search/1000/w	config_version		Godot Engine project
+!:strength +20
+!:mime	application/x-godot-project
+!:ext	godot
+
+### Godot Engine text resources
+
+0	search/1000/w	[gd_resource		Godot Engine text resource
+>&0	search/50/w	type="Environment"	\b, Rendering Environment
+!:mime	application/x-godot-resource
+!:ext	tres
+>&0	search/50/w	type="SpatialMaterial"	\b, Spatial Material
+!:mime	application/x-godot-resource
+!:ext	tres
+>&0	search/50/w	type="ShaderMaterial"	\b, Shader Material
+!:mime	application/x-godot-resource
+!:ext	tres
+
+### Godot Engine text scenes
+
+0	search/1000/w	[gd_scene		Godot Engine TSCN text scene
+!:mime	application/x-godot-scene
+!:ext	tscn/escn
+
+### Godot Engine binary resources/scenes
+
+0	string		RSRC			Godot Engine binary
+>28	string		Environment		\b resource, Rendering Environment
+!:mime	application/x-godot-resource
+!:ext	res
+>28	string		SpatialMaterial		\b resource, Spatial Material
+!:mime	application/x-godot-resource
+!:ext	res/material
+>28	string		ShaderMaterial		\b resource, Shader Material
+!:mime	application/x-godot-resource
+!:ext	res/material
+>28	string		PackedScene		\b scene
+!:mime	application/x-godot-scene
+!:ext	res/scn
+0	string		RSCC			Godot Engine compressed binary resource
+!:mime	application/x-godot-resource
+!:ext	res/material/scn
+
+### Godot Engine texture
+
+0	string		GDST			Godot Engine texture
+!:mime	application/x-godot-resource
+!:ext	stex
-- 
2.30.2



More information about the File mailing list