Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed issue when yield returning same request #498

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Nautilus/Assets/ModPrefabCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public void EnterPrefabIntoCache(GameObject prefab)
if(!Entries.ContainsKey(prefabIdentifier.classId))
{
Entries.Add(prefabIdentifier.classId, prefab);
InternalLogger.Debug($"ModPrefabCache: adding prefab {prefab}");
InternalLogger.Debug($"ModPrefabCache: added prefab {prefab}");
}
else // this should never happen
{
Expand Down
19 changes: 15 additions & 4 deletions Nautilus/Assets/ModPrefabRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
namespace Nautilus.Assets;

// request for getting ModPrefab asynchronously
internal class ModPrefabRequest: IPrefabRequest, IEnumerator
internal class ModPrefabRequest: IPrefabRequest
{
internal bool Done { get; private set; }

private readonly PrefabInfo prefabInfo;

private int state = 0;

private CoroutineTask<GameObject> task;

private TaskResult<GameObject> taskResult;

public ModPrefabRequest(PrefabInfo prefabInfo)
Expand Down Expand Up @@ -50,13 +52,22 @@ public object Current
public bool TryGetPrefab(out GameObject result)
{
result = taskResult.Get();
if (!Done)
{
Done = result;
}
return result != null;
}

public bool MoveNext()
{
Init();
return state++ == 0;
if (task == null)
{
return false;
}

return !TryGetPrefab(out _);
}

public void Reset() {}
Expand Down
7 changes: 7 additions & 0 deletions Nautilus/Patchers/PrefabDatabasePatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,14 @@ private static IPrefabRequest GetModPrefabAsync(string classId)
}

if(ModPrefabCache.Requests.TryGetValue(prefabInfo.ClassID, out var request))
{
if (request.Done && !request.TryGetPrefab(out _))
{
return new ModPrefabRequest(prefabInfo);
}

return request;
}

return new ModPrefabRequest(prefabInfo);
}
Expand Down