예제 #1
0
        static void ReplaceVehicleAI <TOldAI, TNewAI>(VehicleInfo i)
            where TOldAI : VehicleAI where TNewAI : VehicleAI
        {
            // Requires the object to have the old AI
            var oldAI = i.gameObject.GetComponent <TOldAI>();

            if (oldAI == null || oldAI.GetType() != typeof(TOldAI))
            {
                return;
            }

            // Requires the object to not already have the new AI
            var newAI = i.gameObject.GetComponent <TNewAI>();

            if (newAI != null && newAI.GetType() == typeof(TNewAI))
            {
                CODebug.Log(LogChannel.Modding, string.Format("SlowSpeed: {0} already has {1}", i.name, typeof(TNewAI)));
                return;
            }

            CODebug.Log(LogChannel.Modding, string.Format("SlowSpeed: Replacing {0}'s {1} with {2}",
                                                          i.name, typeof(TOldAI), typeof(TNewAI)));

            newAI = i.gameObject.AddComponent <TNewAI>();

            ShallowCopyTo(oldAI, newAI);

            oldAI.ReleaseAI();
            i.m_vehicleAI = newAI;
            UObject.Destroy(oldAI);
            newAI.InitializeAI();
        }
예제 #2
0
        public List <ResilientBuildings.ResilientInfoV1> convertVersionZeroListToOne(List <ResilientBuildings.ResilientInfo> list)
        {
            CODebug.Log(LogChannel.Modding, Mod.modName + " - Converting save data from version 0 to 1");
            List <ResilientBuildings.ResilientInfoV1> newList = new List <ResilientBuildings.ResilientInfoV1>();

            for (int i = 0; i < list.Count; i++)
            {
                ResilientBuildings.ResilientInfo   ri0 = list[i];
                ResilientBuildings.ResilientInfoV1 ri1 = new ResilientBuildings.ResilientInfoV1();
                ri1.activatedDate       = ri0.activatedDate;
                ri1.buildingID          = ri0.buildingID;
                ri1.chosenLevel         = ri0.chosenLevel;
                ri1.currentVisits       = ri0.currentVisits;
                ri1.description         = ri0.description;
                ri1.goodsBuffer1        = ri0.goodsBuffer1;
                ri1.goodsBuffer2        = ri0.goodsBuffer2;
                ri1.goodsBuffer3        = ri0.goodsBuffer3;
                ri1.goodsBuffer4        = ri0.goodsBuffer4;
                ri1.resiliencyActivated = ri0.resiliencyActivated;
                ri1.totalIncome         = ri0.totalIncome;
                ri1.totalVisits         = ri0.totalVisits;
                ri1.unsuscribed         = ri0.unsuscribed;
                ri1.unsuscribeTimer     = ri0.unsuscribeTimer;
                ri1.namesBuffer         = new List <string>();
                newList.Add(ri1);
            }
            return(newList);
        }
예제 #3
0
 public static void Print(object obj)
 {
     if (DEBUG)
     {
         CODebug.Log(LogChannel.Modding, "[DistrictStats] " + obj.ToString());
     }
 }
예제 #4
0
        public override void OnSaveData()
        {
            base.OnSaveData();

            if (!LoadingExtension.installed)
            {
                return;
            }

            CODebug.Log(LogChannel.Modding, Mod.modName + " - try saving data");
            try {
                if (m_serializedData != null)
                {
                    BinaryFormatter bFormatter2 = new BinaryFormatter();
                    MemoryStream    mStream2    = new MemoryStream();
                    bFormatter2.Serialize(mStream2, SAVE_DATA_VERSION);
                    byte[] data2 = mStream2.ToArray();
                    if (data2 != null)
                    {
                        m_serializedData.SaveData(RESILIENTS_VERSION_ID, data2);
                    }

                    BinaryFormatter bFormatter = new BinaryFormatter();
                    MemoryStream    mStream    = new MemoryStream();
                    bFormatter.Serialize(mStream, s_info.m_resilients);
                    byte[] data = mStream.ToArray();
                    if (data != null)
                    {
                        m_serializedData.SaveData(RESILIENTS_DATA_ID, data);
                    }

                    BinaryFormatter bFormatter4 = new BinaryFormatter();
                    MemoryStream    mStream4    = new MemoryStream();
                    bFormatter4.Serialize(mStream4, s_info.m_districts);
                    byte[] data4 = mStream4.ToArray();
                    if (data4 != null)
                    {
                        m_serializedData.SaveData(RESILIENTS_DISTRICTS_ID, data4);
                    }

                    BinaryFormatter bFormatter3 = new BinaryFormatter();
                    MemoryStream    mStream3    = new MemoryStream();
                    bFormatter3.Serialize(mStream3, Settings.inst);
                    byte[] data3 = mStream3.ToArray();

                    if (data3 != null)
                    {
                        m_serializedData.SaveData(RESILIENTS_SETTINGS_ID, data3);
                    }

                    CODebug.Log(LogChannel.Modding, Mod.modName + " - successful saving data");
                }
                else
                {
                }
            } catch (Exception e) {
                CODebug.Log(LogChannel.Modding, Mod.modName + " - Error saving data " + e.StackTrace);
            }
        }
예제 #5
0
        /*********** custom icons *************/

        public static UITextureAtlas CreateTextureAtlas(string textureFile, string atlasName, Material baseMaterial, int spriteWidth, int spriteHeight, int spriteCountHor)
        {
            Texture2D tex = new Texture2D(spriteWidth * spriteCountHor, spriteHeight, TextureFormat.ARGB32, false);

            tex.filterMode = FilterMode.Bilinear;

            try
            {             // LoadTexture
                System.Reflection.Assembly assembly      = System.Reflection.Assembly.GetExecutingAssembly();
                System.IO.Stream           textureStream = assembly.GetManifestResourceStream("ResilientOwners." + textureFile);

                byte[] buf = new byte[textureStream.Length];            //declare arraysize
                textureStream.Read(buf, 0, buf.Length);                 // read from stream to byte array

                tex.LoadImage(buf);

                tex.Apply(true, true);
            }
            catch
            {
                CODebug.Log(LogChannel.Modding, "error opening texture file");
            }

            UITextureAtlas atlas = ScriptableObject.CreateInstance <UITextureAtlas>();

            try
            {             // Setup atlas
                Material material = (Material)Material.Instantiate(baseMaterial);
                material.mainTexture = tex;
                atlas.material       = material;
                atlas.name           = atlasName;
            }
            catch
            {
                CODebug.Log(LogChannel.Modding, "error setting texture");
            }

            // Add sprites
            for (int i = 0; i < spriteCountHor; ++i)
            {
                float uw = 1.0f / spriteCountHor;

                var spriteInfo = new UITextureAtlas.SpriteInfo()
                {
                    name    = atlasName + "_" + i,
                    texture = tex,
                    region  = new Rect(i * uw, 0, uw, 1),
                };

                atlas.AddSprite(spriteInfo);
            }

            return(atlas);
        }
예제 #6
0
        private static bool Prefix(ref LoadThemePanel __instance, ref UIListBox ___m_SaveList, ref UIButton ___m_LoadButton, string ___m_LastSaveName)
        {
            using (AutoProfile.Start("LoadMapPanel.Refresh()")) {
                ClearListing.Invoke(__instance, null);
                bool snowfallOwned = SteamHelper.IsDLCOwned(SteamHelper.DLC.SnowFallDLC);
                foreach (Package.Asset asset in PackageManager.FilterAssets(UserAssetType.MapThemeMetaData))
                {
                    if (asset == null || !asset.isEnabled)
                    {
                        continue;
                    }
                    try {
                        var mmd = asset.Instantiate <MapThemeMetaData>();
                        mmd.SetSelfRef(asset);
                        if (mmd.environment == "Winter" && !snowfallOwned)
                        {
                            continue;
                        }
                        var forbid = false;
                        foreach (string s in Forbidden)
                        {
                            if (asset.fullName.Contains(s))
                            {
                                forbid = true;
                            }
                        }
                        if (forbid)
                        {
                            continue;
                        }
                        var parameters = _addToListingParamCount == 5 ? new object[] { asset.name, mmd.timeStamp, asset, mmd, true } : new object[] { asset.name, mmd.timeStamp, asset, mmd, true, false };
                        AddToListing.Invoke(__instance, parameters);
                    } catch (Exception ex) {
                        CODebug.Error(LogChannel.Serialization, "'" + asset.name + "' failed to load.\n" + ex.ToString());
                    }
                }

                ___m_SaveList.items = GetListingItems.Invoke(__instance, null) as string[];
                var listingCount = (int)GetListingCount.Invoke(__instance, null);
                if (listingCount > 0)
                {
                    var idx = (int)FindIndexOf.Invoke(__instance, new object[] { ___m_LastSaveName });
                    ___m_SaveList.selectedIndex = (idx != -1) ? idx : 0;
                    ___m_LoadButton.isEnabled   = true;
                }
                else
                {
                    ___m_LoadButton.isEnabled = false;
                }
            }
            return(false);
        }
예제 #7
0
        // Returns the closest safe point between target position and platform colliders
        public Vector2 GetClosestSafePosition(Vector2 position)
        {
            float closestDistance = 0.05f;

            Vector2 origin = transform.position;

            // position, angle, distance to box cast
            Vector2 heading   = position - origin;
            float   distance  = heading.magnitude;
            Vector2 direction = heading / distance;
            float   angle     = transform.rotation.eulerAngles.z;

            // check for colliders at new position
            Collider2D hit = CODebug.OverlapBox(position, _boxCollider.size, angle, PlatformMask, Color.cyan, true, 1f);

            //DebugDrawBox(position, _boxCollider.size, angle, Color.cyan, 5f);

            // TODO - fix. doesn't handle rotation.

            // if no hit on box cast, then safe. return position;
            if (hit == null)
            {
                return(position);
            }

            Vector3 conflictHeading   = (Vector2)hit.transform.position - origin;
            float   conflictDistance  = conflictHeading.magnitude;
            Vector2 conflictDirection = conflictHeading / conflictDistance;

            position += -conflictDirection * 0.05f;

            hit = CODebug.OverlapBox(position, _boxCollider.size, angle, PlatformMask, Color.red, true, 1f);
            if (hit == null)
            {
                return(position);
            }
            else
            {
                if (!disableWarnings)
                {
                    Debug.LogWarning("Ignoring SetTransform request - no valid position detected");
                }

                return(origin);
            }
        }
예제 #8
0
        static void ShallowCopyTo(object src, object dst)
        {
            var srcFields = GetFields(src);
            var dstFields = GetFields(dst);

            foreach (var srcField in srcFields)
            {
                FieldInfo dstField;

                if (!dstFields.TryGetValue(srcField.Key, out dstField))
                {
                    continue;
                }

                CODebug.Log(LogChannel.Modding, string.Format("SlowSpeed: Setting {0} to {1} ({2} to {3})",
                                                              dstField.Name, srcField.Value.GetValue(src), src.GetType(), dst.GetType()));

                dstField.SetValue(dst, srcField.Value.GetValue(src));
            }
        }
예제 #9
0
        public virtual void HandleWallWalking()
        {
            HorizontalMovement direction = MovementDirection;

            if (controller == null)
            {
                controller    = (CorgiControllerOverride)_controller;
                _boundsWidth  = controller.BoundsWidth;
                _boundsHeight = controller.BoundsHeight;
                _boundsDiff   = Mathf.Abs(_boundsWidth - _boundsHeight);
            }

            if (direction == HorizontalMovement.Left && _controller.State.IsCollidingLeft)
            {
                // shift position by difference between height / width to accommodate for pivot rotation
                controller.SetTransform(transform.position + transform.up * Mathf.Abs(_boundsDiff));

                RotateGravity(direction);

                // no longer colliding due to rotational shift
                _controller.State.IsCollidingLeft = false;
            }
            else if (direction == HorizontalMovement.Right && _controller.State.IsCollidingRight)
            {
                // shift position by difference between height / width to accommodate for pivot rotation
                controller.SetTransform(transform.position + -transform.up * Mathf.Abs(_boundsDiff));

                RotateGravity(direction);

                // no longer colliding due to rotational shift
                _controller.State.IsCollidingRight = false;
            }
            else if (IsOverLedge())
            {
                // whether player is on vertical or horizontal plane
                //bool isVertical = _defaultGravityAngle == 90 || _defaultGravityAngle == 270;

                RotateGravity((HorizontalMovement)(-(float)direction));

                Transition(true, GravityDirectionVector);

                // get forward direction depending which direction character is facing
                Vector3 forward = _character.IsFacingRight ? transform.right : -transform.right;

                Vector3 forwardAmount = (_boundsWidth * 0.5f * forward) + (_boundsWidth * ledgeCheckRayOffset) * forward + _boundsDiff * forward;
                Vector3 downAmount    = (_boundsWidth * 0.5f * -transform.up) + (_boundsWidth * ledgeCheckRayOffset * -transform.up);

                Vector3 newPosition = transform.position + downAmount + forwardAmount;

                // check whether rotation / position shift is safe
                Collider2D hit = CODebug.OverlapBox(newPosition, controller.BoxCollider.size, _defaultGravityAngle, controller.PlatformMask, Color.cyan);

                // if safe, perform shift
                if (hit == null)
                {
                    transform.localEulerAngles = new Vector3(0, 0, _defaultGravityAngle);

                    // shift character position by overhang extent
                    controller.SetTransform(newPosition);
                }
                else
                {
                    CODebug.DebugDrawBox(newPosition, controller.BoxCollider.size, _defaultGravityAngle, Color.white, 5f);
                    // reverse gravity change
                    RotateGravity((HorizontalMovement)((float)direction));
                }
            }
        }
예제 #10
0
        public override void OnLoadData()
        {
            base.OnLoadData();

            CODebug.Log(LogChannel.Modding, Mod.modName + " - try loading data");

            //			if (s_info == null) {
            //				s_info
            //			}

            try {
                if (m_serializedData != null)
                {
                    byte[] data2 = m_serializedData.LoadData(RESILIENTS_VERSION_ID);
                    if (data2 != null)
                    {
                        BinaryFormatter bFormatter = new BinaryFormatter();
                        MemoryStream    mStream    = new MemoryStream(data2);
                        s_savedDataVersion = (int)bFormatter.Deserialize(mStream);
                    }
                    else
                    {
                        //save had no data
                    }

                    if (s_savedDataVersion >= 0 && s_savedDataVersion <= SAVE_DATA_VERSION)
                    {
                        byte[] data = m_serializedData.LoadData(RESILIENTS_DATA_ID);
                        if (data != null)
                        {
                            BinaryFormatter bFormatter = new BinaryFormatter();
                            MemoryStream    mStream    = new MemoryStream(data);
                            switch (s_savedDataVersion)
                            {
                            case 0:
                                List <ResilientBuildings.ResilientInfo> legacyList = (List <ResilientBuildings.ResilientInfo>)bFormatter.Deserialize(mStream);
                                s_data = convertVersionZeroListToOne(legacyList);
                                break;

                            case 1:
                            case 2:
                            case 3:
                                s_data = (List <ResilientBuildings.ResilientInfoV1>)bFormatter.Deserialize(mStream);
                                break;
                            }

                            CODebug.Log(LogChannel.Modding, Mod.modName + " - successful loading buildings data");
                        }
                        else
                        {
                        }

                        data = m_serializedData.LoadData(RESILIENTS_DISTRICTS_ID);
                        if (data != null)
                        {
                            BinaryFormatter bFormatter = new BinaryFormatter();
                            MemoryStream    mStream    = new MemoryStream(data);
                            switch (s_savedDataVersion)
                            {
                            case 3:
                                s_districts = (List <ResilientBuildings.ResilientDistrict>)bFormatter.Deserialize(mStream);
                                break;
                            }

                            CODebug.Log(LogChannel.Modding, Mod.modName + " - successful loading districts data");
                        }
                        else
                        {
                        }

                        data = m_serializedData.LoadData(RESILIENTS_SETTINGS_ID);
                        if (data != null)
                        {
                            BinaryFormatter bFormatter = new BinaryFormatter();
                            MemoryStream    mStream    = new MemoryStream(data);
                            switch (s_savedDataVersion)
                            {
                            case 2:
                            case 3:
                                Settings.inst = (ResilientSettings)bFormatter.Deserialize(mStream);
                                break;
                            }

                            CODebug.Log(LogChannel.Modding, Mod.modName + " - successful loading settings");
                        }
                        else
                        {
                        }
                    }
                    else
                    {
                        CODebug.Error(LogChannel.Modding, Mod.modName + " - invalid saved data version");
                    }
                }
            } catch (Exception e) {
                CODebug.Log(LogChannel.Modding, Mod.modName + " - Error loading data " + e.Message);
            }
        }
예제 #11
0
        public override int OnAddResource(EconomyResource resource, int amount, Service service, SubService subService, Level level)
        {
            if (!LoadingExtension.installed)
            {
                return(amount);
            }

            //check if OnAddResource call match what we are looking for
            if (!resource.Equals(EconomyResource.PrivateIncome)) //interested in private incomes only
            {
                return(amount);
            }

            if (service != Service.Office)            //only office buildings tracked here
            {
                return(amount);
            }

            //CODebug.Log(LogChannel.Modding, Mod.modName + " - IncomeTracker search building with service " + service + " subservice " + subService + " level " + level + " amount "+amount);

            SimulationManager instance  = Singleton <SimulationManager> .instance;
            BuildingManager   instance2 = Singleton <BuildingManager> .instance;

            //sync with simulation frame
            if (checkedFrameIndex != instance.m_currentFrameIndex)
            {
                checkedFrameIndex = instance.m_currentFrameIndex;
                int num6 = (int)(instance.m_currentFrameIndex & 255u);
                buildingID    = (ushort)(num6 * 192);
                maxBuildingID = (ushort)((num6 + 1) * 192 - 1);
            }

            //sync with BuildingManager SimulationStep loop
            bool skipping = true;
            bool error    = false;

            do
            {
                if ((instance2.m_buildings.m_buffer[buildingID].m_flags & Building.Flags.Created) == Building.Flags.None)
                {
                    skipping = true;
                }
                //abandoned buildings do no go through SimulationStepActive
                else if ((instance2.m_buildings.m_buffer[buildingID].m_flags & (Building.Flags.Abandoned | Building.Flags.BurnedDown)) != Building.Flags.None)
                {
                    skipping = true;
                }
//					else if(instance2.m_buildings.m_buffer[buildingID].Info.m_class.m_service == ItemClass.Service.Residential)
//					{
//						skipping = false;
//						if(service != Service.Residential)
//							error = true;
//					}
//					else if(instance2.m_buildings.m_buffer[buildingID].Info.m_class.m_service == ItemClass.Service.Industrial)
//					{
//						skipping = false;
//						if(service != Service.Industrial)
//							error = true;
//					}
//					else if(instance2.m_buildings.m_buffer[buildingID].Info.m_class.m_service == ItemClass.Service.Commercial)
//					{
//						skipping = false;
//						if(service != Service.Commercial)
//							error = true;
//					}
                else if (instance2.m_buildings.m_buffer[buildingID].Info.m_class.m_service == ItemClass.Service.Office)
                {
                    skipping = false;
                }
//					else if(instance2.m_buildings.m_buffer[buildingID].Info.m_class.m_service == ItemClass.Service.Beautification)
//					{
//						skipping = false;
//						if(service != Service.Beautification)
//							error = true;
//					}
//					else if(instance2.m_buildings.m_buffer[buildingID].Info.m_class.m_service == ItemClass.Service.Citizen)
//					{
//						skipping = false;
//						if(service != Service.Citizen)
//							error = true;
//					}
//					else if(instance2.m_buildings.m_buffer[buildingID].Info.m_class.m_service == ItemClass.Service.Education)
//					{
//						skipping = false;
//						if(service != Service.Education)
//							error = true;
//					}
//					else if(instance2.m_buildings.m_buffer[buildingID].Info.m_class.m_service == ItemClass.Service.Electricity)
//					{
//						skipping = false;
//						if(service != Service.Electricity)
//							error = true;
//					}
//					else if(instance2.m_buildings.m_buffer[buildingID].Info.m_class.m_service == ItemClass.Service.FireDepartment)
//					{
//						skipping = false;
//						if(service != Service.FireDepartment)
//							error = true;
//					}
//					else if(instance2.m_buildings.m_buffer[buildingID].Info.m_class.m_service == ItemClass.Service.Garbage)
//					{
//						skipping = false;
//						if(service != Service.Garbage)
//							error = true;
//					}
//					else if(instance2.m_buildings.m_buffer[buildingID].Info.m_class.m_service == ItemClass.Service.Government)
//					{
//						skipping = false;
////						if(service != Service.Governement)
////							error = true;
//					}
//					else if(instance2.m_buildings.m_buffer[buildingID].Info.m_class.m_service == ItemClass.Service.HealthCare)
//					{
//						skipping = false;
//						if(service != Service.HealthCare)
//							error = true;
//					}
//					else if(instance2.m_buildings.m_buffer[buildingID].Info.m_class.m_service == ItemClass.Service.Monument)
//					{
//						skipping = false;
//						if(service != Service.Monument)
//							error = true;
//					}
//					else if(instance2.m_buildings.m_buffer[buildingID].Info.m_class.m_service == ItemClass.Service.PoliceDepartment)
//					{
//						skipping = false;
//						if(service != Service.PoliceDepartment)
//							error = true;
//					}
//					else if(instance2.m_buildings.m_buffer[buildingID].Info.m_class.m_service == ItemClass.Service.PublicTransport)
//					{
//						skipping = false;
//						if(service != Service.PublicTransport)
//							error = true;
//					}
//					else if(instance2.m_buildings.m_buffer[buildingID].Info.m_class.m_service == ItemClass.Service.Road)
//					{
//						skipping = false;
//						if(service != Service.Road)
//							error = true;
//					}
//					else if(instance2.m_buildings.m_buffer[buildingID].Info.m_class.m_service == ItemClass.Service.Water)
//					{
//						skipping = false;
//						if(service != Service.Water)
//							error = true;
//					}
//					else if(instance2.m_buildings.m_buffer[buildingID].Info.m_class.m_service == ItemClass.Service.Unused1)
//					{
//						skipping = false;
////						if(service != Service.)
////							error = true;
//					}
//					else if(instance2.m_buildings.m_buffer[buildingID].Info.m_class.m_service == ItemClass.Service.Unused2)
//					{
//						skipping = false;
////						if(service != Service.Education)
////							error = true;
//					}
//					else
//					{
////						CODebug.Log(LogChannel.Modding, "income tracker private income for service "+instance2.m_buildings.m_buffer[buildingID].Info.m_class.m_service);
////						skipping = true;
//						skipping = false;
//						if(instance2.m_buildings.m_buffer[buildingID].Info.m_class.m_service.ToString() != service.ToString())
//						{
//							CODebug.Log(LogChannel.Modding, "income tracker mismatch "+instance2.m_buildings.m_buffer[buildingID].Info.m_class.m_service.ToString()+" "+service.ToString());
//						}
//					}

                if (skipping)
                {
                    buildingID++;
                    if (buildingID > maxBuildingID)
                    {
                        error    = true;
                        skipping = false;
                    }
                }
            }while(skipping);


            //check if active and history is activated
            if (!error)
            {
                if (instance2.m_buildings.m_buffer[buildingID].Info.m_class.m_service == ItemClass.Service.Office)
                {
                    int    buildIndex = s_info.GetResilientBuildingIndex((ushort)buildingID);
                    String buildinfo2 = Singleton <BuildingManager> .instance.GetBuildingName(buildingID, default(InstanceID));

                    //CODebug.Log(LogChannel.Modding, Mod.modName + " - IncomeTracker found building with id " + buildingID + " buildIndex " + buildIndex + " " + buildinfo2);
                    if (buildIndex != -1)
                    {
                        ResilientBuildings.ResilientInfoV1 ri = s_info.m_resilients[buildIndex];
                        ri.totalIncome += amount;
                        s_info.m_resilients[buildIndex] = ri;
                    }
                }
                buildingID++; //ensure search starts from next building at next function call
            }
            else
            {
                CODebug.Log(LogChannel.Modding, Mod.modName + " - IncomeTracker could not meet building with service " + service + " subservice " + subService + " level " + level);
            }

            return(amount);
        }
 public static void OutputLog(String logType, String message)
 {
     CODebug.Log(LogChannel.Modding, Mod.InternalName + " - " + logType + ": " + message);
 }