Quote:
Originally Posted by walmartboi
Your CreateCharacter/SaveCharacter/LoadCharacter values are out of line, try checking them.
|
here are my CreateCharacter/LoadCharacter/SaveCharacter voids...
Create character:
Code:
public static string CreateCharacter(string Account, string Name, ushort Body, byte Job)
{
try
{
if (File.Exists(@"C:\OldCODB\Users\" + Account + ".usr") && !File.Exists(@"C:\OldCODB\Users\Characters\" + Name + ".chr"))
{
try
{
FileStream FS = new FileStream(@"C:\OldCODB\Users\Characters\" + Name + ".chr", FileMode.CreateNew);
BinaryWriter BW = new BinaryWriter(FS);
BW.Write(Account);
BW.Write((uint)Program.Rnd.Next(1000001, 19999999));
if (Body == 1003 || Body == 1004)
BW.Write((ushort)1);//Avatar
else
BW.Write((ushort)201);//Avatar
BW.Write(Body);
BW.Write((ushort)(410 + (Program.Rnd.Next(5) * 100)));//Hair
BW.Write((ushort)1010);//Map
BW.Write((ushort)61);//X
BW.Write((ushort)109);//Y
BW.Write((ushort)0);//Previous Map
BW.Write(Job);
BW.Write((byte)0);//Previous Job, 1st RB
BW.Write((byte)1);//Level
BW.Write((ulong)0);//Experience
ushort Str = 0,Agi = 0, Vit = 0, Spi = 0;
GetInitialStats(Job, ref Str, ref Agi, ref Vit, ref Spi);
BW.Write(Str);
BW.Write(Agi);
BW.Write(Vit);
BW.Write(Spi);
BW.Write((ushort)0);//Stat Points
ushort HP = (ushort)(Vit * 24 + Str * 3 + Agi * 3 + Spi * 3);
BW.Write(HP);
BW.Write((ushort)(Spi * 5));//MP
BW.Write((ulong)0);//Donation
BW.Write((uint)100);//Silvers
BW.Write((uint)0);//CPs
BW.Write((uint)0);//Warehouse Silvers
BW.Write((ulong)0);//Virtue Points
BW.Write((ushort)0);//PK Points
BW.Write((ushort)0);//Guild
BW.Write((uint)0);//Guild Donation
BW.Write((byte)0);//Guild Rank
Game.Equipment Eq = new NewestCOServer.Game.Equipment();
Eq.Open();
Eq.WriteThis(BW);
BW.Write((byte)5);//Inventory Count
#region Beginner Items
if (Job == 100)
{
Game.Item I = new NewestCOServer.Game.Item();
I.ID = 421301;
I.MaxDur = ((DatabaseItem)DatabaseItems[(uint)421301]).Durability;
I.CurDur = I.MaxDur;
I.UID = (uint)Program.Rnd.Next(10000000);
I.WriteThis(BW);
}
else if (Job == 50)
{
Game.Item I = new NewestCOServer.Game.Item();
I.ID = 601301;
I.MaxDur = ((DatabaseItem)DatabaseItems[(uint)601301]).Durability;
I.CurDur = I.MaxDur;
I.UID = (uint)Program.Rnd.Next(10000000);
I.WriteThis(BW);
}
else
{
Game.Item I = new NewestCOServer.Game.Item();
I.ID = 410301;
I.MaxDur = ((DatabaseItem)DatabaseItems[(uint)410301]).Durability;
I.CurDur = I.MaxDur;
I.UID = (uint)Program.Rnd.Next(10000000);
I.WriteThis(BW);
}
Game.Item Armor = new NewestCOServer.Game.Item();
Armor.ID = 132004;
Armor.Color = (Game.Item.ArmorColor)(Program.Rnd.Next(3, 9));
Armor.MaxDur = ((DatabaseItem)DatabaseItems[(uint)132004]).Durability;
Armor.CurDur = Armor.MaxDur;
Armor.UID = (uint)Program.Rnd.Next(10000000);
Armor.WriteThis(BW);
Game.Item Stancher = new NewestCOServer.Game.Item();
Stancher.ID = 1000000;
Stancher.UID = (uint)Program.Rnd.Next(10000000);
Stancher.WriteThis(BW);
Stancher.UID = (uint)Program.Rnd.Next(10000000);
Stancher.WriteThis(BW);
Stancher.UID = (uint)Program.Rnd.Next(10000000);
Stancher.WriteThis(BW);
#endregion
for (int n = 0; n < 5; n++)
{
BW.Write((byte)0);//WH[n] Count
//Warehouse[n]
}
BW.Write((byte)0);//WH[5] Count
//Warehouse[5]
BW.Write((byte)0);//Prof Count
if (Job != 100)
BW.Write((byte)0);//SkillCount
else
{
BW.Write((byte)2);//SkillCount
Game.Skill S = new Game.Skill() { ID = 1000 };
S.WriteThis(BW);
S = new Game.Skill() { ID = 1005 };
S.WriteThis(BW);
}
BW.Write((byte)0);//Friend Count
BW.Write((byte)0);//Enemy Count
BW.Write(false);
BW.Write((int)0);
BW.Write((int)0);
BW.Write((long)0);
BW.Write((int)0);
BW.Write((byte)0);
BW.Write((byte)0);
BW.Write((byte)1);//Merchant
BW.Write(0);//
BW.Write(DateTime.Now.Ticks);
BW.Write((ushort)0);
BW.Write(false);
BW.Write((byte)0);//lottery uses today
BW.Write((byte)0);
BW.Write("0");//WH Pass
BW.Write("None");//Spouse Name
BW.Write((uint)0);//Quiz Pts
BW.Flush();
FS.Flush();
BW.Close();
FS.Close();
FS = new FileStream(@"C:\OldCODB\Users\" + Account + ".usr", FileMode.Append);
BW = new BinaryWriter(FS);
BW.Write((byte)Name.Length);
BW.Write(Encoding.ASCII.GetBytes(Name));
BW.Flush();
FS.Flush();
BW.Close();
FS.Close();
Game.Character C = LoadCharacter(Name, ref Account);
if (C != null)
{
C.UniversityPoints = 0;
SaveCharacter(C, Account);
}
}
catch { return "Error! Try again."; }
return "ANSWER_OK";
}
return "Error: Character already exists!";
}
catch (Exception Exc) { Console.WriteLine(Exc); return "Failed to create the character."; }
}
}
LoadCharacter:
Code:
public static Game.Character LoadCharacter(string Name, ref string Account)
{
try
{
Game.Character C = new NewestCOServer.Game.Character();
if (File.Exists(@"C:\OldCODB\Users\Characters\" + Name + ".chr"))
{
FileStream FS = new FileStream(@"C:\OldCODB\Users\Characters\" + Name + ".chr", FileMode.Open);
BinaryReader BR = new BinaryReader(FS);
C.Name = Name;
Account = BR.ReadString();
C.EntityID = BR.ReadUInt32();
C.Avatar = BR.ReadUInt16();
C.Body = BR.ReadUInt16();
C.Hair = BR.ReadUInt16();
C.Loc = new NewestCOServer.Game.Location();
C.Loc.Map = BR.ReadUInt16();
C.Loc.X = BR.ReadUInt16();
C.Loc.Y = BR.ReadUInt16();
C.Loc.PreviousMap = BR.ReadUInt16();
C.Job = BR.ReadByte();
C.PreviousJob1 = BR.ReadByte();
C.PreviousJob2 = BR.ReadByte();
C.Level = BR.ReadByte();
C.Experience = BR.ReadUInt64();
C.Str = BR.ReadUInt16();
C.Agi = BR.ReadUInt16();
C.Vit = BR.ReadUInt16();
C.Spi = BR.ReadUInt16();
C.StatPoints = BR.ReadUInt16();
C.CurHP = BR.ReadUInt16();
C.CurMP = BR.ReadUInt16();
C.Nobility.Donation = BR.ReadUInt64();
C.Nobility.ListPlace = -1;
if (C.Nobility.Donation >= 3000000)
{
C.Nobility.ListPlace = 50;
for (int i = 49; i >= 0; i--)
{
if (C.Nobility.Donation >= Game.World.EmpireBoard[i].Donation)
C.Nobility.ListPlace--;
}
if (C.Nobility.ListPlace < 50)
{
if (C.Nobility.Donation >= 30000000 && C.Nobility.Donation <= 100000000)
C.Nobility.Rank = Game.Ranks.Knight;
else if (C.Nobility.Donation >= 100000000 && C.Nobility.Donation <= 200000000)
C.Nobility.Rank = Game.Ranks.Baron;
else if (C.Nobility.Donation >= 200000000 && C.Nobility.Donation <= 300000000)
C.Nobility.Rank = Game.Ranks.Earl;
else if (C.Nobility.ListPlace >= 15 && C.Nobility.ListPlace <= 50)
C.Nobility.Rank = Game.Ranks.Duke;
else if (C.Nobility.ListPlace >= 3 && C.Nobility.ListPlace <= 15)
C.Nobility.Rank = Game.Ranks.Prince;
else if (C.Nobility.ListPlace <= 3)
C.Nobility.Rank = Game.Ranks.King;
}
}
C.Silvers = BR.ReadUInt32();
C.CPs = BR.ReadUInt32();
C.WHSilvers = BR.ReadUInt32();
C.VP = BR.ReadUInt64();
C.PKPoints = BR.ReadUInt16();
ushort GID = BR.ReadUInt16();
if (Features.Guilds.AllTheGuilds.Contains(GID))
{
C.MyGuild = (Features.Guild)Features.Guilds.AllTheGuilds[GID];
uint Don = BR.ReadUInt32(); ;
byte GR = BR.ReadByte();
if (((Hashtable)C.MyGuild.Members[GR]).Contains(C.EntityID))
{
C.GuildDonation = Don;
C.GuildRank = (Features.GuildRank)GR;
C.MembInfo = (Features.MemberInfo)((Hashtable)C.MyGuild.Members[GR])[C.EntityID];
C.MembInfo.Level = C.Level;
C.GuildDonation = C.MembInfo.Donation;
C.GuildRank = C.MembInfo.Rank;
}
else
C.MyGuild = null;
}
else BR.ReadBytes(5);
C.Equips = new NewestCOServer.Game.Equipment();
C.Equips.ReadThis(BR);
C.Inventory = new ArrayList(40);
byte InventoryCount = BR.ReadByte();
for (byte i = 0; i < InventoryCount; i++)
{
Game.Item I = new NewestCOServer.Game.Item();
I.ReadThis(BR);
C.Inventory.Add(I);
}
C.Warehouses = new NewestCOServer.Game.Banks();
C.Warehouses.ReadThis(BR);
C.Skills = new Hashtable();
byte SkillCount = BR.ReadByte();
for (byte i = 0; i < SkillCount; i++)
{
Game.Skill S = new NewestCOServer.Game.Skill();
S.ReadThis(BR);
C.Skills.Add(S.ID, S);
if (S.ID == 3060)
C.CanReflect = true;
}
C.Profs = new Hashtable();
byte ProfCount = BR.ReadByte();
for (byte i = 0; i < ProfCount; i++)
{
Game.Prof P = new NewestCOServer.Game.Prof();
P.ReadThis(BR);
if (!C.Profs.Contains(P.ID))
C.Profs.Add(P.ID, P);
}
C.Friends = new Hashtable();
byte FriendCount = BR.ReadByte();
for (byte i = 0; i < FriendCount; i++)
{
Game.Friend F = new NewestCOServer.Game.Friend();
F.ReadThis(BR);
if (!C.Friends.Contains(F.UID))
C.Friends.Add(F.UID, F);
}
C.Enemies = new Hashtable();
byte EnemyCount = BR.ReadByte();
for (byte i = 0; i < EnemyCount; i++)
{
Game.Enemy E = new NewestCOServer.Game.Enemy();
E.ReadThis(BR);
if (!C.Enemies.Contains(E.UID))
C.Enemies.Add(E.UID, E);
}
try
{
C.DoubleExp = BR.ReadBoolean();
C.DoubleExpLeft = BR.ReadInt32();
C.BlessingLasts = BR.ReadInt32();
C.BlessingStarted = DateTime.FromBinary(BR.ReadInt64());
C.LuckyTime = BR.ReadUInt32();
C.ExpBallsUsedToday = BR.ReadByte();
C.Reborns = BR.ReadByte();
C.Merchant = (NewestCOServer.Game.MerchantTypes)BR.ReadByte();
C.VipLevel = BR.ReadByte();
try
{
C.LastLogin = DateTime.FromBinary(BR.ReadInt64());
}
catch { C.LastLogin = DateTime.Now; }
C.TrainTimeLeft = BR.ReadUInt16();
C.InOTG = BR.ReadBoolean();
C.LotteryUsed = BR.ReadByte();
try
{
C.WHPassword = Encoding.ASCII.GetString(BR.ReadBytes(BR.ReadByte()));
if (!C.MyClient.ValidWHPass(C.WHPassword))
C.WHPassword = "0";
}
catch { C.WHPassword = "0"; C.UniversityPoints = 0; }
try
{
C.Spouse = Encoding.ASCII.GetString(BR.ReadBytes(BR.ReadByte()));
C.UniversityPoints = BR.ReadUInt32();
}
catch
{
C.VipLevel = 0;
C.ExpBallsUsedToday = 0;
C.LotteryUsed = 0;
C.TrainTimeLeft = 0;
C.InOTG = false;
C.LotteryUsed = 0;
C.WHPassword = "0";
C.Spouse = "None";
C.UniversityPoints = 0;
}
LoadFlowerRank(Name);
}
catch (Exception ex) { Console.WriteLine(ex.ToString()); }
FS.Flush();
BR.Close();
FS.Close();
C.Loaded = true;
}
return C;
}
catch (Exception Exc) { Console.WriteLine(Exc); return null; }
}
and my SaveCharacter:
Code:
public static void SaveCharacter(Game.Character C, string Acc)
{
try
{
FileStream FS = new FileStream(@"C:\OldCODB\Users\Characters\" + C.Name + ".chr", FileMode.Open);
BinaryWriter BW = new BinaryWriter(FS);
int DoubleExp = C.DoubleExpLeft;
if (C.DoubleExp)
DoubleExp -= (int)(DateTime.Now - C.ExpPotionUsed).TotalSeconds;
BW.Write(Acc);
BW.Write(C.EntityID);
BW.Write(C.Avatar);
BW.Write(C.Body);
BW.Write(C.Hair);//Hair
BW.Write(C.Loc.Map);//Map
BW.Write(C.Loc.X);//X
BW.Write(C.Loc.Y);//Y
BW.Write(C.Loc.PreviousMap);//Previous Map
BW.Write(C.Job);
BW.Write(C.PreviousJob1);//Previous Job, 1st RB
BW.Write(C.PreviousJob2);
BW.Write(C.Level);//Level
BW.Write(C.Experience);//Experience
BW.Write(C.Str);
BW.Write(C.Agi);
BW.Write(C.Vit);
BW.Write(C.Spi);
BW.Write(C.StatPoints);//Stat Points
BW.Write(C.CurHP);
BW.Write(C.CurMP);//MP
BW.Write(C.Nobility.Donation);
BW.Write(C.Silvers);//Silvers
BW.Write(C.CPs);
BW.Write(C.WHSilvers);//Warehouse Silvers
BW.Write(C.VP);//Virtue Points
BW.Write(C.PKPoints);//PK Points
if (C.MyGuild != null)
{
BW.Write(C.MyGuild.GuildID);//Guild
BW.Write(C.GuildDonation);//Guild Donation
BW.Write((byte)C.GuildRank);//Guild Rank
}
else BW.Write(new byte[7]);
C.Equips.WriteThis(BW);
BW.Write((byte)C.Inventory.Count);
foreach (Game.Item I in C.Inventory)
I.WriteThis(BW);
C.Warehouses.WriteThis(BW);
BW.Write((byte)C.Skills.Count);
foreach (Game.Skill I in C.Skills.Values)
I.WriteThis(BW);
BW.Write((byte)C.Profs.Count);
foreach (Game.Prof I in C.Profs.Values)
I.WriteThis(BW);
BW.Write((byte)C.Friends.Count);
foreach (Game.Friend I in C.Friends.Values)
I.WriteThis(BW);
BW.Write((byte)C.Enemies.Count);
foreach (Game.Enemy I in C.Enemies.Values)
I.WriteThis(BW);
BW.Write(C.DoubleExp);
BW.Write(DoubleExp);
BW.Write(C.BlessingLasts);
BW.Write(C.BlessingStarted.Ticks);
if (C.GettingLuckyTime)
{
if (!C.Prayer)
C.LuckyTime += (uint)(DateTime.Now - C.PrayDT).TotalSeconds;
else
C.LuckyTime += (uint)(DateTime.Now - C.PrayDT).TotalSeconds * 3;
C.PrayDT = DateTime.Now;
}
BW.Write(C.LuckyTime);
BW.Write(C.ExpBallsUsedToday);
BW.Write(C.Reborns);
BW.Write((byte)C.Merchant);//
BW.Write(C.VipLevel);//
BW.Write(DateTime.Now.Ticks);//When logged off, for otg feature purposes
BW.Write((ushort)(C.TrainTimeLeft + ((DateTime.Now - C.LoggedOn).TotalMinutes * 10)));//Train time left (in minutes)
BW.Write(C.InOTG);
BW.Write(C.LotteryUsed);
BW.Write(C.WHPassword);
BW.Write(C.Spouse);
BW.Write(C.UniversityPoints);//Quiz Pts
if (C.MyClient != null && C.MyClient.AuthInfo.Status != "[GM]" && C.MyClient.AuthInfo.Status != "[PM]")
{
if (C.WHSilvers + C.Silvers >= 50000000)
Console.WriteLine(C.Name + " has suspiciously much silvers: " + (C.WHSilvers + C.Silvers));
if (C.CPs >= 100000)
Console.WriteLine(C.Name + " has suspiciously much cps: " + C.CPs);
}
BW.Flush();
FS.Flush();
BW.Close();
FS.Close();
SaveFlowerRank(C);
}
catch (Exception Exc) { Console.WriteLine(Exc); }
}
can u tell anything from dat lol? Im a newb sorry...