1010using UnityEngine ;
1111
1212namespace PolyMod . Managers ;
13+
1314public static class Main
1415{
1516 internal const int MAX_TECH_TIER = 100 ;
@@ -179,8 +180,8 @@ private static void GameModeScreen_Init(GameModeScreen __instance)
179180
180181 [ HarmonyPrefix ]
181182 [ HarmonyPatch ( typeof ( TechView ) , nameof ( TechView . CreateNode ) ) ]
182- public static bool TechView_CreateNode ( TechView __instance , TechData data , TechItem parentItem , float angle )
183- {
183+ public static bool TechView_CreateNode ( TechView __instance , TechData data , TechItem parentItem , float angle )
184+ {
184185 GameLogicData gameLogicData = GameManager . GameState . GameLogicData ;
185186 TribeData tribeData = gameLogicData . GetTribeData ( GameManager . LocalPlayer . tribe ) ;
186187 float baseAngle = 360 / gameLogicData . GetOverride ( gameLogicData . GetTechData ( TechData . Type . Basic ) , tribeData ) . techUnlocks . Count ;
@@ -358,6 +359,14 @@ internal static void Load(JObject gameLogicdata)
358359 ) ;
359360 continue ;
360361 }
362+ if ( Regex . IsMatch ( Path . GetFileName ( file . name ) , @"^prefab(_.*)?\.json$" ) )
363+ {
364+ Loader . LoadPrefabInfoFile (
365+ mod ,
366+ file
367+ ) ;
368+ continue ;
369+ }
361370
362371 switch ( Path . GetExtension ( file . name ) )
363372 {
@@ -380,5 +389,104 @@ internal static void Load(JObject gameLogicdata)
380389 }
381390 stopwatch . Stop ( ) ;
382391 Plugin . logger . LogInfo ( $ "Loaded all mods in { stopwatch . ElapsedMilliseconds } ms") ;
392+ Unit baseUnit = PrefabManager . units [ GetSkinnedHashKey ( 2 , SkinType . Default ) ] ;
393+ if ( baseUnit != null )
394+ {
395+ foreach ( System . Collections . Generic . KeyValuePair < string , PolyMod . Managers . Visual . PrefabInfo > valuePair in Registry . prefabInfos )
396+ {
397+ Console . Write ( valuePair . Key ) ;
398+ PolyMod . Managers . Visual . PrefabInfo info = valuePair . Value ;
399+ SkinVisualsReference ? skinComp = baseUnit . GetComponent < SkinVisualsReference > ( ) ;
400+ if ( skinComp != null )
401+ {
402+ Transform head = KeepOnlyChildByName ( baseUnit . transform , "Head" ) ;
403+ skinComp . visualParts = new Il2CppInterop . Runtime . InteropTypes . Arrays . Il2CppReferenceArray < SkinVisualsReference . VisualPart > ( 1 ) ;
404+ SkinVisualsReference . VisualPart visualPart = new SkinVisualsReference . VisualPart ( ) ;
405+ visualPart . DefaultSpriteName = "head" ;
406+ visualPart . visualPart = head . gameObject ;
407+ skinComp . visualParts [ 0 ] = visualPart ;
408+ PrefabManager . units [ GetSkinnedHashKey ( 53 , SkinType . Default ) ] = baseUnit ;
409+ }
410+ }
411+ }
412+ else
413+ {
414+ Console . Write ( "NULLLLLLLL" ) ;
415+ }
416+ }
417+
418+ public static Transform KeepOnlyChildByName ( Transform parent , string nameToKeep )
419+ {
420+ Console . Write ( "0" ) ;
421+ var spriteContainer = parent . GetChild ( 0 ) ;
422+ Console . Write ( "1" ) ;
423+ int childCount = spriteContainer . childCount ;
424+ Transform ? toReturn = null ;
425+ for ( int i = 0 ; i < childCount ; i ++ )
426+ {
427+ var child = spriteContainer . GetChild ( i ) ;
428+ Console . Write ( child . gameObject . name ) ;
429+ if ( child . gameObject . name != nameToKeep )
430+ {
431+ GameObject . Destroy ( child . gameObject ) ;
432+ }
433+ else
434+ {
435+ toReturn = child . transform ;
436+ }
437+ }
438+ return toReturn ;
439+ }
440+
441+ private static void GetTypeAndSkin ( int hash , out int type , out SkinType skin )
442+ {
443+ skin = ( SkinType ) ( hash / 1000 ) ;
444+ type = hash % 1000 ;
445+ }
446+
447+ private static int GetSkinnedHashKey ( int type , SkinType skin )
448+ {
449+ return type + ( ( int ) skin * 1000 ) ;
450+ }
451+
452+ public static void GetPrefabTree ( Transform transform , int depth )
453+ {
454+ if ( transform == null ) return ;
455+
456+ GameObject obj = transform . gameObject ;
457+ string indent = new string ( ' ' , depth * 2 ) ;
458+ Console . WriteLine ( $ "{ indent } GameObject: { obj . name } ") ;
459+
460+ var components = obj . GetComponents < Component > ( ) ;
461+ foreach ( var comp in components )
462+ {
463+ if ( comp == null ) continue ;
464+
465+ var typeName = comp . GetIl2CppType ( ) . Name ;
466+
467+ if ( typeName == "SkinVisualsReference" )
468+ {
469+ SkinVisualsReference ? skinComp = comp . TryCast < SkinVisualsReference > ( ) ;
470+ if ( skinComp != null )
471+ {
472+ Console . WriteLine ( $ "{ indent } - Component: { typeName } ") ;
473+ foreach ( SkinVisualsReference . VisualPart part in skinComp . visualParts )
474+ {
475+ if ( part . visualPart == null ) continue ;
476+ Console . WriteLine ( $ "{ indent } - VS: { part . visualPart . GetIl2CppType ( ) . Name } ") ;
477+ Console . WriteLine ( $ "{ indent } - VS: { part . DefaultSpriteName } ") ;
478+ Console . WriteLine ( $ "{ indent } - VS: { part . visualPart . transform . position } ") ;
479+ part . visualPart . transform . position = new Vector3 ( 0 , 0 , 0 ) ;
480+ }
481+ }
482+ }
483+ }
484+
485+ int childCount = transform . childCount ;
486+ for ( int i = 0 ; i < childCount ; i ++ )
487+ {
488+ var child = transform . GetChild ( i ) ;
489+ GetPrefabTree ( child , depth + 1 ) ;
490+ }
383491 }
384492}
0 commit comments