Beispiel #1
0
        public Player(byte[] data, GameReader reader)
        {
            GCHandle gcHandle = GCHandle.Alloc(data, GCHandleType.Pinned);
            var      plr      = (PlayerInfo)Marshal.PtrToStructure(gcHandle.AddrOfPinnedObject(), typeof(PlayerInfo));

            gcHandle.Free();

            this.ColorId      = plr.ColorId;
            this.Disconnected = plr.Disconnected == 1;
            this.HatId        = plr.HatId;
            this.Name         = reader.ReadString((IntPtr)plr.PlayerName);
            this.Id           = plr.PlayerId;
            this.IsImposter   = plr.IsImpostor == 1;
            this.IsDead       = plr.IsDead == 1;

            this.ObjectPtr = plr._object;
            this.TaskPtr   = plr.Tasks;

            var nullRef = ObjectPtr == IntPtr.Zero;

            this.IsLocal = nullRef ? false : reader.ReadMemory <int>(this.ObjectPtr, reader.Offsets.offsets.player.isLocal) != 0;

            var posOffsets = IsLocal ? new List <List <int> >
            {
                reader.Offsets.offsets.player.localX,
                reader.Offsets.offsets.player.localY
            } : new List <List <int> >
            {
                reader.Offsets.offsets.player.remoteX,
                reader.Offsets.offsets.player.remoteY
            };

            this.X = nullRef ? 0 :reader.ReadMemory <float>(this.ObjectPtr, posOffsets[0]);
            this.Y = nullRef ? 0 :reader.ReadMemory <float>(this.ObjectPtr, posOffsets[1]);
        }
        public void Update(AmongUsState previous, GameReader reader)
        {
            if (previous.State == GameState.Menu &&
                this.State == GameState.Lobby &&
                (previous.allPlayers == reader.AllPlayers || this.Players.Count == 1 || this.Players.Any(x => x.IsLocal)))
            {
                this.State = GameState.Menu;
            }

            allPlayers = reader.AllPlayers;
        }
Beispiel #3
0
        public async Task Run()
        {
            Logger.Create();
            Logger.Write("Starting init of services...", Logger.Severity.Core);

            reader = new GameReader();

            await reader.Attach();

            reader.Start();

            Logger.Write("Starting swissbot connections...", Logger.Severity.Core);

            swissbot = new Swissbot();

            await Task.Delay(-1);
        }
        public AmongUsState(GameReader reader)
        {
            // Game state
            var st = reader.GameState;

            switch (st)
            {
            case 0:
                this.State      = GameState.Menu;
                ExiledCausesEnd = false;
                break;

            case 1 or 3:
                this.State      = GameState.Lobby;
                ExiledCausesEnd = false;
                break;

            default:
                if (this.ExiledCausesEnd)
                {
                    State = GameState.Lobby;
                }
                else if (reader.MeetingHudState < 4)
                {
                    State = GameState.Discussion;
                }
                else
                {
                    State = GameState.Tasks;
                }
                break;
            }

            // GameCode
            this.GameCode = reader.GameCode;

            // Player count
            this.PlayerCount = reader.PlayerCount;

            // Host
            this.HostId = reader.ReadMemory <uint>(reader.GameAssemblyAddr, reader.Offsets.offsets.hostId);

            // Client
            this.ClientId = reader.ReadMemory <uint>(reader.GameAssemblyAddr, reader.Offsets.offsets.clientId);

            this.IsHost = HostId == ClientId;

            // players
            var PlayerAddAdr = reader.AllPlayers + (uint)reader.Offsets.offsets.playerAddrPtr;

            for (int i = 0; i != this.PlayerCount; i++)
            {
                var adr = reader.OffsetAddress((IntPtr)PlayerAddAdr, reader.Offsets.offsets.player.offsets);

                byte[] buffer = new byte[Marshal.SizeOf <PlayerInfo>()];
                GameReader.ReadProcessMemory(reader.amongUsHandle, adr.address + adr.last, buffer, buffer.Length, out var read);

                var plr = new Player(buffer, reader);

                this.Players.Add(plr);

                if (plr.IsImposter)
                {
                    this.Imposters++;
                }
                else
                {
                    this.Crewmates++;
                }

                if (plr.IsDead)
                {
                    this.DeadPlayers++;
                }

                PlayerAddAdr += 4;
            }

            if (Imposters == 0 || Imposters >= Crewmates)
            {
                this.ExiledCausesEnd = true;
                this.State           = GameState.Lobby;
            }
        }