Skip to content

Commit

Permalink
Merge pull request #122 from valheimPlus/0.9.0
Browse files Browse the repository at this point in the history
0.9.0
  • Loading branch information
nxPublic authored Feb 25, 2021
2 parents af60879 + 598f831 commit b538e38
Show file tree
Hide file tree
Showing 19 changed files with 351 additions and 41 deletions.
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ All of these features can be adjusted by a configuration file. This also allows
* Modify maximum Players on a server
* Modify auto save interval
* Modify server data rate in kilobyte
* Automatic server configuration sync when a user joins the server to sync the configuration of V+

## Map
* Activate shared position on map automatically
Expand Down Expand Up @@ -453,17 +454,14 @@ baseUnarmedDamage=10
[Server]

; Change false to true to enable this section
enabled=false
enabled=true

; Modify the amount of players on your Server
maxPlayers=10

; Removes the requirement to have a server password
disableServerPassword=false

; This setting adds a version control check to verifiy that the server and yourself have the same configuration file installed.
enforceConfiguration=false

; This settings add a version control check to make sure that people that try to join your game or the server you try to join has V+ installed
enforceMod=true

Expand Down Expand Up @@ -497,7 +495,7 @@ sneakStaminaDrain=10
staminaRegen=5

; Changes the delay until stamina regeneration sets in
staminaRegenDelay=0.5
staminaRegenDelay=1

; Changes the stamina drain of swimming
swimStaminaDrain=5
Expand Down
Binary file added ValheimPlus/Assets/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 26 additions & 3 deletions ValheimPlus/Configurations/ConfigurationExtra.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static string GetServerHashFor(Configuration config) {
return Settings.CreateMD5(serialized);
}

static string ConfigIniPath = Path.GetDirectoryName(Paths.BepInExConfigPath) + Path.DirectorySeparatorChar + "valheim_plus.cfg";
public static string ConfigIniPath = Path.GetDirectoryName(Paths.BepInExConfigPath) + Path.DirectorySeparatorChar + "valheim_plus.cfg";

public static bool LoadSettings()
{
Expand All @@ -53,8 +53,6 @@ public static bool LoadSettings()

public static Configuration LoadFromIni(string filename)
{


var parser = new FileIniDataParser();
IniData configdata = parser.ReadFile(filename);

Expand All @@ -73,6 +71,31 @@ public static Configuration LoadFromIni(string filename)
}
return conf;
}

public static Configuration LoadFromIni(Stream iniStream)
{
using (StreamReader iniReader = new StreamReader(iniStream))
{
var parser = new FileIniDataParser();
IniData configdata = parser.ReadData(iniReader);

var conf = new Configuration();
foreach (var prop in typeof(Configuration).GetProperties())
{
var keyName = prop.Name;
var method = prop.PropertyType.GetMethod("LoadIni",
BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy);

if (method != null)
{
var result = method.Invoke(null, new object[] {configdata, keyName});
prop.SetValue(conf, result, null);
}
}

return conf;
}
}
}

public static class IniDataExtensions
Expand Down
1 change: 0 additions & 1 deletion ValheimPlus/Configurations/Sections/ServerConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ public class ServerConfiguration : BaseConfig<ServerConfiguration>
{
public int maxPlayers { get; set; } = 10;
public bool disableServerPassword { get; set; } = false;
public bool enforceConfiguration { get; internal set; } = true;
public bool enforceMod { get; internal set; } = true;
public int dataRate { get; internal set; } = (60 * 1024); // 614440 == 60kbs
public float autoSaveInterval { get; internal set; } = 1200;
Expand Down
17 changes: 17 additions & 0 deletions ValheimPlus/FejdStartup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using HarmonyLib;
using UnityEngine;
using UnityEngine.UI;
using ValheimPlus.UI;

namespace ValheimPlus
{
[HarmonyPatch(typeof(FejdStartup), "SetupGui")]
class PatchUI
{
static void Postfix()
{
GameObject logo = GameObject.Find("LOGO");
logo.GetComponent<Image>().sprite = VPlusMainMenu.VPlusLogoSprite;
}
}
}
70 changes: 57 additions & 13 deletions ValheimPlus/Fireplace.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using HarmonyLib;
using ValheimPlus.Configurations;
using UnityEngine;

namespace ValheimPlus
{
Expand All @@ -9,23 +8,68 @@ class FireplaceFuel
[HarmonyPatch(typeof(Fireplace), "UpdateFireplace")]
public static class TorchesNoFuel
{
private static void Postfix(Fireplace __instance, ref ZNetView ___m_nview)
/// <summary>
/// Prefix which returns false every time to skip the original method and other prefixes so that we're not
/// needlessly setting fuel value twice
/// </summary>
/// <param name="__instance"></param>
/// <param name="___m_nview"></param>
/// <returns>false</returns>
private static bool Prefix(ref Fireplace __instance, ref ZNetView ___m_nview)
{
if (Configuration.Current.Fireplace.IsEnabled)
{
if (Configuration.Current.Fireplace.onlyTorches)
{
if (__instance.GetHoverText().Contains("torch") || __instance.GetHoverText().Contains("Scounce") || __instance.GetHoverText().Contains("brazier"))
{
___m_nview.GetZDO().Set("fuel", 1f);
}
}
if (!__instance.m_nview.IsValid())
return false; // don't run other prefixes or original
if (__instance.m_nview.IsOwner())
{
if (Configuration.Current.Fireplace.IsEnabled)
{
FireplaceExtension.ApplyFuel(__instance, ref ___m_nview);
}
else
{
___m_nview.GetZDO().Set("fuel", 3f);
// original method
float num1 = __instance.m_nview.GetZDO().GetFloat("fuel");
double timeSinceLastUpdate = __instance.GetTimeSinceLastUpdate();
if (__instance.IsBurning())
{
float num2 = (float)timeSinceLastUpdate / __instance.m_secPerFuel;
float num3 = num1 - num2;
if ((double)num3 <= 0.0)
num3 = 0.0f;
__instance.m_nview.GetZDO().Set("fuel", num3);
}
}
}
}
__instance.UpdateState();
return false; // don't run other prefixes or original
}
}

public static class FireplaceExtension
{
const string woodTorchName = "$piece_groundtorchwood";
const string ironTorchName = "$piece_groundtorch";
const string greenTorchName = "$piece_groundtorchgreen";
const string sconceName = "$piece_sconce";
const string brazierName = "$piece_brazierceiling01";

internal static void ApplyFuel(Fireplace __instance, ref ZNetView ___m_nview)
{
if (Configuration.Current.Fireplace.onlyTorches)
{
if (__instance.m_piece.m_name.Equals(woodTorchName) ||
__instance.m_piece.m_name.Equals(sconceName) ||
__instance.m_piece.m_name.Equals(ironTorchName) ||
__instance.m_piece.m_name.Equals(brazierName) ||
__instance.m_piece.m_name.Equals(greenTorchName))
{
___m_nview.GetZDO().Set("fuel", __instance.m_maxFuel); // setting to max won't waste rss on fill attempts
}
}
else
{
___m_nview.GetZDO().Set("fuel", __instance.m_maxFuel); // setting to max won't waste rss on fill attempts
}
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions ValheimPlus/FodyWeavers.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
<Costura>
<IncludeAssemblies>
INIFileParser
YamlDotNet
</IncludeAssemblies>
</Costura>
</Weavers>
13 changes: 12 additions & 1 deletion ValheimPlus/Game.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
using System;
using HarmonyLib;
using ValheimPlus.RPC;
using Steamworks;
using ValheimPlus.Configurations;
using UnityEngine;

namespace ValheimPlus
{
[HarmonyPatch(typeof(Game), "Start")]
public static class GameStartPatch
{
private static void Prefix()
{
//Config Sync
ZRoutedRpc.instance.Register("VPlusConfigSync", new Action<long, ZPackage>(VPlusConfigSync.RPC_VPlusConfigSync));
}
}

[HarmonyPatch(typeof(Game), "GetDifficultyDamageScale")]
public static class ChangeDifficultyScaleDamage
{
Expand Down Expand Up @@ -61,4 +72,4 @@ private static Boolean Prefix(ref Game __instance, ref Vector3 pos, ref int __re
}
}

}
}
14 changes: 8 additions & 6 deletions ValheimPlus/Initialize.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,25 @@
using System;
using System.IO;
using ValheimPlus.Configurations;
using ValheimPlus.UI;

namespace ValheimPlus
{
// COPYRIGHT 2021 KEVIN "nx#8830" J. // http://n-x.xyz
// GITHUB REPOSITORY https://github.com/nxPublic/ValheimPlus


[BepInPlugin("org.bepinex.plugins.valheim_plus", "Valheim Plus", "0.8.6")]
[BepInPlugin("org.bepinex.plugins.valheim_plus", "Valheim Plus", "0.9.0")]
class ValheimPlusPlugin : BaseUnityPlugin
{

public static string version = "0.8.6";
public static string version = "0.9.0";
public static string newestVersion = "";
public static Boolean isUpToDate = false;

string ConfigPath = Path.GetDirectoryName(Paths.BepInExConfigPath) + Path.DirectorySeparatorChar + "valheim_plus.cfg";

// Project Repository Info
public static string Repository = "https://github.com/nxPublic/ValheimPlus";
public static string ApiRepository = "https://api.github.com/repos/nxPublic/valheimPlus/tags";
public static string Repository = "https://github.com/valheimPlus/ValheimPlus";
public static string ApiRepository = "https://api.github.com/repos/valheimPlus/valheimPlus/tags";

// Awake is called once when both the game and the plug-in are loaded
void Awake()
Expand Down Expand Up @@ -51,6 +50,9 @@ void Awake()
Logger.LogInfo("ValheimPlus [" + version + "] is up to date.");
}

//Logo
VPlusMainMenu.Load();

}


Expand Down
3 changes: 3 additions & 0 deletions ValheimPlus/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@ private static void Prefix()
}

Player.m_localPlayer.ShowTutorial("vplus");

}
}




[HarmonyPatch(typeof(Player), "GetMaxCarryWeight")]
Expand Down
2 changes: 2 additions & 0 deletions ValheimPlus/PlayerStats.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public static class ChangeStaminaUsageOfToolsAndWeapons
private static void Prefix(ref Player __instance, ref float v)
{

// TODO add a check for the origin of the call of this function to restrict it to not reduce stamina drain of running/jumping/swimming etc.

if (Configuration.Current.StaminaUsage.IsEnabled)
{
string weaponType = "";
Expand Down
91 changes: 91 additions & 0 deletions ValheimPlus/RPC/VPlusConfigSync.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using BepInEx;
using ValheimPlus.Configurations;

namespace ValheimPlus.RPC
{
public class VPlusConfigSync
{
public static void RPC_VPlusConfigSync(long sender, ZPackage configPkg)
{
if (ZNet.m_isServer) //Server
{
ZPackage pkg = new ZPackage();

string[] rawConfigData = File.ReadAllLines(ConfigurationExtra.ConfigIniPath);
List<string> cleanConfigData = new List<string>();

for (int i = 0; i < rawConfigData.Length; i++)
{
if (rawConfigData[i].Trim().StartsWith(";") ||
rawConfigData[i].Trim().StartsWith("#")) continue; //Skip comments

if (rawConfigData[i].Trim().IsNullOrWhiteSpace()) continue; //Skip blank lines

//Add to clean data
cleanConfigData.Add(rawConfigData[i]);
}

//Add number of clean lines to package
pkg.Write(cleanConfigData.Count);

//Add each line to the package
foreach (string line in cleanConfigData)
{
pkg.Write(line);

ZLog.Log("SENTCONFIG: " + line);
}

ZRoutedRpc.instance.InvokeRoutedRPC(sender, "VPlusConfigSync", new object[]
{
pkg
});

ZLog.Log("VPlus configuration synced to peer #" + sender);
}
else //Client
{
if (configPkg != null &&
configPkg.Size() > 0 &&
sender == ZRoutedRpc.instance.GetServerPeerID()) //Validate the message is from the server and not another client.
{
int numLines = configPkg.ReadInt();

if (numLines == 0)
{
ZLog.LogWarning("Got zero line config file from server. Cannot load.");
return;
}

using (MemoryStream memStream = new MemoryStream())
{
using (StreamWriter tmpWriter = new StreamWriter(memStream))
{
for (int i = 0; i < numLines; i++)
{
string line = configPkg.ReadString();

tmpWriter.WriteLine(line);

ZLog.Log("CONFIGDATA: " + line);
}

tmpWriter.Flush(); //Flush to memStream
memStream.Position = 0; //Rewind stream

Configuration.Current = ConfigurationExtra.LoadFromIni(memStream);

ZLog.Log("Successfully synced VPlus configuration from server.");
}
}
}
}
}


}
}
Loading

0 comments on commit b538e38

Please sign in to comment.