COPS v6 : Source & Tools [Custom Emulator]

01/14/2020 00:23 CptSky#166
You could try that Ini implementation, it uses Nini ([Only registered and activated users can see links. Click Here To Register...]

Code:
// *
// * ******** COPS v6 Emulator - Open Source ********
// * Copyright (C) 2014 - 2015 Jean-Philippe Boivin
// *
// * Please read the WARNING, DISCLAIMER and PATENTS
// * sections in the LICENSE file.
// *

using System;
using System.IO;
using Nini.Ini;

namespace COServer
{
    /// <summary>
    /// INI parser.
    /// </summary>
    public class Ini : IDisposable
    {
        /// <summary>
        /// The Nini document.
        /// </summary>
        private IniDocument mDoc;
        /// <summary>
        /// The stream of the file.
        /// </summary>
        private Stream mStream;
        /// <summary>
        /// The text reader used by Nini.
        /// </summary>
        private TextReader mReader;

        /// <summary>
        /// Indicate whether or not the object is disposed.
        /// </summary>
        private bool mIsDisposed = false;

        /// <summary>
        /// Open the specified file with an INI reader.
        /// </summary>
        public Ini(String aPath)
        {
            mStream = new FileStream(aPath, FileMode.Open, FileAccess.Read, FileShare.Read);
            mReader = new StreamReader(mStream, Program.Encoding);
            mDoc = new IniDocument(mReader, IniFileType.WindowsStyle);
        }

        ~Ini()
        {
            Dispose(false);
        }

        /// <summary>
        /// Performs application-defined tasks associated with freeing, releasing,
        /// or resetting unmanaged resources.
        /// </summary>
        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }

        /// <summary>
        /// Performs application-defined tasks associated with freeing, releasing,
        /// or resetting unmanaged resources.
        /// </summary>
        protected virtual void Dispose(bool aDisposing)
        {
            if (!mIsDisposed)
            {
                if (aDisposing)
                {
                    if (mReader != null)
                        mReader.Dispose();
                    if (mStream != null)
                        mStream.Dispose();
                }

                mReader = null;
                mStream = null;

                mIsDisposed = true;
            }
        }

        /// <summary>
        /// Determine if the specified key exists in the section.
        /// </summary>
        public Boolean KeyExist(String aSection, String aKey)
        {
            IniSection section = mDoc.Sections[aSection];
            if (section != null)
                return section.Contains(aKey);

            return false;
        }

        /// <summary>
        /// Read the value as a 8-bits signed integer.
        /// </summary>
        public SByte ReadInt8(String aSection, String aKey)
        {
            SByte value = 0;

            IniSection section = mDoc.Sections[aSection];
            if (section != null)
                SByte.TryParse(section.GetValue(aKey), out value);

            return value;
        }

        /// <summary>
        /// Read the value as a 8-bits signed integer.
        /// </summary>
        public SByte ReadInt8(String aSection, String aKey, SByte aDefault)
        {
            SByte value = aDefault;

            IniSection section = mDoc.Sections[aSection];
            if (section != null)
                SByte.TryParse(section.GetValue(aKey), out value);

            return value;
        }

        /// <summary>
        /// Read the value as a 8-bits unsigned integer.
        /// </summary>
        public Byte ReadUInt8(String aSection, String aKey)
        {
            Byte value = 0;

            IniSection section = mDoc.Sections[aSection];
            if (section != null)
                Byte.TryParse(section.GetValue(aKey), out value);

            return value;
        }

        /// <summary>
        /// Read the value as a 8-bits unsigned integer.
        /// </summary>
        public Byte ReadUInt8(String aSection, String aKey, Byte aDefault)
        {
            Byte value = aDefault;

            IniSection section = mDoc.Sections[aSection];
            if (section != null)
                Byte.TryParse(section.GetValue(aKey), out value);

            return value;
        }

        /// <summary>
        /// Read the value as a 16-bits signed integer.
        /// </summary>
        public Int16 ReadInt16(String aSection, String aKey)
        {
            Int16 value = 0;

            IniSection section = mDoc.Sections[aSection];
            if (section != null)
                Int16.TryParse(section.GetValue(aKey), out value);

            return value;
        }

        /// <summary>
        /// Read the value as a 16-bits signed integer.
        /// </summary>
        public Int16 ReadInt16(String aSection, String aKey, Int16 aDefault)
        {
            Int16 value = aDefault;

            IniSection section = mDoc.Sections[aSection];
            if (section != null)
                Int16.TryParse(section.GetValue(aKey), out value);

            return value;
        }

        /// <summary>
        /// Read the value as a 16-bits unsigned integer.
        /// </summary>
        public UInt16 ReadUInt16(String aSection, String aKey)
        {
            UInt16 value = 0;

            IniSection section = mDoc.Sections[aSection];
            if (section != null)
                UInt16.TryParse(section.GetValue(aKey), out value);

            return value;
        }

        /// <summary>
        /// Read the value as a 16-bits unsigned integer.
        /// </summary>
        public UInt16 ReadUInt16(String aSection, String aKey, UInt16 aDefault)
        {
            UInt16 value = aDefault;

            IniSection section = mDoc.Sections[aSection];
            if (section != null)
                UInt16.TryParse(section.GetValue(aKey), out value);

            return value;
        }

        /// <summary>
        /// Read the value as a 32-bits signed integer.
        /// </summary>
        public Int32 ReadInt32(String aSection, String aKey)
        {
            Int32 value = 0;

            IniSection section = mDoc.Sections[aSection];
            if (section != null)
                Int32.TryParse(section.GetValue(aKey), out value);

            return value;
        }

        /// <summary>
        /// Read the value as a 32-bits signed integer.
        /// </summary>
        public Int32 ReadInt32(String aSection, String aKey, Int32 aDefault)
        {
            Int32 value = aDefault;

            IniSection section = mDoc.Sections[aSection];
            if (section != null)
                Int32.TryParse(section.GetValue(aKey), out value);

            return value;
        }

        /// <summary>
        /// Read the value as a 32-bits unsigned integer.
        /// </summary>
        public UInt32 ReadUInt32(String aSection, String aKey)
        {
            UInt32 value = 0;

            IniSection section = mDoc.Sections[aSection];
            if (section != null)
                UInt32.TryParse(section.GetValue(aKey), out value);

            return value;
        }

        /// <summary>
        /// Read the value as a 32-bits unsigned integer.
        /// </summary>
        public UInt32 ReadUInt32(String aSection, String aKey, UInt32 aDefault)
        {
            UInt32 value = aDefault;

            IniSection section = mDoc.Sections[aSection];
            if (section != null)
                UInt32.TryParse(section.GetValue(aKey), out value);

            return value;
        }

        /// <summary>
        /// Read the value as a 64-bits signed integer.
        /// </summary>
        public Int64 ReadInt64(String aSection, String aKey)
        {
            Int64 value = 0;

            IniSection section = mDoc.Sections[aSection];
            if (section != null)
                Int64.TryParse(section.GetValue(aKey), out value);

            return value;
        }

        /// <summary>
        /// Read the value as a 64-bits signed integer.
        /// </summary>
        public Int64 ReadInt64(String aSection, String aKey, Int64 aDefault)
        {
            Int64 value = aDefault;

            IniSection section = mDoc.Sections[aSection];
            if (section != null)
                Int64.TryParse(section.GetValue(aKey), out value);

            return value;
        }

        /// <summary>
        /// Read the value as a 64-bits unsigned integer.
        /// </summary>
        public UInt64 ReadUInt64(String aSection, String aKey)
        {
            UInt64 value = 0;

            IniSection section = mDoc.Sections[aSection];
            if (section != null)
                UInt64.TryParse(section.GetValue(aKey), out value);

            return value;
        }

        /// <summary>
        /// Read the value as a 64-bits unsigned integer.
        /// </summary>
        public UInt64 ReadUInt64(String aSection, String aKey, UInt64 aDefault)
        {
            UInt64 value = aDefault;

            IniSection section = mDoc.Sections[aSection];
            if (section != null)
                UInt64.TryParse(section.GetValue(aKey), out value);

            return value;
        }

        /// <summary>
        /// Read the value as a 32-bits signed decimal.
        /// </summary>
        public Single ReadFloat(String aSection, String aKey)
        {
            Single value = 0;

            IniSection section = mDoc.Sections[aSection];
            if (section != null)
                Single.TryParse(section.GetValue(aKey), out value);

            return value;
        }

        /// <summary>
        /// Read the value as a 32-bits signed decimal.
        /// </summary>
        public Single ReadFloat(String aSection, String aKey, Single aDefault)
        {
            Single value = aDefault;

            IniSection section = mDoc.Sections[aSection];
            if (section != null)
                Single.TryParse(section.GetValue(aKey), out value);

            return value;
        }

        /// <summary>
        /// Read the value as a 64-bits signed decimal.
        /// </summary>
        public Double ReadDouble(String aSection, String aKey)
        {
            Double value = 0;

            IniSection section = mDoc.Sections[aSection];
            if (section != null)
                Double.TryParse(section.GetValue(aKey), out value);

            return value;
        }

        /// <summary>
        /// Read the value as a 64-bits signed decimal.
        /// </summary>
        public Double ReadDouble(String aSection, String aKey, Double aDefault)
        {
            Double value = aDefault;

            IniSection section = mDoc.Sections[aSection];
            if (section != null)
                Double.TryParse(section.GetValue(aKey), out value);

            return value;
        }

        /// <summary>
        /// Read the value as a boolean.
        /// </summary>
        public Boolean ReadBoolean(String aSection, String aKey)
        {
            Boolean value = false;

            IniSection section = mDoc.Sections[aSection];
            if (section != null)
                Boolean.TryParse(section.GetValue(aKey), out value);

            return value;
        }

        /// <summary>
        /// Read the value as a boolean.
        /// </summary>
        public Boolean ReadBoolean(String aSection, String aKey, Boolean aDefault)
        {
            Boolean value = aDefault;

            IniSection section = mDoc.Sections[aSection];
            if (section != null)
                Boolean.TryParse(section.GetValue(aKey), out value);

            return value;
        }

        /// <summary>
        /// Read the value as a string.
        /// </summary>
        [Obsolete]
        public String ReadValue(String aSection, String aKey)
        {
            return ReadString(aSection, aKey);
        }

        /// <summary>
        /// Read the value as a string.
        /// </summary>
        public String ReadString(String aSection, String aKey)
        {
            String value = null;

            IniSection section = mDoc.Sections[aSection];
            if (section != null)
                value = section.GetValue(aKey);

            return value != null ? value : "";
        }

        /// <summary>
        /// Read the value as a string.
        /// </summary>
        public String ReadString(String aSection, String aKey, String aDefault)
        {
            String value = null;

            IniSection section = mDoc.Sections[aSection];
            if (section != null)
                value = section.GetValue(aKey);

            return value != null ? value : aDefault;
        }
    }
}
04/18/2020 17:26 emobaba31#167
[Only registered and activated users can see links. Click Here To Register...]
Everything is OK. but here is frozen.
04/18/2020 21:02 Spirited#168
Quote:
Originally Posted by emobaba31 View Post
[Only registered and activated users can see links. Click Here To Register...]
Everything is OK. but here is frozen.
[Only registered and activated users can see links. Click Here To Register...]
04/24/2020 09:22 grimreaper5325#169
I'm not able to update spawns, can someone point me in the right direction? Just trying to increase pack density in some areas.
04/24/2020 23:36 CptSky#170
Quote:
Originally Posted by grimreaper5325 View Post
I'm not able to update spawns, can someone point me in the right direction? Just trying to increase pack density in some areas.
You need to modify the Spawn.txt (or something like that) and generate the binary file using the Generator.exe

Here's the file layout in txt:
Code:
BWriter.Write(Int16.Parse(Parts[1])); //MapId
BWriter.Write(UInt16.Parse(Parts[2])); //StartX
BWriter.Write(UInt16.Parse(Parts[3])); //StartY
BWriter.Write(UInt16.Parse(Parts[4])); //AddX
BWriter.Write(UInt16.Parse(Parts[5])); //AddY
BWriter.Write(Int32.Parse(Parts[6])); //MaxNPC
BWriter.Write(Int32.Parse(Parts[7])); //Rest Secs
BWriter.Write(Int32.Parse(Parts[8])); //Max_Per_Gen
BWriter.Write(Int32.Parse(Parts[9])); //NpcType
04/25/2020 00:38 grimreaper5325#171
Quote:
Originally Posted by CptSky View Post
You need to modify the Spawn.txt (or something like that) and generate the binary file using the Generator.exe

Here's the file layout in txt:
Code:
BWriter.Write(Int16.Parse(Parts[1])); //MapId
BWriter.Write(UInt16.Parse(Parts[2])); //StartX
BWriter.Write(UInt16.Parse(Parts[3])); //StartY
BWriter.Write(UInt16.Parse(Parts[4])); //AddX
BWriter.Write(UInt16.Parse(Parts[5])); //AddY
BWriter.Write(Int32.Parse(Parts[6])); //MaxNPC
BWriter.Write(Int32.Parse(Parts[7])); //Rest Secs
BWriter.Write(Int32.Parse(Parts[8])); //Max_Per_Gen
BWriter.Write(Int32.Parse(Parts[9])); //NpcType
Thank you, when I tried this before I encountered some errors, not quite sure what I was doing wrong before. I've run into two issues, lottery.exe doesn't work, throws an error that input string is in wrong format (haven't edited it yet). Also can't get shops to update using generator.exe and goods.exe, though I've got spawn editing working.
04/18/2021 21:19 skittles225#172
Hello!

So i am new to programming and private servers. I have played cq back in the day when it was awesome for 6 years and have played on private servers as well.

So i ran everything on 5017 version of the client. Everything works fine, i can connect i can create accounts etc.

Problem is that after I connect, the FPS starts to just go from 38 to 7 to 14 to 24 to 27 and back to 7 constantly, if I move around. If i don't move, it constantly jumps between 37 and 39.

Shouldn't it be a constant 38 or 39? What could be the problem as I have not found anything regarding this issue around.

I also cannot find the "Accounts" file where i am supposed to make my account to be a GM. I have the account files but there is no AccLvl entry in them.

Also i cannot find any commands but i suppose they are the ones for the 5017 client. I do not know yet but i'll keep trying around.

Thank you cheers!