Example #1
0
        public static long GetMainExportID(uint classID, uint value)
        {
#if DEBUG
            int digits = BitConverterExtensions.GetDigitsCount(value);
            if (digits > 5)
            {
                throw new System.ArgumentException($"Value {value} for main export ID must have no more than 5 digits");
            }
#endif
            return((classID * 100000) | value);
        }
Example #2
0
        public static long GetMainExportID(uint classID, uint value)
        {
            if (classID > 100100)
            {
                if (value != 0)
                {
                    throw new ArgumentException("Unique asset type with non unique modifier", nameof(value));
                }
                return(classID);
            }

#if DEBUG
            int digits = BitConverterExtensions.GetDigitsCount(value);
            if (digits > 5)
            {
                throw new ArgumentException($"Value {value} for main export ID must have no more than 5 digits");
            }
#endif
            return((classID * 100000) + value);
        }
Example #3
0
        public static long GenerateExportID(Object asset, Func <long, bool> uniqueChecker)
        {
            if (asset == null)
            {
                throw new ArgumentNullException(nameof(asset));
            }

#warning TODO: values acording to read version (current 2017.3.0f3)
            ThreadSafeRandom random = new ThreadSafeRandom();
            long             exportID;
            do
            {
                uint classID = (uint)asset.ClassID;
#if DEBUG
                int length = BitConverterExtensions.GetDigitsCount(classID);
                if (length > 4)
                {
                    throw new NotSupportedException($"Class ID {classID} with more that 4 digits isn't supported");
                }
#endif
                exportID  = classID;
                exportID *= 1000000000000000L;
                exportID |= unchecked (random.Next(0, 2)) * 100000000000000L;
                exportID |= unchecked (random.Next(0, 2)) * 10000000000000L;
                exportID |= unchecked (random.Next(0, 2)) * 1000000000000L;
                exportID |= unchecked (random.Next(0, 2)) * 100000000000L;
                exportID |= unchecked (random.Next(0, 2)) * 10000000000L;
                exportID |= unchecked (random.Next(0, 2)) * 1000000000L;
                exportID |= unchecked (random.Next(0, 2)) * 100000000L;
                exportID |= unchecked (random.Next(0, 2)) * 10000000L;
                exportID |= unchecked (random.Next(0, 2)) * 1000000L;
                exportID |= unchecked (random.Next(0, 2)) * 100000L;
                exportID |= unchecked (random.Next(0, 2)) * 10000L;
                exportID |= unchecked (random.Next(0, 2)) * 1000L;
                exportID |= unchecked (random.Next(0, 2)) * 100L;
                exportID |= unchecked (random.Next(0, 2)) * 10L;
                exportID |= unchecked (random.Next(0, 2)) * 1L;
            }while (uniqueChecker(exportID));
            return(exportID);
        }