Skip to content
Open
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
9 changes: 7 additions & 2 deletions Mapify.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@ EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Release|Any CPU = Release|Any CPU
Debug|Any CPU = Debug|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{57D181A9-9D9D-4EBA-BBDD-9172EEB79983}.Release|Any CPU.ActiveCfg = Release|Any CPU
{57D181A9-9D9D-4EBA-BBDD-9172EEB79983}.Release|Any CPU.Build.0 = Release|Any CPU
{57D181A9-9D9D-4EBA-BBDD-9172EEB79984}.Release|Any CPU.ActiveCfg = Release|Any CPU
{57D181A9-9D9D-4EBA-BBDD-9172EEB79984}.Release|Any CPU.Build.0 = Release|Any CPU
{57D181A9-9D9D-4EBA-BBDD-9172EEB79984}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{57D181A9-9D9D-4EBA-BBDD-9172EEB79984}.Debug|Any CPU.Build.0 = Debug|Any CPU
{57D181A9-9D9D-4EBA-BBDD-9172EEB79983}.Release|Any CPU.ActiveCfg = Release|Any CPU
{57D181A9-9D9D-4EBA-BBDD-9172EEB79983}.Release|Any CPU.Build.0 = Release|Any CPU
{57D181A9-9D9D-4EBA-BBDD-9172EEB79983}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{57D181A9-9D9D-4EBA-BBDD-9172EEB79983}.Debug|Any CPU.Build.0 = Debug|Any CPU
EndGlobalSection
EndGlobal
3 changes: 2 additions & 1 deletion Mapify/AssetCopiers/AssetCopier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ public abstract class AssetCopier

public static GameObject Instantiate(VanillaAsset asset, bool active = true, bool originShift = true)
{
Mapify.LogDebug(() => "Instantiating asset: " + asset);
Mapify.LogDebug("Instantiating asset: " + asset);

var gameObject = GameObject.Instantiate(prefabs[asset], originShift ? WorldMover.OriginShiftParent : null);
gameObject.SetActive(active);
return gameObject;
Expand Down
3 changes: 1 addition & 2 deletions Mapify/AssetCopiers/GameContentCopier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,7 @@ public class GameContentCopier : AssetCopier
foreach (var module in shop.GetComponentsInChildren<ScanItemCashRegisterModule>())
Object.Destroy(module.gameObject);

Object.Destroy(shop.transform.FindChildByName("Stopwatch"));
Object.Destroy(shop.transform.FindChildByName("PosterAnchor"));
Object.Destroy(shop.gameObject.FindChildByName("PosterAnchor"));

yield return (VanillaAsset.StoreObject, shop.gameObject);

Expand Down
20 changes: 20 additions & 0 deletions Mapify/Components/Reactivate.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using UnityEngine;

namespace Mapify.Components
{
/// <summary>
/// Force the target Gameobject to stay active
/// </summary>
public class Reactivate: MonoBehaviour
{
public GameObject target;

private void Update()
{
if(target.activeSelf) return;

target.SetActive(true);
Destroy(this);
}
}
}
10 changes: 10 additions & 0 deletions Mapify/Mapify.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,22 @@ private static void Patch()

#region Logging

public static void LogDebugExtreme(object msg)
{
LogDebugExtreme(() => msg);
}

public static void LogDebugExtreme(Func<object> resolver)
{
if (Settings.ExtremelyVerboseLogging)
LogDebug(resolver);
}

public static void LogDebug(object msg)
{
LogDebug(() => msg);
}

public static void LogDebug(Func<object> resolver)
{
if (Settings.VerboseLogging)
Expand Down
59 changes: 59 additions & 0 deletions Mapify/Patches/GlobalShopControllerPatch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using System;
using System.Linq;
using DV.Shops;
using HarmonyLib;

namespace Mapify.Patches
{
#if DEBUG
[HarmonyPatch(typeof(GlobalShopController), nameof(GlobalShopController.InitializeShopData))]
Copy link
Owner

Choose a reason for hiding this comment

The 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 #if DEBUG directive or something similar.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add a #if DEBUG.

public class GlobalShopController_InitializeShopData_Patch
{
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);
}
}
}
#endif
}
39 changes: 39 additions & 0 deletions Mapify/Patches/ItemLocationForcerPatch.cs
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.
Copy link
Owner

Choose a reason for hiding this comment

The 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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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.

private void OnDisable()
        {
            var trace = new System.Diagnostics.StackTrace();
            Mapify.LogDebug($"ForceActive.OnDisable");
            Mapify.LogDebug(trace.ToString());
        }

The only thing triggering this is PlayerDistanceMultipleGameObjectsOptimizer when I walk away from the shop. This is expected.
But if I start the game while already at the shop, nothing triggers OnDisable and the scanner is still inactive.
Even if I set the scanner to active in StoreSetup or ItemLocationForcer_Awake_Patch the scanner is inactive.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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.
Can you allow this one hack? Because this PR is blocking all the others 😬

/// </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 reactivate = __instance.gameObject.GetOrAddComponent<Reactivate>();
reactivate.enabled = true;
reactivate.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<Reactivate>(out var reactivate)) return;
reactivate.enabled = false;
}
}

}
3 changes: 2 additions & 1 deletion Mapify/Patches/PlayerDistanceGameObjectsDisablerPatch.cs
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
Expand Down
21 changes: 4 additions & 17 deletions Mapify/Patches/RailwayMeshGeneratorPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,25 +52,12 @@ private static bool Prefix(RailwayMeshGenerator __instance, TrackChunk chunk, Li
[HarmonyPatch(typeof(RailwayMeshGenerator), nameof(RailwayMeshGenerator.UpdateSleepersData))]
public class RailwayMeshGenerator_UpdateSleepersData_Patch
{
private static bool Prefix(TrackChunk chunk, ref JobHandle ___sleepersHandle, NativeList<Vector3> ___sleepersAnchorsPositions, NativeList<float> ___sleepersAnchorsTransformBufferData)
private static bool Prefix(TrackChunk chunk)
{
if (Maps.IsDefaultMap)
return true;
if (Maps.IsDefaultMap) return true;

Track track = chunk.track.GetComponent<Track>();
if (!track.generateSleepers)
return false;

___sleepersHandle = new PlaceSleepersAppendJob(
___sleepersAnchorsTransformBufferData,
___sleepersAnchorsPositions,
chunk.pointSet,
chunk.minIndex,
chunk.maxIndex,
chunk.track.baseType.randomizeAnchorDirection,
chunk.track.baseType.sleeperVerticalOffset
).Schedule(___sleepersHandle);
return false;
var track = chunk.track.GetComponent<Track>();
return track.generateSleepers;
}
}
}
16 changes: 16 additions & 0 deletions Mapify/Patches/ShelfPlacerPatch.cs
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);
}
}
}
1 change: 1 addition & 0 deletions Mapify/SceneInitializers/GameContent/StoreSetup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using DV.CashRegister;
using DV.Optimizers;
using DV.Printers;
using DV.Shops;
using DV.Utils;
Expand Down
10 changes: 5 additions & 5 deletions MapifyEditor/Store/ItemType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,6 @@ public enum ItemType
PaintCan = 178,
PaintCanMuseum = 179,
PaintCanSand = 180,
Crate = 181,
CratePlastic = 182,
PaperBox = 183,
BeaconAmber = 184,
BeaconRed = 185,
BeaconBlue = 186,
Expand All @@ -118,7 +115,7 @@ public enum ItemType
SwitchSetter = 190,
SwitchAlternating = 191,

//build 99.4
// build 99.4
ItemContainerBriefcase = 192,
ItemContainerFolder = 193,
Nameplate = 194,
Expand All @@ -142,6 +139,9 @@ public enum ItemType
ItemContainerFolderBlue = 212,
ItemContainerFolderRed = 213,
ItemContainerFolderYellow = 214,
ItemContainerRegistrator = 215
ItemContainerRegistrator = 215,

// build 99.7
GooglyEye = 216
}
}
8 changes: 4 additions & 4 deletions MapifyEditor/Vanilla/VanillaAsset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,6 @@ public enum VanillaAsset
StoreItemPaintCan = 178,
StoreItemPaintCanMuseum = 179,
StoreItemPaintCanSand = 180,
StoreItemCrate = 181,
StoreItemCratePlastic = 182,
StoreItemPaperBox = 183,
StoreItemBeaconAmber = 184,
StoreItemBeaconRed = 185,
StoreItemBeaconBlue = 186,
Expand Down Expand Up @@ -218,7 +215,10 @@ public enum VanillaAsset
StoreItemItemContainerFolderBlue = 212,
StoreItemItemContainerFolderRed = 213,
StoreItemItemContainerFolderYellow = 214,
StoreItemItemContainerRegistrator = 215
StoreItemItemContainerRegistrator = 215,

// build 99.7
StoreItemGooglyEye = 216

#endregion
}
Expand Down