-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
389 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Windows.Forms; | ||
using pwApi.StructuresRegion; | ||
|
||
namespace pwApi.Readers | ||
{ | ||
public class RegionReader | ||
{ | ||
public RegionStruct Region { get; set; } | ||
public RegionReader(string path) | ||
{ | ||
try | ||
{ | ||
Region = new RegionStruct | ||
{ | ||
Regions = new List<Region>(), | ||
Transp = new List<Transport>() | ||
}; | ||
using (var br = new BinaryReader(File.OpenRead(path))) | ||
{ | ||
Region.Version = br.ReadInt32(); | ||
Region.iNumRegion = br.ReadInt32(); | ||
if (Region.Version > 1) | ||
Region.iNumTrans = br.ReadInt32(); | ||
if (Region.Version > 3) | ||
Region.TimeStamp = br.ReadInt32(); | ||
|
||
for (int i = 0; i < Region.iNumTrans + Region.iNumRegion; i++) | ||
{ | ||
int type = br.ReadInt32(); | ||
if (type == 0) | ||
Region.Regions.Add(new Region(br, i)); | ||
else Region.Transp.Add(new Transport(br, Region.Version,i)); | ||
} | ||
} | ||
} | ||
catch (Exception e) | ||
{ | ||
throw e; | ||
} | ||
|
||
} | ||
|
||
public void SaveAsText(string path) | ||
{ | ||
using (var wr = new StreamWriter(path, false, Encoding.GetEncoding(1200))) | ||
{ | ||
wr.WriteLine("version 5"); | ||
wr.WriteLine("1312962951"); | ||
wr.WriteLine(); | ||
foreach (var region in Region.Regions) | ||
{ | ||
region.SaveAsText(wr); | ||
wr.WriteLine(); | ||
} | ||
foreach (var trans in Region.Transp) | ||
{ | ||
trans.SaveAsText(wr); | ||
wr.WriteLine(); | ||
} | ||
} | ||
|
||
} | ||
public void Save(string path) | ||
{ | ||
using (var bw = new BinaryWriter(File.OpenWrite(path))) | ||
{ | ||
bw.Write(Region.Version); | ||
bw.Write(Region.Regions.Count); | ||
if(Region.Version > 1) | ||
bw.Write(Region.Transp.Count); | ||
if(Region.Version > 3) | ||
bw.Write(Region.TimeStamp); | ||
foreach (var reg in Region.Regions) | ||
{ | ||
bw.Write(0); | ||
reg.Save(bw); | ||
} | ||
foreach (var tra in Region.Transp) | ||
{ | ||
bw.Write(1); | ||
tra.Save(bw,Region.Version); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,45 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
|
||
namespace pwApi.StructuresElement | ||
{ | ||
public class ConfigList | ||
{ | ||
public string Name; | ||
public string Skip; | ||
public Type[] Types; | ||
public ConfigList(String name, String values, String types) | ||
|
||
public ConfigList(string name, string skip, string values, string types) | ||
{ | ||
Name = name; | ||
Skip = skip; | ||
var vals = values.Split(';'); | ||
var tty = types.Split(';'); | ||
Types = new Type[vals.Length]; | ||
|
||
for (int i = 0; i < vals.Length; i++) | ||
for(var i = 0; i < vals.Length; i++) | ||
Types[i] = new Type(vals[i], tty[i]); | ||
} | ||
public static List<ConfigList> ParseList(String path) | ||
} | ||
|
||
public class ConfigLists | ||
{ | ||
public byte NpcTalk; | ||
public List<ConfigList> Lists; | ||
|
||
public void ParseList(string path) | ||
{ | ||
List<ConfigList> lists = new List<ConfigList>(); | ||
Lists = new List<ConfigList>(); | ||
var args = File.ReadAllLines(path); | ||
for (int i = 2; i <= args.Length - 2; i += 5) | ||
var count = int.Parse(args[0]); | ||
NpcTalk = byte.Parse(args[1]); | ||
var line = 2; | ||
for(var i = 0; i < count; i++) | ||
{ | ||
lists.Add(new ConfigList(args[i + 1], args[i + 3], args[i + 4])); | ||
while(args[line] == "") | ||
line++; | ||
Lists.Add(new ConfigList(args[line], args[line + 1], args[line + 2], args[line + 3])); | ||
line += 4; | ||
} | ||
return lists; | ||
} | ||
} | ||
} |
Oops, something went wrong.