void UpdateInventoryCheckboxUI() { #if USE_CHECKBOXES string inventory = passwordView.GetInventoryCharacterCodes(); int inventoryIndex = 0; int inventoryChrIndex = 0; for (int column = 0; column < 6; column++) { { int chr = CharacterCode.CharToIndex(inventory[inventoryChrIndex]); inventoryCheckboxes[inventoryIndex + 0].SetChecked((chr & 0x1) != 0); inventoryCheckboxes[inventoryIndex + 1].SetChecked((chr & 0x2) != 0); inventoryCheckboxes[inventoryIndex + 2].SetChecked((chr & 0x4) != 0); inventoryCheckboxes[inventoryIndex + 3].SetChecked((chr & 0x8) != 0); inventoryCheckboxes[inventoryIndex + 4].SetChecked((chr & 0x10) != 0); inventoryChrIndex++; inventoryIndex += 5; } { int chr = CharacterCode.CharToIndex(inventory[inventoryChrIndex]); inventoryCheckboxes[inventoryIndex + 0].SetChecked((chr & 0x1) != 0); inventoryCheckboxes[inventoryIndex + 1].SetChecked((chr & 0x2) != 0); inventoryCheckboxes[inventoryIndex + 2].SetChecked((chr & 0x4) != 0); inventoryCheckboxes[inventoryIndex + 3].SetChecked((chr & 0x8) != 0); inventoryChrIndex++; inventoryIndex += 4; } } #endif }
public void Paint(PaintEventArgs e) { e.Graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor; e.Graphics.ScaleTransform(2, 2); e.Graphics.DrawImage(baseImage, 0, 0, 256, 224); for (int passwordStringIndex = 0; passwordStringIndex < 48; passwordStringIndex++) { Coord textPosition = StringIndexToTextPosition(passwordStringIndex); Coord textScreenPosition = TextPositionToScreenPosition(textPosition); Rectangle destRect = new Rectangle(textScreenPosition.X, textScreenPosition.Y, 8, 15); int index = CharacterCode.CharToIndex(passwordString[passwordStringIndex]); float awfulFudgeFactor = 0.5f; RectangleF sourceRect = new RectangleF(index * 8, -1, 8 - awfulFudgeFactor, 16); e.Graphics.DrawImage(glyphs, destRect, sourceRect, GraphicsUnit.Point); } Coord caretScreenPosition = TextPositionToScreenPosition(caretTextPosition); // Adjust for caret image caretScreenPosition.X -= 16; caretScreenPosition.Y += 11; e.Graphics.DrawImage(caret, caretScreenPosition.X, caretScreenPosition.Y, 16, 16); }
public void UpdatePassword_LocationIndex(int locationIndex) { char characterCode = CharacterCode.IndexToChar(locationIndex); passwordString[24] = characterCode; passwordUI.Invalidate(); }
ExpectedChecksum GetExpectedChecksum() { ExpectedChecksum result = new ExpectedChecksum(); string str = new string(passwordString); string line1 = str.Substring(0, 12); string line2 = str.Substring(12, 12); string line3 = str.Substring(24, 12); string inventory = str.Substring(36, 12); byte checksum1 = GetChecksumComponent(line1); byte checksum2 = GetChecksumComponent(line2); int expectedPartyChecksum = (checksum1 + checksum2) % 32; result.ExpectedPartyChecksum = CharacterCode.IndexToChar(expectedPartyChecksum); string eventInfo = line3.Substring(0, 9); int eventChecksum = GetChecksumComponent(eventInfo) % 32; result.ExpectedEventChecksum = CharacterCode.IndexToChar(eventChecksum); int inventoryChecksum = GetChecksumComponent(inventory) % 32; result.ExpectedInventoryChecksum = CharacterCode.IndexToChar(inventoryChecksum); return(result); }
public int GetLocationCode() { string str = new string(passwordString); string line3 = str.Substring(24, 12); char locationCodeCharacter = line3[0]; return(CharacterCode.CharToIndex(locationCodeCharacter)); }
byte GetChecksumComponent(string passwordText) { byte result = 0; for (int i = 0; i < passwordText.Length; ++i) { byte v = (byte)CharacterCode.CharToIndex(passwordText[i]); result += v; } return(result); }
public void UpdatePassword_Lines1And2(bool enabled, int desiredLevel, int weaponIndex, int armorIndex, int passwordStartIndex) { if (weaponIndex == -1 || armorIndex == -1) { return; // Not finished loading } if (weaponIndex == (int)Names.Weapon.Invalid || armorIndex == (int)Names.Armor.Invalid) { // Choose some arbitrary invalid sequence passwordString[passwordStartIndex + 0] = '.'; passwordString[passwordStartIndex + 1] = '.'; passwordString[passwordStartIndex + 2] = 'B'; passwordUI.Invalidate(); return; } int code1 = 0; int code2 = 0; int code3 = 0; if (enabled) { int multipleOf20 = desiredLevel / 20; int remainderOf20 = desiredLevel % 20; System.Diagnostics.Debug.Assert(multipleOf20 >= 0 && multipleOf20 <= 4); int levelEncode = remainderOf20; if (remainderOf20 >= 10) { levelEncode += 6; } code1 = levelEncode; int[] armorEncodeList2 = { 0, 0, 1, 1, 2, 3 }; int armorEncode2 = armorEncodeList2[armorIndex]; code2 = multipleOf20 + (armorEncode2 * 8); int weaponEncode = weaponIndex; int[] armorEncodeList3 = { 0, 1, 0, 1, 0, 0 }; int armorEncode3 = armorEncodeList3[armorIndex]; code3 = 16 + (weaponEncode * 2) + armorEncode3; } passwordString[passwordStartIndex + 0] = CharacterCode.IndexToChar(code1); passwordString[passwordStartIndex + 1] = CharacterCode.IndexToChar(code2); passwordString[passwordStartIndex + 2] = CharacterCode.IndexToChar(code3); passwordUI.Invalidate(); }
private void OnInventoryCheckboxCheckChanged(object sender, EventArgs e) { // Update password based on the checkbox UI int inventoryCheckboxIndex = 0; int passwordStringIndex = 0; char[] inventoryCharacterCodes = new char[12]; for (int column = 0; column < 6; column++) { { int l0 = 0; l0 |= inventoryCheckboxes[inventoryCheckboxIndex + 0].GetChecked() ? 0x1 : 0; l0 |= inventoryCheckboxes[inventoryCheckboxIndex + 1].GetChecked() ? 0x2 : 0; l0 |= inventoryCheckboxes[inventoryCheckboxIndex + 2].GetChecked() ? 0x4 : 0; l0 |= inventoryCheckboxes[inventoryCheckboxIndex + 3].GetChecked() ? 0x8 : 0; l0 |= inventoryCheckboxes[inventoryCheckboxIndex + 4].GetChecked() ? 0x10 : 0; inventoryCharacterCodes[passwordStringIndex] = CharacterCode.IndexToChar(l0); passwordStringIndex++; inventoryCheckboxIndex += 5; } { int l1 = 0; l1 |= inventoryCheckboxes[inventoryCheckboxIndex + 0].GetChecked() ? 0x1 : 0; l1 |= inventoryCheckboxes[inventoryCheckboxIndex + 1].GetChecked() ? 0x2 : 0; l1 |= inventoryCheckboxes[inventoryCheckboxIndex + 2].GetChecked() ? 0x4 : 0; l1 |= inventoryCheckboxes[inventoryCheckboxIndex + 3].GetChecked() ? 0x8 : 0; inventoryCharacterCodes[passwordStringIndex] = CharacterCode.IndexToChar(l1); passwordStringIndex++; inventoryCheckboxIndex += 4; } } passwordView.UpdatePassword_Inventory(inventoryCharacterCodes); checksum.UpdateButtonState(passwordView.IsValidChecksum()); }
public void UpdateUI(char[] code) { int code1 = CharacterCode.CharToIndex(code[0]); int code2 = CharacterCode.CharToIndex(code[1]); int code3 = CharacterCode.CharToIndex(code[2]); // Do not reflect the changes back into the password. shouldUpdatePasswordString = false; if (code1 == 0 && code2 == 0 && code3 == 0) { characterEnabledCheckBox.Checked = false; levelLabel.Enabled = false; levelNumericUpDown.Enabled = false; weaponComboBox.Enabled = false; armorComboBox.Enabled = false; shouldUpdatePasswordString = true; return; } characterEnabledCheckBox.Checked = true; levelLabel.Enabled = true; levelNumericUpDown.Enabled = true; weaponComboBox.Enabled = true; armorComboBox.Enabled = true; switch (code2) { case 0: UpdateUIFromCode3(code1, code3, 0, Names.Armor.ClothCloak, Names.Armor.Invalid, 0, Names.Armor.ClothCloak, Names.Armor.PlateMail); break; case 1: UpdateUIFromCode3(code1, code3, 0, Names.Armor.ClothCloak, Names.Armor.Invalid, 20, Names.Armor.ClothCloak, Names.Armor.PlateMail); break; case 2: UpdateUIFromCode3(code1, code3, 20, Names.Armor.PlateMail, Names.Armor.Invalid, 40, Names.Armor.ClothCloak, Names.Armor.PlateMail); break; case 3: UpdateUIFromCode3(code1, code3, 20, Names.Armor.PlateMail, Names.Armor.Invalid, 60, Names.Armor.ClothCloak, Names.Armor.PlateMail); break; case 4: UpdateUIFromCode3(code1, code3, 20, Names.Armor.PlateMail, Names.Armor.Invalid, 80, Names.Armor.ClothCloak, Names.Armor.PlateMail); break; case 5: UpdateUIFromCode3(code1, code3, 20, Names.Armor.PlateMail, Names.Armor.Invalid, 0, Names.Armor.Corruption, Names.Armor.Corruption); break; case 6: case 7: UpdateUIFromCode3(code1, code3, 0, Names.Armor.ClothCloak, Names.Armor.Invalid, 0, Names.Armor.Corruption, Names.Armor.Corruption); break; case 8: UpdateUIFromCode3(code1, code3, 0, Names.Armor.Invalid, Names.Armor.Invalid, 0, Names.Armor.PaddedArmor, Names.Armor.MithrilArmor); break; case 9: UpdateUIFromCode3(code1, code3, 0, Names.Armor.Invalid, Names.Armor.Invalid, 20, Names.Armor.PaddedArmor, Names.Armor.MithrilArmor); break; case 10: UpdateUIFromCode3(code1, code3, 0, Names.Armor.Invalid, Names.Armor.Invalid, 40, Names.Armor.PaddedArmor, Names.Armor.MithrilArmor); break; case 11: UpdateUIFromCode3(code1, code3, 0, Names.Armor.Invalid, Names.Armor.Invalid, 60, Names.Armor.PaddedArmor, Names.Armor.MithrilArmor); break; case 12: UpdateUIFromCode3(code1, code3, 0, Names.Armor.Invalid, Names.Armor.Invalid, 80, Names.Armor.PaddedArmor, Names.Armor.MithrilArmor); break; case 13: case 14: case 15: UpdateUIFromCode3(code1, code3, 0, Names.Armor.Invalid, Names.Armor.Invalid, 0, Names.Armor.Corruption, Names.Armor.Corruption); break; case 16: UpdateUIFromCode3(code1, code3, 0, Names.Armor.Invalid, Names.Armor.Invalid, 0, Names.Armor.LeatherArmor, Names.Armor.Corruption); break; case 17: UpdateUIFromCode3(code1, code3, 0, Names.Armor.Invalid, Names.Armor.Invalid, 20, Names.Armor.LeatherArmor, Names.Armor.Corruption); break; case 18: UpdateUIFromCode3(code1, code3, 0, Names.Armor.Invalid, Names.Armor.Invalid, 40, Names.Armor.LeatherArmor, Names.Armor.Corruption); break; case 19: UpdateUIFromCode3(code1, code3, 0, Names.Armor.Invalid, Names.Armor.Invalid, 60, Names.Armor.LeatherArmor, Names.Armor.Corruption); break; case 20: UpdateUIFromCode3(code1, code3, 0, Names.Armor.Invalid, Names.Armor.Invalid, 80, Names.Armor.LeatherArmor, Names.Armor.Corruption); break; case 21: case 22: case 23: UpdateUIFromCode3(code1, code3, 0, Names.Armor.Invalid, Names.Armor.Invalid, 0, Names.Armor.Corruption, Names.Armor.Corruption); break; case 24: UpdateUIFromCode3(code1, code3, 0, Names.Armor.Invalid, Names.Armor.Invalid, 0, Names.Armor.ChainMail, Names.Armor.Corruption); break; case 25: UpdateUIFromCode3(code1, code3, 0, Names.Armor.Invalid, Names.Armor.Invalid, 20, Names.Armor.ChainMail, Names.Armor.Corruption); break; case 26: UpdateUIFromCode3(code1, code3, 0, Names.Armor.Invalid, Names.Armor.Invalid, 40, Names.Armor.ChainMail, Names.Armor.Corruption); break; case 27: UpdateUIFromCode3(code1, code3, 0, Names.Armor.Invalid, Names.Armor.Invalid, 60, Names.Armor.ChainMail, Names.Armor.Corruption); break; case 28: UpdateUIFromCode3(code1, code3, 0, Names.Armor.Invalid, Names.Armor.Invalid, 80, Names.Armor.ChainMail, Names.Armor.Corruption); break; case 29: case 30: case 31: UpdateUIFromCode3(code1, code3, 0, Names.Armor.Invalid, Names.Armor.Invalid, 0, Names.Armor.Corruption, Names.Armor.Corruption); break; default: break; } shouldUpdatePasswordString = true; }