예제 #1
0
        public void ScriptSpace()
        {
            string path = TestData.GetTestDataPath(Game.GTA3, SaveFileGTA3.FileFormats.PC, "CAT2");

            using SaveFileGTA3 x = SaveFile.Load <SaveFileGTA3>(path, SaveFileGTA3.FileFormats.PC);

            byte  b      = 0xA5;
            short s      = unchecked ((short)0xCCEE);
            int   i      = unchecked ((int)0xCAFEBABE);
            float f      = 133.7f;
            int   offset = 420;

            offset += x.Scripts.Write1ByteToScript(offset, b);
            offset += x.Scripts.Write2BytesToScript(offset, s);
            offset += x.Scripts.Write4BytesToScript(offset, i);
            offset += x.Scripts.WriteFloatToScript(offset, f);
            Assert.Equal(431, offset);

            offset  = 420;
            offset += x.Scripts.Read1ByteFromScript(offset, out byte b2);
            offset += x.Scripts.Read2BytesFromScript(offset, out short s2);
            offset += x.Scripts.Read4BytesFromScript(offset, out int i2);
            offset += x.Scripts.ReadFloatFromScript(offset, out float f2);
            Assert.Equal(431, offset);
            Assert.Equal(b, b2);
            Assert.Equal(s, s2);
            Assert.Equal(i, i2);
            Assert.Equal(f, f2);
        }
예제 #2
0
        public void GlobalVariables()
        {
            Faker  f    = new Faker();
            string path = TestData.GetTestDataPath(Game.GTA3, SaveFileGTA3.FileFormats.PC, "CAT2");

            using SaveFileGTA3 x = SaveFile.Load <SaveFileGTA3>(path, SaveFileGTA3.FileFormats.PC);

            Assert.Equal(987.5, x.Scripts.GetGlobalAsFloat(804));

            int   numGlobals = x.Scripts.Globals.Count();
            int   i0         = f.Random.Int(0, numGlobals - 1);
            int   i1         = f.Random.Int(0, numGlobals - 1);
            int   v0         = f.Random.Int();
            float v1         = f.Random.Float();

            x.Scripts.SetGlobal(i0, v0);
            x.Scripts.SetGlobal(i1, v1);

            int   r0 = x.Scripts.GetGlobal(i0);
            float r1 = x.Scripts.GetGlobalAsFloat(i1);

            Assert.Equal(v0, r0);
            Assert.Equal(v1, r1);
        }