public void PacketFactoryTest()
        {
            // this test only tests the factory, not the packets intialize factory
            PacketFactory.Initialize <WalkPacket>();

            Logger.InitializeLogger(LogManager.GetLogger(typeof(CoreTest)));

            // 1234 simulates packet header iterative number
            string      equipPacket             = "equip 5 0 0.4903.5.0.0 2.340.0.0.0 3.720.0.0.0 5.4912.6.0.0 9.227.0.0.0 10.803.0.0.0 11.347.0.0.0 13.4146.0.0.0 14.4138.0.0.0";
            EquipPacket serializedPacket        = PacketFactory.Serialize <EquipPacket>(equipPacket);
            string      deserializedEquipPacket = PacketFactory.Deserialize(serializedPacket);

            Assert.AreEqual(equipPacket, deserializedEquipPacket);

            // 1234 simulates packet header iterative number
            string   inPacket             = "in 1 ImACharacter - 1 80 116 0 2 1 0 3 0 -1.12.1.8.-1.-1.-1.-1.-1 100 100 0 -1 0 0 0 0 0 0 0 0 -1 - 1 0 0 0 0 1 0 0 0 10 0";
            InPacket serializedInPacket   = PacketFactory.Serialize <InPacket>(inPacket);
            string   deserializedInPacket = PacketFactory.Deserialize(serializedInPacket);

            Assert.AreEqual(inPacket, deserializedInPacket);

            WalkPacket walkPacket = PacketFactory.Serialize <WalkPacket>("walk 3a0 115 1 11");

            Assert.IsNull(walkPacket);
        }
Beispiel #2
0
        public void PacketFactoryTest()
        {
            // this test only tests the factory, not the packets intialize factory
            PacketFactory.Initialize <WalkPacket>();

            Logger.InitializeLogger(LogManager.GetLogger(typeof(CoreTest)));

            // mtlist packet
            const string          mtlistPacket             = "mtlist 30 3 1698 3 1703 3 1861 3 1865 3 1870 3 1873 3 1874 3 1879 3 1880 3 1882 3 1885 3 1887 3 1890 3 1896 3 1900 3 1901 3 1904 3 1908 3 1915 3 1916 3 1919 3 1923 3 1925 3 1931 3 1934 3 1935 3 1937 3 1941 3 1942 3 1946";
            MultiTargetListPacket deserializedMtlistPacket = PacketFactory.Deserialize <MultiTargetListPacket>(mtlistPacket);
            string serializedMtlistPacket = PacketFactory.Serialize(deserializedMtlistPacket);

            Assert.AreEqual(mtlistPacket, serializedMtlistPacket);

            // Equip Packet
            const string equipPacket             = "equip 5 0 0.4903.5.0.0 2.340.0.0.0 3.720.0.0.0 5.4912.6.0.0 9.227.0.0.0 10.803.0.0.0 11.347.0.0.0 13.4146.0.0.0 14.4138.0.0.0";
            EquipPacket  deserializedEquipPacket = PacketFactory.Deserialize <EquipPacket>(equipPacket);
            string       serializedEquipPacket   = PacketFactory.Serialize(deserializedEquipPacket);

            Assert.AreEqual(equipPacket, serializedEquipPacket);

            // In Packet
            const string inPacket             = "in 1 ImACharacter - 1 80 116 0 2 1 0 3 0 -1.12.1.8.-1.-1.-1.-1.-1 100 100 0 -1 0 0 0 0 0 0 0 0 -1 - 1 0 0 0 0 1 0 0 0 10 0";
            InPacket     deserializedInPacket = PacketFactory.Deserialize <InPacket>(inPacket);
            string       serializedInPacket   = PacketFactory.Serialize(deserializedInPacket);

            Assert.AreEqual(inPacket, serializedInPacket);

            // Walk Packet
            const string walkPacket             = "walk 3 115 1 11";
            WalkPacket   deserializedWalkPacket = PacketFactory.Deserialize <WalkPacket>(walkPacket);
            string       serializedWalkPacket   = PacketFactory.Serialize(deserializedWalkPacket);

            Assert.AreEqual(walkPacket, serializedWalkPacket);

            WalkPacket invalidWalkPacket = PacketFactory.Deserialize <WalkPacket>("walk 3a0 115 1 11");

            Assert.IsNull(invalidWalkPacket);

            // Dialog Packet
            const string dialogPacket = "dlg #walk^3^115^1^11 #walk^3^115^1^11 Do you really wanna walk this way?";
            DialogPacket <WalkPacket, WalkPacket> deserializedDialogPacket = PacketFactory.Deserialize <DialogPacket <WalkPacket, WalkPacket> >(dialogPacket);
            string serializedDialogPacket = PacketFactory.Serialize(deserializedDialogPacket);

            Assert.AreEqual(dialogPacket, serializedDialogPacket);
        }
Beispiel #3
0
        public void PacketFactoryTest()
        {
            //this test only tests the factory, not the packets

            //intialize factory
            PacketFactory.Initialize <WalkPacket>();

            //1234 simulates packet header iterative number
            string      equipPacket             = "1234 equip 5 0 0.4903.5.0.0 2.340.0.0.0 3.720.0.0.0 5.4912.6.0.0 9.227.0.0.0 10.803.0.0.0 11.347.0.0.0 13.4146.0.0.0 14.4138.0.0.0";
            EquipPacket serializedPacket        = PacketFactory.Serialize <EquipPacket>(equipPacket);
            string      deserializedEquipPacket = PacketFactory.Deserialize(serializedPacket);

            Assert.AreEqual(equipPacket, $"1234 {deserializedEquipPacket}");

            //1234 simulates packet header iterative number
            string   inPacket             = "1234 in 1 ImACharacter - 1 80 116 0 2 1 0 3 0 -1.12.1.8.-1.-1.-1.-1.-1 100 100 0 -1 0 0 0 0 0 0 0 0 -1 - 1 0 0 0 0 1 0 0 0 10 0";
            InPacket serializedInPacket   = PacketFactory.Serialize <InPacket>(inPacket);
            string   deserializedInPacket = PacketFactory.Deserialize(serializedInPacket);

            Assert.AreEqual(inPacket, $"1234 {deserializedInPacket}");
        }
Beispiel #4
0
        public void PacketFactoryTest()
        {
            // this test only tests the factory, not the packets intialize factory
            PacketFactory.Initialize <WalkPacket>();

            Logger.InitializeLogger(LogManager.GetLogger(typeof(CoreTest)));

            // Equip Packet
            string      equipPacket             = "equip 5 0 0.4903.5.0.0 2.340.0.0.0 3.720.0.0.0 5.4912.6.0.0 9.227.0.0.0 10.803.0.0.0 11.347.0.0.0 13.4146.0.0.0 14.4138.0.0.0";
            EquipPacket deserializedEquipPacket = PacketFactory.Deserialize <EquipPacket>(equipPacket);
            string      serializedEquipPacket   = PacketFactory.Serialize(deserializedEquipPacket);

            Assert.AreEqual(equipPacket, serializedEquipPacket);

            // In Packet
            string   inPacket             = "in 1 ImACharacter - 1 80 116 0 2 1 0 3 0 -1.12.1.8.-1.-1.-1.-1.-1 100 100 0 -1 0 0 0 0 0 0 0 0 -1 - 1 0 0 0 0 1 0 0 0 10 0";
            InPacket deserializedInPacket = PacketFactory.Deserialize <InPacket>(inPacket);
            string   serializedInPacket   = PacketFactory.Serialize(deserializedInPacket);

            Assert.AreEqual(inPacket, serializedInPacket);

            // Walk Packet
            string     walkPacket             = "walk 3 115 1 11";
            WalkPacket deserializedWalkPacket = PacketFactory.Deserialize <WalkPacket>(walkPacket);
            string     serializedWalkPacket   = PacketFactory.Serialize(deserializedWalkPacket);

            Assert.AreEqual(walkPacket, serializedWalkPacket);

            WalkPacket invalidWalkPacket = PacketFactory.Deserialize <WalkPacket>("walk 3a0 115 1 11");

            Assert.IsNull(invalidWalkPacket);

            // Dialog Packet
            string dialogPacket = "dlg #walk^3^115^1^11 #walk^3^115^1^11 Do you really wanna walk this way?";
            DialogPacket <WalkPacket, WalkPacket> deserializedDialogPacket = PacketFactory.Deserialize <DialogPacket <WalkPacket, WalkPacket> >(dialogPacket);
            string serializedDialogPacket = PacketFactory.Serialize(deserializedDialogPacket);

            Assert.AreEqual(dialogPacket, serializedDialogPacket);
        }
        public void loadTextFile(Stream inFile)
        {
            StreamReader fileReader = new StreamReader(inFile);

            while (!fileReader.EndOfStream)
            {
                string currLine    = fileReader.ReadLine();
                string croppedLine = currLine.Trim();
                if (!currLine.StartsWith("//") && croppedLine != "")
                {
                    string[] splitLine = currLine.Split('\t');
                    if (splitLine[0] == "R")    //Range
                    {
                        int         index = Convert.ToInt32(splitLine[1]);
                        short       val1  = Convert.ToInt16(splitLine[2]);
                        short       val2  = Convert.ToInt16(splitLine[3]);
                        short       val3  = Convert.ToInt16(splitLine[4]);
                        short       val4  = Convert.ToInt16(splitLine[5]);
                        EquipPacket temp  = new EquipPacket();
                        temp.Value1 = val1;
                        temp.Value2 = val2;
                        temp.Value3 = val3;
                        temp.Value4 = val4;
                        if (index >= parsedPackets.Count)
                        {
                            parsedPackets.Add(temp);
                        }
                        else
                        {
                            parsedPackets[index] = temp;
                        }
                    }
                    else
                    {
                        string[] indices     = splitLine[0].Split(':');
                        int      manufacture = Convert.ToByte(indices[0]);
                        int      index       = Convert.ToByte(indices[1], 16);
                        parsedWeapons[manufacture][index].IsValid = false;
                        for (int j = 1; j < splitLine.Length; j++)
                        {
                            if (splitLine[j] != "0")
                            {
                                parsedWeapons[manufacture][index].IsValid = true;
                            }
                        }

                        parsedWeapons[manufacture][index].AttackName     = Convert.ToByte(splitLine[1]);
                        parsedWeapons[manufacture][index].ShootEffect    = Convert.ToByte(splitLine[2]);
                        parsedWeapons[manufacture][index].WeaponModel    = Convert.ToByte(splitLine[3]);
                        parsedWeapons[manufacture][index].SelectedRange  = Convert.ToByte(splitLine[4]);
                        parsedWeapons[manufacture][index].MinATP         = Convert.ToInt16(splitLine[5]);
                        parsedWeapons[manufacture][index].MaxATP         = Convert.ToInt16(splitLine[6]);
                        parsedWeapons[manufacture][index].Ata            = Convert.ToInt16(splitLine[7]);
                        parsedWeapons[manufacture][index].StatusEffect   = Convert.ToByte(splitLine[8]);
                        parsedWeapons[manufacture][index].StatusLevel    = Convert.ToByte(splitLine[9]);
                        parsedWeapons[manufacture][index].MaxTargets     = Convert.ToByte(splitLine[10]);
                        parsedWeapons[manufacture][index].AvailableRaces = Convert.ToByte(splitLine[11]);
                        parsedWeapons[manufacture][index].ReqATP         = Convert.ToInt16(splitLine[12]);
                        parsedWeapons[manufacture][index].Rank           = Convert.ToByte(splitLine[13]);
                        parsedWeapons[manufacture][index].DropElement    = Convert.ToByte(splitLine[14]);
                        parsedWeapons[manufacture][index].DropPercent    = Convert.ToByte(splitLine[15]);
                        parsedWeapons[manufacture][index].SoundEffect    = Convert.ToByte(splitLine[16]);
                        parsedWeapons[manufacture][index].SetID          = Convert.ToByte(splitLine[17]);
                        parsedWeapons[manufacture][index].BasePP         = Convert.ToInt16(splitLine[18]);
                        parsedWeapons[manufacture][index].RegenPP        = Convert.ToInt16(splitLine[19]);
                        parsedWeapons[manufacture][index].AtpMod         = Convert.ToInt16(splitLine[20]);
                        parsedWeapons[manufacture][index].DfpMod         = Convert.ToInt16(splitLine[21]);
                        parsedWeapons[manufacture][index].AtaMod         = Convert.ToInt16(splitLine[22]);
                        parsedWeapons[manufacture][index].EvpMod         = Convert.ToInt16(splitLine[23]);
                        parsedWeapons[manufacture][index].StaMod         = Convert.ToInt16(splitLine[24]);
                        parsedWeapons[manufacture][index].TpMod          = Convert.ToInt16(splitLine[25]);
                        parsedWeapons[manufacture][index].MstMod         = Convert.ToInt16(splitLine[26]);
                    }
                }
            }
        }
        bool isPsp1 = false;     //Hack, but works.

        public WeaponParamFile(string inFilename, byte[] rawData, byte[] subHeader, int[] ptrs, int baseAddr)
        {
            header   = subHeader;
            filename = inFilename;
            byte[] tempData = new byte[rawData.Length];
            Array.Copy(rawData, tempData, rawData.Length);
            calculatedPointers = new int[ptrs.Length]; //It may be populated now, but NOT FINAL UNTIL IT'S FINAL.
            for (int i = 0; i < ptrs.Length; i++)
            {
                calculatedPointers[i] = ptrs[i] - baseAddr;
                int    ptrLoc = BitConverter.ToInt32(rawData, calculatedPointers[i]);
                byte[] temp   = BitConverter.GetBytes(ptrLoc - baseAddr);
                Array.Copy(temp, 0, tempData, calculatedPointers[i], temp.Length);
            }
            int          numEntries = 14; //Max number of weapons per manufacturer.
            MemoryStream rawStream  = new MemoryStream(tempData);
            BinaryReader rawReader  = new BinaryReader(rawStream);

            rawStream.Seek(4, SeekOrigin.Begin);
            int fileLength = rawReader.ReadInt32(); //Use to check dummy pointers? The file can happily go over!
            int headerLoc  = rawReader.ReadInt32();

            rawStream.Seek(0x14, SeekOrigin.Begin);
            if (rawReader.ReadInt32() == 0x61726761)
            {
                dataType   = 2;
                numEntries = 80;
            }

            rawStream.Seek(headerLoc, SeekOrigin.Begin);
            int equipPacketLoc = rawReader.ReadInt32();

            weaponClassValue = rawReader.ReadInt32();
            int[] dataLocs        = new int[4];
            int   lowestDataLoc   = 0xFFFFFF;
            int   lowestDataIndex = -1;
            int   secondDataLoc   = headerLoc;
            int   secondDataIndex = -1;

            for (int i = 0; i < 4; i++)
            {
                dataLocs[i] = rawReader.ReadInt32();
                if (dataLocs[i] != 0 && dataLocs[i] < lowestDataLoc)
                {
                    lowestDataLoc   = dataLocs[i];
                    lowestDataIndex = i;
                }
            }
            for (int i = 0; i < 4; i++)
            {
                if (dataLocs[i] != 0 && dataLocs[i] != lowestDataLoc && dataLocs[i] < secondDataLoc)
                {
                    secondDataLoc   = dataLocs[i];
                    secondDataIndex = i;
                }
            }
            byte[][] validWeapons = new byte[4][];
            if (dataType == 2)
            {
                packetCount = rawReader.ReadByte();
                weaponType  = rawReader.ReadByte();
                equipStat   = rawReader.ReadInt16();
            }

            int[] weaponCounts = new int[4];

            int indexLoc = (int)rawStream.Position;

            byte[] firstFour = rawReader.ReadBytes(4);
            byte   expected  = 0;

            for (int i = 0; i < 4; i++)
            {
                if (firstFour[i] != 0xFF && firstFour[i] != expected)
                {
                    isPsp1      = true;
                    packetCount = rawReader.ReadByte();
                    weaponType  = rawReader.ReadByte();
                    equipStat   = rawReader.ReadInt16();
                    break;
                }
                else if (firstFour[i] == expected)
                {
                    expected++;
                }
            }

            if (!isPsp1)
            {
                rawStream.Seek(indexLoc, SeekOrigin.Begin);
                for (int i = 0; i < 4; i++)
                {
                    validWeapons[i] = rawReader.ReadBytes(numEntries);
                    for (int j = 0; j < validWeapons[i].Length; j++)
                    {
                        if (validWeapons[i][j] != 0xFF)
                        {
                            weaponCounts[i]++;
                        }
                    }
                }
            }
            else
            {
                for (int i = 0; i < 4; i++)
                {
                    if (dataLocs[i] != 0)
                    {
                        bool found = false;
                        for (int j = i + 1; j < 4; j++)
                        {
                            if (dataLocs[j] != 0)
                            {
                                weaponCounts[i] = (dataLocs[j] - dataLocs[i]) / 38;
                                found           = true;
                                break;
                            }
                        }
                        if (!found)
                        {
                            weaponCounts[i] = (headerLoc - dataLocs[i]) / 38;
                        }
                    }
                }
            }

            if (dataType != 2 && !isPsp1)
            {
                packetCount = rawReader.ReadByte();
                weaponType  = rawReader.ReadByte();
                equipStat   = rawReader.ReadInt16();
            }
            if (!isPsp1 && (lowestDataIndex == -1 || weaponCounts[lowestDataIndex] * 0x40 <= secondDataLoc - lowestDataLoc))
            {
                dataType = 1;
                throw new Exception("v1 weapons file not supported yet");
                //entry
            }
            if (equipPacketLoc < lowestDataLoc && packetCount > 0)
            {
                rawStream.Seek(equipPacketLoc, SeekOrigin.Begin);
                equipPacket = rawReader.ReadBytes(packetCount * 8);
                //parsedPackets = new EquipPacket[packetCount];
                for (int i = 0; i < packetCount; i++)
                {
                    EquipPacket tempPacket = new EquipPacket();
                    tempPacket.Value1 = BitConverter.ToInt16(equipPacket, i * 8 + 0);
                    tempPacket.Value2 = BitConverter.ToInt16(equipPacket, i * 8 + 2);
                    tempPacket.Value3 = BitConverter.ToInt16(equipPacket, i * 8 + 4);
                    tempPacket.Value4 = BitConverter.ToInt16(equipPacket, i * 8 + 6);
                    parsedPackets.Add(tempPacket);
                }
            }
            parsedWeapons = new Weapon[4][];
            for (int j = 0; j < 4; j++)
            {
                if (isPsp1 && dataLocs[j] != 0)
                {
                    parsedWeapons[j] = new Weapon[weaponCounts[j] - ((sbyte)firstFour[j])];
                }
                else if (isPsp1)
                {
                    parsedWeapons[j] = new Weapon[0];
                }
                else
                {
                    parsedWeapons[j] = new Weapon[numEntries];
                }
                if (dataLocs[j] != 0)
                {
                    for (int i = 0; i < parsedWeapons[j].Length; i++)
                    {
                        parsedWeapons[j][i]         = new Weapon();
                        parsedWeapons[j][i].IsValid = false;
                        if ((isPsp1 && (i + ((sbyte)firstFour[j]) >= 0)) || (!isPsp1 && validWeapons[j][i] != 0xFF))
                        {
                            if (isPsp1)
                            {
                                rawStream.Seek(dataLocs[j] + (i + ((sbyte)firstFour[j])) * 38, SeekOrigin.Begin);
                            }
                            else
                            {
                                rawStream.Seek(dataLocs[j] + validWeapons[j][i] * 38, SeekOrigin.Begin);
                            }
                            parsedWeapons[j][i].IsValid        = true;
                            parsedWeapons[j][i].AttackName     = rawReader.ReadByte();
                            parsedWeapons[j][i].ShootEffect    = rawReader.ReadByte();
                            parsedWeapons[j][i].WeaponModel    = rawReader.ReadByte();
                            parsedWeapons[j][i].SelectedRange  = rawReader.ReadByte();
                            parsedWeapons[j][i].MinATP         = rawReader.ReadInt16();
                            parsedWeapons[j][i].MaxATP         = rawReader.ReadInt16();
                            parsedWeapons[j][i].Ata            = rawReader.ReadInt16();
                            parsedWeapons[j][i].StatusEffect   = rawReader.ReadByte();
                            parsedWeapons[j][i].StatusLevel    = rawReader.ReadByte();
                            parsedWeapons[j][i].MaxTargets     = rawReader.ReadByte();
                            parsedWeapons[j][i].AvailableRaces = rawReader.ReadByte();
                            parsedWeapons[j][i].ReqATP         = rawReader.ReadInt16();
                            byte rankEle = rawReader.ReadByte();
                            parsedWeapons[j][i].Rank        = (byte)(rankEle & 0xF);
                            parsedWeapons[j][i].DropElement = (byte)(rankEle >> 4);
                            parsedWeapons[j][i].DropPercent = rawReader.ReadByte();
                            parsedWeapons[j][i].SoundEffect = rawReader.ReadByte();
                            parsedWeapons[j][i].SetID       = rawReader.ReadByte();
                            parsedWeapons[j][i].BasePP      = rawReader.ReadInt16();
                            short tempPP = rawReader.ReadInt16();
                            if (tempPP != 0)
                            {
                                parsedWeapons[j][i].RegenPP = (short)((5 * parsedWeapons[j][i].BasePP) / tempPP);
                            }
                            else
                            {
                                parsedWeapons[j][i].RegenPP = 0;
                            }
                            parsedWeapons[j][i].AtpMod = rawReader.ReadInt16();
                            parsedWeapons[j][i].DfpMod = rawReader.ReadInt16();
                            parsedWeapons[j][i].AtaMod = rawReader.ReadInt16();
                            parsedWeapons[j][i].EvpMod = rawReader.ReadInt16();
                            parsedWeapons[j][i].StaMod = rawReader.ReadInt16();
                            parsedWeapons[j][i].TpMod  = rawReader.ReadInt16();
                            parsedWeapons[j][i].MstMod = rawReader.ReadInt16();
                            if (isPsp1)
                            {
                                parsedWeapons[j][i].MaxTargets = (byte)(parsedWeapons[j][i].StatusLevel & 0xF);
                                if ((parsedWeapons[j][i].AvailableRaces & 0x40) != 0)
                                {
                                    parsedWeapons[j][i].DropElement |= 0x8;
                                }
                                parsedWeapons[j][i].AvailableRaces &= 0x3F;
                                parsedWeapons[j][i].StatusLevel   >>= 4;
                            }
                        }
                    }
                }
                else
                {
                    for (int i = 0; i < parsedWeapons[j].Length; i++)
                    {
                        parsedWeapons[j][i] = new Weapon();
                    }
                }
            }
        }