-
Notifications
You must be signed in to change notification settings - Fork 6
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
Open
t0stiman
wants to merge
12
commits into
master
Choose a base branch
from
build99.7
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 9 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
e225ea5
new using directives for b99.7
t0stiman 0a3b805
fix missing sleepers on tracks
t0stiman 77d5607
ez debug logging
t0stiman d734c0d
update item list
t0stiman d3b13d7
store items verifications
t0stiman d2514c4
fix shops part 1
t0stiman 0e138ec
fix missing scanner in shops
t0stiman d21e7a5
fix shop poster removal
t0stiman 0bcba5f
fix VanillaAsset copying
t0stiman 867d09d
add #if DEBUG to GlobalShopController patch
t0stiman 536274c
get rid of InstantiateDisabled
t0stiman c910d9d
ForceActive -> Reactivate
t0stiman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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))] | ||
|
t0stiman marked this conversation as resolved.
|
||
| 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); | ||
| } | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. | ||
|
t0stiman marked this conversation as resolved.
|
||
| /// </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; | ||
| } | ||
| } | ||
|
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|
t0stiman marked this conversation as resolved.
Outdated
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.