Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Codigo/Declares.bas
Original file line number Diff line number Diff line change
Expand Up @@ -1906,7 +1906,7 @@ End Enum

Public Type t_UserOBJ
ObjIndex As Integer
amount As Integer
Amount As Long
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. t_UserOBJ.amount As Integer → Amount As Long is a breaking structural change

Changing a UDT field type (and even just its name, though VB is case-insensitive) changes the binary layout of t_UserOBJ.

That can break anything that:

Get/Put’s inventory structs to disk (binary saves, charfiles, etc.)

Sends inventory structs over the network (packet layouts)

Copies memory blobs around (e.g., CopyMemory, RtlMoveMemory, custom serialization)

Even if you never serialize t_UserOBJ, a UDT size change can still break code that assumes offsets.

Action: search for any Get #, Put #, Len(t_UserOBJ), CopyMemory, or packet building that writes t_UserOBJ raw. If any exist, you need a migration/compat layer or keep stored format as Integer and clamp.

Also: Inventory stack sizes being Long is reasonable, but you should enforce caps anyway (anti-dupe / overflow / economy).

Equipped As Byte
ElementalTags As Long
End Type
Expand Down
8 changes: 6 additions & 2 deletions Codigo/ServerConfig.cls
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,12 @@ Public Function LoadSettings(ByVal Filename As String) As Long
mSettings.Add "AUTONAVALBATTLE_Description", reader.GetValue("AUTONAVALBATTLE", "Description")
mSettings.Add "MiningExp", CByte(val(reader.GetValue("JOBEXP", "MiningExp", 1)))
mSettings.Add "FellingExp", CByte(val(reader.GetValue("JOBEXP", "FellingExp", 1)))
mSettings.Add "ForgingExp", CByte(val(reader.GetValue("JOBEXP", "ForgingExp", 1)))
mSettings.Add "CarpentryExp", CByte(val(reader.GetValue("JOBEXP", "CarpentryExp", 1)))
mSettings.Add "IronForgingExp", CByte(val(reader.GetValue("JOBEXP", "IronForgingExp", 1)))
mSettings.Add "SilverForgingExp", CByte(val(reader.GetValue("JOBEXP", "SilverForgingExp", 1)))
mSettings.Add "GoldForgingExp", CByte(val(reader.GetValue("JOBEXP", "GoldForgingExp", 1)))
mSettings.Add "BlodiumForgingExp", CByte(val(reader.GetValue("JOBEXP", "BlodiumForgingExp", 1)))
mSettings.Add "WoodCarpentryExp", CByte(val(reader.GetValue("JOBEXP", "WoodCarpentryExp", 1)))
mSettings.Add "ElvenWoodCarpentryExp", CByte(val(reader.GetValue("JOBEXP", "ElvenWoodCarpentryExp", 1)))
mSettings.Add "FishingExp", CByte(val(reader.GetValue("JOBEXP", "FishingExp", 1)))
mSettings.Add "MixingExp", CByte(val(reader.GetValue("JOBEXP", "MixingExp", 1)))
mSettings.Add "ElseExp", CByte(val(reader.GetValue("JOBEXP", "ElseExp", 1)))
Expand Down
56 changes: 46 additions & 10 deletions Codigo/Trabajo.bas
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ TieneObjetos_Err:
Call TraceError(Err.Number, Err.Description, "Trabajo.TieneObjetos", Erl)
End Function

Function QuitarObjetos(ByVal ItemIndex As Integer, ByVal cant As Integer, ByVal UserIndex As Integer, Optional ByVal ElementalTags As Long = e_ElementalTags.Normal) As Boolean
Function QuitarObjetos(ByVal ItemIndex As Integer, ByVal cant As Long, ByVal UserIndex As Integer, Optional ByVal ElementalTags As Long = e_ElementalTags.Normal) As Boolean
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. QuitarObjetos and material removal types: mixed Long/Integer

You updated:

QuitarObjetos(... cant As Long ...)

But left:

CarpinteroQuitarMateriales(... CantidadElfica As Integer, CantidadPino As Integer)

If someone crafts in bulk and CantidadElfica or CantidadPino can exceed 32767, that’s a silent overflow risk.

Action: make all these quantities Long for consistency:

CantidadElfica As Long

CantidadPino As Long

(and any other “Cantidad*” used in bulk crafting paths)

On Error GoTo QuitarObjetos_Err
With UserList(UserIndex)
Dim i As Long
Expand Down Expand Up @@ -401,7 +401,7 @@ HerreroQuitarMateriales_Err:
Call TraceError(Err.Number, Err.Description, "Trabajo.HerreroQuitarMateriales", Erl)
End Sub

Sub CarpinteroQuitarMateriales(ByVal UserIndex As Integer, ByVal ItemIndex As Integer, ByVal Cantidad As Integer, ByVal CantidadElfica As Integer, ByVal CantidadPino As Integer)
Sub CarpinteroQuitarMateriales(ByVal UserIndex As Integer, ByVal ItemIndex As Integer, ByVal Cantidad As Long, ByVal CantidadElfica As Integer, ByVal CantidadPino As Integer)
On Error GoTo CarpinteroQuitarMateriales_Err
If ObjData(ItemIndex).Madera > 0 Then Call QuitarObjetos(Wood, Cantidad, UserIndex)
If ObjData(ItemIndex).MaderaElfica > 0 Then Call QuitarObjetos(ElvenWood, CantidadElfica, UserIndex)
Expand Down Expand Up @@ -927,7 +927,7 @@ Public Sub HerreroConstruirItem(ByVal UserIndex As Integer, ByVal ItemIndex As I
Call SendData(SendTarget.ToPCAliveArea, UserIndex, PrepareMessagePlayWave(MARTILLOHERRERO, UserList(UserIndex).pos.x, UserList(UserIndex).pos.y))
UserList(UserIndex).Counters.Trabajando = UserList(UserIndex).Counters.Trabajando + 1
If IsFeatureEnabled("gain_exp_while_working") Then
Call GiveExpWhileWorking(UserIndex, UserList(UserIndex).invent.EquippedWorkingToolObjIndex, e_JobsTypes.Blacksmith)
Call GiveExpWhileWorking(UserIndex, MiObj.ObjIndex, e_JobsTypes.Blacksmith, MiObj.Amount)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactor this to pass MiObj by ref and Call GiveExpWhileWorking(UserIndex, MiObj, e_JobsTypes.Blacksmith)

Call WriteUpdateExp(UserIndex)
Call CheckUserLevel(UserIndex)
End If
Expand Down Expand Up @@ -1035,7 +1035,7 @@ Public Sub CarpinteroConstruirItem(ByVal UserIndex As Integer, ByVal ItemIndex A
End If
Call SubirSkill(UserIndex, e_Skill.Carpinteria)
If IsFeatureEnabled("gain_exp_while_working") Then
Call GiveExpWhileWorking(UserIndex, UserList(UserIndex).invent.EquippedWorkingToolObjIndex, e_JobsTypes.Carpenter)
Call GiveExpWhileWorking(UserIndex, MiObj.ObjIndex, e_JobsTypes.Carpenter, MiObj.Amount)
Call WriteUpdateExp(UserIndex)
Call CheckUserLevel(UserIndex)
End If
Expand Down Expand Up @@ -1093,7 +1093,7 @@ Public Sub AlquimistaConstruirItem(ByVal UserIndex As Integer, ByVal ItemIndex A
Call SubirSkill(UserIndex, e_Skill.Alquimia)
Call UpdateUserInv(True, UserIndex, 0)
If IsFeatureEnabled("gain_exp_while_working") Then
Call GiveExpWhileWorking(UserIndex, UserList(UserIndex).invent.EquippedWorkingToolObjIndex, e_JobsTypes.Alchemist)
Call GiveExpWhileWorking(UserIndex, UserList(UserIndex).invent.EquippedWorkingToolObjIndex, e_JobsTypes.Alchemist, MiObj.Amount)
Call WriteUpdateExp(UserIndex)
Call CheckUserLevel(UserIndex)
End If
Expand Down Expand Up @@ -2051,26 +2051,62 @@ Public Function GetExtractResourceForLevel(ByVal level As Integer) As Integer
GetExtractResourceForLevel = RandomNumber(lower, upper)
End Function

Public Function GiveExpWhileWorking(ByVal UserIndex As Integer, ByVal ItemIndex As Integer, ByVal JobType As Byte)
Public Function GiveExpWhileWorking(ByVal UserIndex As Integer, ByVal ItemIndex As Integer, ByVal JobType As Byte, Optional ByVal Quantity As Integer = 1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactor this to GiveExpWhileWorking(ByVal UserIndex As Integer, obj as t_Obj, ByVal JobType As Byte)

  1. GiveExpWhileWorking signature and types: Quantity is a Long, and default type mismatch

You changed:

Public Function GiveExpWhileWorking(... Optional ByVal Quantity As Integer = 1)

But you’re passing MiObj.Amount which is now Long.

In VB6 this will coerce, but it’s still wrong-footed and can overflow if Amount > 32767.

Action: make it:

Optional ByVal Quantity As Long = 1

and keep tmpExp As Long (good change).

On Error GoTo GiveExpWhileWorking_Err:
Dim tmpExp As Byte
Dim tmpExp As Long
Select Case JobType
Case e_JobsTypes.Miner
tmpExp = SvrConfig.GetValue("MiningExp")
Case e_JobsTypes.Woodcutter
tmpExp = SvrConfig.GetValue("FellingExp")
Case e_JobsTypes.Blacksmith
tmpExp = SvrConfig.GetValue("ForgingExp")
If ObjData(ItemIndex).LingH > 0 Then
tmpExp = tmpExp + ObjData(ItemIndex).LingH * SvrConfig.GetValue("IronForgingExp") * Quantity
End If
If ObjData(ItemIndex).LingP > 0 Then
tmpExp = tmpExp + ObjData(ItemIndex).LingP * SvrConfig.GetValue("SilverForgingExp") * Quantity
End If
If ObjData(ItemIndex).LingO > 0 Then
tmpExp = tmpExp + ObjData(ItemIndex).LingO * SvrConfig.GetValue("GoldForgingExp") * Quantity
End If
If ObjData(ItemIndex).Blodium > 0 Then
tmpExp = tmpExp + ObjData(ItemIndex).Blodium * SvrConfig.GetValue("BlodiumForgingExp") * Quantity
End If
Case e_JobsTypes.Carpenter
tmpExp = SvrConfig.GetValue("CarpentryExp")
If ObjData(ItemIndex).Madera > 0 Then
tmpExp = tmpExp + ObjData(ItemIndex).Madera * SvrConfig.GetValue("WoodCarpentryExp") * Quantity
End If
If ObjData(ItemIndex).MaderaElfica > 0 Then
tmpExp = tmpExp + ObjData(ItemIndex).MaderaElfica * SvrConfig.GetValue("ElvenWoodCarpentryExp") * Quantity
End If
Case e_JobsTypes.Woodcutter
tmpExp = SvrConfig.GetValue("FellingExp")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Duplicate Case e_JobsTypes.Woodcutter

You currently have Woodcutter twice:

Case e_JobsTypes.Woodcutter
tmpExp = ...
...
Case e_JobsTypes.Woodcutter
tmpExp = ...

Not harmful (first match wins), but it’s dead/duplicate code and can hide future edits.

Action: remove the duplicate case.

Case e_JobsTypes.Fisherman
If ObjData(ItemIndex).Power >= 2 Then
tmpExp = SvrConfig.GetValue("FishingExp")
End If
Case e_JobsTypes.Alchemist
tmpExp = SvrConfig.GetValue("MixingExp")
If ObjData(ItemIndex).FlorRoja > 0 Then
tmpExp = tmpExp + ObjData(ItemIndex).FlorRoja * SvrConfig.GetValue("MixingExp")
End If
If ObjData(ItemIndex).FlorOceano > 0 Then
tmpExp = tmpExp + ObjData(ItemIndex).FlorRoja * SvrConfig.GetValue("MixingExp")
End If
If ObjData(ItemIndex).ColaDeZorro > 0 Then
tmpExp = tmpExp + ObjData(ItemIndex).FlorRoja * SvrConfig.GetValue("MixingExp")
End If
If ObjData(ItemIndex).Tuna > 0 Then
tmpExp = tmpExp + ObjData(ItemIndex).FlorRoja * SvrConfig.GetValue("MixingExp")
End If
If ObjData(ItemIndex).HongoDeLuz > 0 Then
tmpExp = tmpExp + ObjData(ItemIndex).FlorRoja * SvrConfig.GetValue("MixingExp")
End If
If ObjData(ItemIndex).SemillasPros > 0 Then
tmpExp = tmpExp + ObjData(ItemIndex).FlorRoja * SvrConfig.GetValue("MixingExp")
End If
If ObjData(ItemIndex).Cala > 0 Then
tmpExp = tmpExp + ObjData(ItemIndex).FlorRoja * SvrConfig.GetValue("MixingExp")
End If
Case Else
Comment on lines +2089 to 2110
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Big logic bug in Alchemist EXP: copy/paste uses the wrong ingredient every time

You added:

If ObjData(ItemIndex).FlorOceano > 0 Then
tmpExp = tmpExp + ObjData(ItemIndex).FlorRoja * SvrConfig.GetValue("MixingExp")
End If

…and similarly for ColaDeZorro, Tuna, HongoDeLuz, SemillasPros, Cala: they all add FlorRoja.

That’s almost certainly a bug.

Fix: each branch should multiply its own field:

FlorOceano branch uses ObjData(ItemIndex).FlorOceano

ColaDeZorro uses ObjData(ItemIndex).ColaDeZorro

etc.

Also: you don’t apply * Quantity in the Alchemist case (you do for forging/carpentry). If bulk crafting is intended to scale EXP, you likely want * Quantity for Alchemist too.

tmpExp = SvrConfig.GetValue("ElseExp")
End Select
Expand Down
9 changes: 6 additions & 3 deletions Configuracion.ini
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,12 @@ Description=Evento Automatico
[JOBEXP]
MiningExp=1
FellingExp=1
ForgingExp=1
CarpentryExp=1
FellingExp=1
IronForgingExp=10
SilverForgingExp=25
GoldForgingExp=50
BlodiumForgingExp=5
WoodCarpentryExp=2
ElvenWoodCarpentryExp=8
FishingExp=1
MixingExp=1
ElseExp=1
Expand Down