Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
skynet2 committed Mar 28, 2015
1 parent e3457fb commit bb292af
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
11 changes: 9 additions & 2 deletions PW/editor/pwAPI/pwAPI/StructuresElement/Item.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public string EditorView
}
public void Save(BinaryWriter bw, ConfigList ls)
{

for (int i = 0; i < Values.Length / 2; i++)
{
var type = ls.Types[i];
Expand All @@ -43,6 +44,12 @@ public void Save(BinaryWriter bw, ConfigList ls)
case "string:":
bw.Write(UtilsIO.GenerateArray(Encoding.GetEncoding(936).GetBytes(Values[i, 1]), type.Size));
break;
case "int32":
bw.Write(Convert.ToInt32(Values[i, 1]));
break;
case "float":
bw.Write(Convert.ToSingle(Values[i, 1]));
break;
default:
bw.Write(Values[i, 1]);
break;
Expand Down Expand Up @@ -100,12 +107,12 @@ public static Item ParseItem(ConfigList cfg, BinaryReader br)
case "string:":
vvv[i, 0] = tt.Name;
vvv[i, 1] = Encoding.GetEncoding(936)
.GetString(br.ReadBytes(tt.Size)).Replace("\0", "");
.GetString(br.ReadBytes(tt.Size));
break;
case "wstring:":
vvv[i, 0] = tt.Name;
vvv[i, 1] = Encoding.Unicode.GetString(
br.ReadBytes(tt.Size)).Replace("\0","");
br.ReadBytes(tt.Size));
break;
case "float":
vvv[i, 0] = tt.Name;
Expand Down
10 changes: 7 additions & 3 deletions PW/editor/pwAPI/pwAPI/Utils/UtilsIO.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.IO;
using System;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;

namespace pwApi.Utils
Expand All @@ -19,8 +20,11 @@ public static T DeepClone<T>(T obj)
public static byte[] GenerateArray(byte[] arr, int size)
{
var newArr = new byte[size];
for (int i = 0; i < arr.Length; i++)
newArr[i] = arr[i];
for (int i = 0; i < newArr.Length; i++)
if (i < arr.Length)
newArr[i] = arr[i];
else newArr[i] = 0x0;

return newArr;
}

Expand Down

0 comments on commit bb292af

Please sign in to comment.