Code updates

This commit is contained in:
pan.codes 2025-06-08 21:40:03 +02:00
parent a430310324
commit 393de5e06a
14 changed files with 216 additions and 31 deletions

View file

@ -0,0 +1,7 @@
using HarmonyLib;
using TurnTheGameOn.SimpleTrafficSystem;
namespace SpacemarketSimulator.Patches
{
[HarmonyPatch(typeof(AITrafficLight), "EnableGreenLight")] public static class AITrafficLight_EnableGreenLight_Patch { public static void Postfix(AITrafficLight __instance) => __instance.DisableAllLights(); }
}

View file

@ -0,0 +1,7 @@
using HarmonyLib;
using TurnTheGameOn.SimpleTrafficSystem;
namespace SpacemarketSimulator.Patches
{
[HarmonyPatch(typeof(AITrafficLight), "EnableRedLight")] public static class AITrafficLight_EnableRedLight_Patch { public static void Postfix(AITrafficLight __instance) => __instance.DisableAllLights(); }
}

View file

@ -0,0 +1,7 @@
using HarmonyLib;
using TurnTheGameOn.SimpleTrafficSystem;
namespace SpacemarketSimulator.Patches
{
[HarmonyPatch(typeof(AITrafficLight), "EnableYellowLight")] public static class AITrafficLight_EnableYellowLight_Patch { public static void Postfix(AITrafficLight __instance) => __instance.DisableAllLights(); }
}

View file

@ -0,0 +1,14 @@
using Cinemachine;
using HarmonyLib;
namespace SpacemarketSimulator.Patches
{
[HarmonyPatch(typeof(CinemachineVirtualCamera), "CalculateNewState")]
public static class CinemachineVirtualCamera_CalculateNewState_Patch
{
public static void Postfix(ref CameraState __result)
{
__result.Lens.FarClipPlane = 1500;
}
}
}

View file

@ -0,0 +1,21 @@
using HarmonyLib;
using System;
using UnityEngine;
using UnityEngine.UI;
namespace SpacemarketSimulator.Patches
{
[HarmonyPatch(typeof(MainMenuManager), "Awake")]
public static class MainMenuManager_Awake_Patch
{
public static void Postfix(MainMenuManager __instance)
{
var bg = new Texture2D(1920, 1080);
bg.LoadImage(Properties.Resources.bg);
var image = __instance.gameObject.transform.GetChild(0).gameObject.GetComponent<Image>();
Console.WriteLine(image == null);
image.sprite = Sprite.Create(bg, new Rect(0, 0, bg.width, bg.height), new Vector2(0.5f, 0.5f)); ;
__instance.gameObject.transform.GetChild(1).gameObject.SetActive(false);
}
}
}

View file

@ -0,0 +1,16 @@
using HarmonyLib;
using System.Linq;
namespace SpacemarketSimulator.Patches
{
[HarmonyPatch(typeof(NPCTrafficManager), "SpawnNPC")]
public static class NPCTrafficManager_SpawnNPC_Patch
{
public static void Postfix(NPCTrafficManager __instance)
{
WaypointNavigator npc = __instance.m_ActiveNPCs.Last();
npc.gameObject.SetActive(false);
}
}
}

View file

@ -0,0 +1,13 @@
using HarmonyLib;
namespace SpacemarketSimulator.Patches
{
[HarmonyPatch(typeof(SectionManager), "UpgradeStore")]
public static class SectionManager_UpgradeStore_Patch
{
public static void Postfix()
{
//Plugin.DisableStandardEnvironment();
}
}
}

120
Plugin.cs
View file

@ -1,7 +1,13 @@
using BepInEx; using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib; using HarmonyLib;
using MyBox;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using UnityEngine; using UnityEngine;
using UnityEngine.Assertions.Must;
using UnityEngine.SceneManagement; using UnityEngine.SceneManagement;
namespace SpacemarketSimulator namespace SpacemarketSimulator
@ -9,9 +15,13 @@ namespace SpacemarketSimulator
[BepInPlugin(PluginInfo.PLUGIN_GUID, PluginInfo.PLUGIN_NAME, PluginInfo.PLUGIN_VERSION)] [BepInPlugin(PluginInfo.PLUGIN_GUID, PluginInfo.PLUGIN_NAME, PluginInfo.PLUGIN_VERSION)]
public class Plugin : BaseUnityPlugin public class Plugin : BaseUnityPlugin
{ {
public const string SpaceShader = "Universal Render Pipeline/Lit"; public static Vector3 NPCArrivalPoint = new Vector3(6, -0.06f, 3);
public static ConfigEntry<string> SpaceShader;
public static ConfigEntry<bool> MoveSkyboxWithPlayer;
public static ManualLogSource SLogger;
private void Awake() private void Awake()
{ {
SLogger = Logger;
Logger.LogInfo($"Plugin {PluginInfo.PLUGIN_GUID} is loaded! Applying patch..."); Logger.LogInfo($"Plugin {PluginInfo.PLUGIN_GUID} is loaded! Applying patch...");
Harmony harmony = new Harmony(PluginInfo.PLUGIN_GUID); Harmony harmony = new Harmony(PluginInfo.PLUGIN_GUID);
harmony.PatchAll(); harmony.PatchAll();
@ -21,6 +31,9 @@ namespace SpacemarketSimulator
Logger.LogInfo("Available shader: " + shader.name); Logger.LogInfo("Available shader: " + shader.name);
} }
SpaceShader = Config.Bind("", "Space Shader", "Universal Render Pipeline/Particles/Unlit");
MoveSkyboxWithPlayer = Config.Bind("", "Move Skybox with Player", true);
SceneManager.sceneLoaded += SceneManager_sceneLoaded; SceneManager.sceneLoaded += SceneManager_sceneLoaded;
} }
private Dictionary<string, Texture2D> TextureCache { get; set; } = new(); private Dictionary<string, Texture2D> TextureCache { get; set; } = new();
@ -36,8 +49,8 @@ namespace SpacemarketSimulator
} }
private void ApplySkybox(Transform container) private void ApplySkybox(Transform container)
{ {
float skyboxDistance = 20; float skyboxDistance = 500;
float skyboxScale = 4; float skyboxScale = 100;
PrimitiveType type = PrimitiveType.Plane; PrimitiveType type = PrimitiveType.Plane;
var xmPlane = GameObject.CreatePrimitive(type); var xmPlane = GameObject.CreatePrimitive(type);
@ -60,7 +73,11 @@ namespace SpacemarketSimulator
{ {
x.plane.transform.SetParent(container); x.plane.transform.SetParent(container);
var rend = x.plane.GetComponent<MeshRenderer>(); var rend = x.plane.GetComponent<MeshRenderer>();
rend.material.shader = Shader.Find(SpaceShader); rend.material.shader = Shader.Find(Plugin.SpaceShader.Value);
rend.allowOcclusionWhenDynamic = false;
rend.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
rend.receiveShadows = false;
SpaceShader.SettingChanged += (a, b) => { try { rend.material.shader = Shader.Find(SpaceShader.Value); } catch (Exception e) { Logger.LogError(e); } };
rend.material.mainTexture = LoadTexture(x.texture); rend.material.mainTexture = LoadTexture(x.texture);
}); });
@ -71,27 +88,27 @@ namespace SpacemarketSimulator
var yptd = TransformDefiner.AddToGameObject(ypPlane); var yptd = TransformDefiner.AddToGameObject(ypPlane);
yptd.position = new Vector3(0, skyboxDistance - 0.001f, 0); yptd.position = new Vector3(0, skyboxDistance - 0.001f, 0);
yptd.eulerAngles = new Vector3(0, 90, 0); yptd.eulerAngles = new Vector3(180, -90, 0);
yptd.localScale = new Vector3(skyboxScale, 1, -skyboxScale); yptd.localScale = new Vector3(-skyboxScale, 1, -skyboxScale);
var xmtd = TransformDefiner.AddToGameObject(xmPlane); var xmtd = TransformDefiner.AddToGameObject(xmPlane);
xmtd.position = new Vector3(-skyboxDistance, 0, 0); xmtd.position = new Vector3(-skyboxDistance + 0.001f, 0, 0);
xmtd.eulerAngles = new Vector3(90, 0, 90); xmtd.eulerAngles = new Vector3(90, 0, 90);
xmtd.localScale = new Vector3(skyboxScale, 1, -skyboxScale); xmtd.localScale = new Vector3(skyboxScale, -1, -skyboxScale);
var xptd = TransformDefiner.AddToGameObject(xpPlane); var xptd = TransformDefiner.AddToGameObject(xpPlane);
xptd.localScale = new Vector3(skyboxScale, 1, skyboxScale); xptd.localScale = new Vector3(skyboxScale, 1, skyboxScale);
xptd.position = new Vector3(skyboxDistance, 0, 0); xptd.position = new Vector3(skyboxDistance - 0.001f, 0, 0);
xptd.eulerAngles = new Vector3(-90, 0, 90); xptd.eulerAngles = new Vector3(-90, 0, 90);
var zmtd = TransformDefiner.AddToGameObject(zmPlane); var zmtd = TransformDefiner.AddToGameObject(zmPlane);
zmtd.position = new Vector3(0, 0, -skyboxDistance); zmtd.position = new Vector3(0, 0, -skyboxDistance + 0.001f);
zmtd.eulerAngles = new Vector3(90, 0, 180); zmtd.eulerAngles = new Vector3(90, 180, 180);
zmtd.localScale = new Vector3(skyboxScale, 1, -skyboxScale); zmtd.localScale = new Vector3(-skyboxScale, 1, -skyboxScale);
var zptd = TransformDefiner.AddToGameObject(zpPlane); var zptd = TransformDefiner.AddToGameObject(zpPlane);
zptd.localScale = new Vector3(skyboxScale, 1, skyboxScale); zptd.localScale = new Vector3(skyboxScale, 1, skyboxScale);
zptd.position = new Vector3(0, 0, skyboxDistance); zptd.position = new Vector3(0, 0, skyboxDistance - 0.001f);
zptd.eulerAngles = new Vector3(-90, 0, 0); zptd.eulerAngles = new Vector3(-90, 0, 0);
} }
public void Update() public void Update()
@ -101,15 +118,64 @@ namespace SpacemarketSimulator
Player.transform.position = new Vector3(4.52f, -0.06f, 4.85f); Player.transform.position = new Vector3(4.52f, -0.06f, 4.85f);
} }
} }
private void SceneManager_sceneLoaded(Scene arg0, LoadSceneMode arg1) public static GameObject DisableStandardEnvironment()
{ {
string[] piecesToLeaveEnabled = new string[]
{
"Sidewalk_4x4_A_01 (1)",
"Sidewalk_4x4_A_01 (3)",
"Sidewalk_4x2_A_02 (3)",
"Sidewalk_4x2_A_01 (2)",
"Sidewalk_4x4_A_02 (3)",
"Sidewalk_4x4_A_02 (1)",
"Descent_Store (10)",
"Street",
"Showcase_Store_08",
"Wall_2m_01",
"Wall_4m_01",
"NI_Wall_4m_01",
"Store Status Sign",
"Table Canvas",
"Placement Obstacle",
};
var standardEnvironmentContainer = GameObject.Find("Environment v0.1.1"); var standardEnvironmentContainer = GameObject.Find("Environment v0.1.1");
if (standardEnvironmentContainer == null) return; GameObject street = null;
standardEnvironmentContainer.SetActive(false); if (standardEnvironmentContainer == null) return null;
for (int i = 0; i < standardEnvironmentContainer.transform.childCount; i++)
{
var child = standardEnvironmentContainer.transform.GetChild(i).gameObject;
if (!piecesToLeaveEnabled.Contains(child.name)) child.SetActive(false);
if (child.name == "Street") street = child;
}
for (int i = 0; i < street.transform.childCount; i++)
{
var child = street.transform.GetChild(i).gameObject;
if (!piecesToLeaveEnabled.Contains(child.name)) child.SetActive(false);
}
for (int i = 2; i < 24; i++)
{
SLogger.LogInfo("Disabling Section " + i);
var section = GameObject.Find("Section " + i);
var tbd = section.transform.GetChild(0);
for (int j = 0; j < tbd.childCount; j++)
{
var child = tbd.GetChild(j).gameObject;
SLogger.LogInfo("Disabling " + child.name);
string name = child.name.Split(" (")[0];
if (!piecesToLeaveEnabled.Contains(name)) child.SetActive(false);
}
}
var streetLightsContainer = GameObject.Find("Street Lights"); var streetLightsContainer = GameObject.Find("Street Lights");
streetLightsContainer.SetActive(false); streetLightsContainer.SetActive(false);
return standardEnvironmentContainer;
}
private void SceneManager_sceneLoaded(Scene arg0, LoadSceneMode arg1)
{
var standardEnvironmentContainer = DisableStandardEnvironment();
if (standardEnvironmentContainer == null) return;
Player = GameObject.Find("Player"); Player = GameObject.Find("Player");
var newContainer = new GameObject("Space Environment").transform; var newContainer = new GameObject("Space Environment").transform;
@ -118,17 +184,19 @@ namespace SpacemarketSimulator
var skyboxContainer = new GameObject("Skybox").transform; var skyboxContainer = new GameObject("Skybox").transform;
skyboxContainer.SetParent(newContainer); skyboxContainer.SetParent(newContainer);
GameObject platform = GameObject.CreatePrimitive(PrimitiveType.Plane); //GameObject platform = GameObject.CreatePrimitive(PrimitiveType.Plane);
platform.transform.localScale = new Vector3(1, 1, 1); //platform.transform.localScale = new Vector3(1, 1, 1);
platform.transform.position = new Vector3(6, 0, 6); //platform.transform.position = new Vector3(6, 0, 6);
platform.transform.SetParent(newContainer); //platform.transform.SetParent(newContainer);
//var camera = GameObject.Find("Main Camera");
//(camera.GetComponent<CinemachineBrain>().ActiveVirtualCamera as CinemachineVirtualCamera).;
var renderer = platform.GetComponent<MeshRenderer>(); //var renderer = platform.GetComponent<MeshRenderer>();
renderer.material.shader = Shader.Find("Universal Render Pipeline/Lit"); //renderer.material.shader = Shader.Find("Universal Render Pipeline/Lit");
renderer.material.mainTexture = LoadTexture("metalgrid3_basecolor"); //renderer.material.mainTexture = LoadTexture("metalgrid3_basecolor");
renderer.material.SetTexture("_NORMALMAP", LoadTexture("metalgrid3_normal-ogl")); //renderer.material.SetTexture("_NORMALMAP", LoadTexture("metalgrid3_normal-ogl"));
renderer.material.SetTexture("_METALLICGLOSSMAP", LoadTexture("metalgrid3_metallic")); //renderer.material.SetTexture("_METALLICGLOSSMAP", LoadTexture("metalgrid3_metallic"));
renderer.material.DisableKeyword("_SPECULAR_SETUP"); //renderer.material.DisableKeyword("_SPECULAR_SETUP");
ApplySkybox(skyboxContainer); ApplySkybox(skyboxContainer);

View file

@ -70,6 +70,16 @@ namespace SpacemarketSimulator.Properties {
} }
} }
/// <summary>
/// Sucht eine lokalisierte Ressource vom Typ System.Byte[].
/// </summary>
internal static byte[] bg {
get {
object obj = ResourceManager.GetObject("bg", resourceCulture);
return ((byte[])(obj));
}
}
/// <summary> /// <summary>
/// Sucht eine lokalisierte Ressource vom Typ System.Byte[]. /// Sucht eine lokalisierte Ressource vom Typ System.Byte[].
/// </summary> /// </summary>

View file

@ -121,6 +121,9 @@
<data name="back_galaxyfire1" type="System.Resources.ResXFileRef, System.Windows.Forms"> <data name="back_galaxyfire1" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\back_galaxyfire.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> <value>..\Resources\back_galaxyfire.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data> </data>
<data name="bg" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\image (5).png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="down_galaxyfire1" type="System.Resources.ResXFileRef, System.Windows.Forms"> <data name="down_galaxyfire1" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\down_galaxyfire.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> <value>..\Resources\down_galaxyfire.png;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data> </data>

BIN
Resources/image (4).png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 693 KiB

BIN
Resources/image (5).png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 880 KiB

View file

@ -1,16 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework> <TargetFramework>netstandard2.1</TargetFramework>
<AssemblyName>SpacemarketSimulator</AssemblyName> <AssemblyName>SpacemarketSimulator</AssemblyName>
<Description>My first plugin</Description> <Description>My first plugin</Description>
<Version>1.0.0</Version> <Version>0.1.0</Version>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<LangVersion>latest</LangVersion> <LangVersion>latest</LangVersion>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="BepInEx.Analyzers" Version="1.*" PrivateAssets="all" /> <PackageReference Include="BepInEx.Analyzers" Version="1.*" PrivateAssets="all" />
<PackageReference Include="BepInEx.AssemblyPublicizer.MSBuild" Version="0.4.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="BepInEx.Core" Version="5.*" /> <PackageReference Include="BepInEx.Core" Version="5.*" />
<PackageReference Include="BepInEx.PluginInfoProps" Version="1.*" /> <PackageReference Include="BepInEx.PluginInfoProps" Version="1.*" />
<PackageReference Include="UnityEngine.Modules" Version="2021.3.3" IncludeAssets="compile" /> <PackageReference Include="UnityEngine.Modules" Version="2021.3.3" IncludeAssets="compile" />
@ -20,6 +24,21 @@
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.2" PrivateAssets="all" /> <PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.2" PrivateAssets="all" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Reference Include="Assembly-CSharp" Publicize="true">
<HintPath>D:\SteamLibrary\steamapps\common\Supermarket Simulator\Supermarket Simulator_Data\Managed\Assembly-CSharp.dll</HintPath>
</Reference>
<Reference Include="Cinemachine" Publicize="true">
<HintPath>D:\SteamLibrary\steamapps\common\Supermarket Simulator\Supermarket Simulator_Data\Managed\Cinemachine.dll</HintPath>
</Reference>
<Reference Include="MyBox" Publicize="true">
<HintPath>D:\SteamLibrary\steamapps\common\Supermarket Simulator\Supermarket Simulator_Data\Managed\MyBox.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.UI">
<HintPath>D:\SteamLibrary\steamapps\common\Supermarket Simulator\Supermarket Simulator_Data\Managed\UnityEngine.UI.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Update="Properties\Resources.Designer.cs"> <Compile Update="Properties\Resources.Designer.cs">
<DesignTime>True</DesignTime> <DesignTime>True</DesignTime>

View file

@ -12,7 +12,7 @@ namespace SpacemarketSimulator
public void Update() public void Update()
{ {
transform.localPosition = localPosition; transform.localPosition = localPosition;
transform.localPosition = position + Plugin.Player.transform.position; transform.localPosition = position + (Plugin.MoveSkyboxWithPlayer.Value ? Plugin.Player.transform.position : new Vector3());
transform.localScale = localScale; transform.localScale = localScale;
transform.eulerAngles = eulerAngles; transform.eulerAngles = eulerAngles;
} }