public static async Task WriteBytesLargeAsync(this IConsoleConnectionAsync connection, byte[] data, uint offset, int chunkSize, CancellationToken token) { int byteCount = data.Length; for (int i = 0; i < byteCount; i += chunkSize) { await connection.WriteBytesAsync(SubArray(data, i, chunkSize), offset + (uint)i, token).ConfigureAwait(false); } }
public static async Task <byte[]> ReadBytesLargeAsync(this IConsoleConnectionAsync connection, uint offset, int length, int chunkSize, CancellationToken token) { List <byte> read = new List <byte>(); for (int i = 0; i < length; i += chunkSize) { read.AddRange(await connection.ReadBytesAsync(offset + (uint)i, Math.Min(chunkSize, length - i), token).ConfigureAwait(false)); } return(read.ToArray()); }
private static async Task <string[]> FetchPlayerNames(IConsoleConnectionAsync connection, uint rootInventoryOffset, uint playerSize, CancellationToken token) { List <string> toRet = new List <string>(); for (int i = 0; i < 8; ++i) { ulong address = OffsetHelper.getPlayerIdAddress(rootInventoryOffset) - 0xB8 + 0x20 + (playerSize * (ulong)i); byte[] pName = await connection.ReadBytesAsync((uint)address, 20, token).ConfigureAwait(false); if (!isZeroArray(pName)) { string name = StringUtil.GetString(pName, 0, 10); toRet.Add(name); } } return(toRet.ToArray()); }
public static async Task <Villager2[]> GetVillagerShells(IConsoleConnectionAsync connection, bool log, CancellationToken token) { // villager shells var villagers = new Villager2[10]; for (int i = 0; i < 10; ++i) { var villagerBytes = await connection.ReadBytesAsync((uint)(OffsetHelper.VillagerAddress + (uint)(i * Villager2.SIZE)), 0x3, token).ConfigureAwait(false); villagers[i] = new Villager2(villagerBytes); if (log && villagers[i].Species != (byte)VillagerSpecies.non) { LogUtil.LogInfo($"Found villager: {GameInfo.Strings.GetVillager(villagers[i].InternalName)}", nameof(VillagerHelper)); } } return(villagers); }
private static void LogError(IConsoleConnectionAsync connection, Task task) { if (task.Exception == null) { connection.LogError("Bot has crashed due to an unknown error."); return; } connection.LogError("Bot has crashed due to an error:"); foreach (var ex in task.Exception.InnerExceptions) { connection.LogError(ex.Message); var st = ex.StackTrace; if (st != null) { connection.LogError(st); } } }
protected RoutineExecutor(IConsoleBotManaged <IConsoleConnection, IConsoleConnectionAsync> cfg) { Config = (T)cfg; Connection = cfg.CreateAsynchronous(); }