项目地址:https://github.com/Grasscutters/Grasscutter,本教程使用debian11系统基于版本1.2.0-dev构建,已在ios15.5和windows 10 上通过测试,本文也只讲这两个平台的连接。

准备工作

一台Debian11服务器,配置最低1c1g起

1 安装docker,java环境

docker:

curl -fsSL https://get.docker.com | bash

java:

sudo apt install openjdk-17-jdk 
sudo apt install openjdk-17-jre

2 docker安装mongo数据库

docker run -itd --name mongodb --network host --restart always -v /root/data:/data/db -h genshin_mongo mongo

3 构建服务器

git clone https://github.com/Grasscutters/Grasscutter.git 
cd Grasscutter 
chmod +x gradlew 
./gradlew jar
cd resources && git clone https://github.com/Koko-boya/Grasscutter_Resources
cd Grasscutter_Resources/Resources
mv * /root/Grasscutter/resources

执行完毕后运行 java -jar grasscutter.jar -handbookgrasscutter.jar文件替换为你自己的,一般为 grasscutter.jar-x-x-x.jar)会在当前目录生成 config.json配置文件按两次Ctrl+c退出程序。

3.1 编辑配置文件

编辑文件,文件格式如下,需要替换的有四处:两个 accessAddress替换为你自己的公网IP,accessPort自定义但建议与 bindPort一致(可按需更改)。

vim config.json
{
  "folderStructure": {
    "resources": "./resources/",
    "data": "./data/",
    "packets": "./packets/",
    "scripts": "./resources/scripts/",
    "plugins": "./plugins/"
  },
  "databaseInfo": {
    "server": {
      "connectionUri": "mongodb://localhost:27017",
      "collection": "grasscutter"
    },
    "game": {
      "connectionUri": "mongodb://localhost:27017",
      "collection": "grasscutter"
    }
  },
  "language": {
    "language": "en_US",
    "fallback": "en_US",
    "document": "EN"
  },
  "account": {
    "autoCreate": false,
    "defaultPermissions": [],
    "maxPlayer": -1
  },
  "server": {
    "debugLevel": "NONE",
    "runMode": "HYBRID",
    "http": {
      "bindAddress": "0.0.0.0",
      "accessAddress": "127.0.0.1",
      "bindPort": 443,
      "accessPort": 443,
      "encryption": {
        "useEncryption": true,
        "useInRouting": true,
        "keystore": "./keystore.p12",
        "keystorePassword": "123456"
      },
      "policies": {
        "cors": {
          "enabled": false,
          "allowedOrigins": [
            "*"
          ]
        }
      },
      "files": {
        "indexFile": "./index.html",
        "errorFile": "./404.html"
      }
    },
    "game": {
      "bindAddress": "0.0.0.0",
      "accessAddress": "127.0.0.1",
      "bindPort": 22102,
      "accessPort": 22102,
      "enableConsole": true,
      "gameOptions": {
        "inventoryLimits": {
          "weapons": 2000,
          "relics": 2000,
          "materials": 2000,
          "furniture": 2000,
          "all": 30000
        },
        "avatarLimits": {
          "singlePlayerTeam": 4,
          "multiplayerTeam": 4
        },
        "worldEntityLimit": 1000,
        "watchGachaConfig": false,
        "enableShopItems": true,
        "staminaUsage": true,
        "rates": {
          "adventureExp": 1.0,
          "mora": 1.0,
          "leyLines": 1.0
        }
      },
      "joinOptions": {
        "welcomeEmotes": [
          2007,
          1002,
          4010
        ],
        "welcomeMessage": "Welcome to a Grasscutter server.",
        "welcomeMail": {
          "title": "Welcome to Grasscutter!",
          "content": "Hi there!\r\nFirst of all, welcome to Grasscutter. If you have any issues, please let us know so that Lawnmower can help you! \r\n\r\nCheck out our:\r\n\u003ctype\u003d\"browser\" text\u003d\"Discord\" href\u003d\"https://discord.gg/T5vZU6UyeG\"/\u003e\n",
          "sender": "Lawnmower",
          "items": [
            {
              "itemId": 13509,
              "itemCount": 1,
              "itemLevel": 1
            },
            {
              "itemId": 201,
              "itemCount": 99999,
              "itemLevel": 1
            }
          ]
        }
      },
      "serverAccount": {
        "avatarId": 10000007,
        "nameCardId": 210001,
        "adventureRank": 1,
        "worldLevel": 0,
        "nickName": "Server",
        "signature": "Welcome to Grasscutter!"
      }
    },
    "dispatch": {
      "regions": [],
      "defaultName": "Grasscutter"
    }
  },
  "version": 3
}

再次执行 java -jar grasscutter.jar待启动完毕后输入 account create [账号] [密码]创建账号,可使用 screen后台运行或 supervisor守护进程。

3.2 编辑mitmproxy配置文件

vim proxy_config.py

localhost443改为你自己的配置,分别对应 accessAddressaccessPort

3.3 安装mitmproxy(如不需要在ios上使用则不用安装)

docker run -d --name mit --restart=always -v ~/mitm:/home/mitmproxy/.mitmproxy -v /root/Grasscutter/:/usr/mitm_proxy -p 9000:8899 mitmproxy/mitmproxy mitmdump -p 8899 -s /usr/mitm_proxy/proxy.py --ssl-insecure --set block_global=false --no-http2

至此服务端已全部安装完毕,下面是客户端配置

4 IOS连接

①WIFI感叹号->HTTP代理填入 accessAddress,9000后存储;

②浏览器访问mitm.it后下载ios证书描述文件(如果配置错误无法进入mitm下载证书界面此时显示:If you can see this, traffic is not passing through mitmproxy);

③设置->安装描述文件->通用->关于本机->最下方进入信任刚刚添加的证书;

④进入游戏,输入账号即可。

5 PC连接

①下载fiddler classic,双击打开;

②Tools->Options->Https->勾选Decrypt HTTPS traffic及其子选项,如图: image.png

③回到主界面,图中位置粘贴如下代码,ip:port更改成对应的 accessAddress:accessPort,点击 save scriptimage.png

/* Original script by NicknameGG, modified for Grasscutter by contributors. */
import System;
import System.Windows.Forms;
import Fiddler;
import System.Text.RegularExpressions;
 
class Handlers
{
    static function OnBeforeRequest(oS: Session) {
        if(oS.host.EndsWith(".yuanshen.com") || oS.host.EndsWith(".hoyoverse.com") || oS.host.EndsWith(".mihoyo.com")) {
            oS.host = "ip:port"; // This can also be replaced with another IP address.(输入域名也可)
        }
        if(oS.uriContains("http://uspider.yuanshen.com:8888/log")){
            oS.oRequest.FailSession(200, "Blocked", "haha");
        }
    }
};

④不要使用启动器启动原神客户端,找到游戏根目录的exe运行;

⑤进入游戏现已可正常运行。

6 游戏数据位置说明

/root/
-data #游戏账号数据
-Grasscutter #游戏服务器数据
-mitm #mitmproxy证书存放(未配置则没有)

最后修改:2022 年 05 月 22 日
如果觉得我的文章对你有用,请随意赞赏