Skip to content

Commit

Permalink
Change gamebiz type from enum to string (Scighost#1094)
Browse files Browse the repository at this point in the history
* change gamebiz type from enum to string

* change isvalid to isknown

* gamebiz dapper sql mapper
  • Loading branch information
Scighost authored and Eric-Joker committed Sep 27, 2024
1 parent 4c5dfaa commit 0f358e1
Show file tree
Hide file tree
Showing 59 changed files with 792 additions and 560 deletions.
136 changes: 68 additions & 68 deletions src/Starward.Core/EnumExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,58 +25,58 @@ public static string ToDescription(this Enum @enum)
}


public static GameBiz ToGame(this GameBiz biz)
public static GameBizEnum ToGame(this GameBizEnum biz)
{
return (int)biz switch
{
11 or 12 or 13 or 14 => GameBiz.GenshinImpact,
21 or 22 or 24 => GameBiz.StarRail,
>= 31 and <= 37 => GameBiz.Honkai3rd,
41 or 42 or 44 => GameBiz.ZZZ,
_ => GameBiz.None,
11 or 12 or 13 or 14 => GameBizEnum.GenshinImpact,
21 or 22 or 24 => GameBizEnum.StarRail,
>= 31 and <= 37 => GameBizEnum.Honkai3rd,
41 or 42 or 44 => GameBizEnum.ZZZ,
_ => GameBizEnum.None,
};
}


public static string ToGameName(this GameBiz biz)
public static string ToGameName(this GameBizEnum biz)
{
return biz.ToGame() switch
{
GameBiz.GenshinImpact => CoreLang.Game_GenshinImpact,
GameBiz.StarRail => CoreLang.Game_HonkaiStarRail,
GameBiz.Honkai3rd => CoreLang.Game_HonkaiImpact3rd,
GameBiz.ZZZ => CoreLang.Game_ZZZ,
GameBizEnum.GenshinImpact => CoreLang.Game_GenshinImpact,
GameBizEnum.StarRail => CoreLang.Game_HonkaiStarRail,
GameBizEnum.Honkai3rd => CoreLang.Game_HonkaiImpact3rd,
GameBizEnum.ZZZ => CoreLang.Game_ZZZ,
_ => "",
};
}


public static string ToGameServer(this GameBiz biz)
public static string ToGameServer(this GameBizEnum biz)
{
return biz switch
{
GameBiz.hk4e_cn => CoreLang.GameServer_ChinaOfficial,
GameBiz.hk4e_global => CoreLang.GameServer_GlobalOfficial,
GameBiz.hk4e_cloud => CoreLang.GameServer_ChinaCloud,
GameBiz.hk4e_bilibili => CoreLang.GameServer_Bilibili,
GameBiz.hkrpg_cn => CoreLang.GameServer_ChinaOfficial,
GameBiz.hkrpg_global => CoreLang.GameServer_GlobalOfficial,
GameBiz.hkrpg_bilibili => CoreLang.GameServer_Bilibili,
GameBiz.bh3_cn => CoreLang.GameServer_ChinaOfficial,
GameBiz.bh3_global => CoreLang.GameServer_EuropeAmericas,
GameBiz.bh3_jp => CoreLang.GameServer_Japan,
GameBiz.bh3_kr => CoreLang.GameServer_Korea,
GameBiz.bh3_overseas => CoreLang.GameServer_SoutheastAsia,
GameBiz.bh3_tw => CoreLang.GameServer_TraditionalChinese,
GameBiz.nap_cn => CoreLang.GameServer_ChinaOfficial,
GameBiz.nap_global => CoreLang.GameServer_GlobalOfficial,
GameBiz.nap_bilibili => CoreLang.GameServer_Bilibili,
GameBizEnum.hk4e_cn => CoreLang.GameServer_ChinaOfficial,
GameBizEnum.hk4e_global => CoreLang.GameServer_GlobalOfficial,
GameBizEnum.hk4e_cloud => CoreLang.GameServer_ChinaCloud,
GameBizEnum.hk4e_bilibili => CoreLang.GameServer_Bilibili,
GameBizEnum.hkrpg_cn => CoreLang.GameServer_ChinaOfficial,
GameBizEnum.hkrpg_global => CoreLang.GameServer_GlobalOfficial,
GameBizEnum.hkrpg_bilibili => CoreLang.GameServer_Bilibili,
GameBizEnum.bh3_cn => CoreLang.GameServer_ChinaOfficial,
GameBizEnum.bh3_global => CoreLang.GameServer_EuropeAmericas,
GameBizEnum.bh3_jp => CoreLang.GameServer_Japan,
GameBizEnum.bh3_kr => CoreLang.GameServer_Korea,
GameBizEnum.bh3_overseas => CoreLang.GameServer_SoutheastAsia,
GameBizEnum.bh3_tw => CoreLang.GameServer_TraditionalChinese,
GameBizEnum.nap_cn => CoreLang.GameServer_ChinaOfficial,
GameBizEnum.nap_global => CoreLang.GameServer_GlobalOfficial,
GameBizEnum.nap_bilibili => CoreLang.GameServer_Bilibili,
_ => "",
};
}


public static bool IsChinaServer(this GameBiz biz)
public static bool IsChinaServer(this GameBizEnum biz)
{
return (int)biz switch
{
Expand All @@ -86,7 +86,7 @@ public static bool IsChinaServer(this GameBiz biz)
}


public static bool IsGlobalServer(this GameBiz biz)
public static bool IsGlobalServer(this GameBizEnum biz)
{
return (int)biz switch
{
Expand All @@ -96,7 +96,7 @@ 12 or 22 or (>= 32 and <= 36) or 42 => true,
}


public static bool IsBilibiliServer(this GameBiz biz)
public static bool IsBilibiliServer(this GameBizEnum biz)
{
return (int)biz switch
{
Expand All @@ -107,89 +107,89 @@ public static bool IsBilibiliServer(this GameBiz biz)



public static bool IsChinaOfficial(this GameBiz biz)
public static bool IsChinaOfficial(this GameBizEnum biz)
{
return biz switch
{
GameBiz.hk4e_cn or GameBiz.hkrpg_cn or GameBiz.bh3_cn or GameBiz.nap_cn => true,
GameBizEnum.hk4e_cn or GameBizEnum.hkrpg_cn or GameBizEnum.bh3_cn or GameBizEnum.nap_cn => true,
_ => false,
};
}


public static bool IsGlobalOfficial(this GameBiz biz)
public static bool IsGlobalOfficial(this GameBizEnum biz)
{
return biz switch
{
GameBiz.hk4e_global or GameBiz.hkrpg_global or GameBiz.bh3_global or GameBiz.nap_global => true,
GameBiz.bh3_jp or GameBiz.bh3_kr or GameBiz.bh3_overseas or GameBiz.bh3_tw => true,
GameBizEnum.hk4e_global or GameBizEnum.hkrpg_global or GameBizEnum.bh3_global or GameBizEnum.nap_global => true,
GameBizEnum.bh3_jp or GameBizEnum.bh3_kr or GameBizEnum.bh3_overseas or GameBizEnum.bh3_tw => true,
_ => false,
};
}


public static bool IsBilibili(this GameBiz biz)
public static bool IsBilibili(this GameBizEnum biz)
{
return biz switch
{
GameBiz.hk4e_bilibili or GameBiz.hkrpg_bilibili or GameBiz.nap_bilibili => true,
GameBizEnum.hk4e_bilibili or GameBizEnum.hkrpg_bilibili or GameBizEnum.nap_bilibili => true,
_ => false,
};
}


public static bool IsChinaCloud(this GameBiz biz)
public static bool IsChinaCloud(this GameBizEnum biz)
{
return biz switch
{
GameBiz.hk4e_cloud => true,
GameBizEnum.hk4e_cloud => true,
_ => false,
};
}




public static string GetLauncherRegistryKey(this GameBiz biz)
public static string GetLauncherRegistryKey(this GameBizEnum biz)
{
return biz switch
{
GameBiz.hk4e_cn or GameBiz.hk4e_bilibili => GameRegistry.LauncherPath_hk4e_cn,
GameBiz.hk4e_global => GameRegistry.LauncherPath_hk4e_global,
GameBiz.hk4e_cloud => GameRegistry.LauncherPath_hk4e_cloud,
GameBiz.hkrpg_cn or GameBiz.hkrpg_bilibili => GameRegistry.LauncherPath_hkrpg_cn,
GameBiz.hkrpg_global => GameRegistry.LauncherPath_hkrpg_global,
GameBiz.bh3_cn => GameRegistry.LauncherPath_bh3_cn,
GameBiz.bh3_global => GameRegistry.LauncherPath_bh3_global,
GameBiz.bh3_jp => GameRegistry.LauncherPath_bh3_jp,
GameBiz.bh3_kr => GameRegistry.LauncherPath_bh3_kr,
GameBiz.bh3_overseas => GameRegistry.LauncherPath_bh3_overseas,
GameBiz.bh3_tw => GameRegistry.LauncherPath_bh3_tw,
GameBiz.nap_cn or GameBiz.nap_bilibili => GameRegistry.LauncherPath_HYP_cn,
GameBiz.nap_global => GameRegistry.LauncherPath_HYP_os,
GameBizEnum.hk4e_cn or GameBizEnum.hk4e_bilibili => GameRegistry.LauncherPath_hk4e_cn,
GameBizEnum.hk4e_global => GameRegistry.LauncherPath_hk4e_global,
GameBizEnum.hk4e_cloud => GameRegistry.LauncherPath_hk4e_cloud,
GameBizEnum.hkrpg_cn or GameBizEnum.hkrpg_bilibili => GameRegistry.LauncherPath_hkrpg_cn,
GameBizEnum.hkrpg_global => GameRegistry.LauncherPath_hkrpg_global,
GameBizEnum.bh3_cn => GameRegistry.LauncherPath_bh3_cn,
GameBizEnum.bh3_global => GameRegistry.LauncherPath_bh3_global,
GameBizEnum.bh3_jp => GameRegistry.LauncherPath_bh3_jp,
GameBizEnum.bh3_kr => GameRegistry.LauncherPath_bh3_kr,
GameBizEnum.bh3_overseas => GameRegistry.LauncherPath_bh3_overseas,
GameBizEnum.bh3_tw => GameRegistry.LauncherPath_bh3_tw,
GameBizEnum.nap_cn or GameBizEnum.nap_bilibili => GameRegistry.LauncherPath_HYP_cn,
GameBizEnum.nap_global => GameRegistry.LauncherPath_HYP_os,
_ => "HKEY_LOCAL_MACHINE",
};
}



public static string GetGameRegistryKey(this GameBiz biz)
public static string GetGameRegistryKey(this GameBizEnum biz)
{
return biz switch
{
GameBiz.hk4e_cn or GameBiz.hk4e_bilibili => GameRegistry.GamePath_hk4e_cn,
GameBiz.hk4e_global => GameRegistry.GamePath_hk4e_global,
GameBiz.hk4e_cloud => GameRegistry.GamePath_hk4e_cloud,
GameBiz.hkrpg_cn or GameBiz.hkrpg_bilibili => GameRegistry.GamePath_hkrpg_cn,
GameBiz.hkrpg_global => GameRegistry.GamePath_hkrpg_global,
GameBiz.bh3_cn => GameRegistry.GamePath_bh3_cn,
GameBiz.bh3_global => GameRegistry.GamePath_bh3_global,
GameBiz.bh3_jp => GameRegistry.GamePath_bh3_jp,
GameBiz.bh3_kr => GameRegistry.GamePath_bh3_kr,
GameBiz.bh3_overseas => GameRegistry.GamePath_bh3_overseas,
GameBiz.bh3_tw => GameRegistry.GamePath_bh3_tw,
GameBiz.nap_cn or GameBiz.nap_bilibili => GameRegistry.GamePath_nap_cn,
GameBiz.nap_global => GameRegistry.GamePath_nap_global,
GameBizEnum.hk4e_cn or GameBizEnum.hk4e_bilibili => GameRegistry.GamePath_hk4e_cn,
GameBizEnum.hk4e_global => GameRegistry.GamePath_hk4e_global,
GameBizEnum.hk4e_cloud => GameRegistry.GamePath_hk4e_cloud,
GameBizEnum.hkrpg_cn or GameBizEnum.hkrpg_bilibili => GameRegistry.GamePath_hkrpg_cn,
GameBizEnum.hkrpg_global => GameRegistry.GamePath_hkrpg_global,
GameBizEnum.bh3_cn => GameRegistry.GamePath_bh3_cn,
GameBizEnum.bh3_global => GameRegistry.GamePath_bh3_global,
GameBizEnum.bh3_jp => GameRegistry.GamePath_bh3_jp,
GameBizEnum.bh3_kr => GameRegistry.GamePath_bh3_kr,
GameBizEnum.bh3_overseas => GameRegistry.GamePath_bh3_overseas,
GameBizEnum.bh3_tw => GameRegistry.GamePath_bh3_tw,
GameBizEnum.nap_cn or GameBizEnum.nap_bilibili => GameRegistry.GamePath_nap_cn,
GameBizEnum.nap_global => GameRegistry.GamePath_nap_global,
_ => "HKEY_CURRENT_USER",
};
}
Expand Down
27 changes: 14 additions & 13 deletions src/Starward.Core/Gacha/GachaLogClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,26 +116,26 @@ public async Task<long> GetUidByGachaUrlAsync(string gachaUrl)
[SupportedOSPlatform("windows")]
public static string? GetGameInstallPathFromRegistry(GameBiz biz)
{
if (biz is GameBiz.hk4e_cloud)
if (biz == GameBiz.clgm_cn)
{
return Registry.GetValue(REG_KEY_YS_CLOUD, "InstallPath", null) as string;
}
else if (biz is GameBiz.nap_cn)
else if (biz == GameBiz.nap_cn)
{
return Registry.GetValue(@"HKEY_CURRENT_USER\Software\miHoYo\HYP\standalone\1_1\nap_cn\nap_cn", "GameInstallPath", null) as string;
}
else
{
var key = biz switch
var key = biz.Value switch
{
GameBiz.hk4e_cn or GameBiz.hk4e_bilibili => REG_KEY_YS_CN,
GameBiz.hk4e_global => REG_KEY_YS_OS,
GameBiz.hkrpg_cn or GameBiz.hkrpg_bilibili => REG_KEY_SR_CN,
GameBiz.hkrpg_global => REG_KEY_SR_OS,
GameBiz.bh3_cn => REG_KEY_BH3_CN,
GameBiz.bh3_global => REG_KEY_BH3_GL,
GameBiz.bh3_overseas => REG_KEY_BH3_OS,
GameBiz.bh3_tw => REG_KEY_BH3_TW,
GameBiz.bh3_os => REG_KEY_BH3_OS,
GameBiz.bh3_asia => REG_KEY_BH3_TW,
GameBiz.bh3_kr => REG_KEY_BH3_KR,
GameBiz.bh3_jp => REG_KEY_BH3_JP,
_ => throw new ArgumentOutOfRangeException($"Unknown region {biz}"),
Expand All @@ -159,11 +159,11 @@ public async Task<long> GetUidByGachaUrlAsync(string gachaUrl)

public static string GetGachaCacheFilePath(GameBiz gameBiz, string? installPath)
{
if (gameBiz is GameBiz.hk4e_cloud)
if (gameBiz == GameBiz.clgm_cn)
{
return Path.Join(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), @"GenshinImpactCloudGame\config\logs\MiHoYoSDK.log");
}
string file = gameBiz switch
string file = gameBiz.Value switch
{
GameBiz.hk4e_cn or GameBiz.hk4e_bilibili => Path.Join(installPath, WEB_CACHE_PATH_YS_CN),
GameBiz.hk4e_global => Path.Join(installPath, WEB_CACHE_PATH_YS_OS),
Expand All @@ -176,7 +176,7 @@ public static string GetGachaCacheFilePath(GameBiz gameBiz, string? installPath)
{
lastWriteTime = File.GetLastWriteTime(file);
}
string prefix = gameBiz switch
string prefix = gameBiz.Value switch
{
GameBiz.hk4e_cn or GameBiz.hk4e_bilibili => @"YuanShen_Data\webCaches",
GameBiz.hk4e_global => @"GenshinImpact_Data\webCaches",
Expand All @@ -203,9 +203,9 @@ public static string GetGachaCacheFilePath(GameBiz gameBiz, string? installPath)

private static ReadOnlySpan<byte> GetGachaUrlPattern(GameBiz gameBiz)
{
return gameBiz switch
return gameBiz.Value switch
{
GameBiz.hk4e_cn or GameBiz.hk4e_cloud or GameBiz.hk4e_bilibili => SPAN_WEB_PREFIX_YS_CN,
GameBiz.hk4e_cn or GameBiz.clgm_cn or GameBiz.hk4e_bilibili => SPAN_WEB_PREFIX_YS_CN,
GameBiz.hk4e_global => SPAN_WEB_PREFIX_YS_OS,
GameBiz.hkrpg_cn or GameBiz.hkrpg_bilibili => SPAN_WEB_PREFIX_SR_CN,
GameBiz.hkrpg_global => SPAN_WEB_PREFIX_SR_OS,
Expand Down Expand Up @@ -362,7 +362,7 @@ public async Task<GenshinGachaWiki> GetGenshinGachaInfoAsync(GameBiz gameBiz, st
{
lang = LanguageUtil.FilterLanguage(lang);
GenshinGachaWiki wiki;
if (gameBiz.IsChinaServer() && lang is "zh-cn")
if (gameBiz.IsChinaOfficial() && lang is "zh-cn")
{
const string url = "https://api-takumi.mihoyo.com/event/platsimulator/config?gids=2&game=hk4e";
wiki = await CommonGetAsync<GenshinGachaWiki>(url, cancellationToken);
Expand All @@ -381,7 +381,7 @@ public async Task<StarRailGachaWiki> GetStarRailGachaInfoAsync(GameBiz gameBiz,
{
lang = LanguageUtil.FilterLanguage(lang);
StarRailGachaWiki wiki;
if (gameBiz.IsChinaServer() && lang is "zh-cn")
if (gameBiz.IsChinaOfficial() && lang is "zh-cn")
{
const string url = "https://api-takumi.mihoyo.com/event/rpgsimulator/config?game=hkrpg";
wiki = await CommonGetAsync<StarRailGachaWiki>(url, cancellationToken);
Expand Down Expand Up @@ -417,11 +417,12 @@ public async Task<StarRailGachaWiki> GetStarRailGachaInfoAsync(GameBiz gameBiz,


// todo
[Obsolete("Not finished", true)]
public async Task<GenshinGachaWiki> GetZZZGachaInfoAsync(GameBiz gameBiz, string lang, CancellationToken cancellationToken = default)
{
lang = LanguageUtil.FilterLanguage(lang);
GenshinGachaWiki wiki;
if (gameBiz.IsChinaServer() && lang is "zh-cn")
if (gameBiz.IsChinaOfficial() && lang is "zh-cn")
{
const string url = "https://api-takumi.mihoyo.com/event/platsimulator/config?gids=2&game=hk4e";
wiki = await CommonGetAsync<GenshinGachaWiki>(url, cancellationToken);
Expand Down
Loading

0 comments on commit 0f358e1

Please sign in to comment.