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
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ You may also be able to hold down the `shift` key and click the reload button in

This mod supports placing pins with chat commands. Press `Enter` to start chatting in game. The commands are as follows:

* `/pin` - Place a "dot" pin with no text on the map where you are currently standing.
* `/pin my pin name` - Place a "dot" pin with "my pin name" under it on the map where you are currently standing.
* `/pin [pin-type] [text]` - Place a pin of a certain type with optional text under it on the map where you are currently standing.
* `createPin` - Place a "dot" pin with no text on the map where you are currently standing.
* `createPin my pin name` - Place a "dot" pin with "my pin name" under it on the map where you are currently standing.
* `createPin [pin-type] [text]` - Place a pin of a certain type with optional text under it on the map where you are currently standing.
* Pin types are: `dot`, `fire`, `mine`, `house` and `cave`. Example command: `/pin house my awesome base`
* `/undoPin` - Delete your most recent pin.
* `/deletePin [text]` - Delete the most recent pin that matches the text exactly.
* `undoPin` - Delete your most recent pin.
* `deletePin [text]` - Delete the most recent pin that matches the text exactly.

If a player creates too many pins, their oldest pin will be removed. There is a setting to control how many pins a player can create in `config.json`.

Expand Down
30 changes: 21 additions & 9 deletions WebMap/WebMap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
using BepInEx;
using UnityEngine;
using HarmonyLib;
using WebSocketSharp;
using static ZRoutedRpc;

namespace WebMap {
namespace WebMap
{
//This attribute is required, and lists metadata for your plugin.
//The GUID should be a unique ID for this plugin, which is human readable (as it is used in places like the config). I like to use the java package notation, which is "com.[your name here].[your plugin name here]"
//The name is the name of the plugin that's displayed on load, and the version number just specifies what version the plugin is.
[BepInPlugin("com.kylepaulsen.valheim.webmap", "WebMap", "1.2.0")]
[BepInPlugin("com.kylepaulsen.valheim.webmap", "WebMap", "1.3.0")]

//This is the main declaration of our plugin class. BepInEx searches for all classes inheriting from BaseUnityPlugin to initialize on startup.
//BaseUnityPlugin itself inherits from MonoBehaviour, so you can use this as a reference for what you can declare and use in your plugin class: https://docs.unity3d.com/ScriptReference/MonoBehaviour.html
Expand Down Expand Up @@ -54,7 +56,7 @@ public void Awake() {
try {
var fogTexture = new Texture2D(WebMapConfig.TEXTURE_SIZE, WebMapConfig.TEXTURE_SIZE);
var fogBytes = File.ReadAllBytes(fogImagePath);
fogTexture.LoadImage(fogBytes);
fogTexture.LoadImage(fogBytes, false);
mapDataServer.fogTexture = fogTexture;
} catch (Exception e) {
Debug.Log("WebMap: Failed to read fog image data from disk... Making new fog image..." + e.Message);
Expand All @@ -65,6 +67,7 @@ public void Awake() {
}
fogTexture.SetPixels32(fogColors);
var fogPngBytes = fogTexture.EncodeToPNG();


mapDataServer.fogTexture = fogTexture;
try {
Expand Down Expand Up @@ -235,6 +238,8 @@ static void Postfix(ZoneSystem __instance) {
}
Debug.Log("WebMap: BUILD MAP!");

var c = Color.black;

int num = WebMapConfig.TEXTURE_SIZE / 2;
float num2 = WebMapConfig.PIXEL_SIZE / 2f;
Color32[] colorArray = new Color32[WebMapConfig.TEXTURE_SIZE * WebMapConfig.TEXTURE_SIZE];
Expand All @@ -245,7 +250,7 @@ static void Postfix(ZoneSystem __instance) {
float wx = (float)(j - num) * WebMapConfig.PIXEL_SIZE + num2;
float wy = (float)(i - num) * WebMapConfig.PIXEL_SIZE + num2;
Heightmap.Biome biome = WorldGenerator.instance.GetBiome(wx, wy);
float biomeHeight = WorldGenerator.instance.GetBiomeHeight(biome, wx, wy);
float biomeHeight = WorldGenerator.instance.GetBiomeHeight(biome, wx, wy, out c);
colorArray[i * WebMapConfig.TEXTURE_SIZE + j] = GetPixelColor(biome);
treeMaskArray[i * WebMapConfig.TEXTURE_SIZE + j] = GetMaskColor(wx, wy, biomeHeight, biome);
heightArray[i * WebMapConfig.TEXTURE_SIZE + j] = biomeHeight;
Expand Down Expand Up @@ -336,12 +341,19 @@ static void Prefix(RoutedRPCData data) {
var zdoData = ZDOMan.instance.GetZDO(peer.m_characterID);
var pos = zdoData.GetPosition();
ZPackage package = new ZPackage(data.m_parameters.GetArray());

int messageType = package.ReadInt();
string userName = package.ReadString();
string message = package.ReadString();
var userName = package.ReadString();
_ = package.ReadString();
_ = package.ReadString();
var message = package.ReadString();

//int messageType = package.ReadInt();
//string userName = package.ReadString();
//string message = package.ReadString();
message = (message == null ? "" : message).Trim();

if (message.StartsWith("/pin")) {
if (message.StartsWith("createPin")) {
var messageParts = message.Split(' ');
var pinType = "dot";
var startIdx = 1;
Expand Down Expand Up @@ -369,13 +381,13 @@ static void Prefix(RoutedRPCData data) {
mapDataServer.RemovePin(pinIdx);
}
SavePins();
} else if (message.StartsWith("/undoPin")) {
} else if (message.StartsWith("undoPin")) {
var pinIdx = mapDataServer.pins.FindLastIndex(pin => pin.StartsWith(steamid));
if (pinIdx > -1) {
mapDataServer.RemovePin(pinIdx);
SavePins();
}
} else if (message.StartsWith("/deletePin")) {
} else if (message.StartsWith("deletePin")) {
var messageParts = message.Split(' ');
var pinText = "";
if (messageParts.Length > 1) {
Expand Down
Loading