“模组:编辑 XNB 文件”的版本间的差异

来自Stardew Valley Wiki
跳到导航 跳到搜索
(复制自模组:制作一个XNB模组页面。)
→‎进行修改 润色
 
(未显示4个用户的39个中间版本)
第1行: 第1行:
 ←[[ 使用 模组:目录|目录]]
+
 ←[[模组:目录|目录]]
{{翻译}}
 
  
 本页 介绍 如何 创建一个替换 游戏 文件 的MOD, 便 更改游戏数据 图像和地图。
+
 本页 描述了 如何 编辑 游戏文件以更改游戏 中的 数据 图像和地图。
  
 
==介绍==
 
==介绍==
===XNB 模组的工作原理===
+
=== 什么是 XNB 文件?===
 游戏 <tt>.xnb</tt> 压缩 格式文件把 数据 存储在<tt>Content</tt> 文件 。例如 ,在 对话框里显示 阿比盖尔的头像来自<tt>Content\Portraits\Abigail.xnb</tt> 这个文件。每个<tt>.xnb</tt>包含两个文件: 数据 文件 (如图像)和元数据文件(有关数据文件的信息) 例如,这是<tt>Content\Portraits\Abigail.xnb</tt>里面的内容:
+
 游戏 将数据、地图和纹理存储在 <samp>.xnb</samp> 这种 压缩数据文件中, 它们 游戏 的 <samp>Content</samp> 文件 夹中 。 
  
<pre>
+
例如,对话期间显示的阿比盖尔的头像来自这个文件: <samp>Content\Portraits\Abigail.xnb</samp>。解包这个文件,你会得到 <samp>Abigail.png</samp> 这个图片文件,内容如下:<br />[[File:Modding - creating an XNB mod - example portraits.png]]
Abigail.xnb
 
  Abigail.png
 
  Abigail.yaml
 
</pre>
 
  
  在上面 例子中:
+
(如果你使用 xnbcli 来解包,你通常会得到 <samp>Abigail.json</samp> 文件。 那只是用来打包回 <samp>.xnb</samp> 所需 文件,通常不需要更改它。)
  
* <tt>Abigail.png</tt> 这个文件里包含阿比盖尔的头像。 果你想修 她在 游戏中 的头像,需要编辑的就是这个文件:<br />[[File:Modding - creating an XNB mod - example portraits.png]]
+
=== 何将更 应用到 游戏中 ?===
* <tt>Abigail.yaml</tt> 文件里包含关于 <tt>Abigail.png</tt>  元数据(文件类型之类的),通常情况下不 改动它。
+
  有3 方法可以使你 修改应 到游戏中:
  
XNB 模组 代替了 些游戏原本的XNB 文件 可以 让你 更改 图像(头像,NPC行走图或建筑物外形), 数据 物信息或对话),或地图(包括地图行为 如传送或小 游戏 。 XNB模组 也可以添加全新的内容(如新的NPC)
+
# [[ 模组:Content Patcher|创建 个Content Patcher内容包]](也见:{{nexus mod|1915|nexusmods.com上的Content Patcher}})。这不需要编程,仅编辑 JSON  文件 可以更改 游戏的 XNB  数据 ,也无需替换实际的游戏文件。
 +
# [[:en:Modding:Modder Guide/Get Started|制 一个 SMAPI 模组]] 并使用 [[:en:Modding:Modder_Guide/APIs/Content|内容 API]]。不过 这需要编程。
 +
# 通过替换原始 游戏 文件来创建 XNB 模组 不再建议使用,本页面没有讲解; 访问 [[模组:使用 XNB 模组|使用 XNB 模组]] 获取更多信息
  
===XNB vs SMAPI mods===
+
=== 在哪里可以得到帮助?===
SMAPI is a modding API that lets you change the game using code. SMAPI mods are more powerful, easier to install and remove, and allow multiple mods to change the same content. On the other hand, SMAPI requires you to write code which some modders aren't comfortable with. If you have programming experience, [[Modding:Creating a SMAPI mod|creating a SMAPI mod]] is recommended instead if feasible.
+
欢迎前往星露谷物语[[:en:Modding:Community| 模组社区]] 寻求帮助。
  
  有关这两种mod 更多信息,请看:[[使用模组:玩家常见问题]]
+
==<span id="unpacking">解包游戏文件</span>==
 +
  你无法编辑 <samp>.xnb</samp> 文件其本身,你需要编辑其中 文件
  
===在哪里可以获得帮助?===
+
将文件从中取出叫做 '''解包''';
The Stardew Valley modding community is very welcoming. Feel free [https://discord.gg/stardewvalley come chat on Discord] or [http://community.playstarbound.com/forums/mods.215/ post in the forums].
 
  
== 门==
+
把文件放 其中叫做 '''打包'''。
===第一步===
 
在你开始之前, 你应该安装这些:
 
  
:; on Windows
+
有两个主要的 XNB 解包工具可用:
  
::* '''[https://www.mediafire.com/?b86xecd27yti6f6 XNB Extract 0.2.2]''' 去打开或者组装这个游戏的XNB 文件. <small>(See [http://community.playstarbound.com/threads/beginners-guide-to-xnb-node-and-graphics-editing.110976/ forum post].)</small>
+
===StardewXnbHack===
::* '''[http://www.getpaint.net/download.html Paint.NET]''' 去编辑图像文件(or use your favourite image editor).
+
{{github|Pathoschild/StardewXnbHack#readme|StardewXnbHack}} 是用于解包 XNB 文件 的开源且跨平台的工具。
  
:; on Linux/Mac
+
它不能打包回 <samp>.xnb</samp> ,不过你也只在[[模组:Content Patcher|创建内容包]]时才需要打包回去。
  
::* '''[https://www.winehq.org/download Wine 1.7 or later]''' to run Windows programs like XNB Extract.
+
如何操作:
::* '''[https://www.dropbox.com/s/oj5tch8np74nk4d/XNBExtract0.2.2.zip?dl=0 XNB Extract 0.2.2 for Linux/Mac]''' to unpack and pack the game's XNB files.
 
::* '''[https://www.gimp.org/downloads/ GIMP]''' to edit image files (or use your favourite image editor).
 
  
You should also back up your game's <tt>Content</tt> folder, so you can recover the original files if you make a mistake.
+
# [[模组:使用指南/入门#安装SMAPI|安装 SMAPI]]
 +
# {{github|Pathoschild/StardewXnbHack/releases|下载 StardewXnbHack}}(确保你下载的文件适用于你的系统,例如在Windows平台需要下载: StardewXnbHack-*-for-windows.zip 而不是 source code!)
 +
# 解压缩并放进 [[模组:使用指南/入门#找到你的游戏文件夹|你的游戏文件夹]], 也就是让 <samp>StardewXnbHack.exe</samp> 文件位于与{{executable name|StardewValley}}相同的目录下.
 +
# 双击运行 <samp>StardewXnbHack.exe</samp> (Windows)、<samp>StardewXnbHack.sh</samp> (Linux)、 <samp>StardewXnbHack.command</samp> (MacOS) 来解包游戏文件夹中 <samp>Content</samp> 文件夹下的所有 XNB 文件。
  
===Unpack & pack game files===
+
就是这样!它将会把解包的内容放入游戏文件夹下的 <samp>Content (unpacked)</samp> 文件夹。解包出的文件可用于创建 [[模组:Content Patcher|Content Patcher]] 的内容包。
<span id="unpacking"></span>
 
  
You can't edit an <tt>.xnb</tt> file itself, you need to edit the file that's inside it. Pulling out that inner file is called ''unpacking'', and putting it back is called ''packing''. Here's how to do it:
+
===xnbcli===
 +
{{github|LeonBlade/xnbcli#readme|xnbcli}} 是用于打包和解包 XNB 文件的开源且跨平台的工具。它无法解包带有数据模型的 XNB 文件 (例如 <samp>Data\FishPondData</samp> 或者 <samp>Data\Movies</samp>),并且需要手动编辑数据文件才能与 Content Patcher 等模组一起使用。
  
# Download XNB Extract (see [[#First-time setup]]).
+
如何操作:
# Unpack the file for editing:
 
## Find the file you want to edit in the <tt>Contents</tt> folder.
 
## Copy it into XNB Extract's <tt>Packed</tt> folder.
 
## Double-click <tt>UnpackFiles.bat</tt> (Windows) or <tt>UnpackFiles.sh</tt> (Linux/Mac).
 
# Edit the unpacked file (see below).
 
# Repack the file for the game:
 
## Double-click <tt>PackFiles.bat</tt> (Windows) or <tt>PackFiles.sh</tt> (Linux/Mac).
 
## Move the repacked <tt>.xnb</tt> file back to the original location.
 
  
==Making changes==
+
<ol>
===Spritesheets, tilesheets, or portraits===
+
<li>{{github|LeonBlade/xnbcli/releases|下载 xnbcli}}。 (确保你下载的文件适用于你的系统,例如在Windows平台需要下载:<samp>xnbcli-windows-x64.zip</samp> 而不是 source code!)</li>
[[File:Modding - creating an XNB mod - example tilesheet.png|thumb|An example tilesheet, which consists of a grid of tiles like this: [[File:Modding - creating an XNB mod - example tile 1.png]]]]
+
<li>解压缩下载的文件:
Definitions:
+
# 找到你要解包的文件。
* A '''spritesheet''' is a PNG file containing small images in a regular grid pattern. Each square in the spritesheet's grid pattern is called a '''sprite'''. For example, each in-game item has a sprite in <tt>Content\Maps\spring_objects.xnb</tt>.
+
# 将它放进 xnbcli 的 <samp>packed</samp> 文件夹。
* A '''tilesheet''' is a synonym for spritesheet when used for map tiles. In a tilesheet, each square is called a ''tile'' and is 16×16 pixels.
+
# 双击 <samp>unpack.bat</samp> (Windows)、<samp>unpack.sh</samp> (Linux)、<samp>unpack.command</samp> (Mac)。
* A '''portrait''' is a sprite from the <tt>Content\Characters\*.xnb</tt> spritesheets.
+
# 检查 <samp>Unpacked</samp> 文件夹,解包后的文件在该文件夹中 (如果你没有一次性解包很多文件,它可能会在屏幕上闪烁并瞬间消失,这很正常!无论如何,请注意检查 <samp>Unpacked</samp> 文件夹。注意 1.4 引入了 xnbcli 无法处理的新数据模型格式;对于某些数据文件,你需要使用 [[#StardewXnbHack|StardewXnbHack]] 才行。)
 +
</li>
 +
<li>编辑解压缩的文件(请参见下文)。</li>
 +
<li>如果这是一个数据文件(而不是图像或地图),要替换或编辑该文件,则需要删除 XNB 元数据。当前的 JSON 文件内容应如下所示:
 +
<syntaxhighlight lang="js">
 +
{
 +
   "header": {
 +
     "target": "w",
 +
     "formatVersion": 5,
 +
     "hidef": true,
 +
     "compressed": true
 +
   },
 +
   "readers": [
 +
     {
 +
       "type": "Microsoft.Xna.Framework.Content.DictionaryReader`2[[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]",
 +
       "version": 0
 +
     },
 +
     {
 +
       "type": "Microsoft.Xna.Framework.Content.Int32Reader",
 +
       "version": 0
 +
     },
 +
     {
 +
       "type": "Microsoft.Xna.Framework.Content.StringReader",
 +
       "version": 0
 +
     }
 +
   ],
 +
   "content": {
 +
     "0": "Weeds/0/-1/Basic/Weeds/A bunch of obnoxious weeds."
 +
   }
 +
}
 +
</syntaxhighlight>
 +
只需删除 除了内容字段(content)以外的所有内容,就像这样:
 +
<syntaxhighlight lang="js">
 +
{
 +
   "0": "Weeds/0/-1/Basic/Weeds/A bunch of obnoxious weeds."
 +
}
 +
</syntaxhighlight></li>
 +
</ol>
  
Spritesheets are easy to edit:
+
'''故障排除:'''
# [[#unpacking|Unpack the file]] you want to change.
+
* 如果您在 Linux 或者 Mac 上遇到权限问题:
# Open the unpacked <tt>.png</tt> file in an image editor (see [[#Getting started]]).
+
*# 打开一个终端(在 MacOS 中,在 Spotlight 中搜索“终端”或者英文“Terminal”)
# Make changes directly to the image.
+
*# 输入 <code>chmod +x&nbsp;</code>, 并以一个空格结束输入,现在不要按 Enter 键。
# [[#unpacking|Repack the file]] and copy it back to the original location.
+
*# 拖拽 <samp>unpack.sh</samp> (Linux) 或 <samp>unpack.command</samp> (Mac) 到终端窗口上以输入文件路径。
 +
*# 按 Enter 键。如果操作正确,终端将不会显示任何消息,权限问题应该解决了。
 +
*# 重新尝试运行 <samp>pack.sh</samp> (Linux) 或 <samp>pack.command</samp> (Mac).
 +
* 如果在 Windows 上遇到无法识别的命令,请执行以下操作:
 +
*# 确保你没有误下载 源代码zip!
  
That's it! You can launch the game to see your changes.
+
==打包游戏文件==
 +
你不需要打包游戏文件,如果你正在使用 [[模组:Content Patcher|Content Patcher]] 的话。<br />
 +
使用 <samp>.json</samp>, <samp>.png</samp>, 或者 <samp>.tbin</samp> 文件连接到你的 <samp>content.json</samp>.
  
=== 地图===
+
如果你确实想打包,则需要使用 [[#xnbcli|xnbcli]]:
 请 见:[[ 使用 模组:地图]]
+
# 找到你要重新打包的文件。
 +
# 复制到 xnbcli 的 <samp>unpacked</samp> 文件夹。
 +
# 双击 <samp>pack.bat</samp> (Windows)、<samp>pack.sh</samp> (Linux)、<samp>pack.command</samp> (Mac)。
 +
# 移动打包后的 <samp>.xnb</samp> 文件至原来的位置。
 +
 
 +
==进行修改==
 +
===数据===
 +
  每个 XNB 都有自己的格式。 参阅[[模组: 目录#高阶主题]]中的文档。
 +
 
 +
===图像===
 +
[[File:Modding - creating an XNB mod - example tilesheet.png|thumb|一个spritesheet的示例,它由像[[File:Modding - creating an XNB mod - example tile 1.png]]这样的图块整齐排列而成]]
 +
一些定义:
 +
* '''spritesheet''' 指的是包含小图像的 PNG 文件(小图像通常排列成规则的网格形式)。每一块小图像都称为一个 '''sprite'''。例如,在<samp>Content\Maps\spring_objects.xnb</samp>中,每个游戏内物品都有一个 sprite。
 +
* '''tilesheet''' 是 Spritesheet 的同义词,用于 地图 图块。在tilesheet中,每个方格称为“图块(tile)”,大小为 16×16 像素。
 +
* '''portrait''' 是<samp>Content\Characters\*.xnb</samp>的spritesheets中的sprite。
 +
 
 +
Spritesheets 易于编辑:
 +
# [[#解包游戏文件|解包]] 你想要更改的文件。
 +
# 用图像编辑器(例如Windows平台上的 [http://www.getpaint.net/download.html Paint.NET],或是适用于Windows/Linux/Mac平台的 [https://www.gimp.org/downloads/ GIMP])打开已解包的 <samp>.png</samp>文件。注意,使用支持透明通道(即ARGB 中的 A:alpha 通道)的图像编辑器(例如 Photoshop)非常重要,因此不推荐使用Windows自带的画图。
 +
# 直接对图像进行更改。
 +
# [[#解包游戏文件|重新打包文件]] 然后复制到原位置。
 +
 
 +
就是这样!然后你就可以打开游戏以看看你做出的修改了!
  
 
[[Category:模组]]
 
[[Category:模组]]

2023年7月21日 (五) 18:13的最新版本

目录

本页描述了如何编辑游戏文件以更改游戏中的数据、图像和地图。

介绍

什么是 XNB 文件?

游戏将数据、地图和纹理存储在 .xnb 这种压缩数据文件中,它们在游戏的 Content 文件夹中。

例如,对话期间显示的阿比盖尔的头像来自这个文件: Content\Portraits\Abigail.xnb。解包这个文件,你会得到 Abigail.png 这个图片文件,内容如下:
Modding - creating an XNB mod - example portraits.png

(如果你使用 xnbcli 来解包,你通常会得到 Abigail.json 文件。 那只是用来打包回 .xnb 所需的文件,通常不需要更改它。)

如何将更改应用到游戏中?

有3个方法可以使你的修改应用到游戏中:

  1. 创建一个Content Patcher内容包(也见:nexusmods.com上的Content Patcher)。这不需要编程,仅编辑 JSON 文件就可以更改游戏的 XNB 数据,也无需替换实际的游戏文件。
  2. 制作一个 SMAPI 模组 并使用 内容 API。不过,这需要编程。
  3. 通过替换原始游戏文件来创建 XNB 模组。不再建议使用,本页面没有讲解; 访问 使用 XNB 模组 获取更多信息。

在哪里可以得到帮助?

欢迎前往星露谷物语模组社区寻求帮助。

解包游戏文件

你无法编辑 .xnb 文件其本身,你需要编辑其中的文件。

将文件从中取出叫做 解包

把文件放入其中叫做 打包

有两个主要的 XNB 解包工具可用:

StardewXnbHack

StardewXnbHack 是用于解包 XNB 文件的开源且跨平台的工具。

它不能打包回 .xnb ,不过你也只在创建内容包时才需要打包回去。

如何操作:

  1. 安装 SMAPI
  2. 下载 StardewXnbHack(确保你下载的文件适用于你的系统,例如在Windows平台需要下载: StardewXnbHack-*-for-windows.zip 而不是 source code!)
  3. 解压缩并放进 你的游戏文件夹, 也就是让 StardewXnbHack.exe 文件位于与Stardew Valley executable icon.png StardewValley.exe相同的目录下.
  4. 双击运行 StardewXnbHack.exe (Windows)、StardewXnbHack.sh (Linux)、 StardewXnbHack.command (MacOS) 来解包游戏文件夹中 Content 文件夹下的所有 XNB 文件。

就是这样!它将会把解包的内容放入游戏文件夹下的 Content (unpacked) 文件夹。解包出的文件可用于创建 Content Patcher 的内容包。

xnbcli

xnbcli 是用于打包和解包 XNB 文件的开源且跨平台的工具。它无法解包带有数据模型的 XNB 文件 (例如 Data\FishPondData 或者 Data\Movies),并且需要手动编辑数据文件才能与 Content Patcher 等模组一起使用。

如何操作:

  1. 下载 xnbcli。 (确保你下载的文件适用于你的系统,例如在Windows平台需要下载:xnbcli-windows-x64.zip 而不是 source code!)
  2. 解压缩下载的文件:
    1. 找到你要解包的文件。
    2. 将它放进 xnbcli 的 packed 文件夹。
    3. 双击 unpack.bat (Windows)、unpack.sh (Linux)、unpack.command (Mac)。
    4. 检查 Unpacked 文件夹,解包后的文件在该文件夹中 (如果你没有一次性解包很多文件,它可能会在屏幕上闪烁并瞬间消失,这很正常!无论如何,请注意检查 Unpacked 文件夹。注意 1.4 引入了 xnbcli 无法处理的新数据模型格式;对于某些数据文件,你需要使用 StardewXnbHack 才行。)
  3. 编辑解压缩的文件(请参见下文)。
  4. 如果这是一个数据文件(而不是图像或地图),要替换或编辑该文件,则需要删除 XNB 元数据。当前的 JSON 文件内容应如下所示:
    {
        "header": {
            "target": "w",
            "formatVersion": 5,
            "hidef": true,
            "compressed": true
        },
        "readers": [
            {
                "type": "Microsoft.Xna.Framework.Content.DictionaryReader`2[[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]",
                "version": 0
            },
            {
                "type": "Microsoft.Xna.Framework.Content.Int32Reader",
                "version": 0
            },
            {
                "type": "Microsoft.Xna.Framework.Content.StringReader",
                "version": 0
            }
        ],
        "content": {
            "0": "Weeds/0/-1/Basic/Weeds/A bunch of obnoxious weeds."
        }
    }
    

    只需删除 除了内容字段(content)以外的所有内容,就像这样:

    {
        "0": "Weeds/0/-1/Basic/Weeds/A bunch of obnoxious weeds."
    }
    

故障排除:

  • 如果您在 Linux 或者 Mac 上遇到权限问题:
    1. 打开一个终端(在 MacOS 中,在 Spotlight 中搜索“终端”或者英文“Terminal”)
    2. 输入 chmod +x , 并以一个空格结束输入,现在不要按 Enter 键。
    3. 拖拽 unpack.sh (Linux) 或 unpack.command (Mac) 到终端窗口上以输入文件路径。
    4. 按 Enter 键。如果操作正确,终端将不会显示任何消息,权限问题应该解决了。
    5. 重新尝试运行 pack.sh (Linux) 或 pack.command (Mac).
  • 如果在 Windows 上遇到无法识别的命令,请执行以下操作:
    1. 确保你没有误下载 源代码zip!

打包游戏文件

你不需要打包游戏文件,如果你正在使用 Content Patcher 的话。
使用 .json, .png, 或者 .tbin 文件连接到你的 content.json.

如果你确实想打包,则需要使用 xnbcli

  1. 找到你要重新打包的文件。
  2. 复制到 xnbcli 的 unpacked 文件夹。
  3. 双击 pack.bat (Windows)、pack.sh (Linux)、pack.command (Mac)。
  4. 移动打包后的 .xnb 文件至原来的位置。

进行修改

数据

每个 XNB 都有自己的格式。请参阅模组:目录#高阶主题中的文档。

图像

一个spritesheet的示例,它由像Modding - creating an XNB mod - example tile 1.png这样的图块整齐排列而成

一些定义:

  • spritesheet 指的是包含小图像的 PNG 文件(小图像通常排列成规则的网格形式)。每一块小图像都称为一个 sprite。例如,在Content\Maps\spring_objects.xnb中,每个游戏内物品都有一个 sprite。
  • tilesheet 是 Spritesheet 的同义词,用于地图图块。在tilesheet中,每个方格称为“图块(tile)”,大小为 16×16 像素。
  • portraitContent\Characters\*.xnb的spritesheets中的sprite。

Spritesheets 易于编辑:

  1. 解包你想要更改的文件。
  2. 用图像编辑器(例如Windows平台上的 Paint.NET,或是适用于Windows/Linux/Mac平台的 GIMP)打开已解包的 .png文件。注意,使用支持透明通道(即ARGB 中的 A:alpha 通道)的图像编辑器(例如 Photoshop)非常重要,因此不推荐使用Windows自带的画图。
  3. 直接对图像进行更改。
  4. 重新打包文件 然后复制到原位置。

就是这样!然后你就可以打开游戏以看看你做出的修改了!