Merge changes from hamusuke (#1)

This commit is contained in:
KingRainbow44 2023-08-26 17:57:46 -04:00
parent 7dd63e9816
commit 396f302eac
No known key found for this signature in database
GPG Key ID: FC2CB64B00D257BE
14 changed files with 195 additions and 89 deletions

View File

@ -3,10 +3,12 @@ package emu.grasscutter;
import emu.grasscutter.game.world.Position;
import emu.grasscutter.utils.objects.SparseSet;
import emu.grasscutter.utils.Utils;
import java.util.Arrays;
import java.util.*;
public final class GameConstants {
public static String VERSION = "4.0.0";
public static int[] VERSION_PARTS = {4, 0, 0};
public static boolean DEBUG = false;
public static final int DEFAULT_TEAMS = 4;

View File

@ -15,6 +15,7 @@ import emu.grasscutter.data.excels.giving.*;
import emu.grasscutter.data.excels.monster.*;
import emu.grasscutter.data.excels.quest.*;
import emu.grasscutter.data.excels.reliquary.*;
import emu.grasscutter.data.excels.scene.*;
import emu.grasscutter.data.excels.tower.*;
import emu.grasscutter.data.excels.trial.*;
import emu.grasscutter.data.excels.weapon.*;
@ -269,7 +270,14 @@ public final class GameData {
private static final Int2ObjectMap<InvestigationMonsterData> investigationMonsterDataMap =
new Int2ObjectOpenHashMap<>();
@Getter private static final Int2ObjectMap<ItemData> itemDataMap = new Int2ObjectOpenHashMap<>();
@Getter
private static final Int2ObjectMap<ItemData> itemDataMap = new Int2ObjectOpenHashMap<>();
@Getter
private static final Int2ObjectMap<MapLayerData> mapLayerDataMap = new Int2ObjectOpenHashMap<>();
@Getter
private static final Int2ObjectMap<MapLayerGroupData> mapLayerGroupDataMap = new Int2ObjectOpenHashMap<>();
@Getter
private static final Int2ObjectMap<MonsterCurveData> monsterCurveDataMap =
@ -336,14 +344,16 @@ public final class GameData {
@Getter
private static final Int2ObjectMap<SceneData> sceneDataMap = new Int2ObjectLinkedOpenHashMap<>();
@Getter
private static final Int2ObjectMap<SceneTagData> sceneTagDataMap = new Int2ObjectLinkedOpenHashMap<>();
@Getter
private static final Int2ObjectMap<TalkConfigData> talkConfigDataMap =
new Int2ObjectOpenHashMap<>();
new Int2ObjectOpenHashMap<>();
@Getter
private static final Int2ObjectMap<TowerFloorData> towerFloorDataMap =
new Int2ObjectOpenHashMap<>();
new Int2ObjectOpenHashMap<>();
@Getter
private static final Int2ObjectMap<TowerLevelData> towerLevelDataMap =

View File

@ -0,0 +1,19 @@
package emu.grasscutter.data.excels.scene;
import com.google.gson.annotations.SerializedName;
import emu.grasscutter.data.GameResource;
import emu.grasscutter.data.ResourceType;
import lombok.Getter;
@ResourceType(name = "MapLayerExcelConfigData.json")
@Getter
public final class MapLayerData extends GameResource {
@Getter(onMethod_ = @Override)
private int id;
@SerializedName("NLPFIGAEBFP")
private int idk1;
@SerializedName("GCBPOOPNLLD")
private float level; //how deep thoronium is in me
}

View File

@ -0,0 +1,21 @@
package emu.grasscutter.data.excels.scene;
import com.google.gson.annotations.SerializedName;
import emu.grasscutter.data.GameResource;
import emu.grasscutter.data.ResourceType;
import lombok.Getter;
import java.util.List;
@ResourceType(name = "MapLayerGroupExcelConfigData.json")
@Getter
public final class MapLayerGroupData extends GameResource {
@Getter(onMethod_ = @Override)
private int id;
@SerializedName("FIIAHPKBCDE")
private List<Integer> areaIds;
@SerializedName("ODEFCAMHKNK")
private float mapFloorId; //MapLayerFloorExcel (first level of the maplayer)
}

View File

@ -1,15 +1,15 @@
package emu.grasscutter.data.excels;
package emu.grasscutter.data.excels.scene;
import com.google.gson.annotations.SerializedName;
import emu.grasscutter.data.GameResource;
import emu.grasscutter.data.ResourceType;
import emu.grasscutter.data.*;
import emu.grasscutter.game.props.SceneType;
import java.util.List;
import lombok.Getter;
import java.util.List;
@ResourceType(name = "SceneExcelConfigData.json")
@Getter
public class SceneData extends GameResource {
public final class SceneData extends GameResource {
@Getter(onMethod_ = @Override)
private int id;

View File

@ -0,0 +1,40 @@
package emu.grasscutter.data.excels.scene;
import com.google.gson.annotations.SerializedName;
import emu.grasscutter.data.GameResource;
import emu.grasscutter.data.ResourceType;
import lombok.Getter;
import java.util.List;
@ResourceType(name = "SceneTagConfigData.json")
@Getter
public final class SceneTagData extends GameResource {
@Getter(onMethod_ = @Override)
private int id;
@SerializedName("DJCOAOBDIHP")
private boolean idk1;
@SerializedName("LOLNNMPKHIB")
private boolean idk2;
private boolean isDefaultValid; // shld be there by default
private String sceneTagName;
private int sceneId;
private List<SceneTagCondition> cond;
@Getter
public static class SceneTagCondition {
private CondType condType;
private int param1;
private int param2;
public enum CondType {
SCENE_TAG_COND_TYPE_ACTIVITY_CONTENT_OPEN,
SCENE_TAG_COND_TYPE_QUEST_FINISH,
SCENE_TAG_COND_TYPE_QUEST_GLOBAL_VAR_EQUAL,
SCENE_TAG_COND_TYPE_SPECIFIC_ACTIVITY_OPEN
}
}
}

View File

@ -21,6 +21,7 @@ import emu.grasscutter.game.quest.GameMainQuest;
import emu.grasscutter.game.world.SceneGroupInstance;
import emu.grasscutter.utils.objects.Returnable;
import io.netty.util.concurrent.FastThreadLocalThread;
import javax.annotation.Nullable;
import java.util.List;
import java.util.concurrent.*;
import java.util.stream.Stream;
@ -541,11 +542,20 @@ public final class DatabaseHelper {
DatabaseHelper.saveGameAsync(musicGameBeatmap);
}
@Nullable
public static Achievements getAchievementData(int uid) {
return DatabaseManager.getGameDatastore()
try {
return DatabaseManager.getGameDatastore()
.find(Achievements.class)
.filter(Filters.and(Filters.eq("uid", uid)))
.first();
} catch (IllegalArgumentException e) {
Grasscutter.getLogger().debug("Error occurred while getting uid " + uid + "'s achievement data", e);
DatabaseManager.getGameDatabase()
.getCollection("achievements")
.deleteMany(eq("uid", uid));
return null;
}
}
public static void saveAchievementData(Achievements achievements) {

View File

@ -2,6 +2,7 @@ package emu.grasscutter.game.props;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Stream;
@ -13,17 +14,18 @@ public enum ClimateType {
CLIMATE_RAIN(3),
CLIMATE_THUNDERSTORM(4),
CLIMATE_SNOW(5),
CLIMATE_MIST(6);
CLIMATE_MIST(6),
CLIMATE_DESERT(7);
private static final Int2ObjectMap<ClimateType> map = new Int2ObjectOpenHashMap<>();
private static final Map<String, ClimateType> stringMap = new HashMap<>();
static {
Stream.of(values())
.forEach(
e -> {
map.put(e.getValue(), e);
stringMap.put(e.name(), e);
.forEach(
e -> {
map.put(e.getValue(), e);
stringMap.put(e.name(), e);
});
}

View File

@ -4,9 +4,10 @@ import emu.grasscutter.Grasscutter;
import emu.grasscutter.data.*;
import emu.grasscutter.data.binout.SceneNpcBornEntry;
import emu.grasscutter.data.binout.routes.Route;
import emu.grasscutter.data.excels.*;
import emu.grasscutter.data.excels.ItemData;
import emu.grasscutter.data.excels.codex.CodexAnimalData;
import emu.grasscutter.data.excels.monster.MonsterData;
import emu.grasscutter.data.excels.scene.SceneData;
import emu.grasscutter.data.excels.world.WorldLevelData;
import emu.grasscutter.data.server.Grid;
import emu.grasscutter.game.avatar.Avatar;
@ -22,8 +23,8 @@ import emu.grasscutter.game.props.*;
import emu.grasscutter.game.quest.QuestGroupSuite;
import emu.grasscutter.game.world.data.TeleportProperties;
import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.proto.*;
import emu.grasscutter.net.proto.AttackResultOuterClass.AttackResult;
import emu.grasscutter.net.proto.*;
import emu.grasscutter.net.proto.VisionTypeOuterClass.VisionType;
import emu.grasscutter.scripts.*;
import emu.grasscutter.scripts.constants.EventType;
@ -34,11 +35,12 @@ import emu.grasscutter.server.packet.send.*;
import emu.grasscutter.server.scheduler.ServerTaskScheduler;
import emu.grasscutter.utils.objects.KahnsSort;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import lombok.*;
import javax.annotation.Nullable;
import java.util.*;
import java.util.concurrent.*;
import java.util.stream.Collectors;
import javax.annotation.Nullable;
import lombok.*;
public final class Scene {
@Getter private final World world;

View File

@ -1,20 +1,17 @@
package emu.grasscutter.server.http.dispatch;
import static emu.grasscutter.utils.lang.Language.translate;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.auth.AuthenticationSystem;
import emu.grasscutter.auth.OAuthAuthenticator.ClientType;
import emu.grasscutter.server.http.Router;
import emu.grasscutter.server.http.objects.ComboTokenReqJson;
import emu.grasscutter.server.http.objects.*;
import emu.grasscutter.server.http.objects.ComboTokenReqJson.LoginTokenData;
import emu.grasscutter.server.http.objects.LoginAccountRequestJson;
import emu.grasscutter.server.http.objects.LoginTokenRequestJson;
import emu.grasscutter.utils.JsonUtils;
import emu.grasscutter.utils.Utils;
import emu.grasscutter.utils.*;
import io.javalin.Javalin;
import io.javalin.http.Context;
import static emu.grasscutter.utils.lang.Language.translate;
/** Handles requests related to authentication. */
public final class AuthenticationHandler implements Router {
/**
@ -38,7 +35,7 @@ public final class AuthenticationHandler implements Router {
// Log to console.
Grasscutter.getLogger()
.info(translate("messages.dispatch.account.login_attempt", Utils.address(ctx)));
.debug(translate("messages.dispatch.account.login_attempt", Utils.address(ctx)));
}
/**
@ -62,7 +59,7 @@ public final class AuthenticationHandler implements Router {
// Log to console.
Grasscutter.getLogger()
.info(translate("messages.dispatch.account.login_attempt", Utils.address(ctx)));
.debug(translate("messages.dispatch.account.login_attempt", Utils.address(ctx)));
}
/**
@ -89,7 +86,7 @@ public final class AuthenticationHandler implements Router {
// Log to console.
Grasscutter.getLogger()
.info(translate("messages.dispatch.account.login_attempt", Utils.address(ctx)));
.debug(translate("messages.dispatch.account.login_attempt", Utils.address(ctx)));
}
@Override

View File

@ -235,15 +235,15 @@ public final class RegionHandler implements Router {
// Get region data.
String regionData = "CAESGE5vdCBGb3VuZCB2ZXJzaW9uIGNvbmZpZw==";
if (ctx.queryParamMap().values().size() > 0) {
if (!ctx.queryParamMap().values().isEmpty()) {
if (region != null) regionData = region.getBase64();
}
String clientVersion = versionName.replaceAll(Pattern.compile("[a-zA-Z]").pattern(), "");
String[] versionCode = clientVersion.split("\\.");
int versionMajor = Integer.parseInt(versionCode[0]);
int versionMinor = Integer.parseInt(versionCode[1]);
int versionFix = Integer.parseInt(versionCode[2]);
var clientVersion = versionName.replaceAll(Pattern.compile("[a-zA-Z]").pattern(), "");
var versionCode = clientVersion.split("\\.");
var versionMajor = Integer.parseInt(versionCode[0]);
var versionMinor = Integer.parseInt(versionCode[1]);
var versionFix = Integer.parseInt(versionCode[2]);
if (versionMajor >= 3
|| (versionMajor == 2 && versionMinor == 7 && versionFix >= 50)
@ -254,8 +254,12 @@ public final class RegionHandler implements Router {
String key_id = ctx.queryParam("key_id");
if (!clientVersion.equals(
GameConstants.VERSION)) { // Reject clients when there is a version mismatch
if (
versionMajor != GameConstants.VERSION_PARTS[0] ||
versionMinor != GameConstants.VERSION_PARTS[1]
// The 'fix' or 'patch' version is not checked because it is only used
// when miHoYo is desperate and fucks up big time.
) { // Reject clients when there is a version mismatch
boolean updateClient = GameConstants.VERSION.compareTo(clientVersion) > 0;
@ -268,7 +272,7 @@ public final class RegionHandler implements Router {
StopServerInfo.newBuilder()
.setUrl("https://discord.gg/grasscutters")
.setStopBeginTime((int) Instant.now().getEpochSecond())
.setStopEndTime((int) Instant.now().getEpochSecond() * 2)
.setStopEndTime((int) Instant.now().getEpochSecond() + 1)
.setContentMsg(
updateClient
? "\nVersion mismatch outdated client! \n\nServer version: %s\nClient version: %s"
@ -279,7 +283,7 @@ public final class RegionHandler implements Router {
.buildPartial();
Grasscutter.getLogger()
.info(
.debug(
String.format(
"Connection denied for %s due to %s.",
Utils.address(ctx), updateClient ? "outdated client!" : "outdated server!"));

View File

@ -4,7 +4,7 @@ import emu.grasscutter.Grasscutter;
import emu.grasscutter.command.CommandMap;
import emu.grasscutter.data.GameData;
import emu.grasscutter.data.excels.ItemData;
import emu.grasscutter.data.excels.SceneData;
import emu.grasscutter.data.excels.scene.SceneData;
import emu.grasscutter.data.excels.avatar.AvatarData;
import emu.grasscutter.data.excels.monster.MonsterData;
import emu.grasscutter.utils.FileUtils;

View File

@ -14,11 +14,13 @@ public class PacketGetSceneAreaRsp extends BasePacket {
GetSceneAreaRsp p =
GetSceneAreaRsp.newBuilder()
.setSceneId(sceneId)
.addAllAreaIdList(player.getUnlockedSceneAreas(sceneId))
.addCityInfoList(player.getSotsManager().getCityInfo(1).toProto())
.addCityInfoList(player.getSotsManager().getCityInfo(2).toProto())
.addCityInfoList(player.getSotsManager().getCityInfo(3).toProto())
.setSceneId(sceneId)
.addAllAreaIdList(player.getUnlockedSceneAreas(sceneId))
.addCityInfoList(player.getSotsManager().getCityInfo(1).toProto())
.addCityInfoList(player.getSotsManager().getCityInfo(2).toProto())
.addCityInfoList(player.getSotsManager().getCityInfo(3).toProto())
.addCityInfoList(player.getSotsManager().getCityInfo(4).toProto())
.addCityInfoList(player.getSotsManager().getCityInfo(5).toProto())
.build();
this.setData(p);

View File

@ -1,9 +1,12 @@
package emu.grasscutter.server.packet.send;
import emu.grasscutter.data.GameData;
import emu.grasscutter.data.excels.scene.SceneTagData;
import emu.grasscutter.net.packet.BasePacket;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.PlayerWorldSceneInfoListNotifyOuterClass.PlayerWorldSceneInfoListNotify;
import emu.grasscutter.net.proto.PlayerWorldSceneInfoOuterClass.PlayerWorldSceneInfo;
import java.util.stream.IntStream;
public class PacketPlayerWorldSceneInfoListNotify extends BasePacket {
@ -12,50 +15,44 @@ public class PacketPlayerWorldSceneInfoListNotify extends BasePacket {
super(PacketOpcodes.PlayerWorldSceneInfoListNotify); // Rename opcode later
PlayerWorldSceneInfoListNotify.Builder proto =
PlayerWorldSceneInfoListNotify.newBuilder()
.addInfoList(PlayerWorldSceneInfo.newBuilder().setSceneId(1).setIsLocked(false).build())
.addInfoList(
PlayerWorldSceneInfo.newBuilder()
.setSceneId(3)
.setIsLocked(false)
.addSceneTagIdList(102) // Jade chamber
.addSceneTagIdList(113)
.addSceneTagIdList(117)
// Vanarana (Sumeru tree)
.addSceneTagIdList(1093) // Vana_real
// .addSceneTagIdList(1094) // Vana_dream
// .addSceneTagIdList(1095) // Vana_first
// .addSceneTagIdList(1096) // Vana_festival
// 3.1 event
.addSceneTagIdList(152)
.addSceneTagIdList(153)
// Pyramid
.addSceneTagIdList(1164) // Arena (XMSM_CWLTop)
.addSceneTagIdList(1166) // Pyramid (CWL_Trans_02)
// Brute force
// .addAllSceneTagIdList(IntStream.range(1150, 1250).boxed().toList())
.build())
.addInfoList(
PlayerWorldSceneInfo.newBuilder()
.setSceneId(4)
.setIsLocked(false)
.addSceneTagIdList(106)
.addSceneTagIdList(109)
.addSceneTagIdList(117)
.build())
.addInfoList(PlayerWorldSceneInfo.newBuilder().setSceneId(5).setIsLocked(false).build())
.addInfoList(PlayerWorldSceneInfo.newBuilder().setSceneId(6).setIsLocked(false).build())
.addInfoList(PlayerWorldSceneInfo.newBuilder().setSceneId(7).setIsLocked(false).build())
.addInfoList(
PlayerWorldSceneInfo.newBuilder()
.setSceneId(9)
.setIsLocked(false)
.addAllSceneTagIdList(IntStream.range(0, 3000).boxed().toList())
.build());
PlayerWorldSceneInfoListNotify.newBuilder()
.addInfoList(PlayerWorldSceneInfo.newBuilder().setSceneId(1).setIsLocked(false).build())
.addInfoList(PlayerWorldSceneInfo.newBuilder()
.setSceneId(3)
.setIsLocked(false)
.addAllSceneTagIdList(GameData.getSceneTagDataMap().values().stream()
.filter(sceneTag -> sceneTag.getSceneId() == 3)
.filter(sceneTag -> sceneTag.isDefaultValid() || sceneTag.getCond().get(0).getCondType() != null)
.map(SceneTagData::getId)
.toList())
//.addSceneTagIdList(102) // Jade chamber (alr added)
//.addSceneTagIdList(113)
//.addSceneTagIdList(117)
//.addSceneTagIdList(1093) // 3.0 Vana_real
.addSceneTagIdList(1094) // 3.0 Vana_dream
//.addSceneTagIdList(1095) // 3.0 Vana_first
//.addSceneTagIdList(1096) // 3.0 Vana_festival
.addSceneTagIdList(152) // 3.1 event
.addSceneTagIdList(153) // 3.1 event
.addSceneTagIdList(1164) // Desert Arena (XMSM_CWLTop)
.addSceneTagIdList(1166) // Desert Pyramid (CWL_Trans_02)
.build())
.addInfoList(PlayerWorldSceneInfo.newBuilder()
.setSceneId(4)
.setIsLocked(false)
.addSceneTagIdList(106)
.addSceneTagIdList(109)
.addSceneTagIdList(117)
.build())
.addInfoList(PlayerWorldSceneInfo.newBuilder().setSceneId(5).setIsLocked(false).build())
.addInfoList(PlayerWorldSceneInfo.newBuilder().setSceneId(6).setIsLocked(false).build())
.addInfoList(PlayerWorldSceneInfo.newBuilder().setSceneId(7).setIsLocked(false).build())
.addInfoList(PlayerWorldSceneInfo.newBuilder().setSceneId(9).setIsLocked(false)
.addAllSceneTagIdList(IntStream.range(0, 3000).boxed().toList())
.build())
.addInfoList(PlayerWorldSceneInfo.newBuilder().setSceneId(10).setIsLocked(false)
.addAllSceneTagIdList(IntStream.range(0, 3000).boxed().toList())
.build()); //3.8
this.setData(proto);
}