Skip to content

Commit

Permalink
Merge pull request #62 from fa0311/develop-v4
Browse files Browse the repository at this point in the history
v4.9.0
  • Loading branch information
fa0311 authored Mar 23, 2023
2 parents 0b0850d + 0ce3e65 commit d5c49f8
Show file tree
Hide file tree
Showing 5 changed files with 167 additions and 71 deletions.
5 changes: 4 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
"program": "DMMGamePlayerFastLauncher.py",
"console": "integratedTerminal",
"justMyCode": true,
"args": ["umamusume", "--non-bypass-uac", "--debug"]
"env": {
"ENV": "DEVELOP"
},
"args": ["umamusume", "--non-bypass-uac"]
}
]
}
128 changes: 90 additions & 38 deletions DMMGamePlayerFastLauncher.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import win32security
import sys
from lib.DGPSession import *
import logging


class ErrorManagerType:
Expand All @@ -27,9 +28,21 @@ def __init__(
self.url = url


class LogHandler(logging.Handler):
records: list[object] = []

def __init__(self, level=logging.NOTSET):
super().__init__(level=level)

def emit(self, record):
self.records.append(record)

def output(self) -> list[str]:
return [self.format(record) for record in self.records]


class ErrorManager:
skip: bool = False
debug: bool = False
argument_error: ErrorManagerType = ErrorManagerType(
message="Could not parse argument.",
solution="Is the product_id specified correctly?",
Expand Down Expand Up @@ -78,23 +91,36 @@ class ErrorManager:
url="https://github.com/fa0311/DMMGamePlayerFastLauncher/issues",
)

format: logging.Formatter = logging.Formatter(
"[%(name)s][%(levelname)s] %(message)s"
)
logger: logging.Logger = logging.getLogger(__qualname__)
logHandler: LogHandler = LogHandler()
streamHandler: logging.StreamHandler = logging.StreamHandler()

def __init__(self) -> None:
self.streamHandler.setFormatter(self.format)
self.logHandler.setFormatter(self.format)
self.set_logger(self.logger)

def error(self, error: ErrorManagerType, log: str | None = None):
output = filter(
lambda x: x is not None,
[error.message, error.solution, error.url, log],
[error.solution, error.url, log],
)
if self.skip:
self.info("\n".join(output))
self.logger.warning("\n".join(output), exc_info=True)
else:
raise Exception("\n".join(output))
raise Exception(
"\n".join([error.message] + self.logHandler.output() + list(output))
)

def info(self, text: str, e: Exception | None = None):
if e is None:
print(text)
elif self.debug:
raise e
def set_logger(self, logger: logging.Logger):
logger.setLevel(logging.DEBUG)
if os.environ.get("ENV") == "DEVELOP":
logger.addHandler(self.streamHandler)
else:
print(text)
logger.addHandler(self.logHandler)


class ProcessManager:
Expand All @@ -108,9 +134,10 @@ def __init__(self, error_manager: ErrorManager) -> None:
def run(
self, args: dict[str], admin: bool = False, force: bool = False
) -> subprocess.Popen[bytes] | None:
print(" ".join(args))
error_manager.logger.info(" ".join(args))
if admin:
if not self.non_bypass_uac and not force:
error_manager.logger.info("Run Bypass UAC")
run_bypass_uac()
elif self.non_request_admin:
self.error_manager.error(error=ErrorManager.permission_error)
Expand Down Expand Up @@ -188,72 +215,95 @@ def run_bypass_uac():
argpar.add_argument("--game-args", default=None)
argpar.add_argument("--login-force", action="store_true")
argpar.add_argument("--skip-exception", action="store_true")
argpar.add_argument("--debug", action="store_true")
argpar.add_argument("--https-proxy-uri", default=None)
argpar.add_argument("--non-request-admin", action="store_true")
argpar.add_argument("--non-bypass-uac", action="store_true")
argpar.add_argument("--force-bypass-uac", action="store_true")
argpar.add_argument("--schtasks-path", default="schtasks.exe")


try:
arg = argpar.parse_args()
error_manager.skip = arg.skip_exception
error_manager.debug = arg.debug
process_manager.non_request_admin = arg.non_request_admin
process_manager.non_bypass_uac = arg.non_bypass_uac
except Exception as e:
error_manager.error(error=ErrorManager.argument_error)

session = DgpSession(arg.https_proxy_uri)
error_manager.logger.info(" ".join(sys.argv))

try:
error_manager.logger.info("Start DgpSession")
session = DgpSession(arg.https_proxy_uri)
error_manager.set_logger(session.logger)
except:
error_manager.logger.info("DgpSession Error", exc_info=True)

try:
error_manager.logger.info("Read DB")
session.read()
except Exception as e:
error_manager.info("Read Error", e)
except:
error_manager.logger.info("Read Error", exc_info=True)


if len(session.cookies.items()) == 0:
try:
error_manager.logger.info("Read Cache")
session.read_cache()
except Exception as e:
error_manager.info("Read Cache Error", e)
except:
error_manager.logger.info("Read Cache Error", exc_info=True)

if arg.login_force:
requests.cookies.remove_cookie_by_name(session.cookies, "login_session_id")
try:
requests.cookies.remove_cookie_by_name(session.cookies, "login_session_id")
except:
pass

if session.cookies.get("login_session_id") == None:
if session.cookies.get("login_session_id", **session.cookies_kwargs) == None:
error_manager.logger.info("Request Session Id")
response = session.get("https://apidgp-gameplayer.games.dmm.com/v5/loginurl")
url = response.json()["data"]["url"]
token = urlparse(url).path.split("path=")[-1]
session.get(url)
login_url = (
"https://accounts.dmm.com/service/login/token/=/path={token}/is_app=false"
)
try:
session.get(
f"https://accounts.dmm.com/service/login/token/=/path={token}/is_app=false"
)
except Exception as e:
session.get(login_url)
except:
pass

if session.cookies.get("login_session_id") == None:
error_manager.info("Login Error")
if session.cookies.get("login_session_id", **session.cookies_kwargs) == None:
try:
error_manager.logger.info("Read Cookies Cache")
session.read_cache()
except Exception as e:
error_manager.info("Read Cache Error", e)
except:
error_manager.logger.info("Read Cache Error", exc_info=True)

if session.cookies.get("login_session_id") == None:
if session.cookies.get("login_session_id", **session.cookies_kwargs) == None:
error_manager.error(error=ErrorManager.login_error)

try:
error_manager.logger.info("Write DB")
session.write()
except Exception as e:
error_manager.info("Write Error", e)
except:
error_manager.logger.info("Write Error", exc_info=True)


try:
error_manager.logger.info("Write Cache")
session.write_cache()
except Exception as e:
error_manager.info("Write Cache Error")
except:
error_manager.logger.info("Write Cache Error", exc_info=True)

session.close()

dpg5_config = session.get_config()
try:
error_manager.logger.info("Read DGP Congig")
dpg5_config = session.get_config()
except:
error_manager.logger.info("Read DGP Congig Error", exc_info=True)

if arg.game_path is None:
for contents in dpg5_config["contents"]:
if contents["productId"] == arg.product_id:
Expand All @@ -280,9 +330,10 @@ def run_bypass_uac():
else:
game_path = arg.game_path

response = session.lunch(
"https://apidgp-gameplayer.games.dmm.com/v5/launch/cl", arg.product_id
).json()
error_manager.logger.info("Request to Launch Token")

launch_url = "https://apidgp-gameplayer.games.dmm.com/v5/launch/cl"
response = session.lunch(launch_url, arg.product_id).json()

if response["result_code"] == 100:
dmm_args = response["data"]["execute_args"].split(" ")
Expand All @@ -293,12 +344,13 @@ def run_bypass_uac():
and not arg.non_bypass_uac
and response["data"]["is_administrator"]
):
error_manager.logger.info("Run Bypass UAC")
run_bypass_uac()
start_time = time.time()
process = process_manager.run([game_path] + dmm_args)
for line in process.stdout:
text = line.decode("utf-8").strip()
print(text)
print(text) # GameLog
if time.time() - start_time < 2:
if response["data"]["is_administrator"]:
process = process_manager.run([game_path] + dmm_args, admin=True)
Expand Down
24 changes: 15 additions & 9 deletions docs/README-advance.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
| --game-args | | None | String &#124; None | |
| --login-force | | Flase | Bool | deprecated |
| --skip-exception | | False | Bool | |
| --debug | | False | Bool | |
| --https-proxy-uri | | None | String &#124; None | |
| --non-request-admin | | False | Bool | deprecated |
| --non-bypass-uac | | False | Bool | |
Expand Down Expand Up @@ -93,14 +92,6 @@ Unity 製ゲームの引数はここに詳しく載ってます
例:
`%AppData%\DMMGamePlayerFastLauncher\DMMGamePlayerFastLauncher.exe umamusume --skip-exception`

### debug

デバックモードです
バグ報告の際など指示がある場合に付けてください

例:
`%AppData%\DMMGamePlayerFastLauncher\DMMGamePlayerFastLauncher.exe umamusume --debug`

### https-proxy-uri

https プロキシを設定します
Expand Down Expand Up @@ -238,3 +229,18 @@ DMMGamePlayer を起動してログインし直して下さい
### ゲームに起動引数を与える

[game-args](#game-args)

## それでも解決しない

Issuesを送るのが望ましいがとにかく動かしたい人向け

| ファイル名 | 詳細 | 消した際の影響 |
| --------------- | ------------------------------------------ | ------------------------------------------------------------------------|
| dmmgame.cnf | DMMGamePlayerに関するすべての設定ファイル | ゲームのインストール状況も消えるのでゲームを再インストールする羽目になる |
| Local State | 暗号化に使うキーが入っている | ログイン情報の再入力を求められる |
| Network/Cookies | セッション情報が含まれるデータベース | ログイン情報の再入力を求められる |

これ以外はキャッシュだけど消すときは念のためバックアップを取ることを推奨します

`Local State``Network/Cookies` を消した時に直るケースが多いかも(消した後はDMMGamePlayerを起動してログインし直してください)
`dmmgame.cnf` はあんまり関係ないので消すのはオススメできない
Loading

0 comments on commit d5c49f8

Please sign in to comment.