예제 #1
0
        public override void AwakeBody()
        {
            KlyteUtils.doLog("Loading NonKCModsOverrides");
            #region Suburb Styler
            foreach (var typeName in supportedClasses)
            {
                var type = Type.GetType(typeName);
                try
                {
                    if (type != null)
                    {
                        KlyteUtils.SetPrivateStaticField("GetMainReference", type, new Func <UIComponent>(() => KlyteModsPanel.instance.mainPanel));
                        KlyteUtils.SetPrivateStaticField("ClosePanel", type, new OnButtonClicked(() => KlyteCommonsMod.CloseKCPanel()));
                        KlyteUtils.SetPrivateStaticField("OpenPanel", type, new OnButtonClicked(() => KlyteModsPanel.instance.OpenAt((ModTab)Enum.Parse(typeof(ModTab), KlyteUtils.RunPrivateStaticMethod <string>(type, "GetEnumName")))));



                        MethodInfo createPanelOverride = typeof(NonKCModsOverrides).GetMethod("CreateMainPanelOverride", allFlags);

                        AddRedirect(type.GetMethod("CreateMainPanel", allFlags), createPanelOverride);
                    }
                }
                catch (Exception e)
                {
                    KlyteUtils.doErrorLog($"{e.GetType()} detouring {type}: {e.Message}\n{e.StackTrace}");
                }
            }
            #endregion
        }
예제 #2
0
        protected static I construct(string cityId, string cityName)
        {
            if (string.IsNullOrEmpty(cityId))
            {
                throw new Exception("CITY ID NÃO PODE SER NULO!!!!!");
            }
            I result = new I
            {
                cityId   = cityId,
                cityName = cityName
            };
            SettingsFile settingFile = new SettingsFile
            {
                pathName = result.thisPathName
            };

            GameSettings.AddSettingsFile(settingFile);

            if (!settingFile.IsValid() && cityId != GLOBAL_CONFIG_INDEX)
            {
                try
                {
                    I defaultFile = getConfig(GLOBAL_CONFIG_INDEX, GLOBAL_CONFIG_INDEX);
                    foreach (string key in GameSettings.FindSettingsFileByName(defaultFile.thisFileName).ListKeys())
                    {
                        try
                        {
                            T ci = (T)Enum.Parse(typeof(T), key);
                            switch (ci.ToInt32(CultureInfo.CurrentCulture.NumberFormat) & TYPE_PART)
                            {
                            case TYPE_BOOL:
                                result.setBool(ci, defaultFile.getBool(ci));
                                break;

                            case TYPE_STRING:
                            case TYPE_LIST:
                                result.setString(ci, defaultFile.getString(ci));
                                break;

                            case TYPE_INT:
                                result.setInt(ci, defaultFile.getInt(ci));
                                break;
                            }
                        }
                        catch (Exception e)
                        {
                            KlyteUtils.doErrorLog($"Erro copiando propriedade \"{key}\" para o novo arquivo da classe {typeof(I)}: {e.Message}");
                        }
                    }
                }
                catch
                {
                }
            }
            return(result);
        }
예제 #3
0
        public AssetBundle loadBundle(string filename)
        {
            try
            {
                return(AssetBundle.LoadFromMemory(loadResourceData(filename)));
            }
            catch (Exception e)
            {
                KlyteUtils.doErrorLog("The file could not be read:" + e.Message);
            }

            return(null);
        }
예제 #4
0
        public static object ExecuteReflectionMethod(Type t, string methodName, params object[] args)
        {
            var method = t.GetMethod(methodName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static);

            try
            {
                return(method?.Invoke(null, args));
            }
            catch (Exception e)
            {
                KlyteUtils.doErrorLog("ERROR REFLECTING METHOD: {0} ({1}) => {2}\r\n{3}\r\n{4}", null, methodName, args, e.Message, e.StackTrace);
                return(null);
            }
        }
예제 #5
0
        public Texture2D loadTexture(int x, int y, string filename)
        {
            try
            {
                Texture2D texture = new Texture2D(x, y);
                texture.LoadImage(loadResourceData(filename));
                return(texture);
            }
            catch (Exception e)
            {
                KlyteUtils.doErrorLog("The file could not be read:" + e.Message);
            }

            return(null);
        }
예제 #6
0
        public string loadResourceString(string name)
        {
            name = prefix + name;

            UnmanagedMemoryStream stream = (UnmanagedMemoryStream)Assembly.GetAssembly(resourceReference).GetManifestResourceStream(name);

            if (stream == null)
            {
                KlyteUtils.doErrorLog("Could not find resource: " + name);
                return(null);
            }

            StreamReader read = new StreamReader(stream);

            return(read.ReadToEnd());
        }
예제 #7
0
        public byte[] loadResourceData(string name)
        {
            name = prefix + name;

            UnmanagedMemoryStream stream = (UnmanagedMemoryStream)Assembly.GetAssembly(resourceReference).GetManifestResourceStream(name);

            if (stream == null)
            {
                KlyteUtils.doErrorLog("Could not find resource: " + name);
                return(null);
            }

            BinaryReader read = new BinaryReader(stream);

            return(read.ReadBytes((int)stream.Length));
        }
예제 #8
0
        private Vector3 GetControlPoint(ushort segment)
        {
            Vector3 position       = nodeBuffer[(int)segmentBuffer[(int)segment].m_startNode].m_position;
            Vector3 startDirection = segmentBuffer[(int)segment].m_startDirection;
            Vector3 position2      = nodeBuffer[(int)segmentBuffer[(int)segment].m_endNode].m_position;
            Vector3 endDirection   = segmentBuffer[(int)segment].m_endDirection;

            if (!NetSegment.IsStraight(position, startDirection, position2, endDirection, out float num))
            {
                float num2 = startDirection.x * endDirection.x + startDirection.z * endDirection.z;
                if (num2 >= -0.999f && Line2.Intersect(VectorUtils.XZ(position), VectorUtils.XZ(position + startDirection), VectorUtils.XZ(position2), VectorUtils.XZ(position2 + endDirection), out float d, out float num3))
                {
                    return(position + startDirection * d);
                }
                KlyteUtils.doErrorLog("Warning! Invalid segment directions!");
            }
            return((position + position2) / 2f);
        }
예제 #9
0
 public static bool CreateMainPanelOverride(object __instance)
 {
     try
     {
         var panelType    = KlyteUtils.RunPrivateMethod <Type>(__instance, "GetDefaultClassForMainPanel");
         var textureAtlas = KlyteUtils.RunPrivateMethod <UITextureAtlas>(__instance, "GetTextureAtlasForIcon");
         var iconName     = KlyteUtils.RunPrivateMethod <string>(__instance, "GetIconName");
         var tabWidth     = KlyteUtils.RunPrivateMethod <int>(__instance, "GetTabWidth");
         var tooltipText  = KlyteUtils.RunPrivateMethod <string>(__instance, "GetTooltipText");
         var enumValue    = (ModTab)Enum.Parse(typeof(ModTab), KlyteUtils.RunPrivateMethod <string>(__instance, "GetEnumName"));
         KlyteModsPanel.instance.AddTab(enumValue, panelType, textureAtlas, iconName, tooltipText, (x, y) => { if (y)
                                                                                                               {
                                                                                                                   KlyteUtils.ExecuteReflectionMethod(__instance, "ShowVersionInfoPopup");
                                                                                                               }
                                        }, tabWidth);
         return(false);
     }
     catch (Exception e)
     {
         KlyteUtils.doErrorLog($"{e.GetType()} detouring {__instance}: {e.Message}\n{e.StackTrace}");
     }
     return(true);
 }
예제 #10
0
 public override void doErrorLog(string fmt, params object[] args)
 {
     KlyteUtils.doErrorLog(fmt, args);
 }