Exemplo n.º 1
0
    public bool LinkToDosBOX(int floor, int room)
    {
        int[] processIds = Process.GetProcesses()
                           .Where(x =>
        {
            string name;
            try
            {
                name = x.ProcessName;
            }
            catch
            {
                name = string.Empty;
            }
            return(name.StartsWith("DOSBOX", StringComparison.InvariantCultureIgnoreCase));
        })
                           .Select(x => x.Id)
                           .ToArray();

        if (!processIds.Any())
        {
            RightText.text = "Cannot find DOSBOX process";
            return(false);
        }

        //search player position in DOSBOX processes
        int patternIndex = GetComponent <RoomLoader>().DetectGame() - 1;

        foreach (int processId in processIds)
        {
            ProcessMemoryReader reader = new ProcessMemoryReader(processId);
            foreach (var pattern in PlayerInitialPosition[patternIndex])
            {
                long address = reader.SearchForBytePattern(pattern);
                if (address != -1)
                {
                    //force reload
                    linkfloor = floor;
                    linkroom  = room;

                    memoryAddress = address + MemoryOffsets[patternIndex];
                    ProcessReader = reader;
                    memory        = new byte[ActorStructSize[patternIndex] * 50];
                    dosBoxPattern = patternIndex;

                    //vars
                    if (patternIndex == 0)                     //AITD1 only
                    {
                        GetComponent <Vars>().SearchForPatterns(reader);
                    }
                    return(true);
                }
            }

            reader.Close();
        }

        RightText.text = "Cannot find player data in DOSBOX process memory.";
        return(false);
    }
Exemplo n.º 2
0
    bool SearchForBytePattern(int patternIndex, out int processId, out long address)
    {
        int[] processIds = GetAllDOSBOXProcesses();
        if (!processIds.Any())
        {
            RightText.text = "Cannot find DOSBOX process";
            processId      = -1;
            address        = -1;
            return(false);
        }

        foreach (int pid in processIds)
        {
            ProcessMemoryReader reader = new ProcessMemoryReader(pid);
            var  pattern      = PlayerInitialPosition[patternIndex];
            long foundAddress = reader.SearchForBytePattern(pattern, true);
            if (foundAddress != -1)
            {
                processId = pid;
                address   = foundAddress - 28 - playerInitialSlot[patternIndex] * actorStructSize[patternIndex];

                reader.Close();
                return(true);
            }

            reader.Close();
        }

        processId      = -1;
        address        = -1;
        RightText.text = "Cannot find player data in DOSBOX process memory.";
        return(false);
    }
Exemplo n.º 3
0
    public bool LinkToDosBOX(int floor, int room, int detectedGame)
    {
        //search player position in DOSBOX processes
        int patternIndex = detectedGame - 1;

        int processId = Shared.ProcessId;

        if (processId == -1)
        {
            long memoryAddress;
            if (!SearchForBytePattern(patternIndex, out processId, out memoryAddress))
            {
                return(false);
            }

            Shared.ProcessId          = processId;
            Shared.ActorsMemoryAdress = memoryAddress;
            ProcessReader             = new ProcessMemoryReader(processId);

            //vars
            if (patternIndex == 0)             //AITD1 only
            {
                Shared.ObjectMemoryAddress = ProcessReader.SearchForBytePattern(objectMemoryPattern);

                if (Shared.ObjectMemoryAddress != -1)
                {
                    Shared.ObjectMemoryAddress -= 4 + 52;

                    //adjust actor offset (needed if player has been swapped)
                    ProcessReader.Read(memory, Shared.ObjectMemoryAddress + 52, 2);
                    int playerSlotID = memory.ReadShort(0);
                    Shared.ActorsMemoryAdress += (1 - playerSlotID) * 160;
                }
            }
        }
        else
        {
            ProcessReader = new ProcessMemoryReader(processId);
        }

        //force reload
        linkfloor = floor;
        linkroom  = room;

        dosBoxPattern = patternIndex;

        //check if CDROM/floppy version (AITD1 only)
        byte[] cdPattern = ASCIIEncoding.ASCII.GetBytes("CD Not Found");
        IsCDROMVersion = detectedGame == 1 && ProcessReader.SearchForBytePattern(cdPattern) != -1;

        RightText.text = string.Empty;
        return(true);
    }
Exemplo n.º 4
0
    public bool FindActorsAddressTimeGate()
    {
        //scan range: 0x110000 (extended memory) - 0x300000 (3MB)
        byte[] pattern     = Encoding.ASCII.GetBytes("HARD_DEC");
        int    dataSegment = ProcessReader.SearchForBytePattern(0x110000, 0x1F0000, buffer => Utils.IndexOf(buffer, pattern, 28, 16));

        if (dataSegment != -1)
        {
            ProcessReader.Read(memory, dataSegment + actorArrayAddress[6], 4);
            var result = memory.ReadUnsignedInt(0);
            if (result != 0)
            {
                actorsAddress              = 0;
                ProcessReader.BaseAddress += result;
                return(true);
            }
        }

        return(false);
    }
Exemplo n.º 5
0
 public void SearchForPatterns(ProcessMemoryReader reader)
 {
     varsMemoryAddress  = reader.SearchForBytePattern(varsMemoryPattern);
     cvarsMemoryAddress = reader.SearchForBytePattern(cvarsMemoryPattern);
 }