Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hotfix/0.217.46 patch #116

Merged
merged 2 commits into from
Apr 21, 2024
Merged
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
6 changes: 6 additions & 0 deletions DoPrebuild.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ExecutePrebuild>true</ExecutePrebuild>
</PropertyGroup>
</Project>
1 change: 0 additions & 1 deletion QuickPing/Patches/Localization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ public static string Localize(Location location)
res = Localization.instance.Localize("$location_mountaincave");
break;
#endregion

#region Mistlands
case "Mistlands_DvergrTownEntrance":
case "Mistlands_DvergrTownEntrance1":
Expand Down
85 changes: 50 additions & 35 deletions QuickPing/Patches/Minimap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ namespace QuickPing.Patches
/// </summary>
internal static class Minimap_Patch
{


private static GameObject panel;
private static GameObject nameInput;
private static GameObject toggleSaveName;
Expand All @@ -33,7 +31,6 @@ internal static class Minimap_Patch
/// <returns></returns>
public static Minimap.PinType IsPinable(string strID)
{

string baseLocalization = Localization_Patch.GetBaseTranslation(strID);
Dictionary<Minimap.PinType, List<string>> pinables = new()
{
Expand Down Expand Up @@ -70,7 +67,8 @@ public static Minimap.PinType IsPinable(string strID)
"$piece_deposit_silver",
"$piece_deposit_silvervein",
"$piece_deposit_tin",
"$piece_mudpile"
"$piece_mudpile",
"$piece_giant_brain"
}
},

Expand All @@ -89,6 +87,7 @@ public static Minimap.PinType IsPinable(string strID)
"$item_mushroomblue",
"$item_thistle",
"$item_jotunpuffs",
"$item_ancientroot",
// fix #58 conflicts with PlantEverything
"$peRaspberryBushName",
"$peBlueberryBushName",
Expand All @@ -98,7 +97,7 @@ public static Minimap.PinType IsPinable(string strID)
"$pePickableBlueMushroomName",
"$pePickableThistleName",
"$pePickableDandelionName",

"$pePickableJotunpuffsName",
}
},

Expand All @@ -125,25 +124,29 @@ public static Minimap.PinType IsPinable(string strID)
return pinType;
}
}

return Minimap.PinType.None;
}

/// <summary>
/// Force rename pin
/// </summary>
/// <param name="obj"></param>
internal static void RenamePin(HoverObject obj) => AddPin(obj.Hover, obj.Destructible, obj.Name, obj.center, rename: true);
internal static void RenamePin(HoverObject obj) =>
AddPin(obj.Hover, obj.Destructible, obj.Name, obj.center, rename: true);

/// <summary>
/// Add correct pin to map if Settings.
/// </summary>
/// <param name="obj"></param>
public static void AddPin(HoverObject obj) => AddPin(obj.Hover, obj.Destructible, obj.Name, obj.center);

/// <summary>
/// Add correct pin to map if Settings and bypass filters.
/// </summary>
/// <param name="obj"></param>
public static void ForceAddPin(HoverObject obj) => AddPin(obj.Hover, obj.Destructible, obj.Name, obj.center, true);
public static void ForceAddPin(HoverObject obj) =>
AddPin(obj.Hover, obj.Destructible, obj.Name, obj.center, true);

/// <summary>
/// Add correct pin to map if Settings.
Expand All @@ -153,9 +156,14 @@ public static Minimap.PinType IsPinable(string strID)
/// <param name="strID">Display Name of hover object</param>
/// <param name="pos">Pinged position (last raycast point or hover center)</param>
/// <param name="force">Bypass filters</param>
public static void AddPin(GameObject hover, IDestructible idestructible, string strID, Vector3 pos, bool force = false, bool rename = false)
public static void AddPin(GameObject hover, IDestructible idestructible, string strID, Vector3 pos,
bool force = false, bool rename = false)
{
if (!Settings.AddPin.Value && !force) { return; }
if (!Settings.AddPin.Value && !force)
{
return;
}

bool pinned = false;

Minimap.PinData pinData = new Minimap.PinData
Expand All @@ -180,15 +188,17 @@ public static void AddPin(GameObject hover, IDestructible idestructible, string
}

pinData.m_pos = pos;
pinData = Minimap.instance.AddPin(pinData.m_pos, pinData.m_type, pinData.m_name, true, false, 0L);
pinData = Minimap.instance.AddPin(pinData.m_pos, pinData.m_type, pinData.m_name, true, false,
0L);
pinned = true;
QuickPingPlugin.Log.LogInfo($"Add Portal Pin : Name:{pinData.m_name} x:{pinData.m_pos.x}, y:{pinData.m_pos.y}, Type:{pinData.m_type}");
QuickPingPlugin.Log.LogInfo(
$"Add Portal Pin : Name:{pinData.m_name} x:{pinData.m_pos.x}, y:{pinData.m_pos.y}, Type:{pinData.m_type}");
}

break;
default:
if (closestPin == null || rename)
{

pinData.m_name ??= Localization.instance.Localize(strID);

// check for customnames
Expand All @@ -201,25 +211,31 @@ public static void AddPin(GameObject hover, IDestructible idestructible, string
{
pinData.m_name = Settings.DefaultPingText;
}

if (pinData.m_type == Minimap.PinType.None && force)
{
pinData.m_type = Settings.DefaultPinType.Value;
pinData = Minimap.instance.AddPin(pinData.m_pos, pinData.m_type, pinData.m_name, true, false, 0L);
pinData = Minimap.instance.AddPin(pinData.m_pos, pinData.m_type, pinData.m_name, true,
false, 0L);
pinned = true;
QuickPingPlugin.Log.LogInfo($"Add Pin : Name:{pinData.m_name} x:{pinData.m_pos.x}, y:{pinData.m_pos.y}, Type:{pinData.m_type}");
QuickPingPlugin.Log.LogInfo(
$"Add Pin : Name:{pinData.m_name} x:{pinData.m_pos.x}, y:{pinData.m_pos.y}, Type:{pinData.m_type}");
break;
}

if (pinData.m_type != Minimap.PinType.None)
{
if (closestPin == null)
{
pinData = Minimap.instance.AddPin(pinData.m_pos, pinData.m_type, pinData.m_name, true, false, 0L);
pinData = Minimap.instance.AddPin(pinData.m_pos, pinData.m_type, pinData.m_name, true,
false, 0L);
pinned = true;
}
else if (rename)
pinData = closestPin;
QuickPingPlugin.Log.LogInfo($"Add Pin : Name:{pinData.m_name} x:{pinData.m_pos.x}, y:{pinData.m_pos.y}, Type:{pinData.m_type}");

QuickPingPlugin.Log.LogInfo(
$"Add Pin : Name:{pinData.m_name} x:{pinData.m_pos.x}, y:{pinData.m_pos.y}, Type:{pinData.m_type}");

//Check if Settings.AskForName.Value is true, and if CustomNames contains its name.
//if true ask for user input before adding pin
Expand All @@ -232,23 +248,28 @@ public static void AddPin(GameObject hover, IDestructible idestructible, string
}
}
}

break;
}

if (idestructible != null && pinned)
{
FieldInfo fieldInfo = idestructible.GetType().GetField("m_nview", BindingFlags.Instance | BindingFlags.NonPublic);
FieldInfo fieldInfo = idestructible.GetType()
.GetField("m_nview", BindingFlags.Instance | BindingFlags.NonPublic);
if (fieldInfo == null)
{
QuickPingPlugin.Log.LogWarning($"Unable to link destructible {idestructible} to pin: {pinData.m_name}. (Is it a god?)");
QuickPingPlugin.Log.LogWarning(
$"Unable to link destructible {idestructible} to pin: {pinData.m_name}. (Is it a god?)");
return;
}

ZNetView netView = fieldInfo.GetValue(idestructible) as ZNetView;
ZDOID uid = netView.GetZDO().m_uid;
if (uid == null)
{
QuickPingPlugin.Log.LogError($"Try adding {idestructible} but {netView} uid is null");
}

if (!DataManager.PinnedObjects.ContainsKey(uid))
{
DataManager.PinnedObjects[uid] = pinData;
Expand All @@ -264,6 +285,7 @@ public static void UpdateNameInput()
{
Minimap.instance.m_wasFocused = false;
}

if (Minimap.instance.m_namePin != null)
{
panel.SetActive(true);
Expand All @@ -275,6 +297,7 @@ public static void UpdateNameInput()
{
EventSystem.current.SetSelectedGameObject(nameInput);
}

if (Input.GetKeyDown(KeyCode.Return) || Input.GetKeyDown(KeyCode.KeypadEnter))
{
ValidateNameInput(inputField, toggleSave.isOn);
Expand All @@ -283,6 +306,7 @@ public static void UpdateNameInput()
{
CancelNameInput();
}

Minimap.instance.m_wasFocused = true;
}
else //end
Expand Down Expand Up @@ -329,9 +353,8 @@ private static void ValidateNameInput(InputField inputField, bool save)
QuickPingPlugin.Log.LogInfo($"Save name {Minimap.instance.m_namePin.m_name} for {originalText}");
SaveName(Minimap.instance.m_namePin.m_name, originalText);
}
Minimap.instance.m_namePin = null;


Minimap.instance.m_namePin = null;
}
/// <summary>
/// Save the name of a pinned object and update PinnedObjects list with new value
Expand Down Expand Up @@ -427,7 +450,7 @@ private static void InitNameInput()
parent: panel.transform,
width: 20f,
height: 20f
);
);

Text saveNameText = toggleSaveName.transform.Find("Label").GetComponent<Text>();
saveNameText.color = Color.white;
Expand All @@ -448,8 +471,8 @@ private static void InitNameInput()
//saveAllText.text = "Update all pins.";
//saveAllText.enabled = true;
//toggleSaveAll.GetComponent<Toggle>().interactable = false;

}

#endregion

private static string GetPortalTag(Hoverable hoverable)
Expand All @@ -460,9 +483,6 @@ private static string GetPortalTag(Hoverable hoverable)
}





#region Patches

[HarmonyPatch(typeof(Minimap))]
Expand All @@ -482,26 +502,21 @@ public static bool RemovePin(Minimap __instance, Minimap.PinData pin)
if (p.Value.Compare(pin))
{
pin = __instance.GetClosestPin(p.Value.m_pos, Settings.ClosestPinRange.Value);
DataManager.PinnedObjects.Remove(DataManager.PinnedObjects.FirstOrDefault((x) => x.Value.Compare(p.Value)).Key);
DataManager.PinnedObjects.Remove(DataManager.PinnedObjects
.FirstOrDefault((x) => x.Value.Compare(p.Value)).Key);
break;
}

}

if ((bool)pin.m_uiElement)
{
__instance.DestroyPinMarker(pin);
}

__instance.m_pins.Remove(pin);
return false;
}





#endregion

}


}
}
12 changes: 4 additions & 8 deletions QuickPing/Patches/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,13 @@ private static void Player_Update(Player __instance)
#endregion
private static string GetHoverName(string pingText, GameObject hover, HoverType type)
{
Hoverable hoverable;
Character hoverCreature;
Piece piece;
Location location;
switch (type)
{
case HoverType.GameObject:
//pingText = Settings.pingText;
break;
case HoverType.Hoverable:
hover.TryGetComponent(out hoverable);
hover.TryGetComponent(out Hoverable hoverable);
pingText = !hoverable.GetHoverName().StartsWith("$")
? Localization_Patch.GetBaseTranslation(hoverable.GetHoverName())
: hoverable.GetHoverName();
Expand All @@ -107,15 +103,15 @@ private static string GetHoverName(string pingText, GameObject hover, HoverType
pingText = hover.GetComponentInParent<Piece>().m_name;
break;
case HoverType.Piece:
piece = hover.GetComponent<Piece>();
var piece = hover.GetComponent<Piece>();
pingText = piece.m_name;
break;
case HoverType.Location:
location = hover.GetComponent<Location>();
var location = hover.GetComponent<Location>();
pingText = Localization_Patch.Localize(location);
break;
case HoverType.Character:
hoverCreature = hover.GetComponent<Character>();
var hoverCreature = hover.GetComponent<Character>();
pingText = hoverCreature.m_name;

break;
Expand Down
34 changes: 30 additions & 4 deletions QuickPing/QuickPing.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,6 @@
<PackageReference Include="Digitalroot.References.Unity">
<Version>2022.3.12</Version>
</PackageReference>
<PackageReference Include="Digitalroot.Valheim.Common.References">
<Version>0.217.38</Version>
</PackageReference>
<PackageReference Include="GitVersion.MsBuild">
<Version>5.12.0</Version>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand All @@ -109,6 +106,35 @@
<Version>2.18.0</Version>
</PackageReference>
</ItemGroup>
<ItemGroup>
<Reference Include="assembly_googleanalytics-publicized">
<HintPath>..\..\Digitalroot.Valheim.References\src\Digitalroot.Valheim.References\lib\assembly_googleanalytics-publicized.dll</HintPath>
</Reference>
<Reference Include="assembly_guiutils-publicized">
<HintPath>..\..\Digitalroot.Valheim.References\src\Digitalroot.Valheim.References\lib\assembly_guiutils-publicized.dll</HintPath>
</Reference>
<Reference Include="assembly_lux-publicized">
<HintPath>..\..\Digitalroot.Valheim.References\src\Digitalroot.Valheim.References\lib\assembly_lux-publicized.dll</HintPath>
</Reference>
<Reference Include="assembly_postprocessing-publicized">
<HintPath>..\..\Digitalroot.Valheim.References\src\Digitalroot.Valheim.References\lib\assembly_postprocessing-publicized.dll</HintPath>
</Reference>
<Reference Include="assembly_simplemeshcombine-publicized">
<HintPath>..\..\Digitalroot.Valheim.References\src\Digitalroot.Valheim.References\lib\assembly_simplemeshcombine-publicized.dll</HintPath>
</Reference>
<Reference Include="assembly_steamworks-publicized">
<HintPath>..\..\Digitalroot.Valheim.References\src\Digitalroot.Valheim.References\lib\assembly_steamworks-publicized.dll</HintPath>
</Reference>
<Reference Include="assembly_sunshafts-publicized">
<HintPath>..\..\Digitalroot.Valheim.References\src\Digitalroot.Valheim.References\lib\assembly_sunshafts-publicized.dll</HintPath>
</Reference>
<Reference Include="assembly_utils-publicized">
<HintPath>..\..\Digitalroot.Valheim.References\src\Digitalroot.Valheim.References\lib\assembly_utils-publicized.dll</HintPath>
</Reference>
<Reference Include="assembly_valheim-publicized">
<HintPath>..\..\Digitalroot.Valheim.References\src\Digitalroot.Valheim.References\lib\assembly_valheim-publicized.dll</HintPath>
</Reference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="GetAssemblyVersion" AfterTargets="Build">
<GetAssemblyIdentity AssemblyFiles="$(TargetPath)">
Expand Down Expand Up @@ -141,7 +167,7 @@
<Message Text="Package created at $(AssemblyName).zip" Importance="high" />
<ZipDirectory SourceDirectory="$(PackageDir)" DestinationFile="$(AssemblyName).zip" Overwrite="true" />
</Target>
<Import Project="Environment.props" Condition="Exists('Environment.props')" />
<!-- <Import Project="Environment.props" Condition="Exists('Environment.props')" /> -->
<Target Name="PublishToThunderstorePath">
<ItemGroup>
<PackageFiles Include="$(TargetDir)$(AssemblyName).dll; $(TargetDir)$(AssemblyName).dll.mdb; $(TargetDir)$(AssemblyName).pdb;" />
Expand Down
Loading