From 304bbe12fda74feb843d68858a682528efa90932 Mon Sep 17 00:00:00 2001 From: Ralty <78720179+Raltyro@users.noreply.github.com> Date: Mon, 21 Jul 2025 23:08:01 +0700 Subject: [PATCH] remove macro-fixer that is uhh made by yknoow --- libraries/macro-fixer/extraParams.hxml | 2 - libraries/macro-fixer/haxelib.json | 9 - .../macro-fixer/macros/CustomFieldMacro.hx | 92 ----------- libraries/macro-fixer/macros/HashLinkFixer.hx | 155 ------------------ libs.xml | 2 - project.xml | 3 - .../backend/system/macros/HashLinkFixer.hx | 76 +++++++++ source/funkin/backend/system/macros/Macros.hx | 18 +- 8 files changed, 92 insertions(+), 265 deletions(-) delete mode 100644 libraries/macro-fixer/extraParams.hxml delete mode 100644 libraries/macro-fixer/haxelib.json delete mode 100644 libraries/macro-fixer/macros/CustomFieldMacro.hx delete mode 100644 libraries/macro-fixer/macros/HashLinkFixer.hx create mode 100644 source/funkin/backend/system/macros/HashLinkFixer.hx diff --git a/libraries/macro-fixer/extraParams.hxml b/libraries/macro-fixer/extraParams.hxml deleted file mode 100644 index 6a8e1ff9..00000000 --- a/libraries/macro-fixer/extraParams.hxml +++ /dev/null @@ -1,2 +0,0 @@ ---macro macros.CustomFieldMacro.init() ---macro macros.HashLinkFixer.init() diff --git a/libraries/macro-fixer/haxelib.json b/libraries/macro-fixer/haxelib.json deleted file mode 100644 index 74ac6ce8..00000000 --- a/libraries/macro-fixer/haxelib.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "name": "custom-fields-macro", - "url": "https://example.com/", - "license": "Public", - "description": "A fix", - "version": "1.0.0", - "releasenote": "NOTHING", - "contributors": ["NeeEoo"] -} diff --git a/libraries/macro-fixer/macros/CustomFieldMacro.hx b/libraries/macro-fixer/macros/CustomFieldMacro.hx deleted file mode 100644 index a8c426e6..00000000 --- a/libraries/macro-fixer/macros/CustomFieldMacro.hx +++ /dev/null @@ -1,92 +0,0 @@ -package macros; - -#if macro -import haxe.macro.Compiler; -import haxe.macro.Context; -import haxe.macro.Expr; - -using StringTools; - -/** - * Macro used to add custom fields to classes without having to override the entire file. - */ -class CustomFieldMacro { - public static function init() { - var injections:Map> = [ - "lime.utils.AssetLibrary" => [ - { - name: "tag", - access: [APublic], - kind: FVar(macro: funkin.backend.assets.AssetSource), - pos: (macro null).pos, - } - ], - ]; - - for(lib => fields in injections) { - var build = '@:build(macros.CustomFieldMacro.build("${MacroSerializer.run(fields)}"))'; - //Sys.println('Injecting $build into $lib'); - Compiler.addGlobalMetadata(lib, build); - } - } - - public static function build(fieldData:String) { - var fields = Context.getBuildFields(); - var customFields:Array = MacroUnserializer.run(fieldData); - for(f in customFields) - fields.push(f); - return fields; - } -} - -class MacroSerializer extends haxe.Serializer { - public static function run(v:Dynamic) { - var s = new MacroSerializer(); - s.useEnumIndex = true; - s.serialize(v); - return s.toString(); - } - - public override function serialize(v:Dynamic) { - switch (Type.typeof(v)) { - case TClass(c): - if (!(#if neko untyped c.__is_String #else c == String #end)) { - switch (#if (neko || cs || python) Type.getClassName(c) #else c #end) { - case #if (neko || cs || python) "haxe.macro.Position" #else c if(Type.getClassName(c) == "haxe.macro.Position") #end: - buf.add("P"); - var info = Context.getPosInfos(v); - serialize(info.min); - serialize(info.max); - serialize(info.file); - return; - default: - } - } - default: - } - super.serialize(v); - } -} - -class MacroUnserializer extends haxe.Unserializer { - public static function run(s:String):Dynamic { - var u = new MacroUnserializer(s); - return u.unserialize(); - } - - public override function unserialize():Dynamic { - var c = get(pos++); - switch (c) { - case "P".code: - var min = unserialize(); - var max = unserialize(); - var file = unserialize(); - var o = Context.makePosition({min: min, max: max, file: file}); - return o; - } - pos--; - return super.unserialize(); - } - -} -#end \ No newline at end of file diff --git a/libraries/macro-fixer/macros/HashLinkFixer.hx b/libraries/macro-fixer/macros/HashLinkFixer.hx deleted file mode 100644 index 8b9ffd7c..00000000 --- a/libraries/macro-fixer/macros/HashLinkFixer.hx +++ /dev/null @@ -1,155 +0,0 @@ -package macros; - -#if macro -import haxe.macro.Expr; -import haxe.macro.*; - -using StringTools; -using haxe.macro.PositionTools; - -class HashLinkFixer { - public static var buildMacroString = '@:build(macros.HashLinkFixer.build())'; - - public static var applyOn:Array = [ - "lime", - "std", - "Math", - "", - ]; - - public static var modifiedClasses:Array = []; - - public static function init() { - #if !display - if(Context.defined("display")) return; - if(Context.defined("hl")) { - for(apply in applyOn) { - compile(apply); - } - } - #end - } - - public static function compile(name:String) { - #if !display - Compiler.addGlobalMetadata(name, buildMacroString); - #end - } - - public static function build():Array { - var fields = Context.getBuildFields(); - var clRef = Context.getLocalClass(); - if (clRef == null) return fields; - var cl = clRef.get(); - - if (cl.isAbstract || cl.isExtern || cl.isInterface) return fields; - if (!cl.name.endsWith("_Impl_") && !cl.name.endsWith("_HSX") && !cl.name.endsWith("_HSC")) { - if(cl.params.length > 0) - return fields; - - var definedFields = []; - - for(f in fields.copy()) { - if (f == null) - continue; - if (f.name == "new") - continue; - - if(definedFields.contains(f.name)) continue; // no duplicate fields - - var hlNativeMeta = null; - var hasHlNative = false; - for(m in f.meta) - if (m.name == ":hlNative") { - hasHlNative = true; - hlNativeMeta = m; - break; - } - - if(!hasHlNative) continue; - - switch(f.kind) { - case FFun(fun): - if (fun == null) - continue; - if (fun.params != null && fun.params.length > 0) // TODO: Support for this maybe? - continue; - - if(fun.params == null) - fun.params = []; - - var overrideExpr:Expr; - var returns:Bool = !fun.ret.match(TPath({name: "Void"})); - - var printer = new haxe.macro.Printer(); - if(cl.module == "hl.Gc" && fun.ret == null) returns = false; // fix since they don't explicitly set :Void - if(cl.module == "hl.Format" && fun.ret == null) returns = false; // fix since they don't explicitly set :Void - - var name = 'hlf_${f.name}'; - - var arguments = fun.args == null ? [] : [for(a in fun.args) macro $i{a.name}]; - - var funcExpr:Expr = macro @:privateAccess $i{name}($a{arguments}); - if(returns) funcExpr = macro return $funcExpr; - - var cleanMeta = f.meta.copy().filter(function(m) return m.name != ":hlNative"); - var hasBareMeta = hlNativeMeta.params.length == 0; - - var meta = f.meta.copy(); - switch hlNativeMeta { - case {params: []}: - meta = [{name: ":hlNative", params: [macro "std", macro $v{f.name}], pos: Context.currentPos()}].concat(cleanMeta); - case {params: [_.expr => EConst(CString(name))]}: - meta = [{name: ":hlNative", params: [macro "std", macro $v{name}], pos: Context.currentPos()}].concat(cleanMeta); - case {params: [_.expr => EConst(CFloat(version))]}: - var curVersion = Context.definedValue("hl_ver"); - if(curVersion == null) curVersion = ""; - if(version > curVersion) { - meta = cleanMeta; - if(f.meta.filter((m) -> m.name == ":noExpr").length > 0) - Context.error("Missing function body", f.pos); - funcExpr = fun.expr; // restore to default behaviour - } else { - meta = [{name: ":hlNative", params: [macro "std", macro $v{f.name}], pos: Context.currentPos()}].concat(cleanMeta); - } - default: - } - - var field:Field = { - name: name, - pos: Context.currentPos(), - kind: FFun({ - ret: fun.ret, - params: fun.params.copy(), - expr: funcExpr, - args: fun.args.copy() - }), - access: f.access.copy().filter(function(a) return a != APublic && a != APrivate).concat([APrivate]), - meta: meta - }; - fields.push(field); - definedFields.push(f.name); - - // Remove meta from original function - for(m in f.meta.copy()) - if (m.name == ":hlNative") { - f.meta.remove(m); - } - - default: - } - } - - /*if(definedFields.length > 0) { - trace(cl.module); - - var printer = new haxe.macro.Printer(); - for(field in fields) if(field.name.startsWith("hlf_")) - Sys.println(printer.printField(field)); - }*/ - } - - return fields; - } -} -#end \ No newline at end of file diff --git a/libs.xml b/libs.xml index 76995203..403f646d 100644 --- a/libs.xml +++ b/libs.xml @@ -29,8 +29,6 @@ - - diff --git a/project.xml b/project.xml index 618c397a..d2c566fa 100644 --- a/project.xml +++ b/project.xml @@ -207,9 +207,6 @@ - - -
diff --git a/source/funkin/backend/system/macros/HashLinkFixer.hx b/source/funkin/backend/system/macros/HashLinkFixer.hx new file mode 100644 index 00000000..fc530608 --- /dev/null +++ b/source/funkin/backend/system/macros/HashLinkFixer.hx @@ -0,0 +1,76 @@ +package funkin.backend.system.macros; + +#if macro +import haxe.macro.Expr; +import haxe.macro.*; + +using StringTools; + +class HashLinkFixer { + public static function build():Array { + final fields = Context.getBuildFields(), clRef = Context.getLocalClass(); + + if (clRef == null) return fields; + final cl = clRef.get(); + + if ( + cl.isAbstract || cl.isExtern || cl.isInterface || cl.params.length > 0 || + cl.name.endsWith("_Impl_") || cl.name.endsWith("_HSX") || cl.name.endsWith("_HSC") + ) return fields; + + final pos = Context.currentPos(); + for (i in 0...fields.length) { + final f = fields[i]; + if (f == null || f.name == 'new') continue; + + switch (f.kind) { + case FFun(func): + if (func == null) continue; + + var hlNativeMeta = null; + final cleanMeta = f.meta.filter((m) -> { + if (m.name != ':hlNative') return true; + else { + hlNativeMeta = m; + return false; + } + }); + if (hlNativeMeta == null) continue; + + switch (hlNativeMeta.params) { + case []: hlNativeMeta.params = [macro "std", macro $v{f.name}]; + case [_.expr => EConst(CString(name))]: hlNativeMeta.params = [macro "std", macro $v{name}]; + case [_.expr => EConst(CFloat(version))]: + final curVersion = Context.definedValue("hl_ver"); + if (curVersion != null && version > curVersion) { + if (f.meta.filter((m) -> return m.name == ":noExpr").length > 0) + Context.error("Missing function body", hlNativeMeta.pos); + } + else + hlNativeMeta.params = [macro "std", macro $v{f.name}]; + default: + } + + final name = 'hlf_${f.name}'; + fields.push({ + name: name, + pos: pos, + kind: FFun({ret: func.ret, params: func.params, expr: func.expr, args: func.args}), + access: f.access.filter((a) -> return a != APublic && a != APrivate).concat([APrivate]), + meta: [hlNativeMeta] + }); + + final args = func.args == null ? [] : [for (a in func.args) macro $i{a.name}]; + + f.meta = cleanMeta; + func.expr = args.length == 0 ? macro $i{name}() : macro $i{name}($a{args}); + if (func.ret != null && !func.ret.match(TPath({name: 'Void'}))) + func.expr = macro return ${func.expr}; + default: + } + } + + return fields; + } +} +#end \ No newline at end of file diff --git a/source/funkin/backend/system/macros/Macros.hx b/source/funkin/backend/system/macros/Macros.hx index 86eaa3f7..f3bf4adb 100644 --- a/source/funkin/backend/system/macros/Macros.hx +++ b/source/funkin/backend/system/macros/Macros.hx @@ -39,9 +39,9 @@ class Macros { if(Context.defined("sys")) { for(inc in ["sys", "openfl.net", "funkin.backend.system.net"]) { - if(!isHl) - Compiler.include(inc, compathx4); + if(!isHl) Compiler.include(inc, compathx4); else { + // TODO: Hashlink //Compiler.include(inc, compathx4.concat(["sys.net.UdpSocket", "openfl.net.DatagramSocket"]); // fixes FATAL ERROR : Failed to load function std@socket_set_broadcast } @@ -52,6 +52,20 @@ class Macros { } public static function initMacros() { + if (Context.defined("hl")) { + for (c in ["lime", "std", "Math", ""]) Compiler.addGlobalMetadata(c, "@:build(funkin.backend.system.macros.HashLinkFixer.build())"); + } + + final macroPath = 'funkin.backend.system.macros.Macros'; + Compiler.addMetadata('@:build($macroPath.buildLimeAssetLibrary())', 'lime.utils.AssetLibrary'); + } + + public static function buildLimeAssetLibrary():Array { + final fields:Array = Context.getBuildFields(), pos:Position = Context.currentPos(); + + fields.push({name: 'tag', access: [APublic], pos: pos, kind: FVar(macro :funkin.backend.assets.AssetSource)}); + + return fields; } } #end \ No newline at end of file