[v0.1.1] use psutil to find pid of dolphin
This commit is contained in:
parent
2527142f07
commit
b891a9496a
4 changed files with 21 additions and 51 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -2,3 +2,4 @@ __pycache__/
|
|||
*.egg-info/
|
||||
/dist/
|
||||
/build/
|
||||
/.venv*/
|
||||
|
|
|
@ -1,4 +1,8 @@
|
|||
# Change Log
|
||||
## \[v0.1.1] use psutil to find pid of dolphin (2022/06/26)
|
||||
Use psutil to achieve cross-platform pid finding.
|
||||
This also fixes the dependency issue on Linux.
|
||||
|
||||
## \[v0.1.0] pack into one PyPI package (2022/06/25)
|
||||
Complete all basic functions, including:
|
||||
- find dolphin, init shared memory
|
||||
|
|
|
@ -1,14 +1,15 @@
|
|||
[metadata]
|
||||
name = sup-dolphin-memory-lib
|
||||
version = 0.1.0
|
||||
version = 0.1.1
|
||||
author = sup39
|
||||
author_email = sms@sup39.dev
|
||||
description = A Python library for reading and writing the memory of an emulated game in Dolphin
|
||||
long_description = file: README.md
|
||||
long_description_content_type = text/markdown
|
||||
url = https://github.com/sup39/dolphin-memory-lib
|
||||
url = https://github.com/sup39/sup-dolphin-memory-lib
|
||||
license = MIT
|
||||
project_urls =
|
||||
Bug Tracker = https://github.com/sup39/dolphin-memory-lib/issues
|
||||
Bug Tracker = https://github.com/sup39/sup-dolphin-memory-lib/issues
|
||||
classifiers =
|
||||
Programming Language :: Python :: 3
|
||||
License :: OSI Approved :: MIT License
|
||||
|
@ -20,6 +21,7 @@ package_dir =
|
|||
packages = find:
|
||||
python_requires = >=3.8
|
||||
install_requires =
|
||||
psutil ~= 5.9
|
||||
|
||||
[options.packages.find]
|
||||
where = src
|
||||
|
|
|
@ -13,57 +13,20 @@ https://github.com/aldelaro5/Dolphin-memory-engine
|
|||
'''
|
||||
|
||||
import os
|
||||
from psutil import process_iter
|
||||
from struct import pack, unpack, calcsize
|
||||
from multiprocessing.shared_memory import SharedMemory
|
||||
|
||||
if os.name == 'nt':
|
||||
# windows
|
||||
from ctypes import Structure, POINTER, sizeof, byref, windll
|
||||
from ctypes.wintypes import DWORD, ULONG, LONG, CHAR, MAX_PATH
|
||||
kernel32 = windll.kernel32
|
||||
NULL = 0
|
||||
## https://docs.microsoft.com/ja-jp/windows/win32/api/tlhelp32/ns-tlhelp32-processentry32
|
||||
class PROCESSENTRY32(Structure):
|
||||
_fields_ = [
|
||||
('dwSize', DWORD),
|
||||
('cntUsage', DWORD),
|
||||
('th32ProcessID', DWORD),
|
||||
('th32DefaultHeapID', POINTER(ULONG)),
|
||||
('th32ModuleID', DWORD),
|
||||
('cntThreads', DWORD),
|
||||
('th32ParentProcessID', DWORD),
|
||||
('pcPriClassBase', LONG),
|
||||
('dwFlags', DWORD),
|
||||
('szExeFile', CHAR*MAX_PATH),
|
||||
]
|
||||
## https://docs.microsoft.com/en-us/windows/win32/api/tlhelp32/nf-tlhelp32-createtoolhelp32snapshot
|
||||
TH32CS_SNAPPROCESS = 2
|
||||
## find pids of dolphin
|
||||
def find_dolphin():
|
||||
# prepare entry struct
|
||||
entry = PROCESSENTRY32()
|
||||
entry.dwSize = sizeof(PROCESSENTRY32)
|
||||
# prepare snapshot
|
||||
snapshot = kernel32.CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL)
|
||||
# find pids
|
||||
pids = []
|
||||
if kernel32.Process32First(snapshot, byref(entry)):
|
||||
while True:
|
||||
if entry.szExeFile in (b'Dolphin.exe', b'DolphinQt2.exe', b'DolphinWx.exe'):
|
||||
pids.append(entry.th32ProcessID)
|
||||
if not kernel32.Process32Next(snapshot, byref(entry)): break
|
||||
kernel32.CloseHandle(snapshot);
|
||||
# done
|
||||
return pids
|
||||
else:
|
||||
# UNIX
|
||||
import psutil
|
||||
def find_dolphin():
|
||||
return [
|
||||
proc.pid
|
||||
for proc in psutil.process_iter()
|
||||
if proc.name() in ('dolphin-emu', 'dolphin-emu-qt2', 'dolphin-emu-wx')
|
||||
]
|
||||
dolphinProcNames = \
|
||||
('Dolphin.exe', 'DolphinQt2.exe', 'DolphinWx.exe') if os.name == 'nt' \
|
||||
else ('dolphin-emu', 'dolphin-emu-qt2', 'dolphin-emu-wx')
|
||||
|
||||
def find_dolphin():
|
||||
return [
|
||||
proc.pid
|
||||
for proc in process_iter()
|
||||
if proc.name() in dolphinProcNames
|
||||
]
|
||||
|
||||
'''
|
||||
@typedef {(int|str) | [(int|str), ...int[]]} Addr
|
||||
|
|
Loading…
Reference in a new issue