gaslight gatekeep girlboss :)

This commit is contained in:
2023-01-12 02:55:27 +01:00
parent b797c0c84a
commit cd54185023
47 changed files with 218 additions and 45 deletions
+31
View File
@@ -0,0 +1,31 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Valheim Dev",
"type": "cppvsdbg",
"request": "launch",
"cwd": "C:/Program Files (x86)/Steam/steamapps/common/Valheim_dev",
"program": "C:/Program Files (x86)/Steam/steamapps/common/Valheim_dev/valheim.exe",
"console": "integratedTerminal",
"args": [
"-console"
],
"preLaunchTask": "build debug"
},
{
"name": "Valheim Dev2",
"type": "cppvsdbg",
"request": "launch",
"cwd": "C:/Program Files (x86)/Steam/steamapps/common/Valheim_dev2",
"program": "C:/Program Files (x86)/Steam/steamapps/common/Valheim_dev2/valheim.exe",
"console": "integratedTerminal",
"args": [
"-console"
],
}
]
}
+33
View File
@@ -0,0 +1,33 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "build debug",
"command": "msbuild",
"type": "shell",
"args": [
"${workspaceFolder}/GaslightArrin.sln",
"/t:GaslightArrin",
"/p:Configuration=Debug",
"/p:Platform=\"Any CPU\""
],
"problemMatcher": "$msCompile",
"group": {
"kind": "build",
"isDefault": true
}
},
{
"label": "build release",
"command": "msbuild",
"type": "shell",
"args": [
"${workspaceFolder}/GaslightArrin.sln",
"/t:GaslightArrin",
"/p:Configuration=Release",
"/p:Platform=\"Any CPU\""
],
"problemMatcher": "$msCompile"
}
]
}
+2 -2
View File
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup> <PropertyGroup>
<ExecutePrebuild>false</ExecutePrebuild> <ExecutePrebuild>True</ExecutePrebuild>
</PropertyGroup> </PropertyGroup>
</Project> </Project>
+3 -2
View File
@@ -1,9 +1,9 @@
Microsoft Visual Studio Solution File, Format Version 12.00 Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17 # Visual Studio Version 17
VisualStudioVersion = 17.4.33213.308 VisualStudioVersion = 17.4.33213.308
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GaslightArrin", "JotunnModStub\GaslightArrin.csproj", "{DEAF4438-8089-40ED-8175-398E1261D45B}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GaslightArrin", "GaslightArrin\GaslightArrin.csproj", "{DEAF4438-8089-40ED-8175-398E1261D45B}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -23,3 +23,4 @@ Global
SolutionGuid = {04FA40AF-91D5-4CE8-92ED-7530C8DF0D5E} SolutionGuid = {04FA40AF-91D5-4CE8-92ED-7530C8DF0D5E}
EndGlobalSection EndGlobalSection
EndGlobal EndGlobal
+142
View File
@@ -0,0 +1,142 @@
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using BepInEx;
using HarmonyLib;
using UnityEngine;
namespace EasyStackPlugin
{
[BepInPlugin(PluginGUID, PluginName, PluginVersion)]
[BepInDependency(Jotunn.Main.ModGuid)]
//[NetworkCompatibility(CompatibilityLevel.EveryoneMustHaveMod, VersionStrictness.Minor)]
internal class EasyStackPlugin : BaseUnityPlugin
{
public const string PluginGUID = "com.ecaj.easystack";
public const string PluginName = "EasyStack";
public const string PluginVersion = "1.3.1";
private const string ArrinName = "arrin";
private const string JaceName = "jace";
private const float ReopenChance = 1f;
private const float OpeningSoundChance = 1/20f;
private const float OtherPlayerDistance = 10f;
private Harmony mHarmony;
private static List<Door> DoorQueue = new List<Door>();
private void Awake()
{
mHarmony = Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), PluginGUID);
}
private void OnDestroy()
{
mHarmony?.UnpatchSelf();
}
private void Update()
{
if (Player.m_localPlayer == null) {
return;
}
for (int i = 0; i < DoorQueue.Count; i++) {
var door = DoorQueue[i];
if (door == null) {
DoorQueue.RemoveAt(i);
i--;
continue;
}
var diff = door.transform.position - Player.m_localPlayer.transform.position;
if (Player.m_localPlayer.GetPlayerName().ToLower() == ArrinName) {
// Check if visible to camera
var colliders = door.GetComponent<Piece>()?.GetAllColliders();
var planes = GeometryUtility.CalculateFrustumPlanes(Camera.main);
var visible = colliders != null && colliders.Any(collider => GeometryUtility.TestPlanesAABB(planes, collider.bounds));
if (!visible && diff.magnitude > 6f) {
// Only reopen if still closed
if (door.m_nview.GetZDO().GetInt("state") == 0) {
// Make sure no other players are nearby
bool otherPlayersNearby = false;
foreach (var player in Player.GetAllPlayers()) {
if (player == null || player == Player.m_localPlayer) {
continue;
}
if (Vector3.Distance(player.transform.position, door.transform.position) < OtherPlayerDistance) {
otherPlayersNearby = true;
break;
}
}
if (!otherPlayersNearby) {
// Random 1/10 chance to actually play open sound
var playCloseSound = Random.Range(0f, 1f) < OpeningSoundChance;
var effects = door.m_openEffects;
if (!playCloseSound) {
door.m_openEffects = new EffectList();
}
// Open door :)
var facing = Vector3.Dot(door.transform.forward, Player.m_localPlayer.transform.forward);
door.m_nview.InvokeRPC("UseDoor", facing);
if (!playCloseSound) {
door.m_openEffects = effects;
}
}
}
DoorQueue.RemoveAt(i);
i--;
}
} else if (Player.m_localPlayer.GetPlayerName().ToLower() == JaceName) {
// Check if facing away
var facing = Vector3.Dot(diff.normalized, Player.m_localPlayer.transform.forward);
if (facing < 0 && diff.magnitude > 2f) {
// Close door
if (door.m_nview.GetZDO().GetInt("state") != 0) {
door.m_nview.InvokeRPC("UseDoor", 0);
}
DoorQueue.RemoveAt(i);
i--;
}
}
}
}
[HarmonyPatch(typeof(Door), nameof(Door.Interact))]
private class Door_Interact_Patch
{
private static void Postfix(Door __instance, Humanoid character, bool hold, bool alt, bool __result)
{
if (!__result) {
return;
}
var player = character as Player;
if (player == null) {
return;
}
bool closed = __instance.m_nview.GetZDO().GetInt("state") == 0;
// If Arrin
if (player.GetPlayerName().ToLower() == ArrinName) {
// If door is being closed
if (closed) {
// Random chance for door to reopen after closing
if (Random.Range(0f, 1f) < ReopenChance) {
if (!DoorQueue.Contains(__instance)) {
DoorQueue.Add(__instance);
}
}
}
// If Jace
} else if (player.GetPlayerName().ToLower() == JaceName) {
// If door is being opened, make sure it auto-closes
if (!closed) {
DoorQueue.Add(__instance);
}
}
}
}
}
}
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\packages\JotunnLib.2.10.0\build\JotunnLib.props" Condition="Exists('..\packages\JotunnLib.2.10.0\build\JotunnLib.props')" /> <Import Project="..\packages\JotunnLib.2.10.0\build\JotunnLib.props" Condition="Exists('..\packages\JotunnLib.2.10.0\build\JotunnLib.props')" />
<PropertyGroup> <PropertyGroup>
@@ -7,8 +7,8 @@
<ProjectGuid>{DEAF4438-8089-40ED-8175-398E1261D45B}</ProjectGuid> <ProjectGuid>{DEAF4438-8089-40ED-8175-398E1261D45B}</ProjectGuid>
<OutputType>Library</OutputType> <OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder> <AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>JotunnModStub</RootNamespace> <RootNamespace>EasyStack</RootNamespace>
<AssemblyName>JotunnModStub</AssemblyName> <AssemblyName>EasyStack</AssemblyName>
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion> <TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment> <FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic> <Deterministic>true</Deterministic>

Before

Width:  |  Height:  |  Size: 2.3 KiB

After

Width:  |  Height:  |  Size: 2.3 KiB

@@ -1,4 +1,4 @@
using System.Reflection; using System.Reflection;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following // General Information about an assembly is controlled through the following
@@ -33,3 +33,4 @@ using System.Runtime.InteropServices;
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.3.1.0")] [assembly: AssemblyVersion("1.3.1.0")]
[assembly: AssemblyFileVersion("1.3.1.0")] [assembly: AssemblyFileVersion("1.3.1.0")]
-35
View File
@@ -1,35 +0,0 @@
// JotunnModStub
// a Valheim mod skeleton using Jötunn
//
// File: JotunnModStub.cs
// Project: JotunnModStub
using BepInEx;
using Jotunn.Entities;
using Jotunn.Managers;
namespace EasyStackPlugin
{
[BepInPlugin(PluginGUID, PluginName, PluginVersion)]
[BepInDependency(Jotunn.Main.ModGuid)]
//[NetworkCompatibility(CompatibilityLevel.EveryoneMustHaveMod, VersionStrictness.Minor)]
internal class EasyStackPlugin : BaseUnityPlugin
{
public const string PluginGUID = "com.itmae.easystack";
public const string PluginName = "EasyStack";
public const string PluginVersion = "1.3.1";
// Use this class to add your own localization to the game
// https://valheim-modding.github.io/Jotunn/tutorials/localization.html
public static CustomLocalization Localization = LocalizationManager.Instance.GetLocalization();
private void Awake()
{
// Jotunn comes with its own Logger class to provide a consistent Log style for all mods using it
Jotunn.Logger.LogInfo("ModStub has landed");
// To learn more about Jotunn's features, go to
// https://valheim-modding.github.io/Jotunn/tutorials/overview.html
}
}
}