Skip to content
View in the app

A better way to browse. Learn more.

ResHax

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.
Help us keep the site running.
Zero Tolerance for Disrespect

Py scripting problem

Featured Replies

  • Author
  • Localization

month, posted Fri Feb 15, 2019 8:07 pm (43532)


This script cannot display Chinese, Japanese, Korean and some symbols correctly after extracting the text. Can anyone modify the code so that they can display correctly?


import os
import json
import codecs


def read_block(f):
block_size = 0
index = int.from_bytes(bytes(f.read(4)), byteorder='little')
block_size = 4

len1 = int.from_bytes(bytes(f.read(2)), byteorder='little')
block_size = 2
str1 = codecs.decode(bytes(f.read(len1 * 2)), encoding='utf-8', errors='replace').replace('\00','')
block_size = len1 * 2

return {"index": index, "str1": str1, "size": block_size}

fname = 'tb_npc_script.res'
fsize = os.path.getsize(fname)
entries = []
with open("tb_npc_script.res", "rb") as f:
try:
entry_count = int.from_bytes(f.read(4), byteorder='little')
fsize -= 4
while entry_count > 0:
block = read_block(f)
fsize -= block["size"]
entry_count -= 1
entries.append(block)

except Exception as e:
print(e)

with open('tb_npc_script.txt', 'w', encoding='utf-8') as c:
json.dump(entries, c, ensure_ascii=False, indent=4)

print('??')

tb_npc_script.rar

  • Author
  • Localization

akintos, posted Fri Feb 15, 2019 11:59 pm (43538)


replace line 14

Code:
   str1 = codecs.decode(bytes(f.read(len1 * 2)), encoding='utf-8', errors='replace').replace('\00','')

to this

Code:
   str1 = codecs.decode(bytes(f.read(len1 * 2)), encoding='utf-16', errors='replace').replace('\00','')
  • Author
  • Localization

month, posted Sat Feb 16, 2019 4:24 am (43541)


Thank you. Thank you very much.
Guest
This topic is now closed to further replies.

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.