Skip to content

Commit

Permalink
Merge branch 'Grasscutters:development' into development
Browse files Browse the repository at this point in the history
  • Loading branch information
memetrollsXD authored Apr 23, 2022
2 parents f1fd9b1 + fb2b98a commit b150818
Show file tree
Hide file tree
Showing 52 changed files with 5,463 additions and 173 deletions.
12 changes: 8 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,26 @@ on:
push:
branches:
- "stable"
pull_request:
types:
- opened
- synchronize
- reopened
jobs:
Build-Server-Jar:
runs-on: windows-latest
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup Java
uses: actions/setup-java@v3
with:
distribution: temurin
java-version: '8'
java-version: '16'
- name: Run Gradle
run: .\gradlew.bat && .\gradlew jar
run: ./gradlew && ./gradlew jar
- name: Upload build
uses: actions/upload-artifact@v3
with:
name: Grasscutter
path: grasscutter.jar

2 changes: 1 addition & 1 deletion Grasscutter-Protos
28 changes: 14 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,34 @@ A WIP server reimplementation for *some anime game* 2.3-2.6
* Inventory features (recieving items/characters, upgrading items/characters, etc)
* Gacha system
* Friends list
* Co-op *partially* work
* Co-op *partially* works
# Quick setup guide
### Note
* If you update from an older version, delete `config.json` for regeneration
* If you updated from an older version, delete `config.json` to regenerate it.

### Prerequisites
* JDK-8u202 ([mirror link](https://mirrors.huaweicloud.com/java/jdk/8u202-b08/) since Oracle required an account to download old builds)
* Java 16
* Mongodb (recommended 4.0+)
* Proxy daemon: mitmproxy (mitmdump, recommended), Fiddler Classic, etc.

### Starting up Grasscutter server (Assuming you are on Windows)
1. Setup compile environment `gradlew.bat`
1. Setup the compile environment with `gradlew.bat`
2. Compile Grasscutter with `gradlew jar`
3. Create a folder named `resources` in your Grasscutter directory, bring your `BinOutput` and `ExcelBinOutput` folders into it *(Check the wiki for more details how to get those.)*
3. Create a folder named `resources` in your Grasscutter directory, move your `BinOutput` and `ExcelBinOutput` folders there *(Check the wiki for more details on how to get those.)*
4. Run Grasscutter with `java -jar grasscutter.jar`. Make sure mongodb service is running as well.

### Connecting with the client
½. Create an account using *server console command* below
1. Run a proxy daemon: (choose either one)
- mitmdump: `mitmdump -s proxy.py -k`
- mitmdump: `mitmdump -s proxy.py -k --allow-hosts ".*\.yuanshen\.com|.*\.mihoyo\.com|.*\.hoyoverse\.com"`
- Fiddler Classic: Run Fiddler Classic, turn on `Decrypt https traffic` in setting and change the default port there (Tools -> Options -> Connections) to anything other than `8888`, and load [this script](https://github.lunatic.moe/fiddlerscript).
- [Hosts file](https://github.com/Melledy/Grasscutter/wiki/Running#traffic-route-map)
2. Trust CA certificate:
- mitmdump: `certutil -addstore root %USERPROFILE%\.mitmproxy\mitmproxy-ca-cert.cer`
2. Set network proxy to `127.0.0.1:8080` or the proxy port you specified.
4. *yoink*

* or you can use `run.cmd` to start Server & Proxy daemon with one click
* or you can use `start.cmd` to start Server & Proxy daemon with one click

# Grasscutter commands
There is a dummy user named "Server" in every player's friends list that you can message to use commands. Commands also work in other chat rooms, such as private/team chats.
Expand All @@ -54,26 +54,26 @@ There is a dummy user named "Server" in every player's friends list that you can

`killall`

`setworldlevel [level]` - Relog to see effects properly
`setworldlevel [level]` - Changes your world level, relog to see effects properly

`godmode` - Prevents you from taking damage

`resetconst` - Resets the constellation level on your current active character, will need to relog after using the command to see any changes.
`resetconst` - Resets the constellation level on your currently selected character, will need to relog after using the command to see any changes.

`setstats [stats] [amount]` - Changes the current character's specified stat.
`setstats [stats] [amount]` - Changes the currently selected character's specified stat.

`clearartifacts` - Deletes all unequipped and unlocked level 0 artifacts, **including yellow rarity ones** from your inventory
`clearartifacts` - Deletes all unequipped and unlocked level 0 artifacts, **including 5-star rarity ones** from your inventory

`pos` - Gets your current coordinate.
`pos` - Gets your current coordinates.

`weather [weather id] [climate id]` - Changes the current weather.

*More commands will be updated in the [wiki](https://github.com/Melledy/Grasscutter/wiki/).*

### Bonus
When you want to teleport to somewhere, use the ingame marking function on Map, click Confirm. You will see your character falling from a very high destination, exact location that you marked.
When you want to teleport somewhere, use the in-game marking function on the Map, click Confirm. You will see your character falling from a very high spot at the exact location you marked.

# Quick Troubleshooting
* If compiling wasn't successful, please check your JDK installation (must be JDK 8 and validated JDK's bin PATH variable)
* My client doesn't connect, doesn't login, 4206, etc... - Mostly your proxy daemon setup is *the issue*, if using Fiddler make sure it running on another port except 8888
* My client doesn't connect, doesn't login, 4206, etc... - Mostly your proxy daemon setup is *the issue*, if you're using Fiddler make sure it's running on a port other than 8888
* Startup sequence: Mongodb > Grasscutter > Proxy daemon (mitmdump, fiddler, etc.) > Client
11 changes: 5 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,16 @@ plugins {
id 'application'
}

sourceCompatibility = 1.8
targetCompatibility = 1.8
sourceCompatibility = 16
targetCompatibility = 16

repositories {
mavenCentral()
jcenter()
}

dependencies {
implementation fileTree(dir: 'lib', include: ['*.jar'])

implementation group: 'org.slf4j', name: 'slf4j-api', version: '1.7.32'
implementation group: 'ch.qos.logback', name: 'logback-core', version: '1.2.6'
implementation group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.6'
Expand All @@ -33,9 +32,9 @@ dependencies {
implementation group: 'com.google.code.gson', name: 'gson', version: '2.8.8'
implementation group: 'com.google.protobuf', name: 'protobuf-java', version: '3.18.1'

implementation group: 'org.reflections', name: 'reflections', version: '0.9.12'
implementation group: 'org.reflections', name: 'reflections', version: '0.10.2'

implementation group: 'dev.morphia.morphia', name: 'core', version: '1.6.1'
implementation group: 'dev.morphia.morphia', name: 'morphia-core', version: '2.2.6'

implementation group: 'org.greenrobot', name: 'eventbus-java', version: '3.3.1'
}
Expand Down
Empty file modified gradlew
100644 → 100755
Empty file.
Binary file modified keystore.p12
Binary file not shown.
4 changes: 3 additions & 1 deletion proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ class MlgmXyysd_Genshin_Impact_Proxy:
"minor-api.mihoyo.com",
"public-data-api.mihoyo.com",
"uspider.yuanshen.com",
"sdk-static.mihoyo.com"
"sdk-static.mihoyo.com",
"abtest-api-data-sg.hoyoverse.com",
"log-upload-os.hoyoverse.com"
]

def request(self, flow: http.HTTPFlow) -> None:
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/emu/grasscutter/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ public static class DispatchServerOptions {
public String Ip = "0.0.0.0";
public String PublicIp = "127.0.0.1";
public int Port = 443;
public int PublicPort = 0;
public String KeystorePath = "./keystore.p12";
public String KeystorePassword = "";
public String KeystorePassword = "123456";
public Boolean UseSSL = true;
public Boolean FrontHTTPS = true;

Expand All @@ -53,6 +54,7 @@ public static class GameServerOptions {
public String Ip = "0.0.0.0";
public String PublicIp = "127.0.0.1";
public int Port = 22102;
public int PublicPort = 0;

public String DispatchServerDatabaseUrl = "mongodb://localhost:27017";
public String DispatchServerDatabaseCollection = "grasscutter";
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/emu/grasscutter/Grasscutter.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public final class Grasscutter {
private static DispatchServer dispatchServer;
private static GameServer gameServer;

public static final Reflections reflector = new Reflections();
public static final Reflections reflector = new Reflections("emu.grasscutter");

static {
// Declare logback configuration.
Expand Down Expand Up @@ -118,6 +118,7 @@ public static void saveConfig() {

public static void startConsole() {
String input;
getLogger().info("Done! For help, type \"help\"");
try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
while ((input = br.readLine()) != null) {
try {
Expand Down
1 change: 1 addition & 0 deletions src/main/java/emu/grasscutter/command/CommandMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
public final class CommandMap {
private final Map<String, CommandHandler> commands = new HashMap<>();
private final Map<String, Command> annotations = new HashMap<>();

public CommandMap() {
this(false);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package emu.grasscutter.command.commands;

import emu.grasscutter.command.Command;
import emu.grasscutter.command.CommandHandler;
import emu.grasscutter.game.GenshinPlayer;
import emu.grasscutter.game.inventory.Inventory;
import emu.grasscutter.game.inventory.ItemType;

import java.util.List;

@Command(label = "clearweapons", usage = "clearweapons",
description = "Deletes all unequipped and unlocked weapons, including yellow rarity ones from your inventory",
aliases = {"clearwpns"}, permission = "player.clearweapons")
public final class ClearWeaponsCommand implements CommandHandler {

@Override
public void execute(GenshinPlayer sender, List<String> args) {
if (sender == null) {
CommandHandler.sendMessage(null, "Run this command in-game.");
return; // TODO: clear player's weapons from console or other players
}

Inventory playerInventory = sender.getInventory();
playerInventory.getItems().values().stream()
.filter(item -> item.getItemType() == ItemType.ITEM_WEAPON)
.filter(item -> !item.isLocked() && !item.isEquipped())
.forEach(item -> playerInventory.removeItem(item, item.getCount()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public void execute(GenshinPlayer sender, List<String> args) {
return;
}

sender.dropMessage(String.format("Coord: %.3f, %.3f, %.3f", sender.getPos().getX(), sender.getPos().getY(), sender.getPos().getZ()));
sender.dropMessage(String.format("Coord: %.3f, %.3f, %.3f\nScene id: %d",
sender.getPos().getX(), sender.getPos().getY(), sender.getPos().getZ(), sender.getSceneId()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import emu.grasscutter.command.Command;
import emu.grasscutter.command.CommandHandler;
import emu.grasscutter.data.def.AvatarSkillDepotData;
import emu.grasscutter.game.GenshinPlayer;
import emu.grasscutter.game.avatar.GenshinAvatar;
import emu.grasscutter.game.entity.EntityAvatar;
Expand All @@ -21,8 +22,9 @@ public void execute(GenshinPlayer sender, List<String> args) {
return;
}

if (args.size() < 0 || args.size() < 1){
if (args.size() < 1){
CommandHandler.sendMessage(sender, "To set talent level: /talent set <talentID> <value>");
CommandHandler.sendMessage(sender, "Another way to set talent level: /talent <n or e or q> <value>");
CommandHandler.sendMessage(sender, "To get talent ID: /talent getid");
return;
}
Expand All @@ -31,6 +33,7 @@ public void execute(GenshinPlayer sender, List<String> args) {
switch (cmdSwitch) {
default:
CommandHandler.sendMessage(sender, "To set talent level: /talent set <talentID> <value>");
CommandHandler.sendMessage(sender, "Another way to set talent level: /talent <n or e or q> <value>");
CommandHandler.sendMessage(sender, "To get talent ID: /talent getid");
return;
case "set":
Expand Down Expand Up @@ -90,6 +93,45 @@ public void execute(GenshinPlayer sender, List<String> args) {
return;
}

break;
case "n": case "e": case "q":
try {
EntityAvatar entity = sender.getTeamManager().getCurrentAvatarEntity();
GenshinAvatar avatar = entity.getAvatar();
AvatarSkillDepotData SkillDepot = avatar.getData().getSkillDepot();
int skillId;
switch (cmdSwitch) {
default:
skillId = SkillDepot.getSkills().get(0);
break;
case "e":
skillId = SkillDepot.getSkills().get(1);
break;
case "q":
skillId = SkillDepot.getEnergySkill();
break;
}
int nextLevel = Integer.parseInt(args.get(1));
int currentLevel = avatar.getSkillLevelMap().get(skillId);
if (args.size() < 1){
CommandHandler.sendMessage(sender, "To set talent level: /talent <n or e or q> <value>");
return;
}
if (nextLevel > 16){
CommandHandler.sendMessage(sender, "Invalid talent level. Level should be lower than 16");
return;
}
// Upgrade skill
avatar.getSkillLevelMap().put(skillId, nextLevel);
avatar.save();
// Packet
sender.sendPacket(new PacketAvatarSkillChangeNotify(avatar, skillId, currentLevel, nextLevel));
sender.sendPacket(new PacketAvatarSkillUpgradeRsp(avatar, skillId, currentLevel, nextLevel));
CommandHandler.sendMessage(sender, "Set this talent to " + nextLevel + ".");
} catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, "Invalid talent level.");
return;
}
break;
case "getid":
EntityAvatar entity = sender.getTeamManager().getCurrentAvatarEntity();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package emu.grasscutter.command.commands;

import emu.grasscutter.command.Command;
import emu.grasscutter.command.CommandHandler;
import emu.grasscutter.game.GenshinPlayer;
import emu.grasscutter.utils.Position;

import java.util.List;

@Command(label = "teleport", usage = "teleport <x> <y> <z>", aliases = {"tp"},
description = "Change the player's position.", permission = "player.teleport")
public class TelePortCommand implements CommandHandler {

@Override
public void execute(GenshinPlayer sender, List<String> args) {
if (sender == null) {
CommandHandler.sendMessage(null, "Run this command in-game.");
return;
}

if (args.size() < 3){
CommandHandler.sendMessage(sender, "Usage: /tp <x> <y> <z> [scene id]");
return;
}

try {
float x = Float.parseFloat(args.get(0));
float y = Float.parseFloat(args.get(1));
float z = Float.parseFloat(args.get(2));
int sceneId = sender.getSceneId();
if (args.size() == 4){
sceneId = Integer.parseInt(args.get(3));
}
Position target = new Position(x, y, z);
boolean result = sender.getWorld().transferPlayerToScene(sender, sceneId, target);
if (!result) {
CommandHandler.sendMessage(sender, "Invalid position.");
}
} catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, "Invalid position.");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import dev.morphia.annotations.Entity;
import dev.morphia.annotations.Id;

@Entity(value = "counters", noClassnameStored = true)
@Entity(value = "counters", useDiscriminator = false)
public class DatabaseCounter {
@Id
private String id;
Expand Down
Loading

0 comments on commit b150818

Please sign in to comment.