Skip to content

Commit

Permalink
fallback LookupID
Browse files Browse the repository at this point in the history
fixes #21
  • Loading branch information
Aeroluna committed Feb 5, 2022
1 parent 9c625b8 commit 2bc9dff
Showing 1 changed file with 57 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;
using Chroma.Settings;
using CustomJSONData;
using CustomJSONData.CustomBeatmap;
Expand Down Expand Up @@ -316,17 +317,65 @@ private static void GetChildRecursive(Transform gameObject, ref List<Transform>
// this is where i pretend to know what any of this is doing.
private List<GameObjectInfo> LookupID(string[] gameObjectIds, string id, LookupMethod lookupMethod)
{
int length = gameObjectIds.Length;
LookupID_internal(gameObjectIds, length, out IntPtr buffer, ref length, id, lookupMethod);
try
{
int length = gameObjectIds.Length;
LookupID_internal(gameObjectIds, length, out IntPtr buffer, ref length, id, lookupMethod);

int[] arrayRes = new int[length];
Marshal.Copy(buffer, arrayRes, 0, length);
Marshal.FreeCoTaskMem(buffer);

int[] arrayRes = new int[length];
Marshal.Copy(buffer, arrayRes, 0, length);
Marshal.FreeCoTaskMem(buffer);
List<GameObjectInfo> returnList = new(length);
returnList.AddRange(arrayRes.Select(index => _gameObjectInfos[index]));
return returnList;
}
catch (Exception e)
{
Log.Logger.Log("Error running LookupID, falling back to managed code.", Logger.Level.Error);
Log.Logger.Log("Expect long load times...", Logger.Level.Error);
Log.Logger.Log(e.ToString(), Logger.Level.Error);

return LookupID_Legacy(id, lookupMethod);
}
}

List<GameObjectInfo> returnList = new(length);
returnList.AddRange(arrayRes.Select(index => _gameObjectInfos[index]));
// fuck mono regex fuck mono regex fuck mono regex fuck mono regex fuck mono regex
// fuck mono regex fuck mono regex fuck mono regex fuck mono regex fuck mono regex
// fuck mono regex fuck mono regex fuck mono regex fuck mono regex fuck mono regex
// fuck mono regex fuck mono regex fuck mono regex fuck mono regex fuck mono regex
// fuck mono regex fuck mono regex fuck mono regex fuck mono regex fuck mono regex
private List<GameObjectInfo> LookupID_Legacy(string id, LookupMethod lookupMethod)
{
Func<GameObjectInfo, bool> predicate;
switch (lookupMethod)
{
case LookupMethod.Regex:
Regex regex = new(id, RegexOptions.CultureInvariant | RegexOptions.ECMAScript | RegexOptions.Compiled);
predicate = n => regex.IsMatch(n.FullID);
break;

case LookupMethod.Exact:
predicate = n => n.FullID == id;
break;

case LookupMethod.Contains:
predicate = n => n.FullID.Contains(id);
break;

case LookupMethod.StartsWith:
predicate = n => n.FullID.StartsWith(id);
break;

case LookupMethod.EndsWith:
predicate = n => n.FullID.EndsWith(id);
break;

default:
throw new ArgumentOutOfRangeException(nameof(lookupMethod), "Invalid lookup method.");
}

return returnList;
return _gameObjectInfos.Where(predicate).ToList();
}

private void GetAllGameObjects()
Expand Down

0 comments on commit 2bc9dff

Please sign in to comment.