mirror of
https://github.com/OpenFusionProject/scripts.git
synced 2025-11-24 05:00:22 +00:00
Compare commits
7 Commits
5bf1ce01e3
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a3856cdc9d | ||
|
|
672d7e2b42 | ||
|
|
d5b58d96da | ||
|
|
06869164a1 | ||
|
|
99c80c9c7b | ||
|
4196766a2b
|
|||
|
7922fc060a
|
0
dx2cg/__init__.py
Normal file
0
dx2cg/__init__.py
Normal file
@@ -41,6 +41,7 @@ decls = {
|
||||
|
||||
ops = {
|
||||
"mov": "{0} = {1};",
|
||||
"mov_sat": "{0} = clamp({1}, 0.0, 1.0)",
|
||||
"add": "{0} = {1} + {2};",
|
||||
"mul": "{0} = {1} * {2};",
|
||||
"mad": "{0} = {1} * {2} + {3};",
|
||||
@@ -53,7 +54,7 @@ ops = {
|
||||
"slt": "{0} = float4(({1}.x < {2}.x) ? 1.0f : 0.0f, ({1}.y < {2}.y) ? 1.0f : 0.0f, ({1}.z < {2}.z) ? 1.0f : 0.0f, ({1}.w < {2}.w) ? 1.0f : 0.0f);",
|
||||
"sge": "{0} = float4(({1}.x >= {2}.x) ? 1.0f : 0.0f, ({1}.y >= {2}.y) ? 1.0f : 0.0f, ({1}.z >= {2}.z) ? 1.0f : 0.0f, ({1}.w >= {2}.w) ? 1.0f : 0.0f);",
|
||||
"rcp": "{0} = ({1} == 0.0f) ? FLT_MAX : (({1} == 1.0f) ? {1} : (1 / {1}));",
|
||||
"texld": "{0} = tex2D({2}, (float2){1});",
|
||||
"texld": "{0} = {3}({2}, (float2){1});",
|
||||
}
|
||||
|
||||
struct_a2v = """struct a2v {
|
||||
@@ -185,12 +186,20 @@ def process_header(prog):
|
||||
i = i - 1
|
||||
elif line.startswith("SetTexture"):
|
||||
dec = line.split(' ')
|
||||
if dec[2] != "{2D}":
|
||||
if dec[2] == "{2D}":
|
||||
texture_type = "sampler2D"
|
||||
elif dec[2] == "{3D}":
|
||||
texture_type = "sampler3D"
|
||||
elif dec[2] == "{RECT}":
|
||||
texture_type = "samplerRECT"
|
||||
elif dec[2] == "{CUBE}":
|
||||
texture_type = "samplerCUBE"
|
||||
else:
|
||||
raise ValueError(f"Unknown texture type {dec[2]}")
|
||||
key = f"s{textures}"
|
||||
val = dec[1][1:-1]
|
||||
loctab[key] = val
|
||||
locdecl.append(f"sampler2D {val};")
|
||||
locdecl.append(f"{texture_type} {val};")
|
||||
textures = textures + 1
|
||||
|
||||
del prog[i]
|
||||
@@ -217,7 +226,7 @@ def resolve_args(args, loctab, consts):
|
||||
arg = arg[:dot]
|
||||
else:
|
||||
swiz = ""
|
||||
|
||||
|
||||
if arg[0] == 'r':
|
||||
pass
|
||||
elif arg[0] == 'v':
|
||||
@@ -238,7 +247,23 @@ def resolve_args(args, loctab, consts):
|
||||
|
||||
args[a] = neg + arg + swiz
|
||||
|
||||
def decode(code, args):
|
||||
def get_cgtex_type(name, locdecl):
|
||||
for loc in locdecl:
|
||||
loc = loc.split(' ')
|
||||
if name == loc[1][:-1]:
|
||||
if loc[0] == 'sampler2D':
|
||||
return "tex2D"
|
||||
elif loc[0] == 'sampler3D':
|
||||
return "tex3D"
|
||||
elif loc[0] == 'samplerCUBE':
|
||||
return "texCUBE"
|
||||
elif loc[0] == 'samplerRECT':
|
||||
return "texRECT"
|
||||
else:
|
||||
raise ValueError(f"Unknown CG texture type {loc[0]}")
|
||||
raise ValueError(f"Could not find texture {name} in locals")
|
||||
|
||||
def decode(code, args, locdecl):
|
||||
if code in decls:
|
||||
return [decls[code].format(*args)]
|
||||
elif code in ops:
|
||||
@@ -253,14 +278,18 @@ def decode(code, args):
|
||||
else:
|
||||
swiz = "xyzw"
|
||||
|
||||
lines = [ops[code].format("tmp", *args[1:])]
|
||||
if code == "texld":
|
||||
lines = [ops[code].format("tmp", *args[1:], get_cgtex_type(args[2], locdecl))]
|
||||
else:
|
||||
lines = [ops[code].format("tmp", *args[1:])]
|
||||
|
||||
for c in swiz:
|
||||
lines.append(f"{target}.{c} = tmp.{c};")
|
||||
return lines
|
||||
else:
|
||||
raise ValueError(f"Unknown opcode {code}")
|
||||
|
||||
def process_asm(asm, loctab):
|
||||
def process_asm(asm, loctab, locdecl):
|
||||
shadertype = ""
|
||||
if asm[0] == "\"vs_1_1":
|
||||
shadertype = "vertex"
|
||||
@@ -293,7 +322,7 @@ def process_asm(asm, loctab):
|
||||
code = code[:pp]
|
||||
|
||||
resolve_args(args, loctab, consts)
|
||||
disasm = decode(code, args)
|
||||
disasm = decode(code, args, locdecl)
|
||||
# print(f"{instruction} \t==>\t{disasm}")
|
||||
disasm.insert(0, f"// {instruction}")
|
||||
translated.extend(disasm)
|
||||
@@ -316,7 +345,7 @@ def disassemble(blocks):
|
||||
binds.update(bds)
|
||||
lighting |= light
|
||||
|
||||
(shadertype, disasm) = process_asm(asm, ltab)
|
||||
(shadertype, disasm) = process_asm(asm, ltab, locdecl)
|
||||
shaders[shadertype] = disasm
|
||||
|
||||
text = ""
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
import os
|
||||
import sys
|
||||
from swapper import process
|
||||
from .swapper import process
|
||||
|
||||
def process_file(filename, suffix):
|
||||
dot = filename.rfind(".")
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
import re
|
||||
import sys
|
||||
from disassembler import disassemble
|
||||
from .disassembler import disassemble
|
||||
|
||||
tabs = 3
|
||||
def indent(block):
|
||||
|
||||
@@ -4,6 +4,7 @@ version: '3.1'
|
||||
services:
|
||||
db:
|
||||
image: mysql:5.5.42
|
||||
command: --character-set-server utf8
|
||||
restart: always
|
||||
ports:
|
||||
- 3306:3306
|
||||
|
||||
@@ -179,6 +179,7 @@ def main(conn, xdt_path):
|
||||
for table_name in root:
|
||||
if "Table" in table_name:
|
||||
process_xdt_table(cursor, root, table_name, mappings)
|
||||
finalize(cursor)
|
||||
conn.commit()
|
||||
|
||||
def connect_to_db():
|
||||
@@ -192,10 +193,18 @@ def connect_to_db():
|
||||
def prep_db():
|
||||
conn = connect_to_db()
|
||||
cursor = conn.cursor()
|
||||
# we have to upload a lot of data, so we need to raise the limit
|
||||
cursor.execute("SET GLOBAL max_allowed_packet=1073741824")
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
||||
def finalize(cursor):
|
||||
# credentials used by the game
|
||||
cursor.execute("GRANT SELECT ON XDB.* TO 'cmog' IDENTIFIED BY 'scooby'")
|
||||
# change the root password to something more secure
|
||||
new_root_pw = input("Enter new root password: ")
|
||||
cursor.execute(f"SET PASSWORD = PASSWORD('{new_root_pw}')")
|
||||
|
||||
# %%
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) != 2:
|
||||
|
||||
Reference in New Issue
Block a user