XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet

XFEEDToolBox

【WinUI】XFE精英危险工具箱

公开
关注 0 Fork 0 Star 0
UTF-8
"""Compile the independent trade HLSL with the local D3D compiler; no game/GPU/window use."""
import ctypes
import hashlib
import json
from pathlib import Path

source=Path('XFEEDToolBox/Assets/GalaxyTrade.hlsl')
body=source.read_bytes();buffer=ctypes.create_string_buffer(body)
compiler=ctypes.WinDLL('d3dcompiler_47.dll').D3DCompile
compiler.argtypes=[ctypes.c_void_p,ctypes.c_size_t,ctypes.c_char_p,ctypes.c_void_p,ctypes.c_void_p,
                  ctypes.c_char_p,ctypes.c_char_p,ctypes.c_uint,ctypes.c_uint,
                  ctypes.POINTER(ctypes.c_void_p),ctypes.POINTER(ctypes.c_void_p)]
compiler.restype=ctypes.c_int32
def read_blob(blob):
    if not blob:return b''
    table=ctypes.cast(blob,ctypes.POINTER(ctypes.POINTER(ctypes.c_void_p)))[0]
    try:
        address=ctypes.WINFUNCTYPE(ctypes.c_void_p,ctypes.c_void_p)(table[3])(blob)
        size=ctypes.WINFUNCTYPE(ctypes.c_size_t,ctypes.c_void_p)(table[4])(blob)
        return ctypes.string_at(address,size)
    finally:ctypes.WINFUNCTYPE(ctypes.c_uint,ctypes.c_void_p)(table[2])(blob)
output=Path('artifacts/galaxy-query-research/current-trade/tool-effects');output.mkdir(parents=True,exist_ok=True)
rows=[]
for entry in ('VSOriginalTradeRoute','PSOriginalTradeRoute','VSOriginalTradeHotspot','PSOriginalTradeHotspot'):
    shader=ctypes.c_void_p();errors=ctypes.c_void_p();profile='vs_5_0' if entry.startswith('VS') else 'ps_5_0'
    result=compiler(buffer,len(body),str(source).encode(),None,None,entry.encode(),profile.encode(),0,0,ctypes.byref(shader),ctypes.byref(errors))
    diagnostics=read_blob(errors).rstrip(b'\0').decode(errors='replace')
    bytecode=read_blob(shader)
    if result<0:raise ValueError(f'{entry}: {diagnostics}')
    (output/(entry+'.dxbc')).write_bytes(bytecode)
    rows.append(dict(entry=entry,profile=profile,bytes=len(bytecode),sha256=hashlib.sha256(bytecode).hexdigest(),diagnostics=diagnostics))
result=dict(source=str(source),sourceSha256=hashlib.sha256(body).hexdigest(),gameProcessAccess=False,gpuExecution=False,shaders=rows)
(output/'compile.json').write_text(json.dumps(result,indent=2)+'\n',encoding='utf-8')
print(json.dumps(result,indent=2))