Beispiel #1
0
		public static AssemblyPatch ParseFromJSON(JSON.Object obj)
		{
			var patch = new AssemblyPatch();

			patch.TargetAssembly = Reflection.AssemblyPatcher.GetPatcher(obj["TargetAssembly"].Str);

			patch.FileName = obj["TargetAssembly"].Str;

			if (obj.ContainsKey("Instructions")) {
				foreach (var inst in obj["Instructions"].Array) {
					var instruction = (AssemblyInstruction)AssemblyInstruction.ParseFromJSON(inst.Obj);

					if (instruction.InstructionType == AssemblyInstruction.EInstructionType.CreateType) {
						MainClass.LogLine("-> Creating type: " + instruction.Name);
						patch.TargetAssembly.CreateType(instruction.Name);
					}

					patch.Instructions.Add(instruction);
				}
			}

			foreach (var typ in obj["Types"].Obj) {
				var typePatch = TypePatch.ParseFromJSON(typ.Value.Obj, typ.Key, patch.TargetAssembly);
				patch.Patches.Add(typePatch);
			}
			return patch;
		}
Beispiel #2
0
    public static void Save(JSON json, string fileName, int encriptionKey = 0)
    {
        if (!json.ContainsKey(VersionKey))
        {
            throw new Exception("File without version code");
        }

        if (json.GetInt(VersionKey) > CurrentVersion)
        {
            throw new Exception("File version is newer than this one");
        }

        if (json.GetInt(VersionKey) < CurrentVersion)
        {
            UpdateSave(ref json);
        }

        Debug.Log(json.CreatePrettyString());

        string rawData = json.CreatePrettyString();

        if (encriptionKey != 0)
        {
            rawData = SecureHelper.EncryptDecrypt(rawData, encriptionKey);
        }

        SaveLoadManager.SaveText(fileName, rawData);
    }
Beispiel #3
0
		new internal static BasePatch ParseFromJSON(JSON.Object obj, params object[] args)
		{
			var targetType = args[0] as Reflection.TypePatcher;

			var patch = new MethodPatch();

			if (obj.ContainsKey("TargetMethodSigniture"))
				patch.TargetMethod = targetType.GetMethod(obj["TargetMethod"].Str, obj["TargetMethodSigniture"].Str);
			else
				patch.TargetMethod = targetType.GetMethod(obj["TargetMethod"].Str);

			MainClass.LogLine(" + " + patch.TargetMethod.methodDefinition.GetSigniture());

			foreach (JSON.Value instru in obj["Instructions"].Array) {
				var instrupatch = MethodInstruction.ParseFromJSON(instru.Obj, patch);

				switch (instrupatch.OperandType) {
					case EOperandType.Instruction:
						instrupatch.Operand = patch.TargetMethod.IlProc.Body.Instructions[instrupatch.ParamOrVarOffset];
						break;
					case EOperandType.Variable:
						instrupatch.Operand = patch.TargetMethod.IlProc.Body.Variables[instrupatch.ParamOrVarOffset];
						break;
					case EOperandType.Parameter:
						instrupatch.Operand = patch.TargetMethod.IlProc.Body.Method.Parameters[instrupatch.ParamOrVarOffset];
						break;
				}

				patch.Instructions.Add(instrupatch);
			}

			return patch;
		}
Beispiel #4
0
    public static void LoadData(this ISaveAsJson source, JSON mainData)
    {
        if (!mainData.ContainsKey(source.Key))
        {
            return;
        }
        JSON loadData = mainData.GetJSON(source.Key);

        if (!mainData.ContainsKey(source.Key))
        {
            return;
        }
        if (IsOldVersion(source, loadData))
        {
            source.UpdateSaveData(loadData);
        }
        source.Load(loadData);
    }
    public void Load(JSON data)
    {
        if (!data.ContainsKey("ClipName"))
        {
            return;
        }
        string clipName = data.GetString("ClipName");

        SwapAnimationClip(CharacterPoseManager.Get(clipName));
    }
Beispiel #6
0
        private void ParseFBUserData(string jsonDataFromFbAsString)
        {
            // Parse string data received from FB to JSON
            // Second (optional) parameter is ID for debug purposes. If anything fails in JSON parsing, this debug id is added to exception message.
            // This will greatly help tracking problems in projects where lots of JSON objects are handled and stack trace is not necessary available (like in production builds).
            // This same debug id will be attached also to resulting JSON object so that if any exceptions happens afterwards (for example when reading values from JSON),
            // thos eexceptions will have this ID printed out also.
            JSON fbUserJSON = JSON.ParseString(jsonDataFromFbAsString, "FBUserJSON");

            // Set JSON protected (read only) so no accidental changes are made to it
            // In this example this is of course somewhat pointless since JSON is only used locally in this method and not passed forward to anywhere
            // But very handy if this JSON is paased forward and you want to make sure no other code accidentally changes anything
            fbUserJSON.SetProtected();

            // Add this JSON object to runtime debug in Unity Editor
            // After this call, you can see content of this JSON object in Unity Editor, by choosing "Window -> Total JSON -> JSON Runtime Debug" from Unity menu
            fbUserJSON.DebugInEditor("FB User JSON");

            // Get user basic info
            string userId = fbUserJSON.GetString("id");
            string name   = fbUserJSON.GetString("name");

            // Get user picture info
            JSON   userPictureData     = fbUserJSON.GetJSON("picture").GetJSON("data");
            bool   isPictureSilhouette = userPictureData.GetBool("is_silhouette");
            string pictureUrl          = userPictureData.GetString("url");

            // Get country
            string country;

            try {
                // This code just assumes data contains location information, which it in real life doesn't necessary do
                country = fbUserJSON.GetJSON("location").GetJSON("location").GetString("country");
            }
            catch (JSONKeyNotFoundException) {             // The lazy way to handle possibly missing information
                country = "Unknown";
            }

            // Get currency USD exchange
            decimal?usdExchange = null;

            if (fbUserJSON.ContainsKey("currency"))
            {
                JSON userCurrency = fbUserJSON.GetJSON("currency");
                usdExchange = userCurrency.GetJNumber("usd_exchange").AsDecimal();
            }

            // Print out what we got
            Debug.Log("userId = " + userId);
            Debug.Log("name = " + name);
            Debug.Log("isPictureSilhouette = " + isPictureSilhouette);
            Debug.Log("pictureUrl = " + pictureUrl);
            Debug.Log("country = " + country);
            Debug.Log("usdExchange = " + usdExchange);
        }
Beispiel #7
0
    public static bool IsOldVersion(this ISaveAsJson source, JSON data)
    {
        if (!data.ContainsKey(VersionKey))
        {
            throw new KeyNotFoundException($"El archivo NO contiene la VersionKey '{VersionKey}' para el tipo de archivo: {source.GetType()}");
        }

        int fileVersion = data.GetInt(VersionKey);

        return(fileVersion < source.Version);
    }
 public void LoadSaveData(JSON json)
 {
     if (json.ContainsKey("value"))
     {
         Value.LoadSaveData(json.Get("value") as JSON);
     }
     else
     {
         Debug.LogWarning($"No se pudo cargar 'value' en {this}");
     }
 }
		public static FieldInstruction ParseFromJSON(JSON.Object obj)
		{
			var instruction = new FieldInstruction();

			instruction.InstructionType = (EInstructionType)Enum.Parse(typeof(EInstructionType),
																	   obj["InstructionType"].Str,
																	   true);
			if (obj.ContainsKey("ValueSource")) {
				instruction.ValueSource = (EValueSource)Enum.Parse(typeof(EValueSource), obj["ValueSource"].Str, true);

				switch (instruction.ValueSource) {
					case EValueSource.StaticField:
					case EValueSource.TypeConstruction:
						throw new NotImplementedException(instruction.ValueSource.ToString() + " as ValueSource is not yet implemented.");

					case EValueSource.Custom:
						instruction.Value = obj.ContainsKey("Value") ? obj["Value"].value : null;
						break;

					case EValueSource.PreDefined:
						if (obj["Value"].Str == "%PatcherVersion%") {
							instruction.Value = MainClass.Version;
						}
						break;
				}
			}
			instruction.Public = obj.ContainsKey("Public") ? obj["Public"].Boolean : instruction.Public;
			instruction.Static = obj.ContainsKey("Static") ? obj["Static"].Boolean : instruction.Static;
			instruction.ReadOnly = obj.ContainsKey("ReadOnly") ? obj["ReadOnly"].Boolean : instruction.ReadOnly;
			instruction.Constant = obj.ContainsKey("Constant") ? obj["Constant"].Boolean : instruction.Constant;

			return instruction;
		}
Beispiel #10
0
		new internal static BasePatch ParseFromJSON(JSON.Object obj, params object[] args)
		{
			var targettype = args[0] as string;
			var targetAssembly = args[1] as Reflection.AssemblyPatcher;

			var patch = new TypePatch();

			patch.TargetType = targetAssembly.GetType(targettype);

			if (obj.ContainsKey("Instructions")) {
				foreach (JSON.Value instru in obj["Instructions"].Array) {
					var instruction = TypeInstruction.ParseFromJSON(instru.Obj);

					if (instruction.InstructionType == TypeInstruction.EInstructionType.CreateMethod)
						throw new NotImplementedException("Creating method is not yet a supported feature.");

					if (instruction.InstructionType == TypeInstruction.EInstructionType.CreateField) {
						patch.TargetType.CreateField(instruction.Name);
					}

					patch.Instructions.Add(instruction);
				}
			}

			MainClass.LogLine(targettype);
			if (obj.ContainsKey("Methods")) {
				foreach (JSON.Value met in obj["Methods"].Array) {
					var methodPatch = MethodPatch.ParseFromJSON(met.Obj, patch.TargetType);
					patch.Patches.Add(methodPatch);
				}
			}
			if (obj.ContainsKey("Fields")) {
				foreach (JSON.Value fld in obj["Fields"].Array) {
					var fieldPatch = FieldPatch.ParseFromJSON(fld.Obj, patch.TargetType);
					patch.Patches.Add(fieldPatch);
				}
			}
			return patch;
		}
Beispiel #11
0
    // this has to be called per scenario at start of the scenario, as it creates the basic Empty object for a scenario with its key structures
    // better to be called after the PlayerID is set from GameManager, as this attempts to find an existing User file with same date to modify , or else it create a new one
    public bool SetScenarioMasterLogObject(string key)
    {
        if (LogData == null)
        {
            Init();
        }

        if (key != null && key != "")
        {
            currentSecnarioMasterKey = key;
            currentTAS = 0;


            if (currentSecnarioMasterKey != "")
            {
                // initiate basics Log object Arrays
                JArray TASData                   = new JArray();
                JArray PlayerLookingAtData       = new JArray();
                JArray PlayerMovedToData         = new JArray();
                JArray PlayerSelectedStudentData = new JArray();
                JArray StudentLookingAtData      = new JArray();
                JArray StudentAnimationsData     = new JArray();
                JArray StudentSetupData          = new JArray();


                JSON ScenarioMasterObject = new JSON();

                JSON TeacherActionsObject = new JSON();
                JSON PlayerActionsObject  = new JSON();
                JSON StudentActionsObject = new JSON();

                JSON GettingToKnowYourClassObject = new JSON();

                JSON InitialSituationObject = new JSON();

                // Populate TeacherActions
                TeacherActionsObject.AddOrReplace("TASData", TASData);

                // Populate PlayerActions
                PlayerActionsObject.AddOrReplace("LookingAt", PlayerLookingAtData);
                PlayerActionsObject.AddOrReplace("MovedTo", PlayerMovedToData);
                PlayerActionsObject.AddOrReplace("SelectedStudent", PlayerSelectedStudentData);

                // Populate StudentActions
                StudentActionsObject.AddOrReplace("LookingAt", StudentLookingAtData);
                StudentActionsObject.AddOrReplace("Animations", StudentAnimationsData);

                // Populate GettingToKnowYourClassObject
                GettingToKnowYourClassObject.AddOrReplace("start1", "");
                GettingToKnowYourClassObject.AddOrReplace("end1", "");

                // Populate InitialSituationObject
                InitialSituationObject.AddOrReplace("start2", "");
                InitialSituationObject.AddOrReplace("end2", "");

                // Add all the above and StudentSetup to the Current Scenario Object
                ScenarioMasterObject.AddOrReplace("GettingToKnowYourClass", GettingToKnowYourClassObject);
                ScenarioMasterObject.AddOrReplace("InitialSituation", InitialSituationObject);

                ScenarioMasterObject.AddOrReplace("TeacherActions", TeacherActionsObject);
                ScenarioMasterObject.AddOrReplace("StudentSetup", StudentSetupData);
                ScenarioMasterObject.AddOrReplace("PlayerActions", PlayerActionsObject);
                ScenarioMasterObject.AddOrReplace("StudentActions", StudentActionsObject);



                if (LogData.ContainsKey(currentSecnarioMasterKey))
                {
                    LogData.AddOrReplace(currentSecnarioMasterKey, ScenarioMasterObject);
                }
                else
                {
                    LogData.Add(currentSecnarioMasterKey, ScenarioMasterObject);
                }
            }
            return(true);
        }
        currentSecnarioMasterKey = "";
        Debug.LogAssertion("Key for New attepmt to set Scenario Master Log Object is empty or null");
        return(false);
    }
    private void recursiveAddUI(JSON.Object json, GameObject parent)
    {
        var go = new GameObject(json.GetString("name", "AddUI CreatedPanel"));
        if (parent == null) {
            var parentName = json.GetString("parent", "Overlay");

            parent = findServerCreatedPanel(parentName); //Find parent in serverCreatedUI

            if (parent == null) {
                parent = findClientPanel(parentName);//Find parent in the client UI

                if (parent == null)
                    return; //Parent doesn't exists

                //Add the GameObject to serverCreatedUI since it's a new UI and destroy old one if it exists
                if(go != null)
                    DestroyPanel(go.name, true);
                serverCreatedUI.Add(go);
            }
        }

        generateElement(go, json);

        go.transform.SetParent(parent.transform, false);

        if (json.ContainsKey("childs"))
            foreach (var child in json.GetArray("childs")) {
                recursiveAddUI(child.Obj, go);
            }
    }
 private void GraphicComponentCreated(UnityEngine.UI.Graphic c, JSON.Object obj)
 {
     if (obj.ContainsKey("fadeIn")) {
         c.canvasRenderer.SetAlpha(0f);
         c.CrossFadeAlpha(1f, obj.GetFloat("fadeIn", 0), true);
     }
 }
    private void generateElement(GameObject go, JSON.Object json)
    {
        var rt = go.GetComponent<RectTransform>();
        if (rt) {
            rt.anchorMin = new Vector2(0, 0);
            rt.anchorMax = new Vector2(1, 1);
            rt.offsetMin = new Vector2(0, 0);
            rt.offsetMax = new Vector2(1, 1);
        }

        foreach (var component in json.GetArray( "components" )) {
            CreateComponents(go, component.Obj);
        }

        if (json.ContainsKey("fadeOut")) {
            go.AddComponent<FadeOut>().duration = json.GetFloat("fadeOut", 0);
        }
    }
    private void CreateComponents(GameObject go, JSON.Object obj)
    {
        //
        // This is the 'stupid' but 'safe & predictable way of doing this.
        //
        switch (obj.GetString("type", "UnityEngine.UI.Text")) {
            case "UnityEngine.UI.Text":
                {
                    var c = go.AddComponent<UnityEngine.UI.Text>();
                    c.text = obj.GetString("text", "Text");
                    c.fontSize = obj.GetInt("fontSize", 14);
                    c.font = FileSystem.Load<Font>("Assets/Content/UI/Fonts/" + obj.GetString("font", "RobotoCondensed-Bold.ttf"));
                    c.alignment = (TextAnchor)System.Enum.Parse(typeof(TextAnchor), obj.GetString("align", "UpperLeft"));
                    c.color = ColorEx.Parse(obj.GetString("color", "1.0 1.0 1.0 1.0"));
                    GraphicComponentCreated(c, obj);
                    break;
                }

            case "UnityEngine.UI.Image":
                {
                    var c = go.AddComponent<UnityEngine.UI.Image>();
                    c.sprite = FileSystem.Load<Sprite>(obj.GetString("sprite", "Assets/Content/UI/UI.Background.Tile.psd"));
                    c.material = FileSystem.Load<Material>(obj.GetString("material", "Assets/Icons/IconMaterial.mat"));
                    c.color = ColorEx.Parse(obj.GetString("color", "1.0 1.0 1.0 1.0"));
                    c.type = (UnityEngine.UI.Image.Type)System.Enum.Parse(typeof(UnityEngine.UI.Image.Type), obj.GetString("imagetype", "Simple"));

                    if (obj.ContainsKey("png")) {
                        PngGraphicLoadRequested(c, uint.Parse(obj.GetString("png")));
                    }

                    GraphicComponentCreated(c, obj);

                    break;
                }

            case "UnityEngine.UI.RawImage":
                {
                    var c = go.AddComponent<UnityEngine.UI.RawImage>();
                    c.texture = FileSystem.Load<Texture>(obj.GetString("sprite", "Assets/Icons/rust.png"));
                    c.color = ColorEx.Parse(obj.GetString("color", "1.0 1.0 1.0 1.0"));

                    if (obj.ContainsKey("material")) {
                        c.material = FileSystem.Load<Material>(obj.GetString("material"));
                    }

                    if (obj.ContainsKey("url")) {
                        StartCoroutine(LoadTextureFromWWW(c, obj.GetString("url")));
                    }

                    if (obj.ContainsKey("png")) {
                        PngGraphicLoadRequested(c, uint.Parse(obj.GetString("png")));
                    }

                    GraphicComponentCreated(c, obj);

                    break;
                }

            case "UnityEngine.UI.Button":
                {
                    var c = go.AddComponent<UnityEngine.UI.Button>();

                    if (obj.ContainsKey("command")) {
                        var cmd = obj.GetString("command");
                        c.onClick.AddListener(() => {
                            ConsoleSystem.ClientRunOnServer(cmd);
                        });
                    }

                    if (obj.ContainsKey("close")) {
                        var pnlName = obj.GetString("close");
                        c.onClick.AddListener(() => {
                            DestroyPanel(pnlName);
                        });
                    }

                    // bg image
                    var img = go.AddComponent<UnityEngine.UI.Image>();
                    img.sprite = FileSystem.Load<Sprite>(obj.GetString("sprite", "Assets/Content/UI/UI.Background.Tile.psd"));
                    img.material = FileSystem.Load<Material>(obj.GetString("material", "Assets/Icons/IconMaterial.mat"));
                    img.color = ColorEx.Parse(obj.GetString("color", "1.0 1.0 1.0 1.0"));
                    img.type = (UnityEngine.UI.Image.Type)System.Enum.Parse(typeof(UnityEngine.UI.Image.Type), obj.GetString("imagetype", "Simple"));

                    c.image = img;

                    GraphicComponentCreated(img, obj);

                    break;
                }

            case "UnityEngine.UI.Outline":
                {
                    var c = go.AddComponent<UnityEngine.UI.Outline>();
                    c.effectColor = ColorEx.Parse(obj.GetString("color", "1.0 1.0 1.0 1.0"));
                    c.effectDistance = Vector2Ex.Parse(obj.GetString("distance", "1.0 -1.0"));
                    c.useGraphicAlpha = obj.ContainsKey("useGraphicAlpha");
                    break;
                }
            case "NeedsCursor":
                {
                    go.AddComponent<NeedsCursor>();
                    break;
                }

            case "RectTransform":
                {
                    var rt = go.GetComponent<RectTransform>();
                    if (rt) {
                        rt.anchorMin = Vector2Ex.Parse(obj.GetString("anchormin", "0.0 0.0"));
                        rt.anchorMax = Vector2Ex.Parse(obj.GetString("anchormax", "1.0 1.0"));
                        rt.offsetMin = Vector2Ex.Parse(obj.GetString("offsetmin", "0.0 0.0"));
                        rt.offsetMax = Vector2Ex.Parse(obj.GetString("offsetmax", "1.0 1.0"));
                    }
                    break;
                }
        }
    }
Beispiel #16
0
        /// <summary>
        /// Parse JSON string to key value pairs
        /// </summary>
        /// <param name="rawjson">JSON String</param>
        /// <returns>Key value pairs data</returns>
        public static JSON Parse(string rawjson)
        {
            JSON          outdict            = new JSON();
            StringBuilder keybufferbuilder   = new StringBuilder();
            StringBuilder valuebufferbuilder = new StringBuilder();
            StringReader  bufferreader       = new StringReader(rawjson);

            int  s             = 0;
            bool reading       = false;
            bool inside_string = false;
            bool reading_value = false;

            //break at end (returns -1)
            while (s >= 0)
            {
                s = bufferreader.Read();
                //opening of json
                if (!reading)
                {
                    if ((char)s == '{' && !inside_string && !reading)
                    {
                        reading = true;
                    }
                    continue;
                }
                else
                {
                    //if we find a quote and we are not yet inside a string, advance and get inside
                    if (!inside_string)
                    {
                        //read past the quote
                        if ((char)s == '\"')
                        {
                            inside_string = true;
                        }
                        continue;
                    }
                    if (inside_string)
                    {
                        //if we reached the end of the string
                        if ((char)s == '\"')
                        {
                            inside_string = false;
                            s             = bufferreader.Read(); //advance pointer
                            if ((char)s == ':')
                            {
                                reading_value = true;
                                continue;
                            }
                            if (reading_value && (char)s == ',')
                            {
                                //we know we just ended the line, so put itin our dictionary
                                if (!outdict.ContainsKey(keybufferbuilder.ToString()))
                                {
                                    outdict.Add(keybufferbuilder.ToString(), valuebufferbuilder.ToString());
                                }
                                //and clear the buffers
                                keybufferbuilder.Clear();
                                valuebufferbuilder.Clear();
                                reading_value = false;
                            }
                            if (reading_value && (char)s == '}')
                            {
                                //we know we just ended the line, so put itin our dictionary
                                if (!outdict.ContainsKey(keybufferbuilder.ToString()))
                                {
                                    outdict.Add(keybufferbuilder.ToString(), valuebufferbuilder.ToString());
                                }
                                //and clear the buffers
                                keybufferbuilder.Clear();
                                valuebufferbuilder.Clear();
                                reading_value = false;
                                reading       = false;
                                break;
                            }
                        }
                        else
                        {
                            if (reading_value)
                            {
                                valuebufferbuilder.Append((char)s);
                                continue;
                            }
                            else
                            {
                                keybufferbuilder.Append((char)s);
                                continue;
                            }
                        }
                    }
                    else
                    {
                        switch ((char)s)
                        {
                        case ':':
                            reading_value = true;
                            break;

                        default:
                            if (reading_value)
                            {
                                valuebufferbuilder.Append((char)s);
                            }
                            else
                            {
                                keybufferbuilder.Append((char)s);
                            }
                            break;
                        }
                    }
                }
            }
            return(outdict);
        }
		public static MethodInstruction ParseFromJSON(JSON.Object instru, MethodPatch targetMethod)
		{
			var patch = new MethodInstruction();

			patch.InstructionType = (EInstructionType)Enum.Parse(typeof(EInstructionType),
																 instru["InstructionType"].Str);

			switch (patch.InstructionType) {
				case EInstructionType.SetVisibility:
					patch.Public = instru.ContainsKey("Public") ? instru["Public"].Boolean : patch.Public;
					break;

				case EInstructionType.RemoveRange:
					patch.RemoveEnd = Int32.Parse(instru["RemoveEnd"].Str);
					goto case EInstructionType.RemoveAt;

				case EInstructionType.RemoveAt:
					patch.RemoveStart = Int32.Parse(instru["RemoveStart"].Str);
					goto case EInstructionType.Clear;

				case EInstructionType.Clear:
					return patch;

				case EInstructionType.InsertAfter:
				case EInstructionType.InsertBefore:
					patch.InsertOffset = Int32.Parse(instru["InsertOffset"].Str);
					break;
			}

			patch.Instruction = Instruction.Create(OpCodes.Ret);

			patch.OpCode = (OpCode)typeof(OpCodes).GetField(instru["OpCode"].Str).GetValue(typeof(OpCodes));

			patch.OperandType = (EOperandType)Enum.Parse(typeof(EOperandType), instru["OperandType"].Str);

			switch (patch.OperandType) {
				case EOperandType.Type:
					patch.Operand = Reflection.AssemblyPatcher.GetPatcher(instru["TargetAssembly"].Str).GetType(instru["TargetType"].Str).typeDefinition;
					break;

				case EOperandType.Method:
					if (instru.ContainsKey("TargetMethodSigniture"))
						patch.Operand = targetMethod.TargetMethod.rootAssemblyPatcher.mainModule.Import(Reflection.AssemblyPatcher.GetPatcher(instru["TargetAssembly"].Str).GetType(instru["TargetType"].Str).GetMethod(instru["TargetMethod"].Str,
																																																						instru["TargetMethodSigniture"].Str).methodDefinition);
					else
						patch.Operand = targetMethod.TargetMethod.rootAssemblyPatcher.mainModule.Import(Reflection.AssemblyPatcher.GetPatcher(instru["TargetAssembly"].Str).GetType(instru["TargetType"].Str).GetMethod(instru["TargetMethod"].Str).methodDefinition);
					break;

				case EOperandType.Field:
					patch.Operand = Reflection.AssemblyPatcher.GetPatcher(instru["TargetAssembly"].Str).GetType(instru["TargetType"].Str).GetField(instru["TargetField"].Str);
					break;

				case EOperandType.Parameter:
				case EOperandType.Variable:
				case EOperandType.Instruction:
					patch.ParamOrVarOffset = Int32.Parse(instru["ParamVarOffset"].Str);
					break;

				case EOperandType.SByte:
					patch.Operand = SByte.Parse(instru["Operand"].Str);
					break;

				case EOperandType.Byte:
					patch.Operand = Byte.Parse(instru["Operand"].Str);
					break;

				case EOperandType.Int:
					patch.Operand = Int32.Parse(instru["Operand"].Str);
					break;

				case EOperandType.Float:
					patch.Operand = Single.Parse(instru["Operand"].Str);
					break;

				case EOperandType.Long:
					patch.Operand = Int64.Parse(instru["Operand"].Str);
					break;

				case EOperandType.Double:
					patch.Operand = Double.Parse(instru["Operand"].Str);
					break;

				case EOperandType.String:
					patch.Operand = instru["Operand"].Str;
					break;
			}

			return patch;
		}
Beispiel #18
0
        private void Test1()
        {
            // Create empty JSON object "{}"
            JSON jsonObject = new JSON();

            // Add this JSON object to debug
            // After this call, you can see content of this JSON object in Unity Editor, by choosing "Window -> Total JSON -> JSON Runtime Debug" from Unity menu
            // For debug/development purposes it is very handy to see contents of JSON objects while application is running in editor
            jsonObject.DebugInEditor("CreateAndModify Test JSON");

            Debug.Log("Note! You can see the content of selected JSON objects while application is running by choosing \"Window -> Total JSON -> JSON Runtime Debug\" from Unity menu");

            // Add basic things
            jsonObject.Add("text", "Hello World!");
            jsonObject.Add("number", 42);
            jsonObject.Add("truth", true);
            jsonObject.Add("nullText", null);
            jsonObject.Add("numberArray", new int[] { 1, 2, 4, 8 });

            // Print out
            Debug.Log(jsonObject.CreateString());             // {"text":"Hello World!","number":42,"truth":true,"nullText":null,"numberArray":[1,2,4,8]}

            // Do some changes
            jsonObject.Remove("number");
            jsonObject.Replace("truth", false);

            // Loop through all the keys and print out debug info of all values
            Debug.Log("Info of all the values:");
            foreach (string key in jsonObject.Keys)
            {
                Debug.Log(key + ": " + jsonObject[key]);
            }

            // Loop through all the keys and print out all values in JSON formatted strings
            Debug.Log("Content of all the values:");
            foreach (string key in jsonObject.Keys)
            {
                Debug.Log(key + " -> " + jsonObject[key].CreateString());
            }

            // Get and print out some values
            Debug.Log("Print outs of some values:");
            Debug.Log(jsonObject.GetString("text"));            // "Hello World!"
            Debug.Log(jsonObject.ContainsKey("number"));        // false
            Debug.Log(jsonObject.GetBool("truth"));             // false
            Debug.Log(jsonObject.GetString("nullText"));        // Null

            // Do some changes to array
            JArray jsonArray = jsonObject.GetJArray("numberArray"); // Contains ints 1,2,4,8

            jsonArray.Add(16);                                      // 1,2,4,8,16
            jsonArray.RemoveAt(1);                                  // 1,4,8,16
            jsonArray.InsertAt(3, 0);                               // 1,4,8,0,16
            jsonArray.ReplaceAt(2, -1);                             // 1,4,-1,0,16

            // Print out some array values
            Debug.Log("Array length: " + jsonArray.Length);            // 5
            Debug.Log("Fifth element as int: " + jsonArray.GetInt(4)); // 16

            // Since all values in array are numbers (JNumber) and they all fit to c# int values, array can be also copied to system int array
            int[] systemIntArray = jsonArray.AsIntArray();
            // Print out values
            Debug.Log("Second element as int: " + systemIntArray[1]);           // 4
        }