This chunk type holds text strings. The first two bytes correspond to the format code, of which there are four types. Some chunks in the game do not specify any data after the version number, so be sure to implement bounds checking.
Inheritance: IffChunk
コード例 #1
0
 public OpStaticNamedPropertyProvider(STR strRes, int startValue)
 {
     Map = new Dictionary<int, string>();
     for (int i=0; i<strRes.Length; i++)
     {
         Map.Add(i + startValue, strRes.GetString(i));
     }
 }
コード例 #2
0
ファイル: VarAnimSelect.cs プロジェクト: RHY3756547/FreeSO
        public VarAnimSelect(STR animTable, int oldSel)
            : this()
        {
            AnimDisplay.ShowAnim("a2o-standing-loop");
            RefreshAllList();
            AnimTable = animTable;
            SelectedAnim = oldSel;
            RefreshAnimTable();
            if (MyList.Items.Count > 0) MyList.SelectedIndex = oldSel;

            Text = "Select Animation - " + AnimTable.ChunkLabel + " (#" + AnimTable.ChunkID + ")";
        }
コード例 #3
0
        public static VMPrimitiveExitCode ExecuteGeneric(VMStackFrame context, VMPrimitiveOperand args, STR table)
        {
            var operand = (VMDialogOperand)args;
            var curDialog = (VMDialogResult)context.Thread.BlockingState;
            if (curDialog == null)
            {
                VMDialogHandler.ShowDialog(context, operand, table);

                if ((operand.Flags & VMDialogFlags.Continue) == 0)
                {
                    context.Thread.BlockingState = new VMDialogResult
                    {
                        Type = operand.Type,
                        HasDisplayed = true
                    };
                    return VMPrimitiveExitCode.CONTINUE_NEXT_TICK;
                }
                else return VMPrimitiveExitCode.GOTO_TRUE;
            }
            else
            {
                if (curDialog.Responded || curDialog.WaitTime > DIALOG_MAX_WAITTIME)
                {
                    context.Thread.BlockingState = null;
                    context.VM.SignalDialog(null);
                    switch (curDialog.Type)
                    {
                        default:
                        case VMDialogType.Message:
                            return VMPrimitiveExitCode.GOTO_TRUE;
                        case VMDialogType.YesNo:
                            return (curDialog.ResponseCode == 0) ? VMPrimitiveExitCode.GOTO_TRUE : VMPrimitiveExitCode.GOTO_FALSE;
                        case VMDialogType.YesNoCancel:
                            if (curDialog.ResponseCode > 1)
                            {
                                context.Thread.TempRegisters[((operand.Flags & VMDialogFlags.UseTemp1) > 0) ? 1 : 0] = (short)((curDialog.ResponseCode - 1) % 2);
                                return VMPrimitiveExitCode.GOTO_FALSE;
                            }
                            else return VMPrimitiveExitCode.GOTO_TRUE;
                        case VMDialogType.TextEntry:
                            //todo: filter profanity, limit name length
                            //also verify behaviour.
                            if ((curDialog.ResponseText ?? "") != "")
                                ((VMAvatar)context.StackObject).Name = curDialog.ResponseText;
                            return VMPrimitiveExitCode.GOTO_TRUE;
                        case VMDialogType.NumericEntry:
                            int number;
                            if (!int.TryParse(curDialog.ResponseText, out number)) return VMPrimitiveExitCode.GOTO_FALSE;

                            var tempNumber = ((operand.Flags & VMDialogFlags.UseTemp1) > 0) ? 1 : 0;

                            if ((operand.Flags & VMDialogFlags.UseTempXL) > 0) context.Thread.TempXL[tempNumber] = number;
                            else context.Thread.TempRegisters[tempNumber] = (short)number;
                            return VMPrimitiveExitCode.GOTO_TRUE;
                    }
                }
                else
                {
                    if (!curDialog.HasDisplayed)
                    {
                        VMDialogHandler.ShowDialog(context, operand, table);
                        curDialog.HasDisplayed = true;
                    }
                    return VMPrimitiveExitCode.CONTINUE_NEXT_TICK;
                }
            }
        }
コード例 #4
0
ファイル: VMAvatar.cs プロジェクト: Daribon/FreeSO
        public VMAvatar(GameObject obj)
            : base(obj)
        {
            Name = "Sim";

            BodyStrings = Object.Resource.Get<STR>(Object.OBJ.BodyStringID);

            SetAvatarType(BodyStrings);
            SkinTone = AppearanceType.Light;

            if (UseWorld)
            {
                WorldUI = new AvatarComponent();
                var avatarc = (AvatarComponent)WorldUI;
                avatarc.Avatar = Avatar;
            }

            for (int i = 0; i < 16; i++)
            {
                MotiveChanges[i] = new VMMotiveChange();
                MotiveChanges[i].Motive = (VMMotive)i;
            }
        }
コード例 #5
0
ファイル: VMAvatar.cs プロジェクト: Daribon/FreeSO
        public void SetAvatarType(STR data)
        {
            if (data == null)
            {
                AvatarType = VMAvatarType.Adult;
            }
            else
            {
                var type = data.GetString(0);
                if (type == "adult") AvatarType = VMAvatarType.Adult;
                else if (type == "child") AvatarType = VMAvatarType.Child;
                else if (type == "cat") AvatarType = VMAvatarType.Cat;
                else if (type == "dog") AvatarType = VMAvatarType.Dog;
            }

            switch (AvatarType)
            {
                case VMAvatarType.Adult:
                    Avatar = new SimAvatar(FSO.Content.Content.Get().AvatarSkeletons.Get("adult.skel"));
                    Avatar.Head = FSO.Content.Content.Get().AvatarOutfits.Get("mah010_baldbeard01.oft"); //default to bob newbie, why not
                    Avatar.Body = FSO.Content.Content.Get().AvatarOutfits.Get("mab002_slob.oft");
                    Avatar.Handgroup = Avatar.Body;
                    break;
                case VMAvatarType.Cat:
                    var skel = FSO.Content.Content.Get().AvatarSkeletons.Get("cat.skel");
                    Avatar = new SimAvatar(skel);
                    Avatar.Body = FSO.Content.Content.Get().AvatarOutfits.Get("uaa002cat_calico.oft");
                    break;
                case VMAvatarType.Dog:
                    Avatar = new SimAvatar(FSO.Content.Content.Get().AvatarSkeletons.Get("dog.skel"));
                    Avatar.Body = FSO.Content.Content.Get().AvatarOutfits.Get("uaa012dog_scottish.oft"); //;)
                    break;
            }
        }
コード例 #6
0
ファイル: VMAvatar.cs プロジェクト: Daribon/FreeSO
        public void SetAvatarBodyStrings(STR data, VMContext context)
        {
            if (data == null) return;

            try
            {
                var body = data.GetString(1);
                var randBody = data.GetString(10);

                if (randBody != "")
                {
                    var bodySpl = randBody.Split(';');
                    DefaultSuits.Daywear = Convert.ToUInt64(bodySpl[context.NextRandom((ulong)bodySpl.Length-1)], 16);
                }
                else if (body != "")
                {
                    DefaultSuits.Daywear = Convert.ToUInt64(body, 16);
                }

                BodyOutfit = DefaultSuits.Daywear;

                var head = data.GetString(2);
                var randHead = data.GetString(9);

                if (randHead != "")
                {
                    var headSpl = randHead.Split(';');
                    HeadOutfit = Convert.ToUInt64(headSpl[context.NextRandom((ulong)headSpl.Length-1)], 16);
                }
                else if (head != "")
                {
                    HeadOutfit = Convert.ToUInt64(head, 16);
                }
            }
            catch
            {
                //head or body invalid, resort to default.
            }

            var gender = data.GetString(12);
            var genVar = (int)VMPersonDataVariable.Gender;

            if (gender.Equals("male", StringComparison.InvariantCultureIgnoreCase)) PersonData[genVar] = 0;
            else if (gender.Equals("female", StringComparison.InvariantCultureIgnoreCase)) PersonData[genVar] = 1;
            else if (gender.Equals("dogmale", StringComparison.InvariantCultureIgnoreCase)) PersonData[genVar] = 8;
            else if (gender.Equals("dogfemale", StringComparison.InvariantCultureIgnoreCase)) PersonData[genVar] = 9;
            else if (gender.Equals("catmale", StringComparison.InvariantCultureIgnoreCase)) PersonData[genVar] = 16;
            else if (gender.Equals("catfemale", StringComparison.InvariantCultureIgnoreCase)) PersonData[genVar] = 17;

            var names = data.GetString(11);
            if (names != "")
            {
                var nameSpl = names.Split(';');
                Name = nameSpl[context.NextRandom((ulong)nameSpl.Length)];
            }

            PersonData[(int)VMPersonDataVariable.PersonsAge] = Convert.ToInt16(data.GetString(13));

            var skinTone = data.GetString(14);
            if (skinTone.Equals("lgt", StringComparison.InvariantCultureIgnoreCase)) SkinTone = AppearanceType.Light;
            else if (skinTone.Equals("med", StringComparison.InvariantCultureIgnoreCase)) SkinTone = AppearanceType.Medium;
            else if (skinTone.Equals("drk", StringComparison.InvariantCultureIgnoreCase)) SkinTone = AppearanceType.Dark;
        }
コード例 #7
0
 public OpStaticNamedPropertyProvider(STR strRes)
     : this(strRes, 0)
 {
 }
コード例 #8
0
ファイル: NewObjectDialog.cs プロジェクト: RHY3756547/FreeSO
        private void OKButton_Click(object sender, EventArgs e)
        {
            var name = ChunkLabelEntry.Text;
            var guidT = GUIDEntry.Text;
            uint guid;
            var objProvider = Content.Content.Get().WorldObjects;
            if (name == "") MessageBox.Show("Name cannot be empty!", "Invalid Object Name");
            else if (guidT == "") MessageBox.Show("GUID cannot be empty!", "Invalid GUID");
            else if (!uint.TryParse(guidT, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out guid))
                MessageBox.Show("GUID is invalid! Make sure it is a hex string of size 8. (eg. 6789ABCD)", "Invalid GUID");
            else
            {
                lock (objProvider.Entries)
                {
                    if (objProvider.Entries.ContainsKey(guid))
                    {
                        MessageBox.Show("This GUID is already being used!", "GUID is Taken!");
                        return;
                    }

                    //OK, it's valid. Now to add it to the objects system...
                    //This is a little tricky because we want to add an object that does not exist yet.
                    //There's a special function just for this! But first, we need an OBJD...

                    var obj = new OBJD()
                    {
                        GUID = guid,
                        ObjectType = OBJDType.Normal,
                        ChunkLabel = name,
                        ChunkID = 1,
                        ChunkProcessed = true,
                        ChunkType = "OBJD",
                        ChunkParent = TargetIff,
                        AnimationTableID = 128
                    };

                    Content.Content.Get().Changes.BlockingResMod(new ResAction(() =>
                    {
                        //find a free space to place the object
                        ushort id = 16807; //todo: why???
                        var list = TargetIff.List<OBJD>();
                        if (list != null)
                        {
                            foreach (var chk in list.OrderBy(x => x.ChunkID))
                            {
                                if (chk.ChunkID == id)
                                    id++;
                            }
                        }
                        obj.ChunkID = id;
                        //add it to the iff file
                        TargetIff.AddChunk(obj);
                    }, obj));

                    if (IsNew)
                    {
                        //add a default animation table, for quality of life reasons

                        var anim = new STR()
                        {
                            ChunkLabel = name,
                            ChunkID = 128,
                            ChunkProcessed = true,
                            ChunkType = "STR#",
                            ChunkParent = TargetIff,
                        };

                        anim.InsertString(0, new STRItem { Value = "", Comment = "" });
                        TargetIff.AddChunk(anim);

                        var filename = TargetIff.RuntimeInfo.Path;
                        Directory.CreateDirectory(Path.GetDirectoryName(filename));
                        using (var stream = new FileStream(filename, FileMode.Create))
                            TargetIff.Write(stream);
                    }

                    //add it to the provider
                    objProvider.AddObject(TargetIff, obj);

                    DialogResult = DialogResult.OK;
                    ResultGUID = guid;
                    Close();
                }
            }
        }
コード例 #9
0
ファイル: VMDialogHandler.cs プロジェクト: Daribon/FreeSO
        public static string ParseDialogString(VMStackFrame context, string input, STR source)
        {
            int state = 0;
            StringBuilder command = new StringBuilder();
            StringBuilder output = new StringBuilder();

            for (int i = 0; i < input.Length; i++)
            {
                if (state == 0)
                {
                    if (input[i] == '$')
                    {
                        state = 1; //start parsing string
                        command.Clear();
                    } else {
                        output.Append(input[i]);
                    }
                }
                else
                {
                    command.Append(input[i]);
                    if (i == input.Length - 1 || !CommandSubstrValid(command.ToString()))
                    {
                        if (i != input.Length - 1 || char.IsDigit(input[i]))
                        {
                            command.Remove(command.Length - 1, 1);
                            i--;
                        }

                        var cmdString = command.ToString();
                        ushort[] values = new ushort[3];
                        if (cmdString.Length > 1 && cmdString[cmdString.Length - 1] == ':')
                        {
                            try
                            {
                                if (cmdString == "DynamicStringLocal:")
                                {
                                    for (int j=0; j<3; j++)
                                    {
                                        char next = input[++i];
                                        string num = "";
                                        while (char.IsDigit(next))
                                        {
                                            num += next;
                                            next = (++i == input.Length) ? '!': input[i];
                                        }
                                        if (num == "")
                                        {
                                            values[j] = 65535;
                                            if (j == 1) values[2] = 65535;
                                            break;
                                        }
                                        values[j] = ushort.Parse(num);
                                        if (i == input.Length) break;
                                    }
                                }
                                else
                                {
                                    char next = input[++i];
                                    string num = "";
                                    while (char.IsDigit(next))
                                    {
                                        num += next;
                                        next = (++i == input.Length) ? '!' : input[i];
                                    }
                                    values[0] = ushort.Parse(num);
                                }
                                i--;
                            }
                            catch (FormatException)
                            {

                            }
                        }
                        switch (cmdString)
                        {
                            case "Object":
                                output.Append(context.StackObject.ToString()); break;
                            case "Me":
                                output.Append(context.Caller.ToString()); break;
                            case "TempXL:":
                                output.Append(VMMemory.GetBigVariable(context, Scopes.VMVariableScope.TempXL, values[0]).ToString()); break;
                            case "Temp:":
                                output.Append(VMMemory.GetBigVariable(context, Scopes.VMVariableScope.Temps, values[0]).ToString()); break;
                            case "$":
                                output.Append("$"); i--; break;
                            case "Attribute:":
                                output.Append(VMMemory.GetBigVariable(context, Scopes.VMVariableScope.MyObjectAttributes, values[0]).ToString()); break;
                            case "DynamicStringLocal:":
                                STR res = null;
                                if (values[2] != 65535 && values[1] != 65535)
                                {
                                    VMEntity obj = context.VM.GetObjectById((short)context.Locals[values[2]]);
                                    if (obj == null) break;
                                    ushort tableID = (ushort)context.Locals[values[1]];

                                    {//local
                                        if (obj.SemiGlobal != null) res = obj.SemiGlobal.Resource.Get<STR>(tableID);
                                        if (res == null) res = obj.Object.Resource.Get<STR>(tableID);
                                        if (res == null) res = context.Global.Resource.Get<STR>(tableID);
                                    }
                                } else
                                {
                                    res = source;
                                }

                                ushort index = (ushort)context.Locals[values[0]];
                                if (res != null) output.Append(res.GetString(index));
                                break;
                            case "Local:":
                                output.Append(VMMemory.GetBigVariable(context, Scopes.VMVariableScope.Local, values[0]).ToString()); break;
                            case "NameLocal:":
                                output.Append("(NameLocal)"); break;
                            default:
                                output.Append(cmdString);
                                break;
                        }
                        state = 0;
                    }
                }
            }
            output.Replace("\r\n", "\r\n\r\n");
            return output.ToString();
        }
コード例 #10
0
ファイル: VMDialogHandler.cs プロジェクト: Daribon/FreeSO
        public static void ShowDialog(VMStackFrame context, VMDialogOperand operand, STR source)
        {
            VMDialogInfo info = new VMDialogInfo
            {
                Block = (operand.Flags & VMDialogFlags.Continue) == 0,
                Caller = context.Caller,
                Icon = context.StackObject,
                Operand = operand,
                Message = ParseDialogString(context, source.GetString(operand.MessageStringID - 1), source),
                Title = (operand.TitleStringID == 0) ? "" : ParseDialogString(context, source.GetString(operand.TitleStringID - 1), source),
                IconName = (operand.IconNameStringID == 0) ? "" : ParseDialogString(context, source.GetString(operand.IconNameStringID - 1), source),

                Yes = (operand.YesStringID == 0) ? null : ParseDialogString(context, source.GetString(operand.YesStringID - 1), source),
                No = (operand.NoStringID == 0) ? null : ParseDialogString(context, source.GetString(operand.NoStringID - 1), source),
                Cancel = (operand.CancelStringID == 0) ? null : ParseDialogString(context, source.GetString(operand.CancelStringID - 1), source),
            };
            context.VM.SignalDialog(info);
        }
コード例 #11
0
 public void SetActiveResource(IffChunk chunk, GameIffResource res)
 {
     ActiveString = (STR)chunk;
     UpdateStrings();
 }
コード例 #12
0
        public static string ParseDialogString(VMStackFrame context, string input, STR source)
        {
            int state = 0;
            StringBuilder command = new StringBuilder();
            StringBuilder output = new StringBuilder();

            if (input == null) return "Missing String!!!";

            for (int i = 0; i < input.Length; i++)
            {
                if (state == 0)
                {
                    if (input[i] == '$')
                    {
                        state = 1; //start parsing string
                        command.Clear();
                    } else {
                        output.Append(input[i]);
                    }
                }
                else
                {
                    command.Append(input[i]);
                    if (i == input.Length - 1 || !CommandSubstrValid(command.ToString()))
                    {
                        if (i != input.Length - 1 || char.IsDigit(input[i]))
                        {
                            command.Remove(command.Length - 1, 1);
                            i--;
                        }

                        var cmdString = command.ToString();
                        short[] values = new short[3];
                        if (cmdString.Length > 1 && cmdString[cmdString.Length - 1] == ':')
                        {
                            try
                            {
                                if (cmdString == "DynamicStringLocal:")
                                {
                                    values[1] = -1;
                                    values[2] = -1;
                                    for (int j=0; j<3; j++)
                                    {
                                        char next = input[++i];
                                        string num = "";
                                        while (char.IsDigit(next))
                                        {
                                            num += next;
                                            next = (++i == input.Length) ? '!': input[i];
                                        }
                                        if (num == "")
                                        {
                                            values[j] = -1;
                                            if (j == 1) values[2] = -1;
                                            break;
                                        }
                                        values[j] = short.Parse(num);
                                        if (i == input.Length || next != ':') break;
                                    }
                                }
                                else
                                {
                                    char next = input[++i];
                                    string num = "";
                                    while (char.IsDigit(next))
                                    {
                                        num += next;
                                        next = (++i == input.Length) ? '!' : input[i];
                                    }
                                    values[0] = short.Parse(num);
                                }
                                i--;
                            }
                            catch (FormatException)
                            {

                            }
                        }
                        try
                        {
                            switch (cmdString)
                            {
                                case "Object":
                                case "DynamicObjectName":
                                    output.Append(context.StackObject.ToString()); break;
                                case "Me":
                                    output.Append(context.Caller.ToString()); break;
                                case "TempXL:":
                                    output.Append(VMMemory.GetBigVariable(context, Scopes.VMVariableScope.TempXL, values[0]).ToString()); break;
                                case "MoneyXL:":
                                    output.Append("$" + VMMemory.GetBigVariable(context, Scopes.VMVariableScope.TempXL, values[0]).ToString("##,#0")); break;
                                case "Temp:":
                                    output.Append(VMMemory.GetBigVariable(context, Scopes.VMVariableScope.Temps, values[0]).ToString()); break;
                                case "$":
                                    output.Append("$"); i--; break;
                                case "Attribute:":
                                    output.Append(VMMemory.GetBigVariable(context, Scopes.VMVariableScope.MyObjectAttributes, values[0]).ToString()); break;
                                case "DynamicStringLocal:":
                                    STR res = null;
                                    if (values[2] != -1 && values[1] != -1)
                                    {
                                        VMEntity obj = context.VM.GetObjectById((short)context.Locals[values[2]]);
                                        if (obj == null) break;
                                        ushort tableID = (ushort)context.Locals[values[1]];

                                        {//local
                                            if (obj.SemiGlobal != null) res = obj.SemiGlobal.Get<STR>(tableID);
                                            if (res == null) res = obj.Object.Resource.Get<STR>(tableID);
                                            if (res == null) res = context.Global.Resource.Get<STR>(tableID);
                                        }
                                    } else if (values[1] != -1)
                                    {
                                        //global table
                                        ushort tableID = (ushort)context.Locals[values[1]];
                                        res = context.Global.Resource.Get<STR>(tableID);

                                    } else
                                    {
                                        res = source;
                                    }

                                    ushort index = (ushort)context.Locals[values[0]];
                                    if (res != null)
                                    {
                                        var str = res.GetString(index);
                                        output.Append(ParseDialogString(context, str, res)); // recursive command parsing!
                                        // this is needed for the crafting table.
                                        // though it is also, completely insane?
                                    }
                                    break;
                                case "Local:":
                                    output.Append(VMMemory.GetBigVariable(context, Scopes.VMVariableScope.Local, values[0]).ToString()); break;
                                case "Param:":
                                    output.Append(VMMemory.GetBigVariable(context, Scopes.VMVariableScope.Parameters, values[0]).ToString()); break;
                                case "NameLocal:":
                                    output.Append("(NameLocal)"); break;
                                default:
                                    output.Append(cmdString);
                                    break;
                            }
                        } catch (Exception)
                        {
                            //something went wrong. just skip command
                        }
                        state = 0;
                    }
                }
            }
            output.Replace("\r\n", "\r\n\r\n");
            return output.ToString();
        }
コード例 #13
0
        public static void ShowDialog(VMStackFrame context, VMDialogOperand operand, STR source)
        {
            VMDialogInfo info = new VMDialogInfo
            {
                Block = (operand.Flags & VMDialogFlags.Continue) == 0,
                Caller = context.Caller,
                Icon = context.StackObject,
                Operand = operand,
                Message = ParseDialogString(context, source.GetString(Math.Max(0, operand.MessageStringID - 1)), source),
                Title = (operand.TitleStringID == 0) ? "" : ParseDialogString(context, source.GetString(operand.TitleStringID - 1), source),
                IconName = (operand.IconNameStringID == 0) ? "" : ParseDialogString(context, source.GetString(operand.IconNameStringID - 1), source),

                Yes = (operand.YesStringID == 0) ? null : ParseDialogString(context, source.GetString(operand.YesStringID - 1), source),
                No = (operand.NoStringID == 0) ? null : ParseDialogString(context, source.GetString(operand.NoStringID - 1), source),
                Cancel = (operand.CancelStringID == 0) ? null : ParseDialogString(context, source.GetString(operand.CancelStringID - 1), source),
                DialogID = (context.CodeOwner.GUID << 32) | ((ulong)context.Routine.ID << 16) | context.InstructionPointer
            };
            context.VM.SignalDialog(info);
        }