Exemplo n.º 1
0
        public static TweakReturnVoid LoadThumbnails(ComponentInfoList instance)
        {
            Debug.Log("Loading thumbnails...");

            ComponentInfo[] array = instance.mItems;
            for (int i = 0; i < array.Length; i++)
            {
                ComponentInfo componentInfo = array[i];
                if (componentInfo.mThumbnailName != null && componentInfo.mThumbnailName.StartsWith("RA3Tweaks/"))
                {
                    // Load the new thumbnail
                    Debug.Log("Loading thumbnail for " + componentInfo.mThumbnailName);
                    componentInfo.mThumbnail = AssetsHandler.Bundle.LoadAsset <Sprite>(componentInfo.mThumbnailName.Replace("RA3Tweaks/", ""));
                }
                else
                {
                    // Do the default loading
                    string name = "UI/ComponentThumbs/" + componentInfo.mThumbnailName;
                    componentInfo.mThumbnail = Resources.Load <Sprite>(name);
                }
            }

            // Return 'prevent default' as true to skip over the original code
            return(new TweakReturnVoid(true));
        }
Exemplo n.º 2
0
        public static int LoadFromJsonString(string jsonString)
        {
            Debug.Log("Loading RA3-Tweaks Components...");

            // Load up the custom components.json file
            string newJson = "";
            int    count   = 0;

            string[] allAssets = AssetsHandler.Bundle.GetAllAssetNames();
            foreach (var a in allAssets)
            {
                if (a.EndsWith("/component.json", StringComparison.OrdinalIgnoreCase))
                {
                    // Append this component to the json
                    string compJson      = AssetsHandler.Bundle.LoadAsset <TextAsset>(a).text;
                    string componentName = a.Substring(0, a.LastIndexOf('/') + 1);

                    // Prefix the prefab name with something we can identify later
                    Regex r = new Regex("\"componentprefabname\"\\s*:\\s*\"");
                    compJson = r.Replace(compJson, "\"componentprefabname\": \"RA3Tweaks/" + componentName);

                    Regex r2 = new Regex("\"thumbnail\"\\s*:\\s*\"");
                    compJson = r2.Replace(compJson, "\"thumbnail\": \"RA3Tweaks/" + componentName);

                    Debug.Log("Component.json loaded as:\r\n" + compJson);

                    newJson += (count > 0 ? ",\r\n" : "") + compJson;
                    count++;
                }
            }

            if (count > 0)
            {
                // Strip off the mismatched [ ] and combine the files
                int endIndex = jsonString.LastIndexOf(']');
                if (endIndex > -1)
                {
                    jsonString = jsonString.Substring(0, endIndex - 1) + ",\r\n" + newJson + "\r\n]";
                    Debug.Log(jsonString);
                }
            }


            // Call the original load with the new modified json
            ComponentInfoList instance = typeof(ComponentInfoList).GetField("_instance", BindingFlags.Static | BindingFlags.NonPublic).GetValue(null) as ComponentInfoList;

            return(instance.LoadFromJsonString(jsonString));
        }
Exemplo n.º 3
0
        public static void Initialize()
        {
            Debug.Log("RA3Injection::Plugin Initialized\n");

            ComponentInfoList.CreateFromFileOrResource(Application.dataPath + "/Components.json", "Databases/Components");

            GameObject go = (GameObject)UnityEngine.Object.Instantiate(Resources.Load("ComponentPrefabs/CompSawBlade60"));

            TweakHelpers.LogTransform(go.transform, "");

            string jsonString = System.IO.File.ReadAllText(@"D:\components.json");

            System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture;
            JsonData jsonData = JsonMapper.ToObject(jsonString);

            Debug.Log(jsonString);

            ComponentInfo[] items = new ComponentInfo[jsonData.Count];
            for (int i = 0; i < jsonData.Count; i++)
            {
                int mSubCategory = -1;
                int mCategory    = -1;
                items[i] = new ComponentInfo();
                jsonData[i].Read("active", ref items[i].mActive);
                jsonData[i].Read("displaymass", ref items[i].mDisplayMass);
                jsonData[i].Read("name", ref items[i].mName);
                jsonData[i].Read("description", ref items[i].mDescription);
                jsonData[i].Read("thumbnail", ref items[i].mThumbnailName);
                jsonData[i].Read("componentprefabname", ref items[i].mPrefabName);
                jsonData[i].Read("attchassis", ref items[i].mAttChassis);
                jsonData[i].Read("mirrorx", ref items[i].mMirrorX);
                jsonData[i].Read("mirrory", ref items[i].mMirrorY);
                jsonData[i].Read("mirrorz", ref items[i].mMirrorZ);
                jsonData[i].Read("mass", ref items[i].mMass);
                jsonData[i].Read("elecsupply", ref items[i].mElecSupply);
                jsonData[i].Read("elecdraw", ref items[i].mElecDraw);
                jsonData[i].Read("airsupply", ref items[i].mAirSupply);
                jsonData[i].Read("airdraw", ref items[i].mAirDraw);
                jsonData[i].Read("dpiblunt", ref items[i].mDpiBlunt);
                jsonData[i].Read("dpipierce", ref items[i].mDpiPierce);
                jsonData[i].Read("dpiflame", ref items[i].mDpiFlame);
                jsonData[i].Read("dpielec", ref items[i].mDpiElec);
                jsonData[i].Read("dpsblunt", ref items[i].mDpsBlunt);
                jsonData[i].Read("dpspierce", ref items[i].mDpsPierce);
                jsonData[i].Read("dpsflame", ref items[i].mDpsFlame);
                jsonData[i].Read("dpselec", ref items[i].mDpsElec);
                jsonData[i].Read("hpfactblunt", ref items[i].mHpFactBlunt);
                jsonData[i].Read("hpfactpierce", ref items[i].mHpFactPierce);
                jsonData[i].Read("hpfactflame", ref items[i].mHpFactFlame);
                jsonData[i].Read("hpfactelec", ref items[i].mHpFactElec);
                jsonData[i].Read("hitpoints", ref items[i].mHitPoints);
                jsonData[i].Read("uispecial", ref items[i].mUISpecial);
                jsonData[i].Read("attachsound", ref items[i].mAttachSound);
                jsonData[i].Read("spinupsound", ref items[i].mSpinUpSound);
                jsonData[i].Read("spinupvol", ref items[i].mSpinUpVol);
                jsonData[i].Read("spindownsound", ref items[i].mSpinDownSound);
                jsonData[i].Read("spindownvol", ref items[i].mSpinDownVol);
                jsonData[i].Read("loopsound", ref items[i].mLoopSound);
                jsonData[i].Read("looppitchmin", ref items[i].mLoopPitchMin);
                jsonData[i].Read("looppitchmax", ref items[i].mLoopPitchMax);
                jsonData[i].Read("loopvolmin", ref items[i].mLoopVolMin);
                jsonData[i].Read("loopvolmax", ref items[i].mLoopVolMax);
                jsonData[i].Read("active", ref items[i].mActive);
                jsonData[i].Read("category", ref mCategory);
                jsonData[i].Read("subcatagory", ref mSubCategory);
                jsonData[i].Read("displaymass", ref items[i].mDisplayMass);
                jsonData[i].Read("name", ref items[i].mName);
                jsonData[i].Read("description", ref items[i].mDescription);
                jsonData[i].Read("thumbnail", ref items[i].mThumbnailName);
                jsonData[i].Read("componentprefabname", ref items[i].mPrefabName);
                jsonData[i].Read("attchassis", ref items[i].mAttChassis);
                jsonData[i].Read("mirrorx", ref items[i].mMirrorX);
                jsonData[i].Read("mirrory", ref items[i].mMirrorY);
                jsonData[i].Read("mirrorz", ref items[i].mMirrorZ);
                jsonData[i].Read("mass", ref items[i].mMass);
                jsonData[i].Read("elecsupply", ref items[i].mElecSupply);
                jsonData[i].Read("elecdraw", ref items[i].mElecDraw);
                jsonData[i].Read("airsupply", ref items[i].mAirSupply);
                jsonData[i].Read("airdraw", ref items[i].mAirDraw);
                jsonData[i].Read("dpiblunt", ref items[i].mDpiBlunt);
                jsonData[i].Read("dpipierce", ref items[i].mDpiPierce);
                jsonData[i].Read("dpiflame", ref items[i].mDpiFlame);
                jsonData[i].Read("dpielec", ref items[i].mDpiElec);
                jsonData[i].Read("dpsblunt", ref items[i].mDpsBlunt);
                jsonData[i].Read("dpspierce", ref items[i].mDpsPierce);
                jsonData[i].Read("dpsflame", ref items[i].mDpsFlame);
                jsonData[i].Read("dpselec", ref items[i].mDpsElec);
                jsonData[i].Read("hpfactblunt", ref items[i].mHpFactBlunt);
                jsonData[i].Read("hpfactpierce", ref items[i].mHpFactPierce);
                jsonData[i].Read("hpfactflame", ref items[i].mHpFactFlame);
                jsonData[i].Read("hpfactelec", ref items[i].mHpFactElec);
                jsonData[i].Read("hitpoints", ref items[i].mHitPoints);
                jsonData[i].Read("uispecial", ref items[i].mUISpecial);
                jsonData[i].Read("attachsound", ref items[i].mAttachSound);
                jsonData[i].Read("spinupsound", ref items[i].mSpinUpSound);
                jsonData[i].Read("spinupvol", ref items[i].mSpinUpVol);
                jsonData[i].Read("spindownsound", ref items[i].mSpinDownSound);
                jsonData[i].Read("spindownvol", ref items[i].mSpinDownVol);
                jsonData[i].Read("loopsound", ref items[i].mLoopSound);
                jsonData[i].Read("looppitchmin", ref items[i].mLoopPitchMin);
                jsonData[i].Read("looppitchmax", ref items[i].mLoopPitchMax);
                jsonData[i].Read("loopvolmin", ref items[i].mLoopVolMin);
                jsonData[i].Read("loopvolmax", ref items[i].mLoopVolMax);
                items[i].mCategory    = (ComponentInfo.CATEGORY)mCategory;
                items[i].mSubCategory = (ComponentInfo.CATEGORY)mSubCategory;
            }

            Type              type     = typeof(ComponentInfoList);
            FieldInfo         info     = type.GetField("_instance", BindingFlags.NonPublic | BindingFlags.Static);
            ComponentInfoList infoList = info.GetValue(null) as ComponentInfoList;

            Debug.Log(infoList);

            ComponentInfo[] oldItems = infoList.mItems;
            infoList.mItems = new ComponentInfo[oldItems.Length + items.Length];
            for (int i = 0; i < infoList.mItems.Length; i++)
            {
                if (i < oldItems.Length)
                {
                    infoList.mItems[i] = oldItems[i];
                }
                else
                {
                    infoList.mItems[i] = items[i - oldItems.Length];
                }
            }
        }