Skip to content

Android Support #1570

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 9 commits into
base: dev_2.3.0
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions Modules/BanManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ namespace TOHE;

public static class BanManager
{
private const string DenyNameListPath = "./TOHE-DATA/DenyName.txt";
private const string BanListPath = "./TOHE-DATA/BanList.txt";
private const string ModeratorListPath = "./TOHE-DATA/Moderators.txt";
private const string VIPListPath = "./TOHE-DATA/VIP-List.txt";
private const string WhiteListListPath = "./TOHE-DATA/WhiteList.txt";
private static readonly string DenyNameListPath = @$"{Main.TOHE_Initial_Path}/DenyName.txt";
private static readonly string BanListPath = @$"{Main.TOHE_Initial_Path}/BanList.txt";
private static readonly string ModeratorListPath = @$"{Main.TOHE_Initial_Path}/Moderators.txt";
private static readonly string VIPListPath = @$"{Main.TOHE_Initial_Path}/VIP-List.txt";
private static readonly string WhiteListListPath = @$"{Main.TOHE_Initial_Path}/WhiteList.txt";
//private static List<string> EACList = []; // Don't make it read-only
public static List<string> TempBanWhiteList = []; //To prevent writing to ban list
public static List<Dictionary<string, System.Text.Json.JsonElement>> EACDict = [];
public static void Init()
{
try
{
Directory.CreateDirectory("TOHE-DATA");
Directory.CreateDirectory(Main.TOHE_DATA_FOLDER_NAME);

if (!File.Exists(BanListPath))
{
Expand Down Expand Up @@ -115,7 +115,7 @@ public static bool CheckDenyNamePlayer(PlayerControl player, string name)

try
{
Directory.CreateDirectory("TOHE-DATA");
Directory.CreateDirectory(Main.TOHE_DATA_FOLDER_NAME);
if (!File.Exists(DenyNameListPath)) File.Create(DenyNameListPath).Close();
using StreamReader sr = new(DenyNameListPath);
string line;
Expand Down Expand Up @@ -198,7 +198,7 @@ public static bool CheckBanList(string code, string hashedpuid = "")

try
{
Directory.CreateDirectory("TOHE-DATA");
Directory.CreateDirectory(Main.TOHE_DATA_FOLDER_NAME);
if (!File.Exists(BanListPath)) File.Create(BanListPath).Close();
using StreamReader sr = new(BanListPath);
string line;
Expand Down Expand Up @@ -261,4 +261,4 @@ public static void Postfix(BanMenu __instance, int clientId)
if (!BanManager.CheckBanList(recentClient?.FriendCode, recentClient?.GetHashedPuid()))
__instance.BanButton.GetComponent<ButtonRolloverHandler>().SetEnabledColors();
}
}
}
2 changes: 1 addition & 1 deletion Modules/CustomRolesHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace TOHE;
public static class CustomRolesHelper
{
public static readonly CustomRoles[] AllRoles = EnumHelper.GetAllValues<CustomRoles>();
public static Dictionary<CustomRoles, Type> DuplicatedRoles;
public static Dictionary<CustomRoles, Type> DuplicatedRoles = [];
public static readonly Custom_Team[] AllRoleTypes = EnumHelper.GetAllValues<Custom_Team>();
public static CustomRoles GetVNRole(this CustomRoles role) // RoleBase: Impostor, Shapeshifter, Crewmate, Engineer, Scientist
{
Expand Down
4 changes: 2 additions & 2 deletions Modules/DebugModeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public static class DebugModeManager
// これが有効の時、通常のゲームに支障のないデバッグ機能(詳細ログ・ゲーム外でのデバッグ表示など)が有効化される。
// また、ゲーム内オプションでデバッグモードを有効化することができる。
public static bool AmDebugger { get; private set; } =
#if DEBUG
#if DEBUGWINDOWS || DEBUGANDROID
true; //Change this to true if u need to debug
#else
false;
Expand All @@ -30,4 +30,4 @@ public static void SetupCustomOption()
.SetHeader(true)
.SetHidden(!AmDebugger);
}
}
}
4 changes: 2 additions & 2 deletions Modules/DevManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class DevUser(string code = "", string color = "null", string userType =
//public string GetTag() => Color == "null" ? $"<size=1.2>{Tag}</size>\r\n" : $"<color={Color}><size=1.2>{(Tag == "#Dev" ? Translator.GetString("Developer") : Tag)}</size></color>\r\n";
public string GetTag()
{
string tagColorFilePath = @$"./TOHE-DATA/Tags/SPONSOR_TAGS/{Code}.txt";
string tagColorFilePath = @$"{Main.TOHE_Initial_Path}/Tags/SPONSOR_TAGS/{Code}.txt";

if (Color == "null" || Color == string.Empty) return $"<size=1.2>{Tag}</size>\r\n";
var startColor = Color.TrimStart('#');
Expand All @@ -35,7 +35,7 @@ public string GetTag()
}
//public string GetTag()
//{
// string tagColorFilePath = @$"./TOHE-DATA/Tags/SPONSOR_TAGS/{Code}.txt";
// string tagColorFilePath = Main.StartPath + "Tags/SPONSOR_TAGS/{Code}.txt";

// if (Color == "null" || Color == string.Empty) return $"<size=1.2>{Tag}</size>\r\n";
// var startColor = "FFFF00";
Expand Down
6 changes: 3 additions & 3 deletions Modules/ModUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -273,11 +273,11 @@ public static bool NewVersionCheck()
try
{
var fileName = Assembly.GetExecutingAssembly().Location;
if (Directory.Exists("TOH_DATA") && File.Exists(@"./TOHE-DATA/BanWords.txt"))
if (Directory.Exists(Main.TOHE_DATA_FOLDER_NAME) && File.Exists(@$"{Main.TOHE_Initial_Path}/BanWords.txt"))
{
DirectoryInfo di = new("TOH_DATA");
DirectoryInfo di = new(Main.TOHE_DATA_FOLDER_NAME);
di.Delete(true);
Logger.Warn("Deleting old data´╝ÜTOH_DATA", "NewVersionCheck");
Logger.Warn($"Deleting old data '╝{Main.TOHE_DATA_FOLDER_NAME}'", "NewVersionCheck");
}
}
catch (Exception ex)
Expand Down
2 changes: 1 addition & 1 deletion Modules/OptionSaver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace TOHE.Modules;
public static class OptionSaver
{
[Obfuscation(Exclude = true)]
private static readonly DirectoryInfo SaveDataDirectoryInfo = new("./TOHE-DATA/SaveData/");
private static readonly DirectoryInfo SaveDataDirectoryInfo = new(@$"{Main.TOHE_Initial_Path}/SaveData/");
[Obfuscation(Exclude = true)]
private static readonly FileInfo OptionSaverFileInfo = new($"{SaveDataDirectoryInfo.FullName}/Options.json");

Expand Down
4 changes: 2 additions & 2 deletions Modules/SpamManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace TOHE;

public static class SpamManager
{
//private static readonly string BANEDWORDS_FILE_PATH = "./TOHE-DATA/BanWords.txt";
//private static readonly string BANEDWORDS_FILE_PATH = @$"{Main.TOHE_Initial_Path}/BanWords.txt";
//public static List<string> BanWords = new();
//public static void Init()
//{
Expand All @@ -17,7 +17,7 @@ public static class SpamManager
// {
// try
// {
// if (!Directory.Exists(@"TOHE-DATA")) Directory.CreateDirectory(@"TOHE-DATA");
// if (!Directory.Exists(Main.TOHE_DATA_FOLDER_NAME)) Directory.CreateDirectory(Main.TOHE_DATA_FOLDER_NAME);
// if (File.Exists(@"./BanWords.txt")) File.Move(@"./BanWords.txt", BANEDWORDS_FILE_PATH);
// else
// {
Expand Down
10 changes: 5 additions & 5 deletions Modules/TagManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace TOHE;

public static class TagManager
{
private static readonly string TAGS_FILE_PATH = "./TOHE-DATA/Tags";
private static readonly string TAGS_FILE_PATH = @$"{Main.TOHE_Initial_Path}/Tags";

public static void Init()
{
Expand All @@ -17,13 +17,13 @@ public static void CreateIfNotExists()
{
try
{
if (!Directory.Exists(@"TOHE-DATA/Tags")) Directory.CreateDirectory(@"TOHE-DATA/Tags");
if (!Directory.Exists(TAGS_FILE_PATH)) Directory.CreateDirectory(TAGS_FILE_PATH);
var defaultTagMsg = GetResourcesTxt($"TOHE.Resources.Config.TagTemplate.txt");
if (!File.Exists(@"./TOHE-DATA/Tags/Tag_Template.txt")) // Default tag
if (!File.Exists(@$"{TAGS_FILE_PATH}/Tag_Template.txt")) // Default tag
{
using FileStream fs = File.Create(@"./TOHE-DATA/Tags/Tag_Template.txt");
using FileStream fs = File.Create(@$"{TAGS_FILE_PATH}/Tag_Template.txt");
}
File.WriteAllText(@"./TOHE-DATA/Tags/Tag_Template.txt", defaultTagMsg); // Overwriting default template
File.WriteAllText(@$"{TAGS_FILE_PATH}/Tag_Template.txt", defaultTagMsg); // Overwriting default template
}
catch (Exception ex)
{
Expand Down
12 changes: 6 additions & 6 deletions Modules/TemplateManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace TOHE;

public static class TemplateManager
{
private static readonly string TEMPLATE_FILE_PATH = "./TOHE-DATA/template.txt";
private static readonly string TEMPLATE_FILE_PATH = @$"{Main.TOHE_Initial_Path}/template.txt";
private static readonly Dictionary<string, Func<string>> _replaceDictionaryNormalOptions = new()
{
["RoomCode"] = () => InnerNet.GameCode.IntToGameName(AmongUsClient.Instance.GameId),
Expand Down Expand Up @@ -105,14 +105,14 @@ var lang when lang.StartsWith("it") => "Italian",
_ => "English"
};
else fileName = "English";
if (!Directory.Exists(@"TOHE-DATA")) Directory.CreateDirectory(@"TOHE-DATA");
if (!Directory.Exists(Main.TOHE_DATA_FOLDER_NAME)) Directory.CreateDirectory(Main.TOHE_DATA_FOLDER_NAME);
var defaultTemplateMsg = GetResourcesTxt($"TOHE.Resources.Config.template.{fileName}.txt");
if (!File.Exists(@"./TOHE-DATA/Default_Teamplate.txt")) //default template
if (!File.Exists(@$"{Main.TOHE_Initial_Path}/Default_Teamplate.txt")) //default template
{
Logger.Warn("Creating Default_Template.txt", "TemplateManager");
using FileStream fs = File.Create(@"./TOHE-DATA/Default_Teamplate.txt");
using FileStream fs = File.Create(@$"{Main.TOHE_Initial_Path}/Default_Teamplate.txt");
}
File.WriteAllText(@"./TOHE-DATA/Default_Teamplate.txt", defaultTemplateMsg); //overwriting default template
File.WriteAllText(@$"{Main.TOHE_Initial_Path}/Default_Teamplate.txt", defaultTemplateMsg); //overwriting default template
if (!File.Exists(TEMPLATE_FILE_PATH))
{
if (File.Exists(@"./template.txt")) File.Move(@"./template.txt", TEMPLATE_FILE_PATH);
Expand Down Expand Up @@ -234,4 +234,4 @@ private static string TryGetTitle(string Text, out bool Contains)

return title;
}
}
}
14 changes: 7 additions & 7 deletions Modules/Translator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ namespace TOHE;

public static class Translator
{
public static Dictionary<string, Dictionary<int, string>> translateMaps;
public const string LANGUAGE_FOLDER_NAME = Main.LANGUAGE_FOLDER_NAME;
public static Dictionary<string, Dictionary<int, string>> translateMaps = [];
public static readonly string LANGUAGE_FOLDER_NAME = Main.LANGUAGE_FOLDER_NAME;
private static readonly Dictionary<SupportedLangs, Dictionary<CustomRoles, string>> ActualRoleNames = [];
public static readonly Dictionary<CustomRoles, HashSet<string>> CrossLangRoleNames = [];
public static void Init()
Expand All @@ -27,7 +27,7 @@ public static void LoadLangs()
// Get the directory containing the JSON files (e.g., TOHE.Resources.Lang)
string jsonDirectory = "TOHE.Resources.Lang";
// Get the assembly containing the resources
var assembly = System.Reflection.Assembly.GetExecutingAssembly();
var assembly = Assembly.GetExecutingAssembly();
string[] jsonFileNames = GetJsonFileNames(assembly, jsonDirectory);

translateMaps = [];
Expand Down Expand Up @@ -277,27 +277,27 @@ public static string GetString(string str, SupportedLangs langId, bool showInval
var res = showInvalid ? $"<INVALID:{str}>" : str;
try
{
if (translateMaps.TryGetValue(str, out var dic) && (!dic.TryGetValue((int)langId, out res) || res == "" || (langId is not SupportedLangs.SChinese and not SupportedLangs.TChinese && Regex.IsMatch(res, @"[\u4e00-\u9fa5]") && res == GetString(str, SupportedLangs.SChinese)))) //strに該当する&無効なlangIdかresが空
if (translateMaps.TryGetValue(str, out var dic) && (!dic.TryGetValue((int)langId, out res) || string.IsNullOrEmpty(res) || (langId is not SupportedLangs.SChinese and not SupportedLangs.TChinese && Regex.IsMatch(res, @"[\u4e00-\u9fa5]") && res == GetString(str, SupportedLangs.SChinese)))) //strに該当する&無効なlangIdかresが空
{
if (langId == SupportedLangs.English) res = $"*{str}";
else res = GetString(str, SupportedLangs.English);
}
if (!translateMaps.ContainsKey(str)) //translateMapsにない場合、StringNamesにあれば取得する
{
var stringNames = EnumHelper.GetAllValues<StringNames>().Where(x => x.ToString() == str).ToArray();
if (stringNames != null && stringNames.Any())
if (stringNames != null && stringNames.Length != 0)
res = GetString(stringNames.FirstOrDefault());
}
}
catch (Exception Ex)
{
Logger.Fatal($"Error oucured at [{str}] in String.csv", "Translator");
Logger.Fatal($"Error oucured at [{str}] in en_US.json - langId {langId}", "Translator");
Logger.Error("Here was the error:\n" + Ex.ToString(), "Translator");
}
return res;
}
public static string GetString(StringNames stringName)
=> DestroyableSingleton<TranslationController>.Instance.GetString(stringName, new Il2CppReferenceArray<Il2CppSystem.Object>(0));
=> TranslationController.Instance.GetString(stringName);
public static string GetRoleString(string str, bool forUser = true)
{
var CurrentLanguage = TranslationController.Instance.currentLanguage.languageID;
Expand Down
12 changes: 6 additions & 6 deletions Modules/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1367,14 +1367,14 @@ public static void SendMessage(string text, byte sendTo = byte.MaxValue, string
public static bool IsPlayerModerator(string friendCode)
{
if (friendCode == "") return false;
var friendCodesFilePath = @"./TOHE-DATA/Moderators.txt";
var friendCodesFilePath = @$"{Main.TOHE_Initial_Path}/Moderators.txt";
var friendCodes = File.ReadAllLines(friendCodesFilePath);
return friendCodes.Any(code => code.Contains(friendCode));
}
public static bool IsPlayerVIP(string friendCode)
{
if (friendCode == "") return false;
var friendCodesFilePath = @"./TOHE-DATA/VIP-List.txt";
var friendCodesFilePath = @$"{Main.TOHE_Initial_Path}/VIP-List.txt";
var friendCodes = File.ReadAllLines(friendCodesFilePath);
return friendCodes.Any(code => code.Contains(friendCode));
}
Expand Down Expand Up @@ -1497,7 +1497,7 @@ void SetRealName()
{
if (IsPlayerVIP(player.FriendCode))
{
string colorFilePath = @$"./TOHE-DATA/Tags/VIP_TAGS/{player.FriendCode}.txt";
string colorFilePath = @$"{Main.TOHE_Initial_Path}/Tags/VIP_TAGS/{player.FriendCode}.txt";
//static color
if (!Options.GradientTagsOpt.GetBool())
{
Expand Down Expand Up @@ -1541,7 +1541,7 @@ void SetRealName()
{
if (IsPlayerModerator(player.FriendCode))
{
string colorFilePath = @$"./TOHE-DATA/Tags/MOD_TAGS/{player.FriendCode}.txt";
string colorFilePath = @$"{Main.TOHE_Initial_Path}/Tags/MOD_TAGS/{player.FriendCode}.txt";
//static color
if (!Options.GradientTagsOpt.GetBool())
{
Expand Down Expand Up @@ -1649,7 +1649,7 @@ public static bool IsSameTeammate(this PlayerControl player, PlayerControl targe

return false;
}
public static IEnumerable<t> GetRoleBasesByType<t>() where t : RoleBase
public static IEnumerable<TRole> GetRoleBasesByType<TRole>() where TRole : RoleBase
{
try
{
Expand All @@ -1658,7 +1658,7 @@ public static IEnumerable<t> GetRoleBasesByType<t>() where t : RoleBase
if (cache.Any())
{
var Get = cache.Select(x => x.RoleClass);
return Get.OfType<t>().Any() ? Get.OfType<t>() : null;
return Get.OfType<TRole>().Any() ? Get.OfType<TRole>() : null;
}
}
catch (Exception exx)
Expand Down
8 changes: 4 additions & 4 deletions Patches/ChatCommandPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ namespace TOHE;
[HarmonyPatch(typeof(ChatController), nameof(ChatController.SendChat))]
internal class ChatCommands
{
private static readonly string modLogFiles = @"./TOHE-DATA/ModLogs.txt";
private static readonly string modTagsFiles = @"./TOHE-DATA/Tags/MOD_TAGS";
private static readonly string sponsorTagsFiles = @"./TOHE-DATA/Tags/SPONSOR_TAGS";
private static readonly string vipTagsFiles = @"./TOHE-DATA/Tags/VIP_TAGS";
private static readonly string modLogFiles = @$"{Main.TOHE_Initial_Path}/ModLogs.txt";
private static readonly string modTagsFiles = @$"{Main.TOHE_Initial_Path}/Tags/MOD_TAGS";
private static readonly string sponsorTagsFiles = @$"{Main.TOHE_Initial_Path}/Tags/SPONSOR_TAGS";
private static readonly string vipTagsFiles = @$"{Main.TOHE_Initial_Path}/Tags/VIP_TAGS";

private static readonly Dictionary<char, int> Pollvotes = [];
private static readonly Dictionary<char, string> PollQuestions = [];
Expand Down
4 changes: 2 additions & 2 deletions Patches/ClientOptionsPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public static class OptionsMenuBehaviourStartPatch
private static ClientOptionItem EnableCustomDecorations;
private static ClientOptionItem SwitchVanilla;

#if DEBUG
#if DEBUGWINDOWS || DEBUGANDROID
private static ClientOptionItem VersionCheat;
private static ClientOptionItem GodMode;
private static ClientOptionItem AutoRehost;
Expand Down Expand Up @@ -152,7 +152,7 @@ static void SwitchVanillaButtonToggle()
}
}

#if DEBUG
#if DEBUGWINDOWS || DEBUGANDROID
if (EOSManager.Instance.friendCode.GetDevUser().DeBug)
{
if ((VersionCheat == null || VersionCheat.ToggleButton == null) && DebugModeManager.AmDebugger)
Expand Down
2 changes: 1 addition & 1 deletion Patches/ClientPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ internal class RunLoginPatch
public static bool isAllowedOnline = false;
public static void Prefix(ref bool canOnline)
{
#if DEBUG
#if DEBUGWINDOWS || DEBUGANDROID
if (ClickCount < 10) canOnline = true;
if (ClickCount >= 10) ModUpdater.forceUpdate = false;
#endif
Expand Down
10 changes: 5 additions & 5 deletions Patches/CredentialsPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,18 +145,18 @@ private static void Postfix(VersionShower __instance)
Main.credentialsText = $"<size=70%><size=85%><color={Main.ModColor}>{Main.ModName}</color> v{Main.PluginDisplayVersion}</size>";
var buildtype = "";

#if RELEASE
#if RELEASEWINDOWS || RELEASEANDROID
Main.credentialsText += $"\r\n<color=#a54aff>By <color=#f34c50>The Enhanced Network</color>";
buildtype = "Release";
#endif

#if CANARY
Main.credentialsText += $"\r\n<color=#ffc0cb>Canary:</color><color=#f34c50>{ThisAssembly.Git.Branch}</color>(<color=#ffc0cb>{ThisAssembly.Git.Commit}</color>)";
#if BETAWINDOWS || BETAANDROID
Main.credentialsText += $"\r\n<color=#ffc0cb>Beta:</color><color=#f34c50>{ThisAssembly.Git.Branch}</color>(<color=#ffc0cb>{ThisAssembly.Git.Commit}</color>)";
Main.credentialsText += $"\r\n<color=#a54aff>By <color=#f34c50>The Enhanced Network</color>";
buildtype = "Canary";
buildtype = "Beta";
#endif

#if DEBUG
#if DEBUGWINDOWS || DEBUGANDROID
Main.credentialsText += $"\r\n<color=#ffc0cb>Debug:</color><color=#f34c50>{ThisAssembly.Git.Branch}</color>(<color=#ffc0cb>{ThisAssembly.Git.Commit}</color>)";
Main.credentialsText += $"\r\n<color=#a54aff>By <color=#f34c50>The Enhanced Network</color>";
buildtype = "Debug";
Expand Down
2 changes: 1 addition & 1 deletion Patches/GameOptionsMenuPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ public static void ReCreateSettings(GameOptionsMenu __instance)
}
private static BaseGameSetting GetSetting(OptionItem item)
{
static t CreateAndInvoke<t>(Func<t> func) where t : BaseGameSetting
static TSetting CreateAndInvoke<TSetting>(Func<TSetting> func) where TSetting : BaseGameSetting
{
return func.Invoke();
}
Expand Down
Loading