5165 Save or Load Character Problem.

07/28/2010 04:38 killersub#1
alright so IDK wtf I did 2 dis source dat now wen I login and log out my character doesnt save sumhow and like his/her gears are all fucked up wen u login again like...a necklace is where da armor should be at lol...and da armor is like da weapon...so on...only like 3 things save...

well I'm hoping I can get answers from dis...I'll post my SaveCharacter/LoadCharacter void here...

Code:
public static Game.Character LoadCharacter(string Name, ref string Account)
        {
            try
            {
                Game.Character C = new CoSX.Game.Character();
                if (File.Exists(@"C:\CoSX\Database\Users\Characters\" + Name + ".chr"))
                {
                    FileStream FS = new FileStream(@"C:\CoSX\Database\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 CoSX.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.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 CoSX.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 CoSX.Game.Item();
                        I.ReadThis(BR);
                        C.Inventory.Add(I);
                    }
                    C.Warehouses = new CoSX.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 CoSX.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 CoSX.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 CoSX.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 CoSX.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.TripleExp = BR.ReadBoolean();
                        C.TripleExpLeft = BR.ReadInt32();
                        C.QuadrupleExp = BR.ReadBoolean();
                        C.QuadrupleExpLeft = 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 = (CoSX.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();
                        C.VipMapToday = BR.ReadByte();
                        C.VotedToday = BR.ReadByte();
                        C.ClaimGWWinnings = BR.ReadByte();

                        try
                        {
                            C.WHPassword = Encoding.ASCII.GetString(BR.ReadBytes(BR.ReadByte()));
                            if (C.WHPassword.Length == 0)
                                C.WHPassword = "";
                        }
                        catch { C.WHPassword = ""; C.UniversityPoints = 0; }

                        try
                        {
                            C.Spouse = Encoding.ASCII.GetString(BR.ReadBytes(BR.ReadByte()));
                            C.UniversityPoints = BR.ReadUInt32();
                            C.HunterName = BR.ReadString();
                            C.MonsterHunter = BR.ReadInt32();
                            C.MHunter = BR.ReadBoolean(); 
                            C.Top = BR.ReadInt32();
                        }
                        catch
                        {
                            C.VipLevel = 0;
                            C.ExpBallsUsedToday = 0;
                            C.LotteryUsed = 0;
                            C.TrainTimeLeft = 0;
                            C.InOTG = false;
                            C.LotteryUsed = 0;
                            C.WHPassword = "";
                            C.Spouse = "None";
                            C.UniversityPoints = 0;
                            C.HunterName = "Default";
                            C.MonsterHunter = 0;
                            C.MHunter = false; 
                            C.VipMapToday = 0;
                            C.ClaimGWWinnings = 0;
                            C.VotedToday = 0;
                        }
                    }
                    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; }
        }
Code:
public static void SaveCharacter(Game.Character C, string Acc)
        {
            try
            {
                FileStream FS = new FileStream(@"C:\CoSX\Database\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;
                int TripleExp = C.TripleExpLeft;
                if (C.TripleExp)
                    TripleExp -= (int)(DateTime.Now - C.ExpPotionUsed).TotalSeconds;
                int QuadrupleExp = C.QuadrupleExpLeft;
                if (C.QuadrupleExp)
                    QuadrupleExp -= (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.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.TripleExp);
                BW.Write(TripleExp);
                BW.Write(C.QuadrupleExp);
                BW.Write(QuadrupleExp);
                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.VipMapToday);
                BW.Write(C.ClaimGWWinnings);
                BW.Write(C.VotedToday);
                BW.Write(C.WHPassword);
                BW.Write(C.Spouse);
                BW.Write(C.UniversityPoints);//Quiz Pts 
                BW.Write(C.HunterName);//Quest
                BW.Write(C.MonsterHunter);//Quest
                BW.Write(C.MHunter);//Quest 
                BW.Write(C.Top);

                BW.Flush();
                FS.Flush();
                BW.Close();
                FS.Close();
            }
            catch (Exception Exc) { Console.WriteLine(Exc); }
        }
Regards,
killersub
07/29/2010 03:54 killersub#2
so there's no help with this problem?
07/29/2010 04:06 Fish*#3
have you tried replace it with the old save/load, so nothing is changed?
07/29/2010 04:43 killersub#4
Quote:
Originally Posted by grillmad View Post
have you tried replace it with the old save/load, so nothing is changed?
well as u see in da SaveCharacter void I added also 10x and 20x exp potions (TripleExp and QuadrupleExp) IDK if dats da prob...
also I added da save for MonsterHunter quest...

In da LoadCharacter I have da same shit lol...idk if DATS it...but wat do U suggest?
07/29/2010 07:44 Fish*#5
Try add 1 after 1.
Then u can see wich one makes the problem :)
07/29/2010 22:27 ryuchetval#6
you probably deleted some rows of coding...idk where it is..i know i did this and everything screwed up....
solution:
started all over again :) (i kno it sucks)

also i don't know if this is what you did...i'm just guessing