Skip to content

Commit

Permalink
compatibility for game version 3.0
Browse files Browse the repository at this point in the history
wish history URL is not logged anymore, but can still be found in some
web cache files in the game directory. big shoutouts and thanks to
paimon.moe's Made Baruna <3

- retrieves auth token from cache file instead of log file
- removes platform selection in frontend (can't get URL on android
anymore)
- bumps version to 1.3
- closes #1
  • Loading branch information
Ennea committed Aug 28, 2022
1 parent 1e291ad commit a0e6969
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 93 deletions.
58 changes: 11 additions & 47 deletions frontend/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -254,57 +254,21 @@ <h2>Wish History</h2>
<button type="button" class="close" @click="closeModal()">&times;</button>
<h3>Update wish history</h3>

<p>Select the platform you play Genshin Impact on.</p>
<div class="pretty-choices">
<div>
<label>
<input type="radio" name="platform" value="pc" x-model="selectedPlatform">
<span>PC</span>
</label>
</div>
<div>
<label>
<input type="radio" name="platform" value="android" x-model="selectedPlatform">
<span>Android</span>
</label>
<div>
<p>To update your wish history, click the button below. This process requires you to have opened the in-game wish history the last time you've played Genshin Impact. If you have not done so, or you are not sure, you can start the game and open the in-game wish history now.</p>
<div class="center">
<button type="button" class="button" :disabled="requestInProgress" @click="updateWishes(false)">Update wish history</button>
</div>
</div>

<template x-if="selectedPlatform == 'pc'">
<div>
<p>To update your wish history, click the button below. This process requires you to have opened the in-game wish history the last time you've played Genshin Impact. If you have not done so, or you are not sure, you can start the game and open the in-game wish history now.</p>
<div class="center">
<button type="button" class="button" :disabled="requestInProgress" @click="updateWishes(false)">Update wish history</button>
</div>
</div>
</template>

<template x-if="selectedPlatform == 'android'">
<div>
<p>To get your wish history URL on Android, follow these steps:</p>
<ol>
<li>Open the wish history inside the game.</li>
<li>Once the page has loaded, disable your Wi-Fi and mobile data, then refresh the page.</li>
<li>Copy the URL from the resulting error message.</li>
</ol>
<p>Once you've copied the URL, paste it below:</p>
<form class="input-container" @submit="updateWishes(true, $event)">
<input type="text" placeholder="Wish history URL" x-model="wishHistoryURL">
<button type="submit" class="button" :disabled="requestInProgress || wishHistoryURL.length == 0">Update wish history</button>
</form>
<div id="message-output-container">
<div id="message-output" x-text="backendMessage" x-show="!requestInProgress" :class="backendStatus >= 400 ? 'error' : ''"></div>
<div id="spinner" x-show="requestInProgress">
<svg viewBox="0 0 10 10">
<path d="M5,0C2.239,0 0,2.239 0,5C0,7.76 2.24,10 5,10C7.761,10 10,7.761 10,5L8,5C8,6.657 6.657,8 5,8C3.344,8 2,6.656 2,5C2,3.343 3.343,2 5,2L5,0Z" />
</svg>
</div>
</template>

<template x-if="selectedPlatform != null">
<div id="message-output-container">
<div id="message-output" x-text="backendMessage" x-show="!requestInProgress" :class="backendStatus >= 400 ? 'error' : ''"></div>
<div id="spinner" x-show="requestInProgress">
<svg viewBox="0 0 10 10">
<path d="M5,0C2.239,0 0,2.239 0,5C0,7.76 2.24,10 5,10C7.761,10 10,7.761 10,5L8,5C8,6.657 6.657,8 5,8C3.344,8 2,6.656 2,5C2,3.343 3.343,2 5,2L5,0Z" />
</svg>
</div>
</div>
</template>
</div>
</div>
</aside>

Expand Down
16 changes: 3 additions & 13 deletions frontend/script.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
document.addEventListener('alpine:init', () => {
Alpine.data('app', () => ({
VERSION: '1.2',
VERSION: '1.3',

// raw data from the backend
bannerTypes: {},
Expand All @@ -20,7 +20,6 @@ document.addEventListener('alpine:init', () => {

uidData: {},
selectedUID: null,
selectedPlatform: null,
bannerTypesList: [],
wishHistoryPageSize: 10,
wishHistoryLastPage: 0,
Expand Down Expand Up @@ -181,16 +180,7 @@ document.addEventListener('alpine:init', () => {
});
},

updateWishes(withURL, event) {
if (event) {
event.preventDefault();
}

const body = {};
if (withURL) {
body.url = this.wishHistoryURL;
}

updateWishes() {
// reset message and status, show loading animation
this.backendStatus = 0;
this.backendMessage = '';
Expand All @@ -201,7 +191,7 @@ document.addEventListener('alpine:init', () => {
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(body)
body: '{}'
}).then((response) => {
return new Promise((resolve, reject) => {
response.json().then((json) => {
Expand Down
2 changes: 1 addition & 1 deletion wishing-well.nsi
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
!define MUI_ICON "icon.ico"

Name "Wishing Well"
OutFile "wishing-well-1.2.exe"
OutFile "wishing-well-1.3.exe"
Unicode True
RequestExecutionLevel admin
InstallDir "$PROGRAMFILES\Wishing Well"
Expand Down
2 changes: 1 addition & 1 deletion wishing-well.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# nuitka-project: --windows-company-name=-
# nuitka-project: --windows-product-name=Wishing Well
# nuitka-project: --windows-file-description=Wishing Well
# nuitka-project: --windows-product-version=1.2
# nuitka-project: --windows-product-version=1.3

import logging
import bottle
Expand Down
20 changes: 10 additions & 10 deletions wishing_well/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from .enums import ItemType
from .exceptions import AuthTokenExtractionError, LogNotFoundError, MissingAuthTokenError, EndpointError, RequestError
from .database import Database
from .util import get_log_path
from .util import get_cache_path


class Client:
Expand Down Expand Up @@ -150,18 +150,18 @@ def extract_region_and_auth_token(url):

@staticmethod
def extract_region_and_auth_token_from_file():
path = get_log_path()
if path is None:
path = get_cache_path()
if path is None or not path.exists():
raise LogNotFoundError('Genshin Impact is not installed or has not been started yet.')

with path.open('rb') as fp:
cache_file = fp.read()

url = None
regex = re.compile('^OnGetWebViewPageFinish:(https://webstatic-sea.hoyoverse.com/genshin/event/.+)$')
with path.open('r') as fp:
for line in fp:
match = regex.search(line)
if match is not None:
url = match.group(1)
break
regex = re.compile(b'(https://webstatic-sea.hoyoverse.com/genshin/event/.+)\0')
matches = regex.findall(cache_file)
if len(matches) > 0:
url = matches[-1].decode('utf-8')

if url is None:
raise AuthTokenExtractionError('Could not find authentication token in the log file. Open the wish history in the game, then try again.')
Expand Down
31 changes: 10 additions & 21 deletions wishing_well/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,18 @@
import sys
import tkinter
import webbrowser
import winreg
from pathlib import Path
from tkinter import ttk
from urllib.request import urlopen
from urllib.error import URLError, HTTPError

from .exceptions import LogNotFoundError


def get_data_path():
if sys.platform == 'win32':
path = Path(os.environ['APPDATA']) / 'wishing-well'
elif sys.platform == 'linux':
if 'XDG_DATA_HOME' in os.environ:
path = Path(os.environ['XDG_DATA_HOME']) / 'wishing-well'
else:
path = Path('~/.local/share/wishing-well').expanduser()
elif sys.platform == 'darwin':
if 'XDG_DATA_HOME' in os.environ:
path = Path(os.environ['XDG_DATA_HOME']) / 'wishing-well'
else:
path = Path('~/Library/Application Support/wishing-well').expanduser()
else:
show_error('Wishing Well is only designed to run on Windows or Linux based systems.')
show_error('Wishing Well only supports Windows.')

# create dir if it does not yet exist
if not path.exists():
Expand All @@ -38,16 +27,16 @@ def get_data_path():

return path

def get_log_path():
if sys.platform != 'win32':
raise LogNotFoundError('Cannot find the log file on non-Windows systems.')

path = Path(os.environ['USERPROFILE']) / 'AppData/LocalLow/miHoYo/Genshin Impact/output_log.txt'
if not path.exists():
def get_cache_path():
try:
handle = winreg.CreateKeyEx(winreg.HKEY_LOCAL_MACHINE, 'Software\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\Genshin Impact',
access=winreg.KEY_WOW64_64KEY | winreg.KEY_READ)
path = winreg.QueryValueEx(handle, 'InstallPath')[0]
handle.Close()
return Path(path) / 'Genshin Impact game/GenshinImpact_Data/webCaches/Cache/Cache_Data/data_2'
except (OSError, FileNotFoundError):
return None

return path

def set_up_logging():
log_level = logging.DEBUG if len(sys.argv) > 1 and sys.argv[1] == '--debug' else logging.INFO
log_format = '%(asctime)s %(levelname)s: %(message)s'
Expand Down

0 comments on commit a0e6969

Please sign in to comment.