コード例 #1
0
 /// <summary>
 /// Applies all patches to the given WZ file.
 /// </summary>
 /// <param name="wz">The WZFile to patch.  Assumed to have already been parsed.</param>
 public static void applyPatches(WzFile wz)
 {
     foreach (WzPatcherEntry wpe in customPatches) {
         if (wpe.WzFileName.Equals(wz.Name)) {
             WzPatcherEntry localPatch = new WzPatcherEntry(wz, wpe.NodePath, wpe.NewValue);
             if (!checkSingleNode(localPatch)) {
                 modifySingleNode(localPatch);
             }
             localPatch.wzFile = null;
         }
     }
 }
コード例 #2
0
 /// <summary>
 /// Checks if the specified node has the correct value.
 /// </summary>
 /// <param name="entry"></param>
 /// <returns>True if the check passed, false otherwise.</returns>
 public static bool checkSingleNode(WzPatcherEntry entry)
 {
     IWzImageProperty node = getNode(entry.wzFile, entry.NodePath);
     switch (node.PropertyType)
     {
         case WzPropertyType.ByteFloat:
             {
                 float value = Single.Parse(entry.NewValue);
                 return value == ((WzByteFloatProperty)node).Value;
             }
         case WzPropertyType.Double:
             {
                 double value = Double.Parse(entry.NewValue);
                 return value == ((WzDoubleProperty)node).Value;
             }
         case WzPropertyType.CompressedInt:
             {
                 int value = Int32.Parse(entry.NewValue);
                 return value == ((WzCompressedIntProperty)node).Value;
             }
         case WzPropertyType.Int64:
             {
                 long value = Int64.Parse(entry.NewValue);
                 return value == ((WzInt64Property)node).Value;
             }
         case WzPropertyType.UnsignedShort:
             {
                 ushort value = UInt16.Parse(entry.NewValue);
                 return value == ((WzUnsignedShortProperty)node).Value;
             }
         case WzPropertyType.String:
             {
                 return entry.NewValue.Equals(((WzStringProperty)node).Value);
             }
         case WzPropertyType.Vector:
             {
                 string[] splitted = entry.NewValue.Split(new string[] { "," }, StringSplitOptions.None);
                 int x = Int32.Parse(splitted[0]);
                 int y = Int32.Parse(splitted[1]);
                 Point pos = ((WzVectorProperty)node).Pos;
                 return pos.X == x && pos.Y == y;
             }
         default:
             throw new NotSupportedException("Attempted to check an unsupported property type. type: " + node.PropertyType);
     }
 }
コード例 #3
0
 /// <summary>
 /// Modifies a single WZ node in a single file.
 /// </summary>
 /// <param name="entry"></param>
 public static void modifySingleNode(WzPatcherEntry entry)
 {
     IWzImageProperty node = getNode(entry.wzFile, entry.NodePath);
     if (node != null) {
         switch (node.PropertyType) {
             case WzPropertyType.ByteFloat:
             case WzPropertyType.Double:
                 node.SetValue(Double.Parse(entry.NewValue));
                 break;
             case WzPropertyType.Int64:
                 node.SetValue(Int64.Parse(entry.NewValue));
                 break;
             case WzPropertyType.CompressedInt:
                 node.SetValue(Int32.Parse(entry.NewValue));
                 break;
             case WzPropertyType.UnsignedShort:
                 node.SetValue(UInt16.Parse(entry.NewValue));
                 break;
             case WzPropertyType.String:
                 node.SetValue(entry.NewValue);
                 break;
             case WzPropertyType.Vector:
                 string[] splitted = entry.NewValue.Split(new string[]{","}, StringSplitOptions.None);
                 node.SetValue(new Point(Int32.Parse(splitted[0]), Int32.Parse(splitted[1])));
                 break;
             default:
                 throw new NotSupportedException("Attempted to change an unsupported property type. type: " + node.PropertyType);
         }
         node.ParentImage.Changed = true;
     }
 }