From ac55cd48ebf8f759ef8b560e779a183be6896535 Mon Sep 17 00:00:00 2001 From: Pavel Shevaev Date: Wed, 7 Dec 2022 17:13:10 +0300 Subject: [PATCH] Gradually adding support for all features --- src/codegen.inc.php | 31 ++++++++++++++++++++++++++++--- tpl/macro.twig | 28 ++++++++++++++-------------- 2 files changed, 42 insertions(+), 17 deletions(-) diff --git a/src/codegen.inc.php b/src/codegen.inc.php index 0fbe879..601eef9 100644 --- a/src/codegen.inc.php +++ b/src/codegen.inc.php @@ -31,11 +31,11 @@ function supported_tokens() 'id', 'owner', 'pkey', + 'obscured', + 'diffable', 'bhl_bind' //TODO: - //'obscured', - //'bitfields', - //'diffable', + //'i18n' ]; } @@ -92,6 +92,12 @@ function _add_twig_support(\Twig\Environment $twig) return cs_type_prefix($type); } )); + $twig->addFilter(new \Twig\TwigFilter('obscure_type', + function($type_str, $fld) + { + return obscure_type($type_str, $fld); + } + )); $twig->addFunction(new \Twig\TwigFunction('var_reset', function($name, $type, $default) { @@ -217,6 +223,25 @@ function cs_type_prefix(\mtgType $type) } } +function obscure_type($type_str, $fld) +{ + if($fld->hasToken('obscured')) + { + if($fld->getType() instanceof \mtgBuiltinType && $fld->getType()->isUint32()) + return "CodeStage.AntiCheat.ObscuredType.ObscuredUInt"; + else if($fld->getType() instanceof \mtgBuiltinType && $fld->getType()->isUint64()) + return "CodeStage.AntiCheat.ObscuredType.ObscuredULong"; + else if($fld->getType() instanceof \mtgBuiltinType && $fld->getType()->isInt64()) + return "CodeStage.AntiCheat.ObscuredType.ObscuredLong"; + else if($fld->getType() instanceof \mtgBuiltinType && $fld->getType()->isFloat()) + return "CodeStage.AntiCheat.ObscuredType.ObscuredFloat"; + else + throw new Exception("Not supported obscured type: " . $fld->getType()); + } + + return $type_str; +} + function var_reset($name, \mtgType $type, $default = null) { $str = ''; diff --git a/tpl/macro.twig b/tpl/macro.twig index c0b53e5..4c5afb2 100644 --- a/tpl/macro.twig +++ b/tpl/macro.twig @@ -2,24 +2,24 @@ {% macro decl_units(meta) %} {%- for u in meta.getunits ~%} -{%- if u.object is instanceof('\\mtgMetaStruct') -%} -{{ _self.decl_struct(u.object) }} -{%- elseif u.object is instanceof('\\mtgMetaEnum') -%} -{{ _self.decl_enum(u.object) }} -{%- elseif u.object is instanceof('\\mtgMetaRPC') -%} -{{ _self.decl_rpc(u.object) }} -{%- endif ~%} + {%- if u.object is instanceof('\\mtgMetaStruct') -%} + {{ _self.decl_struct(u.object) }} + {%- elseif u.object is instanceof('\\mtgMetaEnum') -%} + {{ _self.decl_enum(u.object) }} + {%- elseif u.object is instanceof('\\mtgMetaRPC') -%} + {{ _self.decl_rpc(u.object) }} + {%- endif ~%} {%- endfor ~%} {% endmacro %} {% macro decl_struct(o, extra = '') %} -{%- if o.parent and has_token(o, 'POD') -%} -{{Error("@POD structs can't have a parent: " ~ o.name)}} -{%- endif -%} -{%- if o.parent and has_token(o, 'bitfields') -%} -{{Error("@bitfields structs can't have a parent: " ~ o.name)}} -{%- endif -%} + {%- if o.parent and has_token(o, 'POD') -%} + {{Error("@POD structs can't have a parent: " ~ o.name)}} + {%- endif -%} + {%- if o.parent and has_token(o, 'bitfields') -%} + {{Error("@bitfields structs can't have a parent: " ~ o.name)}} + {%- endif -%} {{_self.attributes(o)}} public {{_self.struct_type(o)}} {{o.name}} {{_self.base_struct_class(o)}} @@ -127,7 +127,7 @@ public long fields_mask; {%- macro decl_struct_field(o, f) -%} {{_self.attributes(f)}} -public {{f.type|cs_type}} {{f.name}} {% if not has_token(o, 'POD') -%} {{_self.decl_init_value(f.type)}} {%- endif -%}; +public {{f.type|cs_type|obscure_type(f)}} {{f.name}} {% if not has_token(o, 'POD') -%} {{_self.decl_init_value(f.type)}} {%- endif -%}; {%- endmacro -%} {% macro decl_init_value(type) %}