From 440101fb18a5e29dd9654a3ae83d6e0c7a1213aa Mon Sep 17 00:00:00 2001 From: LastBattle Date: Sat, 28 Nov 2020 19:52:39 +0800 Subject: [PATCH] [WzLib] Fix InvalidCastException when calling WzFloatProperty.SetValue() & WzDoubleProperty.SetValue() --- HaCreator/GUI/MapPhysicsEditor.cs | 51 +++++++------------ .../WzLib/WzProperties/WzDoubleProperty.cs | 4 +- .../WzLib/WzProperties/WzFloatProperty.cs | 4 +- MapleLib/WzLib/WzProperties/WzIntProperty.cs | 2 +- MapleLib/WzLib/WzProperties/WzLongProperty.cs | 2 +- 5 files changed, 25 insertions(+), 38 deletions(-) diff --git a/HaCreator/GUI/MapPhysicsEditor.cs b/HaCreator/GUI/MapPhysicsEditor.cs index 0d96fa5f..bd2717ae 100644 --- a/HaCreator/GUI/MapPhysicsEditor.cs +++ b/HaCreator/GUI/MapPhysicsEditor.cs @@ -133,26 +133,25 @@ private bool Save() WzImage image = (WzImage)wzMapFile[WZ_FILE_IMAGE]; if (image != null) { - SetWzImageValue(image["walkForce"], numericUpDown_walkForce.Value); - SetWzImageValue(image["walkSpeed"], numericUpDown_walkSpeed.Value); - SetWzImageValue(image["walkDrag"], numericUpDown_walkDrag.Value); - SetWzImageValue(image["slipForce"], numericUpDown_slipForce.Value); - SetWzImageValue(image["slipSpeed"], numericUpDown_slipSpeed.Value); - SetWzImageValue(image["floatDrag1"], numericUpDown_floatDrag1.Value); - SetWzImageValue(image["floatDrag2"], numericUpDown_floatDrag2.Value); - SetWzImageValue(image["floatCoefficient"], numericUpDown_floatCoefficient.Value); - SetWzImageValue(image["swimForce"], numericUpDown_swimForce.Value); - SetWzImageValue(image["swimSpeed"], numericUpDown_swimSpeed.Value); - SetWzImageValue(image["flyForce"], numericUpDown_flyForce.Value); - SetWzImageValue(image["flySpeed"], numericUpDown_flySpeed.Value); - SetWzImageValue(image["gravityAcc"], numericUpDown_gravityAcc.Value); - SetWzImageValue(image["fallSpeed"], numericUpDown_fallSpeed.Value); - SetWzImageValue(image["jumpSpeed"], numericUpDown_jumpSpeed.Value); - SetWzImageValue(image["maxFriction"], numericUpDown_maxFriction.Value); - SetWzImageValue(image["minFriction"], numericUpDown_minFriction.Value); - SetWzImageValue(image["swimSpeedDec"], numericUpDown_swimSpeedDec.Value); - SetWzImageValue(image["flyJumpDec"], numericUpDown_flyJumpDec.Value); - + image["walkForce"].SetValue(numericUpDown_walkForce.Value); + image["walkSpeed"].SetValue(numericUpDown_walkSpeed.Value); + image["walkDrag"].SetValue(numericUpDown_walkDrag.Value); + image["slipForce"].SetValue(numericUpDown_slipForce.Value); + image["slipSpeed"].SetValue(numericUpDown_slipSpeed.Value); + image["floatDrag1"].SetValue(numericUpDown_floatDrag1.Value); + image["floatDrag2"].SetValue(numericUpDown_floatDrag2.Value); + image["floatCoefficient"].SetValue(numericUpDown_floatCoefficient.Value); + image["swimForce"].SetValue(numericUpDown_swimForce.Value); + image["swimSpeed"].SetValue(numericUpDown_swimSpeed.Value); + image["flyForce"].SetValue(numericUpDown_flyForce.Value); + image["flySpeed"].SetValue(numericUpDown_flySpeed.Value); + image["gravityAcc"].SetValue(numericUpDown_gravityAcc.Value); + image["fallSpeed"].SetValue(numericUpDown_fallSpeed.Value); + image["jumpSpeed"].SetValue(numericUpDown_jumpSpeed.Value); + image["maxFriction"].SetValue(numericUpDown_maxFriction.Value); + image["minFriction"].SetValue(numericUpDown_minFriction.Value); + image["swimSpeedDec"].SetValue(numericUpDown_swimSpeedDec.Value); + image["flyJumpDec"].SetValue(numericUpDown_flyJumpDec.Value); Program.WzManager.SetWzFileUpdated(WZ_FILE_NAME, image); // flag as changed } @@ -199,18 +198,6 @@ private void button_save_Click(object sender, EventArgs e) Save(); } - private void SetWzImageValue(WzImageProperty image, decimal value) - { - if (image is WzDoubleProperty doubleProperty) - { - doubleProperty.Value = (double)value; - } - else if (image is WzFloatProperty floatProperty) - { - floatProperty.Value = (float)value; - } - } - /// /// Reset to pre-bb map physics values /// diff --git a/MapleLib/WzLib/WzProperties/WzDoubleProperty.cs b/MapleLib/WzLib/WzProperties/WzDoubleProperty.cs index 6752fd16..3b6a59e3 100644 --- a/MapleLib/WzLib/WzProperties/WzDoubleProperty.cs +++ b/MapleLib/WzLib/WzProperties/WzDoubleProperty.cs @@ -34,7 +34,7 @@ public class WzDoubleProperty : WzImageProperty #region Inherited Members public override void SetValue(object value) { - val = (double)value; + val = System.Convert.ToDouble(value); } public override WzImageProperty DeepClone() @@ -79,7 +79,7 @@ public override void Dispose() /// /// The value of this property /// - public double Value { get { return val; } set { val = value; } } + public double Value { get { return val; } set { val = (double) value; } } /// /// Creates a blank WzDoubleProperty /// diff --git a/MapleLib/WzLib/WzProperties/WzFloatProperty.cs b/MapleLib/WzLib/WzProperties/WzFloatProperty.cs index 3e297903..24506f73 100644 --- a/MapleLib/WzLib/WzProperties/WzFloatProperty.cs +++ b/MapleLib/WzLib/WzProperties/WzFloatProperty.cs @@ -35,7 +35,7 @@ public class WzFloatProperty : WzImageProperty #region Inherited Members public override void SetValue(object value) { - val = (float)value; + val = System.Convert.ToSingle(value); } public override WzImageProperty DeepClone() @@ -91,7 +91,7 @@ public override void Dispose() /// /// The value of the property /// - public float Value { get { return val; } set { val = value; } } + public float Value { get { return val; } set { val = (float) value; } } /// /// Creates a blank WzByteFloatProperty /// diff --git a/MapleLib/WzLib/WzProperties/WzIntProperty.cs b/MapleLib/WzLib/WzProperties/WzIntProperty.cs index edaf033c..9222330b 100644 --- a/MapleLib/WzLib/WzProperties/WzIntProperty.cs +++ b/MapleLib/WzLib/WzProperties/WzIntProperty.cs @@ -83,7 +83,7 @@ public override void Dispose() /// /// The value of the property /// - public int Value { get { return val; } set { val = value; } } + public int Value { get { return val; } set { val = (int) value; } } /// /// Creates a blank WzCompressedIntProperty /// diff --git a/MapleLib/WzLib/WzProperties/WzLongProperty.cs b/MapleLib/WzLib/WzProperties/WzLongProperty.cs index 460028f8..c2667957 100644 --- a/MapleLib/WzLib/WzProperties/WzLongProperty.cs +++ b/MapleLib/WzLib/WzProperties/WzLongProperty.cs @@ -79,7 +79,7 @@ public override void Dispose() /// /// The value of the property /// - public long Value { get { return val; } set { val = value; } } + public long Value { get { return val; } set { val = (long) value; } } /// /// Creates a blank WzCompressedIntProperty ///