Gradually adding support for all features

This commit is contained in:
Pavel Shevaev 2022-12-07 17:13:10 +03:00
parent d9ea902c9b
commit ac55cd48eb
2 changed files with 42 additions and 17 deletions

View File

@ -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 = '';

View File

@ -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) %}