Esempio n. 1
0
 void OnDestroy()
 {
     if (ProcessReader != null)
     {
         ProcessReader.Close();
     }
 }
Esempio 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);
    }
Esempio n. 3
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);
    }
Esempio n. 4
0
    bool TryGetMemoryReader(out ProcessMemoryReader reader)
    {
        int processId = SearchDosBoxProcess();

        if (processId != -1)
        {
            reader             = new ProcessMemoryReader(processId);
            reader.BaseAddress = reader.SearchFor16MRegion();
            if (reader.BaseAddress != -1)
            {
                return(true);
            }

            reader.Close();
        }

        reader = null;
        return(false);
    }
Esempio n. 5
0
 public void UnlinkDosBox()
 {
     ProcessReader.Close();
     ProcessReader  = null;
     RightText.text = string.Empty;
 }