PCL2无法正确地自动识别部分原生启动器安装的愚人节版本 #3360 #3361
Replies: 17 comments 70 replies
-
好 找到办法了 |
Beta Was this translation helpful? Give feedback.
-
PCL2不会缓存是吧 |
Beta Was this translation helpful? Give feedback.
-
那直接摆烂显示id得了 |
Beta Was this translation helpful? Give feedback.
-
发现部分mc的json被转换过utf+,需要先将releaseTime改为+00:00 |
Beta Was this translation helpful? Give feedback.
-
口误,UTC+( |
Beta Was this translation helpful? Give feedback.
-
你可能需要考虑到的情况: |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
这是大概的代码样子,龙猫改改就应该可以套上去了( Imports System
Imports Newtonsoft.Json
Imports System.Globalization
''' <summary>
''' 根据提供的Minecraft JSON数据和版本列表JSON数据,找到匹配的Minecraft版本信息
''' </summary>
''' <param name="mcj">Minecraft的JSON数据对象,包含需要查找的版本信息</param>
''' <param name="vj">包含所有Minecraft版本信息的JSON数据对象</param>
''' <returns>如果找到匹配的版本,则返回该版本的JSON字符串;如果未找到,则抛出异常</returns>
Public Function FindMinecraftVersion(mcj As Object, vj As Object) As String
Dim mcv As Object = Nothing '找到的mc版本 为Nothing表示未找到
Dim releaseTime As String = DateTime.Parse(mcj("releaseTime").ToString(), Nothing, DateTimeStyles.AdjustToUniversal).ToString() '获取到的JSOn内的releaseTime
For Each version As Object In vj("versions")
If releaseTime = DateTime.Parse(version("releaseTime").ToString(), Nothing, DateTimeStyles.AdjustToUniversal).ToString() Then
mcv = version
Exit For
End If
Next
If mcv IsNot Nothing Then
Return JsonConvert.SerializeObject(mcv)
Else
Throw New Exception("无法确定Minecraft版本")
End If
End Function |
Beta Was this translation helpful? Give feedback.
-
是服务器就肯定会挂,给API压个几亿的访问或者压个1T的流量会触发CDN流量清洗 |
Beta Was this translation helpful? Give feedback.
-
@allMagicNB 你不是来过 #3294 吗,你看看那个方法行不行 |
Beta Was this translation helpful? Give feedback.
-
建议直接扫 Constant Pool |
Beta Was this translation helpful? Give feedback.
-
我觉得可以想办法反汇编net.minecraft.server.MinecraftServer |
Beta Was this translation helpful? Give feedback.
-
Save it |
Beta Was this translation helpful? Give feedback.
-
好,现在我写出了一个我觉得还行的版本获取(我不会VB,所以以下全是Python)
打印出来的应该就是版本号 |
Beta Was this translation helpful? Give feedback.
-
我也用python写了个更 from zipfile import ZipFile
import json
from typing import List
def get_minecraft_version_id(jar_path:str):
'''
根据minecraft的client.jar获取minecraft的版本
jar_path: client.jar路径
'''
with ZipFile(jar_path,'r') as zf:
version_json_file = False
minecraft_class_file = False
server_class_file = True
for i in zf.filelist:
if i.filename == "version.json":
version_json_file = i
elif i.filename == "net/minecraft/client/Minecraft.class":
minecraft_class_file = i
elif i.filename == "net/minecraft/server/MinecraftServer.class":
server_class_file = i
else:
if not version_json_file and not minecraft_class_file and not server_class_file:
raise RuntimeError("无法获取传入的jar版本号")
if version_json_file: # 新版(>=18w47b)
zi = version_json_file
print(1)
with zf.open(zi,'r') as f:
version_json = json.load(f)
return version_json['id']
elif minecraft_class_file: # 老版(<=1.5.2)
zi = minecraft_class_file
print(2)
with zf.open(zi,'r') as f:
data = f.read()
#if b'Minecraft Minecraft ' not in data:
# continue
d = data.split(b'Minecraft Minecraft ') # 除1.0.0rc2-2外没有任何有存档的快照有Minecraft.class
chars = ''
for b in d[1]:
if b == 1: # \x01 java常量字符串开头是\x01\x00\x{长度}
break
else:
chars += chr(b)
else: # 没break
raise ValueError("未找到下一段个字符串的开头")
return chars
elif server_class_file: # 旧版(>=1.6.4)
zi = server_class_file
print(3)
with zf.open(zi,'r') as f:
data = f.read()
if b"\x01\x00\x01.\x01\x00\x01/\x01\x00" in data: # 在1.8及更高无效
print(1)
d = data.split(b"\x01\x00\x01.\x01\x00\x01/\x01\x00")
chars = ''
for b in d[1][1:]: # 跳过第一个长度字节
if b == 1: # \x01
break
else:
chars += chr(b)
else:
raise ValueError("未找到下一段个字符串的开头")
return chars if chars != "RC2" else "1.0.0-rc2-2"
else: # 这玩意我测试了接近1200遍……
d = data.split(b"\n")
results:List[str] = []
for b in d:
if len(b) < 50 and (b'.' in b or b'w' in b or b"pre" in b or b"Pre" in b or b"Combat" in b) and (
b'0' in b or b'1' in b or b'2' in b or b'3' in b or b'4' in b or
b'5' in b or b'6' in b or b'7' in b or b'8' in b or b'9' in b
):
c = [""]
enable = '0123456789qwertyuiopasdfghjklzxcvbnm.-_ ~QWERTYUIOPASDFGHJKLZXCVBNM'
for r in b:
if chr(r) in enable: # 模糊搜索
c[-1]+=(chr(r))
else:
if c[-1]:
c.append("")
if c != [""]:
results += c
for r in results:
for n in "0123456789":
if (n in r) and ( # 过滤结果
'w' in r or '.' in r or '' or 'pre1' in r
) and not r.startswith('.') and len(r) > 2:
return r 测试了1.20.4 1.12.2 1.12-pre7 1.10.2 1.10.2-pre1 1.8.9 1.7.10 1.6.4 1.5.2 1.4.7 1.3.2 1.2.5 18w10c 16w42a 16w02a 14w30b 13w16a 1.0-rc2-2 1.0 |
Beta Was this translation helpful? Give feedback.
-
@LTCatt 你看看用这玩意获取版本号行不行 |
Beta Was this translation helpful? Give feedback.
-
#3360
Beta Was this translation helpful? Give feedback.
All reactions