Mirage Source

Free ORPG making software.
It is currently Fri Apr 26, 2024 5:38 am

All times are UTC




Post new topic Reply to topic  [ 927 posts ]  Go to page 1, 2, 3, 4, 5 ... 38  Next
Author Message
PostPosted: Wed Apr 08, 2009 12:24 am 
Offline
Pro
User avatar

Joined: Sun Aug 05, 2007 2:26 pm
Posts: 547
Now I know this way may not be the most secure/effecient way to do this, but it will turn what would be a multiple hour project to be done in a matter of seconds. If you want to do it all manaully you can, but here is the quick easy way.

Open up a search box, go to modHandleData.

Search for CInt, replace all (in module) with CCInt

Search for CLng, replace all (in module) with CCLng

Search for CByte, replace all (in module) with CCByte

At the bottom add
Code:
Private Function CCInt(ByRef s As String) As Integer
    ' Make sure there is a valid string
    If LenB(s) = 0 Then Exit Function
    ' Check if it's a number
    If Not s Like "*[!0-9]*" Then
        ' Check for overflows
        If s >= -32768 Then
            If s <= 32767 Then
                CCInt = CInt(s)
            End If
        End If
    End If
End Function



Private Function CCLng(ByRef s As String) As Long
    ' Make sure there is a valid string
    If LenB(s) = 0 Then Exit Function
    ' Check if it's a number
    If Not s Like "*[!0-9]*" Then
        ' Check for overflows
        If s >= -2147483468 Then
            If s <= 2147483468 Then
                CCLng = CLng(s)
            End If
        End If
    End If
End Function

Private Function CCByte(ByRef s As String) As Byte
    ' Make sure there is a valid string
    If LenB(s) = 0 Then Exit Function
    ' Check if it's a number
    If Not s Like "*[!0-9]*" Then
        ' Check for overflows
        If s >= 0 Then
            If s <= 255 Then
                CCByte = CByte(s)
            End If
        End If
    End If
End Function


If you can find any problems please report them. Again I KNOW that this is not the best way to be doing this, but it is such a minuscule difference and I don't know about any of you but I don't want to spend a few hours adding these tedious checks. I would recommend someone doing just that for ms4 though ;).

_________________
GIAKEN wrote:
I think what I see is this happening:

Labmonkey gets mod, everybody loves him, people find out his code sucks, he gets demoted, then banned, then he makes an engine called Chaos Engine.


Last edited by Labmonkey on Fri Apr 10, 2009 2:42 pm, edited 3 times in total.

Top
 Profile  
 
PostPosted: Wed Apr 08, 2009 12:35 am 
Offline
Persistant Poster
User avatar

Joined: Thu Mar 29, 2007 10:30 pm
Posts: 1510
Location: Virginia, USA
Google Talk: hpmccloud@gmail.com
You need to do it like this:

Code:
    Public Function CCInt(ByVal str As String) As Integer
        If IsNumeric(str) Then
            CCInt = CInt(str)
        Else
            CCInt = Val(str)
        End If
    End Function

    Public Function CCLng(ByVal str As String) As Integer
        If IsNumeric(str) Then
            CCLng = CLng(str)
        Else
            CCLng = Val(str)
        End If
    End Function
    Public Function CCByte(ByVal str As String) As Integer
        If IsNumeric(str) Then
            CCByte = CCyte(str)
        Else
            CCByte = Val(str)
        End If
    End Function

_________________
Nean wrote:
Yes harold. Give it to me.

Image
Image


Top
 Profile  
 
PostPosted: Wed Apr 08, 2009 3:43 pm 
Offline
Pro
User avatar

Joined: Sun Aug 05, 2007 2:26 pm
Posts: 547
What does Val do that CInt/CByte/CLng don't? Sorry but it seems like if there was any text in it then there would be errors and it wouldn't matter what you changed the number to.

_________________
GIAKEN wrote:
I think what I see is this happening:

Labmonkey gets mod, everybody loves him, people find out his code sucks, he gets demoted, then banned, then he makes an engine called Chaos Engine.


Top
 Profile  
 
PostPosted: Wed Apr 08, 2009 5:36 pm 
Offline
Persistant Poster
User avatar

Joined: Thu Mar 29, 2007 10:30 pm
Posts: 1510
Location: Virginia, USA
Google Talk: hpmccloud@gmail.com
Oh...well I was getting an error with CInt when it was trying to convert "" to 0, so I put a Val on it and it worked.

_________________
Nean wrote:
Yes harold. Give it to me.

Image
Image


Top
 Profile  
 
PostPosted: Wed Apr 08, 2009 5:40 pm 
Offline
Pro
User avatar

Joined: Sun Aug 05, 2007 2:26 pm
Posts: 547
CInt converts a Numeric string ie "0" , "1", "2" to an integer. "" isn't a number. CCInt will convert that to 0 though. Read the code.

_________________
GIAKEN wrote:
I think what I see is this happening:

Labmonkey gets mod, everybody loves him, people find out his code sucks, he gets demoted, then banned, then he makes an engine called Chaos Engine.


Top
 Profile  
 
PostPosted: Wed Apr 08, 2009 5:40 pm 
Offline
Pro
User avatar

Joined: Tue Nov 13, 2007 2:42 pm
Posts: 509
I would make the function more like this
Code:
Public Function CCInt(ByRef s As String) As Integer
    If Len(s) = 0 Then Exit Function
    If Not s Like "*[!0-9]*" Then CCInt = CInt(s)
End Function


* Edit
I changed it a little bit.

I was testing a little bit more..

If you have a string like "2add2", and use Val(string) it will = 2. With the above method it will equal 0.


Top
 Profile  
 
PostPosted: Thu Apr 09, 2009 8:47 am 
Offline
Knowledgeable

Joined: Sat Jul 08, 2006 8:24 am
Posts: 339
Usning IsNumeric is probably way faster than your code. But yeah, when I told labmonkey about the IsNumeric function, I suggested to check each packet one by one. May be a lot of work, but looks better.


Top
 Profile  
 
PostPosted: Thu Apr 09, 2009 10:52 am 
Offline
Pro
User avatar

Joined: Tue Nov 13, 2007 2:42 pm
Posts: 509
I did a speed test and mine was a tiny bit faster. I'll post the results in a little bit.


Top
 Profile  
 
PostPosted: Thu Apr 09, 2009 11:56 am 
Offline
Persistant Poster
User avatar

Joined: Wed Nov 29, 2006 11:25 pm
Posts: 860
Location: Ayer
Dugor wrote:
I did a speed test and mine was a tiny bit faster. I'll post the results in a little bit.


How'd you do that?

_________________
Image


Top
 Profile  
 
PostPosted: Thu Apr 09, 2009 12:22 pm 
Offline
Pro
User avatar

Joined: Tue Nov 13, 2007 2:42 pm
Posts: 509
Testing IsNumeric vs my method. 10000 loops.

Quote:
%Faster -40| -25| -25| -25| -25| 33.3| -25| -25| 0| -25
Test1 3| 3| 3| 3| 3| 4| 3| 3| 4| 3
Test2 5| 4| 4| 4| 4| 3| 4| 4| 4| 4


There's only a 1 millisecond difference, but that's still something.

Test1:
Code:
Public Sub TestOne()
    CCInt "test1"
End Sub

Private Function CCInt(ByRef s As String) As Integer
    If LenB(s) = 0 Then Exit Function
    If Not s Like "*[!0-9]*" Then CCInt = CInt(s)
End Function


Test2:
Code:
Public Sub TestTwo()
    CCInt "test2"
End Sub

Private Function CCInt(ByRef s As String) As Integer
    If LenB(s) = 0 Then Exit Function
    If IsNumeric(s) Then CCInt = CInt(s)
End Function


I use Spodis' speed template for testing: http://www.vbgore.com/Testing_VB_code_speed


Top
 Profile  
 
PostPosted: Thu Apr 09, 2009 6:14 pm 
Offline
Pro
User avatar

Joined: Mon May 29, 2006 3:26 pm
Posts: 493
Location: São Paulo, Brasil
Google Talk: blackagesbr@gmail.com
Convert to binary packets and you'll have no problem with that at all...

_________________
http://www.blackages.com.br
Image
Dave wrote:
GameBoy wrote:
www.FreeMoney.com
I admit I clicked. I immediately closed upon realizing there was, in fact, no free money.
Robin wrote:
I love you and your computer.Marry me.


Top
 Profile  
 
PostPosted: Thu Apr 09, 2009 6:24 pm 
Offline
Pro
User avatar

Joined: Sun Aug 05, 2007 2:26 pm
Posts: 547
Convert to binary packets and you will have to make some free time in your schedule ;).


Anyway, in a bit i will edit my tutorial to use Dugor's method. Thank's for posting.

_________________
GIAKEN wrote:
I think what I see is this happening:

Labmonkey gets mod, everybody loves him, people find out his code sucks, he gets demoted, then banned, then he makes an engine called Chaos Engine.


Top
 Profile  
 
PostPosted: Thu Apr 09, 2009 6:37 pm 
Offline
Pro
User avatar

Joined: Mon May 29, 2006 3:26 pm
Posts: 493
Location: São Paulo, Brasil
Google Talk: blackagesbr@gmail.com
Labmonkey wrote:
Convert to binary packets and you will have to make some free time in your schedule ;).


Anyway, in a bit i will edit my tutorial to use Dugor's method. Thank's for posting.

Well, it consumes time, I can't deny, but it's worth the time.

_________________
http://www.blackages.com.br
Image
Dave wrote:
GameBoy wrote:
www.FreeMoney.com
I admit I clicked. I immediately closed upon realizing there was, in fact, no free money.
Robin wrote:
I love you and your computer.Marry me.


Top
 Profile  
 
PostPosted: Thu Apr 09, 2009 6:52 pm 
Dragoons Master wrote:
Labmonkey wrote:
Convert to binary packets and you will have to make some free time in your schedule ;).


Anyway, in a bit i will edit my tutorial to use Dugor's method. Thank's for posting.

Well, it consumes time, I can't deny, but it's worth the time.


I dunno. When Dugor helped me convert FPO to byte array packets, it didn't take that long.


Top
  
 
PostPosted: Fri Apr 10, 2009 8:45 am 
Offline
Knowledgeable

Joined: Sat Jul 08, 2006 8:24 am
Posts: 339
Dugor, 1 problem with your test, you only test strings. Trow(<someone teach me how to spell this word please) a number in there, and check if there's a difference, considering in 99% the IsNumeric() function will return true, unless some kid is packet editing.

Basicly, you tested the wrong thing <3. But I forgive you. This time. Don't do it again. Or I'll kill you. Scotty doesn't know. Dont tell Scotty.


Top
 Profile  
 
PostPosted: Fri Apr 10, 2009 8:46 am 
Offline
Submit-Happy
User avatar

Joined: Fri Jun 16, 2006 7:01 am
Posts: 2768
Location: Yorkshire, UK
Joost wrote:
Dugor, 1 problem with your test, you only test strings. Trow(<someone teach me how to spell this word please) a number in there, and check if there's a difference, considering in 99% the IsNumeric() function will return true, unless some kid is packet editing.

Basicly, you tested the wrong thing <3. But I forgive you. This time. Don't do it again. Or I'll kill you. Scotty doesn't know. Dont tell Scotty.


Throw.

_________________
Quote:
Robin:
Why aren't maps and shit loaded up in a dynamic array?
Jacob:
the 4 people that know how are lazy
Robin:
Who are those 4 people?
Jacob:
um
you, me, and 2 others?


Image


Top
 Profile  
 
PostPosted: Fri Apr 10, 2009 12:05 pm 
Offline
Pro
User avatar

Joined: Tue Nov 13, 2007 2:42 pm
Posts: 509
I figured i didn't need to post the results for just a regular number because the results were about the same.
Quote:
%Faster -12.5| -16.7| -28.6| -14.3| 20| -14.3| -14.3| 0| 0| -14.3
Test1 7| 5| 5| 6| 6| 6| 6| 6| 6| 6
Test2 8| 6| 7| 7| 5| 7| 7| 6| 6| 7


Code:
Public Sub TestOne()
    CCInt "222"
End Sub

Private Function CCInt(ByRef s As String) As Integer
    If LenB(s) = 0 Then Exit Function
    If Not s Like "*[!0-9]*" Then CCInt = CInt(s)
End Function


Code:
Public Sub TestTwo()
    CCInt "222"
End Sub

Private Function CCInt(ByRef s As String) As Integer
    If LenB(s) = 0 Then Exit Function
    If IsNumeric(s) Then CCInt = CInt(s)
End Function


Top
 Profile  
 
PostPosted: Fri Apr 10, 2009 12:55 pm 
Offline
Knowledgeable

Joined: Sat Jul 08, 2006 8:24 am
Posts: 339
In that case, I give up, the function you use is better than the function I suggested. Proving once again discussion increases general knowledge ;p


Top
 Profile  
 
PostPosted: Fri Apr 10, 2009 1:14 pm 
Offline
Pro
User avatar

Joined: Sun Aug 05, 2007 2:26 pm
Posts: 547
Ok I updated the tutorial. Thanks!

_________________
GIAKEN wrote:
I think what I see is this happening:

Labmonkey gets mod, everybody loves him, people find out his code sucks, he gets demoted, then banned, then he makes an engine called Chaos Engine.


Top
 Profile  
 
PostPosted: Fri Apr 10, 2009 1:17 pm 
Offline
Pro
User avatar

Joined: Tue Nov 13, 2007 2:42 pm
Posts: 509
Make sure your functions return the right data type!

Code:
Private Function CCByte(ByRef s As String) As Integer

Code:
Private Function CCByte(ByRef s As String) As Byte


Code:
Private Function CCLng(ByRef s As String) As Integer

Code:
Private Function CCLng(ByRef s As String) As Long


Top
 Profile  
 
PostPosted: Fri Apr 10, 2009 1:49 pm 
Offline
Pro
User avatar

Joined: Tue Nov 13, 2007 2:42 pm
Posts: 509
I was just thinking, if you want to be truely protected with these conversions, you'll also need to check for overflows.
Code:
Private Function CCByte(ByRef s As String) As Byte
    ' Make sure there is a valid string
    If LenB(s) = 0 Then Exit Function
    ' Check if it's a number
    If Not s Like "*[!0-9]*" Then
        ' Check for overflows
        If s >= 0 Then
            If s <= 255 Then
                CCByte = CByte(s)
            End If
        End If
    End If
End Function


Code:
Private Function CCInt(ByRef s As String) As Integer
    ' Make sure there is a valid string
    If LenB(s) = 0 Then Exit Function
    ' Check if it's a number
    If Not s Like "*[!0-9]*" Then
        ' Check for overflows
        If s >= -32768 Then
            If s <= 32767 Then
                CCInt = CInt(s)
            End If
        End If
    End If
End Function


Code:
Private Function CCLng(ByRef s As String) As Long
    ' Make sure there is a valid string
    If LenB(s) = 0 Then Exit Function
    ' Check if it's a number
    If Not s Like "*[!0-9]*" Then
        ' Check for overflows
        If s >= -2147483468 Then
            If s <= 2147483468 Then
                CCLng = CLng(s)
            End If
        End If
    End If
End Function


Top
 Profile  
 
PostPosted: Fri Apr 10, 2009 2:43 pm 
Offline
Pro
User avatar

Joined: Sun Aug 05, 2007 2:26 pm
Posts: 547
Thanks Dugor!

_________________
GIAKEN wrote:
I think what I see is this happening:

Labmonkey gets mod, everybody loves him, people find out his code sucks, he gets demoted, then banned, then he makes an engine called Chaos Engine.


Top
 Profile  
 
PostPosted: Wed Dec 01, 2021 10:41 am 
Online
Mirage Source Lover

Joined: Sun Jul 04, 2021 4:04 am
Posts: 487675
сайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайт
сайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайт
сайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайт
сайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайт
сайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайт
сайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайт
сайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайт
сайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайт
сайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтсайтsemiasphalticfluxсайтсайтсайт
сайтсайтсайтсайтсайтсайтhttp://taskreasoning.ruсайтсайтсайтинфосайтсайтtuchkasсайтсайт


Top
 Profile  
 
PostPosted: Tue Jan 11, 2022 3:27 pm 
Online
Mirage Source Lover

Joined: Sun Jul 04, 2021 4:04 am
Posts: 487675
Econ


Top
 Profile  
 
PostPosted: Tue Jan 11, 2022 3:28 pm 
Online
Mirage Source Lover

Joined: Sun Jul 04, 2021 4:04 am
Posts: 487675
130.5


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 927 posts ]  Go to page 1, 2, 3, 4, 5 ... 38  Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 8 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group