Skip to content
This repository has been archived by the owner on Jan 10, 2022. It is now read-only.

Commit

Permalink
Merge pull request #11 from Arion-Kun/worlds
Browse files Browse the repository at this point in the history
World Properties Change to PropInfo Reflection
  • Loading branch information
JustArion authored Jun 8, 2021
2 parents 316add6 + a25e005 commit d3e8100
Showing 1 changed file with 56 additions and 2 deletions.
58 changes: 56 additions & 2 deletions Core.cs
Original file line number Diff line number Diff line change
Expand Up @@ -208,12 +208,66 @@ private static Il2CppSystem.Object FindInstance(IReflect WhereLooking, Type What

return null;
}
private static PropertyInfo FindProperty(IReflect WhereLooking, Type WhatLooking)
{
try
{
var propertyInfos = WhereLooking.GetProperties(BindingFlags.Public | BindingFlags.Static)
.Where(m => m.PropertyType == WhatLooking).ToArray();
if (propertyInfos.Length > 0)
{
foreach(var pinfo in propertyInfos)
{
if (!pinfo.Name.StartsWith("prop_")) continue;
return pinfo;
}

Console.WriteLine("debug: found " + WhereLooking + " : " + WhatLooking);
return propertyInfos.First();
}

MelonLogger.Error("[FindInstance] MethodInfo for " + WhatLooking.Name + " is null");
}
catch (Exception e)
{
MelonLogger.Error($"[FindInstance] {e}");
}

return null;
}
internal static void SetParent(this GameObject obj, GameObject target)
{
obj.transform.parent = target.transform;
}
private static ApiWorld currentRoom => FindInstance(typeof(RoomManager), typeof(ApiWorld)).TryCast<ApiWorld>();
private static ApiWorldInstance currentWorldInstance => FindInstance(typeof(RoomManager), typeof(ApiWorldInstance)).TryCast<ApiWorldInstance>();

private static PropertyInfo _propertyInfoCurrentRoom;

private static ApiWorld currentRoom
{
get
{
if (_propertyInfoCurrentRoom != null) return _propertyInfoCurrentRoom.GetMethod.Invoke(null, null) as ApiWorld;
_propertyInfoCurrentRoom = FindProperty(typeof(RoomManager), typeof(ApiWorld)); //FindInstance(typeof(RoomManager), typeof(ApiWorld)).TryCast<ApiWorld>();
if (_propertyInfoCurrentRoom != null) return _propertyInfoCurrentRoom.GetMethod.Invoke(null, null) as ApiWorld;
MelonLogger.Error("Unable to Find 'currentRoom' PropertyInfo");
return null;
}
}

private static PropertyInfo _propertyInfoCurrentWorldInstance;

private static ApiWorldInstance currentWorldInstance
{
get
{
if (_propertyInfoCurrentWorldInstance != null) return _propertyInfoCurrentWorldInstance.GetMethod.Invoke(null, null) as ApiWorldInstance;
_propertyInfoCurrentWorldInstance = FindProperty(typeof(RoomManager), typeof(ApiWorldInstance)); //FindInstance(typeof(RoomManager), typeof(ApiWorld)).TryCast<ApiWorld>();
if (_propertyInfoCurrentWorldInstance != null) return _propertyInfoCurrentWorldInstance.GetMethod.Invoke(null, null) as ApiWorldInstance;
MelonLogger.Error("Unable to Find 'currentWorldInstance' PropertyInfo");
return null;
}
//FindInstance(typeof(RoomManager), typeof(ApiWorldInstance)).TryCast<ApiWorldInstance>();
}
/// <summary>
/// Current User Instance Cache.
/// </summary>
Expand Down

0 comments on commit d3e8100

Please sign in to comment.