Exemplo n.º 1
0
        internal static bool find_and_open_file(out File file_ptr, bool noError, string full_file_name)
        {
            string file_name = System.IO.Path.GetFileName(full_file_name);
            string dir_path = System.IO.Path.GetDirectoryName(full_file_name);

            if (dir_path.Length == 0)
            {
                dir_path = gbl.exe_path;
            }

            bool file_found;

            file_found = System.IO.File.Exists(System.IO.Path.Combine(dir_path, file_name));

            if (file_found == false && noError == false)
            {
                debug_display("Couldn't find " + file_name + ". Check install.");
            }

            if (file_found == true)
            {
                file_ptr = new File();
                file_ptr.Assign(System.IO.Path.Combine(dir_path, file_name));

                seg051.Reset(file_ptr);
            }
            else
            {
                file_ptr = null;
            }

            return file_found;
        }
Exemplo n.º 2
0
        static void BuildLoadablePlayersLists(ref List <MenuItem> fileNames, ref List <MenuItem> displayNames,
                                              short playerFileSize, int npcOffset, int nameOffset, string fileFilter) // sub_4708B
        {
            Classes.File file = new Classes.File();

            byte[] data = new byte[16];

            foreach (string filePath in Directory.GetFiles(Config.GetSavePath(), fileFilter))
            {
                FileStream stream = System.IO.File.Open(filePath, FileMode.Open, FileAccess.Read);

                if (stream.Length == playerFileSize)
                {
                    stream.Seek(nameOffset, SeekOrigin.Begin);
                    stream.Read(data, 0, 16);

                    string playerName = Sys.ArrayToString(data, 0, 15).Trim();

                    byte var_164;

                    if (gbl.import_from == ImportSource.Hillsfar)
                    {
                        var_164 = 0;
                    }
                    else
                    {
                        stream.Seek(npcOffset, SeekOrigin.Begin);
                        stream.Read(data, 0, 1);
                        var_164 = data[0];
                    }


                    string fullNameText =
                        string.Compare(Path.GetExtension(filePath), ".sav", true) == 0
                            ? string.Format("{0,-15} from save game {1}", playerName, filePath[7])
                            : playerName;

                    bool found = gbl.TeamList.Find(player => playerName == player.name.Trim()) != null;

                    if (found == false && var_164 <= 0x7F)
                    {
                        fileNames.Add(new MenuItem(filePath));
                        displayNames.Add(new MenuItem(fullNameText));
                    }
                }

                stream.Close();
            }
        }
Exemplo n.º 3
0
        internal static void SavePlayer(string arg_0, Player player) // sub_47DFC
        {
            char input_key;

            Classes.File file = new Classes.File();

            gbl.import_from = ImportSource.Curse;

            string ext_text;
            string file_text;

            if (arg_0 == "")
            {
                ext_text  = ".guy";
                file_text = seg042.clean_string(player.name);
            }
            else
            {
                ext_text  = ".sav";
                file_text = arg_0;
            }

            input_key = 'N';

            while (input_key == 'N' &&
                   arg_0.Length == 0 &&
                   seg042.file_find(Path.Combine(Config.GetSavePath(), file_text) + ext_text) == true)
            {
                input_key = ovr027.yes_no(gbl.alertMenuColors, "Overwrite " + file_text + "? ");

                if (input_key == 'N')
                {
                    file_text = string.Empty;

                    while (file_text == string.Empty)
                    {
                        file_text = seg041.getUserInputString(8, 0, 10, "New file name: ");
                    }
                }
            }

            string filePath = Path.Combine(Config.GetSavePath(), file_text);

            file.Assign(filePath + ext_text);

            seg051.Rewrite(file);

            seg051.BlockWrite(Player.StructSize, player.ToByteArray(), file);
            seg051.Close(file);

            seg042.delete_file(filePath + ".swg");

            if (player.items.Count > 0)
            {
                file.Assign(filePath + ".swg");
                seg051.Rewrite(file);

                player.items.ForEach(item => seg051.BlockWrite(Item.StructSize, item.ToByteArray(), file));

                seg051.Close(file);
            }

            seg042.delete_file(filePath + ".fx");

            if (player.affects.Count > 0)
            {
                file.Assign(filePath + ".fx");
                seg051.Rewrite(file);

                foreach (Affect affect in player.affects)
                {
                    seg051.BlockWrite(Affect.StructSize, affect.ToByteArray(), file);
                }

                seg051.Close(file);
            }
        }
Exemplo n.º 4
0
        internal static void SaveGame()
        {
            char inputKey;

            Classes.File save_file = new Classes.File();
            string[]     var_171   = new string[9];

            do
            {
                inputKey = ovr027.displayInput((gbl.game_state == GameState.Camping), 0, gbl.defaultMenuColors, "A B C D E F G H I J", "Save Which Game: ");
            } while (unk_4AEA0.MemberOf(inputKey) == false);

            if (inputKey != '\0')
            {
                gbl.import_from = ImportSource.Curse;

                short var_1FC;

                do
                {
                    save_file.Assign(Path.Combine(Config.GetSavePath(), "savgam" + inputKey + ".dat"));
                    seg051.Rewrite(save_file);
                    var_1FC = gbl.FIND_result;

                    if (unk_4AEEF.MemberOf(var_1FC) == false)
                    {
                        seg041.DisplayAndPause("Unexpected error during save: " + var_1FC.ToString(), 14);
                        seg051.Close(save_file);
                        return;
                    }
                } while (unk_4AEEF.MemberOf(var_1FC) == false);

                ovr027.ClearPromptArea();
                seg041.displayString("Saving...Please Wait", 0, 10, 0x18, 0);

                gbl.area_ptr.game_speed = (byte)gbl.game_speed_var;
                gbl.area_ptr.pics_on    = (byte)(((gbl.PicsOn) ? 0x02 : 0) | ((gbl.AnimationsOn) ? 0x01 : 0));
                gbl.area2_ptr.game_area = gbl.game_area;

                byte[] data = new byte[0x1E00];

                data[0] = gbl.game_area;
                seg051.BlockWrite(1, data, save_file);

                seg051.BlockWrite(0x800, gbl.area_ptr.ToByteArray(), save_file);
                seg051.BlockWrite(0x800, gbl.area2_ptr.ToByteArray(), save_file);
                seg051.BlockWrite(0x400, gbl.stru_1B2CA.ToByteArray(), save_file);
                seg051.BlockWrite(0x1E00, gbl.ecl_ptr.ToByteArray(), save_file);

                data[0] = (byte)gbl.mapPosX;
                data[1] = (byte)gbl.mapPosY;
                data[2] = gbl.mapDirection;
                data[3] = gbl.mapWallType;
                data[4] = gbl.mapWallRoof;
                seg051.BlockWrite(5, data, save_file);

                data[0] = (byte)gbl.last_game_state;
                seg051.BlockWrite(1, data, save_file);
                data[0] = (byte)gbl.game_state;
                seg051.BlockWrite(1, data, save_file);

                for (int i = 0; i < 3; i++)
                {
                    Sys.ShortToArray((short)gbl.setBlocks[i].blockId, data, (i * 4) + 0);
                    Sys.ShortToArray((short)gbl.setBlocks[i].setId, data, (i * 4) + 2);
                }
                seg051.BlockWrite(12, data, save_file);

                int party_count = 0;
                foreach (Player tmp_player in gbl.TeamList)
                {
                    party_count++;
                    var_171[party_count - 1] = "CHRDAT" + inputKey + party_count.ToString();
                }

                data[0] = (byte)party_count;
                seg051.BlockWrite(1, data, save_file);

                for (int i = 0; i < party_count; i++)
                {
                    Sys.StringToArray(data, 0x29 * i, 0x29, var_171[i]);
                }
                seg051.BlockWrite(0x148, data, save_file);
                seg051.Close(save_file);

                party_count = 0;
                foreach (Player tmp_player in gbl.TeamList)
                {
                    party_count++;
                    SavePlayer("CHRDAT" + inputKey + party_count.ToString(), tmp_player);
                    remove_player_file(tmp_player);
                }

                gbl.gameSaved = true;
                ovr027.ClearPromptArea();
            }
        }
Exemplo n.º 5
0
 internal static void Rewrite(File arg_2)
 {
     arg_2.stream.SetLength(0);
 }
Exemplo n.º 6
0
 internal static void Reset(File arg_4)
 {
     arg_4.stream.Seek(0, System.IO.SeekOrigin.Begin);
 }
Exemplo n.º 7
0
 internal static void Close(File arg_0)
 {
     arg_0.stream.Close();
 }
Exemplo n.º 8
0
 internal static void BlockWrite(int arg_4, byte[] arg_6, File arg_A)
 {
     arg_A.stream.Write(arg_6, 0, arg_4);
 }
Exemplo n.º 9
0
 internal static int BlockRead(int count, byte[] data, File file)
 {
     return file.stream.Read(data, 0, count);
 }
Exemplo n.º 10
0
        // sub_4708B
        static void BuildLoadablePlayersLists(ref List<MenuItem> fileNames, ref List<MenuItem> displayNames,
            short playerFileSize, int npcOffset, int nameOffset, string fileFilter)
        {
            Classes.File file = new Classes.File();

            byte[] data = new byte[16];

            foreach (string filePath in Directory.GetFiles(Config.GetSavePath(), fileFilter))
            {
                FileStream stream = System.IO.File.Open(filePath, FileMode.Open, FileAccess.Read);

                if (stream.Length == playerFileSize)
                {
                    stream.Seek(nameOffset, SeekOrigin.Begin);
                    stream.Read(data, 0, 16);

                    string playerName = Sys.ArrayToString(data, 0, 15).Trim();

                    byte var_164;

                    if (gbl.import_from == ImportSource.Hillsfar)
                    {
                        var_164 = 0;
                    }
                    else
                    {
                        stream.Seek(npcOffset, SeekOrigin.Begin);
                        stream.Read(data, 0, 1);
                        var_164 = data[0];
                    }

                    string fullNameText =
                        string.Compare(Path.GetExtension(filePath), ".sav", true) == 0 ?
                        string.Format("{0,-15} from save game {1}", playerName, filePath[7]) : playerName;

                    bool found = gbl.TeamList.Find(player => playerName == player.name.Trim()) != null;

                    if (found == false && var_164 <= 0x7F)
                    {
                        fileNames.Add(new MenuItem(filePath));
                        displayNames.Add(new MenuItem(fullNameText));
                    }
                }

                stream.Close();
            }
        }
Exemplo n.º 11
0
        // sub_47DFC
        internal static void SavePlayer(string arg_0, Player player)
        {
            char input_key;
            Classes.File file = new Classes.File();

            gbl.import_from = ImportSource.Curse;

            string ext_text;
            string file_text;

            if (arg_0 == "")
            {
                ext_text = ".guy";
                file_text = seg042.clean_string(player.name);
            }
            else
            {
                ext_text = ".sav";
                file_text = arg_0;
            }

            input_key = 'N';

            while (input_key == 'N' &&
                arg_0.Length == 0 &&
                seg042.file_find(Path.Combine(Config.GetSavePath(), file_text) + ext_text) == true)
            {
                input_key = ovr027.yes_no(gbl.alertMenuColors, "Overwrite " + file_text + "? ");

                if (input_key == 'N')
                {
                    file_text = string.Empty;

                    while (file_text == string.Empty)
                    {
                        file_text = seg041.getUserInputString(8, 0, 10, "New file name: ");
                    }
                }
            }

            string filePath = Path.Combine(Config.GetSavePath(), file_text);

            file.Assign(filePath + ext_text);

            seg051.Rewrite(file);

            seg051.BlockWrite(Player.StructSize, player.ToByteArray(), file);
            seg051.Close(file);

            seg042.delete_file(filePath + ".swg");

            if (player.items.Count > 0)
            {
                file.Assign(filePath + ".swg");
                seg051.Rewrite(file);

                player.items.ForEach(item => seg051.BlockWrite(Item.StructSize, item.ToByteArray(), file));

                seg051.Close(file);
            }

            seg042.delete_file(filePath + ".fx");

            if (player.affects.Count > 0)
            {
                file.Assign(filePath + ".fx");
                seg051.Rewrite(file);

                foreach (Affect affect in player.affects)
                {
                    seg051.BlockWrite(Affect.StructSize, affect.ToByteArray(), file);
                }

                seg051.Close(file);
            }
        }
Exemplo n.º 12
0
        internal static void SaveGame()
        {
            char inputKey;
            Classes.File save_file = new Classes.File();
            string[] var_171 = new string[9];

            do
            {
                inputKey = ovr027.displayInput((gbl.game_state == GameState.Camping), 0, gbl.defaultMenuColors, "A B C D E F G H I J", "Save Which Game: ");

            } while (unk_4AEA0.MemberOf(inputKey) == false);

            if (inputKey != '\0')
            {
                gbl.import_from = ImportSource.Curse;

                short var_1FC;

                do
                {
                    save_file.Assign(Path.Combine(Config.GetSavePath(), "savgam" + inputKey + ".dat"));
                    seg051.Rewrite(save_file);
                    var_1FC = gbl.FIND_result;

                    if (unk_4AEEF.MemberOf(var_1FC) == false)
                    {
                        seg041.DisplayAndPause("Unexpected error during save: " + var_1FC.ToString(), 14);
                        seg051.Close(save_file);
                        return;
                    }
                } while (unk_4AEEF.MemberOf(var_1FC) == false);

                ovr027.ClearPromptArea();
                seg041.displayString("Saving...Please Wait", 0, 10, 0x18, 0);

                gbl.area_ptr.game_speed = (byte)gbl.game_speed_var;
                gbl.area_ptr.pics_on = (byte)(((gbl.PicsOn) ? 0x02 : 0) | ((gbl.AnimationsOn) ? 0x01 : 0));
                gbl.area2_ptr.game_area = gbl.game_area;

                byte[] data = new byte[0x1E00];

                data[0] = gbl.game_area;
                seg051.BlockWrite(1, data, save_file);

                seg051.BlockWrite(0x800, gbl.area_ptr.ToByteArray(), save_file);
                seg051.BlockWrite(0x800, gbl.area2_ptr.ToByteArray(), save_file);
                seg051.BlockWrite(0x400, gbl.stru_1B2CA.ToByteArray(), save_file);
                seg051.BlockWrite(0x1E00, gbl.ecl_ptr.ToByteArray(), save_file);

                data[0] = (byte)gbl.mapPosX;
                data[1] = (byte)gbl.mapPosY;
                data[2] = gbl.mapDirection;
                data[3] = gbl.mapWallType;
                data[4] = gbl.mapWallRoof;
                seg051.BlockWrite(5, data, save_file);

                data[0] = (byte)gbl.last_game_state;
                seg051.BlockWrite(1, data, save_file);
                data[0] = (byte)gbl.game_state;
                seg051.BlockWrite(1, data, save_file);

                for (int i = 0; i < 3; i++)
                {
                    Sys.ShortToArray((short)gbl.setBlocks[i].blockId, data, (i * 4) + 0);
                    Sys.ShortToArray((short)gbl.setBlocks[i].setId, data, (i * 4) + 2);
                }
                seg051.BlockWrite(12, data, save_file);

                int party_count = 0;
                foreach (Player tmp_player in gbl.TeamList)
                {
                    party_count++;
                    var_171[party_count - 1] = "CHRDAT" + inputKey + party_count.ToString();
                }

                data[0] = (byte)party_count;
                seg051.BlockWrite(1, data, save_file);

                for (int i = 0; i < party_count; i++)
                {
                    Sys.StringToArray(data, 0x29 * i, 0x29, var_171[i]);
                }
                seg051.BlockWrite(0x148, data, save_file);
                seg051.Close(save_file);

                party_count = 0;
                foreach (Player tmp_player in gbl.TeamList)
                {
                    party_count++;
                    SavePlayer("CHRDAT" + inputKey + party_count.ToString(), tmp_player);
                    remove_player_file(tmp_player);
                }

                gbl.gameSaved = true;
                ovr027.ClearPromptArea();
            }
        }