Skip to content

Commit

Permalink
fixed gizmo issue + fixed being able to dual wield two handeds + fixe…
Browse files Browse the repository at this point in the history
…d options not serializing + fixed assembly references
  • Loading branch information
rheirman committed Feb 29, 2020
1 parent 4bde2fc commit bf73924
Show file tree
Hide file tree
Showing 107 changed files with 6,777 additions and 7,682 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*.vs
Source/DualWield.vs/*
Source/DualWield/obj/*
1.1/Source/DualWield/obj/*
Binary file removed 1.1/Assemblies/0Harmony.dll
Binary file not shown.
Binary file modified 1.1/Assemblies/DualWield.dll
Binary file not shown.
Binary file added 1.1/Assemblies/Unity.TextMeshPro.dll
Binary file not shown.
Binary file added 1.1/Assemblies/UnityEngine.AIModule.dll
Binary file not shown.
Binary file added 1.1/Assemblies/UnityEngine.ARModule.dll
Binary file not shown.
Binary file not shown.
Binary file added 1.1/Assemblies/UnityEngine.AndroidJNIModule.dll
Binary file not shown.
Binary file added 1.1/Assemblies/UnityEngine.AnimationModule.dll
Binary file not shown.
Binary file added 1.1/Assemblies/UnityEngine.AssetBundleModule.dll
Binary file not shown.
Binary file added 1.1/Assemblies/UnityEngine.AudioModule.dll
Binary file not shown.
Binary file added 1.1/Assemblies/UnityEngine.ClothModule.dll
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added 1.1/Assemblies/UnityEngine.CoreModule.dll
Binary file not shown.
Binary file not shown.
Binary file added 1.1/Assemblies/UnityEngine.DSPGraphModule.dll
Binary file not shown.
Binary file added 1.1/Assemblies/UnityEngine.DirectorModule.dll
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added 1.1/Assemblies/UnityEngine.GridModule.dll
Binary file not shown.
Binary file not shown.
Binary file added 1.1/Assemblies/UnityEngine.IMGUIModule.dll
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added 1.1/Assemblies/UnityEngine.InputModule.dll
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added 1.1/Assemblies/UnityEngine.Physics2DModule.dll
Binary file not shown.
Binary file added 1.1/Assemblies/UnityEngine.PhysicsModule.dll
Binary file not shown.
Binary file added 1.1/Assemblies/UnityEngine.ProfilerModule.dll
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added 1.1/Assemblies/UnityEngine.SpriteMaskModule.dll
Binary file not shown.
Binary file added 1.1/Assemblies/UnityEngine.SpriteShapeModule.dll
Binary file not shown.
Binary file not shown.
Binary file added 1.1/Assemblies/UnityEngine.SubstanceModule.dll
Binary file not shown.
Binary file added 1.1/Assemblies/UnityEngine.TLSModule.dll
Binary file not shown.
Binary file added 1.1/Assemblies/UnityEngine.TerrainModule.dll
Binary file not shown.
Binary file not shown.
Binary file added 1.1/Assemblies/UnityEngine.TextCoreModule.dll
Binary file not shown.
Binary file not shown.
Binary file added 1.1/Assemblies/UnityEngine.TilemapModule.dll
Binary file not shown.
Binary file added 1.1/Assemblies/UnityEngine.UI.dll
Binary file not shown.
Binary file added 1.1/Assemblies/UnityEngine.UIElementsModule.dll
Binary file not shown.
Binary file added 1.1/Assemblies/UnityEngine.UIModule.dll
Binary file not shown.
Binary file added 1.1/Assemblies/UnityEngine.UNETModule.dll
Binary file not shown.
Binary file added 1.1/Assemblies/UnityEngine.UmbraModule.dll
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added 1.1/Assemblies/UnityEngine.VFXModule.dll
Binary file not shown.
Binary file added 1.1/Assemblies/UnityEngine.VRModule.dll
Binary file not shown.
Binary file added 1.1/Assemblies/UnityEngine.VehiclesModule.dll
Binary file not shown.
Binary file added 1.1/Assemblies/UnityEngine.VideoModule.dll
Binary file not shown.
Binary file added 1.1/Assemblies/UnityEngine.WindModule.dll
Binary file not shown.
Binary file added 1.1/Assemblies/UnityEngine.XRModule.dll
Binary file not shown.
Binary file added 1.1/Assemblies/UnityEngine.dll
Binary file not shown.
6 changes: 3 additions & 3 deletions 1.1/Source/DualWield/Base.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class Base : ModBase
{
public static Base Instance { get; private set; }
ExtendedDataStorage _extendedDataStorage;
public override string ModIdentifier => "DualWield";
public override string ModIdentifier => "Roolo.DualWield";

internal static SettingHandle<bool> settingsGroup_Drawing;
internal static SettingHandle<bool> settingsGroup_DualWield;
Expand Down Expand Up @@ -301,15 +301,15 @@ where isWeapon(td)

public override void MapComponentsInitializing(Map map)
{
_extendedDataStorage = UtilityWorldObjectManager.GetUtilityWorldObject<ExtendedDataStorage>();
_extendedDataStorage = Find.World.GetComponent<ExtendedDataStorage>();
base.MapComponentsInitializing(map);
}
public override void WorldLoaded()
{
//Failsafe if other mods prevent the store from being loaded during MapComponentsInitializing
if (_extendedDataStorage == null)
{
_extendedDataStorage = UtilityWorldObjectManager.GetUtilityWorldObject<ExtendedDataStorage>();
_extendedDataStorage = Find.World.GetComponent<ExtendedDataStorage>();
}
base.WorldLoaded();
}
Expand Down
1 change: 0 additions & 1 deletion 1.1/Source/DualWield/Command_DualWield.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public override float GetWidth(float maxWidth)

public override GizmoResult GizmoOnGUI(Vector2 topLeft, float maxWidth)
{
Log.Message("GizmoOnGUI");
GizmoResult res = base.GizmoOnGUI(topLeft, maxWidth);
GUI.color = offHandThing.DrawColor;
Material material = (!this.disabled) ? null : TexUI.GrayscaleGUI;
Expand Down
198 changes: 69 additions & 129 deletions 1.1/Source/DualWield/DualWield.csproj

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions 1.1/Source/DualWield/Harmony/Pawn_EquipmentTracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,25 @@ static bool Prefix(Pawn_EquipmentTracker __instance, ThingWithComps eq)
{
if (eq.def.IsTwoHand() && offHandEquipped)
{
DropOffHand(__instance, eq, offHand);
string herHis = __instance.pawn.story.bodyType == BodyTypeDefOf.Male ? "DW_HerHis_Male".Translate() : "DW_HerHis_Female".Translate();
Messages.Message("DW_Message_UnequippedOffHand".Translate(new object[] { __instance.pawn.Name.ToStringShort, herHis }), new LookTargets(__instance.pawn), MessageTypeDefOf.CautionInput);
}
return true;
}
}

private static void DropOffHand(Pawn_EquipmentTracker __instance, ThingWithComps eq, ThingWithComps offHand)
{
if (__instance.TryDropEquipment(offHand, out ThingWithComps resultingEq, __instance.pawn.Position))
{
resultingEq?.SetForbidden(value: false);
}
else
{
Log.Error(__instance.pawn + " couldn't make room for equipment " + eq);
}
}
}

}
40 changes: 36 additions & 4 deletions 1.1/Source/DualWield/Harmony/VerbTracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,57 @@
using System.Reflection;
using System.Reflection.Emit;
using System.Text;
using UnityEngine;
using Verse;

namespace DualWield.Harmony
{

[HarmonyPatch(typeof(VerbTracker), "CreateVerbTargetCommand")]
public class VerbTracker_CreateVerbTargetCommand
{
static bool Prefix(VerbTracker __instance, Thing ownerThing, Verb verb, ref Command_VerbTarget __result) {
static void Postfix(VerbTracker __instance, Thing ownerThing, ref Verb verb, ref Command_VerbTarget __result) {
if (ownerThing is ThingWithComps twc && twc.ParentHolder is Pawn_EquipmentTracker peqt)
{
CompEquippable ce = __instance.directOwner as CompEquippable;

if (peqt.pawn.equipment.TryGetOffHandEquipment(out ThingWithComps offHandEquip))
{
if (offHandEquip != twc)
{
__result = CreateDualWieldCommand(ownerThing, offHandEquip, verb);
return false;
}
}
}
return true;
}
private static Command_VerbTarget CreateVerbTargetCommand(VerbTracker __instance, Thing ownerThing, Verb verb)
{

Command_VerbTarget command_VerbTarget = new Command_VerbTarget();
command_VerbTarget.defaultDesc = ownerThing.LabelCap + ": " + ownerThing.def.description.CapitalizeFirst();
command_VerbTarget.icon = ownerThing.def.uiIcon;
command_VerbTarget.iconAngle = ownerThing.def.uiIconAngle;
command_VerbTarget.iconOffset = ownerThing.def.uiIconOffset;
command_VerbTarget.tutorTag = "VerbTarget";
command_VerbTarget.verb = verb;
if (verb.caster.Faction != Faction.OfPlayer)
{
command_VerbTarget.Disable("CannotOrderNonControlled".Translate());
}
else if (verb.CasterIsPawn)
{
if (verb.CasterPawn.WorkTagIsDisabled(WorkTags.Violent))
{
command_VerbTarget.Disable("IsIncapableOfViolence".Translate(verb.CasterPawn.LabelShort, verb.CasterPawn));
}
else if (!verb.CasterPawn.drafter.Drafted)
{
command_VerbTarget.Disable("IsNotDrafted".Translate(verb.CasterPawn.LabelShort, verb.CasterPawn));
}
}
return command_VerbTarget;
}


private static Command_VerbTarget CreateDualWieldCommand(Thing ownerThing, Thing offHandThing, Verb verb)
{
Expand Down Expand Up @@ -74,7 +103,10 @@ private static IEnumerable<Command> RemoveCommandForOffHand(IEnumerable<Command>

if (verb.EquipmentSource is ThingWithComps twc && twc.ParentHolder is Pawn_EquipmentTracker peqt)
{
if (peqt.pawn.equipment.TryGetOffHandEquipment(out ThingWithComps offHandEquip) && offHandEquip == twc)
bool offhandIsPrimary = false;
//Remove offhand gizmo when dual wielding
//Don't remove offhand gizmo when offhand weapon is the only weapon being carried by the pawn
if (peqt.pawn.equipment.TryGetOffHandEquipment(out ThingWithComps offHandEquip) && offHandEquip == twc && offHandEquip != peqt.Primary)
{
continue;
}
Expand Down
26 changes: 17 additions & 9 deletions 1.1/Source/DualWield/Settings/DictRecordHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,7 @@ public class DictRecordHandler : SettingHandleConvertible
public Dictionary<String, Record> inner = new Dictionary<String, Record>();
public Dictionary<String, Record> InnerList { get { return inner; } set { inner = value; } }
private XmlSerializer serializer = new XmlSerializer(typeof(Record));
XmlSerializerNamespaces ns = new XmlSerializerNamespaces();

public DictRecordHandler()
{
ns.Add("", "");
}
public override void FromString(string settingValue)
{
inner = new Dictionary<String, Record>();
Expand Down Expand Up @@ -57,14 +52,27 @@ public override string ToString()
childXml = xmlDoc.CreateElement(XmlConvert.EncodeName(child.Key));
//Log.Warning("Couldn't create Dual Wield settings for: " + child.Key + ", because this defname isn't suitable for XML storage");
}
StringWriter writer = new StringWriter();
serializer.Serialize(writer, child.Value, ns);
childXml.InnerXml = writer.ToString();
childXml.InnerXml = SerializeToString(child.Value);
root.AppendChild(childXml);
}

return xmlDoc.OuterXml;
}
// To Clean XML
private string SerializeToString<T>(T value)
{
var emptyNamespaces = new XmlSerializerNamespaces(new[] { XmlQualifiedName.Empty });
var serializer = new XmlSerializer(value.GetType());
var settings = new XmlWriterSettings();
settings.Indent = true;
settings.OmitXmlDeclaration = true;

using (var stream = new StringWriter())
using (var writer = XmlWriter.Create(stream, settings))
{
serializer.Serialize(writer, value, emptyNamespaces);
return stream.ToString();
}
}
}

}
6 changes: 5 additions & 1 deletion 1.1/Source/DualWield/Storage/ExtendedDataStorage.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using HugsLib.Utils;
using RimWorld.Planet;
using System;
using System.Collections.Generic;
using System.Linq;
Expand All @@ -10,7 +11,7 @@ namespace DualWield.Storage
/**
* Storage used to extend existing Rimworld objects with additional data. Caution should be taken when assigning the IDs.
**/
public class ExtendedDataStorage : UtilityWorldObject, IExposable
public class ExtendedDataStorage : WorldComponent, IExposable
{
private Dictionary<int, IExposable> _store =
new Dictionary<int, IExposable>();
Expand All @@ -21,6 +22,9 @@ public class ExtendedDataStorage : UtilityWorldObject, IExposable
internal int lastEmergencySignalDelay = 0;
internal int lastEmergencySignalCooldown = 0;

public ExtendedDataStorage(World world) : base(world)
{
}
public override void ExposeData()
{
base.ExposeData();
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@ C:\Program Files (x86)\Steam\steamapps\common\RimWorld\Mods\DualWield\Source\Dua
C:\Program Files (x86)\Steam\steamapps\common\RimWorld\Mods\DualWield\Source\DualWield\obj\Debug\DualWield.csproj.CoreCompileInputs.cache
C:\Program Files (x86)\Steam\steamapps\common\RimWorld\Mods\DualWield\1.1\Assemblies\DualWield.dll
C:\Program Files (x86)\Steam\steamapps\common\RimWorld\Mods\DualWield\Source\DualWield\obj\Debug\DualWield.dll
C:\Program Files (x86)\Steam\steamapps\common\RimWorld\Mods\DualWield\1.1\Source\DualWield\obj\Debug\DualWield.csprojAssemblyReference.cache
C:\Program Files (x86)\Steam\steamapps\common\RimWorld\Mods\DualWield\1.1\Source\DualWield\obj\Debug\DualWield.dll
C:\Program Files (x86)\Steam\steamapps\common\RimWorld\Mods\DualWield\1.1\Source\DualWield\obj\Debug\DualWield.csproj.CopyComplete
Binary file modified 1.1/Source/DualWield/obj/Debug/DualWield.dll
Binary file not shown.
3 changes: 2 additions & 1 deletion 1.1/Source/DualWield/packages.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Lib.Harmony" version="2.0.0.5" targetFramework="net472" />
<package id="Lib.Harmony" version="2.0.0.7" targetFramework="net472" />
<package id="UnlimitedHugs.Rimworld.HugsLib" version="7.0.1" targetFramework="net472" />
</packages>
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading

0 comments on commit bf73924

Please sign in to comment.