public static void Array16Copy(out Array16 <uint> output, Array16 <uint> input)
 {
     output.x0  = input.x0;
     output.x1  = input.x1;
     output.x2  = input.x2;
     output.x3  = input.x3;
     output.x4  = input.x4;
     output.x5  = input.x5;
     output.x6  = input.x6;
     output.x7  = input.x7;
     output.x8  = input.x8;
     output.x9  = input.x9;
     output.x10 = input.x10;
     output.x11 = input.x11;
     output.x12 = input.x12;
     output.x13 = input.x13;
     output.x14 = input.x14;
     output.x15 = input.x15;
 }
Example #2
0
        private void FollowNextVehicle()
        {
            Array16 <Vehicle> vehicles = VehicleManager.instance.m_vehicles;
            VehicleOptions    options  = m_optionPanel.m_options;

            for (uint i = (m_seekStart + 1) % vehicles.m_size; i != m_seekStart; i = (i + 1) % vehicles.m_size)
            {
                if (vehicles.m_buffer[i].Info == m_optionPanel.m_options.prefab)
                {
                    bool isSpawned = (vehicles.m_buffer[i].m_flags & Vehicle.Flags.Spawned) == Vehicle.Flags.Spawned;

                    InstanceID instanceID = default(InstanceID);
                    instanceID.Vehicle = (ushort)i;

                    if (!isSpawned || instanceID.IsEmpty || !InstanceManager.IsValid(instanceID))
                    {
                        continue;
                    }

                    Vector3    targetPosition;
                    Quaternion quaternion;
                    Vector3    vector;

                    if (!InstanceManager.GetPosition(instanceID, out targetPosition, out quaternion, out vector))
                    {
                        continue;
                    }

                    Vector3 pos = targetPosition;
                    GameAreaManager.instance.ClampPoint(ref targetPosition);
                    if (targetPosition != pos)
                    {
                        continue;
                    }

                    m_cameraController.SetTarget(instanceID, ToolsModifierControl.cameraController.transform.position, false);

                    m_seekStart = (i + 1) % vehicles.m_size;
                    return;
                }
            }
            m_seekStart = 0;
        }
 // TODO: Only used in tests. Remove?
 public static void Array16LoadLittleEndian32(out Array16 <uint> output, byte[] input, int inputOffset)
 {
     output.x0  = LoadLittleEndian32(input, inputOffset + 0);
     output.x1  = LoadLittleEndian32(input, inputOffset + 4);
     output.x2  = LoadLittleEndian32(input, inputOffset + 8);
     output.x3  = LoadLittleEndian32(input, inputOffset + 12);
     output.x4  = LoadLittleEndian32(input, inputOffset + 16);
     output.x5  = LoadLittleEndian32(input, inputOffset + 20);
     output.x6  = LoadLittleEndian32(input, inputOffset + 24);
     output.x7  = LoadLittleEndian32(input, inputOffset + 28);
     output.x8  = LoadLittleEndian32(input, inputOffset + 32);
     output.x9  = LoadLittleEndian32(input, inputOffset + 36);
     output.x10 = LoadLittleEndian32(input, inputOffset + 40);
     output.x11 = LoadLittleEndian32(input, inputOffset + 44);
     output.x12 = LoadLittleEndian32(input, inputOffset + 48);
     output.x13 = LoadLittleEndian32(input, inputOffset + 52);
     output.x14 = LoadLittleEndian32(input, inputOffset + 56);
     output.x15 = LoadLittleEndian32(input, inputOffset + 60);
 }
 public static void Array16LoadBigEndian64(out Array16 <ulong> output, byte[] input, int inputOffset)
 {
     output.x0  = LoadBigEndian64(input, inputOffset + 0);
     output.x1  = LoadBigEndian64(input, inputOffset + 8);
     output.x2  = LoadBigEndian64(input, inputOffset + 16);
     output.x3  = LoadBigEndian64(input, inputOffset + 24);
     output.x4  = LoadBigEndian64(input, inputOffset + 32);
     output.x5  = LoadBigEndian64(input, inputOffset + 40);
     output.x6  = LoadBigEndian64(input, inputOffset + 48);
     output.x7  = LoadBigEndian64(input, inputOffset + 56);
     output.x8  = LoadBigEndian64(input, inputOffset + 64);
     output.x9  = LoadBigEndian64(input, inputOffset + 72);
     output.x10 = LoadBigEndian64(input, inputOffset + 80);
     output.x11 = LoadBigEndian64(input, inputOffset + 88);
     output.x12 = LoadBigEndian64(input, inputOffset + 96);
     output.x13 = LoadBigEndian64(input, inputOffset + 104);
     output.x14 = LoadBigEndian64(input, inputOffset + 112);
     output.x15 = LoadBigEndian64(input, inputOffset + 120);
 }
Example #5
0
 private static bool CreateOutgoingVehicle(bool __result, TransportStationAI __instance, ushort buildingID, ref Building buildingData, ushort startStop, int gateIndex)
 {
     if (__instance.m_transportLineInfo != null && (ushort)FindConnectionVehicle.Invoke(__instance, new object[] { buildingID, buildingData, startStop, 3000f }) == 0)
     {
         SVMUtils.doLog("START CreateOutgoingVehicle: {0} , {1}", typeof(TransportStationAI), __instance.name);
         ServiceSystemDefinition def = ServiceSystemDefinition.from(buildingData.Info).FirstOrDefault();
         if (def == null)
         {
             SVMUtils.doLog("SSD Não definido para: {0} {1} {2}", buildingData.Info.m_class.m_service, buildingData.Info.m_class.m_subService, buildingData.Info.m_class.m_level);
             return(false);
         }
         SVMUtils.doLog("[{1}] SSD = {0}", def, "CreateIncomingVehicle");
         VehicleInfo randomVehicleInfo = ServiceSystemDefinition.availableDefinitions[def].GetAModel(buildingID);
         SVMUtils.doLog("[{1}] Veh = {0}", randomVehicleInfo?.ToString() ?? "<NULL>", "CreateIncomingVehicle");
         if (randomVehicleInfo != null)
         {
             Array16 <Vehicle> vehicles   = Singleton <VehicleManager> .instance.m_vehicles;
             Randomizer        randomizer = default(Randomizer);
             randomizer.seed = (ulong)((long)gateIndex);
             __instance.CalculateSpawnPosition(buildingID, ref buildingData, ref randomizer, randomVehicleInfo, out Vector3 vector, out Vector3 vector2);
             TransportInfo transportInfo = __instance.m_transportInfo;
             if (__instance.m_secondaryTransportInfo != null && __instance.m_secondaryTransportInfo.m_class.m_subService == __instance.m_transportLineInfo.m_class.m_subService)
             {
                 transportInfo = __instance.m_secondaryTransportInfo;
             }
             if (randomVehicleInfo.m_vehicleAI.CanSpawnAt(vector) && Singleton <VehicleManager> .instance.CreateVehicle(out ushort num, ref Singleton <SimulationManager> .instance.m_randomizer, randomVehicleInfo, vector, transportInfo.m_vehicleReason, false, true))
             {
                 vehicles.m_buffer[(int)num].m_gateIndex = (byte)gateIndex;
                 Vehicle[] expr_12E_cp_0 = vehicles.m_buffer;
                 ushort    expr_12E_cp_1 = num;
                 expr_12E_cp_0[(int)expr_12E_cp_1].m_flags = (expr_12E_cp_0[(int)expr_12E_cp_1].m_flags | (Vehicle.Flags.Importing | Vehicle.Flags.Exporting));
                 randomVehicleInfo.m_vehicleAI.SetSource(num, ref vehicles.m_buffer[(int)num], buildingID);
                 randomVehicleInfo.m_vehicleAI.SetTarget(num, ref vehicles.m_buffer[(int)num], startStop);
                 SVMUtils.doLog("END CreateOutgoingVehicle: {0} , {1}", typeof(TransportStationAI), __instance.name);
                 __result = true;
                 return(false);
             }
         }
     }
     SVMUtils.doLog("END2 CreateOutgoingVehicle: {0} , {1}", typeof(TransportStationAI), __instance.name);
     __result = false;
     return(false);
 }
Example #6
0
 public static void Array16LoadBigEndian64(out Array16 <ulong> output, byte[] input, int inputOffset)
 {
     output.X0  = LoadBigEndian64(input, inputOffset + 0);
     output.X1  = LoadBigEndian64(input, inputOffset + 8);
     output.X2  = LoadBigEndian64(input, inputOffset + 16);
     output.X3  = LoadBigEndian64(input, inputOffset + 24);
     output.X4  = LoadBigEndian64(input, inputOffset + 32);
     output.X5  = LoadBigEndian64(input, inputOffset + 40);
     output.X6  = LoadBigEndian64(input, inputOffset + 48);
     output.X7  = LoadBigEndian64(input, inputOffset + 56);
     output.X8  = LoadBigEndian64(input, inputOffset + 64);
     output.X9  = LoadBigEndian64(input, inputOffset + 72);
     output.X10 = LoadBigEndian64(input, inputOffset + 80);
     output.X11 = LoadBigEndian64(input, inputOffset + 88);
     output.X12 = LoadBigEndian64(input, inputOffset + 96);
     output.X13 = LoadBigEndian64(input, inputOffset + 104);
     output.X14 = LoadBigEndian64(input, inputOffset + 112);
     output.X15 = LoadBigEndian64(input, inputOffset + 120);
 }
 public static void Array16LoadBigEndian64(out Array16<ulong> output, byte[] input, int inputOffset)
 {
     output.x0 = LoadBigEndian64(input, inputOffset + 0);
     output.x1 = LoadBigEndian64(input, inputOffset + 8);
     output.x2 = LoadBigEndian64(input, inputOffset + 16);
     output.x3 = LoadBigEndian64(input, inputOffset + 24);
     output.x4 = LoadBigEndian64(input, inputOffset + 32);
     output.x5 = LoadBigEndian64(input, inputOffset + 40);
     output.x6 = LoadBigEndian64(input, inputOffset + 48);
     output.x7 = LoadBigEndian64(input, inputOffset + 56);
     output.x8 = LoadBigEndian64(input, inputOffset + 64);
     output.x9 = LoadBigEndian64(input, inputOffset + 72);
     output.x10 = LoadBigEndian64(input, inputOffset + 80);
     output.x11 = LoadBigEndian64(input, inputOffset + 88);
     output.x12 = LoadBigEndian64(input, inputOffset + 96);
     output.x13 = LoadBigEndian64(input, inputOffset + 104);
     output.x14 = LoadBigEndian64(input, inputOffset + 112);
     output.x15 = LoadBigEndian64(input, inputOffset + 120);
 }
Example #8
0
 private void Update()
 {
     if (!this._initialized)
     {
         return;
     }
     if (this.SimulationLineCount > this.KnownLineCount)
     {
         Array16 <TransportLine> lines = Singleton <TransportManager> .instance.m_lines;
         for (ushort lineID = 0; (uint)lineID < lines.m_size; ++lineID)
         {
             if (LineWatcher.IsValid(ref lines.m_buffer[(int)lineID]) && this._knownLines.Add(lineID))
             {
                 CachedTransportLineData.SetLineDefaults(lineID);
                 DepotUtil.AutoAssignLineDepot(lineID, out var position);
                 if (OptionsWrapper <Settings> .Options.ShowLineInfo &&
                     lines.m_buffer[(int)lineID].Info?.m_class?.m_service != ItemClass.Service.Disaster)
                 {
                     WorldInfoPanel.Show <PublicTransportWorldInfoPanel>(position, new InstanceID()
                     {
                         TransportLine = lineID
                     });
                 }
             }
         }
     }
     else
     {
         if (this.SimulationLineCount >= this.KnownLineCount)
         {
             return;
         }
         Array16 <TransportLine> lines = Singleton <TransportManager> .instance.m_lines;
         for (ushort lineID = 0; (uint)lineID < lines.m_size; ++lineID)
         {
             if (!LineWatcher.IsValid(ref lines.m_buffer[(int)lineID]))
             {
                 this._knownLines.Remove(lineID);
             }
         }
     }
 }
        private static void PrepareInternalKey(out Array16 <uint> internalKey, byte[] key, int keyOffset, byte[] nonce,
                                               int nonceOffset)
        {
            internalKey.x0  = Salsa20.SalsaConst0;
            internalKey.x1  = ByteIntegerConverter.LoadLittleEndian32(key, keyOffset + 0);
            internalKey.x2  = ByteIntegerConverter.LoadLittleEndian32(key, keyOffset + 4);
            internalKey.x3  = ByteIntegerConverter.LoadLittleEndian32(key, keyOffset + 8);
            internalKey.x4  = ByteIntegerConverter.LoadLittleEndian32(key, keyOffset + 12);
            internalKey.x5  = Salsa20.SalsaConst1;
            internalKey.x6  = ByteIntegerConverter.LoadLittleEndian32(nonce, nonceOffset + 0);
            internalKey.x7  = ByteIntegerConverter.LoadLittleEndian32(nonce, nonceOffset + 4);
            internalKey.x8  = ByteIntegerConverter.LoadLittleEndian32(nonce, nonceOffset + 8);
            internalKey.x9  = ByteIntegerConverter.LoadLittleEndian32(nonce, nonceOffset + 12);
            internalKey.x10 = Salsa20.SalsaConst2;
            internalKey.x11 = ByteIntegerConverter.LoadLittleEndian32(key, keyOffset + 16);
            internalKey.x12 = ByteIntegerConverter.LoadLittleEndian32(key, keyOffset + 20);
            internalKey.x13 = ByteIntegerConverter.LoadLittleEndian32(key, keyOffset + 24);
            internalKey.x14 = ByteIntegerConverter.LoadLittleEndian32(key, keyOffset + 28);
            internalKey.x15 = Salsa20.SalsaConst3;
            SalsaCore.HSalsa(out internalKey, ref internalKey, 20);

            //key
            internalKey.x1  = internalKey.x0;
            internalKey.x2  = internalKey.x5;
            internalKey.x3  = internalKey.x10;
            internalKey.x4  = internalKey.x15;
            internalKey.x11 = internalKey.x6;
            internalKey.x12 = internalKey.x7;
            internalKey.x13 = internalKey.x8;
            internalKey.x14 = internalKey.x9;
            //const
            internalKey.x0  = Salsa20.SalsaConst0;
            internalKey.x5  = Salsa20.SalsaConst1;
            internalKey.x10 = Salsa20.SalsaConst2;
            internalKey.x15 = Salsa20.SalsaConst3;
            //nonce
            internalKey.x6 = ByteIntegerConverter.LoadLittleEndian32(nonce, nonceOffset + 16);
            internalKey.x7 = ByteIntegerConverter.LoadLittleEndian32(nonce, nonceOffset + 20);
            //offset
            internalKey.x8 = 0;
            internalKey.x9 = 0;
        }
        private void _guiCitizens()
        {
            GUIStyle _counterStyle = new GUIStyle();
            Array16 <CitizenInstance> citizenInstances = Singleton <CitizenManager> .instance.m_instances;

            for (int i = 1; i < citizenInstances.m_size; ++i)
            {
                CitizenInstance citizenInstance = citizenInstances.m_buffer[i];
                if (citizenInstance.m_flags == CitizenInstance.Flags.None)
                {
                    continue;
                }

                Vector3 pos       = citizenInstance.GetLastFramePosition();
                var     screenPos = Camera.main.WorldToScreenPoint(pos);
                screenPos.y = Screen.height - screenPos.y;

                if (screenPos.z < 0)
                {
                    continue;
                }

                var camPos = Singleton <SimulationManager> .instance.m_simulationView.m_position;
                var diff   = pos - camPos;
                if (diff.magnitude > DebugCloseLod)
                {
                    continue;                     // do not draw if too distant
                }
                var zoom = 1.0f / diff.magnitude * 150f;

                _counterStyle.fontSize         = (int)(10f * zoom);
                _counterStyle.normal.textColor = new Color(1f, 0f, 1f);
                //_counterStyle.normal.background = MakeTex(1, 1, new Color(0f, 0f, 0f, 0.4f));

                String labelStr = "Cit. " + i;

                Vector2 dim       = _counterStyle.CalcSize(new GUIContent(labelStr));
                Rect    labelRect = new Rect(screenPos.x - dim.x / 2f, screenPos.y - dim.y - 50f, dim.x, dim.y);

                GUI.Box(labelRect, labelStr, _counterStyle);
            }
        }
Example #11
0
        public static bool StartTransfer(DepotAI __instance, ushort buildingID, TransferManager.TransferReason reason, TransferManager.TransferOffer offer)
        {
            if (!m_managedReasons.Contains(reason) || offer.TransportLine == 0)
            {
                return(true);
            }

            TLMUtils.doLog("START TRANSFER!!!!!!!!");
            TransportInfo m_transportInfo = __instance.m_transportInfo;
            BuildingInfo  m_info          = __instance.m_info;

            TLMUtils.doLog("m_info {0} | m_transportInfo {1} | Line: {2}", m_info.name, m_transportInfo.name, offer.TransportLine);


            if (reason == m_transportInfo.m_vehicleReason || (__instance.m_secondaryTransportInfo != null && reason == __instance.m_secondaryTransportInfo.m_vehicleReason))
            {
                var tsd = TransportSystemDefinition.From(__instance.m_transportInfo);

                Instance.SetRandomBuilding(ref tsd, offer.TransportLine, ref buildingID);

                TLMUtils.doLog("randomVehicleInfo");
                VehicleInfo randomVehicleInfo = DoModelDraw(offer.TransportLine);
                if (randomVehicleInfo == null)
                {
                    randomVehicleInfo = Singleton <VehicleManager> .instance.GetRandomVehicleInfo(ref Singleton <SimulationManager> .instance.m_randomizer, m_info.m_class.m_service, m_info.m_class.m_subService, m_info.m_class.m_level);
                }
                if (randomVehicleInfo != null)
                {
                    TLMUtils.doLog("randomVehicleInfo != null");
                    Array16 <Vehicle> vehicles = Singleton <VehicleManager> .instance.m_vehicles;
                    __instance.CalculateSpawnPosition(buildingID, ref Singleton <BuildingManager> .instance.m_buildings.m_buffer[buildingID], ref Singleton <SimulationManager> .instance.m_randomizer, randomVehicleInfo, out Vector3 position, out Vector3 vector);
                    if (Singleton <VehicleManager> .instance.CreateVehicle(out ushort vehicleID, ref Singleton <SimulationManager> .instance.m_randomizer, randomVehicleInfo, position, reason, false, true))
                    {
                        TLMUtils.doLog("CreatedVehicle!!!");
                        randomVehicleInfo.m_vehicleAI.SetSource(vehicleID, ref vehicles.m_buffer[vehicleID], buildingID);
                        randomVehicleInfo.m_vehicleAI.StartTransfer(vehicleID, ref vehicles.m_buffer[vehicleID], reason, offer);
                    }
                    return(false);
                }
            }
            return(true);
        }
        private static void LocateNextBuildingInstance(PrefabInfo prefab)
        {
            Array16 <Building> buildings = BuildingManager.instance.m_buildings;

            for (uint i = (buildingInstanceCounter + 1) % buildings.m_size; i != buildingInstanceCounter; i = (i + 1) % buildings.m_size)
            {
                if (buildings.m_buffer[i].Info == prefab)
                {
                    bool isValid = (buildings.m_buffer[i].m_flags != Building.Flags.None && buildings.m_buffer[i].m_flags != Building.Flags.Deleted);
                    if (!isValid)
                    {
                        continue;
                    }
                    SetCameraPosition(buildings.m_buffer[i].m_position);
                    buildingInstanceCounter = (i + 1) % buildings.m_size;
                    return;
                }
            }
            buildingInstanceCounter = 0;
        }
        private static void LocateNextNetworkSegmentInstance(PrefabInfo prefab)
        {
            Array16 <NetSegment> segments = NetManager.instance.m_segments;

            for (uint i = (networkSegmentInstanceCounter + 1) % segments.m_size; i != networkSegmentInstanceCounter; i = (i + 1) % segments.m_size)
            {
                if (segments.m_buffer[i].Info == prefab)
                {
                    bool isValid = (segments.m_buffer[i].m_flags != NetSegment.Flags.None && segments.m_buffer[i].m_flags != NetSegment.Flags.Deleted);
                    if (!isValid)
                    {
                        continue;
                    }
                    SetCameraPosition(segments.m_buffer[i].m_middlePosition);
                    networkSegmentInstanceCounter = (i + 1) % segments.m_size;
                    return;
                }
            }
            networkSegmentInstanceCounter = 0;
        }
        private static void LocateNextPropDecalInstance(PrefabInfo prefab)
        {
            Array16 <PropInstance> props = PropManager.instance.m_props;

            for (uint i = (propInstanceCounter + 1) % props.m_size; i != propInstanceCounter; i = (i + 1) % props.m_size)
            {
                if (props.m_buffer[i].Info == prefab)
                {
                    bool isValid = ((PropInstance.Flags)props.m_buffer[i].m_flags != PropInstance.Flags.None && (PropInstance.Flags)props.m_buffer[i].m_flags != PropInstance.Flags.Deleted);
                    if (!isValid)
                    {
                        continue;
                    }
                    SetCameraPosition(props.m_buffer[i].Position);
                    propInstanceCounter = (i + 1) % props.m_size;
                    return;
                }
            }
            propInstanceCounter = 0;
        }
Example #15
0
        private static void PrepareInternalKey(out Array16<UInt32> internalKey, byte[] key, int keyOffset, byte[] nonce, int nonceOffset)
        {
            internalKey.x0 = Salsa20.SalsaConst0;
            internalKey.x1 = ByteIntegerConverter.LoadLittleEndian32(key, keyOffset + 0);
            internalKey.x2 = ByteIntegerConverter.LoadLittleEndian32(key, keyOffset + 4);
            internalKey.x3 = ByteIntegerConverter.LoadLittleEndian32(key, keyOffset + 8);
            internalKey.x4 = ByteIntegerConverter.LoadLittleEndian32(key, keyOffset + 12);
            internalKey.x5 = Salsa20.SalsaConst1;
            internalKey.x6 = ByteIntegerConverter.LoadLittleEndian32(nonce, nonceOffset + 0);
            internalKey.x7 = ByteIntegerConverter.LoadLittleEndian32(nonce, nonceOffset + 4);
            internalKey.x8 = ByteIntegerConverter.LoadLittleEndian32(nonce, nonceOffset + 8);
            internalKey.x9 = ByteIntegerConverter.LoadLittleEndian32(nonce, nonceOffset + 12);
            internalKey.x10 = Salsa20.SalsaConst2;
            internalKey.x11 = ByteIntegerConverter.LoadLittleEndian32(key, keyOffset + 16);
            internalKey.x12 = ByteIntegerConverter.LoadLittleEndian32(key, keyOffset + 20);
            internalKey.x13 = ByteIntegerConverter.LoadLittleEndian32(key, keyOffset + 24);
            internalKey.x14 = ByteIntegerConverter.LoadLittleEndian32(key, keyOffset + 28);
            internalKey.x15 = Salsa20.SalsaConst3;
            SalsaCore.HSalsa(out internalKey, ref internalKey, 20);

            //key
            internalKey.x1 = internalKey.x0;
            internalKey.x2 = internalKey.x5;
            internalKey.x3 = internalKey.x10;
            internalKey.x4 = internalKey.x15;
            internalKey.x11 = internalKey.x6;
            internalKey.x12 = internalKey.x7;
            internalKey.x13 = internalKey.x8;
            internalKey.x14 = internalKey.x9;
            //const
            internalKey.x0 = Salsa20.SalsaConst0;
            internalKey.x5 = Salsa20.SalsaConst1;
            internalKey.x10 = Salsa20.SalsaConst2;
            internalKey.x15 = Salsa20.SalsaConst3;
            //nonce
            internalKey.x6 = ByteIntegerConverter.LoadLittleEndian32(nonce, nonceOffset + 16);
            internalKey.x7 = ByteIntegerConverter.LoadLittleEndian32(nonce, nonceOffset + 20);
            //offset
            internalKey.x8 = 0;
            internalKey.x9 = 0;
        }
Example #16
0
        public static IEnumerator ActionRemoveExisting(ThreadBase t)
        {
            VehicleInfo       info     = m_removeInfo;
            Array16 <Vehicle> vehicles = VehicleManager.instance.m_vehicles;

            for (ushort i = 0; i < vehicles.m_buffer.Length; i++)
            {
                if (vehicles.m_buffer[i].Info != null)
                {
                    if (info == vehicles.m_buffer[i].Info)
                    {
                        VehicleManager.instance.ReleaseVehicle(i);
                    }
                }

                if (i % 256 == 255)
                {
                    yield return(i);
                }
            }
        }
Example #17
0
        public static IEnumerator ActionRemoveParked(ThreadBase t)
        {
            VehicleInfo             info           = m_removeParkedInfo;
            Array16 <VehicleParked> parkedVehicles = VehicleManager.instance.m_parkedVehicles;

            for (ushort i = 0; i < parkedVehicles.m_buffer.Length; i++)
            {
                if (parkedVehicles.m_buffer[i].Info != null)
                {
                    if (info == parkedVehicles.m_buffer[i].Info)
                    {
                        VehicleManager.instance.ReleaseParkedVehicle(i);
                    }
                }

                if (i % 256 == 255)
                {
                    yield return(i);
                }
            }
        }
        public static void StartTransfer(TransferManager.TransferReason material, TransferManager.TransferOffer offerOut, TransferManager.TransferOffer offerIn, int delta)
        {
            bool offerInActive  = offerIn.Active;
            bool offerOutActive = offerOut.Active;

            if (offerInActive && offerIn.Vehicle != 0)
            {
                DebugLog.LogToFileOnly("Error: offerInActive && offerIn.Vehicle");
            }
            else if (offerOutActive && offerOut.Vehicle != 0)
            {
                DebugLog.LogToFileOnly("Error: offerOutActive && offerOut.Vehicle");
            }
            else if (offerInActive && offerIn.Citizen != 0u)
            {
                DebugLog.LogToFileOnly("Error: offerInActive && offerIn.Citizen");
            }
            else if (offerOutActive && offerOut.Citizen != 0u)
            {
                DebugLog.LogToFileOnly("Error: offerOutActive && offerOut.Citizen");
            }
            else if (offerOutActive && offerOut.Building != 0)
            {
                Array16 <Building> buildings = Singleton <BuildingManager> .instance.m_buildings;
                ushort             building  = offerOut.Building;
                offerIn.Amount = delta;
                if (ResourceBuildingAI.IsSpecialBuilding(building))
                {
                    StartSpecialBuildingTransfer(building, ref buildings.m_buffer[building], material, offerIn);
                }
                else
                {
                    DebugLog.LogToFileOnly("Error: offerOutActive && offerOut.Building");
                }
            }
            else if (offerInActive && offerIn.Building != 0)
            {
                DebugLog.LogToFileOnly("Error: offerInActive && offerIn.Building");
            }
        }
        private void ShowSigns(bool viewOnly)
        {
            Array16 <NetSegment> segments = Singleton <NetManager> .instance.m_segments;
            bool handleHovered            = false;

            for (int i = 1; i < segments.m_size; ++i)
            {
                if (segments.m_buffer[i].m_flags == NetSegment.Flags.None)                 // segment is unused
                {
                    continue;
                }
#if !DEBUG
                if ((segments.m_buffer[i].m_flags & NetSegment.Flags.Untouchable) != NetSegment.Flags.None)
                {
                    continue;
                }
#endif
                var segmentInfo = segments.m_buffer[i].Info;

                Vector3 centerPos = segments.m_buffer[i].m_bounds.center;
                var     screenPos = Camera.main.WorldToScreenPoint(centerPos);
                screenPos.y = Screen.height - screenPos.y;

                if (screenPos.z < 0)
                {
                    continue;
                }

                // draw speed limits
                if (TrafficManagerTool.GetToolMode() != ToolMode.VehicleRestrictions || i != SelectedSegmentId)                   // no speed limit overlay on selected segment when in vehicle restrictions mode
                {
                    if (drawSpeedLimitHandles((ushort)i, viewOnly))
                    {
                        handleHovered = true;
                    }
                }
            }
            overlayHandleHovered = handleHovered;
        }
        /// <summary>
        /// Displays node ids over nodes
        /// </summary>
        private void _guiNodes()
        {
            GUIStyle          _counterStyle = new GUIStyle();
            Array16 <NetNode> nodes         = Singleton <NetManager> .instance.m_nodes;

            for (int i = 1; i < nodes.m_size; ++i)
            {
                if ((nodes.m_buffer[i].m_flags & NetNode.Flags.Created) == NetNode.Flags.None)                 // node is unused
                {
                    continue;
                }

                Vector3 pos       = nodes.m_buffer[i].m_position;
                var     screenPos = Camera.main.WorldToScreenPoint(pos);
                screenPos.y = Screen.height - screenPos.y;

                if (screenPos.z < 0)
                {
                    continue;
                }

                var camPos = Singleton <SimulationManager> .instance.m_simulationView.m_position;
                var diff   = pos - camPos;
                if (diff.magnitude > DebugCloseLod)
                {
                    continue;                     // do not draw if too distant
                }
                var zoom = 1.0f / diff.magnitude * 150f;

                _counterStyle.fontSize         = (int)(15f * zoom);
                _counterStyle.normal.textColor = new Color(0f, 0f, 1f);

                String  labelStr  = "Node " + i;
                Vector2 dim       = _counterStyle.CalcSize(new GUIContent(labelStr));
                Rect    labelRect = new Rect(screenPos.x - dim.x / 2f, screenPos.y, dim.x, dim.y);

                GUI.Label(labelRect, labelStr, _counterStyle);
            }
        }
        public static void StartSpecialBuildingTransfer(ushort buildingID, ref Building data, TransferManager.TransferReason material, TransferManager.TransferOffer offer)
        {
            VehicleInfo vehicleInfo = null;

            if (material == (TransferManager.TransferReason) 124)
            {
                vehicleInfo = Singleton <VehicleManager> .instance.GetRandomVehicleInfo(ref Singleton <SimulationManager> .instance.m_randomizer, ItemClass.Service.Industrial, ItemClass.SubService.IndustrialForestry, ItemClass.Level.Level1);
            }
            else if (material == (TransferManager.TransferReason) 125)
            {
                vehicleInfo = Singleton <VehicleManager> .instance.GetRandomVehicleInfo(ref Singleton <SimulationManager> .instance.m_randomizer, ItemClass.Service.Industrial, ItemClass.SubService.IndustrialFarming, ItemClass.Level.Level1);
            }


            if (vehicleInfo != null)
            {
                Array16 <Vehicle> vehicles = Singleton <VehicleManager> .instance.m_vehicles;
                if (Singleton <VehicleManager> .instance.CreateVehicle(out ushort vehicleID, ref Singleton <SimulationManager> .instance.m_randomizer, vehicleInfo, data.m_position, material, false, true))
                {
                    vehicleInfo.m_vehicleAI.SetSource(vehicleID, ref vehicles.m_buffer[vehicleID], buildingID);
                    if (vehicleInfo.m_vehicleAI is CargoTruckAI)
                    {
                        CargoTruckAI AI = vehicleInfo.m_vehicleAI as CargoTruckAI;
                        CustomCargoTruckAI.CargoTruckAISetSourceForRealConstruction(vehicleID, ref vehicles.m_buffer[vehicleID], buildingID);
                        vehicles.m_buffer[(int)vehicleID].m_transferSize = (ushort)AI.m_cargoCapacity;
                    }
                    else
                    {
                        DebugLog.LogToFileOnly("Error: vehicleInfo is not cargoTruckAI " + vehicleInfo.m_vehicleAI.ToString());
                    }
                    vehicleInfo.m_vehicleAI.StartTransfer(vehicleID, ref vehicles.m_buffer[vehicleID], material, offer);
                    ushort building4 = offer.Building;
                    if (building4 != 0)
                    {
                        vehicleInfo.m_vehicleAI.GetSize(vehicleID, ref vehicles.m_buffer[vehicleID], out int _, out int _);
                    }
                }
            }
        }
        public static T[] Array16ToArray <T>(Array16 <T> input)
        {
            var output = new T[16];

            output[0]  = input.x0;
            output[1]  = input.x1;
            output[2]  = input.x2;
            output[3]  = input.x3;
            output[4]  = input.x4;
            output[5]  = input.x5;
            output[6]  = input.x6;
            output[7]  = input.x7;
            output[8]  = input.x8;
            output[9]  = input.x9;
            output[10] = input.x10;
            output[11] = input.x11;
            output[12] = input.x12;
            output[13] = input.x13;
            output[14] = input.x14;
            output[15] = input.x15;
            return(output);
        }
Example #23
0
        private T[] ToArray <T>(Array16 <T> a)
        {
            var result = new T[16];

            result[0]  = a.x0;
            result[1]  = a.x1;
            result[2]  = a.x2;
            result[3]  = a.x3;
            result[4]  = a.x4;
            result[5]  = a.x5;
            result[6]  = a.x6;
            result[7]  = a.x7;
            result[8]  = a.x8;
            result[9]  = a.x9;
            result[10] = a.x10;
            result[11] = a.x11;
            result[12] = a.x12;
            result[13] = a.x13;
            result[14] = a.x14;
            result[15] = a.x15;
            return(result);
        }
Example #24
0
        public BackwardUpdates(ref Vp9BackwardUpdates counts)
        {
            InterModeCounts = new Array7 <Array3 <Array2 <uint> > >();

            for (int i = 0; i < 7; i++)
            {
                InterModeCounts[i][0][0] = counts.InterMode[i][2];
                InterModeCounts[i][0][1] = counts.InterMode[i][0] + counts.InterMode[i][1] + counts.InterMode[i][3];
                InterModeCounts[i][1][0] = counts.InterMode[i][0];
                InterModeCounts[i][1][1] = counts.InterMode[i][1] + counts.InterMode[i][3];
                InterModeCounts[i][2][0] = counts.InterMode[i][1];
                InterModeCounts[i][2][1] = counts.InterMode[i][3];
            }

            YModeCounts            = counts.YMode;
            UvModeCounts           = counts.UvMode;
            PartitionCounts        = counts.Partition;
            SwitchableInterpsCount = counts.SwitchableInterp;
            IntraInterCount        = counts.IntraInter;
            CompInterCount         = counts.CompInter;
            SingleRefCount         = counts.SingleRef;
            CompRefCount           = counts.CompRef;
            Tx32x32     = counts.Tx32x32;
            Tx16x16     = counts.Tx16x16;
            Tx8x8       = counts.Tx8x8;
            MbSkipCount = counts.Skip;
            Joints      = counts.Joints;
            Sign        = counts.Sign;
            Classes     = counts.Classes;
            Class0      = counts.Class0;
            Bits        = counts.Bits;
            Class0Fp    = counts.Class0Fp;
            Fp          = counts.Fp;
            Class0Hp    = counts.Class0Hp;
            Hp          = counts.Hp;
            CoefCounts  = counts.Coef;
            EobCounts   = counts.EobBranch;
        }
        private void ShowSigns(bool viewOnly)
        {
            bool stateUpdated             = false;
            bool handleHovered            = false;
            Array16 <NetSegment> segments = Singleton <NetManager> .instance.m_segments;

            foreach (ushort segmentId in currentRestrictedSegmentIds)
            {
                var segmentInfo = segments.m_buffer[segmentId].Info;

                Vector3 centerPos = segments.m_buffer[segmentId].m_bounds.center;
                var     screenPos = Camera.main.WorldToScreenPoint(centerPos);
                screenPos.y = Screen.height - screenPos.y;

                if (screenPos.z < 0)
                {
                    continue;
                }

                // draw vehicle restrictions
                bool update;
                if (drawVehicleRestrictionHandles((ushort)segmentId, viewOnly || segmentId != SelectedSegmentId, out update))
                {
                    handleHovered = true;
                }

                if (update)
                {
                    stateUpdated = true;
                }
            }
            overlayHandleHovered = handleHovered;

            if (stateUpdated)
            {
                RefreshCurrentRestrictedSegmentIds();
            }
        }
Example #26
0
        public static void ResizeArray16 <T>(Array16 <T> array, ushort newSize)
        {
            array.m_size = newSize;
            Array.Resize(ref array.m_buffer, (int)newSize);

            var unusedCount = (uint)array.GetType().GetField("m_unusedCount").GetValue(array);
            var unusedItems = (ushort[])array.GetType().GetField("m_unusedItems").GetValue(array);

            ushort[] newUnusedItems = new ushort[newSize];
            Buffer.BlockCopy(unusedItems, 0, newUnusedItems, 0, 4 * unusedItems.Length);

            // Now add our own unused items
            for (uint i = (uint)unusedItems.Length; i < newSize + 1; i++)
            {
                newUnusedItems[i - 1] = (ushort)i;
            }

            // Update the unusedCount to be in line with the new array size
            // This is just adding the newly sized additions.
            unusedCount += newSize - unusedCount;

            array.GetType().GetField("m_unusedCount").SetValue(array, unusedCount);
            array.GetType().GetField("m_unusedItems").SetValue(array, newUnusedItems);
        }
Example #27
0
        internal static void Salsa(out Array16 <UInt32> output, ref Array16 <UInt32> input, int rounds)
        {
            HSalsa(out Array16 <uint> temp, ref input, rounds);

            unchecked
            {
                output.x0  = temp.x0 + input.x0;
                output.x1  = temp.x1 + input.x1;
                output.x2  = temp.x2 + input.x2;
                output.x3  = temp.x3 + input.x3;
                output.x4  = temp.x4 + input.x4;
                output.x5  = temp.x5 + input.x5;
                output.x6  = temp.x6 + input.x6;
                output.x7  = temp.x7 + input.x7;
                output.x8  = temp.x8 + input.x8;
                output.x9  = temp.x9 + input.x9;
                output.x10 = temp.x10 + input.x10;
                output.x11 = temp.x11 + input.x11;
                output.x12 = temp.x12 + input.x12;
                output.x13 = temp.x13 + input.x13;
                output.x14 = temp.x14 + input.x14;
                output.x15 = temp.x15 + input.x15;
            }
        }
        private void ShowSigns(bool viewOnly)
        {
            if (viewOnly && !Options.vehicleRestrictionsOverlay)
            {
                return;
            }

            Array16 <NetSegment> segments = Singleton <NetManager> .instance.m_segments;
            bool handleHovered            = false;

            for (int i = 1; i < segments.m_size; ++i)
            {
                if (segments.m_buffer[i].m_flags == NetSegment.Flags.None)                 // segment is unused
                {
                    continue;
                }

                var segmentInfo = segments.m_buffer[i].Info;

                Vector3 centerPos = segments.m_buffer[i].m_bounds.center;
                var     screenPos = Camera.main.WorldToScreenPoint(centerPos);
                screenPos.y = Screen.height - screenPos.y;

                if (screenPos.z < 0)
                {
                    continue;
                }

                // draw vehicle restrictions
                if (drawVehicleRestrictionHandles((ushort)i, viewOnly || i != SelectedSegmentId))
                {
                    handleHovered = true;
                }
            }
            overlayHandleHovered = handleHovered;
        }
        /// <summary>
        /// Displays vehicle ids over vehicles
        /// </summary>
        private void _guiVehicles()
        {
            GUIStyle              _counterStyle = new GUIStyle();
            Array16 <Vehicle>     vehicles      = Singleton <VehicleManager> .instance.m_vehicles;
            LaneConnectionManager connManager   = Singleton <LaneConnectionManager> .instance;
            SimulationManager     simManager    = Singleton <SimulationManager> .instance;
            NetManager            netManager    = Singleton <NetManager> .instance;

            for (int i = 1; i < vehicles.m_size; ++i)
            {
                Vehicle vehicle = vehicles.m_buffer[i];
                if (vehicle.m_flags == 0)                 // node is unused
                {
                    continue;
                }

                Vector3 vehPos    = vehicle.GetLastFramePosition();
                var     screenPos = Camera.main.WorldToScreenPoint(vehPos);
                screenPos.y = Screen.height - screenPos.y;

                if (screenPos.z < 0)
                {
                    continue;
                }

                var camPos = simManager.m_simulationView.m_position;
                var diff   = vehPos - camPos;
                if (diff.magnitude > DebugCloseLod)
                {
                    continue;                     // do not draw if too distant
                }
                var zoom = 1.0f / diff.magnitude * 150f;

                _counterStyle.fontSize         = (int)(10f * zoom);
                _counterStyle.normal.textColor = new Color(1f, 1f, 1f);
                //_counterStyle.normal.background = MakeTex(1, 1, new Color(0f, 0f, 0f, 0.4f));

                VehicleState      vState  = VehicleStateManager.GetVehicleState((ushort)i);
                PathUnit.Position?curPos  = vState?.GetCurrentPathPosition(ref vehicle);
                PathUnit.Position?nextPos = vState?.GetNextPathPosition(ref vehicle);
                bool?  startNode          = vState?.CurrentSegmentEnd?.StartNode;
                ushort?segmentId          = vState?.CurrentSegmentEnd?.SegmentId;
                ushort?transitNodeId      = vState?.CurrentSegmentEnd?.NodeId;

                /*float distanceToTransitNode = Single.NaN;
                 * float timeToTransitNode = Single.NaN;*/
                float vehSpeed = vehicle.GetLastFrameVelocity().magnitude;

                Vector3?targetPos = null;
                if (transitNodeId != null)
                {
                    targetPos = netManager.m_nodes.m_buffer[(ushort)transitNodeId].m_position;
                }

                /*if (transitNodeId != null && segmentId != null && startNode != null && curPos != null) {
                 *      bool outgoing = false;
                 *      connManager.GetLaneEndPoint((ushort)segmentId, (bool)startNode, ((PathUnit.Position)curPos).m_lane, null, null, out outgoing, out targetPos);
                 * }*/

                /*if (targetPos != null) {
                 *      distanceToTransitNode = ((Vector3)targetPos - vehPos).magnitude;
                 *      if (vehSpeed > 0)
                 *              timeToTransitNode = distanceToTransitNode / vehSpeed;
                 *      else
                 *              timeToTransitNode = Single.PositiveInfinity;
                 * }*/
                String labelStr = "V #" + i + " @ " + vState?.CurrentSegmentEnd?.SegmentId;
                //String labelStr = "Veh. " + i + " @ " + String.Format("{0:0.##}", vehSpeed) + "/" + (vState != null ? vState.CurrentMaxSpeed.ToString() : "-") + " (" + (vState != null ? vState.VehicleType.ToString() : "-") + ", valid? " + (vState != null ? vState.Valid.ToString() : "-") + ")" + ", len: " + (vState != null ? vState.TotalLength.ToString() : "-") + ", state: " + (vState != null ? vState.JunctionTransitState.ToString() : "-");
#if PATHRECALC
                labelStr += ", recalc: " + (vState != null ? vState.LastPathRecalculation.ToString() : "-");
#endif
                //labelStr += "\npos: " + curPos?.m_segment + "(" + curPos?.m_lane + ")->" + nextPos?.m_segment + "(" + nextPos?.m_lane + ")" /* + ", dist: " + distanceToTransitNode + ", time: " + timeToTransitNode*/ + ", last update: " + vState?.LastPositionUpdate;
#if USEPATHWAITCOUNTER
                labelStr += ", wait: " + vState?.PathWaitCounter;
#endif

                Vector2 dim       = _counterStyle.CalcSize(new GUIContent(labelStr));
                Rect    labelRect = new Rect(screenPos.x - dim.x / 2f, screenPos.y - dim.y - 50f, dim.x, dim.y);

                GUI.Box(labelRect, labelStr, _counterStyle);

                //_counterStyle.normal.background = null;
            }
        }
        internal static void Core(out Array8<UInt64> outputState, ref Array8<UInt64> inputState, ref Array16<UInt64> input)
        {
            UInt64 a = inputState.x0;
            UInt64 b = inputState.x1;
            UInt64 c = inputState.x2;
            UInt64 d = inputState.x3;
            UInt64 e = inputState.x4;
            UInt64 f = inputState.x5;
            UInt64 g = inputState.x6;
            UInt64 h = inputState.x7;

            UInt64 w0 = input.x0;
            UInt64 w1 = input.x1;
            UInt64 w2 = input.x2;
            UInt64 w3 = input.x3;
            UInt64 w4 = input.x4;
            UInt64 w5 = input.x5;
            UInt64 w6 = input.x6;
            UInt64 w7 = input.x7;
            UInt64 w8 = input.x8;
            UInt64 w9 = input.x9;
            UInt64 w10 = input.x10;
            UInt64 w11 = input.x11;
            UInt64 w12 = input.x12;
            UInt64 w13 = input.x13;
            UInt64 w14 = input.x14;
            UInt64 w15 = input.x15;

            int t = 0;
            while (true)
            {
                ulong t1, t2;

                {//0
                    t1 = h +
                         ((e >> 14) ^ (e << (64 - 14)) ^ (e >> 18) ^ (e << (64 - 18)) ^ (e >> 41) ^ (e << (64 - 41))) +
                        //Sigma1(e)
                         ((e & f) ^ (~e & g)) + //Ch(e,f,g)
                         K[t] + w0;
                    t2 = ((a >> 28) ^ (a << (64 - 28)) ^ (a >> 34) ^ (a << (64 - 34)) ^ (a >> 39) ^ (a << (64 - 39))) +
                        //Sigma0(a)
                         ((a & b) ^ (a & c) ^ (b & c)); //Maj(a,b,c)
                    h = g;
                    g = f;
                    f = e;
                    e = d + t1;
                    d = c;
                    c = b;
                    b = a;
                    a = t1 + t2;
                    t++;
                }
                {//1
                    t1 = h +
                         ((e >> 14) ^ (e << (64 - 14)) ^ (e >> 18) ^ (e << (64 - 18)) ^ (e >> 41) ^ (e << (64 - 41))) +
                        //Sigma1(e)
                         ((e & f) ^ (~e & g)) + //Ch(e,f,g)
                         K[t] + w1;
                    t2 = ((a >> 28) ^ (a << (64 - 28)) ^ (a >> 34) ^ (a << (64 - 34)) ^ (a >> 39) ^ (a << (64 - 39))) +
                        //Sigma0(a)
                         ((a & b) ^ (a & c) ^ (b & c)); //Maj(a,b,c)
                    h = g;
                    g = f;
                    f = e;
                    e = d + t1;
                    d = c;
                    c = b;
                    b = a;
                    a = t1 + t2;
                    t++;
                }
                {//2
                    t1 = h +
                         ((e >> 14) ^ (e << (64 - 14)) ^ (e >> 18) ^ (e << (64 - 18)) ^ (e >> 41) ^ (e << (64 - 41))) +
                        //Sigma1(e)
                         ((e & f) ^ (~e & g)) + //Ch(e,f,g)
                         K[t] + w2;
                    t2 = ((a >> 28) ^ (a << (64 - 28)) ^ (a >> 34) ^ (a << (64 - 34)) ^ (a >> 39) ^ (a << (64 - 39))) +
                        //Sigma0(a)
                         ((a & b) ^ (a & c) ^ (b & c)); //Maj(a,b,c)
                    h = g;
                    g = f;
                    f = e;
                    e = d + t1;
                    d = c;
                    c = b;
                    b = a;
                    a = t1 + t2;
                    t++;
                }
                {//3
                    t1 = h +
                         ((e >> 14) ^ (e << (64 - 14)) ^ (e >> 18) ^ (e << (64 - 18)) ^ (e >> 41) ^ (e << (64 - 41))) +
                        //Sigma1(e)
                         ((e & f) ^ (~e & g)) + //Ch(e,f,g)
                         K[t] + w3;
                    t2 = ((a >> 28) ^ (a << (64 - 28)) ^ (a >> 34) ^ (a << (64 - 34)) ^ (a >> 39) ^ (a << (64 - 39))) +
                        //Sigma0(a)
                         ((a & b) ^ (a & c) ^ (b & c)); //Maj(a,b,c)
                    h = g;
                    g = f;
                    f = e;
                    e = d + t1;
                    d = c;
                    c = b;
                    b = a;
                    a = t1 + t2;
                    t++;
                }
                {//4
                    t1 = h +
                         ((e >> 14) ^ (e << (64 - 14)) ^ (e >> 18) ^ (e << (64 - 18)) ^ (e >> 41) ^ (e << (64 - 41))) +
                        //Sigma1(e)
                         ((e & f) ^ (~e & g)) + //Ch(e,f,g)
                         K[t] + w4;
                    t2 = ((a >> 28) ^ (a << (64 - 28)) ^ (a >> 34) ^ (a << (64 - 34)) ^ (a >> 39) ^ (a << (64 - 39))) +
                        //Sigma0(a)
                         ((a & b) ^ (a & c) ^ (b & c)); //Maj(a,b,c)
                    h = g;
                    g = f;
                    f = e;
                    e = d + t1;
                    d = c;
                    c = b;
                    b = a;
                    a = t1 + t2;
                    t++;
                }
                {//5
                    t1 = h +
                         ((e >> 14) ^ (e << (64 - 14)) ^ (e >> 18) ^ (e << (64 - 18)) ^ (e >> 41) ^ (e << (64 - 41))) +
                        //Sigma1(e)
                         ((e & f) ^ (~e & g)) + //Ch(e,f,g)
                         K[t] + w5;
                    t2 = ((a >> 28) ^ (a << (64 - 28)) ^ (a >> 34) ^ (a << (64 - 34)) ^ (a >> 39) ^ (a << (64 - 39))) +
                        //Sigma0(a)
                         ((a & b) ^ (a & c) ^ (b & c)); //Maj(a,b,c)
                    h = g;
                    g = f;
                    f = e;
                    e = d + t1;
                    d = c;
                    c = b;
                    b = a;
                    a = t1 + t2;
                    t++;
                }
                {//6
                    t1 = h +
                         ((e >> 14) ^ (e << (64 - 14)) ^ (e >> 18) ^ (e << (64 - 18)) ^ (e >> 41) ^ (e << (64 - 41))) +
                        //Sigma1(e)
                         ((e & f) ^ (~e & g)) + //Ch(e,f,g)
                         K[t] + w6;
                    t2 = ((a >> 28) ^ (a << (64 - 28)) ^ (a >> 34) ^ (a << (64 - 34)) ^ (a >> 39) ^ (a << (64 - 39))) +
                        //Sigma0(a)
                         ((a & b) ^ (a & c) ^ (b & c)); //Maj(a,b,c)
                    h = g;
                    g = f;
                    f = e;
                    e = d + t1;
                    d = c;
                    c = b;
                    b = a;
                    a = t1 + t2;
                    t++;
                }
                {//7
                    t1 = h +
                         ((e >> 14) ^ (e << (64 - 14)) ^ (e >> 18) ^ (e << (64 - 18)) ^ (e >> 41) ^ (e << (64 - 41))) +
                        //Sigma1(e)
                         ((e & f) ^ (~e & g)) + //Ch(e,f,g)
                         K[t] + w7;
                    t2 = ((a >> 28) ^ (a << (64 - 28)) ^ (a >> 34) ^ (a << (64 - 34)) ^ (a >> 39) ^ (a << (64 - 39))) +
                        //Sigma0(a)
                         ((a & b) ^ (a & c) ^ (b & c)); //Maj(a,b,c)
                    h = g;
                    g = f;
                    f = e;
                    e = d + t1;
                    d = c;
                    c = b;
                    b = a;
                    a = t1 + t2;
                    t++;
                }
                {//8
                    t1 = h +
                         ((e >> 14) ^ (e << (64 - 14)) ^ (e >> 18) ^ (e << (64 - 18)) ^ (e >> 41) ^ (e << (64 - 41))) +
                        //Sigma1(e)
                         ((e & f) ^ (~e & g)) + //Ch(e,f,g)
                         K[t] + w8;
                    t2 = ((a >> 28) ^ (a << (64 - 28)) ^ (a >> 34) ^ (a << (64 - 34)) ^ (a >> 39) ^ (a << (64 - 39))) +
                        //Sigma0(a)
                         ((a & b) ^ (a & c) ^ (b & c)); //Maj(a,b,c)
                    h = g;
                    g = f;
                    f = e;
                    e = d + t1;
                    d = c;
                    c = b;
                    b = a;
                    a = t1 + t2;
                    t++;
                }
                {//9
                    t1 = h +
                         ((e >> 14) ^ (e << (64 - 14)) ^ (e >> 18) ^ (e << (64 - 18)) ^ (e >> 41) ^ (e << (64 - 41))) +
                        //Sigma1(e)
                         ((e & f) ^ (~e & g)) + //Ch(e,f,g)
                         K[t] + w9;
                    t2 = ((a >> 28) ^ (a << (64 - 28)) ^ (a >> 34) ^ (a << (64 - 34)) ^ (a >> 39) ^ (a << (64 - 39))) +
                        //Sigma0(a)
                         ((a & b) ^ (a & c) ^ (b & c)); //Maj(a,b,c)
                    h = g;
                    g = f;
                    f = e;
                    e = d + t1;
                    d = c;
                    c = b;
                    b = a;
                    a = t1 + t2;
                    t++;
                }
                {//10
                    t1 = h +
                         ((e >> 14) ^ (e << (64 - 14)) ^ (e >> 18) ^ (e << (64 - 18)) ^ (e >> 41) ^ (e << (64 - 41))) +
                        //Sigma1(e)
                         ((e & f) ^ (~e & g)) + //Ch(e,f,g)
                         K[t] + w10;
                    t2 = ((a >> 28) ^ (a << (64 - 28)) ^ (a >> 34) ^ (a << (64 - 34)) ^ (a >> 39) ^ (a << (64 - 39))) +
                        //Sigma0(a)
                         ((a & b) ^ (a & c) ^ (b & c)); //Maj(a,b,c)
                    h = g;
                    g = f;
                    f = e;
                    e = d + t1;
                    d = c;
                    c = b;
                    b = a;
                    a = t1 + t2;
                    t++;
                }
                {//11
                    t1 = h +
                         ((e >> 14) ^ (e << (64 - 14)) ^ (e >> 18) ^ (e << (64 - 18)) ^ (e >> 41) ^ (e << (64 - 41))) +
                        //Sigma1(e)
                         ((e & f) ^ (~e & g)) + //Ch(e,f,g)
                         K[t] + w11;
                    t2 = ((a >> 28) ^ (a << (64 - 28)) ^ (a >> 34) ^ (a << (64 - 34)) ^ (a >> 39) ^ (a << (64 - 39))) +
                        //Sigma0(a)
                         ((a & b) ^ (a & c) ^ (b & c)); //Maj(a,b,c)
                    h = g;
                    g = f;
                    f = e;
                    e = d + t1;
                    d = c;
                    c = b;
                    b = a;
                    a = t1 + t2;
                    t++;
                }
                {//12
                    t1 = h +
                         ((e >> 14) ^ (e << (64 - 14)) ^ (e >> 18) ^ (e << (64 - 18)) ^ (e >> 41) ^ (e << (64 - 41))) +
                        //Sigma1(e)
                         ((e & f) ^ (~e & g)) + //Ch(e,f,g)
                         K[t] + w12;
                    t2 = ((a >> 28) ^ (a << (64 - 28)) ^ (a >> 34) ^ (a << (64 - 34)) ^ (a >> 39) ^ (a << (64 - 39))) +
                        //Sigma0(a)
                         ((a & b) ^ (a & c) ^ (b & c)); //Maj(a,b,c)
                    h = g;
                    g = f;
                    f = e;
                    e = d + t1;
                    d = c;
                    c = b;
                    b = a;
                    a = t1 + t2;
                    t++;
                }
                {//13
                    t1 = h +
                         ((e >> 14) ^ (e << (64 - 14)) ^ (e >> 18) ^ (e << (64 - 18)) ^ (e >> 41) ^ (e << (64 - 41))) +
                        //Sigma1(e)
                         ((e & f) ^ (~e & g)) + //Ch(e,f,g)
                         K[t] + w13;
                    t2 = ((a >> 28) ^ (a << (64 - 28)) ^ (a >> 34) ^ (a << (64 - 34)) ^ (a >> 39) ^ (a << (64 - 39))) +
                        //Sigma0(a)
                         ((a & b) ^ (a & c) ^ (b & c)); //Maj(a,b,c)
                    h = g;
                    g = f;
                    f = e;
                    e = d + t1;
                    d = c;
                    c = b;
                    b = a;
                    a = t1 + t2;
                    t++;
                }
                {//14
                    t1 = h +
                         ((e >> 14) ^ (e << (64 - 14)) ^ (e >> 18) ^ (e << (64 - 18)) ^ (e >> 41) ^ (e << (64 - 41))) +
                        //Sigma1(e)
                         ((e & f) ^ (~e & g)) + //Ch(e,f,g)
                         K[t] + w14;
                    t2 = ((a >> 28) ^ (a << (64 - 28)) ^ (a >> 34) ^ (a << (64 - 34)) ^ (a >> 39) ^ (a << (64 - 39))) +
                        //Sigma0(a)
                         ((a & b) ^ (a & c) ^ (b & c)); //Maj(a,b,c)
                    h = g;
                    g = f;
                    f = e;
                    e = d + t1;
                    d = c;
                    c = b;
                    b = a;
                    a = t1 + t2;
                    t++;
                }
                {//15
                    t1 = h +
                         ((e >> 14) ^ (e << (64 - 14)) ^ (e >> 18) ^ (e << (64 - 18)) ^ (e >> 41) ^ (e << (64 - 41))) +
                        //Sigma1(e)
                         ((e & f) ^ (~e & g)) + //Ch(e,f,g)
                         K[t] + w15;
                    t2 = ((a >> 28) ^ (a << (64 - 28)) ^ (a >> 34) ^ (a << (64 - 34)) ^ (a >> 39) ^ (a << (64 - 39))) +
                        //Sigma0(a)
                         ((a & b) ^ (a & c) ^ (b & c)); //Maj(a,b,c)
                    h = g;
                    g = f;
                    f = e;
                    e = d + t1;
                    d = c;
                    c = b;
                    b = a;
                    a = t1 + t2;
                    t++;
                }
                if (t == 80)
                    break;

                w0 += ((w14 >> 19) ^ (w14 << (64 - 19)) ^ (w14 >> 61) ^ (w14 << (64 - 61)) ^ (w14 >> 6)) +
                      w9 +
                      ((w1 >> 1) ^ (w1 << (64 - 1)) ^ (w1 >> 8) ^ (w1 << (64 - 8)) ^ (w1 >> 7));
                w1 += ((w15 >> 19) ^ (w15 << (64 - 19)) ^ (w15 >> 61) ^ (w15 << (64 - 61)) ^ (w15 >> 6)) +
                     w10 +
                     ((w2 >> 1) ^ (w2 << (64 - 1)) ^ (w2 >> 8) ^ (w2 << (64 - 8)) ^ (w2 >> 7));
                w2 += ((w0 >> 19) ^ (w0 << (64 - 19)) ^ (w0 >> 61) ^ (w0 << (64 - 61)) ^ (w0 >> 6)) +
                     w11 +
                     ((w3 >> 1) ^ (w3 << (64 - 1)) ^ (w3 >> 8) ^ (w3 << (64 - 8)) ^ (w3 >> 7));
                w3 += ((w1 >> 19) ^ (w1 << (64 - 19)) ^ (w1 >> 61) ^ (w1 << (64 - 61)) ^ (w1 >> 6)) +
                     w12 +
                     ((w4 >> 1) ^ (w4 << (64 - 1)) ^ (w4 >> 8) ^ (w4 << (64 - 8)) ^ (w4 >> 7));
                w4 += ((w2 >> 19) ^ (w2 << (64 - 19)) ^ (w2 >> 61) ^ (w2 << (64 - 61)) ^ (w2 >> 6)) +
                     w13 +
                     ((w5 >> 1) ^ (w5 << (64 - 1)) ^ (w5 >> 8) ^ (w5 << (64 - 8)) ^ (w5 >> 7));
                w5 += ((w3 >> 19) ^ (w3 << (64 - 19)) ^ (w3 >> 61) ^ (w3 << (64 - 61)) ^ (w3 >> 6)) +
                     w14 +
                     ((w6 >> 1) ^ (w6 << (64 - 1)) ^ (w6 >> 8) ^ (w6 << (64 - 8)) ^ (w6 >> 7));
                w6 += ((w4 >> 19) ^ (w4 << (64 - 19)) ^ (w4 >> 61) ^ (w4 << (64 - 61)) ^ (w4 >> 6)) +
                     w15 +
                     ((w7 >> 1) ^ (w7 << (64 - 1)) ^ (w7 >> 8) ^ (w7 << (64 - 8)) ^ (w7 >> 7));
                w7 += ((w5 >> 19) ^ (w5 << (64 - 19)) ^ (w5 >> 61) ^ (w5 << (64 - 61)) ^ (w5 >> 6)) +
                     w0 +
                     ((w8 >> 1) ^ (w8 << (64 - 1)) ^ (w8 >> 8) ^ (w8 << (64 - 8)) ^ (w8 >> 7));
                w8 += ((w6 >> 19) ^ (w6 << (64 - 19)) ^ (w6 >> 61) ^ (w6 << (64 - 61)) ^ (w6 >> 6)) +
                     w1 +
                     ((w9 >> 1) ^ (w9 << (64 - 1)) ^ (w9 >> 8) ^ (w9 << (64 - 8)) ^ (w9 >> 7));
                w9 += ((w7 >> 19) ^ (w7 << (64 - 19)) ^ (w7 >> 61) ^ (w7 << (64 - 61)) ^ (w7 >> 6)) +
                     w2 +
                     ((w10 >> 1) ^ (w10 << (64 - 1)) ^ (w10 >> 8) ^ (w10 << (64 - 8)) ^ (w10 >> 7));
                w10 += ((w8 >> 19) ^ (w8 << (64 - 19)) ^ (w8 >> 61) ^ (w8 << (64 - 61)) ^ (w8 >> 6)) +
                      w3 +
                      ((w11 >> 1) ^ (w11 << (64 - 1)) ^ (w11 >> 8) ^ (w11 << (64 - 8)) ^ (w11 >> 7));
                w11 += ((w9 >> 19) ^ (w9 << (64 - 19)) ^ (w9 >> 61) ^ (w9 << (64 - 61)) ^ (w9 >> 6)) +
                      w4 +
                      ((w12 >> 1) ^ (w12 << (64 - 1)) ^ (w12 >> 8) ^ (w12 << (64 - 8)) ^ (w12 >> 7));
                w12 += ((w10 >> 19) ^ (w10 << (64 - 19)) ^ (w10 >> 61) ^ (w10 << (64 - 61)) ^ (w10 >> 6)) +
                      w5 +
                      ((w13 >> 1) ^ (w13 << (64 - 1)) ^ (w13 >> 8) ^ (w13 << (64 - 8)) ^ (w13 >> 7));
                w13 += ((w11 >> 19) ^ (w11 << (64 - 19)) ^ (w11 >> 61) ^ (w11 << (64 - 61)) ^ (w11 >> 6)) +
                      w6 +
                      ((w14 >> 1) ^ (w14 << (64 - 1)) ^ (w14 >> 8) ^ (w14 << (64 - 8)) ^ (w14 >> 7));
                w14 += ((w12 >> 19) ^ (w12 << (64 - 19)) ^ (w12 >> 61) ^ (w12 << (64 - 61)) ^ (w12 >> 6)) +
                      w7 +
                      ((w15 >> 1) ^ (w15 << (64 - 1)) ^ (w15 >> 8) ^ (w15 << (64 - 8)) ^ (w15 >> 7));
                w15 += ((w13 >> 19) ^ (w13 << (64 - 19)) ^ (w13 >> 61) ^ (w13 << (64 - 61)) ^ (w13 >> 6)) +
                      w8 +
                      ((w0 >> 1) ^ (w0 << (64 - 1)) ^ (w0 >> 8) ^ (w0 << (64 - 8)) ^ (w0 >> 7));
            }

            outputState.x0 = inputState.x0 + a;
            outputState.x1 = inputState.x1 + b;
            outputState.x2 = inputState.x2 + c;
            outputState.x3 = inputState.x3 + d;
            outputState.x4 = inputState.x4 + e;
            outputState.x5 = inputState.x5 + f;
            outputState.x6 = inputState.x6 + g;
            outputState.x7 = inputState.x7 + h;
        }
        /// <summary>
        /// Displays segment ids over segments
        /// </summary>
        private void _guiSegments()
        {
            GUIStyle             _counterStyle = new GUIStyle();
            Array16 <NetSegment> segments      = Singleton <NetManager> .instance.m_segments;

            for (int i = 1; i < segments.m_size; ++i)
            {
                if (segments.m_buffer[i].m_flags == NetSegment.Flags.None)                 // segment is unused
                {
                    continue;
                }
#if !DEBUG
                if ((segments.m_buffer[i].m_flags & NetSegment.Flags.Untouchable) != NetSegment.Flags.None)
                {
                    continue;
                }
#endif
                var segmentInfo = segments.m_buffer[i].Info;

                Vector3 centerPos = segments.m_buffer[i].m_bounds.center;
                var     screenPos = Camera.main.WorldToScreenPoint(centerPos);
                screenPos.y = Screen.height - screenPos.y;

                if (screenPos.z < 0)
                {
                    continue;
                }

                var camPos = Singleton <SimulationManager> .instance.m_simulationView.m_position;
                var diff   = centerPos - camPos;
                if (diff.magnitude > DebugCloseLod)
                {
                    continue;                     // do not draw if too distant
                }
                if (Options.nodesOverlay)
                {
                    var zoom = 1.0f / diff.magnitude * 150f;

                    _counterStyle.fontSize         = (int)(12f * zoom);
                    _counterStyle.normal.textColor = new Color(1f, 0f, 0f);

                    String labelStr = "Segment " + i;
#if DEBUGx
                    labelStr += ", flags: " + segments.m_buffer[i].m_flags.ToString() + ", condition: " + segments.m_buffer[i].m_condition;
#endif
#if DEBUG
                    SegmentEnd startEnd = TrafficPriority.GetPrioritySegment(segments.m_buffer[i].m_startNode, (ushort)i);
                    SegmentEnd endEnd   = TrafficPriority.GetPrioritySegment(segments.m_buffer[i].m_endNode, (ushort)i);
                    labelStr += "\nstart? " + (startEnd != null) + " veh.: " + startEnd?.GetRegisteredVehicleCount() + ", end? " + (endEnd != null) + " veh.: " + endEnd?.GetRegisteredVehicleCount();
#endif
                    labelStr += "\nTraffic: " + segments.m_buffer[i].m_trafficDensity + " %";
#if MARKCONGESTEDSEGMENTS
                    if (CustomRoadAI.initDone && CustomRoadAI.segmentCongestion[i])
                    {
                        labelStr += " congested!";
                    }
#endif

                    float meanLaneSpeed = 0f;

                    int  lIndex     = 0;
                    uint laneId     = segments.m_buffer[i].m_lanes;
                    int  validLanes = 0;
                    while (lIndex < segmentInfo.m_lanes.Length && laneId != 0u)
                    {
                        NetInfo.Lane lane = segmentInfo.m_lanes[lIndex];
                        if (lane.CheckType(NetInfo.LaneType.Vehicle | NetInfo.LaneType.TransportVehicle, VehicleInfo.VehicleType.Car))
                        {
                            if (CustomRoadAI.laneMeanSpeeds[i] != null && lIndex < CustomRoadAI.laneMeanSpeeds[i].Length)
                            {
                                if (CustomRoadAI.laneMeanSpeeds[i][lIndex] >= 0)
                                {
                                    meanLaneSpeed += (float)CustomRoadAI.laneMeanSpeeds[i][lIndex];
                                    ++validLanes;
                                }
                            }
                        }
                        lIndex++;
                        laneId = Singleton <NetManager> .instance.m_lanes.m_buffer[laneId].m_nextLane;
                    }

                    if (validLanes > 0)
                    {
                        meanLaneSpeed /= Convert.ToSingle(validLanes);
                    }

                    /*if (CustomRoadAI.InStartupPhase)
                     *      labelStr += " (in start-up phase)";
                     * else*/
                    labelStr += " (avg. speed: " + String.Format("{0:0.##}", meanLaneSpeed) + " %)";

#if DEBUG
                    labelStr += "\nstart: " + segments.m_buffer[i].m_startNode + ", end: " + segments.m_buffer[i].m_endNode;
#endif

                    Vector2 dim       = _counterStyle.CalcSize(new GUIContent(labelStr));
                    Rect    labelRect = new Rect(screenPos.x - dim.x / 2f, screenPos.y, dim.x, dim.y);

                    GUI.Label(labelRect, labelStr, _counterStyle);

                    if (Options.showLanes)
                    {
                        _guiLanes((ushort)i, ref segments.m_buffer[i], ref segmentInfo);
                    }
                }
            }
        }
 // ToDo: Only used in tests. Remove?
 public static void Array16LoadLittleEndian32(out Array16<UInt32> output, byte[] input, int inputOffset)
 {
     output.x0 = LoadLittleEndian32(input, inputOffset + 0);
     output.x1 = LoadLittleEndian32(input, inputOffset + 4);
     output.x2 = LoadLittleEndian32(input, inputOffset + 8);
     output.x3 = LoadLittleEndian32(input, inputOffset + 12);
     output.x4 = LoadLittleEndian32(input, inputOffset + 16);
     output.x5 = LoadLittleEndian32(input, inputOffset + 20);
     output.x6 = LoadLittleEndian32(input, inputOffset + 24);
     output.x7 = LoadLittleEndian32(input, inputOffset + 28);
     output.x8 = LoadLittleEndian32(input, inputOffset + 32);
     output.x9 = LoadLittleEndian32(input, inputOffset + 36);
     output.x10 = LoadLittleEndian32(input, inputOffset + 40);
     output.x11 = LoadLittleEndian32(input, inputOffset + 44);
     output.x12 = LoadLittleEndian32(input, inputOffset + 48);
     output.x13 = LoadLittleEndian32(input, inputOffset + 52);
     output.x14 = LoadLittleEndian32(input, inputOffset + 56);
     output.x15 = LoadLittleEndian32(input, inputOffset + 60);
 }
Example #33
0
        public static void HSalsa(out Array16\\ output, ref Array16\\ input, int rounds)
        {
            InternalAssert.Assert(rounds % 2 == 0, "Number of salsa rounds must be even");

            int doubleRounds = rounds / 2;

            UInt32 x0 = input.x0;
            UInt32 x1 = input.x1;
            UInt32 x2 = input.x2;
            UInt32 x3 = input.x3;
            UInt32 x4 = input.x4;
            UInt32 x5 = input.x5;
            UInt32 x6 = input.x6;
            UInt32 x7 = input.x7;
            UInt32 x8 = input.x8;
            UInt32 x9 = input.x9;
            UInt32 x10 = input.x10;
            UInt32 x11 = input.x11;
            UInt32 x12 = input.x12;
            UInt32 x13 = input.x13;
            UInt32 x14 = input.x14;
            UInt32 x15 = input.x15;

            unchecked
            {
                for (int i = 0; i \\\>\ (32 - 7));
                    y = x4 + x0;
                    x8 ^= (y \\\>\ (32 - 9));
                    y = x8 + x4;
                    x12 ^= (y \\\>\ (32 - 13));
                    y = x12 + x8;
                    x0 ^= (y \\\>\ (32 - 18));

                    // row 1
                    y = x5 + x1;
                    x9 ^= (y \\\>\ (32 - 7));
                    y = x9 + x5;
                    x13 ^= (y \\\>\ (32 - 9));
                    y = x13 + x9;
                    x1 ^= (y \\\>\ (32 - 13));
                    y = x1 + x13;
                    x5 ^= (y \\\>\ (32 - 18));

                    // row 2
                    y = x10 + x6;
                    x14 ^= (y \\\>\ (32 - 7));
                    y = x14 + x10;
                    x2 ^= (y \\\>\ (32 - 9));
                    y = x2 + x14;
                    x6 ^= (y \\\>\ (32 - 13));
                    y = x6 + x2;
                    x10 ^= (y \\\>\ (32 - 18));

                    // row 3
                    y = x15 + x11;
                    x3 ^= (y \\\>\ (32 - 7));
                    y = x3 + x15;
                    x7 ^= (y \\\>\ (32 - 9));
                    y = x7 + x3;
                    x11 ^= (y \\\>\ (32 - 13));
                    y = x11 + x7;
                    x15 ^= (y \\\>\ (32 - 18));

                    // column 0
                    y = x0 + x3;
                    x1 ^= (y \\\>\ (32 - 7));
                    y = x1 + x0;
                    x2 ^= (y \\\>\ (32 - 9));
                    y = x2 + x1;
                    x3 ^= (y \\\>\ (32 - 13));
                    y = x3 + x2;
                    x0 ^= (y \\\>\ (32 - 18));

                    // column 1
                    y = x5 + x4;
                    x6 ^= (y \\\>\ (32 - 7));
                    y = x6 + x5;
                    x7 ^= (y \\\>\ (32 - 9));
                    y = x7 + x6;
                    x4 ^= (y \\\>\ (32 - 13));
                    y = x4 + x7;
                    x5 ^= (y \\\>\ (32 - 18));

                    // column 2
                    y = x10 + x9;
                    x11 ^= (y \\\>\ (32 - 7));
                    y = x11 + x10;
                    x8 ^= (y \\\>\ (32 - 9));
                    y = x8 + x11;
                    x9 ^= (y \\\>\ (32 - 13));
                    y = x9 + x8;
                    x10 ^= (y \\\>\ (32 - 18));

                    // column 3
                    y = x15 + x14;
                    x12 ^= (y \\\>\ (32 - 7));
                    y = x12 + x15;
                    x13 ^= (y \\\>\ (32 - 9));
                    y = x13 + x12;
                    x14 ^= (y \\\>\ (32 - 13));
                    y = x14 + x13;
                    x15 ^= (y \\\>\ (32 - 18));
                }
            }
Example #34
0
        public static void HSalsa(out Array16<uint> output, ref Array16<uint> input, int rounds)
        {
            Contract.Requires<InvalidOperationException>(rounds % 2 == 0);

            int doubleRounds = rounds / 2;

            uint x0 = input.x0;
            uint x1 = input.x1;
            uint x2 = input.x2;
            uint x3 = input.x3;
            uint x4 = input.x4;
            uint x5 = input.x5;
            uint x6 = input.x6;
            uint x7 = input.x7;
            uint x8 = input.x8;
            uint x9 = input.x9;
            uint x10 = input.x10;
            uint x11 = input.x11;
            uint x12 = input.x12;
            uint x13 = input.x13;
            uint x14 = input.x14;
            uint x15 = input.x15;

            unchecked
            {
                for (int i = 0; i < doubleRounds; i++)
                {
                    uint y;

                    // row 0
                    y = x0 + x12;
                    x4 ^= (y << 7) | (y >> (32 - 7));
                    y = x4 + x0;
                    x8 ^= (y << 9) | (y >> (32 - 9));
                    y = x8 + x4;
                    x12 ^= (y << 13) | (y >> (32 - 13));
                    y = x12 + x8;
                    x0 ^= (y << 18) | (y >> (32 - 18));

                    // row 1
                    y = x5 + x1;
                    x9 ^= (y << 7) | (y >> (32 - 7));
                    y = x9 + x5;
                    x13 ^= (y << 9) | (y >> (32 - 9));
                    y = x13 + x9;
                    x1 ^= (y << 13) | (y >> (32 - 13));
                    y = x1 + x13;
                    x5 ^= (y << 18) | (y >> (32 - 18));

                    // row 2
                    y = x10 + x6;
                    x14 ^= (y << 7) | (y >> (32 - 7));
                    y = x14 + x10;
                    x2 ^= (y << 9) | (y >> (32 - 9));
                    y = x2 + x14;
                    x6 ^= (y << 13) | (y >> (32 - 13));
                    y = x6 + x2;
                    x10 ^= (y << 18) | (y >> (32 - 18));

                    // row 3
                    y = x15 + x11;
                    x3 ^= (y << 7) | (y >> (32 - 7));
                    y = x3 + x15;
                    x7 ^= (y << 9) | (y >> (32 - 9));
                    y = x7 + x3;
                    x11 ^= (y << 13) | (y >> (32 - 13));
                    y = x11 + x7;
                    x15 ^= (y << 18) | (y >> (32 - 18));

                    // column 0
                    y = x0 + x3;
                    x1 ^= (y << 7) | (y >> (32 - 7));
                    y = x1 + x0;
                    x2 ^= (y << 9) | (y >> (32 - 9));
                    y = x2 + x1;
                    x3 ^= (y << 13) | (y >> (32 - 13));
                    y = x3 + x2;
                    x0 ^= (y << 18) | (y >> (32 - 18));

                    // column 1
                    y = x5 + x4;
                    x6 ^= (y << 7) | (y >> (32 - 7));
                    y = x6 + x5;
                    x7 ^= (y << 9) | (y >> (32 - 9));
                    y = x7 + x6;
                    x4 ^= (y << 13) | (y >> (32 - 13));
                    y = x4 + x7;
                    x5 ^= (y << 18) | (y >> (32 - 18));

                    // column 2
                    y = x10 + x9;
                    x11 ^= (y << 7) | (y >> (32 - 7));
                    y = x11 + x10;
                    x8 ^= (y << 9) | (y >> (32 - 9));
                    y = x8 + x11;
                    x9 ^= (y << 13) | (y >> (32 - 13));
                    y = x9 + x8;
                    x10 ^= (y << 18) | (y >> (32 - 18));

                    // column 3
                    y = x15 + x14;
                    x12 ^= (y << 7) | (y >> (32 - 7));
                    y = x12 + x15;
                    x13 ^= (y << 9) | (y >> (32 - 9));
                    y = x13 + x12;
                    x14 ^= (y << 13) | (y >> (32 - 13));
                    y = x14 + x13;
                    x15 ^= (y << 18) | (y >> (32 - 18));
                }
            }

            output.x0 = x0;
            output.x1 = x1;
            output.x2 = x2;
            output.x3 = x3;
            output.x4 = x4;
            output.x5 = x5;
            output.x6 = x6;
            output.x7 = x7;
            output.x8 = x8;
            output.x9 = x9;
            output.x10 = x10;
            output.x11 = x11;
            output.x12 = x12;
            output.x13 = x13;
            output.x14 = x14;
            output.x15 = x15;
        }
Example #35
0
 public static void Salsa(out Array16<uint> output, ref Array16<uint> input, int rounds)
 {
     Array16<uint> temp;
     HSalsa(out temp, ref input, rounds);
     unchecked
     {
         output.x0 = temp.x0 + input.x0;
         output.x1 = temp.x1 + input.x1;
         output.x2 = temp.x2 + input.x2;
         output.x3 = temp.x3 + input.x3;
         output.x4 = temp.x4 + input.x4;
         output.x5 = temp.x5 + input.x5;
         output.x6 = temp.x6 + input.x6;
         output.x7 = temp.x7 + input.x7;
         output.x8 = temp.x8 + input.x8;
         output.x9 = temp.x9 + input.x9;
         output.x10 = temp.x10 + input.x10;
         output.x11 = temp.x11 + input.x11;
         output.x12 = temp.x12 + input.x12;
         output.x13 = temp.x13 + input.x13;
         output.x14 = temp.x14 + input.x14;
         output.x15 = temp.x15 + input.x15;
     }
 }
        /*public static void Array16LoadLittleEndian32(out Array16<UInt32> output, byte[] input, int inputOffset, int inputLength)
        {
            Array8<UInt32> temp;
            if (inputLength > 32)
            {
                output.x0 = LoadLittleEndian32(input, inputOffset + 0);
                output.x1 = LoadLittleEndian32(input, inputOffset + 4);
                output.x2 = LoadLittleEndian32(input, inputOffset + 8);
                output.x3 = LoadLittleEndian32(input, inputOffset + 12);
                output.x4 = LoadLittleEndian32(input, inputOffset + 16);
                output.x5 = LoadLittleEndian32(input, inputOffset + 20);
                output.x6 = LoadLittleEndian32(input, inputOffset + 24);
                output.x7 = LoadLittleEndian32(input, inputOffset + 28);
                Array8LoadLittleEndian32(out temp, input, inputOffset + 32, inputLength - 32);
                output.x8 = temp.x0;
                output.x9 = temp.x1;
                output.x10 = temp.x2;
                output.x11 = temp.x3;
                output.x12 = temp.x4;
                output.x13 = temp.x5;
                output.x14 = temp.x6;
                output.x15 = temp.x7;
            }
            else
            {
                Array8LoadLittleEndian32(out temp, input, inputOffset, inputLength);
                output.x0 = temp.x0;
                output.x1 = temp.x1;
                output.x2 = temp.x2;
                output.x3 = temp.x3;
                output.x4 = temp.x4;
                output.x5 = temp.x5;
                output.x6 = temp.x6;
                output.x7 = temp.x7;
                output.x8 = 0;
                output.x9 = 0;
                output.x10 = 0;
                output.x11 = 0;
                output.x12 = 0;
                output.x13 = 0;
                output.x14 = 0;
                output.x15 = 0;
            }
        }*/

        public static void Array16StoreLittleEndian32(byte[] output, int outputOffset, ref Array16<UInt32> input)
        {
            StoreLittleEndian32(output, outputOffset + 0, input.x0);
            StoreLittleEndian32(output, outputOffset + 4, input.x1);
            StoreLittleEndian32(output, outputOffset + 8, input.x2);
            StoreLittleEndian32(output, outputOffset + 12, input.x3);
            StoreLittleEndian32(output, outputOffset + 16, input.x4);
            StoreLittleEndian32(output, outputOffset + 20, input.x5);
            StoreLittleEndian32(output, outputOffset + 24, input.x6);
            StoreLittleEndian32(output, outputOffset + 28, input.x7);
            StoreLittleEndian32(output, outputOffset + 32, input.x8);
            StoreLittleEndian32(output, outputOffset + 36, input.x9);
            StoreLittleEndian32(output, outputOffset + 40, input.x10);
            StoreLittleEndian32(output, outputOffset + 44, input.x11);
            StoreLittleEndian32(output, outputOffset + 48, input.x12);
            StoreLittleEndian32(output, outputOffset + 52, input.x13);
            StoreLittleEndian32(output, outputOffset + 56, input.x14);
            StoreLittleEndian32(output, outputOffset + 60, input.x15);
        }
Example #37
0
        public static void HSalsa(out Array16<UInt32> output, ref Array16<UInt32> input, int rounds)
        {
            InternalAssert.Assert(rounds % 2 == 0, "Number of salsa rounds must be even");

            int doubleRounds = rounds / 2;

            UInt32 x0 = input.x0;
            UInt32 x1 = input.x1;
            UInt32 x2 = input.x2;
            UInt32 x3 = input.x3;
            UInt32 x4 = input.x4;
            UInt32 x5 = input.x5;
            UInt32 x6 = input.x6;
            UInt32 x7 = input.x7;
            UInt32 x8 = input.x8;
            UInt32 x9 = input.x9;
            UInt32 x10 = input.x10;
            UInt32 x11 = input.x11;
            UInt32 x12 = input.x12;
            UInt32 x13 = input.x13;
            UInt32 x14 = input.x14;
            UInt32 x15 = input.x15;

            unchecked
            {
                for (int i = 0; i < doubleRounds; i++)
                {
                    UInt32 y;

                    // row 0
                    y = x0 + x12;
                    x4 ^= (y << 7) | (y >> (32 - 7));
                    y = x4 + x0;
                    x8 ^= (y << 9) | (y >> (32 - 9));
                    y = x8 + x4;
                    x12 ^= (y << 13) | (y >> (32 - 13));
                    y = x12 + x8;
                    x0 ^= (y << 18) | (y >> (32 - 18));

                    // row 1
                    y = x5 + x1;
                    x9 ^= (y << 7) | (y >> (32 - 7));
                    y = x9 + x5;
                    x13 ^= (y << 9) | (y >> (32 - 9));
                    y = x13 + x9;
                    x1 ^= (y << 13) | (y >> (32 - 13));
                    y = x1 + x13;
                    x5 ^= (y << 18) | (y >> (32 - 18));

                    // row 2
                    y = x10 + x6;
                    x14 ^= (y << 7) | (y >> (32 - 7));
                    y = x14 + x10;
                    x2 ^= (y << 9) | (y >> (32 - 9));
                    y = x2 + x14;
                    x6 ^= (y << 13) | (y >> (32 - 13));
                    y = x6 + x2;
                    x10 ^= (y << 18) | (y >> (32 - 18));

                    // row 3
                    y = x15 + x11;
                    x3 ^= (y << 7) | (y >> (32 - 7));
                    y = x3 + x15;
                    x7 ^= (y << 9) | (y >> (32 - 9));
                    y = x7 + x3;
                    x11 ^= (y << 13) | (y >> (32 - 13));
                    y = x11 + x7;
                    x15 ^= (y << 18) | (y >> (32 - 18));

                    // column 0
                    y = x0 + x3;
                    x1 ^= (y << 7) | (y >> (32 - 7));
                    y = x1 + x0;
                    x2 ^= (y << 9) | (y >> (32 - 9));
                    y = x2 + x1;
                    x3 ^= (y << 13) | (y >> (32 - 13));
                    y = x3 + x2;
                    x0 ^= (y << 18) | (y >> (32 - 18));

                    // column 1
                    y = x5 + x4;
                    x6 ^= (y << 7) | (y >> (32 - 7));
                    y = x6 + x5;
                    x7 ^= (y << 9) | (y >> (32 - 9));
                    y = x7 + x6;
                    x4 ^= (y << 13) | (y >> (32 - 13));
                    y = x4 + x7;
                    x5 ^= (y << 18) | (y >> (32 - 18));

                    // column 2
                    y = x10 + x9;
                    x11 ^= (y << 7) | (y >> (32 - 7));
                    y = x11 + x10;
                    x8 ^= (y << 9) | (y >> (32 - 9));
                    y = x8 + x11;
                    x9 ^= (y << 13) | (y >> (32 - 13));
                    y = x9 + x8;
                    x10 ^= (y << 18) | (y >> (32 - 18));

                    // column 3
                    y = x15 + x14;
                    x12 ^= (y << 7) | (y >> (32 - 7));
                    y = x12 + x15;
                    x13 ^= (y << 9) | (y >> (32 - 9));
                    y = x13 + x12;
                    x14 ^= (y << 13) | (y >> (32 - 13));
                    y = x14 + x13;
                    x15 ^= (y << 18) | (y >> (32 - 18));
                }
            }

            output.x0 = x0;
            output.x1 = x1;
            output.x2 = x2;
            output.x3 = x3;
            output.x4 = x4;
            output.x5 = x5;
            output.x6 = x6;
            output.x7 = x7;
            output.x8 = x8;
            output.x9 = x9;
            output.x10 = x10;
            output.x11 = x11;
            output.x12 = x12;
            output.x13 = x13;
            output.x14 = x14;
            output.x15 = x15;
        }
 public static void Array16StoreLittleEndian32(byte[] output, int outputOffset, ref Array16 <uint> input)
 {
     StoreLittleEndian32(output, outputOffset + 0, input.x0);
     StoreLittleEndian32(output, outputOffset + 4, input.x1);
     StoreLittleEndian32(output, outputOffset + 8, input.x2);
     StoreLittleEndian32(output, outputOffset + 12, input.x3);
     StoreLittleEndian32(output, outputOffset + 16, input.x4);
     StoreLittleEndian32(output, outputOffset + 20, input.x5);
     StoreLittleEndian32(output, outputOffset + 24, input.x6);
     StoreLittleEndian32(output, outputOffset + 28, input.x7);
     StoreLittleEndian32(output, outputOffset + 32, input.x8);
     StoreLittleEndian32(output, outputOffset + 36, input.x9);
     StoreLittleEndian32(output, outputOffset + 40, input.x10);
     StoreLittleEndian32(output, outputOffset + 44, input.x11);
     StoreLittleEndian32(output, outputOffset + 48, input.x12);
     StoreLittleEndian32(output, outputOffset + 52, input.x13);
     StoreLittleEndian32(output, outputOffset + 56, input.x14);
     StoreLittleEndian32(output, outputOffset + 60, input.x15);
 }
 public static void Array16LoadLittleEndian32(out Array16<UInt32> output, byte[] input, int inputOffset, int inputLength)
 {
     Array8<UInt32> temp;
     if (inputLength > 32)
     {
         output.x0 = LoadLittleEndian32(input, inputOffset + 0);
         output.x1 = LoadLittleEndian32(input, inputOffset + 4);
         output.x2 = LoadLittleEndian32(input, inputOffset + 8);
         output.x3 = LoadLittleEndian32(input, inputOffset + 12);
         output.x4 = LoadLittleEndian32(input, inputOffset + 16);
         output.x5 = LoadLittleEndian32(input, inputOffset + 20);
         output.x6 = LoadLittleEndian32(input, inputOffset + 24);
         output.x7 = LoadLittleEndian32(input, inputOffset + 28);
         Array8LoadLittleEndian32(out temp, input, inputOffset + 32, inputLength - 32);
         output.x8 = temp.x0;
         output.x9 = temp.x1;
         output.x10 = temp.x2;
         output.x11 = temp.x3;
         output.x12 = temp.x4;
         output.x13 = temp.x5;
         output.x14 = temp.x6;
         output.x15 = temp.x7;
     }
     else
     {
         Array8LoadLittleEndian32(out temp, input, inputOffset, inputLength);
         output.x0 = temp.x0;
         output.x1 = temp.x1;
         output.x2 = temp.x2;
         output.x3 = temp.x3;
         output.x4 = temp.x4;
         output.x5 = temp.x5;
         output.x6 = temp.x6;
         output.x7 = temp.x7;
         output.x8 = 0;
         output.x9 = 0;
         output.x10 = 0;
         output.x11 = 0;
         output.x12 = 0;
         output.x13 = 0;
         output.x14 = 0;
         output.x15 = 0;
     }
 }