Skip to content

Commit

Permalink
Added RomInfo for trainer special script and handle scriptnumber
Browse files Browse the repository at this point in the history
  • Loading branch information
Mixone-FinallyHere committed May 16, 2024
1 parent 6dcbd18 commit 3a4cb3c
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 49 deletions.
90 changes: 41 additions & 49 deletions DS_Map/Main Window.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
using DSPRE.Editors;

namespace DSPRE {


public partial class MainProgram : Form {

Expand Down Expand Up @@ -690,14 +690,14 @@ private void ReadROMInitData() {
spawnEditorToolStripButton.Enabled = true;
spawnEditorToolStripMenuItem.Enabled = true;
monEditorToolStripMenuItem.Enabled = true;

scriptCommandsButton.Enabled = true;
if (!RomInfo.gameFamily.Equals(GameFamilies.HGSS)) {
mainTabControl.TabPages.Remove(tabPageEncountersEditor);
} else {
overlayEditorToolStripMenuItem.Enabled = true;
}

Helpers.statusLabelMessage();
this.Text += " - " + RomInfo.fileName;
}
Expand Down Expand Up @@ -983,7 +983,7 @@ private void SetupHeaderEditor() {

/* Read Header internal names */
try {
headerListBoxNames = Helpers.getHeaderListBoxNames();
headerListBoxNames = Helpers.getHeaderListBoxNames();
internalNames = Helpers.getInternalNames();

headerListBox.Items.Clear();
Expand Down Expand Up @@ -1256,7 +1256,7 @@ private void RefreshHeaderEditorFields() {
textFileUpDown.Value = currentHeader.textArchiveID;
wildPokeUpDown.Value = currentHeader.wildPokemon;
weatherUpDown.Value = currentHeader.weatherID;
cameraUpDown.Value = currentHeader.cameraAngleID;
cameraUpDown.Value = currentHeader.cameraAngleID;
battleBackgroundUpDown.Value = currentHeader.battleBackground;

if (RomInfo.gameFamily == GameFamilies.HGSS) {
Expand Down Expand Up @@ -3766,13 +3766,13 @@ private void wireframeCheckBox_CheckedChanged(object sender, EventArgs e) {
private void addBuildingButton_Click(object sender, EventArgs e) {
AddBuildingToMap(new Building());
}

private void duplicateBuildingButton_Click(object sender, EventArgs e) {
if (buildingsListBox.SelectedIndex > -1) {
AddBuildingToMap(new Building(currentMapFile.buildings[buildingsListBox.SelectedIndex]));
}
}

private void AddBuildingToMap(Building b) {
currentMapFile.buildings.Add(b);

Expand All @@ -3788,7 +3788,7 @@ private void AddBuildingToMap(Building b) {
/* Redraw scene with new building */
RenderMap(ref mapRenderer, ref buildingsRenderer, ref currentMapFile, ang, dist, elev, perspective, mapOpenGlControl.Width, mapOpenGlControl.Height, mapTexturesOn, bldTexturesOn);
}

private void buildIndexComboBox_SelectedIndexChanged(object sender, EventArgs e) {
if (Helpers.HandlersDisabled || buildingsListBox.SelectedIndex < 0) {
return;
Expand All @@ -3804,7 +3804,7 @@ private void buildIndexComboBox_SelectedIndexChanged(object sender, EventArgs e)

RenderMap(ref mapRenderer, ref buildingsRenderer, ref currentMapFile, ang, dist, elev, perspective, mapOpenGlControl.Width, mapOpenGlControl.Height, mapTexturesOn, bldTexturesOn);
}

private void buildingsListBox_SelectedIndexChanged(object sender, EventArgs e) {
int buildingNumber = buildingsListBox.SelectedIndex;
if (Helpers.HandlersDisabled || buildingNumber < 0) {
Expand Down Expand Up @@ -3836,19 +3836,20 @@ private void buildingsListBox_SelectedIndexChanged(object sender, EventArgs e) {

Helpers.RestoreDisableHandler();
}

private void xRotBuildUpDown_ValueChanged(object sender, EventArgs e) {
int selection = buildingsListBox.SelectedIndex;

if (selection <= -1 || Helpers.HandlersDisabled) {
return;
}
Helpers.DisableHandlers();

xRotDegBldUpDown.Value = (decimal)Building.U16ToDeg(currentMapFile.buildings[selection].xRotation = (ushort)((int)xRotBuildUpDown.Value & ushort.MaxValue));
currentMapFile.buildings[selection].xRotation = (ushort)((int)xRotBuildUpDown.Value & ushort.MaxValue);
xRotDegBldUpDown.Value = (decimal)Building.U16ToDeg(currentMapFile.buildings[selection].xRotation);
RenderMap(ref mapRenderer, ref buildingsRenderer, ref currentMapFile, ang, dist, elev, perspective, mapOpenGlControl.Width, mapOpenGlControl.Height, mapTexturesOn, bldTexturesOn);

Helpers.EnableHandlers();
Console.WriteLine("X Rot " + currentMapFile.buildings[selection].xRotation.ToString());
}

private void yRotBuildUpDown_ValueChanged(object sender, EventArgs e) {
Expand Down Expand Up @@ -3917,28 +3918,28 @@ private void zRotDegBldUpDown_ValueChanged(object sender, EventArgs e) {

Helpers.EnableHandlers();
}

private void buildingHeightUpDown_ValueChanged(object sender, EventArgs e) {
if (buildingsListBox.SelectedIndex > -1) {
currentMapFile.buildings[buildingsListBox.SelectedIndex].height = (uint)buildingHeightUpDown.Value;
RenderMap(ref mapRenderer, ref buildingsRenderer, ref currentMapFile, ang, dist, elev, perspective, mapOpenGlControl.Width, mapOpenGlControl.Height, mapTexturesOn, bldTexturesOn);
}
}

private void buildingLengthUpDown_ValueChanged(object sender, EventArgs e) {
if (buildingsListBox.SelectedIndex > -1) {
currentMapFile.buildings[buildingsListBox.SelectedIndex].length = (uint)buildingLengthUpDown.Value;
RenderMap(ref mapRenderer, ref buildingsRenderer, ref currentMapFile, ang, dist, elev, perspective, mapOpenGlControl.Width, mapOpenGlControl.Height, mapTexturesOn, bldTexturesOn);
}
}

private void buildingWidthUpDown_ValueChanged(object sender, EventArgs e) {
if (buildingsListBox.SelectedIndex > -1) {
currentMapFile.buildings[buildingsListBox.SelectedIndex].width = (uint)buildingWidthUpDown.Value;
RenderMap(ref mapRenderer, ref buildingsRenderer, ref currentMapFile, ang, dist, elev, perspective, mapOpenGlControl.Width, mapOpenGlControl.Height, mapTexturesOn, bldTexturesOn);
}
}

private void exportBuildingsButton_Click(object sender, EventArgs e) {
SaveFileDialog sf = new SaveFileDialog {
Filter = MapFile.BuildingsFilter,
Expand All @@ -3952,7 +3953,7 @@ private void exportBuildingsButton_Click(object sender, EventArgs e) {

MessageBox.Show("Buildings exported successfully!", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
}

private void importBuildingsButton_Click(object sender, EventArgs e) {
OpenFileDialog ib = new OpenFileDialog {
Filter = MapFile.BuildingsFilter
Expand All @@ -3973,7 +3974,7 @@ private void importBuildingsButton_Click(object sender, EventArgs e) {
RenderMap(ref mapRenderer, ref buildingsRenderer, ref currentMapFile, ang, dist, elev, perspective, mapOpenGlControl.Width, mapOpenGlControl.Height, mapTexturesOn, bldTexturesOn);
MessageBox.Show("Buildings imported successfully!", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
}

private void interiorRadioButton_CheckedChanged(object sender, EventArgs e) {
Helpers.DisableHandlers();
int index = buildIndexComboBox.SelectedIndex;
Expand All @@ -4000,7 +4001,7 @@ private void interiorRadioButton_CheckedChanged(object sender, EventArgs e) {
RenderMap(ref mapRenderer, ref buildingsRenderer, ref currentMapFile, ang, dist, elev, perspective, mapOpenGlControl.Width, mapOpenGlControl.Height, mapTexturesOn, bldTexturesOn);
Helpers.EnableHandlers();
}

private void removeBuildingButton_Click(object sender, EventArgs e) {
int toRemoveListBoxID = buildingsListBox.SelectedIndex;
if (toRemoveListBoxID > -1) {
Expand All @@ -4025,7 +4026,7 @@ private void removeBuildingButton_Click(object sender, EventArgs e) {
}
}
}

private void xBuildUpDown_ValueChanged(object sender, EventArgs e) {
if (Helpers.HandlersDisabled || buildingsListBox.SelectedIndex < 0) {
return;
Expand All @@ -4043,7 +4044,7 @@ private void xBuildUpDown_ValueChanged(object sender, EventArgs e) {
currentMapFile.buildings[buildingsListBox.SelectedIndex].xFraction = (ushort)(decPart * 65535);
RenderMap(ref mapRenderer, ref buildingsRenderer, ref currentMapFile, ang, dist, elev, perspective, mapOpenGlControl.Width, mapOpenGlControl.Height, mapTexturesOn, bldTexturesOn);
}

private void zBuildUpDown_ValueChanged(object sender, EventArgs e) {
if (Helpers.HandlersDisabled || buildingsListBox.SelectedIndex < 0)
return;
Expand All @@ -4060,7 +4061,7 @@ private void zBuildUpDown_ValueChanged(object sender, EventArgs e) {
currentMapFile.buildings[buildingsListBox.SelectedIndex].zFraction = (ushort)(decPart * 65535);
RenderMap(ref mapRenderer, ref buildingsRenderer, ref currentMapFile, ang, dist, elev, perspective, mapOpenGlControl.Width, mapOpenGlControl.Height, mapTexturesOn, bldTexturesOn);
}

private void yBuildUpDown_ValueChanged(object sender, EventArgs e) {
if (Helpers.HandlersDisabled || buildingsListBox.SelectedIndex < 0)
return;
Expand Down Expand Up @@ -4198,7 +4199,7 @@ private SortedSet<byte> FindUsedCollisions() {
}
private SortedSet<byte> FindUnusedCollisions() {
int mapCount = romInfo.GetMapCount();

SortedSet<byte> allUnusedTypes = new SortedSet<byte>();
for (int i = 0; i <= byte.MaxValue; i++) {
allUnusedTypes.Add((byte)i);
Expand Down Expand Up @@ -4701,7 +4702,7 @@ private void valueTypeRadioButton_CheckedChanged(object sender, EventArgs e) {

#region 3D Model Editor
public const ushort MAPMODEL_CRITICALSIZE = 61000;

private void importMapButton_Click(object sender, EventArgs e) {
OpenFileDialog im = new OpenFileDialog {
Filter = MapFile.NSBMDFilter
Expand Down Expand Up @@ -4731,7 +4732,7 @@ private void importMapButton_Click(object sender, EventArgs e) {
}
MessageBox.Show(message, title, MessageBoxButtons.OK, MessageBoxIcon.Information);
}

private void exportMapButton_Click(object sender, EventArgs e) {
SaveFileDialog em = new SaveFileDialog {
FileName = selectMapComboBox.SelectedItem.ToString()
Expand Down Expand Up @@ -6244,13 +6245,9 @@ private void owScriptNumericUpDown_ValueChanged(object sender, EventArgs e) {
}
private void owSightRangeUpDown_ValueChanged(object sender, EventArgs e) {
int selection = overworldsListBox.SelectedIndex;

if (Helpers.HandlersDisabled || selection < 0) {
return;
}

currentEvFile.overworlds[selection].sightRange = (ushort)owSightRangeUpDown.Value;
}

private void owSpriteComboBox_SelectedIndexChanged(object sender, EventArgs e) {
int selection = overworldsListBox.SelectedIndex;
if (owSpriteComboBox.SelectedIndex < 0) {
Expand Down Expand Up @@ -6280,22 +6277,17 @@ private void owSpriteComboBox_SelectedIndexChanged(object sender, EventArgs e) {
}
private void owPartnerTrainerCheckBox_CheckedChanged(object sender, EventArgs e) {
int selection = overworldsListBox.SelectedIndex;

if (Helpers.HandlersDisabled || selection < 0) {
return;
}

currentEvFile.overworlds[selection].scriptNumber = (ushort)(currentEvFile.overworlds[selection].scriptNumber + (owPartnerTrainerCheckBox.Checked ? 2000 : -2000));
owScriptNumericUpDown.Value = (ushort)(currentEvFile.overworlds[selection].scriptNumber + (owPartnerTrainerCheckBox.Checked ? 2000 : -2000));
}
private void owTrainerComboBox_SelectedIndexChanged(object sender, EventArgs e) {
int selection = overworldsListBox.SelectedIndex;

if (Helpers.HandlersDisabled || selection < 0) {
return;
private void owTrainerComboBox_SelectedIndexChanged(object sender, EventArgs e) {
ushort scriptNum = (ushort)(owTrainerComboBox.SelectedIndex + (owPartnerTrainerCheckBox.Checked ? 4999 : 2999));
if (owTrainerComboBox.SelectedIndex > trainerFunnyScriptNumber - 1 ) {
scriptNum++;
}

currentEvFile.overworlds[selection].scriptNumber = (ushort)(owTrainerComboBox.SelectedIndex + (owPartnerTrainerCheckBox.Checked ? 4999 : 2999));
owScriptNumericUpDown.Value = scriptNum;
}

private void owXMapUpDown_ValueChanged(object sender, EventArgs e) {
int selection = overworldsListBox.SelectedIndex;

Expand Down Expand Up @@ -7816,7 +7808,7 @@ public void RefreshAbilities(int forPokemon) {
int currentIndex = trainerComboBox.SelectedIndex;
SetupTrainerEditor();
trainerComboBox.SelectedIndex = currentIndex;
}
}
}

private void SetupTrainerEditor() {
Expand Down Expand Up @@ -8210,10 +8202,10 @@ private void partyCountUpDown_ValueChanged(object sender, EventArgs e) {
}
}

private void trainerMovesCheckBox_CheckedChanged(object sender, EventArgs e) {
for (int i = 0; i < TrainerFile.POKE_IN_PARTY; i++) {
private void trainerMovesCheckBox_CheckedChanged(object sender, EventArgs e) {
for (int i = 0; i < TrainerFile.POKE_IN_PARTY; i++) {
for (int j = 0; j < Party.MOVES_PER_POKE; j++) {
(partyMovesGroupboxList[i].Controls[j] as ComboBox).Enabled = trainerMovesCheckBox.Checked;
(partyMovesGroupboxList[i].Controls[j] as ComboBox).Enabled = trainerMovesCheckBox.Checked;
}
if (trainerMovesCheckBox.Checked && i < currentTrainerFile.trp.partyCount && Helpers.HandlersEnabled) {
Helpers.BackUpDisableHandler();
Expand All @@ -8226,13 +8218,13 @@ private void trainerMovesCheckBox_CheckedChanged(object sender, EventArgs e) {
for (int j = 0; j < Party.MOVES_PER_POKE; j++) {
(partyMovesGroupboxList[i].Controls[j] as ComboBox).SelectedIndex = currentTrainerFile.party[i].moves[j];
Debug.Print("Move for dropdwon " + j.ToString() + " is " + currentTrainerFile.party[i].moves[j].ToString());
}
}
Helpers.RestoreDisableHandler();
} else {
//currentTrainerFile.party[i].moves = null;
}
}
RefreshTrainerPartyGUI();
RefreshTrainerPartyGUI();
}
private void trainerItemsCheckBox_CheckedChanged(object sender, EventArgs e) {
for (int i = 0; i < TrainerFile.POKE_IN_PARTY; i++) {
Expand Down Expand Up @@ -8562,7 +8554,7 @@ private void saveTrainerClassButton_Click(object sender, EventArgs e) {

if (trainerClassEncounterMusicDict.TryGetValue(b_selectedTrClass, out var dictEntry)) {
ARM9.WriteBytes(BitConverter.GetBytes(eyeMusicID), dictEntry.entryOffset + 2);

if (gameFamily.Equals(GameFamilies.HGSS)) {
ARM9.WriteBytes(BitConverter.GetBytes(altEyeMusicID), dictEntry.entryOffset + 4);
}
Expand Down
18 changes: 18 additions & 0 deletions DS_Map/RomInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public class RomInfo
public static int locationNamesTextNumber { get; private set; }
public static int trainerNameLenOffset { get; private set; }
public static int trainerNameMaxLen => SetTrainerNameMaxLen();
public static int trainerFunnyScriptNumber { get; private set; }

public static string internalNamesLocation { get; private set; }
public static readonly byte internalNameLength = 16;
Expand Down Expand Up @@ -219,6 +220,7 @@ public RomInfo(string id, string romName, bool useSuffix = true)
SetLocationNamesTextNumber();
SetTrainerNamesMessageNumber();
SetTrainerClassMessageNumber();
SetTrainerFunnyScriptNumber();
SetTrainerNameLenOffset();

/* System */
Expand Down Expand Up @@ -1109,6 +1111,22 @@ private static void SetTrainerClassMessageNumber()
}
}

private static void SetTrainerFunnyScriptNumber() {
switch (gameFamily) {
case GameFamilies.DP:
trainerFunnyScriptNumber = 851;
break;

case GameFamilies.Plat:
trainerFunnyScriptNumber = 929;
break;

default: // HGSS
trainerFunnyScriptNumber = 740;
break;
}
}

private static void SetTrainerNameLenOffset()
{
switch (RomInfo.gameFamily)
Expand Down

0 comments on commit 3a4cb3c

Please sign in to comment.