0

My code selects items from a comboBox by its index number then assigns a specific byte to each item. For this I am using the If statement and am having to repeat it so many times.

I know how to use loops very basically but I haven't got a clue how to do it when each item needs a different value assigned to it.

        if (weaponcamCombo.SelectedIndex == 0)
        {
            PS3.SetMemory(Offsets.WeaponCamo + (0x80 * (uint)camoclassUD.Value) + (0x564 * (uint)camosoldierUD.Value), new byte[] { 0x0A });
        }
        if (weaponcamCombo.SelectedIndex == 1)
        {
            PS3.SetMemory(Offsets.WeaponCamo + (0x80 * (uint)camoclassUD.Value) + (0x564 * (uint)camosoldierUD.Value), new byte[] { 0x0B });
        }
        if (weaponcamCombo.SelectedIndex == 2)
        {
            PS3.SetMemory(Offsets.WeaponCamo + (0x80 * (uint)camoclassUD.Value) + (0x564 * (uint)camosoldierUD.Value), new byte[] { 0x0C });
        }

As you see a specific byte is assigned to each item, I was wondering how I would still do this but in a loop?

Thanks

3
  • Can you Describe what will be the answer of 0X0F + 4? Commented Jul 21, 2014 at 21:09
  • I mean if selectedIndex is 4 then what will be your answer? I am trying to understand the bit calculation so that I could try to answer your question. Commented Jul 21, 2014 at 21:22
  • @Vishal The code is the same except the byte is 0x0E this time and it will assign that to the offset "WeaponCamo" Commented Jul 21, 2014 at 21:26

2 Answers 2

2

Add weaponcamCombo.SelectedIndex to 0x0A

if(weaponcamCombo.SelectedIndex>-1)
{
    PS3.SetMemory(Offsets.WeaponCamo + (0x80 * (uint)camoclassUD.Value) + (0x564 * (uint)camosoldierUD.Value), new byte[] { 0x0A + weaponcamCombo.SelectedIndex  });
}

OR use a lookup table (in fact an array)

var values = new byte[]{0x0f,0x6a};

if(weaponcamCombo.SelectedIndex>-1)
{
    PS3.SetMemory(Offsets.WeaponCamo + (0x80 * (uint)camoclassUD.Value) + (0x564 * (uint)camosoldierUD.Value), new byte[] { values[weaponcamCombo.SelectedIndex] });
}
Sign up to request clarification or add additional context in comments.

3 Comments

You also should check that the selected index is valid before doing this
The only issue that there is would be that sometimes the byte could be completely random. So e.g. 0x0F then next it would be 0x6A and so on
@TobyCook then use an array new byte[]{0x0f,0x6a}; where the index to array is weaponcamCombo.SelectedIndex
0

You might be able to create a function that sets the memory and then just call it with an index.

public void SetMemory(int index)
{ 
    if(index >= 0)
    {
        PS3.SetMemory(Offsets.WeaponCamo + (0x80 * (uint)camoclassUD.Value) + (0x564 * (uint)camosoldierUD.Value), new byte[] { (0x0A + index)});
    }
}

Then call it like this:

    SetMemory(weaponcamCombo.SelectedIndex);    

1 Comment

I have the bytes set up in a class as well as they are random bytes. Would there be any way to use them from the class in the indexing?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.