-
-
Notifications
You must be signed in to change notification settings - Fork 5
Build 99.7 compatibility #140
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
base: master
Are you sure you want to change the base?
Changes from 9 commits
e225ea5
0a3b805
77d5607
d734c0d
d3b13d7
d2514c4
0e138ec
d21e7a5
0bcba5f
867d09d
536274c
c910d9d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,10 +18,26 @@ public abstract class AssetCopier | |
|
|
||
| public static GameObject Instantiate(VanillaAsset asset, bool active = true, bool originShift = true) | ||
| { | ||
| Mapify.LogDebug(() => "Instantiating asset: " + asset); | ||
| var gameObject = GameObject.Instantiate(prefabs[asset], originShift ? WorldMover.OriginShiftParent : null); | ||
| gameObject.SetActive(active); | ||
| return gameObject; | ||
| Mapify.LogDebug($"Instantiating asset: {asset}"); | ||
|
|
||
| if(prefabs.TryGetValue(asset, out var prefab)) | ||
| { | ||
| var parent = originShift ? WorldMover.OriginShiftParent : null; | ||
| if (active) | ||
| { | ||
| var instantiated = GameObject.Instantiate(prefab, parent); | ||
| instantiated.SetActive(true); | ||
| return instantiated; | ||
| } | ||
|
|
||
| // instantiate disabled so Awake, Start etc. don't run | ||
| return UnityUtils.InstantiateDisabled(prefab, parent); | ||
| } | ||
|
|
||
| Mapify.LogError($"Failed to instantiate asset {asset}"); | ||
| var nothing = new GameObject(); | ||
|
||
| nothing.SetActive(false); | ||
| return nothing; | ||
| } | ||
|
|
||
| public static void Cleanup() | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| using UnityEngine; | ||
|
|
||
| namespace Mapify.Components | ||
| { | ||
| /// <summary> | ||
| /// Force the target Gameobject to stay active | ||
| /// </summary> | ||
| public class ForceActive: MonoBehaviour | ||
| { | ||
| public GameObject target; | ||
|
|
||
| private void Update() | ||
| { | ||
| if(target.activeSelf) return; | ||
| target.SetActive(true); | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| using System; | ||
| using System.Linq; | ||
| using DV.Shops; | ||
| using HarmonyLib; | ||
|
|
||
| namespace Mapify.Patches | ||
| { | ||
| [HarmonyPatch(typeof(GlobalShopController), nameof(GlobalShopController.InitializeShopData))] | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need to be doing this for everyone every time? I assume you use this to know what items to add to the enum, so it should probably be behind an
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll add a |
||
| public class GlobalShopControllerPatch | ||
| { | ||
| private static void Postfix(GlobalShopController __instance) | ||
| { | ||
| VerifyItemTypeEnum(__instance); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Verify that the ItemType enum is up to date. | ||
| /// </summary> | ||
| private static void VerifyItemTypeEnum(GlobalShopController __instance) | ||
| { | ||
| var inGameItems = __instance.shopItemsData.Select(dat => dat.item.itemPrefabName.ToLower().Replace("_", "")).ToArray(); | ||
|
|
||
| var inModItems = Enum.GetValues(typeof(Editor.ItemType)) | ||
| .Cast<Editor.ItemType>() | ||
| .Select(itemEnum => itemEnum.ToString().ToLower()) | ||
| .ToArray(); | ||
|
|
||
| bool verifiedSuccessfully = true; | ||
|
|
||
| foreach (var inModItem in inModItems) | ||
| { | ||
| if(inGameItems.Contains(inModItem)) continue; | ||
|
|
||
| Mapify.LogError($"{nameof(ItemType)} '{inModItem}' does not exist in-game"); | ||
| verifiedSuccessfully = false; | ||
| } | ||
|
|
||
| foreach (var inGameItem in inGameItems) | ||
| { | ||
| if(inModItems.Contains(inGameItem)) continue; | ||
|
|
||
| // the keys are intentionally left out | ||
| if(inGameItem.StartsWith("key")) continue; | ||
|
|
||
| Mapify.LogWarning($"Item '{inGameItem}' does not exist in enum {nameof(ItemType)}"); | ||
| } | ||
|
|
||
| if(verifiedSuccessfully) return; | ||
|
|
||
| Mapify.LogDebug("Items in game:"); | ||
| foreach (var inGameItem in inGameItems) | ||
| { | ||
| Mapify.LogDebug(inGameItem); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| using DV; | ||
| using DV.Shops; | ||
| using HarmonyLib; | ||
| using Mapify.Components; | ||
| using Mapify.Map; | ||
| using VLB; | ||
|
|
||
| namespace Mapify.Patches | ||
| { | ||
| /// <summary> | ||
| /// Something keeps setting the shop scanner inactive. This patch prevents that. | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should find what's causing this, not add some weird hacky workaround. You should be able to see what's happening by inspecting the stacktrace from the OnEnable/OnDisable methods of something attached to an item.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the stracktrace suggestion, but I still can't figure it out. The only thing triggering this is
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I changed the Forceactive class to Reactivate, which sets the target object to active once and then destroys itself. |
||
| /// </summary> | ||
| [HarmonyPatch(typeof(ItemLocationForcer), nameof(ItemLocationForcer.Awake))] | ||
| public class ItemLocationForcer_Awake_Patch | ||
| { | ||
| private static void Postfix(ItemLocationForcer __instance) | ||
| { | ||
| if(__instance.itemGO == null || Maps.IsDefaultMap) return; | ||
| if(!__instance.itemGO.TryGetComponent<ShopScanner>(out var shopScanner)) return; | ||
|
|
||
| Mapify.LogDebug($"Forcing scanner at '{shopScanner.gameObject.GetPath()}' active"); | ||
| var forceActive = __instance.gameObject.GetOrAddComponent<ForceActive>(); | ||
| forceActive.enabled = true; | ||
| forceActive.target = shopScanner.gameObject; | ||
| } | ||
| } | ||
|
|
||
| [HarmonyPatch(typeof(ItemLocationForcer), nameof(ItemLocationForcer.OnDisable))] | ||
| public class ItemLocationForcer_OnDisable_Patch | ||
| { | ||
| private static void Postfix(ItemLocationForcer __instance) | ||
| { | ||
| if(__instance.itemGO == null || Maps.IsDefaultMap) return; | ||
| if(!__instance.itemGO.TryGetComponent<ForceActive>(out var forceActive)) return; | ||
| forceActive.enabled = false; | ||
| } | ||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| using HarmonyLib; | ||
| using DV.Optimizers; | ||
| using HarmonyLib; | ||
| using UnityEngine; | ||
|
|
||
| namespace Mapify.Patches | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| using DV.Shops; | ||
| using HarmonyLib; | ||
| using Mapify.Map; | ||
|
|
||
| namespace Mapify.Patches | ||
| { | ||
| [HarmonyPatch(typeof(ShelfPlacer), nameof(ShelfPlacer.TryPlaceOnAnyShelf))] | ||
| public class ShelfPlacer_TryPlaceOnAnyShelf_Patch | ||
| { | ||
| private static void Postfix(ShelfItem item, bool __result) | ||
| { | ||
| if(Maps.IsDefaultMap || !__result) return; | ||
| item.gameObject.SetActive(true); | ||
| } | ||
| } | ||
| } |
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| using UnityEngine; | ||
|
|
||
| namespace Mapify | ||
| { | ||
| // source: https://discussions.unity.com/t/instantiate-inactive-object/39830/5 | ||
| public static class UnityUtils | ||
| { | ||
| /// <summary> | ||
| /// Will instantiate an object disabled preventing it from calling Awake/OnEnable. | ||
| /// </summary> | ||
| public static T InstantiateDisabled<T>(T original, Transform parent = null, bool worldPositionStays = false) where T : Object | ||
| { | ||
| if (!GetActiveState(original)) | ||
| { | ||
| return Object.Instantiate(original, parent, worldPositionStays); | ||
| } | ||
|
|
||
| (GameObject coreObject, Transform coreObjectTransform) = CreateDisabledCoreObject(parent); | ||
| T instance = Object.Instantiate(original, coreObjectTransform, worldPositionStays); | ||
| SetActiveState(instance, false); | ||
| SetParent(instance, parent, worldPositionStays); | ||
| Object.Destroy(coreObject); | ||
| return instance; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Will instantiate an object disabled preventing it from calling Awake/OnEnable. | ||
| /// </summary> | ||
| public static T InstantiateDisabled<T>(T original, Vector3 position, Quaternion rotation, Transform parent = null) where T : Object | ||
| { | ||
| if (!GetActiveState(original)) | ||
| { | ||
| return Object.Instantiate(original, position, rotation, parent); | ||
| } | ||
|
|
||
| (GameObject coreObject, Transform coreObjectTransform) = CreateDisabledCoreObject(parent); | ||
| T instance = Object.Instantiate(original, position, rotation, coreObjectTransform); | ||
| SetActiveState(instance, false); | ||
| SetParent(instance, parent, false); | ||
| Object.Destroy(coreObject); | ||
| return instance; | ||
| } | ||
|
|
||
| private static (GameObject coreObject, Transform coreObjectTransform) CreateDisabledCoreObject(Transform parent = null) | ||
| { | ||
| GameObject coreObject = new GameObject(string.Empty); | ||
| coreObject.SetActive(false); | ||
| Transform coreObjectTransform = coreObject.transform; | ||
| coreObjectTransform.SetParent(parent); | ||
|
|
||
| return (coreObject, coreObjectTransform); | ||
| } | ||
|
|
||
| private static bool GetActiveState<T>(T @object) where T : Object | ||
| { | ||
| switch (@object) | ||
| { | ||
| case GameObject gameObject: | ||
| { | ||
| return gameObject.activeSelf; | ||
| } | ||
| case Component component: | ||
| { | ||
| return component.gameObject.activeSelf; | ||
| } | ||
| default: | ||
| { | ||
| return false; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private static void SetActiveState<T>(T @object, bool state) where T : Object | ||
| { | ||
| switch (@object) | ||
| { | ||
| case GameObject gameObject: | ||
| { | ||
| gameObject.SetActive(state); | ||
|
|
||
| break; | ||
| } | ||
| case Component component: | ||
| { | ||
| component.gameObject.SetActive(state); | ||
|
|
||
| break; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private static void SetParent<T>(T @object, Transform parent, bool worldPositionStays) where T : Object | ||
| { | ||
| switch (@object) | ||
| { | ||
| case GameObject gameObject: | ||
| { | ||
| gameObject.transform.SetParent(parent, worldPositionStays); | ||
|
|
||
| break; | ||
| } | ||
| case Component component: | ||
| { | ||
| component.transform.SetParent(parent, worldPositionStays); | ||
|
|
||
| break; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.